1 /* === S Y N F I G ========================================================= */
3 ** \brief Template Header
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 /* === S T A R T =========================================================== */
25 #ifndef __SYNFIG_GAMMA_H
26 #define __SYNFIG_GAMMA_H
28 /* === H E A D E R S ======================================================= */
32 /* === M A C R O S ========================================================= */
34 /* === T Y P E D E F S ===================================================== */
36 /* === C L A S S E S & S T R U C T S ======================================= */
41 ** \brief This class performs color correction on Color classes.
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];
61 Gamma(float x=1):black_level(0) { set_gamma(x); }
63 void set_gamma(float x);
64 void set_gamma_r(float x);
65 void set_gamma_g(float x);
66 void set_gamma_b(float x);
67 void set_black_level(float x);
69 void set_red_blue_level(float x);
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; }
73 float get_gamma_r()const { return gamma_r; }
74 float get_gamma_g()const { return gamma_g; }
75 float get_gamma_b()const { return gamma_b; }
76 float get_black_level()const { return black_level; }
77 float get_red_blue_level()const { return red_blue_level; }
79 void refresh_gamma_r();
80 void refresh_gamma_g();
81 void refresh_gamma_b();
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.0f)]; }
88 const unsigned char &g_F32_to_U8(float x)const { return table_g_U16_to_U8[(int)(x*65535.0f)]; }
89 const unsigned char &b_F32_to_U8(float x)const { return table_b_U16_to_U8[(int)(x*65535.0f)]; }
91 unsigned short r_F32_to_U16(float x)const { return (unsigned short)table_r_U16_to_U8[(int)(x*65535.0f)]<<8; }
92 unsigned short g_F32_to_U16(float x)const { return (unsigned short)table_g_U16_to_U8[(int)(x*65535.0f)]<<8; }
93 unsigned short b_F32_to_U16(float x)const { return (unsigned short)table_b_U16_to_U8[(int)(x*65535.0f)]<<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); }
102 }; // END of class Gamma
104 }; // END of namespace synfig
106 /* === E N D =============================================================== */