mirror of
https://github.com/zxing/zxing.git
synced 2025-02-02 05:41:08 -08:00
Eliminated up to 700 execeptions being thrown per image by changing one method to return -1 on failure.
git-svn-id: https://zxing.googlecode.com/svn/trunk@1154 59b500cc-1b3d-0410-9834-0bbf25fbcc57
This commit is contained in:
parent
01792f7460
commit
fbff1b9718
|
@ -106,6 +106,9 @@ public final class Code39Reader extends OneDReader {
|
||||||
do {
|
do {
|
||||||
recordPattern(row, nextStart, counters);
|
recordPattern(row, nextStart, counters);
|
||||||
int pattern = toNarrowWidePattern(counters);
|
int pattern = toNarrowWidePattern(counters);
|
||||||
|
if (pattern < 0) {
|
||||||
|
throw ReaderException.getInstance();
|
||||||
|
}
|
||||||
decodedChar = patternToChar(pattern);
|
decodedChar = patternToChar(pattern);
|
||||||
result.append(decodedChar);
|
result.append(decodedChar);
|
||||||
lastStart = nextStart;
|
lastStart = nextStart;
|
||||||
|
@ -187,15 +190,11 @@ public final class Code39Reader extends OneDReader {
|
||||||
counters[counterPosition]++;
|
counters[counterPosition]++;
|
||||||
} else {
|
} else {
|
||||||
if (counterPosition == patternLength - 1) {
|
if (counterPosition == patternLength - 1) {
|
||||||
try {
|
if (toNarrowWidePattern(counters) == ASTERISK_ENCODING) {
|
||||||
if (toNarrowWidePattern(counters) == ASTERISK_ENCODING) {
|
// Look for whitespace before start pattern, >= 50% of width of start pattern
|
||||||
// Look for whitespace before start pattern, >= 50% of width of start pattern
|
if (row.isRange(Math.max(0, patternStart - (i - patternStart) / 2), patternStart, false)) {
|
||||||
if (row.isRange(Math.max(0, patternStart - (i - patternStart) / 2), patternStart, false)) {
|
return new int[]{patternStart, i};
|
||||||
return new int[]{patternStart, i};
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} catch (ReaderException re) {
|
|
||||||
// no match, continue
|
|
||||||
}
|
}
|
||||||
patternStart += counters[0] + counters[1];
|
patternStart += counters[0] + counters[1];
|
||||||
for (int y = 2; y < patternLength; y++) {
|
for (int y = 2; y < patternLength; y++) {
|
||||||
|
@ -214,7 +213,9 @@ public final class Code39Reader extends OneDReader {
|
||||||
throw ReaderException.getInstance();
|
throw ReaderException.getInstance();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static int toNarrowWidePattern(int[] counters) throws ReaderException {
|
// For efficiency, returns -1 on failure. Not throwing here saved as many as 700 exceptions
|
||||||
|
// per image when using some of our blackbox images.
|
||||||
|
private static int toNarrowWidePattern(int[] counters) {
|
||||||
int numCounters = counters.length;
|
int numCounters = counters.length;
|
||||||
int maxNarrowCounter = 0;
|
int maxNarrowCounter = 0;
|
||||||
int wideCounters;
|
int wideCounters;
|
||||||
|
@ -248,14 +249,14 @@ public final class Code39Reader extends OneDReader {
|
||||||
wideCounters--;
|
wideCounters--;
|
||||||
// totalWideCountersWidth = 3 * average, so this checks if counter >= 3/2 * average
|
// totalWideCountersWidth = 3 * average, so this checks if counter >= 3/2 * average
|
||||||
if ((counter << 1) >= totalWideCountersWidth) {
|
if ((counter << 1) >= totalWideCountersWidth) {
|
||||||
throw ReaderException.getInstance();
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return pattern;
|
return pattern;
|
||||||
}
|
}
|
||||||
} while (wideCounters > 3);
|
} while (wideCounters > 3);
|
||||||
throw ReaderException.getInstance();
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static char patternToChar(int pattern) throws ReaderException {
|
private static char patternToChar(int pattern) throws ReaderException {
|
||||||
|
|
Loading…
Reference in a new issue