10 functions · QR + PNG · MIT (Nayuki)

qrcodegen Function Reference

Compiled in by build.bat qrcodegen. QR Code generation and one-step PNG output.

Encoding (4 functions)

qrcodegen_encodeText encode

One-step text encoding (optimal mode auto-selected); the caller provides the module and temp buffers (qrcodegen_BUFFER_LEN_MAX or computed by calcSegmentBufferSize). Four ECC levels (LOW/MEDIUM/QUARTILE/HIGH); min/maxVersion 0 means auto.

bool qrcodegen_encodeText(const char* text, uint8_t tempBuffer[], uint8_t qrcode[], enum qrcodegen_Ecc ecl, enum qrcodegen_Mode minMode, enum qrcodegen_Mode maxMode, int minVersion, int maxVersion, enum qrcodegen_Mask mask, bool boostEcl);

qrcodegen_encodeBinary / encodeSegments / encodeSegmentsAdvanced encode

Binary data / segmented / advanced entries (manual mask, boostEcl control) — segmented encoding mixes numeric and text for optimal compression.

PNG output (xs helper layer)

qrcodegen_png render

One-step module-matrix to 1-bit grayscale PNG: scale×scale pixels per module, border modules of quiet zone on all sides (spec recommends ≥ 4). IDAT compressed via xrt's XDEFLATE_ZLIB stream (zlib header/adler32 from xrt), per-chunk CRC32 local. Returns an xrtMalloc buffer (free with xrtFree); *pOutSize receives the length; invalid parameters return NULL.

unsigned char* qrcodegen_png(const uint8_t qrcode[], int scale, int border, size_t* pOutSize);
Example · encode to PNG
uint8_t aQr[qrcodegen_BUFFER_LEN_MAX];
uint8_t aTemp[qrcodegen_BUFFER_LEN_MAX];
size_t iSize;
unsigned char* pPng;

if ( qrcodegen_encodeText("https://xs.xywhsoft.com",
    aTemp, aQr, qrcodegen_Ecc_MEDIUM,
    qrcodegen_Mode_BYTE, qrcodegen_Mode_BYTE, 0, 0,
    qrcodegen_Mask_AUTO, true) ) {
    pPng = qrcodegen_png(aQr, 4, 4, &iSize);
    /* pPng: PNG bytes (357 bytes @ 33 modules + 4 quiet × 4px) */
    xrtFree(pPng);
}

Reads & detection (4 functions)

qrcodegen_getSize / getModule read

Matrix side length and per-module value (true=dark) — for custom renderers (SVG, terminal art, canvas) or writing pixel buffers directly.

int qrcodegen_getSize(const uint8_t qrcode[]); bool qrcodegen_getModule(const uint8_t qrcode[], int x, int y);

qrcodegen_isNumeric / isAlphanumeric / calcSegmentBufferSize detect

Mode detection (numeric/alphanumeric) for segmented encoding decisions; calcSegmentBufferSize computes the temp buffer needed for a segment.

Upstream is zero-allocation (caller provides buffers); the PNG layer is an xserver extension helper (not upstream), depending on the host xrt deflate. Full sources in the repository's lib/qrcodegen.