L4Re Operating System Framework
Interface and Usage Documentation
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
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 * License: see LICENSE.spdx (in this directory or the directories above)
8 */
9
10#pragma once
11
12#include <l4/sys/compiler.h>
13#include <l4/cxx/minmax>
14
15namespace L4Re { namespace Video {
16
22{
23private:
24 unsigned char _bits;
25 unsigned char _shift;
26
27public:
29 Color_component() : _bits(0), _shift(0) {}
30
36 Color_component(unsigned char bits, unsigned char shift)
37 : _bits(bits), _shift(shift) {}
38
43 unsigned char size() const { return _bits; }
44
49 unsigned char shift() const { return _shift; }
50
55 bool operator == (Color_component const &o) const
56 { return _shift == o._shift && _bits == o._bits; }
57
63 int get(unsigned long v) const
64 {
65 return ((v >> _shift) & ~(~0UL << _bits)) << (16UL - _bits);
66 }
67
73 long unsigned set(int v) const
74 { return (static_cast<unsigned long>(v) >> (16UL - _bits)) << _shift; }
75
80 template< typename OUT >
81 void dump(OUT &s) const
82 {
83 s.printf("%d(%d)", static_cast<int>(size()), static_cast<int>(shift()));
84 }
85} __attribute__((packed));
86
95{
96private:
97 Color_component _r, _g, _b, _a;
98 unsigned char _bpp;
99
100public:
105 Color_component const &r() const { return _r; }
106
111 Color_component const &g() const { return _g; }
112
117 Color_component const &b() const { return _b; }
118
123 Color_component const &a() const { return _a; }
124
132 {
133 unsigned char top_bit = cxx::max<unsigned char>(_r.size() + _r.shift(),
134 _g.size() + _g.shift());
135 top_bit = cxx::max<unsigned char>(top_bit, _b.size() + _b.shift());
136 top_bit = cxx::max<unsigned char>(top_bit, _a.size() + _a.shift());
137
138 unsigned char bits = _bpp * 8;
139
140 if (top_bit < bits)
141 return Color_component(bits - top_bit, top_bit);
142
143 return Color_component(0, 0);
144 }
145
150 unsigned char bytes_per_pixel() const { return _bpp; }
151
156 unsigned char bits_per_pixel() const
157 { return _r.size() + _g.size() + _b.size() + _a.size(); }
158
163 bool has_alpha() const { return _a.size() > 0; }
164
169 void r(Color_component const &c) { _r = c; }
170
175 void g(Color_component const &c) { _g = c; }
176
181 void b(Color_component const &c) { _b = c; }
182
187 void a(Color_component const &c) { _a = c; }
188
193 void bytes_per_pixel(unsigned char bpp) { _bpp = bpp; }
194
198 Pixel_info() : _bpp(0) {};
199
212 Pixel_info(unsigned char bpp, char r, char rs, char g, char gs,
213 char b, char bs, char a = 0, char as = 0)
214 : _r(r, rs), _g(g, gs), _b(b, bs), _a(a, as), _bpp(bpp)
215 {}
216
223 template<typename VBI>
224 explicit Pixel_info(VBI const *vbi)
225 : _r(vbi->red_mask_size, vbi->red_field_position),
226 _g(vbi->green_mask_size, vbi->green_field_position),
227 _b(vbi->blue_mask_size, vbi->blue_field_position),
228 _bpp((vbi->bits_per_pixel + 7) / 8)
229 {}
230
236 bool operator == (Pixel_info const &o) const
237 {
238 return _r == o._r && _g == o._g && _b == o._b && _a == o._a && _bpp == o._bpp;
239 }
240
245 template< typename OUT >
246 void dump(OUT &s) const
247 {
248 s.printf("RGBA(%d):%d(%d):%d(%d):%d(%d):%d(%d)",
249 static_cast<int>(bytes_per_pixel()),
250 static_cast<int>(r().size()), static_cast<int>(r().shift()),
251 static_cast<int>(g().size()), static_cast<int>(g().shift()),
252 static_cast<int>(b().size()), static_cast<int>(b().shift()),
253 static_cast<int>(a().size()), static_cast<int>(a().shift()));
254 }
255};
256
257
258}}
259
260
A color component.
Definition colors:22
void dump(OUT &s) const
Dump information on the view information to a stream.
Definition colors:81
long unsigned set(int v) const
Transform 16bit normalized value to the component in the color space.
Definition colors:73
unsigned char size() const
Return the number of bits used by the component.
Definition colors:43
Color_component()
Constructor.
Definition colors:29
int get(unsigned long v) const
Get component from value (normalized to 16bits).
Definition colors:63
Color_component(unsigned char bits, unsigned char shift)
Constructor.
Definition colors:36
unsigned char shift() const
Return the position of the component in the pixel.
Definition colors:49
Pixel information.
Definition colors:95
Color_component const & g() const
Return the green color compoment of the pixel.
Definition colors:111
Color_component const & b() const
Return the blue color compoment of the pixel.
Definition colors:117
Pixel_info(VBI const *vbi)
Convenience constructor.
Definition colors:224
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:212
Color_component const & a() const
Return the alpha color compoment of the pixel.
Definition colors:123
void a(Color_component const &c)
Set the alpha color component of the pixel.
Definition colors:187
void g(Color_component const &c)
Set the green color component of the pixel.
Definition colors:175
bool has_alpha() const
Return whether the pixel has an alpha channel.
Definition colors:163
Pixel_info()
Constructor.
Definition colors:198
Color_component const & r() const
Return the red color compoment of the pixel.
Definition colors:105
void bytes_per_pixel(unsigned char bpp)
Set the size of the pixel in bytes.
Definition colors:193
void r(Color_component const &c)
Set the red color component of the pixel.
Definition colors:169
void b(Color_component const &c)
Set the blue color component of the pixel.
Definition colors:181
void dump(OUT &s) const
Dump information on the pixel to a stream.
Definition colors:246
unsigned char bits_per_pixel() const
Number of bits of the pixel.
Definition colors:156
unsigned char bytes_per_pixel() const
Query size of pixel in bytes.
Definition colors:150
Color_component const padding() const
Compute the padding pseudo component.
Definition colors:131
L4 compiler related defines.
#define L4_EXPORT
Attribute to mark functions, variables, and data types as being exported from a library.
Definition compiler.h:210
L4Re C++ Interfaces.
Definition cmd_control:14