mirror of
https://github.com/serratus/quaggaJS.git
synced 2026-08-12 21:21:42 +08:00
195: Extracted common method to BarcodeReader;
This commit is contained in:
@@ -1,3 +1,5 @@
|
|||||||
|
import ArrayHelper from '../common/array_helper';
|
||||||
|
|
||||||
function BarcodeReader(config, supplements) {
|
function BarcodeReader(config, supplements) {
|
||||||
this._row = [];
|
this._row = [];
|
||||||
this.config = config || {};
|
this.config = config || {};
|
||||||
@@ -195,6 +197,33 @@ BarcodeReader.prototype._fillCounters = function(offset, end, isWhite) {
|
|||||||
return counters;
|
return counters;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
BarcodeReader.prototype._toCounters = function(start, counter) {
|
||||||
|
var self = this,
|
||||||
|
numCounters = counter.length,
|
||||||
|
end = self._row.length,
|
||||||
|
isWhite = !self._row[start],
|
||||||
|
i,
|
||||||
|
counterPos = 0;
|
||||||
|
|
||||||
|
ArrayHelper.init(counter, 0);
|
||||||
|
|
||||||
|
for ( i = start; i < end; i++) {
|
||||||
|
if (self._row[i] ^ isWhite) {
|
||||||
|
counter[counterPos]++;
|
||||||
|
} else {
|
||||||
|
counterPos++;
|
||||||
|
if (counterPos === numCounters) {
|
||||||
|
break;
|
||||||
|
} else {
|
||||||
|
counter[counterPos] = 1;
|
||||||
|
isWhite = !isWhite;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return counter;
|
||||||
|
};
|
||||||
|
|
||||||
Object.defineProperty(BarcodeReader.prototype, "FORMAT", {
|
Object.defineProperty(BarcodeReader.prototype, "FORMAT", {
|
||||||
value: 'unknown',
|
value: 'unknown',
|
||||||
writeable: false
|
writeable: false
|
||||||
|
|||||||
@@ -20,33 +20,6 @@ var properties = {
|
|||||||
Code39Reader.prototype = Object.create(BarcodeReader.prototype, properties);
|
Code39Reader.prototype = Object.create(BarcodeReader.prototype, properties);
|
||||||
Code39Reader.prototype.constructor = Code39Reader;
|
Code39Reader.prototype.constructor = Code39Reader;
|
||||||
|
|
||||||
Code39Reader.prototype._toCounters = function(start, counter) {
|
|
||||||
var self = this,
|
|
||||||
numCounters = counter.length,
|
|
||||||
end = self._row.length,
|
|
||||||
isWhite = !self._row[start],
|
|
||||||
i,
|
|
||||||
counterPos = 0;
|
|
||||||
|
|
||||||
ArrayHelper.init(counter, 0);
|
|
||||||
|
|
||||||
for ( i = start; i < end; i++) {
|
|
||||||
if (self._row[i] ^ isWhite) {
|
|
||||||
counter[counterPos]++;
|
|
||||||
} else {
|
|
||||||
counterPos++;
|
|
||||||
if (counterPos === numCounters) {
|
|
||||||
break;
|
|
||||||
} else {
|
|
||||||
counter[counterPos] = 1;
|
|
||||||
isWhite = !isWhite;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return counter;
|
|
||||||
};
|
|
||||||
|
|
||||||
Code39Reader.prototype._decode = function() {
|
Code39Reader.prototype._decode = function() {
|
||||||
var self = this,
|
var self = this,
|
||||||
counters = [0, 0, 0, 0, 0, 0, 0, 0, 0],
|
counters = [0, 0, 0, 0, 0, 0, 0, 0, 0],
|
||||||
|
|||||||
@@ -24,33 +24,6 @@ var properties = {
|
|||||||
Code93Reader.prototype = Object.create(BarcodeReader.prototype, properties);
|
Code93Reader.prototype = Object.create(BarcodeReader.prototype, properties);
|
||||||
Code93Reader.prototype.constructor = Code93Reader;
|
Code93Reader.prototype.constructor = Code93Reader;
|
||||||
|
|
||||||
Code93Reader.prototype._toCounters = function(start, counter) {
|
|
||||||
var self = this,
|
|
||||||
numCounters = counter.length,
|
|
||||||
end = self._row.length,
|
|
||||||
isWhite = !self._row[start],
|
|
||||||
i,
|
|
||||||
counterPos = 0;
|
|
||||||
|
|
||||||
ArrayHelper.init(counter, 0);
|
|
||||||
|
|
||||||
for ( i = start; i < end; i++) {
|
|
||||||
if (self._row[i] ^ isWhite) {
|
|
||||||
counter[counterPos]++;
|
|
||||||
} else {
|
|
||||||
counterPos++;
|
|
||||||
if (counterPos === numCounters) {
|
|
||||||
break;
|
|
||||||
} else {
|
|
||||||
counter[counterPos] = 1;
|
|
||||||
isWhite = !isWhite;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return counter;
|
|
||||||
};
|
|
||||||
|
|
||||||
Code93Reader.prototype._decode = function() {
|
Code93Reader.prototype._decode = function() {
|
||||||
var self = this,
|
var self = this,
|
||||||
counters = [0, 0, 0, 0, 0, 0],
|
counters = [0, 0, 0, 0, 0, 0],
|
||||||
@@ -235,7 +208,7 @@ Code93Reader.prototype._decodeExtended = function(charArray) {
|
|||||||
case 'c':
|
case 'c':
|
||||||
if (nextChar >= 'A' && nextChar <= 'O') {
|
if (nextChar >= 'A' && nextChar <= 'O') {
|
||||||
decodedChar = String.fromCharCode(nextCharCode - 32);
|
decodedChar = String.fromCharCode(nextCharCode - 32);
|
||||||
} else if (nextChar == 'Z') {
|
} else if (nextChar === 'Z') {
|
||||||
decodedChar = ':';
|
decodedChar = ':';
|
||||||
} else {
|
} else {
|
||||||
return null;
|
return null;
|
||||||
|
|||||||
Reference in New Issue
Block a user