24#if __has_include("ra8_tile_cache.h")
51#define ZOOM_HAVE_TILES
70static const char*
const s_tag =
"zoom_tiles";
78 "zoom_pan_t and ra8_tile_pan_dir_t must agree: none");
80 "zoom_pan_t and ra8_tile_pan_dir_t must agree: left");
82 "zoom_pan_t and ra8_tile_pan_dir_t must agree: right");
84 "zoom_pan_t and ra8_tile_pan_dir_t must agree: up");
86 "zoom_pan_t and ra8_tile_pan_dir_t must agree: down");
108typedef enum : uint16_t {
109 k_zoom_tiles_native_level = 0U,
160static void internal_tile_copy(
const ra8_tile_t* tile,
163 const zoom_tile_span_t* span,
167 const uint32_t x0 = (span->x > org_x) ? span->x : org_x;
168 const uint32_t y0 = (span->y > org_y) ? span->y : org_y;
169 const uint32_t tx_end = org_x + (uint32_t)tile->
width;
170 const uint32_t ty_end = org_y + (uint32_t)tile->height;
171 const uint32_t x1 = ((span->x + span->w) < tx_end) ? (span->x + span->w) : tx_end;
172 const uint32_t y1 = ((span->y + span->h) < ty_end) ? (span->y + span->h) : ty_end;
173 for (uint32_t sy = y0; sy < y1; ++sy) {
174 const uint8_t* srow = &tile->pixels[((sy - org_y) * (uint32_t)tile->width) + (x0 - org_x)];
175 uint8_t* drow = &out[((sy - span->y) * stride) + (x0 - span->x)];
176 (void)
memcpy(drow, srow, (
size_t)(x1 - x0));
214 const zoom_tile_span_t* span,
222 .zoom = (uint16_t)k_zoom_tiles_native_level,
228 const uint32_t org_x = (uint32_t)tx * (uint32_t)ts->
tile_w;
229 const uint32_t org_y = (uint32_t)ty * (uint32_t)ts->
tile_h;
230 const uint32_t exp_w =
232 const uint32_t exp_h =
236 if (((uint32_t)tile.
width != exp_w) || ((uint32_t)tile.
height != exp_h)) {
241 internal_tile_copy(&tile, org_x, org_y, span, out, stride);
256 if ((width == 0U) || (height == 0U) || (tile_w == 0U) || (tile_h == 0U)) {
260 const uint32_t cols = ((width + (uint32_t)tile_w) - 1U) / (uint32_t)tile_w;
261 const uint32_t rows = ((height + (uint32_t)tile_h) - 1U) / (uint32_t)tile_h;
263 if ((cols > (uint32_t)UINT16_MAX) || (rows > (uint32_t)UINT16_MAX)) {
320 const zoom_tile_span_t* span,
324 for (uint16_t tx = tx0; tx <= tx1; ++tx) {
360 const zoom_tile_span_t* span,
364 for (uint16_t ty = tiles->
ty0; ty <= tiles->ty1; ++ty) {
412 if ((w == 0U) || (h == 0U) || (out_stride < w)) {
417 if (((x + w) > ts->
width) || ((y + h) > ts->
height)) {
449 "pixel rect to tile rect");
451 const zoom_tile_span_t span = {.x = x, .y = y, .w = w, .h = h};
452 return internal_walk_tiles(ts, &tiles, &span, out, out_stride);
459 uint16_t* out_warmed)
479 "visible window to tile rect");
486 .zoom = (uint16_t)k_zoom_tiles_native_level,
487 .max_tiles = max_tiles,
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_RETURN_ON_ERROR(err, tag, message)
Early return on error, propagating the code upward.
#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_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_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.
void * memcpy(void *dst, const void *src, size_t n)
Copy memory area between non-overlapping regions.
#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.
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.
ra8_err_t ra8_tile_rect_of_pixels(uint32_t px, uint32_t py, uint32_t pw, uint32_t ph, uint16_t tile_w, uint16_t tile_h, uint16_t tile_cols, uint16_t tile_rows, ra8_tile_rect_t *out)
Convert a pixel rectangle into the inclusive tile rectangle covering it.
Bounded UI interaction core: hit-testing, screen stack, paging.
Tile-cache state (caller-owned; treat as private).
Identifies one decoded image tile.
A predictive pan-prefetch request: what is visible + where it heads.
An inclusive rectangle of tile grid coordinates (the visible tiles).
uint16_t ty0
Topmost visible tile row (inclusive).
uint16_t tx1
Rightmost visible tile column (inclusive).
uint16_t tx0
Leftmost visible tile column (inclusive).
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.
Axis-aligned rectangle in framebuffer pixel coordinates.
int32_t w
Width (pixels, >= 0).
int32_t h
Height (pixels, >= 0).
int32_t x
Left edge (pixels).
int32_t y
Top edge (pixels).
A magnifiable full-resolution image behind the gray8 sub-rect seam.
A tiled gray8 image, its grid, and the cache that pages it.
uint16_t tile_cols
Derived tile columns.
ra8_tile_cache_t * cache
Borrowed, initialised tile cache.
uint16_t tile_w
Tile width, pixels.
uint16_t tile_rows
Derived tile rows.
uint16_t tile_h
Tile height, pixels.
uint32_t width
Full-resolution image width, pixels.
uint32_t image_id
Tile-cache key image id for this image.
uint32_t height
Full-resolution image height, pixels.
Live viewport: where it is looking, how magnified, and what it owes the panel.
Tap-to-zoom image viewer: viewport state machine + tiled magnifying render (#478).
ra8_err_t zoom_source_init(zoom_source_t *out, zoom_read_fn read, void *ctx, uint32_t width, uint32_t height)
Bind a gray8 sub-rectangle reader and its extent as a magnifiable source.
ra8_err_t zoom_view_window(const zoom_view_t *v, ra8_ui_rect_t *out)
The source rectangle currently visible, in source pixels.
zoom_pan_t
Discrete pan direction for tap-band navigation.
@ k_zoom_pan_right
Viewport travels toward +x.
@ k_zoom_pan_left
Viewport travels toward -x.
@ k_zoom_pan_none
No movement.
@ k_zoom_pan_down
Viewport travels toward +y.
@ k_zoom_pan_up
Viewport travels toward -y.
Bind a tiled gray8 atlas behind an ra8_tile_cache as a zoom source (#478).
ra8_err_t zoom_tiles_prefetch(zoom_tile_src_t *ts, const zoom_view_t *v, zoom_pan_t dir, uint16_t max_tiles, uint16_t *out_warmed)
Warm the tiles one pan step beyond what a view currently shows.
ra8_err_t zoom_tile_read(void *ctx, uint32_t x, uint32_t y, uint32_t w, uint32_t h, uint8_t *out, uint32_t out_stride)
zoom_read_fn over a tiled atlas paged by an ra8_tile_cache.
ra8_err_t zoom_tile_src_bind(zoom_tile_src_t *ts, zoom_source_t *out)
Present a bound tiled image to the zoom engine as a zoom_source_t.
ra8_err_t zoom_tile_src_init(zoom_tile_src_t *ts, ra8_tile_cache_t *cache, uint32_t image_id, uint32_t width, uint32_t height, uint16_t tile_w, uint16_t tile_h)
Bind a tiled image and its cache, deriving the tile grid.