33 #ifdef USE_LUT_FOR_8_TO_FP_CONV
35 static float lut8bitFP[256] =
37 0.000000, 0.003922, 0.007843, 0.011765, 0.015686, 0.019608, 0.023529, 0.027451,
38 0.031373, 0.035294, 0.039216, 0.043137, 0.047059, 0.050980, 0.054902, 0.058824,
39 0.062745, 0.066667, 0.070588, 0.074510, 0.078431, 0.082353, 0.086275, 0.090196,
40 0.094118, 0.098039, 0.101961, 0.105882, 0.109804, 0.113725, 0.117647, 0.121569,
41 0.125490, 0.129412, 0.133333, 0.137255, 0.141176, 0.145098, 0.149020, 0.152941,
42 0.156863, 0.160784, 0.164706, 0.168627, 0.172549, 0.176471, 0.180392, 0.184314,
43 0.188235, 0.192157, 0.196078, 0.200000, 0.203922, 0.207843, 0.211765, 0.215686,
44 0.219608, 0.223529, 0.227451, 0.231373, 0.235294, 0.239216, 0.243137, 0.247059,
45 0.250980, 0.254902, 0.258824, 0.262745, 0.266667, 0.270588, 0.274510, 0.278431,
46 0.282353, 0.286275, 0.290196, 0.294118, 0.298039, 0.301961, 0.305882, 0.309804,
47 0.313725, 0.317647, 0.321569, 0.325490, 0.329412, 0.333333, 0.337255, 0.341176,
48 0.345098, 0.349020, 0.352941, 0.356863, 0.360784, 0.364706, 0.368627, 0.372549,
49 0.376471, 0.380392, 0.384314, 0.388235, 0.392157, 0.396078, 0.400000, 0.403922,
50 0.407843, 0.411765, 0.415686, 0.419608, 0.423529, 0.427451, 0.431373, 0.435294,
51 0.439216, 0.443137, 0.447059, 0.450980, 0.454902, 0.458824, 0.462745, 0.466667,
52 0.470588, 0.474510, 0.478431, 0.482353, 0.486275, 0.490196, 0.494118, 0.498039,
53 0.501961, 0.505882, 0.509804, 0.513725, 0.517647, 0.521569, 0.525490, 0.529412,
54 0.533333, 0.537255, 0.541176, 0.545098, 0.549020, 0.552941, 0.556863, 0.560784,
55 0.564706, 0.568627, 0.572549, 0.576471, 0.580392, 0.584314, 0.588235, 0.592157,
56 0.596078, 0.600000, 0.603922, 0.607843, 0.611765, 0.615686, 0.619608, 0.623529,
57 0.627451, 0.631373, 0.635294, 0.639216, 0.643137, 0.647059, 0.650980, 0.654902,
58 0.658824, 0.662745, 0.666667, 0.670588, 0.674510, 0.678431, 0.682353, 0.686275,
59 0.690196, 0.694118, 0.698039, 0.701961, 0.705882, 0.709804, 0.713725, 0.717647,
60 0.721569, 0.725490, 0.729412, 0.733333, 0.737255, 0.741176, 0.745098, 0.749020,
61 0.752941, 0.756863, 0.760784, 0.764706, 0.768627, 0.772549, 0.776471, 0.780392,
62 0.784314, 0.788235, 0.792157, 0.796078, 0.800000, 0.803922, 0.807843, 0.811765,
63 0.815686, 0.819608, 0.823529, 0.827451, 0.831373, 0.835294, 0.839216, 0.843137,
64 0.847059, 0.850980, 0.854902, 0.858824, 0.862745, 0.866667, 0.870588, 0.874510,
65 0.878431, 0.882353, 0.886275, 0.890196, 0.894118, 0.898039, 0.901961, 0.905882,
66 0.909804, 0.913725, 0.917647, 0.921569, 0.925490, 0.929412, 0.933333, 0.937255,
67 0.941176, 0.945098, 0.949020, 0.952941, 0.956863, 0.960784, 0.964706, 0.968627,
68 0.972549, 0.976471, 0.980392, 0.984314, 0.988235, 0.992157, 0.996078, 1.000000
85 if(myBlack != myWhite)
86 myPntScale = 1.0f / (myWhite - myBlack);
87 else myPntScale = 1.0f;
111 myBlack = pix.myBlack;
112 myWhite = pix.myWhite;
113 myValue = pix.myValue;
114 if(myBlack != myWhite)
115 myPntScale = 1.0f / (myWhite - myBlack);
116 else myPntScale = 1.0f;
127 myBlack = pix.myBlack;
128 myWhite = pix.myWhite;
129 myValue = pix.myValue;
137 unsigned short value)
144 if(myBlack != myWhite)
145 myPntScale = 1.0f / (myWhite - myBlack);
146 else myPntScale = 1.0f;
153 unsigned short value)
170 myBlack = pix.myBlack;
171 myWhite = pix.myWhite;
172 myValue = pix.myValue;
173 if(myBlack != myWhite)
174 myPntScale = 1.0f / (myWhite - myBlack);
175 else myPntScale = 1.0f;
185 myBlack = pix.myBlack;
186 myWhite = pix.myWhite;
187 myValue = pix.myValue;
202 if(myBlack != myWhite)
203 myPntScale = 1.0f / (myWhite - myBlack);
204 else myPntScale = 1.0f;
228 myBlack = pix.myBlack;
229 myWhite = pix.myWhite;
230 myValue = pix.myValue;
231 if(myBlack != myWhite)
232 myPntScale = 1.0f / (myWhite - myBlack);
233 else myPntScale = 1.0f;
244 myBlack = pix.myBlack;
245 myWhite = pix.myWhite;
246 myValue = pix.myValue;
313 myBlack = pix.myBlack;
314 myWhite = pix.myWhite;
315 myValue = pix.myValue;
327 myBlack = pix.myBlack;
328 myWhite = pix.myWhite;
329 myValue = pix.myValue;
340 myBlack = pix.myBlack;
341 myWhite = pix.myWhite;
342 myValue = pix.myValue;
354 myBlack = pix.myBlack;
355 myWhite = pix.myWhite;
356 myValue = pix.myValue;
360 template<
class Type,
int fast>
368 if(myBlack != myWhite)
369 myPntScale = 1.0f / (myWhite - myBlack);
370 else myPntScale = 1.0f;
373 template<
class Type,
int fast>
379 myBlack = pix.myBlack;
380 myWhite = pix.myWhite;
381 myValue = pix.myValue;
383 if(myBlack != myWhite)
384 myPntScale = 1.0f / (myWhite - myBlack);
385 else myPntScale = 1.0f;
391 {
return "char:slow"; }
394 {
return "char:fast"; }
397 {
return "short:slow"; }
400 {
return "short:fast"; }
403 {
return "int:slow"; }
406 {
return "int:fast"; }
409 {
return "float:slow"; }
412 {
return "float:fast"; }
415 {
return "float16:slow"; }
418 {
return "float16:fast"; }
420 template<
class Type,
int fast>
inline const char *
422 {
return "unknown"; }
445 return (
unsigned char) 0;
452 return (
unsigned char) 0;
456 inline unsigned short
463 inline unsigned short
470 inline unsigned short
473 return (
unsigned short) 0;
477 inline unsigned short
480 return (
unsigned short) 0;
575 int result = (
int(myValue) - myBlack) *maxValue() /(myWhite - myBlack);
577 result = result * (myWhite - myBlack) / maxValue() + myBlack;
579 if(result > maxValue())
591 return (val > 0) ? (myValue /
val) : 0;
601 result = (
int64(myValue) - myBlack) * max / (myWhite - myBlack);
603 result = result * (myWhite - myBlack) / max + myBlack;
636 result = (
int(myValue) - myBlack) *max / (myWhite - myBlack);
639 result = (f > 0.0) ?
int64(f + 0.5) :
int64(f-0.5);
640 result = result *(myWhite+myBlack) / max + myBlack;
647 return (
unsigned char)
result;
663 result = (f>0.0) ?
int64(f + 0.5) :
int64(f - 0.5);
673 return (
unsigned char)
result;
679 int result = (
int(myValue) - myBlack) *UCHAR_MAX / (myWhite - myBlack);
681 if(result > UCHAR_MAX)
686 return (
unsigned char)
result;
699 / (
int64)(myWhite - myBlack);
701 if(result > (
int64)USHRT_MAX)
702 result = (
int64)USHRT_MAX;
706 return (
unsigned short) (result&0x0000FFFFU);
712 unsigned short val = (((
unsigned short)myValue) << 8) +
713 ((
unsigned short)myValue);
723 ((
int64)UINT_MAX) / ((
int64)(myWhite - myBlack));
726 if(val > (
int64) UINT_MAX) val = (
int64) UINT_MAX;
728 return (
unsigned int)
val;
734 unsigned int result = (((
unsigned int)myValue) << 24U) +
735 (((
unsigned int)myValue) << 16U) +
736 (((
unsigned int)myValue) << 8U) +
737 (((
unsigned int)myValue));
744 return float((
int)(myValue - myBlack)) * myPntScale;
750 #ifdef USE_LUT_FOR_8_TO_FP_CONV
751 return lut8bitFP[myValue];
753 return (((
int)myValue) * 3.921569e-03
f);
761 int max = maxValue();
763 int result = (v * (myWhite - myBlack) + half) / max + myBlack;
770 myValue = (
unsigned char) result;
777 int max = maxValue();
782 myValue = (
unsigned char) v;
789 int range = myWhite - myBlack;
790 float max = float(
int(maxValue()) - myBlack) / float(range);
791 float min = float(
int(minValue()) - myBlack) / float(range);
798 return (
int)
SYSfloorIL(range *f +myBlack +0.5F);
817 if(b < 0.0F) b = 0.0F;
818 if(w < 0.0F) w = 0.0F;
819 if(b > 1.0F) b = 1.0F;
820 if(w > 1.0F) w = 1.0F;
824 if(myBlack != myWhite)
825 myPntScale = 1.0f / (myWhite - myBlack);
841 inline unsigned short
846 result = result * (myWhite - myBlack) / USHRT_MAX + myBlack;
848 if(result > maxValue())
853 return (
unsigned short)
result;
857 inline unsigned short
860 return (val > 0) ? (myValue /
val) : 0;
864 inline unsigned short
870 result = (
int64(myValue) - myBlack) * USHRT_MAX / (myWhite - myBlack);
872 result = result * (myWhite - myBlack) / USHRT_MAX + myBlack;
883 inline unsigned short
898 inline unsigned short
904 result = (
int(myValue) - myBlack) *max / (myWhite - myBlack);
908 result = (f > 0.0) ?
int64(f + 0.5) :
int64(f-0.5);
909 result = result *(myWhite+myBlack) / max + myBlack;
916 return (
unsigned short)
result;
920 inline unsigned short
932 result = (f>0.0) ?
int64(f + 0.5) :
int64(f - 0.5);
942 return (
unsigned short)
result;
948 float result = ((float)myValue-(
float)myBlack) /
float(myWhite-myBlack);
952 else if(result < 0.0
f)
961 unsigned char val = (
unsigned char) ((myValue >> 8)&0x00FF);
962 if(val < UCHAR_MAX && (myValue &0x0080))
971 int result = (
int(myValue) - myBlack) *USHRT_MAX / (myWhite - myBlack);
973 if(result > USHRT_MAX)
978 return (
unsigned short)
result;
990 float val = float(myValue - myBlack) *myPntScale;
992 if(val < 0.0
f) val = 0.0f;
993 else if(val > 1.0
f) val = 1.0f;
995 return (
unsigned int)
SYSfloorIL(val * UINT_MAX);
1001 unsigned int result = (((
unsigned int)myValue) << 15) +
1002 (((
unsigned int)myValue) >> 1);
1009 return float((
int)(myValue - myBlack)) * myPntScale;
1015 return ((
int)myValue) * 1.5259021e-5
f;
1022 int max = maxValue();
1023 int half = (max>>1);
1024 int result = (v * (myWhite - myBlack) + half) / max + myBlack;
1031 myValue = (
unsigned short) result;
1038 int max = maxValue();
1043 myValue = (
unsigned short) v;
1051 int range = myWhite - myBlack;
1052 float max = float(
int(maxValue()) - myBlack) / float(range);
1053 float min = float(
int(minValue()) - myBlack) / float(range);
1079 if(b < 0.0F) b = 0.0F;
1080 if(w < 0.0F) w = 0.0F;
1081 if(b > 1.0F) b = 1.0F;
1082 if(w > 1.0F) w = 1.0F;
1086 if(myBlack != myWhite)
1087 myPntScale = 1.0f / (myWhite - myBlack);
1116 return (
float)((double(myValue) - myBlack) * myPntScale);
1122 return myValue / double(UINT_MAX);
1131 result = result * (myWhite - myBlack) / INT_MAX + myBlack;
1133 if(result > maxValue())
1134 result = maxValue();
1135 else if(result < minValue())
1136 result = minValue();
1138 return (
unsigned int)
result;
1145 return (val != 0) ? (myValue /
val) : 0;
1148 #define ABS(x) ((x) < 0 ? -x : x)
1158 result = (
int64(myValue) - myBlack) * INT_MAX / (myWhite - myBlack);
1163 #if defined(WIN32) || (defined(LINUX) && !defined(INTEL_COMPILER))
1166 maxmult =
ABS(9223372036854775807LL / result);
1174 if(
SYSabs(val) > maxmult)
1176 if((val > 0 && result > 0) ||
1177 (val < 0 && result < 0))
1189 result = result * (myWhite - myBlack) / INT_MAX + myBlack;
1194 else if(result < minValue())
1195 result = minValue();
1209 else if(result < minValue())
1210 result = minValue();
1223 result = (
int(myValue) - myBlack) * max / (myWhite - myBlack);
1227 result = (f > 0.0) ?
int64(f + 0.5) :
int64(f-0.5);
1228 result = result *(myWhite+myBlack) / max + myBlack;
1232 else if(result < minValue())
1233 result = minValue();
1248 result = (f>0.0) ?
int64(f + 0.5) :
int64(f - 0.5);
1252 else if(result < minValue())
1253 result = minValue();
1261 int64 result = (((
int64)(myValue)) -myBlack) *UCHAR_MAX /(myWhite-myBlack);
1263 if(result > UCHAR_MAX)
1268 return (
unsigned char)
result;
1276 val = (
unsigned char) ((myValue >> 24U)&0x000000FFU);
1277 if(val < UCHAR_MAX && (myValue & 0x00800000U))
1287 ((
int64)(myWhite - myBlack));
1289 if(result > (
int64) USHRT_MAX)
1290 result = (
int64) USHRT_MAX;
1294 return (
unsigned short) (result&0x0000FFFF);
1302 val = (
unsigned short) ((myValue >> 16U)&0x0000FFFFU);
1303 if(val < USHRT_MAX && (myValue & 0x00008000U))
1306 return (
unsigned short)
val;
1313 result = (result - myBlack) *INT_MAX / (myWhite - myBlack);
1314 if(result > INT_MAX)
1316 else if(result < INT_MIN)
1319 return (
unsigned int)
result;
1332 else if(result < minValue())
1333 result = minValue();
1335 myValue = (
unsigned int) result;
1346 else if(v < minValue())
1356 int range = myWhite - myBlack;
1357 float max = float(maxValue() - myBlack) / float(range);
1358 float min = float(minValue() - myBlack) / float(range);
1377 return (
unsigned int)(
SYSfloorIL(maxValue() *f +0.5F));
1384 if(b < 0.0F) b = 0.0F;
1385 if(w < 0.0F) w = 0.0F;
1386 if(b > 1.0F) b = 1.0F;
1387 if(w > 1.0F) w = 1.0F;
1391 if(myBlack != myWhite)
1392 myPntScale = 1.0f / (myWhite - myBlack);
1412 return myValue +
val;
1419 return myValue +
val;
1426 return myValue /
val;
1433 return myValue /
val;
1440 return myValue *
val;
1447 return myValue *
val;
1454 return myValue + fval;
1461 return myValue + fval;
1468 return myValue / fval;
1475 return myValue / fval;
1482 return myValue * fval;
1489 return myValue * fval;
1496 return myValue += fval;
1503 return myValue += fval;
1518 val = (
unsigned char)
SYSfloorIL(f * UCHAR_MAX + 0.5F);
1535 val = (
unsigned char)
SYSfloorIL(f * UCHAR_MAX + 0.5F);
1552 val = (
unsigned short)
SYSfloorIL(f * USHRT_MAX + 0.5F);
1569 val = (
unsigned short)
SYSfloorIL(f * USHRT_MAX + 0.5F);
1623 return (
float)myValue;
1629 return (
float)myValue;
1636 return (myValue = (
float)val);
1643 return (myValue = (
float)val);
1650 return SYSisEqual(myValue,
float(val));
1657 return SYSisEqual(myValue,
float(val));
1664 return (myValue = fval);
1671 return (myValue = fval);
1678 return SYSisEqual(myValue, fval);
1685 return SYSisEqual(myValue, fval);
1707 return (myValue = (
float)val);
1714 return (myValue = (
float)val);
1721 return SYSisEqual((
float)myValue,
float(val));
1728 return SYSisEqual((
float)myValue,
float(val));
1736 return (
float) myValue;
1744 return (
float) myValue;
1751 return SYSisEqual((
float)myValue, fval);
1758 return SYSisEqual((
float)myValue, fval);
1765 return (
int) ((float)f);
1772 return (
int) ((float)f);
1777 template<
class Type,
int fast>
inline bool
1779 unsigned b,
unsigned w)
const
1781 return myType == format && (myType ==
PXL_FLOAT16 ||
1783 (b == myBlack && w == myWhite));
1787 template<
class Type,
int fast>
inline Type
1795 if(val > max - myValue)
1811 template<
class Type,
int fast>
inline Type
1814 return *
this + (-
val);
1817 template<
class Type,
int fast>
inline Type
1820 myValue = *
this +
val;
1824 template<
class Type,
int fast>
inline Type
1827 myValue = *
this + (-
val);
1831 template<
class Type,
int fast>
inline Type
1834 myValue = *
this /
val;
1838 template<
class Type,
int fast>
inline Type
1841 myValue = *
this *
val;
1846 template<
class Type,
int fast>
inline Type
1849 return *
this + getIntFromFloat(fval);
1852 template<
class Type,
int fast>
inline Type
1855 return *
this + (-fval);
1858 template<
class Type,
int fast>
inline Type
1864 return *
this * (1.0F/fval);
1868 template<
class Type,
int fast>
inline Type
1872 return *
this +=
val;
1875 template<
class Type,
int fast>
inline Type
1878 return *
this += (-fval);
1881 template<
class Type,
int fast>
inline Type
1884 return myValue = (*
this * fval);
1887 template<
class Type,
int fast>
inline Type
1892 myValue = maxValue();
1896 return *
this *= (1.0F/fval);
1900 inline unsigned char
1911 inline unsigned char
1914 float f = fval * float(myWhite - myBlack) + (float)myBlack;
1923 inline unsigned short
1934 inline unsigned short
1937 float f = fval * float(myWhite - myBlack) + (float)myBlack;
1945 template<
class Type,
int fast>
inline Type
1948 double f = fval * double(myWhite - myBlack) + myBlack;
1954 else if(f > maxValue())
1957 set((
unsigned int) f);
1962 template<
class Type,
int fast>
inline Type
1965 if(val > maxValue())
1966 myValue = maxValue();
1967 else if(val < minValue())
1968 myValue = minValue();
1975 template<
class Type,
int fast>
inline Type
1984 template<
class Type,
int fast>
inline bool
1987 unsigned int val = (
int)
SYSfloorIL(fval *(myWhite-myBlack) +myBlack +0.5F);
1989 return (*
this == val);
1992 template<
class Type,
int fast>
inline bool
1995 if(val > maxValue())
1998 return (val == myValue) ? 1 : 0;
2001 template<
class Type,
int fast>
inline void
2008 template<
class Type,
int fast>
inline void
2015 template<
class Type,
int fast>
void
vint4 max(const vint4 &a, const vint4 &b)
bool isSameType(PXL_DataFormat format, unsigned b, unsigned w) const
GLuint const GLfloat * val
GLint GLint GLsizei GLsizei GLsizei GLint GLenum format
Type operator+(int) const
bool operator==(unsigned int) const
Type operator*(int) const
GLubyte GLubyte GLubyte GLubyte w
PXL_Pixel(unsigned int black=0, unsigned int white=0, Type value=0)
Type operator-(int) const
typedef int(WINAPI *PFNWGLRELEASEPBUFFERDCARBPROC)(HPBUFFERARB hPbuffer
Helper class to output stack traces from the current execution point.
void doTraceback(UTsignalHandlerArg sig_arg, const char *label=0, bool add_markers=false)
GLdouble GLdouble GLdouble b
int getIntFromFloat(float f) const
void mapValue(unsigned int val)
Type operator/(int) const
Type assign(unsigned int)
const char * formatName() const
void setBWPoints(float b, float w)
vint4 min(const vint4 &a, const vint4 &b)
void setRange(unsigned int b, unsigned int w)
GLsizei const GLfloat * value
fpreal32 SYSfloorIL(fpreal32 val)
PXL_API void PXLdetermineProcCaps()