25 #ifndef __SYNFIG_GAMMA_H
26 #define __SYNFIG_GAMMA_H
52 unsigned char table_r_U16_to_U8[65536];
53 unsigned char table_g_U16_to_U8[65536];
54 unsigned char table_b_U16_to_U8[65536];
56 float table_r_U8_to_F32[256];
57 float table_g_U8_to_F32[256];
58 float table_b_U8_to_F32[256];
70 void set_all(
float r,
float g,
float b,
float black,
float red_blue=1.0f);
72 float get_gamma()
const {
return (gamma_r+gamma_g+gamma_b)*0.33333333; }
83 const unsigned char &
r_U16_to_U8(
int i)
const {
return table_r_U16_to_U8[i]; }
84 const unsigned char &
g_U16_to_U8(
int i)
const {
return table_g_U16_to_U8[i]; }
85 const unsigned char &
b_U16_to_U8(
int i)
const {
return table_b_U16_to_U8[i]; }
87 const unsigned char &
r_F32_to_U8(
float x)
const {
return table_r_U16_to_U8[(int)(x*65535.0
f)]; }
88 const unsigned char &
g_F32_to_U8(
float x)
const {
return table_g_U16_to_U8[(int)(x*65535.0
f)]; }
89 const unsigned char &
b_F32_to_U8(
float x)
const {
return table_b_U16_to_U8[(int)(x*65535.0
f)]; }
91 unsigned short r_F32_to_U16(
float x)
const {
return (
unsigned short)table_r_U16_to_U8[(int)(x*65535.0
f)]<<8; }
92 unsigned short g_F32_to_U16(
float x)
const {
return (
unsigned short)table_g_U16_to_U8[(int)(x*65535.0
f)]<<8; }
93 unsigned short b_F32_to_U16(
float x)
const {
return (
unsigned short)table_b_U16_to_U8[(int)(x*65535.0
f)]<<8; }
95 const float&
r_U8_to_F32(
int i)
const {
return table_r_U8_to_F32[i]; }
96 const float&
g_U8_to_F32(
int i)
const {
return table_g_U8_to_F32[i]; }
97 const float&
b_U8_to_F32(
int i)
const {
return table_b_U8_to_F32[i]; }
99 float r_F32_to_F32(
float x)
const {
return static_cast<float>(pow(x,gamma_r)*(1.0f-black_level)+black_level); }
100 float g_F32_to_F32(
float x)
const {
return static_cast<float>(pow(x,gamma_g)*(1.0f-black_level)+black_level); }
101 float b_F32_to_F32(
float x)
const {
return static_cast<float>(pow(x,gamma_b)*(1.0f-black_level)+black_level); }