Add other raster operations (all having only src and dst).
[libguac-client-rdp.git] / src / rdp_gdi.c
index 7e17099..46ac9f3 100644 (file)
@@ -20,6 +20,7 @@
  * the Initial Developer. All Rights Reserved.
  *
  * Contributor(s):
+ * Matt Hortman
  *
  * Alternatively, the contents of this file may be used under the terms of
  * either the GNU General Public License Version 2 or later (the "GPL"), or
 #include "client.h"
 #include "rdp_bitmap.h"
 
-guac_composite_mode guac_rdp_rop3_composite_mode(guac_client* client,
+guac_transfer_function guac_rdp_rop3_transfer_function(guac_client* client,
         int rop3) {
 
     /* Translate supported ROP3 opcodes into composite modes */
     switch (rop3) {
 
+        /* "DSon" !(src | dest) */
+        case 0x11: return GUAC_TRANSFER_BINARY_NOR;
+
+        /* "DSna" !src & dest */
+        case 0x22: return GUAC_TRANSFER_BINARY_NSRC_AND;
+
+        /* "Sn" !src */
+        case 0x33: return GUAC_TRANSFER_BINARY_NSRC;
+
+        /* "SDna" (src & !dest) */
+        case 0x44: return GUAC_TRANSFER_BINARY_NDEST_AND;
+
+        /* "Dn" !dest */
+        case 0x55: return GUAC_TRANSFER_BINARY_NDEST;
+
         /* "SRCINVERT" (src ^ dest) */
-        case 0x66: return GUAC_COMP_BINARY_XOR;
+        case 0x66: return GUAC_TRANSFER_BINARY_XOR;
+
+        /* "DSan" !(src & dest) */
+        case 0x77: return GUAC_TRANSFER_BINARY_NAND;
 
         /* "SRCAND" (src & dest) */
-        case 0x88: return GUAC_COMP_BINARY_AND;
+        case 0x88: return GUAC_TRANSFER_BINARY_AND;
 
-        /* "MERGEPAINT" !(src | dest)*/
-        case 0xBB: return GUAC_COMP_BINARY_NOR;
+        /* "DSxn" !(src ^ dest) */
+        case 0x99: return GUAC_TRANSFER_BINARY_XNOR;
+
+        /* "MERGEPAINT" (!src | dest)*/
+        case 0xBB: return GUAC_TRANSFER_BINARY_NSRC_OR;
 
         /* "SRCCOPY" (src) */
-        case 0xCC: return GUAC_COMP_OVER;
+        case 0xCC: return GUAC_TRANSFER_BINARY_SRC;
+
+        /* "SDno" (src | !dest) */
+        case 0xDD: return GUAC_TRANSFER_BINARY_NDEST_OR;
 
         /* "SRCPAINT" (src | dest) */
-        case 0xEE: return GUAC_COMP_BINARY_OR;
+        case 0xEE: return GUAC_TRANSFER_BINARY_OR;
+
+        /* 0x00 = "BLACKNESS" (0) */
+        /* 0xAA = "NOP" (dest) */
+        /* 0xFF = "WHITENESS" (1) */
 
     }
 
     /* Log warning if ROP3 opcode not supported */
-    guac_client_log_info (client, "guac_rdp_rop3_composite_mode: UNSUPPORTED opcode = 0x%02X", rop3);
-    return GUAC_COMP_OVER;
+    guac_client_log_info (client, "guac_rdp_rop3_transfer_function: "
+            "UNSUPPORTED opcode = 0x%02X", rop3);
+
+    /* Default to BINARY_SRC */
+    return GUAC_TRANSFER_BINARY_SRC;
 
 }
 
@@ -126,12 +158,27 @@ void guac_rdp_gdi_memblt(rdpContext* context, MEMBLT_ORDER* memblt) {
     guac_socket* socket = client->socket;
     guac_rdp_bitmap* bitmap = (guac_rdp_bitmap*) memblt->bitmap;
 
-    if (bitmap->layer != NULL)
-        guac_protocol_send_copy(socket,
-                bitmap->layer,
-                memblt->nXSrc, memblt->nYSrc, memblt->nWidth, memblt->nHeight,
-                guac_rdp_rop3_composite_mode(client, memblt->bRop),
-                current_layer, memblt->nLeftRect, memblt->nTopRect);
+    if (bitmap->layer != NULL) {
+
+        /* If operation is just SRC, simply copy */
+        if (memblt->bRop == 0xCC)
+            guac_protocol_send_copy(socket,
+                    bitmap->layer,
+                    memblt->nXSrc, memblt->nYSrc,
+                    memblt->nWidth, memblt->nHeight,
+                    GUAC_COMP_OVER,
+                    current_layer, memblt->nLeftRect, memblt->nTopRect);
+
+        /* Otherwise, use transfer */
+        else
+            guac_protocol_send_transfer(socket,
+                    bitmap->layer,
+                    memblt->nXSrc, memblt->nYSrc,
+                    memblt->nWidth, memblt->nHeight,
+                    guac_rdp_rop3_transfer_function(client, memblt->bRop),
+                    current_layer, memblt->nLeftRect, memblt->nTopRect);
+
+    }
 
 }