OSDN Git Service

* updated copyright.
[modchxj/mod_chxj.git] / src / chxj_calc_ecc.c
1 /*
2  * Copyright (C) 2005-2011 Atsushi Konno All rights reserved.
3  * Copyright (C) 2005 QSDN,Inc. All rights reserved.
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  *     http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */
17 #include "chxj_qr_code.h"
18 #include "chxj_calc_ecc.h"
19 #include "apr.h"
20 #include "apr_strings.h"
21 #include "http_log.h"
22 #include <assert.h>
23 /*
24 #define QR_CODE_DEBUG
25 */
26
27 /*----------------------------------------------------------------------------*/
28 /* »Ø¿ô¢ªÀ°¿ô                                                                 */
29 /*----------------------------------------------------------------------------*/
30 static const unsigned int v_galois_log_to_int[] = {
31   1, 2, 4, 8, 16, 32, 64, 128,
32   29, 58, 116, 232, 205, 135, 19, 38,
33   76, 152, 45, 90, 180, 117, 234, 201,
34   143, 3, 6, 12, 24, 48, 96, 192,
35   157, 39, 78, 156, 37, 74, 148, 53,
36   106, 212, 181, 119, 238, 193, 159, 35,
37   70, 140, 5, 10, 20, 40, 80, 160,
38   93, 186, 105, 210, 185, 111, 222, 161,
39   95, 190, 97, 194, 153, 47, 94, 188,
40   101, 202, 137, 15, 30, 60, 120, 240,
41   253, 231, 211, 187, 107, 214, 177, 127,
42   254, 225, 223, 163, 91, 182, 113, 226,
43   217, 175, 67, 134, 17, 34, 68, 136,
44   13, 26, 52, 104, 208, 189, 103, 206,
45   129, 31, 62, 124, 248, 237, 199, 147,
46   59, 118, 236, 197, 151, 51, 102, 204,
47   133, 23, 46, 92, 184, 109, 218, 169,
48   79, 158, 33, 66, 132, 21, 42, 84,
49   168, 77, 154, 41, 82, 164, 85, 170,
50   73, 146, 57, 114, 228, 213, 183, 115,
51   230, 209, 191, 99, 198, 145, 63, 126,
52   252, 229, 215, 179, 123, 246, 241, 255,
53   227, 219, 171, 75, 150, 49, 98, 196,
54   149, 55, 110, 220, 165, 87, 174, 65,
55   130, 25, 50, 100, 200, 141, 7, 14,
56   28, 56, 112, 224, 221, 167, 83, 166,
57   81, 162, 89, 178, 121, 242, 249, 239,
58   195, 155, 43, 86, 172, 69, 138, 9,
59   18, 36, 72, 144, 61, 122, 244, 245,
60   247, 243, 251, 235, 203, 139, 11, 22,
61   44, 88, 176, 125, 250, 233, 207, 131,
62   27, 54, 108, 216, 173, 71, 142, 1,
63   2, 4, 8, 16, 32, 64, 128, 29,
64   58, 116, 232, 205, 135, 19, 38, 76,
65   152, 45, 90, 180, 117, 234, 201, 143,
66   3, 6, 12, 24, 48, 96, 192, 157,
67   39, 78, 156, 37, 74, 148, 53, 106,
68   212, 181, 119, 238, 193, 159, 35, 70,
69   140, 5, 10, 20, 40, 80, 160, 93,
70   186, 105, 210, 185, 111, 222, 161, 95,
71   190, 97, 194, 153, 47, 94, 188, 101,
72   202, 137, 15, 30, 60, 120, 240, 253,
73   231, 211, 187, 107, 214, 177, 127, 254,
74   225, 223, 163, 91, 182, 113, 226, 217,
75   175, 67, 134, 17, 34, 68, 136, 13,
76   26, 52, 104, 208, 189, 103, 206, 129,
77   31, 62, 124, 248, 237, 199, 147, 59,
78   118, 236, 197, 151, 51, 102, 204, 133,
79   23, 46, 92, 184, 109, 218, 169, 79,
80   158, 33, 66, 132, 21, 42, 84, 168,
81   77, 154, 41, 82, 164, 85, 170, 73,
82   146, 57, 114, 228, 213, 183, 115, 230,
83   209, 191, 99, 198, 145, 63, 126, 252,
84   229, 215, 179, 123, 246, 241, 255, 227,
85   219, 171, 75, 150, 49, 98, 196, 149,
86   55, 110, 220, 165, 87, 174, 65, 130,
87   25, 50, 100, 200, 141, 7, 14, 28,
88   56, 112, 224, 221, 167, 83, 166, 81,
89   162, 89, 178, 121, 242, 249, 239, 195,
90   155, 43, 86, 172, 69, 138, 9, 18,
91   36, 72, 144, 61, 122, 244, 245, 247,
92   243, 251, 235, 203, 139, 11, 22, 44,
93   88, 176, 125, 250, 233, 207, 131, 27,
94   54, 108, 216, 173, 71, 142, 1, 0,
95 };
96
97 /*----------------------------------------------------------------------------*/
98 /* À°¿ô¢ª»Ø¿ô                                                                 */
99 /*----------------------------------------------------------------------------*/
100 static const unsigned int v_galois_int_to_log[] = {
101   0, 0, 1, 25, 2, 50, 26, 198, 3,
102   223, 51, 238, 27, 104, 199, 75, 4,
103   100, 224, 14, 52, 141, 239, 129, 28,
104   193, 105, 248, 200, 8, 76, 113, 5,
105   138, 101, 47, 225, 36, 15, 33, 53,
106   147, 142, 218, 240, 18, 130, 69, 29,
107   181, 194, 125, 106, 39, 249, 185, 201,
108   154, 9, 120, 77, 228, 114, 166, 6,
109   191, 139, 98, 102, 221, 48, 253, 226,
110   152, 37, 179, 16, 145, 34, 136, 54,
111   208, 148, 206, 143, 150, 219, 189, 241,
112   210, 19, 92, 131, 56, 70, 64, 30,
113   66, 182, 163, 195, 72, 126, 110, 107,
114   58, 40, 84, 250, 133, 186, 61, 202,
115   94, 155, 159, 10, 21, 121, 43, 78,
116   212, 229, 172, 115, 243, 167, 87, 7,
117   112, 192, 247, 140, 128, 99, 13, 103,
118   74, 222, 237, 49, 197, 254, 24, 227,
119   165, 153, 119, 38, 184, 180, 124, 17,
120   68, 146, 217, 35, 32, 137, 46, 55,
121   63, 209, 91, 149, 188, 207, 205, 144,
122   135, 151, 178, 220, 252, 190, 97, 242,
123   86, 211, 171, 20, 42, 93, 158, 132,
124   60, 57, 83, 71, 109, 65, 162, 31,
125   45, 67, 216, 183, 123, 164, 118, 196,
126   23, 73, 236, 127, 12, 111, 246, 108,
127   161, 59, 82, 41, 157, 85, 170, 251,
128   96, 134, 177, 187, 204, 62, 90, 203,
129   89, 95, 176, 156, 169, 160, 81, 11,
130   245, 22, 235, 122, 117, 44, 215, 79,
131   174, 213, 233, 230, 231, 173, 232, 116,
132   214, 244, 234, 168, 80, 88, 175, 
133 };
134
135 /*----------------------------------------------------------------------------*/
136 /* À¸À®Â¿¹à¼° - ¸í¤êÄûÀµ¥³¡¼¥É¿ô7 ¤ò¤¢¤é¤ï¤¹                                  */
137 /* x^7 + ¦Á^87x^6 + ¦Á^229x^5 + ¦Á^146x^4 + ¦Á^149x^3 + ¦Á^238x^2 + ¦Á^102x   */
138 /* + ¦Á^21                                                                    */
139 /* ¤Î¦Á¤Î»Ø¿ô¤òÇÛÎó¤Ë¤â¤Ä                                                     */
140 /*----------------------------------------------------------------------------*/
141 static const int v_poly_ecc7[] = {
142   21, 102,238,149,146,229,87,0,
143 };
144 /*----------------------------------------------------------------------------*/
145 /* À¸À®Â¿¹à¼° - ¸í¤êÄûÀµ¥³¡¼¥É¿ô10 ¤ò¤¢¤é¤ï¤¹                                 */
146 /* JIS X0510 : x10¡Ü¦Á251x9¡Ü¦Á67x8¡Ü¦Á61x6¡Ü¦Á118x5¡Ü¦Á70x4¡Ü¦Á64x3¡Ü        */
147 /*             ¦Á94x2¡Ü¦Á32x¡Ü¦Á45                                            */
148 /* Àµ²ò:       x10¡Ü¦Á251x9¡Ü¦Á67x8¡Ü¦Á46x7¡Ü¦Á61x6¡Ü¦Á118x5¡Ü¦Á70x4¡Ü        */
149 /*             ¦Á64x3¡Ü¦Á94x2¡Ü¦Á32x¡Ü¦Á45                                    */
150 /* JIS X510¤Ç¤Ïx7¤Î¹à¤¬Â¸ºß¤·¤Ê¤¤¡£                                           */
151 /*----------------------------------------------------------------------------*/
152 static const int v_poly_ecc10[] = {
153   45, 32, 94, 64, 70, 118, 61, 46, 67, 251, 0,
154 };
155
156 /*----------------------------------------------------------------------------*/
157 /* À¸À®Â¿¹à¼° - ¸í¤êÄûÀµ¥³¡¼¥É¿ô13 ¤ò¤¢¤é¤ï¤¹                                 */
158 /*----------------------------------------------------------------------------*/
159 static const int v_poly_ecc13[] = {
160   78, 140, 206, 218, 130, 104, 106, 100,
161   86, 100, 176, 152, 74, 0,
162 };
163 /*----------------------------------------------------------------------------*/
164 /* À¸À®Â¿¹à¼° - ¸í¤êÄûÀµ¥³¡¼¥É¿ô15 ¤ò¤¢¤é¤ï¤¹                                 */
165 /*----------------------------------------------------------------------------*/
166 static const int v_poly_ecc15[] = {
167   105, 99, 5, 124, 140, 237, 58, 58, 
168   51, 37, 202, 91, 61, 183, 8, 0,
169 };
170 /*----------------------------------------------------------------------------*/
171 /* À¸À®Â¿¹à¼° - ¸í¤êÄûÀµ¥³¡¼¥É¿ô16 ¤ò¤¢¤é¤ï¤¹                                 */
172 /*----------------------------------------------------------------------------*/
173 static const int v_poly_ecc16[] = {
174   120, 225, 194, 182, 169, 147, 191, 91,
175   3, 76, 161, 102, 109, 107, 104, 120, 0,
176 };
177 /*----------------------------------------------------------------------------*/
178 /* À¸À®Â¿¹à¼° - ¸í¤êÄûÀµ¥³¡¼¥É¿ô17 ¤ò¤¢¤é¤ï¤¹                                 */
179 /*----------------------------------------------------------------------------*/
180 static const int v_poly_ecc17[] = {
181   136,163,243,39,150,99,24,147,214,206,
182   123,239,43,78,206,139,43,0,
183 };
184 /*----------------------------------------------------------------------------*/
185 /* À¸À®Â¿¹à¼° - ¸í¤êÄûÀµ¥³¡¼¥É¿ô18 ¤ò¤¢¤é¤ï¤¹                                 */
186 /*----------------------------------------------------------------------------*/
187 static const int v_poly_ecc18[] = {
188   153, 96, 98, 5, 179, 252, 148, 152,
189   187, 79, 170, 118, 97, 184, 94, 158,
190   234, 215, 0,
191 };
192 /*----------------------------------------------------------------------------*/
193 /* À¸À®Â¿¹à¼° - ¸í¤êÄûÀµ¥³¡¼¥É¿ô20 ¤ò¤¢¤é¤ï¤¹                                 */
194 /*----------------------------------------------------------------------------*/
195 static const int v_poly_ecc20[] = {
196   190, 188, 212, 212, 164, 156, 239, 83,
197   225, 221, 180, 202, 187, 26, 163, 61,
198   50, 79, 60, 17, 0,
199 };
200 /*----------------------------------------------------------------------------*/
201 /* À¸À®Â¿¹à¼° - ¸í¤êÄûÀµ¥³¡¼¥É¿ô22 ¤ò¤¢¤é¤ï¤¹                                 */
202 /* x22¡Ü¦Á210x21¡Ü¦Á171x20¡Ü¦Á247x19¡Ü¦Á242x18¡Ü¦Á93x17¡Ü¦Á230x16¡Ü¦Á14x15¡Ü  */
203 /* ¦Á109x14¡Ü¦Á221x13¡Ü¦Á53x12¡Ü¦Á200x11¡Ü¦Á74x10¡Ü¦Á8x9¡Ü¦Á172x8¡Ü¦Á98x7¡Ü   */
204 /* ¦Á80x6¡Ü¦Á219x5¡Ü¦Á134x4¡Ü¦Á160x3¡Ü¦Á105x2¡Ü¦Á165x¡Ü¦Á231                  */
205 /*----------------------------------------------------------------------------*/
206 static const int v_poly_ecc22[] = {
207   231, 165, 105, 160, 134, 219, 80, 98,
208   172, 8, 74, 200, 53, 221, 109, 14, 
209   230, 93, 242, 247, 171, 210, 0,
210 };
211
212 /*----------------------------------------------------------------------------*/
213 /* À¸À®Â¿¹à¼° - ¸í¤êÄûÀµ¥³¡¼¥É¿ô24 ¤ò¤¢¤é¤ï¤¹                                 */
214 /* x24¡Ü ¦Á229x23¡Ü ¦Á121x22¡Ü ¦Á135x21¡Ü ¦Á48x20¡Ü ¦Á211x19¡Ü ¦Á117x18¡Ü     */
215 /* ¦Á251x17¡Ü¦Á126x16¡Ü¦Á159x15¡Ü ¦Á180x14¡Ü ¦Á169x13¡Ü ¦Á152x12¡Ü ¦Á192x11¡Ü */
216 /* ¦Á226x10¡Ü ¦Á228x9¡Ü ¦Á218x8¡Ü ¦Á111x7¡Üx6¡Ü ¦Á117x5¡Ü ¦Á232x4¡Ü ¦Á87x3¡Ü  */
217 /* ¦Á96x2¡Ü ¦Á227x¡Ü ¦Á21                                                     */
218 /*----------------------------------------------------------------------------*/
219 static const int v_poly_ecc24[] = {
220   21, 227, 96, 87, 232, 117, 0, 111,
221   218, 228, 226, 192, 152, 169, 180, 159,
222   126, 251, 117, 211, 48, 135, 121, 229,
223   0,
224 };
225
226 /*----------------------------------------------------------------------------*/
227 /* À¸À®Â¿¹à¼° - ¸í¤êÄûÀµ¥³¡¼¥É¿ô26 ¤ò¤¢¤é¤ï¤¹                                 */
228 /*----------------------------------------------------------------------------*/
229 static const int v_poly_ecc26[] = {
230   70, 218, 145, 153, 227, 48, 102, 13,
231   142, 245, 21, 161, 53, 165, 28, 111,
232   201, 145, 17, 118, 182, 103, 2, 158,
233   125, 173, 0,
234 };
235 /*----------------------------------------------------------------------------*/
236 /* À¸À®Â¿¹à¼° - ¸í¤êÄûÀµ¥³¡¼¥É¿ô28 ¤ò¤¢¤é¤ï¤¹                                 */
237 /* x28¡Ü ¦Á168x27¡Ü ¦Á223x26¡Ü ¦Á200x25¡Ü ¦Á104x24¡Ü ¦Á224x23¡Ü ¦Á234x22¡Ü    */
238 /* ¦Á108x21¡Ü ¦Á180x20 ¡Ü ¦Á110x19¡Ü ¦Á190x18¡Ü ¦Á195x17¡Ü ¦Á147x16¡Ü         */
239 /* ¦Á205x15¡Ü ¦Á27x14¡Ü ¦Á232x13¡Ü ¦Á201x12 ¡Ü ¦Á21x11¡Ü ¦Á43x10¡Ü ¦Á245x9¡Ü  */
240 /* ¦Á87x8¡Ü ¦Á42x7¡Ü ¦Á195x6¡Ü ¦Á212x5¡Ü ¦Á119x4¡Ü ¦Á242x3¡Ü ¦Á37x2¡Ü ¦Á9x¡Ü  */
241 /* ¦Á123                                                                      */
242 /*----------------------------------------------------------------------------*/
243 static const int v_poly_ecc28[] = {
244   123, 9, 37, 242, 119, 212, 195, 42,
245   87, 245, 43, 21, 201, 232, 27, 205,
246   147, 195, 190, 110, 180, 108, 234, 224,
247   104, 200, 223, 168, 0,
248 };
249 /*----------------------------------------------------------------------------*/
250 /* À¸À®Â¿¹à¼° - ¸í¤êÄûÀµ¥³¡¼¥É¿ô30 ¤ò¤¢¤é¤ï¤¹                                 */
251 /* x30¡Ü ¦Á41x29¡Ü ¦Á173x28¡Ü ¦Á145x27¡Ü ¦Á152x26¡Ü ¦Á216x25¡Ü ¦Á31x24¡Ü      */
252 /* ¦Á179x23¡Ü ¦Á182x22 ¡Ü ¦Á50x21¡Ü ¦Á48x20¡Ü ¦Á110x19¡Ü ¦Á86x18¡Ü ¦Á239x17¡Ü */
253 /* ¦Á96x16¡Ü ¦Á222x15¡Ü ¦Á125x14¡Ü ¦Á42x13¡Ü ¦Á173x12¡Ü ¦Á226x11¡Ü ¦Á193x10¡Ü */
254 /* ¦Á224x9¡Ü ¦Á130x8¡Ü ¦Á156x7¡Ü ¦Á37x6¡Ü ¦Á251x5 ¡Ü ¦Á216x4¡Ü ¦Á238x3¡Ü      */
255 /* ¦Á40x2¡Ü ¦Á192x¡Ü ¦Á180                                                    */
256 /*----------------------------------------------------------------------------*/
257 static const int v_poly_ecc30[] = {
258   180, 192, 40, 238, 216, 251, 37, 156,
259   130, 224, 193, 226, 173, 42, 125, 222,
260   96, 239, 86, 110, 48, 50, 182, 179,
261   31, 216, 152, 145, 173, 41, 0,
262 };
263 /*----------------------------------------------------------------------------*/
264 /* À¸À®Â¿¹à¼° - ¸í¤êÄûÀµ¥³¡¼¥É¿ô32 ¤ò¤¢¤é¤ï¤¹                                 */
265 /* x32¡Ü ¦Á10x31¡Ü ¦Á6x30¡Ü ¦Á106x29¡Ü ¦Á190x28¡Ü ¦Á249x27¡Ü ¦Á167x26¡Ü       */
266 /* ¦Á4x25¡Ü ¦Á67x24¡Ü ¦Á209x23 ¡Ü ¦Á138x22 ¡Ü ¦Á138x21 ¡Ü ¦Á32x20 ¡Ü ¦Á242x19 */
267 /* ¡Ü ¦Á123x18 ¡Ü ¦Á89x17 ¡Ü ¦Á27x16 ¡Ü ¦Á120x15 ¡Ü ¦Á185x14¡Ü ¦Á80x13¡Ü      */
268 /* ¦Á156x12¡Ü ¦Á38x11¡Ü ¦Á60x10¡Ü ¦Á171x9¡Ü ¦Á60x8¡Ü ¦Á28x7¡Ü ¦Á222x6 ¡Ü      */
269 /* ¦Á80x5¡Ü¦Á52x4¡Ü ¦Á254x3¡Ü ¦Á185x2¡Ü ¦Á220x¡Ü ¦Á241                        */
270 /*----------------------------------------------------------------------------*/
271 static const int v_poly_ecc32[] = {
272   241, 220, 185, 254, 52, 80, 222, 28,
273   60, 171, 60, 38, 156, 80, 185, 120,
274   27, 89, 123, 242, 32, 138, 138, 209,
275   67, 4, 167, 249, 190, 106, 6, 10, 
276   0,
277 };
278 /*----------------------------------------------------------------------------*/
279 /* À¸À®Â¿¹à¼° - ¸í¤êÄûÀµ¥³¡¼¥É¿ô34 ¤ò¤¢¤é¤ï¤¹                                 */
280 /* x34¡Ü ¦Á111x33¡Ü ¦Á77x32¡Ü ¦Á146x31¡Ü ¦Á94x30¡Ü ¦Á26x29¡Ü ¦Á21x28¡Ü        */
281 /* ¦Á108x27¡Ü ¦Á19x26¡Ü ¦Á105x25¡Ü ¦Á94x24¡Ü ¦Á113x23¡Ü ¦Á193x22¡Ü ¦Á86x21¡Ü  */
282 /* ¦Á140x20¡Ü ¦Á163x19¡Ü ¦Á125x18¡Ü ¦Á58x17 ¡Ü ¦Á158x16¡Ü ¦Á229x15¡Ü          */
283 /* ¦Á239x14¡Ü ¦Á218x13¡Ü ¦Á103x12¡Ü ¦Á56x11¡Ü ¦Á70x10¡Ü ¦Á114x9¡Ü ¦Á61x8¡Ü    */
284 /* ¦Á183x7¡Ü ¦Á129x6¡Ü ¦Á167x5¡Ü ¦Á13x4¡Ü ¦Á98x3¡Ü ¦Á62x2¡Ü ¦Á129x¡Ü ¦Á51     */
285 /*----------------------------------------------------------------------------*/
286 static const int v_poly_ecc34[] = {
287   51, 129, 62, 98, 13, 167, 129, 183,
288   61, 114, 70, 56, 103, 218, 239, 229,
289   158, 58, 125, 163, 140, 86, 193, 113,
290   94, 105, 19, 108, 21, 26, 94, 146,
291   77, 111, 0,
292 };
293 /*----------------------------------------------------------------------------*/
294 /* À¸À®Â¿¹à¼° - ¸í¤êÄûÀµ¥³¡¼¥É¿ô36 ¤ò¤¢¤é¤ï¤¹                                 */
295 /* x36¡Ü ¦Á200x35¡Ü ¦Á183x34¡Ü ¦Á98x33¡Ü ¦Á16x32¡Ü ¦Á172x31¡Ü ¦Á31x30¡Ü       */
296 /* ¦Á246x29¡Ü ¦Á234x28 ¡Ü ¦Á60x27 ¡Ü ¦Á152x26 ¡Ü ¦Á115x25 ¡Ü x24 ¡Ü ¦Á167x23  */
297 /* ¡Ü ¦Á152x22 ¡Ü ¦Á113x21 ¡Ü ¦Á248x20 ¡Ü¦Á238x19 ¡Ü ¦Á107x18 ¡Ü ¦Á18x17 ¡Ü   */
298 /* ¦Á63x16 ¡Ü ¦Á218x15 ¡Ü ¦Á37x14 ¡Ü ¦Á87x13 ¡Ü ¦Á210x12 ¡Ü¦Á105x11           */
299 /* ¡Ü ¦Á177x10¡Ü ¦Á120x9¡Ü ¦Á74x8¡Ü ¦Á121x7¡Ü ¦Á196x6¡Ü ¦Á117x5¡Ü ¦Á251x4¡Ü   */
300 /* ¦Á113x3¡Ü ¦Á233x2 ¡Ü ¦Á30x¡Ü ¦Á120                                         */
301 /*----------------------------------------------------------------------------*/
302 static const int v_poly_ecc36[] = {
303   120, 30, 233, 113, 251, 117, 196, 121,
304   74, 120, 177, 105, 210, 87, 37, 218,
305   63, 18, 107, 238, 248, 113, 152, 167,
306   0, 115, 152, 60, 234, 246, 31, 172,
307   16, 98, 183, 200, 0,
308 };
309 /*----------------------------------------------------------------------------*/
310 /* À¸À®Â¿¹à¼° - ¸í¤êÄûÀµ¥³¡¼¥É¿ô40 ¤ò¤¢¤é¤ï¤¹                                 */
311 /* x40¡Ü ¦Á59x39¡Ü ¦Á116x38¡Ü ¦Á79x37¡Ü ¦Á161x36¡Ü ¦Á252x35¡Ü ¦Á98x34¡Ü       */
312 /* ¦Á128x33¡Ü ¦Á205x32 ¡Ü ¦Á128x31¡Ü ¦Á161x30¡Ü ¦Á247x29¡Ü ¦Á57x28¡Ü          */
313 /* ¦Á163x27¡Ü ¦Á56x26¡Ü ¦Á235x25¡Ü ¦Á106x24 ¡Ü ¦Á53x23¡Ü ¦Á26x22¡Ü ¦Á187x21¡Ü */
314 /* ¦Á174x20¡Ü ¦Á226x19¡Ü ¦Á104x18¡Ü ¦Á170x17¡Ü ¦Á7x16 ¡Ü ¦Á175x15 ¡Ü ¦Á35x14¡Ü*/
315 /* ¦Á181x13 ¡Ü ¦Á114x12 ¡Ü ¦Á88x11 ¡Ü ¦Á41x10 ¡Ü ¦Á47x9 ¡Ü ¦Á163x8 ¡Ü         */
316 /* ¦Á125x7¡Ü ¦Á134x6¡Ü ¦Á72x5¡Ü ¦Á20x4¡Ü ¦Á232x3¡Ü ¦Á53x2¡Ü ¦Á35x¡Ü ¦Á15      */
317 /*----------------------------------------------------------------------------*/
318 static const int v_poly_ecc40[] = {
319   15, 35, 53, 232, 20, 72, 134, 125,
320   163, 47, 41, 88, 114, 181, 35, 175,
321   7, 170, 104, 226, 174, 187, 26, 53,
322   106, 235, 56, 163, 57, 247, 161, 128,
323   205, 128, 98, 252, 161, 79, 116, 59,
324   0,
325 };
326 /*----------------------------------------------------------------------------*/
327 /* À¸À®Â¿¹à¼° - ¸í¤êÄûÀµ¥³¡¼¥É¿ô42 ¤ò¤¢¤é¤ï¤¹                                 */
328 /* x42¡Ü ¦Á250x41¡Ü ¦Á103x40¡Ü ¦Á221x39¡Ü ¦Á230x38¡Ü ¦Á25x37¡Ü ¦Á18x36¡Ü      */
329 /* ¦Á137x35¡Ü ¦Á231x34¡Ü x33¡Ü ¦Á3x32¡Ü ¦Á58x31¡Ü ¦Á242x30¡Ü ¦Á221x29¡Ü       */
330 /* ¦Á191x28¡Ü ¦Á110x27¡Ü ¦Á84x26¡Ü ¦Á230x25¡Ü ¦Á8x24 ¡Ü ¦Á188x23 ¡Ü ¦Á106x22¡Ü*/
331 /* ¦Á96x21 ¡Ü ¦Á147x20 ¡Ü ¦Á15x19 ¡Ü ¦Á131x18 ¡Ü ¦Á139x17 ¡Ü ¦Á34x16 ¡Ü       */
332 /* ¦Á101x15 ¡Ü ¦Á223x14 ¡Ü ¦Á39x13 ¡Ü ¦Á101x12 ¡Ü ¦Á213x11 ¡Ü ¦Á199x10 ¡Ü     */
333 /* ¦Á237x9 ¡Ü ¦Á254x8¡Ü ¦Á201x7¡Ü ¦Á123x6¡Ü ¦Á171x5¡Ü ¦Á162x4¡Ü ¦Á194x3¡Ü     */
334 /* ¦Á117x2¡Ü ¦Á50x¡Ü ¦Á96                                                     */
335 /*----------------------------------------------------------------------------*/
336 static const int v_poly_ecc42[] = {
337   96, 50, 117, 194, 162, 171, 123, 201,
338   254, 237, 199, 213, 101, 39, 223, 101,
339   34, 139, 131, 15, 147, 96, 106, 188,
340   8, 230, 84, 110, 191, 221, 242, 58,
341   3, 0, 231, 137, 18, 25, 230, 221,
342   103, 250, 0,
343 };
344 /*----------------------------------------------------------------------------*/
345 /* À¸À®Â¿¹à¼° - ¸í¤êÄûÀµ¥³¡¼¥É¿ô44 ¤ò¤¢¤é¤ï¤¹                                 */
346 /* x44¡Ü ¦Á190x43¡Ü ¦Á7x42¡Ü ¦Á61x41¡Ü ¦Á121x40¡Ü ¦Á71x39¡Ü ¦Á246x38¡Ü        */
347 /* ¦Á69x37¡Ü ¦Á55x36¡Ü ¦Á168x35 ¡Ü ¦Á188x34 ¡Ü ¦Á89x33 ¡Ü ¦Á243x32 ¡Ü         */
348 /* ¦Á191x31 ¡Ü ¦Á25x30 ¡Ü ¦Á72x29 ¡Ü ¦Á123x28 ¡Ü ¦Á9x27¡Ü ¦Á145x26¡Ü ¦Á14x25¡Ü*/
349 /* ¦Á247x24¡Ü ¦Áx23¡Ü ¦Á238x22¡Ü ¦Á44x21¡Ü ¦Á78x20¡Ü ¦Á143x19 ¡Ü ¦Á62x18¡Ü    */
350 /* ¦Á224x17¡Ü ¦Á126x16¡Ü ¦Á118x15¡Ü ¦Á114x14¡Ü ¦Á68x13¡Ü ¦Á163x12¡Ü ¦Á52x11¡Ü */
351 /* ¦Á194x10¡Ü ¦Á217x9 ¡Ü ¦Á147x8¡Ü ¦Á204x7¡Ü ¦Á169x6¡Ü ¦Á37x5¡Ü ¦Á130x4¡Ü     */
352 /* ¦Á113x3¡Ü ¦Á102x2¡Ü ¦Á73x¡Ü ¦Á181                                          */
353 /*----------------------------------------------------------------------------*/
354 static const int v_poly_ecc44[] = {
355   181,  73, 102, 113, 130,  37, 169, 204,
356   147, 217, 194,  52, 163,  68, 114, 118, 
357   126, 224,  62, 143,  78,  44, 238,   1,
358   247,  14, 145,   9, 123,  72,  25, 191,
359   243,  89, 188, 168,  55,  69, 246,  71,
360   121,  61,   7, 190,   0,
361 };
362 /*----------------------------------------------------------------------------*/
363 /* À¸À®Â¿¹à¼° - ¸í¤êÄûÀµ¥³¡¼¥É¿ô46 ¤ò¤¢¤é¤ï¤¹                                 */
364 /* x46¡Ü ¦Á112x45¡Ü ¦Á94x44¡Ü ¦Á88x43¡Ü ¦Á112x42¡Ü ¦Á253x41¡Ü ¦Á224x40¡Ü      */
365 /* ¦Á202x39¡Ü ¦Á115x38 ¡Ü ¦Á187x37 ¡Ü ¦Á99x36 ¡Ü ¦Á89x35 ¡Ü ¦Á5x34 ¡Ü ¦Á54x33 */
366 /* ¡Ü ¦Á113x32 ¡Ü ¦Á129x31 ¡Ü ¦Á44x30 ¡Ü ¦Á58x29¡Ü ¦Á16x28¡Ü ¦Á135x27¡Ü       */
367 /* ¦Á216x26¡Ü ¦Á169x25¡Ü ¦Á211x24¡Ü ¦Á36x23¡Ü ¦Áx22¡Ü ¦Á4x21¡Ü ¦Á96x20 ¡Ü     */
368 /* ¦Á60x19¡Ü ¦Á241x18¡Ü ¦Á73x17¡Ü ¦Á104x16¡Ü ¦Á234x15¡Ü ¦Á8x14¡Ü ¦Á249x13¡Ü   */
369 /* ¦Á245x12 ¡Ü ¦Á119x11¡Ü ¦Á174x10¡Ü ¦Á52x9¡Ü ¦Á25x8¡Ü ¦Á157x7¡Ü ¦Á224x6¡Ü    */
370 /* ¦Á43x5¡Ü ¦Á202x4¡Ü ¦Á223x3 ¡Ü ¦Á19x2¡Ü ¦Á82x¡Ü ¦Á15                        */
371 /*----------------------------------------------------------------------------*/
372 static const int v_poly_ecc46[] = {
373    15,  82,  19, 223, 202,  43, 224, 157,
374    25,  52, 174, 119, 245, 249,   8, 234,
375   104,  73, 241,  60,  96,   4,   1,  36,
376   211, 169, 216, 135,  16,  58,  44, 129,
377   113,  54,   5,  89,  99, 187, 115, 202,
378   224, 253, 112,  88,  94, 112,   0,
379 };
380 /*----------------------------------------------------------------------------*/
381 /* À¸À®Â¿¹à¼° - ¸í¤êÄûÀµ¥³¡¼¥É¿ô48 ¤ò¤¢¤é¤ï¤¹                                 */
382 /* x48¡Ü ¦Á228x47¡Ü ¦Á25x46¡Ü ¦Á196x45¡Ü ¦Á130x44¡Ü ¦Á211x43¡Ü ¦Á146x42¡Ü     */
383 /* ¦Á60x41¡Ü ¦Á24x40 ¡Ü ¦Á251x39¡Ü ¦Á90x38¡Ü ¦Á39x37¡Ü ¦Á102x36¡Ü ¦Á240x35¡Ü  */
384 /* ¦Á61x34¡Ü ¦Á178x33¡Ü ¦Á63x32¡Ü ¦Á46x31 ¡Ü ¦Á123x30¡Ü ¦Á115x29 ¡Ü ¦Á18x28 ¡Ü*/
385 /*  ¦Á221x27 ¡Ü ¦Á111x26 ¡Ü ¦Á135x25 ¡Ü ¦Á160x24 ¡Ü ¦Á182x23 ¡Ü ¦Á205x22¡Ü    */
386 /* ¦Á107x21¡Ü ¦Á206x20¡Ü ¦Á95x19¡Ü ¦Á150x18¡Ü ¦Á120x17¡Ü ¦Á184x16¡Ü ¦Á91x15   */
387 /* ¡Ü ¦Á21x14 ¡Ü ¦Á247x13 ¡Ü ¦Á156x12 ¡Ü ¦Á140x11 ¡Ü ¦Á238x10 ¡Ü ¦Á191x9 ¡Ü   */
388 /* ¦Á11x8 ¡Ü ¦Á94x7 ¡Ü ¦Á227x6¡Ü ¦Á84x5¡Ü ¦Á50x4¡Ü ¦Á163x3¡Ü ¦Á39x2¡Ü ¦Á34x¡Ü */
389 /* ¦Á108                                                                      */
390 /*----------------------------------------------------------------------------*/
391 static const int v_poly_ecc48[] = {
392   108,  34,  39, 163,  50,  84, 227,  94,
393    11, 191, 238, 140, 156, 247,  21,  91,
394   184, 120, 150,  95, 206, 107, 205, 182,
395   160, 135, 111, 221,  18, 115, 123,  46,
396    63, 178,  61, 240, 102,  39,  90, 251,
397    24,  60, 146, 211, 130, 196,  25, 228,
398     0,
399 };
400 /*----------------------------------------------------------------------------*/
401 /* À¸À®Â¿¹à¼° - ¸í¤êÄûÀµ¥³¡¼¥É¿ô50 ¤ò¤¢¤é¤ï¤¹                                 */
402 /* x50¡Ü ¦Á232x49¡Ü ¦Á125x48¡Ü ¦Á157x47¡Ü ¦Á161x46¡Ü ¦Á164x45¡Ü ¦Á9x44¡Ü      */
403 /* ¦Á118x43¡Ü ¦Á46x42 ¡Ü ¦Á209x41¡Ü ¦Á99x40¡Ü ¦Á203x39¡Ü ¦Á193x38¡Ü ¦Á35x37¡Ü */
404 /* ¦Á3x36¡Ü ¦Á209x35¡Ü ¦Á111x34 ¡Ü ¦Á195x33¡Ü ¦Á242x32¡Ü ¦Á203x31¡Ü ¦Á225x30¡Ü*/
405 /* ¦Á46x29¡Ü ¦Á13x28¡Ü ¦Á32x27¡Ü ¦Á160x26 ¡Ü ¦Á126x25¡Ü ¦Á209x24¡Ü ¦Á130x23¡Ü */
406 /* ¦Á160x22¡Ü ¦Á242x21¡Ü ¦Á215x20¡Ü ¦Á242x19¡Ü ¦Á75x18 ¡Ü ¦Á77x17¡Ü ¦Á42x16¡Ü */
407 /* ¦Á189x15¡Ü ¦Á32x14¡Ü ¦Á113x13¡Ü ¦Á65x12¡Ü ¦Á124x11¡Ü ¦Á69x10¡Ü ¦Á228x9¡Ü   */
408 /* ¦Á114x8¡Ü ¦Á235x7¡Ü ¦Á175x6¡Ü ¦Á124x5¡Ü ¦Á170x4¡Ü ¦Á215x3¡Ü ¦Á232x2¡Ü      */
409 /* ¦Á133x¡Ü ¦Á205                                                             */
410 /*----------------------------------------------------------------------------*/
411 static const int v_poly_ecc50[] = {
412   205, 133, 232, 215, 170, 124, 175, 235,
413   114, 228,  69, 124,  65, 113,  32, 189,
414    42,  77,  75, 242, 215, 242, 160, 130,
415   209, 126, 160,  32,  13,  46, 225, 203,
416   242, 195, 111, 209,   3,  35, 193, 203,
417    99, 209,  46, 118,   9, 164, 161, 157,
418   125, 232, 0,
419 };
420 /*----------------------------------------------------------------------------*/
421 /* À¸À®Â¿¹à¼° - ¸í¤êÄûÀµ¥³¡¼¥É¿ô52 ¤ò¤¢¤é¤ï¤¹                                 */
422 /* x52¡Ü ¦Á116x51¡Ü ¦Á50x50¡Ü ¦Á86x49¡Ü ¦Á186x48¡Ü ¦Á50x47¡Ü ¦Á220x46¡Ü       */
423 /* ¦Á251x45¡Ü ¦Á89x44 ¡Ü ¦Á192x43¡Ü ¦Á46x42¡Ü ¦Á86x41¡Ü ¦Á127x40¡Ü ¦Á124x39¡Ü */
424 /* ¦Á19x38¡Ü ¦Á184x37¡Ü ¦Á233x36 ¡Ü ¦Á151x35¡Ü ¦Á215x34¡Ü ¦Á22x33¡Ü ¦Á14x32¡Ü */
425 /* ¦Á59x31¡Ü ¦Á145x30¡Ü ¦Á37x29¡Ü ¦Á242x28 ¡Ü ¦Á203x27¡Ü ¦Á134x26¡Ü ¦Á254x25¡Ü*/
426 /* ¦Á89x24¡Ü ¦Á190x23¡Ü ¦Á94x22¡Ü ¦Á59x21¡Ü ¦Á65x20 ¡Ü ¦Á124x19¡Ü ¦Á113x18¡Ü  */
427 /* ¦Á100x17¡Ü ¦Á233x16¡Ü ¦Á235x15¡Ü ¦Á121x14¡Ü ¦Á22x13¡Ü ¦Á76x12 ¡Ü ¦Á86x11¡Ü */
428 /* ¦Á97x10¡Ü ¦Á39x9¡Ü ¦Á242x8¡Ü ¦Á200x7¡Ü ¦Á220x6¡Ü ¦Á101x5¡Ü ¦Á33x4¡Ü        */
429 /* ¦Á239x3 ¡Ü ¦Á254x2¡Ü ¦Á116x ¦Á51                                           */
430 /*----------------------------------------------------------------------------*/
431 static const int v_poly_ecc52[] = {
432    51, 116, 254, 239,  33, 101, 220, 200,
433   242,  39,  97,  86,  76,  22, 121, 235,
434   233, 100, 113, 124,  65,  59,  94, 190,
435    89, 254, 134, 203, 242,  37, 145,  59,
436    14,  22, 215, 151, 233, 184,  19, 124,
437   127,  86,  46, 192,  89, 251, 220,  50,
438   186,  86,  50, 116,   0,
439 };
440 /*----------------------------------------------------------------------------*/
441 /* À¸À®Â¿¹à¼° - ¸í¤êÄûÀµ¥³¡¼¥É¿ô54 ¤ò¤¢¤é¤ï¤¹                                 */
442 /* x54¡Ü ¦Á183x53¡Ü ¦Á26x52¡Ü ¦Á201x51¡Ü ¦Á87x50¡Ü ¦Á210x49¡Ü ¦Á221x48¡Ü      */
443 /* ¦Á113x47¡Ü ¦Á21x46 ¡Ü ¦Á46x45¡Ü ¦Á65x44¡Ü ¦Á45x43¡Ü ¦Á50x42¡Ü ¦Á238x41¡Ü   */
444 /* ¦Á184x40¡Ü ¦Á249x39¡Ü ¦Á225x38  ¡Ü ¦Á102x37¡Ü ¦Á58x36¡Ü ¦Á209x35¡Ü         */
445 /* ¦Á218x34¡Ü ¦Á109x33¡Ü ¦Á165x32¡Ü ¦Á26x31¡Ü ¦Á95x30  ¡Ü ¦Á184x29¡Ü          */
446 /* ¦Á192x28¡Ü ¦Á52x27¡Ü ¦Á245x26¡Ü ¦Á35x25¡Ü ¦Á254x24¡Ü ¦Á238x23¡Ü ¦Á175x22   */
447 /* ¡Ü ¦Á172x21¡Ü ¦Á79x20¡Ü ¦Á123x19¡Ü ¦Á25x18¡Ü ¦Á122x17¡Ü ¦Á43x16¡Ü          */
448 /* ¦Á120x15¡Ü ¦Á108x14 ¡Ü ¦Á215x13¡Ü ¦Á80x12¡Ü ¦Á128x11¡Ü ¦Á201x10¡Ü          */
449 /* ¦Á235x9¡Ü ¦Á8x8¡Ü ¦Á153x7¡Ü ¦Á59x6¡Ü ¦Á101x5 ¡Ü ¦Á31x4¡Ü ¦Á198x3¡Ü         */
450 /* ¦Á76x2¡Ü ¦Á31x¡Ü ¦Á156                                                     */
451 /*----------------------------------------------------------------------------*/
452 static const int v_poly_ecc54[] = {
453   156,  31,  76, 198,  31, 101,  59, 153,
454     8, 235, 201, 128,  80, 215, 108, 120,
455    43, 122,  25, 123,  79, 172, 175, 238,
456   254,  35, 245,  52, 192, 184,  95,  26,
457   165, 109, 218, 209,  58, 102, 225, 249,
458   184, 238,  50,  45,  65,  46,  21, 113,
459   221, 210,  87, 201,  26, 183,   0,
460 };
461 /*----------------------------------------------------------------------------*/
462 /* À¸À®Â¿¹à¼° - ¸í¤êÄûÀµ¥³¡¼¥É¿ô56 ¤ò¤¢¤é¤ï¤¹                                 */
463 /* x56¡Ü¦Á106x55¡Ü¦Á120x54¡Ü¦Á107x53¡Ü¦Á157x52¡Ü¦Á164x51¡Ü¦Á216x50¡Ü          */
464 /* ¦Á112x49¡Ü¦Á116x48¡Ü¦Á2x47¡Ü¦Á91x46¡Ü¦Á248x45¡Ü¦Á163x44¡Ü¦Á36x43¡Ü         */
465 /* ¦Á201x42¡Ü¦Á202x41¡Ü¦Á229x40¡Ü¦Á6x39¡Ü¦Á144x38¡Ü¦Á254x37¡Ü¦Á155x36¡Ü       */
466 /* ¦Á135x35¡Ü¦Á208x34¡Ü¦Á170x33¡Ü¦Á209x32¡Ü¦Á12x31 ¡Ü¦Á139x30¡Ü               */
467 /* ¦Á127x29¡Ü¦Á142x28¡Ü¦Á182x27¡Ü¦Á249x26¡Ü¦Á177x25¡Ü¦Á174x24¡Ü               */
468 /* ¦Á190x23¡Ü¦Á28x22¡Ü¦Á10x21¡Ü¦Á85x20¡Ü¦Á239x19¡Ü¦Á184x18¡Ü¦Á101x17¡Ü        */
469 /* ¦Á124x16¡Ü¦Á152x15¡Ü¦Á206x14¡Ü¦Á96x13¡Ü¦Á23x12¡Ü¦Á163x11¡Ü¦Á61x10¡Ü        */
470 /* ¦Á27x9¡Ü¦Á196x8¡Ü¦Á247x7¡Ü¦Á151x6¡Ü¦Á154x5¡Ü¦Á202x4¡Ü¦Á207x3¡Ü             */
471 /* ¦Á20x2¡Ü¦Á61x¡Ü¦Á10                                                        */
472 /*----------------------------------------------------------------------------*/
473 static const int v_poly_ecc56[] = {
474    10,  61,  20, 207, 202, 154, 151, 247,
475   196,  27,  61, 163,  23,  96, 206, 152,
476   124, 101, 184, 239,  85,  10,  28, 190,
477   174, 177, 249, 182, 142, 127, 139,  12,
478   209, 170, 208, 135, 155, 254, 144,   6,
479   229, 202, 201,  36, 163, 248,  91,   2,
480   116, 112, 216, 164, 157, 107, 120, 106,
481     0,
482 };
483 /*----------------------------------------------------------------------------*/
484 /* À¸À®Â¿¹à¼° - ¸í¤êÄûÀµ¥³¡¼¥É¿ô58 ¤ò¤¢¤é¤ï¤¹                                 */
485 /* x58¡Ü ¦Á82x57¡Ü ¦Á116x56¡Ü ¦Á26x55¡Ü ¦Á247x54¡Ü ¦Á66x53¡Ü ¦Á27x52¡Ü        */
486 /* ¦Á62x51¡Ü ¦Á107x50¡Ü ¦Á252x49¡Ü ¦Á182x48¡Ü ¦Á200x47¡Ü ¦Á185x46¡Ü           */
487 /* ¦Á235x45¡Ü ¦Á55x44¡Ü ¦Á251x43¡Ü ¦Á242x42¡Ü ¦Á210x41 ¡Ü ¦Á144x40¡Ü          */
488 /* ¦Á154x39¡Ü ¦Á237x38¡Ü ¦Á176x37¡Ü ¦Á141x36¡Ü ¦Á192x35¡Ü ¦Á248x34¡Ü          */
489 /* ¦Á152x33 ¡Ü ¦Á249x32¡Ü ¦Á206x31¡Ü ¦Á85x30¡Ü ¦Á253x29¡Ü ¦Á142x28¡Ü          */
490 /* ¦Á65x27¡Ü ¦Á165x26¡Ü ¦Á125x25 ¡Ü ¦Á23x24¡Ü ¦Á24x23¡Ü ¦Á30x22¡Ü ¦Á122x21¡Ü  */
491 /* ¦Á240x20¡Ü ¦Á214x19¡Ü ¦Á6x18¡Ü ¦Á129x17¡Ü ¦Á218x16¡Ü ¦Á29x15¡Ü ¦Á145x14¡Ü  */
492 /* ¦Á127x13¡Ü ¦Á134x12¡Ü ¦Á206x11¡Ü ¦Á245x10¡Ü ¦Á117x9¡Ü ¦Á29x8¡Ü ¦Á41x7¡Ü    */
493 /* ¦Á63x6¡Ü ¦Á159x5¡Ü ¦Á142x4¡Ü ¦Á233x3¡Ü ¦Á125x2¡Ü ¦Á148x¡Ü ¦Á123            */
494 /*----------------------------------------------------------------------------*/
495 static const int v_poly_ecc58[] = {
496   123, 148, 125, 233, 142, 159,  63,  41,
497    29, 117, 245, 206, 134, 127, 145,  29,
498   218, 129,   6, 214, 240, 122,  30,  24,
499    23, 125, 165,  65, 142, 253,  85, 206,
500   249, 152, 248, 192, 141, 176, 237, 154,
501   144, 210, 242, 251,  55, 235, 185, 200,
502   182, 252, 107,  62,  27,  66, 247,  26,
503   116,  82,   0,
504 };
505 /*----------------------------------------------------------------------------*/
506 /* À¸À®Â¿¹à¼° - ¸í¤êÄûÀµ¥³¡¼¥É¿ô60 ¤ò¤¢¤é¤ï¤¹                                 */
507 /* x60¡Ü ¦Á107x59¡Ü ¦Á140x58¡Ü ¦Á26x57¡Ü ¦Á12x56¡Ü ¦Á9x55¡Ü ¦Á141x54¡Ü        */
508 /* ¦Á243x53¡Ü ¦Á197x52 ¡Ü ¦Á226x51¡Ü ¦Á197x50¡Ü ¦Á219x49¡Ü ¦Á45x48¡Ü          */
509 /* ¦Á211x47¡Ü ¦Á101x46¡Ü ¦Á219x45¡Ü ¦Á120x44¡Ü ¦Á28x43¡Ü ¦Á181x42¡Ü           */
510 /* ¦Á127x41¡Ü ¦Á6x40¡Ü ¦Á100x39¡Ü ¦Á247x38¡Ü ¦Á2x37¡Ü ¦Á205x36¡Ü ¦Á198x35¡Ü   */
511 /* ¦Á57x34¡Ü ¦Á115x33¡Ü ¦Á219x32¡Ü ¦Á101x31¡Ü ¦Á109x30¡Ü ¦Á160x29¡Ü ¦Á82x28¡Ü */
512 /* ¦Á37x27¡Ü ¦Á38x26¡Ü ¦Á238x25¡Ü ¦Á49x24¡Ü ¦Á160x23¡Ü ¦Á209x22¡Ü ¦Á121x21¡Ü  */
513 /* ¦Á86x20¡Ü ¦Á11x19 ¡Ü ¦Á124x18¡Ü ¦Á30x17¡Ü ¦Á181x16¡Ü ¦Á84x15¡Ü ¦Á25x14¡Ü   */
514 /* ¦Á194x13¡Ü ¦Á87x12¡Ü ¦Á65x11¡Ü ¦Á102x10¡Ü ¦Á190x9¡Ü ¦Á220x8¡Ü ¦Á70x7¡Ü     */
515 /* ¦Á27x6¡Ü ¦Á209x5¡Ü ¦Á16x4¡Ü ¦Á89x3¡Ü ¦Á7x2¡Ü ¦Á33x ¡Ü ¦Á240                */
516 /*----------------------------------------------------------------------------*/
517 static const int v_poly_ecc60[] = {
518   240,  33,   7,  89,  16, 209,  27,  70,
519   220, 190, 102,  65,  87, 194,  25,  84,
520   181,  30, 124,  11,  86, 121, 209, 160,
521    49, 238,  38,  37,  82, 160, 109, 101,
522   219, 115,  57, 198, 205,   2, 247, 100,
523     6, 127, 181,  28, 120, 219, 101, 211,
524    45, 219, 197, 226, 197, 243, 141,   9,
525    12,  26, 140, 107,   0,
526 };
527 /*----------------------------------------------------------------------------*/
528 /* À¸À®Â¿¹à¼° - ¸í¤êÄûÀµ¥³¡¼¥É¿ô62 ¤ò¤¢¤é¤ï¤¹                                 */
529 /* x62¡Ü ¦Á65x61¡Ü ¦Á202x60¡Ü ¦Á113x59¡Ü ¦Á98x58¡Ü ¦Á71x57¡Ü ¦Á223x56¡Ü       */
530 /* ¦Á248x55¡Ü ¦Á118x54¡Ü ¦Á214x53¡Ü ¦Á94x52¡Üx51¡Ü ¦Á122x50¡Ü ¦Á37x49¡Ü       */
531 /* ¦Á23x48¡Ü ¦Á2x47¡Ü ¦Á228x46¡Ü ¦Á58x45¡Ü ¦Á121x44¡Ü ¦Á7x43¡Ü ¦Á105x42¡Ü     */
532 /* ¦Á135x41¡Ü ¦Á78x40¡Ü ¦Á243x39¡Ü ¦Á118x38¡Ü ¦Á70x37¡Ü ¦Á76x36¡Ü ¦Á223x35¡Ü  */
533 /* ¦Á89x34¡Ü ¦Á72x33¡Ü ¦Á50x32¡Ü ¦Á70x31¡Ü ¦Á111x30¡Ü ¦Á194x29¡Ü ¦Á17x28      */
534 /* ¡Ü ¦Á212x27¡Ü ¦Á126x26¡Ü ¦Á181x25¡Ü ¦Á35x24¡Ü ¦Á221x23¡Ü ¦Á117x22¡Ü        */
535 /* ¦Á235x21¡Ü ¦Á11x20¡Ü ¦Á229x19¡Ü ¦Á149x18¡Ü ¦Á147x17¡Ü ¦Á123x16¡Ü ¦Á213x15¡Ü*/
536 /* ¦Á40x14¡Ü ¦Á115x13¡Ü ¦Á6x12¡Ü ¦Á200x11 ¡Ü ¦Á100x10¡Ü ¦Á26x9¡Ü ¦Á246x8¡Ü    */
537 /* ¦Á182x7¡Ü ¦Á218x6¡Ü ¦Á127x5 ¦Á215x4¡Ü ¦Á36x3¡Ü ¦Á186x2¡Ü ¦Á110x¡Ü ¦Á106    */
538 /* !! JISµ¬Ìó¤Ëtypo¤¢¤ê¡£x5¤Î¹à¤¬Ìµ¤«¤Ã¤¿¤Î¤Ç¡¢¦Á127x5¤È¤·¤ÆÄɲᣠ           */
539 /*----------------------------------------------------------------------------*/
540 static const int v_poly_ecc62[] = {
541   106, 110, 186,  36, 215, 127, 218, 182,
542   246,  26, 100, 200,   6, 115,  40, 213,
543   123, 147, 149, 229,  11, 235, 117, 221,
544    35, 181, 126, 212,  17, 194, 111,  70,
545    50,  72,  89, 223,  76,  70, 118, 243,
546    78, 135, 105,   7, 121,  58, 228,   2,
547    23,  37, 122,   0,  94, 214, 118, 248,
548   223,  71,  98, 113, 202,  65,   0,
549 };
550 /*----------------------------------------------------------------------------*/
551 /* À¸À®Â¿¹à¼° - ¸í¤êÄûÀµ¥³¡¼¥É¿ô64 ¤ò¤¢¤é¤ï¤¹                                 */
552 /* x64 ¡Ü ¦Á45x63 ¡Ü ¦Á51x62 ¡Ü ¦Á175x61 ¡Ü ¦Á9x60 ¡Ü ¦Á7x59 ¡Ü ¦Á158x58 ¡Ü   */
553 /* ¦Á159x57 ¡Ü ¦Á49x56 ¡Ü¦Á68x55 ¡Ü ¦Á119x54¡Ü ¦Á92x53¡Ü ¦Á123x52¡Ü ¦Á177x51¡Ü*/
554 /* ¦Á204x50¡Ü ¦Á187x49¡Ü ¦Á254x48¡Ü ¦Á200x47¡Ü ¦Á78x46¡Ü ¦Á141x45¡Ü ¦Á149x44¡Ü*/
555 /* ¦Á119x43¡Ü ¦Á26x42¡Ü ¦Á127x41¡Ü ¦Á53x40¡Ü ¦Á160x39¡Ü ¦Á93x38¡Ü ¦Á199x37¡Ü  */
556 /* ¦Á212x36¡Ü ¦Á29x35¡Ü ¦Á24x34¡Ü ¦Á145x33¡Ü ¦Á156x32¡Ü ¦Á208x31¡Ü ¦Á150x30¡Ü */
557 /* ¦Á218x29¡Ü ¦Á209x28¡Ü ¦Á4x27¡Ü ¦Á216x26¡Ü¦Á91x25¡Ü ¦Á47x24¡Ü ¦Á184x23¡Ü    */
558 /* ¦Á146x22¡Ü ¦Á47x21¡Ü ¦Á140x20¡Ü ¦Á195x19¡Ü ¦Á195x18¡Ü ¦Á125x17¡Ü ¦Á242x16¡Ü*/
559 /* ¦Á238x15¡Ü ¦Á63x14¡Ü ¦Á99x13¡Ü ¦Á108x12¡Ü ¦Á140x11¡Ü ¦Á230x10¡Ü ¦Á242x9¡Ü  */
560 /* ¦Á31x8¡Ü ¦Á204x7¡Ü ¦Á11x6¡Ü ¦Á178x5¡Ü ¦Á243x4¡Ü ¦Á217x3¡Ü ¦Á156x2¡Ü        */
561 /* ¦Á213x¡Ü ¦Á231                                                             */
562 /*----------------------------------------------------------------------------*/
563 static const int v_poly_ecc64[] = {
564   231, 213, 156, 217, 243, 178,  11, 204,
565    31, 242, 230, 140, 108,  99,  63, 238,
566   242, 125, 195, 195, 140,  47, 146, 184,
567    47,  91, 216,   4, 209, 218, 150, 208,
568   156, 145,  24,  29, 212, 199,  93, 160,
569    53, 127,  26, 119, 149, 141,  78, 200,
570   254, 187, 204, 177, 123,  92, 119,  68,
571    49, 159, 158,   7,   9, 175,  51,  45,
572   0,
573 };
574 /*----------------------------------------------------------------------------*/
575 /* À¸À®Â¿¹à¼° - ¸í¤êÄûÀµ¥³¡¼¥É¿ô66 ¤ò¤¢¤é¤ï¤¹                                 */
576 /* x66¡Ü ¦Á5x65¡Ü ¦Á118x64¡Ü ¦Á222x63¡Ü ¦Á180x62¡Ü ¦Á136x61¡Ü ¦Á136x60¡Ü      */
577 /* ¦Á162x59¡Ü ¦Á51x58¡Ü ¦Á46x57¡Ü ¦Á117x56¡Ü ¦Á13x55¡Ü ¦Á215x54¡Ü ¦Á81x53¡Ü   */
578 /* ¦Á17x52¡Ü ¦Á139x51¡Ü ¦Á247x50¡Ü ¦Á197x49¡Ü ¦Á171x48¡Ü ¦Á95x47¡Ü ¦Á173x46¡Ü */
579 /* ¦Á65x45¡Ü ¦Á137x44¡Ü ¦Á178x43¡Ü ¦Á68x42¡Ü ¦Á111x41¡Ü ¦Á95x40¡Ü ¦Á101x39¡Ü  */
580 /* ¦Á41x38¡Ü ¦Á72x37¡Ü ¦Á214x36¡Ü ¦Á169x35¡Ü ¦Á197x34¡Ü ¦Á95x33 ¡Ü ¦Á7x32 ¡Ü  */
581 /* ¦Á44x31 ¡Ü ¦Á154x30 ¡Ü ¦Á77x29 ¡Ü ¦Á111x28 ¡Ü ¦Á236x27 ¡Ü ¦Á40x26 ¡Ü       */
582 /* ¦Á121x25 ¡Ü ¦Á143x24 ¡Ü ¦Á63x23 ¡Ü ¦Á87x22 ¡Ü ¦Á80x21 ¡Ü ¦Á253x20 ¡Ü       */
583 /* ¦Á240x19 ¡Ü ¦Á126x18 ¡Ü¦Á217x17 ¡Ü ¦Á77x16 ¡Ü ¦Á34x15 ¡Ü ¦Á232x14 ¡Ü       */
584 /* ¦Á106x13 ¡Ü ¦Á50x12 ¡Ü ¦Á168x11 ¡Ü ¦Á82x10 ¡Ü ¦Á76x9 ¡Ü¦Á146x8¡Ü ¦Á67x7¡Ü  */
585 /* ¦Á106x6¡Ü ¦Á171x5¡Ü ¦Á25x4¡Ü ¦Á132x3¡Ü ¦Á93x2¡Ü ¦Á45x¡Ü ¦Á105              */
586 /*----------------------------------------------------------------------------*/
587 static const int v_poly_ecc66[] = {
588   105,  45,  93, 132,  25, 171, 106,  67,
589   146,  76,  82, 168,  50, 106, 232,  34,
590    77, 217, 126, 240, 253,  80,  87,  63,
591   143, 121,  40, 236, 111,  77, 154,  44,
592     7,  95, 197, 169, 214,  72,  41, 101,
593    95, 111,  68, 178, 137,  65, 173,  95,
594   171, 197, 247, 139,  17,  81, 215,  13,
595   117,  46,  51, 162, 136, 136, 180, 222,
596   118,   5,   0,
597 };
598 /*----------------------------------------------------------------------------*/
599 /* À¸À®Â¿¹à¼° - ¸í¤êÄûÀµ¥³¡¼¥É¿ô68 ¤ò¤¢¤é¤ï¤¹                                 */
600 /* x68¡Ü ¦Á247x67¡Ü ¦Á159x66¡Ü ¦Á223x65¡Ü ¦Á33x64¡Ü ¦Á224x63¡Ü ¦Á93x62¡Ü      */
601 /* ¦Á77x61¡Ü ¦Á70x60¡Ü ¦Á90x59 ¡Ü ¦Á160x58 ¡Ü ¦Á32x57 ¡Ü ¦Á254x56¡Ü ¦Á43x55¡Ü */
602 /* ¦Á150x54 ¡Ü ¦Á84x53 ¡Ü ¦Á101x52 ¡Ü¦Á190x51¡Ü ¦Á205x50¡Ü ¦Á133x49¡Ü         */
603 /* ¦Á52x48¡Ü ¦Á60x47¡Ü ¦Á202x46¡Ü ¦Á165x45¡Ü ¦Á220x44¡Ü ¦Á203x43¡Ü ¦Á151x42¡Ü */
604 /* ¦Á93x41¡Ü ¦Á84x40¡Ü ¦Á15x39¡Ü ¦Á84x38¡Ü ¦Á253x37¡Ü ¦Á173x36¡Ü ¦Á160x35¡Ü   */
605 /* ¦Á89x34 ¡Ü ¦Á227x33 ¡Ü ¦Á52x32 ¡Ü ¦Á199x31 ¡Ü ¦Á97x30¡Ü ¦Á95x29¡Ü ¦Á231x28 */
606 /* ¡Ü ¦Á52x27 ¡Ü ¦Á177x26¡Ü ¦Á41x25¡Ü ¦Á125x24¡Ü ¦Á137x23¡Ü ¦Á241x22¡Ü        */
607 /* ¦Á166x21¡Ü ¦Á225x20¡Ü ¦Á118x19¡Ü ¦Á2x18¡Ü ¦Á54x17¡Ü ¦Á32x16¡Ü ¦Á82x15¡Ü    */
608 /* ¦Á215x14¡Ü ¦Á175x13¡Ü ¦Á198x12¡Ü ¦Á43x11¡Ü ¦Á238x10¡Ü ¦Á235x9¡Ü ¦Á27x8¡Ü   */
609 /* ¦Á101x7¡Ü ¦Á184x6¡Ü ¦Á127x5¡Ü ¦Á3x4¡Ü ¦Á5x3¡Ü ¦Á8x2¡Ü ¦Á163x¡Ü ¦Á238       */
610 /*----------------------------------------------------------------------------*/
611 static const int v_poly_ecc68[] = {
612   238, 163,   8,   5,   3, 127, 184, 101,
613    27, 235, 238,  43, 198, 175, 215,  82,
614    32,  54,   2, 118, 225, 166, 241, 137,
615   125,  41, 177,  52, 231,  95,  97, 199,
616    52, 227,  89, 160, 173, 253,  84,  15,
617    84,  93, 151, 203, 220, 165, 202,  60,
618    52, 133, 205, 190, 101,  84, 150,  43,
619   254,  32, 160,  90,  70,  77,  93, 224,
620    33, 223, 159, 247,   0,
621 };
622
623 /*----------------------------------------------------------------------------*/
624 /* À¸À®Â¿¹à¼°¤Ë¥¢¥¯¥»¥¹¤¹¤ë¤¿¤á¤ÎÇÛÎó                                         */
625 /*----------------------------------------------------------------------------*/
626 static const int *v_poly_ecc[] = {
627 /* ¥¨¥é¡¼ÄûÀµ¸ì¿ô *//* Â¿¹à¼°¤ÎÇÛÎó */
628 /* 0              */ NULL,
629 /* 1              */ NULL,
630 /* 2              */ NULL,
631 /* 3              */ NULL,
632 /* 4              */ NULL,
633 /* 5              */ NULL,
634 /* 6              */ NULL,
635 /* 7              */ v_poly_ecc7,
636 /* 8              */ NULL,
637 /* 9              */ NULL,
638 /* 10             */ v_poly_ecc10,
639 /* 11             */ NULL,
640 /* 12             */ NULL,
641 /* 13             */ v_poly_ecc13,
642 /* 14             */ NULL,
643 /* 15             */ v_poly_ecc15,
644 /* 16             */ v_poly_ecc16,
645 /* 17             */ v_poly_ecc17,
646 /* 18             */ v_poly_ecc18,
647 /* 19             */ NULL,
648 /* 20             */ v_poly_ecc20,
649 /* 21             */ NULL,
650 /* 22             */ v_poly_ecc22,
651 /* 23             */ NULL,
652 /* 24             */ v_poly_ecc24,
653 /* 25             */ NULL,
654 /* 26             */ v_poly_ecc26,
655 /* 27             */ NULL,
656 /* 28             */ v_poly_ecc28,
657 /* 29             */ NULL,
658 /* 30             */ v_poly_ecc30,
659 /* 31             */ NULL,
660 /* 32             */ v_poly_ecc32,
661 /* 33             */ NULL,
662 /* 34             */ v_poly_ecc34,
663 /* 35             */ NULL,
664 /* 36             */ v_poly_ecc36,
665 /* 37             */ NULL,
666 /* 38             */ NULL,
667 /* 39             */ NULL,
668 /* 40             */ v_poly_ecc40,
669 /* 41             */ NULL,
670 /* 42             */ v_poly_ecc42,
671 /* 43             */ NULL,
672 /* 44             */ v_poly_ecc44,
673 /* 45             */ NULL,
674 /* 46             */ v_poly_ecc46,
675 /* 47             */ NULL,
676 /* 48             */ v_poly_ecc48,
677 /* 49             */ NULL,
678 /* 50             */ v_poly_ecc50,
679 /* 51             */ NULL,
680 /* 52             */ v_poly_ecc52,
681 /* 53             */ NULL,
682 /* 54             */ v_poly_ecc54,
683 /* 55             */ NULL,
684 /* 56             */ v_poly_ecc56,
685 /* 57             */ NULL,
686 /* 58             */ v_poly_ecc58,
687 /* 59             */ NULL,
688 /* 60             */ v_poly_ecc60,
689 /* 61             */ NULL,
690 /* 62             */ v_poly_ecc62,
691 /* 63             */ NULL,
692 /* 64             */ v_poly_ecc64,
693 /* 65             */ NULL,
694 /* 66             */ v_poly_ecc66,
695 /* 67             */ NULL,
696 /* 68             */ v_poly_ecc68,
697 };
698 /*----------------------------------------------------------------------------*/
699 /* ECCSPEC                                                                    */
700 /* ¸í¤êÄûÀµÆÃÀ­                                                               */
701 /*----------------------------------------------------------------------------*/
702 typedef struct _qr_ecc_spec_t {
703   qr_ver_t ver;
704   qr_level_t level;
705   struct rs_block_t {
706     int rs_block_count;
707     int total_code_count;
708     int data_code_count;
709   } rs[2];
710 } qr_ecc_spec_t;
711
712 static qr_ecc_spec_t v_ecc_spec_table[] = {
713   { QR_VER_1, QR_LEVEL_L, {{1, 26, 19,},{  0, 0, 0,}}}, /* OK */
714   { QR_VER_1, QR_LEVEL_M, {{1, 26, 16,},{  0, 0, 0,}}}, /* OK */
715   { QR_VER_1, QR_LEVEL_Q, {{1, 26, 13,},{  0, 0, 0,}}}, /* OK */
716   { QR_VER_1, QR_LEVEL_H, {{1, 26,  9,},{  0, 0, 0,}}}, /* OK */
717
718   { QR_VER_2, QR_LEVEL_L, {{1, 44, 34,},{  0, 0, 0,}}}, /* OK */
719   { QR_VER_2, QR_LEVEL_M, {{1, 44, 28,},{  0, 0, 0,}}}, /* OK */
720   { QR_VER_2, QR_LEVEL_Q, {{1, 44, 22,},{  0, 0, 0,}}}, /* OK */
721   { QR_VER_2, QR_LEVEL_H, {{1, 44, 16,},{  0, 0, 0,}}}, /* OK */
722
723   { QR_VER_3, QR_LEVEL_L, {{1, 70, 55,},{  0, 0, 0,}}},
724   { QR_VER_3, QR_LEVEL_M, {{1, 70, 44,},{  0, 0, 0,}}},
725   { QR_VER_3, QR_LEVEL_Q, {{2, 35, 17,},{  0, 0, 0,}}},
726   { QR_VER_3, QR_LEVEL_H, {{2, 35, 13,},{  0, 0, 0,}}},
727
728   { QR_VER_4, QR_LEVEL_L, {{1,100, 80,},{  0, 0, 0,}}},
729   { QR_VER_4, QR_LEVEL_M, {{2, 50, 32,},{  0, 0, 0,}}},
730   { QR_VER_4, QR_LEVEL_Q, {{2, 50, 24,},{  0, 0, 0,}}},
731   { QR_VER_4, QR_LEVEL_H, {{4, 25,  9,},{  0, 0, 0,}}}, /* OK */
732
733   { QR_VER_5, QR_LEVEL_L, {{1,134,108,},{  0, 0, 0,}}},
734   { QR_VER_5, QR_LEVEL_M, {{2, 67, 43,},{  0, 0, 0,}}},
735   { QR_VER_5, QR_LEVEL_Q, {{2, 33, 15,},{  2,34,16,}}}, /* OK */
736   { QR_VER_5, QR_LEVEL_H, {{2, 33, 11,},{  2,34,12,}}}, /* OK */
737
738   { QR_VER_6, QR_LEVEL_L, {{2, 86, 68,},{  0,  0,  0,}}},
739   { QR_VER_6, QR_LEVEL_M, {{4, 43, 27,},{  0,  0,  0,}}},
740   { QR_VER_6, QR_LEVEL_Q, {{4, 43, 19,},{  0,  0,  0,}}},
741   { QR_VER_6, QR_LEVEL_H, {{4, 43, 15,},{  0,  0,  0,}}}, /* OK */
742
743   { QR_VER_7, QR_LEVEL_L, {{2, 98, 78,},{  0,  0,  0,}}},
744   { QR_VER_7, QR_LEVEL_M, {{4, 49, 31,},{  0,  0,  0,}}},
745   { QR_VER_7, QR_LEVEL_Q, {{2, 32, 14,},{  4, 33, 15,}}},
746   { QR_VER_7, QR_LEVEL_H, {{4, 39, 13,},{  1, 40, 14,}}}, /* OK */
747
748   { QR_VER_8, QR_LEVEL_L, {{2,121, 97,},{  0,  0,  0,}}},
749   { QR_VER_8, QR_LEVEL_M, {{2, 60, 38,},{  2, 61, 39,}}},
750   { QR_VER_8, QR_LEVEL_Q, {{4, 40, 18,},{  2, 41, 19,}}},
751   { QR_VER_8, QR_LEVEL_H, {{4, 40, 14,},{  2, 41, 15,}}}, /* OK */
752
753   { QR_VER_9, QR_LEVEL_L, {{2,146,116,},{  0,  0,  0,}}},
754   { QR_VER_9, QR_LEVEL_M, {{3, 58, 36,},{  2, 59, 37,}}},
755   { QR_VER_9, QR_LEVEL_Q, {{4, 36, 16,},{  4, 37, 17,}}},
756   { QR_VER_9, QR_LEVEL_H, {{4, 36, 12,},{  4, 37, 13,}}},
757
758   { QR_VER_10, QR_LEVEL_L, {{2, 86, 68,},{  2, 87, 69,}}},
759   { QR_VER_10, QR_LEVEL_M, {{4, 69, 43,},{  1, 70, 44,}}},
760   { QR_VER_10, QR_LEVEL_Q, {{6, 43, 19,},{  2, 44, 20,}}},
761   { QR_VER_10, QR_LEVEL_H, {{6, 43, 15,},{  2, 44, 16,}}},
762
763   { QR_VER_11, QR_LEVEL_L, {{4,101, 81,},{  0,  0,  0,}}},
764   { QR_VER_11, QR_LEVEL_M, {{1, 80, 50,},{  4, 81, 51,}}},
765   { QR_VER_11, QR_LEVEL_Q, {{4, 50, 22,},{  4, 51, 23,}}},
766   { QR_VER_11, QR_LEVEL_H, {{3, 36, 12,},{  8, 37, 13,}}},
767
768   { QR_VER_12, QR_LEVEL_L, {{2,116, 92,},{  2,117, 93,}}},
769   { QR_VER_12, QR_LEVEL_M, {{6, 58, 36,},{  2, 59, 37,}}},
770   { QR_VER_12, QR_LEVEL_Q, {{4, 46, 20,},{  6, 47, 21,}}},
771   { QR_VER_12, QR_LEVEL_H, {{7, 42, 14,},{  4, 43, 15,}}},
772
773   { QR_VER_13, QR_LEVEL_L, {{ 4,133,107,},{  0,  0,  0,}}},
774   { QR_VER_13, QR_LEVEL_M, {{ 8, 59, 37,},{  1, 60, 38,}}},
775   { QR_VER_13, QR_LEVEL_Q, {{ 8, 44, 20,},{  4, 45, 21,}}},
776   { QR_VER_13, QR_LEVEL_H, {{12, 33, 11,},{  4, 34, 12,}}},
777
778   { QR_VER_14, QR_LEVEL_L, {{ 3,145,115,},{  1,146,116,}}},
779
780   /*------------------------------------------------------------------*/
781   /* JIS X0510¤Îp34¤Ç¤Ï¡¢(65,44,12)¤È¤Ê¤Ã¤Æ¤¤¤ë¤¬¡¢¸í¤ê¤Ë»×¤ï¤ì¤Þ¤¹¡£ */
782   /* ¤³¤³¤Ç¤Ï¡¢(65,41,24¡Ë¤È¤·¤Æ¤¤¤Þ¤¹                                */
783   /*------------------------------------------------------------------*/
784   { QR_VER_14, QR_LEVEL_M, {{ 4, 64, 40,},{  5, 65, 41,}}}, 
785   { QR_VER_14, QR_LEVEL_Q, {{11, 36, 16,},{  5, 37, 17,}}},
786   { QR_VER_14, QR_LEVEL_H, {{11, 36, 12,},{  5, 37, 13,}}},
787
788   { QR_VER_15, QR_LEVEL_L, {{ 5,109, 87,},{  1,110, 88,}}},
789   { QR_VER_15, QR_LEVEL_M, {{ 5, 65, 41,},{  5, 66, 42,}}},
790   { QR_VER_15, QR_LEVEL_Q, {{ 5, 54, 24,},{  7, 55, 25,}}},
791   { QR_VER_15, QR_LEVEL_H, {{11, 36, 12,},{  7, 37, 13,}}},
792
793   { QR_VER_16, QR_LEVEL_L, {{ 5,122, 98,},{  1,123, 99,}}},
794   { QR_VER_16, QR_LEVEL_M, {{ 7, 73, 45,},{  3, 74, 46,}}},
795   { QR_VER_16, QR_LEVEL_Q, {{15, 43, 19,},{  2, 44, 20,}}},
796   { QR_VER_16, QR_LEVEL_H, {{ 3, 45, 15,},{ 13, 46, 16,}}},
797
798   { QR_VER_17, QR_LEVEL_L, {{ 1,135,107,},{  5,136,108,}}},
799   { QR_VER_17, QR_LEVEL_M, {{10, 74, 46,},{  1, 75, 47,}}},
800   { QR_VER_17, QR_LEVEL_Q, {{ 1, 50, 22,},{ 15, 51, 23,}}},
801   { QR_VER_17, QR_LEVEL_H, {{ 2, 42, 14,},{ 17, 43, 15,}}},
802
803   { QR_VER_18, QR_LEVEL_L, {{ 5,150,120,},{  1,151,121,}}},
804   { QR_VER_18, QR_LEVEL_M, {{ 9, 69, 43,},{  4, 70, 44,}}},
805   { QR_VER_18, QR_LEVEL_Q, {{17, 50, 22,},{  1, 51, 23,}}},
806   { QR_VER_18, QR_LEVEL_H, {{ 2, 42, 14,},{ 19, 43, 15,}}},
807
808   { QR_VER_19, QR_LEVEL_L, {{ 3,141,113,},{  4,142,114,}}},
809   { QR_VER_19, QR_LEVEL_M, {{ 3, 70, 44,},{ 11, 71, 45,}}},
810   { QR_VER_19, QR_LEVEL_Q, {{17, 47, 21,},{  4, 48, 22,}}},
811   { QR_VER_19, QR_LEVEL_H, {{ 9, 39, 13,},{ 16, 40, 14,}}},
812
813   { QR_VER_20, QR_LEVEL_L, {{ 3,135,107,},{  5,136,108,}}},
814   { QR_VER_20, QR_LEVEL_M, {{ 3, 67, 41,},{ 13, 68, 42,}}},
815   { QR_VER_20, QR_LEVEL_Q, {{15, 54, 24,},{  5, 55, 25,}}},
816   { QR_VER_20, QR_LEVEL_H, {{15, 43, 15,},{ 10, 44, 16,}}},
817
818   { QR_VER_21, QR_LEVEL_L, {{ 4,144,116,},{  4,145,117,}}},
819   { QR_VER_21, QR_LEVEL_M, {{17, 68, 42,},{  0,  0,  0,}}},
820   { QR_VER_21, QR_LEVEL_Q, {{17, 50, 22,},{  6, 51, 23,}}},
821   { QR_VER_21, QR_LEVEL_H, {{19, 46, 16,},{  6, 47, 17,}}},
822
823   { QR_VER_22, QR_LEVEL_L, {{ 2,139,111,},{  7,140,112,}}},
824   { QR_VER_22, QR_LEVEL_M, {{17, 74, 46,},{  0,  0,  0,}}},
825   { QR_VER_22, QR_LEVEL_Q, {{ 7, 54, 24,},{ 16, 55, 25,}}},
826   { QR_VER_22, QR_LEVEL_H, {{34, 37, 13,},{  0,  0,  0,}}},
827
828   { QR_VER_23, QR_LEVEL_L, {{ 4,151,121,},{  5,152,122,}}},
829   { QR_VER_23, QR_LEVEL_M, {{ 4, 75, 47,},{ 14, 76, 48,}}},
830   { QR_VER_23, QR_LEVEL_Q, {{11, 54, 24,},{ 14, 55, 25,}}},
831   { QR_VER_23, QR_LEVEL_H, {{16, 45, 15,},{ 14, 46, 16,}}},
832
833   { QR_VER_24, QR_LEVEL_L, {{ 6,147,117,},{  4,148,118,}}},
834   { QR_VER_24, QR_LEVEL_M, {{ 6, 73, 45,},{ 14, 74, 46,}}},
835   { QR_VER_24, QR_LEVEL_Q, {{11, 54, 24,},{ 16, 55, 25,}}},
836   { QR_VER_24, QR_LEVEL_H, {{30, 46, 16,},{  2, 47, 17,}}},
837
838   { QR_VER_25, QR_LEVEL_L, {{ 8,132,106,},{  4,133,107,}}},
839   { QR_VER_25, QR_LEVEL_M, {{ 8, 75, 47,},{ 13, 76, 48,}}},
840   { QR_VER_25, QR_LEVEL_Q, {{ 7, 54, 24,},{ 22, 55, 25,}}},
841   { QR_VER_25, QR_LEVEL_H, {{22, 45, 15,},{ 13, 46, 16,}}},
842
843   { QR_VER_26, QR_LEVEL_L, {{10,142,114,},{  2,143,115,}}},
844   { QR_VER_26, QR_LEVEL_M, {{19, 74, 46,},{  4, 75, 47,}}},
845   { QR_VER_26, QR_LEVEL_Q, {{28, 50, 22,},{  6, 51, 23,}}},
846   { QR_VER_26, QR_LEVEL_H, {{33, 46, 16,},{  4, 47, 17,}}},
847
848   { QR_VER_27, QR_LEVEL_L, {{ 8,152,122,},{  4,153,123,}}},
849   { QR_VER_27, QR_LEVEL_M, {{22, 73, 45,},{  3, 74, 46,}}},
850   { QR_VER_27, QR_LEVEL_Q, {{ 8, 53, 23,},{ 26, 54, 24,}}},
851   { QR_VER_27, QR_LEVEL_H, {{12, 45, 15,},{ 28, 46, 16,}}},
852
853   { QR_VER_28, QR_LEVEL_L, {{ 3,147,117,},{ 10,148,118,}}},
854   { QR_VER_28, QR_LEVEL_M, {{ 3, 73, 45,},{ 23, 74, 46,}}},
855   { QR_VER_28, QR_LEVEL_Q, {{ 4, 54, 24,},{ 31, 55, 25,}}},
856   { QR_VER_28, QR_LEVEL_H, {{11, 45, 15,},{ 31, 46, 16,}}},
857
858   { QR_VER_29, QR_LEVEL_L, {{ 7,146,116,},{  7,147,117,}}},
859   { QR_VER_29, QR_LEVEL_M, {{21, 73, 45,},{  7, 74, 46,}}},
860   { QR_VER_29, QR_LEVEL_Q, {{ 1, 53, 23,},{ 37, 54, 24,}}},
861   { QR_VER_29, QR_LEVEL_H, {{19, 45, 15,},{ 26, 46, 16,}}},
862
863   { QR_VER_30, QR_LEVEL_L, {{ 5,145,115,},{ 10,146,116,}}},
864   { QR_VER_30, QR_LEVEL_M, {{19, 75, 47,},{ 10, 76, 48,}}},
865   { QR_VER_30, QR_LEVEL_Q, {{15, 54, 24,},{ 25, 55, 25,}}},
866   { QR_VER_30, QR_LEVEL_H, {{23, 45, 15,},{ 25, 46, 16,}}},
867
868   { QR_VER_31, QR_LEVEL_L, {{13,145,115,},{  3,146,116,}}},
869   { QR_VER_31, QR_LEVEL_M, {{ 2, 74, 46,},{ 29, 75, 47,}}},
870   { QR_VER_31, QR_LEVEL_Q, {{42, 54, 24,},{  1, 55, 25,}}},
871   { QR_VER_31, QR_LEVEL_H, {{23, 45, 15,},{ 28, 46, 16,}}},
872
873   { QR_VER_32, QR_LEVEL_L, {{17,145,115,},{  0,  0,  0,}}},
874   { QR_VER_32, QR_LEVEL_M, {{10, 74, 46,},{ 23, 75, 47,}}},
875   { QR_VER_32, QR_LEVEL_Q, {{10, 54, 24,},{ 35, 55, 25,}}},
876   { QR_VER_32, QR_LEVEL_H, {{19, 45, 15,},{ 35, 46, 16,}}},
877
878   { QR_VER_33, QR_LEVEL_L, {{17,145,115,},{  1,146,116,}}},
879   { QR_VER_33, QR_LEVEL_M, {{14, 74, 46,},{ 21, 75, 47,}}},
880   { QR_VER_33, QR_LEVEL_Q, {{29, 54, 24,},{ 19, 55, 25,}}},
881   { QR_VER_33, QR_LEVEL_H, {{11, 45, 15,},{ 46, 46, 16,}}},
882
883   { QR_VER_34, QR_LEVEL_L, {{13,145,115,},{  6,146,116,}}},
884   { QR_VER_34, QR_LEVEL_M, {{14, 74, 46,},{ 23, 75, 47,}}},
885   { QR_VER_34, QR_LEVEL_Q, {{44, 54, 24,},{  7, 55, 25,}}},
886   { QR_VER_34, QR_LEVEL_H, {{59, 46, 16,},{  1, 47, 17,}}},
887
888   { QR_VER_35, QR_LEVEL_L, {{12,151,121,},{  7,152,122,}}},
889   { QR_VER_35, QR_LEVEL_M, {{12, 75, 47,},{ 26, 76, 48,}}},
890   { QR_VER_35, QR_LEVEL_Q, {{39, 54, 24,},{ 14, 55, 25,}}},
891   { QR_VER_35, QR_LEVEL_H, {{22, 45, 15,},{ 41, 46, 16,}}},
892
893   { QR_VER_36, QR_LEVEL_L, {{ 6,151,121,},{ 14,152,122,}}},
894   { QR_VER_36, QR_LEVEL_M, {{ 6, 75, 47,},{ 34, 76, 48,}}},
895   { QR_VER_36, QR_LEVEL_Q, {{46, 54, 24,},{ 10, 55, 25,}}},
896   { QR_VER_36, QR_LEVEL_H, {{ 2, 45, 15,},{ 64, 46, 16,}}},
897
898   { QR_VER_37, QR_LEVEL_L, {{17,152,122,},{  4,153,123,}}},
899   { QR_VER_37, QR_LEVEL_M, {{29, 74, 46,},{ 14, 75, 47,}}},
900   { QR_VER_37, QR_LEVEL_Q, {{49, 54, 24,},{ 10, 55, 25,}}},
901   { QR_VER_37, QR_LEVEL_H, {{24, 45, 15,},{ 46, 46, 16,}}},
902
903   { QR_VER_38, QR_LEVEL_L, {{ 4,152,122,},{ 18,153,123,}}},
904   { QR_VER_38, QR_LEVEL_M, {{13, 74, 46,},{ 32, 75, 47,}}},
905   { QR_VER_38, QR_LEVEL_Q, {{48, 54, 24,},{ 14, 55, 25,}}},
906   { QR_VER_38, QR_LEVEL_H, {{42, 45, 15,},{ 32, 46, 16,}}},
907
908   { QR_VER_39, QR_LEVEL_L, {{20,147,117,},{  4,148,118,}}},
909   { QR_VER_39, QR_LEVEL_M, {{40, 75, 47,},{  7, 76, 48,}}},
910   { QR_VER_39, QR_LEVEL_Q, {{43, 54, 24,},{ 22, 55, 25,}}},
911   { QR_VER_39, QR_LEVEL_H, {{10, 45, 15,},{ 67, 46, 16,}}},
912
913   { QR_VER_40, QR_LEVEL_L, {{19,148,118,},{  6,149,119,}}},
914   { QR_VER_40, QR_LEVEL_M, {{18, 75, 47,},{ 31, 76, 48,}}},
915   { QR_VER_40, QR_LEVEL_Q, {{34, 54, 24,},{ 34, 55, 25,}}},
916   { QR_VER_40, QR_LEVEL_H, {{20, 45, 15,},{ 61, 46, 16,}}},
917 };
918
919
920
921
922 /**
923  * ¸í¤êÄûÀµ¾ðÊó¤òÉղä·¤Þ¤¹¡£¤Þ¤¿¡¢£Ò£Ó¥Ö¥í¥Ã¥¯¿ô¤¬Ê£¿ô¤Î¾ì¹ç¤Ï¡¢
924  * ¥¤¥ó¥¿¥ê¡¼¥Ö¤·¤¿·ë²Ì¤ò<code>dst</code>¤ËÀßÄꤷ¤Þ¤¹.
925  */
926 int
927 chxj_calc_ecc(qr_code_t     *qrcode,
928               unsigned char *indata, 
929               unsigned char *dst)
930 {
931   request_rec *r = qrcode->r;
932   int ii;
933   int jj;
934   int rslt_pos = 0;
935   int in_pos = 0;
936   int xx;
937   int rs_pos;
938   int rs_cnt;
939   int data_count;
940   int ecc_count;
941   int rs_total_block_count;   /* RS¥Ö¥í¥Ã¥¯Áí¿ô */
942   int *rs_block_rest;         /* RS¥Ö¥í¥Ã¥¯Ëè¤Î»Ä¿ô */
943   int *rs_block_size;         /* RS¥Ö¥í¥Ã¥¯Ëè¤Î¥µ¥¤¥º */
944   int *rs_block_ecc_size;     /* RS¥Ö¥í¥Ã¥¯Ëè¤Îecc¤Î¥µ¥¤¥º */
945   int now_rs_num;
946   int total_size;
947   int exist_flag = 0;
948   unsigned char** rs_block;
949 #ifdef QR_CODE_DEBUG
950   DBG(r,"start chxj_calc_ecc()");
951 #endif
952
953   rs_total_block_count = v_ecc_spec_table[qrcode->version*4+qrcode->level].rs[0].rs_block_count +
954                          v_ecc_spec_table[qrcode->version*4+qrcode->level].rs[1].rs_block_count ;
955
956   rs_block = (unsigned char **)apr_palloc(r->pool, sizeof(unsigned char*)*rs_total_block_count);
957   rs_block_rest = (int *)apr_palloc(r->pool, sizeof(int)*rs_total_block_count);
958   rs_block_size = (int *)apr_palloc(r->pool, sizeof(int)*rs_total_block_count);
959   rs_block_ecc_size = (int *)apr_palloc(r->pool, sizeof(int)*rs_total_block_count);
960
961   total_size = (v_ecc_spec_table[qrcode->version*4+qrcode->level].rs[0].rs_block_count 
962                * v_ecc_spec_table[qrcode->version*4+qrcode->level].rs[0].total_code_count) +
963                (v_ecc_spec_table[qrcode->version*4+qrcode->level].rs[1].rs_block_count 
964                 * v_ecc_spec_table[qrcode->version*4+qrcode->level].rs[1].total_code_count);
965
966
967   now_rs_num = 0;
968   for (rs_pos = 0; rs_pos < 2; rs_pos++) {
969     for (rs_cnt = v_ecc_spec_table[qrcode->version*4+qrcode->level].rs[rs_pos].rs_block_count;
970          rs_cnt > 0;
971          rs_cnt--) {
972
973       unsigned char *tmp;
974       int  rs_ii = 0;
975
976       data_count  = v_ecc_spec_table[qrcode->version*4+qrcode->level].rs[rs_pos].data_code_count;
977       ecc_count = v_ecc_spec_table[qrcode->version*4+qrcode->level].rs[rs_pos].total_code_count - data_count;
978
979 #ifdef QR_CODE_DEBUG
980       DBG(r,"data_count[%d] ecc_count[%d]", data_count, ecc_count);
981 #endif
982
983       rs_block[now_rs_num] = (unsigned char*)apr_palloc(qrcode->r->pool, data_count + ecc_count + 1);
984       tmp = (unsigned char*)apr_palloc(qrcode->r->pool, data_count + ecc_count + 1);
985
986       rs_block_size[now_rs_num] = rs_block_rest[now_rs_num] = data_count + ecc_count;
987       rs_block_ecc_size[now_rs_num] = ecc_count;
988
989 #ifdef QR_CODE_DEBUG
990       DBG(r,"apr_palloc() tmp");
991 #endif
992
993       memset(tmp, 0, data_count + ecc_count + 1);
994       memset(rs_block[now_rs_num], 0, data_count + ecc_count + 1);
995
996 #ifdef QR_CODE_DEBUG
997       DBG(r,"memset end");
998 #endif
999
1000       /* ¸µ¥Ç¡¼¥¿¤ò¥³¥Ô¡¼ */
1001       for (jj=0; jj<data_count; jj++) {
1002         tmp[data_count + ecc_count - 1 - jj] = indata[in_pos];
1003
1004         rs_block[now_rs_num][rs_ii++] = indata[in_pos];
1005
1006         in_pos++;
1007       }
1008 #ifdef QR_CODE_DEBUG
1009       /* for DEBUG */
1010       do {
1011         char *debug_rows;
1012
1013         debug_rows    = apr_palloc(r->pool, 1);
1014         debug_rows[0] = 0;
1015
1016         for (jj=ecc_count + data_count - 1; jj>=0; jj--)
1017           debug_rows = apr_pstrcat(r->pool, debug_rows, apr_psprintf(r->pool, "[%d]", tmp[jj]), NULL);
1018
1019         DBG(r,"rows [%s]", debug_rows);
1020       } while(0);
1021       /* for DEBUG END */
1022 #endif
1023
1024       ii=data_count + ecc_count -1;
1025
1026       for (xx = data_count - 1; xx >= 0; xx--) {
1027         int tgt = tmp[ii--];
1028         int shisu = v_galois_int_to_log[tgt];
1029 #ifdef QR_CODE_DEBUG
1030         DBG(r,"tgt[%d] shisu[%d]", tgt, shisu);
1031 #endif
1032         if (tgt == 0)
1033           continue;
1034
1035         for (jj=ecc_count; jj>=0;jj--) {
1036           assert(v_poly_ecc[ecc_count] != NULL);
1037           tmp[jj+xx] ^= v_galois_log_to_int[(v_poly_ecc[ecc_count][jj] + shisu)]; 
1038         }
1039 #ifdef QR_CODE_DEBUG
1040         /* for DEBUG */
1041         do {
1042           char *debug_rows;
1043
1044           debug_rows = apr_palloc(r->pool, 1);
1045           debug_rows[0] = 0;
1046           for (jj=ecc_count + data_count - 1; jj>=0; jj--)
1047             debug_rows = apr_pstrcat(r->pool, debug_rows, apr_psprintf(r->pool, "[%d]", tmp[jj]), NULL);
1048
1049           DBG(r,"rows [%s]", debug_rows);
1050         } while(0);
1051         /* for DEBUG END */
1052 #endif
1053       }
1054
1055       for (; ii>=0; ii--)
1056         rs_block[now_rs_num][rs_ii++] = tmp[ii];
1057
1058       now_rs_num++;
1059     }
1060   }
1061
1062 #ifdef QR_CODE_DEBUG
1063   /* for DEBUG */
1064   do {
1065     DBG(r,"######### RS BLOCK DUMP ###############");
1066     for (jj=0; jj<rs_total_block_count; jj++) {
1067        char *rows = apr_psprintf(r->pool, "%02d size:[%d] rest:[%d]",jj, rs_block_size[jj], rs_block_rest[jj]);
1068        for (ii=0; ii<rs_block_size[jj]; ii++) {
1069          rows = apr_pstrcat(r->pool, rows, apr_psprintf(r->pool, "[%d]", rs_block[jj][ii]), NULL);
1070        }
1071        DBG(r,"%s", rows);
1072     }
1073   } while(0);
1074 #endif
1075
1076
1077   /* ¥¤¥ó¥¿¥ê¡¼¥Ö¤Î¼ÂÁõ ¡Ê¥Ç¡¼¥¿Éô¡Ë*/
1078   for (;;) {
1079     exist_flag = 0;
1080     for (jj=0; jj<rs_total_block_count; jj++) {
1081       if (rs_block_rest[jj] - rs_block_ecc_size[jj] > 0) {
1082         dst[rslt_pos++] = rs_block[jj][rs_block_size[jj]-rs_block_rest[jj]];
1083         rs_block_rest[jj]--;
1084         exist_flag = 1;
1085       }
1086     }
1087     if (exist_flag == 0) {
1088       /* RS¥Ö¥í¥Ã¥¯¤Î»Ä¿ô¤¬Á´¤Æ£°¤Ë¤Ê¤Ã¤¿¤é¡¢½ªÎ» */
1089       break;
1090     }
1091   }
1092   /* ¥¤¥ó¥¿¥ê¡¼¥Ö¤Î¼ÂÁõ¡Ê£Å£Ã£ÃÉô¡Ë */
1093   for (;;) {
1094     exist_flag = 0;
1095     for (jj=0; jj<rs_total_block_count; jj++) {
1096       if (rs_block_rest[jj] > 0) {
1097         dst[rslt_pos++] = rs_block[jj][rs_block_size[jj]-rs_block_rest[jj]];
1098         rs_block_rest[jj]--;
1099         exist_flag = 1;
1100       }
1101     }
1102     if (exist_flag == 0) {
1103       /* RS¥Ö¥í¥Ã¥¯¤Î»Ä¿ô¤¬Á´¤Æ£°¤Ë¤Ê¤Ã¤¿¤é¡¢½ªÎ» */
1104       break;
1105     }
1106   }
1107 #ifdef QR_CODE_DEBUG
1108   /* for DEBUG */
1109   do {
1110     DBG(r,"######### AFTER BLOCK DUMP ###############");
1111     for (ii=0; ii<rslt_pos; ii++) {
1112       DBG(r,"[%d]", dst[ii]);
1113     }
1114   } while(0);
1115 #endif
1116
1117   return rslt_pos;
1118 }
1119 /*
1120  * vim:ts=2 et
1121  */