Skip to content

Commit

Permalink
Merge pull request #1457 from IldarKhayrutdinov/tiff-format
Browse files Browse the repository at this point in the history
#12 Tiff specific fixes for LZW
  • Loading branch information
brianpopow authored Dec 3, 2020
2 parents a1aec8c + 239cc2f commit d386a9f
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 7 deletions.
4 changes: 1 addition & 3 deletions src/ImageSharp/Formats/Tiff/Utils/TiffLzwDecoder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -168,14 +168,12 @@ public void DecodePixels(int length, int dataSize, Span<byte> pixels)

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;
Expand Down
12 changes: 10 additions & 2 deletions tests/ImageSharp.Tests/Formats/Tiff/TiffDecoderTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ public void Identify(string imagePath, int expectedPixelSize, int expectedWidth,
}

[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);
Expand Down Expand Up @@ -91,6 +91,7 @@ public void TiffDecoder_CanDecode_Uncompressed<TPixel>(TestImageProvider<TPixel>

[Theory]
[WithFile(Calliphora_PaletteUncompressed, PixelTypes.Rgba32)]
[WithFile(PaletteDeflateMultistrip, PixelTypes.Rgba32)]
[WithFile(RgbPalette, PixelTypes.Rgba32)]
[WithFile(RgbPaletteDeflate, PixelTypes.Rgba32)]
[WithFile(PaletteUncompressed, PixelTypes.Rgba32)]
Expand All @@ -101,11 +102,14 @@ public void TiffDecoder_CanDecode_WithPalette<TPixel>(TestImageProvider<TPixel>
}

[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<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : unmanaged, IPixel<TPixel>
{
Expand All @@ -115,6 +119,9 @@ public void TiffDecoder_CanDecode_DeflateCompressed<TPixel>(TestImageProvider<TP
[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<TPixel>(TestImageProvider<TPixel> provider)
Expand Down Expand Up @@ -147,6 +154,7 @@ public void TiffDecoder_CanDecode_Fax3Compressed<TPixel>(TestImageProvider<TPixe
[Theory]
[WithFile(Calliphora_RgbPackbits, PixelTypes.Rgba32)]
[WithFile(RgbPackbits, PixelTypes.Rgba32)]
[WithFile(RgbPackbitsMultistrip, PixelTypes.Rgba32)]
public void TiffDecoder_CanDecode_PackBitsCompressed<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : unmanaged, IPixel<TPixel>
{
Expand Down
4 changes: 2 additions & 2 deletions tests/ImageSharp.Tests/TestImages.cs
Original file line number Diff line number Diff line change
Expand Up @@ -558,11 +558,11 @@ public static class Tiff

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 };
}
}
}

0 comments on commit d386a9f

Please sign in to comment.