trouble with d.mon under linux

Carl Anderson candrsn at mindspring.com
Mon Mar 27 22:52:51 EST 2000


Andrea Bistacchi wrote:
> 
> Dear all,
> I just finished installing Grass5beta6 (intel PC with linux redhat 6.1),
> but when I try opening a window I get the following error:
> 
...
> can not allocate any read/write color cells
> Problem selecting x6. Will try once more
> 


run xdpyinfo (/usr/X11R6/bin/xdpyinfo)

scroll through the output looking for 
  depths (2):	1,8
this means you are running a 8 bit display

If this is not true ignore all of the rest of this message.

GRASS 24 bit XDRIVER has problems if:
    there is more than one visual
    the default colormap is not writeable 
    

I hacked this patch to run GRASS on some SUNS with 8 bit displays, and I 
tested it on a RH6.1 Linux using startx -- -bpp 8.
(I get the same results as you did when in 8 bit mode on XFree86)

inside your grass source
  cd to 
     src/display/devices/XDRIVER/XDRIVER24
and apply the attached patch
    patch -p1 < XD2.diff
then /usr/local/bin/gmake5 while in that directory

If all goes well, you should immediately be able to 
   d.mon start=x0  to you hearts delight.

As a bonus if you want to force TrueColor for your 8 bit 
Display (you are running XF86 3.3.5 and it supports multiple visuals)

set nlev to be -1
  d.mon start=x0 nlev=-1

on your 8 bit display you will not be able to see any difference
excepting that the color palette for the screen will be animated
as you enter the screen.

to compare 
  d.mon start=x0
and
  d.mon start=x0 nlev=-1
at the same time.

SUNs have overlays that allow multiple bit depths at the same time. ie
the
default visual is 8bit PsuedoColor but has 24bit TrueColor available.


DISCLAIMER:
This patch works for me but your results may vary.
I don't pretend that the code is pretty only functional (for me)

save the files 
	Graph_Set.c
	SWITCHER.c
	local_proto.h
	Clr_table.c
if you want to revert the changes 
or you can 
	patch -p1 -R < XD2.diff


Please email the results should you try the patch.


ATTENTION:
Markus Neteler,  this is not the patch I sent you over the weekend. 
This 
version searches for a TrueColor visual a bit harder before
dropping to the default Visual.


-- 
----------------------------------
E-Mail: candrsn at mindspring.com
Date: Wed, 03/27/2000 12:00:00 +0000 (GMT)

Flying Monkeys Usually Mean Trouble.
----------------------------------
-------------- next part --------------
Common subdirectories: XDRIVER24/CVS and XDRIVER24_new/CVS
diff -u XDRIVER24/Clr_table.c XDRIVER24_new/Clr_table.c
--- XDRIVER24/Clr_table.c	Sun Mar 26 09:37:12 2000
+++ XDRIVER24_new/Clr_table.c	Sun Mar 26 20:14:40 2000
@@ -193,14 +193,14 @@
 
 #endif /* ORIG */
 
-Colormap InitColorTableFixed (void)
+Colormap InitColorTableFixed (Colormap cmap)
 {
     float span;
     int r, g, b, i;
     unsigned char R, G, B;
     static int n_levels = 0;
     XColor xcolor;
-    Colormap cmap;
+/*    Colormap cmap;  */
 
     table_type = FIXED;
     /* figure out how many equal levels of r, g, and b are possible
@@ -218,7 +218,8 @@
 	/* allocate xpixels array */
 	xpixels = (u_long *) calloc(n_levels*n_levels*n_levels, sizeof(u_long));
     }
-    cmap = DefaultColormap(dpy, scrn);
+/*    cmap = DefaultColormap(dpy, scrn);  */
+
     /* Generate "fixed" color table */
     span = 255.0 / (float) (n_levels - 1);
     i = 0;
diff -u XDRIVER24/Graph_Set.c XDRIVER24_new/Graph_Set.c
--- XDRIVER24/Graph_Set.c	Sun Mar 26 09:36:55 2000
+++ XDRIVER24_new/Graph_Set.c	Mon Mar 27 22:19:05 2000
@@ -43,7 +43,7 @@
 
 int scrn = 0;
 GC gc;
