Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(165)

Side by Side Diff: xfa/src/fxbarcode/pdf417/BC_PDF417ErrorCorrection.cpp

Issue 1172793002: Merge to XFA: Use stdint.h types throughout PDFium. (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@xfa
Patch Set: Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2014 PDFium Authors. All rights reserved. 1 // Copyright 2014 PDFium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6 // Original code is licensed as follows: 6 // Original code is licensed as follows:
7 /* 7 /*
8 * Copyright 2006 Jeremias Maerki in part, and ZXing Authors in part 8 * Copyright 2006 Jeremias Maerki in part, and ZXing Authors in part
9 * 9 *
10 * Licensed under the Apache License, Version 2.0 (the "License"); 10 * Licensed under the Apache License, Version 2.0 (the "License");
11 * you may not use this file except in compliance with 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 12 * You may obtain a copy of the License at
13 * 13 *
14 * http://www.apache.org/licenses/LICENSE-2.0 14 * http://www.apache.org/licenses/LICENSE-2.0
15 * 15 *
16 * Unless required by applicable law or agreed to in writing, software 16 * Unless required by applicable law or agreed to in writing, software
17 * distributed under the License is distributed on an "AS IS" BASIS, 17 * distributed under the License is distributed on an "AS IS" BASIS,
18 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 18 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19 * See the License for the specific language governing permissions and 19 * See the License for the specific language governing permissions and
20 * limitations under the License. 20 * limitations under the License.
21 */ 21 */
22 22
23 #include "../barcode.h" 23 #include "../barcode.h"
24 #include "BC_PDF417ErrorCorrection.h" 24 #include "BC_PDF417ErrorCorrection.h"
25 FX_INT32 CBC_PDF417ErrorCorrection::EC_COEFFICIENTS[][2500] = { 25 int32_t CBC_PDF417ErrorCorrection::EC_COEFFICIENTS[][2500] = {
26 {27, 917}, 26 {27, 917},
27 {522, 568, 723, 809}, 27 {522, 568, 723, 809},
28 {237, 308, 436, 284, 646, 653, 428, 379}, 28 {237, 308, 436, 284, 646, 653, 428, 379},
29 { 29 {
30 274, 562, 232, 755, 599, 524, 801, 132, 295, 116, 442, 428, 295, 30 274, 562, 232, 755, 599, 524, 801, 132, 295, 116, 442, 428, 295,
31 42, 176, 65 31 42, 176, 65
32 }, 32 },
33 { 33 {
34 361, 575, 922, 525, 176, 586, 640, 321, 536, 742, 677, 742, 687, 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, 35 284, 193, 517, 273, 494, 263, 147, 593, 800, 571, 320, 803,
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
125 223, 849, 647, 63, 310, 863, 251, 366, 304, 282, 738, 675, 125 223, 849, 647, 63, 310, 863, 251, 366, 304, 282, 738, 675,
126 410, 389, 244, 31, 121, 303, 263 126 410, 389, 244, 31, 121, 303, 263
127 } 127 }
128 }; 128 };
129 CBC_PDF417ErrorCorrection::CBC_PDF417ErrorCorrection() 129 CBC_PDF417ErrorCorrection::CBC_PDF417ErrorCorrection()
130 { 130 {
131 } 131 }
132 CBC_PDF417ErrorCorrection::~CBC_PDF417ErrorCorrection() 132 CBC_PDF417ErrorCorrection::~CBC_PDF417ErrorCorrection()
133 { 133 {
134 } 134 }
135 FX_INT32 CBC_PDF417ErrorCorrection::getErrorCorrectionCodewordCount(FX_INT32 err orCorrectionLevel, FX_INT32 &e) 135 int32_t CBC_PDF417ErrorCorrection::getErrorCorrectionCodewordCount(int32_t error CorrectionLevel, int32_t &e)
136 { 136 {
137 if (errorCorrectionLevel < 0 || errorCorrectionLevel > 8) { 137 if (errorCorrectionLevel < 0 || errorCorrectionLevel > 8) {
138 e = BCExceptionErrorCorrectionLevelMustBeBetween0And8; 138 e = BCExceptionErrorCorrectionLevelMustBeBetween0And8;
139 return -1; 139 return -1;
140 } 140 }
141 return 1 << (errorCorrectionLevel + 1); 141 return 1 << (errorCorrectionLevel + 1);
142 } 142 }
143 FX_INT32 CBC_PDF417ErrorCorrection::getRecommendedMinimumErrorCorrectionLevel(FX _INT32 n, FX_INT32 &e) 143 int32_t CBC_PDF417ErrorCorrection::getRecommendedMinimumErrorCorrectionLevel(int 32_t n, int32_t &e)
144 { 144 {
145 if (n <= 0) { 145 if (n <= 0) {
146 e = BCExceptionIllegalArgumentnMustBeAbove0; 146 e = BCExceptionIllegalArgumentnMustBeAbove0;
147 return -1; 147 return -1;
148 } 148 }
149 if (n <= 40) { 149 if (n <= 40) {
150 return 2; 150 return 2;
151 } 151 }
152 if (n <= 160) { 152 if (n <= 160) {
153 return 3; 153 return 3;
154 } 154 }
155 if (n <= 320) { 155 if (n <= 320) {
156 return 4; 156 return 4;
157 } 157 }
158 if (n <= 863) { 158 if (n <= 863) {
159 return 5; 159 return 5;
160 } 160 }
161 e = BCExceptionNoRecommendationPossible; 161 e = BCExceptionNoRecommendationPossible;
162 return -1; 162 return -1;
163 } 163 }
164 CFX_WideString CBC_PDF417ErrorCorrection::generateErrorCorrection(CFX_WideString dataCodewords, FX_INT32 errorCorrectionLevel, FX_INT32 &e) 164 CFX_WideString CBC_PDF417ErrorCorrection::generateErrorCorrection(CFX_WideString dataCodewords, int32_t errorCorrectionLevel, int32_t &e)
165 { 165 {
166 FX_INT32 k = getErrorCorrectionCodewordCount(errorCorrectionLevel, e); 166 int32_t k = getErrorCorrectionCodewordCount(errorCorrectionLevel, e);
167 BC_EXCEPTION_CHECK_ReturnValue(e, (FX_WCHAR)' '); 167 BC_EXCEPTION_CHECK_ReturnValue(e, (FX_WCHAR)' ');
168 FX_WCHAR* ech = FX_Alloc(FX_WCHAR, k * sizeof(FX_WCHAR)); 168 FX_WCHAR* ech = FX_Alloc(FX_WCHAR, k * sizeof(FX_WCHAR));
169 FXSYS_memset32(ech, 0, k * sizeof(FX_WCHAR)); 169 FXSYS_memset32(ech, 0, k * sizeof(FX_WCHAR));
170 FX_INT32 sld = dataCodewords.GetLength(); 170 int32_t sld = dataCodewords.GetLength();
171 for (FX_INT32 i = 0; i < sld; i++) { 171 for (int32_t i = 0; i < sld; i++) {
172 FX_INT32 t1 = (dataCodewords.GetAt(i) + ech[k - 1]) % 929; 172 int32_t t1 = (dataCodewords.GetAt(i) + ech[k - 1]) % 929;
173 FX_INT32 t2; 173 int32_t t2;
174 FX_INT32 t3; 174 int32_t t3;
175 for (FX_INT32 j = k - 1; j >= 1; j--) { 175 for (int32_t j = k - 1; j >= 1; j--) {
176 t2 = (t1 * EC_COEFFICIENTS[errorCorrectionLevel][j]) % 929; 176 t2 = (t1 * EC_COEFFICIENTS[errorCorrectionLevel][j]) % 929;
177 t3 = 929 - t2; 177 t3 = 929 - t2;
178 ech[j] = (FX_WCHAR) ((ech[j - 1] + t3) % 929); 178 ech[j] = (FX_WCHAR) ((ech[j - 1] + t3) % 929);
179 } 179 }
180 t2 = (t1 * EC_COEFFICIENTS[errorCorrectionLevel][0]) % 929; 180 t2 = (t1 * EC_COEFFICIENTS[errorCorrectionLevel][0]) % 929;
181 t3 = 929 - t2; 181 t3 = 929 - t2;
182 ech[0] = (FX_WCHAR) (t3 % 929); 182 ech[0] = (FX_WCHAR) (t3 % 929);
183 } 183 }
184 CFX_WideString sb; 184 CFX_WideString sb;
185 for (FX_INT32 j = k - 1; j >= 0; j--) { 185 for (int32_t j = k - 1; j >= 0; j--) {
186 if (ech[j] != 0) { 186 if (ech[j] != 0) {
187 ech[j] = (FX_WCHAR) (929 - ech[j]); 187 ech[j] = (FX_WCHAR) (929 - ech[j]);
188 } 188 }
189 sb += (FX_WCHAR)ech[j]; 189 sb += (FX_WCHAR)ech[j];
190 } 190 }
191 FX_Free (ech); 191 FX_Free (ech);
192 return sb; 192 return sb;
193 } 193 }
OLDNEW
« no previous file with comments | « xfa/src/fxbarcode/pdf417/BC_PDF417ErrorCorrection.h ('k') | xfa/src/fxbarcode/pdf417/BC_PDF417HighLevelEncoder.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698