1 /* === S I N F G =========================================================== */
3 ** \brief Template File
5 ** $Id: gamma.cpp,v 1.1.1.1 2005/01/04 01:23:14 darco Exp $
8 ** Copyright (c) 2002 Robert B. Quattlebaum Jr.
10 ** This software and associated documentation
11 ** are CONFIDENTIAL and PROPRIETARY property of
12 ** the above-mentioned copyright holder.
14 ** You may not copy, print, publish, or in any
15 ** other way distribute this software without
16 ** a prior written agreement with
17 ** the copyright holder.
20 /* ========================================================================= */
22 /* === H E A D E R S ======================================================= */
36 /* === U S I N G =========================================================== */
39 //using namespace etl;
40 using namespace sinfg;
42 /* === M A C R O S ========================================================= */
44 /* === G L O B A L S ======================================================= */
46 /* === P R O C E D U R E S ================================================= */
48 /* === M E T H O D S ======================================================= */
51 Gamma::set_gamma(float x)
53 gamma_r=gamma_g=gamma_b=x;
58 float f(float(i)/65536.0f);
60 table_r_U16_to_U8[i]=table_g_U16_to_U8[i]=table_b_U16_to_U8[i]=(unsigned char)(f*(255.0f-(black_level*255))+0.5f + black_level*255.0f);
64 table_r_U8_to_F32[i]=table_g_U8_to_F32[i]=table_b_U8_to_F32[i]=pow((float(i)/255.0f)*(1.0f-black_level)+black_level,gamma_r);
69 Gamma::refresh_gamma_r()
72 // const float scalar(min(red_blue_level,1.0f));
73 const float scalar(1.0f);
76 float f(float(i)/65536.0f);
77 f=pow(f,gamma_r)*scalar;
78 table_r_U16_to_U8[i]=(unsigned char)(f*(255.0f-(black_level*255))+0.5f + black_level*255.0f);
82 table_r_U8_to_F32[i]=pow((float(i)/255.0f)*(1.0f-black_level)+black_level,gamma_r)*scalar;
86 Gamma::refresh_gamma_g()
89 // const float scalar(sqrt(min(red_blue_level,2.0f-red_blue_level)));
90 const float scalar(1.0f);
93 float f(float(i)/65536.0f);
94 f=pow(f,gamma_g)*scalar;
95 table_g_U16_to_U8[i]=(unsigned char)(f*(255.0f-(black_level*255))+0.5f + black_level*255.0f);
98 table_g_U8_to_F32[i]=pow((float(i)/255.0f)*(1.0f-black_level)+black_level,gamma_g)*scalar;
102 Gamma::refresh_gamma_b()
105 // const float scalar(min(2.0f-red_blue_level,1.0f));
106 const float scalar(1.0f);
109 float f(float(i)/65536.0f);
110 f=pow(f,gamma_b)*scalar;
111 table_b_U16_to_U8[i]=(unsigned char)(f*(255.0f-(black_level*255))+0.5f + black_level*255.0f);
114 table_b_U8_to_F32[i]=pow((float(i)/255.0f)*(1.0f-black_level)+black_level,gamma_b)*scalar;
118 Gamma::set_gamma_r(float x)
120 // If the gamma hasn't changed, then don't recompute the tables
121 if(x==gamma_r) return;
128 Gamma::set_gamma_g(float x)
130 // If the gamma hasn't changed, then don't recompute the tables
131 if(x==gamma_g) return;
138 Gamma::set_gamma_b(float x)
140 // If the gamma hasn't changed, then don't recompute the tables
141 if(x==gamma_b) return;
148 Gamma::set_black_level(float x)
150 // If the black_level hasn't changed, then don't recompute the tables
151 if(x==black_level) return;
162 Gamma::set_red_blue_level(float x)
164 // If the black_level hasn't changed, then don't recompute the tables
165 if(x==red_blue_level) return;
176 Gamma::set_all(float r, float g, float b, float black, float red_blue)
178 // If nothing has changed, then don't recompute the tables
179 if(gamma_r==r && gamma_g==g && gamma_b==b && black_level==black && red_blue_level==red_blue)
186 red_blue_level=red_blue;