Added barcode format to result-data; minor fixes to Code128Reader; fixes #45

pull/62/head
Christoph Oberhofer 10 years ago
parent 8c0fcaa031
commit e142350863

@ -34,6 +34,7 @@ module.exports = function(grunt) {
},
"baseUrl" : "src",
"name" : "quagga",
"useStrict": false,
"out" : "dist/quagga.js",
"include" : ['quagga'],
"optimize" : "none",

@ -1,7 +1,7 @@
quaggaJS
========
- [Changelog](#changelog) (2015-06-13)
- [Changelog](#changelog) (2015-06-14)
## What is QuaggaJS?
@ -143,7 +143,8 @@ empty.
```javascript
{
"codeResult": {
"code": "FANAVF1461710",
"code": "FANAVF1461710", // the decoded code as a string
"format": "code_128", // or code_39, codabar, ean_13, ean_8, upc_a, upc_e
"start": 355,
"end": 26,
"codeset": 100,
@ -299,6 +300,10 @@ work.
## <a name="changelog">Changelog</a>
### 2015-06-13
- Improvements
- Added ``format`` property to ``codeResult`` (in [result](#resultobject))
### 2015-06-13
- Improvements
- Added fixes for ``Code39Reader`` (trailing whitespace was missing)

169
dist/quagga.js vendored

@ -437,7 +437,7 @@ define("almond", function(){});
define(
'barcode_reader',[],function() {
"use strict";
function BarcodeReader() {
this._row = [];
@ -600,6 +600,9 @@ define(
} else {
result.direction = BarcodeReader.DIRECTION.FORWARD;
}
if (result) {
result.format = self.FORMAT;
}
return result;
};
@ -614,6 +617,11 @@ define(
}
return true;
};
Object.defineProperty(BarcodeReader.prototype, "FORMAT", {
value: 'unknown',
writeable: false
});
BarcodeReader.DIRECTION = {
FORWARD : 1,
@ -638,7 +646,7 @@ define(
"./barcode_reader"
],
function(BarcodeReader) {
"use strict";
function Code128Reader() {
BarcodeReader.call(this);
@ -764,7 +772,8 @@ define(
[2, 3, 3, 1, 1, 1, 2]
]},
SINGLE_CODE_ERROR: {value: 1},
AVG_CODE_ERROR: {value: 0.5}
AVG_CODE_ERROR: {value: 0.5},
FORMAT: {value: "code_128", writeable: false}
};
Code128Reader.prototype = Object.create(BarcodeReader.prototype, properties);
@ -811,58 +820,6 @@ define(
}
return null;
};
Code128Reader.prototype._findEnd = function() {
var counter = [0, 0, 0, 0, 0, 0, 0],
i,
self = this,
offset = self._nextSet(self._row),
isWhite = !self._row[offset],
counterPos = 0,
bestMatch = {
error : Number.MAX_VALUE,
code : -1,
start : 0,
end : 0
},
error,
j,
sum,
normalized;
for ( i = offset; i < self._row.length; i++) {
if (self._row[i] ^ isWhite) {
counter[counterPos]++;
} else {
if (counterPos === counter.length - 1) {
sum = 0;
for ( j = 0; j < counter.length; j++) {
sum += counter[j];
}
normalized = self._normalize(counter, 13);
error = self._matchPattern(normalized, self.CODE_PATTERN[self.STOP_CODE]);
if (error < self.AVG_CODE_ERROR) {
bestMatch.error = error;
bestMatch.start = i - sum;
bestMatch.end = i;
return bestMatch;
}
for ( j = 0; j < 5; j++) {
counter[j] = counter[j + 2];
}
counter[5] = 0;
counter[6] = 0;
counterPos--;
} else {
counterPos++;
}
counter[counterPos] = 1;
isWhite = !isWhite;
}
}
return null;
};
Code128Reader.prototype._findStart = function() {
var counter = [0, 0, 0, 0, 0, 0],
@ -1052,7 +1009,7 @@ define(
// find end bar
code.end = self._nextUnset(self._row, code.end);
if (code.end === self._row.length) {
if(!self._verifyTrailingWhitespace(code)){
return null;
}
@ -1063,9 +1020,15 @@ define(
return null;
}
if (!result.length) {
return null;
}
// remove last code from result (checksum)
result.splice(result.length - 1, 1);
return {
code : result.join(""),
start : startInfo.start,
@ -1076,6 +1039,20 @@ define(
endInfo : code
};
};
BarcodeReader.prototype._verifyTrailingWhitespace = function(endInfo) {
var self = this,
trailingWhitespaceEnd;
trailingWhitespaceEnd = endInfo.end + ((endInfo.end - endInfo.start) / 2);
if (trailingWhitespaceEnd < self._row.length) {
if (self._matchRange(endInfo.end, trailingWhitespaceEnd, 0)) {
return endInfo;
}
}
return null;
};
return (Code128Reader);
}
@ -1088,7 +1065,7 @@ define(
"./barcode_reader"
],
function(BarcodeReader) {
"use strict";
function EANReader(opts) {
BarcodeReader.call(this, opts);
@ -1125,7 +1102,8 @@ define(
]},
CODE_FREQUENCY : {value: [0, 11, 13, 14, 19, 25, 28, 21, 22, 26]},
SINGLE_CODE_ERROR: {value: 0.7},
AVG_CODE_ERROR: {value: 0.3}
AVG_CODE_ERROR: {value: 0.3},
FORMAT: {value: "ean_13", writeable: false}
};
EANReader.prototype = Object.create(BarcodeReader.prototype, properties);
@ -1416,7 +1394,7 @@ define(
/* global define */
define('image_loader',[],function() {
"use strict";
var ImageLoader = {};
ImageLoader.load = function(directory, callback, offset, size, sequence) {
@ -1480,7 +1458,7 @@ define('image_loader',[],function() {
/* global define */
define('input_stream',["image_loader"], function(ImageLoader) {
"use strict";
var InputStream = {};
InputStream.createVideoStream = function(video) {
@ -1827,7 +1805,7 @@ define("typedefs", (function (global) {
/* global define */
define('subImage',["typedefs"], function() {
"use strict";
/**
* Construct representing a part of another {ImageWrapper}. Shares data
@ -1924,7 +1902,7 @@ define('subImage',["typedefs"], function() {
/* global define, vec2 */
define('cluster',[],function() {
"use strict";
/**
* Creates a cluster for grouping similar orientations of datapoints
@ -4269,7 +4247,7 @@ define("glMatrixAddon", ["glMatrix"], (function (global) {
/* global define */
define('array_helper',[],function() {
"use strict";
return {
init : function(arr, val) {
@ -4356,7 +4334,7 @@ define('array_helper',[],function() {
define('cv_utils',['cluster', 'glMatrixAddon', "array_helper"], function(Cluster2, glMatrixAddon, ArrayHelper) {
"use strict";
/*
* cv_utils.js
* Collection of CV functions and libraries
@ -5073,7 +5051,7 @@ define('image_wrapper',[
],
function(SubImage, CVUtils, ArrayHelper) {
'use strict';
/**
* Represents a basic image combining the data and size.
@ -5494,7 +5472,7 @@ define('image_wrapper',[
* http://www.codeproject.com/Tips/407172/Connected-Component-Labeling-and-Vectorization
*/
define('tracer',[],function() {
"use strict";
var Tracer = {
searchDirections : [[0, 1], [1, 1], [1, 0], [1, -1], [0, -1], [-1, -1], [-1, 0], [-1, 1]],
@ -5603,7 +5581,7 @@ define('tracer',[],function() {
* http://www.codeproject.com/Tips/407172/Connected-Component-Labeling-and-Vectorization
*/
define('rasterizer',["tracer"], function(Tracer) {
"use strict";
var Rasterizer = {
createContour2D : function() {
@ -5799,7 +5777,7 @@ define('rasterizer',["tracer"], function(Tracer) {
/* global define */
define('skeletonizer',[],function() {
"use strict";
/* @preserve ASM BEGIN */
function Skeletonizer(stdlib, foreign, buffer) {
@ -6004,7 +5982,7 @@ define('skeletonizer',[],function() {
/* global define */
define('image_debug',[],function() {
"use strict";
return {
drawRect: function(pos, size, ctx, style){
@ -6595,7 +6573,7 @@ function(ImageWrapper, CVUtils, Rasterizer, Tracer, skeletonizer, ArrayHelper, I
/* global define */
define('bresenham',["cv_utils", "image_wrapper"], function(CVUtils, ImageWrapper) {
"use strict";
var Bresenham = {};
var Slope = {
@ -6815,7 +6793,7 @@ define(
"./array_helper"
],
function(BarcodeReader, ArrayHelper) {
"use strict";
function Code39Reader() {
BarcodeReader.call(this);
@ -6825,7 +6803,8 @@ define(
ALPHABETH_STRING: {value: "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ-. *$/+%"},
ALPHABET: {value: [48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 45, 46, 32, 42, 36, 47, 43, 37]},
CHARACTER_ENCODINGS: {value: [0x034, 0x121, 0x061, 0x160, 0x031, 0x130, 0x070, 0x025, 0x124, 0x064, 0x109, 0x049, 0x148, 0x019, 0x118, 0x058, 0x00D, 0x10C, 0x04C, 0x01C, 0x103, 0x043, 0x142, 0x013, 0x112, 0x052, 0x007, 0x106, 0x046, 0x016, 0x181, 0x0C1, 0x1C0, 0x091, 0x190, 0x0D0, 0x085, 0x184, 0x0C4, 0x094, 0x0A8, 0x0A2, 0x08A, 0x02A]},
ASTERISK: {value: 0x094}
ASTERISK: {value: 0x094},
FORMAT: {value: "code_39", writeable: false}
};
Code39Reader.prototype = Object.create(BarcodeReader.prototype, properties);
@ -7034,7 +7013,7 @@ define(
"./code_39_reader"
],
function(Code39Reader) {
"use strict";
function Code39VINReader() {
Code39Reader.call(this);
@ -7094,7 +7073,7 @@ define(
"./barcode_reader"
],
function(BarcodeReader) {
"use strict";
function CodabarReader() {
BarcodeReader.call(this);
@ -7108,7 +7087,8 @@ define(
START_END: {value: [0x01A, 0x029, 0x00B, 0x00E]},
MIN_ENCODED_CHARS: {value: 4},
MAX_ACCEPTABLE: {value: 2.0},
PADDING: {value: 1.5}
PADDING: {value: 1.5},
FORMAT: {value: "codabar", writeable: false}
};
CodabarReader.prototype = Object.create(BarcodeReader.prototype, properties);
@ -7407,13 +7387,17 @@ define(
"./ean_reader"
],
function(EANReader) {
"use strict";
function UPCReader() {
EANReader.call(this);
}
UPCReader.prototype = Object.create(EANReader.prototype);
var properties = {
FORMAT: {value: "upc_a", writeable: false}
};
UPCReader.prototype = Object.create(EANReader.prototype, properties);
UPCReader.prototype.constructor = UPCReader;
UPCReader.prototype._decode = function() {
@ -7438,13 +7422,17 @@ define(
"./ean_reader"
],
function(EANReader) {
"use strict";
function EAN8Reader() {
EANReader.call(this);
}
EAN8Reader.prototype = Object.create(EANReader.prototype);
var properties = {
FORMAT: {value: "ean_8", writeable: false}
};
EAN8Reader.prototype = Object.create(EANReader.prototype, properties);
EAN8Reader.prototype.constructor = EAN8Reader;
EAN8Reader.prototype._decodePayload = function(code, result, decodedCodes) {
@ -7489,7 +7477,7 @@ define(
"./ean_reader"
],
function(EANReader) {
"use strict";
function UPCEReader() {
EANReader.call(this);
@ -7499,7 +7487,8 @@ define(
CODE_FREQUENCY : {value: [
[ 56, 52, 50, 49, 44, 38, 35, 42, 41, 37 ],
[7, 11, 13, 14, 19, 25, 28, 21, 22, 26]]},
STOP_PATTERN: { value: [1 / 6 * 7, 1 / 6 * 7, 1 / 6 * 7, 1 / 6 * 7, 1 / 6 * 7, 1 / 6 * 7]}
STOP_PATTERN: { value: [1 / 6 * 7, 1 / 6 * 7, 1 / 6 * 7, 1 / 6 * 7, 1 / 6 * 7, 1 / 6 * 7]},
FORMAT: {value: "upc_e", writeable: false}
};
UPCEReader.prototype = Object.create(EANReader.prototype, properties);
@ -7618,7 +7607,7 @@ define('barcode_decoder',[
UPCReader,
EAN8Reader,
UPCEReader) {
"use strict";
var readers = {
code_128_reader: Code128Reader,
@ -7644,8 +7633,7 @@ define('barcode_decoder',[
overlay : null
}
},
_barcodeReaders = [],
_barcodeReader = null;
_barcodeReaders = [];
initCanvas();
initReaders();
@ -7766,9 +7754,6 @@ define('barcode_decoder',[
for ( i = 0; i < _barcodeReaders.length && result === null; i++) {
result = _barcodeReaders[i].decodePattern(barcodeLine.line);
if (result !== null) {
_barcodeReader = _barcodeReaders[i];
}
}
if(result === null){
return null;
@ -7897,7 +7882,7 @@ define('barcode_decoder',[
/* global define */
define('frame_grabber',["cv_utils"], function(CVUtils) {
"use strict";
var FrameGrabber = {};
@ -7976,7 +7961,7 @@ define('frame_grabber',["cv_utils"], function(CVUtils) {
/* global define */
define('html_utils',[], function() {
"use strict";
function createNode(htmlStr) {
var temp = document.createElement('div');
@ -8076,7 +8061,7 @@ define('config',[],function(){
/* global define */
define('events',[],function() {
"use strict";
var _events = function() {
var events = {};
@ -8167,7 +8152,7 @@ define('events',[],function() {
/* global define, MediaStreamTrack */
define('camera_access',["html_utils"], function(HtmlUtils) {
"use strict";
var streamRef,
loadedDataHandler;
@ -8332,7 +8317,7 @@ function(Code128Reader,
Events,
CameraAccess,
ImageDebug) {
"use strict";
var _inputStream,
_framegrabber,

File diff suppressed because one or more lines are too long

@ -162,7 +162,7 @@ define(['quagga'], function(Quagga) {
$node = $('<li><div class="thumbnail"><div class="imgWrapper"><img /></div><div class="caption"><h4 class="code"></h4></div></div></li>');
$node.find("img").attr("src", canvas.toDataURL());
$node.find("h4.code").html(code);
$node.find("h4.code").html(code + " (" + result.codeResult.format + ")");
$("#result_strip ul.thumbnails").prepend($node);
});
});

@ -1,6 +1,6 @@
{
"name": "quagga",
"version": "0.6.8",
"version": "0.6.9",
"description": "An advanced barcode-scanner written in JavaScript",
"main": "dist/quagga.js",
"devDependencies": {

@ -35,6 +35,7 @@ define(['quagga', 'async'], function(Quagga, async) {
Quagga.decodeSingle(config, function(result) {
console.log(sample.name);
expect(result.codeResult.code).to.equal(sample.result);
expect(result.codeResult.format).to.equal(sample.format);
callback();
});
}, function() {
@ -45,18 +46,22 @@ define(['quagga', 'async'], function(Quagga, async) {
describe("EAN", function() {
var config = generateConfig(),
testSet = [
{"name": "image-001.jpg", "result": "3574660239843"},
{"name": "image-002.jpg", "result": "8032754490297"},
{"name": "image-003.jpg", "result": "4006209700068"},
/* {"name": "image-004.jpg", "result": "9002233139084"}, */
/* {"name": "image-005.jpg", "result": "8004030044005"}, */
{"name": "image-006.jpg", "result": "4003626011159"},
{"name": "image-007.jpg", "result": "2111220009686"},
{"name": "image-008.jpg", "result": "9000275609022"},
{"name": "image-009.jpg", "result": "9004593978587"},
{"name": "image-010.jpg", "result": "9002244845578"}
];
testSet = [
{"name": "image-001.jpg", "result": "3574660239843"},
{"name": "image-002.jpg", "result": "8032754490297"},
{"name": "image-003.jpg", "result": "4006209700068"},
/* {"name": "image-004.jpg", "result": "9002233139084"}, */
/* {"name": "image-005.jpg", "result": "8004030044005"}, */
{"name": "image-006.jpg", "result": "4003626011159"},
{"name": "image-007.jpg", "result": "2111220009686"},
{"name": "image-008.jpg", "result": "9000275609022"},
{"name": "image-009.jpg", "result": "9004593978587"},
{"name": "image-010.jpg", "result": "9002244845578"}
];
testSet.forEach(function(sample) {
sample.format = "ean_13";
});
config.decoder.readers = ['ean_reader'];
_runTestSet(testSet, config);
@ -65,17 +70,21 @@ define(['quagga', 'async'], function(Quagga, async) {
describe("Code128", function() {
var config = generateConfig(),
testSet = [
{"name": "image-001.jpg", "result": "0001285112001000040801"},
{"name": "image-002.jpg", "result": "FANAVF1461710"},
{"name": "image-003.jpg", "result": "673023"},
// {"name": "image-004.jpg", "result": "010210150301625334"},
{"name": "image-005.jpg", "result": "419055603900009001012999"},
{"name": "image-006.jpg", "result": "419055603900009001012999"},
{"name": "image-007.jpg", "result": "T 000003552345"},
{"name": "image-008.jpg", "result": "FANAVF1461710"},
{"name": "image-009.jpg", "result": "0001285112001000040801"},
{"name": "image-010.jpg", "result": "673023"}
];
{"name": "image-001.jpg", "result": "0001285112001000040801"},
// {"name": "image-002.jpg", "result": "FANAVF1461710"},
// {"name": "image-003.jpg", "result": "673023"},
{"name": "image-004.jpg", "result": "010210150301625334"},
{"name": "image-005.jpg", "result": "419055603900009001012999"},
{"name": "image-006.jpg", "result": "419055603900009001012999"},
{"name": "image-007.jpg", "result": "T 000003552345"},
{"name": "image-008.jpg", "result": "FANAVF1461710"},
{"name": "image-009.jpg", "result": "0001285112001000040801"},
{"name": "image-010.jpg", "result": "673023"}
];
testSet.forEach(function(sample) {
sample.format = "code_128";
});
config.decoder.readers = ['code_128_reader'];
_runTestSet(testSet, config);
@ -84,17 +93,21 @@ define(['quagga', 'async'], function(Quagga, async) {
describe("Code39", function() {
var config = generateConfig(),
testSet = [
{"name": "image-001.jpg", "result": "B3% $DAD$"},
/*{"name": "image-002.jpg", "result": "QUAGGAJS"},*/
{"name": "image-003.jpg", "result": "CODE39"},
{"name": "image-004.jpg", "result": "QUAGGAJS"},
/* {"name": "image-005.jpg", "result": "CODE39"}, */
{"name": "image-006.jpg", "result": "2/4-8/16-32"},
{"name": "image-007.jpg", "result": "2/4-8/16-32"},
{"name": "image-008.jpg", "result": "CODE39"},
{"name": "image-009.jpg", "result": "2/4-8/16-32"},
{"name": "image-010.jpg", "result": "CODE39"}
];
{"name": "image-001.jpg", "result": "B3% $DAD$"},
/*{"name": "image-002.jpg", "result": "QUAGGAJS"},*/
{"name": "image-003.jpg", "result": "CODE39"},
{"name": "image-004.jpg", "result": "QUAGGAJS"},
/* {"name": "image-005.jpg", "result": "CODE39"}, */
{"name": "image-006.jpg", "result": "2/4-8/16-32"},
{"name": "image-007.jpg", "result": "2/4-8/16-32"},
{"name": "image-008.jpg", "result": "CODE39"},
{"name": "image-009.jpg", "result": "2/4-8/16-32"},
{"name": "image-010.jpg", "result": "CODE39"}
];
testSet.forEach(function(sample) {
sample.format = "code_39";
});
config.decoder.readers = ['code_39_reader'];
_runTestSet(testSet, config);
@ -103,17 +116,21 @@ define(['quagga', 'async'], function(Quagga, async) {
describe("EAN-8", function() {
var config = generateConfig(),
testSet = [
{"name": "image-001.jpg", "result": "42191605"},
{"name": "image-002.jpg", "result": "42191605"},
{"name": "image-003.jpg", "result": "90311208"},
{"name": "image-004.jpg", "result": "24057257"},
{"name": "image-005.jpg", "result": "90162602"},
{"name": "image-006.jpg", "result": "24036153"},
{"name": "image-007.jpg", "result": "42176817"},
/*{"name": "image-008.jpg", "result": "42191605"},*/
{"name": "image-009.jpg", "result": "42242215"},
{"name": "image-010.jpg", "result": "42184799"}
];
{"name": "image-001.jpg", "result": "42191605"},
{"name": "image-002.jpg", "result": "42191605"},
{"name": "image-003.jpg", "result": "90311208"},
{"name": "image-004.jpg", "result": "24057257"},
{"name": "image-005.jpg", "result": "90162602"},
{"name": "image-006.jpg", "result": "24036153"},
{"name": "image-007.jpg", "result": "42176817"},
/*{"name": "image-008.jpg", "result": "42191605"},*/
{"name": "image-009.jpg", "result": "42242215"},
{"name": "image-010.jpg", "result": "42184799"}
];
testSet.forEach(function(sample) {
sample.format = "ean_8";
});
config.decoder.readers = ['ean_8_reader'];
_runTestSet(testSet, config);
@ -134,6 +151,10 @@ define(['quagga', 'async'], function(Quagga, async) {
{"name": "image-010.jpg", "result": "039047013551"}
];
testSet.forEach(function(sample) {
sample.format = "upc_a";
});
config.decoder.readers = ['upc_reader'];
_runTestSet(testSet, config);
});
@ -153,6 +174,10 @@ define(['quagga', 'async'], function(Quagga, async) {
{"name": "image-010.jpg", "result": "01264904"}
];
testSet.forEach(function(sample) {
sample.format = "upc_e";
});
config.decoder.readers = ['upc_e_reader'];
_runTestSet(testSet, config);
});
@ -172,6 +197,10 @@ define(['quagga', 'async'], function(Quagga, async) {
{"name": "image-010.jpg", "result": "C$399.95A"}
];
testSet.forEach(function(sample) {
sample.format = "codabar";
});
config.decoder.readers = ['codabar_reader'];
_runTestSet(testSet, config);
});

@ -49,8 +49,7 @@ define([
overlay : null
}
},
_barcodeReaders = [],
_barcodeReader = null;
_barcodeReaders = [];
initCanvas();
initReaders();
@ -171,9 +170,6 @@ define([
for ( i = 0; i < _barcodeReaders.length && result === null; i++) {
result = _barcodeReaders[i].decodePattern(barcodeLine.line);
if (result !== null) {
_barcodeReader = _barcodeReaders[i];
}
}
if(result === null){
return null;

@ -166,6 +166,9 @@ define(
} else {
result.direction = BarcodeReader.DIRECTION.FORWARD;
}
if (result) {
result.format = self.FORMAT;
}
return result;
};
@ -180,6 +183,11 @@ define(
}
return true;
};
Object.defineProperty(BarcodeReader.prototype, "FORMAT", {
value: 'unknown',
writeable: false
});
BarcodeReader.DIRECTION = {
FORWARD : 1,

@ -20,7 +20,8 @@ define(
START_END: {value: [0x01A, 0x029, 0x00B, 0x00E]},
MIN_ENCODED_CHARS: {value: 4},
MAX_ACCEPTABLE: {value: 2.0},
PADDING: {value: 1.5}
PADDING: {value: 1.5},
FORMAT: {value: "codabar", writeable: false}
};
CodabarReader.prototype = Object.create(BarcodeReader.prototype, properties);

@ -132,7 +132,8 @@ define(
[2, 3, 3, 1, 1, 1, 2]
]},
SINGLE_CODE_ERROR: {value: 1},
AVG_CODE_ERROR: {value: 0.5}
AVG_CODE_ERROR: {value: 0.5},
FORMAT: {value: "code_128", writeable: false}
};
Code128Reader.prototype = Object.create(BarcodeReader.prototype, properties);
@ -179,58 +180,6 @@ define(
}
return null;
};
Code128Reader.prototype._findEnd = function() {
var counter = [0, 0, 0, 0, 0, 0, 0],
i,
self = this,
offset = self._nextSet(self._row),
isWhite = !self._row[offset],
counterPos = 0,
bestMatch = {
error : Number.MAX_VALUE,
code : -1,
start : 0,
end : 0
},
error,
j,
sum,
normalized;
for ( i = offset; i < self._row.length; i++) {
if (self._row[i] ^ isWhite) {
counter[counterPos]++;
} else {
if (counterPos === counter.length - 1) {
sum = 0;
for ( j = 0; j < counter.length; j++) {
sum += counter[j];
}
normalized = self._normalize(counter, 13);
error = self._matchPattern(normalized, self.CODE_PATTERN[self.STOP_CODE]);
if (error < self.AVG_CODE_ERROR) {
bestMatch.error = error;
bestMatch.start = i - sum;
bestMatch.end = i;
return bestMatch;
}
for ( j = 0; j < 5; j++) {
counter[j] = counter[j + 2];
}
counter[5] = 0;
counter[6] = 0;
counterPos--;
} else {
counterPos++;
}
counter[counterPos] = 1;
isWhite = !isWhite;
}
}
return null;
};
Code128Reader.prototype._findStart = function() {
var counter = [0, 0, 0, 0, 0, 0],
@ -420,7 +369,7 @@ define(
// find end bar
code.end = self._nextUnset(self._row, code.end);
if (code.end === self._row.length) {
if(!self._verifyTrailingWhitespace(code)){
return null;
}
@ -431,9 +380,15 @@ define(
return null;
}
if (!result.length) {
return null;
}
// remove last code from result (checksum)
result.splice(result.length - 1, 1);
return {
code : result.join(""),
start : startInfo.start,
@ -444,6 +399,20 @@ define(
endInfo : code
};
};
BarcodeReader.prototype._verifyTrailingWhitespace = function(endInfo) {
var self = this,
trailingWhitespaceEnd;
trailingWhitespaceEnd = endInfo.end + ((endInfo.end - endInfo.start) / 2);
if (trailingWhitespaceEnd < self._row.length) {
if (self._matchRange(endInfo.end, trailingWhitespaceEnd, 0)) {
return endInfo;
}
}
return null;
};
return (Code128Reader);
}

@ -17,7 +17,8 @@ define(
ALPHABETH_STRING: {value: "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ-. *$/+%"},
ALPHABET: {value: [48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 45, 46, 32, 42, 36, 47, 43, 37]},
CHARACTER_ENCODINGS: {value: [0x034, 0x121, 0x061, 0x160, 0x031, 0x130, 0x070, 0x025, 0x124, 0x064, 0x109, 0x049, 0x148, 0x019, 0x118, 0x058, 0x00D, 0x10C, 0x04C, 0x01C, 0x103, 0x043, 0x142, 0x013, 0x112, 0x052, 0x007, 0x106, 0x046, 0x016, 0x181, 0x0C1, 0x1C0, 0x091, 0x190, 0x0D0, 0x085, 0x184, 0x0C4, 0x094, 0x0A8, 0x0A2, 0x08A, 0x02A]},
ASTERISK: {value: 0x094}
ASTERISK: {value: 0x094},
FORMAT: {value: "code_39", writeable: false}
};
Code39Reader.prototype = Object.create(BarcodeReader.prototype, properties);

@ -12,7 +12,11 @@ define(
EANReader.call(this);
}
EAN8Reader.prototype = Object.create(EANReader.prototype);
var properties = {
FORMAT: {value: "ean_8", writeable: false}
};
EAN8Reader.prototype = Object.create(EANReader.prototype, properties);
EAN8Reader.prototype.constructor = EAN8Reader;
EAN8Reader.prototype._decodePayload = function(code, result, decodedCodes) {

@ -43,7 +43,8 @@ define(
]},
CODE_FREQUENCY : {value: [0, 11, 13, 14, 19, 25, 28, 21, 22, 26]},
SINGLE_CODE_ERROR: {value: 0.7},
AVG_CODE_ERROR: {value: 0.3}
AVG_CODE_ERROR: {value: 0.3},
FORMAT: {value: "ean_13", writeable: false}
};
EANReader.prototype = Object.create(BarcodeReader.prototype, properties);

@ -16,7 +16,8 @@ define(
CODE_FREQUENCY : {value: [
[ 56, 52, 50, 49, 44, 38, 35, 42, 41, 37 ],
[7, 11, 13, 14, 19, 25, 28, 21, 22, 26]]},
STOP_PATTERN: { value: [1 / 6 * 7, 1 / 6 * 7, 1 / 6 * 7, 1 / 6 * 7, 1 / 6 * 7, 1 / 6 * 7]}
STOP_PATTERN: { value: [1 / 6 * 7, 1 / 6 * 7, 1 / 6 * 7, 1 / 6 * 7, 1 / 6 * 7, 1 / 6 * 7]},
FORMAT: {value: "upc_e", writeable: false}
};
UPCEReader.prototype = Object.create(EANReader.prototype, properties);

@ -12,7 +12,11 @@ define(
EANReader.call(this);
}
UPCReader.prototype = Object.create(EANReader.prototype);
var properties = {
FORMAT: {value: "upc_a", writeable: false}
};
UPCReader.prototype = Object.create(EANReader.prototype, properties);
UPCReader.prototype.constructor = UPCReader;
UPCReader.prototype._decode = function() {

Loading…
Cancel
Save