OLD | NEW |
| (Empty) |
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 2006 Jeremias Maerki in part, and ZXing Authors in part | |
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 "barcode.h" | |
24 #include "include/BC_PDF417ErrorCorrection.h" | |
25 FX_INT32 CBC_PDF417ErrorCorrection::EC_COEFFICIENTS[][2500] = { | |
26 {27, 917}, | |
27 {522, 568, 723, 809}, | |
28 {237, 308, 436, 284, 646, 653, 428, 379}, | |
29 { | |
30 274, 562, 232, 755, 599, 524, 801, 132, 295, 116, 442, 428, 295, | |
31 42, 176, 65 | |
32 }, | |
33 { | |
34 361, 575, 922, 525, 176, 586, 640, 321, 536, 742, 677, 742, 687, | |
35 284, 193, 517, 273, 494, 263, 147, 593, 800, 571, 320, 803, | |
36 133, 231, 390, 685, 330, 63, 410 | |
37 }, | |
38 { | |
39 539, 422, 6, 93, 862, 771, 453, 106, 610, 287, 107, 505, 733, | |
40 877, 381, 612, 723, 476, 462, 172, 430, 609, 858, 822, 543, | |
41 376, 511, 400, 672, 762, 283, 184, 440, 35, 519, 31, 460, | |
42 594, 225, 535, 517, 352, 605, 158, 651, 201, 488, 502, 648, | |
43 733, 717, 83, 404, 97, 280, 771, 840, 629, 4, 381, 843, | |
44 623, 264, 543 | |
45 }, | |
46 { | |
47 521, 310, 864, 547, 858, 580, 296, 379, 53, 779, 897, 444, 400, | |
48 925, 749, 415, 822, 93, 217, 208, 928, 244, 583, 620, 246, | |
49 148, 447, 631, 292, 908, 490, 704, 516, 258, 457, 907, 594, | |
50 723, 674, 292, 272, 96, 684, 432, 686, 606, 860, 569, 193, | |
51 219, 129, 186, 236, 287, 192, 775, 278, 173, 40, 379, 712, | |
52 463, 646, 776, 171, 491, 297, 763, 156, 732, 95, 270, 447, | |
53 90, 507, 48, 228, 821, 808, 898, 784, 663, 627, 378, 382, | |
54 262, 380, 602, 754, 336, 89, 614, 87, 432, 670, 616, 157, | |
55 374, 242, 726, 600, 269, 375, 898, 845, 454, 354, 130, 814, | |
56 587, 804, 34, 211, 330, 539, 297, 827, 865, 37, 517, 834, | |
57 315, 550, 86, 801, 4, 108, 539 | |
58 }, | |
59 { | |
60 524, 894, 75, 766, 882, 857, 74, 204, 82, 586, 708, 250, 905, | |
61 786, 138, 720, 858, 194, 311, 913, 275, 190, 375, 850, 438, | |
62 733, 194, 280, 201, 280, 828, 757, 710, 814, 919, 89, 68, | |
63 569, 11, 204, 796, 605, 540, 913, 801, 700, 799, 137, 439, | |
64 418, 592, 668, 353, 859, 370, 694, 325, 240, 216, 257, 284, | |
65 549, 209, 884, 315, 70, 329, 793, 490, 274, 877, 162, 749, | |
66 812, 684, 461, 334, 376, 849, 521, 307, 291, 803, 712, 19, | |
67 358, 399, 908, 103, 511, 51, 8, 517, 225, 289, 470, 637, | |
68 731, 66, 255, 917, 269, 463, 830, 730, 433, 848, 585, 136, | |
69 538, 906, 90, 2, 290, 743, 199, 655, 903, 329, 49, 802, | |
70 580, 355, 588, 188, 462, 10, 134, 628, 320, 479, 130, 739, | |
71 71, 263, 318, 374, 601, 192, 605, 142, 673, 687, 234, 722, | |
72 384, 177, 752, 607, 640, 455, 193, 689, 707, 805, 641, 48, | |
73 60, 732, 621, 895, 544, 261, 852, 655, 309, 697, 755, 756, | |
74 60, 231, 773, 434, 421, 726, 528, 503, 118, 49, 795, 32, | |
75 144, 500, 238, 836, 394, 280, 566, 319, 9, 647, 550, 73, | |
76 914, 342, 126, 32, 681, 331, 792, 620, 60, 609, 441, 180, | |
77 791, 893, 754, 605, 383, 228, 749, 760, 213, 54, 297, 134, | |
78 54, 834, 299, 922, 191, 910, 532, 609, 829, 189, 20, 167, | |
79 29, 872, 449, 83, 402, 41, 656, 505, 579, 481, 173, 404, | |
80 251, 688, 95, 497, 555, 642, 543, 307, 159, 924, 558, 648, | |
81 55, 497, 10 | |
82 }, | |
83 { | |
84 352, 77, 373, 504, 35, 599, 428, 207, 409, 574, 118, 498, 285, | |
85 380, 350, 492, 197, 265, 920, 155, 914, 299, 229, 643, 294, | |
86 871, 306, 88, 87, 193, 352, 781, 846, 75, 327, 520, 435, | |
87 543, 203, 666, 249, 346, 781, 621, 640, 268, 794, 534, 539, | |
88 781, 408, 390, 644, 102, 476, 499, 290, 632, 545, 37, 858, | |
89 916, 552, 41, 542, 289, 122, 272, 383, 800, 485, 98, 752, | |
90 472, 761, 107, 784, 860, 658, 741, 290, 204, 681, 407, 855, | |
91 85, 99, 62, 482, 180, 20, 297, 451, 593, 913, 142, 808, | |
92 684, 287, 536, 561, 76, 653, 899, 729, 567, 744, 390, 513, | |
93 192, 516, 258, 240, 518, 794, 395, 768, 848, 51, 610, 384, | |
94 168, 190, 826, 328, 596, 786, 303, 570, 381, 415, 641, 156, | |
95 237, 151, 429, 531, 207, 676, 710, 89, 168, 304, 402, 40, | |
96 708, 575, 162, 864, 229, 65, 861, 841, 512, 164, 477, 221, | |
97 92, 358, 785, 288, 357, 850, 836, 827, 736, 707, 94, 8, | |
98 494, 114, 521, 2, 499, 851, 543, 152, 729, 771, 95, 248, | |
99 361, 578, 323, 856, 797, 289, 51, 684, 466, 533, 820, 669, | |
100 45, 902, 452, 167, 342, 244, 173, 35, 463, 651, 51, 699, | |
101 591, 452, 578, 37, 124, 298, 332, 552, 43, 427, 119, 662, | |
102 777, 475, 850, 764, 364, 578, 911, 283, 711, 472, 420, 245, | |
103 288, 594, 394, 511, 327, 589, 777, 699, 688, 43, 408, 842, | |
104 383, 721, 521, 560, 644, 714, 559, 62, 145, 873, 663, 713, | |
105 159, 672, 729, 624, 59, 193, 417, 158, 209, 563, 564, 343, | |
106 693, 109, 608, 563, 365, 181, 772, 677, 310, 248, 353, 708, | |
107 410, 579, 870, 617, 841, 632, 860, 289, 536, 35, 777, 618, | |
108 586, 424, 833, 77, 597, 346, 269, 757, 632, 695, 751, 331, | |
109 247, 184, 45, 787, 680, 18, 66, 407, 369, 54, 492, 228, | |
110 613, 830, 922, 437, 519, 644, 905, 789, 420, 305, 441, 207, | |
111 300, 892, 827, 141, 537, 381, 662, 513, 56, 252, 341, 242, | |
112 797, 838, 837, 720, 224, 307, 631, 61, 87, 560, 310, 756, | |
113 665, 397, 808, 851, 309, 473, 795, 378, 31, 647, 915, 459, | |
114 806, 590, 731, 425, 216, 548, 249, 321, 881, 699, 535, 673, | |
115 782, 210, 815, 905, 303, 843, 922, 281, 73, 469, 791, 660, | |
116 162, 498, 308, 155, 422, 907, 817, 187, 62, 16, 425, 535, | |
117 336, 286, 437, 375, 273, 610, 296, 183, 923, 116, 667, 751, | |
118 353, 62, 366, 691, 379, 687, 842, 37, 357, 720, 742, 330, | |
119 5, 39, 923, 311, 424, 242, 749, 321, 54, 669, 316, 342, | |
120 299, 534, 105, 667, 488, 640, 672, 576, 540, 316, 486, 721, | |
121 610, 46, 656, 447, 171, 616, 464, 190, 531, 297, 321, 762, | |
122 752, 533, 175, 134, 14, 381, 433, 717, 45, 111, 20, 596, | |
123 284, 736, 138, 646, 411, 877, 669, 141, 919, 45, 780, 407, | |
124 164, 332, 899, 165, 726, 600, 325, 498, 655, 357, 752, 768, | |
125 223, 849, 647, 63, 310, 863, 251, 366, 304, 282, 738, 675, | |
126 410, 389, 244, 31, 121, 303, 263 | |
127 } | |
128 }; | |
129 CBC_PDF417ErrorCorrection::CBC_PDF417ErrorCorrection() | |
130 { | |
131 } | |
132 CBC_PDF417ErrorCorrection::~CBC_PDF417ErrorCorrection() | |
133 { | |
134 } | |
135 FX_INT32 CBC_PDF417ErrorCorrection::getErrorCorrectionCodewordCount(FX_INT32 err
orCorrectionLevel, FX_INT32 &e) | |
136 { | |
137 if (errorCorrectionLevel < 0 || errorCorrectionLevel > 8) { | |
138 e = BCExceptionErrorCorrectionLevelMustBeBetween0And8; | |
139 return -1; | |
140 } | |
141 return 1 << (errorCorrectionLevel + 1); | |
142 } | |
143 FX_INT32 CBC_PDF417ErrorCorrection::getRecommendedMinimumErrorCorrectionLevel(FX
_INT32 n, FX_INT32 &e) | |
144 { | |
145 if (n <= 0) { | |
146 e = BCExceptionIllegalArgumentnMustBeAbove0; | |
147 return -1; | |
148 } | |
149 if (n <= 40) { | |
150 return 2; | |
151 } | |
152 if (n <= 160) { | |
153 return 3; | |
154 } | |
155 if (n <= 320) { | |
156 return 4; | |
157 } | |
158 if (n <= 863) { | |
159 return 5; | |
160 } | |
161 e = BCExceptionNoRecommendationPossible; | |
162 return -1; | |
163 } | |
164 CFX_WideString CBC_PDF417ErrorCorrection::generateErrorCorrection(CFX_WideString
dataCodewords, FX_INT32 errorCorrectionLevel, FX_INT32 &e) | |
165 { | |
166 FX_INT32 k = getErrorCorrectionCodewordCount(errorCorrectionLevel, e); | |
167 BC_EXCEPTION_CHECK_ReturnValue(e, (FX_WCHAR)' '); | |
168 FX_WCHAR* ech = FX_Alloc(FX_WCHAR, k * sizeof(FX_WCHAR)); | |
169 FXSYS_memset32(ech, 0, k * sizeof(FX_WCHAR)); | |
170 FX_INT32 sld = dataCodewords.GetLength(); | |
171 for (FX_INT32 i = 0; i < sld; i++) { | |
172 FX_INT32 t1 = (dataCodewords.GetAt(i) + ech[k - 1]) % 929; | |
173 FX_INT32 t2; | |
174 FX_INT32 t3; | |
175 for (FX_INT32 j = k - 1; j >= 1; j--) { | |
176 t2 = (t1 * EC_COEFFICIENTS[errorCorrectionLevel][j]) % 929; | |
177 t3 = 929 - t2; | |
178 ech[j] = (FX_WCHAR) ((ech[j - 1] + t3) % 929); | |
179 } | |
180 t2 = (t1 * EC_COEFFICIENTS[errorCorrectionLevel][0]) % 929; | |
181 t3 = 929 - t2; | |
182 ech[0] = (FX_WCHAR) (t3 % 929); | |
183 } | |
184 CFX_WideString sb; | |
185 for (FX_INT32 j = k - 1; j >= 0; j--) { | |
186 if (ech[j] != 0) { | |
187 ech[j] = (FX_WCHAR) (929 - ech[j]); | |
188 } | |
189 sb += (FX_WCHAR)ech[j]; | |
190 } | |
191 FX_Free (ech); | |
192 return sb; | |
193 } | |
OLD | NEW |