15317bbafSopenharmony_ciQR Code generator library - C 25317bbafSopenharmony_ci============================= 35317bbafSopenharmony_ci 45317bbafSopenharmony_ci 55317bbafSopenharmony_ciIntroduction 65317bbafSopenharmony_ci------------ 75317bbafSopenharmony_ci 85317bbafSopenharmony_ciThis project aims to be the best, clearest QR Code generator library. The primary goals are flexible options and absolute correctness. Secondary goals are compact implementation size and good documentation comments. 95317bbafSopenharmony_ci 105317bbafSopenharmony_ciHome page with live JavaScript demo, extensive descriptions, and competitor comparisons: https://www.nayuki.io/page/qr-code-generator-library 115317bbafSopenharmony_ci 125317bbafSopenharmony_ci 135317bbafSopenharmony_ciFeatures 145317bbafSopenharmony_ci-------- 155317bbafSopenharmony_ci 165317bbafSopenharmony_ciCore features: 175317bbafSopenharmony_ci 185317bbafSopenharmony_ci* Significantly shorter code but more documentation comments compared to competing libraries 195317bbafSopenharmony_ci* Supports encoding all 40 versions (sizes) and all 4 error correction levels, as per the QR Code Model 2 standard 205317bbafSopenharmony_ci* Output format: Raw modules/pixels of the QR symbol 215317bbafSopenharmony_ci* Detects finder-like penalty patterns more accurately than other implementations 225317bbafSopenharmony_ci* Encodes numeric and special-alphanumeric text in less space than general text 235317bbafSopenharmony_ci* Completely avoids heap allocation (`malloc()`), instead relying on suitably sized buffers from the caller and fixed-size stack allocations 245317bbafSopenharmony_ci* Coded carefully to prevent memory corruption, integer overflow, platform-dependent inconsistencies, and undefined behavior; tested rigorously to confirm safety 255317bbafSopenharmony_ci* Open-source code under the permissive MIT License 265317bbafSopenharmony_ci 275317bbafSopenharmony_ciManual parameters: 285317bbafSopenharmony_ci 295317bbafSopenharmony_ci* User can specify minimum and maximum version numbers allowed, then library will automatically choose smallest version in the range that fits the data 305317bbafSopenharmony_ci* User can specify mask pattern manually, otherwise library will automatically evaluate all 8 masks and select the optimal one 315317bbafSopenharmony_ci* User can specify absolute error correction level, or allow the library to boost it if it doesn't increase the version number 325317bbafSopenharmony_ci* User can create a list of data segments manually and add ECI segments 335317bbafSopenharmony_ci 345317bbafSopenharmony_ciMore information about QR Code technology and this library's design can be found on the project home page. 355317bbafSopenharmony_ci 365317bbafSopenharmony_ci 375317bbafSopenharmony_ciExamples 385317bbafSopenharmony_ci-------- 395317bbafSopenharmony_ci 405317bbafSopenharmony_ci```c 415317bbafSopenharmony_ci#include <stdbool.h> 425317bbafSopenharmony_ci#include <stdint.h> 435317bbafSopenharmony_ci#include "qrcodegen.h" 445317bbafSopenharmony_ci 455317bbafSopenharmony_ci// Text data 465317bbafSopenharmony_ciuint8_t qr0[qrcodegen_BUFFER_LEN_MAX]; 475317bbafSopenharmony_ciuint8_t tempBuffer[qrcodegen_BUFFER_LEN_MAX]; 485317bbafSopenharmony_cibool ok = qrcodegen_encodeText("Hello, world!", 495317bbafSopenharmony_ci tempBuffer, qr0, qrcodegen_Ecc_MEDIUM, 505317bbafSopenharmony_ci qrcodegen_VERSION_MIN, qrcodegen_VERSION_MAX, 515317bbafSopenharmony_ci qrcodegen_Mask_AUTO, true); 525317bbafSopenharmony_ciif (!ok) 535317bbafSopenharmony_ci return; 545317bbafSopenharmony_ci 555317bbafSopenharmony_ciint size = qrcodegen_getSize(qr0); 565317bbafSopenharmony_cifor (int y = 0; y < size; y++) { 575317bbafSopenharmony_ci for (int x = 0; x < size; x++) { 585317bbafSopenharmony_ci (... paint qrcodegen_getModule(qr0, x, y) ...) 595317bbafSopenharmony_ci } 605317bbafSopenharmony_ci} 615317bbafSopenharmony_ci 625317bbafSopenharmony_ci// Binary data 635317bbafSopenharmony_ciuint8_t dataAndTemp[qrcodegen_BUFFER_LEN_FOR_VERSION(7)] 645317bbafSopenharmony_ci = {0xE3, 0x81, 0x82}; 655317bbafSopenharmony_ciuint8_t qr1[qrcodegen_BUFFER_LEN_FOR_VERSION(7)]; 665317bbafSopenharmony_ciok = qrcodegen_encodeBinary(dataAndTemp, 3, qr1, 675317bbafSopenharmony_ci qrcodegen_Ecc_HIGH, 2, 7, qrcodegen_Mask_4, false); 685317bbafSopenharmony_ci``` 695317bbafSopenharmony_ci 705317bbafSopenharmony_ciMore complete set of examples: https://github.com/nayuki/QR-Code-generator/blob/master/c/qrcodegen-demo.c . 71