--- sourceforge.net/trunk/rdesktop/xwin.c 2003/10/22 10:55:11 508 +++ sourceforge.net/trunk/rdesktop/xwin.c 2003/10/29 06:29:05 524 @@ -57,6 +57,7 @@ /* endianness */ static BOOL g_host_be; static BOOL g_xserver_be; +static BOOL g_xserver_bgr; /* software backing store */ static BOOL g_ownbackstore; @@ -202,33 +203,29 @@ pc.red = (pc.red * 0x1f) / 0xff; pc.green = (pc.green * 0x3f) / 0xff; pc.blue = (pc.blue * 0x1f) / 0xff; - return (pc.red << 11) | (pc.green << 5) | pc.blue; + if (g_xserver_bgr) + return (pc.blue << 11) | (pc.green << 5) | pc.red; + else + return (pc.red << 11) | (pc.green << 5) | pc.blue; + } static uint32 make_colour24(PixelColour pc) { - if (g_xserver_be) - { - return pc.red | (pc.green << 8) | (pc.blue << 16); - } + if (g_xserver_bgr) + return (pc.blue << 16) | (pc.green << 8) | pc.red; else - { return (pc.red << 16) | (pc.green << 8) | pc.blue; - } } static uint32 make_colour32(PixelColour pc) { - if (g_xserver_be) - { - return pc.red | (pc.green << 8) | (pc.blue << 16); - } + if (g_xserver_bgr) + return (pc.blue << 16) | (pc.green << 8) | pc.red; else - { return (pc.red << 16) | (pc.green << 8) | pc.blue; - } } #define BSWAP16(x) { x = (((x & 0xff) << 8) | (x >> 8)); } @@ -275,6 +272,7 @@ colour = make_colour16(split_colour24(colour)); break; case 24: + colour = make_colour24(split_colour24(colour)); break; case 32: colour = make_colour32(split_colour24(colour)); @@ -293,10 +291,25 @@ } static void -translate8to16(uint8 * data, uint16 * out, uint16 * end) +translate8to16(uint8 * data, uint8 * out, uint8 * end) { + uint16 value; + while (out < end) - *(out++) = (uint16) g_colmap[*(data++)]; + { + value = (uint16) g_colmap[*(data++)]; + + if (g_xserver_be) + { + *(out++) = value >> 8; + *(out++) = value; + } + else + { + *(out++) = value; + *(out++) = value >> 8; + } + } } /* little endian - conversion happens when colourmap is built */ @@ -308,17 +321,46 @@ while (out < end) { value = g_colmap[*(data++)]; - *(out++) = value; - *(out++) = value >> 8; - *(out++) = value >> 16; + + if (g_xserver_be) + { + *(out++) = value >> 16; + *(out++) = value >> 8; + *(out++) = value; + } + else + { + *(out++) = value; + *(out++) = value >> 8; + *(out++) = value >> 16; + } } } static void -translate8to32(uint8 * data, uint32 * out, uint32 * end) +translate8to32(uint8 * data, uint8 * out, uint8 * end) { + uint32 value; + while (out < end) - *(out++) = g_colmap[*(data++)]; + { + value = g_colmap[*(data++)]; + + if (g_xserver_be) + { + *(out++) = value >> 24; + *(out++) = value >> 16; + *(out++) = value >> 8; + *(out++) = value; + } + else + { + *(out++) = value; + *(out++) = value >> 8; + *(out++) = value >> 16; + *(out++) = value >> 24; + } + } } /* todo the remaining translate function might need some big endian check ?? */ @@ -335,7 +377,8 @@ if (g_host_be) { - BSWAP16(pixel)} + BSWAP16(pixel); + } value = make_colour16(split_colour15(pixel)); @@ -364,7 +407,8 @@ if (g_host_be) { - BSWAP16(pixel)} + BSWAP16(pixel); + } value = make_colour24(split_colour15(pixel)); if (g_xserver_be) @@ -457,7 +501,8 @@ if (g_host_be) { - BSWAP16(pixel)} + BSWAP16(pixel); + } value = make_colour24(split_colour16(pixel)); @@ -625,13 +670,13 @@ translate8to8(data, out, end); break; case 16: - translate8to16(data, (uint16 *) out, (uint16 *) end); + translate8to16(data, out, end); break; case 24: translate8to24(data, out, end); break; case 32: - translate8to32(data, (uint32 *) out, (uint32 *) end); + translate8to32(data, out, end); break; } break; @@ -705,7 +750,11 @@ return False; } - if (g_owncolmap != True) + /* private colour map code only works for 8 bpp */ + if (g_owncolmap && (g_bpp > 8)) + g_owncolmap = False; + + if (!g_owncolmap) { g_xcolmap = DefaultColormapOfScreen(g_screen); if (g_depth <= 8) @@ -720,6 +769,7 @@ test = 1; g_host_be = !(BOOL) (*(uint8 *) (&test)); g_xserver_be = (ImageByteOrder(g_display) == MSBFirst); + g_xserver_bgr = (g_visual->blue_mask > g_visual->red_mask); /* * Determine desktop size @@ -776,8 +826,7 @@ xclip_init(); - /* todo take this out when high colour is done */ - printf("server bpp %d client bpp %d depth %d\n", g_server_bpp, g_bpp, g_depth); + DEBUG_RDP5(("server bpp %d client bpp %d depth %d\n", g_server_bpp, g_bpp, g_depth)); return True; } @@ -1251,11 +1300,24 @@ XImage *image; Pixmap bitmap; uint8 *tdata; + int bitmap_pad; + + if (g_server_bpp == 8) + { + bitmap_pad = 8; + } + else + { + bitmap_pad = g_bpp; + + if (g_bpp == 24) + bitmap_pad = 32; + } tdata = (g_owncolmap ? data : translate_image(width, height, data)); bitmap = XCreatePixmap(g_display, g_wnd, width, height, g_depth); image = XCreateImage(g_display, g_visual, g_depth, ZPixmap, 0, - (char *) tdata, width, height, g_server_bpp == 8 ? 8 : g_bpp, 0); + (char *) tdata, width, height, bitmap_pad, 0); XPutImage(g_display, bitmap, g_gc, image, 0, 0, 0, 0, width, height); @@ -1270,9 +1332,23 @@ { XImage *image; uint8 *tdata; + int bitmap_pad; + + if (g_server_bpp == 8) + { + bitmap_pad = 8; + } + else + { + bitmap_pad = g_bpp; + + if (g_bpp == 24) + bitmap_pad = 32; + } + tdata = (g_owncolmap ? data : translate_image(width, height, data)); image = XCreateImage(g_display, g_visual, g_depth, ZPixmap, 0, - (char *) tdata, width, height, g_server_bpp == 8 ? 8 : g_bpp, 0); + (char *) tdata, width, height, bitmap_pad, 0); if (g_ownbackstore) {