rcbench
Servo and ESC test bench: panel, IOmcu and shared C
Loading...
Searching...
No Matches
gfx_sprite.c File Reference

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>

Macros

#define KEEP(a)
 The destination's weight under alpha a, in 32nds, rounded down: floor(32 x (15 - a) / 15).

Functions

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).

Variables

static const uint8_t k_keep [16]
 KEEP() for every alpha, 0 to 15.

Detailed Description

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

Macro Definition Documentation

◆ KEEP

#define KEEP ( a)
Value:
((uint8_t)((32u * (15u - (a))) / 15u))

The destination's weight under alpha a, in 32nds, rounded down: floor(32 x (15 - a) / 15).

Function Documentation

◆ 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
dstthe pixel under it
srcthe sprite's pixel, premultiplied by its alpha
aits alpha, 1 to 14 of 15
Returns
the blended pixel

◆ gfx_sprite_draw()

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).

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
cthe canvas
xthe sprite's left edge on the canvas
yits top edge
spthe 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

Variable Documentation

◆ k_keep

const uint8_t k_keep[16]
static
Initial value:
= {
KEEP(0), KEEP(1), KEEP(2), KEEP(3), KEEP(4), KEEP(5),
KEEP(6), KEEP(7), KEEP(8), KEEP(9), KEEP(10), KEEP(11),
KEEP(12), KEEP(13), KEEP(14), KEEP(15),
}
#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.