xref: /third_party/qrcodegen/c/qrcodegen-demo.c (revision 5317bbaf)
15317bbafSopenharmony_ci/*
25317bbafSopenharmony_ci * QR Code generator demo (C)
35317bbafSopenharmony_ci *
45317bbafSopenharmony_ci * Run this command-line program with no arguments. The program
55317bbafSopenharmony_ci * computes a demonstration QR Codes and print it to the console.
65317bbafSopenharmony_ci *
75317bbafSopenharmony_ci * Copyright (c) Project Nayuki. (MIT License)
85317bbafSopenharmony_ci * https://www.nayuki.io/page/qr-code-generator-library
95317bbafSopenharmony_ci *
105317bbafSopenharmony_ci * Permission is hereby granted, free of charge, to any person obtaining a copy of
115317bbafSopenharmony_ci * this software and associated documentation files (the "Software"), to deal in
125317bbafSopenharmony_ci * the Software without restriction, including without limitation the rights to
135317bbafSopenharmony_ci * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
145317bbafSopenharmony_ci * the Software, and to permit persons to whom the Software is furnished to do so,
155317bbafSopenharmony_ci * subject to the following conditions:
165317bbafSopenharmony_ci * - The above copyright notice and this permission notice shall be included in
175317bbafSopenharmony_ci *   all copies or substantial portions of the Software.
185317bbafSopenharmony_ci * - The Software is provided "as is", without warranty of any kind, express or
195317bbafSopenharmony_ci *   implied, including but not limited to the warranties of merchantability,
205317bbafSopenharmony_ci *   fitness for a particular purpose and noninfringement. In no event shall the
215317bbafSopenharmony_ci *   authors or copyright holders be liable for any claim, damages or other
225317bbafSopenharmony_ci *   liability, whether in an action of contract, tort or otherwise, arising from,
235317bbafSopenharmony_ci *   out of or in connection with the Software or the use or other dealings in the
245317bbafSopenharmony_ci *   Software.
255317bbafSopenharmony_ci */
265317bbafSopenharmony_ci
275317bbafSopenharmony_ci#include <stdbool.h>
285317bbafSopenharmony_ci#include <stddef.h>
295317bbafSopenharmony_ci#include <stdio.h>
305317bbafSopenharmony_ci#include <stdlib.h>
315317bbafSopenharmony_ci#include <string.h>
325317bbafSopenharmony_ci#include "qrcodegen.h"
335317bbafSopenharmony_ci
345317bbafSopenharmony_ci
355317bbafSopenharmony_ci// Function prototypes
365317bbafSopenharmony_cistatic void doBasicDemo(void);
375317bbafSopenharmony_cistatic void doVarietyDemo(void);
385317bbafSopenharmony_cistatic void doSegmentDemo(void);
395317bbafSopenharmony_cistatic void doMaskDemo(void);
405317bbafSopenharmony_cistatic void printQr(const uint8_t qrcode[]);
415317bbafSopenharmony_ci
425317bbafSopenharmony_ci
435317bbafSopenharmony_ci// The main application program.
445317bbafSopenharmony_ciint main(void) {
455317bbafSopenharmony_ci	doBasicDemo();
465317bbafSopenharmony_ci	doVarietyDemo();
475317bbafSopenharmony_ci	doSegmentDemo();
485317bbafSopenharmony_ci	doMaskDemo();
495317bbafSopenharmony_ci	return EXIT_SUCCESS;
505317bbafSopenharmony_ci}
515317bbafSopenharmony_ci
525317bbafSopenharmony_ci
535317bbafSopenharmony_ci
545317bbafSopenharmony_ci/*---- Demo suite ----*/
555317bbafSopenharmony_ci
565317bbafSopenharmony_ci// Creates a single QR Code, then prints it to the console.
575317bbafSopenharmony_cistatic void doBasicDemo(void) {
585317bbafSopenharmony_ci	const char *text = "Hello, world!";                // User-supplied text
595317bbafSopenharmony_ci	enum qrcodegen_Ecc errCorLvl = qrcodegen_Ecc_LOW;  // Error correction level
605317bbafSopenharmony_ci
615317bbafSopenharmony_ci	// Make and print the QR Code symbol
625317bbafSopenharmony_ci	uint8_t qrcode[qrcodegen_BUFFER_LEN_MAX];
635317bbafSopenharmony_ci	uint8_t tempBuffer[qrcodegen_BUFFER_LEN_MAX];
645317bbafSopenharmony_ci	bool ok = qrcodegen_encodeText(text, tempBuffer, qrcode, errCorLvl,
655317bbafSopenharmony_ci		qrcodegen_VERSION_MIN, qrcodegen_VERSION_MAX, qrcodegen_Mask_AUTO, true);
665317bbafSopenharmony_ci	if (ok)
675317bbafSopenharmony_ci		printQr(qrcode);
685317bbafSopenharmony_ci}
695317bbafSopenharmony_ci
705317bbafSopenharmony_ci
715317bbafSopenharmony_ci// Creates a variety of QR Codes that exercise different features of the library, and prints each one to the console.
725317bbafSopenharmony_cistatic void doVarietyDemo(void) {
735317bbafSopenharmony_ci	{  // Numeric mode encoding (3.33 bits per digit)
745317bbafSopenharmony_ci		uint8_t qrcode[qrcodegen_BUFFER_LEN_MAX];
755317bbafSopenharmony_ci		uint8_t tempBuffer[qrcodegen_BUFFER_LEN_MAX];
765317bbafSopenharmony_ci		bool ok = qrcodegen_encodeText("314159265358979323846264338327950288419716939937510", tempBuffer, qrcode,
775317bbafSopenharmony_ci			qrcodegen_Ecc_MEDIUM, qrcodegen_VERSION_MIN, qrcodegen_VERSION_MAX, qrcodegen_Mask_AUTO, true);
785317bbafSopenharmony_ci		if (ok)
795317bbafSopenharmony_ci			printQr(qrcode);
805317bbafSopenharmony_ci	}
815317bbafSopenharmony_ci
825317bbafSopenharmony_ci	{  // Alphanumeric mode encoding (5.5 bits per character)
835317bbafSopenharmony_ci		uint8_t qrcode[qrcodegen_BUFFER_LEN_MAX];
845317bbafSopenharmony_ci		uint8_t tempBuffer[qrcodegen_BUFFER_LEN_MAX];
855317bbafSopenharmony_ci		bool ok = qrcodegen_encodeText("DOLLAR-AMOUNT:$39.87 PERCENTAGE:100.00% OPERATIONS:+-*/", tempBuffer, qrcode,
865317bbafSopenharmony_ci			qrcodegen_Ecc_HIGH, qrcodegen_VERSION_MIN, qrcodegen_VERSION_MAX, qrcodegen_Mask_AUTO, true);
875317bbafSopenharmony_ci		if (ok)
885317bbafSopenharmony_ci			printQr(qrcode);
895317bbafSopenharmony_ci	}
905317bbafSopenharmony_ci
915317bbafSopenharmony_ci	{  // Unicode text as UTF-8
925317bbafSopenharmony_ci		const char *text = "\xE3\x81\x93\xE3\x82\x93\xE3\x81\xAB\xE3\x81\xA1wa\xE3\x80\x81"
935317bbafSopenharmony_ci			"\xE4\xB8\x96\xE7\x95\x8C\xEF\xBC\x81\x20\xCE\xB1\xCE\xB2\xCE\xB3\xCE\xB4";
945317bbafSopenharmony_ci		uint8_t qrcode[qrcodegen_BUFFER_LEN_MAX];
955317bbafSopenharmony_ci		uint8_t tempBuffer[qrcodegen_BUFFER_LEN_MAX];
965317bbafSopenharmony_ci		bool ok = qrcodegen_encodeText(text, tempBuffer, qrcode,
975317bbafSopenharmony_ci			qrcodegen_Ecc_QUARTILE, qrcodegen_VERSION_MIN, qrcodegen_VERSION_MAX, qrcodegen_Mask_AUTO, true);
985317bbafSopenharmony_ci		if (ok)
995317bbafSopenharmony_ci			printQr(qrcode);
1005317bbafSopenharmony_ci	}
1015317bbafSopenharmony_ci
1025317bbafSopenharmony_ci	{  // Moderately large QR Code using longer text (from Lewis Carroll's Alice in Wonderland)
1035317bbafSopenharmony_ci		const char *text =
1045317bbafSopenharmony_ci			"Alice was beginning to get very tired of sitting by her sister on the bank, "
1055317bbafSopenharmony_ci			"and of having nothing to do: once or twice she had peeped into the book her sister was reading, "
1065317bbafSopenharmony_ci			"but it had no pictures or conversations in it, 'and what is the use of a book,' thought Alice "
1075317bbafSopenharmony_ci			"'without pictures or conversations?' So she was considering in her own mind (as well as she could, "
1085317bbafSopenharmony_ci			"for the hot day made her feel very sleepy and stupid), whether the pleasure of making a "
1095317bbafSopenharmony_ci			"daisy-chain would be worth the trouble of getting up and picking the daisies, when suddenly "
1105317bbafSopenharmony_ci			"a White Rabbit with pink eyes ran close by her.";
1115317bbafSopenharmony_ci		uint8_t qrcode[qrcodegen_BUFFER_LEN_MAX];
1125317bbafSopenharmony_ci		uint8_t tempBuffer[qrcodegen_BUFFER_LEN_MAX];
1135317bbafSopenharmony_ci		bool ok = qrcodegen_encodeText(text, tempBuffer, qrcode,
1145317bbafSopenharmony_ci			qrcodegen_Ecc_HIGH, qrcodegen_VERSION_MIN, qrcodegen_VERSION_MAX, qrcodegen_Mask_AUTO, true);
1155317bbafSopenharmony_ci		if (ok)
1165317bbafSopenharmony_ci			printQr(qrcode);
1175317bbafSopenharmony_ci	}
1185317bbafSopenharmony_ci}
1195317bbafSopenharmony_ci
1205317bbafSopenharmony_ci
1215317bbafSopenharmony_ci// Creates QR Codes with manually specified segments for better compactness.
1225317bbafSopenharmony_cistatic void doSegmentDemo(void) {
1235317bbafSopenharmony_ci	{  // Illustration "silver"
1245317bbafSopenharmony_ci		const char *silver0 = "THE SQUARE ROOT OF 2 IS 1.";
1255317bbafSopenharmony_ci		const char *silver1 = "41421356237309504880168872420969807856967187537694807317667973799";
1265317bbafSopenharmony_ci		uint8_t qrcode[qrcodegen_BUFFER_LEN_MAX];
1275317bbafSopenharmony_ci		uint8_t tempBuffer[qrcodegen_BUFFER_LEN_MAX];
1285317bbafSopenharmony_ci		bool ok;
1295317bbafSopenharmony_ci		{
1305317bbafSopenharmony_ci			char *concat = calloc(strlen(silver0) + strlen(silver1) + 1, sizeof(char));
1315317bbafSopenharmony_ci			if (concat == NULL) {
1325317bbafSopenharmony_ci				perror("calloc");
1335317bbafSopenharmony_ci				exit(EXIT_FAILURE);
1345317bbafSopenharmony_ci			}
1355317bbafSopenharmony_ci			strcat(concat, silver0);
1365317bbafSopenharmony_ci			strcat(concat, silver1);
1375317bbafSopenharmony_ci			ok = qrcodegen_encodeText(concat, tempBuffer, qrcode, qrcodegen_Ecc_LOW,
1385317bbafSopenharmony_ci				qrcodegen_VERSION_MIN, qrcodegen_VERSION_MAX, qrcodegen_Mask_AUTO, true);
1395317bbafSopenharmony_ci			if (ok)
1405317bbafSopenharmony_ci				printQr(qrcode);
1415317bbafSopenharmony_ci			free(concat);
1425317bbafSopenharmony_ci		}
1435317bbafSopenharmony_ci		{
1445317bbafSopenharmony_ci			uint8_t *segBuf0 = malloc(qrcodegen_calcSegmentBufferSize(qrcodegen_Mode_ALPHANUMERIC, strlen(silver0)) * sizeof(uint8_t));
1455317bbafSopenharmony_ci			uint8_t *segBuf1 = malloc(qrcodegen_calcSegmentBufferSize(qrcodegen_Mode_NUMERIC, strlen(silver1)) * sizeof(uint8_t));
1465317bbafSopenharmony_ci			if (segBuf0 == NULL || segBuf1 == NULL) {
1475317bbafSopenharmony_ci				perror("malloc");
1485317bbafSopenharmony_ci				exit(EXIT_FAILURE);
1495317bbafSopenharmony_ci			}
1505317bbafSopenharmony_ci			struct qrcodegen_Segment segs[] = {
1515317bbafSopenharmony_ci				qrcodegen_makeAlphanumeric(silver0, segBuf0),
1525317bbafSopenharmony_ci				qrcodegen_makeNumeric(silver1, segBuf1),
1535317bbafSopenharmony_ci			};
1545317bbafSopenharmony_ci			ok = qrcodegen_encodeSegments(segs, sizeof(segs) / sizeof(segs[0]), qrcodegen_Ecc_LOW, tempBuffer, qrcode);
1555317bbafSopenharmony_ci			free(segBuf0);
1565317bbafSopenharmony_ci			free(segBuf1);
1575317bbafSopenharmony_ci			if (ok)
1585317bbafSopenharmony_ci				printQr(qrcode);
1595317bbafSopenharmony_ci		}
1605317bbafSopenharmony_ci	}
1615317bbafSopenharmony_ci
1625317bbafSopenharmony_ci	{  // Illustration "golden"
1635317bbafSopenharmony_ci		const char *golden0 = "Golden ratio \xCF\x86 = 1.";
1645317bbafSopenharmony_ci		const char *golden1 = "6180339887498948482045868343656381177203091798057628621354486227052604628189024497072072041893911374";
1655317bbafSopenharmony_ci		const char *golden2 = "......";
1665317bbafSopenharmony_ci		uint8_t qrcode[qrcodegen_BUFFER_LEN_MAX];
1675317bbafSopenharmony_ci		uint8_t tempBuffer[qrcodegen_BUFFER_LEN_MAX];
1685317bbafSopenharmony_ci		bool ok;
1695317bbafSopenharmony_ci		{
1705317bbafSopenharmony_ci			char *concat = calloc(strlen(golden0) + strlen(golden1) + strlen(golden2) + 1, sizeof(char));
1715317bbafSopenharmony_ci			if (concat == NULL) {
1725317bbafSopenharmony_ci				perror("calloc");
1735317bbafSopenharmony_ci				exit(EXIT_FAILURE);
1745317bbafSopenharmony_ci			}
1755317bbafSopenharmony_ci			strcat(concat, golden0);
1765317bbafSopenharmony_ci			strcat(concat, golden1);
1775317bbafSopenharmony_ci			strcat(concat, golden2);
1785317bbafSopenharmony_ci			ok = qrcodegen_encodeText(concat, tempBuffer, qrcode, qrcodegen_Ecc_LOW,
1795317bbafSopenharmony_ci				qrcodegen_VERSION_MIN, qrcodegen_VERSION_MAX, qrcodegen_Mask_AUTO, true);
1805317bbafSopenharmony_ci			if (ok)
1815317bbafSopenharmony_ci				printQr(qrcode);
1825317bbafSopenharmony_ci			free(concat);
1835317bbafSopenharmony_ci		}
1845317bbafSopenharmony_ci		{
1855317bbafSopenharmony_ci			uint8_t *bytes = malloc(strlen(golden0) * sizeof(uint8_t));
1865317bbafSopenharmony_ci			if (bytes == NULL) {
1875317bbafSopenharmony_ci				perror("malloc");
1885317bbafSopenharmony_ci				exit(EXIT_FAILURE);
1895317bbafSopenharmony_ci			}
1905317bbafSopenharmony_ci			for (size_t i = 0, len = strlen(golden0); i < len; i++)
1915317bbafSopenharmony_ci				bytes[i] = (uint8_t)golden0[i];
1925317bbafSopenharmony_ci			uint8_t *segBuf0 = malloc(qrcodegen_calcSegmentBufferSize(qrcodegen_Mode_BYTE, strlen(golden0)) * sizeof(uint8_t));
1935317bbafSopenharmony_ci			uint8_t *segBuf1 = malloc(qrcodegen_calcSegmentBufferSize(qrcodegen_Mode_NUMERIC, strlen(golden1)) * sizeof(uint8_t));
1945317bbafSopenharmony_ci			uint8_t *segBuf2 = malloc(qrcodegen_calcSegmentBufferSize(qrcodegen_Mode_ALPHANUMERIC, strlen(golden2)) * sizeof(uint8_t));
1955317bbafSopenharmony_ci			if (segBuf0 == NULL || segBuf1 == NULL || segBuf2 == NULL) {
1965317bbafSopenharmony_ci				perror("malloc");
1975317bbafSopenharmony_ci				exit(EXIT_FAILURE);
1985317bbafSopenharmony_ci			}
1995317bbafSopenharmony_ci			struct qrcodegen_Segment segs[] = {
2005317bbafSopenharmony_ci				qrcodegen_makeBytes(bytes, strlen(golden0), segBuf0),
2015317bbafSopenharmony_ci				qrcodegen_makeNumeric(golden1, segBuf1),
2025317bbafSopenharmony_ci				qrcodegen_makeAlphanumeric(golden2, segBuf2),
2035317bbafSopenharmony_ci			};
2045317bbafSopenharmony_ci			free(bytes);
2055317bbafSopenharmony_ci			ok = qrcodegen_encodeSegments(segs, sizeof(segs) / sizeof(segs[0]), qrcodegen_Ecc_LOW, tempBuffer, qrcode);
2065317bbafSopenharmony_ci			free(segBuf0);
2075317bbafSopenharmony_ci			free(segBuf1);
2085317bbafSopenharmony_ci			free(segBuf2);
2095317bbafSopenharmony_ci			if (ok)
2105317bbafSopenharmony_ci				printQr(qrcode);
2115317bbafSopenharmony_ci		}
2125317bbafSopenharmony_ci	}
2135317bbafSopenharmony_ci
2145317bbafSopenharmony_ci	{  // Illustration "Madoka": kanji, kana, Cyrillic, full-width Latin, Greek characters
2155317bbafSopenharmony_ci		uint8_t qrcode[qrcodegen_BUFFER_LEN_MAX];
2165317bbafSopenharmony_ci		uint8_t tempBuffer[qrcodegen_BUFFER_LEN_MAX];
2175317bbafSopenharmony_ci		bool ok;
2185317bbafSopenharmony_ci		{
2195317bbafSopenharmony_ci			const char *madoka =  // Encoded in UTF-8
2205317bbafSopenharmony_ci				"\xE3\x80\x8C\xE9\xAD\x94\xE6\xB3\x95\xE5"
2215317bbafSopenharmony_ci				"\xB0\x91\xE5\xA5\xB3\xE3\x81\xBE\xE3\x81"
2225317bbafSopenharmony_ci				"\xA9\xE3\x81\x8B\xE2\x98\x86\xE3\x83\x9E"
2235317bbafSopenharmony_ci				"\xE3\x82\xAE\xE3\x82\xAB\xE3\x80\x8D\xE3"
2245317bbafSopenharmony_ci				"\x81\xA3\xE3\x81\xA6\xE3\x80\x81\xE3\x80"
2255317bbafSopenharmony_ci				"\x80\xD0\x98\xD0\x90\xD0\x98\xE3\x80\x80"
2265317bbafSopenharmony_ci				"\xEF\xBD\x84\xEF\xBD\x85\xEF\xBD\x93\xEF"
2275317bbafSopenharmony_ci				"\xBD\x95\xE3\x80\x80\xCE\xBA\xCE\xB1\xEF"
2285317bbafSopenharmony_ci				"\xBC\x9F";
2295317bbafSopenharmony_ci			ok = qrcodegen_encodeText(madoka, tempBuffer, qrcode, qrcodegen_Ecc_LOW,
2305317bbafSopenharmony_ci				qrcodegen_VERSION_MIN, qrcodegen_VERSION_MAX, qrcodegen_Mask_AUTO, true);
2315317bbafSopenharmony_ci			if (ok)
2325317bbafSopenharmony_ci				printQr(qrcode);
2335317bbafSopenharmony_ci		}
2345317bbafSopenharmony_ci		{
2355317bbafSopenharmony_ci			const int kanjiChars[] = {  // Kanji mode encoding (13 bits per character)
2365317bbafSopenharmony_ci				0x0035, 0x1002, 0x0FC0, 0x0AED, 0x0AD7,
2375317bbafSopenharmony_ci				0x015C, 0x0147, 0x0129, 0x0059, 0x01BD,
2385317bbafSopenharmony_ci				0x018D, 0x018A, 0x0036, 0x0141, 0x0144,
2395317bbafSopenharmony_ci				0x0001, 0x0000, 0x0249, 0x0240, 0x0249,
2405317bbafSopenharmony_ci				0x0000, 0x0104, 0x0105, 0x0113, 0x0115,
2415317bbafSopenharmony_ci				0x0000, 0x0208, 0x01FF, 0x0008,
2425317bbafSopenharmony_ci			};
2435317bbafSopenharmony_ci			size_t len = sizeof(kanjiChars) / sizeof(kanjiChars[0]);
2445317bbafSopenharmony_ci			uint8_t *segBuf = calloc(qrcodegen_calcSegmentBufferSize(qrcodegen_Mode_KANJI, len), sizeof(uint8_t));
2455317bbafSopenharmony_ci			if (segBuf == NULL) {
2465317bbafSopenharmony_ci				perror("calloc");
2475317bbafSopenharmony_ci				exit(EXIT_FAILURE);
2485317bbafSopenharmony_ci			}
2495317bbafSopenharmony_ci			struct qrcodegen_Segment seg;
2505317bbafSopenharmony_ci			seg.mode = qrcodegen_Mode_KANJI;
2515317bbafSopenharmony_ci			seg.numChars = (int)len;
2525317bbafSopenharmony_ci			seg.bitLength = 0;
2535317bbafSopenharmony_ci			for (size_t i = 0; i < len; i++) {
2545317bbafSopenharmony_ci				for (int j = 12; j >= 0; j--, seg.bitLength++)
2555317bbafSopenharmony_ci					segBuf[seg.bitLength >> 3] |= ((kanjiChars[i] >> j) & 1) << (7 - (seg.bitLength & 7));
2565317bbafSopenharmony_ci			}
2575317bbafSopenharmony_ci			seg.data = segBuf;
2585317bbafSopenharmony_ci			ok = qrcodegen_encodeSegments(&seg, 1, qrcodegen_Ecc_LOW, tempBuffer, qrcode);
2595317bbafSopenharmony_ci			free(segBuf);
2605317bbafSopenharmony_ci			if (ok)
2615317bbafSopenharmony_ci				printQr(qrcode);
2625317bbafSopenharmony_ci		}
2635317bbafSopenharmony_ci	}
2645317bbafSopenharmony_ci}
2655317bbafSopenharmony_ci
2665317bbafSopenharmony_ci
2675317bbafSopenharmony_ci// Creates QR Codes with the same size and contents but different mask patterns.
2685317bbafSopenharmony_cistatic void doMaskDemo(void) {
2695317bbafSopenharmony_ci	{  // Project Nayuki URL
2705317bbafSopenharmony_ci		uint8_t qrcode[qrcodegen_BUFFER_LEN_MAX];
2715317bbafSopenharmony_ci		uint8_t tempBuffer[qrcodegen_BUFFER_LEN_MAX];
2725317bbafSopenharmony_ci		bool ok;
2735317bbafSopenharmony_ci
2745317bbafSopenharmony_ci		ok = qrcodegen_encodeText("https://www.nayuki.io/", tempBuffer, qrcode,
2755317bbafSopenharmony_ci			qrcodegen_Ecc_HIGH, qrcodegen_VERSION_MIN, qrcodegen_VERSION_MAX, qrcodegen_Mask_AUTO, true);
2765317bbafSopenharmony_ci		if (ok)
2775317bbafSopenharmony_ci			printQr(qrcode);
2785317bbafSopenharmony_ci
2795317bbafSopenharmony_ci		ok = qrcodegen_encodeText("https://www.nayuki.io/", tempBuffer, qrcode,
2805317bbafSopenharmony_ci			qrcodegen_Ecc_HIGH, qrcodegen_VERSION_MIN, qrcodegen_VERSION_MAX, qrcodegen_Mask_3, true);
2815317bbafSopenharmony_ci		if (ok)
2825317bbafSopenharmony_ci			printQr(qrcode);
2835317bbafSopenharmony_ci	}
2845317bbafSopenharmony_ci
2855317bbafSopenharmony_ci	{  // Chinese text as UTF-8
2865317bbafSopenharmony_ci		const char *text =
2875317bbafSopenharmony_ci			"\xE7\xB6\xAD\xE5\x9F\xBA\xE7\x99\xBE\xE7\xA7\x91\xEF\xBC\x88\x57\x69\x6B\x69\x70"
2885317bbafSopenharmony_ci			"\x65\x64\x69\x61\xEF\xBC\x8C\xE8\x81\x86\xE8\x81\xBD\x69\x2F\xCB\x8C\x77\xC9\xAA"
2895317bbafSopenharmony_ci			"\x6B\xE1\xB5\xBB\xCB\x88\x70\x69\xCB\x90\x64\x69\x2E\xC9\x99\x2F\xEF\xBC\x89\xE6"
2905317bbafSopenharmony_ci			"\x98\xAF\xE4\xB8\x80\xE5\x80\x8B\xE8\x87\xAA\xE7\x94\xB1\xE5\x85\xA7\xE5\xAE\xB9"
2915317bbafSopenharmony_ci			"\xE3\x80\x81\xE5\x85\xAC\xE9\x96\x8B\xE7\xB7\xA8\xE8\xBC\xAF\xE4\xB8\x94\xE5\xA4"
2925317bbafSopenharmony_ci			"\x9A\xE8\xAA\x9E\xE8\xA8\x80\xE7\x9A\x84\xE7\xB6\xB2\xE8\xB7\xAF\xE7\x99\xBE\xE7"
2935317bbafSopenharmony_ci			"\xA7\x91\xE5\x85\xA8\xE6\x9B\xB8\xE5\x8D\x94\xE4\xBD\x9C\xE8\xA8\x88\xE7\x95\xAB";
2945317bbafSopenharmony_ci		uint8_t qrcode[qrcodegen_BUFFER_LEN_MAX];
2955317bbafSopenharmony_ci		uint8_t tempBuffer[qrcodegen_BUFFER_LEN_MAX];
2965317bbafSopenharmony_ci		bool ok;
2975317bbafSopenharmony_ci
2985317bbafSopenharmony_ci		ok = qrcodegen_encodeText(text, tempBuffer, qrcode,
2995317bbafSopenharmony_ci			qrcodegen_Ecc_MEDIUM, qrcodegen_VERSION_MIN, qrcodegen_VERSION_MAX, qrcodegen_Mask_0, true);
3005317bbafSopenharmony_ci		if (ok)
3015317bbafSopenharmony_ci			printQr(qrcode);
3025317bbafSopenharmony_ci
3035317bbafSopenharmony_ci		ok = qrcodegen_encodeText(text, tempBuffer, qrcode,
3045317bbafSopenharmony_ci			qrcodegen_Ecc_MEDIUM, qrcodegen_VERSION_MIN, qrcodegen_VERSION_MAX, qrcodegen_Mask_1, true);
3055317bbafSopenharmony_ci		if (ok)
3065317bbafSopenharmony_ci			printQr(qrcode);
3075317bbafSopenharmony_ci
3085317bbafSopenharmony_ci		ok = qrcodegen_encodeText(text, tempBuffer, qrcode,
3095317bbafSopenharmony_ci			qrcodegen_Ecc_MEDIUM, qrcodegen_VERSION_MIN, qrcodegen_VERSION_MAX, qrcodegen_Mask_5, true);
3105317bbafSopenharmony_ci		if (ok)
3115317bbafSopenharmony_ci			printQr(qrcode);
3125317bbafSopenharmony_ci
3135317bbafSopenharmony_ci		ok = qrcodegen_encodeText(text, tempBuffer, qrcode,
3145317bbafSopenharmony_ci			qrcodegen_Ecc_MEDIUM, qrcodegen_VERSION_MIN, qrcodegen_VERSION_MAX, qrcodegen_Mask_7, true);
3155317bbafSopenharmony_ci		if (ok)
3165317bbafSopenharmony_ci			printQr(qrcode);
3175317bbafSopenharmony_ci	}
3185317bbafSopenharmony_ci}
3195317bbafSopenharmony_ci
3205317bbafSopenharmony_ci
3215317bbafSopenharmony_ci
3225317bbafSopenharmony_ci/*---- Utilities ----*/
3235317bbafSopenharmony_ci
3245317bbafSopenharmony_ci// Prints the given QR Code to the console.
3255317bbafSopenharmony_cistatic void printQr(const uint8_t qrcode[]) {
3265317bbafSopenharmony_ci	int size = qrcodegen_getSize(qrcode);
3275317bbafSopenharmony_ci	int border = 4;
3285317bbafSopenharmony_ci	for (int y = -border; y < size + border; y++) {
3295317bbafSopenharmony_ci		for (int x = -border; x < size + border; x++) {
3305317bbafSopenharmony_ci			fputs((qrcodegen_getModule(qrcode, x, y) ? "##" : "  "), stdout);
3315317bbafSopenharmony_ci		}
3325317bbafSopenharmony_ci		fputs("\n", stdout);
3335317bbafSopenharmony_ci	}
3345317bbafSopenharmony_ci	fputs("\n", stdout);
3355317bbafSopenharmony_ci}
336