Reorganizing functions/methods

feature/104
Christoph Oberhofer 9 years ago
parent 8cae60cdee
commit 1b9d5451ed

@ -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;

Loading…
Cancel
Save