mirror of
https://github.com/serratus/quaggaJS.git
synced 2026-08-12 21:21:42 +08:00
Added barcode format to result-data; minor fixes to Code128Reader; fixes #45
This commit is contained in:
@@ -49,8 +49,7 @@ define([
|
||||
overlay : null
|
||||
}
|
||||
},
|
||||
_barcodeReaders = [],
|
||||
_barcodeReader = null;
|
||||
_barcodeReaders = [];
|
||||
|
||||
initCanvas();
|
||||
initReaders();
|
||||
@@ -171,9 +170,6 @@ define([
|
||||
|
||||
for ( i = 0; i < _barcodeReaders.length && result === null; i++) {
|
||||
result = _barcodeReaders[i].decodePattern(barcodeLine.line);
|
||||
if (result !== null) {
|
||||
_barcodeReader = _barcodeReaders[i];
|
||||
}
|
||||
}
|
||||
if(result === null){
|
||||
return null;
|
||||
|
||||
@@ -166,6 +166,9 @@ define(
|
||||
} else {
|
||||
result.direction = BarcodeReader.DIRECTION.FORWARD;
|
||||
}
|
||||
if (result) {
|
||||
result.format = self.FORMAT;
|
||||
}
|
||||
return result;
|
||||
};
|
||||
|
||||
@@ -180,6 +183,11 @@ define(
|
||||
}
|
||||
return true;
|
||||
};
|
||||
|
||||
Object.defineProperty(BarcodeReader.prototype, "FORMAT", {
|
||||
value: 'unknown',
|
||||
writeable: false
|
||||
});
|
||||
|
||||
BarcodeReader.DIRECTION = {
|
||||
FORWARD : 1,
|
||||
|
||||
@@ -20,7 +20,8 @@ define(
|
||||
START_END: {value: [0x01A, 0x029, 0x00B, 0x00E]},
|
||||
MIN_ENCODED_CHARS: {value: 4},
|
||||
MAX_ACCEPTABLE: {value: 2.0},
|
||||
PADDING: {value: 1.5}
|
||||
PADDING: {value: 1.5},
|
||||
FORMAT: {value: "codabar", writeable: false}
|
||||
};
|
||||
|
||||
CodabarReader.prototype = Object.create(BarcodeReader.prototype, properties);
|
||||
|
||||
+23
-54
@@ -132,7 +132,8 @@ define(
|
||||
[2, 3, 3, 1, 1, 1, 2]
|
||||
]},
|
||||
SINGLE_CODE_ERROR: {value: 1},
|
||||
AVG_CODE_ERROR: {value: 0.5}
|
||||
AVG_CODE_ERROR: {value: 0.5},
|
||||
FORMAT: {value: "code_128", writeable: false}
|
||||
};
|
||||
|
||||
Code128Reader.prototype = Object.create(BarcodeReader.prototype, properties);
|
||||
@@ -179,58 +180,6 @@ define(
|
||||
}
|
||||
return null;
|
||||
};
|
||||
|
||||
Code128Reader.prototype._findEnd = function() {
|
||||
var counter = [0, 0, 0, 0, 0, 0, 0],
|
||||
i,
|
||||
self = this,
|
||||
offset = self._nextSet(self._row),
|
||||
isWhite = !self._row[offset],
|
||||
counterPos = 0,
|
||||
bestMatch = {
|
||||
error : Number.MAX_VALUE,
|
||||
code : -1,
|
||||
start : 0,
|
||||
end : 0
|
||||
},
|
||||
error,
|
||||
j,
|
||||
sum,
|
||||
normalized;
|
||||
|
||||
for ( i = offset; i < self._row.length; i++) {
|
||||
if (self._row[i] ^ isWhite) {
|
||||
counter[counterPos]++;
|
||||
} else {
|
||||
if (counterPos === counter.length - 1) {
|
||||
sum = 0;
|
||||
for ( j = 0; j < counter.length; j++) {
|
||||
sum += counter[j];
|
||||
}
|
||||
normalized = self._normalize(counter, 13);
|
||||
error = self._matchPattern(normalized, self.CODE_PATTERN[self.STOP_CODE]);
|
||||
if (error < self.AVG_CODE_ERROR) {
|
||||
bestMatch.error = error;
|
||||
bestMatch.start = i - sum;
|
||||
bestMatch.end = i;
|
||||
return bestMatch;
|
||||
}
|
||||
|
||||
for ( j = 0; j < 5; j++) {
|
||||
counter[j] = counter[j + 2];
|
||||
}
|
||||
counter[5] = 0;
|
||||
counter[6] = 0;
|
||||
counterPos--;
|
||||
} else {
|
||||
counterPos++;
|
||||
}
|
||||
counter[counterPos] = 1;
|
||||
isWhite = !isWhite;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
};
|
||||
|
||||
Code128Reader.prototype._findStart = function() {
|
||||
var counter = [0, 0, 0, 0, 0, 0],
|
||||
@@ -420,7 +369,7 @@ define(
|
||||
|
||||
// find end bar
|
||||
code.end = self._nextUnset(self._row, code.end);
|
||||
if (code.end === self._row.length) {
|
||||
if(!self._verifyTrailingWhitespace(code)){
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -431,9 +380,15 @@ define(
|
||||
return null;
|
||||
}
|
||||
|
||||
if (!result.length) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// remove last code from result (checksum)
|
||||
result.splice(result.length - 1, 1);
|
||||
|
||||
|
||||
|
||||
return {
|
||||
code : result.join(""),
|
||||
start : startInfo.start,
|
||||
@@ -444,6 +399,20 @@ define(
|
||||
endInfo : code
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
BarcodeReader.prototype._verifyTrailingWhitespace = function(endInfo) {
|
||||
var self = this,
|
||||
trailingWhitespaceEnd;
|
||||
|
||||
trailingWhitespaceEnd = endInfo.end + ((endInfo.end - endInfo.start) / 2);
|
||||
if (trailingWhitespaceEnd < self._row.length) {
|
||||
if (self._matchRange(endInfo.end, trailingWhitespaceEnd, 0)) {
|
||||
return endInfo;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
};
|
||||
|
||||
return (Code128Reader);
|
||||
}
|
||||
|
||||
@@ -17,7 +17,8 @@ define(
|
||||
ALPHABETH_STRING: {value: "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ-. *$/+%"},
|
||||
ALPHABET: {value: [48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 45, 46, 32, 42, 36, 47, 43, 37]},
|
||||
CHARACTER_ENCODINGS: {value: [0x034, 0x121, 0x061, 0x160, 0x031, 0x130, 0x070, 0x025, 0x124, 0x064, 0x109, 0x049, 0x148, 0x019, 0x118, 0x058, 0x00D, 0x10C, 0x04C, 0x01C, 0x103, 0x043, 0x142, 0x013, 0x112, 0x052, 0x007, 0x106, 0x046, 0x016, 0x181, 0x0C1, 0x1C0, 0x091, 0x190, 0x0D0, 0x085, 0x184, 0x0C4, 0x094, 0x0A8, 0x0A2, 0x08A, 0x02A]},
|
||||
ASTERISK: {value: 0x094}
|
||||
ASTERISK: {value: 0x094},
|
||||
FORMAT: {value: "code_39", writeable: false}
|
||||
};
|
||||
|
||||
Code39Reader.prototype = Object.create(BarcodeReader.prototype, properties);
|
||||
|
||||
+5
-1
@@ -12,7 +12,11 @@ define(
|
||||
EANReader.call(this);
|
||||
}
|
||||
|
||||
EAN8Reader.prototype = Object.create(EANReader.prototype);
|
||||
var properties = {
|
||||
FORMAT: {value: "ean_8", writeable: false}
|
||||
};
|
||||
|
||||
EAN8Reader.prototype = Object.create(EANReader.prototype, properties);
|
||||
EAN8Reader.prototype.constructor = EAN8Reader;
|
||||
|
||||
EAN8Reader.prototype._decodePayload = function(code, result, decodedCodes) {
|
||||
|
||||
+2
-1
@@ -43,7 +43,8 @@ define(
|
||||
]},
|
||||
CODE_FREQUENCY : {value: [0, 11, 13, 14, 19, 25, 28, 21, 22, 26]},
|
||||
SINGLE_CODE_ERROR: {value: 0.7},
|
||||
AVG_CODE_ERROR: {value: 0.3}
|
||||
AVG_CODE_ERROR: {value: 0.3},
|
||||
FORMAT: {value: "ean_13", writeable: false}
|
||||
};
|
||||
|
||||
EANReader.prototype = Object.create(BarcodeReader.prototype, properties);
|
||||
|
||||
+2
-1
@@ -16,7 +16,8 @@ define(
|
||||
CODE_FREQUENCY : {value: [
|
||||
[ 56, 52, 50, 49, 44, 38, 35, 42, 41, 37 ],
|
||||
[7, 11, 13, 14, 19, 25, 28, 21, 22, 26]]},
|
||||
STOP_PATTERN: { value: [1 / 6 * 7, 1 / 6 * 7, 1 / 6 * 7, 1 / 6 * 7, 1 / 6 * 7, 1 / 6 * 7]}
|
||||
STOP_PATTERN: { value: [1 / 6 * 7, 1 / 6 * 7, 1 / 6 * 7, 1 / 6 * 7, 1 / 6 * 7, 1 / 6 * 7]},
|
||||
FORMAT: {value: "upc_e", writeable: false}
|
||||
};
|
||||
|
||||
UPCEReader.prototype = Object.create(EANReader.prototype, properties);
|
||||
|
||||
+5
-1
@@ -12,7 +12,11 @@ define(
|
||||
EANReader.call(this);
|
||||
}
|
||||
|
||||
UPCReader.prototype = Object.create(EANReader.prototype);
|
||||
var properties = {
|
||||
FORMAT: {value: "upc_a", writeable: false}
|
||||
};
|
||||
|
||||
UPCReader.prototype = Object.create(EANReader.prototype, properties);
|
||||
UPCReader.prototype.constructor = UPCReader;
|
||||
|
||||
UPCReader.prototype._decode = function() {
|
||||
|
||||
Reference in New Issue
Block a user