libwebsockets
Lightweight C library for HTML5 websockets
Loading...
Searching...
No Matches
lws-svg.h File Reference
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  lws_svg_render

Macros

#define LWS_SVG_RGBA(_r, _g, _b, _a)
#define LWS_SVG_ALPHA(_c)

Typedefs

typedef struct lws_svg lws_svg_t
typedef int(* lws_svg_span_cb_t) (void *user, int x0, int x1, uint32_t rgba)
typedef struct lws_svg_render lws_svg_render_t

Enumerations

enum  lws_svg_par_t { LWS_SVG_PAR_DEFAULT , LWS_SVG_PAR_NONE }

Functions

LWS_VISIBLE LWS_EXTERN lws_svg_tlws_svg_new (void)
LWS_VISIBLE LWS_EXTERN void lws_svg_free (lws_svg_t **svg)
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_VISIBLE LWS_EXTERN unsigned int lws_svg_get_width (const lws_svg_t *svg)
LWS_VISIBLE LWS_EXTERN unsigned int lws_svg_get_height (const lws_svg_t *svg)
LWS_VISIBLE LWS_EXTERN char lws_svg_get_doc_complete (const lws_svg_t *svg)
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)

Data Structure Documentation

◆ lws_svg_render

struct lws_svg_render

Definition at line 162 of file lws-svg.h.

Collaboration diagram for lws_svg_render:
Data Fields
int w
int h
char aa

Macro Definition Documentation

◆ LWS_SVG_RGBA

#define LWS_SVG_RGBA ( _r,
_g,
_b,
_a )
Value:
((uint32_t)(_r) & 0xff) | \
(((uint32_t)(_g) & 0xff) << 8) | \
(((uint32_t)(_b) & 0xff) << 16) | \
(((uint32_t)(_a) & 0xff) << 24))
unsigned int uint32_t

Definition at line 44 of file lws-svg.h.

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

◆ LWS_SVG_ALPHA

#define LWS_SVG_ALPHA ( _c)
Value:
((uint32_t)(((_c) >> 24) & 0xff))

Definition at line 50 of file lws-svg.h.

Typedef Documentation

◆ lws_svg_t

typedef struct lws_svg lws_svg_t

Definition at line 39 of file lws-svg.h.

◆ lws_svg_span_cb_t

typedef int(* lws_svg_span_cb_t) (void *user, int x0, int x1, uint32_t rgba)

Definition at line 160 of file lws-svg.h.

◆ lws_svg_render_t

Enumeration Type Documentation

◆ lws_svg_par_t

Enumerator
LWS_SVG_PAR_DEFAULT 
LWS_SVG_PAR_NONE 

Definition at line 57 of file lws-svg.h.

57 {
58 LWS_SVG_PAR_DEFAULT, /* xMidYMid meet */
59 LWS_SVG_PAR_NONE, /* stretch to fill */
lws_svg_par_t
Definition lws-svg.h:57
@ LWS_SVG_PAR_DEFAULT
Definition lws-svg.h:58
@ LWS_SVG_PAR_NONE
Definition lws-svg.h:59

Function Documentation

◆ lws_svg_new()

LWS_VISIBLE LWS_EXTERN lws_svg_t * lws_svg_new ( void )

lws_svg_new() - create an SVG scene parse object

Returns a new SVG scene object which should be destroyed with lws_svg_free(), or NULL if OOM.

References LWS_EXTERN, and LWS_VISIBLE.

◆ lws_svg_free()

LWS_VISIBLE LWS_EXTERN void lws_svg_free ( lws_svg_t ** svg)

lws_svg_free() - destroy an SVG scene object

Parameters
svgpointer to the scene object pointer to destroy and set NULL

This also frees the retained scene and all sub-allocations.

References LWS_EXTERN, and LWS_VISIBLE.

◆ 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_parse() - parse streaming SVG document input

Parameters
svgthe SVG scene object
bufpointer to a const uint8_t array of SVG input
lenpointer to the count of bytes available at *buf
hold_at_metadatanonzero to stop consuming once the root <svg> tag has been parsed

Makes SVG input available to the scene parser so it can build the retained vector scene. If the call consumed any input, *buf and *len are adjusted accordingly. The parser is stateful so it is not sensitive to the input chunk sizes it is fed.

If hold_at_metadata is set, parsing stops at the end of the root <svg> open tag even if further input is available at *buf, so image dimensions can be discovered before committing to retaining the whole document.

Returns LWS_SRET_OK if the document has completely parsed (ie, the root element has closed), or, when hold_at_metadata is set, as soon as the root tag parsed; LWS_SRET_WANT_INPUT if the input so far was consumed and more is needed to progress; or a return with LWS_SRET_FATAL set if the document is too broken to process. When LWS_SRET_OK is returned for the full document case, the retained scene is complete and ready for rendering; if the input ends without closing the root element, whatever parsed so far is still renderable.

References LWS_EXTERN, and LWS_VISIBLE.

◆ lws_svg_get_width()

LWS_VISIBLE LWS_EXTERN unsigned int lws_svg_get_width ( const lws_svg_t * svg)

lws_svg_get_width() - get intrinsic document width in px

Parameters
svgthe SVG scene object

Returns the intrinsic document width in px once the root tag has been parsed: the width attribute if it is in px, otherwise the viewBox width if present, otherwise the CSS default replaced element width. Returns 0 if the root tag has not been parsed yet.

References LWS_EXTERN, and LWS_VISIBLE.

◆ lws_svg_get_height()

LWS_VISIBLE LWS_EXTERN unsigned int lws_svg_get_height ( const lws_svg_t * svg)

lws_svg_get_height() - get intrinsic document height in px

Parameters
svgthe SVG scene object

As lws_svg_get_width(), but for the document height.

References LWS_EXTERN, and LWS_VISIBLE.

◆ lws_svg_get_doc_complete()

LWS_VISIBLE LWS_EXTERN char lws_svg_get_doc_complete ( const lws_svg_t * svg)

lws_svg_get_doc_complete() - has the whole document been parsed?

Parameters
svgthe SVG scene object

Returns nonzero if the root element has closed (or an unrecoverable truncated-document condition was reached), so the retained scene will not change any further.

◆ 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_line() - render a single raster line of the scene

Parameters
svgthe SVG scene object
rirender mapping info (output raster size)
ythe output line to render, 0 .. ri->h - 1
cbcallback to receive filled spans on the line
useropaque user pointer passed to the callback

Maps the retained user-space geometry into a ri->w x ri->h px raster according to the document's viewBox and preserveAspectRatio policy, and renders output line y of it by scanline intersection of the flattened geometry, delivering the filled spans via cb in document order.

Sample points are at pixel centres, so with the default binary coverage a pixel is either covered or not. With ri->aa set, coverage is the exact covered fraction of the pixel square, computed as the area integral of the winding function over the pixel (each band-clipped boundary edge contributes clipped-linear ramp areas, with no supersampling): corners, thin features and slivers between scanlines are handled exactly, and the span alpha carries the fractional coverage for compositing.

Lines can be rendered in any order and repeatedly; the scene is not modified except for internal scratch reallocation. Calls on the same scene object are not reentrant against each other.

Returns LWS_SRET_OK, or LWS_SRET_FATAL if an internal allocation failed.