From 624a36c0248d7f6d247791ef847b750c15d27794 Mon Sep 17 00:00:00 2001 From: Ildar Khayrutdinov Date: Thu, 3 Dec 2020 20:48:35 +0300 Subject: [PATCH 1/2] #12 Tiff specific fixes for lzw --- src/ImageSharp/Formats/Tiff/Utils/TiffLzwDecoder.cs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/ImageSharp/Formats/Tiff/Utils/TiffLzwDecoder.cs b/src/ImageSharp/Formats/Tiff/Utils/TiffLzwDecoder.cs index ddd63b910..1ce99980a 100644 --- a/src/ImageSharp/Formats/Tiff/Utils/TiffLzwDecoder.cs +++ b/src/ImageSharp/Formats/Tiff/Utils/TiffLzwDecoder.cs @@ -168,14 +168,12 @@ namespace SixLabors.ImageSharp.Formats.Experimental.Tiff.Utils pixelStack[top++] = suffix[code]; - // Fix for Gifs that have "deferred clear code" as per here : - // https://bugzilla.mozilla.org/show_bug.cgi?id=55918 if (availableCode < MaxStackSize) { prefix[availableCode] = oldCode; suffix[availableCode] = first; availableCode++; - if (availableCode == codeMask + 1 && availableCode < MaxStackSize) + if (availableCode > codeMask - 1 && availableCode < MaxStackSize) { codeSize++; codeMask = (1 << codeSize) - 1; From 3a4c0d007ef921abd55528c7b30051fdcbd0a1ff Mon Sep 17 00:00:00 2001 From: Ildar Khayrutdinov Date: Thu, 3 Dec 2020 22:07:10 +0300 Subject: [PATCH 2/2] Perform tests files --- .../Formats/Tiff/TiffDecoderTests.cs | 12 ++++++++++-- tests/ImageSharp.Tests/TestImages.cs | 4 ++-- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/tests/ImageSharp.Tests/Formats/Tiff/TiffDecoderTests.cs b/tests/ImageSharp.Tests/Formats/Tiff/TiffDecoderTests.cs index a78a34939..c5e09b65e 100644 --- a/tests/ImageSharp.Tests/Formats/Tiff/TiffDecoderTests.cs +++ b/tests/ImageSharp.Tests/Formats/Tiff/TiffDecoderTests.cs @@ -59,8 +59,8 @@ namespace SixLabors.ImageSharp.Tests.Formats.Tiff } [Theory] - [InlineData(TestImages.Tiff.RgbLzwNoPredictorMultistrip, TiffByteOrder.LittleEndian)] - [InlineData(TestImages.Tiff.RgbLzwNoPredictorMultistripMotorola, TiffByteOrder.BigEndian)] + [InlineData(RgbLzwNoPredictorMultistrip, TiffByteOrder.LittleEndian)] + [InlineData(RgbLzwNoPredictorMultistripMotorola, TiffByteOrder.BigEndian)] public void ByteOrder(string imagePath, TiffByteOrder expectedByteOrder) { var testFile = TestFile.Create(imagePath); @@ -91,6 +91,7 @@ namespace SixLabors.ImageSharp.Tests.Formats.Tiff [Theory] [WithFile(Calliphora_PaletteUncompressed, PixelTypes.Rgba32)] + [WithFile(PaletteDeflateMultistrip, PixelTypes.Rgba32)] [WithFile(RgbPalette, PixelTypes.Rgba32)] [WithFile(RgbPaletteDeflate, PixelTypes.Rgba32)] [WithFile(PaletteUncompressed, PixelTypes.Rgba32)] @@ -101,11 +102,14 @@ namespace SixLabors.ImageSharp.Tests.Formats.Tiff } [Theory] + [WithFile(GrayscaleDeflateMultistrip, PixelTypes.Rgba32)] + [WithFile(RgbDeflateMultistrip, PixelTypes.Rgba32)] [WithFile(Calliphora_GrayscaleDeflate, PixelTypes.Rgba32)] [WithFile(Calliphora_GrayscaleDeflate_Predictor, PixelTypes.Rgba32)] [WithFile(Calliphora_RgbDeflate_Predictor, PixelTypes.Rgba32)] [WithFile(RgbDeflate, PixelTypes.Rgba32)] [WithFile(RgbDeflatePredictor, PixelTypes.Rgba32)] + [WithFile(SmallRgbDeflate, PixelTypes.Rgba32)] public void TiffDecoder_CanDecode_DeflateCompressed(TestImageProvider provider) where TPixel : unmanaged, IPixel { @@ -115,6 +119,9 @@ namespace SixLabors.ImageSharp.Tests.Formats.Tiff [Theory] [WithFile(RgbLzwPredictor, PixelTypes.Rgba32)] [WithFile(RgbLzwNoPredictor, PixelTypes.Rgba32)] + [WithFile(RgbLzwNoPredictorSinglestripMotorola, PixelTypes.Rgba32)] + [WithFile(RgbLzwNoPredictorMultistripMotorola, PixelTypes.Rgba32)] + [WithFile(RgbLzwMultistripPredictor, PixelTypes.Rgba32)] [WithFile(Calliphora_RgbLzw_Predictor, PixelTypes.Rgba32)] [WithFile(SmallRgbLzw, PixelTypes.Rgba32)] public void TiffDecoder_CanDecode_LzwCompressed(TestImageProvider provider) @@ -147,6 +154,7 @@ namespace SixLabors.ImageSharp.Tests.Formats.Tiff [Theory] [WithFile(Calliphora_RgbPackbits, PixelTypes.Rgba32)] [WithFile(RgbPackbits, PixelTypes.Rgba32)] + [WithFile(RgbPackbitsMultistrip, PixelTypes.Rgba32)] public void TiffDecoder_CanDecode_PackBitsCompressed(TestImageProvider provider) where TPixel : unmanaged, IPixel { diff --git a/tests/ImageSharp.Tests/TestImages.cs b/tests/ImageSharp.Tests/TestImages.cs index a6a94c692..ef46e2289 100644 --- a/tests/ImageSharp.Tests/TestImages.cs +++ b/tests/ImageSharp.Tests/TestImages.cs @@ -558,11 +558,11 @@ namespace SixLabors.ImageSharp.Tests public const string SampleMetadata = "Tiff/metadata_sample.tiff"; - public static readonly string[] Multiframes = { MultiframeDeflateWithPreview /*MultiframeLzw_Predictor, MultiFrameDifferentSize, MultiframeDifferentSizeTiled, MultiFrameDifferentVariants,*/ }; + public static readonly string[] Multiframes = { MultiframeDeflateWithPreview, MultiframeLzwPredictor /*, MultiFrameDifferentSize, MultiframeDifferentSizeTiled, MultiFrameDifferentVariants,*/ }; public static readonly string[] Metadata = { SampleMetadata }; - public static readonly string[] NotSupported = { Calliphora_RgbJpeg, RgbLzwMultistripPredictor, RgbJpeg, RgbUncompressedTiled, MultiframeLzwPredictor, MultiframeDifferentSize, MultiframeDifferentVariants }; + public static readonly string[] NotSupported = { Calliphora_RgbJpeg, RgbJpeg, RgbUncompressedTiled, MultiframeDifferentSize, MultiframeDifferentVariants }; } } }