ra8-firmware 0.1.0
Bare-metal firmware for the Renesas RA8 family (RA8D2 / RA8P1)
Loading...
Searching...
No Matches
comic.h
Go to the documentation of this file.
1
64#pragma once
65
66#include <stddef.h>
67#include <stdint.h>
68
69#include "epub_miniz_alloc.h"
70#include "ra8_err.h"
71#include "ra8_rar.h"
72#include "ra8_rar5.h"
73#include "unarch_gzip.h"
74#include "unarch_tar.h"
75#include "unarch_xz.h"
76
77#ifdef __cplusplus
78extern "C" {
79#endif
80
95typedef size_t (*comic_read_fn)(void* ctx, uint64_t offset, void* buf, size_t len);
96
110
116typedef enum : uint16_t {
120
140typedef struct {
141 uint32_t name_off;
142 uint16_t name_len;
143 uint8_t extractable;
144 uint8_t rar_method;
145 uint32_t zip_index;
146 uint64_t data_off;
147 uint64_t pack_size;
148 uint64_t raw_size;
150
159typedef struct {
161 void* ctx;
162 uint64_t size;
164
202
240[[nodiscard]] ra8_err_t comic_open(comic_t* c,
241 comic_read_fn read,
242 void* ctx,
243 uint64_t size,
244 comic_page_t* pages,
245 uint32_t page_cap,
246 char* names,
247 uint32_t names_cap);
248
263static inline uint32_t comic_page_count(const comic_t* c)
264{
265 if (c == nullptr) {
266 return 0U;
267 }
268 if (c->kind == k_comic_kind_none) {
269 return 0U;
270 }
271 return c->page_count;
272}
273
288static inline comic_kind_t comic_kind(const comic_t* c)
289{
290 if (c == nullptr) {
291 return k_comic_kind_none;
292 }
293 return c->kind;
294}
295
327[[nodiscard]] ra8_err_t comic_page_info(const comic_t* c,
328 uint32_t page,
329 char* name_buf,
330 uint16_t name_cap,
331 uint16_t* out_name_len,
332 uint64_t* out_raw_size,
333 uint8_t* out_extractable);
334
369[[nodiscard]] ra8_err_t
370comic_page_read(comic_t* c, uint32_t page, uint8_t* buf, size_t cap, size_t* got);
371
389[[nodiscard]] ra8_err_t comic_close(comic_t* c);
390
399typedef enum : uint8_t {
402
453[[nodiscard]] ra8_err_t comic_open_wrapped(comic_t* c,
454 comic_read_fn read,
455 void* ctx,
456 uint64_t size,
457 comic_page_t* pages,
458 uint32_t page_cap,
459 char* names,
460 uint32_t names_cap,
461 uint8_t* arena,
462 size_t arena_cap,
463 void* xz_scratch,
464 uint32_t xz_scratch_len);
465
466#ifdef __cplusplus
467}
468#endif
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.
Definition comic.c:472
comic_wrap_dims_t
Alignment of the unwrap arena a wrapped open consumes.
Definition comic.h:399
@ k_comic_wrap_align
Required unwrap-arena alignment, bytes.
Definition comic.h:400
size_t(* comic_read_fn)(void *ctx, uint64_t offset, void *buf, size_t len)
Seek+read backing over the comic-archive bytes.
Definition comic.h:95
ra8_err_t comic_open_wrapped(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, uint8_t *arena, size_t arena_cap, void *xz_scratch, uint32_t xz_scratch_len)
Open a comic that may be gzip- or XZ-wrapped (.cbt.gz, .tar.xz).
ra8_err_t comic_close(comic_t *c)
Release an open comic's backend resources.
Definition comic.c:494
comic_kind_t
Which container an opened comic is.
Definition comic.h:104
@ k_comic_kind_cbz
ZIP of images (.cbz).
Definition comic.h:106
@ k_comic_kind_cbt
tar of images (.cbt).
Definition comic.h:108
@ k_comic_kind_cbr
RAR of images (.cbr).
Definition comic.h:107
@ k_comic_kind_none
Not opened / unrecognised.
Definition comic.h:105
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.
Definition comic.c:390
static comic_kind_t comic_kind(const comic_t *c)
The detected container kind of an open comic.
Definition comic.h:288
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.
Definition comic.c:434
static uint32_t comic_page_count(const comic_t *c)
Number of pages in an open comic.
Definition comic.h:263
comic_limits_t
Fixed sizes for magic detection and the inline ZIP-reader storage.
Definition comic.h:116
@ k_comic_magic_len
Bytes read to detect the container magic.
Definition comic.h:117
@ k_comic_zip_bytes
Inline storage for miniz's mz_zip_archive.
Definition comic.h:118
Caller-owned bounded-arena allocator for miniz.
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
Clean-room RAR 5.0 ("method 50") decompressor – LZ + Huffman + filters.
Clean-room, read-only RAR archive walker (RAR4 + RAR5 headers, STORE data).
One entry in the resident, sorted page index.
Definition comic.h:140
uint64_t raw_size
Encoded image length in bytes (decoder input).
Definition comic.h:148
uint64_t data_off
CBR: absolute offset of the member data area.
Definition comic.h:146
uint64_t pack_size
CBR: packed member size in bytes.
Definition comic.h:147
uint8_t extractable
1 if this reader can decode the page's bytes.
Definition comic.h:143
uint32_t zip_index
CBZ: miniz central-directory index.
Definition comic.h:145
uint16_t name_len
Page name length in bytes.
Definition comic.h:142
uint32_t name_off
Offset of the page name in the name arena.
Definition comic.h:141
uint8_t rar_method
CBR: ra8_rar_method_t (0 = store); 0 for CBZ.
Definition comic.h:144
Stable seek+read descriptor bound to the CBZ backend's miniz reader.
Definition comic.h:159
uint64_t size
Archive length in bytes.
Definition comic.h:162
void * ctx
Backing context.
Definition comic.h:161
comic_read_fn read
Backing reader (mirrors comic_t::read).
Definition comic.h:160
One open comic archive: backing, kind, page index, and backend state.
Definition comic.h:179
unarch_tar_t tar
CBT tar walker state.
Definition comic.h:192
epub_miniz_arena_t miniz_arena
Per-comic allocator descriptor bound through miniz's opaque pointer.
Definition comic.h:198
uint32_t page_count
Populated page count.
Definition comic.h:185
uint8_t zip_active
1 = miniz reader is initialised (CBZ).
Definition comic.h:194
uint32_t names_len
Bytes used in names.
Definition comic.h:188
comic_read_fn read
Byte reader over the archive.
Definition comic.h:180
void * ctx
Context for read.
Definition comic.h:181
comic_kind_t kind
Detected container kind.
Definition comic.h:193
comic_stream_t stream
CBZ miniz I/O descriptor (stable addr).
Definition comic.h:189
uint8_t zip_storage[k_comic_zip_bytes]
Inline storage for miniz's mz_zip_archive (CBZ; no heap).
Definition comic.h:196
char * names
Caller name arena.
Definition comic.h:186
ra8_rar_t rar
CBR walker state.
Definition comic.h:190
uint32_t page_cap
Capacity of pages in entries.
Definition comic.h:184
ra8_rar5_state_t rar5_state
CBR RAR5 decompressor scratch (no heap).
Definition comic.h:191
uint64_t size
Archive length in bytes.
Definition comic.h:182
comic_page_t * pages
Caller page-index array.
Definition comic.h:183
uint32_t names_cap
Capacity of names in bytes.
Definition comic.h:187
epub_miniz_workspace_t miniz_workspace
Per-comic bounded allocator workspace (used only for CBZ).
Definition comic.h:200
Descriptor for one caller-owned miniz allocation arena.
Exactly-sized, maximally-aligned storage for one miniz arena.
Caller-owned zero-heap scratch for one ra8_rar5_decompress call.
One open RAR archive: the backing plus the detected generation.
Definition ra8_rar.h:144
One open tar archive: the backing plus the walk's running budget.
Definition unarch_tar.h:97
Clean-room gzip member decoder (RFC 1952) over the miniz DEFLATE core.
Clean-room, read-only streaming tar walker (POSIX ustar + pax + GNU).
Bounded, fail-closed XZ/LZMA2 decoding over the vendored xz-embedded.