CVS: rdesktop pstcache.c,1.5,1.6 rdesktop.c,1.140,1.141 rdp.c,1.92,1.93 secure.c,1.54,1.55 xwin.c,1.202,1.203

Peter Åstrand <[email protected]>
Newsgroups gmane.network.rdesktop.cvs
Message-ID <[email protected]>
Update of /cvsroot/rdesktop/rdesktop
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv22058

Modified Files:
	pstcache.c rdesktop.c rdp.c secure.c xwin.c 
Log Message:
Applied patch #1390148 from Ilya Konstantinov: Refactoring of color depth code.

Index: pstcache.c
===================================================================
RCS file: /cvsroot/rdesktop/rdesktop/pstcache.c,v
retrieving revision 1.5
retrieving revision 1.6
diff -C2 -d -r1.5 -r1.6
*** pstcache.c	3 Aug 2005 10:56:16 -0000	1.5
--- pstcache.c	24 Jan 2006 12:40:24 -0000	1.6
***************
*** 25,29 ****
  #define IS_PERSISTENT(id) (id < 8 && g_pstcache_fd[id] > 0)
  
! extern int g_server_bpp;
  extern BOOL g_bitmap_cache;
  extern BOOL g_bitmap_cache_persist_enable;
--- 25,29 ----
  #define IS_PERSISTENT(id) (id < 8 && g_pstcache_fd[id] > 0)
  
! extern int g_server_depth;
  extern BOOL g_bitmap_cache;
  extern BOOL g_bitmap_cache_persist_enable;
***************
*** 132,137 ****
  			memcpy(keylist[idx], cellhdr.key, sizeof(HASH_KEY));
  
! 			/* Pre-cache (not possible for 8bpp because 8bpp needs a colourmap) */
! 			if (g_bitmap_cache_precache && cellhdr.stamp && g_server_bpp > 8)
  				pstcache_load_bitmap(id, idx);
  
--- 132,137 ----
  			memcpy(keylist[idx], cellhdr.key, sizeof(HASH_KEY));
  
! 			/* Pre-cache (not possible for 8 bit colour depth cause it needs a colourmap) */
! 			if (g_bitmap_cache_precache && cellhdr.stamp && g_server_depth > 8)
  				pstcache_load_bitmap(id, idx);
  
***************
*** 180,184 ****
  	}
  
! 	g_pstcache_Bpp = (g_server_bpp + 7) / 8;
  	sprintf(filename, "cache/pstcache_%d_%d", cache_id, g_pstcache_Bpp);
  	DEBUG(("persistent bitmap cache file: %s\n", filename));
--- 180,184 ----
  	}
  
! 	g_pstcache_Bpp = (g_server_depth + 7) / 8;
  	sprintf(filename, "cache/pstcache_%d_%d", cache_id, g_pstcache_Bpp);
  	DEBUG(("persistent bitmap cache file: %s\n", filename));

Index: rdesktop.c
===================================================================
RCS file: /cvsroot/rdesktop/rdesktop/rdesktop.c,v
retrieving revision 1.140
retrieving revision 1.141
diff -C2 -d -r1.140 -r1.141
*** rdesktop.c	30 Dec 2005 20:32:06 -0000	1.140
--- rdesktop.c	24 Jan 2006 12:40:24 -0000	1.141
***************
*** 70,74 ****
  				   4 ypos neg  */
  extern int g_tcp_port_rdp;
! int g_server_bpp = 8;
  int g_win_button_size = 0;	/* If zero, disable single app mode */
  BOOL g_bitmap_compression = True;
--- 70,74 ----
  				   4 ypos neg  */
  extern int g_tcp_port_rdp;
! int g_server_depth = 8;
  int g_win_button_size = 0;	/* If zero, disable single app mode */
  BOOL g_bitmap_compression = True;
***************
*** 591,599 ****
  
  			case 'a':
! 				g_server_bpp = strtol(optarg, NULL, 10);
! 				if (g_server_bpp != 8 && g_server_bpp != 16 && g_server_bpp != 15
! 				    && g_server_bpp != 24)
  				{
! 					error("invalid server bpp\n");
  					return 1;
  				}
