From bc28395abfea8a6a183b2ac500fd3e352f8aec3c Mon Sep 17 00:00:00 2001 From: Joel Martin Date: Thu, 10 May 2012 18:13:07 -0500 Subject: [PATCH] Add/use display.drawImage which is viewport relative. Fixes https://github.com/kanaka/noVNC/issues/163 When using an encoding with raw images (tight, tightPNG) we need to draw those image relative to the viewport so that clipping works when the viewport isn't at 0, 0. --- include/display.js | 6 ++++++ include/rfb.js | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/include/display.js b/include/display.js index f2ecdba3..1fe883cc 100644 --- a/include/display.js +++ b/include/display.js @@ -577,6 +577,12 @@ that.blitStringImage = function(str, x, y) { img.src = str; }; +// Wrap ctx.drawImage but relative to viewport +that.drawImage = function(img, x, y) { + c_ctx.drawImage(img, x - viewport.x, y - viewport.y); +}; + + that.changeCursor = function(pixels, mask, hotx, hoty, w, h) { if (conf.cursor_uri === false) { Util.Warn("changeCursor called but no cursor data URI support"); diff --git a/include/rfb.js b/include/rfb.js index 75a19e0c..91e68081 100644 --- a/include/rfb.js +++ b/include/rfb.js @@ -1562,7 +1562,7 @@ scan_tight_imgQ = function() { } else if (data.type === 'rgb') { display.blitRgbImage(data.x, data.y, data.width, data.height, data.img.data, 0); } else { - ctx.drawImage(data.img, data.x, data.y); + display.drawImage(data.img, data.x, data.y); } } setTimeout(scan_tight_imgQ, scan_imgQ_rate);