ra8-firmware 0.1.0
Bare-metal firmware for the Renesas RA8 family (RA8D2 / RA8P1)
Loading...
Searching...
No Matches
rabook_compile.h
Go to the documentation of this file.
1
46#pragma once
47
48#ifdef __cplusplus
49extern "C" {
50#endif
51
52#include <stdint.h>
53
54#include "book.h"
55#include "ra8_err.h"
56
66typedef struct {
67 /* Pointers grouped before the uint32 caps so the 64-bit host unit-test
68 * build has zero inter-field padding (clang-analyzer optin.performance). */
75 uint8_t* image_pool;
76 uint8_t* out;
77 uint32_t chapter_cap;
78 uint32_t node_cap;
79 uint32_t attr_cap;
80 uint32_t stylesheet_cap;
81 uint32_t image_cap;
82 uint32_t string_cap;
83 uint32_t image_pool_cap;
84 uint32_t out_cap;
86
98typedef struct {
100 uint32_t chapter_count;
101 uint32_t node_count;
102 uint32_t attr_count;
104 uint32_t image_count;
105 uint32_t string_size;
107 uint32_t title_off;
108 uint32_t author_off;
109 uint32_t language_off;
110 uint32_t identifier_off;
112 uint32_t flags;
114 bool failed;
116
131 uint32_t offset,
132 uint8_t* dst,
133 uint32_t requested,
134 uint32_t* out_read);
135
148typedef ra8_err_t (*ra8_rabook_write_fn)(void* ctx,
149 const uint8_t* src,
150 uint32_t requested,
151 uint32_t* out_written);
152
175
196uint32_t ra8_rabook_intern(ra8_rabook_ctx_t* ctx, const char* str);
197
219 uint32_t name_off,
220 const book_attr_t* attrs,
221 uint16_t attr_count);
222
239uint32_t ra8_rabook_add_text(ra8_rabook_ctx_t* ctx, uint32_t text_off);
240
259ra8_err_t ra8_rabook_link_child(ra8_rabook_ctx_t* ctx, uint32_t parent, uint32_t child);
260
280ra8_rabook_link_sibling(ra8_rabook_ctx_t* ctx, uint32_t previous_node, uint32_t next_sibling);
281
302 uint32_t title_off,
303 uint32_t href_off,
304 uint32_t root_node);
305
333 uint32_t id_off,
334 uint16_t width,
335 uint16_t height,
336 uint8_t format,
337 uint8_t pixel_format,
338 const uint8_t* data,
339 uint32_t data_size);
340
368 uint32_t id_off,
369 uint16_t width,
370 uint16_t height,
371 uint8_t format,
372 uint8_t pixel_format,
373 uint32_t data_size,
374 uint32_t* out_data_off);
375
394uint32_t
395ra8_rabook_add_stylesheet(ra8_rabook_ctx_t* ctx, uint32_t source_off, uint32_t scope_chapter);
396
424 uint32_t title_off,
425 uint32_t author_off,
426 uint32_t language_off,
427 uint32_t identifier_off,
428 uint32_t cover_image_index);
429
459ra8_err_t ra8_rabook_finalize(ra8_rabook_ctx_t* ctx, const void** out_blob, uint32_t* out_len);
460
494 ra8_rabook_image_read_fn image_read,
495 void* image_ctx,
497 void* write_ctx,
498 uint8_t* scratch,
499 uint32_t scratch_cap,
500 uint32_t* out_len);
501
502#ifdef __cplusplus
503} /* extern "C" */
504#endif
Flat, execute-in-place container for a build-time "compiled" e-book.
-proof
Error Code Definitions for ra8-firmware.
ra8_err_codes_t ra8_err_t
Canonical error-return type used by every ra8-firmware API.
Definition ra8_err.h:546
uint32_t ra8_rabook_add_element(ra8_rabook_ctx_t *ctx, uint32_t name_off, const book_attr_t *attrs, uint16_t attr_count)
Append an element node with its attributes; return its node index.
ra8_err_t ra8_rabook_link_sibling(ra8_rabook_ctx_t *ctx, uint32_t previous_node, uint32_t next_sibling)
Set previous_node's next sibling to next_sibling.
uint32_t ra8_rabook_add_text(ra8_rabook_ctx_t *ctx, uint32_t text_off)
Append a text node carrying text_off; return its node index.
ra8_err_t ra8_rabook_finalize(ra8_rabook_ctx_t *ctx, const void **out_blob, uint32_t *out_len)
Lay out the tables and pools, fill the header, CRC, and emit the blob.
ra8_err_t ra8_rabook_link_child(ra8_rabook_ctx_t *ctx, uint32_t parent, uint32_t child)
Set parent's first child to child.
uint32_t ra8_rabook_intern(ra8_rabook_ctx_t *ctx, const char *str)
Intern a NUL-terminated UTF-8 string into the pool, de-duplicated.
ra8_err_t(* ra8_rabook_image_read_fn)(void *ctx, uint32_t offset, uint8_t *dst, uint32_t requested, uint32_t *out_read)
Read bytes from an externally stored image pool.
uint32_t ra8_rabook_add_image(ra8_rabook_ctx_t *ctx, uint32_t id_off, uint16_t width, uint16_t height, uint8_t format, uint8_t pixel_format, const uint8_t *data, uint32_t data_size)
Append an image descriptor and copy its pixel/SVG bytes into the pool.
ra8_err_t ra8_rabook_set_metadata(ra8_rabook_ctx_t *ctx, uint32_t title_off, uint32_t author_off, uint32_t language_off, uint32_t identifier_off, uint32_t cover_image_index)
Record the book metadata offsets that land in the blob header.
ra8_err_t(* ra8_rabook_write_fn)(void *ctx, const uint8_t *src, uint32_t requested, uint32_t *out_written)
Append bytes to a streaming RABOOK1 destination.
uint32_t ra8_rabook_add_image_external(ra8_rabook_ctx_t *ctx, uint32_t id_off, uint16_t width, uint16_t height, uint8_t format, uint8_t pixel_format, uint32_t data_size, uint32_t *out_data_off)
Append an image descriptor whose bytes live in a caller-owned spool.
uint32_t ra8_rabook_add_stylesheet(ra8_rabook_ctx_t *ctx, uint32_t source_off, uint32_t scope_chapter)
Append a preserved stylesheet; return its stylesheet index.
uint32_t ra8_rabook_add_chapter(ra8_rabook_ctx_t *ctx, uint32_t title_off, uint32_t href_off, uint32_t root_node)
Append a spine chapter; return its chapter index.
ra8_err_t rabook_compile_init(ra8_rabook_ctx_t *ctx, const ra8_rabook_buffers_t *buf)
Bind a builder context to its caller-provided arenas.
ra8_err_t ra8_rabook_finalize_stream(const ra8_rabook_ctx_t *ctx, ra8_rabook_image_read_fn image_read, void *image_ctx, ra8_rabook_write_fn write, void *write_ctx, uint8_t *scratch, uint32_t scratch_cap, uint32_t *out_len)
Stream a canonical flat RABOOK1 blob without a full output arena.
One name="value" attribute on an element.
Definition book.h:317
One spine document (a renderable chapter) plus its TOC label.
Definition book.h:280
Descriptor for one transcoded image in the image pool.
Definition book.h:354
One DOM node.
Definition book.h:299
A preserved CSS stylesheet and the chapter it scopes to.
Definition book.h:332
Caller-owned, fixed-capacity arenas the builder appends into (no heap).
uint32_t out_cap
Output capacity in bytes.
uint32_t attr_cap
Max attribute records.
uint8_t * image_pool
Image-pool byte arena.
uint32_t chapter_cap
Max chapters.
uint32_t stylesheet_cap
Max stylesheets.
char * string_pool
String-pool byte arena.
uint32_t image_cap
Max image descriptors.
uint32_t image_pool_cap
Image-pool capacity in bytes.
book_image_t * images
Image-table arena.
uint32_t string_cap
String-pool capacity in bytes.
book_stylesheet_t * stylesheets
Stylesheet-table arena.
uint32_t node_cap
Max DOM nodes.
book_node_t * nodes
Node-table arena.
uint8_t * out
Final-blob output buffer.
book_attr_t * attrs
Attribute-table arena.
book_chapter_t * chapters
Chapter-table arena.
Builder state: the arenas plus running counts and a sticky-fail flag.
bool failed
Sticky: an arena overflowed.
uint32_t title_off
Metadata: title string offset.
uint8_t image_pool_mode
Internal builder storage mode.
uint32_t string_size
String-pool bytes used.
uint32_t stylesheet_count
Stylesheets appended so far.
uint32_t cover_image_index
Cover image index, or nil.
uint32_t image_pool_size
Image-pool bytes used.
ra8_rabook_buffers_t buf
Caller-provided arenas.
uint32_t language_off
Metadata: language string offset.
uint32_t chapter_count
Chapters appended so far.
uint32_t node_count
Nodes appended so far.
uint32_t image_count
Images appended so far.
uint32_t flags
Reserved header flags (0 in v1).
uint32_t author_off
Metadata: author string offset.
uint32_t identifier_off
Metadata: identifier string offset.
uint32_t attr_count
Attributes appended so far.