00316 {
00317
long needBits,theSize;
00318
long i,gridPoints;
00319
OSErr err =
noErr;
00320
UINT16 *cube =
nil;
00321
register long aMaxVal;
00322
register long aShift;
00323
long aRound;
00324
00325
LH_START_PROC(
"MakeCMColorCube")
00326
00327 err = CalcGridPoints4Cube(*theCubeSize, inputDim, &gridPoints, &needBits);
00328 if (err)
00329 goto CleanupAndExit;
00330
00331 theSize = gridPoints;
00332 for( i=1; i<inputDim; ++i)theSize *= gridPoints;
00333
00334 if( inputDim > 4 )
00335 {
00336 err =
cmparamErr;
00337
goto CleanupAndExit;
00338 }
00339 *theCubeSize = theSize * inputDim;
00340
if( inputDim != 4 )
00341 *theCubeSize = theSize * 4;
00342
00343 *aHdlPtr =
ALLOC_DATA(*theCubeSize*2, &err);
00344
if (err !=
noErr)
00345
goto CleanupAndExit;
00346
00347
LOCK_DATA( *aHdlPtr );
00348 cube = (
UINT16 *)
DATA_2_PTR( *aHdlPtr );
00349 aMaxVal = (1<<(30-needBits))-1;
00350 aMaxVal = aMaxVal / ( gridPoints -1 );
00351 aShift = 30 - needBits - 16;
00352 aRound = 0;
00353
if( inputDim == 1 )
00354 {
00355
for( i=0; i<gridPoints; ++i){
00356 *cube++ = (
UINT16)(( aMaxVal * i + aRound) >> aShift);
00357 *cube++ = 0;
00358 *cube++ = 0;
00359 *cube++ = 0;
00360 }
00361 }
00362
else if( inputDim == 2)
00363 {
00364
register long j;
00365
register UINT16 aI;
00366
for( i=0; i<gridPoints; ++i){
00367 aI = (
UINT16)(( aMaxVal * i + aRound ) >> aShift);
00368
for( j=0; j<gridPoints; ++j){
00369 *cube++ = aI;
00370 *cube++ = (
UINT16)(( aMaxVal * j + aRound ) >> aShift);
00371 *cube++ = 0;
00372 *cube++ = 0;
00373 }
00374 }
00375 }
00376
else if( inputDim == 3)
00377 {
00378
register long j,k;
00379
register UINT16 aI, aJ;
00380
for( i=0; i<gridPoints; ++i){
00381 aI = (
UINT16)(( aMaxVal * i + aRound ) >> aShift);
00382
for( j=0; j<gridPoints; ++j){
00383 aJ = (
UINT16)(( aMaxVal * j + aRound ) >> aShift);
00384
for( k=0; k<gridPoints; ++k){
00385 *cube++ = aI;
00386 *cube++ = aJ;
00387 *cube++ = (
UINT16)(( aMaxVal * k + aRound ) >> aShift);
00388 *cube++ = 0;
00389 }
00390 }
00391 }
00392 }
00393
else if( inputDim == 4){
00394
register long j,k,l;
00395
register UINT16 aI, aJ,aK;
00396
for( i=0; i<gridPoints; ++i){
00397 aI = (
UINT16)(( aMaxVal * i + aRound ) >> aShift);
00398
for( j=0; j<gridPoints; ++j){
00399 aJ = (
UINT16)(( aMaxVal * j + aRound ) >> aShift);
00400
for( k=0; k<gridPoints; ++k){
00401 aK = (
UINT16)(( aMaxVal * k + aRound ) >> aShift);
00402
for( l=0; l<gridPoints; ++l){
00403 *cube++ = aI;
00404 *cube++ = aJ;
00405 *cube++ = aK;
00406 *cube++ = (
UINT16)(( aMaxVal * l + aRound ) >> aShift);
00407 }
00408 }
00409 }
00410 }
00411 }
00412
else
00413 {
00414 *aHdlPtr =
DISPOSE_IF_DATA(*aHdlPtr);
00415 err =
cmparamErr;
00416
goto CleanupAndExit;
00417 }
00418
UNLOCK_DATA(*aHdlPtr);
00419 *theBits = needBits;
00420 CleanupAndExit:
00421
LH_END_PROC(
"MakeCMColorCube")
00422 return err;
00423 }