32static const char*
const s_tag =
"zoom";
54typedef enum : uint8_t {
62 const int32_t plane = src_dim * scale;
67 int32_t d1 = plane - anchor;
83 const int32_t s0 = (anchor + d0) / scale;
84 const int32_t s1 = (anchor + d1 - 1) / scale;
89 const int32_t span = (s1 - s0) + 1;
90 out->
s0 = (uint32_t)s0;
91 out->
count = (uint32_t)span;
136 const int64_t sum = (int64_t)a + (int64_t)b;
137 if (sum > (int64_t)INT32_MAX) {
140 if (sum < (int64_t)INT32_MIN) {
169 if (plane <= extent) {
172 return -((extent - plane) / 2);
177 if (anchor > (plane - extent)) {
178 return plane - extent;
201 const int32_t scale = (int32_t)v->
scale;
279 if ((cfg->
dst.
w <= 0) || (cfg->
dst.
h <= 0)) {
311 const uint32_t width = (uint32_t)cfg->
dst.
w;
320 if (rows > (uint32_t)cfg->
dst.
h) {
321 rows = (uint32_t)cfg->
dst.
h;
327 *out_strip_rows = (uint16_t)rows;
365 if (opening > ceiling) {
369 *out_scale = opening;
370 *out_ceiling = ceiling;
419 uint16_t* out_strip_rows,
421 uint8_t* out_ceiling)
487 uint16_t strip_rows = 0U;
488 uint8_t opening = 0U;
489 uint8_t ceiling = 0U;
536 return (v !=
nullptr) && v->
active;
542 const uint8_t ceiling_v = (max < floor_v) ? floor_v : max;
543 if (scale >= ceiling_v) {
546 const uint16_t doubled = (uint16_t)((uint16_t)scale * (uint16_t)
k_zoom_scale_dbl);
547 if (doubled >= (uint16_t)ceiling_v) {
550 if (doubled < (uint16_t)floor_v) {
553 return (uint8_t)doubled;
571 if (scale == v->
scale) {
580 const int32_t off_x = focus_x - v->
dst.
x;
581 const int32_t off_y = focus_y - v->
dst.
y;
582 const int64_t old = (int64_t)v->
scale;
583 const int64_t plane_x = (int64_t)(v->
anchor_x + off_x) * (int64_t)scale;
584 const int64_t plane_y = (int64_t)(v->
anchor_y + off_y) * (int64_t)scale;
585 const int64_t scaled_x = plane_x / old;
586 const int64_t scaled_y = plane_y / old;
587 v->
anchor_x = (int32_t)scaled_x - off_x;
588 v->
anchor_y = (int32_t)scaled_y - off_y;
657 out->
x = (int32_t)ax.
s0;
658 out->
w = (int32_t)ax.
count;
659 out->
y = (int32_t)ay.
s0;
660 out->
h = (int32_t)ay.
count;
static const char * s_tag
Logging / check tag.
Annotation-attribute framework macros for ra8-firmware.
#define RA8_PRIV
Module-private helper: shared across TUs but only inside one library.
#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_no_mem
Static buffer exhausted (no dynamic memory on this project).
@ k_ra8_err_out_of_range
Sensor or peripheral output out of valid range.
@ k_ra8_err_invalid_arg
Invalid function argument.
@ k_ra8_err_invalid_state
Module in wrong state for requested operation.
@ k_ra8_ok
Success – operation completed with all postconditions satisfied.
ra8_err_codes_t ra8_err_t
Canonical error-return type used by every ra8-firmware API.
#define ra8_log_error(tag, message)
RA8 log error.
Bounded UI interaction core: hit-testing, screen stack, paging.
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).
One axis of the viewport resolved against the image: coverage + source span.
uint32_t count
Source indices feeding the covered span (0 if none).
int32_t d1
One past the last covered destination offset.
uint32_t s0
First source index feeding the covered span.
int32_t d0
First covered destination offset inside the viewport.
What the reader must flush, and with which waveform.
zoom_refresh_t refresh
Waveform class for that flush.
ra8_ui_rect_t rect
Panel rectangle to flush.
bool present
False: nothing changed, do not flush at all.
uint8_t * packed
The strip packed to 4 bpp (2 px/byte).
uint32_t row_cap
Capacity of row, bytes.
uint8_t * row
One source row, >= dst.w bytes.
uint32_t packed_cap
Capacity of packed, bytes.
uint32_t strip_cap
Capacity of strip, bytes.
uint8_t * strip
gray8 destination strip, dst.w * strip_rows.
A magnifiable full-resolution image behind the gray8 sub-rect seam.
uint32_t height
Full-resolution source height, pixels.
uint32_t width
Full-resolution source width, pixels.
zoom_read_fn read
gray8 sub-rectangle reader (never NULL once bound).
void * ctx
Opaque context handed back to read.
Everything zoom_view_open needs; nothing it does not.
ra8_ui_rect_t dst
Viewport in framebuffer pixels.
zoom_source_t src
Bound source (see zoom_source_init).
int32_t focus_x
Opening centre, source pixels (x).
uint8_t scale
Opening magnification (0 => scale_min).
uint8_t scale_max
Ladder ceiling (0 => k_zoom_scale_max).
int32_t focus_y
Opening centre, source pixels (y).
uint16_t settle_ms
Settle window (0 => the module default).
zoom_policy_t policy
Waveform scheduling policy.
zoom_scratch_t scratch
Caller-owned composite buffers.
Live viewport: where it is looking, how magnified, and what it owes the panel.
uint32_t last_input_ms
Timestamp of the last viewport change.
uint8_t scale_max
Ladder ceiling for this view.
zoom_refresh_t pending_kind
Waveform the owed flush should use.
zoom_policy_t policy
Waveform scheduling policy.
bool settle_armed
A quality repaint is still due after settling.
uint8_t scale
Current integer magnification.
zoom_source_t src
Bound source.
zoom_scratch_t scratch
Caller-owned composite buffers.
ra8_ui_rect_t dst
Viewport in framebuffer pixels.
uint16_t strip_rows
Destination rows per composite strip.
int32_t anchor_y
Plane row shown at dst.y.
bool active
The view is open.
bool pending
A flush is owed.
int32_t anchor_x
Plane column shown at dst.x.
uint16_t settle_ms
Input silence before the quality repaint.
#define min(x, y)
Untyped minimum shim used by the SOUP's buffer clamping.
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_invalidate(zoom_view_t *v, uint32_t now_ms)
Declare the viewport's pixels stale for a reason the engine cannot see.
bool zoom_view_active(const zoom_view_t *v)
Whether a view is open.
zoom_step_t
Pan-step geometry and the ladder multiplier (no magic numbers).
@ k_zoom_overlap_div
Viewport fraction retained across a pan step.
@ k_zoom_scale_dbl
Ladder multiplier (doubling, not increment).
ra8_err_t zoom_view_rebind(zoom_view_t *v, const zoom_source_t *src, uint32_t now_ms)
Point an open view at a different source, keeping zoom and position.
static int32_t internal_sat_add(int32_t a, int32_t b)
Saturating signed addition (never wraps at the int32 boundary).
static bool internal_dim_ok(uint32_t dim)
Whether a source dimension is inside the engine's addressable range.
ra8_err_t zoom_view_close(zoom_view_t *v)
Close a view; it stops owing the panel anything.
static void internal_view_adopt(zoom_view_t *v, const zoom_view_cfg_t *cfg, uint8_t opening, uint8_t ceiling, uint16_t strip_rows)
Publish a validated configuration into a view and open it.
ra8_err_t zoom_view_pan_dir(zoom_view_t *v, zoom_pan_t dir, uint32_t now_ms)
Pan by a discrete step in one direction (the tap-band interaction).
static ra8_err_t internal_cfg_ptrs_ok(const zoom_view_cfg_t *cfg)
Validate every pointer a configuration must carry.
void priv_zoom_axis(int32_t anchor, int32_t extent, int32_t scale, int32_t src_dim, zoom_axis_t *out)
Resolve one viewport axis against the image at the current magnification.
static int32_t internal_clamp_anchor(int32_t anchor, int32_t plane, int32_t extent)
Clamp one anchor against the magnified plane and the viewport extent.
static ra8_err_t internal_cfg_ok(const zoom_view_cfg_t *cfg, uint16_t *out_strip_rows, uint8_t *out_scale, uint8_t *out_ceiling)
Run every configuration check, in the order they depend on each other.
static ra8_err_t internal_cfg_extent_ok(const zoom_view_cfg_t *cfg)
Validate the viewport extent and the source extent.
static void internal_reclamp(zoom_view_t *v)
Re-clamp both anchors against the current source, scale and viewport.
ra8_err_t zoom_view_pan(zoom_view_t *v, int32_t dx, int32_t dy, uint32_t now_ms)
Pan the viewport by a destination-pixel delta.
bool zoom_view_tick(zoom_view_t *v, uint32_t now_ms)
Advance the settle timer; promote a bi-level view to full quality.
ra8_err_t zoom_view_window(const zoom_view_t *v, ra8_ui_rect_t *out)
The source rectangle currently visible, in source pixels.
ra8_err_t zoom_view_present(zoom_view_t *v, zoom_present_t *out)
Take the pending flush plan, clearing it.
static ra8_err_t internal_cfg_ladder_ok(const zoom_view_cfg_t *cfg, uint8_t *out_scale, uint8_t *out_ceiling)
Resolve and validate the magnification ladder a configuration asks for.
static ra8_err_t internal_cfg_scratch_ok(const zoom_view_cfg_t *cfg, uint16_t *out_strip_rows)
Derive the strip height from the scratch budget and check every capacity.
uint8_t zoom_scale_cycle(uint8_t scale, uint8_t min, uint8_t max)
Next magnification on the doubling ladder, wrapping back to the minimum.
static void internal_touch(zoom_view_t *v, uint32_t now_ms)
Record an interactive viewport change and schedule the flush it owes.
ra8_err_t zoom_view_open(zoom_view_t *v, const zoom_view_cfg_t *cfg)
Open a viewport onto a source, centred on a source-pixel focus.
ra8_err_t zoom_view_set_scale(zoom_view_t *v, uint8_t scale, int32_t focus_x, int32_t focus_y, uint32_t now_ms)
Set the magnification, keeping a panel point fixed under the finger.
Tap-to-zoom image viewer: viewport state machine + tiled magnifying render (#478).
@ k_zoom_policy_responsive
Fast during a burst, quality once settled.
@ k_zoom_strip_rows_max
Destination rows composited per strip.
@ k_zoom_scale_max
Engine ceiling on integer magnification.
@ k_zoom_scale_min
1:1 – one source pixel per panel pixel.
@ k_zoom_dim_max
Largest accepted source width or height, pixels.
@ k_zoom_settle_ms_default
Default input-silence settle window, ms.
ra8_err_t(* zoom_read_fn)(void *ctx, uint32_t x, uint32_t y, uint32_t w, uint32_t h, uint8_t *out, uint32_t out_stride)
Read a sub-rectangle of the magnified source as gray8 (the DIP seam).
@ k_zoom_refresh_quality
Settled: panel GC16 (all 16 levels, slow).
@ k_zoom_refresh_fast
Interactive burst: panel A2 (bi-level, fast).
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.
Module-private seam shared by the zoom state machine and its render.