00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
#ifndef LHGeneralIncs_h
00015
#include "General.h"
00016
#endif
00017
00018
#ifndef LHTheRoutines_h
00019
#include "Routines.h"
00020
#endif
00021
00022
#ifndef LHFragment_h
00023
#include "Fragment.h"
00024
#endif
00025
00026
#ifndef LHCalcNDim_h
00027
#include "CalcNDim.h"
00028
#endif
00029
00030
#ifndef LHDoNDim_h
00031
#include "DoNDim.h"
00032
#endif
00033
00034
00035
#if ! realThing
00036
#ifdef DEBUG_OUTPUT
00037
#define kThisFile kLHGenLutsID
00038
#define DoDisplayLutNew DoDisplayLut
00039
#endif
00040
#endif
00041
00042
#ifndef LHStdConversionLuts_h
00043
#include "StdConv.h"
00044
#endif
00045
00046 #define ALLOW_DEVICE_LINK
00047
00048
00049
00050
00051
00052
#ifdef WRITE_LUTS
00053
void
00054 WriteLut2File (
Str255 theTitle,
00055 LUT_DATA_TYPE theLut,
00056 OSType theType );
00057
00058
00059
00060
void
00061 WriteLut2File ( Str255 theTitle,
00062 LUT_DATA_TYPE theLut,
00063 OSType theType )
00064 {
00065 FSSpec theFSSpec;
00066
SINT16 refNum;
00067
SINT32 theCount;
00068
00069
if (theLut)
00070 {
00071 FSMakeFSSpec(0, 0, theTitle, &theFSSpec);
00072 FSpDelete(&theFSSpec);
00073 FSpCreate(&theFSSpec, 'Fill', theType, 0L);
00074 FSpOpenDF(&theFSSpec,fsWrPerm,&refNum);
00075 theCount =
GETDATASIZE(theLut);
00076 FSWrite(refNum, &theCount,
DATA_2_PTR(theLut));
00077 FSClose(refNum);
00078 }
00079 }
00080
#endif
00081
00082
00083
00084
00085
00086
00087
#ifdef WRITE_STRING
00088
#include "stdio.h"
00089
void
00090 WriteString2File ( Str255 theFile,
00091 Str255 theString );
00092
00093
00094
00095
void
00096 WriteString2File ( Str255 theFile,
00097 Str255 theString )
00098 {
00099 FSSpec theFSSpec;
00100
SINT16 refNum;
00101
SINT32 theCount;
00102
SINT32 curEOF;
00103
OSErr err;
00104
00105 FSMakeFSSpec(-LMGetSFSaveDisk(), LMGetCurDirStore(), theFile, &theFSSpec);
00106 err = FSpOpenDF(&theFSSpec,fsWrPerm,&refNum);
00107
if (err == fnfErr)
00108 {
00109 FSpCreate(&theFSSpec, 'MPS ', 'TEXT', 0L);
00110 FSpOpenDF(&theFSSpec,fsWrPerm,&refNum);
00111 }
00112 GetEOF(refNum,&curEOF);
00113 SetFPos(refNum,fsFromStart,curEOF);
00114 theCount = theString[0];
00115 FSWrite(refNum, &theCount, &theString[1]);
00116 FSClose(refNum);
00117 }
00118
00119
#endif
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143
00144 #define CLIPPByte(x,a,b) ((x)<(a)?(UINT8)(a):((x)>(b)?(UINT8)(b):(UINT8)(x+.5)))
00145 #define CLIPPWord(x,a,b) ((x)<(a)?(UINT16)(a):((x)>(b)?(UINT16)(b):(UINT16)(x+.5)))
00146
00147 #define VAL_USED_BITS 16
00148 #define VAL_MAX (1<<VAL_USED_BITS)
00149 #define VAL_MAXM1 (VAL_MAX-1)
00150
00151
00152
00153
00154
00155
00156
00157
void
00158 CreateLinearElut16 ( Ptr theElut,
00159 SINT32 theSize,
00160 SINT32 gridPoints,
00161 SINT32 gridPointsCube)
00162 {
00163
UINT16* wordPtr;
00164
register UINT32 aVal;
00165
SINT16 loop;
00166
register UINT32 aFac;
00167
register UINT32 aDiv;
00168
register UINT32 aRound;
00169
#ifdef DEBUG_OUTPUT
00170
CMError err =
noErr;
00171
#endif
00172
00173
LH_START_PROC(
"CreateLinearElut16")
00174
if ( gridPointsCube )
00175 {
00176
if( gridPoints ){
00177 aFac = (
UINT32)((gridPoints-1) * (256*128. * gridPointsCube) + (gridPointsCube-1) / 2) ;
00178 aFac = aFac / (gridPointsCube-1);
00179 aDiv = (
UINT32)((gridPoints * (theSize-1) + .9999999 )/ 2.);
00180 }
00181
else{
00182 aFac = (
UINT32)( (256*128. * gridPointsCube) + (gridPointsCube-1) / 2) ;
00183 aFac = aFac / (gridPointsCube-1);
00184 aDiv = (
UINT32)(( (theSize-1) + .9999999 )/ 2.);
00185 }
00186 }
00187
else
00188 {
00189
if( gridPoints ){
00190 aFac = (gridPoints-1) * 65536;
00191 aDiv = gridPoints * (theSize-1);
00192 }
00193
else{
00194 aFac = 65535 ;
00195 aDiv = (theSize-1) ;
00196 }
00197 }
00198 aRound = aDiv/2-1;
00199 wordPtr = (
UINT16*)theElut;
00200
for (loop =0; loop< theSize; loop++)
00201 {
00202 aVal = (loop * aFac + aRound ) / aDiv;
00203
if ( aVal >
VAL_MAXM1 )
00204 aVal =
VAL_MAXM1;
00205 wordPtr[loop] = (
UINT16)aVal;
00206 }
00207
LH_END_PROC(
"CreateLinearElut16")
00208 }
00209
00210
00211
00212
00213
00214
00215
00216
00217
void
00218 CreateLinearElut ( Ptr theElut,
00219 SINT32 theSize,
00220 SINT32 gridPoints,
00221 SINT32 gridPointsCube)
00222 {
00223
UINT16* wordPtr;
00224
register UINT32 aVal;
00225
SINT32 loop;
00226
register UINT32 aFac;
00227
register UINT32 aDiv;
00228
register UINT32 aRound;
00229
register UINT32 aMax;
00230
#ifdef DEBUG_OUTPUT
00231
CMError err =
noErr;
00232
#endif
00233
00234
LH_START_PROC(
"CreateLinearElut")
00235
if ( gridPointsCube )
00236 {
00237
if( gridPoints ){
00238 aMax = 1024 * (gridPoints-1) / gridPoints;
00239 aFac = (
UINT32)((gridPoints-1) * (1024 * gridPointsCube) + (gridPointsCube-1) / 2) ;
00240 aFac = aFac / (gridPointsCube-1);
00241 aDiv = (
UINT32)((gridPoints * (theSize-1) + .9999999 ));
00242 }
00243
else{
00244 aFac = (
UINT32)( (1024 * gridPointsCube) + (gridPointsCube-1) / 2) ;
00245 aFac = aFac / (gridPointsCube-1);
00246 aDiv = (
UINT32)(( (theSize-1) + .9999999 ));
00247 aMax = 1023;
00248 }
00249 }
00250
else
00251 {
00252
if( gridPoints ){
00253 aMax = 1024 * (gridPoints-1) / gridPoints;
00254 aFac = (gridPoints-1) * 1024/2;
00255 aDiv = gridPoints * (theSize-1)/2;
00256 }
00257
else{
00258 aMax = 1023;
00259 aFac = aMax;
00260 aDiv = (theSize-1) ;
00261 }
00262 }
00263 aRound = aDiv/2-1;
00264 wordPtr = (
UINT16*)theElut;
00265
for (loop =0; loop< theSize; loop++)
00266 {
00267 aVal = (loop * aFac + aRound ) / aDiv;
00268
if ( aVal > aMax )
00269 aVal = aMax;
00270 wordPtr[loop] = (
UINT16)aVal;
00271 }
00272
LH_END_PROC(
"CreateLinearElut")
00273 }
00274
00275
00276
00277
00278
00279
00280
void
00281 CreateLinearAlut16 ( UINT16* theAlut,
00282 SINT32 aCount )
00283 {
00284
SINT32 count = aCount;
00285
SINT32 loop;
00286
SINT32 aFac = 4096*
VAL_MAXM1/(count-1);
00287
SINT32 aRound = 2047;
00288
SINT32 aVal;
00289
#ifdef DEBUG_OUTPUT
00290
CMError err =
noErr;
00291
#endif
00292
00293
LH_START_PROC(
"CreateLinearAlut16")
00294
for ( loop = 0; loop < count; loop++)
00295 {
00296 aVal = ( loop * aFac + aRound ) >> 12;
00297
if ( aVal >
VAL_MAXM1 )
00298 aVal =
VAL_MAXM1;
00299 theAlut[loop] = (
UINT16)aVal;
00300 }
00301
LH_END_PROC(
"CreateLinearAlut16")
00302 }
00303
00304
00305
00306
00307
00308
00309
void
00310 CreateLinearAlut ( UINT8* theAlut,
00311 SINT32 count )
00312 {
00313
SINT32 adr_Bits;
00314
SINT32 loop,i;
00315
SINT32 shift;
00316
SINT32 aRound;
00317
SINT32 aVal;
00318
#ifdef DEBUG_OUTPUT
00319
CMError err =
noErr;
00320
#endif
00321
00322
LH_START_PROC(
"CreateLinearAlut")
00323
for( i=1; i<100; ++i)
00324
if ( (1<<i) == count )
00325
break;
00326
if ( i<= 0 || i >= 100 )
00327
return;
00328 adr_Bits = i;
00329 shift = adr_Bits - 8;
00330
if ( shift > 0 )
00331 aRound = (1<<(shift-1));
00332
else
00333 aRound = 0;
00334
00335
for ( loop = 0; loop < count; loop++)
00336 {
00337 aVal = ( loop + aRound ) >> shift;
00338
if ( aVal > 255 )
00339 aVal = 255;
00340 theAlut[loop] = (
UINT8)aVal;
00341 }
00342
LH_END_PROC(
"CreateLinearAlut")
00343 }
00344
00345
00346
00347
00348
00349
00350
00351
void
00352
SetMem16 (
void *wordPtr,
00353 UINT32 numBytes,
00354 UINT16 wordValue);
00355
void
00356 SetMem16 (
void *wordPtr,
00357 UINT32 numBytes,
00358 UINT16 wordValue)
00359 {
00360
register SINT32 i;
00361
register SINT32 count = numBytes;
00362
register UINT16 *ptr = (
UINT16 *)wordPtr;
00363
register UINT16 value = wordValue;
00364
#ifdef DEBUG_OUTPUT
00365
CMError err =
noErr;
00366
#endif
00367
00368
LH_START_PROC(
"SetMem16")
00369
for (i = 0; i < count; ++i)
00370 *ptr++ = value;
00371
LH_END_PROC(
"SetMem16")
00372 }
00373
00374
00375
00376
00377
00378
00379
CMError
00380 DoMakeGamutForMonitor (
CMLutParamPtr theLutData,
00381
LHCombiDataPtr theCombiData)
00382 {
00383
OSType colorantTags[3];
00384
icXYZType colorantData[3];
00385
SINT16 loop;
00386
CMError err;
00387
UINT32 elementSize;
00388
00389
LH_START_PROC(
"DoMakeGamutForMonitor")
00390
00391 colorantTags[0] =
icSigRedColorantTag;
00392 colorantTags[1] =
icSigGreenColorantTag;
00393 colorantTags[2] =
icSigBlueColorantTag;
00394
00395
00396
for (loop = 0; loop < 3; loop++)
00397 {
00398 err =
CMGetProfileElement(theCombiData->
theProfile, colorantTags[loop], &elementSize,
nil);
00399
if (err !=
noErr)
00400
goto CleanupAndExit;
00401 err =
CMGetProfileElement(theCombiData->
theProfile, colorantTags[loop], &elementSize, &colorantData[loop]);
00402
#ifdef IntelMode
00403
SwapLongOffset( &colorantData[loop].base.sig, 0, 4 );
00404 SwapLongOffset( &colorantData[loop], (ULONG)((
char*)&colorantData[0].data.
data[0]-(
char*)&colorantData[0]), elementSize );
00405
#endif
00406
if (err !=
noErr)
00407
goto CleanupAndExit;
00408 }
00409
00410
if ( theCombiData->
precision ==
cmBestMode )
00411 {
00412 err =
MakeGamut16or32ForMonitor( &colorantData[0], &colorantData[1], &colorantData[2], theLutData,
TRUE );
00413 theLutData->
colorLutGridPoints = 32;
00414 }
00415
else
00416 {
00417 err =
MakeGamut16or32ForMonitor( &colorantData[0], &colorantData[1], &colorantData[2], theLutData,
FALSE);
00418 theLutData->
colorLutGridPoints = 16;
00419 }
00420 theLutData->
colorLutInDim = 3;
00421 theLutData->
colorLutOutDim = 1;
00422 theLutData->
inputLutEntryCount = (1<<
adr_breite_elut);
00423 theLutData->
inputLutWordSize =
VAL_USED_BITS;
00424 theLutData->
outputLutEntryCount =
adr_bereich_alut;
00425 theLutData->
outputLutWordSize =
bit_breite_alut;
00426 theLutData->
colorLutWordSize = 8;
00427
00428
#ifdef DEBUG_OUTPUT
00429
if ( DebugLutCheck( kDisplayGamut ) )
00430 {
00431
LOCK_DATA(theLutData->
colorLut);
00432
if (theCombiData->
precision ==
cmBestMode)
00433 Show32by32by32GamutXLUT(
DATA_2_PTR(theLutData->
colorLut));
00434
else
00435 Show16by16by16GamutXLUT(
DATA_2_PTR(theLutData->
colorLut));
00436
UNLOCK_DATA(theLutData->
colorLut);
00437 }
00438
#endif
00439
00440 CleanupAndExit:
00441
00442
LH_END_PROC(
"DoMakeGamutForMonitor")
00443
return err;
00444 }
00445
00446
00447
00448
00449
00450
00451
00452
00453
CMError
00454 GetMatrixFromProfile (
CMLutParamPtr theLutData,
00455
LHCombiDataPtr theCombiData,
00456 OSType theTag,
00457
double factor )
00458 {
00459
CMError err =
noErr;
00460
OSErr aOSerr =
noErr;
00461
SINT32 i;
00462
SINT32 j;
00463
Matrix2D localMatrix;
00464
long matrix[3][3];
00465
UINT32 byteCount;
00466
SINT32 offset;
00467
00468
LH_START_PROC(
"GetMatrixFromProfile")
00469
00470
00471 offset = 12;
00472 byteCount = 9 *
sizeof(
Fixed);
00473 err =
CMGetPartialProfileElement(theCombiData->
theProfile, theTag, offset, &byteCount, &matrix);
00474
#ifdef IntelMode
00475
SwapLongOffset( &matrix, 0, byteCount );
00476
#endif
00477
if (err)
00478
goto CleanupAndExit;
00479
00480
for (i = 0; i < 3; i++)
00481
for (j = 0; j < 3; j++)
00482 localMatrix[i][j] = (
double)( matrix[i][j] / 65536.0 * factor);
00483
00484
if ( 0 || localMatrix[0][0] + localMatrix[1][1] + localMatrix[2][2] != 3.0 )
00485 {
00486 theLutData->
matrixMFT =
SmartNewPtr(
sizeof(
Matrix2D), &aOSerr);
00487 err = aOSerr;
00488
if (err)
00489
goto CleanupAndExit;
00490
BlockMoveData(localMatrix, theLutData->
matrixMFT,
sizeof(
Matrix2D));
00491 }
00492
else
00493 theLutData->
matrixMFT =
nil;
00494
00495
00496
00497 CleanupAndExit:
00498
00499
LH_END_PROC(
"GetMatrixFromProfile")
00500
return err;
00501 }
00502
00503
00504
00505
00506
00507
00508
00509
00510
00511
CMError
00512 Extract_MFT_Elut (
CMLutParamPtr theLutData,
00513
LHCombiDataPtr theCombiData,
00514 Ptr profileLutPtr,
00515 OSType theTag )
00516 {
00517
CMError err =
noErr;
00518
OSErr aOSerr =
noErr;
00519
UINT32 byteCount;
00520
SINT32 offset;
00521
SINT32 i;
00522
SINT32 inputTableEntries;
00523
Ptr theInputLuts =
nil;
00524
Boolean readLutFromFile =
TRUE;
00525
UINT16* shortPtr;
00526
00527
LH_START_PROC(
"Extract_MFT_Elut")
00528
00529
00530
00531
00532
if ( *((
OSType*)profileLutPtr) ==
icSigLut8Type )
00533 {
00534
00535 inputTableEntries = 256;
00536 offset = 48;
00537 byteCount = theLutData->
colorLutInDim * inputTableEntries;
00538 theInputLuts =
SmartNewPtr(byteCount, &aOSerr);
00539 err = aOSerr;
00540
if (err)
00541
goto CleanupAndExit;
00542 err =
CMGetPartialProfileElement(theCombiData->
theProfile, theTag, offset, &byteCount, theInputLuts);
00543
if (err)
00544
goto CleanupAndExit;
00545
if ( theCombiData->
doCreate_16bit_ELut )
00546 {
00547
00548
if ((theCombiData->
doCreateLinkProfile) && (theCombiData->
profLoop == 0))
00549 err =
Fill_ushort_ELUTs_from_lut8Tag( theLutData, theInputLuts,
adr_breite_elut,
bit_breite_elut, 0 );
00550
else
00551 err =
Fill_ushort_ELUTs_from_lut8Tag( theLutData, theInputLuts,
adr_breite_elut,
VAL_USED_BITS, theLutData->
colorLutGridPoints );
00552 theLutData->
inputLutEntryCount = (1<<
adr_breite_elut);
00553 theLutData->
inputLutWordSize =
VAL_USED_BITS;
00554 }
00555
else
00556 {
00557
if ( theCombiData->
doCreate_16bit_Combi )
00558 {
00559
if (theCombiData->
maxProfileCount == 0)
00560 err =
Fill_ushort_ELUTs_from_lut8Tag( theLutData, theInputLuts,
adr_breite_elut,
VAL_USED_BITS, theLutData->
colorLutGridPoints );
00561
else
00562 err =
Fill_ushort_ELUTs_from_lut8Tag( theLutData, theInputLuts,
adr_breite_elut,
VAL_USED_BITS, theCombiData->
gridPointsCube );
00563 theLutData->
inputLutWordSize =
VAL_USED_BITS;
00564 }
00565
else
00566 {
00567
if (theCombiData->
maxProfileCount == 0)
00568 err =
Fill_ushort_ELUTs_from_lut8Tag( theLutData, theInputLuts,
adr_breite_elut,
bit_breite_elut, theLutData->
colorLutGridPoints );
00569
else
00570 err =
Fill_ushort_ELUTs_from_lut8Tag( theLutData, theInputLuts,
adr_breite_elut,
bit_breite_elut, theCombiData->
gridPointsCube );
00571 theLutData->
inputLutWordSize =
bit_breite_elut;
00572
00573 }
00574 theLutData->
inputLutEntryCount = (1<<
adr_breite_elut);
00575 }
00576 }
00577
else
00578
00579
00580
00581 {
00582
00583 inputTableEntries = ((
icLut16Type *)profileLutPtr)->lut.inputEnt;
00584
if (inputTableEntries <2)
00585 {
00586
#if ! realThing
00587
readLutFromFile =
FALSE;
00588 inputTableEntries = 2;
00589
#else
00590
err =
cmProfileError;
00591
goto CleanupAndExit;
00592
#endif
00593
}
00594
if (readLutFromFile)
00595 {
00596 offset = 52;
00597 byteCount = theLutData->
colorLutInDim * inputTableEntries *
sizeof(
UINT16);
00598 theInputLuts =
SmartNewPtr(byteCount, &aOSerr);
00599 err = aOSerr;
00600
if (err)
00601
goto CleanupAndExit;
00602 err =
CMGetPartialProfileElement(theCombiData->
theProfile, theTag, offset, &byteCount, theInputLuts);
00603
#ifdef IntelMode
00604
SwapShortOffset( theInputLuts, 0, byteCount );
00605
#endif
00606
if (err)
00607
goto CleanupAndExit;
00608 }
else
00609 {
00610 theInputLuts =
SmartNewPtr(inputTableEntries *
sizeof(
SINT16) * theLutData->
colorLutInDim, &aOSerr);
00611 err = aOSerr;
00612
if (err)
00613
goto CleanupAndExit;
00614 shortPtr = (
UINT16*)theInputLuts;
00615
for (i = 0; i< (theLutData->
colorLutInDim * inputTableEntries); i+=inputTableEntries)
00616 {
00617 shortPtr[i] = 0;
00618 shortPtr[i+1] = 0xFFFF;
00619 }
00620 }
00621
if ( theCombiData->
doCreate_16bit_ELut )
00622 {
00623
00624
if ((theCombiData->
doCreateLinkProfile) && (theCombiData->
profLoop == 0))
00625 err =
Fill_ushort_ELUTs_from_lut16Tag( theLutData, theInputLuts,
adr_breite_elut,
VAL_USED_BITS, 0, inputTableEntries );
00626
else
00627 err =
Fill_ushort_ELUTs_from_lut16Tag( theLutData, theInputLuts,
adr_breite_elut,
VAL_USED_BITS, theLutData->
colorLutGridPoints, inputTableEntries );
00628 theLutData->
inputLutEntryCount = (1<<
adr_breite_elut);
00629 theLutData->
inputLutWordSize =
VAL_USED_BITS;
00630 }
00631
else
00632 {
00633
if ( theCombiData->
doCreate_16bit_Combi )
00634 {
00635
if (theCombiData->
maxProfileCount == 0)
00636 err =
Fill_ushort_ELUTs_from_lut16Tag( theLutData, theInputLuts,
adr_breite_elut,
VAL_USED_BITS, theLutData->
colorLutGridPoints, inputTableEntries );
00637
else
00638 err =
Fill_ushort_ELUTs_from_lut16Tag( theLutData, theInputLuts,
adr_breite_elut,
VAL_USED_BITS, theCombiData->
gridPointsCube, inputTableEntries );
00639 theLutData->
inputLutWordSize =
VAL_USED_BITS;
00640 }
00641
else
00642 {
00643
if (theCombiData->
maxProfileCount == 0)
00644 err =
Fill_ushort_ELUTs_from_lut16Tag( theLutData, theInputLuts,
adr_breite_elut,
bit_breite_elut, theLutData->
colorLutGridPoints, inputTableEntries );
00645
else
00646 err =
Fill_ushort_ELUTs_from_lut16Tag( theLutData, theInputLuts,
adr_breite_elut,
bit_breite_elut, theCombiData->
gridPointsCube, inputTableEntries );
00647 theLutData->
inputLutWordSize =
bit_breite_elut;
00648 }
00649 theLutData->
inputLutEntryCount = (1<<
adr_breite_elut);
00650 }
00651 }
00652
if (err)
00653
goto CleanupAndExit;
00654
00655
00656
00657
00658 CleanupAndExit:
00659 theInputLuts =
DisposeIfPtr(theInputLuts);
00660
00661
LH_END_PROC(
"Extract_MFT_Elut")
00662
return err;
00663 }
00664
00665
00666
00667
00668
00669
00670
00671
00672
CMError
00673 Extract_MFT_Xlut (
CMLutParamPtr theLutData,
00674
LHCombiDataPtr theCombiData,
00675 Ptr profileLutPtr,
00676 OSType theTag )
00677 {
00678
CMError err =
noErr;
00679
OSErr aOSerr =
noErr;
00680
SINT32 i;
00681
SINT32 clutSize;
00682
LUT_DATA_TYPE localXlut =
nil;
00683
Ptr tempXlut =
nil;
00684
Ptr bytePtr =
nil;
00685
Ptr xlutPtr =
nil;
00686
SINT32 offset;
00687
SINT32 inputTableEntries;
00688
UINT32 byteCount;
00689
UINT32 theSize;
00690
UINT32 aExtraSize;
00691
00692
LH_START_PROC(
"Extract_MFT_Xlut")
00693
00694 clutSize = theLutData->
colorLutOutDim;
00695
for(i=0; i<theLutData->
colorLutInDim; i++)
00696 clutSize *= theLutData->
colorLutGridPoints;
00697
00698
00699
00700
00701
if ( *((
OSType*)profileLutPtr) ==
icSigLut8Type )
00702 {
00703
if ( theCombiData->
maxProfileCount == 0 ){
00704 theSize = 1;
00705 aExtraSize = 1;
00706
for( i=0; i<(theLutData->
colorLutInDim-1); ++i){
00707 theSize *= theLutData->
colorLutGridPoints;
00708 aExtraSize += theSize;
00709 }
00710
#ifdef ALLOW_MMX
00711
aExtraSize++;
00712
#endif
00713
}
00714
else{
00715 aExtraSize = 0;
00716 }
00717 aExtraSize *= theLutData->
colorLutOutDim;
00718 localXlut =
ALLOC_DATA(clutSize+aExtraSize, &aOSerr);
00719 err = aOSerr;
00720
if (err)
00721
goto CleanupAndExit;
00722
LOCK_DATA(localXlut);
00723 inputTableEntries = 256;
00724 offset = 48 + (inputTableEntries * theLutData->
colorLutInDim);
00725 byteCount = clutSize;
00726 err =
CMGetPartialProfileElement(theCombiData->
theProfile, theTag, offset, &byteCount,
DATA_2_PTR(localXlut));
00727 theLutData->
colorLutWordSize = 8;
00728
if (err)
00729
goto CleanupAndExit;
00730 }
else
00731
00732
00733
00734 {
00735
if (( theCombiData->
maxProfileCount > 0 ) || (theCombiData->
doCreateLinkProfile) || (theCombiData->
doCreate_16bit_XLut))
00736 clutSize *= 2;
00737
if ( theCombiData->
maxProfileCount == 0 ){
00738 theSize = 1;
00739 aExtraSize = 1;
00740
for( i=0; i<(theLutData->
colorLutInDim-1); ++i){
00741 theSize *= theLutData->
colorLutGridPoints;
00742 aExtraSize += theSize;
00743 }
00744
if (( theCombiData->
doCreateLinkProfile) || (theCombiData->
doCreate_16bit_XLut)){
00745 aExtraSize *= 2;
00746 }
00747
#ifdef ALLOW_MMX
00748
aExtraSize++;
00749
#endif
00750
}
00751
else{
00752 aExtraSize = 0;
00753 }
00754 aExtraSize *= theLutData->
colorLutOutDim;
00755 localXlut =
ALLOC_DATA(clutSize+aExtraSize, &aOSerr);
00756 err = aOSerr;
00757
if (err)
00758
goto CleanupAndExit;
00759
LOCK_DATA(localXlut);
00760 inputTableEntries = ((
icLut16Type *)profileLutPtr)->lut.inputEnt;
00761
if (inputTableEntries <2)
00762 {
00763 err =
cmProfileError;
00764
goto CleanupAndExit;
00765 }
00766 offset = 52 + ( inputTableEntries * theLutData->
colorLutInDim) *
sizeof(
UINT16);
00767
00768
if (( theCombiData->
maxProfileCount > 0 ) || (theCombiData->
doCreateLinkProfile) || (theCombiData->
doCreate_16bit_XLut))
00769 {
00770 byteCount = clutSize;
00771 tempXlut = 0;
00772 err =
CMGetPartialProfileElement(theCombiData->
theProfile, theTag, offset, &byteCount,
DATA_2_PTR(localXlut));
00773
#ifdef IntelMode
00774
SwapShortOffset( localXlut, 0, byteCount );
00775
#endif
00776
theLutData->
colorLutWordSize =
VAL_USED_BITS;
00777
if (err)
00778
goto CleanupAndExit;
00779 }
00780
else
00781 {
00782
#ifdef DEBUG_OUTPUT
00783
if ( DebugCheck(kThisFile, kDebugMiscInfo) )
00784
DebugPrint(
"� Extract_MFT_Xlut: 1 Link profile mode\n",err);
00785
#endif
00786
byteCount = clutSize *
sizeof(
UINT16);
00787 tempXlut =
SmartNewPtr(byteCount, &aOSerr);
00788 err = aOSerr;
00789
if (err)
00790
goto CleanupAndExit;
00791 err =
CMGetPartialProfileElement(theCombiData->
theProfile, theTag, offset, &byteCount, tempXlut);
00792
#ifdef IntelMode
00793
00794
#endif
00795
if (err)
00796
goto CleanupAndExit;
00797 bytePtr = tempXlut;
00798 xlutPtr = (
Ptr)
DATA_2_PTR(localXlut);
00799
for (i = 0; i < clutSize; i++)
00800 {
00801 *xlutPtr = *bytePtr;
00802 bytePtr+=2;
00803 xlutPtr++;
00804 }
00805 theLutData->
colorLutWordSize = 8;
00806 }
00807 }
00808
UNLOCK_DATA(localXlut);
00809 theLutData->
colorLut = localXlut;
00810 localXlut =
nil;
00811
00812
00813
00814
00815 CleanupAndExit:
00816 localXlut =
DISPOSE_IF_DATA(localXlut);
00817 tempXlut =
DisposeIfPtr(tempXlut);
00818
00819
LH_END_PROC(
"Extract_MFT_Xlut")
00820
return err;
00821 }
00822
00823
00824
00825
00826
00827
00828
00829
CMError
00830 Extract_MFT_Alut (
CMLutParamPtr theLutData,
00831
LHCombiDataPtr theCombiData,
00832 Ptr profileLutPtr,
00833 OSType theTag )
00834 {
00835
CMError err =
noErr;
00836
OSErr aOSerr =
noErr;
00837
UINT32 byteCount;
00838
SINT32 offset;
00839
SINT32 clutSize;
00840
SINT32 i;
00841
SINT32 inputTableEntries;
00842
SINT32 outputTableEntries;
00843
Ptr theOutputLuts =
nil;
00844
Boolean readLutFromFile =
TRUE;
00845
UINT16* shortPtr;
00846
00847
LH_START_PROC(
"Extract_MFT_Alut")
00848
00849 clutSize = theLutData->
colorLutOutDim;
00850
for(i=0; i<theLutData->
colorLutInDim; i++)
00851 clutSize *= theLutData->
colorLutGridPoints;
00852
00853
00854
00855
if ( *((
OSType*)profileLutPtr) ==
icSigLut8Type )
00856 {
00857
00858 inputTableEntries = 256;
00859 outputTableEntries = 256;
00860 offset = 48 + (inputTableEntries * theLutData->
colorLutInDim) + clutSize;
00861 byteCount = theLutData->
colorLutOutDim * outputTableEntries;
00862 theOutputLuts =
SmartNewPtr(byteCount, &aOSerr);
00863 err = aOSerr;
00864
if (err)
00865
goto CleanupAndExit;
00866 err =
CMGetPartialProfileElement(theCombiData->
theProfile, theTag, offset, &byteCount, theOutputLuts);
00867
if (err)
00868
goto CleanupAndExit;
00869
if ( theCombiData->
doCreate_16bit_ALut || theCombiData->
doCreate_16bit_Combi )
00870 {
00871 err =
Fill_ushort_ALUTs_from_lut8Tag( theLutData, theOutputLuts,
adr_breite_alut);
00872
if (err)
00873
goto CleanupAndExit;
00874 theLutData->
outputLutEntryCount =
adr_bereich_alut;
00875 theLutData->
outputLutWordSize =
VAL_USED_BITS;
00876 }
00877
else
00878 {
00879 err =
Fill_byte_ALUTs_from_lut8Tag( theLutData, theOutputLuts,
adr_breite_alut);
00880
if (err)
00881
goto CleanupAndExit;
00882 theLutData->
outputLutEntryCount =
adr_bereich_alut;
00883 theLutData->
outputLutWordSize =
bit_breite_alut;
00884 }
00885 }
00886
00887
00888
00889
else
00890 {
00891
00892 inputTableEntries = ((
icLut16Type *)profileLutPtr)->lut.inputEnt;
00893
if (inputTableEntries <2)
00894 {
00895
#if realThing
00896
err =
cmProfileError;
00897
goto CleanupAndExit;
00898
#endif
00899
}
00900 outputTableEntries = ((
icLut16Type *)profileLutPtr)->lut.outputEnt;
00901
if (outputTableEntries <2)
00902 {
00903
#if ! realThing
00904
readLutFromFile =
FALSE;
00905 outputTableEntries = 2;
00906
#else
00907
err =
cmProfileError;
00908
goto CleanupAndExit;
00909
#endif
00910
}
00911
if (readLutFromFile)
00912 {
00913 offset = 52 + (( inputTableEntries * theLutData->
colorLutInDim) + clutSize) *
sizeof(
UINT16);
00914 byteCount = theLutData->
colorLutOutDim * outputTableEntries *
sizeof(
UINT16);
00915 theOutputLuts =
SmartNewPtr(byteCount, &aOSerr);
00916 err = aOSerr;
00917
if (err)
00918
goto CleanupAndExit;
00919 err =
CMGetPartialProfileElement(theCombiData->
theProfile, theTag, offset, &byteCount, theOutputLuts);
00920
if (err)
00921
goto CleanupAndExit;
00922
#ifdef IntelMode
00923
SwapShortOffset( theOutputLuts, 0, byteCount );
00924
#endif
00925
}
else
00926 {
00927 theOutputLuts =
SmartNewPtr(2 *
sizeof(
SINT16) * theLutData->
colorLutOutDim, &aOSerr);
00928 err = aOSerr;
00929
if (err)
00930
goto CleanupAndExit;
00931 shortPtr = (
UINT16*)theOutputLuts;
00932
for (i = 0; i< ( theLutData->
colorLutOutDim * outputTableEntries ); i+=outputTableEntries)
00933 {
00934 shortPtr[i] = 0;
00935 shortPtr[i+1] = (
UINT16)0xFFFF;
00936 }
00937 }
00938
if ( theCombiData->
doCreate_16bit_ALut || theCombiData->
doCreate_16bit_Combi )
00939 {
00940 err =
Fill_ushort_ALUTs_from_lut16Tag( theLutData, theOutputLuts,
adr_breite_alut, outputTableEntries);
00941
if (err)
00942
goto CleanupAndExit;
00943 theLutData->
outputLutEntryCount =
adr_bereich_alut;
00944 theLutData->
outputLutWordSize =
VAL_USED_BITS;
00945 }
00946
else
00947 {
00948 err =
Fill_byte_ALUTs_from_lut16Tag( theLutData, theOutputLuts,
adr_breite_alut, outputTableEntries);
00949
if (err)
00950
goto CleanupAndExit;
00951 theLutData->
outputLutEntryCount =
adr_bereich_alut;
00952 theLutData->
outputLutWordSize =
bit_breite_alut;
00953 }
00954 }
00955
00956
00957
00958
00959 CleanupAndExit:
00960 theOutputLuts =
DisposeIfPtr(theOutputLuts);
00961
00962
LH_END_PROC(
"Extract_MFT_Alut")
00963
return err;
00964 }
00965
00966
00967
00968
00969
00970
00971
00972
CMError
00973 ExtractAll_MFT_Luts (
CMLutParamPtr theLutData,
00974
LHCombiDataPtr theCombiData,
00975 OSType theTag )
00976 {
00977
CMError err =
noErr;
00978
OSErr aOSerr =
noErr;
00979
Ptr profileLutPtr =
nil;
00980
UINT32 elementSize;
00981
double factor;
00982
UINT32 byteCount;
00983
00984
LH_START_PROC(
"ExtractAll_MFT_Luts")
00985
00986
00987 err =
CMGetProfileElement(theCombiData->
theProfile, theTag, &elementSize,
nil);
00988
if (err)
00989
goto CleanupAndExit;
00990
00991 byteCount = 52;
00992 profileLutPtr =
SmartNewPtr(byteCount, &aOSerr);
00993 err = aOSerr;
00994
if (err)
00995
goto CleanupAndExit;
00996
00997 err =
CMGetProfileElement(theCombiData->
theProfile, theTag, &byteCount, profileLutPtr);
00998
#ifdef IntelMode
00999
SwapLongOffset( &((
icLut16Type*)profileLutPtr)->base.sig, 0, 4 );
01000 SwapShortOffset( &((
icLut16Type*)profileLutPtr)->lut.inputEnt, 0, 2 );
01001 SwapShortOffset( &((
icLut16Type*)profileLutPtr)->lut.outputEnt, 0, 2 );
01002
#endif
01003
if (err)
01004
goto CleanupAndExit;
01005
01006 theLutData->
colorLutInDim = ((
icLut8Type*)profileLutPtr)->lut.inputChan;
01007 theLutData->
colorLutOutDim = ((
icLut8Type*)profileLutPtr)->lut.outputChan;
01008 theLutData->
colorLutGridPoints = ((
icLut8Type*)profileLutPtr)->lut.clutPoints;
01009
01010
01011
01012
01013
01014
01015
01016
if ( ( theLutData->
colorLutInDim == 3) &&
01017 ( ( theCombiData->
amIPCS && (theCombiData->
profileConnectionSpace ==
icSigXYZData) ) ||
01018 ( !theCombiData->
amIPCS && (theCombiData->
dataColorSpace ==
icSigXYZData) ) ) )
01019 {
01020 factor = 1.;
01021 err =
GetMatrixFromProfile(theLutData, theCombiData, theTag, factor);
01022 }
01023
01024
01025 err =
Extract_MFT_Alut( theLutData, theCombiData, profileLutPtr, theTag );
01026
if (err)
01027
goto CleanupAndExit;
01028
01029
01030 err =
Extract_MFT_Xlut ( theLutData, theCombiData, profileLutPtr, theTag );
01031
if (err)
01032
goto CleanupAndExit;
01033
01034
01035 err =
Extract_MFT_Elut( theLutData, theCombiData, profileLutPtr, theTag );
01036
if (err)
01037
goto CleanupAndExit;
01038
01039
01040
01041
01042 CleanupAndExit:
01043 profileLutPtr =
DisposeIfPtr(profileLutPtr);
01044
01045
LH_END_PROC(
"ExtractAll_MFT_Luts")
01046
return err;
01047 }
01048
01049
01050
01051
01052
01053
01054
01055
01056
CMError
01057 Extract_TRC_Alut (
CMLutParamPtr theLutData,
01058
LHCombiDataPtr theCombiData )
01059 {
01060
OSType trcSig[
kNumOfRGBchannels];
01061
icCurveType* pCurveTag =
nil;
01062
icCurveType* invertCurveTag =
nil;
01063
CMError err =
noErr;
01064
OSErr aOSerr =
noErr;
01065
UINT32 elementSize;
01066
SINT32 loop;
01067
SINT32 theSize;
01068
SINT32 theAlutSize;
01069
UINT8 addrBits;
01070
LUT_DATA_TYPE localAlut =
nil;
01071
01072
LH_START_PROC(
"Extract_TRC_Alut")
01073
01074
01075 addrBits =
adr_breite_alut;
01076
if ( theCombiData->
doCreate_16bit_ALut || theCombiData->
doCreate_16bit_Combi )
01077 theSize =
sizeof(
UINT16);
01078
else
01079 theSize =
sizeof(
UINT8);
01080 theAlutSize = (1<<addrBits);
01081 localAlut =
ALLOC_DATA(theLutData->
colorLutOutDim * theAlutSize * theSize + theSize, &aOSerr);
01082 err = aOSerr;
01083
if (err)
01084 {
01085
#ifdef DEBUG_OUTPUT
01086
if ( err && DebugCheck(kThisFile, kDebugErrorInfo) )
01087
DebugPrint(
"� Extract_TRC_Alut ALLOC_DATA(%d * %d) error\n",theLutData->
colorLutOutDim , theAlutSize);
01088
#endif
01089
goto CleanupAndExit;
01090 }
01091
LOCK_DATA(localAlut);
01092
if (!theCombiData->
amIPCS)
01093 {
01094
01095
01096
01097
if ( theCombiData->
doCreate_16bit_ALut || theCombiData->
doCreate_16bit_Combi )
01098 {
01099
CreateLinearAlut16 ( (
UINT16 *)
DATA_2_PTR(localAlut),theAlutSize);
01100
for (loop = 0; loop < theLutData->
colorLutOutDim; loop++)
01101
BlockMoveData(
DATA_2_PTR(localAlut), (
Ptr)
DATA_2_PTR(localAlut) + loop * theAlutSize *
sizeof(
UINT16), theAlutSize *
sizeof(
UINT16));
01102 theLutData->
outputLutEntryCount = (
SINT16)theAlutSize;
01103 theLutData->
outputLutWordSize =
VAL_USED_BITS;
01104 }
01105
else
01106 {
01107
CreateLinearAlut ( (
UINT8 *)
DATA_2_PTR(localAlut),theAlutSize);
01108
for (loop = 0; loop < theLutData->
colorLutOutDim; loop++)
01109
BlockMoveData(
DATA_2_PTR(localAlut), (
Ptr)
DATA_2_PTR(localAlut) + loop * theAlutSize, theAlutSize);
01110 theLutData->
outputLutEntryCount = (
SINT16)theAlutSize;
01111 theLutData->
outputLutWordSize = 8;
01112 }
01113 }
01114
else
01115 {
01116
01117
01118
01119 trcSig[0] =
icSigRedTRCTag;
01120 trcSig[1] =
icSigGreenTRCTag;
01121 trcSig[2] =
icSigBlueTRCTag;
01122
01123
for (loop = 0; loop <
kNumOfRGBchannels; loop++)
01124 {
01125 err =
CMGetProfileElement(theCombiData->
theProfile, trcSig[loop], &elementSize,
nil);
01126
if (err)
01127
goto CleanupAndExit;
01128 pCurveTag = (
icCurveType *)
SmartNewPtr(elementSize, &aOSerr);
01129 err = aOSerr;
01130
if (err)
01131
goto CleanupAndExit;
01132
01133 err =
CMGetProfileElement(theCombiData->
theProfile, trcSig[loop], &elementSize, pCurveTag);
01134
if (err){
01135
goto CleanupAndExit;
01136 }
01137
#ifdef IntelMode
01138
SwapLongOffset( &pCurveTag->
base.
sig, 0, 4 );
01139 SwapLong( &pCurveTag->
curve.
count );
01140 SwapShortOffset( pCurveTag, (ULONG)((
SINT8*)&pCurveTag->
curve.
data[0]-(
SINT8*)pCurveTag), elementSize );
01141
#endif
01142
if (pCurveTag)
01143 {
01144
if ( theCombiData->
doCreate_16bit_ALut || theCombiData->
doCreate_16bit_Combi )
01145 {
01146 err =
Fill_inverse_ushort_ALUT_from_CurveTag( pCurveTag, (
UINT16*)
DATA_2_PTR(localAlut) + (theAlutSize * loop), addrBits);
01147
if (err)
01148
goto CleanupAndExit;
01149 theLutData->
outputLutEntryCount = (
SINT16)theAlutSize;
01150 theLutData->
outputLutWordSize =
VAL_USED_BITS;
01151 }
01152
else
01153 {
01154 err =
Fill_inverse_byte_ALUT_from_CurveTag( pCurveTag, (
UINT8*)
DATA_2_PTR(localAlut) + (theAlutSize * loop), addrBits);
01155
if (err)
01156
goto CleanupAndExit;
01157 theLutData->
outputLutEntryCount = (
SINT16)theAlutSize;
01158 theLutData->
outputLutWordSize =
bit_breite_alut;
01159 }
01160 pCurveTag = (
icCurveType*)
DisposeIfPtr((
Ptr)pCurveTag);
01161 }
else
01162 {
01163 err =
unimpErr;
01164
goto CleanupAndExit;
01165 }
01166 }
01167 }
01168
UNLOCK_DATA(localAlut);
01169
01170 theLutData->
outputLut = localAlut;
01171 localAlut =
nil;
01172
01173
01174
01175 CleanupAndExit:
01176 localAlut =
DISPOSE_IF_DATA(localAlut);
01177 pCurveTag = (
icCurveType*)
DisposeIfPtr((
Ptr)pCurveTag);
01178
01179
LH_END_PROC(
"Extract_TRC_Alut")
01180
return err;
01181 }
01182
01183
01184
01185
01186
01187
01188
01189
CMError
01190 Extract_TRC_Elut (
CMLutParamPtr theLutData,
01191
LHCombiDataPtr theCombiData )
01192 {
01193
OSType trcSig[
kNumOfRGBchannels];
01194
icCurveType* pCurveTag =
nil;
01195
SINT32 loop;
01196
SINT32 theElutSize;
01197
CMError err =
noErr;
01198
OSErr aOSerr =
noErr;
01199
UINT32 elementSize;
01200
LUT_DATA_TYPE localElut =
nil;
01201
Ptr singleElut =
nil;
01202
01203
LH_START_PROC(
"Extract_TRC_Elut")
01204
01205 theElutSize = (1<<
adr_breite_elut) *
sizeof (
UINT16);
01206 localElut =
ALLOC_DATA(theLutData->
colorLutInDim * theElutSize + sizeof (
UINT16), &aOSerr);
01207 err = aOSerr;
01208
if (err)
01209
goto CleanupAndExit;
01210
01211
01212 theLutData->
colorLutGridPoints = theCombiData->
gridPointsCube;
01213
01214
LOCK_DATA(localElut);
01215
if (theCombiData->
amIPCS)
01216 {
01217
01218
01219
01220
if ( theCombiData->
doCreate_16bit_ELut )
01221 {
01222
CreateLinearElut16 ( (
Ptr)
DATA_2_PTR(localElut), theElutSize /
sizeof(
UINT16), theLutData->
colorLutGridPoints, 0);
01223 theLutData->
inputLutEntryCount = theElutSize /
sizeof(
UINT16);
01224 theLutData->
inputLutWordSize =
VAL_USED_BITS;
01225 }
01226
else
01227 {
01228
if ( theCombiData->
doCreate_16bit_Combi )
01229 {
01230
CreateLinearElut16 ( (
Ptr)
DATA_2_PTR(localElut), theElutSize /
sizeof(
UINT16), theCombiData->
gridPointsCube, 0);
01231 theLutData->
inputLutWordSize =
VAL_USED_BITS;
01232 }
01233
else
01234 {
01235
CreateLinearElut ( (
Ptr)
DATA_2_PTR(localElut), theElutSize /
sizeof(
UINT16), theCombiData->
gridPointsCube, 0);
01236 theLutData->
inputLutWordSize =
bit_breite_elut;
01237 }
01238 theLutData->
inputLutEntryCount = theElutSize /
sizeof(
UINT16);
01239 }
01240
for (loop = 1; loop < theLutData->
colorLutInDim; loop++)
01241
BlockMoveData(
DATA_2_PTR(localElut), (
Ptr)
DATA_2_PTR(localElut) + loop * theElutSize, theElutSize);
01242 }
01243
else
01244 {
01245
01246
01247
01248 trcSig[0] =
icSigRedTRCTag;
01249 trcSig[1] =
icSigGreenTRCTag;
01250 trcSig[2] =
icSigBlueTRCTag;
01251
01252 singleElut =
SmartNewPtr(theElutSize, &aOSerr);
01253 err = aOSerr;
01254
if (err)
01255
goto CleanupAndExit;
01256
for (loop = 0; loop <
kNumOfRGBchannels; loop++)
01257 {
01258 err =
CMGetProfileElement(theCombiData->
theProfile, trcSig[loop], &elementSize,
nil);
01259
if (err)
01260
goto CleanupAndExit;
01261 pCurveTag = (
icCurveType *)
SmartNewPtr(elementSize, &aOSerr);
01262 err = aOSerr;
01263
if (err)
01264
goto CleanupAndExit;
01265
01266 err =
CMGetProfileElement(theCombiData->
theProfile, trcSig[loop], &elementSize, pCurveTag);
01267
#ifdef IntelMode
01268
SwapLongOffset( &pCurveTag->
base.
sig, 0, 4 );
01269 SwapLong( &pCurveTag->
curve.
count );
01270 SwapShortOffset( pCurveTag, (ULONG)((
char*)&pCurveTag->
curve.
data[0]-(
char*)pCurveTag), elementSize );
01271
#endif
01272
if (err)
01273
goto CleanupAndExit;
01274
if ( theCombiData->
doCreate_16bit_ELut )
01275 {
01276
if ((theCombiData->
doCreateLinkProfile) && (theCombiData->
profLoop == 0))
01277 err =
Fill_ushort_ELUT_from_CurveTag(pCurveTag, (
UINT16*)singleElut,
adr_breite_elut,
VAL_USED_BITS, 0);
01278
else
01279 err =
Fill_ushort_ELUT_from_CurveTag(pCurveTag, (
UINT16*)singleElut,
adr_breite_elut,
VAL_USED_BITS, theLutData->
colorLutGridPoints);
01280 theLutData->
inputLutEntryCount = (1<<
adr_breite_elut);
01281 theLutData->
inputLutWordSize =
VAL_USED_BITS;
01282 }
01283
else
01284 {
01285
if ( theCombiData->
doCreate_16bit_Combi )
01286 {
01287 err =
Fill_ushort_ELUT_from_CurveTag(pCurveTag, (
UINT16*)singleElut,
adr_breite_elut,
VAL_USED_BITS, theCombiData->
gridPointsCube);
01288 theLutData->
inputLutWordSize =
VAL_USED_BITS;
01289 }
01290
else
01291 {
01292 err =
Fill_ushort_ELUT_from_CurveTag(pCurveTag, (
UINT16*)singleElut,
adr_breite_elut,
bit_breite_elut, theCombiData->
gridPointsCube);
01293 theLutData->
inputLutWordSize =
bit_breite_elut;
01294 }
01295 theLutData->
inputLutEntryCount = (1<<
adr_breite_elut);
01296 }
01297
if (err)
01298
goto CleanupAndExit;
01299
BlockMoveData(singleElut, (
Ptr)
DATA_2_PTR(localElut) + loop * theElutSize, theElutSize);
01300 pCurveTag = (
icCurveType *)
DisposeIfPtr((
Ptr)pCurveTag);
01301 }
01302 }
01303
01304
UNLOCK_DATA(localElut);
01305 theLutData->
inputLut = localElut;
01306 localElut =
nil;
01307
01308
01309
01310 CleanupAndExit:
01311 pCurveTag = (
icCurveType *)
DisposeIfPtr((
Ptr)pCurveTag);
01312 localElut =
DISPOSE_IF_DATA(localElut);
01313 singleElut =
DisposeIfPtr(singleElut);
01314
01315
LH_END_PROC(
"Extract_TRC_Elut")
01316
return err;
01317 }
01318
01319
01320
01321
01322
01323
CMError
01324 Extract_TRC_Matrix (
CMLutParamPtr theLutData,
01325
LHCombiDataPtr theCombiData )
01326 {
01327
icXYZType colorantData[
kNumOfRGBchannels];
01328
icXYZType curMediaWhite;
01329
Matrix2D localMatrix;
01330
Matrix2D invertMatrix;
01331
OSType colorantTags[
kNumOfRGBchannels];
01332
CMError err =
noErr;
01333
OSErr aOSerr =
noErr;
01334
SINT32 loop;
01335
SINT32 i;
01336
SINT32 j;
01337
UINT32 elementSize;
01338
double factor;
01339
01340
LH_START_PROC(
"Extract_TRC_Matrix")
01341
01342
01343 colorantTags[0] =
icSigRedColorantTag;
01344 colorantTags[1] =
icSigGreenColorantTag;
01345 colorantTags[2] =
icSigBlueColorantTag;
01346
01347
01348
01349
01350
for (loop = 0; loop <
kNumOfRGBchannels; loop++)
01351 {
01352 err =
CMGetProfileElement(theCombiData->
theProfile, colorantTags[loop], &elementSize,
nil);
01353
if (err !=
noErr)
01354
goto CleanupAndExit;
01355 err =
CMGetProfileElement(theCombiData->
theProfile, colorantTags[loop], &elementSize, &colorantData[loop]);
01356
#ifdef IntelMode
01357
SwapLongOffset( &colorantData[loop].base.sig, 0, 4 );
01358 SwapLongOffset( &colorantData[loop], (ULONG)((
SINT8*)&colorantData[0].data.
data[0]-(
SINT8*)&colorantData[0]), elementSize );
01359
#endif
01360
if (err !=
noErr)
01361
goto CleanupAndExit;
01362 localMatrix[0][loop] = ((
double)colorantData[loop].data.data[0].X) / 65536. / 2.;
01363 localMatrix[1][loop] = ((
double)colorantData[loop].data.data[0].Y) / 65536. / 2.;
01364 localMatrix[2][loop] = ((
double)colorantData[loop].data.data[0].Z) / 65536. / 2.;
01365 }
01366
01367
if (theCombiData->
renderingIntent ==
icAbsoluteColorimetric)
01368 {
01369 elementSize =
sizeof(
icXYZType);
01370 err =
CMGetProfileElement(theCombiData->
theProfile,
icSigMediaWhitePointTag, &elementSize, &curMediaWhite);
01371
#ifdef IntelMode
01372
SwapLongOffset( &curMediaWhite.
base.
sig, 0, 4 );
01373 SwapLongOffset( &curMediaWhite, (ULONG)((
SINT8*)&curMediaWhite.
data.
data[0]-(
SINT8*)&curMediaWhite), elementSize );
01374
#endif
01375
if (err !=
cmElementTagNotFound)
01376 {
01377
if (err !=
noErr)
01378
goto CleanupAndExit;
01379
01380
for (i=0; i<3; i++)
01381 {
01382
if (i == 0)
01383 factor = ((
double)curMediaWhite.data.data[0].X) / 65536. / 0.9642;
01384
else if (i == 1)
01385 factor = ((
double)curMediaWhite.data.data[0].Y) / 65536.;
01386
else
01387 factor = ((
double)curMediaWhite.data.data[0].Z) / 65536. / 0.8249;
01388
01389
for (j=0; j<3; j++)
01390 localMatrix[i][j] *= factor;
01391 }
01392 }
01393 }
01394
01395
if (theCombiData->
amIPCS)
01396 {
01397
doubMatrixInvert(localMatrix, invertMatrix);
01398
BlockMoveData(invertMatrix, localMatrix, 9 *
sizeof(
double));
01399 }
01400
01401 theLutData->
matrixTRC =
SmartNewPtr(
sizeof(
Matrix2D), &aOSerr);
01402 err = aOSerr;
01403
if (err)
01404
goto CleanupAndExit;
01405
BlockMoveData(localMatrix, theLutData->
matrixTRC,
sizeof(
Matrix2D));
01406
01407
01408
01409 CleanupAndExit:
01410
01411
LH_END_PROC(
"Extract_TRC_Matrix")
01412
return err;
01413 }
01414
01415
01416
01417
01418
01419
01420
CMError
01421 ExtractAll_TRC_Luts (
CMLutParamPtr theLutData,
01422
LHCombiDataPtr theCombiData )
01423 {
01424
CMError err =
noErr;
01425
01426
LH_START_PROC(
"ExtractAll_TRC_Luts")
01427
01428 theLutData->
colorLutInDim =
kNumOfRGBchannels;
01429 theLutData->
colorLutOutDim =
kNumOfRGBchannels;
01430
01431
01432 err =
Extract_TRC_Alut( theLutData, theCombiData);
01433
if (err !=
noErr)
01434
goto CleanupAndExit;
01435
01436
01437 err =
Extract_TRC_Matrix ( theLutData, theCombiData);
01438
if (err !=
noErr)
01439
goto CleanupAndExit;
01440
01441
01442 err =
Extract_TRC_Elut( theLutData, theCombiData);
01443
if (err !=
noErr)
01444
goto CleanupAndExit;
01445
01446
01447
01448
01449 CleanupAndExit:
01450
01451
LH_END_PROC(
"ExtractAll_TRC_Luts")
01452
return err;
01453 }
01454
01455
01456
01457
01458
01459
01460
CMError
01461 Extract_Gray_Luts (
CMLutParamPtr theLutData,
01462
LHCombiDataPtr theCombiData )
01463 {
01464
CMError err =
noErr;
01465
OSErr aOSerr =
noErr;
01466
LUT_DATA_TYPE theElut =
nil;
01467
LUT_DATA_TYPE theXlut =
nil;
01468
LUT_DATA_TYPE theAlut =
nil;
01469
SINT32 theElutSize;
01470
SINT32 theAlutSize;
01471
SINT32 theXlutSize;
01472
SINT32 loop;
01473
UINT32 elementSize;
01474
UINT8* bytePtr =
nil;
01475
UINT16* wordPtr =
nil;
01476
icCurveType* pCurveTag =
nil;
01477
SINT32 theSize;
01478
01479
LH_START_PROC(
"Extract_Gray_Luts")
01480
01481 theLutData->
colorLutGridPoints = 2;
01482
01483
if (theCombiData->
amIPCS)
01484 {
01485 theLutData->
colorLutInDim = 3;
01486 theLutData->
colorLutOutDim = 1;
01487 }
else
01488 {
01489 theLutData->
colorLutInDim = 1;
01490 theLutData->
colorLutOutDim = 3;
01491 }
01492
01493
if (err)
01494
goto CleanupAndExit;
01495
01496
01497 err =
CMGetProfileElement(theCombiData->
theProfile,
icSigGrayTRCTag, &elementSize,
nil);
01498
if (err)
01499
goto CleanupAndExit;
01500 pCurveTag = (
icCurveType *)
SmartNewPtr(elementSize, &aOSerr);
01501 err = aOSerr;
01502
if (err)
01503
goto CleanupAndExit;
01504 err =
CMGetProfileElement(theCombiData->
theProfile,
icSigGrayTRCTag, &elementSize, pCurveTag);
01505
#ifdef IntelMode
01506
SwapLongOffset( &pCurveTag->
base.
sig, 0, 4 );
01507 SwapLong( &pCurveTag->
curve.
count );
01508 SwapShortOffset( pCurveTag, (ULONG)((
SINT8*)&pCurveTag->
curve.
data[0]-(
SINT8*)pCurveTag), elementSize );
01509
#endif
01510
if (err)
01511
goto CleanupAndExit;
01512
01513
01514
01515
01516
if ( theCombiData->
profileConnectionSpace ==
icSigLabData )
01517 {
01518
if (theCombiData->
amIPCS)
01519 {
01520 theXlutSize = ((1 << theLutData->
colorLutInDim)+1 ) * (theLutData->
colorLutOutDim) *
sizeof(
UINT16);
01521 theXlut =
ALLOC_DATA(theXlutSize +
sizeof (
UINT16), &aOSerr);
01522 err = aOSerr;
01523
if (err)
01524
goto CleanupAndExit;
01525
LOCK_DATA(theXlut);
01526 wordPtr = (
UINT16*)
DATA_2_PTR(theXlut);
01527 *(wordPtr ) = 0x0000;
01528 *(wordPtr + 1) = 0x0000;
01529 *(wordPtr + 2) = 0x0000;
01530 *(wordPtr + 3) = 0x0000;
01531 *(wordPtr + 4) = 0xffff;
01532 *(wordPtr + 5) = 0xffff;
01533 *(wordPtr + 6) = 0xffff;
01534 *(wordPtr + 7) = 0xffff;
01535
UNLOCK_DATA(theXlut);
01536 theLutData->
colorLutWordSize = 16;
01537 }
else
01538 {
01539 theXlutSize = (1 << theLutData->
colorLutInDim ) * (theLutData->
colorLutOutDim) *
sizeof(
UINT16);
01540 theXlut =
ALLOC_DATA(theXlutSize +
sizeof (
UINT16), &aOSerr);
01541 err = aOSerr;
01542
if (err)
01543
goto CleanupAndExit;
01544
LOCK_DATA(theXlut);
01545 wordPtr = (
UINT16*)
DATA_2_PTR(theXlut);
01546 *(wordPtr ) = 0x0000;
01547 *(wordPtr + 1) = 0x0000;
01548 *(wordPtr + 2) = 0x0000;
01549 *(wordPtr + 3) = 0xffff;
01550 *(wordPtr + 4) = 0xffff;
01551 *(wordPtr + 5) = 0xffff;
01552
UNLOCK_DATA(theXlut);
01553 theLutData->
colorLutWordSize = 16;
01554 }
01555 }
else
01556 {
01557
if (theCombiData->
amIPCS)
01558 {
01559 theLutData->
colorLutGridPoints = 3;
01560 theXlutSize = (9 * theLutData->
colorLutInDim ) * (theLutData->
colorLutOutDim) *
sizeof(
UINT16);
01561 theXlut =
ALLOC_DATA(theXlutSize + 7*
sizeof (
UINT16), &aOSerr);
01562 err = aOSerr;
01563
if (err)
01564
goto CleanupAndExit;
01565
LOCK_DATA(theXlut);
01566 wordPtr = (
UINT16*)
DATA_2_PTR(theXlut);
01567
for (loop = 0; loop < theLutData->
colorLutGridPoints; loop ++)
01568 {
01569 *wordPtr++ = 0x0000;
01570 *wordPtr++ = 0x0000;
01571 *wordPtr++ = 0x0000;
01572 *wordPtr++ = 0xffff;
01573 *wordPtr++ = 0xffff;
01574 *wordPtr++ = 0xffff;
01575 *wordPtr++ = 0xffff;
01576 *wordPtr++ = 0xffff;
01577 *wordPtr++ = 0xffff;
01578 }
01579
UNLOCK_DATA(theXlut);
01580 theLutData->
colorLutWordSize = 16;
01581 }
else
01582 {
01583 theXlutSize = (1 << theLutData->
colorLutInDim ) * (theLutData->
colorLutOutDim) *
sizeof(
UINT16);
01584 theXlut =
ALLOC_DATA(theXlutSize +
sizeof (
UINT16), &aOSerr);
01585 err = aOSerr;
01586
if (err)
01587
goto CleanupAndExit;
01588
LOCK_DATA(theXlut);
01589 wordPtr = (
UINT16*)
DATA_2_PTR(theXlut);
01590 *(wordPtr ) = 0x0000;
01591 *(wordPtr + 1) = 0x0000;
01592 *(wordPtr + 2) = 0x0000;
01593 *(wordPtr + 3) = 0x0f6d5 / 2;
01594 *(wordPtr + 4) = 0x0ffff / 2;
01595 *(wordPtr + 5) = 0x0d3c2 / 2;
01596
UNLOCK_DATA(theXlut);
01597 theLutData->
colorLutWordSize = 16;
01598 }
01599 }
01600
01601
01602
01603
01604 theElutSize = (1<<
adr_breite_elut) *
sizeof (
UINT16);
01605 theElut =
ALLOC_DATA(theElutSize * theLutData->
colorLutInDim + sizeof (
UINT16), &aOSerr);
01606 err = aOSerr;
01607
if (err)
01608
goto CleanupAndExit;
01609
LOCK_DATA(theElut);
01610
01611
if (theCombiData->
amIPCS)
01612 {
01613
01614
01615
01616
if ( theCombiData->
doCreate_16bit_ELut )
01617 {
01618
CreateLinearElut16 ( (
Ptr)
DATA_2_PTR(theElut), theElutSize /
sizeof(
UINT16), theLutData->
colorLutGridPoints, 0);
01619 theLutData->
inputLutEntryCount = theElutSize /
sizeof(
UINT16);
01620 theLutData->
inputLutWordSize =
VAL_USED_BITS;
01621 }
01622
else
01623 {
01624
if ( theCombiData->
doCreate_16bit_Combi )
01625 {
01626
CreateLinearElut16 ( (
Ptr)
DATA_2_PTR(theElut), theElutSize /
sizeof(
UINT16), theCombiData->
gridPointsCube, 0);
01627 theLutData->
inputLutWordSize =
VAL_USED_BITS;
01628 }
01629
else
01630 {
01631
CreateLinearElut ( (
Ptr)
DATA_2_PTR(theElut), theElutSize /
sizeof(
UINT16), theCombiData->
gridPointsCube, 0);
01632 theLutData->
inputLutWordSize =
bit_breite_elut;
01633 }
01634 theLutData->
inputLutEntryCount = theElutSize /
sizeof(
UINT16);
01635 }
01636 }
01637
else
01638 {
01639
01640
01641
01642
if ( theCombiData->
doCreate_16bit_ELut )
01643 {
01644 err =
Fill_ushort_ELUT_from_CurveTag(pCurveTag, (
UINT16*)
DATA_2_PTR(theElut),
adr_breite_elut,
VAL_USED_BITS, theLutData->
colorLutGridPoints);
01645 theLutData->
inputLutEntryCount = (1<<
adr_breite_elut);
01646 theLutData->
inputLutWordSize =
VAL_USED_BITS;
01647 }
01648
else
01649 {
01650
if ( theCombiData->
doCreate_16bit_Combi )
01651 {
01652 err =
Fill_ushort_ELUT_from_CurveTag(pCurveTag, (
UINT16*)
DATA_2_PTR(theElut),
adr_breite_elut,
VAL_USED_BITS, theCombiData->
gridPointsCube);
01653 theLutData->
inputLutWordSize =
VAL_USED_BITS;
01654 }
01655
else
01656 {
01657 err =
Fill_ushort_ELUT_from_CurveTag(pCurveTag, (
UINT16*)
DATA_2_PTR(theElut),
adr_breite_elut,
bit_breite_elut, theCombiData->
gridPointsCube);
01658 theLutData->
inputLutWordSize =
bit_breite_elut;
01659 }
01660 theLutData->
inputLutEntryCount = (1<<
adr_breite_elut);
01661 }
01662
01663 }
01664
for (loop = 1; loop < (theLutData->
colorLutInDim); loop++)
01665
BlockMoveData(
DATA_2_PTR(theElut), (
Ptr)
DATA_2_PTR(theElut) + loop * theElutSize, theElutSize);
01666
UNLOCK_DATA(theElut);
01667
01668
01669
01670
01671
if ( theCombiData->
doCreate_16bit_ALut || theCombiData->
doCreate_16bit_Combi )
01672 theSize =
sizeof(
UINT16);
01673
else
01674 theSize =
sizeof(
UINT8);
01675
01676 theAlutSize = (1<<
adr_breite_alut);
01677 theAlut =
ALLOC_DATA(theLutData->
colorLutOutDim * theAlutSize * theSize + theSize, &aOSerr);
01678 err = aOSerr;
01679
if (err)
01680
goto CleanupAndExit;
01681
01682
LOCK_DATA(theAlut);
01683
if (theCombiData->
amIPCS)
01684 {
01685
01686
01687
01688
if ( theCombiData->
doCreate_16bit_ALut || theCombiData->
doCreate_16bit_Combi )
01689 {
01690 err =
Fill_inverse_ushort_ALUT_from_CurveTag( pCurveTag, (
UINT16*)
DATA_2_PTR(theAlut),
adr_breite_alut);
01691
if (err)
01692
goto CleanupAndExit;
01693 theLutData->
outputLutEntryCount = (
SINT16)theAlutSize;
01694 theLutData->
outputLutWordSize =
VAL_USED_BITS;
01695 }
01696
else
01697 {
01698 err =
Fill_inverse_byte_ALUT_from_CurveTag( pCurveTag, (
UINT8*)
DATA_2_PTR(theAlut),
adr_breite_alut);
01699
if (err)
01700
goto CleanupAndExit;
01701 theLutData->
outputLutEntryCount = (
SINT16)theAlutSize;
01702 theLutData->
outputLutWordSize =
bit_breite_alut;
01703 }
01704 }
else
01705 {
01706
01707
01708
01709
if ( theCombiData->
doCreate_16bit_ALut || theCombiData->
doCreate_16bit_Combi )
01710 {
01711
CreateLinearAlut16 ( (
UINT16 *)
DATA_2_PTR(theAlut), theAlutSize);
01712 theLutData->
outputLutEntryCount = (
SINT16)theAlutSize;
01713 theLutData->
outputLutWordSize =
VAL_USED_BITS;
01714
if ( theCombiData->
profileConnectionSpace ==
icSigLabData )
01715
SetMem16((
Ptr)
DATA_2_PTR(theAlut) + theAlutSize * theSize, (theLutData->
colorLutOutDim -1 ) * theAlutSize, 0x08000);
01716
else
01717 {
01718
for (loop = 1; loop < theLutData->
colorLutOutDim; loop++)
01719
BlockMoveData(
DATA_2_PTR(theAlut), (
Ptr)
DATA_2_PTR(theAlut) + loop * theAlutSize *
sizeof(
UINT16), theAlutSize *
sizeof(
UINT16));
01720 }
01721 }
01722
else
01723 {
01724
CreateLinearAlut ( (
UINT8 *)
DATA_2_PTR(theAlut), theAlutSize);
01725 theLutData->
outputLutEntryCount = theAlutSize;
01726 theLutData->
outputLutWordSize =
VAL_USED_BITS;
01727
if ( theCombiData->
profileConnectionSpace ==
icSigLabData )
01728
SetMem((
Ptr)
DATA_2_PTR(theAlut) + theAlutSize * theSize, (theLutData->
colorLutOutDim -1 ) * theAlutSize * theSize, 0x080);
01729
else
01730 {
01731
for (loop = 1; loop < theLutData->
colorLutOutDim; loop++)
01732
BlockMoveData(
DATA_2_PTR(theAlut), (
Ptr)
DATA_2_PTR(theAlut) + loop * theAlutSize, theAlutSize);
01733 }
01734 }
01735 }
01736
UNLOCK_DATA(theAlut);
01737
01738
01739 theLutData->
inputLut = theElut; theElut =
nil;
01740 theLutData->
outputLut = theAlut; theAlut =
nil;
01741 theLutData->
colorLut = theXlut; theXlut =
nil;
01742
01743
01744
01745
01746 CleanupAndExit:
01747 pCurveTag = (
icCurveType*)
DisposeIfPtr((
Ptr)pCurveTag);
01748 theElut =
DISPOSE_IF_DATA(theElut);
01749 theAlut =
DISPOSE_IF_DATA(theAlut);
01750 theXlut =
DISPOSE_IF_DATA(theXlut);
01751
01752
LH_END_PROC(
"Extract_Gray_Luts")
01753
return err;
01754 }
01755
01756
01757
01758
01759
01760
01761
CMError
01762 ExtractAllLuts (
CMLutParamPtr theLutData,
01763
LHCombiDataPtr theCombiData )
01764 {
01765
CMError err =
noErr;
01766
OSType theTag;
01767
01768
LH_START_PROC(
"ExtractAllLuts")
01769
01770
01771
if ( theCombiData->
doCreateGamutLut )
01772 theTag =
icSigGamutTag;
01773
else
01774 {
01775
switch (theCombiData->
renderingIntent)
01776 {
01777
case icPerceptual:
01778
if (theCombiData->
usePreviewTag)
01779 theTag =
icSigPreview0Tag;
01780
else
01781 {
01782
if (theCombiData->
amIPCS)
01783 theTag =
icSigBToA0Tag;
01784
else
01785 theTag =
icSigAToB0Tag;
01786 }
01787
break;
01788
case icRelativeColorimetric:
01789
if (theCombiData->
usePreviewTag)
01790 theTag =
icSigPreview1Tag;
01791
else
01792 {
01793
if (theCombiData->
amIPCS)
01794 theTag =
icSigBToA1Tag;
01795
else
01796 theTag =
icSigAToB1Tag;
01797 }
01798
break;
01799
case icSaturation:
01800
if (theCombiData->
usePreviewTag)
01801 theTag =
icSigPreview2Tag;
01802
else
01803 {
01804
if (theCombiData->
amIPCS)
01805 theTag =
icSigBToA2Tag;
01806
else
01807 theTag =
icSigAToB2Tag;
01808 }
01809
break;
01810
case icAbsoluteColorimetric:
01811
if (theCombiData->
usePreviewTag)
01812 theTag =
icSigPreview1Tag;
01813
else
01814 {
01815
if (theCombiData->
amIPCS)
01816 theTag =
icSigBToA1Tag;
01817
else
01818 theTag =
icSigAToB1Tag;
01819 }
01820
break;
01821
default:
01822 err =
cmProfileError;
01823
break;
01824 }
01825 }
01826
#ifdef DEBUG_OUTPUT
01827
if ( DebugCheck(kThisFile, kDebugMiscInfo) )
01828
DebugPrint(
" ExtractAllLuts: theTag = '%4.4s'=0x%08X (renderingIntent = %d)\n", &theTag, theTag, theCombiData->
renderingIntent );
01829
#endif
01830
01831
switch (theCombiData->
profileClass)
01832 {
01833
01834
01835
01836
case icSigInputClass:
01837
switch (theCombiData->
dataColorSpace)
01838 {
01839
case icSigGrayData:
01840 err =
Extract_Gray_Luts( theLutData, theCombiData);
01841
break;
01842
case icSigRgbData:
01843 err =
ExtractAll_MFT_Luts( theLutData, theCombiData, theTag );
01844
if ( err !=
noErr && theCombiData->
renderingIntent !=
icPerceptual )
01845 {
01846
if (theCombiData->
amIPCS)
01847 theTag =
icSigBToA0Tag;
01848
else
01849 theTag =
icSigAToB0Tag;
01850
#ifdef DEBUG_OUTPUT
01851
if ( DebugCheck(kThisFile, kDebugErrorInfo) )
01852
DebugPrint(
"� 'scnr': ExtractAll_MFT_Luts failed - continuing with '%4.4s'...\n", &theTag);
01853
#endif
01854
err =
ExtractAll_MFT_Luts( theLutData, theCombiData, theTag );
01855 }
01856
if (( err !=
noErr ) && (theCombiData->
profileConnectionSpace ==
icSigXYZData ))
01857 {
01858
01859
#ifdef DEBUG_OUTPUT
01860
if ( DebugCheck(kThisFile, kDebugErrorInfo) )
01861
DebugPrint(
"� 'scnr': ExtractAll_MFT_Luts failed - continuing with TRC...\n");
01862
#endif
01863
err =
ExtractAll_TRC_Luts( theLutData, theCombiData );
01864 }
01865
break;
01866
case icSigCmykData:
01867 err =
ExtractAll_MFT_Luts( theLutData, theCombiData, theTag );
01868
if ( err !=
noErr && theCombiData->
renderingIntent !=
icPerceptual )
01869 {
01870
if (theCombiData->
amIPCS)
01871 theTag =
icSigBToA0Tag;
01872
else
01873 theTag =
icSigAToB0Tag;
01874
#ifdef DEBUG_OUTPUT
01875
if ( DebugCheck(kThisFile, kDebugErrorInfo) )
01876
DebugPrint(
"� 'scnr': ExtractAll_MFT_Luts failed - continuing with '%4.4s'...\n", &theTag);
01877
#endif
01878
err =
ExtractAll_MFT_Luts( theLutData, theCombiData, theTag );
01879 }
01880
break;
01881
default:
01882
01883
if (theCombiData->
amIPCS)
01884 theTag =
icSigBToA0Tag;
01885
else
01886 theTag =
icSigAToB0Tag;
01887 err =
ExtractAll_MFT_Luts( theLutData, theCombiData, theTag );
01888
break;
01889 }
01890
break;
01891
01892
01893
01894
case icSigDisplayClass:
01895
switch (theCombiData->
dataColorSpace)
01896 {
01897
case icSigGrayData:
01898 err =
Extract_Gray_Luts( theLutData, theCombiData);
01899
break;
01900
case icSigRgbData:
01901
if ( theCombiData->
doCreateGamutLut)
01902 {
01903 err =
DoMakeGamutForMonitor( theLutData, theCombiData );
01904 }
else
01905 {
01906 err =
ExtractAll_MFT_Luts(theLutData, theCombiData, theTag);
01907
if (( err !=
noErr ) && (theCombiData->
profileConnectionSpace ==
icSigXYZData ))
01908 {
01909
01910
#ifdef DEBUG_OUTPUT
01911
if ( DebugCheck(kThisFile, kDebugErrorInfo) )
01912
DebugPrint(
"� 'mntr': ExtractAll_MFT_Luts failed - continuing with TRC...\n");
01913
#endif
01914
err =
ExtractAll_TRC_Luts( theLutData, theCombiData );
01915 }
01916 }
01917
break;
01918
case icSigCmykData:
01919
default:
01920 err =
ExtractAll_MFT_Luts(theLutData, theCombiData, theTag);
01921
break;
01922 }
01923
break;
01924
01925
01926
01927
case icSigOutputClass:
01928
switch (theCombiData->
dataColorSpace)
01929 {
01930
case icSigGrayData:
01931 err =
Extract_Gray_Luts( theLutData, theCombiData );
01932
break;
01933
case icSigRgbData:
01934
case icSigCmykData:
01935
default:
01936 err =
ExtractAll_MFT_Luts( theLutData, theCombiData, theTag );
01937
break;
01938 }
01939
break;
01940
01941
01942
01943
case icSigLinkClass:
01944 err =
ExtractAll_MFT_Luts( theLutData, theCombiData,
icSigAToB0Tag );
01945
break;
01946
01947
01948
01949
case icSigColorSpaceClass:
01950
if (theCombiData->
amIPCS)
01951 err =
ExtractAll_MFT_Luts( theLutData, theCombiData,
icSigBToA0Tag );
01952
else
01953 err =
ExtractAll_MFT_Luts( theLutData, theCombiData,
icSigAToB0Tag );
01954
break;
01955
01956
01957
01958
case icSigAbstractClass:
01959 err =
ExtractAll_MFT_Luts( theLutData, theCombiData,
icSigAToB0Tag );
01960
break;
01961
default:
01962 err =
cmProfileError;
01963
break;
01964 }
01965
01966
LH_END_PROC(
"ExtractAllLuts")
01967
return err;
01968 }
01969
#ifdef RenderInt
01970
long GetActualRenderingIntent(
CMMModelPtr CMSession, UINT32 i )
01971 {
01972
long Render;
01973 Render =
icAbsoluteColorimetric;
01974
if( CMSession->dwFlags &
kUseRelColorimetric ) Render =
icRelativeColorimetric;
01975
if( i == 0xffffffff )
return Render;
01976
01977
if( CMSession-> aIntentArr && CMSession-> nIntents >= 1 ){
01978
if( i < CMSession-> nIntents ){
01979 Render = CMSession-> aIntentArr[i];
01980 }
01981 }
01982
return Render;
01983 }
01984
#endif
01985
CMError InitNamedColorProfileData( CMMModelPtr storage,
01986 CMProfileRef aProf,
01987
long pcs,
01988
long *theDeviceCoords);
01989
01990
01991
01992
01993
01994
01995
01996
01997
01998
CMError
01999 Create_LH_ProfileSet ( CMMModelPtr CMSession,
02000
CMConcatProfileSet* profileSet,
02001
LHConcatProfileSet** newProfileSet )
02002 {
02003
icHeader profHeader;
02004
LHConcatProfileSet* theProfileSet;
02005
CMProfileRef theProfile;
02006
OSType previousDataColorSpace = 0x20202020;
02007
OSType previousConnectionSpace = 0x20202020;
02008
UINT32 previousRenderingIntent;
02009
CMError err =
noErr;
02010
OSErr aOSerr =
noErr;
02011
UINT32 elementSize = 0;
02012
SINT16 max;
02013
SINT16 theSize;
02014
SINT16 index = 0;
02015
UINT16 profLoop;
02016
Boolean amIPCS =
FALSE;
02017
OSType theTag;
02018
UINT32 intentIndex = 0;
02019
long nDeviceCoords;
02020
02021
LH_START_PROC(
"Create_LH_ProfileSet")
02022
02023 nDeviceCoords=0;
02024
max = profileSet->
count * 3;
02025 theSize =
sizeof (
LHConcatProfileSet) +
sizeof(
LHProfile) *
max;
02026 theProfileSet = (
LHConcatProfileSet *)
SmartNewPtrClear(theSize, &aOSerr);
02027 err = aOSerr;
02028
if (err)
02029
goto CleanupAndExit;
02030
02031 theProfileSet->
keyIndex = profileSet->
keyIndex;
02032
02033 CMSession->hasNamedColorProf =
NoNamedColorProfile;
02034
for ( profLoop = 0; profLoop < profileSet->
count; profLoop++ )
02035 {
02036 err =
CMGetProfileHeader(profileSet->
profileSet[profLoop], (
CMCoreProfileHeader *)&profHeader);
02037
if (err)
02038
goto CleanupAndExit;
02039
if (profLoop == 0){
02040
#ifdef RenderInt
02041
if( CMSession->
dwFlags != 0xffffffff ){
02042 profHeader.
renderingIntent = GetActualRenderingIntent( CMSession, profLoop );
02043 }
02044
#endif
02045
theProfileSet->
prof[index].
renderingIntent = profHeader.
renderingIntent;
02046 }
02047
else{
02048
#ifdef RenderInt
02049
if( CMSession->
dwFlags != 0xffffffff ){
02050 profHeader.
renderingIntent = GetActualRenderingIntent( CMSession, profLoop );
02051 previousRenderingIntent = profHeader.
renderingIntent;
02052 }
02053
#endif
02054
theProfileSet->
prof[index].
renderingIntent = previousRenderingIntent;
02055 }
02056
if ( (profLoop > 0) && (profLoop < profileSet->
count - 1) )
02057 {
02058
02059
if( profHeader.
deviceClass ==
icSigColorSpaceClass )
02060
continue;
02061
if( profHeader.
deviceClass ==
icSigNamedColorClass ){
02062 err =
cmCantConcatenateError;
02063
goto CleanupAndExit;
02064 }
02065 }
02066
02067
02068
02069
if( profHeader.
deviceClass ==
icSigNamedColorClass ){
02070 err =
InitNamedColorProfileData( CMSession, profileSet->
profileSet[profLoop], profHeader.
pcs, &nDeviceCoords );
02071
if (err)
02072
goto CleanupAndExit;
02073 profHeader.
pcs =
icSigLabData;
02074
if( profileSet->
count == 1 ){
02075 CMSession->hasNamedColorProf =
NamedColorProfileOnly;
02076
02077 }
02078
else if( profLoop == 0 ){
02079 CMSession->hasNamedColorProf =
NamedColorProfileAtBegin;
02080 profHeader.
colorSpace =
icSigNamedData;
02081 CMSession->firstColorSpace =
icSigNamedData;
02082 theProfileSet->
prof[index].
pcsConversionMode =
kNoInfo;
02083 theProfileSet->
prof[index].
profileSet = 0;
02084 index++;
02085 theProfileSet->
prof[index].
renderingIntent = previousRenderingIntent;
02086 previousDataColorSpace = (
OSType)profHeader.
colorSpace;
02087 }
02088
else if( profLoop == profileSet->
count-1 ){
02089 CMSession->hasNamedColorProf =
NamedColorProfileAtEnd;
02090 CMSession->lastColorSpace =
icSigNamedData;
02091 profHeader.
colorSpace =
icSigNamedData;
02092 theProfileSet->
prof[index].
pcsConversionMode =
kNoInfo;
02093 theProfileSet->
prof[index].
profileSet = 0;
02094 index++;
02095 theProfileSet->
prof[index].
renderingIntent = previousRenderingIntent;
02096 }
02097 }
02098
if (amIPCS)
02099 {
02100
if (previousConnectionSpace != (
OSType)profHeader.
pcs)
02101 {
02102
02103
if (previousConnectionSpace ==
icSigLabData)
02104 theProfileSet->
prof[index].
pcsConversionMode =
kDoLab2XYZ;
02105
else
02106 theProfileSet->
prof[index].
pcsConversionMode =
kDoXYZ2Lab;
02107 index++;
02108 theProfileSet->
prof[index].
renderingIntent = previousRenderingIntent;
02109 }
02110 }
else if (index > 0)
02111 {
02112
if ( previousDataColorSpace != (
OSType)profHeader.
colorSpace)
02113 {
02114
02115 theProfileSet->
prof[index].
profileSet = theProfileSet->
prof[index-1].
profileSet;
02116 index++;
02117 theProfileSet->
count = index;
02118
02119
if (previousConnectionSpace != (
OSType)profHeader.
pcs)
02120 {
02121
02122
if (previousConnectionSpace ==
icSigLabData)
02123 theProfileSet->
prof[index].
pcsConversionMode =
kDoLab2XYZ;
02124
else
02125 theProfileSet->
prof[index].
pcsConversionMode =
kDoXYZ2Lab;
02126 theProfileSet->
prof[index].
renderingIntent = previousRenderingIntent;
02127 index++;
02128 }
02129
02130 previousDataColorSpace = profHeader.
colorSpace;
02131 previousConnectionSpace = profHeader.
pcs;
02132 amIPCS =
TRUE;
02133 }
02134 }
02135
02136
02137
02138
02139 theProfileSet->
prof[index].
profileSet = profileSet->
profileSet[profLoop];
02140
if( profHeader.
deviceClass ==
icSigNamedColorClass ){
02141 theProfileSet->
prof[index].
profileSet = 0;
02142 }
02143 index++;
02144
if( intentIndex < CMSession-> nIntents -1 ) intentIndex++;
02145
02146
02147
02148
02149
02150
if( amIPCS && (profLoop > 0) && (profLoop < profileSet->
count - 1) )
02151 {
02152
02153
if (profHeader.
deviceClass ==
icSigColorSpaceClass)
02154 index--;
02155
else
02156 {
02157
02158 theProfile = theProfileSet->
prof[index-1].
profileSet;
02159
02160
02161
switch (previousRenderingIntent)
02162 {
02163
case icPerceptual:
02164 theTag =
icSigPreview0Tag;
02165
break;
02166
02167
case icRelativeColorimetric:
02168 theTag =
icSigPreview1Tag;
02169
break;
02170
02171
case icSaturation:
02172 theTag =
icSigPreview2Tag;
02173
break;
02174
02175
case icAbsoluteColorimetric:
02176 theTag =
icSigPreview1Tag;
02177
break;
02178
02179
default:
02180 err =
cmProfileError;
02181
goto CleanupAndExit;
02182 }
02183 err =
CMGetProfileElement(theProfile, theTag, &elementSize,
nil);
02184
02185
if (err ==
noErr)
02186 {
02187 theProfileSet->
prof[index-1].
usePreviewTag =
TRUE;
02188 theProfileSet->
prof[index-1].
renderingIntent = profHeader.
renderingIntent;
02189 }
else
02190 {
02191
02192
if ( (profHeader.
deviceClass !=
icSigAbstractClass) && (profHeader.
deviceClass !=
icSigLinkClass) && (profHeader.
deviceClass !=
icSigNamedColorClass) )
02193 {
02194
#ifdef RenderInt
02195
if( CMSession->
dwFlags != 0xffffffff ){
02196 profHeader.
renderingIntent = GetActualRenderingIntent( CMSession, 0xffffffff );
02197 }
02198
#endif
02199
theProfileSet->
prof[index].
profileSet = profileSet->
profileSet[profLoop];
02200 theProfileSet->
prof[index].
renderingIntent = profHeader.
renderingIntent;
02201 index++;
02202 }
02203 }
02204 amIPCS =
FALSE;
02205 }
02206 }
02207 theProfileSet->
count = index;
02208 previousDataColorSpace = profHeader.
colorSpace;
02209 previousConnectionSpace = profHeader.
pcs;
02210 previousRenderingIntent = profHeader.
renderingIntent;
02211
02212
if( profHeader.
deviceClass ==
icSigLinkClass ){
02213 previousDataColorSpace = profHeader.
pcs;
02214 amIPCS =
TRUE;
02215 }
02216
if (amIPCS)
02217 amIPCS = (previousDataColorSpace ==
icSigLabData) || (previousDataColorSpace ==
icSigXYZData);
02218
else
02219 amIPCS =
TRUE;
02220 }
02221
02222
#ifdef ALLOW_DEVICE_LINK
02223
if( (CMSession)->appendDeviceLink ){
02224
if( previousDataColorSpace == (CMSession)->lastColorSpace ){
02225 theProfileSet->
prof[index].
profileSet = profileSet->
profileSet[profLoop];
02226 theProfileSet->
prof[index].
renderingIntent =
icPerceptual;
02227 index++;
02228 theProfileSet->
count = index;
02229 err =
CMGetProfileHeader(profileSet->
profileSet[profLoop], (
CMCoreProfileHeader *)&profHeader);
02230
if (err)
02231
goto CleanupAndExit;
02232 (CMSession)->lastColorSpace = profHeader.
pcs;
02233 }
02234
else{
02235 err =
cmCantConcatenateError;
02236
goto CleanupAndExit;
02237 }
02238 }
02239
if( CMSession->hasNamedColorProf ==
NamedColorProfileAtEnd || CMSession->hasNamedColorProf ==
NamedColorProfileOnly ){
02240 theProfileSet->
count--;
02241 }
02242
if( CMSession->hasNamedColorProf ==
NamedColorProfileAtBegin ){
02243 theProfileSet->
count--;
02244
for( profLoop=0; profLoop<theProfileSet->
count; profLoop++){
02245 theProfileSet->
prof[profLoop] = theProfileSet->
prof[profLoop+1];
02246 }
02247 }
02248
#endif
02249
*newProfileSet = theProfileSet;
02250 theProfileSet =
nil;
02251
02252
02253
02254 CleanupAndExit:
02255 theProfileSet = (
LHConcatProfileSet *)
DisposeIfPtr((
Ptr)theProfileSet);
02256
02257
LH_END_PROC(
"Create_LH_ProfileSet")
02258
return err;
02259 }
02260
02261 #define DoLabSpecial
02262
#ifdef DoLabSpecial
02263
OSErr MakeSpecialCube16(
long inputDim,
02264
long *theCubeSize,
02265 CUBE_DATA_TYPE *theCube,
02266
long *theBits,
02267
long *theExtraSize );
02268 OSErr MakeSpecialCube16(
long inputDim,
02269
long *theCubeSize,
02270 CUBE_DATA_TYPE *theCube,
02271
long *theBits,
02272
long *theExtraSize )
02273 {
02274
long needBits,theSize,aExtraSize;
02275
long i,gridPoints;
02276
OSErr err =
noErr;
02277
UINT16 *cube =
nil;
02278
CUBE_DATA_TYPE tempCube;
02279
02280
LH_START_PROC(
"MakeSpecialCube16")
02281 err =
CalcGridPoints4Cube(*theCubeSize, inputDim, &gridPoints, &needBits);
02282
if (err)
02283
goto CleanupAndExit;
02284
02285 theSize = 1;
02286 aExtraSize = 1;
02287
for( i=0; i<(inputDim-1); ++i){
02288 theSize *= gridPoints;
02289 aExtraSize += theSize;
02290 }
02291
02292
#ifdef ALLOW_MMX
02293
aExtraSize++;
02294
#endif
02295
theSize *= gridPoints;
02296
02297 *theExtraSize = aExtraSize;
02298 *theCubeSize = theSize * inputDim;
02299 tempCube =
ALLOC_DATA( (theSize+aExtraSize) * inputDim*2, &err);
02300
if (err !=
noErr)
02301
goto CleanupAndExit;
02302
LOCK_DATA(tempCube);
02303 cube = (
UINT16*)
DATA_2_PTR(tempCube);
02304
02305 *theBits = needBits;
02306
if( inputDim == 3)
02307 {
02308
register unsigned long aShift;
02309
register long j,k;
02310
register UINT16 aI, aJ, aK;
02311 aShift = (16 - needBits);
02312
02313 gridPoints /= 2;
02314 needBits--;
02315
for( i=0; i<=gridPoints; ++i){
02316 aI = (
UINT16)(i<< aShift);
02317
for( j=0; j<=gridPoints; ++j){
02318 aJ = (
UINT16)(j<< aShift);
02319
for( k=0; k<=gridPoints; ++k){
02320 *cube++ = aI;
02321 *cube++ = aJ;
02322 aK = (
UINT16)(k<< aShift);
02323 *cube++ = aK;
02324 }
02325
for( k=1; k<gridPoints; ++k){
02326 *cube++ = aI;
02327 *cube++ = aJ;
02328 aK = (
UINT16)(k<< aShift);
02329 aK |= aK >> needBits;
02330 aK |= aK >> (2*needBits);
02331 aK |= aK >> (4*needBits);
02332 *cube++ = aK+0x08000;
02333 }
02334 }
02335
for( j=1; j<gridPoints; ++j){
02336 aJ = (
UINT16)(j<< aShift);
02337 aJ |= aJ >> needBits;
02338 aJ |= aJ >> (2*needBits);
02339 aJ |= aJ >> (4*needBits);
02340 aJ += 0x08000;
02341
for( k=0; k<=gridPoints; ++k){
02342 *cube++ = aI;
02343 *cube++ = aJ;
02344 aK = (
UINT16)(k<< aShift);
02345 *cube++ = aK;
02346 }
02347
for( k=1; k<gridPoints; ++k){
02348 *cube++ = aI;
02349 *cube++ = aJ;
02350 aK = (
UINT16)(k<< aShift);
02351 aK |= aK >> needBits;
02352 aK |= aK >> (2*needBits);
02353 aK |= aK >> (4*needBits);
02354 *cube++ = aK+0x08000;
02355 }
02356 }
02357 }
02358
for( i=1; i<gridPoints; ++i){
02359 aI = (
UINT16)(i<< aShift);
02360 aI |= aI >> needBits;
02361 aI |= aI >> (2*needBits);
02362 aI |= aI >> (4*needBits);
02363 aI += 0x08000;
02364
for( j=0; j<=gridPoints; ++j){
02365 aJ = (
UINT16)(j<< aShift);
02366
for( k=0; k<=gridPoints; ++k){
02367 *cube++ = aI;
02368 *cube++ = aJ;
02369 aK = (
UINT16)(k<< aShift);
02370 *cube++ = aK;
02371 }
02372
for( k=1; k<gridPoints; ++k){
02373 *cube++ = aI;
02374 *cube++ = aJ;
02375 aK = (
UINT16)(k<< aShift);
02376 aK |= aK >> needBits;
02377 aK |= aK >> (2*needBits);
02378 aK |= aK >> (4*needBits);
02379 *cube++ = aK+0x08000;
02380 }
02381 }
02382
for( j=1; j<gridPoints; ++j){
02383 aJ = (
UINT16)(j<< aShift);
02384 aJ |= aJ >> needBits;
02385 aJ |= aJ >> (2*needBits);
02386 aJ |= aJ >> (4*needBits);
02387 aJ += 0x08000;
02388
for( k=0; k<=gridPoints; ++k){
02389 *cube++ = aI;
02390 *cube++ = aJ;
02391 aK = (
UINT16)(k<< aShift);
02392 *cube++ = aK;
02393 }
02394
for( k=1; k<gridPoints; ++k){
02395 *cube++ = aI;
02396 *cube++ = aJ;
02397 aK = (
UINT16)(k<< aShift);
02398 aK |= aK >> needBits;
02399 aK |= aK >> (2*needBits);
02400 aK |= aK >> (4*needBits);
02401 *cube++ = aK+0x08000;
02402 }
02403 }
02404 }
02405 }
02406
UNLOCK_DATA(tempCube);
02407 *theCube = tempCube;
02408 CleanupAndExit:
02409
LH_END_PROC(
"MakeSpecialCube16")
02410
return err;
02411 }
02412
#endif
02413
02414
02415
02416
02417
02418
02419
02420
02421
02422
CMError
02423 CreateCombi ( CMMModelPtr modelingData,
02424
CMConcatProfileSet* profileSet,
02425
LHConcatProfileSet* newProfileSet,
02426
CMLutParamPtr finalLutData,
02427 Boolean createGamutLut )
02428 {
02429
icHeader profHeader;
02430
CMLutParam aDoNDimTableData;
02431
DoMatrixForCubeStruct aDoMatrixForCubeStruct;
02432
CMCalcParam calcParam;
02433
02434
CMError err =
noErr;
02435
OSErr aOSerr =
noErr;
02436
CUBE_DATA_TYPE inputBuffer =
nil;
02437
CUBE_DATA_TYPE outputBuffer =
nil;
02438
02439
SINT32 loop;
02440
SINT32 theSize;
02441
SINT32 theElutSize;
02442
SINT32 theAlutSize;
02443
SINT32 theCubeSize;
02444
SINT32 theExtraSize=1;
02445
SINT32 theCubePixelCount;
02446
UINT16 profLoop;
02447
SINT32 savedGridPoints;
02448
SINT32 gridBits;
02449
SINT32 gridPointsCube;
02450
Boolean SavedoCreate_16bit_XLut;
02451
Boolean SavedoCreate_16bit_ALut;
02452
void *SaveoutputLut;
02453
long SaveoutputLutEntryCount;
02454
long SaveoutputLutWordSize;
02455
02456
UINT8 bIsLabConnection = 0;
02457
02458
SINT32 numOfElutsCube;
02459
02460
Boolean doSaveElut =
TRUE;
02461
Boolean skipCombi =
FALSE;
02462
Boolean pcsConversion =
FALSE;
02463
Boolean useOutputBuffer;
02464
LHCombiData theCombiData;
02465
CMLutParam theLutData;
02466
SINT32 theBufferByteCount;
02467
UINT16 aUINT16;
02468
UINT16 *wordPtr =
nil;
02469
UINT8 *xlutPtr =
nil;
02470
#ifdef DoLabSpecial
02471
UINT32 aFac;
02472
UINT32 i;
02473
#endif
02474
02475
#ifdef WRITE_LUTS
02476
Str255 fileString;
02477
#endif
02478
#ifdef DEBUG_OUTPUT
02479
Str255 lutString;
02480
#endif
02481
LH_START_PROC(
"CreateCombi")
02482
02483 theBufferByteCount = 2;
02484
SetMem(&theCombiData,
sizeof(
LHCombiData), 0);
02485
SetMem(&theLutData,
sizeof(
CMLutParam), 0);
02486
02487 theCombiData.
amIPCS =
FALSE;
02488
if ( modelingData->hasNamedColorProf ==
NamedColorProfileAtBegin ){
02489 theCombiData.
amIPCS =
TRUE;
02490 }
02491
if (newProfileSet->
count == 1)
02492 skipCombi =
TRUE;
02493
02494 err =
CMGetProfileHeader(profileSet->
profileSet[0], (
CMCoreProfileHeader *)&profHeader);
02495
if (err)
02496
goto CleanupAndExit;
02497 modelingData->precision = (
SINT16)((profHeader.
flags &
kQualityMask)>>16);
02498
02499
#ifdef RenderInt
02500
if( modelingData->
dwFlags != 0xffffffff ){
02501 modelingData->precision = (
short)( modelingData->dwFlags & 0x0ffff);
02502 }
02503
#endif
02504
if ( modelingData->precision >=
cmBestMode )
02505 {
02506 theCombiData.
doCreate_16bit_Combi =
TRUE;
02507 modelingData->precision =
cmBestMode;
02508 }
02509
else
02510 {
02511 theCombiData.
doCreate_16bit_Combi =
FALSE;
02512 }
02513
#ifdef DEBUG_OUTPUT
02514
if ( DebugCheck(kThisFile, kDebugMiscInfo) )
02515
DebugPrint(
" CMMModelHandle->precision = %d doCreate_16bit_Combi=%d\n",modelingData->precision,theCombiData.
doCreate_16bit_Combi);
02516
#endif
02517
02518
switch (modelingData->precision)
02519 {
02520
case cmNormalMode:
02521
if (createGamutLut)
02522 theCubePixelCount = 87382;
02523
else
02524 theCubePixelCount = 87382;
02525
if( modelingData->lookup )theCubePixelCount = 87382;
02526
break;
02527
case cmDraftMode:
02528
if (createGamutLut)
02529 theCubePixelCount = 5462;
02530
else
02531 theCubePixelCount = 5462;
02532
break;
02533
case cmBestMode:
02534
if (createGamutLut)
02535 theCubePixelCount = 87382;
02536
else
02537 theCubePixelCount = 87382;
02538
break;
02539 }
02540 theCubeSize = theCubePixelCount * 3;
02541 theCombiData.
precision = modelingData->precision;
02542 theCombiData.
maxProfileCount = newProfileSet->
count-1;
02543 theCombiData.
doCreateLinkProfile = (modelingData->currentCall ==
kCMMNewLinkProfile);
02544
switch ( modelingData->firstColorSpace )
02545 {
02546
case icSigXYZData:
02547
case icSigLabData:
02548
case icSigLuvData:
02549
case icSigYxyData:
02550
case icSigRgbData:
02551
case icSigHsvData:
02552
case icSigHlsData:
02553
case icSigCmyData:
02554
#ifdef PI_Application_h
02555
case icSigYCbCrData:
02556
case icSigMCH3Data:
02557
case icSigNamedData:
02558
#endif
02559
err =
CalcGridPoints4Cube ( theCubeSize, 3, &theCombiData.
gridPointsCube, &gridBits );
02560
break;
02561
case icSigGrayData:
02562 theCubeSize = 255 ;
02563 err =
CalcGridPoints4Cube ( theCubeSize, 1, &theCombiData.
gridPointsCube, &gridBits );
02564
break;
02565
case icSigCmykData:
02566
case icSigMCH4Data:
02567 err =
CalcGridPoints4Cube ( theCubeSize, 4, &theCombiData.
gridPointsCube, &gridBits );
02568
break;
02569
case icSigMCH2Data:
02570 err =
CalcGridPoints4Cube ( theCubeSize, 2, &theCombiData.
gridPointsCube, &gridBits );
02571
break;
02572
case icSigMCH5Data:
02573 err =
CalcGridPoints4Cube ( theCubeSize, 5, &theCombiData.
gridPointsCube, &gridBits );
02574
break;
02575
case icSigMCH6Data:
02576 err =
CalcGridPoints4Cube ( theCubeSize, 6, &theCombiData.
gridPointsCube, &gridBits );
02577
break;
02578
case icSigMCH7Data:
02579 err =
CalcGridPoints4Cube ( theCubeSize, 7, &theCombiData.
gridPointsCube, &gridBits );
02580
break;
02581
case icSigMCH8Data:
02582 err =
CalcGridPoints4Cube ( theCubeSize, 8, &theCombiData.
gridPointsCube, &gridBits );
02583
break;
02584 }
02585
02586 bIsLabConnection = 0;
02587
if( profHeader.
pcs ==
icSigXYZData ){
02588
for ( profLoop = 0; profLoop < newProfileSet->
count; profLoop++ ){
02589
if( newProfileSet->
prof[profLoop].
profileSet == 0 ){
02590 bIsLabConnection |= 1;
02591 }
02592 }
02593 }
02594 err =
CMGetProfileHeader(profileSet->
profileSet[profileSet->
count-1], (
CMCoreProfileHeader *)&profHeader);
02595
if (err)
02596
goto CleanupAndExit;
02597
if( profHeader.
pcs ==
icSigXYZData ){
02598
for ( profLoop = 0; profLoop < newProfileSet->
count; profLoop++ ){
02599
if( newProfileSet->
prof[profLoop].
profileSet == 0 && !createGamutLut ){
02600 bIsLabConnection |=2;
02601 }
02602 }
02603 }
02604
02605
if( modelingData->hasNamedColorProf ==
NamedColorProfileAtBegin ){
02606 bIsLabConnection |=1;
02607 theCombiData.
doCreate_16bit_Combi =
TRUE;
02608 }
02609
02610
if( modelingData->hasNamedColorProf ==
NamedColorProfileAtEnd ){
02611 bIsLabConnection |=2;
02612 theCombiData.
doCreate_16bit_Combi =
TRUE;
02613 }
02614
02615
02616
02617
02618
for ( profLoop = 0; profLoop < newProfileSet->
count; profLoop++ )
02619 {
02620
#ifdef DEBUG_OUTPUT
02621
if ( DebugCheck(kThisFile, kDebugMiscInfo) )
02622
DebugPrint(
" <��������������������� Processing profile #%d ���������������������>\n",profLoop);
02623
#endif
02624
theCombiData.
profLoop = (
long)profLoop;
02625
if ( theCombiData.
doCreateLinkProfile )
02626 {
02627 theCombiData.
doCreate_16bit_ELut =
TRUE;
02628 theCombiData.
doCreate_16bit_XLut =
TRUE;
02629 theCombiData.
doCreate_16bit_ALut =
TRUE;
02630 }
else
02631 {
02632 theCombiData.
doCreate_16bit_ELut = ( profLoop != 0 );
02633 theCombiData.
doCreate_16bit_XLut = theCombiData.
doCreate_16bit_Combi;
02634 theCombiData.
doCreate_16bit_ALut = ( profLoop != newProfileSet->
count-1 );
02635 }
02636
if (newProfileSet->
prof[profLoop].
profileSet)
02637 {
02638 theCombiData.
theProfile = newProfileSet->
prof[profLoop].
profileSet;
02639 err =
CMGetProfileHeader(theCombiData.
theProfile, (
CMCoreProfileHeader *)&profHeader);
02640
if (err)
02641
goto CleanupAndExit;
02642 theCombiData.
profileClass = profHeader.
deviceClass;
02643 theCombiData.
dataColorSpace = profHeader.
colorSpace;
02644 theCombiData.
profileConnectionSpace = profHeader.
pcs;
02645 theCombiData.
renderingIntent = newProfileSet->
prof[profLoop].
renderingIntent;
02646 pcsConversion =
FALSE;
02647 }
02648
else{
02649 pcsConversion =
TRUE;
02650 }
02651
if ( (err ==
noErr) || pcsConversion ){
02652
02653 theLutData.
inputLut =
DISPOSE_IF_DATA(theLutData.
inputLut);
02654 theLutData.
outputLut =
DISPOSE_IF_DATA(theLutData.
outputLut);
02655 theLutData.
colorLut =
DISPOSE_IF_DATA(theLutData.
colorLut);
02656 theLutData.
matrixMFT =
DisposeIfPtr(theLutData.
matrixMFT);
02657 theLutData.
matrixTRC =
DisposeIfPtr(theLutData.
matrixTRC);
02658
02659
if (pcsConversion)
02660 {
02661
02662
02663
02664
if (inputBuffer ==
nil)
02665 {
02666 theLutData.
colorLutInDim = 3;
02667
#ifdef DoLabSpecial
02668
if( modelingData->firstColorSpace ==
icSigLabData || modelingData->firstColorSpace ==
icSigLuvData ){
02669 err =
MakeSpecialCube16(theLutData.
colorLutInDim, &theCubeSize, &theLutData.
colorLut, &gridBits, &theExtraSize );
02670 }
02671
else
02672
#endif
02673
err =
MakeCube16(theLutData.
colorLutInDim, &theCubeSize, &theLutData.
colorLut, &gridBits, &theExtraSize );
02674
#ifdef DEBUG_OUTPUT
02675
if ( DebugCheck(kThisFile, kDebugMiscInfo) )
02676
DebugPrint(
" MakeCube16 -> '%d' bits cubeSize = %d\n",gridBits, theCubeSize);
02677
#endif
02678
if (err)
02679
goto CleanupAndExit;
02680 theCubePixelCount = theCubeSize / theLutData.
colorLutInDim;
02681 numOfElutsCube = theLutData.
colorLutInDim;
02682 gridPointsCube = 1<<gridBits;
02683 savedGridPoints = gridPointsCube;
02684
if( profLoop == 0 ){
02685 theLutData.
inputLutEntryCount = 1<<
adr_breite_elut;
02686
if( theCombiData.
doCreate_16bit_ELut ) theLutData.
inputLutWordSize =
VAL_USED_BITS;
02687
else theLutData.
inputLutWordSize =
bit_breite_elut;
02688 theLutData.
colorLutGridPoints = gridPointsCube;
02689 }
02690
02691 }
02692
else{
02693 theLutData.
colorLut = inputBuffer;
02694 inputBuffer =
nil;
02695 }
02696
02697
LOCK_DATA(theLutData.
colorLut);
02698
#ifdef DEBUG_OUTPUT
02699
ShowCube16( profLoop,
"Lab<->XYZ", createGamutLut, (
UINT16 *)
DATA_2_PTR(theLutData.
colorLut), gridPointsCube, theLutData.
colorLutInDim, 3,
VAL_USED_BITS );
02700
#endif
02701
02702
02703
02704
02705
02706
02707
02708
02709
02710
02711
02712
02713
02714
02715
02716
if ( newProfileSet->
prof[profLoop].
pcsConversionMode ==
kDoLab2XYZ )
02717 {
02718
#ifdef DEBUG_OUTPUT
02719
if ( DebugCheck(kThisFile, kDebugMiscInfo) )
02720
DebugPrint(
" doing a PCS conversion: Lab -> XYZ\n");
02721
#endif
02722
Lab2XYZ_forCube16((
UINT16*)
DATA_2_PTR(theLutData.
colorLut), theCubePixelCount);
02723 }
02724
else if ( newProfileSet->
prof[profLoop].
pcsConversionMode ==
kDoXYZ2Lab )
02725 {
02726
#ifdef DEBUG_OUTPUT
02727
if ( DebugCheck(kThisFile, kDebugMiscInfo) )
02728
DebugPrint(
" doing a PCS conversion: XYZ -> Lab\n");
02729
#endif
02730
XYZ2Lab_forCube16((
UINT16*)
DATA_2_PTR(theLutData.
colorLut), theCubePixelCount);
02731 }
02732
#ifdef DEBUG_OUTPUT
02733
ShowCube16( profLoop,
"after Lab<->XYZ", createGamutLut, (
UINT16 *)
DATA_2_PTR(theLutData.
colorLut), gridPointsCube, theLutData.
colorLutInDim, 3,
VAL_USED_BITS );
02734
#endif
02735
UNLOCK_DATA(theLutData.
colorLut);
02736 skipCombi =
TRUE;
02737 theLutData.
colorLutInDim =
kNumOfLab_XYZchannels;
02738 theLutData.
colorLutOutDim =
kNumOfLab_XYZchannels;
02739 }
else
02740 {
02741
02742
02743
02744 theCombiData.
doCreateGamutLut = createGamutLut && (profLoop == newProfileSet->
count - 1);
02745 theCombiData.
usePreviewTag = (
UINT8)newProfileSet->
prof[profLoop].
usePreviewTag;
02746
02747
02748
02749
02750
02751
if( bIsLabConnection & 1 ){
02752
if ( theCombiData.
maxProfileCount > 0 ){
02753 theCombiData.
maxProfileCount = 0;
02754 SavedoCreate_16bit_XLut = theCombiData.
doCreate_16bit_XLut;
02755 theCombiData.
doCreate_16bit_XLut =
TRUE;
02756 }
02757 }
02758
if( bIsLabConnection & 2 ){
02759 SavedoCreate_16bit_ALut = theCombiData.
doCreate_16bit_ALut;
02760 theCombiData.
doCreate_16bit_ALut =
TRUE;
02761 }
02762 err =
ExtractAllLuts (&theLutData, &theCombiData);
02763
if( newProfileSet->
count == 1 ){
02764 gridPointsCube = theLutData.
colorLutGridPoints;
02765 }
02766
02767
if( bIsLabConnection & 1 ){
02768 theCombiData.
maxProfileCount = newProfileSet->
count-1;
02769
if ( theCombiData.
maxProfileCount > 0 ){
02770 theCombiData.
doCreate_16bit_XLut = SavedoCreate_16bit_XLut;
02771 }
02772 }
02773
if( bIsLabConnection & 2 ){
02774 theCombiData.
doCreate_16bit_ALut = SavedoCreate_16bit_ALut;
02775 }
02776
02777
if (err)
02778
goto CleanupAndExit;
02779
if ( (theLutData.
colorLutInDim == 0) || (theLutData.
colorLutOutDim == 0))
02780 {
02781 err =
cmProfileError;
02782
goto CleanupAndExit;
02783 }
02784 }
02785
#ifdef DEBUG_OUTPUT
02786
if ( DebugCheck(kThisFile, kDebugEXASizeInfo) )
02787 {
02788
if (theLutData.
inputLut)
02789
DebugPrint(
" Elut = %6d\n", (theLutData.
inputLutEntryCount*theLutData.
colorLutInDim*(theLutData.
inputLutWordSize>8?2:1)));
02790
if (theLutData.
colorLut)
02791
DebugPrint(
" Xlut colorLutGridPoints = %6d\n colorLutInDim = %6d\n colorLutOutDim = %6d\n colorLutWordSize = %6d\n",
02792 theLutData.
colorLutGridPoints,theLutData.
colorLutInDim,theLutData.
colorLutOutDim,theLutData.
colorLutWordSize);
02793
if (theLutData.
outputLut)
02794
DebugPrint(
" Alut = %6d ", (theLutData.
outputLutEntryCount*theLutData.
colorLutOutDim*(theLutData.
outputLutWordSize>8?2:1)));
02795
DebugPrint(
"\n");
02796 }
02797
#endif
02798
if (theLutData.
matrixMFT)
02799 skipCombi =
FALSE;
02800
02801
02802
02803
if (doSaveElut)
02804 {
02805
if ( skipCombi )
02806 savedGridPoints = theLutData.
colorLutGridPoints;
02807
else
02808 {
02809
if (theLutData.
colorLutInDim == 1)
02810 {
02811 theCubeSize = 255 ;
02812 }
02813
02814
#ifdef DoLabSpecial
02815
if( modelingData->firstColorSpace ==
icSigLabData || modelingData->firstColorSpace ==
icSigLuvData ){
02816 err =
MakeSpecialCube16(theLutData.
colorLutInDim, &theCubeSize, &inputBuffer, &gridBits, &theExtraSize );
02817 }
02818
else
02819
#endif
02820
err =
MakeCube16(theLutData.
colorLutInDim, &theCubeSize, &inputBuffer, &gridBits, &theExtraSize);
02821
#ifdef DEBUG_OUTPUT
02822
if ( DebugCheck(kThisFile, kDebugMiscInfo) )
02823
DebugPrint(
" MakeCube16 -> '%d' bits cubeSize = %d\n",gridBits, theCubeSize);
02824
#endif
02825
if (err)
02826
goto CleanupAndExit;
02827 theCubePixelCount = theCubeSize / theLutData.
colorLutInDim;
02828 numOfElutsCube = theLutData.
colorLutInDim;
02829 gridPointsCube = 1<<gridBits;
02830 savedGridPoints = gridPointsCube;
02831 }
02832
02833
02834 theSize = theLutData.
inputLutEntryCount * theLutData.
colorLutInDim;
02835
if ( theLutData.
inputLutWordSize > 8 )
02836 theSize *= 2;
02837
02838
if( bIsLabConnection & 1 ){
02839
02840 finalLutData->
inputLut =
ALLOC_DATA(theSize+2, &aOSerr);
02841 err = aOSerr;
02842
if (err)
02843
goto CleanupAndExit;
02844
02845
02846 theElutSize = theSize / theLutData.
colorLutInDim;
02847
LOCK_DATA(finalLutData->
inputLut);
02848
if( theCombiData.
doCreate_16bit_ELut || theCombiData.
doCreate_16bit_Combi){
02849
CreateLinearElut16 ( (
Ptr)
DATA_2_PTR(finalLutData->
inputLut), theElutSize/ sizeof (
UINT16), gridPointsCube, 0 );
02850 finalLutData->
inputLutWordSize =
VAL_USED_BITS;
02851 }
02852
else{
02853
CreateLinearElut ( (
Ptr)
DATA_2_PTR(finalLutData->
inputLut), theElutSize/ sizeof (
UINT16), gridPointsCube, 0 );
02854 finalLutData->
inputLutWordSize =
bit_breite_elut;
02855 }
02856
for (loop = 0; loop < theLutData.
colorLutInDim; loop++)
02857
BlockMoveData(
DATA_2_PTR(finalLutData->
inputLut), (
Ptr)
DATA_2_PTR(finalLutData->
inputLut) + loop * theElutSize, theElutSize);
02858 finalLutData->
inputLutEntryCount = theElutSize/
sizeof(
UINT16);
02859
UNLOCK_DATA(finalLutData->
inputLut);
02860 finalLutData->
colorLutInDim = theLutData.
colorLutInDim;
02861 bIsLabConnection &= ~1;
02862 }
02863
else{
02864 finalLutData->
inputLutWordSize = theLutData.
inputLutWordSize;
02865 finalLutData->
inputLut = theLutData.
inputLut;
02866 finalLutData->
inputLutEntryCount = theLutData.
inputLutEntryCount;
02867 finalLutData->
colorLutInDim = theLutData.
colorLutInDim;
02868
02869 theLutData.
inputLut =
ALLOC_DATA(theSize+2, &aOSerr);
02870 err = aOSerr;
02871
if (err)
02872
goto CleanupAndExit;
02873
02874
02875 theElutSize = theSize / theLutData.
colorLutInDim;
02876
LOCK_DATA(theLutData.
inputLut);
02877
CreateLinearElut16 ( (
Ptr)
DATA_2_PTR(theLutData.
inputLut), theElutSize/ sizeof (
UINT16), theLutData.
colorLutGridPoints, 0);
02878
for (loop = 0; loop < theLutData.
colorLutInDim; loop++)
02879
BlockMoveData(
DATA_2_PTR(theLutData.
inputLut), (
Ptr)
DATA_2_PTR(theLutData.
inputLut) + loop * theElutSize, theElutSize);
02880 theLutData.
inputLutEntryCount = theElutSize/
sizeof(
UINT16);
02881 theLutData.
inputLutWordSize =
VAL_USED_BITS;
02882
UNLOCK_DATA(theLutData.
inputLut);
02883 }
02884 doSaveElut =
FALSE;
02885
#ifdef DoLabSpecial
02886
if( (modelingData->firstColorSpace ==
icSigLabData || modelingData->firstColorSpace ==
icSigLuvData) ){
02887
LOCK_DATA(finalLutData->
inputLut);
02888 wordPtr = (
UINT16 *)
DATA_2_PTR( finalLutData->
inputLut );
02889 aFac = (((1<<15)*((
UINT32)finalLutData->
inputLutEntryCount-1)*(
UINT32)gridPointsCube + finalLutData->
inputLutEntryCount/2)/
02890 (
UINT32)finalLutData->
inputLutEntryCount + gridPointsCube/2)/((
UINT32)gridPointsCube-1);
02891 i = finalLutData->
inputLutEntryCount/2 - 1;
02892
for( aUINT16 = 0; aUINT16 < (
UINT16)finalLutData->
colorLutInDim; aUINT16++){
02893
for( loop = 0; loop <= (
SINT32)(i+1); loop++){
02894 *wordPtr++ = (
UINT16)((*wordPtr * aFac + (1<<(15-1)) )>>15);
02895 }
02896
02897
for( loop = 1; loop <= (
SINT32)i; loop++){
02898 *wordPtr++ = (
UINT16)((*wordPtr * ((aFac *( i - loop ) + (1<<15) * loop + i/2)/i) + (1<<(15-1)) )>>15);
02899 }
02900 }
02901
UNLOCK_DATA(finalLutData->
inputLut);
02902 }
02903
#endif
02904
}
02905
02906
02907
02908
02909
if (profLoop == newProfileSet->
count - 1)
02910 {
02911
02912 theSize = theLutData.
outputLutEntryCount * theLutData.
colorLutOutDim;
02913
if ( theLutData.
outputLutWordSize > 8 )
02914 theSize *= 2;
02915
if( bIsLabConnection & 2 ){
02916 SaveoutputLut = theLutData.
outputLut;
02917 SaveoutputLutEntryCount = theLutData.
outputLutEntryCount;
02918 SaveoutputLutWordSize = theLutData.
outputLutWordSize;
02919 }
02920
else{
02921 finalLutData->
outputLut = theLutData.
outputLut;
02922 finalLutData->
outputLutEntryCount = theLutData.
outputLutEntryCount;
02923 finalLutData->
outputLutWordSize = theLutData.
outputLutWordSize;
02924 }
02925 finalLutData->
colorLutOutDim = theLutData.
colorLutOutDim;
02926
02927 theAlutSize = (1<<
adr_breite_alut);
02928
if (theCombiData.
doCreate_16bit_ALut || theCombiData.
doCreate_16bit_Combi)
02929 {
02930 theSize =
sizeof(
UINT16);;
02931 theLutData.
outputLut =
ALLOC_DATA(theLutData.
colorLutOutDim * theAlutSize * theSize+theSize, &aOSerr);
02932 err = aOSerr;
02933
if (err)
02934
goto CleanupAndExit;
02935
LOCK_DATA(theLutData.
outputLut);
02936
CreateLinearAlut16 ( (
UINT16 *)
DATA_2_PTR(theLutData.
outputLut), theAlutSize);
02937
for (loop = 1; loop < theLutData.
colorLutOutDim; loop++)
02938
BlockMoveData(
DATA_2_PTR(theLutData.
outputLut), (
Ptr)
DATA_2_PTR(theLutData.
outputLut) + loop * theAlutSize *
sizeof(
UINT16), theAlutSize *
sizeof(
UINT16));
02939 theLutData.
outputLutEntryCount = (
SINT16)theAlutSize;
02940 theLutData.
outputLutWordSize =
VAL_USED_BITS;
02941
UNLOCK_DATA(theLutData.
outputLut);
02942 }
02943
else
02944 {
02945 theSize =
sizeof(
UINT8);;
02946 theLutData.
outputLut =
ALLOC_DATA(theLutData.
colorLutOutDim * theAlutSize * theSize+theSize, &aOSerr);
02947 err = aOSerr;
02948
if (err)
02949
goto CleanupAndExit;
02950
LOCK_DATA(theLutData.
outputLut);
02951
02952
CreateLinearAlut( (
UINT8*)
DATA_2_PTR(theLutData.
outputLut), theAlutSize );
02953
for (loop = 1; loop < theLutData.
colorLutOutDim; loop++)
02954
BlockMoveData(
DATA_2_PTR(theLutData.
outputLut), (
Ptr)
DATA_2_PTR(theLutData.
outputLut) + loop * theAlutSize, theAlutSize);
02955 theLutData.
outputLutEntryCount = theAlutSize;
02956 theLutData.
outputLutWordSize =
bit_breite_alut;
02957
UNLOCK_DATA(theLutData.
outputLut);
02958 theBufferByteCount = 1;
02959 }
02960
if( bIsLabConnection & 2 ){
02961 bIsLabConnection &= ~2;
02962 finalLutData->
outputLut = theLutData.
outputLut;
02963 finalLutData->
outputLutEntryCount = theLutData.
outputLutEntryCount;
02964 finalLutData->
outputLutWordSize = theLutData.
outputLutWordSize;
02965 theLutData.
outputLut = SaveoutputLut;
02966 theLutData.
outputLutEntryCount = SaveoutputLutEntryCount;
02967 theLutData.
outputLutWordSize = SaveoutputLutWordSize;
02968 }
02969 }
02970
02971
if (skipCombi)
02972 {
02973
02974
02975
02976
if (newProfileSet->
count == 1){
02977 theSize = 1;
02978 theExtraSize = 1;
02979
for( loop=0; loop<(theLutData.
colorLutInDim-1); ++loop){
02980 theSize *=theLutData.
colorLutGridPoints ;
02981 theExtraSize += theSize;
02982 }
02983 theSize = 1;
02984
for( loop=0; loop<theLutData.
colorLutInDim; ++loop){
02985 theSize *= theLutData.
colorLutGridPoints;
02986 }
02987 theSize *= theLutData.
colorLutOutDim;
02988
#ifdef ALLOW_MMX
02989
theExtraSize++;
02990
#endif
02991
theExtraSize *= theLutData.
colorLutOutDim;
02992 inputBuffer =
DISPOSE_IF_DATA(inputBuffer);
02993
if( theCombiData.
doCreate_16bit_Combi ){
02994 inputBuffer =
ALLOC_DATA( (theSize+theExtraSize) * 2, &aOSerr );
02995 err = aOSerr;
02996
if (err)
02997
goto CleanupAndExit;
02998
02999
LOCK_DATA(theLutData.
colorLut);
03000
LOCK_DATA(inputBuffer);
03001 wordPtr = (
UINT16 *)
DATA_2_PTR( inputBuffer );
03002 xlutPtr = (
UINT8 *)
DATA_2_PTR( theLutData.
colorLut );
03003
if( theLutData.
colorLutWordSize == 8 ){
03004
for( loop=0; loop<theSize; ++loop){
03005 aUINT16 = (
UINT16)xlutPtr[loop];
03006 wordPtr[loop] = (aUINT16<<8) | aUINT16;
03007 }
03008 }
03009
else{
03010
BlockMoveData( xlutPtr, wordPtr, theSize * 2 );
03011 }
03012
UNLOCK_DATA(theLutData.
colorLut);
03013
UNLOCK_DATA(inputBuffer);
03014 theLutData.
colorLut = inputBuffer;
03015 theLutData.
colorLutWordSize = 16;
03016 inputBuffer = 0;
03017 }
03018
else{
03019 inputBuffer =
ALLOC_DATA( (theSize+theExtraSize), &aOSerr );
03020 err = aOSerr;
03021
if (err)
03022
goto CleanupAndExit;
03023
03024
LOCK_DATA(theLutData.
colorLut);
03025
LOCK_DATA(inputBuffer);
03026 wordPtr = (
UINT16 *)
DATA_2_PTR( inputBuffer );
03027 xlutPtr = (
UINT8 *)
DATA_2_PTR( theLutData.
colorLut );
03028
BlockMoveData( xlutPtr, wordPtr, theSize );
03029
UNLOCK_DATA(theLutData.
colorLut);
03030
UNLOCK_DATA(inputBuffer);
03031
DISPOSE_IF_DATA( theLutData.
colorLut );
03032 theLutData.
colorLut = inputBuffer;
03033 theLutData.
colorLutWordSize = 8;
03034 inputBuffer = 0;
03035 }
03036
03037
03038
03039
03040
03041
03042
03043
03044
03045
03046
03047
03048
03049
03050
03051
03052
03053
03054
03055
03056
03057
03058
03059
03060
03061
03062
03063
03064 }
03065 inputBuffer =
DISPOSE_IF_DATA(inputBuffer);
03066 inputBuffer = theLutData.
colorLut;
03067
if (inputBuffer){
03068 theCubeSize = theCubePixelCount * theLutData.
colorLutInDim;
03069 theCubeSize *= theLutData.
colorLutOutDim;
03070 }
03071 theLutData.
colorLut = 0;
03072
if ( (profLoop == newProfileSet->
count - 1) && ( ! theCombiData.
doCreate_16bit_ALut && !theCombiData.
doCreate_16bit_Combi) )
03073 theBufferByteCount = 1;
03074
03075 }
else
03076 {
03077
03078
03079
03080
if (theLutData.
matrixTRC)
03081 {
03082
03083
03084
03085
LOCK_DATA(theLutData.
inputLut);
03086
LOCK_DATA(theLutData.
outputLut);
03087
LOCK_DATA(inputBuffer);
03088
#ifdef DEBUG_OUTPUT
03089
if ( DebugCheck(kThisFile, kDebugMiscInfo) )
03090 {
03091
DebugPrint(
"� matrixTRC: calling DoMatrixForCube16 (gridPointsCube = %d inputBuffer = %d)\n", gridPointsCube, theCubeSize);
03092
DebugPrint(
" theLutData.colorLutGridPoints = %d\n", theLutData.
colorLutGridPoints);
03093
DebugPrint(
" %f %f %f\n %f %f %f\n %f %f %f\n",
03094 (*(
Matrix2D *)theLutData.
matrixTRC)[0][0],(*(
Matrix2D *)theLutData.
matrixTRC)[0][1],(*(
Matrix2D *)theLutData.
matrixTRC)[0][2],
03095 (*(
Matrix2D *)theLutData.
matrixTRC)[1][0],(*(
Matrix2D *)theLutData.
matrixTRC)[1][1],(*(
Matrix2D *)theLutData.
matrixTRC)[1][2],
03096 (*(
Matrix2D *)theLutData.
matrixTRC)[2][0],(*(
Matrix2D *)theLutData.
matrixTRC)[2][1],(*(
Matrix2D *)theLutData.
matrixTRC)[2][2]);
03097 }
03098
if ( createGamutLut )
03099 {
03100
if (DebugLutCheck(kDisplayEXAGamut) )
03101 {
03102 lutString[0] =
sprintf((
SINT8*)&lutString[1],
"Gamut-E Lut #%d @ matrixTRC", profLoop);
03103 DoDisplayLutNew(lutString,&theLutData, 0);
03104 lutString[0] =
sprintf((
SINT8*)&lutString[1],
"Gamut-A Lut #%d @ matrixTRC", profLoop);
03105 DoDisplayLutNew(lutString,&theLutData, 2);
03106 }
03107 }
else if (DebugLutCheck(kDebugEXAReal))
03108 {
03109
03110 lutString[0] =
sprintf((
SINT8*)&lutString[1],
"E Lut #%d @ matrixTRC", profLoop);
03111 DoDisplayLutNew(lutString,&theLutData, 0);
03112 lutString[0] =
sprintf((
SINT8*)&lutString[1],
"A Lut #%d @ matrixTRC", profLoop);
03113 DoDisplayLutNew(lutString,&theLutData, 2);
03114 }
03115
#endif
03116
#ifdef WRITE_LUTS
03117
if ( !createGamutLut )
03118 {
03119 fileString[0] =
sprintf((
SINT8*)&fileString[1],
"E Lut #%d @ matrixTRC", profLoop);
03120 WriteLut2File( fileString,theLutData.
inputLut, 'ELUT');
03121 fileString[0] =
sprintf((
SINT8*)&fileString[1],
"A Lut #%d @ matrixTRC", profLoop);
03122 WriteLut2File( fileString,theLutData.
outputLut, 'ALUT');
03123 }
03124
#endif
03125
aDoMatrixForCubeStruct.
aElutAdrSize = theLutData.
inputLutEntryCount;
03126 aDoMatrixForCubeStruct.
aElutAdrShift = 0;
03127 aDoMatrixForCubeStruct.
aElutWordSize = theLutData.
inputLutWordSize;
03128 aDoMatrixForCubeStruct.
separateEluts =
TRUE;
03129 aDoMatrixForCubeStruct.
ein_lut = (
UINT16 *)
DATA_2_PTR(theLutData.
inputLut);
03130 aDoMatrixForCubeStruct.
aAlutAdrSize = theLutData.
outputLutEntryCount;
03131 aDoMatrixForCubeStruct.
aAlutAdrShift = 0;
03132 aDoMatrixForCubeStruct.
aAlutWordSize = theLutData.
outputLutWordSize;
03133 aDoMatrixForCubeStruct.
separateAluts =
TRUE;
03134 aDoMatrixForCubeStruct.
aus_lut = (
UINT8 *)
DATA_2_PTR(theLutData.
outputLut);
03135 aDoMatrixForCubeStruct.
theMatrix = (
Matrix2D *)theLutData.
matrixTRC;
03136 aDoMatrixForCubeStruct.
aPointCount = theCubePixelCount;
03137 aDoMatrixForCubeStruct.
gridPoints = gridPointsCube;
03138 aDoMatrixForCubeStruct.
aBufferByteCount = theBufferByteCount;
03139 aDoMatrixForCubeStruct.
theArr = (
UINT8 *)
DATA_2_PTR(inputBuffer);
03140
#ifdef DEBUG_OUTPUT
03141
ShowCube16( profLoop,
"DoMatrixForCube16", createGamutLut, (
UINT16 *)
DATA_2_PTR(inputBuffer), gridPointsCube, numOfElutsCube, 3,
VAL_USED_BITS );
03142
#endif
03143
#ifdef WRITE_LUTS
03144
if ( !createGamutLut )
03145 {
03146 fileString[0] =
sprintf((
SINT8*)&fileString[1],
"DoMat4Cube #%d (TRC)", profLoop);
03147 WriteLut2File( fileString,inputBuffer, 'XLUT');
03148 }
03149
#endif
03150
DoMatrixForCube16( &aDoMatrixForCubeStruct );
03151
#ifdef DEBUG_OUTPUT
03152
ShowCube16( profLoop,
"after DoMatrixForCube16", createGamutLut, (
UINT16 *)
DATA_2_PTR(inputBuffer), gridPointsCube, numOfElutsCube, 3, 8*theBufferByteCount );
03153
#endif
03154
#ifdef WRITE_LUTS
03155
if ( !createGamutLut )
03156 {
03157 fileString[0] =
sprintf((
SINT8*)&fileString[1],
"after DoMat4Cube #%d (TRC)", profLoop);
03158 WriteLut2File( fileString,inputBuffer, 'XLUT');
03159 }
03160
#endif
03161
03162
UNLOCK_DATA(inputBuffer);
03163
UNLOCK_DATA(theLutData.
inputLut);
03164
UNLOCK_DATA(theLutData.
outputLut);
03165
03166 }
else
03167 {
03168
03169
03170
03171
03172
03173
if ( theCombiData.
amIPCS && newProfileSet->
prof[profLoop].
renderingIntent ==
icAbsoluteColorimetric )
03174 {
03175
03176
if (!newProfileSet->
prof[profLoop].
usePreviewTag) {
03177
LOCK_DATA(inputBuffer);
03178 err =
DoAbsoluteShiftForPCS_Cube16( (
UINT16*)
DATA_2_PTR(inputBuffer), theCubePixelCount,
03179 theCombiData.
theProfile, (
Boolean)(theCombiData.
profileConnectionSpace !=
icSigLabData),
kAbsShiftBeforeDoNDim );
03180
UNLOCK_DATA(inputBuffer);
03181
if (err)
03182
goto CleanupAndExit;
03183 }
03184 }
03185
if (theLutData.
matrixMFT)
03186 {
03187
03188
03189
03190
03191
LOCK_DATA(inputBuffer);
03192
#ifdef DEBUG_OUTPUT
03193
if ( DebugCheck(kThisFile, kDebugMiscInfo) )
03194 {
03195
DebugPrint(
"� matrixMFT: calling DoOnlyMatrixForCube16\n");
03196
DebugPrint(
" %f %f %f\n %f %f %f\n %f %f %f\n",
03197 (*(
Matrix2D *)theLutData.
matrixMFT)[0][0],(*(
Matrix2D *)theLutData.
matrixMFT)[0][1],(*(
Matrix2D *)theLutData.
matrixMFT)[0][2],
03198 (*(
Matrix2D *)theLutData.
matrixMFT)[1][0],(*(
Matrix2D *)theLutData.
matrixMFT)[1][1],(*(
Matrix2D *)theLutData.
matrixMFT)[1][2],
03199 (*(
Matrix2D *)theLutData.
matrixMFT)[2][0],(*(
Matrix2D *)theLutData.
matrixMFT)[2][1],(*(
Matrix2D *)theLutData.
matrixMFT)[2][2]);
03200 }
03201
#endif
03202
#ifdef DEBUG_OUTPUT
03203
ShowCube16( profLoop,
"DoOnlyMatrixForCube16 (mft)", createGamutLut, (
UINT16 *)
DATA_2_PTR(inputBuffer), gridPointsCube, numOfElutsCube,
kNumOfLab_XYZchannels,
VAL_USED_BITS );
03204
#endif
03205
#ifdef WRITE_LUTS
03206
if ( !createGamutLut )
03207 {
03208 fileString[0] =
sprintf((
SINT8*)&fileString[1],
"DoOnlyMat4Cube #%d (mft)", profLoop);
03209 WriteLut2File( fileString,inputBuffer, 'XLUT');
03210 }
03211
#endif
03212
DoOnlyMatrixForCube16( (
Matrix2D *)theLutData.
matrixMFT, (
Ptr)
DATA_2_PTR(inputBuffer), theCubePixelCount, gridPointsCube );
03213
#ifdef DEBUG_OUTPUT
03214
ShowCube16( profLoop,
"after DoOnlyMatrixForCube16 (mft)", createGamutLut, (
UINT16 *)
DATA_2_PTR(inputBuffer), gridPointsCube, numOfElutsCube,
kNumOfLab_XYZchannels,
VAL_USED_BITS );
03215
#endif
03216
#ifdef WRITE_LUTS
03217
if ( !createGamutLut )
03218 {
03219 fileString[0] =
sprintf((
SINT8*)&fileString[1],
"DoOnlyMat4Cube #%d (mft)", profLoop);
03220 WriteLut2File( fileString,inputBuffer, 'XLUT');
03221 }
03222
#endif
03223
03224
UNLOCK_DATA(inputBuffer);
03225 }
03226
if (theLutData.
colorLutInDim >= theLutData.
colorLutOutDim && theBufferByteCount == 2 )
03227 {
03228 outputBuffer = inputBuffer;
03229 useOutputBuffer =
FALSE;
03230 }
else
03231 {
03232 outputBuffer =
ALLOC_DATA( (theCubePixelCount + theExtraSize ) * theLutData.
colorLutOutDim * theBufferByteCount, &aOSerr);
03233 err = aOSerr;
03234
if (err)
03235
goto CleanupAndExit;
03236 useOutputBuffer =
TRUE;
03237 }
03238
LOCK_DATA(inputBuffer);
03239
LOCK_DATA(outputBuffer);
03240
LOCK_DATA(theLutData.
inputLut);
03241
LOCK_DATA(theLutData.
colorLut);
03242
LOCK_DATA(theLutData.
outputLut);
03243
#ifdef DEBUG_OUTPUT
03244
if ( createGamutLut )
03245 {
03246
if ( DebugLutCheck(kDisplayEXAGamut) )
03247 {
03248 lutString[0] =
sprintf((
SINT8*)&lutString[1],
"Gamut-E Lut #%d @ DoNDim", profLoop);
03249 DoDisplayLutNew(lutString,&theLutData, 0);
03250 lutString[0] =
sprintf((
SINT8*)&lutString[1],
"Gamut-A Lut #%d @ DoNDim", profLoop);
03251 DoDisplayLutNew(lutString,&theLutData, 2);
03252 lutString[0] =
sprintf((
SINT8*)&lutString[1],
"Gamut-X Lut #%d @ DoNDim", profLoop);
03253 DoDisplayLutNew(lutString, &theLutData,1);
03254 }
03255 }
else if (DebugLutCheck(kDebugEXAReal) )
03256 {
03257 lutString[0] =
sprintf((
SINT8*)&lutString[1],
"E Lut #%d @ DoNDim", profLoop);
03258 DoDisplayLutNew(lutString,&theLutData, 0);
03259 lutString[0] =
sprintf((
SINT8*)&lutString[1],
"A Lut #%d @ DoNDim", profLoop);
03260 DoDisplayLutNew(lutString,&theLutData, 2);
03261 lutString[0] =
sprintf((
SINT8*)&lutString[1],
"X Lut #%d @ DoNDim", profLoop);
03262 DoDisplayLutNew(lutString, &theLutData,1);
03263 }
03264
#endif
03265
03266
#ifdef WRITE_LUTS
03267
if ( !createGamutLut )
03268 {
03269 fileString[0] =
sprintf((
SINT8*)&fileString[1],
"E Lut #%d @ DoNDim", profLoop);
03270 WriteLut2File( fileString,theLutData.
inputLut, 'ELUT');
03271 fileString[0] =
sprintf((
SINT8*)&fileString[1],
"A Lut #%d @ DoNDim", profLoop);
03272 WriteLut2File( fileString,theLutData.
outputLut, 'ALUT');
03273 fileString[0] =
sprintf((
SINT8*)&fileString[1],
"X Lut #%d @ DoNDim", profLoop);
03274 WriteLut2File( fileString,theLutData.
colorLut, 'XLUT');
03275 }
03276
#endif
03277
03278 calcParam.
cmInputColorSpace =
cm16PerChannelPacking;
03279 calcParam.
cmOutputColorSpace = theBufferByteCount == 1 ?
cm8PerChannelPacking :
cm16PerChannelPacking;
03280 calcParam.
cmPixelPerLine = theCubePixelCount;
03281 calcParam.
cmLineCount = 1;
03282 calcParam.
cmInputPixelOffset =
sizeof(
SINT16)*theLutData.
colorLutInDim;
03283 calcParam.
cmOutputPixelOffset = theBufferByteCount*theLutData.
colorLutOutDim;
03284 calcParam.
cmInputBytesPerLine = theCubePixelCount*calcParam.
cmInputPixelOffset;
03285 calcParam.
cmOutputBytesPerLine = theCubePixelCount*calcParam.
cmOutputPixelOffset;
03286
03287
03288
for (loop = 0; loop<theLutData.
colorLutInDim; loop++)
03289 calcParam.
inputData[loop] = (
Ptr)(
DATA_2_PTR(inputBuffer)) + loop *
sizeof(
SINT16);
03290
for (loop = 0; loop<theLutData.
colorLutOutDim; loop++)
03291 calcParam.
outputData[loop] = (
Ptr)(
DATA_2_PTR(outputBuffer)) + loop * theBufferByteCount;
03292 calcParam.
clearMask =
FALSE;
03293 calcParam.
copyAlpha =
FALSE;
03294
03295
#ifdef DEBUG_OUTPUT
03296
ShowCube16( profLoop,
"DoNDim", createGamutLut, (
UINT16 *)
DATA_2_PTR(inputBuffer), gridPointsCube, numOfElutsCube, theLutData.
colorLutInDim,
VAL_USED_BITS );
03297
#endif
03298
#ifdef WRITE_LUTS
03299
if ( !createGamutLut )
03300 {
03301 fileString[0] =
sprintf((
SINT8*)&fileString[1],
"DoNDim #%d", profLoop);
03302 WriteLut2File( fileString,inputBuffer, 'XLUT');
03303 }
03304
#endif
03305
03306 aDoNDimTableData = theLutData;
03307
#if ! LUTS_ARE_PTR_BASED
03308
aDoNDimTableData.
inputLut =
DATA_2_PTR(theLutData.inputLut);
03309 aDoNDimTableData.
colorLut =
DATA_2_PTR(theLutData.colorLut);
03310 aDoNDimTableData.
outputLut =
DATA_2_PTR(theLutData.outputLut);
03311
#endif
03312
if (theLutData.colorLutWordSize == 18)
03313 {
03314
if ( theBufferByteCount == 1 )
03315 err =
CalcNDim_Data16To8_Lut8(&calcParam, &aDoNDimTableData);
03316
else
03317 err =
CalcNDim_Data16To16_Lut8(&calcParam, &aDoNDimTableData);
03318 }
else
03319 {
03320
if ( theBufferByteCount == 1 )
03321 err =
CalcNDim_Data16To8_Lut16(&calcParam, &aDoNDimTableData);
03322
else
03323 err =
CalcNDim_Data16To16_Lut16(&calcParam, &aDoNDimTableData);
03324 }
03325
if (err)
03326
goto CleanupAndExit;
03327
#ifdef DEBUG_OUTPUT
03328
ShowCube16( profLoop,
"after DoNDim", createGamutLut, (
UINT16 *)
DATA_2_PTR(outputBuffer), gridPointsCube, numOfElutsCube, theLutData.colorLutOutDim, 8*theBufferByteCount );
03329
#endif
03330
#ifdef WRITE_LUTS
03331
if ( !createGamutLut )
03332 {
03333 fileString[0] =
sprintf((
SINT8*)&fileString[1],
"after DoNDim #%d", profLoop);
03334 WriteLut2File( fileString,outputBuffer, 'XLUT');
03335 }
03336
#endif
03337
UNLOCK_DATA(theLutData.inputLut);
03338
UNLOCK_DATA(theLutData.colorLut);
03339
UNLOCK_DATA(theLutData.outputLut);
03340
UNLOCK_DATA(inputBuffer);
03341
UNLOCK_DATA(outputBuffer);
03342
03343
03344
03345
if (newProfileSet->
prof[profLoop].
usePreviewTag && newProfileSet->
prof[profLoop].
renderingIntent ==
icAbsoluteColorimetric) {
03346
LOCK_DATA(outputBuffer);
03347 err =
DoAbsoluteShiftForPCS_Cube16( (
UINT16*)
DATA_2_PTR(outputBuffer), theCubePixelCount,
03348 theCombiData.
theProfile, (
Boolean)(theCombiData.
profileConnectionSpace !=
icSigLabData),
kAbsShiftAfterDoNDim );
03349
UNLOCK_DATA(outputBuffer);
03350
if (err)
03351
goto CleanupAndExit;
03352 }
03353
if ( !theCombiData.
amIPCS && newProfileSet->
prof[profLoop].
renderingIntent ==
icAbsoluteColorimetric )
03354 {
03355
LOCK_DATA(outputBuffer);
03356 err =
DoAbsoluteShiftForPCS_Cube16( (
UINT16*)
DATA_2_PTR(outputBuffer), theCubePixelCount,
03357 theCombiData.
theProfile, (
Boolean)(theCombiData.
profileConnectionSpace !=
icSigLabData),
kAbsShiftAfterDoNDim );
03358
UNLOCK_DATA(outputBuffer);
03359
if (err)
03360
goto CleanupAndExit;
03361 }
03362
03363
if (useOutputBuffer)
03364 {
03365 inputBuffer =
DISPOSE_IF_DATA(inputBuffer);
03366 inputBuffer = outputBuffer;
03367 }
else
03368 {
03369
03370
03371
03372
03373
03374
03375 }
03376
03377 theCubeSize = theCubePixelCount * theLutData.colorLutOutDim * theBufferByteCount;
03378 outputBuffer =
nil;
03379 }
03380 }
03381 }
03382 skipCombi =
FALSE;
03383
if( profHeader.
deviceClass ==
icSigLinkClass ){
03384 theCombiData.
dataColorSpace = profHeader.
pcs;
03385 theCombiData.
amIPCS =
TRUE;
03386 }
03387
03388
if (theCombiData.
amIPCS && !pcsConversion)
03389 theCombiData.
amIPCS = (theCombiData.
usePreviewTag ==
TRUE) || (theCombiData.
dataColorSpace ==
icSigLabData) || (theCombiData.
dataColorSpace ==
icSigXYZData);
03390
else
03391 theCombiData.
amIPCS =
TRUE;
03392 }
03393
#ifdef DEBUG_OUTPUT
03394
if ( DebugCheck(kThisFile, kDebugMiscInfo) )
03395
DebugPrint(
" <������������������������������������������������������������������>\n");
03396
#endif
03397
theLutData.
colorLut =
DISPOSE_IF_DATA(theLutData.
colorLut);
03398 theLutData.
colorLut = inputBuffer;
03399 inputBuffer =
nil;
03400
03401 finalLutData->
colorLut = theLutData.
colorLut; theLutData.
colorLut =
nil;
03402 finalLutData->
colorLutGridPoints = savedGridPoints;
03403
if ( theBufferByteCount == 1 )
03404 finalLutData->
colorLutWordSize = 8;
03405
else
03406 finalLutData->
colorLutWordSize = 16;
03407
03408
03409
03410 CleanupAndExit:
03411 inputBuffer =
DISPOSE_IF_DATA(inputBuffer);
03412 outputBuffer =
DISPOSE_IF_DATA(outputBuffer);
03413 theLutData.
inputLut =
DISPOSE_IF_DATA(theLutData.
inputLut);
03414 theLutData.
outputLut =
DISPOSE_IF_DATA(theLutData.
outputLut);
03415 theLutData.
colorLut =
DISPOSE_IF_DATA(theLutData.
colorLut);
03416 theLutData.
matrixMFT =
DisposeIfPtr(theLutData.
matrixMFT);
03417 theLutData.
matrixTRC =
DisposeIfPtr(theLutData.
matrixTRC);
03418
03419
LH_END_PROC(
"CreateCombi")
03420
return err;
03421 }
03422
03423
03424
03425
03426
03427
03428
03429
03430
03431
CMError
03432 PrepareCombiLUTs ( CMMModelPtr CMSession,
03433
CMConcatProfileSet* profileSet )
03434 {
03435
icHeader firstHeader;
03436
icHeader lastHeader;
03437
LHConcatProfileSet* newProfileSet =
nil;
03438
CMError err =
noErr;
03439
Boolean needGamutCalc =
FALSE;
03440
CMLutParam theLutData;
03441
UINT16 count;
03442
03443
LH_START_PROC(
"PrepareCombiLUTs")
03444
03445
03446
03447
SetMem(&theLutData,
sizeof(
CMLutParam), 0);
03448 count = profileSet->
count;
03449
03450
03451 err =
CMGetProfileHeader(profileSet->
profileSet[0], (
CMCoreProfileHeader *)&firstHeader);
03452
if (err)
03453
goto CleanupAndExit;
03454 (CMSession)->firstColorSpace = firstHeader.
colorSpace;
03455
03456 err =
CMGetProfileHeader(profileSet->
profileSet[count-1], (
CMCoreProfileHeader *)&lastHeader);
03457
if (err)
03458
goto CleanupAndExit;
03459 (CMSession)->lastColorSpace = lastHeader.
colorSpace;
03460
if( lastHeader.
deviceClass ==
icSigLinkClass )
03461 (CMSession)->lastColorSpace = lastHeader.
pcs;
03462
else
03463 (CMSession)->lastColorSpace = lastHeader.
colorSpace;
03464
#ifdef ALLOW_DEVICE_LINK
03465
if( count > 1 && lastHeader.
deviceClass ==
icSigLinkClass ){
03466 (CMSession)->appendDeviceLink =
TRUE;
03467 profileSet->
count--;
03468 }
03469
else{
03470 (CMSession)->appendDeviceLink =
FALSE;
03471 }
03472
#endif
03473
03474
03475
03476
03477
if ( (lastHeader.
deviceClass ==
icSigOutputClass) || (lastHeader.
deviceClass ==
icSigDisplayClass) )
03478 needGamutCalc =
TRUE;
03479
03480
if ( (CMSession)->currentCall ==
kCMMNewLinkProfile )
03481 needGamutCalc =
FALSE;
03482
03483
03484
03485
03486
03487
if ( (firstHeader.
flags &
kCreateGamutLutMask) ==
kCreateGamutLutMask)
03488 needGamutCalc =
FALSE;
03489
03490
#ifdef RenderInt
03491
if( CMSession->
dwFlags != 0xffffffff ){
03492
if( CMSession->dwFlags &
kCreateGamutLutMask ){
03493 needGamutCalc =
FALSE;
03494 }
03495
else if( lastHeader.
deviceClass ==
icSigOutputClass ||
03496 lastHeader.
deviceClass ==
icSigDisplayClass )
03497 needGamutCalc =
TRUE;
03498 }
03499
#endif
03500
03501 err =
Create_LH_ProfileSet( CMSession, profileSet, &newProfileSet);
03502
if (err)
03503
goto CleanupAndExit;
03504
03505
#ifdef DEBUG_OUTPUT
03506
if ( ! needGamutCalc && DebugCheck(kThisFile, kDebugMiscInfo) )
03507
DebugPrint(
"\n <=================== Gamut Combi is not created =================>\n\n");
03508
#endif
03509
03510
03511
03512
if( CMSession->hasNamedColorProf ==
NamedColorProfileOnly ||
03513 CMSession->hasNamedColorProf ==
NamedColorProfileAtEnd )needGamutCalc =
FALSE;
03514
if (needGamutCalc)
03515 {
03516
#ifdef DEBUG_OUTPUT
03517
if ( DebugCheck(kThisFile, kDebugMiscInfo) )
03518
DebugPrint(
" <======================= Create Gamut Combi =====================>\n");
03519
#endif
03520
if( lastHeader.
pcs !=
icSigXYZData &&
03521 lastHeader.
deviceClass ==
icSigDisplayClass &&
03522 lastHeader.
colorSpace ==
icSigRgbData ){
03523
03524 newProfileSet->
prof[newProfileSet->
count] = newProfileSet->
prof[newProfileSet->
count-1];
03525 newProfileSet->
prof[newProfileSet->
count-1].
pcsConversionMode =
kDoLab2XYZ;
03526 newProfileSet->
prof[newProfileSet->
count-1].
profileSet = 0;
03527 newProfileSet->
prof[newProfileSet->
count-1].
renderingIntent = 0;
03528 newProfileSet->
count++;
03529 }
03530 err =
CreateCombi(CMSession, profileSet, newProfileSet, &theLutData,
kDoGamutLut );
03531
if( lastHeader.
pcs !=
icSigXYZData &&
03532 lastHeader.
deviceClass ==
icSigDisplayClass &&
03533 lastHeader.
colorSpace ==
icSigRgbData ){
03534
03535 newProfileSet->
count--;
03536 newProfileSet->
prof[newProfileSet->
count-1] = newProfileSet->
prof[newProfileSet->
count];
03537 }
03538
03539
#ifdef DEBUG_OUTPUT
03540
if ( err && DebugCheck(kThisFile, kDebugErrorInfo) )
03541
DebugPrint(
"� Error: PrepareCombiLUTs - kDoGamutLut: %d\n",err);
03542
#endif
03543
03544
if (err ==
noErr)
03545 {
03546
#ifdef DEBUG_OUTPUT
03547
if (DebugLutCheck(kDisplayEXAGamut) )
03548 {
03549
LOCK_DATA(theLutData.
inputLut);
03550
LOCK_DATA(theLutData.
colorLut);
03551
LOCK_DATA(theLutData.
outputLut);
03552 DoDisplayLutNew(
"\pFINAL GAMUT E Lut", &theLutData, 0);
03553 DoDisplayLutNew(
"\pFINAL GAMUT A Lut", &theLutData, 2);
03554 DoDisplayLutNew(
"\pFINAL GAMUT X Lut", &theLutData, 1);
03555
UNLOCK_DATA(theLutData.
inputLut);
03556
UNLOCK_DATA(theLutData.
colorLut);
03557
UNLOCK_DATA(theLutData.
outputLut);
03558 }
03559
if ( DebugLutCheck( kDisplayGamut ) )
03560 {
03561
LOCK_DATA(theLutData.
colorLut);
03562
if ((CMSession)->precision ==
cmBestMode)
03563 Show32by32by32GamutXLUT(
DATA_2_PTR(theLutData.
colorLut));
03564
else
03565 Show16by16by16GamutXLUT(
DATA_2_PTR(theLutData.
colorLut));
03566
UNLOCK_DATA(theLutData.
colorLut);
03567 }
03568
#endif
03569
if (theLutData.
inputLut ==
nil)
03570 {
03571
#ifdef DEBUG_OUTPUT
03572
if ( DebugCheck(kThisFile, kDebugErrorInfo) )
03573
DebugPrint(
"� ERROR: final Gamut Elut == nil\n");
03574
#endif
03575
}
else
03576 {
03577 (CMSession)->gamutLutParam.inputLut = theLutData.
inputLut;
03578 theLutData.
inputLut =
nil;
03579 }
03580
03581
if (theLutData.
outputLut ==
nil)
03582 {
03583
#ifdef DEBUG_OUTPUT
03584
if ( DebugCheck(kThisFile, kDebugErrorInfo) )
03585
DebugPrint(
"� ERROR: final Gamut Alut == nil\n");
03586
#endif
03587
}
else
03588 {
03589 (CMSession)->gamutLutParam.outputLut = theLutData.
outputLut;
03590 theLutData.
outputLut =
nil;
03591 }
03592
03593
if (theLutData.
colorLut ==
nil)
03594 {
03595
#ifdef DEBUG_OUTPUT
03596
if ( DebugCheck(kThisFile, kDebugErrorInfo) )
03597
DebugPrint(
"� ERROR: final Gamut Xlut == nil\n");
03598
#endif
03599
}
else
03600 {
03601 (CMSession)->gamutLutParam.colorLut = theLutData.
colorLut;
03602 theLutData.
colorLut =
nil;
03603 }
03604 (CMSession)->gamutLutParam.colorLutInDim = theLutData.
colorLutInDim;
03605 (CMSession)->gamutLutParam.colorLutOutDim = theLutData.
colorLutOutDim;
03606 (CMSession)->gamutLutParam.colorLutGridPoints = theLutData.
colorLutGridPoints;
03607 (CMSession)->gamutLutParam.colorLutWordSize = theLutData.
colorLutWordSize;
03608 (CMSession)->gamutLutParam.inputLutWordSize = theLutData.
inputLutWordSize;
03609 (CMSession)->gamutLutParam.outputLutWordSize = theLutData.
outputLutWordSize;
03610 (CMSession)->gamutLutParam.inputLutEntryCount = theLutData.
inputLutEntryCount;
03611 (CMSession)->gamutLutParam.outputLutEntryCount = theLutData.
outputLutEntryCount;
03612 }
03613
else{
03614 theLutData.
inputLut =
DISPOSE_IF_DATA(theLutData.
inputLut);
03615 theLutData.
outputLut =
DISPOSE_IF_DATA(theLutData.
outputLut);
03616 theLutData.
colorLut =
DISPOSE_IF_DATA(theLutData.
colorLut);
03617 }
03618 }
03619
03620
03621
03622
#ifdef DEBUG_OUTPUT
03623
if ( DebugCheck(kThisFile, kDebugMiscInfo) )
03624
DebugPrint(
" <======================= Create real Combi ======================>\n");
03625
#endif
03626
03627 err =
CreateCombi(CMSession, profileSet, newProfileSet, &theLutData,
kDoDefaultLut );
03628
if (err){
03629 CMSession->theNamedColorTagData =
DISPOSE_IF_DATA( CMSession->theNamedColorTagData);
03630 CMSession->gamutLutParam.inputLut =
DISPOSE_IF_DATA( CMSession->gamutLutParam.inputLut);
03631 CMSession->gamutLutParam.outputLut =
DISPOSE_IF_DATA( CMSession->gamutLutParam.outputLut);
03632 CMSession->gamutLutParam.colorLut =
DISPOSE_IF_DATA( CMSession->gamutLutParam.colorLut);
03633
goto CleanupAndExit;
03634 }
03635
03636
#ifdef DEBUG_OUTPUT
03637
if (DebugLutCheck(kDebugEXAReal) )
03638 {
03639
LOCK_DATA(theLutData.
inputLut);
03640
LOCK_DATA(theLutData.
colorLut);
03641
LOCK_DATA(theLutData.
outputLut);
03642 DoDisplayLutNew(
"\pFINAL E Lut", &theLutData, 0);
03643 DoDisplayLutNew(
"\pFINAL A Lut", &theLutData, 2);
03644 DoDisplayLutNew(
"\pFINAL X Lut", &theLutData, 1);
03645
UNLOCK_DATA(theLutData.
inputLut);
03646
UNLOCK_DATA(theLutData.
colorLut);
03647
UNLOCK_DATA(theLutData.
outputLut);
03648 }
03649
#endif
03650
#ifdef WRITE_LUTS
03651
LOCK_DATA(theLutData.
inputLut);
03652
LOCK_DATA(theLutData.
colorLut);
03653
LOCK_DATA(theLutData.
outputLut);
03654 WriteLut2File(
"\pFINAL E Lut",theLutData.
inputLut, 'ELUT');
03655 WriteLut2File(
"\pFINAL A Lut",theLutData.
outputLut, 'ALUT');
03656 WriteLut2File(
"\pFINAL X Lut",theLutData.
colorLut, 'XLUT');
03657
UNLOCK_DATA(theLutData.
inputLut);
03658
UNLOCK_DATA(theLutData.
colorLut);
03659
UNLOCK_DATA(theLutData.
outputLut);
03660
#endif
03661
03662
if (theLutData.
inputLut ==
nil)
03663 {
03664
#ifdef DEBUG_OUTPUT
03665
if ( DebugCheck(kThisFile, kDebugErrorInfo) )
03666
DebugPrint(
"� ERROR: theLutData.inputLut == nil\n");
03667
#endif
03668
}
else
03669 {
03670 (CMSession)->lutParam.inputLut = theLutData.
inputLut;
03671 theLutData.
inputLut =
nil;
03672 }
03673
03674
if (theLutData.
outputLut ==
nil)
03675 {
03676
#ifdef DEBUG_OUTPUT
03677
if ( DebugCheck(kThisFile, kDebugErrorInfo) )
03678
DebugPrint(
"� ERROR: theLutData.outputLut == nil\n");
03679
#endif
03680
}
else
03681 {
03682 (CMSession)->lutParam.outputLut = theLutData.
outputLut;
03683 theLutData.
outputLut =
nil;
03684 }
03685
03686
if (theLutData.
colorLut ==
nil)
03687 {
03688
#ifdef DEBUG_OUTPUT
03689
if ( DebugCheck(kThisFile, kDebugErrorInfo) )
03690
DebugPrint(
"� ERROR: theLutData.colorLut == nil\n");
03691
#endif
03692
}
else
03693 {
03694 (CMSession)->lutParam.colorLut = theLutData.
colorLut;
03695 theLutData.
colorLut =
nil;
03696 }
03697
03698 (CMSession)->lutParam.colorLutInDim = theLutData.
colorLutInDim;
03699 (CMSession)->lutParam.colorLutOutDim = theLutData.
colorLutOutDim;
03700 (CMSession)->lutParam.colorLutGridPoints = theLutData.
colorLutGridPoints;
03701 (CMSession)->lutParam.colorLutWordSize = theLutData.
colorLutWordSize;
03702 (CMSession)->lutParam.inputLutWordSize = theLutData.
inputLutWordSize;
03703 (CMSession)->lutParam.outputLutWordSize = theLutData.
outputLutWordSize;
03704 (CMSession)->lutParam.inputLutEntryCount = theLutData.
inputLutEntryCount;
03705 (CMSession)->lutParam.outputLutEntryCount = theLutData.
outputLutEntryCount;
03706
03707
03708
03709
03710 CleanupAndExit:
03711 newProfileSet = (
LHConcatProfileSet *)
DisposeIfPtr((
Ptr)newProfileSet);
03712 theLutData.
inputLut =
DISPOSE_IF_DATA(theLutData.
inputLut);
03713 theLutData.
outputLut =
DISPOSE_IF_DATA(theLutData.
outputLut);
03714 theLutData.
colorLut =
DISPOSE_IF_DATA(theLutData.
colorLut);
03715
03716
LH_END_PROC(
"PrepareCombiLUTs")
03717
return err;
03718 }
03719
03720 CMError InitNamedColorProfileData( CMMModelPtr storage,
03721 CMProfileRef aProf,
03722
long pcs,
03723
long *theDeviceCoords )
03724 {
03725
CMError err =
noErr;
03726
UINT32 elementSize,count,nDeviceCoords,i;
03727
LUT_DATA_TYPE profileLutPtr = 0;
03728
Ptr cPtr;
03729
OSErr aOSerr;
03730
03731 *theDeviceCoords = 0;
03732
if( storage->hasNamedColorProf !=
NoNamedColorProfile ){
03733 err =
cmCantConcatenateError;
03734
goto CleanupAndExit;
03735 }
03736 err =
CMGetProfileElement(aProf,
icSigNamedColor2Tag, &elementSize,
nil);
03737
if (err)
03738
goto CleanupAndExit;
03739
03740 profileLutPtr =
ALLOC_DATA(elementSize, &aOSerr );
03741 err = aOSerr;
03742
if (err)
03743
goto CleanupAndExit;
03744
03745
LOCK_DATA(profileLutPtr);
03746 err =
CMGetProfileElement( aProf,
icSigNamedColor2Tag, &elementSize,
DATA_2_PTR(profileLutPtr) );
03747
if (err)
03748
goto CleanupAndExit;
03749
#ifdef IntelMode
03750
SwapLongOffset( &((
icNamedColor2Type*)profileLutPtr)->ncolor.count, 0, 4 );
03751 SwapLongOffset( &((
icNamedColor2Type*)profileLutPtr)->ncolor.nDeviceCoords, 0, 4 );
03752
#endif
03753
count = ((
icNamedColor2Type*)profileLutPtr)->ncolor.count;
03754 nDeviceCoords = ((
icNamedColor2Type*)profileLutPtr)->ncolor.nDeviceCoords;
03755 cPtr = &((
icNamedColor2Type*)profileLutPtr)->ncolor.data[0];
03756
if(
pcs ==
icSigXYZData ){
03757
for( i=0; i<count; i++){
03758 cPtr += 32;
03759
#ifdef IntelMode
03760
SwapShortOffset( cPtr, 0, 3*2 );
03761
XYZ2Lab_forCube16((
unsigned short *)cPtr, 1);
03762 cPtr += 3*2;
03763 SwapShortOffset( cPtr, 0, nDeviceCoords*2 );
03764 cPtr += nDeviceCoords*2;
03765
#else
03766
XYZ2Lab_forCube16((
unsigned short *)cPtr, 1);
03767 cPtr += 3*2 + nDeviceCoords*2;
03768
#endif
03769
}
03770 }
03771
#ifdef IntelMode
03772
else{
03773
for( i=0; i<count; i++){
03774 cPtr += 32;
03775 SwapShortOffset( cPtr, 0, 3*2 );
03776 cPtr += 3*2;
03777 SwapShortOffset( cPtr, 0, nDeviceCoords*2 );
03778 cPtr += nDeviceCoords*2;
03779 }
03780 }
03781
#endif
03782
storage->theNamedColorTagData = profileLutPtr;
03783
UNLOCK_DATA(profileLutPtr);
03784 profileLutPtr = 0;
03785 *theDeviceCoords = nDeviceCoords;
03786
03787 CleanupAndExit:
03788
DISPOSE_IF_DATA(profileLutPtr);
03789
return err;
03790 }