diff --git a/protocols/vnc/include/vnc_handlers.h b/protocols/vnc/include/vnc_handlers.h index c325e5ab..92730db3 100644 --- a/protocols/vnc/include/vnc_handlers.h +++ b/protocols/vnc/include/vnc_handlers.h @@ -48,6 +48,7 @@ rfbBool guac_vnc_malloc_framebuffer(rfbClient* rfb_client); void guac_vnc_cut_text(rfbClient* client, const char* text, int textlen); void guac_vnc_client_log_info(const char* format, ...); void guac_vnc_client_log_error(const char* format, ...); +void guac_vnc_set_pixel_format(rfbClient* client, int color_depth); #endif diff --git a/protocols/vnc/src/client.c b/protocols/vnc/src/client.c index 8d35e01e..eb12ee3d 100644 --- a/protocols/vnc/src/client.c +++ b/protocols/vnc/src/client.c @@ -56,6 +56,7 @@ const char* GUAC_CLIENT_ARGS[] = { "encodings", "password", "swap-red-blue", + "color-depth", NULL }; @@ -75,7 +76,7 @@ int guac_client_init(guac_client* client, int argc, char** argv) { /*** PARSE ARGUMENTS ***/ - if (argc < 6) { + if (argc < 7) { guac_protocol_send_error(client->socket, "Wrong argument count received."); guac_socket_flush(client->socket); return 1; @@ -117,6 +118,9 @@ int guac_client_init(guac_client* client, int argc, char** argv) { /* Password */ rfb_client->GetPassword = guac_vnc_get_password; + + /* Depth */ + guac_vnc_set_pixel_format(rfb_client, atoi(argv[6])); /* Hook into allocation so we can handle resize. */ guac_client_data->rfb_MallocFrameBuffer = rfb_client->MallocFrameBuffer; diff --git a/protocols/vnc/src/vnc_handlers.c b/protocols/vnc/src/vnc_handlers.c index 5cd1d03c..f03e8b0c 100644 --- a/protocols/vnc/src/vnc_handlers.c +++ b/protocols/vnc/src/vnc_handlers.c @@ -251,6 +251,44 @@ char* guac_vnc_get_password(rfbClient* client) { return ((vnc_guac_client_data*) gc->data)->password; } +void guac_vnc_set_pixel_format(rfbClient* client, int color_depth) { + switch(color_depth) { + case 8: + client->format.depth = 8; + client->format.bitsPerPixel = 8; + client->format.blueShift = 6; + client->format.redShift = 0; + client->format.greenShift = 3; + client->format.blueMax = 3; + client->format.redMax = 7; + client->format.greenMax = 7; + break; + + case 16: + client->format.depth = 16; + client->format.bitsPerPixel = 16; + client->format.blueShift = 0; + client->format.redShift = 11; + client->format.greenShift = 5; + client->format.blueMax = 0x1f; + client->format.redMax = 0x1f; + client->format.greenMax = 0x3f; + break; + + case 24: + case 32: + default: + client->format.depth = 24; + client->format.bitsPerPixel = 32; + client->format.blueShift = 0; + client->format.redShift = 16; + client->format.greenShift = 8; + client->format.blueMax = 0xff; + client->format.redMax = 0xff; + client->format.greenMax = 0xff; + } +} + rfbBool guac_vnc_malloc_framebuffer(rfbClient* rfb_client) { guac_client* gc = rfbClientGetClientData(rfb_client, __GUAC_CLIENT);