diff --git a/src/ImageSharp/Formats/Jpeg/Port/Components/ScanDecoder.cs b/src/ImageSharp/Formats/Jpeg/Port/Components/ScanDecoder.cs index 066dbf3ac..8b711eaa8 100644 --- a/src/ImageSharp/Formats/Jpeg/Port/Components/ScanDecoder.cs +++ b/src/ImageSharp/Formats/Jpeg/Port/Components/ScanDecoder.cs @@ -621,6 +621,8 @@ namespace ImageSharp.Formats.Jpeg.Port.Components short code = -1; // TODO: Adding this code introduces error into the decoder. + // NOTES # During investigation of the libjpeg implementation it appears that they pull 32bits at a time and operate on those bits + // using 3 methods: FillBits, PeekBits, and ReadBits. We should attempt to do the same. // It doesn't appear to speed anything up either. // if (this.bitsUnRead < 8) // { diff --git a/src/ImageSharp/Formats/Jpeg/Port/JpegDecoderCore.cs b/src/ImageSharp/Formats/Jpeg/Port/JpegDecoderCore.cs index 074ee3cfd..8bc43f0f7 100644 --- a/src/ImageSharp/Formats/Jpeg/Port/JpegDecoderCore.cs +++ b/src/ImageSharp/Formats/Jpeg/Port/JpegDecoderCore.cs @@ -542,11 +542,6 @@ namespace ImageSharp.Formats.Jpeg.Port remaining--; int quantizationTableSpec = this.InputStream.ReadByte(); - if (quantizationTableSpec > 3) - { - throw new ImageFormatException($"Bad Tq index value: {quantizationTableSpec}"); - } - switch (quantizationTableSpec >> 4) { case 0: @@ -561,7 +556,7 @@ namespace ImageSharp.Formats.Jpeg.Port this.InputStream.Read(this.temp, 0, 64); remaining -= 64; - Span tableSpan = this.quantizationTables.Tables.GetRowSpan(quantizationTableSpec); + Span tableSpan = this.quantizationTables.Tables.GetRowSpan(quantizationTableSpec & 15); for (int j = 0; j < 64; j++) { tableSpan[QuantizationTables.DctZigZag[j]] = this.temp[j]; @@ -581,7 +576,7 @@ namespace ImageSharp.Formats.Jpeg.Port this.InputStream.Read(this.temp, 0, 128); remaining -= 128; - Span tableSpan = this.quantizationTables.Tables.GetRowSpan(quantizationTableSpec); + Span tableSpan = this.quantizationTables.Tables.GetRowSpan(quantizationTableSpec & 15); for (int j = 0; j < 64; j++) { tableSpan[QuantizationTables.DctZigZag[j]] = (short)((this.temp[2 * j] << 8) | this.temp[(2 * j) + 1]); diff --git a/tests/ImageSharp.Tests/FileTestBase.cs b/tests/ImageSharp.Tests/FileTestBase.cs index 51a1562f5..1c3cb2d5b 100644 --- a/tests/ImageSharp.Tests/FileTestBase.cs +++ b/tests/ImageSharp.Tests/FileTestBase.cs @@ -70,7 +70,9 @@ namespace ImageSharp.Tests // TestFile.Create(TestImages.Jpeg.Baseline.Ycck), // Perf: Enable for local testing only // TestFile.Create(TestImages.Jpeg.Baseline.Cmyk), // Perf: Enable for local testing only // TestFile.Create(TestImages.Jpeg.Baseline.Floorplan), // Perf: Enable for local testing only + // TestFile.Create(TestImages.Jpeg.Progressive.Festzug), // Perf: Enable for local testing only // TestFile.Create(TestImages.Jpeg.Baseline.Bad.MissingEOF), // Perf: Enable for local testing only + // TestFile.Create(TestImages.Jpeg.Baseline.Bad.ExifUndefType), // Perf: Enable for local testing only // TestFile.Create(TestImages.Jpeg.Progressive.Fb), // Perf: Enable for local testing only // TestFile.Create(TestImages.Jpeg.Progressive.Progress), // Perf: Enable for local testing only // TestFile.Create(TestImages.Jpeg.Baseline.GammaDalaiLamaGray), // Perf: Enable for local testing only diff --git a/tests/ImageSharp.Tests/TestFile.cs b/tests/ImageSharp.Tests/TestFile.cs index b09aff78e..ffcd0b95b 100644 --- a/tests/ImageSharp.Tests/TestFile.cs +++ b/tests/ImageSharp.Tests/TestFile.cs @@ -116,7 +116,7 @@ namespace ImageSharp.Tests /// public string GetFileNameWithoutExtension(object value) { - return this.FileNameWithoutExtension + "-" + value; + return $"{this.FileNameWithoutExtension}-{value}"; } /// @@ -138,7 +138,7 @@ namespace ImageSharp.Tests /// public Image CreateImage(IImageDecoder decoder) { - return Image.Load(this.image.Configuration, this.Bytes, decoder); + return Image.Load(this.GetImage().Configuration, this.Bytes, decoder); } private Image GetImage()