vfs: check userland buffers before reading them.
[haiku.git] / headers / libs / agg / agg_gamma_functions.h
blob45facac00c2a3ec513730744359d5135421f2cd9
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 //----------------------------------------------------------------------------
16 #ifndef AGG_GAMMA_FUNCTIONS_INCLUDED
17 #define AGG_GAMMA_FUNCTIONS_INCLUDED
19 #include <math.h>
20 #include "agg_basics.h"
22 namespace agg
24 //===============================================================gamma_none
25 struct gamma_none
27 double operator()(double x) const { return x; }
31 //==============================================================gamma_power
32 class gamma_power
34 public:
35 gamma_power() : m_gamma(1.0) {}
36 gamma_power(double g) : m_gamma(g) {}
38 void gamma(double g) { m_gamma = g; }
39 double gamma() const { return m_gamma; }
41 double operator() (double x) const
43 return pow(x, m_gamma);
46 private:
47 double m_gamma;
51 //==========================================================gamma_threshold
52 class gamma_threshold
54 public:
55 gamma_threshold() : m_threshold(0.5) {}
56 gamma_threshold(double t) : m_threshold(t) {}
58 void threshold(double t) { m_threshold = t; }
59 double threshold() const { return m_threshold; }
61 double operator() (double x) const
63 return (x < m_threshold) ? 0.0 : 1.0;
66 private:
67 double m_threshold;
71 //============================================================gamma_linear
72 class gamma_linear
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) {}
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; }
84 double operator() (double x) const
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);
91 private:
92 double m_start;
93 double m_end;
97 //==========================================================gamma_multiply
98 class gamma_multiply
100 public:
101 gamma_multiply() : m_mul(1.0) {}
102 gamma_multiply(double v) : m_mul(v) {}
104 void value(double v) { m_mul = v; }
105 double value() const { return m_mul; }
107 double operator() (double x) const
109 double y = x * m_mul;
110 if(y > 1.0) y = 1.0;
111 return y;
114 private:
115 double m_mul;
120 #endif