From: Constantin Kaplinsky Date: Wed, 3 Sep 2008 03:12:18 +0000 (+0000) Subject: [Bugfix] Make sure the video selection is always a multiple of 16x8 pixels. Previousl... X-Git-Tag: v0.0.90~395 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=10da44dee7982dd14b1ccecd9af6f100123cd272;p=tigervnc.git [Bugfix] Make sure the video selection is always a multiple of 16x8 pixels. Previously, the selection could cross the framebuffer boundaries and clipping it back to screen could break 16x8 alignment. git-svn-id: svn://svn.code.sf.net/p/tigervnc/code/trunk@2746 3789f03b-4d11-0410-bbf8-ca57d06f2519 --- diff --git a/java/src/com/tightvnc/vncviewer/VncCanvas.java b/java/src/com/tightvnc/vncviewer/VncCanvas.java index 332efa38..5422137b 100644 --- a/java/src/com/tightvnc/vncviewer/VncCanvas.java +++ b/java/src/com/tightvnc/vncviewer/VncCanvas.java @@ -2015,9 +2015,18 @@ class VncCanvas extends Canvas w = (w * 100 + scalingFactor/2) / scalingFactor; h = (h * 100 + scalingFactor/2) / scalingFactor; } + // Clip the selection to framebuffer. + if (x < 0) + x = 0; + if (y < 0) + y = 0; + if (x + w > rfb.framebufferWidth) + w = rfb.framebufferWidth - x; + if (y + h > rfb.framebufferHeight) + h = rfb.framebufferHeight - y; // Make width a multiple of 16. int widthCorrection = w % 16; - if (widthCorrection >= 8) { + if (widthCorrection >= 8 && x + (w / 16 + 1) * 16 <= rfb.framebufferWidth) { widthCorrection -= 16; } w -= widthCorrection; @@ -2026,7 +2035,7 @@ class VncCanvas extends Canvas } // Make height a multiple of 8. int heightCorrection = h % 8; - if (heightCorrection >= 4) { + if (heightCorrection >= 4 && y + (h / 8 + 1) * 8 <= rfb.framebufferHeight) { heightCorrection -= 8; } h -= heightCorrection; @@ -2034,20 +2043,14 @@ class VncCanvas extends Canvas y += heightCorrection; } // Translate the selection back to screen coordinates if requested. - int clipWidth = rfb.framebufferWidth; - int clipHeight = rfb.framebufferHeight; if (useScreenCoords && rfb.framebufferWidth != scaledWidth) { x = (x * scalingFactor + 50) / 100; y = (y * scalingFactor + 50) / 100; w = (w * scalingFactor + 50) / 100; h = (h * scalingFactor + 50) / 100; - clipWidth = scaledWidth; - clipHeight = scaledHeight; } // Clip the selection to screen/framebuffer and return the result. - Rectangle selection = new Rectangle(x, y, w, h); - Rectangle clip = new Rectangle(0, 0, clipWidth, clipHeight); - return selection.intersection(clip); + return new Rectangle(x, y, w, h); } /**