--- 591,600 ----
  
  			case 'a':
! 				g_server_depth = strtol(optarg, NULL, 10);
! 				if (g_server_depth != 8 &&
! 				    g_server_depth != 16 &&
! 				    g_server_depth != 15 && g_server_depth != 24)
  				{
! 					error("Invalid server colour depth.\n");
  					return 1;
  				}

Index: rdp.c
===================================================================
RCS file: /cvsroot/rdesktop/rdesktop/rdp.c,v
retrieving revision 1.92
retrieving revision 1.93
diff -C2 -d -r1.92 -r1.93
*** rdp.c	8 Aug 2005 19:15:55 -0000	1.92
--- rdp.c	24 Jan 2006 12:40:24 -0000	1.93
***************
*** 45,49 ****
  extern uint16 g_server_rdp_version;
  extern uint32 g_rdp5_performanceflags;
! extern int g_server_bpp;
  extern int g_width;
  extern int g_height;
--- 45,49 ----
  extern uint16 g_server_rdp_version;
  extern uint32 g_rdp5_performanceflags;
! extern int g_server_depth;
  extern int g_width;
  extern int g_height;
***************
*** 621,625 ****
  	out_uint16_le(s, RDP_CAPLEN_BITMAP);
  
! 	out_uint16_le(s, g_server_bpp);	/* Preferred BPP */
  	out_uint16_le(s, 1);	/* Receive 1 BPP */
  	out_uint16_le(s, 1);	/* Receive 4 BPP */
--- 621,625 ----
  	out_uint16_le(s, RDP_CAPLEN_BITMAP);
  
! 	out_uint16_le(s, g_server_depth);	/* Preferred colour depth */
  	out_uint16_le(s, 1);	/* Receive 1 BPP */
  	out_uint16_le(s, 1);	/* Receive 4 BPP */
***************
*** 685,689 ****
  	out_uint16_le(s, RDP_CAPLEN_BMPCACHE);
  
! 	Bpp = (g_server_bpp + 7) / 8;
  	out_uint8s(s, 24);	/* unused */
  	out_uint16_le(s, 0x258);	/* entries */
--- 685,689 ----
  	out_uint16_le(s, RDP_CAPLEN_BMPCACHE);
  
! 	Bpp = (g_server_depth + 7) / 8;	/* bytes per pixel */
  	out_uint8s(s, 24);	/* unused */
  	out_uint16_le(s, 0x258);	/* entries */
