1 //---------------------------------------------------------------------------- 2 // Anti-Grain Geometry - Version 2.2 3 // Copyright (C) 2002-2004 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 <math.h> 20 #include "agg_basics.h" 21 22 namespace agg 23 { 24 //===============================================================gamma_none 25 struct gamma_none 26 { 27 double operator()(double x) const { return x; } 28 }; 29 30 31 //==============================================================gamma_power 32 class gamma_power 33 { 34 public: 35 gamma_power() : m_gamma(1.0) {} 36 gamma_power(double g) : m_gamma(g) {} 37 38 void gamma(double g) { m_gamma = g; } 39 double gamma() const { return m_gamma; } 40 41 double operator() (double x) const 42 { 43 return pow(x, m_gamma); 44 } 45 46 private: 47 double m_gamma; 48 }; 49 50 51 //==========================================================gamma_threshold 52 class gamma_threshold 53 { 54 public: 55 gamma_threshold() : m_threshold(0.5) {} 56 gamma_threshold(double t) : m_threshold(t) {} 57 58 void threshold(double t) { m_threshold = t; } 59 double threshold() const { return m_threshold; } 60 61 double operator() (double x) const 62 { 63 return (x < m_threshold) ? 0.0 : 1.0; 64 } 65 66 private: 67 double m_threshold; 68 }; 69 70 71 //============================================================gamma_linear 72 class gamma_linear 73 { 74 public: 75 gamma_linear() : m_start(0.0), m_end(1.0) {} 76 gamma_linear(double s, double e) : m_start(s), m_end(e) {} 77 78 void set(double s, double e) { m_start = s; m_end = e; } 79 void start(double s) { m_start = s; } 80 void end(double e) { m_end = e; } 81 double start() const { return m_start; } 82 double end() const { return m_end; } 83 84 double operator() (double x) const 85 { 86 if(x < m_start) return 0.0; 87 if(x > m_end) return 1.0; 88 return (x - m_start) / (m_end - m_start); 89 } 90 91 private: 92 double m_start; 93 double m_end; 94 }; 95 96 97 //==========================================================gamma_multiply 98 class gamma_multiply 99 { 100 public: 101 gamma_multiply() : m_mul(1.0) {} 102 gamma_multiply(double v) : m_mul(v) {} 103 104 void value(double v) { m_mul = v; } 105 double value() const { return m_mul; } 106 107 double operator() (double x) const 108 { 109 double y = x * m_mul; 110 if(y > 1.0) y = 1.0; 111 return y; 112 } 113 114 private: 115 double m_mul; 116 }; 117 118 } 119 120 #endif 121 122 123 124