L4Re Operating System Framework
Interface and Usage Documentation
Loading...
Searching...
No Matches
colors
1// vi:set ft=cpp: -*- Mode: C++ -*-
2/*
3 * (c) 2008-2009 Adam Lackorzynski <adam@os.inf.tu-dresden.de>,
4 * Alexander Warg <warg@os.inf.tu-dresden.de>
5 * economic rights: Technische Universität Dresden (Germany)
6 *
7 * This file is part of TUD:OS and distributed under the terms of the
8 * GNU General Public License 2.
9 * Please see the COPYING-GPL-2 file for details.
10 *
11 * As a special exception, you may use this file as part of a free software
12 * library without restriction. Specifically, if other files instantiate
13 * templates or use macros or inline functions from this file, or you compile
14 * this file and link it with other files to produce an executable, this
15 * file does not by itself cause the resulting executable to be covered by
16 * the GNU General Public License. This exception does not however
17 * invalidate any other reasons why the executable file might be covered by
18 * the GNU General Public License.
19 */
20
21#pragma once
22
23#include <l4/sys/compiler.h>
24#include <l4/cxx/minmax>
25
26namespace L4Re { namespace Video {
27
33{
34private:
35 unsigned char _bits;
36 unsigned char _shift;
37
38public:
40 Color_component() : _bits(0), _shift(0) {}
41
47 Color_component(unsigned char bits, unsigned char shift)
48 : _bits(bits), _shift(shift) {}
49
54 unsigned char size() const { return _bits; }
55
60 unsigned char shift() const { return _shift; }
61
66 bool operator == (Color_component const &o) const
67 { return _shift == o._shift && _bits == o._bits; }
68
74 int get(unsigned long v) const
75 {
76 return ((v >> _shift) & ~(~0UL << _bits)) << (16UL - _bits);
77 }
78
84 long unsigned set(int v) const
85 { return (static_cast<unsigned long>(v) >> (16UL - _bits)) << _shift; }
86
91 template< typename OUT >
92 void dump(OUT &s) const
93 {
94 s.printf("%d(%d)", static_cast<int>(size()), static_cast<int>(shift()));
95 }
96} __attribute__((packed));
97
106{
107private:
108 Color_component _r, _g, _b, _a;
109 unsigned char _bpp;
110
111public:
116 Color_component const &r() const { return _r; }
117
122 Color_component const &g() const { return _g; }
123
128 Color_component const &b() const { return _b; }
129
134 Color_component const &a() const { return _a; }
135
143 {
144 unsigned char top_bit = cxx::max<unsigned char>(_r.size() + _r.shift(),
145 _g.size() + _g.shift());
146 top_bit = cxx::max<unsigned char>(top_bit, _b.size() + _b.shift());
147 top_bit = cxx::max<unsigned char>(top_bit, _a.size() + _a.shift());
148
149 unsigned char bits = _bpp * 8;
150
151 if (top_bit < bits)
152 return Color_component(bits - top_bit, top_bit);
153
154 return Color_component(0, 0);
155 }
156
161 unsigned char bytes_per_pixel() const { return _bpp; }
162
167 unsigned char bits_per_pixel() const
168 { return _r.size() + _g.size() + _b.size() + _a.size(); }
169
174 bool has_alpha() const { return _a.size() > 0; }
175
180 void r(Color_component const &c) { _r = c; }
181
186 void g(Color_component const &c) { _g = c; }
187
192 void b(Color_component const &c) { _b = c; }
193
198 void a(Color_component const &c) { _a = c; }
199
204 void bytes_per_pixel(unsigned char bpp) { _bpp = bpp; }
205
209 Pixel_info() : _bpp(0) {};
210
223 Pixel_info(unsigned char bpp, char r, char rs, char g, char gs,
224 char b, char bs, char a = 0, char as = 0)
225 : _r(r, rs), _g(g, gs), _b(b, bs), _a(a, as), _bpp(bpp)
226 {}
227
234 template<typename VBI>
235 explicit Pixel_info(VBI const *vbi)
236 : _r(vbi->red_mask_size, vbi->red_field_position),
237 _g(vbi->green_mask_size, vbi->green_field_position),
238 _b(vbi->blue_mask_size, vbi->blue_field_position),
239 _bpp((vbi->bits_per_pixel + 7) / 8)
240 {}
241
247 bool operator == (Pixel_info const &o) const
248 {
249 return _r == o._r && _g == o._g && _b == o._b && _a == o._a && _bpp == o._bpp;
250 }
251
256 template< typename OUT >
257 void dump(OUT &s) const
258 {
259 s.printf("RGBA(%d):%d(%d):%d(%d):%d(%d):%d(%d)",
260 static_cast<int>(bytes_per_pixel()),
261 static_cast<int>(r().size()), static_cast<int>(r().shift()),
262 static_cast<int>(g().size()), static_cast<int>(g().shift()),
263 static_cast<int>(b().size()), static_cast<int>(b().shift()),
264 static_cast<int>(a().size()), static_cast<int>(a().shift()));
265 }
266};
267
268
269}}
270
271
A color component.
Definition colors:33
void dump(OUT &s) const
Dump information on the view information to a stream.
Definition colors:92
long unsigned set(int v) const
Transform 16bit normalized value to the component in the color space.
Definition colors:84
unsigned char size() const
Return the number of bits used by the component.
Definition colors:54
Color_component()
Constructor.
Definition colors:40
int get(unsigned long v) const
Get component from value (normalized to 16bits).
Definition colors:74
Color_component(unsigned char bits, unsigned char shift)
Constructor.
Definition colors:47
unsigned char shift() const
Return the position of the component in the pixel.
Definition colors:60
Pixel information.
Definition colors:106
Color_component const & g() const
Return the green color compoment of the pixel.
Definition colors:122
Color_component const & b() const
Return the blue color compoment of the pixel.
Definition colors:128
Pixel_info(VBI const *vbi)
Convenience constructor.
Definition colors:235
Pixel_info(unsigned char bpp, char r, char rs, char g, char gs, char b, char bs, char a=0, char as=0)
Constructor.
Definition colors:223
Color_component const & a() const
Return the alpha color compoment of the pixel.
Definition colors:134
void a(Color_component const &c)
Set the alpha color component of the pixel.
Definition colors:198
void g(Color_component const &c)
Set the green color component of the pixel.
Definition colors:186
bool has_alpha() const
Return whether the pixel has an alpha channel.
Definition colors:174
Pixel_info()
Constructor.
Definition colors:209
Color_component const & r() const
Return the red color compoment of the pixel.
Definition colors:116
void bytes_per_pixel(unsigned char bpp)
Set the size of the pixel in bytes.
Definition colors:204
void r(Color_component const &c)
Set the red color component of the pixel.
Definition colors:180
void b(Color_component const &c)
Set the blue color component of the pixel.
Definition colors:192
void dump(OUT &s) const
Dump information on the pixel to a stream.
Definition colors:257
unsigned char bits_per_pixel() const
Number of bits of the pixel.
Definition colors:167
unsigned char bytes_per_pixel() const
Query size of pixel in bytes.
Definition colors:161
Color_component const padding() const
Compute the padding pseudo component.
Definition colors:142
L4 compiler related defines.
#define L4_EXPORT
Attribute to mark functions, variables, and data types as being exported from a library.
Definition compiler.h:231
L4Re C++ Interfaces.
Definition l4re.dox:17