IccMAX 2.1.27
Color Profile Tools
Loading...
Searching...
No Matches
CubeFile Class Reference

Public Member Functions

 CubeFile (const char *szFilename)
 
 ~CubeFile ()
 
void close ()
 
std::string getCopyright ()
 
std::string getDescription ()
 
icFloatNumbergetMaxInput ()
 
icFloatNumbergetMinInput ()
 
bool isCustomInputRange ()
 
bool parse3DTable (icFloatNumber *toLut, icUInt32Number nSizeLut)
 
bool parseHeader ()
 
int sizeLut3D ()
 

Protected Member Functions

const char * getNext (const char *str)
 
std::string getNextLine ()
 
std::string getTitle (const char *str)
 
bool isEOF ()
 
bool open ()
 
std::string toEnd (const char *str)
 

Protected Attributes

bool m_bLutInVideoRange = false
 
bool m_bLutOutVideoRange = false
 
std::string m_comments
 
FILE * m_f =nullptr
 
icFloatNumber m_fMaxInput [3] = { 1.0f, 1.0f, 1.0f }
 
icFloatNumber m_fMinInput [3] = { 0.0f, 0.0f, 0.0f }
 
std::string m_sFilename
 
int m_sizeLut3D = 0
 
std::string m_title
 

Detailed Description

Constructor & Destructor Documentation

◆ CubeFile()

CubeFile::CubeFile ( const char *  szFilename)
inline
85 {
86 m_sFilename = szFilename;
87 }
std::string m_sFilename
Definition iccFromCube.cpp:251

References m_sFilename.

Referenced by main().

+ Here is the caller graph for this function:

◆ ~CubeFile()

CubeFile::~CubeFile ( )
inline
88{ close(); }
void close()
Definition iccFromCube.cpp:90

References close().

+ Here is the call graph for this function:

Member Function Documentation

◆ close()

void CubeFile::close ( )
inline
91 {
92 if (m_f)
93 fclose(m_f);
94 m_f = nullptr;
95 }
FILE * m_f
Definition iccFromCube.cpp:320

References m_f.

Referenced by ~CubeFile(), and main().

+ Here is the caller graph for this function:

◆ getCopyright()

std::string CubeFile::getCopyright ( )
inline
202{ return m_comments; }
std::string m_comments
Definition iccFromCube.cpp:327

References m_comments.

Referenced by main().

+ Here is the caller graph for this function:

◆ getDescription()

std::string CubeFile::getDescription ( )
inline
201{ return m_title; }
std::string m_title
Definition iccFromCube.cpp:326

References m_title.

Referenced by main().

+ Here is the caller graph for this function:

◆ getMaxInput()

icFloatNumber * CubeFile::getMaxInput ( )
inline
205{ return m_fMaxInput; }
icFloatNumber m_fMaxInput[3]
Definition iccFromCube.cpp:324

References m_fMaxInput.

Referenced by main().

+ Here is the caller graph for this function:

◆ getMinInput()

icFloatNumber * CubeFile::getMinInput ( )
inline
204{ return m_fMinInput; }
icFloatNumber m_fMinInput[3]
Definition iccFromCube.cpp:323

References m_fMinInput.

Referenced by main().

+ Here is the caller graph for this function:

◆ getNext()

const char * CubeFile::getNext ( const char *  str)
inlineprotected
280 {
281 while (*str && *str == ' ') str++;
282 while (*str && *str != ' ') str++;
283 while (*str && *str == ' ') str++;
284
285 return str;
286 }

Referenced by parse3DTable(), and parseHeader().

+ Here is the caller graph for this function:

◆ getNextLine()

std::string CubeFile::getNextLine ( )
inlineprotected
303 {
304 std::string rv;
305 for (int n=0; n<MAX_LINE_LEN && !isEOF(); n++) {
306 char c = fgetc(m_f);
307
308 if ((c < 0 && feof(m_f)) || c == '\n')
309 break;
310
311 if (c == '\r') //skip unsupported carriage returns
312 continue;
313
314 rv += (unsigned char)c;
315 }
316
317 return rv;
318 }
#define MAX_LINE_LEN
Definition iccFromCube.cpp:300
bool isEOF()
Definition iccFromCube.cpp:298

References isEOF(), and m_f.

Referenced by parse3DTable(), and parseHeader().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getTitle()

std::string CubeFile::getTitle ( const char *  str)
inlineprotected
265 {
266 std::string rv;
267 bool bNeedQuote = false;
268 if (*str == '\"') {
269 bNeedQuote = true;
270 str++;
271 }
272 while (*str && (!bNeedQuote || *str != '\"')) {
273 rv += *str++;
274 }
275
276 return rv;
277 }

