Get rid of HAVE_GTK2 conditional (never used) and has_gtk2 (marked as FIXME: shouldn...
[gnash.git] / testsuite / FuzzyPixel.h
blob6039e623c153a501a43057c3686bcae8b9419281
1 /*
2 * Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010 Free Software Foundation, Inc.
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 3 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18 */
20 #ifndef GNASH_FUZZYPIXEL_H
21 #define GNASH_FUZZYPIXEL_H
23 #include "Range2d.h"
24 #include "GnashKey.h" // for namespace key
25 #include "RGBA.h" // for rgba class (composition)
27 #include <iostream>
29 namespace gnash {
31 /// An utility class used to compare rgba values with a given tolerance
33 /// This is simply a wrapper around an rgba value, with an associated
34 /// tolerance used when comparing with another FuzzyPixel.
35 ///
36 /// Currently (but we might change this in the future), the tolerance is
37 /// used to compare red, green, blue and alpha values.
38 ///
39 /// A negative tolerance may be used to mark the FuzzyPixel as
40 /// an "invalid" one, which is a FuzzyPixel that will never be equal
41 /// to any other. Intollerant FuzzyPixel.
42 ///
43 /// See operator== for more info.
44 ///
45 class FuzzyPixel
48 public:
50 friend std::ostream& operator<< (std::ostream& o, const FuzzyPixel& p);
52 /// Construct an Intollerant FuzzyPixel.
54 /// Intollerant means that any comparison will fail.
55 /// Actual value of the pixel doesn't make much sense.
56 ///
57 FuzzyPixel()
59 _col(0,0,0,0),
60 _tol(-1)
64 /// Construct a FuzzyPixel with given color and tolerance
66 /// @param color
67 /// The color value
68 ///
69 /// @param tolerance
70 /// The tolerance to use in comparisons.
71 ///
72 FuzzyPixel(const rgba& color, short unsigned tolerance=0)
74 _col(color),
75 // From short unsigned to signed we hopefully never swap sign.
76 // Use the default constructor to build intolerant fuzzy pixels.
77 _tol(int(tolerance))
81 /// Construct a FuzzyPixel with given values and 0 tolerance.
83 /// Use setTolerance to modify the tolerance value.
84 ///
85 /// @param r
86 /// The red value.
87 ///
88 /// @param g
89 /// The green value.
90 ///
91 /// @param b
92 /// The blue value.
93 ///
94 /// @param a
95 /// The alpha value.
96 ///
97 FuzzyPixel(boost::uint8_t r, boost::uint8_t g, boost::uint8_t b, boost::uint8_t a)
99 _col(r, g, b, a),
100 _tol(0)
104 /// Set the tolerance to use in comparisons
106 /// @param tol
107 /// The tolerance to use in comparisons.
109 void setTolerance(unsigned short tol)
111 _tol = int(tol);
114 /// Make this fuzzy pixel intolerant
115 void setIntolerant()
117 _tol = -1;
120 /// Compare two FuzzyPixel using the tolerance of the most tolerant of the two
122 /// Note that if any of the two operands is intolerant, any equality
123 /// comparison will fail.
125 /// See default constructor and setIntolerant for more info.
127 bool operator==(const FuzzyPixel& other) const;
129 /// Return true if a and b are below a given tolerance
130 static bool fuzzyEqual(int a, int b, int tol)
132 return abs(a-b) <= tol;
135 private:
137 // actual color
138 rgba _col;
140 // tolerance value
141 int _tol;
145 } // namespace gnash
147 #endif // _GNASH_FUZZYPIXEL_H