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

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

Issue 2649563003: Replace CFX_ByteArray with CFX_ArrayTemplate<uint8_t> (Closed)
Patch Set: re-upload Created 3 years, 11 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");
(...skipping 21 matching lines...) Expand all
32 } 32 }
33 void CBC_ReedSolomonEncoder::Init() { 33 void CBC_ReedSolomonEncoder::Init() {
34 m_cachedGenerators.Add(new CBC_ReedSolomonGF256Poly(m_field, 1)); 34 m_cachedGenerators.Add(new CBC_ReedSolomonGF256Poly(m_field, 1));
35 } 35 }
36 CBC_ReedSolomonGF256Poly* CBC_ReedSolomonEncoder::BuildGenerator(int32_t degree, 36 CBC_ReedSolomonGF256Poly* CBC_ReedSolomonEncoder::BuildGenerator(int32_t degree,
37 int32_t& e) { 37 int32_t& e) {
38 if (degree >= m_cachedGenerators.GetSize()) { 38 if (degree >= m_cachedGenerators.GetSize()) {
39 CBC_ReedSolomonGF256Poly* lastGenerator = 39 CBC_ReedSolomonGF256Poly* lastGenerator =
40 m_cachedGenerators[m_cachedGenerators.GetSize() - 1]; 40 m_cachedGenerators[m_cachedGenerators.GetSize() - 1];
41 for (int32_t d = m_cachedGenerators.GetSize(); d <= degree; d++) { 41 for (int32_t d = m_cachedGenerators.GetSize(); d <= degree; d++) {
42 CFX_Int32Array temp; 42 CFX_ArrayTemplate<int32_t> temp;
43 temp.Add(1); 43 temp.Add(1);
44 temp.Add(m_field->Exp(d - 1)); 44 temp.Add(m_field->Exp(d - 1));
45 CBC_ReedSolomonGF256Poly temp_poly; 45 CBC_ReedSolomonGF256Poly temp_poly;
46 temp_poly.Init(m_field, &temp, e); 46 temp_poly.Init(m_field, &temp, e);
47 BC_EXCEPTION_CHECK_ReturnValue(e, nullptr); 47 BC_EXCEPTION_CHECK_ReturnValue(e, nullptr);
48 CBC_ReedSolomonGF256Poly* nextGenerator = 48 CBC_ReedSolomonGF256Poly* nextGenerator =
49 lastGenerator->Multiply(&temp_poly, e); 49 lastGenerator->Multiply(&temp_poly, e);
50 BC_EXCEPTION_CHECK_ReturnValue(e, nullptr); 50 BC_EXCEPTION_CHECK_ReturnValue(e, nullptr);
51 m_cachedGenerators.Add(nextGenerator); 51 m_cachedGenerators.Add(nextGenerator);
52 lastGenerator = nextGenerator; 52 lastGenerator = nextGenerator;
53 } 53 }
54 } 54 }
55 return m_cachedGenerators[degree]; 55 return m_cachedGenerators[degree];
56 } 56 }
57 void CBC_ReedSolomonEncoder::Encode(CFX_Int32Array* toEncode, 57 void CBC_ReedSolomonEncoder::Encode(CFX_ArrayTemplate<int32_t>* toEncode,
58 int32_t ecBytes, 58 int32_t ecBytes,
59 int32_t& e) { 59 int32_t& e) {
60 if (ecBytes == 0) { 60 if (ecBytes == 0) {
61 e = BCExceptionNoCorrectionBytes; 61 e = BCExceptionNoCorrectionBytes;
62 BC_EXCEPTION_CHECK_ReturnVoid(e); 62 BC_EXCEPTION_CHECK_ReturnVoid(e);
63 } 63 }
64 int32_t dataBytes = toEncode->GetSize() - ecBytes; 64 int32_t dataBytes = toEncode->GetSize() - ecBytes;
65 if (dataBytes <= 0) { 65 if (dataBytes <= 0) {
66 e = BCExceptionNoDataBytesProvided; 66 e = BCExceptionNoDataBytesProvided;
67 BC_EXCEPTION_CHECK_ReturnVoid(e); 67 BC_EXCEPTION_CHECK_ReturnVoid(e);
68 } 68 }
69 CBC_ReedSolomonGF256Poly* generator = BuildGenerator(ecBytes, e); 69 CBC_ReedSolomonGF256Poly* generator = BuildGenerator(ecBytes, e);
70 BC_EXCEPTION_CHECK_ReturnVoid(e); 70 BC_EXCEPTION_CHECK_ReturnVoid(e);
71 CFX_Int32Array infoCoefficients; 71 CFX_ArrayTemplate<int32_t> infoCoefficients;
72 infoCoefficients.SetSize(dataBytes); 72 infoCoefficients.SetSize(dataBytes);
73 for (int32_t x = 0; x < dataBytes; x++) { 73 for (int32_t x = 0; x < dataBytes; x++) {
74 infoCoefficients[x] = toEncode->operator[](x); 74 infoCoefficients[x] = toEncode->operator[](x);
75 } 75 }
76 CBC_ReedSolomonGF256Poly info; 76 CBC_ReedSolomonGF256Poly info;
77 info.Init(m_field, &infoCoefficients, e); 77 info.Init(m_field, &infoCoefficients, e);
78 BC_EXCEPTION_CHECK_ReturnVoid(e); 78 BC_EXCEPTION_CHECK_ReturnVoid(e);
79 std::unique_ptr<CBC_ReedSolomonGF256Poly> infoTemp( 79 std::unique_ptr<CBC_ReedSolomonGF256Poly> infoTemp(
80 info.MultiplyByMonomial(ecBytes, 1, e)); 80 info.MultiplyByMonomial(ecBytes, 1, e));
81 BC_EXCEPTION_CHECK_ReturnVoid(e); 81 BC_EXCEPTION_CHECK_ReturnVoid(e);
82 std::unique_ptr<CFX_ArrayTemplate<CBC_ReedSolomonGF256Poly*>> temp( 82 std::unique_ptr<CFX_ArrayTemplate<CBC_ReedSolomonGF256Poly*>> temp(
83 infoTemp->Divide(generator, e)); 83 infoTemp->Divide(generator, e));
84 BC_EXCEPTION_CHECK_ReturnVoid(e); 84 BC_EXCEPTION_CHECK_ReturnVoid(e);
85 CBC_ReedSolomonGF256Poly* remainder = (*temp)[1]; 85 CBC_ReedSolomonGF256Poly* remainder = (*temp)[1];
86 CFX_Int32Array* coefficients = remainder->GetCoefficients(); 86 CFX_ArrayTemplate<int32_t>* coefficients = remainder->GetCoefficients();
87 int32_t numZeroCoefficients = ecBytes - coefficients->GetSize(); 87 int32_t numZeroCoefficients = ecBytes - coefficients->GetSize();
88 for (int32_t i = 0; i < numZeroCoefficients; i++) { 88 for (int32_t i = 0; i < numZeroCoefficients; i++) {
89 (*toEncode)[dataBytes + i] = 0; 89 (*toEncode)[dataBytes + i] = 0;
90 } 90 }
91 for (int32_t y = 0; y < coefficients->GetSize(); y++) { 91 for (int32_t y = 0; y < coefficients->GetSize(); y++) {
92 (*toEncode)[dataBytes + numZeroCoefficients + y] = 92 (*toEncode)[dataBytes + numZeroCoefficients + y] =
93 coefficients->operator[](y); 93 coefficients->operator[](y);
94 } 94 }
95 for (int32_t k = 0; k < temp->GetSize(); k++) { 95 for (int32_t k = 0; k < temp->GetSize(); k++) {
96 delete (*temp)[k]; 96 delete (*temp)[k];
97 } 97 }
98 } 98 }
99 CBC_ReedSolomonEncoder::~CBC_ReedSolomonEncoder() { 99 CBC_ReedSolomonEncoder::~CBC_ReedSolomonEncoder() {
100 for (int32_t i = 0; i < m_cachedGenerators.GetSize(); i++) 100 for (int32_t i = 0; i < m_cachedGenerators.GetSize(); i++)
101 delete m_cachedGenerators[i]; 101 delete m_cachedGenerators[i];
102 } 102 }
OLDNEW
« no previous file with comments | « xfa/fxbarcode/common/reedsolomon/BC_ReedSolomon.h ('k') | xfa/fxbarcode/common/reedsolomon/BC_ReedSolomonGF256.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698