-
Notifications
You must be signed in to change notification settings - Fork 5
/
qr.h
200 lines (190 loc) · 9.6 KB
/
qr.h
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
/* Simple QR Code Generator - Support Tables
* Most of these routines are copied or heavily derived from
* the thonky.com website, where they were derived from
* Galios field math tables and the QR Code standard.
* No copyright is asserted for anything in this qr.h file.
* B.J. Guillot ([email protected])
* Version 1.0
* 2016-07-01
*/
// See http://www.thonky.com/qr-code-tutorial/log-antilog-table
unsigned char a[] = { // 256 bytes
1, 2, 4, 8, 16, 32, 64, 128,
29, 58, 116, 232, 205, 135, 19, 38,
76, 152, 45, 90, 180, 117, 234, 201,
143, 3, 6, 12, 24, 48, 96, 192,
157, 39, 78, 156, 37, 74, 148, 53,
106, 212, 181, 119, 238, 193, 159, 35,
70, 140, 5, 10, 20, 40, 80, 160,
93, 186, 105, 210, 185, 111, 222, 161,
95, 190, 97, 194, 153, 47, 94, 188,
101, 202, 137, 15, 30, 60, 120, 240,
253, 231, 211, 187, 107, 214, 177, 127,
254, 225, 223, 163, 91, 182, 113, 226,
217, 175, 67, 134, 17, 34, 68, 136,
13, 26, 52, 104, 208, 189, 103, 206,
129, 31, 62, 124, 248, 237, 199, 147,
59, 118, 236, 197, 151, 51, 102, 204,
133, 23, 46, 92, 184, 109, 218, 169,
79, 158, 33, 66, 132, 21, 42, 84,
168, 77, 154, 41, 82, 164, 85, 170,
73, 146, 57, 114, 228, 213, 183, 115,
230, 209, 191, 99, 198, 145, 63, 126,
252, 229, 215, 179, 123, 246, 241, 255,
227, 219, 171, 75, 150, 49, 98, 196,
149, 55, 110, 220, 165, 87, 174, 65,
130, 25, 50, 100, 200, 141, 7, 14,
28, 56, 112, 224, 221, 167, 83, 166,
81, 162, 89, 178, 121, 242, 249, 239,
195, 155, 43, 86, 172, 69, 138, 9,
18, 36, 72, 144, 61, 122, 244, 245,
247, 243, 251, 235, 203, 139, 11, 22,
44, 88, 176, 125, 250, 233, 207, 131,
27, 54, 108, 216, 173, 71, 142, 1
};
unsigned char a_inv[] = { // 256 bytes
0, 0, 1, 25, 2, 50, 26, 198,
3, 223, 51, 238, 27, 104, 199, 75,
4, 100, 224, 14, 52, 141, 239, 129,
28, 193, 105, 248, 200, 8, 76, 113,
5, 138, 101, 47, 225, 36, 15, 33,
53, 147, 142, 218, 240, 18, 130, 69,
29, 181, 194, 125, 106, 39, 249, 185,
201, 154, 9, 120, 77, 228, 114, 166,
6, 191, 139, 98, 102, 221, 48, 253,
226, 152, 37, 179, 16, 145, 34, 136,
54, 208, 148, 206, 143, 150, 219, 189,
241, 210, 19, 92, 131, 56, 70, 64,
30, 66, 182, 163, 195, 72, 126, 110,
107, 58, 40, 84, 250, 133, 186, 61,
202, 94, 155, 159, 10, 21, 121, 43,
78, 212, 229, 172, 115, 243, 167, 87,
7, 112, 192, 247, 140, 128, 99, 13,
103, 74, 222, 237, 49, 197, 254, 24,
227, 165, 153, 119, 38, 184, 180, 124,
17, 68, 146, 217, 35, 32, 137, 46,
55, 63, 209, 91, 149, 188, 207, 205,
144, 135, 151, 178, 220, 252, 190, 97,
242, 86, 211, 171, 20, 42, 93, 158,
132, 60, 57, 83, 71, 109, 65, 162,
31, 45, 67, 216, 183, 123, 164, 118,
196, 23, 73, 236, 127, 12, 111, 246,
108, 161, 59, 82, 41, 157, 85, 170,
251, 96, 134, 177, 187, 204, 62, 90,
203, 89, 95, 176, 156, 169, 160, 81,
11, 245, 22, 235, 122, 117, 44, 215,
79, 174, 213, 233, 230, 231, 173, 232,
116, 214, 244, 234, 168, 80, 88, 175
};
unsigned char gen_poly[] = { // 181 bytes
74,152,176,100,86,100,106,104,130,218,206,140,78, // 13th Polynomial (offset=0)
215,234,158,94,184,97,118,170,79,187,152,148,252,179,5,98,96,153, // 18th Polynomial (offset=13)
17,60,79,50,61,163,26,187,202,180,221,225,83,239,156,164,212,212,188,190, // 20th Poly (offset=31)
210,171,247,242,93,230,14,109,221,53,200,74,8,172,98,80,219,134,160,105,165,231, // 22nd Poly (offset=51)
229,121,135,48,211,117,251,126,159,180,169,152,192,226,228,218,111,0,117,232,87,96,227,21, // 24th Poly (offset=73)
173,125,158,2,103,182,118,17,145,201,111,28,165,53,161,21,245,142,13,102,48,227,153,145,218,70, // 26th Poly (offset=97)
168,223,200,104,224,234,108,180,110,190,195,147,205,27,232,201,21,43,245,87,42,195,212,119,242,37,9,123, // 28th Poly (offset=123)
41,173,145,152,216,31,179,182,50,48,110,86,239,96,222,125,42,173,226,193,224,130,156,37,251,216,238,40,192,180}; //30th Poly (offset=151)
unsigned char gen_offset[] = {0, 0, 0, 0, 0, 13, 0, 31, 0, 51, 0, 73, 0, 97, 0, 123, 0, 151}; //index 0 is for the 13th polynominal (18 bytes)
int16_t mask_info[] = { // 14 bytes
13663, // Mask Q-0 (011010101011111)
12392, // Mask Q-1 (011000001101000)
16177, // Mask Q-2 (011111100110001)
14854, // Mask Q-3 (011101000000110)
9396, // Mask Q-4 (010010010110100)
8579, // Mask Q-5 (010000110000011)
11994, // Mask Q-6 (010111011011010)
11245 // Mask Q-7 (010101111101101)
};
unsigned char version_info[] = { // 34 * 3 = 102 bytes; for simplicity, storing as three 6-bit numbers
// TODO: CAN GET RID OF BYTE #3 -- IT'S PREDICTABLE!!!! REDUCES STORAGE TO 68 BYTES
20, 50, 7, // Version 7 (000111110010010100)
60, 22, 8, // Version 8 (001000010110111100)
25, 42, 9, // Version 9 (001001101010011001)
19, 19, 10, // Version 10 (001010010011010011)
54, 47, 11, // Version 11 (001011101111110110)
34, 29, 12, // Version 12 (001100011101100010)
7, 33, 13, // Version 13 (001101100001000111)
13, 24, 14, // Version 14 (001110011000001101)
40, 36, 15, // Version 15 (001111100100101000)
56, 45, 16, // Version 16 (010000101101111000)
29, 17, 17, // Version 17 (010001010001011101)
23, 40, 18, // Version 18 (010010101000010111)
50, 20, 19, // Version 19 (010011010100110010)
38, 38, 20, // Version 20 (010100100110100110)
3, 26, 21, // Version 21 (010101011010000011)
9, 35, 22, // Version 22 (010110100011001001)
44, 31, 23, // Version 23 (010111011111101100)
4, 59, 24, // Version 24 (011000111011000100)
33, 7, 25, // Version 25 (011001000111100001)
43, 62, 26, // Version 26 (011010111110101011)
14, 2, 27, // Version 27 (011011000010001110)
26, 48, 28, // Version 28 (011100110000011010)
63, 12, 29, // Version 29 (011101001100111111)
53, 53, 30, // Version 30 (011110110101110101)
16, 9, 31, // Version 31 (011111001001010000)
21, 39, 32, // Version 32 (100000100111010101)
48, 27, 33, // Version 33 (100001011011110000)
58, 34, 34, // Version 34 (100010100010111010)
31, 30, 35, // Version 35 (100011011110011111)
11, 44, 36, // Version 36 (100100101100001011)
46, 16, 37, // Version 37 (100101010000101110)
36, 41, 38, // Version 38 (100110101001100100)
1, 21, 39, // Version 39 (100111010101000001)
41, 49, 40 // Version 40 (101000110001101001)
};
// Maximum unencoded original message length (character capacity) for Byte encoding, quality Q:
// V1=11, V2=20, V3=32, V4=46, V5=60, V6=74, V7=86, V8=108, V9=130, V10=151, V11=177, V12=203, V13=241, V14=258, V15=292,
// V16=322, V17=364, V18=394, V19=442, V20=482, V21=509
// V40 = 34*24 + 34*25 = 816+850=1666-3=1663 max len
unsigned char codeword_parameters[40][12] = { // 480 bytes
// 1st column: error correction codewords per block
// 2nd column: number of blocks in group 1
// 3rd column: number of data codewords in each of group 1's blocks
// 4th column: number of blocks in group 2
// 5th column: number of data codewords in each of group 2's blocks
// 6th column: number of remainder bits
// 7th-13th column: alignment pattern locations center module (skipping location 6)
// note: (2nd * 3rd) + (4th * 5th) = number of maximum data codewords permitted in message
// note: pixel size is (4*VERSION+17) where VERSION starts at 1 through 40 (only 21 supported below)
{13, 1, 13, 0, 0, 0, 0, 0, 0, 0, 0, 0}, // 1-Q
{22, 1, 22, 0, 0, 7, 18, 0, 0, 0, 0, 0}, // 2-Q
{18, 2, 17, 0, 0, 7, 22, 0, 0, 0, 0, 0}, // 3-Q
{26, 2, 24, 0, 0, 7, 26, 0, 0, 0, 0, 0}, // 4-Q
{18, 2, 15, 2, 16, 7, 30, 0, 0, 0, 0, 0}, // 5-Q
{24, 4, 19, 0, 0, 7, 34, 0, 0, 0, 0, 0}, // 6-Q
{18, 2, 14, 4, 15, 0, 22, 38, 0, 0, 0, 0}, // 7-Q
{22, 4, 18, 2, 19, 0, 24, 42, 0, 0, 0, 0}, // 8-Q
{20, 4, 16, 4, 17, 0, 26, 46, 0, 0, 0, 0}, // 9-Q
{24, 6, 19, 2, 20, 0, 28, 50, 0, 0, 0, 0}, //10-Q
{28, 4, 22, 4, 23, 0, 30, 54, 0, 0, 0, 0}, //11-Q
{26, 4, 20, 6, 21, 0, 32, 58, 0, 0, 0, 0}, //12-Q
{24, 8, 20, 4, 21, 0, 34, 62, 0, 0, 0, 0}, //13-Q
{20, 11, 16, 5, 17, 3, 26, 46, 66, 0, 0, 0}, //14-Q
{30, 5, 24, 7, 25, 3, 26, 48, 70, 0, 0, 0}, //15-Q
{24, 15, 19, 2, 20, 3, 26, 50, 74, 0, 0, 0}, //16-Q
{28, 1, 22, 15, 23, 3, 30, 54, 78, 0, 0, 0}, //17-Q
{28, 17, 22, 1, 23, 3, 30, 56, 82, 0, 0, 0}, //18-Q
{26, 17, 21, 4, 22, 3, 30, 58, 86, 0, 0, 0}, //19-Q
{30, 15, 24, 5, 25, 3, 34, 62, 90, 0, 0, 0}, //20-Q
{28, 17, 22, 6, 23, 4, 28, 50, 72, 94, 0, 0}, //21-Q
{30, 7, 24, 16, 25, 4, 26, 50, 74, 98, 0, 0}, //22-Q
{30, 11, 24, 14, 25, 4, 30, 54, 78, 102, 0, 0}, //23-Q
{30, 11, 24, 16, 25, 4, 28, 54, 80, 106, 0, 0}, //24-Q
{30, 7, 24, 22, 25, 4, 32, 58, 84, 110, 0, 0}, //25-Q
{28, 28, 22, 6, 23, 4, 30, 58, 86, 114, 0, 0}, //26-Q
{30, 8, 23, 26, 24, 4, 34, 62, 90, 118, 0, 0}, //27-Q
{30, 4, 24, 31, 25, 3, 26, 50, 74, 98, 122, 0}, //28-Q
{30, 1, 23, 37, 24, 3, 30, 54, 78, 102, 126, 0}, //29-Q
{30, 15, 24, 25, 25, 3, 26, 52, 78, 104, 130, 0}, //30-Q
{30, 42, 24, 1, 25, 3, 30, 56, 82, 108, 134, 0}, //31-Q
{30, 10, 24, 35, 25, 3, 34, 60, 86, 112, 138, 0}, //32-Q
{30, 29, 24, 19, 25, 3, 30, 58, 86, 114, 142, 0}, //33-Q
{30, 44, 24, 7, 25, 3, 34, 62, 90, 118, 146, 0}, //34-Q
{30, 39, 24, 14, 25, 0, 30, 54, 78, 102, 126, 150}, //35-Q
{30, 46, 24, 10, 25, 0, 24, 50, 76, 102, 128, 154}, //36-Q
{30, 49, 24, 10, 25, 0, 28, 54, 80, 106, 132, 158}, //37-Q
{30, 48, 24, 14, 25, 0, 32, 58, 84, 110, 136, 162}, //38-Q
{30, 43, 24, 22, 25, 0, 26, 54, 82, 110, 138, 166}, //39-Q
{30, 34, 24, 34, 25, 0, 30, 58, 86, 114, 142, 170} //40-Q
};