***************
*** 882,888 ****
  rdp_process_bitmap_caps(STREAM s)
  {
! 	uint16 width, height, bpp;
  
! 	in_uint16_le(s, bpp);
  	in_uint8s(s, 6);
  
--- 882,888 ----
  rdp_process_bitmap_caps(STREAM s)
  {
! 	uint16 width, height, depth;
  
! 	in_uint16_le(s, depth);
  	in_uint8s(s, 6);
  
***************
*** 890,907 ****
  	in_uint16_le(s, height);
  
! 	DEBUG(("setting desktop size and bpp to: %dx%dx%d\n", width, height, bpp));
  
  	/*
! 	 * The server may limit bpp and change the size of the desktop (for
  	 * example when shadowing another session).
  	 */
! 	if (g_server_bpp != bpp)
  	{
! 		warning("colour depth changed from %d to %d\n", g_server_bpp, bpp);
! 		g_server_bpp = bpp;
  	}
  	if (g_width != width || g_height != height)
  	{
! 		warning("screen size changed from %dx%d to %dx%d\n", g_width, g_height,
  			width, height);
  		g_width = width;
--- 890,908 ----
  	in_uint16_le(s, height);
  
! 	DEBUG(("setting desktop size and depth to: %dx%dx%d\n", width, height, depth));
  
  	/*
! 	 * The server may limit depth and change the size of the desktop (for
  	 * example when shadowing another session).
  	 */
! 	if (g_server_depth != depth)
  	{
! 		warning("Remote desktop does not support colour depth %d; falling back to %d\n",
! 			g_server_depth, depth);
! 		g_server_depth = depth;
  	}
  	if (g_width != width || g_height != height)
  	{
! 		warning("Remote desktop changed from %dx%d to %dx%d.\n", g_width, g_height,
  			width, height);
  		g_width = width;

Index: secure.c
===================================================================
RCS file: /cvsroot/rdesktop/rdesktop/secure.c,v
retrieving revision 1.54
retrieving revision 1.55
diff -C2 -d -r1.54 -r1.55
*** secure.c	30 Dec 2005 20:32:06 -0000	1.54
--- secure.c	24 Jan 2006 12:40:24 -0000	1.55
***************
*** 38,42 ****
  extern BOOL g_use_rdp5;
  extern BOOL g_console_session;
! extern int g_server_bpp;
  extern uint16 mcs_userid;
  extern VCHANNEL g_channels[];
--- 38,42 ----
  extern BOOL g_use_rdp5;
  extern BOOL g_console_session;
! extern int g_server_depth;
  extern uint16 mcs_userid;
  extern VCHANNEL g_channels[];
***************
*** 460,464 ****
  
  	out_uint32(s, 0);
! 	out_uint8(s, g_server_bpp);
  	out_uint16_le(s, 0x0700);
  	out_uint8(s, 0);
--- 460,464 ----
  
  	out_uint32(s, 0);
! 	out_uint8(s, g_server_depth);
  	out_uint16_le(s, 0x0700);
  	out_uint8(s, 0);
***************
*** 765,769 ****
  	{
  		g_use_rdp5 = 0;
! 		g_server_bpp = 8;
  	}
  }
--- 765,769 ----
  	{
  		g_use_rdp5 = 0;
! 		g_server_depth = 8;
  	}
  }

Index: xwin.c
===================================================================
RCS file: /cvsroot/rdesktop/rdesktop/xwin.c,v
retrieving revision 1.202
retrieving revision 1.203
diff -C2 -d -r1.202 -r1.203
*** xwin.c	24 Jan 2006 12:25:49 -0000	1.202
--- xwin.c	24 Jan 2006 12:40:24 -0000	1.203
***************
*** 39,43 ****
  extern BOOL g_hide_decorations;
  extern char g_title[];
! extern int g_server_bpp;
  extern int g_win_button_size;
  
--- 39,45 ----
  extern BOOL g_hide_decorations;
  extern char g_title[];
! /* Color depth of the RDP session.
!    As of RDP 5.1, it may be 8, 15, 16 or 24. */
! extern int g_server_depth;
  extern int g_win_button_size;
  
***************
*** 54,58 ****
--- 56,66 ----
  static GC g_create_glyph_gc = NULL;
  static Visual *g_visual;
+ /* Color depth of the X11 visual of our window (e.g. 24 for True Color R8G8B visual).
+    This may be 32 for R8G8B8 visuals, and then the rest of the bits are undefined
+    as far as we're concerned. */
  static int g_depth;
+ /* Bits-per-Pixel of the pixmaps we'll be using to draw on our window.
+    This may be larger than g_depth, in which case some of the bits would
+    be kept solely for alignment (e.g. 32bpp pixmaps on a 24bpp visual). */
  static int g_bpp;
  static XIM g_IM;
***************
*** 64,68 ****
  static BOOL g_focused;
  static BOOL g_mouse_in_wnd;
! static BOOL g_arch_match = False;	/* set to True if RGB XServer and little endian */
  
  /* endianness */
--- 72,82 ----
  static BOOL g_focused;
  static BOOL g_mouse_in_wnd;
! /* Indicates the visual is has 15, 16 or 24 depth
!    and the same color channel masks as its RDP equivalent. */
! static BOOL g_compatible_depth;
! /* Indicates whether RDP's bitmaps and our XImages have the same
!    binary format. If so, we can avoid an expensive translation.
!    If this is True, so is g_compatible_depth. */
! static BOOL g_no_translate_image = False;
  
  /* endianness */
***************
*** 151,155 ****
  static uint32 *g_colmap = NULL;
  
! #define TRANSLATE(col)		( g_server_bpp != 8 ? translate_colour(col) : g_owncolmap ? col : g_colmap[col] )
  #define SET_FOREGROUND(col)	XSetForeground(g_display, g_gc, TRANSLATE(col));
  #define SET_BACKGROUND(col)	XSetBackground(g_display, g_gc, TRANSLATE(col));
--- 165,169 ----
  static uint32 *g_colmap = NULL;
  
! #define TRANSLATE(col)		( g_server_depth != 8 ? translate_colour(col) : g_owncolmap ? col : g_colmap[col] )
  #define SET_FOREGROUND(col)	XSetForeground(g_display, g_gc, TRANSLATE(col));
  #define SET_BACKGROUND(col)	XSetBackground(g_display, g_gc, TRANSLATE(col));
***************
*** 241,245 ****
  {
  	PixelColour pc;
! 	switch (g_server_bpp)
  	{
  		case 15:
--- 255,259 ----
  {
  	PixelColour pc;
! 	switch (g_server_depth)
  	{
  		case 15:
***************
*** 252,255 ****
--- 266,275 ----
  			SPLITCOLOUR24(colour, pc);
  			break;
+ 		default:
+ 			/* Avoid warning */
+ 			pc.red = 0;
+ 			pc.green = 0;
+ 			pc.blue = 0;
+ 			break;
  	}
  	return MAKECOLOUR(pc);
***************
*** 303,307 ****
  	uint16 value;
  
! 	if (g_arch_match)
  	{
  		/* *INDENT-OFF* */
--- 323,327 ----
  	uint16 value;
  
! 	if (g_compatible_depth)
  	{
  		/* *INDENT-OFF* */
***************
*** 337,341 ****
  	uint32 value;
  
! 	if (g_xserver_be)
  	{
  		while (out < end)
--- 357,361 ----
  	uint32 value;
  
! 	if (g_compatible_depth)
  	{
  		while (out < end)
***************
*** 360,364 ****
  	uint32 value;
  
! 	if (g_arch_match)
  	{
  		/* *INDENT-OFF* */
--- 380,384 ----
  	uint32 value;
  
! 	if (g_compatible_depth)
  	{
  		/* *INDENT-OFF* */
***************
*** 432,436 ****
  	PixelColour pc;
  
! 	if (g_arch_match)
  	{
  		/* *INDENT-OFF* */
--- 452,456 ----
  	PixelColour pc;
  
! 	if (g_compatible_depth)
  	{
  		/* *INDENT-OFF* */
***************
*** 482,486 ****
  	PixelColour pc;
  
! 	if (g_arch_match)
  	{
  		/* *INDENT-OFF* */
--- 502,506 ----
  	PixelColour pc;
  
! 	if (g_compatible_depth)
  	{
  		/* *INDENT-OFF* */
***************
*** 590,594 ****
  	PixelColour pc;
  
! 	if (g_arch_match)
  	{
  		/* *INDENT-OFF* */
--- 610,614 ----
  	PixelColour pc;
  
! 	if (g_compatible_depth)
  	{
  		/* *INDENT-OFF* */
***************
*** 660,664 ****
  	PixelColour pc;
  
! 	if (g_arch_match)
  	{
  		/* *INDENT-OFF* */
--- 680,684 ----
  	PixelColour pc;
  
! 	if (g_compatible_depth)
  	{
  		/* *INDENT-OFF* */
***************
*** 789,793 ****
  	PixelColour pc;
  
! 	if (g_arch_match)
  	{
  		/* *INDENT-OFF* */
--- 809,813 ----
  	PixelColour pc;
  
! 	if (g_compatible_depth)
  	{
  		/* *INDENT-OFF* */
***************
*** 844,857 ****
  	uint8 *end;
  
! 	/* if server and xserver bpp match, */
! 	/* and arch(endian) matches, no need to translate */
! 	/* just return data */
! 	if (g_arch_match)
  	{
! 		if (g_depth == 15 && g_server_bpp == 15)
! 			return data;
! 		if (g_depth == 16 && g_server_bpp == 16)
! 			return data;
! 		if (g_depth == 24 && g_bpp == 24 && g_server_bpp == 24)
  			return data;
  	}
--- 864,880 ----
  	uint8 *end;
  
! 	/*
! 	   If RDP depth and X Visual depths match,
! 	   and arch(endian) matches, no need to translate:
! 	   just return data.
! 	   Note: select_visual should've already ensured g_no_translate
! 	   is only set for compatible depths, but the RDP depth might've
! 	   changed during connection negotiations.
! 	 */
! 	if (g_no_translate_image)
  	{
! 		if ((g_depth == 15 && g_server_depth == 15) ||
! 		    (g_depth == 16 && g_server_depth == 16) ||
! 		    (g_depth == 24 && g_server_depth == 24))
  			return data;
  	}
***************
*** 861,865 ****
  	end = out + size;
  
! 	switch (g_server_bpp)
  	{
  		case 24:
--- 884,888 ----
  	end = out + size;
  
! 	switch (g_server_depth)
  	{
  		case 24:
***************
*** 959,1070 ****
  }
  
! BOOL
! ui_init(void)
  {
- 	XVisualInfo vi;
  	XPixmapFormatValues *pfm;
! 	uint16 test;
! 	int i, screen_num, nvisuals;
  	XVisualInfo *vmatches = NULL;
  	XVisualInfo template;
! 	Bool TrueColorVisual = False;
  
! 	g_display = XOpenDisplay(NULL);
! 	if (g_display == NULL)
  	{
! 		error("Failed to open display: %s\n", XDisplayName(NULL));
  		return False;
  	}
  
! 	screen_num = DefaultScreen(g_display);
! 	g_x_socket = ConnectionNumber(g_display);
! 	g_screen = ScreenOfDisplay(g_display, screen_num);
! 	g_depth = DefaultDepthOfScreen(g_screen);
! 
! 	/* Search for best TrueColor depth */
  	template.class = TrueColor;
! 	vmatches = XGetVisualInfo(g_display, VisualClassMask, &template, &nvisuals);
! 
! 	nvisuals--;
! 	while (nvisuals >= 0)
  	{
! 		if ((vmatches + nvisuals)->depth > g_depth)
  		{
! 			g_depth = (vmatches + nvisuals)->depth;
! 		}
! 		nvisuals--;
! 		TrueColorVisual = True;
! 	}
  
! 	test = 1;
! 	g_host_be = !(BOOL) (*(uint8 *) (&test));
! 	g_xserver_be = (ImageByteOrder(g_display) == MSBFirst);
  
! 	if ((g_server_bpp == 8) && ((!TrueColorVisual) || (g_depth <= 8)))
! 	{
! 		/* we use a colourmap, so the default visual should do */
! 		g_visual = DefaultVisualOfScreen(g_screen);
! 		g_depth = DefaultDepthOfScreen(g_screen);
  
! 		/* Do not allocate colours on a TrueColor visual */
! 		if (g_visual->class == TrueColor)
! 		{
! 			g_owncolmap = False;
  		}
  	}
  	else
  	{
! 		/* need a truecolour visual */
! 		if (!XMatchVisualInfo(g_display, screen_num, g_depth, TrueColor, &vi))
  		{
! 			error("The display does not support true colour - high colour support unavailable.\n");
  			return False;
  		}
  
! 		g_visual = vi.visual;
! 		g_owncolmap = False;
! 		calculate_shifts(vi.red_mask, &g_red_shift_r, &g_red_shift_l);
! 		calculate_shifts(vi.blue_mask, &g_blue_shift_r, &g_blue_shift_l);
! 		calculate_shifts(vi.green_mask, &g_green_shift_r, &g_green_shift_l);
  
! 		/* if RGB video and everything is little endian */
! 		if ((vi.red_mask > vi.green_mask && vi.green_mask > vi.blue_mask) &&
! 		    !g_xserver_be && !g_host_be)
  		{
! 			if (g_depth <= 16 || (g_red_shift_l == 16 && g_green_shift_l == 8 &&
! 					      g_blue_shift_l == 0))
  			{
! 				g_arch_match = True;
  			}
- 		}
  
! 		if (g_arch_match)
! 		{
! 			DEBUG(("Architectures match, enabling little endian optimisations.\n"));
  		}
  	}
  
! 	pfm = XListPixmapFormats(g_display, &i);
! 	if (pfm != NULL)
  	{
! 		/* Use maximum bpp for this depth - this is generally
! 		   desirable, e.g. 24 bits->32 bits. */
! 		while (i--)
! 		{
! 			if ((pfm[i].depth == g_depth) && (pfm[i].bits_per_pixel > g_bpp))
! 			{
! 				g_bpp = pfm[i].bits_per_pixel;
! 			}
! 		}
! 		XFree(pfm);
  	}
  
- 	if (g_bpp < 8)
  	{
! 		error("Less than 8 bpp not currently supported.\n");
! 		XCloseDisplay(g_display);
  		return False;
  	}
  
  	if (!g_owncolmap)
  	{
--- 982,1227 ----
  }
  
! /* Given a mask of a colour channel (e.g. XVisualInfo.red_mask),
!    calculates the bits-per-pixel of this channel (a.k.a. colour weight).
!  */
! static unsigned
! calculate_mask_weight(uint32 mask)
! {
! 	unsigned weight = 0;
! 	do
! 	{
! 		weight += (mask & 1);
! 	}
! 	while (mask >>= 1);
! 	return weight;
! }
! 
! static BOOL
! select_visual()
  {
  	XPixmapFormatValues *pfm;
! 	int pixmap_formats_count, visuals_count;
  	XVisualInfo *vmatches = NULL;
  	XVisualInfo template;
! 	int i;
! 	unsigned red_weight, blue_weight, green_weight;
  
! 	red_weight = blue_weight = green_weight = 0;
! 
! 	pfm = XListPixmapFormats(g_display, &pixmap_formats_count);
! 	if (pfm == NULL)
  	{
! 		error("Unable to get list of pixmap formats from display.\n");
! 		XCloseDisplay(g_display);
  		return False;
  	}
  
! 	/* Search for best TrueColor visual */
  	template.class = TrueColor;
! 	vmatches = XGetVisualInfo(g_display, VisualClassMask, &template, &visuals_count);
! 	g_visual = NULL;
! 	g_no_translate_image = False;
! 	g_compatible_depth = False;
! 	if (vmatches != NULL)
  	{
! 		for (i = 0; i < visuals_count; ++i)
  		{
! 			XVisualInfo *visual_info = &vmatches[i];
  
! 			/* Try to find a no-translation visual that'll
! 			   allow us to use RDP bitmaps directly as ZPixmaps. */
! 			if (!g_xserver_be && (((visual_info->depth == 15) &&
! 					       /* R5G5B5 */
! 					       (visual_info->red_mask == 0x7c00) &&
! 					       (visual_info->green_mask == 0x3e0) &&
! 					       (visual_info->blue_mask == 0x1f)) ||
! 					      ((visual_info->depth == 16) &&
! 					       /* R5G6B5 */
! 					       (visual_info->red_mask == 0xf800) &&
! 					       (visual_info->green_mask == 0x7e0) &&
! 					       (visual_info->blue_mask == 0x1f)) ||
! 					      ((visual_info->depth == 24) &&
! 					       /* R8G8B8 */
! 					       (visual_info->red_mask == 0xff0000) &&
! 					       (visual_info->green_mask == 0xff00) &&
! 					       (visual_info->blue_mask == 0xff))))
! 			{
! 				g_visual = visual_info->visual;
! 				g_depth = visual_info->depth;
! 				g_compatible_depth = True;
! 				g_no_translate_image = (visual_info->depth == g_server_depth);
! 				if (g_no_translate_image)
! 					/* We found the best visual */
! 					break;
! 			}
! 			else
! 			{
! 				g_compatible_depth = False;
! 			}
  
! 			if (visual_info->depth > 24)
! 			{
! 				/* Avoid 32-bit visuals and likes like the plague.
! 				   They're either untested or proven to work bad
! 				   (e.g. nvidia's Composite 32-bit visual).
! 				   Most implementation offer a 24-bit visual anyway. */
! 				continue;
! 			}
  
! 			/* Only care for visuals, for whose BPPs (not depths!)
! 			   we have a translateXtoY function. */
! 			BOOL can_translate_to_bpp = False;
! 			int j;
! 			for (j = 0; j < pixmap_formats_count; ++j)
! 			{
! 				if (pfm[j].depth == visual_info->depth)
! 				{
! 					if ((pfm[j].bits_per_pixel == 16) ||
! 					    (pfm[j].bits_per_pixel == 24) ||
! 					    (pfm[j].bits_per_pixel == 32))
! 					{
! 						can_translate_to_bpp = True;
! 					}
! 					break;
! 				}
! 			}
! 
! 			/* Prefer formats which have the most colour depth.
! 			   We're being truly aristocratic here, minding each
! 			   weight on its own. */
! 			if (can_translate_to_bpp)
! 			{
! 				unsigned vis_red_weight =
! 					calculate_mask_weight(visual_info->red_mask);
! 				unsigned vis_green_weight =
! 					calculate_mask_weight(visual_info->green_mask);
! 				unsigned vis_blue_weight =
! 					calculate_mask_weight(visual_info->blue_mask);
! 				if ((vis_red_weight >= red_weight)
! 				    && (vis_green_weight >= green_weight)
! 				    && (vis_blue_weight >= blue_weight))
! 				{
! 					red_weight = vis_red_weight;
! 					green_weight = vis_green_weight;
! 					blue_weight = vis_blue_weight;
! 					g_visual = visual_info->visual;
! 					g_depth = visual_info->depth;
! 				}
! 			}
  		}
+ 		XFree(vmatches);
+ 	}
+ 
+ 	if (g_visual != NULL)
+ 	{
+ 		g_owncolmap = False;
+ 		calculate_shifts(g_visual->red_mask, &g_red_shift_r, &g_red_shift_l);
+ 		calculate_shifts(g_visual->green_mask, &g_green_shift_r, &g_green_shift_l);
+ 		calculate_shifts(g_visual->blue_mask, &g_blue_shift_r, &g_blue_shift_l);
  	}
  	else
  	{
! 		template.class = PseudoColor;
! 		template.depth = 8;
! 		template.colormap_size = 256;
! 		vmatches =
! 			XGetVisualInfo(g_display,
! 				       VisualClassMask | VisualDepthMask | VisualColormapSizeMask,
! 				       &template, &visuals_count);
! 		if (vmatches == NULL)
  		{
! 			error("No usable TrueColor or PseudoColor visuals on this display.\n");
! 			XCloseDisplay(g_display);
! 			XFree(pfm);
  			return False;
  		}
  
! 		/* we use a colourmap, so the default visual should do */
! 		g_owncolmap = True;
! 		g_visual = vmatches[0].visual;
! 		g_depth = vmatches[0].depth;
! 	}
  
! 	g_bpp = 0;
! 	for (i = 0; i < pixmap_formats_count; ++i)
! 	{
! 		XPixmapFormatValues *pf = &pfm[i];
! 		if (pf->depth == g_depth)
  		{
! 			g_bpp = pf->bits_per_pixel;
! 
! 			if (g_no_translate_image)
  			{
! 				switch (g_server_depth)
! 				{
! 					case 15:
! 					case 16:
! 						if (g_bpp != 16)
! 							g_no_translate_image = False;
! 						break;
! 					case 24:
! 						/* Yes, this will force image translation
! 						   on most modern servers which use 32 bits
! 						   for R8G8B8. */
! 						if (g_bpp != 24)
! 							g_no_translate_image = False;
! 						break;
! 					default:
! 						g_no_translate_image = False;
! 						break;
! 				}
  			}
  
! 			/* Pixmap formats list is a depth-to-bpp mapping --
! 			   there's just a single entry for every depth,
! 			   so we can safely break here */
! 			break;
  		}
  	}
+ 	XFree(pfm);
+ 	pfm = NULL;
+ 	return True;
+ }
  
! BOOL
! ui_init(void)
! {
! 	int screen_num;
! 
! 	g_display = XOpenDisplay(NULL);
! 	if (g_display == NULL)
  	{
! 		error("Failed to open display: %s\n", XDisplayName(NULL));
! 		return False;
  	}
  
  	{
! 		uint16 endianess_test = 1;
! 		g_host_be = !(BOOL) (*(uint8 *) (&endianess_test));
! 	}
! 
! 	g_xserver_be = (ImageByteOrder(g_display) == MSBFirst);
! 	screen_num = DefaultScreen(g_display);
! 	g_x_socket = ConnectionNumber(g_display);
! 	g_screen = ScreenOfDisplay(g_display, screen_num);
! 	g_depth = DefaultDepthOfScreen(g_screen);
! 
! 	if (!select_visual())
  		return False;
+ 
+ 	if (g_no_translate_image)
+ 	{
+ 		DEBUG(("Performance optimization possible: avoiding image translation (colour depth conversion).\n"));
  	}
  
+ 	if (g_server_depth > g_bpp)
+ 	{
+ 		warning("Remote desktop colour depth %d higher than display colour depth %d.\n",
+ 			g_server_depth, g_bpp);
+ 	}
+ 
+ 	DEBUG(("RDP depth: %d, display depth: %d, display bpp: %d, X server BE: %d, host BE: %d\n",
+ 	       g_server_depth, g_depth, g_bpp, g_xserver_be, g_host_be));
+ 
  	if (!g_owncolmap)
  	{
***************
*** 1073,1082 ****
  					AllocNone);
  		if (g_depth <= 8)
! 			warning("Screen depth is 8 bits or lower: you may want to use -C for a private colourmap\n");
  	}
  
  	if ((!g_ownbackstore) && (DoesBackingStore(g_screen) != Always))
  	{
! 		warning("External BackingStore not available, using internal\n");
  		g_ownbackstore = True;
  	}
--- 1230,1239 ----
  					AllocNone);
  		if (g_depth <= 8)
! 			warning("Display colour depth is %d bit: you may want to use -C for a private colourmap.\n", g_depth);
  	}
  
  	if ((!g_ownbackstore) && (DoesBackingStore(g_screen) != Always))
  	{
! 		warning("External BackingStore not available. Using internal.\n");
  		g_ownbackstore = True;
  	}
***************
*** 1129,1133 ****
  	xclip_init();
  
! 	DEBUG_RDP5(("server bpp %d client bpp %d depth %d\n", g_server_bpp, g_bpp, g_depth));
  
  	return True;
--- 1286,1290 ----
  	xclip_init();
  
! 	DEBUG_RDP5(("server bpp %d client bpp %d depth %d\n", g_server_depth, g_bpp, g_depth));
  
  	return True;
***************
*** 1690,1694 ****
  	int bitmap_pad;
  
! 	if (g_server_bpp == 8)
  	{
  		bitmap_pad = 8;
--- 1847,1851 ----
  	int bitmap_pad;
  
! 	if (g_server_depth == 8)
  	{
  		bitmap_pad = 8;
***************
*** 1722,1726 ****
  	int bitmap_pad;
  
! 	if (g_server_bpp == 8)
  	{
  		bitmap_pad = 8;
--- 1879,1883 ----
  	int bitmap_pad;
  
! 	if (g_server_depth == 8)
  	{
  		bitmap_pad = 8;



-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through log files
for problems?  Stop!  Download the new AJAX search engine that makes
searching your log files as easy as surfing the  web.  DOWNLOAD SPLUNK!
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=103432&bid=230486&dat=121642
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.