don't use CROSS_FLAGS for executables, as -all-staic prevents Android from looking...
[gnash.git] / libcore / RGBA.h
blobcfb2c6005f58577a441b0b0aa1825e2878aa779a
1 // RGBA.h: RGBA color handling.
2 //
3 // Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012
4 // Free Software Foundation, Inc
5 //
6 // This program is free software; you can redistribute it and/or modify
7 // it under the terms of the GNU General Public License as published by
8 // the Free Software Foundation; either version 3 of the License, or
9 // (at your option) any later version.
10 //
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License
17 // along with this program; if not, write to the Free Software
18 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 //
21 #ifndef GNASH_RGBA_H
22 #define GNASH_RGBA_H
24 #include <string>
25 #include <boost/cstdint.hpp>
27 #include "dsodefs.h"
28 #include "SWF.h"
30 namespace gnash {
32 /// A basic RGBA type
34 /// This both represents a SWF RGBA record and is a basic Gnash type for
35 /// color values.
36 class DSOEXPORT rgba
38 public:
40 /// Construct default RGBA value.
42 /// Default value is 0xffffffff (solid white).
43 rgba()
45 m_r(255),
46 m_g(255),
47 m_b(255),
48 m_a(255)
51 /// Construct an RGBA with the provided values
53 /// @param r Red
54 /// @param g Green
55 /// @param b Blue
56 /// @param a Alpha (transparency)
57 rgba(boost::uint8_t r, boost::uint8_t g, boost::uint8_t b,
58 boost::uint8_t a)
60 m_r(r),
61 m_g(g),
62 m_b(b),
63 m_a(a)
67 /// Parse a 32-bit unsigned integer as three packed R,G,B bytes.
69 /// Alpha will be untouched.
70 /// Blue is the least significant byte.
71 ///
72 /// This function is meant to be used to
73 /// parse ActionScript colors in numeric format.
74 void parseRGB(boost::uint32_t rgbCol) {
75 m_r = static_cast<boost::uint8_t>(rgbCol >> 16);
76 m_g = static_cast<boost::uint8_t>(rgbCol >> 8);
77 m_b = static_cast<boost::uint8_t>(rgbCol);
80 /// Return a 32-bit unsigned integer as four packed R,G,B bytes.
82 /// Blue is the least significant byte. The most significant (alpha)
83 /// byte is unused.
84 ///
85 /// This function is meant to be used to output ActionScript colors
86 /// in numeric format.
87 boost::uint32_t toRGB() const {
88 return (m_r << 16) + (m_g << 8) + m_b;
91 /// Return a 32-bit unsigned integer as four packed A,R,G,B bytes.
93 /// Blue is the least significant byte.
94 ///
95 /// This function is meant to be used to output ActionScript colors
96 /// in numeric format.
97 boost::uint32_t toRGBA() const {
98 return toRGB() + (m_a << 24);
101 friend std::ostream& operator<<(std::ostream& os, const rgba& r);
103 bool operator==(const rgba& o) const {
104 return m_r == o.m_r &&
105 m_g == o.m_g &&
106 m_b == o.m_b &&
107 m_a == o.m_a;
110 bool operator!=(const rgba& o) const {
111 return !(*this == o);
114 boost::uint8_t m_r, m_g, m_b, m_a;
118 std::ostream& operator<<(std::ostream& os, const rgba& r);
120 /// Create an RGBA value from a hex string (e.g. FF0000)
122 /// @param color A hex string in 'rrbbgg' format. This must contain only
123 /// a valid hexadecimal number. It is the caller's
124 /// responsibility to check it.
125 rgba colorFromHexString(const std::string& color);
127 /// Used for morphing.
128 rgba lerp(const rgba& a, const rgba& b, float f);
130 } // namespace gnash
132 #endif
135 // Local Variables:
136 // mode: C++
137 // indent-tabs-mode: t
138 // End: