Gnash
0.8.10
|
00001 // RGBA.h: RGBA color handling. 00002 // 00003 // Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012 00004 // 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 00101 friend std::ostream& operator<<(std::ostream& os, const rgba& r); 00102 00103 bool operator==(const rgba& o) const { 00104 return m_r == o.m_r && 00105 m_g == o.m_g && 00106 m_b == o.m_b && 00107 m_a == o.m_a; 00108 } 00109 00110 bool operator!=(const rgba& o) const { 00111 return !(*this == o); 00112 } 00113 00114 boost::uint8_t m_r, m_g, m_b, m_a; 00115 00116 }; 00117 00118 std::ostream& operator<<(std::ostream& os, const rgba& r); 00119 00121 // 00125 rgba colorFromHexString(const std::string& color); 00126 00128 rgba lerp(const rgba& a, const rgba& b, float f); 00129 00130 } // namespace gnash 00131 00132 #endif 00133 00134 00135 // Local Variables: 00136 // mode: C++ 00137 // indent-tabs-mode: t 00138 // End: