32 #ifdef USE_LUT_FOR_8_TO_FP_CONV
34 static float lut8bitFP[256] =
36 0.000000, 0.003922, 0.007843, 0.011765, 0.015686, 0.019608, 0.023529, 0.027451,
37 0.031373, 0.035294, 0.039216, 0.043137, 0.047059, 0.050980, 0.054902, 0.058824,
38 0.062745, 0.066667, 0.070588, 0.074510, 0.078431, 0.082353, 0.086275, 0.090196,
39 0.094118, 0.098039, 0.101961, 0.105882, 0.109804, 0.113725, 0.117647, 0.121569,
40 0.125490, 0.129412, 0.133333, 0.137255, 0.141176, 0.145098, 0.149020, 0.152941,
41 0.156863, 0.160784, 0.164706, 0.168627, 0.172549, 0.176471, 0.180392, 0.184314,
42 0.188235, 0.192157, 0.196078, 0.200000, 0.203922, 0.207843, 0.211765, 0.215686,
43 0.219608, 0.223529, 0.227451, 0.231373, 0.235294, 0.239216, 0.243137, 0.247059,
44 0.250980, 0.254902, 0.258824, 0.262745, 0.266667, 0.270588, 0.274510, 0.278431,
45 0.282353, 0.286275, 0.290196, 0.294118, 0.298039, 0.301961, 0.305882, 0.309804,
46 0.313725, 0.317647, 0.321569, 0.325490, 0.329412, 0.333333, 0.337255, 0.341176,
47 0.345098, 0.349020, 0.352941, 0.356863, 0.360784, 0.364706, 0.368627, 0.372549,
48 0.376471, 0.380392, 0.384314, 0.388235, 0.392157, 0.396078, 0.400000, 0.403922,
49 0.407843, 0.411765, 0.415686, 0.419608, 0.423529, 0.427451, 0.431373, 0.435294,
50 0.439216, 0.443137, 0.447059, 0.450980, 0.454902, 0.458824, 0.462745, 0.466667,
51 0.470588, 0.474510, 0.478431, 0.482353, 0.486275, 0.490196, 0.494118, 0.498039,
52 0.501961, 0.505882, 0.509804, 0.513725, 0.517647, 0.521569, 0.525490, 0.529412,
53 0.533333, 0.537255, 0.541176, 0.545098, 0.549020, 0.552941, 0.556863, 0.560784,
54 0.564706, 0.568627, 0.572549, 0.576471, 0.580392, 0.584314, 0.588235, 0.592157,
55 0.596078, 0.600000, 0.603922, 0.607843, 0.611765, 0.615686, 0.619608, 0.623529,
56 0.627451, 0.631373, 0.635294, 0.639216, 0.643137, 0.647059, 0.650980, 0.654902,
57 0.658824, 0.662745, 0.666667, 0.670588, 0.674510, 0.678431, 0.682353, 0.686275,
58 0.690196, 0.694118, 0.698039, 0.701961, 0.705882, 0.709804, 0.713725, 0.717647,
59 0.721569, 0.725490, 0.729412, 0.733333, 0.737255, 0.741176, 0.745098, 0.749020,
60 0.752941, 0.756863, 0.760784, 0.764706, 0.768627, 0.772549, 0.776471, 0.780392,
61 0.784314, 0.788235, 0.792157, 0.796078, 0.800000, 0.803922, 0.807843, 0.811765,
62 0.815686, 0.819608, 0.823529, 0.827451, 0.831373, 0.835294, 0.839216, 0.843137,
63 0.847059, 0.850980, 0.854902, 0.858824, 0.862745, 0.866667, 0.870588, 0.874510,
64 0.878431, 0.882353, 0.886275, 0.890196, 0.894118, 0.898039, 0.901961, 0.905882,
65 0.909804, 0.913725, 0.917647, 0.921569, 0.925490, 0.929412, 0.933333, 0.937255,
66 0.941176, 0.945098, 0.949020, 0.952941, 0.956863, 0.960784, 0.964706, 0.968627,
67 0.972549, 0.976471, 0.980392, 0.984314, 0.988235, 0.992157, 0.996078, 1.000000
84 if(myBlack != myWhite)
85 myPntScale = 1.0f / (myWhite - myBlack);
86 else myPntScale = 1.0f;
110 myBlack = pix.myBlack;
111 myWhite = pix.myWhite;
112 myValue = pix.myValue;
113 if(myBlack != myWhite)
114 myPntScale = 1.0f / (myWhite - myBlack);
115 else myPntScale = 1.0f;
126 myBlack = pix.myBlack;
127 myWhite = pix.myWhite;
128 myValue = pix.myValue;
136 unsigned short value)
143 if(myBlack != myWhite)
144 myPntScale = 1.0f / (myWhite - myBlack);
145 else myPntScale = 1.0f;
152 unsigned short value)
169 myBlack = pix.myBlack;
170 myWhite = pix.myWhite;
171 myValue = pix.myValue;
172 if(myBlack != myWhite)
173 myPntScale = 1.0f / (myWhite - myBlack);
174 else myPntScale = 1.0f;
184 myBlack = pix.myBlack;
185 myWhite = pix.myWhite;
186 myValue = pix.myValue;
201 if(myBlack != myWhite)
202 myPntScale = 1.0f / (myWhite - myBlack);
203 else myPntScale = 1.0f;
227 myBlack = pix.myBlack;
228 myWhite = pix.myWhite;
229 myValue = pix.myValue;
230 if(myBlack != myWhite)
231 myPntScale = 1.0f / (myWhite - myBlack);
232 else myPntScale = 1.0f;
243 myBlack = pix.myBlack;
244 myWhite = pix.myWhite;
245 myValue = pix.myValue;
312 myBlack = pix.myBlack;
313 myWhite = pix.myWhite;
314 myValue = pix.myValue;
326 myBlack = pix.myBlack;
327 myWhite = pix.myWhite;
328 myValue = pix.myValue;
339 myBlack = pix.myBlack;
340 myWhite = pix.myWhite;
341 myValue = pix.myValue;
353 myBlack = pix.myBlack;
354 myWhite = pix.myWhite;
355 myValue = pix.myValue;
359 template<
class Type,
int fast>
367 if(myBlack != myWhite)
368 myPntScale = 1.0f / (myWhite - myBlack);
369 else myPntScale = 1.0f;
372 template<
class Type,
int fast>
378 myBlack = pix.myBlack;
379 myWhite = pix.myWhite;
380 myValue = pix.myValue;
382 if(myBlack != myWhite)
383 myPntScale = 1.0f / (myWhite - myBlack);
384 else myPntScale = 1.0f;
390 {
return "char:slow"; }
393 {
return "char:fast"; }
396 {
return "short:slow"; }
399 {
return "short:fast"; }
402 {
return "int:slow"; }
405 {
return "int:fast"; }
408 {
return "float:slow"; }
411 {
return "float:fast"; }
414 {
return "float16:slow"; }
417 {
return "float16:fast"; }
419 template<
class Type,
int fast>
inline const char *
421 {
return "unknown"; }
444 return (
unsigned char) 0;
451 return (
unsigned char) 0;
455 inline unsigned short
462 inline unsigned short
469 inline unsigned short
472 return (
unsigned short) 0;
476 inline unsigned short
479 return (
unsigned short) 0;
574 int result = (
int(myValue) - myBlack) *maxValue() /(myWhite - myBlack);
576 result = result * (myWhite - myBlack) / maxValue() + myBlack;
578 if(result > maxValue())
590 return (val > 0) ? (myValue /
val) : 0;
600 result = (
int64(myValue) - myBlack) * max / (myWhite - myBlack);
602 result = result * (myWhite - myBlack) / max + myBlack;
635 result = (
int(myValue) - myBlack) *max / (myWhite - myBlack);
638 result = (f > 0.0) ?
int64(f + 0.5) :
int64(f-0.5);
639 result = result *(myWhite+myBlack) / max + myBlack;
646 return (
unsigned char)
result;
662 result = (f>0.0) ?
int64(f + 0.5) :
int64(f - 0.5);
672 return (
unsigned char)
result;
678 int result = (
int(myValue) - myBlack) *UCHAR_MAX / (myWhite - myBlack);
680 if(result > UCHAR_MAX)
685 return (
unsigned char)
result;
698 / (
int64)(myWhite - myBlack);
700 if(result > (
int64)USHRT_MAX)
701 result = (
int64)USHRT_MAX;
705 return (
unsigned short) (result&0x0000FFFFU);
711 unsigned short val = (((
unsigned short)myValue) << 8) +
712 ((
unsigned short)myValue);
722 ((
int64)UINT_MAX) / ((
int64)(myWhite - myBlack));
725 if(val > (
int64) UINT_MAX) val = (
int64) UINT_MAX;
727 return (
unsigned int)
val;
733 unsigned int result = (((
unsigned int)myValue) << 24U) +
734 (((
unsigned int)myValue) << 16U) +
735 (((
unsigned int)myValue) << 8U) +
736 (((
unsigned int)myValue));
743 return float((
int)(myValue - myBlack)) * myPntScale;
749 #ifdef USE_LUT_FOR_8_TO_FP_CONV
750 return lut8bitFP[myValue];
752 return (((
int)myValue) * 3.921569e-03
f);
760 int max = maxValue();
762 int result = (v * (myWhite - myBlack) + half) / max + myBlack;
769 myValue = (
unsigned char) result;
776 int max = maxValue();
781 myValue = (
unsigned char) v;
788 int range = myWhite - myBlack;
797 return (
int)
SYSfloorIL(range *f +myBlack +0.5F);
816 if(b < 0.0F) b = 0.0F;
817 if(w < 0.0F) w = 0.0F;
818 if(b > 1.0F) b = 1.0F;
819 if(w > 1.0F) w = 1.0F;
823 if(myBlack != myWhite)
824 myPntScale = 1.0f / (myWhite - myBlack);
840 inline unsigned short
845 result = result * (myWhite - myBlack) / USHRT_MAX + myBlack;
847 if(result > maxValue())
852 return (
unsigned short)
result;
856 inline unsigned short
859 return (val > 0) ? (myValue /
val) : 0;
863 inline unsigned short
869 result = (
int64(myValue) - myBlack) * USHRT_MAX / (myWhite - myBlack);
871 result = result * (myWhite - myBlack) / USHRT_MAX + myBlack;
882 inline unsigned short
897 inline unsigned short
903 result = (
int(myValue) - myBlack) *max / (myWhite - myBlack);
907 result = (f > 0.0) ?
int64(f + 0.5) :
int64(f-0.5);
908 result = result *(myWhite+myBlack) / max + myBlack;
915 return (
unsigned short)
result;
919 inline unsigned short
931 result = (f>0.0) ?
int64(f + 0.5) :
int64(f - 0.5);
941 return (
unsigned short)
result;
947 float result = ((
float)myValue-(
float)myBlack) /
float(myWhite-myBlack);
951 else if(result < 0.0
f)
960 unsigned char val = (
unsigned char) ((myValue >> 8)&0x00FF);
961 if(val < UCHAR_MAX && (myValue &0x0080))
970 int result = (
int(myValue) - myBlack) *USHRT_MAX / (myWhite - myBlack);
972 if(result > USHRT_MAX)
977 return (
unsigned short)
result;
989 float val =
float(myValue - myBlack) *myPntScale;
991 if(val < 0.0
f) val = 0.0f;
992 else if(val > 1.0
f) val = 1.0f;
994 return (
unsigned int)
SYSfloorIL(val * UINT_MAX);
1000 unsigned int result = (((
unsigned int)myValue) << 15) +
1001 (((
unsigned int)myValue) >> 1);
1008 return float((
int)(myValue - myBlack)) * myPntScale;
1014 return ((
int)myValue) * 1.5259021e-5
f;
1021 int max = maxValue();
1022 int half = (max>>1);
1023 int result = (v * (myWhite - myBlack) + half) / max + myBlack;
1030 myValue = (
unsigned short) result;
1037 int max = maxValue();
1042 myValue = (
unsigned short) v;
1050 int range = myWhite - myBlack;
1051 float max =
float(
int(maxValue()) - myBlack) /
float(range);
1052 float min =
float(
int(minValue()) - myBlack) /
float(range);
1078 if(b < 0.0F) b = 0.0F;
1079 if(w < 0.0F) w = 0.0F;
1080 if(b > 1.0F) b = 1.0F;
1081 if(w > 1.0F) w = 1.0F;
1085 if(myBlack != myWhite)
1086 myPntScale = 1.0f / (myWhite - myBlack);
1115 return (
float)((double(myValue) - myBlack) * myPntScale);
1121 return myValue / double(UINT_MAX);
1130 result = result * (myWhite - myBlack) / INT_MAX + myBlack;
1132 if(result > maxValue())
1133 result = maxValue();
1134 else if(result < minValue())
1135 result = minValue();
1137 return (
unsigned int)
result;
1144 return (val != 0) ? (myValue /
val) : 0;
1147 #define ABS(x) ((x) < 0 ? -x : x)
1157 result = (
int64(myValue) - myBlack) * INT_MAX / (myWhite - myBlack);
1162 #if defined(WIN32) || (defined(LINUX) && !defined(INTEL_COMPILER))
1165 maxmult =
ABS(9223372036854775807LL / result);
1170 if(
SYSabs(val) > maxmult)
1172 if((val > 0 && result > 0) ||
1173 (val < 0 && result < 0))
1185 result = result * (myWhite - myBlack) / INT_MAX + myBlack;
1190 else if(result < minValue())
1191 result = minValue();
1205 else if(result < minValue())
1206 result = minValue();
1219 result = (
int(myValue) - myBlack) * max / (myWhite - myBlack);
1223 result = (f > 0.0) ?
int64(f + 0.5) :
int64(f-0.5);
1224 result = result *(myWhite+myBlack) / max + myBlack;
1228 else if(result < minValue())
1229 result = minValue();
1244 result = (f>0.0) ?
int64(f + 0.5) :
int64(f - 0.5);
1248 else if(result < minValue())
1249 result = minValue();
1257 int64 result = (((
int64)(myValue)) -myBlack) *UCHAR_MAX /(myWhite-myBlack);
1259 if(result > UCHAR_MAX)
1264 return (
unsigned char)
result;
1272 val = (
unsigned char) ((myValue >> 24U)&0x000000FFU);
1273 if(val < UCHAR_MAX && (myValue & 0x00800000U))
1283 ((
int64)(myWhite - myBlack));
1285 if(result > (
int64) USHRT_MAX)
1286 result = (
int64) USHRT_MAX;
1290 return (
unsigned short) (result&0x0000FFFF);
1298 val = (
unsigned short) ((myValue >> 16U)&0x0000FFFFU);
1299 if(val < USHRT_MAX && (myValue & 0x00008000U))
1302 return (
unsigned short)
val;
1309 result = (result - myBlack) *INT_MAX / (myWhite - myBlack);
1310 if(result > INT_MAX)
1312 else if(result < INT_MIN)
1315 return (
unsigned int)
result;
1328 else if(result < minValue())
1329 result = minValue();
1331 myValue = (
unsigned int) result;
1342 else if(v < minValue())
1352 int range = myWhite - myBlack;
1373 return (
unsigned int)(
SYSfloorIL(maxValue() *f +0.5F));
1380 if(b < 0.0F) b = 0.0F;
1381 if(w < 0.0F) w = 0.0F;
1382 if(b > 1.0F) b = 1.0F;
1383 if(w > 1.0F) w = 1.0F;
1387 if(myBlack != myWhite)
1388 myPntScale = 1.0f / (myWhite - myBlack);
1408 return myValue +
val;
1415 return myValue +
val;
1422 return myValue /
val;
1429 return myValue /
val;
1436 return myValue *
val;
1443 return myValue *
val;
1450 return myValue + fval;
1457 return myValue + fval;
1464 return myValue / fval;
1471 return myValue / fval;
1478 return myValue * fval;
1485 return myValue * fval;
1492 return myValue += fval;
1499 return myValue += fval;
1514 val = (
unsigned char)
SYSfloorIL(f * UCHAR_MAX + 0.5F);
1531 val = (
unsigned char)
SYSfloorIL(f * UCHAR_MAX + 0.5F);
1548 val = (
unsigned short)
SYSfloorIL(f * USHRT_MAX + 0.5F);
1565 val = (
unsigned short)
SYSfloorIL(f * USHRT_MAX + 0.5F);
1619 return (
float)myValue;
1625 return (
float)myValue;
1632 return (myValue = (
float)val);
1639 return (myValue = (
float)val);
1660 return (myValue = fval);
1667 return (myValue = fval);
1703 return (myValue = (
float)val);
1710 return (myValue = (
float)val);
1717 return SYSisEqual((
float)myValue,
float(val));
1724 return SYSisEqual((
float)myValue,
float(val));
1732 return (
float) myValue;
1740 return (
float) myValue;
1761 return (
int) ((
float)f);
1768 return (
int) ((
float)f);
1773 template<
class Type,
int fast>
inline bool
1775 unsigned b,
unsigned w)
const
1777 return myType == format && (myType ==
PXL_FLOAT16 ||
1779 (b == myBlack && w == myWhite));
1783 template<
class Type,
int fast>
inline Type
1791 if(val > max - myValue)
1807 template<
class Type,
int fast>
inline Type
1810 return *
this + (-
val);
1813 template<
class Type,
int fast>
inline Type
1816 myValue = *
this +
val;
1820 template<
class Type,
int fast>
inline Type
1823 myValue = *
this + (-
val);
1827 template<
class Type,
int fast>
inline Type
1830 myValue = *
this /
val;
1834 template<
class Type,
int fast>
inline Type
1837 myValue = *
this *
val;
1842 template<
class Type,
int fast>
inline Type
1845 return *
this + getIntFromFloat(fval);
1848 template<
class Type,
int fast>
inline Type
1851 return *
this + (-fval);
1854 template<
class Type,
int fast>
inline Type
1860 return *
this * (1.0F/fval);
1864 template<
class Type,
int fast>
inline Type
1868 return *
this +=
val;
1871 template<
class Type,
int fast>
inline Type
1874 return *
this += (-fval);
1877 template<
class Type,
int fast>
inline Type
1880 return myValue = (*
this * fval);
1883 template<
class Type,
int fast>
inline Type
1888 myValue = maxValue();
1892 return *
this *= (1.0F/fval);
1896 inline unsigned char
1907 inline unsigned char
1910 float f = fval *
float(myWhite - myBlack) + (
float)myBlack;
1919 inline unsigned short
1930 inline unsigned short
1933 float f = fval *
float(myWhite - myBlack) + (
float)myBlack;
1941 template<
class Type,
int fast>
inline Type
1944 double f = fval * double(myWhite - myBlack) + myBlack;
1950 else if(f > maxValue())
1953 set((
unsigned int) f);
1958 template<
class Type,
int fast>
inline Type
1961 if(val > maxValue())
1962 myValue = maxValue();
1963 else if(val < minValue())
1964 myValue = minValue();
1971 template<
class Type,
int fast>
inline Type
1980 template<
class Type,
int fast>
inline bool
1983 unsigned int val = (
int)
SYSfloorIL(fval *(myWhite-myBlack) +myBlack +0.5F);
1985 return (*
this == val);
1988 template<
class Type,
int fast>
inline bool
1991 if(val > maxValue())
1994 return (val == myValue) ? 1 : 0;
1997 template<
class Type,
int fast>
inline void
2004 template<
class Type,
int fast>
inline void
2011 template<
class Type,
int fast>
void
typedef int(APIENTRYP RE_PFNGLXSWAPINTERVALSGIPROC)(int)
bool isSameType(PXL_DataFormat format, unsigned b, unsigned w) const
imath_half_bits_t half
if we're in a C-only context, alias the half bits type to half
GLsizei const GLfloat * value
ImageBuf OIIO_API min(Image_or_Const A, Image_or_Const B, ROI roi={}, int nthreads=0)
**But if you need a result
Type operator+(int) const
bool operator==(unsigned int) const
Type operator*(int) const
IMATH_NAMESPACE::V2f float
GLint GLint GLsizei GLint GLenum format
PXL_Pixel(unsigned int black=0, unsigned int white=0, Type value=0)
Type operator-(int) const
GLboolean GLboolean GLboolean 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)
ImageBuf OIIO_API max(Image_or_Const A, Image_or_Const B, ROI roi={}, int nthreads=0)
GLubyte GLubyte GLubyte GLubyte w
bool SYSisEqual(const UT_Vector2T< T > &a, const UT_Vector2T< T > &b, S tol=SYS_FTOLERANCE)
Componentwise equality.
void setRange(unsigned int b, unsigned int w)
fpreal32 SYSfloorIL(fpreal32 val)
PXL_API void PXLdetermineProcCaps()