42typedef enum : uint8_t {
54typedef enum : uint8_t {
73 if (stbi_info_from_memory(bytes, (
int)len, &x, &y, &comp) == 0) {
122 if (((int64_t)box_w * (int64_t)src_h) <= ((int64_t)box_h * (int64_t)src_w)) {
125 sh = (int32_t)(((int64_t)src_h * (int64_t)box_w) / (int64_t)src_w);
129 sw = (int32_t)(((int64_t)src_w * (int64_t)box_h) / (int64_t)src_h);
165 const char*
const reason = stbi_failure_reason();
175 if ((reason !=
nullptr) && (
strstr(reason,
"outofmem") !=
nullptr)) {
225 for (int32_t dy = 0; dy < fit_h; dy++) {
226 const int32_t map_y = (int32_t)(((int64_t)dy * (int64_t)src_h) / (int64_t)fit_h);
227 for (int32_t dx = 0; dx < fit_w; dx++) {
228 const int32_t map_x = (int32_t)(((int64_t)dx * (int64_t)src_w) / (int64_t)fit_w);
278 const uint8_t* bytes,
303 uint8_t*
const pixels = stbi_load_from_memory(bytes, (
int)len, &sx, &sy, &comp, (
int)
k_ra8_img_req_rgb);
314 if ((pixels ==
nullptr) || (sx <= 0) || (sy <= 0)) {
326 stbi_image_free(pixels);
330 if (out_w !=
nullptr) {
333 if (out_h !=
nullptr) {
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_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_err_no_mem
Static buffer exhausted (no dynamic memory on this project).
@ 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.
char * strstr(const char *haystack, const char *needle)
Locate substring in string.
Software 2D graphics primitives layered on top of a caller-ownedframebuffer (DRW / D/AVE 2D / GLCDC r...
ra8_err_t ra8_gfx_pixel(int32_t x, int32_t y, uint32_t color)
Set a single pixel.
Heap-free scratch allocator hooks for the stb_image single-TU build.
void ra8_img_arena_bind(ra8_img_arena_t *arena)
Bind arena as the active scratch for subsequent decode allocations.
void ra8_img_arena_unbind(void)
Unbind the active arena; subsequent allocation hooks fail with nullptr.
Lightweight Logging Interface for ra8-firmware.
#define ra8_log_error(tag, message)
RA8 log error.
static void internal_blit_scaled(const uint8_t *pixels, int32_t src_w, int32_t src_h, int32_t fit_w, int32_t fit_h, int32_t dst_x, int32_t dst_y)
Nearest-neighbour blit a decoded RGB image into the bound framebuffer.
ra8_img_shift_t
Channel shifts to assemble a 0x00RRGGBB colour for ra8_gfx (no magics).
@ k_ra8_img_shift_r
Red channel shift into 0x00RRGGBB.
@ k_ra8_img_shift_g
Green channel shift into 0x00RRGGBB.
ra8_img_pack_t
Pixel-packing and channel constants (no magic numbers).
@ k_ra8_img_min_edge
Minimum scaled / box edge length, pixels.
@ k_ra8_img_ch_b
Blue byte offset within an RGB triple.
@ k_ra8_img_ch_r
Red byte offset within an RGB triple.
@ k_ra8_img_req_rgb
Desired channel count requested from stb_image.
@ k_ra8_img_ch_g
Green byte offset within an RGB triple.
ra8_err_t ra8_img_decode_blit(ra8_img_arena_t *arena, const uint8_t *bytes, size_t len, int32_t dst_x, int32_t dst_y, int32_t box_w, int32_t box_h, int32_t *out_w, int32_t *out_h)
Implementation of ra8_img_decode_blit() – nearest-neighbour scale.
static void internal_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)
Compute the aspect-preserving fit rectangle for an image in a box.
static void internal_arena_release(ra8_img_arena_t *arena)
Unbind the decode arena and force it back to the fully-drained state.
ra8_err_t ra8_img_probe_size(const uint8_t *bytes, size_t len, int32_t *out_w, int32_t *out_h)
Probe an image's intrinsic dimensions without a full decode.
static ra8_err_t internal_decode_fail(void)
Map a decode failure to the closest ra8_err_t via stbi_failure_reason.
static const char *const s_tag_img
Log tag for the image decode/blit module.
Zero-heap raster image decode + scale + blit for reflow (#106).
Minimal SVG handling for the reflow ereader (#112).
bool ra8_svg_is_svg(const uint8_t *bytes, size_t len)
Heuristically decide whether bytes are an SVG document.
ra8_err_t ra8_svg_size(const uint8_t *svg, size_t len, int32_t *out_w, int32_t *out_h)
Report an SVG's intrinsic size (width/height, else viewBox dimensions).
Caller-owned bump arena backing a single image decode.
size_t offset
Current bump offset.
size_t live
Live (allocated, not freed) blocks.