mirror of
https://github.com/gyurix1968/guacamole-client.git
synced 2025-09-07 13:41:21 +00:00
#320: Ensure source rectangle of transfer and copy is clipped to source canvas bounds.
This commit is contained in:
@@ -555,10 +555,22 @@ Guacamole.Layer = function(width, height) {
|
|||||||
this.transfer = function(srcLayer, srcx, srcy, srcw, srch, x, y, transferFunction) {
|
this.transfer = function(srcLayer, srcx, srcy, srcw, srch, x, y, transferFunction) {
|
||||||
scheduleTaskSynced(srcLayer, function() {
|
scheduleTaskSynced(srcLayer, function() {
|
||||||
|
|
||||||
if (layer.autosize != 0) fitRect(x, y, srcw, srch);
|
|
||||||
|
|
||||||
var srcCanvas = srcLayer.getCanvas();
|
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
|
// Get image data from src and dst
|
||||||
var src = srcLayer.getCanvas().getContext("2d").getImageData(srcx, srcy, srcw, srch);
|
var src = srcLayer.getCanvas().getContext("2d").getImageData(srcx, srcy, srcw, srch);
|
||||||
@@ -597,8 +609,6 @@ Guacamole.Layer = function(width, height) {
|
|||||||
// Draw image data
|
// Draw image data
|
||||||
displayContext.putImageData(dst, x, y);
|
displayContext.putImageData(dst, x, y);
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -625,10 +635,23 @@ Guacamole.Layer = function(width, height) {
|
|||||||
*/
|
*/
|
||||||
this.copy = function(srcLayer, srcx, srcy, srcw, srch, x, y) {
|
this.copy = function(srcLayer, srcx, srcy, srcw, srch, x, y) {
|
||||||
scheduleTaskSynced(srcLayer, function() {
|
scheduleTaskSynced(srcLayer, function() {
|
||||||
if (layer.autosize != 0) fitRect(x, y, srcw, srch);
|
|
||||||
|
|
||||||
var srcCanvas = srcLayer.getCanvas();
|
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);
|
displayContext.drawImage(srcCanvas, srcx, srcy, srcw, srch, x, y, srcw, srch);
|
||||||
|
|
||||||
});
|
});
|
||||||
|
Reference in New Issue
Block a user