30typedef enum : uint32_t {
91 int32_t fh = (src_w > 0) ? ((box_w * src_h) / src_w) : box_h;
94 fw = (src_h > 0) ? ((box_h * src_w) / src_h) : box_w;
96 *fit_w = (fw < 1) ? 1 : fw;
97 *fit_h = (fh < 1) ? 1 : fh;
110 if ((out_img->
width == 0U) || (out_img->
height == 0U)) {
117static int32_t
sh_clampi(int32_t v, int32_t lo, int32_t hi)
119 const int32_t x = (v < lo) ? lo : v;
120 return (x > hi) ? hi : x;
126 const size_t flat = ((size_t)j * (size_t)w) + (
size_t)i;
128 const size_t bi = flat >> 1U;
129 if ((flat & 1U) == 0U) {
146 for (int32_t j = 0; j < h; ++j) {
157 for (int32_t i = 0; i < w; ++i) {
185 if (!
sh_gray4_image(src, img_idx, &img) || (box_w <= 0) || (box_h <= 0)) {
191 uint32_t last_sy = UINT32_MAX;
192 for (int32_t dy = 0; dy < fh; ++dy) {
193 const uint32_t sy = (uint32_t)((dy * (int32_t)img.
height) / fh);
198 for (int32_t dx = 0; dx < fw; ++dx) {
199 const uint32_t sx = (uint32_t)((dx * (int32_t)img.
width) / fw);
210 if ((src ==
nullptr) || (w <= 0) || (h <= 0)) {
239 if (!
sh_gray4_image(src, img_idx, &img) || (box_w <= 0) || (box_h <= 0)) {
245 const int32_t ox = dst_x + ((box_w - fw) / (int32_t)
k_sh_two);
246 const int32_t oy = dst_y + ((box_h - fh) / (int32_t)
k_sh_two);
251 uint32_t last_sy = UINT32_MAX;
252 for (int32_t dy = 0; dy < fh; ++dy) {
253 const uint32_t sy = (uint32_t)((dy * (int32_t)img.
height) / fh);
258 for (int32_t dx = 0; dx < rw; ++dx) {
259 const uint32_t sx = (uint32_t)((dx * (int32_t)img.
width) / fw);
264 if (out_w !=
nullptr) {
267 if (out_h !=
nullptr) {
289 const int32_t w = ((int32_t)img.
width < sub_w) ? (int32_t)img.
width : sub_w;
290 const int32_t h = ((int32_t)img.
height < sub_h) ? (int32_t)img.
height : sub_h;
316 if ((src ==
nullptr) || (out_cx ==
nullptr) || (out_cy ==
nullptr)) {
320 if (!
sh_gray4_image(src, img_idx, &img) || (box_w <= 0) || (box_h <= 0)) {
326 const int32_t ox = box_x + ((box_w - fw) / (int32_t)
k_sh_two);
327 const int32_t oy = box_y + ((box_h - fh) / (int32_t)
k_sh_two);
328 const bool inside = (px >= ox) && (px < (ox + fw)) && (py >= oy) && (py < (oy + fh));
332 *out_cx = ((px - ox) * (int32_t)img.
width) / fw;
333 *out_cy = ((py - oy) * (int32_t)img.
height) / fh;
@ k_book_image_gray4
4bpp gray, 2px/byte; pixel (x,y) is at flat index y*width + x.
ra8_err_t book_src_image_rect(const book_src_t *src, const book_image_t *img, uint32_t x, uint32_t y, uint32_t w, uint32_t h, uint8_t *out, uint32_t out_stride)
Read a sub-rectangle of a raster image (4bpp or 8bpp) as gray8, row by row.
ra8_err_t book_src_image(const book_src_t *src, uint32_t idx, book_image_t *out_img)
Read one image descriptor out of a book source (resident or paged).
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.
@ k_ra8_err_invalid_arg
Invalid function argument.
@ 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.
Software 2D graphics primitives layered on top of a caller-ownedframebuffer (DRW / D/AVE 2D / GLCDC r...
ra8_err_t ra8_gfx_reset_clip(void)
Reset the clip rectangle to the whole framebuffer.
ra8_err_t ra8_gfx_blit_gray4_zoom(const uint8_t *src, int32_t src_w, int32_t src_h, int32_t sx, int32_t sy, int32_t sw, int32_t sh, int32_t zoom, int32_t dst_x, int32_t dst_y)
Nearest-neighbour integer-zoom blit of a sub-rectangle of a packed 4-bit grayscale image into the fra...
ra8_err_t ra8_gfx_set_clip(int32_t x, int32_t y, int32_t w, int32_t h)
Restrict all subsequent drawing to a rectangle (dirty-region updates).
ra8_err_t ra8_gfx_blit_gray8(const uint8_t *src, int32_t w, int32_t h, int32_t dst_x, int32_t dst_y)
Blit an 8-bit grayscale image to a framebuffer rectangle.
Shared contract for the ereader_shelf multi-screen e-reader.
void sh_border(ra8_ui_rect_t r, uint32_t colour, int32_t width)
Draw a width-thick rectangle outline in colour.
@ k_sh_loupe_w
Lens window width in framebuffer pixels.
@ k_sh_loupe_zoom
Integer magnification of the sampled window.
@ k_sh_loupe_h
Lens window height in framebuffer pixels.
@ k_sh_loupe_border
Lens chrome (frame) thickness in pixels.
@ k_sh_fb_w
Panel width in pixels.
static bool sh_loupe_stage(const book_src_t *src, const book_image_t *img, int32_t sx, int32_t sy, int32_t w, int32_t h)
Stage the w x h source window at (sx, sy) into s_sh_loupe.
ra8_err_t sh_image_blit_cover(const book_src_t *src, uint32_t img_idx, int32_t dst_x, int32_t dst_y, int32_t box_w, int32_t box_h, int32_t *out_w, int32_t *out_h)
Decode + aspect-fit a 4bpp image straight into the framebuffer box.
ra8_err_t sh_image_decode_gray8(const book_src_t *src, uint32_t img_idx, uint8_t *out, int32_t box_w, int32_t box_h, int32_t *out_w, int32_t *out_h)
Decode a 4bpp grayscale image, aspect-fit-scale it into box, and write the result into a gray8 buffer...
static bool sh_gray4_image(const book_src_t *src, uint32_t img_idx, book_image_t *out_img)
Read image descriptor img_idx via the library and confirm it is a renderable gray4 raster that fits s...
static uint8_t s_sh_cover_row[k_sh_fb_w]
One decoded gray8 row of the scaled cover, reused across rows.
bool sh_image_loupe_map(const book_src_t *src, uint32_t img_idx, int32_t box_x, int32_t box_y, int32_t box_w, int32_t box_h, int32_t px, int32_t py, int32_t *out_cx, int32_t *out_cy)
Map a framebuffer touch point over an aspect-fit image box to full-resolution source coordinates (lou...
ra8_err_t sh_image_loupe(const book_src_t *src, uint32_t img_idx, int32_t src_cx, int32_t src_cy, int32_t dst_x, int32_t dst_y)
Draw the magnifier loupe: a k_sh_loupe_zoom-magnified 1:1 window of a full-resolution 4bpp source ima...
static void sh_fit_box(int32_t src_w, int32_t src_h, int32_t box_w, int32_t box_h, int32_t *fit_w, int32_t *fit_h)
Aspect-fit src_w x src_h into box; sets fit_w / fit_h (>=1).
void sh_image_blit_gray8(const uint8_t *src, int32_t w, int32_t h, int32_t dst_x, int32_t dst_y)
Blit a gray8 bitmap to the bound framebuffer at dst_x, dst_y.
static int32_t sh_clampi(int32_t v, int32_t lo, int32_t hi)
Clamp v into [lo, hi] (assumes hi >= lo).
static uint8_t s_sh_loupe[((k_sh_loupe_w/k_sh_loupe_zoom) *(k_sh_loupe_h/k_sh_loupe_zoom))/k_sh_two]
One magnifier-loupe source window, repacked as a compact gray4 image.
sh_img_const_t
Nibble repack + scale-bound constants.
@ k_sh_img_max_w
Max accepted source width (row-buffer cap).
@ k_sh_nib_sh
Gray8->gray4 nibble shift for the loupe repack.
@ k_sh_two
Centring divisor / half-extent divisor.
static void sh_loupe_pack(int32_t j, int32_t i, int32_t w, uint8_t g8)
Pack gray8 pixel g8 into s_sh_loupe at flat index j * w + i.
static bool sh_gray4_fetch_row(const book_src_t *src, const book_image_t *img, uint32_t sy)
Read source row sy of img as unpacked gray8 into s_sh_gray8_row via the library's sub-rect reader.
static uint8_t s_sh_gray8_row[k_sh_img_max_w]
One unpacked gray8 source row read from the paged image pool.
static void sh_loupe_chrome(int32_t dst_x, int32_t dst_y)
Frame the lens window with a k_sh_loupe_border-thick ink border.
Descriptor for one transcoded image in the image pool.
uint16_t height
Pixel height.
uint8_t format
book_image_format_t.
uint16_t width
Pixel width.
A book data source: resident (zero-copy) or paged (demand-fetched).
Axis-aligned rectangle in framebuffer pixel coordinates.