OLD | NEW |
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"); |
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
165 CFX_WideString CBC_ErrorCorrection::createECCBlock(CFX_WideString codewords, | 165 CFX_WideString CBC_ErrorCorrection::createECCBlock(CFX_WideString codewords, |
166 int32_t numECWords, | 166 int32_t numECWords, |
167 int32_t& e) { | 167 int32_t& e) { |
168 return createECCBlock(codewords, 0, codewords.GetLength(), numECWords, e); | 168 return createECCBlock(codewords, 0, codewords.GetLength(), numECWords, e); |
169 } | 169 } |
170 CFX_WideString CBC_ErrorCorrection::createECCBlock(CFX_WideString codewords, | 170 CFX_WideString CBC_ErrorCorrection::createECCBlock(CFX_WideString codewords, |
171 int32_t start, | 171 int32_t start, |
172 int32_t len, | 172 int32_t len, |
173 int32_t numECWords, | 173 int32_t numECWords, |
174 int32_t& e) { | 174 int32_t& e) { |
175 int32_t table = -1; | 175 static const size_t kFactorTableNum = sizeof(FACTOR_SETS) / sizeof(int32_t); |
176 for (int32_t i = 0; i < sizeof(FACTOR_SETS) / sizeof(int32_t); i++) { | 176 size_t table = 0; |
177 if (FACTOR_SETS[i] == numECWords) { | 177 while (table < kFactorTableNum && FACTOR_SETS[table] != numECWords) |
178 table = i; | 178 table++; |
179 break; | 179 |
180 } | 180 if (table >= kFactorTableNum) { |
181 } | |
182 if (table < 0) { | |
183 e = BCExceptionIllegalArgument; | 181 e = BCExceptionIllegalArgument; |
184 return (FX_WCHAR*)""; | 182 return (FX_WCHAR*)""; |
185 } | 183 } |
186 uint16_t* ecc = FX_Alloc(uint16_t, numECWords); | 184 uint16_t* ecc = FX_Alloc(uint16_t, numECWords); |
187 FXSYS_memset(ecc, 0, numECWords * sizeof(uint16_t)); | 185 FXSYS_memset(ecc, 0, numECWords * sizeof(uint16_t)); |
188 for (int32_t l = start; l < start + len; l++) { | 186 for (int32_t l = start; l < start + len; l++) { |
189 uint16_t m = ecc[numECWords - 1] ^ codewords.GetAt(l); | 187 uint16_t m = ecc[numECWords - 1] ^ codewords.GetAt(l); |
190 for (int32_t k = numECWords - 1; k > 0; k--) { | 188 for (int32_t k = numECWords - 1; k > 0; k--) { |
191 if (m != 0 && FACTORS[table][k] != 0) { | 189 if (m != 0 && FACTORS[table][k] != 0) { |
192 ecc[k] = (uint16_t)(ecc[k - 1] ^ | 190 ecc[k] = (uint16_t)(ecc[k - 1] ^ |
193 ALOG[(LOG[m] + LOG[FACTORS[table][k]]) % 255]); | 191 ALOG[(LOG[m] + LOG[FACTORS[table][k]]) % 255]); |
194 } else { | 192 } else { |
195 ecc[k] = ecc[k - 1]; | 193 ecc[k] = ecc[k - 1]; |
196 } | 194 } |
197 } | 195 } |
198 if (m != 0 && FACTORS[table][0] != 0) { | 196 if (m != 0 && FACTORS[table][0] != 0) { |
199 ecc[0] = (uint16_t)ALOG[(LOG[m] + LOG[FACTORS[table][0]]) % 255]; | 197 ecc[0] = (uint16_t)ALOG[(LOG[m] + LOG[FACTORS[table][0]]) % 255]; |
200 } else { | 198 } else { |
201 ecc[0] = 0; | 199 ecc[0] = 0; |
202 } | 200 } |
203 } | 201 } |
204 CFX_WideString strecc; | 202 CFX_WideString strecc; |
205 for (int32_t j = 0; j < numECWords; j++) { | 203 for (int32_t j = 0; j < numECWords; j++) { |
206 strecc += (FX_WCHAR)ecc[numECWords - j - 1]; | 204 strecc += (FX_WCHAR)ecc[numECWords - j - 1]; |
207 } | 205 } |
208 FX_Free(ecc); | 206 FX_Free(ecc); |
209 return strecc; | 207 return strecc; |
210 } | 208 } |
OLD | NEW |