Hoyt's FORK of DemoIccMAX 2.1.17.hoyt
Documentation for Hoyt's FORK of DemoIccMAX
Loading...
Searching...
No Matches
IccProfile.cpp File Reference

File: IccProfile.cpp. More...

#include <ctime>
#include <cstring>
#include <cmath>
#include "IccProfile.h"
#include "IccTag.h"
#include "IccArrayBasic.h"
#include "IccIO.h"
#include "IccUtil.h"
#include "IccMatrixMath.h"
#include "IccMD5.h"
+ Include dependency graph for IccProfile.cpp:

Go to the source code of this file.

Functions

void CalcProfileID (CIccIO *pIO, icProfileID *pProfileID)
 Name: CalcProfileID.
 
bool CalcProfileID (const icChar *szFilename, icProfileID *pProfileID)
 Name: CalcProfileID.
 
static bool compare_float (double x, double y, double eps=0.0000001f)
 
static bool compare_float (float x, float y, float eps=0.01f)
 
CIccProfile * OpenIccProfile (const icChar *szFilename, bool bUseSubProfile)
 Name: OpenIccProfile.
 
CIccProfile * OpenIccProfile (const icUInt8Number *pMem, icUInt32Number nSize, bool bUseSubProfile)
 Name: OpenIccProfile.
 
CIccProfile * ReadIccProfile (const icChar *szFilename, bool bUseSubProfile)
 Name: ReadIccProfile.
 
CIccProfile * ReadIccProfile (const icUInt8Number *pMem, icUInt32Number nSize, bool bUseSubProfile)
 Name: ReadIccProfile.
 
bool SaveIccProfile (const icChar *szFilename, CIccProfile *pIcc, icProfileIDSaveMethod nWriteId)
 Name: SaveIccProfile.
 
bool SaveIccProfile (FILE *f, CIccProfile *pIcc, icProfileIDSaveMethod nWriteId)
 Name: SaveIccProfile.
 
CIccProfile * ValidateIccProfile (CIccIO *pIO, std::string &sReport, icValidateStatus &nStatus)
 Name: ValidateIccProfile.
 
CIccProfile * ValidateIccProfile (const icChar *szFilename, std::string &sReport, icValidateStatus &nStatus)
 Name: ValidateIccProfile.
 

Detailed Description

File: IccProfile.cpp.

Contains: Implementation of the CIccProfile class.

Version: V1

Copyright: � see ICC Software License

Definition in file IccProfile.cpp.

Function Documentation

◆ CalcProfileID() [1/2]

void CalcProfileID ( CIccIO * pIO,
icProfileID * pProfileID )

Name: CalcProfileID.

Purpose: Calculate the Profile ID using MD5 Fingerprinting method.

Args: pIO = The CIccIO object, pProfileID = array where the profileID will be stored

Definition at line 3724 of file IccProfile.cpp.

3725{
3726 icUInt32Number len, num, nBlock, pos;
3728 icUInt8Number buffer[1024] = {0};
3729
3730 //remember where we are
3731 pos = pIO->Tell();
3732
3733 //Get length and set up to read entire file
3734 len = pIO->GetLength();
3735 pIO->Seek(0, icSeekSet);
3736
3737 //read file updating checksum as we go
3739 nBlock = 0;
3740 while(len) {
3741 num = pIO->Read8(&buffer[0],1024);
3742 if (!nBlock) { // Zero out 3 header contents in Profile ID calculation
3743 memset(buffer+44, 0, 4); //Profile flags
3744 memset(buffer+64, 0, 4); //Rendering Intent
3745 memset(buffer+84, 0, 16); //Profile Id
3746 }
3747 icMD5Update(&context,buffer,num);
3748 nBlock++;
3749 len -=num;
3750 }
3751 icMD5Final(&pProfileID->ID8[0],&context);
3752
3753 //go back where we were
3754 pIO->Seek(pos, icSeekSet);
3755}
@ icSeekSet
Definition IccIO.h:83
void icMD5Init(MD5_CTX *context)
MD5 initialization.
Definition IccMD5.cpp:99
void icMD5Final(unsigned char *digest, MD5_CTX *context)
MD5 finalization.
Definition IccMD5.cpp:150
void icMD5Update(MD5_CTX *context, unsigned char *input, unsigned int inputLen)
MD5 block update operation.
Definition IccMD5.cpp:114
static const CFAllocatorContext context
unsigned int icUInt32Number
virtual icInt32Number GetLength()
Definition IccIO.h:130
virtual icInt32Number Read8(void *pBuf8, icInt32Number nNum=1)
Definition IccIO.h:104
virtual icInt32Number Tell()
Definition IccIO.h:133
virtual icInt32Number Seek(icInt32Number nOffset, icSeekVal pos)
Definition IccIO.h:132
unsigned char icUInt8Number
Number definitions.
MD5 context.
Definition IccMD5.h:52
icUInt8Number ID8[16]

