Initial migration to webpack

pull/72/head
Christoph Oberhofer 10 years ago
parent a852394bd9
commit 38da5b0d41

@ -11,49 +11,8 @@ module.exports = function(grunt) {
configFile: 'karma-integration.conf.js'
}
},
uglify : {
options : {
banner : '/*! <%= pkg.name %> <%= grunt.template.today("yyyy-mm-dd") %> */\n',
preserveComments: 'some'
},
build : {
src : 'dist/<%= pkg.name %>.js',
dest : 'dist/<%= pkg.name %>.min.js'
}
},
jshint : {
all : ['Gruntfile.js', 'src/*.js']
},
requirejs : {
compile : {
options : {
almond : true,
wrap : {
startFile : 'build/start.frag',
endFile : 'build/end.frag'
},
"baseUrl" : "src",
"name" : "quagga",
"useStrict": true,
"out" : "dist/quagga.js",
"include" : ['quagga'],
"optimize" : "none",
"findNestedDependencies" : true,
"skipSemiColonInsertion" : true,
"shim" : {
"typedefs" : {
"deps" : [],
"exports" : "typedefs"
}
},
"paths" : {
"typedefs" : "typedefs",
"gl-matrix": "../node_modules/gl-matrix/dist/gl-matrix-min"
}
}
}
}
});

14632
dist/quagga.js vendored

File diff suppressed because one or more lines are too long

1
dist/quagga.map vendored

File diff suppressed because one or more lines are too long

17
dist/quagga.min.js vendored

File diff suppressed because one or more lines are too long

@ -6,6 +6,9 @@
"browser": "dist/quagga.js",
"devDependencies": {
"async": "^1.4.2",
"babel-core": "^5.8.25",
"babel-eslint": "^4.1.3",
"babel-loader": "^5.3.2",
"chai": "^3.2.0",
"grunt": "^0.4.5",
"grunt-contrib-jshint": "^0.11.3",
@ -23,7 +26,9 @@
"karma-sinon": "^1.0.4",
"karma-sinon-chai": "~0.2.0",
"mocha": "^2.3.2",
"sinon": "^1.16.1"
"sinon": "^1.16.1",
"webpack": "^1.12.2",
"webpack-core": "^0.6.7"
},
"directories": {
"doc": "doc"
@ -56,8 +61,8 @@
"dependencies": {
"get-pixels": "^3.2.3",
"gl-matrix": "^2.3.1",
"lodash": "^3.10.1",
"ndarray": "^1.0.18",
"ndarray-linear-interpolate": "^1.0.0",
"requirejs": "^2.1.20"
"ndarray-linear-interpolate": "^1.0.0"
}
}

@ -0,0 +1,35 @@
var ConcatSource = require("webpack-core/lib/ConcatSource");
var OriginalSource = require("webpack-core/lib/OriginalSource");
function MyUmdPlugin(options) {
this.name = options.library;
console.log(this.name);
}
module.exports = MyUmdPlugin;
MyUmdPlugin.prototype.apply = function(compiler) {
compiler.plugin("this-compilation", function(compilation) {
var mainTemplate = compilation.mainTemplate;
console.log("Compilation: " + (typeof compilation.templatesPlugin));
compilation.templatesPlugin("render-with-entry", function(source, chunk, hash) {
var amdFactory = "factory";
return new ConcatSource(new OriginalSource(
"(function webpackUniversalModuleDefinition(root, factory) {\n" +
" if(typeof exports === 'object' && typeof module === 'object')\n" +
" module.exports = factory(factory.toString());\n" +
" else if(typeof exports === 'object')\n" +
" exports[\"" + this.name + "\"] = factory(factory.toString());\n" +
" else\n" +
" root[\"" + this.name + "\"] = factory(factory.toString());\n" +
"})(this, function(__factorySource__) {\nreturn ", "webpack/myModuleDefinition"), source, "\n});\n");
}.bind(this));
mainTemplate.plugin("global-hash-paths", function(paths) {
if(this.name) paths = paths.concat(this.name);
return paths;
}.bind(this));
mainTemplate.plugin("hash", function(hash) {
hash.update("umd");
hash.update(this.name + "");
}.bind(this));
}.bind(this));
};

