28#if __has_include("ra8_tile_cache.h") && __has_include("jof.h")
45static const char*
const s_tag =
"epub_img_tiles";
98internal_entry_pread(
void* ctx, uint64_t offset, uint8_t* buf,
size_t len,
size_t* got)
174 const jof_pread_fn pread = (src->
book !=
nullptr) ? internal_entry_pread : src->pread;
175 void* pctx = (src->
book !=
nullptr) ? (
void*)src : src->
pread_ctx;
201 uint32_t scratch_cap)
205 (void)
memset(binder, 0,
sizeof(*binder));
207 binder->
scratch_cap = (scratch !=
nullptr) ? scratch_cap : 0U;
277 (void)
memset(src, 0,
sizeof(*src));
290 const size_t plen =
strlen(path);
294 ra8_err_t err = internal_check_slot(binder, image_id);
299 (void)
memset(src, 0,
sizeof(*src));
300 err = internal_fill_book_source(src, book, path, plen, image_id);
316 ra8_err_t err = internal_check_slot(binder, image_id);
321 (void)
memset(src, 0,
sizeof(*src));
328 (void)
memset(src, 0,
sizeof(*src));
367 const ra8_tile_key_t key = {.image_id = image_id, .tile_x = tile_x, .tile_y = tile_y};
383 uint16_t* out_warmed)
397 .max_tiles = max_tiles,
426 if (ld->
book ==
nullptr) {
435 if (href_len == 0U) {
463static ra8_err_t internal_loader_null_ok(
const void* ctx,
465 const uint8_t** out_bytes,
466 const size_t* out_len)
478 const uint8_t** out_bytes,
481 const ra8_err_t nz = internal_loader_null_ok(ctx, href, out_bytes, out_len);
487 const ra8_err_t ok = internal_loader_args_ok(ld, href_len);
492 (void)
memcpy(path, href, (
size_t)href_len);
493 path[href_len] =
'\0';
EPUB (.epub) reader and chapter iterator for ra8-firmware.
@ k_epub_max_path_len
Max href length (incl.
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...
Iterative, bounded-RAM ZIP-entry extraction for the EPUB reader (#231).
ra8_err_t epub_entry_pread(epub_book_t *book, const char *path, uint64_t offset, uint8_t *buf, size_t len, size_t *got)
Positioned read of a stored (uncompressed) archive entry – windowed random access in bounded RAM (#23...
ra8_err_t epub_entry_close(epub_entry_reader_t *reader)
Tear down a streaming-entry cursor and release its inflate state (#231).
ra8_err_t epub_entry_open(epub_book_t *book, const char *path, epub_entry_reader_t *out_reader, uint64_t *out_size)
Begin a bounded-RAM streaming extraction of one archive entry (#231).
int epub_img_tiles_unused_translation_unit_t
Page a large in-EPUB image through ra8_tile_cache + a real reflow <img> loader off the streaming read...
ra8_err_t epub_tile_binder_add(epub_tile_binder_t *binder, epub_book_t *book, const char *path, uint32_t image_id)
Register a stored in-archive JOF atlas entry under image_id (#231).
ra8_err_t epub_tile_binder_info(const epub_tile_binder_t *binder, uint32_t image_id, jof_info_t *out_info)
Report a registered image's parsed geometry (#231).
ra8_err_t epub_tile_binder_add_ext(epub_tile_binder_t *binder, jof_pread_fn pread, void *pread_ctx, uint64_t total_size, uint32_t image_id)
Register an externally-backed JOF atlas under image_id (#231).
ra8_err_t epub_tile_binder_prefetch_pan(epub_tile_binder_t *binder, uint32_t image_id, const ra8_tile_rect_t *view, ra8_tile_pan_dir_t dir, uint16_t max_tiles, uint16_t *out_warmed)
Predictively warm the tiles one step ahead of a panning image (#341).
@ k_epub_tile_max_sources
Distinct images per binder.
ra8_err_t epub_reflow_img_load(void *ctx, const char *href, uint32_t href_len, const uint8_t **out_bytes, size_t *out_len)
Real reflow <img> byte loader off an EPUB book (#231).
ra8_err_t epub_tile_binder_init(epub_tile_binder_t *binder, const ra8_tile_cache_cfg_t *storage, uint8_t *scratch, uint32_t scratch_cap)
Initialise a tile binder over caller-supplied tile-cache storage (#231).
ra8_err_t epub_tile_binder_put(epub_tile_binder_t *binder, const uint8_t *pixels)
Release one pin taken by epub_tile_binder_get() (#231).
ra8_err_t epub_tile_binder_get(epub_tile_binder_t *binder, uint32_t image_id, uint16_t tile_x, uint16_t tile_y, ra8_tile_t *out_tile)
Get (and pin) one decoded tile of a registered image (#231).
JOF band-tile atlas: the display-native normalized image format (#231, shared with the longstrip scro...
ra8_err_t(* jof_pread_fn)(void *ctx, uint64_t offset, uint8_t *buf, size_t len, size_t *got)
Positioned-read seam over an atlas backing store (DIP).
ra8_err_t jof_read_tile(jof_pread_fn pread, void *pread_ctx, const jof_info_t *info, uint16_t tile_x, uint16_t tile_y, uint8_t *scratch, uint32_t scratch_cap, uint8_t *out_px, uint32_t out_cap, uint16_t *out_w, uint16_t *out_h)
Read + decode one tile into caller pixels, in bounded RAM.
ra8_err_t jof_parse(jof_pread_fn pread, void *pread_ctx, uint64_t total_size, jof_info_t *out_info)
Parse + validate a JOF atlas's header, footer and index bounds.
static const char * s_tag
Logging / check tag.
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.
Error Code Definitions for ra8-firmware.
@ k_ra8_err_no_mem
Static buffer exhausted (no dynamic memory on this project).
@ k_ra8_err_out_of_range
Sensor or peripheral output out of valid range.
@ k_ra8_err_invalid_arg
Invalid function argument.
@ k_ra8_ok
Success – operation completed with all postconditions satisfied.
@ k_ra8_err_not_found
Requested item not found (lookup / search missed).
@ 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.
static uint8_t internal_find(ra8_port_pin_t pin)
Find the row watching a pin.
void * memset(void *dst, int value, size_t n)
Fill memory with a constant byte value.
size_t strlen(const char *s)
Calculate string length.
void * memcpy(void *dst, const void *src, size_t n)
Copy memory area between non-overlapping regions.
static ra8_err_t internal_tile_decode(void *ctx, const void *key, uint8_t *cell, uint32_t cell_bytes, void *user)
Decode trampoline: adapt ra8_tile_decode_fn to the keycache seam.
Fixed-RAM-budget image-tile cache with LRU eviction (Layer 3b, #147).
ra8_err_t ra8_tile_cache_get(ra8_tile_cache_t *tc, const ra8_tile_key_t *key, ra8_tile_t *out_tile)
Get (and pin) the decoded tile for key.
ra8_err_t ra8_tile_cache_prefetch_pan(ra8_tile_cache_t *tc, const ra8_tile_prefetch_req_t *req, uint16_t *out_warmed)
Predictively warm the tiles one step ahead of a panning viewport.
ra8_err_t ra8_tile_cache_put(ra8_tile_cache_t *tc, const uint8_t *pixels)
Release one pin on a tile previously returned by ra8_tile_cache_get.
ra8_err_t ra8_tile_cache_init(ra8_tile_cache_t *tc, const ra8_tile_cache_cfg_t *cfg)
Initialise a tile cache over caller-supplied storage.
ra8_tile_pan_dir_t
Direction of viewport travel, for predictive pan prefetch.
Forward streaming cursor over one ZIP entry – inflate in bounded RAM (#231).
Context for the real reflow <img> loader (epub_reflow_img_load).
uint8_t * scratch
Caller-owned encoded-bytes scratch.
size_t scratch_cap
Scratch capacity (bounded RAM ceiling).
epub_book_t * book
Book to resolve <img src> hrefs against.
Binds up to k_epub_tile_max_sources images to one tile cache.
epub_tile_source_t sources[k_epub_tile_max_sources]
Registered images.
uint8_t * scratch
Stored-tile staging for deflate atlases.
ra8_tile_cache_t cache
Owned tile cache (decode wired to the binder).
uint32_t scratch_cap
Capacity of scratch.
uint8_t source_count
Registered image count.
One registered atlas image (private to the binder; treat as opaque).
jof_pread_fn pread
External atlas read seam, or NULL.
uint32_t image_id
Tile-cache key namespace for this image.
uint64_t total_size
Atlas byte length (backing size).
void * pread_ctx
Context for pread.
char path[k_epub_max_path_len]
Entry path (book-backed only).
epub_book_t * book
Owning book, or NULL for external atlas.
jof_info_t info
Parsed + validated atlas geometry.
Parsed + validated geometry of one JOF atlas.
uint16_t tile_rows
Ceil(height / tile_h) tile rows.
uint16_t tile_cols
Ceil(width / tile_w) tile columns.
Caller-supplied storage + decoder for ra8_tile_cache_init.
ra8_tile_decode_fn decode
Decode-on-miss callback.
void * decode_ctx
Opaque context passed to decode.
Identifies one decoded image tile.
uint16_t tile_y
Tile row index (in tile units).
uint16_t tile_x
Tile column index (in tile units).
uint32_t image_id
Source image identifier.
A predictive pan-prefetch request: what is visible + where it heads.
An inclusive rectangle of tile grid coordinates (the visible tiles).
A pinned view of a cached tile returned by ra8_tile_cache_get.