From d393a833f4ed1f4d506ace8a5316c2f68304602e Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Tue, 11 Aug 2015 16:24:54 -0700 Subject: [PATCH] GUAC-240: Add support for "img" instruction. --- .../src/main/webapp/modules/Client.js | 21 +++++++++++ .../src/main/webapp/modules/Display.js | 35 +++++++++++++++++++ 2 files changed, 56 insertions(+) diff --git a/guacamole-common-js/src/main/webapp/modules/Client.js b/guacamole-common-js/src/main/webapp/modules/Client.js index 75e1684b4..799f9650f 100644 --- a/guacamole-common-js/src/main/webapp/modules/Client.js +++ b/guacamole-common-js/src/main/webapp/modules/Client.js @@ -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) { var channelMask = parseInt(parameters[0]); diff --git a/guacamole-common-js/src/main/webapp/modules/Display.js b/guacamole-common-js/src/main/webapp/modules/Display.js index e5fb74610..ab286792f 100644 --- a/guacamole-common-js/src/main/webapp/modules/Display.js +++ b/guacamole-common-js/src/main/webapp/modules/Display.js @@ -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 * will be loaded automatically, and this and any future operations will