diff --git a/src/reader/barcode_reader.js b/src/reader/barcode_reader.js index 3eeadb1..8182533 100644 --- a/src/reader/barcode_reader.js +++ b/src/reader/barcode_reader.js @@ -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; diff --git a/src/reader/code_128_reader.js b/src/reader/code_128_reader.js index e7ea281..cb74587 100644 --- a/src/reader/code_128_reader.js +++ b/src/reader/code_128_reader.js @@ -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,37 +149,36 @@ 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) { - for (code = 0; code < self.CODE_PATTERN.length; code++) { - error = self._matchPattern(normalized, self.CODE_PATTERN[code]); - if (error < bestMatch.error) { - bestMatch.code = code; - bestMatch.error = error; - } - } - bestMatch.end = i; - if (bestMatch.code === -1 || bestMatch.error > self.AVG_CODE_ERROR) { - return null; - } - if (self.CODE_PATTERN[bestMatch.code]) { - bestMatch.correction.bar = calculateCorrection( - self.CODE_PATTERN[bestMatch.code], normalized, - this.MODULE_INDICES.bar); - bestMatch.correction.space = calculateCorrection( - self.CODE_PATTERN[bestMatch.code], normalized, - this.MODULE_INDICES.space); + if (correction) { + self._correct(counter, correction); + } + for (code = 0; code < self.CODE_PATTERN.length; code++) { + error = self._matchPattern(counter, self.CODE_PATTERN[code]); + if (error < bestMatch.error) { + bestMatch.code = code; + bestMatch.error = error; } - return bestMatch; } + bestMatch.end = i; + if (bestMatch.code === -1 || bestMatch.error > self.AVG_CODE_ERROR) { + return null; + } + if (self.CODE_PATTERN[bestMatch.code]) { + bestMatch.correction.bar = calculateCorrection( + self.CODE_PATTERN[bestMatch.code], counter, + this.MODULE_INDICES.bar); + bestMatch.correction.space = calculateCorrection( + 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,27 +225,24 @@ 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]); - if (error < bestMatch.error) { - bestMatch.code = code; - bestMatch.error = error; - } - } - if (bestMatch.error < self.AVG_CODE_ERROR) { - bestMatch.start = i - sum; - bestMatch.end = i; - bestMatch.correction.bar = calculateCorrection( - self.CODE_PATTERN[bestMatch.code], normalized, - this.MODULE_INDICES.bar); - bestMatch.correction.space = calculateCorrection( - self.CODE_PATTERN[bestMatch.code], normalized, - this.MODULE_INDICES.space); - return bestMatch; + for (code = self.START_CODE_A; code <= self.START_CODE_C; code++) { + error = self._matchPattern(counter, self.CODE_PATTERN[code]); + if (error < bestMatch.error) { + bestMatch.code = code; + bestMatch.error = error; } } + if (bestMatch.error < self.AVG_CODE_ERROR) { + bestMatch.start = i - sum; + bestMatch.end = i; + bestMatch.correction.bar = calculateCorrection( + self.CODE_PATTERN[bestMatch.code], counter, + this.MODULE_INDICES.bar); + bestMatch.correction.space = calculateCorrection( + self.CODE_PATTERN[bestMatch.code], counter, + this.MODULE_INDICES.space); + return bestMatch; + } for ( j = 0; j < 4; j++) { counter[j] = counter[j + 2]; diff --git a/src/reader/ean_reader.js b/src/reader/ean_reader.js index 9845859..c90b088 100644 --- a/src/reader/ean_reader.js +++ b/src/reader/ean_reader.js @@ -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]}, diff --git a/src/reader/i2of5_reader.js b/src/reader/i2of5_reader.js index a064074..46e4426 100644 --- a/src/reader/i2of5_reader.js +++ b/src/reader/i2of5_reader.js @@ -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,16 +109,12 @@ 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); - - if (error < epsilon) { - bestMatch.error = error; - bestMatch.start = i - sum; - bestMatch.end = i; - return bestMatch; - } + 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++) { @@ -233,20 +228,16 @@ 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]); - if (error < bestMatch.error) { - bestMatch.code = code; - bestMatch.error = error; - } - } - if (bestMatch.error < epsilon) { - return bestMatch; + for (code = 0; code < self.CODE_PATTERN.length; code++) { + error = self._matchPattern(counter, self.CODE_PATTERN[code]); + if (error < bestMatch.error) { + bestMatch.code = code; + bestMatch.error = error; } } - return null; + if (bestMatch.error < epsilon) { + return bestMatch; + } }; I2of5Reader.prototype._decodePayload = function(counters, result, decodedCodes) {