|
|
|
@ -8,7 +8,6 @@
|
|
|
|
|
|
|
|
|
|
import * as Log from './util/logging.js';
|
|
|
|
|
import Base64 from "./base64.js";
|
|
|
|
|
import { supportsImageMetadata } from './util/browser.js';
|
|
|
|
|
|
|
|
|
|
export default class Display {
|
|
|
|
|
constructor(target) {
|
|
|
|
@ -392,46 +391,6 @@ export default class Display {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
blitRgbImage(x, y, width, height, arr, offset, fromQueue) {
|
|
|
|
|
if (this._renderQ.length !== 0 && !fromQueue) {
|
|
|
|
|
// NB(directxman12): it's technically more performant here to use preallocated arrays,
|
|
|
|
|
// but it's a lot of extra work for not a lot of payoff -- if we're using the render queue,
|
|
|
|
|
// this probably isn't getting called *nearly* as much
|
|
|
|
|
const newArr = new Uint8Array(width * height * 3);
|
|
|
|
|
newArr.set(new Uint8Array(arr.buffer, 0, newArr.length));
|
|
|
|
|
this._renderQPush({
|
|
|
|
|
'type': 'blitRgb',
|
|
|
|
|
'data': newArr,
|
|
|
|
|
'x': x,
|
|
|
|
|
'y': y,
|
|
|
|
|
'width': width,
|
|
|
|
|
'height': height,
|
|
|
|
|
});
|
|
|
|
|
} else {
|
|
|
|
|
this._rgbImageData(x, y, width, height, arr, offset);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
blitRgbxImage(x, y, width, height, arr, offset, fromQueue) {
|
|
|
|
|
if (this._renderQ.length !== 0 && !fromQueue) {
|
|
|
|
|
// NB(directxman12): it's technically more performant here to use preallocated arrays,
|
|
|
|
|
// but it's a lot of extra work for not a lot of payoff -- if we're using the render queue,
|
|
|
|
|
// this probably isn't getting called *nearly* as much
|
|
|
|
|
const newArr = new Uint8Array(width * height * 4);
|
|
|
|
|
newArr.set(new Uint8Array(arr.buffer, 0, newArr.length));
|
|
|
|
|
this._renderQPush({
|
|
|
|
|
'type': 'blitRgbx',
|
|
|
|
|
'data': newArr,
|
|
|
|
|
'x': x,
|
|
|
|
|
'y': y,
|
|
|
|
|
'width': width,
|
|
|
|
|
'height': height,
|
|
|
|
|
});
|
|
|
|
|
} else {
|
|
|
|
|
this._rgbxImageData(x, y, width, height, arr, offset);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
drawImage(img, x, y, w, h) {
|
|
|
|
|
if (img.width != w || img.height != h) {
|
|
|
|
|
this._drawCtx.drawImage(img, x, y, w, h);
|
|
|
|
@ -491,19 +450,6 @@ export default class Display {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_rgbImageData(x, y, width, height, arr, offset) {
|
|
|
|
|
const img = this._drawCtx.createImageData(width, height);
|
|
|
|
|
const data = img.data;
|
|
|
|
|
for (let i = 0, j = offset; i < width * height * 4; i += 4, j += 3) {
|
|
|
|
|
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, y);
|
|
|
|
|
this._damage(x, y, img.width, img.height);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_bgrxImageData(x, y, width, height, arr, offset) {
|
|
|
|
|
const img = this._drawCtx.createImageData(width, height);
|
|
|
|
|
const data = img.data;
|
|
|
|
@ -517,19 +463,6 @@ export default class Display {
|
|
|
|
|
this._damage(x, y, img.width, img.height);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_rgbxImageData(x, y, width, height, arr, offset) {
|
|
|
|
|
// NB(directxman12): arr must be an Type Array view
|
|
|
|
|
let img;
|
|
|
|
|
if (supportsImageMetadata) {
|
|
|
|
|
img = new ImageData(new Uint8ClampedArray(arr.buffer, arr.byteOffset, width * height * 4), width, height);
|
|
|
|
|
} else {
|
|
|
|
|
img = this._drawCtx.createImageData(width, height);
|
|
|
|
|
img.data.set(new Uint8ClampedArray(arr.buffer, arr.byteOffset, width * height * 4));
|
|
|
|
|
}
|
|
|
|
|
this._drawCtx.putImageData(img, x, y);
|
|
|
|
|
this._damage(x, y, img.width, img.height);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_renderQPush(action) {
|
|
|
|
|
this._renderQ.push(action);
|
|
|
|
|
if (this._renderQ.length === 1) {
|
|
|
|
@ -563,12 +496,6 @@ export default class Display {
|
|
|
|
|
case 'blit':
|
|
|
|
|
this.blitImage(a.x, a.y, a.width, a.height, a.data, 0, true);
|
|
|
|
|
break;
|
|
|
|
|
case 'blitRgb':
|
|
|
|
|
this.blitRgbImage(a.x, a.y, a.width, a.height, a.data, 0, true);
|
|
|
|
|
break;
|
|
|
|
|
case 'blitRgbx':
|
|
|
|
|
this.blitRgbxImage(a.x, a.y, a.width, a.height, a.data, 0, true);
|
|
|
|
|
break;
|
|
|
|
|
case 'img':
|
|
|
|
|
/* IE tends to set "complete" prematurely, so check dimensions */
|
|
|
|
|
if (a.img.complete && (a.img.width !== 0) && (a.img.height !== 0)) {
|
|
|
|
|