ra8-firmware 0.1.0
Bare-metal firmware for the Renesas RA8 family (RA8D2 / RA8P1)
Loading...
Searching...
No Matches
mg_reader.c File Reference

Tap-driven pan/zoom viewer over a tiled manga page (ereader_manga). More...

#include "mg_reader.h"
#include <stddef.h>
#include <stdint.h>
#include "jof.h"
#include "ra8_check.h"
#include "ra8_err.h"
#include "ra8_gfx.h"
#include "ra8_gfx_font.h"
#include "ra8_tile_cache.h"
Include dependency graph for mg_reader.c:

Go to the source code of this file.

Enumerations

enum  mg_color_t : uint32_t {
  k_mg_col_letterbox = 0x000000U ,
  k_mg_col_status_bg = 0x141420U ,
  k_mg_col_status_fg = 0xFFFFFFU ,
  k_mg_col_minimap_bg = 0x202830U ,
  k_mg_col_minimap_fg = 0x808890U ,
  k_mg_col_minimap_view = 0xFFE000U
}
 Chrome palette (0x00RRGGBB; ra8_gfx packs to RGB565). More...
enum  mg_metric_t : uint16_t {
  k_mg_status_cap = 48U ,
  k_mg_status_text_x = 16U ,
  k_mg_glyph_h = 16U ,
  k_mg_dec_max = 12U ,
  k_mg_i32_dec_digits = 10U
}
 Text / formatting metrics. More...
enum  mg_bits_t : uint8_t {
  k_mg_dec_ten = 10U ,
  k_mg_r_drop = 3U ,
  k_mg_g_drop = 2U ,
  k_mg_r_sh = 11U ,
  k_mg_g_sh = 5U
}
 gray8 -> RGB565 field shifts and the decimal radix. More...
enum  mg_fnv_t : uint32_t {
  k_mg_fnv_offset = 2166136261U ,
  k_mg_fnv_prime = 16777619U
}
 FNV-1a-32 constants. More...
enum  mg_pixfmt_t : uint8_t { k_mg_gray8_bpp = 1U }
 The single JOF pixel format the reader can blit. More...

Functions

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 int32_t mg_content_h (const mg_reader_t *r)
 Content-area height below the status bar, panel px.
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_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 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.
static uint16_t mg_g565 (uint8_t g)
 Pack a gray8 sample into an RGB565 pixel.
static void mg_clamp (mg_reader_t *r)
 Viewport-clamp the reader for the active zoom (fit pins to 0,0).
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.
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 ra8_err_t mg_render_page (mg_reader_t *r)
 Page every tile overlapping the viewport through the cache and blit.
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.
ra8_err_t mg_reader_render (mg_reader_t *r)
 Render the current viewport + chrome into the framebuffer.
