Claw  1.7.0
pixel.hpp
Go to the documentation of this file.
1 /*
2  CLAW - a C++ Library Absolutely Wonderful
3 
4  CLAW is a free library without any particular aim but being useful to
5  anyone.
6 
7  Copyright (C) 2005-2011 Julien Jorge
8 
9  This library is free software; you can redistribute it and/or
10  modify it under the terms of the GNU Lesser General Public
11  License as published by the Free Software Foundation; either
12  version 2.1 of the License, or (at your option) any later version.
13 
14  This library is distributed in the hope that it will be useful,
15  but WITHOUT ANY WARRANTY; without even the implied warranty of
16  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17  Lesser General Public License for more details.
18 
19  You should have received a copy of the GNU Lesser General Public
20  License along with this library; if not, write to the Free Software
21  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22 
23  contact: julien.jorge@gamned.org
24 */
30 #ifndef __CLAW_PIXEL_HPP_
31 #define __CLAW_PIXEL_HPP_
32 
33 #include <string>
34 
35 namespace claw
36 {
37  namespace graphic
38  {
39  struct rgba_pixel;
40 
44  struct rgb_pixel
45  {
46  typedef unsigned char component_type;
47 
49  struct
50  {
52  component_type red;
53 
55  component_type green;
56 
58  component_type blue;
59 
60  } components;
61 
62  public:
63  rgb_pixel();
64  rgb_pixel( component_type r, component_type g, component_type b );
65  rgb_pixel( const rgba_pixel& p );
66  explicit rgb_pixel( const std::string& c );
67 
68  bool operator==(const rgb_pixel& that) const;
69  bool operator==(const rgba_pixel& that) const;
70  bool operator!=(const rgb_pixel& that) const;
71  bool operator!=(const rgba_pixel& that) const;
72 
73  }; // struct rgb_pixel
74 
78  struct rgba_pixel
79  {
80  typedef unsigned char component_type;
81 
82  union
83  {
85  unsigned int pixel;
86 
88  struct
89  {
91  component_type red;
92 
94  component_type green;
95 
97  component_type blue;
98 
100  component_type alpha;
101 
102  } components;
103  };
104 
105  public:
106  rgba_pixel();
107  rgba_pixel( const rgb_pixel& that );
108  rgba_pixel( component_type r, component_type g, component_type b,
109  component_type a );
110  explicit rgba_pixel( const std::string& c );
111 
112  rgba_pixel& operator=( const rgb_pixel& that );
113  bool operator==( const rgba_pixel& that ) const;
114  bool operator!=( const rgba_pixel& that ) const;
115 
116  component_type luminosity() const;
117 
118  }; // struct rgba_pixel
119 
120  typedef rgb_pixel rgb_pixel_8;
121  typedef rgba_pixel rgba_pixel_8;
122 
123  extern rgba_pixel transparent_pixel;
124 
125  extern rgba_pixel black_pixel;
126  extern rgba_pixel white_pixel;
127 
128  extern rgba_pixel blue_pixel;
129  extern rgba_pixel green_pixel;
130  extern rgba_pixel red_pixel;
131 
132  extern rgba_pixel yellow_pixel;
133  extern rgba_pixel magenta_pixel;
134  extern rgba_pixel cyan_pixel;
135 
136  } // namespace graphic
137 } // namespace claw
138 
139 #endif // __CLAW_PIXEL_HPP__