mirror of
https://github.com/serratus/quaggaJS.git
synced 2026-08-12 21:21:42 +08:00
Fixed Code128 Reader
This commit is contained in:
@@ -66,33 +66,6 @@ BarcodeReader.prototype._nextSet = function(line, offset) {
|
||||
return line.length;
|
||||
};
|
||||
|
||||
BarcodeReader.prototype._normalize = function(counter, correction) {
|
||||
var i,
|
||||
self = this,
|
||||
sum = 0,
|
||||
ratio,
|
||||
numOnes = 0,
|
||||
normalized = new Array(counter.length),
|
||||
norm = 0,
|
||||
modulo = self.MODULO;
|
||||
|
||||
for (i = 0; i < normalized.length; i++) {
|
||||
normalized[i] = counter[i] < this.minBarWidth ? counter[i] = this.minBarWidth : counter[i];
|
||||
}
|
||||
if (correction) {
|
||||
self._correct(normalized, correction);
|
||||
}
|
||||
for (i = 0; i < normalized.length; i++) {
|
||||
sum += normalized[i];
|
||||
}
|
||||
ratio = sum / (modulo - numOnes);
|
||||
for (i = 0; i < normalized.length; i++) {
|
||||
norm = normalized[i] === 1 ? normalized[i] : normalized[i] / ratio;
|
||||
normalized[i] = norm;
|
||||
}
|
||||
return normalized;
|
||||
};
|
||||
|
||||
BarcodeReader.prototype._correctBars = function(counter, correction, indices) {
|
||||
var length = indices.length,
|
||||
tmp = 0;
|
||||
|
||||
@@ -13,7 +13,6 @@ var properties = {
|
||||
START_CODE_B: {value: 104},
|
||||
START_CODE_C: {value: 105},
|
||||
STOP_CODE: {value: 106},
|
||||
MODULO: {value: 11},
|
||||
CODE_PATTERN: {value: [
|
||||
[2, 1, 2, 2, 2, 2],
|
||||
[2, 2, 2, 1, 2, 2],
|
||||
@@ -150,18 +149,18 @@ Code128Reader.prototype._decodeCode = function(start, correction) {
|
||||
}
|
||||
},
|
||||
code,
|
||||
error,
|
||||
normalized;
|
||||
error;
|
||||
|
||||
for ( i = offset; i < self._row.length; i++) {
|
||||
if (self._row[i] ^ isWhite) {
|
||||
counter[counterPos]++;
|
||||
} else {
|
||||
if (counterPos === counter.length - 1) {
|
||||
normalized = self._normalize(counter, correction);
|
||||
if (normalized) {
|
||||
if (correction) {
|
||||
self._correct(counter, correction);
|
||||
}
|
||||
for (code = 0; code < self.CODE_PATTERN.length; code++) {
|
||||
error = self._matchPattern(normalized, self.CODE_PATTERN[code]);
|
||||
error = self._matchPattern(counter, self.CODE_PATTERN[code]);
|
||||
if (error < bestMatch.error) {
|
||||
bestMatch.code = code;
|
||||
bestMatch.error = error;
|
||||
@@ -173,14 +172,13 @@ Code128Reader.prototype._decodeCode = function(start, correction) {
|
||||
}
|
||||
if (self.CODE_PATTERN[bestMatch.code]) {
|
||||
bestMatch.correction.bar = calculateCorrection(
|
||||
self.CODE_PATTERN[bestMatch.code], normalized,
|
||||
self.CODE_PATTERN[bestMatch.code], counter,
|
||||
this.MODULE_INDICES.bar);
|
||||
bestMatch.correction.space = calculateCorrection(
|
||||
self.CODE_PATTERN[bestMatch.code], normalized,
|
||||
self.CODE_PATTERN[bestMatch.code], counter,
|
||||
this.MODULE_INDICES.space);
|
||||
}
|
||||
return bestMatch;
|
||||
}
|
||||
} else {
|
||||
counterPos++;
|
||||
}
|
||||
@@ -216,8 +214,7 @@ Code128Reader.prototype._findStart = function() {
|
||||
code,
|
||||
error,
|
||||
j,
|
||||
sum,
|
||||
normalized;
|
||||
sum;
|
||||
|
||||
for ( i = offset; i < self._row.length; i++) {
|
||||
if (self._row[i] ^ isWhite) {
|
||||
@@ -228,10 +225,8 @@ Code128Reader.prototype._findStart = function() {
|
||||
for ( j = 0; j < counter.length; j++) {
|
||||
sum += counter[j];
|
||||
}
|
||||
normalized = self._normalize(counter);
|
||||
if (normalized) {
|
||||
for (code = self.START_CODE_A; code <= self.START_CODE_C; code++) {
|
||||
error = self._matchPattern(normalized, self.CODE_PATTERN[code]);
|
||||
error = self._matchPattern(counter, self.CODE_PATTERN[code]);
|
||||
if (error < bestMatch.error) {
|
||||
bestMatch.code = code;
|
||||
bestMatch.error = error;
|
||||
@@ -241,14 +236,13 @@ Code128Reader.prototype._findStart = function() {
|
||||
bestMatch.start = i - sum;
|
||||
bestMatch.end = i;
|
||||
bestMatch.correction.bar = calculateCorrection(
|
||||
self.CODE_PATTERN[bestMatch.code], normalized,
|
||||
self.CODE_PATTERN[bestMatch.code], counter,
|
||||
this.MODULE_INDICES.bar);
|
||||
bestMatch.correction.space = calculateCorrection(
|
||||
self.CODE_PATTERN[bestMatch.code], normalized,
|
||||
self.CODE_PATTERN[bestMatch.code], counter,
|
||||
this.MODULE_INDICES.space);
|
||||
return bestMatch;
|
||||
}
|
||||
}
|
||||
|
||||
for ( j = 0; j < 4; j++) {
|
||||
counter[j] = counter[j + 2];
|
||||
|
||||
@@ -17,7 +17,6 @@ function getDefaulConfig() {
|
||||
|
||||
var properties = {
|
||||
CODE_L_START: {value: 0},
|
||||
MODULO: {value: 7},
|
||||
CODE_G_START: {value: 10},
|
||||
START_PATTERN: {value: [1, 1, 1]},
|
||||
STOP_PATTERN: {value: [1, 1, 1]},
|
||||
|
||||
@@ -23,9 +23,8 @@ function getDefaulConfig() {
|
||||
var N = 1,
|
||||
W = 3,
|
||||
properties = {
|
||||
MODULO: {value: 10},
|
||||
START_PATTERN: {value: [N * 2.5, N * 2.5, N * 2.5, N * 2.5]},
|
||||
STOP_PATTERN: {value: [N * 2, N * 2, W * 2]},
|
||||
START_PATTERN: {value: [N, N, N, N]},
|
||||
STOP_PATTERN: {value: [N, N, W]},
|
||||
CODE_PATTERN: {value: [
|
||||
[N, N, W, W, N],
|
||||
[W, N, N, N, W],
|
||||
@@ -110,17 +109,13 @@ I2of5Reader.prototype._findPattern = function(pattern, offset, isWhite, tryHarde
|
||||
for ( j = 0; j < counter.length; j++) {
|
||||
sum += counter[j];
|
||||
}
|
||||
normalized = self._normalize(counter);
|
||||
if (normalized) {
|
||||
error = self._matchPattern(normalized, pattern);
|
||||
|
||||
error = self._matchPattern(counter, pattern);
|
||||
if (error < epsilon) {
|
||||
bestMatch.error = error;
|
||||
bestMatch.start = i - sum;
|
||||
bestMatch.end = i;
|
||||
return bestMatch;
|
||||
}
|
||||
}
|
||||
if (tryHarder) {
|
||||
for (j = 0; j < counter.length - 2; j++) {
|
||||
counter[j] = counter[j + 2];
|
||||
@@ -233,10 +228,8 @@ I2of5Reader.prototype._decodeCode = function(counter) {
|
||||
for ( j = 0; j < counter.length; j++) {
|
||||
sum += counter[j];
|
||||
}
|
||||
normalized = self._normalize(counter);
|
||||
if (normalized) {
|
||||
for (code = 0; code < self.CODE_PATTERN.length; code++) {
|
||||
error = self._matchPattern(normalized, self.CODE_PATTERN[code]);
|
||||
error = self._matchPattern(counter, self.CODE_PATTERN[code]);
|
||||
if (error < bestMatch.error) {
|
||||
bestMatch.code = code;
|
||||
bestMatch.error = error;
|
||||
@@ -245,8 +238,6 @@ I2of5Reader.prototype._decodeCode = function(counter) {
|
||||
if (bestMatch.error < epsilon) {
|
||||
return bestMatch;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
};
|
||||
|
||||
I2of5Reader.prototype._decodePayload = function(counters, result, decodedCodes) {
|
||||
|
||||
Reference in New Issue
Block a user