📄 lcms.h
字号:
// Clamp with saturationLCMS_INLINE WORD _cmsClampWord(int in){ if (in < 0) return 0; if (in > 0xFFFF) return 0xFFFFU; // Including marker return (WORD) in;}// ------------------------------------------------------------------------------------------- end of inline functions// Signal error from inside lcms codevoid cdecl cmsSignalError(int ErrorCode, const char *ErrorText, ...);// Alignment handling (needed in ReadLUT16 and ReadLUT8)typedef struct { icS15Fixed16Number a; icUInt16Number b; } _cmsTestAlign16;#define SIZEOF_UINT16_ALIGNED (sizeof(_cmsTestAlign16) - sizeof(icS15Fixed16Number))typedef struct { icS15Fixed16Number a; icUInt8Number b; } _cmsTestAlign8;#define SIZEOF_UINT8_ALIGNED (sizeof(_cmsTestAlign8) - sizeof(icS15Fixed16Number))// Fixed pointtypedef icInt32Number Fixed32; // Fixed 15.16 whith sign#define INT_TO_FIXED(x) ((x)<<16)#define DOUBLE_TO_FIXED(x) ((Fixed32) ((x)*65536.0+0.5))#define FIXED_TO_INT(x) ((x)>>16)#define FIXED_REST_TO_INT(x) ((x)& 0xFFFFU)#define FIXED_TO_DOUBLE(x) (((double)x)/65536.0)#define ROUND_FIXED_TO_INT(x) (((x)+0x8000)>>16)Fixed32 cdecl FixedMul(Fixed32 a, Fixed32 b);Fixed32 cdecl FixedSquare(Fixed32 a);#ifdef USE_INLINELCMS_INLINE Fixed32 ToFixedDomain(int a) { return a + ((a + 0x7fff) / 0xffff); }LCMS_INLINE int FromFixedDomain(Fixed32 a) { return a - ((a + 0x7fff) >> 16); } #elseFixed32 cdecl ToFixedDomain(int a); // (a * 65536.0 / 65535.0)int cdecl FromFixedDomain(Fixed32 a); // (a * 65535.0 + .5)#endifFixed32 cdecl FixedLERP(Fixed32 a, Fixed32 l, Fixed32 h);WORD cdecl FixedScale(WORD a, Fixed32 s);// Vector & Matrix operations. I'm using the notation frequently found in// literature. Mostly 'Graphic Gems' samples. Not to be same routines.// Vector members#define VX 0#define VY 1#define VZ 2typedef struct { // Fixed 15.16 bits vector Fixed32 n[3]; } WVEC3, FAR* LPWVEC3;typedef struct { // Matrix (Fixed 15.16) WVEC3 v[3]; } WMAT3, FAR* LPWMAT3;void cdecl VEC3init(LPVEC3 r, double x, double y, double z); // double versionvoid cdecl VEC3initF(LPWVEC3 r, double x, double y, double z); // Fix32 versionvoid cdecl VEC3toFix(LPWVEC3 r, LPVEC3 v);void cdecl VEC3fromFix(LPVEC3 r, LPWVEC3 v);void cdecl VEC3scaleFix(LPWORD r, LPWVEC3 Scale);void cdecl VEC3swap(LPVEC3 a, LPVEC3 b);void cdecl VEC3divK(LPVEC3 r, LPVEC3 v, double d);void cdecl VEC3perK(LPVEC3 r, LPVEC3 v, double d);void cdecl VEC3minus(LPVEC3 r, LPVEC3 a, LPVEC3 b);void cdecl VEC3perComp(LPVEC3 r, LPVEC3 a, LPVEC3 b);BOOL cdecl VEC3equal(LPWVEC3 a, LPWVEC3 b, double Tolerance);BOOL cdecl VEC3equalF(LPVEC3 a, LPVEC3 b, double Tolerance);void cdecl VEC3scaleAndCut(LPWVEC3 r, LPVEC3 v, double d);void cdecl VEC3cross(LPVEC3 r, LPVEC3 u, LPVEC3 v);void cdecl VEC3saturate(LPVEC3 v);double cdecl VEC3distance(LPVEC3 a, LPVEC3 b);double cdecl VEC3length(LPVEC3 a);void cdecl MAT3identity(LPMAT3 a);void cdecl MAT3per(LPMAT3 r, LPMAT3 a, LPMAT3 b);void cdecl MAT3perK(LPMAT3 r, LPMAT3 v, double d);int cdecl MAT3inverse(LPMAT3 a, LPMAT3 b);BOOL cdecl MAT3solve(LPVEC3 x, LPMAT3 a, LPVEC3 b);double cdecl MAT3det(LPMAT3 m);void cdecl MAT3eval(LPVEC3 r, LPMAT3 a, LPVEC3 v);void cdecl MAT3toFix(LPWMAT3 r, LPMAT3 v);void cdecl MAT3fromFix(LPMAT3 r, LPWMAT3 v);void cdecl MAT3evalW(LPWVEC3 r, LPWMAT3 a, LPWVEC3 v);BOOL cdecl MAT3isIdentity(LPWMAT3 a, double Tolerance);void cdecl MAT3scaleAndCut(LPWMAT3 r, LPMAT3 v, double d);// Is a table linear?int cdecl cmsIsLinear(WORD Table[], int nEntries);// I hold this structures describing domain// details mainly for optimization purposes.struct _lcms_l16params_struc;typedef void (* _cms3DLERP)(WORD Input[], WORD Output[], WORD LutTable[], struct _lcms_l16params_struc* p);typedef struct _lcms_l8opt_struc { // Used on 8 bit interpolations unsigned int X0[256], Y0[256], Z0[256]; WORD rx[256], ry[256], rz[256]; } L8PARAMS, FAR* LPL8PARAMS;typedef struct _lcms_l16params_struc { // Used on 16 bits interpolations int nSamples; // Valid on all kinds of tables int nInputs; // != 1 only in 3D interpolation int nOutputs; // != 1 only in 3D interpolation WORD Domain; int opta1, opta2; int opta3, opta4; // Optimization for 3D LUT int opta5, opta6; int opta7, opta8; _cms3DLERP Interp3D; // The interpolation routine LPL8PARAMS p8; // Points to some tables for 8-bit speedup } L16PARAMS, *LPL16PARAMS;void cdecl cmsCalcL16Params(int nSamples, LPL16PARAMS p);void cdecl cmsCalcCLUT16Params(int nSamples, int InputChan, int OutputChan, LPL16PARAMS p);void cdecl cmsCalcCLUT16ParamsEx(int nSamples, int InputChan, int OutputChan, BOOL lUseTetrahedral, LPL16PARAMS p);WORD cdecl cmsLinearInterpLUT16(WORD Value, WORD LutTable[], LPL16PARAMS p);Fixed32 cdecl cmsLinearInterpFixed(WORD Value1, WORD LutTable[], LPL16PARAMS p);WORD cdecl cmsReverseLinearInterpLUT16(WORD Value, WORD LutTable[], LPL16PARAMS p);void cdecl cmsTrilinearInterp16(WORD Input[], WORD Output[], WORD LutTable[], LPL16PARAMS p);void cdecl cmsTetrahedralInterp16(WORD Input[], WORD Output[], WORD LutTable[], LPL16PARAMS p);void cdecl cmsTetrahedralInterp8(WORD Input[], WORD Output[], WORD LutTable[], LPL16PARAMS p);// LUT handling#define LUT_HASMATRIX 0x0001 // Do-op Flags#define LUT_HASTL1 0x0002#define LUT_HASTL2 0x0008#define LUT_HAS3DGRID 0x0010// New in rev 4.0 of ICC spec#define LUT_HASMATRIX3 0x0020 // Matrix + offset for LutAToB#define LUT_HASMATRIX4 0x0040 // Matrix + offset for LutBToA#define LUT_HASTL3 0x0100 // '3' curves for LutAToB#define LUT_HASTL4 0x0200 // '4' curves for LutBToA// V4 emulation#define LUT_V4_OUTPUT_EMULATE_V2 0x10000 // Is a V4 output LUT, emulating V2#define LUT_V4_INPUT_EMULATE_V2 0x20000 // Is a V4 input LUT, emulating V2#define LUT_V2_OUTPUT_EMULATE_V4 0x40000 // Is a V2 output LUT, emulating V4#define LUT_V2_INPUT_EMULATE_V4 0x80000 // Is a V2 input LUT, emulating V4struct _lcms_LUT_struc { DWORD wFlags; WMAT3 Matrix; // 15fixed16 matrix unsigned int InputChan; unsigned int OutputChan; unsigned int InputEntries; unsigned int OutputEntries; unsigned int cLutPoints; LPWORD L1[MAXCHANNELS]; // First linearization LPWORD L2[MAXCHANNELS]; // Last linearization LPWORD T; // 3D CLUT unsigned int Tsize; // CLUT size in bytes // Parameters & Optimizations L16PARAMS In16params; L16PARAMS Out16params; L16PARAMS CLut16params; int Intent; // Accomplished intent // New for Rev 4.0 of spec (reserved) WMAT3 Mat3; WVEC3 Ofs3; LPWORD L3[MAXCHANNELS]; L16PARAMS L3params; unsigned int L3Entries; WMAT3 Mat4; WVEC3 Ofs4; LPWORD L4[MAXCHANNELS]; L16PARAMS L4params; unsigned int L4Entries; // Gray axes fixup. Only on v2 8-bit Lab LUT BOOL FixGrayAxes; // Parameters used for curve creation LCMSGAMMAPARAMS LCurvesBirth[4][MAXCHANNELS]; }; // LUT, FAR* LPLUT;BOOL cdecl _cmsSmoothEndpoints(LPWORD Table, int nEntries);// CRC of gamma tablesunsigned int _cmsCrc32OfGammaTable(LPGAMMATABLE Table);// Sampled curvesLPSAMPLEDCURVE cdecl cmsAllocSampledCurve(int nItems);void cdecl cmsFreeSampledCurve(LPSAMPLEDCURVE p);LPSAMPLEDCURVE cdecl cmsDupSampledCurve(LPSAMPLEDCURVE p);LPSAMPLEDCURVE cdecl cmsConvertGammaToSampledCurve(LPGAMMATABLE Gamma, int nPoints);LPGAMMATABLE cdecl cmsConvertSampledCurveToGamma(LPSAMPLEDCURVE Sampled, double Max);void cdecl cmsEndpointsOfSampledCurve(LPSAMPLEDCURVE p, double* Min, double* Max);void cdecl cmsClampSampledCurve(LPSAMPLEDCURVE p, double Min, double Max);BOOL cdecl cmsSmoothSampledCurve(LPSAMPLEDCURVE Tab, double SmoothingLambda);void cdecl cmsRescaleSampledCurve(LPSAMPLEDCURVE p, double Min, double Max, int nPoints);LPSAMPLEDCURVE cdecl cmsJoinSampledCurves(LPSAMPLEDCURVE X, LPSAMPLEDCURVE Y, int nResultingPoints);// Shaper/Matrix handling#define MATSHAPER_HASMATRIX 0x0001 // Do-ops flags#define MATSHAPER_HASSHAPER 0x0002#define MATSHAPER_INPUT 0x0004 // Behaviour#define MATSHAPER_OUTPUT 0x0008#define MATSHAPER_HASINPSHAPER 0x0010#define MATSHAPER_ALLSMELTED (MATSHAPER_INPUT|MATSHAPER_OUTPUT)typedef struct { DWORD dwFlags; WMAT3 Matrix; L16PARAMS p16; // Primary curve LPWORD L[3]; L16PARAMS p2_16; // Secondary curve (used as input in smelted ones) LPWORD L2[3]; } MATSHAPER, FAR* LPMATSHAPER;LPMATSHAPER cdecl cmsAllocMatShaper(LPMAT3 matrix, LPGAMMATABLE Shaper[], DWORD Behaviour);LPMATSHAPER cdecl cmsAllocMatShaper2(LPMAT3 matrix, LPGAMMATABLE In[], LPGAMMATABLE Out[], DWORD Behaviour);void cdecl cmsFreeMatShaper(LPMATSHAPER MatShaper);void cdecl cmsEvalMatShaper(LPMATSHAPER MatShaper, WORD In[], WORD Out[]);BOOL cdecl cmsReadICCMatrixRGB2XYZ(LPMAT3 r, cmsHPROFILE hProfile);LPMATSHAPER cdecl cmsBuildInputMatrixShaper(cmsHPROFILE InputProfile);LPMATSHAPER cdecl cmsBuildOutputMatrixShaper(cmsHPROFILE OutputProfile);// White Point & Primary chromas handlingBOOL cdecl cmsAdaptationMatrix(LPMAT3 r, LPMAT3 ConeMatrix, LPcmsCIEXYZ FromIll, LPcmsCIEXYZ ToIll);BOOL cdecl cmsAdaptMatrixToD50(LPMAT3 r, LPcmsCIExyY SourceWhitePt);BOOL cdecl cmsAdaptMatrixFromD50(LPMAT3 r, LPcmsCIExyY DestWhitePt);BOOL cdecl cmsReadChromaticAdaptationMatrix(LPMAT3 r, cmsHPROFILE hProfile);// Inter-PCS conversion routines. They assume D50 as white point.void cdecl cmsXYZ2LabEncoded(WORD XYZ[3], WORD Lab[3]);void cdecl cmsLab2XYZEncoded(WORD Lab[3], WORD XYZ[3]);// Retrieve text representation of WPvoid cdecl _cmsIdentifyWhitePoint(char *Buffer, LPcmsCIEXYZ WhitePt);// Quantize to WORD in a (MaxSamples - 1) domainWORD cdecl _cmsQuantizeVal(double i, int MaxSamples);LPcmsNAMEDCOLORLIST cdecl cmsAllocNamedColorList(int n);int cdecl cmsReadICCnamedColorList(cmsHTRANSFORM xform, cmsHPROFILE hProfile, icTagSignature sig);void cdecl cmsFreeNamedColorList(LP
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -