Hoyt's FORK of DemoIccMAX 2.1.17.hoyt
Documentation for Hoyt's FORK of DemoIccMAX
Loading...
Searching...
No Matches
IccTagDict.cpp
Go to the documentation of this file.
1/** @file
2 File: IccTagDictTag.cpp
3
4 Contains: Implementation of prototype dictType Tag
5
6 Version: V1
7
8 Copyright: � 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//////////////////////////////////////////////////////////////////////
65// HISTORY:
66//
67// -Initial implementation by Max Derhak Jun-26-2009
68//
69//////////////////////////////////////////////////////////////////////
70
71#ifdef WIN32
72#pragma warning( disable: 4786) //disable warning in <list.h>
73#endif
74
75#include <stdio.h>
76#include <math.h>
77#include <string.h>
78#include <stdlib.h>
79#include <codecvt>
80#include <locale>
81#include "IccTagDict.h"
82#include "IccUtil.h"
83#include "IccIO.h"
84
85
86//MSVC 6.0 doesn't support std::string correctly so we disable support in this case
87#ifndef ICC_UNSUPPORTED_TAG_DICT
88
89using convert_type = std::codecvt_utf8<wchar_t>;
90
91
92/*=============================================================================
93* CLASS CIccDictEntry
94*=============================================================================*/
95
96/**
97******************************************************************************
98* Name: CIccDictEntry::CIccDictEntry
99*
100* Purpose:
101*
102* Args:
103*
104* Return:
105******************************************************************************/
107{
108 m_sName = new std::wstring();
109 m_sValue = new std::wstring();
110 m_pNameLocalized = NULL;
111 m_pValueLocalized = NULL;
112 m_bValueSet = false;
113}
114
115/**
116******************************************************************************
117* Name: CIccDictEntry::CIccDictEntry
118*
119* Purpose:
120*
121* Args:
122*
123* Return:
124******************************************************************************/
126{
127 m_sName = new std::wstring();
128 m_sValue = new std::wstring();
129
130 *m_sName = *IDE.m_sName;
132 *m_sValue = *IDE.m_sValue;
133
134 if (IDE.m_pNameLocalized) {
136 }
137 else
138 m_pNameLocalized = NULL;
139
140 if (IDE.m_pValueLocalized) {
142 }
143 else
144 m_pValueLocalized = NULL;
145}
146
147/**
148******************************************************************************
149* Name: CIccDictEntry::operator=
150*
151* Purpose:
152*
153* Args:
154*
155* Return:
156******************************************************************************/
158{
160 delete m_pNameLocalized;
161
163 delete m_pValueLocalized;
164
165 *m_sName = *IDE.m_sName;
167 *m_sValue = *IDE.m_sValue;
168
169 if (IDE.m_pNameLocalized) {
171 }
172 else
173 m_pNameLocalized = NULL;
174
175 if (IDE.m_pValueLocalized) {
177 }
178 else
179 m_pValueLocalized = NULL;
180
181 return *this;
182}
183
184/**
185******************************************************************************
186* Name: CIccDictEntry::~CIccDictEntry
187*
188* Purpose:
189*
190* Args:
191*
192* Return:
193******************************************************************************/
195{
196 delete m_sName;
197 delete m_sValue;
198 delete m_pNameLocalized;
199 delete m_pValueLocalized;
200}
201
202/**
203******************************************************************************
204* Name: CIccDictEntry::Describe
205*
206* Purpose:
207*
208* Args:
209*
210* Return:
211******************************************************************************/
212void CIccDictEntry::Describe(std::string &sDescription, int nVerboseness)
213{
214 std::wstring ws;
215
216 //setup converter
217 std::wstring_convert<convert_type, wchar_t> converter;
218
219 sDescription += "BEGIN DICT_ENTRY\nName=";
220 ws.assign(m_sName->begin(), m_sName->end());
221 sDescription += converter.to_bytes(ws);
222 sDescription += "\nValue=";
223 ws.assign(m_sValue->begin(), m_sValue->end());
224 sDescription += converter.to_bytes(ws);
225 sDescription += "\n";
226
227 if (m_pNameLocalized) {
228 sDescription += "BEGIN NAME_LOCALIZATION\n";
229 m_pNameLocalized->Describe(sDescription, nVerboseness);
230 sDescription += "END NAME_LOCALIZATION\n";
231 }
232 if (m_pValueLocalized) {
233 sDescription += "BEGIN VALUE_LOCALIZATION\n";
234 m_pValueLocalized->Describe(sDescription, nVerboseness);
235 sDescription += "END VALUE_LOCALIZATION\n";
236 }
237 sDescription += "END DICT_ENTRY\n";
238}
239
240
241/**
242******************************************************************************
243* Name: CIccDictEntry::PosRecSize
244*
245* Purpose:
246*
247* Args:
248*
249* Return:
250******************************************************************************/
252{
254 return 32;
256 return 24;
257 return 16;
258}
259
260
261bool CIccDictEntry::SetValue(std::wstring sValue)
262{
263 bool rv = m_bValueSet && !m_sValue->empty();
264
265 *m_sValue = sValue;
266 m_bValueSet = true;
267 return rv;
268}
269
270/**
271******************************************************************************
272* Name: CIccDictEntry::SetNameLocalized
273*
274* Purpose:
275*
276* Args:
277*
278* Return:
279******************************************************************************/
281{
282 bool rv;
283
284 if (m_pNameLocalized) {
285 delete m_pNameLocalized;
286 rv = true;
287 }
288 else
289 rv = false;
290
291 m_pNameLocalized = pNameLocalized;
292
293 return rv;
294}
295
296
297/**
298******************************************************************************
299* Name: CIccDictEntry::SetValueLocalized
300*
301* Purpose:
302*
303* Args:
304*
305* Return:
306******************************************************************************/
308{
309 bool rv;
310
311 if (m_pValueLocalized) {
312 delete m_pValueLocalized;
313 rv = true;
314 }
315 else
316 rv = false;
317
318 m_pValueLocalized = pValueLocalized;
319
320 return rv;
321}
322
323/*=============================================================================
324 * CLASS CIccTagDict
325 *============================================================================*/
326
327/**
328 ******************************************************************************
329 * Name: CIccTagDict::CIccTagDict
330 *
331 * Purpose:
332 *
333 * Args:
334 *
335 * Return:
336 ******************************************************************************/
338{
339 m_tagSize = m_tagStart = 0;
340 m_bBadAlignment = false;
341
343}
344
345/**
346 ******************************************************************************
347 * Name: CIccTagDict::CIccTagDict
348 *
349 * Purpose:
350 *
351 * Args:
352 *
353 * Return:
354 ******************************************************************************/
356{
357 m_tagSize = m_tagStart = 0;
358 m_bBadAlignment = false;
360
361 CIccNameValueDict::iterator i;
362 CIccDictEntryPtr ptr = {};
363
364 for (i=dict.m_Dict->begin(); i!=dict.m_Dict->end(); i++) {
365 ptr.ptr = new CIccDictEntry(*i->ptr);
366
367 m_Dict->push_back(ptr);
368 }
369}
370
371/**
372 ******************************************************************************
373 * Name: &operator=
374 *
375 * Purpose:
376 *
377 * Args:
378 *
379 * Return:
380 ******************************************************************************/
382{
383 if (&dict == this)
384 return *this;
385
386 Cleanup();
387
388 CIccNameValueDict::iterator i;
389 CIccDictEntryPtr ptr = {};
390
391 for (i=dict.m_Dict->begin(); i!=dict.m_Dict->end(); i++) {
392 ptr.ptr = new CIccDictEntry(*i->ptr);
393
394 m_Dict->push_back(ptr);
395 }
396
397 return *this;
398}
399
400/**
401 ******************************************************************************
402 * Name: CIccTagDict::~CIccTagDict
403 *
404 * Purpose:
405 *
406 * Args:
407 *
408 * Return:
409 ******************************************************************************/
411{
412 Cleanup();
413 delete m_Dict;
414}
415
416
417/**
418******************************************************************************
419* Name: CIccTagDict::MaxPosRecSize;
420*
421* Purpose:
422*
423* Args:
424*
425* Return:
426******************************************************************************/
428{
429
430 icUInt32Number rv = 16;
431
432 CIccNameValueDict::iterator i;
433 CIccDictEntry ptr;
434
435 for (i=m_Dict->begin(); i!=m_Dict->end(); i++) {
436 if (i->ptr->PosRecSize() > rv)
437 rv = i->ptr->PosRecSize();
438 }
439
440 return rv;
441}
442
443
444/**
445 ******************************************************************************
446 * Name: CIccTagDict::Describe
447 *
448 * Purpose:
449 *
450 * Args:
451 *
452 * Return:
453 ******************************************************************************/
454void CIccTagDict::Describe(std::string &sDescription, int nVerboseness)
455{
456 icChar buf[128];
457
458 sprintf(buf, "BEGIN DICT_TAG\n");
459 sDescription += buf;
460
461 CIccNameValueDict::iterator i;
462 for (i=m_Dict->begin(); i!=m_Dict->end(); i++) {
463 sDescription += "\n";
464
465 i->ptr->Describe(sDescription, nVerboseness);
466 }
467
468 sprintf(buf, "\nEND DICT_TAG\n");
469 sDescription += buf;
470}
471
479
480
481/**
482 ******************************************************************************
483 * Name: CIccTagDict::Read
484 *
485 * Purpose:
486 *
487 * Args:
488 *
489 * Return:
490 ******************************************************************************/
492{
494
495 m_tagSize = size;
496
497 icUInt32Number headerSize = sizeof(icTagTypeSignature) +
498 sizeof(icUInt32Number) +
499 sizeof(icUInt32Number) +
500 sizeof(icUInt32Number);
501
502 if (headerSize > size)
503 return false;
504
505 if (!pIO) {
506 return false;
507 }
508
509 Cleanup();
510
511 m_tagStart = pIO->Tell();
512
513 if (!pIO->Read32(&sig))
514 return false;
515
516 if (!pIO->Read32(&m_nReserved))
517 return false;
518
519 icUInt32Number count, reclen, i;
520
521 if (!pIO->Read32(&count))
522 return false;
523
524 if (!pIO->Read32(&reclen))
525 return false;
526
527 if (reclen!=16 && reclen!=24 && reclen!=32)
528 return false;
529
530 if (headerSize + count*reclen > size)
531 return false;
532
533 icDictRecordPos *pos = (icDictRecordPos*)calloc(count, sizeof(icDictRecordPos));
534 if (!pos)
535 return false;
536
537 //Read TagDir
538 for (i=0; i<count; i++) {
539 if (!pIO->Read32(&pos[i].posName.offset) ||
540 !pIO->Read32(&pos[i].posName.size) ||
541 !pIO->Read32(&pos[i].posValue.offset) ||
542 !pIO->Read32(&pos[i].posValue.size)) {
543 free(pos);
544 return false;
545 }
546
547 if (reclen>=24) {
548 if (!pIO->Read32(&pos[i].posNameLocalized.offset) ||
549 !pIO->Read32(&pos[i].posNameLocalized.size)) {
550 free(pos);
551 return false;
552 }
553 if (reclen>=32) {
554 if (!pIO->Read32(&pos[i].posValueLocalized.offset) ||
555 !pIO->Read32(&pos[i].posValueLocalized.size)) {
556 free(pos);
557 return false;
558 }
559 }
560 }
561
562 if ((pos[i].posName.offset & 0x3) ||
563 (pos[i].posValue.offset & 0x3) ||
564 (pos[i].posNameLocalized.offset & 0x3) ||
565 (pos[i].posValueLocalized.offset & 0x3))
566 m_bBadAlignment = true;
567 }
568
569 icUInt32Number bufsize = 128, num;
570 icUnicodeChar *buf = (icUnicodeChar*)malloc(bufsize);
571 CIccDictEntryPtr ptr = {};
572 std::wstring str;
573
574 for (i=0; i<count; i++) {
575 ptr.ptr = new CIccDictEntry();
576 if (!ptr.ptr)
577 return false;
578
579 //GetName
580 if (pos[i].posName.offset) {
581 if (!pos[i].posName.size) {
582 str.clear();
583 ptr.ptr->SetValue(str);
584 }
585 else {
586 if (pos[i].posName.offset + pos[i].posName.size >size ||
587 !pos[i].posName.size) {
588 free(pos);
589 free(buf);
590 delete ptr.ptr;
591 return false;
592 }
593
594 //Make sure we have buf large enough for the string
595 if (bufsize < pos[i].posName.size) {
596 bufsize = pos[i].posName.size;
597 buf = (icUnicodeChar*)icRealloc(buf, bufsize);
598 if (!buf) {
599 free(pos);
600 delete ptr.ptr;
601 return false;
602 }
603 }
604
605 if (pIO->Seek(m_tagStart+pos[i].posName.offset, icSeekSet)<0) {
606 free(pos);
607 free(buf);
608 delete ptr.ptr;
609 return false;
610 }
611
612 num = pos[i].posName.size / sizeof(icUnicodeChar);
613 if (pIO->Read16(buf, num)!=(icInt32Number)num) {
614 free(pos);
615 free(buf);
616 delete ptr.ptr;
617 return false;
618 }
619 str.assign(&buf[0], &buf[num]);
620 ptr.ptr->GetName() = str;
621 }
622 }
623
624 //GetValue
625 if (pos[i].posValue.offset) {
626 if (!pos[i].posValue.size) {
627 str.clear();
628 ptr.ptr->SetValue(str);
629 }
630 else {
631 if (pos[i].posValue.offset + pos[i].posValue.size >size ||
632 (pos[i].posValue.size&1)) {
633 free(pos);
634 free(buf);
635 delete ptr.ptr;
636 return false;
637 }
638
639 //Make sure we have buf large enough for the string
640 if (bufsize < pos[i].posValue.size) {
641 bufsize = pos[i].posValue.size;
642 buf = (icUnicodeChar*)icRealloc(buf, bufsize);
643 if (!buf) {
644 free(pos);
645 delete ptr.ptr;
646 return false;
647 }
648 }
649
650 if (pIO->Seek(m_tagStart+pos[i].posValue.offset, icSeekSet)<0) {
651 free(pos);
652 free(buf);
653 delete ptr.ptr;
654 return false;
655 }
656
657 num = pos[i].posValue.size / sizeof(icUnicodeChar);
658 if (pIO->Read16(buf, num)!=(icInt32Number)num) {
659 free(pos);
660 free(buf);
661 delete ptr.ptr;
662 return false;
663 }
664 str.assign(&buf[0], &buf[num]);
665 ptr.ptr->SetValue(str);
666 }
667 }
668
669 //Get NameLocalized
670 if (pos[i].posNameLocalized.offset) {
671 if (pos[i].posNameLocalized.offset + pos[i].posNameLocalized.size > size ||
672 pos[i].posNameLocalized.size < sizeof(icSignature)) {
673 free(pos);
674 free(buf);
675 delete ptr.ptr;
676 return false;
677 }
678
679 if (pIO->Seek(m_tagStart+pos[i].posNameLocalized.offset, icSeekSet)<0) {
680 free(pos);
681 free(buf);
682 delete ptr.ptr;
683 return false;
684 }
685
687 if (!pIO->Read32(&textSig, 1)) {
688 free(pos);
689 free(buf);
690 delete ptr.ptr;
691 return false;
692 }
693
694 if (textSig != icSigMultiLocalizedUnicodeType) {
695 free(pos);
696 free(buf);
697 delete ptr.ptr;
698 return false;
699 }
700
701 if (pIO->Seek(m_tagStart+pos[i].posNameLocalized.offset, icSeekSet)<0) {
702 free(pos);
703 free(buf);
704 delete ptr.ptr;
705 return false;
706 }
707
709
710 if (!pTag || !pTag->Read(pos[i].posNameLocalized.size, pIO)) {
711 free(pos);
712 free(buf);
713 delete ptr.ptr;
714 return false;
715 }
716
717 ptr.ptr->SetNameLocalized(pTag);
718 }
719
720 //Get ValueLocalized
721 if (pos[i].posValueLocalized.offset) {
722 if (pos[i].posValueLocalized.offset + pos[i].posValueLocalized.size > size ||
723 pos[i].posValueLocalized.size < sizeof(icSignature)) {
724 free(pos);
725 free(buf);
726 delete ptr.ptr;
727 return false;
728 }
729
730 if (pIO->Seek(m_tagStart+pos[i].posValueLocalized.offset, icSeekSet)<0) {
731 free(pos);
732 free(buf);
733 delete ptr.ptr;
734 return false;
735 }
736
738 if (!pIO->Read32(&textSig, 1)) {
739 free(pos);
740 free(buf);
741 delete ptr.ptr;
742 return false;
743 }
744
745 if (textSig != icSigMultiLocalizedUnicodeType) {
746 free(pos);
747 free(buf);
748 delete ptr.ptr;
749 return false;
750 }
751
752 if (pIO->Seek(m_tagStart+pos[i].posValueLocalized.offset, icSeekSet)<0) {
753 free(pos);
754 free(buf);
755 delete ptr.ptr;
756 return false;
757 }
758
760
761 if (!pTag || !pTag->Read(pos[i].posValueLocalized.size, pIO)) {
762 free(pos);
763 free(buf);
764 delete ptr.ptr;
765 return false;
766 }
767
768 ptr.ptr->SetValueLocalized(pTag);
769 }
770
771 m_Dict->push_back(ptr);
772 }
773
774 free(pos);
775 free(buf);
776
777 return true;
778}
779
780/**
781 ******************************************************************************
782 * Name: CIccTagDict::Write
783 *
784 * Purpose:
785 *
786 * Args:
787 *
788 * Return:
789 ******************************************************************************/
791{
793
794 if (!pIO)
795 return false;
796
797 m_tagStart = pIO->Tell();
798
799 if (!pIO->Write32(&sig))
800 return false;
801
802 if (!pIO->Write32(&m_nReserved))
803 return false;
804
805 CIccNameValueDict::iterator i, j;
806 icUInt32Number count;
807 icUInt8Number zbuf[32];
808
809 memset(zbuf, 0, 32);
810
811 for (count=0, i=m_Dict->begin(); i!= m_Dict->end(); i++) {
812 if (i->ptr)
813 count++;
814 }
815
816 pIO->Write32(&count);
817
818 icUInt32Number recSize = MaxPosRecSize();
819 pIO->Write32(&recSize);
820
821 icDictRecordPos *pos = (icDictRecordPos*)calloc(count, sizeof(icDictRecordPos));
822 if (!pos)
823 return false;
824
825 icUInt32Number n, dirpos = pIO->Tell();
826
827 //Write Unintialized Dict rec offset array
828 for (i=m_Dict->begin(); i!= m_Dict->end(); i++) {
829 if (i->ptr) {
830 pIO->Write8(zbuf, recSize);
831 }
832 }
833
835 std::wstring::const_iterator chrptr;
836 //Write Dict records
837 for (n=0, i=m_Dict->begin(); i!= m_Dict->end(); i++) {
838 if (i->ptr) {
839 pos[n].posName.offset = pIO->Tell()-m_tagStart;
840
841 for(chrptr = i->ptr->GetName().begin(); chrptr!=i->ptr->GetName().end(); chrptr++) {
842 c=(icUnicodeChar)*chrptr;
843 pIO->Write16(&c, 1);
844 }
845 pos[n].posName.size = pIO->Tell()-m_tagStart - pos[n].posName.offset;
846 pIO->Align32();
847
848 if (i->ptr->IsValueSet()) {
849 pos[n].posValue.offset = pIO->Tell()-m_tagStart;
850 for(chrptr = i->ptr->ValueBegin(); chrptr!=i->ptr->ValueEnd(); chrptr++) {
851 c=(icUnicodeChar)*chrptr;
852 pIO->Write16(&c, 1);
853 }
854 pos[n].posValue.size = pIO->Tell()-m_tagStart - pos[n].posValue.offset;
855 pIO->Align32();
856 }
857
858 if (recSize>16 && i->ptr->GetNameLocalized()) {
859 pos[n].posNameLocalized.offset = pIO->Tell()-m_tagStart;
860 i->ptr->GetNameLocalized()->Write(pIO);
862 pIO->Align32();
863 }
864
865 if (recSize>24 && i->ptr->GetValueLocalized()) {
866 pos[n].posValueLocalized.offset = pIO->Tell()-m_tagStart;
867 i->ptr->GetValueLocalized()->Write(pIO);
869 pIO->Align32();
870 }
871 n++;
872 }
873 }
874 icUInt32Number endpos = pIO->Tell();
875
876 pIO->Seek(dirpos, icSeekSet);
877
878 //Write TagDir with offsets and sizes
879 for (n=0, i=m_Dict->begin(); i!= m_Dict->end(); i++) {
880 if (i->ptr) {
881 pIO->Write32(&pos[n].posName.offset);
882 pIO->Write32(&pos[n].posName.size);
883 pIO->Write32(&pos[n].posValue.offset);
884 pIO->Write32(&pos[n].posValue.size);
885 if (recSize>16) {
886 pIO->Write32(&pos[n].posNameLocalized.offset);
887 pIO->Write32(&pos[n].posNameLocalized.size);
888 if (recSize>24) {
889 pIO->Write32(&pos[n].posValueLocalized.offset);
890 pIO->Write32(&pos[n].posValueLocalized.size);
891 }
892 }
893 }
894 n++;
895 }
896 pIO->Seek(endpos, icSeekSet);
897
898 free(pos);
899
900 return true;
901}
902
903
904/**
905 ******************************************************************************
906 * Name: CIccTagDict::Validate
907 *
908 * Purpose:
909 *
910 * Args:
911 *
912 * Return:
913 ******************************************************************************/
914icValidateStatus CIccTagDict::Validate(std::string sigPath, std::string &sReport,
915 const CIccProfile* pProfile /*=NULL*/) const
916{
917 icValidateStatus rv = CIccTag::Validate(sigPath, sReport, pProfile);
918
919 CIccInfo Info;
920 std::string sSigPathName = Info.GetSigPathName(sigPath);
921
922 // Check for duplicate tags
923 if (!AreNamesUnique()) {
924 sReport += icMsgValidateWarning;
925 sReport += sSigPathName;
926 sReport += " - There are duplicate names.\n";
928 }
929
930 if (!AreNamesNonzero()) {
931 sReport += icMsgValidateWarning;
932 sReport += sSigPathName;
933 sReport += " - There zero-length names.\n";
935 }
936
937 // Check for duplicate tags
938 if (m_bBadAlignment) {
939 sReport += icMsgValidateWarning;
940 sReport += sSigPathName;
941 sReport += " - Some Data elements are not aligned correctly\n";
943 }
944
945 return rv;
946}
947
948/**
949 ***************************************************************************
950 * Name: CIccTagDict::Cleanup
951 *
952 * Purpose: Detach from a pending IO object
953 ***************************************************************************
954 */
956{
957 CIccNameValueDict::iterator i;
958
959 for (i=m_Dict->begin(); i!=m_Dict->end(); i++) {
960 if (i->ptr)
961 delete i->ptr;
962 }
963 m_Dict->clear();
964}
965
966/**
967******************************************************************************
968* Name: CIccTagDict::AreNamesUnique
969*
970* Purpose: For each tag it checks to see if any other tags have the same
971* signature.
972*
973*
974* Return:
975* true if all tags have unique signatures, or false if there are duplicate
976* tag signatures.
977*******************************************************************************
978*/
980{
981 CIccNameValueDict::const_iterator i, j;
982
983 for (i=m_Dict->begin(); i!=m_Dict->end(); i++) {
984 j=i;
985 for (j++; j!= m_Dict->end(); j++) {
986 if (i->ptr->GetName() == j->ptr->GetName())
987 return false;
988 }
989 }
990
991 return true;
992}
993
994/**
995******************************************************************************
996* Name: CIccTagDict::AreNamesNonzero
997*
998* Purpose: For each tag it checks to see if any other tags have the same
999* signature.
1000*
1001*
1002* Return:
1003* true if all tags have unique signatures, or false if there are duplicate
1004* tag signatures.
1005*******************************************************************************
1006*/
1008{
1009 CIccNameValueDict::const_iterator i, j;
1010
1011 for (i=m_Dict->begin(); i!=m_Dict->end(); i++) {
1012 if (i->ptr->GetName().empty())
1013 return false;
1014 }
1015
1016return true;
1017}
1018
1019
1020/**
1021 ****************************************************************************
1022 * Name: CIccTagDict::Get
1023 *
1024 * Purpose: Get a dictionary entry with a given name
1025 *
1026 * Args:
1027 * sName - name to find in dictionary
1028 *
1029 * Return:
1030 * Pointer to desired dictionary entry, or NULL if not found.
1031 *****************************************************************************
1032 */
1033CIccDictEntry* CIccTagDict::Get(std::wstring sName) const
1034{
1035 CIccNameValueDict::const_iterator i;
1036
1037 for (i=m_Dict->begin(); i!=m_Dict->end(); i++) {
1038 if (i->ptr->GetName() == sName)
1039 return i->ptr;
1040 }
1041
1042 return NULL;
1043}
1044
1045/**
1046****************************************************************************
1047* Name: CIccTagDict::Get
1048*
1049* Purpose: Get a dictionary entry with a given name
1050*
1051* Args:
1052* sName - name to find in dictionary
1053*
1054* Return:
1055* Pointer to desired dictionary entry, or NULL if not found.
1056*****************************************************************************
1057*/
1059{
1060 std::wstring sName;
1061 while(*szName)
1062 sName += *szName;
1063
1064 return Get(sName);
1065}
1066
1067
1068/**
1069****************************************************************************
1070* Name: CIccTagDict::Get
1071*
1072* Purpose: Get a dictionary entry with a given name
1073*
1074* Args:
1075* sName - name to find in dictionary
1076*
1077* Return:
1078* Pointer to desired dictionary entry, or NULL if not found.
1079*****************************************************************************
1080*/
1082{
1083 std::wstring sName(szName, szName+strlen(szName));
1084
1085 return Get(sName);
1086}
1087
1088/**
1089****************************************************************************
1090* Name: CIccTagDict::GetValue
1091*
1092* Purpose: Get a value associated with a given name
1093*
1094* Args:
1095* sName - name to find in dictionary
1096*
1097* Return:
1098* Pointer to desired dictionary entry, or NULL if not found.
1099*****************************************************************************
1100*/
1101std::wstring CIccTagDict::GetValue(std::wstring sName, bool *bIsSet) const
1102{
1103 CIccDictEntry *de = Get(sName);
1104
1105 if (de) {
1106
1107 if (bIsSet)
1108 *bIsSet = de->IsValueSet();
1109
1110 return de->GetValue();
1111 }
1112
1113 if (bIsSet)
1114 *bIsSet = false;
1115
1116 std::wstring str;
1117 return str;
1118}
1119
1120/**
1121****************************************************************************
1122* Name: CIccTagDict::GetValue
1123*
1124* Purpose: Get a value associated with a given name
1125*
1126* Args:
1127* szName - name to find in dictionary
1128*
1129* Return:
1130* Pointer to desired dictionary entry, or NULL if not found.
1131*****************************************************************************
1132*/
1133std::wstring CIccTagDict::GetValue(const icUnicodeChar *szName, bool *bIsSet) const
1134{
1135 std::wstring sName;
1136 while(*szName)
1137 sName += *szName;
1138
1139 return GetValue(sName, bIsSet);
1140}
1141
1142/**
1143****************************************************************************
1144* Name: CIccTagDict::GetValue
1145*
1146* Purpose: Get a value associated with a given name
1147*
1148* Args:
1149* szName - name to find in dictionary
1150*
1151* Return:
1152* Pointer to desired dictionary entry, or NULL if not found.
1153*****************************************************************************
1154*/
1155std::wstring CIccTagDict::GetValue(const char *szName, bool *bIsSet) const
1156{
1157 std::wstring sName(szName, szName+strlen(szName));
1158
1159 return GetValue(sName, bIsSet);
1160}
1161
1162/**
1163****************************************************************************
1164* Name: CIccTagDict::GetNameLocalized
1165*
1166* Purpose: Get a localized name information associated with a given name
1167*
1168* Args:
1169* sName - name to find in dictionary
1170*
1171* Return:
1172* localized information for name
1173*****************************************************************************
1174*/
1176{
1177 CIccDictEntry *de = Get(sName);
1178
1179 if (de)
1180 return de->GetNameLocalized();
1181
1182 return NULL;
1183}
1184
1185/**
1186****************************************************************************
1187* Name: CIccTagDict::GetNameLocalized
1188*
1189* Purpose: Get a localized name information associated with a given name
1190*
1191* Args:
1192* sName - name to find in dictionary
1193*
1194* Return:
1195* localized information for name
1196*****************************************************************************
1197*/
1199{
1200 std::wstring sName;
1201 while(*szName)
1202 sName += *szName;
1203
1204 return GetNameLocalized(sName);
1205}
1206
1207/**
1208****************************************************************************
1209* Name: CIccTagDict::GetNameLocalized
1210*
1211* Purpose: Get a localized name information associated with a given name
1212*
1213* Args:
1214* sName - name to find in dictionary
1215*
1216* Return:
1217* localized information for name
1218*****************************************************************************
1219*/
1220
1222{
1223 std::wstring sName(szName, szName+strlen(szName));
1224
1225 return GetNameLocalized(sName);
1226}
1227
1228
1229/**
1230****************************************************************************
1231* Name: CIccTagDict::GetValueLocalized
1232*
1233* Purpose: Get a localized name information for value associated with a given name
1234*
1235* Args:
1236* sName - name to find in dictionary
1237*
1238* Return:
1239* localized information for name's value
1240*****************************************************************************
1241*/
1243{
1244 CIccDictEntry *de = Get(sName);
1245
1246 if (de)
1247 return de->GetValueLocalized();
1248
1249 return NULL;
1250}
1251
1252/**
1253****************************************************************************
1254* Name: CIccTagDict::GetValueLocalized
1255*
1256* Purpose: Get a localized name information for value associated with a given name
1257*
1258* Args:
1259* sName - name to find in dictionary
1260*
1261* Return:
1262* localized information for name's value
1263*****************************************************************************
1264*/
1266{
1267 std::wstring sName;
1268 while(*szName)
1269 sName += *szName;
1270
1271 return GetValueLocalized(sName);
1272}
1273
1274/**
1275****************************************************************************
1276* Name: CIccTagDict::GetValueLocalized
1277*
1278* Purpose: Get a localized name information for value associated with a given name
1279*
1280* Args:
1281* sName - name to find in dictionary
1282*
1283* Return:
1284* localized information for name's value
1285*****************************************************************************
1286*/
1287
1289{
1290 std::wstring sName(szName, szName+strlen(szName));
1291
1292 return GetValueLocalized(sName);
1293}
1294
1295
1296/**
1297******************************************************************************
1298* Name: CIccTagDict::Remove
1299*
1300* Purpose: Remove a name value pair from the dictionary
1301*
1302* Args:
1303* sName = the name to look for in the dictionary
1304*
1305* Return:
1306* true if sName exists and was removed, or false otherwise
1307*******************************************************************************
1308*/
1309bool CIccTagDict::Remove(std::wstring sName)
1310{
1311 CIccNameValueDict::iterator i;
1312
1313 for (i=m_Dict->begin(); i!=m_Dict->end(); i++) {
1314 if (i->ptr->GetName() == sName) {
1315 delete i->ptr;
1316
1317 m_Dict->erase(i);
1318 return true;
1319 }
1320 }
1321
1322 return false;
1323}
1324
1325
1326/**
1327******************************************************************************
1328* Name: CIccTagDict::Remove
1329*
1330* Purpose: Remove a name value pair from the dictionary
1331*
1332* Args:
1333* sName = the name to look for in the dictionary
1334*
1335* Return:
1336* true if sName exists and was remove , or false otherwise
1337*******************************************************************************
1338*/
1340{
1341 std::wstring sName;
1342 while(*szName)
1343 sName += *szName;
1344
1345 return Remove(sName);
1346
1347}
1348
1349
1350/**
1351******************************************************************************
1352* Name: CIccTagDict::Remove
1353*
1354* Purpose: Remove a name value pair from the dictionary
1355*
1356* Args:
1357* sName = the name to look for in the dictionary
1358*
1359* Return:
1360* true if sName exists and was remove , or false otherwise
1361*******************************************************************************
1362*/
1364{
1365 std::wstring sName(szName, szName+strlen(szName));
1366
1367 return Remove(sName);
1368}
1369
1370
1371/**
1372******************************************************************************
1373* Name: CIccTagDict::Set
1374*
1375* Purpose: Associate a value with a name in the dictionary
1376*
1377* Args:
1378* sName = the name to look for in the dictionary
1379* sValue = value to associate with sName
1380* bUnset = flag to indicate that value has not been set (no data for value in tag)
1381*
1382* Return:
1383* true if value associate with sName was changed, or false if no change
1384*******************************************************************************
1385*/
1386bool CIccTagDict::Set(std::wstring sName, std::wstring sValue, bool bUnSet)
1387{
1388 CIccDictEntry *de = Get(sName);
1389
1390 if (de) {
1391 if (de->GetValue()==sValue && de->IsValueSet() && !bUnSet)
1392 return false;
1393 }
1394 else {
1395 de = new CIccDictEntry;
1396 de->GetName() = sName;
1397
1398 CIccDictEntryPtr ptr = {};
1399 ptr.ptr = de;
1400 m_Dict->push_back(ptr);
1401 }
1402
1403 if (sValue.empty() && bUnSet)
1404 de->UnsetValue();
1405 else
1406 de->SetValue(sValue);
1407
1408 return true;
1409}
1410
1412{
1413 std::wstring sName;
1414 while(*szName)
1415 sName += *szName;
1416
1417 std::wstring sValue;
1418
1419 if (szValue) {
1420 while(*szValue)
1421 sValue += *szValue;
1422
1423 return Set(sName, sValue, false);
1424 }
1425
1426 return Set(sName, sValue, true);
1427}
1428
1429bool CIccTagDict::Set(const char *szName, const char *szValue)
1430{
1431 std::wstring sName(szName, szName+strlen(szName));
1432 std::wstring sValue;
1433
1434 if (szValue) {
1435 sValue.assign(szValue, szValue+strlen(szValue));
1436
1437 return Set(sName, sValue, false);
1438 }
1439
1440 return Set(sName, sValue, true);
1441}
1442
1444{
1445 CIccDictEntry *de = Get(sName);
1446
1447 if (!de) {
1448 de = new CIccDictEntry;
1449 de->GetName() = sName;
1450
1451 CIccDictEntryPtr ptr = {};
1452 ptr.ptr = de;
1453 m_Dict->push_back(ptr);
1454 }
1455
1456 return de->SetNameLocalized(pTag);
1457}
1458
1460{
1461 std::wstring sName;
1462 while(*szName)
1463 sName += *szName++;
1464
1465 return SetNameLocalized(sName, pTag);
1466}
1467
1469{
1470 std::wstring sName;
1471 while(*szName)
1472 sName += *szName++;
1473
1474 return SetNameLocalized(sName, pTag);
1475}
1476
1478{
1479 CIccDictEntry *de = Get(sName);
1480
1481 if (!de) {
1482 de = new CIccDictEntry;
1483 de->GetName() = sName;
1484
1485 CIccDictEntryPtr ptr = {};
1486 ptr.ptr = de;
1487 m_Dict->push_back(ptr);
1488 }
1489
1490 return de->SetValueLocalized(pTag);
1491}
1492
1494{
1495 std::wstring sName;
1496 while(*szName)
1497 sName += *szName++;
1498
1499 return SetValueLocalized(sName, pTag);
1500}
1501
1503{
1504 std::wstring sName(szName, szName+strlen(szName));
1505
1506 return SetValueLocalized(sName, pTag);
1507}
1508
1509#endif //ICC_UNSUPPORTED_TAG_DICT
icArraySignature sig
char icChar
Definition IccDefs.h:109
icValidateStatus
Definition IccDefs.h:118
@ icValidateWarning
Definition IccDefs.h:120
File: IccIO.h.
@ icSeekSet
Definition IccIO.h:83
std::codecvt_utf8< wchar_t > convert_type
File: IccTagDictTag.h.
std::list< CIccDictEntryPtr > CIccNameValueDict
List Class: CIccDictEntry.
Definition IccTagDict.h:151
const icChar * szName
icValidateStatus icMaxStatus(icValidateStatus s1, icValidateStatus s2)
Name: icMaxStatus.
Definition IccUtil.cpp:244
const char * icMsgValidateWarning
Definition IccUtil.cpp:90
void * icRealloc(void *ptr, size_t size)
Name: icRealloc.
Definition IccUtil.cpp:111
File: IccUtil.h.
icTagTypeSignature
unsigned int icUInt32Number
Data Class: CIccDictEntry.
Definition IccTagDict.h:97
std::wstring * m_sValue
Definition IccTagDict.h:131
void UnsetValue()
Definition IccTagDict.h:121
bool SetValueLocalized(CIccTagMultiLocalizedUnicode *pValueLocalized)
Name: CIccDictEntry::SetValueLocalized.
CIccDictEntry()
Name: CIccDictEntry::CIccDictEntry.
bool SetNameLocalized(CIccTagMultiLocalizedUnicode *pNameLocalized)
Name: CIccDictEntry::SetNameLocalized.
CIccTagMultiLocalizedUnicode * GetValueLocalized()
Definition IccTagDict.h:119
CIccTagMultiLocalizedUnicode * GetNameLocalized()
Definition IccTagDict.h:118
virtual ~CIccDictEntry()
Name: CIccDictEntry::~CIccDictEntry.
std::wstring & GetName()
Definition IccTagDict.h:109
bool SetValue(std::wstring sValue)
CIccDictEntry & operator=(const CIccDictEntry &IDE)
Name: CIccDictEntry::operator=.
std::wstring * m_sName
Definition IccTagDict.h:130
bool IsValueSet()
Definition IccTagDict.h:115
void Describe(std::string &sDescription, int nVerboseness)
Name: CIccDictEntry::Describe.
bool m_bValueSet
Definition IccTagDict.h:132
CIccTagMultiLocalizedUnicode * m_pValueLocalized
Definition IccTagDict.h:135
CIccTagMultiLocalizedUnicode * m_pNameLocalized
Definition IccTagDict.h:134
std::wstring GetValue()
Definition IccTagDict.h:114
icUInt32Number PosRecSize()
Name: CIccDictEntry::PosRecSize.
Definition IccTagDict.h:139
CIccDictEntry * ptr
Definition IccTagDict.h:141
Type: Class.
Definition IccIO.h:97
virtual icInt32Number Write8(void *pBuf8, icInt32Number nNum=1)
Definition IccIO.h:105
icInt32Number Write16(void *pBuf16, icInt32Number nNum=1)
Definition IccIO.cpp:122
icInt32Number Read16(void *pBuf16, icInt32Number nNum=1)
Definition IccIO.cpp:114
virtual icInt32Number Tell()
Definition IccIO.h:133
bool Align32()
Write operation to make sure that filelength is evenly divisible by 4.
Definition IccIO.cpp:341
icInt32Number Write32(void *pBuf32, icInt32Number nNum=1)
Definition IccIO.cpp:152
virtual icInt32Number Seek(icInt32Number nOffset, icSeekVal pos)
Definition IccIO.h:132
icInt32Number Read32(void *pBuf32, icInt32Number nNum=1)
Definition IccIO.cpp:143
Type: Class.
Definition IccUtil.h:303
std::string GetSigPathName(std::string sigPath)
Definition IccUtil.cpp:1614
Class: CIccTagDict.
Definition IccTagDict.h:161
CIccDictEntry * Get(const char *szName) const
Name: CIccTagDict::Get.
std::wstring GetValue(const char *szName, bool *bIsSet=NULL) const
Name: CIccTagDict::GetValue.
bool Set(const char *szName, const char *szValue=NULL)
bool AreNamesUnique() const
Name: CIccTagDict::AreNamesUnique.
virtual ~CIccTagDict()
Name: CIccTagDict::~CIccTagDict.
CIccTagMultiLocalizedUnicode * GetNameLocalized(std::wstring sName) const
Name: CIccTagDict::GetNameLocalized.
virtual bool Read(icUInt32Number size, CIccIO *pIO)
Name: CIccTagDict::Read.
icUInt32Number MaxPosRecSize()
Name: CIccTagDict::MaxPosRecSize;.
bool m_bBadAlignment
Definition IccTagDict.h:217
bool SetValueLocalized(const char *szName, CIccTagMultiLocalizedUnicode *pTag)
CIccNameValueDict * m_Dict
Definition IccTagDict.h:214
void Cleanup()
Name: CIccTagDict::Cleanup.
CIccTagMultiLocalizedUnicode * GetValueLocalized(std::wstring sName) const
Name: CIccTagDict::GetValueLocalized.
CIccTagDict()
Name: CIccTagDict::CIccTagDict.
icUInt32Number m_tagStart
Definition IccTagDict.h:222
virtual icTagTypeSignature GetType() const
Function: GetType()
Definition IccTagDict.h:169
icUInt32Number m_tagSize
Definition IccTagDict.h:221
bool Remove(std::wstring sName)
Name: CIccTagDict::Remove.
virtual bool Write(CIccIO *pIO)
Name: CIccTagDict::Write.
bool SetNameLocalized(const char *szName, CIccTagMultiLocalizedUnicode *pTag)
virtual void Describe(std::string &sDescription, int nVerboseness)
Name: CIccTagDict::Describe.
bool AreNamesNonzero() const
Name: CIccTagDict::AreNamesNonzero.
virtual icValidateStatus Validate(std::string sigPath, std::string &sReport, const CIccProfile *pProfile=NULL) const
Name: CIccTagDict::Validate.
CIccTagDict & operator=(const CIccTagDict &dict)
Name: &operator=.
icUInt32Number m_nReserved
virtual icValidateStatus Validate(std::string sigPath, std::string &sReport, const CIccProfile *pProfile=NULL) const
Function: Validate Each derived tag will implement it's own IsValid() function.
Class: CIccTagMultiLocalizedUnicode.
virtual CIccTag * NewCopy() const
Function: NewCopy(sDescription) Each derived tag will implement it's own NewCopy() function.
virtual void Describe(std::string &sDescription, int nVerboseness)
Name: CIccTagMultiLocalizedUnicode::Describe.
virtual bool Read(icUInt32Number size, CIccIO *pIO)
Name: CIccTagMultiLocalizedUnicode::Read.
unsigned char icUInt8Number
Number definitions.
long icInt32Number
icUInt16Number icUnicodeChar
16-bit unicode characters
icUInt32Number icSignature
@ icSigMultiLocalizedUnicodeType
icPositionNumber posValue
icPositionNumber posValueLocalized
icPositionNumber posNameLocalized
icPositionNumber posName
icUInt32Number offset
icUInt32Number size