3328{
3330
3331 int nPrecision = 2;
3333 nPrecision = 1;
3334
3337
3338 pCLUT =
new CIccCLUT(nInput, nOutput, nPrecision);
3339
3340 if (!pCLUT){
3341 parseStr += "Error in creating CLUT Table. Check values of Precision, InputChannel, or OutputChannels.\n";
3342 return NULL;
3343 }
3344
3345 xmlNode *grid =
icXmlFindNode(pNode->children,
"GridPoints");
3346 if (grid) {
3348
3351 parseStr += "Error in setting the size of GridPoints. Check values of GridPoints, InputChannel, or OutputChannels.\n";
3352 delete pCLUT;
3353 return NULL;
3354 }
3355 }
3356 else {
3357 parseStr += "Error parsing GridPoints.\n";
3358 delete pCLUT;
3359 return NULL;
3360 }
3361 }
3362 else {
3364
3365 xmlAttr *gridGranularity =
icXmlFindAttr(pNode,
"GridGranularity");
3366
3367 if (gridGranularity) {
3369 }
3370 else {
3371 delete pCLUT;
3372 return NULL;
3373 }
3374 if (!pCLUT->
Init(nGridGranularity)) {
3375 parseStr += "Error in setting the size of GridGranularity. Check values of GridGranularity, InputChannel, or OutputChannels.\n";
3376 delete pCLUT;
3377 return NULL;
3378 }
3379 }
3380
3381 xmlNode *table =
icXmlFindNode(pNode->children,
"TableData");
3382
3383 if (table) {
3386 if (precision && atoi(precision) == 1) {
3389 }
3390 else {
3393 }
3394 }
3395
3397 if (!filename || !filename[0]) {
3399 }
3400
3401 if (filename[0]) {
3403
3404 if (!file) {
3405
3406 parseStr += "Error! - File '";
3407 parseStr += filename;
3408 parseStr +="' not found.\n";
3409 delete pCLUT;
3410 return NULL;
3411 }
3412
3414
3415 if (!strcmp(format, "text")) {
3417 char *buf = (char *)malloc(num);
3418
3419 if (!buf) {
3420 perror("Memory Error");
3421 parseStr += "'";
3422 parseStr += filename;
3423 parseStr += "' may not be a valid text file.\n";
3424 delete file;
3425 delete pCLUT;
3426 return NULL;
3427 }
3428
3429
3431
3432 if (!strcmp(encoding, "int8"))
3434 else if (!strcmp(encoding, "int16"))
3436 else if (!strcmp(encoding, "float"))
3438 else if (encoding[0]) {
3439 parseStr+= "Unknown encoding \"";
3440 parseStr+= encoding;
3441 parseStr+= "\" - using default encoding\n";
3442 }
3443
3444 if (file->
Read8(buf, num)!=num) {
3445 perror("Read-File Error");
3446 parseStr += "'";
3447 parseStr += filename;
3448 parseStr += "' may not be a valid text file.\n";
3449 free(buf);
3450 delete file;
3451 delete pCLUT;
3452 return NULL;
3453 }
3454
3457
3459 parseStr += "File '";
3460 parseStr += filename;
3461 parseStr += "' is not a valid text file.\n";
3462 free(buf);
3463 delete file;
3464 delete pCLUT;
3465 return NULL;
3466 }
3467
3469 parseStr += "Error! - Number of entries in file '";
3470 parseStr += filename;
3471 parseStr += "'is not equal to the size of the CLUT Table.\n";
3472 parseStr += " a. Check values of GridGranularity/GridPoints, InputChannel, or OutputChannels.\n";
3473 parseStr += " b. File may not be a valid text file.\n";
3474 free(buf);
3475 delete file;
3476 delete pCLUT;
3477 return NULL;
3478 }
3481
3483 for (i=0; i<data.
GetSize(); i++) {
3485 }
3486 }
3489
3491 parseStr += "File '";
3492 parseStr += filename;
3493 parseStr += "' is not a valid text file.\n";
3494 free(buf);
3495 delete file;
3496 delete pCLUT;
3497 return NULL;
3498 }
3499
3501 parseStr += "Error! - Number of entries in file '";
3502 parseStr += filename;
3503 parseStr += "'is not equal to the size of the CLUT Table.\n";
3504 parseStr += " a. Check values of GridGranularity/GridPoints, InputChannel, or OutputChannels.\n";
3505 parseStr += " b. File may not be a valid text file.\n";
3506 free(buf);
3507 delete file;
3508 delete pCLUT;
3509 return NULL;
3510 }
3513
3515 for (i=0; i<data.
GetSize(); i++) {
3517 }
3518 }
3521
3523 parseStr += "File '";
3524 parseStr += filename;
3525 parseStr += "' is not a valid text file.\n";
3526 free(buf);
3527 delete file;
3528 delete pCLUT;
3529 return NULL;
3530 }
3531
3533 parseStr += "Error! - Number of entries in file '";
3534 parseStr += filename;
3535 parseStr += "'is not equal to the size of the CLUT Table.\n";
3536 parseStr += " a. Check values of GridGranularity/GridPoints, InputChannel, or OutputChannels.\n";
3537 parseStr += " b. File may not be a valid text file.\n";
3538 free(buf);
3539 delete file;
3540 delete pCLUT;
3541 return NULL;
3542 }
3545
3547 for (i=0; i<data.
GetSize(); i++) {
3548 *dst++ = *src++;
3549 }
3550 }
3551 else {
3552 parseStr += "Error! Unknown text data type.\n";
3553 free(buf);
3554 delete file;
3555 delete pCLUT;
3556 return NULL;
3557 }
3558 free(buf);
3559 }
3560 else if (!strcmp(format, "binary")) {
3562 bool little_endian = !strcmp(order, "little");
3563
3565
3567
3568 if (!strcmp(encoding, "int8"))
3570 else if (!strcmp(encoding, "int16"))
3572 else if (!strcmp(encoding, "float"))
3574 else if (encoding[0]) {
3575 parseStr+= "Unknown encoding \"";
3576 parseStr+= encoding;
3577 parseStr+= "\" - using int16.\n";
3579 }
3580 else {
3581 parseStr+= "CLUT TableData Encoding type not specified.\n";
3582 }
3583 }
3584
3588
3590 parseStr += "Error! - Number of entries in file '";
3591 parseStr += filename;
3592 parseStr += "'is not equal to the size of the CLUT Table.\n";
3593 parseStr += " a. Check values of GridGranularity/GridPoints, InputChannel, or OutputChannels.\n";
3594 parseStr += " b. File may not be a valid binary file.\n";
3595 delete file;
3596 delete pCLUT;
3597 return NULL;
3598 }
3601 for (i=0; i<num; i++) {
3602 if (!file->
Read8(&value)) {
3603 perror("Read-File Error");
3604 parseStr += "'";
3605 parseStr += filename;
3606 parseStr += "' may not be a valid binary file.\n";
3607 delete file;
3608 delete pCLUT;
3609 return NULL;
3610 }
3612 }
3613 }
3618
3620 parseStr += "Error! - Number of entries in file '";
3621 parseStr += filename;
3622 parseStr += "'is not equal to the size of the CLUT Table.\n";
3623 parseStr += " a. Check values of GridGranularity/GridPoints, InputChannel, or OutputChannels.\n";
3624 parseStr += " b. File may not be a valid binary file.\n";
3625 delete file;
3626 delete pCLUT;
3627 return NULL;
3628 }
3630
3632 for (i=0; i<num; i++) {
3633 if (!file->
Read16(&value)) {
3634 perror("Read-File Error");
3635 parseStr += "'";
3636 parseStr += filename;
3637 parseStr += "' may not be a valid binary file.\n";
3638 delete file;
3639 delete pCLUT;
3640 return NULL;
3641 }
3642#ifdef ICC_BYTE_ORDER_LITTLE_ENDIAN
3643 if (little_endian) {
3644#else
3645 if (!little_endian) {
3646#endif
3648 ptr[0] = ptr[1];
3649 ptr[1] = t;
3650 }
3652 }
3653 }
3658
3660 parseStr += "Error! - Number of entries in file '";
3661 parseStr += filename;
3662 parseStr += "'is not equal to the size of the CLUT Table.\n";
3663 parseStr += " a. Check values of GridGranularity/GridPoints, InputChannel, or OutputChannels.\n";
3664 parseStr += " b. File may not be a valid binary file.\n";
3665 delete file;
3666 delete pCLUT;
3667 return NULL;
3668 }
3670
3672 for (i=0; i<num; i++) {
3674 perror("Read-File Error");
3675 parseStr += "'";
3676 parseStr += filename;
3677 parseStr += "' may not be a valid binary file.\n";
3678 delete file;
3679 delete pCLUT;
3680 return NULL;
3681 }
3682#ifdef ICC_BYTE_ORDER_LITTLE_ENDIAN
3683 if (little_endian) {
3684#else
3685 if (!little_endian) {
3686#endif
3688 tmp = ptr[0]; ptr[0] = ptr[3]; ptr[3] = tmp;
3689 tmp = ptr[1]; ptr[1] = ptr[2]; ptr[2] = tmp;
3690 }
3691 *dst++ = value;
3692 }
3693 }
3694 else {
3695 parseStr += "Error! Unknown binary data type.\n";
3696 delete file;
3697 delete pCLUT;
3698 return NULL;
3699 }
3700
3701 }
3702 else {
3703 parseStr += "Error! Unknown Format type.\n";
3704 delete pCLUT;
3705 return NULL;
3706 }
3707
3708 delete file;
3709 }
3710 else {
3713
3715 parseStr += "Error! - unable to parse data in CLUT.\n";
3716 delete pCLUT;
3717 return NULL;
3718 }
3719
3721 parseStr += "Error! - Number of entries is not equal to the size of the CLUT Table.\n";
3722 delete pCLUT;
3723 return NULL;
3724 }
3727
3729 for (i=0; i<data.
GetSize(); i++) {
3731 }
3732 }
3735
3737 parseStr += "Error! - unable to parse data in CLUT.\n";
3738 delete pCLUT;
3739 return NULL;
3740 }
3741
3743 parseStr += "Error! - Number of entries is not equal to the size of the CLUT Table.\n";
3744 delete pCLUT;
3745 return NULL;
3746 }
3749
3751 for (i=0; i<data.
GetSize(); i++) {
3753 }
3754 }
3757
3759 parseStr += "Error! - unable to parse data in CLUT.\n";
3760 delete pCLUT;
3761 return NULL;
3762 }
3763
3765 parseStr += "Error! - Number of entries is not equal to the size of the CLUT Table.\n";
3766 delete pCLUT;
3767 return NULL;
3768 }
3771
3773 for (i=0; i<data.
GetSize(); i++) {
3774 *dst++ = *src++;
3775 }
3776 }
3777 else {
3778 parseStr += "Error! Unknown table data type.";
3779 delete pCLUT;
3780 return NULL;
3781 }
3782 }
3783 }
3784 else {
3785 parseStr += "Error! Cannot find table data.";
3786 delete pCLUT;
3787 return NULL;
3788 }
3789
3790 return pCLUT;
3791}
unsigned char icUInt8Number
Definition icProfileHeader.h:250
float icFloat32Number
Definition icProfileHeader.h:313
unsigned short icUInt16Number
Definition icProfileHeader.h:256
unsigned long icUInt32Number
Definition icProfileHeader.h:262
float icFloatNumber
Definition IccDefs.h:101
@ icConvert8Bit
Definition IccXmlConfig.h:68
@ icConvertFloat
Definition IccXmlConfig.h:70
@ icConvert16Bit
Definition IccXmlConfig.h:69
@ icConvertVariable
Definition IccXmlConfig.h:71
xmlAttr * icXmlFindAttr(xmlNode *pNode, const char *szAttrName)
Definition IccUtilXml.cpp:669
xmlNode * icXmlFindNode(xmlNode *pNode, const char *szNodeName)
Definition IccUtilXml.cpp:687
const char * icXmlAttrValue(xmlAttr *attr, const char *szDefault="")
Definition IccUtilXml.cpp:572
CIccIO * IccOpenFileIO(const icChar *szFilename, const char *szAttr)
Definition IccIoXml.cpp:100
icInt32Number ReadFloat32Float(void *pBufFloat, icInt32Number nNum=1)
Definition IccIO.cpp:302
virtual icInt32Number GetLength()
Definition IccIO.h:130
virtual icInt32Number Read8(void *pBuf8, icInt32Number nNum=1)
Definition IccIO.h:104
icInt32Number Read16(void *pBuf16, icInt32Number nNum=1)
Definition IccIO.cpp:114
Definition IccTagLut.h:326
icUInt16Number GetOutputChannels() const
Definition IccTagLut.h:357
icUInt32Number NumPoints() const
Definition IccTagLut.h:348
void SetPrecision(icUInt8Number nPrecision)
Definition IccTagLut.h:382
icFloatNumber * GetData(int index)
Definition IccTagLut.h:347
bool Init(icUInt8Number nGridPoints, icUInt32Number nMaxSize=0, icUInt8Number nBytesPerPoint=4)
Definition IccTagLut.cpp:1806
Definition IccUtilXml.h:145
static bool ParseArray(T *buf, icUInt32Number nBufSize, xmlNode *pNode)
Definition IccUtilXml.cpp:1034
bool ParseTextArrayNum(const char *szText, icUInt32Number num, std::string &parseStr)
Definition IccUtilXml.cpp:807
T * GetBuf()
Definition IccUtilXml.h:165
icUInt32Number GetSize()
Definition IccUtilXml.h:166