mirror of
https://github.com/serratus/quaggaJS.git
synced 2026-08-12 21:21:42 +08:00
Reorganizing functions/methods
This commit is contained in:
@@ -58,8 +58,7 @@ BarcodeReader.prototype._normalize = function(counter, correction) {
|
|||||||
modulo = self.MODULO;
|
modulo = self.MODULO;
|
||||||
|
|
||||||
if (correction) {
|
if (correction) {
|
||||||
correct(counter, correction.bar, [0, 2, 4]);
|
self._correct(counter, correction);
|
||||||
correct(counter, correction.space, [1, 3, 5]);
|
|
||||||
}
|
}
|
||||||
for (i = 0; i < counter.length; i++) {
|
for (i = 0; i < counter.length; i++) {
|
||||||
sum += counter[i];
|
sum += counter[i];
|
||||||
@@ -72,7 +71,7 @@ BarcodeReader.prototype._normalize = function(counter, correction) {
|
|||||||
return normalized;
|
return normalized;
|
||||||
};
|
};
|
||||||
|
|
||||||
function correct(counter, correction, indices) {
|
BarcodeReader.prototype._correctBars = function(counter, correction, indices) {
|
||||||
var length = indices.length,
|
var length = indices.length,
|
||||||
tmp = 0;
|
tmp = 0;
|
||||||
while(length--) {
|
while(length--) {
|
||||||
|
|||||||
@@ -125,7 +125,8 @@ var properties = {
|
|||||||
]},
|
]},
|
||||||
SINGLE_CODE_ERROR: {value: 0.64},
|
SINGLE_CODE_ERROR: {value: 0.64},
|
||||||
AVG_CODE_ERROR: {value: 0.30},
|
AVG_CODE_ERROR: {value: 0.30},
|
||||||
FORMAT: {value: "code_128", writeable: false}
|
FORMAT: {value: "code_128", writeable: false},
|
||||||
|
MODULE_INDICES: {value: {bar: [0, 2, 4], space: [1, 3, 5]}}
|
||||||
};
|
};
|
||||||
|
|
||||||
Code128Reader.prototype = Object.create(BarcodeReader.prototype, properties);
|
Code128Reader.prototype = Object.create(BarcodeReader.prototype, properties);
|
||||||
@@ -172,9 +173,11 @@ Code128Reader.prototype._decodeCode = function(start, correction) {
|
|||||||
}
|
}
|
||||||
if (self.CODE_PATTERN[bestMatch.code]) {
|
if (self.CODE_PATTERN[bestMatch.code]) {
|
||||||
bestMatch.correction.bar = calculateCorrection(
|
bestMatch.correction.bar = calculateCorrection(
|
||||||
self.CODE_PATTERN[bestMatch.code], normalized, [0, 2, 4]);
|
self.CODE_PATTERN[bestMatch.code], normalized,
|
||||||
|
this.MODULE_INDICES.bar);
|
||||||
bestMatch.correction.space = calculateCorrection(
|
bestMatch.correction.space = calculateCorrection(
|
||||||
self.CODE_PATTERN[bestMatch.code], normalized, [1, 3, 5]);
|
self.CODE_PATTERN[bestMatch.code], normalized,
|
||||||
|
this.MODULE_INDICES.space);
|
||||||
}
|
}
|
||||||
return bestMatch;
|
return bestMatch;
|
||||||
}
|
}
|
||||||
@@ -188,17 +191,10 @@ Code128Reader.prototype._decodeCode = function(start, correction) {
|
|||||||
return null;
|
return null;
|
||||||
};
|
};
|
||||||
|
|
||||||
function calculateCorrection(expected, normalized, indices) {
|
Code128Reader.prototype._correct = function(counter, correction) {
|
||||||
var length = indices.length,
|
this._correctBars(counter, correction.bar, this.MODULE_INDICES.bar);
|
||||||
sumNormalized = 0,
|
this._correctBars(counter, correction.space, this.MODULE_INDICES.space);
|
||||||
sumExpected = 0;
|
};
|
||||||
|
|
||||||
while(length--) {
|
|
||||||
sumExpected += expected[indices[length]];
|
|
||||||
sumNormalized += normalized[indices[length]];
|
|
||||||
}
|
|
||||||
return sumExpected/sumNormalized;
|
|
||||||
}
|
|
||||||
|
|
||||||
Code128Reader.prototype._findStart = function() {
|
Code128Reader.prototype._findStart = function() {
|
||||||
var counter = [0, 0, 0, 0, 0, 0],
|
var counter = [0, 0, 0, 0, 0, 0],
|
||||||
@@ -456,4 +452,16 @@ BarcodeReader.prototype._verifyTrailingWhitespace = function(endInfo) {
|
|||||||
return null;
|
return null;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
function calculateCorrection(expected, normalized, indices) {
|
||||||
|
var length = indices.length,
|
||||||
|
sumNormalized = 0,
|
||||||
|
sumExpected = 0;
|
||||||
|
|
||||||
|
while(length--) {
|
||||||
|
sumExpected += expected[indices[length]];
|
||||||
|
sumNormalized += normalized[indices[length]];
|
||||||
|
}
|
||||||
|
return sumExpected/sumNormalized;
|
||||||
|
}
|
||||||
|
|
||||||
export default Code128Reader;
|
export default Code128Reader;
|
||||||
|
|||||||
Reference in New Issue
Block a user