Browse Source

Tiff decoder can now handle special case, when rowsPerStrip has the default value

pull/1570/head
Brian Popow 5 years ago
parent
commit
7d51106880
  1. 11
      src/ImageSharp/Formats/Tiff/TiffDecoderCore.cs
  2. 1
      tests/ImageSharp.Tests/Formats/Tiff/TiffDecoderTests.cs
  3. 1
      tests/ImageSharp.Tests/TestImages.cs
  4. 3
      tests/Images/Input/Tiff/ccitt_fax3_uncompressed.tiff

11
src/ImageSharp/Formats/Tiff/TiffDecoderCore.cs

@ -34,6 +34,11 @@ namespace SixLabors.ImageSharp.Formats.Experimental.Tiff
/// </summary>
private BufferedReadStream inputStream;
/// <summary>
/// RowsPerStrip default value, which is effectively infinity.
/// </summary>
private const int RowsPerStripInfinity = 2147483647;
/// <summary>
/// Initializes a new instance of the <see cref="TiffDecoderCore" /> class.
/// </summary>
@ -281,6 +286,12 @@ namespace SixLabors.ImageSharp.Formats.Experimental.Tiff
private void DecodeStripsChunky<TPixel>(ImageFrame<TPixel> frame, int rowsPerStrip, Number[] stripOffsets, Number[] stripByteCounts, int width)
where TPixel : unmanaged, IPixel<TPixel>
{
// If the rowsPerStrip has the default value, which is effectively infinity. That is, the entire image is one strip.
if (rowsPerStrip == RowsPerStripInfinity)
{
rowsPerStrip = frame.Height;
}
int uncompressedStripSize = this.CalculateStripBufferSize(frame.Width, rowsPerStrip);
int bitsPerPixel = this.BitsPerPixel;

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

@ -137,6 +137,7 @@ namespace SixLabors.ImageSharp.Tests.Formats.Tiff
[WithFile(CcittFax3AllMakeupCodes, PixelTypes.Rgba32)]
[WithFile(Calliphora_Fax3Compressed, PixelTypes.Rgba32)]
[WithFile(Calliphora_Fax3Compressed_WithEolPadding, PixelTypes.Rgba32)]
[WithFile(Fax3Uncompressed, PixelTypes.Rgba32)]
public void TiffDecoder_CanDecode_Fax3Compressed<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : unmanaged, IPixel<TPixel> => TestTiffDecoder(provider);

1
tests/ImageSharp.Tests/TestImages.cs

@ -522,6 +522,7 @@ namespace SixLabors.ImageSharp.Tests
public const string Calliphora_RgbPackbits = "Tiff/Calliphora_rgb_packbits.tiff";
public const string Calliphora_RgbUncompressed = "Tiff/Calliphora_rgb_uncompressed.tiff";
public const string Calliphora_Fax3Compressed = "Tiff/Calliphora_ccitt_fax3.tiff";
public const string Fax3Uncompressed = "Tiff/ccitt_fax3_uncompressed.tiff";
public const string Calliphora_Fax3Compressed_WithEolPadding = "Tiff/Calliphora_ccitt_fax3_with_eol_padding.tiff";
public const string Calliphora_Fax4Compressed = "Tiff/Calliphora_ccitt_fax4.tiff";
public const string Calliphora_HuffmanCompressed = "Tiff/Calliphora_huffman_rle.tiff";

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

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