00131 {
00132
register long ii,jj;
00133
register long i;
00134
00135
register long aLong0;
00136
register long aLong1;
00137
register long aLong2;
00138
register long theEnd;
00139
register long aElutShift,
aElutShiftNum,aAlutShift,aElutOffset,aAlutOffset;
00140
register unsigned long aElutAdrSize,separateEluts,separateAluts;
00141
register long aVal;
00142
long aMatrix[3][3];
00143
register double aFactor,dVal;
00144
register unsigned long aMax;
00145
register UINT16 *ein_lut;
00146
register UINT16 *aus_lut;
00147
register UINT8 *aus_lutByte;
00148
register unsigned long aAlutAdrSize;
00149
register UINT16 *theArr;
00150
register UINT8 *theByteArr;
00151
register unsigned long ko,ko0;
00152
register long aElutShiftRight;
00153
00154
00155
#ifdef DEBUG_OUTPUT
00156
long err=0;
00157
#endif
00158
LH_START_PROC(
"DoMatrixForCube16")
00159
00160
00161 ein_lut = aStructPtr->ein_lut;
00162 aus_lut = (UINT16 *)aStructPtr->aus_lut;
00163 aus_lutByte = (UINT8 *)aus_lut;
00164 theArr = (UINT16 *)aStructPtr->theArr;
00165 theByteArr = (UINT8 *)theArr;
00166 aAlutAdrSize = aStructPtr->aAlutAdrSize;
00167 aElutAdrSize = aStructPtr->aElutAdrSize;
00168 separateEluts = aStructPtr->separateEluts;
00169 separateAluts = aStructPtr->separateAluts;
00170 theEnd = 3*aStructPtr->aPointCount;
00171 aMax = aAlutAdrSize-1;
00172
00173 for( i=0; i<33; i++) if( (1L<<i) == (
long)aElutAdrSize )break;
00174 if( i > 32 ) return;
00175 aElutShift = 16-i;
00176 aElutShiftRight = aStructPtr->aElutWordSize - aElutShift + 0;
00177 if( aElutShiftRight < 0 ) return;
00178 aElutShiftNum = 1<<aElutShift;
00179
00180 aFactor = 2*8. * aMax /(aStructPtr->gridPoints-1)*(
double)aStructPtr->gridPoints;
00181 for( ii=0; ii<3; ii++){
00182
for( jj=0; jj<3; jj++){
00183 dVal = (*(aStructPtr->theMatrix))[ii][jj]*aFactor;
00184 aMatrix[ii][jj] = (
long)
Round(dVal);
00185 }
00186 }
00187
#if FARBR_DEBUG
00188
DebugPrint(
"theArr=(d)");
for(ii=0; ii<3; ++ii)
for( jj=0; jj<3; jj++)
DebugPrint(
"%f ",aMatrix[ii][jj]);
DebugPrint(
"\n");
00189
00190
00191
00192
00193
00194
00195
#endif
00196
if( aStructPtr->aBufferByteCount == 2 ){
00197 aAlutShift = 16-aStructPtr->aAlutWordSize;
00198
for (i = 0; i < theEnd; i +=3){
00199
00200 aElutOffset = 0;
00201 ko = (theArr[i+0]);
00202 ko0 = ko - ( ko >> ( 16 -
aElutShift ));
00203 ko = ko0 & (
aElutShiftNum - 1 );
00204 ko0 = ko0 >>
aElutShift;
00205
if( ko0 >= (aElutAdrSize-1) ){
00206 aLong0 = ein_lut[ ko0 + aElutOffset ]<<(
aElutShift-aElutShiftRight);
00207 }
00208
else{
00209 ko0 += aElutOffset;
00210 aLong0 = ( ein_lut[ ko0 ] * (
aElutShiftNum - ko ) + ein_lut[ ko0 + 1 ] * ko )>>aElutShiftRight;
00211 }
00212
if( separateEluts )aElutOffset += aElutAdrSize;
00213
00214 ko = (theArr[i+1]);
00215 ko0 = ko - ( ko >> ( 16 -
aElutShift ));
00216 ko = ko0 & (
aElutShiftNum - 1 );
00217 ko0 = ko0 >>
aElutShift;
00218
if( ko0 >= (aElutAdrSize-1) ){
00219 aLong1 = ein_lut[ ko0 + aElutOffset ]<<(
aElutShift-aElutShiftRight);
00220 }
00221
else{
00222 ko0 += aElutOffset;
00223 aLong1 = ( ein_lut[ ko0 ] * (
aElutShiftNum - ko ) + ein_lut[ ko0 + 1 ] * ko )>>aElutShiftRight;
00224 }
00225
if( separateEluts )aElutOffset += aElutAdrSize;
00226
00227 ko = (theArr[i+2]);
00228 ko0 = ko - ( ko >> ( 16 -
aElutShift ));
00229 ko = ko0 & (
aElutShiftNum - 1 );
00230 ko0 = ko0 >>
aElutShift;
00231
if( ko0 >= (aElutAdrSize-1) ){
00232 aLong2 = ein_lut[ ko0 + aElutOffset ]<<(
aElutShift-aElutShiftRight);
00233 }
00234
else{
00235 ko0 += aElutOffset;
00236 aLong2 = ( ein_lut[ ko0 ] * (
aElutShiftNum - ko ) + ein_lut[ ko0 + 1 ] * ko )>>aElutShiftRight;
00237 }
00238
00239 aLong0 = ( aLong0 +2 )>>2;
00240 aLong1 = ( aLong1 +2 )>>2;
00241 aLong2 = ( aLong2 +2 )>>2;
00242 aAlutOffset = 0;
00243
for( ii=0; ii<3; ii++){
00244 aVal = aMatrix[ii][0] * aLong0;
00245 aVal += aMatrix[ii][1] * aLong1;
00246 aVal += aMatrix[ii][2] * aLong2;
00247 aVal = (aVal+((1<<9)-1))>>10;
00248
if( aVal < 0 ) aVal = 0;
00249
00250 ko0= ( aVal>> (3+2+3) );
00251
if( ko0 >= (aAlutAdrSize-1) ){
00252 theArr[i+ii] = aus_lut[ (aAlutAdrSize-1) + aAlutOffset ] <<aAlutShift;
00253 }
00254
else{
00255 ko0 += aAlutOffset;
00256 ko = ( aVal & ((1<<(3+2+3))-1) );
00257 theArr[i+ii] = (
UINT16)(( aus_lut[ ko0 ] * ( (1<<(3+2+3)) - ko ) + aus_lut[ ko0 +1 ] * ko)>>((3+2+3)-aAlutShift));
00258 }
00259
if( separateAluts )aAlutOffset += aAlutAdrSize;
00260 }
00261
#if FARBR_DEBUG
00262
DebugPrint(
"i=%ld\n",i);
00263
DebugPrint(
"theArr=(d)");
for(ii=0; ii<3; ++ii)
DebugPrint(
"%ld ",theArr[i+ii]);
DebugPrint(
"\n");
00264
DebugPrint(
"ein_reg=(d)");
DebugPrint(
"%ld ",aLong0);
DebugPrint(
"%ld ",aLong1);
DebugPrint(
"%ld ",aLong2);
DebugPrint(
"\n");
00265
#endif
00266
}
00267 }
00268
else{
00269 aAlutShift = aStructPtr->aAlutWordSize - 8;
00270
for (i = 0; i < theEnd; i +=3){
00271
00272
00273 aElutOffset = 0;
00274 ko = (theArr[i+0]);
00275 ko0 = ko - ( ko >> ( 16 -
aElutShift ));
00276 ko = ko0 & (
aElutShiftNum - 1 );
00277 ko0 = ko0 >>
aElutShift;
00278
if( ko0 >= (aElutAdrSize-1) ){
00279 aLong0 = ein_lut[ ko0 + aElutOffset ]<<(
aElutShift-aElutShiftRight);
00280 }
00281
else{
00282 ko0 += aElutOffset;
00283 aLong0 = ( ein_lut[ ko0 ] * (
aElutShiftNum - ko ) + ein_lut[ ko0 + 1 ] * ko )>>aElutShiftRight;
00284 }
00285
if( separateEluts )aElutOffset += aElutAdrSize;
00286
00287 ko = (theArr[i+1]);
00288 ko0 = ko - ( ko >> ( 16 -
aElutShift ));
00289 ko = ko0 & (
aElutShiftNum - 1 );
00290 ko0 = ko0 >>
aElutShift;
00291
if( ko0 >= (aElutAdrSize-1) ){
00292 aLong1 = ein_lut[ ko0 + aElutOffset ]<<(
aElutShift-aElutShiftRight);
00293 }
00294
else{
00295 ko0 += aElutOffset;
00296 aLong1 = ( ein_lut[ ko0 ] * (
aElutShiftNum - ko ) + ein_lut[ ko0 + 1 ] * ko )>>aElutShiftRight;
00297 }
00298
if( separateEluts )aElutOffset += aElutAdrSize;
00299
00300 ko = (theArr[i+2]);
00301 ko0 = ko - ( ko >> ( 16 -
aElutShift ));
00302 ko = ko0 & (
aElutShiftNum - 1 );
00303 ko0 = ko0 >>
aElutShift;
00304
if( ko0 >= (aElutAdrSize-1) ){
00305 aLong2 = ein_lut[ ko0 + aElutOffset ]<<(
aElutShift-aElutShiftRight);
00306 }
00307
else{
00308 ko0 += aElutOffset;
00309 aLong2 = ( ein_lut[ ko0 ] * (
aElutShiftNum - ko ) + ein_lut[ ko0 + 1 ] * ko )>>aElutShiftRight;
00310 }
00311
00312 aLong0 = ( aLong0 +2 )>>2;
00313 aLong1 = ( aLong1 +2 )>>2;
00314 aLong2 = ( aLong2 +2 )>>2;
00315 aAlutOffset = 0;
00316
if( aStructPtr->aAlutWordSize > 8 ){
00317
for( ii=0; ii<3; ii++){
00318 aVal = aMatrix[ii][0] * aLong0;
00319 aVal += aMatrix[ii][1] * aLong1;
00320 aVal += aMatrix[ii][2] * aLong2;
00321 aVal = (aVal+((1<<12)-1))>>13;
00322
if( aVal < 0 ) aVal = 0;
00323
00324 ko0= (aVal+((1<<(3+2-1))-1)) >> (3+2);
00325
if( ko0 >= (aAlutAdrSize-1) ){
00326 theByteArr[i+ii] = aus_lut[ (aAlutAdrSize-1) + aAlutOffset ] >>aAlutShift;
00327 }
00328
else{
00329 theByteArr[i+ii] = aus_lut[ ko0 + aAlutOffset ] >>aAlutShift;
00330 }
00331
if( separateAluts )aAlutOffset += aAlutAdrSize;
00332 }
00333 }
00334
else{
00335
for( ii=0; ii<3; ii++){
00336 aVal = aMatrix[ii][0] * aLong0;
00337 aVal += aMatrix[ii][1] * aLong1;
00338 aVal += aMatrix[ii][2] * aLong2;
00339 aVal = (aVal+((1<<12)-1))>>13;
00340
if( aVal < 0 ) aVal = 0;
00341
00342 ko0= (aVal+((1<<(3+2-1))-1)) >> (3+2);
00343
if( ko0 >= (aAlutAdrSize-1) ){
00344 theByteArr[i+ii] = aus_lutByte[ (aAlutAdrSize-1) + aAlutOffset ] ;
00345 }
00346
else{
00347 theByteArr[i+ii] = aus_lutByte[ ko0 + aAlutOffset ] ;
00348 }
00349
if( separateAluts )aAlutOffset += aAlutAdrSize;
00350 }
00351 }
00352
#if FARBR_DEBUG
00353
DebugPrint(
"i=%ld\n",i);
00354
DebugPrint(
"theArr=(d)");
for(ii=0; ii<3; ++ii)
DebugPrint(
"%ld ",theArr[i+ii]);
DebugPrint(
"\n");
00355
DebugPrint(
"ein_reg=(d)");
DebugPrint(
"%ld ",aLong0);
DebugPrint(
"%ld ",aLong1);
DebugPrint(
"%ld ",aLong2);
DebugPrint(
"\n");
00356
#endif
00357
}
00358 }
00359
LH_END_PROC(
"DoMatrixForCube16")
00360 }