Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

switch to dealing strictly with imagedata

  • Loading branch information...
commit f19c24274198b61ddf15e0c81a993a3676834227 1 parent bf06198
@mental authored
Showing with 7 additions and 20 deletions.
  1. +7 −20 js/retrograph.js
View
27 js/retrograph.js
@@ -46,23 +46,9 @@ var Retrograph = (function () {
this._transferBuffer = Module._malloc(TRANSFER_BUFFER_SIZE);
this._currentScanline = 0;
- this.canvas = document.createElement('canvas');
- this._ctx = this._canvas.getContext('2d');
-
- this.canvas.setAttribute('width', RETROGRAPH_DISPLAY_WIDTH);
- this.canvas.setAttribute('height', RETROGRAPH_DISPLAY_HEIGHT);
-
- // Canvas width and height are specified in CSS pixels. There can be
- // multiple display (and therefore image data) pixels to a CSS pixel,
- // so we have to scale the canvas accordingly.
- var tempImageData = this._ctx.getImageData(0, 0, RETROGRAPH_DISPLAY_WIDTH, RETROGRAPH_DISPLAY_HEIGHT);
- this._cssWidth = RETROGRAPH_DISPLAY_WIDTH * RETROGRAPH_DISPLAY_WIDTH / tempImageData.width;
- this._cssHeight = RETROGRAPH_DISPLAY_HEIGHT * RETROGRAPH_DISPLAY_HEIGHT / tempImageData.height;
-
- this.canvas.setAttribute('width', this._cssWidth);
- this.canvas.setAttribute('height', this._cssHeight);
-
- this._imageData = this._ctx.getImageData(0, 0, this._cssWidth, this._cssHeight);
+ var canvas = document.createElement('canvas');
+ var ctx = this._canvas.getContext('2d');
+ this._imageData = ctx.createImageData(RETROGRAPH_DISPLAY_WIDTH, RETROGRAPH_DISPLAY_HEIGHT);
this._vdu = retrograph_new();
checkError(this._vdu);
@@ -116,11 +102,12 @@ var Retrograph = (function () {
}
this._renderScanlines(RETROGRAPH_DISPLAY_HEIGHT);
checkError(this._vdu);
- this._ctx.putImageData(this._imageData, 0, 0);
+ return this._imageData;
};
VDU.prototype.waitScanlines = function (numScanlines) {
- this._renderScanlines(Math.max(0, numScanlines);
+ this._renderScanlines(Math.max(0, numScanlines));
+ checkError(this._vdu);
};
VDU.prototype._renderScanlines = function (numScanlines) {
@@ -130,7 +117,7 @@ var Retrograph = (function () {
var srcArray = Module.HEAP8;
var destArray = this._imageData.data;
var srcOffset = this._transferBuffer;
- var destOffset = this._currentScanline + this._imageData.width * 4;
+ var destOffset = this._currentScanline + RETROGRAPH_DISPLAY_WIDTH * 4;
for (var i = 0; i < RETROGRAPH_DISPLAY_WIDTH; i++) {
destArray[destOffset+i] = srcArray[srcOffset+i];
}
Please sign in to comment.
Something went wrong with that request. Please try again.