|
RMGui 0.15.0
C11 retained-mode UI library: layout kernel, style schema, widget painters, fonts, software framebuffer
|
image.h — caller-owned image decoder registry, PNG decoding into straight-alpha RGBA8 framebuffers, and painting decoded IMAGE artwork. More...
#include <stddef.h>#include <stdint.h>#include "fb.h"#include "layout.h"#include "draw_target.h"Data Structures | |
| struct | rmgui_image_limits_t |
| Per-decode hostile-input safety limits, checked before pixel allocation. More... | |
| struct | rmgui_image_codec_t |
| Immutable decoder descriptor. More... | |
| struct | rmgui_image_codecs_t |
| Caller-owned ordered registry. More... | |
Macros | |
| #define | RMGUI_IMAGE_LIMITS_DEFAULT {16384, UINT64_C(16777216)} |
| Default limits: 16,384 pixels per side and 16,777,216 pixels (64 MiB RGBA8). | |
Functions | |
| int | rmgui_image_codecs_init (rmgui_image_codecs_t *out, const rmgui_image_codec_t **storage, size_t capacity) |
| Initialize an empty registry borrowing storage. | |
| int | rmgui_image_codecs_add (rmgui_image_codecs_t *registry, const rmgui_image_codec_t *codec) |
| Append a descriptor with a nonempty name and non-NULL callbacks. | |
| int | rmgui_image_decode (const rmgui_image_codecs_t *registry, rmgui_fb_t *out, const uint8_t *bytes, size_t length, const rmgui_image_limits_t *limits) |
| Dispatch to the first registered codec whose sniff matches. | |
| int | rmgui_image_decode_png (rmgui_fb_t *out, const uint8_t *bytes, size_t length, const rmgui_image_limits_t *limits) |
| Decode the PNG in bytes[0, length) into *out: an allocated framebuffer of the image's width x height, released only by rmgui_fb_free. | |
| int | rmgui_image_prepare (rmgui_fb_t *out, const rmgui_fb_t *source, rmgui_rect_t source_rect, int width, int height, int nearest, void *pixels, size_t capacity) |
| Prepare an immutable-size RGBA8 snapshot of source_rect from source at width x height. | |
| void | rmgui_image_paint (rmgui_fb_t *fb, const rmgui_fb_t *image, const rmgui_layout_snapshot_node_t *node, rmgui_rect_t clip, rmgui_color_t tint) |
| Paint image, a straight-alpha RGBA8 framebuffer, into fb as the layout kernel placed it on node, a published IMAGE or GRAPHIC snapshot node: the whole image is scaled into node->image_rect and shown only inside node->image_clip, node->clip, clip and fb. | |
| void | rmgui_image_paint_to (rmgui_target_t *, const rmgui_fb_t *, const rmgui_layout_snapshot_node_t *, rmgui_rect_t, rmgui_color_t) |
| Explicit destination image paint with identical sampling and masks. | |
Variables | |
| const rmgui_image_codec_t | rmgui_image_codec_png |
| PNG descriptor for explicit registration; no automatic/global registration. | |
image.h — caller-owned image decoder registry, PNG decoding into straight-alpha RGBA8 framebuffers, and painting decoded IMAGE artwork.
The library has no filesystem loader; the caller supplies the bytes.
| #define RMGUI_IMAGE_LIMITS_DEFAULT {16384, UINT64_C(16777216)} |
Default limits: 16,384 pixels per side and 16,777,216 pixels (64 MiB RGBA8).
This initializer is a policy default, not a library-imposed upper bound.
| int rmgui_image_codecs_init | ( | rmgui_image_codecs_t * | out, |
| const rmgui_image_codec_t ** | storage, | ||
| size_t | capacity ) |
Initialize an empty registry borrowing storage.
NULL storage is valid only for zero capacity. Returns 0, or -1 leaving *out unchanged on invalid input.
| int rmgui_image_codecs_add | ( | rmgui_image_codecs_t * | registry, |
| const rmgui_image_codec_t * | codec ) |
Append a descriptor with a nonempty name and non-NULL callbacks.
Returns 0, or -1 without mutation for NULL/invalid arguments or exhausted capacity. Duplicate descriptors are permitted; dispatch uses registration order.
| int rmgui_image_decode | ( | const rmgui_image_codecs_t * | registry, |
| rmgui_fb_t * | out, | ||
| const uint8_t * | bytes, | ||
| size_t | length, | ||
| const rmgui_image_limits_t * | limits ) |
Dispatch to the first registered codec whose sniff matches.
No allocation occurs in the registry itself. Returns the decoder's result; -1 leaves *out unchanged for invalid arguments, invalid limits, no match or decode refusal. No later codec is tried after a matching decoder refuses.
| int rmgui_image_decode_png | ( | rmgui_fb_t * | out, |
| const uint8_t * | bytes, | ||
| size_t | length, | ||
| const rmgui_image_limits_t * | limits ) |
Decode the PNG in bytes[0, length) into *out: an allocated framebuffer of the image's width x height, released only by rmgui_fb_free.
*out must not hold an allocated framebuffer: it is overwritten, not released. The decoder transfers its final allocation without copying. For 16-bit input the RGBA8 pixels are compacted in place; the allocation retains its RGBA16 byte size (up to 128 MiB at the pixel cap).
Every PNG colour type and bit depth is accepted: grey, grey + alpha, palette, RGB and RGBA at 1, 2, 4, 8 or 16 bits per channel, interlaced or not. The pixels are R, G, B, A bytes in straight (not premultiplied) alpha, as every fb.h blit and draw.h blend expects:
Returns 0. Returns -1, leaving *out unchanged, when out or bytes is NULL, length is 0 or above INT_MAX, the bytes are not a PNG, the PNG is truncated, corrupt or unsupported, its dimensions exceed the per-call limits (checked from the header before any pixel buffer is allocated), its allocation sizes exceed stb's signed int representation or size_t, or an allocation fails.
NULL limits select RMGUI_IMAGE_LIMITS_DEFAULT; otherwise both fields must be positive. Limits bound declared dimensions, not crafted-stream work or intermediate allocations. The private stb decoder is not a security sandbox; callers must establish a suitable trust boundary for compressed inputs.
| int rmgui_image_prepare | ( | rmgui_fb_t * | out, |
| const rmgui_fb_t * | source, | ||
| rmgui_rect_t | source_rect, | ||
| int | width, | ||
| int | height, | ||
| int | nearest, | ||
| void * | pixels, | ||
| size_t | capacity ) |
Prepare an immutable-size RGBA8 snapshot of source_rect from source at width x height.
nearest != 0 selects corner-anchored nearest-neighbour; otherwise sampling is exactly rmgui_fb_blit_filtered. Writes into the caller's pixels[0, capacity), requiring width * height * 4 bytes. Source and output dimensions must be positive ints with byte counts fitting size_t. No allocation, eviction, source reference or implicit refresh. Reprepare explicitly when source pixels, source_rect, size or filter change.
Returns 0 and sets *out to a framebuffer borrowing pixels. Returns -1 without changing *out or pixels for invalid geometry, insufficient capacity, NULL arguments or overlapping source and output storage. out must not alias source. The caller owns pixels; do not fb_free/resize this borrowed framebuffer. Paint it using rmgui_image_paint_to with an image_rect of exactly width x height: filtering is then bypassed while tint, rounded corners and shape coverage still apply. RECORD pins this framebuffer and its pixels until submit/discard, as for any image.
| void rmgui_image_paint | ( | rmgui_fb_t * | fb, |
| const rmgui_fb_t * | image, | ||
| const rmgui_layout_snapshot_node_t * | node, | ||
| rmgui_rect_t | clip, | ||
| rmgui_color_t | tint ) |
Paint image, a straight-alpha RGBA8 framebuffer, into fb as the layout kernel placed it on node, a published IMAGE or GRAPHIC snapshot node: the whole image is scaled into node->image_rect and shown only inside node->image_clip, node->clip, clip and fb.
The pixels are composited by draw.h's straight-over rule.
Scaling follows node->image_scale. Zero (every fit but INTEGER_SCALE, and GRAPHIC): the sampling of rmgui_fb_blit_filtered. Nonzero (INTEGER_SCALE): nearest-neighbour, where pixel i of image_rect shows image column floor(i * image->width / image_rect.w), rows likewise, so a rect that is an exact multiple of the image replicates each pixel into a block.
The node's cut-out is its rounded node->rect (corner_radius follows rmgui_fb_blit_masked's radius rule), intersected with node->shape when present. The shape is stretched over node->rect by mask.h's nearest-pixel rule, matching the layout hit shape, and multiplies each rounded pixel's alpha. Clipping never shifts either cut-out.
tint modulates the image as in rmgui_fb_blit_masked; {255, 255, 255, 255} is no tint.
Paints nothing when fb or image is NULL or empty, fb == image or they share pixel storage, node is NULL, node->image_rect or the visible area is empty (an unarranged or hidden node), or tint.a is 0. No heap allocation; image and node are borrowed for the call.
| void rmgui_image_paint_to | ( | rmgui_target_t * | , |
| const rmgui_fb_t * | , | ||
| const rmgui_layout_snapshot_node_t * | , | ||
| rmgui_rect_t | , | ||
| rmgui_color_t | ) |
Explicit destination image paint with identical sampling and masks.
RECORD pins image and shape through submit/discard; no allocation. Declare retained revisions first with rmgui_target_source_stamped and rmgui_target_mask_stamped; the painter reuses those resource entries. Resource/capacity failures latch on the stream.
|
extern |
PNG descriptor for explicit registration; no automatic/global registration.