barby-chunky_png 0.3.3
Sign up to get free protection for your applications and to get access to all the features.
- data/README +29 -0
- data/bin/barby +41 -0
- data/lib/barby/barcode/bookland.rb +37 -0
- data/lib/barby/barcode/code_128.rb +410 -0
- data/lib/barby/barcode/code_25.rb +193 -0
- data/lib/barby/barcode/code_25_iata.rb +23 -0
- data/lib/barby/barcode/code_25_interleaved.rb +73 -0
- data/lib/barby/barcode/code_39.rb +233 -0
- data/lib/barby/barcode/code_93.rb +230 -0
- data/lib/barby/barcode/data_matrix.rb +46 -0
- data/lib/barby/barcode/ean_13.rb +178 -0
- data/lib/barby/barcode/ean_8.rb +32 -0
- data/lib/barby/barcode/gs1_128.rb +42 -0
- data/lib/barby/barcode/pdf_417.rb +76 -0
- data/lib/barby/barcode/qr_code.rb +101 -0
- data/lib/barby/barcode.rb +116 -0
- data/lib/barby/outputter/ascii_outputter.rb +41 -0
- data/lib/barby/outputter/cairo_outputter.rb +185 -0
- data/lib/barby/outputter/pdfwriter_outputter.rb +83 -0
- data/lib/barby/outputter/png_outputter.rb +97 -0
- data/lib/barby/outputter/prawn_outputter.rb +99 -0
- data/lib/barby/outputter/rmagick_outputter.rb +126 -0
- data/lib/barby/outputter/svg_outputter.rb +225 -0
- data/lib/barby/outputter.rb +132 -0
- data/lib/barby/vendor.rb +3 -0
- data/lib/barby/version.rb +9 -0
- data/lib/barby.rb +17 -0
- data/vendor/Pdf417lib-java-0.91/lib/Pdf417lib.jar +0 -0
- data/vendor/Pdf417lib-java-0.91/lib/Pdf417lib.java +1471 -0
- data/vendor/rqrcode/CHANGELOG +29 -0
- data/vendor/rqrcode/COPYING +19 -0
- data/vendor/rqrcode/README +98 -0
- data/vendor/rqrcode/Rakefile +65 -0
- data/vendor/rqrcode/lib/rqrcode/core_ext/array/behavior.rb +9 -0
- data/vendor/rqrcode/lib/rqrcode/core_ext/array.rb +5 -0
- data/vendor/rqrcode/lib/rqrcode/core_ext/integer/bitwise.rb +11 -0
- data/vendor/rqrcode/lib/rqrcode/core_ext/integer.rb +5 -0
- data/vendor/rqrcode/lib/rqrcode/core_ext.rb +5 -0
- data/vendor/rqrcode/lib/rqrcode/qrcode/qr_8bit_byte.rb +37 -0
- data/vendor/rqrcode/lib/rqrcode/qrcode/qr_bit_buffer.rb +56 -0
- data/vendor/rqrcode/lib/rqrcode/qrcode/qr_code.rb +421 -0
- data/vendor/rqrcode/lib/rqrcode/qrcode/qr_math.rb +63 -0
- data/vendor/rqrcode/lib/rqrcode/qrcode/qr_polynomial.rb +78 -0
- data/vendor/rqrcode/lib/rqrcode/qrcode/qr_rs_block.rb +313 -0
- data/vendor/rqrcode/lib/rqrcode/qrcode/qr_util.rb +254 -0
- data/vendor/rqrcode/lib/rqrcode/qrcode.rb +4 -0
- data/vendor/rqrcode/lib/rqrcode.rb +13 -0
- data/vendor/rqrcode/test/runtest.rb +78 -0
- data/vendor/rqrcode/test/test_data.rb +21 -0
- metadata +129 -0
@@ -0,0 +1,313 @@
|
|
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
|
+
RQRCode::QRRSBlock::RS_BLOCK_TABLE = [
|
23
|
+
|
24
|
+
# L
|
25
|
+
# M
|
26
|
+
# Q
|
27
|
+
# H
|
28
|
+
|
29
|
+
# 1
|
30
|
+
[1, 26, 19],
|
31
|
+
[1, 26, 16],
|
32
|
+
[1, 26, 13],
|
33
|
+
[1, 26, 9],
|
34
|
+
|
35
|
+
# 2
|
36
|
+
[1, 44, 34],
|
37
|
+
[1, 44, 28],
|
38
|
+
[1, 44, 22],
|
39
|
+
[1, 44, 16],
|
40
|
+
|
41
|
+
# 3
|
42
|
+
[1, 70, 55],
|
43
|
+
[1, 70, 44],
|
44
|
+
[2, 35, 17],
|
45
|
+
[2, 35, 13],
|
46
|
+
|
47
|
+
# 4
|
48
|
+
[1, 100, 80],
|
49
|
+
[2, 50, 32],
|
50
|
+
[2, 50, 24],
|
51
|
+
[4, 25, 9],
|
52
|
+
|
53
|
+
# 5
|
54
|
+
[1, 134, 108],
|
55
|
+
[2, 67, 43],
|
56
|
+
[2, 33, 15, 2, 34, 16],
|
57
|
+
[2, 33, 11, 2, 34, 12],
|
58
|
+
|
59
|
+
# 6
|
60
|
+
[2, 86, 68],
|
61
|
+
[4, 43, 27],
|
62
|
+
[4, 43, 19],
|
63
|
+
[4, 43, 15],
|
64
|
+
|
65
|
+
# 7
|
66
|
+
[2, 98, 78],
|
67
|
+
[4, 49, 31],
|
68
|
+
[2, 32, 14, 4, 33, 15],
|
69
|
+
[4, 39, 13, 1, 40, 14],
|
70
|
+
|
71
|
+
# 8
|
72
|
+
[2, 121, 97],
|
73
|
+
[2, 60, 38, 2, 61, 39],
|
74
|
+
[4, 40, 18, 2, 41, 19],
|
75
|
+
[4, 40, 14, 2, 41, 15],
|
76
|
+
|
77
|
+
# 9
|
78
|
+
[2, 146, 116],
|
79
|
+
[3, 58, 36, 2, 59, 37],
|
80
|
+
[4, 36, 16, 4, 37, 17],
|
81
|
+
[4, 36, 12, 4, 37, 13],
|
82
|
+
|
83
|
+
# 10
|
84
|
+
[2, 86, 68, 2, 87, 69],
|
85
|
+
[4, 69, 43, 1, 70, 44],
|
86
|
+
[6, 43, 19, 2, 44, 20],
|
87
|
+
[6, 43, 15, 2, 44, 16],
|
88
|
+
|
89
|
+
# 11
|
90
|
+
[4, 101, 81],
|
91
|
+
[1, 80, 50, 4, 81, 51],
|
92
|
+
[4, 50, 22, 4, 51, 23],
|
93
|
+
[3, 36, 12, 8, 37, 13],
|
94
|
+
|
95
|
+
# 12
|
96
|
+
[2, 116, 92, 2, 117, 93],
|
97
|
+
[6, 58, 36, 2, 59, 37],
|
98
|
+
[4, 46, 20, 6, 47, 21],
|
99
|
+
[7, 42, 14, 4, 43, 15],
|
100
|
+
|
101
|
+
# 13
|
102
|
+
[4, 133, 107],
|
103
|
+
[8, 59, 37, 1, 60, 38],
|
104
|
+
[8, 44, 20, 4, 45, 21],
|
105
|
+
[12, 33, 11, 4, 34, 12],
|
106
|
+
|
107
|
+
# 14
|
108
|
+
[3, 145, 115, 1, 146, 116],
|
109
|
+
[4, 64, 40, 5, 65, 41],
|
110
|
+
[11, 36, 16, 5, 37, 17],
|
111
|
+
[11, 36, 12, 5, 37, 13],
|
112
|
+
|
113
|
+
# 15
|
114
|
+
[5, 109, 87, 1, 110, 88],
|
115
|
+
[5, 65, 41, 5, 66, 42],
|
116
|
+
[5, 54, 24, 7, 55, 25],
|
117
|
+
[11, 36, 12],
|
118
|
+
|
119
|
+
# 16
|
120
|
+
[5, 122, 98, 1, 123, 99],
|
121
|
+
[7, 73, 45, 3, 74, 46],
|
122
|
+
[15, 43, 19, 2, 44, 20],
|
123
|
+
[3, 45, 15, 13, 46, 16],
|
124
|
+
|
125
|
+
# 17
|
126
|
+
[1, 135, 107, 5, 136, 108],
|
127
|
+
[10, 74, 46, 1, 75, 47],
|
128
|
+
[1, 50, 22, 15, 51, 23],
|
129
|
+
[2, 42, 14, 17, 43, 15],
|
130
|
+
|
131
|
+
# 18
|
132
|
+
[5, 150, 120, 1, 151, 121],
|
133
|
+
[9, 69, 43, 4, 70, 44],
|
134
|
+
[17, 50, 22, 1, 51, 23],
|
135
|
+
[2, 42, 14, 19, 43, 15],
|
136
|
+
|
137
|
+
# 19
|
138
|
+
[3, 141, 113, 4, 142, 114],
|
139
|
+
[3, 70, 44, 11, 71, 45],
|
140
|
+
[17, 47, 21, 4, 48, 22],
|
141
|
+
[9, 39, 13, 16, 40, 14],
|
142
|
+
|
143
|
+
# 20
|
144
|
+
[3, 135, 107, 5, 136, 108],
|
145
|
+
[3, 67, 41, 13, 68, 42],
|
146
|
+
[15, 54, 24, 5, 55, 25],
|
147
|
+
[15, 43, 15, 10, 44, 16],
|
148
|
+
|
149
|
+
# 21
|
150
|
+
[4, 144, 116, 4, 145, 117],
|
151
|
+
[17, 68, 42],
|
152
|
+
[17, 50, 22, 6, 51, 23],
|
153
|
+
[19, 46, 16, 6, 47, 17],
|
154
|
+
|
155
|
+
# 22
|
156
|
+
[2, 139, 111, 7, 140, 112],
|
157
|
+
[17, 74, 46],
|
158
|
+
[7, 54, 24, 16, 55, 25],
|
159
|
+
[34, 37, 13],
|
160
|
+
|
161
|
+
# 23
|
162
|
+
[4, 151, 121, 5, 152, 122],
|
163
|
+
[4, 75, 47, 14, 76, 48],
|
164
|
+
[11, 54, 24, 14, 55, 25],
|
165
|
+
[16, 45, 15, 14, 46, 16],
|
166
|
+
|
167
|
+
# 24
|
168
|
+
[6, 147, 117, 4, 148, 118],
|
169
|
+
[6, 73, 45, 14, 74, 46],
|
170
|
+
[11, 54, 24, 16, 55, 25],
|
171
|
+
[30, 46, 16, 2, 47, 17],
|
172
|
+
|
173
|
+
# 25
|
174
|
+
[8, 132, 106, 4, 133, 107],
|
175
|
+
[8, 75, 47, 13, 76, 48],
|
176
|
+
[7, 54, 24, 22, 55, 25],
|
177
|
+
[22, 45, 15, 13, 46, 16],
|
178
|
+
|
179
|
+
# 26
|
180
|
+
[10, 142, 114, 2, 143, 115],
|
181
|
+
[19, 74, 46, 4, 75, 47],
|
182
|
+
[28, 50, 22, 6, 51, 23],
|
183
|
+
[33, 46, 16, 4, 47, 17],
|
184
|
+
|
185
|
+
# 27
|
186
|
+
[8, 152, 122, 4, 153, 123],
|
187
|
+
[22, 73, 45, 3, 74, 46],
|
188
|
+
[8, 53, 23, 26, 54, 24],
|
189
|
+
[12, 45, 15, 28, 46, 16],
|
190
|
+
|
191
|
+
# 28
|
192
|
+
[3, 147, 117, 10, 148, 118],
|
193
|
+
[3, 73, 45, 23, 74, 46],
|
194
|
+
[4, 54, 24, 31, 55, 25],
|
195
|
+
[11, 45, 15, 31, 46, 16],
|
196
|
+
|
197
|
+
# 29
|
198
|
+
[7, 146, 116, 7, 147, 117],
|
199
|
+
[21, 73, 45, 7, 74, 46],
|
200
|
+
[1, 53, 23, 37, 54, 24],
|
201
|
+
[19, 45, 15, 26, 46, 16],
|
202
|
+
|
203
|
+
# 30
|
204
|
+
[5, 145, 115, 10, 146, 116],
|
205
|
+
[19, 75, 47, 10, 76, 48],
|
206
|
+
[15, 54, 24, 25, 55, 25],
|
207
|
+
[23, 45, 15, 25, 46, 16],
|
208
|
+
|
209
|
+
# 31
|
210
|
+
[13, 145, 115, 3, 146, 116],
|
211
|
+
[2, 74, 46, 29, 75, 47],
|
212
|
+
[42, 54, 24, 1, 55, 25],
|
213
|
+
[23, 45, 15, 28, 46, 16],
|
214
|
+
|
215
|
+
# 32
|
216
|
+
[17, 145, 115],
|
217
|
+
[10, 74, 46, 23, 75, 47],
|
218
|
+
[10, 54, 24, 35, 55, 25],
|
219
|
+
[19, 45, 15, 35, 46, 16],
|
220
|
+
|
221
|
+
# 33
|
222
|
+
[17, 145, 115, 1, 146, 116],
|
223
|
+
[14, 74, 46, 21, 75, 47],
|
224
|
+
[29, 54, 24, 19, 55, 25],
|
225
|
+
[11, 45, 15, 46, 46, 16],
|
226
|
+
|
227
|
+
# 34
|
228
|
+
[13, 145, 115, 6, 146, 116],
|
229
|
+
[14, 74, 46, 23, 75, 47],
|
230
|
+
[44, 54, 24, 7, 55, 25],
|
231
|
+
[59, 46, 16, 1, 47, 17],
|
232
|
+
|
233
|
+
# 35
|
234
|
+
[12, 151, 121, 7, 152, 122],
|
235
|
+
[12, 75, 47, 26, 76, 48],
|
236
|
+
[39, 54, 24, 14, 55, 25],
|
237
|
+
[22, 45, 15, 41, 46, 16],
|
238
|
+
|
239
|
+
# 36
|
240
|
+
[6, 151, 121, 14, 152, 122],
|
241
|
+
[6, 75, 47, 34, 76, 48],
|
242
|
+
[46, 54, 24, 10, 55, 25],
|
243
|
+
[2, 45, 15, 64, 46, 16],
|
244
|
+
|
245
|
+
# 37
|
246
|
+
[17, 152, 122, 4, 153, 123],
|
247
|
+
[29, 74, 46, 14, 75, 47],
|
248
|
+
[49, 54, 24, 10, 55, 25],
|
249
|
+
[24, 45, 15, 46, 46, 16],
|
250
|
+
|
251
|
+
# 38
|
252
|
+
[4, 152, 122, 18, 153, 123],
|
253
|
+
[13, 74, 46, 32, 75, 47],
|
254
|
+
[48, 54, 24, 14, 55, 25],
|
255
|
+
[42, 45, 15, 32, 46, 16],
|
256
|
+
|
257
|
+
# 39
|
258
|
+
[20, 147, 117, 4, 148, 118],
|
259
|
+
[40, 75, 47, 7, 76, 48],
|
260
|
+
[43, 54, 24, 22, 55, 25],
|
261
|
+
[10, 45, 15, 67, 46, 16],
|
262
|
+
|
263
|
+
# 40
|
264
|
+
[19, 148, 118, 6, 149, 119],
|
265
|
+
[18, 75, 47, 31, 76, 48],
|
266
|
+
[34, 54, 24, 34, 55, 25],
|
267
|
+
[20, 45, 15, 61, 46, 16]
|
268
|
+
|
269
|
+
]
|
270
|
+
|
271
|
+
def QRRSBlock.get_rs_blocks( type_no, error_correct_level )
|
272
|
+
rs_block = QRRSBlock.get_rs_block_table( type_no, error_correct_level )
|
273
|
+
|
274
|
+
if rs_block.nil?
|
275
|
+
raise QRCodeRunTimeError,
|
276
|
+
"bad rsblock @ typeno: #{type_no}/error_correct_level:#{error_correct_level}"
|
277
|
+
end
|
278
|
+
|
279
|
+
length = rs_block.size / 3
|
280
|
+
list = []
|
281
|
+
|
282
|
+
( 0...length ).each do |i|
|
283
|
+
count = rs_block[i * 3 + 0]
|
284
|
+
total_count = rs_block[i * 3 + 1]
|
285
|
+
data_count = rs_block[i * 3 + 2]
|
286
|
+
|
287
|
+
( 0...count ).each do |j|
|
288
|
+
list << QRRSBlock.new( total_count, data_count )
|
289
|
+
end
|
290
|
+
end
|
291
|
+
|
292
|
+
list
|
293
|
+
end
|
294
|
+
|
295
|
+
|
296
|
+
def QRRSBlock.get_rs_block_table( type_number, error_correct_level )
|
297
|
+
case error_correct_level
|
298
|
+
when QRERRORCORRECTLEVEL[:l]
|
299
|
+
QRRSBlock::RS_BLOCK_TABLE[(type_number - 1) * 4 + 0]
|
300
|
+
when QRERRORCORRECTLEVEL[:m]
|
301
|
+
QRRSBlock::RS_BLOCK_TABLE[(type_number - 1) * 4 + 1]
|
302
|
+
when QRERRORCORRECTLEVEL[:q]
|
303
|
+
QRRSBlock::RS_BLOCK_TABLE[(type_number - 1) * 4 + 2]
|
304
|
+
when QRERRORCORRECTLEVEL[:h]
|
305
|
+
QRRSBlock::RS_BLOCK_TABLE[(type_number - 1) * 4 + 3]
|
306
|
+
else
|
307
|
+
nil
|
308
|
+
end
|
309
|
+
end
|
310
|
+
|
311
|
+
end
|
312
|
+
|
313
|
+
end
|
@@ -0,0 +1,254 @@
|
|
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
|
+
|
65
|
+
def QRUtil.get_bch_type_info( data )
|
66
|
+
d = data << 10
|
67
|
+
while QRUtil.get_bch_digit(d) - QRUtil.get_bch_digit(G15) >= 0
|
68
|
+
d ^= (G15 << (QRUtil.get_bch_digit(d) - QRUtil.get_bch_digit(G15)))
|
69
|
+
end
|
70
|
+
(( data << 10 ) | d) ^ G15_MASK
|
71
|
+
end
|
72
|
+
|
73
|
+
|
74
|
+
def QRUtil.get_bch_type_number( data )
|
75
|
+
d = data << 12
|
76
|
+
while QRUtil.get_bch_digit(d) - QRUtil.get_bch_digit(G18) >= 0
|
77
|
+
d ^= (G18 << (QRUtil.get_bch_digit(d) - QRUtil.get_bch_digit(G18)))
|
78
|
+
end
|
79
|
+
( data << 12 ) | d
|
80
|
+
end
|
81
|
+
|
82
|
+
|
83
|
+
def QRUtil.get_bch_digit( data )
|
84
|
+
digit = 0
|
85
|
+
|
86
|
+
while data != 0
|
87
|
+
digit = digit + 1
|
88
|
+
data = (data).rszf(1)
|
89
|
+
end
|
90
|
+
|
91
|
+
digit
|
92
|
+
end
|
93
|
+
|
94
|
+
|
95
|
+
def QRUtil.get_pattern_position( type_number )
|
96
|
+
PATTERN_POSITION_TABLE[ type_number - 1 ]
|
97
|
+
end
|
98
|
+
|
99
|
+
|
100
|
+
def QRUtil.get_mask( mask_pattern, i, j )
|
101
|
+
case mask_pattern
|
102
|
+
when QRMASKPATTERN[:pattern000]
|
103
|
+
(i + j) % 2 == 0
|
104
|
+
when QRMASKPATTERN[:pattern001]
|
105
|
+
i % 2 == 0
|
106
|
+
when QRMASKPATTERN[:pattern010]
|
107
|
+
j % 3 == 0
|
108
|
+
when QRMASKPATTERN[:pattern011]
|
109
|
+
(i + j) % 3 == 0
|
110
|
+
when QRMASKPATTERN[:pattern100]
|
111
|
+
((i / 2).floor + (j / 3).floor ) % 2 == 0
|
112
|
+
when QRMASKPATTERN[:pattern101]
|
113
|
+
(i * j) % 2 + (i * j) % 3 == 0
|
114
|
+
when QRMASKPATTERN[:pattern110]
|
115
|
+
( (i * j) % 2 + (i * j) % 3) % 2 == 0
|
116
|
+
when QRMASKPATTERN[:pattern111]
|
117
|
+
( (i * j) % 3 + (i + j) % 2) % 2 == 0
|
118
|
+
else
|
119
|
+
raise QRCodeRunTimeError, "bad mask_pattern: #{mask_pattern}"
|
120
|
+
end
|
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, type )
|
136
|
+
if 1 <= type && type < 10
|
137
|
+
|
138
|
+
# 1 - 9
|
139
|
+
case mode
|
140
|
+
when QRMODE[:mode_number] then 10
|
141
|
+
when QRMODE[:mode_alpha_num] then 9
|
142
|
+
when QRMODE[:mode_8bit_byte] then 8
|
143
|
+
when QRMODE[:mode_kanji] then 8
|
144
|
+
else
|
145
|
+
raise QRCodeRunTimeError, "mode: #{mode}"
|
146
|
+
end
|
147
|
+
|
148
|
+
elsif type < 27
|
149
|
+
|
150
|
+
# 10 -26
|
151
|
+
case mode
|
152
|
+
when QRMODE[:mode_number] then 12
|
153
|
+
when QRMODE[:mode_alpha_num] then 11
|
154
|
+
when QRMODE[:mode_8bit_byte] then 16
|
155
|
+
when QRMODE[:mode_kanji] then 10
|
156
|
+
else
|
157
|
+
raise QRCodeRunTimeError, "mode: #{mode}"
|
158
|
+
end
|
159
|
+
|
160
|
+
elsif type < 41
|
161
|
+
|
162
|
+
# 27 - 40
|
163
|
+
case mode
|
164
|
+
when QRMODE[:mode_number] then 14
|
165
|
+
when QRMODE[:mode_alpha_num] then 13
|
166
|
+
when QRMODE[:mode_8bit_byte] then 16
|
167
|
+
when QRMODE[:mode_kanji] then 12
|
168
|
+
else
|
169
|
+
raise QRCodeRunTimeError, "mode: #{mode}"
|
170
|
+
end
|
171
|
+
|
172
|
+
else
|
173
|
+
raise QRCodeRunTimeError, "type: #{type}"
|
174
|
+
end
|
175
|
+
end
|
176
|
+
|
177
|
+
|
178
|
+
def QRUtil.get_lost_point( qr_code )
|
179
|
+
module_count = qr_code.module_count
|
180
|
+
lost_point = 0
|
181
|
+
|
182
|
+
# level1
|
183
|
+
( 0...module_count ).each do |row|
|
184
|
+
( 0...module_count ).each do |col|
|
185
|
+
same_count = 0
|
186
|
+
dark = qr_code.is_dark( row, col )
|
187
|
+
|
188
|
+
( -1..1 ).each do |r|
|
189
|
+
next if row + r < 0 || module_count <= row + r
|
190
|
+
|
191
|
+
( -1..1 ).each do |c|
|
192
|
+
next if col + c < 0 || module_count <= col + c
|
193
|
+
next if r == 0 && c == 0
|
194
|
+
if dark == qr_code.is_dark( row + r, col + c )
|
195
|
+
same_count += 1
|
196
|
+
end
|
197
|
+
end
|
198
|
+
end
|
199
|
+
|
200
|
+
if same_count > 5
|
201
|
+
lost_point += (3 + same_count - 5)
|
202
|
+
end
|
203
|
+
end
|
204
|
+
end
|
205
|
+
|
206
|
+
# level 2
|
207
|
+
( 0...( module_count - 1 ) ).each do |row|
|
208
|
+
( 0...( module_count - 1 ) ).each do |col|
|
209
|
+
count = 0
|
210
|
+
count = count + 1 if qr_code.is_dark( row, col )
|
211
|
+
count = count + 1 if qr_code.is_dark( row + 1, col )
|
212
|
+
count = count + 1 if qr_code.is_dark( row, col + 1 )
|
213
|
+
count = count + 1 if qr_code.is_dark( row + 1, col + 1 )
|
214
|
+
lost_point = lost_point + 3 if (count == 0 || count == 4)
|
215
|
+
end
|
216
|
+
end
|
217
|
+
|
218
|
+
# level 3
|
219
|
+
( 0...module_count ).each do |row|
|
220
|
+
( 0...( module_count - 6 ) ).each do |col|
|
221
|
+
if qr_code.is_dark( row, col ) && !qr_code.is_dark( row, col + 1 ) && qr_code.is_dark( row, col + 2 ) && qr_code.is_dark( row, col + 3 ) && qr_code.is_dark( row, col + 4 ) && !qr_code.is_dark( row, col + 5 ) && qr_code.is_dark( row, col + 6 )
|
222
|
+
lost_point = lost_point + 40
|
223
|
+
end
|
224
|
+
end
|
225
|
+
end
|
226
|
+
|
227
|
+
( 0...module_count ).each do |col|
|
228
|
+
( 0...( module_count - 6 ) ).each do |row|
|
229
|
+
if qr_code.is_dark(row, col) && !qr_code.is_dark(row + 1, col) && qr_code.is_dark(row + 2, col) && qr_code.is_dark(row + 3, col) && qr_code.is_dark(row + 4, col) && !qr_code.is_dark(row + 5, col) && qr_code.is_dark(row + 6, col)
|
230
|
+
lost_point = lost_point + 40
|
231
|
+
end
|
232
|
+
end
|
233
|
+
end
|
234
|
+
|
235
|
+
# level 4
|
236
|
+
dark_count = 0
|
237
|
+
|
238
|
+
( 0...module_count ).each do |col|
|
239
|
+
( 0...module_count ).each do |row|
|
240
|
+
if qr_code.is_dark(row, col)
|
241
|
+
dark_count = dark_count + 1
|
242
|
+
end
|
243
|
+
end
|
244
|
+
end
|
245
|
+
|
246
|
+
ratio = (100 * dark_count / module_count / module_count - 50).abs / 5
|
247
|
+
lost_point = lost_point * 10
|
248
|
+
|
249
|
+
lost_point
|
250
|
+
end
|
251
|
+
|
252
|
+
end
|
253
|
+
|
254
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
#--
|
4
|
+
# Copyright 2008 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
|
+
require "rqrcode/core_ext"
|
13
|
+
require "rqrcode/qrcode"
|
@@ -0,0 +1,78 @@
|
|
1
|
+
require "test/unit"
|
2
|
+
require "lib/rqrcode"
|
3
|
+
|
4
|
+
class QRCodeTest < Test::Unit::TestCase
|
5
|
+
require "test/test_data"
|
6
|
+
|
7
|
+
def test_no_data_given
|
8
|
+
assert_raise(RQRCode::QRCodeArgumentError) {
|
9
|
+
RQRCode::QRCode.new( :size => 1, :level => :h )
|
10
|
+
RQRCode::QRCode.new( :size => 1 )
|
11
|
+
RQRCode::QRCode.new
|
12
|
+
}
|
13
|
+
assert_raise(RQRCode::QRCodeRunTimeError) {
|
14
|
+
qr = RQRCode::QRCode.new('duncan')
|
15
|
+
qr.is_dark(0,999999)
|
16
|
+
}
|
17
|
+
end
|
18
|
+
|
19
|
+
def test_H_
|
20
|
+
qr = RQRCode::QRCode.new( 'duncan', :size => 1 )
|
21
|
+
|
22
|
+
assert_equal qr.modules.size, 21
|
23
|
+
assert_equal qr.modules, MATRIX_1_H
|
24
|
+
|
25
|
+
qr = RQRCode::QRCode.new( 'duncan', :size => 1 )
|
26
|
+
assert_equal qr.modules, MATRIX_1_H
|
27
|
+
qr = RQRCode::QRCode.new( 'duncan', :size => 1, :level => :l )
|
28
|
+
assert_equal qr.modules, MATRIX_1_L
|
29
|
+
qr = RQRCode::QRCode.new( 'duncan', :size => 1, :level => :m )
|
30
|
+
assert_equal qr.modules, MATRIX_1_M
|
31
|
+
qr = RQRCode::QRCode.new( 'duncan', :size => 1, :level => :q )
|
32
|
+
assert_equal qr.modules, MATRIX_1_Q
|
33
|
+
end
|
34
|
+
|
35
|
+
def test_3_H_
|
36
|
+
qr = RQRCode::QRCode.new( 'duncan', :size => 3 )
|
37
|
+
|
38
|
+
assert_equal qr.modules.size, 29
|
39
|
+
assert_equal qr.modules, MATRIX_3_H
|
40
|
+
end
|
41
|
+
|
42
|
+
def test_5_H_
|
43
|
+
qr = RQRCode::QRCode.new( 'duncan', :size => 5 )
|
44
|
+
|
45
|
+
assert_equal qr.modules.size, 37
|
46
|
+
assert_equal qr.modules, MATRIX_5_H
|
47
|
+
end
|
48
|
+
|
49
|
+
def test_10_H_
|
50
|
+
qr = RQRCode::QRCode.new( 'duncan', :size => 10 )
|
51
|
+
|
52
|
+
assert_equal qr.modules.size, 57
|
53
|
+
assert_equal qr.modules, MATRIX_10_H
|
54
|
+
end
|
55
|
+
|
56
|
+
def test_4_H_
|
57
|
+
qr = RQRCode::QRCode.new('www.bbc.co.uk/programmes/b0090blw',
|
58
|
+
:level => :l )
|
59
|
+
assert_equal qr.modules, MATRIX_4_L
|
60
|
+
qr = RQRCode::QRCode.new('www.bbc.co.uk/programmes/b0090blw',
|
61
|
+
:level => :m )
|
62
|
+
assert_equal qr.modules, MATRIX_4_M
|
63
|
+
qr = RQRCode::QRCode.new('www.bbc.co.uk/programmes/b0090blw',
|
64
|
+
:level => :q )
|
65
|
+
assert_equal qr.modules, MATRIX_4_Q
|
66
|
+
|
67
|
+
qr = RQRCode::QRCode.new('www.bbc.co.uk/programmes/b0090blw')
|
68
|
+
assert_equal qr.modules.size, 33
|
69
|
+
assert_equal qr.modules, MATRIX_4_H
|
70
|
+
end
|
71
|
+
|
72
|
+
def test_to_s
|
73
|
+
qr = RQRCode::QRCode.new( 'duncan', :size => 1 )
|
74
|
+
assert_equal qr.to_s[0..21], "xxxxxxx xx x xxxxxxx\n"
|
75
|
+
assert_equal qr.to_s( :true => 'q', :false => 'n' )[0..21], "qqqqqqqnqqnqnnqqqqqqq\n"
|
76
|
+
assert_equal qr.to_s( :true => '@' )[0..21], "@@@@@@@ @@ @ @@@@@@@\n"
|
77
|
+
end
|
78
|
+
end
|