Anti-Grain Geometry - AGG (libagg)
2.5
|
00001 //---------------------------------------------------------------------------- 00002 // Anti-Grain Geometry (AGG) - Version 2.5 00003 // A high quality rendering engine for C++ 00004 // Copyright (C) 2002-2006 Maxim Shemanarev 00005 // Contact: mcseem@antigrain.com 00006 // mcseemagg@yahoo.com 00007 // http://antigrain.com 00008 // 00009 // AGG is free software; you can redistribute it and/or 00010 // modify it under the terms of the GNU General Public License 00011 // as published by the Free Software Foundation; either version 2 00012 // of the License, or (at your option) any later version. 00013 // 00014 // AGG is distributed in the hope that it will be useful, 00015 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00016 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00017 // GNU General Public License for more details. 00018 // 00019 // You should have received a copy of the GNU General Public License 00020 // along with AGG; if not, write to the Free Software 00021 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 00022 // MA 02110-1301, USA. 00023 //---------------------------------------------------------------------------- 00024 00025 #ifndef AGG_GAMMA_FUNCTIONS_INCLUDED 00026 #define AGG_GAMMA_FUNCTIONS_INCLUDED 00027 00028 #include <math.h> 00029 #include "agg_basics.h" 00030 00031 namespace agg 00032 { 00033 //===============================================================gamma_none 00034 struct gamma_none 00035 { 00036 double operator()(double x) const { return x; } 00037 }; 00038 00039 00040 //==============================================================gamma_power 00041 class gamma_power 00042 { 00043 public: 00044 gamma_power() : m_gamma(1.0) {} 00045 gamma_power(double g) : m_gamma(g) {} 00046 00047 void gamma(double g) { m_gamma = g; } 00048 double gamma() const { return m_gamma; } 00049 00050 double operator() (double x) const 00051 { 00052 return pow(x, m_gamma); 00053 } 00054 00055 private: 00056 double m_gamma; 00057 }; 00058 00059 00060 //==========================================================gamma_threshold 00061 class gamma_threshold 00062 { 00063 public: 00064 gamma_threshold() : m_threshold(0.5) {} 00065 gamma_threshold(double t) : m_threshold(t) {} 00066 00067 void threshold(double t) { m_threshold = t; } 00068 double threshold() const { return m_threshold; } 00069 00070 double operator() (double x) const 00071 { 00072 return (x < m_threshold) ? 0.0 : 1.0; 00073 } 00074 00075 private: 00076 double m_threshold; 00077 }; 00078 00079 00080 //============================================================gamma_linear 00081 class gamma_linear 00082 { 00083 public: 00084 gamma_linear() : m_start(0.0), m_end(1.0) {} 00085 gamma_linear(double s, double e) : m_start(s), m_end(e) {} 00086 00087 void set(double s, double e) { m_start = s; m_end = e; } 00088 void start(double s) { m_start = s; } 00089 void end(double e) { m_end = e; } 00090 double start() const { return m_start; } 00091 double end() const { return m_end; } 00092 00093 double operator() (double x) const 00094 { 00095 if(x < m_start) return 0.0; 00096 if(x > m_end) return 1.0; 00097 return (x - m_start) / (m_end - m_start); 00098 } 00099 00100 private: 00101 double m_start; 00102 double m_end; 00103 }; 00104 00105 00106 //==========================================================gamma_multiply 00107 class gamma_multiply 00108 { 00109 public: 00110 gamma_multiply() : m_mul(1.0) {} 00111 gamma_multiply(double v) : m_mul(v) {} 00112 00113 void value(double v) { m_mul = v; } 00114 double value() const { return m_mul; } 00115 00116 double operator() (double x) const 00117 { 00118 double y = x * m_mul; 00119 if(y > 1.0) y = 1.0; 00120 return y; 00121 } 00122 00123 private: 00124 double m_mul; 00125 }; 00126 00127 } 00128 00129 #endif 00130 00131 00132