Make automated FSCommand invocation tests show player-side output.
[gnash.git] / testsuite / FuzzyPixel.h
blobd5dfe3243830d854195452efbfb5c58eaad70a7f
1 /*
2 * Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012
3 * Free Software Foundation, Inc.
4 *
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.
9 *
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
19 */
21 #ifndef GNASH_FUZZYPIXEL_H
22 #define GNASH_FUZZYPIXEL_H
24 #include "Range2d.h"
25 #include "GnashKey.h" // for namespace key
26 #include "RGBA.h" // for rgba class (composition)
27 #include "dsodefs.h" // for DSOTEXPORT
29 #include <cmath>
30 #include <ostream>
32 namespace gnash {
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.
38 ///
39 /// Currently (but we might change this in the future), the tolerance is
40 /// used to compare red, green, blue and alpha values.
41 ///
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.
45 ///
46 /// See operator== for more info.
47 ///
48 class FuzzyPixel
51 public:
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.
59 ///
60 FuzzyPixel()
62 _col(0,0,0,0),
63 _tol(-1)
67 /// Construct a FuzzyPixel with given color and tolerance
69 /// @param color
70 /// The color value
71 ///
72 /// @param tolerance
73 /// The tolerance to use in comparisons.
74 ///
75 FuzzyPixel(const rgba& color, short unsigned tolerance=0)
77 _col(color),
78 // From short unsigned to signed we hopefully never swap sign.
79 // Use the default constructor to build intolerant fuzzy pixels.
80 _tol(int(tolerance))
84 /// Construct a FuzzyPixel with given values and 0 tolerance.
86 /// Use setTolerance to modify the tolerance value.
87 ///
88 /// @param r
89 /// The red value.
90 ///
91 /// @param g
92 /// The green value.
93 ///
94 /// @param b
95 /// The blue value.
96 ///
97 /// @param a
98 /// The alpha value.
99 ///
100 FuzzyPixel(std::uint8_t r, std::uint8_t g, std::uint8_t b, std::uint8_t a)
102 _col(r, g, b, a),
103 _tol(0)
107 /// Set the tolerance to use in comparisons
109 /// @param tol
110 /// The tolerance to use in comparisons.
112 void setTolerance(unsigned short tol)
114 _tol = int(tol);
117 /// Make this fuzzy pixel intolerant
118 void setIntolerant()
120 _tol = -1;
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;
138 private:
140 // actual color
141 rgba _col;
143 // tolerance value
144 int _tol;
148 } // namespace gnash
150 #endif // _GNASH_FUZZYPIXEL_H