This commit is contained in:
Jungkook Park 2016-08-21 10:38:28 +00:00 committed by GitHub
commit 92728aae5e
1 changed files with 23 additions and 4 deletions

View File

@ -15,14 +15,24 @@ var Display;
(function () { (function () {
"use strict"; "use strict";
var SUPPORTS_IMAGEDATA_CONSTRUCTOR = false; var SUPPORTS_UINT8CLAMPEDARRAY = false;
try { try {
new ImageData(new Uint8ClampedArray(1), 1, 1); new Uint8ClampedArray(1);
SUPPORTS_IMAGEDATA_CONSTRUCTOR = true; SUPPORTS_UINT8CLAMPEDARRAY = true;
} catch (ex) { } catch (ex) {
// ignore failure // 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) { Display = function (defaults) {
this._drawCtx = null; this._drawCtx = null;
this._c_forceCanvas = false; this._c_forceCanvas = false;
@ -716,9 +726,18 @@ var Display;
var img; var img;
if (SUPPORTS_IMAGEDATA_CONSTRUCTOR) { if (SUPPORTS_IMAGEDATA_CONSTRUCTOR) {
img = new ImageData(new Uint8ClampedArray(arr.buffer, arr.byteOffset, width * height * 4), width, height); 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 = this._drawCtx.createImageData(width, height);
img.data.set(new Uint8ClampedArray(arr.buffer, arr.byteOffset, width * height * 4)); 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); this._drawCtx.putImageData(img, x - vx, y - vy);
}, },