Referenced by parseHeader().

+ Here is the caller graph for this function:

◆ isCustomInputRange()

bool CubeFile::isCustomInputRange ( )
inline
208 {
209 if (!icIsNear(m_fMinInput[0], 0.0) || !icIsNear(m_fMinInput[1], 0.0) || !icIsNear(m_fMinInput[2], 0.0) ||
210 !icIsNear(m_fMaxInput[0], 1.0) || !icIsNear(m_fMaxInput[1], 1.0) || !icIsNear(m_fMaxInput[2], 1.0))
211 return true;
212 return false;
213 }
ICCPROFLIB_API bool icIsNear(icFloatNumber v1, icFloatNumber v2, icFloatNumber nearRange=1.0e-8)
Definition IccUtil.cpp:142

References icIsNear(), m_fMaxInput, and m_fMinInput.

Referenced by main().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ isEOF()

bool CubeFile::isEOF ( )
inlineprotected
298{ return m_f ? feof(m_f)!=0 : true; }

References m_f.

Referenced by getNextLine(), parse3DTable(), and parseHeader().

+ Here is the caller graph for this function:

◆ open()

bool CubeFile::open ( )
inlineprotected
254 {
255 if (!m_f) {
256 m_f = fopen(m_sFilename.c_str(), "rb");
257 }
258 else {
259 fseek(m_f, 0, SEEK_SET);
260 }
261 return m_f != nullptr;
262 }

References m_f, and m_sFilename.

Referenced by parseHeader().

+ Here is the caller graph for this function:

◆ parse3DTable()

bool CubeFile::parse3DTable ( icFloatNumber toLut,
icUInt32Number  nSizeLut 
)
inline
217 {
219
220 //
221 if (!m_sizeLut3D || nSizeLut != num*3)
222 return false;
223
224 const char* next;
225 for (auto n = 0u; n < num && !isEOF();) {
226 std::string line = getNextLine();
227
228 //Skip empty and commented lines
229 if (line[0] == '#' || line.size() == 0)
230 continue;
231 *toLut++ = (icFloatNumber)atof(line.c_str());
232 next = getNext(line.c_str());
233 if (!next) {
234 printf("Invalid 3DLUT entry\n");
235 return false;
236 }
237 *toLut++ = (icFloatNumber)atof(next);
238 next = getNext(next);
239 if (!next) {
240 printf("Invalid 3DLUT entry\n");
241 return false;
242 }
243 *toLut++ = (icFloatNumber)atof(next);
244
245 n++;
246 }
247 return true;
248 }
unsigned long icUInt32Number
Definition icProfileHeader.h:262
float icFloatNumber
Definition IccDefs.h:101
const char * getNext(const char *str)
Definition iccFromCube.cpp:279
int m_sizeLut3D
Definition iccFromCube.cpp:322
std::string getNextLine()
Definition iccFromCube.cpp:302

References getNext(), getNextLine(), isEOF(), and m_sizeLut3D.

Referenced by main().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ parseHeader()

