From e186c52f32d23f379e70783436e390cf5c1eaa9f Mon Sep 17 00:00:00 2001 From: Brian Popow Date: Mon, 3 Feb 2025 19:39:36 +0100 Subject: [PATCH] Add test case for tiled tiff, deflate compressed with predictor --- src/ImageSharp/Formats/Tiff/TiffDecoderCore.cs | 3 ++- tests/ImageSharp.Tests/Formats/Tiff/TiffDecoderTests.cs | 1 + tests/ImageSharp.Tests/TestImages.cs | 1 + .../Input/Tiff/tiled_rgba_deflate_compressed_predictor.tiff | 3 +++ 4 files changed, 7 insertions(+), 1 deletion(-) create mode 100644 tests/Images/Input/Tiff/tiled_rgba_deflate_compressed_predictor.tiff diff --git a/src/ImageSharp/Formats/Tiff/TiffDecoderCore.cs b/src/ImageSharp/Formats/Tiff/TiffDecoderCore.cs index 43d7944eab..1c15646970 100644 --- a/src/ImageSharp/Formats/Tiff/TiffDecoderCore.cs +++ b/src/ImageSharp/Formats/Tiff/TiffDecoderCore.cs @@ -717,7 +717,8 @@ internal class TiffDecoderCore : ImageDecoderCore // Undo the horziontal predictor for each tile row. if (this.Predictor == TiffPredictor.Horizontal) { - HorizontalPredictor.UndoRow(uncompressedPixelRow, tileLength, 0, this.ColorType); + int pixelsInTileRow = isLastHorizontalTile ? remainingPixelsInRow : tileLength; + HorizontalPredictor.UndoRow(uncompressedPixelRow, pixelsInTileRow, 0, this.ColorType); } tileBufferOffset += bytesPerTileRow; diff --git a/tests/ImageSharp.Tests/Formats/Tiff/TiffDecoderTests.cs b/tests/ImageSharp.Tests/Formats/Tiff/TiffDecoderTests.cs index 09cfe2cbea..ed6bad03aa 100644 --- a/tests/ImageSharp.Tests/Formats/Tiff/TiffDecoderTests.cs +++ b/tests/ImageSharp.Tests/Formats/Tiff/TiffDecoderTests.cs @@ -87,6 +87,7 @@ public class TiffDecoderTests : TiffDecoderBaseTester [WithFile(QuadTile, PixelTypes.Rgba32)] [WithFile(TiledChunky, PixelTypes.Rgba32)] [WithFile(TiledPlanar, PixelTypes.Rgba32)] + [WithFile(TiledDeflateCompressedWithPredictor, PixelTypes.Rgba32)] public void TiffDecoder_CanDecode_Tiled(TestImageProvider provider) where TPixel : unmanaged, IPixel => TestTiffDecoder(provider); diff --git a/tests/ImageSharp.Tests/TestImages.cs b/tests/ImageSharp.Tests/TestImages.cs index 4130474b58..cea4e3059f 100644 --- a/tests/ImageSharp.Tests/TestImages.cs +++ b/tests/ImageSharp.Tests/TestImages.cs @@ -986,6 +986,7 @@ public static class TestImages public const string QuadTile = "Tiff/quad-tile.tiff"; public const string TiledChunky = "Tiff/rgb_uncompressed_tiled_chunky.tiff"; public const string TiledPlanar = "Tiff/rgb_uncompressed_tiled_planar.tiff"; + public const string TiledDeflateCompressedWithPredictor = "Tiff/tiled_rgba_deflate_compressed_predictor.tiff"; // Images with alpha channel. public const string Rgba2BitUnassociatedAlpha = "Tiff/RgbaUnassociatedAlpha2bit.tiff"; diff --git a/tests/Images/Input/Tiff/tiled_rgba_deflate_compressed_predictor.tiff b/tests/Images/Input/Tiff/tiled_rgba_deflate_compressed_predictor.tiff new file mode 100644 index 0000000000..f30e29ec85 --- /dev/null +++ b/tests/Images/Input/Tiff/tiled_rgba_deflate_compressed_predictor.tiff @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:c4f44a67086fafc1d8784922a491e0b944b4afcd09f14b66d951b042d2745e0c +size 166487