2020-03-09 18:13:32 +01:00
|
|
|
#include <libimg.h>
|
|
|
|
#include "libimg-internal.h"
|
|
|
|
|
|
|
|
#include <gint/display.h>
|
|
|
|
|
2020-03-15 12:11:57 +01:00
|
|
|
#ifdef FX9860G
|
|
|
|
#include <gint/gray.h>
|
|
|
|
#endif
|
|
|
|
|
2020-03-09 18:13:32 +01:00
|
|
|
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
|
2020-03-09 19:09:15 +01:00
|
|
|
void img_render_vram(img_t img, int x, int y)
|
2020-03-09 18:13:32 +01:00
|
|
|
{
|
|
|
|
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++)
|
|
|
|
{
|
2020-03-15 12:11:57 +01:00
|
|
|
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++)
|
|
|
|
{
|
2021-04-27 15:51:49 +02:00
|
|
|
dpixel(x+dx, y+dy, px[dx]);
|
2020-03-09 18:13:32 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
#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 */
|