From 77c6f2aa568baf67a8a48d0cdeb2cf982e4f34a4 Mon Sep 17 00:00:00 2001 From: Marti Maria Date: Wed, 21 Dec 2011 14:58:09 +0100 Subject: Fixed a bug in named color devicelink generation --- ChangeLog | 2 ++ src/cmsopt.c | 20 ++++++++++++++++++++ src/cmsvirt.c | 5 +++++ src/cmsxform.c | 12 +++++++++--- 4 files changed, 36 insertions(+), 3 deletions(-) diff --git a/ChangeLog b/ChangeLog index 2c67fde..98fb6cc 100644 --- a/ChangeLog +++ b/ChangeLog @@ -56,3 +56,5 @@ Added compatibilty with Argyll's CGATS parser 2.3 Maintenance release ----------------------- + +Fixed a bug in the named color devicelink generation diff --git a/src/cmsopt.c b/src/cmsopt.c index 1b0d33e..0f11ba5 100644 --- a/src/cmsopt.c +++ b/src/cmsopt.c @@ -529,6 +529,7 @@ cmsBool OptimizeByResampling(cmsPipeline** Lut, cmsUInt32Number Intent, cmsUInt3 { cmsPipeline* Src; cmsPipeline* Dest; + cmsStage* mpe; cmsStage* CLUT; cmsStage *KeepPreLin = NULL, *KeepPostLin = NULL; int nGridPoints; @@ -544,6 +545,9 @@ cmsBool OptimizeByResampling(cmsPipeline** Lut, cmsUInt32Number Intent, cmsUInt3 // This is a loosy optimization! does not apply in floating-point cases if (_cmsFormatterIsFloat(*InputFormat) || _cmsFormatterIsFloat(*OutputFormat)) return FALSE; + + + ColorSpace = _cmsICCcolorSpace(T_COLORSPACE(*InputFormat)); OutputColorSpace = _cmsICCcolorSpace(T_COLORSPACE(*OutputFormat)); nGridPoints = _cmsReasonableGridpointsByColorspace(ColorSpace, *dwFlags); @@ -554,6 +558,13 @@ cmsBool OptimizeByResampling(cmsPipeline** Lut, cmsUInt32Number Intent, cmsUInt3 Src = *Lut; + // Named color pipelines cannot be optimized either + for (mpe = cmsPipelineGetPtrToFirstStage(Src); + mpe != NULL; + mpe = cmsStageNext(mpe)) { + if (cmsStageType(mpe) == cmsSigNamedColorElemType) return FALSE; + } + // Allocate an empty LUT Dest = cmsPipelineAlloc(Src ->ContextID, Src ->InputChannels, Src ->OutputChannels); if (!Dest) return FALSE; @@ -912,6 +923,7 @@ cmsBool OptimizeByComputingLinearization(cmsPipeline** Lut, cmsUInt32Number Inte cmsStage* OptimizedCLUTmpe; cmsColorSpaceSignature ColorSpace, OutputColorSpace; cmsStage* OptimizedPrelinMpe; + cmsStage* mpe; cmsToneCurve** OptimizedPrelinCurves; _cmsStageCLutData* OptimizedPrelinCLUT; @@ -930,6 +942,14 @@ cmsBool OptimizeByComputingLinearization(cmsPipeline** Lut, cmsUInt32Number Inte } OriginalLut = *Lut; + + // Named color pipelines cannot be optimized either + for (mpe = cmsPipelineGetPtrToFirstStage(OriginalLut); + mpe != NULL; + mpe = cmsStageNext(mpe)) { + if (cmsStageType(mpe) == cmsSigNamedColorElemType) return FALSE; + } + ColorSpace = _cmsICCcolorSpace(T_COLORSPACE(*InputFormat)); OutputColorSpace = _cmsICCcolorSpace(T_COLORSPACE(*OutputFormat)); nGridPoints = _cmsReasonableGridpointsByColorspace(ColorSpace, *dwFlags); diff --git a/src/cmsvirt.c b/src/cmsvirt.c index 9a7e718..eafa58b 100644 --- a/src/cmsvirt.c +++ b/src/cmsvirt.c @@ -934,6 +934,11 @@ cmsHPROFILE CreateNamedColorDevicelink(cmsHTRANSFORM xform) // Colorant count now depends on the output space nc2 ->ColorantCount = cmsPipelineOutputChannels(v ->Lut); + // Make sure we have proper formatters + cmsChangeBuffersFormat(xform, TYPE_NAMED_COLOR_INDEX, + FLOAT_SH(0) | COLORSPACE_SH(_cmsLCMScolorSpace(v ->ExitColorSpace)) + | BYTES_SH(2) | CHANNELS_SH(cmsChannelsOf(v ->ExitColorSpace))); + // Apply the transfor to colorants. for (i=0; i < nColors; i++) { cmsDoTransform(xform, &i, nc2 ->List[i].DeviceColorant, 1); diff --git a/src/cmsxform.c b/src/cmsxform.c index 8a76dae..eef54e4 100644 --- a/src/cmsxform.c +++ b/src/cmsxform.c @@ -369,6 +369,7 @@ _cmsTRANSFORM* AllocEmptyTransform(cmsContext ContextID, cmsUInt32Number InputFo if (InputFormat == 0 && OutputFormat == 0) { p ->FromInput = p ->ToOutput = NULL; + dwFlags |= cmsFLAGS_CAN_CHANGE_FORMATTER; } else { @@ -509,6 +510,12 @@ cmsHTRANSFORM CMSEXPORT cmsCreateExtendedTransform(cmsContext ContextID, cmsPipeline* Lut; cmsUInt32Number LastIntent = Intents[nProfiles-1]; + // If it is a fake transform + if (dwFlags & cmsFLAGS_NULLTRANSFORM) + { + return AllocEmptyTransform(ContextID, InputFormat, OutputFormat, dwFlags); + } + // If gamut check is requested, make sure we have a gamut profile if (dwFlags & cmsFLAGS_GAMUTCHECK) { if (hGamutProfile == NULL) dwFlags &= ~cmsFLAGS_GAMUTCHECK; @@ -788,10 +795,9 @@ cmsBool CMSEXPORT cmsChangeBuffersFormat(cmsHTRANSFORM hTransform, _cmsTRANSFORM* xform = (_cmsTRANSFORM*) hTransform; cmsFormatter16 FromInput, ToOutput; - cmsUInt32Number BytesPerPixelInput; + - // We only can afford to change formatters if previous transform is at least 16 bits - BytesPerPixelInput = T_BYTES(xform ->InputFormat); + // We only can afford to change formatters if previous transform is at least 16 bits if (!(xform ->dwOriginalFlags & cmsFLAGS_CAN_CHANGE_FORMATTER)) { cmsSignalError(xform ->ContextID, cmsERROR_NOT_SUITABLE, "cmsChangeBuffersFormat works only on transforms created originally with at least 16 bits of precision"); -- cgit v1.2.1