From 40d92b7cec8f5d4c352d71fcd00d45d83565043f Mon Sep 17 00:00:00 2001 From: Norman Feske Date: Fri, 12 Sep 2014 20:22:51 +0200 Subject: [PATCH] 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. --- repos/os/include/os/pixel_rgba.h | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/repos/os/include/os/pixel_rgba.h b/repos/os/include/os/pixel_rgba.h index 82a045daa..d5af43249 100644 --- a/repos/os/include/os/pixel_rgba.h +++ b/repos/os/include/os/pixel_rgba.h @@ -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 + static inline Pixel_rgba mix(Pixel_rgba p1, PT p2, int alpha); + /** * Compute average color value of four pixels */