From 652637d47565870dd4a87dd07c3594bf3040b94d Mon Sep 17 00:00:00 2001 From: lephe Date: Tue, 27 Aug 2019 21:04:07 +0200 Subject: [PATCH] bopti: add support for r5g6b5 and r5g6b5a on fxcg50 This commit introduces bopti for fxcg50 with the first basic 16-bit formats. The performance is rather slow, especially for large images, and will need refinements and/or overclock to be really efficient in full-screen real-time applications. --- include/gint/display-fx.h | 31 ------------------------------- include/gint/display.h | 37 +++++++++++++++++++++++++++++++++++++ src/render-cg/bopti-asm.h | 12 ++++++++++++ src/render-cg/dimage.c | 23 +++++++++++++++++++++++ 4 files changed, 72 insertions(+), 31 deletions(-) create mode 100644 src/render-cg/dimage.c diff --git a/include/gint/display-fx.h b/include/gint/display-fx.h index eb0a6b3..f7ef95c 100644 --- a/include/gint/display-fx.h +++ b/include/gint/display-fx.h @@ -81,37 +81,6 @@ typedef struct } GPACKED(4) image_t; -/* dimage() - render a full image - This function blits an image on the VRAM using gint's special format. It is - a special case of dsubimage() where the full image is drawn with clipping. - - @x @y Coordinates of the top-left corner of the image - @image Pointer to image encoded with [fxconv] */ -void dimage(int x, int y, image_t const *image); - -/* Option values for dsubimage() */ -enum { - /* No option */ - DIMAGE_NONE = 0x00, - - /* Disable clipping, ie. adjustments to the specified subrectangle and - screen location such that any part that overflows from the image or - the screen is ignored. Slightly faster. */ - DIMAGE_NOCLIP = 0x01, -}; - -/* dsubimage() - render a section of an image - This function blits a subrectangle [left, top, width, height] of an image on - the VRAM. It is more general than dimage() and also provides a few options. - - @x @y Coordinates on screen of the rendered subrectangle - @image Pointer to image encoded with [fxconv] - @left @top Top-left coordinates of the subrectangle within [image] - @width @height Subrectangle dimensions - @flags OR-combination of DIMAGE_* flags */ -void dsubimage(int x, int y, image_t const *image, int left, int top, - int width, int height, int flags); - #endif /* FX9860G */ #endif /* GINT_DISPLAY_FX */ diff --git a/include/gint/display.h b/include/gint/display.h index eb5c97e..177c879 100644 --- a/include/gint/display.h +++ b/include/gint/display.h @@ -199,6 +199,43 @@ void dsize(const char *str, font_t const * font, int *w, int *h); fxcg50: Any R5G6B5 color, or C_NONE */ void dtext(int x, int y, const char *str, int fg, int bg); +//--- +// Image rendering (bopti) +//--- + +/* The image_t structure is platform-dependent. */ + +/* dimage() - render a full image + This function blits an image on the VRAM using gint's special format. It is + a special case of dsubimage() where the full image is drawn with clipping. + + @x @y Coordinates of the top-left corner of the image + @image Pointer to image encoded with [fxconv] */ +void dimage(int x, int y, image_t const *image); + +/* Option values for dsubimage() */ +enum { + /* No option */ + DIMAGE_NONE = 0x00, + + /* Disable clipping, ie. adjustments to the specified subrectangle and + screen location such that any part that overflows from the image or + the screen is ignored. Slightly faster. */ + DIMAGE_NOCLIP = 0x01, +}; + +/* dsubimage() - render a section of an image + This function blits a subrectangle [left, top, width, height] of an image on + the VRAM. It is more general than dimage() and also provides a few options. + + @x @y Coordinates on screen of the rendered subrectangle + @image Pointer to image encoded with [fxconv] + @left @top Top-left coordinates of the subrectangle within [image] + @width @height Subrectangle dimensions + @flags OR-combination of DIMAGE_* flags */ +void dsubimage(int x, int y, image_t const *image, int left, int top, + int width, int height, int flags); + //--- // Advanced functions //--- diff --git a/src/render-cg/bopti-asm.h b/src/render-cg/bopti-asm.h index 04d3096..71cbbde 100644 --- a/src/render-cg/bopti-asm.h +++ b/src/render-cg/bopti-asm.h @@ -22,4 +22,16 @@ void bopti_r5g6b5(uint16_t const *data, uint16_t *target, int width, void bopti_r5g6b5a(uint16_t const *data, uint16_t *target, int width, int height, int in_stride, int out_stride, uint16_t alpha); +/* bopti_render_clip(): Render with clipping + Same parameters as dsubimage(), except for flags. */ +void bopti_render_clip(int x, int y, image_t const *img, int left, int top, + int width, int height); + +/* bopti_render_clip(): Render without clipping + Behaviour is not defined if (left,top)+(width,height) is not included in the + source image or (x,y)+(width,height) is not included in the VRAM area. + Same parameters as dsubimage(), except for flags. */ +void bopti_render_noclip(int x, int y, image_t const *img, int left, int top, + int width, int height); + #endif /* GINT_RENDERCG_BOPTIASM */ diff --git a/src/render-cg/dimage.c b/src/render-cg/dimage.c new file mode 100644 index 0000000..94e7dcc --- /dev/null +++ b/src/render-cg/dimage.c @@ -0,0 +1,23 @@ +#define GINT_NEED_VRAM +#include +#include "bopti-asm.h" + +/* dimage() - render a full image */ +void dimage(int x, int y, image_t const *img) +{ + bopti_render_clip(x, y, img, 0, 0, img->width, img->height); +} + +/* dsubimage() - render a section of an image */ +void dsubimage(int x, int y, image_t const *img, int left, int top, + int width, int height, int flags) +{ + if(flags & DIMAGE_NOCLIP) + { + bopti_render_noclip(x, y, img, left, top, width, height); + } + else + { + bopti_render_clip(x, y, img, left, top, width, height); + } +}