Fix data loss / assert when encoding tiles with empty resolution levels - #1657
Open
nico wants to merge 1 commit into
Open
Fix data loss / assert when encoding tiles with empty resolution levels#1657nico wants to merge 1 commit into
nico wants to merge 1 commit into
Conversation
When a tile is narrow but the number of decomposition levels is large, some of its lower resolution levels can become empty. Neither 5/3 not 9/7 DWT handled zero-length inputs correctly: - opj_dwt_encode_and_deinterleave_h_one_row (5/3, lossless): The `if (even)` branch correctly checks `if (width > 1)`, but the else branch for the odd case special-cased `width == 1` and then just had an `else` branch on that. This caused width == 0 to be handled incorrectly. This is similar to the `if (even)` branch just above, and also similar to inverse opj_idwt53_h with its `if (len > 1)`. Fixes uclouvain#1575. - opj_dwt_encode_and_deinterleave_h_one_row_real (9/7, lossy): only returned early for width == 1, so for width == 0 it called opj_dwt_encode_1_real() with dn == sn == 0. This tripped the `assert(dn + sn > 1)` therein in debug builds. Return early for `width <= 1`, to handle empty tiles too. Before this commit, reproduced with a 119x53 grayscale image: width 119 with `-t 117` leaves a 2-pixel-wide right edge tile, and `-n 5` makes that tile's three lowest resolution levels empty: # lossless: cols 117-118 corrupted opj_compress -i in.pgm -o out.jp2 -n 5 -t 117,53 # lossy: assert abort in debug builds opj_compress -i in.pgm -o out.jp2 -n 5 -t 117,53 -I
Contributor
Author
|
I have a roundtrip test for this too, but I'll put it in a separate PR in case the fix is easier to merge than the test for some reason. |
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.
When a tile is narrow but the number of decomposition levels is large, some of its lower resolution levels can become empty. Neither 5/3 not 9/7 DWT handled zero-length inputs correctly:
opj_dwt_encode_and_deinterleave_h_one_row (5/3, lossless): The
if (even)branch correctly checksif (width > 1), but the else branch for the odd case special-casedwidth == 1and then just had anelsebranch on that. This caused width == 0 to be handled incorrectly. This is similar to theif (even)branch just above, and also similar to inverse opj_idwt53_h with itsif (len > 1). Fixesopj_compresssometimes loses data when encoding in lossless mode #1575.opj_dwt_encode_and_deinterleave_h_one_row_real (9/7, lossy): only returned early for width == 1, so for width == 0 it called opj_dwt_encode_1_real() with dn == sn == 0. This tripped the
assert(dn + sn > 1)therein in debug builds. Return early forwidth <= 1, to handle empty tiles too.Before this commit, reproduced with a 119x53 grayscale image: width 119 with
-t 117leaves a 2-pixel-wide right edge tile, and-n 5makes that tile's three lowest resolution levels empty: