00073 {
00074
unsigned long i, inCount, outCount, clipIndex, ulFactor;
00075
unsigned long intpFirst, intpLast, halfStep, ulAux, target;
00076
short monot;
00077
unsigned short *inCurve, *usPtr, *stopPtr;
00078
double flFactor;
00079
#ifdef DEBUG_OUTPUT
00080
OSErr err=
noErr;
00081
#endif
00082
LH_START_PROC(
"Fill_inverse_ushort_ALUT_from_CurveTag")
00083
00084 if( pCurveTag->base.sig != icSigCurveType
00085 || addrBits > 15 )
00086 {
00087
#ifdef DEBUG_OUTPUT
00088
if ( DebugCheck(kThisFile, kDebugErrorInfo) )
00089
DebugPrint(
"� Fill_inverse_ushort_ALUT_from_CurveTag ERROR: addrBits= %d\n",addrBits);
00090
#endif
00091
return(
cmparamErr);
00092 }
00093
00094 outCount = 1 << addrBits;
00095 clipIndex = outCount - 1;
00096
00097
00098
00099
if(pCurveTag->
curve.
count == 0)
00100 {
00101 ulFactor = ((
unsigned long)65535 << 16) / clipIndex;
00102
00103
for(i=0; i<clipIndex; i++)
00104 usALUT[i] = (
unsigned short)((i * ulFactor + 32767) >> 16);
00105
00106
for(i=clipIndex; i<outCount; i++)
00107 usALUT[i] = 0xFFFF;
00108
00109
return(
noErr);
00110 }
00111
else if(pCurveTag->
curve.
count == 1)
00112 {
00113
Fill_inverseGamma_ushort_ALUT(usALUT, addrBits, pCurveTag->
curve.
data[0]);
00114
return(
noErr);
00115 }
00116
00117
00118
00119 inCount = pCurveTag->
curve.
count;
00120 inCurve = pCurveTag->
curve.
data;
00121
00122
00123 flFactor = (
double)clipIndex / 65535.;
00124
00125 halfStep = clipIndex >> 1;
00126
00127
00128
for(monot=0, i=1; i<inCount; i++)
00129 {
00130
if(inCurve[i-1] < inCurve[i])
00131 monot++;
00132
else if(inCurve[i-1] > inCurve[i])
00133 monot--;
00134 }
00135
00136
if(monot >= 0)
00137 {
00138
for(i=1; i<inCount; i++)
00139
if(inCurve[i-1] > inCurve[i])
00140 inCurve[i] = inCurve[i-1];
00141
00142 intpFirst = (
unsigned long)(inCurve[0] * flFactor + 0.9999);
00143 intpLast = (
unsigned long)(inCurve[inCount-1] * flFactor);
00144
00145
for(i=0; i<intpFirst; i++)
00146 usALUT[i] = 0;
00147
for(i=intpLast+1; i<outCount; i++)
00148 usALUT[i] = 0xFFFF;
00149
00150
00151 usPtr = inCurve;
00152 stopPtr = inCurve + inCount - 2;
00153
00154
for(i=intpFirst; i<=intpLast; i++)
00155 {
00156 target = (0x0FFFF * i + halfStep) / clipIndex;
00157
while(*(usPtr+1) < target && usPtr < stopPtr)
00158 usPtr++;
00159
00160 ulAux = ((
unsigned long)(usPtr - inCurve) << 16) / (inCount - 1);
00161
if(*(usPtr+1) != *usPtr)
00162 {
00163 ulAux += ((target - (
unsigned long)*usPtr) << 16)
00164 / ( (*(usPtr+1) - *usPtr) * (inCount - 1) );
00165
00166
if(ulAux & 0x10000)
00167 ulAux = 0xFFFF;
00168 }
00169
00170 usALUT[i] = (
unsigned short)ulAux;
00171 }
00172 }
00173
else
00174 {
00175
for(i=1; i<inCount; i++)
00176
if(inCurve[i-1] < inCurve[i])
00177 inCurve[i] = inCurve[i-1];
00178
00179 intpFirst = (
unsigned long)(inCurve[inCount-1] * flFactor + 0.9999);
00180 intpLast = (
unsigned long)(inCurve[0] * flFactor);
00181
00182
for(i=0; i<intpFirst; i++)
00183 usALUT[i] = 0xFFFF;
00184
for(i=intpLast+1; i<outCount; i++)
00185 usALUT[i] = 0;
00186
00187
00188 usPtr = inCurve + inCount - 1;
00189 stopPtr = inCurve + 1;
00190
00191
for(i=intpFirst; i<=intpLast; i++)
00192 {
00193 target = (0x0FFFF * i + halfStep) / clipIndex;
00194
while(*(usPtr-1) < target && usPtr > stopPtr)
00195 usPtr--;
00196
00197 ulAux = ((
unsigned long)(usPtr-1 - inCurve) << 16) / (inCount - 1);
00198
if(*(usPtr-1) != *usPtr)
00199 {
00200 ulAux += (((
unsigned long)*(usPtr-1) - target) << 16)
00201 / ( (*(usPtr-1) - *usPtr) * (inCount - 1) );
00202
00203
if(ulAux & 0x10000)
00204 ulAux = 0xFFFF;
00205 }
00206
00207 usALUT[i] = (
unsigned short)ulAux;
00208 }
00209 }
00210
00211
00212
LH_END_PROC(
"Fill_inverse_ushort_ALUT_from_CurveTag")
00213 return(noErr);
00214 }