Skip to content

Commit 354efbc

Browse files
committed
Fix UnrollPlanarWordsPremul() skipping only 1 plane instead of Extra 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.
1 parent 8f7f96b commit 354efbc

1 file changed

Lines changed: 3 additions & 2 deletions

File tree

src/cmspack.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -659,15 +659,16 @@ cmsUInt8Number* UnrollPlanarWordsPremul(CMSREGISTER _cmsTRANSFORM* info,
659659
cmsUInt32Number SwapFirst = T_SWAPFIRST(info->InputFormat);
660660
cmsUInt32Number Reverse= T_FLAVOR(info ->InputFormat);
661661
cmsUInt32Number SwapEndian = T_ENDIAN16(info -> InputFormat);
662+
cmsUInt32Number Extra = T_EXTRA(info -> InputFormat);
662663
cmsUInt32Number i;
663664
cmsUInt32Number ExtraFirst = DoSwap ^ SwapFirst;
664665
cmsUInt8Number* Init = accum;
665-
666+
666667
cmsUInt16Number alpha = (ExtraFirst ? ((cmsUInt16Number*)accum)[0] : ((cmsUInt16Number*)accum)[nChan * Stride / 2]);
667668
cmsUInt32Number alpha_factor = _cmsToFixedDomain(alpha);
668669

669670
if (ExtraFirst) {
670-
accum += Stride;
671+
accum += Extra * Stride;
671672
}
672673

673674
for (i=0; i < nChan; i++) {

0 commit comments

Comments
 (0)