Skip to content

[V4] Preserve PGM and PPM sample precision - #3260

Merged
JimBobSquarePants merged 3 commits into
release/4.1.xfrom
fix/pbm-maxval-scaling-v4
Oct 28, 2026
Merged

JimBobSquarePants merged 3 commits into
release/4.1.xfrom
fix/pbm-maxval-scaling-v4

Conversation

@JimBobSquarePants

Copy link
Copy Markdown
Member

Prerequisites

  • I have written a descriptive pull-request title
  • I have verified that there are no overlapping pull-requests open
  • I have verified that I am following the existing coding patterns and practice as demonstrated in the repository. These follow strict Stylecop rules 👮.
  • I have provided test coverage for my change (where applicable)

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

jafin and others added 2 commits October 28, 2026 12:39
… 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.
@JimBobSquarePants
JimBobSquarePants marked this pull request as ready for review October 28, 2026 03:05
@JimBobSquarePants
JimBobSquarePants merged commit 9e16b57 into release/4.1.x Oct 28, 2026
11 checks passed
@JimBobSquarePants
JimBobSquarePants deleted the fix/pbm-maxval-scaling-v4 branch October 28, 2026 03:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

PGM/PPM images with a 16-bit maxval other than 65535 decode to only a few gray levels

2 participants