CDC Badge OS
Firmware for the CDC Badge v1.0 hardware security key
Loading...
Searching...
No Matches
cdc::ui::qr Namespace Reference

Functions

void packModule (uint8_t *out, uint16_t stride, uint8_t scale, uint8_t quiet, int mx, int my)
 Sets the packed pixels of one black QR module.
int measure (const char *data, uint8_t max_version, uint8_t ecc, uint16_t *out_modules)
 Measures the module count for data without rendering.
int render (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)
 Encodes data and packs it into a 1-bpp raster.

Variables

constexpr uint16_t QR_MAX_SIDE_PX = 1024
 Hard cap on the rendered side length in pixels (incl. quiet zone, scaled).

Function Documentation

◆ measure()

int cdc::ui::qr::measure ( const char * data,
uint8_t max_version,
uint8_t ecc,
uint16_t * out_modules )

Measures the module count for data without rendering.

Parameters
dataNUL-terminated payload text.
max_versionMaximum QR version 1..20 (0 defaults to 20).
eccECC level 0..3 (LOW..HIGH).
out_modulesReceives the side length in modules.
Returns
0 on success, negative on failure (bad args or data too long).

Definition at line 73 of file QrRaster.cpp.

Referenced by host_qr_measure(), and render().

◆ packModule()

void cdc::ui::qr::packModule ( uint8_t * out,
uint16_t stride,
uint8_t scale,
uint8_t quiet,
int mx,
int my )
inline

Sets the packed pixels of one black QR module.

Pure bit-packing shared by the firmware renderer and the host unit tests: module (mx, my) inks a scale x scale pixel block offset by the quiet zone. Rows are MSB-first, a set bit is black.

Parameters
outPacked raster, stride bytes per row, pre-cleared to white.
strideBytes per row.
scalePixels per module, >= 1.
quietQuiet-zone width in modules per edge.
mxModule column.
myModule row.

Definition at line 33 of file QrRaster.h.

References cdc::ui::scale.

◆ render()

int cdc::ui::qr::render ( 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 )

Encodes data and packs it into a 1-bpp raster.

The rendered side is (modules + 2 * quiet_modules) * scale pixels; the quiet zone is white. Rows are packed MSB-first with a set bit meaning black.

Parameters
dataNUL-terminated payload text.
max_versionMaximum QR version 1..20 (0 defaults to 20).
eccECC level 0..3 (LOW..HIGH).
scalePixels per module, >= 1.
quiet_modulesQuiet-zone width in modules per edge.
outCaller buffer for the packed rows.
out_sizeCapacity of out in bytes.
out_stride_bytesReceives the row stride (side_px + 7) / 8.
out_height_pxReceives the side length in pixels.
Returns
0 on success, -1 on encode failure, -2 on bad args / side too large, -3 when out is too small.

Definition at line 84 of file QrRaster.cpp.

References measure(), QR_MAX_SIDE_PX, and cdc::ui::scale.

Referenced by host_qr_render_bitmap().

Variable Documentation

◆ QR_MAX_SIDE_PX

uint16_t cdc::ui::qr::QR_MAX_SIDE_PX = 1024
inlineconstexpr

Hard cap on the rendered side length in pixels (incl. quiet zone, scaled).

Definition at line 18 of file QrRaster.h.

Referenced by render().