From c48a4ebce84f409ed14bc9ebc2fc677060d3604a Mon Sep 17 00:00:00 2001 From: Norman Feske Date: Thu, 11 Sep 2014 16:28:20 +0200 Subject: [PATCH] os: add texture_rgb888.h and texture_rgb565.h The headers 'texture_rgb565.h' and 'texture_rgb888' contain template specializations needed for using the 'Texture::rgba' function for the respective pixel formats. The specializations were formerly contained in application-local code. --- repos/demo/include/scout/canvas.h | 34 +------------------ repos/gems/src/app/backdrop/main.cc | 4 +-- repos/os/include/os/pixel_rgb888.h | 19 +++++++++++ repos/os/include/os/texture.h | 2 +- .../gems => os/include/os}/texture_rgb565.h | 2 +- .../gems => os/include/os}/texture_rgb888.h | 2 +- 6 files changed, 25 insertions(+), 38 deletions(-) rename repos/{gems/include/gems => os/include/os}/texture_rgb565.h (98%) rename repos/{gems/include/gems => os/include/os}/texture_rgb888.h (98%) diff --git a/repos/demo/include/scout/canvas.h b/repos/demo/include/scout/canvas.h index 0b7110311..051754ead 100644 --- a/repos/demo/include/scout/canvas.h +++ b/repos/demo/include/scout/canvas.h @@ -70,42 +70,10 @@ struct Scout::Canvas_base : Texture_allocator }; -#include +#include #include -namespace Genode { - - template <> - inline void - Texture::rgba(unsigned char const *rgba, unsigned len, int y) - { - if (len > size().w()) len = size().w(); - if (y < 0 || y >= (int)size().h()) return; - - Genode::Pixel_rgb565 *dst_pixel = pixel() + y*size().w(); - unsigned char *dst_alpha = alpha() ? alpha() + y*size().w() : 0; - - Genode::Dither_matrix::Row dither_row = Dither_matrix::row(y); - - for (unsigned i = 0; i < len; i++) { - - int v = dither_row.value(i) >> 5; - int r = *rgba++ + v; - int g = *rgba++ + v; - int b = *rgba++ + v; - int a = *rgba++ + v; - - using Genode::min; - dst_pixel[i].rgba(min(r, 255), min(g, 255), min(b, 255)); - - if (dst_alpha) - dst_alpha[i] = min(a, 255); - } - } -} - - template class Scout::Canvas : public Canvas_base { diff --git a/repos/gems/src/app/backdrop/main.cc b/repos/gems/src/app/backdrop/main.cc index d542f1da4..9c9dac131 100644 --- a/repos/gems/src/app/backdrop/main.cc +++ b/repos/gems/src/app/backdrop/main.cc @@ -21,14 +21,14 @@ #include #include #include +#include +#include /* gems includes */ #include #include #include #include -#include -#include using namespace Genode; diff --git a/repos/os/include/os/pixel_rgb888.h b/repos/os/include/os/pixel_rgb888.h index 7bacf2c64..f0101b613 100644 --- a/repos/os/include/os/pixel_rgb888.h +++ b/repos/os/include/os/pixel_rgb888.h @@ -21,6 +21,25 @@ namespace Genode { typedef Pixel_rgba Pixel_rgb888; + + template <> + inline Pixel_rgb888 Pixel_rgb888::blend(Pixel_rgb888 src, int alpha) + { + Pixel_rgb888 res; + res.pixel = (alpha * ((src.pixel & 0xff00) >> 8) & 0xff00) + | (((alpha * (src.pixel & 0xff00ff)) >> 8) & 0xff00ff); + return res; + } + + + template <> + inline Pixel_rgb888 Pixel_rgb888::mix(Pixel_rgb888 p1, Pixel_rgb888 p2, int alpha) + { + Pixel_rgb888 res; + + res.pixel = blend(p1, 255 - alpha).pixel + blend(p2, alpha).pixel; + return res; + } } #endif /* _INCLUDE__OS__PIXEL_RGB888_H_ */ diff --git a/repos/os/include/os/texture.h b/repos/os/include/os/texture.h index e0dce24f4..4453c2d53 100644 --- a/repos/os/include/os/texture.h +++ b/repos/os/include/os/texture.h @@ -57,7 +57,7 @@ class Genode::Texture : public Texture_base /** * Import rgba data line into texture */ - void rgba(unsigned char const *rgba, unsigned len, int y); + inline void rgba(unsigned char const *rgba, unsigned len, int y); }; #endif /* _INCLUDE__OS__TEXTURE_H_ */ diff --git a/repos/gems/include/gems/texture_rgb565.h b/repos/os/include/os/texture_rgb565.h similarity index 98% rename from repos/gems/include/gems/texture_rgb565.h rename to repos/os/include/os/texture_rgb565.h index 7159980eb..46b243d53 100644 --- a/repos/gems/include/gems/texture_rgb565.h +++ b/repos/os/include/os/texture_rgb565.h @@ -22,7 +22,7 @@ namespace Genode { template <> - void + inline void Texture::rgba(unsigned char const *rgba, unsigned len, int y) { if (len > size().w()) len = size().w(); diff --git a/repos/gems/include/gems/texture_rgb888.h b/repos/os/include/os/texture_rgb888.h similarity index 98% rename from repos/gems/include/gems/texture_rgb888.h rename to repos/os/include/os/texture_rgb888.h index 8a0a79ffb..32435e0ce 100644 --- a/repos/gems/include/gems/texture_rgb888.h +++ b/repos/os/include/os/texture_rgb888.h @@ -21,7 +21,7 @@ namespace Genode { template <> - void + inline void Texture::rgba(unsigned char const *rgba, unsigned len, int y) { if (len > size().w()) len = size().w();