-Colormap floatcmap, fixedcmap;
+Colormap floatcmap, fixedcmap = 0;
 Cursor grcurse, grxh;
 u_long gemask;
 XFontStruct *fontstruct;        /* Font descpritor */
@@ -72,11 +72,18 @@
     XWMHints *wmhints;
     XColor fg_color, bg_color, xcolors[256];
     char title[1024];
-
+    Visual	*use_visual = 0;
+    Display	*use_display = 0;
+    Depth	*use_depth = 0;
+    Screen	*use_screen = 0;    
+
+    int		result, use_bit_depth, use_depth_num;
+    XVisualInfo	*mvisual_info;
+        
     /* Open the display using the $DISPLAY environment variable to
      * locate the X server. Return 0 if cannot open. */
     if (!(dpy = XOpenDisplay(NULL))) {
-        fprintf(stderr, "Graph_Set: can't open %s\n", XDisplayName(NULL));
+        fprintf(stderr, "Graph_Set: can't open Display %s\n", XDisplayName(NULL));
         return 0;
     }
     scrn = DefaultScreen(dpy);
@@ -104,40 +111,110 @@
      ***************************************************************/
 /*  NCOLORS = DisplayCells(dpy, scrn) ; */
 
-    if (DefaultVisual(dpy,scrn)->class==TrueColor) {
+    use_screen = ScreenOfDisplay(dpy, scrn);
+
+/*  try each depth available on the default screen 
+ *   looking for a depth that can run TrueColor 
+ *   be desirous of an 24 bit depth display
+*/  
+    use_visual = 0;
+    
+/*	The Following line dead loops under XFree85 3.3.5 if the bit depth is 
+/*	16 or 8 bits.  The same is not true under SUN openwin.		*/
+/*    result = XMatchVisualInfo (dpy, scrn, 24, TrueColor, mvisual_info);
+/*    if ( result != 0 ) {
+/*      use_visual = mvisual_info->visual;
+/*      use_bit_depth = mvisual_info->depth;
+/*      scrn = mvisual_info->screen;
+/*      fixedcmap = XCreateColormap(dpy, DefaultRootWindow(dpy), use_visual, AllocNone); 
+/*    }  
+*/
+
+   if ( nlev == -1 )
+   {
+    int num_visuals;
+    int search_mask = VisualClassMask;
+    int highest_bit_depth = 0;
+    int vis_num;
+
+    XVisualInfo search_template;
+
+    search_template.class = TrueColor;
+
+    mvisual_info  = 
+	XGetVisualInfo(dpy, search_mask, &search_template, &num_visuals );
+
+    printf ("found %d visuals of TrueColor type... searching for highest bit depth \n", num_visuals);
+    for ( vis_num = 0; vis_num < num_visuals; vis_num++ )
+    {
+	if ( mvisual_info[vis_num].depth > highest_bit_depth )
+        {
+          use_visual = mvisual_info[vis_num].visual;
+	  scrn = mvisual_info[vis_num].screen;
+	  use_bit_depth =  mvisual_info[vis_num].depth;
+	  highest_bit_depth = use_bit_depth;
+          fixedcmap = XCreateColormap(dpy, DefaultRootWindow(dpy), use_visual, AllocNone);
+	  nlev = mvisual_info[vis_num].colormap_size;  
+ 	}
+    }
+    XFree (mvisual_info);
+    }
+
+    if ( nlev == -1 )
+    {
+      nlev = 32;
+    }
+
+/*  If We can't find the visual class secified above then drop to the 
+/*  DefaultVisual							*/  
+    if ( use_visual == 0 ) {
+      printf ("unable to find a desired visual, ... using default \n");
+      use_bit_depth = DefaultDepth (dpy, scrn);
+      use_visual = DefaultVisual (dpy, scrn);  
+    }  
+
+    if (use_visual->class==TrueColor || use_visual->class==DirectColor ) {
 #ifndef ORIG
-      theVisual = DefaultVisual(dpy,scrn);
+      theVisual = use_visual;
 #endif /* ORIG */
       truecolor++;
       fprintf(stderr,"got a TrueColor (Read-Only!) Visual\n");
-#ifndef ORIG
-      fprintf(stderr,"ncolors: %d\n",nlev * nlev * nlev);
-      fprintf(stderr,"allocating memory...\n");
-#endif /* ORIG */
-    }
 
-    if (truecolor) {
 #ifdef ORIG
       NCOLORS=256;
 #else /* ORIG */
       NCOLORS=nlev*nlev*nlev; 	
+
+#endif /* ORIG */
+#ifndef ORIG
+      fprintf(stderr,"ncolors: %d\n",NCOLORS);
+      fprintf(stderr,"allocating memory...\n");
 #endif /* ORIG */
+
     } else {
       NCOLORS = GetRealNumberOfColors(dpy, scrn) ;
 #ifdef ORIG
        fprintf(stderr,"Found %d colors on Display\n",NCOLORS);
 #endif /* ORIG */
+      NCOLORS = use_visual->map_entries;
       if (!NCOLORS) {
 	fprintf(stderr,"can not allocate any read/write color cells\n");
 	exit(1);
       }
     }
-
+    
     bg_color.pixel = BlackPixel(dpy, scrn);
     fg_color.pixel = WhitePixel(dpy, scrn);
     XQueryColor(dpy, DefaultColormap(dpy, scrn), &bg_color);
     XQueryColor(dpy, DefaultColormap(dpy, scrn), &fg_color);
-    fixedcmap = InitColorTableFixed();
+    if ( fixedcmap  == 0 ) {
+      fixedcmap = DefaultColormap(dpy, scrn); 
+    }
+    fixedcmap = InitColorTableFixed(fixedcmap); 
+
+/*  Below Here there should no more use DefaultXxxxxx routines from X   */
+/*  Just in case we dont want to use the Defaults 			*/
+
 
     if (!truecolor) {
       (void) XAllocColor(dpy, fixedcmap, &bg_color);
@@ -145,8 +222,8 @@
 
     /* Allocate floating colormap and set with b/w stripes */
 
-      floatcmap = XCreateColormap(dpy, DefaultRootWindow(dpy),
-				  DefaultVisual(dpy, scrn), AllocAll);
+      floatcmap = XCreateColormap(dpy, use_screen->root,
+				  use_visual, AllocAll);
       for (i = 0; i < NCOLORS; i++) {
         xcolors[i].pixel = i;
       }
@@ -185,10 +262,10 @@
     /* Create the Window with the information in the XSizeHints, the
      * border width,  and the border & background pixels. */
 
-    grwin = XCreateWindow(dpy, DefaultRootWindow(dpy), szhints->x,
+    grwin = XCreateWindow(dpy, RootWindow(dpy, scrn), szhints->x,
             szhints->y, (unsigned)szhints->width, (unsigned)szhints->height, 
-			BORDER, DefaultDepth(dpy, scrn),
-			InputOutput, DefaultVisual(dpy, scrn),
+			BORDER, use_bit_depth,
+			InputOutput, use_visual,
 			(CWEventMask | CWBackingStore | CWColormap | CWBorderPixel |
 			CWBackPixel), &xswa);
 
diff -u XDRIVER24/SWITCHER.c XDRIVER24_new/SWITCHER.c
--- XDRIVER24/SWITCHER.c	Fri Feb  4 03:54:43 2000
+++ XDRIVER24_new/SWITCHER.c	Mon Mar 27 22:33:46 2000
@@ -189,7 +189,8 @@
 	fprintf(stderr,"Nlev is zero, resetting to 32\n");
 	nlev=32;
     }
-    if ( nlev < 0 ) {
+/* pass nlev=-1 to Graph_Set as a flag to try to force TrueColor  */;
+    if ( nlev < -1 ) {
 	fprintf(stderr,"Nlev is negative, resetting to 32\n");
 	nlev=32;
     }
diff -u XDRIVER24/local_proto.h XDRIVER24_new/local_proto.h
--- XDRIVER24/local_proto.h	Sun Mar 26 20:16:03 2000
+++ XDRIVER24_new/local_proto.h	Sun Mar 26 20:14:41 2000
@@ -4,7 +4,7 @@
 int can_do_float(void);
 /* Clr_table.c */
 int Color_table_float(void);
-Colormap InitColorTableFixed(void);
+Colormap InitColorTableFixed(Colormap cmap);
 int Color_table_fixed(void);
 /* Draw_line.c */
 int draw_line(int, int, int, int);
Common subdirectories: XDRIVER24/old and XDRIVER24_new/old


More information about the grass-user mailing list