3316{
3318
3319 int nPrecision = 2;
3321 nPrecision = 1;
3322
3325
3326 pCLUT =
new CIccCLUT(nInput, nOutput, nPrecision);
3327
3328 if (!pCLUT){
3329 parseStr += "Error in creating CLUT Table. Check values of Precision, InputChannel, or OutputChannels.\n";
3330 return NULL;
3331 }
3332
3333 xmlNode *grid =
icXmlFindNode(pNode->children,
"GridPoints");
3334 if (grid) {
3336
3339 parseStr += "Error in setting the size of GridPoints. Check values of GridPoints, InputChannel, or OutputChannels.\n";
3340 delete pCLUT;
3341 return NULL;
3342 }
3343 }
3344 else {
3345 parseStr += "Error parsing GridPoints.\n";
3346 delete pCLUT;
3347 return NULL;
3348 }
3349 }
3350 else {
3352
3353 xmlAttr *gridGranularity =
icXmlFindAttr(pNode,
"GridGranularity");
3354
3355 if (gridGranularity) {
3357 }
3358 else {
3359 delete pCLUT;
3360 return NULL;
3361 }
3362 if (!pCLUT->
Init(nGridGranularity)) {
3363 parseStr += "Error in setting the size of GridGranularity. Check values of GridGranularity, InputChannel, or OutputChannels.\n";
3364 delete pCLUT;
3365 return NULL;
3366 }
3367 }
3368
3369 xmlNode *table =
icXmlFindNode(pNode->children,
"TableData");
3370
3371 if (table) {
3374 if (precision && atoi(precision) == 1) {
3377 }
3378 else {
3381 }
3382 }
3383
3385 if (!filename || !filename[0]) {
3387 }
3388
3389 if (filename[0]) {
3391
3392 if (!file) {
3393
3394 parseStr += "Error! - File '";
3395 parseStr += filename;
3396 parseStr +="' not found.\n";
3397 delete pCLUT;
3398 return NULL;
3399 }
3400
3402
3403 if (!strcmp(format, "text")) {
3405 char *buf = (char *)malloc(num);
3406
3407 if (!buf) {
3408 perror("Memory Error");
3409 parseStr += "'";
3410 parseStr += filename;
3411 parseStr += "' may not be a valid text file.\n";
3412 delete file;
3413 delete pCLUT;
3414 return NULL;
3415 }
3416
3417
3419
3420 if (!strcmp(encoding, "int8"))
3422 else if (!strcmp(encoding, "int16"))
3424 else if (!strcmp(encoding, "float"))
3426 else if (encoding[0]) {
3427 parseStr+= "Unknown encoding \"";
3428 parseStr+= encoding;
3429 parseStr+= "\" - using default encoding\n";
3430 }
3431
3432 if (file->
Read8(buf, num)!=num) {
3433 perror("Read-File Error");
3434 parseStr += "'";
3435 parseStr += filename;
3436 parseStr += "' may not be a valid text file.\n";
3437 free(buf);
3438 delete file;
3439 delete pCLUT;
3440 return NULL;
3441 }
3442
3445
3447 parseStr += "File '";
3448 parseStr += filename;
3449 parseStr += "' is not a valid text file.\n";
3450 free(buf);
3451 delete file;
3452 delete pCLUT;
3453 return NULL;
3454 }
3455
3457 parseStr += "Error! - Number of entries in file '";
3458 parseStr += filename;
3459 parseStr += "'is not equal to the size of the CLUT Table.\n";
3460 parseStr += " a. Check values of GridGranularity/GridPoints, InputChannel, or OutputChannels.\n";
3461 parseStr += " b. File may not be a valid text file.\n";
3462 free(buf);
3463 delete file;
3464 delete pCLUT;
3465 return NULL;
3466 }
3469
3471 for (i=0; i<data.
GetSize(); i++) {
3473 }
3474 }
3477
3479 parseStr += "File '";
3480 parseStr += filename;
3481 parseStr += "' is not a valid text file.\n";
3482 free(buf);
3483 delete file;
3484 delete pCLUT;
3485 return NULL;
3486 }
3487
3489 parseStr += "Error! - Number of entries in file '";
3490 parseStr += filename;
3491 parseStr += "'is not equal to the size of the CLUT Table.\n";
3492 parseStr += " a. Check values of GridGranularity/GridPoints, InputChannel, or OutputChannels.\n";
3493 parseStr += " b. File may not be a valid text file.\n";
3494 free(buf);
3495 delete file;
3496 delete pCLUT;
3497 return NULL;
3498 }
3501
3503 for (i=0; i<data.
GetSize(); i++) {
3505 }
3506 }
3509
3511 parseStr += "File '";
3512 parseStr += filename;
3513 parseStr += "' is not a valid text file.\n";
3514 free(buf);
3515 delete file;
3516 delete pCLUT;
3517 return NULL;
3518 }
3519
3521 parseStr += "Error! - Number of entries in file '";
3522 parseStr += filename;
3523 parseStr += "'is not equal to the size of the CLUT Table.\n";
3524 parseStr += " a. Check values of GridGranularity/GridPoints, InputChannel, or OutputChannels.\n";
3525 parseStr += " b. File may not be a valid text file.\n";
3526 free(buf);
3527 delete file;
3528 delete pCLUT;
3529 return NULL;
3530 }
3533
3535 for (i=0; i<data.
GetSize(); i++) {
3536 *dst++ = *src++;
3537 }
3538 }
3539 else {
3540 parseStr += "Error! Unknown text data type.\n";
3541 free(buf);
3542 delete file;
3543 delete pCLUT;
3544 return NULL;
3545 }
3546 free(buf);
3547 }
3548 else if (!strcmp(format, "binary")) {
3550 bool little_endian = !strcmp(order, "little");
3551
3553
3555
3556 if (!strcmp(encoding, "int8"))
3558 else if (!strcmp(encoding, "int16"))
3560 else if (!strcmp(encoding, "float"))
3562 else if (encoding[0]) {
3563 parseStr+= "Unknown encoding \"";
3564 parseStr+= encoding;
3565 parseStr+= "\" - using int16.\n";
3567 }
3568 else {
3569 parseStr+= "CLUT TableData Encoding type not specified.\n";
3570 }
3571 }
3572
3576
3578 parseStr += "Error! - Number of entries in file '";
3579 parseStr += filename;
3580 parseStr += "'is not equal to the size of the CLUT Table.\n";
3581 parseStr += " a. Check values of GridGranularity/GridPoints, InputChannel, or OutputChannels.\n";
3582 parseStr += " b. File may not be a valid binary file.\n";
3583 delete file;
3584 delete pCLUT;
3585 return NULL;
3586 }
3589 for (i=0; i<num; i++) {
3590 if (!file->
Read8(&value)) {
3591 perror("Read-File Error");
3592 parseStr += "'";
3593 parseStr += filename;
3594 parseStr += "' may not be a valid binary file.\n";
3595 delete file;
3596 delete pCLUT;
3597 return NULL;
3598 }
3600 }
3601 }
3606
3608 parseStr += "Error! - Number of entries in file '";
3609 parseStr += filename;
3610 parseStr += "'is not equal to the size of the CLUT Table.\n";
3611 parseStr += " a. Check values of GridGranularity/GridPoints, InputChannel, or OutputChannels.\n";
3612 parseStr += " b. File may not be a valid binary file.\n";
3613 delete file;
3614 delete pCLUT;
3615 return NULL;
3616 }
3618
3620 for (i=0; i<num; i++) {
3621 if (!file->
Read16(&value)) {
3622 perror("Read-File Error");
3623 parseStr += "'";
3624 parseStr += filename;
3625 parseStr += "' may not be a valid binary file.\n";
3626 delete file;
3627 delete pCLUT;
3628 return NULL;
3629 }
3630#ifdef ICC_BYTE_ORDER_LITTLE_ENDIAN
3631 if (little_endian) {
3632#else
3633 if (!little_endian) {
3634#endif
3636 ptr[0] = ptr[1];
3637 ptr[1] = t;
3638 }
3640 }
3641 }
3646
3648 parseStr += "Error! - Number of entries in file '";
3649 parseStr += filename;
3650 parseStr += "'is not equal to the size of the CLUT Table.\n";
3651 parseStr += " a. Check values of GridGranularity/GridPoints, InputChannel, or OutputChannels.\n";
3652 parseStr += " b. File may not be a valid binary file.\n";
3653 delete file;
3654 delete pCLUT;
3655 return NULL;
3656 }
3658
3660 for (i=0; i<num; i++) {
3662 perror("Read-File Error");
3663 parseStr += "'";
3664 parseStr += filename;
3665 parseStr += "' may not be a valid binary file.\n";
3666 delete file;
3667 delete pCLUT;
3668 return NULL;
3669 }
3670#ifdef ICC_BYTE_ORDER_LITTLE_ENDIAN
3671 if (little_endian) {
3672#else
3673 if (!little_endian) {
3674#endif
3676 tmp = ptr[0]; ptr[0] = ptr[3]; ptr[3] = tmp;
3677 tmp = ptr[1]; ptr[1] = ptr[2]; ptr[2] = tmp;
3678 }
3679 *dst++ = value;
3680 }
3681 }
3682 else {
3683 parseStr += "Error! Unknown binary data type.\n";
3684 delete file;
3685 delete pCLUT;
3686 return NULL;
3687 }
3688
3689 }
3690 else {
3691 parseStr += "Error! Unknown Format type.\n";
3692 delete pCLUT;
3693 return NULL;
3694 }
3695
3696 delete file;
3697 }
3698 else {
3701
3703 parseStr += "Error! - unable to parse data in CLUT.\n";
3704 delete pCLUT;
3705 return NULL;
3706 }
3707
3709 parseStr += "Error! - Number of entries is not equal to the size of the CLUT Table.\n";
3710 delete pCLUT;
3711 return NULL;
3712 }
3715
3717 for (i=0; i<data.
GetSize(); i++) {
3719 }
3720 }
3723
3725 parseStr += "Error! - unable to parse data in CLUT.\n";
3726 delete pCLUT;
3727 return NULL;
3728 }
3729
3731 parseStr += "Error! - Number of entries is not equal to the size of the CLUT Table.\n";
3732 delete pCLUT;
3733 return NULL;
3734 }
3737
3739 for (i=0; i<data.
GetSize(); i++) {
3741 }
3742 }
3745
3747 parseStr += "Error! - unable to parse data in CLUT.\n";
3748 delete pCLUT;
3749 return NULL;
3750 }
3751
3753 parseStr += "Error! - Number of entries is not equal to the size of the CLUT Table.\n";
3754 delete pCLUT;
3755 return NULL;
3756 }
3759
3761 for (i=0; i<data.
GetSize(); i++) {
3762 *dst++ = *src++;
3763 }
3764 }
3765 else {
3766 parseStr += "Error! Unknown table data type.";
3767 delete pCLUT;
3768 return NULL;
3769 }
3770 }
3771 }
3772 else {
3773 parseStr += "Error! Cannot find table data.";
3774 delete pCLUT;
3775 return NULL;
3776 }
3777
3778 return pCLUT;
3779}
float icFloatNumber
All floating point operations/variables in IccProfLib use the icFloatNumber data type.
CIccIO * IccOpenFileIO(const icChar *szFilename, const char *szAttr)
xmlAttr * icXmlFindAttr(xmlNode *pNode, const char *szAttrName)
xmlNode * icXmlFindNode(xmlNode *pNode, const char *szNodeName)
const char * icXmlAttrValue(xmlAttr *attr, const char *szDefault)
unsigned int icUInt32Number
icUInt16Number GetOutputChannels() const
icUInt32Number NumPoints() const
void SetPrecision(icUInt8Number nPrecision)
icFloatNumber * GetData(int index)
bool Init(icUInt8Number nGridPoints, icUInt32Number nMaxSize=0, icUInt8Number nBytesPerPoint=4)
Name: CIccCLUT::Init.
icInt32Number ReadFloat32Float(void *pBufFloat, icInt32Number nNum=1)
virtual icInt32Number GetLength()
virtual icInt32Number Read8(void *pBuf8, icInt32Number nNum=1)
icInt32Number Read16(void *pBuf16, icInt32Number nNum=1)
static bool ParseArray(T *buf, icUInt32Number nBufSize, xmlNode *pNode)
bool ParseTextArrayNum(const char *szText, icUInt32Number num, std::string &parseStr)