50 int32_t source_height,
52 int32_t target_height,
55 const int64_t tw = (int64_t)target_width;
56 const int64_t th = (int64_t)target_height;
58 int64_t height = ((int64_t)source_height * tw) / (int64_t)source_width;
61 width = ((int64_t)source_width * th) / (int64_t)source_height;
70 .y = (int32_t)((th - height) / 2),
71 .width = (int32_t)width,
72 .height = (int32_t)height};
90 uint32_t native_height,
91 uint32_t* render_width,
92 uint32_t* render_height)
95 uint32_t width = native_width;
96 uint32_t height = native_height;
98 height = (uint32_t)(((uint64_t)height * (uint64_t)edge) / (uint64_t)width);
102 width = (uint32_t)(((uint64_t)width * (uint64_t)edge) / (uint64_t)height);
105 *render_width = (width == 0U) ? 1U : width;
106 *render_height = (height == 0U) ? 1U : height;
129 uint64_t declared = 0U;
147 if ((error ==
k_ra8_ok) && ((uint64_t)*out_bytes != declared)) {
181 if ((error ==
k_ra8_ok) && ((width <= 0) || (height <= 0))) {
253 for (uint32_t page = 0U; page < reader->
tile_n; ++page) {
264 const uint32_t source_width = reader->
tile_wpx[page];
265 const uint32_t source_height = reader->
tile_hpx[page];
268 (int32_t)source_height,
286 const uint32_t render_width = reader->
tile_wpx[index];
287 const uint32_t render_height = reader->
tile_hpx[index];
288 const uint64_t required =
289 (uint64_t)render_width * (uint64_t)render_height * (uint64_t)
sizeof(uint16_t);
290 if ((required > (uint64_t)pixel_bytes) || (render_width > UINT16_MAX) ||
291 (render_height > UINT16_MAX)) {
299 .width = (int32_t)render_width,
300 .height = (int32_t)render_height};
311 *width = render_width;
312 *height = render_height;
Unified demand-paged reader for comic-book archives – CBZ (ZIP) and CBR (RAR).
ra8_err_t comic_page_read(comic_t *c, uint32_t page, uint8_t *buf, size_t cap, size_t *got)
Extract one page's encoded image bytes for the decoder.
ra8_err_t comic_open(comic_t *c, comic_read_fn read, void *ctx, uint64_t size, comic_page_t *pages, uint32_t page_cap, char *names, uint32_t names_cap)
Open a comic archive (CBZ or CBR) and build its sorted page index.
ra8_err_t comic_page_info(const comic_t *c, uint32_t page, char *name_buf, uint16_t name_cap, uint16_t *out_name_len, uint64_t *out_raw_size, uint8_t *out_extractable)
Read one page's manifest entry: name, encoded length, decodability.
Annotation-attribute framework macros for ra8-firmware.
#define RA8_INTERNAL
Marker that a function is intended to be static (file-local).
Unified decompression-limits policy: one bound set for every decoder.
ra8_err_t ra8_decomp_check_declared(const ra8_decomp_limits_t *limits, uint64_t comp_size, uint64_t out_size)
Header-level check of a member's declared sizes against a policy.
Error Code Definitions for ra8-firmware.
@ 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.
Software 2D graphics primitives layered on top of a caller-ownedframebuffer (DRW / D/AVE 2D / GLCDC r...
@ k_ra8_gfx_format_rgb565
16-bit RGB565, little-endian in memory.
@ k_ra8_gfx_max_dim
Maximum supported edge length.
ra8_err_t ra8_gfx_clear(uint32_t color)
Fill the bound framebuffer's clip region with a single colour.
ra8_err_t ra8_gfx_init(void *fb, uint16_t width, uint16_t height, ra8_gfx_format_t format)
Bind ra8_gfx to a caller-owned framebuffer.
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.
static void internal_fit_centered(int32_t source_width, int32_t source_height, int32_t target_width, int32_t target_height, viewer_fit_box_t *box)
Fit an image into a target while preserving aspect ratio.
static ra8_err_t internal_decode(ra8_viewer_reader_t *reader, uint32_t page, const viewer_fit_box_t *fit)
Decode one page into the currently selected graphics target.
size_t priv_viewer_comic_read(void *ctx, uint64_t offset, void *buffer, size_t length)
Adapt exact descriptor reads to the comic size-returning seam.
ra8_err_t priv_viewer_render_comic(ra8_viewer_reader_t *reader, uint32_t page)
Render one comic page into the fixed framebuffer.
static void internal_cap_render(uint32_t native_width, uint32_t native_height, uint32_t *render_width, uint32_t *render_height)
Cap a page to the graphics engine edge limit.
ra8_err_t priv_viewer_size_comic_tiles(ra8_viewer_reader_t *reader)
Probe every comic page into the bound dimension arrays.
static ra8_err_t internal_read_page(ra8_viewer_reader_t *reader, uint32_t page, size_t *out_bytes)
Extract one bounded encoded page into its resident slice.
ra8_err_t priv_viewer_tile_comic(ra8_viewer_reader_t *reader, uint32_t index, uint16_t *pixels, size_t pixel_bytes, uint32_t *width, uint32_t *height)
Render one comic page into caller-owned RGB565 storage.
static ra8_err_t internal_probe_page(ra8_viewer_reader_t *reader, uint32_t page)
Probe one page and publish its bounded render dimensions.
ra8_err_t priv_viewer_open_comic(ra8_viewer_reader_t *reader)
Open a bare CBZ/CBR/CBT engine over a bound reader.
@ k_ra8_viewer_fb_height
Framebuffer height in pixels.
@ k_ra8_viewer_fb_width
Framebuffer width in pixels.
struct ra8_viewer_reader ra8_viewer_reader_t
Opaque state bound inside caller-owned workspace.
Cross-translation-unit state for the bounded JOF/comic viewer.
ra8_err_t priv_viewer_pread(void *ctx, uint64_t offset, uint8_t *buffer, size_t length, size_t *out_read)
JOF positional-reader seam over viewer_file_ctx_t.
size_t priv_viewer_comic_read(void *ctx, uint64_t offset, void *buffer, size_t length)
Adapt exact descriptor reads to the comic size-returning seam.
@ k_viewer_background
White graphics clear colour.
@ k_viewer_comic_page_cap
Maximum indexed pages.
@ k_viewer_comic_name_bytes
Member-name arena bytes.
Zero-heap raster image decode + scale + blit for reflow (#106).
ra8_err_t ra8_img_decode_blit(ra8_img_arena_t *arena, const uint8_t *bytes, size_t len, int32_t dst_x, int32_t dst_y, int32_t box_w, int32_t box_h, int32_t *out_w, int32_t *out_h)
Decode bytes and blit it, scaled to fit, into the bound framebuffer.
ra8_err_t ra8_img_probe_size(const uint8_t *bytes, size_t len, int32_t *out_w, int32_t *out_h)
Probe an image's intrinsic dimensions without a full decode.
Caller-owned bump arena backing a single image decode.
uint32_t * tile_hpx
Native height per viewport tile.
uint32_t * tile_wpx
Native width per viewport tile.
viewer_comic_t comic
Comic engine and caller slices.
uint16_t * fb
Fixed headless framebuffer.
viewer_file_ctx_t file
Raw source descriptor.
ra8_decomp_limits_t limits
Shared untrusted-input policy.
uint32_t tile_n
Populated dimension entries.
uint8_t * page
Resident encoded-image bytes.
comic_t archive
Open CBZ/CBR/CBT facade.
char * names
Resident member-name arena.
size_t page_cap
Encoded-image capacity in bytes.
uint8_t * arena
stb caller-owned decode arena.
comic_page_t * pages
Resident sorted page index.
size_t arena_cap
Decode-arena capacity in bytes.
uint64_t size
Document length in bytes.
Destination rectangle for aspect-preserving page placement.
int32_t x
Left edge in target pixels.
int32_t height
Render height in pixels.
int32_t y
Top edge in target pixels.
int32_t width
Render width in pixels.