Fixes bug that is caused by using custom aspectRatio; Closes #37

pull/40/head
Christoph Oberhofer 10 years ago
parent 1042672938
commit eb9fedb794

48
dist/quagga.js vendored

@ -1479,7 +1479,17 @@ define('input_stream',["image_loader"], function(ImageLoader) {
var that = {}, var that = {},
_config = null, _config = null,
_eventNames = ['canrecord', 'ended'], _eventNames = ['canrecord', 'ended'],
_eventHandlers = {}; _eventHandlers = {},
_calculatedWidth,
_calculatedHeight;
function initSize() {
var width = video.videoWidth,
height = video.videoHeight;
_calculatedWidth = _config.size ? width/height > 1 ? _config.size : Math.floor((width/height) * _config.size) : width;
_calculatedHeight = _config.size ? width/height > 1 ? Math.floor((height/width) * _config.size) : _config.size : height;
}
that.getRealWidth = function() { that.getRealWidth = function() {
return video.videoWidth; return video.videoWidth;
@ -1490,11 +1500,19 @@ define('input_stream',["image_loader"], function(ImageLoader) {
}; };
that.getWidth = function() { that.getWidth = function() {
return _config.halfSample ? video.videoWidth / 2 : video.videoWidth; return _calculatedWidth;
}; };
that.getHeight = function() { that.getHeight = function() {
return _config.halfSample ? video.videoHeight / 2 : video.videoHeight; return _calculatedHeight;
};
that.setWidth = function(width) {
_calculatedWidth = width;
};
that.setHeight = function(height) {
_calculatedHeight = height;
}; };
that.setInputStream = function(config) { that.setInputStream = function(config) {
@ -1552,7 +1570,10 @@ define('input_stream',["image_loader"], function(ImageLoader) {
that.trigger = function(eventName, args) { that.trigger = function(eventName, args) {
var j, var j,
handlers = _eventHandlers[eventName]; handlers = _eventHandlers[eventName];
if (eventName === 'canrecord') {
initSize();
}
if (handlers && handlers.length > 0) { if (handlers && handlers.length > 0) {
for ( j = 0; j < handlers.length; j++) { for ( j = 0; j < handlers.length; j++) {
handlers[j].apply(that, args); handlers[j].apply(that, args);
@ -1575,14 +1596,6 @@ define('input_stream',["image_loader"], function(ImageLoader) {
return false; return false;
}; };
that.getWidth = function() {
return this.getConfig().halfSample ? video.videoWidth / 2 : video.videoWidth;
};
that.getHeight = function() {
return this.getConfig().halfSample ? video.videoHeight / 2 : video.videoHeight;
};
return that; return that;
}; };
@ -8240,19 +8253,20 @@ function(Code128Reader,
var patchSize, var patchSize,
width = _inputStream.getWidth(), width = _inputStream.getWidth(),
height = _inputStream.getHeight(), height = _inputStream.getHeight(),
halfSample = _config.locator.halfSample, halfSample = _config.locator.halfSample ? 0.5 : 1,
size = { size = {
x: Math.floor(width * (halfSample ? 0.5 : 1)), x: Math.floor(width * halfSample),
y: Math.floor(height * (halfSample ? 0.5 : 1)) y: Math.floor(height * halfSample)
}; };
if (_config.locate) { if (_config.locate) {
try { try {
console.log(size);
patchSize = CVUtils.calculatePatchSize(_config.locator.patchSize, size); patchSize = CVUtils.calculatePatchSize(_config.locator.patchSize, size);
} catch (error) { } catch (error) {
if (error instanceof CVUtils.AdjustToSizeError) { if (error instanceof CVUtils.AdjustToSizeError) {
_inputStream.setWidth(Math.floor(width/error.patchSize.x)*error.patchSize.x); _inputStream.setWidth(Math.floor(Math.floor(size.x/error.patchSize.x)*(1/halfSample)*error.patchSize.x));
_inputStream.setHeight(Math.floor(height/error.patchSize.y)*error.patchSize.y); _inputStream.setHeight(Math.floor(Math.floor(size.y/error.patchSize.y)*(1/halfSample)*error.patchSize.y));
patchSize = error.patchSize; patchSize = error.patchSize;
} }
} }

File diff suppressed because one or more lines are too long

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

@ -9,7 +9,17 @@ define(["image_loader"], function(ImageLoader) {
var that = {}, var that = {},
_config = null, _config = null,
_eventNames = ['canrecord', 'ended'], _eventNames = ['canrecord', 'ended'],
_eventHandlers = {}; _eventHandlers = {},
_calculatedWidth,
_calculatedHeight;
function initSize() {
var width = video.videoWidth,
height = video.videoHeight;
_calculatedWidth = _config.size ? width/height > 1 ? _config.size : Math.floor((width/height) * _config.size) : width;
_calculatedHeight = _config.size ? width/height > 1 ? Math.floor((height/width) * _config.size) : _config.size : height;
}
that.getRealWidth = function() { that.getRealWidth = function() {
return video.videoWidth; return video.videoWidth;
@ -20,11 +30,19 @@ define(["image_loader"], function(ImageLoader) {
}; };
that.getWidth = function() { that.getWidth = function() {
return _config.halfSample ? video.videoWidth / 2 : video.videoWidth; return _calculatedWidth;
}; };
that.getHeight = function() { that.getHeight = function() {
return _config.halfSample ? video.videoHeight / 2 : video.videoHeight; return _calculatedHeight;
};
that.setWidth = function(width) {
_calculatedWidth = width;
};
that.setHeight = function(height) {
_calculatedHeight = height;
}; };
that.setInputStream = function(config) { that.setInputStream = function(config) {
@ -82,7 +100,10 @@ define(["image_loader"], function(ImageLoader) {
that.trigger = function(eventName, args) { that.trigger = function(eventName, args) {
var j, var j,
handlers = _eventHandlers[eventName]; handlers = _eventHandlers[eventName];
if (eventName === 'canrecord') {
initSize();
}
if (handlers && handlers.length > 0) { if (handlers && handlers.length > 0) {
for ( j = 0; j < handlers.length; j++) { for ( j = 0; j < handlers.length; j++) {
handlers[j].apply(that, args); handlers[j].apply(that, args);
@ -105,14 +126,6 @@ define(["image_loader"], function(ImageLoader) {
return false; return false;
}; };
that.getWidth = function() {
return this.getConfig().halfSample ? video.videoWidth / 2 : video.videoWidth;
};
that.getHeight = function() {
return this.getConfig().halfSample ? video.videoHeight / 2 : video.videoHeight;
};
return that; return that;
}; };

@ -111,19 +111,20 @@ function(Code128Reader,
var patchSize, var patchSize,
width = _inputStream.getWidth(), width = _inputStream.getWidth(),
height = _inputStream.getHeight(), height = _inputStream.getHeight(),
halfSample = _config.locator.halfSample, halfSample = _config.locator.halfSample ? 0.5 : 1,
size = { size = {
x: Math.floor(width * (halfSample ? 0.5 : 1)), x: Math.floor(width * halfSample),
y: Math.floor(height * (halfSample ? 0.5 : 1)) y: Math.floor(height * halfSample)
}; };
if (_config.locate) { if (_config.locate) {
try { try {
console.log(size);
patchSize = CVUtils.calculatePatchSize(_config.locator.patchSize, size); patchSize = CVUtils.calculatePatchSize(_config.locator.patchSize, size);
} catch (error) { } catch (error) {
if (error instanceof CVUtils.AdjustToSizeError) { if (error instanceof CVUtils.AdjustToSizeError) {
_inputStream.setWidth(Math.floor(width/error.patchSize.x)*error.patchSize.x); _inputStream.setWidth(Math.floor(Math.floor(size.x/error.patchSize.x)*(1/halfSample)*error.patchSize.x));
_inputStream.setHeight(Math.floor(height/error.patchSize.y)*error.patchSize.y); _inputStream.setHeight(Math.floor(Math.floor(size.y/error.patchSize.y)*(1/halfSample)*error.patchSize.y));
patchSize = error.patchSize; patchSize = error.patchSize;
} }
} }

Loading…
Cancel
Save