diff options
-rw-r--r-- | freerdp/Makefile.am | 2 | ||||
-rw-r--r-- | freerdp/xrdp-color.c | 246 | ||||
-rw-r--r-- | freerdp/xrdp-color.h | 30 | ||||
-rw-r--r-- | freerdp/xrdp-freerdp.c | 110 | ||||
-rw-r--r-- | freerdp/xrdp-freerdp.h | 1 |
5 files changed, 381 insertions, 8 deletions
diff --git a/freerdp/Makefile.am b/freerdp/Makefile.am index a63044f4..afb4f85c 100644 --- a/freerdp/Makefile.am +++ b/freerdp/Makefile.am @@ -13,7 +13,7 @@ INCLUDES = \ lib_LTLIBRARIES = \ libxrdpfreerdp.la -libxrdpfreerdp_la_SOURCES = xrdp-freerdp.c +libxrdpfreerdp_la_SOURCES = xrdp-freerdp.c xrdp-color.c libxrdpfreerdp_la_LIBADD = \ $(top_srcdir)/common/libcommon.la \ diff --git a/freerdp/xrdp-color.c b/freerdp/xrdp-color.c new file mode 100644 index 00000000..16765377 --- /dev/null +++ b/freerdp/xrdp-color.c @@ -0,0 +1,246 @@ +/* + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + + xrdp: A Remote Desktop Protocol server. + Copyright (C) Jay Sorg 2010 + + freerdp wrapper + +*/ + +#include "xrdp-freerdp.h" + +char* APP_CC +convert_bitmap(int in_bpp, int out_bpp, char* bmpdata, + int width, int height, int* palette) +{ + char* out; + char* src; + char* dst; + int i; + int j; + int red; + int green; + int blue; + int pixel; + + if ((in_bpp == 8) && (out_bpp == 8)) + { + out = (char*)g_malloc(width * height, 0); + src = bmpdata; + dst = out; + for (i = 0; i < height; i++) + { + for (j = 0; j < width; j++) + { + pixel = *((tui8*)src); + pixel = palette[pixel]; + SPLITCOLOR32(red, green, blue, pixel); + pixel = COLOR8(red, green, blue); + *dst = pixel; + src++; + dst++; + } + } + return out; + } + if ((in_bpp == 8) && (out_bpp == 16)) + { + out = (char*)g_malloc(width * height * 2, 0); + src = bmpdata; + dst = out; + for (i = 0; i < height; i++) + { + for (j = 0; j < width; j++) + { + pixel = *((tui8*)src); + pixel = palette[pixel]; + SPLITCOLOR32(red, green, blue, pixel); + pixel = COLOR16(red, green, blue); + *((tui16*)dst) = pixel; + src++; + dst += 2; + } + } + return out; + } + if ((in_bpp == 8) && (out_bpp == 24)) + { + out = (char*)g_malloc(width * height * 4, 0); + src = bmpdata; + dst = out; + for (i = 0; i < height; i++) + { + for (j = 0; j < width; j++) + { + pixel = *((tui8*)src); + pixel = palette[pixel]; + SPLITCOLOR32(red, green, blue, pixel); + pixel = COLOR24RGB(red, green, blue); + *((tui32*)dst) = pixel; + src++; + dst += 4; + } + } + return out; + } + if ((in_bpp == 15) && (out_bpp == 16)) + { + out = (char*)g_malloc(width * height * 2, 0); + src = bmpdata; + dst = out; + for (i = 0; i < height; i++) + { + for (j = 0; j < width; j++) + { + pixel = *((tui16*)src); + SPLITCOLOR15(red, green, blue, pixel); + pixel = COLOR16(red, green, blue); + *((tui16*)dst) = pixel; + src += 2; + dst += 2; + } + } + return out; + } + if ((in_bpp == 15) && (out_bpp == 24)) + { + out = (char*)g_malloc(width * height * 4, 0); + src = bmpdata; + dst = out; + for (i = 0; i < height; i++) + { + for (j = 0; j < width; j++) + { + pixel = *((tui16*)src); + SPLITCOLOR15(red, green, blue, pixel); + pixel = COLOR24RGB(red, green, blue); + *((tui32*)dst) = pixel; + src += 2; + dst += 4; + } + } + return out; + } + if ((in_bpp == 16) && (out_bpp == 16)) + { + return bmpdata; + } + if ((in_bpp == 16) && (out_bpp == 24)) + { + out = (char*)g_malloc(width * height * 4, 0); + src = bmpdata; + dst = out; + for (i = 0; i < height; i++) + { + for (j = 0; j < width; j++) + { + pixel = *((tui16*)src); + SPLITCOLOR16(red, green, blue, pixel); + pixel = COLOR24RGB(red, green, blue); + *((tui32*)dst) = pixel; + src += 2; + dst += 4; + } + } + return out; + } + if ((in_bpp == 24) && (out_bpp == 24)) + { + out = (char*)g_malloc(width * height * 4, 0); + src = bmpdata; + dst = out; + for (i = 0; i < height; i++) + { + for (j = 0; j < width; j++) + { + blue = *((tui8*)src); + src++; + green = *((tui8*)src); + src++; + red = *((tui8*)src); + src++; + pixel = COLOR24RGB(red, green, blue); + *((tui32*)dst) = pixel; + dst += 4; + } + } + return out; + } + return 0; +} + +/*****************************************************************************/ +/* returns color or 0 */ +int APP_CC +convert_color(int in_bpp, int out_bpp, int in_color, int* palette) +{ + int pixel; + int red; + int green; + int blue; + + if ((in_bpp == 8) && (out_bpp == 8)) + { + pixel = palette[in_color]; + SPLITCOLOR32(red, green, blue, pixel); + pixel = COLOR8(red, green, blue); + return pixel; + } + if ((in_bpp == 8) && (out_bpp == 16)) + { + pixel = palette[in_color]; + SPLITCOLOR32(red, green, blue, pixel); + pixel = COLOR16(red, green, blue); + return pixel; + } + if ((in_bpp == 8) && (out_bpp == 24)) + { + pixel = palette[in_color]; + SPLITCOLOR32(red, green, blue, pixel); + pixel = COLOR24BGR(red, green, blue); + return pixel; + } + if ((in_bpp == 15) && (out_bpp == 16)) + { + pixel = in_color; + SPLITCOLOR15(red, green, blue, pixel); + pixel = COLOR16(red, green, blue); + return pixel; + } + if ((in_bpp == 15) && (out_bpp == 24)) + { + pixel = in_color; + SPLITCOLOR15(red, green, blue, pixel); + pixel = COLOR24BGR(red, green, blue); + return pixel; + } + if ((in_bpp == 16) && (out_bpp == 16)) + { + return in_color; + } + if ((in_bpp == 16) && (out_bpp == 24)) + { + pixel = in_color; + SPLITCOLOR16(red, green, blue, pixel); + pixel = COLOR24BGR(red, green, blue); + return pixel; + } + if ((in_bpp == 24) && (out_bpp == 24)) + { + return in_color; + } + return 0; +} diff --git a/freerdp/xrdp-color.h b/freerdp/xrdp-color.h new file mode 100644 index 00000000..c9375b53 --- /dev/null +++ b/freerdp/xrdp-color.h @@ -0,0 +1,30 @@ +/* + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + + xrdp: A Remote Desktop Protocol server. + Copyright (C) Jay Sorg 2010 + +*/ + +#ifndef __XRDP_COLOR_H +#define __XRDP_COLOR_H + +char* APP_CC +convert_bitmap(int in_bpp, int out_bpp, char* bmpdata, + int width, int height, int* palette); +int APP_CC +convert_color(int in_bpp, int out_bpp, int in_color, int* palette); + +#endif diff --git a/freerdp/xrdp-freerdp.c b/freerdp/xrdp-freerdp.c index 55487962..23beef44 100644 --- a/freerdp/xrdp-freerdp.c +++ b/freerdp/xrdp-freerdp.c @@ -21,6 +21,7 @@ */ #include "xrdp-freerdp.h" +#include "xrdp-color.h" #define GET_MOD(_inst) ((struct mod*)((_inst)->param1)) #define SET_MOD(_inst, _mod) ((_inst)->param1) = _mod @@ -40,6 +41,18 @@ struct my_glyph int height; }; +struct my_cursor +{ + char* andmask; + int andbpp; + char* xormask; + int xorbpp; + int width; + int height; + int hotx; + int hoty; +}; + /*****************************************************************************/ /* return error */ static int DEFAULT_CC @@ -310,9 +323,19 @@ ui_paint_bitmap(rdpInst* inst, int x, int y, int cx, int cy, int width, int height, uint8* data) { struct mod* mod; + char* bmpdata; mod = GET_MOD(inst); - mod->server_paint_rect(mod, x, y, cx, cy, data, width, height, 0, 0); + bmpdata = convert_bitmap(mod->settings->server_depth, mod->bpp, + data, width, height, mod->cmap); + if (bmpdata != 0) + { + mod->server_paint_rect(mod, x, y, cx, cy, bmpdata, width, height, 0, 0); + } + if (bmpdata != (char*)data) + { + g_free(bmpdata); + } } /******************************************************************************/ @@ -341,6 +364,8 @@ ui_rect(rdpInst* inst, int x, int y, int cx, int cy, int color) struct mod* mod; mod = GET_MOD(inst); + color = convert_color(mod->settings->server_depth, mod->bpp, + color, mod->cmap); mod->server_set_fgcolor(mod, color); mod->server_fill_rect(mod, x, y, cx, cy); } @@ -428,7 +453,11 @@ ui_patblt(rdpInst* inst, uint8 opcode, int x, int y, int cx, int cy, mod = GET_MOD(inst); mod->server_set_opcode(mod, opcode); + fgcolor = convert_color(mod->settings->server_depth, mod->bpp, + fgcolor, mod->cmap); mod->server_set_fgcolor(mod, fgcolor); + bgcolor = convert_color(mod->settings->server_depth, mod->bpp, + bgcolor, mod->cmap); mod->server_set_bgcolor(mod, bgcolor); mod->server_set_mixmode(mod, 1); if (brush->bd != 0) @@ -471,13 +500,24 @@ static void DEFAULT_CC ui_memblt(rdpInst* inst, uint8 opcode, int x, int y, int cx, int cy, RD_HBITMAP src, int srcx, int srcy) { - struct my_bitmap* bm; + struct my_bitmap* bitmap; struct mod* mod; + char* bmpdata; mod = GET_MOD(inst); - bm = (struct my_bitmap*)src; - mod->server_paint_rect(mod, x, y, cx, cy, bm->data, - bm->width, bm->height, srcx, srcy); + bitmap = (struct my_bitmap*)src; + bmpdata = convert_bitmap(mod->settings->server_depth, mod->bpp, + bitmap->data, bitmap->width, + bitmap->height, mod->cmap); + if (bmpdata != 0) + { + mod->server_paint_rect(mod, x, y, cx, cy, bmpdata, + bitmap->width, bitmap->height, srcx, srcy); + } + if (bmpdata != bitmap->data) + { + g_free(bmpdata); + } } /******************************************************************************/ @@ -556,14 +596,32 @@ ui_resize_window(rdpInst* inst) static void DEFAULT_CC ui_set_cursor(rdpInst* inst, RD_HCURSOR cursor) { + struct mod* mod; + struct my_cursor* cur; + g_writeln("ui_set_cursor:"); + mod = GET_MOD(inst); + cur = (struct my_cursor*)cursor; + if (cur != 0) + { + //mod->server_set_cursor(mod, cur->hotx, cur->hoty, cur-> + } } /******************************************************************************/ static void DEFAULT_CC ui_destroy_cursor(rdpInst* inst, RD_HCURSOR cursor) { + struct my_cursor* cur; + g_writeln("ui_destroy_cursor:"); + cur = (struct my_cursor*)cursor; + if (cur != 0) + { + g_free(cur->andmask); + g_free(cur->xormask); + } + g_free(cur); } /******************************************************************************/ @@ -572,8 +630,15 @@ ui_create_cursor(rdpInst* inst, unsigned int x, unsigned int y, int width, int height, uint8* andmask, uint8* xormask, int bpp) { + struct my_cursor* cur; + g_writeln("ui_create_cursor:"); - return 0; + cur = (struct my_cursor*)g_malloc(sizeof(struct my_cursor), 1); + cur->width = width; + cur->height = height; + cur->hotx = x; + cur->hoty = y; + return (RD_HCURSOR)cur; } /******************************************************************************/ @@ -594,8 +659,32 @@ ui_set_default_cursor(rdpInst* inst) static RD_HPALETTE DEFAULT_CC ui_create_colormap(rdpInst* inst, RD_PALETTE* colors) { + struct mod* mod; + int index; + int red; + int green; + int blue; + int pixel; + int count; + int* cmap; + + mod = GET_MOD(inst); g_writeln("ui_create_colormap:"); - return 0; + count = 256; + if (count > colors->ncolors) + { + count = colors->ncolors; + } + cmap = (int*)g_malloc(256 * 4, 1); + for (index = 0; index < count; index++) + { + red = colors->colors[index].red; + green = colors->colors[index].green; + blue = colors->colors[index].blue; + pixel = COLOR24RGB(red, green, blue); + cmap[index] = pixel; + } + return (RD_HPALETTE)cmap; } /******************************************************************************/ @@ -609,7 +698,12 @@ ui_move_pointer(rdpInst* inst, int x, int y) static void DEFAULT_CC ui_set_colormap(rdpInst* inst, RD_HPALETTE map) { + struct mod* mod; + + mod = GET_MOD(inst); g_writeln("ui_set_colormap:"); + g_memcpy(mod->cmap, map, 256 * 4); + g_free(map); } /******************************************************************************/ @@ -664,6 +758,8 @@ mod_init(void) mod->mod_check_wait_objs = mod_check_wait_objs; mod->settings = (struct rdp_set*)g_malloc(sizeof(struct rdp_set), 1); + mod->settings->width = 1280; + mod->settings->height = 1024; mod->settings->encryption = 1; mod->settings->server_depth = 16; mod->settings->bitmap_cache = 1; diff --git a/freerdp/xrdp-freerdp.h b/freerdp/xrdp-freerdp.h index dcb8964e..cd931003 100644 --- a/freerdp/xrdp-freerdp.h +++ b/freerdp/xrdp-freerdp.h @@ -103,4 +103,5 @@ struct mod int bpp; struct rdp_set* settings; struct rdp_inst* inst; + int cmap[256]; }; |