ra8_err_t mg_reader_prefetch (mg_reader_t *r)
 Warm the tiles one step ahead of the last pan (predictive prefetch).
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).
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.
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.
bool mg_reader_toggle_zoom (mg_reader_t *r)
 Toggle the zoom between 1:1 and fit-page (SW-button entry point).
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 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 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.
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=..").
uint32_t mg_fnv1a (const void *buf, uint32_t len)
 FNV-1a-32 over a byte buffer (framebuffer render hash for the banner).
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_reader_bind (mg_reader_t *r, const mg_reader_cfg_t *cfg)
 Populate reader state from an already-validated config (no checks).
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).
static ra8_err_t mg_reader_check_geometry (const mg_reader_cfg_t *cfg)
 Validate framebuffer + atlas geometry; reject non-gray8 atlases (#339).
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.
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.

Variables

static const char k_mg_tag [] = "mg_reader"
 Log tag for the reader's null-pointer guards.

Detailed Description

Tap-driven pan/zoom viewer over a tiled manga page (ereader_manga).

Tag
[Ring 6 / APP] {World: NS}

Implementation of the presentation model declared in inc/mg_reader.h. The reader owns no hardware: it maps page pixels to panel pixels, pages the covered tiles through ra8_tile_cache one at a time, packs gray8 to RGB565, and draws the chrome through ra8_gfx – so the same render runs on the firmware, under ra8_emulator, and in the host unit test.

Since
0.1.0

Definition in file mg_reader.c.

Enumeration Type Documentation

◆ mg_bits_t

enum mg_bits_t : uint8_t

gray8 -> RGB565 field shifts and the decimal radix.

Since
0.1.0
Enumerator
k_mg_dec_ten 

Decimal radix.

k_mg_r_drop 

gray8 -> 5-bit field shift.

k_mg_g_drop 

gray8 -> 6-bit field shift.

k_mg_r_sh 

RGB565 red field shift.

k_mg_g_sh 

RGB565 green field shift.

Definition at line 67 of file mg_reader.c.

◆ mg_color_t

enum mg_color_t : uint32_t

Chrome palette (0x00RRGGBB; ra8_gfx packs to RGB565).

Since
0.1.0
Enumerator
k_mg_col_letterbox 

Framebuffer clear (page margins).

k_mg_col_status_bg 

Status-bar background.

k_mg_col_status_fg 

Status-bar text.

k_mg_col_minimap_bg 

Minimap page area.

k_mg_col_minimap_fg 

Minimap frame.

k_mg_col_minimap_view 

Minimap current-viewport rect.

Definition at line 40 of file mg_reader.c.

◆ mg_fnv_t

enum mg_fnv_t : uint32_t

FNV-1a-32 constants.

Since
0.1.0
Enumerator
k_mg_fnv_offset 

FNV-1a-32 offset basis.

k_mg_fnv_prime 

FNV-1a-32 prime.

Definition at line 80 of file mg_reader.c.

◆ mg_metric_t

enum mg_metric_t : uint16_t

Text / formatting metrics.

Since
0.1.0
Enumerator
k_mg_status_cap 

Status-string scratch capacity.

k_mg_status_text_x 

Status text left inset, panel px.

k_mg_glyph_h 

ra8_gfx_font_8x16 glyph height.

k_mg_dec_max 

Decimal digit scratch length.

k_mg_i32_dec_digits 

Maximum non-negative int32_t digits.

Definition at line 54 of file mg_reader.c.

◆ mg_pixfmt_t

enum mg_pixfmt_t : uint8_t

The single JOF pixel format the reader can blit.

Every blit path here (mg_blit_tile via mg_g565) reads one byte per pixel and expands it as gray8. A JOF atlas may instead declare bpp 3 (RGB888) or 4 (RGBA8888) – jof_produce follows the source decoder's channel count – so mg_reader_init fails closed on anything but k_mg_gray8_bpp rather than mis-reading a colour tile one byte per pixel and rendering garbage (#339).

Since
0.1.0
Enumerator
k_mg_gray8_bpp 

The only bytes-per-pixel the reader supports.

Definition at line 98 of file mg_reader.c.

Function Documentation

◆ mg_append_str()

uint32_t mg_append_str ( char * buf,
uint32_t cap,
uint32_t pos,
const char * s,
uint32_t length )
static

Append an exact immutable fragment, bounded by cap.

Definition at line 512 of file mg_reader.c.

Referenced by mg_reader_status().

◆ mg_append_uint()

uint32_t mg_append_uint ( char * buf,
uint32_t cap,
uint32_t pos,
int32_t val )
static

Append an unsigned decimal (from a signed val, clamped >= 0).

Definition at line 488 of file mg_reader.c.

References k_mg_dec_max, k_mg_dec_ten, and k_mg_i32_dec_digits.

Referenced by mg_reader_status().

◆ mg_blit_tile()

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] )
static

Blit one pinned gray8 tile's viewport overlap into the framebuffer.

Definition at line 220 of file mg_reader.c.

References mg_reader_t::fb, mg_reader_t::fb_w, ra8_tile_t::height, mg_g565(), mg_map(), ra8_tile_t::pixels, mg_reader_t::tile_h, mg_reader_t::tile_w, and ra8_tile_t::width.

Referenced by mg_render_page().

◆ mg_clamp()

void mg_clamp ( mg_reader_t * r)
static

Viewport-clamp the reader for the active zoom (fit pins to 0,0).

Definition at line 188 of file mg_reader.c.

References mg_reader_t::fb_w, k_mg_zoom_fit, mg_content_h(), mg_reader_t::page_h, mg_reader_t::page_w, mg_reader_t::view_x, mg_reader_t::view_y, and mg_reader_t::zoom.

Referenced by mg_pan(), mg_reader_bind(), and mg_reader_toggle_zoom().

◆ mg_content_h()

int32_t mg_content_h ( const mg_reader_t * r)
static

Content-area height below the status bar, panel px.

Definition at line 113 of file mg_reader.c.

References mg_reader_t::fb_h, and k_mg_statusbar_h.

Referenced by mg_clamp(), mg_fit_factor(), mg_offsets(), and mg_region().

