mirror of
https://github.com/genodelabs/genode.git
synced 2024-12-21 06:33:31 +00:00
gems: move reusable code to include/gems
This patch makes various utilities that were originally developed for the backdrop application publicly available.
This commit is contained in:
parent
40d92b7cec
commit
0b3efa90c9
@ -11,8 +11,8 @@
|
||||
* under the terms of the GNU General Public License version 2.
|
||||
*/
|
||||
|
||||
#ifndef _CHUNKY_TEXTURE_H_
|
||||
#define _CHUNKY_TEXTURE_H_
|
||||
#ifndef _INCLUDE__GEMS__CHUNKY_TEXTURE_H_
|
||||
#define _INCLUDE__GEMS__CHUNKY_TEXTURE_H_
|
||||
|
||||
#include <os/surface.h>
|
||||
#include <os/attached_ram_dataspace.h>
|
||||
@ -59,4 +59,4 @@ class Chunky_texture : Genode::Attached_ram_dataspace, public Genode::Texture<PT
|
||||
{ }
|
||||
};
|
||||
|
||||
#endif /* _CHUNKY_TEXTURE_H_ */
|
||||
#endif /* _INCLUDE__GEMS__CHUNKY_TEXTURE_H_ */
|
@ -11,8 +11,8 @@
|
||||
* under the terms of the GNU General Public License version 2.
|
||||
*/
|
||||
|
||||
#ifndef _FILE_H_
|
||||
#define _FILE_H_
|
||||
#ifndef _INCLUDE__GEMS__FILE_H_
|
||||
#define _INCLUDE__GEMS__FILE_H_
|
||||
|
||||
/* Genode includes */
|
||||
#include <base/allocator.h>
|
||||
@ -46,5 +46,5 @@ class File
|
||||
Genode::size_t size() const { return _file_size; }
|
||||
};
|
||||
|
||||
#endif /* _FILE_H_ */
|
||||
#endif /* _INCLUDE__GEMS__FILE_H_ */
|
||||
|
@ -11,8 +11,8 @@
|
||||
* under the terms of the GNU General Public License version 2.
|
||||
*/
|
||||
|
||||
#ifndef _PNG_IMAGE_H_
|
||||
#define _PNG_IMAGE_H_
|
||||
#ifndef _INCLUDE__GEMS__PNG_IMAGE_H_
|
||||
#define _INCLUDE__GEMS__PNG_IMAGE_H_
|
||||
|
||||
/* Genode includes */
|
||||
#include <os/texture.h>
|
||||
@ -20,9 +20,9 @@
|
||||
/* libpng include */
|
||||
#include <png.h>
|
||||
|
||||
/* local includes */
|
||||
#include "chunky_texture.h"
|
||||
#include "texture_utils.h"
|
||||
/* gems includes */
|
||||
#include <gems/chunky_texture.h>
|
||||
#include <gems/texture_utils.h>
|
||||
|
||||
class Png_image
|
||||
{
|
||||
@ -178,4 +178,4 @@ class Png_image
|
||||
}
|
||||
};
|
||||
|
||||
#endif /* _PNG_IMAGE_H_ */
|
||||
#endif /* _INCLUDE__GEMS__PNG_IMAGE_H_ */
|
@ -11,10 +11,12 @@
|
||||
* under the terms of the GNU General Public License version 2.
|
||||
*/
|
||||
|
||||
#ifndef _INCLUDE__GEMS__TEXTURE_RGB565_H_
|
||||
#define _INCLUDE__GEMS__TEXTURE_RGB565_H_
|
||||
|
||||
/* Genode includes */
|
||||
#include <os/texture.h>
|
||||
#include <os/pixel_rgb565.h>
|
||||
#include <os/pixel_rgb888.h>
|
||||
#include <util/dither_matrix.h>
|
||||
|
||||
namespace Genode {
|
||||
@ -47,33 +49,6 @@ namespace Genode {
|
||||
dst_alpha[i] = min(a, 255);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
template <>
|
||||
void
|
||||
Texture<Pixel_rgb888>::rgba(unsigned char const *rgba, unsigned len, int y)
|
||||
{
|
||||
if (len > size().w()) len = size().w();
|
||||
if (y < 0 || y >= (int)size().h()) return;
|
||||
|
||||
Pixel_rgb888 *dst_pixel = pixel() + y*size().w();
|
||||
unsigned char *dst_alpha = alpha() ? alpha() + y*size().w() : 0;
|
||||
|
||||
for (unsigned i = 0; i < len; i++) {
|
||||
|
||||
int r = *rgba++;
|
||||
int g = *rgba++;
|
||||
int b = *rgba++;
|
||||
int a = *rgba++;
|
||||
|
||||
dst_pixel[i].rgba(r, g, b);
|
||||
|
||||
if (dst_alpha)
|
||||
dst_alpha[i] = min(a, 255);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
template class Genode::Texture<Genode::Pixel_rgb565>;
|
||||
template class Genode::Texture<Genode::Pixel_rgb888>;
|
||||
#endif /* _INCLUDE__GEMS__TEXTURE_RGB565_H_ */
|
48
repos/gems/include/gems/texture_rgb888.h
Normal file
48
repos/gems/include/gems/texture_rgb888.h
Normal file
@ -0,0 +1,48 @@
|
||||
/*
|
||||
* \brief Support for Genode::Texture
|
||||
* \author Norman Feske
|
||||
* \date 2014-08-14
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (C) 2014 Genode Labs GmbH
|
||||
*
|
||||
* This file is part of the Genode OS framework, which is distributed
|
||||
* under the terms of the GNU General Public License version 2.
|
||||
*/
|
||||
|
||||
#ifndef _INCLUDE__GEMS__TEXTURE_RGB888_H_
|
||||
#define _INCLUDE__GEMS__TEXTURE_RGB888_H_
|
||||
|
||||
/* Genode includes */
|
||||
#include <os/texture.h>
|
||||
#include <os/pixel_rgb888.h>
|
||||
|
||||
namespace Genode {
|
||||
|
||||
template <>
|
||||
void
|
||||
Texture<Pixel_rgb888>::rgba(unsigned char const *rgba, unsigned len, int y)
|
||||
{
|
||||
if (len > size().w()) len = size().w();
|
||||
if (y < 0 || y >= (int)size().h()) return;
|
||||
|
||||
Pixel_rgb888 *dst_pixel = pixel() + y*size().w();
|
||||
unsigned char *dst_alpha = alpha() ? alpha() + y*size().w() : 0;
|
||||
|
||||
for (unsigned i = 0; i < len; i++) {
|
||||
|
||||
int r = *rgba++;
|
||||
int g = *rgba++;
|
||||
int b = *rgba++;
|
||||
int a = *rgba++;
|
||||
|
||||
dst_pixel[i].rgba(r, g, b);
|
||||
|
||||
if (dst_alpha)
|
||||
dst_alpha[i] = min(a, 255);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif /* _INCLUDE__GEMS__TEXTURE_RGB888_H_ */
|
@ -11,8 +11,8 @@
|
||||
* under the terms of the GNU General Public License version 2.
|
||||
*/
|
||||
|
||||
#ifndef _TEXTURE_UTILS_H_
|
||||
#define _TEXTURE_UTILS_H_
|
||||
#ifndef _INCLUDE__GEMS__TEXTURE_UTILS_H_
|
||||
#define _INCLUDE__GEMS__TEXTURE_UTILS_H_
|
||||
|
||||
#include <os/texture.h>
|
||||
|
||||
@ -94,4 +94,4 @@ static void convert_pixel_format(Genode::Texture<SRC_PT> const &src,
|
||||
Genode::env()->heap()->free(row, row_num_bytes);
|
||||
}
|
||||
|
||||
#endif /* _TEXTURE_UTILS_H_ */
|
||||
#endif /* _INCLUDE__GEMS__TEXTURE_UTILS_H_ */
|
@ -11,8 +11,8 @@
|
||||
* under the terms of the GNU General Public License version 2.
|
||||
*/
|
||||
|
||||
#ifndef _XML_ANCHOR_H_
|
||||
#define _XML_ANCHOR_H_
|
||||
#ifndef _INCLUDE__GEMS__XML_ANCHOR_H_
|
||||
#define _INCLUDE__GEMS__XML_ANCHOR_H_
|
||||
|
||||
#include <util/xml_node.h>
|
||||
|
||||
@ -68,4 +68,4 @@ class Anchor
|
||||
}
|
||||
};
|
||||
|
||||
#endif /* _XML_ANCHOR_H_ */
|
||||
#endif /* _INCLUDE__GEMS__XML_ANCHOR_H_ */
|
4
repos/gems/lib/mk/file.mk
Normal file
4
repos/gems/lib/mk/file.mk
Normal file
@ -0,0 +1,4 @@
|
||||
SRC_CC = file.cc
|
||||
LIBS += libc
|
||||
|
||||
vpath file.cc $(REP_DIR)/src/lib/file
|
@ -21,14 +21,14 @@
|
||||
#include <nitpicker_gfx/texture_painter.h>
|
||||
#include <os/attached_dataspace.h>
|
||||
#include <util/volatile_object.h>
|
||||
#include <os/pixel_rgb565.h>
|
||||
#include <os/pixel_rgb888.h>
|
||||
|
||||
/* local includes */
|
||||
#include "png_image.h"
|
||||
#include "file.h"
|
||||
#include "xml_anchor.h"
|
||||
#include "texture_utils.h"
|
||||
/* gems includes */
|
||||
#include <gems/png_image.h>
|
||||
#include <gems/file.h>
|
||||
#include <gems/xml_anchor.h>
|
||||
#include <gems/texture_utils.h>
|
||||
#include <gems/texture_rgb565.h>
|
||||
#include <gems/texture_rgb888.h>
|
||||
|
||||
using namespace Genode;
|
||||
|
||||
|
@ -1,3 +1,3 @@
|
||||
TARGET = backdrop
|
||||
SRC_CC = main.cc file.cc texture.cc
|
||||
LIBS = base config libc libpng zlib blit
|
||||
TARGET = backdrop
|
||||
SRC_CC = main.cc
|
||||
LIBS = base config libc libpng zlib blit file
|
||||
|
@ -14,8 +14,8 @@
|
||||
/* Genode includes */
|
||||
#include <base/printf.h>
|
||||
|
||||
/* local includes */
|
||||
#include "file.h"
|
||||
/* gems includes */
|
||||
#include <gems/file.h>
|
||||
|
||||
/* libc includes */
|
||||
#include <sys/types.h>
|
Loading…
Reference in New Issue
Block a user