提交 2c9872eb 编写于 作者: P prr

6821031: Upgrade OpenJDK's LittleCMS version to 1.18

Reviewed-by: bae, igor
上级 bde204b6
...@@ -374,6 +374,10 @@ JNIEXPORT void JNICALL Java_sun_java2d_cmm_lcms_LCMS_getTagData ...@@ -374,6 +374,10 @@ JNIEXPORT void JNICALL Java_sun_java2d_cmm_lcms_LCMS_getTagData
return; return;
} }
// Modify data for a tag in a profile
LCMSBOOL LCMSEXPORT _cmsModifyTagData(cmsHPROFILE hProfile,
icTagSignature sig, void *data, size_t size);
/* /*
* Class: sun_java2d_cmm_lcms_LCMS * Class: sun_java2d_cmm_lcms_LCMS
* Method: setTagData * Method: setTagData
...@@ -561,10 +565,10 @@ JNIEXPORT void JNICALL Java_sun_java2d_cmm_lcms_LCMS_initLCMS ...@@ -561,10 +565,10 @@ JNIEXPORT void JNICALL Java_sun_java2d_cmm_lcms_LCMS_initLCMS
PF_ID_fID = (*env)->GetFieldID (env, Pf, "ID", "J"); PF_ID_fID = (*env)->GetFieldID (env, Pf, "ID", "J");
} }
BOOL _cmsModifyTagData(cmsHPROFILE hProfile, icTagSignature sig, LCMSBOOL _cmsModifyTagData(cmsHPROFILE hProfile, icTagSignature sig,
void *data, size_t size) void *data, size_t size)
{ {
BOOL isNew; LCMSBOOL isNew;
int i, idx, delta, count; int i, idx, delta, count;
LPBYTE padChars[3] = {0, 0, 0}; LPBYTE padChars[3] = {0, 0, 0};
LPBYTE beforeBuf, afterBuf, ptr; LPBYTE beforeBuf, afterBuf, ptr;
......
...@@ -29,7 +29,7 @@ ...@@ -29,7 +29,7 @@
// //
// //
// Little cms // Little cms
// Copyright (C) 1998-2006 Marti Maria // Copyright (C) 1998-2007 Marti Maria
// //
// Permission is hereby granted, free of charge, to any person obtaining // Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the "Software"), // a copy of this software and associated documentation files (the "Software"),
...@@ -51,7 +51,7 @@ ...@@ -51,7 +51,7 @@
// CIECAM 02 appearance model // CIECAM 02 appearance model. Many thanks to Jordi Vilar for the debugging.
#include "lcms.h" #include "lcms.h"
...@@ -196,6 +196,10 @@ CAM02COLOR NonlinearCompression(CAM02COLOR clr, LPcmsCIECAM02 pMod) ...@@ -196,6 +196,10 @@ CAM02COLOR NonlinearCompression(CAM02COLOR clr, LPcmsCIECAM02 pMod)
clr.RGBpa[i] = (400.0 * temp) / (temp + 27.13) + 0.1; clr.RGBpa[i] = (400.0 * temp) / (temp + 27.13) + 0.1;
} }
} }
clr.A = (((2.0 * clr.RGBpa[0]) + clr.RGBpa[1] +
(clr.RGBpa[2] / 20.0)) - 0.305) * pMod->Nbb;
return clr; return clr;
} }
...@@ -249,9 +253,6 @@ CAM02COLOR ComputeCorrelates(CAM02COLOR clr, LPcmsCIECAM02 pMod) ...@@ -249,9 +253,6 @@ CAM02COLOR ComputeCorrelates(CAM02COLOR clr, LPcmsCIECAM02 pMod)
clr.H = 300 + ((100*((clr.h - 237.53)/1.2)) / temp); clr.H = 300 + ((100*((clr.h - 237.53)/1.2)) / temp);
} }
clr.A = (((2.0 * clr.RGBpa[0]) + clr.RGBpa[1] +
(clr.RGBpa[2] / 20.0)) - 0.305) * pMod->Nbb;
clr.J = 100.0 * pow((clr.A / pMod->adoptedWhite.A), clr.J = 100.0 * pow((clr.A / pMod->adoptedWhite.A),
(pMod->c * pMod->z)); (pMod->c * pMod->z));
...@@ -395,7 +396,7 @@ LCMSHANDLE LCMSEXPORT cmsCIECAM02Init(LPcmsViewingConditions pVC) ...@@ -395,7 +396,7 @@ LCMSHANDLE LCMSEXPORT cmsCIECAM02Init(LPcmsViewingConditions pVC)
LPcmsCIECAM02 lpMod; LPcmsCIECAM02 lpMod;
if((lpMod = (LPcmsCIECAM02) malloc(sizeof(cmsCIECAM02))) == NULL) { if((lpMod = (LPcmsCIECAM02) _cmsMalloc(sizeof(cmsCIECAM02))) == NULL) {
return (LCMSHANDLE) NULL; return (LCMSHANDLE) NULL;
} }
...@@ -449,14 +450,19 @@ LCMSHANDLE LCMSEXPORT cmsCIECAM02Init(LPcmsViewingConditions pVC) ...@@ -449,14 +450,19 @@ LCMSHANDLE LCMSEXPORT cmsCIECAM02Init(LPcmsViewingConditions pVC)
lpMod -> z = compute_z(lpMod); lpMod -> z = compute_z(lpMod);
lpMod -> Nbb = computeNbb(lpMod); lpMod -> Nbb = computeNbb(lpMod);
lpMod -> FL = computeFL(lpMod); lpMod -> FL = computeFL(lpMod);
if (lpMod -> D == D_CALCULATE ||
lpMod -> D == D_CALCULATE_DISCOUNT) {
lpMod -> D = computeD(lpMod); lpMod -> D = computeD(lpMod);
}
lpMod -> Ncb = lpMod -> Nbb; lpMod -> Ncb = lpMod -> Nbb;
lpMod -> adoptedWhite = XYZtoCAT02(lpMod -> adoptedWhite); lpMod -> adoptedWhite = XYZtoCAT02(lpMod -> adoptedWhite);
lpMod -> adoptedWhite = ChromaticAdaptation(lpMod -> adoptedWhite, lpMod); lpMod -> adoptedWhite = ChromaticAdaptation(lpMod -> adoptedWhite, lpMod);
lpMod -> adoptedWhite = CAT02toHPE(lpMod -> adoptedWhite); lpMod -> adoptedWhite = CAT02toHPE(lpMod -> adoptedWhite);
lpMod -> adoptedWhite = NonlinearCompression(lpMod -> adoptedWhite, lpMod); lpMod -> adoptedWhite = NonlinearCompression(lpMod -> adoptedWhite, lpMod);
lpMod -> adoptedWhite = ComputeCorrelates(lpMod -> adoptedWhite, lpMod);
return (LCMSHANDLE) lpMod; return (LCMSHANDLE) lpMod;
...@@ -465,7 +471,7 @@ LCMSHANDLE LCMSEXPORT cmsCIECAM02Init(LPcmsViewingConditions pVC) ...@@ -465,7 +471,7 @@ LCMSHANDLE LCMSEXPORT cmsCIECAM02Init(LPcmsViewingConditions pVC)
void LCMSEXPORT cmsCIECAM02Done(LCMSHANDLE hModel) void LCMSEXPORT cmsCIECAM02Done(LCMSHANDLE hModel)
{ {
LPcmsCIECAM02 lpMod = (LPcmsCIECAM02) (LPSTR) hModel; LPcmsCIECAM02 lpMod = (LPcmsCIECAM02) (LPSTR) hModel;
if (lpMod) free(lpMod); if (lpMod) _cmsFree(lpMod);
} }
...@@ -510,3 +516,4 @@ void LCMSEXPORT cmsCIECAM02Reverse(LCMSHANDLE hModel, LPcmsJCh pIn, LPcmsCIEXYZ ...@@ -510,3 +516,4 @@ void LCMSEXPORT cmsCIECAM02Reverse(LCMSHANDLE hModel, LPcmsJCh pIn, LPcmsCIEXYZ
pOut ->Z = clr.XYZ[2]; pOut ->Z = clr.XYZ[2];
} }
...@@ -29,7 +29,7 @@ ...@@ -29,7 +29,7 @@
// //
// //
// Little cms // Little cms
// Copyright (C) 1998-2006 Marti Maria // Copyright (C) 1998-2007 Marti Maria
// //
// Permission is hereby granted, free of charge, to any person obtaining // Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the "Software"), // a copy of this software and associated documentation files (the "Software"),
...@@ -174,7 +174,7 @@ typedef struct { ...@@ -174,7 +174,7 @@ typedef struct {
LCMSAPI void LCMSEXPORT cmsCIECAM97sDone(LCMSHANDLE hModel) LCMSAPI void LCMSEXPORT cmsCIECAM97sDone(LCMSHANDLE hModel)
{ {
LPcmsCIECAM97s lpMod = (LPcmsCIECAM97s) (LPSTR) hModel; LPcmsCIECAM97s lpMod = (LPcmsCIECAM97s) (LPSTR) hModel;
if (lpMod) free(lpMod); if (lpMod) _cmsFree(lpMod);
} }
// Partial discounting for adaptation degree computation // Partial discounting for adaptation degree computation
...@@ -331,7 +331,7 @@ LCMSAPI LCMSHANDLE LCMSEXPORT cmsCIECAM97sInit(LPcmsViewingConditions pVC) ...@@ -331,7 +331,7 @@ LCMSAPI LCMSHANDLE LCMSEXPORT cmsCIECAM97sInit(LPcmsViewingConditions pVC)
LPcmsCIECAM97s lpMod; LPcmsCIECAM97s lpMod;
VEC3 tmp; VEC3 tmp;
if((lpMod = (LPcmsCIECAM97s) malloc(sizeof(cmsCIECAM97s))) == NULL) { if((lpMod = (LPcmsCIECAM97s) _cmsMalloc(sizeof(cmsCIECAM97s))) == NULL) {
return (LCMSHANDLE) NULL; return (LCMSHANDLE) NULL;
} }
...@@ -449,7 +449,7 @@ LCMSAPI LCMSHANDLE LCMSEXPORT cmsCIECAM97sInit(LPcmsViewingConditions pVC) ...@@ -449,7 +449,7 @@ LCMSAPI LCMSHANDLE LCMSEXPORT cmsCIECAM97sInit(LPcmsViewingConditions pVC)
// RGB_subw = [MlamRigg][WP/YWp] // RGB_subw = [MlamRigg][WP/YWp]
#ifdef USE_CIECAM97s2 #ifdef USE_CIECAM97s2
MAT3eval(&lpMod -> RGB_subw, &lpMod -> MlamRigg, (LPVEC3) &lpMod -> WP); MAT3eval(&lpMod -> RGB_subw, &lpMod -> MlamRigg, &lpMod -> WP);
#else #else
VEC3divK(&tmp, (LPVEC3) &lpMod -> WP, lpMod->WP.Y); VEC3divK(&tmp, (LPVEC3) &lpMod -> WP, lpMod->WP.Y);
MAT3eval(&lpMod -> RGB_subw, &lpMod -> MlamRigg, &tmp); MAT3eval(&lpMod -> RGB_subw, &lpMod -> MlamRigg, &tmp);
......
...@@ -29,7 +29,7 @@ ...@@ -29,7 +29,7 @@
// //
// //
// Little cms // Little cms
// Copyright (C) 1998-2006 Marti Maria // Copyright (C) 1998-2007 Marti Maria
// //
// Permission is hereby granted, free of charge, to any person obtaining // Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the "Software"), // a copy of this software and associated documentation files (the "Software"),
...@@ -256,7 +256,7 @@ void ComputeBlackPointCompensationFactors(LPcmsCIEXYZ BlackPointIn, ...@@ -256,7 +256,7 @@ void ComputeBlackPointCompensationFactors(LPcmsCIEXYZ BlackPointIn,
// Return TRUE if both m and of are empy -- "m" being identity and "of" being 0 // Return TRUE if both m and of are empy -- "m" being identity and "of" being 0
static static
BOOL IdentityParameters(LPWMAT3 m, LPWVEC3 of) LCMSBOOL IdentityParameters(LPWMAT3 m, LPWVEC3 of)
{ {
WVEC3 wv0; WVEC3 wv0;
...@@ -661,3 +661,6 @@ int cmsChooseCnvrt(int Absolute, ...@@ -661,3 +661,6 @@ int cmsChooseCnvrt(int Absolute,
return rc; return rc;
} }
...@@ -29,7 +29,7 @@ ...@@ -29,7 +29,7 @@
// //
// //
// Little cms // Little cms
// Copyright (C) 1998-2006 Marti Maria // Copyright (C) 1998-2007 Marti Maria
// //
// Permission is hereby granted, free of charge, to any person obtaining // Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the "Software"), // a copy of this software and associated documentation files (the "Software"),
...@@ -57,6 +57,7 @@ ...@@ -57,6 +57,7 @@
// errors. // errors.
void cdecl cmsSignalError(int ErrorCode, const char *ErrorText, ...); void cdecl cmsSignalError(int ErrorCode, const char *ErrorText, ...);
int LCMSEXPORT cmsErrorAction(int lAbort); int LCMSEXPORT cmsErrorAction(int lAbort);
void LCMSEXPORT cmsSetErrorHandler(cmsErrorHandlerFunction Fn); void LCMSEXPORT cmsSetErrorHandler(cmsErrorHandlerFunction Fn);
...@@ -96,7 +97,7 @@ void cmsSignalError(int ErrorCode, const char *ErrorText, ...) ...@@ -96,7 +97,7 @@ void cmsSignalError(int ErrorCode, const char *ErrorText, ...)
char Buffer[1024]; char Buffer[1024];
vsprintf(Buffer, ErrorText, args); vsnprintf(Buffer, 1023, ErrorText, args);
va_end(args); va_end(args);
if (UserErrorHandler(ErrorCode, Buffer)) { if (UserErrorHandler(ErrorCode, Buffer)) {
...@@ -118,8 +119,8 @@ void cmsSignalError(int ErrorCode, const char *ErrorText, ...) ...@@ -118,8 +119,8 @@ void cmsSignalError(int ErrorCode, const char *ErrorText, ...)
char Buffer1[1024]; char Buffer1[1024];
char Buffer2[256]; char Buffer2[256];
sprintf(Buffer1, "Error #%x; ", ErrorCode); snprintf(Buffer1, 767, "Error #%x; ", ErrorCode);
vsprintf(Buffer2, ErrorText, args); vsnprintf(Buffer2, 255, ErrorText, args);
strcat(Buffer1, Buffer2); strcat(Buffer1, Buffer2);
MessageBox(NULL, Buffer1, "Little cms", MessageBox(NULL, Buffer1, "Little cms",
MB_OK|MB_ICONSTOP|MB_TASKMODAL); MB_OK|MB_ICONSTOP|MB_TASKMODAL);
......
...@@ -29,7 +29,7 @@ ...@@ -29,7 +29,7 @@
// //
// //
// Little cms // Little cms
// Copyright (C) 1998-2006 Marti Maria // Copyright (C) 1998-2007 Marti Maria
// //
// Permission is hereby granted, free of charge, to any person obtaining // Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the "Software"), // a copy of this software and associated documentation files (the "Software"),
...@@ -63,9 +63,9 @@ LPGAMMATABLE LCMSEXPORT cmsReverseGamma(int nResultSamples, LPGAMMATABLE InGamma ...@@ -63,9 +63,9 @@ LPGAMMATABLE LCMSEXPORT cmsReverseGamma(int nResultSamples, LPGAMMATABLE InGamma
LPGAMMATABLE LCMSEXPORT cmsBuildParametricGamma(int nEntries, int Type, double Params[]); LPGAMMATABLE LCMSEXPORT cmsBuildParametricGamma(int nEntries, int Type, double Params[]);
LPGAMMATABLE LCMSEXPORT cmsJoinGamma(LPGAMMATABLE InGamma, LPGAMMATABLE OutGamma); LPGAMMATABLE LCMSEXPORT cmsJoinGamma(LPGAMMATABLE InGamma, LPGAMMATABLE OutGamma);
LPGAMMATABLE LCMSEXPORT cmsJoinGammaEx(LPGAMMATABLE InGamma, LPGAMMATABLE OutGamma, int nPoints); LPGAMMATABLE LCMSEXPORT cmsJoinGammaEx(LPGAMMATABLE InGamma, LPGAMMATABLE OutGamma, int nPoints);
BOOL LCMSEXPORT cmsSmoothGamma(LPGAMMATABLE Tab, double lambda); LCMSBOOL LCMSEXPORT cmsSmoothGamma(LPGAMMATABLE Tab, double lambda);
BOOL cdecl _cmsSmoothEndpoints(LPWORD Table, int nPoints); LCMSBOOL cdecl _cmsSmoothEndpoints(LPWORD Table, int nPoints);
// Sampled curves // Sampled curves
...@@ -74,7 +74,7 @@ LPSAMPLEDCURVE cdecl cmsAllocSampledCurve(int nItems); ...@@ -74,7 +74,7 @@ LPSAMPLEDCURVE cdecl cmsAllocSampledCurve(int nItems);
void cdecl cmsFreeSampledCurve(LPSAMPLEDCURVE p); void cdecl cmsFreeSampledCurve(LPSAMPLEDCURVE p);
void cdecl cmsEndpointsOfSampledCurve(LPSAMPLEDCURVE p, double* Min, double* Max); void cdecl cmsEndpointsOfSampledCurve(LPSAMPLEDCURVE p, double* Min, double* Max);
void cdecl cmsClampSampledCurve(LPSAMPLEDCURVE p, double Min, double Max); void cdecl cmsClampSampledCurve(LPSAMPLEDCURVE p, double Min, double Max);
BOOL cdecl cmsSmoothSampledCurve(LPSAMPLEDCURVE Tab, double SmoothingLambda); LCMSBOOL cdecl cmsSmoothSampledCurve(LPSAMPLEDCURVE Tab, double SmoothingLambda);
void cdecl cmsRescaleSampledCurve(LPSAMPLEDCURVE p, double Min, double Max, int nPoints); void cdecl cmsRescaleSampledCurve(LPSAMPLEDCURVE p, double Min, double Max, int nPoints);
LPSAMPLEDCURVE cdecl cmsJoinSampledCurves(LPSAMPLEDCURVE X, LPSAMPLEDCURVE Y, int nResultingPoints); LPSAMPLEDCURVE cdecl cmsJoinSampledCurves(LPSAMPLEDCURVE X, LPSAMPLEDCURVE Y, int nResultingPoints);
...@@ -84,7 +84,6 @@ double LCMSEXPORT cmsEstimateGammaEx(LPWORD GammaTable, int nEntries, double The ...@@ -84,7 +84,6 @@ double LCMSEXPORT cmsEstimateGammaEx(LPWORD GammaTable, int nEntries, double The
// ---------------------------------------------------------------------------------------- // ----------------------------------------------------------------------------------------
// #define DEBUG 1
#define MAX_KNOTS 4096 #define MAX_KNOTS 4096
typedef float vec[MAX_KNOTS+1]; typedef float vec[MAX_KNOTS+1];
...@@ -144,14 +143,14 @@ LPGAMMATABLE LCMSEXPORT cmsAllocGamma(int nEntries) ...@@ -144,14 +143,14 @@ LPGAMMATABLE LCMSEXPORT cmsAllocGamma(int nEntries)
LPGAMMATABLE p; LPGAMMATABLE p;
size_t size; size_t size;
if (nEntries > 65530) { if (nEntries > 65530 || nEntries <= 0) {
cmsSignalError(LCMS_ERRC_WARNING, "Couldn't create gammatable of more than 65530 entries; 65530 assumed"); cmsSignalError(LCMS_ERRC_ABORTED, "Couldn't create gammatable of more than 65530 entries");
nEntries = 65530; return NULL;
} }
size = sizeof(GAMMATABLE) + (sizeof(WORD) * (nEntries-1)); size = sizeof(GAMMATABLE) + (sizeof(WORD) * (nEntries-1));
p = (LPGAMMATABLE) malloc(size); p = (LPGAMMATABLE) _cmsMalloc(size);
if (!p) return NULL; if (!p) return NULL;
ZeroMemory(p, size); ZeroMemory(p, size);
...@@ -164,7 +163,7 @@ LPGAMMATABLE LCMSEXPORT cmsAllocGamma(int nEntries) ...@@ -164,7 +163,7 @@ LPGAMMATABLE LCMSEXPORT cmsAllocGamma(int nEntries)
void LCMSEXPORT cmsFreeGamma(LPGAMMATABLE Gamma) void LCMSEXPORT cmsFreeGamma(LPGAMMATABLE Gamma)
{ {
if (Gamma) free(Gamma); if (Gamma) _cmsFree(Gamma);
} }
...@@ -278,6 +277,15 @@ LPGAMMATABLE LCMSEXPORT cmsReverseGamma(int nResultSamples, LPGAMMATABLE InGamma ...@@ -278,6 +277,15 @@ LPGAMMATABLE LCMSEXPORT cmsReverseGamma(int nResultSamples, LPGAMMATABLE InGamma
LPWORD InPtr; LPWORD InPtr;
LPGAMMATABLE p; LPGAMMATABLE p;
// Try to reverse it analytically whatever possible
if (InGamma -> Seed.Type > 0 && InGamma -> Seed.Type <= 5 &&
_cmsCrc32OfGammaTable(InGamma) == InGamma -> Seed.Crc32) {
return cmsBuildParametricGamma(nResultSamples, -(InGamma -> Seed.Type), InGamma ->Seed.Params);
}
// Nope, reverse the table
p = cmsAllocGamma(nResultSamples); p = cmsAllocGamma(nResultSamples);
if (!p) return NULL; if (!p) return NULL;
...@@ -528,7 +536,7 @@ void smooth2(vec w, vec y, vec z, float lambda, int m) ...@@ -528,7 +536,7 @@ void smooth2(vec w, vec y, vec z, float lambda, int m)
// Smooths a curve sampled at regular intervals // Smooths a curve sampled at regular intervals
BOOL LCMSEXPORT cmsSmoothGamma(LPGAMMATABLE Tab, double lambda) LCMSBOOL LCMSEXPORT cmsSmoothGamma(LPGAMMATABLE Tab, double lambda)
{ {
vec w, y, z; vec w, y, z;
...@@ -640,13 +648,13 @@ LPSAMPLEDCURVE cmsAllocSampledCurve(int nItems) ...@@ -640,13 +648,13 @@ LPSAMPLEDCURVE cmsAllocSampledCurve(int nItems)
{ {
LPSAMPLEDCURVE pOut; LPSAMPLEDCURVE pOut;
pOut = (LPSAMPLEDCURVE) malloc(sizeof(SAMPLEDCURVE)); pOut = (LPSAMPLEDCURVE) _cmsMalloc(sizeof(SAMPLEDCURVE));
if (pOut == NULL) if (pOut == NULL)
return NULL; return NULL;
if((pOut->Values = (double *) malloc(nItems * sizeof(double))) == NULL) if((pOut->Values = (double *) _cmsMalloc(nItems * sizeof(double))) == NULL)
{ {
free(pOut); _cmsFree(pOut);
return NULL; return NULL;
} }
...@@ -659,8 +667,8 @@ LPSAMPLEDCURVE cmsAllocSampledCurve(int nItems) ...@@ -659,8 +667,8 @@ LPSAMPLEDCURVE cmsAllocSampledCurve(int nItems)
void cmsFreeSampledCurve(LPSAMPLEDCURVE p) void cmsFreeSampledCurve(LPSAMPLEDCURVE p)
{ {
free((LPVOID) p -> Values); _cmsFree((LPVOID) p -> Values);
free((LPVOID) p); _cmsFree((LPVOID) p);
} }
...@@ -731,7 +739,7 @@ void cmsClampSampledCurve(LPSAMPLEDCURVE p, double Min, double Max) ...@@ -731,7 +739,7 @@ void cmsClampSampledCurve(LPSAMPLEDCURVE p, double Min, double Max)
// Smooths a curve sampled at regular intervals // Smooths a curve sampled at regular intervals
BOOL cmsSmoothSampledCurve(LPSAMPLEDCURVE Tab, double lambda) LCMSBOOL cmsSmoothSampledCurve(LPSAMPLEDCURVE Tab, double lambda)
{ {
vec w, y, z; vec w, y, z;
int i, nItems; int i, nItems;
...@@ -915,14 +923,11 @@ LPSAMPLEDCURVE cmsConvertGammaToSampledCurve(LPGAMMATABLE Gamma, int nPoints) ...@@ -915,14 +923,11 @@ LPSAMPLEDCURVE cmsConvertGammaToSampledCurve(LPGAMMATABLE Gamma, int nPoints)
// Smooth endpoints (used in Black/White compensation) // Smooth endpoints (used in Black/White compensation)
BOOL _cmsSmoothEndpoints(LPWORD Table, int nEntries) LCMSBOOL _cmsSmoothEndpoints(LPWORD Table, int nEntries)
{ {
vec w, y, z; vec w, y, z;
int i, Zeros, Poles; int i, Zeros, Poles;
#ifdef DEBUG
ASAVE(Table, nEntries, "nonsmt.txt");
#endif
if (cmsIsLinear(Table, nEntries)) return FALSE; // Nothing to do if (cmsIsLinear(Table, nEntries)) return FALSE; // Nothing to do
......
...@@ -29,7 +29,7 @@ ...@@ -29,7 +29,7 @@
// //
// //
// Little cms // Little cms
// Copyright (C) 1998-2006 Marti Maria // Copyright (C) 1998-2007 Marti Maria
// //
// Permission is hereby granted, free of charge, to any person obtaining // Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the "Software"), // a copy of this software and associated documentation files (the "Software"),
...@@ -66,7 +66,7 @@ to use highlights, then it will be lost. ...@@ -66,7 +66,7 @@ to use highlights, then it will be lost.
*/ */
BOOL _cmsEndPointsBySpace(icColorSpaceSignature Space, WORD **White, WORD **Black, LCMSBOOL _cmsEndPointsBySpace(icColorSpaceSignature Space, WORD **White, WORD **Black,
int *nOutputs) int *nOutputs)
{ {
// Only most common spaces // Only most common spaces
...@@ -376,7 +376,6 @@ double LCMSEXPORT cmsCIE2000DeltaE(LPcmsCIELab Lab1, LPcmsCIELab Lab2, ...@@ -376,7 +376,6 @@ double LCMSEXPORT cmsCIE2000DeltaE(LPcmsCIELab Lab1, LPcmsCIELab Lab2,
double bs = Lab2 ->b; double bs = Lab2 ->b;
double Cs = sqrt( Sqr(as) + Sqr(bs) ); double Cs = sqrt( Sqr(as) + Sqr(bs) );
double G = 0.5 * ( 1 - sqrt(pow((C + Cs) / 2 , 7.0) / (pow((C + Cs) / 2, 7.0) + pow(25.0, 7.0) ) )); double G = 0.5 * ( 1 - sqrt(pow((C + Cs) / 2 , 7.0) / (pow((C + Cs) / 2, 7.0) + pow(25.0, 7.0) ) ));
double a_p = (1 + G ) * a1; double a_p = (1 + G ) * a1;
...@@ -390,15 +389,21 @@ double LCMSEXPORT cmsCIE2000DeltaE(LPcmsCIELab Lab1, LPcmsCIELab Lab2, ...@@ -390,15 +389,21 @@ double LCMSEXPORT cmsCIE2000DeltaE(LPcmsCIELab Lab1, LPcmsCIELab Lab2,
double C_ps = sqrt(Sqr(a_ps) + Sqr(b_ps)); double C_ps = sqrt(Sqr(a_ps) + Sqr(b_ps));
double h_ps = atan2deg(a_ps, b_ps); double h_ps = atan2deg(a_ps, b_ps);
double meanC_p =(C_p + C_ps) / 2;
double hps_plus_hp = h_ps + h_p;
double hps_minus_hp = h_ps - h_p;
double meanC_p =(C_p + C_ps) / 2; double meanh_p = fabs(hps_minus_hp) <= 180.000001 ? (hps_plus_hp)/2 :
(hps_plus_hp) < 360 ? (hps_plus_hp + 360)/2 :
(hps_plus_hp - 360)/2;
double meanh_p = fabs(h_ps-h_p) <= 180 ? (h_ps + h_p)/2 : (h_ps+h_p-360)/2; double delta_h = (hps_minus_hp) <= -180.000001 ? (hps_minus_hp + 360) :
(hps_minus_hp) > 180 ? (hps_minus_hp - 360) :
(hps_minus_hp);
double delta_L = (Ls - L1);
double delta_C = (C_ps - C_p );
double delta_h = fabs(h_p - h_ps) <= 180 ? fabs(h_p - h_ps) : 360 - fabs(h_p - h_ps);
double delta_L = fabs(L1 - Ls);
double delta_C = fabs(C_p - C_ps);
double delta_H =2 * sqrt(C_ps*C_p) * sin(RADIANES(delta_h) / 2); double delta_H =2 * sqrt(C_ps*C_p) * sin(RADIANES(delta_h) / 2);
...@@ -1065,7 +1070,7 @@ void SlopeLimiting(WORD Table[], int nEntries) ...@@ -1065,7 +1070,7 @@ void SlopeLimiting(WORD Table[], int nEntries)
// Check for monotonicity. // Check for monotonicity.
static static
BOOL IsMonotonic(LPGAMMATABLE t) LCMSBOOL IsMonotonic(LPGAMMATABLE t)
{ {
int n = t -> nEntries; int n = t -> nEntries;
int i, last; int i, last;
...@@ -1088,7 +1093,7 @@ BOOL IsMonotonic(LPGAMMATABLE t) ...@@ -1088,7 +1093,7 @@ BOOL IsMonotonic(LPGAMMATABLE t)
// Check for endpoints // Check for endpoints
static static
BOOL HasProperEndpoints(LPGAMMATABLE t) LCMSBOOL HasProperEndpoints(LPGAMMATABLE t)
{ {
if (t ->GammaTable[0] != 0) return FALSE; if (t ->GammaTable[0] != 0) return FALSE;
if (t ->GammaTable[t ->nEntries-1] != 0xFFFF) return FALSE; if (t ->GammaTable[t ->nEntries-1] != 0xFFFF) return FALSE;
...@@ -1109,7 +1114,7 @@ void _cmsComputePrelinearizationTablesFromXFORM(cmsHTRANSFORM h[], int nTransfor ...@@ -1109,7 +1114,7 @@ void _cmsComputePrelinearizationTablesFromXFORM(cmsHTRANSFORM h[], int nTransfor
unsigned int t, i, v; unsigned int t, i, v;
int j; int j;
WORD In[MAXCHANNELS], Out[MAXCHANNELS]; WORD In[MAXCHANNELS], Out[MAXCHANNELS];
BOOL lIsSuitable; LCMSBOOL lIsSuitable;
_LPcmsTRANSFORM InputXForm = (_LPcmsTRANSFORM) h[0]; _LPcmsTRANSFORM InputXForm = (_LPcmsTRANSFORM) h[0];
_LPcmsTRANSFORM OutputXForm = (_LPcmsTRANSFORM) h[nTransforms-1]; _LPcmsTRANSFORM OutputXForm = (_LPcmsTRANSFORM) h[nTransforms-1];
...@@ -1126,10 +1131,10 @@ void _cmsComputePrelinearizationTablesFromXFORM(cmsHTRANSFORM h[], int nTransfor ...@@ -1126,10 +1131,10 @@ void _cmsComputePrelinearizationTablesFromXFORM(cmsHTRANSFORM h[], int nTransfor
} }
// Do nothing on all but RGB to RGB transforms // Do nothing on all but Gray/RGB to Gray/RGB transforms
if ((InputXForm ->EntryColorSpace != icSigRgbData) || if (((InputXForm ->EntryColorSpace != icSigRgbData) && (InputXForm ->EntryColorSpace != icSigGrayData)) ||
(OutputXForm->ExitColorSpace != icSigRgbData)) return; ((OutputXForm->ExitColorSpace != icSigRgbData) && (OutputXForm->ExitColorSpace != icSigGrayData))) return;
for (t = 0; t < Grid -> InputChan; t++) for (t = 0; t < Grid -> InputChan; t++)
...@@ -1169,10 +1174,13 @@ void _cmsComputePrelinearizationTablesFromXFORM(cmsHTRANSFORM h[], int nTransfor ...@@ -1169,10 +1174,13 @@ void _cmsComputePrelinearizationTablesFromXFORM(cmsHTRANSFORM h[], int nTransfor
if (!HasProperEndpoints(Trans[t])) if (!HasProperEndpoints(Trans[t]))
lIsSuitable = FALSE; lIsSuitable = FALSE;
/*
// Exclude if transfer function is not smooth enough // Exclude if transfer function is not smooth enough
// to be modelled as a gamma function, or the gamma is reversed // to be modelled as a gamma function, or the gamma is reversed
if (cmsEstimateGamma(Trans[t]) < 1.0) if (cmsEstimateGamma(Trans[t]) < 1.0)
lIsSuitable = FALSE; lIsSuitable = FALSE;
*/
} }
......
...@@ -29,7 +29,7 @@ ...@@ -29,7 +29,7 @@
// //
// //
// Little cms // Little cms
// Copyright (C) 1998-2006 Marti Maria // Copyright (C) 1998-2007 Marti Maria
// //
// Permission is hereby granted, free of charge, to any person obtaining // Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the "Software"), // a copy of this software and associated documentation files (the "Software"),
...@@ -282,7 +282,7 @@ void Eval8Inputs(WORD StageABC[], WORD StageLMN[], WORD LutTable[], LPL16PARAMS ...@@ -282,7 +282,7 @@ void Eval8Inputs(WORD StageABC[], WORD StageLMN[], WORD LutTable[], LPL16PARAMS
// Fills optimization parameters // Fills optimization parameters
void cmsCalcCLUT16ParamsEx(int nSamples, int InputChan, int OutputChan, void cmsCalcCLUT16ParamsEx(int nSamples, int InputChan, int OutputChan,
BOOL lUseTetrahedral, LPL16PARAMS p) LCMSBOOL lUseTetrahedral, LPL16PARAMS p)
{ {
int clutPoints; int clutPoints;
...@@ -579,7 +579,7 @@ WORD cmsReverseLinearInterpLUT16(WORD Value, WORD LutTable[], LPL16PARAMS p) ...@@ -579,7 +579,7 @@ WORD cmsReverseLinearInterpLUT16(WORD Value, WORD LutTable[], LPL16PARAMS p)
// Identify if value fall downto 0 or FFFF zone // Identify if value fall downto 0 or FFFF zone
if (Value == 0) return 0; if (Value == 0) return 0;
if (Value == 0xFFFF) return 0xFFFF; // if (Value == 0xFFFF) return 0xFFFF;
// else restrict to valid zone // else restrict to valid zone
...@@ -631,7 +631,7 @@ WORD cmsReverseLinearInterpLUT16(WORD Value, WORD LutTable[], LPL16PARAMS p) ...@@ -631,7 +631,7 @@ WORD cmsReverseLinearInterpLUT16(WORD Value, WORD LutTable[], LPL16PARAMS p)
a = (y1 - y0) / (x1 - x0); a = (y1 - y0) / (x1 - x0);
b = y0 - a * x0; b = y0 - a * x0;
if (a == 0) return (WORD) x; if (fabs(a) < 0.01) return (WORD) x;
f = ((Value - b) / a); f = ((Value - b) / a);
...@@ -763,7 +763,7 @@ void cmsTrilinearInterp16(WORD Input[], WORD Output[], ...@@ -763,7 +763,7 @@ void cmsTrilinearInterp16(WORD Input[], WORD Output[],
X0 = p -> opta3 * x0; X0 = p -> opta3 * x0;
X1 = X0 + (Input[0] == 0xFFFFU ? 0 : p->opta3); X1 = X0 + (Input[0] == 0xFFFFU ? 0 : p->opta3);
Y0 = p -> opta2 * y0; Y0 = p -> opta2 * y0;
Y1 = Y0 + (Input[1] == 0xFFFFU ? 0 : p->opta2); Y1 = Y0 + (Input[1] == 0xFFFFU ? 0 : p->opta2);
Z0 = p -> opta1 * z0; Z0 = p -> opta1 * z0;
...@@ -942,7 +942,7 @@ void cmsTetrahedralInterp16(WORD Input[], ...@@ -942,7 +942,7 @@ void cmsTetrahedralInterp16(WORD Input[],
X0 = p -> opta3 * x0; X0 = p -> opta3 * x0;
X1 = X0 + (Input[0] == 0xFFFFU ? 0 : p->opta3); X1 = X0 + (Input[0] == 0xFFFFU ? 0 : p->opta3);
Y0 = p -> opta2 * y0; Y0 = p -> opta2 * y0;
Y1 = Y0 + (Input[1] == 0xFFFFU ? 0 : p->opta2); Y1 = Y0 + (Input[1] == 0xFFFFU ? 0 : p->opta2);
Z0 = p -> opta1 * z0; Z0 = p -> opta1 * z0;
...@@ -1009,11 +1009,11 @@ void cmsTetrahedralInterp16(WORD Input[], ...@@ -1009,11 +1009,11 @@ void cmsTetrahedralInterp16(WORD Input[],
Rest = c1 * rx + c2 * ry + c3 * rz; Rest = c1 * rx + c2 * ry + c3 * rz;
// There is a lot of math hidden in this expression. The rest is in fixed domain // There is a lot of math hidden in this expression. The rest is in fixed domain
// and the result in 0..ffff domain. So the complete expression should be // and the result in 0..ffff domain. So the complete expression should be
// ROUND_FIXED_TO_INT(ToFixedDomain(Rest)) But that can be optimized as (Rest + 0x7FFF) / 0xFFFF // ROUND_FIXED_TO_INT(ToFixedDomain(Rest)) But that can be optimized as (Rest + 0x7FFF) / 0xFFFF
Output[OutChan] = (WORD) (c0 + ((Rest + 0x7FFF) / 0xFFFF)); Output[OutChan] = (WORD) (c0 + ((Rest + 0x7FFF) / 0xFFFF));
} }
...@@ -1131,3 +1131,4 @@ void cmsTetrahedralInterp8(WORD Input[], ...@@ -1131,3 +1131,4 @@ void cmsTetrahedralInterp8(WORD Input[],
} }
#undef DENS #undef DENS
...@@ -29,7 +29,7 @@ ...@@ -29,7 +29,7 @@
// //
// //
// Little cms // Little cms
// Copyright (C) 1998-2006 Marti Maria // Copyright (C) 1998-2007 Marti Maria
// //
// Permission is hereby granted, free of charge, to any person obtaining // Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the "Software"), // a copy of this software and associated documentation files (the "Software"),
...@@ -62,7 +62,7 @@ ...@@ -62,7 +62,7 @@
typedef struct { typedef struct {
LPBYTE Block; // Points to allocated memory LPBYTE Block; // Points to allocated memory
size_t Size; // Size of allocated memory size_t Size; // Size of allocated memory
int Pointer; // Points to current location size_t Pointer; // Points to current location
int FreeBlockOnClose; // As title int FreeBlockOnClose; // As title
} FILEMEM; } FILEMEM;
...@@ -70,18 +70,19 @@ typedef struct { ...@@ -70,18 +70,19 @@ typedef struct {
static static
LPVOID MemoryOpen(LPBYTE Block, size_t Size, char Mode) LPVOID MemoryOpen(LPBYTE Block, size_t Size, char Mode)
{ {
FILEMEM* fm = (FILEMEM*) malloc(sizeof(FILEMEM)); FILEMEM* fm = (FILEMEM*) _cmsMalloc(sizeof(FILEMEM));
if (fm == NULL) return NULL;
ZeroMemory(fm, sizeof(FILEMEM)); ZeroMemory(fm, sizeof(FILEMEM));
if (Mode == 'r') { if (Mode == 'r') {
fm ->Block = (LPBYTE) malloc(Size); fm ->Block = (LPBYTE) _cmsMalloc(Size);
if (fm ->Block == NULL) { if (fm ->Block == NULL) {
free(fm); _cmsFree(fm);
return NULL; return NULL;
} }
CopyMemory(fm->Block, Block, Size); CopyMemory(fm->Block, Block, Size);
fm ->FreeBlockOnClose = TRUE; fm ->FreeBlockOnClose = TRUE;
} }
...@@ -103,13 +104,27 @@ size_t MemoryRead(LPVOID buffer, size_t size, size_t count, struct _lcms_iccprof ...@@ -103,13 +104,27 @@ size_t MemoryRead(LPVOID buffer, size_t size, size_t count, struct _lcms_iccprof
FILEMEM* ResData = (FILEMEM*) Icc ->stream; FILEMEM* ResData = (FILEMEM*) Icc ->stream;
LPBYTE Ptr; LPBYTE Ptr;
size_t len = size * count; size_t len = size * count;
size_t extent = ResData -> Pointer + len;
if (len == 0) {
return 0;
}
if (ResData -> Pointer + len > ResData -> Size){ if (len / size != count) {
cmsSignalError(LCMS_ERRC_ABORTED, "Read from memory error. Integer overflow with count / size.");
return 0;
}
len = (ResData -> Size - ResData -> Pointer); if (extent < len || extent < ResData -> Pointer) {
cmsSignalError(LCMS_ERRC_WARNING, "Read from memory error. Got %d bytes, block should be of %d bytes", len * size, count * size); cmsSignalError(LCMS_ERRC_ABORTED, "Read from memory error. Integer overflow with len.");
return 0;
}
if (ResData -> Pointer + len > ResData -> Size) {
len = (ResData -> Size - ResData -> Pointer);
cmsSignalError(LCMS_ERRC_ABORTED, "Read from memory error. Got %d bytes, block should be of %d bytes", len * size, count * size);
return 0;
} }
Ptr = ResData -> Block; Ptr = ResData -> Block;
...@@ -123,7 +138,7 @@ size_t MemoryRead(LPVOID buffer, size_t size, size_t count, struct _lcms_iccprof ...@@ -123,7 +138,7 @@ size_t MemoryRead(LPVOID buffer, size_t size, size_t count, struct _lcms_iccprof
// SEEK_CUR is assumed // SEEK_CUR is assumed
static static
BOOL MemorySeek(struct _lcms_iccprofile_struct* Icc, size_t offset) LCMSBOOL MemorySeek(struct _lcms_iccprofile_struct* Icc, size_t offset)
{ {
FILEMEM* ResData = (FILEMEM*) Icc ->stream; FILEMEM* ResData = (FILEMEM*) Icc ->stream;
...@@ -147,10 +162,10 @@ size_t MemoryTell(struct _lcms_iccprofile_struct* Icc) ...@@ -147,10 +162,10 @@ size_t MemoryTell(struct _lcms_iccprofile_struct* Icc)
} }
// Writes data to memory, also keeps used space for further reference // Writes data to memory, also keeps used space for further reference. NO CHECK IS PERFORMED
static static
BOOL MemoryWrite(struct _lcms_iccprofile_struct* Icc, size_t size, void *Ptr) LCMSBOOL MemoryWrite(struct _lcms_iccprofile_struct* Icc, size_t size, void *Ptr)
{ {
FILEMEM* ResData = (FILEMEM*) Icc ->stream; FILEMEM* ResData = (FILEMEM*) Icc ->stream;
...@@ -167,11 +182,17 @@ BOOL MemoryWrite(struct _lcms_iccprofile_struct* Icc, size_t size, void *Ptr) ...@@ -167,11 +182,17 @@ BOOL MemoryWrite(struct _lcms_iccprofile_struct* Icc, size_t size, void *Ptr)
static static
BOOL MemoryGrow(struct _lcms_iccprofile_struct* Icc, size_t size) LCMSBOOL MemoryGrow(struct _lcms_iccprofile_struct* Icc, size_t size)
{ {
FILEMEM* ResData = (FILEMEM*) Icc->stream; FILEMEM* ResData = (FILEMEM*) Icc->stream;
void* newBlock = realloc(ResData->Block, ResData->Size + size); void* newBlock = NULL;
/* Follow same policies as functions in lcms.h */
if (ResData->Size + size < 0) return NULL;
if (ResData->Size + size > (size_t)1024*1024*500))) return NULL;
newBlock = realloc(ResData->Block, ResData->Size + size);
if (!newBlock) { if (!newBlock) {
return FALSE; return FALSE;
...@@ -183,15 +204,15 @@ BOOL MemoryGrow(struct _lcms_iccprofile_struct* Icc, size_t size) ...@@ -183,15 +204,15 @@ BOOL MemoryGrow(struct _lcms_iccprofile_struct* Icc, size_t size)
static static
BOOL MemoryClose(struct _lcms_iccprofile_struct* Icc) LCMSBOOL MemoryClose(struct _lcms_iccprofile_struct* Icc)
{ {
FILEMEM* ResData = (FILEMEM*) Icc ->stream; FILEMEM* ResData = (FILEMEM*) Icc ->stream;
if (ResData ->FreeBlockOnClose) { if (ResData ->FreeBlockOnClose) {
if (ResData ->Block) free(ResData ->Block); if (ResData ->Block) _cmsFree(ResData ->Block);
} }
free(ResData); _cmsFree(ResData);
return 0; return 0;
} }
...@@ -209,7 +230,7 @@ size_t FileRead(void *buffer, size_t size, size_t count, struct _lcms_iccprofile ...@@ -209,7 +230,7 @@ size_t FileRead(void *buffer, size_t size, size_t count, struct _lcms_iccprofile
{ {
size_t nReaded = fread(buffer, size, count, (FILE*) Icc->stream); size_t nReaded = fread(buffer, size, count, (FILE*) Icc->stream);
if (nReaded != count) { if (nReaded != count) {
cmsSignalError(LCMS_ERRC_WARNING, "Read error. Got %d bytes, block should be of %d bytes", nReaded * size, count * size); cmsSignalError(LCMS_ERRC_ABORTED, "Read error. Got %d bytes, block should be of %d bytes", nReaded * size, count * size);
return 0; return 0;
} }
...@@ -218,7 +239,7 @@ size_t FileRead(void *buffer, size_t size, size_t count, struct _lcms_iccprofile ...@@ -218,7 +239,7 @@ size_t FileRead(void *buffer, size_t size, size_t count, struct _lcms_iccprofile
static static
BOOL FileSeek(struct _lcms_iccprofile_struct* Icc, size_t offset) LCMSBOOL FileSeek(struct _lcms_iccprofile_struct* Icc, size_t offset)
{ {
if (fseek((FILE*) Icc ->stream, (long) offset, SEEK_SET) != 0) { if (fseek((FILE*) Icc ->stream, (long) offset, SEEK_SET) != 0) {
...@@ -240,7 +261,7 @@ size_t FileTell(struct _lcms_iccprofile_struct* Icc) ...@@ -240,7 +261,7 @@ size_t FileTell(struct _lcms_iccprofile_struct* Icc)
static static
BOOL FileWrite(struct _lcms_iccprofile_struct* Icc, size_t size, LPVOID Ptr) LCMSBOOL FileWrite(struct _lcms_iccprofile_struct* Icc, size_t size, LPVOID Ptr)
{ {
if (size == 0) return TRUE; if (size == 0) return TRUE;
...@@ -256,14 +277,14 @@ BOOL FileWrite(struct _lcms_iccprofile_struct* Icc, size_t size, LPVOID Ptr) ...@@ -256,14 +277,14 @@ BOOL FileWrite(struct _lcms_iccprofile_struct* Icc, size_t size, LPVOID Ptr)
static static
BOOL FileGrow(struct _lcms_iccprofile_struct* Icc, size_t size) LCMSBOOL FileGrow(struct _lcms_iccprofile_struct* Icc, size_t size)
{ {
return TRUE; return TRUE;
} }
static static
BOOL FileClose(struct _lcms_iccprofile_struct* Icc) LCMSBOOL FileClose(struct _lcms_iccprofile_struct* Icc)
{ {
return fclose((FILE*) Icc ->stream); return fclose((FILE*) Icc ->stream);
} }
...@@ -276,7 +297,7 @@ BOOL FileClose(struct _lcms_iccprofile_struct* Icc) ...@@ -276,7 +297,7 @@ BOOL FileClose(struct _lcms_iccprofile_struct* Icc)
cmsHPROFILE _cmsCreateProfilePlaceholder(void) cmsHPROFILE _cmsCreateProfilePlaceholder(void)
{ {
LPLCMSICCPROFILE Icc = (LPLCMSICCPROFILE) malloc(sizeof(LCMSICCPROFILE)); LPLCMSICCPROFILE Icc = (LPLCMSICCPROFILE) _cmsMalloc(sizeof(LCMSICCPROFILE));
if (Icc == NULL) return NULL; if (Icc == NULL) return NULL;
// Empty values // Empty values
...@@ -314,7 +335,7 @@ icTagSignature LCMSEXPORT cmsGetTagSignature(cmsHPROFILE hProfile, icInt32Number ...@@ -314,7 +335,7 @@ icTagSignature LCMSEXPORT cmsGetTagSignature(cmsHPROFILE hProfile, icInt32Number
// Search for a specific tag in tag dictionary // Search for a specific tag in tag dictionary
// Returns position or -1 if tag not found // Returns position or -1 if tag not found
icInt32Number _cmsSearchTag(LPLCMSICCPROFILE Profile, icTagSignature sig, BOOL lSignalError) icInt32Number _cmsSearchTag(LPLCMSICCPROFILE Profile, icTagSignature sig, LCMSBOOL lSignalError)
{ {
icInt32Number i; icInt32Number i;
...@@ -335,7 +356,7 @@ icInt32Number _cmsSearchTag(LPLCMSICCPROFILE Profile, icTagSignature sig, BOOL l ...@@ -335,7 +356,7 @@ icInt32Number _cmsSearchTag(LPLCMSICCPROFILE Profile, icTagSignature sig, BOOL l
// Check existance // Check existance
BOOL LCMSEXPORT cmsIsTag(cmsHPROFILE hProfile, icTagSignature sig) LCMSBOOL LCMSEXPORT cmsIsTag(cmsHPROFILE hProfile, icTagSignature sig)
{ {
LPLCMSICCPROFILE Icc = (LPLCMSICCPROFILE) (LPSTR) hProfile; LPLCMSICCPROFILE Icc = (LPLCMSICCPROFILE) (LPSTR) hProfile;
return _cmsSearchTag(Icc, sig, FALSE) >= 0; return _cmsSearchTag(Icc, sig, FALSE) >= 0;
...@@ -354,7 +375,7 @@ LPVOID _cmsInitTag(LPLCMSICCPROFILE Icc, icTagSignature sig, size_t size, const ...@@ -354,7 +375,7 @@ LPVOID _cmsInitTag(LPLCMSICCPROFILE Icc, icTagSignature sig, size_t size, const
if (i >=0) { if (i >=0) {
if (Icc -> TagPtrs[i]) free(Icc -> TagPtrs[i]); if (Icc -> TagPtrs[i]) _cmsFree(Icc -> TagPtrs[i]);
} }
else { else {
...@@ -365,11 +386,14 @@ LPVOID _cmsInitTag(LPLCMSICCPROFILE Icc, icTagSignature sig, size_t size, const ...@@ -365,11 +386,14 @@ LPVOID _cmsInitTag(LPLCMSICCPROFILE Icc, icTagSignature sig, size_t size, const
cmsSignalError(LCMS_ERRC_ABORTED, "Too many tags (%d)", MAX_TABLE_TAG); cmsSignalError(LCMS_ERRC_ABORTED, "Too many tags (%d)", MAX_TABLE_TAG);
Icc ->TagCount = MAX_TABLE_TAG-1; Icc ->TagCount = MAX_TABLE_TAG-1;
return NULL;
} }
} }
Ptr = malloc(size); Ptr = _cmsMalloc(size);
if (Ptr == NULL) return NULL;
CopyMemory(Ptr, Init, size); CopyMemory(Ptr, Init, size);
Icc ->TagNames[i] = sig; Icc ->TagNames[i] = sig;
...@@ -400,6 +424,8 @@ LPLCMSICCPROFILE _cmsCreateProfileFromFilePlaceholder(const char* FileName) ...@@ -400,6 +424,8 @@ LPLCMSICCPROFILE _cmsCreateProfileFromFilePlaceholder(const char* FileName)
if (NewIcc == NULL) return NULL; if (NewIcc == NULL) return NULL;
strncpy(NewIcc -> PhysicalFile, FileName, MAX_PATH-1); strncpy(NewIcc -> PhysicalFile, FileName, MAX_PATH-1);
NewIcc -> PhysicalFile[MAX_PATH-1] = 0;
NewIcc ->stream = ICCfile; NewIcc ->stream = ICCfile;
NewIcc ->Read = FileRead; NewIcc ->Read = FileRead;
...@@ -502,7 +528,7 @@ void _cmsSetSaveToMemory(LPLCMSICCPROFILE Icc, LPVOID MemPtr, size_t dwSize) ...@@ -502,7 +528,7 @@ void _cmsSetSaveToMemory(LPLCMSICCPROFILE Icc, LPVOID MemPtr, size_t dwSize)
BOOL LCMSEXPORT cmsTakeMediaWhitePoint(LPcmsCIEXYZ Dest, cmsHPROFILE hProfile) LCMSBOOL LCMSEXPORT cmsTakeMediaWhitePoint(LPcmsCIEXYZ Dest, cmsHPROFILE hProfile)
{ {
LPLCMSICCPROFILE Icc = (LPLCMSICCPROFILE) hProfile; LPLCMSICCPROFILE Icc = (LPLCMSICCPROFILE) hProfile;
*Dest = Icc -> MediaWhitePoint; *Dest = Icc -> MediaWhitePoint;
...@@ -510,14 +536,14 @@ BOOL LCMSEXPORT cmsTakeMediaWhitePoint(LPcmsCIEXYZ Dest, cmsHPROFILE hProfile) ...@@ -510,14 +536,14 @@ BOOL LCMSEXPORT cmsTakeMediaWhitePoint(LPcmsCIEXYZ Dest, cmsHPROFILE hProfile)
} }
BOOL LCMSEXPORT cmsTakeMediaBlackPoint(LPcmsCIEXYZ Dest, cmsHPROFILE hProfile) LCMSBOOL LCMSEXPORT cmsTakeMediaBlackPoint(LPcmsCIEXYZ Dest, cmsHPROFILE hProfile)
{ {
LPLCMSICCPROFILE Icc = (LPLCMSICCPROFILE) hProfile; LPLCMSICCPROFILE Icc = (LPLCMSICCPROFILE) hProfile;
*Dest = Icc -> MediaBlackPoint; *Dest = Icc -> MediaBlackPoint;
return TRUE; return TRUE;
} }
BOOL LCMSEXPORT cmsTakeIluminant(LPcmsCIEXYZ Dest, cmsHPROFILE hProfile) LCMSBOOL LCMSEXPORT cmsTakeIluminant(LPcmsCIEXYZ Dest, cmsHPROFILE hProfile)
{ {
LPLCMSICCPROFILE Icc = (LPLCMSICCPROFILE) hProfile; LPLCMSICCPROFILE Icc = (LPLCMSICCPROFILE) hProfile;
*Dest = Icc -> Illuminant; *Dest = Icc -> Illuminant;
...@@ -575,7 +601,7 @@ void LCMSEXPORT cmsSetProfileID(cmsHPROFILE hProfile, LPBYTE ProfileID) ...@@ -575,7 +601,7 @@ void LCMSEXPORT cmsSetProfileID(cmsHPROFILE hProfile, LPBYTE ProfileID)
} }
BOOL LCMSEXPORT cmsTakeCreationDateTime(struct tm *Dest, cmsHPROFILE hProfile) LCMSBOOL LCMSEXPORT cmsTakeCreationDateTime(struct tm *Dest, cmsHPROFILE hProfile)
{ {
LPLCMSICCPROFILE Icc = (LPLCMSICCPROFILE) (LPSTR) hProfile; LPLCMSICCPROFILE Icc = (LPLCMSICCPROFILE) (LPSTR) hProfile;
CopyMemory(Dest, &Icc ->Created, sizeof(struct tm)); CopyMemory(Dest, &Icc ->Created, sizeof(struct tm));
...@@ -596,23 +622,18 @@ void LCMSEXPORT cmsSetPCS(cmsHPROFILE hProfile, icColorSpaceSignature pcs) ...@@ -596,23 +622,18 @@ void LCMSEXPORT cmsSetPCS(cmsHPROFILE hProfile, icColorSpaceSignature pcs)
Icc -> PCS = pcs; Icc -> PCS = pcs;
} }
icColorSpaceSignature LCMSEXPORT cmsGetColorSpace(cmsHPROFILE hProfile) icColorSpaceSignature LCMSEXPORT cmsGetColorSpace(cmsHPROFILE hProfile)
{ {
LPLCMSICCPROFILE Icc = (LPLCMSICCPROFILE) hProfile; LPLCMSICCPROFILE Icc = (LPLCMSICCPROFILE) hProfile;
return Icc -> ColorSpace; return Icc -> ColorSpace;
} }
void LCMSEXPORT cmsSetColorSpace(cmsHPROFILE hProfile, icColorSpaceSignature sig) void LCMSEXPORT cmsSetColorSpace(cmsHPROFILE hProfile, icColorSpaceSignature sig)
{ {
LPLCMSICCPROFILE Icc = (LPLCMSICCPROFILE) hProfile; LPLCMSICCPROFILE Icc = (LPLCMSICCPROFILE) hProfile;
Icc -> ColorSpace = sig; Icc -> ColorSpace = sig;
} }
icProfileClassSignature LCMSEXPORT cmsGetDeviceClass(cmsHPROFILE hProfile) icProfileClassSignature LCMSEXPORT cmsGetDeviceClass(cmsHPROFILE hProfile)
{ {
LPLCMSICCPROFILE Icc = (LPLCMSICCPROFILE) hProfile; LPLCMSICCPROFILE Icc = (LPLCMSICCPROFILE) hProfile;
...@@ -625,7 +646,6 @@ DWORD LCMSEXPORT cmsGetProfileICCversion(cmsHPROFILE hProfile) ...@@ -625,7 +646,6 @@ DWORD LCMSEXPORT cmsGetProfileICCversion(cmsHPROFILE hProfile)
return (DWORD) Icc -> Version; return (DWORD) Icc -> Version;
} }
void LCMSEXPORT cmsSetProfileICCversion(cmsHPROFILE hProfile, DWORD Version) void LCMSEXPORT cmsSetProfileICCversion(cmsHPROFILE hProfile, DWORD Version)
{ {
LPLCMSICCPROFILE Icc = (LPLCMSICCPROFILE) hProfile; LPLCMSICCPROFILE Icc = (LPLCMSICCPROFILE) hProfile;
...@@ -664,7 +684,7 @@ LPVOID DupBlock(LPLCMSICCPROFILE Icc, LPVOID Block, size_t size) ...@@ -664,7 +684,7 @@ LPVOID DupBlock(LPLCMSICCPROFILE Icc, LPVOID Block, size_t size)
// This is tricky, since LUT structs does have pointers // This is tricky, since LUT structs does have pointers
BOOL LCMSEXPORT _cmsAddLUTTag(cmsHPROFILE hProfile, icTagSignature sig, const void* lut) LCMSBOOL LCMSEXPORT _cmsAddLUTTag(cmsHPROFILE hProfile, icTagSignature sig, const void* lut)
{ {
LPLCMSICCPROFILE Icc = (LPLCMSICCPROFILE) (LPSTR) hProfile; LPLCMSICCPROFILE Icc = (LPLCMSICCPROFILE) (LPSTR) hProfile;
LPLUT Orig, Stored; LPLUT Orig, Stored;
...@@ -692,7 +712,7 @@ BOOL LCMSEXPORT _cmsAddLUTTag(cmsHPROFILE hProfile, icTagSignature sig, const vo ...@@ -692,7 +712,7 @@ BOOL LCMSEXPORT _cmsAddLUTTag(cmsHPROFILE hProfile, icTagSignature sig, const vo
} }
BOOL LCMSEXPORT _cmsAddXYZTag(cmsHPROFILE hProfile, icTagSignature sig, const cmsCIEXYZ* XYZ) LCMSBOOL LCMSEXPORT _cmsAddXYZTag(cmsHPROFILE hProfile, icTagSignature sig, const cmsCIEXYZ* XYZ)
{ {
LPLCMSICCPROFILE Icc = (LPLCMSICCPROFILE) (LPSTR) hProfile; LPLCMSICCPROFILE Icc = (LPLCMSICCPROFILE) (LPSTR) hProfile;
...@@ -701,7 +721,7 @@ BOOL LCMSEXPORT _cmsAddXYZTag(cmsHPROFILE hProfile, icTagSignature sig, const cm ...@@ -701,7 +721,7 @@ BOOL LCMSEXPORT _cmsAddXYZTag(cmsHPROFILE hProfile, icTagSignature sig, const cm
} }
BOOL LCMSEXPORT _cmsAddTextTag(cmsHPROFILE hProfile, icTagSignature sig, const char* Text) LCMSBOOL LCMSEXPORT _cmsAddTextTag(cmsHPROFILE hProfile, icTagSignature sig, const char* Text)
{ {
LPLCMSICCPROFILE Icc = (LPLCMSICCPROFILE) (LPSTR) hProfile; LPLCMSICCPROFILE Icc = (LPLCMSICCPROFILE) (LPSTR) hProfile;
...@@ -709,7 +729,7 @@ BOOL LCMSEXPORT _cmsAddTextTag(cmsHPROFILE hProfile, icTagSignature sig, const c ...@@ -709,7 +729,7 @@ BOOL LCMSEXPORT _cmsAddTextTag(cmsHPROFILE hProfile, icTagSignature sig, const c
return TRUE; return TRUE;
} }
BOOL LCMSEXPORT _cmsAddGammaTag(cmsHPROFILE hProfile, icTagSignature sig, LPGAMMATABLE TransferFunction) LCMSBOOL LCMSEXPORT _cmsAddGammaTag(cmsHPROFILE hProfile, icTagSignature sig, LPGAMMATABLE TransferFunction)
{ {
LPLCMSICCPROFILE Icc = (LPLCMSICCPROFILE) (LPSTR) hProfile; LPLCMSICCPROFILE Icc = (LPLCMSICCPROFILE) (LPSTR) hProfile;
...@@ -718,7 +738,7 @@ BOOL LCMSEXPORT _cmsAddGammaTag(cmsHPROFILE hProfile, icTagSignature sig, LPGAMM ...@@ -718,7 +738,7 @@ BOOL LCMSEXPORT _cmsAddGammaTag(cmsHPROFILE hProfile, icTagSignature sig, LPGAMM
} }
BOOL LCMSEXPORT _cmsAddChromaticityTag(cmsHPROFILE hProfile, icTagSignature sig, LPcmsCIExyYTRIPLE Chrm) LCMSBOOL LCMSEXPORT _cmsAddChromaticityTag(cmsHPROFILE hProfile, icTagSignature sig, LPcmsCIExyYTRIPLE Chrm)
{ {
LPLCMSICCPROFILE Icc = (LPLCMSICCPROFILE) (LPSTR) hProfile; LPLCMSICCPROFILE Icc = (LPLCMSICCPROFILE) (LPSTR) hProfile;
...@@ -727,7 +747,7 @@ BOOL LCMSEXPORT _cmsAddChromaticityTag(cmsHPROFILE hProfile, icTagSignature sig, ...@@ -727,7 +747,7 @@ BOOL LCMSEXPORT _cmsAddChromaticityTag(cmsHPROFILE hProfile, icTagSignature sig,
} }
BOOL LCMSEXPORT _cmsAddSequenceDescriptionTag(cmsHPROFILE hProfile, icTagSignature sig, LPcmsSEQ pseq) LCMSBOOL LCMSEXPORT _cmsAddSequenceDescriptionTag(cmsHPROFILE hProfile, icTagSignature sig, LPcmsSEQ pseq)
{ {
LPLCMSICCPROFILE Icc = (LPLCMSICCPROFILE) (LPSTR) hProfile; LPLCMSICCPROFILE Icc = (LPLCMSICCPROFILE) (LPSTR) hProfile;
...@@ -737,28 +757,40 @@ BOOL LCMSEXPORT _cmsAddSequenceDescriptionTag(cmsHPROFILE hProfile, icTagSignatu ...@@ -737,28 +757,40 @@ BOOL LCMSEXPORT _cmsAddSequenceDescriptionTag(cmsHPROFILE hProfile, icTagSignatu
} }
BOOL LCMSEXPORT _cmsAddNamedColorTag(cmsHPROFILE hProfile, icTagSignature sig, LPcmsNAMEDCOLORLIST nc) LCMSBOOL LCMSEXPORT _cmsAddNamedColorTag(cmsHPROFILE hProfile, icTagSignature sig, LPcmsNAMEDCOLORLIST nc)
{ {
LPLCMSICCPROFILE Icc = (LPLCMSICCPROFILE) (LPSTR) hProfile; LPLCMSICCPROFILE Icc = (LPLCMSICCPROFILE) (LPSTR) hProfile;
_cmsInitTag(Icc, sig, sizeof(cmsNAMEDCOLORLIST) + (nc ->nColors - 1) * sizeof(cmsNAMEDCOLOR), nc); _cmsInitTag(Icc, sig, sizeof(cmsNAMEDCOLORLIST) + (nc ->nColors - 1) * sizeof(cmsNAMEDCOLOR), nc);
return FALSE; return TRUE;
} }
BOOL LCMSEXPORT _cmsAddDateTimeTag(cmsHPROFILE hProfile, icTagSignature sig, struct tm *DateTime) LCMSBOOL LCMSEXPORT _cmsAddDateTimeTag(cmsHPROFILE hProfile, icTagSignature sig, struct tm *DateTime)
{ {
LPLCMSICCPROFILE Icc = (LPLCMSICCPROFILE) (LPSTR) hProfile; LPLCMSICCPROFILE Icc = (LPLCMSICCPROFILE) (LPSTR) hProfile;
_cmsInitTag(Icc, sig, sizeof(struct tm), DateTime); _cmsInitTag(Icc, sig, sizeof(struct tm), DateTime);
return FALSE; return TRUE;
} }
BOOL LCMSEXPORT _cmsAddColorantTableTag(cmsHPROFILE hProfile, icTagSignature sig, LPcmsNAMEDCOLORLIST nc) LCMSBOOL LCMSEXPORT _cmsAddColorantTableTag(cmsHPROFILE hProfile, icTagSignature sig, LPcmsNAMEDCOLORLIST nc)
{ {
LPLCMSICCPROFILE Icc = (LPLCMSICCPROFILE) (LPSTR) hProfile; LPLCMSICCPROFILE Icc = (LPLCMSICCPROFILE) (LPSTR) hProfile;
_cmsInitTag(Icc, sig, sizeof(cmsNAMEDCOLORLIST) + (nc ->nColors - 1) * sizeof(cmsNAMEDCOLOR), nc); _cmsInitTag(Icc, sig, sizeof(cmsNAMEDCOLORLIST) + (nc ->nColors - 1) * sizeof(cmsNAMEDCOLOR), nc);
return FALSE; return TRUE;
}
LCMSBOOL LCMSEXPORT _cmsAddChromaticAdaptationTag(cmsHPROFILE hProfile, icTagSignature sig, const cmsCIEXYZ* mat)
{
LPLCMSICCPROFILE Icc = (LPLCMSICCPROFILE) (LPSTR) hProfile;
_cmsInitTag(Icc, sig, 3*sizeof(cmsCIEXYZ), mat);
return TRUE;
} }
...@@ -29,7 +29,7 @@ ...@@ -29,7 +29,7 @@
// //
// //
// Little cms // Little cms
// Copyright (C) 1998-2006 Marti Maria // Copyright (C) 1998-2007 Marti Maria
// //
// Permission is hereby granted, free of charge, to any person obtaining // Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the "Software"), // a copy of this software and associated documentation files (the "Software"),
...@@ -118,7 +118,7 @@ LPLUT LCMSEXPORT cmsAllocLUT(void) ...@@ -118,7 +118,7 @@ LPLUT LCMSEXPORT cmsAllocLUT(void)
{ {
LPLUT NewLUT; LPLUT NewLUT;
NewLUT = (LPLUT) malloc(sizeof(LUT)); NewLUT = (LPLUT) _cmsMalloc(sizeof(LUT));
if (NewLUT) if (NewLUT)
ZeroMemory(NewLUT, sizeof(LUT)); ZeroMemory(NewLUT, sizeof(LUT));
...@@ -171,9 +171,10 @@ void LCMSEXPORT cmsFreeLUT(LPLUT Lut) ...@@ -171,9 +171,10 @@ void LCMSEXPORT cmsFreeLUT(LPLUT Lut)
static static
LPVOID DupBlockTab(LPVOID Org, size_t size) LPVOID DupBlockTab(LPVOID Org, size_t size)
{ {
LPVOID mem = malloc(size); LPVOID mem = _cmsMalloc(size);
if (mem != NULL)
CopyMemory(mem, Org, size);
CopyMemory(mem, Org, size);
return mem; return mem;
} }
...@@ -211,6 +212,37 @@ unsigned int UIpow(unsigned int a, unsigned int b) ...@@ -211,6 +212,37 @@ unsigned int UIpow(unsigned int a, unsigned int b)
} }
LCMSBOOL _cmsValidateLUT(LPLUT NewLUT)
{
unsigned int calc = 1;
unsigned int oldCalc;
unsigned int power = NewLUT -> InputChan;
if (NewLUT -> cLutPoints > 100) return FALSE;
if (NewLUT -> InputChan > MAXCHANNELS) return FALSE;
if (NewLUT -> OutputChan > MAXCHANNELS) return FALSE;
if (NewLUT -> cLutPoints == 0) return TRUE;
for (; power > 0; power--) {
oldCalc = calc;
calc *= NewLUT -> cLutPoints;
if (calc / NewLUT -> cLutPoints != oldCalc) {
return FALSE;
}
}
oldCalc = calc;
calc *= NewLUT -> OutputChan;
if (NewLUT -> OutputChan && calc / NewLUT -> OutputChan != oldCalc) {
return FALSE;
}
return TRUE;
}
LPLUT LCMSEXPORT cmsAlloc3DGrid(LPLUT NewLUT, int clutPoints, int inputChan, int outputChan) LPLUT LCMSEXPORT cmsAlloc3DGrid(LPLUT NewLUT, int clutPoints, int inputChan, int outputChan)
{ {
DWORD nTabSize; DWORD nTabSize;
...@@ -220,12 +252,17 @@ LPLUT LCMSEXPORT cmsAlloc3DGrid(LPLUT NewLUT, int clutPoints, int inputChan, int ...@@ -220,12 +252,17 @@ LPLUT LCMSEXPORT cmsAlloc3DGrid(LPLUT NewLUT, int clutPoints, int inputChan, int
NewLUT -> InputChan = inputChan; NewLUT -> InputChan = inputChan;
NewLUT -> OutputChan = outputChan; NewLUT -> OutputChan = outputChan;
if (!_cmsValidateLUT(NewLUT)) {
return NULL;
}
nTabSize = NewLUT -> OutputChan * UIpow(NewLUT->cLutPoints,
NewLUT->InputChan);
nTabSize = (NewLUT -> OutputChan * UIpow(NewLUT->cLutPoints, NewLUT -> T = (LPWORD) _cmsCalloc(sizeof(WORD), nTabSize);
NewLUT->InputChan) nTabSize *= sizeof(WORD);
* sizeof(WORD)); if (NewLUT -> T == NULL) return NULL;
NewLUT -> T = (LPWORD) malloc(nTabSize);
ZeroMemory(NewLUT -> T, nTabSize); ZeroMemory(NewLUT -> T, nTabSize);
NewLUT ->Tsize = nTabSize; NewLUT ->Tsize = nTabSize;
...@@ -254,10 +291,12 @@ LPLUT LCMSEXPORT cmsAllocLinearTable(LPLUT NewLUT, LPGAMMATABLE Tables[], int nT ...@@ -254,10 +291,12 @@ LPLUT LCMSEXPORT cmsAllocLinearTable(LPLUT NewLUT, LPGAMMATABLE Tables[], int nT
for (i=0; i < NewLUT -> InputChan; i++) { for (i=0; i < NewLUT -> InputChan; i++) {
PtrW = (LPWORD) malloc(sizeof(WORD) * NewLUT -> InputEntries); PtrW = (LPWORD) _cmsMalloc(sizeof(WORD) * NewLUT -> InputEntries);
if (PtrW == NULL) return NULL;
NewLUT -> L1[i] = PtrW; NewLUT -> L1[i] = PtrW;
CopyMemory(PtrW, Tables[i]->GammaTable, sizeof(WORD) * NewLUT -> InputEntries); CopyMemory(PtrW, Tables[i]->GammaTable, sizeof(WORD) * NewLUT -> InputEntries);
CopyMemory(&NewLUT -> LCurvesSeed[0][i], &Tables[i] -> Seed, sizeof(LCMSGAMMAPARAMS)); CopyMemory(&NewLUT -> LCurvesSeed[0][i], &Tables[i] -> Seed, sizeof(LCMSGAMMAPARAMS));
} }
...@@ -268,10 +307,12 @@ LPLUT LCMSEXPORT cmsAllocLinearTable(LPLUT NewLUT, LPGAMMATABLE Tables[], int nT ...@@ -268,10 +307,12 @@ LPLUT LCMSEXPORT cmsAllocLinearTable(LPLUT NewLUT, LPGAMMATABLE Tables[], int nT
NewLUT -> OutputEntries = Tables[0] -> nEntries; NewLUT -> OutputEntries = Tables[0] -> nEntries;
for (i=0; i < NewLUT -> OutputChan; i++) { for (i=0; i < NewLUT -> OutputChan; i++) {
PtrW = (LPWORD) malloc(sizeof(WORD) * NewLUT -> OutputEntries); PtrW = (LPWORD) _cmsMalloc(sizeof(WORD) * NewLUT -> OutputEntries);
if (PtrW == NULL) return NULL;
NewLUT -> L2[i] = PtrW; NewLUT -> L2[i] = PtrW;
CopyMemory(PtrW, Tables[i]->GammaTable, sizeof(WORD) * NewLUT -> OutputEntries); CopyMemory(PtrW, Tables[i]->GammaTable, sizeof(WORD) * NewLUT -> OutputEntries);
CopyMemory(&NewLUT -> LCurvesSeed[1][i], &Tables[i] -> Seed, sizeof(LCMSGAMMAPARAMS)); CopyMemory(&NewLUT -> LCurvesSeed[1][i], &Tables[i] -> Seed, sizeof(LCMSGAMMAPARAMS));
} }
break; break;
...@@ -285,10 +326,12 @@ LPLUT LCMSEXPORT cmsAllocLinearTable(LPLUT NewLUT, LPGAMMATABLE Tables[], int nT ...@@ -285,10 +326,12 @@ LPLUT LCMSEXPORT cmsAllocLinearTable(LPLUT NewLUT, LPGAMMATABLE Tables[], int nT
for (i=0; i < NewLUT -> InputChan; i++) { for (i=0; i < NewLUT -> InputChan; i++) {
PtrW = (LPWORD) malloc(sizeof(WORD) * NewLUT -> L3Entries); PtrW = (LPWORD) _cmsMalloc(sizeof(WORD) * NewLUT -> L3Entries);
if (PtrW == NULL) return NULL;
NewLUT -> L3[i] = PtrW; NewLUT -> L3[i] = PtrW;
CopyMemory(PtrW, Tables[i]->GammaTable, sizeof(WORD) * NewLUT -> L3Entries); CopyMemory(PtrW, Tables[i]->GammaTable, sizeof(WORD) * NewLUT -> L3Entries);
CopyMemory(&NewLUT -> LCurvesSeed[2][i], &Tables[i] -> Seed, sizeof(LCMSGAMMAPARAMS)); CopyMemory(&NewLUT -> LCurvesSeed[2][i], &Tables[i] -> Seed, sizeof(LCMSGAMMAPARAMS));
} }
break; break;
...@@ -298,10 +341,12 @@ LPLUT LCMSEXPORT cmsAllocLinearTable(LPLUT NewLUT, LPGAMMATABLE Tables[], int nT ...@@ -298,10 +341,12 @@ LPLUT LCMSEXPORT cmsAllocLinearTable(LPLUT NewLUT, LPGAMMATABLE Tables[], int nT
NewLUT -> L4Entries = Tables[0] -> nEntries; NewLUT -> L4Entries = Tables[0] -> nEntries;
for (i=0; i < NewLUT -> OutputChan; i++) { for (i=0; i < NewLUT -> OutputChan; i++) {
PtrW = (LPWORD) malloc(sizeof(WORD) * NewLUT -> L4Entries); PtrW = (LPWORD) _cmsMalloc(sizeof(WORD) * NewLUT -> L4Entries);
if (PtrW == NULL) return NULL;
NewLUT -> L4[i] = PtrW; NewLUT -> L4[i] = PtrW;
CopyMemory(PtrW, Tables[i]->GammaTable, sizeof(WORD) * NewLUT -> L4Entries); CopyMemory(PtrW, Tables[i]->GammaTable, sizeof(WORD) * NewLUT -> L4Entries);
CopyMemory(&NewLUT -> LCurvesSeed[3][i], &Tables[i] -> Seed, sizeof(LCMSGAMMAPARAMS)); CopyMemory(&NewLUT -> LCurvesSeed[3][i], &Tables[i] -> Seed, sizeof(LCMSGAMMAPARAMS));
} }
break; break;
...@@ -580,7 +625,7 @@ LPLUT _cmsBlessLUT8(LPLUT Lut) ...@@ -580,7 +625,7 @@ LPLUT _cmsBlessLUT8(LPLUT Lut)
LPL16PARAMS p = &Lut ->CLut16params; LPL16PARAMS p = &Lut ->CLut16params;
p8 = (LPL8PARAMS) malloc(sizeof(L8PARAMS)); p8 = (LPL8PARAMS) _cmsMalloc(sizeof(L8PARAMS));
if (p8 == NULL) return NULL; if (p8 == NULL) return NULL;
// values comes * 257, so we can safely take first byte (x << 8 + x) // values comes * 257, so we can safely take first byte (x << 8 + x)
...@@ -593,8 +638,8 @@ LPLUT _cmsBlessLUT8(LPLUT Lut) ...@@ -593,8 +638,8 @@ LPLUT _cmsBlessLUT8(LPLUT Lut)
if (Lut ->wFlags & LUT_HASTL1) { if (Lut ->wFlags & LUT_HASTL1) {
for (j=0; j < 3; j++) for (j=0; j < 3; j++)
StageABC[i] = cmsLinearInterpLUT16(StageABC[i], StageABC[j] = cmsLinearInterpLUT16(StageABC[j],
Lut -> L1[i], Lut -> L1[j],
&Lut -> In16params); &Lut -> In16params);
Lut ->wFlags &= ~LUT_HASTL1; Lut ->wFlags &= ~LUT_HASTL1;
} }
...@@ -697,7 +742,7 @@ void EvalLUTdoubleKLab(LPLUT Lut, const VEC3* In, WORD FixedK, LPcmsCIELab Out) ...@@ -697,7 +742,7 @@ void EvalLUTdoubleKLab(LPLUT Lut, const VEC3* In, WORD FixedK, LPcmsCIELab Out)
wIn[3] = FixedK; wIn[3] = FixedK;
cmsEvalLUT(Lut, wIn, wOut); cmsEvalLUT(Lut, wIn, wOut);
cmsLabEncoded2Float(Out, wOut); cmsLabEncoded2Float(Out, wOut);
} }
// Builds a Jacobian CMY->Lab // Builds a Jacobian CMY->Lab
...@@ -722,9 +767,9 @@ void ComputeJacobianLab(LPLUT Lut, LPMAT3 Jacobian, const VEC3* Colorant, WORD K ...@@ -722,9 +767,9 @@ void ComputeJacobianLab(LPLUT Lut, LPMAT3 Jacobian, const VEC3* Colorant, WORD K
EvalLUTdoubleKLab(Lut, &ColorantD, K, &LabD); EvalLUTdoubleKLab(Lut, &ColorantD, K, &LabD);
Jacobian->v[0].n[j] = ((LabD.L - Lab.L) / JACOBIAN_EPSILON); Jacobian->v[0].n[j] = ((LabD.L - Lab.L) / JACOBIAN_EPSILON);
Jacobian->v[1].n[j] = ((LabD.a - Lab.a) / JACOBIAN_EPSILON); Jacobian->v[1].n[j] = ((LabD.a - Lab.a) / JACOBIAN_EPSILON);
Jacobian->v[2].n[j] = ((LabD.b - Lab.b) / JACOBIAN_EPSILON); Jacobian->v[2].n[j] = ((LabD.b - Lab.b) / JACOBIAN_EPSILON);
} }
} }
...@@ -797,18 +842,18 @@ LCMSAPI double LCMSEXPORT cmsEvalLUTreverse(LPLUT Lut, WORD Target[], WORD Resul ...@@ -797,18 +842,18 @@ LCMSAPI double LCMSEXPORT cmsEvalLUTreverse(LPLUT Lut, WORD Target[], WORD Resul
// Obtain slope // Obtain slope
ComputeJacobianLab(Lut, &Jacobian, &x, FixedK); ComputeJacobianLab(Lut, &Jacobian, &x, FixedK);
// Solve system // Solve system
tmp2.n[0] = fx.L - Goal.L; tmp2.n[0] = fx.L - Goal.L;
tmp2.n[1] = fx.a - Goal.a; tmp2.n[1] = fx.a - Goal.a;
tmp2.n[2] = fx.b - Goal.b; tmp2.n[2] = fx.b - Goal.b;
if (!MAT3solve(&tmp, &Jacobian, &tmp2)) if (!MAT3solve(&tmp, &Jacobian, &tmp2))
break; break;
// Move our guess // Move our guess
x.n[0] -= tmp.n[0]; x.n[0] -= tmp.n[0];
x.n[1] -= tmp.n[1]; x.n[1] -= tmp.n[1];
x.n[2] -= tmp.n[2]; x.n[2] -= tmp.n[2];
// Some clipping.... // Some clipping....
VEC3saturate(&x); VEC3saturate(&x);
...@@ -822,3 +867,6 @@ LCMSAPI double LCMSEXPORT cmsEvalLUTreverse(LPLUT Lut, WORD Target[], WORD Resul ...@@ -822,3 +867,6 @@ LCMSAPI double LCMSEXPORT cmsEvalLUTreverse(LPLUT Lut, WORD Target[], WORD Resul
return LastError; return LastError;
} }
...@@ -29,7 +29,7 @@ ...@@ -29,7 +29,7 @@
// //
// //
// Little cms // Little cms
// Copyright (C) 1998-2006 Marti Maria // Copyright (C) 1998-2007 Marti Maria
// //
// Permission is hereby granted, free of charge, to any person obtaining // Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the "Software"), // a copy of this software and associated documentation files (the "Software"),
...@@ -62,6 +62,7 @@ ...@@ -62,6 +62,7 @@
// data yet in fixed point, so no additional process is required. // data yet in fixed point, so no additional process is required.
// Then, we obtain data on 15.16, so we need to shift >> by 1 to // Then, we obtain data on 15.16, so we need to shift >> by 1 to
// obtain 1.15 PCS format. // obtain 1.15 PCS format.
// On OUTPUT profiles, things are inverse, we must first expand 1 bit // On OUTPUT profiles, things are inverse, we must first expand 1 bit
// by shifting left, and then convert result between 0 and 1.000 to // by shifting left, and then convert result between 0 and 1.000 to
// RGB, so FromFixedDomain() must be called before pass values to // RGB, so FromFixedDomain() must be called before pass values to
...@@ -71,6 +72,7 @@ ...@@ -71,6 +72,7 @@
// input is encoded from 0 to 0xffff, we must first use the shaper and // input is encoded from 0 to 0xffff, we must first use the shaper and
// then the matrix, an additional FromFixedDomain() must be used to // then the matrix, an additional FromFixedDomain() must be used to
// accomodate output values. // accomodate output values.
// For a sake of simplicity, I will handle this three behaviours // For a sake of simplicity, I will handle this three behaviours
// with different routines, so the flags MATSHAPER_INPUT and MATSHAPER_OUTPUT // with different routines, so the flags MATSHAPER_INPUT and MATSHAPER_OUTPUT
// can be conbined to signal smelted matrix-shapers // can be conbined to signal smelted matrix-shapers
...@@ -89,7 +91,7 @@ int ComputeTables(LPGAMMATABLE Table[3], LPWORD Out[3], LPL16PARAMS p16) ...@@ -89,7 +91,7 @@ int ComputeTables(LPGAMMATABLE Table[3], LPWORD Out[3], LPL16PARAMS p16)
{ {
LPWORD PtrW; LPWORD PtrW;
PtrW = (LPWORD) malloc(sizeof(WORD) * p16 -> nSamples); PtrW = (LPWORD) _cmsMalloc(sizeof(WORD) * p16 -> nSamples);
if (PtrW == NULL) return -1; // Signal error if (PtrW == NULL) return -1; // Signal error
...@@ -119,7 +121,7 @@ LPMATSHAPER cmsAllocMatShaper2(LPMAT3 Matrix, LPGAMMATABLE In[], LPGAMMATABLE Ou ...@@ -119,7 +121,7 @@ LPMATSHAPER cmsAllocMatShaper2(LPMAT3 Matrix, LPGAMMATABLE In[], LPGAMMATABLE Ou
LPMATSHAPER NewMatShaper; LPMATSHAPER NewMatShaper;
int rc; int rc;
NewMatShaper = (LPMATSHAPER) malloc(sizeof(MATSHAPER)); NewMatShaper = (LPMATSHAPER) _cmsMalloc(sizeof(MATSHAPER));
if (NewMatShaper) if (NewMatShaper)
ZeroMemory(NewMatShaper, sizeof(MATSHAPER)); ZeroMemory(NewMatShaper, sizeof(MATSHAPER));
...@@ -171,7 +173,13 @@ LPMATSHAPER cmsAllocMatShaper(LPMAT3 Matrix, LPGAMMATABLE Tables[], DWORD Behavi ...@@ -171,7 +173,13 @@ LPMATSHAPER cmsAllocMatShaper(LPMAT3 Matrix, LPGAMMATABLE Tables[], DWORD Behavi
LPMATSHAPER NewMatShaper; LPMATSHAPER NewMatShaper;
int i, AllLinear; int i, AllLinear;
NewMatShaper = (LPMATSHAPER) malloc(sizeof(MATSHAPER)); if (Matrix == NULL) return NULL;
for (i=0; i < 3; i++) {
if (Tables[i] == NULL) return NULL;
}
NewMatShaper = (LPMATSHAPER) _cmsMalloc(sizeof(MATSHAPER));
if (NewMatShaper) if (NewMatShaper)
ZeroMemory(NewMatShaper, sizeof(MATSHAPER)); ZeroMemory(NewMatShaper, sizeof(MATSHAPER));
...@@ -187,17 +195,16 @@ LPMATSHAPER cmsAllocMatShaper(LPMAT3 Matrix, LPGAMMATABLE Tables[], DWORD Behavi ...@@ -187,17 +195,16 @@ LPMATSHAPER cmsAllocMatShaper(LPMAT3 Matrix, LPGAMMATABLE Tables[], DWORD Behavi
NewMatShaper -> dwFlags |= MATSHAPER_HASMATRIX; NewMatShaper -> dwFlags |= MATSHAPER_HASMATRIX;
// Now, on the table characteristics // Now, on the table characteristics
cmsCalcL16Params(Tables[0] -> nEntries, &NewMatShaper -> p16); cmsCalcL16Params(Tables[0] -> nEntries, &NewMatShaper -> p16);
// Copy tables // Copy tables
AllLinear = 0; AllLinear = 0;
for (i=0; i < 3; i++) for (i=0; i < 3; i++) {
{
LPWORD PtrW; LPWORD PtrW;
PtrW = (LPWORD) malloc(sizeof(WORD) * NewMatShaper -> p16.nSamples); PtrW = (LPWORD) _cmsMalloc(sizeof(WORD) * NewMatShaper -> p16.nSamples);
if (PtrW == NULL) { if (PtrW == NULL) {
cmsFreeMatShaper(NewMatShaper); cmsFreeMatShaper(NewMatShaper);
...@@ -235,11 +242,11 @@ void cmsFreeMatShaper(LPMATSHAPER MatShaper) ...@@ -235,11 +242,11 @@ void cmsFreeMatShaper(LPMATSHAPER MatShaper)
for (i=0; i < 3; i++) for (i=0; i < 3; i++)
{ {
if (MatShaper -> L[i]) free(MatShaper ->L[i]); if (MatShaper -> L[i]) _cmsFree(MatShaper ->L[i]);
if (MatShaper -> L2[i]) free(MatShaper ->L2[i]); if (MatShaper -> L2[i]) _cmsFree(MatShaper ->L2[i]);
} }
free(MatShaper); _cmsFree(MatShaper);
} }
......
...@@ -29,7 +29,7 @@ ...@@ -29,7 +29,7 @@
// //
// //
// Little cms // Little cms
// Copyright (C) 1998-2006 Marti Maria // Copyright (C) 1998-2007 Marti Maria
// //
// Permission is hereby granted, free of charge, to any person obtaining // Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the "Software"), // a copy of this software and associated documentation files (the "Software"),
...@@ -71,16 +71,16 @@ double cdecl VEC3length(LPVEC3 a); ...@@ -71,16 +71,16 @@ double cdecl VEC3length(LPVEC3 a);
double cdecl VEC3distance(LPVEC3 a, LPVEC3 b); double cdecl VEC3distance(LPVEC3 a, LPVEC3 b);
void cdecl MAT3identity(LPMAT3 a); void cdecl MAT3identity(LPMAT3 a);
void cdecl MAT3per(LPMAT3 r, LPMAT3 a, LPMAT3 b); void cdecl MAT3per(LPMAT3 r, LPMAT3 a, LPMAT3 b);
int cdecl MAT3inverse(LPMAT3 a, LPMAT3 b); int cdecl MAT3inverse(LPMAT3 a, LPMAT3 b);
BOOL cdecl MAT3solve(LPVEC3 x, LPMAT3 a, LPVEC3 b); LCMSBOOL cdecl MAT3solve(LPVEC3 x, LPMAT3 a, LPVEC3 b);
double cdecl MAT3det(LPMAT3 m); double cdecl MAT3det(LPMAT3 m);
void cdecl MAT3eval(LPVEC3 r, LPMAT3 a, LPVEC3 v); void cdecl MAT3eval(LPVEC3 r, LPMAT3 a, LPVEC3 v);
void cdecl MAT3toFix(LPWMAT3 r, LPMAT3 v); void cdecl MAT3toFix(LPWMAT3 r, LPMAT3 v);
void cdecl MAT3evalW(LPWVEC3 r, LPWMAT3 a, LPWVEC3 v); void cdecl MAT3evalW(LPWVEC3 r, LPWMAT3 a, LPWVEC3 v);
void cdecl MAT3perK(LPMAT3 r, LPMAT3 v, double d); void cdecl MAT3perK(LPMAT3 r, LPMAT3 v, double d);
void cdecl MAT3scaleAndCut(LPWMAT3 r, LPMAT3 v, double d); void cdecl MAT3scaleAndCut(LPWMAT3 r, LPMAT3 v, double d);
// --------------------- Implementation ---------------------------- // --------------------- Implementation ----------------------------
...@@ -345,13 +345,13 @@ void VEC3minus(LPVEC3 r, LPVEC3 a, LPVEC3 b) ...@@ -345,13 +345,13 @@ void VEC3minus(LPVEC3 r, LPVEC3 a, LPVEC3 b)
// Check id two vectors are the same, allowing tolerance // Check id two vectors are the same, allowing tolerance
static static
BOOL RangeCheck(double l, double h, double v) LCMSBOOL RangeCheck(double l, double h, double v)
{ {
return (v >= l && v <= h); return (v >= l && v <= h);
} }
BOOL VEC3equal(LPWVEC3 a, LPWVEC3 b, double Tolerance) LCMSBOOL VEC3equal(LPWVEC3 a, LPWVEC3 b, double Tolerance)
{ {
int i; int i;
double c; double c;
...@@ -367,7 +367,7 @@ BOOL VEC3equal(LPWVEC3 a, LPWVEC3 b, double Tolerance) ...@@ -367,7 +367,7 @@ BOOL VEC3equal(LPWVEC3 a, LPWVEC3 b, double Tolerance)
return TRUE; return TRUE;
} }
BOOL VEC3equalF(LPVEC3 a, LPVEC3 b, double Tolerance) LCMSBOOL VEC3equalF(LPVEC3 a, LPVEC3 b, double Tolerance)
{ {
int i; int i;
double c; double c;
...@@ -462,7 +462,7 @@ void MAT3identity(LPMAT3 a) ...@@ -462,7 +462,7 @@ void MAT3identity(LPMAT3 a)
// Check if matrix is Identity. Allow a tolerance as % // Check if matrix is Identity. Allow a tolerance as %
BOOL MAT3isIdentity(LPWMAT3 a, double Tolerance) LCMSBOOL MAT3isIdentity(LPWMAT3 a, double Tolerance)
{ {
int i; int i;
MAT3 Idd; MAT3 Idd;
...@@ -545,16 +545,16 @@ int MAT3inverse(LPMAT3 a, LPMAT3 b) ...@@ -545,16 +545,16 @@ int MAT3inverse(LPMAT3 a, LPMAT3 b)
// Solve a system in the form Ax = b // Solve a system in the form Ax = b
BOOL MAT3solve(LPVEC3 x, LPMAT3 a, LPVEC3 b) LCMSBOOL MAT3solve(LPVEC3 x, LPMAT3 a, LPVEC3 b)
{ {
MAT3 m, a_1; MAT3 m, a_1;
CopyMemory(&m, a, sizeof(MAT3)); CopyMemory(&m, a, sizeof(MAT3));
if (!MAT3inverse(&m, &a_1)) return FALSE; // Singular matrix if (!MAT3inverse(&m, &a_1)) return FALSE; // Singular matrix
MAT3eval(x, &a_1, b); MAT3eval(x, &a_1, b);
return TRUE; return TRUE;
} }
...@@ -839,3 +839,7 @@ void MAT3scaleAndCut(LPWMAT3 r, LPMAT3 v, double d) ...@@ -839,3 +839,7 @@ void MAT3scaleAndCut(LPWMAT3 r, LPMAT3 v, double d)
VEC3scaleAndCut(&r -> v[1], &v -> v[1], d); VEC3scaleAndCut(&r -> v[1], &v -> v[1], d);
VEC3scaleAndCut(&r -> v[2], &v -> v[2], d); VEC3scaleAndCut(&r -> v[2], &v -> v[2], d);
} }
...@@ -29,7 +29,7 @@ ...@@ -29,7 +29,7 @@
// //
// //
// Little cms // Little cms
// Copyright (C) 1998-2006 Marti Maria // Copyright (C) 1998-2007 Marti Maria
// //
// Permission is hereby granted, free of charge, to any person obtaining // Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the "Software"), // a copy of this software and associated documentation files (the "Software"),
...@@ -74,7 +74,7 @@ LPcmsNAMEDCOLORLIST GrowNamedColorList(LPcmsNAMEDCOLORLIST v, int ByElements) ...@@ -74,7 +74,7 @@ LPcmsNAMEDCOLORLIST GrowNamedColorList(LPcmsNAMEDCOLORLIST v, int ByElements)
NewElements *= 2; NewElements *= 2;
size = sizeof(cmsNAMEDCOLORLIST) + (sizeof(cmsNAMEDCOLOR) * NewElements); size = sizeof(cmsNAMEDCOLORLIST) + (sizeof(cmsNAMEDCOLOR) * NewElements);
TheNewList = (LPcmsNAMEDCOLORLIST) malloc(size); TheNewList = (LPcmsNAMEDCOLORLIST) _cmsMalloc(size);
if (TheNewList == NULL) { if (TheNewList == NULL) {
...@@ -86,7 +86,7 @@ LPcmsNAMEDCOLORLIST GrowNamedColorList(LPcmsNAMEDCOLORLIST v, int ByElements) ...@@ -86,7 +86,7 @@ LPcmsNAMEDCOLORLIST GrowNamedColorList(LPcmsNAMEDCOLORLIST v, int ByElements)
CopyMemory(TheNewList, v, sizeof(cmsNAMEDCOLORLIST) + (v ->nColors - 1) * sizeof(cmsNAMEDCOLOR)); CopyMemory(TheNewList, v, sizeof(cmsNAMEDCOLORLIST) + (v ->nColors - 1) * sizeof(cmsNAMEDCOLOR));
TheNewList -> Allocated = NewElements; TheNewList -> Allocated = NewElements;
free(v); _cmsFree(v);
return TheNewList; return TheNewList;
} }
} }
...@@ -99,7 +99,7 @@ LPcmsNAMEDCOLORLIST cmsAllocNamedColorList(int n) ...@@ -99,7 +99,7 @@ LPcmsNAMEDCOLORLIST cmsAllocNamedColorList(int n)
{ {
size_t size = sizeof(cmsNAMEDCOLORLIST) + (n - 1) * sizeof(cmsNAMEDCOLOR); size_t size = sizeof(cmsNAMEDCOLORLIST) + (n - 1) * sizeof(cmsNAMEDCOLOR);
LPcmsNAMEDCOLORLIST v = (LPcmsNAMEDCOLORLIST) malloc(size); LPcmsNAMEDCOLORLIST v = (LPcmsNAMEDCOLORLIST) _cmsMalloc(size);
if (v == NULL) { if (v == NULL) {
...@@ -124,10 +124,10 @@ void cmsFreeNamedColorList(LPcmsNAMEDCOLORLIST v) ...@@ -124,10 +124,10 @@ void cmsFreeNamedColorList(LPcmsNAMEDCOLORLIST v)
return; return;
} }
free(v); _cmsFree(v);
} }
BOOL cmsAppendNamedColor(cmsHTRANSFORM xform, const char* Name, WORD PCS[3], WORD Colorant[MAXCHANNELS]) LCMSBOOL cmsAppendNamedColor(cmsHTRANSFORM xform, const char* Name, WORD PCS[3], WORD Colorant[MAXCHANNELS])
{ {
_LPcmsTRANSFORM v = (_LPcmsTRANSFORM) xform; _LPcmsTRANSFORM v = (_LPcmsTRANSFORM) xform;
LPcmsNAMEDCOLORLIST List; LPcmsNAMEDCOLORLIST List;
...@@ -146,6 +146,7 @@ BOOL cmsAppendNamedColor(cmsHTRANSFORM xform, const char* Name, WORD PCS[3], WOR ...@@ -146,6 +146,7 @@ BOOL cmsAppendNamedColor(cmsHTRANSFORM xform, const char* Name, WORD PCS[3], WOR
List ->List[List ->nColors].PCS[i] = PCS[i]; List ->List[List ->nColors].PCS[i] = PCS[i];
strncpy(List ->List[List ->nColors].Name, Name, MAX_PATH-1); strncpy(List ->List[List ->nColors].Name, Name, MAX_PATH-1);
List ->List[List ->nColors].Name[MAX_PATH-1] = 0;
List ->nColors++; List ->nColors++;
return TRUE; return TRUE;
...@@ -164,18 +165,17 @@ int LCMSEXPORT cmsNamedColorCount(cmsHTRANSFORM xform) ...@@ -164,18 +165,17 @@ int LCMSEXPORT cmsNamedColorCount(cmsHTRANSFORM xform)
} }
BOOL LCMSEXPORT cmsNamedColorInfo(cmsHTRANSFORM xform, int nColor, char* Name, char* Prefix, char* Suffix) LCMSBOOL LCMSEXPORT cmsNamedColorInfo(cmsHTRANSFORM xform, int nColor, char* Name, char* Prefix, char* Suffix)
{ {
_LPcmsTRANSFORM v = (_LPcmsTRANSFORM) xform; _LPcmsTRANSFORM v = (_LPcmsTRANSFORM) xform;
if (v ->NamedColorList == NULL) return FALSE; if (v ->NamedColorList == NULL) return FALSE;
if (nColor < 0 || nColor >= cmsNamedColorCount(xform)) return FALSE; if (nColor < 0 || nColor >= cmsNamedColorCount(xform)) return FALSE;
if (Name) strncpy(Name, v ->NamedColorList->List[nColor].Name, 31); if (Name) { strncpy(Name, v ->NamedColorList->List[nColor].Name, 31); Name[31] = 0; }
if (Prefix) strncpy(Prefix, v ->NamedColorList->Prefix, 31); if (Prefix) { strncpy(Prefix, v ->NamedColorList->Prefix, 31); Prefix[31] = 0; }
if (Suffix) strncpy(Suffix, v ->NamedColorList->Suffix, 31); if (Suffix) { strncpy(Suffix, v ->NamedColorList->Suffix, 31); Suffix[31] = 0; }
return TRUE; return TRUE;
} }
...@@ -196,3 +196,5 @@ int LCMSEXPORT cmsNamedColorIndex(cmsHTRANSFORM xform, const char* Name) ...@@ -196,3 +196,5 @@ int LCMSEXPORT cmsNamedColorIndex(cmsHTRANSFORM xform, const char* Name)
return -1; return -1;
} }
...@@ -29,7 +29,7 @@ ...@@ -29,7 +29,7 @@
// //
// //
// Little cms // Little cms
// Copyright (C) 1998-2006 Marti Maria // Copyright (C) 1998-2007 Marti Maria
// //
// Permission is hereby granted, free of charge, to any person obtaining // Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the "Software"), // a copy of this software and associated documentation files (the "Software"),
...@@ -624,3 +624,7 @@ void LCMSEXPORT cmsXYZEncoded2Float(LPcmsCIEXYZ fXYZ, const WORD XYZ[3]) ...@@ -624,3 +624,7 @@ void LCMSEXPORT cmsXYZEncoded2Float(LPcmsCIEXYZ fXYZ, const WORD XYZ[3])
fXYZ -> Z = XYZ2float(XYZ[2]); fXYZ -> Z = XYZ2float(XYZ[2]);
} }
...@@ -29,7 +29,7 @@ ...@@ -29,7 +29,7 @@
// //
// //
// Little cms // Little cms
// Copyright (C) 1998-2006 Marti Maria // Copyright (C) 1998-2007 Marti Maria
// //
// Permission is hereby granted, free of charge, to any person obtaining // Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the "Software"), // a copy of this software and associated documentation files (the "Software"),
...@@ -120,7 +120,7 @@ int ComponentOf(int n, int clut, int nColorant) ...@@ -120,7 +120,7 @@ int ComponentOf(int n, int clut, int nColorant)
// This routine does a sweep on whole input space, and calls its callback // This routine does a sweep on whole input space, and calls its callback
// function on knots. returns TRUE if all ok, FALSE otherwise. // function on knots. returns TRUE if all ok, FALSE otherwise.
BOOL LCMSEXPORT cmsSample3DGrid(LPLUT Lut, _cmsSAMPLER Sampler, LPVOID Cargo, DWORD dwFlags) LCMSBOOL LCMSEXPORT cmsSample3DGrid(LPLUT Lut, _cmsSAMPLER Sampler, LPVOID Cargo, DWORD dwFlags)
{ {
int i, t, nTotalPoints, Colorant, index; int i, t, nTotalPoints, Colorant, index;
WORD In[MAXCHANNELS], Out[MAXCHANNELS]; WORD In[MAXCHANNELS], Out[MAXCHANNELS];
...@@ -145,12 +145,16 @@ BOOL LCMSEXPORT cmsSample3DGrid(LPLUT Lut, _cmsSAMPLER Sampler, LPVOID Cargo, DW ...@@ -145,12 +145,16 @@ BOOL LCMSEXPORT cmsSample3DGrid(LPLUT Lut, _cmsSAMPLER Sampler, LPVOID Cargo, DW
&Lut -> In16params); &Lut -> In16params);
} }
for (t=0; t < (int) Lut -> OutputChan; t++)
Out[t] = Lut->T[index + t];
// if (dwFlags & SAMPLER_INSPECT) { if (dwFlags & SAMPLER_HASTL2) {
for (t=0; t < (int) Lut -> OutputChan; t++) for (t=0; t < (int) Lut -> OutputChan; t++)
Out[t] = Lut->T[index + t]; Out[t] = cmsLinearInterpLUT16(Out[t],
// } Lut -> L2[t],
&Lut -> Out16params);
}
if (!Sampler(In, Out, Cargo)) if (!Sampler(In, Out, Cargo))
...@@ -255,9 +259,11 @@ LPLUT _cmsPrecalculateDeviceLink(cmsHTRANSFORM h, DWORD dwFlags) ...@@ -255,9 +259,11 @@ LPLUT _cmsPrecalculateDeviceLink(cmsHTRANSFORM h, DWORD dwFlags)
LPLUT Grid; LPLUT Grid;
int nGridPoints; int nGridPoints;
DWORD dwFormatIn, dwFormatOut; DWORD dwFormatIn, dwFormatOut;
DWORD SaveFormatIn, SaveFormatOut;
int ChannelsIn, ChannelsOut; int ChannelsIn, ChannelsOut;
LPLUT SaveGamutLUT; LPLUT SaveGamutLUT;
// Remove any gamut checking // Remove any gamut checking
SaveGamutLUT = p ->Gamut; SaveGamutLUT = p ->Gamut;
p ->Gamut = NULL; p ->Gamut = NULL;
...@@ -276,8 +282,13 @@ LPLUT _cmsPrecalculateDeviceLink(cmsHTRANSFORM h, DWORD dwFlags) ...@@ -276,8 +282,13 @@ LPLUT _cmsPrecalculateDeviceLink(cmsHTRANSFORM h, DWORD dwFlags)
dwFormatIn = (CHANNELS_SH(ChannelsIn)|BYTES_SH(2)); dwFormatIn = (CHANNELS_SH(ChannelsIn)|BYTES_SH(2));
dwFormatOut = (CHANNELS_SH(ChannelsOut)|BYTES_SH(2)); dwFormatOut = (CHANNELS_SH(ChannelsOut)|BYTES_SH(2));
p -> FromInput = _cmsIdentifyInputFormat(p, dwFormatIn); SaveFormatIn = p ->InputFormat;
p -> ToOutput = _cmsIdentifyOutputFormat(p, dwFormatOut); SaveFormatOut = p ->OutputFormat;
p -> InputFormat = dwFormatIn;
p -> OutputFormat = dwFormatOut;
p -> FromInput = _cmsIdentifyInputFormat(p, dwFormatIn);
p -> ToOutput = _cmsIdentifyOutputFormat(p, dwFormatOut);
// Fix gamut & gamma possible mismatches. // Fix gamut & gamma possible mismatches.
...@@ -289,7 +300,6 @@ LPLUT _cmsPrecalculateDeviceLink(cmsHTRANSFORM h, DWORD dwFlags) ...@@ -289,7 +300,6 @@ LPLUT _cmsPrecalculateDeviceLink(cmsHTRANSFORM h, DWORD dwFlags)
_cmsComputePrelinearizationTablesFromXFORM(hOne, 1, Grid); _cmsComputePrelinearizationTablesFromXFORM(hOne, 1, Grid);
} }
// Attention to this typecast! we can take the luxury to // Attention to this typecast! we can take the luxury to
// do this since cmsHTRANSFORM is only an alias to a pointer // do this since cmsHTRANSFORM is only an alias to a pointer
// to the transform struct. // to the transform struct.
...@@ -297,11 +307,13 @@ LPLUT _cmsPrecalculateDeviceLink(cmsHTRANSFORM h, DWORD dwFlags) ...@@ -297,11 +307,13 @@ LPLUT _cmsPrecalculateDeviceLink(cmsHTRANSFORM h, DWORD dwFlags)
if (!cmsSample3DGrid(Grid, XFormSampler, (LPVOID) p, Grid -> wFlags)) { if (!cmsSample3DGrid(Grid, XFormSampler, (LPVOID) p, Grid -> wFlags)) {
cmsFreeLUT(Grid); cmsFreeLUT(Grid);
return NULL; Grid = NULL;
} }
p ->Gamut = SaveGamutLUT;
p ->InputFormat = SaveFormatIn;
p ->OutputFormat = SaveFormatOut;
p ->Gamut = SaveGamutLUT;
return Grid; return Grid;
} }
...@@ -348,7 +360,7 @@ int BlackPreservingGrayOnlySampler(register WORD In[], register WORD Out[], regi ...@@ -348,7 +360,7 @@ int BlackPreservingGrayOnlySampler(register WORD In[], register WORD Out[], regi
// That is our K-preserving callback. // Preserve all K plane.
static static
int BlackPreservingSampler(register WORD In[], register WORD Out[], register LPVOID Cargo) int BlackPreservingSampler(register WORD In[], register WORD Out[], register LPVOID Cargo)
{ {
...@@ -469,6 +481,7 @@ int LCMSEXPORT cmsSetCMYKPreservationStrategy(int n) ...@@ -469,6 +481,7 @@ int LCMSEXPORT cmsSetCMYKPreservationStrategy(int n)
return OldVal; return OldVal;
} }
#pragma warning(disable: 4550)
// Get a pointer to callback on depending of strategy // Get a pointer to callback on depending of strategy
static static
...@@ -504,11 +517,10 @@ LPLUT _cmsPrecalculateBlackPreservingDeviceLink(cmsHTRANSFORM hCMYK2CMYK, DWORD ...@@ -504,11 +517,10 @@ LPLUT _cmsPrecalculateBlackPreservingDeviceLink(cmsHTRANSFORM hCMYK2CMYK, DWORD
if (p -> dwOriginalFlags & cmsFLAGS_BLACKPOINTCOMPENSATION) if (p -> dwOriginalFlags & cmsFLAGS_BLACKPOINTCOMPENSATION)
LocalFlags |= cmsFLAGS_BLACKPOINTCOMPENSATION; LocalFlags |= cmsFLAGS_BLACKPOINTCOMPENSATION;
// Fill in cargo struct // Fill in cargo struct
Cargo.cmyk2cmyk = hCMYK2CMYK; Cargo.cmyk2cmyk = hCMYK2CMYK;
// Compute tone curve // Compute tone curve.
Cargo.KTone = _cmsBuildKToneCurve(hCMYK2CMYK, 256); Cargo.KTone = _cmsBuildKToneCurve(hCMYK2CMYK, 256);
if (Cargo.KTone == NULL) return NULL; if (Cargo.KTone == NULL) return NULL;
cmsCalcL16Params(Cargo.KTone ->nEntries, &Cargo.KToneParams); cmsCalcL16Params(Cargo.KTone ->nEntries, &Cargo.KToneParams);
...@@ -522,11 +534,11 @@ LPLUT _cmsPrecalculateBlackPreservingDeviceLink(cmsHTRANSFORM hCMYK2CMYK, DWORD ...@@ -522,11 +534,11 @@ LPLUT _cmsPrecalculateBlackPreservingDeviceLink(cmsHTRANSFORM hCMYK2CMYK, DWORD
Cargo.LabK2cmyk = cmsReadICCLut(p->OutputProfile, Device2PCS[p->Intent]); Cargo.LabK2cmyk = cmsReadICCLut(p->OutputProfile, Device2PCS[p->Intent]);
// Is there any table available? // Is there any table available?
if (Cargo.LabK2cmyk == NULL) { if (Cargo.LabK2cmyk == NULL) {
Grid = NULL; Grid = NULL;
goto Cleanup; goto Cleanup;
} }
// Setup a roundtrip on output profile for TAC estimation // Setup a roundtrip on output profile for TAC estimation
Cargo.hRoundTrip = cmsCreateTransform(p ->OutputProfile, TYPE_CMYK_16, Cargo.hRoundTrip = cmsCreateTransform(p ->OutputProfile, TYPE_CMYK_16,
...@@ -654,7 +666,7 @@ void PatchLUT(LPLUT Grid, WORD At[], WORD Value[], ...@@ -654,7 +666,7 @@ void PatchLUT(LPLUT Grid, WORD At[], WORD Value[],
BOOL _cmsFixWhiteMisalignment(_LPcmsTRANSFORM p) LCMSBOOL _cmsFixWhiteMisalignment(_LPcmsTRANSFORM p)
{ {
WORD *WhitePointIn, *WhitePointOut, *BlackPointIn, *BlackPointOut; WORD *WhitePointIn, *WhitePointOut, *BlackPointIn, *BlackPointOut;
...@@ -682,3 +694,4 @@ BOOL _cmsFixWhiteMisalignment(_LPcmsTRANSFORM p) ...@@ -682,3 +694,4 @@ BOOL _cmsFixWhiteMisalignment(_LPcmsTRANSFORM p)
return TRUE; return TRUE;
} }
...@@ -206,6 +206,11 @@ typedef __int32_t icInt64Number[2]; ...@@ -206,6 +206,11 @@ typedef __int32_t icInt64Number[2];
#if defined(__sun) || defined(__hpux) || defined (__MINGW) || defined(__MINGW32__) #if defined(__sun) || defined(__hpux) || defined (__MINGW) || defined(__MINGW32__)
#if defined (__MINGW) || defined(__MINGW32__)
#include <stdint.h>
#endif
typedef uint8_t icUInt8Number; typedef uint8_t icUInt8Number;
typedef uint16_t icUInt16Number; typedef uint16_t icUInt16Number;
typedef uint32_t icUInt32Number; typedef uint32_t icUInt32Number;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册