Fix UnrollPlanarWordsPremul() skipping only 1 plane instead of Extra planes#585
Merged
Merged
Conversation
…planes
UnrollPlanarWordsPremul() in src/cmspack.c advances accum by a single
Stride when ExtraFirst is set, regardless of how many extra (non-color)
planes are declared via T_EXTRA(). For formats with Extra > 1 (e.g. two
extra planes ahead of the color planes), this shifts every subsequent
color-channel read one plane early and leaves the last color channel
unread, corrupting the unrolled pixel.
The chunky sibling UnrollAnyWordsPremul() had the identical bug, fixed
in a prior merge by adding an Extra local (T_EXTRA(info->InputFormat))
and multiplying it into the pre-skip offset. This applies the same fix
to the planar function: add the missing Extra local and change the
ExtraFirst pre-skip from `accum += Stride` to `accum += Extra * Stride`.
Verified with a formatter-dispatch harness exercising
COLORSPACE_SH(PT_CMYK)|CHANNELS_SH(4)|BYTES_SH(2)|PLANAR_SH(1)|
EXTRA_SH(2)|PREMUL_SH(1)|DOSWAP_SH(1): before the fix, wIn came out as
{0x5555,0x4444,0x3333,0x2222} instead of the correct
{0x6666,0x5555,0x4444,0x3333}, with the K channel never read. After
the fix all 5 regression cases (Extra=1/2/3, both ExtraFirst settings)
pass with no change to previously-correct behavior.
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.
UnrollPlanarWordsPremul()insrc/cmspack.ccomputesExtraFirstbut never readsT_EXTRA(info->InputFormat). WhenExtraFirstis set it advancesaccumby a singleStride, regardless of how many extra (non-color) planes are actually declared. For formats withExtra > 1this shifts every subsequent color-channel read one plane early and leaves the last color channel unread, corrupting the unrolled pixel.The chunky sibling
UnrollAnyWordsPremul()had the identical bug and was already fixed by adding anExtralocal and multiplying it into the pre-skip offset (accum += Extra * sizeof(cmsUInt16Number)). This PR applies the equivalent fix to the planar function:Reproduced with a formatter-dispatch harness for
COLORSPACE_SH(PT_CMYK)|CHANNELS_SH(4)|BYTES_SH(2)|PLANAR_SH(1)|EXTRA_SH(2)|PREMUL_SH(1)|DOSWAP_SH(1)(2 extra planes ahead of 4 color planes): before the fixwIncame out as{0x5555,0x4444,0x3333,0x2222}instead of the correct{0x6666,0x5555,0x4444,0x3333}, with the K channel never read at all. After the fix, a 5-case regression suite coveringExtra=1/2/3with bothExtraFirstsettings (including the pre-existing, most commonExtra=1case, and the already-correct!ExtraFirstpath) all pass with no behavior change to previously-correct cases.