-
-
Notifications
You must be signed in to change notification settings - Fork 867
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Undo horizontal prediction for each tile row in case of tiled tiff's #2878
base: main
Are you sure you want to change the base?
Changes from 1 commit
f72be91
e186c52
787e04d
e3c7471
f11fbc1
47c6755
97133fe
f804ca2
dacb713
dec1dc1
9954f50
71f7d86
5cfa2bc
0a52ee7
7a5be72
8f97280
18f8de9
23cfdd2
85c7ed2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -683,7 +683,8 @@ private void DecodeTilesChunky<TPixel>( | |
Span<byte> tileBufferSpan = tileBuffer.GetSpan(); | ||
Span<byte> uncompressedPixelBufferSpan = uncompressedPixelBuffer.GetSpan(); | ||
|
||
using TiffBaseDecompressor decompressor = this.CreateDecompressor<TPixel>(frame.Width, bitsPerPixel); | ||
bool isTiled = true; | ||
using TiffBaseDecompressor decompressor = this.CreateDecompressor<TPixel>(frame.Width, bitsPerPixel, isTiled); | ||
TiffBaseColorDecoder<TPixel> colorDecoder = this.CreateChunkyColorDecoder<TPixel>(); | ||
|
||
int tileIndex = 0; | ||
|
@@ -712,6 +713,13 @@ private void DecodeTilesChunky<TPixel>( | |
{ | ||
Span<byte> uncompressedPixelRow = uncompressedPixelBufferSpan.Slice(uncompressedPixelBufferOffset, bytesToCopy); | ||
tileBufferSpan.Slice(tileBufferOffset, bytesToCopy).CopyTo(uncompressedPixelRow); | ||
|
||
// Undo the horziontal predictor for each tile row. | ||
if (this.Predictor == TiffPredictor.Horizontal) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @JimBobSquarePants I am not sure, if this is the best approach to undo the predictor here. I tried to do this in HorizontalPredictor.Undo(), but could not figure out a way without replicating the logic to iterate over the tiles in DecodeTilesChunky(). Maybe you have a better idea howto do this? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So, are you writing the row, then undoing the write? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It currently works like this:
The horizontal predictor is used with lzw and deflate compression to achieve better compression. It assumes that neighboring pixel values do not change much and therefore only stores the difference between two consecutive pixels instead the actual pixel values. Because it is tight to lzw and deflate compression, it feels to me this should be the concern of the decompressor and not be handled outside (which is the case for none tiled images). I will try to gather more tiled image test cases for all the different color formats and then see if I can figure out a way how I can move the undoing of the predictor inside the uncompressing method. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah, I understand. I'm just trying to read through TiffLibrary and LibTiff.NET to see how it works there as a reference. I agree the decompressor feels like it should be responsible though. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I have moved undoing the predictor for tiles into the HorizontalPredictor class now with I think it is ready for review. I have gathered as much different example files of tiled tiff I could. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks @brianpopow I'll get on it ASAP |
||
{ | ||
HorizontalPredictor.UndoRow(uncompressedPixelRow, tileLength, 0, this.ColorType); | ||
} | ||
|
||
tileBufferOffset += bytesPerTileRow; | ||
uncompressedPixelBufferOffset += bytesPerRow; | ||
} | ||
|
@@ -750,7 +758,7 @@ private TiffBasePlanarColorDecoder<TPixel> CreatePlanarColorDecoder<TPixel>() | |
this.YcbcrSubSampling, | ||
this.byteOrder); | ||
|
||
private TiffBaseDecompressor CreateDecompressor<TPixel>(int frameWidth, int bitsPerPixel) | ||
private TiffBaseDecompressor CreateDecompressor<TPixel>(int frameWidth, int bitsPerPixel, bool isTiled = false) | ||
where TPixel : unmanaged, IPixel<TPixel> => | ||
TiffDecompressorsFactory.Create( | ||
this.Options, | ||
|
@@ -765,7 +773,8 @@ private TiffBaseDecompressor CreateDecompressor<TPixel>(int frameWidth, int bits | |
this.JpegTables, | ||
this.OldJpegCompressionStartOfImageMarker.GetValueOrDefault(), | ||
this.FillOrder, | ||
this.byteOrder); | ||
this.byteOrder, | ||
isTiled); | ||
|
||
private IMemoryOwner<ulong> ConvertNumbers(Array array, out Span<ulong> span) | ||
{ | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can this switch not happen outside the loop?