mirror of
https://github.com/zxing/zxing.git
synced 2025-03-05 20:48:51 -08:00
A few more small optimizations
git-svn-id: https://zxing.googlecode.com/svn/trunk@2516 59b500cc-1b3d-0410-9834-0bbf25fbcc57
This commit is contained in:
parent
6352a421a3
commit
14b2eeb7ae
|
@ -23,6 +23,7 @@ import com.google.zxing.Result;
|
||||||
import com.google.zxing.ResultPoint;
|
import com.google.zxing.ResultPoint;
|
||||||
import com.google.zxing.common.BitArray;
|
import com.google.zxing.common.BitArray;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -78,6 +79,7 @@ public final class CodaBarReader extends OneDReader {
|
||||||
@Override
|
@Override
|
||||||
public Result decodeRow(int rowNumber, BitArray row, Map<DecodeHintType,?> hints) throws NotFoundException {
|
public Result decodeRow(int rowNumber, BitArray row, Map<DecodeHintType,?> hints) throws NotFoundException {
|
||||||
|
|
||||||
|
Arrays.fill(counters, 0);
|
||||||
setCounters(row);
|
setCounters(row);
|
||||||
int startOffset = findStartPattern();
|
int startOffset = findStartPattern();
|
||||||
int nextStart = startOffset;
|
int nextStart = startOffset;
|
||||||
|
|
|
@ -56,14 +56,15 @@ public final class Code39Reader extends OneDReader {
|
||||||
|
|
||||||
private final boolean usingCheckDigit;
|
private final boolean usingCheckDigit;
|
||||||
private final boolean extendedMode;
|
private final boolean extendedMode;
|
||||||
|
private final StringBuilder decodeRowResult;
|
||||||
|
private final int[] counters;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a reader that assumes all encoded data is data, and does not treat the final
|
* Creates a reader that assumes all encoded data is data, and does not treat the final
|
||||||
* character as a check digit. It will not decoded "extended Code 39" sequences.
|
* character as a check digit. It will not decoded "extended Code 39" sequences.
|
||||||
*/
|
*/
|
||||||
public Code39Reader() {
|
public Code39Reader() {
|
||||||
usingCheckDigit = false;
|
this(false);
|
||||||
extendedMode = false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -74,8 +75,7 @@ public final class Code39Reader extends OneDReader {
|
||||||
* data, and verify that the checksum passes.
|
* data, and verify that the checksum passes.
|
||||||
*/
|
*/
|
||||||
public Code39Reader(boolean usingCheckDigit) {
|
public Code39Reader(boolean usingCheckDigit) {
|
||||||
this.usingCheckDigit = usingCheckDigit;
|
this(usingCheckDigit, false);
|
||||||
this.extendedMode = false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -91,19 +91,22 @@ public final class Code39Reader extends OneDReader {
|
||||||
public Code39Reader(boolean usingCheckDigit, boolean extendedMode) {
|
public Code39Reader(boolean usingCheckDigit, boolean extendedMode) {
|
||||||
this.usingCheckDigit = usingCheckDigit;
|
this.usingCheckDigit = usingCheckDigit;
|
||||||
this.extendedMode = extendedMode;
|
this.extendedMode = extendedMode;
|
||||||
|
decodeRowResult = new StringBuilder(20);
|
||||||
|
counters = new int[9];
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Result decodeRow(int rowNumber, BitArray row, Map<DecodeHintType,?> hints)
|
public Result decodeRow(int rowNumber, BitArray row, Map<DecodeHintType,?> hints)
|
||||||
throws NotFoundException, ChecksumException, FormatException {
|
throws NotFoundException, ChecksumException, FormatException {
|
||||||
|
|
||||||
int[] counters = new int[9];
|
Arrays.fill(counters, 0);
|
||||||
|
decodeRowResult.setLength(0);
|
||||||
|
|
||||||
int[] start = findAsteriskPattern(row, counters);
|
int[] start = findAsteriskPattern(row, counters);
|
||||||
// Read off white space
|
// Read off white space
|
||||||
int nextStart = row.getNextSet(start[1]);
|
int nextStart = row.getNextSet(start[1]);
|
||||||
int end = row.getSize();
|
int end = row.getSize();
|
||||||
|
|
||||||
StringBuilder result = new StringBuilder(20);
|
|
||||||
char decodedChar;
|
char decodedChar;
|
||||||
int lastStart;
|
int lastStart;
|
||||||
do {
|
do {
|
||||||
|
@ -113,7 +116,7 @@ public final class Code39Reader extends OneDReader {
|
||||||
throw NotFoundException.getNotFoundInstance();
|
throw NotFoundException.getNotFoundInstance();
|
||||||
}
|
}
|
||||||
decodedChar = patternToChar(pattern);
|
decodedChar = patternToChar(pattern);
|
||||||
result.append(decodedChar);
|
decodeRowResult.append(decodedChar);
|
||||||
lastStart = nextStart;
|
lastStart = nextStart;
|
||||||
for (int counter : counters) {
|
for (int counter : counters) {
|
||||||
nextStart += counter;
|
nextStart += counter;
|
||||||
|
@ -121,7 +124,7 @@ public final class Code39Reader extends OneDReader {
|
||||||
// Read off white space
|
// Read off white space
|
||||||
nextStart = row.getNextSet(nextStart);
|
nextStart = row.getNextSet(nextStart);
|
||||||
} while (decodedChar != '*');
|
} while (decodedChar != '*');
|
||||||
result.setLength(result.length() - 1); // remove asterisk
|
decodeRowResult.setLength(decodeRowResult.length() - 1); // remove asterisk
|
||||||
|
|
||||||
// Look for whitespace after pattern:
|
// Look for whitespace after pattern:
|
||||||
int lastPatternSize = 0;
|
int lastPatternSize = 0;
|
||||||
|
@ -136,27 +139,27 @@ public final class Code39Reader extends OneDReader {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (usingCheckDigit) {
|
if (usingCheckDigit) {
|
||||||
int max = result.length() - 1;
|
int max = decodeRowResult.length() - 1;
|
||||||
int total = 0;
|
int total = 0;
|
||||||
for (int i = 0; i < max; i++) {
|
for (int i = 0; i < max; i++) {
|
||||||
total += ALPHABET_STRING.indexOf(result.charAt(i));
|
total += ALPHABET_STRING.indexOf(decodeRowResult.charAt(i));
|
||||||
}
|
}
|
||||||
if (result.charAt(max) != ALPHABET[total % 43]) {
|
if (decodeRowResult.charAt(max) != ALPHABET[total % 43]) {
|
||||||
throw ChecksumException.getChecksumInstance();
|
throw ChecksumException.getChecksumInstance();
|
||||||
}
|
}
|
||||||
result.setLength(max);
|
decodeRowResult.setLength(max);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (result.length() == 0) {
|
if (decodeRowResult.length() == 0) {
|
||||||
// false positive
|
// false positive
|
||||||
throw NotFoundException.getNotFoundInstance();
|
throw NotFoundException.getNotFoundInstance();
|
||||||
}
|
}
|
||||||
|
|
||||||
String resultString;
|
String resultString;
|
||||||
if (extendedMode) {
|
if (extendedMode) {
|
||||||
resultString = decodeExtended(result);
|
resultString = decodeExtended(decodeRowResult);
|
||||||
} else {
|
} else {
|
||||||
resultString = result.toString();
|
resultString = decodeRowResult.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
float left = (float) (start[1] + start[0]) / 2.0f;
|
float left = (float) (start[1] + start[0]) / 2.0f;
|
||||||
|
@ -172,9 +175,6 @@ public final class Code39Reader extends OneDReader {
|
||||||
}
|
}
|
||||||
|
|
||||||
private static int[] findAsteriskPattern(BitArray row, int[] counters) throws NotFoundException {
|
private static int[] findAsteriskPattern(BitArray row, int[] counters) throws NotFoundException {
|
||||||
// Should not be needed, but appears to work around a Java 7 JIT bug? This comes in corrupted
|
|
||||||
Arrays.fill(counters, 0);
|
|
||||||
|
|
||||||
int width = row.getSize();
|
int width = row.getSize();
|
||||||
int rowOffset = row.getNextSet(0);
|
int rowOffset = row.getNextSet(0);
|
||||||
|
|
||||||
|
|
|
@ -264,8 +264,6 @@ public final class RSSExpandedReader extends AbstractRSSReader {
|
||||||
if (allFound) {
|
if (allFound) {
|
||||||
// 'pairs' contains all the pairs from the row 'r'
|
// 'pairs' contains all the pairs from the row 'r'
|
||||||
iterator.remove();
|
iterator.remove();
|
||||||
// start from the begining
|
|
||||||
removePartialRows(pairs, rows);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue