Improved support on Code 39 barcodes

This commit is contained in:
Christoph Oberhofer
2015-03-04 22:23:59 +01:00
parent 7638bc41eb
commit b91246c699
16 changed files with 72 additions and 20 deletions
+12
View File
@@ -161,6 +161,18 @@ define(
}
return result;
};
BarcodeReader.prototype._matchRange = function(start, end, value) {
var i;
start = start < 0 ? 0 : start;
for (i = start; i < end; i++) {
if (this._row[i] !== value) {
return false;
}
}
return true;
};
BarcodeReader.DIRECTION = {
FORWARD : 1,
+21 -7
View File
@@ -79,6 +79,8 @@ define(
} while(decodedChar !== '*');
result.pop();
return {
code : result.join(""),
start : start.start,
@@ -116,6 +118,7 @@ define(
var numCounters = counters.length,
maxNarrowWidth = 0,
numWideBars = numCounters,
wideBarWidth = 0,
self = this,
pattern,
i;
@@ -128,18 +131,25 @@ define(
if (counters[i] > maxNarrowWidth) {
pattern |= 1 << (numCounters - 1 - i);
numWideBars++;
wideBarWidth += counters[i];
}
}
if (numWideBars === 3) {
for (i = 0; i < numCounters && numWideBars > 0; i++) {
if (counters[i] > maxNarrowWidth) {
numWideBars--;
if ((counters[i] * 3) >= wideBarWidth) {
return -1;
}
}
}
return pattern;
}
}
return -1;
};
Code39Reader.prototype._findEnd = function() {
};
Code39Reader.prototype._findStart = function() {
var self = this,
offset = self._nextSet(self._row),
@@ -148,7 +158,8 @@ define(
counterPos = 0,
isWhite = false,
i,
j;
j,
whiteSpaceMustStart;
for ( i = offset; i < self._row.length; i++) {
if (self._row[i] ^ isWhite) {
@@ -158,10 +169,13 @@ define(
// find start pattern
if (self._toPattern(counter) === self.ASTERISK) {
return {
start: patternStart,
end: i
};
whiteSpaceMustStart = Math.floor(Math.max(0, patternStart - ((i - patternStart) / 4)));
if (self._matchRange(whiteSpaceMustStart, patternStart, 0)) {
return {
start: patternStart,
end: i
};
}
}
patternStart += counter[0] + counter[1];
+1 -1
View File
@@ -16,7 +16,7 @@ define(function(){
debug: false,
controls: false,
locate: true,
numOfWorkers: 0,
numOfWorkers: 4,
scriptName: 'quagga.js',
visual: {
show: true