Browse Source

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

pull/1457/head
Brian Popow 6 years ago
parent
commit
0bb0ab0c00
  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. BIN
      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>
/// Gets a value indicating whether there is more data to read left.
/// </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>
/// 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/>
public void Dispose()
{
this.Data.Dispose();
}
public void Dispose() => this.Data.Dispose();
private uint WhiteTerminatingCodeRunLength()
{

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

@ -28,8 +28,7 @@
### Know issue which need to be fixed
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.
- Decoding compressed images with HorizontalPrediction: Works for deflate, but not for lzw (maybe an issue with lzw itself?).
### 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 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 GrayscaleUncompressed = "Tiff/grayscale_uncompressed.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_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,
HuffmanRleAllTermCodes, HuffmanRleAllMakeupCodes, GrayscaleDeflateMultistrip, Calliphora_GrayscaleDeflate, Calliphora_GrayscaleUncompressed,
HuffmanRleAllTermCodes, HuffmanRleAllMakeupCodes, HuffmanRle_basi3p02, GrayscaleDeflateMultistrip, Calliphora_GrayscaleDeflate, Calliphora_GrayscaleUncompressed,
GrayscaleUncompressed, PaletteDeflateMultistrip, PaletteUncompressed, RgbDeflateMultistrip, /*RgbJpeg,*/ /* RgbLzwMultistrip_Predictor,*/
RgbLzwNoPredictorMultistrip, RgbLzwNoPredictorMultistripMotorola, RgbLzwNoPredictorSinglestripMotorola, RgbPackbits, RgbPackbitsMultistrip, RgbUncompressed,
/* MultiframeLzw_Predictor, MultiFrameDifferentVariants, SampleMetadata,*/ SmallRgbDeflate, SmallRgbLzw, RgbLzwNoPredictor

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

Binary file not shown.
Loading…
Cancel
Save