bopti: expose bopti functions and implement dimage() and dimage_opt()

This commit is contained in:
lephe 2019-05-04 21:00:40 +02:00
parent 9b24267488
commit 81baa4c26a
5 changed files with 92 additions and 34 deletions

View file

@ -27,4 +27,24 @@ void masks(int x1, int x2, uint32_t *masks);
/* Font currently configured for text rendering */
extern font_t const * topti_font;
/* bopti_render_clip() - render a bopti image with clipping
@x @y Location of the top-left corner
@img Image encoded by [fxconv]
@left @top @w @h Bounding box to render */
void bopti_render_clip(int x, int y, image_t const *img, int left, int top,
int w, int h);
/* bopti_render_noclip() - render a bopti image without clipping
This function is only ever slightly faster than bopti_render_clip(),
eliminating two types of coordinate checks:
1. The bounding box does not overflow from the image
2. The final rendering does not overflow from the screen
@x @y Location of the top-left corner
@img Image encoded by [fxconv]
@left @top @w @h Bounding box to render */
void bopti_render_noclip(int x, int y, image_t const *img, int left, int top,
int w, int h);
#endif /* DISPLAY_FX */

View file

@ -134,6 +134,33 @@ 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 dimage_opt() 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 dimage_opt() */
enum {
/* 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,
};
/* dimage_opt() - 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 */
void dimage_opt(int x, int y, image_t const *image, int left, int top,
int width, int height, int flags);
//---
// Text rendering (topti)
//---

View file

@ -52,7 +52,7 @@ struct command
/* Ignored elements between two rendered grid rows */
int vram_stride;
/* Ignored elements between two columns rendered grid columns */
/* Ignored elements between two rendered grid columns */
int data_stride;
/* Assembly function, prototype depends on image type */

25
src/render-fx/dimage.c Normal file
View file

@ -0,0 +1,25 @@
#include <gint/display.h>
#include <display/fx.h>
/* dimage() - render a full image */
void dimage(int x, int y, image_t const *img)
{
if(img->gray) return;
bopti_render_clip(x, y, img, 0, 0, img->width, img->height);
}
/* dimage_opt() - render a section of an image */
void dimage_opt(int x, int y, image_t const *img, int left, int top,
int width, int height, int flags)
{
if(img->gray) return;
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);
}
}

View file

@ -23,39 +23,25 @@ void drect(int x1, int y1, int x2, int y2, color_t color)
uint32_t *base = vram + (y1 << 2);
uint32_t *lword = vram + (y2 << 2) + 4;
switch(color)
if(color == color_white) while(lword > base)
{
case color_white:
while(lword > base)
{
*--lword &= ~m[3];
*--lword &= ~m[2];
*--lword &= ~m[1];
*--lword &= ~m[0];
}
break;
case color_black:
while(lword > base)
{
*--lword |= m[3];
*--lword |= m[2];
*--lword |= m[1];
*--lword |= m[0];
}
break;
case color_reverse:
while(lword > base)
{
*--lword ^= m[3];
*--lword ^= m[2];
*--lword ^= m[1];
*--lword ^= m[0];
}
break;
/* Other colors are unsupported */
default: return;
*--lword &= ~m[3];
*--lword &= ~m[2];
*--lword &= ~m[1];
*--lword &= ~m[0];
}
else if(color == color_black) while(lword > base)
{
*--lword |= m[3];
*--lword |= m[2];
*--lword |= m[1];
*--lword |= m[0];
}
else if(color == color_reverse) while(lword > base)
{
*--lword ^= m[3];
*--lword ^= m[2];
*--lword ^= m[1];
*--lword ^= m[0];
}
}