From 314bc7201d340ab303b36a0ade2c37cf40b83a3b Mon Sep 17 00:00:00 2001 From: Marti Maria Date: Fri, 11 Mar 2011 16:14:51 +0100 Subject: Fixing several minor issues --- ChangeLog | 5 +- include/lcms2_plugin.h | 4 +- src/cmserr.c | 18 +- src/cmsio0.c | 14 +- src/cmsio1.c | 14 +- src/cmslut.c | 14 +- src/cmsopt.c | 26 ++- src/cmspack.c | 28 +-- src/cmsps2.c | 542 ++++++++++++++++++++++++------------------------- src/cmstypes.c | 40 ++-- src/cmsvirt.c | 12 +- src/cmsxform.c | 44 ++-- src/lcms2_internal.h | 6 +- 13 files changed, 397 insertions(+), 370 deletions(-) diff --git a/ChangeLog b/ChangeLog index 53ad5da..27c370f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -13,7 +13,7 @@ Added cmsTagLinkedTo Fixed some typos in error messages Peliminary Delphi wrapper Fixed a bug in tificc in floating point formats -Fixed a bug in device link creation on v4 profiles +Fixed a bug in device link creation on v4 profiles Fixed a bug in psid and profile sequence tags Fixed memory leaks on when recovering from errors Fixed an issue on curve inversion @@ -32,3 +32,6 @@ Removed pthreads need Updated linkicc to 2.1, cleanup Fixed some potential issues as NULL dereferencing Fixed GBD bug (out of bounds memory overwrite) +changed memmove to memcpy in cache for xput improvement +Profiles with weird curves are not prone to p`relinearization optimization. + diff --git a/include/lcms2_plugin.h b/include/lcms2_plugin.h index 896fa49..340f27c 100644 --- a/include/lcms2_plugin.h +++ b/include/lcms2_plugin.h @@ -1,7 +1,7 @@ //--------------------------------------------------------------------------------- // // Little Color Management System -// Copyright (c) 1998-2010 Marti Maria Saguer +// Copyright (c) 1998-2011 Marti Maria Saguer // // Permission is hereby granted, free of charge, to any person obtaining // a copy of this software and associated documentation files (the "Software"), @@ -387,7 +387,7 @@ typedef struct _cms_typehandler_struct { void *Ptr); // Additional parameters used by the calling thread - cmsContext ContextID; + cmsContext ContextID; cmsUInt32Number ICCVersion; } cmsTagTypeHandler; diff --git a/src/cmserr.c b/src/cmserr.c index 55f0358..caa17e5 100644 --- a/src/cmserr.c +++ b/src/cmserr.c @@ -47,14 +47,14 @@ long int CMSEXPORT cmsfilelength(FILE* f) p = ftell(f); // register current file position - if (fseek(f, 0, SEEK_END) != 0) { - return -1; - } + if (fseek(f, 0, SEEK_END) != 0) { + return -1; + } - n = ftell(f); + n = ftell(f); fseek(f, p, SEEK_SET); // file position restored - return n; + return n; } @@ -192,10 +192,10 @@ cmsBool _cmsRegisterMemHandlerPlugin(cmsPluginBase *Data) return TRUE; } - // Check for required callbacks - if (Plugin -> MallocPtr == NULL || + // Check for required callbacks + if (Plugin -> MallocPtr == NULL || Plugin -> FreePtr == NULL || - Plugin -> ReallocPtr == NULL) return FALSE; + Plugin -> ReallocPtr == NULL) return FALSE; // Set replacement functions MallocPtr = Plugin -> MallocPtr; @@ -384,7 +384,7 @@ void DefaultLogErrorHandlerFunction(cmsContext ContextID, cmsUInt32Number ErrorC cmsUNUSED_PARAMETER(ContextID); cmsUNUSED_PARAMETER(ErrorCode); - cmsUNUSED_PARAMETER(Text); + cmsUNUSED_PARAMETER(Text); } // Change log error diff --git a/src/cmsio0.c b/src/cmsio0.c index 5553a65..f429ad6 100644 --- a/src/cmsio0.c +++ b/src/cmsio0.c @@ -1122,7 +1122,7 @@ cmsBool SaveTags(_cmsICCPROFILE* Icc, _cmsICCPROFILE* FileOrig) continue; } - TypeBase = TypeHandler ->Signature; + TypeBase = TypeHandler ->Signature; if (!_cmsWriteTypeBase(io, TypeBase)) return FALSE; @@ -1307,7 +1307,7 @@ cmsBool CMSEXPORT cmsCloseProfile(cmsHPROFILE hProfile) TypeHandler ->ContextID = Icc ->ContextID; // As an additional parameters TypeHandler ->ICCVersion = Icc ->Version; - TypeHandler ->FreePtr(TypeHandler, Icc -> TagPtrs[i]); + TypeHandler ->FreePtr(TypeHandler, Icc -> TagPtrs[i]); } else _cmsFree(Icc ->ContextID, Icc ->TagPtrs[i]); @@ -1481,11 +1481,11 @@ cmsBool CMSEXPORT cmsWriteTag(cmsHPROFILE hProfile, cmsTagSignature sig, const v TypeHandler ->ContextID = Icc ->ContextID; // As an additional parameter TypeHandler ->ICCVersion = Icc ->Version; - TypeHandler->FreePtr(TypeHandler, Icc -> TagPtrs[i]); + TypeHandler->FreePtr(TypeHandler, Icc -> TagPtrs[i]); + } } } } - } else { // New one i = Icc -> TagCount; @@ -1560,10 +1560,10 @@ cmsBool CMSEXPORT cmsWriteTag(cmsHPROFILE hProfile, cmsTagSignature sig, const v TypeHandler ->ContextID = Icc ->ContextID; TypeHandler ->ICCVersion = Icc ->Version; - Icc ->TagPtrs[i] = TypeHandler ->DupPtr(TypeHandler, data, TagDescriptor ->ElemCount); + Icc ->TagPtrs[i] = TypeHandler ->DupPtr(TypeHandler, data, TagDescriptor ->ElemCount); if (Icc ->TagPtrs[i] == NULL) { - + _cmsTagSignature2String(TypeString, (cmsTagSignature) Type); _cmsTagSignature2String(SigString, sig); cmsSignalError(Icc ->ContextID, cmsERROR_CORRUPTION_DETECTED, "Malformed struct in type '%s' for tag '%s'", TypeString, SigString); @@ -1653,7 +1653,7 @@ cmsInt32Number CMSEXPORT cmsReadRawTag(cmsHPROFILE hProfile, cmsTagSignature sig cmsCloseIOhandler(MemIO); return 0; } - + // Serialize TypeHandler ->ContextID = Icc ->ContextID; TypeHandler ->ICCVersion = Icc ->Version; diff --git a/src/cmsio1.c b/src/cmsio1.c index 7be30e7..b235333 100644 --- a/src/cmsio1.c +++ b/src/cmsio1.c @@ -629,7 +629,7 @@ cmsSEQ* _cmsReadProfileSequence(cmsHPROFILE hProfile) // Take profile sequence description first ProfileSeq = (cmsSEQ*) cmsReadTag(hProfile, cmsSigProfileSequenceDescTag); - + // Take profile sequence ID ProfileId = (cmsSEQ*) cmsReadTag(hProfile, cmsSigProfileSequenceIdTag); @@ -642,14 +642,14 @@ cmsSEQ* _cmsReadProfileSequence(cmsHPROFILE hProfile) if (ProfileSeq ->n != ProfileId ->n) return cmsDupProfileSequenceDescription(ProfileSeq); NewSeq = cmsDupProfileSequenceDescription(ProfileSeq); - + // Ok, proceed to the mixing if (NewSeq != NULL) { - for (i=0; i < ProfileSeq ->n; i++) { - - memmove(&NewSeq ->seq[i].ProfileID, &ProfileId ->seq[i].ProfileID, sizeof(cmsProfileID)); - NewSeq ->seq[i].Description = cmsMLUdup(ProfileId ->seq[i].Description); - } + for (i=0; i < ProfileSeq ->n; i++) { + + memmove(&NewSeq ->seq[i].ProfileID, &ProfileId ->seq[i].ProfileID, sizeof(cmsProfileID)); + NewSeq ->seq[i].Description = cmsMLUdup(ProfileId ->seq[i].Description); + } } return NewSeq; } diff --git a/src/cmslut.c b/src/cmslut.c index 772c110..e4475d2 100644 --- a/src/cmslut.c +++ b/src/cmslut.c @@ -261,7 +261,7 @@ cmsStage* CMSEXPORT cmsStageAllocToneCurves(cmsContext ContextID, cmsUInt32Numbe cmsStageFree(NewMPE); return NULL; } - + NewMPE ->Data = (void*) NewElem; NewElem ->nCurves = nChannels; @@ -286,7 +286,7 @@ cmsStage* CMSEXPORT cmsStageAllocToneCurves(cmsContext ContextID, cmsUInt32Numbe } } - return NewMPE; + return NewMPE; } @@ -582,7 +582,7 @@ cmsStage* CMSEXPORT cmsStageAllocCLut16bitGranular(cmsContext ContextID, cmsStageFree(NewMPE); return NULL; } - + return NewMPE; } @@ -642,9 +642,9 @@ cmsStage* CMSEXPORT cmsStageAllocCLutFloatGranular(cmsContext ContextID, const c } NewMPE ->Data = (void*) NewElem; - + // There is a potential integer overflow on conputing n and nEntries. - NewElem -> nEntries = n = outputChan * CubeSize( clutPoints, inputChan); + NewElem -> nEntries = n = outputChan * CubeSize(clutPoints, inputChan); NewElem -> HasFloatValues = TRUE; if (n == 0) { @@ -733,13 +733,13 @@ cmsBool CMSEXPORT cmsStageSampleCLut16bit(cmsStage* mpe, cmsSAMPLER16 Sampler, v cmsUInt32Number* nSamples; cmsUInt16Number In[cmsMAXCHANNELS], Out[MAX_STAGE_CHANNELS]; _cmsStageCLutData* clut; - + if (mpe == NULL) return FALSE; clut = (_cmsStageCLutData*) mpe->Data; if (clut == NULL) return FALSE; - + nSamples = clut->Params ->nSamples; nInputs = clut->Params ->nInputs; nOutputs = clut->Params ->nOutputs; diff --git a/src/cmsopt.c b/src/cmsopt.c index 2a839ef..4c28a07 100644 --- a/src/cmsopt.c +++ b/src/cmsopt.c @@ -873,6 +873,27 @@ void PrelinEval8(register const cmsUInt16Number Input[], #undef DENS + +// Curves that contain wide empty areas are not optimizeable +static +cmsBool IsDegenerated(const cmsToneCurve* g) +{ + int i, Zeros = 0, Poles = 0; + int nEntries = g ->nEntries; + + for (i=0; i < nEntries; i++) { + + if (g ->Table16[i] == 0x0000) Zeros++; + if (g ->Table16[i] == 0xffff) Poles++; + } + + if (Zeros == 1 && Poles == 1) return FALSE; // For linear tables + if (Zeros > (nEntries / 4)) return TRUE; // Degenerated, mostly zeros + if (Poles > (nEntries / 4)) return TRUE; // Degenerated, mostly poles + + return FALSE; +} + // -------------------------------------------------------------------------------------------------------------- // We need xput over here @@ -952,7 +973,10 @@ cmsBool OptimizeByComputingLinearization(cmsPipeline** Lut, cmsUInt32Number Inte // Exclude if non-monotonic if (!cmsIsToneCurveMonotonic(Trans[t])) - lIsSuitable = FALSE; + lIsSuitable = FALSE; + + if (IsDegenerated(Trans[t])) + lIsSuitable = FALSE; } // If it is not suitable, just quit diff --git a/src/cmspack.c b/src/cmspack.c index 196afa9..ae8df4f 100644 --- a/src/cmspack.c +++ b/src/cmspack.c @@ -333,9 +333,9 @@ cmsUInt8Number* UnrollLabV2_16(register _cmsTRANSFORM* info, // for duplex static cmsUInt8Number* Unroll2Bytes(register _cmsTRANSFORM* info, - register cmsUInt16Number wIn[], - register cmsUInt8Number* accum, - register cmsUInt32Number Stride) + register cmsUInt16Number wIn[], + register cmsUInt8Number* accum, + register cmsUInt32Number Stride) { wIn[0] = FROM_8_TO_16(*accum); accum++; // ch1 wIn[1] = FROM_8_TO_16(*accum); accum++; // ch2 @@ -348,20 +348,20 @@ cmsUInt8Number* Unroll2Bytes(register _cmsTRANSFORM* info, // Monochrome duplicates L into RGB for null-transforms static cmsUInt8Number* Unroll1Byte(register _cmsTRANSFORM* info, - register cmsUInt16Number wIn[], - register cmsUInt8Number* accum, - register cmsUInt32Number Stride) + register cmsUInt16Number wIn[], + register cmsUInt8Number* accum, + register cmsUInt32Number Stride) { - wIn[0] = wIn[1] = wIn[2] = FROM_8_TO_16(*accum); accum++; // L + wIn[0] = wIn[1] = wIn[2] = FROM_8_TO_16(*accum); accum++; // L return accum; } static cmsUInt8Number* Unroll1ByteSkip1(register _cmsTRANSFORM* info, - register cmsUInt16Number wIn[], - register cmsUInt8Number* accum, - register cmsUInt32Number Stride) + register cmsUInt16Number wIn[], + register cmsUInt8Number* accum, + register cmsUInt32Number Stride) { wIn[0] = wIn[1] = wIn[2] = FROM_8_TO_16(*accum); accum++; // L accum += 1; @@ -628,9 +628,9 @@ cmsUInt8Number* Unroll1WordSkip3(register _cmsTRANSFORM* info, static cmsUInt8Number* Unroll2Words(register _cmsTRANSFORM* info, - register cmsUInt16Number wIn[], - register cmsUInt8Number* accum, - register cmsUInt32Number Stride) + register cmsUInt16Number wIn[], + register cmsUInt8Number* accum, + register cmsUInt32Number Stride) { wIn[0] = *(cmsUInt16Number*) accum; accum += 2; // ch1 wIn[1] = *(cmsUInt16Number*) accum; accum += 2; // ch2 @@ -2239,7 +2239,7 @@ static cmsFormatters16 InputFormatters16[] = { { CHANNELS_SH(1)|BYTES_SH(1)|EXTRA_SH(2), ANYSPACE, Unroll1ByteSkip2}, { CHANNELS_SH(1)|BYTES_SH(1)|FLAVOR_SH(1), ANYSPACE, Unroll1ByteReversed}, { COLORSPACE_SH(PT_MCH2)|CHANNELS_SH(2)|BYTES_SH(1), 0, Unroll2Bytes}, - + { TYPE_LabV2_8, 0, UnrollLabV2_8 }, { TYPE_ALabV2_8, 0, UnrollALabV2_8 }, { TYPE_LabV2_16, 0, UnrollLabV2_16 }, diff --git a/src/cmsps2.c b/src/cmsps2.c index 250e047..6b0a73c 100644 --- a/src/cmsps2.c +++ b/src/cmsps2.c @@ -26,7 +26,7 @@ #include "lcms2_internal.h" -// PostScript ColorRenderingDictionary and ColorSpaceArray +// PostScript ColorRenderingDictionary and ColorSpaceArray #define MAXPSCOLS 60 // Columns on tables @@ -266,20 +266,20 @@ // This struct holds the memory block currently being write typedef struct { - _cmsStageCLutData* Pipeline; - cmsIOHANDLER* m; + _cmsStageCLutData* Pipeline; + cmsIOHANDLER* m; - int FirstComponent; - int SecondComponent; - - const char* PreMaj; - const char* PostMaj; - const char* PreMin; - const char* PostMin; + int FirstComponent; + int SecondComponent; + + const char* PreMaj; + const char* PostMaj; + const char* PreMin; + const char* PostMin; - int FixWhite; // Force mapping of pure white + int FixWhite; // Force mapping of pure white - cmsColorSpaceSignature ColorSpace; // ColorSpace of profile + cmsColorSpaceSignature ColorSpace; // ColorSpace of profile } cmsPsSamplerCargo; @@ -300,9 +300,9 @@ cmsUInt8Number Word2Byte(cmsUInt16Number w) static cmsUInt8Number L2Byte(cmsUInt16Number w) { - int ww = w + 0x0080; + int ww = w + 0x0080; - if (ww > 0xFFFF) return 0xFF; + if (ww > 0xFFFF) return 0xFF; return (cmsUInt8Number) ((cmsUInt16Number) (ww >> 8) & 0xFF); } @@ -313,14 +313,14 @@ cmsUInt8Number L2Byte(cmsUInt16Number w) static void WriteByte(cmsIOHANDLER* m, cmsUInt8Number b) { - _cmsIOPrintf(m, "%02x", b); - _cmsPSActualColumn += 2; + _cmsIOPrintf(m, "%02x", b); + _cmsPSActualColumn += 2; - if (_cmsPSActualColumn > MAXPSCOLS) { + if (_cmsPSActualColumn > MAXPSCOLS) { - _cmsIOPrintf(m, "\n"); - _cmsPSActualColumn = 0; - } + _cmsIOPrintf(m, "\n"); + _cmsPSActualColumn = 0; + } } // ----------------------------------------------------------------- PostScript generation @@ -346,19 +346,19 @@ static void EmitHeader(cmsIOHANDLER* m, const char* Title, cmsHPROFILE hProfile) { time_t timer; - cmsMLU *Description, *Copyright; - char DescASCII[256], CopyrightASCII[256]; + cmsMLU *Description, *Copyright; + char DescASCII[256], CopyrightASCII[256]; time(&timer); - - Description = (cmsMLU*) cmsReadTag(hProfile, cmsSigProfileDescriptionTag); - Copyright = (cmsMLU*) cmsReadTag(hProfile, cmsSigCopyrightTag); + + Description = (cmsMLU*) cmsReadTag(hProfile, cmsSigProfileDescriptionTag); + Copyright = (cmsMLU*) cmsReadTag(hProfile, cmsSigCopyrightTag); - DescASCII[0] = DescASCII[255] = 0; + DescASCII[0] = DescASCII[255] = 0; CopyrightASCII[0] = CopyrightASCII[255] = 0; - if (Description != NULL) cmsMLUgetASCII(Description, cmsNoLanguage, cmsNoCountry, DescASCII, 255); - if (Copyright != NULL) cmsMLUgetASCII(Copyright, cmsNoLanguage, cmsNoCountry, CopyrightASCII, 255); + if (Description != NULL) cmsMLUgetASCII(Description, cmsNoLanguage, cmsNoCountry, DescASCII, 255); + if (Copyright != NULL) cmsMLUgetASCII(Copyright, cmsNoLanguage, cmsNoCountry, CopyrightASCII, 255); _cmsIOPrintf(m, "%%!PS-Adobe-3.0\n"); _cmsIOPrintf(m, "%%\n"); @@ -451,7 +451,7 @@ void EmitLab2XYZ(cmsIOHANDLER* m) _cmsIOPrintf(m, "{255 mul 128 sub 200 div } bind\n"); _cmsIOPrintf(m, "]\n"); _cmsIOPrintf(m, "/MatrixABC [ 1 1 1 1 0 0 0 0 -1]\n"); - _cmsIOPrintf(m, "/RangeLMN [ -0.236 1.254 0 1 -0.635 1.640 ]\n"); + _cmsIOPrintf(m, "/RangeLMN [ -0.236 1.254 0 1 -0.635 1.640 ]\n"); _cmsIOPrintf(m, "/DecodeLMN [\n"); _cmsIOPrintf(m, "{dup 6 29 div ge {dup dup mul mul} {4 29 div sub 108 841 div mul} ifelse 0.964200 mul} bind\n"); _cmsIOPrintf(m, "{dup 6 29 div ge {dup dup mul mul} {4 29 div sub 108 841 div mul} ifelse } bind\n"); @@ -477,7 +477,7 @@ void Emit1Gamma(cmsIOHANDLER* m, cmsToneCurve* Table) if (cmsIsToneCurveLinear(Table)) return; // Check if is really an exponential. If so, emit "exp" - gamma = cmsEstimateGamma(Table, 0.001); + gamma = cmsEstimateGamma(Table, 0.001); if (gamma > 0) { _cmsIOPrintf(m, "{ %g exp } bind ", gamma); return; @@ -496,7 +496,7 @@ void Emit1Gamma(cmsIOHANDLER* m, cmsToneCurve* Table) _cmsIOPrintf(m, " ["); for (i=0; i < Table->nEntries; i++) { - _cmsIOPrintf(m, "%d ", Table->Table16[i]); + _cmsIOPrintf(m, "%d ", Table->Table16[i]); } _cmsIOPrintf(m, "] "); // v tab @@ -548,15 +548,15 @@ void EmitNGamma(cmsIOHANDLER* m, int n, cmsToneCurve* g[]) int i; for( i=0; i < n; i++ ) - { + { if (g[i] == NULL) return; // Error - if (i > 0 && GammaTableEquals(g[i-1]->Table16, g[i]->Table16, g[i]->nEntries)) { + if (i > 0 && GammaTableEquals(g[i-1]->Table16, g[i]->Table16, g[i]->nEntries)) { _cmsIOPrintf(m, "dup "); } else { - Emit1Gamma(m, g[i]); + Emit1Gamma(m, g[i]); } } @@ -641,21 +641,21 @@ int OutputValueSampler(register const cmsUInt16Number In[], register cmsUInt16Nu sc ->SecondComponent = In[1]; } - // Dump table. + // Dump table. - for (i=0; i < sc -> Pipeline ->Params->nOutputs; i++) { + for (i=0; i < sc -> Pipeline ->Params->nOutputs; i++) { - cmsUInt16Number wWordOut = Out[i]; + cmsUInt16Number wWordOut = Out[i]; cmsUInt8Number wByteOut; // Value as byte - + - // We always deal with Lab4 - - wByteOut = Word2Byte(wWordOut); - WriteByte(sc -> m, wByteOut); - } + // We always deal with Lab4 + + wByteOut = Word2Byte(wWordOut); + WriteByte(sc -> m, wByteOut); + } - return 1; + return 1; } // Writes a Pipeline on memstream. Could be 8 or 16 bits based @@ -673,7 +673,7 @@ void WriteCLUT(cmsIOHANDLER* m, cmsStage* mpe, const char* PreMaj, sc.FirstComponent = -1; sc.SecondComponent = -1; - sc.Pipeline = (_cmsStageCLutData *) mpe ->Data; + sc.Pipeline = (_cmsStageCLutData *) mpe ->Data; sc.m = m; sc.PreMaj = PreMaj; sc.PostMaj= PostMaj; @@ -685,8 +685,8 @@ void WriteCLUT(cmsIOHANDLER* m, cmsStage* mpe, const char* PreMaj, _cmsIOPrintf(m, "["); - for (i=0; i < sc.Pipeline->Params->nInputs; i++) - _cmsIOPrintf(m, " %d ", sc.Pipeline->Params->nSamples[i]); + for (i=0; i < sc.Pipeline->Params->nInputs; i++) + _cmsIOPrintf(m, " %d ", sc.Pipeline->Params->nSamples[i]); _cmsIOPrintf(m, " [\n"); @@ -705,25 +705,25 @@ static int EmitCIEBasedA(cmsIOHANDLER* m, cmsToneCurve* Curve, cmsCIEXYZ* BlackPoint) { - _cmsIOPrintf(m, "[ /CIEBasedA\n"); - _cmsIOPrintf(m, " <<\n"); + _cmsIOPrintf(m, "[ /CIEBasedA\n"); + _cmsIOPrintf(m, " <<\n"); - _cmsIOPrintf(m, "/DecodeA "); + _cmsIOPrintf(m, "/DecodeA "); - Emit1Gamma(m, Curve); + Emit1Gamma(m, Curve); - _cmsIOPrintf(m, " \n"); + _cmsIOPrintf(m, " \n"); - _cmsIOPrintf(m, "/MatrixA [ 0.9642 1.0000 0.8249 ]\n"); - _cmsIOPrintf(m, "/RangeLMN [ 0.0 0.9642 0.0 1.0000 0.0 0.8249 ]\n"); + _cmsIOPrintf(m, "/MatrixA [ 0.9642 1.0000 0.8249 ]\n"); + _cmsIOPrintf(m, "/RangeLMN [ 0.0 0.9642 0.0 1.0000 0.0 0.8249 ]\n"); - EmitWhiteBlackD50(m, BlackPoint); - EmitIntent(m, INTENT_PERCEPTUAL); + EmitWhiteBlackD50(m, BlackPoint); + EmitIntent(m, INTENT_PERCEPTUAL); - _cmsIOPrintf(m, ">>\n"); - _cmsIOPrintf(m, "]\n"); + _cmsIOPrintf(m, ">>\n"); + _cmsIOPrintf(m, "]\n"); - return 1; + return 1; } @@ -732,38 +732,38 @@ int EmitCIEBasedA(cmsIOHANDLER* m, cmsToneCurve* Curve, cmsCIEXYZ* BlackPoint) static int EmitCIEBasedABC(cmsIOHANDLER* m, cmsFloat64Number* Matrix, cmsToneCurve** CurveSet, cmsCIEXYZ* BlackPoint) { - int i; - - _cmsIOPrintf(m, "[ /CIEBasedABC\n"); - _cmsIOPrintf(m, "<<\n"); - _cmsIOPrintf(m, "/DecodeABC [ "); + int i; + + _cmsIOPrintf(m, "[ /CIEBasedABC\n"); + _cmsIOPrintf(m, "<<\n"); + _cmsIOPrintf(m, "/DecodeABC [ "); - EmitNGamma(m, 3, CurveSet); + EmitNGamma(m, 3, CurveSet); - _cmsIOPrintf(m, "]\n"); + _cmsIOPrintf(m, "]\n"); - _cmsIOPrintf(m, "/MatrixABC [ " ); + _cmsIOPrintf(m, "/MatrixABC [ " ); - for( i=0; i < 3; i++ ) { + for( i=0; i < 3; i++ ) { _cmsIOPrintf(m, "%.6f %.6f %.6f ", Matrix[i + 3*0], Matrix[i + 3*1], Matrix[i + 3*2]); - } + } - _cmsIOPrintf(m, "]\n"); + _cmsIOPrintf(m, "]\n"); - _cmsIOPrintf(m, "/RangeLMN [ 0.0 0.9642 0.0 1.0000 0.0 0.8249 ]\n"); + _cmsIOPrintf(m, "/RangeLMN [ 0.0 0.9642 0.0 1.0000 0.0 0.8249 ]\n"); - EmitWhiteBlackD50(m, BlackPoint); - EmitIntent(m, INTENT_PERCEPTUAL); + EmitWhiteBlackD50(m, BlackPoint); + EmitIntent(m, INTENT_PERCEPTUAL); - _cmsIOPrintf(m, ">>\n"); - _cmsIOPrintf(m, "]\n"); + _cmsIOPrintf(m, ">>\n"); + _cmsIOPrintf(m, "]\n"); - return 1; + return 1; } @@ -773,12 +773,12 @@ int EmitCIEBasedDEF(cmsIOHANDLER* m, cmsPipeline* Pipeline, int Intent, cmsCIEXY const char* PreMaj; const char* PostMaj; const char* PreMin, *PostMin; - cmsStage* mpe; + cmsStage* mpe; - mpe = Pipeline ->Elements; + mpe = Pipeline ->Elements; - switch (cmsStageInputChannels(mpe)) { + switch (cmsStageInputChannels(mpe)) { case 3: _cmsIOPrintf(m, "[ /CIEBasedDEF\n"); @@ -800,18 +800,18 @@ int EmitCIEBasedDEF(cmsIOHANDLER* m, cmsPipeline* Pipeline, int Intent, cmsCIEXY _cmsIOPrintf(m, "<<\n"); - if (cmsStageType(mpe) == cmsSigCurveSetElemType) { - + if (cmsStageType(mpe) == cmsSigCurveSetElemType) { + _cmsIOPrintf(m, "/DecodeDEF [ "); - EmitNGamma(m, cmsStageOutputChannels(mpe), _cmsStageGetPtrToCurveSet(mpe)); + EmitNGamma(m, cmsStageOutputChannels(mpe), _cmsStageGetPtrToCurveSet(mpe)); _cmsIOPrintf(m, "]\n"); - mpe = mpe ->Next; + mpe = mpe ->Next; } - if (cmsStageType(mpe) == cmsSigCLutElemType) { + if (cmsStageType(mpe) == cmsSigCLutElemType) { _cmsIOPrintf(m, "/Table "); WriteCLUT(m, mpe, PreMaj, PostMaj, PreMin, PostMin, FALSE, (cmsColorSpaceSignature) 0); @@ -832,7 +832,7 @@ int EmitCIEBasedDEF(cmsIOHANDLER* m, cmsPipeline* Pipeline, int Intent, cmsCIEXY // Generates a curve from a gray profile static -cmsToneCurve* ExtractGray2Y(cmsContext ContextID, cmsHPROFILE hProfile, int Intent) + cmsToneCurve* ExtractGray2Y(cmsContext ContextID, cmsHPROFILE hProfile, int Intent) { cmsToneCurve* Out = cmsBuildTabulatedToneCurve16(ContextID, 256, NULL); cmsHPROFILE hXYZ = cmsCreateXYZProfile(); @@ -840,15 +840,15 @@ cmsToneCurve* ExtractGray2Y(cmsContext ContextID, cmsHPROFILE hProfile, int Inte int i; if (Out != NULL) { - for (i=0; i < 256; i++) { - - cmsUInt8Number Gray = (cmsUInt8Number) i; - cmsCIEXYZ XYZ; - - cmsDoTransform(xform, &Gray, &XYZ, 1); - - Out ->Table16[i] =_cmsQuickSaturateWord(XYZ.Y * 65535.0); - } + for (i=0; i < 256; i++) { + + cmsUInt8Number Gray = (cmsUInt8Number) i; + cmsCIEXYZ XYZ; + + cmsDoTransform(xform, &Gray, &XYZ, 1); + + Out ->Table16[i] =_cmsQuickSaturateWord(XYZ.Y * 65535.0); + } } cmsDeleteTransform(xform); @@ -878,30 +878,30 @@ int WriteInputLUT(cmsIOHANDLER* m, cmsHPROFILE hProfile, int Intent, cmsUInt32Nu InputFormat = cmsFormatterForColorspaceOfProfile(hProfile, 2, FALSE); nChannels = T_CHANNELS(InputFormat); - - cmsDetectBlackPoint(&BlackPointAdaptedToD50, hProfile, Intent, 0); + + cmsDetectBlackPoint(&BlackPointAdaptedToD50, hProfile, Intent, 0); - // Adjust output to Lab4 + // Adjust output to Lab4 hLab = cmsCreateLab4ProfileTHR(m ->ContextID, NULL); - Profiles[0] = hProfile; - Profiles[1] = hLab; + Profiles[0] = hProfile; + Profiles[1] = hLab; - xform = cmsCreateMultiprofileTransform(Profiles, 2, InputFormat, TYPE_Lab_DBL, Intent, 0); - cmsCloseProfile(hLab); - - if (xform == NULL) { + xform = cmsCreateMultiprofileTransform(Profiles, 2, InputFormat, TYPE_Lab_DBL, Intent, 0); + cmsCloseProfile(hLab); + + if (xform == NULL) { - cmsSignalError(m ->ContextID, cmsERROR_COLORSPACE_CHECK, "Cannot create transform Profile -> Lab"); - return 0; - } + cmsSignalError(m ->ContextID, cmsERROR_COLORSPACE_CHECK, "Cannot create transform Profile -> Lab"); + return 0; + } // Only 1, 3 and 4 channels are allowed switch (nChannels) { case 1: { - cmsToneCurve* Gray2Y = ExtractGray2Y(m ->ContextID, hProfile, Intent); + cmsToneCurve* Gray2Y = ExtractGray2Y(m ->ContextID, hProfile, Intent); EmitCIEBasedA(m, Gray2Y, &BlackPointAdaptedToD50); cmsFreeToneCurve(Gray2Y); } @@ -909,15 +909,15 @@ int WriteInputLUT(cmsIOHANDLER* m, cmsHPROFILE hProfile, int Intent, cmsUInt32Nu case 3: case 4: { - cmsUInt32Number OutFrm = TYPE_Lab_16; + cmsUInt32Number OutFrm = TYPE_Lab_16; cmsPipeline* DeviceLink; _cmsTRANSFORM* v = (_cmsTRANSFORM*) xform; - DeviceLink = cmsPipelineDup(v ->Lut); - if (DeviceLink == NULL) return 0; + DeviceLink = cmsPipelineDup(v ->Lut); + if (DeviceLink == NULL) return 0; - dwFlags |= cmsFLAGS_FORCE_CLUT; - _cmsOptimizePipeline(&DeviceLink, Intent, &InputFormat, &OutFrm, &dwFlags); + dwFlags |= cmsFLAGS_FORCE_CLUT; + _cmsOptimizePipeline(&DeviceLink, Intent, &InputFormat, &OutFrm, &dwFlags); rc = EmitCIEBasedDEF(m, DeviceLink, Intent, &BlackPointAdaptedToD50); cmsPipelineFree(DeviceLink); @@ -926,7 +926,7 @@ int WriteInputLUT(cmsIOHANDLER* m, cmsHPROFILE hProfile, int Intent, cmsUInt32Nu default: - cmsSignalError(m ->ContextID, cmsERROR_COLORSPACE_CHECK, "Only 3, 4 channels supported for CSA. This profile has %d channels.", nChannels); + cmsSignalError(m ->ContextID, cmsERROR_COLORSPACE_CHECK, "Only 3, 4 channels supported for CSA. This profile has %d channels.", nChannels); return 0; } @@ -948,25 +948,25 @@ cmsFloat64Number* GetPtrToMatrix(const cmsStage* mpe) // Does create CSA based on matrix-shaper. Allowed types are gray and RGB based static -int WriteInputMatrixShaper(cmsIOHANDLER* m, cmsHPROFILE hProfile, cmsStage* Matrix, cmsStage* Shaper) + int WriteInputMatrixShaper(cmsIOHANDLER* m, cmsHPROFILE hProfile, cmsStage* Matrix, cmsStage* Shaper) { cmsColorSpaceSignature ColorSpace; int rc; cmsCIEXYZ BlackPointAdaptedToD50; ColorSpace = cmsGetColorSpace(hProfile); - + cmsDetectBlackPoint(&BlackPointAdaptedToD50, hProfile, INTENT_RELATIVE_COLORIMETRIC, 0); if (ColorSpace == cmsSigGrayData) { - - cmsToneCurve** ShaperCurve = _cmsStageGetPtrToCurveSet(Shaper); - rc = EmitCIEBasedA(m, ShaperCurve[0], &BlackPointAdaptedToD50); - + + cmsToneCurve** ShaperCurve = _cmsStageGetPtrToCurveSet(Shaper); + rc = EmitCIEBasedA(m, ShaperCurve[0], &BlackPointAdaptedToD50); + } else if (ColorSpace == cmsSigRgbData) { - + cmsMAT3 Mat; int i, j; @@ -977,16 +977,16 @@ int WriteInputMatrixShaper(cmsIOHANDLER* m, cmsHPROFILE hProfile, cmsStage* Matr Mat.v[i].n[j] *= MAX_ENCODEABLE_XYZ; rc = EmitCIEBasedABC(m, (cmsFloat64Number *) &Mat, - _cmsStageGetPtrToCurveSet(Shaper), - &BlackPointAdaptedToD50); + _cmsStageGetPtrToCurveSet(Shaper), + &BlackPointAdaptedToD50); } else { - cmsSignalError(m ->ContextID, cmsERROR_COLORSPACE_CHECK, "Profile is not suitable for CSA. Unsupported colorspace."); + cmsSignalError(m ->ContextID, cmsERROR_COLORSPACE_CHECK, "Profile is not suitable for CSA. Unsupported colorspace."); return 0; } - - return rc; + + return rc; } @@ -1003,11 +1003,11 @@ int WriteNamedColorCSA(cmsIOHANDLER* m, cmsHPROFILE hNamedColor, int Intent) char ColorName[32]; cmsNAMEDCOLORLIST* NamedColorList; - hLab = cmsCreateLab4ProfileTHR(m ->ContextID, NULL); + hLab = cmsCreateLab4ProfileTHR(m ->ContextID, NULL); xform = cmsCreateTransform(hNamedColor, TYPE_NAMED_COLOR_INDEX, hLab, TYPE_Lab_DBL, Intent, 0); if (xform == NULL) return 0; - NamedColorList = cmsGetNamedColorList(xform); + NamedColorList = cmsGetNamedColorList(xform); if (NamedColorList == NULL) return 0; _cmsIOPrintf(m, "<<\n"); @@ -1045,66 +1045,66 @@ int WriteNamedColorCSA(cmsIOHANDLER* m, cmsHPROFILE hNamedColor, int Intent) // Does create a Color Space Array on XYZ colorspace for PostScript usage static cmsUInt32Number GenerateCSA(cmsContext ContextID, - cmsHPROFILE hProfile, - cmsUInt32Number Intent, - cmsUInt32Number dwFlags, - cmsIOHANDLER* mem) -{ - cmsUInt32Number dwBytesUsed; - cmsPipeline* lut = NULL; - cmsStage* Matrix, *Shaper; + cmsHPROFILE hProfile, + cmsUInt32Number Intent, + cmsUInt32Number dwFlags, + cmsIOHANDLER* mem) +{ + cmsUInt32Number dwBytesUsed; + cmsPipeline* lut = NULL; + cmsStage* Matrix, *Shaper; - // Is a named color profile? - if (cmsGetDeviceClass(hProfile) == cmsSigNamedColorClass) { + // Is a named color profile? + if (cmsGetDeviceClass(hProfile) == cmsSigNamedColorClass) { - if (!WriteNamedColorCSA(mem, hProfile, Intent)) goto Error; - } - else { + if (!WriteNamedColorCSA(mem, hProfile, Intent)) goto Error; + } + else { - // Any profile class are allowed (including devicelink), but - // output (PCS) colorspace must be XYZ or Lab - cmsColorSpaceSignature ColorSpace = cmsGetPCS(hProfile); + // Any profile class are allowed (including devicelink), but + // output (PCS) colorspace must be XYZ or Lab + cmsColorSpaceSignature ColorSpace = cmsGetPCS(hProfile); - if (ColorSpace != cmsSigXYZData && - ColorSpace != cmsSigLabData) { + if (ColorSpace != cmsSigXYZData && + ColorSpace != cmsSigLabData) { - cmsSignalError(ContextID, cmsERROR_COLORSPACE_CHECK, "Invalid output color space"); - goto Error; - } + cmsSignalError(ContextID, cmsERROR_COLORSPACE_CHECK, "Invalid output color space"); + goto Error; + } - // Read the lut with all necessary conversion stages - lut = _cmsReadInputLUT(hProfile, Intent); - if (lut == NULL) goto Error; + // Read the lut with all necessary conversion stages + lut = _cmsReadInputLUT(hProfile, Intent); + if (lut == NULL) goto Error; - // Tone curves + matrix can be implemented without any LUT - if (cmsPipelineCheckAndRetreiveStages(lut, 2, cmsSigCurveSetElemType, cmsSigMatrixElemType, &Shaper, &Matrix)) { + // Tone curves + matrix can be implemented without any LUT + if (cmsPipelineCheckAndRetreiveStages(lut, 2, cmsSigCurveSetElemType, cmsSigMatrixElemType, &Shaper, &Matrix)) { - if (!WriteInputMatrixShaper(mem, hProfile, Matrix, Shaper)) goto Error; + if (!WriteInputMatrixShaper(mem, hProfile, Matrix, Shaper)) goto Error; - } - else { - // We need a LUT for the rest - if (!WriteInputLUT(mem, hProfile, Intent, dwFlags)) goto Error; - } - } + } + else { + // We need a LUT for the rest + if (!WriteInputLUT(mem, hProfile, Intent, dwFlags)) goto Error; + } + } - // Done, keep memory usage - dwBytesUsed = mem ->UsedSpace; + // Done, keep memory usage + dwBytesUsed = mem ->UsedSpace; - // Get rid of LUT - if (lut != NULL) cmsPipelineFree(lut); + // Get rid of LUT + if (lut != NULL) cmsPipelineFree(lut); - // Finally, return used byte count - return dwBytesUsed; + // Finally, return used byte count + return dwBytesUsed; Error: - if (lut != NULL) cmsPipelineFree(lut); - return 0; + if (lut != NULL) cmsPipelineFree(lut); + return 0; } // ------------------------------------------------------ Color Rendering Dictionary (CRD) @@ -1181,15 +1181,15 @@ void EmitPQRStage(cmsIOHANDLER* m, cmsHPROFILE hProfile, int DoBPC, int lIsAbsol if (lIsAbsolute) { // For absolute colorimetric intent, encode back to relative - // and generate a relative Pipeline + // and generate a relative Pipeline - // Relative encoding is obtained across XYZpcs*(D50/WhitePoint) + // Relative encoding is obtained across XYZpcs*(D50/WhitePoint) - cmsCIEXYZ White; + cmsCIEXYZ White; - _cmsReadMediaWhitePoint(&White, hProfile); + _cmsReadMediaWhitePoint(&White, hProfile); - _cmsIOPrintf(m,"/MatrixPQR [1 0 0 0 1 0 0 0 1 ]\n"); + _cmsIOPrintf(m,"/MatrixPQR [1 0 0 0 1 0 0 0 1 ]\n"); _cmsIOPrintf(m,"/RangePQR [ -0.5 2 -0.5 2 -0.5 2 ]\n"); _cmsIOPrintf(m, "%% Absolute colorimetric -- encode to relative to maximize LUT usage\n" @@ -1197,7 +1197,7 @@ void EmitPQRStage(cmsIOHANDLER* m, cmsHPROFILE hProfile, int DoBPC, int lIsAbsol "{0.9642 mul %g div exch pop exch pop exch pop exch pop} bind\n" "{1.0000 mul %g div exch pop exch pop exch pop exch pop} bind\n" "{0.8249 mul %g div exch pop exch pop exch pop exch pop} bind\n]\n", - White.X, White.Y, White.Z); + White.X, White.Y, White.Z); return; } @@ -1290,50 +1290,50 @@ int WriteOutputLUT(cmsIOHANDLER* m, cmsHPROFILE hProfile, int Intent, cmsUInt32N cmsCIEXYZ BlackPointAdaptedToD50; cmsBool lDoBPC = (dwFlags & cmsFLAGS_BLACKPOINTCOMPENSATION); cmsBool lFixWhite = !(dwFlags & cmsFLAGS_NOWHITEONWHITEFIXUP); - cmsUInt32Number InFrm = TYPE_Lab_16; - int RelativeEncodingIntent; - cmsColorSpaceSignature ColorSpace; + cmsUInt32Number InFrm = TYPE_Lab_16; + int RelativeEncodingIntent; + cmsColorSpaceSignature ColorSpace; - hLab = cmsCreateLab4ProfileTHR(m ->ContextID, NULL); - if (hLab == NULL) return 0; + hLab = cmsCreateLab4ProfileTHR(m ->ContextID, NULL); + if (hLab == NULL) return 0; OutputFormat = cmsFormatterForColorspaceOfProfile(hProfile, 2, FALSE); - nChannels = T_CHANNELS(OutputFormat); + nChannels = T_CHANNELS(OutputFormat); - ColorSpace = cmsGetColorSpace(hProfile); + ColorSpace = cmsGetColorSpace(hProfile); - // For absolute colorimetric, the LUT is encoded as relative in order to preserve precision. + // For absolute colorimetric, the LUT is encoded as relative in order to preserve precision. RelativeEncodingIntent = Intent; - if (RelativeEncodingIntent == INTENT_ABSOLUTE_COLORIMETRIC) - RelativeEncodingIntent = INTENT_RELATIVE_COLORIMETRIC; + if (RelativeEncodingIntent == INTENT_ABSOLUTE_COLORIMETRIC) + RelativeEncodingIntent = INTENT_RELATIVE_COLORIMETRIC; - // Use V4 Lab always - Profiles[0] = hLab; - Profiles[1] = hProfile; + // Use V4 Lab always + Profiles[0] = hLab; + Profiles[1] = hProfile; - xform = cmsCreateMultiprofileTransformTHR(m ->ContextID, - Profiles, 2, TYPE_Lab_DBL, - OutputFormat, RelativeEncodingIntent, 0); - cmsCloseProfile(hLab); + xform = cmsCreateMultiprofileTransformTHR(m ->ContextID, + Profiles, 2, TYPE_Lab_DBL, + OutputFormat, RelativeEncodingIntent, 0); + cmsCloseProfile(hLab); if (xform == NULL) { - cmsSignalError(m ->ContextID, cmsERROR_COLORSPACE_CHECK, "Cannot create transform Lab -> Profile in CRD creation"); + cmsSignalError(m ->ContextID, cmsERROR_COLORSPACE_CHECK, "Cannot create transform Lab -> Profile in CRD creation"); return 0; } // Get a copy of the internal devicelink v = (_cmsTRANSFORM*) xform; DeviceLink = cmsPipelineDup(v ->Lut); - if (DeviceLink == NULL) return 0; + if (DeviceLink == NULL) return 0; - // We need a CLUT - dwFlags |= cmsFLAGS_FORCE_CLUT; - _cmsOptimizePipeline(&DeviceLink, RelativeEncodingIntent, &InFrm, &OutputFormat, &dwFlags); + // We need a CLUT + dwFlags |= cmsFLAGS_FORCE_CLUT; + _cmsOptimizePipeline(&DeviceLink, RelativeEncodingIntent, &InFrm, &OutputFormat, &dwFlags); _cmsIOPrintf(m, "<<\n"); _cmsIOPrintf(m, "/ColorRenderingType 1\n"); @@ -1358,7 +1358,7 @@ int WriteOutputLUT(cmsIOHANDLER* m, cmsHPROFILE hProfile, int Intent, cmsUInt32N _cmsIOPrintf(m, "/RenderTable "); - + WriteCLUT(m, cmsPipelineGetPtrToFirstStage(DeviceLink), "<", ">\n", "", "", lFixWhite, ColorSpace); _cmsIOPrintf(m, " %d {} bind ", nChannels); @@ -1418,19 +1418,19 @@ int WriteNamedColorCRD(cmsIOHANDLER* m, cmsHPROFILE hNamedColor, int Intent, cms cmsUInt32Number OutputFormat; char ColorName[32]; char Colorant[128]; - cmsNAMEDCOLORLIST* NamedColorList; + cmsNAMEDCOLORLIST* NamedColorList; - + OutputFormat = cmsFormatterForColorspaceOfProfile(hNamedColor, 2, FALSE); - nColorant = T_CHANNELS(OutputFormat); + nColorant = T_CHANNELS(OutputFormat); - + xform = cmsCreateTransform(hNamedColor, TYPE_NAMED_COLOR_INDEX, NULL, OutputFormat, Intent, dwFlags); if (xform == NULL) return 0; - NamedColorList = cmsGetNamedColorList(xform); - if (NamedColorList == NULL) return 0; + NamedColorList = cmsGetNamedColorList(xform); + if (NamedColorList == NULL) return 0; _cmsIOPrintf(m, "<<\n"); _cmsIOPrintf(m, "(colorlistcomment) (%s) \n", "Named profile"); @@ -1473,128 +1473,128 @@ int WriteNamedColorCRD(cmsIOHANDLER* m, cmsHPROFILE hNamedColor, int Intent, cms static cmsUInt32Number GenerateCRD(cmsContext ContextID, - cmsHPROFILE hProfile, - cmsUInt32Number Intent, cmsUInt32Number dwFlags, - cmsIOHANDLER* mem) + cmsHPROFILE hProfile, + cmsUInt32Number Intent, cmsUInt32Number dwFlags, + cmsIOHANDLER* mem) { - cmsUInt32Number dwBytesUsed; + cmsUInt32Number dwBytesUsed; - if (!(dwFlags & cmsFLAGS_NODEFAULTRESOURCEDEF)) { + if (!(dwFlags & cmsFLAGS_NODEFAULTRESOURCEDEF)) { - EmitHeader(mem, "Color Rendering Dictionary (CRD)", hProfile); - } + EmitHeader(mem, "Color Rendering Dictionary (CRD)", hProfile); + } - // Is a named color profile? - if (cmsGetDeviceClass(hProfile) == cmsSigNamedColorClass) { + // Is a named color profile? + if (cmsGetDeviceClass(hProfile) == cmsSigNamedColorClass) { - if (!WriteNamedColorCRD(mem, hProfile, Intent, dwFlags)) { - return 0; - } - } - else { + if (!WriteNamedColorCRD(mem, hProfile, Intent, dwFlags)) { + return 0; + } + } + else { - // CRD are always implemented as LUT + // CRD are always implemented as LUT - if (!WriteOutputLUT(mem, hProfile, Intent, dwFlags)) { - return 0; - } - } + if (!WriteOutputLUT(mem, hProfile, Intent, dwFlags)) { + return 0; + } + } - if (!(dwFlags & cmsFLAGS_NODEFAULTRESOURCEDEF)) { + if (!(dwFlags & cmsFLAGS_NODEFAULTRESOURCEDEF)) { - _cmsIOPrintf(mem, "%%%%EndResource\n"); - _cmsIOPrintf(mem, "\n%% CRD End\n"); - } + _cmsIOPrintf(mem, "%%%%EndResource\n"); + _cmsIOPrintf(mem, "\n%% CRD End\n"); + } - // Done, keep memory usage - dwBytesUsed = mem ->UsedSpace; + // Done, keep memory usage + dwBytesUsed = mem ->UsedSpace; - // Finally, return used byte count - return dwBytesUsed; + // Finally, return used byte count + return dwBytesUsed; - cmsUNUSED_PARAMETER(ContextID); + cmsUNUSED_PARAMETER(ContextID); } -cmsUInt32Number CMSEXPORT cmsGetPostScriptColorResource(cmsContext ContextID, - cmsPSResourceType Type, - cmsHPROFILE hProfile, - cmsUInt32Number Intent, - cmsUInt32Number dwFlags, - cmsIOHANDLER* io) +cmsUInt32Number CMSEXPORT cmsGetPostScriptColorResource(cmsContext ContextID, + cmsPSResourceType Type, + cmsHPROFILE hProfile, + cmsUInt32Number Intent, + cmsUInt32Number dwFlags, + cmsIOHANDLER* io) { - cmsUInt32Number rc; + cmsUInt32Number rc; - switch (Type) { + switch (Type) { - case cmsPS_RESOURCE_CSA: - rc = GenerateCSA(ContextID, hProfile, Intent, dwFlags, io); - break; - - default: - case cmsPS_RESOURCE_CRD: - rc = GenerateCRD(ContextID, hProfile, Intent, dwFlags, io); - break; - } + case cmsPS_RESOURCE_CSA: + rc = GenerateCSA(ContextID, hProfile, Intent, dwFlags, io); + break; + + default: + case cmsPS_RESOURCE_CRD: + rc = GenerateCRD(ContextID, hProfile, Intent, dwFlags, io); + break; + } - return rc; + return rc; } cmsUInt32Number CMSEXPORT cmsGetPostScriptCRD(cmsContext ContextID, - cmsHPROFILE hProfile, + cmsHPROFILE hProfile, cmsUInt32Number Intent, cmsUInt32Number dwFlags, void* Buffer, cmsUInt32Number dwBufferLen) { - cmsIOHANDLER* mem; + cmsIOHANDLER* mem; cmsUInt32Number dwBytesUsed; // Set up the serialization engine - if (Buffer == NULL) - mem = cmsOpenIOhandlerFromNULL(ContextID); - else + if (Buffer == NULL) + mem = cmsOpenIOhandlerFromNULL(ContextID); + else mem = cmsOpenIOhandlerFromMem(ContextID, Buffer, dwBufferLen, "w"); if (!mem) return 0; - dwBytesUsed = cmsGetPostScriptColorResource(ContextID, cmsPS_RESOURCE_CRD, hProfile, Intent, dwFlags, mem); - + dwBytesUsed = cmsGetPostScriptColorResource(ContextID, cmsPS_RESOURCE_CRD, hProfile, Intent, dwFlags, mem); + // Get rid of memory stream - cmsCloseIOhandler(mem); + cmsCloseIOhandler(mem); - return dwBytesUsed; + return dwBytesUsed; } // Does create a Color Space Array on XYZ colorspace for PostScript usage cmsUInt32Number CMSEXPORT cmsGetPostScriptCSA(cmsContext ContextID, - cmsHPROFILE hProfile, - cmsUInt32Number Intent, - cmsUInt32Number dwFlags, - void* Buffer, - cmsUInt32Number dwBufferLen) + cmsHPROFILE hProfile, + cmsUInt32Number Intent, + cmsUInt32Number dwFlags, + void* Buffer, + cmsUInt32Number dwBufferLen) { - cmsIOHANDLER* mem; + cmsIOHANDLER* mem; cmsUInt32Number dwBytesUsed; - if (Buffer == NULL) - mem = cmsOpenIOhandlerFromNULL(ContextID); - else + if (Buffer == NULL) + mem = cmsOpenIOhandlerFromNULL(ContextID); + else mem = cmsOpenIOhandlerFromMem(ContextID, Buffer, dwBufferLen, "w"); if (!mem) return 0; - dwBytesUsed = cmsGetPostScriptColorResource(ContextID, cmsPS_RESOURCE_CSA, hProfile, Intent, dwFlags, mem); - + dwBytesUsed = cmsGetPostScriptColorResource(ContextID, cmsPS_RESOURCE_CSA, hProfile, Intent, dwFlags, mem); + // Get rid of memory stream - cmsCloseIOhandler(mem); + cmsCloseIOhandler(mem); - return dwBytesUsed; + return dwBytesUsed; } diff --git a/src/cmstypes.c b/src/cmstypes.c index 394a225..47d0e35 100644 --- a/src/cmstypes.c +++ b/src/cmstypes.c @@ -1,7 +1,7 @@ //--------------------------------------------------------------------------------- // // Little Color Management System -// Copyright (c) 1998-2010 Marti Maria Saguer +// Copyright (c) 1998-2011 Marti Maria Saguer // // Permission is hereby granted, free of charge, to any person obtaining // a copy of this software and associated documentation files (the "Software"), @@ -1622,7 +1622,7 @@ cmsBool Read8bitTables(cmsContext ContextID, cmsIOHANDLER* io, cmsPipeline* lut Tables[i]->Table16[j] = (cmsUInt16Number) FROM_8_TO_16(Temp[j]); } - _cmsFree(ContextID, Temp); + _cmsFree(ContextID, Temp); Temp = NULL; @@ -1688,7 +1688,7 @@ unsigned int uipow(cmsUInt32Number n, cmsUInt32Number a, cmsUInt32Number b) if (n == 0) return 0; for (; b > 0; b--) { - + rv *= a; // Check for overflow @@ -1889,16 +1889,16 @@ cmsBool Type_LUT8_Write(struct _cms_typehandler_struct* self, cmsIOHANDLER* io, nTabSize = uipow(NewLUT->OutputChannels, clutPoints, NewLUT ->InputChannels); if (nTabSize > 0) { - // The 3D CLUT. - if (clut != NULL) { + // The 3D CLUT. + if (clut != NULL) { - for (j=0; j < nTabSize; j++) { + for (j=0; j < nTabSize; j++) { - val = (cmsUInt8Number) FROM_16_TO_8(clut ->Tab.T[j]); - if (!_cmsWriteUInt8Number(io, val)) return FALSE; + val = (cmsUInt8Number) FROM_16_TO_8(clut ->Tab.T[j]); + if (!_cmsWriteUInt8Number(io, val)) return FALSE; + } } } - } // The postlinearization table if (!Write8bitTables(self ->ContextID, io, NewLUT ->OutputChannels, PostMPE)) return FALSE; @@ -2202,10 +2202,10 @@ cmsBool Type_LUT16_Write(struct _cms_typehandler_struct* self, cmsIOHANDLER* io nTabSize = uipow(OutputChannels, clutPoints, InputChannels); if (nTabSize > 0) { - // The 3D CLUT. - if (clut != NULL) { - if (!_cmsWriteUInt16Array(io, nTabSize, clut->Tab.T)) return FALSE; - } + // The 3D CLUT. + if (clut != NULL) { + if (!_cmsWriteUInt16Array(io, nTabSize, clut->Tab.T)) return FALSE; + } } // The postlinearization table @@ -2370,7 +2370,7 @@ cmsStage* ReadSetOfCurves(struct _cms_typehandler_struct* self, cmsIOHANDLER* io if (nCurves > cmsMAXCHANNELS) return FALSE; if (!io -> Seek(io, Offset)) return FALSE; - + for (i=0; i < nCurves; i++) Curves[i] = NULL; @@ -2380,9 +2380,9 @@ cmsStage* ReadSetOfCurves(struct _cms_typehandler_struct* self, cmsIOHANDLER* io if (Curves[i] == NULL) goto Error; if (!_cmsReadAlignment(io)) goto Error; } - + Lin = cmsStageAllocToneCurves(self ->ContextID, nCurves, Curves); - + Error: for (i=0; i < nCurves; i++) cmsFreeToneCurve(Curves[i]); @@ -3242,7 +3242,7 @@ static cmsBool SaveDescription(struct _cms_typehandler_struct* self, cmsIOHANDLER* io, cmsMLU* Text) { if (self ->ICCVersion < 0x4000000) { - + if (!_cmsWriteTypeBase(io, cmsSigTextDescriptionType)) return FALSE; return Type_Text_Description_Write(self, io, Text, 1); } @@ -4555,9 +4555,9 @@ void *Type_vcgt_Read(struct _cms_typehandler_struct* self, if (!_cmsReadUInt16Number(io, &nElems)) goto Error; if (!_cmsReadUInt16Number(io, &nBytes)) goto Error; - // Adobe's quirk fixup. Fixing broken profiles... - if (nElems == 256 && nBytes == 1 && SizeOfTag == 1576) - nBytes = 2; + // Adobe's quirk fixup. Fixing broken profiles... + if (nElems == 256 && nBytes == 1 && SizeOfTag == 1576) + nBytes = 2; // Populate tone curves diff --git a/src/cmsvirt.c b/src/cmsvirt.c index 9df9dc4..dade596 100644 --- a/src/cmsvirt.c +++ b/src/cmsvirt.c @@ -1,7 +1,7 @@ //--------------------------------------------------------------------------------- // // Little Color Management System -// Copyright (c) 1998-2010 Marti Maria Saguer +// Copyright (c) 1998-2011 Marti Maria Saguer // // Permission is hereby granted, free of charge, to any person obtaining // a copy of this software and associated documentation files (the "Software"), @@ -1054,7 +1054,7 @@ cmsHPROFILE CMSEXPORT cmsTransform2DeviceLink(cmsHTRANSFORM hTransform, cmsFloat cmsPipelineInsertStage(LUT, cmsAT_END, _cmsStageAllocLabV4ToV2(ContextID)); } - + hProfile = cmsCreateProfilePlaceholder(ContextID); if (!hProfile) goto Error; // can't allocate @@ -1084,7 +1084,7 @@ cmsHPROFILE CMSEXPORT cmsTransform2DeviceLink(cmsHTRANSFORM hTransform, cmsFloat if (dwFlags & cmsFLAGS_FORCE_CLUT) AllowedLUT = NULL; else - AllowedLUT = FindCombination(LUT, Version >= 4.0, DestinationTag); + AllowedLUT = FindCombination(LUT, Version >= 4.0, DestinationTag); if (AllowedLUT == NULL) { @@ -1115,16 +1115,16 @@ cmsHPROFILE CMSEXPORT cmsTransform2DeviceLink(cmsHTRANSFORM hTransform, cmsFloat goto Error; } - + if (dwFlags & cmsFLAGS_8BITS_DEVICELINK) cmsPipelineSetSaveAs8bitsFlag(LUT, TRUE); // Tag profile with information if (!SetTextTags(hProfile, L"devicelink")) goto Error; - + // Store result if (!cmsWriteTag(hProfile, DestinationTag, LUT)) goto Error; - + if (xform -> InputColorant != NULL) { if (!cmsWriteTag(hProfile, cmsSigColorantTableTag, xform->InputColorant)) goto Error; diff --git a/src/cmsxform.c b/src/cmsxform.c index 90b33fc..0d34001 100644 --- a/src/cmsxform.c +++ b/src/cmsxform.c @@ -100,7 +100,7 @@ void CMSEXPORT cmsDoTransform(cmsHTRANSFORM Transform, { _cmsTRANSFORM* p = (_cmsTRANSFORM*) Transform; - + p -> xform(p, InputBuffer, OutputBuffer, Size); } @@ -110,7 +110,7 @@ void CMSEXPORT cmsDoTransform(cmsHTRANSFORM Transform, // Float xform converts floats. Since there are no performance issues, one routine does all job, including gamut check. // Note that because extended range, we can use a -1.0 value for out of gamut in this case. static -void FloatXFORM(_cmsTRANSFORM* p, +void FloatXFORM(_cmsTRANSFORM* p, const void* in, void* out, cmsUInt32Number Size) { @@ -271,7 +271,7 @@ void CachedXFORM(_cmsTRANSFORM* p, memset(wOut, 0, sizeof(wOut)); // Get copy of zero cache - memmove(&Cache, &p ->Cache, sizeof(Cache)); + memcpy(&Cache, &p ->Cache, sizeof(Cache)); for (i=0; i < n; i++) { @@ -279,19 +279,19 @@ void CachedXFORM(_cmsTRANSFORM* p, if (memcmp(wIn, Cache.CacheIn, sizeof(Cache.CacheIn)) == 0) { - memmove(wOut, Cache.CacheOut, sizeof(Cache.CacheOut)); + memcpy(wOut, Cache.CacheOut, sizeof(Cache.CacheOut)); } else { p ->Lut ->Eval16Fn(wIn, wOut, p -> Lut->Data); - memmove(Cache.CacheIn, wIn, sizeof(Cache.CacheIn)); - memmove(Cache.CacheOut, wOut, sizeof(Cache.CacheOut)); + memcpy(Cache.CacheIn, wIn, sizeof(Cache.CacheIn)); + memcpy(Cache.CacheOut, wOut, sizeof(Cache.CacheOut)); } output = p -> ToOutput(p, wOut, output, Size); } - + } @@ -316,24 +316,24 @@ void CachedXFORMGamutCheck(_cmsTRANSFORM* p, memset(wOut, 0, sizeof(cmsUInt16Number) * cmsMAXCHANNELS); // Get copy of zero cache - memmove(&Cache, &p ->Cache, sizeof(Cache)); + memcpy(&Cache, &p ->Cache, sizeof(Cache)); for (i=0; i < n; i++) { accum = p -> FromInput(p, wIn, accum, Size); if (memcmp(wIn, Cache.CacheIn, sizeof(Cache.CacheIn)) == 0) { - memmove(wOut, Cache.CacheOut, sizeof(Cache.CacheOut)); + memcpy(wOut, Cache.CacheOut, sizeof(Cache.CacheOut)); } else { TransformOnePixelWithGamutCheck(p, wIn, wOut); - memmove(Cache.CacheIn, wIn, sizeof(Cache.CacheIn)); - memmove(Cache.CacheOut, wOut, sizeof(Cache.CacheOut)); + memcpy(Cache.CacheIn, wIn, sizeof(Cache.CacheIn)); + memcpy(Cache.CacheOut, wOut, sizeof(Cache.CacheOut)); } output = p -> ToOutput(p, wOut, output, Size); } - + } @@ -429,7 +429,7 @@ cmsBool GetXFormColorSpaces(int nProfiles, cmsHPROFILE hProfiles[], cmsColorSpac cmsColorSpaceSignature PostColorSpace; int i; - if (hProfiles[0] == NULL) return FALSE; + if (hProfiles[0] == NULL) return FALSE; *Input = PostColorSpace = cmsGetColorSpace(hProfiles[0]); @@ -440,7 +440,7 @@ cmsBool GetXFormColorSpaces(int nProfiles, cmsHPROFILE hProfiles[], cmsColorSpac int lIsInput = (PostColorSpace != cmsSigXYZData) && (PostColorSpace != cmsSigLabData); - if (hProfile == NULL) return FALSE; + if (hProfile == NULL) return FALSE; if (lIsInput) { @@ -458,7 +458,7 @@ cmsBool GetXFormColorSpaces(int nProfiles, cmsHPROFILE hProfiles[], cmsColorSpac *Output = PostColorSpace; - return TRUE; + return TRUE; } // Check colorspace @@ -510,10 +510,10 @@ cmsHTRANSFORM CMSEXPORT cmsCreateExtendedTransform(cmsContext ContextID, dwFlags |= cmsFLAGS_NOCACHE; // Mark entry/exit spaces - if (!GetXFormColorSpaces(nProfiles, hProfiles, &EntryColorSpace, &ExitColorSpace)) { - cmsSignalError(ContextID, cmsERROR_NULL, "NULL input profiles on transform"); - return NULL; - } + if (!GetXFormColorSpaces(nProfiles, hProfiles, &EntryColorSpace, &ExitColorSpace)) { + cmsSignalError(ContextID, cmsERROR_NULL, "NULL input profiles on transform"); + return NULL; + } // Check if proper colorspaces if (!IsProperColorSpace(EntryColorSpace, InputFormat)) { @@ -549,7 +549,7 @@ cmsHTRANSFORM CMSEXPORT cmsCreateExtendedTransform(cmsContext ContextID, xform ->ExitColorSpace = ExitColorSpace; xform ->RenderingIntent = Intents[nProfiles-1]; xform ->Lut = Lut; - + // Create a gamut check LUT if requested if (hGamutProfile != NULL && (dwFlags & cmsFLAGS_GAMUTCHECK)) xform ->GamutCheck = _cmsCreateGamutCheckPipeline(ContextID, hProfiles, @@ -783,7 +783,7 @@ cmsBool CMSEXPORT cmsChangeBuffersFormat(cmsHTRANSFORM hTransform, xform ->InputFormat = InputFormat; xform ->OutputFormat = OutputFormat; - xform ->FromInput = FromInput; - xform ->ToOutput = ToOutput; + xform ->FromInput = FromInput; + xform ->ToOutput = ToOutput; return TRUE; } diff --git a/src/lcms2_internal.h b/src/lcms2_internal.h index 4963171..8cb8bd0 100644 --- a/src/lcms2_internal.h +++ b/src/lcms2_internal.h @@ -531,9 +531,9 @@ struct _cmstransform_struct; typedef struct { - // 1-pixel cache (16 bits only) - cmsUInt16Number CacheIn[cmsMAXCHANNELS]; - cmsUInt16Number CacheOut[cmsMAXCHANNELS]; + // 1-pixel cache (16 bits only) + cmsUInt16Number CacheIn[cmsMAXCHANNELS]; + cmsUInt16Number CacheOut[cmsMAXCHANNELS]; } _cmsCACHE; -- cgit v1.2.1