separate mono and gray rendering to VRAM on fx-9860G

This commit is contained in:
Lephenixnoir 2020-03-15 12:11:57 +01:00
parent 8af23cf69a
commit 99caef2c81
Signed by: Lephenixnoir
GPG Key ID: 1BBA026E13FC0495
3 changed files with 43 additions and 3 deletions

View File

@ -70,6 +70,8 @@ img_render_vram(sprite, x, y);
`img_render_vram()`, as every other libimg function, accounts for transparent pixels. Only opaque pixels will be copied to VRAM. This makes it very easy to blend images together by just rendering in sequence.
As a quick note, if you have an image with gray pixels on fx-9860G, you need to use `img_render_vram_gray()` instead (with the same parameters). When using `img_render_vram()`, gray pixels will be approximated as black and white.
## Creating and destroying new images
Because our converted sprite is read-only, we can't do much more for now. To start working on transforms and cool animations, we need to create new images that can be written to. There are two ways to do this; the first is to create an empty image of a fixed size, and the second is to duplicate an existing image.

View File

@ -175,13 +175,29 @@ void img_render(img_t src, img_t dst);
VRAM supports both monochrome and gray pixels. This function clips the
rendered image onto the VRAM.
On fx-CG 50, this functions is exactly equivalent to:
This function only renders to black-and-white VRAM. Dark gray and light gray
pixels are replaced by black and while, respectively. To render imges under
the gray engine, use img_render_vram_gray().
On fx-CG 50, this function is exactly equivalent to:
img_render(src, img_at(img_vram(), x, y)).
@src Source image
@x @y Render destination on VRAM */
void img_render_vram(img_t src, int x, int y);
#ifdef FX9860G
/* img_render_vram_gray(): Render a gray image to the VRAM
On fx-9860G, mono and gray rendering code must be separated. This function
is the direct equivalent of img_render_vram(), but it renders to the gray
VRAM and is suitable for gray images.
@src Source image
@x @y Render destination on gray VRAM */
void img_render_vram_gray(img_t src, int x, int y);
#endif
//---
// Geometric transforms

View File

@ -3,6 +3,10 @@
#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;
@ -54,8 +58,26 @@ void img_render_vram(img_t img, int x, int y)
for(int dy = 0; dy < img.height; dy++, px += img.stride)
for(int dx = 0; dx < img.width; dx++)
{
/* TODO: Render using gray? */
dpixel(x+dx, y+dy, px[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 */