◆ mg_fit_factor()

uint8_t mg_fit_factor ( const mg_reader_t * r)
static

Smallest integer decimation that fits the page in the content area.

Definition at line 554 of file mg_reader.c.

References mg_reader_t::fb_w, mg_content_h(), mg_reader_t::page_h, and mg_reader_t::page_w.

Referenced by mg_reader_bind().

◆ mg_fnv1a()

uint32_t mg_fnv1a ( const void * buf,
uint32_t len )
nodiscard

FNV-1a-32 over a byte buffer (framebuffer render hash for the banner).

Parameters
[in]bufBytes to hash.
[in]lenByte count.
Returns
uint32_t The FNV-1a-32 digest.
Return values
2166136261The offset basis, when len is 0 (empty digest).
Precondition
buf holds len readable bytes (or len is 0).
None.
Postcondition
No state is mutated.
The digest is deterministic across host / ra8_emulator / silicon.
Note
Thread-safe (pure).
Since
0.1.0

Definition at line 540 of file mg_reader.c.

References k_mg_fnv_offset, and k_mg_fnv_prime.

Referenced by mg_print_banner().

◆ mg_g565()

uint16_t mg_g565 ( uint8_t g)
static

Pack a gray8 sample into an RGB565 pixel.

Definition at line 179 of file mg_reader.c.

References k_mg_g_drop, k_mg_g_sh, k_mg_r_drop, and k_mg_r_sh.

Referenced by mg_blit_tile().

◆ mg_map()

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 )
static

Map one caller-clipped page pixel to the panel; false if off-grid.

Definition at line 154 of file mg_reader.c.

References k_mg_statusbar_h, mg_reader_t::view_x, and mg_reader_t::view_y.

Referenced by mg_blit_tile().

◆ mg_offsets()

void mg_offsets ( const mg_reader_t * r,
int32_t * ox,
int32_t * oy )
static

Panel-pixel offset that centres the shown region in the content area.

Definition at line 137 of file mg_reader.c.

References mg_reader_t::fb_w, mg_content_h(), mg_region(), and mg_scale().

Referenced by mg_render_page().

◆ mg_pan()

bool mg_pan ( mg_reader_t * r,
int32_t dx,
int32_t dy )
static

Slide the viewport by (dx,dy) page px; false if pinned / at fit.

Definition at line 402 of file mg_reader.c.

References k_mg_zoom_fit, k_ra8_tile_pan_none, mg_reader_t::last_pan, mg_clamp(), mg_pan_dir(), mg_reader_t::view_x, mg_reader_t::view_y, and mg_reader_t::zoom.

Referenced by mg_reader_tap().

◆ mg_pan_dir()

ra8_tile_pan_dir_t mg_pan_dir ( int32_t dx,
int32_t dy )
static

Pan direction of a (dx,dy) step (exactly one axis is non-zero).

Definition at line 387 of file mg_reader.c.

References k_ra8_tile_pan_down, k_ra8_tile_pan_left, k_ra8_tile_pan_right, and k_ra8_tile_pan_up.

Referenced by mg_pan().

◆ mg_reader_bind()

◆ mg_reader_check_geometry()

ra8_err_t mg_reader_check_geometry ( const mg_reader_cfg_t * cfg)
static

◆ mg_reader_check_ptrs()

ra8_err_t mg_reader_check_ptrs ( const mg_reader_t * r,
const mg_reader_cfg_t * cfg )
static

Null-guard the init inputs (5 preconditions, NASA Rule 5).

Definition at line 590 of file mg_reader.c.

References mg_reader_cfg_t::cache, mg_reader_cfg_t::fb, mg_reader_cfg_t::info, k_mg_tag, k_ra8_ok, and RA8_CHECK_NULL_PTR.

Referenced by mg_reader_init().

◆ mg_reader_init()

ra8_err_t mg_reader_init ( mg_reader_t * r,
const mg_reader_cfg_t * cfg )
nodiscard

Bind a viewer to a produced atlas and reset it to 1:1 top-left.

Parameters
[out]rReader state to populate.
[in]cfgFramebuffer + cache + parsed atlas geometry.
Returns
ra8_err_t Error code.
Return values
k_ra8_okReader ready; viewport at (0,0), zoom 1:1.
k_ra8_err_null_ptrr, cfg, or a required cfg field NULL.
k_ra8_err_invalid_sizecfg geometry is zero / smaller than the fb.
k_ra8_err_not_supportedcfg->info->bpp is not 1 (gray8); the blit path reads one byte per pixel, so a colour atlas is rejected rather than mis-rendered.
Precondition
cfg->info came from a successful jof_parse.
cfg->info->bpp == 1 (gray8); colour atlases are unsupported.
cfg->fb covers fb_w * fb_h RGB565 pixels.
Postcondition
On success the viewport is clamped inside the page.
On any error r is left unbound.
Note
Not thread-safe.
Since
0.1.0

