mirror of
https://github.com/genodelabs/genode.git
synced 2024-12-21 22:47:50 +00:00
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.
This commit is contained in:
parent
0b3efa90c9
commit
c48a4ebce8
@ -70,42 +70,10 @@ struct Scout::Canvas_base : Texture_allocator
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
#include <os/pixel_rgb565.h>
|
#include <os/texture_rgb565.h>
|
||||||
#include <base/env.h>
|
#include <base/env.h>
|
||||||
|
|
||||||
|
|
||||||
namespace Genode {
|
|
||||||
|
|
||||||
template <>
|
|
||||||
inline void
|
|
||||||
Texture<Pixel_rgb565>::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 <typename PT>
|
template <typename PT>
|
||||||
class Scout::Canvas : public Canvas_base
|
class Scout::Canvas : public Canvas_base
|
||||||
{
|
{
|
||||||
|
@ -21,14 +21,14 @@
|
|||||||
#include <nitpicker_gfx/texture_painter.h>
|
#include <nitpicker_gfx/texture_painter.h>
|
||||||
#include <os/attached_dataspace.h>
|
#include <os/attached_dataspace.h>
|
||||||
#include <util/volatile_object.h>
|
#include <util/volatile_object.h>
|
||||||
|
#include <os/texture_rgb565.h>
|
||||||
|
#include <os/texture_rgb888.h>
|
||||||
|
|
||||||
/* gems includes */
|
/* gems includes */
|
||||||
#include <gems/png_image.h>
|
#include <gems/png_image.h>
|
||||||
#include <gems/file.h>
|
#include <gems/file.h>
|
||||||
#include <gems/xml_anchor.h>
|
#include <gems/xml_anchor.h>
|
||||||
#include <gems/texture_utils.h>
|
#include <gems/texture_utils.h>
|
||||||
#include <gems/texture_rgb565.h>
|
|
||||||
#include <gems/texture_rgb888.h>
|
|
||||||
|
|
||||||
using namespace Genode;
|
using namespace Genode;
|
||||||
|
|
||||||
|
@ -21,6 +21,25 @@ namespace Genode {
|
|||||||
typedef Pixel_rgba<unsigned long, Surface_base::RGB888,
|
typedef Pixel_rgba<unsigned long, Surface_base::RGB888,
|
||||||
0xff0000, 16, 0xff00, 8, 0xff, 0, 0, 0>
|
0xff0000, 16, 0xff00, 8, 0xff, 0, 0, 0>
|
||||||
Pixel_rgb888;
|
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_ */
|
#endif /* _INCLUDE__OS__PIXEL_RGB888_H_ */
|
||||||
|
@ -57,7 +57,7 @@ class Genode::Texture : public Texture_base
|
|||||||
/**
|
/**
|
||||||
* Import rgba data line into texture
|
* 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_ */
|
#endif /* _INCLUDE__OS__TEXTURE_H_ */
|
||||||
|
@ -22,7 +22,7 @@
|
|||||||
namespace Genode {
|
namespace Genode {
|
||||||
|
|
||||||
template <>
|
template <>
|
||||||
void
|
inline void
|
||||||
Texture<Pixel_rgb565>::rgba(unsigned char const *rgba, unsigned len, int y)
|
Texture<Pixel_rgb565>::rgba(unsigned char const *rgba, unsigned len, int y)
|
||||||
{
|
{
|
||||||
if (len > size().w()) len = size().w();
|
if (len > size().w()) len = size().w();
|
@ -21,7 +21,7 @@
|
|||||||
namespace Genode {
|
namespace Genode {
|
||||||
|
|
||||||
template <>
|
template <>
|
||||||
void
|
inline void
|
||||||
Texture<Pixel_rgb888>::rgba(unsigned char const *rgba, unsigned len, int y)
|
Texture<Pixel_rgb888>::rgba(unsigned char const *rgba, unsigned len, int y)
|
||||||
{
|
{
|
||||||
if (len > size().w()) len = size().w();
|
if (len > size().w()) len = size().w();
|
Loading…
Reference in New Issue
Block a user