rqrcode 0.10.1 → 2.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.github/workflows/ruby.yml +28 -0
- data/.gitignore +13 -0
- data/.rspec +2 -0
- data/CHANGELOG.md +54 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +68 -0
- data/LICENSE.txt +21 -0
- data/README.md +223 -135
- data/Rakefile +10 -0
- data/_config.yml +1 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/images/ansi-screen-shot.png +0 -0
- data/images/github-qrcode.png +0 -0
- data/images/github-qrcode.svg +32 -0
- data/lib/rqrcode/export/ansi.rb +22 -25
- data/lib/rqrcode/export/html.rb +8 -10
- data/lib/rqrcode/export/png.rb +62 -45
- data/lib/rqrcode/export/svg.rb +180 -24
- data/lib/rqrcode/export.rb +6 -0
- data/lib/rqrcode/qrcode/qrcode.rb +17 -0
- data/lib/rqrcode/qrcode.rb +3 -4
- data/lib/rqrcode/version.rb +3 -1
- data/lib/rqrcode.rb +8 -19
- data/rqrcode.gemspec +39 -0
- metadata +91 -60
- data/CHANGELOG +0 -97
- data/LICENSE +0 -19
- data/lib/rqrcode/core_ext/array/behavior.rb +0 -12
- data/lib/rqrcode/core_ext/array.rb +0 -5
- data/lib/rqrcode/core_ext/integer/bitwise.rb +0 -13
- data/lib/rqrcode/core_ext/integer.rb +0 -5
- data/lib/rqrcode/core_ext.rb +0 -5
- data/lib/rqrcode/qrcode/qr_8bit_byte.rb +0 -36
- data/lib/rqrcode/qrcode/qr_alphanumeric.rb +0 -47
- data/lib/rqrcode/qrcode/qr_bit_buffer.rb +0 -99
- data/lib/rqrcode/qrcode/qr_code.rb +0 -585
- data/lib/rqrcode/qrcode/qr_math.rb +0 -63
- data/lib/rqrcode/qrcode/qr_numeric.rb +0 -57
- data/lib/rqrcode/qrcode/qr_polynomial.rb +0 -78
- data/lib/rqrcode/qrcode/qr_rs_block.rb +0 -314
- data/lib/rqrcode/qrcode/qr_util.rb +0 -272
- data/test/data.rb +0 -25
- data/test/test_helper.rb +0 -5
- data/test/test_regresions.rb +0 -10
- data/test/test_rqrcode.rb +0 -155
- data/test/test_rqrcode_export.rb +0 -27
@@ -1,78 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
|
3
|
-
#--
|
4
|
-
# Copyright 2004 by Duncan Robertson (duncan@whomwah.com).
|
5
|
-
# All rights reserved.
|
6
|
-
|
7
|
-
# Permission is granted for use, copying, modification, distribution,
|
8
|
-
# and distribution of modified versions of this work as long as the
|
9
|
-
# above copyright notice is included.
|
10
|
-
#++
|
11
|
-
|
12
|
-
module RQRCode #:nodoc:
|
13
|
-
|
14
|
-
class QRPolynomial
|
15
|
-
|
16
|
-
def initialize( num, shift )
|
17
|
-
raise QRCodeRunTimeError, "#{num.size}/#{shift}" if num.empty?
|
18
|
-
offset = 0
|
19
|
-
|
20
|
-
while offset < num.size && num[offset] == 0
|
21
|
-
offset = offset + 1
|
22
|
-
end
|
23
|
-
|
24
|
-
@num = Array.new( num.size - offset + shift )
|
25
|
-
|
26
|
-
( 0...num.size - offset ).each do |i|
|
27
|
-
@num[i] = num[i + offset]
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
|
32
|
-
def get( index )
|
33
|
-
@num[index]
|
34
|
-
end
|
35
|
-
|
36
|
-
|
37
|
-
def get_length
|
38
|
-
@num.size
|
39
|
-
end
|
40
|
-
|
41
|
-
|
42
|
-
def multiply( e )
|
43
|
-
num = Array.new( get_length + e.get_length - 1 )
|
44
|
-
|
45
|
-
( 0...get_length ).each do |i|
|
46
|
-
( 0...e.get_length ).each do |j|
|
47
|
-
tmp = num[i + j].nil? ? 0 : num[i + j]
|
48
|
-
num[i + j] = tmp ^ QRMath.gexp(QRMath.glog( get(i) ) + QRMath.glog(e.get(j)))
|
49
|
-
end
|
50
|
-
end
|
51
|
-
|
52
|
-
return QRPolynomial.new( num, 0 )
|
53
|
-
end
|
54
|
-
|
55
|
-
|
56
|
-
def mod( e )
|
57
|
-
if get_length - e.get_length < 0
|
58
|
-
return self
|
59
|
-
end
|
60
|
-
|
61
|
-
ratio = QRMath.glog(get(0)) - QRMath.glog(e.get(0))
|
62
|
-
num = Array.new(get_length)
|
63
|
-
|
64
|
-
( 0...get_length ).each do |i|
|
65
|
-
num[i] = get(i)
|
66
|
-
end
|
67
|
-
|
68
|
-
( 0...e.get_length ).each do |i|
|
69
|
-
tmp = num[i].nil? ? 0 : num[i]
|
70
|
-
num[i] = tmp ^ QRMath.gexp(QRMath.glog(e.get(i)) + ratio)
|
71
|
-
end
|
72
|
-
|
73
|
-
return QRPolynomial.new( num, 0 ).mod(e)
|
74
|
-
end
|
75
|
-
|
76
|
-
end
|
77
|
-
|
78
|
-
end
|
@@ -1,314 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
|
3
|
-
#--
|
4
|
-
# Copyright 2004 by Duncan Robertson (duncan@whomwah.com).
|
5
|
-
# All rights reserved.
|
6
|
-
|
7
|
-
# Permission is granted for use, copying, modification, distribution,
|
8
|
-
# and distribution of modified versions of this work as long as the
|
9
|
-
# above copyright notice is included.
|
10
|
-
#++
|
11
|
-
|
12
|
-
module RQRCode #:nodoc:
|
13
|
-
|
14
|
-
class QRRSBlock
|
15
|
-
attr_reader :data_count, :total_count
|
16
|
-
|
17
|
-
def initialize( total_count, data_count )
|
18
|
-
@total_count = total_count
|
19
|
-
@data_count = data_count
|
20
|
-
end
|
21
|
-
|
22
|
-
# http://www.thonky.com/qr-code-tutorial/error-correction-table/
|
23
|
-
RQRCode::QRRSBlock::RS_BLOCK_TABLE = [
|
24
|
-
|
25
|
-
# L
|
26
|
-
# M
|
27
|
-
# Q
|
28
|
-
# H
|
29
|
-
|
30
|
-
# 1
|
31
|
-
[1, 26, 19],
|
32
|
-
[1, 26, 16],
|
33
|
-
[1, 26, 13],
|
34
|
-
[1, 26, 9],
|
35
|
-
|
36
|
-
# 2
|
37
|
-
[1, 44, 34],
|
38
|
-
[1, 44, 28],
|
39
|
-
[1, 44, 22],
|
40
|
-
[1, 44, 16],
|
41
|
-
|
42
|
-
# 3
|
43
|
-
[1, 70, 55],
|
44
|
-
[1, 70, 44],
|
45
|
-
[2, 35, 17],
|
46
|
-
[2, 35, 13],
|
47
|
-
|
48
|
-
# 4
|
49
|
-
[1, 100, 80],
|
50
|
-
[2, 50, 32],
|
51
|
-
[2, 50, 24],
|
52
|
-
[4, 25, 9],
|
53
|
-
|
54
|
-
# 5
|
55
|
-
[1, 134, 108],
|
56
|
-
[2, 67, 43],
|
57
|
-
[2, 33, 15, 2, 34, 16],
|
58
|
-
[2, 33, 11, 2, 34, 12],
|
59
|
-
|
60
|
-
# 6
|
61
|
-
[2, 86, 68],
|
62
|
-
[4, 43, 27],
|
63
|
-
[4, 43, 19],
|
64
|
-
[4, 43, 15],
|
65
|
-
|
66
|
-
# 7
|
67
|
-
[2, 98, 78],
|
68
|
-
[4, 49, 31],
|
69
|
-
[2, 32, 14, 4, 33, 15],
|
70
|
-
[4, 39, 13, 1, 40, 14],
|
71
|
-
|
72
|
-
# 8
|
73
|
-
[2, 121, 97],
|
74
|
-
[2, 60, 38, 2, 61, 39],
|
75
|
-
[4, 40, 18, 2, 41, 19],
|
76
|
-
[4, 40, 14, 2, 41, 15],
|
77
|
-
|
78
|
-
# 9
|
79
|
-
[2, 146, 116],
|
80
|
-
[3, 58, 36, 2, 59, 37],
|
81
|
-
[4, 36, 16, 4, 37, 17],
|
82
|
-
[4, 36, 12, 4, 37, 13],
|
83
|
-
|
84
|
-
# 10
|
85
|
-
[2, 86, 68, 2, 87, 69],
|
86
|
-
[4, 69, 43, 1, 70, 44],
|
87
|
-
[6, 43, 19, 2, 44, 20],
|
88
|
-
[6, 43, 15, 2, 44, 16],
|
89
|
-
|
90
|
-
# 11
|
91
|
-
[4, 101, 81],
|
92
|
-
[1, 80, 50, 4, 81, 51],
|
93
|
-
[4, 50, 22, 4, 51, 23],
|
94
|
-
[3, 36, 12, 8, 37, 13],
|
95
|
-
|
96
|
-
# 12
|
97
|
-
[2, 116, 92, 2, 117, 93],
|
98
|
-
[6, 58, 36, 2, 59, 37],
|
99
|
-
[4, 46, 20, 6, 47, 21],
|
100
|
-
[7, 42, 14, 4, 43, 15],
|
101
|
-
|
102
|
-
# 13
|
103
|
-
[4, 133, 107],
|
104
|
-
[8, 59, 37, 1, 60, 38],
|
105
|
-
[8, 44, 20, 4, 45, 21],
|
106
|
-
[12, 33, 11, 4, 34, 12],
|
107
|
-
|
108
|
-
# 14
|
109
|
-
[3, 145, 115, 1, 146, 116],
|
110
|
-
[4, 64, 40, 5, 65, 41],
|
111
|
-
[11, 36, 16, 5, 37, 17],
|
112
|
-
[11, 36, 12, 5, 37, 13],
|
113
|
-
|
114
|
-
# 15
|
115
|
-
[5, 109, 87, 1, 110, 88],
|
116
|
-
[5, 65, 41, 5, 66, 42],
|
117
|
-
[5, 54, 24, 7, 55, 25],
|
118
|
-
[11, 36, 12, 7, 37, 13],
|
119
|
-
|
120
|
-
# 16
|
121
|
-
[5, 122, 98, 1, 123, 99],
|
122
|
-
[7, 73, 45, 3, 74, 46],
|
123
|
-
[15, 43, 19, 2, 44, 20],
|
124
|
-
[3, 45, 15, 13, 46, 16],
|
125
|
-
|
126
|
-
# 17
|
127
|
-
[1, 135, 107, 5, 136, 108],
|
128
|
-
[10, 74, 46, 1, 75, 47],
|
129
|
-
[1, 50, 22, 15, 51, 23],
|
130
|
-
[2, 42, 14, 17, 43, 15],
|
131
|
-
|
132
|
-
# 18
|
133
|
-
[5, 150, 120, 1, 151, 121],
|
134
|
-
[9, 69, 43, 4, 70, 44],
|
135
|
-
[17, 50, 22, 1, 51, 23],
|
136
|
-
[2, 42, 14, 19, 43, 15],
|
137
|
-
|
138
|
-
# 19
|
139
|
-
[3, 141, 113, 4, 142, 114],
|
140
|
-
[3, 70, 44, 11, 71, 45],
|
141
|
-
[17, 47, 21, 4, 48, 22],
|
142
|
-
[9, 39, 13, 16, 40, 14],
|
143
|
-
|
144
|
-
# 20
|
145
|
-
[3, 135, 107, 5, 136, 108],
|
146
|
-
[3, 67, 41, 13, 68, 42],
|
147
|
-
[15, 54, 24, 5, 55, 25],
|
148
|
-
[15, 43, 15, 10, 44, 16],
|
149
|
-
|
150
|
-
# 21
|
151
|
-
[4, 144, 116, 4, 145, 117],
|
152
|
-
[17, 68, 42],
|
153
|
-
[17, 50, 22, 6, 51, 23],
|
154
|
-
[19, 46, 16, 6, 47, 17],
|
155
|
-
|
156
|
-
# 22
|
157
|
-
[2, 139, 111, 7, 140, 112],
|
158
|
-
[17, 74, 46],
|
159
|
-
[7, 54, 24, 16, 55, 25],
|
160
|
-
[34, 37, 13],
|
161
|
-
|
162
|
-
# 23
|
163
|
-
[4, 151, 121, 5, 152, 122],
|
164
|
-
[4, 75, 47, 14, 76, 48],
|
165
|
-
[11, 54, 24, 14, 55, 25],
|
166
|
-
[16, 45, 15, 14, 46, 16],
|
167
|
-
|
168
|
-
# 24
|
169
|
-
[6, 147, 117, 4, 148, 118],
|
170
|
-
[6, 73, 45, 14, 74, 46],
|
171
|
-
[11, 54, 24, 16, 55, 25],
|
172
|
-
[30, 46, 16, 2, 47, 17],
|
173
|
-
|
174
|
-
# 25
|
175
|
-
[8, 132, 106, 4, 133, 107],
|
176
|
-
[8, 75, 47, 13, 76, 48],
|
177
|
-
[7, 54, 24, 22, 55, 25],
|
178
|
-
[22, 45, 15, 13, 46, 16],
|
179
|
-
|
180
|
-
# 26
|
181
|
-
[10, 142, 114, 2, 143, 115],
|
182
|
-
[19, 74, 46, 4, 75, 47],
|
183
|
-
[28, 50, 22, 6, 51, 23],
|
184
|
-
[33, 46, 16, 4, 47, 17],
|
185
|
-
|
186
|
-
# 27
|
187
|
-
[8, 152, 122, 4, 153, 123],
|
188
|
-
[22, 73, 45, 3, 74, 46],
|
189
|
-
[8, 53, 23, 26, 54, 24],
|
190
|
-
[12, 45, 15, 28, 46, 16],
|
191
|
-
|
192
|
-
# 28
|
193
|
-
[3, 147, 117, 10, 148, 118],
|
194
|
-
[3, 73, 45, 23, 74, 46],
|
195
|
-
[4, 54, 24, 31, 55, 25],
|
196
|
-
[11, 45, 15, 31, 46, 16],
|
197
|
-
|
198
|
-
# 29
|
199
|
-
[7, 146, 116, 7, 147, 117],
|
200
|
-
[21, 73, 45, 7, 74, 46],
|
201
|
-
[1, 53, 23, 37, 54, 24],
|
202
|
-
[19, 45, 15, 26, 46, 16],
|
203
|
-
|
204
|
-
# 30
|
205
|
-
[5, 145, 115, 10, 146, 116],
|
206
|
-
[19, 75, 47, 10, 76, 48],
|
207
|
-
[15, 54, 24, 25, 55, 25],
|
208
|
-
[23, 45, 15, 25, 46, 16],
|
209
|
-
|
210
|
-
# 31
|
211
|
-
[13, 145, 115, 3, 146, 116],
|
212
|
-
[2, 74, 46, 29, 75, 47],
|
213
|
-
[42, 54, 24, 1, 55, 25],
|
214
|
-
[23, 45, 15, 28, 46, 16],
|
215
|
-
|
216
|
-
# 32
|
217
|
-
[17, 145, 115],
|
218
|
-
[10, 74, 46, 23, 75, 47],
|
219
|
-
[10, 54, 24, 35, 55, 25],
|
220
|
-
[19, 45, 15, 35, 46, 16],
|
221
|
-
|
222
|
-
# 33
|
223
|
-
[17, 145, 115, 1, 146, 116],
|
224
|
-
[14, 74, 46, 21, 75, 47],
|
225
|
-
[29, 54, 24, 19, 55, 25],
|
226
|
-
[11, 45, 15, 46, 46, 16],
|
227
|
-
|
228
|
-
# 34
|
229
|
-
[13, 145, 115, 6, 146, 116],
|
230
|
-
[14, 74, 46, 23, 75, 47],
|
231
|
-
[44, 54, 24, 7, 55, 25],
|
232
|
-
[59, 46, 16, 1, 47, 17],
|
233
|
-
|
234
|
-
# 35
|
235
|
-
[12, 151, 121, 7, 152, 122],
|
236
|
-
[12, 75, 47, 26, 76, 48],
|
237
|
-
[39, 54, 24, 14, 55, 25],
|
238
|
-
[22, 45, 15, 41, 46, 16],
|
239
|
-
|
240
|
-
# 36
|
241
|
-
[6, 151, 121, 14, 152, 122],
|
242
|
-
[6, 75, 47, 34, 76, 48],
|
243
|
-
[46, 54, 24, 10, 55, 25],
|
244
|
-
[2, 45, 15, 64, 46, 16],
|
245
|
-
|
246
|
-
# 37
|
247
|
-
[17, 152, 122, 4, 153, 123],
|
248
|
-
[29, 74, 46, 14, 75, 47],
|
249
|
-
[49, 54, 24, 10, 55, 25],
|
250
|
-
[24, 45, 15, 46, 46, 16],
|
251
|
-
|
252
|
-
# 38
|
253
|
-
[4, 152, 122, 18, 153, 123],
|
254
|
-
[13, 74, 46, 32, 75, 47],
|
255
|
-
[48, 54, 24, 14, 55, 25],
|
256
|
-
[42, 45, 15, 32, 46, 16],
|
257
|
-
|
258
|
-
# 39
|
259
|
-
[20, 147, 117, 4, 148, 118],
|
260
|
-
[40, 75, 47, 7, 76, 48],
|
261
|
-
[43, 54, 24, 22, 55, 25],
|
262
|
-
[10, 45, 15, 67, 46, 16],
|
263
|
-
|
264
|
-
# 40
|
265
|
-
[19, 148, 118, 6, 149, 119],
|
266
|
-
[18, 75, 47, 31, 76, 48],
|
267
|
-
[34, 54, 24, 34, 55, 25],
|
268
|
-
[20, 45, 15, 61, 46, 16]
|
269
|
-
|
270
|
-
]
|
271
|
-
|
272
|
-
def QRRSBlock.get_rs_blocks(version, error_correct_level)
|
273
|
-
rs_block = QRRSBlock.get_rs_block_table(version, error_correct_level)
|
274
|
-
|
275
|
-
if rs_block.nil?
|
276
|
-
raise QRCodeRunTimeError,
|
277
|
-
"bad rsblock @ version: #{version}/error_correct_level:#{error_correct_level}"
|
278
|
-
end
|
279
|
-
|
280
|
-
length = rs_block.size / 3
|
281
|
-
list = []
|
282
|
-
|
283
|
-
( 0...length ).each do |i|
|
284
|
-
count = rs_block[i * 3 + 0]
|
285
|
-
total_count = rs_block[i * 3 + 1]
|
286
|
-
data_count = rs_block[i * 3 + 2]
|
287
|
-
|
288
|
-
( 0...count ).each do |j|
|
289
|
-
list << QRRSBlock.new( total_count, data_count )
|
290
|
-
end
|
291
|
-
end
|
292
|
-
|
293
|
-
list
|
294
|
-
end
|
295
|
-
|
296
|
-
|
297
|
-
def QRRSBlock.get_rs_block_table(version, error_correct_level)
|
298
|
-
case error_correct_level
|
299
|
-
when QRERRORCORRECTLEVEL[:l]
|
300
|
-
QRRSBlock::RS_BLOCK_TABLE[(version - 1) * 4 + 0]
|
301
|
-
when QRERRORCORRECTLEVEL[:m]
|
302
|
-
QRRSBlock::RS_BLOCK_TABLE[(version - 1) * 4 + 1]
|
303
|
-
when QRERRORCORRECTLEVEL[:q]
|
304
|
-
QRRSBlock::RS_BLOCK_TABLE[(version - 1) * 4 + 2]
|
305
|
-
when QRERRORCORRECTLEVEL[:h]
|
306
|
-
QRRSBlock::RS_BLOCK_TABLE[(version - 1) * 4 + 3]
|
307
|
-
else
|
308
|
-
nil
|
309
|
-
end
|
310
|
-
end
|
311
|
-
|
312
|
-
end
|
313
|
-
|
314
|
-
end
|
@@ -1,272 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
|
3
|
-
#--
|
4
|
-
# Copyright 2004 by Duncan Robertson (duncan@whomwah.com).
|
5
|
-
# All rights reserved.
|
6
|
-
|
7
|
-
# Permission is granted for use, copying, modification, distribution,
|
8
|
-
# and distribution of modified versions of this work as long as the
|
9
|
-
# above copyright notice is included.
|
10
|
-
#++
|
11
|
-
|
12
|
-
module RQRCode #:nodoc:
|
13
|
-
|
14
|
-
class QRUtil
|
15
|
-
|
16
|
-
PATTERN_POSITION_TABLE = [
|
17
|
-
|
18
|
-
[],
|
19
|
-
[6, 18],
|
20
|
-
[6, 22],
|
21
|
-
[6, 26],
|
22
|
-
[6, 30],
|
23
|
-
[6, 34],
|
24
|
-
[6, 22, 38],
|
25
|
-
[6, 24, 42],
|
26
|
-
[6, 26, 46],
|
27
|
-
[6, 28, 50],
|
28
|
-
[6, 30, 54],
|
29
|
-
[6, 32, 58],
|
30
|
-
[6, 34, 62],
|
31
|
-
[6, 26, 46, 66],
|
32
|
-
[6, 26, 48, 70],
|
33
|
-
[6, 26, 50, 74],
|
34
|
-
[6, 30, 54, 78],
|
35
|
-
[6, 30, 56, 82],
|
36
|
-
[6, 30, 58, 86],
|
37
|
-
[6, 34, 62, 90],
|
38
|
-
[6, 28, 50, 72, 94],
|
39
|
-
[6, 26, 50, 74, 98],
|
40
|
-
[6, 30, 54, 78, 102],
|
41
|
-
[6, 28, 54, 80, 106],
|
42
|
-
[6, 32, 58, 84, 110],
|
43
|
-
[6, 30, 58, 86, 114],
|
44
|
-
[6, 34, 62, 90, 118],
|
45
|
-
[6, 26, 50, 74, 98, 122],
|
46
|
-
[6, 30, 54, 78, 102, 126],
|
47
|
-
[6, 26, 52, 78, 104, 130],
|
48
|
-
[6, 30, 56, 82, 108, 134],
|
49
|
-
[6, 34, 60, 86, 112, 138],
|
50
|
-
[6, 30, 58, 86, 114, 142],
|
51
|
-
[6, 34, 62, 90, 118, 146],
|
52
|
-
[6, 30, 54, 78, 102, 126, 150],
|
53
|
-
[6, 24, 50, 76, 102, 128, 154],
|
54
|
-
[6, 28, 54, 80, 106, 132, 158],
|
55
|
-
[6, 32, 58, 84, 110, 136, 162],
|
56
|
-
[6, 26, 54, 82, 110, 138, 166],
|
57
|
-
[6, 30, 58, 86, 114, 142, 170]
|
58
|
-
]
|
59
|
-
|
60
|
-
G15 = 1 << 10 | 1 << 8 | 1 << 5 | 1 << 4 | 1 << 2 | 1 << 1 | 1 << 0
|
61
|
-
G18 = 1 << 12 | 1 << 11 | 1 << 10 | 1 << 9 | 1 << 8 | 1 << 5 | 1 << 2 | 1 << 0
|
62
|
-
G15_MASK = 1 << 14 | 1 << 12 | 1 << 10 | 1 << 4 | 1 << 1
|
63
|
-
|
64
|
-
DEMERIT_POINTS_1 = 3
|
65
|
-
DEMERIT_POINTS_2 = 3
|
66
|
-
DEMERIT_POINTS_3 = 40
|
67
|
-
DEMERIT_POINTS_4 = 10
|
68
|
-
|
69
|
-
BITS_FOR_MODE = {
|
70
|
-
QRMODE[:mode_number] => [10, 12, 14],
|
71
|
-
QRMODE[:mode_alpha_numk] => [9, 11, 13],
|
72
|
-
QRMODE[:mode_8bit_byte] => [8, 16, 16],
|
73
|
-
QRMODE[:mode_kanji] => [8, 10, 12],
|
74
|
-
}
|
75
|
-
|
76
|
-
def QRUtil.max_size
|
77
|
-
PATTERN_POSITION_TABLE.count
|
78
|
-
end
|
79
|
-
|
80
|
-
def QRUtil.get_bch_format_info( data )
|
81
|
-
d = data << 10
|
82
|
-
while QRUtil.get_bch_digit(d) - QRUtil.get_bch_digit(G15) >= 0
|
83
|
-
d ^= (G15 << (QRUtil.get_bch_digit(d) - QRUtil.get_bch_digit(G15)))
|
84
|
-
end
|
85
|
-
(( data << 10 ) | d) ^ G15_MASK
|
86
|
-
end
|
87
|
-
|
88
|
-
|
89
|
-
def QRUtil.get_bch_version(data)
|
90
|
-
d = data << 12
|
91
|
-
while QRUtil.get_bch_digit(d) - QRUtil.get_bch_digit(G18) >= 0
|
92
|
-
d ^= (G18 << (QRUtil.get_bch_digit(d) - QRUtil.get_bch_digit(G18)))
|
93
|
-
end
|
94
|
-
( data << 12 ) | d
|
95
|
-
end
|
96
|
-
|
97
|
-
|
98
|
-
def QRUtil.get_bch_digit( data )
|
99
|
-
digit = 0
|
100
|
-
|
101
|
-
while data != 0
|
102
|
-
digit = digit + 1
|
103
|
-
data = (data).rszf(1)
|
104
|
-
end
|
105
|
-
|
106
|
-
digit
|
107
|
-
end
|
108
|
-
|
109
|
-
|
110
|
-
def QRUtil.get_pattern_positions(version)
|
111
|
-
PATTERN_POSITION_TABLE[version - 1]
|
112
|
-
end
|
113
|
-
|
114
|
-
|
115
|
-
def QRUtil.get_mask( mask_pattern, i, j )
|
116
|
-
if mask_pattern > QRMASKCOMPUTATIONS.size
|
117
|
-
raise QRCodeRunTimeError, "bad mask_pattern: #{mask_pattern}"
|
118
|
-
end
|
119
|
-
|
120
|
-
return QRMASKCOMPUTATIONS[mask_pattern].call(i, j)
|
121
|
-
end
|
122
|
-
|
123
|
-
|
124
|
-
def QRUtil.get_error_correct_polynomial( error_correct_length )
|
125
|
-
a = QRPolynomial.new( [1], 0 )
|
126
|
-
|
127
|
-
( 0...error_correct_length ).each do |i|
|
128
|
-
a = a.multiply( QRPolynomial.new( [1, QRMath.gexp(i)], 0 ) )
|
129
|
-
end
|
130
|
-
|
131
|
-
a
|
132
|
-
end
|
133
|
-
|
134
|
-
|
135
|
-
def QRUtil.get_length_in_bits(mode, version)
|
136
|
-
if !QRMODE.value?(mode)
|
137
|
-
raise QRCodeRunTimeError, "Unknown mode: #{mode}"
|
138
|
-
end
|
139
|
-
|
140
|
-
if version > 40
|
141
|
-
raise QRCodeRunTimeError, "Unknown version: #{version}"
|
142
|
-
end
|
143
|
-
|
144
|
-
if version.between?(1, 9)
|
145
|
-
# 1 - 9
|
146
|
-
macro_version = 0
|
147
|
-
elsif version <= 26
|
148
|
-
# 10 - 26
|
149
|
-
macro_version = 1
|
150
|
-
elsif version <= 40
|
151
|
-
# 27 - 40
|
152
|
-
macro_version = 2
|
153
|
-
end
|
154
|
-
|
155
|
-
return BITS_FOR_MODE[mode][macro_version]
|
156
|
-
end
|
157
|
-
|
158
|
-
def QRUtil.get_lost_points(modules)
|
159
|
-
demerit_points = 0
|
160
|
-
|
161
|
-
demerit_points += QRUtil.demerit_points_1_same_color(modules)
|
162
|
-
demerit_points += QRUtil.demerit_points_2_full_blocks(modules)
|
163
|
-
demerit_points += QRUtil.demerit_points_3_dangerous_patterns(modules)
|
164
|
-
demerit_points += QRUtil.demerit_points_4_dark_ratio(modules)
|
165
|
-
|
166
|
-
return demerit_points
|
167
|
-
end
|
168
|
-
|
169
|
-
def QRUtil.demerit_points_1_same_color(modules)
|
170
|
-
demerit_points = 0
|
171
|
-
module_count = modules.size
|
172
|
-
|
173
|
-
# level1
|
174
|
-
(0...module_count).each do |row|
|
175
|
-
(0...module_count).each do |col|
|
176
|
-
same_count = 0
|
177
|
-
dark = modules[row][col]
|
178
|
-
|
179
|
-
( -1..1 ).each do |r|
|
180
|
-
next if row + r < 0 || module_count <= row + r
|
181
|
-
|
182
|
-
( -1..1 ).each do |c|
|
183
|
-
next if col + c < 0 || module_count <= col + c
|
184
|
-
next if r == 0 && c == 0
|
185
|
-
if dark == modules[row + r][col + c]
|
186
|
-
same_count += 1
|
187
|
-
end
|
188
|
-
end
|
189
|
-
end
|
190
|
-
|
191
|
-
if same_count > 5
|
192
|
-
demerit_points += (DEMERIT_POINTS_1 + same_count - 5)
|
193
|
-
end
|
194
|
-
end
|
195
|
-
end
|
196
|
-
|
197
|
-
return demerit_points
|
198
|
-
end
|
199
|
-
|
200
|
-
def QRUtil.demerit_points_2_full_blocks(modules)
|
201
|
-
demerit_points = 0
|
202
|
-
module_count = modules.size
|
203
|
-
|
204
|
-
# level 2
|
205
|
-
(0...(module_count - 1)).each do |row|
|
206
|
-
(0...(module_count - 1)).each do |col|
|
207
|
-
count = 0
|
208
|
-
count += 1 if modules[row][col]
|
209
|
-
count += 1 if modules[row + 1][col]
|
210
|
-
count += 1 if modules[row][col + 1]
|
211
|
-
count += 1 if modules[row + 1][col + 1]
|
212
|
-
if (count == 0 || count == 4)
|
213
|
-
demerit_points += DEMERIT_POINTS_2
|
214
|
-
end
|
215
|
-
end
|
216
|
-
end
|
217
|
-
|
218
|
-
return demerit_points
|
219
|
-
end
|
220
|
-
|
221
|
-
def QRUtil.demerit_points_3_dangerous_patterns(modules)
|
222
|
-
demerit_points = 0
|
223
|
-
module_count = modules.size
|
224
|
-
|
225
|
-
# level 3
|
226
|
-
modules.each do |row|
|
227
|
-
(module_count - 6).times do |col_idx|
|
228
|
-
if row[col_idx] &&
|
229
|
-
!row[col_idx + 1] &&
|
230
|
-
row[col_idx + 2] &&
|
231
|
-
row[col_idx + 3] &&
|
232
|
-
row[col_idx + 4] &&
|
233
|
-
!row[col_idx + 5] &&
|
234
|
-
row[col_idx + 6]
|
235
|
-
demerit_points += DEMERIT_POINTS_3
|
236
|
-
end
|
237
|
-
end
|
238
|
-
end
|
239
|
-
|
240
|
-
(0...module_count).each do |col|
|
241
|
-
(0...(module_count - 6)).each do |row|
|
242
|
-
if modules[row][col] &&
|
243
|
-
!modules[row + 1][col] &&
|
244
|
-
modules[row + 2][col] &&
|
245
|
-
modules[row + 3][col] &&
|
246
|
-
modules[row + 4][col] &&
|
247
|
-
!modules[row + 5][col] &&
|
248
|
-
modules[row + 6][col]
|
249
|
-
demerit_points += DEMERIT_POINTS_3
|
250
|
-
end
|
251
|
-
end
|
252
|
-
end
|
253
|
-
|
254
|
-
return demerit_points
|
255
|
-
end
|
256
|
-
|
257
|
-
def QRUtil.demerit_points_4_dark_ratio(modules)
|
258
|
-
# level 4
|
259
|
-
dark_count = modules.reduce(0) do |sum, col|
|
260
|
-
sum + col.count(true)
|
261
|
-
end
|
262
|
-
|
263
|
-
ratio = dark_count / (modules.size * modules.size)
|
264
|
-
ratio_delta = (100 * ratio - 50).abs / 5
|
265
|
-
|
266
|
-
demerit_points = ratio_delta * DEMERIT_POINTS_4
|
267
|
-
return demerit_points
|
268
|
-
end
|
269
|
-
|
270
|
-
end
|
271
|
-
|
272
|
-
end
|