Hoyt's FORK of DemoIccMAX 2.1.17.hoyt
Documentation for Hoyt's FORK of DemoIccMAX
Loading...
Searching...
No Matches
IccTagProfSeqId.cpp
Go to the documentation of this file.
1/** @file
2 File: IccProfSeqId.cpp
3
4 Contains: Implementation of prototype profileSequenceIdentifier Tag
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//////////////////////////////////////////////////////////////////////
65// HISTORY:
66//
67// -Initial implementation by Max Derhak Oct-21-2006
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 "IccTagProfSeqId.h"
80#include "IccUtil.h"
81#include "IccIO.h"
82
83/**
84****************************************************************************
85* Name: sampleICC::CIccProfileIdDesc::CIccProfileIdDesc
86*
87* Purpose:
88*
89* Args:
90*
91* Return:
92*
93*****************************************************************************
94*/
99
100
101/**
102****************************************************************************
103* Name: sampleICC::CIccProfileIdDesc::CIccProfileIdDesc
104*
105* Purpose:
106*
107* Args:
108* CIccProfile &profile
109*
110* Return:
111*
112*****************************************************************************
113*/
115{
116 m_profileID = profile.m_Header.profileID;
117 CIccTag *pTag = profile.FindTag(icSigProfileDescriptionTag);
118
119 if (pTag) {
120 switch (pTag->GetType()) {
122 {
124 }
125 break;
126
128 {
130
131 m_desc.SetText(pText->GetText());
132 }
133 break;
134
135 case icSigTextType:
136 {
137 CIccTagText *pText = (CIccTagText*)pTag;
138
139 m_desc.SetText(pText->GetText());
140 }
141 break;
142
143 default:
144 break;
145 }
146 }
147}
148
149
150/**
151****************************************************************************
152* Name: sampleICC::CIccProfileIdDesc::CIccProfileIdDesc
153*
154* Purpose:
155*
156* Args:
157* icProfileID id
158* CIccMultiLocalizedUnicode desc
159*
160* Return:
161*
162*****************************************************************************
163*/
169
170
171/**
172****************************************************************************
173* Name: sampleICC::CIccProfileIdDesc::CIccProfileIdDesc
174*
175* Purpose:
176*
177* Args:
178* const CIccProfileIdDesc &pid
179*
180* Return:
181*
182*****************************************************************************
183*/
189
190
191/**
192****************************************************************************
193* Name: sampleICC::CIccProfileIdDesc::operator=
194*
195* Purpose:
196*
197* Args:
198* const CIccProfileIdDesc &pid
199*
200* Return:
201* CIccProfileIdDesc &
202*****************************************************************************
203*/
205{
206 if (&pid == this)
207 return *this;
208
210 m_desc = pid.m_desc;
211
212 return *this;
213}
214
215
216/**
217****************************************************************************
218* Name: sampleICC::CIccProfileIdDesc::Describe
219*
220* Purpose:
221*
222* Args:
223* std::string &sDescription
224*
225* Return:
226* void
227*****************************************************************************
228*/
229void CIccProfileIdDesc::Describe(std::string &sDescription, int nVerboseness)
230{
231 std::string Dump;
232
233 sDescription += "ProfileID:\n";
234
235 size_t i;
236 char buf[20];
237 for (i=0; i<sizeof(icProfileID); i++) {
238 if (i && i%4==0)
239 sDescription += " ";
240 sprintf(buf, "%02x", m_profileID.ID8[i]);
241 sDescription += buf;
242 }
243 sDescription += "\n";
244
245 sDescription += "Description:\n";
246 m_desc.Describe(sDescription, nVerboseness);
247
248 sDescription += "\n";
249}
250
251
252/**
253****************************************************************************
254* Name: sampleICC::CIccProfileIdDesc::Read
255*
256* Purpose:
257*
258* Args:
259* icUInt32Number size
260* CIccIO *pIO
261*
262* Return:
263* bool
264*****************************************************************************
265*/
267{
268 if (sizeof (icProfileID) > size)
269 return false;
270
271 if (pIO->Read8(&m_profileID, sizeof(icProfileID))!=sizeof(icProfileID))
272 return false;
273
274 if (!m_desc.Read(size - sizeof(icProfileID), pIO))
275 return false;
276
277 return true;
278}
279
280
281/**
282****************************************************************************
283* Name: sampleICC::CIccProfileIdDesc::Write
284*
285* Purpose:
286*
287* Args:
288* CIccIO *pIO
289*
290* Return:
291* bool
292*****************************************************************************
293*/
295{
296 pIO->Write8(&m_profileID, sizeof(icProfileID));
297 m_desc.Write(pIO);
298
299 return true;
300}
301
302
303/**
304****************************************************************************
305* Name: CIccProfileIdDesc::Validate
306*
307* Purpose:
308*
309* Args:
310* std::string &sReport
311*
312* Return:
313* icValidateStatus
314*****************************************************************************
315*/
316icValidateStatus CIccProfileIdDesc::Validate(std::string sigPath, std::string &sReport, const CIccProfile* pProfile) const
317{
318 return m_desc.Validate(sigPath, sReport, pProfile);
319}
320
321
322
323/**
324 ******************************************************************************
325 * Name: CIccTagProfileSequenceId::CIccTagProfileSequenceId
326 *
327 * Purpose:
328 *
329 * Args:
330 *
331 * Return:
332 ******************************************************************************/
337
338/**
339 ******************************************************************************
340 * Name: CIccTagProfileSequenceId::CIccTagProfileSequenceId
341 *
342 * Purpose:
343 *
344 * Args:
345 *
346 * Return:
347 ******************************************************************************/
354
355/**
356 ******************************************************************************
357 * Name: &operator=
358 *
359 * Purpose:
360 *
361 * Args:
362 *
363 * Return:
364 ******************************************************************************/
366{
367 if (&psi == this)
368 return *this;
369
370 *m_list = *psi.m_list;
371
372 return *this;
373}
374
375/**
376 ******************************************************************************
377 * Name: CIccTagProfileSequenceId::~CIccTagProfileSequenceId
378 *
379 * Purpose:
380 *
381 * Args:
382 *
383 * Return:
384 ******************************************************************************/
389
390
391/**
392 ******************************************************************************
393 * Name: CIccTagProfileSequenceId::ParseMem
394 *
395 * Purpose:
396 *
397 * Args:
398 *
399 * Return:
400 ******************************************************************************/
402{
403 CIccMemIO IO;
404
405 if (!IO.Attach(pMem, size))
406 return NULL;
407
409
410 if (!pProSeqId->Read(size, &IO)) {
411 delete pProSeqId;
412 return NULL;
413 }
414
415 return pProSeqId;
416}
417
418
419/**
420 ******************************************************************************
421 * Name: CIccTagProfileSequenceId::Describe
422 *
423 * Purpose:
424 *
425 * Args:
426 *
427 * Return:
428 ******************************************************************************/
429void CIccTagProfileSequenceId::Describe(std::string &sDescription, int nVerboseness)
430{
431 icChar buf[128];
432
433 sprintf(buf, "BEGIN ProfileSequenceIdentification_TAG\n");
434 sDescription += buf;
435 sDescription += "\n";
436
437 int i;
438 CIccProfileIdDescList::iterator j;
439 for (i=0, j=m_list->begin(); j!=m_list->end(); i++, j++) {
440 sprintf(buf, "ProfileDescription_%d:\n", i+1);
441 sDescription += buf;
442 j->Describe(sDescription, nVerboseness);
443 }
444
445 sprintf(buf, "END ProfileSequenceIdentification_TAG\n");
446 sDescription += buf;
447 sDescription += "\n";
448}
449
450
451/**
452 ******************************************************************************
453 * Name: CIccTagProfileSequenceId::Read
454 *
455 * Purpose:
456 *
457 * Args:
458 *
459 * Return:
460 ******************************************************************************/
462{
463 icUInt32Number headerSize = sizeof(icTagTypeSignature) +
464 sizeof(icUInt32Number) +
465 sizeof(icUInt32Number);
466
467 if (headerSize > size)
468 return false;
469
470 if (!pIO) {
471 return false;
472 }
473
474 m_list->clear();
475
477 icUInt32Number tagStart = pIO->Tell();
478
479 if (!pIO->Read32(&sig))
480 return false;
481
482 if (!pIO->Read32(&m_nReserved))
483 return false;
484
485 icUInt32Number count, i;
486
487 if (!pIO->Read32(&count))
488 return false;
489
490 if (headerSize + (icUInt64Number)count*sizeof(icUInt32Number)*2 > size)
491 return false;
492
493 if (!count) {
494 return true;
495 }
496
497 icPositionNumber *pos = new icPositionNumber[count];
498 if (!pos)
499 return false;
500
501 //Read TagDir
502 for (i=0; i<count; i++) {
503 if (!pIO->Read32(&pos[i].offset) ||
504 !pIO->Read32(&pos[i].size)) {
505 delete [] pos;
506 return false;
507 }
508 }
509
511
512 for (i=0; i<count; i++) {
513 if (pos[i].offset + pos[i].size > size) {
514 delete [] pos;
515 return false;
516 }
517 pIO->Seek(tagStart + pos[i].offset, icSeekSet);
518
519 if (!pid.Read(pos[i].size, pIO)) {
520 delete [] pos;
521 return false;
522 }
523
524 m_list->push_back(pid);
525 }
526
527 delete [] pos;
528
529 return true;
530}
531
532/**
533 ******************************************************************************
534 * Name: CIccTagProfileSequenceId::Write
535 *
536 * Purpose:
537 *
538 * Args:
539 *
540 * Return:
541 ******************************************************************************/
543{
545
546 if (!pIO)
547 return false;
548
549 icUInt32Number tagStart = pIO->Tell();
550
551 if (!pIO->Write32(&sig))
552 return false;
553
554 if (!pIO->Write32(&m_nReserved))
555 return false;
556
557 icUInt32Number i, count = (icUInt32Number)m_list->size();
558
559 pIO->Write32(&count);
560
561 icPositionNumber *pos = new icPositionNumber[count];
562 if (!pos)
563 return false;
564
565 icUInt32Number dirpos = pIO->Tell();
566
567 //Write Unintialized TagDir
568 for (i=0; i<count; i++) {
569 pos[i].offset = 0;
570 pos[i].size = 0;
571 pIO->Write32(&pos[i].offset);
572 pIO->Write32(&pos[i].size);
573 }
574
575 CIccProfileIdDescList::iterator j;
576
577 //Write Tags
578 for (i=0, j=m_list->begin(); j!= m_list->end(); i++, j++) {
579 pos[i].offset = pIO->Tell();
580
581 j->Write(pIO);
582 pos[i].size = pIO->Tell() - pos[i].offset;
583 pos[i].offset -= tagStart;
584
585 pIO->Align32();
586 }
587
588 icUInt32Number endpos = pIO->Tell();
589
590 pIO->Seek(dirpos, icSeekSet);
591
592 //Write TagDir with offsets and sizes
593 for (i=0; i<count; i++) {
594 pIO->Write32(&pos[i].offset);
595 pIO->Write32(&pos[i].size);
596 }
597
598 pIO->Seek(endpos, icSeekSet);
599
600 return true;
601}
602
603
604/**
605 ******************************************************************************
606 * Name: CIccTagProfileSequenceId::Validate
607 *
608 * Purpose:
609 *
610 * Args:
611 *
612 * Return:
613 ******************************************************************************/
614icValidateStatus CIccTagProfileSequenceId::Validate(std::string sigPath, std::string &sReport,
615 const CIccProfile* pProfile /*=NULL*/) const
616{
617 icValidateStatus rv = CIccTag::Validate(sigPath, sReport, pProfile);
618
619 CIccInfo Info;
620 std::string sSigName = Info.GetSigPathName(sigPath);
621
622 CIccProfileIdDescList::iterator i;
623
624 for (i=m_list->begin(); i!=m_list->end(); i++) {
625 rv = icMaxStatus(rv, i->Validate(sigPath+icGetSigPath(GetType()), sReport, pProfile));
626 }
627
628 return rv;
629}
630
631
632/**
633****************************************************************************
634* Name: sampleICC::CIccTagProfileSequenceId::AddProfileDescription
635*
636* Purpose:
637*
638* Args:
639* CIccProfileIdDesc &profileDesc
640*
641* Return:
642* bool
643*****************************************************************************
644*/
646{
647 m_list->push_back(profileDesc);
648
649 return true;
650}
651
652
653/**
654****************************************************************************
655* Name: sampleICC::CIccTagProfileSequenceId::GetFirst
656*
657* Purpose:
658*
659* Args:
660*
661* Return:
662* CIccProfileIdDesc *
663*****************************************************************************
664*/
666{
667 if (m_list->size())
668 return &(*(m_list->begin()));
669
670 return NULL;
671}
672
673
674/**
675****************************************************************************
676* Name: sampleICC::CIccTagProfileSequenceId::GetLast
677*
678* Purpose:
679*
680* Args:
681*
682* Return:
683* CIccProfileIdDesc *
684*****************************************************************************
685*/
687{
688 if (m_list->size())
689 return &(*(m_list->rbegin()));
690
691 return NULL;
692}
693
icArraySignature sig
char icChar
Definition IccDefs.h:109
icValidateStatus
Definition IccDefs.h:118
File: IccIO.h.
@ icSeekSet
Definition IccIO.h:83
File: IccTagProfSeqId.h.
std::list< CIccProfileIdDesc > CIccProfileIdDescList
icValidateStatus icMaxStatus(icValidateStatus s1, icValidateStatus s2)
Name: icMaxStatus.
Definition IccUtil.cpp:244
std::string icGetSigPath(icUInt32Number nSig)
Definition IccUtil.cpp:1191
File: IccUtil.h.
icTagTypeSignature
unsigned int icUInt32Number
Type: Class.
Definition IccIO.h:97
virtual icInt32Number Write8(void *pBuf8, icInt32Number nNum=1)
Definition IccIO.h:105
virtual icInt32Number Read8(void *pBuf8, icInt32Number nNum=1)
Definition IccIO.h:104
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
Type: Class.
Definition IccIO.h:217
bool Attach(icUInt8Number *pData, icUInt32Number nSize, bool bWrite=false)
Definition IccIO.cpp:686
CIccTagMultiLocalizedUnicode m_desc
icValidateStatus Validate(std::string sigPath, std::string &sReport, const CIccProfile *pProfile=NULL) const
Name: CIccProfileIdDesc::Validate.
bool Write(CIccIO *pIO)
Name: sampleICC::CIccProfileIdDesc::Write.
CIccProfileIdDesc()
Name: sampleICC::CIccProfileIdDesc::CIccProfileIdDesc.
bool Read(icUInt32Number size, CIccIO *pIO)
Name: sampleICC::CIccProfileIdDesc::Read.
void Describe(std::string &sDescription, int nVerboseness)
Name: sampleICC::CIccProfileIdDesc::Describe.
icProfileID m_profileID
CIccProfileIdDesc & operator=(const CIccProfileIdDesc &pid)
Name: sampleICC::CIccProfileIdDesc::operator=.
Class: CIccTag.
virtual icTagTypeSignature GetType() const
Function: GetType()
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.
void SetText(const icChar *szText, icLanguageCode nLanguageCode=icLanguageCodeEnglish, icCountryCode nRegionCode=icCountryCodeUSA)
Name: refIccMAX::CIccTagMultiLocalizedUnicode::SetText.
virtual icValidateStatus Validate(std::string sigPath, std::string &sReport, const CIccProfile *pProfile=NULL) const
Name: CIccTagMultiLocalizedUnicode::Validate.
virtual void Describe(std::string &sDescription, int nVerboseness)
Name: CIccTagMultiLocalizedUnicode::Describe.
virtual bool Read(icUInt32Number size, CIccIO *pIO)
Name: CIccTagMultiLocalizedUnicode::Read.
virtual bool Write(CIccIO *pIO)
Name: CIccTagMultiLocalizedUnicode::Write.
Class: CIccTagProfileSequenceId.
virtual void Describe(std::string &sDescription, int nVerboseness)
Name: CIccTagProfileSequenceId::Describe.
CIccProfileIdDesc * GetFirst()
Name: sampleICC::CIccTagProfileSequenceId::GetFirst.
bool AddProfileDescription(CIccProfile &profile)
CIccProfileIdDesc * GetLast()
Name: sampleICC::CIccTagProfileSequenceId::GetLast.
virtual bool Write(CIccIO *pIO)
Name: CIccTagProfileSequenceId::Write.
CIccTagProfileSequenceId()
Name: CIccTagProfileSequenceId::CIccTagProfileSequenceId.
static CIccTagProfileSequenceId * ParseMem(icUInt8Number *pMem, icUInt32Number size)
Name: CIccTagProfileSequenceId::ParseMem.
virtual ~CIccTagProfileSequenceId()
Name: CIccTagProfileSequenceId::~CIccTagProfileSequenceId.
virtual icValidateStatus Validate(std::string sigPath, std::string &sReport, const CIccProfile *pProfile=NULL) const
Name: CIccTagProfileSequenceId::Validate.
CIccTagProfileSequenceId & operator=(const CIccTagProfileSequenceId &lut)
Name: &operator=.
virtual icTagTypeSignature GetType() const
Function: GetType()
CIccProfileIdDescList * m_list
virtual bool Read(icUInt32Number size, CIccIO *pIO)
Name: CIccTagProfileSequenceId::Read.
Class: CIccTagTextDescription()
const icChar * GetText() const
Class: CIccTagText()
const icChar * GetText() const
unsigned char icUInt8Number
Number definitions.
@ icSigMultiLocalizedUnicodeType
@ icSigTextDescriptionType
@ icSigTextType
icUInt32Number icUInt64Number[2]
@ icSigProfileDescriptionTag
icUInt32Number offset
icUInt32Number size
Profile ID.
icUInt8Number ID8[16]