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

gfx's anti-aliased disc, capsule and ring placed in fractions of a pixel. More...

#include "gfx.h"

Go to the source code of this file.

Functions

void gfx_fill_circle_aaf (gfx_canvas_t *c, float cx, float cy, float r, gfx_color_t col)
 A disc of radius r centred on (cx, cy), anti-aliased from each pixel's distance to the centre.
void gfx_capsule_aaf (gfx_canvas_t *c, float ax, float ay, float bx, float by, float thickness, gfx_color_t col)
 A capsule, a thick line with round ends, from (ax, ay) to (bx, by), anti-aliased from each pixel's distance to its spine.
void gfx_ring_aaf (gfx_canvas_t *c, float cx, float cy, float r, float thickness, float a0_deg, float a1_deg, gfx_color_t col, gfx_color_t into, float fade_deg)
 A ring, or an arc of one, solved per pixel from its distance and direction to the centre.

Detailed Description

gfx's anti-aliased disc, capsule and ring placed in fractions of a pixel.

The whole-pixel shapes of gfx.h jump a pixel at a time when the thing they draw moves: a servo horn turning by a tenth of a degree moves its tip by a sixth of a pixel and is drawn where it was, then a pixel further. These take their centres, ends, radii and widths as floats and blend their edge pixels from the exact distance, so a shape that moves by a tenth of a pixel changes its edge pixels' coverage by about a tenth. At whole numbers the disc and the capsule give the same pixels as gfx_fill_circle_aa() and gfx_capsule_aa(), which are drawn through them.

They follow gfx.h's contracts: everything clips to canvas->clip, and coverage is blended per call.

SPDX-License-Identifier: MIT

Function Documentation

◆ gfx_capsule_aaf()

void gfx_capsule_aaf ( gfx_canvas_t * c,
float ax,
float ay,
float bx,
float by,
float thickness,
gfx_color_t col )

A capsule, a thick line with round ends, from (ax, ay) to (bx, by), anti-aliased from each pixel's distance to its spine.

Parameters
cthe canvas
axone end's column, px
ayits row, px
bxthe other end's column, px
byits row, px
thicknessthe width, px; 0 or less draws nothing
colthe colour

◆ gfx_fill_circle_aaf()

void gfx_fill_circle_aaf ( gfx_canvas_t * c,
float cx,
float cy,
float r,
gfx_color_t col )

A disc of radius r centred on (cx, cy), anti-aliased from each pixel's distance to the centre.

Parameters
cthe canvas
cxthe centre's column, px
cythe centre's row, px
rthe radius, px; 0 or less draws nothing
colthe colour

◆ gfx_ring_aaf()

void gfx_ring_aaf ( gfx_canvas_t * c,
float cx,
float cy,
float r,
float thickness,
float a0_deg,
float a1_deg,
gfx_color_t col,
gfx_color_t into,
float fade_deg )

A ring, or an arc of one, solved per pixel from its distance and direction to the centre.

gfx_arc_fade() walks its arc and rounds each step to a pixel. This one blends the band's two edges and the arc's two ends over half a pixel either side, the ends measured along the arc at each pixel's radius. A span of 360deg or more is the whole ring. A pixel whose centre lies half a pixel or more beyond the band or past an end is not touched.

Parameters
cthe canvas
cxthe centre's column, px
cythe centre's row, px
rthe band's middle radius, px
thicknessthe band's width, px
a0_degone end, degrees counter-clockwise from +x (90 is up)
a1_degthe other end, degrees
colthe colour
intothe colour each end fades from over fade_deg
fade_degthe fade's length, degrees; 0 for none