11 #ifndef __IMG_GammaTable__
12 #define __IMG_GammaTable__
26 template <
typename T>
static constexpr
inline T
29 constexpr
T zero = 0.0031308;
31 constexpr
T a = 0.055;
32 constexpr
T gamma = 2.4;
33 return x <= zero ? x*scale : (1+
a)*SYSpow(x, 1/gamma) -
a;
35 template <
typename T>
static constexpr
inline T
38 constexpr
T zero = 0.018;
40 constexpr
T a = 0.099;
41 constexpr
T gamma = 0.45;
42 return x <= zero ? x*scale : (1+
a)*SYSpow(x, gamma) -
a;
44 template <
typename T>
static constexpr
inline T
47 return SYSsafepow(x, 1/gamma);
49 template <
typename T>
static constexpr
inline T
52 constexpr
T gamma = 2.2;
53 return linearToGamma(x, gamma);
56 template <
typename T>
static constexpr
inline T
59 constexpr
T zero = 0.04045;
61 constexpr
T a = 0.055;
62 constexpr
T gamma = 2.4;
63 return x <= zero ? x*(1/
scale) : SYSpow((x+a)*(1/(1+
a)), gamma);
65 template <
typename T>
static constexpr
inline T
68 constexpr
T zero = 0.081;
70 constexpr
T a = 0.099;
71 constexpr
T gamma = 0.45;
72 return x <= zero ? x*(1/
scale) : SYSpow((x+a)*(1/(1+
a)), (1/gamma));
74 template <
typename T>
static constexpr
inline T
77 return SYSsafepow(x, gamma);
79 template <
typename T>
static constexpr
inline T
82 constexpr
T gamma = 2.2;
83 return gammaToLinear(x, gamma);
92 result[3] = myLinear01[src[3]];
95 result[2] = lut[src[2]];
98 result[1] = lut[src[1]];
101 result[0] = lut[src[0]];
111 toFloat(result, src, nchan, myRGBtoLinear1);
116 toFloat(result, src, nchan, myRec709toLinear1);
121 toFloat(result, src, nchan, myGamma22toLinear1);
127 float myRGBtoLinear1[256];
128 float myRec709toLinear1[256];
129 float myGamma22toLinear1[256];
130 float myLinear01[256];
133 namespace IMG_GammaTable
140 template <
typename T>
155 void linearToFloat(
float *
result,
const T *
src,
int nchan)
157 for (
int i = 0; i < nchan; ++i)
158 result[i] = toFloat(src[i]);
162 void sRGBToFloat(
float *
dst,
const T *src,
int nchan)
167 dst[3] = toFloat(src[3]);
181 void rec709ToFloat(
float *dst,
const T *src,
int nchan)
186 dst[3] = toFloat(src[3]);
200 void gamma22ToFloat(
float *dst,
const T *src,
int nchan)
205 dst[3] = toFloat(src[3]);
243 linearToFloat(result, src, n);
246 sRGBToFloat(result, src, n);
249 gamma22ToFloat(result, src, n);
252 rec709ToFloat(result, src, n);
267 linearToFloat(result, src, n);
286 linearToFloat(result, src, n);
289 sRGBToFloat(result, src, n);
292 gamma22ToFloat(result, src, n);
295 rec709ToFloat(result, src, n);
311 linearToFloat(result, src, n);
static const IMG_GammaTableDetail & get()
float toFloat< fpreal16 >(fpreal16 d)
SYS_FORCE_INLINE void gamma22ToFloat< uint8 >(float *dst, const uint8 *src, int nchan)
float toFloat< uint8 >(uint8 d)
float linear01(uint8 v) const
static constexpr int AutoStride
GLboolean GLboolean GLboolean GLboolean a
**But if you need a result
static constexpr T linearToGamma(T x, T gamma)
SYS_FORCE_INLINE void toFloat(float *result, const uint8 *src, int nchan, const float *lut) const
GA_API const UT_StringHolder scale
void convert< uint8 >(float *result, const uint8 *src, int n, IMG_ColorSpace cs)
IMATH_NAMESPACE::V2f float
SYS_FORCE_INLINE void rec709ToFloat(float *result, const uint8 *src, int nchan) const
float toFloat< fpreal64 >(fpreal64 d)
static constexpr T linearToSRGB(T x)
SYS_FORCE_INLINE void rec709ToFloat< uint8 >(float *dst, const uint8 *src, int nchan)
static constexpr T gammaToLinear(T x, T gamma)
SYS_FORCE_INLINE void gamma22ToFloat(float *result, const uint8 *src, int nchan) const
const stride_t AutoStride
SYS_FORCE_INLINE void sRGBToFloat(float *result, const uint8 *src, int nchan) const
static constexpr T linearToRec709(T x)
float toFloat< fpreal32 >(fpreal32 d)
ImageBuf OIIO_API max(Image_or_Const A, Image_or_Const B, ROI roi={}, int nthreads=0)
SYS_FORCE_INLINE void sRGBToFloat< uint8 >(float *dst, const uint8 *src, int nchan)
static constexpr T rec709ToLinear(T x)
IMG_ColorSpace
Modes for how to translate colors in images for texture lookups.
void builtinConvert< uint8 >(float *result, const uint8 *src, int n, IMG_ColorSpace cs)
static constexpr T gamma22ToLinear(T x)
ImageBuf OIIO_API zero(ROI roi, int nthreads=0)
static constexpr T srgbToLinear(T x)
static constexpr T linearToGamma22(T x)