mirror of
https://github.com/zxing/zxing.git
synced 2025-01-12 19:57:27 -08:00
Codabar optimization
git-svn-id: https://zxing.googlecode.com/svn/trunk@2515 59b500cc-1b3d-0410-9834-0bbf25fbcc57
This commit is contained in:
parent
ef33d45809
commit
6352a421a3
|
@ -291,29 +291,41 @@ public final class CodaBarReader extends OneDReader {
|
|||
if (end >= counterLength) {
|
||||
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++) {
|
||||
for (int j = position + i; j < end; j += 2) {
|
||||
if (counters[j] < mins[i]) {
|
||||
mins[i] = counters[j];
|
||||
}
|
||||
if (counters[j] > maxes[i]) {
|
||||
maxes[i] = counters[j];
|
||||
}
|
||||
int[] theCounters = counters;
|
||||
|
||||
int maxBar = 0;
|
||||
int minBar = Integer.MAX_VALUE;
|
||||
for (int j = position; j < end; j += 2) {
|
||||
int currentCounter = theCounters[j];
|
||||
if (currentCounter < minBar) {
|
||||
minBar = currentCounter;
|
||||
}
|
||||
if (currentCounter > maxBar) {
|
||||
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 pattern = 0;
|
||||
for (int i = 0; i < 7; i++) {
|
||||
int barOrSpace = i & 1;
|
||||
int threshold = (i & 1) == 0 ? thresholdBar : thresholdSpace;
|
||||
bitmask >>= 1;
|
||||
if (counters[position + i] > thresholds[barOrSpace]) {
|
||||
if (theCounters[position + i] > threshold) {
|
||||
pattern |= bitmask;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue