Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Tetragramm
GitHub Repository: Tetragramm/opencv
Path: blob/master/3rdparty/quirc/include/quirc.h
16337 views
1
/* quirc -- QR-code recognition library
2
* Copyright (C) 2010-2012 Daniel Beer <[email protected]>
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 <stdint.h>
21
22
#ifdef __cplusplus
23
extern "C" {
24
#endif
25
26
struct quirc;
27
28
/* Obtain the library version string. */
29
const char *quirc_version(void);
30
31
/* Construct a new QR-code recognizer. This function will return NULL
32
* if sufficient memory could not be allocated.
33
*/
34
struct quirc *quirc_new(void);
35
36
/* Destroy a QR-code recognizer. */
37
void quirc_destroy(struct quirc *q);
38
39
/* Resize the QR-code recognizer. The size of an image must be
40
* specified before codes can be analyzed.
41
*
42
* This function returns 0 on success, or -1 if sufficient memory could
43
* not be allocated.
44
*/
45
int quirc_resize(struct quirc *q, int w, int h);
46
47
/* These functions are used to process images for QR-code recognition.
48
* quirc_begin() must first be called to obtain access to a buffer into
49
* which the input image should be placed. Optionally, the current
50
* width and height may be returned.
51
*
52
* After filling the buffer, quirc_end() should be called to process
53
* the image for QR-code recognition. The locations and content of each
54
* code may be obtained using accessor functions described below.
55
*/
56
uint8_t *quirc_begin(struct quirc *q, int *w, int *h);
57
void quirc_end(struct quirc *q);
58
59
/* This structure describes a location in the input image buffer. */
60
struct quirc_point {
61
int x;
62
int y;
63
};
64
65
/* This enum describes the various decoder errors which may occur. */
66
typedef enum {
67
QUIRC_SUCCESS = 0,
68
QUIRC_ERROR_INVALID_GRID_SIZE,
69
QUIRC_ERROR_INVALID_VERSION,
70
QUIRC_ERROR_FORMAT_ECC,
71
QUIRC_ERROR_DATA_ECC,
72
QUIRC_ERROR_UNKNOWN_DATA_TYPE,
73
QUIRC_ERROR_DATA_OVERFLOW,
74
QUIRC_ERROR_DATA_UNDERFLOW
75
} quirc_decode_error_t;
76
77
/* Return a string error message for an error code. */
78
const char *quirc_strerror(quirc_decode_error_t err);
79
80
/* Limits on the maximum size of QR-codes and their content. */
81
#define QUIRC_MAX_BITMAP 3917
82
#define QUIRC_MAX_PAYLOAD 8896
83
84
/* QR-code ECC types. */
85
#define QUIRC_ECC_LEVEL_M 0
86
#define QUIRC_ECC_LEVEL_L 1
87
#define QUIRC_ECC_LEVEL_H 2
88
#define QUIRC_ECC_LEVEL_Q 3
89
90
/* QR-code data types. */
91
#define QUIRC_DATA_TYPE_NUMERIC 1
92
#define QUIRC_DATA_TYPE_ALPHA 2
93
#define QUIRC_DATA_TYPE_BYTE 4
94
#define QUIRC_DATA_TYPE_KANJI 8
95
96
/* Common character encodings */
97
#define QUIRC_ECI_ISO_8859_1 1
98
#define QUIRC_ECI_IBM437 2
99
#define QUIRC_ECI_ISO_8859_2 4
100
#define QUIRC_ECI_ISO_8859_3 5
101
#define QUIRC_ECI_ISO_8859_4 6
102
#define QUIRC_ECI_ISO_8859_5 7
103
#define QUIRC_ECI_ISO_8859_6 8
104
#define QUIRC_ECI_ISO_8859_7 9
105
#define QUIRC_ECI_ISO_8859_8 10
106
#define QUIRC_ECI_ISO_8859_9 11
107
#define QUIRC_ECI_WINDOWS_874 13
108
#define QUIRC_ECI_ISO_8859_13 15
109
#define QUIRC_ECI_ISO_8859_15 17
110
#define QUIRC_ECI_SHIFT_JIS 20
111
#define QUIRC_ECI_UTF_8 26
112
113
/* This structure is used to return information about detected QR codes
114
* in the input image.
115
*/
116
struct quirc_code {
117
/* The four corners of the QR-code, from top left, clockwise */
118
struct quirc_point corners[4];
119
120
/* The number of cells across in the QR-code. The cell bitmap
121
* is a bitmask giving the actual values of cells. If the cell
122
* at (x, y) is black, then the following bit is set:
123
*
124
* cell_bitmap[i >> 3] & (1 << (i & 7))
125
*
126
* where i = (y * size) + x.
127
*/
128
int size;
129
uint8_t cell_bitmap[QUIRC_MAX_BITMAP];
130
};
131
132
/* This structure holds the decoded QR-code data */
133
struct quirc_data {
134
/* Various parameters of the QR-code. These can mostly be
135
* ignored if you only care about the data.
136
*/
137
int version;
138
int ecc_level;
139
int mask;
140
141
/* This field is the highest-valued data type found in the QR
142
* code.
143
*/
144
int data_type;
145
146
/* Data payload. For the Kanji datatype, payload is encoded as
147
* Shift-JIS. For all other datatypes, payload is ASCII text.
148
*/
149
uint8_t payload[QUIRC_MAX_PAYLOAD];
150
int payload_len;
151
152
/* ECI assignment number */
153
uint32_t eci;
154
};
155
156
/* Return the number of QR-codes identified in the last processed
157
* image.
158
*/
159
int quirc_count(const struct quirc *q);
160
161
/* Extract the QR-code specified by the given index. */
162
void quirc_extract(const struct quirc *q, int index,
163
struct quirc_code *code);
164
165
/* Decode a QR-code, returning the payload data. */
166
quirc_decode_error_t quirc_decode(const struct quirc_code *code,
167
struct quirc_data *data);
168
169
#ifdef __cplusplus
170
}
171
#endif
172
173
#endif
174
175