41typedef enum : uint16_t {
47 "pipeline chapter cap must match epub cap");
49 "pipeline toc cap must match epub cap");
56typedef enum : uint8_t {
60static const char*
const s_tag =
"ra8_rabook_pipeline";
69#ifndef RA8_RABOOK_NO_RASTER
95 const uint8_t* pixels,
101 if ((ow == sw) && (oh == sh)) {
104 if (((uint32_t)ow * (uint32_t)oh) > scr->
gray_cap) {
139 const uint8_t* gray_src,
199 if (pixels ==
nullptr) {
207 uint16_t ow = (uint16_t)sw;
208 uint16_t oh = (uint16_t)sh;
213 const uint8_t* gray_src =
215 if (gray_src ==
nullptr) {
216 stbi_image_free(pixels);
221 uint32_t encoded_size = 0U;
223 stbi_image_free(pixels);
263 uint16_t chapter_idx,
267 for (uint16_t ti = 0U; ti < toc_count; ti++) {
268 uint16_t ch_idx = 0U;
271 return entry_buf->
title;
338 for (uint16_t i = 0U; i < count; i++) {
340 if (item ==
nullptr) {
355 scr->
css[got] =
'\0';
392 const char*
const img_prefix =
"image/";
402#ifdef RA8_RABOOK_NO_RASTER
426#ifndef RA8_RABOOK_NO_RASTER
466 uint32_t* cover_index_out)
473 for (uint16_t i = 0U; i < count; i++) {
475 if (item ==
nullptr) {
483 *cover_index_out = idx;
513 uint16_t chapter_count = 0U;
519 uint16_t toc_count = 0U;
524 for (uint16_t ci = 0U; ci < chapter_count; ci++) {
610 const void** out_blob,
624 uint32_t cover_image_index = (uint32_t)
k_book_nil;
647 const void** out_blob,
Flat, execute-in-place container for a build-time "compiled" e-book.
@ k_book_nil
Absent index / "applies to all chapters".
@ k_book_image_svg
Verbatim UTF-8 SVG source (vector; on-device rasterized).
@ k_book_image_gray4
4bpp gray, 2px/byte; pixel (x,y) is at flat index y*width + x.
@ 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).
EPUB (.epub) reader and chapter iterator for ra8-firmware.
uint16_t epub_manifest_count(const epub_book_t *book)
Number of <manifest> <item> entries retained (#151).
const epub_manifest_item_t * epub_manifest_item(const epub_book_t *book, uint16_t index)
Borrow the manifest item at index (OPF document order, #151).
ra8_err_t epub_toc_entry_to_chapter(const epub_book_t *book, uint16_t toc_idx, uint16_t *out_chapter_idx)
Resolve a TOC entry to the spine chapter index it points into.
ra8_err_t epub_get_metadata(const epub_book_t *book, epub_metadata_t *out_meta)
Return Dublin Core metadata strings.
ra8_err_t epub_load_chapter(epub_book_t *book, uint16_t idx, uint8_t *out_xhtml, size_t max_len, size_t *got_len)
Extract the raw XHTML bytes of one chapter into the caller's buffer.
@ k_epub_max_toc
Max table-of-contents entries we keep.
@ k_epub_max_chapters
Max spine length we accept.
ra8_err_t epub_get_toc_entry(const epub_book_t *book, uint16_t idx, epub_toc_entry_t *out_entry)
Copy one table-of-contents entry into the caller's struct.
ra8_err_t epub_get_chapter_count(const epub_book_t *book, uint16_t *out_count)
Report how many chapters the spine contains.
ra8_err_t epub_get_toc_count(const epub_book_t *book, uint16_t *out_count)
Report how many table-of-contents entries the book exposes.
ra8_err_t epub_get_resource(epub_book_t *book, const char *path, uint8_t *out_buf, size_t max_len, size_t *got_len)
Copy the raw bytes of an arbitrary archive resource into the caller's buffer (#140 external styleshee...
static const char * s_tag
Logging / check tag.
Annotation-attribute framework macros for ra8-firmware.
#define RA8_PRIV
Module-private helper: shared across TUs but only inside one library.
#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.
Error Code Definitions for ra8-firmware.
@ k_ra8_ok
Success – operation completed with all postconditions satisfied.
@ k_ra8_err_not_found
Requested item not found (lookup / search missed).
ra8_err_codes_t ra8_err_t
Canonical error-return type used by every ra8-firmware API.
int strncmp(const char *s1, const char *s2, size_t n)
Compare two strings up to a specified length.
int strcmp(const char *s1, const char *s2)
Compare two null-terminated strings.
size_t strlen(const char *s)
Calculate string length.
Minimal FAT12/FAT16/FAT32 filesystem adapter (read + write).
Heap-free scratch allocator hooks for the stb_image single-TU build.
void ra8_img_arena_bind(ra8_img_arena_t *arena)
Bind arena as the active scratch for subsequent decode allocations.
void ra8_img_arena_unbind(void)
Unbind the active arena; subsequent allocation hooks fail with nullptr.
Lightweight Logging Interface for ra8-firmware.
#define ra8_log_error(tag, message)
RA8 log error.
Grayscale image transcode stage (4-bpp / 8-bpp) for the on-device EPUB compiler (#149).
ra8_err_t ra8_rabook_gray4_encode(const uint8_t *gray_pixels, uint16_t w, uint16_t h, uint8_t *out, uint32_t out_cap, uint32_t *out_size)
Quantise a grayscale buffer to 16 levels and pack as 4-bpp nibbles.
ra8_err_t ra8_rabook_gray4_downscale(const uint8_t *src, uint16_t src_w, uint16_t src_h, uint8_t *dst, uint16_t dst_w, uint16_t dst_h)
Bilinear-interpolate a grayscale image from (src_w x src_h) to (dst_w x dst_h).
ra8_err_t ra8_rabook_gray8_encode(const uint8_t *gray_pixels, uint16_t w, uint16_t h, uint8_t *out, uint32_t out_cap, uint32_t *out_size)
Copy a grayscale buffer out verbatim as 8-bpp (one byte per pixel).
void ra8_rabook_gray4_output_dims(uint16_t src_w, uint16_t src_h, uint16_t max_edge, uint16_t *out_w, uint16_t *out_h)
Compute scaled output dimensions keeping the longer edge within max_edge.
static ra8_err_t internal_encode_gray(const ra8_rabook_pipeline_scratch_t *scr, const uint8_t *gray_src, uint16_t ow, uint16_t oh, uint32_t *out_size)
Encode gray_src into scr->image_raw at the device-profile depth.
static ra8_err_t internal_compile_images(ra8_rabook_ctx_t *ctx, const ra8_rabook_pipeline_scratch_t *scr, epub_book_t *epub, uint32_t *cover_index_out)
Compile every manifest image into the builder, resolving the cover.
ra8_pipeline_stbi_t
stb_image channel-count selector (no magic literals).
@ k_stbi_grey
Request 8-bit grayscale output from stb_image.
static const char * internal_chapter_title(const epub_book_t *epub, uint16_t chapter_idx, uint16_t toc_count, epub_toc_entry_t *entry_buf)
Find the TOC title for one spine chapter (first-entry-wins).
ra8_err_t rabook_compile_from_epub_to_buffer(epub_book_t *epub, const ra8_rabook_buffers_t *bufs, const ra8_rabook_pipeline_scratch_t *scr, const void **out_blob, uint32_t *out_len)
Compile an open EPUB into a RABOOK1 blob left in bufs->out, with no filesystem write.
ra8_pipeline_limits_t
Static bounds used for NASA Rule 2 loop annotations.
@ k_pipeline_max_toc
== k_epub_max_toc (cross-check).
@ k_pipeline_max_chapters
== k_epub_max_chapters (cross-check).
static uint32_t internal_transcode_image(ra8_rabook_ctx_t *ctx, const ra8_rabook_pipeline_scratch_t *scr, uint32_t id_off, size_t raw_len)
Decode one raw image, transcode to the profile's gray depth, add to builder.
static ra8_err_t internal_compile_chapters(epub_book_t *epub, const ra8_rabook_pipeline_scratch_t *scr, ra8_rabook_ctx_t *ctx)
Parse every spine chapter into the builder DOM.
static const uint8_t * internal_downscale_if_needed(const ra8_rabook_pipeline_scratch_t *scr, const uint8_t *pixels, uint16_t sw, uint16_t sh, uint16_t ow, uint16_t oh)
Resolve the gray source buffer for the encode, downscaling if required.
static ra8_err_t internal_compile_to_blob(epub_book_t *epub, const ra8_rabook_buffers_t *bufs, const ra8_rabook_pipeline_scratch_t *scr, const void **out_blob, uint32_t *out_len)
Run the compile stages and finalize the RABOOK1 blob in bufs->out.
static uint32_t internal_add_manifest_image(ra8_rabook_ctx_t *ctx, const ra8_rabook_pipeline_scratch_t *scr, epub_book_t *epub, const epub_manifest_item_t *item)
Add one manifest item to the builder if it is an image.
ra8_err_t priv_rabook_pipeline_check_common(const epub_book_t *epub, const ra8_rabook_buffers_t *bufs, const ra8_rabook_pipeline_scratch_t *scr)
Reject any NULL among the three arguments common to both compile entry points (rabook_compile_from_ep...
static ra8_err_t internal_compile_metadata(ra8_rabook_ctx_t *ctx, epub_book_t *epub, uint32_t cover_image_index)
Intern the Dublin Core metadata and record it (the final emit stage).
static ra8_err_t internal_compile_stylesheets(ra8_rabook_ctx_t *ctx, const ra8_rabook_pipeline_scratch_t *scr, epub_book_t *epub)
Emit each text/css manifest item as a stylesheet, in OPF order.
End-to-end EPUB -> RABOOK1 compile pipeline (#149).
Private validation seam shared by RABOOK pipeline entry points.
Bounded XHTML-to-RABOOK streaming builder.
ra8_err_t ra8_rabook_xml_parse_chapter(const uint8_t *xhtml_bytes, size_t xhtml_len, ra8_rabook_ctx_t *ctx, const char *chapter_href, const char *chapter_title, ra8_rabook_xml_workspace_t *workspace)
Parse one XHTML chapter and append it to ctx.
Zero-heap builder that emits a RABOOK1 blob (the #149 compiler back-end).
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.
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.
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.
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.
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.
Zero-heap raster image decode + scale + blit for reflow (#106).
char chapter_paths[k_epub_max_chapters][k_epub_max_path_len]
Manifest hrefs (relative to OPF dir).
char cover_path[k_epub_max_path_len]
Path to cover image (or empty).
One <manifest> <item> entry, retained in OPF document order.
char media_type[k_epub_media_len]
Item media-type (or "" if absent).
char href[k_epub_max_path_len]
Item href (relative to the OPF dir).
One titled entry in the table of contents.
char title[k_epub_meta_len]
Navigation label text ("" if none).
Caller-owned, fixed-capacity arenas the builder appends into (no heap).
Builder state: the arenas plus running counts and a sticky-fail flag.
Caller-owned temporary buffers the pipeline stage needs.
uint16_t max_image_edge
Opt-in downscale clamp on the longer edge in pixels; 0 (the zero-init default) preserves source resol...
uint8_t pixel_format
Device profile: raster depth to emit, book_image_pixfmt_t.
uint32_t gray_cap
Capacity of gray in pixels (bytes).
uint8_t * gray
Intermediate gray-pixel downscale buffer.
char * css
Stylesheet load scratch (NUL-terminated).
size_t xhtml_cap
Capacity of xhtml in bytes.
uint8_t * image_raw
Raw encoded cover/image byte buffer.
ra8_rabook_xml_workspace_t * xml_workspace
Caller-owned XHTML parser state.
bool skip_images
Drop all images (text/CSS-only).
size_t image_cap
Capacity of image_raw in bytes.
size_t css_cap
Capacity of css in bytes.
ra8_img_arena_t * img_arena
stb_image bump arena (caller-sized scratch).
uint8_t * xhtml
Chapter XHTML scratch buffer.