From beff7f4e08e673614340c045ccf7ae22b44a5bf3 Mon Sep 17 00:00:00 2001 From: Gerrit Brehmer Date: Thu, 19 Dec 2019 15:47:42 +0100 Subject: [PATCH] missing rotation in _rgbImageData --- core/display.js | 101 +++++++++++++++++++++++++++++++++++------------- package.json | 2 +- 2 files changed, 76 insertions(+), 27 deletions(-) diff --git a/core/display.js b/core/display.js index 170f9e78..50a152a6 100644 --- a/core/display.js +++ b/core/display.js @@ -629,14 +629,63 @@ 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 + + if (this._rotate === 'right') { + let j = offset; + for (let yv = 0; yv < height; yv++) { + for (let xv = 0; xv < width; xv++) { + let doff = ((xv * height) + (width - yv - 1)) * 4; + data[doff] = arr[j]; + data[doff + 1] = arr[j + 1]; + data[doff + 2] = arr[j + 2]; + data[doff + 3] = 255; // Alpha + j += 3; + } + } + } else if (this._rotate === 'left') { + let j = offset; + for (let yv = height - 1; yv >= 0; yv--) { + for (let xv = width - 1; xv >= 0; xv--) { + let doff = ((xv * height) + (width - yv - 1)) * 4; //((height - xv - 1) + (width * yv)) * 4; + data[doff] = arr[j]; + data[doff + 1] = arr[j + 1]; + data[doff + 2] = arr[j + 2]; + data[doff + 3] = 255; // Alpha + j += 3; + } + } + } else if (this._rotate === 'double') { + let length = width * height * 4; + for (let i = 4, j = offset; i <= length; i += 4, j += 3) { + data[length - i] = arr[j]; + data[length - i + 1] = arr[j + 1]; + data[length - i + 2] = arr[j + 2]; + data[length - i + 3] = 255; // Alpha + } + } else { + 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); + let x0 = x; + let y0 = y; + if (this._rotate === 'right') { + let a = x0; + x0 = this._fb_width - y0 - 1 - height; + y0 = a; + } else if (this._rotate === 'left') { + let a = y0; + y0 = this._fb_height - x0 - 1 - width; + x0 = a; + } else if (this._rotate === 'double') { + y0 = this._fb_height - y0 - 1 - height; + x0 = this._fb_width - x0 - 1 - width; + } + this._drawCtx.putImageData(img, x0, y0); + this._damage(x0, y0, img.width, img.height); } _bgrxImageData(x, y, width, height, arr, offset) { @@ -644,11 +693,11 @@ export default class Display { const data = img.data; if (this._rotate === 'right') { - var j = offset; - for (var yv = 0; yv < height; yv++) { - for (var xv = 0; xv < width; xv++) { - var doff = ((xv * height) + (width - yv - 1)) * 4; - data[doff] = arr[j + 2]; + let j = offset; + for (let yv = 0; yv < height; yv++) { + for (let xv = 0; xv < width; xv++) { + let doff = ((xv * height) + (width - yv - 1)) * 4; + data[doff] = arr[j + 2]; data[doff + 1] = arr[j + 1]; data[doff + 2] = arr[j]; data[doff + 3] = 255; // Alpha @@ -656,11 +705,11 @@ export default class Display { } } } else if (this._rotate === 'left') { - var j = offset; - for (var yv = height - 1; yv >= 0; yv--) { - for (var xv = width - 1; xv >= 0; xv--) { - var doff = ((xv * height) + (width - yv - 1)) * 4; //((height - xv - 1) + (width * yv)) * 4; - data[doff] = arr[j + 2]; + let j = offset; + for (let yv = height - 1; yv >= 0; yv--) { + for (let xv = width - 1; xv >= 0; xv--) { + let doff = ((xv * height) + (width - yv - 1)) * 4; //((height - xv - 1) + (width * yv)) * 4; + data[doff] = arr[j + 2]; data[doff + 1] = arr[j + 1]; data[doff + 2] = arr[j]; data[doff + 3] = 255; // Alpha @@ -668,29 +717,29 @@ export default class Display { } } } else if (this._rotate === 'double') { - var length = width * height * 4; - for (var i = 4, j = offset; i <= length; i += 4, j += 4) { - data[length - i] = arr[j + 2]; + let length = width * height * 4; + for (let i = 4, j = offset; i <= length; i += 4, j += 4) { + data[length - i] = arr[j + 2]; data[length - i + 1] = arr[j + 1]; data[length - i + 2] = arr[j]; data[length - i + 3] = 255; // Alpha } } else { - for (var i = 0, j = offset; i < width * height * 4; i += 4, j += 4) { - data[i] = arr[j + 2]; + for (let i = 0, j = offset; i < width * height * 4; i += 4, j += 4) { + data[i] = arr[j + 2]; data[i + 1] = arr[j + 1]; data[i + 2] = arr[j]; data[i + 3] = 255; // Alpha } } - var x0 = x; - var y0 = y; + let x0 = x; + let y0 = y; if (this._rotate === 'right') { - var a = x0; + let a = x0; x0 = this._fb_width - y0 - 1 - height; y0 = a; } else if (this._rotate === 'left') { - var a = y0; + let a = y0; y0 = this._fb_height - x0 - 1 - width; x0 = a; } else if (this._rotate === 'double') { diff --git a/package.json b/package.json index 07cda8f2..dc1282e7 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@gbrehmer/novnc", - "version": "1.1.0-patch14", + "version": "1.1.0-patch15", "description": "An HTML5 VNC client", "browser": "lib/rfb", "directories": {