os: improve alpha-channel support for Pixel_rgba

This patch add an optional alpha argument to the constructor, which may
be passed to a pixel type representing an alpha channel. Furthermore,
a new overload of the mix function has been added to accommodate use
cases where one texture is applied to both a pixel surface and an alpha
channel.
This commit is contained in:
Norman Feske 2014-09-12 20:22:51 +02:00
parent b01c74ae12
commit 40d92b7cec
1 changed files with 15 additions and 2 deletions

View File

@ -59,10 +59,11 @@ class Genode::Pixel_rgba
*/
Pixel_rgba() {}
Pixel_rgba(int red, int green, int blue) :
Pixel_rgba(int red, int green, int blue, int alpha = 255) :
pixel((_shift(red, r_shift) & r_mask)
| (_shift(green, g_shift) & g_mask)
| (_shift(blue, b_shift) & b_mask)) { }
| (_shift(blue, b_shift) & b_mask)
| (_shift(alpha, a_shift) & a_mask)) { }
static Surface_base::Pixel_format format() { return FORMAT; }
@ -80,6 +81,7 @@ class Genode::Pixel_rgba
inline int r() const { return _shift(pixel & r_mask, -r_shift); }
inline int g() const { return _shift(pixel & g_mask, -g_shift); }
inline int b() const { return _shift(pixel & b_mask, -b_shift); }
inline int a() const { return _shift(pixel & a_mask, -a_shift); }
/**
* Compute average color value of two pixels
@ -96,6 +98,17 @@ class Genode::Pixel_rgba
*/
static inline Pixel_rgba mix(Pixel_rgba p1, Pixel_rgba p2, int alpha);
/**
* Mix two pixels where p2 may be of a different pixel format
*
* This is useful for drawing operations that apply the same texture
* to a pixel surface as well as an alpha surface. When drawing on the
* alpha surface, 'p1' will be of type 'Pixel_alpha8' whereas 'p2'
* corresponds to the pixel type of the texture.
*/
template <typename PT>
static inline Pixel_rgba mix(Pixel_rgba p1, PT p2, int alpha);
/**
* Compute average color value of four pixels
*/