[comp.windows.x] Allocating color cells on a DEC5000pgx

bmc@bmw.mayo.EDU (02/01/91)

Given the following workstation:
	DEC5000pgx
	Ultrix 4.1 & DECwindows

The following code failes (i.e. xncolors becomes = to 0):

cmap = XCreateColormap (display, window, visual, AllocNone);
xncolors = (unsigned int)visual->map_entries;
while (!XAllocColorCells (display, cmap, True, xplane_masks, 8, xpixels,
        xncolors)) {
	fprintf (stderr,"failed to allocate %d colorcells trying %d\n",xncolors,
		 xncolors-1);
	xncolors--;
	}
xmaxcolor = xncolors;

I am trying to find the maximum number of color cells I can get for my
application. According to xdpyinfo, if I use a PseudoColor visual I
should be able to get a maximum of 256 color cells and 8 planes.

I request a visual via:

vtemplate.class = PseudoColor;
vtemplate.depth = G_bits;
vtemplate.screen = DefaultScreen(display);
vlist = XGetVisualInfo (display, VisualScreenMask | VisualClassMask |  
                        VisualDepthMask, &vtemplate, &visuals_matched);

and set my window's visual to vlist[0] if the call is successful.

Can any kind soul point out what I am doing wrong? I need to get as
many colorcells as possible, yet still be kind to other applications
that may be running. Many thanks in advance for any and all aid.

--Bruce

-----------------------------------------------------------------
Bruce M. Cameron                                 bmc@mayo.edu
Biotechnology Computing Resource                 (507) 284-3288
Medical Sciences 1-14                            
Mayo Foundation
Rochester, MN 55960                              WD9CKW
-----------------------------------------------------------------

mouse@lightning.mcrcim.mcgill.EDU (02/06/91)

> Given the following workstation:
> 	DEC5000pgx
> 	Ultrix 4.1 & DECwindows

> The following code failes (i.e. xncolors becomes = to 0):

> cmap = XCreateColormap (display, window, visual, AllocNone);
> xncolors = (unsigned int)visual->map_entries;
> while (!XAllocColorCells (display, cmap, True, xplane_masks, 8, xpixels,
>         xncolors)) {
> 	fprintf (stderr,"failed to allocate %d colorcells trying %d\n",xncolors,
> 		 xncolors-1);
> 	xncolors--;
> 	}

From the Xlib document:

	The XAllocColorCells function allocates read/write color cells.
	[...] If ncolors and nplanes are requested, then ncolors pixels
	and nplane plane masks are returned.

In your case, ncolors is xncolors and nplanes is 8.

	No mask will have any bits set to 1 in common with any other
	mask or with any of the pixels.  By ORing together each pixel
	with zero or more masks, ncolors * 2^nplanes distinct pixels
	can be produced.

In other words, asking for 8 planes essentially asks for the whole
colormap.  You probably want to ask for 256 pixels and 0 planes.  (If
XAllocColorCells fails for 8 planes and 1 pixel, either your server is
reserving a cells or two (eg, for the cursor) or there's a bug.)

> I am trying to find the maximum number of color cells I can get for
> my application.

You almost certainly want to ask for 0 planes and xncolors pixels, then.

> According to xdpyinfo, if I use a PseudoColor visual I should be able
> to get a maximum of 256 color cells and 8 planes.

> I need to get as many colorcells as possible, yet still be kind to
> other applications that may be running.

That's a bit of a contradiction in terms.  If you want to avoid other
applications going technicolor, you must allocate out of the default
colormap.  (The next best thing would be to use a standard colormap,
but that will probably still technicolor dumb applications that
allocate a couple of read-only cells in the default map and nothing
else, xterm for example.)  If you create your own colormap, you can
fill in the whole thing; you don't have to worry about conflicts with
other applications.  (You can create it with AllocAll instead of
AllocNone, if you want, which automatically allocates the whole map to
you at creation time.)  In this case, though, everything else will
presumably go technicolor when the window manager gives your window
colormap focus.

					der Mouse

			old: mcgill-vision!mouse
			new: mouse@larry.mcrcim.mcgill.edu