- Main Page
- Related Pages
- Namespaces
- Classes
- Files

# gamma.h

Go to the documentation of this file.

    00001 /* === S Y N F I G ========================================================= */
    00021 /* ========================================================================= */
    00022
    00023 /* === S T A R T =========================================================== */
    00024
    00025 #ifndef __SYNFIG_GAMMA_H
    00026 #define __SYNFIG_GAMMA_H
    00027
    00028 /* === H E A D E R S ======================================================= */
    00029
    00030 #include <cmath>
    00031
    00032 /* === M A C R O S ========================================================= */
    00033
    00034 /* === T Y P E D E F S ===================================================== */
    00035
    00036 /* === C L A S S E S & S T R U C T S ======================================= */
    00037
    00038 namespace synfig {
    00039
    00044 class Gamma
    00045 {
    00046     float gamma_r;
    00047     float gamma_g;
    00048     float gamma_b;
    00049     float black_level;
    00050     float red_blue_level;
    00051
    00052     unsigned char table_r_U16_to_U8[65536];
    00053     unsigned char table_g_U16_to_U8[65536];
    00054     unsigned char table_b_U16_to_U8[65536];
    00055
    00056     float table_r_U8_to_F32[256];
    00057     float table_g_U8_to_F32[256];
    00058     float table_b_U8_to_F32[256];
    00059
    00060 public:
    00061     Gamma(float x=1):black_level(0) { set_gamma(x); }
    00062
    00063     void set_gamma(float x);
    00064     void set_gamma_r(float x);
    00065     void set_gamma_g(float x);
    00066     void set_gamma_b(float x);
    00067     void set_black_level(float x);
    00068
    00069     void set_red_blue_level(float x);
    00070     void set_all(float r, float g, float b, float black, float red_blue=1.0f);
    00071
    00072     float get_gamma()const { return (gamma_r+gamma_g+gamma_b)*0.33333333; }
    00073     float get_gamma_r()const { return gamma_r; }
    00074     float get_gamma_g()const { return gamma_g; }
    00075     float get_gamma_b()const { return gamma_b; }
    00076     float get_black_level()const { return black_level; }
    00077     float get_red_blue_level()const { return red_blue_level; }
    00078
    00079     void refresh_gamma_r();
    00080     void refresh_gamma_g();
    00081     void refresh_gamma_b();
    00082
    00083     const unsigned char &r_U16_to_U8(int i)const { return table_r_U16_to_U8[i]; }
    00084     const unsigned char &g_U16_to_U8(int i)const { return table_g_U16_to_U8[i]; }
    00085     const unsigned char &b_U16_to_U8(int i)const { return table_b_U16_to_U8[i]; }
    00086
    00087     const unsigned char &r_F32_to_U8(float x)const { return table_r_U16_to_U8[(int)(x*65535.0f)]; }
    00088     const unsigned char &g_F32_to_U8(float x)const { return table_g_U16_to_U8[(int)(x*65535.0f)]; }
    00089     const unsigned char &b_F32_to_U8(float x)const { return table_b_U16_to_U8[(int)(x*65535.0f)]; }
    00090
    00091     unsigned short r_F32_to_U16(float x)const { return (unsigned short)table_r_U16_to_U8[(int)(x*65535.0f)]<<8; }
    00092     unsigned short g_F32_to_U16(float x)const { return (unsigned short)table_g_U16_to_U8[(int)(x*65535.0f)]<<8; }
    00093     unsigned short b_F32_to_U16(float x)const { return (unsigned short)table_b_U16_to_U8[(int)(x*65535.0f)]<<8; }
    00094
    00095     const float& r_U8_to_F32(int i)const { return table_r_U8_to_F32[i]; }
    00096     const float& g_U8_to_F32(int i)const { return table_g_U8_to_F32[i]; }
    00097     const float& b_U8_to_F32(int i)const { return table_b_U8_to_F32[i]; }
    00098
    00099     float r_F32_to_F32(float x)const { return static_cast<float>(pow(x,gamma_r)*(1.0f-black_level)+black_level); }
    00100     float g_F32_to_F32(float x)const { return static_cast<float>(pow(x,gamma_g)*(1.0f-black_level)+black_level); }
    00101     float b_F32_to_F32(float x)const { return static_cast<float>(pow(x,gamma_b)*(1.0f-black_level)+black_level); }
    00102 }; // END of class Gamma
    00103
    00104 }; // END of namespace synfig
    00105
    00106 /* === E N D =============================================================== */
    00107
    00108 #endif