From 0addbcac897fb53e5400025f0f8ac405de204fbb Mon Sep 17 00:00:00 2001 From: Pierre Ossman Date: Thu, 23 Aug 2018 16:52:48 +0200 Subject: [PATCH] Use ImageBitmap when possible These are much faster than Image object in some browsers, so prefer them when possible. --- core/display.js | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/core/display.js b/core/display.js index 213b1df77..f3c3478fd 100644 --- a/core/display.js +++ b/core/display.js @@ -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);