Repository navigation
Fix lines left unconverted for NLT type 0 and unsigned type 3 - #421
Merged
Merged
Conversation
Since aous72#356, tile::push() and tile::pull() pick the sample converter of a component by the type of its NLT record: the plain converter when there is no record, the type 3 converter for type 3 (for signed samples only on the reversible path), and the LUT converter for types 2 and 4. Before cases now match no branch, so no converter runs and the line keeps whatever its buffer held before: - a type 0 (no nonlinearity) record, which param_nlt::read() accepts and set_nonlinear_transform(c, OJPH_NLT_NO_NLT) writes for a component that should not use the nonlinearity of the other components; - type 3 on an unsigned component that uses the reversible path. On decoding, the output lines of such a component are never written, so the application receives the uninitialized contents of the line buffers allocated in codestream::finalize_alloc() instead of the decoded samples; MemorySanitizer reports their use. On encoding, the codestream is built from the uninitialized contents of the tile's lines. Set nlt_ptr to NULL for both cases in tile::finalize_alloc(), so that every dispatch in push() and pull(), with and without the colour transform, uses the plain converter for them, as before aous72#356. Add three tests to tests/test_nlt.cpp: - TypeZeroRecordOfOneComponentKeepsSamples: type 3 for all components and type 0 for one of them; that component decodes to the same samples as without a nonlinearity, and the reversible round trip is lossless. - TypeZeroMarkerSegmentKeepsSamples: a codestream with an inserted type 0 NLT marker segment decodes to the same samples as without it. - BinaryComplementOfUnsignedSamplesIsLossless: a reversible round trip of 8-bit unsigned samples with type 3 is lossless, with and without the colour transform and with and without a type 0 component. The encoding and decoding helpers of the test use interleaved lines when the colour transform is employed, as the library requires. All three tests fail without this change and pass with it; the rest of the test suite passes.
Owner
|
Hi Mar, Thank you for this PR. It was an oversight. Kind regards, |
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.
Since #356,
tile::push()andtile::pull()choose a component's sample converter by the type of its NLT record:Before #356, the plain converter was the fallback for everything else. Two cases now match no branch, so no converter runs and the line keeps whatever its buffer held before:
param_nlt::read()accepts one, andset_nonlinear_transform(c, OJPH_NLT_NO_NLT)writes one for a component that should not use the other components' nonlinearity.When decoding, the output lines of such a component are never written. The application gets the uninitialized contents of the line buffers allocated in
codestream::finalize_alloc()instead of the decoded samples, and MemorySanitizer reports their use. When encoding, the codestream is built from the uninitialized contents of the tile's lines.Change
tile::finalize_alloc()now setsnlt_ptrtoNULLin both cases. Every dispatch inpush()andpull()then uses the plain converter for them, with and without the colour transform, as before #356. I put the fix in one place instead of adding anelseto each of the eight dispatches, because the reversible ones would each need the sign-dependent shift repeated. Irreversible type 3 is left unchanged.Tests (
tests/test_nlt.cpp)TypeZeroRecordOfOneComponentKeepsSamples: all components get type 3 except one, which gets type 0. That component decodes to the same samples as without a nonlinearity, and the reversible round trip is lossless.TypeZeroMarkerSegmentKeepsSamples: a codestream with an inserted type 0 NLT marker segment decodes to the same samples as without it, with both wavelets.BinaryComplementOfUnsignedSamplesIsLossless: a reversible round trip of 8-bit unsigned samples with type 3 is lossless. It is checked with and without the colour transform, and with and without one component on type 0.When the colour transform is employed, the test's encode and decode helpers now exchange lines interleaved, as the library requires.
All three tests fail without the change; for example, more than 12230 of 12288 samples are wrong in every case of the last test. With the change they pass, and the whole
ctestsuite passes (138/138).test_nltalso passes under MemorySanitizer.This is the change of #408, which is no longer reachable, rebased on the current
master.