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 >> (unsigned long)_shift)
77 & ~(~0UL << (unsigned long)_bits)) << (unsigned long)(16 - _bits);
78 }
79
85 long unsigned set(int v) const
86 { return (v >> (unsigned long)(16 - _bits)) << (unsigned long)_shift; }
87
93 template< typename OUT >
94 void dump(OUT &s) const
95 {
96 s.printf("%d(%d)", (int)size(), (int)shift());
97 }
98} __attribute__((packed));
99
108{
109private:
110 Color_component _r, _g, _b, _a;
111 unsigned char _bpp;
112
113public:
118 Color_component const &r() const { return _r; }
119
124 Color_component const &g() const { return _g; }
125
130 Color_component const &b() const { return _b; }
131
136 Color_component const &a() const { return _a; }
137
145 {
146 unsigned char top_bit = cxx::max<unsigned char>(_r.size() + _r.shift(),
147 _g.size() + _g.shift());
148 top_bit = cxx::max<unsigned char>(top_bit, _b.size() + _b.shift());
149 top_bit = cxx::max<unsigned char>(top_bit, _a.size() + _a.shift());
150
151 unsigned char bits = _bpp * 8;
152
153 if (top_bit < bits)
154 return Color_component(bits - top_bit, top_bit);
155
156 return Color_component(0, 0);
157 }
158
163 unsigned char bytes_per_pixel() const { return _bpp; }
164
169 unsigned char bits_per_pixel() const
170 { return _r.size() + _g.size() + _b.size() + _a.size(); }
171
176 bool has_alpha() const { return _a.size() > 0; }
177
182 void r(Color_component const &c) { _r = c; }
183
188 void g(Color_component const &c) { _g = c; }
189
194 void b(Color_component const &c) { _b = c; }
195
200 void a(Color_component const &c) { _a = c; }
201
206 void bytes_per_pixel(unsigned char bpp) { _bpp = bpp; }
207
211 Pixel_info() = default;
212
225 Pixel_info(unsigned char bpp, char r, char rs, char g, char gs,
226 char b, char bs, char a = 0, char as = 0)
227 : _r(r, rs), _g(g, gs), _b(b, bs), _a(a, as), _bpp(bpp)
228 {}
229
236 template<typename VBI>
237 explicit Pixel_info(VBI const *vbi)
238 : _r(vbi->red_mask_size, vbi->red_field_position),
239 _g(vbi->green_mask_size, vbi->green_field_position),
240 _b(vbi->blue_mask_size, vbi->blue_field_position),
241 _bpp((vbi->bits_per_pixel + 7) / 8)
242 {}
243
249 bool operator == (Pixel_info const &o) const
250 {
251 return _r == o._r && _g == o._g && _b == o._b && _a == o._a && _bpp == o._bpp;
252 }
253
259 template< typename OUT >
260 void dump(OUT &s) const
261 {
262 s.printf("RGBA(%d):%d(%d):%d(%d):%d(%d):%d(%d)",
263 (int)bytes_per_pixel(),
264 (int)r().size(), (int)r().shift(),
265 (int)g().size(), (int)g().shift(),
266 (int)b().size(), (int)b().shift(),
267 (int)a().size(), (int)a().shift());
268 }
269};
270
271
272}}
273
274
A color component.
Definition colors:33
void dump(OUT &s) const
Dump information on the view information to a stream.
Definition colors:94
long unsigned set(int v) const
Transform 16bit normalized value to the component in the color space.
Definition colors:85
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:108
Color_component const & g() const
Return the green color compoment of the pixel.
Definition colors:124
Color_component const & b() const
Return the blue color compoment of the pixel.
Definition colors:130
Pixel_info(VBI const *vbi)
Convenience constructor.
Definition colors:237
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:225
Color_component const & a() const
Return the alpha color compoment of the pixel.
Definition colors:136
void a(Color_component const &c)
Set the alpha color component of the pixel.
Definition colors:200
void g(Color_component const &c)
Set the green color component of the pixel.
Definition colors:188
bool has_alpha() const
Return whether the pixel has an alpha channel.
Definition colors:176
Color_component const & r() const
Return the red color compoment of the pixel.
Definition colors:118
void bytes_per_pixel(unsigned char bpp)
Set the size of the pixel in bytes.
Definition colors:206
void r(Color_component const &c)
Set the red color component of the pixel.
Definition colors:182
void b(Color_component const &c)
Set the blue color component of the pixel.
Definition colors:194
void dump(OUT &s) const
Dump information on the pixel to a stream.
Definition colors:260
unsigned char bits_per_pixel() const
Number of bits of the pixel.
Definition colors:169
unsigned char bytes_per_pixel() const
Query size of pixel in bytes.
Definition colors:163
Pixel_info()=default
Constructor.
Color_component const padding() const
Compute the padding pseudo component.
Definition colors:144
L4 compiler related defines.
#define L4_EXPORT
Attribute to mark functions, variables, and data types as being exported from a library.
Definition compiler.h:221
L4Re C++ Interfaces.
Definition cmd_control:15