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,421 @@
|
|
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
|
+
module RQRCode #:nodoc:
|
13
|
+
|
14
|
+
QRMODE = {
|
15
|
+
:mode_number => 1 << 0,
|
16
|
+
:mode_alpha_numk => 1 << 1,
|
17
|
+
:mode_8bit_byte => 1 << 2,
|
18
|
+
:mode_kanji => 1 << 3
|
19
|
+
}
|
20
|
+
|
21
|
+
QRERRORCORRECTLEVEL = {
|
22
|
+
:l => 1,
|
23
|
+
:m => 0,
|
24
|
+
:q => 3,
|
25
|
+
:h => 2
|
26
|
+
}
|
27
|
+
|
28
|
+
QRMASKPATTERN = {
|
29
|
+
:pattern000 => 0,
|
30
|
+
:pattern001 => 1,
|
31
|
+
:pattern010 => 2,
|
32
|
+
:pattern011 => 3,
|
33
|
+
:pattern100 => 4,
|
34
|
+
:pattern101 => 5,
|
35
|
+
:pattern110 => 6,
|
36
|
+
:pattern111 => 7
|
37
|
+
}
|
38
|
+
|
39
|
+
# StandardErrors
|
40
|
+
|
41
|
+
class QRCodeArgumentError < ArgumentError; end
|
42
|
+
class QRCodeRunTimeError < RuntimeError; end
|
43
|
+
|
44
|
+
# == Creation
|
45
|
+
#
|
46
|
+
# QRCode objects expect only one required constructor parameter
|
47
|
+
# and an optional hash of any other. Here's a few examples:
|
48
|
+
#
|
49
|
+
# qr = RQRCode::QRCode.new('hello world')
|
50
|
+
# qr = RQRCode::QRCode.new('hello world', :size => 1, :level => :m )
|
51
|
+
#
|
52
|
+
|
53
|
+
class QRCode
|
54
|
+
attr_reader :modules, :module_count
|
55
|
+
|
56
|
+
PAD0 = 0xEC
|
57
|
+
PAD1 = 0x11
|
58
|
+
|
59
|
+
# Expects a string to be parsed in, other args are optional
|
60
|
+
#
|
61
|
+
# # string - the string you wish to encode
|
62
|
+
# # size - the size of the qrcode (default 4)
|
63
|
+
# # level - the error correction level, can be:
|
64
|
+
# * Level :l 7% of code can be restored
|
65
|
+
# * Level :m 15% of code can be restored
|
66
|
+
# * Level :q 25% of code can be restored
|
67
|
+
# * Level :h 30% of code can be restored (default :h)
|
68
|
+
#
|
69
|
+
# qr = RQRCode::QRCode.new('hello world', :size => 1, :level => :m )
|
70
|
+
#
|
71
|
+
|
72
|
+
def initialize( *args )
|
73
|
+
raise QRCodeArgumentError unless args.first.kind_of?( String )
|
74
|
+
|
75
|
+
@data = args.shift
|
76
|
+
options = args.extract_options!
|
77
|
+
level = options[:level] || :h
|
78
|
+
@error_correct_level = QRERRORCORRECTLEVEL[ level.to_sym ]
|
79
|
+
@type_number = options[:size] || 4
|
80
|
+
@module_count = @type_number * 4 + 17
|
81
|
+
@modules = nil
|
82
|
+
@data_cache = nil
|
83
|
+
@data_list = QR8bitByte.new( @data )
|
84
|
+
|
85
|
+
self.make
|
86
|
+
end
|
87
|
+
|
88
|
+
# <tt>is_dark</tt> is called with a +col+ and +row+ parameter. This will
|
89
|
+
# return true or false based on whether that coordinate exists in the
|
90
|
+
# matrix returned. It would normally be called while iterating through
|
91
|
+
# <tt>modules</tt>. A simple example would be:
|
92
|
+
#
|
93
|
+
# instance.is_dark( 10, 10 ) => true
|
94
|
+
#
|
95
|
+
|
96
|
+
def is_dark( row, col )
|
97
|
+
if row < 0 || @module_count <= row || col < 0 || @module_count <= col
|
98
|
+
raise QRCodeRunTimeError, "#{row},#{col}"
|
99
|
+
end
|
100
|
+
@modules[row][col]
|
101
|
+
end
|
102
|
+
|
103
|
+
# This is a public method that returns the QR Code you have
|
104
|
+
# generated as a string. It will not be able to be read
|
105
|
+
# in this format by a QR Code reader, but will give you an
|
106
|
+
# idea if the final outout. It takes two optional args
|
107
|
+
# +:true+ and +:false+ which are there for you to choose
|
108
|
+
# how the output looks. Here's an example of it's use:
|
109
|
+
#
|
110
|
+
# instance.to_s =>
|
111
|
+
# xxxxxxx x x x x x xx xxxxxxx
|
112
|
+
# x x xxx xxxxxx xxx x x
|
113
|
+
# x xxx x xxxxx x xx x xxx x
|
114
|
+
#
|
115
|
+
# instance._to_s( :true => 'E', :false => 'Q') =>
|
116
|
+
# EEEEEEEQEQQEQEQQQEQEQQEEQQEEEEEEE
|
117
|
+
# EQQQQQEQQEEEQQEEEEEEQEEEQQEQQQQQE
|
118
|
+
# EQEEEQEQQEEEEEQEQQQQQQQEEQEQEEEQE
|
119
|
+
#
|
120
|
+
|
121
|
+
def to_s( *args )
|
122
|
+
options = args.extract_options!
|
123
|
+
row = options[:true] || 'x'
|
124
|
+
col = options[:false] || ' '
|
125
|
+
|
126
|
+
res = []
|
127
|
+
|
128
|
+
@modules.each_index do |c|
|
129
|
+
tmp = []
|
130
|
+
@modules.each_index do |r|
|
131
|
+
if is_dark(c,r)
|
132
|
+
tmp << row
|
133
|
+
else
|
134
|
+
tmp << col
|
135
|
+
end
|
136
|
+
end
|
137
|
+
res << tmp.join
|
138
|
+
end
|
139
|
+
res.join("\n")
|
140
|
+
end
|
141
|
+
|
142
|
+
protected
|
143
|
+
|
144
|
+
def make #:nodoc:
|
145
|
+
make_impl( false, get_best_mask_pattern )
|
146
|
+
end
|
147
|
+
|
148
|
+
private
|
149
|
+
|
150
|
+
|
151
|
+
def make_impl( test, mask_pattern ) #:nodoc:
|
152
|
+
@modules = Array.new( @module_count )
|
153
|
+
|
154
|
+
( 0...@module_count ).each do |row|
|
155
|
+
@modules[row] = Array.new( @module_count )
|
156
|
+
end
|
157
|
+
|
158
|
+
setup_position_probe_pattern( 0, 0 )
|
159
|
+
setup_position_probe_pattern( @module_count - 7, 0 )
|
160
|
+
setup_position_probe_pattern( 0, @module_count - 7 )
|
161
|
+
setup_position_adjust_pattern
|
162
|
+
setup_timing_pattern
|
163
|
+
setup_type_info( test, mask_pattern )
|
164
|
+
setup_type_number( test ) if @type_number >= 7
|
165
|
+
|
166
|
+
if @data_cache.nil?
|
167
|
+
@data_cache = QRCode.create_data(
|
168
|
+
@type_number, @error_correct_level, @data_list
|
169
|
+
)
|
170
|
+
end
|
171
|
+
|
172
|
+
map_data( @data_cache, mask_pattern )
|
173
|
+
end
|
174
|
+
|
175
|
+
|
176
|
+
def setup_position_probe_pattern( row, col ) #:nodoc:
|
177
|
+
( -1..7 ).each do |r|
|
178
|
+
next if ( row + r ) <= -1 || @module_count <= ( row + r )
|
179
|
+
( -1..7 ).each do |c|
|
180
|
+
next if ( col + c ) <= -1 || @module_count <= ( col + c )
|
181
|
+
if 0 <= r && r <= 6 && ( c == 0 || c == 6 ) || 0 <= c && c <= 6 && ( r == 0 || r == 6 ) || 2 <= r && r <= 4 && 2 <= c && c <= 4
|
182
|
+
@modules[row + r][col + c] = true;
|
183
|
+
else
|
184
|
+
@modules[row + r][col + c] = false;
|
185
|
+
end
|
186
|
+
end
|
187
|
+
end
|
188
|
+
end
|
189
|
+
|
190
|
+
|
191
|
+
def get_best_mask_pattern #:nodoc:
|
192
|
+
min_lost_point = 0
|
193
|
+
pattern = 0
|
194
|
+
|
195
|
+
( 0...8 ).each do |i|
|
196
|
+
make_impl( true, i )
|
197
|
+
lost_point = QRUtil.get_lost_point( self )
|
198
|
+
|
199
|
+
if i == 0 || min_lost_point > lost_point
|
200
|
+
min_lost_point = lost_point
|
201
|
+
pattern = i
|
202
|
+
end
|
203
|
+
end
|
204
|
+
pattern
|
205
|
+
end
|
206
|
+
|
207
|
+
|
208
|
+
def setup_timing_pattern #:nodoc:
|
209
|
+
( 8...@module_count - 8 ).each do |i|
|
210
|
+
@modules[i][6] = @modules[6][i] = i % 2 == 0
|
211
|
+
end
|
212
|
+
end
|
213
|
+
|
214
|
+
|
215
|
+
def setup_position_adjust_pattern #:nodoc:
|
216
|
+
pos = QRUtil.get_pattern_position(@type_number)
|
217
|
+
|
218
|
+
( 0...pos.size ).each do |i|
|
219
|
+
( 0...pos.size ).each do |j|
|
220
|
+
row = pos[i]
|
221
|
+
col = pos[j]
|
222
|
+
|
223
|
+
next unless @modules[row][col].nil?
|
224
|
+
|
225
|
+
( -2..2 ).each do |r|
|
226
|
+
( -2..2 ).each do |c|
|
227
|
+
if r == -2 || r == 2 || c == -2 || c == 2 || ( r == 0 && c == 0 )
|
228
|
+
@modules[row + r][col + c] = true
|
229
|
+
else
|
230
|
+
@modules[row + r][col + c] = false
|
231
|
+
end
|
232
|
+
end
|
233
|
+
end
|
234
|
+
end
|
235
|
+
end
|
236
|
+
end
|
237
|
+
|
238
|
+
|
239
|
+
def setup_type_number( test ) #:nodoc:
|
240
|
+
bits = QRUtil.get_bch_type_number( @type_number )
|
241
|
+
|
242
|
+
( 0...18 ).each do |i|
|
243
|
+
mod = ( !test && ( (bits >> i) & 1) == 1 )
|
244
|
+
@modules[ (i / 3).floor ][ i % 3 + @module_count - 8 - 3 ] = mod
|
245
|
+
@modules[ i % 3 + @module_count - 8 - 3 ][ (i / 3).floor ] = mod
|
246
|
+
end
|
247
|
+
end
|
248
|
+
|
249
|
+
|
250
|
+
def setup_type_info( test, mask_pattern ) #:nodoc:
|
251
|
+
data = (@error_correct_level << 3 | mask_pattern)
|
252
|
+
bits = QRUtil.get_bch_type_info( data )
|
253
|
+
|
254
|
+
( 0...15 ).each do |i|
|
255
|
+
mod = (!test && ( (bits >> i) & 1) == 1)
|
256
|
+
|
257
|
+
# vertical
|
258
|
+
if i < 6
|
259
|
+
@modules[i][8] = mod
|
260
|
+
elsif i < 8
|
261
|
+
@modules[ i + 1 ][8] = mod
|
262
|
+
else
|
263
|
+
@modules[ @module_count - 15 + i ][8] = mod
|
264
|
+
end
|
265
|
+
|
266
|
+
# horizontal
|
267
|
+
if i < 8
|
268
|
+
@modules[8][ @module_count - i - 1 ] = mod
|
269
|
+
elsif i < 9
|
270
|
+
@modules[8][ 15 - i - 1 + 1 ] = mod
|
271
|
+
else
|
272
|
+
@modules[8][ 15 - i - 1 ] = mod
|
273
|
+
end
|
274
|
+
end
|
275
|
+
|
276
|
+
# fixed module
|
277
|
+
@modules[ @module_count - 8 ][8] = !test
|
278
|
+
end
|
279
|
+
|
280
|
+
|
281
|
+
def map_data( data, mask_pattern ) #:nodoc:
|
282
|
+
inc = -1
|
283
|
+
row = @module_count - 1
|
284
|
+
bit_index = 7
|
285
|
+
byte_index = 0
|
286
|
+
|
287
|
+
( @module_count - 1 ).step( 1, -2 ) do |col|
|
288
|
+
col = col - 1 if col <= 6
|
289
|
+
|
290
|
+
while true do
|
291
|
+
( 0...2 ).each do |c|
|
292
|
+
|
293
|
+
if @modules[row][ col - c ].nil?
|
294
|
+
dark = false
|
295
|
+
if byte_index < data.size
|
296
|
+
dark = (( (data[byte_index]).rszf( bit_index ) & 1) == 1 )
|
297
|
+
end
|
298
|
+
mask = QRUtil.get_mask( mask_pattern, row, col - c )
|
299
|
+
dark = !dark if mask
|
300
|
+
@modules[row][ col - c ] = dark
|
301
|
+
bit_index -= 1
|
302
|
+
|
303
|
+
if bit_index == -1
|
304
|
+
byte_index += 1
|
305
|
+
bit_index = 7
|
306
|
+
end
|
307
|
+
end
|
308
|
+
end
|
309
|
+
|
310
|
+
row += inc
|
311
|
+
|
312
|
+
if row < 0 || @module_count <= row
|
313
|
+
row -= inc
|
314
|
+
inc = -inc
|
315
|
+
break
|
316
|
+
end
|
317
|
+
end
|
318
|
+
end
|
319
|
+
end
|
320
|
+
|
321
|
+
def QRCode.create_data( type_number, error_correct_level, data_list ) #:nodoc:
|
322
|
+
rs_blocks = QRRSBlock.get_rs_blocks( type_number, error_correct_level )
|
323
|
+
buffer = QRBitBuffer.new
|
324
|
+
|
325
|
+
data = data_list
|
326
|
+
buffer.put( data.mode, 4 )
|
327
|
+
buffer.put(
|
328
|
+
data.get_length, QRUtil.get_length_in_bits( data.mode, type_number )
|
329
|
+
)
|
330
|
+
data.write( buffer )
|
331
|
+
|
332
|
+
total_data_count = 0
|
333
|
+
( 0...rs_blocks.size ).each do |i|
|
334
|
+
total_data_count = total_data_count + rs_blocks[i].data_count
|
335
|
+
end
|
336
|
+
|
337
|
+
if buffer.get_length_in_bits > total_data_count * 8
|
338
|
+
raise QRCodeRunTimeError,
|
339
|
+
"code length overflow. (#{buffer.get_length_in_bits}>#{total_data_count})"
|
340
|
+
end
|
341
|
+
|
342
|
+
if buffer.get_length_in_bits + 4 <= total_data_count * 8
|
343
|
+
buffer.put( 0, 4 )
|
344
|
+
end
|
345
|
+
|
346
|
+
while buffer.get_length_in_bits % 8 != 0
|
347
|
+
buffer.put_bit( false )
|
348
|
+
end
|
349
|
+
|
350
|
+
while true
|
351
|
+
break if buffer.get_length_in_bits >= total_data_count * 8
|
352
|
+
buffer.put( QRCode::PAD0, 8 )
|
353
|
+
break if buffer.get_length_in_bits >= total_data_count * 8
|
354
|
+
buffer.put( QRCode::PAD1, 8 )
|
355
|
+
end
|
356
|
+
|
357
|
+
QRCode.create_bytes( buffer, rs_blocks )
|
358
|
+
end
|
359
|
+
|
360
|
+
|
361
|
+
def QRCode.create_bytes( buffer, rs_blocks ) #:nodoc:
|
362
|
+
offset = 0
|
363
|
+
max_dc_count = 0
|
364
|
+
max_ec_count = 0
|
365
|
+
dcdata = Array.new( rs_blocks.size )
|
366
|
+
ecdata = Array.new( rs_blocks.size )
|
367
|
+
|
368
|
+
( 0...rs_blocks.size ).each do |r|
|
369
|
+
dc_count = rs_blocks[r].data_count
|
370
|
+
ec_count = rs_blocks[r].total_count - dc_count
|
371
|
+
max_dc_count = [ max_dc_count, dc_count ].max
|
372
|
+
max_ec_count = [ max_ec_count, ec_count ].max
|
373
|
+
dcdata[r] = Array.new( dc_count )
|
374
|
+
|
375
|
+
( 0...dcdata[r].size ).each do |i|
|
376
|
+
dcdata[r][i] = 0xff & buffer.buffer[ i + offset ]
|
377
|
+
end
|
378
|
+
|
379
|
+
offset = offset + dc_count
|
380
|
+
rs_poly = QRUtil.get_error_correct_polynomial( ec_count )
|
381
|
+
raw_poly = QRPolynomial.new( dcdata[r], rs_poly.get_length - 1 )
|
382
|
+
mod_poly = raw_poly.mod( rs_poly )
|
383
|
+
ecdata[r] = Array.new( rs_poly.get_length - 1 )
|
384
|
+
( 0...ecdata[r].size ).each do |i|
|
385
|
+
mod_index = i + mod_poly.get_length - ecdata[r].size
|
386
|
+
ecdata[r][i] = mod_index >= 0 ? mod_poly.get( mod_index ) : 0
|
387
|
+
end
|
388
|
+
end
|
389
|
+
|
390
|
+
total_code_count = 0
|
391
|
+
( 0...rs_blocks.size ).each do |i|
|
392
|
+
total_code_count = total_code_count + rs_blocks[i].total_count
|
393
|
+
end
|
394
|
+
|
395
|
+
data = Array.new( total_code_count )
|
396
|
+
index = 0
|
397
|
+
|
398
|
+
( 0...max_dc_count ).each do |i|
|
399
|
+
( 0...rs_blocks.size ).each do |r|
|
400
|
+
if i < dcdata[r].size
|
401
|
+
index += 1
|
402
|
+
data[index-1] = dcdata[r][i]
|
403
|
+
end
|
404
|
+
end
|
405
|
+
end
|
406
|
+
|
407
|
+
( 0...max_ec_count ).each do |i|
|
408
|
+
( 0...rs_blocks.size ).each do |r|
|
409
|
+
if i < ecdata[r].size
|
410
|
+
index += 1
|
411
|
+
data[index-1] = ecdata[r][i]
|
412
|
+
end
|
413
|
+
end
|
414
|
+
end
|
415
|
+
|
416
|
+
data
|
417
|
+
end
|
418
|
+
|
419
|
+
end
|
420
|
+
|
421
|
+
end
|
@@ -0,0 +1,63 @@
|
|
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 QRMath
|
15
|
+
|
16
|
+
module_eval {
|
17
|
+
exp_table = Array.new(256)
|
18
|
+
log_table = Array.new(256)
|
19
|
+
|
20
|
+
( 0...8 ).each do |i|
|
21
|
+
exp_table[i] = 1 << i
|
22
|
+
end
|
23
|
+
|
24
|
+
( 8...256 ).each do |i|
|
25
|
+
exp_table[i] = exp_table[i - 4] \
|
26
|
+
^ exp_table[i - 5] \
|
27
|
+
^ exp_table[i - 6] \
|
28
|
+
^ exp_table[i - 8]
|
29
|
+
end
|
30
|
+
|
31
|
+
( 0...255 ).each do |i|
|
32
|
+
log_table[exp_table[i] ] = i
|
33
|
+
end
|
34
|
+
|
35
|
+
EXP_TABLE = exp_table
|
36
|
+
LOG_TABLE = log_table
|
37
|
+
}
|
38
|
+
|
39
|
+
class << self
|
40
|
+
|
41
|
+
def glog(n)
|
42
|
+
raise QRCodeRunTimeError, "glog(#{n})" if ( n < 1 )
|
43
|
+
LOG_TABLE[n]
|
44
|
+
end
|
45
|
+
|
46
|
+
|
47
|
+
def gexp(n)
|
48
|
+
while n < 0
|
49
|
+
n = n + 255
|
50
|
+
end
|
51
|
+
|
52
|
+
while n >= 256
|
53
|
+
n = n - 255
|
54
|
+
end
|
55
|
+
|
56
|
+
EXP_TABLE[n]
|
57
|
+
end
|
58
|
+
|
59
|
+
end
|
60
|
+
|
61
|
+
end
|
62
|
+
|
63
|
+
end
|
@@ -0,0 +1,78 @@
|
|
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
|