SampleICC Main srcforge
Main Page | Class Hierarchy | Class List | File List | Class Members | File Members

IccTagLut.h

Go to the documentation of this file.
00001 
00012 /*
00013  * The ICC Software License, Version 0.1
00014  *
00015  *
00016  * Copyright (c) 2005 The International Color Consortium. All rights 
00017  * reserved.
00018  *
00019  * Redistribution and use in source and binary forms, with or without
00020  * modification, are permitted provided that the following conditions
00021  * are met:
00022  *
00023  * 1. Redistributions of source code must retain the above copyright
00024  *    notice, this list of conditions and the following disclaimer. 
00025  *
00026  * 2. Redistributions in binary form must reproduce the above copyright
00027  *    notice, this list of conditions and the following disclaimer in
00028  *    the documentation and/or other materials provided with the
00029  *    distribution.
00030  *
00031  * 3. The end-user documentation included with the redistribution,
00032  *    if any, must include the following acknowledgment:  
00033  *       "This product includes software developed by the
00034  *        The International Color Consortium (www.color.org)"
00035  *    Alternately, this acknowledgment may appear in the software itself,
00036  *    if and wherever such third-party acknowledgments normally appear.
00037  *
00038  * 4. In the absence of prior written permission, the names "ICC" and "The
00039  *    International Color Consortium" must not be used to imply that the
00040  *    ICC organization endorses or promotes products derived from this
00041  *    software.
00042  *
00043  *
00044  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
00045  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
00046  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
00047  * DISCLAIMED.  IN NO EVENT SHALL THE INTERNATIONAL COLOR CONSORTIUM OR
00048  * ITS CONTRIBUTING MEMBERS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
00049  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
00050  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
00051  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
00052  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
00053  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
00054  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
00055  * SUCH DAMAGE.
00056  * ====================================================================
00057  *
00058  * This software consists of voluntary contributions made by many
00059  * individuals on behalf of the The International Color Consortium. 
00060  *
00061  *
00062  * Membership in the ICC is encouraged when this software is used for
00063  * commercial purposes. 
00064  *
00065  *  
00066  * For more information on The International Color Consortium, please
00067  * see <http://www.color.org/>.
00068  *  
00069  * 
00070  */
00071 
00073 // HISTORY:
00074 //
00075 // -Initial implementation by Max Derhak 5-15-2003
00076 //
00077 // -Moved LUT tags to separate file 4-30-2005
00078 //
00080 
00081 #if !defined(_ICCTAGLUT_H)
00082 #define _ICCTAGLUT_H
00083 
00084 #ifdef USESAMPLEICCNAMESPACE
00085 namespace sampleICC {
00086 #endif
00087 
00088 #include "IccTagBasic.h"
00089 
00097 class ICCPROFLIB_API CIccCurve : public CIccTag
00098 {
00099 public:
00100   CIccCurve() {}
00101   virtual CIccTag *NewCopy() const { return new CIccCurve; } 
00102   virtual ~CIccCurve() {}
00103 
00104   virtual void DumpLut(std::string &sDescription, const icChar *szName,
00105     icColorSpaceSignature csSig, int nIndex) {}
00106 
00107   virtual void Begin() {}
00108   virtual icFloatNumber Apply(icFloatNumber v) { return v; }
00109 
00110   icFloatNumber Find(icFloatNumber v) { return Find(v, 0, Apply(0), 1.0, Apply(1.0)); }
00111   virtual bool IsIdentity() {return false;}
00112 
00113 protected:
00114   icFloatNumber Find(icFloatNumber v,
00115     icFloatNumber p0, icFloatNumber v0,
00116     icFloatNumber p1, icFloatNumber v1);
00117 
00118 };
00119 typedef CIccCurve* LPIccCurve;
00120 
00121 typedef enum {
00122   icInitNone,
00123   icInitZero,
00124   icInitIdentity,
00125 } icTagCurveSizeInit;
00126 
00134 class ICCPROFLIB_API CIccTagCurve : public CIccCurve
00135 {
00136 public:
00137   CIccTagCurve(int nSize=0);
00138   CIccTagCurve(const CIccTagCurve &ITCurve);
00139   CIccTagCurve &operator=(const CIccTagCurve &CurveTag);
00140   virtual CIccTag *NewCopy() const { return new CIccTagCurve(*this);}
00141   virtual ~CIccTagCurve();
00142 
00143   virtual icTagTypeSignature GetType() { return icSigCurveType; }
00144   virtual const icChar *GetClassName() { return "CIccTagCurve"; }
00145 
00146   virtual void Describe(std::string &sDescription);
00147   virtual void DumpLut(std::string &sDescription, const icChar *szName, 
00148     icColorSpaceSignature csSig, int nIndex);
00149 
00150   virtual bool Read(icUInt32Number size, CIccIO *pIO);
00151   virtual bool Write(CIccIO *pIO);
00152 
00153   icFloatNumber &operator[](icUInt32Number index) {return m_Curve[index];}
00154   icFloatNumber *GetData(icUInt32Number index) {return &m_Curve[index];}
00155   icUInt32Number GetSize() const { return m_nSize; }
00156   void SetSize(icUInt32Number nSize, icTagCurveSizeInit nSizeOpt=icInitZero);
00157   void SetGamma(icFloatNumber gamma);
00158 
00159   virtual void Begin() {m_nMaxIndex = (icUInt16Number)m_nSize - 1;}
00160   virtual icFloatNumber Apply(icFloatNumber v);
00161   virtual icValidateStatus Validate(icTagSignature sig, std::string &sReport, const CIccProfile* pProfile=NULL) const;
00162   virtual bool IsIdentity();
00163 
00164 protected:
00165   icFloatNumber *m_Curve;
00166   icUInt32Number m_nSize;
00167   icUInt16Number m_nMaxIndex;
00168 };
00169 
00177 class ICCPROFLIB_API CIccTagParametricCurve : public CIccCurve
00178 {
00179 public:
00180   CIccTagParametricCurve();
00181   CIccTagParametricCurve(const CIccTagParametricCurve &ITPC);
00182   CIccTagParametricCurve &operator=(const CIccTagParametricCurve &ParamCurveTag);
00183   virtual CIccTag *NewCopy() const { return new CIccTagParametricCurve(*this);}
00184   virtual ~CIccTagParametricCurve();
00185 
00186   virtual icTagTypeSignature GetType() { return icSigParametricCurveType; }
00187   virtual const icChar *GetClassName() { return "CIccTagParametricCurve"; }
00188 
00189   virtual void Describe(std::string &sDescription);
00190   virtual void DumpLut(std::string &sDescription, const icChar *szName,
00191     icColorSpaceSignature csSig, int nIndex);
00192 
00193   virtual bool Read(icUInt32Number size, CIccIO *pIO);
00194   virtual bool Write(CIccIO *pIO);
00195 
00196 
00197   bool SetFunctionType(icUInt16Number nFunctionType); //# parameters set by 
00198   icUInt16Number GetFunctionType() const {return m_nFunctionType; }
00199 
00200   icUInt16Number GetNumParam() const { return m_nNumParam; }
00201   icS15Fixed16Number *GetParams() const { return m_Param; }
00202   icS15Fixed16Number Param(int index) const { return m_Param[index]; }
00203   icS15Fixed16Number& operator[](int index) { return m_Param[index]; }
00204 
00205   virtual void Begin();
00206   virtual icFloatNumber Apply(icFloatNumber v);
00207   virtual icValidateStatus Validate(icTagSignature sig, std::string &sReport, const CIccProfile* pProfile=NULL);
00208   virtual bool IsIdentity();
00209 
00210 protected:
00211   icUInt16Number      m_nReserved2;
00212   icUInt16Number      m_nFunctionType;
00213   icS15Fixed16Number *m_Param;
00214   icUInt16Number      m_nNumParam;
00215 
00216   icFloatNumber *m_dParam;
00217 };
00218 
00219 
00227 class ICCPROFLIB_API CIccMatrix
00228 {
00229 public:
00230   CIccMatrix(bool bUseConstants=true);
00231   CIccMatrix(const CIccMatrix &MatrixClass);
00232   CIccMatrix &operator=(const CIccMatrix &MatrixClass);
00233   virtual ~CIccMatrix() {}
00234 
00235   void DumpLut(std::string &sDescription, const icChar *szName);
00236 
00237   icFloatNumber m_e[12]; //e = element
00238   bool m_bUseConstants;
00239 
00240   virtual void Apply(icFloatNumber *Pixel);
00241   icValidateStatus Validate(icTagTypeSignature sig, std::string &sReport, const CIccProfile* pProfile=NULL) const;
00242   virtual bool IsIdentity();
00243 };
00244 
00252 class ICCPROFLIB_API IIccCLUTExec 
00253 {
00254 public:
00255   virtual ~IIccCLUTExec() {}
00256 
00257   virtual void PixelOp(icFloatNumber* pGridAdr, icFloatNumber* pData)=0;
00258 };
00259 
00260 typedef icFloatNumber (*icCLUTCLIPFUNC)(icFloatNumber v);
00261 
00269 class ICCPROFLIB_API CIccCLUT
00270 {
00271 public:
00272   CIccCLUT(icUInt8Number nInputChannels, icUInt8Number nOutputChannels, icUInt8Number nPrecision=2);
00273   CIccCLUT(const CIccCLUT &ICLUT);
00274   CIccCLUT &operator=(const CIccCLUT &CLUTClass);
00275   virtual ~CIccCLUT();
00276 
00277   void Init(icUInt8Number nGridPoints);
00278   void Init(icUInt8Number *pGridPoints);
00279 
00280   bool ReadData(icUInt32Number size, CIccIO *pIO, icUInt8Number nPrecision);
00281   bool WriteData(CIccIO *pIO, icUInt8Number nPrecision);
00282 
00283   bool Read(icUInt32Number size, CIccIO *pIO);
00284   bool Write(CIccIO *pIO);
00285 
00286   void DumpLut(std::string  &sDescription, const icChar *szName,
00287                icColorSpaceSignature csInput, icColorSpaceSignature csOutput);
00288 
00289   icFloatNumber& operator[](int index) { return m_pData[index]; }
00290   icFloatNumber* GetData(int index) { return &m_pData[index]; }
00291   icUInt32Number NumPoints() const { return m_nNumPoints; }
00292   icUInt8Number GridPoints() const { return m_GridPoints[0]; }
00293   icUInt8Number GridPoint(int index) const { return m_GridPoints[index]; }
00294 
00295   icUInt32Number GetDimSize(icUInt8Number nIndex) const { return m_DimSize[nIndex]; }
00296 
00297   icUInt8Number GetInputDim() const { return m_nInput; }
00298   icUInt8Number GetOutputChannels() const { return m_nOutput; }
00299 
00300   void Begin();
00301   void Interp3dTetra(icFloatNumber *destPixel, const icFloatNumber *srcPixel);
00302   void Interp3d(icFloatNumber *destPixel, const icFloatNumber *srcPixel);
00303   void Interp4d(icFloatNumber *destPixel, const icFloatNumber *srcPixel);
00304   void Interp5d(icFloatNumber *destPixel, const icFloatNumber *srcPixel);
00305   void Interp6d(icFloatNumber *destPixel, const icFloatNumber *srcPixel);
00306   void InterpND(icFloatNumber *destPixel, const icFloatNumber *srcPixel);
00307 
00308   void Iterate(IIccCLUTExec* pExec);
00309   icValidateStatus Validate(icTagTypeSignature sig, std::string &sReport, const CIccProfile* pProfile=NULL)  const;
00310 
00311   void SetClipFunc(icCLUTCLIPFUNC ClipFunc) { UnitClip = ClipFunc; }
00312 
00313   icUInt8Number GetPrecision() { return m_nPrecision; }
00314 
00315 protected:
00316   void Iterate(std::string &sDescription, icUInt8Number nIndex, icUInt32Number nPos);
00317   void SubIterate(IIccCLUTExec* pExec, icUInt8Number nIndex, icUInt32Number nPos);
00318 
00319   icCLUTCLIPFUNC UnitClip;
00320 
00321   icUInt8Number m_nReserved2[3];
00322   
00323   icUInt8Number m_nInput;
00324   icUInt8Number m_nOutput;
00325   icUInt8Number m_nPrecision;
00326 
00327   icUInt8Number m_GridPoints[16];
00328   icUInt32Number m_nNumPoints;
00329 
00330   icUInt32Number m_DimSize[16];
00331   icFloatNumber *m_pData;
00332 
00333   //Iteration temporary variables
00334   icUInt8Number m_GridAdr[16];
00335   icFloatNumber m_fGridAdr[16];
00336   icChar *m_pOutText, *m_pVal;
00337   icColorSpaceSignature m_csInput, m_csOutput;
00338 
00339   //Tetrahedral interpolation variables
00340   icUInt8Number m_MaxGridPoint[16];
00341   icUInt32Number n000, n001, n010, n011, n100, n101, n110, n111, n1000, n10000, n100000;
00342 
00343   //ND Interpolation
00344   icUInt32Number *m_nOffset;
00345   // Temporary ND Interp Variables
00346   icFloatNumber *m_g, *m_s, *m_df;
00347   icUInt32Number* m_ig;
00348   icUInt32Number m_nNodes, m_nPower[16];
00349 };
00350 
00351 
00360 class ICCPROFLIB_API CIccMBB : public CIccTag
00361 {
00362   friend class ICCPROFLIB_API CIccXform3DLut;
00363   friend class ICCPROFLIB_API CIccXform4DLut;
00364   friend class ICCPROFLIB_API CIccXformNDLut;
00365 public:
00366   CIccMBB();
00367   CIccMBB(const CIccMBB &IMBB);
00368   CIccMBB &operator=(const CIccMBB &IMBB);
00369   virtual CIccTag* NewCopy() const {return new CIccMBB(*this);}
00370   virtual ~CIccMBB();
00371 
00372   virtual bool IsMBBType() { return true;}
00373 
00374   virtual icUInt8Number GetPrecision() { return 2; }
00375   virtual bool IsInputMatrix() { return m_bInputMatrix; } //Is matrix on input side of CLUT?
00376   virtual bool UseLegacyPCS() { return false; } //Treat Lab Encoding differently?
00377 
00378   bool IsInputB() { return IsInputMatrix(); }
00379 
00380   void Cleanup();
00381   void Init(icUInt8Number nInputChannels, icUInt8Number nOutputChannels);
00382 
00383   icUInt8Number InputChannels() const { return m_nInput; }
00384   icUInt8Number OutputChannels() const { return m_nOutput; }
00385 
00386   virtual void Describe(std::string &sDescription);
00387 
00388   virtual void SetColorSpaces(icColorSpaceSignature csInput, icColorSpaceSignature csOutput);
00389   virtual icValidateStatus Validate(icTagSignature sig, std::string &sReport, const CIccProfile* pProfile=NULL);
00390 
00391   LPIccCurve* NewCurvesA();
00392   CIccCLUT*   NewCLUT(icUInt8Number nGridPoints, icUInt8Number nPrecision=2);
00393   CIccCLUT*   NewCLUT(icUInt8Number *pGridPoints, icUInt8Number nPrecision=2);
00394   CIccMatrix* NewMatrix();
00395   LPIccCurve* NewCurvesM();
00396   LPIccCurve* NewCurvesB();
00397 
00398   CIccMatrix *GetMatrix() const  {return m_Matrix; }
00399   CIccCLUT   *GetCLUT() const    {return m_CLUT;}
00400   LPIccCurve *GetCurvesA() const {return m_CurvesA;}
00401   LPIccCurve *GetCurvesB() const {return m_CurvesB;}
00402   LPIccCurve *GetCurvesM() const {return m_CurvesM;}
00403 
00404 
00405 
00406 protected:
00407   bool m_bInputMatrix;
00408 
00409   icUInt8Number m_nInput;
00410   icUInt8Number m_nOutput;
00411 
00412   icColorSpaceSignature m_csInput;
00413   icColorSpaceSignature m_csOutput;
00414 
00415   LPIccCurve *m_CurvesA;
00416   CIccCLUT  *m_CLUT;
00417   CIccMatrix *m_Matrix;
00418   LPIccCurve *m_CurvesM;
00419   LPIccCurve *m_CurvesB;
00420 
00421 };
00422 
00430 class ICCPROFLIB_API CIccTagLutAtoB : public CIccMBB
00431 {
00432 public:
00433   CIccTagLutAtoB();
00434   CIccTagLutAtoB(const CIccTagLutAtoB &ITLA2B);
00435   CIccTagLutAtoB &operator=(const CIccTagLutAtoB &ITLA2B);
00436   virtual CIccTag* NewCopy() { return new CIccTagLutAtoB(*this); }
00437   virtual ~CIccTagLutAtoB();
00438 
00439   virtual icTagTypeSignature GetType() { return icSigLutAtoBType; }
00440 
00441   bool Read(icUInt32Number size, CIccIO *pIO);
00442   bool Write(CIccIO *pIO);
00443   virtual icValidateStatus Validate(icTagSignature sig, std::string &sReport, const CIccProfile* pProfile=NULL);
00444 
00445 protected:
00446   icUInt16Number m_nReservedWord;
00447 };
00448 
00456 class ICCPROFLIB_API CIccTagLutBtoA : public CIccTagLutAtoB
00457 {
00458 public:
00459   CIccTagLutBtoA();
00460   CIccTagLutBtoA(const CIccTagLutBtoA &ITLB2A);
00461   CIccTagLutBtoA &operator=(const CIccTagLutBtoA &ITLB2A);
00462   virtual CIccTag* NewCopy() { return new CIccTagLutBtoA(*this); }
00463 
00464   virtual icTagTypeSignature GetType() { return icSigLutBtoAType; }
00465   virtual icValidateStatus Validate(icTagSignature sig, std::string &sReport, const CIccProfile* pProfile=NULL);
00466 };
00467 
00468 
00476 class ICCPROFLIB_API CIccTagLut8 : public CIccMBB
00477 {
00478 public:
00479   CIccTagLut8();
00480   CIccTagLut8(const CIccTagLut8 &ITL);
00481   CIccTagLut8 &operator=(const CIccTagLut8 &ITL);
00482   virtual CIccTag* NewCopy() const {return new CIccTagLut8(*this);}
00483   virtual ~CIccTagLut8();
00484 
00485   virtual icTagTypeSignature GetType() { return icSigLut8Type; }
00486 
00487   bool Read(icUInt32Number size, CIccIO *pIO);
00488   bool Write(CIccIO *pIO);
00489 
00490   virtual void SetColorSpaces(icColorSpaceSignature csInput, icColorSpaceSignature csOutput);
00491   virtual icValidateStatus Validate(icTagSignature sig, std::string &sReport, const CIccProfile* pProfile=NULL);
00492 
00493 protected:
00494   icUInt8Number m_nReservedByte;
00495   icS15Fixed16Number m_XYZMatrix[9];
00496 };
00497 
00505 class ICCPROFLIB_API CIccTagLut16 : public CIccMBB
00506 {
00507 public:
00508   CIccTagLut16();
00509   CIccTagLut16(const CIccTagLut16 &ITL);
00510   CIccTagLut16 &operator=(const CIccTagLut16 &ITL);
00511   virtual CIccTag* NewCopy() const {return new CIccTagLut16(*this);}
00512   virtual ~CIccTagLut16();
00513   
00514   virtual icTagTypeSignature GetType() { return icSigLut16Type; }
00515   virtual bool UseLegacyPCS() { return true; } //Treat Lab Encoding differently?
00516 
00517   bool Read(icUInt32Number size, CIccIO *pIO);
00518   bool Write(CIccIO *pIO);
00519 
00520   virtual void SetColorSpaces(icColorSpaceSignature csInput, icColorSpaceSignature csOutput);
00521   virtual icValidateStatus Validate(icTagSignature sig, std::string &sReport, const CIccProfile* pProfile=NULL);
00522 
00523 protected:
00524   icUInt8Number m_nReservedByte;
00525   icS15Fixed16Number m_XYZMatrix[9];
00526 };
00527 
00528 
00529 #ifdef USESAMPLEICCNAMESPACE
00530 } //namespace sampleICC
00531 #endif
00532 
00533 #endif // !defined(_ICCTAG_H)

Generated on Tue Jun 26 17:51:43 2007 for IccProfLib by  doxygen 1.3.9.1