| 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 2007 ZXing authors | 8 * Copyright 2007 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/src/fxbarcode/common/reedsolomon/BC_ReedSolomonGF256Poly.h" |
| 24 |
| 25 #include <memory> |
| 26 |
| 23 #include "xfa/src/fxbarcode/common/reedsolomon/BC_ReedSolomonGF256.h" | 27 #include "xfa/src/fxbarcode/common/reedsolomon/BC_ReedSolomonGF256.h" |
| 24 #include "xfa/src/fxbarcode/common/reedsolomon/BC_ReedSolomonGF256Poly.h" | |
| 25 | 28 |
| 26 CBC_ReedSolomonGF256Poly::CBC_ReedSolomonGF256Poly(CBC_ReedSolomonGF256* field, | 29 CBC_ReedSolomonGF256Poly::CBC_ReedSolomonGF256Poly(CBC_ReedSolomonGF256* field, |
| 27 int32_t coefficients) { | 30 int32_t coefficients) { |
| 28 if (field == NULL) { | 31 if (field == NULL) { |
| 29 return; | 32 return; |
| 30 } | 33 } |
| 31 m_field = field; | 34 m_field = field; |
| 32 m_coefficients.Add(coefficients); | 35 m_coefficients.Add(coefficients); |
| 33 } | 36 } |
| 34 CBC_ReedSolomonGF256Poly::CBC_ReedSolomonGF256Poly() { | 37 CBC_ReedSolomonGF256Poly::CBC_ReedSolomonGF256Poly() { |
| (...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 209 temp->Init(m_field, &product, e); | 212 temp->Init(m_field, &product, e); |
| 210 BC_EXCEPTION_CHECK_ReturnValue(e, NULL); | 213 BC_EXCEPTION_CHECK_ReturnValue(e, NULL); |
| 211 return temp; | 214 return temp; |
| 212 } | 215 } |
| 213 CFX_PtrArray* CBC_ReedSolomonGF256Poly::Divide(CBC_ReedSolomonGF256Poly* other, | 216 CFX_PtrArray* CBC_ReedSolomonGF256Poly::Divide(CBC_ReedSolomonGF256Poly* other, |
| 214 int32_t& e) { | 217 int32_t& e) { |
| 215 if (other->IsZero()) { | 218 if (other->IsZero()) { |
| 216 e = BCExceptionDivideByZero; | 219 e = BCExceptionDivideByZero; |
| 217 BC_EXCEPTION_CHECK_ReturnValue(e, NULL); | 220 BC_EXCEPTION_CHECK_ReturnValue(e, NULL); |
| 218 } | 221 } |
| 219 CBC_ReedSolomonGF256Poly* rsg1 = m_field->GetZero()->Clone(e); | 222 std::unique_ptr<CBC_ReedSolomonGF256Poly> quotient( |
| 223 m_field->GetZero()->Clone(e)); |
| 220 BC_EXCEPTION_CHECK_ReturnValue(e, NULL); | 224 BC_EXCEPTION_CHECK_ReturnValue(e, NULL); |
| 221 CBC_AutoPtr<CBC_ReedSolomonGF256Poly> quotient(rsg1); | 225 std::unique_ptr<CBC_ReedSolomonGF256Poly> remainder(Clone(e)); |
| 222 CBC_ReedSolomonGF256Poly* rsg2 = Clone(e); | |
| 223 BC_EXCEPTION_CHECK_ReturnValue(e, NULL); | 226 BC_EXCEPTION_CHECK_ReturnValue(e, NULL); |
| 224 CBC_AutoPtr<CBC_ReedSolomonGF256Poly> remainder(rsg2); | |
| 225 int32_t denominatorLeadingTerm = other->GetCoefficients(other->GetDegree()); | 227 int32_t denominatorLeadingTerm = other->GetCoefficients(other->GetDegree()); |
| 226 int32_t inverseDenominatorLeadingTeam = | 228 int32_t inverseDenominatorLeadingTeam = |
| 227 m_field->Inverse(denominatorLeadingTerm, e); | 229 m_field->Inverse(denominatorLeadingTerm, e); |
| 228 BC_EXCEPTION_CHECK_ReturnValue(e, NULL); | 230 BC_EXCEPTION_CHECK_ReturnValue(e, NULL); |
| 229 while (remainder->GetDegree() >= other->GetDegree() && !remainder->IsZero()) { | 231 while (remainder->GetDegree() >= other->GetDegree() && !remainder->IsZero()) { |
| 230 int32_t degreeDifference = remainder->GetDegree() - other->GetDegree(); | 232 int32_t degreeDifference = remainder->GetDegree() - other->GetDegree(); |
| 231 int32_t scale = | 233 int32_t scale = |
| 232 m_field->Multiply(remainder->GetCoefficients((remainder->GetDegree())), | 234 m_field->Multiply(remainder->GetCoefficients((remainder->GetDegree())), |
| 233 inverseDenominatorLeadingTeam); | 235 inverseDenominatorLeadingTeam); |
| 234 CBC_ReedSolomonGF256Poly* rsg3 = | 236 std::unique_ptr<CBC_ReedSolomonGF256Poly> term( |
| 235 other->MultiplyByMonomial(degreeDifference, scale, e); | 237 other->MultiplyByMonomial(degreeDifference, scale, e)); |
| 236 BC_EXCEPTION_CHECK_ReturnValue(e, NULL); | 238 BC_EXCEPTION_CHECK_ReturnValue(e, NULL); |
| 237 CBC_AutoPtr<CBC_ReedSolomonGF256Poly> term(rsg3); | 239 std::unique_ptr<CBC_ReedSolomonGF256Poly> iteratorQuotient( |
| 238 CBC_ReedSolomonGF256Poly* rsg4 = | 240 m_field->BuildMonomial(degreeDifference, scale, e)); |
| 239 m_field->BuildMonomial(degreeDifference, scale, e); | |
| 240 BC_EXCEPTION_CHECK_ReturnValue(e, NULL); | 241 BC_EXCEPTION_CHECK_ReturnValue(e, NULL); |
| 241 CBC_AutoPtr<CBC_ReedSolomonGF256Poly> iteratorQuotient(rsg4); | 242 quotient.reset(quotient->AddOrSubtract(iteratorQuotient.get(), e)); |
| 242 CBC_ReedSolomonGF256Poly* rsg5 = | |
| 243 quotient->AddOrSubtract(iteratorQuotient.get(), e); | |
| 244 BC_EXCEPTION_CHECK_ReturnValue(e, NULL); | 243 BC_EXCEPTION_CHECK_ReturnValue(e, NULL); |
| 245 CBC_AutoPtr<CBC_ReedSolomonGF256Poly> temp(rsg5); | 244 remainder.reset(remainder->AddOrSubtract(term.get(), e)); |
| 246 quotient = temp; | |
| 247 CBC_ReedSolomonGF256Poly* rsg6 = remainder->AddOrSubtract(term.get(), e); | |
| 248 BC_EXCEPTION_CHECK_ReturnValue(e, NULL); | 245 BC_EXCEPTION_CHECK_ReturnValue(e, NULL); |
| 249 CBC_AutoPtr<CBC_ReedSolomonGF256Poly> temp1(rsg6); | |
| 250 remainder = temp1; | |
| 251 } | 246 } |
| 252 CFX_PtrArray* tempPtrA = new CFX_PtrArray; | 247 CFX_PtrArray* tempPtrA = new CFX_PtrArray; |
| 253 tempPtrA->Add(quotient.release()); | 248 tempPtrA->Add(quotient.release()); |
| 254 tempPtrA->Add(remainder.release()); | 249 tempPtrA->Add(remainder.release()); |
| 255 return tempPtrA; | 250 return tempPtrA; |
| 256 } | 251 } |
| 257 CBC_ReedSolomonGF256Poly::~CBC_ReedSolomonGF256Poly() { | 252 CBC_ReedSolomonGF256Poly::~CBC_ReedSolomonGF256Poly() { |
| 258 m_coefficients.RemoveAll(); | 253 m_coefficients.RemoveAll(); |
| 259 } | 254 } |
| OLD | NEW |