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

Side by Side Diff: xfa/src/fxbarcode/datamatrix/BC_ErrorCorrection.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. 8 * Copyright 2006 Jeremias Maerki.
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_Encoder.h" 24 #include "BC_Encoder.h"
25 #include "BC_SymbolShapeHint.h" 25 #include "BC_SymbolShapeHint.h"
26 #include "BC_SymbolInfo.h" 26 #include "BC_SymbolInfo.h"
27 #include "BC_ErrorCorrection.h" 27 #include "BC_ErrorCorrection.h"
28 FX_INT32 CBC_ErrorCorrection::FACTOR_SETS[] = {5, 7, 10, 11, 12, 14, 18, 20, 24, 28, 36, 42, 48, 56, 62, 68}; 28 int32_t CBC_ErrorCorrection::FACTOR_SETS[] = {5, 7, 10, 11, 12, 14, 18, 20, 24, 28, 36, 42, 48, 56, 62, 68};
29 FX_INT32 CBC_ErrorCorrection::FACTORS[][100] = { 29 int32_t CBC_ErrorCorrection::FACTORS[][100] = {
30 {228, 48, 15, 111, 62}, 30 {228, 48, 15, 111, 62},
31 {23, 68, 144, 134, 240, 92, 254}, 31 {23, 68, 144, 134, 240, 92, 254},
32 {28, 24, 185, 166, 223, 248, 116, 255, 110, 61}, 32 {28, 24, 185, 166, 223, 248, 116, 255, 110, 61},
33 {175, 138, 205, 12, 194, 168, 39, 245, 60, 97, 120}, 33 {175, 138, 205, 12, 194, 168, 39, 245, 60, 97, 120},
34 {41, 153, 158, 91, 61, 42, 142, 213, 97, 178, 100, 242}, 34 {41, 153, 158, 91, 61, 42, 142, 213, 97, 178, 100, 242},
35 {156, 97, 192, 252, 95, 9, 157, 119, 138, 45, 18, 186, 83, 185}, 35 {156, 97, 192, 252, 95, 9, 157, 119, 138, 45, 18, 186, 83, 185},
36 {83, 195, 100, 39, 188, 75, 66, 61, 241, 213, 109, 129, 94, 254, 225, 48, 90 , 188}, 36 {83, 195, 100, 39, 188, 75, 66, 61, 241, 213, 109, 129, 94, 254, 225, 48, 90 , 188},
37 {15, 195, 244, 9, 233, 71, 168, 2, 188, 160, 153, 145, 253, 79, 108, 82, 27, 174, 186, 172}, 37 {15, 195, 244, 9, 233, 71, 168, 2, 188, 160, 153, 145, 253, 79, 108, 82, 27, 174, 186, 172},
38 { 38 {
39 52, 190, 88, 205, 109, 39, 176, 21, 155, 197, 251, 223, 155, 21, 5, 172, 39 52, 190, 88, 205, 109, 39, 176, 21, 155, 197, 251, 223, 155, 21, 5, 172,
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
71 176, 170, 4, 107, 232, 7, 94, 166, 224, 124, 86, 47, 11, 204 71 176, 170, 4, 107, 232, 7, 94, 166, 224, 124, 86, 47, 11, 204
72 }, 72 },
73 { 73 {
74 220, 228, 173, 89, 251, 149, 159, 56, 89, 33, 147, 244, 154, 36, 73, 127 , 74 220, 228, 173, 89, 251, 149, 159, 56, 89, 33, 147, 244, 154, 36, 73, 127 ,
75 213, 136, 248, 180, 234, 197, 158, 177, 68, 122, 93, 213, 15, 160, 227, 236, 75 213, 136, 248, 180, 234, 197, 158, 177, 68, 122, 93, 213, 15, 160, 227, 236,
76 66, 139, 153, 185, 202, 167, 179, 25, 220, 232, 96, 210, 231, 136, 223, 239, 76 66, 139, 153, 185, 202, 167, 179, 25, 220, 232, 96, 210, 231, 136, 223, 239,
77 181, 241, 59, 52, 172, 25, 49, 232, 211, 189, 64, 54, 108, 153, 132, 63, 77 181, 241, 59, 52, 172, 25, 49, 232, 211, 189, 64, 54, 108, 153, 132, 63,
78 96, 103, 82, 186 78 96, 103, 82, 186
79 } 79 }
80 }; 80 };
81 FX_INT32 CBC_ErrorCorrection::MODULO_VALUE = 0x12D; 81 int32_t CBC_ErrorCorrection::MODULO_VALUE = 0x12D;
82 FX_INT32 CBC_ErrorCorrection::LOG[256] = {0}; 82 int32_t CBC_ErrorCorrection::LOG[256] = {0};
83 FX_INT32 CBC_ErrorCorrection::ALOG[256] = {0}; 83 int32_t CBC_ErrorCorrection::ALOG[256] = {0};
84 void CBC_ErrorCorrection::Initialize() 84 void CBC_ErrorCorrection::Initialize()
85 { 85 {
86 FX_INT32 p = 1; 86 int32_t p = 1;
87 for (FX_INT32 i = 0; i < 255; i++) { 87 for (int32_t i = 0; i < 255; i++) {
88 ALOG[i] = p; 88 ALOG[i] = p;
89 LOG[p] = i; 89 LOG[p] = i;
90 p <<= 1; 90 p <<= 1;
91 if (p >= 256) { 91 if (p >= 256) {
92 p ^= MODULO_VALUE; 92 p ^= MODULO_VALUE;
93 } 93 }
94 } 94 }
95 } 95 }
96 void CBC_ErrorCorrection::Finalize() 96 void CBC_ErrorCorrection::Finalize()
97 { 97 {
98 } 98 }
99 CBC_ErrorCorrection::CBC_ErrorCorrection() 99 CBC_ErrorCorrection::CBC_ErrorCorrection()
100 { 100 {
101 } 101 }
102 CBC_ErrorCorrection::~CBC_ErrorCorrection() 102 CBC_ErrorCorrection::~CBC_ErrorCorrection()
103 { 103 {
104 } 104 }
105 CFX_WideString CBC_ErrorCorrection::encodeECC200(CFX_WideString codewords, CBC_S ymbolInfo* symbolInfo, FX_INT32 &e) 105 CFX_WideString CBC_ErrorCorrection::encodeECC200(CFX_WideString codewords, CBC_S ymbolInfo* symbolInfo, int32_t &e)
106 { 106 {
107 if (codewords.GetLength() != symbolInfo->m_dataCapacity) { 107 if (codewords.GetLength() != symbolInfo->m_dataCapacity) {
108 e = BCExceptionIllegalArgument; 108 e = BCExceptionIllegalArgument;
109 return (FX_LPWSTR)""; 109 return (FX_LPWSTR)"";
110 } 110 }
111 CFX_WideString sb; 111 CFX_WideString sb;
112 sb += codewords; 112 sb += codewords;
113 FX_INT32 blockCount = symbolInfo->getInterleavedBlockCount(); 113 int32_t blockCount = symbolInfo->getInterleavedBlockCount();
114 if (blockCount == 1) { 114 if (blockCount == 1) {
115 CFX_WideString ecc = createECCBlock(codewords, symbolInfo->m_errorCodewo rds, e); 115 CFX_WideString ecc = createECCBlock(codewords, symbolInfo->m_errorCodewo rds, e);
116 BC_EXCEPTION_CHECK_ReturnValue(e, (FX_LPWSTR)""); 116 BC_EXCEPTION_CHECK_ReturnValue(e, (FX_LPWSTR)"");
117 sb += ecc; 117 sb += ecc;
118 } else { 118 } else {
119 CFX_Int32Array dataSizes; 119 CFX_Int32Array dataSizes;
120 dataSizes.SetSize(blockCount); 120 dataSizes.SetSize(blockCount);
121 CFX_Int32Array errorSizes; 121 CFX_Int32Array errorSizes;
122 errorSizes.SetSize(blockCount); 122 errorSizes.SetSize(blockCount);
123 CFX_Int32Array startPos; 123 CFX_Int32Array startPos;
124 startPos.SetSize(blockCount); 124 startPos.SetSize(blockCount);
125 for (FX_INT32 i = 0; i < blockCount; i++) { 125 for (int32_t i = 0; i < blockCount; i++) {
126 dataSizes[i] = symbolInfo->getDataLengthForInterleavedBlock(i + 1); 126 dataSizes[i] = symbolInfo->getDataLengthForInterleavedBlock(i + 1);
127 errorSizes[i] = symbolInfo->getErrorLengthForInterleavedBlock(i + 1) ; 127 errorSizes[i] = symbolInfo->getErrorLengthForInterleavedBlock(i + 1) ;
128 startPos[i] = 0; 128 startPos[i] = 0;
129 if (i > 0) { 129 if (i > 0) {
130 startPos[i] = startPos[i - 1] + dataSizes[i]; 130 startPos[i] = startPos[i - 1] + dataSizes[i];
131 } 131 }
132 } 132 }
133 for (FX_INT32 block = 0; block < blockCount; block++) { 133 for (int32_t block = 0; block < blockCount; block++) {
134 CFX_WideString temp; 134 CFX_WideString temp;
135 for (FX_INT32 d = block; d < symbolInfo->m_dataCapacity; d += blockC ount) { 135 for (int32_t d = block; d < symbolInfo->m_dataCapacity; d += blockCo unt) {
136 temp += (FX_WCHAR)codewords.GetAt(d); 136 temp += (FX_WCHAR)codewords.GetAt(d);
137 } 137 }
138 CFX_WideString ecc = createECCBlock(temp, errorSizes[block], e); 138 CFX_WideString ecc = createECCBlock(temp, errorSizes[block], e);
139 BC_EXCEPTION_CHECK_ReturnValue(e, (FX_LPWSTR)""); 139 BC_EXCEPTION_CHECK_ReturnValue(e, (FX_LPWSTR)"");
140 FX_INT32 pos = 0; 140 int32_t pos = 0;
141 for (FX_INT32 l = block; l < errorSizes[block] * blockCount; l += bl ockCount) { 141 for (int32_t l = block; l < errorSizes[block] * blockCount; l += blo ckCount) {
142 sb.SetAt(symbolInfo->m_dataCapacity + l, ecc.GetAt(pos++)); 142 sb.SetAt(symbolInfo->m_dataCapacity + l, ecc.GetAt(pos++));
143 } 143 }
144 } 144 }
145 } 145 }
146 return sb; 146 return sb;
147 } 147 }
148 CFX_WideString CBC_ErrorCorrection::createECCBlock(CFX_WideString codewords, FX_ INT32 numECWords, FX_INT32 &e) 148 CFX_WideString CBC_ErrorCorrection::createECCBlock(CFX_WideString codewords, int 32_t numECWords, int32_t &e)
149 { 149 {
150 return createECCBlock(codewords, 0, codewords.GetLength(), numECWords, e); 150 return createECCBlock(codewords, 0, codewords.GetLength(), numECWords, e);
151 } 151 }
152 CFX_WideString CBC_ErrorCorrection::createECCBlock(CFX_WideString codewords, FX_ INT32 start, FX_INT32 len, FX_INT32 numECWords, FX_INT32 &e) 152 CFX_WideString CBC_ErrorCorrection::createECCBlock(CFX_WideString codewords, int 32_t start, int32_t len, int32_t numECWords, int32_t &e)
153 { 153 {
154 FX_INT32 table = -1; 154 int32_t table = -1;
155 for (FX_INT32 i = 0; i < sizeof(FACTOR_SETS) / sizeof(FX_INT32); i++) { 155 for (int32_t i = 0; i < sizeof(FACTOR_SETS) / sizeof(int32_t); i++) {
156 if (FACTOR_SETS[i] == numECWords) { 156 if (FACTOR_SETS[i] == numECWords) {
157 table = i; 157 table = i;
158 break; 158 break;
159 } 159 }
160 } 160 }
161 if (table < 0) { 161 if (table < 0) {
162 e = BCExceptionIllegalArgument; 162 e = BCExceptionIllegalArgument;
163 return (FX_LPWSTR)""; 163 return (FX_LPWSTR)"";
164 } 164 }
165 FX_WORD* ecc = FX_Alloc(FX_WORD, numECWords); 165 FX_WORD* ecc = FX_Alloc(FX_WORD, numECWords);
166 FXSYS_memset32(ecc, 0, numECWords * sizeof(FX_WORD)); 166 FXSYS_memset32(ecc, 0, numECWords * sizeof(FX_WORD));
167 for (FX_INT32 l = start; l < start + len; l++) { 167 for (int32_t l = start; l < start + len; l++) {
168 FX_BYTE A = (FX_BYTE)codewords.GetAt(l); 168 uint8_t A = (uint8_t)codewords.GetAt(l);
169 FX_WORD B = ecc[numECWords - 1]; 169 FX_WORD B = ecc[numECWords - 1];
170 FX_WORD m = ecc[numECWords - 1] ^ codewords.GetAt(l); 170 FX_WORD m = ecc[numECWords - 1] ^ codewords.GetAt(l);
171 for (FX_INT32 k = numECWords - 1; k > 0; k--) { 171 for (int32_t k = numECWords - 1; k > 0; k--) {
172 if (m != 0 && FACTORS[table][k] != 0) { 172 if (m != 0 && FACTORS[table][k] != 0) {
173 FX_INT32 a = LOG[FACTORS[table][k]]; 173 int32_t a = LOG[FACTORS[table][k]];
174 FX_INT32 b = ALOG[(LOG[m] + LOG[FACTORS[table][k]]) % 255]; 174 int32_t b = ALOG[(LOG[m] + LOG[FACTORS[table][k]]) % 255];
175 FX_WORD c = ecc[k - 1]; 175 FX_WORD c = ecc[k - 1];
176 FX_WORD D = (ecc[k - 1] ^ ALOG[(LOG[m] + LOG[FACTORS[table][k]]) % 255]); 176 FX_WORD D = (ecc[k - 1] ^ ALOG[(LOG[m] + LOG[FACTORS[table][k]]) % 255]);
177 ecc[k] = (FX_WORD ) (ecc[k - 1] ^ ALOG[(LOG[m] + LOG[FACTORS[tab le][k]]) % 255]); 177 ecc[k] = (FX_WORD ) (ecc[k - 1] ^ ALOG[(LOG[m] + LOG[FACTORS[tab le][k]]) % 255]);
178 } else { 178 } else {
179 ecc[k] = ecc[k - 1]; 179 ecc[k] = ecc[k - 1];
180 } 180 }
181 } 181 }
182 if (m != 0 && FACTORS[table][0] != 0) { 182 if (m != 0 && FACTORS[table][0] != 0) {
183 ecc[0] = (FX_WORD) ALOG[(LOG[m] + LOG[FACTORS[table][0]]) % 255]; 183 ecc[0] = (FX_WORD) ALOG[(LOG[m] + LOG[FACTORS[table][0]]) % 255];
184 } else { 184 } else {
185 ecc[0] = 0; 185 ecc[0] = 0;
186 } 186 }
187 } 187 }
188 CFX_WideString strecc; 188 CFX_WideString strecc;
189 for (FX_INT32 j = 0; j < numECWords; j++) { 189 for (int32_t j = 0; j < numECWords; j++) {
190 strecc += (FX_WCHAR)ecc[numECWords - j - 1]; 190 strecc += (FX_WCHAR)ecc[numECWords - j - 1];
191 } 191 }
192 FX_Free(ecc); 192 FX_Free(ecc);
193 return strecc; 193 return strecc;
194 } 194 }
OLDNEW
« no previous file with comments | « xfa/src/fxbarcode/datamatrix/BC_ErrorCorrection.h ('k') | xfa/src/fxbarcode/datamatrix/BC_HighLevelEncoder.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698