CDC Badge OS
Firmware for the CDC Badge v1.0 hardware security key
Loading...
Searching...
No Matches
Image decoding

Decode PNG/JPEG bytes into a dithered 1-bpp raster (no capability). More...

Functions

int host_image_info (const uint8_t *data, size_t len, uint16_t *out_w, uint16_t *out_h)
 Decode only the image header to get its dimensions.
int host_image_render (const uint8_t *data, size_t len, uint16_t target_w, uint8_t *out, size_t out_size, uint16_t *out_stride_bytes, uint16_t *out_height_px)
 Decode, scale to target_w (aspect preserved) and dither to 1-bpp.

Detailed Description

Decode PNG/JPEG bytes into a dithered 1-bpp raster (no capability).

Pure compute on caller memory. Output layout matches the QR and surface APIs: packed rows, MSB-first, a set bit is black. Decoding uses the same engine as the firmware image viewer (max ~1 megapixel input).

Function Documentation

◆ host_image_info()

int host_image_info ( const uint8_t * data,
size_t len,
uint16_t * out_w,
uint16_t * out_h )

Decode only the image header to get its dimensions.

Parameters
dataEncoded PNG or JPEG bytes.
lenByte length.
out_wReceives the native width in pixels.
out_hReceives the native height in pixels.
Returns
HOST_OK, HOST_ERR_INVALID_ARG, HOST_ERR_GENERIC (unsupported or corrupt image, too many pixels).

Definition at line 42 of file host_api_image.cpp.

References HOST_ERR_GENERIC, HOST_ERR_INVALID_ARG, HOST_OK, LOG_W, and TAG.

Referenced by cdc::plugin_manager::w_host_image_info().

◆ host_image_render()

int host_image_render ( const uint8_t * data,
size_t len,
uint16_t target_w,
uint8_t * out,
size_t out_size,
uint16_t * out_stride_bytes,
uint16_t * out_height_px )

Decode, scale to target_w (aspect preserved) and dither to 1-bpp.

Parameters
dataEncoded PNG or JPEG bytes.
lenByte length.
target_wOutput width in pixels, 1..1024 (e.g. 384 for thermal print).
outCaller buffer for packed rows.
out_sizeCapacity of out in bytes.
out_stride_bytesReceives the row stride (target_w + 7) / 8.
out_height_pxReceives the scaled height.
Returns
HOST_OK, HOST_ERR_INVALID_ARG, HOST_ERR_NO_MEMORY (out too small or allocation failed), HOST_ERR_GENERIC (decode failure).

Definition at line 56 of file host_api_image.cpp.

References HOST_ERR_GENERIC, HOST_ERR_INVALID_ARG, HOST_ERR_NO_MEMORY, HOST_OK, LOG_W, cdc::core::psramAlloc(), and TAG.

Referenced by host_sprite_create_from_image(), and cdc::plugin_manager::w_host_image_render().