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

Side by Side Diff: xfa/fxbarcode/qrcode/BC_QRCoderVersion.cpp

Issue 2048983002: Get rid of NULLs in xfa/fxbarcode/ (Closed) Base URL: https://pdfium.googlesource.com/pdfium@master
Patch Set: nits Created 4 years, 6 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
« no previous file with comments | « xfa/fxbarcode/qrcode/BC_QRCoderMode.cpp ('k') | xfa/fxbarcode/qrcode/BC_QRDataBlock.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 336 matching lines...) Expand 10 before | Expand all | Expand 10 after
347 } 347 }
348 CBC_QRCoderECBlocks* CBC_QRCoderVersion::GetECBlocksForLevel( 348 CBC_QRCoderECBlocks* CBC_QRCoderVersion::GetECBlocksForLevel(
349 CBC_QRCoderErrorCorrectionLevel* ecLevel) { 349 CBC_QRCoderErrorCorrectionLevel* ecLevel) {
350 return m_ecBlocksArray[ecLevel->Ordinal()]; 350 return m_ecBlocksArray[ecLevel->Ordinal()];
351 } 351 }
352 CBC_QRCoderVersion* CBC_QRCoderVersion::GetProvisionalVersionForDimension( 352 CBC_QRCoderVersion* CBC_QRCoderVersion::GetProvisionalVersionForDimension(
353 int32_t dimension, 353 int32_t dimension,
354 int32_t& e) { 354 int32_t& e) {
355 if ((dimension % 4) != 1) { 355 if ((dimension % 4) != 1) {
356 e = BCExceptionRead; 356 e = BCExceptionRead;
357 BC_EXCEPTION_CHECK_ReturnValue(e, NULL); 357 BC_EXCEPTION_CHECK_ReturnValue(e, nullptr);
358 } 358 }
359 CBC_QRCoderVersion* qcv = GetVersionForNumber((dimension - 17) >> 2, e); 359 CBC_QRCoderVersion* qcv = GetVersionForNumber((dimension - 17) >> 2, e);
360 BC_EXCEPTION_CHECK_ReturnValue(e, NULL); 360 BC_EXCEPTION_CHECK_ReturnValue(e, nullptr);
361 return qcv; 361 return qcv;
362 } 362 }
363 CBC_QRCoderVersion* CBC_QRCoderVersion::DecodeVersionInformation( 363 CBC_QRCoderVersion* CBC_QRCoderVersion::DecodeVersionInformation(
364 int32_t versionBits, 364 int32_t versionBits,
365 int32_t& e) { 365 int32_t& e) {
366 int32_t bestDifference = FXSYS_IntMax; 366 int32_t bestDifference = FXSYS_IntMax;
367 int32_t bestVersion = 0; 367 int32_t bestVersion = 0;
368 for (int32_t i = 0; i < 34; i++) { 368 for (int32_t i = 0; i < 34; i++) {
369 int32_t targetVersion = VERSION_DECODE_INFO[i]; 369 int32_t targetVersion = VERSION_DECODE_INFO[i];
370 if (targetVersion == versionBits) { 370 if (targetVersion == versionBits) {
371 CBC_QRCoderVersion* qcv = GetVersionForNumber(i + 7, e); 371 CBC_QRCoderVersion* qcv = GetVersionForNumber(i + 7, e);
372 BC_EXCEPTION_CHECK_ReturnValue(e, NULL); 372 BC_EXCEPTION_CHECK_ReturnValue(e, nullptr);
373 return qcv; 373 return qcv;
374 } 374 }
375 int32_t bitsDifference = CBC_QRCoderFormatInformation::NumBitsDiffering( 375 int32_t bitsDifference = CBC_QRCoderFormatInformation::NumBitsDiffering(
376 versionBits, targetVersion); 376 versionBits, targetVersion);
377 if (bitsDifference < bestDifference) { 377 if (bitsDifference < bestDifference) {
378 bestVersion = i + 7; 378 bestVersion = i + 7;
379 bestDifference = bitsDifference; 379 bestDifference = bitsDifference;
380 } 380 }
381 } 381 }
382 if (bestDifference <= 3) { 382 if (bestDifference <= 3) {
383 CBC_QRCoderVersion* qcv = GetVersionForNumber(bestVersion, e); 383 CBC_QRCoderVersion* qcv = GetVersionForNumber(bestVersion, e);
384 BC_EXCEPTION_CHECK_ReturnValue(e, NULL); 384 BC_EXCEPTION_CHECK_ReturnValue(e, nullptr);
385 return qcv; 385 return qcv;
386 } 386 }
387 return NULL; 387 return nullptr;
388 } 388 }
389 CBC_CommonBitMatrix* CBC_QRCoderVersion::BuildFunctionPattern(int32_t& e) { 389 CBC_CommonBitMatrix* CBC_QRCoderVersion::BuildFunctionPattern(int32_t& e) {
390 int32_t dimension = GetDimensionForVersion(); 390 int32_t dimension = GetDimensionForVersion();
391 CBC_CommonBitMatrix* bitMatrix = new CBC_CommonBitMatrix(); 391 CBC_CommonBitMatrix* bitMatrix = new CBC_CommonBitMatrix();
392 bitMatrix->Init(dimension); 392 bitMatrix->Init(dimension);
393 bitMatrix->SetRegion(0, 0, 9, 9, e); 393 bitMatrix->SetRegion(0, 0, 9, 9, e);
394 BC_EXCEPTION_CHECK_ReturnValue(e, NULL); 394 BC_EXCEPTION_CHECK_ReturnValue(e, nullptr);
395 bitMatrix->SetRegion(dimension - 8, 0, 8, 9, e); 395 bitMatrix->SetRegion(dimension - 8, 0, 8, 9, e);
396 BC_EXCEPTION_CHECK_ReturnValue(e, NULL); 396 BC_EXCEPTION_CHECK_ReturnValue(e, nullptr);
397 bitMatrix->SetRegion(0, dimension - 8, 9, 8, e); 397 bitMatrix->SetRegion(0, dimension - 8, 9, 8, e);
398 BC_EXCEPTION_CHECK_ReturnValue(e, NULL); 398 BC_EXCEPTION_CHECK_ReturnValue(e, nullptr);
399 int32_t max = m_alignmentPatternCenters.GetSize(); 399 int32_t max = m_alignmentPatternCenters.GetSize();
400 for (int32_t x = 0; x < max; x++) { 400 for (int32_t x = 0; x < max; x++) {
401 int32_t i = m_alignmentPatternCenters[x] - 2; 401 int32_t i = m_alignmentPatternCenters[x] - 2;
402 for (int32_t y = 0; y < max; y++) { 402 for (int32_t y = 0; y < max; y++) {
403 if ((x == 0 && (y == 0 || y == max - 1)) || (x == max - 1 && y == 0)) { 403 if ((x == 0 && (y == 0 || y == max - 1)) || (x == max - 1 && y == 0)) {
404 continue; 404 continue;
405 } 405 }
406 bitMatrix->SetRegion(m_alignmentPatternCenters[y] - 2, i, 5, 5, e); 406 bitMatrix->SetRegion(m_alignmentPatternCenters[y] - 2, i, 5, 5, e);
407 BC_EXCEPTION_CHECK_ReturnValue(e, NULL); 407 BC_EXCEPTION_CHECK_ReturnValue(e, nullptr);
408 } 408 }
409 } 409 }
410 bitMatrix->SetRegion(6, 9, 1, dimension - 17, e); 410 bitMatrix->SetRegion(6, 9, 1, dimension - 17, e);
411 BC_EXCEPTION_CHECK_ReturnValue(e, NULL); 411 BC_EXCEPTION_CHECK_ReturnValue(e, nullptr);
412 bitMatrix->SetRegion(9, 6, dimension - 17, 1, e); 412 bitMatrix->SetRegion(9, 6, dimension - 17, 1, e);
413 BC_EXCEPTION_CHECK_ReturnValue(e, NULL); 413 BC_EXCEPTION_CHECK_ReturnValue(e, nullptr);
414 if (m_versionNumber > 6) { 414 if (m_versionNumber > 6) {
415 bitMatrix->SetRegion(dimension - 11, 0, 3, 6, e); 415 bitMatrix->SetRegion(dimension - 11, 0, 3, 6, e);
416 BC_EXCEPTION_CHECK_ReturnValue(e, NULL); 416 BC_EXCEPTION_CHECK_ReturnValue(e, nullptr);
417 bitMatrix->SetRegion(0, dimension - 11, 6, 3, e); 417 bitMatrix->SetRegion(0, dimension - 11, 6, 3, e);
418 BC_EXCEPTION_CHECK_ReturnValue(e, NULL); 418 BC_EXCEPTION_CHECK_ReturnValue(e, nullptr);
419 } 419 }
420 return bitMatrix; 420 return bitMatrix;
421 } 421 }
422 CBC_QRCoderVersion* CBC_QRCoderVersion::GetVersionForNumber( 422 CBC_QRCoderVersion* CBC_QRCoderVersion::GetVersionForNumber(
423 int32_t versionNumber, 423 int32_t versionNumber,
424 int32_t& e) { 424 int32_t& e) {
425 if (VERSION->GetSize() == 0) { 425 if (VERSION->GetSize() == 0) {
426 VERSION->Add(new CBC_QRCoderVersion( 426 VERSION->Add(new CBC_QRCoderVersion(
427 1, new CBC_QRCoderECBlocks(7, new CBC_QRCoderECB(1, 19)), 427 1, new CBC_QRCoderECBlocks(7, new CBC_QRCoderECB(1, 19)),
428 new CBC_QRCoderECBlocks(10, new CBC_QRCoderECB(1, 16)), 428 new CBC_QRCoderECBlocks(10, new CBC_QRCoderECB(1, 16)),
(...skipping 318 matching lines...) Expand 10 before | Expand all | Expand 10 after
747 new CBC_QRCoderECB(6, 119)), 747 new CBC_QRCoderECB(6, 119)),
748 new CBC_QRCoderECBlocks(28, new CBC_QRCoderECB(18, 47), 748 new CBC_QRCoderECBlocks(28, new CBC_QRCoderECB(18, 47),
749 new CBC_QRCoderECB(31, 48)), 749 new CBC_QRCoderECB(31, 48)),
750 new CBC_QRCoderECBlocks(30, new CBC_QRCoderECB(34, 24), 750 new CBC_QRCoderECBlocks(30, new CBC_QRCoderECB(34, 24),
751 new CBC_QRCoderECB(34, 25)), 751 new CBC_QRCoderECB(34, 25)),
752 new CBC_QRCoderECBlocks(30, new CBC_QRCoderECB(20, 15), 752 new CBC_QRCoderECBlocks(30, new CBC_QRCoderECB(20, 15),
753 new CBC_QRCoderECB(61, 16)))); 753 new CBC_QRCoderECB(61, 16))));
754 } 754 }
755 if (versionNumber < 1 || versionNumber > 40) { 755 if (versionNumber < 1 || versionNumber > 40) {
756 e = BCExceptionIllegalArgument; 756 e = BCExceptionIllegalArgument;
757 BC_EXCEPTION_CHECK_ReturnValue(e, NULL); 757 BC_EXCEPTION_CHECK_ReturnValue(e, nullptr);
758 } 758 }
759 return (*VERSION)[versionNumber - 1]; 759 return (*VERSION)[versionNumber - 1];
760 } 760 }
761 761
762 void CBC_QRCoderVersion::Destroy() { 762 void CBC_QRCoderVersion::Destroy() {
763 for (int32_t i = 0; i < VERSION->GetSize(); i++) 763 for (int32_t i = 0; i < VERSION->GetSize(); i++)
764 delete (*VERSION)[i]; 764 delete (*VERSION)[i];
765 VERSION->RemoveAll(); 765 VERSION->RemoveAll();
766 } 766 }
OLDNEW
« no previous file with comments | « xfa/fxbarcode/qrcode/BC_QRCoderMode.cpp ('k') | xfa/fxbarcode/qrcode/BC_QRDataBlock.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698