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

Encode text into a 1-bpp packed QR raster (no capability required). More...

Functions

int host_qr_measure (const char *data, uint8_t max_version, uint8_t ecc, uint16_t *out_modules)
 Measure the QR module count for data without rendering.
int host_qr_render_bitmap (const char *data, uint8_t max_version, uint8_t ecc, uint8_t scale, uint8_t quiet_modules, uint8_t *out, size_t out_size, uint16_t *out_stride_bytes, uint16_t *out_height_px)
 Encode data into a packed 1-bpp QR raster.

Detailed Description

Encode text into a 1-bpp packed QR raster (no capability required).

Pure compute on caller memory. The output layout matches the surface and image APIs: packed rows, MSB-first, a set bit is black. Blit the result onto a surface with host_surface_draw_bitmap or send it to a printer.

Function Documentation

◆ host_qr_measure()

int host_qr_measure ( const char * data,
uint8_t max_version,
uint8_t ecc,
uint16_t * out_modules )

Measure the QR module count for data without rendering.

Parameters
dataNUL-terminated payload text.
max_versionMaximum QR version 1..20 (0 = 20).
eccECC level 0..3 (LOW, MED, QUART, HIGH).
out_modulesReceives the side length in modules.
Returns
HOST_OK, HOST_ERR_INVALID_ARG, HOST_ERR_GENERIC (data too long).

Definition at line 16 of file host_api_qr.cpp.

References HOST_ERR_GENERIC, HOST_ERR_INVALID_ARG, HOST_OK, and cdc::ui::qr::measure().

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

◆ host_qr_render_bitmap()

int host_qr_render_bitmap ( const char * data,
uint8_t max_version,
uint8_t ecc,
uint8_t scale,
uint8_t quiet_modules,
uint8_t * out,
size_t out_size,
uint16_t * out_stride_bytes,
uint16_t * out_height_px )

Encode data into a packed 1-bpp QR raster.

Side length is (modules + 2 * quiet_modules) * scale pixels, capped at

  1. The quiet zone renders white.
    Parameters
    dataNUL-terminated payload text.
    max_versionMaximum QR version 1..20 (0 = 20).
    eccECC level 0..3.
    scalePixels per module (0 counts as 1).
    quiet_modulesQuiet-zone width in modules per edge.
    outCaller buffer for packed rows.
    out_sizeCapacity of out in bytes.
    out_stride_bytesReceives the row stride in bytes.
    out_height_pxReceives the side length in pixels.
    Returns
    HOST_OK, HOST_ERR_INVALID_ARG (bad args or side > 1024), HOST_ERR_NO_MEMORY (out too small), HOST_ERR_GENERIC.

Definition at line 24 of file host_api_qr.cpp.

References HOST_ERR_GENERIC, HOST_ERR_INVALID_ARG, HOST_ERR_NO_MEMORY, HOST_OK, and cdc::ui::qr::render().

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