Definition at line 619 of file mg_reader.c.

References k_ra8_ok, mg_reader_bind(), mg_reader_check_geometry(), and mg_reader_check_ptrs().

Referenced by main().

◆ mg_reader_prefetch()

ra8_err_t mg_reader_prefetch ( mg_reader_t * r)
nodiscard

Warm the tiles one step ahead of the last pan (predictive prefetch).

Called in the idle window after mg_reader_render presents a panned frame, so the next tiles the viewport will expose are decoded into the cache before the next pan needs them – the image counterpart of the chapter-text read-ahead (book_src_prefetch_chapter). Warms the lead tile row/column in r->last_pan through ra8_tile_cache_prefetch_pan, sizing the budget from the cache's spare capacity (capacity - currently-visible tiles) so a prefetch can never evict an on-screen tile. A no-op when the last action was not a moving pan (last_pan == k_ra8_tile_pan_none – the initial frame, a zoom toggle, a pan clamped at the page edge, or fit-page zoom where a pan is a no-op), or when the cache has no spare capacity. Transparent: warming changes only residency, so the next mg_reader_render is byte-identical.

Parameters
[in,out]rBound reader (its last_pan seeds the direction).
Returns
ra8_err_t Error code.
Return values
k_ra8_okPrefetch ran (possibly warming zero tiles).
k_ra8_err_null_ptrr or its cache was NULL.
k_ra8_err_*Propagated from ra8_tile_cache_prefetch_pan.
Precondition
r was populated by mg_reader_init.
The tile cache can decode the lead-edge tiles.
Postcondition
No on-screen tile resident after the last render is evicted.
r->fb and the viewport state are unchanged.
Note
Not thread-safe. Single-threaded read-ahead only.
See also
mg_reader_render()
Since
0.1.0

Definition at line 349 of file mg_reader.c.

References mg_reader_t::cache, mg_reader_t::image_id, k_mg_tag, k_ra8_ok, k_ra8_tile_pan_none, mg_reader_t::last_pan, mg_region(), mg_tiles_of_region(), RA8_CHECK_NULL_PTR, ra8_tile_cache_capacity(), ra8_tile_cache_prefetch_pan(), mg_reader_t::tile_cols, and mg_reader_t::tile_rows.

Referenced by mg_poll_touch().

◆ mg_reader_render()

ra8_err_t mg_reader_render ( mg_reader_t * r)
nodiscard

Render the current viewport + chrome into the framebuffer.

Clears the framebuffer, pages every tile overlapping the viewport through the cache (get/blit/put one at a time so a small cache evicts across the frame), packs gray8 to RGB565 with nearest- neighbour decimation at fit-page zoom, then draws the status bar and the minimap overlay.

Parameters
[in,out]rBound reader.
Returns
ra8_err_t Error code.
Return values
k_ra8_okThe framebuffer holds the current view.
k_ra8_err_null_ptrr or its framebuffer was NULL.
k_ra8_err_*Propagated from the tile cache / gfx.
Precondition
r was populated by mg_reader_init and ra8_gfx is bound to r->fb.
The tile cache can decode every covered tile.
Postcondition
On success r->fb holds the rendered screen.
Every tile pinned during the frame was released.
Note
Not thread-safe.
Since
0.1.0

Definition at line 332 of file mg_reader.c.

References mg_reader_t::fb, k_mg_col_letterbox, k_mg_tag, k_ra8_ok, mg_render_minimap(), mg_render_page(), mg_render_status(), RA8_CHECK_NULL_PTR, and ra8_gfx_clear().

Referenced by main(), and mg_poll_touch().

◆ mg_reader_status()

ra8_err_t mg_reader_status ( const mg_reader_t * r,
char * buf,
uint32_t cap )
nodiscard

Format the status-bar string ("MANGA 1:1 x=.. y=..").

