| 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 2012 ZXing authors | 8 * Copyright 2012 ZXing authors |
| 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 "xfa/fxbarcode/pdf417/BC_PDF417Common.h" | 23 #include "xfa/fxbarcode/pdf417/BC_PDF417Common.h" |
| 24 #include "xfa/fxbarcode/pdf417/BC_PDF417ECErrorCorrection.h" | 24 #include "xfa/fxbarcode/pdf417/BC_PDF417ECErrorCorrection.h" |
| 25 #include "xfa/fxbarcode/pdf417/BC_PDF417ECModulusGF.h" | 25 #include "xfa/fxbarcode/pdf417/BC_PDF417ECModulusGF.h" |
| 26 #include "xfa/fxbarcode/pdf417/BC_PDF417ECModulusPoly.h" | 26 #include "xfa/fxbarcode/pdf417/BC_PDF417ECModulusPoly.h" |
| 27 #include "xfa/fxbarcode/utils.h" | 27 #include "xfa/fxbarcode/utils.h" |
| 28 | 28 |
| 29 CBC_PDF417ECModulusGF* CBC_PDF417ECErrorCorrection::m_field = NULL; | 29 CBC_PDF417ECModulusGF* CBC_PDF417ECErrorCorrection::m_field = nullptr; |
| 30 | 30 |
| 31 void CBC_PDF417ECErrorCorrection::Initialize(int32_t& e) { | 31 void CBC_PDF417ECErrorCorrection::Initialize(int32_t& e) { |
| 32 m_field = | 32 m_field = |
| 33 new CBC_PDF417ECModulusGF(CBC_PDF417Common::NUMBER_OF_CODEWORDS, 3, e); | 33 new CBC_PDF417ECModulusGF(CBC_PDF417Common::NUMBER_OF_CODEWORDS, 3, e); |
| 34 } | 34 } |
| 35 void CBC_PDF417ECErrorCorrection::Finalize() { | 35 void CBC_PDF417ECErrorCorrection::Finalize() { |
| 36 delete m_field; | 36 delete m_field; |
| 37 } | 37 } |
| 38 CBC_PDF417ECErrorCorrection::CBC_PDF417ECErrorCorrection() {} | 38 CBC_PDF417ECErrorCorrection::CBC_PDF417ECErrorCorrection() {} |
| 39 CBC_PDF417ECErrorCorrection::~CBC_PDF417ECErrorCorrection() {} | 39 CBC_PDF417ECErrorCorrection::~CBC_PDF417ECErrorCorrection() {} |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 130 int32_t& e) { | 130 int32_t& e) { |
| 131 if (a->getDegree() < b->getDegree()) { | 131 if (a->getDegree() < b->getDegree()) { |
| 132 CBC_PDF417ECModulusPoly* temp = a; | 132 CBC_PDF417ECModulusPoly* temp = a; |
| 133 a = b; | 133 a = b; |
| 134 b = temp; | 134 b = temp; |
| 135 } | 135 } |
| 136 CBC_PDF417ECModulusPoly* rLast = a; | 136 CBC_PDF417ECModulusPoly* rLast = a; |
| 137 CBC_PDF417ECModulusPoly* r = b; | 137 CBC_PDF417ECModulusPoly* r = b; |
| 138 CBC_PDF417ECModulusPoly* tLast = m_field->getZero(); | 138 CBC_PDF417ECModulusPoly* tLast = m_field->getZero(); |
| 139 CBC_PDF417ECModulusPoly* t = m_field->getOne(); | 139 CBC_PDF417ECModulusPoly* t = m_field->getOne(); |
| 140 CBC_PDF417ECModulusPoly* qtemp = NULL; | 140 CBC_PDF417ECModulusPoly* qtemp = nullptr; |
| 141 CBC_PDF417ECModulusPoly* rtemp = NULL; | 141 CBC_PDF417ECModulusPoly* rtemp = nullptr; |
| 142 CBC_PDF417ECModulusPoly* ttemp = NULL; | 142 CBC_PDF417ECModulusPoly* ttemp = nullptr; |
| 143 int32_t i = 0; | 143 int32_t i = 0; |
| 144 int32_t j = 0; | 144 int32_t j = 0; |
| 145 int32_t m = 0; | 145 int32_t m = 0; |
| 146 int32_t n = 0; | 146 int32_t n = 0; |
| 147 while (r->getDegree() >= R / 2) { | 147 while (r->getDegree() >= R / 2) { |
| 148 CBC_PDF417ECModulusPoly* rLastLast = rLast; | 148 CBC_PDF417ECModulusPoly* rLastLast = rLast; |
| 149 CBC_PDF417ECModulusPoly* tLastLast = tLast; | 149 CBC_PDF417ECModulusPoly* tLastLast = tLast; |
| 150 rLast = r; | 150 rLast = r; |
| 151 tLast = t; | 151 tLast = t; |
| 152 m = i; | 152 m = i; |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 254 return nullptr; | 254 return nullptr; |
| 255 } | 255 } |
| 256 CBC_PDF417ECModulusPoly* sigma = t->multiply(inverse, e); | 256 CBC_PDF417ECModulusPoly* sigma = t->multiply(inverse, e); |
| 257 delete ttemp; | 257 delete ttemp; |
| 258 if (e != BCExceptionNO) { | 258 if (e != BCExceptionNO) { |
| 259 delete rtemp; | 259 delete rtemp; |
| 260 return nullptr; | 260 return nullptr; |
| 261 } | 261 } |
| 262 CBC_PDF417ECModulusPoly* omega = r->multiply(inverse, e); | 262 CBC_PDF417ECModulusPoly* omega = r->multiply(inverse, e); |
| 263 delete rtemp; | 263 delete rtemp; |
| 264 BC_EXCEPTION_CHECK_ReturnValue(e, NULL); | 264 BC_EXCEPTION_CHECK_ReturnValue(e, nullptr); |
| 265 CFX_ArrayTemplate<CBC_PDF417ECModulusPoly*>* modulusPoly = | 265 CFX_ArrayTemplate<CBC_PDF417ECModulusPoly*>* modulusPoly = |
| 266 new CFX_ArrayTemplate<CBC_PDF417ECModulusPoly*>(); | 266 new CFX_ArrayTemplate<CBC_PDF417ECModulusPoly*>(); |
| 267 modulusPoly->Add(sigma); | 267 modulusPoly->Add(sigma); |
| 268 modulusPoly->Add(omega); | 268 modulusPoly->Add(omega); |
| 269 return modulusPoly; | 269 return modulusPoly; |
| 270 } | 270 } |
| 271 CFX_Int32Array* CBC_PDF417ECErrorCorrection::findErrorLocations( | 271 CFX_Int32Array* CBC_PDF417ECErrorCorrection::findErrorLocations( |
| 272 CBC_PDF417ECModulusPoly* errorLocator, | 272 CBC_PDF417ECModulusPoly* errorLocator, |
| 273 int32_t& e) { | 273 int32_t& e) { |
| 274 int32_t numErrors = errorLocator->getDegree(); | 274 int32_t numErrors = errorLocator->getDegree(); |
| 275 CFX_Int32Array* result = new CFX_Int32Array; | 275 CFX_Int32Array* result = new CFX_Int32Array; |
| 276 result->SetSize(numErrors); | 276 result->SetSize(numErrors); |
| 277 int32_t ee = 0; | 277 int32_t ee = 0; |
| 278 for (int32_t i = 1; i < m_field->getSize() && ee < numErrors; i++) { | 278 for (int32_t i = 1; i < m_field->getSize() && ee < numErrors; i++) { |
| 279 if (errorLocator->evaluateAt(i) == 0) { | 279 if (errorLocator->evaluateAt(i) == 0) { |
| 280 result->SetAt(ee, m_field->inverse(i, e)); | 280 result->SetAt(ee, m_field->inverse(i, e)); |
| 281 if (e != BCExceptionNO) { | 281 if (e != BCExceptionNO) { |
| 282 delete result; | 282 delete result; |
| 283 return NULL; | 283 return nullptr; |
| 284 } | 284 } |
| 285 ee++; | 285 ee++; |
| 286 } | 286 } |
| 287 } | 287 } |
| 288 if (ee != numErrors) { | 288 if (ee != numErrors) { |
| 289 e = BCExceptionChecksumException; | 289 e = BCExceptionChecksumException; |
| 290 delete result; | 290 delete result; |
| 291 return NULL; | 291 return nullptr; |
| 292 } | 292 } |
| 293 return result; | 293 return result; |
| 294 } | 294 } |
| 295 CFX_Int32Array* CBC_PDF417ECErrorCorrection::findErrorMagnitudes( | 295 CFX_Int32Array* CBC_PDF417ECErrorCorrection::findErrorMagnitudes( |
| 296 CBC_PDF417ECModulusPoly* errorEvaluator, | 296 CBC_PDF417ECModulusPoly* errorEvaluator, |
| 297 CBC_PDF417ECModulusPoly* errorLocator, | 297 CBC_PDF417ECModulusPoly* errorLocator, |
| 298 CFX_Int32Array& errorLocations, | 298 CFX_Int32Array& errorLocations, |
| 299 int32_t& e) { | 299 int32_t& e) { |
| 300 int32_t errorLocatorDegree = errorLocator->getDegree(); | 300 int32_t errorLocatorDegree = errorLocator->getDegree(); |
| 301 CFX_Int32Array formalDerivativeCoefficients; | 301 CFX_Int32Array formalDerivativeCoefficients; |
| 302 formalDerivativeCoefficients.SetSize(errorLocatorDegree); | 302 formalDerivativeCoefficients.SetSize(errorLocatorDegree); |
| 303 for (int32_t l = 1; l <= errorLocatorDegree; l++) { | 303 for (int32_t l = 1; l <= errorLocatorDegree; l++) { |
| 304 formalDerivativeCoefficients[errorLocatorDegree - l] = | 304 formalDerivativeCoefficients[errorLocatorDegree - l] = |
| 305 m_field->multiply(l, errorLocator->getCoefficient(l)); | 305 m_field->multiply(l, errorLocator->getCoefficient(l)); |
| 306 } | 306 } |
| 307 CBC_PDF417ECModulusPoly formalDerivative(m_field, | 307 CBC_PDF417ECModulusPoly formalDerivative(m_field, |
| 308 formalDerivativeCoefficients, e); | 308 formalDerivativeCoefficients, e); |
| 309 BC_EXCEPTION_CHECK_ReturnValue(e, NULL); | 309 BC_EXCEPTION_CHECK_ReturnValue(e, nullptr); |
| 310 int32_t s = errorLocations.GetSize(); | 310 int32_t s = errorLocations.GetSize(); |
| 311 CFX_Int32Array* result = new CFX_Int32Array; | 311 CFX_Int32Array* result = new CFX_Int32Array; |
| 312 result->SetSize(s); | 312 result->SetSize(s); |
| 313 for (int32_t i = 0; i < s; i++) { | 313 for (int32_t i = 0; i < s; i++) { |
| 314 int32_t xiInverse = m_field->inverse(errorLocations[i], e); | 314 int32_t xiInverse = m_field->inverse(errorLocations[i], e); |
| 315 if (e != BCExceptionNO) { | 315 if (e != BCExceptionNO) { |
| 316 delete result; | 316 delete result; |
| 317 return NULL; | 317 return nullptr; |
| 318 } | 318 } |
| 319 int32_t numerator = | 319 int32_t numerator = |
| 320 m_field->subtract(0, errorEvaluator->evaluateAt(xiInverse)); | 320 m_field->subtract(0, errorEvaluator->evaluateAt(xiInverse)); |
| 321 int32_t denominator = | 321 int32_t denominator = |
| 322 m_field->inverse(formalDerivative.evaluateAt(xiInverse), e); | 322 m_field->inverse(formalDerivative.evaluateAt(xiInverse), e); |
| 323 if (e != BCExceptionNO) { | 323 if (e != BCExceptionNO) { |
| 324 delete result; | 324 delete result; |
| 325 return NULL; | 325 return nullptr; |
| 326 } | 326 } |
| 327 result->SetAt(i, m_field->multiply(numerator, denominator)); | 327 result->SetAt(i, m_field->multiply(numerator, denominator)); |
| 328 } | 328 } |
| 329 return result; | 329 return result; |
| 330 } | 330 } |
| OLD | NEW |