References context, CIccIO::GetLength(), icMD5Final(), icMD5Init(), icMD5Update(), icSeekSet, icProfileID::ID8, CIccIO::Read8(), CIccIO::Seek(), and CIccIO::Tell().

Referenced by CalcProfileID().

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

◆ CalcProfileID() [2/2]

bool CalcProfileID ( const icChar * szFilename,
icProfileID * pProfileID )

Name: CalcProfileID.

Purpose: Calculate the Profile ID using MD5 Fingerprinting method.

Args: szFileName = name of the file whose profile ID has to be calculated, pProfileID = array where the profileID will be stored

Definition at line 3768 of file IccProfile.cpp.

3769{
3770 CIccFileIO FileIO;
3771
3772 if (!FileIO.Open(szFilename, "rb")) {
3773 memset(pProfileID, 0, sizeof(icProfileID));
3774 return false;
3775 }
3776
3777 CalcProfileID(&FileIO, pProfileID);
3778 return true;
3779}
void CalcProfileID(CIccIO *pIO, icProfileID *pProfileID)
Name: CalcProfileID.
Type: Class.
Definition IccIO.h:150
bool Open(const icChar *szFilename, const icChar *szAttr)
Definition IccIO.cpp:382
Profile ID.

References CalcProfileID(), and CIccFileIO::Open().

+ Here is the call graph for this function:

◆ compare_float() [1/2]

static bool compare_float ( double x,
double y,
double eps = 0.0000001f )
inlinestatic

Definition at line 1333 of file IccProfile.cpp.

1333 {
1334 return (fabs(x-y)<eps);
1335}

◆ compare_float() [2/2]

static bool compare_float ( float x,
float y,
float eps = 0.01f )
inlinestatic

Definition at line 1329 of file IccProfile.cpp.

1329 {
1330 return (fabsf(x-y)<eps);
1331}

◆ OpenIccProfile() [1/2]

CIccProfile * OpenIccProfile ( const icChar * szFilename,
bool bUseSubProfile )

Name: OpenIccProfile.

Purpose: Open an ICC profile file. This will only read the profile header and tag directory. Loading of actual tags will be deferred until the tags are actually referenced by FindTag().

Args: szFilename - zero terminated string with filename of ICC profile to read bUseSubProfile - will attempt to open a subprofile if present

Return: Pointer to icc profile object, or NULL on failure

Definition at line 3386 of file IccProfile.cpp.

3387{
3388 CIccFileIO *pFileIO = new CIccFileIO;
3389
3390 if (!pFileIO->Open(szFilename, "rb")) {
3391 delete pFileIO;
3392 return NULL;
3393 }
3394
3395 CIccProfile *pIcc = new CIccProfile;
3396
3397 if (!pIcc->Attach(pFileIO, bUseSubProfile)) {
3398 delete pIcc;
3399 delete pFileIO;
3400 return NULL;
3401 }
3402
3403 return pIcc;
3404}

References CIccFileIO::Open().

Referenced by CIccDefaultEncProfileCacheHandler::GetEncodingProfile(), GetProfileFromBuf(), IccProfileOpenHandle(), main(), main(), main(), main(), and MyFrame::OpenFile().

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

◆ OpenIccProfile() [2/2]

CIccProfile * OpenIccProfile ( const icUInt8Number * pMem,
icUInt32Number nSize,
bool bUseSubProfile )

Name: OpenIccProfile.

Purpose: Open an ICC profile file. This will only read the profile header and tag directory. Loading of actual tags will be deferred until the tags are actually referenced by FindTag().

Args: pMem = pointer to memory containing profile data nSize = size of memory related to profile

Return: Pointer to icc profile object, or NULL on failure

Definition at line 3460 of file IccProfile.cpp.

3461{
3462 CIccMemIO *pMemIO = new CIccMemIO;
3463
3464 if (!pMemIO->Attach((icUInt8Number*)pMem, nSize)) {
3465 delete pMemIO;
3466 return NULL;
3467 }
3468
3469 CIccProfile *pIcc = new CIccProfile;
3470
3471 if (!pIcc->Attach(pMemIO, bUseSubProfile)) {
3472 delete pIcc;
3473 delete pMemIO;
3474 return NULL;
3475 }
3476
3477 return pIcc;
3478}
Type: Class.
Definition IccIO.h:217
bool Attach(icUInt8Number *pData, icUInt32Number nSize, bool bWrite=false)
Definition IccIO.cpp:686

References CIccMemIO::Attach().

+ Here is the call graph for this function:

◆ ReadIccProfile() [1/2]

CIccProfile * ReadIccProfile ( const icChar * szFilename,
bool bUseSubProfile )

Name: ReadIccProfile.

Purpose: Read an ICC profile file.

Args: szFilename - zero terminated string with filename of ICC profile to read bUseSubProfile - will attempt to open a subprofile if present

Return: Pointer to ICC profile object, or NULL on failure

Definition at line 3273 of file IccProfile.cpp.

3274{
3275 CIccFileIO *pFileIO = new CIccFileIO;
3276
3277 if (!pFileIO->Open(szFilename, "rb")) {
3278 delete pFileIO;
3279 return NULL;
3280 }
3281
3282 CIccProfile *pIcc = new CIccProfile;
3283
3284 if (!pIcc->Read(pFileIO, bUseSubProfile)) {
3285 delete pIcc;
3286 delete pFileIO;
3287 return NULL;
3288 }
3289 delete pFileIO;
3290
3291 return pIcc;
3292}

References CIccFileIO::Open().

Referenced by CIccEvalCompare::EvaluateProfile(), CIccPRMG::EvaluateProfile(), getIccProfLibProfileFromColorsyncProfile(), IccProfileReadHandle(), main(), and main().

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

◆ ReadIccProfile() [2/2]

CIccProfile * ReadIccProfile ( const icUInt8Number * pMem,
icUInt32Number nSize,
bool bUseSubProfile )

Name: ReadIccProfile.

Purpose: Read an ICC profile file.

Args: pMem = pointer to memory containing profile data nSize = size of memory related to profile bUseSubProfile - will attempt to open a subprofile if present

Return: Pointer to icc profile object, or NULL on failure

Definition at line 3348 of file IccProfile.cpp.

3349{
3350 CIccMemIO *pMemIO = new CIccMemIO();
3351
3352 if (!pMemIO->Attach((icUInt8Number*)pMem, nSize)) {
3353 delete pMemIO;
3354 return NULL;
3355 }
3356
3357 CIccProfile *pIcc = new CIccProfile;
3358
3359 if (!pIcc->Read(pMemIO)) {
3360 delete pIcc;
3361 delete pMemIO;
3362 return NULL;
3363 }
3364 delete pMemIO;
3365
3366 return pIcc;
3367}

References CIccMemIO::Attach().

+ Here is the call graph for this function:

◆ SaveIccProfile() [1/2]

bool SaveIccProfile ( const icChar * szFilename,
CIccProfile * pIcc,
icProfileIDSaveMethod nWriteId )

Name: SaveIccProfile.

Purpose: Save an ICC profile file.

Args: szFilename - zero terminated string with filename of ICC profile to create

Return: true = success, false = failure

Definition at line 3628 of file IccProfile.cpp.

3629{
3630 CIccFileIO FileIO;
3631
3632 if (!pIcc)
3633 return false;
3634
3635 if (!FileIO.Open(szFilename, "w+b")) {
3636 return false;
3637 }
3638
3639 if (!pIcc->Write(&FileIO, nWriteId)) {
3640 return false;
3641 }
3642
3643 return true;
3644}

References CIccFileIO::Open().

Referenced by CIccDefaultEncProfileConverter::ConvertFromParams(), CDevLinkWriter::finish(), and main().

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

◆ SaveIccProfile() [2/2]

bool SaveIccProfile ( FILE * f,
CIccProfile * pIcc,
icProfileIDSaveMethod nWriteId )

Name: SaveIccProfile.

Purpose: Save an ICC profile file.

Args: f - handle to file io stream (closed outside of this function)

Return: true = success, false = failure

Definition at line 3659 of file IccProfile.cpp.

3660{
3661 CIccFileIO FileIO;
3662
3663 if (!pIcc)
3664 return false;
3665
3666 if (!FileIO.Attach(f)) {
3667 return false;
3668 }
3669
3670 if (!pIcc->Write(&FileIO, nWriteId)) {
3671 return false;
3672 }
3673
3674 FileIO.Detach();
3675
3676 return true;
3677}
void Detach()
Definition IccIO.cpp:437
bool Attach(FILE *f)
Definition IccIO.cpp:426

References CIccFileIO::Attach(), and CIccFileIO::Detach().

+ Here is the call graph for this function:

◆ ValidateIccProfile() [1/2]

CIccProfile * ValidateIccProfile ( CIccIO * pIO,
std::string & sReport,
icValidateStatus & nStatus )

Name: ValidateIccProfile.

Purpose: Open an ICC profile file. This will only read the profile header and tag directory. Loading of actual tags will be deferred until the tags are actually referenced by FindTag().

Args: pIO - Handle to IO access object (Not ValidateIccProfile assumes ownership of this object) sReport - std::string to put report into nStatus - return status value

Return: Pointer to icc profile object, or NULL on failure

Definition at line 3497 of file IccProfile.cpp.

3498{
3499 if (!pIO) {
3501 sReport += " - ";
3502 sReport += "- Invalid I/O Handle\n";
3503 delete pIO;
3504 return NULL;
3505 }
3506
3507 CIccProfile *pIcc = new CIccProfile;
3508
3509 if (!pIcc) {
3510 delete pIO;
3511 return NULL;
3512 }
3513
3514 nStatus = pIcc->ReadValidate(pIO, sReport);
3515
3516 if (nStatus>=icValidateCriticalError) {
3517 delete pIcc;
3518 delete pIO;
3519 return NULL;
3520 }
3521
3522 delete pIO;
3523
3524 nStatus = pIcc->Validate(sReport);
3525
3526 return pIcc;
3527}
@ icValidateCriticalError
Definition IccDefs.h:122
const char * icMsgValidateCriticalError
Definition IccUtil.cpp:92

References icMsgValidateCriticalError, and icValidateCriticalError.

Referenced by main(), and MyDialog::MyDialog().

+ Here is the caller graph for this function:

◆ ValidateIccProfile() [2/2]

CIccProfile * ValidateIccProfile ( const icChar * szFilename,
std::string & sReport,
icValidateStatus & nStatus )

Name: ValidateIccProfile.

Purpose: Open an ICC profile file. This will only read the profile header and tag directory. Loading of actual tags will be deferred until the tags are actually referenced by FindTag().

Args: szFilename - zero terminated string with filename of ICC profile to read sReport - std::string to put report into nStatus - return status value

Return: Pointer to icc profile object, or NULL on failure

Definition at line 3578 of file IccProfile.cpp.

3579{
3580 CIccFileIO *pFileIO = new CIccFileIO;
3581
3582 if (!pFileIO->Open(szFilename, "rb")) {
3584 sReport += " - ";
3585 sReport += szFilename;
3586 sReport += "- Invalid Filename\n";
3587 delete pFileIO;
3588 return NULL;
3589 }
3590
3591 CIccProfile *pIcc = new CIccProfile;
3592
3593 if (!pIcc) {
3594 delete pFileIO;
3595 return NULL;
3596 }
3597
3598 nStatus = pIcc->ReadValidate(pFileIO, sReport);
3599
3600 if (nStatus>=icValidateCriticalError) {
3601 delete pIcc;
3602 delete pFileIO;
3603 return NULL;
3604 }
3605
3606 delete pFileIO;
3607
3608 nStatus = icMaxStatus(nStatus, pIcc->Validate(sReport));
3609
3610 return pIcc;
3611}
icValidateStatus icMaxStatus(icValidateStatus s1, icValidateStatus s2)
Name: icMaxStatus.
Definition IccUtil.cpp:244

References icMaxStatus(), icMsgValidateCriticalError, icValidateCriticalError, and CIccFileIO::Open().

+ Here is the call graph for this function: