Codabar optimization

git-svn-id: https://zxing.googlecode.com/svn/trunk@2515 59b500cc-1b3d-0410-9834-0bbf25fbcc57
This commit is contained in:
srowen 2012-11-12 20:12:04 +00:00
parent ef33d45809
commit 6352a421a3

View file

@ -291,29 +291,41 @@ public final class CodaBarReader extends OneDReader {
if (end >= counterLength) { if (end >= counterLength) {
return -1; return -1;
} }
// First element is for bars, second is for spaces.
int[] maxes = {0, 0};
int[] mins = {Integer.MAX_VALUE, Integer.MAX_VALUE};
int[] thresholds = {0, 0};
for (int i = 0; i < 2; i++) { int[] theCounters = counters;
for (int j = position + i; j < end; j += 2) {
if (counters[j] < mins[i]) { int maxBar = 0;
mins[i] = counters[j]; int minBar = Integer.MAX_VALUE;
for (int j = position; j < end; j += 2) {
int currentCounter = theCounters[j];
if (currentCounter < minBar) {
minBar = currentCounter;
} }
if (counters[j] > maxes[i]) { if (currentCounter > maxBar) {
maxes[i] = counters[j]; maxBar = currentCounter;
} }
} }
thresholds[i] = (mins[i] + maxes[i]) / 2; int thresholdBar = (minBar + maxBar) / 2;
int maxSpace = 0;
int minSpace = Integer.MAX_VALUE;
for (int j = position + 1; j < end; j += 2) {
int currentCounter = theCounters[j];
if (currentCounter < minSpace) {
minSpace = currentCounter;
} }
if (currentCounter > maxSpace) {
maxSpace = currentCounter;
}
}
int thresholdSpace = (minSpace + maxSpace) / 2;
int bitmask = 1 << 7; int bitmask = 1 << 7;
int pattern = 0; int pattern = 0;
for (int i = 0; i < 7; i++) { for (int i = 0; i < 7; i++) {
int barOrSpace = i & 1; int threshold = (i & 1) == 0 ? thresholdBar : thresholdSpace;
bitmask >>= 1; bitmask >>= 1;
if (counters[position + i] > thresholds[barOrSpace]) { if (theCounters[position + i] > threshold) {
pattern |= bitmask; pattern |= bitmask;
} }
} }