00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #ifndef PXL_LOOKUP_H
00020 #define PXL_LOOKUP_H
00021
00022 #include "PXL_API.h"
00023
00024 class PXL_Plane;
00025 class PXL_Raster;
00026 class UT_FileLUT;
00027
00028 #include <stdio.h>
00029 #include <SYS/SYS_Types.h>
00030 #include "PXL_Common.h"
00031 #include <CL/CL_Clip.h>
00032
00033 enum PXL_LookupType
00034 {
00035 PXL_LOOKUP_R = 0x001,
00036 PXL_LOOKUP_G = 0x002,
00037 PXL_LOOKUP_B = 0x004,
00038 PXL_LOOKUP_A = 0x008,
00039
00040 PXL_LOOKUP_RGB = 0x017,
00041 PXL_LOOKUP_RGBA = 0x01F,
00042
00043 PXL_LOOKUP_COLOR = 0x027,
00044 PXL_LOOKUP_ALL = 0x02F,
00045
00046 PXL_LOOKUP_3D = 0x040,
00047 PXL_LOOKUP_3D_1D = 0x060,
00048 PXL_LOOKUP_3D_HDR = 0x140
00049 };
00050
00051
00052 #define PXL_LOOKUP_1D 0x3F
00053 #define PXL_SEPARATE_CHANNELS 0x10
00054 #define PXL_SINGLE_CHANNEL 0x20
00055 #define PXL_ILLEGAL_MATCH 0x30
00056 #define PXL_LOG_SAMPLE 0x100
00057
00058
00059 class PXL_API PXL_Lookup
00060 {
00061 public:
00062 PXL_Lookup();
00063 ~PXL_Lookup();
00064
00065 void reset();
00066
00067
00068
00069
00070 void evalLUT(float color[3]) const;
00071
00072
00073 void setLUT(const CL_Clip &clip);
00074
00075
00076 void set3DLUT(int size, float *lut);
00077
00078
00079
00080
00081 void applyLUT(PXL_Raster &r, float gamma = 1.0f,
00082 float black=0.0f, float white=1.0f,
00083 int comp = -1) const;
00084
00085
00086
00087 PXL_LookupType getType() const;
00088 bool getLogSampling() const;
00089 float getLogBias() const;
00090 int getNumChannels() const;
00091 int getTableSize() const;
00092 float getBlackPoint() const;
00093 float getWhitePoint() const;
00094 void getDomain(float &s, float &e) const;
00095 void getRange(float &s, float &e) const;
00096
00097 bool hasSpecificFormat(PXL_DataFormat &format) const;
00098 bool hasLUTfor(PXL_LookupType type) const;
00099
00100 void setType(PXL_LookupType type);
00101 void setLogSampling(bool log);
00102 void setLogBias(float bias);
00103 void setSpecificFormat(PXL_DataFormat format);
00104 void setNumChannels(int num);
00105 void setTableSize(int size);
00106 void setBlackWhitePoints(float b, float w);
00107 void setDomain(float s,float e);
00108 void setRange(float s, float e);
00109 void invert(int newsize = 0);
00110
00111 bool isHalfPrec() const { return myHalfPrecFlag; }
00112
00113
00114 bool is3DLUT() const { return myCubeSize != 0; }
00115 int get3DSize() const { return myCubeSize; }
00116
00117
00118
00119 float *getRawLUT(PXL_LookupType type);
00120 const float *getRawLUT(PXL_LookupType type) const;
00121
00122 bool evalLUT(PXL_LookupType,
00123 int nsamples,
00124 float *data,
00125 unsigned b = 0,
00126 unsigned w = 0) const;
00127
00128 bool evalLUT(PXL_LookupType,
00129 int nsamples,
00130 float *data,
00131 float black, float white,
00132 float from = 0.0f, float to = 1.0f) const;
00133 float evalLUT(PXL_LookupType, float pos) const;
00134
00135 void eval1DLUT(float color[3]) const;
00136 void get1DLUT(float *lut[4], int size, float b, float w,
00137 float sc, float sh, float gamma) const;
00138
00139 void apply1DLUT(PXL_Raster &raster,
00140 float gamma = 1.0f,
00141 float black = 0.0f,
00142 float white = 1.0f,
00143 int comp = -1) const;
00144
00145
00146 void eval3DLUT(float color[3]) const;
00147
00148
00149
00150
00151 void copy3DLUT(float *lut) const;
00152 void copy3DLUT(fpreal16 *lut) const;
00153
00154
00155 void clamp3DLUT();
00156
00157 void apply3DLUT(PXL_Raster &r, float gamma = 1.0f,
00158 float black = 0.0f, float white = 1.0f,
00159 int component = -1) const;
00160
00161
00162
00163 bool load(const char *filename, bool header_only = false);
00164 bool save(const char *filename, bool half_prec=false) const;
00165
00166
00167 bool load(FILE *fp, bool header_only);
00168 bool loadBinary(FILE *fp, bool header_only);
00169 bool save(FILE *fp) const;
00170 bool saveBinary(FILE *fp, bool half_prec = false) const;
00171
00172
00173
00174
00175 UT_FileLUT *getCineonLUT(bool forward,
00176 const char *filename = 0) const;
00177
00178 void setTextureID(unsigned int id) { myTextureID = id; }
00179 unsigned int getTextureID() const;
00180 void clearTextureID();
00181
00182 private:
00183 int getIndexFor(PXL_LookupType type) const;
00184
00185 bool correctLUT();
00186
00187 void save1D(FILE *fp, bool bin, bool half = false) const;
00188 void save3D(FILE *fp, bool bin, bool half = false) const;
00189
00190 CL_Clip *myTable;
00191 PXL_LookupType myType;
00192 PXL_DataFormat myFormat;
00193
00194
00195 float *myCubeLUT;
00196 int myCubeSize;
00197
00198 float myBlack;
00199 float myWhite;
00200 float myDomStart;
00201 float myDomEnd;
00202 float myRangeStart;
00203 float myRangeEnd;
00204 float myLogBias;
00205 unsigned int myTextureID;
00206 bool myHalfPrecFlag;
00207 };
00208
00209 #endif