summaryrefslogtreecommitdiff
path: root/xfa/src/fxbarcode/oned/BC_OneDReader.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'xfa/src/fxbarcode/oned/BC_OneDReader.cpp')
-rw-r--r--xfa/src/fxbarcode/oned/BC_OneDReader.cpp279
1 files changed, 143 insertions, 136 deletions
diff --git a/xfa/src/fxbarcode/oned/BC_OneDReader.cpp b/xfa/src/fxbarcode/oned/BC_OneDReader.cpp
index 810b2c70c7..2338d0d086 100644
--- a/xfa/src/fxbarcode/oned/BC_OneDReader.cpp
+++ b/xfa/src/fxbarcode/oned/BC_OneDReader.cpp
@@ -27,153 +27,160 @@
#include "BC_OneDReader.h"
const int32_t CBC_OneDReader::INTEGER_MATH_SHIFT = 8;
const int32_t CBC_OneDReader::PATTERN_MATCH_RESULT_SCALE_FACTOR = 1 << 8;
-CBC_OneDReader::CBC_OneDReader()
-{
+CBC_OneDReader::CBC_OneDReader() {}
+CBC_OneDReader::~CBC_OneDReader() {}
+CFX_ByteString CBC_OneDReader::Decode(CBC_BinaryBitmap* image, int32_t& e) {
+ CFX_ByteString strtemp = Decode(image, 0, e);
+ BC_EXCEPTION_CHECK_ReturnValue(e, "");
+ return strtemp;
}
-CBC_OneDReader::~CBC_OneDReader()
-{
+CFX_ByteString CBC_OneDReader::Decode(CBC_BinaryBitmap* image,
+ int32_t hints,
+ int32_t& e) {
+ CFX_ByteString strtemp = DeDecode(image, hints, e);
+ BC_EXCEPTION_CHECK_ReturnValue(e, "");
+ return strtemp;
}
-CFX_ByteString CBC_OneDReader::Decode(CBC_BinaryBitmap *image, int32_t &e)
-{
- CFX_ByteString strtemp = Decode(image, 0, e);
- BC_EXCEPTION_CHECK_ReturnValue(e, "");
- return strtemp;
-}
-CFX_ByteString CBC_OneDReader::Decode(CBC_BinaryBitmap *image, int32_t hints, int32_t &e)
-{
- CFX_ByteString strtemp = DeDecode(image, hints, e);
- BC_EXCEPTION_CHECK_ReturnValue(e, "");
- return strtemp;
-}
-CFX_ByteString CBC_OneDReader::DeDecode(CBC_BinaryBitmap *image, int32_t hints, int32_t &e)
-{
- int32_t width = image->GetWidth();
- int32_t height = image->GetHeight();
- CBC_CommonBitArray *row = NULL;
- int32_t middle = height >> 1;
- FX_BOOL tryHarder = FALSE;
- int32_t rowStep = FX_MAX(1, height >> (tryHarder ? 8 : 5));
- int32_t maxLines;
- if (tryHarder) {
- maxLines = height;
- } else {
- maxLines = 15;
- }
- for (int32_t x = 0; x < maxLines; x++) {
- int32_t rowStepsAboveOrBelow = (x + 1) >> 1;
- FX_BOOL isAbove = (x & 0x01) == 0;
- int32_t rowNumber = middle + rowStep * (isAbove ? rowStepsAboveOrBelow : -rowStepsAboveOrBelow);
- if (rowNumber < 0 || rowNumber >= height) {
- break;
- }
- row = image->GetBlackRow(rowNumber, NULL, e);
- if (e != BCExceptionNO) {
- e = BCExceptionNO;
- if(row != NULL) {
- delete row;
- row = NULL;
- }
- continue;
- }
- for (int32_t attempt = 0; attempt < 2; attempt++) {
- if (attempt == 1) {
- row->Reverse();
- }
- CFX_ByteString result = DecodeRow(rowNumber, row, hints, e);
- if (e != BCExceptionNO) {
- e = BCExceptionNO;
- continue;
- }
- if(row != NULL) {
- delete row;
- row = NULL;
- }
- return result;
- }
- if(row != NULL) {
- delete row;
- row = NULL;
- }
- }
- e = BCExceptionNotFound;
- return "";
-}
-void CBC_OneDReader::RecordPattern(CBC_CommonBitArray *row, int32_t start, CFX_Int32Array *counters, int32_t &e)
-{
- int32_t numCounters = counters->GetSize();
- for (int32_t i = 0; i < numCounters; i++) {
- (*counters)[i] = 0;
+CFX_ByteString CBC_OneDReader::DeDecode(CBC_BinaryBitmap* image,
+ int32_t hints,
+ int32_t& e) {
+ int32_t width = image->GetWidth();
+ int32_t height = image->GetHeight();
+ CBC_CommonBitArray* row = NULL;
+ int32_t middle = height >> 1;
+ FX_BOOL tryHarder = FALSE;
+ int32_t rowStep = FX_MAX(1, height >> (tryHarder ? 8 : 5));
+ int32_t maxLines;
+ if (tryHarder) {
+ maxLines = height;
+ } else {
+ maxLines = 15;
+ }
+ for (int32_t x = 0; x < maxLines; x++) {
+ int32_t rowStepsAboveOrBelow = (x + 1) >> 1;
+ FX_BOOL isAbove = (x & 0x01) == 0;
+ int32_t rowNumber =
+ middle +
+ rowStep * (isAbove ? rowStepsAboveOrBelow : -rowStepsAboveOrBelow);
+ if (rowNumber < 0 || rowNumber >= height) {
+ break;
}
- int32_t end = row->GetSize();
- if (start >= end) {
- e = BCExceptionNotFound;
- return;
+ row = image->GetBlackRow(rowNumber, NULL, e);
+ if (e != BCExceptionNO) {
+ e = BCExceptionNO;
+ if (row != NULL) {
+ delete row;
+ row = NULL;
+ }
+ continue;
}
- FX_BOOL isWhite = !row->Get(start);
- int32_t counterPosition = 0;
- int32_t j = start;
- while (j < end) {
- FX_BOOL pixel = row->Get(j);
- if (pixel ^ isWhite) {
- (*counters)[counterPosition]++;
- } else {
- counterPosition++;
- if (counterPosition == numCounters) {
- break;
- } else {
- (*counters)[counterPosition] = 1;
- isWhite = !isWhite;
- }
- }
- j++;
+ for (int32_t attempt = 0; attempt < 2; attempt++) {
+ if (attempt == 1) {
+ row->Reverse();
+ }
+ CFX_ByteString result = DecodeRow(rowNumber, row, hints, e);
+ if (e != BCExceptionNO) {
+ e = BCExceptionNO;
+ continue;
+ }
+ if (row != NULL) {
+ delete row;
+ row = NULL;
+ }
+ return result;
}
- if (!(counterPosition == numCounters || (counterPosition == numCounters - 1 && j == end))) {
- e = BCExceptionNotFound;
- return;
+ if (row != NULL) {
+ delete row;
+ row = NULL;
}
+ }
+ e = BCExceptionNotFound;
+ return "";
}
-void CBC_OneDReader::RecordPatternInReverse(CBC_CommonBitArray *row, int32_t start, CFX_Int32Array *counters, int32_t &e)
-{
- int32_t numTransitionsLeft = counters->GetSize();
- FX_BOOL last = row->Get(start);
- while (start > 0 && numTransitionsLeft >= 0) {
- if (row->Get(--start) != last) {
- numTransitionsLeft--;
- last = !last;
- }
- }
- if (numTransitionsLeft >= 0) {
- e = BCExceptionNotFound;
- return;
+void CBC_OneDReader::RecordPattern(CBC_CommonBitArray* row,
+ int32_t start,
+ CFX_Int32Array* counters,
+ int32_t& e) {
+ int32_t numCounters = counters->GetSize();
+ for (int32_t i = 0; i < numCounters; i++) {
+ (*counters)[i] = 0;
+ }
+ int32_t end = row->GetSize();
+ if (start >= end) {
+ e = BCExceptionNotFound;
+ return;
+ }
+ FX_BOOL isWhite = !row->Get(start);
+ int32_t counterPosition = 0;
+ int32_t j = start;
+ while (j < end) {
+ FX_BOOL pixel = row->Get(j);
+ if (pixel ^ isWhite) {
+ (*counters)[counterPosition]++;
+ } else {
+ counterPosition++;
+ if (counterPosition == numCounters) {
+ break;
+ } else {
+ (*counters)[counterPosition] = 1;
+ isWhite = !isWhite;
+ }
}
- RecordPattern(row, start + 1, counters, e);
- BC_EXCEPTION_CHECK_ReturnVoid(e);
+ j++;
+ }
+ if (!(counterPosition == numCounters ||
+ (counterPosition == numCounters - 1 && j == end))) {
+ e = BCExceptionNotFound;
+ return;
+ }
}
-int32_t CBC_OneDReader::PatternMatchVariance(CFX_Int32Array *counters, const int32_t *pattern, int32_t maxIndividualVariance)
-{
- int32_t numCounters = counters->GetSize();
- int32_t total = 0;
- int32_t patternLength = 0;
- for (int32_t i = 0; i < numCounters; i++) {
- total += (*counters)[i];
- patternLength += pattern[i];
+void CBC_OneDReader::RecordPatternInReverse(CBC_CommonBitArray* row,
+ int32_t start,
+ CFX_Int32Array* counters,
+ int32_t& e) {
+ int32_t numTransitionsLeft = counters->GetSize();
+ FX_BOOL last = row->Get(start);
+ while (start > 0 && numTransitionsLeft >= 0) {
+ if (row->Get(--start) != last) {
+ numTransitionsLeft--;
+ last = !last;
}
- if (total < patternLength) {
+ }
+ if (numTransitionsLeft >= 0) {
+ e = BCExceptionNotFound;
+ return;
+ }
+ RecordPattern(row, start + 1, counters, e);
+ BC_EXCEPTION_CHECK_ReturnVoid(e);
+}
+int32_t CBC_OneDReader::PatternMatchVariance(CFX_Int32Array* counters,
+ const int32_t* pattern,
+ int32_t maxIndividualVariance) {
+ int32_t numCounters = counters->GetSize();
+ int32_t total = 0;
+ int32_t patternLength = 0;
+ for (int32_t i = 0; i < numCounters; i++) {
+ total += (*counters)[i];
+ patternLength += pattern[i];
+ }
+ if (total < patternLength) {
#undef max
- return FXSYS_IntMax;
- }
- int32_t unitBarWidth = (total << INTEGER_MATH_SHIFT) / patternLength;
- maxIndividualVariance = (maxIndividualVariance * unitBarWidth) >> INTEGER_MATH_SHIFT;
- int32_t totalVariance = 0;
- for (int32_t x = 0; x < numCounters; x++) {
- int32_t counter = (*counters)[x] << INTEGER_MATH_SHIFT;
- int32_t scaledPattern = pattern[x] * unitBarWidth;
- int32_t variance = counter > scaledPattern ? counter - scaledPattern : scaledPattern - counter;
- if (variance > maxIndividualVariance) {
+ return FXSYS_IntMax;
+ }
+ int32_t unitBarWidth = (total << INTEGER_MATH_SHIFT) / patternLength;
+ maxIndividualVariance =
+ (maxIndividualVariance * unitBarWidth) >> INTEGER_MATH_SHIFT;
+ int32_t totalVariance = 0;
+ for (int32_t x = 0; x < numCounters; x++) {
+ int32_t counter = (*counters)[x] << INTEGER_MATH_SHIFT;
+ int32_t scaledPattern = pattern[x] * unitBarWidth;
+ int32_t variance = counter > scaledPattern ? counter - scaledPattern
+ : scaledPattern - counter;
+ if (variance > maxIndividualVariance) {
#undef max
- return FXSYS_IntMax;
- }
- totalVariance += variance;
+ return FXSYS_IntMax;
}
- return totalVariance / total;
+ totalVariance += variance;
+ }
+ return totalVariance / total;
}