+ * Transfer a rectangle of image data from one Layer to this Layer using the
+ * specified transfer function.
+ *
+ * @param {Guacamole.Layer} srcLayer The Layer to copy image data from.
+ * @param {Number} srcx The X coordinate of the upper-left corner of the
+ * rectangle within the source Layer's coordinate
+ * space to copy data from.
+ * @param {Number} srcy The Y coordinate of the upper-left corner of the
+ * rectangle within the source Layer's coordinate
+ * space to copy data from.
+ * @param {Number} srcw The width of the rectangle within the source Layer's
+ * coordinate space to copy data from.
+ * @param {Number} srch The height of the rectangle within the source
+ * Layer's coordinate space to copy data from.
+ * @param {Number} x The destination X coordinate.
+ * @param {Number} y The destination Y coordinate.
+ * @param {Function} transferFunction The transfer function to use to
+ * transfer data from source to
+ * destination.
+ */
+ this.transfer = function(srcLayer, srcx, srcy, srcw, srch, x, y, transferFunction) {
+
+ var drawComplete = false;
+ var srcLock = null;
+
+ function doTransfer() {
+ if (layer.autosize != 0) fitRect(x, y, srcw, srch);
+
+ var srcCanvas = srcLayer.getCanvas();
+ if (srcCanvas.width != 0 && srcCanvas.height != 0) {
+
+ // Get image data from src and dst
+ var src = srcLayer.getCanvas().getContext("2d").getImageData(srcx, srcy, srcw, srch);
+ var dst = displayContext.getImageData(x , y, srcw, srch);
+
+ // Apply transfer for each pixel
+ for (var i=0; i<srcw*srch*4; i+=4) {
+ dst.data[i ] = transferFunction(src.data[i ], dst.data[i ]);
+ dst.data[i+1] = transferFunction(src.data[i+1], dst.data[i+1]);
+ dst.data[i+2] = transferFunction(src.data[i+2], dst.data[i+2]);
+ dst.data[i+3] = 0xFF; // Assume output opaque
+ }
+
+ }
+
+ // Unblock the source layer now that draw is complete
+ if (srcLock != null)
+ srcLock.unblock();
+
+ // Flag operation as done
+ drawComplete = true;
+ }
+
+ // If we ARE the source layer, no need to sync.
+ // Syncing would result in deadlock.
+ if (layer === srcLayer)
+ scheduleTask(doTransfer);
+
+ // Otherwise synchronize copy operation with source layer
+ else {
+
+ // Currently blocked draw task
+ var task = scheduleTask(doTransfer, true);
+
+ // Unblock draw task once source layer is ready
+ srcLayer.sync(task.unblock);
+
+ // Block source layer until draw completes
+ // Note that the draw MAY have already been performed at this point,
+ // in which case creating a lock on the source layer will lead to
+ // deadlock (the draw task has already run and will thus never
+ // clear the lock)
+ if (!drawComplete)
+ srcLock = srcLayer.sync(null, true);
+
+ }
+
+ };
+
+ /**