1 /* === S I N F G =========================================================== */
3 ** \brief Template Header
5 ** $Id: gamma.h,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 /* === S T A R T =========================================================== */
24 #ifndef __SINFG_GAMMA_H
25 #define __SINFG_GAMMA_H
27 /* === H E A D E R S ======================================================= */
31 /* === M A C R O S ========================================================= */
33 /* === T Y P E D E F S ===================================================== */
35 /* === C L A S S E S & S T R U C T S ======================================= */
40 ** \brief This class performs color correction on Color classes.
51 unsigned char table_r_U16_to_U8[65536];
52 unsigned char table_g_U16_to_U8[65536];
53 unsigned char table_b_U16_to_U8[65536];
55 float table_r_U8_to_F32[256];
56 float table_g_U8_to_F32[256];
57 float table_b_U8_to_F32[256];
60 Gamma(float x=1):black_level(0) { set_gamma(x); }
62 void set_gamma(float x);
63 void set_gamma_r(float x);
64 void set_gamma_g(float x);
65 void set_gamma_b(float x);
66 void set_black_level(float x);
68 void set_red_blue_level(float x);
69 void set_all(float r, float g, float b, float black, float red_blue=1.0f);
71 float get_gamma()const { return (gamma_r+gamma_g+gamma_b)*0.33333333; }
72 float get_gamma_r()const { return gamma_r; }
73 float get_gamma_g()const { return gamma_g; }
74 float get_gamma_b()const { return gamma_b; }
75 float get_black_level()const { return black_level; }
76 float get_red_blue_level()const { return red_blue_level; }
78 void refresh_gamma_r();
79 void refresh_gamma_g();
80 void refresh_gamma_b();
82 const unsigned char &r_U16_to_U8(int i)const { return table_r_U16_to_U8[i]; }
83 const unsigned char &g_U16_to_U8(int i)const { return table_g_U16_to_U8[i]; }
84 const unsigned char &b_U16_to_U8(int i)const { return table_b_U16_to_U8[i]; }
86 const unsigned char &r_F32_to_U8(float x)const { return table_r_U16_to_U8[(int)(x*65535.0f)]; }
87 const unsigned char &g_F32_to_U8(float x)const { return table_g_U16_to_U8[(int)(x*65535.0f)]; }
88 const unsigned char &b_F32_to_U8(float x)const { return table_b_U16_to_U8[(int)(x*65535.0f)]; }
90 unsigned short r_F32_to_U16(float x)const { return (unsigned short)table_r_U16_to_U8[(int)(x*65535.0f)]<<8; }
91 unsigned short g_F32_to_U16(float x)const { return (unsigned short)table_g_U16_to_U8[(int)(x*65535.0f)]<<8; }
92 unsigned short b_F32_to_U16(float x)const { return (unsigned short)table_b_U16_to_U8[(int)(x*65535.0f)]<<8; }
94 const float& r_U8_to_F32(int i)const { return table_r_U8_to_F32[i]; }
95 const float& g_U8_to_F32(int i)const { return table_g_U8_to_F32[i]; }
96 const float& b_U8_to_F32(int i)const { return table_b_U8_to_F32[i]; }
98 float r_F32_to_F32(float x)const { return static_cast<float>(pow(x,gamma_r)*(1.0f-black_level)+black_level); }
99 float g_F32_to_F32(float x)const { return static_cast<float>(pow(x,gamma_g)*(1.0f-black_level)+black_level); }
100 float b_F32_to_F32(float x)const { return static_cast<float>(pow(x,gamma_b)*(1.0f-black_level)+black_level); }
101 }; // END of class Gamma
103 }; // END of namespace sinfg
105 /* === E N D =============================================================== */