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;
|
||||
|
||||
if (correction) {
|
||||
correct(counter, correction.bar, [0, 2, 4]);
|
||||
correct(counter, correction.space, [1, 3, 5]);
|
||||
self._correct(counter, correction);
|
||||
}
|
||||
for (i = 0; i < counter.length; i++) {
|
||||
sum += counter[i];
|
||||
@@ -72,7 +71,7 @@ BarcodeReader.prototype._normalize = function(counter, correction) {
|
||||
return normalized;
|
||||
};
|
||||
|
||||
function correct(counter, correction, indices) {
|
||||
BarcodeReader.prototype._correctBars = function(counter, correction, indices) {
|
||||
var length = indices.length,
|
||||
tmp = 0;
|
||||
while(length--) {
|
||||
|
||||
@@ -125,7 +125,8 @@ var properties = {
|
||||
]},
|
||||
SINGLE_CODE_ERROR: {value: 0.64},
|
||||
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);
|
||||
@@ -172,9 +173,11 @@ Code128Reader.prototype._decodeCode = function(start, correction) {
|
||||
}
|
||||
if (self.CODE_PATTERN[bestMatch.code]) {
|
||||
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(
|
||||
self.CODE_PATTERN[bestMatch.code], normalized, [1, 3, 5]);
|
||||
self.CODE_PATTERN[bestMatch.code], normalized,
|
||||
this.MODULE_INDICES.space);
|
||||
}
|
||||
return bestMatch;
|
||||
}
|
||||
@@ -188,17 +191,10 @@ Code128Reader.prototype._decodeCode = function(start, correction) {
|
||||
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;
|
||||
}
|
||||
Code128Reader.prototype._correct = function(counter, correction) {
|
||||
this._correctBars(counter, correction.bar, this.MODULE_INDICES.bar);
|
||||
this._correctBars(counter, correction.space, this.MODULE_INDICES.space);
|
||||
};
|
||||
|
||||
Code128Reader.prototype._findStart = function() {
|
||||
var counter = [0, 0, 0, 0, 0, 0],
|
||||
@@ -456,4 +452,16 @@ BarcodeReader.prototype._verifyTrailingWhitespace = function(endInfo) {
|
||||
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;
|
||||
|
||||
Reference in New Issue
Block a user