@ -1,10 +1,4 @@
/* jshint undef: true, unused: true, browser:true, devel: true */
/* global define */
define(function() {
"use strict";
return {
export default {
init : function(arr, val) {
var l = arr.length;
while (l--) {
@ -82,5 +76,4 @@ define(function() {
}
return sum;
}
};
});
};

@ -1,33 +1,16 @@
/* jshint undef: true, unused: true, browser:true, devel: true */
/* global define */
import Bresenham from './bresenham';
import ImageDebug from './image_debug';
import Code128Reader from './code_128_reader';
import EANReader from './ean_reader';
import Code39Reader from './code_39_reader';
import Code39VINReader from './code_39_vin_reader';
import CodabarReader from './codabar_reader';
import UPCReader from './upc_reader';
import EAN8Reader from './ean_8_reader';
import UPCEReader from './upc_e_reader';
import I2of5Reader from './i2of5_reader';
define([
"bresenham",
"image_debug",
'code_128_reader',
'ean_reader',
'code_39_reader',
'code_39_vin_reader',
'codabar_reader',
'upc_reader',
'ean_8_reader',
'upc_e_reader',
'i2of5_reader'
], function(
Bresenham,
ImageDebug,
Code128Reader,
EANReader,
Code39Reader,
Code39VINReader,
CodabarReader,
UPCReader,
EAN8Reader,
UPCEReader,
I2of5Reader) {
"use strict";
var readers = {
var readers = {
code_128_reader: Code128Reader,
ean_reader: EANReader,
ean_8_reader: EAN8Reader,
@ -37,8 +20,8 @@ define([
upc_reader: UPCReader,
upc_e_reader: UPCEReader,
i2of5_reader: I2of5Reader
};
var BarcodeDecoder = {
};
export default {
create : function(config, inputImageWrapper) {
var _canvas = {
ctx : {
@ -299,7 +282,4 @@ define([
}
};
}
};
return (BarcodeDecoder);
});
};

@ -1,10 +1,16 @@
/* jshint undef: true, unused: true, browser:true, devel: true */
/* global define */
define("barcode_locator", ["image_wrapper", "cv_utils", "rasterizer", "tracer", "skeletonizer", "array_helper", "image_debug", "gl-matrix"],
function(ImageWrapper, CVUtils, Rasterizer, Tracer, skeletonizer, ArrayHelper, ImageDebug, glMatrix) {
var _config,
import ImageWrapper from './image_wrapper';
import CVUtils from './cv_utils';
import Rasterizer from './rasterizer';
import Tracer from './tracer';
import skeletonizer from './skeletonizer';
import ArrayHelper from './array_helper';
import ImageDebug from './image_debug';
import glMatrix from 'gl-matrix';
var _config,
_currentImageWrapper,
_skelImageWrapper,
_subImageWrapper,
@ -27,9 +33,9 @@ function(ImageWrapper, CVUtils, Rasterizer, Tracer, skeletonizer, ArrayHelper, I
_skeletonizer,
vec2 = glMatrix.vec2,
mat2 = glMatrix.mat2,
self = this;
self = (typeof window !== 'undefined') ? window : self;
function initBuffers() {
function initBuffers() {
var skeletonImageData;
if (_config.halfSample) {
@ -63,9 +69,9 @@ function(ImageWrapper, CVUtils, Rasterizer, Tracer, skeletonizer, ArrayHelper, I
}, undefined, Array, true);
_patchGrid = new ImageWrapper(_imageToPatchGrid.size, undefined, undefined, true);
_patchLabelGrid = new ImageWrapper(_imageToPatchGrid.size, undefined, Int32Array, true);
}
}
function initCanvas() {
function initCanvas() {
if (_config.useWorker || typeof document === 'undefined') {
return;
}
@ -77,13 +83,13 @@ function(ImageWrapper, CVUtils, Rasterizer, Tracer, skeletonizer, ArrayHelper, I
_canvasContainer.ctx.binary = _canvasContainer.dom.binary.getContext("2d");
_canvasContainer.dom.binary.width = _binaryImageWrapper.size.x;
_canvasContainer.dom.binary.height = _binaryImageWrapper.size.y;
}
}
/**
/**
* Creates a bounding box which encloses all the given patches
* @returns {Array} The minimal bounding box
*/
function boxFromPatches(patches) {
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;
// draw all patches which are to be taken into consideration
@ -158,24 +164,24 @@ function(ImageWrapper, CVUtils, Rasterizer, Tracer, skeletonizer, ArrayHelper, I
}
return box;
}
}
/**
/**
* Creates a binary image of the current image
*/
function binarizeImage() {
function binarizeImage() {
CVUtils.otsuThreshold(_currentImageWrapper, _binaryImageWrapper);
_binaryImageWrapper.zeroBorder();
if (_config.showCanvas) {
_binaryImageWrapper.show(_canvasContainer.dom.binary, 255);
}
}
}
/**
/**
* Iterate over the entire image
* extract patches
*/
function findPatches() {
function findPatches() {
var i,
j,
x,
@ -220,14 +226,14 @@ function(ImageWrapper, CVUtils, Rasterizer, Tracer, skeletonizer, ArrayHelper, I
}
return patchesFound;
}
}
/**
/**
* Finds those connected areas which contain at least 6 patches
* and returns them ordered DESC by the number of contained patches
* @param {Number} maxLabel
*/
function findBiggestConnectedAreas(maxLabel){
function findBiggestConnectedAreas(maxLabel){
var i,
sum,
labelHist = [],
@ -260,12 +266,12 @@ function(ImageWrapper, CVUtils, Rasterizer, Tracer, skeletonizer, ArrayHelper, I
});
return topLabels;
}
}
/**
/**
*
*/
function findBoxes(topLabels, maxLabel) {
function findBoxes(topLabels, maxLabel) {
var i,
j,
sum,
@ -301,13 +307,13 @@ function(ImageWrapper, CVUtils, Rasterizer, Tracer, skeletonizer, ArrayHelper, I
}
}
return boxes;
}
}
/**
/**
* Find similar moments (via cluster)
* @param {Object} moments
*/
function similarMoments(moments) {
function similarMoments(moments) {
var clusters = CVUtils.cluster(moments, 0.90);
var topCluster = CVUtils.topGeneric(clusters, 1, function(e) {
return e.getPoints().length;
@ -320,9 +326,9 @@ function(ImageWrapper, CVUtils, Rasterizer, Tracer, skeletonizer, ArrayHelper, I
}
}
return result;
}
}
function skeletonize(x, y) {
function skeletonize(x, y) {
_binaryImageWrapper.subImageAsCopy(_subImageWrapper, CVUtils.imageRef(x, y));
_skeletonizer.skeletonize();
@ -330,9 +336,9 @@ function(ImageWrapper, CVUtils, Rasterizer, Tracer, skeletonizer, ArrayHelper, I
if (_config.showSkeleton) {
_skelImageWrapper.overlay(_canvasContainer.dom.binary, 360, CVUtils.imageRef(x, y));
}
}
}
/**
/**
* Extracts and describes those patches which seem to contain a barcode pattern
* @param {Array} moments
* @param {Object} patchPos,
@ -340,7 +346,7 @@ function(ImageWrapper, CVUtils, Rasterizer, Tracer, skeletonizer, ArrayHelper, I
* @param {Number} y
* @returns {Array} list of patches
*/
function describePatch(moments, patchPos, x, y) {
function describePatch(moments, patchPos, x, y) {
var k,
avg,
sum = 0,
@ -388,13 +394,13 @@ function(ImageWrapper, CVUtils, Rasterizer, Tracer, skeletonizer, ArrayHelper, I
}
}
return patchesFound;
}
}
/**
/**
* finds patches which are connected and share the same orientation
* @param {Object} patchesFound
*/
function rasterizeAngularSimilarity(patchesFound) {
function rasterizeAngularSimilarity(patchesFound) {
var label = 0,
threshold = 0.95,
currIdx = 0,
@ -477,9 +483,9 @@ function(ImageWrapper, CVUtils, Rasterizer, Tracer, skeletonizer, ArrayHelper, I
}
return label;
}
}
return {
export default {
init : function(inputImageWrapper, config) {
_config = config;
_inputImageWrapper = inputImageWrapper;
@ -556,6 +562,4 @@ function(ImageWrapper, CVUtils, Rasterizer, Tracer, skeletonizer, ArrayHelper, I
width + " )and height (" + height +
") must a multiple of " + patchSize.x);
}
};
});
};

@ -1,17 +1,10 @@
/* jshint undef: true, unused: true, browser:true, devel: true */
/* global define */
define(
function() {
"use strict";
function BarcodeReader(config) {
function BarcodeReader(config) {
this._row = [];
this.config = config || {};
return this;
}
}
BarcodeReader.prototype._nextUnset = function(line, start) {
BarcodeReader.prototype._nextUnset = function(line, start) {
var i;
if (start === undefined) {
@ -23,9 +16,9 @@ define(
}
}
return line.length;
};
};
BarcodeReader.prototype._matchPattern = function(counter, code) {
BarcodeReader.prototype._matchPattern = function(counter, code) {
var i,
error = 0,
singleError = 0,
@ -40,9 +33,9 @@ define(
error += singleError;
}
return error/modulo;
};
};
BarcodeReader.prototype._nextSet = function(line, offset) {
BarcodeReader.prototype._nextSet = function(line, offset) {
var i;
offset = offset || 0;
@ -52,9 +45,9 @@ define(
}
}
return line.length;
};
};
BarcodeReader.prototype._normalize = function(counter, modulo) {
BarcodeReader.prototype._normalize = function(counter, modulo) {
var i,
self = this,
sum = 0,
@ -87,9 +80,9 @@ define(
}
}
return normalized;
};
};
BarcodeReader.prototype._matchTrace = function(cmpCounter, epsilon) {
BarcodeReader.prototype._matchTrace = function(cmpCounter, epsilon) {
var counter = [],
i,
self = this,
@ -148,9 +141,9 @@ define(
bestMatch.end = self._row.length - 1;
bestMatch.counter = counter;
return bestMatch;
};
};
BarcodeReader.prototype.decodePattern = function(pattern) {
BarcodeReader.prototype.decodePattern = function(pattern) {
var self = this,
result;
@ -171,9 +164,9 @@ define(
result.format = self.FORMAT;
}
return result;
};
};
BarcodeReader.prototype._matchRange = function(start, end, value) {
BarcodeReader.prototype._matchRange = function(start, end, value) {
var i;
start = start < 0 ? 0 : start;
@ -183,9 +176,9 @@ define(
}
}
return true;
};
};
BarcodeReader.prototype._fillCounters = function(offset, end, isWhite) {
BarcodeReader.prototype._fillCounters = function(offset, end, isWhite) {
var self = this,
counterPos = 0,
i,
@ -206,26 +199,24 @@ define(
}
}
return counters;
};
};
Object.defineProperty(BarcodeReader.prototype, "FORMAT", {
Object.defineProperty(BarcodeReader.prototype, "FORMAT", {
value: 'unknown',
writeable: false
});
});
BarcodeReader.DIRECTION = {
BarcodeReader.DIRECTION = {
FORWARD : 1,
REVERSE : -1
};
};
BarcodeReader.Exception = {
BarcodeReader.Exception = {
StartNotFoundException : "Start-Info was not found!",
CodeNotFoundException : "Code could not be found!",
PatternNotFoundException : "Pattern could not be found!"
};
};
BarcodeReader.CONFIG_KEYS = {};
BarcodeReader.CONFIG_KEYS = {};
return (BarcodeReader);
}
);
export default BarcodeReader;

@ -1,17 +1,15 @@
/* jshint undef: true, unused: true, browser:true, devel: true */
/* global define */
import CVUtils from './cv_utils';
import ImageWrapper from './image_wrapper';
define(["cv_utils", "image_wrapper"], function(CVUtils, ImageWrapper) {
"use strict";
var Bresenham = {};
var Bresenham = {};
var Slope = {
var Slope = {
DIR : {
UP : 1,
DOWN : -1
}
};
/**
};
/**
* Scans a line of the given image from point p1 to p2 and returns a result object containing
* gray-scale values (0-255) of the underlying pixels in addition to the min
* and max values.
@ -20,7 +18,7 @@ define(["cv_utils", "image_wrapper"], function(CVUtils, ImageWrapper) {
* @param {Object} p2 The end point {x,y}
* @returns {line, min, max}
*/
Bresenham.getBarcodeLine = function(imageWrapper, p1, p2) {
Bresenham.getBarcodeLine = function(imageWrapper, p1, p2) {
var x0 = p1.x | 0,
y0 = p1.y | 0,
x1 = p2.x | 0,
@ -90,9 +88,9 @@ define(["cv_utils", "image_wrapper"], function(CVUtils, ImageWrapper) {
min : min,
max : max
};
};
};
Bresenham.toOtsuBinaryLine = function(result) {
Bresenham.toOtsuBinaryLine = function(result) {
var line = result.line,
image = new ImageWrapper({x: line.length - 1, y: 1}, line),
threshold = CVUtils.determineOtsuThreshold(image, 5);
@ -104,14 +102,14 @@ define(["cv_utils", "image_wrapper"], function(CVUtils, ImageWrapper) {
line: line,
threshold: threshold
};
};
};
/**
/**
* Converts the result from getBarcodeLine into a binary representation
* also considering the frequency and slope of the signal for more robust results
* @param {Object} result {line, min, max}
*/
Bresenham.toBinaryLine = function(result) {
Bresenham.toBinaryLine = function(result) {
var min = result.min,
max = result.max,
@ -178,12 +176,12 @@ define(["cv_utils", "image_wrapper"], function(CVUtils, ImageWrapper) {
line : line,
threshold : threshold
};
};
};
/**
/**
* Used for development only
*/
Bresenham.debug = {
Bresenham.debug = {
printFrequency: function(line, canvas) {
var i,
ctx = canvas.getContext("2d");
@ -211,7 +209,6 @@ define(["cv_utils", "image_wrapper"], function(CVUtils, ImageWrapper) {
}
}
}
};
};
return (Bresenham);
});
export default Bresenham;

@ -1,18 +1,15 @@
/* jshint undef: true, unused: true, browser:true, devel: true */
/* global define, MediaStreamTrack */
const merge = require('lodash/object/merge');
define(["html_utils"], function(HtmlUtils) {
"use strict";
var streamRef,
var streamRef,
loadedDataHandler;
/**
/**
* Wraps browser-specific getUserMedia
* @param {Object} constraints
* @param {Object} success Callback
* @param {Object} failure Callback
*/
function getUserMedia(constraints, success, failure) {
function getUserMedia(constraints, success, failure) {
if (typeof navigator.getUserMedia !== 'undefined') {
navigator.getUserMedia(constraints, function (stream) {
streamRef = stream;
@ -22,9 +19,9 @@ define(["html_utils"], function(HtmlUtils) {
} else {
failure(new TypeError("getUserMedia not available"));
}
}
}
function loadedData(video, callback) {
function loadedData(video, callback) {
var attempts = 10;
function checkVideo() {
@ -41,16 +38,16 @@ define(["html_utils"], function(HtmlUtils) {
attempts--;
}
checkVideo();
}
}
/**
/**
* Tries to attach the camera-stream to a given video-element
* and calls the callback function when the content is ready
* @param {Object} constraints
* @param {Object} video
* @param {Object} callback
*/
function initCamera(constraints, video, callback) {
function initCamera(constraints, video, callback) {
getUserMedia(constraints, function(src) {
video.src = src;
if (loadedDataHandler) {
@ -62,20 +59,20 @@ define(["html_utils"], function(HtmlUtils) {
}, function(e) {
callback(e);
});
}
}
/**
/**
* Normalizes the incoming constraints to satisfy the current browser
* @param config
* @param cb Callback which is called whenever constraints are created
* @returns {*}
*/
function normalizeConstraints(config, cb) {
function normalizeConstraints(config, cb) {
var constraints = {
audio: false,
video: true
},
videoConstraints = HtmlUtils.mergeObjects({
videoConstraints = merge({
width: 640,
height: 480,
minAspectRatio: 0,
@ -114,21 +111,21 @@ define(["html_utils"], function(HtmlUtils) {
};
return cb(constraints);
}
}
}
/**
/**
* Requests the back-facing camera of the user. The callback is called
* whenever the stream is ready to be consumed, or if an error occures.
* @param {Object} video
* @param {Object} callback
*/
function request(video, videoConstraints, callback) {
function request(video, videoConstraints, callback) {
normalizeConstraints(videoConstraints, function(constraints) {
initCamera(constraints, video, callback);
});
}
}
return {
export default {
request : function(video, constraints, callback) {
request(video, constraints, callback);
},
@ -139,5 +136,4 @@ define(["html_utils"], function(HtmlUtils) {
}
streamRef = null;
}
};
});
};

@ -1,14 +1,8 @@
/* jshint undef: true, unused: true, browser:true, devel: true */
/* global define */
define(["gl-matrix"], function(glMatrix) {
"use strict";
var vec2 = glMatrix.vec2;
import {vec2} from 'gl-matrix';
/**
* Creates a cluster for grouping similar orientations of datapoints
*/
var Cluster = {
export default {
create : function(point, threshold) {
var points = [], center = {
rad : 0,
@ -66,7 +60,4 @@ define(["gl-matrix"], function(glMatrix) {
id : id
};
}
};
return (Cluster);
});
};

@ -1,19 +1,11 @@
/* jshint undef: true, unused: true, browser:true, devel: true */
/* global define */
import BarcodeReader from './barcode_reader';
define(
[
"./barcode_reader"
],
function(BarcodeReader) {
"use strict";
function CodabarReader() {
function CodabarReader() {
BarcodeReader.call(this);
this._counters = [];
}
}
var properties = {
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]},
@ -22,12 +14,12 @@ define(
MAX_ACCEPTABLE: {value: 2.0},
PADDING: {value: 1.5},
FORMAT: {value: "codabar", writeable: false}
};
};
CodabarReader.prototype = Object.create(BarcodeReader.prototype, properties);
CodabarReader.prototype.constructor = CodabarReader;
CodabarReader.prototype = Object.create(BarcodeReader.prototype, properties);
CodabarReader.prototype.constructor = CodabarReader;
CodabarReader.prototype._decode = function() {
CodabarReader.prototype._decode = function() {
var self = this,
result = [],
start,
@ -83,18 +75,18 @@ define(
startInfo : start,
decodedCodes : result
};
};
};
CodabarReader.prototype._verifyWhitespace = function(startCounter, endCounter) {
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)) {
return true;
}
}
return false;
};
};
CodabarReader.prototype._calculatePatternLength = function(offset) {
CodabarReader.prototype._calculatePatternLength = function(offset) {
var i,
sum = 0;
@ -103,9 +95,9 @@ define(
}
return sum;
};
};
CodabarReader.prototype._thresholdResultPattern = function(result, startCounter){
CodabarReader.prototype._thresholdResultPattern = function(result, startCounter){
var self = this,
categorization = {
space: {
@ -144,9 +136,9 @@ define(
});
return categorization;
};
};
CodabarReader.prototype._charToPattern = function(char) {
CodabarReader.prototype._charToPattern = function(char) {
var self = this,
charCode = char.charCodeAt(0),
i;
@ -157,9 +149,9 @@ define(
}
}
return 0x0;
};
};
CodabarReader.prototype._validateResult = function(result, startCounter) {
CodabarReader.prototype._validateResult = function(result, startCounter) {
var self = this,
thresholds = self._thresholdResultPattern(result, startCounter),
i,
@ -184,9 +176,9 @@ define(
pos += 8;
}
return true;
};
};
CodabarReader.prototype._patternToChar = function(pattern) {
CodabarReader.prototype._patternToChar = function(pattern) {
var i,
self = this;
@ -196,9 +188,9 @@ define(
}
}
return -1;
};
};
CodabarReader.prototype._computeAlternatingThreshold = function(offset, end) {
CodabarReader.prototype._computeAlternatingThreshold = function(offset, end) {
var i,
min = Number.MAX_VALUE,
max = 0,
@ -215,9 +207,9 @@ define(
}
return ((min + max) / 2.0) | 0;
};
};
CodabarReader.prototype._toPattern = function(offset) {
CodabarReader.prototype._toPattern = function(offset) {
var numCounters = 7,
end = offset + numCounters,
barThreshold,
@ -243,9 +235,9 @@ define(
}
return pattern;
};
};
CodabarReader.prototype._isStartEnd = function(pattern) {
CodabarReader.prototype._isStartEnd = function(pattern) {
var i;
for (i = 0; i < this.START_END.length; i++) {
@ -254,9 +246,9 @@ define(
}
}
return false;
};
};
CodabarReader.prototype._sumCounters = function(start, end) {
CodabarReader.prototype._sumCounters = function(start, end) {
var i,
sum = 0;
@ -264,9 +256,9 @@ define(
sum += this._counters[i];
}
return sum;
};
};
CodabarReader.prototype._findStart = function() {
CodabarReader.prototype._findStart = function() {
var self = this,
i,
pattern,
@ -287,8 +279,6 @@ define(
};
}
}
};
};
return (CodabarReader);
}
);
export default CodabarReader;

@ -1,18 +1,10 @@
/* jshint undef: true, unused: true, browser:true, devel: true */
/* global define */
import BarcodeReader from './barcode_reader';
define(
[
"./barcode_reader"
],
function(BarcodeReader) {
"use strict";
function Code128Reader() {
function Code128Reader() {
BarcodeReader.call(this);
}
}
var properties = {
var properties = {
CODE_SHIFT : {value: 98},
CODE_C : {value: 99},
CODE_B : {value: 100},
@ -134,12 +126,12 @@ define(
SINGLE_CODE_ERROR: {value: 1},
AVG_CODE_ERROR: {value: 0.5},
FORMAT: {value: "code_128", writeable: false}
};
};
Code128Reader.prototype = Object.create(BarcodeReader.prototype, properties);
Code128Reader.prototype.constructor = Code128Reader;
Code128Reader.prototype = Object.create(BarcodeReader.prototype, properties);
Code128Reader.prototype.constructor = Code128Reader;
Code128Reader.prototype._decodeCode = function(start) {
Code128Reader.prototype._decodeCode = function(start) {
var counter = [0, 0, 0, 0, 0, 0],
i,
self = this,
@ -181,9 +173,9 @@ define(
}
}
return null;
};
};
Code128Reader.prototype._findStart = function() {
Code128Reader.prototype._findStart = function() {
var counter = [0, 0, 0, 0, 0, 0],
i,
self = this,
@ -241,9 +233,9 @@ define(
}
}
return null;
};
};
Code128Reader.prototype._decode = function() {
Code128Reader.prototype._decode = function() {
var self = this,
startInfo = self._findStart(),
code = null,
@ -402,10 +394,10 @@ define(
decodedCodes : decodedCodes,
endInfo : code
};
};
};
BarcodeReader.prototype._verifyTrailingWhitespace = function(endInfo) {
BarcodeReader.prototype._verifyTrailingWhitespace = function(endInfo) {
var self = this,
trailingWhitespaceEnd;
@ -416,8 +408,6 @@ define(
}
}
return null;
};
};
return (Code128Reader);
}
);
export default Code128Reader;

@ -1,30 +1,22 @@
/* jshint undef: true, unused: true, browser:true, devel: true */
/* global define */
define(
[
"./barcode_reader",
"./array_helper"
],
function(BarcodeReader, ArrayHelper) {
"use strict";
function Code39Reader() {
import BarcodeReader from './barcode_reader';
import ArrayHelper from './array_helper';
function Code39Reader() {
BarcodeReader.call(this);
}
}
var properties = {
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]},
ASTERISK: {value: 0x094},
FORMAT: {value: "code_39", writeable: false}
};
};
Code39Reader.prototype = Object.create(BarcodeReader.prototype, properties);
Code39Reader.prototype.constructor = Code39Reader;
Code39Reader.prototype = Object.create(BarcodeReader.prototype, properties);
Code39Reader.prototype.constructor = Code39Reader;
Code39Reader.prototype._toCounters = function(start, counter) {
Code39Reader.prototype._toCounters = function(start, counter) {
var self = this,
numCounters = counter.length,
end = self._row.length,
@ -49,9 +41,9 @@ define(
}
return counter;
};
};
Code39Reader.prototype._decode = function() {
Code39Reader.prototype._decode = function() {
var self = this,
counters = [0,0,0,0,0,0,0,0,0],
result = [],
@ -98,9 +90,9 @@ define(
startInfo : start,
decodedCodes : result
};
};
};
Code39Reader.prototype._verifyTrailingWhitespace = function(lastStart, nextStart, counters) {
Code39Reader.prototype._verifyTrailingWhitespace = function(lastStart, nextStart, counters) {
var trailingWhitespaceEnd,
patternSize = ArrayHelper.sum(counters);
@ -109,9 +101,9 @@ define(
return true;
}
return false;
};
};
Code39Reader.prototype._patternToChar = function(pattern) {
Code39Reader.prototype._patternToChar = function(pattern) {
var i,
self = this;
@ -120,9 +112,9 @@ define(
return String.fromCharCode(self.ALPHABET[i]);
}
}
};
};
Code39Reader.prototype._findNextWidth = function(counters, current) {
Code39Reader.prototype._findNextWidth = function(counters, current) {
var i,
minWidth = Number.MAX_VALUE;
@ -133,9 +125,9 @@ define(
}
return minWidth;
};
};
Code39Reader.prototype._toPattern = function(counters) {
Code39Reader.prototype._toPattern = function(counters) {
var numCounters = counters.length,
maxNarrowWidth = 0,
numWideBars = numCounters,
@ -169,9 +161,9 @@ define(
}
}
return -1;
};
};
Code39Reader.prototype._findStart = function() {
Code39Reader.prototype._findStart = function() {
var self = this,
offset = self._nextSet(self._row),
patternStart = offset,
@ -214,8 +206,6 @@ define(
}
}
return null;
};
};
return (Code39Reader);
}
);
export default Code39Reader;

@ -1,28 +1,20 @@
/* jshint undef: true, unused: true, browser:true, devel: true */
/* global define */
import Code39Reader from './code_39_reader';
define(
[
"./code_39_reader"
],
function(Code39Reader) {
"use strict";
function Code39VINReader() {
function Code39VINReader() {
Code39Reader.call(this);
}
}
var patterns = {
var patterns = {
IOQ: /[IOQ]/g,
AZ09: /[A-Z0-9]{17}/
};
};
Code39VINReader.prototype = Object.create(Code39Reader.prototype);
Code39VINReader.prototype.constructor = Code39VINReader;
Code39VINReader.prototype = Object.create(Code39Reader.prototype);
Code39VINReader.prototype.constructor = Code39VINReader;
// Cribbed from:
// https://github.com/zxing/zxing/blob/master/core/src/main/java/com/google/zxing/client/result/VINResultParser.java
Code39VINReader.prototype._decode = function() {
// Cribbed from:
// https://github.com/zxing/zxing/blob/master/core/src/main/java/com/google/zxing/client/result/VINResultParser.java
Code39VINReader.prototype._decode = function() {
var result = Code39Reader.prototype._decode.apply(this);
if (!result) {
return null;
@ -47,13 +39,11 @@ define(
result.code = code;
return result;
};
};
Code39VINReader.prototype._checkChecksum = function(code) {
Code39VINReader.prototype._checkChecksum = function(code) {
// TODO
return !!code;
};
};
return (Code39VINReader);
}
);
export default Code39VINReader;

@ -1,10 +1,6 @@
/**
* The basic configuration
*/
define(function(){
var config = {
inputStream: { name: "Live",
export default {
inputStream: {
name: "Live",
type: "LiveStream",
constraints: {
width: 640,
@ -29,7 +25,7 @@ define(function(){
visual: {
show: true
},
decoder:{
decoder: {
drawBoundingBox: false,
showFrequency: false,
drawScanline: false,
@ -54,7 +50,4 @@ define(function(){
showBB: false
}
}
};
return config;
});
};

@ -1,29 +1,15 @@
/* jshint undef: true, unused: true, browser:true, devel: true */
/* global define */
import Cluster2 from './cluster';
import ArrayHelper from './array_helper';
import {vec2, vec3} from 'gl-matrix';
define(['cluster', "array_helper", "gl-matrix"], function(Cluster2, ArrayHelper, glMatrix) {
var CVUtils = {};
"use strict";
/*
* cv_utils.js
* Collection of CV functions and libraries
*/
/**
* Namespace for various CV alorithms
* @class Represents a collection of useful CV algorithms/functions
*/
var CVUtils = {},
vec2 = glMatrix.vec2,
vec3 = glMatrix.vec3;
/**
/**
* @param x x-coordinate
* @param y y-coordinate
* @return ImageReference {x,y} Coordinate
*/
CVUtils.imageRef = function(x, y) {
CVUtils.imageRef = function(x, y) {
var that = {
x : x,
y : y,
@ -40,13 +26,13 @@ define(['cluster', "array_helper", "gl-matrix"], function(Cluster2, ArrayHelper,
}
};
return that;
};
};
/**
/**
* Computes an integral image of a given grayscale image.
* @param imageDataContainer {ImageDataContainer} the image to be integrated
*/
CVUtils.computeIntegralImage2 = function(imageWrapper, integralWrapper) {
CVUtils.computeIntegralImage2 = function(imageWrapper, integralWrapper) {
var imageData = imageWrapper.data;
var width = imageWrapper.size.x;
var height = imageWrapper.size.y;
@ -86,9 +72,9 @@ define(['cluster', "array_helper", "gl-matrix"], function(Cluster2, ArrayHelper,
posD++;
}
}
};
};
CVUtils.computeIntegralImage = function(imageWrapper, integralWrapper) {
CVUtils.computeIntegralImage = function(imageWrapper, integralWrapper) {
var imageData = imageWrapper.data;
var width = imageWrapper.size.x;
var height = imageWrapper.size.y;
@ -108,9 +94,9 @@ define(['cluster', "array_helper", "gl-matrix"], function(Cluster2, ArrayHelper,
integralImageData[((v) * width) + u] = sum + integralImageData[(v - 1) * width + u];
}
}
};
};
CVUtils.thresholdImage = function(imageWrapper, threshold, targetWrapper) {
CVUtils.thresholdImage = function(imageWrapper, threshold, targetWrapper) {
if (!targetWrapper) {
targetWrapper = imageWrapper;
}
@ -119,9 +105,9 @@ define(['cluster', "array_helper", "gl-matrix"], function(Cluster2, ArrayHelper,
while (length--) {
targetData[length] = imageData[length] < threshold ? 1 : 0;
}
};
};
CVUtils.computeHistogram = function(imageWrapper, bitsPerPixel) {
CVUtils.computeHistogram = function(imageWrapper, bitsPerPixel) {
if (!bitsPerPixel) {
bitsPerPixel = 8;
}
@ -135,9 +121,9 @@ define(['cluster', "array_helper", "gl-matrix"], function(Cluster2, ArrayHelper,
hist[imageData[length] >> bitShift]++;
}
return hist;
};
};
CVUtils.sharpenLine = function(line) {
CVUtils.sharpenLine = function(line) {
var i,
length = line.length,
left = line[0],
@ -152,9 +138,9 @@ define(['cluster', "array_helper", "gl-matrix"], function(Cluster2, ArrayHelper,
center = right;
}
return line;
};
};
CVUtils.determineOtsuThreshold = function(imageWrapper, bitsPerPixel) {
CVUtils.determineOtsuThreshold = function(imageWrapper, bitsPerPixel) {
if (!bitsPerPixel) {
bitsPerPixel = 8;
}
@ -202,17 +188,17 @@ define(['cluster', "array_helper", "gl-matrix"], function(Cluster2, ArrayHelper,
threshold = determineThreshold();
return threshold << bitShift;
};
};
CVUtils.otsuThreshold = function(imageWrapper, targetWrapper) {
CVUtils.otsuThreshold = function(imageWrapper, targetWrapper) {
var threshold = CVUtils.determineOtsuThreshold(imageWrapper);
CVUtils.thresholdImage(imageWrapper, threshold, targetWrapper);
return threshold;
};
};
// local thresholding
CVUtils.computeBinaryImage = function(imageWrapper, integralWrapper, targetWrapper) {
// local thresholding
CVUtils.computeBinaryImage = function(imageWrapper, integralWrapper, targetWrapper) {
CVUtils.computeIntegralImage(imageWrapper, integralWrapper);
if (!targetWrapper) {
@ -252,9 +238,9 @@ define(['cluster', "array_helper", "gl-matrix"], function(Cluster2, ArrayHelper,
targetData[v * width + u] = imageData[v * width + u] > (avg + 5) ? 0 : 1;
}
}
};
};
CVUtils.cluster = function(points, threshold, property) {
CVUtils.cluster = function(points, threshold, property) {
var i, k, cluster, point, clusters = [];
if (!property) {
@ -283,9 +269,9 @@ define(['cluster', "array_helper", "gl-matrix"], function(Cluster2, ArrayHelper,
return clusters;
};
};
CVUtils.Tracer = {
CVUtils.Tracer = {
trace : function(points, vec) {
var iteration, maxIterations = 10, top = [], result = [], centerPos = 0, currentPos = 0;
@ -352,12 +338,12 @@ define(['cluster', "array_helper", "gl-matrix"], function(Cluster2, ArrayHelper,
return result;
}
};
};
CVUtils.DILATE = 1;
CVUtils.ERODE = 2;
CVUtils.DILATE = 1;
CVUtils.ERODE = 2;
CVUtils.dilate = function(inImageWrapper, outImageWrapper) {
CVUtils.dilate = function(inImageWrapper, outImageWrapper) {
var v, u, inImageData = inImageWrapper.data, outImageData = outImageWrapper.data, height = inImageWrapper.size.y, width = inImageWrapper.size.x, sum, yStart1, yStart2, xStart1, xStart2;
for ( v = 1; v < height - 1; v++) {
@ -373,9 +359,9 @@ define(['cluster', "array_helper", "gl-matrix"], function(Cluster2, ArrayHelper,
outImageData[v * width + u] = sum > 0 ? 1 : 0;
}
}
};
};
CVUtils.erode = function(inImageWrapper, outImageWrapper) {
CVUtils.erode = function(inImageWrapper, outImageWrapper) {
var v, u, inImageData = inImageWrapper.data, outImageData = outImageWrapper.data, height = inImageWrapper.size.y, width = inImageWrapper.size.x, sum, yStart1, yStart2, xStart1, xStart2;
for ( v = 1; v < height - 1; v++) {
@ -391,9 +377,9 @@ define(['cluster', "array_helper", "gl-matrix"], function(Cluster2, ArrayHelper,
outImageData[v * width + u] = sum === 5 ? 1 : 0;
}
}
};
};
CVUtils.subtract = function(aImageWrapper, bImageWrapper, resultImageWrapper) {
CVUtils.subtract = function(aImageWrapper, bImageWrapper, resultImageWrapper) {
if (!resultImageWrapper) {
resultImageWrapper = aImageWrapper;
}
@ -402,9 +388,9 @@ define(['cluster', "array_helper", "gl-matrix"], function(Cluster2, ArrayHelper,
while (length--) {
cImageData[length] = aImageData[length] - bImageData[length];
}
};
};
CVUtils.bitwiseOr = function(aImageWrapper, bImageWrapper, resultImageWrapper) {
CVUtils.bitwiseOr = function(aImageWrapper, bImageWrapper, resultImageWrapper) {
if (!resultImageWrapper) {
resultImageWrapper = aImageWrapper;
}
@ -413,18 +399,18 @@ define(['cluster', "array_helper", "gl-matrix"], function(Cluster2, ArrayHelper,
while (length--) {
cImageData[length] = aImageData[length] || bImageData[length];
}
};
};
CVUtils.countNonZero = function(imageWrapper) {
CVUtils.countNonZero = function(imageWrapper) {
var length = imageWrapper.data.length, data = imageWrapper.data, sum = 0;
while (length--) {
sum += data[length];
}
return sum;
};
};
CVUtils.topGeneric = function(list, top, scoreFunc) {
CVUtils.topGeneric = function(list, top, scoreFunc) {
var i, minIdx = 0, min = 0, queue = [], score, hit, pos;
for ( i = 0; i < top; i++) {
@ -451,20 +437,20 @@ define(['cluster', "array_helper", "gl-matrix"], function(Cluster2, ArrayHelper,
}
return queue;
};
};
CVUtils.grayArrayFromImage = function(htmlImage, offsetX, ctx, array) {
CVUtils.grayArrayFromImage = function(htmlImage, offsetX, ctx, array) {
ctx.drawImage(htmlImage, offsetX, 0, htmlImage.width, htmlImage.height);
var ctxData = ctx.getImageData(offsetX, 0, htmlImage.width, htmlImage.height).data;
CVUtils.computeGray(ctxData, array);
};
};
CVUtils.grayArrayFromContext = function(ctx, size, offset, array) {
CVUtils.grayArrayFromContext = function(ctx, size, offset, array) {
var ctxData = ctx.getImageData(offset.x, offset.y, size.x, size.y).data;
CVUtils.computeGray(ctxData, array);
};
};
CVUtils.grayAndHalfSampleFromCanvasData = function(canvasData, size, outArray) {
CVUtils.grayAndHalfSampleFromCanvasData = function(canvasData, size, outArray) {
var topRowIdx = 0;
var bottomRowIdx = size.x;
var endIdx = Math.floor(canvasData.length / 4);
@ -484,9 +470,9 @@ define(['cluster', "array_helper", "gl-matrix"], function(Cluster2, ArrayHelper,
bottomRowIdx = bottomRowIdx + inWidth;
}
};
};
CVUtils.computeGray = function(imageData, outArray, config) {
CVUtils.computeGray = function(imageData, outArray, config) {
var l = (imageData.length / 4) | 0,
i,
singleChannel = config && config.singleChannel === true;
@ -500,9 +486,9 @@ define(['cluster', "array_helper", "gl-matrix"], function(Cluster2, ArrayHelper,
outArray[i] = Math.floor(0.299 * imageData[i * 4 + 0] + 0.587 * imageData[i * 4 + 1] + 0.114 * imageData[i * 4 + 2]);
}
}
};
};
CVUtils.loadImageArray = function(src, callback, canvas) {
CVUtils.loadImageArray = function(src, callback, canvas) {
if (!canvas)
canvas = document.createElement('canvas');
var img = new Image();
@ -522,13 +508,13 @@ define(['cluster', "array_helper", "gl-matrix"], function(Cluster2, ArrayHelper,
}, this);
};
img.src = src;
};
};
/**
/**
* @param inImg {ImageWrapper} input image to be sampled
* @param outImg {ImageWrapper} to be stored in
*/
CVUtils.halfSample = function(inImgWrapper, outImgWrapper) {
CVUtils.halfSample = function(inImgWrapper, outImgWrapper) {
var inImg = inImgWrapper.data;
var inWidth = inImgWrapper.size.x;
var outImg = outImgWrapper.data;
@ -547,9 +533,9 @@ define(['cluster', "array_helper", "gl-matrix"], function(Cluster2, ArrayHelper,
topRowIdx = topRowIdx + inWidth;
bottomRowIdx = bottomRowIdx + inWidth;
}
};
};
CVUtils.hsv2rgb = function(hsv, rgb) {
CVUtils.hsv2rgb = function(hsv, rgb) {
var h = hsv[0], s = hsv[1], v = hsv[2], c = v * s, x = c * (1 - Math.abs((h / 60) % 2 - 1)), m = v - c, r = 0, g = 0, b = 0;
rgb = rgb || [0, 0, 0];
@ -576,9 +562,9 @@ define(['cluster', "array_helper", "gl-matrix"], function(Cluster2, ArrayHelper,
rgb[1] = ((g + m) * 255) | 0;
rgb[2] = ((b + m) * 255) | 0;
return rgb;
};
};
CVUtils._computeDivisors = function(n) {
CVUtils._computeDivisors = function(n) {
var largeDivisors = [],
divisors = [],
i;
@ -592,9 +578,9 @@ define(['cluster', "array_helper", "gl-matrix"], function(Cluster2, ArrayHelper,
}
}
return divisors.concat(largeDivisors);
};
};
CVUtils._computeIntersection = function(arr1, arr2) {
CVUtils._computeIntersection = function(arr1, arr2) {
var i = 0,
j = 0,
result = [];
@ -611,9 +597,9 @@ define(['cluster', "array_helper", "gl-matrix"], function(Cluster2, ArrayHelper,
}
}
return result;
};
};
CVUtils.calculatePatchSize = function(patchSize, imgSize) {
CVUtils.calculatePatchSize = function(patchSize, imgSize) {
var divisorsX = this._computeDivisors(imgSize.x),
divisorsY = this._computeDivisors(imgSize.y),
wideSide = Math.max(imgSize.x, imgSize.y),
@ -660,18 +646,18 @@ define(['cluster', "array_helper", "gl-matrix"], function(Cluster2, ArrayHelper,
}
}
return optimalPatchSize;
};
};
CVUtils._parseCSSDimensionValues = function(value) {
CVUtils._parseCSSDimensionValues = function(value) {
var dimension = {
value: parseFloat(value),
unit: value.indexOf("%") === value.length-1 ? "%" : "%"
};
return dimension;
};
};
CVUtils._dimensionsConverters = {
CVUtils._dimensionsConverters = {
top: function(dimension, context) {
if (dimension.unit === "%") {
return Math.floor(context.height * (dimension.value / 100));
@ -692,9 +678,9 @@ define(['cluster', "array_helper", "gl-matrix"], function(Cluster2, ArrayHelper,
return Math.floor(context.width * (dimension.value / 100));
}
}
};
};
CVUtils.computeImageArea = function(inputWidth, inputHeight, area) {
CVUtils.computeImageArea = function(inputWidth, inputHeight, area) {
var context = {width: inputWidth, height: inputHeight};
var parsedArea = Object.keys(area).reduce(function(result, key) {
@ -712,8 +698,6 @@ define(['cluster', "array_helper", "gl-matrix"], function(Cluster2, ArrayHelper,
sw: parsedArea.right - parsedArea.left,
sh: parsedArea.bottom - parsedArea.top
};
};
return (CVUtils);
});
};
export default CVUtils;

@ -1,25 +1,17 @@
/* jshint undef: true, unused: true, browser:true, devel: true */
/* global define */
import EANReader from './ean_reader';
define(
[
"./ean_reader"
],
function(EANReader) {
"use strict";
function EAN8Reader() {
function EAN8Reader() {
EANReader.call(this);
}
}
var properties = {
var properties = {
FORMAT: {value: "ean_8", writeable: false}
};
};
EAN8Reader.prototype = Object.create(EANReader.prototype, properties);
EAN8Reader.prototype.constructor = EAN8Reader;
EAN8Reader.prototype = Object.create(EANReader.prototype, properties);
EAN8Reader.prototype.constructor = EAN8Reader;
EAN8Reader.prototype._decodePayload = function(code, result, decodedCodes) {
EAN8Reader.prototype._decodePayload = function(code, result, decodedCodes) {
var i,
self = this;
@ -48,8 +40,6 @@ define(
}
return code;
};
};
return (EAN8Reader);
}
);
export default EAN8Reader;

@ -1,18 +1,10 @@
/* jshint undef: true, unused: true, browser:true, devel: true */
/* global define */
import BarcodeReader from './barcode_reader';
define(
[
"./barcode_reader"
],
function(BarcodeReader) {
"use strict";
function EANReader(opts) {
function EANReader(opts) {
BarcodeReader.call(this, opts);
}
}
var properties = {
var properties = {
CODE_L_START : {value: 0},
MODULO : {value: 7},
CODE_G_START : {value: 10},
@ -45,12 +37,12 @@ define(
SINGLE_CODE_ERROR: {value: 0.67},
AVG_CODE_ERROR: {value: 0.27},
FORMAT: {value: "ean_13", writeable: false}
};
};
EANReader.prototype = Object.create(BarcodeReader.prototype, properties);
EANReader.prototype.constructor = EANReader;
EANReader.prototype = Object.create(BarcodeReader.prototype, properties);
EANReader.prototype.constructor = EANReader;
EANReader.prototype._decodeCode = function(start, coderange) {
EANReader.prototype._decodeCode = function(start, coderange) {
var counter = [0, 0, 0, 0],
i,
self = this,
@ -99,9 +91,9 @@ define(
}
}
return null;
};
};
EANReader.prototype._findPattern = function(pattern, offset, isWhite, tryHarder, epsilon) {
EANReader.prototype._findPattern = function(pattern, offset, isWhite, tryHarder, epsilon) {
var counter = [],
self = this,
i,
@ -175,9 +167,9 @@ define(
}
}
return null;
};
};
EANReader.prototype._findStart = function() {
EANReader.prototype._findStart = function() {
var self = this,
leadingWhitespaceStart,
offset = self._nextSet(self._row),
@ -197,9 +189,9 @@ define(
offset = startInfo.end;
startInfo = null;
}
};
};
EANReader.prototype._verifyTrailingWhitespace = function(endInfo) {
EANReader.prototype._verifyTrailingWhitespace = function(endInfo) {
var self = this,
trailingWhitespaceEnd;
@ -210,16 +202,16 @@ define(
}
}
return null;
};
};
EANReader.prototype._findEnd = function(offset, isWhite) {
EANReader.prototype._findEnd = function(offset, isWhite) {
var self = this,
endInfo = self._findPattern(self.STOP_PATTERN, offset, isWhite, false);
return endInfo !== null ? self._verifyTrailingWhitespace(endInfo) : null;
};
};
EANReader.prototype._calculateFirstDigit = function(codeFrequency) {
EANReader.prototype._calculateFirstDigit = function(codeFrequency) {
var i,
self = this;
@ -229,9 +221,9 @@ define(
}
}
return null;
};
};
EANReader.prototype._decodePayload = function(code, result, decodedCodes) {
EANReader.prototype._decodePayload = function(code, result, decodedCodes) {
var i,
self = this,
codeFrequency = 0x0,
@ -274,9 +266,9 @@ define(
}
return code;
};
};
EANReader.prototype._decode = function() {
EANReader.prototype._decode = function() {
var startInfo,
self = this,
code,
@ -317,9 +309,9 @@ define(
startInfo : startInfo,
decodedCodes : decodedCodes
};
};
};
EANReader.prototype._checksum = function(result) {
EANReader.prototype._checksum = function(result) {
var sum = 0, i;
for ( i = result.length - 2; i >= 0; i -= 2) {
@ -330,8 +322,6 @@ define(
sum += result[i];
}
return sum % 10 === 0;
};
};
return (EANReader);
}
);
export default (EANReader);

@ -1,10 +1,4 @@
/* jshint undef: true, unused: true, browser:true, devel: true */
/* global define */
define(function() {
"use strict";
var _events = function() {
export default function() {
var events = {};
function getEvent(eventName) {
@ -85,7 +79,4 @@ define(function() {
}
}
};
}();
return _events;
});
}();

@ -1,12 +1,8 @@
/* jshint undef: true, unused: true, browser:true, devel: true */
/* global define */
import CVUtils from './cv_utils';
define(["cv_utils"], function(CVUtils) {
"use strict";
var FrameGrabber = {};
var FrameGrabber = {};
FrameGrabber.create = function(inputStream, canvas) {
FrameGrabber.create = function(inputStream, canvas) {
var _that = {},
_streamConfig = inputStream.getConfig(),
_video_size = CVUtils.imageRef(inputStream.getRealWidth(), inputStream.getRealHeight()),
@ -72,7 +68,6 @@ define(["cv_utils"], function(CVUtils) {
};
return _that;
};
};
return (FrameGrabber);
});
export default FrameGrabber;

@ -1,40 +0,0 @@
/* jshint undef: true, unused: true, browser:true, devel: true */
/* global define */
define([], function() {
"use strict";
function createNode(htmlStr) {
var temp = document.createElement('div');
temp.innerHTML = htmlStr;
while (temp.firstChild) {
return temp.firstChild;
}
}
function mergeObjects(obj1, obj2) {
for (var p in obj2) {
try {
if (obj2[p].constructor == Object) {
obj1[p] = mergeObjects(obj1[p], obj2[p]);
} else {
obj1[p] = obj2[p];
}
} catch(e) {
obj1[p] = obj2[p];
}
}
return obj1;
}
return {
createNode : function(htmlStr) {
return createNode(htmlStr);
},
mergeObjects : function(obj1, obj2) {
return mergeObjects(obj1, obj2);
}
};
});

@ -1,34 +1,26 @@
/* jshint undef: true, unused: true, browser:true, devel: true */
/* global define */
define(
[
"./barcode_reader",
"./html_utils"
],
function(BarcodeReader, HTMLUtils) {
"use strict";
function I2of5Reader(opts) {
opts = HTMLUtils.mergeObjects(getDefaulConfig(), opts);
import BarcodeReader from './barcode_reader';
const merge = require('lodash/object/merge');
function I2of5Reader(opts) {
opts = merge(getDefaulConfig(), opts);
BarcodeReader.call(this, opts);
this.barSpaceRatio = [1, 1];
if (opts.normalizeBarSpaceWidth) {
this.SINGLE_CODE_ERROR = 0.38;
this.AVG_CODE_ERROR = 0.09;
}
}
}
function getDefaulConfig() {
function getDefaulConfig() {
var config = {};
Object.keys(I2of5Reader.CONFIG_KEYS).forEach(function(key) {
config[key] = I2of5Reader.CONFIG_KEYS[key]['default'];
});
return config;
}
}
var N = 1,
var N = 1,
W = 3,
properties = {
MODULO : {value: 10},
@ -50,12 +42,12 @@ define(
AVG_CODE_ERROR: {value: 0.38, writable: true},
MAX_CORRECTION_FACTOR: {value: 5},
FORMAT: {value: "i2of5"}
};
};
I2of5Reader.prototype = Object.create(BarcodeReader.prototype, properties);
I2of5Reader.prototype.constructor = I2of5Reader;
I2of5Reader.prototype = Object.create(BarcodeReader.prototype, properties);
I2of5Reader.prototype.constructor = I2of5Reader;
I2of5Reader.prototype._matchPattern = function(counter, code) {
I2of5Reader.prototype._matchPattern = function(counter, code) {
if (this.config.normalizeBarSpaceWidth) {
var i,
counterSum = [0, 0],
@ -79,9 +71,9 @@ define(
}
}
return BarcodeReader.prototype._matchPattern.call(this, counter, code);
};
};
I2of5Reader.prototype._findPattern = function(pattern, offset, isWhite, tryHarder) {
I2of5Reader.prototype._findPattern = function(pattern, offset, isWhite, tryHarder) {
var counter = [],
self = this,
i,
@ -147,9 +139,9 @@ define(
}
}
return null;
};
};
I2of5Reader.prototype._findStart = function() {
I2of5Reader.prototype._findStart = function() {
var self = this,
leadingWhitespaceStart,
offset = self._nextSet(self._row),
@ -171,9 +163,9 @@ define(
offset = startInfo.end;
startInfo = null;
}
};
};
I2of5Reader.prototype._verifyTrailingWhitespace = function(endInfo) {
I2of5Reader.prototype._verifyTrailingWhitespace = function(endInfo) {
var self = this,
trailingWhitespaceEnd;
@ -184,9 +176,9 @@ define(
}
}
return null;
};
};
I2of5Reader.prototype._findEnd = function() {
I2of5Reader.prototype._findEnd = function() {
var self = this,
endInfo,
tmp;
@ -205,9 +197,9 @@ define(
endInfo.end = self._row.length - tmp;
return endInfo !== null ? self._verifyTrailingWhitespace(endInfo) : null;
};
};
I2of5Reader.prototype._decodePair = function(counterPair) {
I2of5Reader.prototype._decodePair = function(counterPair) {
var i,
code,
codes = [],
@ -221,9 +213,9 @@ define(
codes.push(code);
}
return codes;
};
};
I2of5Reader.prototype._decodeCode = function(counter) {
I2of5Reader.prototype._decodeCode = function(counter) {
var j,
self = this,
sum = 0,
@ -255,9 +247,9 @@ define(
}
}
return null;
};
};
I2of5Reader.prototype._decodePayload = function(counters, result, decodedCodes) {
I2of5Reader.prototype._decodePayload = function(counters, result, decodedCodes) {
var i,
self = this,
pos = 0,
@ -281,13 +273,13 @@ define(
}
}
return codes;
};
};
I2of5Reader.prototype._verifyCounterLength = function(counters) {
I2of5Reader.prototype._verifyCounterLength = function(counters) {
return (counters.length % 10 === 0);
};
};
I2of5Reader.prototype._decode = function() {
I2of5Reader.prototype._decode = function() {
var startInfo,
endInfo,
self = this,
@ -328,17 +320,15 @@ define(
startInfo : startInfo,
decodedCodes : decodedCodes
};
};
};
I2of5Reader.CONFIG_KEYS = {
I2of5Reader.CONFIG_KEYS = {
normalizeBarSpaceWidth: {
'type': 'boolean',
'default': false,
'description': 'If true, the reader tries to normalize the' +
'width-difference between bars and spaces'
}
};
};
return (I2of5Reader);
}
);
export default I2of5Reader;

@ -1,10 +1,4 @@
/* jshint undef: true, unused: true, browser:true, devel: true */
/* global define */
define(function() {
"use strict";
return {
export default {
drawRect: function(pos, size, ctx, style){
ctx.strokeStyle = style.color;
ctx.fillStyle = style.color;
@ -44,6 +38,4 @@ define(function() {
ctx.putImageData(canvasData, 0, 0);
return true;
}
};
});
};

@ -1,11 +1,5 @@
/* jshint undef: true, unused: true, browser:true, devel: true */
/* global define */
define(function() {
"use strict";
var ImageLoader = {};
ImageLoader.load = function(directory, callback, offset, size, sequence) {
var ImageLoader = {};
ImageLoader.load = function(directory, callback, offset, size, sequence) {
var htmlImagesSrcArray = new Array(size),
htmlImagesArray = new Array(htmlImagesSrcArray.length),
i,
@ -51,13 +45,12 @@ define(function() {
addOnloadHandler(img, htmlImagesArray);
img.src = htmlImagesSrcArray[i];
}
};
};
function addOnloadHandler(img, htmlImagesArray) {
function addOnloadHandler(img, htmlImagesArray) {
img.onload = function() {
htmlImagesArray.loaded(this);
};
}
}
return (ImageLoader);
});
export default (ImageLoader);

@ -1,19 +1,9 @@
/* jshint undef: true, unused: true, browser:true, devel: true */
/* global define */
define([
"subImage",
"cv_utils",
"array_helper",
"gl-matrix"
],
function(SubImage, CVUtils, ArrayHelper, glMatrix) {
'use strict';
var vec2 = glMatrix.vec2,
mat2 = glMatrix.mat2;
/**
import SubImage from './subImage';
import CVUtils from './cv_utils';
import ArrayHelper from './array_helper';
import {vec2, mat2} from 'gl-matrix';
/**
* Represents a basic image combining the data and size.
* In addition, some methods for manipulation are contained.
* @param size {x,y} The size of the image in pixel
@ -22,7 +12,7 @@ define([
* @param initialize {Boolean} Indicating if the array should be initialized on creation.
* @returns {ImageWrapper}
*/
function ImageWrapper(size, data, ArrayType, initialize) {
function ImageWrapper(size, data, ArrayType, initialize) {
if (!data) {
if (ArrayType) {
this.data = new ArrayType(size.x * size.y);
@ -40,20 +30,20 @@ define([
this.data = data;
}
this.size = size;
}
}
/**
/**
* tests if a position is within the image with a given offset
* @param imgRef {x, y} The location to test
* @param border Number the padding value in pixel
* @returns {Boolean} true if location inside the image's border, false otherwise
* @see cvd/image.h
*/
ImageWrapper.prototype.inImageWithBorder = function(imgRef, border) {
ImageWrapper.prototype.inImageWithBorder = function(imgRef, border) {
return (imgRef.x >= border) && (imgRef.y >= border) && (imgRef.x < (this.size.x - border)) && (imgRef.y < (this.size.y - border));
};
};
/**
/**
* Transforms an image according to the given affine-transformation matrix.
* @param inImg ImageWrapper a image containing the information to be extracted.
* @param outImg ImageWrapper the image to be filled. The whole image out image is filled by the in image.
@ -63,7 +53,7 @@ define([
* @returns Number the number of pixels not in the in image
* @see cvd/vision.h
*/
ImageWrapper.transform = function(inImg, outImg, M, inOrig, outOrig) {
ImageWrapper.transform = function(inImg, outImg, M, inOrig, outOrig) {
var w = outImg.size.x, h = outImg.size.y, iw = inImg.size.x, ih = inImg.size.y;
var across = vec2.clone([M[0], M[2]]);
var down = vec2.clone([M[1], M[3]]);
@ -121,9 +111,9 @@ define([
}
return count;
}
};
};
/**
/**
* Performs bilinear sampling
* @param inImg Image to extract sample from
* @param x the x-coordinate
@ -131,7 +121,7 @@ define([
* @returns the sampled value
* @see cvd/vision.h
*/
ImageWrapper.sample = function(inImg, x, y) {
ImageWrapper.sample = function(inImg, x, y) {
var lx = Math.floor(x);
var ly = Math.floor(y);
var w = inImg.size.x;
@ -146,35 +136,35 @@ define([
var result = Math.floor(x * (y * (e - c + d) - e) + y * (c - a) + a);
return result;
};
};
/**
/**
* Initializes a given array. Sets each element to zero.
* @param array {Array} The array to initialize
*/
ImageWrapper.clearArray = function(array) {
ImageWrapper.clearArray = function(array) {
var l = array.length;
while (l--) {
array[l] = 0;
}
};
};
/**
/**
* Creates a {SubImage} from the current image ({this}).
* @param from {ImageRef} The position where to start the {SubImage} from. (top-left corner)
* @param size {ImageRef} The size of the resulting image
* @returns {SubImage} A shared part of the original image
*/
ImageWrapper.prototype.subImage = function(from, size) {
ImageWrapper.prototype.subImage = function(from, size) {
return new SubImage(from, size, this);
};
};
/**
/**
* Creates an {ImageWrapper) and copies the needed underlying image-data area
* @param imageWrapper {ImageWrapper} The target {ImageWrapper} where the data should be copied
* @param from {ImageRef} The location where to copy from (top-left location)
*/
ImageWrapper.prototype.subImageAsCopy = function(imageWrapper, from) {
ImageWrapper.prototype.subImageAsCopy = function(imageWrapper, from) {
var sizeY = imageWrapper.size.y, sizeX = imageWrapper.size.x;
var x, y;
for ( x = 0; x < sizeX; x++) {
@ -182,33 +172,33 @@ define([
imageWrapper.data[y * sizeX + x] = this.data[(from.y + y) * this.size.x + from.x + x];
}
}
};
};
ImageWrapper.prototype.copyTo = function(imageWrapper) {
ImageWrapper.prototype.copyTo = function(imageWrapper) {
var length = this.data.length, srcData = this.data, dstData = imageWrapper.data;
while (length--) {
dstData[length] = srcData[length];
}
};
};
/**
/**
* Retrieves a given pixel position from the image
* @param x {Number} The x-position
* @param y {Number} The y-position
* @returns {Number} The grayscale value at the pixel-position
*/
ImageWrapper.prototype.get = function(x, y) {
ImageWrapper.prototype.get = function(x, y) {
return this.data[y * this.size.x + x];
};
};
/**
/**
* Retrieves a given pixel position from the image
* @param x {Number} The x-position
* @param y {Number} The y-position
* @returns {Number} The grayscale value at the pixel-position
*/
ImageWrapper.prototype.getSafe = function(x, y) {
ImageWrapper.prototype.getSafe = function(x, y) {
var i;
if (!this.indexMapping) {
@ -226,24 +216,24 @@ define([
}
}
return this.data[(this.indexMapping.y[y + this.size.y]) * this.size.x + this.indexMapping.x[x + this.size.x]];
};
};
/**
/**
* Sets a given pixel position in the image
* @param x {Number} The x-position
* @param y {Number} The y-position
* @param value {Number} The grayscale value to set
* @returns {ImageWrapper} The Image itself (for possible chaining)
*/
ImageWrapper.prototype.set = function(x, y, value) {
ImageWrapper.prototype.set = function(x, y, value) {
this.data[y * this.size.x + x] = value;
return this;
};
};
/**
/**
* Sets the border of the image (1 pixel) to zero
*/
ImageWrapper.prototype.zeroBorder = function() {
ImageWrapper.prototype.zeroBorder = function() {
var i, width = this.size.x, height = this.size.y, data = this.data;
for ( i = 0; i < width; i++) {
data[i] = data[(height - 1) * width + i] = 0;
@ -251,21 +241,21 @@ define([
for ( i = 1; i < height - 1; i++) {
data[i * width] = data[i * width + (width - 1)] = 0;
}
};
};
/**
/**
* Inverts a binary image in place
*/
ImageWrapper.prototype.invert = function() {
ImageWrapper.prototype.invert = function() {
var data = this.data, length = data.length;
while (length--) {
data[length] = data[length] ? 0 : 1;
}
};
};
ImageWrapper.prototype.convolve = function(kernel) {
ImageWrapper.prototype.convolve = function(kernel) {
var x, y, kx, ky, kSize = (kernel.length / 2) | 0, accu = 0;
for ( y = 0; y < this.size.y; y++) {
for ( x = 0; x < this.size.x; x++) {
@ -278,9 +268,9 @@ define([
this.data[y * this.size.x + x] = accu;
}
}
};
};
ImageWrapper.prototype.moments = function(labelcount) {
ImageWrapper.prototype.moments = function(labelcount) {
var data = this.data,
x,
y,
@ -355,14 +345,14 @@ define([
}
return result;
};
};
/**
/**
* Displays the {ImageWrapper} in a given canvas
* @param canvas {Canvas} The canvas element to write to
* @param scale {Number} Scale which is applied to each pixel-value
*/
ImageWrapper.prototype.show = function(canvas, scale) {
ImageWrapper.prototype.show = function(canvas, scale) {
var ctx,
frame,
data,
@ -392,14 +382,14 @@ define([
}
//frame.data = data;
ctx.putImageData(frame, 0, 0);
};
};
/**
/**
* Displays the {SubImage} in a given canvas
* @param canvas {Canvas} The canvas element to write to
* @param scale {Number} Scale which is applied to each pixel-value
*/
ImageWrapper.prototype.overlay = function(canvas, scale, from) {
ImageWrapper.prototype.overlay = function(canvas, scale, from) {
if (!scale || scale < 0 || scale > 360) {
scale = 360;
}
@ -421,7 +411,6 @@ define([
data[length * 4 + 3] = 255;
}
ctx.putImageData(frame, from.x, from.y);
};
};
return (ImageWrapper);
});
export default ImageWrapper;

@ -1,11 +1,7 @@
/* jshint undef: true, unused: true, browser:true, devel: true */
/* global define */
import ImageLoader from './image_loader';
define(["image_loader"], function(ImageLoader) {
"use strict";
var InputStream = {};
InputStream.createVideoStream = function(video) {
var InputStream = {};
InputStream.createVideoStream = function(video) {
var that = {},
_config = null,
_eventNames = ['canrecord', 'ended'],
@ -139,9 +135,9 @@ define(["image_loader"], function(ImageLoader) {
};
return that;
};
};
InputStream.createLiveStream = function(video) {
InputStream.createLiveStream = function(video) {
video.setAttribute("autoplay", true);
var that = InputStream.createVideoStream(video);
@ -150,9 +146,9 @@ define(["image_loader"], function(ImageLoader) {
};
return that;
};
};
InputStream.createImageStream = function() {
InputStream.createImageStream = function() {
var that = {};
var _config = null;
@ -311,7 +307,6 @@ define(["image_loader"], function(ImageLoader) {
};
return that;
};
};
return (InputStream);
});
export default InputStream;

@ -1,33 +1,19 @@
/* jshint undef: true, unused: true, browser:true, devel: true, evil: true */
/* global define */
define([
"input_stream",
"image_wrapper",
"barcode_locator",
"barcode_decoder",
"frame_grabber",
"html_utils",
"config",
"events",
"camera_access",
"image_debug",
"gl-matrix",
"result_collector"],
function(InputStream,
ImageWrapper,
BarcodeLocator,
BarcodeDecoder,
FrameGrabber,
HtmlUtils,
_config,
Events,
CameraAccess,
ImageDebug,
glMatrix,
ResultCollector) {
"use strict";
var _inputStream,
import TypeDefs from './typedefs';
import InputStream from './input_stream';
import ImageWrapper from './image_wrapper';
import BarcodeLocator from './barcode_locator';
import BarcodeDecoder from './barcode_decoder';
import FrameGrabber from './frame_grabber';
import Config from './config';
import Events from './events';
import CameraAccess from './camera_access';
import ImageDebug from './image_debug';
import {vec2} from 'gl-matrix';
import ResultCollector from './result_collector';
const merge = require('lodash/object/merge');
var _inputStream,
_framegrabber,
_stopped,
_canvasContainer = {
@ -45,15 +31,15 @@ function(InputStream,
_decoder,
_workerPool = [],
_onUIThread = true,
vec2 = glMatrix.vec2,
_resultCollector;
_resultCollector,
_config = {};
function initializeData(imageWrapper) {
function initializeData(imageWrapper) {
initBuffers(imageWrapper);
_decoder = BarcodeDecoder.create(_config.decoder, _inputImageWrapper);
}
}
function initConfig() {
function initConfig() {
if (typeof document !== "undefined") {
var vis = [{
node: document.querySelector("div[data-controls]"),
@ -73,9 +59,9 @@ function(InputStream,
}
}
}
}
}
function initInputStream(cb) {
function initInputStream(cb) {
var video;
if (_config.inputStream.type == "VideoStream") {
video = document.createElement("video");
@ -105,9 +91,9 @@ function(InputStream,
_inputStream.setAttribute("autoplay", true);
_inputStream.setInputStream(_config.inputStream);
_inputStream.addEventListener("canrecord", canRecord.bind(undefined, cb));
}
}
function canRecord(cb) {
function canRecord(cb) {
BarcodeLocator.checkImageConstraints(_inputStream, _config.locator);
initCanvas();
_framegrabber = FrameGrabber.create(_inputStream, _canvasContainer.dom.image);
@ -122,14 +108,14 @@ function(InputStream,
initializeData();
ready(cb);
}
}
}
function ready(cb){
function ready(cb){
_inputStream.play();
cb();
}
}
function initCanvas() {
function initCanvas() {
if (typeof document !== "undefined") {
var $viewport = document.querySelector("#interactive.viewport");
_canvasContainer.dom.image = document.querySelector("canvas.imgBuffer");
@ -161,9 +147,9 @@ function(InputStream,
_canvasContainer.dom.overlay.width = _inputStream.getCanvasSize().x;
_canvasContainer.dom.overlay.height = _inputStream.getCanvasSize().y;
}
}
}
function initBuffers(imageWrapper) {
function initBuffers(imageWrapper) {
if (imageWrapper) {
_inputImageWrapper = imageWrapper;
} else {
@ -181,9 +167,9 @@ function(InputStream,
vec2.clone([_inputImageWrapper.size.x, 0])
];
BarcodeLocator.init(_inputImageWrapper, _config.locator);
}
}
function getBoundingBoxes() {
function getBoundingBoxes() {
if (_config.locate) {
return BarcodeLocator.locate();
} else {
@ -193,9 +179,9 @@ function(InputStream,
vec2.clone(_boxSize[2]),
vec2.clone(_boxSize[3])]];
}
}
}
function transformResult(result) {
function transformResult(result) {
var topRight = _inputStream.getTopRight(),
xOffset = topRight.x,
yOffset = topRight.y,
@ -230,9 +216,9 @@ function(InputStream,
line[1].x += xOffset;
line[1].y += yOffset;
}
}
}
function publishResult(result, imageData) {
function publishResult(result, imageData) {
if (_onUIThread) {
transformResult(result);
if (imageData && result && result.codeResult) {
@ -246,9 +232,9 @@ function(InputStream,
if (result && result.codeResult) {
Events.publish("detected", result);
}
}
}
function locateAndDecode() {
function locateAndDecode() {
var result,
boxes;
@ -261,9 +247,9 @@ function(InputStream,
} else {
publishResult();
}
}
}
function update() {
function update() {
var availableWorker;
if (_onUIThread) {
@ -293,9 +279,9 @@ function(InputStream,
} else {
locateAndDecode();
}
}
}
function start() {
function start() {
_stopped = false;
( function frame() {
if (!_stopped) {
@ -305,9 +291,9 @@ function(InputStream,
}
}
}());
}
}
function initWorkers(cb) {
function initWorkers(cb) {
var i;
_workerPool = [];
@ -321,9 +307,9 @@ function(InputStream,
cb();
}
}
}
}
function initWorker(cb) {
function initWorker(cb) {
var blobURL,
workerThread = {
worker: undefined,
@ -356,10 +342,11 @@ function(InputStream,
imageData: workerThread.imageData,
config: _config
}, [workerThread.imageData.buffer]);
}
}
function workerInterface(factory) {
function workerInterface(factory) {
window = self;
if (factory) {
/* jshint ignore:start */
var Quagga = factory();
@ -398,9 +385,9 @@ function(InputStream,
self.postMessage({'event': 'initialized', imageData: imageWrapper.data}, [imageWrapper.data.buffer]);
}
/* jshint ignore:end */
}
}
function generateWorkerBlob() {
function generateWorkerBlob() {
var blob,
factorySource;
@ -414,9 +401,9 @@ function(InputStream,
{type : 'text/javascript'});
return window.URL.createObjectURL(blob);
}
}
function setReaders(readers) {
function setReaders(readers) {
if (_decoder) {
_decoder.setReaders(readers);
} else if (_onUIThread && _workerPool.length > 0) {
@ -424,11 +411,11 @@ function(InputStream,
workerThread.worker.postMessage({cmd: 'setReaders', readers: readers});
});
}
}
}
return {
export default {
init : function(config, cb, imageWrapper) {
_config = HtmlUtils.mergeObjects(_config, config);
_config = merge({}, Config, config);
if (imageWrapper) {
_onUIThread = false;
initializeData(imageWrapper);
@ -477,7 +464,7 @@ function(InputStream,
},
canvas : _canvasContainer,
decodeSingle : function(config, resultCallback) {
config = HtmlUtils.mergeObjects({
config = merge({
inputStream: {
type : "ImageStream",
sequence : false,
@ -500,5 +487,4 @@ function(InputStream,
ImageWrapper: ImageWrapper,
ImageDebug: ImageDebug,
ResultCollector: ResultCollector
};
});
};

@ -1,13 +1,9 @@
/* jshint undef: true, unused: true, browser:true, devel: true */
/* global define */
import Tracer from './tracer';
/**
* http://www.codeproject.com/Tips/407172/Connected-Component-Labeling-and-Vectorization
*/
define(["tracer"], function(Tracer) {
"use strict";
var Rasterizer = {
var Rasterizer = {
createContour2D : function() {
return {
dir : null,
@ -192,7 +188,6 @@ define(["tracer"], function(Tracer) {
}
};
}
};
};
return (Rasterizer);
});
export default Rasterizer;

@ -1,10 +1,6 @@
/* jshint undef: true, unused: true, browser:true, devel: true */
/* global define */
import ImageDebug from './image_debug';
define(["image_debug"], function(ImageDebug) {
"use strict";
function contains(codeResult, list) {
function contains(codeResult, list) {
if (list) {
return list.some(function (item) {
return Object.keys(item).every(function (key) {
@ -13,16 +9,16 @@ define(["image_debug"], function(ImageDebug) {
});
}
return false;
}
}
function passesFilter(codeResult, filter) {
function passesFilter(codeResult, filter) {
if (typeof filter === 'function') {
return filter(codeResult);
}
return true;
}
}
return {
export default {
create: function(config) {
var canvas = document.createElement("canvas"),
ctx = canvas.getContext("2d"),
@ -55,5 +51,4 @@ define(["image_debug"], function(ImageDebug) {
}
};
}
};
});
};

@ -1,11 +1,5 @@
/* jshint undef: true, unused: true, browser:true, devel: true, -W041: false */
/* global define */
define(function() {
"use strict";
/* @preserve ASM BEGIN */
function Skeletonizer(stdlib, foreign, buffer) {
/* @preserve ASM BEGIN */
function Skeletonizer(stdlib, foreign, buffer) {
"use asm";
var images = new stdlib.Uint8Array(buffer),
@ -197,8 +191,7 @@ define(function() {
return {
skeletonize : skeletonize
};
}
/* @preserve ASM END */
}
/* @preserve ASM END */
return Skeletonizer;
});
export default Skeletonizer;

@ -1,10 +1,4 @@
/* jshint undef: true, unused: true, browser:true, devel: true */
/* global define */
define(["typedefs"], function() {
"use strict";
/**
/**
* Construct representing a part of another {ImageWrapper}. Shares data
* between the parent and the child.
* @param from {ImageRef} The position where to start the {SubImage} from. (top-left corner)
@ -12,7 +6,7 @@ define(["typedefs"], function() {
* @param I {ImageWrapper} The {ImageWrapper} to share from
* @returns {SubImage} A shared part of the original image
*/
function SubImage(from, size, I) {
function SubImage(from, size, I) {
if (!I) {
I = {
data : null,
@ -25,14 +19,14 @@ define(["typedefs"], function() {
this.from = from;
this.size = size;
}
}
/**
/**
* Displays the {SubImage} in a given canvas
* @param canvas {Canvas} The canvas element to write to
* @param scale {Number} Scale which is applied to each pixel-value
*/
SubImage.prototype.show = function(canvas, scale) {
SubImage.prototype.show = function(canvas, scale) {
var ctx,
frame,
data,
@ -62,36 +56,35 @@ define(["typedefs"], function() {
}
frame.data = data;
ctx.putImageData(frame, 0, 0);
};
};
/**
/**
* Retrieves a given pixel position from the {SubImage}
* @param x {Number} The x-position
* @param y {Number} The y-position
* @returns {Number} The grayscale value at the pixel-position
*/
SubImage.prototype.get = function(x, y) {
SubImage.prototype.get = function(x, y) {
return this.data[(this.from.y + y) * this.originalSize.x + this.from.x + x];
};
};
/**
/**
* Updates the underlying data from a given {ImageWrapper}
* @param image {ImageWrapper} The updated image
*/
SubImage.prototype.updateData = function(image) {
SubImage.prototype.updateData = function(image) {
this.originalSize = image.size;
this.data = image.data;
};
};
/**
/**
* Updates the position of the shared area
* @param from {x,y} The new location
* @returns {SubImage} returns {this} for possible chaining
*/
SubImage.prototype.updateFrom = function(from) {
SubImage.prototype.updateFrom = function(from) {
this.from = from;
return this;
};
};
return (SubImage);
});
export default (SubImage);

@ -1,13 +1,7 @@
/* jshint undef: true, unused: true, browser:true, devel: true */
/* global define */
/**
* http://www.codeproject.com/Tips/407172/Connected-Component-Labeling-and-Vectorization
*/
define(function() {
"use strict";
var Tracer = {
var Tracer = {
searchDirections : [[0, 1], [1, 1], [1, 0], [1, -1], [0, -1], [-1, -1], [-1, 0], [-1, 1]],
create : function(imageWrapper, labelWrapper) {
var imageData = imageWrapper.data,
@ -102,7 +96,6 @@ define(function() {
}
};
}
};
};
return (Tracer);
});
export default (Tracer);

@ -3,8 +3,7 @@
* Normalizes browser-specific prefixes
*/
glMatrixArrayType = Float32Array;
if (typeof window !== 'undefined') {
if (typeof window !== 'undefined') {
window.requestAnimFrame = (function () {
return window.requestAnimationFrame ||
window.webkitRequestAnimationFrame ||
@ -18,8 +17,8 @@ if (typeof window !== 'undefined') {
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) {
}
Math.imul = Math.imul || function(a, b) {
var ah = (a >>> 16) & 0xffff,
al = a & 0xffff,
bh = (b >>> 16) & 0xffff,
@ -27,4 +26,8 @@ Math.imul = Math.imul || function(a, b) {
// 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 {
}

@ -1,29 +1,21 @@
/* jshint undef: true, unused: true, browser:true, devel: true */
/* global define */
import EANReader from './ean_reader';
define(
[
"./ean_reader"
],
function(EANReader) {
"use strict";
function UPCEReader() {
function UPCEReader() {
EANReader.call(this);
}
}
var properties = {
var properties = {
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]},
FORMAT: {value: "upc_e", writeable: false}
};
};
UPCEReader.prototype = Object.create(EANReader.prototype, properties);
UPCEReader.prototype.constructor = UPCEReader;
UPCEReader.prototype = Object.create(EANReader.prototype, properties);
UPCEReader.prototype.constructor = UPCEReader;
UPCEReader.prototype._decodePayload = function(code, result, decodedCodes) {
UPCEReader.prototype._decodePayload = function(code, result, decodedCodes) {
var i,
self = this,
codeFrequency = 0x0;
@ -45,9 +37,9 @@ define(
}
return code;
};
};
UPCEReader.prototype._determineParity = function(codeFrequency, result) {
UPCEReader.prototype._determineParity = function(codeFrequency, result) {
var self =this,
i,
nrSystem;
@ -62,9 +54,9 @@ define(
}
}
return false;
};
};
UPCEReader.prototype._convertToUPCA = function(result) {
UPCEReader.prototype._convertToUPCA = function(result) {
var upca = [result[0]],
lastDigit = result[result.length - 2];
@ -86,18 +78,18 @@ define(
upca.push(result[result.length - 1]);
return upca;
};
};
UPCEReader.prototype._checksum = function(result) {
UPCEReader.prototype._checksum = function(result) {
return EANReader.prototype._checksum.call(this, this._convertToUPCA(result));
};
};
UPCEReader.prototype._findEnd = function(offset, isWhite) {
UPCEReader.prototype._findEnd = function(offset, isWhite) {
isWhite = true;
return EANReader.prototype._findEnd.call(this, offset, isWhite);
};
};
UPCEReader.prototype._verifyTrailingWhitespace = function(endInfo) {
UPCEReader.prototype._verifyTrailingWhitespace = function(endInfo) {
var self = this,
trailingWhitespaceEnd;
@ -107,8 +99,6 @@ define(
return endInfo;
}
}
};
};
return (UPCEReader);
}
);
export default UPCEReader;

@ -1,25 +1,17 @@
/* jshint undef: true, unused: true, browser:true, devel: true */
/* global define */
import EANReader from './ean_reader';
define(
[
"./ean_reader"
],
function(EANReader) {
"use strict";
function UPCReader() {
function UPCReader() {
EANReader.call(this);
}
}
var properties = {
var properties = {
FORMAT: {value: "upc_a", writeable: false}
};
};
UPCReader.prototype = Object.create(EANReader.prototype, properties);
UPCReader.prototype.constructor = UPCReader;
UPCReader.prototype = Object.create(EANReader.prototype, properties);
UPCReader.prototype.constructor = UPCReader;
UPCReader.prototype._decode = function() {
UPCReader.prototype._decode = function() {
var result = EANReader.prototype._decode.call(this);
if (result && result.code && result.code.length === 13 && result.code.charAt(0) === "0") {
@ -28,8 +20,6 @@ define(
return result;
}
return null;
};
};
return (UPCReader);
}
);
export default EANReader;

@ -0,0 +1,34 @@
var webpack = require('webpack'),
MyUmdPlugin = require('./plugins/umd');
module.exports = {
entry: [
'./src/quagga.js'
],
devtool: 'source-map',
module: {
loaders: [{
test: /\.jsx?$/,
exclude: /node_modules/,
loader: 'babel'
}]
},
resolve: {
extensions: ['', '.js', '.jsx']
},
output: {
path: __dirname + '/dist',
publicPath: '/',
filename: 'quagga.js',
sourceMapFilename: 'quagga.map'
},
devServer: {
contentBase: './',
hot: true
},
plugins: [
new MyUmdPlugin({
library: 'Quagga'
})
]
};

@ -0,0 +1,8 @@
var webpack = require('webpack');
module.exports = require('./webpack.config.js');
module.exports.plugins.unshift(
new webpack.optimize.UglifyJsPlugin()
);
module.exports.output.filename = 'quagga.min.js';
Loading…
Cancel
Save