-
Notifications
You must be signed in to change notification settings - Fork 8
/
libqrencode.vapi
309 lines (291 loc) · 8.05 KB
/
libqrencode.vapi
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
/**
* A library for encoding data in a QR Code symbol, a kind of 2D symbology.
*/
[CCode (cheader_filename = "qrencode.h")]
namespace QR {
/**
* The state of each module (dot).
*
* Only {@link Dot.BLACK} is useful for usual applications.
*/
[CCode (cname = "unsigned char", has_type_id = false)]
[Flags]
public enum Dot {
[CCode (cname = "1")]
BLACK,
[CCode (cname = "2")]
DATA_AND_ECC,
[CCode (cname = "4")]
FORMAT,
[CCode (cname = "8")]
VERSION,
[CCode (cname = "16")]
TIMING,
[CCode (cname = "32")]
ALIGNMENT,
[CCode (cname = "64")]
FINDER,
[CCode (cname = "128")]
NON_DATA
}
/**
* Level of error correction.
*/
[CCode (cname = "QRecLevel", cprefix = "QR_ECLEVEL_")]
public enum ECLevel {
/**
* Lowest
*/
L,
M,
Q,
/**
* Highest
*/
H
}
/**
* Encoding mode.
*/
[CCode (cname = "QRencodeMode", cprefix = "QR_MODE_")]
public enum Mode {
/**
* Numeric mode
*/
NUM,
/**
* Alphabet-numeric mode
*/
AN,
/**
* 8-bit data mode
*/
[CCode (cname = "QR_MODE_8")]
EIGHT_BIT,
/**
* Kanji (shift-jis) mode
*/
KANJI,
/**
* Internal use only
*/
STRUCTURE
}
/**
* Symbol data is represented as an array contains width*width {@link uint8}.
*
* Each point represents a module (dot).
* described.
*/
[CCode (cname = "QRcode", free_function = "QRcode_free", has_type_id = false)]
[Compact]
public class Code {
public int version;
public int width;
[CCode (array_length = false)]
public Dot[] data;
/**
* Create a symbol from the string.
*
* The library automatically parses the input string and encodes in a QR Code
* symbol.
* This function is THREAD UNSAFE.
* @param str input string.
* @param version version of the symbol. If 0, the library chooses the
* minimum version for the given input data.
* @param level error correction level.
* @param hint tell the library how non-alphanumerical characters should be
* encoded. If {@link Mode.KANJI} is given, kanji characters will be encoded
* as Shif-JIS characters. If {@link Mode.EIGHT_BIT} is given, all of
* non-alphanumerical characters will be encoded as is. If you want to embed
* UTF-8 string, choose this.
* @param casesensitive case-sensitive or not.
* @return The version of the result QRcode may be larger than the designated
* version. On error, null is returned, and errno is set to indicate the
* error.
*/
[CCode (cname = "QRcode_encodeString")]
public static Code? encode_string (string str, int version, ECLevel level, Mode hint, bool casesensitive);
/**
* Create a symbol from the string encoding the whole data in 8-bit mode.
* @see encode_string
*/
[CCode (cname = "QRcode_encodeString8bit")]
public static Code? encode_string_8bit (string str, int version, ECLevel level);
public bool get (int x, int y) {
if (x < width && y < width) {
return Dot.BLACK in data[x * width + y];
} else {
return false;
}
}
}
/**
* The input strings and version and error correction level.
*/
[CCode (cname = "QRinput", free_function = "QRinput_free", has_type_id = false)]
[Compact]
public class Input {
/**
* Instantiate an input data object.
* @param version version number.
* @param level Error correction level.
* @return On error, null is returned and errno is set to indicate the
* error.
*/
[CCode (cname = "QRinput_new2")]
public Input? create (int version, ECLevel level);
/**
* The current error correction level.
*/
public ECLevel correction {
[CCode (cname = "QRinput_getErrorCorrectionLevel")]
get;
[CCode (cname = "QRinput_setErrorCorrectionLevel")]
set;
}
/**
* The current version. (Zero for automatic)
*/
public int version {
[CCode (cname = "QRinput_getVersion")]
get;
[CCode (cname = "QRinput_setVersion")]
set;
}
/**
* Instantiate an input data object.
*
* The version is set to 0 (auto-select) and the error correction level is
* set to {@link ECLevel.L}.
*/
[CCode (cname = "QRinput_new")]
public Input ();
/**
* Append data to an input object.
* The data is copied and appended to the input object.
* @param mode encoding mode.
* @param data the input data.
* @return false on success
*/
[CCode (cname = "QRinput_append")]
public bool append (Mode mode, [CCode (array_length_pos = 1.1)] uint8[] data);
/**
* Validate the input data.
* @param mode encoding mode.
* @param data the input data.
* @return false on success
*/
[CCode (cname = "QRinput_check")]
public bool check (Mode mode, [CCode (array_length_pos = 1.1)] uint8[] data);
/**
* Create a symbol from the input data.
*
* This function is THREAD UNSAFE.
* @return The version of the result QRcode may be larger than the
* designated version. On error, NULL is returned, and errno is set to
* indicate the error.
*/
[CCode (cname = "QRcode_encodeInput")]
public Code? encode ();
/**
* Split an input.
*
* It calculates a parity, set it, then insert structured-append headers.
*
* Version number and error correction level must be set.
* @return a set of input data. On error, null is returned, and errno is
* set to indicate the error.
*/
[CCode (cname = "QRinput_splitQRinputToStruct")]
public extern StructSym? split ();
}
/**
* Singly-linked list of {@link Code}s.
*
* Used to represent a structured symbols.
*/
[CCode (cname = "QRcode_List", free_function = "QRcode_List_free", has_type_id = false)]
[Compact]
public class List {
public Code code;
public List? next;
/**
* The number of symbols included.
*/
public int size {
[CCode (cname = "QRcode_List_size")]
get;
}
/**
* Create structured symbols from the string.
*
* The library automatically parses the input string and encodes in a QR Code
* symbol.
*
* This function is THREAD UNSAFE.
* @param str input string.
* @param version version of the symbol.
* @param level error correction level.
* @param hint tell the library how non-alphanumerical characters should be
* encoded. If {@link Mode.KANJI} is given, kanji characters will be
* encoded as Shif-JIS characters. If {@link Mode.EIGHT_BIT} is given, all
* of non-alphanumerical characters will be encoded as is. If you want to
* embed UTF-8 string, choose this.
* @param casesensitive case-sensitive or not.
* @return On error, null is returned, and errno is set to indicate the
* error.
*/
[CCode (cname = "QRcode_encodeStringStructured")]
public static List? encode_string (string str, int version, ECLevel level, Mode hint, bool casesensitive);
/**
* Create structured symbols from the string encoding whole data in 8-bit mode.
* @see encode_string
*/
[CCode (cname = "QRcode_encodeString8bitStructured")]
public static List? encode_string_8bit (string str, int version, ECLevel level);
}
/**
* Set of {@link Input} for structured symbols.
*/
[CCode (cname = "QRinput_Struct", free_function = "QRinput_Struct_free", has_type_id = false)]
[Compact]
public class StructSym {
/**
* Instantiate a set of input data object.
*/
[CCode (cname = "QRinput_Struct_new")]
public StructSym ();
/**
* The parity of structured symbols.
*/
public uint8 parity {
[CCode (cname = "QRinput_Struct_setParity")]
set;
}
/**
* Append a QRinput object to the set.
*
* Never append the same QRinput object twice or more.
* @param input an input object.
* @return number of input objects in the structure or -1 if an error occurred.
*/
[CCode (cname = "QRinput_Struct_appendInput")]
public int append (Input input);
/**
* Create structured symbols from the input data.
*
* This function is THREAD UNSAFE.
*/
[CCode (cname = "QRcode_encodeInputStructured")]
public List? encode ();
/**
* Insert structured-append headers to the input structure.
*
* It calculates a parity and set it if the parity is not set yet.
* @return false on success
*/
[CCode (cname = "QRinput_Struct_insertStructuredAppendHeaders")]
public bool insert_headers ();
}
}