GUAC-240: Add support for "img" instruction.

This commit is contained in:
Michael Jumper
2015-08-11 16:24:54 -07:00
parent 886c2f3a50
commit d393a833f4
2 changed files with 56 additions and 0 deletions

View File

@@ -886,6 +886,27 @@ Guacamole.Client = function(tunnel) {
}, },
"img": function(parameters) {
var stream_index = parseInt(parameters[0]);
var channelMask = parseInt(parameters[1]);
var layer = getLayer(parseInt(parameters[2]));
var mimetype = parameters[3];
var x = parseInt(parameters[4]);
var y = parseInt(parameters[5]);
// Create stream
var stream = streams[stream_index] = new Guacamole.InputStream(guac_client, stream_index);
var reader = new Guacamole.BlobReader(stream, mimetype);
// Draw blob when stream is complete
reader.onend = function drawImageBlob() {
display.setChannelMask(layer, channelMask);
display.drawBlob(layer, x, y, reader.getBlob());
};
},
"jpeg": function(parameters) { "jpeg": function(parameters) {
var channelMask = parseInt(parameters[0]); var channelMask = parseInt(parameters[0]);

View File

@@ -527,6 +527,41 @@ Guacamole.Display = function() {
}); });
}; };
/**
* Draws the image contained within the specified Blob at the given
* coordinates. The Blob specified must already be populated with image
* data.
*
* @param {Guacamole.Layer} layer
* The layer to draw upon.
*
* @param {Number} x
* The destination X coordinate.
*
* @param {Number} y
* The destination Y coordinate.
*
* @param {Blob} blob
* The Blob containing the image data to draw.
*/
this.drawBlob = function(layer, x, y, blob) {
// Create URL for blob
var url = URL.createObjectURL(blob);
// Draw and free blob URL when ready
var task = scheduleTask(function __display_drawBlob() {
layer.drawImage(x, y, image);
URL.revokeObjectURL(url);
}, true);
// Load image from URL
var image = new Image();
image.onload = task.unblock;
image.src = url;
};
/** /**
* Draws the image at the specified URL at the given coordinates. The image * Draws the image at the specified URL at the given coordinates. The image
* will be loaded automatically, and this and any future operations will * will be loaded automatically, and this and any future operations will