#320: Ensure source rectangle of transfer and copy is clipped to source canvas bounds.

This commit is contained in:
Michael Jumper
2013-05-12 22:31:00 -07:00
parent a75b651422
commit c874fb7817

View File

@@ -555,10 +555,22 @@ Guacamole.Layer = function(width, height) {
this.transfer = function(srcLayer, srcx, srcy, srcw, srch, x, y, transferFunction) {
scheduleTaskSynced(srcLayer, function() {
if (layer.autosize != 0) fitRect(x, y, srcw, srch);
var srcCanvas = srcLayer.getCanvas();
if (srcCanvas.width != 0 && srcCanvas.height != 0) {
// If entire rectangle outside source canvas, stop
if (srcx >= srcCanvas.width || srcy >= srcCanvas.height) return;
// Otherwise, clip rectangle to area
if (srcx + srcw > srcCanvas.width)
srcw = srcCanvas.width - srcx;
if (srcy + srch > srcCanvas.height)
srch = srcCanvas.height - srcy;
// Stop if nothing to draw.
if (srcw == 0 || srch == 0) return;
if (layer.autosize != 0) fitRect(x, y, srcw, srch);
// Get image data from src and dst
var src = srcLayer.getCanvas().getContext("2d").getImageData(srcx, srcy, srcw, srch);
@@ -597,8 +609,6 @@ Guacamole.Layer = function(width, height) {
// Draw image data
displayContext.putImageData(dst, x, y);
}
});
};
@@ -625,10 +635,23 @@ Guacamole.Layer = function(width, height) {
*/
this.copy = function(srcLayer, srcx, srcy, srcw, srch, x, y) {
scheduleTaskSynced(srcLayer, function() {
if (layer.autosize != 0) fitRect(x, y, srcw, srch);
var srcCanvas = srcLayer.getCanvas();
if (srcCanvas.width != 0 && srcCanvas.height != 0)
// If entire rectangle outside source canvas, stop
if (srcx >= srcCanvas.width || srcy >= srcCanvas.height) return;
// Otherwise, clip rectangle to area
if (srcx + srcw > srcCanvas.width)
srcw = srcCanvas.width - srcx;
if (srcy + srch > srcCanvas.height)
srch = srcCanvas.height - srcy;
// Stop if nothing to draw.
if (srcw == 0 || srch == 0) return;
if (layer.autosize != 0) fitRect(x, y, srcw, srch);
displayContext.drawImage(srcCanvas, srcx, srcy, srcw, srch, x, y, srcw, srch);
});