mirror of
https://github.com/zxing/zxing.git
synced 2025-02-02 05:41:08 -08:00
Changed OneDReader::recordPattern to not throw exceptions. For now it just
moves them up a level to the callers. git-svn-id: https://zxing.googlecode.com/svn/trunk@1531 59b500cc-1b3d-0410-9834-0bbf25fbcc57
This commit is contained in:
parent
d096810e67
commit
2476762007
|
@ -205,8 +205,10 @@ namespace zxing {
|
||||||
}
|
}
|
||||||
|
|
||||||
int Code128Reader::decodeCode(Ref<BitArray> row, int counters[], int countersCount,
|
int Code128Reader::decodeCode(Ref<BitArray> row, int counters[], int countersCount,
|
||||||
int rowOffset){
|
int rowOffset) {
|
||||||
recordPattern(row, rowOffset, counters, countersCount);
|
if (!recordPattern(row, rowOffset, counters, countersCount)) {
|
||||||
|
throw ReaderException("");
|
||||||
|
}
|
||||||
unsigned int bestVariance = MAX_AVG_VARIANCE; // worst variance we'll accept
|
unsigned int bestVariance = MAX_AVG_VARIANCE; // worst variance we'll accept
|
||||||
int bestMatch = -1;
|
int bestMatch = -1;
|
||||||
for (int d = 0; d < CODE_PATTERNS_LENGTH; d++) {
|
for (int d = 0; d < CODE_PATTERNS_LENGTH; d++) {
|
||||||
|
|
|
@ -102,7 +102,9 @@ namespace oned {
|
||||||
char decodedChar;
|
char decodedChar;
|
||||||
int lastStart;
|
int lastStart;
|
||||||
do {
|
do {
|
||||||
recordPattern(row, nextStart, counters, countersLen);
|
if (!recordPattern(row, nextStart, counters, countersLen)) {
|
||||||
|
throw ReaderException("");
|
||||||
|
}
|
||||||
int pattern = toNarrowWidePattern(counters, countersLen);
|
int pattern = toNarrowWidePattern(counters, countersLen);
|
||||||
if (pattern < 0) {
|
if (pattern < 0) {
|
||||||
throw ReaderException("pattern < 0");
|
throw ReaderException("pattern < 0");
|
||||||
|
|
|
@ -134,7 +134,9 @@ namespace zxing {
|
||||||
|
|
||||||
while (payloadStart < payloadEnd) {
|
while (payloadStart < payloadEnd) {
|
||||||
// Get 10 runs of black/white.
|
// Get 10 runs of black/white.
|
||||||
recordPattern(row, payloadStart, counterDigitPair, counterDigitPairLen);
|
if (!recordPattern(row, payloadStart, counterDigitPair, counterDigitPairLen)) {
|
||||||
|
throw ReaderException("");
|
||||||
|
}
|
||||||
// Split them into each array
|
// Split them into each array
|
||||||
for (int k = 0; k < 5; k++) {
|
for (int k = 0; k < 5; k++) {
|
||||||
int twoK = k << 1;
|
int twoK = k << 1;
|
||||||
|
|
|
@ -112,13 +112,16 @@ namespace zxing {
|
||||||
// if there's exactly two points (which there should be), flip the x coordinate
|
// if there's exactly two points (which there should be), flip the x coordinate
|
||||||
// if there's not exactly 2, I don't know what do do with it
|
// if there's not exactly 2, I don't know what do do with it
|
||||||
if (points.size() == 2) {
|
if (points.size() == 2) {
|
||||||
Ref<ResultPoint> pointZero(new OneDResultPoint(width - points[0]->getX() - 1, points[0]->getY()));
|
Ref<ResultPoint> pointZero(new OneDResultPoint(width - points[0]->getX() - 1,
|
||||||
|
points[0]->getY()));
|
||||||
points[0] = pointZero;
|
points[0] = pointZero;
|
||||||
|
|
||||||
Ref<ResultPoint> pointOne(new OneDResultPoint(width - points[1]->getX() - 1, points[1]->getY()));
|
Ref<ResultPoint> pointOne(new OneDResultPoint(width - points[1]->getX() - 1,
|
||||||
|
points[1]->getY()));
|
||||||
points[1] = pointOne;
|
points[1] = pointOne;
|
||||||
|
|
||||||
result.reset(new Result(result->getText(),result->getRawBytes(),points,result->getBarcodeFormat()));
|
result.reset(new Result(result->getText(), result->getRawBytes(), points,
|
||||||
|
result->getBarcodeFormat()));
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
@ -127,7 +130,8 @@ namespace zxing {
|
||||||
throw ReaderException("doDecode() failed");
|
throw ReaderException("doDecode() failed");
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned int OneDReader::patternMatchVariance(int counters[], int countersSize, const int pattern[], int maxIndividualVariance) {
|
unsigned int OneDReader::patternMatchVariance(int counters[], int countersSize,
|
||||||
|
const int pattern[], int maxIndividualVariance) {
|
||||||
int numCounters = countersSize;
|
int numCounters = countersSize;
|
||||||
unsigned int total = 0;
|
unsigned int total = 0;
|
||||||
unsigned int patternLength = 0;
|
unsigned int patternLength = 0;
|
||||||
|
@ -159,14 +163,14 @@ namespace zxing {
|
||||||
return totalVariance / total;
|
return totalVariance / total;
|
||||||
}
|
}
|
||||||
|
|
||||||
void OneDReader::recordPattern(Ref<BitArray> row, int start, int counters[], int countersCount){
|
bool OneDReader::recordPattern(Ref<BitArray> row, int start, int counters[], int countersCount) {
|
||||||
int numCounters = countersCount;//sizeof(counters) / sizeof(int);
|
int numCounters = countersCount;//sizeof(counters) / sizeof(int);
|
||||||
for (int i = 0; i < numCounters; i++) {
|
for (int i = 0; i < numCounters; i++) {
|
||||||
counters[i] = 0;
|
counters[i] = 0;
|
||||||
}
|
}
|
||||||
int end = row->getSize();
|
int end = row->getSize();
|
||||||
if (start >= end) {
|
if (start >= end) {
|
||||||
throw ReaderException("recordPattern: start >= end");
|
return false;
|
||||||
}
|
}
|
||||||
bool isWhite = !row->get(start);
|
bool isWhite = !row->get(start);
|
||||||
int counterPosition = 0;
|
int counterPosition = 0;
|
||||||
|
@ -189,8 +193,9 @@ namespace zxing {
|
||||||
// If we read fully the last section of pixels and filled up our counters -- or filled
|
// If we read fully the last section of pixels and filled up our counters -- or filled
|
||||||
// the last counter but ran off the side of the image, OK. Otherwise, a problem.
|
// the last counter but ran off the side of the image, OK. Otherwise, a problem.
|
||||||
if (!(counterPosition == numCounters || (counterPosition == numCounters - 1 && i == end))) {
|
if (!(counterPosition == numCounters || (counterPosition == numCounters - 1 && i == end))) {
|
||||||
throw ReaderException("recordPattern");
|
return false;
|
||||||
}
|
}
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
OneDReader::~OneDReader() {
|
OneDReader::~OneDReader() {
|
||||||
|
|
|
@ -41,7 +41,7 @@ namespace zxing {
|
||||||
|
|
||||||
static unsigned int patternMatchVariance(int counters[], int countersSize,
|
static unsigned int patternMatchVariance(int counters[], int countersSize,
|
||||||
const int pattern[], int maxIndividualVariance);
|
const int pattern[], int maxIndividualVariance);
|
||||||
static void recordPattern(Ref<BitArray> row, int start, int counters[], int countersCount);
|
static bool recordPattern(Ref<BitArray> row, int start, int counters[], int countersCount);
|
||||||
virtual ~OneDReader();
|
virtual ~OneDReader();
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -233,10 +233,11 @@ namespace zxing {
|
||||||
sizeof(START_END_PATTERN) / sizeof(int));
|
sizeof(START_END_PATTERN) / sizeof(int));
|
||||||
}
|
}
|
||||||
|
|
||||||
// int UPCEANReader::decodeDigit(Ref<BitArray> row, int counters[], int countersLen, int rowOffset, int** patterns/*[][]*/, int paterns1Len, int paterns2Len)
|
|
||||||
int UPCEANReader::decodeDigit(Ref<BitArray> row, int counters[], int countersLen, int rowOffset,
|
int UPCEANReader::decodeDigit(Ref<BitArray> row, int counters[], int countersLen, int rowOffset,
|
||||||
UPC_EAN_PATTERNS patternType) {
|
UPC_EAN_PATTERNS patternType) {
|
||||||
recordPattern(row, rowOffset, counters, countersLen);
|
if (!recordPattern(row, rowOffset, counters, countersLen)) {
|
||||||
|
throw ReaderException("");
|
||||||
|
}
|
||||||
unsigned int bestVariance = MAX_AVG_VARIANCE; // worst variance we'll accept
|
unsigned int bestVariance = MAX_AVG_VARIANCE; // worst variance we'll accept
|
||||||
int bestMatch = -1;
|
int bestMatch = -1;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue