//
//---------------------------------------------------------------------------------
//
-// Version 2.8beta0
+// Version 2.8
//
#ifndef _lcms2_H
// T: Pixeltype
// F: Flavor 0=MinIsBlack(Chocolate) 1=MinIsWhite(Vanilla)
// P: Planar? 0=Chunky, 1=Planar
-// X: swap 16 bps endianess?
+// X: swap 16 bps endianness?
// S: Do swap? ie, BGR, KYMC
// E: Extra samples
// C: Channels (Samples per pixel)
// Context handling --------------------------------------------------------------------------------------------------------
// Each context holds its owns globals and its own plug-ins. There is a global context with the id = 0 for lecacy compatibility
-// though using the global context is not recomended. Proper context handling makes lcms more thread-safe.
+// though using the global context is not recommended. Proper context handling makes lcms more thread-safe.
typedef struct _cmsContext_struct* cmsContext;
const void* Buffer);
};
-// Endianess adjust functions
+// Endianness adjust functions
CMSAPI cmsUInt16Number CMSEXPORT _cmsAdjustEndianess16(cmsUInt16Number Word);
CMSAPI cmsUInt32Number CMSEXPORT _cmsAdjustEndianess32(cmsUInt32Number Value);
CMSAPI void CMSEXPORT _cmsAdjustEndianess64(cmsUInt64Number* Result, cmsUInt64Number* QWord);
// Handles extra channels copying alpha if requested by the flags
void _cmsHandleExtraChannels(_cmsTRANSFORM* p, const void* in,
- void* out,
- cmsUInt32Number PixelsPerLine,
- cmsUInt32Number LineCount,
- const cmsStride* Stride)
-{
- size_t i, j, k;
- cmsUInt32Number nExtra;
- cmsUInt32Number SourceStartingOrder[cmsMAXCHANNELS];
- cmsUInt32Number SourceIncrements[cmsMAXCHANNELS];
- cmsUInt32Number DestStartingOrder[cmsMAXCHANNELS];
- cmsUInt32Number DestIncrements[cmsMAXCHANNELS];
- cmsUInt32Number SourceStrideIncrements[cmsMAXCHANNELS];
- cmsUInt32Number DestStrideIncrements[cmsMAXCHANNELS];
-
- cmsUInt8Number* SourcePtr[cmsMAXCHANNELS];
- cmsUInt8Number* DestPtr[cmsMAXCHANNELS];
-
- cmsFormatterAlphaFn copyValueFn;
-
- // Make sure we need some copy
- if (!(p->dwOriginalFlags & cmsFLAGS_COPY_ALPHA))
- return;
-
- // Make sure we have same number of alpha channels. If not, just return as this should be checked at transform creation time.
- nExtra = T_EXTRA(p->InputFormat);
- if (nExtra != T_EXTRA(p->OutputFormat))
- return;
-
- // Anything to do?
- if (nExtra == 0)
- return;
+ void* out,
+ cmsUInt32Number PixelsPerLine,
+ cmsUInt32Number LineCount,
+ const cmsStride* Stride)
+{
+ cmsUInt32Number i, j, k;
+ cmsUInt32Number nExtra;
+ cmsUInt32Number SourceStartingOrder[cmsMAXCHANNELS];
+ cmsUInt32Number SourceIncrements[cmsMAXCHANNELS];
+ cmsUInt32Number DestStartingOrder[cmsMAXCHANNELS];
+ cmsUInt32Number DestIncrements[cmsMAXCHANNELS];
- // Compute the increments
- ComputeComponentIncrements(p->InputFormat, Stride->BytesPerPlaneIn, SourceStartingOrder, SourceIncrements);
- ComputeComponentIncrements(p->OutputFormat, Stride->BytesPerPlaneOut, DestStartingOrder, DestIncrements);
-
- // Check for conversions 8, 16, half, float, dbl
- copyValueFn = _cmsGetFormatterAlpha(p->ContextID, p->InputFormat, p->OutputFormat);
+ cmsFormatterAlphaFn copyValueFn;
- memset(SourceStrideIncrements, 0, sizeof(SourceStrideIncrements));
- memset(DestStrideIncrements, 0, sizeof(DestStrideIncrements));
+ // Make sure we need some copy
+ if (!(p->dwOriginalFlags & cmsFLAGS_COPY_ALPHA))
+ return;
- // The loop itself
- for (i = 0; i < LineCount; i++) {
+ // Exit early if in-place color-management is occurring - no need to copy extra channels to themselves.
+ if (p->InputFormat == p->OutputFormat && in == out)
+ return;
- // Prepare pointers for the loop
- for (j = 0; j < nExtra; j++) {
+ // Make sure we have same number of alpha channels. If not, just return as this should be checked at transform creation time.
+ nExtra = T_EXTRA(p->InputFormat);
+ if (nExtra != T_EXTRA(p->OutputFormat))
+ return;
- SourcePtr[j] = (cmsUInt8Number*)in + SourceStartingOrder[j] + SourceStrideIncrements[j];
- DestPtr[j] = (cmsUInt8Number*)out + DestStartingOrder[j] + DestStrideIncrements[j];
- }
+ // Anything to do?
+ if (nExtra == 0)
+ return;
- for (j = 0; j < PixelsPerLine; j++) {
+ // Compute the increments
+ ComputeComponentIncrements(p->InputFormat, Stride->BytesPerPlaneIn, SourceStartingOrder, SourceIncrements);
+ ComputeComponentIncrements(p->OutputFormat, Stride->BytesPerPlaneOut, DestStartingOrder, DestIncrements);
- for (k = 0; k < nExtra; k++) {
+ // Check for conversions 8, 16, half, float, dbl
+ copyValueFn = _cmsGetFormatterAlpha(p->ContextID, p->InputFormat, p->OutputFormat);
- copyValueFn(DestPtr[k], SourcePtr[k]);
+ if (nExtra == 1) { // Optimized routine for copying a single extra channel quickly
- SourcePtr[k] += SourceIncrements[k];
- DestPtr[k] += DestIncrements[k];
- }
- }
+ cmsUInt8Number* SourcePtr;
+ cmsUInt8Number* DestPtr;
- for (j = 0; j < nExtra; j++) {
+ cmsUInt32Number SourceStrideIncrement = 0;
+ cmsUInt32Number DestStrideIncrement = 0;
- SourceStrideIncrements[j] += Stride->BytesPerLineIn;
- DestStrideIncrements[j] += Stride->BytesPerLineOut;
- }
- }
+ // The loop itself
+ for (i = 0; i < LineCount; i++) {
+
+ // Prepare pointers for the loop
+ SourcePtr = (cmsUInt8Number*)in + SourceStartingOrder[0] + SourceStrideIncrement;
+ DestPtr = (cmsUInt8Number*)out + DestStartingOrder[0] + DestStrideIncrement;
+
+ for (j = 0; j < PixelsPerLine; j++) {
+
+ copyValueFn(DestPtr, SourcePtr);
+
+ SourcePtr += SourceIncrements[0];
+ DestPtr += DestIncrements[0];
+ }
+
+ SourceStrideIncrement += Stride->BytesPerLineIn;
+ DestStrideIncrement += Stride->BytesPerLineOut;
+ }
+
+ }
+ else { // General case with more than one extra channel
+
+ cmsUInt8Number* SourcePtr[cmsMAXCHANNELS];
+ cmsUInt8Number* DestPtr[cmsMAXCHANNELS];
+
+ cmsUInt32Number SourceStrideIncrements[cmsMAXCHANNELS];
+ cmsUInt32Number DestStrideIncrements[cmsMAXCHANNELS];
+
+ memset(SourceStrideIncrements, 0, sizeof(SourceStrideIncrements));
+ memset(DestStrideIncrements, 0, sizeof(DestStrideIncrements));
+
+ // The loop itself
+ for (i = 0; i < LineCount; i++) {
+
+ // Prepare pointers for the loop
+ for (j = 0; j < nExtra; j++) {
+
+ SourcePtr[j] = (cmsUInt8Number*)in + SourceStartingOrder[j] + SourceStrideIncrements[j];
+ DestPtr[j] = (cmsUInt8Number*)out + DestStartingOrder[j] + DestStrideIncrements[j];
+ }
+
+ for (j = 0; j < PixelsPerLine; j++) {
+
+ for (k = 0; k < nExtra; k++) {
+
+ copyValueFn(DestPtr[k], SourcePtr[k]);
+
+ SourcePtr[k] += SourceIncrements[k];
+ DestPtr[k] += DestIncrements[k];
+ }
+ }
+
+ for (j = 0; j < nExtra; j++) {
+
+ SourceStrideIncrements[j] += Stride->BytesPerLineIn;
+ DestStrideIncrements[j] += Stride->BytesPerLineOut;
+ }
+ }
+ }
}
+
}
// Parses a float number
-// This can not call directly atof because it uses locale dependant
+// This can not call directly atof because it uses locale dependent
// parsing, while CCMX files always use . as decimal separator
static
cmsFloat64Number ParseFloatNumber(const char *Buffer)
}
-// -------------------------------------------------------------- Higer level parsing
+// -------------------------------------------------------------- Higher level parsing
static
cmsBool DataFormatSection(cmsIT8* it8)
-// Init usefull pointers
+// Init useful pointers
static
void CookPointers(cmsIT8* it8)
};
-// A pointer to the begining of the list
+// A pointer to the beginning of the list
_cmsIntentsPluginChunkType _cmsIntentsPluginChunk = { NULL };
// Duplicates the zone of memory used by the plug-in in the new context
return TRUE;
}
- // Make sure to pass thru K (which now is fixed)
+ // Make sure to pass through K (which now is fixed)
Outf[3] = LabK[3];
// Apply TAC if needed
memset(&bp, 0, sizeof(bp));
// We need the input LUT of the last profile, assuming this one is responsible of
- // black generation. This LUT will be seached in inverse order.
+ // black generation. This LUT will be searched in inverse order.
bp.LabK2cmyk = _cmsReadInputLUT(hProfiles[nProfiles-1], INTENT_RELATIVE_COLORIMETRIC);
if (bp.LabK2cmyk == NULL) goto Cleanup;
}
}
-// Auxiliar to fill memory management functions from plugin (or context 0 defaults)
+// Auxiliary to fill memory management functions from plugin (or context 0 defaults)
void _cmsInstallAllocFunctions(cmsPluginMemHandler* Plugin, _cmsMemPluginChunkType* ptr)
{
if (Plugin == NULL) {
// Error logging ******************************************************************
-// There is no error handling at all. When a funtion fails, it returns proper value.
+// There is no error handling at all. When a function fails, it returns proper value.
// For example, all create functions does return NULL on failure. Other return FALSE
// It may be interesting, for the developer, to know why the function is failing.
// for that reason, lcms2 does offer a logging function. This function does recive
// a ENGLISH string with some clues on what is going wrong. You can show this
// info to the end user, or just create some sort of log.
// The logging function should NOT terminate the program, as this obviously can leave
-// resources. It is the programmer's responsability to check each function return code
+// resources. It is the programmer's responsibility to check each function return code
// to make sure it didn't fail.
// Error messages are limited to MAX_ERROR_MESSAGE_LEN
return Val;
}
-// Evaluate a segmented funtion for a single value. Return -1 if no valid segment found .
+// Evaluate a segmented function for a single value. Return -1 if no valid segment found .
// If fn type is 0, perform an interpolation on the table
static
cmsFloat64Number EvalSegmentedFn(const cmsToneCurve *g, cmsFloat64Number R)
#include "lcms2_internal.h"\r
\r
\r
-// Auxiliar: append a Lab identity after the given sequence of profiles\r
+// Auxiliary: append a Lab identity after the given sequence of profiles\r
// and return the transform. Lab profile is closed, rest of profiles are kept open.\r
cmsHTRANSFORM _cmsChain2Lab(cmsContext ContextID,\r
cmsUInt32Number nProfiles,\r
}\r
\r
// Build the relationship. This effectively limits the maximum accuracy to 16 bits, but\r
- // since this is used on black-preserving LUTs, we are not loosing accuracy in any case\r
+ // since this is used on black-preserving LUTs, we are not losing accuracy in any case\r
KTone = cmsJoinToneCurve(ContextID, in, out, nPoints);\r
\r
// Get rid of components\r
}\r
\r
// Does compute a gamut LUT going back and forth across pcs -> relativ. colorimetric intent -> pcs\r
-// the dE obtained is then annotated on the LUT. Values truely out of gamut are clipped to dE = 0xFFFE\r
+// the dE obtained is then annotated on the LUT. Values truly out of gamut are clipped to dE = 0xFFFE\r
// and values changed are supposed to be handled by any gamut remapping, so, are out of gamut as well.\r
//\r
// **WARNING: This algorithm does assume that gamut remapping algorithms does NOT move in-gamut colors,\r
int i;
cmsUInt32Number Samples[MAX_INPUT_DIMENSIONS];
- // Fill the auxiliar array
+ // Fill the auxiliary array
for (i=0; i < MAX_INPUT_DIMENSIONS; i++)
Samples[i] = nSamples;
return nReaded;
}
-// Postion file pointer in the file
+// Position file pointer in the file
static
cmsBool FileSeek(cmsIOHANDLER* iohandler, cmsUInt32Number offset)
{
{
cmsIOHANDLER* iohandler = NULL;
FILE* fm = NULL;
+ cmsInt32Number fileLen;
_cmsAssert(FileName != NULL);
_cmsAssert(AccessMode != NULL);
_cmsFree(ContextID, iohandler);
cmsSignalError(ContextID, cmsERROR_FILE, "File '%s' not found", FileName);
return NULL;
+ }
+ fileLen = cmsfilelength(fm);
+ if (fileLen < 0)
+ {
+ fclose(fm);
+ _cmsFree(ContextID, iohandler);
+ cmsSignalError(ContextID, cmsERROR_FILE, "Cannot get size of file '%s'", FileName);
+ return NULL;
}
- iohandler -> ReportedSize = (cmsUInt32Number) cmsfilelength(fm);
+
+ iohandler -> ReportedSize = (cmsUInt32Number) fileLen;
break;
case 'w':
cmsIOHANDLER* CMSEXPORT cmsOpenIOhandlerFromStream(cmsContext ContextID, FILE* Stream)
{
cmsIOHANDLER* iohandler = NULL;
+ cmsInt32Number fileSize;
+
+ fileSize = cmsfilelength(Stream);
+ if (fileSize < 0)
+ {
+ cmsSignalError(ContextID, cmsERROR_FILE, "Cannot get size of stream");
+ return NULL;
+ }
iohandler = (cmsIOHANDLER*) _cmsMallocZero(ContextID, sizeof(cmsIOHANDLER));
if (iohandler == NULL) return NULL;
iohandler -> ContextID = ContextID;
iohandler -> stream = (void*) Stream;
iohandler -> UsedSpace = 0;
- iohandler -> ReportedSize = (cmsUInt32Number) cmsfilelength(Stream);
+ iohandler -> ReportedSize = (cmsUInt32Number) fileSize;
iohandler -> PhysicalFile[0] = 0;
iohandler ->Read = FileRead;
}
-// Check existance
+// Check existence
cmsBool CMSEXPORT cmsIsTag(cmsHPROFILE hProfile, cmsTagSignature sig)
{
_cmsICCPROFILE* Icc = (_cmsICCPROFILE*) (void*) hProfile;
return FALSE;
}
- // Adjust endianess of the used parameters
+ // Adjust endianness of the used parameters
Icc -> DeviceClass = (cmsProfileClassSignature) _cmsAdjustEndianess32(Header.deviceClass);
Icc -> ColorSpace = (cmsColorSpaceSignature) _cmsAdjustEndianess32(Header.colorSpace);
Icc -> PCS = (cmsColorSpaceSignature) _cmsAdjustEndianess32(Header.pcs);
memset(&Header.reserved, 0, sizeof(Header.reserved));
- // Set profile ID. Endianess is always big endian
+ // Set profile ID. Endianness is always big endian
memmove(&Header.profileID, &Icc ->ProfileID, 16);
// Dump the header
LocalTypeHandler.ICCVersion = Icc ->Version;
Icc -> TagPtrs[n] = LocalTypeHandler.ReadPtr(&LocalTypeHandler, io, &ElemCount, TagSize);
- // The tag type is supported, but something wrong happend and we cannot read the tag.
+ // The tag type is supported, but something wrong happened and we cannot read the tag.
// let know the user about this (although it is just a warning)
if (Icc -> TagPtrs[n] == NULL) {
}
-// Auxiliar, read colorants as a MAT3 structure. Used by any function that needs a matrix-shaper
+// Auxiliary, read colorants as a MAT3 structure. Used by any function that needs a matrix-shaper
static
cmsBool ReadICCMatrixRGB2XYZ(cmsMAT3* r, cmsHPROFILE hProfile)
{
cmsTagSignature tagFloat;
cmsContext ContextID = cmsGetProfileContextID(hProfile);
- // On named color, take the appropiate tag
+ // On named color, take the appropriate tag
if (cmsGetDeviceClass(hProfile) == cmsSigNamedColorClass) {
cmsPipeline* Lut;
return Lut;
}
- // This is an attempt to reuse this funtion to retrieve the matrix-shaper as pipeline no
+ // This is an attempt to reuse this function to retrieve the matrix-shaper as pipeline no
// matter other LUT are present and have precedence. Intent = -1 means just this.
- if (Intent != -1) {
+ if (Intent >= INTENT_PERCEPTUAL && Intent <= INTENT_ABSOLUTE_COLORIMETRIC) {
tag16 = Device2PCS16[Intent];
tagFloat = Device2PCSFloat[Intent];
// Check if this is a grayscale profile.
if (cmsGetColorSpace(hProfile) == cmsSigGrayData) {
- // if so, build appropiate conversion tables.
+ // if so, build appropriate conversion tables.
// The tables are the PCS iluminant, scaled across GrayTRC
return BuildGrayInputMatrixPipeline(hProfile);
}
if (Lut == NULL) return NULL;
// If PCS is Lab or XYZ, the floating point tag is accepting data in the space encoding,
- // and since the formatter has already accomodated to 0..1.0, we should undo this change
+ // and since the formatter has already accommodated to 0..1.0, we should undo this change
if ( PCS == cmsSigLabData)
{
if (!cmsPipelineInsertStage(Lut, cmsAT_BEGIN, _cmsStageNormalizeToLabFloat(ContextID)))
cmsContext ContextID = cmsGetProfileContextID(hProfile);
- if (Intent != -1) {
+ if (Intent >= INTENT_PERCEPTUAL && Intent <= INTENT_ABSOLUTE_COLORIMETRIC) {
tag16 = PCS2Device16[Intent];
tagFloat = PCS2DeviceFloat[Intent];
// Check if this is a grayscale profile.
if (cmsGetColorSpace(hProfile) == cmsSigGrayData) {
- // if so, build appropiate conversion tables.
+ // if so, build appropriate conversion tables.
// The tables are the PCS iluminant, scaled across GrayTRC
return BuildGrayOutputPipeline(hProfile);
}
{
cmsPipeline* Lut;
cmsTagTypeSignature OriginalType;
- cmsTagSignature tag16 = Device2PCS16[Intent];
- cmsTagSignature tagFloat = Device2PCSFloat[Intent];
+ cmsTagSignature tag16;
+ cmsTagSignature tagFloat;
cmsContext ContextID = cmsGetProfileContextID(hProfile);
- // On named color, take the appropiate tag
+ if (Intent < INTENT_PERCEPTUAL || Intent > INTENT_ABSOLUTE_COLORIMETRIC)
+ return NULL;
+
+ tag16 = Device2PCS16[Intent];
+ tagFloat = Device2PCSFloat[Intent];
+
+ // On named color, take the appropriate tag
if (cmsGetDeviceClass(hProfile) == cmsSigNamedColorClass) {
- cmsNAMEDCOLORLIST* nc = (cmsNAMEDCOLORLIST*) cmsReadTag(hProfile, cmsSigNamedColor2Tag);
+ cmsNAMEDCOLORLIST* nc = (cmsNAMEDCOLORLIST*)cmsReadTag(hProfile, cmsSigNamedColor2Tag);
if (nc == NULL) return NULL;
goto Error;
return Lut;
-Error:
+ Error:
cmsPipelineFree(Lut);
cmsFreeNamedColorList(nc);
return NULL;
}
+
if (cmsIsTag(hProfile, tagFloat)) { // Float tag takes precedence
// Floating point LUT are always V
tagFloat = Device2PCSFloat[0];
if (cmsIsTag(hProfile, tagFloat)) {
- return cmsPipelineDup((cmsPipeline*) cmsReadTag(hProfile, tagFloat));
+ return cmsPipelineDup((cmsPipeline*)cmsReadTag(hProfile, tagFloat));
}
if (!cmsIsTag(hProfile, tag16)) { // Is there any LUT-Based table?
- tag16 = Device2PCS16[0];
+ tag16 = Device2PCS16[0];
if (!cmsIsTag(hProfile, tag16)) return NULL;
}
// Check profile version and LUT type. Do the necessary adjustments if needed
// Read the tag
- Lut = (cmsPipeline*) cmsReadTag(hProfile, tag16);
+ Lut = (cmsPipeline*)cmsReadTag(hProfile, tag16);
if (Lut == NULL) return NULL;
// The profile owns the Lut, so we need to copy it
ChangeInterpolationToTrilinear(Lut);
// After reading it, we have info about the original type
- OriginalType = _cmsGetTagTrueType(hProfile, tag16);
+ OriginalType = _cmsGetTagTrueType(hProfile, tag16);
// We need to adjust data for Lab16 on output
if (OriginalType != cmsSigLut16Type) return Lut;
// Here it is possible to get Lab on both sides
if (cmsGetColorSpace(hProfile) == cmsSigLabData) {
- if(!cmsPipelineInsertStage(Lut, cmsAT_BEGIN, _cmsStageAllocLabV4ToV2(ContextID)))
+ if (!cmsPipelineInsertStage(Lut, cmsAT_BEGIN, _cmsStageAllocLabV4ToV2(ContextID)))
goto Error2;
}
if (cmsGetPCS(hProfile) == cmsSigLabData) {
- if(!cmsPipelineInsertStage(Lut, cmsAT_END, _cmsStageAllocLabV2ToV4(ContextID)))
+ if (!cmsPipelineInsertStage(Lut, cmsAT_END, _cmsStageAllocLabV2ToV4(ContextID)))
goto Error2;
}
}
-// Auxiliar, read and duplicate a MLU if found.
+// Auxiliary, read and duplicate a MLU if found.
static
cmsMLU* GetMLUFromProfile(cmsHPROFILE h, cmsTagSignature sig)
{
r -> n[VZ] = z;
}
-// Vector substraction
+// Vector subtraction
void CMSEXPORT _cmsVEC3minus(cmsVEC3* r, const cmsVEC3* a, const cmsVEC3* b)
{
r -> n[VX] = a -> n[VX] - b -> n[VX];
}
-// Add an ASCII entry.
+// Add an ASCII entry. Do not add any \0 termination (ICC1v43_2010-12.pdf page 61)
cmsBool CMSEXPORT cmsMLUsetASCII(cmsMLU* mlu, const char LanguageCode[3], const char CountryCode[3], const char* ASCIIString)
{
- cmsUInt32Number i, len = (cmsUInt32Number) strlen(ASCIIString)+1;
+ cmsUInt32Number i, len = (cmsUInt32Number) strlen(ASCIIString);
wchar_t* WStr;
cmsBool rc;
cmsUInt16Number Lang = strTo16(LanguageCode);
return (cmsUInt32Number)(p - s);
}
-
-// Add a wide entry
+// Add a wide entry. Do not add any \0 terminator (ICC1v43_2010-12.pdf page 61)
cmsBool CMSEXPORT cmsMLUsetWide(cmsMLU* mlu, const char Language[3], const char Country[3], const wchar_t* WideString)
{
cmsUInt16Number Lang = strTo16(Language);
if (mlu == NULL) return FALSE;
if (WideString == NULL) return FALSE;
- len = (cmsUInt32Number) (mywcslen(WideString) + 1) * sizeof(wchar_t);
+ len = (cmsUInt32Number) (mywcslen(WideString)) * sizeof(wchar_t);
return AddMLUBlock(mlu, len, WideString, Lang, Cntry);
}
return TRUE;
}
-// Auxiliar, to see if two values are equal or very different
+// Auxiliary, to see if two values are equal or very different
static
cmsBool WhitesAreEqual(int n, cmsUInt16Number White1[], cmsUInt16Number White2[] )
{
for (i=0; i < n; i++) {
- if (abs(White1[i] - White2[i]) > 0xf000) return TRUE; // Values are so extremly different that the fixup should be avoided
+ if (abs(White1[i] - White2[i]) > 0xf000) return TRUE; // Values are so extremely different that the fixup should be avoided
if (White1[i] != White2[i]) return FALSE;
}
return TRUE;
#define ANYFLAVOR FLAVOR_SH(1)
-// Supress waning about info never being used
+// Suppress waning about info never being used
#ifdef _MSC_VER
#pragma warning(disable : 4100)
wLab[2] = ab2Fix4(Lab.b);
}
-// Auxiliar: convert to Radians
+// Auxiliary: convert to Radians
static
cmsFloat64Number RADIANS(cmsFloat64Number deg)
{
}
-// Auxiliar: atan2 but operating in degrees and returning 0 if a==b==0
+// Auxiliary: atan2 but operating in degrees and returning 0 if a==b==0
static
cmsFloat64Number atan2deg(cmsFloat64Number a, cmsFloat64Number b)
{
}
-// Auxiliar: Square
+// Auxiliary: Square
static
cmsFloat64Number Sqr(cmsFloat64Number v)
{
#endif
}
-// Auxiliar -- read 8, 16 and 32-bit numbers
+// Auxiliary -- read 8, 16 and 32-bit numbers
cmsBool CMSEXPORT _cmsReadUInt8Number(cmsIOHANDLER* io, cmsUInt8Number* n)
{
cmsUInt8Number tmp;
_cmsAssert(io != NULL);
- if (io -> Read(io, &tmp, sizeof(cmsFloat32Number), 1) != 1)
+ if (io -> Read(io, &tmp, sizeof(cmsUInt32Number), 1) != 1)
return FALSE;
if (n != NULL) {
tmp = _cmsAdjustEndianess32(tmp);
- *n = *(cmsFloat32Number*) &tmp;
+ *n = *(cmsFloat32Number*) (void*) &tmp;
}
return TRUE;
}
_cmsAssert(io != NULL);
- tmp = *(cmsUInt32Number*) &n;
+ tmp = *(cmsUInt32Number*) (void*) &n;
tmp = _cmsAdjustEndianess32(tmp);
if (io -> Write(io, sizeof(cmsUInt32Number), &tmp) != 1)
return FALSE;
va_start(args, frm);
len = vsnprintf((char*) Buffer, 2047, frm, args);
- if (len < 0) return FALSE; // Truncated, which is a fatal error for us
+ if (len < 0) {
+ va_end(args);
+ return FALSE; // Truncated, which is a fatal error for us
+ }
rc = io ->Write(io, len, Buffer);
//
// Each row contains Pipeline values for all but first component. So, I
// detect row changing by keeping a copy of last value of first
-// component. -1 is used to mark begining of whole block.
+// component. -1 is used to mark beginning of whole block.
static
int OutputValueSampler(register const cmsUInt16Number In[], register cmsUInt16Number Out[], register void* Cargo)
}
-// Auxiliar to retrieve a pointer to the segmentr containing the Lab value
+// Auxiliary to retrieve a pointer to the segmentr containing the Lab value
static
cmsGDBPoint* GetPoint(cmsGDB* gbd, const cmsCIELab* Lab, cmsSpherical* sp)
{
_cmsAssert(Lab != NULL);
_cmsAssert(sp != NULL);
- // Center L* by substracting half of its domain, that's 50
+ // Center L* by subtracting half of its domain, that's 50
_cmsVEC3init(&v, Lab ->L - 50.0, Lab ->a, Lab ->b);
// Convert to spherical coordinates
// This file implements every single tag and tag type as described in the ICC spec. Some types
// have been deprecated, like ncl and Data. There is no implementation for those types as there
// are no profiles holding them. The programmer can also extend this list by defining his own types
-// by using the appropiate plug-in. There are three types of plug ins regarding that. First type
+// by using the appropriate plug-in. There are three types of plug ins regarding that. First type
// allows to define new tags using any existing type. Next plug-in type allows to define new types
// and the third one is very specific: allows to extend the number of elements in the multiprocessing
// elements special type.
}
-// Auxiliar to convert UTF-32 to UTF-16 in some cases
+// Auxiliary to convert UTF-32 to UTF-16 in some cases
static
cmsBool _cmsWriteWCharArray(cmsIOHANDLER* io, cmsUInt32Number n, const wchar_t* Array)
{
return TRUE;
}
-// Auxiliar to read an array of wchar_t
+// Auxiliary to read an array of wchar_t
static
cmsBool _cmsReadWCharArray(cmsIOHANDLER* io, cmsUInt32Number n, wchar_t* Array)
{
cmsUInt32Number n,
cmsUInt32Number SizeOfTag);
-// Helper function to deal with position tables as decribed in ICC spec 4.3
+// Helper function to deal with position tables as described in ICC spec 4.3
// A table of n elements is readed, where first comes n records containing offsets and sizes and
// then a block containing the data itself. This allows to reuse same data in more than one entry
static
}
// Tell the real text len including the null terminator and padding
- len_text = strlen(Text) + 1;
+ len_text = (cmsUInt32Number) strlen(Text) + 1;
// Compute an total tag size requirement
len_tag_requirement = (8+4+len_text+4+4+2*len_text+2+1+67);
len_aligned = _cmsALIGNLONG(len_tag_requirement);
LargestPosition = EndOfThisString;
}
- // Now read the remaining of tag and fill all strings. Substract the directory
+ // Now read the remaining of tag and fill all strings. Subtract the directory
SizeOfTag = (LargestPosition * sizeof(wchar_t)) / sizeof(cmsUInt16Number);
if (SizeOfTag == 0)
{
-// Auxiliar, read an string specified as count + string
+// Auxiliary, read an string specified as count + string
static
cmsBool ReadCountAndSting(struct _cms_typehandler_struct* self, cmsIOHANDLER* io, cmsMLU* mlu, cmsUInt32Number* SizeOfTag, const char* Section)
{
static
cmsBool Type_MPEclut_Write(struct _cms_typehandler_struct* self, cmsIOHANDLER* io, void* Ptr, cmsUInt32Number nItems)
{
- cmsUInt8Number Dimensions8[16];
+ cmsUInt8Number Dimensions8[16]; // 16 because the spec says 16 and not max number of channels
cmsUInt32Number i;
cmsStage* mpe = (cmsStage*) Ptr;
_cmsStageCLutData* clut = (_cmsStageCLutData*) mpe ->Data;
- // Check for maximum number of channels
- if (mpe -> InputChannels > 15) return FALSE;
+ // Check for maximum number of channels supported by lcms
+ if (mpe -> InputChannels > MAX_INPUT_DIMENSIONS) return FALSE;
// Only floats are supported in MPE
if (clut ->HasFloatValues == FALSE) return FALSE;
// If no way, then force CLUT that for sure can be written
if (AllowedLUT == NULL) {
+ cmsStage* FirstStage;
+ cmsStage* LastStage;
+
dwFlags |= cmsFLAGS_FORCE_CLUT;
_cmsOptimizePipeline(ContextID, &LUT, xform ->RenderingIntent, &FrmIn, &FrmOut, &dwFlags);
// Put identity curves if needed
- if (cmsPipelineGetPtrToFirstStage(LUT) ->Type != cmsSigCurveSetElemType)
+ FirstStage = cmsPipelineGetPtrToFirstStage(LUT);
+ if (FirstStage != NULL && FirstStage ->Type != cmsSigCurveSetElemType)
if (!cmsPipelineInsertStage(LUT, cmsAT_BEGIN, _cmsStageAllocIdentityCurves(ContextID, ChansIn)))
goto Error;
- if (cmsPipelineGetPtrToLastStage(LUT) ->Type != cmsSigCurveSetElemType)
+ LastStage = cmsPipelineGetPtrToLastStage(LUT);
+ if (LastStage != NULL && LastStage ->Type != cmsSigCurveSetElemType)
if (!cmsPipelineInsertStage(LUT, cmsAT_END, _cmsStageAllocIdentityCurves(ContextID, ChansOut)))
goto Error;
}
-// Auxiliar: Handle precalculated gamut check. The retrieval of context may be alittle bit slow, but this function is not critical.
+// Auxiliary: Handle precalculated gamut check. The retrieval of context may be alittle bit slow, but this function is not critical.
static
void TransformOnePixelWithGamutCheck(_cmsTRANSFORM* p,
const cmsUInt16Number wIn[],
// Dictionary
cmsUInt32Number TagCount;
cmsTagSignature TagNames[MAX_TABLE_TAG];
- cmsTagSignature TagLinked[MAX_TABLE_TAG]; // The tag to wich is linked (0=none)
+ cmsTagSignature TagLinked[MAX_TABLE_TAG]; // The tag to which is linked (0=none)
cmsUInt32Number TagSizes[MAX_TABLE_TAG]; // Size on disk
cmsUInt32Number TagOffsets[MAX_TABLE_TAG];
cmsBool TagSaveAsRaw[MAX_TABLE_TAG]; // True to write uncooked