xref: /third_party/qrcodegen/c/qrcodegen.h (revision 5317bbaf)
15317bbafSopenharmony_ci/*
25317bbafSopenharmony_ci * QR Code generator library (C)
35317bbafSopenharmony_ci *
45317bbafSopenharmony_ci * Copyright (c) Project Nayuki. (MIT License)
55317bbafSopenharmony_ci * https://www.nayuki.io/page/qr-code-generator-library
65317bbafSopenharmony_ci *
75317bbafSopenharmony_ci * Permission is hereby granted, free of charge, to any person obtaining a copy of
85317bbafSopenharmony_ci * this software and associated documentation files (the "Software"), to deal in
95317bbafSopenharmony_ci * the Software without restriction, including without limitation the rights to
105317bbafSopenharmony_ci * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
115317bbafSopenharmony_ci * the Software, and to permit persons to whom the Software is furnished to do so,
125317bbafSopenharmony_ci * subject to the following conditions:
135317bbafSopenharmony_ci * - The above copyright notice and this permission notice shall be included in
145317bbafSopenharmony_ci *   all copies or substantial portions of the Software.
155317bbafSopenharmony_ci * - The Software is provided "as is", without warranty of any kind, express or
165317bbafSopenharmony_ci *   implied, including but not limited to the warranties of merchantability,
175317bbafSopenharmony_ci *   fitness for a particular purpose and noninfringement. In no event shall the
185317bbafSopenharmony_ci *   authors or copyright holders be liable for any claim, damages or other
195317bbafSopenharmony_ci *   liability, whether in an action of contract, tort or otherwise, arising from,
205317bbafSopenharmony_ci *   out of or in connection with the Software or the use or other dealings in the
215317bbafSopenharmony_ci *   Software.
225317bbafSopenharmony_ci */
235317bbafSopenharmony_ci
245317bbafSopenharmony_ci#pragma once
255317bbafSopenharmony_ci
265317bbafSopenharmony_ci#include <stdbool.h>
275317bbafSopenharmony_ci#include <stddef.h>
285317bbafSopenharmony_ci#include <stdint.h>
295317bbafSopenharmony_ci
305317bbafSopenharmony_ci
315317bbafSopenharmony_ci#ifdef __cplusplus
325317bbafSopenharmony_ciextern "C" {
335317bbafSopenharmony_ci#endif
345317bbafSopenharmony_ci
355317bbafSopenharmony_ci
365317bbafSopenharmony_ci/*
375317bbafSopenharmony_ci * This library creates QR Code symbols, which is a type of two-dimension barcode.
385317bbafSopenharmony_ci * Invented by Denso Wave and described in the ISO/IEC 18004 standard.
395317bbafSopenharmony_ci * A QR Code structure is an immutable square grid of dark and light cells.
405317bbafSopenharmony_ci * The library provides functions to create a QR Code from text or binary data.
415317bbafSopenharmony_ci * The library covers the QR Code Model 2 specification, supporting all versions (sizes)
425317bbafSopenharmony_ci * from 1 to 40, all 4 error correction levels, and 4 character encoding modes.
435317bbafSopenharmony_ci *
445317bbafSopenharmony_ci * Ways to create a QR Code object:
455317bbafSopenharmony_ci * - High level: Take the payload data and call qrcodegen_encodeText() or qrcodegen_encodeBinary().
465317bbafSopenharmony_ci * - Low level: Custom-make the list of segments and call
475317bbafSopenharmony_ci *   qrcodegen_encodeSegments() or qrcodegen_encodeSegmentsAdvanced().
485317bbafSopenharmony_ci * (Note that all ways require supplying the desired error correction level and various byte buffers.)
495317bbafSopenharmony_ci */
505317bbafSopenharmony_ci
515317bbafSopenharmony_ci
525317bbafSopenharmony_ci/*---- Enum and struct types----*/
535317bbafSopenharmony_ci
545317bbafSopenharmony_ci/*
555317bbafSopenharmony_ci * The error correction level in a QR Code symbol.
565317bbafSopenharmony_ci */
575317bbafSopenharmony_cienum qrcodegen_Ecc {
585317bbafSopenharmony_ci	// Must be declared in ascending order of error protection
595317bbafSopenharmony_ci	// so that an internal qrcodegen function works properly
605317bbafSopenharmony_ci	qrcodegen_Ecc_LOW = 0 ,  // The QR Code can tolerate about  7% erroneous codewords
615317bbafSopenharmony_ci	qrcodegen_Ecc_MEDIUM  ,  // The QR Code can tolerate about 15% erroneous codewords
625317bbafSopenharmony_ci	qrcodegen_Ecc_QUARTILE,  // The QR Code can tolerate about 25% erroneous codewords
635317bbafSopenharmony_ci	qrcodegen_Ecc_HIGH    ,  // The QR Code can tolerate about 30% erroneous codewords
645317bbafSopenharmony_ci};
655317bbafSopenharmony_ci
665317bbafSopenharmony_ci
675317bbafSopenharmony_ci/*
685317bbafSopenharmony_ci * The mask pattern used in a QR Code symbol.
695317bbafSopenharmony_ci */
705317bbafSopenharmony_cienum qrcodegen_Mask {
715317bbafSopenharmony_ci	// A special value to tell the QR Code encoder to
725317bbafSopenharmony_ci	// automatically select an appropriate mask pattern
735317bbafSopenharmony_ci	qrcodegen_Mask_AUTO = -1,
745317bbafSopenharmony_ci	// The eight actual mask patterns
755317bbafSopenharmony_ci	qrcodegen_Mask_0 = 0,
765317bbafSopenharmony_ci	qrcodegen_Mask_1,
775317bbafSopenharmony_ci	qrcodegen_Mask_2,
785317bbafSopenharmony_ci	qrcodegen_Mask_3,
795317bbafSopenharmony_ci	qrcodegen_Mask_4,
805317bbafSopenharmony_ci	qrcodegen_Mask_5,
815317bbafSopenharmony_ci	qrcodegen_Mask_6,
825317bbafSopenharmony_ci	qrcodegen_Mask_7,
835317bbafSopenharmony_ci};
845317bbafSopenharmony_ci
855317bbafSopenharmony_ci
865317bbafSopenharmony_ci/*
875317bbafSopenharmony_ci * Describes how a segment's data bits are interpreted.
885317bbafSopenharmony_ci */
895317bbafSopenharmony_cienum qrcodegen_Mode {
905317bbafSopenharmony_ci	qrcodegen_Mode_NUMERIC      = 0x1,
915317bbafSopenharmony_ci	qrcodegen_Mode_ALPHANUMERIC = 0x2,
925317bbafSopenharmony_ci	qrcodegen_Mode_BYTE         = 0x4,
935317bbafSopenharmony_ci	qrcodegen_Mode_KANJI        = 0x8,
945317bbafSopenharmony_ci	qrcodegen_Mode_ECI          = 0x7,
955317bbafSopenharmony_ci};
965317bbafSopenharmony_ci
975317bbafSopenharmony_ci
985317bbafSopenharmony_ci/*
995317bbafSopenharmony_ci * A segment of character/binary/control data in a QR Code symbol.
1005317bbafSopenharmony_ci * The mid-level way to create a segment is to take the payload data
1015317bbafSopenharmony_ci * and call a factory function such as qrcodegen_makeNumeric().
1025317bbafSopenharmony_ci * The low-level way to create a segment is to custom-make the bit buffer
1035317bbafSopenharmony_ci * and initialize a qrcodegen_Segment struct with appropriate values.
1045317bbafSopenharmony_ci * Even in the most favorable conditions, a QR Code can only hold 7089 characters of data.
1055317bbafSopenharmony_ci * Any segment longer than this is meaningless for the purpose of generating QR Codes.
1065317bbafSopenharmony_ci * Moreover, the maximum allowed bit length is 32767 because
1075317bbafSopenharmony_ci * the largest QR Code (version 40) has 31329 modules.
1085317bbafSopenharmony_ci */
1095317bbafSopenharmony_cistruct qrcodegen_Segment {
1105317bbafSopenharmony_ci	// The mode indicator of this segment.
1115317bbafSopenharmony_ci	enum qrcodegen_Mode mode;
1125317bbafSopenharmony_ci
1135317bbafSopenharmony_ci	// The length of this segment's unencoded data. Measured in characters for
1145317bbafSopenharmony_ci	// numeric/alphanumeric/kanji mode, bytes for byte mode, and 0 for ECI mode.
1155317bbafSopenharmony_ci	// Always zero or positive. Not the same as the data's bit length.
1165317bbafSopenharmony_ci	int numChars;
1175317bbafSopenharmony_ci
1185317bbafSopenharmony_ci	// The data bits of this segment, packed in bitwise big endian.
1195317bbafSopenharmony_ci	// Can be null if the bit length is zero.
1205317bbafSopenharmony_ci	uint8_t *data;
1215317bbafSopenharmony_ci
1225317bbafSopenharmony_ci	// The number of valid data bits used in the buffer. Requires
1235317bbafSopenharmony_ci	// 0 <= bitLength <= 32767, and bitLength <= (capacity of data array) * 8.
1245317bbafSopenharmony_ci	// The character count (numChars) must agree with the mode and the bit buffer length.
1255317bbafSopenharmony_ci	int bitLength;
1265317bbafSopenharmony_ci};
1275317bbafSopenharmony_ci
1285317bbafSopenharmony_ci
1295317bbafSopenharmony_ci
1305317bbafSopenharmony_ci/*---- Macro constants and functions ----*/
1315317bbafSopenharmony_ci
1325317bbafSopenharmony_ci#define qrcodegen_VERSION_MIN   1  // The minimum version number supported in the QR Code Model 2 standard
1335317bbafSopenharmony_ci#define qrcodegen_VERSION_MAX  40  // The maximum version number supported in the QR Code Model 2 standard
1345317bbafSopenharmony_ci
1355317bbafSopenharmony_ci// Calculates the number of bytes needed to store any QR Code up to and including the given version number,
1365317bbafSopenharmony_ci// as a compile-time constant. For example, 'uint8_t buffer[qrcodegen_BUFFER_LEN_FOR_VERSION(25)];'
1375317bbafSopenharmony_ci// can store any single QR Code from version 1 to 25 (inclusive). The result fits in an int (or int16).
1385317bbafSopenharmony_ci// Requires qrcodegen_VERSION_MIN <= n <= qrcodegen_VERSION_MAX.
1395317bbafSopenharmony_ci#define qrcodegen_BUFFER_LEN_FOR_VERSION(n)  ((((n) * 4 + 17) * ((n) * 4 + 17) + 7) / 8 + 1)
1405317bbafSopenharmony_ci
1415317bbafSopenharmony_ci// The worst-case number of bytes needed to store one QR Code, up to and including
1425317bbafSopenharmony_ci// version 40. This value equals 3918, which is just under 4 kilobytes.
1435317bbafSopenharmony_ci// Use this more convenient value to avoid calculating tighter memory bounds for buffers.
1445317bbafSopenharmony_ci#define qrcodegen_BUFFER_LEN_MAX  qrcodegen_BUFFER_LEN_FOR_VERSION(qrcodegen_VERSION_MAX)
1455317bbafSopenharmony_ci
1465317bbafSopenharmony_ci
1475317bbafSopenharmony_ci
1485317bbafSopenharmony_ci/*---- Functions (high level) to generate QR Codes ----*/
1495317bbafSopenharmony_ci
1505317bbafSopenharmony_ci/*
1515317bbafSopenharmony_ci * Encodes the given text string to a QR Code, returning true if successful.
1525317bbafSopenharmony_ci * If the data is too long to fit in any version in the given range
1535317bbafSopenharmony_ci * at the given ECC level, then false is returned.
1545317bbafSopenharmony_ci *
1555317bbafSopenharmony_ci * The input text must be encoded in UTF-8 and contain no NULs.
1565317bbafSopenharmony_ci * Requires 1 <= minVersion <= maxVersion <= 40.
1575317bbafSopenharmony_ci *
1585317bbafSopenharmony_ci * The smallest possible QR Code version within the given range is automatically
1595317bbafSopenharmony_ci * chosen for the output. Iff boostEcl is true, then the ECC level of the result
1605317bbafSopenharmony_ci * may be higher than the ecl argument if it can be done without increasing the
1615317bbafSopenharmony_ci * version. The mask is either between qrcodegen_Mask_0 to 7 to force that mask, or
1625317bbafSopenharmony_ci * qrcodegen_Mask_AUTO to automatically choose an appropriate mask (which may be slow).
1635317bbafSopenharmony_ci *
1645317bbafSopenharmony_ci * About the arrays, letting len = qrcodegen_BUFFER_LEN_FOR_VERSION(maxVersion):
1655317bbafSopenharmony_ci * - Before calling the function:
1665317bbafSopenharmony_ci *   - The array ranges tempBuffer[0 : len] and qrcode[0 : len] must allow
1675317bbafSopenharmony_ci *     reading and writing; hence each array must have a length of at least len.
1685317bbafSopenharmony_ci *   - The two ranges must not overlap (aliasing).
1695317bbafSopenharmony_ci *   - The initial state of both ranges can be uninitialized
1705317bbafSopenharmony_ci *     because the function always writes before reading.
1715317bbafSopenharmony_ci * - After the function returns:
1725317bbafSopenharmony_ci *   - Both ranges have no guarantee on which elements are initialized and what values are stored.
1735317bbafSopenharmony_ci *   - tempBuffer contains no useful data and should be treated as entirely uninitialized.
1745317bbafSopenharmony_ci *   - If successful, qrcode can be passed into qrcodegen_getSize() and qrcodegen_getModule().
1755317bbafSopenharmony_ci *
1765317bbafSopenharmony_ci * If successful, the resulting QR Code may use numeric,
1775317bbafSopenharmony_ci * alphanumeric, or byte mode to encode the text.
1785317bbafSopenharmony_ci *
1795317bbafSopenharmony_ci * In the most optimistic case, a QR Code at version 40 with low ECC
1805317bbafSopenharmony_ci * can hold any UTF-8 string up to 2953 bytes, or any alphanumeric string
1815317bbafSopenharmony_ci * up to 4296 characters, or any digit string up to 7089 characters.
1825317bbafSopenharmony_ci * These numbers represent the hard upper limit of the QR Code standard.
1835317bbafSopenharmony_ci *
1845317bbafSopenharmony_ci * Please consult the QR Code specification for information on
1855317bbafSopenharmony_ci * data capacities per version, ECC level, and text encoding mode.
1865317bbafSopenharmony_ci */
1875317bbafSopenharmony_cibool qrcodegen_encodeText(const char *text, uint8_t tempBuffer[], uint8_t qrcode[],
1885317bbafSopenharmony_ci	enum qrcodegen_Ecc ecl, int minVersion, int maxVersion, enum qrcodegen_Mask mask, bool boostEcl);
1895317bbafSopenharmony_ci
1905317bbafSopenharmony_ci
1915317bbafSopenharmony_ci/*
1925317bbafSopenharmony_ci * Encodes the given binary data to a QR Code, returning true if successful.
1935317bbafSopenharmony_ci * If the data is too long to fit in any version in the given range
1945317bbafSopenharmony_ci * at the given ECC level, then false is returned.
1955317bbafSopenharmony_ci *
1965317bbafSopenharmony_ci * Requires 1 <= minVersion <= maxVersion <= 40.
1975317bbafSopenharmony_ci *
1985317bbafSopenharmony_ci * The smallest possible QR Code version within the given range is automatically
1995317bbafSopenharmony_ci * chosen for the output. Iff boostEcl is true, then the ECC level of the result
2005317bbafSopenharmony_ci * may be higher than the ecl argument if it can be done without increasing the
2015317bbafSopenharmony_ci * version. The mask is either between qrcodegen_Mask_0 to 7 to force that mask, or
2025317bbafSopenharmony_ci * qrcodegen_Mask_AUTO to automatically choose an appropriate mask (which may be slow).
2035317bbafSopenharmony_ci *
2045317bbafSopenharmony_ci * About the arrays, letting len = qrcodegen_BUFFER_LEN_FOR_VERSION(maxVersion):
2055317bbafSopenharmony_ci * - Before calling the function:
2065317bbafSopenharmony_ci *   - The array ranges dataAndTemp[0 : len] and qrcode[0 : len] must allow
2075317bbafSopenharmony_ci *     reading and writing; hence each array must have a length of at least len.
2085317bbafSopenharmony_ci *   - The two ranges must not overlap (aliasing).
2095317bbafSopenharmony_ci *   - The input array range dataAndTemp[0 : dataLen] should normally be
2105317bbafSopenharmony_ci *     valid UTF-8 text, but is not required by the QR Code standard.
2115317bbafSopenharmony_ci *   - The initial state of dataAndTemp[dataLen : len] and qrcode[0 : len]
2125317bbafSopenharmony_ci *     can be uninitialized because the function always writes before reading.
2135317bbafSopenharmony_ci * - After the function returns:
2145317bbafSopenharmony_ci *   - Both ranges have no guarantee on which elements are initialized and what values are stored.
2155317bbafSopenharmony_ci *   - dataAndTemp contains no useful data and should be treated as entirely uninitialized.
2165317bbafSopenharmony_ci *   - If successful, qrcode can be passed into qrcodegen_getSize() and qrcodegen_getModule().
2175317bbafSopenharmony_ci *
2185317bbafSopenharmony_ci * If successful, the resulting QR Code will use byte mode to encode the data.
2195317bbafSopenharmony_ci *
2205317bbafSopenharmony_ci * In the most optimistic case, a QR Code at version 40 with low ECC can hold any byte
2215317bbafSopenharmony_ci * sequence up to length 2953. This is the hard upper limit of the QR Code standard.
2225317bbafSopenharmony_ci *
2235317bbafSopenharmony_ci * Please consult the QR Code specification for information on
2245317bbafSopenharmony_ci * data capacities per version, ECC level, and text encoding mode.
2255317bbafSopenharmony_ci */
2265317bbafSopenharmony_cibool qrcodegen_encodeBinary(uint8_t dataAndTemp[], size_t dataLen, uint8_t qrcode[],
2275317bbafSopenharmony_ci	enum qrcodegen_Ecc ecl, int minVersion, int maxVersion, enum qrcodegen_Mask mask, bool boostEcl);
2285317bbafSopenharmony_ci
2295317bbafSopenharmony_ci
2305317bbafSopenharmony_ci/*---- Functions (low level) to generate QR Codes ----*/
2315317bbafSopenharmony_ci
2325317bbafSopenharmony_ci/*
2335317bbafSopenharmony_ci * Encodes the given segments to a QR Code, returning true if successful.
2345317bbafSopenharmony_ci * If the data is too long to fit in any version at the given ECC level,
2355317bbafSopenharmony_ci * then false is returned.
2365317bbafSopenharmony_ci *
2375317bbafSopenharmony_ci * The smallest possible QR Code version is automatically chosen for
2385317bbafSopenharmony_ci * the output. The ECC level of the result may be higher than the
2395317bbafSopenharmony_ci * ecl argument if it can be done without increasing the version.
2405317bbafSopenharmony_ci *
2415317bbafSopenharmony_ci * About the byte arrays, letting len = qrcodegen_BUFFER_LEN_FOR_VERSION(qrcodegen_VERSION_MAX):
2425317bbafSopenharmony_ci * - Before calling the function:
2435317bbafSopenharmony_ci *   - The array ranges tempBuffer[0 : len] and qrcode[0 : len] must allow
2445317bbafSopenharmony_ci *     reading and writing; hence each array must have a length of at least len.
2455317bbafSopenharmony_ci *   - The two ranges must not overlap (aliasing).
2465317bbafSopenharmony_ci *   - The initial state of both ranges can be uninitialized
2475317bbafSopenharmony_ci *     because the function always writes before reading.
2485317bbafSopenharmony_ci *   - The input array segs can contain segments whose data buffers overlap with tempBuffer.
2495317bbafSopenharmony_ci * - After the function returns:
2505317bbafSopenharmony_ci *   - Both ranges have no guarantee on which elements are initialized and what values are stored.
2515317bbafSopenharmony_ci *   - tempBuffer contains no useful data and should be treated as entirely uninitialized.
2525317bbafSopenharmony_ci *   - Any segment whose data buffer overlaps with tempBuffer[0 : len]
2535317bbafSopenharmony_ci *     must be treated as having invalid values in that array.
2545317bbafSopenharmony_ci *   - If successful, qrcode can be passed into qrcodegen_getSize() and qrcodegen_getModule().
2555317bbafSopenharmony_ci *
2565317bbafSopenharmony_ci * Please consult the QR Code specification for information on
2575317bbafSopenharmony_ci * data capacities per version, ECC level, and text encoding mode.
2585317bbafSopenharmony_ci *
2595317bbafSopenharmony_ci * This function allows the user to create a custom sequence of segments that switches
2605317bbafSopenharmony_ci * between modes (such as alphanumeric and byte) to encode text in less space.
2615317bbafSopenharmony_ci * This is a low-level API; the high-level API is qrcodegen_encodeText() and qrcodegen_encodeBinary().
2625317bbafSopenharmony_ci */
2635317bbafSopenharmony_cibool qrcodegen_encodeSegments(const struct qrcodegen_Segment segs[], size_t len,
2645317bbafSopenharmony_ci	enum qrcodegen_Ecc ecl, uint8_t tempBuffer[], uint8_t qrcode[]);
2655317bbafSopenharmony_ci
2665317bbafSopenharmony_ci
2675317bbafSopenharmony_ci/*
2685317bbafSopenharmony_ci * Encodes the given segments to a QR Code, returning true if successful.
2695317bbafSopenharmony_ci * If the data is too long to fit in any version in the given range
2705317bbafSopenharmony_ci * at the given ECC level, then false is returned.
2715317bbafSopenharmony_ci *
2725317bbafSopenharmony_ci * Requires 1 <= minVersion <= maxVersion <= 40.
2735317bbafSopenharmony_ci *
2745317bbafSopenharmony_ci * The smallest possible QR Code version within the given range is automatically
2755317bbafSopenharmony_ci * chosen for the output. Iff boostEcl is true, then the ECC level of the result
2765317bbafSopenharmony_ci * may be higher than the ecl argument if it can be done without increasing the
2775317bbafSopenharmony_ci * version. The mask is either between qrcodegen_Mask_0 to 7 to force that mask, or
2785317bbafSopenharmony_ci * qrcodegen_Mask_AUTO to automatically choose an appropriate mask (which may be slow).
2795317bbafSopenharmony_ci *
2805317bbafSopenharmony_ci * About the byte arrays, letting len = qrcodegen_BUFFER_LEN_FOR_VERSION(qrcodegen_VERSION_MAX):
2815317bbafSopenharmony_ci * - Before calling the function:
2825317bbafSopenharmony_ci *   - The array ranges tempBuffer[0 : len] and qrcode[0 : len] must allow
2835317bbafSopenharmony_ci *     reading and writing; hence each array must have a length of at least len.
2845317bbafSopenharmony_ci *   - The two ranges must not overlap (aliasing).
2855317bbafSopenharmony_ci *   - The initial state of both ranges can be uninitialized
2865317bbafSopenharmony_ci *     because the function always writes before reading.
2875317bbafSopenharmony_ci *   - The input array segs can contain segments whose data buffers overlap with tempBuffer.
2885317bbafSopenharmony_ci * - After the function returns:
2895317bbafSopenharmony_ci *   - Both ranges have no guarantee on which elements are initialized and what values are stored.
2905317bbafSopenharmony_ci *   - tempBuffer contains no useful data and should be treated as entirely uninitialized.
2915317bbafSopenharmony_ci *   - Any segment whose data buffer overlaps with tempBuffer[0 : len]
2925317bbafSopenharmony_ci *     must be treated as having invalid values in that array.
2935317bbafSopenharmony_ci *   - If successful, qrcode can be passed into qrcodegen_getSize() and qrcodegen_getModule().
2945317bbafSopenharmony_ci *
2955317bbafSopenharmony_ci * Please consult the QR Code specification for information on
2965317bbafSopenharmony_ci * data capacities per version, ECC level, and text encoding mode.
2975317bbafSopenharmony_ci *
2985317bbafSopenharmony_ci * This function allows the user to create a custom sequence of segments that switches
2995317bbafSopenharmony_ci * between modes (such as alphanumeric and byte) to encode text in less space.
3005317bbafSopenharmony_ci * This is a low-level API; the high-level API is qrcodegen_encodeText() and qrcodegen_encodeBinary().
3015317bbafSopenharmony_ci */
3025317bbafSopenharmony_cibool qrcodegen_encodeSegmentsAdvanced(const struct qrcodegen_Segment segs[], size_t len, enum qrcodegen_Ecc ecl,
3035317bbafSopenharmony_ci	int minVersion, int maxVersion, enum qrcodegen_Mask mask, bool boostEcl, uint8_t tempBuffer[], uint8_t qrcode[]);
3045317bbafSopenharmony_ci
3055317bbafSopenharmony_ci
3065317bbafSopenharmony_ci/*
3075317bbafSopenharmony_ci * Tests whether the given string can be encoded as a segment in numeric mode.
3085317bbafSopenharmony_ci * A string is encodable iff each character is in the range 0 to 9.
3095317bbafSopenharmony_ci */
3105317bbafSopenharmony_cibool qrcodegen_isNumeric(const char *text);
3115317bbafSopenharmony_ci
3125317bbafSopenharmony_ci
3135317bbafSopenharmony_ci/*
3145317bbafSopenharmony_ci * Tests whether the given string can be encoded as a segment in alphanumeric mode.
3155317bbafSopenharmony_ci * A string is encodable iff each character is in the following set: 0 to 9, A to Z
3165317bbafSopenharmony_ci * (uppercase only), space, dollar, percent, asterisk, plus, hyphen, period, slash, colon.
3175317bbafSopenharmony_ci */
3185317bbafSopenharmony_cibool qrcodegen_isAlphanumeric(const char *text);
3195317bbafSopenharmony_ci
3205317bbafSopenharmony_ci
3215317bbafSopenharmony_ci/*
3225317bbafSopenharmony_ci * Returns the number of bytes (uint8_t) needed for the data buffer of a segment
3235317bbafSopenharmony_ci * containing the given number of characters using the given mode. Notes:
3245317bbafSopenharmony_ci * - Returns SIZE_MAX on failure, i.e. numChars > INT16_MAX or the internal
3255317bbafSopenharmony_ci *   calculation of the number of needed bits exceeds INT16_MAX (i.e. 32767).
3265317bbafSopenharmony_ci * - Otherwise, all valid results are in the range [0, ceil(INT16_MAX / 8)], i.e. at most 4096.
3275317bbafSopenharmony_ci * - It is okay for the user to allocate more bytes for the buffer than needed.
3285317bbafSopenharmony_ci * - For byte mode, numChars measures the number of bytes, not Unicode code points.
3295317bbafSopenharmony_ci * - For ECI mode, numChars must be 0, and the worst-case number of bytes is returned.
3305317bbafSopenharmony_ci *   An actual ECI segment can have shorter data. For non-ECI modes, the result is exact.
3315317bbafSopenharmony_ci */
3325317bbafSopenharmony_cisize_t qrcodegen_calcSegmentBufferSize(enum qrcodegen_Mode mode, size_t numChars);
3335317bbafSopenharmony_ci
3345317bbafSopenharmony_ci
3355317bbafSopenharmony_ci/*
3365317bbafSopenharmony_ci * Returns a segment representing the given binary data encoded in
3375317bbafSopenharmony_ci * byte mode. All input byte arrays are acceptable. Any text string
3385317bbafSopenharmony_ci * can be converted to UTF-8 bytes and encoded as a byte mode segment.
3395317bbafSopenharmony_ci */
3405317bbafSopenharmony_cistruct qrcodegen_Segment qrcodegen_makeBytes(const uint8_t data[], size_t len, uint8_t buf[]);
3415317bbafSopenharmony_ci
3425317bbafSopenharmony_ci
3435317bbafSopenharmony_ci/*
3445317bbafSopenharmony_ci * Returns a segment representing the given string of decimal digits encoded in numeric mode.
3455317bbafSopenharmony_ci */
3465317bbafSopenharmony_cistruct qrcodegen_Segment qrcodegen_makeNumeric(const char *digits, uint8_t buf[]);
3475317bbafSopenharmony_ci
3485317bbafSopenharmony_ci
3495317bbafSopenharmony_ci/*
3505317bbafSopenharmony_ci * Returns a segment representing the given text string encoded in alphanumeric mode.
3515317bbafSopenharmony_ci * The characters allowed are: 0 to 9, A to Z (uppercase only), space,
3525317bbafSopenharmony_ci * dollar, percent, asterisk, plus, hyphen, period, slash, colon.
3535317bbafSopenharmony_ci */
3545317bbafSopenharmony_cistruct qrcodegen_Segment qrcodegen_makeAlphanumeric(const char *text, uint8_t buf[]);
3555317bbafSopenharmony_ci
3565317bbafSopenharmony_ci
3575317bbafSopenharmony_ci/*
3585317bbafSopenharmony_ci * Returns a segment representing an Extended Channel Interpretation
3595317bbafSopenharmony_ci * (ECI) designator with the given assignment value.
3605317bbafSopenharmony_ci */
3615317bbafSopenharmony_cistruct qrcodegen_Segment qrcodegen_makeEci(long assignVal, uint8_t buf[]);
3625317bbafSopenharmony_ci
3635317bbafSopenharmony_ci
3645317bbafSopenharmony_ci/*---- Functions to extract raw data from QR Codes ----*/
3655317bbafSopenharmony_ci
3665317bbafSopenharmony_ci/*
3675317bbafSopenharmony_ci * Returns the side length of the given QR Code, assuming that encoding succeeded.
3685317bbafSopenharmony_ci * The result is in the range [21, 177]. Note that the length of the array buffer
3695317bbafSopenharmony_ci * is related to the side length - every 'uint8_t qrcode[]' must have length at least
3705317bbafSopenharmony_ci * qrcodegen_BUFFER_LEN_FOR_VERSION(version), which equals ceil(size^2 / 8 + 1).
3715317bbafSopenharmony_ci */
3725317bbafSopenharmony_ciint qrcodegen_getSize(const uint8_t qrcode[]);
3735317bbafSopenharmony_ci
3745317bbafSopenharmony_ci
3755317bbafSopenharmony_ci/*
3765317bbafSopenharmony_ci * Returns the color of the module (pixel) at the given coordinates, which is false
3775317bbafSopenharmony_ci * for light or true for dark. The top left corner has the coordinates (x=0, y=0).
3785317bbafSopenharmony_ci * If the given coordinates are out of bounds, then false (light) is returned.
3795317bbafSopenharmony_ci */
3805317bbafSopenharmony_cibool qrcodegen_getModule(const uint8_t qrcode[], int x, int y);
3815317bbafSopenharmony_ci
3825317bbafSopenharmony_ci
3835317bbafSopenharmony_ci#ifdef __cplusplus
3845317bbafSopenharmony_ci}
3855317bbafSopenharmony_ci#endif
386