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 Oct 23, 2020
1 parent 7a6d805 commit 8804b91
Showing 1 changed file with 17 additions and 8 deletions.
25 changes: 17 additions & 8 deletions core/display.js
Original file line number Diff line number Diff line change
Expand Up @@ -368,16 +368,25 @@ export default class Display {
'height': height
};

const img = new Image();
img.src = "data: " + mime + ";base64," + Base64.encode(arr);
/* IE tends to set "complete" prematurely, so check dimensions */
if (img.complete && (img.width !== 0) && (img.height !== 0)) {
a.img = img;
if (window.createImageBitmap) {
let blob = new Blob([arr], { type: mime });
createImageBitmap(blob)
.then((img) => {
a.img = img;
this._scanRenderQ();
});
} else {
img.addEventListener('load', () => {
const img = new Image();
img.src = "data: " + mime + ";base64," + Base64.encode(arr);
/* IE tends to set "complete" prematurely, so check dimensions */
if (img.complete && (img.width !== 0) && (img.height !== 0)) {
a.img = img;
this._scanRenderQ();
});
} else {
img.addEventListener('load', () => {
a.img = img;
this._scanRenderQ();
});
}
}

this._renderQPush(a);
Expand Down

0 comments on commit 8804b91

Please sign in to comment.