zenilib  0.5.3.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
Color.hxx
Go to the documentation of this file.
1 /* This file is part of the Zenipex Library (zenilib).
2  * Copyright (C) 2011 Mitchell Keith Bloch (bazald).
3  *
4  * zenilib is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU Lesser General Public License as published by
6  * the Free Software Foundation, either version 3 of the License, or
7  * (at your option) any later version.
8  *
9  * zenilib is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public License
15  * along with zenilib. If not, see <http://www.gnu.org/licenses/>.
16  */
17 
18 #ifndef ZENI_COLOR_HXX
19 #define ZENI_COLOR_HXX
20 
21 #include <Zeni/Color.h>
22 
23 #include <cassert>
24 
25 namespace Zeni {
26 
27  unsigned char Color::r_ub() const {
28  return static_cast<unsigned char>(r*0xFF);
29  }
30 
31  unsigned char Color::g_ub() const {
32  return static_cast<unsigned char>(g*0xFF);
33  }
34 
35  unsigned char Color::b_ub() const {
36  return static_cast<unsigned char>(b*0xFF);
37  }
38 
39  unsigned char Color::a_ub() const {
40  return static_cast<unsigned char>(a*0xFF);
41  }
42 
44  return Uint32(r_ub() << 24) | Uint32(g_ub() << 16) | Uint32(b_ub() << 8) | Uint32(a_ub());
45  }
46 
48  return Uint32(a_ub() << 24) | Uint32(r_ub() << 16) | Uint32(g_ub() << 8) | Uint32(b_ub());
49  }
50 
52  return Uint32(b_ub() << 24) | Uint32(g_ub() << 16) | Uint32(r_ub() << 8) | Uint32(a_ub());
53  }
54 
55  const float & Color::operator[](const int &index) const {
56  assert(-1 < index && index < 4);
57  const float * const ptr = &r;
58  return ptr[index];
59  }
60 
61  float & Color::operator[](const int &index) {
62  assert(-1 < index && index < 4);
63  float * const ptr = &r;
64  return ptr[index];
65  }
66 
67 }
68 
69 #endif
unsigned char a_ub() const
Get the alpha channel [0x00, 0xFF].
Definition: Color.hxx:39
GLboolean GLboolean g
Definition: glew.h:8736
GLboolean GLboolean GLboolean GLboolean a
Definition: glew.h:8736
#define assert(x)
Definition: SDL_malloc.c:1234
Uint32 get_rgba() const
Get a Uint32 representation of 0xRRGGBBAA.
Definition: Color.hxx:43
const float & operator[](const int &index) const
Get &#39;index&#39;.
Definition: Color.hxx:55
unsigned char r_ub() const
Get the red channel [0x00, 0xFF].
Definition: Color.hxx:27
uint32_t Uint32
An unsigned 32-bit integer type.
Definition: SDL_stdinc.h:145
unsigned char b_ub() const
Get the blue channel [0x00, 0xFF].
Definition: Color.hxx:35
GLuint index
Definition: glew.h:1800
unsigned char g_ub() const
Get the green channel [0x00, 0xFF].
Definition: Color.hxx:31
Uint32 get_bgra() const
Get a Uint32 representation of 0xBBGGRRAA - Endianness swap of rgba.
Definition: Color.hxx:51
GLdouble GLdouble GLdouble r
Definition: glew.h:1392
GLdouble GLdouble GLdouble b
Definition: glew.h:8383
float r
Definition: Color.h:66
Uint32 get_argb() const
Get a Uint32 representation of 0xAARRGGBB.
Definition: Color.hxx:47