summaryrefslogtreecommitdiff
path: root/fxbarcode/pdf417/BC_PDF417ErrorCorrection.cpp
diff options
context:
space:
mode:
authorLei Zhang <thestig@chromium.org>2017-04-27 23:58:03 -0700
committerChromium commit bot <commit-bot@chromium.org>2017-04-28 19:12:30 +0000
commit60cd033adf6c469ff47bdaf85a66b5817fdd188b (patch)
treea91b3cee7aaeb0dc650fd857bfd3476da848eacf /fxbarcode/pdf417/BC_PDF417ErrorCorrection.cpp
parent7831f57f04ad3f581222b0a23eeb736601f98e96 (diff)
downloadpdfium-60cd033adf6c469ff47bdaf85a66b5817fdd188b.tar.xz
Remove dead dimensions code in fxbarcode.chromium/3084
Remove more exceptions. Change-Id: I3b8b8b9837b0010b1e0060ddd56e93c78f9f0fb5 Reviewed-on: https://pdfium-review.googlesource.com/4410 Reviewed-by: Tom Sepez <tsepez@chromium.org> Commit-Queue: Lei Zhang <thestig@chromium.org>
Diffstat (limited to 'fxbarcode/pdf417/BC_PDF417ErrorCorrection.cpp')
-rw-r--r--fxbarcode/pdf417/BC_PDF417ErrorCorrection.cpp64
1 files changed, 20 insertions, 44 deletions
diff --git a/fxbarcode/pdf417/BC_PDF417ErrorCorrection.cpp b/fxbarcode/pdf417/BC_PDF417ErrorCorrection.cpp
index abdd113911..6f1d7946eb 100644
--- a/fxbarcode/pdf417/BC_PDF417ErrorCorrection.cpp
+++ b/fxbarcode/pdf417/BC_PDF417ErrorCorrection.cpp
@@ -21,7 +21,8 @@
*/
#include "fxbarcode/pdf417/BC_PDF417ErrorCorrection.h"
-#include "fxbarcode/utils.h"
+
+#include <vector>
namespace {
@@ -124,47 +125,24 @@ const uint16_t* const EC_COEFFICIENTS[9] = {
CBC_PDF417ErrorCorrection::CBC_PDF417ErrorCorrection() {}
CBC_PDF417ErrorCorrection::~CBC_PDF417ErrorCorrection() {}
int32_t CBC_PDF417ErrorCorrection::getErrorCorrectionCodewordCount(
- int32_t errorCorrectionLevel,
- int32_t& e) {
- if (errorCorrectionLevel < 0 || errorCorrectionLevel > 8) {
- e = BCExceptionErrorCorrectionLevelMustBeBetween0And8;
+ int32_t errorCorrectionLevel) {
+ if (errorCorrectionLevel < 0 || errorCorrectionLevel > 8)
return -1;
- }
return 1 << (errorCorrectionLevel + 1);
}
-int32_t CBC_PDF417ErrorCorrection::getRecommendedMinimumErrorCorrectionLevel(
- int32_t n,
- int32_t& e) {
- if (n <= 0) {
- e = BCExceptionIllegalArgumentnMustBeAbove0;
- return -1;
- }
- if (n <= 40) {
- return 2;
- }
- if (n <= 160) {
- return 3;
- }
- if (n <= 320) {
- return 4;
- }
- if (n <= 863) {
- return 5;
- }
- e = BCExceptionNoRecommendationPossible;
- return -1;
-}
-
-CFX_WideString CBC_PDF417ErrorCorrection::generateErrorCorrection(
- CFX_WideString dataCodewords,
+bool CBC_PDF417ErrorCorrection::generateErrorCorrection(
+ const CFX_WideString& dataCodewords,
int32_t errorCorrectionLevel,
- int32_t& e) {
- int32_t k = getErrorCorrectionCodewordCount(errorCorrectionLevel, e);
- if (e != BCExceptionNO)
- return L" ";
- wchar_t* ech = FX_Alloc(wchar_t, k);
- memset(ech, 0, k * sizeof(wchar_t));
+ CFX_WideString* result) {
+ assert(result);
+ assert(result->IsEmpty());
+
+ int32_t k = getErrorCorrectionCodewordCount(errorCorrectionLevel);
+ if (k < 0)
+ return false;
+
+ std::vector<wchar_t> ech(k);
int32_t sld = dataCodewords.GetLength();
for (int32_t i = 0; i < sld; i++) {
int32_t t1 = (dataCodewords.GetAt(i) + ech[k - 1]) % 929;
@@ -179,13 +157,11 @@ CFX_WideString CBC_PDF417ErrorCorrection::generateErrorCorrection(
t3 = 929 - t2;
ech[0] = (wchar_t)(t3 % 929);
}
- CFX_WideString sb;
+ result->Reserve(k);
for (int32_t j = k - 1; j >= 0; j--) {
- if (ech[j] != 0) {
- ech[j] = (wchar_t)(929 - ech[j]);
- }
- sb += (wchar_t)ech[j];
+ if (ech[j] != 0)
+ ech[j] = static_cast<wchar_t>(929) - ech[j];
+ *result += ech[j];
}
- FX_Free(ech);
- return sb;
+ return true;
}