1 /* === S Y N F I G ========================================================= */
3 ** \brief Template File
8 ** Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley
10 ** This package is free software; you can redistribute it and/or
11 ** modify it under the terms of the GNU General Public License as
12 ** published by the Free Software Foundation; either version 2 of
13 ** the License, or (at your option) any later version.
15 ** This package is distributed in the hope that it will be useful,
16 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 ** General Public License for more details.
21 /* ========================================================================= */
23 /* === H E A D E R S ======================================================= */
37 /* === U S I N G =========================================================== */
40 //using namespace etl;
41 using namespace synfig;
43 /* === M A C R O S ========================================================= */
45 /* === G L O B A L S ======================================================= */
47 /* === P R O C E D U R E S ================================================= */
49 /* === M E T H O D S ======================================================= */
52 Gamma::set_gamma(float x)
54 gamma_r=gamma_g=gamma_b=x;
59 float f(float(i)/65536.0f);
61 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);
65 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);
70 Gamma::refresh_gamma_r()
73 // const float scalar(min(red_blue_level,1.0f));
74 const float scalar(1.0f);
77 float f(float(i)/65536.0f);
78 f=pow(f,gamma_r)*scalar;
79 table_r_U16_to_U8[i]=(unsigned char)(f*(255.0f-(black_level*255))+0.5f + black_level*255.0f);
83 table_r_U8_to_F32[i]=pow((float(i)/255.0f)*(1.0f-black_level)+black_level,gamma_r)*scalar;
87 Gamma::refresh_gamma_g()
90 // const float scalar(sqrt(min(red_blue_level,2.0f-red_blue_level)));
91 const float scalar(1.0f);
94 float f(float(i)/65536.0f);
95 f=pow(f,gamma_g)*scalar;
96 table_g_U16_to_U8[i]=(unsigned char)(f*(255.0f-(black_level*255))+0.5f + black_level*255.0f);
99 table_g_U8_to_F32[i]=pow((float(i)/255.0f)*(1.0f-black_level)+black_level,gamma_g)*scalar;
103 Gamma::refresh_gamma_b()
106 // const float scalar(min(2.0f-red_blue_level,1.0f));
107 const float scalar(1.0f);
110 float f(float(i)/65536.0f);
111 f=pow(f,gamma_b)*scalar;
112 table_b_U16_to_U8[i]=(unsigned char)(f*(255.0f-(black_level*255))+0.5f + black_level*255.0f);
115 table_b_U8_to_F32[i]=pow((float(i)/255.0f)*(1.0f-black_level)+black_level,gamma_b)*scalar;
119 Gamma::set_gamma_r(float x)
121 // If the gamma hasn't changed, then don't recompute the tables
122 if(x==gamma_r) return;
129 Gamma::set_gamma_g(float x)
131 // If the gamma hasn't changed, then don't recompute the tables
132 if(x==gamma_g) return;
139 Gamma::set_gamma_b(float x)
141 // If the gamma hasn't changed, then don't recompute the tables
142 if(x==gamma_b) return;
149 Gamma::set_black_level(float x)
151 // If the black_level hasn't changed, then don't recompute the tables
152 if(x==black_level) return;
163 Gamma::set_red_blue_level(float x)
165 // If the black_level hasn't changed, then don't recompute the tables
166 if(x==red_blue_level) return;
177 Gamma::set_all(float r, float g, float b, float black, float red_blue)
179 // If nothing has changed, then don't recompute the tables
180 if(gamma_r==r && gamma_g==g && gamma_b==b && black_level==black && red_blue_level==red_blue)
187 red_blue_level=red_blue;