Parameters
[in]rBound reader.
[out]bufDestination, NUL-terminated on return.
[in]capCapacity of buf (>= 1).
Returns
ra8_err_t Error code.
Return values
k_ra8_okThe status text was written.
k_ra8_err_null_ptrr or buf was NULL.
k_ra8_err_invalid_sizecap was 0.
Precondition
r was populated by mg_reader_init.
buf holds cap writable bytes.
Postcondition
buf is NUL-terminated within cap.
No reader state is mutated.
Note
Thread-safe for distinct buffers.
Since
0.1.0

Definition at line 522 of file mg_reader.c.

References k_mg_tag, k_mg_zoom_full, k_ra8_err_invalid_size, k_ra8_ok, mg_append_str(), mg_append_uint(), RA8_CHECK_NULL_PTR, mg_reader_t::view_x, mg_reader_t::view_y, and mg_reader_t::zoom.

Referenced by mg_render_status().

◆ mg_reader_tap()

bool mg_reader_tap ( mg_reader_t * r,
int32_t x,
int32_t y )
nodiscard

Apply a tap: pan or toggle zoom, and report whether state changed.

Maps (x,y) through mg_zone_hit, then mutates the viewport (an edge zone, clamped inside the page) or the zoom (the centre zone). A pan already at the page edge, or a tap on no zone, leaves the state unchanged and returns false so the caller can skip the redraw.

Parameters
[in,out]rBound reader.
[in]xTap X, panel pixels.
[in]yTap Y, panel pixels.
Returns
bool Whether the viewport or zoom changed.
Return values
trueState changed; the caller should re-render.
falseTap hit nothing actionable (no redraw needed).
Precondition
r was populated by mg_reader_init.
x and y are panel coordinates.
Postcondition
On true the viewport/zoom reflects the tap, clamped inside the page.
On false r is byte-for-byte unchanged.
Note
Not thread-safe.
Since
0.1.0

Definition at line 461 of file mg_reader.c.

References k_mg_pan_step, k_mg_zone_none, k_mg_zone_pan_down, k_mg_zone_pan_left, k_mg_zone_pan_right, k_mg_zone_pan_up, k_mg_zone_zoom, mg_pan(), mg_reader_toggle_zoom(), and mg_zone_hit().

Referenced by mg_poll_touch().

◆ mg_reader_toggle_zoom()

bool mg_reader_toggle_zoom ( mg_reader_t * r)
nodiscard

Toggle the zoom between 1:1 and fit-page (SW-button entry point).

Parameters
[in,out]rBound reader.
Returns
bool Whether the zoom was toggled.
Return values
trueThe zoom state flipped (the normal case).
falser was NULL (nothing toggled).
Precondition
r was populated by mg_reader_init.
None.
Postcondition
On true r->zoom is the other mg_zoom_t member.
The viewport is re-clamped for the new zoom.
Note
Not thread-safe.
Since
0.1.0

Definition at line 450 of file mg_reader.c.

References k_mg_zoom_fit, k_mg_zoom_full, k_ra8_tile_pan_none, mg_reader_t::last_pan, mg_clamp(), and mg_reader_t::zoom.

Referenced by mg_reader_tap().

◆ mg_region()

void mg_region ( const mg_reader_t * r,
int32_t * x0,
int32_t * y0,
int32_t * x1,
int32_t * y1 )
static

Source page rectangle currently shown, clamped to the page.

Definition at line 119 of file mg_reader.c.

References mg_reader_t::fb_w, mg_content_h(), mg_scale(), mg_reader_t::page_h, mg_reader_t::page_w, mg_reader_t::view_x, and mg_reader_t::view_y.

Referenced by mg_offsets(), mg_reader_prefetch(), mg_render_minimap(), and mg_render_page().

◆ mg_render_minimap()

void mg_render_minimap ( mg_reader_t * r)
static

◆ mg_render_page()

ra8_err_t mg_render_page ( mg_reader_t * r)
static

Page every tile overlapping the viewport through the cache and blit.

Definition at line 262 of file mg_reader.c.

References mg_reader_t::cache, mg_reader_t::image_id, k_ra8_ok, mg_blit_tile(), mg_offsets(), mg_region(), mg_scale(), mg_tiles_of_region(), ra8_tile_t::pixels, ra8_tile_cache_get(), and ra8_tile_cache_put().

Referenced by mg_reader_render().

◆ mg_render_status()

ra8_err_t mg_render_status ( mg_reader_t * r)
static

Draw the top status bar (background band + the status string).

Definition at line 291 of file mg_reader.c.

