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

Side by Side Diff: xfa/src/fxbarcode/common/reedsolomon/BC_ReedSolomon.cpp

Issue 1734823002: Get rid of CBC_AutoPtr and use std::unique_ptr instead. (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: rebase Created 4 years, 9 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 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_ReedSolomon.h" 23 #include "xfa/src/fxbarcode/common/reedsolomon/BC_ReedSolomon.h"
24
25 #include <memory>
26
24 #include "xfa/src/fxbarcode/common/reedsolomon/BC_ReedSolomonGF256.h" 27 #include "xfa/src/fxbarcode/common/reedsolomon/BC_ReedSolomonGF256.h"
25 #include "xfa/src/fxbarcode/common/reedsolomon/BC_ReedSolomonGF256Poly.h" 28 #include "xfa/src/fxbarcode/common/reedsolomon/BC_ReedSolomonGF256Poly.h"
26 29
27 CBC_ReedSolomonEncoder::CBC_ReedSolomonEncoder(CBC_ReedSolomonGF256* field) { 30 CBC_ReedSolomonEncoder::CBC_ReedSolomonEncoder(CBC_ReedSolomonGF256* field) {
28 m_field = field; 31 m_field = field;
29 } 32 }
30 void CBC_ReedSolomonEncoder::Init() { 33 void CBC_ReedSolomonEncoder::Init() {
31 m_cachedGenerators.Add(new CBC_ReedSolomonGF256Poly(m_field, 1)); 34 m_cachedGenerators.Add(new CBC_ReedSolomonGF256Poly(m_field, 1));
32 } 35 }
33 CBC_ReedSolomonGF256Poly* CBC_ReedSolomonEncoder::BuildGenerator(int32_t degree, 36 CBC_ReedSolomonGF256Poly* CBC_ReedSolomonEncoder::BuildGenerator(int32_t degree,
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
67 CBC_ReedSolomonGF256Poly* generator = BuildGenerator(ecBytes, e); 70 CBC_ReedSolomonGF256Poly* generator = BuildGenerator(ecBytes, e);
68 BC_EXCEPTION_CHECK_ReturnVoid(e); 71 BC_EXCEPTION_CHECK_ReturnVoid(e);
69 CFX_Int32Array infoCoefficients; 72 CFX_Int32Array infoCoefficients;
70 infoCoefficients.SetSize(dataBytes); 73 infoCoefficients.SetSize(dataBytes);
71 for (int32_t x = 0; x < dataBytes; x++) { 74 for (int32_t x = 0; x < dataBytes; x++) {
72 infoCoefficients[x] = toEncode->operator[](x); 75 infoCoefficients[x] = toEncode->operator[](x);
73 } 76 }
74 CBC_ReedSolomonGF256Poly info; 77 CBC_ReedSolomonGF256Poly info;
75 info.Init(m_field, &infoCoefficients, e); 78 info.Init(m_field, &infoCoefficients, e);
76 BC_EXCEPTION_CHECK_ReturnVoid(e); 79 BC_EXCEPTION_CHECK_ReturnVoid(e);
77 CBC_ReedSolomonGF256Poly* rsg = info.MultiplyByMonomial(ecBytes, 1, e); 80 std::unique_ptr<CBC_ReedSolomonGF256Poly> infoTemp(
81 info.MultiplyByMonomial(ecBytes, 1, e));
78 BC_EXCEPTION_CHECK_ReturnVoid(e); 82 BC_EXCEPTION_CHECK_ReturnVoid(e);
79 CBC_AutoPtr<CBC_ReedSolomonGF256Poly> infoTemp(rsg); 83 std::unique_ptr<CFX_PtrArray> temp(infoTemp->Divide(generator, e));
80 CFX_PtrArray* pa = infoTemp->Divide(generator, e);
81 BC_EXCEPTION_CHECK_ReturnVoid(e); 84 BC_EXCEPTION_CHECK_ReturnVoid(e);
82 CBC_AutoPtr<CFX_PtrArray> temp(pa);
83 CBC_ReedSolomonGF256Poly* remainder = 85 CBC_ReedSolomonGF256Poly* remainder =
84 (CBC_ReedSolomonGF256Poly*)(temp->operator[](1)); 86 (CBC_ReedSolomonGF256Poly*)(temp->operator[](1));
85 CFX_Int32Array* coefficients = remainder->GetCoefficients(); 87 CFX_Int32Array* coefficients = remainder->GetCoefficients();
86 int32_t numZeroCoefficients = ecBytes - coefficients->GetSize(); 88 int32_t numZeroCoefficients = ecBytes - coefficients->GetSize();
87 for (int32_t i = 0; i < numZeroCoefficients; i++) { 89 for (int32_t i = 0; i < numZeroCoefficients; i++) {
88 (*toEncode)[dataBytes + i] = 0; 90 (*toEncode)[dataBytes + i] = 0;
89 } 91 }
90 for (int32_t y = 0; y < coefficients->GetSize(); y++) { 92 for (int32_t y = 0; y < coefficients->GetSize(); y++) {
91 (*toEncode)[dataBytes + numZeroCoefficients + y] = 93 (*toEncode)[dataBytes + numZeroCoefficients + y] =
92 coefficients->operator[](y); 94 coefficients->operator[](y);
93 } 95 }
94 for (int32_t k = 0; k < temp->GetSize(); k++) { 96 for (int32_t k = 0; k < temp->GetSize(); k++) {
95 delete (CBC_ReedSolomonGF256Poly*)(*temp)[k]; 97 delete (CBC_ReedSolomonGF256Poly*)(*temp)[k];
96 } 98 }
97 } 99 }
98 CBC_ReedSolomonEncoder::~CBC_ReedSolomonEncoder() { 100 CBC_ReedSolomonEncoder::~CBC_ReedSolomonEncoder() {
99 for (int32_t i = 0; i < m_cachedGenerators.GetSize(); i++) { 101 for (int32_t i = 0; i < m_cachedGenerators.GetSize(); i++) {
100 delete (CBC_ReedSolomonGF256Poly*)m_cachedGenerators[i]; 102 delete (CBC_ReedSolomonGF256Poly*)m_cachedGenerators[i];
101 } 103 }
102 } 104 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698