Fixed unit/integration testing; fixed a few linting errors;

This commit is contained in:
Christoph Oberhofer
2015-10-03 23:36:58 +02:00
parent 38da5b0d41
commit 8668e79b63
38 changed files with 1359 additions and 1309 deletions
+7 -7
View File
@@ -1,5 +1,5 @@
export default {
init : function(arr, val) {
init: function(arr, val) {
var l = arr.length;
while (l--) {
arr[l] = val;
@@ -10,7 +10,7 @@ export default {
* Shuffles the content of an array
* @return {Array} the array itself shuffled
*/
shuffle : function(arr) {
shuffle: function(arr) {
var i = arr.length - 1, j, x;
for (i; i >= 0; i--) {
j = Math.floor(Math.random() * i);
@@ -21,7 +21,7 @@ export default {
return arr;
},
toPointList : function(arr) {
toPointList: function(arr) {
var i, j, row = [], rows = [];
for ( i = 0; i < arr.length; i++) {
row = [];
@@ -37,7 +37,7 @@ export default {
* returns the elements which's score is bigger than the threshold
* @return {Array} the reduced array
*/
threshold : function(arr, threshold, scoreFunc) {
threshold: function(arr, threshold, scoreFunc) {
var i, queue = [];
for ( i = 0; i < arr.length; i++) {
if (scoreFunc.apply(arr, [arr[i]]) >= threshold) {
@@ -47,7 +47,7 @@ export default {
return queue;
},
maxIndex : function(arr) {
maxIndex: function(arr) {
var i, max = 0;
for ( i = 0; i < arr.length; i++) {
if (arr[i] > arr[max]) {
@@ -57,7 +57,7 @@ export default {
return max;
},
max : function(arr) {
max: function(arr) {
var i, max = 0;
for ( i = 0; i < arr.length; i++) {
if (arr[i] > max) {
@@ -71,7 +71,7 @@ export default {
var length = arr.length,
sum = 0;
while(length--) {
while (length--) {
sum += arr[length];
}
return sum;
+34 -32
View File
@@ -22,17 +22,17 @@ var readers = {
i2of5_reader: I2of5Reader
};
export default {
create : function(config, inputImageWrapper) {
create: function(config, inputImageWrapper) {
var _canvas = {
ctx : {
frequency : null,
pattern : null,
overlay : null
ctx: {
frequency: null,
pattern: null,
overlay: null
},
dom : {
frequency : null,
pattern : null,
overlay : null
dom: {
frequency: null,
pattern: null,
overlay: null
}
},
_barcodeReaders = [];
@@ -48,7 +48,7 @@ export default {
if (!_canvas.dom.frequency) {
_canvas.dom.frequency = document.createElement("canvas");
_canvas.dom.frequency.className = "frequency";
if($debug) {
if ($debug) {
$debug.appendChild(_canvas.dom.frequency);
}
}
@@ -58,7 +58,7 @@ export default {
if (!_canvas.dom.pattern) {
_canvas.dom.pattern = document.createElement("canvas");
_canvas.dom.pattern.className = "patternBuffer";
if($debug) {
if ($debug) {
$debug.appendChild(_canvas.dom.pattern);
}
}
@@ -82,10 +82,11 @@ export default {
} else if (typeof readerConfig === 'string') {
reader = readerConfig;
}
console.log("Before registering reader: ", reader);
_barcodeReaders.push(new readers[reader](config));
});
console.log("Registered Readers: " + _barcodeReaders
.map(function(reader) {return JSON.stringify({format: reader.FORMAT, config: reader.config});})
.map((reader) => JSON.stringify({format: reader.FORMAT, config: reader.config}))
.join(', '));
}
@@ -93,11 +94,11 @@ export default {
if (typeof document !== 'undefined') {
var i,
vis = [{
node : _canvas.dom.frequency,
prop : config.showFrequency
node: _canvas.dom.frequency,
prop: config.showFrequency
}, {
node : _canvas.dom.pattern,
prop : config.showPattern
node: _canvas.dom.pattern,
prop: config.showPattern
}];
for (i = 0; i < vis.length; i++) {
@@ -118,8 +119,8 @@ export default {
function getExtendedLine(line, angle, ext) {
function extendLine(amount) {
var extension = {
y : amount * Math.sin(angle),
x : amount * Math.cos(angle)
y: amount * Math.sin(angle),
x: amount * Math.cos(angle)
};
line[0].y -= extension.y;
@@ -130,8 +131,9 @@ export default {
// check if inside image
extendLine(ext);
while (ext > 1 && (!inputImageWrapper.inImageWithBorder(line[0], 0) || !inputImageWrapper.inImageWithBorder(line[1], 0))) {
ext -= Math.ceil(ext/2);
while (ext > 1 && (!inputImageWrapper.inImageWithBorder(line[0], 0)
|| !inputImageWrapper.inImageWithBorder(line[1], 0))) {
ext -= Math.ceil(ext / 2);
extendLine(-ext);
}
return line;
@@ -139,11 +141,11 @@ export default {
function getLine(box) {
return [{
x : (box[1][0] - box[0][0]) / 2 + box[0][0],
y : (box[1][1] - box[0][1]) / 2 + box[0][1]
x: (box[1][0] - box[0][0]) / 2 + box[0][0],
y: (box[1][1] - box[0][1]) / 2 + box[0][1]
}, {
x : (box[3][0] - box[2][0]) / 2 + box[2][0],
y : (box[3][1] - box[2][1]) / 2 + box[2][1]
x: (box[3][0] - box[2][0]) / 2 + box[2][0],
y: (box[3][1] - box[2][1]) / 2 + box[2][1]
}];
}
@@ -195,8 +197,8 @@ export default {
// move line perpendicular to angle
dir = sideLength / slices * i * (i % 2 === 0 ? -1 : 1);
extension = {
y : dir * xdir,
x : dir * ydir
y: dir * xdir,
x: dir * ydir
};
line[0].y += extension.x;
line[0].x -= extension.y;
@@ -234,17 +236,17 @@ export default {
line = getLine(box);
lineLength = getLineLength(line);
lineAngle = Math.atan2(line[1].y - line[0].y, line[1].x - line[0].x);
line = getExtendedLine(line, lineAngle, Math.floor(lineLength*0.1));
if(line === null){
line = getExtendedLine(line, lineAngle, Math.floor(lineLength * 0.1));
if (line === null){
return null;
}
result = tryDecode(line);
if(result === null) {
if (result === null) {
result = tryDecodeBruteForce(box, line, lineAngle);
}
if(result === null) {
if (result === null) {
return null;
}
@@ -262,10 +264,10 @@ export default {
}
return {
decodeFromBoundingBox : function(box) {
decodeFromBoundingBox: function(box) {
return decodeFromBoundingBox(box);
},
decodeFromBoundingBoxes : function(boxes) {
decodeFromBoundingBoxes: function(boxes) {
var i, result;
for ( i = 0; i < boxes.length; i++) {
result = decodeFromBoundingBox(boxes[i]);
+73 -47
View File
@@ -1,6 +1,3 @@
/* jshint undef: true, unused: true, browser:true, devel: true */
/* global define */
import ImageWrapper from './image_wrapper';
import CVUtils from './cv_utils';
import Rasterizer from './rasterizer';
@@ -21,11 +18,11 @@ var _config,
_binaryImageWrapper,
_patchSize,
_canvasContainer = {
ctx : {
binary : null
ctx: {
binary: null
},
dom : {
binary : null
dom: {
binary: null
}
},
_numPatches = {x: 0, y: 0},
@@ -40,8 +37,8 @@ function initBuffers() {
if (_config.halfSample) {
_currentImageWrapper = new ImageWrapper({
x : _inputImageWrapper.size.x / 2 | 0,
y : _inputImageWrapper.size.y / 2 | 0
x: _inputImageWrapper.size.x / 2 | 0,
y: _inputImageWrapper.size.y / 2 | 0
});
} else {
_currentImageWrapper = _inputImageWrapper;
@@ -56,16 +53,19 @@ function initBuffers() {
_labelImageWrapper = new ImageWrapper(_patchSize, undefined, Array, true);
skeletonImageData = new ArrayBuffer(64*1024);
_subImageWrapper = new ImageWrapper(_patchSize, new Uint8Array(skeletonImageData, 0, _patchSize.x * _patchSize.y));
_skelImageWrapper = new ImageWrapper(_patchSize, new Uint8Array(skeletonImageData, _patchSize.x * _patchSize.y * 3, _patchSize.x * _patchSize.y), undefined, true);
skeletonImageData = new ArrayBuffer(64 * 1024);
_subImageWrapper = new ImageWrapper(_patchSize,
new Uint8Array(skeletonImageData, 0, _patchSize.x * _patchSize.y));
_skelImageWrapper = new ImageWrapper(_patchSize,
new Uint8Array(skeletonImageData, _patchSize.x * _patchSize.y * 3, _patchSize.x * _patchSize.y),
undefined, true);
_skeletonizer = skeletonizer(self, {
size : _patchSize.x
size: _patchSize.x
}, skeletonImageData);
_imageToPatchGrid = new ImageWrapper({
x : (_currentImageWrapper.size.x / _subImageWrapper.size.x) | 0,
y : (_currentImageWrapper.size.y / _subImageWrapper.size.y) | 0
x: (_currentImageWrapper.size.x / _subImageWrapper.size.x) | 0,
y: (_currentImageWrapper.size.y / _subImageWrapper.size.y) | 0
}, undefined, Array, true);
_patchGrid = new ImageWrapper(_imageToPatchGrid.size, undefined, undefined, true);
_patchLabelGrid = new ImageWrapper(_imageToPatchGrid.size, undefined, Int32Array, true);
@@ -90,7 +90,18 @@ function initCanvas() {
* @returns {Array} The minimal bounding box
*/
function boxFromPatches(patches) {
var overAvg, i, j, patch, transMat, minx = _binaryImageWrapper.size.x, miny = _binaryImageWrapper.size.y, maxx = -_binaryImageWrapper.size.x, maxy = -_binaryImageWrapper.size.y, box, scale;
var overAvg,
i,
j,
patch,
transMat,
minx =
_binaryImageWrapper.size.x,
miny = _binaryImageWrapper.size.y,
maxx = -_binaryImageWrapper.size.x,
maxy = -_binaryImageWrapper.size.y,
box,
scale;
// draw all patches which are to be taken into consideration
overAvg = 0;
@@ -191,9 +202,8 @@ function findPatches() {
rasterizer,
rasterResult,
patch;
for ( i = 0; i < _numPatches.x; i++) {
for ( j = 0; j < _numPatches.y; j++) {
for (i = 0; i < _numPatches.x; i++) {
for (j = 0; j < _numPatches.y; j++) {
x = _subImageWrapper.size.x * i;
y = _subImageWrapper.size.y * j;
@@ -207,7 +217,8 @@ function findPatches() {
rasterResult = rasterizer.rasterize(0);
if (_config.showLabels) {
_labelImageWrapper.overlay(_canvasContainer.dom.binary, Math.floor(360 / rasterResult.count), {x : x, y : y});
_labelImageWrapper.overlay(_canvasContainer.dom.binary, Math.floor(360 / rasterResult.count),
{x: x, y: y});
}
// calculate moments from the skeletonized patch
@@ -221,7 +232,8 @@ function findPatches() {
if (_config.showFoundPatches) {
for ( i = 0; i < patchesFound.length; i++) {
patch = patchesFound[i];
ImageDebug.drawRect(patch.pos, _subImageWrapper.size, _canvasContainer.ctx.binary, {color: "#99ff00", lineWidth: 2});
ImageDebug.drawRect(patch.pos, _subImageWrapper.size, _canvasContainer.ctx.binary,
{color: "#99ff00", lineWidth: 2});
}
}
@@ -251,8 +263,8 @@ function findBiggestConnectedAreas(maxLabel){
labelHist = labelHist.map(function(val, idx) {
return {
val : val,
label : idx + 1
val: val,
label: idx + 1
};
});
@@ -301,7 +313,8 @@ function findBoxes(topLabels, maxLabel) {
patch = patches[j];
hsv[0] = (topLabels[i].label / (maxLabel + 1)) * 360;
CVUtils.hsv2rgb(hsv, rgb);
ImageDebug.drawRect(patch.pos, _subImageWrapper.size, _canvasContainer.ctx.binary, {color: "rgb(" + rgb.join(",") + ")", lineWidth: 2});
ImageDebug.drawRect(patch.pos, _subImageWrapper.size, _canvasContainer.ctx.binary,
{color: "rgb(" + rgb.join(",") + ")", lineWidth: 2});
}
}
}
@@ -349,12 +362,11 @@ function skeletonize(x, y) {
function describePatch(moments, patchPos, x, y) {
var k,
avg,
sum = 0,
eligibleMoments = [],
matchingMoments,
patch,
patchesFound = [],
minComponentWeight = Math.ceil(_patchSize.x/3);
minComponentWeight = Math.ceil(_patchSize.x / 3);
if (moments.length >= 2) {
// only collect moments which's area covers at least minComponentWeight pixels.
@@ -366,7 +378,6 @@ function describePatch(moments, patchPos, x, y) {
// if at least 2 moments are found which have at least minComponentWeights covered
if (eligibleMoments.length >= 2) {
sum = eligibleMoments.length;
matchingMoments = similarMoments(eligibleMoments);
avg = 0;
// determine the similarity of the moments
@@ -376,18 +387,25 @@ function describePatch(moments, patchPos, x, y) {
// Only two of the moments are allowed not to fit into the equation
// add the patch to the set
if (matchingMoments.length > 1 && matchingMoments.length >= (eligibleMoments.length / 4) * 3 && matchingMoments.length > moments.length / 4) {
if (matchingMoments.length > 1
&& matchingMoments.length >= (eligibleMoments.length / 4) * 3
&& matchingMoments.length > moments.length / 4) {
avg /= matchingMoments.length;
patch = {
index : patchPos[1] * _numPatches.x + patchPos[0],
pos : {
x : x,
y : y
index: patchPos[1] * _numPatches.x + patchPos[0],
pos: {
x: x,
y: y
},
box : [vec2.clone([x, y]), vec2.clone([x + _subImageWrapper.size.x, y]), vec2.clone([x + _subImageWrapper.size.x, y + _subImageWrapper.size.y]), vec2.clone([x, y + _subImageWrapper.size.y])],
moments : matchingMoments,
rad : avg,
vec : vec2.clone([Math.cos(avg), Math.sin(avg)])
box: [
vec2.clone([x, y]),
vec2.clone([x + _subImageWrapper.size.x, y]),
vec2.clone([x + _subImageWrapper.size.x, y + _subImageWrapper.size.y]),
vec2.clone([x, y + _subImageWrapper.size.y])
],
moments: matchingMoments,
rad: avg,
vec: vec2.clone([Math.cos(avg), Math.sin(avg)])
};
patchesFound.push(patch);
}
@@ -420,10 +438,17 @@ function rasterizeAngularSimilarity(patchesFound) {
}
function trace(currentIdx) {
var x, y, currentPatch, patch, idx, dir, current = {
x : currentIdx % _patchLabelGrid.size.x,
y : (currentIdx / _patchLabelGrid.size.x) | 0
}, similarity;
var x,
y,
currentPatch,
patch,
idx,
dir,
current = {
x: currentIdx % _patchLabelGrid.size.x,
y: (currentIdx / _patchLabelGrid.size.x) | 0
},
similarity;
if (currentIdx < _patchLabelGrid.data.length) {
currentPatch = _imageToPatchGrid.data[currentIdx];
@@ -477,7 +502,8 @@ function rasterizeAngularSimilarity(patchesFound) {
patch = _imageToPatchGrid.data[j];
hsv[0] = (_patchLabelGrid.data[j] / (label + 1)) * 360;
CVUtils.hsv2rgb(hsv, rgb);
ImageDebug.drawRect(patch.pos, _subImageWrapper.size, _canvasContainer.ctx.binary, {color: "rgb(" + rgb.join(",") + ")", lineWidth: 2});
ImageDebug.drawRect(patch.pos, _subImageWrapper.size, _canvasContainer.ctx.binary,
{color: "rgb(" + rgb.join(",") + ")", lineWidth: 2});
}
}
}
@@ -486,7 +512,7 @@ function rasterizeAngularSimilarity(patchesFound) {
}
export default {
init : function(inputImageWrapper, config) {
init: function(inputImageWrapper, config) {
_config = config;
_inputImageWrapper = inputImageWrapper;
@@ -494,10 +520,10 @@ export default {
initCanvas();
},
locate : function() {
locate: function() {
var patchesFound,
topLabels,
boxes;
topLabels,
boxes;
if (_config.halfSample) {
CVUtils.halfSample(_inputImageWrapper, _currentImageWrapper);
@@ -551,8 +577,8 @@ export default {
patchSize = CVUtils.calculatePatchSize(config.patchSize, size);
console.log("Patch-Size: " + JSON.stringify(patchSize));
inputStream.setWidth(Math.floor(Math.floor(size.x/patchSize.x)*(1/halfSample)*patchSize.x));
inputStream.setHeight(Math.floor(Math.floor(size.y/patchSize.y)*(1/halfSample)*patchSize.y));
inputStream.setWidth(Math.floor(Math.floor(size.x / patchSize.x) * (1 / halfSample) * patchSize.x));
inputStream.setHeight(Math.floor(Math.floor(size.y / patchSize.y) * (1 / halfSample) * patchSize.y));
if ((inputStream.getWidth() % patchSize.x) === 0 && (inputStream.getHeight() % patchSize.y) === 0) {
return true;
+10 -10
View File
@@ -32,7 +32,7 @@ BarcodeReader.prototype._matchPattern = function(counter, code) {
}
error += singleError;
}
return error/modulo;
return error / modulo;
};
BarcodeReader.prototype._nextSet = function(line, offset) {
@@ -73,7 +73,7 @@ BarcodeReader.prototype._normalize = function(counter, modulo) {
normalized.push(norm);
}
} else {
ratio = (sum + numOnes)/modulo;
ratio = (sum + numOnes) / modulo;
for (i = 0; i < counter.length; i++) {
norm = counter[i] / ratio;
normalized.push(norm);
@@ -90,9 +90,9 @@ BarcodeReader.prototype._matchTrace = function(cmpCounter, epsilon) {
isWhite = !self._row[offset],
counterPos = 0,
bestMatch = {
error : Number.MAX_VALUE,
code : -1,
start : 0
error: Number.MAX_VALUE,
code: -1,
start: 0
},
error;
@@ -207,14 +207,14 @@ Object.defineProperty(BarcodeReader.prototype, "FORMAT", {
});
BarcodeReader.DIRECTION = {
FORWARD : 1,
REVERSE : -1
FORWARD: 1,
REVERSE: -1
};
BarcodeReader.Exception = {
StartNotFoundException : "Start-Info was not found!",
CodeNotFoundException : "Code could not be found!",
PatternNotFoundException : "Pattern could not be found!"
StartNotFoundException: "Start-Info was not found!",
CodeNotFoundException: "Code could not be found!",
PatternNotFoundException: "Pattern could not be found!"
};
BarcodeReader.CONFIG_KEYS = {};
+17 -18
View File
@@ -4,9 +4,9 @@ import ImageWrapper from './image_wrapper';
var Bresenham = {};
var Slope = {
DIR : {
UP : 1,
DOWN : -1
DIR: {
UP: 1,
DOWN: -1
}
};
/**
@@ -71,7 +71,7 @@ Bresenham.getBarcodeLine = function(imageWrapper, p1, p2) {
y = y0;
ystep = y0 < y1 ? 1 : -1;
for ( x = x0; x < x1; x++) {
if(steep){
if (steep){
read(y, x);
} else {
read(x, y);
@@ -84,9 +84,9 @@ Bresenham.getBarcodeLine = function(imageWrapper, p1, p2) {
}
return {
line : line,
min : min,
max : max
line: line,
min: min,
max: max
};
};
@@ -110,7 +110,6 @@ Bresenham.toOtsuBinaryLine = function(result) {
* @param {Object} result {line, min, max}
*/
Bresenham.toBinaryLine = function(result) {
var min = result.min,
max = result.max,
line = result.line,
@@ -128,15 +127,15 @@ Bresenham.toBinaryLine = function(result) {
// 1. find extrema
currentDir = line[0] > center ? Slope.DIR.UP : Slope.DIR.DOWN;
extrema.push({
pos : 0,
val : line[0]
pos: 0,
val: line[0]
});
for ( i = 0; i < line.length - 2; i++) {
slope = (line[i + 1] - line[i]);
slope2 = (line[i + 2] - line[i + 1]);
if ((slope + slope2) < rThreshold && line[i + 1] < (center*1.5)) {
if ((slope + slope2) < rThreshold && line[i + 1] < (center * 1.5)) {
dir = Slope.DIR.DOWN;
} else if ((slope + slope2) > threshold && line[i + 1] > (center*0.5)) {
} else if ((slope + slope2) > threshold && line[i + 1] > (center * 0.5)) {
dir = Slope.DIR.UP;
} else {
dir = currentDir;
@@ -144,15 +143,15 @@ Bresenham.toBinaryLine = function(result) {
if (currentDir !== dir) {
extrema.push({
pos : i,
val : line[i]
pos: i,
val: line[i]
});
currentDir = dir;
}
}
extrema.push({
pos : line.length,
val : line[line.length - 1]
pos: line.length,
val: line[line.length - 1]
});
for ( j = extrema[0].pos; j < extrema[1].pos; j++) {
@@ -173,8 +172,8 @@ Bresenham.toBinaryLine = function(result) {
}
return {
line : line,
threshold : threshold
line: line,
threshold: threshold
};
};
+4 -4
View File
@@ -83,9 +83,9 @@ function normalizeConstraints(config, cb) {
if ( typeof MediaStreamTrack !== 'undefined' && typeof MediaStreamTrack.getSources !== 'undefined') {
MediaStreamTrack.getSources(function(sourceInfos) {
var videoSourceId;
for (var i = 0; i != sourceInfos.length; ++i) {
for (var i = 0; i < sourceInfos.length; ++i) {
var sourceInfo = sourceInfos[i];
if (sourceInfo.kind == "video" && sourceInfo.facing == videoConstraints.facing) {
if (sourceInfo.kind === "video" && sourceInfo.facing === videoConstraints.facing) {
videoSourceId = sourceInfo.id;
}
}
@@ -126,10 +126,10 @@ function request(video, videoConstraints, callback) {
}
export default {
request : function(video, constraints, callback) {
request: function(video, constraints, callback) {
request(video, constraints, callback);
},
release : function() {
release: function() {
var tracks = streamRef && streamRef.getVideoTracks();
if (tracks.length) {
tracks[0].stop();
+15 -13
View File
@@ -3,11 +3,13 @@ import {vec2} from 'gl-matrix';
* Creates a cluster for grouping similar orientations of datapoints
*/
export default {
create : function(point, threshold) {
var points = [], center = {
rad : 0,
vec : vec2.clone([0, 0])
}, pointMap = {};
create: function(point, threshold) {
var points = [],
center = {
rad: 0,
vec: vec2.clone([0, 0])
},
pointMap = {};
function init() {
add(point);
@@ -31,13 +33,13 @@ export default {
init();
return {
add : function(point) {
add: function(point) {
if (!pointMap[point.id]) {
add(point);
updateCenter();
}
},
fits : function(point) {
fits: function(point) {
// check cosine similarity to center-angle
var similarity = Math.abs(vec2.dot(point.point.vec, center.vec));
if (similarity > threshold) {
@@ -45,19 +47,19 @@ export default {
}
return false;
},
getPoints : function() {
getPoints: function() {
return points;
},
getCenter : function() {
getCenter: function() {
return center;
}
};
},
createPoint : function(point, id, property) {
createPoint: function(point, id, property) {
return {
rad : point[property],
point : point,
id : id
rad: point[property],
point: point,
id: id
};
}
};
+15 -12
View File
@@ -8,7 +8,8 @@ function CodabarReader() {
var properties = {
ALPHABETH_STRING: {value: "0123456789-$:/.+ABCD"},
ALPHABET: {value: [48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 45, 36, 58, 47, 46, 43, 65, 66, 67, 68]},
CHARACTER_ENCODINGS: {value: [0x003, 0x006, 0x009, 0x060, 0x012, 0x042, 0x021, 0x024, 0x030, 0x048, 0x00c, 0x018, 0x045, 0x051, 0x054, 0x015, 0x01A, 0x029, 0x00B, 0x00E]},
CHARACTER_ENCODINGS: {value: [0x003, 0x006, 0x009, 0x060, 0x012, 0x042, 0x021, 0x024, 0x030, 0x048, 0x00c, 0x018,
0x045, 0x051, 0x054, 0x015, 0x01A, 0x029, 0x00B, 0x00E]},
START_END: {value: [0x01A, 0x029, 0x00B, 0x00E]},
MIN_ENCODED_CHARS: {value: 4},
MAX_ACCEPTABLE: {value: 2.0},
@@ -49,7 +50,7 @@ CodabarReader.prototype._decode = function() {
if (result.length > 1 && self._isStartEnd(pattern)) {
break;
}
} while(nextStart < self._counters.length);
} while (nextStart < self._counters.length);
// verify end
if ((result.length - 2) < self.MIN_ENCODED_CHARS || !self._isStartEnd(pattern)) {
@@ -69,17 +70,19 @@ CodabarReader.prototype._decode = function() {
end = start.start + self._sumCounters(start.startCounter, nextStart - 8);
return {
code : result.join(""),
start : start.start,
end : end,
startInfo : start,
decodedCodes : result
code: result.join(""),
start: start.start,
end: end,
startInfo: start,
decodedCodes: result
};
};
CodabarReader.prototype._verifyWhitespace = function(startCounter, endCounter) {
if ((startCounter - 1 <= 0) || this._counters[startCounter-1] >= (this._calculatePatternLength(startCounter) / 2.0)) {
if ((endCounter + 8 >= this._counters.length) || this._counters[endCounter+7] >= (this._calculatePatternLength(endCounter) / 2.0)) {
if ((startCounter - 1 <= 0)
|| this._counters[startCounter - 1] >= (this._calculatePatternLength(startCounter) / 2.0)) {
if ((endCounter + 8 >= this._counters.length)
|| this._counters[endCounter + 7] >= (this._calculatePatternLength(endCounter) / 2.0)) {
return true;
}
}
@@ -120,7 +123,7 @@ CodabarReader.prototype._thresholdResultPattern = function(result, startCounter)
pattern = self._charToPattern(result[i]);
for (j = 6; j >= 0; j--) {
kind = (j & 1) === 2 ? categorization.bar : categorization.space;
cat = (pattern & 1) === 1 ? kind.wide : kind.narrow;
cat = (pattern & 1) === 1 ? kind.wide : kind.narrow;
cat.size += self._counters[pos + j];
cat.counts++;
pattern >>= 1;
@@ -130,7 +133,7 @@ CodabarReader.prototype._thresholdResultPattern = function(result, startCounter)
["space", "bar"].forEach(function(key) {
var kind = categorization[key];
kind.wide.min = Math.floor((kind.narrow.size/kind.narrow.counts + kind.wide.size / kind.wide.counts) / 2);
kind.wide.min = Math.floor((kind.narrow.size / kind.narrow.counts + kind.wide.size / kind.wide.counts) / 2);
kind.narrow.max = Math.ceil(kind.wide.min);
kind.wide.max = Math.ceil((kind.wide.size * self.MAX_ACCEPTABLE + self.PADDING) / kind.wide.counts);
});
@@ -166,7 +169,7 @@ CodabarReader.prototype._validateResult = function(result, startCounter) {
pattern = self._charToPattern(result[i]);
for (j = 6; j >= 0; j--) {
kind = (j & 1) === 0 ? thresholds.bar : thresholds.space;
cat = (pattern & 1) === 1 ? kind.wide : kind.narrow;
cat = (pattern & 1) === 1 ? kind.wide : kind.narrow;
size = self._counters[pos + j];
if (size < cat.min || size > cat.max) {
return false;
+34 -40
View File
@@ -5,16 +5,16 @@ function Code128Reader() {
}
var properties = {
CODE_SHIFT : {value: 98},
CODE_C : {value: 99},
CODE_B : {value: 100},
CODE_A : {value: 101},
START_CODE_A : {value: 103},
START_CODE_B : {value: 104},
START_CODE_C : {value: 105},
STOP_CODE : {value: 106},
MODULO : {value: 11},
CODE_PATTERN : {value: [
CODE_SHIFT: {value: 98},
CODE_C: {value: 99},
CODE_B: {value: 100},
CODE_A: {value: 101},
START_CODE_A: {value: 103},
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],
[2, 2, 2, 2, 2, 1],
@@ -139,10 +139,10 @@ Code128Reader.prototype._decodeCode = function(start) {
isWhite = !self._row[offset],
counterPos = 0,
bestMatch = {
error : Number.MAX_VALUE,
code : -1,
start : start,
end : start
error: Number.MAX_VALUE,
code: -1,
start: start,
end: start
},
code,
error,
@@ -183,10 +183,10 @@ Code128Reader.prototype._findStart = function() {
isWhite = false,
counterPos = 0,
bestMatch = {
error : Number.MAX_VALUE,
code : -1,
start : 0,
end : 0
error: Number.MAX_VALUE,
code: -1,
start: 0,
end: 0
},
code,
error,
@@ -247,20 +247,19 @@ Code128Reader.prototype._decode = function() {
rawResult = [],
decodedCodes = [],
shiftNext = false,
unshift,
lastCharacterWasPrintable;
unshift;
if (startInfo === null) {
return null;
}
code = {
code : startInfo.code,
start : startInfo.start,
end : startInfo.end
code: startInfo.code,
start: startInfo.start,
end: startInfo.end
};
decodedCodes.push(code);
checksum = code.code;
switch(code.code) {
switch (code.code) {
case self.START_CODE_A:
codeset = self.CODE_A;
break;
@@ -286,7 +285,7 @@ Code128Reader.prototype._decode = function() {
}
decodedCodes.push(code);
switch(codeset) {
switch (codeset) {
case self.CODE_A:
if (code.code < 64) {
result.push(String.fromCharCode(32 + code.code));
@@ -314,9 +313,6 @@ Code128Reader.prototype._decode = function() {
if (code.code < 96) {
result.push(String.fromCharCode(32 + code.code));
} else {
if (code.code != self.STOP_CODE) {
lastCharacterWasPrintable = false;
}
switch (code.code) {
case self.CODE_SHIFT:
shiftNext = true;
@@ -355,7 +351,7 @@ Code128Reader.prototype._decode = function() {
done = true;
}
if (unshift) {
codeset = codeset == self.CODE_A ? self.CODE_B : self.CODE_A;
codeset = codeset === self.CODE_A ? self.CODE_B : self.CODE_A;
}
}
@@ -365,14 +361,14 @@ Code128Reader.prototype._decode = function() {
// find end bar
code.end = self._nextUnset(self._row, code.end);
if(!self._verifyTrailingWhitespace(code)){
if (!self._verifyTrailingWhitespace(code)){
return null;
}
// checksum
// Does not work correctly yet!!! startcode - endcode?
checksum -= multiplier * rawResult[rawResult.length - 1];
if (checksum % 103 != rawResult[rawResult.length - 1]) {
if (checksum % 103 !== rawResult[rawResult.length - 1]) {
return null;
}
@@ -383,16 +379,14 @@ Code128Reader.prototype._decode = function() {
// remove last code from result (checksum)
result.splice(result.length - 1, 1);
return {
code : result.join(""),
start : startInfo.start,
end : code.end,
codeset : codeset,
startInfo : startInfo,
decodedCodes : decodedCodes,
endInfo : code
code: result.join(""),
start: startInfo.start,
end: code.end,
codeset: codeset,
startInfo: startInfo,
decodedCodes: decodedCodes,
endInfo: code
};
};
+16 -13
View File
@@ -7,8 +7,12 @@ function Code39Reader() {
var properties = {
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]},
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},
FORMAT: {value: "code_39", writeable: false}
};
@@ -45,7 +49,7 @@ Code39Reader.prototype._toCounters = function(start, counter) {
Code39Reader.prototype._decode = function() {
var self = this,
counters = [0,0,0,0,0,0,0,0,0],
counters = [0, 0, 0, 0, 0, 0, 0, 0, 0],
result = [],
start = self._findStart(),
decodedChar,
@@ -72,23 +76,23 @@ Code39Reader.prototype._decode = function() {
lastStart = nextStart;
nextStart += ArrayHelper.sum(counters);
nextStart = self._nextSet(self._row, nextStart);
} while(decodedChar !== '*');
} while (decodedChar !== '*');
result.pop();
if (!result.length) {
return null;
}
if(!self._verifyTrailingWhitespace(lastStart, nextStart, counters)) {
if (!self._verifyTrailingWhitespace(lastStart, nextStart, counters)) {
return null;
}
return {
code : result.join(""),
start : start.start,
end : nextStart,
startInfo : start,
decodedCodes : result
code: result.join(""),
start: start.start,
end: nextStart,
startInfo: start,
decodedCodes: result
};
};
@@ -136,7 +140,7 @@ Code39Reader.prototype._toPattern = function(counters) {
pattern,
i;
while(numWideBars > 3) {
while (numWideBars > 3) {
maxNarrowWidth = self._findNextWidth(counters, maxNarrowWidth);
numWideBars = 0;
pattern = 0;
@@ -167,7 +171,7 @@ Code39Reader.prototype._findStart = function() {
var self = this,
offset = self._nextSet(self._row),
patternStart = offset,
counter = [0,0,0,0,0,0,0,0,0],
counter = [0, 0, 0, 0, 0, 0, 0, 0, 0],
counterPos = 0,
isWhite = false,
i,
@@ -179,7 +183,6 @@ Code39Reader.prototype._findStart = function() {
counter[counterPos]++;
} else {
if (counterPos === counter.length - 1) {
// find start pattern
if (self._toPattern(counter) === self.ASTERISK) {
whiteSpaceMustStart = Math.floor(Math.max(0, patternStart - ((i - patternStart) / 4)));
+23 -26
View File
@@ -3,31 +3,28 @@
* Normalizes browser-specific prefixes
*/
if (typeof window !== 'undefined') {
window.requestAnimFrame = (function () {
return window.requestAnimationFrame ||
window.webkitRequestAnimationFrame ||
window.mozRequestAnimationFrame ||
window.oRequestAnimationFrame ||
window.msRequestAnimationFrame ||
function (/* function FrameRequestCallback */ callback, /* DOMElement Element */ element) {
window.setTimeout(callback, 1000 / 60);
};
})();
if (typeof window !== 'undefined') {
window.requestAnimFrame = (function () {
return window.requestAnimationFrame ||
window.webkitRequestAnimationFrame ||
window.mozRequestAnimationFrame ||
window.oRequestAnimationFrame ||
window.msRequestAnimationFrame ||
function (/* function FrameRequestCallback */ callback) {
window.setTimeout(callback, 1000 / 60);
};
})();
navigator.getUserMedia = navigator.getUserMedia || navigator.webkitGetUserMedia || navigator.mozGetUserMedia || navigator.msGetUserMedia;
window.URL = window.URL || window.webkitURL || window.mozURL || window.msURL;
}
Math.imul = Math.imul || function(a, b) {
var ah = (a >>> 16) & 0xffff,
al = a & 0xffff,
bh = (b >>> 16) & 0xffff,
bl = b & 0xffff;
// the shift by 0 fixes the sign on the high part
// the final |0 converts the unsigned value into a signed value
return ((al * bl) + (((ah * bl + al * bh) << 16) >>> 0)|0);
};
export default {
navigator.getUserMedia = navigator.getUserMedia ||
navigator.webkitGetUserMedia || navigator.mozGetUserMedia || navigator.msGetUserMedia;
window.URL = window.URL || window.webkitURL || window.mozURL || window.msURL;
}
Math.imul = Math.imul || function(a, b) {
var ah = (a >>> 16) & 0xffff,
al = a & 0xffff,
bh = (b >>> 16) & 0xffff,
bl = b & 0xffff;
// the shift by 0 fixes the sign on the high part
// the final |0 converts the unsigned value into a signed value
return ((al * bl) + (((ah * bl + al * bh) << 16) >>> 0) | 0);
};
+2 -2
View File
@@ -14,12 +14,12 @@ UPCReader.prototype.constructor = UPCReader;
UPCReader.prototype._decode = function() {
var result = EANReader.prototype._decode.call(this);
console.log("result", result);
if (result && result.code && result.code.length === 13 && result.code.charAt(0) === "0") {
result.code = result.code.substring(1);
return result;
}
return null;
};
export default EANReader;
export default UPCReader;
File diff suppressed because one or more lines are too long