Repository navigation
Conversation
… the pixel type A non-standard maxval was applied with a brightness pass after the samples had been converted to the destination pixel type. A 16-bit sample with a small maxval was narrowed to 8 bits first, so decoding to an 8-bit pixel type such as the default Rgb24 kept only a few distinct levels (maxval 1000 gave five). The plain and binary decoders now scale every sample from [0, maxval] to the full 8-bit or 16-bit range with rounded integer arithmetic before the pixel conversion, and the extra brightness pass over the image is removed.
4 tasks done
This branch has not been deployed
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.
Prerequisites
Description
Problem
The decoder handled a maxval other than 255 or 65535 in two steps:
Brightnesspass over the whole image.Step 2 happened after any loss of precision in step 1. A 16-bit sample with a small maxval was narrowed to 8 bits before it was scaled. As a result, decoding to an 8-bit pixel type, such as
Rgb24(the default forImage.Load), kept only a few distinct levels. For example, with maxval 1000:Change
[0, maxval]to the full 8-bit or 16-bit range before they convert the row to the pixel type.PbmSampleScaler.Scalemethod does the scaling for both decoders.Brightnesspass over the decoded image is removed. Images with a non-standard maxval now need one pass less.Testing
The new theory
Decode_NonStandardMaxPixelValue_ScalesSamplesToByteRangeinPbmDecoderTestscovers P2, P3, P5 and P6 with maxval 100 and 1000. It decodes toRgb24and compares each component withround(sample * 255 / maxval), with a tolerance of one step. The test inputs are built in memory.On
main, the four maxval 1000 cases fail and the maxval 100 cases pass. With this change, all eight cases pass.I ran all tests in the Pbm namespace in Release on net10.0: 121 passed. These include the existing reference-image comparisons for maxval 15 inputs and the round-trip tests.
Fixes #3239