40typedef enum : uint32_t {
54typedef enum : uint16_t {
67typedef enum : uint8_t {
80typedef enum : uint32_t {
98typedef enum : uint8_t {
126 if (xe > (int32_t)r->
page_w) {
129 if (ye > (int32_t)r->
page_h) {
145 const int32_t disp_w = ((x1 - x0) + s - 1) / s;
146 const int32_t disp_h = ((y1 - y0) + s - 1) / s;
147 int32_t px = (r->
fb_w - disp_w) / 2;
149 *ox = (px > 0) ? px : 0;
150 *oy = (py > 0) ? py : 0;
163 const int32_t rx = sx - r->
view_x;
164 const int32_t ry = sy - r->
view_y;
165 if (((rx % s) != 0) || ((ry % s) != 0)) {
168 const int32_t px = ox + (rx / s);
184 return (uint16_t)(((uint16_t)(r5 <<
k_mg_r_sh)) | ((uint16_t)(g6 <<
k_mg_g_sh)) | b5);
205 }
else if (r->
view_x > maxx) {
210 }
else if (r->
view_y > maxy) {
227 const int32_t reg[4])
229 const int32_t px0 = (int32_t)tx * (int32_t)r->
tile_w;
230 const int32_t py0 = (int32_t)ty * (int32_t)r->
tile_h;
231 for (int32_t rr = 0; rr < (int32_t)t->
height; ++rr) {
232 const int32_t sy = py0 + rr;
233 if ((sy < reg[1]) || (sy >= reg[3])) {
236 for (int32_t cc = 0; cc < (int32_t)t->
width; ++cc) {
237 const int32_t sx = px0 + cc;
238 if ((sx < reg[0]) || (sx >= reg[2])) {
243 if (!
mg_map(r, s, ox, oy, sx, sy, &dx, &dy)) {
246 const uint8_t g = t->
pixels[(rr * (int32_t)t->
width) + cc];
255 out[0] = (uint16_t)(reg[0] / (int32_t)r->
tile_w);
256 out[1] = (uint16_t)(reg[1] / (int32_t)r->
tile_h);
257 out[2] = (uint16_t)((reg[2] - 1) / (int32_t)r->
tile_w);
258 out[3] = (uint16_t)((reg[3] - 1) / (int32_t)r->
tile_h);
265 mg_region(r, ®[0], ®[1], ®[2], ®[3]);
270 uint16_t tiles[4] = {};
272 for (uint16_t ty = tiles[1]; ty <= tiles[3]; ++ty) {
273 for (uint16_t tx = tiles[0]; tx <= tiles[2]; ++tx) {
319 mg_region(r, ®[0], ®[1], ®[2], ®[3]);
320 const int32_t vx = inx + ((reg[0] * inw) / (int32_t)r->
page_w);
321 const int32_t vy = iny + ((reg[1] * inh) / (int32_t)r->
page_h);
322 int32_t vw = ((reg[2] - reg[0]) * inw) / (int32_t)r->
page_w;
323 int32_t vh = ((reg[3] - reg[1]) * inh) / (int32_t)r->
page_h;
360 mg_region(r, ®[0], ®[1], ®[2], ®[3]);
361 uint16_t tiles[4] = {};
365 const uint32_t frame =
366 ((uint32_t)(tiles[2] - tiles[0]) + 1U) * ((uint32_t)(tiles[3] - tiles[1]) + 1U);
368 const uint32_t spare = (cap > frame) ? (cap - frame) : 0U;
369 const uint16_t budget = (spare > (uint32_t)UINT16_MAX) ? (uint16_t)UINT16_MAX : (uint16_t)spare;
372 .view = {.tx0 = tiles[0], .ty0 = tiles[1], .tx1 = tiles[2], .ty1 = tiles[3]},
407 const int32_t ox = r->
view_x;
408 const int32_t oy = r->
view_y;
412 const bool moved = (r->
view_x != ox) || (r->
view_y != oy);
438 if (y >= (r->
fb_h - band)) {
444 if (x >= (r->
fb_w - band)) {
488static uint32_t
mg_append_uint(
char* buf, uint32_t cap, uint32_t pos, int32_t val)
492 uint32_t v = (val < 0) ? 0U : (uint32_t)val;
503 for (uint32_t i = 0U; (i < n) && (pos < (cap - 1U)); ++i) {
504 buf[pos] = tmp[n - 1U - i];
512static uint32_t
mg_append_str(
char* buf, uint32_t cap, uint32_t pos,
const char* s, uint32_t length)
514 for (uint32_t i = 0U; (i < length) && (pos < (cap - 1U)); ++i) {
530 pos =
mg_append_str(buf, cap, pos,
"MANGA ",
sizeof(
"MANGA ") - 1U);
532 static_assert(
sizeof(
"1:1 x=") ==
sizeof(
"FIT x="),
"zoom labels must have equal extents");
533 pos =
mg_append_str(buf, cap, pos, zoom,
sizeof(
"1:1 x=") - 1U);
535 pos =
mg_append_str(buf, cap, pos,
" y=",
sizeof(
" y=") - 1U);
542 const uint8_t* p = (
const uint8_t*)buf;
547 for (uint32_t i = 0U; i < len; ++i) {
556 const int32_t cw = r->
fb_w;
558 const int32_t fx = ((int32_t)r->
page_w + cw - 1) / cw;
559 const int32_t fy = ((int32_t)r->
page_h + ch - 1) / ch;
560 int32_t f = (fx > fy) ? fx : fy;
@ k_mg_dec_ten
Decimal radix / hex split.
JOF band-tile atlas: the display-native normalized image format (#231, shared with the longstrip scro...
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.
bool mg_reader_tap(mg_reader_t *r, int32_t x, int32_t y)
Apply a tap: pan or toggle zoom, and report whether state changed.
static const char k_mg_tag[]
Log tag for the reader's null-pointer guards.
mg_pixfmt_t
The single JOF pixel format the reader can blit.
@ k_mg_gray8_bpp
The only bytes-per-pixel the reader supports.
ra8_err_t mg_tile_decode(void *ctx, const ra8_tile_key_t *key, uint8_t *cell, uint32_t cell_bytes, uint16_t *out_w, uint16_t *out_h)
Tile-cache decode-on-miss callback: page one atlas tile into a cell.
mg_metric_t
Text / formatting metrics.
@ k_mg_status_cap
Status-string scratch capacity.
@ k_mg_glyph_h
ra8_gfx_font_8x16 glyph height.
@ k_mg_i32_dec_digits
Maximum non-negative int32_t digits.
@ k_mg_status_text_x
Status text left inset, panel px.
@ k_mg_dec_max
Decimal digit scratch length.
static uint32_t mg_append_uint(char *buf, uint32_t cap, uint32_t pos, int32_t val)
Append an unsigned decimal (from a signed val, clamped >= 0).
static void mg_region(const mg_reader_t *r, int32_t *x0, int32_t *y0, int32_t *x1, int32_t *y1)
Source page rectangle currently shown, clamped to the page.
static void mg_tiles_of_region(const mg_reader_t *r, const int32_t reg[4], uint16_t out[4])
Inclusive tile rect {tx0,ty0,tx1,ty1} covering a page region.
static int32_t mg_content_h(const mg_reader_t *r)
Content-area height below the status bar, panel px.
static ra8_err_t mg_reader_check_ptrs(const mg_reader_t *r, const mg_reader_cfg_t *cfg)
Null-guard the init inputs (5 preconditions, NASA Rule 5).
ra8_err_t mg_reader_status(const mg_reader_t *r, char *buf, uint32_t cap)
Format the status-bar string ("MANGA 1:1 x=.. y=..").
mg_zone_t mg_zone_hit(const mg_reader_t *r, int32_t x, int32_t y)
Classify a panel coordinate into its tap-zone.
uint32_t mg_fnv1a(const void *buf, uint32_t len)
FNV-1a-32 over a byte buffer (framebuffer render hash for the banner).
static uint16_t mg_g565(uint8_t g)
Pack a gray8 sample into an RGB565 pixel.
ra8_err_t mg_reader_prefetch(mg_reader_t *r)
Warm the tiles one step ahead of the last pan (predictive prefetch).
ra8_err_t mg_reader_render(mg_reader_t *r)
Render the current viewport + chrome into the framebuffer.
static ra8_err_t mg_render_page(mg_reader_t *r)
Page every tile overlapping the viewport through the cache and blit.
static uint8_t mg_fit_factor(const mg_reader_t *r)
Smallest integer decimation that fits the page in the content area.
static void mg_blit_tile(mg_reader_t *r, const ra8_tile_t *t, uint16_t tx, uint16_t ty, int32_t s, int32_t ox, int32_t oy, const int32_t reg[4])
Blit one pinned gray8 tile's viewport overlap into the framebuffer.
mg_bits_t
gray8 -> RGB565 field shifts and the decimal radix.
@ k_mg_r_drop
gray8 -> 5-bit field shift.
@ k_mg_r_sh
RGB565 red field shift.
@ k_mg_g_drop
gray8 -> 6-bit field shift.
@ k_mg_g_sh
RGB565 green field shift.
static void mg_offsets(const mg_reader_t *r, int32_t *ox, int32_t *oy)
Panel-pixel offset that centres the shown region in the content area.
static void mg_clamp(mg_reader_t *r)
Viewport-clamp the reader for the active zoom (fit pins to 0,0).
static ra8_err_t mg_reader_check_geometry(const mg_reader_cfg_t *cfg)
Validate framebuffer + atlas geometry; reject non-gray8 atlases (#339).
static void mg_reader_bind(mg_reader_t *r, const mg_reader_cfg_t *cfg)
Populate reader state from an already-validated config (no checks).
static int32_t mg_scale(const mg_reader_t *r)
Decimation factor for the active zoom (1 at 1:1, fit_factor at fit).
static ra8_err_t mg_render_status(mg_reader_t *r)
Draw the top status bar (background band + the status string).
static void mg_render_minimap(mg_reader_t *r)
Draw the bottom-right minimap: the page bounds + the viewport rect.
mg_fnv_t
FNV-1a-32 constants.
@ k_mg_fnv_prime
FNV-1a-32 prime.
@ k_mg_fnv_offset
FNV-1a-32 offset basis.
ra8_err_t mg_reader_init(mg_reader_t *r, const mg_reader_cfg_t *cfg)
Bind a viewer to a produced atlas and reset it to 1:1 top-left.
static bool mg_map(const mg_reader_t *r, int32_t s, int32_t ox, int32_t oy, int32_t sx, int32_t sy, int32_t *dx, int32_t *dy)
Map one caller-clipped page pixel to the panel; false if off-grid.
mg_color_t
Chrome palette (0x00RRGGBB; ra8_gfx packs to RGB565).
@ k_mg_col_minimap_bg
Minimap page area.
@ k_mg_col_status_bg
Status-bar background.
@ k_mg_col_minimap_view
Minimap current-viewport rect.
@ k_mg_col_status_fg
Status-bar text.
@ k_mg_col_letterbox
Framebuffer clear (page margins).
@ k_mg_col_minimap_fg
Minimap frame.
static uint32_t mg_append_str(char *buf, uint32_t cap, uint32_t pos, const char *s, uint32_t length)
Append an exact immutable fragment, bounded by cap.
static bool mg_pan(mg_reader_t *r, int32_t dx, int32_t dy)
Slide the viewport by (dx,dy) page px; false if pinned / at fit.
bool mg_reader_toggle_zoom(mg_reader_t *r)
Toggle the zoom between 1:1 and fit-page (SW-button entry point).
static ra8_tile_pan_dir_t mg_pan_dir(int32_t dx, int32_t dy)
Pan direction of a (dx,dy) step (exactly one axis is non-zero).
Tap-driven pan/zoom viewer over a tiled manga page (ereader_manga).
mg_zone_t
The tap-zone a panel coordinate falls in (mg_zone_hit result).
@ k_mg_zone_pan_up
Top edge band: slide viewport up.
@ k_mg_zone_zoom
Centre: toggle 1:1 <-> fit-page.
@ k_mg_zone_pan_left
Left edge band: slide left.
@ k_mg_zone_pan_right
Right edge band: slide right.
@ k_mg_zone_none
Outside every actionable zone.
@ k_mg_zone_pan_down
Bottom edge band: slide down.
@ k_mg_minimap_h
Minimap overlay height, panel px.
@ k_mg_edge_band
Edge pan tap-zone thickness, panel px.
@ k_mg_minimap_w
Minimap overlay width, panel px.
@ k_mg_pan_step
Viewport slide per edge tap, page px.
@ k_mg_statusbar_h
Top status-bar band height, panel px.
@ k_mg_minimap_in
Minimap interior inset, px.
@ k_mg_minimap_pad
Minimap inset from the panel edge, px.
@ k_mg_zoom_fit
Fit-page – whole page decimated to the panel.
@ k_mg_zoom_full
1:1 – one page pixel per panel pixel; panned.
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_not_supported
Requested feature not compiled in, not wired, or not supported by this MCU variant.
@ 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...
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_text_out(int32_t x, int32_t y, const char *str, const ra8_gfx_font_t *font, uint32_t fg_color, uint32_t bg_color)
Render a NUL-terminated ASCII string.
ra8_err_t ra8_gfx_rect(int32_t x, int32_t y, int32_t w, int32_t h, uint32_t color, bool filled)
Draw an axis-aligned rectangle.
Bitmap font descriptor + bundled font handles for ra8_gfx.
const ra8_gfx_font_t ra8_gfx_font_8x16
Bundled 8x16 IBM PC VGA bitmap font, ASCII 0x20..0x7E.
#define ra8_log_error(tag, message)
RA8 log error.
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.
uint32_t ra8_tile_cache_capacity(const ra8_tile_cache_t *tc)
Report the number of cells the cache can hold.
ra8_tile_pan_dir_t
Direction of viewport travel, for predictive pan prefetch.
@ k_ra8_tile_pan_none
No travel: prefetch is a no-op.
@ k_ra8_tile_pan_up
Warm the row above the viewport.
@ k_ra8_tile_pan_down
Warm the row below the viewport.
@ k_ra8_tile_pan_left
Warm the column left of the viewport.
@ k_ra8_tile_pan_right
Warm the column right of the viewport.
uint8_t bpp
Bytes per pixel (1, 3 or 4).
uint16_t tile_w
Tile width, pixels.
uint16_t width
Image width, pixels.
uint16_t tile_rows
Ceil(height / tile_h) tile rows.
uint16_t tile_h
Tile height, pixels.
uint16_t height
Image height, pixels.
uint16_t tile_cols
Ceil(width / tile_w) tile columns.
Everything mg_reader_init needs to bind a viewer to a page.
uint16_t * fb
RGB565 framebuffer (panel).
const jof_info_t * info
Parsed atlas geometry.
ra8_tile_cache_t * cache
Tile cache over the atlas.
int32_t fb_h
Framebuffer height, pixels.
uint32_t image_id
Tile-cache key image id.
int32_t fb_w
Framebuffer width, pixels.
Viewer state: the page geometry plus the current viewport + zoom.
int32_t view_x
Viewport left in page px (1:1 anchor).
int32_t view_y
Viewport top in page px (1:1 anchor).
uint32_t image_id
Tile-cache key image id.
int32_t fb_w
Framebuffer width, pixels.
uint16_t tile_h
Atlas tile height, pixels.
uint8_t fit_factor
Decimation factor for fit-page (>= 1).
uint16_t tile_w
Atlas tile width, pixels.
uint16_t page_h
Full page height, pixels.
uint16_t * fb
RGB565 panel framebuffer.
int32_t fb_h
Framebuffer height, pixels.
uint16_t page_w
Full page width, pixels.
ra8_tile_cache_t * cache
Tile cache paging the atlas.
uint8_t zoom
Current mg_zoom_t.
uint16_t tile_cols
Atlas tile columns.
uint16_t tile_rows
Atlas tile rows.
ra8_tile_pan_dir_t last_pan
Last pan direction (mg_reader_prefetch seed).
Decode-on-miss context bound into the tile cache (DIP seam).
const jof_info_t * info
Parsed atlas geometry.
jof_pread_fn pread
Atlas positioned-read seam.
uint8_t * scratch
Deflate stored-stream staging.
void * pread_ctx
Context for pread.
uint32_t scratch_cap
Capacity of scratch.
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).
A predictive pan-prefetch request: what is visible + where it heads.
A pinned view of a cached tile returned by ra8_tile_cache_get.
const uint8_t * pixels
Decoded tile pixels (cell payload).
uint16_t height
Decoded tile height in pixels.
uint16_t width
Decoded tile width in pixels.