Browse Source

Fix issue with huffman RLE where last bits of a row could get ignored

pull/1570/head
Brian Popow 6 years ago
parent
commit
73fdeee347
  1. 18
      src/ImageSharp/Formats/Tiff/Compression/T4BitReader.cs
  2. 3
      src/ImageSharp/Formats/Tiff/README.md
  3. 5
      tests/ImageSharp.Tests/TestImages.cs
  4. 3
      tests/Images/Input/Tiff/basi3p02_huffman_rle.tiff

18
src/ImageSharp/Formats/Tiff/Compression/T4BitReader.cs

@ -253,7 +253,18 @@ namespace SixLabors.ImageSharp.Formats.Experimental.Tiff.Compression
/// <summary> /// <summary>
/// Gets a value indicating whether there is more data to read left. /// Gets a value indicating whether there is more data to read left.
/// </summary> /// </summary>
public bool HasMoreData => this.position < (ulong)this.dataLength - 1; public bool HasMoreData
{
get
{
if (this.isModifiedHuffmanRle)
{
return this.position < (ulong)this.dataLength - 1 || (this.bitsRead > 0 && this.bitsRead < 7);
}
return this.position < (ulong)this.dataLength - 1;
}
}
/// <summary> /// <summary>
/// Gets a value indicating whether the current run is a white pixel run, otherwise its a black pixel run. /// Gets a value indicating whether the current run is a white pixel run, otherwise its a black pixel run.
@ -381,10 +392,7 @@ namespace SixLabors.ImageSharp.Formats.Experimental.Tiff.Compression
} }
/// <inheritdoc/> /// <inheritdoc/>
public void Dispose() public void Dispose() => this.Data.Dispose();
{
this.Data.Dispose();
}
private uint WhiteTerminatingCodeRunLength() private uint WhiteTerminatingCodeRunLength()
{ {

3
src/ImageSharp/Formats/Tiff/README.md

@ -28,8 +28,7 @@
### Know issue which need to be fixed ### Know issue which need to be fixed
Decoder: Decoder:
- Decoding HUffman RLE for `Calliphora_huffman_rle.tiff` has 4 pixels difference to the reference decoder. Al those are at the very edge of the image (reason unknown so far). - Decoding compressed images with HorizontalPrediction: Works for deflate, but not for lzw (maybe an issue with lzw itself?).
- Decoding compressed images with HorizontalPrediction: Works for deflate, but not for lzw.
### Deviations from the TIFF spec (to be fixed) ### Deviations from the TIFF spec (to be fixed)

5
tests/ImageSharp.Tests/TestImages.cs

@ -522,6 +522,9 @@ namespace SixLabors.ImageSharp.Tests
public const string HuffmanRleAllTermCodes = "Tiff/huffman_rle_all_terminating_codes.tiff"; public const string HuffmanRleAllTermCodes = "Tiff/huffman_rle_all_terminating_codes.tiff";
public const string HuffmanRleAllMakeupCodes = "Tiff/huffman_rle_all_makeup_codes.tiff"; public const string HuffmanRleAllMakeupCodes = "Tiff/huffman_rle_all_makeup_codes.tiff";
// Test case for an issue, that the last bits in a row got ignored.
public const string HuffmanRle_basi3p02 = "Tiff/basi3p02_huffman_rle.tiff";
public const string GrayscaleDeflateMultistrip = "Tiff/grayscale_deflate_multistrip.tiff"; public const string GrayscaleDeflateMultistrip = "Tiff/grayscale_deflate_multistrip.tiff";
public const string GrayscaleUncompressed = "Tiff/grayscale_uncompressed.tiff"; public const string GrayscaleUncompressed = "Tiff/grayscale_uncompressed.tiff";
public const string PaletteDeflateMultistrip = "Tiff/palette_grayscale_deflate_multistrip.tiff"; public const string PaletteDeflateMultistrip = "Tiff/palette_grayscale_deflate_multistrip.tiff";
@ -558,7 +561,7 @@ namespace SixLabors.ImageSharp.Tests
Calliphora_GrayscaleDeflate_Predictor, Calliphora_RgbDeflate_Predictor, RgbDeflatePredictor, Calliphora_GrayscaleDeflate_Predictor, Calliphora_RgbDeflate_Predictor, RgbDeflatePredictor,
Calliphora_RgbLzw_Predictor, RgbLzwPredictor, // TODO: Undoing the horizontal prediction seems to fail for lzw. Do we need to do something different for lzw? Calliphora_RgbLzw_Predictor, RgbLzwPredictor, // TODO: Undoing the horizontal prediction seems to fail for lzw. Do we need to do something different for lzw?
Calliphora_BiColor, Calliphora_RgbUncompressed, Calliphora_HuffmanCompressed, Calliphora_Fax3Compressed, CcittFax3AllTermCodes, CcittFax3AllMakeupCodes, Calliphora_BiColor, Calliphora_RgbUncompressed, Calliphora_HuffmanCompressed, Calliphora_Fax3Compressed, CcittFax3AllTermCodes, CcittFax3AllMakeupCodes,
HuffmanRleAllTermCodes, HuffmanRleAllMakeupCodes, GrayscaleDeflateMultistrip, Calliphora_GrayscaleDeflate, Calliphora_GrayscaleUncompressed, HuffmanRleAllTermCodes, HuffmanRleAllMakeupCodes, HuffmanRle_basi3p02, GrayscaleDeflateMultistrip, Calliphora_GrayscaleDeflate, Calliphora_GrayscaleUncompressed,
GrayscaleUncompressed, PaletteDeflateMultistrip, PaletteUncompressed, RgbDeflateMultistrip, /*RgbJpeg,*/ /* RgbLzwMultistrip_Predictor,*/ GrayscaleUncompressed, PaletteDeflateMultistrip, PaletteUncompressed, RgbDeflateMultistrip, /*RgbJpeg,*/ /* RgbLzwMultistrip_Predictor,*/
RgbLzwNoPredictorMultistrip, RgbLzwNoPredictorMultistripMotorola, RgbLzwNoPredictorSinglestripMotorola, RgbPackbits, RgbPackbitsMultistrip, RgbUncompressed, RgbLzwNoPredictorMultistrip, RgbLzwNoPredictorMultistripMotorola, RgbLzwNoPredictorSinglestripMotorola, RgbPackbits, RgbPackbitsMultistrip, RgbUncompressed,
/* MultiframeLzw_Predictor, MultiFrameDifferentVariants, SampleMetadata,*/ SmallRgbDeflate, SmallRgbLzw, RgbLzwNoPredictor /* MultiframeLzw_Predictor, MultiFrameDifferentVariants, SampleMetadata,*/ SmallRgbDeflate, SmallRgbLzw, RgbLzwNoPredictor

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

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