Gnash 0.8.9
|
00001 // RGBA.h: RGBA color handling. 00002 // 00003 // Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010, 00004 // 2011 Free Software 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 <string> 00025 #include <boost/cstdint.hpp> 00026 00027 #include "dsodefs.h" 00028 #include "SWF.h" 00029 00030 namespace gnash { 00031 00033 // 00036 class DSOEXPORT rgba 00037 { 00038 public: 00039 00041 // 00043 rgba() 00044 : 00045 m_r(255), 00046 m_g(255), 00047 m_b(255), 00048 m_a(255) 00049 {} 00050 00052 // 00057 rgba(boost::uint8_t r, boost::uint8_t g, boost::uint8_t b, 00058 boost::uint8_t a) 00059 : 00060 m_r(r), 00061 m_g(g), 00062 m_b(b), 00063 m_a(a) 00064 { 00065 } 00066 00068 // 00074 void parseRGB(boost::uint32_t rgbCol) { 00075 m_r = static_cast<boost::uint8_t>(rgbCol >> 16); 00076 m_g = static_cast<boost::uint8_t>(rgbCol >> 8); 00077 m_b = static_cast<boost::uint8_t>(rgbCol); 00078 } 00079 00081 // 00087 boost::uint32_t toRGB() const { 00088 return (m_r << 16) + (m_g << 8) + m_b; 00089 } 00090 00092 // 00097 boost::uint32_t toRGBA() const { 00098 return toRGB() + (m_a << 24); 00099 } 00100 00102 void set(boost::uint8_t r, boost::uint8_t g, boost::uint8_t b, 00103 boost::uint8_t a) { 00104 m_r = r; 00105 m_g = g; 00106 m_b = b; 00107 m_a = a; 00108 } 00109 00111 void set_lerp(const rgba& a, const rgba& b, float f); 00112 00114 std::string toShortString() const; 00115 00116 friend std::ostream& operator<< (std::ostream& os, const rgba& r); 00117 00118 bool operator==(const rgba& o) const { 00119 return m_r == o.m_r && 00120 m_g == o.m_g && 00121 m_b == o.m_b && 00122 m_a == o.m_a; 00123 } 00124 00125 bool operator!=(const rgba& o) const { 00126 return !(*this == o); 00127 } 00128 00129 boost::uint8_t m_r, m_g, m_b, m_a; 00130 00131 }; 00132 00133 std::ostream& operator<< (std::ostream& os, const rgba& r); 00134 00136 // 00140 rgba colorFromHexString(const std::string& color); 00141 00142 00143 } // namespace gnash 00144 00145 #endif 00146 00147 00148 // Local Variables: 00149 // mode: C++ 00150 // indent-tabs-mode: t 00151 // End: