mirror of
https://github.com/gyurix1968/guacamole-client.git
synced 2025-09-06 21:27:40 +00:00
#320: Ensure source rectangle of transfer and copy is clipped to source canvas bounds.
This commit is contained in:
@@ -555,50 +555,60 @@ 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() {
|
||||||
|
|
||||||
|
var srcCanvas = srcLayer.getCanvas();
|
||||||
|
|
||||||
|
// 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);
|
if (layer.autosize != 0) fitRect(x, y, srcw, srch);
|
||||||
|
|
||||||
var srcCanvas = srcLayer.getCanvas();
|
// Get image data from src and dst
|
||||||
if (srcCanvas.width != 0 && srcCanvas.height != 0) {
|
var src = srcLayer.getCanvas().getContext("2d").getImageData(srcx, srcy, srcw, srch);
|
||||||
|
var dst = displayContext.getImageData(x , y, srcw, srch);
|
||||||
|
|
||||||
// Get image data from src and dst
|
// Apply transfer for each pixel
|
||||||
var src = srcLayer.getCanvas().getContext("2d").getImageData(srcx, srcy, srcw, srch);
|
for (var i=0; i<srcw*srch*4; i+=4) {
|
||||||
var dst = displayContext.getImageData(x , y, srcw, srch);
|
|
||||||
|
|
||||||
// Apply transfer for each pixel
|
// Get source pixel environment
|
||||||
for (var i=0; i<srcw*srch*4; i+=4) {
|
var src_pixel = new Guacamole.Layer.Pixel(
|
||||||
|
src.data[i],
|
||||||
|
src.data[i+1],
|
||||||
|
src.data[i+2],
|
||||||
|
src.data[i+3]
|
||||||
|
);
|
||||||
|
|
||||||
|
// Get destination pixel environment
|
||||||
|
var dst_pixel = new Guacamole.Layer.Pixel(
|
||||||
|
dst.data[i],
|
||||||
|
dst.data[i+1],
|
||||||
|
dst.data[i+2],
|
||||||
|
dst.data[i+3]
|
||||||
|
);
|
||||||
|
|
||||||
// Get source pixel environment
|
// Apply transfer function
|
||||||
var src_pixel = new Guacamole.Layer.Pixel(
|
transferFunction(src_pixel, dst_pixel);
|
||||||
src.data[i],
|
|
||||||
src.data[i+1],
|
|
||||||
src.data[i+2],
|
|
||||||
src.data[i+3]
|
|
||||||
);
|
|
||||||
|
|
||||||
// Get destination pixel environment
|
|
||||||
var dst_pixel = new Guacamole.Layer.Pixel(
|
|
||||||
dst.data[i],
|
|
||||||
dst.data[i+1],
|
|
||||||
dst.data[i+2],
|
|
||||||
dst.data[i+3]
|
|
||||||
);
|
|
||||||
|
|
||||||
// Apply transfer function
|
// Save pixel data
|
||||||
transferFunction(src_pixel, dst_pixel);
|
dst.data[i ] = dst_pixel.red;
|
||||||
|
dst.data[i+1] = dst_pixel.green;
|
||||||
// Save pixel data
|
dst.data[i+2] = dst_pixel.blue;
|
||||||
dst.data[i ] = dst_pixel.red;
|
dst.data[i+3] = dst_pixel.alpha;
|
||||||
dst.data[i+1] = dst_pixel.green;
|
|
||||||
dst.data[i+2] = dst_pixel.blue;
|
|
||||||
dst.data[i+3] = dst_pixel.alpha;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
// Draw image data
|
|
||||||
displayContext.putImageData(dst, x, y);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Draw image data
|
||||||
|
displayContext.putImageData(dst, x, y);
|
||||||
|
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -625,11 +635,24 @@ 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)
|
|
||||||
displayContext.drawImage(srcCanvas, srcx, srcy, srcw, srch, x, y, srcw, srch);
|
// 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);
|
||||||
|
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
Reference in New Issue
Block a user