• Main Page
  • Related Pages
  • Namespaces
  • Classes
  • Files
  • Examples
  • File List
  • File Members

FuzzyPixel.h

Go to the documentation of this file.
00001 /* 
00002  *   Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010 Free Software Foundation, Inc.
00003  * 
00004  * This program is free software; you can redistribute it and/or modify
00005  * it under the terms of the GNU General Public License as published by
00006  * the Free Software Foundation; either version 3 of the License, or
00007  * (at your option) any later version.
00008  * 
00009  * This program is distributed in the hope that it will be useful,
00010  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  * GNU General Public License for more details.
00013  * 
00014  * You should have received a copy of the GNU General Public License
00015  * along with this program; if not, write to the Free Software
00016  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
00017  *
00018  */ 
00019 
00020 #ifndef GNASH_FUZZYPIXEL_H
00021 #define GNASH_FUZZYPIXEL_H
00022 
00023 #include "Range2d.h"
00024 #include "GnashKey.h" // for namespace key
00025 #include "RGBA.h" // for rgba class (composition)
00026 
00027 #include <iostream> 
00028 
00029 namespace gnash {
00030 
00032 //
00045 class FuzzyPixel
00046 {
00047 
00048 public:
00049 
00050         friend std::ostream& operator<< (std::ostream& o, const FuzzyPixel& p);
00051 
00053         //
00057         FuzzyPixel()
00058                 :
00059                 _col(0,0,0,0),
00060                 _tol(-1)
00061         {
00062         }
00063 
00065         //
00072         FuzzyPixel(const rgba& color, short unsigned tolerance=0)
00073                 :
00074                 _col(color),
00075                 // From short unsigned to signed we hopefully never swap sign.
00076                 // Use the default constructor to build intolerant fuzzy pixels.
00077                 _tol(int(tolerance))
00078         {
00079         }
00080 
00082         //
00097         FuzzyPixel(boost::uint8_t r, boost::uint8_t g, boost::uint8_t b, boost::uint8_t a)
00098                 :
00099                 _col(r, g, b, a),
00100                 _tol(0)
00101         {
00102         }
00103 
00105         //
00109         void setTolerance(unsigned short tol)
00110         {
00111                 _tol = int(tol);
00112         }
00113 
00115         void setIntolerant()
00116         {
00117                 _tol = -1;
00118         }
00119 
00121         //
00127         bool operator==(const FuzzyPixel& other) const;
00128 
00130         static bool fuzzyEqual(int a, int b, int tol)
00131         {
00132                 return abs(a-b) <= tol;
00133         }
00134 
00135 private:
00136 
00137         // actual color 
00138         rgba _col;
00139 
00140         // tolerance value
00141         int _tol;
00142 
00143 };
00144 
00145 } // namespace gnash
00146 
00147 #endif // _GNASH_FUZZYPIXEL_H

Generated on Thu Sep 2 2010 for Gnash by  doxygen 1.7.1