Derive PCX plane count from the image, not the line width#9798
Open
chuenchen309 wants to merge 1 commit into
Open
Derive PCX plane count from the image, not the line width#9798chuenchen309 wants to merge 1 commit into
chuenchen309 wants to merge 1 commit into
Conversation
When decoding a multi-plane (e.g. RGB) PCX scanline, the decoder recovered the per-plane stride by guessing the band count as state->bytes / xsize. state->bytes is planes * stride, so when the padded stride differs from the width (an odd-width line padded to an even stride) that quotient is wrong: for a width-3 RGB line it gives 4 bands / stride 3, the plane-compaction step is skipped, and the R/G/B planes stay interleaved. The pixels decode to the wrong colours with no error raised. Use the known band count (im->bands) to split the line instead. Added an RGB round-trip regression at a width that triggers the padding. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Member
|
For the record, the idea was originally introduced in 5ecec7d |
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.
Changes proposed in this pull request:
PcxDecode.crecovered theper-plane stride by guessing the band count as
state->bytes / state->xsize.Since
state->bytesisplanes * stride, that quotient is wrong whenever theeven-padded stride differs from the width. For a width-3 RGB line it yields 4
bands / stride 3, the plane-compaction step is skipped, and the R/G/B planes
stay interleaved — the image decodes to the wrong colours with no error
raised. Derive the split from the known band count (
im->bands) instead.padding. The existing
test_odduses a 511×511 RGB image, whose width makesthe guess land on the right value by luck, so it never caught this.
Scope note: at width 1 an RGB PCX still raises
OSErroron read — that is aseparate problem on the encoder side (it emits only two of the three colour
planes), with a different root cause, so I've left it out of this change.
This PR was authored by an AI coding agent (Claude Code) running on this
account: the AI found the bug (verified against the real C codec, not a
simulation), ran the repro, wrote the test, and wrote this description. The
human account holder reviews every change and is accountable for it. The
verification is real and re-runnable from the diff. If this isn't the kind of
contribution you want, say so and I'll close it.