00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #ifndef PXL_PIXEL_C
00022 #define PXL_PIXEL_C
00023
00024 #include <limits.h>
00025 #include <math.h>
00026 #include <iostream.h>
00027 #include <stdlib.h>
00028
00029 #include <SYS/SYS_Types.h>
00030
00031 #include <UT/UT_Endian.h>
00032 #include <UT/UT_Floor.h>
00033 #include <UT/UT_Math.h>
00034 #include <UT/UT_ProcessorDefines.h>
00035
00036 #include "PXL_Pixel.h"
00037
00038
00039
00040
00041
00042
00043
00044 #ifdef USE_LUT_FOR_8_TO_FP_CONV
00045
00046 static float lut8bitFP[256] =
00047 {
00048 0.000000, 0.003922, 0.007843, 0.011765, 0.015686, 0.019608, 0.023529, 0.027451,
00049 0.031373, 0.035294, 0.039216, 0.043137, 0.047059, 0.050980, 0.054902, 0.058824,
00050 0.062745, 0.066667, 0.070588, 0.074510, 0.078431, 0.082353, 0.086275, 0.090196,
00051 0.094118, 0.098039, 0.101961, 0.105882, 0.109804, 0.113725, 0.117647, 0.121569,
00052 0.125490, 0.129412, 0.133333, 0.137255, 0.141176, 0.145098, 0.149020, 0.152941,
00053 0.156863, 0.160784, 0.164706, 0.168627, 0.172549, 0.176471, 0.180392, 0.184314,
00054 0.188235, 0.192157, 0.196078, 0.200000, 0.203922, 0.207843, 0.211765, 0.215686,
00055 0.219608, 0.223529, 0.227451, 0.231373, 0.235294, 0.239216, 0.243137, 0.247059,
00056 0.250980, 0.254902, 0.258824, 0.262745, 0.266667, 0.270588, 0.274510, 0.278431,
00057 0.282353, 0.286275, 0.290196, 0.294118, 0.298039, 0.301961, 0.305882, 0.309804,
00058 0.313725, 0.317647, 0.321569, 0.325490, 0.329412, 0.333333, 0.337255, 0.341176,
00059 0.345098, 0.349020, 0.352941, 0.356863, 0.360784, 0.364706, 0.368627, 0.372549,
00060 0.376471, 0.380392, 0.384314, 0.388235, 0.392157, 0.396078, 0.400000, 0.403922,
00061 0.407843, 0.411765, 0.415686, 0.419608, 0.423529, 0.427451, 0.431373, 0.435294,
00062 0.439216, 0.443137, 0.447059, 0.450980, 0.454902, 0.458824, 0.462745, 0.466667,
00063 0.470588, 0.474510, 0.478431, 0.482353, 0.486275, 0.490196, 0.494118, 0.498039,
00064 0.501961, 0.505882, 0.509804, 0.513725, 0.517647, 0.521569, 0.525490, 0.529412,
00065 0.533333, 0.537255, 0.541176, 0.545098, 0.549020, 0.552941, 0.556863, 0.560784,
00066 0.564706, 0.568627, 0.572549, 0.576471, 0.580392, 0.584314, 0.588235, 0.592157,
00067 0.596078, 0.600000, 0.603922, 0.607843, 0.611765, 0.615686, 0.619608, 0.623529,
00068 0.627451, 0.631373, 0.635294, 0.639216, 0.643137, 0.647059, 0.650980, 0.654902,
00069 0.658824, 0.662745, 0.666667, 0.670588, 0.674510, 0.678431, 0.682353, 0.686275,
00070 0.690196, 0.694118, 0.698039, 0.701961, 0.705882, 0.709804, 0.713725, 0.717647,
00071 0.721569, 0.725490, 0.729412, 0.733333, 0.737255, 0.741176, 0.745098, 0.749020,
00072 0.752941, 0.756863, 0.760784, 0.764706, 0.768627, 0.772549, 0.776471, 0.780392,
00073 0.784314, 0.788235, 0.792157, 0.796078, 0.800000, 0.803922, 0.807843, 0.811765,
00074 0.815686, 0.819608, 0.823529, 0.827451, 0.831373, 0.835294, 0.839216, 0.843137,
00075 0.847059, 0.850980, 0.854902, 0.858824, 0.862745, 0.866667, 0.870588, 0.874510,
00076 0.878431, 0.882353, 0.886275, 0.890196, 0.894118, 0.898039, 0.901961, 0.905882,
00077 0.909804, 0.913725, 0.917647, 0.921569, 0.925490, 0.929412, 0.933333, 0.937255,
00078 0.941176, 0.945098, 0.949020, 0.952941, 0.956863, 0.960784, 0.964706, 0.968627,
00079 0.972549, 0.976471, 0.980392, 0.984314, 0.988235, 0.992157, 0.996078, 1.000000
00080 };
00081 #endif
00082
00083
00084
00085 template<>
00086 inline
00087 PXL_Pixel<unsigned char, 0>::PXL_Pixel(unsigned int black,
00088 unsigned int white,
00089 unsigned char value)
00090 {
00091 PXLdetermineProcCaps();
00092 myType = PXL_INT8;
00093 myBlack = black;
00094 myWhite = white;
00095 myValue = value;
00096 if(myBlack != myWhite)
00097 myPntScale = 1.0f / (myWhite - myBlack);
00098 else myPntScale = 1.0f;
00099 }
00100
00101 template<>
00102 inline
00103 PXL_Pixel<unsigned char, 1>::PXL_Pixel(unsigned int black,
00104 unsigned int white,
00105 unsigned char value)
00106 {
00107 PXLdetermineProcCaps();
00108 myType = PXL_INT8;
00109 myBlack = black;
00110 myWhite = white;
00111 myValue = value;
00112 myPntScale = 1.0f;
00113 }
00114
00115 template<>
00116 inline
00117 PXL_Pixel<unsigned char, 0>::PXL_Pixel(const PXL_Pixel &pix)
00118 {
00119 PXLdetermineProcCaps();
00120 myType = PXL_INT8;
00121
00122 myBlack = pix.myBlack;
00123 myWhite = pix.myWhite;
00124 myValue = pix.myValue;
00125 if(myBlack != myWhite)
00126 myPntScale = 1.0f / (myWhite - myBlack);
00127 else myPntScale = 1.0f;
00128 }
00129
00130
00131 template<>
00132 inline
00133 PXL_Pixel<unsigned char, 1>::PXL_Pixel(const PXL_Pixel &pix)
00134 {
00135 PXLdetermineProcCaps();
00136 myType = PXL_INT8;
00137
00138 myBlack = pix.myBlack;
00139 myWhite = pix.myWhite;
00140 myValue = pix.myValue;
00141 myPntScale = 1.0f;
00142 }
00143
00144 template<>
00145 inline
00146 PXL_Pixel<unsigned short, 0>::PXL_Pixel(unsigned int black,
00147 unsigned int white,
00148 unsigned short value)
00149 {
00150 PXLdetermineProcCaps();
00151 myType = PXL_INT16;
00152 myBlack = black;
00153 myWhite = white;
00154 myValue = value;
00155 if(myBlack != myWhite)
00156 myPntScale = 1.0f / (myWhite - myBlack);
00157 else myPntScale = 1.0f;
00158 }
00159
00160 template<>
00161 inline
00162 PXL_Pixel<unsigned short, 1>::PXL_Pixel(unsigned int black,
00163 unsigned int white,
00164 unsigned short value)
00165 {
00166 PXLdetermineProcCaps();
00167 myType = PXL_INT16;
00168 myBlack = black;
00169 myWhite = white;
00170 myValue = value;
00171 myPntScale = 1.0f;
00172 }
00173
00174 template<>
00175 inline
00176 PXL_Pixel<unsigned short, 0>::PXL_Pixel(const PXL_Pixel &pix)
00177 {
00178 PXLdetermineProcCaps();
00179 myType = PXL_INT16;
00180
00181 myBlack = pix.myBlack;
00182 myWhite = pix.myWhite;
00183 myValue = pix.myValue;
00184 if(myBlack != myWhite)
00185 myPntScale = 1.0f / (myWhite - myBlack);
00186 else myPntScale = 1.0f;
00187 }
00188
00189 template<>
00190 inline
00191 PXL_Pixel<unsigned short, 1>::PXL_Pixel(const PXL_Pixel &pix)
00192 {
00193 PXLdetermineProcCaps();
00194 myType = PXL_INT16;
00195
00196 myBlack = pix.myBlack;
00197 myWhite = pix.myWhite;
00198 myValue = pix.myValue;
00199 myPntScale = 1.0f;
00200 }
00201
00202 template<>
00203 inline
00204 PXL_Pixel<unsigned int, 0>::PXL_Pixel(unsigned int black,
00205 unsigned int white,
00206 unsigned int value)
00207 {
00208 PXLdetermineProcCaps();
00209 myType = PXL_INT32;
00210 myBlack = black;
00211 myWhite = white;
00212 myValue = value;
00213 if(myBlack != myWhite)
00214 myPntScale = 1.0f / (myWhite - myBlack);
00215 else myPntScale = 1.0f;
00216 }
00217
00218 template<>
00219 inline
00220 PXL_Pixel<unsigned int, 1>::PXL_Pixel(unsigned int black,
00221 unsigned int white,
00222 unsigned int value)
00223 {
00224 PXLdetermineProcCaps();
00225 myType = PXL_INT32;
00226 myBlack = black;
00227 myWhite = white;
00228 myValue = value;
00229 myPntScale = 1.0f;
00230 }
00231
00232 template<>
00233 inline
00234 PXL_Pixel<unsigned int, 0>::PXL_Pixel(const PXL_Pixel &pix)
00235 {
00236 PXLdetermineProcCaps();
00237 myType = PXL_INT32;
00238
00239 myBlack = pix.myBlack;
00240 myWhite = pix.myWhite;
00241 myValue = pix.myValue;
00242 if(myBlack != myWhite)
00243 myPntScale = 1.0f / (myWhite - myBlack);
00244 else myPntScale = 1.0f;
00245 }
00246
00247
00248 template<>
00249 inline
00250 PXL_Pixel<unsigned int, 1>::PXL_Pixel(const PXL_Pixel &pix)
00251 {
00252 PXLdetermineProcCaps();
00253 myType = PXL_INT32;
00254
00255 myBlack = pix.myBlack;
00256 myWhite = pix.myWhite;
00257 myValue = pix.myValue;
00258 myPntScale = 1.0f;
00259 }
00260
00261 template<>
00262 inline
00263 PXL_Pixel<float, 0>::PXL_Pixel(unsigned int black,
00264 unsigned int white,
00265 float value)
00266 {
00267 PXLdetermineProcCaps();
00268 myType = PXL_FLOAT32;
00269 myBlack = black;
00270 myWhite = white;
00271 myValue = value;
00272 myPntScale = 1.0f;
00273 }
00274
00275 template<>
00276 inline
00277 PXL_Pixel<float, 1>::PXL_Pixel(unsigned int black,
00278 unsigned int white,
00279 float value)
00280 {
00281 PXLdetermineProcCaps();
00282 myType = PXL_FLOAT32;
00283 myBlack = black;
00284 myWhite = white;
00285 myValue = value;
00286 myPntScale = 1.0f;
00287 }
00288
00289 template<>
00290 inline
00291 PXL_Pixel<fpreal16, 0>::PXL_Pixel(unsigned int,
00292 unsigned int,
00293 fpreal16 value)
00294 {
00295 PXLdetermineProcCaps();
00296 myType = PXL_FLOAT16;
00297 myBlack = 0;
00298 myWhite = 1;
00299 myValue = value;
00300 myPntScale = 1.0f;
00301 }
00302
00303 template<>
00304 inline
00305 PXL_Pixel<fpreal16, 1>::PXL_Pixel(unsigned int,
00306 unsigned int,
00307 fpreal16 value)
00308 {
00309 PXLdetermineProcCaps();
00310 myType = PXL_FLOAT16;
00311 myBlack = 0;
00312 myWhite = 1;
00313 myValue = value;
00314 myPntScale = 1.0f;
00315 }
00316
00317 template<>
00318 inline
00319 PXL_Pixel<float, 0>::PXL_Pixel(const PXL_Pixel &pix)
00320 {
00321 PXLdetermineProcCaps();
00322 myType = PXL_FLOAT32;
00323
00324 myBlack = pix.myBlack;
00325 myWhite = pix.myWhite;
00326 myValue = pix.myValue;
00327 myPntScale = 1.0f;
00328 }
00329
00330
00331 template<>
00332 inline
00333 PXL_Pixel<float, 1>::PXL_Pixel(const PXL_Pixel &pix)
00334 {
00335 PXLdetermineProcCaps();
00336 myType = PXL_FLOAT32;
00337
00338 myBlack = pix.myBlack;
00339 myWhite = pix.myWhite;
00340 myValue = pix.myValue;
00341 myPntScale = 1.0f;
00342 }
00343
00344 template<>
00345 inline
00346 PXL_Pixel<fpreal16, 0>::PXL_Pixel(const PXL_Pixel &pix)
00347 {
00348 PXLdetermineProcCaps();
00349 myType = PXL_FLOAT16;
00350
00351 myBlack = pix.myBlack;
00352 myWhite = pix.myWhite;
00353 myValue = pix.myValue;
00354 myPntScale = 1.0f;
00355 }
00356
00357
00358 template<>
00359 inline
00360 PXL_Pixel<fpreal16, 1>::PXL_Pixel(const PXL_Pixel &pix)
00361 {
00362 PXLdetermineProcCaps();
00363 myType = PXL_FLOAT16;
00364
00365 myBlack = pix.myBlack;
00366 myWhite = pix.myWhite;
00367 myValue = pix.myValue;
00368 myPntScale = 1.0f;
00369 }
00370
00371 template<class Type, int fast>
00372 inline
00373 PXL_Pixel<Type, fast>::PXL_Pixel(unsigned b, unsigned int w, Type v)
00374 {
00375 PXLdetermineProcCaps();
00376 myBlack = b;
00377 myWhite = w;
00378 myValue = v;
00379 if(myBlack != myWhite)
00380 myPntScale = 1.0f / (myWhite - myBlack);
00381 else myPntScale = 1.0f;
00382 }
00383
00384 template<class Type, int fast>
00385 inline
00386 PXL_Pixel<Type, fast>::PXL_Pixel(const PXL_Pixel &pix)
00387 {
00388 PXLdetermineProcCaps();
00389 myType = pix.myType;
00390 myBlack = pix.myBlack;
00391 myWhite = pix.myWhite;
00392 myValue = pix.myValue;
00393
00394 if(myBlack != myWhite)
00395 myPntScale = 1.0f / (myWhite - myBlack);
00396 else myPntScale = 1.0f;
00397 }
00398
00399
00400 template<>
00401 inline const char * PXL_Pixel<unsigned char, 0>::formatName() const
00402 { return "char:slow"; }
00403 template<>
00404 inline const char * PXL_Pixel<unsigned char, 1>::formatName() const
00405 { return "char:fast"; }
00406 template<>
00407 inline const char * PXL_Pixel<unsigned short, 0>::formatName() const
00408 { return "short:slow"; }
00409 template<>
00410 inline const char * PXL_Pixel<unsigned short, 1>::formatName() const
00411 { return "short:fast"; }
00412 template<>
00413 inline const char * PXL_Pixel<unsigned int, 0>::formatName() const
00414 { return "int:slow"; }
00415 template<>
00416 inline const char * PXL_Pixel<unsigned int, 1>::formatName() const
00417 { return "int:fast"; }
00418 template<>
00419 inline const char * PXL_Pixel<float, 0>::formatName() const
00420 { return "float:slow"; }
00421 template<>
00422 inline const char * PXL_Pixel<float, 1>::formatName() const
00423 { return "float:fast"; }
00424 template<>
00425 inline const char * PXL_Pixel<fpreal16, 0>::formatName() const
00426 { return "float16:slow"; }
00427 template<>
00428 inline const char * PXL_Pixel<fpreal16, 1>::formatName() const
00429 { return "float16:fast"; }
00430
00431 template<class Type, int fast> inline const char *
00432 PXL_Pixel<Type, fast>::formatName() const
00433 { return "unknown"; }
00434
00435
00436
00437
00438 template<>
00439 inline unsigned char
00440 PXL_Pixel<unsigned char, 0>::maxValue() const
00441 {
00442 return UCHAR_MAX;
00443 }
00444
00445 template<>
00446 inline unsigned char
00447 PXL_Pixel<unsigned char, 1>::maxValue() const
00448 {
00449 return UCHAR_MAX;
00450 }
00451
00452 template<>
00453 inline unsigned char
00454 PXL_Pixel<unsigned char,0>::minValue() const
00455 {
00456 return (unsigned char) 0;
00457 }
00458
00459 template<>
00460 inline unsigned char
00461 PXL_Pixel<unsigned char,1>::minValue() const
00462 {
00463 return (unsigned char) 0;
00464 }
00465
00466 template<>
00467 inline unsigned short
00468 PXL_Pixel<unsigned short,0>::maxValue() const
00469 {
00470 return USHRT_MAX;
00471 }
00472
00473 template<>
00474 inline unsigned short
00475 PXL_Pixel<unsigned short,1>::maxValue() const
00476 {
00477 return USHRT_MAX;
00478 }
00479
00480 template<>
00481 inline unsigned short
00482 PXL_Pixel<unsigned short,0>::minValue() const
00483 {
00484 return (unsigned short) 0;
00485 }
00486
00487 template<>
00488 inline unsigned short
00489 PXL_Pixel<unsigned short,1>::minValue() const
00490 {
00491 return (unsigned short) 0;
00492 }
00493
00494 template<>
00495 inline unsigned int
00496 PXL_Pixel<unsigned int,0>::maxValue() const
00497 {
00498 return UINT_MAX;
00499 }
00500
00501 template<>
00502 inline unsigned int
00503 PXL_Pixel<unsigned int,1>::maxValue() const
00504 {
00505 return UINT_MAX;
00506 }
00507
00508 template<>
00509 inline unsigned int
00510 PXL_Pixel<unsigned int,0>::minValue() const
00511 {
00512 return 0;
00513 }
00514
00515 template<>
00516 inline unsigned int
00517 PXL_Pixel<unsigned int,1>::minValue() const
00518 {
00519 return 0;
00520 }
00521
00522 template<>
00523 inline float
00524 PXL_Pixel<float,0>::minValue() const
00525 {
00526 return (float) 0.0F;
00527 }
00528
00529 template<>
00530 inline float
00531 PXL_Pixel<float,1>::minValue() const
00532 {
00533 return (float) 0.0F;
00534 }
00535
00536 template<>
00537 inline float
00538 PXL_Pixel<float,0>::maxValue() const
00539 {
00540 return 1.0F;
00541 }
00542
00543 template<>
00544 inline float
00545 PXL_Pixel<float,1>::maxValue() const
00546 {
00547 return 1.0F;
00548 }
00549
00550
00551 template<>
00552 inline fpreal16
00553 PXL_Pixel<fpreal16,0>::minValue() const
00554 {
00555 return -H_REAL16_MAX;
00556 }
00557
00558 template<>
00559 inline fpreal16
00560 PXL_Pixel<fpreal16,1>::minValue() const
00561 {
00562 return -H_REAL16_MAX;
00563 }
00564
00565 template<>
00566 inline fpreal16
00567 PXL_Pixel<fpreal16,0>::maxValue() const
00568 {
00569 return H_REAL16_MAX;
00570 }
00571
00572 template<>
00573 inline fpreal16
00574 PXL_Pixel<fpreal16,1>::maxValue() const
00575 {
00576 return H_REAL16_MAX;
00577 }
00578
00579
00580
00581
00582 template<>
00583 inline unsigned char
00584 PXL_Pixel<unsigned char,0>::operator/(int val) const
00585 {
00586 int result = (int(myValue) - myBlack) *maxValue() /(myWhite - myBlack);
00587 result /= val;
00588 result = result * (myWhite - myBlack) / maxValue() + myBlack;
00589
00590 if(result > maxValue())
00591 result = maxValue();
00592 else if(result < 0)
00593 result = 0;
00594
00595 return result;
00596 }
00597
00598 template<>
00599 inline unsigned char
00600 PXL_Pixel<unsigned char,1>::operator/(int val) const
00601 {
00602 return (val > 0) ? (myValue / val) : 0;
00603 }
00604
00605 template<>
00606 inline unsigned char
00607 PXL_Pixel<unsigned char,0>::operator*(int val) const
00608 {
00609 int64 result = myValue;
00610 int64 max = maxValue();
00611
00612 result = (int64(myValue) - myBlack) * max / (myWhite - myBlack);
00613 result *= val;
00614 result = result * (myWhite - myBlack) / max + myBlack;
00615
00616 if(result > max)
00617 result = max;
00618 else if(result < 0)
00619 result = 0;
00620
00621 return result;
00622 }
00623
00624 template<>
00625 inline unsigned char
00626 PXL_Pixel<unsigned char,1>::operator*(int val) const
00627 {
00628 int64 max = maxValue();
00629 int64 result = myValue * val;
00630
00631 if(result > max)
00632 result = max;
00633 else if(result < 0)
00634 result = 0;
00635
00636 return result;
00637 }
00638
00639 template<>
00640 inline unsigned char
00641 PXL_Pixel<unsigned char,0>::operator*(float fval) const
00642 {
00643 int64 result;
00644 int64 max = maxValue();
00645 double f;
00646
00647 result = (int(myValue) - myBlack) *max / (myWhite - myBlack);
00648
00649 f = result * fval;
00650 result = (f > 0.0) ? int64(f + 0.5) : int64(f-0.5);
00651 result = result *(myWhite+myBlack) / max + myBlack;
00652
00653 if(result > max)
00654 result = max;
00655 else if(result < 0)
00656 result = 0;
00657
00658 return (unsigned char) result;
00659 }
00660
00661 template<>
00662 inline unsigned char
00663 PXL_Pixel<unsigned char,1>::operator*(float fval) const
00664 {
00665 int64 result;
00666 int64 max = maxValue();
00667
00668 if(fval > 0.0F)
00669 {
00670 double f;
00671
00672 result = myValue;
00673 f = result * fval;
00674 result = (f>0.0) ? int64(f + 0.5) : int64(f - 0.5);
00675 }
00676 else
00677 result = 0;
00678
00679 if(result > max)
00680 result = max;
00681 else if(result < 0)
00682 result = 0;
00683
00684 return (unsigned char) result;
00685 }
00686
00687 template<>
00688 inline PXL_Pixel<unsigned char,0>::operator unsigned char () const
00689 {
00690 int result = (int(myValue) - myBlack) *UCHAR_MAX / (myWhite - myBlack);
00691
00692 if(result > UCHAR_MAX)
00693 result = UCHAR_MAX;
00694 else if(result < 0)
00695 result = 0;
00696
00697 return (unsigned char) result;
00698 }
00699
00700 template<>
00701 inline PXL_Pixel<unsigned char,1>::operator unsigned char () const
00702 {
00703 return myValue;
00704 }
00705
00706 template<>
00707 inline PXL_Pixel<unsigned char,0>::operator unsigned short () const
00708 {
00709 int64 result = (((int64)myValue) - ((int64)myBlack)) *((int64)USHRT_MAX)
00710 / (int64)(myWhite - myBlack);
00711
00712 if(result > (int64)USHRT_MAX)
00713 result = (int64)USHRT_MAX;
00714 else if(result < 0)
00715 result = 0;
00716
00717 return (unsigned short) (result&0x0000FFFFU);
00718 }
00719
00720 template<>
00721 inline PXL_Pixel<unsigned char,1>::operator unsigned short () const
00722 {
00723 unsigned short val = (((unsigned short)myValue) << 8) +
00724 ((unsigned short)myValue);
00725
00726 return val;
00727 }
00728
00729
00730 template<>
00731 inline PXL_Pixel<unsigned char,0>::operator unsigned int () const
00732 {
00733 int64 val = (int64)((myValue) - myBlack) *
00734 ((int64)UINT_MAX) / ((int64)(myWhite - myBlack));
00735
00736 if(val < 0) val =0;
00737 if(val > (int64) UINT_MAX) val = (int64) UINT_MAX;
00738
00739 return (unsigned int) val;
00740 }
00741
00742 template<>
00743 inline PXL_Pixel<unsigned char,1>::operator unsigned int () const
00744 {
00745 unsigned int result = (((unsigned int)myValue) << 24U) +
00746 (((unsigned int)myValue) << 16U) +
00747 (((unsigned int)myValue) << 8U) +
00748 (((unsigned int)myValue));
00749 return result;
00750 }
00751
00752 template<>
00753 inline PXL_Pixel<unsigned char,0>::operator float () const
00754 {
00755 return float((int)(myValue - myBlack)) * myPntScale;
00756 }
00757
00758 template<>
00759 inline PXL_Pixel<unsigned char,1>::operator float () const
00760 {
00761 #ifdef USE_LUT_FOR_8_TO_FP_CONV
00762 return lut8bitFP[myValue];
00763 #else
00764 return (((int)myValue) * 3.921569e-03f);
00765 #endif
00766 }
00767
00768 template<>
00769 inline void
00770 PXL_Pixel<unsigned char,0>::mapValue(unsigned int v)
00771 {
00772 int max = maxValue();
00773 int half = (max>>1);
00774 int result = (v * (myWhite - myBlack) + half) / max + myBlack;
00775
00776 if(result > max)
00777 result = max;
00778 else if(result < 0)
00779 result = 0;
00780
00781 myValue = (unsigned char) result;
00782 }
00783
00784 template<>
00785 inline void
00786 PXL_Pixel<unsigned char,1>::mapValue(unsigned int v)
00787 {
00788 int max = maxValue();
00789
00790 if(v > max)
00791 v = max;
00792
00793 myValue = (unsigned char) v;
00794 }
00795
00796 template<>
00797 inline int
00798 PXL_Pixel<unsigned char,0>::getIntFromFloat(float f) const
00799 {
00800 int range = myWhite - myBlack;
00801 float max = float(int(maxValue()) - myBlack) / float(range);
00802 float min = float(int(minValue()) - myBlack) / float(range);
00803
00804 if(f > max)
00805 f = max;
00806 else if(f < min)
00807 f = min;
00808
00809 return (int) UTfloorIL(range *f +myBlack +0.5F);
00810 }
00811
00812 template<>
00813 inline int
00814 PXL_Pixel<unsigned char,1>::getIntFromFloat(float f) const
00815 {
00816 if(f > 1.0F)
00817 f = 1.0F;
00818 else if(f < 0.0F)
00819 f = 0.0F;
00820
00821 return int(UTfloorIL(maxValue() *f +0.5F));
00822 }
00823
00824 template<>
00825 inline void
00826 PXL_Pixel<unsigned char, 0>::setBWPoints(float b, float w)
00827 {
00828 if(b < 0.0F) b = 0.0F;
00829 if(w < 0.0F) w = 0.0F;
00830 if(b > 1.0F) b = 1.0F;
00831 if(w > 1.0F) w = 1.0F;
00832
00833 myBlack = (unsigned int)UTfloorIL(b * UCHAR_MAX + 0.5F);
00834 myWhite = (unsigned int)UTfloorIL(w * UCHAR_MAX + 0.5F);
00835 if(myBlack != myWhite)
00836 myPntScale = 1.0f / (myWhite - myBlack);
00837 else
00838 myPntScale = 1.0f;
00839 }
00840
00841 template<>
00842 inline void
00843 PXL_Pixel<unsigned char, 1>::setBWPoints(float , float )
00844 {
00845 myPntScale = 1.0f;
00846 }
00847
00848
00849
00850
00851 template<>
00852 inline unsigned short
00853 PXL_Pixel<unsigned short,0>::operator/(int val) const
00854 {
00855 int64 result = (int64(myValue) -myBlack) * USHRT_MAX / (myWhite - myBlack);
00856 result /= val;
00857 result = result * (myWhite - myBlack) / USHRT_MAX + myBlack;
00858
00859 if(result > maxValue())
00860 result = maxValue();
00861 else if(result < 0)
00862 result = 0;
00863
00864 return (unsigned short) result;
00865 }
00866
00867 template<>
00868 inline unsigned short
00869 PXL_Pixel<unsigned short,1>::operator/(int val) const
00870 {
00871 return (val > 0) ? (myValue / val) : 0;
00872 }
00873
00874 template<>
00875 inline unsigned short
00876 PXL_Pixel<unsigned short,0>::operator*(int val) const
00877 {
00878 int64 result = myValue;
00879 int64 max = maxValue();
00880
00881 result = (int64(myValue) - myBlack) * USHRT_MAX / (myWhite - myBlack);
00882 result *= val;
00883 result = result * (myWhite - myBlack) / USHRT_MAX + myBlack;
00884
00885 if(result > max)
00886 result = max;
00887 else if(result < 0)
00888 result = 0;
00889
00890 return result;
00891 }
00892
00893 template<>
00894 inline unsigned short
00895 PXL_Pixel<unsigned short,1>::operator*(int val) const
00896 {
00897 int64 result = myValue * val;
00898 int64 max = maxValue();
00899
00900 if(result > max)
00901 result = max;
00902 else if(result < 0)
00903 result = 0;
00904
00905 return result;
00906 }
00907
00908 template<>
00909 inline unsigned short
00910 PXL_Pixel<unsigned short,0>::operator*(float fval) const
00911 {
00912 int64 result;
00913 int64 max = maxValue();
00914
00915 result = (int(myValue) - myBlack) *max / (myWhite - myBlack);
00916 double f;
00917
00918 f = result * fval;
00919 result = (f > 0.0) ? int64(f + 0.5) : int64(f-0.5);
00920 result = result *(myWhite+myBlack) / max + myBlack;
00921
00922 if(result > max)
00923 result = max;
00924 else if(result < 0)
00925 result = 0;
00926
00927 return (unsigned short) result;
00928 }
00929
00930 template<>
00931 inline unsigned short
00932 PXL_Pixel<unsigned short,1>::operator*(float fval) const
00933 {
00934 int64 result;
00935 int64 max = maxValue();
00936
00937 if(fval > 0.0F)
00938 {
00939 double f;
00940
00941 result = myValue;
00942 f = result * fval;
00943 result = (f>0.0) ? int64(f + 0.5) : int64(f - 0.5);
00944 }
00945 else
00946 result = 0;
00947
00948 if(result > max)
00949 result = max;
00950 else if(result < 0)
00951 result = 0;
00952
00953 return (unsigned short) result;
00954 }
00955
00956 template<>
00957 inline PXL_Pixel<unsigned short,0>::operator unsigned char () const
00958 {
00959 float result = ((float)myValue-(float)myBlack) / float(myWhite-myBlack);
00960
00961 if(result > 1.0f)
00962 result = 1.0f;
00963 else if(result < 0.0f)
00964 result = 0.0f;
00965
00966 return (int) UTfloorIL(result * UCHAR_MAX);
00967 }
00968
00969 template<>
00970 inline PXL_Pixel<unsigned short,1>::operator unsigned char () const
00971 {
00972 unsigned char val = (unsigned char) ((myValue >> 8)&0x00FF);
00973 if(val < UCHAR_MAX && (myValue &0x0080))
00974 val++;
00975
00976 return val;
00977 }
00978
00979 template<>
00980 inline PXL_Pixel<unsigned short,0>::operator unsigned short () const
00981 {
00982 int result = (int(myValue) - myBlack) *USHRT_MAX / (myWhite - myBlack);
00983
00984 if(result > USHRT_MAX)
00985 result = USHRT_MAX;
00986 else if(result < 0)
00987 result = 0;
00988
00989 return (unsigned short) result;
00990 }
00991
00992 template<>
00993 inline PXL_Pixel<unsigned short,1>::operator unsigned short () const
00994 {
00995 return myValue;
00996 }
00997
00998 template<>
00999 inline PXL_Pixel<unsigned short,0>::operator unsigned int () const
01000 {
01001 float val = float(myValue - myBlack) *myPntScale;
01002
01003 if(val < 0.0f) val = 0.0f;
01004 else if(val > 1.0f) val = 1.0f;
01005
01006 return (unsigned int) UTfloorIL(val * UINT_MAX);
01007 }
01008
01009 template<>
01010 inline PXL_Pixel<unsigned short,1>::operator unsigned int () const
01011 {
01012 unsigned int result = (((unsigned int)myValue) << 15) +
01013 (((unsigned int)myValue) >> 1);
01014 return result;
01015 }
01016
01017 template<>
01018 inline PXL_Pixel<unsigned short,0>::operator float () const
01019 {
01020 return float((int)(myValue - myBlack)) * myPntScale;
01021 }
01022
01023 template<>
01024 inline PXL_Pixel<unsigned short,1>::operator float () const
01025 {
01026 return ((int)myValue) * 1.5259021e-5f;
01027 }
01028
01029 template<>
01030 inline void
01031 PXL_Pixel<unsigned short,0>::mapValue(unsigned int v)
01032 {
01033 int max = maxValue();
01034 int half = (max>>1);
01035 int result = (v * (myWhite - myBlack) + half) / max + myBlack;
01036
01037 if(result > max)
01038 result = max;
01039 else if(result < 0)
01040 result = 0;
01041
01042 myValue = (unsigned short) result;
01043 }
01044
01045 template<>
01046 inline void
01047 PXL_Pixel<unsigned short,1>::mapValue(unsigned int v)
01048 {
01049 int max = maxValue();
01050
01051 if(v > max)
01052 v = max;
01053
01054 myValue = (unsigned short) v;
01055 }
01056
01057
01058 template<>
01059 inline int
01060 PXL_Pixel<unsigned short,0>::getIntFromFloat(float f) const
01061 {
01062 int range = myWhite - myBlack;
01063 float max = float(int(maxValue()) - myBlack) / float(range);
01064 float min = float(int(minValue()) - myBlack) / float(range);
01065
01066 if(f > max)
01067 f = max;
01068 else if(f < min)
01069 f = min;
01070
01071 return int(UTfloorIL(range *f +myBlack +0.5F));
01072 }
01073
01074 template<>
01075 inline int
01076 PXL_Pixel<unsigned short,1>::getIntFromFloat(float f) const
01077 {
01078 if(f > 1.0F)
01079 f = 1.0F;
01080 else if(f < 0.0F)
01081 f = 0.0F;
01082
01083 return int(UTfloorIL(maxValue() *f +0.5F));
01084 }
01085
01086 template<>
01087 inline void
01088 PXL_Pixel<unsigned short, 0>::setBWPoints(float b, float w)
01089 {
01090 if(b < 0.0F) b = 0.0F;
01091 if(w < 0.0F) w = 0.0F;
01092 if(b > 1.0F) b = 1.0F;
01093 if(w > 1.0F) w = 1.0F;
01094
01095 myBlack = (unsigned int)UTfloorIL(b * USHRT_MAX + 0.5F);
01096 myWhite = (unsigned int)UTfloorIL(w * USHRT_MAX + 0.5F);
01097 if(myBlack != myWhite)
01098 myPntScale = 1.0f / (myWhite - myBlack);
01099 else
01100 myPntScale = 1.0f;
01101 }
01102
01103 template<>
01104 inline void
01105 PXL_Pixel<unsigned short, 1>::setBWPoints(float , float )
01106 {
01107 myPntScale = 1.0f;
01108 }
01109
01110
01111
01112
01113
01114
01115
01116
01117
01118 template<>
01119 inline PXL_Pixel<unsigned int,1>::operator unsigned int () const
01120 {
01121 return myValue;
01122 }
01123
01124 template<>
01125 inline PXL_Pixel<unsigned int,0>::operator float () const
01126 {
01127 return (float)((double(myValue) - myBlack) * myPntScale);
01128 }
01129
01130 template<>
01131 inline PXL_Pixel<unsigned int,1>::operator float () const
01132 {
01133 return myValue / double(UINT_MAX);
01134 }
01135
01136 template<>
01137 inline unsigned int
01138 PXL_Pixel<unsigned int,0>::operator/(int val) const
01139 {
01140 int64 result = (int64(myValue) -myBlack)*INT_MAX / (myWhite - myBlack);
01141 result /= val;
01142 result = result * (myWhite - myBlack) / INT_MAX + myBlack;
01143
01144 if(result > maxValue())
01145 result = maxValue();
01146 else if(result < minValue())
01147 result = minValue();
01148
01149 return (unsigned int) result;
01150 }
01151
01152 template<>
01153 inline unsigned int
01154 PXL_Pixel<unsigned int,1>::operator/(int val) const
01155 {
01156 return (val != 0) ? (myValue / val) : 0;
01157 }
01158
01159 #define ABS(x) ((x) < 0 ? -x : x)
01160
01161 template<>
01162 inline unsigned int
01163 PXL_Pixel<unsigned int,0>::operator*(int val) const
01164 {
01165 int64 result = myValue;
01166 int64 max = maxValue();
01167 int64 maxmult;
01168
01169 result = (int64(myValue) - myBlack) * INT_MAX / (myWhite - myBlack);
01170
01171
01172
01173
01174 #if defined(WIN32) || (defined(LINUX) && !defined(INTEL_COMPILER))
01175 maxmult = ABS( ( ((~int64(0))^(int64(1)<<63)) / result ) );
01176 #else
01177 maxmult = ABS(9223372036854775807LL / result);
01178 #endif
01179
01180 if((val > 0 && result > 0) ||
01181 (val < 0 && result < 0) &&
01182 abs(val) > maxmult)
01183 {
01184 result = max;
01185 }
01186 else if(abs(val) > maxmult)
01187 {
01188 result = -max -1;
01189 }
01190 else
01191 {
01192 result *= val;
01193 result = result * (myWhite - myBlack) / INT_MAX + myBlack;
01194 }
01195
01196 if(result > max)
01197 result = max;
01198 else if(result < minValue())
01199 result = minValue();
01200
01201 return result;
01202 }
01203
01204 template<>
01205 inline unsigned int
01206 PXL_Pixel<unsigned int,1>::operator*(int val) const
01207 {
01208 int64 result = myValue * val;
01209 int64 max = maxValue();
01210
01211 if(result > max)
01212 result = max;
01213 else if(result < minValue())
01214 result = minValue();
01215
01216 return result;
01217 }
01218
01219 template<>
01220 inline unsigned int
01221 PXL_Pixel<unsigned int,0>::operator*(float fval) const
01222 {
01223 int64 result;
01224 int64 max = maxValue();
01225 double f;
01226
01227 result = (int(myValue) - myBlack) * max / (myWhite - myBlack);
01228
01229 f = result * fval;
01230
01231 result = (f > 0.0) ? int64(f + 0.5) : int64(f-0.5);
01232 result = result *(myWhite+myBlack) / max + myBlack;
01233
01234 if(result > max)
01235 result = max;
01236 else if(result < minValue())
01237 result = minValue();
01238
01239 return (int) result;
01240 }
01241
01242 template<>
01243 inline unsigned int
01244 PXL_Pixel<unsigned int,1>::operator*(float fval) const
01245 {
01246 int64 result;
01247 int64 max = maxValue();
01248 double f;
01249
01250 result = myValue;
01251 f = result * fval;
01252 result = (f>0.0) ? int64(f + 0.5) : int64(f - 0.5);
01253
01254 if(result > max)
01255 result = max;
01256 else if(result < minValue())
01257 result = minValue();
01258
01259 return (int) result;
01260 }
01261
01262 template<>
01263 inline PXL_Pixel<unsigned int,0>::operator unsigned char () const
01264 {
01265 int64 result = (((int64)(myValue)) -myBlack) *UCHAR_MAX /(myWhite-myBlack);
01266
01267 if(result > UCHAR_MAX)
01268 result = UCHAR_MAX;
01269 else if(result < 0)
01270 result = 0;
01271
01272 return (unsigned char) result;
01273 }
01274
01275 template<>
01276 inline PXL_Pixel<unsigned int,1>::operator unsigned char () const
01277 {
01278 unsigned int val;
01279
01280 val = (unsigned char) ((myValue >> 24U)&0x000000FFU);
01281 if(val < UCHAR_MAX && (myValue & 0x00800000U))
01282 val++;
01283
01284 return val;
01285 }
01286
01287 template<>
01288 inline PXL_Pixel<unsigned int,0>::operator unsigned short () const
01289 {
01290 int64 result = (int64)((int64)myValue-(int64)myBlack) *((int64)USHRT_MAX) /
01291 ((int64)(myWhite - myBlack));
01292
01293 if(result > (int64) USHRT_MAX)
01294 result = (int64) USHRT_MAX;
01295 else if(result < 0)
01296 result = 0;
01297
01298 return (unsigned short) (result&0x0000FFFF);
01299 }
01300
01301 template<>
01302 inline PXL_Pixel<unsigned int,1>::operator unsigned short () const
01303 {
01304 int val;
01305
01306 val = (unsigned short) ((myValue >> 16U)&0x0000FFFFU);
01307 if(val < USHRT_MAX && (myValue & 0x00008000U))
01308 val++;
01309
01310 return (unsigned short) val;
01311 }
01312
01313 template<>
01314 inline PXL_Pixel<unsigned int,0>::operator unsigned int () const
01315 {
01316 int64 result = myValue;
01317 result = (result - myBlack) *INT_MAX / (myWhite - myBlack);
01318 if(result > INT_MAX)
01319 result = INT_MAX;
01320 else if(result < INT_MIN)
01321 result = INT_MIN;
01322
01323 return (unsigned int) result;
01324 }
01325
01326 template<>
01327 inline void
01328 PXL_Pixel<unsigned int,0>::mapValue(unsigned int v)
01329 {
01330 int64 max = maxValue();
01331 int64 half = (max>>1);
01332 int64 result = (int64(v) * (myWhite - myBlack) + half) / max + myBlack;
01333
01334 if(result > max)
01335 result = max;
01336 else if(result < minValue())
01337 result = minValue();
01338
01339 myValue = (unsigned int) result;
01340 }
01341
01342 template<>
01343 inline void
01344 PXL_Pixel<unsigned int,1>::mapValue(unsigned int v)
01345 {
01346 int64 max = maxValue();
01347
01348 if(v > max)
01349 v = max;
01350 else if(v < minValue())
01351 v = minValue();
01352
01353 myValue = (int) v;
01354 }
01355
01356 template<>
01357 inline int
01358 PXL_Pixel<unsigned int,0>::getIntFromFloat(float f) const
01359 {
01360 int range = myWhite - myBlack;
01361 float max = float(maxValue() - myBlack) / float(range);
01362 float min = float(minValue() - myBlack) / float(range);
01363
01364 if(f > max)
01365 f = max;
01366 else if(f < min)
01367 f = min;
01368
01369 return int(UTfloorIL(range *f +myBlack +0.5F));
01370 }
01371
01372 template<>
01373 inline int
01374 PXL_Pixel<unsigned int,1>::getIntFromFloat(float f) const
01375 {
01376 if(f > 1.0F)
01377 f = 1.0F;
01378 else if(f < 0.0F)
01379 f = 0.0F;
01380
01381 return (unsigned int)(UTfloorIL(maxValue() *f +0.5F));
01382 }
01383
01384 template<>
01385 inline void
01386 PXL_Pixel<unsigned int, 0>::setBWPoints(float b, float w)
01387 {
01388 if(b < 0.0F) b = 0.0F;
01389 if(w < 0.0F) w = 0.0F;
01390 if(b > 1.0F) b = 1.0F;
01391 if(w > 1.0F) w = 1.0F;
01392
01393 myBlack = (unsigned int)UTfloorIL(b * UINT_MAX + 0.5F);
01394 myWhite = (unsigned int)UTfloorIL(w * UINT_MAX + 0.5F);
01395 if(myBlack != myWhite)
01396 myPntScale = 1.0f / (myWhite - myBlack);
01397 else
01398 myPntScale = 1.0f;
01399 }
01400
01401 template<>
01402 inline void
01403 PXL_Pixel<unsigned int, 1>::setBWPoints(float , float )
01404 {
01405 myPntScale = 1.0f;
01406 }
01407
01408
01409
01410
01411
01412 template<>
01413 inline float
01414 PXL_Pixel<float,0>::operator +(int val) const
01415 {
01416 return myValue + val;
01417 }
01418
01419 template<>
01420 inline float
01421 PXL_Pixel<float,1>::operator +(int val) const
01422 {
01423 return myValue + val;
01424 }
01425
01426 template<>
01427 inline float
01428 PXL_Pixel<float,0>::operator/(int val) const
01429 {
01430 return myValue / val;
01431 }
01432
01433 template<>
01434 inline float
01435 PXL_Pixel<float,1>::operator/(int val) const
01436 {
01437 return myValue / val;
01438 }
01439
01440 template<>
01441 inline float
01442 PXL_Pixel<float,0>::operator*(int val) const
01443 {
01444 return myValue * val;
01445 }
01446
01447 template<>
01448 inline float
01449 PXL_Pixel<float,1>::operator*(int val) const
01450 {
01451 return myValue * val;
01452 }
01453
01454 template<>
01455 inline float
01456 PXL_Pixel<float,0>::operator + (float fval) const
01457 {
01458 return myValue + fval;
01459 }
01460
01461 template<>
01462 inline float
01463 PXL_Pixel<float,1>::operator + (float fval) const
01464 {
01465 return myValue + fval;
01466 }
01467
01468 template<>
01469 inline float
01470 PXL_Pixel<float,0>::operator / (float fval) const
01471 {
01472 return myValue / fval;
01473 }
01474
01475 template<>
01476 inline float
01477 PXL_Pixel<float,1>::operator / (float fval) const
01478 {
01479 return myValue / fval;
01480 }
01481
01482 template<>
01483 inline float
01484 PXL_Pixel<float,0>::operator * (float fval) const
01485 {
01486 return myValue * fval;
01487 }
01488
01489 template<>
01490 inline float
01491 PXL_Pixel<float,1>::operator * (float fval) const
01492 {
01493 return myValue * fval;
01494 }
01495
01496 template<>
01497 inline float
01498 PXL_Pixel<float,0>::operator +=(float fval)
01499 {
01500 return myValue += fval;
01501 }
01502
01503 template<>
01504 inline float
01505 PXL_Pixel<float,1>::operator +=(float fval)
01506 {
01507 return myValue += fval;
01508 }
01509
01510 template<>
01511 inline PXL_Pixel<float,0>::operator unsigned char () const
01512 {
01513 unsigned char val;
01514 float f;
01515
01516 f = myValue;
01517 if(f < 0.0F)
01518 f = 0.0F;
01519 else if(f > 1.0F)
01520 f = 1.0F;
01521
01522 val = (unsigned char) UTfloorIL(f * UCHAR_MAX + 0.5F);
01523
01524 return val;
01525 }
01526
01527 template<>
01528 inline PXL_Pixel<float,1>::operator unsigned char () const
01529 {
01530 unsigned char val;
01531 float f;
01532
01533 f = myValue;
01534 if(f < 0.0F)
01535 f = 0.0F;
01536 else if(f > 1.0F)
01537 f = 1.0F;
01538
01539 val = (unsigned char) UTfloorIL(f * UCHAR_MAX + 0.5F);
01540
01541 return val;
01542 }
01543
01544 template<>
01545 inline PXL_Pixel<float,0>::operator unsigned short () const
01546 {
01547 unsigned short val;
01548 float f;
01549
01550 f = myValue;
01551 if(f < 0.0F)
01552 f = 0.0F;
01553 else if(f > 1.0F)
01554 f = 1.0F;
01555
01556 val = (unsigned short) UTfloorIL(f * USHRT_MAX + 0.5F);
01557
01558 return val;
01559 }
01560
01561 template<>
01562 inline PXL_Pixel<float,1>::operator unsigned short () const
01563 {
01564 unsigned short val;
01565 float f;
01566
01567 f = myValue;
01568 if(f < 0.0F)
01569 f = 0.0F;
01570 else if(f > 1.0F)
01571 f = 1.0F;
01572
01573 val = (unsigned short) UTfloorIL(f * USHRT_MAX + 0.5F);
01574
01575 return val;
01576 }
01577
01578 template<>
01579 inline PXL_Pixel<float,0>::operator unsigned int () const
01580 {
01581 unsigned int result;
01582 float f;
01583
01584 f = myValue;
01585 if(f < 0.0F)
01586 f = 0.0F;
01587 else if(f > 1.0F)
01588 f = 1.0F;
01589
01590 result = (unsigned int)UTfloorIL(f * UINT_MAX);
01591
01592 return result;
01593 }
01594
01595 template<>
01596 inline PXL_Pixel<float,1>::operator unsigned int () const
01597 {
01598 unsigned int result;
01599 float f;
01600
01601 f = myValue;
01602 if(f < 0.0F)
01603 f = 0.0F;
01604 else if(f > 1.0F)
01605 f = 1.0F;
01606
01607 result = (unsigned int)UTfloorIL(f * UINT_MAX);
01608
01609 return result;
01610 }
01611
01612 template<>
01613 inline PXL_Pixel<float,0>::operator float () const
01614 {
01615 return myValue;
01616 }
01617
01618 template<>
01619 inline PXL_Pixel<float,1>::operator float () const
01620 {
01621 return myValue;
01622 }
01623
01624 template<>
01625 inline PXL_Pixel<fpreal16,0>::operator float () const
01626 {
01627 return (float)myValue;
01628 }
01629
01630 template<>
01631 inline PXL_Pixel<fpreal16,1>::operator float () const
01632 {
01633 return (float)myValue;
01634 }
01635
01636 template<>
01637 inline float
01638 PXL_Pixel<float,0>::assign(unsigned int val)
01639 {
01640 return (myValue = (float)val);
01641 }
01642
01643 template<>
01644 inline float
01645 PXL_Pixel<float,1>::assign(unsigned int val)
01646 {
01647 return (myValue = (float)val);
01648 }
01649
01650 template<>
01651 inline int
01652 PXL_Pixel<float,0>::operator==(unsigned int val) const
01653 {
01654 return UTisEqual(myValue, float(val));
01655 }
01656
01657 template<>
01658 inline int
01659 PXL_Pixel<float,1>::operator==(unsigned int val) const
01660 {
01661 return UTisEqual(myValue, float(val));
01662 }
01663
01664 template<>
01665 inline float
01666 PXL_Pixel<float,0>::operator =(float fval)
01667 {
01668 return (myValue = fval);
01669 }
01670
01671 template<>
01672 inline float
01673 PXL_Pixel<float,1>::operator =(float fval)
01674 {
01675 return (myValue = fval);
01676 }
01677
01678 template<>
01679 inline int
01680 PXL_Pixel<float,0>::operator==(float fval) const
01681 {
01682 return UTisEqual(myValue, fval);
01683 }
01684
01685 template<>
01686 inline int
01687 PXL_Pixel<float,1>::operator==(float fval) const
01688 {
01689 return UTisEqual(myValue, fval);
01690 }
01691
01692 template<>
01693 inline int
01694 PXL_Pixel<float,0>::getIntFromFloat(float f) const
01695 {
01696 return (int)f;
01697 }
01698
01699 template<>
01700 inline int
01701 PXL_Pixel<float,1>::getIntFromFloat(float f) const
01702 {
01703 return (int)f;
01704 }
01705
01706
01707 template<>
01708 inline fpreal16
01709 PXL_Pixel<fpreal16,0>::assign(unsigned int val)
01710 {
01711 return (myValue = (float)val);
01712 }
01713
01714 template<>
01715 inline fpreal16
01716 PXL_Pixel<fpreal16,1>::assign(unsigned int val)
01717 {
01718 return (myValue = (float)val);
01719 }
01720
01721 template<>
01722 inline int
01723 PXL_Pixel<fpreal16,0>::operator==(unsigned int val) const
01724 {
01725 return UTisEqual((float)myValue, float(val));
01726 }
01727
01728 template<>
01729 inline int
01730 PXL_Pixel<fpreal16,1>::operator==(unsigned int val) const
01731 {
01732 return UTisEqual((float)myValue, float(val));
01733 }
01734
01735 template<>
01736 inline fpreal16
01737 PXL_Pixel<fpreal16,0>::operator =(float fval)
01738 {
01739 myValue = fval;
01740 return (float) myValue;
01741 }
01742
01743 template<>
01744 inline fpreal16
01745 PXL_Pixel<fpreal16,1>::operator =(float fval)
01746 {
01747 myValue = fval;
01748 return (float) myValue;
01749 }
01750
01751 template<>
01752 inline int
01753 PXL_Pixel<fpreal16,0>::operator==(float fval) const
01754 {
01755 return UTisEqual((float)myValue, fval);
01756 }
01757
01758 template<>
01759 inline int
01760 PXL_Pixel<fpreal16,1>::operator==(float fval) const
01761 {
01762 return UTisEqual((float)myValue, fval);
01763 }
01764
01765 template<>
01766 inline int
01767 PXL_Pixel<fpreal16,0>::getIntFromFloat(float f) const
01768 {
01769 return (int) ((float)f);
01770 }
01771
01772 template<>
01773 inline int
01774 PXL_Pixel<fpreal16,1>::getIntFromFloat(float f) const
01775 {
01776 return (int) ((float)f);
01777 }
01778
01779
01780
01781 template<class Type, int fast> inline bool
01782 PXL_Pixel<Type,fast>::isSameType(PXL_DataFormat format,
01783 unsigned b, unsigned w) const
01784 {
01785 return myType == format && (myType == PXL_FLOAT16 ||
01786 myType == PXL_FLOAT32 ||
01787 (b == myBlack && w == myWhite));
01788 }
01789
01790
01791 template<class Type, int fast> inline Type
01792 PXL_Pixel<Type,fast>::operator+(int val) const
01793 {
01794 Type result = myValue;
01795 Type max = maxValue();
01796
01797 if(val > 0)
01798 {
01799 if(val > max - myValue)
01800 result = max;
01801 else
01802 result += val;
01803 }
01804 else if(val < 0)
01805 {
01806 if(-val > myValue)
01807 result = 0;
01808 else
01809 result += val;
01810 }
01811
01812 return result;
01813 }
01814
01815 template<class Type, int fast> inline Type
01816 PXL_Pixel<Type,fast>::operator-(int val) const
01817 {
01818 return *this + (-val);
01819 }
01820
01821 template<class Type, int fast> inline Type
01822 PXL_Pixel<Type,fast>::operator+=(int val)
01823 {
01824 myValue = *this + val;
01825 return myValue;
01826 }
01827
01828 template<class Type, int fast> inline Type
01829 PXL_Pixel<Type,fast>::operator-=(int val)
01830 {
01831 myValue = *this + (-val);
01832 return myValue;
01833 }
01834
01835 template<class Type, int fast> inline Type
01836 PXL_Pixel<Type,fast>::operator/=(int val)
01837 {
01838 myValue = *this / val;
01839 return myValue;
01840 }
01841
01842 template<class Type, int fast> inline Type
01843 PXL_Pixel<Type,fast>::operator*=(int val)
01844 {
01845 myValue = *this * val;
01846 return myValue;
01847 }
01848
01849
01850 template<class Type, int fast> inline Type
01851 PXL_Pixel<Type,fast>::operator+(float fval) const
01852 {
01853 return *this + getIntFromFloat(fval);
01854 }
01855
01856 template<class Type, int fast> inline Type
01857 PXL_Pixel<Type,fast>::operator-(float fval) const
01858 {
01859 return *this + (-fval);
01860 }
01861
01862 template<class Type, int fast> inline Type
01863 PXL_Pixel<Type,fast>::operator/(float fval) const
01864 {
01865 if(fval == 0.0F)
01866 return maxValue();
01867 else
01868 return *this * (1.0F/fval);
01869 }
01870
01871
01872 template<class Type, int fast> inline Type
01873 PXL_Pixel<Type,fast>::operator+=(float fval)
01874 {
01875 int val = (int) UTfloorIL((myWhite-myBlack) *fval +myBlack + 0.5F);
01876 return *this += val;
01877 }
01878
01879 template<class Type, int fast> inline Type
01880 PXL_Pixel<Type,fast>::operator-=(float fval)
01881 {
01882 return *this += (-fval);
01883 }
01884
01885 template<class Type, int fast> inline Type
01886 PXL_Pixel<Type,fast>::operator*=(float fval)
01887 {
01888 return myValue = (*this * fval);
01889 }
01890
01891 template<class Type, int fast> inline Type
01892 PXL_Pixel<Type,fast>::operator/=(float fval)
01893 {
01894 if(fval == 0.0F)
01895 {
01896 myValue = maxValue();
01897 return myValue;
01898 }
01899 else
01900 return *this *= (1.0F/fval);
01901 }
01902
01903 template<>
01904 inline unsigned char
01905 PXL_Pixel<unsigned char,1>::operator =(float fval)
01906 {
01907 int t = (int) UTfloorIL(fval * 255.0f +0.5F);
01908
01909 myValue = (unsigned char) PXLclampChar(t);
01910
01911 return myValue;
01912 }
01913
01914 template<>
01915 inline unsigned char
01916 PXL_Pixel<unsigned char,0>::operator =(float fval)
01917 {
01918 float f = fval * float(myWhite - myBlack) + (float)myBlack;
01919 int t = (int) UTfloorIL(f +0.5F);
01920
01921 myValue = (unsigned char) PXLclampChar(t);
01922
01923 return myValue;
01924 }
01925
01926 template<>
01927 inline unsigned short
01928 PXL_Pixel<unsigned short,1>::operator =(float fval)
01929 {
01930 int t = (int) UTfloorIL(fval * 65535.0f +0.5F);
01931
01932 myValue = (unsigned short) PXLclampShort(t);
01933
01934 return myValue;
01935 }
01936
01937 template<>
01938 inline unsigned short
01939 PXL_Pixel<unsigned short,0>::operator =(float fval)
01940 {
01941 float f = fval * float(myWhite - myBlack) + (float)myBlack;
01942 int t = (int) UTfloorIL(f +0.5F);
01943
01944 myValue = PXLclampShort(t);
01945
01946 return myValue;
01947 }
01948
01949 template<class Type, int fast> inline Type
01950 PXL_Pixel<Type,fast>::operator =(float fval)
01951 {
01952 double f = fval * double(myWhite - myBlack) + myBlack;
01953
01954 f = UTfloorIL(f +0.5F);
01955
01956 if(f < minValue())
01957 set(minValue());
01958 else if(f > maxValue())
01959 set(maxValue());
01960 else
01961 set((unsigned int) f);
01962
01963 return myValue;
01964 }
01965
01966 template<class Type, int fast> inline Type
01967 PXL_Pixel<Type,fast>::assign(unsigned int val)
01968 {
01969 if(val > maxValue())
01970 myValue = maxValue();
01971 else if(val < minValue())
01972 myValue = minValue();
01973 else
01974 myValue = val;
01975
01976 return myValue;
01977 }
01978
01979 template<class Type, int fast> inline Type
01980 PXL_Pixel<Type,fast>::set(Type val)
01981 {
01982 myValue = val;
01983 return myValue;
01984 }
01985
01986
01987
01988 template<class Type, int fast> inline int
01989 PXL_Pixel<Type,fast>::operator==(float fval) const
01990 {
01991 unsigned int val = (int) UTfloorIL(fval *(myWhite-myBlack) +myBlack +0.5F);
01992
01993 return (*this == val);
01994 }
01995
01996 template<class Type, int fast> inline int
01997 PXL_Pixel<Type,fast>::operator==(unsigned int val) const
01998 {
01999 if(val > maxValue())
02000 val = maxValue();
02001
02002 return (val == myValue) ? 1 : 0;
02003 }
02004
02005 template<class Type, int fast> inline void
02006 PXL_Pixel<Type,fast>::setRange(unsigned int b, unsigned int w)
02007 {
02008 myWhite = w;
02009 myBlack = b;
02010 }
02011
02012 template<class Type, int fast> inline void
02013 PXL_Pixel<Type,fast>::mapValue(unsigned int v)
02014 {
02015
02016 myValue = v;
02017 }
02018
02019 template<class Type, int fast> void
02020 PXL_Pixel<Type, fast>::setBWPoints(float , float )
02021 {
02022 myPntScale = 1.0f;
02023 }
02024
02025 #endif