04000 {
04001
CMCalcParam calcParam;
04002
CMLutParam lutParam;
04003
CMError err = -1;
04004
ColorSpaceInfo info;
04005
CalcProcPtr calcRoutine =
nil;
04006
CMBitmap bitMapOut;
04007
CMBitmap bitMapIn = *inBitMap;
04008
OSType inColorSpace = modelingData->firstColorSpace;
04009
OSType outColorSpace = modelingData->lastColorSpace;
04010
Boolean progressProcWasCalled =
FALSE;
04011
SINT32 offset;
04012
SINT32 progressTimer;
04013
SINT32 dimLoop;
04014
Boolean matchInPlace =
FALSE;
04015
long progressProcCount = 0;
04016
SINT32 inLineCount;
04017
Ptr aBuffer;
04018
04019
LH_START_PROC(
"LHMatchBitMapPrivate")
04020
04021 LOCK_DATA((modelingData)->lutParam.inputLut);
04022 LOCK_DATA((modelingData)->lutParam.colorLut);
04023 LOCK_DATA((modelingData)->lutParam.outputLut);
04024
04025 if( outBitMap == nil ){
04026 bitMapOut = *inBitMap;
04027 matchInPlace =
TRUE;
04028 }
04029
else{
04030 bitMapOut = *outBitMap;
04031 }
04032
04033
SetMem(&info,
sizeof(
ColorSpaceInfo), 0);
04034
SetMem(&calcParam,
sizeof(
CMCalcParam), 0);
04035
04036
FillLutParam(&lutParam, modelingData);
04037
FillCalcParam(&calcParam, &bitMapIn, &bitMapOut);
04038
04039 err =
CheckInputColorSpace( &bitMapIn, &calcParam, &info, inColorSpace, lutParam.
colorLutInDim );
04040 inLineCount = calcParam.
cmLineCount;
04041
if (err)
04042
goto CleanupAndExit;
04043
04044
if (matchInPlace){
04045 err =
SetOutputColorSpaceInplace( &calcParam, &info, outColorSpace);
04046
if (err)
04047
goto CleanupAndExit;
04048 }
04049 err =
CheckOutputColorSpace( &bitMapOut, &calcParam, &info, outColorSpace, lutParam.
colorLutOutDim );
04050
if (err)
04051
goto CleanupAndExit;
04052
04053
if (matchInPlace)
04054 {
04055
if (info.
inputPixelSize < info.
outputPixelSize)
04056 {
04057 err =
cmInvalidDstMap;
04058
goto CleanupAndExit;
04059 }
04060
04061 bitMapIn.
space = calcParam.
cmOutputColorSpace;
04062 }
else
04063 {
04064 calcParam.
copyAlpha = (calcParam.
cmInputColorSpace &
cmAlphaSpace) && (calcParam.
cmOutputColorSpace &
cmAlphaSpace);
04065 }
04066
04067 info.
inPlace = bitMapOut.
image == bitMapIn.
image && info.
tempInBuffer ==
nil && info.
tempOutBuffer ==
nil;
04068 calcRoutine =
FindCalcRoutine( &calcParam, &lutParam, &info, modelingData->lookup );
04069
if (calcRoutine ==
nil)
04070 {
04071 err =
cmMethodError;
04072
goto CleanupAndExit;
04073 }
04074
04075
if( info.
inPlace && calcParam.
cmInputPixelOffset < calcParam.
cmOutputPixelOffset ){
04076
for( dimLoop=0; dimLoop<8; dimLoop++){
04077 calcParam.
inputData[dimLoop] = (
Ptr)calcParam.
inputData[dimLoop] + (calcParam.
cmLineCount-1) * calcParam.
cmInputBytesPerLine + (calcParam.
cmPixelPerLine-1) * calcParam.
cmInputPixelOffset;
04078 calcParam.
outputData[dimLoop] = (
Ptr)calcParam.
outputData[dimLoop] + (calcParam.
cmLineCount-1) * calcParam.
cmOutputBytesPerLine + (calcParam.
cmPixelPerLine-1) * calcParam.
cmOutputPixelOffset;
04079 }
04080 calcParam.
cmInputPixelOffset = -calcParam.
cmInputPixelOffset;
04081 calcParam.
cmOutputPixelOffset = -calcParam.
cmOutputPixelOffset;
04082 calcParam.
cmInputBytesPerLine = -calcParam.
cmInputBytesPerLine;
04083 calcParam.
cmOutputBytesPerLine = -calcParam.
cmOutputBytesPerLine;
04084 }
04085
04086
if ((info.
tempInBuffer ==
nil) && (info.
tempOutBuffer ==
nil)&& modelingData->hasNamedColorProf ==
NoNamedColorProfile)
04087 {
04088
if (progressProc ==
nil)
04089 err =
CallCalcProc(calcRoutine,&calcParam, &lutParam);
04090
else
04091 {
04092 calcParam.
cmLineCount =
kMaxTempBlock / calcParam.
cmInputBytesPerLine;
04093
if (calcParam.
cmLineCount < 1)
04094 calcParam.
cmLineCount = 1;
04095
else if (calcParam.
cmLineCount > bitMapIn.
height)
04096 calcParam.
cmLineCount = bitMapIn.
height;
04097
04098 progressTimer =
TickCount();
04099
while ( info.
processedLinesIn < bitMapIn.
height )
04100 {
04101 err =
CallCalcProc(calcRoutine,&calcParam, &lutParam);
04102
04103
for (dimLoop = 0; dimLoop< lutParam.
colorLutInDim; dimLoop++)
04104 calcParam.
inputData[dimLoop] = (
Ptr)calcParam.
inputData[dimLoop] + calcParam.
cmLineCount * calcParam.
cmInputBytesPerLine;
04105
04106
for (dimLoop = 0; dimLoop< lutParam.
colorLutOutDim; dimLoop++)
04107 calcParam.
outputData[dimLoop] = (
Ptr)calcParam.
outputData[dimLoop] + calcParam.
cmLineCount * calcParam.
cmOutputBytesPerLine;
04108
04109 info.
processedLinesIn += calcParam.
cmLineCount;
04110
if ( info.
processedLinesIn + calcParam.
cmLineCount > bitMapIn.
height )
04111 calcParam.
cmLineCount = bitMapIn.
height-info.
processedLinesIn;
04112
04113
04114
if ( progressProc && ( progressTimer +
kProgressTicks < (
SINT32)
TickCount()) )
04115 {
04116 progressProcWasCalled =
TRUE;
04117
if (
CallCMBitmapCallBackProc ( progressProc, bitMapIn.
height, info.
processedLinesIn, (
void *)refCon ))
04118 {
04119 info.
processedLinesIn = bitMapIn.
height;
04120 err =
userCanceledErr;
04121 }
else
04122 progressTimer =
TickCount();
04123 progressProcCount = info.
processedLinesIn;
04124 }
04125 }
04126 }
04127 }
04128
else if (modelingData->hasNamedColorProf !=
NamedColorProfileOnly ){
04129 info.
processedLinesIn = 0;
04130 progressTimer =
TickCount();
04131
if( info.
tempInBuffer && info.
tempOutBuffer ){
04132
if( inLineCount > calcParam.
cmLineCount )inLineCount = calcParam.
cmLineCount;
04133 }
04134
else if( info.
tempInBuffer ){
04135
if( progressProc && modelingData->hasNamedColorProf ==
NamedColorProfileAtEnd ){
04136 inLineCount /= 32;
04137
if( inLineCount < 1 ) inLineCount = 1;
04138 }
04139 }
04140
else if( info.
tempOutBuffer ){
04141 inLineCount = calcParam.
cmLineCount;
04142 }
04143
else if( progressProc ){
04144 inLineCount =
kMaxTempBlock / calcParam.
cmInputBytesPerLine;
04145
if (inLineCount < 1)
04146 inLineCount = 1;
04147
else if (inLineCount > bitMapIn.
height)
04148 inLineCount = bitMapIn.
height;
04149
if( modelingData->hasNamedColorProf ==
NamedColorProfileAtEnd ){
04150 inLineCount /= 32;
04151
if( inLineCount < 1 ) inLineCount = 1;
04152 }
04153 }
04154
while ( info.
processedLinesIn < bitMapIn.
height )
04155 {
04156
if ( info.
processedLinesIn + inLineCount > bitMapIn.
height )
04157 inLineCount = bitMapIn.
height-info.
processedLinesIn;
04158
04159
if (info.
origSizeIn == 5 )
04160
Convert5To8 ( bitMapIn.
image, (Ptr)info.
tempInBuffer, info.
processedLinesIn, inLineCount, bitMapIn.
width, bitMapIn.
rowBytes );
04161
#ifdef PI_Application_h
04162
else if (info.
origSizeIn == 6 )
04163 Convert565To8 ( bitMapIn.
image, (Ptr)info.
tempInBuffer, info.
processedLinesIn, inLineCount, bitMapIn.
width, bitMapIn.
rowBytes );
04164
#endif
04165
else if (info.
origSizeIn == 10 )
04166
Convert10To16 ( bitMapIn.
image, (Ptr)info.
tempInBuffer, info.
processedLinesIn, inLineCount, bitMapIn.
width, bitMapIn.
rowBytes );
04167
04168
if (modelingData->hasNamedColorProf ==
NamedColorProfileAtBegin ){
04169 err =
ConvertIndexToLabBitmap( modelingData, bitMapIn.
image,
04170 (Ptr)info.
tempInBuffer, info.
processedLinesIn,
04171 inLineCount, bitMapIn.
width,
04172 bitMapIn.
rowBytes,
04173 calcParam.
cmInputBytesPerLine,
04174 calcParam.
cmInputPixelOffset*8 );
04175
if (err)
04176
goto CleanupAndExit;
04177 }
04178 calcParam.
cmLineCount = inLineCount;
04179 err =
CallCalcProc( calcRoutine, &calcParam, &lutParam );
04180
if (err)
04181
goto CleanupAndExit;
04182
04183
if (modelingData->hasNamedColorProf ==
NamedColorProfileAtEnd ){
04184
if( info.
tempOutBuffer )aBuffer = (
Ptr)info.
tempOutBuffer;
04185
else aBuffer = bitMapOut.
image;
04186 err =
ConvertLabToIndexBitmap( modelingData, aBuffer,
04187 info.
processedLinesIn,
04188 calcParam.
cmLineCount,
04189 bitMapOut.
width, bitMapOut.
rowBytes );
04190
if (err)
04191
goto CleanupAndExit;
04192 }
04193
04194
if( info.
origSizeOut == 5 )
04195
Convert8To5 ( (Ptr)info.
tempOutBuffer, bitMapOut.
image, info.
processedLinesIn, calcParam.
cmLineCount, bitMapOut.
width, bitMapOut.
rowBytes);
04196
#ifdef PI_Application_h
04197
else if( info.
origSizeOut == 6 )
04198 Convert8To565 ( (Ptr)info.
tempOutBuffer, bitMapOut.
image, info.
processedLinesIn, calcParam.
cmLineCount, bitMapOut.
width, bitMapOut.
rowBytes);
04199
#endif
04200
else if( info.
origSizeOut == 10 )
04201
Convert16To10 ( (Ptr)info.
tempOutBuffer, bitMapOut.
image, info.
processedLinesIn, calcParam.
cmLineCount, bitMapOut.
width, bitMapOut.
rowBytes);
04202
04203 info.
processedLinesIn += inLineCount;
04204
04205
if ( progressProc && ( progressTimer +
kProgressTicks < (
SINT32)
TickCount()) )
04206 {
04207 progressProcWasCalled =
TRUE;
04208
if (
CallCMBitmapCallBackProc ( progressProc, bitMapIn.
height, info.
processedLinesIn, (
void *)refCon ))
04209 {
04210 info.
processedLinesIn = bitMapIn.
height;
04211 err =
userCanceledErr;
04212 }
else
04213 progressTimer =
TickCount();
04214 progressProcCount = info.
processedLinesIn;
04215 }
04216
if( !info.
tempInBuffer ){
04217 offset = calcParam.
cmLineCount * calcParam.
cmInputBytesPerLine;
04218
for (dimLoop = 0; dimLoop< lutParam.
colorLutInDim; dimLoop++)
04219 calcParam.
inputData[dimLoop] = (
Ptr)calcParam.
inputData[dimLoop] + offset;
04220 }
04221
if( !info.
tempOutBuffer ){
04222 offset = calcParam.
cmLineCount * calcParam.
cmOutputBytesPerLine;
04223
for (dimLoop = 0; dimLoop< lutParam.
colorLutOutDim; dimLoop++)
04224 calcParam.
outputData[dimLoop] = (
Ptr)calcParam.
outputData[dimLoop] + offset;
04225 }
04226 }
04227 }
04228
else{
04229
CopyIndexData( &bitMapIn, &bitMapOut, &info );
04230 }
04231
if (err)
04232
goto CleanupAndExit;
04233
04234
if( progressProcWasCalled && progressProcCount != bitMapIn.
height )
04235
CallCMBitmapCallBackProc ( progressProc, bitMapIn.
height, bitMapIn.
height, (
void *)refCon );
04236 CleanupAndExit:
04237
04238
04239
DisposeIfPtr((Ptr)info.
tempInBuffer);
04240
DisposeIfPtr((Ptr)info.
tempOutBuffer);
04241
04242
UNLOCK_DATA((modelingData)->lutParam.
inputLut);
04243
UNLOCK_DATA((modelingData)->lutParam.
colorLut);
04244
UNLOCK_DATA((modelingData)->lutParam.
outputLut);
04245
04246
LH_END_PROC(
"LHMatchBitMapPrivate")
04247
04248 return err;
04249 }