2 * Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012
3 * Free Software Foundation, Inc.
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 3 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
21 #ifndef GNASH_FUZZYPIXEL_H
22 #define GNASH_FUZZYPIXEL_H
25 #include "GnashKey.h" // for namespace key
26 #include "RGBA.h" // for rgba class (composition)
27 #include "dsodefs.h" // for DSOTEXPORT
34 /// An utility class used to compare rgba values with a given tolerance
36 /// This is simply a wrapper around an rgba value, with an associated
37 /// tolerance used when comparing with another FuzzyPixel.
39 /// Currently (but we might change this in the future), the tolerance is
40 /// used to compare red, green, blue and alpha values.
42 /// A negative tolerance may be used to mark the FuzzyPixel as
43 /// an "invalid" one, which is a FuzzyPixel that will never be equal
44 /// to any other. Intollerant FuzzyPixel.
46 /// See operator== for more info.
53 friend std::ostream
& operator<< (std::ostream
& o
, const FuzzyPixel
& p
);
55 /// Construct an Intollerant FuzzyPixel.
57 /// Intollerant means that any comparison will fail.
58 /// Actual value of the pixel doesn't make much sense.
67 /// Construct a FuzzyPixel with given color and tolerance
73 /// The tolerance to use in comparisons.
75 FuzzyPixel(const rgba
& color
, short unsigned tolerance
=0)
78 // From short unsigned to signed we hopefully never swap sign.
79 // Use the default constructor to build intolerant fuzzy pixels.
84 /// Construct a FuzzyPixel with given values and 0 tolerance.
86 /// Use setTolerance to modify the tolerance value.
100 FuzzyPixel(std::uint8_t r
, std::uint8_t g
, std::uint8_t b
, std::uint8_t a
)
107 /// Set the tolerance to use in comparisons
110 /// The tolerance to use in comparisons.
112 void setTolerance(unsigned short tol
)
117 /// Make this fuzzy pixel intolerant
123 /// Compare two FuzzyPixel using the tolerance of the most tolerant of the two
125 /// Note that if any of the two operands is intolerant, any equality
126 /// comparison will fail.
128 /// See default constructor and setIntolerant for more info.
130 bool operator==(const FuzzyPixel
& other
) const;
132 /// Return true if a and b are below a given tolerance
133 static bool fuzzyEqual(int a
, int b
, int tol
)
135 return std::abs(a
-b
) <= tol
;
150 #endif // _GNASH_FUZZYPIXEL_H