References mg_reader_t::fb_w, k_mg_col_status_bg, k_mg_col_status_fg, k_mg_glyph_h, k_mg_status_cap, k_mg_status_text_x, k_mg_statusbar_h, mg_reader_status(), ra8_gfx_font_8x16, ra8_gfx_rect(), and ra8_gfx_text_out().

Referenced by mg_reader_render().

◆ mg_scale()

int32_t mg_scale ( const mg_reader_t * r)
static

Decimation factor for the active zoom (1 at 1:1, fit_factor at fit).

Definition at line 107 of file mg_reader.c.

References mg_reader_t::fit_factor, k_mg_zoom_fit, and mg_reader_t::zoom.

Referenced by mg_offsets(), mg_region(), and mg_render_page().

◆ mg_tile_decode()

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 )
nodiscard

Tile-cache decode-on-miss callback: page one atlas tile into a cell.

Matches ra8_tile_decode_fn. Reads key->tile_x / tile_y and reads that tile out of the atlas through jof_read_tile (raw copy or deflate inflate) into cell, reporting the tile's clamped dimensions.

Parameters
[in]ctxA mg_tile_src_t* bound at cache init.
[in]keyThe tile to decode.
[out]cellDestination cell (cell_bytes writable).
[in]cell_bytesCell capacity in bytes.
[out]out_wDecoded tile width, pixels.
[out]out_hDecoded tile height, pixels.
Returns
ra8_err_t k_ra8_ok on success, or the read-tile error verbatim.
Return values
k_ra8_okTile decoded into cell.
k_ra8_err_null_ptrA required pointer was NULL.
k_ra8_err_*Propagated from jof_read_tile.
Precondition
ctx points at a live mg_tile_src_t.
cell holds cell_bytes writable bytes.
Postcondition
On success (*out_w) * (*out_h) gray8 bytes are valid in cell.
On any error cell content is unspecified.
Note
Not thread-safe (shares the read-tile scratch).
Since
0.1.0

Definition at line 633 of file mg_reader.c.

References mg_tile_src_t::info, jof_read_tile(), k_mg_tag, mg_tile_src_t::pread, mg_tile_src_t::pread_ctx, RA8_CHECK_NULL_PTR, mg_tile_src_t::scratch, mg_tile_src_t::scratch_cap, ra8_tile_key_t::tile_x, and ra8_tile_key_t::tile_y.

Referenced by mg_setup_cache().

◆ mg_tiles_of_region()

void mg_tiles_of_region ( const mg_reader_t * r,
const int32_t reg[4],
uint16_t out[4] )
static

Inclusive tile rect {tx0,ty0,tx1,ty1} covering a page region.

Definition at line 253 of file mg_reader.c.

References mg_reader_t::tile_h, and mg_reader_t::tile_w.

Referenced by mg_reader_prefetch(), and mg_render_page().

◆ mg_zone_hit()

mg_zone_t mg_zone_hit ( const mg_reader_t * r,
int32_t x,
int32_t y )
nodiscard

Classify a panel coordinate into its tap-zone.

Pure hit-test with no side effects: the centre rectangle (inside all four edge bands, below the status bar) is the zoom zone; each edge band is its pan zone; the status bar and any gap map to k_mg_zone_none.

Parameters
[in]rBound reader (for the framebuffer extent).
[in]xTap X, panel pixels.
[in]yTap Y, panel pixels.
Returns
mg_zone_t The zone (x,y) falls in.
Return values
k_mg_zone_noneStatus bar / outside the content area.
k_mg_zone_pan_*An edge band.
k_mg_zone_zoomThe centre.
Precondition
r was populated by mg_reader_init.
x and y are panel coordinates.
Postcondition
No state is mutated.
The result is one mg_zone_t member.
Note
Thread-safe (pure over its inputs).
Since
0.1.0

Definition at line 417 of file mg_reader.c.

References mg_reader_t::fb_h, mg_reader_t::fb_w, k_mg_edge_band, k_mg_statusbar_h, k_mg_zone_none, k_mg_zone_pan_down, k_mg_zone_pan_left, k_mg_zone_pan_right, k_mg_zone_pan_up, and k_mg_zone_zoom.

Referenced by mg_reader_tap().

Variable Documentation

◆ k_mg_tag

const char k_mg_tag[] = "mg_reader"
static

Log tag for the reader's null-pointer guards.

Definition at line 33 of file mg_reader.c.

Referenced by mg_reader_check_geometry(), mg_reader_check_ptrs(), mg_reader_prefetch(), mg_reader_render(), mg_reader_status(), and mg_tile_decode().