libwebsockets
Lightweight C library for HTML5 websockets
Toggle main menu visibility
Loading...
Searching...
No Matches
lws-svg.h
Go to the documentation of this file.
1
/*
2
* lws svg
3
*
4
* Written in 2026 by Andy Green <andy@warmcat.com>
5
*
6
* Permission is hereby granted, free of charge, to any person obtaining a copy
7
* of this software and associated documentation files (the "Software"), to
8
* deal in the Software without restriction, including without limitation the
9
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
10
* sell copies of the Software, and to permit persons to whom the Software is
11
* furnished to do so, subject to the following conditions:
12
*
13
* The above copyright notice and this permission notice shall be included in
14
* all copies or substantial portions of the Software.
15
*
16
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
22
* IN THE SOFTWARE.
23
*
24
* Stateful, linewise SVG renderer for the fill-only subset of SVG.
25
*
26
* The document is parsed streaming (the parser is not sensitive to the input
27
* chunk sizes) into a retained vector scene in a single lwsac. Curves are
28
* flattened adaptively at parse time, to a tolerance derived from the
29
* viewBox size. Individual raster lines are then produced on demand by
30
* scanline intersection against the retained geometry, so any line can be
31
* rendered at any time, in any order.
32
*
33
* The supported subset is solid fills with nonzero or evenodd winding,
34
* transforms, viewBox / preserveAspectRatio mapping, group fill property
35
* inheritance and opacity. Strokes, gradients, text and filters are not
36
* rendered in this phase of the work.
37
*/
38
39
typedef
struct
lws_svg
lws_svg_t
;
40
41
/* rgba packing is r in bits 0-7, g in 8-15, b in 16-23, alpha in 24-31, so it
42
* matches lws_display_colour_t layout */
43
44
#define LWS_SVG_RGBA(_r, _g, _b, _a) (uint32_t)( \
45
((uint32_t)(_r) & 0xff) | \
46
(((uint32_t)(_g) & 0xff) << 8) | \
47
(((uint32_t)(_b) & 0xff) << 16) | \
48
(((uint32_t)(_a) & 0xff) << 24))
49
50
#define LWS_SVG_ALPHA(_c) ((uint32_t)(((_c) >> 24) & 0xff))
51
52
/*
53
* Render mapping policy from preserveAspectRatio, only meaningful when a
54
* viewBox exists
55
*/
56
57
typedef
enum
{
58
LWS_SVG_PAR_DEFAULT
,
/* xMidYMid meet */
59
LWS_SVG_PAR_NONE
,
/* stretch to fill */
60
}
lws_svg_par_t
;
61
68
LWS_VISIBLE
LWS_EXTERN
lws_svg_t
*
69
lws_svg_new
(
void
);
70
78
LWS_VISIBLE
LWS_EXTERN
void
79
lws_svg_free
(
lws_svg_t
**svg);
80
108
LWS_VISIBLE
LWS_EXTERN
lws_stateful_ret_t
109
lws_svg_parse
(
lws_svg_t
*svg,
const
uint8_t
**buf,
size_t
*len,
110
char
hold_at_metadata);
111
122
LWS_VISIBLE
LWS_EXTERN
unsigned
int
123
lws_svg_get_width
(
const
lws_svg_t
*svg);
124
132
LWS_VISIBLE
LWS_EXTERN
unsigned
int
133
lws_svg_get_height
(
const
lws_svg_t
*svg);
134
144
LWS_VISIBLE
LWS_EXTERN
char
145
lws_svg_get_doc_complete
(
const
lws_svg_t
*svg);
146
147
/*
148
* Span callback for rendered lines. Filled spans are delivered in ascending
149
* x with \p x0 the first covered pixel and \p x1 one past the last covered
150
* pixel (so the span is half-open [x0, x1)). \p rgba is the span fill colour
151
* with composed-opacity alpha in the top byte.
152
*
153
* With ri->aa clear (the default), coverage is binary at pixel centres, and
154
* each shape produces spans of the same alpha. With ri->aa set, coverage is
155
* the exact covered fraction of each pixel (area antialiasing), spans are
156
* additionally split where the fraction changes, and the alpha byte is the
157
* fill alpha scaled by the pixel's coverage. Returning nonzero stops the
158
* line rendering, which then returns LWS_SRET_OK.
159
*/
160
typedef
int (*
lws_svg_span_cb_t
)(
void
*user,
int
x0,
int
x1,
uint32_t
rgba);
161
162
typedef
struct
lws_svg_render
{
163
int
w
;
/* output raster width in px */
164
int
h
;
/* output raster height in px */
165
char
aa
;
/* nonzero: area-antialiased coverage */
166
}
lws_svg_render_t
;
167
196
LWS_VISIBLE
LWS_EXTERN
lws_stateful_ret_t
197
lws_svg_render_line
(
lws_svg_t
*svg,
const
lws_svg_render_t
*ri,
int
y,
198
lws_svg_span_cb_t
cb,
void
*user);
uint32_t
unsigned int uint32_t
Definition
libwebsockets.h:744
LWS_EXTERN
#define LWS_EXTERN
Definition
libwebsockets.h:327
uint8_t
unsigned char uint8_t
Definition
libwebsockets.h:746
lws_stateful_ret_t
lws_stateful_ret_t
Definition
libwebsockets.h:802
LWS_VISIBLE
#define LWS_VISIBLE
Definition
libwebsockets.h:322
lws_svg_parse
LWS_VISIBLE LWS_EXTERN lws_stateful_ret_t lws_svg_parse(lws_svg_t *svg, const uint8_t **buf, size_t *len, char hold_at_metadata)
lws_svg_get_width
LWS_VISIBLE LWS_EXTERN unsigned int lws_svg_get_width(const lws_svg_t *svg)
lws_svg_render_line
LWS_VISIBLE LWS_EXTERN lws_stateful_ret_t lws_svg_render_line(lws_svg_t *svg, const lws_svg_render_t *ri, int y, lws_svg_span_cb_t cb, void *user)
lws_svg_render::h
int h
Definition
lws-svg.h:164
lws_svg_new
LWS_VISIBLE LWS_EXTERN lws_svg_t * lws_svg_new(void)
lws_svg_span_cb_t
int(* lws_svg_span_cb_t)(void *user, int x0, int x1, uint32_t rgba)
Definition
lws-svg.h:160
lws_svg_render::w
int w
Definition
lws-svg.h:163
lws_svg_par_t
lws_svg_par_t
Definition
lws-svg.h:57
LWS_SVG_PAR_DEFAULT
@ LWS_SVG_PAR_DEFAULT
Definition
lws-svg.h:58
LWS_SVG_PAR_NONE
@ LWS_SVG_PAR_NONE
Definition
lws-svg.h:59
lws_svg_render::aa
char aa
Definition
lws-svg.h:165
lws_svg_get_height
LWS_VISIBLE LWS_EXTERN unsigned int lws_svg_get_height(const lws_svg_t *svg)
lws_svg_t
struct lws_svg lws_svg_t
Definition
lws-svg.h:39
lws_svg_render_t
struct lws_svg_render lws_svg_render_t
lws_svg_get_doc_complete
LWS_VISIBLE LWS_EXTERN char lws_svg_get_doc_complete(const lws_svg_t *svg)
lws_svg_free
LWS_VISIBLE LWS_EXTERN void lws_svg_free(lws_svg_t **svg)
lws_svg_render
Definition
lws-svg.h:162
include
libwebsockets
lws-svg.h
Generated on
for libwebsockets by
1.18.0