1// Copyright 2014 PDFium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6// Original code is licensed as follows:
7/*
8 * Copyright 2007 ZXing authors
9 *
10 * Licensed under the Apache License, Version 2.0 (the "License");
11 * you may not use this file except in compliance with the License.
12 * You may obtain a copy of the License at
13 *
14 *      http://www.apache.org/licenses/LICENSE-2.0
15 *
16 * Unless required by applicable law or agreed to in writing, software
17 * distributed under the License is distributed on an "AS IS" BASIS,
18 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19 * See the License for the specific language governing permissions and
20 * limitations under the License.
21 */
22
23#include "xfa/src/fxbarcode/barcode.h"
24#include "xfa/src/fxbarcode/utils.h"
25#include "xfa/src/fxbarcode/common/BC_CommonBitMatrix.h"
26#include "BC_QRCoderECB.h"
27#include "BC_QRCoderFormatInformation.h"
28#include "BC_QRCoderErrorCorrectionLevel.h"
29#include "BC_QRCoderBitVector.h"
30#include "BC_QRCoderECBlocks.h"
31#include "BC_QRCoderVersion.h"
32const int32_t CBC_QRCoderVersion::VERSION_DECODE_INFO[] = {
33    0x07C94, 0x085BC, 0x09A99, 0x0A4D3, 0x0BBF6, 0x0C762, 0x0D847,
34    0x0E60D, 0x0F928, 0x10B78, 0x1145D, 0x12A17, 0x13532, 0x149A6,
35    0x15683, 0x168C9, 0x177EC, 0x18EC4, 0x191E1, 0x1AFAB, 0x1B08E,
36    0x1CC1A, 0x1D33F, 0x1ED75, 0x1F250, 0x209D5, 0x216F0, 0x228BA,
37    0x2379F, 0x24B0B, 0x2542E, 0x26A64, 0x27541, 0x28C69};
38CFX_PtrArray* CBC_QRCoderVersion::VERSION = NULL;
39void CBC_QRCoderVersion::Initialize() {
40  VERSION = new CFX_PtrArray();
41}
42void CBC_QRCoderVersion::Finalize() {
43  for (int32_t i = 0; i < VERSION->GetSize(); i++) {
44    CBC_QRCoderVersion* v = (CBC_QRCoderVersion*)(VERSION->GetAt(i));
45    delete v;
46  }
47  delete VERSION;
48}
49CBC_QRCoderVersion::CBC_QRCoderVersion(int32_t versionNumber,
50                                       CBC_QRCoderECBlocks* ecBlocks1,
51                                       CBC_QRCoderECBlocks* ecBlocks2,
52                                       CBC_QRCoderECBlocks* ecBlocks3,
53                                       CBC_QRCoderECBlocks* ecBlocks4) {
54  m_versionNumber = versionNumber;
55  m_ecBlocks.Add(ecBlocks1);
56  m_ecBlocks.Add(ecBlocks2);
57  m_ecBlocks.Add(ecBlocks3);
58  m_ecBlocks.Add(ecBlocks4);
59  int32_t total = 0;
60  int32_t ecCodeWords = ecBlocks1->GetECCodeWordsPerBlock();
61  CFX_PtrArray* ecbArray = ecBlocks1->GetECBlocks();
62  for (int32_t i = 0; i < ecbArray->GetSize(); i++) {
63    CBC_QRCoderECB* ecBlock = (CBC_QRCoderECB*)((*ecbArray)[i]);
64    total += ecBlock->GetCount() * (ecBlock->GetDataCodeWords() + ecCodeWords);
65  }
66  m_totalCodeWords = total;
67  switch (versionNumber) {
68    case 1:
69      break;
70    case 2:
71      m_alignmentPatternCenters.Add(6);
72      m_alignmentPatternCenters.Add(18);
73      break;
74    case 3:
75      m_alignmentPatternCenters.Add(6);
76      m_alignmentPatternCenters.Add(22);
77      break;
78    case 4:
79      m_alignmentPatternCenters.Add(6);
80      m_alignmentPatternCenters.Add(26);
81      break;
82    case 5:
83      m_alignmentPatternCenters.Add(6);
84      m_alignmentPatternCenters.Add(30);
85      break;
86    case 6:
87      m_alignmentPatternCenters.Add(6);
88      m_alignmentPatternCenters.Add(34);
89      break;
90    case 7:
91      m_alignmentPatternCenters.Add(6);
92      m_alignmentPatternCenters.Add(22);
93      m_alignmentPatternCenters.Add(38);
94      break;
95    case 8:
96      m_alignmentPatternCenters.Add(6);
97      m_alignmentPatternCenters.Add(24);
98      m_alignmentPatternCenters.Add(42);
99      break;
100    case 9:
101      m_alignmentPatternCenters.Add(6);
102      m_alignmentPatternCenters.Add(26);
103      m_alignmentPatternCenters.Add(46);
104      break;
105    case 10:
106      m_alignmentPatternCenters.Add(6);
107      m_alignmentPatternCenters.Add(28);
108      m_alignmentPatternCenters.Add(50);
109      break;
110    case 11:
111      m_alignmentPatternCenters.Add(6);
112      m_alignmentPatternCenters.Add(30);
113      m_alignmentPatternCenters.Add(54);
114      break;
115    case 12:
116      m_alignmentPatternCenters.Add(6);
117      m_alignmentPatternCenters.Add(32);
118      m_alignmentPatternCenters.Add(58);
119      break;
120    case 13:
121      m_alignmentPatternCenters.Add(6);
122      m_alignmentPatternCenters.Add(34);
123      m_alignmentPatternCenters.Add(62);
124      break;
125    case 14:
126      m_alignmentPatternCenters.Add(6);
127      m_alignmentPatternCenters.Add(26);
128      m_alignmentPatternCenters.Add(46);
129      m_alignmentPatternCenters.Add(66);
130      break;
131    case 15:
132      m_alignmentPatternCenters.Add(6);
133      m_alignmentPatternCenters.Add(26);
134      m_alignmentPatternCenters.Add(48);
135      m_alignmentPatternCenters.Add(70);
136      break;
137    case 16:
138      m_alignmentPatternCenters.Add(6);
139      m_alignmentPatternCenters.Add(26);
140      m_alignmentPatternCenters.Add(50);
141      m_alignmentPatternCenters.Add(74);
142      break;
143    case 17:
144      m_alignmentPatternCenters.Add(6);
145      m_alignmentPatternCenters.Add(30);
146      m_alignmentPatternCenters.Add(54);
147      m_alignmentPatternCenters.Add(78);
148      break;
149    case 18:
150      m_alignmentPatternCenters.Add(6);
151      m_alignmentPatternCenters.Add(30);
152      m_alignmentPatternCenters.Add(56);
153      m_alignmentPatternCenters.Add(82);
154      break;
155    case 19:
156      m_alignmentPatternCenters.Add(6);
157      m_alignmentPatternCenters.Add(30);
158      m_alignmentPatternCenters.Add(58);
159      m_alignmentPatternCenters.Add(86);
160      break;
161    case 20:
162      m_alignmentPatternCenters.Add(6);
163      m_alignmentPatternCenters.Add(34);
164      m_alignmentPatternCenters.Add(62);
165      m_alignmentPatternCenters.Add(90);
166      break;
167    case 21:
168      m_alignmentPatternCenters.Add(6);
169      m_alignmentPatternCenters.Add(28);
170      m_alignmentPatternCenters.Add(50);
171      m_alignmentPatternCenters.Add(72);
172      m_alignmentPatternCenters.Add(94);
173      break;
174    case 22:
175      m_alignmentPatternCenters.Add(6);
176      m_alignmentPatternCenters.Add(26);
177      m_alignmentPatternCenters.Add(50);
178      m_alignmentPatternCenters.Add(74);
179      m_alignmentPatternCenters.Add(98);
180      break;
181    case 23:
182      m_alignmentPatternCenters.Add(6);
183      m_alignmentPatternCenters.Add(30);
184      m_alignmentPatternCenters.Add(54);
185      m_alignmentPatternCenters.Add(74);
186      m_alignmentPatternCenters.Add(102);
187      break;
188    case 24:
189      m_alignmentPatternCenters.Add(6);
190      m_alignmentPatternCenters.Add(28);
191      m_alignmentPatternCenters.Add(54);
192      m_alignmentPatternCenters.Add(80);
193      m_alignmentPatternCenters.Add(106);
194      break;
195    case 25:
196      m_alignmentPatternCenters.Add(6);
197      m_alignmentPatternCenters.Add(32);
198      m_alignmentPatternCenters.Add(58);
199      m_alignmentPatternCenters.Add(84);
200      m_alignmentPatternCenters.Add(110);
201      break;
202    case 26:
203      m_alignmentPatternCenters.Add(6);
204      m_alignmentPatternCenters.Add(30);
205      m_alignmentPatternCenters.Add(58);
206      m_alignmentPatternCenters.Add(86);
207      m_alignmentPatternCenters.Add(114);
208      break;
209    case 27:
210      m_alignmentPatternCenters.Add(6);
211      m_alignmentPatternCenters.Add(34);
212      m_alignmentPatternCenters.Add(62);
213      m_alignmentPatternCenters.Add(90);
214      m_alignmentPatternCenters.Add(118);
215      break;
216    case 28:
217      m_alignmentPatternCenters.Add(6);
218      m_alignmentPatternCenters.Add(26);
219      m_alignmentPatternCenters.Add(50);
220      m_alignmentPatternCenters.Add(74);
221      m_alignmentPatternCenters.Add(98);
222      m_alignmentPatternCenters.Add(122);
223      break;
224    case 29:
225      m_alignmentPatternCenters.Add(6);
226      m_alignmentPatternCenters.Add(30);
227      m_alignmentPatternCenters.Add(54);
228      m_alignmentPatternCenters.Add(78);
229      m_alignmentPatternCenters.Add(102);
230      m_alignmentPatternCenters.Add(126);
231      break;
232    case 30:
233      m_alignmentPatternCenters.Add(6);
234      m_alignmentPatternCenters.Add(26);
235      m_alignmentPatternCenters.Add(52);
236      m_alignmentPatternCenters.Add(78);
237      m_alignmentPatternCenters.Add(104);
238      m_alignmentPatternCenters.Add(130);
239      break;
240    case 31:
241      m_alignmentPatternCenters.Add(6);
242      m_alignmentPatternCenters.Add(30);
243      m_alignmentPatternCenters.Add(56);
244      m_alignmentPatternCenters.Add(82);
245      m_alignmentPatternCenters.Add(108);
246      m_alignmentPatternCenters.Add(134);
247      break;
248    case 32:
249      m_alignmentPatternCenters.Add(6);
250      m_alignmentPatternCenters.Add(34);
251      m_alignmentPatternCenters.Add(60);
252      m_alignmentPatternCenters.Add(86);
253      m_alignmentPatternCenters.Add(112);
254      m_alignmentPatternCenters.Add(138);
255      break;
256    case 33:
257      m_alignmentPatternCenters.Add(6);
258      m_alignmentPatternCenters.Add(30);
259      m_alignmentPatternCenters.Add(58);
260      m_alignmentPatternCenters.Add(86);
261      m_alignmentPatternCenters.Add(114);
262      m_alignmentPatternCenters.Add(142);
263      break;
264    case 34:
265      m_alignmentPatternCenters.Add(6);
266      m_alignmentPatternCenters.Add(34);
267      m_alignmentPatternCenters.Add(62);
268      m_alignmentPatternCenters.Add(90);
269      m_alignmentPatternCenters.Add(118);
270      m_alignmentPatternCenters.Add(146);
271      break;
272    case 35:
273      m_alignmentPatternCenters.Add(6);
274      m_alignmentPatternCenters.Add(30);
275      m_alignmentPatternCenters.Add(54);
276      m_alignmentPatternCenters.Add(78);
277      m_alignmentPatternCenters.Add(102);
278      m_alignmentPatternCenters.Add(126);
279      m_alignmentPatternCenters.Add(150);
280      break;
281    case 36:
282      m_alignmentPatternCenters.Add(6);
283      m_alignmentPatternCenters.Add(24);
284      m_alignmentPatternCenters.Add(50);
285      m_alignmentPatternCenters.Add(76);
286      m_alignmentPatternCenters.Add(102);
287      m_alignmentPatternCenters.Add(128);
288      m_alignmentPatternCenters.Add(154);
289      break;
290    case 37:
291      m_alignmentPatternCenters.Add(6);
292      m_alignmentPatternCenters.Add(28);
293      m_alignmentPatternCenters.Add(54);
294      m_alignmentPatternCenters.Add(80);
295      m_alignmentPatternCenters.Add(106);
296      m_alignmentPatternCenters.Add(132);
297      m_alignmentPatternCenters.Add(158);
298      break;
299    case 38:
300      m_alignmentPatternCenters.Add(6);
301      m_alignmentPatternCenters.Add(32);
302      m_alignmentPatternCenters.Add(58);
303      m_alignmentPatternCenters.Add(84);
304      m_alignmentPatternCenters.Add(110);
305      m_alignmentPatternCenters.Add(136);
306      m_alignmentPatternCenters.Add(162);
307      break;
308    case 39:
309      m_alignmentPatternCenters.Add(6);
310      m_alignmentPatternCenters.Add(26);
311      m_alignmentPatternCenters.Add(54);
312      m_alignmentPatternCenters.Add(82);
313      m_alignmentPatternCenters.Add(110);
314      m_alignmentPatternCenters.Add(138);
315      m_alignmentPatternCenters.Add(166);
316      break;
317    case 40:
318      m_alignmentPatternCenters.Add(6);
319      m_alignmentPatternCenters.Add(30);
320      m_alignmentPatternCenters.Add(58);
321      m_alignmentPatternCenters.Add(86);
322      m_alignmentPatternCenters.Add(114);
323      m_alignmentPatternCenters.Add(142);
324      m_alignmentPatternCenters.Add(170);
325      break;
326  }
327}
328CBC_QRCoderVersion::~CBC_QRCoderVersion() {
329  if (m_ecBlocks.GetSize() != 0) {
330    int32_t itBeg = 0;
331    int32_t itEnd = m_ecBlocks.GetSize();
332    while (itBeg != itEnd) {
333      delete ((CBC_QRCoderECBlocks*)(m_ecBlocks[itBeg]));
334      itBeg++;
335    }
336  }
337}
338int32_t CBC_QRCoderVersion::GetVersionNumber() {
339  return m_versionNumber;
340}
341CFX_Int32Array* CBC_QRCoderVersion::GetAlignmentPatternCenters() {
342  return &m_alignmentPatternCenters;
343}
344int32_t CBC_QRCoderVersion::GetTotalCodeWords() {
345  return m_totalCodeWords;
346}
347int32_t CBC_QRCoderVersion::GetDimensionForVersion() {
348  return 17 + 4 * m_versionNumber;
349}
350CBC_QRCoderECBlocks* CBC_QRCoderVersion::GetECBlocksForLevel(
351    CBC_QRCoderErrorCorrectionLevel* ecLevel) {
352  return (CBC_QRCoderECBlocks*)m_ecBlocks[ecLevel->Ordinal()];
353}
354CBC_QRCoderVersion* CBC_QRCoderVersion::GetProvisionalVersionForDimension(
355    int32_t dimension,
356    int32_t& e) {
357  if ((dimension % 4) != 1) {
358    e = BCExceptionRead;
359    BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
360  }
361  CBC_QRCoderVersion* qcv = GetVersionForNumber((dimension - 17) >> 2, e);
362  BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
363  return qcv;
364}
365CBC_QRCoderVersion* CBC_QRCoderVersion::DecodeVersionInformation(
366    int32_t versionBits,
367    int32_t& e) {
368  int32_t bestDifference = FXSYS_IntMax;
369  int32_t bestVersion = 0;
370  for (int32_t i = 0; i < 34; i++) {
371    int32_t targetVersion = VERSION_DECODE_INFO[i];
372    if (targetVersion == versionBits) {
373      CBC_QRCoderVersion* qcv = GetVersionForNumber(i + 7, e);
374      BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
375      return qcv;
376    }
377    int32_t bitsDifference = CBC_QRCoderFormatInformation::NumBitsDiffering(
378        versionBits, targetVersion);
379    if (bitsDifference < bestDifference) {
380      bestVersion = i + 7;
381      bestDifference = bitsDifference;
382    }
383  }
384  if (bestDifference <= 3) {
385    CBC_QRCoderVersion* qcv = GetVersionForNumber(bestVersion, e);
386    BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
387    return qcv;
388  }
389  return NULL;
390}
391CBC_CommonBitMatrix* CBC_QRCoderVersion::BuildFunctionPattern(int32_t& e) {
392  int32_t dimension = GetDimensionForVersion();
393  CBC_CommonBitMatrix* bitMatrix = new CBC_CommonBitMatrix();
394  bitMatrix->Init(dimension);
395  bitMatrix->SetRegion(0, 0, 9, 9, e);
396  BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
397  bitMatrix->SetRegion(dimension - 8, 0, 8, 9, e);
398  BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
399  bitMatrix->SetRegion(0, dimension - 8, 9, 8, e);
400  BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
401  int32_t max = m_alignmentPatternCenters.GetSize();
402  for (int32_t x = 0; x < max; x++) {
403    int32_t i = m_alignmentPatternCenters[x] - 2;
404    for (int32_t y = 0; y < max; y++) {
405      if ((x == 0 && (y == 0 || y == max - 1)) || (x == max - 1 && y == 0)) {
406        continue;
407      }
408      bitMatrix->SetRegion(m_alignmentPatternCenters[y] - 2, i, 5, 5, e);
409      BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
410    }
411  }
412  bitMatrix->SetRegion(6, 9, 1, dimension - 17, e);
413  BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
414  bitMatrix->SetRegion(9, 6, dimension - 17, 1, e);
415  BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
416  if (m_versionNumber > 6) {
417    bitMatrix->SetRegion(dimension - 11, 0, 3, 6, e);
418    BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
419    bitMatrix->SetRegion(0, dimension - 11, 6, 3, e);
420    BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
421  }
422  return bitMatrix;
423}
424CBC_QRCoderVersion* CBC_QRCoderVersion::GetVersionForNumber(
425    int32_t versionNumber,
426    int32_t& e) {
427  if (VERSION->GetSize() == 0) {
428    VERSION->Add(new CBC_QRCoderVersion(
429        1, new CBC_QRCoderECBlocks(7, new CBC_QRCoderECB(1, 19)),
430        new CBC_QRCoderECBlocks(10, new CBC_QRCoderECB(1, 16)),
431        new CBC_QRCoderECBlocks(13, new CBC_QRCoderECB(1, 13)),
432        new CBC_QRCoderECBlocks(17, new CBC_QRCoderECB(1, 9))));
433    VERSION->Add(new CBC_QRCoderVersion(
434        2, new CBC_QRCoderECBlocks(10, new CBC_QRCoderECB(1, 34)),
435        new CBC_QRCoderECBlocks(16, new CBC_QRCoderECB(1, 28)),
436        new CBC_QRCoderECBlocks(22, new CBC_QRCoderECB(1, 22)),
437        new CBC_QRCoderECBlocks(28, new CBC_QRCoderECB(1, 16))));
438    VERSION->Add(new CBC_QRCoderVersion(
439        3, new CBC_QRCoderECBlocks(15, new CBC_QRCoderECB(1, 55)),
440        new CBC_QRCoderECBlocks(26, new CBC_QRCoderECB(1, 44)),
441        new CBC_QRCoderECBlocks(18, new CBC_QRCoderECB(2, 17)),
442        new CBC_QRCoderECBlocks(22, new CBC_QRCoderECB(2, 13))));
443    VERSION->Add(new CBC_QRCoderVersion(
444        4, new CBC_QRCoderECBlocks(20, new CBC_QRCoderECB(1, 80)),
445        new CBC_QRCoderECBlocks(18, new CBC_QRCoderECB(2, 32)),
446        new CBC_QRCoderECBlocks(26, new CBC_QRCoderECB(2, 24)),
447        new CBC_QRCoderECBlocks(16, new CBC_QRCoderECB(4, 9))));
448    VERSION->Add(new CBC_QRCoderVersion(
449        5, new CBC_QRCoderECBlocks(26, new CBC_QRCoderECB(1, 108)),
450        new CBC_QRCoderECBlocks(24, new CBC_QRCoderECB(2, 43)),
451        new CBC_QRCoderECBlocks(18, new CBC_QRCoderECB(2, 15),
452                                new CBC_QRCoderECB(2, 16)),
453        new CBC_QRCoderECBlocks(22, new CBC_QRCoderECB(2, 11),
454                                new CBC_QRCoderECB(2, 12))));
455    VERSION->Add(new CBC_QRCoderVersion(
456        6, new CBC_QRCoderECBlocks(18, new CBC_QRCoderECB(2, 68)),
457        new CBC_QRCoderECBlocks(16, new CBC_QRCoderECB(4, 27)),
458        new CBC_QRCoderECBlocks(24, new CBC_QRCoderECB(4, 19)),
459        new CBC_QRCoderECBlocks(28, new CBC_QRCoderECB(4, 15))));
460    VERSION->Add(new CBC_QRCoderVersion(
461        7, new CBC_QRCoderECBlocks(20, new CBC_QRCoderECB(2, 78)),
462        new CBC_QRCoderECBlocks(18, new CBC_QRCoderECB(4, 31)),
463        new CBC_QRCoderECBlocks(18, new CBC_QRCoderECB(2, 14),
464                                new CBC_QRCoderECB(4, 15)),
465        new CBC_QRCoderECBlocks(26, new CBC_QRCoderECB(4, 13),
466                                new CBC_QRCoderECB(1, 14))));
467    VERSION->Add(new CBC_QRCoderVersion(
468        8, new CBC_QRCoderECBlocks(24, new CBC_QRCoderECB(2, 97)),
469        new CBC_QRCoderECBlocks(22, new CBC_QRCoderECB(2, 38),
470                                new CBC_QRCoderECB(2, 39)),
471        new CBC_QRCoderECBlocks(22, new CBC_QRCoderECB(4, 18),
472                                new CBC_QRCoderECB(2, 19)),
473        new CBC_QRCoderECBlocks(26, new CBC_QRCoderECB(4, 14),
474                                new CBC_QRCoderECB(2, 15))));
475    VERSION->Add(new CBC_QRCoderVersion(
476        9, new CBC_QRCoderECBlocks(30, new CBC_QRCoderECB(2, 116)),
477        new CBC_QRCoderECBlocks(22, new CBC_QRCoderECB(3, 36),
478                                new CBC_QRCoderECB(2, 37)),
479        new CBC_QRCoderECBlocks(20, new CBC_QRCoderECB(4, 16),
480                                new CBC_QRCoderECB(4, 17)),
481        new CBC_QRCoderECBlocks(24, new CBC_QRCoderECB(4, 12),
482                                new CBC_QRCoderECB(4, 13))));
483    VERSION->Add(new CBC_QRCoderVersion(
484        10, new CBC_QRCoderECBlocks(18, new CBC_QRCoderECB(2, 68),
485                                    new CBC_QRCoderECB(2, 69)),
486        new CBC_QRCoderECBlocks(26, new CBC_QRCoderECB(4, 43),
487                                new CBC_QRCoderECB(1, 44)),
488        new CBC_QRCoderECBlocks(24, new CBC_QRCoderECB(6, 19),
489                                new CBC_QRCoderECB(2, 20)),
490        new CBC_QRCoderECBlocks(28, new CBC_QRCoderECB(6, 15),
491                                new CBC_QRCoderECB(2, 16))));
492    VERSION->Add(new CBC_QRCoderVersion(
493        11, new CBC_QRCoderECBlocks(20, new CBC_QRCoderECB(4, 81)),
494        new CBC_QRCoderECBlocks(30, new CBC_QRCoderECB(1, 50),
495                                new CBC_QRCoderECB(4, 51)),
496        new CBC_QRCoderECBlocks(28, new CBC_QRCoderECB(4, 22),
497                                new CBC_QRCoderECB(4, 23)),
498        new CBC_QRCoderECBlocks(24, new CBC_QRCoderECB(3, 12),
499                                new CBC_QRCoderECB(8, 13))));
500    VERSION->Add(new CBC_QRCoderVersion(
501        12, new CBC_QRCoderECBlocks(24, new CBC_QRCoderECB(2, 92),
502                                    new CBC_QRCoderECB(2, 93)),
503        new CBC_QRCoderECBlocks(22, new CBC_QRCoderECB(6, 36),
504                                new CBC_QRCoderECB(2, 37)),
505        new CBC_QRCoderECBlocks(26, new CBC_QRCoderECB(4, 20),
506                                new CBC_QRCoderECB(6, 21)),
507        new CBC_QRCoderECBlocks(28, new CBC_QRCoderECB(7, 14),
508                                new CBC_QRCoderECB(4, 15))));
509    VERSION->Add(new CBC_QRCoderVersion(
510        13, new CBC_QRCoderECBlocks(26, new CBC_QRCoderECB(4, 107)),
511        new CBC_QRCoderECBlocks(22, new CBC_QRCoderECB(8, 37),
512                                new CBC_QRCoderECB(1, 38)),
513        new CBC_QRCoderECBlocks(24, new CBC_QRCoderECB(8, 20),
514                                new CBC_QRCoderECB(4, 21)),
515        new CBC_QRCoderECBlocks(22, new CBC_QRCoderECB(12, 11),
516                                new CBC_QRCoderECB(4, 12))));
517    VERSION->Add(new CBC_QRCoderVersion(
518        14, new CBC_QRCoderECBlocks(30, new CBC_QRCoderECB(3, 115),
519                                    new CBC_QRCoderECB(1, 116)),
520        new CBC_QRCoderECBlocks(24, new CBC_QRCoderECB(4, 40),
521                                new CBC_QRCoderECB(5, 41)),
522        new CBC_QRCoderECBlocks(20, new CBC_QRCoderECB(11, 16),
523                                new CBC_QRCoderECB(5, 17)),
524        new CBC_QRCoderECBlocks(24, new CBC_QRCoderECB(11, 12),
525                                new CBC_QRCoderECB(5, 13))));
526    VERSION->Add(new CBC_QRCoderVersion(
527        15, new CBC_QRCoderECBlocks(22, new CBC_QRCoderECB(5, 87),
528                                    new CBC_QRCoderECB(1, 88)),
529        new CBC_QRCoderECBlocks(24, new CBC_QRCoderECB(5, 41),
530                                new CBC_QRCoderECB(5, 42)),
531        new CBC_QRCoderECBlocks(30, new CBC_QRCoderECB(5, 24),
532                                new CBC_QRCoderECB(7, 25)),
533        new CBC_QRCoderECBlocks(24, new CBC_QRCoderECB(11, 12),
534                                new CBC_QRCoderECB(7, 13))));
535    VERSION->Add(new CBC_QRCoderVersion(
536        16, new CBC_QRCoderECBlocks(24, new CBC_QRCoderECB(5, 98),
537                                    new CBC_QRCoderECB(1, 99)),
538        new CBC_QRCoderECBlocks(28, new CBC_QRCoderECB(7, 45),
539                                new CBC_QRCoderECB(3, 46)),
540        new CBC_QRCoderECBlocks(24, new CBC_QRCoderECB(15, 19),
541                                new CBC_QRCoderECB(2, 20)),
542        new CBC_QRCoderECBlocks(30, new CBC_QRCoderECB(3, 15),
543                                new CBC_QRCoderECB(13, 16))));
544    VERSION->Add(new CBC_QRCoderVersion(
545        17, new CBC_QRCoderECBlocks(28, new CBC_QRCoderECB(1, 107),
546                                    new CBC_QRCoderECB(5, 108)),
547        new CBC_QRCoderECBlocks(28, new CBC_QRCoderECB(10, 46),
548                                new CBC_QRCoderECB(1, 47)),
549        new CBC_QRCoderECBlocks(28, new CBC_QRCoderECB(1, 22),
550                                new CBC_QRCoderECB(15, 23)),
551        new CBC_QRCoderECBlocks(28, new CBC_QRCoderECB(2, 14),
552                                new CBC_QRCoderECB(17, 15))));
553    VERSION->Add(new CBC_QRCoderVersion(
554        18, new CBC_QRCoderECBlocks(30, new CBC_QRCoderECB(5, 120),
555                                    new CBC_QRCoderECB(1, 121)),
556        new CBC_QRCoderECBlocks(26, new CBC_QRCoderECB(9, 43),
557                                new CBC_QRCoderECB(4, 44)),
558        new CBC_QRCoderECBlocks(28, new CBC_QRCoderECB(17, 22),
559                                new CBC_QRCoderECB(1, 23)),
560        new CBC_QRCoderECBlocks(28, new CBC_QRCoderECB(2, 14),
561                                new CBC_QRCoderECB(19, 15))));
562    VERSION->Add(new CBC_QRCoderVersion(
563        19, new CBC_QRCoderECBlocks(28, new CBC_QRCoderECB(3, 113),
564                                    new CBC_QRCoderECB(4, 114)),
565        new CBC_QRCoderECBlocks(26, new CBC_QRCoderECB(3, 44),
566                                new CBC_QRCoderECB(11, 45)),
567        new CBC_QRCoderECBlocks(26, new CBC_QRCoderECB(17, 21),
568                                new CBC_QRCoderECB(4, 22)),
569        new CBC_QRCoderECBlocks(26, new CBC_QRCoderECB(9, 13),
570                                new CBC_QRCoderECB(16, 14))));
571    VERSION->Add(new CBC_QRCoderVersion(
572        20, new CBC_QRCoderECBlocks(28, new CBC_QRCoderECB(3, 107),
573                                    new CBC_QRCoderECB(5, 108)),
574        new CBC_QRCoderECBlocks(26, new CBC_QRCoderECB(3, 41),
575                                new CBC_QRCoderECB(13, 42)),
576        new CBC_QRCoderECBlocks(30, new CBC_QRCoderECB(15, 24),
577                                new CBC_QRCoderECB(5, 25)),
578        new CBC_QRCoderECBlocks(28, new CBC_QRCoderECB(15, 15),
579                                new CBC_QRCoderECB(10, 16))));
580    VERSION->Add(new CBC_QRCoderVersion(
581        21, new CBC_QRCoderECBlocks(28, new CBC_QRCoderECB(4, 116),
582                                    new CBC_QRCoderECB(4, 117)),
583        new CBC_QRCoderECBlocks(26, new CBC_QRCoderECB(17, 42)),
584        new CBC_QRCoderECBlocks(28, new CBC_QRCoderECB(17, 22),
585                                new CBC_QRCoderECB(6, 23)),
586        new CBC_QRCoderECBlocks(30, new CBC_QRCoderECB(19, 16),
587                                new CBC_QRCoderECB(6, 17))));
588    VERSION->Add(new CBC_QRCoderVersion(
589        22, new CBC_QRCoderECBlocks(28, new CBC_QRCoderECB(2, 111),
590                                    new CBC_QRCoderECB(7, 112)),
591        new CBC_QRCoderECBlocks(28, new CBC_QRCoderECB(17, 46)),
592        new CBC_QRCoderECBlocks(30, new CBC_QRCoderECB(7, 24),
593                                new CBC_QRCoderECB(16, 25)),
594        new CBC_QRCoderECBlocks(24, new CBC_QRCoderECB(34, 13))));
595    VERSION->Add(new CBC_QRCoderVersion(
596        23, new CBC_QRCoderECBlocks(30, new CBC_QRCoderECB(4, 121),
597                                    new CBC_QRCoderECB(5, 122)),
598        new CBC_QRCoderECBlocks(28, new CBC_QRCoderECB(4, 47),
599                                new CBC_QRCoderECB(14, 48)),
600        new CBC_QRCoderECBlocks(30, new CBC_QRCoderECB(11, 24),
601                                new CBC_QRCoderECB(14, 25)),
602        new CBC_QRCoderECBlocks(30, new CBC_QRCoderECB(16, 15),
603                                new CBC_QRCoderECB(14, 16))));
604    VERSION->Add(new CBC_QRCoderVersion(
605        24, new CBC_QRCoderECBlocks(30, new CBC_QRCoderECB(6, 117),
606                                    new CBC_QRCoderECB(4, 118)),
607        new CBC_QRCoderECBlocks(28, new CBC_QRCoderECB(6, 45),
608                                new CBC_QRCoderECB(14, 46)),
609        new CBC_QRCoderECBlocks(30, new CBC_QRCoderECB(11, 24),
610                                new CBC_QRCoderECB(16, 25)),
611        new CBC_QRCoderECBlocks(30, new CBC_QRCoderECB(30, 16),
612                                new CBC_QRCoderECB(2, 17))));
613    VERSION->Add(new CBC_QRCoderVersion(
614        25, new CBC_QRCoderECBlocks(26, new CBC_QRCoderECB(8, 106),
615                                    new CBC_QRCoderECB(4, 107)),
616        new CBC_QRCoderECBlocks(28, new CBC_QRCoderECB(8, 47),
617                                new CBC_QRCoderECB(13, 48)),
618        new CBC_QRCoderECBlocks(30, new CBC_QRCoderECB(7, 24),
619                                new CBC_QRCoderECB(22, 25)),
620        new CBC_QRCoderECBlocks(30, new CBC_QRCoderECB(22, 15),
621                                new CBC_QRCoderECB(13, 16))));
622    VERSION->Add(new CBC_QRCoderVersion(
623        26, new CBC_QRCoderECBlocks(28, new CBC_QRCoderECB(10, 114),
624                                    new CBC_QRCoderECB(2, 115)),
625        new CBC_QRCoderECBlocks(28, new CBC_QRCoderECB(19, 46),
626                                new CBC_QRCoderECB(4, 47)),
627        new CBC_QRCoderECBlocks(28, new CBC_QRCoderECB(28, 22),
628                                new CBC_QRCoderECB(6, 23)),
629        new CBC_QRCoderECBlocks(30, new CBC_QRCoderECB(33, 16),
630                                new CBC_QRCoderECB(4, 17))));
631    VERSION->Add(new CBC_QRCoderVersion(
632        27, new CBC_QRCoderECBlocks(30, new CBC_QRCoderECB(8, 122),
633                                    new CBC_QRCoderECB(4, 123)),
634        new CBC_QRCoderECBlocks(28, new CBC_QRCoderECB(22, 45),
635                                new CBC_QRCoderECB(3, 46)),
636        new CBC_QRCoderECBlocks(30, new CBC_QRCoderECB(8, 23),
637                                new CBC_QRCoderECB(26, 24)),
638        new CBC_QRCoderECBlocks(30, new CBC_QRCoderECB(12, 15),
639                                new CBC_QRCoderECB(28, 16))));
640    VERSION->Add(new CBC_QRCoderVersion(
641        28, new CBC_QRCoderECBlocks(30, new CBC_QRCoderECB(3, 117),
642                                    new CBC_QRCoderECB(10, 118)),
643        new CBC_QRCoderECBlocks(28, new CBC_QRCoderECB(3, 45),
644                                new CBC_QRCoderECB(23, 46)),
645        new CBC_QRCoderECBlocks(30, new CBC_QRCoderECB(4, 24),
646                                new CBC_QRCoderECB(31, 25)),
647        new CBC_QRCoderECBlocks(30, new CBC_QRCoderECB(11, 15),
648                                new CBC_QRCoderECB(31, 16))));
649    VERSION->Add(new CBC_QRCoderVersion(
650        29, new CBC_QRCoderECBlocks(30, new CBC_QRCoderECB(7, 116),
651                                    new CBC_QRCoderECB(7, 117)),
652        new CBC_QRCoderECBlocks(28, new CBC_QRCoderECB(21, 45),
653                                new CBC_QRCoderECB(7, 46)),
654        new CBC_QRCoderECBlocks(30, new CBC_QRCoderECB(1, 23),
655                                new CBC_QRCoderECB(37, 24)),
656        new CBC_QRCoderECBlocks(30, new CBC_QRCoderECB(19, 15),
657                                new CBC_QRCoderECB(26, 16))));
658    VERSION->Add(new CBC_QRCoderVersion(
659        30, new CBC_QRCoderECBlocks(30, new CBC_QRCoderECB(5, 115),
660                                    new CBC_QRCoderECB(10, 116)),
661        new CBC_QRCoderECBlocks(28, new CBC_QRCoderECB(19, 47),
662                                new CBC_QRCoderECB(10, 48)),
663        new CBC_QRCoderECBlocks(30, new CBC_QRCoderECB(15, 24),
664                                new CBC_QRCoderECB(25, 25)),
665        new CBC_QRCoderECBlocks(30, new CBC_QRCoderECB(23, 15),
666                                new CBC_QRCoderECB(25, 16))));
667    VERSION->Add(new CBC_QRCoderVersion(
668        31, new CBC_QRCoderECBlocks(30, new CBC_QRCoderECB(13, 115),
669                                    new CBC_QRCoderECB(3, 116)),
670        new CBC_QRCoderECBlocks(28, new CBC_QRCoderECB(2, 46),
671                                new CBC_QRCoderECB(29, 47)),
672        new CBC_QRCoderECBlocks(30, new CBC_QRCoderECB(42, 24),
673                                new CBC_QRCoderECB(1, 25)),
674        new CBC_QRCoderECBlocks(30, new CBC_QRCoderECB(23, 15),
675                                new CBC_QRCoderECB(28, 16))));
676    VERSION->Add(new CBC_QRCoderVersion(
677        32, new CBC_QRCoderECBlocks(30, new CBC_QRCoderECB(17, 115)),
678        new CBC_QRCoderECBlocks(28, new CBC_QRCoderECB(10, 46),
679                                new CBC_QRCoderECB(23, 47)),
680        new CBC_QRCoderECBlocks(30, new CBC_QRCoderECB(10, 24),
681                                new CBC_QRCoderECB(35, 25)),
682        new CBC_QRCoderECBlocks(30, new CBC_QRCoderECB(19, 15),
683                                new CBC_QRCoderECB(35, 16))));
684    VERSION->Add(new CBC_QRCoderVersion(
685        33, new CBC_QRCoderECBlocks(30, new CBC_QRCoderECB(17, 115),
686                                    new CBC_QRCoderECB(1, 116)),
687        new CBC_QRCoderECBlocks(28, new CBC_QRCoderECB(14, 46),
688                                new CBC_QRCoderECB(21, 47)),
689        new CBC_QRCoderECBlocks(30, new CBC_QRCoderECB(29, 24),
690                                new CBC_QRCoderECB(19, 25)),
691        new CBC_QRCoderECBlocks(30, new CBC_QRCoderECB(11, 15),
692                                new CBC_QRCoderECB(46, 16))));
693    VERSION->Add(new CBC_QRCoderVersion(
694        34, new CBC_QRCoderECBlocks(30, new CBC_QRCoderECB(13, 115),
695                                    new CBC_QRCoderECB(6, 116)),
696        new CBC_QRCoderECBlocks(28, new CBC_QRCoderECB(14, 46),
697                                new CBC_QRCoderECB(23, 47)),
698        new CBC_QRCoderECBlocks(30, new CBC_QRCoderECB(44, 24),
699                                new CBC_QRCoderECB(7, 25)),
700        new CBC_QRCoderECBlocks(30, new CBC_QRCoderECB(59, 16),
701                                new CBC_QRCoderECB(1, 17))));
702    VERSION->Add(new CBC_QRCoderVersion(
703        35, new CBC_QRCoderECBlocks(30, new CBC_QRCoderECB(12, 121),
704                                    new CBC_QRCoderECB(7, 122)),
705        new CBC_QRCoderECBlocks(28, new CBC_QRCoderECB(12, 47),
706                                new CBC_QRCoderECB(26, 48)),
707        new CBC_QRCoderECBlocks(30, new CBC_QRCoderECB(39, 24),
708                                new CBC_QRCoderECB(14, 25)),
709        new CBC_QRCoderECBlocks(30, new CBC_QRCoderECB(22, 15),
710                                new CBC_QRCoderECB(41, 16))));
711    VERSION->Add(new CBC_QRCoderVersion(
712        36, new CBC_QRCoderECBlocks(30, new CBC_QRCoderECB(6, 121),
713                                    new CBC_QRCoderECB(14, 122)),
714        new CBC_QRCoderECBlocks(28, new CBC_QRCoderECB(6, 47),
715                                new CBC_QRCoderECB(34, 48)),
716        new CBC_QRCoderECBlocks(30, new CBC_QRCoderECB(46, 24),
717                                new CBC_QRCoderECB(10, 25)),
718        new CBC_QRCoderECBlocks(30, new CBC_QRCoderECB(2, 15),
719                                new CBC_QRCoderECB(64, 16))));
720    VERSION->Add(new CBC_QRCoderVersion(
721        37, new CBC_QRCoderECBlocks(30, new CBC_QRCoderECB(17, 122),
722                                    new CBC_QRCoderECB(4, 123)),
723        new CBC_QRCoderECBlocks(28, new CBC_QRCoderECB(29, 46),
724                                new CBC_QRCoderECB(14, 47)),
725        new CBC_QRCoderECBlocks(30, new CBC_QRCoderECB(49, 24),
726                                new CBC_QRCoderECB(10, 25)),
727        new CBC_QRCoderECBlocks(30, new CBC_QRCoderECB(24, 15),
728                                new CBC_QRCoderECB(46, 16))));
729    VERSION->Add(new CBC_QRCoderVersion(
730        38, new CBC_QRCoderECBlocks(30, new CBC_QRCoderECB(4, 122),
731                                    new CBC_QRCoderECB(18, 123)),
732        new CBC_QRCoderECBlocks(28, new CBC_QRCoderECB(13, 46),
733                                new CBC_QRCoderECB(32, 47)),
734        new CBC_QRCoderECBlocks(30, new CBC_QRCoderECB(48, 24),
735                                new CBC_QRCoderECB(14, 25)),
736        new CBC_QRCoderECBlocks(30, new CBC_QRCoderECB(42, 15),
737                                new CBC_QRCoderECB(32, 16))));
738    VERSION->Add(new CBC_QRCoderVersion(
739        39, new CBC_QRCoderECBlocks(30, new CBC_QRCoderECB(20, 117),
740                                    new CBC_QRCoderECB(4, 118)),
741        new CBC_QRCoderECBlocks(28, new CBC_QRCoderECB(40, 47),
742                                new CBC_QRCoderECB(7, 48)),
743        new CBC_QRCoderECBlocks(30, new CBC_QRCoderECB(43, 24),
744                                new CBC_QRCoderECB(22, 25)),
745        new CBC_QRCoderECBlocks(30, new CBC_QRCoderECB(10, 15),
746                                new CBC_QRCoderECB(67, 16))));
747    VERSION->Add(new CBC_QRCoderVersion(
748        40, new CBC_QRCoderECBlocks(30, new CBC_QRCoderECB(19, 118),
749                                    new CBC_QRCoderECB(6, 119)),
750        new CBC_QRCoderECBlocks(28, new CBC_QRCoderECB(18, 47),
751                                new CBC_QRCoderECB(31, 48)),
752        new CBC_QRCoderECBlocks(30, new CBC_QRCoderECB(34, 24),
753                                new CBC_QRCoderECB(34, 25)),
754        new CBC_QRCoderECBlocks(30, new CBC_QRCoderECB(20, 15),
755                                new CBC_QRCoderECB(61, 16))));
756  }
757  if (versionNumber < 1 || versionNumber > 40) {
758    e = BCExceptionIllegalArgument;
759    BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
760  }
761  return (CBC_QRCoderVersion*)(*VERSION)[versionNumber - 1];
762}
763void CBC_QRCoderVersion::Destroy() {
764  int32_t i;
765  for (i = 0; i < VERSION->GetSize(); i++) {
766    delete ((CBC_QRCoderVersion*)(*VERSION)[i]);
767  }
768}
769