ra8-firmware 0.1.0
Bare-metal firmware for the Renesas RA8 family (RA8D2 / RA8P1)
Loading...
Searching...
No Matches
reflow_svg_internal.h
Go to the documentation of this file.
1
29#pragma once
30
31#include <stddef.h>
32#include <stdint.h>
33
34#include "ra8_attributes.h"
35
82
87typedef struct {
88 int32_t x;
89 int32_t y;
90} svg_pt_t;
91
102typedef struct {
103 float a;
104 float b;
105 float c;
106 float d;
107 float e;
108 float f;
109} svg_utf_t;
110
112typedef struct svg_grads svg_grads_t;
113
118typedef struct {
119 int32_t bx;
120 int32_t by;
121 int32_t bw;
122 int32_t bh;
123 int32_t vx;
124 int32_t vy;
125 int32_t vw;
126 int32_t vh;
127 /* User-space `transform=` as a 2x3 affine, applied to a point BEFORE the
128 * viewBox->box map: (x,y) -> (ua*x+uc*y+ue, ub*x+ud*y+uf). Identity
129 * (ua=ud=1, others 0) reproduces the untransformed render byte-for-byte; the
130 * axis-aligned case (ub==0 && uc==0) keeps the fast-path primitives. */
131 float ua;
132 float ub;
133 float uc;
134 float ud;
135 float ue;
136 float uf;
137 /* Gradients defined in the document, scanned once before the render walk.
138 * NULL keeps the solid-fill render byte-for-byte unchanged. A shape whose
139 * `fill="url(#id)"` resolves here is filled per-pixel via priv_ra8_svgp_fill_poly_grad. */
142
147typedef struct {
148 float off;
149 uint32_t col;
150} svg_stop_t;
151
161typedef struct {
162 uint8_t kind;
163 uint8_t nstops;
164 char id[k_svg_grad_id];
165 float x1;
166 float y1;
167 float x2;
168 float y2;
170} svg_grad_t;
171
180
181/* ===========================================================================
182 * Cross-TU helper prototypes (defined `static`-free in one TU, called in others)
183 * ===========================================================================
184 */
185
206RA8_PRIV bool priv_ra8_svgp_ws(char c);
207
228RA8_PRIV char priv_ra8_svgp_lc(char c);
229
254RA8_PRIV bool priv_ra8_svgp_starts_ci(const uint8_t* s, size_t len, size_t at, const char* lit);
255
279RA8_PRIV size_t priv_ra8_svgp_find_ci(const uint8_t* s, size_t len, size_t from, const char* lit);
280
303RA8_PRIV int32_t priv_ra8_svgp_num(const uint8_t* s, size_t len, size_t* i);
304
329RA8_PRIV bool
330priv_ra8_svgp_attr(const uint8_t* s, size_t len, const char* name, size_t* voff, size_t* vlen);
331
355RA8_PRIV int32_t priv_ra8_svgp_attr_num(const uint8_t* s,
356 size_t len,
357 const char* name,
358 int32_t def);
359
381RA8_PRIV uint32_t priv_ra8_svgp_paint(const uint8_t* s, size_t len);
382
407RA8_PRIV uint32_t priv_ra8_svgp_attr_paint(const uint8_t* s,
408 size_t len,
409 const char* name,
410 uint32_t def);
411
438RA8_PRIV uint32_t priv_ra8_svgp_resolve_fill(const uint8_t* s,
439 size_t len,
440 const svg_xform_t* t,
441 uint32_t def,
442 int32_t* gi);
443
467RA8_PRIV float priv_ra8_svgp_numf(const uint8_t* s, size_t len, size_t* i);
468
490
512RA8_PRIV void
513priv_ra8_svgp_map_point(const svg_xform_t* t, int32_t ux, int32_t uy, int32_t* fx, int32_t* fy);
514
535RA8_PRIV int32_t priv_ra8_svgp_mx(const svg_xform_t* t, int32_t sx);
536
557RA8_PRIV int32_t priv_ra8_svgp_my(const svg_xform_t* t, int32_t sy);
558
579RA8_PRIV int32_t priv_ra8_svgp_sx(const svg_xform_t* t, int32_t sw);
580
600RA8_PRIV void priv_ra8_svgp_apply_xform(svg_xform_t* t, const uint8_t* tag, size_t tlen);
601
621RA8_PRIV void
622priv_ra8_svgp_fill_poly(const int32_t* xs, const int32_t* ys, int32_t n, uint32_t color);
623
644RA8_PRIV void
645priv_ra8_svgp_fill_poly_grad(const int32_t* xs, const int32_t* ys, int32_t n, const svg_grad_t* g);
646
684RA8_PRIV int32_t priv_match_grad(const svg_grads_t* grads, const uint8_t* val, size_t vlen);
685
710 svg_pt_t p0,
711 const int32_t* args,
712 svg_pt_t p_end,
713 int32_t* xs,
714 int32_t* ys,
715 int32_t* n);
716
735RA8_PRIV void priv_ra8_svgp_draw_rect(const uint8_t* s, size_t len, const svg_xform_t* t);
736
756RA8_PRIV void priv_ra8_svgp_draw_circle(const uint8_t* s, size_t len, const svg_xform_t* t);
757
776RA8_PRIV void priv_ra8_svgp_draw_line(const uint8_t* s, size_t len, const svg_xform_t* t);
777
796RA8_PRIV void priv_ra8_svgp_draw_polygon(const uint8_t* s, size_t len, const svg_xform_t* t);
797
816RA8_PRIV void priv_ra8_svgp_draw_polyline(const uint8_t* s, size_t len, const svg_xform_t* t);
817
836RA8_PRIV void priv_ra8_svgp_draw_path(const uint8_t* s, size_t len, const svg_xform_t* t);
Annotation-attribute framework macros for ra8-firmware.
#define RA8_PRIV
Module-private helper: shared across TUs but only inside one library.
int32_t priv_ra8_svgp_sx(const svg_xform_t *t, int32_t sw)
Scale a user-space length by the user x scale and the viewBox x ratio.
struct svg_grads svg_grads_t
Forward decl: the document's gradient set (defined after svg_xform_t).
uint32_t priv_ra8_svgp_paint(const uint8_t *s, size_t len)
Parse an SVG paint value ('rgb'/'rrggbb'/name/'none') to 0x00RRGGBB.
Definition reflow_svg.c:614
int32_t priv_ra8_svgp_num(const uint8_t *s, size_t len, size_t *i)
Parse the integer part of one SVG number at s[*i]; truncate fractions.
Definition reflow_svg.c:255
void priv_ra8_svgp_fill_poly_grad(const int32_t *xs, const int32_t *ys, int32_t n, const svg_grad_t *g)
Per-pixel gradient scanline fill of polygon (xs,ys)[0..n).
void priv_ra8_svgp_draw_circle(const uint8_t *s, size_t len, const svg_xform_t *t)
Draw one SVG 'circle' element using its fill colour or gradient.
void priv_ra8_svgp_draw_polygon(const uint8_t *s, size_t len, const svg_xform_t *t)
Draw one SVG 'polygon' element as a filled polygon.
void priv_ra8_svgp_fill_poly(const int32_t *xs, const int32_t *ys, int32_t n, uint32_t color)
Even-odd scanline fill of polygon (xs,ys)[0..n) with a solid colour.
void priv_ra8_svgp_map_point(const svg_xform_t *t, int32_t ux, int32_t uy, int32_t *fx, int32_t *fy)
Map a user-space point through the FULL affine, then viewBox->box.
void priv_ra8_svgp_draw_polyline(const uint8_t *s, size_t len, const svg_xform_t *t)
Draw one SVG 'polyline' element as connected stroke line segments.
float priv_ra8_svgp_numf(const uint8_t *s, size_t len, size_t *i)
Parse one SVG floating-point number at s[*i], skipping separators.
void priv_ra8_svgp_draw_rect(const uint8_t *s, size_t len, const svg_xform_t *t)
Draw one SVG 'rect' element using its fill colour or gradient.
void priv_ra8_svgp_flatten_arc(const svg_xform_t *t, svg_pt_t p0, const int32_t *args, svg_pt_t p_end, int32_t *xs, int32_t *ys, int32_t *n)
Flatten an SVG elliptical arc into the polygon vertex array.
void priv_ra8_svgp_apply_xform(svg_xform_t *t, const uint8_t *tag, size_t tlen)
Compose the 'transform=' attribute from tag onto t's user affine.
bool priv_ra8_svgp_ws(char c)
Test whether a character is XML whitespace.
Definition reflow_svg.c:58
bool priv_ra8_svgp_attr(const uint8_t *s, size_t len, const char *name, size_t *voff, size_t *vlen)
Find attribute name in tag span s[0..len); return its value slice.
Definition reflow_svg.c:364
uint32_t priv_ra8_svgp_resolve_fill(const uint8_t *s, size_t len, const svg_xform_t *t, uint32_t def, int32_t *gi)
Resolve a shape's 'fill': a solid colour, or a gradient index via gi.
Definition reflow_svg.c:721
int32_t priv_ra8_svgp_mx(const svg_xform_t *t, int32_t sx)
Map a user-space x coordinate to a framebuffer x coordinate.
uint32_t priv_ra8_svgp_attr_paint(const uint8_t *s, size_t len, const char *name, uint32_t def)
Read an SVG attribute as a paint colour, returning def when absent.
Definition reflow_svg.c:654
size_t priv_ra8_svgp_find_ci(const uint8_t *s, size_t len, size_t from, const char *lit)
Find the first case-insensitive occurrence of lit in s[from..len).
Definition reflow_svg.c:166
int32_t priv_match_grad(const svg_grads_t *grads, const uint8_t *val, size_t vlen)
Match a 'url(id)' paint value to a gradient index in the document set.
Definition reflow_svg.c:665
bool priv_ra8_svgp_starts_ci(const uint8_t *s, size_t len, size_t at, const char *lit)
Case-insensitive prefix test of lit at at within s[0..len).
Definition reflow_svg.c:123
void priv_ra8_svgp_draw_line(const uint8_t *s, size_t len, const svg_xform_t *t)
Draw one SVG 'line' element using its stroke colour.
int32_t priv_ra8_svgp_attr_num(const uint8_t *s, size_t len, const char *name, int32_t def)
Read an SVG attribute as a signed integer, returning def when absent.
Definition reflow_svg.c:424
char priv_ra8_svgp_lc(char c)
ASCII-fold a character to lower case.
Definition reflow_svg.c:88
bool priv_ra8_svgp_has_rot(const svg_xform_t *t)
Test whether the user transform contains rotation or shear.
priv_svg_consts_t
Parse + colour constants for the SVG subset.
@ k_svg_arc_ey
A arg index: endpoint Y.
@ k_svg_path_args
Max args of a path command (A).
@ k_svg_bom2
UTF-8 BOM byte 2.
@ k_svg_arc_ex
A arg index: endpoint X.
@ k_svg_hex6
#rrggbb digit count.
@ k_svg_grad_linear
<linearGradient> kind.
@ k_svg_grad_radial
<radialGradient> kind.
@ k_svg_def_fill
SVG default fill is black.
@ k_svg_grad_max
Max gradients defined per document.
@ k_svg_hex_a10
Value of hex 'a'/'A'.
@ k_svg_arc_large
A arg index: large-arc flag.
@ k_svg_sh_r
Red shift within 0x00RRGGBB.
@ k_svg_arc_seg_max
Max segments per arc flatten.
@ k_svg_hex3
#rgb digit count.
@ k_svg_poly_min
Min points for a fillable polygon.
@ k_svg_arc_rx
A arg index: semi-axis X.
@ k_svg_hex_chan
Bits per colour channel.
@ k_svg_dec
Decimal base.
@ k_svg_bom0
UTF-8 BOM byte 0.
@ k_svg_no_paint
none / absent paint sentinel.
@ k_svg_hex_base
Hex base / "not a hex digit".
@ k_svg_hex_nib
Bits per hex nibble.
@ k_svg_poly_max
Max points / scanline crossings.
@ k_svg_path_ep
Endpoint pair size (x, y); M/L/T.
@ k_svg_arc_ry
A arg index: semi-axis Y.
@ k_svg_viewbox_n
viewBox number count.
@ k_svg_g_depth_max
Max nested <g> transform depth.
@ k_svg_arc_sweep
A arg index: sweep flag.
@ k_svg_bom_len
UTF-8 BOM length.
@ k_svg_rect_pts
Corner count of a rectangle.
@ k_svg_argc_cube
Arg count of C.
@ k_svg_arc_rot
A arg index: x-axis rotation.
@ k_svg_grad_id
Max gradient id length, bytes.
@ k_svg_bom1
UTF-8 BOM byte 1.
@ k_svg_circle_seg
N-gon segments for a transformed circle.
@ k_svg_curve_seg
Segments per cubic-Bezier flatten.
@ k_svg_cube_ey
C endpoint-y argument index.
@ k_svg_grad_stops
Max colour stops per gradient.
@ k_svg_argc_quad
Arg count of S / Q.
@ k_svg_chan_mask
One 8-bit RGB channel mask.
void priv_ra8_svgp_draw_path(const uint8_t *s, size_t len, const svg_xform_t *t)
Draw one SVG 'path' element as a filled polygon.
int32_t priv_ra8_svgp_my(const svg_xform_t *t, int32_t sy)
Map a user-space y coordinate to a framebuffer y coordinate.
A parsed linear/radial gradient in objectBoundingBox units.
float x2
Linear end x / radial radius.
uint8_t kind
k_svg_grad_linear / k_svg_grad_radial.
float y1
Linear start y / radial centre y.
float y2
Linear end y (unused for radial).
uint8_t nstops
Number of valid stops.
float x1
Linear start x / radial centre x.
svg_stop_t stops[k_svg_grad_stops]
Colour stops, in document order.
Bounded set of gradients scanned from the document before the render.
svg_grad_t g[k_svg_grad_max]
The gradient table.
int32_t n
Number of valid gradients (<= k_svg_grad_max).
A 2-D point in SVG user space (an x/y pair).
int32_t y
Y coordinate.
int32_t x
X coordinate.
One gradient colour stop: an offset in [0,1] and an 0x00RRGGBB colour.
float off
Stop offset, clamped to [0,1].
uint32_t col
Stop colour, 0x00RRGGBB.
A user transform= as a full 2x3 affine matrix.
float c
Row0 col1 (x shear).
float e
X translate.
float f
Y translate.
float a
Row0 col0 (x scale).
float b
Row1 col0 (y shear).
float d
Row1 col1 (y scale).
SVG-user-space -> framebuffer-box coordinate transform.
float ub
Affine b (y shear; 0 = axis-aligned).
int32_t bw
Box width.
int32_t vx
viewBox min-x.
float ue
Affine e (x translate, user units).
float ud
Affine d (y scale; 1 = identity).
int32_t bx
Box left.
int32_t vy
viewBox min-y.
int32_t vw
viewBox width.
float uf
Affine f (y translate, user units).
int32_t vh
viewBox height.
int32_t by
Box top.
float uc
Affine c (x shear; 0 = axis-aligned).
float ua
Affine a (x scale; 1 = identity).
int32_t bh
Box height.
const svg_grads_t * grads
Document gradient set, or NULL.