Gnash  0.8.11dev
RGBA.h
Go to the documentation of this file.
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.
15 //
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 //
20 
21 #ifndef GNASH_RGBA_H
22 #define GNASH_RGBA_H
23 
24 #include <string>
25 #include <cstdint>
26 
27 #include "dsodefs.h" // for DSOTEXPORT
28 
29 namespace gnash {
30 
32 //
36 {
37 public:
38 
40  //
42  constexpr rgba()
43  :
44  m_r(255),
45  m_g(255),
46  m_b(255),
47  m_a(255)
48  {}
49 
51  //
56  rgba(std::uint8_t r, std::uint8_t g, std::uint8_t b,
57  std::uint8_t a)
58  :
59  m_r(r),
60  m_g(g),
61  m_b(b),
62  m_a(a)
63  {
64  }
65 
67  //
73  void parseRGB(std::uint32_t rgbCol) {
74  m_r = static_cast<std::uint8_t>(rgbCol >> 16);
75  m_g = static_cast<std::uint8_t>(rgbCol >> 8);
76  m_b = static_cast<std::uint8_t>(rgbCol);
77  }
78 
80  //
86  std::uint32_t toRGB() const {
87  return (m_r << 16) + (m_g << 8) + m_b;
88  }
89 
91  //
96  std::uint32_t toRGBA() const {
97  return toRGB() + (m_a << 24);
98  }
99 
100  friend std::ostream& operator<<(std::ostream& os, const rgba& r);
101 
102  bool operator==(const rgba& o) const {
103  return m_r == o.m_r &&
104  m_g == o.m_g &&
105  m_b == o.m_b &&
106  m_a == o.m_a;
107  }
108 
109  bool operator!=(const rgba& o) const {
110  return !(*this == o);
111  }
112 
113  std::uint8_t m_r, m_g, m_b, m_a;
114 
115 };
116 
117 DSOTEXPORT std::ostream& operator<<(std::ostream& os, const rgba& r);
118 
120 //
124 rgba colorFromHexString(const std::string& color);
125 
127 rgba DSOEXPORT lerp(const rgba& a, const rgba& b, float f);
128 
129 } // namespace gnash
130 
131 #endif
132 
133 
134 // Local Variables:
135 // mode: C++
136 // indent-tabs-mode: t
137 // End:
Definition: GnashKey.h:147
std::uint8_t m_b
Definition: RGBA.h:113
Anonymous namespace for callbacks, local functions, event handlers etc.
Definition: dbus_ext.cpp:40
Definition: GnashKey.h:152
Definition: GnashKey.h:161
std::uint8_t m_g
Definition: RGBA.h:113
const VGfloat color[4]
Definition: testr_gtk.cpp:82
Definition: GnashKey.h:164
std::ostream & operator<<(std::ostream &o, const URL &u)
Definition: URL.cpp:447
T lerp(T a, T b, T f)
Definition: GnashNumeric.h:85
std::uint32_t toRGBA() const
Return a 32-bit unsigned integer as four packed A,R,G,B bytes.
Definition: RGBA.h:96
bool operator==(const rgba &o) const
Definition: RGBA.h:102
rgba colorFromHexString(const std::string &color)
Create an RGBA value from a hex string (e.g. FF0000)
Definition: RGBA.cpp:41
Definition: GnashKey.h:148
#define DSOEXPORT
Definition: dsodefs.h:55
constexpr rgba()
Construct default RGBA value.
Definition: RGBA.h:42
rgba(std::uint8_t r, std::uint8_t g, std::uint8_t b, std::uint8_t a)
Construct an RGBA with the provided values.
Definition: RGBA.h:56
std::uint8_t m_a
Definition: RGBA.h:113
void parseRGB(std::uint32_t rgbCol)
Parse a 32-bit unsigned integer as three packed R,G,B bytes.
Definition: RGBA.h:73
#define DSOTEXPORT
Definition: dsodefs.h:63
Definition: GnashKey.h:153
bool operator!=(const rgba &o) const
Definition: RGBA.h:109
std::uint8_t m_r
Definition: RGBA.h:113
std::uint32_t toRGB() const
Return a 32-bit unsigned integer as four packed R,G,B bytes.
Definition: RGBA.h:86
A basic RGBA type.
Definition: RGBA.h:35