Anti-Grain Geometry Tutorial
agg_gamma_functions.h
1 //----------------------------------------------------------------------------
2 // Anti-Grain Geometry - Version 2.4
3 // Copyright (C) 2002-2005 Maxim Shemanarev (http://www.antigrain.com)
4 //
5 // Permission to copy, use, modify, sell and distribute this software
6 // is granted provided this copyright notice appears in all copies.
7 // This software is provided "as is" without express or implied
8 // warranty, and with no claim as to its suitability for any purpose.
9 //
10 //----------------------------------------------------------------------------
11 // Contact: mcseem@antigrain.com
12 // mcseemagg@yahoo.com
13 // http://www.antigrain.com
14 //----------------------------------------------------------------------------
15 
16 #ifndef AGG_GAMMA_FUNCTIONS_INCLUDED
17 #define AGG_GAMMA_FUNCTIONS_INCLUDED
18 
19 #include "agg_basics.h"
20 
21 namespace agg
22 {
23  //===============================================================gamma_none
24  struct gamma_none
25  {
26  double operator()(double x) const { return x; }
27  };
28 
29 
30  //==============================================================gamma_power
32  {
33  public:
34  gamma_power() : m_gamma(1.0) {}
35  gamma_power(double g) : m_gamma(g) {}
36 
37  void gamma(double g) { m_gamma = g; }
38  double gamma() const { return m_gamma; }
39 
40  double operator() (double x) const
41  {
42  return pow(x, m_gamma);
43  }
44 
45  private:
46  double m_gamma;
47  };
48 
49 
50  //==========================================================gamma_threshold
52  {
53  public:
54  gamma_threshold() : m_threshold(0.5) {}
55  gamma_threshold(double t) : m_threshold(t) {}
56 
57  void threshold(double t) { m_threshold = t; }
58  double threshold() const { return m_threshold; }
59 
60  double operator() (double x) const
61  {
62  return (x < m_threshold) ? 0.0 : 1.0;
63  }
64 
65  private:
66  double m_threshold;
67  };
68 
69 
70  //============================================================gamma_linear
72  {
73  public:
74  gamma_linear() : m_start(0.0), m_end(1.0) {}
75  gamma_linear(double s, double e) : m_start(s), m_end(e) {}
76 
77  void set(double s, double e) { m_start = s; m_end = e; }
78  void start(double s) { m_start = s; }
79  void end(double e) { m_end = e; }
80  double start() const { return m_start; }
81  double end() const { return m_end; }
82 
83  double operator() (double x) const
84  {
85  if(x < m_start) return 0.0;
86  if(x > m_end) return 1.0;
87  return (x - m_start) / (m_end - m_start);
88  }
89 
90  private:
91  double m_start;
92  double m_end;
93  };
94 
95 
96  //==========================================================gamma_multiply
98  {
99  public:
100  gamma_multiply() : m_mul(1.0) {}
101  gamma_multiply(double v) : m_mul(v) {}
102 
103  void value(double v) { m_mul = v; }
104  double value() const { return m_mul; }
105 
106  double operator() (double x) const
107  {
108  double y = x * m_mul;
109  if(y > 1.0) y = 1.0;
110  return y;
111  }
112 
113  private:
114  double m_mul;
115  };
116 
117  inline double sRGB_to_linear(double x)
118  {
119  return (x <= 0.04045) ? (x / 12.92) : pow((x + 0.055) / (1.055), 2.4);
120  }
121 
122  inline double linear_to_sRGB(double x)
123  {
124  return (x <= 0.0031308) ? (x * 12.92) : (1.055 * pow(x, 1 / 2.4) - 0.055);
125  }
126 }
127 
128 #endif
129 
130 
131 
Definition: agg_arc.cpp:24