Repository navigation
fix(j2k): write the last row of output buffers without trailing padding - #313
Merged
Merged
Conversation
The packed 8- and 16-bit writers zipped the source rows with `out.chunks_exact_mut(stride)`. Buffer validation accepts a buffer of `strided_output_len` bytes, `stride * (height - 1) + row_bytes`, which has no padding after the last row; with a stride wider than the row, that last row is a partial chunk, `chunks_exact_mut` drops it, and the decode returned Ok with the row unwritten. This hit full-image and scaled 8-bit decodes at such a stride (row copies, RGB to RGBA and RGBA to RGB) and every 16-bit decode at one, regions included. The 8-bit region row sink and the component-plane writers already index rows and were not affected. The five loops now take their rows from one helper that chunks by stride and keeps the last, shorter chunk, sliced to the row's bytes as before. The loops are otherwise unchanged. A new decode test writes every 8- and 16-bit format of gray, RGB and RGBA images at 8 and 12 bits, full, region, scaled and region-scaled, serial and parallel, into a buffer of exactly `strided_output_len` bytes and compares it with a decode into a padded buffer: 96 of its 160 cases lost the last row before this change.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The packed 8- and 16-bit writers zipped the source rows with
out.chunks_exact_mut(stride). Buffer validation accepts a buffer ofstrided_output_lenbytes,stride * (height - 1) + row_bytes, whichhas no padding after the last row; with a stride wider than the row, that
last row is a partial chunk,
chunks_exact_mutdrops it, and the decodereturned Ok with the row unwritten. This hit full-image and scaled 8-bit
decodes at such a stride (row copies, RGB to RGBA and RGBA to RGB) and
every 16-bit decode at one, regions included. The 8-bit region row sink and
the component-plane writers already index rows and were not affected.
The five loops now take their rows from one helper that chunks by stride
and keeps the last, shorter chunk, sliced to the row's bytes as before.
The loops are otherwise unchanged.
A new decode test writes every 8- and 16-bit format of gray, RGB and RGBA
images at 8 and 12 bits, full, region, scaled and region-scaled, serial
and parallel, into a buffer of exactly
strided_output_lenbytes andcompares it with a decode into a padded buffer: 96 of its 160 cases lost
the last row before this change.
Validation