rqr 0.2.0-x86-mswin32

Sign up to get free protection for your applications and to get access to all the features.
data/History.txt ADDED
@@ -0,0 +1,13 @@
1
+ == 0.2.0 2008-08-13
2
+
3
+ * Added win32 package
4
+ * macport available (alpha)
5
+
6
+ == 0.1.1 2008-05-26
7
+
8
+ * Update API.
9
+
10
+ == 0.1.0 2008-05-23
11
+
12
+ * 1 major enhancement:
13
+ * Initial release
data/License.txt ADDED
@@ -0,0 +1,23 @@
1
+ Note: Original QR_Encode.h and QR_Encode.cpp are free license. (by Psytec Inc)
2
+
3
+ Copyright (c) 2008 Ryota Maruko, Keiko Soezima
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23
+
data/Manifest.txt ADDED
@@ -0,0 +1,30 @@
1
+ History.txt
2
+ License.txt
3
+ Manifest.txt
4
+ README.txt
5
+ Rakefile
6
+ config/hoe.rb
7
+ config/requirements.rb
8
+ ext/rqr/QR_Encode.cpp
9
+ ext/rqr/QR_Encode.h
10
+ ext/rqr/extconf.rb
11
+ ext/rqr/qr.i
12
+ ext/rqr/qr_draw.h
13
+ ext/rqr/qr_draw_jpeg.cpp
14
+ ext/rqr/qr_draw_jpeg.h
15
+ ext/rqr/qr_draw_png.cpp
16
+ ext/rqr/qr_draw_png.h
17
+ ext/rqr/qr_draw_ps.cpp
18
+ ext/rqr/qr_draw_ps.h
19
+ ext/rqr/qr_draw_tiff.cpp
20
+ ext/rqr/qr_draw_tiff.h
21
+ ext/rqr/qr_wrap.cxx
22
+ ext/rqr/win2ansi.h
23
+ lib/rqr.rb
24
+ lib/rqr/QR.so
25
+ lib/rqr/errors.rb
26
+ lib/rqr/qrcode.rb
27
+ lib/rqr/version.rb
28
+ setup.rb
29
+ test/test_helper.rb
30
+ test/test_rqr.rb
data/README.txt ADDED
@@ -0,0 +1,83 @@
1
+ == rqr
2
+
3
+ * http://rubyforge.org/projects/rqr/
4
+
5
+ == DESCRIPTION:
6
+
7
+ A ruby library to create QR code image. Output: PS, JPEG, PNG, EPS, TIFF.
8
+
9
+ == SYNOPSIS:
10
+
11
+ require "rubygem"
12
+ require "rqrcode"
13
+
14
+ qr = RQR::QRCode.new()
15
+
16
+ #Define a file format with extensions.
17
+ qr.save("http://www.google.com", "path/to/qrcode.jpg")
18
+
19
+ #Define a file format with symbol.
20
+ qr.save("http://www.yahoo.com", "path/to/qrcodefile", :png)
21
+
22
+
23
+ #QRCode options
24
+ #Use options with hash values.
25
+ #:level L:0, M:1(default), Q:2, H:3
26
+ #:version S:0(default), M:1, L:2
27
+ #:auto_extent true|false auto extent if over version size
28
+ #:masking masking pattern 0-7, -1(default auto)
29
+ #:length data length
30
+ #:module_size module size (pixel)
31
+ #:eps_preview true|false
32
+
33
+ #This sample creates a EPS with preview.
34
+ qr = QRCode.new(:eps_preview => true, :auto_extent=false)
35
+ qr.save("http://www.ebay.com", "path/to/qrcode.eps")
36
+
37
+ == REQUIREMENTS:
38
+
39
+ * libjpeg
40
+ * libpng
41
+ * libtiff
42
+
43
+ == Note:
44
+ If using OSX, Use Fink(http://www.finkproject.org) Universal Binary libs.
45
+ * sudo fink install libjpeg
46
+ * sudo fink install libpng
47
+ * sudo fink install libtiff
48
+
49
+ or use MacPorts (http://www.macports.com)
50
+ * sudo port install jpeg
51
+ * sudo port install libpng
52
+ * sudo port install tiff
53
+
54
+
55
+ == INSTALL:
56
+
57
+ * sudo gem install rqr
58
+
59
+
60
+ == LICENSE:
61
+
62
+ (The MIT License)
63
+
64
+ Copyright (c) 2008 Ryota Maruko, Keiko Soezima
65
+
66
+ Permission is hereby granted, free of charge, to any person obtaining
67
+ a copy of this software and associated documentation files (the
68
+ 'Software'), to deal in the Software without restriction, including
69
+ without limitation the rights to use, copy, modify, merge, publish,
70
+ distribute, sublicense, and/or sell copies of the Software, and to
71
+ permit persons to whom the Software is furnished to do so, subject to
72
+ the following conditions:
73
+
74
+ The above copyright notice and this permission notice shall be
75
+ included in all copies or substantial portions of the Software.
76
+
77
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
78
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
79
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
80
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
81
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
82
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
83
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Rakefile ADDED
@@ -0,0 +1,5 @@
1
+ PACKAGE_PLATFORM = (ARGV[0] =~ /mswin32$/) ? 'mswin32' : RUBY_PLATFORM
2
+ require 'config/requirements'
3
+ require 'config/hoe' # setup Hoe + all gem configuration
4
+
5
+ Dir['tasks/**/*.rake'].each { |rake| load rake }
data/config/hoe.rb ADDED
@@ -0,0 +1,87 @@
1
+ require 'rqr/version'
2
+
3
+ AUTHOR = 'Ryota Maruko' # can also be an array of Authors
4
+ EMAIL = "pools _at_ rubyforge _dot_ org"
5
+ DESCRIPTION = "A ruby library to create qrcode. Output: PS, JPEG, PNG, EPS, TIFF."
6
+ GEM_NAME = 'rqr' # what ppl will type to install your gem
7
+ RUBYFORGE_PROJECT = 'rqr' # The unix name for your project
8
+ HOMEPATH = "http://#{RUBYFORGE_PROJECT}.rubyforge.org"
9
+ DOWNLOAD_PATH = "http://rubyforge.org/projects/#{RUBYFORGE_PROJECT}"
10
+
11
+ @config_file = "~/.rubyforge/user-config.yml"
12
+ @config = nil
13
+ RUBYFORGE_USERNAME = "unknown"
14
+ def rubyforge_username
15
+ unless @config
16
+ begin
17
+ @config = YAML.load(File.read(File.expand_path(@config_file)))
18
+ rescue
19
+ puts <<-EOS
20
+ ERROR: No rubyforge config file found: #{@config_file}
21
+ Run 'rubyforge setup' to prepare your env for access to Rubyforge
22
+ - See http://newgem.rubyforge.org/rubyforge.html for more details
23
+ EOS
24
+ exit
25
+ end
26
+ end
27
+ RUBYFORGE_USERNAME.replace @config["username"]
28
+ end
29
+
30
+
31
+ REV = nil
32
+ # UNCOMMENT IF REQUIRED:
33
+ # REV = `svn info`.each {|line| if line =~ /^Revision:/ then k,v = line.split(': '); break v.chomp; else next; end} rescue nil
34
+ VERS = Rqr::VERSION::STRING + (REV ? ".#{REV}" : "")
35
+ RDOC_OPTS = ['--quiet', '--title', 'rqr documentation',
36
+ "--opname", "index.html",
37
+ "--line-numbers",
38
+ "--main", "README",
39
+ "--inline-source"]
40
+
41
+ class Hoe
42
+ def extra_deps
43
+ @extra_deps.reject! { |x| Array(x).first == 'hoe' }
44
+ @extra_deps
45
+ end
46
+
47
+ def spec= s
48
+
49
+ if PACKAGE_PLATFORM =~ /mswin32/
50
+ s.files = s.files.reject! {|f| f =~ /extconf\.rb/ }
51
+ else
52
+ s.files = s.files.reject! {|f| f =~ /QR\.so/ }
53
+ end
54
+ @spec = s
55
+ end
56
+
57
+ end
58
+
59
+ # Generate all the Rake tasks
60
+ # Run 'rake -T' to see list of generated tasks (from gem root directory)
61
+ $hoe = Hoe.new(GEM_NAME, VERS) do |p|
62
+ p.developer(AUTHOR, EMAIL)
63
+ p.description = DESCRIPTION
64
+ p.summary = DESCRIPTION
65
+ p.url = HOMEPATH
66
+ p.rubyforge_name = RUBYFORGE_PROJECT if RUBYFORGE_PROJECT
67
+ p.test_globs = ["test/**/test_*.rb"]
68
+ p.clean_globs |= ['**/.*.sw?', '*.gem', '.config', '**/.DS_Store'] #An array of file patterns to delete on clean.
69
+
70
+ # == Optional
71
+ p.changes = p.paragraphs_of("History.txt", 0..1).join("\n\n")
72
+ #p.extra_deps = [] # An array of rubygem dependencies [name, version], e.g. [ ['active_support', '>= 1.3.1'] ]
73
+
74
+ #p.spec_extras = {} # A hash of extra values to set in the gemspec.
75
+ if PACKAGE_PLATFORM =~ /mswin32/
76
+ platform = Gem::Platform.respond_to?(:new) ? Gem::Platform.new('mswin32') : Gem::Platform::WIN32
77
+ p.spec_extras[:platform] = platform
78
+ else
79
+ p.spec_extras[:extensions] = ['ext/rqr/extconf.rb']
80
+ end
81
+
82
+ end
83
+
84
+ CHANGES = $hoe.paragraphs_of('History.txt', 0..1).join("\\n\\n")
85
+ PATH = (RUBYFORGE_PROJECT == GEM_NAME) ? RUBYFORGE_PROJECT : "#{RUBYFORGE_PROJECT}/#{GEM_NAME}"
86
+ $hoe.remote_rdoc_dir = File.join(PATH.gsub(/^#{RUBYFORGE_PROJECT}\/?/,''), 'rdoc')
87
+ $hoe.rsync_args = '-av --delete --ignore-errors'
@@ -0,0 +1,15 @@
1
+ require 'fileutils'
2
+ include FileUtils
3
+
4
+ require 'rubygems'
5
+ %w[rake hoe newgem rubigen].each do |req_gem|
6
+ begin
7
+ require req_gem
8
+ rescue LoadError
9
+ puts "This Rakefile requires the '#{req_gem}' RubyGem."
10
+ puts "Installation: gem install #{req_gem} -y"
11
+ exit
12
+ end
13
+ end
14
+
15
+ $:.unshift(File.join(File.dirname(__FILE__), %w[.. lib]))
@@ -0,0 +1,1949 @@
1
+ //// QR_Encode.cpp : CQR_Encode �N���X �C���v�������e�[�V���� �t�@�C��
2
+ //// Date 2006/05/17 Ver. 1.12 [Class Ver.1.21] Psytec Inc.
3
+ //
4
+ //#include "stdafx.h"
5
+ #include "QR_Encode.h"
6
+
7
+ //#ifdef _DEBUG
8
+ //#define new DEBUG_NEW
9
+ //#undef THIS_FILE
10
+ //static char THIS_FILE[] = __FILE__;
11
+ //#endif
12
+
13
+ /////////////////////////////////////////////////////////////////////////////
14
+ // QR�R�[�h�o�[�W����(�^��)���
15
+ static QR_VERSIONINFO QR_VersonInfo[] = {{0}, // (�_�~�[:Ver.0)
16
+ { 1, // Ver.1
17
+ 26, 19, 16, 13, 9,
18
+ 0, 0, 0, 0, 0, 0, 0,
19
+ 1, 26, 19,
20
+ 1, 26, 16,
21
+ 1, 26, 13,
22
+ 1, 26, 9,
23
+ 0, 0, 0,
24
+ 0, 0, 0,
25
+ 0, 0, 0,
26
+ 0, 0, 0},
27
+ { 2, // Ver.2
28
+ 44, 34, 28, 22, 16,
29
+ 1, 18, 0, 0, 0, 0, 0,
30
+ 1, 44, 34,
31
+ 1, 44, 28,
32
+ 1, 44, 22,
33
+ 1, 44, 16,
34
+ 0, 0, 0,
35
+ 0, 0, 0,
36
+ 0, 0, 0,
37
+ 0, 0, 0},
38
+ { 3, // Ver.3
39
+ 70, 55, 44, 34, 26,
40
+ 1, 22, 0, 0, 0, 0, 0,
41
+ 1, 70, 55,
42
+ 1, 70, 44,
43
+ 2, 35, 17,
44
+ 2, 35, 13,
45
+ 0, 0, 0,
46
+ 0, 0, 0,
47
+ 0, 0, 0,
48
+ 0, 0, 0},
49
+ { 4, // Ver.4
50
+ 100, 80, 64, 48, 36,
51
+ 1, 26, 0, 0, 0, 0, 0,
52
+ 1, 100, 80,
53
+ 2, 50, 32,
54
+ 2, 50, 24,
55
+ 4, 25, 9,
56
+ 0, 0, 0,
57
+ 0, 0, 0,
58
+ 0, 0, 0,
59
+ 0, 0, 0},
60
+ { 5, // Ver.5
61
+ 134, 108, 86, 62, 46,
62
+ 1, 30, 0, 0, 0, 0, 0,
63
+ 1, 134, 108,
64
+ 2, 67, 43,
65
+ 2, 33, 15,
66
+ 2, 33, 11,
67
+ 0, 0, 0,
68
+ 0, 0, 0,
69
+ 2, 34, 16,
70
+ 2, 34, 12},
71
+ { 6, // Ver.6
72
+ 172, 136, 108, 76, 60,
73
+ 1, 34, 0, 0, 0, 0, 0,
74
+ 2, 86, 68,
75
+ 4, 43, 27,
76
+ 4, 43, 19,
77
+ 4, 43, 15,
78
+ 0, 0, 0,
79
+ 0, 0, 0,
80
+ 0, 0, 0,
81
+ 0, 0, 0},
82
+ { 7, // Ver.7
83
+ 196, 156, 124, 88, 66,
84
+ 2, 22, 38, 0, 0, 0, 0,
85
+ 2, 98, 78,
86
+ 4, 49, 31,
87
+ 2, 32, 14,
88
+ 4, 39, 13,
89
+ 0, 0, 0,
90
+ 0, 0, 0,
91
+ 4, 33, 15,
92
+ 1, 40, 14},
93
+ { 8, // Ver.8
94
+ 242, 194, 154, 110, 86,
95
+ 2, 24, 42, 0, 0, 0, 0,
96
+ 2, 121, 97,
97
+ 2, 60, 38,
98
+ 4, 40, 18,
99
+ 4, 40, 14,
100
+ 0, 0, 0,
101
+ 2, 61, 39,
102
+ 2, 41, 19,
103
+ 2, 41, 15},
104
+ { 9, // Ver.9
105
+ 292, 232, 182, 132, 100,
106
+ 2, 26, 46, 0, 0, 0, 0,
107
+ 2, 146, 116,
108
+ 3, 58, 36,
109
+ 4, 36, 16,
110
+ 4, 36, 12,
111
+ 0, 0, 0,
112
+ 2, 59, 37,
113
+ 4, 37, 17,
114
+ 4, 37, 13},
115
+ {10, // Ver.10
116
+ 346, 274, 216, 154, 122,
117
+ 2, 28, 50, 0, 0, 0, 0,
118
+ 2, 86, 68,
119
+ 4, 69, 43,
120
+ 6, 43, 19,
121
+ 6, 43, 15,
122
+ 2, 87, 69,
123
+ 1, 70, 44,
124
+ 2, 44, 20,
125
+ 2, 44, 16},
126
+ {11, // Ver.11
127
+ 404, 324, 254, 180, 140,
128
+ 2, 30, 54, 0, 0, 0, 0,
129
+ 4, 101, 81,
130
+ 1, 80, 50,
131
+ 4, 50, 22,
132
+ 3, 36, 12,
133
+ 0, 0, 0,
134
+ 4, 81, 51,
135
+ 4, 51, 23,
136
+ 8, 37, 13},
137
+ {12, // Ver.12
138
+ 466, 370, 290, 206, 158,
139
+ 2, 32, 58, 0, 0, 0, 0,
140
+ 2, 116, 92,
141
+ 6, 58, 36,
142
+ 4, 46, 20,
143
+ 7, 42, 14,
144
+ 2, 117, 93,
145
+ 2, 59, 37,
146
+ 6, 47, 21,
147
+ 4, 43, 15},
148
+ {13, // Ver.13
149
+ 532, 428, 334, 244, 180,
150
+ 2, 34, 62, 0, 0, 0, 0,
151
+ 4, 133, 107,
152
+ 8, 59, 37,
153
+ 8, 44, 20,
154
+ 12, 33, 11,
155
+ 0, 0, 0,
156
+ 1, 60, 38,
157
+ 4, 45, 21,
158
+ 4, 34, 12},
159
+ {14, // Ver.14
160
+ 581, 461, 365, 261, 197,
161
+ 3, 26, 46, 66, 0, 0, 0,
162
+ 3, 145, 115,
163
+ 4, 64, 40,
164
+ 11, 36, 16,
165
+ 11, 36, 12,
166
+ 1, 146, 116,
167
+ 5, 65, 41,
168
+ 5, 37, 17,
169
+ 5, 37, 13},
170
+ {15, // Ver.15
171
+ 655, 523, 415, 295, 223,
172
+ 3, 26, 48, 70, 0, 0, 0,
173
+ 5, 109, 87,
174
+ 5, 65, 41,
175
+ 5, 54, 24,
176
+ 11, 36, 12,
177
+ 1, 110, 88,
178
+ 5, 66, 42,
179
+ 7, 55, 25,
180
+ 7, 37, 13},
181
+ {16, // Ver.16
182
+ 733, 589, 453, 325, 253,
183
+ 3, 26, 50, 74, 0, 0, 0,
184
+ 5, 122, 98,
185
+ 7, 73, 45,
186
+ 15, 43, 19,
187
+ 3, 45, 15,
188
+ 1, 123, 99,
189
+ 3, 74, 46,
190
+ 2, 44, 20,
191
+ 13, 46, 16},
192
+ {17, // Ver.17
193
+ 815, 647, 507, 367, 283,
194
+ 3, 30, 54, 78, 0, 0, 0,
195
+ 1, 135, 107,
196
+ 10, 74, 46,
197
+ 1, 50, 22,
198
+ 2, 42, 14,
199
+ 5, 136, 108,
200
+ 1, 75, 47,
201
+ 15, 51, 23,
202
+ 17, 43, 15},
203
+ {18, // Ver.18
204
+ 901, 721, 563, 397, 313,
205
+ 3, 30, 56, 82, 0, 0, 0,
206
+ 5, 150, 120,
207
+ 9, 69, 43,
208
+ 17, 50, 22,
209
+ 2, 42, 14,
210
+ 1, 151, 121,
211
+ 4, 70, 44,
212
+ 1, 51, 23,
213
+ 19, 43, 15},
214
+ {19, // Ver.19
215
+ 991, 795, 627, 445, 341,
216
+ 3, 30, 58, 86, 0, 0, 0,
217
+ 3, 141, 113,
218
+ 3, 70, 44,
219
+ 17, 47, 21,
220
+ 9, 39, 13,
221
+ 4, 142, 114,
222
+ 11, 71, 45,
223
+ 4, 48, 22,
224
+ 16, 40, 14},
225
+ {20, // Ver.20
226
+ 1085, 861, 669, 485, 385,
227
+ 3, 34, 62, 90, 0, 0, 0,
228
+ 3, 135, 107,
229
+ 3, 67, 41,
230
+ 15, 54, 24,
231
+ 15, 43, 15,
232
+ 5, 136, 108,
233
+ 13, 68, 42,
234
+ 5, 55, 25,
235
+ 10, 44, 16},
236
+ {21, // Ver.21
237
+ 1156, 932, 714, 512, 406,
238
+ 4, 28, 50, 72, 94, 0, 0,
239
+ 4, 144, 116,
240
+ 17, 68, 42,
241
+ 17, 50, 22,
242
+ 19, 46, 16,
243
+ 4, 145, 117,
244
+ 0, 0, 0,
245
+ 6, 51, 23,
246
+ 6, 47, 17},
247
+ {22, // Ver.22
248
+ 1258, 1006, 782, 568, 442,
249
+ 4, 26, 50, 74, 98, 0, 0,
250
+ 2, 139, 111,
251
+ 17, 74, 46,
252
+ 7, 54, 24,
253
+ 34, 37, 13,
254
+ 7, 140, 112,
255
+ 0, 0, 0,
256
+ 16, 55, 25,
257
+ 0, 0, 0},
258
+ {23, // Ver.23
259
+ 1364, 1094, 860, 614, 464,
260
+ 4, 30, 54, 78, 102, 0, 0,
261
+ 4, 151, 121,
262
+ 4, 75, 47,
263
+ 11, 54, 24,
264
+ 16, 45, 15,
265
+ 5, 152, 122,
266
+ 14, 76, 48,
267
+ 14, 55, 25,
268
+ 14, 46, 16},
269
+ {24, // Ver.24
270
+ 1474, 1174, 914, 664, 514,
271
+ 4, 28, 54, 80, 106, 0, 0,
272
+ 6, 147, 117,
273
+ 6, 73, 45,
274
+ 11, 54, 24,
275
+ 30, 46, 16,
276
+ 4, 148, 118,
277
+ 14, 74, 46,
278
+ 16, 55, 25,
279
+ 2, 47, 17},
280
+ {25, // Ver.25
281
+ 1588, 1276, 1000, 718, 538,
282
+ 4, 32, 58, 84, 110, 0, 0,
283
+ 8, 132, 106,
284
+ 8, 75, 47,
285
+ 7, 54, 24,
286
+ 22, 45, 15,
287
+ 4, 133, 107,
288
+ 13, 76, 48,
289
+ 22, 55, 25,
290
+ 13, 46, 16},
291
+ {26, // Ver.26
292
+ 1706, 1370, 1062, 754, 596,
293
+ 4, 30, 58, 86, 114, 0, 0,
294
+ 10, 142, 114,
295
+ 19, 74, 46,
296
+ 28, 50, 22,
297
+ 33, 46, 16,
298
+ 2, 143, 115,
299
+ 4, 75, 47,
300
+ 6, 51, 23,
301
+ 4, 47, 17},
302
+ {27, // Ver.27
303
+ 1828, 1468, 1128, 808, 628,
304
+ 4, 34, 62, 90, 118, 0, 0,
305
+ 8, 152, 122,
306
+ 22, 73, 45,
307
+ 8, 53, 23,
308
+ 12, 45, 15,
309
+ 4, 153, 123,
310
+ 3, 74, 46,
311
+ 26, 54, 24,
312
+ 28, 46, 16},
313
+ {28, // Ver.28
314
+ 1921, 1531, 1193, 871, 661,
315
+ 5, 26, 50, 74, 98, 122, 0,
316
+ 3, 147, 117,
317
+ 3, 73, 45,
318
+ 4, 54, 24,
319
+ 11, 45, 15,
320
+ 10, 148, 118,
321
+ 23, 74, 46,
322
+ 31, 55, 25,
323
+ 31, 46, 16},
324
+ {29, // Ver.29
325
+ 2051, 1631, 1267, 911, 701,
326
+ 5, 30, 54, 78, 102, 126, 0,
327
+ 7, 146, 116,
328
+ 21, 73, 45,
329
+ 1, 53, 23,
330
+ 19, 45, 15,
331
+ 7, 147, 117,
332
+ 7, 74, 46,
333
+ 37, 54, 24,
334
+ 26, 46, 16},
335
+ {30, // Ver.30
336
+ 2185, 1735, 1373, 985, 745,
337
+ 5, 26, 52, 78, 104, 130, 0,
338
+ 5, 145, 115,
339
+ 19, 75, 47,
340
+ 15, 54, 24,
341
+ 23, 45, 15,
342
+ 10, 146, 116,
343
+ 10, 76, 48,
344
+ 25, 55, 25,
345
+ 25, 46, 16},
346
+ {31, // Ver.31
347
+ 2323, 1843, 1455, 1033, 793,
348
+ 5, 30, 56, 82, 108, 134, 0,
349
+ 13, 145, 115,
350
+ 2, 74, 46,
351
+ 42, 54, 24,
352
+ 23, 45, 15,
353
+ 3, 146, 116,
354
+ 29, 75, 47,
355
+ 1, 55, 25,
356
+ 28, 46, 16},
357
+ {32, // Ver.32
358
+ 2465, 1955, 1541, 1115, 845,
359
+ 5, 34, 60, 86, 112, 138, 0,
360
+ 17, 145, 115,
361
+ 10, 74, 46,
362
+ 10, 54, 24,
363
+ 19, 45, 15,
364
+ 0, 0, 0,
365
+ 23, 75, 47,
366
+ 35, 55, 25,
367
+ 35, 46, 16},
368
+ {33, // Ver.33
369
+ 2611, 2071, 1631, 1171, 901,
370
+ 5, 30, 58, 86, 114, 142, 0,
371
+ 17, 145, 115,
372
+ 14, 74, 46,
373
+ 29, 54, 24,
374
+ 11, 45, 15,
375
+ 1, 146, 116,
376
+ 21, 75, 47,
377
+ 19, 55, 25,
378
+ 46, 46, 16},
379
+ {34, // Ver.34
380
+ 2761, 2191, 1725, 1231, 961,
381
+ 5, 34, 62, 90, 118, 146, 0,
382
+ 13, 145, 115,
383
+ 14, 74, 46,
384
+ 44, 54, 24,
385
+ 59, 46, 16,
386
+ 6, 146, 116,
387
+ 23, 75, 47,
388
+ 7, 55, 25,
389
+ 1, 47, 17},
390
+ {35, // Ver.35
391
+ 2876, 2306, 1812, 1286, 986,
392
+ 6, 30, 54, 78, 102, 126, 150,
393
+ 12, 151, 121,
394
+ 12, 75, 47,
395
+ 39, 54, 24,
396
+ 22, 45, 15,
397
+ 7, 152, 122,
398
+ 26, 76, 48,
399
+ 14, 55, 25,
400
+ 41, 46, 16},
401
+ {36, // Ver.36
402
+ 3034, 2434, 1914, 1354, 1054,
403
+ 6, 24, 50, 76, 102, 128, 154,
404
+ 6, 151, 121,
405
+ 6, 75, 47,
406
+ 46, 54, 24,
407
+ 2, 45, 15,
408
+ 14, 152, 122,
409
+ 34, 76, 48,
410
+ 10, 55, 25,
411
+ 64, 46, 16},
412
+ {37, // Ver.37
413
+ 3196, 2566, 1992, 1426, 1096,
414
+ 6, 28, 54, 80, 106, 132, 158,
415
+ 17, 152, 122,
416
+ 29, 74, 46,
417
+ 49, 54, 24,
418
+ 24, 45, 15,
419
+ 4, 153, 123,
420
+ 14, 75, 47,
421
+ 10, 55, 25,
422
+ 46, 46, 16},
423
+ {38, // Ver.38
424
+ 3362, 2702, 2102, 1502, 1142,
425
+ 6, 32, 58, 84, 110, 136, 162,
426
+ 4, 152, 122,
427
+ 13, 74, 46,
428
+ 48, 54, 24,
429
+ 42, 45, 15,
430
+ 18, 153, 123,
431
+ 32, 75, 47,
432
+ 14, 55, 25,
433
+ 32, 46, 16},
434
+ {39, // Ver.39
435
+ 3532, 2812, 2216, 1582, 1222,
436
+ 6, 26, 54, 82, 110, 138, 166,
437
+ 20, 147, 117,
438
+ 40, 75, 47,
439
+ 43, 54, 24,
440
+ 10, 45, 15,
441
+ 4, 148, 118,
442
+ 7, 76, 48,
443
+ 22, 55, 25,
444
+ 67, 46, 16},
445
+ {40, // Ver.40
446
+ 3706, 2956, 2334, 1666, 1276,
447
+ 6, 30, 58, 86, 114, 142, 170,
448
+ 19, 148, 118,
449
+ 18, 75, 47,
450
+ 34, 54, 24,
451
+ 20, 45, 15,
452
+ 6, 149, 119,
453
+ 31, 76, 48,
454
+ 34, 55, 25,
455
+ 61, 46, 16}
456
+ };
457
+
458
+
459
+ /////////////////////////////////////////////////////////////////////////////
460
+ // GF(2^8)���w���������ϊ��e�[�u��
461
+ static BYTE byExpToInt[] = { 1, 2, 4, 8, 16, 32, 64, 128, 29, 58, 116, 232, 205, 135, 19, 38,
462
+ 76, 152, 45, 90, 180, 117, 234, 201, 143, 3, 6, 12, 24, 48, 96, 192,
463
+ 157, 39, 78, 156, 37, 74, 148, 53, 106, 212, 181, 119, 238, 193, 159, 35,
464
+ 70, 140, 5, 10, 20, 40, 80, 160, 93, 186, 105, 210, 185, 111, 222, 161,
465
+ 95, 190, 97, 194, 153, 47, 94, 188, 101, 202, 137, 15, 30, 60, 120, 240,
466
+ 253, 231, 211, 187, 107, 214, 177, 127, 254, 225, 223, 163, 91, 182, 113, 226,
467
+ 217, 175, 67, 134, 17, 34, 68, 136, 13, 26, 52, 104, 208, 189, 103, 206,
468
+ 129, 31, 62, 124, 248, 237, 199, 147, 59, 118, 236, 197, 151, 51, 102, 204,
469
+ 133, 23, 46, 92, 184, 109, 218, 169, 79, 158, 33, 66, 132, 21, 42, 84,
470
+ 168, 77, 154, 41, 82, 164, 85, 170, 73, 146, 57, 114, 228, 213, 183, 115,
471
+ 230, 209, 191, 99, 198, 145, 63, 126, 252, 229, 215, 179, 123, 246, 241, 255,
472
+ 227, 219, 171, 75, 150, 49, 98, 196, 149, 55, 110, 220, 165, 87, 174, 65,
473
+ 130, 25, 50, 100, 200, 141, 7, 14, 28, 56, 112, 224, 221, 167, 83, 166,
474
+ 81, 162, 89, 178, 121, 242, 249, 239, 195, 155, 43, 86, 172, 69, 138, 9,
475
+ 18, 36, 72, 144, 61, 122, 244, 245, 247, 243, 251, 235, 203, 139, 11, 22,
476
+ 44, 88, 176, 125, 250, 233, 207, 131, 27, 54, 108, 216, 173, 71, 142, 1};
477
+
478
+
479
+ /////////////////////////////////////////////////////////////////////////////
480
+ // GF(2^8)���������w���ϊ��e�[�u��
481
+ static BYTE byIntToExp[] = { 0, 0, 1, 25, 2, 50, 26, 198, 3, 223, 51, 238, 27, 104, 199, 75,
482
+ 4, 100, 224, 14, 52, 141, 239, 129, 28, 193, 105, 248, 200, 8, 76, 113,
483
+ 5, 138, 101, 47, 225, 36, 15, 33, 53, 147, 142, 218, 240, 18, 130, 69,
484
+ 29, 181, 194, 125, 106, 39, 249, 185, 201, 154, 9, 120, 77, 228, 114, 166,
485
+ 6, 191, 139, 98, 102, 221, 48, 253, 226, 152, 37, 179, 16, 145, 34, 136,
486
+ 54, 208, 148, 206, 143, 150, 219, 189, 241, 210, 19, 92, 131, 56, 70, 64,
487
+ 30, 66, 182, 163, 195, 72, 126, 110, 107, 58, 40, 84, 250, 133, 186, 61,
488
+ 202, 94, 155, 159, 10, 21, 121, 43, 78, 212, 229, 172, 115, 243, 167, 87,
489
+ 7, 112, 192, 247, 140, 128, 99, 13, 103, 74, 222, 237, 49, 197, 254, 24,
490
+ 227, 165, 153, 119, 38, 184, 180, 124, 17, 68, 146, 217, 35, 32, 137, 46,
491
+ 55, 63, 209, 91, 149, 188, 207, 205, 144, 135, 151, 178, 220, 252, 190, 97,
492
+ 242, 86, 211, 171, 20, 42, 93, 158, 132, 60, 57, 83, 71, 109, 65, 162,
493
+ 31, 45, 67, 216, 183, 123, 164, 118, 196, 23, 73, 236, 127, 12, 111, 246,
494
+ 108, 161, 59, 82, 41, 157, 85, 170, 251, 96, 134, 177, 187, 204, 62, 90,
495
+ 203, 89, 95, 176, 156, 169, 160, 81, 11, 245, 22, 235, 122, 117, 44, 215,
496
+ 79, 174, 213, 233, 230, 231, 173, 232, 116, 214, 244, 234, 168, 80, 88, 175};
497
+
498
+
499
+ /////////////////////////////////////////////////////////////////////////////
500
+ // �������������������W��
501
+ static BYTE byRSExp7[] = {87, 229, 146, 149, 238, 102, 21};
502
+ static BYTE byRSExp10[] = {251, 67, 46, 61, 118, 70, 64, 94, 32, 45};
503
+ static BYTE byRSExp13[] = { 74, 152, 176, 100, 86, 100, 106, 104, 130, 218, 206, 140, 78};
504
+ static BYTE byRSExp15[] = { 8, 183, 61, 91, 202, 37, 51, 58, 58, 237, 140, 124, 5, 99, 105};
505
+ static BYTE byRSExp16[] = {120, 104, 107, 109, 102, 161, 76, 3, 91, 191, 147, 169, 182, 194, 225, 120};
506
+ static BYTE byRSExp17[] = { 43, 139, 206, 78, 43, 239, 123, 206, 214, 147, 24, 99, 150, 39, 243, 163, 136};
507
+ static BYTE byRSExp18[] = {215, 234, 158, 94, 184, 97, 118, 170, 79, 187, 152, 148, 252, 179, 5, 98, 96, 153};
508
+ static BYTE byRSExp20[] = { 17, 60, 79, 50, 61, 163, 26, 187, 202, 180, 221, 225, 83, 239, 156, 164, 212, 212, 188, 190};
509
+ static BYTE byRSExp22[] = {210, 171, 247, 242, 93, 230, 14, 109, 221, 53, 200, 74, 8, 172, 98, 80, 219, 134, 160, 105,
510
+ 165, 231};
511
+ static BYTE byRSExp24[] = {229, 121, 135, 48, 211, 117, 251, 126, 159, 180, 169, 152, 192, 226, 228, 218, 111, 0, 117, 232,
512
+ 87, 96, 227, 21};
513
+ static BYTE byRSExp26[] = {173, 125, 158, 2, 103, 182, 118, 17, 145, 201, 111, 28, 165, 53, 161, 21, 245, 142, 13, 102,
514
+ 48, 227, 153, 145, 218, 70};
515
+ static BYTE byRSExp28[] = {168, 223, 200, 104, 224, 234, 108, 180, 110, 190, 195, 147, 205, 27, 232, 201, 21, 43, 245, 87,
516
+ 42, 195, 212, 119, 242, 37, 9, 123};
517
+ static BYTE byRSExp30[] = { 41, 173, 145, 152, 216, 31, 179, 182, 50, 48, 110, 86, 239, 96, 222, 125, 42, 173, 226, 193,
518
+ 224, 130, 156, 37, 251, 216, 238, 40, 192, 180};
519
+ static BYTE byRSExp32[] = { 10, 6, 106, 190, 249, 167, 4, 67, 209, 138, 138, 32, 242, 123, 89, 27, 120, 185, 80, 156,
520
+ 38, 69, 171, 60, 28, 222, 80, 52, 254, 185, 220, 241};
521
+ static BYTE byRSExp34[] = {111, 77, 146, 94, 26, 21, 108, 19, 105, 94, 113, 193, 86, 140, 163, 125, 58, 158, 229, 239,
522
+ 218, 103, 56, 70, 114, 61, 183, 129, 167, 13, 98, 62, 129, 51};
523
+ static BYTE byRSExp36[] = {200, 183, 98, 16, 172, 31, 246, 234, 60, 152, 115, 0, 167, 152, 113, 248, 238, 107, 18, 63,
524
+ 218, 37, 87, 210, 105, 177, 120, 74, 121, 196, 117, 251, 113, 233, 30, 120};
525
+ static BYTE byRSExp38[] = {159, 34, 38, 228, 230, 59, 243, 95, 49, 218, 176, 164, 20, 65, 45, 111, 39, 81, 49, 118,
526
+ 113, 222, 193, 250, 242, 168, 217, 41, 164, 247, 177, 30, 238, 18, 120, 153, 60, 193};
527
+ static BYTE byRSExp40[] = { 59, 116, 79, 161, 252, 98, 128, 205, 128, 161, 247, 57, 163, 56, 235, 106, 53, 26, 187, 174,
528
+ 226, 104, 170, 7, 175, 35, 181, 114, 88, 41, 47, 163, 125, 134, 72, 20, 232, 53, 35, 15};
529
+ static BYTE byRSExp42[] = {250, 103, 221, 230, 25, 18, 137, 231, 0, 3, 58, 242, 221, 191, 110, 84, 230, 8, 188, 106,
530
+ 96, 147, 15, 131, 139, 34, 101, 223, 39, 101, 213, 199, 237, 254, 201, 123, 171, 162, 194, 117,
531
+ 50, 96};
532
+ static BYTE byRSExp44[] = {190, 7, 61, 121, 71, 246, 69, 55, 168, 188, 89, 243, 191, 25, 72, 123, 9, 145, 14, 247,
533
+ 1, 238, 44, 78, 143, 62, 224, 126, 118, 114, 68, 163, 52, 194, 217, 147, 204, 169, 37, 130,
534
+ 113, 102, 73, 181};
535
+ static BYTE byRSExp46[] = {112, 94, 88, 112, 253, 224, 202, 115, 187, 99, 89, 5, 54, 113, 129, 44, 58, 16, 135, 216,
536
+ 169, 211, 36, 1, 4, 96, 60, 241, 73, 104, 234, 8, 249, 245, 119, 174, 52, 25, 157, 224,
537
+ 43, 202, 223, 19, 82, 15};
538
+ static BYTE byRSExp48[] = {228, 25, 196, 130, 211, 146, 60, 24, 251, 90, 39, 102, 240, 61, 178, 63, 46, 123, 115, 18,
539
+ 221, 111, 135, 160, 182, 205, 107, 206, 95, 150, 120, 184, 91, 21, 247, 156, 140, 238, 191, 11,
540
+ 94, 227, 84, 50, 163, 39, 34, 108};
541
+ static BYTE byRSExp50[] = {232, 125, 157, 161, 164, 9, 118, 46, 209, 99, 203, 193, 35, 3, 209, 111, 195, 242, 203, 225,
542
+ 46, 13, 32, 160, 126, 209, 130, 160, 242, 215, 242, 75, 77, 42, 189, 32, 113, 65, 124, 69,
543
+ 228, 114, 235, 175, 124, 170, 215, 232, 133, 205};
544
+ static BYTE byRSExp52[] = {116, 50, 86, 186, 50, 220, 251, 89, 192, 46, 86, 127, 124, 19, 184, 233, 151, 215, 22, 14,
545
+ 59, 145, 37, 242, 203, 134, 254, 89, 190, 94, 59, 65, 124, 113, 100, 233, 235, 121, 22, 76,
546
+ 86, 97, 39, 242, 200, 220, 101, 33, 239, 254, 116, 51};
547
+ static BYTE byRSExp54[] = {183, 26, 201, 87, 210, 221, 113, 21, 46, 65, 45, 50, 238, 184, 249, 225, 102, 58, 209, 218,
548
+ 109, 165, 26, 95, 184, 192, 52, 245, 35, 254, 238, 175, 172, 79, 123, 25, 122, 43, 120, 108,
549
+ 215, 80, 128, 201, 235, 8, 153, 59, 101, 31, 198, 76, 31, 156};
550
+ static BYTE byRSExp56[] = {106, 120, 107, 157, 164, 216, 112, 116, 2, 91, 248, 163, 36, 201, 202, 229, 6, 144, 254, 155,
551
+ 135, 208, 170, 209, 12, 139, 127, 142, 182, 249, 177, 174, 190, 28, 10, 85, 239, 184, 101, 124,
552
+ 152, 206, 96, 23, 163, 61, 27, 196, 247, 151, 154, 202, 207, 20, 61, 10};
553
+ static BYTE byRSExp58[] = { 82, 116, 26, 247, 66, 27, 62, 107, 252, 182, 200, 185, 235, 55, 251, 242, 210, 144, 154, 237,
554
+ 176, 141, 192, 248, 152, 249, 206, 85, 253, 142, 65, 165, 125, 23, 24, 30, 122, 240, 214, 6,
555
+ 129, 218, 29, 145, 127, 134, 206, 245, 117, 29, 41, 63, 159, 142, 233, 125, 148, 123};
556
+ static BYTE byRSExp60[] = {107, 140, 26, 12, 9, 141, 243, 197, 226, 197, 219, 45, 211, 101, 219, 120, 28, 181, 127, 6,
557
+ 100, 247, 2, 205, 198, 57, 115, 219, 101, 109, 160, 82, 37, 38, 238, 49, 160, 209, 121, 86,
558
+ 11, 124, 30, 181, 84, 25, 194, 87, 65, 102, 190, 220, 70, 27, 209, 16, 89, 7, 33, 240};
559
+ static BYTE byRSExp62[] = { 65, 202, 113, 98, 71, 223, 248, 118, 214, 94, 0, 122, 37, 23, 2, 228, 58, 121, 7, 105,
560
+ 135, 78, 243, 118, 70, 76, 223, 89, 72, 50, 70, 111, 194, 17, 212, 126, 181, 35, 221, 117,
561
+ 235, 11, 229, 149, 147, 123, 213, 40, 115, 6, 200, 100, 26, 246, 182, 218, 127, 215, 36, 186,
562
+ 110, 106};
563
+ static BYTE byRSExp64[] = { 45, 51, 175, 9, 7, 158, 159, 49, 68, 119, 92, 123, 177, 204, 187, 254, 200, 78, 141, 149,
564
+ 119, 26, 127, 53, 160, 93, 199, 212, 29, 24, 145, 156, 208, 150, 218, 209, 4, 216, 91, 47,
565
+ 184, 146, 47, 140, 195, 195, 125, 242, 238, 63, 99, 108, 140, 230, 242, 31, 204, 11, 178, 243,
566
+ 217, 156, 213, 231};
567
+ static BYTE byRSExp66[] = { 5, 118, 222, 180, 136, 136, 162, 51, 46, 117, 13, 215, 81, 17, 139, 247, 197, 171, 95, 173,
568
+ 65, 137, 178, 68, 111, 95, 101, 41, 72, 214, 169, 197, 95, 7, 44, 154, 77, 111, 236, 40,
569
+ 121, 143, 63, 87, 80, 253, 240, 126, 217, 77, 34, 232, 106, 50, 168, 82, 76, 146, 67, 106,
570
+ 171, 25, 132, 93, 45, 105};
571
+ static BYTE byRSExp68[] = {247, 159, 223, 33, 224, 93, 77, 70, 90, 160, 32, 254, 43, 150, 84, 101, 190, 205, 133, 52,
572
+ 60, 202, 165, 220, 203, 151, 93, 84, 15, 84, 253, 173, 160, 89, 227, 52, 199, 97, 95, 231,
573
+ 52, 177, 41, 125, 137, 241, 166, 225, 118, 2, 54, 32, 82, 215, 175, 198, 43, 238, 235, 27,
574
+ 101, 184, 127, 3, 5, 8, 163, 238};
575
+
576
+ static LPBYTE byRSExp[] = {NULL, NULL, NULL, NULL, NULL, NULL, NULL, byRSExp7, NULL, NULL,
577
+ byRSExp10, NULL, NULL, byRSExp13, NULL, byRSExp15, byRSExp16, byRSExp17, byRSExp18, NULL,
578
+ byRSExp20, NULL, byRSExp22, NULL, byRSExp24, NULL, byRSExp26, NULL, byRSExp28, NULL,
579
+ byRSExp30, NULL, byRSExp32, NULL, byRSExp34, NULL, byRSExp36, NULL, byRSExp38, NULL,
580
+ byRSExp40, NULL, byRSExp42, NULL, byRSExp44, NULL, byRSExp46, NULL, byRSExp48, NULL,
581
+ byRSExp50, NULL, byRSExp52, NULL, byRSExp54, NULL, byRSExp56, NULL, byRSExp58, NULL,
582
+ byRSExp60, NULL, byRSExp62, NULL, byRSExp64, NULL, byRSExp66, NULL, byRSExp68};
583
+
584
+ // �������C���W�P�[�^�r�b�g��(�o�[�W�����O���[�v��, {S, M, L})
585
+ static int nIndicatorLenNumeral[] = {10, 12, 14};
586
+ static int nIndicatorLenAlphabet[] = { 9, 11, 13};
587
+ static int nIndicatorLen8Bit[] = { 8, 16, 16};
588
+ static int nIndicatorLenKanji[] = { 8, 10, 12};
589
+
590
+
591
+ /////////////////////////////////////////////////////////////////////////////
592
+ // QR_Encode �N���X�̍\�z/����
593
+
594
+ CQR_Encode::CQR_Encode()
595
+ {
596
+ }
597
+
598
+ CQR_Encode::~CQR_Encode()
599
+ {
600
+ }
601
+
602
+
603
+ /////////////////////////////////////////////////////////////////////////////
604
+ // CQR_Encode::EncodeData
605
+ // �p �r�F�f�[�^�G���R�[�h
606
+ // �� ���F���������x���A�^��(0=����)�A�^�Ԏ����g���t���O�A�}�X�L���O�ԍ�(-1=����)�A�G���R�[�h�f�[�^�A�G���R�[�h�f�[�^��
607
+ // �߂�l�F�G���R�[�h������=TRUE�A�f�[�^�Ȃ��A�܂��͗e�ʃI�[�o�[��=FALSE
608
+
609
+ BOOL CQR_Encode::EncodeData(int nLevel, int nVersion, BOOL bAutoExtent, int nMaskingNo, LPCSTR lpsSource, int ncSource)
610
+ {
611
+ int i, j;
612
+
613
+ m_nLevel = nLevel;
614
+ m_nMaskingNo = nMaskingNo;
615
+
616
+ // �f�[�^�����w�肳��Ă��Ȃ��ꍇ�� lstrlen �ɂ���Ď擾
617
+ int ncLength = ncSource > 0 ? ncSource : lstrlen(lpsSource);
618
+
619
+ if (ncLength == 0)
620
+ return FALSE; // �f�[�^�Ȃ�
621
+
622
+ // �o�[�W����(�^��)�`�F�b�N
623
+ int nEncodeVersion = GetEncodeVersion(nVersion, lpsSource, ncLength);
624
+
625
+ if (nEncodeVersion == 0)
626
+ return FALSE; // �e�ʃI�[�o�[
627
+
628
+ if (nVersion == 0)
629
+ {
630
+ // �^�Ԏ���
631
+ m_nVersion = nEncodeVersion;
632
+ }
633
+ else
634
+ {
635
+ if (nEncodeVersion <= nVersion)
636
+ {
637
+ m_nVersion = nVersion;
638
+ }
639
+ else
640
+ {
641
+ if (bAutoExtent)
642
+ m_nVersion = nEncodeVersion; // �o�[�W����(�^��)�����g��
643
+ else
644
+ return FALSE; // �e�ʃI�[�o�[
645
+ }
646
+ }
647
+
648
+ // �^�[�~�l�[�^�R�[�h"0000"�t��
649
+ int ncDataCodeWord = QR_VersonInfo[m_nVersion].ncDataCodeWord[nLevel];
650
+
651
+ int ncTerminater = min(4, (ncDataCodeWord * 8) - m_ncDataCodeWordBit);
652
+
653
+ if (ncTerminater > 0)
654
+ m_ncDataCodeWordBit = SetBitStream(m_ncDataCodeWordBit, 0, ncTerminater);
655
+
656
+ // �p�f�B���O�R�[�h"11101100, 00010001"�t��
657
+ BYTE byPaddingCode = 0xec;
658
+
659
+ for (i = (m_ncDataCodeWordBit + 7) / 8; i < ncDataCodeWord; ++i)
660
+ {
661
+ m_byDataCodeWord[i] = byPaddingCode;
662
+
663
+ byPaddingCode = (BYTE)(byPaddingCode == 0xec ? 0x11 : 0xec);
664
+ }
665
+
666
+ // ���R�[�h���[�h�Z�o�G���A�N���A
667
+ m_ncAllCodeWord = QR_VersonInfo[m_nVersion].ncAllCodeWord;
668
+ ZeroMemory(m_byAllCodeWord, m_ncAllCodeWord);
669
+
670
+ int nDataCwIndex = 0; // �f�[�^�R�[�h���[�h�����ʒu
671
+
672
+ // �f�[�^�u���b�N������
673
+ int ncBlock1 = QR_VersonInfo[m_nVersion].RS_BlockInfo1[nLevel].ncRSBlock;
674
+ int ncBlock2 = QR_VersonInfo[m_nVersion].RS_BlockInfo2[nLevel].ncRSBlock;
675
+ int ncBlockSum = ncBlock1 + ncBlock2;
676
+
677
+ int nBlockNo = 0; // �������u���b�N�ԍ�
678
+
679
+ // �u���b�N�ʃf�[�^�R�[�h���[�h��
680
+ int ncDataCw1 = QR_VersonInfo[m_nVersion].RS_BlockInfo1[nLevel].ncDataCodeWord;
681
+ int ncDataCw2 = QR_VersonInfo[m_nVersion].RS_BlockInfo2[nLevel].ncDataCodeWord;
682
+
683
+ // �f�[�^�R�[�h���[�h�C���^�[���[�u�z�u
684
+ for (i = 0; i < ncBlock1; ++i)
685
+ {
686
+ for (j = 0; j < ncDataCw1; ++j)
687
+ {
688
+ m_byAllCodeWord[(ncBlockSum * j) + nBlockNo] = m_byDataCodeWord[nDataCwIndex++];
689
+ }
690
+
691
+ ++nBlockNo;
692
+ }
693
+
694
+ for (i = 0; i < ncBlock2; ++i)
695
+ {
696
+ for (j = 0; j < ncDataCw2; ++j)
697
+ {
698
+ if (j < ncDataCw1)
699
+ {
700
+ m_byAllCodeWord[(ncBlockSum * j) + nBlockNo] = m_byDataCodeWord[nDataCwIndex++];
701
+ }
702
+ else
703
+ {
704
+ // �Q��ڃu���b�N�[�����z�u
705
+ m_byAllCodeWord[(ncBlockSum * ncDataCw1) + i] = m_byDataCodeWord[nDataCwIndex++];
706
+ }
707
+ }
708
+
709
+ ++nBlockNo;
710
+ }
711
+
712
+ // �u���b�N�ʂq�r�R�[�h���[�h��(������ł͓���)
713
+ int ncRSCw1 = QR_VersonInfo[m_nVersion].RS_BlockInfo1[nLevel].ncAllCodeWord - ncDataCw1;
714
+ int ncRSCw2 = QR_VersonInfo[m_nVersion].RS_BlockInfo2[nLevel].ncAllCodeWord - ncDataCw2;
715
+
716
+ /////////////////////////////////////////////////////////////////////////
717
+ // �q�r�R�[�h���[�h�Z�o
718
+
719
+ nDataCwIndex = 0;
720
+ nBlockNo = 0;
721
+
722
+ for (i = 0; i < ncBlock1; ++i)
723
+ {
724
+ ZeroMemory(m_byRSWork, sizeof(m_byRSWork));
725
+
726
+ memmove(m_byRSWork, m_byDataCodeWord + nDataCwIndex, ncDataCw1);
727
+
728
+ GetRSCodeWord(m_byRSWork, ncDataCw1, ncRSCw1);
729
+
730
+ // �q�r�R�[�h���[�h�z�u
731
+ for (j = 0; j < ncRSCw1; ++j)
732
+ {
733
+ m_byAllCodeWord[ncDataCodeWord + (ncBlockSum * j) + nBlockNo] = m_byRSWork[j];
734
+ }
735
+
736
+ nDataCwIndex += ncDataCw1;
737
+ ++nBlockNo;
738
+ }
739
+
740
+ for (i = 0; i < ncBlock2; ++i)
741
+ {
742
+ ZeroMemory(m_byRSWork, sizeof(m_byRSWork));
743
+
744
+ memmove(m_byRSWork, m_byDataCodeWord + nDataCwIndex, ncDataCw2);
745
+
746
+ GetRSCodeWord(m_byRSWork, ncDataCw2, ncRSCw2);
747
+
748
+ // �q�r�R�[�h���[�h�z�u
749
+ for (j = 0; j < ncRSCw2; ++j)
750
+ {
751
+ m_byAllCodeWord[ncDataCodeWord + (ncBlockSum * j) + nBlockNo] = m_byRSWork[j];
752
+ }
753
+
754
+ nDataCwIndex += ncDataCw2;
755
+ ++nBlockNo;
756
+ }
757
+
758
+ m_nSymbleSize = m_nVersion * 4 + 17;
759
+
760
+ // ���W���[���z�u
761
+ FormatModule();
762
+
763
+ return TRUE;
764
+ }
765
+
766
+
767
+ /////////////////////////////////////////////////////////////////////////////
768
+ // CQR_Encode::GetEncodeVersion
769
+ // �p �r�F�G���R�[�h���o�[�W����(�^��)�擾
770
+ // �� ���F�����J�n�o�[�W�����A�G���R�[�h�f�[�^�A�G���R�[�h�f�[�^��
771
+ // �߂�l�F�o�[�W�����ԍ��i�e�ʃI�[�o�[��=0�j
772
+
773
+ int CQR_Encode::GetEncodeVersion(int nVersion, LPCSTR lpsSource, int ncLength)
774
+ {
775
+ int nVerGroup = nVersion >= 27 ? QR_VRESION_L : (nVersion >= 10 ? QR_VRESION_M : QR_VRESION_S);
776
+ int i, j;
777
+
778
+ for (i = nVerGroup; i <= QR_VRESION_L; ++i)
779
+ {
780
+ if (EncodeSourceData(lpsSource, ncLength, i))
781
+ {
782
+ if (i == QR_VRESION_S)
783
+ {
784
+ for (j = 1; j <= 9; ++j)
785
+ {
786
+ if ((m_ncDataCodeWordBit + 7) / 8 <= QR_VersonInfo[j].ncDataCodeWord[m_nLevel])
787
+ return j;
788
+ }
789
+ }
790
+ else if (i == QR_VRESION_M)
791
+ {
792
+ for (j = 10; j <= 26; ++j)
793
+ {
794
+ if ((m_ncDataCodeWordBit + 7) / 8 <= QR_VersonInfo[j].ncDataCodeWord[m_nLevel])
795
+ return j;
796
+ }
797
+ }
798
+ else if (i == QR_VRESION_L)
799
+ {
800
+ for (j = 27; j <= 40; ++j)
801
+ {
802
+ if ((m_ncDataCodeWordBit + 7) / 8 <= QR_VersonInfo[j].ncDataCodeWord[m_nLevel])
803
+ return j;
804
+ }
805
+ }
806
+ }
807
+ }
808
+
809
+ return 0;
810
+ }
811
+
812
+
813
+ /////////////////////////////////////////////////////////////////////////////
814
+ // CQR_Encode::EncodeSourceData
815
+ // �p �r�F���̓f�[�^�G���R�[�h
816
+ // �� ���F���̓f�[�^�A���̓f�[�^���A�o�[�W����(�^��)�O���[�v
817
+ // �߂�l�F�G���R�[�h������=TRUE
818
+
819
+ BOOL CQR_Encode::EncodeSourceData(LPCSTR lpsSource, int ncLength, int nVerGroup)
820
+ {
821
+ ZeroMemory(m_nBlockLength, sizeof(m_nBlockLength));
822
+
823
+ int i, j;
824
+
825
+ // �ǂ̃��[�h��������(�o�C�g)�p�����Ă��邩�𒲍�
826
+ for (m_ncDataBlock = i = 0; i < ncLength; ++i)
827
+ {
828
+ BYTE byMode;
829
+
830
+ if (i < ncLength - 1 && IsKanjiData(lpsSource[i], lpsSource[i + 1]))
831
+ byMode = QR_MODE_KANJI;
832
+ else if (IsNumeralData(lpsSource[i]))
833
+ byMode = QR_MODE_NUMERAL;
834
+ else if (IsAlphabetData(lpsSource[i]))
835
+ byMode = QR_MODE_ALPHABET;
836
+ else
837
+ byMode = QR_MODE_8BIT;
838
+
839
+ if (i == 0)
840
+ m_byBlockMode[0] = byMode;
841
+
842
+ if (m_byBlockMode[m_ncDataBlock] != byMode)
843
+ m_byBlockMode[++m_ncDataBlock] = byMode;
844
+
845
+ ++m_nBlockLength[m_ncDataBlock];
846
+
847
+ if (byMode == QR_MODE_KANJI)
848
+ {
849
+ // �����͕������ł͂Ȃ� ���ŋL�^
850
+ ++m_nBlockLength[m_ncDataBlock];
851
+ ++i;
852
+ }
853
+ }
854
+
855
+ ++m_ncDataBlock;
856
+
857
+ /////////////////////////////////////////////////////////////////////////
858
+ // �אڂ���p�������[�h�u���b�N�Ɛ������[�h�u���b�N�̕��т��������ɂ�茋��
859
+
860
+ int ncSrcBits, ncDstBits; // ���̃r�b�g���ƒP��̉p�������[�h�u���b�N�������ꍇ�̃r�b�g��
861
+
862
+ int nBlock = 0;
863
+
864
+ while (nBlock < m_ncDataBlock - 1)
865
+ {
866
+ int ncJoinFront, ncJoinBehind; // �O��W�r�b�g�o�C�g���[�h�u���b�N�ƌ��������ꍇ�̃r�b�g��
867
+ int nJoinPosition = 0; // �W�r�b�g�o�C�g���[�h�u���b�N�Ƃ̌����F-1=�O�ƌ����A0=�������Ȃ��A1=���ƌ���
868
+
869
+ // �u�����|�p�����v�܂��́u�p�����|�����v�̕���
870
+ if ((m_byBlockMode[nBlock] == QR_MODE_NUMERAL && m_byBlockMode[nBlock + 1] == QR_MODE_ALPHABET) ||
871
+ (m_byBlockMode[nBlock] == QR_MODE_ALPHABET && m_byBlockMode[nBlock + 1] == QR_MODE_NUMERAL))
872
+ {
873
+ // ���̃r�b�g���ƒP��̉p�������[�h�u���b�N�������ꍇ�̃r�b�g�����r
874
+ ncSrcBits = GetBitLength(m_byBlockMode[nBlock], m_nBlockLength[nBlock], nVerGroup) +
875
+ GetBitLength(m_byBlockMode[nBlock + 1], m_nBlockLength[nBlock + 1], nVerGroup);
876
+
877
+ ncDstBits = GetBitLength(QR_MODE_ALPHABET, m_nBlockLength[nBlock] + m_nBlockLength[nBlock + 1], nVerGroup);
878
+
879
+ if (ncSrcBits > ncDstBits)
880
+ {
881
+ // �O��ɂW�r�b�g�o�C�g���[�h�u���b�N������ꍇ�A�����Ƃ̌������L�����ǂ������`�F�b�N
882
+ if (nBlock >= 1 && m_byBlockMode[nBlock - 1] == QR_MODE_8BIT)
883
+ {
884
+ // �O�ɂW�r�b�g�o�C�g���[�h�u���b�N����
885
+ ncJoinFront = GetBitLength(QR_MODE_8BIT, m_nBlockLength[nBlock - 1] + m_nBlockLength[nBlock], nVerGroup) +
886
+ GetBitLength(m_byBlockMode[nBlock + 1], m_nBlockLength[nBlock + 1], nVerGroup);
887
+
888
+ if (ncJoinFront > ncDstBits + GetBitLength(QR_MODE_8BIT, m_nBlockLength[nBlock - 1], nVerGroup))
889
+ ncJoinFront = 0; // �W�r�b�g�o�C�g���[�h�u���b�N�Ƃ͌������Ȃ�
890
+ }
891
+ else
892
+ ncJoinFront = 0;
893
+
894
+ if (nBlock < m_ncDataBlock - 2 && m_byBlockMode[nBlock + 2] == QR_MODE_8BIT)
895
+ {
896
+ // ���ɂW�r�b�g�o�C�g���[�h�u���b�N����
897
+ ncJoinBehind = GetBitLength(m_byBlockMode[nBlock], m_nBlockLength[nBlock], nVerGroup) +
898
+ GetBitLength(QR_MODE_8BIT, m_nBlockLength[nBlock + 1] + m_nBlockLength[nBlock + 2], nVerGroup);
899
+
900
+ if (ncJoinBehind > ncDstBits + GetBitLength(QR_MODE_8BIT, m_nBlockLength[nBlock + 2], nVerGroup))
901
+ ncJoinBehind = 0; // �W�r�b�g�o�C�g���[�h�u���b�N�Ƃ͌������Ȃ�
902
+ }
903
+ else
904
+ ncJoinBehind = 0;
905
+
906
+ if (ncJoinFront != 0 && ncJoinBehind != 0)
907
+ {
908
+ // �O�㗼���ɂW�r�b�g�o�C�g���[�h�u���b�N������ꍇ�̓f�[�^�����Z���Ȃ����D��
909
+ nJoinPosition = (ncJoinFront < ncJoinBehind) ? -1 : 1;
910
+ }
911
+ else
912
+ {
913
+ nJoinPosition = (ncJoinFront != 0) ? -1 : ((ncJoinBehind != 0) ? 1 : 0);
914
+ }
915
+
916
+ if (nJoinPosition != 0)
917
+ {
918
+ // �W�r�b�g�o�C�g���[�h�u���b�N�Ƃ̌���
919
+ if (nJoinPosition == -1)
920
+ {
921
+ m_nBlockLength[nBlock - 1] += m_nBlockLength[nBlock];
922
+
923
+ // �㑱���V�t�g
924
+ for (i = nBlock; i < m_ncDataBlock - 1; ++i)
925
+ {
926
+ m_byBlockMode[i] = m_byBlockMode[i + 1];
927
+ m_nBlockLength[i] = m_nBlockLength[i + 1];
928
+ }
929
+ }
930
+ else
931
+ {
932
+ m_byBlockMode[nBlock + 1] = QR_MODE_8BIT;
933
+ m_nBlockLength[nBlock + 1] += m_nBlockLength[nBlock + 2];
934
+
935
+ // �㑱���V�t�g
936
+ for (i = nBlock + 2; i < m_ncDataBlock - 1; ++i)
937
+ {
938
+ m_byBlockMode[i] = m_byBlockMode[i + 1];
939
+ m_nBlockLength[i] = m_nBlockLength[i + 1];
940
+ }
941
+ }
942
+
943
+ --m_ncDataBlock;
944
+ }
945
+ else
946
+ {
947
+ // �p�����Ɛ����̕��т�P��̉p�������[�h�u���b�N�ɓ���
948
+
949
+ if (nBlock < m_ncDataBlock - 2 && m_byBlockMode[nBlock + 2] == QR_MODE_ALPHABET)
950
+ {
951
+ // �������悤�Ƃ���u���b�N�̌��ɑ����p�������[�h�u���b�N������
952
+ m_nBlockLength[nBlock + 1] += m_nBlockLength[nBlock + 2];
953
+
954
+ // �㑱���V�t�g
955
+ for (i = nBlock + 2; i < m_ncDataBlock - 1; ++i)
956
+ {
957
+ m_byBlockMode[i] = m_byBlockMode[i + 1];
958
+ m_nBlockLength[i] = m_nBlockLength[i + 1];
959
+ }
960
+
961
+ --m_ncDataBlock;
962
+ }
963
+
964
+ m_byBlockMode[nBlock] = QR_MODE_ALPHABET;
965
+ m_nBlockLength[nBlock] += m_nBlockLength[nBlock + 1];
966
+
967
+ // �㑱���V�t�g
968
+ for (i = nBlock + 1; i < m_ncDataBlock - 1; ++i)
969
+ {
970
+ m_byBlockMode[i] = m_byBlockMode[i + 1];
971
+ m_nBlockLength[i] = m_nBlockLength[i + 1];
972
+ }
973
+
974
+ --m_ncDataBlock;
975
+
976
+ if (nBlock >= 1 && m_byBlockMode[nBlock - 1] == QR_MODE_ALPHABET)
977
+ {
978
+ // ���������u���b�N�̑O�̉p�������[�h�u���b�N������
979
+ m_nBlockLength[nBlock - 1] += m_nBlockLength[nBlock];
980
+
981
+ // �㑱���V�t�g
982
+ for (i = nBlock; i < m_ncDataBlock - 1; ++i)
983
+ {
984
+ m_byBlockMode[i] = m_byBlockMode[i + 1];
985
+ m_nBlockLength[i] = m_nBlockLength[i + 1];
986
+ }
987
+
988
+ --m_ncDataBlock;
989
+ }
990
+ }
991
+
992
+ continue; // ���݈ʒu�̃u���b�N���Ē���
993
+ }
994
+ }
995
+
996
+ ++nBlock; // ���u���b�N�𒲍�
997
+ }
998
+
999
+ /////////////////////////////////////////////////////////////////////////
1000
+ // �A������Z�����[�h�u���b�N���W�r�b�g�o�C�g���[�h�u���b�N��
1001
+
1002
+ nBlock = 0;
1003
+
1004
+ while (nBlock < m_ncDataBlock - 1)
1005
+ {
1006
+ ncSrcBits = GetBitLength(m_byBlockMode[nBlock], m_nBlockLength[nBlock], nVerGroup)
1007
+ + GetBitLength(m_byBlockMode[nBlock + 1], m_nBlockLength[nBlock + 1], nVerGroup);
1008
+
1009
+ ncDstBits = GetBitLength(QR_MODE_8BIT, m_nBlockLength[nBlock] + m_nBlockLength[nBlock + 1], nVerGroup);
1010
+
1011
+ // �O�ɂW�r�b�g�o�C�g���[�h�u���b�N������ꍇ�A�d������C���W�P�[�^�������Z
1012
+ if (nBlock >= 1 && m_byBlockMode[nBlock - 1] == QR_MODE_8BIT)
1013
+ ncDstBits -= (4 + nIndicatorLen8Bit[nVerGroup]);
1014
+
1015
+ // ���ɂW�r�b�g�o�C�g���[�h�u���b�N������ꍇ�A�d������C���W�P�[�^�������Z
1016
+ if (nBlock < m_ncDataBlock - 2 && m_byBlockMode[nBlock + 2] == QR_MODE_8BIT)
1017
+ ncDstBits -= (4 + nIndicatorLen8Bit[nVerGroup]);
1018
+
1019
+ if (ncSrcBits > ncDstBits)
1020
+ {
1021
+ if (nBlock >= 1 && m_byBlockMode[nBlock - 1] == QR_MODE_8BIT)
1022
+ {
1023
+ // ��������u���b�N�̑O�ɂ���W�r�b�g�o�C�g���[�h�u���b�N������
1024
+ m_nBlockLength[nBlock - 1] += m_nBlockLength[nBlock];
1025
+
1026
+ // �㑱���V�t�g
1027
+ for (i = nBlock; i < m_ncDataBlock - 1; ++i)
1028
+ {
1029
+ m_byBlockMode[i] = m_byBlockMode[i + 1];
1030
+ m_nBlockLength[i] = m_nBlockLength[i + 1];
1031
+ }
1032
+
1033
+ --m_ncDataBlock;
1034
+ --nBlock;
1035
+ }
1036
+
1037
+ if (nBlock < m_ncDataBlock - 2 && m_byBlockMode[nBlock + 2] == QR_MODE_8BIT)
1038
+ {
1039
+ // ��������u���b�N�̌��ɂ���W�r�b�g�o�C�g���[�h�u���b�N������
1040
+ m_nBlockLength[nBlock + 1] += m_nBlockLength[nBlock + 2];
1041
+
1042
+ // �㑱���V�t�g
1043
+ for (i = nBlock + 2; i < m_ncDataBlock - 1; ++i)
1044
+ {
1045
+ m_byBlockMode[i] = m_byBlockMode[i + 1];
1046
+ m_nBlockLength[i] = m_nBlockLength[i + 1];
1047
+ }
1048
+
1049
+ --m_ncDataBlock;
1050
+ }
1051
+
1052
+ m_byBlockMode[nBlock] = QR_MODE_8BIT;
1053
+ m_nBlockLength[nBlock] += m_nBlockLength[nBlock + 1];
1054
+
1055
+ // �㑱���V�t�g
1056
+ for (i = nBlock + 1; i < m_ncDataBlock - 1; ++i)
1057
+ {
1058
+ m_byBlockMode[i] = m_byBlockMode[i + 1];
1059
+ m_nBlockLength[i] = m_nBlockLength[i + 1];
1060
+ }
1061
+
1062
+ --m_ncDataBlock;
1063
+
1064
+ // ���������u���b�N�̑O����Ē���
1065
+ if (nBlock >= 1)
1066
+ --nBlock;
1067
+
1068
+ continue;
1069
+ }
1070
+
1071
+ ++nBlock; // ���u���b�N�𒲍�
1072
+ }
1073
+
1074
+ /////////////////////////////////////////////////////////////////////////
1075
+ // �r�b�g�z��
1076
+ int ncComplete = 0; // �����σf�[�^�J�E���^
1077
+ WORD wBinCode;
1078
+
1079
+ m_ncDataCodeWordBit = 0; // �r�b�g�P�ʏ����J�E���^
1080
+
1081
+ ZeroMemory(m_byDataCodeWord, MAX_DATACODEWORD);
1082
+
1083
+ for (i = 0; i < m_ncDataBlock && m_ncDataCodeWordBit != -1; ++i)
1084
+ {
1085
+ if (m_byBlockMode[i] == QR_MODE_NUMERAL)
1086
+ {
1087
+ /////////////////////////////////////////////////////////////////
1088
+ // �������[�h
1089
+
1090
+ // �C���W�P�[�^(0001b)
1091
+ m_ncDataCodeWordBit = SetBitStream(m_ncDataCodeWordBit, 1, 4);
1092
+
1093
+ // �������Z�b�g
1094
+ m_ncDataCodeWordBit = SetBitStream(m_ncDataCodeWordBit, (WORD)m_nBlockLength[i], nIndicatorLenNumeral[nVerGroup]);
1095
+
1096
+ // �r�b�g��ۑ�
1097
+ for (j = 0; j < m_nBlockLength[i]; j += 3)
1098
+ {
1099
+ if (j < m_nBlockLength[i] - 2)
1100
+ {
1101
+ wBinCode = (WORD)(((lpsSource[ncComplete + j] - '0') * 100) +
1102
+ ((lpsSource[ncComplete + j + 1] - '0') * 10) +
1103
+ (lpsSource[ncComplete + j + 2] - '0'));
1104
+
1105
+ m_ncDataCodeWordBit = SetBitStream(m_ncDataCodeWordBit, wBinCode, 10);
1106
+ }
1107
+ else if (j == m_nBlockLength[i] - 2)
1108
+ {
1109
+ // �[���Q�o�C�g
1110
+ wBinCode = (WORD)(((lpsSource[ncComplete + j] - '0') * 10) +
1111
+ (lpsSource[ncComplete + j + 1] - '0'));
1112
+
1113
+ m_ncDataCodeWordBit = SetBitStream(m_ncDataCodeWordBit, wBinCode, 7);
1114
+ }
1115
+ else if (j == m_nBlockLength[i] - 1)
1116
+ {
1117
+ // �[���P�o�C�g
1118
+ wBinCode = (WORD)(lpsSource[ncComplete + j] - '0');
1119
+
1120
+ m_ncDataCodeWordBit = SetBitStream(m_ncDataCodeWordBit, wBinCode, 4);
1121
+ }
1122
+ }
1123
+
1124
+ ncComplete += m_nBlockLength[i];
1125
+ }
1126
+
1127
+ else if (m_byBlockMode[i] == QR_MODE_ALPHABET)
1128
+ {
1129
+ /////////////////////////////////////////////////////////////////
1130
+ // �p�������[�h
1131
+
1132
+ // ���[�h�C���W�P�[�^(0010b)
1133
+ m_ncDataCodeWordBit = SetBitStream(m_ncDataCodeWordBit, 2, 4);
1134
+
1135
+ // �������Z�b�g
1136
+ m_ncDataCodeWordBit = SetBitStream(m_ncDataCodeWordBit, (WORD)m_nBlockLength[i], nIndicatorLenAlphabet[nVerGroup]);
1137
+
1138
+ // �r�b�g��ۑ�
1139
+ for (j = 0; j < m_nBlockLength[i]; j += 2)
1140
+ {
1141
+ if (j < m_nBlockLength[i] - 1)
1142
+ {
1143
+ wBinCode = (WORD)((AlphabetToBinaly(lpsSource[ncComplete + j]) * 45) +
1144
+ AlphabetToBinaly(lpsSource[ncComplete + j + 1]));
1145
+
1146
+ m_ncDataCodeWordBit = SetBitStream(m_ncDataCodeWordBit, wBinCode, 11);
1147
+ }
1148
+ else
1149
+ {
1150
+ // �[���P�o�C�g
1151
+ wBinCode = (WORD)AlphabetToBinaly(lpsSource[ncComplete + j]);
1152
+
1153
+ m_ncDataCodeWordBit = SetBitStream(m_ncDataCodeWordBit, wBinCode, 6);
1154
+ }
1155
+ }
1156
+
1157
+ ncComplete += m_nBlockLength[i];
1158
+ }
1159
+
1160
+ else if (m_byBlockMode[i] == QR_MODE_8BIT)
1161
+ {
1162
+ /////////////////////////////////////////////////////////////////
1163
+ // �W�r�b�g�o�C�g���[�h
1164
+
1165
+ // ���[�h�C���W�P�[�^(0100b)
1166
+ m_ncDataCodeWordBit = SetBitStream(m_ncDataCodeWordBit, 4, 4);
1167
+
1168
+ // �������Z�b�g
1169
+ m_ncDataCodeWordBit = SetBitStream(m_ncDataCodeWordBit, (WORD)m_nBlockLength[i], nIndicatorLen8Bit[nVerGroup]);
1170
+
1171
+ // �r�b�g��ۑ�
1172
+ for (j = 0; j < m_nBlockLength[i]; ++j)
1173
+ {
1174
+ m_ncDataCodeWordBit = SetBitStream(m_ncDataCodeWordBit, (WORD)lpsSource[ncComplete + j], 8);
1175
+ }
1176
+
1177
+ ncComplete += m_nBlockLength[i];
1178
+ }
1179
+ else // m_byBlockMode[i] == QR_MODE_KANJI
1180
+ {
1181
+ /////////////////////////////////////////////////////////////////
1182
+ // �������[�h
1183
+
1184
+ // ���[�h�C���W�P�[�^(1000b)
1185
+ m_ncDataCodeWordBit = SetBitStream(m_ncDataCodeWordBit, 8, 4);
1186
+
1187
+ // �������Z�b�g
1188
+ m_ncDataCodeWordBit = SetBitStream(m_ncDataCodeWordBit, (WORD)(m_nBlockLength[i] / 2), nIndicatorLenKanji[nVerGroup]);
1189
+
1190
+ // �������[�h�Ńr�b�g��ۑ�
1191
+ for (j = 0; j < m_nBlockLength[i] / 2; ++j)
1192
+ {
1193
+ WORD wBinCode = KanjiToBinaly((WORD)(((BYTE)lpsSource[ncComplete + (j * 2)] << 8) + (BYTE)lpsSource[ncComplete + (j * 2) + 1]));
1194
+
1195
+ m_ncDataCodeWordBit = SetBitStream(m_ncDataCodeWordBit, wBinCode, 13);
1196
+ }
1197
+
1198
+ ncComplete += m_nBlockLength[i];
1199
+ }
1200
+ }
1201
+
1202
+ return (m_ncDataCodeWordBit != -1);
1203
+ }
1204
+
1205
+
1206
+ /////////////////////////////////////////////////////////////////////////////
1207
+ // CQR_Encode::GetBitLength
1208
+ // �p �r�F�r�b�g���擾
1209
+ // �� ���F�f�[�^���[�h��ʁA�f�[�^���A�o�[�W����(�^��)�O���[�v
1210
+ // �߂�l�F�f�[�^�r�b�g��
1211
+ // �� �l�F�������[�h�ł̃f�[�^�������͕������ł͂Ȃ��o�C�g��
1212
+
1213
+ int CQR_Encode::GetBitLength(BYTE nMode, int ncData, int nVerGroup)
1214
+ {
1215
+ int ncBits = 0;
1216
+
1217
+ switch (nMode)
1218
+ {
1219
+ case QR_MODE_NUMERAL:
1220
+ ncBits = 4 + nIndicatorLenNumeral[nVerGroup] + (10 * (ncData / 3));
1221
+ switch (ncData % 3)
1222
+ {
1223
+ case 1:
1224
+ ncBits += 4;
1225
+ break;
1226
+ case 2:
1227
+ ncBits += 7;
1228
+ break;
1229
+ default: // case 0:
1230
+ break;
1231
+ }
1232
+
1233
+ break;
1234
+
1235
+ case QR_MODE_ALPHABET:
1236
+ ncBits = 4 + nIndicatorLenAlphabet[nVerGroup] + (11 * (ncData / 2)) + (6 * (ncData % 2));
1237
+ break;
1238
+
1239
+ case QR_MODE_8BIT:
1240
+ ncBits = 4 + nIndicatorLen8Bit[nVerGroup] + (8 * ncData);
1241
+ break;
1242
+
1243
+ default: // case QR_MODE_KANJI:
1244
+ ncBits = 4 + nIndicatorLenKanji[nVerGroup] + (13 * (ncData / 2));
1245
+ break;
1246
+ }
1247
+
1248
+ return ncBits;
1249
+ }
1250
+
1251
+
1252
+ /////////////////////////////////////////////////////////////////////////////
1253
+ // CQR_Encode::SetBitStream
1254
+ // �p �r�F�r�b�g�Z�b�g
1255
+ // �� ���F�}���ʒu�A�r�b�g�z��f�[�^�A�f�[�^�r�b�g��(�ő�16)
1256
+ // �߂�l�F����}���ʒu(�o�b�t�@�I�[�o�[��=-1)
1257
+ // �� �l�Fm_byDataCodeWord �Ɍ��ʂ��Z�b�g(�v�[��������)
1258
+
1259
+ int CQR_Encode::SetBitStream(int nIndex, WORD wData, int ncData)
1260
+ {
1261
+ int i;
1262
+
1263
+ if (nIndex == -1 || nIndex + ncData > MAX_DATACODEWORD * 8)
1264
+ return -1;
1265
+
1266
+ for (i = 0; i < ncData; ++i)
1267
+ {
1268
+ if (wData & (1 << (ncData - i - 1)))
1269
+ {
1270
+ m_byDataCodeWord[(nIndex + i) / 8] |= 1 << (7 - ((nIndex + i) % 8));
1271
+ }
1272
+ }
1273
+
1274
+ return nIndex + ncData;
1275
+ }
1276
+
1277
+
1278
+ /////////////////////////////////////////////////////////////////////////////
1279
+ // CQR_Encode::IsNumeralData
1280
+ // �p �r�F�������[�h�Y���`�F�b�N
1281
+ // �� ���F��������
1282
+ // �߂�l�F�Y����=TRUE
1283
+
1284
+ BOOL CQR_Encode::IsNumeralData(unsigned char c)
1285
+ {
1286
+ if (c >= '0' && c <= '9')
1287
+ return TRUE;
1288
+
1289
+ return FALSE;
1290
+ }
1291
+
1292
+
1293
+ /////////////////////////////////////////////////////////////////////////////
1294
+ // CQR_Encode::IsAlphabetData
1295
+ // �p �r�F�p�������[�h�Y���`�F�b�N
1296
+ // �� ���F��������
1297
+ // �߂�l�F�Y����=TRUE
1298
+
1299
+ BOOL CQR_Encode::IsAlphabetData(unsigned char c)
1300
+ {
1301
+ if (c >= '0' && c <= '9')
1302
+ return TRUE;
1303
+
1304
+ if (c >= 'A' && c <= 'Z')
1305
+ return TRUE;
1306
+
1307
+ if (c == ' ' || c == '$' || c == '%' || c == '*' || c == '+' || c == '-' || c == '.' || c == '/' || c == ':')
1308
+ return TRUE;
1309
+
1310
+ return FALSE;
1311
+ }
1312
+
1313
+
1314
+ /////////////////////////////////////////////////////////////////////////////
1315
+ // CQR_Encode::IsKanjiData
1316
+ // �p �r�F�������[�h�Y���`�F�b�N
1317
+ // �� ���F���������i16�r�b�g�����j
1318
+ // �߂�l�F�Y����=TRUE
1319
+ // �� �l�FEBBFh �ȍ~�� S-JIS �͑ΏۊO
1320
+
1321
+ BOOL CQR_Encode::IsKanjiData(unsigned char c1, unsigned char c2)
1322
+ {
1323
+ if (((c1 >= 0x81 && c1 <= 0x9f) || (c1 >= 0xe0 && c1 <= 0xeb)) && (c2 >= 0x40))
1324
+ {
1325
+ if ((c1 == 0x9f && c2 > 0xfc) || (c1 == 0xeb && c2 > 0xbf))
1326
+ return FALSE;
1327
+
1328
+ return TRUE;
1329
+ }
1330
+
1331
+ return FALSE;
1332
+ }
1333
+
1334
+
1335
+ /////////////////////////////////////////////////////////////////////////////
1336
+ // CQR_Encode::AlphabetToBinaly
1337
+ // �p �r�F�p�������[�h�����̃o�C�i����
1338
+ // �� ���F�Ώە���
1339
+ // �߂�l�F�o�C�i���l
1340
+
1341
+ BYTE CQR_Encode::AlphabetToBinaly(unsigned char c)
1342
+ {
1343
+ if (c >= '0' && c <= '9') return (unsigned char)(c - '0');
1344
+
1345
+ if (c >= 'A' && c <= 'Z') return (unsigned char)(c - 'A' + 10);
1346
+
1347
+ if (c == ' ') return 36;
1348
+
1349
+ if (c == '$') return 37;
1350
+
1351
+ if (c == '%') return 38;
1352
+
1353
+ if (c == '*') return 39;
1354
+
1355
+ if (c == '+') return 40;
1356
+
1357
+ if (c == '-') return 41;
1358
+
1359
+ if (c == '.') return 42;
1360
+
1361
+ if (c == '/') return 43;
1362
+
1363
+ return 44; // c == ':'
1364
+ }
1365
+
1366
+
1367
+ /////////////////////////////////////////////////////////////////////////////
1368
+ // CQR_Encode::KanjiToBinaly
1369
+ // �p �r�F�������[�h�����̃o�C�i����
1370
+ // �� ���F�Ώە���
1371
+ // �߂�l�F�o�C�i���l
1372
+
1373
+ WORD CQR_Encode::KanjiToBinaly(WORD wc)
1374
+ {
1375
+ if (wc >= 0x8140 && wc <= 0x9ffc)
1376
+ wc -= 0x8140;
1377
+ else // (wc >= 0xe040 && wc <= 0xebbf)
1378
+ wc -= 0xc140;
1379
+
1380
+ return (WORD)(((wc >> 8) * 0xc0) + (wc & 0x00ff));
1381
+ }
1382
+
1383
+
1384
+ /////////////////////////////////////////////////////////////////////////////
1385
+ // CQR_Encode::GetRSCodeWord
1386
+ // �p �r�F�q�r�������R�[�h���[�h�擾
1387
+ // �� ���F�f�[�^�R�[�h���[�h�A�h���X�A�f�[�^�R�[�h���[�h���A�q�r�R�[�h���[�h��
1388
+ // �� �l�F���R�[�h���[�h���̃G���A���m�ۂ��Ă���Ăяo��
1389
+
1390
+ void CQR_Encode::GetRSCodeWord(LPBYTE lpbyRSWork, int ncDataCodeWord, int ncRSCodeWord)
1391
+ {
1392
+ int i, j;
1393
+
1394
+ for (i = 0; i < ncDataCodeWord ; ++i)
1395
+ {
1396
+ if (lpbyRSWork[0] != 0)
1397
+ {
1398
+ BYTE nExpFirst = byIntToExp[lpbyRSWork[0]]; // �����W�����搔�Z�o
1399
+
1400
+ for (j = 0; j < ncRSCodeWord; ++j)
1401
+ {
1402
+ // �e���搔�ɏ����搔�����Z�i% 255 �� ��^255 = 1�j
1403
+ BYTE nExpElement = (BYTE)(((int)(byRSExp[ncRSCodeWord][j] + nExpFirst)) % 255);
1404
+
1405
+ // �r���_���a�ɂ���]�Z�o
1406
+ lpbyRSWork[j] = (BYTE)(lpbyRSWork[j + 1] ^ byExpToInt[nExpElement]);
1407
+ }
1408
+
1409
+ // �c�茅���V�t�g
1410
+ for (j = ncRSCodeWord; j < ncDataCodeWord + ncRSCodeWord - 1; ++j)
1411
+ lpbyRSWork[j] = lpbyRSWork[j + 1];
1412
+ }
1413
+ else
1414
+ {
1415
+ // �c�茅���V�t�g
1416
+ for (j = 0; j < ncDataCodeWord + ncRSCodeWord - 1; ++j)
1417
+ lpbyRSWork[j] = lpbyRSWork[j + 1];
1418
+ }
1419
+ }
1420
+ }
1421
+
1422
+
1423
+ /////////////////////////////////////////////////////////////////////////////
1424
+ // CQR_Encode::FormatModule
1425
+ // �p �r�F���W���[���ւ̃f�[�^�z�u
1426
+ // �߂�l�F��ӂ̃��W���[����
1427
+
1428
+ void CQR_Encode::FormatModule()
1429
+ {
1430
+ int i, j;
1431
+
1432
+ ZeroMemory(m_byModuleData, sizeof(m_byModuleData));
1433
+
1434
+ // �@�\���W���[���z�u
1435
+ SetFunctionModule();
1436
+
1437
+ // �f�[�^�p�^�[���z�u
1438
+ SetCodeWordPattern();
1439
+
1440
+ if (m_nMaskingNo == -1)
1441
+ {
1442
+ // �œK�}�X�L���O�p�^�[���I��
1443
+ m_nMaskingNo = 0;
1444
+
1445
+ SetMaskingPattern(m_nMaskingNo); // �}�X�L���O
1446
+ SetFormatInfoPattern(m_nMaskingNo); // �t�H�[�}�b�g���p�^�[���z�u
1447
+
1448
+ int nMinPenalty = CountPenalty();
1449
+
1450
+ for (i = 1; i <= 7; ++i)
1451
+ {
1452
+ SetMaskingPattern(i); // �}�X�L���O
1453
+ SetFormatInfoPattern(i); // �t�H�[�}�b�g���p�^�[���z�u
1454
+
1455
+ int nPenalty = CountPenalty();
1456
+
1457
+ if (nPenalty < nMinPenalty)
1458
+ {
1459
+ nMinPenalty = nPenalty;
1460
+ m_nMaskingNo = i;
1461
+ }
1462
+ }
1463
+ }
1464
+
1465
+ SetMaskingPattern(m_nMaskingNo); // �}�X�L���O
1466
+ SetFormatInfoPattern(m_nMaskingNo); // �t�H�[�}�b�g���p�^�[���z�u
1467
+
1468
+ // ���W���[���p�^�[�����u�[���l�ɕϊ�
1469
+ for (i = 0; i < m_nSymbleSize; ++i)
1470
+ {
1471
+ for (j = 0; j < m_nSymbleSize; ++j)
1472
+ {
1473
+ m_byModuleData[i][j] = (BYTE)((m_byModuleData[i][j] & 0x11) != 0);
1474
+ }
1475
+ }
1476
+ }
1477
+
1478
+
1479
+ /////////////////////////////////////////////////////////////////////////////
1480
+ // CQR_Encode::SetFunctionModule
1481
+ // �p �r�F�@�\���W���[���z�u
1482
+ // �� �l�F�t�H�[�}�b�g���͋@�\���W���[���o�^�̂�(���f�[�^�͋�)
1483
+
1484
+ void CQR_Encode::SetFunctionModule()
1485
+ {
1486
+ int i, j;
1487
+
1488
+ // �ʒu���o�p�^�[��
1489
+ SetFinderPattern(0, 0);
1490
+ SetFinderPattern(m_nSymbleSize - 7, 0);
1491
+ SetFinderPattern(0, m_nSymbleSize - 7);
1492
+
1493
+ // �ʒu���o�p�^�[���Z�p���[�^
1494
+ for (i = 0; i < 8; ++i)
1495
+ {
1496
+ m_byModuleData[i][7] = m_byModuleData[7][i] = '\x20';
1497
+ m_byModuleData[m_nSymbleSize - 8][i] = m_byModuleData[m_nSymbleSize - 8 + i][7] = '\x20';
1498
+ m_byModuleData[i][m_nSymbleSize - 8] = m_byModuleData[7][m_nSymbleSize - 8 + i] = '\x20';
1499
+ }
1500
+
1501
+ // �t�H�[�}�b�g���L�q�ʒu���@�\���W���[�����Ƃ��ēo�^
1502
+ for (i = 0; i < 9; ++i)
1503
+ {
1504
+ m_byModuleData[i][8] = m_byModuleData[8][i] = '\x20';
1505
+ }
1506
+
1507
+ for (i = 0; i < 8; ++i)
1508
+ {
1509
+ m_byModuleData[m_nSymbleSize - 8 + i][8] = m_byModuleData[8][m_nSymbleSize - 8 + i] = '\x20';
1510
+ }
1511
+
1512
+ // �o�[�W�������p�^�[��
1513
+ SetVersionPattern();
1514
+
1515
+ // �ʒu���킹�p�^�[��
1516
+ for (i = 0; i < QR_VersonInfo[m_nVersion].ncAlignPoint; ++i)
1517
+ {
1518
+ SetAlignmentPattern(QR_VersonInfo[m_nVersion].nAlignPoint[i], 6);
1519
+ SetAlignmentPattern(6, QR_VersonInfo[m_nVersion].nAlignPoint[i]);
1520
+
1521
+ for (j = 0; j < QR_VersonInfo[m_nVersion].ncAlignPoint; ++j)
1522
+ {
1523
+ SetAlignmentPattern(QR_VersonInfo[m_nVersion].nAlignPoint[i], QR_VersonInfo[m_nVersion].nAlignPoint[j]);
1524
+ }
1525
+ }
1526
+
1527
+ // �^�C�~���O�p�^�[��
1528
+ for (i = 8; i <= m_nSymbleSize - 9; ++i)
1529
+ {
1530
+ m_byModuleData[i][6] = (i % 2) == 0 ? '\x30' : '\x20';
1531
+ m_byModuleData[6][i] = (i % 2) == 0 ? '\x30' : '\x20';
1532
+ }
1533
+ }
1534
+
1535
+
1536
+ /////////////////////////////////////////////////////////////////////////////
1537
+ // CQR_Encode::SetFinderPattern
1538
+ // �p �r�F�ʒu���o�p�^�[���z�u
1539
+ // �� ���F�z�u������W
1540
+
1541
+ void CQR_Encode::SetFinderPattern(int x, int y)
1542
+ {
1543
+ static BYTE byPattern[] = {0x7f, // 1111111b
1544
+ 0x41, // 1000001b
1545
+ 0x5d, // 1011101b
1546
+ 0x5d, // 1011101b
1547
+ 0x5d, // 1011101b
1548
+ 0x41, // 1000001b
1549
+ 0x7f}; // 1111111b
1550
+ int i, j;
1551
+
1552
+ for (i = 0; i < 7; ++i)
1553
+ {
1554
+ for (j = 0; j < 7; ++j)
1555
+ {
1556
+ m_byModuleData[x + j][y + i] = (byPattern[i] & (1 << (6 - j))) ? '\x30' : '\x20';
1557
+ }
1558
+ }
1559
+ }
1560
+
1561
+
1562
+ /////////////////////////////////////////////////////////////////////////////
1563
+ // CQR_Encode::SetAlignmentPattern
1564
+ // �p �r�F�ʒu���킹�p�^�[���z�u
1565
+ // �� ���F�z�u�������W
1566
+
1567
+ void CQR_Encode::SetAlignmentPattern(int x, int y)
1568
+ {
1569
+ static BYTE byPattern[] = {0x1f, // 11111b
1570
+ 0x11, // 10001b
1571
+ 0x15, // 10101b
1572
+ 0x11, // 10001b
1573
+ 0x1f}; // 11111b
1574
+ int i, j;
1575
+
1576
+ if (m_byModuleData[x][y] & 0x20)
1577
+ return; // �@�\���W���[���Əd�����邽�ߏ��O
1578
+
1579
+ x -= 2; y -= 2; // ��������W�ɕϊ�
1580
+
1581
+ for (i = 0; i < 5; ++i)
1582
+ {
1583
+ for (j = 0; j < 5; ++j)
1584
+ {
1585
+ m_byModuleData[x + j][y + i] = (byPattern[i] & (1 << (4 - j))) ? '\x30' : '\x20';
1586
+ }
1587
+ }
1588
+ }
1589
+
1590
+
1591
+ /////////////////////////////////////////////////////////////////////////////
1592
+ // CQR_Encode::SetVersionPattern
1593
+ // �p �r�F�o�[�W����(�^��)���p�^�[���z�u
1594
+ // �� �l�F�g���a�b�g(18,6)�������������Ƃ��Ďg�p
1595
+
1596
+ void CQR_Encode::SetVersionPattern()
1597
+ {
1598
+ int i, j;
1599
+
1600
+ if (m_nVersion <= 6)
1601
+ return;
1602
+
1603
+ int nVerData = m_nVersion << 12;
1604
+
1605
+ // ��]�r�b�g�Z�o
1606
+ for (i = 0; i < 6; ++i)
1607
+ {
1608
+ if (nVerData & (1 << (17 - i)))
1609
+ {
1610
+ nVerData ^= (0x1f25 << (5 - i));
1611
+ }
1612
+ }
1613
+
1614
+ nVerData += m_nVersion << 12;
1615
+
1616
+ for (i = 0; i < 6; ++i)
1617
+ {
1618
+ for (j = 0; j < 3; ++j)
1619
+ {
1620
+ m_byModuleData[m_nSymbleSize - 11 + j][i] = m_byModuleData[i][m_nSymbleSize - 11 + j] =
1621
+ (nVerData & (1 << (i * 3 + j))) ? '\x30' : '\x20';
1622
+ }
1623
+ }
1624
+ }
1625
+
1626
+
1627
+ /////////////////////////////////////////////////////////////////////////////
1628
+ // CQR_Encode::SetCodeWordPattern
1629
+ // �p �r�F�f�[�^�p�^�[���z�u
1630
+
1631
+ void CQR_Encode::SetCodeWordPattern()
1632
+ {
1633
+ int x = m_nSymbleSize;
1634
+ int y = m_nSymbleSize - 1;
1635
+
1636
+ int nCoef_x = 1; // �����z�u����
1637
+ int nCoef_y = 1; // �����z�u����
1638
+
1639
+ int i, j;
1640
+
1641
+ for (i = 0; i < m_ncAllCodeWord; ++i)
1642
+ {
1643
+ for (j = 0; j < 8; ++j)
1644
+ {
1645
+ do
1646
+ {
1647
+ x += nCoef_x;
1648
+ nCoef_x *= -1;
1649
+
1650
+ if (nCoef_x < 0)
1651
+ {
1652
+ y += nCoef_y;
1653
+
1654
+ if (y < 0 || y == m_nSymbleSize)
1655
+ {
1656
+ y = (y < 0) ? 0 : m_nSymbleSize - 1;
1657
+ nCoef_y *= -1;
1658
+
1659
+ x -= 2;
1660
+
1661
+ if (x == 6) // �^�C�~���O�p�^�[��
1662
+ --x;
1663
+ }
1664
+ }
1665
+ }
1666
+ while (m_byModuleData[x][y] & 0x20); // �@�\���W���[�������O
1667
+
1668
+ m_byModuleData[x][y] = (m_byAllCodeWord[i] & (1 << (7 - j))) ? '\x02' : '\x00';
1669
+ }
1670
+ }
1671
+ }
1672
+
1673
+
1674
+ /////////////////////////////////////////////////////////////////////////////
1675
+ // CQR_Encode::SetMaskingPattern
1676
+ // �p �r�F�}�X�L���O�p�^�[���z�u
1677
+ // �� ���F�}�X�L���O�p�^�[���ԍ�
1678
+
1679
+ void CQR_Encode::SetMaskingPattern(int nPatternNo)
1680
+ {
1681
+ int i, j;
1682
+
1683
+ for (i = 0; i < m_nSymbleSize; ++i)
1684
+ {
1685
+ for (j = 0; j < m_nSymbleSize; ++j)
1686
+ {
1687
+ if (! (m_byModuleData[j][i] & 0x20)) // �@�\���W���[�������O
1688
+ {
1689
+ BOOL bMask;
1690
+
1691
+ switch (nPatternNo)
1692
+ {
1693
+ case 0:
1694
+ bMask = ((i + j) % 2 == 0);
1695
+ break;
1696
+
1697
+ case 1:
1698
+ bMask = (i % 2 == 0);
1699
+ break;
1700
+
1701
+ case 2:
1702
+ bMask = (j % 3 == 0);
1703
+ break;
1704
+
1705
+ case 3:
1706
+ bMask = ((i + j) % 3 == 0);
1707
+ break;
1708
+
1709
+ case 4:
1710
+ bMask = (((i / 2) + (j / 3)) % 2 == 0);
1711
+ break;
1712
+
1713
+ case 5:
1714
+ bMask = (((i * j) % 2) + ((i * j) % 3) == 0);
1715
+ break;
1716
+
1717
+ case 6:
1718
+ bMask = ((((i * j) % 2) + ((i * j) % 3)) % 2 == 0);
1719
+ break;
1720
+
1721
+ default: // case 7:
1722
+ bMask = ((((i * j) % 3) + ((i + j) % 2)) % 2 == 0);
1723
+ break;
1724
+ }
1725
+
1726
+ m_byModuleData[j][i] = (BYTE)((m_byModuleData[j][i] & 0xfe) | (((m_byModuleData[j][i] & 0x02) > 1) ^ bMask));
1727
+ }
1728
+ }
1729
+ }
1730
+ }
1731
+
1732
+
1733
+ /////////////////////////////////////////////////////////////////////////////
1734
+ // CQR_Encode::SetFormatInfoPattern
1735
+ // �p �r�F�t�H�[�}�b�g���z�u
1736
+ // �� ���F�}�X�L���O�p�^�[���ԍ�
1737
+
1738
+ void CQR_Encode::SetFormatInfoPattern(int nPatternNo)
1739
+ {
1740
+ int nFormatInfo;
1741
+ int i;
1742
+
1743
+ switch (m_nLevel)
1744
+ {
1745
+ case QR_LEVEL_M:
1746
+ nFormatInfo = 0x00; // 00nnnb
1747
+ break;
1748
+
1749
+ case QR_LEVEL_L:
1750
+ nFormatInfo = 0x08; // 01nnnb
1751
+ break;
1752
+
1753
+ case QR_LEVEL_Q:
1754
+ nFormatInfo = 0x18; // 11nnnb
1755
+ break;
1756
+
1757
+ default: // case QR_LEVEL_H:
1758
+ nFormatInfo = 0x10; // 10nnnb
1759
+ break;
1760
+ }
1761
+
1762
+ nFormatInfo += nPatternNo;
1763
+
1764
+ int nFormatData = nFormatInfo << 10;
1765
+
1766
+ // ��]�r�b�g�Z�o
1767
+ for (i = 0; i < 5; ++i)
1768
+ {
1769
+ if (nFormatData & (1 << (14 - i)))
1770
+ {
1771
+ nFormatData ^= (0x0537 << (4 - i)); // 10100110111b
1772
+ }
1773
+ }
1774
+
1775
+ nFormatData += nFormatInfo << 10;
1776
+
1777
+ // �}�X�L���O
1778
+ nFormatData ^= 0x5412; // 101010000010010b
1779
+
1780
+ // ����ʒu���o�p�^�[������z�u
1781
+ for (i = 0; i <= 5; ++i)
1782
+ m_byModuleData[8][i] = (nFormatData & (1 << i)) ? '\x30' : '\x20';
1783
+
1784
+ m_byModuleData[8][7] = (nFormatData & (1 << 6)) ? '\x30' : '\x20';
1785
+ m_byModuleData[8][8] = (nFormatData & (1 << 7)) ? '\x30' : '\x20';
1786
+ m_byModuleData[7][8] = (nFormatData & (1 << 8)) ? '\x30' : '\x20';
1787
+
1788
+ for (i = 9; i <= 14; ++i)
1789
+ m_byModuleData[14 - i][8] = (nFormatData & (1 << i)) ? '\x30' : '\x20';
1790
+
1791
+ // �E��ʒu���o�p�^�[�����z�u
1792
+ for (i = 0; i <= 7; ++i)
1793
+ m_byModuleData[m_nSymbleSize - 1 - i][8] = (nFormatData & (1 << i)) ? '\x30' : '\x20';
1794
+
1795
+ // �����ʒu���o�p�^�[���E�z�u
1796
+ m_byModuleData[8][m_nSymbleSize - 8] = '\x30'; // �Œ�Ã��W���[��
1797
+
1798
+ for (i = 8; i <= 14; ++i)
1799
+ m_byModuleData[8][m_nSymbleSize - 15 + i] = (nFormatData & (1 << i)) ? '\x30' : '\x20';
1800
+ }
1801
+
1802
+
1803
+ /////////////////////////////////////////////////////////////////////////////
1804
+ // CQR_Encode::CountPenalty
1805
+ // �p �r�F�}�X�N��y�i���e�B�X�R�A�Z�o
1806
+
1807
+ int CQR_Encode::CountPenalty()
1808
+ {
1809
+ int nPenalty = 0;
1810
+ int i, j, k;
1811
+
1812
+ // ���F�̗�̗אڃ��W���[��
1813
+ for (i = 0; i < m_nSymbleSize; ++i)
1814
+ {
1815
+ for (j = 0; j < m_nSymbleSize - 4; ++j)
1816
+ {
1817
+ int nCount = 1;
1818
+
1819
+ for (k = j + 1; k < m_nSymbleSize; k++)
1820
+ {
1821
+ if (((m_byModuleData[i][j] & 0x11) == 0) == ((m_byModuleData[i][k] & 0x11) == 0))
1822
+ ++nCount;
1823
+ else
1824
+ break;
1825
+ }
1826
+
1827
+ if (nCount >= 5)
1828
+ {
1829
+ nPenalty += 3 + (nCount - 5);
1830
+ }
1831
+
1832
+ j = k - 1;
1833
+ }
1834
+ }
1835
+
1836
+ // ���F�̍s�̗אڃ��W���[��
1837
+ for (i = 0; i < m_nSymbleSize; ++i)
1838
+ {
1839
+ for (j = 0; j < m_nSymbleSize - 4; ++j)
1840
+ {
1841
+ int nCount = 1;
1842
+
1843
+ for (k = j + 1; k < m_nSymbleSize; k++)
1844
+ {
1845
+ if (((m_byModuleData[j][i] & 0x11) == 0) == ((m_byModuleData[k][i] & 0x11) == 0))
1846
+ ++nCount;
1847
+ else
1848
+ break;
1849
+ }
1850
+
1851
+ if (nCount >= 5)
1852
+ {
1853
+ nPenalty += 3 + (nCount - 5);
1854
+ }
1855
+
1856
+ j = k - 1;
1857
+ }
1858
+ }
1859
+
1860
+ // ���F�̃��W���[���u���b�N�i�Q�~�Q�j
1861
+ for (i = 0; i < m_nSymbleSize - 1; ++i)
1862
+ {
1863
+ for (j = 0; j < m_nSymbleSize - 1; ++j)
1864
+ {
1865
+ if ((((m_byModuleData[i][j] & 0x11) == 0) == ((m_byModuleData[i + 1][j] & 0x11) == 0)) &&
1866
+ (((m_byModuleData[i][j] & 0x11) == 0) == ((m_byModuleData[i] [j + 1] & 0x11) == 0)) &&
1867
+ (((m_byModuleData[i][j] & 0x11) == 0) == ((m_byModuleData[i + 1][j + 1] & 0x11) == 0)))
1868
+ {
1869
+ nPenalty += 3;
1870
+ }
1871
+ }
1872
+ }
1873
+
1874
+ // �����ɂ����� 1:1:3:1:1 �䗦�i��:��:��:��:�Áj�̃p�^�[��
1875
+ for (i = 0; i < m_nSymbleSize; ++i)
1876
+ {
1877
+ for (j = 0; j < m_nSymbleSize - 6; ++j)
1878
+ {
1879
+ if (((j == 0) || (! (m_byModuleData[i][j - 1] & 0x11))) && // �� �܂��� �V���{���O
1880
+ ( m_byModuleData[i][j] & 0x11) && // �� - 1
1881
+ (! (m_byModuleData[i][j + 1] & 0x11)) && // �� - 1
1882
+ ( m_byModuleData[i][j + 2] & 0x11) && // �� ��
1883
+ ( m_byModuleData[i][j + 3] & 0x11) && // �� ��3
1884
+ ( m_byModuleData[i][j + 4] & 0x11) && // �� ��
1885
+ (! (m_byModuleData[i][j + 5] & 0x11)) && // �� - 1
1886
+ ( m_byModuleData[i][j + 6] & 0x11) && // �� - 1
1887
+ ((j == m_nSymbleSize - 7) || (! (m_byModuleData[i][j + 7] & 0x11)))) // �� �܂��� �V���{���O
1888
+ {
1889
+ // �O�܂��͌��4�ȏ�̖��p�^�[��
1890
+ if (((j < 2 || ! (m_byModuleData[i][j - 2] & 0x11)) &&
1891
+ (j < 3 || ! (m_byModuleData[i][j - 3] & 0x11)) &&
1892
+ (j < 4 || ! (m_byModuleData[i][j - 4] & 0x11))) ||
1893
+ ((j >= m_nSymbleSize - 8 || ! (m_byModuleData[i][j + 8] & 0x11)) &&
1894
+ (j >= m_nSymbleSize - 9 || ! (m_byModuleData[i][j + 9] & 0x11)) &&
1895
+ (j >= m_nSymbleSize - 10 || ! (m_byModuleData[i][j + 10] & 0x11))))
1896
+ {
1897
+ nPenalty += 40;
1898
+ }
1899
+ }
1900
+ }
1901
+ }
1902
+
1903
+ // ����s�ɂ����� 1:1:3:1:1 �䗦�i��:��:��:��:�Áj�̃p�^�[��
1904
+ for (i = 0; i < m_nSymbleSize; ++i)
1905
+ {
1906
+ for (j = 0; j < m_nSymbleSize - 6; ++j)
1907
+ {
1908
+ if (((j == 0) || (! (m_byModuleData[j - 1][i] & 0x11))) && // �� �܂��� �V���{���O
1909
+ ( m_byModuleData[j] [i] & 0x11) && // �� - 1
1910
+ (! (m_byModuleData[j + 1][i] & 0x11)) && // �� - 1
1911
+ ( m_byModuleData[j + 2][i] & 0x11) && // �� ��
1912
+ ( m_byModuleData[j + 3][i] & 0x11) && // �� ��3
1913
+ ( m_byModuleData[j + 4][i] & 0x11) && // �� ��
1914
+ (! (m_byModuleData[j + 5][i] & 0x11)) && // �� - 1
1915
+ ( m_byModuleData[j + 6][i] & 0x11) && // �� - 1
1916
+ ((j == m_nSymbleSize - 7) || (! (m_byModuleData[j + 7][i] & 0x11)))) // �� �܂��� �V���{���O
1917
+ {
1918
+ // �O�܂��͌��4�ȏ�̖��p�^�[��
1919
+ if (((j < 2 || ! (m_byModuleData[j - 2][i] & 0x11)) &&
1920
+ (j < 3 || ! (m_byModuleData[j - 3][i] & 0x11)) &&
1921
+ (j < 4 || ! (m_byModuleData[j - 4][i] & 0x11))) ||
1922
+ ((j >= m_nSymbleSize - 8 || ! (m_byModuleData[j + 8][i] & 0x11)) &&
1923
+ (j >= m_nSymbleSize - 9 || ! (m_byModuleData[j + 9][i] & 0x11)) &&
1924
+ (j >= m_nSymbleSize - 10 || ! (m_byModuleData[j + 10][i] & 0x11))))
1925
+ {
1926
+ nPenalty += 40;
1927
+ }
1928
+ }
1929
+ }
1930
+ }
1931
+
1932
+ // �S�̂ɑ΂���Ã��W���[���̐�߂銄��
1933
+ int nCount = 0;
1934
+
1935
+ for (i = 0; i < m_nSymbleSize; ++i)
1936
+ {
1937
+ for (j = 0; j < m_nSymbleSize; ++j)
1938
+ {
1939
+ if (! (m_byModuleData[i][j] & 0x11))
1940
+ {
1941
+ ++nCount;
1942
+ }
1943
+ }
1944
+ }
1945
+
1946
+ nPenalty += (abs(50 - ((nCount * 100) / (m_nSymbleSize * m_nSymbleSize))) / 5) * 10;
1947
+
1948
+ return nPenalty;
1949
+ }