From ebd9f36b0db9438e5529aef8a54d31676b2ecace Mon Sep 17 00:00:00 2001 From: Norman Feske Date: Sat, 9 Mar 2019 17:27:24 +0100 Subject: [PATCH] os: Pixel_rgba::transfer interface The new 'transfer' function interface defines how pixel/alpha values sampled from texture are applied to a destination pixel, similar to the role of a fragment shader in GPU-based rendering. The transfer function can be customized by defining custom pixel types, which may be (but don't need to be) derived from 'Pixel_rgba'. Issue #3221 --- repos/os/include/os/pixel_rgba.h | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/repos/os/include/os/pixel_rgba.h b/repos/os/include/os/pixel_rgba.h index e3fc986c5c..8e27cffe5a 100644 --- a/repos/os/include/os/pixel_rgba.h +++ b/repos/os/include/os/pixel_rgba.h @@ -116,6 +116,23 @@ class Genode::Pixel_rgba Pixel_rgba p3, Pixel_rgba p4) { return avr(avr(p1, p2), avr(p3, p4)); } + /** + * Copy pixel with alpha + * + * \param src source color value (e.g., obtained from a texture) + * \param src_a alpha value corresponding to the 'src' pixel + * \param alpha alpha value + * \param dst destination pixel + */ + template + static void transfer(TPT const &src, int src_a, int alpha, PT &dst) + { + if (src_a) { + int register a = (src_a * alpha)>>8; + if (a) dst = PT::mix(dst, src, a); + } + } + /** * Return alpha value of pixel */