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

Side by Side Diff: xfa/fxbarcode/common/reedsolomon/BC_ReedSolomonGF256Poly.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 20 matching lines...) Expand all
31 if (!field) 31 if (!field)
32 return; 32 return;
33 33
34 m_field = field; 34 m_field = field;
35 m_coefficients.Add(coefficients); 35 m_coefficients.Add(coefficients);
36 } 36 }
37 CBC_ReedSolomonGF256Poly::CBC_ReedSolomonGF256Poly() { 37 CBC_ReedSolomonGF256Poly::CBC_ReedSolomonGF256Poly() {
38 m_field = nullptr; 38 m_field = nullptr;
39 } 39 }
40 void CBC_ReedSolomonGF256Poly::Init(CBC_ReedSolomonGF256* field, 40 void CBC_ReedSolomonGF256Poly::Init(CBC_ReedSolomonGF256* field,
41 CFX_Int32Array* coefficients, 41 CFX_ArrayTemplate<int32_t>* coefficients,
42 int32_t& e) { 42 int32_t& e) {
43 if (!coefficients || coefficients->GetSize() == 0) { 43 if (!coefficients || coefficients->GetSize() == 0) {
44 e = BCExceptionCoefficientsSizeIsNull; 44 e = BCExceptionCoefficientsSizeIsNull;
45 BC_EXCEPTION_CHECK_ReturnVoid(e); 45 BC_EXCEPTION_CHECK_ReturnVoid(e);
46 } 46 }
47 m_field = field; 47 m_field = field;
48 int32_t coefficientsLength = coefficients->GetSize(); 48 int32_t coefficientsLength = coefficients->GetSize();
49 if ((coefficientsLength > 1 && (*coefficients)[0] == 0)) { 49 if ((coefficientsLength > 1 && (*coefficients)[0] == 0)) {
50 int32_t firstNonZero = 1; 50 int32_t firstNonZero = 1;
51 while ((firstNonZero < coefficientsLength) && 51 while ((firstNonZero < coefficientsLength) &&
52 ((*coefficients)[firstNonZero] == 0)) { 52 ((*coefficients)[firstNonZero] == 0)) {
53 firstNonZero++; 53 firstNonZero++;
54 } 54 }
55 if (firstNonZero == coefficientsLength) { 55 if (firstNonZero == coefficientsLength) {
56 m_coefficients.Copy(*(m_field->GetZero()->GetCoefficients())); 56 m_coefficients.Copy(*(m_field->GetZero()->GetCoefficients()));
57 } else { 57 } else {
58 m_coefficients.SetSize(coefficientsLength - firstNonZero); 58 m_coefficients.SetSize(coefficientsLength - firstNonZero);
59 for (int32_t i = firstNonZero, j = 0; i < coefficientsLength; i++, j++) { 59 for (int32_t i = firstNonZero, j = 0; i < coefficientsLength; i++, j++) {
60 m_coefficients[j] = coefficients->operator[](i); 60 m_coefficients[j] = coefficients->operator[](i);
61 } 61 }
62 } 62 }
63 } else { 63 } else {
64 m_coefficients.Copy(*coefficients); 64 m_coefficients.Copy(*coefficients);
65 } 65 }
66 } 66 }
67 CFX_Int32Array* CBC_ReedSolomonGF256Poly::GetCoefficients() { 67 CFX_ArrayTemplate<int32_t>* CBC_ReedSolomonGF256Poly::GetCoefficients() {
68 return &m_coefficients; 68 return &m_coefficients;
69 } 69 }
70 int32_t CBC_ReedSolomonGF256Poly::GetDegree() { 70 int32_t CBC_ReedSolomonGF256Poly::GetDegree() {
71 return m_coefficients.GetSize() - 1; 71 return m_coefficients.GetSize() - 1;
72 } 72 }
73 bool CBC_ReedSolomonGF256Poly::IsZero() { 73 bool CBC_ReedSolomonGF256Poly::IsZero() {
74 return m_coefficients[0] == 0; 74 return m_coefficients[0] == 0;
75 } 75 }
76 int32_t CBC_ReedSolomonGF256Poly::GetCoefficients(int32_t degree) { 76 int32_t CBC_ReedSolomonGF256Poly::GetCoefficients(int32_t degree) {
77 return m_coefficients[m_coefficients.GetSize() - 1 - degree]; 77 return m_coefficients[m_coefficients.GetSize() - 1 - degree];
(...skipping 24 matching lines...) Expand all
102 return temp; 102 return temp;
103 } 103 }
104 CBC_ReedSolomonGF256Poly* CBC_ReedSolomonGF256Poly::AddOrSubtract( 104 CBC_ReedSolomonGF256Poly* CBC_ReedSolomonGF256Poly::AddOrSubtract(
105 CBC_ReedSolomonGF256Poly* other, 105 CBC_ReedSolomonGF256Poly* other,
106 int32_t& e) { 106 int32_t& e) {
107 if (IsZero()) 107 if (IsZero())
108 return other->Clone(e); 108 return other->Clone(e);
109 if (other->IsZero()) 109 if (other->IsZero())
110 return Clone(e); 110 return Clone(e);
111 111
112 CFX_Int32Array smallerCoefficients; 112 CFX_ArrayTemplate<int32_t> smallerCoefficients;
113 smallerCoefficients.Copy(m_coefficients); 113 smallerCoefficients.Copy(m_coefficients);
114 CFX_Int32Array largerCoefficients; 114 CFX_ArrayTemplate<int32_t> largerCoefficients;
115 largerCoefficients.Copy(*(other->GetCoefficients())); 115 largerCoefficients.Copy(*(other->GetCoefficients()));
116 if (smallerCoefficients.GetSize() > largerCoefficients.GetSize()) { 116 if (smallerCoefficients.GetSize() > largerCoefficients.GetSize()) {
117 CFX_Int32Array temp; 117 CFX_ArrayTemplate<int32_t> temp;
118 temp.Copy(smallerCoefficients); 118 temp.Copy(smallerCoefficients);
119 smallerCoefficients.Copy(largerCoefficients); 119 smallerCoefficients.Copy(largerCoefficients);
120 largerCoefficients.Copy(temp); 120 largerCoefficients.Copy(temp);
121 } 121 }
122 CFX_Int32Array sumDiff; 122 CFX_ArrayTemplate<int32_t> sumDiff;
123 sumDiff.SetSize(largerCoefficients.GetSize()); 123 sumDiff.SetSize(largerCoefficients.GetSize());
124 int32_t lengthDiff = 124 int32_t lengthDiff =
125 largerCoefficients.GetSize() - smallerCoefficients.GetSize(); 125 largerCoefficients.GetSize() - smallerCoefficients.GetSize();
126 for (int32_t i = 0; i < lengthDiff; i++) { 126 for (int32_t i = 0; i < lengthDiff; i++) {
127 sumDiff[i] = largerCoefficients[i]; 127 sumDiff[i] = largerCoefficients[i];
128 } 128 }
129 for (int32_t j = lengthDiff; j < largerCoefficients.GetSize(); j++) { 129 for (int32_t j = lengthDiff; j < largerCoefficients.GetSize(); j++) {
130 sumDiff[j] = (CBC_ReedSolomonGF256::AddOrSubtract( 130 sumDiff[j] = (CBC_ReedSolomonGF256::AddOrSubtract(
131 smallerCoefficients[j - lengthDiff], largerCoefficients[j])); 131 smallerCoefficients[j - lengthDiff], largerCoefficients[j]));
132 } 132 }
133 CBC_ReedSolomonGF256Poly* temp = new CBC_ReedSolomonGF256Poly(); 133 CBC_ReedSolomonGF256Poly* temp = new CBC_ReedSolomonGF256Poly();
134 temp->Init(m_field, &sumDiff, e); 134 temp->Init(m_field, &sumDiff, e);
135 BC_EXCEPTION_CHECK_ReturnValue(e, nullptr); 135 BC_EXCEPTION_CHECK_ReturnValue(e, nullptr);
136 return temp; 136 return temp;
137 } 137 }
138 CBC_ReedSolomonGF256Poly* CBC_ReedSolomonGF256Poly::Multiply( 138 CBC_ReedSolomonGF256Poly* CBC_ReedSolomonGF256Poly::Multiply(
139 CBC_ReedSolomonGF256Poly* other, 139 CBC_ReedSolomonGF256Poly* other,
140 int32_t& e) { 140 int32_t& e) {
141 if (IsZero() || other->IsZero()) 141 if (IsZero() || other->IsZero())
142 return m_field->GetZero()->Clone(e); 142 return m_field->GetZero()->Clone(e);
143 143
144 CFX_Int32Array aCoefficients; 144 CFX_ArrayTemplate<int32_t> aCoefficients;
145 aCoefficients.Copy(m_coefficients); 145 aCoefficients.Copy(m_coefficients);
146 int32_t aLength = m_coefficients.GetSize(); 146 int32_t aLength = m_coefficients.GetSize();
147 CFX_Int32Array bCoefficients; 147 CFX_ArrayTemplate<int32_t> bCoefficients;
148 bCoefficients.Copy(*(other->GetCoefficients())); 148 bCoefficients.Copy(*(other->GetCoefficients()));
149 int32_t bLength = other->GetCoefficients()->GetSize(); 149 int32_t bLength = other->GetCoefficients()->GetSize();
150 CFX_Int32Array product; 150 CFX_ArrayTemplate<int32_t> product;
151 product.SetSize(aLength + bLength - 1); 151 product.SetSize(aLength + bLength - 1);
152 for (int32_t i = 0; i < aLength; i++) { 152 for (int32_t i = 0; i < aLength; i++) {
153 int32_t aCoeff = m_coefficients[i]; 153 int32_t aCoeff = m_coefficients[i];
154 for (int32_t j = 0; j < bLength; j++) { 154 for (int32_t j = 0; j < bLength; j++) {
155 product[i + j] = CBC_ReedSolomonGF256::AddOrSubtract( 155 product[i + j] = CBC_ReedSolomonGF256::AddOrSubtract(
156 product[i + j], 156 product[i + j],
157 m_field->Multiply(aCoeff, other->GetCoefficients()->operator[](j))); 157 m_field->Multiply(aCoeff, other->GetCoefficients()->operator[](j)));
158 } 158 }
159 } 159 }
160 CBC_ReedSolomonGF256Poly* temp = new CBC_ReedSolomonGF256Poly(); 160 CBC_ReedSolomonGF256Poly* temp = new CBC_ReedSolomonGF256Poly();
161 temp->Init(m_field, &product, e); 161 temp->Init(m_field, &product, e);
162 BC_EXCEPTION_CHECK_ReturnValue(e, nullptr); 162 BC_EXCEPTION_CHECK_ReturnValue(e, nullptr);
163 return temp; 163 return temp;
164 } 164 }
165 CBC_ReedSolomonGF256Poly* CBC_ReedSolomonGF256Poly::Multiply(int32_t scalar, 165 CBC_ReedSolomonGF256Poly* CBC_ReedSolomonGF256Poly::Multiply(int32_t scalar,
166 int32_t& e) { 166 int32_t& e) {
167 if (scalar == 0) 167 if (scalar == 0)
168 return m_field->GetZero()->Clone(e); 168 return m_field->GetZero()->Clone(e);
169 if (scalar == 1) 169 if (scalar == 1)
170 return Clone(e); 170 return Clone(e);
171 171
172 int32_t size = m_coefficients.GetSize(); 172 int32_t size = m_coefficients.GetSize();
173 CFX_Int32Array product; 173 CFX_ArrayTemplate<int32_t> product;
174 product.SetSize(size); 174 product.SetSize(size);
175 for (int32_t i = 0; i < size; i++) { 175 for (int32_t i = 0; i < size; i++) {
176 product[i] = m_field->Multiply(m_coefficients[i], scalar); 176 product[i] = m_field->Multiply(m_coefficients[i], scalar);
177 } 177 }
178 CBC_ReedSolomonGF256Poly* temp = new CBC_ReedSolomonGF256Poly(); 178 CBC_ReedSolomonGF256Poly* temp = new CBC_ReedSolomonGF256Poly();
179 temp->Init(m_field, &product, e); 179 temp->Init(m_field, &product, e);
180 BC_EXCEPTION_CHECK_ReturnValue(e, nullptr); 180 BC_EXCEPTION_CHECK_ReturnValue(e, nullptr);
181 return temp; 181 return temp;
182 } 182 }
183 CBC_ReedSolomonGF256Poly* CBC_ReedSolomonGF256Poly::MultiplyByMonomial( 183 CBC_ReedSolomonGF256Poly* CBC_ReedSolomonGF256Poly::MultiplyByMonomial(
184 int32_t degree, 184 int32_t degree,
185 int32_t coefficient, 185 int32_t coefficient,
186 int32_t& e) { 186 int32_t& e) {
187 if (degree < 0) { 187 if (degree < 0) {
188 e = BCExceptionDegreeIsNegative; 188 e = BCExceptionDegreeIsNegative;
189 return nullptr; 189 return nullptr;
190 } 190 }
191 if (coefficient == 0) 191 if (coefficient == 0)
192 return m_field->GetZero()->Clone(e); 192 return m_field->GetZero()->Clone(e);
193 193
194 int32_t size = m_coefficients.GetSize(); 194 int32_t size = m_coefficients.GetSize();
195 CFX_Int32Array product; 195 CFX_ArrayTemplate<int32_t> product;
196 product.SetSize(size + degree); 196 product.SetSize(size + degree);
197 for (int32_t i = 0; i < size; i++) { 197 for (int32_t i = 0; i < size; i++) {
198 product[i] = (m_field->Multiply(m_coefficients[i], coefficient)); 198 product[i] = (m_field->Multiply(m_coefficients[i], coefficient));
199 } 199 }
200 CBC_ReedSolomonGF256Poly* temp = new CBC_ReedSolomonGF256Poly(); 200 CBC_ReedSolomonGF256Poly* temp = new CBC_ReedSolomonGF256Poly();
201 temp->Init(m_field, &product, e); 201 temp->Init(m_field, &product, e);
202 BC_EXCEPTION_CHECK_ReturnValue(e, nullptr); 202 BC_EXCEPTION_CHECK_ReturnValue(e, nullptr);
203 return temp; 203 return temp;
204 } 204 }
205 205
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
238 CFX_ArrayTemplate<CBC_ReedSolomonGF256Poly*>* tempPtrA = 238 CFX_ArrayTemplate<CBC_ReedSolomonGF256Poly*>* tempPtrA =
239 new CFX_ArrayTemplate<CBC_ReedSolomonGF256Poly*>(); 239 new CFX_ArrayTemplate<CBC_ReedSolomonGF256Poly*>();
240 tempPtrA->Add(quotient.release()); 240 tempPtrA->Add(quotient.release());
241 tempPtrA->Add(remainder.release()); 241 tempPtrA->Add(remainder.release());
242 return tempPtrA; 242 return tempPtrA;
243 } 243 }
244 244
245 CBC_ReedSolomonGF256Poly::~CBC_ReedSolomonGF256Poly() { 245 CBC_ReedSolomonGF256Poly::~CBC_ReedSolomonGF256Poly() {
246 m_coefficients.RemoveAll(); 246 m_coefficients.RemoveAll();
247 } 247 }
OLDNEW
« no previous file with comments | « xfa/fxbarcode/common/reedsolomon/BC_ReedSolomonGF256Poly.h ('k') | xfa/fxbarcode/datamatrix/BC_DefaultPlacement.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698