AxlPixmap — Image Decode (PNG / JPEG / GIF / BMP)
See AxlGfx — Graphics for an overview of the graphics substrate.
AxlPixmap decodes encoded image byte buffers into
AxlGfxBuffer pixel arrays for blit-style consumption (icons,
button bitmaps, CSS <img> and background-image).
Header: <axl/axl-pixmap.h>
Backed by stb_image vendored
at deps/stb/stb_image.h (dual MIT / Public Domain licensed).
Two entry points:
axl_pixmap_inforeturns dimensions without decoding — for layout-driven container sizing before committing to a full pixel-buffer allocation.axl_pixmap_decodereturns a fully-decodedAxlGfxBuffer; output is 4-channel BGRA matchingAxlGfxPixellayout, so the returned buffer is directly blittable viaaxl_gfx_buffer_present.
Naming note: pixmap (map of pixels) — distinct from
AxlImage — executable-image lifecycle (UEFI executable-image lifecycle).
API Reference
Image decoders for PNG, JPEG, GIF, and BMP into AxlGfxBuffer.
Decodes byte buffers into AxlGfxBuffer pixel arrays for blit-style consumption (icons, button bitmaps, CSS <img> and background- image). Backed by stb_image — public-domain single-header decoder vendored at deps/stb/stb_image.h.
Naming note: pixmap to distinguish from <axl/axl-image.h> (which is for UEFI executable-image lifecycle — LoadImage/StartImage/UnloadImage). pixmap
here is “map of
pixels” — the decoded raster data, not the format-on-disk and not anything executable.
Two entry points:
axl_pixmap_inforeturns dimensions WITHOUT decoding — useful for layout-driven container sizing before committing to a full pixel-buffer allocation.axl_pixmap_decodereturns a fully-decoded AxlGfxBuffer.
The public API is toolkit-neutral — no HTML/CSS-shaped intrinsic-sizing helpers, no DPI metadata. Consumers wrap at their own layer.
// Layout-before-decode: size the container, decide whether to
// commit to the full buffer alloc.
uint32_t w, h;
if (axl_pixmap_info(bytes, len, &w, &h) == AXL_OK
&& w <= my_max_w && h <= my_max_h)
{
AxlGfxBuffer *buf = axl_pixmap_decode(bytes, len);
if (buf) {
axl_gfx_buffer_present(buf, dst_x, dst_y);
axl_gfx_buffer_free(buf);
}
}
Functions
-
int axl_pixmap_info(const uint8_t *bytes, size_t len, uint32_t *out_w, uint32_t *out_h)
Get pixel dimensions of an encoded image without allocating a decode buffer.
Wraps stb_image’s
stbi_info_from_memory. Parses just enough of the format’s header to extract width and height — for PNG that’s the 8-byte signature + 25-byte IHDR chunk; for JPEG it’s the SOFn marker. Cheap compared to full decode.Supports the same formats as
axl_pixmap_decode(PNG, JPEG, GIF, BMP).- Parameters:
bytes – [in] encoded image byte buffer
len – buffer length in bytes
out_w – [out] image width in pixels (NULL OK)
out_h – [out] image height in pixels (NULL OK)
- Returns:
AXL_OK on success. AXL_ERR if bytes is NULL, len is too small to contain any recognized format header, the format is unrecognized, or the header is malformed. Output pointers untouched on error.
-
AxlGfxBuffer *axl_pixmap_decode(const uint8_t *bytes, size_t len)
Decode an encoded image byte buffer into a fresh AxlGfxBuffer.
Format is auto-detected from the buffer magic; supports PNG, JPEG, GIF (first frame only), and BMP. Output is 4-channel BGRA matching AxlGfxPixel’s layout — directly blittable via
axl_gfx_buffer_present. Source formats that omit alpha (e.g. opaque BMP, JPEG) getalpha = 0xFFfor every pixel.Decoded buffer dimensions match what
axl_pixmap_inforeports.Callers receive ownership and must free with
axl_gfx_buffer_free.- Parameters:
bytes – [in] encoded image byte buffer
len – buffer length in bytes
- Returns:
new AxlGfxBuffer on success (caller frees). NULL on allocation failure, unrecognized format, malformed input, bytes NULL, or len 0.