[comp.windows.x] Need help creating a standard gray colormap

wschmidt@cs.tamu.edu (William M Schmidt) (04/07/91)

I have an application that needs a gray level colormap and I'm having some
problems creating one.

To see if one is available I use:

int status;
XStandardcolormap gray-info;
Colormap gray_colormap;
XColor *grays;
...
status = XGetStandardColormap(display, window, &gray_info, XA_RGB_GRAY_MAP);

if ( !status )
     ... code to install the colormap. No problem.
  else
    {
      gray_colormap = XCreateColormap(display, window, visual, AllocAll);
      grays = (XColor *)calloc(ncolors, sizeof(XColor));

      for ( i = 0; i < ncolors; i++ )
	{
          grays[i].pixel = (unsigned long) i;
          intensity = (65536 / (1 << depth) ) * i - 1;
	  grays[i].red = grays[i].green = grays[i].blue = intensity;
          grays[i].flags = DoRed | DoGreen | DoBlue;
	}

      XStoreColors(display, gray_colormap, grays, ncolors);

      gray_info.colormap = gray_colormap;

      XSetStandardColormap(display, root_window, &gray_info, 
			   XA_RGB_GRAY_MAP);
      XSetWindowColormap(display, root_window, gray_colormap);
    }
...

My problem is that I thought that even if the standard colormap didn't
exist, i.e. gray_info.colormap = 0 after the XGetStandardColormap() that
the other fields in gray_info would be filled. This doesn't seem to be
happening. How do I determine *_max, *_mult and the base_pixel values?
Using 2^depth for red_max and setting red_mult = 1 and base pixel = 0
doens't work. By the way, before I do this I check that visual is a
dynamic visual. What am I missing?

				Bill