Commit 3add7a8f authored by Gabriel Monnerat's avatar Gabriel Monnerat

erp5_document_scanner: Move handleDataURLRead code outside the promise

parent 5f872cc2
......@@ -17,49 +17,53 @@
});
}
function getOrientation(blob, callback) {
var fr = new FileReader();
return new RSVP.Promise(function waitFormDataURLRead(resolve, reject) {
fr.addEventListener("load", function handleDataURLRead(evt) {
var view = new DataView(evt.target.result),
length = view.byteLength,
offset = 2,
marker,
little,
tags,
i;
if (view.getUint16(0, false) !== 0xFFD8) {
return resolve(-2);
function handleDataURLRead(data_url) {
var view = new DataView(data_url),
length = view.byteLength,
offset = 2,
marker,
little,
tags,
i;
if (view.getUint16(0, false) !== 0xFFD8) {
return -2;
}
while (offset < length) {
if (view.getUint16(offset + 2, false) <= 8) {
return -1;
}
marker = view.getUint16(offset, false);
offset += 2;
if (marker === 0xFFE1) {
offset += 2;
if (view.getUint32(offset, false) !== 0x45786966) {
return -1;
}
while (offset < length) {
if (view.getUint16(offset + 2, false) <= 8) {
return resolve(-1);
}
marker = view.getUint16(offset, false);
offset += 2;
if (marker === 0xFFE1) {
offset += 2;
if (view.getUint32(offset, false) !== 0x45786966) {
return resolve(-1);
}
offset += 6;
little = view.getUint16(offset, false) === 0x4949;
offset += view.getUint32(offset + 4, little);
tags = view.getUint16(offset, little);
offset += 2;
for (i = 0; i < tags; i = i + 1) {
if (view.getUint16(offset + (i * 12), little) === 0x0112) {
return resolve(view.getUint16(offset + (i * 12) + 8, little));
}
}
continue;
} else if ((marker & 0xFF00) !== 0xFF00) {
break;
offset += 6;
little = view.getUint16(offset, false) === 0x4949;
offset += view.getUint32(offset + 4, little);
tags = view.getUint16(offset, little);
offset += 2;
for (i = 0; i < tags; i = i + 1) {
if (view.getUint16(offset + (i * 12), little) === 0x0112) {
return view.getUint16(offset + (i * 12) + 8, little);
}
offset += view.getUint16(offset, false);
}
return resolve(-1);
continue;
} else if ((marker & 0xFF00) !== 0xFF00) {
break;
}
offset += view.getUint16(offset, false);
}
return -1;
}
function getOrientation(blob, callback) {
var fr = new FileReader();
return new RSVP.Promise(function waitFormDataURLRead(resolve, reject) {
fr.addEventListener("load", function onload(evt) {
resolve(handleDataURLRead(evt.target.result));
});
fr.addEventListener("error", reject);
......
......@@ -244,7 +244,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>982.16570.34450.716</string> </value>
<value> <string>982.16659.47570.45977</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -262,7 +262,7 @@
</tuple>
<state>
<tuple>
<float>1583145490.98</float>
<float>1583149298.17</float>
<string>UTC</string>
</tuple>
</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