--- sourceforge.net/trunk/rdesktop/xwin.c 2003/02/04 05:32:13 309 +++ sourceforge.net/trunk/rdesktop/xwin.c 2003/02/05 14:16:33 311 @@ -89,7 +89,7 @@ static Colormap xcolmap; static uint32 *colmap; -#define TRANSLATE(col) ( server_bpp != 8 ? col : owncolmap ? col : translate_colour(colmap[col]) ) +#define TRANSLATE(col) ( server_bpp != 8 ? translate_colour(col) : owncolmap ? col : translate_colour(colmap[col]) ) #define SET_FOREGROUND(col) XSetForeground(display, gc, TRANSLATE(col)); #define SET_BACKGROUND(col) XSetBackground(display, gc, TRANSLATE(col)); @@ -137,23 +137,112 @@ (unsigned char *) &motif_hints, PROP_MOTIF_WM_HINTS_ELEMENTS); } +uint32 +colour16to24(uint32 colour) +{ + int r; + int g; + int b; + r = (colour & 0xf800) >> 11; + r = (r * 0xff) / 0x1f; + g = (colour & 0x07e0) >> 5; + g = (g * 0xff) / 0x3f; + b = (colour & 0x001f); + b = (b * 0xff) / 0x1f; + return (r << 16) | (g << 8) | b; +} + +uint32 +colour16to32(uint32 colour) +{ + return colour16to24(colour); +} + +uint32 +colour24to32(uint32 colour) +{ + return colour; +} + +#define BSWAP16(x) { x = (((x & 0xff) << 8) | (x >> 8)); } +#define BSWAP24(x) { x = (((x & 0xff) << 16) | (x >> 16) | ((x >> 8) & 0xff00)); } +#define BSWAP32(x) { x = (((x & 0xff00ff) << 8) | ((x >> 8) & 0xff00ff)); \ + x = (x << 16) | (x >> 16); } + +static uint32 +translate_colour(uint32 colour) +{ + switch (server_bpp) + { + case 16: + switch (bpp) + { + case 16: + break; + case 24: + colour = colour16to24(colour); + break; + case 32: + colour = colour16to32(colour); + break; + } + break; + case 24: + switch (bpp) + { + case 24: + break; + case 32: + colour = colour24to32(colour); + break; + } + break; + } + switch (bpp) + { + case 16: + if (host_be != xserver_be) + BSWAP16(colour); + break; + + case 24: + if (xserver_be) + BSWAP24(colour); + break; + + case 32: + if (host_be != xserver_be) + BSWAP32(colour); + break; + } + + return colour; +} + static void -translate8(uint8 * data, uint8 * out, uint8 * end) +translate8to8(uint8 * data, uint8 * out, uint8 * end) { while (out < end) *(out++) = (uint8) colmap[*(data++)]; } static void -translate16(uint8 * data, uint16 * out, uint16 * end) +translate8to16(uint8 * data, uint16 * out, uint16 * end) { while (out < end) *(out++) = (uint16) colmap[*(data++)]; } +static void +translate16to16(uint16 * data, uint16 * out, uint16 * end) +{ + while (out < end) + *(out++) = (uint16) translate_colour(*(data++)); +} + /* little endian - conversion happens when colourmap is built */ static void -translate24(uint8 * data, uint8 * out, uint8 * end) +translate8to24(uint8 * data, uint8 * out, uint8 * end) { uint32 value; @@ -167,12 +256,33 @@ } static void -translate32(uint8 * data, uint32 * out, uint32 * end) +translate16to24(uint16 * data, uint8 * out, uint8 * end) +{ + uint32 value; + + while (out < end) + { + value = translate_colour(*(data++)); + *(out++) = value; + *(out++) = value >> 8; + *(out++) = value >> 16; + } +} + +static void +translate8to32(uint8 * data, uint32 * out, uint32 * end) { while (out < end) *(out++) = colmap[*(data++)]; } +static void +translate16to32(uint16 * data, uint32 * out, uint32 * end) +{ + while (out < end) + *(out++) = translate_colour(*(data++)); +} + static uint8 * translate_image(int width, int height, uint8 * data) { @@ -180,57 +290,39 @@ uint8 *out = xmalloc(size); uint8 *end = out + size; + if (server_bpp == 16) + { + if (bpp == 16) + translate16to16((uint16 *) data, (uint16 *) out, (uint16 *) end); + else if (bpp == 24) + translate16to24((uint16 *) data, out, end); /* todo, check this one */ + else if (bpp == 32) + translate16to32((uint16 *) data, (uint32 *) out, (uint32 *) end); + return out; + } + /* todo needs server_bpp == 24 */ switch (bpp) { case 8: - translate8(data, out, end); + translate8to8(data, out, end); break; case 16: - translate16(data, (uint16 *) out, (uint16 *) end); + translate8to16(data, (uint16 *) out, (uint16 *) end); break; case 24: - translate24(data, out, end); + translate8to24(data, out, end); break; case 32: - translate32(data, (uint32 *) out, (uint32 *) end); + translate8to32(data, (uint32 *) out, (uint32 *) end); break; } return out; } -#define BSWAP16(x) { x = (((x & 0xff) << 8) | (x >> 8)); } -#define BSWAP24(x) { x = (((x & 0xff) << 16) | (x >> 16) | ((x >> 8) & 0xff00)); } -#define BSWAP32(x) { x = (((x & 0xff00ff) << 8) | ((x >> 8) & 0xff00ff)); \ - x = (x << 16) | (x >> 16); } - -static uint32 -translate_colour(uint32 colour) -{ - switch (bpp) - { - case 16: - if (host_be != xserver_be) - BSWAP16(colour); - break; - - case 24: - if (xserver_be) - BSWAP24(colour); - break; - - case 32: - if (host_be != xserver_be) - BSWAP32(colour); - break; - } - - return colour; -} - BOOL get_key_state(unsigned int state, uint32 keysym) { @@ -734,7 +826,7 @@ tdata = (owncolmap ? data : translate_image(width, height, data)); bitmap = XCreatePixmap(display, wnd, width, height, depth); image = XCreateImage(display, visual, depth, ZPixmap, 0, - (char *) tdata, width, height, 8, 0); + (char *) tdata, width, height, server_bpp == 8 ? 8 : bpp, 0); XPutImage(display, bitmap, gc, image, 0, 0, 0, 0, width, height); @@ -749,28 +841,9 @@ { XImage *image; uint8 *tdata; - - if (server_bpp == 16) - { - image = XCreateImage(display, visual, depth, ZPixmap, 0, - (char *) data, width, height, 16, 0); - - if (ownbackstore) - { - XPutImage(display, backstore, gc, image, 0, 0, x, y, cx, cy); - XCopyArea(display, backstore, wnd, gc, x, y, cx, cy, x, y); - } - else - { - XPutImage(display, wnd, gc, image, 0, 0, x, y, cx, cy); - } - - XFree(image); - return; - } tdata = (owncolmap ? data : translate_image(width, height, data)); image = XCreateImage(display, visual, depth, ZPixmap, 0, - (char *) tdata, width, height, 8, 0); + (char *) tdata, width, height, server_bpp == 8 ? 8 : bpp, 0); if (ownbackstore) {