Skip to content

Commit

Permalink
Use ImageBitmap when possible
Browse files Browse the repository at this point in the history
These are much faster than Image object in some browsers, so prefer
them when possible.
  • Loading branch information
CendioOssman committed Aug 23, 2018
1 parent 8b25488 commit ecd9bfe
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions core/display.js
Original file line number Diff line number Diff line change
Expand Up @@ -382,15 +382,24 @@ export default class Display {
'y': y
};

const img = new Image();
img.src = "data: " + mime + ";base64," + Base64.encode(arr);
if (img.complete) {
a.img = img;
} else {
img.addEventListener('load', () => {
if (window.createImageBitmap) {
let blob = new Blob([arr], { type: mime });
createImageBitmap(blob)
.then((img) => {
a.img = img;
this._scan_renderQ();
});
} else {
const img = new Image();
img.src = "data: " + mime + ";base64," + Base64.encode(arr);
if (img.complete) {
a.img = img;
} else {
img.addEventListener('load', () => {
a.img = img;
this._scan_renderQ();
});
}
}

this._renderQ_push(a);
Expand Down

0 comments on commit ecd9bfe

Please sign in to comment.