Main Page | Class Hierarchy | Class List | File List | Class Members | File Members

pi_cmm.c File Reference

#include "General.h"
#include "GenLuts.h"
#include "PI_CMM.h"
#include "StdConv.h"

Go to the source code of this file.

Defines

#define ALLOW_DEVICE_LINK   /* allows link as the last profile in a chain, change in genluts.c too */

Functions

CMError CMMInitPrivate (CMMModelPtr storage, CMProfileRef srcProfile, CMProfileRef dstProfile)
CMError MakeSessionFromLink (CMMModelPtr storage, CMConcatProfileSet *profileSet)
CMError CMMConcatInitPrivate (CMMModelPtr storage, CMConcatProfileSet *profileSet)
Boolean IsPowerOf2 (unsigned long l)


Define Documentation

#define ALLOW_DEVICE_LINK   /* allows link as the last profile in a chain, change in genluts.c too */
 

Definition at line 39 of file lh_open/pi_cmm.c.


Function Documentation

CMError CMMConcatInitPrivate CMMModelPtr  storage,
CMConcatProfileSet profileSet
 

Definition at line 197 of file lh_open/pi_cmm.c.

00199 { 00200 CMCoreProfileHeader firstHeader; 00201 CMCoreProfileHeader lastHeader; 00202 CMCoreProfileHeader tempHeader; 00203 CMError err = noErr; 00204 unsigned short count; 00205 unsigned short loop; 00206 Boolean valid; 00207 CMProfileRef theProfile; 00208 #ifdef DEBUG_OUTPUT 00209 long timer = TickCount(); 00210 #endif 00211 00212 00213 #ifdef DEBUG_OUTPUT 00214 if ( DebugCheck(kThisFile, kDebugMiscInfo) ) 00215 { 00216 DebugPrint("¥ ->CMMConcatInitPrivate\n"); 00217 DebugPrint(" got %d profiles keyindex is %d \n", profileSet->count, profileSet->keyIndex); 00218 } 00219 #endif 00220 00221 count = profileSet->count; 00222 if (count == 0) 00223 { 00224 err = cmparamErr; 00225 goto CleanupAndExit; 00226 } 00227 /* ------------------------------------------------------------------------------------------ get first header */ 00228 err = CMGetProfileHeader( profileSet->profileSet[0], &firstHeader); 00229 if (err) 00230 goto CleanupAndExit; 00231 /* ------------------------------------------------------------------------------------------ only one profile? -> has to be a link profile */ 00232 storage->lookup = (Boolean)((firstHeader.flags & kLookupOnlyMask)>>16); /* lookup vs. interpolation */ 00233 00234 #ifdef RenderInt 00235 if( storage-> dwFlags != 0xffffffff ){ 00236 storage->lookup = (Boolean)((storage-> dwFlags & kLookupOnlyMask)>>16); 00237 } 00238 #endif 00239 if (count == 1 && firstHeader.deviceClass != icSigNamedColorClass ) 00240 { 00241 if (firstHeader.deviceClass != icSigLinkClass && firstHeader.deviceClass != icSigAbstractClass ) 00242 { 00243 err =cmCantConcatenateError; 00244 goto CleanupAndExit; 00245 } 00246 else{ 00247 err = MakeSessionFromLink( storage, profileSet ); 00248 if( err == 0 )return noErr; 00249 } 00250 lastHeader = firstHeader; 00251 } else 00252 { 00253 /* -------------------------------------------------------------------------------------- get last header */ 00254 err = CMGetProfileHeader( profileSet->profileSet[count-1], &lastHeader); 00255 if (err) 00256 goto CleanupAndExit; 00257 #ifndef ALLOW_DEVICE_LINK 00258 if (lastHeader.deviceClass == icSigLinkClass) 00259 { 00260 err = cmCantConcatenateError; 00261 goto CleanupAndExit; 00262 } 00263 #endif 00264 } 00265 00266 /* ------------------------------------------------------------------------------------------ valid profiles ??? */ 00267 for ( loop = 0; loop < count; loop++) 00268 { 00269 theProfile = profileSet->profileSet[loop]; 00270 err = CMValidateProfile( theProfile, &valid ); 00271 if (err) 00272 goto CleanupAndExit; 00273 if (!valid) 00274 { 00275 #ifdef DEBUG_OUTPUT 00276 if ( DebugCheck(kThisFile, kDebugErrorInfo) ) 00277 DebugPrint("¥ CMMConcatInitPrivate ERROR: profile #%d is NOT valid!\n", loop); 00278 #endif 00279 #ifdef realThing 00280 err = cmProfileError; 00281 goto CleanupAndExit; 00282 #endif 00283 } 00284 /* -------------------------------------------------------------------------------------- link profiles may not be used inbetween */ 00285 if ( (loop > 0) && (loop < count-1)) 00286 { 00287 err = CMGetProfileHeader( profileSet->profileSet[loop], &tempHeader); 00288 if (err) 00289 goto CleanupAndExit; 00290 if (tempHeader.deviceClass == icSigLinkClass) 00291 { 00292 err = cmCantConcatenateError; 00293 goto CleanupAndExit; 00294 } 00295 } 00296 } 00297 00298 /* ------------------------------------------------------------------------------------------ no abstract profile as first or last */ 00299 if ( (count >1) && ( (firstHeader.deviceClass == icSigAbstractClass) || (lastHeader.deviceClass == icSigAbstractClass) ) ) 00300 { 00301 err = cmCantConcatenateError; 00302 goto CleanupAndExit; 00303 } 00304 00305 /* ------------------------------------------------------------------------------------------ initialization */ 00306 (storage)->lutParam.inputLut = DISPOSE_IF_DATA((storage)->lutParam.inputLut); 00307 (storage)->lutParam.colorLut = DISPOSE_IF_DATA((storage)->lutParam.colorLut); 00308 (storage)->lutParam.outputLut = DISPOSE_IF_DATA((storage)->lutParam.outputLut); 00309 00310 (storage)->gamutLutParam.inputLut = DISPOSE_IF_DATA((storage)->gamutLutParam.inputLut); 00311 (storage)->gamutLutParam.colorLut = DISPOSE_IF_DATA((storage)->gamutLutParam.colorLut); 00312 (storage)->gamutLutParam.outputLut = DISPOSE_IF_DATA((storage)->gamutLutParam.outputLut); 00313 00314 (storage)->theNamedColorTagData = DISPOSE_IF_DATA((storage)->theNamedColorTagData); 00315 /* ------------------------------------------------------------------------------------------ check 'special' cases */ 00316 { 00317 err = PrepareCombiLUTs( storage, profileSet ); 00318 } 00319 00320 CleanupAndExit: 00321 00322 #ifdef DEBUG_OUTPUT 00323 if ( err && DebugCheck(kThisFile, kDebugErrorInfo) ) 00324 DebugPrint(" CMMConcatInitPrivate: err = %d\n", err); 00325 DebugPrint(" time in CMMConcatInitPrivate: %f second(s)\n",(TickCount()-timer)/60.0); 00326 DebugPrint("¥ <-CMMConcatInitPrivate\n"); 00327 #endif 00328 return( err ); 00329 }

CMError CMMInitPrivate CMMModelPtr  storage,
CMProfileRef  srcProfile,
CMProfileRef  dstProfile
 

Definition at line 60 of file lh_open/pi_cmm.c.

00063 { 00064 CMError err = noErr; 00065 OSErr aOSerr = noErr; 00066 CMConcatProfileSet *profileSet = nil; 00067 CMCoreProfileHeader sourceHeader; 00068 CMCoreProfileHeader destHeader; 00069 Boolean valid; 00070 short mode = 0; 00071 #ifdef DEBUG_OUTPUT 00072 long timer = TickCount(); 00073 #endif 00074 00075 #ifdef DEBUG_OUTPUT 00076 if ( DebugCheck(kThisFile, kDebugMiscInfo) ) 00077 DebugPrint("¥ ->CMMInitPrivate\n"); 00078 #endif 00079 00080 /* --------------------------------------------------------------------------------------- valid profiles ???*/ 00081 err = CMValidateProfile( srcProfile, &valid ); 00082 if (err) 00083 goto CleanupAndExit; 00084 if (!valid) 00085 { 00086 #ifdef DEBUG_OUTPUT 00087 if ( DebugCheck(kThisFile, kDebugErrorInfo) ) 00088 DebugPrint("¥ CMMInitPrivate ERROR: srcProfile is NOT valid!\n"); 00089 #endif 00090 00091 #ifdef realThing 00092 err = cmProfileError; 00093 goto CleanupAndExit; 00094 #endif 00095 } 00096 00097 err = CMValidateProfile(dstProfile, &valid ); 00098 if (err) 00099 goto CleanupAndExit; 00100 if (!valid) 00101 { 00102 #ifdef DEBUG_OUTPUT 00103 if ( DebugCheck(kThisFile, kDebugErrorInfo) ) 00104 DebugPrint("¥ CMMInitPrivate ERROR: dstProfile is NOT valid!\n"); 00105 #endif 00106 #ifdef realThing 00107 err = cmProfileError; 00108 goto CleanupAndExit; 00109 #endif 00110 } 00111 00112 /* --------------------------------------------------------------------------------------- initialization*/ 00113 (storage)->lutParam.inputLut = DISPOSE_IF_DATA((storage)->lutParam.inputLut); 00114 (storage)->lutParam.colorLut = DISPOSE_IF_DATA((storage)->lutParam.colorLut); 00115 (storage)->lutParam.outputLut = DISPOSE_IF_DATA((storage)->lutParam.outputLut); 00116 00117 (storage)->gamutLutParam.inputLut = DISPOSE_IF_DATA((storage)->gamutLutParam.inputLut); 00118 (storage)->gamutLutParam.colorLut = DISPOSE_IF_DATA((storage)->gamutLutParam.colorLut); 00119 (storage)->gamutLutParam.outputLut = DISPOSE_IF_DATA((storage)->gamutLutParam.outputLut); 00120 00121 (storage)->theNamedColorTagData = DISPOSE_IF_DATA((storage)->theNamedColorTagData); 00122 00123 (storage)->srcProfileVersion = icVersionNumber; 00124 (storage)->dstProfileVersion = icVersionNumber; 00125 00126 /* --------------------------------------------------------------------------------------- check version of source profile*/ 00127 err = CMGetProfileHeader( srcProfile, &sourceHeader); 00128 if (err) 00129 goto CleanupAndExit; 00130 00131 if ( !((sourceHeader.version & 0xff000000) >= icVersionNumber) ){ 00132 err = cmProfileError; 00133 goto CleanupAndExit; 00134 } 00135 if (sourceHeader.deviceClass == icSigLinkClass) 00136 { 00137 err = cmCantConcatenateError; 00138 goto CleanupAndExit; 00139 } 00140 00141 /* --------------------------------------------------------------------------------------- check version of destination profile*/ 00142 err = CMGetProfileHeader( dstProfile, &destHeader); 00143 if (err) 00144 goto CleanupAndExit; 00145 00146 if ( !((destHeader.version & 0xff000000) >= icVersionNumber) ){ 00147 err = cmProfileError; 00148 goto CleanupAndExit; 00149 } 00150 if (destHeader.deviceClass == icSigLinkClass) 00151 { 00152 err = cmCantConcatenateError; 00153 goto CleanupAndExit; 00154 } 00155 storage->lookup = (Boolean)((sourceHeader.flags & kLookupOnlyMask)>>16); /* lookup vs. interpolation */ 00156 00157 #ifdef RenderInt 00158 if( storage-> dwFlags != 0xffffffff ){ 00159 storage->lookup = (Boolean)((storage-> dwFlags & kLookupOnlyMask)>>16); 00160 } 00161 #endif 00162 /* --------------------------------------------------------------------------------------- 'normal' cases*/ 00163 profileSet = (CMConcatProfileSet *)SmartNewPtr(sizeof (CMConcatProfileSet) + sizeof(CMProfileRef), &aOSerr); 00164 if (aOSerr) 00165 goto CleanupAndExit; 00166 00167 profileSet->count = 2; 00168 profileSet->keyIndex = 1; 00169 /* profileSet->flags = sourceHeader.flags; */ 00170 profileSet->profileSet[0] = srcProfile; 00171 /* profileSet->profileSet[0]->renderingIntent = sourceHeader.renderingIntent; */ 00172 profileSet->profileSet[1] = dstProfile; 00173 /* profileSet->profileSet[1]->renderingIntent = destHeader.renderingIntent; */ 00174 00175 err = PrepareCombiLUTs( storage, profileSet ); 00176 if (err) 00177 goto CleanupAndExit; 00178 00179 CleanupAndExit: 00180 profileSet = (CMConcatProfileSet*)DisposeIfPtr( (Ptr)profileSet ); 00181 00182 #ifdef DEBUG_OUTPUT 00183 if ( err && DebugCheck(kThisFile, kDebugErrorInfo) ) 00184 DebugPrint("¥ CMMInitPrivate: err = %d\n", err); 00185 if ( DebugCheck(kThisFile, kDebugTimingInfo) ) 00186 DebugPrint(" time in CMMInitPrivate: %f second(s)\n",(TickCount()-timer)/60.0); 00187 if ( DebugCheck(kThisFile, kDebugMiscInfo) ) 00188 DebugPrint("¥ <-CMMInitPrivate\n"); 00189 #endif 00190 return err; 00191 }

Boolean IsPowerOf2 unsigned long  l  ) 
 

Definition at line 332 of file lh_open/pi_cmm.c.

References Boolean.

00333 { 00334 unsigned long i; 00335 for( i=1; i<32; i++){ 00336 if( (1U<<i) == l ) return 1; 00337 } 00338 return 0; 00339 }

CMError MakeSessionFromLink CMMModelPtr  storage,
CMConcatProfileSet profileSet
 

Definition at line 342 of file lh_open/pi_cmm.c.

References CMError, CMGetProfileElement(), CMGetProfileHeader(), CMLutParam::colorLutGridPoints, CMLutParam::colorLutInDim, CMLutParam::colorLutOutDim, icHeader::colorSpace, DisposeIfPtr(), LHCombiData::doCreate_16bit_ALut, LHCombiData::doCreate_16bit_Combi, LHCombiData::doCreate_16bit_ELut, LHCombiData::doCreate_16bit_XLut, Extract_MFT_Alut(), Extract_MFT_Elut(), Extract_MFT_Xlut(), GetMatrixFromProfile(), icSigAToB0Tag, icSigLut16Type, icSigXYZData, icVersionNumber, LH_END_PROC, LH_START_PROC, CMLutParam::matrixMFT, LHCombiData::maxProfileCount, nil, noErr, OSErr, OSType, icHeader::pcs, CMConcatProfileSet::profileSet, Ptr, SmartNewPtr(), LHCombiData::theProfile, and UINT32.

00344 { 00345 CMLutParam theLut={0}; 00346 CMLutParam *theLutData; 00347 LHCombiData theCombi={0}; 00348 LHCombiData *theCombiData; 00349 double *aDoublePtr; 00350 double aDouble; 00351 OSType theTag = icSigAToB0Tag; 00352 00353 CMError err = noErr; 00354 OSErr aOSerr = noErr; 00355 Ptr profileLutPtr = nil; 00356 UINT32 elementSize; 00357 double factor; 00358 UINT32 byteCount; 00359 CMCoreProfileHeader aHeader; 00360 00361 LH_START_PROC("MakeSessionFromLink") 00362 00363 00364 theLutData = &theLut; 00365 theCombiData = &theCombi; 00366 theCombiData->theProfile = profileSet->profileSet[0]; 00367 00368 /* -------------------------------------------------------- get partial tag data from profile */ 00369 err = CMGetProfileElement(theCombiData->theProfile, theTag, &elementSize, nil); 00370 if (err) 00371 goto CleanupAndExit; 00372 00373 byteCount = 52; /* get the first 52 bytes out of the profile */ 00374 profileLutPtr = SmartNewPtr(byteCount, &aOSerr); 00375 err = aOSerr; 00376 if (err) 00377 goto CleanupAndExit; 00378 00379 err = CMGetProfileElement( theCombiData->theProfile, theTag, &byteCount, profileLutPtr ); 00380 if (err) 00381 goto CleanupAndExit; 00382 #ifdef IntelMode 00383 SwapLongOffset( &((icLut16Type*)profileLutPtr)->base.sig, 0, 4 ); 00384 SwapShortOffset( &((icLut16Type*)profileLutPtr)->lut.inputEnt, 0, 2 ); 00385 SwapShortOffset( &((icLut16Type*)profileLutPtr)->lut.outputEnt, 0, 2 ); 00386 #endif 00387 00388 theLutData->colorLutInDim = ((icLut8Type*)profileLutPtr)->lut.inputChan; 00389 theLutData->colorLutOutDim = ((icLut8Type*)profileLutPtr)->lut.outputChan; 00390 theLutData->colorLutGridPoints = ((icLut8Type*)profileLutPtr)->lut.clutPoints; 00391 00392 switch( theLutData->colorLutInDim ){ 00393 case 3: 00394 if( theLutData->colorLutGridPoints != 16 && theLutData->colorLutGridPoints != 32 ){ 00395 err = 1; 00396 goto CleanupAndExit; 00397 } 00398 break; 00399 case 4: 00400 if( theLutData->colorLutGridPoints != 8 && theLutData->colorLutGridPoints != 16 ){ 00401 err = 1; 00402 goto CleanupAndExit; 00403 } 00404 break; 00405 } 00406 00407 err = CMGetProfileHeader( profileSet->profileSet[0], &aHeader); 00408 if (err) 00409 goto CleanupAndExit; 00410 storage->firstColorSpace = aHeader.colorSpace; 00411 storage->lastColorSpace = aHeader.pcs; 00412 storage->srcProfileVersion = icVersionNumber; 00413 storage->dstProfileVersion = icVersionNumber; 00414 00415 if ( ( theLutData->colorLutInDim == 3) && 00416 ( aHeader.pcs == icSigXYZData ) ) 00417 { 00418 factor = 1.; 00419 err = GetMatrixFromProfile(theLutData, theCombiData, theTag, factor); 00420 if( err ) goto CleanupAndExit; 00421 aDoublePtr = (double *)theLutData->matrixMFT; 00422 if( aDoublePtr != 0 ){ 00423 aDouble = aDoublePtr[0] + aDoublePtr[4] + aDoublePtr[8]; 00424 if( aDouble > 3.0 + 1E-6 || aDouble < 3.0 - 1E-6 ){ 00425 err = 1; 00426 goto CleanupAndExit; 00427 } 00428 } 00429 } 00430 theCombiData->maxProfileCount = 0; 00431 if( ((icLut16Type*)profileLutPtr)->base.sig == icSigLut16Type ){ 00432 theCombiData->doCreate_16bit_Combi = 1; 00433 theCombiData->doCreate_16bit_ELut = 0; 00434 theCombiData->doCreate_16bit_XLut = 1; 00435 theCombiData->doCreate_16bit_ALut = 0; 00436 } 00437 else{ 00438 theCombiData->doCreate_16bit_Combi = 0; 00439 theCombiData->doCreate_16bit_ELut = 0; 00440 theCombiData->doCreate_16bit_XLut = 0; 00441 theCombiData->doCreate_16bit_ALut = 0; 00442 } 00443 00444 /* ---------------------------------------------------------------------- process A Lut */ 00445 err = Extract_MFT_Alut( theLutData, theCombiData, profileLutPtr, theTag ); 00446 if (err) 00447 goto CleanupAndExit; 00448 00449 /* ---------------------------------------------------------------------- process X Lut */ 00450 err = Extract_MFT_Xlut ( theLutData, theCombiData, profileLutPtr, theTag ); 00451 if (err) 00452 goto CleanupAndExit; 00453 00454 /* ---------------------------------------------------------------------- process E Lut */ 00455 err = Extract_MFT_Elut( theLutData, theCombiData, profileLutPtr, theTag ); 00456 if (err) 00457 goto CleanupAndExit; 00458 00459 storage->lutParam = *theLutData; 00460 00461 /* --------------------------------------------------------------------------------- 00462 clean up 00463 ---------------------------------------------------------------------------------*/ 00464 CleanupAndExit: 00465 profileLutPtr = DisposeIfPtr(profileLutPtr); 00466 LH_END_PROC("MakeSessionFromLink") 00467 return err; 00468 }


Generated on Sat May 15 19:45:08 2004 for test by doxygen 1.3.7