bool CubeFile::parseHeader ( )
inline
98 {
99 if (!open())
100 return false;
101
102 m_title.clear();
103 m_comments.clear();
104 m_sizeLut3D = 0;
105 m_fMinInput[0] = m_fMinInput[1] = m_fMinInput[2] = 0.0f;
106 m_fMaxInput[0] = m_fMaxInput[1] = m_fMaxInput[2] = 1.0f;
107
108 bool bAddBlankLine = false;
109 while (!isEOF()) {
110 long pos = ftell(m_f);
111 std::string line = getNextLine();
112
113 if (line[0] == '-' || line[0] == '.' || (line[0] >= '0' && line[0] <= '9')) {
114 //undo getNextLine so it can be 3D table can be parsed
115 fseek(m_f, pos, SEEK_SET);
116 break;
117 }
118
119 if (!line.size()) {
120 if (m_comments.size()) {
121 bAddBlankLine = true;
122 }
123 }
124 else if (line.substr(0, 6) == "TITLE ") {
125 if (m_title.size()) {
126 m_title += "\n";
127 }
128 m_title += getTitle(line.c_str() + 6);
129 }
130 else if (line[0] == '#') {
131 if (bAddBlankLine) {
132 m_comments += "\n";
133 }
134 if (line[1]==' ')
135 m_comments += line.c_str() + 2;
136 else
137 m_comments += line.c_str() + 1;
138 m_comments += '\n';
139
140 bAddBlankLine = false;
141 }
142 else if (line.substr(0, 12) == "LUT_1D_SiZE ") {
143 printf("1DLUTs are not supported\n");
144 return false;
145 }
146 else if (line.substr(0, 12) == "LUT_3D_SIZE ") {
147 m_sizeLut3D = atoi(line.c_str() + 12);
148 }
149 else if (line.substr(0, 19) == "LUT_3D_INPUT_RANGE ") {
150 m_fMinInput[0] = m_fMinInput[1] = m_fMinInput[2] = (icFloatNumber)atof(line.c_str() + 19);
151 const char* next = getNext(line.c_str() + 19);
152 if (next) {
153 m_fMaxInput[0] = m_fMaxInput[1] = m_fMaxInput[2] = (icFloatNumber)atof(next);
154 }
155 }
156 else if (line.substr(0, 11) == "DOMAIN_MIN ") {
157 m_fMinInput[0] = (icFloatNumber)atof(line.c_str() + 11);
158 const char* next = getNext(line.c_str());
159 if (next) {
160 m_fMinInput[1] = (icFloatNumber)atof(next);
161 next = getNext(next);
162 if (next) {
163 m_fMinInput[2] = (icFloatNumber)atof(next);
164 }
165 else
166 m_fMinInput[2] = m_fMinInput[1];
167 }
168 else {
170 }
171 }
172 else if (line.substr(0, 11) == "DOMAIN_MAX ") {
173 m_fMaxInput[0] = (icFloatNumber)atof(line.c_str() + 11);
174 const char* next = getNext(line.c_str());
175 if (next) {
176 m_fMaxInput[1] = (icFloatNumber)atof(next);
177 next = getNext(next);
178 if (next) {
179 m_fMaxInput[2] = (icFloatNumber)atof(next);
180 }
181 else
182 m_fMaxInput[2] = m_fMaxInput[1];
183 }
184 else {
186 }
187 }
188 else if (line.substr(0, 18) == "LUT_IN_VIDEO_RANGE")
189 m_bLutInVideoRange = true;
190 else if (line.substr(0, 19) == "LUT_OUT_VIDEO_RANGE")
191 m_bLutOutVideoRange = true;
192 else {
193 printf("Unknown keyword '%s'\n", line.c_str());
194 return false;
195 }
196 }
197
198 return !isEOF();
199 }
bool open()
Definition iccFromCube.cpp:253
std::string getTitle(const char *str)
Definition iccFromCube.cpp:264
bool m_bLutInVideoRange
Definition iccFromCube.cpp:329
bool m_bLutOutVideoRange
Definition iccFromCube.cpp:330

References getNext(), getNextLine(), getTitle(), isEOF(), m_bLutInVideoRange, m_bLutOutVideoRange, m_comments, m_f, m_fMaxInput, m_fMinInput, m_sizeLut3D, m_title, and open().

Referenced by main().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ sizeLut3D()

int CubeFile::sizeLut3D ( )
inline
215{ return m_sizeLut3D; }

References m_sizeLut3D.

Referenced by main().

+ Here is the caller graph for this function:

◆ toEnd()

std::string CubeFile::toEnd ( const char *  str)
inlineprotected
289 {
290 std::string rv;
291 while (*str && *str != '\"') {
292 rv += *str++;
293 }
294
295 return rv;
296 }

Field Documentation

◆ m_bLutInVideoRange

bool CubeFile::m_bLutInVideoRange = false
protected

Referenced by parseHeader().

◆ m_bLutOutVideoRange

bool CubeFile::m_bLutOutVideoRange = false
protected

Referenced by parseHeader().

◆ m_comments

std::string CubeFile::m_comments
protected

Referenced by getCopyright(), and parseHeader().

◆ m_f

FILE* CubeFile::m_f =nullptr
protected

◆ m_fMaxInput

icFloatNumber CubeFile::m_fMaxInput[3] = { 1.0f, 1.0f, 1.0f }
protected
324{ 1.0f, 1.0f, 1.0f };

Referenced by getMaxInput(), isCustomInputRange(), and parseHeader().

◆ m_fMinInput

icFloatNumber CubeFile::m_fMinInput[3] = { 0.0f, 0.0f, 0.0f }
protected
323{ 0.0f, 0.0f, 0.0f };

Referenced by getMinInput(), isCustomInputRange(), and parseHeader().

◆ m_sFilename

std::string CubeFile::m_sFilename
protected

Referenced by CubeFile(), and open().

◆ m_sizeLut3D

int CubeFile::m_sizeLut3D = 0
protected

◆ m_title

std::string CubeFile::m_title
protected

Referenced by getDescription(), and parseHeader().


The documentation for this class was generated from the following file: