IccMAX 2.1.27
Color Profile Tools
Loading...
Searching...
No Matches
IccProfile.cpp File Reference
#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)
 
bool CalcProfileID (const icChar *szFilename, icProfileID *pProfileID)
 
static bool compare_float (double x, double y, double eps=0.0000001f)
 
static bool compare_float (float x, float y, float eps=0.01f)
 
CIccProfileOpenIccProfile (const icChar *szFilename, bool bUseSubProfile)
 
CIccProfileOpenIccProfile (const icUInt8Number *pMem, icUInt32Number nSize, bool bUseSubProfile)
 
CIccProfileReadIccProfile (const icChar *szFilename, bool bUseSubProfile)
 
CIccProfileReadIccProfile (const icUInt8Number *pMem, icUInt32Number nSize, bool bUseSubProfile)
 
bool SaveIccProfile (const icChar *szFilename, CIccProfile *pIcc, icProfileIDSaveMethod nWriteId)
 
bool SaveIccProfile (FILE *f, CIccProfile *pIcc, icProfileIDSaveMethod nWriteId)
 
CIccProfileValidateIccProfile (CIccIO *pIO, std::string &sReport, icValidateStatus &nStatus)
 
CIccProfileValidateIccProfile (const icChar *szFilename, std::string &sReport, icValidateStatus &nStatus)
 
CIccProfileValidateIccProfile (const icUInt8Number *pMem, icUInt32Number nSize, std::string &sReport, icValidateStatus &nStatus)
 

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

3778{
3779 icUInt32Number len, num, nBlock, pos;
3781 icUInt8Number buffer[1024] = {0};
3782
3783 //remember where we are
3784 pos = pIO->Tell();
3785
3786 //Get length and set up to read entire file
3787 len = pIO->GetLength();
3788 pIO->Seek(0, icSeekSet);
3789
3790 //read file updating checksum as we go
3792 nBlock = 0;
3793 while(len) {
3794 num = pIO->Read8(&buffer[0],1024);
3795 if (!nBlock) { // Zero out 3 header contents in Profile ID calculation
3796 memset(buffer+44, 0, 4); //Profile flags
3797 memset(buffer+64, 0, 4); //Rendering Intent
3798 memset(buffer+84, 0, 16); //Profile Id
3799 }
3800 icMD5Update(&context,buffer,num);
3801 nBlock++;
3802 len -=num;
3803 }
3804 icMD5Final(&pProfileID->ID8[0],&context);
3805
3806 //go back where we were
3807 pIO->Seek(pos, icSeekSet);
3808}
unsigned char icUInt8Number
Definition icProfileHeader.h:250
unsigned long icUInt32Number
Definition icProfileHeader.h:262
icUInt8Number ID8[16]
Definition icProfileHeader.h:2037
@ icSeekSet
Definition IccIO.h:83
Definition IccMD5.h:52
void ICCPROFLIB_API icMD5Update(MD5_CTX *context, unsigned char *input, unsigned int inputLen)
Definition IccMD5.cpp:114
void ICCPROFLIB_API icMD5Final(unsigned char *digest, MD5_CTX *context)
Definition IccMD5.cpp:150
void ICCPROFLIB_API icMD5Init(MD5_CTX *context)
Definition IccMD5.cpp:99
static const CFAllocatorContext context
Definition RefIccMAXCmm.cpp:1188
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

References 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

3822{
3823 CIccFileIO FileIO;
3824
3825 if (!FileIO.Open(szFilename, "rb")) {
3826 memset(pProfileID, 0, sizeof(icProfileID));
3827 return false;
3828 }
3829
3830 CalcProfileID(&FileIO, pProfileID);
3831 return true;
3832}
Definition icProfileHeader.h:2036
void CalcProfileID(CIccIO *pIO, icProfileID *pProfileID)
Definition IccProfile.cpp:3777
Definition IccIO.h:150
bool Open(const icChar *szFilename, const icChar *szAttr)
Definition IccIO.cpp:382

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
1334 {
1335 return (fabs(x-y)<eps);
1336}

◆ compare_float() [2/2]

static bool compare_float ( float  x,
float  y,
float  eps = 0.01f 
)
inlinestatic
1330 {
1331 return (fabsf(x-y)<eps);
1332}

◆ 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

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

References CIccProfile, and CIccFileIO::Open().

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

+ 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 bUseSubProfile = flag to indicate that to use embedded subprofile

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

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

References CIccMemIO::Attach(), and CIccProfile.

Referenced by main(), and PrintIccProfileInfo().

+ Here is the call graph for this function:
+ Here is the caller 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

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

References CIccProfile, and CIccFileIO::Open().

Referenced by CIccPRMG::EvaluateProfile(), CIccEvalCompare::EvaluateProfile(), 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

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

References CIccMemIO::CIccMemIO(), CIccMemIO::Attach(), and CIccProfile.

+ 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

3682{
3683 CIccFileIO FileIO;
3684
3685 if (!pIcc)
3686 return false;
3687
3688 if (!FileIO.Open(szFilename, "w+b")) {
3689 return false;
3690 }
3691
3692 if (!pIcc->Write(&FileIO, nWriteId)) {
3693 return false;
3694 }
3695
3696 return true;
3697}

References CIccFileIO::Open().

Referenced by 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

3713{
3714 CIccFileIO FileIO;
3715
3716 if (!pIcc)
3717 return false;
3718
3719 if (!FileIO.Attach(f)) {
3720 return false;
3721 }
3722
3723 if (!pIcc->Write(&FileIO, nWriteId)) {
3724 return false;
3725 }
3726
3727 FileIO.Detach();
3728
3729 return true;
3730}
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/3]

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

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

References CIccProfile, icMsgValidateCriticalError, and icValidateCriticalError.

◆ ValidateIccProfile() [2/3]

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

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

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

Referenced by main().

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

◆ ValidateIccProfile() [3/3]

CIccProfile * ValidateIccProfile ( const icUInt8Number pMem,
icUInt32Number  nSize,
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: pMem = pointer to memory containing profile data nSize = size of memory related to profile sReport - std::string to put report into nStatus - return status value

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

3635{
3636 CIccMemIO* pMemIO = new CIccMemIO;
3637
3638 if (!pMemIO->Attach((icUInt8Number*)pMem, nSize)) {
3640 sReport += " - Unable to attach IO access to memory block.";
3641 delete pMemIO;
3642 return NULL;
3643 }
3644
3645 CIccProfile* pIcc = new CIccProfile;
3646
3647 if (!pIcc) {
3648 delete pMemIO;
3649 return NULL;
3650 }
3651
3652 nStatus = pIcc->ReadValidate(pMemIO, sReport);
3653
3654 if (nStatus >= icValidateCriticalError) {
3655 delete pIcc;
3656 delete pMemIO;
3657 return NULL;
3658 }
3659
3660 delete pMemIO;
3661
3662 nStatus = icMaxStatus(nStatus, pIcc->Validate(sReport));
3663
3664 return pIcc;
3665}

References CIccMemIO::Attach(), CIccProfile, icMaxStatus(), icMsgValidateCriticalError, and icValidateCriticalError.

+ Here is the call graph for this function: