ra8-firmware 0.1.0
Bare-metal firmware for the Renesas RA8 family (RA8D2 / RA8P1)
Loading...
Searching...
No Matches
reflow_svg_shape.c File Reference

SVG shape rasterisers: rect / circle / line / polygon + fill + arc (#112). More...

#include <math.h>
#include "ra8_attributes.h"
#include "ra8_gfx.h"
#include "reflow_svg_internal.h"
Include dependency graph for reflow_svg_shape.c:

Go to the source code of this file.

Data Structures

struct  svg_arc_t
 Centre-parametrisation of an SVG elliptical arc. More...

Functions

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_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_line (const uint8_t *s, size_t len, const svg_xform_t *t)
 Draw one SVG 'line' element using its stroke colour.
static int32_t internal_parse_points (const uint8_t *v, size_t vlen, const svg_xform_t *t, int32_t *xs, int32_t *ys)
 Parse a 'points' attribute value into framebuffer-space vertices.
static void internal_sort_i32 (int32_t *a, int32_t m)
 Sort m int32 values in a into ascending order using insertion sort.
static int32_t internal_scanline_x (const int32_t *xs, const int32_t *ys, int32_t n, int32_t y, int32_t *xint)
 Collect framebuffer X coordinates where polygon edges cross scanline y.
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.
static uint32_t internal_col_lerp (uint32_t a, uint32_t b, float f)
 Linear-interpolate two 0x00RRGGBB colours by factor f in [0, 1].
static uint32_t internal_grad_eval (const svg_grad_t *g, float px, float py)
 Evaluate gradient g at bbox-relative point (px, py).
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_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_draw_polyline (const uint8_t *s, size_t len, const svg_xform_t *t)
 Draw one SVG 'polyline' element as connected stroke line segments.
static float internal_absf (float v)
 Compute the absolute value of a float without using libm fabsf.
static void internal_arc_solve (svg_arc_t *a, float x1p, float y1p, float rx, float ry, float mx, float my, bool large, bool sweep)
 Solve an arc's centre + start/sweep angles (F.6.5.2 / F.6.5.5-6).
static svg_arc_t internal_arc_center (svg_pt_t p0, svg_pt_t p_end, int32_t rx_in, int32_t ry_in, int32_t rot_deg, bool large, bool sweep)
 Convert an SVG endpoint-parametrised arc to centre parametrisation.
static int32_t internal_arc_segs (float dt)
 Compute a bounded segment count for an arc of signed sweep dt.
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.

Variables

static const float s_svg_2pi = 6.28318531F
 2*Pi, for wrapping an arc's signed sweep into range.

Detailed Description

SVG shape rasterisers: rect / circle / line / polygon + fill + arc (#112).

The <rect>, <circle>, <line>, <polygon>, and <polyline> rasterisers, the even-odd scanline polygon fill (solid and per-pixel gradient), the gradient colour evaluator, and the elliptical-arc flatten (shared with the <path> A command). Axis-aligned shapes keep the ra8_gfx fast path; rotated / sheared shapes are mapped through the affine and scanline-filled. No DOM, no heap. See reflow_svg_internal.h for the shared geometry types and cross-TU helper contracts.

[Ring 4 / Reflow] {World: NS}

Since
0.1.0

Definition in file reflow_svg_shape.c.

Function Documentation

◆ internal_absf()

float internal_absf ( float v)
static

Compute the absolute value of a float without using libm fabsf.

Returns -v when v is negative, otherwise returns v unchanged. Used in internal_arc_center and internal_arc_segs to avoid dragging in the full libm dependency for a trivial operation that the compiler can inline.

Parameters
[in]vFloat value whose absolute value is needed.
Returns
float The absolute value of v.
Return values
-vWhen v < 0.0F.
vWhen v >= 0.0F.
Precondition
v is any finite float value (NaN and infinity return themselves).
No external state is required.
Postcondition
The return value is >= 0.0F for all finite v.
v is not modified.
Note
Not thread-safe in isolation; callers in this module are single-threaded during SVG render.
Since
0.1.0

Definition at line 686 of file reflow_svg_shape.c.

Referenced by internal_arc_center(), and internal_arc_segs().

◆ internal_arc_center()

svg_arc_t internal_arc_center ( svg_pt_t p0,
svg_pt_t p_end,
int32_t rx_in,
int32_t ry_in,
int32_t rot_deg,
bool large,
bool sweep )
static

Convert an SVG endpoint-parametrised arc to centre parametrisation.

Implements the SVG 1.1 implementation-notes F.6.5 algorithm: out-of-range radii are scaled up (F.6.6.2), the centre is solved via internal_arc_solve (F.6.5.2), and the start angle plus signed sweep are derived (F.6.5.5/6) honouring the large-arc and sweep flags. Pure (no MMIO/heap); uses libm cosf, sinf, sqrtf.

Parameters
[in]p0Arc start (current point, user space).
[in]p_endArc end (user space, already absolute).
[in]rx_inRequested semi-axis X (its absolute value is used).
[in]ry_inRequested semi-axis Y (its absolute value is used).
[in]rot_degX-axis rotation in degrees.
[in]largeLarge-arc flag.
[in]sweepSweep (positive-angle) flag.
Returns
svg_arc_t The centre parametrisation of the arc.
Return values
{.ok=false}Zero radius, or p0 and p_end are coincident.
{.ok=true}All fields valid: centre, semi-axes, start angle, sweep.
Precondition
rx_in and ry_in fit in a float without overflow (SVG coords are bounded).
p0 and p_end are valid user-space points.
Postcondition
When ok == true, the fields cx, cy, rx, ry, t1, and dt are all valid.
When ok == false, no other field in the returned struct is meaningful.
Note
Not thread-safe in isolation; callers in this module are single-threaded during SVG render.
Since
0.1.0

Definition at line 816 of file reflow_svg_shape.c.

References svg_arc_t::cos_phi, internal_absf(), internal_arc_solve(), svg_arc_t::ok, svg_arc_t::sin_phi, svg_pt_t::x, and svg_pt_t::y.

Referenced by priv_ra8_svgp_flatten_arc().

◆ internal_arc_segs()

int32_t internal_arc_segs ( float dt)
static

Compute a bounded segment count for an arc of signed sweep dt.

Divides the absolute value of dt by the target radians-per-segment function-local arc step (~pi/8) and adds 1 to ensure at least one segment. The result is clamped to k_svg_arc_seg_max (24) to keep the vertex count bounded regardless of the sweep angle.

Parameters
[in]dtSigned arc sweep in radians; negative values are valid.
Returns
int32_t Number of segments to use when flattening the arc.
Return values
1..k_svg_arc_seg_maxAlways within this range.
Precondition
dt is a finite float; the absolute value is used for the calculation.
dt is finite so division by the positive local arc step is defined.
Postcondition
The return value is in [1, k_svg_arc_seg_max].
dt is not modified.
Note
Not thread-safe in isolation; callers in this module are single-threaded during SVG render.
Since
0.1.0

Definition at line 878 of file reflow_svg_shape.c.

References internal_absf(), and k_svg_arc_seg_max.

Referenced by priv_ra8_svgp_flatten_arc().

◆ internal_arc_solve()

void internal_arc_solve ( svg_arc_t * a,
float x1p,
float y1p,
float rx,
float ry,
float mx,
float my,
bool large,
bool sweep )
static

Solve an arc's centre + start/sweep angles (F.6.5.2 / F.6.5.5-6).

Finishes internal_arc_center from its rotated half-chord (x1p,y1p), the (radius-corrected) semi-axes (rx,ry), and the endpoint midpoint (mx,my). Fills a's centre, start angle, signed sweep, radii, and sets a->ok to true. The cos_phi / sin_phi fields of a must already be set by the caller. The signed sweep a->dt is adjusted so its direction is consistent with sweep (positive angle) and large (large-arc) flags.

Parameters
[in,out]aArc struct; centre, angles, radii, and ok are written.
[in]x1pRotated half-chord X (F.6.5.1, user space).
[in]y1pRotated half-chord Y (F.6.5.1, user space).
[in]rxCorrected semi-axis X.
[in]ryCorrected semi-axis Y.
[in]mxEndpoint midpoint X (user space).
[in]myEndpoint midpoint Y (user space).
[in]largeLarge-arc flag from the 'A' command.
[in]sweepSweep (positive-angle) flag from the 'A' command.
Precondition
a is a valid non-NULL pointer with cos_phi / sin_phi already set.
rx > 0.0F and ry > 0.0F (degenerate radii handled by the caller).
Postcondition
a->ok is set to true.
a->cx, a->cy, a->t1, a->dt, a->rx, a->ry are valid.
Note
Not thread-safe in isolation; callers in this module are single-threaded during SVG render.
Since
0.1.0

Definition at line 744 of file reflow_svg_shape.c.

References svg_arc_t::cos_phi, svg_arc_t::cx, svg_arc_t::cy, svg_arc_t::dt, svg_arc_t::ok, svg_arc_t::rx, svg_arc_t::ry, s_svg_2pi, svg_arc_t::sin_phi, and svg_arc_t::t1.

Referenced by internal_arc_center().

◆ internal_col_lerp()

uint32_t internal_col_lerp ( uint32_t a,
uint32_t b,
float f )
static

Linear-interpolate two 0x00RRGGBB colours by factor f in [0, 1].

Extracts the R, G, and B channels from a and b, interpolates each independently as (channel_a + (channel_b - channel_a) * f), and recombines into a 0x00RRGGBB result. The factor f is not clamped by this function; the gradient evaluator is responsible for providing a value in [0,1]. Used by internal_grad_eval to blend adjacent gradient stops.

Parameters
[in]aColour A in 0x00RRGGBB format.
[in]bColour B in 0x00RRGGBB format.
[in]fInterpolation factor; 0.0F returns a, 1.0F returns b.
Returns
uint32_t The interpolated colour in 0x00RRGGBB format.
Return values
0x000000..0xFFFFFFThe per-channel linear blend of a and b at f.
Precondition
f is in the range [0.0F, 1.0F] to produce a value between a and b.
a and b have bits [31:24] clear (0x00RRGGBB format).
Postcondition
The return value has bits [31:24] clear.
Each channel of the return value is clamped to [0, 255] by construction.
Note
Not thread-safe in isolation; callers in this module are single-threaded during SVG render.
Since
0.1.0

Definition at line 421 of file reflow_svg_shape.c.

References k_svg_chan_mask, k_svg_hex_chan, and k_svg_sh_r.

Referenced by internal_grad_eval().

◆ internal_grad_eval()

uint32_t internal_grad_eval ( const svg_grad_t * g,
float px,
float py )
static

Evaluate gradient g at bbox-relative point (px, py).

For a linear gradient the scalar parameter is the projection of (px - x1, py - y1) onto the vector (x2 - x1, y2 - y1) normalised by the squared length of that vector. For a radial gradient the parameter is the Euclidean distance from (x1, y1) divided by radius x2. The parameter is compared against stop offsets; values before the first stop return the first stop colour, values after the last return the last stop colour, and values between two stops are linearly interpolated by internal_col_lerp. Returns the default fill colour when g->nstops is zero.

Parameters
[in]gGradient to evaluate; must not be NULL and must have nstops >= 1.
[in]pxBounding-box-relative X position in [0, 1].
[in]pyBounding-box-relative Y position in [0, 1].
Returns
uint32_t The evaluated colour in 0x00RRGGBB format.
Return values
(uint32_t)k_svg_def_fillWhen g->nstops is 0.
0x000000..0xFFFFFFInterpolated or clamped stop colour.
Precondition
g is a valid non-NULL pointer to an initialised svg_grad_t.
px and py are bounding-box-relative coordinates (typically in [0,1]).
Postcondition
The return value has bits [31:24] clear (0x00RRGGBB format).
g is not modified.
Note
Not thread-safe in isolation; callers in this module are single-threaded during SVG render.
Since
0.1.0

Definition at line 477 of file reflow_svg_shape.c.

References svg_stop_t::col, internal_col_lerp(), k_svg_def_fill, k_svg_grad_radial, svg_grad_t::kind, svg_grad_t::nstops, svg_stop_t::off, svg_grad_t::stops, svg_grad_t::x1, svg_grad_t::x2, svg_grad_t::y1, and svg_grad_t::y2.

Referenced by priv_ra8_svgp_fill_poly_grad().

◆ internal_parse_points()

int32_t internal_parse_points ( const uint8_t * v,
size_t vlen,
const svg_xform_t * t,
int32_t * xs,
int32_t * ys )
static

Parse a 'points' attribute value into framebuffer-space vertices.

Scans v[0..vlen) for whitespace/comma-separated x,y integer pairs via priv_ra8_svgp_num, maps each pair through the full affine via priv_ra8_svgp_map_point, and stores the result in xs[n] / ys[n]. Terminates when k_svg_poly_max vertices have been collected or the end of the span is reached. Returns the count of vertex pairs filled.

Parameters
[in]vByte span containing the 'points' value text; must not be NULL.
[in]vlenTotal valid bytes in v.
[in]tActive coordinate transform; must not be NULL.
[out]xsArray of at least k_svg_poly_max int32_t for X coords; must not be NULL.
[out]ysArray of at least k_svg_poly_max int32_t for Y coords; must not be NULL.
Returns
int32_t Number of vertices filled in xs / ys.
Return values
0No valid x,y pairs found.
1..k_svg_poly_maxCount of vertices parsed and mapped.
Precondition
v is a valid pointer to at least vlen bytes.
xs and ys are valid arrays of at least k_svg_poly_max elements.
Postcondition
xs[0..return-1] and ys[0..return-1] hold framebuffer coordinates.
The return value is in [0, k_svg_poly_max].
Note
Not thread-safe in isolation; callers in this module are single-threaded during SVG render.
Since
0.1.0

Definition at line 233 of file reflow_svg_shape.c.

References k_svg_poly_max, priv_ra8_svgp_map_point(), priv_ra8_svgp_num(), and priv_ra8_svgp_ws().

Referenced by priv_ra8_svgp_draw_polygon(), and priv_ra8_svgp_draw_polyline().

◆ internal_scanline_x()

int32_t internal_scanline_x ( const int32_t * xs,
const int32_t * ys,
int32_t n,
int32_t y,
int32_t * xint )
static

Collect framebuffer X coordinates where polygon edges cross scanline y.

Iterates over all n edges of the polygon. For each edge from vertex i to vertex (i+1)n, checks whether scanline y passes through it (using the half-open interval [y0,y1) or [y1,y0)). For crossing edges, computes the X intercept via linear interpolation with 64-bit arithmetic and stores it in xint. Stops early if k_svg_poly_max crossings are found.

Parameters
[in]xsArray of n polygon vertex X coordinates (framebuffer); must not be NULL.
[in]ysArray of n polygon vertex Y coordinates (framebuffer); must not be NULL.
[in]nNumber of polygon vertices.
[in]yScanline Y coordinate to test.
[out]xintArray of at least k_svg_poly_max int32_t for crossing X values; must not be NULL.
Returns
int32_t Number of edge crossings written to xint.
Return values
0No edges cross scanline y.
mm intercept X values in xint[0..m-1], unsorted.
Precondition
xs and ys are valid pointers to at least n elements.
xint is a valid array of at least k_svg_poly_max elements.
Postcondition
xint[0..return-1] hold the X coordinates of edge-scanline intersections.
The return value is in [0, k_svg_poly_max].
Note
Not thread-safe in isolation; callers in this module are single-threaded during SVG render.
Since
0.1.0

Definition at line 323 of file reflow_svg_shape.c.

References k_svg_poly_max.

Referenced by priv_ra8_svgp_fill_poly(), and priv_ra8_svgp_fill_poly_grad().

◆ internal_sort_i32()

void internal_sort_i32 ( int32_t * a,
int32_t m )
static

Sort m int32 values in a into ascending order using insertion sort.

Uses the classic O(m^2) insertion sort, which is efficient for small arrays (m is bounded by k_svg_poly_max scanline crossings per row). Works in-place with a single temporary variable per outer iteration. Used by the scanline fill algorithm to sort X-intercept coordinates before pairing them for span fill.

Parameters
[in,out]aArray of m int32_t values to sort in place; must not be NULL.
[in]mCount of valid elements in a; must be >= 0.
Precondition
a is a valid pointer to at least m elements.
m is in [0, k_svg_poly_max].
Postcondition
a[0..m-1] are sorted in non-decreasing order.
The number of valid elements in a is unchanged.
Note
Not thread-safe in isolation; callers in this module are single-threaded during SVG render.
Since
0.1.0

Definition at line 277 of file reflow_svg_shape.c.

Referenced by priv_ra8_svgp_fill_poly(), and priv_ra8_svgp_fill_poly_grad().

◆ priv_ra8_svgp_draw_circle()

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.

Reads 'cx', 'cy', and 'r' attributes from the tag span s[0..len). Axis-aligned solid circles use the ra8_gfx_circle fast-path; under a rotating/shearing transform the circle is approximated by a k_svg_circle_seg N-gon whose vertices are mapped through the full affine, then scanline-filled by priv_ra8_svgp_fill_poly or priv_ra8_svgp_fill_poly_grad. Returns without drawing when both gi < 0 and fill == k_svg_no_paint.

Parameters
[in]sByte span of the element tag; must not be NULL.
[in]lenTotal valid bytes in s (the tag span length).
[in]tActive coordinate transform; must not be NULL.
Precondition
s is a valid pointer to at least len bytes.
t is a valid non-NULL pointer to an initialised svg_xform_t.
Postcondition
All pixels inside the circle boundary are painted with the fill colour.
No pixels outside the circle boundary are modified.
Note
Not thread-safe in isolation; callers in this module are single-threaded during SVG render.
Since
0.1.0

Definition at line 119 of file reflow_svg_shape.c.

References svg_grads::g, svg_xform_t::grads, k_svg_circle_seg, k_svg_def_fill, k_svg_no_paint, priv_ra8_svgp_attr_num(), priv_ra8_svgp_fill_poly(), priv_ra8_svgp_fill_poly_grad(), priv_ra8_svgp_has_rot(), priv_ra8_svgp_map_point(), priv_ra8_svgp_mx(), priv_ra8_svgp_my(), priv_ra8_svgp_resolve_fill(), priv_ra8_svgp_sx(), ra8_gfx_circle(), and s_svg_2pi.

Referenced by internal_dispatch_shape().

◆ priv_ra8_svgp_draw_line()

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.

Reads 'stroke' paint, 'x1', 'y1', 'x2', and 'y2' attributes from the tag span s[0..len). Both endpoints are mapped through the full affine via priv_ra8_svgp_map_point and the result is forwarded to ra8_gfx_line. Returns without drawing when 'stroke' is absent or parses to k_svg_no_paint. Note: 'fill' is ignored for 'line' elements (SVG specification).

Parameters
[in]sByte span of the element tag; must not be NULL.
[in]lenTotal valid bytes in s (the tag span length).
[in]tActive coordinate transform; must not be NULL.
Precondition
s is a valid pointer to at least len bytes.
t is a valid non-NULL pointer to an initialised svg_xform_t.
Postcondition
The line from (x1,y1) to (x2,y2) is drawn in the stroke colour.
No drawing occurs when the stroke colour is k_svg_no_paint.
Note
Not thread-safe in isolation; callers in this module are single-threaded during SVG render.
Since
0.1.0

Definition at line 177 of file reflow_svg_shape.c.

References k_svg_no_paint, priv_ra8_svgp_attr_num(), priv_ra8_svgp_attr_paint(), priv_ra8_svgp_map_point(), and ra8_gfx_line().

Referenced by internal_dispatch_shape().

◆ priv_ra8_svgp_draw_polygon()

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.

Resolves the fill (solid or gradient), reads the 'points' attribute, parses vertices into framebuffer space via internal_parse_points, and fills the resulting polygon with priv_ra8_svgp_fill_poly or priv_ra8_svgp_fill_poly_grad. Returns without drawing when the fill is absent/none or the 'points' attribute is not present.

Parameters
[in]sByte span of the element tag; must not be NULL.
[in]lenTotal valid bytes in s.
[in]tActive coordinate transform; must not be NULL.
Precondition
s is a valid pointer to at least len bytes.
t is a valid non-NULL pointer to an initialised svg_xform_t.
Postcondition
All pixels inside the polygon boundary are painted with the fill colour.
No drawing occurs when fill is absent or 'points' is missing.
Note
Not thread-safe in isolation; callers in this module are single-threaded during SVG render.
Since
0.1.0

Definition at line 601 of file reflow_svg_shape.c.

References svg_grads::g, svg_xform_t::grads, internal_parse_points(), k_svg_def_fill, k_svg_no_paint, k_svg_poly_max, priv_ra8_svgp_attr(), priv_ra8_svgp_fill_poly(), priv_ra8_svgp_fill_poly_grad(), and priv_ra8_svgp_resolve_fill().

Referenced by internal_dispatch_shape().

◆ priv_ra8_svgp_draw_polyline()

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.

Reads the 'stroke' paint and the 'points' attribute. Parses vertex pairs into framebuffer space via internal_parse_points and connects adjacent vertices with ra8_gfx_line. Returns without drawing when the stroke colour is absent/none or the 'points' attribute is not present.

Parameters
[in]sByte span of the element tag; must not be NULL.
[in]lenTotal valid bytes in s.
[in]tActive coordinate transform; must not be NULL.
Precondition
s is a valid pointer to at least len bytes.
t is a valid non-NULL pointer to an initialised svg_xform_t.
Postcondition
All (n-1) line segments between adjacent vertices are drawn in the stroke colour.
No drawing occurs when stroke is absent or 'points' is missing.
Note
Not thread-safe in isolation; callers in this module are single-threaded during SVG render.
Since
0.1.0

Definition at line 644 of file reflow_svg_shape.c.

References internal_parse_points(), k_svg_no_paint, k_svg_poly_max, priv_ra8_svgp_attr(), priv_ra8_svgp_attr_paint(), and ra8_gfx_line().

Referenced by internal_dispatch_shape().

◆ priv_ra8_svgp_draw_rect()

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.

Reads 'x', 'y', 'width', and 'height' attributes from the tag span s[0..len). Axis-aligned solid rects use the ra8_gfx_rect fast-path; under a rotating/shearing transform the 4 corners are mapped through the full affine via priv_ra8_svgp_map_point and the resulting quad is scanline-filled by priv_ra8_svgp_fill_poly or priv_ra8_svgp_fill_poly_grad. Returns without drawing when both gi < 0 and fill == k_svg_no_paint.

Parameters
[in]sByte span of the element tag; must not be NULL.
[in]lenTotal valid bytes in s (the tag span length).
[in]tActive coordinate transform; must not be NULL.
Precondition
s is a valid pointer to at least len bytes.
t is a valid non-NULL pointer to an initialised svg_xform_t.
Postcondition
All pixels inside the rect boundary are painted with the fill colour.
No pixels outside the rect boundary are modified.
Note
Not thread-safe in isolation; callers in this module are single-threaded during SVG render.
Since
0.1.0

Definition at line 61 of file reflow_svg_shape.c.

References svg_grads::g, svg_xform_t::grads, k_svg_def_fill, k_svg_no_paint, k_svg_rect_pts, priv_ra8_svgp_attr_num(), priv_ra8_svgp_fill_poly(), priv_ra8_svgp_fill_poly_grad(), priv_ra8_svgp_has_rot(), priv_ra8_svgp_map_point(), priv_ra8_svgp_mx(), priv_ra8_svgp_my(), priv_ra8_svgp_resolve_fill(), priv_ra8_svgp_sx(), and ra8_gfx_rect().

Referenced by internal_dispatch_shape().

◆ priv_ra8_svgp_fill_poly()

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.

Computes the bounding Y range of the polygon, then for each scanline Y in [ymin, ymax] calls internal_scanline_x to collect intercepts, sorts them via internal_sort_i32, and fills pairs of spans with ra8_gfx_line. Returns immediately for polygons with fewer than k_svg_poly_min vertices.

Parameters
[in]xsArray of n framebuffer X coordinates; must not be NULL.
[in]ysArray of n framebuffer Y coordinates; must not be NULL.
[in]nNumber of polygon vertices.
[in]colorFill colour in 0x00RRGGBB format.
Precondition
xs and ys are valid pointers to at least n elements.
n <= k_svg_poly_max.
Postcondition
All pixels inside the even-odd polygon boundary are painted color.
No drawing occurs when n < k_svg_poly_min.
Note
Not thread-safe in isolation; callers in this module are single-threaded during SVG render.
Since
0.1.0

Definition at line 371 of file reflow_svg_shape.c.

References internal_scanline_x(), internal_sort_i32(), k_svg_poly_max, k_svg_poly_min, and ra8_gfx_line().

Referenced by priv_ra8_svgp_draw_circle(), priv_ra8_svgp_draw_path(), priv_ra8_svgp_draw_polygon(), and priv_ra8_svgp_draw_rect().

◆ priv_ra8_svgp_fill_poly_grad()

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

Computes the bounding box of the polygon, then for each scanline Y in [ymin, ymax] collects edge intercepts via internal_scanline_x and sorts them. For each filled span, iterates over pixels and evaluates the gradient at the bounding-box-relative position ((x-xmin)/bw, (y-ymin)/bh) via internal_grad_eval. Each pixel is written individually with ra8_gfx_pixel. Returns immediately when n < k_svg_poly_min.

Parameters
[in]xsArray of n framebuffer X coordinates; must not be NULL.
[in]ysArray of n framebuffer Y coordinates; must not be NULL.
[in]nNumber of polygon vertices.
[in]gGradient descriptor to evaluate per pixel; must not be NULL.
Precondition
xs and ys are valid pointers to at least n elements.
g is a valid non-NULL pointer with g->nstops >= 1.
Postcondition
All pixels inside the even-odd polygon boundary are painted with the gradient colour evaluated at their bounding-box-relative position.
No drawing occurs when n < k_svg_poly_min.
Note
Not thread-safe in isolation; callers in this module are single-threaded during SVG render.
Since
0.1.0

Definition at line 541 of file reflow_svg_shape.c.

References internal_grad_eval(), internal_scanline_x(), internal_sort_i32(), k_svg_poly_max, k_svg_poly_min, and ra8_gfx_pixel().

Referenced by priv_ra8_svgp_draw_circle(), priv_ra8_svgp_draw_path(), priv_ra8_svgp_draw_polygon(), and priv_ra8_svgp_draw_rect().

◆ priv_ra8_svgp_flatten_arc()

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.

Converts the endpoint-parametrised arc (P0 to p_end, with radii, rotation, and flags from args) to centre form via internal_arc_center. When the arc is degenerate (ok==false), appends a single line-to p_end. Otherwise samples the arc at internal_arc_segs(a.dt) parameter values using trigonometry (the ellipse equation in the rotated frame) and appends each mapped framebuffer point. Bounded by k_svg_poly_max.

Parameters
[in]tActive coordinate transform; must not be NULL.
[in]p0Arc start point (current path position, user space).
[in]argsArc argument array indexed by svg_arc_* constants; must not be NULL.
[in]p_endArc end point (absolute, user space).
[out]xsVertex X array of at least k_svg_poly_max elements; must not be NULL.
[out]ysVertex Y array of at least k_svg_poly_max elements; must not be NULL.
[in,out]nCurrent vertex count; updated by this function.
Precondition
t is a valid non-NULL pointer to an initialised svg_xform_t.
args has at least k_svg_path_args (7) valid int32_t entries.
Postcondition
*n is increased by the number of arc sample points appended.
*n <= k_svg_poly_max on exit.
Note
Not thread-safe in isolation; callers in this module are single-threaded during SVG render.
Since
0.1.0

Definition at line 917 of file reflow_svg_shape.c.

References svg_arc_t::cos_phi, svg_arc_t::cx, svg_arc_t::cy, svg_arc_t::dt, internal_arc_center(), internal_arc_segs(), k_svg_arc_large, k_svg_arc_rot, k_svg_arc_rx, k_svg_arc_ry, k_svg_arc_sweep, k_svg_poly_max, svg_arc_t::ok, priv_ra8_svgp_map_point(), svg_arc_t::rx, svg_arc_t::ry, svg_arc_t::sin_phi, svg_arc_t::t1, svg_pt_t::x, and svg_pt_t::y.

Referenced by internal_path_curve().

Variable Documentation

◆ s_svg_2pi

const float s_svg_2pi = 6.28318531F
static

2*Pi, for wrapping an arc's signed sweep into range.

Definition at line 29 of file reflow_svg_shape.c.

Referenced by internal_arc_solve(), and priv_ra8_svgp_draw_circle().