GL Studio C++ Runtime API
gls_color.h
Go to the documentation of this file.
1/*! \file
2 \brief The Color class: Implements a 4 component RGBA color.
3
4 \par Copyright Information
5
6 Copyright (c) 2017 by The DiSTI Corporation.<br>
7 11301 Corporate Blvd; Suite 100<br>
8 Orlando, Florida 32817<br>
9 USA<br>
10 <br>
11 All rights reserved.<br>
12
13 This Software contains proprietary trade secrets of DiSTI and may not be
14reproduced, in whole or part, in any form, or by any means of electronic,
15mechanical, or otherwise, without the written permission of DiSTI. Said
16permission may be derived through the purchase of applicable DiSTI product
17licenses which detail the distribution rights of this content and any
18Derivative Works based on this or other copyrighted DiSTI Software.
19
20 NO WARRANTY. THE SOFTWARE IS PROVIDED "AS-IS," WITHOUT WARRANTY OF ANY KIND,
21AND ANY USE OF THIS SOFTWARE PRODUCT IS AT YOUR OWN RISK. TO THE MAXIMUM EXTENT
22PERMITTED BY APPLICABLE LAW, DISTI AND ITS SUPPLIERS DISCLAIM ALL WARRANTIES
23AND CONDITIONS, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
24IMPLIED WARRANTIES AND CONDITIONS OF MERCHANTABILITY AND/OR FITNESS FOR A
25PARTICULAR PURPOSE, TITLE, AND NON-INFRINGEMENT, WITH REGARD TO THE SOFTWARE.
26
27 LIMITATION OF LIABILITY. TO THE MAXIMUM EXTENT PERMITTED BY APPLICABLE LAW,
28IN NO EVENT SHALL DISTI OR ITS SUPPLIERS BE LIABLE FOR ANY SPECIAL, INCIDENTAL,
29INDIRECT, OR CONSEQUENTIAL DAMAGES WHATSOEVER (INCLUDING, WITHOUT LIMITATION,
30DAMAGES FOR LOSS OF BUSINESS PROFITS, BUSINESS INTERRUPTION, LOSS OF BUSINESS
31INFORMATION, OR ANY OTHER PECUNIARY LOSS) ARISING OUT OF THE USE OF OR
32INABILITY TO USE THE SOFTWARE, EVEN IF DISTI HAS BEEN ADVISED OF THE POSSIBILITY
33OF SUCH DAMAGES. DISTI'S ENTIRE LIABILITY AND YOUR EXCLUSIVE REMEDY SHALL NOT
34EXCEED FIVE DOLLARS (US$5.00).
35
36 The aforementioned terms and restrictions are governed by the laws of the
37State of Florida and the United States of America.
38
39*/
40#ifndef _GLS_COLOR_H
41#define _GLS_COLOR_H
42
43#include "disti_include.h"
44#include "unhide_globals.h"
45#include <iosfwd> // Forward references for the stream operators
46#include <string.h> // For memcmp
47
48namespace disti
49{
50/** \class GlsColor
51 The Color class: Implements a 4 component RGBA color.
52*/
54{
55 unsigned char rgba[ 4 ]; /** Red, Green, Blue, Alpha 0-255 range */
56
57public:
58 /** default constructor. Intializes rgba data to zero */
60 {
61 rgba[ 0 ] = rgba[ 1 ] = rgba[ 2 ] = rgba[ 3 ] = 0;
62 }
63
64 /** 4ub constructor. Intializes using rgba values
65 * \param r Red value, range 0-255
66 * \param g Green value, range 0-255
67 * \param b Blue value, range 0-255
68 * \param a Alpha value, range 0-255
69 */
70 GlsColor( unsigned char r, unsigned char g, unsigned char b, unsigned char a = 255 )
71 {
72 rgba[ 0 ] = r;
73 rgba[ 1 ] = g;
74 rgba[ 2 ] = b;
75 rgba[ 3 ] = a;
76 }
77
78 /** 4ubv constructor. Intializes using rgba value
79 * \param newColor 4 character RGBA array, range 0-255
80 */
81 GlsColor( const unsigned char newColor[] )
82 {
83 rgba[ 0 ] = newColor[ 0 ];
84 rgba[ 1 ] = newColor[ 1 ];
85 rgba[ 2 ] = newColor[ 2 ];
86 rgba[ 3 ] = newColor[ 3 ];
87 }
88
89 /** 4ul constructor.
90 * \param rgbaVal Unsigned long containing color in the form RRGGBBAA (8 bits per component
91 */
92 GlsColor( unsigned long rgbaVal )
93 {
94 rgba[ 0 ] = (unsigned char)( ( rgbaVal & 0xFF000000 ) >> 24 );
95 rgba[ 1 ] = (unsigned char)( ( rgbaVal & 0x00FF0000 ) >> 16 );
96 rgba[ 2 ] = (unsigned char)( ( rgbaVal & 0x0000FF00 ) >> 8 );
97 rgba[ 3 ] = (unsigned char)( ( rgbaVal & 0x000000FF ) );
98 }
99
100 /// Copy constructor.
101 /// \param color The color to copy from.
102 GlsColor( const GlsColor& color )
103 {
104 memcpy( rgba, color.rgba, sizeof( unsigned char ) * 4 );
105 }
106
107 /** Sets RGBA value using floats
108 * \param r Red value, range 0-1.0
109 * \param g Green value, range 0-1.0
110 * \param b Blue value, range 0-1.0
111 * \param a Alpha value, range 0-1.0
112 */
113 void SetRGBA4f( float r, float g, float b, float a = 1 )
114 {
115 rgba[ 0 ] = (unsigned char)( r * 255.0f );
116 rgba[ 1 ] = (unsigned char)( g * 255.0f );
117 rgba[ 2 ] = (unsigned char)( b * 255.0f );
118 rgba[ 3 ] = (unsigned char)( a * 255.0f );
119 }
120
121 /** Gets RGBA value using floats
122 * \param r Red value, range 0-1.0
123 * \param g Green value, range 0-1.0
124 * \param b Blue value, range 0-1.0
125 * \param a Alpha value, range 0-1.0
126 */
127 void GetRGBA4f( float& r, float& g, float& b, float& a ) const
128 {
129 r = (float)rgba[ 0 ] / 255.0f;
130 g = (float)rgba[ 1 ] / 255.0f;
131 b = (float)rgba[ 2 ] / 255.0f;
132 a = (float)rgba[ 3 ] / 255.0f;
133 }
134
135 /** Sets RGBA value using doubles
136 * \param r Red value, range 0-1.0
137 * \param g Green value, range 0-1.0
138 * \param b Blue value, range 0-1.0
139 * \param a Alpha value, range 0-1.0
140 */
141 void SetRGBA4d( double r, double g, double b, double a = 1 )
142 {
143 rgba[ 0 ] = (unsigned char)( r * 255.0 );
144 rgba[ 1 ] = (unsigned char)( g * 255.0 );
145 rgba[ 2 ] = (unsigned char)( b * 255.0 );
146 rgba[ 3 ] = (unsigned char)( a * 255.0 );
147 }
148
149 /** Gets RGBA value using doubles
150 * \param r Red value, range 0-1.0
151 * \param g Green value, range 0-1.0
152 * \param b Blue value, range 0-1.0
153 * \param a Alpha value, range 0-1.0
154 */
155 void GetRGBA4d( double& r, double& g, double& b, double& a ) const
156 {
157 r = (double)rgba[ 0 ] / 255.0;
158 g = (double)rgba[ 1 ] / 255.0;
159 b = (double)rgba[ 2 ] / 255.0;
160 a = (double)rgba[ 3 ] / 255.0;
161 }
162
163 /** Sets RGBA value
164 * \param r Red value, range 0-255
165 * \param g Green value, range 0-255
166 * \param b Blue value, range 0-255
167 * \param a Alpha value, range 0-255
168 */
169 void RGBA( unsigned char r, unsigned char g, unsigned char b, unsigned char a = 255 )
170 {
171 rgba[ 0 ] = r;
172 rgba[ 1 ] = g;
173 rgba[ 2 ] = b;
174 rgba[ 3 ] = a;
175 }
176
177 /** Sets RGBA value
178 * \param newColor 4 character RGBA array, range 0-255
179 */
180 void RGBA( const unsigned char newColor[] )
181 {
182 memcpy( rgba, newColor, sizeof( unsigned char ) * 4 );
183 }
184
185 /** Sets RGBA value
186 * \param rgbaVal Unsigned long containing color in the form RRGGBBAA (8 bits per component
187 */
188 void RGBA( unsigned long rgbaVal )
189 {
190 rgba[ 0 ] = (unsigned char)( ( rgbaVal & 0xFF000000 ) >> 24 );
191 rgba[ 1 ] = (unsigned char)( ( rgbaVal & 0x00FF0000 ) >> 16 );
192 rgba[ 2 ] = (unsigned char)( ( rgbaVal & 0x0000FF00 ) >> 8 );
193 rgba[ 3 ] = (unsigned char)( ( rgbaVal & 0x000000FF ) );
194 }
195
196 /// Gets RGBA value
197 /// \return A pointer to array of 4 unsigned chars containing rgba (0-255 range).
198 unsigned char* RGBA() { return rgba; }
199
200 /// Gets RGBA value
201 /// \return A const pointer to array of 4 unsigned chars containing rgba (0-255 range).
202 const unsigned char* RGBA() const { return rgba; }
203
204 /** \return RGBA value packed into a 32 bit unsigned int in host byte order */
205 unsigned long RGBA_ULong() const
206 {
207 return ( rgba[ 0 ] << 24 ) | ( rgba[ 1 ] << 16 ) | ( rgba[ 2 ] << 8 ) | rgba[ 3 ];
208 }
209
210 /** \return The Red component of this color */
211 unsigned char R() const { return rgba[ 0 ]; }
212
213 /** \return The Green component of this color */
214 unsigned char G() const { return rgba[ 1 ]; }
215
216 /** \return The Blue component of this color */
217 unsigned char B() const { return rgba[ 2 ]; }
218
219 /** \return The Alpha component of this color */
220 unsigned char A() const { return rgba[ 3 ]; }
221
222 /** Set the Red component of this color
223 * \param val The new value for the component
224 */
225 void R( const unsigned char val ) { rgba[ 0 ] = val; }
226
227 /** Set the Green component of this color
228 * \param val The new value for the component
229 */
230 void G( const unsigned char val ) { rgba[ 1 ] = val; }
231
232 /** Set the Blue component of this color
233 * \param val The new value for the component
234 */
235 void B( const unsigned char val ) { rgba[ 2 ] = val; }
236
237 /** Set the Alpha component of this color
238 * \param val The new value for the component
239 */
240 void A( const unsigned char val ) { rgba[ 3 ] = val; }
241
242 /** Determines if the color is identical to the supplied color
243 \param arg color to compare to
244 \return TRUE if equal, else FALSE
245 */
246 bool operator==( const GlsColor& arg ) const
247 {
248 return 0 == memcmp( rgba, arg.rgba, sizeof( unsigned char ) * 4 );
249 }
250
251 /** Determines if the color is NOT identical to the supplied color
252 \param arg color to compare to
253 \return TRUE if NOT equal, else FALSE
254 */
255 bool operator!=( const GlsColor& arg ) const
256 {
257 return 0 != memcmp( rgba, arg.rgba, sizeof( unsigned char ) * 4 );
258 }
259
260 /// Assignment operator
261 /// \param color The color to copy.
262 /// \return The resulting color (this).
263 GlsColor& operator=( const GlsColor& color )
264 {
265 if( &color != this )
266 {
267 memcpy( rgba, color.rgba, sizeof( unsigned char ) * 4 );
268 }
269 return *this;
270 }
271};
272
273/// Stream out operator
274/// \param outstr The stream to write to.
275/// \param color The color to write to the stream.
276/// \return The stream in its current state.
277DISTI_EXPORT std::ostream& operator<<( std::ostream& outstr, const GlsColor& color );
278
279/// Stream in operator
280/// \param instr The stream to read from.
281/// \param color The returned color to read from the stream.
282/// \return The stream in its current state.
283DISTI_EXPORT std::istream& operator>>( std::istream& instr, GlsColor& color );
284
285/// Alias for backwards compatibility
287
288} // namespace disti
289
290#endif
Definition: gls_color.h:54
GlsColor & operator=(const GlsColor &color)
Definition: gls_color.h:263
void A(const unsigned char val)
Definition: gls_color.h:240
unsigned char G() const
Definition: gls_color.h:214
void GetRGBA4f(float &r, float &g, float &b, float &a) const
Definition: gls_color.h:127
void R(const unsigned char val)
Definition: gls_color.h:225
void B(const unsigned char val)
Definition: gls_color.h:235
void RGBA(const unsigned char newColor[])
Definition: gls_color.h:180
void SetRGBA4f(float r, float g, float b, float a=1)
Definition: gls_color.h:113
unsigned char R() const
Definition: gls_color.h:211
void RGBA(unsigned long rgbaVal)
Definition: gls_color.h:188
void SetRGBA4d(double r, double g, double b, double a=1)
Definition: gls_color.h:141
bool operator==(const GlsColor &arg) const
Definition: gls_color.h:246
GlsColor()
Definition: gls_color.h:59
void G(const unsigned char val)
Definition: gls_color.h:230
GlsColor(unsigned long rgbaVal)
Definition: gls_color.h:92
bool operator!=(const GlsColor &arg) const
Definition: gls_color.h:255
void GetRGBA4d(double &r, double &g, double &b, double &a) const
Definition: gls_color.h:155
unsigned char B() const
Definition: gls_color.h:217
unsigned long RGBA_ULong() const
Definition: gls_color.h:205
const unsigned char * RGBA() const
Definition: gls_color.h:202
GlsColor(const unsigned char newColor[])
Definition: gls_color.h:81
GlsColor(unsigned char r, unsigned char g, unsigned char b, unsigned char a=255)
Definition: gls_color.h:70
unsigned char A() const
Definition: gls_color.h:220
unsigned char * RGBA()
Definition: gls_color.h:198
GlsColor(const GlsColor &color)
Definition: gls_color.h:102
void RGBA(unsigned char r, unsigned char g, unsigned char b, unsigned char a=255)
Definition: gls_color.h:169
A file for all GL Studio files to include.
Force inclusion of the DirectShow library.
Definition: bmpimage.h:47
std::ostream & operator<<(std::ostream &outstr, const AttributeName &name)
GlsColor glsColor
Alias for backwards compatibility.
Definition: gls_color.h:286
std::istream & operator>>(std::istream &instr, GlsColor &color)
The DistiUnhideGlobalsDummyClass class.