From dd75a3e77f417b8ea81d6e106e4df224e60975ab Mon Sep 17 00:00:00 2001 From: Jungkook Park Date: Wed, 17 Feb 2016 20:14:54 +0900 Subject: [PATCH] Fix bug that copying image buffer to ImageData fails in IE10 --- include/display.js | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/include/display.js b/include/display.js index 6bf89bd6..54b3b8bc 100644 --- a/include/display.js +++ b/include/display.js @@ -15,14 +15,24 @@ var Display; (function () { "use strict"; - var SUPPORTS_IMAGEDATA_CONSTRUCTOR = false; + var SUPPORTS_UINT8CLAMPEDARRAY = false; try { - new ImageData(new Uint8ClampedArray(1), 1, 1); - SUPPORTS_IMAGEDATA_CONSTRUCTOR = true; + new Uint8ClampedArray(1); + SUPPORTS_UINT8CLAMPEDARRAY = true; } catch (ex) { // ignore failure } + var SUPPORTS_IMAGEDATA_CONSTRUCTOR = false; + if (SUPPORTS_UINT8CLAMPEDARRAY) { + try { + new ImageData(new Uint8ClampedArray(1), 1, 1); + SUPPORTS_IMAGEDATA_CONSTRUCTOR = true; + } catch (ex) { + // ignore failure + } + } + Display = function (defaults) { this._drawCtx = null; this._c_forceCanvas = false; @@ -706,9 +716,18 @@ var Display; var img; if (SUPPORTS_IMAGEDATA_CONSTRUCTOR) { img = new ImageData(new Uint8ClampedArray(arr.buffer, arr.byteOffset, width * height * 4), width, height); - } else { + } else if (SUPPORTS_UINT8CLAMPEDARRAY) { img = this._drawCtx.createImageData(width, height); img.data.set(new Uint8ClampedArray(arr.buffer, arr.byteOffset, width * height * 4)); + } else { + img = this._drawCtx.createImageData(width, height); + var data = img.data; + for (var i = 0, j = offset; i < width * height * 4; i += 4, j += 4) { + data[i] = arr[j]; + data[i + 1] = arr[j + 1]; + data[i + 2] = arr[j + 2]; + data[i + 3] = 255; // Alpha + } } this._drawCtx.putImageData(img, x - vx, y - vy); },