40typedef enum : uint32_t {
52 out->
base = (
const uint8_t*)base;
116 uint8_t* d = (uint8_t*)dst;
118 uint32_t remaining = len;
120 for (uint32_t it = 0U; (it < max_iter) && (remaining > 0U); ++it) {
121 void* page =
nullptr;
127 const uint32_t avail = src->
frame_bytes - in_frame;
128 const uint32_t n = (remaining < avail) ? remaining : avail;
129 (void)
memcpy(d, &((
const uint8_t*)page)[in_frame], n);
145 if (((uint64_t)off + (uint64_t)len) > (uint64_t)src->
size) {
151 if (src->
base !=
nullptr) {
155 if (src->
vm ==
nullptr) {
180typedef enum : uint32_t {
227 const uint32_t row_flat = (ry * (uint32_t)img->
width) + x;
231 for (uint32_t it = 0U; it < max_iter; ++it) {
235 const uint32_t remain = w - done;
238 const uint32_t flat0 = row_flat + done;
239 const uint32_t first = flat0 >> 1U;
240 const uint32_t last = (flat0 + cpx - 1U) >> 1U;
241 const uint32_t n = (last - first) + 1U;
244 if ((off + (uint64_t)n) > (uint64_t)src->
size) {
251 for (uint32_t i = 0U; i < cpx; ++i) {
252 const uint32_t flat = flat0 + i;
253 const uint8_t
byte = packed[(flat >> 1U) - first];
303 const uint32_t row_flat = (ry * (uint32_t)img->
width) + x;
308 if ((off + (uint64_t)w) <= (uint64_t)src->
size) {
347 if ((w == 0U) || (h == 0U) || (out_stride < w)) {
350 if ((((uint64_t)x + (uint64_t)w) > (uint64_t)img->
width) ||
351 (((uint64_t)y + (uint64_t)h) > (uint64_t)img->
height)) {
355 for (uint32_t row = 0U; row < h; ++row) {
356 uint8_t*
const dst = &out[(size_t)row * (
size_t)out_stride];
380typedef enum : uint32_t {
449 if (abs_off >= src->
size) {
452 const uint32_t remain = src->
size - abs_off;
453 const uint32_t want = cap - 1U;
454 const uint32_t chunk = (remain < want) ? remain : want;
460 while ((nlen < chunk) && (buf[nlen] !=
'\0')) {
507 uint32_t off = abs_off;
508 const uint32_t max_iter =
510 for (uint32_t it = 0U; it < max_iter; ++it) {
511 if (off >= src->
size) {
514 const uint32_t remain = src->
size - off;
516 const uint32_t chunk = (remain < want) ? remain : want;
523 while ((nlen < chunk) && (buf[nlen] !=
'\0')) {
660 uint32_t* stack = s_paged_stack;
663 bool at_break =
true;
669 while ((sp > 0U) && ok && (guard < max_iter)) {
672 const uint32_t n = stack[sp];
678 return ok && (guard < max_iter);
682 uint32_t chapter_idx,
695 if (src->
base !=
nullptr) {
725 if (src->
vm ==
nullptr) {
742 const uint64_t noff =
Flat, execute-in-place container for a build-time "compiled" e-book.
ra8_err_t book_chapter_text(const void *base, uint32_t chapter_idx, char *out, size_t cap, size_t *out_len)
Extract one chapter's readable plain text from the DOM.
@ k_book_node_text
A text run: carries a string, no children.
@ k_book_nil
Absent index / "applies to all chapters".
@ k_book_image_gray4
4bpp gray, 2px/byte; pixel (x,y) is at flat index y*width + x.
static book_image_pixfmt_t book_image_pixfmt(const book_image_t *img)
Declared pixel depth of one image descriptor.
book_image_pixfmt_t
Pixel depth of a k_book_image_gray4 raster in the image pool.
@ k_book_pixfmt_gray4
4bpp packed grayscale, 2px/byte (default; every pre-field blob).
@ k_book_pixfmt_gray8
8bpp grayscale, 1px/byte (lossless against any grey panel).
book DOM-walk helpers shared across the library's translation units.
bool priv_book_is_block(const char *name)
Test whether an element name is a block-level HTML element.
bool priv_book_emit_break(char *out, size_t cap, size_t *pos, bool *at_break)
Append a paragraph break, collapsing consecutive block-level breaks.
bool priv_book_emit_text(char *out, size_t cap, size_t *pos, const char *str, bool *at_break)
Append a whitespace-collapsed text run to the output buffer.
@ k_book_xhtml_stack
Max pending open/close walk entries.
@ k_book_xhtml_iter_x
Iteration-guard multiplier over node_count.
ra8_err_t book_src_paged(book_src_t *out, ra8_vmem_t *vm, uint32_t object_id, uint32_t frame_bytes, uint32_t size)
Bind a paged book source over an ra8_vmem cache + ra8_vsource object.
static ra8_err_t internal_paged_node(const book_src_t *src, uint32_t idx, book_node_t *out)
Read one DOM node record out of a paged/resident book source by index.
static const char *const s_tag_paged
Log tag for paged-source diagnostics.
static ra8_err_t internal_book_image_row(const book_src_t *src, const book_image_t *img, uint32_t x, uint32_t ry, uint32_t w, uint8_t *out)
Unpack one horizontal gray4 run [x, x+w) of source row ry to gray8.
static ra8_err_t internal_paged_str_short(const book_src_t *src, uint32_t abs_off, char *buf, uint32_t cap)
Copy a short NUL-terminated string (a tag name) out into a buffer.
book_paged_bound_t
Loop-bound headroom for the frame-by-frame copy-out (NASA Rule 2).
@ k_book_paged_min_frame
Smallest accepted frame size (Rule-2 bound).
@ k_book_paged_span_pad
Extra frame iterations over the exact span.
book_image_rect_const_t
4bpp nibble packing + the per-read pixel budget (no magic numbers).
@ k_book_rect_chunk_pad
Loop-bound headroom over ceil(w / k_book_rect_chunk_px).
@ k_book_gray4_nib_sh
Nibble shift and 4->8 bit replicate amount.
@ k_book_gray4_ppb
Pixels packed per pool byte.
@ k_book_rect_chunk_px
Max pixels unpacked per bounded span read.
@ k_book_gray4_nib_lo
Low-nibble mask (odd flat index).
ra8_err_t book_src_image_rect(const book_src_t *src, const book_image_t *img, uint32_t x, uint32_t y, uint32_t w, uint32_t h, uint8_t *out, uint32_t out_stride)
Read a sub-rectangle of a raster image (4bpp or 8bpp) as gray8, row by row.
static ra8_err_t internal_book_image_row_gray8(const book_src_t *src, const book_image_t *img, uint32_t x, uint32_t ry, uint32_t w, uint8_t *out)
Copy one horizontal gray8 run [x, x+w) of source row ry into out.
ra8_err_t book_src_prefetch_chapter(const book_src_t *src, uint32_t chapter_idx)
Warm the cache frame holding a chapter's first content bytes, without pinning it (single-threaded rea...
static ra8_err_t internal_book_src_read_paged(const book_src_t *src, uint32_t off, void *dst, uint32_t len)
Copy a byte range out of a paged source, frame by frame.
static bool internal_paged_visit_node(const book_src_t *src, uint32_t n, char *out, size_t cap, size_t *pos, bool *at_break, uint32_t *stack, uint32_t *sp, ra8_err_t *io_err)
Process one popped node in the paged text walk.
static bool internal_walk_text_paged(const book_src_t *src, uint32_t root, uint32_t node_count, char *out, size_t cap, size_t *pos, ra8_err_t *io_err)
Bounded pre-order text walk over a paged book source.
ra8_err_t book_src_resident(book_src_t *out, const void *base, uint32_t size)
Bind a resident (already-inflated, fully resident) book as a source.
static bool internal_paged_emit_run(const book_src_t *src, uint32_t abs_off, char *out, size_t cap, size_t *pos, bool *at_break, ra8_err_t *io_err)
Emit one text run from a paged source, collapsing whitespace.
ra8_err_t book_src_image(const book_src_t *src, uint32_t idx, book_image_t *out_img)
Read one image descriptor out of a book source (resident or paged).
book_paged_walk_bound_t
Staging sizes and loop bounds for the paged text walk (no magic numbers).
@ k_book_paged_tagbuf
Staging for one (short) element tag name.
@ k_book_paged_strbuf
Staging chunk for a paged text run.
@ k_book_paged_pad
Loop-bound headroom over the exact span.
ra8_err_t book_src_read(const book_src_t *src, uint32_t off, void *dst, uint32_t len)
Copy a byte range out of a book source (resident memcpy or paged fault).
ra8_err_t book_chapter_text_src(const book_src_t *src, uint32_t chapter_idx, char *out, size_t cap, size_t *out_len)
Extract one chapter's plain text from a book source (resident or paged).
Paged (demand-fetched) accessor mode for book over ra8_vmem (#163).
Annotation-attribute framework macros for ra8-firmware.
#define RA8_INTERNAL
Marker that a function is intended to be static (file-local).
Validation and Error-Checking Macros for ra8-firmware.
#define RA8_CHECK_NULL_PTR(ptr, tag, message)
Reject nullptr pointer, returning k_ra8_err_null_ptr.
@ k_ra8_err_out_of_range
Sensor or peripheral output out of valid range.
@ k_ra8_err_invalid_arg
Invalid function argument.
@ k_ra8_err_invalid_state
Module in wrong state for requested operation.
@ k_ra8_ok
Success – operation completed with all postconditions satisfied.
@ k_ra8_err_invalid_size
Invalid size parameter (too large, too small, or misaligned).
ra8_err_codes_t ra8_err_t
Canonical error-return type used by every ra8-firmware API.
void * memcpy(void *dst, const void *src, size_t n)
Copy memory area between non-overlapping regions.
Byte-range page cache with SLRU eviction (Layer 2, #147).
ra8_err_t ra8_vmem_put(ra8_vmem_t *vm, void *page)
Release one pin on a frame previously returned by ra8_vmem_get.
ra8_err_t ra8_vmem_get(ra8_vmem_t *vm, uint32_t object_id, uint64_t offset, void **out_page)
Get (and pin) the frame holding object object_id at offset.
ra8_err_t ra8_vmem_prefetch(ra8_vmem_t *vm, uint32_t object_id, uint64_t offset)
Warm the frame holding object object_id at offset into the cache without holding a pin (single-thread...
One spine document (a renderable chapter) plus its TOC label.
uint32_t root_node
Node-table index of this chapter's root element.
Descriptor for one transcoded image in the image pool.
uint16_t height
Pixel height.
uint8_t format
book_image_format_t.
uint16_t width
Pixel width.
uint32_t data_off
Image-pool offset of the compressed pixel data.
uint8_t kind
book_node_kind_t.
uint32_t text_off
Text: string-pool offset of the run (element: 0).
uint32_t next_sibling
Index of next sibling node, or nil.
uint32_t name_off
Element: string-pool offset of tag name (text: 0).
uint32_t first_child
Index of first child node, or nil.
A book data source: resident (zero-copy) or paged (demand-fetched).
book_header_t hdr
Resident copy of the blob header.
uint32_t size
Total blob length in bytes.
const uint8_t * base
Resident blob base, or NULL in paged mode.
uint32_t frame_bytes
Paged: ra8_vmem frame size, for slice math.
ra8_vmem_t * vm
Paged page cache, or NULL in resident mode.
uint32_t object_id
Paged: the book's ra8_vsource object id.
Page-cache state (caller-owned; treat as private).