Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
8585 | rgimad | 1 | /* quirc -- QR-code recognition library |
2 | * Copyright (C) 2010-2012 Daniel Beer |
||
3 | * |
||
4 | * Permission to use, copy, modify, and/or distribute this software for any |
||
5 | * purpose with or without fee is hereby granted, provided that the above |
||
6 | * copyright notice and this permission notice appear in all copies. |
||
7 | * |
||
8 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES |
||
9 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF |
||
10 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR |
||
11 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES |
||
12 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN |
||
13 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF |
||
14 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
||
15 | */ |
||
16 | |||
17 | #ifndef QUIRC_H_ |
||
18 | #define QUIRC_H_ |
||
19 | |||
20 | #include |
||
21 | |||
22 | /*#ifndef UINT8_MAX |
||
23 | #define UINT8_MAX (255) |
||
24 | #endif |
||
25 | #ifndef UINT16_MAX |
||
26 | #define UINT16_MAX (65535) |
||
27 | #endif*/ |
||
28 | |||
29 | #ifdef __cplusplus |
||
30 | extern "C" { |
||
31 | #endif |
||
32 | |||
33 | struct quirc; |
||
34 | |||
35 | /* Obtain the library version string. */ |
||
36 | const char *quirc_version(void); |
||
37 | |||
38 | /* Construct a new QR-code recognizer. This function will return NULL |
||
39 | * if sufficient memory could not be allocated. |
||
40 | */ |
||
41 | struct quirc *quirc_new(void); |
||
42 | |||
43 | /* Destroy a QR-code recognizer. */ |
||
44 | void quirc_destroy(struct quirc *q); |
||
45 | |||
46 | /* Resize the QR-code recognizer. The size of an image must be |
||
47 | * specified before codes can be analyzed. |
||
48 | * |
||
49 | * This function returns 0 on success, or -1 if sufficient memory could |
||
50 | * not be allocated. |
||
51 | */ |
||
52 | int quirc_resize(struct quirc *q, int w, int h); |
||
53 | |||
54 | /* These functions are used to process images for QR-code recognition. |
||
55 | * quirc_begin() must first be called to obtain access to a buffer into |
||
56 | * which the input image should be placed. Optionally, the current |
||
57 | * width and height may be returned. |
||
58 | * |
||
59 | * After filling the buffer, quirc_end() should be called to process |
||
60 | * the image for QR-code recognition. The locations and content of each |
||
61 | * code may be obtained using accessor functions described below. |
||
62 | */ |
||
63 | uint8_t *quirc_begin(struct quirc *q, int *w, int *h); |
||
64 | void quirc_end(struct quirc *q); |
||
65 | |||
66 | /* This structure describes a location in the input image buffer. */ |
||
67 | struct quirc_point { |
||
68 | int x; |
||
69 | int y; |
||
70 | }; |
||
71 | |||
72 | /* This enum describes the various decoder errors which may occur. */ |
||
73 | typedef enum { |
||
74 | QUIRC_SUCCESS = 0, |
||
75 | QUIRC_ERROR_INVALID_GRID_SIZE, |
||
76 | QUIRC_ERROR_INVALID_VERSION, |
||
77 | QUIRC_ERROR_FORMAT_ECC, |
||
78 | QUIRC_ERROR_DATA_ECC, |
||
79 | QUIRC_ERROR_UNKNOWN_DATA_TYPE, |
||
80 | QUIRC_ERROR_DATA_OVERFLOW, |
||
81 | QUIRC_ERROR_DATA_UNDERFLOW |
||
82 | } quirc_decode_error_t; |
||
83 | |||
84 | /* Return a string error message for an error code. */ |
||
85 | const char *quirc_strerror(quirc_decode_error_t err); |
||
86 | |||
87 | /* Limits on the maximum size of QR-codes and their content. */ |
||
88 | #define QUIRC_MAX_VERSION 40 |
||
89 | #define QUIRC_MAX_GRID_SIZE (QUIRC_MAX_VERSION * 4 + 17) |
||
90 | #define QUIRC_MAX_BITMAP (((QUIRC_MAX_GRID_SIZE * QUIRC_MAX_GRID_SIZE) + 7) / 8) |
||
91 | #define QUIRC_MAX_PAYLOAD 8896 |
||
92 | |||
93 | /* QR-code ECC types. */ |
||
94 | #define QUIRC_ECC_LEVEL_M 0 |
||
95 | #define QUIRC_ECC_LEVEL_L 1 |
||
96 | #define QUIRC_ECC_LEVEL_H 2 |
||
97 | #define QUIRC_ECC_LEVEL_Q 3 |
||
98 | |||
99 | /* QR-code data types. */ |
||
100 | #define QUIRC_DATA_TYPE_NUMERIC 1 |
||
101 | #define QUIRC_DATA_TYPE_ALPHA 2 |
||
102 | #define QUIRC_DATA_TYPE_BYTE 4 |
||
103 | #define QUIRC_DATA_TYPE_KANJI 8 |
||
104 | |||
105 | /* Common character encodings */ |
||
106 | #define QUIRC_ECI_ISO_8859_1 1 |
||
107 | #define QUIRC_ECI_IBM437 2 |
||
108 | #define QUIRC_ECI_ISO_8859_2 4 |
||
109 | #define QUIRC_ECI_ISO_8859_3 5 |
||
110 | #define QUIRC_ECI_ISO_8859_4 6 |
||
111 | #define QUIRC_ECI_ISO_8859_5 7 |
||
112 | #define QUIRC_ECI_ISO_8859_6 8 |
||
113 | #define QUIRC_ECI_ISO_8859_7 9 |
||
114 | #define QUIRC_ECI_ISO_8859_8 10 |
||
115 | #define QUIRC_ECI_ISO_8859_9 11 |
||
116 | #define QUIRC_ECI_WINDOWS_874 13 |
||
117 | #define QUIRC_ECI_ISO_8859_13 15 |
||
118 | #define QUIRC_ECI_ISO_8859_15 17 |
||
119 | #define QUIRC_ECI_SHIFT_JIS 20 |
||
120 | #define QUIRC_ECI_UTF_8 26 |
||
121 | |||
122 | /* This structure is used to return information about detected QR codes |
||
123 | * in the input image. |
||
124 | */ |
||
125 | struct quirc_code { |
||
126 | /* The four corners of the QR-code, from top left, clockwise */ |
||
127 | struct quirc_point corners[4]; |
||
128 | |||
129 | /* The number of cells across in the QR-code. The cell bitmap |
||
130 | * is a bitmask giving the actual values of cells. If the cell |
||
131 | * at (x, y) is black, then the following bit is set: |
||
132 | * |
||
133 | * cell_bitmap[i >> 3] & (1 << (i & 7)) |
||
134 | * |
||
135 | * where i = (y * size) + x. |
||
136 | */ |
||
137 | int size; |
||
138 | uint8_t cell_bitmap[QUIRC_MAX_BITMAP]; |
||
139 | }; |
||
140 | |||
141 | /* This structure holds the decoded QR-code data */ |
||
142 | struct quirc_data { |
||
143 | /* Various parameters of the QR-code. These can mostly be |
||
144 | * ignored if you only care about the data. |
||
145 | */ |
||
146 | int version; |
||
147 | int ecc_level; |
||
148 | int mask; |
||
149 | |||
150 | /* This field is the highest-valued data type found in the QR |
||
151 | * code. |
||
152 | */ |
||
153 | int data_type; |
||
154 | |||
155 | /* Data payload. For the Kanji datatype, payload is encoded as |
||
156 | * Shift-JIS. For all other datatypes, payload is ASCII text. |
||
157 | */ |
||
158 | uint8_t payload[QUIRC_MAX_PAYLOAD]; |
||
159 | int payload_len; |
||
160 | |||
161 | /* ECI assignment number */ |
||
162 | uint32_t eci; |
||
163 | }; |
||
164 | |||
165 | /* Return the number of QR-codes identified in the last processed |
||
166 | * image. |
||
167 | */ |
||
168 | int quirc_count(const struct quirc *q); |
||
169 | |||
170 | /* Extract the QR-code specified by the given index. */ |
||
171 | void quirc_extract(const struct quirc *q, int index, |
||
172 | struct quirc_code *code); |
||
173 | |||
174 | /* Decode a QR-code, returning the payload data. */ |
||
175 | quirc_decode_error_t quirc_decode(const struct quirc_code *code, |
||
176 | struct quirc_data *data); |
||
177 | |||
178 | /* Flip a QR-code according to optional mirror feature of ISO 18004:2015 */ |
||
179 | void quirc_flip(struct quirc_code *code); |
||
180 | |||
181 | #ifdef __cplusplus |
||
182 | } |
||
183 | #endif |
||
184 | |||
185 | #endif><> |