Bug Summary

File:IccXML/IccLibXML/IccUtilXml.cpp
Warning:line 144, column 12
Value stored to 'nAlloc' during its initialization is never read

Annotated Source Code

Press '?' to see keyboard shortcuts

clang -cc1 -cc1 -triple x86_64-apple-macosx14.0.0 -Wundef-prefix=TARGET_OS_ -Werror=undef-prefix -Wdeprecated-objc-isa-usage -Werror=deprecated-objc-isa-usage -analyze -disable-free -clear-ast-before-backend -disable-llvm-verifier -discard-value-names -main-file-name IccUtilXml.cpp -analyzer-checker=core -analyzer-checker=apiModeling -analyzer-checker=unix -analyzer-checker=osx -analyzer-checker=security.insecureAPI.decodeValueOfObjCType -analyzer-checker=deadcode -analyzer-checker=cplusplus -analyzer-checker=security.insecureAPI.UncheckedReturn -analyzer-checker=security.insecureAPI.getpw -analyzer-checker=security.insecureAPI.gets -analyzer-checker=security.insecureAPI.mktemp -analyzer-checker=security.insecureAPI.mkstemp -analyzer-checker=security.insecureAPI.vfork -analyzer-checker=nullability.NullPassedToNonnull -analyzer-checker=nullability.NullReturnedFromNonnull -analyzer-output plist -w -setup-static-analyzer -mrelocation-model pic -pic-level 2 -mframe-pointer=all -ffp-contract=on -fno-rounding-math -funwind-tables=2 -target-sdk-version=14.0 -fcompatibility-qualified-id-block-type-checking -fvisibility-inlines-hidden-static-local-var -target-cpu penryn -tune-cpu generic -debugger-tuning=lldb -target-linker-version 1015.7 -fprofile-instrument=clang -fcoverage-mapping -fcoverage-compilation-dir=/Users/xss/DemoIccMAX-hoyt-master/build/IccXML -resource-dir /usr/local/Cellar/llvm/17.0.3/lib/clang/17 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.0.sdk -D IccXML2_EXPORTS -I /Users/xss/DemoIccMAX-hoyt-master/build/Cmake/../../IccProfLib -I /Library/Developer/CommandLineTools/SDKs/MacOSX12.sdk/usr/include/libxml2 -I /Developer/Headers/FlatCarbon -F/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.0.sdk/System/Library/Frameworks -internal-isystem /usr/local/Cellar/llvm/17.0.3/bin/../include/c++/v1 -internal-isystem /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.0.sdk/usr/local/include -internal-isystem /usr/local/Cellar/llvm/17.0.3/lib/clang/17/include -internal-externc-isystem /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.0.sdk/usr/include -std=gnu++17 -fdeprecated-macro -fdebug-compilation-dir=/Users/xss/DemoIccMAX-hoyt-master/build/IccXML -ferror-limit 19 -fsanitize=address -fsanitize-system-ignorelist=/usr/local/Cellar/llvm/17.0.3/lib/clang/17/share/asan_ignorelist.txt -fno-sanitize-memory-param-retval -fsanitize-address-use-after-scope -fsanitize-address-globals-dead-stripping -fno-assume-sane-operator-new -stack-protector 1 -fblocks -fencode-extended-block-signature -fregister-global-dtors-with-atexit -fgnuc-version=4.2.1 -fcxx-exceptions -fexceptions -fmax-type-align=16 -analyzer-output=html -D__GCC_HAVE_DWARF2_CFI_ASM=1 -o /var/folders/l9/sd9kj1px4yq2wc5_lkwhlt6w0000gn/T/scan-build-2023-10-28-102616-57860-1 -x c++ /Users/xss/DemoIccMAX-hoyt-master/IccXML/IccLibXML/IccUtilXml.cpp
1/** @file
2 File: IccUtilXml.cpp
3
4 Contains: Implementation of XML conversion utilities
5
6 Version: V1
7
8 Copyright: (c) see ICC Software License
9*/
10
11/*
12 * The ICC Software License, Version 0.2
13 *
14 *
15 * Copyright (c) 2003-2012 The International Color Consortium. All rights
16 * reserved.
17 *
18 * Redistribution and use in source and binary forms, with or without
19 * modification, are permitted provided that the following conditions
20 * are met:
21 *
22 * 1. Redistributions of source code must retain the above copyright
23 * notice, this list of conditions and the following disclaimer.
24 *
25 * 2. Redistributions in binary form must reproduce the above copyright
26 * notice, this list of conditions and the following disclaimer in
27 * the documentation and/or other materials provided with the
28 * distribution.
29 *
30 * 3. In the absence of prior written permission, the names "ICC" and "The
31 * International Color Consortium" must not be used to imply that the
32 * ICC organization endorses or promotes products derived from this
33 * software.
34 *
35 *
36 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
37 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
38 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
39 * DISCLAIMED. IN NO EVENT SHALL THE INTERNATIONAL COLOR CONSORTIUM OR
40 * ITS CONTRIBUTING MEMBERS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
41 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
42 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
43 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
44 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
45 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
46 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
47 * SUCH DAMAGE.
48 * ====================================================================
49 *
50 * This software consists of voluntary contributions made by many
51 * individuals on behalf of the The International Color Consortium.
52 *
53 *
54 * Membership in the ICC is encouraged when this software is used for
55 * commercial purposes.
56 *
57 *
58 * For more information on The International Color Consortium, please
59 * see <http://www.color.org/>.
60 *
61 *
62 */
63
64#include <time.h>
65#include "IccUtilXml.h"
66#include "IccConvertUTF.h"
67#include "IccTagFactory.h"
68#include <iostream>
69
70#ifdef WIN32
71#include <windows.h>
72#ifdef GetClassName
73#undef GetClassName
74#endif
75#endif
76#include <cstring> /* C strings strcpy, memcpy ... */
77#include <math.h> /* nanf */
78
79
80
81CIccUTF16String::CIccUTF16String()
82{
83 m_alloc=64;
84 m_len = 0;
85 m_str = (icUInt16Number*)calloc(m_alloc, sizeof(icUInt16Number));
86}
87
88CIccUTF16String::CIccUTF16String(const icUInt16Number *uzStr)
89{
90 m_len = WStrlen(uzStr);
91 m_alloc = AllocSize(m_len);
92
93 m_str = (icUInt16Number *)malloc(m_alloc*sizeof(icUInt16Number));
94 memcpy(m_str, uzStr, m_len+1*sizeof(icUInt16Number));
95}
96
97CIccUTF16String::CIccUTF16String(const char *szStr)
98{
99 size_t sizeSrc = strlen(szStr);
100
101 if (sizeSrc) {
102 m_alloc = AllocSize(sizeSrc*2);
103 m_str = (UTF16 *)calloc(m_alloc, sizeof(icUInt16Number)); //overallocate to allow for up to 4 bytes per character
104 UTF16 *szDest = m_str;
105 icConvertUTF8toUTF16((const UTF8 **)&szStr, (const UTF8 *)&szStr[sizeSrc], &szDest, &szDest[m_alloc], lenientConversion);
106 if (m_str[0]==0xfeff) {
107 size_t i;
108 for (i=1; m_str[i]; i++)
109 m_str[i-1] = m_str[i];
110 m_str[i-1] = 0;
111 }
112 m_len = WStrlen(m_str);
113 }
114 else {
115 m_alloc = 64;
116 m_len = 0;
117 m_str = (icUInt16Number*)calloc(m_alloc, sizeof(icUInt16Number));
118 }
119}
120
121CIccUTF16String::CIccUTF16String(const CIccUTF16String &str)
122{
123 m_alloc = str.m_alloc;
124 m_len = str.m_len;
125 m_str = (icUInt16Number*)malloc(m_alloc*sizeof(icUInt16Number));
126
127 memcpy(m_str, str.m_str, (m_alloc)*sizeof(icUInt16Number));
128}
129
130CIccUTF16String::~CIccUTF16String()
131{
132 free(m_str);
133}
134
135void CIccUTF16String::Clear()
136{
137 m_len = 0;
138 m_str[0] = 0;
139}
140
141bool CIccUTF16String::Resize(size_t len)
142{
143 if (len>m_alloc) {
144 size_t nAlloc = AllocSize(len);
Value stored to 'nAlloc' during its initialization is never read
145
146 m_str = (icUInt16Number*)icRealloc(m_str, m_alloc*sizeof(icUInt16Number));
147
148 if (!m_str) {
149 m_len = 0;
150 return false;
151 }
152 }
153
154 if (len>m_len) {
155 memset(&m_str[m_len], 0x0020, (len-m_len)*sizeof(icUInt16Number));
156 }
157 m_len = len;
158 m_str[m_len] = 0;
159 return true;
160}
161
162size_t CIccUTF16String::WStrlen(const icUInt16Number *uzStr)
163{
164 size_t n=0;
165 while(uzStr[n]) n++;
166
167 return n;
168}
169
170CIccUTF16String& CIccUTF16String::operator=(const CIccUTF16String &wstr)
171{
172 if (m_alloc<=wstr.m_alloc) {
173 m_str = (icUInt16Number*)icRealloc(m_str, m_alloc*sizeof(icUInt16Number));
174 if (m_str)
175 m_alloc = wstr.m_alloc;
176 else
177 m_alloc = 0;
178 }
179 if (m_str) {
180 m_len = wstr.m_len;
181
182 memcpy(m_str, wstr.m_str, (m_len+1)*sizeof(icUInt16Number));
183 }
184 else {
185 m_len = 0;
186 }
187
188 return *this;
189}
190
191CIccUTF16String& CIccUTF16String::operator=(const char *szStr)
192{
193 FromUtf8(szStr, 0);
194
195 return *this;
196}
197
198CIccUTF16String& CIccUTF16String::operator=(const icUInt16Number *uzStr)
199{
200 size_t n = WStrlen(uzStr);
201 size_t nAlloc = AllocSize(n);
202
203 if (m_alloc<=nAlloc) {
204 m_str = (icUInt16Number*)icRealloc(m_str, m_alloc*sizeof(icUInt16Number));
205 if (m_str)
206 m_alloc = nAlloc;
207 else
208 m_alloc = 0;
209 }
210 if (m_str) {
211 m_len = n;
212
213 memcpy(m_str, uzStr, (m_len+1)*sizeof(icUInt16Number));
214 }
215 else {
216 m_len = 0;
217 }
218
219 return *this;
220}
221
222
223bool CIccUTF16String::FromUtf8(const char *szStr, size_t sizeSrc)
224{
225 if (!sizeSrc)
226 sizeSrc = strlen(szStr);
227
228 if (sizeSrc) {
229 size_t nAlloc = AllocSize(sizeSrc*2);
230 if (m_alloc<=nAlloc) {
231 m_str = (icUInt16Number*)icRealloc(m_str, m_alloc*sizeof(icUInt16Number));
232 m_alloc = nAlloc;
233 }
234 if (m_str) {
235 UTF16 *szDest = m_str;
236 icConvertUTF8toUTF16((const UTF8 **)&szStr, (const UTF8 *)&szStr[sizeSrc], &szDest, &szDest[m_alloc], lenientConversion);
237 if (m_str[0]==0xfeff) {
238 size_t i;
239 for (i=1; m_str[i]; i++)
240 m_str[i-1] = m_str[i];
241 m_str[i-1] = 0;
242 }
243 m_len = WStrlen(m_str);
244 }
245 else {
246 m_len =0;
247 return false;
248 }
249 }
250 else {
251 m_len = 0;
252 m_str[0] = 0;
253 }
254 return true;
255}
256
257const char *CIccUTF16String::ToUtf8(std::string &buf)
258{
259 return icUtf16ToUtf8(buf, m_str, (int)m_len);
260}
261
262const wchar_t *CIccUTF16String::ToWString(std::wstring &buf)
263{
264 size_t i;
265
266 buf.clear();
267
268 for (i=0; i<m_len; i++) {
269 buf += (wchar_t)m_str[i];
270 }
271
272 return buf.c_str();
273}
274
275const char *icFixXml(std::string &buf, const char *szStr)
276{
277 buf = "";
278 while (*szStr) {
279 switch (*szStr) {
280 case '\'':
281 buf += "&apos;";
282 break;
283 case '&':
284 buf += "&amp;";
285 break;
286 case '\"':
287 buf += "&quot;";
288 break;
289 case '<':
290 buf += "&lt;";
291 break;
292 case '>':
293 buf += "&gt;";
294 break;
295 default:
296 buf += *szStr;
297 }
298 szStr++;
299 }
300
301 return buf.c_str();
302}
303
304const char *icFixXml(char *szDest, const char *szStr)
305{
306 char *m_ptr = szDest;
307
308 while (*szStr) {
309 switch (*szStr) {
310 case '\'':
311 strcpy(m_ptr, "&apos;");
312 m_ptr += 6;
313 break;
314 case '&':
315 strcpy(m_ptr, "&amp;");
316 m_ptr += 5;
317 break;
318 case '\"':
319 strcpy(m_ptr, "&quot;");
320 m_ptr += 6;
321 break;
322 case '<':
323 strcpy(m_ptr, "&lt;");
324 m_ptr += 4;
325 break;
326 case '>':
327 strcpy(m_ptr, "&gt;");
328 m_ptr += 4;
329 break;
330 default:
331 *m_ptr++ = *szStr;
332 }
333 szStr++;
334 }
335 *m_ptr = '\0';
336
337 return szDest;
338}
339
340const char *icUtf16ToUtf8(std::string &buf, const icUInt16Number *szSrc, int sizeSrc/*=0*/)
341{
342 if (!sizeSrc) {
343 sizeSrc = (int)CIccUTF16String::WStrlen(szSrc);
344 }
345
346 int n = sizeSrc*4;
347
348 if (n) {
349 char *szBuf = (char *)malloc(n+1);
350 char *szDest = szBuf;
351 icConvertUTF16toUTF8(&szSrc, &szSrc[sizeSrc], (UTF8**)&szDest, (UTF8*)&szDest[n+1], lenientConversion);
352 *szDest= '\0';
353
354 buf = szBuf;
355 free(szBuf);
356 }
357 else {
358 buf.clear();
359 }
360
361 return buf.c_str();
362}
363
364const unsigned short *icUtf8ToUtf16(CIccUTF16String &buf, const char *szSrc, int sizeSrc/*=0*/)
365{
366 buf.FromUtf8(szSrc, sizeSrc);
367
368 return buf.c_str();
369}
370
371const char *icAnsiToUtf8(std::string &buf, const char *szSrc)
372{
373#ifdef WIN32
374 size_t len = strlen(szSrc)+1;
375 wchar_t *szUnicodeBuf = (wchar_t*)malloc(len*sizeof(icUInt16Number)*2);
376 char *szBuf = (char*)malloc(len*2);
377
378 size_t n;
379
380 n=MultiByteToWideChar(CP_ACP, 0, szSrc, (int)len-1, szUnicodeBuf, (int)len*2);
381 szUnicodeBuf[n] = '\0';
382
383 n = WideCharToMultiByte(CP_UTF8, 0, (const wchar_t*)szUnicodeBuf, (int)n, szBuf, (int)len*2, 0, NULL__null);
384 szBuf[n] = '\0';
385
386 buf = szBuf;
387
388 free(szBuf);
389 free(szUnicodeBuf);
390#else
391 buf = szSrc;
392#endif
393 return buf.c_str();
394}
395
396const char *icUtf8ToAnsi(std::string &buf, const char *szSrc)
397{
398#ifdef WIN32
399 size_t len = strlen(szSrc)+1;
400 wchar_t *szUnicodeBuf = (wchar_t*)malloc(len*sizeof(icUInt16Number)*2);
401 char *szBuf = (char*)malloc(len*2);
402
403 size_t n;
404
405 n=MultiByteToWideChar(CP_UTF8, 0, szSrc, (int)len, szUnicodeBuf, (int)len*2);
406 szUnicodeBuf[n] = '\0';
407
408 n = WideCharToMultiByte(CP_ACP, 0, (const wchar_t*)szUnicodeBuf, (int)n, szBuf, (int)len*2, "?", NULL__null);
409 szBuf[n] = '\0';
410
411 buf = szBuf;
412
413 free(szBuf);
414 free(szUnicodeBuf);
415#else
416 buf = szSrc;
417#endif
418 return buf.c_str();
419}
420
421class CIccDumpXmlCLUT : public IIccCLUTExec
422{
423public:
424 CIccDumpXmlCLUT(std::string *xml, icConvertType nType, std::string blanks, icUInt16Number nSamples, icUInt8Number nPixelsPerRow)
425 {
426 m_xml = xml;
427 m_nType = nType;
428 m_blanks = blanks;
429 m_nSamples = nSamples;
430 m_nPixelsPerRow = nPixelsPerRow;
431 m_nCurPixel = 0;
432 }
433
434 virtual void PixelOp(icFloatNumber* pGridAdr, icFloatNumber* pData)
435 {
436 if (!pData) {
437 std::cerr << "Error: pData is nullptr." << std::endl;
438 return; // Early return if pData is null
439 }
440
441 int i;
442 char buf[128];
443
444 if (!(m_nCurPixel % m_nPixelsPerRow))
445 *m_xml += m_blanks;
446
447 switch(m_nType) {
448 case icConvert8Bit:
449 for (i=0; i<m_nSamples; i++) {
450 if (&pData[i] == nullptr) { // Check if accessing pData[i] is valid
451 std::cerr << "Error: pData[i] is out of bounds." << std::endl;
452 return;
453 }
454 sprintf(buf, " %3d", (icUInt8Number)(pData[i]*255.0 + 0.5));
455 *m_xml += buf;
456 }
457 break;
458 case icConvert16Bit:
459 for (i=0; i<m_nSamples; i++) {
460 sprintf(buf, " %5d", (icUInt16Number)(pData[i]*65535.0 + 0.5));
461 *m_xml += buf;
462 }
463 break;
464 case icConvertFloat:
465 default:
466 for (i=0; i<m_nSamples; i++) {
467 sprintf(buf, " %13.8f", pData[i]);
468 *m_xml += buf;
469 }
470 break;
471 }
472 m_nCurPixel++;
473 if (!(m_nCurPixel % m_nPixelsPerRow)) {
474 *m_xml += "\n";
475 }
476 }
477
478 void Finish()
479 {
480 if (m_nCurPixel % m_nPixelsPerRow) {
481 *m_xml += "\n";
482 }
483 }
484
485 std::string *m_xml;
486 icConvertType m_nType;
487 std::string m_blanks;
488 icUInt16Number m_nSamples;
489 icUInt8Number m_nPixelsPerRow;
490 icUInt32Number m_nCurPixel;
491};
492
493bool icCLUTDataToXml(std::string &xml, CIccCLUT *pCLUT, icConvertType nType, std::string blanks,
494 bool bSaveGridPoints/*=false*/)
495{
496 char buf[128];
497 int nStartType = nType;
498 if (nType == icConvertVariable) {
499 nType = pCLUT->GetPrecision()==1 ? icConvert8Bit : icConvert16Bit;
500 }
501
502 if (bSaveGridPoints) {
503 xml += blanks + " <GridPoints>";
504 int i;
505
506 for (i=0; i<pCLUT->GetInputDim(); i++) {
507 if (i)
508 sprintf(buf, " %d", pCLUT->GridPoint(i));
509 else
510 sprintf(buf, "%d", pCLUT->GridPoint(i));
511 xml += buf;
512 }
513 xml += "</GridPoints>\n";
514 }
515
516 int nPixelsPerRow = pCLUT->GridPoint(0);
517
518 // if the CLUT has no GridPoints, profile is invalid
519 if (nPixelsPerRow == 0) {
520 printf("\nError! - CLUT Table not found.\n");
521 return false;
522 }
523
524 CIccDumpXmlCLUT dumper(&xml, nType, blanks + " ", pCLUT->GetOutputChannels(), nPixelsPerRow);
525
526 xml += blanks + " <TableData";
527
528 if (nStartType == icConvertVariable && nType == icConvert8Bit) {
529 sprintf(buf, " Precision=\"1\"");
530 xml += buf;
531 }
532
533 xml += ">\n";
534
535 pCLUT->Iterate(&dumper);
536
537 dumper.Finish();
538
539 xml += blanks + " </TableData>\n";
540
541 return true;
542
543}
544
545bool icCLUTToXml(std::string &xml, CIccCLUT *pCLUT, icConvertType nType, std::string blanks,
546 bool bSaveGridPoints/*=false*/, const char *szExtraAttrs/*=""*/, const char *szName/*="CLUT"*/)
547{
548 char buf[128];
549 xml += blanks + "<" + szName;
550
551 if (!bSaveGridPoints) {
552 sprintf(buf, " GridGranularity=\"%d\"", pCLUT->GridPoint(0));
553 xml += buf;
554 }
555
556 if (szExtraAttrs && *szExtraAttrs) {
557 xml += szExtraAttrs;
558 }
559 xml += ">\n";
560
561 icCLUTDataToXml(xml, pCLUT, nType, blanks, bSaveGridPoints);
562
563 xml += blanks + "</" + szName + ">\n";
564 return true;
565}
566
567icFloatNumber icXmlStrToFloat(const xmlChar *szStr)
568{
569 float f=0.0;
570 sscanf((const char*)szStr, "%f", &f);
571
572 return (icFloatNumber)f;
573}
574
575icSignature icXmlStrToSig(const char *szStr)
576{
577 return icGetSigVal(szStr);
578}
579
580const char *icXmlAttrValue(xmlAttr *attr, const char *szDefault)
581{
582 if (attr && attr->children && attr->children->type == XML_TEXT_NODE && attr->children->content)
583 return (const char*)attr->children->content;
584
585 return szDefault;
586}
587
588const char *icXmlAttrValue(xmlNode *pNode, const char *szName, const char *szDefault)
589{
590 xmlAttr *attr = icXmlFindAttr(pNode, szName);
591 if (attr) {
592 return icXmlAttrValue(attr, szDefault);
593 }
594 return szDefault;
595}
596
597icUInt32Number icXmlGetChildSigVal(xmlNode *pNode)
598{
599 if (!pNode || !pNode->children || !pNode->children->content)
600 return 0;
601
602 return icGetSigVal((const char*)pNode->children->content);
603}
604
605static int hexValue(char c)
606{
607 if (c>='0' && c<='9')
608 return c-'0';
609 if (c>='A' && c<='F')
610 return c-'A'+10;
611 if (c>='a' && c<='f')
612 return c-'a'+10;
613 return -1;
614}
615
616
617icUInt32Number icXmlGetHexData(void *pBuf, const char *szText, icUInt32Number nBufSize)
618{
619 unsigned char *pDest = (unsigned char*)pBuf;
620 icUInt32Number rv =0;
621
622 while(*szText && rv<nBufSize) {
623 int c1=hexValue(szText[0]);
624 int c2=hexValue(szText[1]);
625 if (c1>=0 && c2>=0) {
626 *pDest = c1*16+ c2;
627 pDest++;
628 szText +=2;
629 rv++;
630 }
631 else {
632 szText++;
633 }
634 }
635 return rv;
636}
637
638icUInt32Number icXmlGetHexDataSize(const char *szText)
639{
640 icUInt32Number rv =0;
641
642 while(*szText) {
643 int c1=hexValue(szText[0]);
644 int c2=hexValue(szText[1]);
645 if (c1>=0 && c2>=0) {
646 szText +=2;
647 rv++;
648 }
649 else {
650 szText++;
651 }
652 }
653 return rv;
654}
655
656icUInt32Number icXmlDumpHexData(std::string &xml, std::string blanks, void *pBuf, icUInt32Number nBufSize)
657{
658 icUInt8Number *m_ptr = (icUInt8Number *)pBuf;
659 char buf[15];
660 icUInt32Number i;
661
662 for (i=0; i<nBufSize; i++, m_ptr++) {
663 if (!(i%32)) {
664 if (i)
665 xml += "\n";
666 xml += blanks;
667 }
668 sprintf(buf, "%02x", *m_ptr);
669 xml += buf;
670 }
671 if (i) {
672 xml += "\n";
673 }
674 return i;
675}
676
677xmlAttr *icXmlFindAttr(xmlNode *pNode, const char *szAttrName)
678{
679 if (!pNode) return NULL__null;
680
681 xmlAttr *attr;
682
683 for (attr = pNode->properties; attr; attr = attr->next) {
684 if (attr->type != XML_ATTRIBUTE_NODE)
685 continue;
686
687 if (!icXmlStrCmp(attr->name, szAttrName)strcmp((const char *)(attr->name), (const char*)(szAttrName
))
) {
688 return attr;
689 }
690 }
691
692 return NULL__null;
693}
694
695xmlNode *icXmlFindNode(xmlNode *pNode, const char *szNodeName)
696{
697 if (!pNode) return NULL__null;
698
699 for (; pNode; pNode = pNode->next) {
700 if (pNode->type != XML_ELEMENT_NODE)
701 continue;
702
703 if (!icXmlStrCmp(pNode->name, szNodeName)strcmp((const char *)(pNode->name), (const char*)(szNodeName
))
) {
704 return pNode;
705 }
706 }
707
708 return NULL__null;
709}
710
711icUInt32Number icXmlNodeCount(xmlNode *pNode, const char *szNodeName)
712{
713 icUInt32Number rv = 0;
714 for (; pNode; pNode = pNode->next) {
715 if (pNode->type == XML_ELEMENT_NODE &&
716 !icXmlStrCmp(pNode->name, szNodeName)strcmp((const char *)(pNode->name), (const char*)(szNodeName
))
) {
717 rv++;
718 }
719 }
720 return rv;
721}
722
723icUInt32Number icXmlNodeCount2(xmlNode *pNode, const char *szNodeName1, const char *szNodeName2)
724{
725 icUInt32Number rv = 0;
726 for (; pNode; pNode = pNode->next) {
727 if (pNode->type == XML_ELEMENT_NODE &&
728 (!icXmlStrCmp(pNode->name, szNodeName1)strcmp((const char *)(pNode->name), (const char*)(szNodeName1
))
|| !icXmlStrCmp(pNode->name, szNodeName2)strcmp((const char *)(pNode->name), (const char*)(szNodeName2
))
)) {
729 rv++;
730 }
731 }
732 return rv;
733}
734
735icUInt32Number icXmlNodeCount3(xmlNode *pNode, const char *szNodeName1, const char *szNodeName2, const char *szNodeName3)
736{
737 icUInt32Number rv = 0;
738 for (; pNode; pNode = pNode->next) {
739 if (pNode->type == XML_ELEMENT_NODE &&
740 (!icXmlStrCmp(pNode->name, szNodeName1)strcmp((const char *)(pNode->name), (const char*)(szNodeName1
))
|| !icXmlStrCmp(pNode->name, szNodeName2)strcmp((const char *)(pNode->name), (const char*)(szNodeName2
))
|| !icXmlStrCmp(pNode->name, szNodeName3)strcmp((const char *)(pNode->name), (const char*)(szNodeName3
))
)) {
741 rv++;
742 }
743 }
744 return rv;
745}
746
747template <class T, icTagTypeSignature Tsig>
748CIccXmlArrayType<T, Tsig>::CIccXmlArrayType()
749{
750 m_pBuf = NULL__null;
751 m_nSize = 0;
752}
753
754template <class T, icTagTypeSignature Tsig>
755CIccXmlArrayType<T, Tsig>::~CIccXmlArrayType()
756{
757 if (m_pBuf) {
758 free(m_pBuf);
759 }
760}
761
762template <class T, icTagTypeSignature Tsig>
763bool CIccXmlArrayType<T, Tsig>::ParseArray(xmlNode *pNode)
764{
765 char scanType[2];
766 scanType[0] = (Tsig == icSigFloatArrayType((icTagTypeSignature)0x66637420) ? 'f' : 'n');
767 scanType[1] = 0;
768
769 icUInt32Number n = icXmlNodeCount(pNode, scanType);
770
771 if (n) {
772 if (!SetSize(n))
773 return false;
774 return ParseArray(m_pBuf, m_nSize, pNode);
775 }
776
777 for ( ;pNode && pNode->type!= XML_TEXT_NODE; pNode=pNode->next);
778
779 if (!pNode || !pNode->content)
780 return false;
781
782 n = ParseTextCount((const char*)pNode->content);
783
784 if (!n || !SetSize(n))
785 return false;
786
787 return ParseArray(m_pBuf, m_nSize, pNode);
788}
789
790template <class T, icTagTypeSignature Tsig>
791bool CIccXmlArrayType<T, Tsig>::ParseTextArray(const char *szText)
792{
793 icUInt32Number n = ParseTextCount(szText);
794
795 if (n) {
796 if (!SetSize(n))
797 return false;
798
799 return ParseText(m_pBuf, m_nSize, szText)==m_nSize;
800 }
801
802 return false;
803}
804
805template <class T, icTagTypeSignature Tsig>
806bool CIccXmlArrayType<T, Tsig>::ParseTextArray(xmlNode *pNode)
807{
808 if (pNode->children && pNode->children->type==XML_TEXT_NODE) {
809 return ParseTextArray((const char*)pNode->children->content);
810 }
811 return false;
812}
813
814template <class T, icTagTypeSignature Tsig>
815bool CIccXmlArrayType<T, Tsig>::ParseTextArrayNum(const char *szText, icUInt32Number num, std::string &parseStr)
816{
817 icUInt32Number n = ParseTextCountNum(szText, num, parseStr);
818 if (n) {
819 if (!SetSize(n))
820 return false;
821 return ParseText(m_pBuf, m_nSize, szText)==m_nSize;
822 }
823
824 return false;
825}
826
827template <class T, icTagTypeSignature Tsig>
828bool CIccXmlArrayType<T, Tsig>::DumpArray(std::string &xml, std::string blanks, T *buf, icUInt32Number nBufSize,
829 icConvertType nType, icUInt8Number nColumns)
830{
831 char str[200];
832
833 if (!nColumns) nColumns = 1;
834 icUInt32Number i;
835
836 for (i=0; i<nBufSize; i++) {
837 if (!(i%nColumns)) {
838 xml += blanks;
839 }
840 else {
841 xml += " ";
842 }
843
844 switch (Tsig) {
845 case icSigUInt8ArrayType:
846 switch (nType) {
847 case icConvert8Bit:
848 default:
849 sprintf(str, "%u", (icUInt8Number)buf[i]);
850 break;
851
852 case icConvert16Bit:
853 sprintf(str, "%u", (icUInt16Number)((icFloatNumber)buf[i] * 65535.0 / 255.0 + 0.5));
854 break;
855
856 case icConvertFloat:
857 sprintf(str, "%.8f", (icFloatNumber)buf[i] / 255.0);
858 break;
859 }
860 break;
861
862 case icSigUInt16ArrayType:
863 switch (nType) {
864 case icConvert8Bit:
865 sprintf(str, "%u", (icUInt16Number)((icFloatNumber)buf[i] * 255.0 / 65535.0 + 0.5));
866 break;
867
868 case icConvert16Bit:
869 default:
870 sprintf(str, "%u", (icUInt16Number)buf[i]);
871 break;
872
873 case icConvertFloat:
874 sprintf(str, "%.8f", (icFloatNumber)buf[i] / 65535.0);
875 break;
876 }
877 break;
878
879 case icSigUInt32ArrayType:
880 sprintf(str, "%u", (icUInt32Number)buf[i]);
881 break;
882
883 case icSigUInt64ArrayType:
884 // unused
885 break;
886
887 case icSigFloatArrayType((icTagTypeSignature)0x66637420):
888 case icSigFloat32ArrayType:
889 case icSigFloat64ArrayType:
890 switch (nType) {
891 case icConvert8Bit:
892 sprintf(str, "%u", (icUInt8Number)(buf[i] * 255.0 + 0.5));
893 break;
894
895 case icConvert16Bit:
896 sprintf(str, "%u", (icUInt16Number)(buf[i] * 65535.0 + 0.5));
897 break;
898
899 case icConvertFloat:
900 default:
901 sprintf(str, "%.8f", (icFloatNumber)buf[i]);
902 }
903 break;
904 }
905 xml += str;
906 if (i%nColumns == nColumns-1) {
907 xml += "\n";
908 }
909 }
910
911 if (i%nColumns) {
912 xml += "\n";
913 }
914
915 return true;
916}
917
918// for multi-platform support
919// replaced "_inline" with "inline"
920static inline bool icIsNumChar(char c)
921{
922 if ((c>='0' && c<='9') || c=='.' || c=='+' || c=='-' || c=='e' || c == 'n' || c == 'a')
923 return true;
924 return false;
925}
926
927// function used when checking contents of a file
928// count the number of entries.
929template <class T, icTagTypeSignature Tsig>
930icUInt32Number CIccXmlArrayType<T, Tsig>::ParseTextCountNum(const char *szText, icUInt32Number num, std::string &parseStr)
931{
932 icUInt32Number n = 0;
933 bool bInNum = false;
934 //icUInt32Number count = 1;
935
936 //while (*szText) {
937 for (icUInt32Number i=0; i<num; i++) {
938 if (icIsNumChar(*szText)) {
939 if (!bInNum) {
940 bInNum = true;
941 }
942 }
943 else if (bInNum && !strncmp(szText, "#QNAN", 5)) { //Handle 1.#QNAN000 (non a number)
944 i+=4;
945 szText+=4;
946 }
947 // an invalid character is encountered (not digit and not space)
948 else if (!isspace(*szText) && i <= num ){
949 char line[100];
950 sprintf(line, "Data '%c' in position %d is not a number. ", *szText, i);
951 parseStr += line;
952 return false;
953 }
954 else if (bInNum) { //char is a space
955 n++;
956 bInNum = false;
957 }
958 szText++;
959 //count++;
960 }
961 if (bInNum) {
962 n++;
963 }
964
965 return n;
966}
967
968template <class T, icTagTypeSignature Tsig>
969icUInt32Number CIccXmlArrayType<T, Tsig>::ParseTextCount(const char *szText)
970{
971 icUInt32Number n = 0;
972 bool bInNum = false;
973
974 while (*szText) {
975 if (icIsNumChar(*szText)) {
976 if (!bInNum) {
977 bInNum = true;
978 }
979 }
980 else if (bInNum && !strncmp(szText, "#QNAN", 5)) { //Handle 1.#QNAN000 (non a number)
981 szText+=4;
982 }
983 else if (bInNum) {
984 n++;
985 bInNum = false;
986 }
987 szText++;
988 }
989 if (bInNum) {
990 n++;
991 }
992
993 return n;
994}
995
996template <class T, icTagTypeSignature Tsig>
997icUInt32Number CIccXmlArrayType<T, Tsig>::ParseText(T* pBuf, icUInt32Number nSize, const char *szText)
998{
999 icUInt32Number n = 0, b = 0;
1000 bool bInNum = false;
1001 char num[256];
1002
1003 while (*szText && n<nSize) {
1004 if (icIsNumChar(*szText)) {
1005 if (!bInNum) {
1006 bInNum = true;
1007 b=0;
1008 }
1009 num[b] = *szText;
1010
1011 if (b+2<sizeof(num))
1012 b++;
1013 }
1014 else if (bInNum) {
1015 num[b] = 0;
1016 if (!strncmp(num, "nan", 3) || !strncmp(num, "-nan", 4)) {
1017 pBuf[n] = (T)nanf(num);
1018 }
1019 else {
1020 pBuf[n] = (T)atof(num);
1021 }
1022 n++;
1023 bInNum = false;
1024 }
1025 szText++;
1026 }
1027 if (bInNum) {
1028 num[b] = 0;
1029 if (!strncmp(num, "nan", 3) || !strncmp(num, "-nan", 4)) {
1030 pBuf[n] = (T)nanf(num);
1031 }
1032 else {
1033 pBuf[n] = (T)atof(num);
1034 }
1035 n++;
1036 }
1037
1038 return n;
1039}
1040
1041template <class T, icTagTypeSignature Tsig>
1042bool CIccXmlArrayType<T, Tsig>::ParseArray(T* pBuf, icUInt32Number nSize, xmlNode *pNode)
1043{
1044 icUInt32Number n;
1045 if (Tsig==icSigFloatArrayType((icTagTypeSignature)0x66637420)) {
1046 n = icXmlNodeCount(pNode, "f");
1047
1048 if (!n) {
1049 if (pNode->type!=XML_TEXT_NODE || !pNode->content)
1050 return false;
1051
1052 n = ParseTextCount((const char*)pNode->content);
1053 if (!n || n>nSize)
1054 return false;
1055
1056 ParseText(pBuf, n, (const char*)pNode->content);
1057 }
1058 else {
1059 if (n>nSize)
1060 return false;
1061
1062 icUInt32Number i;
1063 for (i=0; i<nSize && pNode; pNode = pNode->next) {
1064 if (pNode->type == XML_ELEMENT_NODE &&
1065 !icXmlStrCmp(pNode->name, "f")strcmp((const char *)(pNode->name), (const char*)("f")) &&
1066 pNode->children &&
1067 pNode->children->content) {
1068 float f;
1069 sscanf((const char *)(pNode->children->content), "%f", &f);
1070 pBuf[i] = (T)f;
1071 i++;
1072 }
1073 }
1074 }
1075 }
1076 else {
1077 n = icXmlNodeCount(pNode, "n");
1078
1079 if (!n) {
1080 if (pNode->type!=XML_TEXT_NODE || !pNode->content)
1081 return false;
1082
1083 n = ParseTextCount((const char *)pNode->content);
1084 if (!n || n>nSize)
1085 return false;
1086
1087 n = ParseText(pBuf, n, (const char *)pNode->content);
1088 }
1089 else {
1090 if (n>nSize)
1091 return false;
1092
1093 icUInt32Number i;
1094 for (i=0; i<nSize && pNode; pNode = pNode->next) {
1095 if (pNode->type == XML_ELEMENT_NODE &&
1096 !icXmlStrCmp(pNode->name, "n")strcmp((const char *)(pNode->name), (const char*)("n")) &&
1097 pNode->children &&
1098 pNode->children->content) {
1099 pBuf[i] = (T)atol((const char *)(pNode->children->content));
1100 i++;
1101 }
1102 }
1103 }
1104 }
1105 return nSize==n;
1106}
1107
1108
1109template <class T, icTagTypeSignature Tsig>
1110bool CIccXmlArrayType<T, Tsig>::SetSize(icUInt32Number nSize)
1111{
1112 if (m_pBuf) {
1113 free(m_pBuf);
1114 }
1115 m_pBuf = (T*)malloc(nSize * sizeof(T));
1116 if (!m_pBuf) {
1117 m_nSize = 0;
1118 return false;
1119 }
1120 m_nSize = nSize;
1121
1122 return true;
1123}
1124
1125//Make sure typedef classes get built
1126template class CIccXmlArrayType<icUInt8Number, icSigUInt8ArrayType>;
1127template class CIccXmlArrayType<icUInt16Number, icSigUInt16ArrayType>;
1128template class CIccXmlArrayType<icUInt32Number, icSigUInt32ArrayType>;
1129template class CIccXmlArrayType<icUInt64Number, icSigUInt64ArrayType>;
1130template class CIccXmlArrayType<icFloatNumber, icSigFloatArrayType((icTagTypeSignature)0x66637420)>;
1131template class CIccXmlArrayType<icFloat32Number, icSigFloat32ArrayType>;
1132template class CIccXmlArrayType<icFloat64Number, icSigFloat64ArrayType>;
1133
1134
1135const icRenderingIntent icGetRenderingIntentValue (icChar *szRenderingIntent)
1136{
1137 if (!strcmp(szRenderingIntent, "Perceptual"))
1138 return icPerceptual;
1139 else if (!strcmp(szRenderingIntent, "Media-relative colorimetric"))
1140 return icRelativeColorimetric;
1141 else if (!strcmp(szRenderingIntent, "Saturation"))
1142 return icSaturation;
1143 else if (!strcmp(szRenderingIntent, "ICC-absolute colorimetric"))
1144 return icAbsoluteColorimetric;
1145
1146 return icPerceptual;
1147}
1148
1149const icChar* icGetTagSigTypeName(icTagTypeSignature tagTypeSig)
1150{
1151 const icChar *rv = CIccTagCreator::GetTagTypeSigName(tagTypeSig);
1152
1153 // if the tag signature is not found, it is a custom type.
1154 if (!rv)
1155 return "PrivateType";
1156
1157 return rv;
1158}
1159
1160icTagTypeSignature icGetTypeNameTagSig(const icChar* szTagType)
1161{
1162 return CIccTagCreator::GetTagTypeNameSig(szTagType);
1163
1164}
1165
1166const icChar* icGetTagSigName(icTagSignature tagTypeSig)
1167{
1168 const icChar *rv = CIccTagCreator::GetTagSigName(tagTypeSig);
1169
1170 // if the tag signature is not found, it is a custom type.
1171 if (!rv)
1172 return "PrivateTag";
1173
1174 return rv;
1175}
1176
1177icTagSignature icGetTagNameSig(const icChar *szName)
1178{
1179 return CIccTagCreator::GetTagNameSig(szName);
1180}
1181
1182
1183icStandardObserver icGetNamedStandardObserverValue(const icChar* str)
1184{
1185 if (!strcmp(str, "Unknown observer"))
1186 return icStdObsUnknown;
1187
1188 if (!strcmp(str, "CIE 1931 standard colorimetric observer"))
1189 return icStdObs1931TwoDegrees;
1190
1191 if (!strcmp(str, "CIE 1964 standard colorimetric observer"))
1192 return icStdObs1964TenDegrees;
1193
1194 return icStdObsCustomicStdObsUnknown;
1195}
1196
1197
1198icMeasurementGeometry icGeNamedtMeasurementGeometryValue(const icChar* str)
1199{
1200 if (!strcmp(str, "Geometry Unknown"))
1201 return icGeometryUnknown;
1202
1203 if (!strcmp(str, "Geometry 0-45 or 45-0"))
1204 return icGeometry045or450;
1205
1206 if (!strcmp(str, "Geometry 0-d or d-0"))
1207 return icGeometry0dord0;
1208
1209 if (!strcmp(str, "Max Geometry"))
1210 return icMaxEnumGeometry((icMeasurementGeometry) 0xFFFFFFFF);
1211
1212 return icGeometryUnknown;
1213}
1214
1215icMeasurementFlare icGetNamedMeasurementFlareValue(const icChar * str)
1216{
1217 if (!strcmp(str, "Flare 0"))
1218 return icFlare0;
1219
1220 if (!strcmp(str, "Flare 100"))
1221 return icFlare100;
1222
1223 if (!strcmp(str, "Max Flare"))
1224 return icMaxEnumFlare((icMeasurementFlare) 0xFFFFFFFF);
1225
1226 return icFlare0;
1227}
1228
1229icIlluminant icGetIlluminantValue(const icChar* str)
1230{
1231 if (!strcmp(str, "Illuminant Unknown"))
1232 return icIlluminantUnknown;
1233
1234 if (!strcmp(str, "Illuminant D50") || !strcmp(str, "D50"))
1235 return icIlluminantD50;
1236
1237 if (!strcmp(str, "Illuminant D65") || !strcmp(str, "D65"))
1238 return icIlluminantD65;
1239
1240 if (!strcmp(str, "Illuminant D93") || !strcmp(str, "D93"))
1241 return icIlluminantD93;
1242
1243 if (!strcmp(str, "Illuminant F2") || !strcmp(str, "F2"))
1244 return icIlluminantF2;
1245
1246 if (!strcmp(str, "Illuminant D55") || !strcmp(str, "D55"))
1247 return icIlluminantD55;
1248
1249 if (!strcmp(str, "Illuminant A") || !strcmp(str, "A"))
1250 return icIlluminantA;
1251
1252 if (!strcmp(str, "Illuminant EquiPowerE") || !strcmp(str, "Illuminant E") || !strcmp(str, "E"))
1253 return icIlluminantEquiPowerE;
1254
1255 if (!strcmp(str, "Illuminant F8") || !strcmp(str, "F8"))
1256 return icIlluminantF8;
1257
1258 if (!strcmp(str, "Illuminant Black Body") || !strcmp(str, "Black Body"))
1259 return icIlluminantBlackBody;
1260
1261 if (!strcmp(str, "Illuminant Daylight") || !strcmp(str, "Daylight"))
1262 return icIlluminantDaylight;
1263
1264 if (!strcmp(str, "Illuminant B") || !strcmp(str, "B"))
1265 return icIlluminantB;
1266
1267 if (!strcmp(str, "Illuminant C") || !strcmp(str, "C"))
1268 return icIlluminantC;
1269
1270 if (!strcmp(str, "Illuminant F1") || !strcmp(str, "F1"))
1271 return icIlluminantF1;
1272
1273 if (!strcmp(str, "Illuminant F3") || !strcmp(str, "F3"))
1274 return icIlluminantF3;
1275
1276 if (!strcmp(str, "Illuminant F4") || !strcmp(str, "F4"))
1277 return icIlluminantF4;
1278
1279 if (!strcmp(str, "Illuminant F5") || !strcmp(str, "F5"))
1280 return icIlluminantF5;
1281
1282 if (!strcmp(str, "Illuminant F6") || !strcmp(str, "F6"))
1283 return icIlluminantF6;
1284
1285 if (!strcmp(str, "Illuminant F7") || !strcmp(str, "F7"))
1286 return icIlluminantF7;
1287
1288 if (!strcmp(str, "Illuminant F9") || !strcmp(str, "F9"))
1289 return icIlluminantF9;
1290
1291 if (!strcmp(str, "Illuminant F10") || !strcmp(str, "F10"))
1292 return icIlluminantF10;
1293
1294 if (!strcmp(str, "Illuminant F11") || !strcmp(str, "F11"))
1295 return icIlluminantF11;
1296
1297 if (!strcmp(str, "Illuminant F12") || !strcmp(str, "F12"))
1298 return icIlluminantF12;
1299
1300 return icIlluminantCustomicIlluminantUnknown;
1301}
1302
1303const icChar* icGetStandardObserverName(icStandardObserver str)
1304{
1305 switch (str) {
1306 case icStdObsUnknown:
1307 return "Unknown Observer";
1308
1309 case icStdObs1931TwoDegrees:
1310 return "CIE 1931 standard colorimetric observer";
1311
1312 case icStdObs1964TenDegrees:
1313 return "CIE 1964 standard colorimetric observer";
1314
1315 default:
1316 return "Unknown Observer";
1317 }
1318}
1319
1320icDateTimeNumber icGetDateTimeValue(const icChar* str)
1321{
1322 unsigned int day=0, month=0, year=0, hours=0, minutes=0, seconds=0;
1323 icDateTimeNumber dateTime;
1324
1325 if (!stricmpstrcasecmp(str, "now")) {
1326 time_t rawtime;
1327 struct tm * timeinfo;
1328
1329 time ( &rawtime );
1330 timeinfo = localtime ( &rawtime );
1331 year = timeinfo->tm_year+1900;
1332 month = timeinfo->tm_mon+1;
1333 day = timeinfo->tm_mday;
1334 hours = timeinfo->tm_hour;
1335 minutes = timeinfo->tm_min;
1336 seconds = timeinfo->tm_sec;
1337 }
1338 else {
1339 sscanf(str, "%d-%02d-%02dT%02d:%02d:%02d", &year, &month, &day, &hours, &minutes, &seconds);
1340 }
1341
1342 dateTime.year = year;
1343 dateTime.month = month;
1344 dateTime.day = day;
1345 dateTime.hours = hours;
1346 dateTime.minutes = minutes;
1347 dateTime.seconds = seconds;
1348
1349 return dateTime;
1350}
1351
1352icUInt64Number icGetDeviceAttrValue(xmlNode *pNode)
1353{
1354 icUInt64Number devAttr = 0;
1355 xmlAttr *attr = icXmlFindAttr(pNode, "ReflectiveOrTransparency");
1356 if (attr && !strcmp(icXmlAttrValue(attr), "transparency")) {
1357 devAttr |= icTransparency0x00000001;
1358 }
1359
1360 attr = icXmlFindAttr(pNode, "GlossyOrMatte");
1361 if (attr && !strcmp(icXmlAttrValue(attr), "matte")) {
1362 devAttr |= icMatte0x00000002;
1363 }
1364
1365 attr = icXmlFindAttr(pNode, "MediaPolarity");
1366 if (attr && !strcmp(icXmlAttrValue(attr), "negative")) {
1367 devAttr |= icMediaNegative0x00000004;
1368 }
1369
1370 attr = icXmlFindAttr(pNode, "MediaColour");
1371 if (attr && !strcmp(icXmlAttrValue(attr), "blackAndWhite")) {
1372 devAttr |= icMediaBlackAndWhite0x00000008;
1373 }
1374
1375 attr = icXmlFindAttr(pNode, "VendorSpecific");
1376 if (attr) {
1377 icUInt64Number vendor;
1378#if defined(__APPLE__1)
1379 sscanf(icXmlAttrValue(attr), "%llx", &vendor);
1380#else
1381 sscanf(icXmlAttrValue(attr), "%I64x", &vendor);
1382#endif
1383 devAttr |= vendor;
1384 }
1385
1386 return devAttr;
1387}
1388
1389icColorantEncoding icGetColorantValue(const icChar* str)
1390{
1391 if (!strcmp(str, "ITU-R BT.709"))
1392 return icColorantITU;
1393
1394 if (!strcmp(str, "SMPTE RP145-1994"))
1395 return icColorantSMPTE;
1396
1397 if (!strcmp(str, "EBU Tech.3213-E"))
1398 return icColorantEBU;
1399
1400 if (!strcmp(str, "P22"))
1401 return icColorantP22;
1402
1403 return icColorantUnknown;
1404}
1405
1406icMeasurementUnitSig icGetMeasurementValue(const icChar* str)
1407{
1408 if (!strcmp(str, "Status A"))
1409 return icSigStatusA;
1410
1411 if (!strcmp(str, "Status E"))
1412 return icSigStatusE;
1413
1414 if (!strcmp(str, "Status I"))
1415 return icSigStatusI;
1416
1417 if (!strcmp(str, "Status T"))
1418 return icSigStatusT;
1419
1420 if (!strcmp(str, "Status M"))
1421 return icSigStatusM;
1422
1423 if (!strcmp(str, "DIN with no polarizing filter"))
1424 return icSigDN;
1425
1426 if (!strcmp(str, "DIN with polarizing filter"))
1427 return icSigDNP;
1428
1429 if (!strcmp(str, "Narrow band DIN with no polarizing filter"))
1430 return icSigDNN;
1431
1432 if (!strcmp(str, "Narrow band DIN with polarizing filter"))
1433 return icSigDNNP;
1434
1435 return icSigStatusA;
1436}
1437
1438const std::string icGetDeviceAttrName(icUInt64Number devAttr)
1439{
1440 char line[256];
1441 std::string xml;
1442
1443 if (devAttr & icTransparency0x00000001)
1444 sprintf(line, "<DeviceAttributes ReflectiveOrTransparency=\"transparency\"");
1445 else
1446 sprintf(line, "<DeviceAttributes ReflectiveOrTransparency=\"reflective\"");
1447 xml += line;
1448
1449
1450 if (devAttr & icMatte0x00000002)
1451 sprintf(line, " GlossyOrMatte=\"matte\"");
1452 else
1453 sprintf(line, " GlossyOrMatte=\"glossy\"");
1454 xml += line;
1455
1456
1457 if (devAttr & icMediaNegative0x00000004)
1458 sprintf(line, " MediaPolarity=\"negative\"");
1459 else
1460 sprintf(line, " MediaPolarity=\"positive\"");
1461 xml += line;
1462
1463 if (devAttr & icMediaBlackAndWhite0x00000008)
1464 sprintf(line, " MediaColour=\"blackAndwhite\"");
1465 else
1466 sprintf(line, " MediaColour=\"colour\"");
1467 xml += line;
1468
1469 icUInt64Number otherAttr = ~((icUInt64Number)icTransparency0x00000001|icMatte0x00000002|icMediaNegative0x00000004|icMediaBlackAndWhite0x00000008);
1470
1471 if (devAttr & otherAttr) {
1472#if defined(__APPLE__1)
1473 sprintf(line, " VendorSpecific=\"%016llx\"", devAttr & otherAttr);
1474#else
1475 sprintf(line, " VendorSpecific=\"%016I64x\"", devAttr & otherAttr);
1476#endif
1477 xml += line;
1478 }
1479
1480 xml += "/>\n";
1481
1482 return xml;
1483}
1484
1485const std::string icGetHeaderFlagsName(icUInt32Number flags, bool bUsesMCS)
1486{
1487 char line[256];
1488 std::string xml;
1489
1490 if (flags & icEmbeddedProfileTrue0x00000001)
1491 sprintf(line, "<ProfileFlags EmbeddedInFile=\"true\"");
1492 else
1493 sprintf(line, "<ProfileFlags EmbeddedInFile=\"false\"");
1494 xml += line;
1495
1496 if (flags & icUseWithEmbeddedDataOnly0x00000002)
1497 sprintf(line, " UseWithEmbeddedDataOnly=\"true\"");
1498 else
1499 sprintf(line, " UseWithEmbeddedDataOnly=\"false\"");
1500 xml += line;
1501
1502 icUInt32Number otherFlags = ~(icEmbeddedProfileTrue0x00000001|icUseWithEmbeddedDataOnly0x00000002);
1503
1504 if (bUsesMCS) {
1505 if (flags & icMCSNeedsSubsetTrue0x00000004)
1506 sprintf(line, " MCSNeedsSubset=\"true\"");
1507 else
1508 sprintf(line, " MCSNeedsSubset=\"false\"");
1509 xml += line;
1510
1511 otherFlags &= ~icMCSNeedsSubsetTrue0x00000004;
1512 }
1513
1514
1515 if (flags & otherFlags) {
1516 sprintf(line, " VendorFlags=\"%08x\"", flags & otherFlags);
1517 xml += line;
1518 }
1519
1520 xml += "/>\n";
1521
1522 return xml;
1523}
1524
1525const std::string icGetPadSpace(double value)
1526{
1527 std::string space = "";
1528 if ( value >=0 && value < 10)
1529 space = " ";
1530 if ( value >=10 && value < 100)
1531 space = " ";
1532 if ( value >=100 && value < 1000 )
1533 space = " ";
1534
1535 return space;
1536}
1537