libimg/src/render.c

91 lines
1.8 KiB
C

#include <libimg.h>
#include "libimg-internal.h"
#include <gint/display.h>
#ifdef FX9860G
#include <gint/gray.h>
#endif
void img_fill(img_t img, img_pixel_t color)
{
img_pixel_t *px = img.pixels;
for(int y = 0; y < img.height; y++, px += img.stride)
for(int x = 0; x < img.width; x++)
{
px[x] = color;
}
}
void img_clear(img_t img)
{
img_fill(img, IMG_ALPHA);
}
void img_render(img_t src, img_t dst)
{
if(img_null(src) || img_null(dst) || dst.flags & FLAG_RO) return;
/* Clip the rectangle */
if(src.width > dst.width)
src = img_sub(src, 0, 0, dst.width, -1);
if(src.height > dst.height)
src = img_sub(src, 0, 0, -1, dst.height);
/* Copy pixels */
img_pixel_t *src_px = src.pixels;
img_pixel_t *dst_px = dst.pixels;
for(int dy = 0; dy < src.height; dy++)
{
for(int dx = 0; dx < src.width; dx++)
{
if(src_px[dx] != IMG_ALPHA)
dst_px[dx] = src_px[dx];
}
src_px += src.stride;
dst_px += dst.stride;
}
}
#ifdef FX9860G
void img_render_vram(img_t img, int x, int y)
{
img_pixel_t *px = img.pixels;
for(int dy = 0; dy < img.height; dy++, px += img.stride)
for(int dx = 0; dx < img.width; dx++)
{
img_pixel_t c = px[dx];
/* Provide a mildly useful approximation of gray rendering.
Seeing the black-and-white approximation might make it more
explicit to the user that mono rendering has been used,
rather than rendering nothing */
if(c == C_DARK) c = C_BLACK;
if(c == C_LIGHT) c = C_WHITE;
dpixel(x+dx, y+dy, c);
}
}
void img_render_vram_gray(img_t img, int x, int y)
{
img_pixel_t *px = img.pixels;
for(int dy = 0; dy < img.height; dy++, px += img.stride)
for(int dx = 0; dx < img.width; dx++)
{
gpixel(x+dx, y+dy, px[dx]);
}
}
#endif /* FX9860G */
#ifdef FXCG50
void img_render_vram(img_t img, int x, int y)
{
img_render(img, img_at(img_vram(), x, y));
}
#endif /* FXCG50 */