From f0d7de4df4646cc98d264b49a9e9a3183eaf5d06 Mon Sep 17 00:00:00 2001 From: Marti Maria Date: Mon, 11 Dec 2023 14:55:18 +0100 Subject: [PATCH] Fix planar stride on words Fix planar words from float --- src/cmspack.c | 2 +- testbed/testcms2.c | 29 +++++++++++++++++++++++++++++ 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/src/cmspack.c b/src/cmspack.c index c191896c..90c3720e 100644 --- a/src/cmspack.c +++ b/src/cmspack.c @@ -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; } diff --git a/testbed/testcms2.c b/testbed/testcms2.c index c3107a2b..851b11c0 100644 --- a/testbed/testcms2.c +++ b/testbed/testcms2.c @@ -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. */ @@ -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);