mirror of
https://github.com/sorenisanerd/gotty.git
synced 2024-11-10 07:44:25 +00:00
c66ae7b2e4
Launch an Xspice and run: echo -ne "\033]844;127.0.0.1;9876\007" This will launch a SPiCE client connecting to 127.0.0.1:9876. Still need to add all the security stuff and generally be more defensive in the implementation.
63 lines
1.8 KiB
JavaScript
63 lines
1.8 KiB
JavaScript
var SWCanvas = function(canvas) {
|
|
this.arr = new ArrayBuffer(canvas.width*canvas.height*4);
|
|
this.arr32 = new Uint32Array(this.arr);
|
|
this.arr8 = new Uint8ClampedArray(this.arr);
|
|
this.canvas = canvas;
|
|
this.width = this.canvas.width;
|
|
this.height = this.canvas.height;
|
|
};
|
|
|
|
SWCanvas.prototype.putImageData = function(imgData, x, y) {
|
|
var srcArr = imgData.data.buffer;
|
|
var w = imgData.width;
|
|
var pos = imgData.height;
|
|
var tmp;
|
|
var canvasWidth = this.width;
|
|
var tmpArr;
|
|
while(pos--) {
|
|
tmp = (y+pos)*canvasWidth+x;
|
|
tmpArr = new Uint32Array(srcArr, w*pos*4, w);
|
|
this.arr32.set(tmpArr, tmp);
|
|
}
|
|
};
|
|
|
|
SWCanvas.prototype.getImageData = function(x, y, width, height) {
|
|
var result = new Uint32Array(width*height);
|
|
var arr = this.arr32;
|
|
var pos=height;
|
|
var tmp;
|
|
var canvasWidth = this.width;
|
|
while(pos--) {
|
|
tmp = (y+pos)*canvasWidth+x;
|
|
var line = arr.subarray(tmp,tmp+width);
|
|
result.set(line, width*pos);
|
|
}
|
|
return new ImageData(new Uint8ClampedArray(result.buffer), width, height);
|
|
};
|
|
|
|
SWCanvas.prototype.fillRect = function(r, g, b, x, y, width, height) {
|
|
var line = new Uint32Array(width);
|
|
var color32 = 4278190080 | r | g << 8 | b << 16;
|
|
var canvasWidth = this.width;
|
|
var w = width;
|
|
while(w--) {
|
|
line[w] = color32;
|
|
}
|
|
var tmp;
|
|
while(height--) {
|
|
tmp = (y+height)*canvasWidth+x;
|
|
this.arr32.set(line, tmp);
|
|
}
|
|
}
|
|
|
|
//copy from canvas to arr
|
|
SWCanvas.prototype.flushBack = function() {
|
|
var arr8 = this.canvas.getContext('2d').getImageData(0, 0, this.width, this.height).data;
|
|
this.arr8.set(arr8);
|
|
};
|
|
|
|
//copy from arr to canvas
|
|
SWCanvas.prototype.flush = function() {
|
|
var imgData = new ImageData(this.arr8, this.width, this.height);
|
|
this.canvas.getContext('2d').putImageData(imgData,0, 0);
|
|
}; |