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

RGBA.h

Go to the documentation of this file.
00001 // RGBA.h: RGBA color handling.
00002 // 
00003 //   Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010 Free Software
00004 //   Foundation, Inc
00005 // 
00006 // This program is free software; you can redistribute it and/or modify
00007 // it under the terms of the GNU General Public License as published by
00008 // the Free Software Foundation; either version 3 of the License, or
00009 // (at your option) any later version.
00010 // 
00011 // This program is distributed in the hope that it will be useful,
00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014 // GNU General Public License for more details.
00015 //
00016 // You should have received a copy of the GNU General Public License
00017 // along with this program; if not, write to the Free Software
00018 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
00019 // 
00020 
00021 #ifndef GNASH_RGBA_H
00022 #define GNASH_RGBA_H
00023 
00024 #include "SWF.h"
00025 
00026 #include <string>
00027 #include <boost/cstdint.hpp> 
00028 
00029 namespace gnash {
00030     class SWFStream;
00031 }
00032 
00033 namespace gnash {
00034 
00036 //
00039 class rgba
00040 {
00041 public:
00042 
00044     //
00046     rgba()
00047         :
00048         m_r(255),
00049         m_g(255),
00050         m_b(255),
00051         m_a(255)
00052     {}
00053 
00055     //
00060     rgba(boost::uint8_t r, boost::uint8_t g, boost::uint8_t b, 
00061             boost::uint8_t a)
00062         :
00063         m_r(r),
00064         m_g(g),
00065         m_b(b),
00066         m_a(a)
00067     {
00068     }
00069 
00071     //
00077     void parseRGB(boost::uint32_t rgbCol) {
00078         m_r = static_cast<boost::uint8_t>(rgbCol >> 16);
00079         m_g = static_cast<boost::uint8_t>(rgbCol >> 8);
00080         m_b = static_cast<boost::uint8_t>(rgbCol);
00081     }
00082 
00084     //
00090     boost::uint32_t toRGB() const {
00091         return (m_r << 16) + (m_g << 8) + m_b;
00092     }
00093 
00095     //
00100     boost::uint32_t toRGBA() const {
00101         return toRGB() + (m_a << 24);
00102     }
00103 
00105     void set(boost::uint8_t r, boost::uint8_t g, boost::uint8_t b,
00106             boost::uint8_t a) {
00107         m_r = r;
00108         m_g = g;
00109         m_b = b;
00110         m_a = a;
00111     }
00112 
00114     void set_lerp(const rgba& a, const rgba& b, float f);
00115 
00117     std::string toShortString() const;
00118 
00119     friend std::ostream& operator<< (std::ostream& os, const rgba& r);
00120 
00121     bool operator==(const rgba& o) const {
00122         return m_r == o.m_r && 
00123                m_g == o.m_g && 
00124                m_b == o.m_b && 
00125                m_a == o.m_a;
00126     }
00127 
00128     bool operator!=(const rgba& o) const {
00129         return !(*this == o);
00130     }
00131 
00132     boost::uint8_t m_r, m_g, m_b, m_a;
00133 
00134 };
00135 
00136 std::ostream& operator<< (std::ostream& os, const rgba& r);
00137 
00139 //
00142 rgba readRGBA(SWFStream& in);
00143 
00145 rgba readRGB(SWFStream& in);
00146     
00148 //
00152 rgba colorFromHexString(const std::string& color);
00153 
00154 
00155 } // namespace gnash
00156 
00157 #endif 
00158 
00159 
00160 // Local Variables:
00161 // mode: C++
00162 // indent-tabs-mode: t
00163 // End:

Generated on Fri Mar 16 2012 15:46:12 for Gnash by  doxygen 1.7.1