00001
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00072
00073
00074
00075
00077
00078 #if !defined(_ICCCMM_H)
00079 #define _ICCCMM_H
00080
00081 #include "IccProfile.h"
00082 #include "IccTag.h"
00083 #include "IccUtil.h"
00084 #include <list>
00085
00086 #ifdef USESAMPLEICCNAMESPACE
00087 namespace sampleICC {
00088 #endif
00089
00091 typedef enum {
00092 icCmmStatBad = -1,
00093 icCmmStatOk = 0,
00094 icCmmStatCantOpenProfile = 1,
00095 icCmmStatBadSpaceLink = 2,
00096 icCmmStatInvalidProfile = 3,
00097 icCmmStatBadXform = 4,
00098 icCmmStatInvalidLut = 5,
00099 icCmmStatProfileMissingTag = 6,
00100 icCmmStatColorNotFound = 7,
00101 icCmmStatIncorrectApply = 8,
00102 icCmmStatBadColorEncoding = 9,
00103 icCmmStatAllocErr = 10,
00104 icCmmStatBadLutType = 11,
00105 } icStatusCMM;
00106
00108 typedef enum {
00109 icInterpLinear = 0,
00110 icInterpTetrahedral = 1,
00111 } icXformInterp;
00112
00114 typedef enum {
00115 icXformLutColor = 0,
00116 icXformLutNamedColor = 1,
00117 icXformLutPreview = 2,
00118 icXformLutGamut = 3,
00119 } icXformLutType;
00120
00121 #define icPerceptualRefBlackX 0.00336
00122 #define icPerceptualRefBlackY 0.0034731
00123 #define icPerceptualRefBlackZ 0.00287
00124
00125 #define icPerceptualRefWhiteX 0.9642
00126 #define icPerceptualRefWhiteY 1.0000
00127 #define icPerceptualRefWhiteZ 0.8249
00128
00129
00130 typedef enum {
00131 icXformTypeMatrixTRC = 0,
00132 icXformType3DLut = 1,
00133 icXformType4DLut = 2,
00134 icXformTypeNDLut = 3,
00135 icXformTypeNamedColor = 4,
00136 icXformTypeMpe = 5,
00137 } icXformType;
00138
00150 class ICCPROFLIB_API CIccXform
00151 {
00152 public:
00153 CIccXform();
00154 virtual ~CIccXform();
00155
00156 virtual icXformType GetXformType()=0;
00157
00159 static CIccXform *Create(CIccProfile *pProfile, bool bInput=true, icRenderingIntent nIntent=icUnknownIntent,
00160 icXformInterp nInterp=icInterpLinear, icXformLutType nLutType=icXformLutColor,
00161 bool bUseMpeTags=true);
00162
00165 static CIccXform *Create(CIccProfile &pProfile, bool bInput=true, icRenderingIntent nIntent=icUnknownIntent,
00166 icXformInterp nInterp=icInterpLinear, icXformLutType nLutType=icXformLutColor,
00167 bool bUseMpeTags=true);
00168
00169 virtual icStatusCMM Begin();
00170 virtual void Apply(icFloatNumber *DstPixel, const icFloatNumber *SrcPixel)=0;
00171
00172
00173 virtual bool RemoveIO() { return m_pProfile->Detach(); }
00174
00176 virtual icColorSpaceSignature GetSrcSpace() const;
00177
00179 virtual icColorSpaceSignature GetDstSpace() const;
00180
00182 virtual bool UseLegacyPCS() const { return false; }
00184 virtual bool IsVersion2() const { return !m_pProfile || m_pProfile->m_Header.version < icVersionNumberV4; }
00185
00187 bool IsInput() const { return m_bInput; }
00188
00190 void SetParams(CIccProfile *pProfile, bool bInput, icRenderingIntent nIntent, icXformInterp nInterp);
00191
00193 virtual LPIccCurve* ExtractInputCurves()=0;
00194 virtual LPIccCurve* ExtractOutputCurves()=0;
00195
00196 protected:
00197
00198 const icFloatNumber *CheckSrcAbs(const icFloatNumber *Pixel);
00199 void CheckDstAbs(icFloatNumber *Pixel);
00200
00201 CIccProfile *m_pProfile;
00202 bool m_bInput;
00203 icRenderingIntent m_nIntent;
00204
00205 icFloatNumber m_AbsLab[3];
00206 icXYZNumber m_MediaXYZ;
00207
00208 icXformInterp m_nInterp;
00209 };
00210
00218 class ICCPROFLIB_API CIccXformPtr {
00219 public:
00220 CIccXform *ptr;
00221 };
00222
00223
00231 typedef std::list<CIccXformPtr> CIccXformList;
00232
00241 class ICCPROFLIB_API CIccXformMatrixTRC : public CIccXform
00242 {
00243 public:
00244 CIccXformMatrixTRC();
00245 virtual ~CIccXformMatrixTRC();
00246
00247 virtual icXformType GetXformType() { return icXformTypeMatrixTRC; }
00248
00249 virtual icStatusCMM Begin();
00250 virtual void Apply(icFloatNumber *DstPixel, const icFloatNumber *SrcPixel);
00251
00252 virtual LPIccCurve* ExtractInputCurves();
00253 virtual LPIccCurve* ExtractOutputCurves();
00254
00255 protected:
00256 icFloatNumber m_e[9];
00257 CIccCurve *m_Curve[3];
00258 CIccCurve *GetCurve(icSignature sig) const;
00259 CIccCurve *GetInvCurve(icSignature sig) const;
00260
00261 CIccTagXYZ *GetColumn(icSignature sig) const;
00262 bool m_bFreeCurve;
00264 LPIccCurve* m_ApplyCurvePtr;
00265 };
00266
00275 class ICCPROFLIB_API CIccXform3DLut : public CIccXform
00276 {
00277 public:
00278 CIccXform3DLut(CIccTag *pTag);
00279 virtual ~CIccXform3DLut();
00280
00281 virtual icXformType GetXformType() { return icXformType3DLut; }
00282
00283 virtual icStatusCMM Begin();
00284 virtual void Apply(icFloatNumber *DstPixel, const icFloatNumber *SrcPixel);
00285
00286 virtual bool UseLegacyPCS() const { return m_pTag->UseLegacyPCS(); }
00287
00288 virtual LPIccCurve* ExtractInputCurves();
00289 virtual LPIccCurve* ExtractOutputCurves();
00290 protected:
00291 CIccMBB *m_pTag;
00292
00294 LPIccCurve* m_ApplyCurvePtrA;
00295 LPIccCurve* m_ApplyCurvePtrB;
00296 LPIccCurve* m_ApplyCurvePtrM;
00297 CIccMatrix* m_ApplyMatrixPtr;
00298 };
00299
00308 class ICCPROFLIB_API CIccXform4DLut : public CIccXform
00309 {
00310 public:
00311 CIccXform4DLut(CIccTag *pTag);
00312 virtual ~CIccXform4DLut();
00313
00314 virtual icXformType GetXformType() { return icXformType4DLut; }
00315
00316 virtual icStatusCMM Begin();
00317 virtual void Apply(icFloatNumber *DstPixel, const icFloatNumber *SrcPixel);
00318
00319 virtual bool UseLegacyPCS() const { return m_pTag->UseLegacyPCS(); }
00320
00321 virtual LPIccCurve* ExtractInputCurves();
00322 virtual LPIccCurve* ExtractOutputCurves();
00323 protected:
00324 CIccMBB *m_pTag;
00325
00327 LPIccCurve* m_ApplyCurvePtrA;
00328 LPIccCurve* m_ApplyCurvePtrB;
00329 LPIccCurve* m_ApplyCurvePtrM;
00330 CIccMatrix* m_ApplyMatrixPtr;
00331 };
00332
00341 class ICCPROFLIB_API CIccXformNDLut : public CIccXform
00342 {
00343 public:
00344 CIccXformNDLut(CIccTag *pTag);
00345 virtual ~CIccXformNDLut();
00346
00347 virtual icXformType GetXformType() { return icXformTypeNDLut; }
00348
00349 virtual icStatusCMM Begin();
00350 virtual void Apply(icFloatNumber *DstPixel, const icFloatNumber *SrcPixel);
00351
00352 virtual bool UseLegacyPCS() const { return m_pTag->UseLegacyPCS(); }
00353
00354 virtual LPIccCurve* ExtractInputCurves();
00355 virtual LPIccCurve* ExtractOutputCurves();
00356 protected:
00357 CIccMBB *m_pTag;
00358 int m_nNumInput;
00359
00361 LPIccCurve* m_ApplyCurvePtrA;
00362 LPIccCurve* m_ApplyCurvePtrB;
00363 LPIccCurve* m_ApplyCurvePtrM;
00364 CIccMatrix* m_ApplyMatrixPtr;
00365 };
00366
00376 typedef enum {
00377 icApplyPixel2Pixel = 0,
00378 icApplyNamed2Pixel = 1,
00379 icApplyPixel2Named = 2,
00380 icApplyNamed2Named = 3,
00381 } icApplyInterface;
00382
00383
00392 class ICCPROFLIB_API CIccXformNamedColor : public CIccXform
00393 {
00394 public:
00395 CIccXformNamedColor(CIccTag *pTag, icColorSpaceSignature csPCS, icColorSpaceSignature csDevice);
00396 virtual ~CIccXformNamedColor();
00397
00398 virtual icXformType GetXformType() { return icXformTypeNamedColor; }
00399
00400 virtual icStatusCMM Begin();
00401
00403 icApplyInterface GetInterface() const {return m_nApplyInterface;}
00404
00405 virtual void Apply(icFloatNumber *DstPixel, const icFloatNumber *SrcPixel) {}
00406 void Apply(icChar *DstColorName, const icFloatNumber *SrcPixel);
00407 icStatusCMM Apply(icFloatNumber *DstPixel, const icChar *SrcColorName);
00408
00409 virtual bool UseLegacyPCS() const { return m_pTag->UseLegacyPCS(); }
00410
00411 icStatusCMM SetSrcSpace(icColorSpaceSignature nSrcSpace);
00412 icStatusCMM SetDestSpace(icColorSpaceSignature nDestSpace);
00413
00415 icColorSpaceSignature GetSrcSpace() const { return m_nSrcSpace; }
00417 icColorSpaceSignature GetDstSpace() const { return m_nDestSpace; }
00418
00420 bool IsSrcPCS() const {return m_nSrcSpace == m_pTag->GetPCS();}
00422 bool IsDestPCS() const {return m_nDestSpace == m_pTag->GetPCS();}
00423
00424
00425 virtual LPIccCurve* ExtractInputCurves() {return NULL;}
00426 virtual LPIccCurve* ExtractOutputCurves() {return NULL;}
00427
00428 protected:
00429 CIccTagNamedColor2 *m_pTag;
00430 icApplyInterface m_nApplyInterface;
00431 icColorSpaceSignature m_nSrcSpace;
00432 icColorSpaceSignature m_nDestSpace;
00433 };
00434
00435 class ICCPROFLIB_API CIccXformMpe : public CIccXform
00436 {
00437 public:
00438 CIccXformMpe(CIccTag *pTag);
00439 virtual ~CIccXformMpe();
00440
00441 virtual icXformType GetXformType() { return icXformTypeMpe; }
00442
00444 static CIccXform *Create(CIccProfile *pProfile, bool bInput=true, icRenderingIntent nIntent=icUnknownIntent,
00445 icXformInterp nInterp=icInterpLinear, icXformLutType nLutType=icXformLutColor);
00446
00447 virtual icStatusCMM Begin();
00448 virtual void Apply(icFloatNumber *DstPixel, const icFloatNumber *SrcPixel);
00449 virtual bool UseLegacyPCS() const { return false; }
00450 virtual LPIccCurve* ExtractInputCurves() {return NULL;}
00451 virtual LPIccCurve* ExtractOutputCurves() {return NULL;}
00452
00453 protected:
00454 CIccTagMultiProcessElement *m_pTag;
00455 bool m_bUsingAcs;
00456 };
00457
00468 class ICCPROFLIB_API CIccPCS
00469 {
00470 public:
00471 CIccPCS();
00472 virtual ~CIccPCS() {}
00473
00474 void Reset(icColorSpaceSignature StartSpace, bool bUseLegacyPCS = false);
00475
00476 virtual const icFloatNumber *Check(const icFloatNumber *SrcPixel, CIccXform *pXform);
00477 void CheckLast(icFloatNumber *SrcPixel, icColorSpaceSignature Space);
00478
00479 static void LabToXyz(icFloatNumber *Dst, const icFloatNumber *Src, bool bNoClip=false);
00480 static void XyzToLab(icFloatNumber *Dst, const icFloatNumber *Src, bool bNoClip=false);
00481 static void Lab2ToXyz(icFloatNumber *Dst, const icFloatNumber *Src, bool bNoClip=false);
00482 static void XyzToLab2(icFloatNumber *Dst, const icFloatNumber *Src, bool bNoClip=false);
00483 static icFloatNumber NegClip(icFloatNumber v);
00484 static icFloatNumber UnitClip(icFloatNumber v);
00485
00486 static void Lab2ToLab4(icFloatNumber *Dst, const icFloatNumber *Src, bool bNoclip=false);
00487 static void Lab4ToLab2(icFloatNumber *Dst, const icFloatNumber *Src);
00488 protected:
00489
00490 bool m_bIsV2Lab;
00491 icColorSpaceSignature m_Space;
00492
00493 icFloatNumber m_Convert[3];
00494 };
00495
00531 typedef enum
00532 {
00533 icEncodeValue=0,
00534 icEncodePercent,
00535 icEncodeFloat,
00536 icEncode8Bit,
00537 icEncode16Bit,
00538 icEncodeUnknown,
00539 } icFloatColorEncoding;
00540
00550 class ICCPROFLIB_API CIccCmm
00551 {
00552 public:
00553 CIccCmm(icColorSpaceSignature nSrcSpace=icSigUnknownData,
00554 icColorSpaceSignature nDestSpace=icSigUnknownData,
00555 bool bFirstInput=true);
00556 virtual ~CIccCmm();
00557
00558 virtual CIccPCS *GetPCS() { return new CIccPCS(); }
00559
00561 virtual icStatusCMM AddXform(const icChar *szProfilePath, icRenderingIntent nIntent=icUnknownIntent,
00562 icXformInterp nInterp=icInterpLinear, icXformLutType nLutType=icXformLutColor,
00563 bool bUseMpeTags=true);
00564 virtual icStatusCMM AddXform(icUInt8Number *pProfileMem, icUInt32Number nProfileLen,
00565 icRenderingIntent nIntent=icUnknownIntent, icXformInterp nInterp=icInterpLinear,
00566 icXformLutType nLutType=icXformLutColor, bool bUseMpeTags=true);
00567 virtual icStatusCMM AddXform(CIccProfile *pProfile, icRenderingIntent nIntent=icUnknownIntent,
00568 icXformInterp nInterp=icInterpLinear, icXformLutType nLutType=icXformLutColor,
00569 bool bUseMpeTags=true);
00570 virtual icStatusCMM AddXform(CIccProfile &Profile, icRenderingIntent nIntent=icUnknownIntent,
00571 icXformInterp nInterp=icInterpLinear, icXformLutType nLutType=icXformLutColor,
00572 bool bUseMpeTags=true);
00573
00575 virtual icStatusCMM Begin();
00576
00577 virtual icStatusCMM Apply(icFloatNumber *DstPixel, const icFloatNumber *SrcPixel);
00578
00579
00580 virtual icStatusCMM RemoveAllIO();
00581
00583 virtual icUInt32Number GetNumXforms() const;
00584
00586 icColorSpaceSignature GetSourceSpace() const { return m_nSrcSpace; }
00588 icColorSpaceSignature GetDestSpace() const { return m_nDestSpace; }
00590 icRenderingIntent GetLastIntent() const { return m_nLastIntent; }
00591
00593 icUInt16Number GetSourceSamples() const {return (icUInt16Number)icGetSpaceSamples(m_nSrcSpace);}
00595 icUInt16Number GetDestSamples() const {return (icUInt16Number)icGetSpaceSamples(m_nDestSpace);}
00596
00598 bool Valid() const { return m_bValid; }
00599
00600
00601 static bool IsInGamut(icFloatNumber *pData);
00602
00604 static icStatusCMM ToInternalEncoding(icColorSpaceSignature nSpace, icFloatColorEncoding nEncode,
00605 icFloatNumber *pInternal, const icFloatNumber *pData, bool bClip=true);
00606 static icStatusCMM ToInternalEncoding(icColorSpaceSignature nSpace, icFloatNumber *pInternal,
00607 const icUInt8Number *pData);
00608 static icStatusCMM ToInternalEncoding(icColorSpaceSignature nSpace, icFloatNumber *pInternal,
00609 const icUInt16Number *pData);
00610 icStatusCMM ToInternalEncoding(icFloatNumber *pInternal, const icUInt8Number *pData) {return ToInternalEncoding(m_nSrcSpace, pInternal, pData);}
00611 icStatusCMM ToInternalEncoding(icFloatNumber *pInternal, const icUInt16Number *pData) {return ToInternalEncoding(m_nSrcSpace, pInternal, pData);}
00612
00613
00615 static icStatusCMM FromInternalEncoding(icColorSpaceSignature nSpace, icFloatColorEncoding nEncode,
00616 icFloatNumber *pData, const icFloatNumber *pInternal, bool bClip=true);
00617 static icStatusCMM FromInternalEncoding(icColorSpaceSignature nSpace, icUInt8Number *pData,
00618 const icFloatNumber *pInternal);
00619 static icStatusCMM FromInternalEncoding(icColorSpaceSignature nSpace, icUInt16Number *pData,
00620 const icFloatNumber *pInternal);
00621 icStatusCMM FromInternalEncoding(icUInt8Number *pData, icFloatNumber *pInternal) {return FromInternalEncoding(m_nDestSpace, pData, pInternal);}
00622 icStatusCMM FromInternalEncoding(icUInt16Number *pData, icFloatNumber *pInternal) {return FromInternalEncoding(m_nDestSpace, pData, pInternal);}
00623
00624 static const icChar *GetFloatColorEncoding(icFloatColorEncoding val);
00625 static icFloatColorEncoding GetFloatColorEncoding(const icChar* val);
00626
00627 virtual icColorSpaceSignature GetFirstXformSource();
00628 virtual icColorSpaceSignature GetLastXformDest();
00629
00630 protected:
00631 bool m_bValid;
00632
00633 bool m_bLastInput;
00634 icColorSpaceSignature m_nSrcSpace;
00635 icColorSpaceSignature m_nDestSpace;
00636
00637 icColorSpaceSignature m_nLastSpace;
00638 icRenderingIntent m_nLastIntent;
00639
00640 CIccXformList *m_Xforms;
00641
00642 CIccPCS *m_pPCS;
00643 };
00644
00653 class ICCPROFLIB_API CIccNamedColorCmm : public CIccCmm
00654 {
00655 public:
00657 CIccNamedColorCmm(icColorSpaceSignature nSrcSpace=icSigUnknownData,
00658 icColorSpaceSignature nDestSpace=icSigUnknownData,
00659 bool bFirstInput=true);
00660 virtual ~CIccNamedColorCmm();
00661
00663 virtual icStatusCMM AddXform(const icChar *szProfilePath, icRenderingIntent nIntent=icUnknownIntent,
00664 icXformInterp nInterp=icInterpLinear, icXformLutType nLutType=icXformLutColor,
00665 bool bUseMpeTags=true);
00666 virtual icStatusCMM AddXform(CIccProfile *pProfile, icRenderingIntent nIntent=icUnknownIntent,
00667 icXformInterp nInterp=icInterpLinear, icXformLutType nLutType=icXformLutColor,
00668 bool buseMpeTags=true);
00669
00671 virtual icStatusCMM Begin();
00672
00674 virtual icStatusCMM Apply(icFloatNumber *DstPixel, const icFloatNumber *SrcPixel);
00675 virtual icStatusCMM Apply(icChar* DstColorName, const icFloatNumber *SrcPixel);
00676 virtual icStatusCMM Apply(icFloatNumber *DstPixel, const icChar *SrcColorName);
00677 virtual icStatusCMM Apply(icChar* DstColorName, const icChar *SrcColorName);
00678
00680 icApplyInterface GetInterface() const {return m_nApplyInterface;}
00681
00682 icStatusCMM SetLastXformDest(icColorSpaceSignature nDestSpace);
00683
00684 protected:
00685 icApplyInterface m_nApplyInterface;
00686 };
00687
00688
00689 class ICCPROFLIB_API CIccMruPixel
00690 {
00691 public:
00692 CIccMruPixel() { pPixelData = NULL; pNext = NULL; }
00693
00694 icFloatNumber *pPixelData;
00695 CIccMruPixel *pNext;
00696 };
00697
00706 class ICCPROFLIB_API CIccMruCmm : public CIccCmm
00707 {
00708 private:
00709 CIccMruCmm();
00710 public:
00711 virtual ~CIccMruCmm();
00712
00713
00714 static CIccMruCmm* Attach(CIccCmm *pCmm, icUInt8Number nCacheSize=6);
00715
00716
00717 virtual icStatusCMM AddXform(const icChar *szProfilePath, icRenderingIntent nIntent=icUnknownIntent,
00718 icXformInterp nInterp=icInterpLinear, icXformLutType nLutType=icXformLutColor,
00719 bool bUseMpeTags=true) { return icCmmStatBad; }
00720 virtual icStatusCMM AddXform(icUInt8Number *pProfileMem, icUInt32Number nProfileLen,
00721 icRenderingIntent nIntent=icUnknownIntent, icXformInterp nInterp=icInterpLinear,
00722 icXformLutType nLutType=icXformLutColor, bool bUseMpeTags=true) { return icCmmStatBad; }
00723 virtual icStatusCMM AddXform(CIccProfile *pProfile, icRenderingIntent nIntent=icUnknownIntent,
00724 icXformInterp nInterp=icInterpLinear, icXformLutType nLutType=icXformLutColor,
00725 bool bUseMpeTags=true) { return icCmmStatBad; }
00726 virtual icStatusCMM AddXform(CIccProfile &Profile, icRenderingIntent nIntent=icUnknownIntent,
00727 icXformInterp nInterp=icInterpLinear, icXformLutType nLutType=icXformLutColor,
00728 bool bUseMpeTags=true) { return icCmmStatBad; }
00729 virtual icStatusCMM Begin() { return icCmmStatBad; }
00730
00731 virtual icStatusCMM Apply(icFloatNumber *DstPixel, const icFloatNumber *SrcPixel);
00732
00733
00734 virtual icStatusCMM RemoveAllIO() { return m_pCmm->RemoveAllIO(); }
00735 virtual CIccPCS *GetPCS() { return m_pCmm->GetPCS(); }
00736 virtual icUInt32Number GetNumXforms() const { return m_pCmm->GetNumXforms(); }
00737
00738 virtual icColorSpaceSignature GetFirstXformSource() { return m_pCmm->GetFirstXformSource(); }
00739 virtual icColorSpaceSignature GetLastXformDest() { return m_pCmm->GetLastXformDest(); }
00740
00741 protected:
00742 bool Init(CIccCmm *pCmm, icUInt8Number nCacheSize);
00743
00744 CIccCmm *m_pCmm;
00745
00746 icUInt16Number m_nCacheSize;
00747
00748 icFloatNumber *m_pixelData;
00749
00750 CIccMruPixel *m_pFirst;
00751 CIccMruPixel *m_cache;
00752
00753 icUInt16Number m_nNumPixel;
00754
00755 icUInt32Number m_nTotalSamples;
00756 icUInt32Number m_nSrcSamples;
00757
00758 icUInt32Number m_nSrcSize;
00759 icUInt32Number m_nDstSize;
00760 };
00761
00762 #ifdef USESAMPLEICCNAMESPACE
00763 };
00764 #endif
00765
00766 #endif // !defined(_ICCCMM_H)