Skip to content

Commit 7da6c33

Browse files
authored
Merge pull request #1723 from SixLabors/bp/fixPlanarDecoding
Fix issue calculating the stripIndex for planar tiff's
2 parents 83427f2 + 4f19692 commit 7da6c33

File tree

5 files changed

+16
-2
lines changed

5 files changed

+16
-2
lines changed

src/ImageSharp/Formats/Tiff/TiffDecoderCore.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -272,11 +272,11 @@ private void DecodeStripsPlanar<TPixel>(ImageFrame<TPixel> frame, int rowsPerStr
272272
{
273273
int stripHeight = i < stripsPerPlane - 1 || frame.Height % rowsPerStrip == 0 ? rowsPerStrip : frame.Height % rowsPerStrip;
274274

275+
int stripIndex = i;
275276
for (int planeIndex = 0; planeIndex < stripsPerPixel; planeIndex++)
276277
{
277-
int stripIndex = (i * stripsPerPixel) + planeIndex;
278-
279278
decompressor.Decompress(this.inputStream, (uint)stripOffsets[stripIndex], (uint)stripByteCounts[stripIndex], stripBuffers[planeIndex].GetSpan());
279+
stripIndex += stripsPerPlane;
280280
}
281281

282282
colorDecoder.Decode(stripBuffers, pixels, 0, rowsPerStrip * i, frame.Width, stripHeight);

tests/ImageSharp.Tests/Formats/Tiff/TiffDecoderTests.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,12 @@ public void ByteOrder(string imagePath, ByteOrder expectedByteOrder)
8484
public void TiffDecoder_CanDecode_Uncompressed<TPixel>(TestImageProvider<TPixel> provider)
8585
where TPixel : unmanaged, IPixel<TPixel> => TestTiffDecoder(provider);
8686

87+
[Theory]
88+
[WithFile(FlowerRgb888Planar6Strips, PixelTypes.Rgba32)]
89+
[WithFile(FlowerRgb888Planar15Strips, PixelTypes.Rgba32)]
90+
public void TiffDecoder_Planar<TPixel>(TestImageProvider<TPixel> provider)
91+
where TPixel : unmanaged, IPixel<TPixel> => TestTiffDecoder(provider);
92+
8793
[Theory]
8894
[WithFile(Calliphora_PaletteUncompressed, PixelTypes.Rgba32)]
8995
[WithFile(PaletteDeflateMultistrip, PixelTypes.Rgba32)]

tests/ImageSharp.Tests/TestImages.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -576,6 +576,8 @@ public static class Tiff
576576
public const string FlowerRgb444Planar = "Tiff/flower-rgb-planar-04.tiff";
577577
public const string FlowerRgb222Contiguous = "Tiff/flower-rgb-contig-02.tiff";
578578
public const string FlowerRgb222Planar = "Tiff/flower-rgb-planar-02.tiff";
579+
public const string FlowerRgb888Planar6Strips = "Tiff/flower-rgb-planar-08-6strips.tiff";
580+
public const string FlowerRgb888Planar15Strips = "Tiff/flower-rgb-planar-08-15strips.tiff";
579581
public const string Flower2BitGray = "Tiff/flower-minisblack-02.tiff";
580582
public const string Flower2BitPalette = "Tiff/flower-palette-02.tiff";
581583
public const string Flower4BitPalette = "Tiff/flower-palette-04.tiff";
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
version https://git-lfs.github.com/spec/v1
2+
oid sha256:a49cf47fdf2ea43e5cb5a473523e50222fb13ff6a66bda2e4bdd5796f66140d8
3+
size 9770
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
version https://git-lfs.github.com/spec/v1
2+
oid sha256:a49cf47fdf2ea43e5cb5a473523e50222fb13ff6a66bda2e4bdd5796f66140d8
3+
size 9770

0 commit comments

Comments
 (0)