2 * Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010 Free Software Foundation, Inc.
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.
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
20 #ifndef GNASH_FUZZYPIXEL_H
21 #define GNASH_FUZZYPIXEL_H
24 #include "GnashKey.h" // for namespace key
25 #include "RGBA.h" // for rgba class (composition)
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.
36 /// Currently (but we might change this in the future), the tolerance is
37 /// used to compare red, green, blue and alpha values.
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.
43 /// See operator== for more info.
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.
64 /// Construct a FuzzyPixel with given color and tolerance
70 /// The tolerance to use in comparisons.
72 FuzzyPixel(const rgba
& color
, short unsigned tolerance
=0)
75 // From short unsigned to signed we hopefully never swap sign.
76 // Use the default constructor to build intolerant fuzzy pixels.
81 /// Construct a FuzzyPixel with given values and 0 tolerance.
83 /// Use setTolerance to modify the tolerance value.
97 FuzzyPixel(boost::uint8_t r
, boost::uint8_t g
, boost::uint8_t b
, boost::uint8_t a
)
104 /// Set the tolerance to use in comparisons
107 /// The tolerance to use in comparisons.
109 void setTolerance(unsigned short tol
)
114 /// Make this fuzzy pixel intolerant
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
;
147 #endif // _GNASH_FUZZYPIXEL_H