Repository navigation
[V4] Preserve PGM and PPM sample precision - #3260
Merged
Merged
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 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
V4 backport of #3227.
Normalize non-standard PGM and PPM sample ranges before packing the destination pixel. This preserves sample precision and removes the separate brightness pass. Full-range inputs keep the existing byte and ushort paths. Normalization uses one reusable float row and the existing bulk pixel API. Traversal remains scalar.
Sample saturation applies in every integrity mode. Early EOF returns the available image data without copying unused pooled memory. Decimal sample overflow saturates; overflowing header fields remain fatal before allocation. Binary parsing preserves raster bytes that resemble whitespace or comments.
Regression tests use stored inputs and exact byte and ushort expectations. Existing tolerances and reference images are unchanged. No public API changes.
All 140 PBM tests pass in Release on .NET 8 and .NET 10, with no failures or skips.
Fixes #3239