Browse Source

Add test case for tiled gray tiff, deflate compressed with predictor

pull/2878/head
Brian Popow 1 year ago
parent
commit
e3c747158d
  1. 27
      src/ImageSharp/Formats/Tiff/Compression/HorizontalPredictor.cs
  2. 1
      tests/ImageSharp.Tests/Formats/Tiff/TiffDecoderTests.cs
  3. 1
      tests/ImageSharp.Tests/TestImages.cs
  4. 3
      tests/Images/Input/Tiff/tiled_gray_deflate_compressed_predictor.tiff

27
src/ImageSharp/Formats/Tiff/Compression/HorizontalPredictor.cs

@ -67,6 +67,11 @@ internal static class HorizontalPredictor
// TODO: Implement missing colortypes, see above.
switch (colorType)
{
case TiffColorType.BlackIsZero8:
case TiffColorType.WhiteIsZero8:
case TiffColorType.PaletteColor:
UndoGray8BitRow(pixelBytes, width, y);
break;
case TiffColorType.Rgb888:
case TiffColorType.CieLab:
UndoRgb24BitRow(pixelBytes, width, y);
@ -168,20 +173,26 @@ internal static class HorizontalPredictor
}
}
private static void UndoGray8BitRow(Span<byte> pixelBytes, int width, int y)
{
int rowBytesCount = width;
int height = pixelBytes.Length / rowBytesCount;
Span<byte> rowBytes = pixelBytes.Slice(y * rowBytesCount, rowBytesCount);
byte pixelValue = rowBytes[0];
for (int x = 1; x < width; x++)
{
pixelValue += rowBytes[x];
rowBytes[x] = pixelValue;
}
}
private static void UndoGray8Bit(Span<byte> pixelBytes, int width)
{
int rowBytesCount = width;
int height = pixelBytes.Length / rowBytesCount;
for (int y = 0; y < height; y++)
{
Span<byte> rowBytes = pixelBytes.Slice(y * rowBytesCount, rowBytesCount);
byte pixelValue = rowBytes[0];
for (int x = 1; x < width; x++)
{
pixelValue += rowBytes[x];
rowBytes[x] = pixelValue;
}
UndoGray8BitRow(pixelBytes, width, y);
}
}

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

@ -89,6 +89,7 @@ public class TiffDecoderTests : TiffDecoderBaseTester
[WithFile(TiledPlanar, PixelTypes.Rgba32)]
[WithFile(TiledRgbaDeflateCompressedWithPredictor, PixelTypes.Rgba32)]
[WithFile(TiledRgbDeflateCompressedWithPredictor, PixelTypes.Rgba32)]
[WithFile(TiledGrayDeflateCompressedWithPredictor, PixelTypes.Rgba32)]
public void TiffDecoder_CanDecode_Tiled<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : unmanaged, IPixel<TPixel> => TestTiffDecoder(provider);

1
tests/ImageSharp.Tests/TestImages.cs

@ -988,6 +988,7 @@ public static class TestImages
public const string TiledPlanar = "Tiff/rgb_uncompressed_tiled_planar.tiff";
public const string TiledRgbaDeflateCompressedWithPredictor = "Tiff/tiled_rgba_deflate_compressed_predictor.tiff";
public const string TiledRgbDeflateCompressedWithPredictor = "Tiff/tiled_rgb_deflate_compressed_predictor.tiff";
public const string TiledGrayDeflateCompressedWithPredictor = "Tiff/tiled_gray_deflate_compressed_predictor.tiff";
// Images with alpha channel.
public const string Rgba2BitUnassociatedAlpha = "Tiff/RgbaUnassociatedAlpha2bit.tiff";

3
tests/Images/Input/Tiff/tiled_gray_deflate_compressed_predictor.tiff

@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:b5133a684a86dbc9ef48f1f988ec505765f086861c96033d350b7565ebd28271
size 52663
Loading…
Cancel
Save