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

Side by Side Diff: xfa/fxbarcode/pdf417/BC_PDF417ECModulusPoly.cpp

Issue 1936733002: Replace CFX_PtrArray with typesafe CFX_ArrayTemplate, part 10 (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: Nits Created 4 years, 7 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 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 <memory>
24
23 #include "xfa/fxbarcode/pdf417/BC_PDF417Common.h" 25 #include "xfa/fxbarcode/pdf417/BC_PDF417Common.h"
24 #include "xfa/fxbarcode/pdf417/BC_PDF417ECModulusGF.h" 26 #include "xfa/fxbarcode/pdf417/BC_PDF417ECModulusGF.h"
25 #include "xfa/fxbarcode/pdf417/BC_PDF417ECModulusPoly.h" 27 #include "xfa/fxbarcode/pdf417/BC_PDF417ECModulusPoly.h"
26 #include "xfa/fxbarcode/utils.h" 28 #include "xfa/fxbarcode/utils.h"
27 29
28 CBC_PDF417ECModulusPoly::CBC_PDF417ECModulusPoly(CBC_PDF417ECModulusGF* field, 30 CBC_PDF417ECModulusPoly::CBC_PDF417ECModulusPoly(CBC_PDF417ECModulusGF* field,
29 CFX_Int32Array& coefficients, 31 CFX_Int32Array& coefficients,
30 int32_t& e) { 32 int32_t& e) {
31 if (coefficients.GetSize() == 0) { 33 if (coefficients.GetSize() == 0) {
32 e = BCExceptionIllegalArgument; 34 e = BCExceptionIllegalArgument;
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after
205 int32_t size = m_coefficients.GetSize(); 207 int32_t size = m_coefficients.GetSize();
206 CFX_Int32Array product; 208 CFX_Int32Array product;
207 product.SetSize(size); 209 product.SetSize(size);
208 for (int32_t i = 0; i < size; i++) { 210 for (int32_t i = 0; i < size; i++) {
209 product[i] = m_field->multiply(m_coefficients[i], scalar); 211 product[i] = m_field->multiply(m_coefficients[i], scalar);
210 } 212 }
211 modulusPoly = new CBC_PDF417ECModulusPoly(m_field, product, e); 213 modulusPoly = new CBC_PDF417ECModulusPoly(m_field, product, e);
212 BC_EXCEPTION_CHECK_ReturnValue(e, NULL); 214 BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
213 return modulusPoly; 215 return modulusPoly;
214 } 216 }
217
215 CBC_PDF417ECModulusPoly* CBC_PDF417ECModulusPoly::multiplyByMonomial( 218 CBC_PDF417ECModulusPoly* CBC_PDF417ECModulusPoly::multiplyByMonomial(
216 int32_t degree, 219 int32_t degree,
217 int32_t coefficient, 220 int32_t coefficient,
218 int32_t& e) { 221 int32_t& e) {
219 if (degree < 0) { 222 if (degree < 0) {
220 e = BCExceptionIllegalArgument; 223 e = BCExceptionIllegalArgument;
221 return NULL; 224 return nullptr;
222 } 225 }
223 CBC_PDF417ECModulusPoly* modulusPoly = NULL; 226 CBC_PDF417ECModulusPoly* modulusPoly = nullptr;
224 if (coefficient == 0) { 227 if (coefficient == 0) {
225 modulusPoly = new CBC_PDF417ECModulusPoly( 228 modulusPoly = new CBC_PDF417ECModulusPoly(
226 m_field->getZero()->m_field, m_field->getZero()->m_coefficients, e); 229 m_field->getZero()->m_field, m_field->getZero()->m_coefficients, e);
227 BC_EXCEPTION_CHECK_ReturnValue(e, NULL); 230 BC_EXCEPTION_CHECK_ReturnValue(e, nullptr);
228 return modulusPoly; 231 return modulusPoly;
229 } 232 }
230 int32_t size = m_coefficients.GetSize(); 233 int32_t size = m_coefficients.GetSize();
231 CFX_Int32Array product; 234 CFX_Int32Array product;
232 product.SetSize(size + degree); 235 product.SetSize(size + degree);
233 for (int32_t i = 0; i < size; i++) { 236 for (int32_t i = 0; i < size; i++) {
234 product[i] = m_field->multiply(m_coefficients[i], coefficient); 237 product[i] = m_field->multiply(m_coefficients[i], coefficient);
235 } 238 }
236 modulusPoly = new CBC_PDF417ECModulusPoly(m_field, product, e); 239 modulusPoly = new CBC_PDF417ECModulusPoly(m_field, product, e);
237 BC_EXCEPTION_CHECK_ReturnValue(e, NULL); 240 BC_EXCEPTION_CHECK_ReturnValue(e, nullptr);
238 return modulusPoly; 241 return modulusPoly;
239 } 242 }
240 CFX_PtrArray* CBC_PDF417ECModulusPoly::divide(CBC_PDF417ECModulusPoly* other, 243
241 int32_t& e) { 244 CFX_ArrayTemplate<CBC_PDF417ECModulusPoly*>* CBC_PDF417ECModulusPoly::divide(
245 CBC_PDF417ECModulusPoly* other,
246 int32_t& e) {
242 if (other->isZero()) { 247 if (other->isZero()) {
243 e = BCExceptionDivideByZero; 248 e = BCExceptionDivideByZero;
244 return NULL; 249 return nullptr;
245 } 250 }
246 CBC_PDF417ECModulusPoly* quotient = new CBC_PDF417ECModulusPoly( 251 std::unique_ptr<CBC_PDF417ECModulusPoly> quotient(new CBC_PDF417ECModulusPoly(
247 m_field->getZero()->m_field, m_field->getZero()->m_coefficients, e); 252 m_field->getZero()->m_field, m_field->getZero()->m_coefficients, e));
248 BC_EXCEPTION_CHECK_ReturnValue(e, NULL); 253 BC_EXCEPTION_CHECK_ReturnValue(e, nullptr);
249 CBC_PDF417ECModulusPoly* remainder = 254 std::unique_ptr<CBC_PDF417ECModulusPoly> remainder(
250 new CBC_PDF417ECModulusPoly(m_field, m_coefficients, e); 255 new CBC_PDF417ECModulusPoly(m_field, m_coefficients, e));
251 if (e != BCExceptionNO) { 256 if (e != BCExceptionNO)
252 delete quotient; 257 return nullptr;
253 return NULL; 258
254 }
255 int32_t denominatorLeadingTerm = other->getCoefficient(other->getDegree()); 259 int32_t denominatorLeadingTerm = other->getCoefficient(other->getDegree());
256 int32_t inverseDenominatorLeadingTerm = 260 int32_t inverseDenominatorLeadingTerm =
257 m_field->inverse(denominatorLeadingTerm, e); 261 m_field->inverse(denominatorLeadingTerm, e);
258 if (e != BCExceptionNO) { 262 if (e != BCExceptionNO)
259 delete quotient; 263 return nullptr;
260 delete remainder; 264
261 return NULL;
262 }
263 while (remainder->getDegree() >= other->getDegree() && !remainder->isZero()) { 265 while (remainder->getDegree() >= other->getDegree() && !remainder->isZero()) {
264 int32_t degreeDifference = remainder->getDegree() - other->getDegree(); 266 int32_t degreeDifference = remainder->getDegree() - other->getDegree();
265 int32_t scale = 267 int32_t scale =
266 m_field->multiply(remainder->getCoefficient(remainder->getDegree()), 268 m_field->multiply(remainder->getCoefficient(remainder->getDegree()),
267 inverseDenominatorLeadingTerm); 269 inverseDenominatorLeadingTerm);
268 CBC_PDF417ECModulusPoly* term = 270 std::unique_ptr<CBC_PDF417ECModulusPoly> term(
269 other->multiplyByMonomial(degreeDifference, scale, e); 271 other->multiplyByMonomial(degreeDifference, scale, e));
270 if (e != BCExceptionNO) { 272 if (e != BCExceptionNO)
271 delete quotient; 273 return nullptr;
272 delete remainder; 274
273 return NULL; 275 std::unique_ptr<CBC_PDF417ECModulusPoly> iterationQuotient(
274 } 276 m_field->buildMonomial(degreeDifference, scale, e));
275 CBC_PDF417ECModulusPoly* iterationQuotient = 277 if (e != BCExceptionNO)
276 m_field->buildMonomial(degreeDifference, scale, e); 278 return nullptr;
277 if (e != BCExceptionNO) { 279
278 delete quotient; 280 quotient.reset(quotient->add(iterationQuotient.get(), e));
279 delete remainder; 281 if (e != BCExceptionNO)
280 delete term; 282 return nullptr;
281 return NULL; 283
282 } 284 remainder.reset(remainder->subtract(term.get(), e));
283 CBC_PDF417ECModulusPoly* temp = quotient; 285 if (e != BCExceptionNO)
284 quotient = temp->add(iterationQuotient, e); 286 return nullptr;
285 delete iterationQuotient;
286 delete temp;
287 if (e != BCExceptionNO) {
288 delete remainder;
289 return NULL;
290 }
291 temp = remainder;
292 remainder = temp->subtract(term, e);
293 delete term;
294 delete temp;
295 if (e != BCExceptionNO) {
296 delete quotient;
297 return NULL;
298 }
299 } 287 }
300 CFX_PtrArray* modulusPoly = new CFX_PtrArray; 288
301 modulusPoly->Add(quotient); 289 CFX_ArrayTemplate<CBC_PDF417ECModulusPoly*>* modulusPoly =
302 modulusPoly->Add(remainder); 290 new CFX_ArrayTemplate<CBC_PDF417ECModulusPoly*>();
291 modulusPoly->Add(quotient.release());
292 modulusPoly->Add(remainder.release());
303 return modulusPoly; 293 return modulusPoly;
304 } 294 }
295
305 CFX_ByteString CBC_PDF417ECModulusPoly::toString() { 296 CFX_ByteString CBC_PDF417ECModulusPoly::toString() {
306 CFX_ByteString result; 297 CFX_ByteString result;
307 for (int32_t degree = getDegree(); degree >= 0; degree--) { 298 for (int32_t degree = getDegree(); degree >= 0; degree--) {
308 int32_t coefficient = getCoefficient(degree); 299 int32_t coefficient = getCoefficient(degree);
309 if (coefficient != 0) { 300 if (coefficient != 0) {
310 if (coefficient < 0) { 301 if (coefficient < 0) {
311 result += " - "; 302 result += " - ";
312 coefficient = -coefficient; 303 coefficient = -coefficient;
313 } else { 304 } else {
314 if (result.GetLength() > 0) { 305 if (result.GetLength() > 0) {
315 result += " + "; 306 result += " + ";
316 } 307 }
317 } 308 }
318 if (degree == 0 || coefficient != 1) { 309 if (degree == 0 || coefficient != 1) {
319 result += coefficient; 310 result += coefficient;
320 } 311 }
321 if (degree != 0) { 312 if (degree != 0) {
322 if (degree == 1) { 313 if (degree == 1) {
323 result += 'x'; 314 result += 'x';
324 } else { 315 } else {
325 result += "x^"; 316 result += "x^";
326 result += degree; 317 result += degree;
327 } 318 }
328 } 319 }
329 } 320 }
330 } 321 }
331 return result; 322 return result;
332 } 323 }
OLDNEW
« no previous file with comments | « xfa/fxbarcode/pdf417/BC_PDF417ECModulusPoly.h ('k') | xfa/fxbarcode/qrcode/BC_QRBitMatrixParser.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698