From 5030b97d241b7e4f5f39c892366eb8d2d619d504 Mon Sep 17 00:00:00 2001 From: ArvidNorr Date: Fri, 23 May 2014 07:15:53 +0200 Subject: [PATCH 01/10] added support for optional background image --- xrdp/xrdp.ini | 3 +++ xrdp/xrdp_login_wnd.c | 23 ++++++++++++++++++++++- xrdp/xrdp_types.h | 1 + 3 files changed, 26 insertions(+), 1 deletion(-) diff --git a/xrdp/xrdp.ini b/xrdp/xrdp.ini index 12387ce3..1f11f8c3 100644 --- a/xrdp/xrdp.ini +++ b/xrdp/xrdp.ini @@ -68,6 +68,9 @@ ls_height=430 # login screen background color in RGB format ls_bg_color=dedede +# optional background image filename (bmp format). +#ls_background_image= + # logo # full path to bmp-file or file in shared folder ls_logo_filename= diff --git a/xrdp/xrdp_login_wnd.c b/xrdp/xrdp_login_wnd.c index 8b14cb26..f8896c4e 100644 --- a/xrdp/xrdp_login_wnd.c +++ b/xrdp/xrdp_login_wnd.c @@ -576,6 +576,23 @@ xrdp_login_wnd_create(struct xrdp_wm *self) if (regular) { + // Load the background image. + // If no file is specified no default image will be loaded. + // We only load the image if bpp > 8 + if (globals->ls_background_image[0] != 0 && self->screen->bpp > 8) + { + char fileName[256] ; + but = xrdp_bitmap_create(4, 4, self->screen->bpp, WND_TYPE_IMAGE, self); + g_snprintf(fileName, 255, "%s/%s", XRDP_SHARE_PATH, globals->ls_background_image); + log_message(LOG_LEVEL_DEBUG, "We try to load the following background file: %s", fileName); + xrdp_bitmap_load(but, fileName, self->palette); + but->parent = self->screen; + but->owner = self->screen; + but->left = self->screen->width - but->width; + but->top = self->screen->height - but->height; + list_add_item(self->screen->child_list, (long)but); + } + /* if logo image not specified, use default */ if (globals->ls_logo_filename[0] == 0) g_snprintf(globals->ls_logo_filename, 255, "%s/xrdp_logo.bmp", XRDP_SHARE_PATH); @@ -848,7 +865,11 @@ load_xrdp_config(struct xrdp_config *config, int bpp) g_strncpy(globals->ls_logo_filename, v, 255); globals->ls_logo_filename[255] = 0; } - + else if (g_strncmp(n, "ls_background_image", 255) == 0) + { + g_strncpy(globals->ls_background_image, v, 255); + globals->ls_background_image[255] = 0; + } else if (g_strncmp(n, "ls_logo_x_pos", 64) == 0) globals->ls_logo_x_pos = g_atoi(v); diff --git a/xrdp/xrdp_types.h b/xrdp/xrdp_types.h index 973b64e8..0e31dd59 100644 --- a/xrdp/xrdp_types.h +++ b/xrdp/xrdp_types.h @@ -580,6 +580,7 @@ struct xrdp_cfg_globals int ls_height; /* window height */ int ls_bg_color; /* background color */ char ls_logo_filename[256]; /* logo filename */ + char ls_background_image[256]; /* background image file name */ int ls_logo_x_pos; /* logo x co-ordinate */ int ls_logo_y_pos; /* logo y co-ordinate */ int ls_label_x_pos; /* x pos of labels */ From 17bbecabd36dce18936e3163cd402f8e800da745 Mon Sep 17 00:00:00 2001 From: Jay Sorg Date: Sat, 7 Jun 2014 20:15:14 -0700 Subject: [PATCH 02/10] chansrv: remove simple sound and load pulse modules --- configure.ac | 26 ------ sesman/chansrv/Makefile.am | 10 --- sesman/chansrv/sound.c | 167 +------------------------------------ sesman/chansrv/sound.h | 9 +- 4 files changed, 3 insertions(+), 209 deletions(-) diff --git a/configure.ac b/configure.ac index d11998f8..c3f95bf9 100644 --- a/configure.ac +++ b/configure.ac @@ -43,22 +43,10 @@ AC_ARG_ENABLE(tjpeg, AS_HELP_STRING([--enable-tjpeg], [Build turbo jpeg module (default: no)]), [tjpeg=true], [tjpeg=false]) AM_CONDITIONAL(XRDP_TJPEG, [test x$tjpeg = xtrue]) - -AC_ARG_ENABLE(simplesound, AS_HELP_STRING([--enable-simplesound], - [Build simple pulse audio interface (default: no)]), - [simplesound=true], [simplesound=false]) -AM_CONDITIONAL(XRDP_SIMPLESOUND, [test x$simplesound = xtrue]) - AC_ARG_ENABLE(fuse, AS_HELP_STRING([--enable-fuse], [Build fuse(clipboard file / drive redir) (default: no)]), [fuse=true], [fuse=false]) AM_CONDITIONAL(XRDP_FUSE, [test x$fuse = xtrue]) - -AC_ARG_ENABLE(loadpulsemodules, AS_HELP_STRING([--enable-loadpulsemodules], - [Build code to load pulse audio modules (default: no)]), - [loadpulsemodules=true], [loadpulsemodules=false]) -AM_CONDITIONAL(XRDP_LOAD_PULSE_MODULES, [test x$loadpulsemodules = xtrue]) - AC_ARG_ENABLE(xrdpvr, AS_HELP_STRING([--enable-xrdpvr], [Build xrdpvr module (default: no)]), [xrdpvr=true], [xrdpvr=false]) @@ -113,20 +101,6 @@ then [#define _FILE_OFFSET_BITS 64]) fi -# checking for libpulse -if ! test -z "$enable_loadpulsemodules" -then - AC_CHECK_HEADER([pulse/util.h], [], - [AC_MSG_ERROR([please install libpulse-dev or libpulse-devel])]) -fi - -# checking for libpulse libpulse-simple -if ! test -z "$enable_simplesound" -then - AC_CHECK_HEADER([pulse/simple.h], [], - [AC_MSG_ERROR([please install libpulse-dev or libpulse-devel])]) -fi - # checking for TurboJPEG if ! test -z "$enable_tjpeg" then diff --git a/sesman/chansrv/Makefile.am b/sesman/chansrv/Makefile.am index 9aa3ebe7..81218db1 100644 --- a/sesman/chansrv/Makefile.am +++ b/sesman/chansrv/Makefile.am @@ -16,21 +16,11 @@ EXTRA_INCLUDES = EXTRA_LIBS = EXTRA_FLAGS = -if XRDP_SIMPLESOUND -EXTRA_DEFINES += -DXRDP_SIMPLESOUND -EXTRA_LIBS += -lpthread -lpulse -lpulse-simple -endif - if XRDP_FUSE EXTRA_DEFINES += -DXRDP_FUSE EXTRA_LIBS += -lfuse endif -if XRDP_LOAD_PULSE_MODULES -EXTRA_DEFINES += -DXRDP_LOAD_PULSE_MODULES -EXTRA_LIBS += -lpulse -endif - AM_CFLAGS = \ -DXRDP_CFG_PATH=\"${sysconfdir}/xrdp\" \ -DXRDP_SBIN_PATH=\"${sbindir}\" \ diff --git a/sesman/chansrv/sound.c b/sesman/chansrv/sound.c index efb7ff85..59e89c3e 100644 --- a/sesman/chansrv/sound.c +++ b/sesman/chansrv/sound.c @@ -1,7 +1,7 @@ /** * xrdp: A Remote Desktop Protocol server. * - * Copyright (C) Jay Sorg 2009-2013 + * Copyright (C) Jay Sorg 2009-2014 * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -23,10 +23,6 @@ #include #include -#ifdef XRDP_LOAD_PULSE_MODULES -#include -#endif - #include "sound.h" #include "thread_calls.h" #include "defines.h" @@ -655,11 +651,6 @@ sound_init(void) g_memset(g_sent_flag, 0, sizeof(g_sent_flag)); -#ifdef XRDP_LOAD_PULSE_MODULES - if (load_pulse_modules()) - LOG(0, ("Audio and microphone redirection will not work!")); -#endif - /* init sound output */ sound_send_server_output_formats(); @@ -726,10 +717,6 @@ sound_deinit(void) fifo_deinit(&in_fifo); -#ifdef XRDP_LOAD_PULSE_MODULES - system("pulseaudio --kill"); -#endif - return 0; } @@ -841,158 +828,6 @@ sound_check_wait_objs(void) return 0; } -/** - * Load xrdp pulseaudio sink and source modules - * - * @return 0 on success, -1 on failure - *****************************************************************************/ - -#ifdef XRDP_LOAD_PULSE_MODULES - -static int APP_CC -load_pulse_modules() -{ - struct sockaddr_un sa; - - pid_t pid; - char* cli; - int fd; - int i; - int rv; - char buf[1024]; - - /* is pulse audio daemon running? */ - if (pa_pid_file_check_running(&pid, "pulseaudio") < 0) - { - LOG(0, ("load_pulse_modules: No PulseAudio daemon running, " - "or not running as session daemon")); - } - - /* get name of unix domain socket used by pulseaudio for CLI */ - if ((cli = (char *) pa_runtime_path("cli")) == NULL) - { - LOG(0, ("load_pulse_modules: Error getting PulesAudio runtime path")); - return -1; - } - - /* open a socket */ - if ((fd = socket(PF_LOCAL, SOCK_STREAM, 0)) < 0) - { - pa_xfree(cli); - LOG(0, ("load_pulse_modules: Socket open error")); - return -1; - } - - /* set it up */ - memset(&sa, 0, sizeof(struct sockaddr_un)); - sa.sun_family = AF_UNIX; - pa_strlcpy(sa.sun_path, cli, sizeof(sa.sun_path)); - pa_xfree(cli); - - for (i = 0; i < 20; i++) - { - if (pa_pid_file_kill(SIGUSR2, NULL, "pulseaudio") < 0) - LOG(0, ("load_pulse_modules: Failed to kill PulseAudio daemon")); - - if ((rv = connect(fd, (struct sockaddr*) &sa, sizeof(sa))) < 0 && - (errno != ECONNREFUSED && errno != ENOENT)) - { - LOG(0, ("load_pulse_modules: connect() failed with error: %s", - strerror(errno))); - return -1; - } - - if (rv >= 0) - break; - - pa_msleep(300); - } - - if (i >= 20) - { - LOG(0, ("load_pulse_modules: Daemon not responding")); - return -1; - } - - LOG(0, ("load_pulse_modules: connected to pulseaudio daemon")); - - /* read back PulseAudio sign on message */ - memset(buf, 0, 1024); - recv(fd, buf, 1024, 0); - - /* send cmd to load source module */ - memset(buf, 0, 1024); - sprintf(buf, "load-module module-xrdp-source\n"); - send(fd, buf, strlen(buf), 0); - - /* read back response */ - memset(buf, 0, 1024); - recv(fd, buf, 1024, 0); - if (strcasestr(buf, "Module load failed") != 0) - { - LOG(0, ("load_pulse_modules: Error loading module-xrdp-source")); - } - else - { - LOG(0, ("load_pulse_modules: Loaded module-xrdp-source")); - - /* success, set it as the default source */ - memset(buf, 0, 1024); - sprintf(buf, "set-default-source xrdp-source\n"); - send(fd, buf, strlen(buf), 0); - - memset(buf, 0, 1024); - recv(fd, buf, 1024, 0); - - if (strcasestr(buf, "does not exist") != 0) - { - LOG(0, ("load_pulse_modules: Error setting default source")); - } - else - { - LOG(0, ("load_pulse_modules: set default source")); - } - } - - /* send cmd to load sink module */ - memset(buf, 0, 1024); - sprintf(buf, "load-module module-xrdp-sink\n"); - send(fd, buf, strlen(buf), 0); - - /* read back response */ - memset(buf, 0, 1024); - recv(fd, buf, 1024, 0); - if (strcasestr(buf, "Module load failed") != 0) - { - LOG(0, ("load_pulse_modules: Error loading module-xrdp-sink")); - } - else - { - LOG(0, ("load_pulse_modules: Loaded module-xrdp-sink")); - - /* success, set it as the default sink */ - memset(buf, 0, 1024); - sprintf(buf, "set-default-sink xrdp-sink\n"); - send(fd, buf, strlen(buf), 0); - - memset(buf, 0, 1024); - recv(fd, buf, 1024, 0); - - if (strcasestr(buf, "does not exist") != 0) - { - LOG(0, ("load_pulse_modules: Error setting default sink")); - } - else - { - LOG(0, ("load_pulse_modules: set default sink")); - } - } - - close(fd); - return 0; -} -#endif - /****************************************************************************** ** ** ** Microphone releated code ** diff --git a/sesman/chansrv/sound.h b/sesman/chansrv/sound.h index c26d0913..b443f0e3 100644 --- a/sesman/chansrv/sound.h +++ b/sesman/chansrv/sound.h @@ -1,7 +1,7 @@ /** * xrdp: A Remote Desktop Protocol server. * - * Copyright (C) Jay Sorg 2009-2013 + * Copyright (C) Jay Sorg 2009-2014 * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -19,11 +19,6 @@ #ifndef _SOUND_H_ #define _SOUND_H_ -#if defined(XRDP_SIMPLESOUND) -#include -#include -#endif - #include "arch.h" #include "parse.h" #include "os_calls.h" @@ -75,5 +70,5 @@ static int APP_CC sound_input_start_recording(); static int APP_CC sound_input_stop_recording(); static int APP_CC sound_process_input_data(struct stream *s, int bytes); static int DEFAULT_CC sound_sndsrvr_source_data_in(struct trans *trans); -static int APP_CC load_pulse_modules(); + #endif From c8e61a80420101c5ae2f2e031cbab492f9de730a Mon Sep 17 00:00:00 2001 From: Jay Sorg Date: Sat, 7 Jun 2014 20:22:07 -0700 Subject: [PATCH 03/10] chansrv: more remove simple sound --- sesman/chansrv/sound.c | 140 ----------------------------------------- 1 file changed, 140 deletions(-) diff --git a/sesman/chansrv/sound.c b/sesman/chansrv/sound.c index 59e89c3e..d95d1afa 100644 --- a/sesman/chansrv/sound.c +++ b/sesman/chansrv/sound.c @@ -52,11 +52,6 @@ int g_buf_index = 0; int g_sent_time[256]; int g_sent_flag[256]; -#if defined(XRDP_SIMPLESOUND) -static void *DEFAULT_CC -read_raw_audio_data(void *arg); -#endif - #define CHANSRV_PORT_OUT_STR "/tmp/.xrdp/xrdp_chansrv_audio_out_socket_%d" #define CHANSRV_PORT_IN_STR "/tmp/.xrdp/xrdp_chansrv_audio_in_socket_%d" @@ -676,13 +671,6 @@ sound_init(void) /* save data from sound_server_source */ fifo_init(&in_fifo, 100); -#if defined(XRDP_SIMPLESOUND) - - /* start thread to read raw audio data from pulseaudio device */ - tc_thread_create(read_raw_audio_data, 0); - -#endif - return 0; } @@ -1161,131 +1149,3 @@ sound_sndsrvr_source_data_in(struct trans *trans) return 0; } - -/*****************************************************************************/ - -#if defined(XRDP_SIMPLESOUND) - -#define AUDIO_BUF_SIZE 2048 - -static int DEFAULT_CC -sttrans_data_in(struct trans *self) -{ - LOG(0, ("sttrans_data_in:\n")); - return 0; -} - -/** - * read raw audio data from pulseaudio device and write it - * to a unix domain socket on which trans server is listening - */ - -static void *DEFAULT_CC -read_raw_audio_data(void *arg) -{ - pa_sample_spec samp_spec; - pa_simple *simple = NULL; - uint32_t bytes_read; - char *cptr; - int i; - int error; - struct trans *strans; - char path[256]; - struct stream *outs; - - strans = trans_create(TRANS_MODE_UNIX, 8192, 8192); - - if (strans == 0) - { - LOG(0, ("read_raw_audio_data: trans_create failed\n")); - return 0; - } - - strans->trans_data_in = sttrans_data_in; - g_snprintf(path, 255, CHANSRV_PORT_OUT_STR, g_display_num); - - if (trans_connect(strans, "", path, 100) != 0) - { - LOG(0, ("read_raw_audio_data: trans_connect failed\n")); - trans_delete(strans); - return 0; - } - - /* setup audio format */ - samp_spec.format = PA_SAMPLE_S16LE; - samp_spec.rate = 44100; - samp_spec.channels = 2; - - /* if we are root, then for first 8 seconds connection to pulseaudo server - fails; if we are non-root, then connection succeeds on first attempt; - for now we have changed code to be non-root, but this may change in the - future - so pretend we are root and try connecting to pulseaudio server - for upto one minute */ - for (i = 0; i < 60; i++) - { - simple = pa_simple_new(NULL, "xrdp", PA_STREAM_RECORD, NULL, - "record", &samp_spec, NULL, NULL, &error); - - if (simple) - { - /* connected to pulseaudio server */ - LOG(0, ("read_raw_audio_data: connected to pulseaudio server\n")); - break; - } - - LOG(0, ("read_raw_audio_data: ERROR creating PulseAudio async interface\n")); - LOG(0, ("read_raw_audio_data: %s\n", pa_strerror(error))); - g_sleep(1000); - } - - if (i == 60) - { - /* failed to connect to audio server */ - trans_delete(strans); - return NULL; - } - - /* insert header just once */ - outs = trans_get_out_s(strans, 8192); - out_uint32_le(outs, 0); - out_uint32_le(outs, AUDIO_BUF_SIZE + 8); - cptr = outs->p; - out_uint8s(outs, AUDIO_BUF_SIZE); - s_mark_end(outs); - - while (1) - { - /* read a block of raw audio data... */ - g_memset(cptr, 0, 4); - bytes_read = pa_simple_read(simple, cptr, AUDIO_BUF_SIZE, &error); - - if (bytes_read < 0) - { - LOG(0, ("read_raw_audio_data: ERROR reading from pulseaudio stream\n")); - LOG(0, ("read_raw_audio_data: %s\n", pa_strerror(error))); - break; - } - - /* bug workaround: - even when there is no audio data, pulseaudio is returning without - errors but the data itself is zero; we use this zero data to - determine that there is no audio data present */ - if (*cptr == 0 && *(cptr + 1) == 0 && *(cptr + 2) == 0 && *(cptr + 3) == 0) - { - g_sleep(10); - continue; - } - - if (trans_force_write_s(strans, outs) != 0) - { - LOG(0, ("read_raw_audio_data: ERROR writing audio data to server\n")); - break; - } - } - - pa_simple_free(simple); - trans_delete(strans); - return NULL; -} - -#endif From 5d495539196d4c9645f50fbb8f685b33ea5c5820 Mon Sep 17 00:00:00 2001 From: Jay Sorg Date: Tue, 10 Jun 2014 16:25:54 -0700 Subject: [PATCH 04/10] work on 32 bit planar bitmap compressor --- libxrdp/xrdp_bitmap32_compress.c | 61 +++++++++++++++++++++++- xrdp/xrdp_bitmap.c | 79 ++++++++++++++++++++++++++++++-- 2 files changed, 134 insertions(+), 6 deletions(-) diff --git a/libxrdp/xrdp_bitmap32_compress.c b/libxrdp/xrdp_bitmap32_compress.c index b681d040..b1aaaa9a 100644 --- a/libxrdp/xrdp_bitmap32_compress.c +++ b/libxrdp/xrdp_bitmap32_compress.c @@ -19,14 +19,73 @@ * 32 bpp compression */ +/* +RDP 6.0 Bitmap Compression +http://msdn.microsoft.com/en-us/library/cc241877.aspx +*/ + #include "libxrdp.h" /*****************************************************************************/ +/* returns the number of lines compressed */ int APP_CC xrdp_bitmap32_compress(char *in_data, int width, int height, struct stream *s, int bpp, int byte_limit, int start_line, struct stream *temp_s, int e) { - return 0; + int pixel; + int *ptr32; + char *ptr8; + char *alpha_data; + char *red_data; + char *green_data; + char *blue_data; + int alpha_bytes; + int red_bytes; + int green_bytes; + int blue_bytes; + int iindex; + int jindex; + int cx; + int cy; + + alpha_data = g_malloc(width * height * 4, 0); + red_data = alpha_data + width * height; + green_data = red_data + width * height; + blue_data = green_data + width * height; + alpha_bytes = 0; + red_bytes = 0; + green_bytes = 0; + blue_bytes = 0; + cx = width; + cy = 0; + + /* split planes */ + while (start_line >= 0) + { + ptr32 = (int *) (in_data + start_line * width * 4); + for (iindex = 0; iindex < width; iindex++) + { + pixel = *ptr32; + ptr32++; + alpha_data[alpha_bytes] = pixel >> 24; + alpha_bytes++; + red_data[red_bytes] = pixel >> 16; + red_bytes++; + green_data[green_bytes] = pixel >> 8; + green_bytes++; + blue_data[blue_bytes] = pixel >> 0; + blue_bytes++; + } + start_line--; + cy++; + } + out_uint8(s, 0x20); /* no alpha */ + out_uint8a(s, red_data, red_bytes); + out_uint8a(s, green_data, green_bytes); + out_uint8a(s, blue_data, blue_bytes); + out_uint8(s, 0x00); + g_free(alpha_data); + return cy; } diff --git a/xrdp/xrdp_bitmap.c b/xrdp/xrdp_bitmap.c index 49750221..87fb0ebc 100644 --- a/xrdp/xrdp_bitmap.c +++ b/xrdp/xrdp_bitmap.c @@ -679,7 +679,7 @@ xrdp_bitmap_get_pixel(struct xrdp_bitmap *self, int x, int y) { return GETPIXEL16(self->data, x, y, self->width); } - else if (self->bpp == 24) + else if (self->bpp >= 24) { return GETPIXEL32(self->data, x, y, self->width); } @@ -712,7 +712,7 @@ xrdp_bitmap_set_pixel(struct xrdp_bitmap *self, int x, int y, int pixel) { SETPIXEL16(self->data, x, y, self->width, pixel); } - else if (self->bpp == 24) + else if (self->bpp >= 24) { SETPIXEL32(self->data, x, y, self->width, pixel); } @@ -779,7 +779,7 @@ xrdp_bitmap_copy_box(struct xrdp_bitmap *self, return 1; } - if (self->bpp == 24) + if (self->bpp >= 24) { s32 = ((tui32 *)(self->data)) + (self->width * y + x); d32 = ((tui32 *)(dest->data)) + (dest->width * desty + destx); @@ -849,7 +849,7 @@ xrdp_bitmap_hash_crc(struct xrdp_bitmap *self) int index; char hash_data[16]; - if (self->bpp == 24) + if (self->bpp >= 24) { bytes = self->width * self->height * 4; } @@ -953,7 +953,76 @@ xrdp_bitmap_copy_box_with_crc(struct xrdp_bitmap *self, CRC_PASS(self->height, crc); CRC_PASS(self->height >> 8, crc); - if (self->bpp == 24) + if (self->bpp == 32) + { + s32 = ((tui32 *)(self->data)) + (self->width * y + x); + d32 = ((tui32 *)(dest->data)) + (dest->width * desty + destx); + incs = self->width - cx; + incd = dest->width - cx; + + for (i = 0; i < cy; i++) + { + j = 0; + + while (j < cx - 4) + { + pixel = *s32; + *d32 = pixel; + CRC_PASS(pixel, crc); + CRC_PASS(pixel >> 8, crc); + CRC_PASS(pixel >> 16, crc); + CRC_PASS(pixel >> 24, crc); + s32++; + d32++; + + pixel = *s32; + *d32 = pixel; + CRC_PASS(pixel, crc); + CRC_PASS(pixel >> 8, crc); + CRC_PASS(pixel >> 16, crc); + CRC_PASS(pixel >> 24, crc); + s32++; + d32++; + + pixel = *s32; + *d32 = pixel; + CRC_PASS(pixel, crc); + CRC_PASS(pixel >> 8, crc); + CRC_PASS(pixel >> 16, crc); + CRC_PASS(pixel >> 24, crc); + s32++; + d32++; + + pixel = *s32; + *d32 = pixel; + CRC_PASS(pixel, crc); + CRC_PASS(pixel >> 8, crc); + CRC_PASS(pixel >> 16, crc); + CRC_PASS(pixel >> 24, crc); + s32++; + d32++; + + j += 4; + } + while (j < cx) + { + pixel = *s32; + *d32 = pixel; + CRC_PASS(pixel, crc); + CRC_PASS(pixel >> 8, crc); + CRC_PASS(pixel >> 16, crc); + CRC_PASS(pixel >> 24, crc); + s32++; + d32++; + + j += 1; + } + + s32 += incs; + d32 += incd; + } + } + else if (self->bpp == 24) { s32 = ((tui32 *)(self->data)) + (self->width * y + x); d32 = ((tui32 *)(dest->data)) + (dest->width * desty + destx); From d9b87e734b04dc860f46f2cfd6e9c34787e1c891 Mon Sep 17 00:00:00 2001 From: Jay Sorg Date: Tue, 10 Jun 2014 16:58:25 -0700 Subject: [PATCH 05/10] common: small fix for 32 bit color --- common/defines.h | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/common/defines.h b/common/defines.h index c6e85a08..d87ddae7 100644 --- a/common/defines.h +++ b/common/defines.h @@ -72,7 +72,7 @@ (bpp==8?COLOR8(HRED(c),HGREEN(c),HBLUE(c)): \ (bpp==15?COLOR15(HRED(c),HGREEN(c),HBLUE(c)): \ (bpp==16?COLOR16(HRED(c),HGREEN(c),HBLUE(c)): \ - (bpp==24?COLOR24BGR(HRED(c),HGREEN(c),HBLUE(c)):c) \ + (bpp>=24?COLOR24BGR(HRED(c),HGREEN(c),HBLUE(c)):c) \ ) \ ) \ ) \ @@ -101,4 +101,10 @@ /* use crc for bitmap cache lookups */ #define USE_CRC +#define XR_RGB2BGR(a_ulColor) \ + (a_ulColor & 0xFF000000) | \ + ((a_ulColor & 0x00FF0000) >> 16) | \ + (a_ulColor & 0x0000FF00) | \ + ((a_ulColor & 0x000000FF) << 16) + #endif From 73bdb57ee27221f8bcce35b895afdb0df9fbb801 Mon Sep 17 00:00:00 2001 From: Jay Sorg Date: Tue, 10 Jun 2014 17:49:15 -0700 Subject: [PATCH 06/10] more fixes for 32 bit color --- libxrdp/xrdp_bitmap32_compress.c | 34 ++++++++++++++++++++++++-------- xorg/X11R7.6/rdp/rdpup.c | 4 ++-- xup/xup.c | 6 +++--- 3 files changed, 31 insertions(+), 13 deletions(-) diff --git a/libxrdp/xrdp_bitmap32_compress.c b/libxrdp/xrdp_bitmap32_compress.c index b1aaaa9a..6af7ed75 100644 --- a/libxrdp/xrdp_bitmap32_compress.c +++ b/libxrdp/xrdp_bitmap32_compress.c @@ -49,17 +49,20 @@ xrdp_bitmap32_compress(char *in_data, int width, int height, int jindex; int cx; int cy; + int header; - alpha_data = g_malloc(width * height * 4, 0); - red_data = alpha_data + width * height; - green_data = red_data + width * height; - blue_data = green_data + width * height; + header = 0x20; /* no alpha TODO */ + + cx = width + e; + cy = 0; + alpha_data = g_malloc(cx * height * 4, 0); + red_data = alpha_data + cx * height; + green_data = red_data + cx * height; + blue_data = green_data + cx * height; alpha_bytes = 0; red_bytes = 0; green_bytes = 0; blue_bytes = 0; - cx = width; - cy = 0; /* split planes */ while (start_line >= 0) @@ -78,14 +81,29 @@ xrdp_bitmap32_compress(char *in_data, int width, int height, blue_data[blue_bytes] = pixel >> 0; blue_bytes++; } + for (iindex = 0; iindex < e; iindex++) + { + alpha_data[alpha_bytes] = 0; + alpha_bytes++; + red_data[red_bytes] = 0; + red_bytes++; + green_data[green_bytes] = 0; + green_bytes++; + blue_data[blue_bytes] = 0; + blue_bytes++; + } start_line--; cy++; } - out_uint8(s, 0x20); /* no alpha */ + out_uint8(s, header); out_uint8a(s, red_data, red_bytes); out_uint8a(s, green_data, green_bytes); out_uint8a(s, blue_data, blue_bytes); - out_uint8(s, 0x00); + if ((header & 0x10) == 0) + { + /* pad if no RLE */ + out_uint8(s, 0x00); + } g_free(alpha_data); return cy; } diff --git a/xorg/X11R7.6/rdp/rdpup.c b/xorg/X11R7.6/rdp/rdpup.c index 83525251..e7f504ec 100644 --- a/xorg/X11R7.6/rdp/rdpup.c +++ b/xorg/X11R7.6/rdp/rdpup.c @@ -1563,7 +1563,7 @@ convert_pixel(int in_pixel) if (g_rdpScreen.depth == 24) { - if (g_rdpScreen.rdp_bpp == 24) + if (g_rdpScreen.rdp_bpp >= 24) { rv = in_pixel; SPLITCOLOR32(red, green, blue, rv); @@ -1619,7 +1619,7 @@ convert_pixels(void *src, void *dst, int num_pixels) { src32 = (unsigned int *)src; - if (g_rdpScreen.rdp_bpp == 24) + if (g_rdpScreen.rdp_bpp >= 24) { dst32 = (unsigned int *)dst; diff --git a/xup/xup.c b/xup/xup.c index 95161f96..f1ddf4c2 100644 --- a/xup/xup.c +++ b/xup/xup.c @@ -178,11 +178,11 @@ lib_mod_connect(struct mod *mod) mod->server_msg(mod, "started connecting", 0); - /* only support 8, 15, 16, and 24 bpp connections from rdp client */ - if (mod->bpp != 8 && mod->bpp != 15 && mod->bpp != 16 && mod->bpp != 24) + /* only support 8, 15, 16, 24, and 32 bpp connections from rdp client */ + if (mod->bpp != 8 && mod->bpp != 15 && mod->bpp != 16 && mod->bpp != 24 && mod->bpp != 32) { mod->server_msg(mod, - "error - only supporting 8, 15, 16, and 24 bpp rdp connections", 0); + "error - only supporting 8, 15, 16, 24, and 32 bpp rdp connections", 0); LIB_DEBUG(mod, "out lib_mod_connect error"); return 1; } From e494f5367f5662940e13cecef9bea21a3850730e Mon Sep 17 00:00:00 2001 From: Jay Sorg Date: Sun, 15 Jun 2014 13:59:25 -0700 Subject: [PATCH 07/10] libxrdp: planar(32 bit) compression working now --- libxrdp/xrdp_bitmap32_compress.c | 222 +++++++++++++++++++++++++++++-- 1 file changed, 209 insertions(+), 13 deletions(-) diff --git a/libxrdp/xrdp_bitmap32_compress.c b/libxrdp/xrdp_bitmap32_compress.c index 6af7ed75..c3afff90 100644 --- a/libxrdp/xrdp_bitmap32_compress.c +++ b/libxrdp/xrdp_bitmap32_compress.c @@ -26,6 +26,173 @@ http://msdn.microsoft.com/en-us/library/cc241877.aspx #include "libxrdp.h" +#define FLAGS_RLE 0x10 +#define FLAGS_NOALPHA 0x20 + +#define LLOG_LEVEL 1 +#define LLOGLN(_level, _args) \ + do { if (_level < LLOG_LEVEL) { g_writeln _args ; } } while (0) +#define LHEXDUMP(_level, _args) \ + do { if (_level < LLOG_LEVEL) { g_hexdump _args ; } } while (0) + +/*****************************************************************************/ +static int APP_CC +fdelta(char *plane, int cx, int cy) +{ + char delta; + char *ptr8; + int index; + int jndex; + + for (jndex = cy - 2; jndex >= 0; jndex--) + { + ptr8 = plane + jndex * cx; + for (index = 0; index < cx; index++) + { + delta = ptr8[cx] - ptr8[0]; + if (delta & 0x80) + { + delta = (((~delta) + 1) << 1) - 1; + } + else + { + delta = delta << 1; + } + ptr8[cx] = delta; + ptr8++; + } + } + return 0; +} + +/*****************************************************************************/ +static int APP_CC +fout(int collen, int replen, char *colptr, struct stream *s) +{ + int code; + int lcollen; + int lreplen; + int cont; + + LLOGLN(10, ("fout: collen %d replen %d", collen, replen)); + cont = collen > 13; + while (cont) + { + lcollen = collen; + if (lcollen > 15) + { + lcollen = 15; + } + code = lcollen << 4; + out_uint8(s, code); + out_uint8a(s, colptr, lcollen); + colptr += lcollen; + collen -= lcollen; + cont = collen > 13; + } + cont = (collen > 0) || (replen > 0); + while (cont) + { + lreplen = replen; + if ((collen == 0) && (lreplen > 15)) + { + /* big run */ + if (lreplen > 47) + { + lreplen = 47; + } + LLOGLN(10, ("fout: big run lreplen %d", lreplen)); + replen -= lreplen; + code = ((lreplen & 0xF) << 4) | ((lreplen & 0xF0) >> 4); + } + else + { + if (lreplen > 15) + { + lreplen = 15; + } + replen -= lreplen; + if (lreplen < 3) + { + collen += lreplen; + lreplen = 0; + } + code = (collen << 4) | lreplen; + } + out_uint8(s, code); + out_uint8a(s, colptr, collen); + colptr += collen + lreplen; + collen = 0; + cont = replen > 0; + } + return 0; +} + +/*****************************************************************************/ +static int APP_CC +fpack(char *plane, int cx, int cy, struct stream *s) +{ + char *ptr8; + char *colptr; + char *lend; + int jndex; + int collen; + int replen; + + LLOGLN(10, ("fpack:")); + for (jndex = 0; jndex < cy; jndex++) + { + LLOGLN(10, ("line start line %d cx %d cy %d", jndex, cx, cy)); + ptr8 = plane + jndex * cx; + LHEXDUMP(10, (ptr8, cx)); + lend = ptr8 + (cx - 1); + colptr = ptr8; + if (colptr[0] == 0) + { + collen = 0; + replen = 1; + } + else + { + collen = 1; + replen = 0; + } + while (ptr8 < lend) + { + if (ptr8[0] == ptr8[1]) + { + replen++; + } + else + { + if (replen > 0) + { + if (replen < 3) + { + collen += replen + 1; + replen = 0; + } + else + { + fout(collen, replen, colptr, s); + colptr = ptr8 + 1; + replen = 0; + collen = 1; + } + } + else + { + collen++; + } + } + ptr8++; + } + /* end of line */ + fout(collen, replen, colptr, s); + } + return 0; +} + /*****************************************************************************/ /* returns the number of lines compressed */ int APP_CC @@ -36,7 +203,6 @@ xrdp_bitmap32_compress(char *in_data, int width, int height, { int pixel; int *ptr32; - char *ptr8; char *alpha_data; char *red_data; char *green_data; @@ -45,17 +211,20 @@ xrdp_bitmap32_compress(char *in_data, int width, int height, int red_bytes; int green_bytes; int blue_bytes; - int iindex; - int jindex; + int index; int cx; int cy; int header; - header = 0x20; /* no alpha TODO */ + LLOGLN(10, ("xrdp_bitmap32_compress:")); + + //header = FLAGS_NOALPHA | FLAGS_RLE; + //header = FLAGS_NOALPHA; + header = FLAGS_RLE; cx = width + e; cy = 0; - alpha_data = g_malloc(cx * height * 4, 0); + alpha_data = temp_s->data; red_data = alpha_data + cx * height; green_data = red_data + cx * height; blue_data = green_data + cx * height; @@ -68,7 +237,7 @@ xrdp_bitmap32_compress(char *in_data, int width, int height, while (start_line >= 0) { ptr32 = (int *) (in_data + start_line * width * 4); - for (iindex = 0; iindex < width; iindex++) + for (index = 0; index < width; index++) { pixel = *ptr32; ptr32++; @@ -81,7 +250,7 @@ xrdp_bitmap32_compress(char *in_data, int width, int height, blue_data[blue_bytes] = pixel >> 0; blue_bytes++; } - for (iindex = 0; iindex < e; iindex++) + for (index = 0; index < e; index++) { alpha_data[alpha_bytes] = 0; alpha_bytes++; @@ -95,15 +264,42 @@ xrdp_bitmap32_compress(char *in_data, int width, int height, start_line--; cy++; } - out_uint8(s, header); - out_uint8a(s, red_data, red_bytes); - out_uint8a(s, green_data, green_bytes); - out_uint8a(s, blue_data, blue_bytes); - if ((header & 0x10) == 0) + + if (header & FLAGS_RLE) { + out_uint8(s, header); + + /* delta, other steps */ + if ((header & FLAGS_NOALPHA) == 0) + { + fdelta(alpha_data, cx, cy); + } + fdelta(red_data, cx, cy); + fdelta(green_data, cx, cy); + fdelta(blue_data, cx, cy); + + /* pack */ + if ((header & FLAGS_NOALPHA) == 0) + { + fpack(alpha_data, cx, cy, s); + } + fpack(red_data, cx, cy, s); + fpack(green_data, cx, cy, s); + fpack(blue_data, cx, cy, s); + } + else + { + out_uint8(s, header); + if ((header & FLAGS_NOALPHA) == 0) + { + out_uint8a(s, alpha_data, alpha_bytes); + } + out_uint8a(s, red_data, red_bytes); + out_uint8a(s, green_data, green_bytes); + out_uint8a(s, blue_data, blue_bytes); /* pad if no RLE */ out_uint8(s, 0x00); } - g_free(alpha_data); + return cy; } From aa35a327528c507505de33496dd214c40675fd6e Mon Sep 17 00:00:00 2001 From: Jay Sorg Date: Sun, 15 Jun 2014 16:17:40 -0700 Subject: [PATCH 08/10] libxrdp: 32 bpp compression changes / fixes --- libxrdp/xrdp_bitmap32_compress.c | 151 +++++++++++++++++++------------ libxrdp/xrdp_orders.c | 12 ++- 2 files changed, 105 insertions(+), 58 deletions(-) diff --git a/libxrdp/xrdp_bitmap32_compress.c b/libxrdp/xrdp_bitmap32_compress.c index c3afff90..1bcf5db9 100644 --- a/libxrdp/xrdp_bitmap32_compress.c +++ b/libxrdp/xrdp_bitmap32_compress.c @@ -35,6 +35,58 @@ http://msdn.microsoft.com/en-us/library/cc241877.aspx #define LHEXDUMP(_level, _args) \ do { if (_level < LLOG_LEVEL) { g_hexdump _args ; } } while (0) +/*****************************************************************************/ +static int APP_CC +fsplit(char *in_data, int start_line, int width, int e, + char *alpha_data, char *red_data, char *green_data, char *blue_data) +{ + int index; + int pixel; + int cy; + int alpha_bytes; + int red_bytes; + int green_bytes; + int blue_bytes; + int *ptr32; + + cy = 0; + alpha_bytes = 0; + red_bytes = 0; + green_bytes = 0; + blue_bytes = 0; + while (start_line >= 0) + { + ptr32 = (int *) (in_data + start_line * width * 4); + for (index = 0; index < width; index++) + { + pixel = *ptr32; + ptr32++; + alpha_data[alpha_bytes] = pixel >> 24; + alpha_bytes++; + red_data[red_bytes] = pixel >> 16; + red_bytes++; + green_data[green_bytes] = pixel >> 8; + green_bytes++; + blue_data[blue_bytes] = pixel >> 0; + blue_bytes++; + } + for (index = 0; index < e; index++) + { + alpha_data[alpha_bytes] = 0; + alpha_bytes++; + red_data[red_bytes] = 0; + red_bytes++; + green_data[green_bytes] = 0; + green_bytes++; + blue_data[blue_bytes] = 0; + blue_bytes++; + } + start_line--; + cy++; + } + return cy; +} + /*****************************************************************************/ static int APP_CC fdelta(char *plane, int cx, int cy) @@ -135,11 +187,13 @@ fpack(char *plane, int cx, int cy, struct stream *s) char *ptr8; char *colptr; char *lend; + char *holdp; int jndex; int collen; int replen; LLOGLN(10, ("fpack:")); + holdp = s->p; for (jndex = 0; jndex < cy; jndex++) { LLOGLN(10, ("line start line %d cx %d cy %d", jndex, cx, cy)); @@ -190,7 +244,7 @@ fpack(char *plane, int cx, int cy, struct stream *s) /* end of line */ fout(collen, replen, colptr, s); } - return 0; + return (int) (s->p - holdp); } /*****************************************************************************/ @@ -201,8 +255,6 @@ xrdp_bitmap32_compress(char *in_data, int width, int height, int start_line, struct stream *temp_s, int e) { - int pixel; - int *ptr32; char *alpha_data; char *red_data; char *green_data; @@ -211,10 +263,10 @@ xrdp_bitmap32_compress(char *in_data, int width, int height, int red_bytes; int green_bytes; int blue_bytes; - int index; int cx; int cy; int header; + int max_bytes; LLOGLN(10, ("xrdp_bitmap32_compress:")); @@ -223,80 +275,67 @@ xrdp_bitmap32_compress(char *in_data, int width, int height, header = FLAGS_RLE; cx = width + e; - cy = 0; alpha_data = temp_s->data; red_data = alpha_data + cx * height; green_data = red_data + cx * height; blue_data = green_data + cx * height; - alpha_bytes = 0; - red_bytes = 0; - green_bytes = 0; - blue_bytes = 0; /* split planes */ - while (start_line >= 0) - { - ptr32 = (int *) (in_data + start_line * width * 4); - for (index = 0; index < width; index++) - { - pixel = *ptr32; - ptr32++; - alpha_data[alpha_bytes] = pixel >> 24; - alpha_bytes++; - red_data[red_bytes] = pixel >> 16; - red_bytes++; - green_data[green_bytes] = pixel >> 8; - green_bytes++; - blue_data[blue_bytes] = pixel >> 0; - blue_bytes++; - } - for (index = 0; index < e; index++) - { - alpha_data[alpha_bytes] = 0; - alpha_bytes++; - red_data[red_bytes] = 0; - red_bytes++; - green_data[green_bytes] = 0; - green_bytes++; - blue_data[blue_bytes] = 0; - blue_bytes++; - } - start_line--; - cy++; - } + cy = fsplit(in_data, start_line, width, e, + alpha_data, red_data, green_data, blue_data); if (header & FLAGS_RLE) { out_uint8(s, header); - - /* delta, other steps */ - if ((header & FLAGS_NOALPHA) == 0) + if (header & FLAGS_NOALPHA) + { + fdelta(red_data, cx, cy); + fdelta(green_data, cx, cy); + fdelta(blue_data, cx, cy); + red_bytes = fpack(red_data, cx, cy, s); + green_bytes = fpack(green_data, cx, cy, s); + blue_bytes = fpack(blue_data, cx, cy, s); + max_bytes = cx * cy * 3; + } + else { fdelta(alpha_data, cx, cy); + fdelta(red_data, cx, cy); + fdelta(green_data, cx, cy); + fdelta(blue_data, cx, cy); + alpha_bytes = fpack(alpha_data, cx, cy, s); + red_bytes = fpack(red_data, cx, cy, s); + green_bytes = fpack(green_data, cx, cy, s); + blue_bytes = fpack(blue_data, cx, cy, s); + max_bytes = cx * cy * 4; } - fdelta(red_data, cx, cy); - fdelta(green_data, cx, cy); - fdelta(blue_data, cx, cy); - - /* pack */ - if ((header & FLAGS_NOALPHA) == 0) + if (alpha_bytes + red_bytes + green_bytes + blue_bytes > max_bytes) { - fpack(alpha_data, cx, cy, s); + LLOGLN(10, ("xrdp_bitmap32_compress: too big, argb " + "bytes %d %d %d %d cx %d cy %d", alpha_bytes, red_bytes, + green_bytes, blue_bytes, cx, cy)); } - fpack(red_data, cx, cy, s); - fpack(green_data, cx, cy, s); - fpack(blue_data, cx, cy, s); } else { out_uint8(s, header); - if ((header & FLAGS_NOALPHA) == 0) + red_bytes = cx * cy; + green_bytes = cx * cy; + blue_bytes = cx * cy; + if (header & FLAGS_NOALPHA) + { + out_uint8a(s, red_data, red_bytes); + out_uint8a(s, green_data, green_bytes); + out_uint8a(s, blue_data, blue_bytes); + } + else { + alpha_bytes = cx * cy; out_uint8a(s, alpha_data, alpha_bytes); + out_uint8a(s, red_data, red_bytes); + out_uint8a(s, green_data, green_bytes); + out_uint8a(s, blue_data, blue_bytes); } - out_uint8a(s, red_data, red_bytes); - out_uint8a(s, green_data, green_bytes); - out_uint8a(s, blue_data, blue_bytes); /* pad if no RLE */ out_uint8(s, 0x00); } diff --git a/libxrdp/xrdp_orders.c b/libxrdp/xrdp_orders.c index 7ba6cf01..1412386e 100644 --- a/libxrdp/xrdp_orders.c +++ b/libxrdp/xrdp_orders.c @@ -2327,8 +2327,16 @@ xrdp_orders_send_bitmap(struct xrdp_orders *self, init_stream(temp_s, 16384); p = s->p; i = height; - lines_sending = xrdp_bitmap_compress(data, width, height, s, bpp, 16384, - i - 1, temp_s, e); + if (bpp > 24) + { + lines_sending = xrdp_bitmap32_compress(data, width, height, s, bpp, 16384, + i - 1, temp_s, e); + } + else + { + lines_sending = xrdp_bitmap_compress(data, width, height, s, bpp, 16384, + i - 1, temp_s, e); + } if (lines_sending != height) { From ca6bec36e6db708cc58e3d17fe2e864fe62b608a Mon Sep 17 00:00:00 2001 From: Jay Sorg Date: Tue, 17 Jun 2014 13:06:45 -0700 Subject: [PATCH 09/10] libxrdp: no logic change, fix warning, some optimize planar compression --- libxrdp/xrdp_bitmap32_compress.c | 82 ++++++++++++++++++++++---------- 1 file changed, 57 insertions(+), 25 deletions(-) diff --git a/libxrdp/xrdp_bitmap32_compress.c b/libxrdp/xrdp_bitmap32_compress.c index 1bcf5db9..ef20ba0f 100644 --- a/libxrdp/xrdp_bitmap32_compress.c +++ b/libxrdp/xrdp_bitmap32_compress.c @@ -40,46 +40,77 @@ static int APP_CC fsplit(char *in_data, int start_line, int width, int e, char *alpha_data, char *red_data, char *green_data, char *blue_data) { +#if defined(L_ENDIAN) + int alpha; + int red; + int green; + int blue; +#endif int index; + int out_index; int pixel; int cy; - int alpha_bytes; - int red_bytes; - int green_bytes; - int blue_bytes; int *ptr32; cy = 0; - alpha_bytes = 0; - red_bytes = 0; - green_bytes = 0; - blue_bytes = 0; + out_index = 0; while (start_line >= 0) { ptr32 = (int *) (in_data + start_line * width * 4); - for (index = 0; index < width; index++) + index = 0; +#if defined(L_ENDIAN) + while (index + 4 <= width) + { + pixel = *ptr32; + ptr32++; + alpha = (pixel >> 24) & 0x000000ff; + red = (pixel >> 16) & 0x000000ff; + green = (pixel >> 8) & 0x000000ff; + blue = (pixel >> 0) & 0x000000ff; + pixel = *ptr32; + ptr32++; + alpha |= (pixel >> 16) & 0x0000ff00; + red |= (pixel >> 8) & 0x0000ff00; + green |= (pixel << 0) & 0x0000ff00; + blue |= (pixel << 8) & 0x0000ff00; + pixel = *ptr32; + ptr32++; + alpha |= (pixel >> 8) & 0x00ff0000; + red |= (pixel >> 0) & 0x00ff0000; + green |= (pixel << 8) & 0x00ff0000; + blue |= (pixel << 16) & 0x00ff0000; + pixel = *ptr32; + ptr32++; + alpha |= (pixel << 0) & 0xff000000; + red |= (pixel << 8) & 0xff000000; + green |= (pixel << 16) & 0xff000000; + blue |= (pixel << 24) & 0xff000000; + *((int*)(alpha_data + out_index)) = alpha; + *((int*)(red_data + out_index)) = red; + *((int*)(green_data + out_index)) = green; + *((int*)(blue_data + out_index)) = blue; + out_index += 4; + index += 4; + } +#endif + while (index < width) { pixel = *ptr32; ptr32++; - alpha_data[alpha_bytes] = pixel >> 24; - alpha_bytes++; - red_data[red_bytes] = pixel >> 16; - red_bytes++; - green_data[green_bytes] = pixel >> 8; - green_bytes++; - blue_data[blue_bytes] = pixel >> 0; - blue_bytes++; + alpha_data[out_index] = pixel >> 24; + red_data[out_index] = pixel >> 16; + green_data[out_index] = pixel >> 8; + blue_data[out_index] = pixel >> 0; + out_index++; + index++; } for (index = 0; index < e; index++) { - alpha_data[alpha_bytes] = 0; - alpha_bytes++; - red_data[red_bytes] = 0; - red_bytes++; - green_data[green_bytes] = 0; - green_bytes++; - blue_data[blue_bytes] = 0; - blue_bytes++; + alpha_data[out_index] = 0; + red_data[out_index] = 0; + green_data[out_index] = 0; + blue_data[out_index] = 0; + out_index++; } start_line--; cy++; @@ -292,6 +323,7 @@ xrdp_bitmap32_compress(char *in_data, int width, int height, fdelta(red_data, cx, cy); fdelta(green_data, cx, cy); fdelta(blue_data, cx, cy); + alpha_bytes = 0; red_bytes = fpack(red_data, cx, cy, s); green_bytes = fpack(green_data, cx, cy, s); blue_bytes = fpack(blue_data, cx, cy, s); From b142a59e69ee2b4a721641fe7f5dc9dadb2bb020 Mon Sep 17 00:00:00 2001 From: Jay Sorg Date: Tue, 17 Jun 2014 22:41:10 -0700 Subject: [PATCH 10/10] libxrdp: changes for planar compression --- libxrdp/libxrdp.h | 7 +- libxrdp/xrdp_bitmap32_compress.c | 263 ++++++++++++++++++++++++------- libxrdp/xrdp_orders.c | 18 ++- 3 files changed, 216 insertions(+), 72 deletions(-) diff --git a/libxrdp/libxrdp.h b/libxrdp/libxrdp.h index 2ea8b61d..ddfe260b 100644 --- a/libxrdp/libxrdp.h +++ b/libxrdp/libxrdp.h @@ -117,9 +117,10 @@ struct xrdp_sec void *decrypt_rc4_info; void *encrypt_rc4_info; char pub_exp[4]; - char pub_mod[64]; + char pub_mod[256]; char pub_sig[64]; - char pri_exp[64]; + char pri_exp[256]; + int rsa_key_bytes; /* 64 or 256 */ int channel_code; int multimon; char fips_encrypt_key[24]; @@ -509,7 +510,7 @@ int APP_CC xrdp_bitmap32_compress(char *in_data, int width, int height, struct stream *s, int bpp, int byte_limit, int start_line, struct stream *temp_s, - int e); + int e, int flags); int APP_CC xrdp_jpeg_compress(void *handle, char *in_data, int width, int height, struct stream *s, int bpp, int byte_limit, diff --git a/libxrdp/xrdp_bitmap32_compress.c b/libxrdp/xrdp_bitmap32_compress.c index ef20ba0f..d843cff1 100644 --- a/libxrdp/xrdp_bitmap32_compress.c +++ b/libxrdp/xrdp_bitmap32_compress.c @@ -36,9 +36,10 @@ http://msdn.microsoft.com/en-us/library/cc241877.aspx do { if (_level < LLOG_LEVEL) { g_hexdump _args ; } } while (0) /*****************************************************************************/ +/* split ARGB */ static int APP_CC -fsplit(char *in_data, int start_line, int width, int e, - char *alpha_data, char *red_data, char *green_data, char *blue_data) +fsplit4(char *in_data, int start_line, int width, int e, + char *alpha_data, char *red_data, char *green_data, char *blue_data) { #if defined(L_ENDIAN) int alpha; @@ -106,10 +107,10 @@ fsplit(char *in_data, int start_line, int width, int e, } for (index = 0; index < e; index++) { - alpha_data[out_index] = 0; - red_data[out_index] = 0; - green_data[out_index] = 0; - blue_data[out_index] = 0; + alpha_data[out_index] = alpha_data[out_index - 1]; + red_data[out_index] = red_data[out_index - 1]; + green_data[out_index] = green_data[out_index - 1]; + blue_data[out_index] = blue_data[out_index - 1]; out_index++; } start_line--; @@ -119,20 +120,99 @@ fsplit(char *in_data, int start_line, int width, int e, } /*****************************************************************************/ +/* split RGB */ static int APP_CC -fdelta(char *plane, int cx, int cy) +fsplit3(char *in_data, int start_line, int width, int e, + char *red_data, char *green_data, char *blue_data) +{ +#if defined(L_ENDIAN) + int red; + int green; + int blue; +#endif + int index; + int out_index; + int pixel; + int cy; + int *ptr32; + + cy = 0; + out_index = 0; + while (start_line >= 0) + { + ptr32 = (int *) (in_data + start_line * width * 4); + index = 0; +#if defined(L_ENDIAN) + while (index + 4 <= width) + { + pixel = *ptr32; + ptr32++; + red = (pixel >> 16) & 0x000000ff; + green = (pixel >> 8) & 0x000000ff; + blue = (pixel >> 0) & 0x000000ff; + pixel = *ptr32; + ptr32++; + red |= (pixel >> 8) & 0x0000ff00; + green |= (pixel << 0) & 0x0000ff00; + blue |= (pixel << 8) & 0x0000ff00; + pixel = *ptr32; + ptr32++; + red |= (pixel >> 0) & 0x00ff0000; + green |= (pixel << 8) & 0x00ff0000; + blue |= (pixel << 16) & 0x00ff0000; + pixel = *ptr32; + ptr32++; + red |= (pixel << 8) & 0xff000000; + green |= (pixel << 16) & 0xff000000; + blue |= (pixel << 24) & 0xff000000; + *((int*)(red_data + out_index)) = red; + *((int*)(green_data + out_index)) = green; + *((int*)(blue_data + out_index)) = blue; + out_index += 4; + index += 4; + } +#endif + while (index < width) + { + pixel = *ptr32; + ptr32++; + red_data[out_index] = pixel >> 16; + green_data[out_index] = pixel >> 8; + blue_data[out_index] = pixel >> 0; + out_index++; + index++; + } + for (index = 0; index < e; index++) + { + red_data[out_index] = red_data[out_index - 1]; + green_data[out_index] = green_data[out_index - 1]; + blue_data[out_index] = blue_data[out_index - 1]; + out_index++; + } + start_line--; + cy++; + } + return cy; +} + +/*****************************************************************************/ +static int APP_CC +fdelta(char *in_plane, char *out_plane, int cx, int cy) { char delta; - char *ptr8; + char *src8; + char *dst8; int index; int jndex; + g_memcpy(out_plane, in_plane, cx); for (jndex = cy - 2; jndex >= 0; jndex--) { - ptr8 = plane + jndex * cx; + src8 = in_plane + jndex * cx; + dst8 = out_plane + jndex * cx; for (index = 0; index < cx; index++) { - delta = ptr8[cx] - ptr8[0]; + delta = src8[cx] - src8[0]; if (delta & 0x80) { delta = (((~delta) + 1) << 1) - 1; @@ -141,8 +221,9 @@ fdelta(char *plane, int cx, int cy) { delta = delta << 1; } - ptr8[cx] = delta; - ptr8++; + dst8[cx] = delta; + src8++; + dst8++; } } return 0; @@ -278,99 +359,159 @@ fpack(char *plane, int cx, int cy, struct stream *s) return (int) (s->p - holdp); } +/*****************************************************************************/ +static int APP_CC +foutraw3(struct stream *s, int bytes, int header, + char *red_data, char *green_data, char *blue_data) +{ + out_uint8(s, header); + out_uint8a(s, red_data, bytes); + out_uint8a(s, green_data, bytes); + out_uint8a(s, blue_data, bytes); + /* pad if no RLE */ + out_uint8(s, 0x00); + return 0; +} + +/*****************************************************************************/ +static int APP_CC +foutraw4(struct stream *s, int bytes, int header, + char *alpha_data, char *red_data, char *green_data, char *blue_data) +{ + out_uint8(s, header); + out_uint8a(s, alpha_data, bytes); + out_uint8a(s, red_data, bytes); + out_uint8a(s, green_data, bytes); + out_uint8a(s, blue_data, bytes); + /* pad if no RLE */ + out_uint8(s, 0x00); + return 0; +} + /*****************************************************************************/ /* returns the number of lines compressed */ int APP_CC xrdp_bitmap32_compress(char *in_data, int width, int height, struct stream *s, int bpp, int byte_limit, int start_line, struct stream *temp_s, - int e) + int e, int flags) { char *alpha_data; char *red_data; char *green_data; char *blue_data; + char *salpha_data; + char *sred_data; + char *sgreen_data; + char *sblue_data; int alpha_bytes; int red_bytes; int green_bytes; int blue_bytes; int cx; int cy; - int header; int max_bytes; + int total_bytes; + int header; LLOGLN(10, ("xrdp_bitmap32_compress:")); - //header = FLAGS_NOALPHA | FLAGS_RLE; - //header = FLAGS_NOALPHA; - header = FLAGS_RLE; - + header = flags & 0xFF; cx = width + e; - alpha_data = temp_s->data; + salpha_data = temp_s->data; + sred_data = salpha_data + cx * height; + sgreen_data = sred_data + cx * height; + sblue_data = sgreen_data + cx * height; + alpha_data = sblue_data + cx * height; red_data = alpha_data + cx * height; green_data = red_data + cx * height; blue_data = green_data + cx * height; - /* split planes */ - cy = fsplit(in_data, start_line, width, e, - alpha_data, red_data, green_data, blue_data); - - if (header & FLAGS_RLE) + if (header & FLAGS_NOALPHA) { - out_uint8(s, header); - if (header & FLAGS_NOALPHA) + cy = fsplit3(in_data, start_line, width, e, + sred_data, sgreen_data, sblue_data); + if (header & FLAGS_RLE) { - fdelta(red_data, cx, cy); - fdelta(green_data, cx, cy); - fdelta(blue_data, cx, cy); - alpha_bytes = 0; + fdelta(sred_data, red_data, cx, cy); + fdelta(sgreen_data, green_data, cx, cy); + fdelta(sblue_data, blue_data, cx, cy); + out_uint8(s, header); red_bytes = fpack(red_data, cx, cy, s); green_bytes = fpack(green_data, cx, cy, s); blue_bytes = fpack(blue_data, cx, cy, s); + total_bytes = red_bytes + green_bytes + blue_bytes; + if (1 + total_bytes > byte_limit) + { + /* failed */ + LLOGLN(0, ("xrdp_bitmap32_compress: too big, rgb " + "bytes %d %d %d total_bytes %d cx %d cy %d byte_limit %d", + red_bytes, green_bytes, blue_bytes, + total_bytes, cx, cy, byte_limit)); + return 0; + } max_bytes = cx * cy * 3; + if (total_bytes > max_bytes) + { + /* raw is better */ + LLOGLN(10, ("xrdp_bitmap32_compress: too big, rgb " + "bytes %d %d %d total_bytes %d cx %d cy %d max_bytes %d", + red_bytes, green_bytes, blue_bytes, + total_bytes, cx, cy, max_bytes)); + init_stream(s, 0); + foutraw3(s, cx * cy, FLAGS_NOALPHA, sred_data, + sgreen_data, sblue_data); + } } else { - fdelta(alpha_data, cx, cy); - fdelta(red_data, cx, cy); - fdelta(green_data, cx, cy); - fdelta(blue_data, cx, cy); - alpha_bytes = fpack(alpha_data, cx, cy, s); - red_bytes = fpack(red_data, cx, cy, s); - green_bytes = fpack(green_data, cx, cy, s); - blue_bytes = fpack(blue_data, cx, cy, s); - max_bytes = cx * cy * 4; - } - if (alpha_bytes + red_bytes + green_bytes + blue_bytes > max_bytes) - { - LLOGLN(10, ("xrdp_bitmap32_compress: too big, argb " - "bytes %d %d %d %d cx %d cy %d", alpha_bytes, red_bytes, - green_bytes, blue_bytes, cx, cy)); + foutraw3(s, cx * cy, FLAGS_NOALPHA, sred_data, + sgreen_data, sblue_data); } } else { - out_uint8(s, header); - red_bytes = cx * cy; - green_bytes = cx * cy; - blue_bytes = cx * cy; - if (header & FLAGS_NOALPHA) + cy = fsplit4(in_data, start_line, width, e, + salpha_data, sred_data, sgreen_data, sblue_data); + if (header & FLAGS_RLE) { - out_uint8a(s, red_data, red_bytes); - out_uint8a(s, green_data, green_bytes); - out_uint8a(s, blue_data, blue_bytes); + fdelta(salpha_data, alpha_data, cx, cy); + fdelta(sred_data, red_data, cx, cy); + fdelta(sgreen_data, green_data, cx, cy); + fdelta(sblue_data, blue_data, cx, cy); + out_uint8(s, header); + alpha_bytes = fpack(alpha_data, cx, cy, s); + red_bytes = fpack(red_data, cx, cy, s); + green_bytes = fpack(green_data, cx, cy, s); + blue_bytes = fpack(blue_data, cx, cy, s); + max_bytes = cx * cy * 4; + total_bytes = alpha_bytes + red_bytes + green_bytes + blue_bytes; + if (1 + total_bytes > byte_limit) + { + /* failed */ + LLOGLN(0, ("xrdp_bitmap32_compress: too big, argb " + "bytes %d %d %d %d total_bytes %d cx %d cy %d byte_limit %d", + alpha_bytes, red_bytes, green_bytes, blue_bytes, + total_bytes, cx, cy, byte_limit)); + return 0; + } + if (total_bytes > max_bytes) + { + /* raw is better */ + LLOGLN(10, ("xrdp_bitmap32_compress: too big, argb " + "bytes %d %d %d %d total_bytes %d cx %d cy %d max_bytes %d", + alpha_bytes, red_bytes, green_bytes, blue_bytes, + total_bytes, cx, cy, max_bytes)); + init_stream(s, 0); + foutraw4(s, cx * cy, 0, salpha_data, sred_data, + sgreen_data, sblue_data); + } } else { - alpha_bytes = cx * cy; - out_uint8a(s, alpha_data, alpha_bytes); - out_uint8a(s, red_data, red_bytes); - out_uint8a(s, green_data, green_bytes); - out_uint8a(s, blue_data, blue_bytes); + foutraw4(s, cx * cy, 0, salpha_data, sred_data, + sgreen_data, sblue_data); } - /* pad if no RLE */ - out_uint8(s, 0x00); } - return cy; } diff --git a/libxrdp/xrdp_orders.c b/libxrdp/xrdp_orders.c index 1412386e..88ffda8e 100644 --- a/libxrdp/xrdp_orders.c +++ b/libxrdp/xrdp_orders.c @@ -2322,15 +2322,16 @@ xrdp_orders_send_bitmap(struct xrdp_orders *self, } make_stream(s); - init_stream(s, 16384); + init_stream(s, 16384 * 2); make_stream(temp_s); - init_stream(temp_s, 16384); + init_stream(temp_s, 16384 * 2); p = s->p; i = height; if (bpp > 24) { - lines_sending = xrdp_bitmap32_compress(data, width, height, s, bpp, 16384, - i - 1, temp_s, e); + lines_sending = xrdp_bitmap32_compress(data, width, height, s, + bpp, 16384, + i - 1, temp_s, e, 0x30); } else { @@ -2590,15 +2591,16 @@ xrdp_orders_send_bitmap2(struct xrdp_orders *self, } make_stream(s); - init_stream(s, 16384); + init_stream(s, 16384 * 2); make_stream(temp_s); - init_stream(temp_s, 16384); + init_stream(temp_s, 16384 * 2); p = s->p; i = height; if (bpp > 24) { - lines_sending = xrdp_bitmap32_compress(data, width, height, s, bpp, 16384, - i - 1, temp_s, e); + lines_sending = xrdp_bitmap32_compress(data, width, height, s, + bpp, 16384, + i - 1, temp_s, e, 0x30); } else {