feat: return `multiple` as array instead of object

pull/90/head
dgreif 10 years ago
parent 9a9b8de4bc
commit 2c14a4897d

@ -381,10 +381,11 @@ more possible clashes, or false-positives. One should take care of the order
the readers are given, since some might return a value even though it is not the readers are given, since some might return a value even though it is not
the correct type (EAN-13 vs. UPC-A). the correct type (EAN-13 vs. UPC-A).
The `multiple` property tells the decoder if it should stop after finding a The `multiple` property tells the decoder if it should continue decoding after
single result. If multiple is set to `true`, the `result` object will have a finding a valid barcode. If multiple is set to `true`, the results will be
`barcodes` array, each of which is a `result` object with it's own `codeResult`, returned as an array of result objects. Each object in the array will have a
`box`, `line`, etc. `box`, and may have a `codeResult` depending on the success of decoding the
individual box.
The remaining properties `drawBoundingBox`, `showFrequency`, `drawScanline` and The remaining properties `drawBoundingBox`, `showFrequency`, `drawScanline` and
`showPattern` are mostly of interest during debugging and visualization. `showPattern` are mostly of interest during debugging and visualization.

@ -267,21 +267,23 @@ export default {
return decodeFromBoundingBox(box); return decodeFromBoundingBox(box);
}, },
decodeFromBoundingBoxes: function(boxes) { decodeFromBoundingBoxes: function(boxes) {
var i, result, barcodes = []; var i, result,
for ( i = 0; i < boxes.length; i++) { barcodes = [],
result = decodeFromBoundingBox(boxes[i]); multiple = config.multiple;
if (result && result.codeResult) {
result.box = boxes[i];
if (!config.multiple) { for ( i = 0; i < boxes.length; i++) {
return result; const box = boxes[i];
} result = decodeFromBoundingBox(box) || {};
result.box = box;
if (multiple) {
barcodes.push(result); barcodes.push(result);
} else if (result.codeResult) {
return result;
} }
} }
if (config.multiple) { if (multiple) {
return { return {
barcodes barcodes
}; };

@ -178,6 +178,10 @@ function transformResult(result) {
moveLine(result.line); moveLine(result.line);
} }
if (result.box) {
moveBox(result.box);
}
if (result.boxes && result.boxes.length > 0) { if (result.boxes && result.boxes.length > 0) {
for (i = 0; i < result.boxes.length; i++) { for (i = 0; i < result.boxes.length; i++) {
moveBox(result.boxes[i]); moveBox(result.boxes[i]);
@ -202,39 +206,35 @@ function transformResult(result) {
} }
function addResult (result, imageData) { function addResult (result, imageData) {
var i;
if (!imageData || !_resultCollector) { if (!imageData || !_resultCollector) {
return; return;
} }
if (result.barcodes) { if (result.barcodes) {
for (i = 0; i < result.barcodes.length; i++) { result.barcodes.filter(barcode => barcode.codeResult)
addResult(result.barcodes[i], imageData); .forEach(barcode => addResult(barcode, imageData));
} } else if (result.codeResult) {
return;
}
if (result.codeResult) {
_resultCollector.addResult(imageData, _inputStream.getCanvasSize(), result.codeResult); _resultCollector.addResult(imageData, _inputStream.getCanvasSize(), result.codeResult);
} }
} }
function hasCodeResult (result) { function hasCodeResult (result) {
return result && result.barcodes ? return result && (result.barcodes ?
result.barcodes.some(barcode => barcode.codeResult) : result.barcodes.some(barcode => barcode.codeResult) :
result.codeResult; result.codeResult);
} }
function publishResult(result, imageData) { function publishResult(result, imageData) {
const resultToPublish = result && (result.barcodes || result);
if (result && _onUIThread) { if (result && _onUIThread) {
transformResult(result); transformResult(result);
addResult(result, imageData); addResult(result, imageData);
} }
Events.publish("processed", result); Events.publish("processed", resultToPublish);
if (hasCodeResult(result)) { if (hasCodeResult(result)) {
Events.publish("detected", result); Events.publish("detected", resultToPublish);
} }
} }

Loading…
Cancel
Save