Skip to content

Commit

Permalink
Fix planar stride on words
Browse files Browse the repository at this point in the history
Fix planar words from float
  • Loading branch information
mm2 committed Dec 11, 2023
1 parent f75ee89 commit f0d7de4
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/cmspack.c
Original file line number Diff line number Diff line change
Expand Up @@ -3035,7 +3035,7 @@ cmsUInt8Number* PackWordsFromFloat(_cmsTRANSFORM* info,
vv = _cmsQuickSaturateWord(v);

if (Planar)
((cmsUInt16Number*)output)[(i + start) * Stride] = vv;
((cmsUInt16Number*)output)[(i + start) * Stride/2] = vv;
else
((cmsUInt16Number*)output)[i + start] = vv;
}
Expand Down
29 changes: 29 additions & 0 deletions testbed/testcms2.c
Original file line number Diff line number Diff line change
Expand Up @@ -8222,6 +8222,34 @@ int CheckPlanar8opt(void)
return 1;
}

/**
* Bug reported from float32 to uint16 planar
*/
#define TYPE_RGB_FLT_PLANAR (FLOAT_SH(1)|COLORSPACE_SH(PT_RGB)|CHANNELS_SH(3)|BYTES_SH(4)|PLANAR_SH(1))

static
int CheckPlanarFloat2int(void)
{
cmsHPROFILE sRGB = cmsCreate_sRGBProfile();

cmsHTRANSFORM transform = cmsCreateTransform(sRGB, TYPE_RGB_FLT_PLANAR,
sRGB, TYPE_RGB_16_PLANAR,INTENT_PERCEPTUAL, 0);

const cmsFloat32Number input[] = { 0, 0.4, 0.8, 0.1, 0.5, 0.9, 0.2, 0.6, 1.0, 0.3, 0.7, 1.0 };
cmsUInt16Number output[3*4] = { 0 };

cmsDoTransform(transform, input, output, 4);

cmsDeleteTransform(transform);
cmsCloseProfile(sRGB);

return 1;
}





/**
* Bug reported & fixed. Thanks to Kornel Lesinski for spotting this.
*/
Expand Down Expand Up @@ -9733,6 +9761,7 @@ int main(int argc, char* argv[])
Check("Set free a tag", CheckRemoveTag);
Check("Matrix simplification", CheckMatrixSimplify);
Check("Planar 8 optimization", CheckPlanar8opt);
Check("Planar float to int16", CheckPlanarFloat2int);
Check("Swap endian feature", CheckSE);
Check("Transform line stride RGB", CheckTransformLineStride);
Check("Forged MPE profile", CheckForgedMPE);
Expand Down

0 comments on commit f0d7de4

Please sign in to comment.