Commit 640a5e02 authored by Romain Courteaud's avatar Romain Courteaud

erp5_document_scanner: handle caman error

parent a06535ce
...@@ -126,23 +126,28 @@ ...@@ -126,23 +126,28 @@
caman.Store.flush(true); caman.Store.flush(true);
} }
return new Promise(function (resolve) { return new Promise(function (resolve, reject) {
// XXX the correct usage is `new Caman()` but the library does not support it // XXX the correct usage is `new Caman()` but the library does not support it
local_caman = caman(canvas, null, function () { local_caman = caman(canvas, null, function () {
if (settings.brightness && settings.brightness !== 0) { try {
this.brightness(settings.brightness); if (settings.brightness && settings.brightness !== 0) {
} this.brightness(settings.brightness);
if (settings.contrast && settings.contrast !== 0) { }
this.contrast(settings.contrast); if (settings.contrast && settings.contrast !== 0) {
} this.contrast(settings.contrast);
if (settings.enable_greyscale) { }
this.greyscale(); if (settings.enable_greyscale) {
} this.greyscale();
this.render(function () { }
// XXX canceller should be called automatically ? this.render(function () {
// XXX canceller should be called automatically ?
canceller();
resolve();
});
} catch (error) {
canceller(); canceller();
resolve(); reject(error);
}); }
}); });
return local_caman; return local_caman;
}, canceller); }, canceller);
...@@ -480,10 +485,13 @@ ...@@ -480,10 +485,13 @@
return blob; return blob;
} }
var canvas; var div;
return new RSVP.Queue(createImageBitmap(blob)) return new RSVP.Queue(createImageBitmap(blob))
.push(function (bitmap) { .push(function (bitmap) {
canvas = domsugar('canvas'); var canvas = domsugar('canvas');
// Caman expect the canvas to be in a container
// in order to replace it when resizing
div = domsugar('div', [canvas]);
canvas.width = bitmap.width; canvas.width = bitmap.width;
canvas.height = bitmap.height; canvas.height = bitmap.height;
...@@ -492,7 +500,7 @@ ...@@ -492,7 +500,7 @@
return handleCaman(canvas, settings); return handleCaman(canvas, settings);
}) })
.push(function () { .push(function () {
return promiseCanvasToBlob(canvas); return promiseCanvasToBlob(div.firstElementChild);
}); });
} }
...@@ -529,7 +537,10 @@ ...@@ -529,7 +537,10 @@
return image_capture.getPhotoCapabilities(); return image_capture.getPhotoCapabilities();
}) })
.push(function (capabilities) { .push(function (capabilities) {
return image_capture.takePhoto({imageWidth: capabilities.imageWidth.max}); return image_capture.takePhoto({
imageWidth: capabilities.imageWidth.max,
imageHeight: capabilities.imageHeight.max
});
}) })
.push(function (blob) { .push(function (blob) {
gadget.detached_promise_dict.media_stream.cancel('Not needed anymore, as captured'); gadget.detached_promise_dict.media_stream.cancel('Not needed anymore, as captured');
......
...@@ -244,7 +244,7 @@ ...@@ -244,7 +244,7 @@
</item> </item>
<item> <item>
<key> <string>serial</string> </key> <key> <string>serial</string> </key>
<value> <string>982.57254.54695.8721</string> </value> <value> <string>982.58248.12377.39526</string> </value>
</item> </item>
<item> <item>
<key> <string>state</string> </key> <key> <string>state</string> </key>
...@@ -262,7 +262,7 @@ ...@@ -262,7 +262,7 @@
</tuple> </tuple>
<state> <state>
<tuple> <tuple>
<float>1585584566.97</float> <float>1585644055.38</float>
<string>UTC</string> <string>UTC</string>
</tuple> </tuple>
</state> </state>
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment