|
libwebsockets
Lightweight C library for HTML5 websockets
|
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_t * | lws_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) |
| struct lws_svg_render |
| #define LWS_SVG_RGBA | ( | _r, | |
| _g, | |||
| _b, | |||
| _a ) |
Definition at line 44 of file lws-svg.h.
| #define LWS_SVG_ALPHA | ( | _c | ) |
| 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 |
| enum lws_svg_par_t |
| Enumerator | |
|---|---|
| LWS_SVG_PAR_DEFAULT | |
| LWS_SVG_PAR_NONE | |
Definition at line 57 of file lws-svg.h.
| 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_VISIBLE LWS_EXTERN void lws_svg_free | ( | lws_svg_t ** | svg | ) |
lws_svg_free() - destroy an SVG scene object
| svg | pointer 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_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
| svg | the SVG scene object |
| buf | pointer to a const uint8_t array of SVG input |
| len | pointer to the count of bytes available at *buf |
| hold_at_metadata | nonzero 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_VISIBLE LWS_EXTERN unsigned int lws_svg_get_width | ( | const lws_svg_t * | svg | ) |
lws_svg_get_width() - get intrinsic document width in px
| svg | the 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_VISIBLE LWS_EXTERN unsigned int lws_svg_get_height | ( | const lws_svg_t * | svg | ) |
lws_svg_get_height() - get intrinsic document height in px
| svg | the SVG scene object |
As lws_svg_get_width(), but for the document height.
References LWS_EXTERN, and LWS_VISIBLE.
| 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?
| svg | the 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_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
| svg | the SVG scene object |
| ri | render mapping info (output raster size) |
| y | the output line to render, 0 .. ri->h - 1 |
| cb | callback to receive filled spans on the line |
| user | opaque 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.