gfx_sprite_draw(): a run-length encoded image with 4-bit alpha, blended onto a canvas. See include/gfx_sprite.h.
More...
#include "gfx_sprite.h"
#include "gfx_int.h"
#include "gfx_work.h"
#include <string.h>
|
| #define | KEEP(a) |
| | The destination's weight under alpha a, in 32nds, rounded down: floor(32 x (15 - a) / 15).
|
|
| static gfx_color_t | blend (gfx_color_t dst, gfx_color_t src, unsigned a) |
| | One partly covered pixel: src, premultiplied, over dst.
|
|
static gfx_color_t | rd16 (const uint8_t *p) |
| | A little-endian 16-bit value at p.
|
| bool | gfx_sprite_draw (gfx_canvas_t *c, int x, int y, const gfx_sprite_t *sp) |
| | Blend sp onto c with its top-left corner at (x, y).
|
|
| static const uint8_t | k_keep [16] |
| | KEEP() for every alpha, 0 to 15.
|
gfx_sprite_draw(): a run-length encoded image with 4-bit alpha, blended onto a canvas. See include/gfx_sprite.h.
SPDX-License-Identifier: MIT
◆ KEEP
Value:((uint8_t)((32u * (15u - (a))) / 15u))
The destination's weight under alpha a, in 32nds, rounded down: floor(32 x (15 - a) / 15).
◆ blend()
| gfx_color_t blend |
( |
gfx_color_t | dst, |
|
|
gfx_color_t | src, |
|
|
unsigned | a ) |
|
inlinestatic |
One partly covered pixel: src, premultiplied, over dst.
The three channels are spread over a 32-bit word with room above each (green in bits 21 to 26, red 11 to 15, blue 0 to 4), scaled by one multiply and folded back. The weight is rounded down, so src plus the scaled dst stays within each channel and nothing carries.
- Parameters
-
| dst | the pixel under it |
| src | the sprite's pixel, premultiplied by its alpha |
| a | its alpha, 1 to 14 of 15 |
- Returns
- the blended pixel
◆ gfx_sprite_draw()
Blend sp onto c with its top-left corner at (x, y).
Stops at the end of the table, or at a run that would cross the end of its row, so a short or damaged table draws less and reads nothing past its bytes.
- Parameters
-
| c | the canvas |
| x | the sprite's left edge on the canvas |
| y | its top edge |
| sp | the sprite, or NULL for none |
- Returns
- true when the whole table was read, row by row, to its last byte; false for NULL, an empty sprite or a table that does not hold w x h pixels in exactly
bytes
◆ k_keep
Initial value: = {
}
#define KEEP(a)
The destination's weight under alpha a, in 32nds, rounded down: floor(32 x (15 - a) / 15).
Definition gfx_sprite.c:18
KEEP() for every alpha, 0 to 15.