Hoyt's FORK of DemoIccMAX 2.1.17.hoyt
Documentation for Hoyt's FORK of DemoIccMAX
Loading...
Searching...
No Matches
IccTagEmbedIcc.cpp
Go to the documentation of this file.
1/** @file
2File: IccTagEmbedIcc.cpp
3
4Contains: Implementation of the CIccTagEmbedProfile class
5
6Version: V1
7
8Copyright: ? see ICC Software License
9*/
10
11/*
12* The ICC Software License, Version 0.2
13*
14*
15* Copyright (c) 2003-2018 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 5-15-2003
68//
69//////////////////////////////////////////////////////////////////////
70
71#ifdef WIN32
72#pragma warning( disable: 4786) //disable warning in <list.h>
73#include <windows.h>
74#endif
75#include <stdio.h>
76#include <math.h>
77#include <string.h>
78#include <stdlib.h>
79#include "IccTagEmbedIcc.h"
80#include "IccUtil.h"
81#include "IccProfile.h"
82#include "IccTagFactory.h"
83#include "IccIO.h"
84
85/**
86****************************************************************************
87* Name: CIccTagEmbedProfile::CIccTagEmbedProfile
88*
89* Purpose: Constructor
90*
91*****************************************************************************
92*/
97
98/**
99****************************************************************************
100* Name: CIccTagEmbedProfile::CIccTagEmbedProfile
101*
102* Purpose: Copy Constructor
103*
104* Args:
105* ITU = The CIccTagEmbedProfile object to be copied
106*****************************************************************************
107*/
109{
110 if (ITEP.m_pProfile) {
111 m_pProfile = ITEP.m_pProfile->NewCopy();
112 }
113 else
114 m_pProfile = NULL;
115}
116
117/**
118****************************************************************************
119* Name: CIccTagEmbedProfile::operator=
120*
121* Purpose: Copy Operator
122*
123* Args:
124* UnknownTag = The CIccTagEmbedProfile object to be copied
125*****************************************************************************
126*/
128{
129 if (&ITEP == this)
130 return *this;
131
132 if (m_pProfile)
133 delete m_pProfile;
134
135 if (ITEP.m_pProfile)
136 m_pProfile = ITEP.m_pProfile->NewCopy();
137 else
138 m_pProfile = NULL;
139
140 return *this;
141}
142
143/**
144****************************************************************************
145* Name: CIccTagEmbedProfile::~CIccTagEmbedProfile
146*
147* Purpose: Destructor
148*****************************************************************************
149*/
155
156
157/**
158****************************************************************************
159* Name: CIccTagEmbedProfile::Read
160*
161* Purpose: Read in an unknown tag type into a data block
162*
163* Args:
164* size - # of bytes in tag,
165* pIO - IO object to read tag from
166* pProfile - pProfile object calling read
167*
168* Return:
169* true = successful, false = failure
170*****************************************************************************
171*/
172bool CIccTagEmbeddedProfile::Read(icUInt32Number size, CIccIO *pIO, CIccProfile *pProfile)
173{
174 if (size<sizeof(icTagTypeSignature) || !pIO) {
175 return false;
176 }
177
178 icTagTypeSignature nType;
179
180 if (!pIO->Read32(&nType))
181 return false;
182
183 if (nType != GetType())
184 return false;
185
186 size = size - sizeof(icTagTypeSignature);
187
188 if (size < sizeof(m_nReserved))
189 return false;
190
191 if (!pIO->Read32(&m_nReserved))
192 return false;
193
194 size = size - sizeof(m_nReserved);
195
196 CIccEmbedIO *pEmbedIO = new CIccEmbedIO();
197
198 if (!pEmbedIO->Attach(pIO, size)) {
199 delete pEmbedIO;
200 return false;
201 }
202
203 if (m_pProfile)
204 delete m_pProfile;
205
206 m_pProfile = pProfile ? pProfile->NewProfile() : new CIccProfile();
207
208 if (pProfile && pProfile->HasIO()) {
209 if (!m_pProfile->Attach(pEmbedIO)) {
210 delete pEmbedIO;
211 delete m_pProfile;
212 m_pProfile = NULL;
213
214 return false;
215 }
216 }
217 else {
218 bool stat = m_pProfile->Read(pEmbedIO);
219 delete pEmbedIO;
220
221 if (!stat) {
222 delete m_pProfile;
223 m_pProfile = NULL;
224
225 return false;
226 }
227
228 return stat;
229 }
230
231 return true;
232}
233
234/**
235****************************************************************************
236* Name: CIccTagEmbedProfile::ReadAll
237*
238* Purpose: Read all tags associated with the embedded profile
239*
240*
241* Return:
242* true = successful, false = failure
243*****************************************************************************
244*/
246{
247 if (!m_pProfile)
248 return true;
249
250 return m_pProfile->ReadTags(m_pProfile);
251}
252
253
254/**
255****************************************************************************
256* Name: CIccTagEmbedProfile::Write
257*
258* Purpose: Write an unknown tag to a file
259*
260* Args:
261* pIO - The IO object to write tag to.
262*
263* Return:
264* true = succesful, false = failure
265*****************************************************************************
266*/
268{
269 if (!pIO)
270 return false;
271
272 icTagTypeSignature nType = GetType();
273
274 if (!pIO->Write32(&nType))
275 return false;
276
277 if (!pIO->Write32(&m_nReserved))
278 return false;
279
280
281 if (m_pProfile) {
282 CIccEmbedIO embedIO;
283 if (!embedIO.Attach(pIO))
284 return false;
285
286 icProfileIDSaveMethod bWriteId = (m_pProfile->m_Header.profileID.ID32[0] ||
287 m_pProfile->m_Header.profileID.ID32[1] ||
288 m_pProfile->m_Header.profileID.ID32[2] ||
289 m_pProfile->m_Header.profileID.ID32[3]) ? icAlwaysWriteID : icVersionBasedID;
290 bool rv = m_pProfile->Write(&embedIO, bWriteId);
291 return rv;
292 }
293
294 return true;
295}
296
297
298/**
299****************************************************************************
300* Name: CIccTagEmbedProfile::Describe
301*
302* Purpose: Dump data associated with unknown tag to a string
303*
304* Args:
305* sDescription - string to concatenate tag dump to
306*****************************************************************************
307*/
308void CIccTagEmbeddedProfile::Describe(std::string &sDescription, int nVerboseness)
309{
310 if (m_pProfile) {
311 sDescription += "Embedded profile in Tag\n";
312
313 // Code below is copied from iccDumpProfile.cpp
314 icHeader* pHdr = &m_pProfile->m_Header;
315 CIccInfo Fmt;
316 char buf[180];
317
318 if (Fmt.IsProfileIDCalculated(&pHdr->profileID)) {
319 sDescription += "Profile ID: %s\n";
320 sDescription += Fmt.GetProfileID(&pHdr->profileID);
321 }
322 else
323 sDescription += "Profile ID: Profile ID not calculated.\n";
324 sDescription += "Size: ";
325 sprintf(buf, "%d(0x%x) bytes\n", pHdr->size, pHdr->size);
326 sDescription += buf;
327 sDescription += "\nHeader\n";
328 sDescription += "------\n";
329 sprintf(buf, "Attributes: %s\n", Fmt.GetDeviceAttrName(pHdr->attributes));
330 sDescription += buf;
331 sprintf(buf, "Cmm: %s\n", Fmt.GetCmmSigName((icCmmSignature)(pHdr->cmmId)));
332 sDescription += buf;
333 sprintf(buf, "Creation Date: %d/%d/%d %02u:%02u:%02u\n",
334 pHdr->date.month, pHdr->date.day, pHdr->date.year,
335 pHdr->date.hours, pHdr->date.minutes, pHdr->date.seconds);
336 sDescription += buf;
337 sprintf(buf, "Creator: %s\n", icGetSig(buf, pHdr->creator));
338 sDescription += buf;
339 sprintf(buf, "Data Color Space: %s\n", Fmt.GetColorSpaceSigName(pHdr->colorSpace));
340 sDescription += buf;
341 sprintf(buf, "Flags %s\n", Fmt.GetProfileFlagsName(pHdr->flags));
342 sDescription += buf;
343 sprintf(buf, "PCS Color Space: %s\n", Fmt.GetColorSpaceSigName(pHdr->pcs));
344 sDescription += buf;
345 sprintf(buf, "Platform: %s\n", Fmt.GetPlatformSigName(pHdr->platform));
346 sDescription += buf;
347 sprintf(buf, "Rendering Intent: %s\n", Fmt.GetRenderingIntentName((icRenderingIntent)(pHdr->renderingIntent)));
348 sDescription += buf;
349 sprintf(buf, "Profile Class: %s\n", Fmt.GetProfileClassSigName(pHdr->deviceClass));
350 sDescription += buf;
351 if (pHdr->deviceSubClass) {
352 sprintf(buf, "Profile SubClass: %s\n", icGetSig(buf, pHdr->deviceSubClass));
353 sDescription += buf;
354 }
355 else
356 sDescription += "Profile SubClass: Not Defined\n";
357 sprintf(buf, "Version: %s\n", Fmt.GetVersionName(pHdr->version));
358 sDescription += buf;
359 if (pHdr->version >= icVersionNumberV5 && pHdr->deviceSubClass) {
360 sprintf(buf, "SubClass Version: %s\n", Fmt.GetSubClassVersionName(pHdr->version));
361 sDescription += buf;
362 }
363 sprintf(buf, "Illuminant: X=%.4lf, Y=%.4lf, Z=%.4lf\n",
364 icFtoD(pHdr->illuminant.X),
365 icFtoD(pHdr->illuminant.Y),
366 icFtoD(pHdr->illuminant.Z));
367 sDescription += buf;
368 sprintf(buf, "Spectral PCS: %s\n", Fmt.GetSpectralColorSigName(pHdr->spectralPCS));
369 sDescription += buf;
370 if (pHdr->spectralRange.start || pHdr->spectralRange.end || pHdr->spectralRange.steps) {
371 sprintf(buf, "Spectral PCS Range: start=%.1fnm, end=%.1fnm, steps=%d\n",
374 pHdr->spectralRange.steps);
375 sDescription += buf;
376 }
377 else {
378 sDescription += "Spectral PCS Range: Not Defined\n";
379 }
380
381 if (pHdr->biSpectralRange.start || pHdr->biSpectralRange.end || pHdr->biSpectralRange.steps) {
382 sprintf(buf, "BiSpectral Range: start=%.1fnm, end=%.1fnm, steps=%d\n",
385 pHdr->biSpectralRange.steps);
386 sDescription += buf;
387 }
388 else {
389 sDescription += "BiSpectral Range: Not Defined\n";
390 }
391 if (pHdr->mcs) {
392 sprintf(buf, "MCS Color Space: %s\n", Fmt.GetColorSpaceSigName((icColorSpaceSignature)pHdr->mcs));
393 sDescription += buf;
394 }
395 else {
396 sDescription += "MCS Color Space: Not Defined\n";
397 }
398
399 sDescription += "\nProfile Tags\n";
400 sDescription += "------------\n";
401
402 sprintf(buf, "%28s ID %8s\t%8s\t%8s\n", "Tag", "Offset", "Size", "Pad");
403 sDescription += buf;
404 sprintf(buf, "%28s ------ %8s\t%8s\t%8s\n", "----", "------", "----", "---");
405 sDescription += buf;
406
407 int n, closest, pad;
408 TagEntryList::iterator i, j;
409
410 // n is number of Tags in Tag Table
411 for (n = 0, i = m_pProfile->m_Tags->begin(); i != m_pProfile->m_Tags->end(); i++, n++) {
412 // Find closest tag after this tag, by scanning all offsets of other tags
413 closest = pHdr->size;
414 for (j = m_pProfile->m_Tags->begin(); j != m_pProfile->m_Tags->end(); j++) {
415 if ((i != j) && (j->TagInfo.offset >= i->TagInfo.offset + i->TagInfo.size) && ((int)j->TagInfo.offset <= closest)) {
416 closest = j->TagInfo.offset;
417 }
418 }
419 // Number of actual padding bytes between this tag and closest neighbour (or EOF)
420 // Should be 0-3 if compliant. Negative number if tags overlap!
421 pad = closest - i->TagInfo.offset - i->TagInfo.size;
422
423 sprintf(buf, "%28s %s %8d\t%8d\t%8d\n", Fmt.GetTagSigName(i->TagInfo.sig),
424 icGetSig(buf, i->TagInfo.sig, false), i->TagInfo.offset, i->TagInfo.size, pad);
425 sDescription += buf;
426 }
427 }
428 else {
429 sDescription += "No profile embedded in Tag\n";
430 }
431}
432
433/**
434******************************************************************************
435* Name: CIccTagEmbedProfile::Validate
436*
437* Purpose: Check tag data validity. In base class we only look at the
438* tag's reserved data value
439*
440* Args:
441* sig = signature of tag being validated,
442* sReport = String to add report information to
443*
444* Return:
445* icValidateStatusOK if valid, or other error status.
446******************************************************************************
447*/
448icValidateStatus CIccTagEmbeddedProfile::Validate(std::string sigPath, std::string &sReport, const CIccProfile* pProfile/*=NULL*/) const
449{
450 icValidateStatus rv = CIccTag::Validate(sigPath, sReport, pProfile);
451
452 CIccInfo Info;
453
454 if (!m_pProfile) {
455 sReport += icMsgValidateWarning;
456 sReport += Info.GetSigPathName(sigPath);
457 sReport += " - No Profile defined for embedded profile tag.\n";
458
460 return rv;
461 }
462
463 rv = icMaxStatus(rv, m_pProfile->Validate(sReport, sigPath));
464
465 if (pProfile) {
466 if (m_pProfile->m_Header.colorSpace != pProfile->m_Header.colorSpace) {
468 sReport += Info.GetSigPathName(sigPath);
469 sReport += " - color space does not match for embedded profile.\n";
470
472 }
473 if (m_pProfile->m_Header.deviceClass != pProfile->m_Header.deviceClass) {
475 sReport += Info.GetSigPathName(sigPath);
476 sReport += " - device class does not match for embedded profile.\n";
477
479 }
480 }
481
482 return rv;
483}
icValidateStatus
Definition IccDefs.h:118
@ icValidateWarning
Definition IccDefs.h:120
@ icValidateCriticalError
Definition IccDefs.h:122
File: IccIO.h.
File: IccProfile.h.
File: IccTagEmbedIcc.h.
File: IccTagFactory.h.
icValidateStatus icMaxStatus(icValidateStatus s1, icValidateStatus s2)
Name: icMaxStatus.
Definition IccUtil.cpp:244
const char * icMsgValidateWarning
Definition IccUtil.cpp:90
icFloatNumber icFtoD(icS15Fixed16Number num)
Definition IccUtil.cpp:559
const char * icMsgValidateCriticalError
Definition IccUtil.cpp:92
icFloatNumber icF16toF(icFloat16Number num)
Definition IccUtil.cpp:629
const icChar * icGetSig(icChar *pBuf, icUInt32Number nSig, bool bGetHexVal)
Definition IccUtil.cpp:1028
File: IccUtil.h.
icTagTypeSignature
unsigned int icUInt32Number
Type: Class.
Definition IccIO.h:185
bool Attach(CIccIO *pIO, icInt32Number nSize=0, bool bOwnIO=false)
Definition IccIO.cpp:519
Type: Class.
Definition IccIO.h:97
icInt32Number Write32(void *pBuf32, icInt32Number nNum=1)
Definition IccIO.cpp:152
icInt32Number Read32(void *pBuf32, icInt32Number nNum=1)
Definition IccIO.cpp:143
Type: Class.
Definition IccUtil.h:303
bool IsProfileIDCalculated(icProfileID *profileID)
Definition IccUtil.cpp:2305
const icChar * GetVersionName(icUInt32Number val)
Definition IccUtil.cpp:1428
const icChar * GetSpectralColorSigName(icSpectralColorSignature sig)
Definition IccUtil.cpp:1769
const icChar * GetCmmSigName(icCmmSignature sig)
Definition IccUtil.cpp:1874
const icChar * GetProfileClassSigName(icProfileClassSignature sig)
Definition IccUtil.cpp:1804
const icChar * GetTagSigName(icTagSignature sig)
Definition IccUtil.cpp:1495
const icChar * GetProfileFlagsName(icUInt32Number val, bool bCheckMCS=false)
Definition IccUtil.cpp:1465
const icChar * GetPlatformSigName(icPlatformSignature sig)
Definition IccUtil.cpp:1845
const icChar * GetProfileID(icProfileID *profileID)
Definition IccUtil.cpp:2293
const icChar * GetColorSpaceSigName(icColorSpaceSignature sig)
Definition IccUtil.cpp:1640
const icChar * GetDeviceAttrName(icUInt64Number val)
Definition IccUtil.cpp:1448
std::string GetSigPathName(std::string sigPath)
Definition IccUtil.cpp:1614
const icChar * GetSubClassVersionName(icUInt32Number val)
Definition IccUtil.cpp:1438
const icChar * GetRenderingIntentName(icRenderingIntent val, bool bIsV5=false)
Definition IccUtil.cpp:2091
Class: IccTagEmbeddedProfile.
CIccTagEmbeddedProfile()
Name: CIccTagEmbedProfile::CIccTagEmbedProfile.
virtual bool Write(CIccIO *pIO)
Name: CIccTagEmbedProfile::Write.
virtual icTagTypeSignature GetType() const
Function: GetType()
CIccTagEmbeddedProfile & operator=(const CIccTagEmbeddedProfile &UnknownTag)
Name: CIccTagEmbedProfile::operator=.
virtual icValidateStatus Validate(std::string sigPath, std::string &sReport, const CIccProfile *pProfile=NULL) const
Name: CIccTagEmbedProfile::Validate.
virtual bool ReadAll()
Name: CIccTagEmbedProfile::ReadAll.
virtual void Describe(std::string &sDescription, int nVerboseness)
Name: CIccTagEmbedProfile::Describe.
virtual bool Read(icUInt32Number size, CIccIO *pIO)
Function: Read(size, pIO) - Read tag from file.
virtual ~CIccTagEmbeddedProfile()
Name: CIccTagEmbedProfile::~CIccTagEmbedProfile.
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.
icColorSpaceSignature
Color Space Signatures.
#define icVersionNumberV5
icRenderingIntent
Rendering Intents, used in the profile header.
icCmmSignature
CMM signatures from the signature registry (as of Mar 6, 2018)
icUInt16Number year
icUInt16Number month
icUInt16Number minutes
icUInt16Number seconds
icUInt16Number hours
icUInt16Number day
The Profile header.
icSpectralRange spectralRange
icXYZNumber illuminant
icUInt32Number renderingIntent
icUInt64Number attributes
icColorSpaceSignature colorSpace
icProfileClassSignature deviceClass
icSignature deviceSubClass
icSignature cmmId
icSpectralColorSignature spectralPCS
icDateTimeNumber date
icPlatformSignature platform
icSignature creator
icUInt32Number flags
icUInt32Number version
icMaterialColorSignature mcs
icProfileID profileID
icUInt32Number size
icSpectralRange biSpectralRange
icColorSpaceSignature pcs
icUInt16Number steps
icFloat16Number start
icFloat16Number end
icS15Fixed16Number Y
icS15Fixed16Number Z
icS15Fixed16Number X