Loading...
Searching...
No Matches
colors
// vi:set ft=cpp: -*- Mode: C++ -*-
/*
* (c) 2008-2009 Adam Lackorzynski <adam@os.inf.tu-dresden.de>,
* Alexander Warg <warg@os.inf.tu-dresden.de>
* economic rights: Technische Universität Dresden (Germany)
*
* License: see LICENSE.spdx (in this directory or the directories above)
*/
#pragma once
#include <l4/sys/compiler.h>
#include <l4/cxx/minmax>
namespace L4Re { namespace Video {
class L4_EXPORT Color_component
{
private:
unsigned char _bits;
unsigned char _shift;
public:
Color_component() : _bits(0), _shift(0) {}
Color_component(unsigned char bits, unsigned char shift)
: _bits(bits), _shift(shift) {}
unsigned char size() const { return _bits; }
unsigned char shift() const { return _shift; }
bool operator == (Color_component const &o) const
{ return _shift == o._shift && _bits == o._bits; }
int get(unsigned long v) const
{
return ((v >> _shift) & ~(~0UL << _bits)) << (16UL - _bits);
}
long unsigned set(int v) const
{ return (static_cast<unsigned long>(v) >> (16UL - _bits)) << _shift; }
template< typename OUT >
void dump(OUT &s) const
{
s.printf("%d(%d)", static_cast<int>(size()), static_cast<int>(shift()));
}
} __attribute__((packed));
class L4_EXPORT Pixel_info
{
private:
Color_component _r, _g, _b, _a;
unsigned char _bpp;
public:
Color_component const &r() const { return _r; }
Color_component const &g() const { return _g; }
Color_component const &b() const { return _b; }
Color_component const &a() const { return _a; }
Color_component const padding() const
{
unsigned char top_bit = cxx::max<unsigned char>(_r.size() + _r.shift(),
_g.size() + _g.shift());
top_bit = cxx::max<unsigned char>(top_bit, _b.size() + _b.shift());
top_bit = cxx::max<unsigned char>(top_bit, _a.size() + _a.shift());
unsigned char bits = _bpp * 8;
if (top_bit < bits)
return Color_component(bits - top_bit, top_bit);
return Color_component(0, 0);
}
unsigned char bytes_per_pixel() const { return _bpp; }
unsigned char bits_per_pixel() const
{ return _r.size() + _g.size() + _b.size() + _a.size(); }
bool has_alpha() const { return _a.size() > 0; }
void r(Color_component const &c) { _r = c; }
void g(Color_component const &c) { _g = c; }
void b(Color_component const &c) { _b = c; }
void a(Color_component const &c) { _a = c; }
void bytes_per_pixel(unsigned char bpp) { _bpp = bpp; }
Pixel_info() : _bpp(0) {};
Pixel_info(unsigned char bpp, char r, char rs, char g, char gs,
char b, char bs, char a = 0, char as = 0)
: _r(r, rs), _g(g, gs), _b(b, bs), _a(a, as), _bpp(bpp)
{}
template<typename VBI>
explicit Pixel_info(VBI const *vbi)
: _r(vbi->red_mask_size, vbi->red_field_position),
_g(vbi->green_mask_size, vbi->green_field_position),
_b(vbi->blue_mask_size, vbi->blue_field_position),
_bpp((vbi->bits_per_pixel + 7) / 8)
{}
bool operator == (Pixel_info const &o) const
{
return _r == o._r && _g == o._g && _b == o._b && _a == o._a && _bpp == o._bpp;
}
template< typename OUT >
void dump(OUT &s) const
{
s.printf("RGBA(%d):%d(%d):%d(%d):%d(%d):%d(%d)",
static_cast<int>(bytes_per_pixel()),
static_cast<int>(r().size()), static_cast<int>(r().shift()),
static_cast<int>(g().size()), static_cast<int>(g().shift()),
static_cast<int>(b().size()), static_cast<int>(b().shift()),
static_cast<int>(a().size()), static_cast<int>(a().shift()));
}
};
}}
L4Re::Video::Color_component
A color component.
Definition colors:22
L4Re::Video::Color_component::dump
void dump(OUT &s) const
Dump information on the view information to a stream.
Definition colors:81
L4Re::Video::Color_component::set
long unsigned set(int v) const
Transform 16bit normalized value to the component in the color space.
Definition colors:73
L4Re::Video::Color_component::size
unsigned char size() const
Return the number of bits used by the component.
Definition colors:43
L4Re::Video::Color_component::Color_component
Color_component()
Constructor.
Definition colors:29
L4Re::Video::Color_component::get
int get(unsigned long v) const
Get component from value (normalized to 16bits).
Definition colors:63
L4Re::Video::Color_component::Color_component
Color_component(unsigned char bits, unsigned char shift)
Constructor.
Definition colors:36
L4Re::Video::Color_component::shift
unsigned char shift() const
Return the position of the component in the pixel.
Definition colors:49
L4Re::Video::Pixel_info::g
Color_component const & g() const
Return the green color compoment of the pixel.
Definition colors:111
L4Re::Video::Pixel_info::b
Color_component const & b() const
Return the blue color compoment of the pixel.
Definition colors:117
L4Re::Video::Pixel_info::Pixel_info
Pixel_info(VBI const *vbi)
Convenience constructor.
Definition colors:224
L4Re::Video::Pixel_info::Pixel_info
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
L4Re::Video::Pixel_info::a
Color_component const & a() const
Return the alpha color compoment of the pixel.
Definition colors:123
L4Re::Video::Pixel_info::a
void a(Color_component const &c)
Set the alpha color component of the pixel.
Definition colors:187
L4Re::Video::Pixel_info::g
void g(Color_component const &c)
Set the green color component of the pixel.
Definition colors:175
L4Re::Video::Pixel_info::has_alpha
bool has_alpha() const
Return whether the pixel has an alpha channel.
Definition colors:163
L4Re::Video::Pixel_info::Pixel_info
Pixel_info()
Constructor.
Definition colors:198
L4Re::Video::Pixel_info::r
Color_component const & r() const
Return the red color compoment of the pixel.
Definition colors:105
L4Re::Video::Pixel_info::bytes_per_pixel
void bytes_per_pixel(unsigned char bpp)
Set the size of the pixel in bytes.
Definition colors:193
L4Re::Video::Pixel_info::r
void r(Color_component const &c)
Set the red color component of the pixel.
Definition colors:169
L4Re::Video::Pixel_info::b
void b(Color_component const &c)
Set the blue color component of the pixel.
Definition colors:181
L4Re::Video::Pixel_info::dump
void dump(OUT &s) const
Dump information on the pixel to a stream.
Definition colors:246
L4Re::Video::Pixel_info::bits_per_pixel
unsigned char bits_per_pixel() const
Number of bits of the pixel.
Definition colors:156
L4Re::Video::Pixel_info::bytes_per_pixel
unsigned char bytes_per_pixel() const
Query size of pixel in bytes.
Definition colors:150
L4Re::Video::Pixel_info::padding
Color_component const padding() const
Compute the padding pseudo component.
Definition colors:131
compiler.h
L4 compiler related defines.
L4_EXPORT
#define L4_EXPORT
Attribute to mark functions, variables, and data types as being exported from a library.
Definition compiler.h:214
L4Re
L4Re C++ Interfaces.
Definition cmd_control:14