[comp.windows.x] Allocating 256 color cells

kjartan@raunvis.UUCP (Kjartan Pierre Emilsson Jardedlisfraedi) (06/14/88)

Hi

  I am writing an application in X to be able to control and change the
color table of a vt100 (X server) interactively whilst viewing a picture or
running a graphic program.  The application is mouse driven and independent
of any process that might be running at the same time.
  The program works pretty well except for a little bug which has annoyed me
a lot.  The problem is that when I try to allocate more than 249 color cells
the allocating routine returns pixel value 0 for all color cells.  It is
just as if the first 8 pixel values (0-7) were fixed as read-only color
cells.  I think that this same bug shines through the GKS system we are
using (as it is written in X), but there it manifest itself in such a manner
that trying to use pixel values higher than 245 results in an illegal color
index error.  Does anyone have any idea what is going on here, and if so how
one should proceed to allocate 256 color cells ?

		Thanks in advance.

...........................................................................    

    "If you don't like what your left hemisphere thinks, shoot if off."

			Kjartan Pierre Emilsson, Iceland.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

jim@EXPO.LCS.MIT.EDU (Jim Fulton) (06/16/88)

Deja vu.

The default colormap will always have at least colors preallocated for
BlackPixel and WhitePixel.  In addition, if you are already running any
applications (such as a couple of xterms, an xclock, an xload, a window
manager, etc.), they will most likely have also allocated some color cells
out of the default colormap.  So, you won't probably won't be able to 
allocate more than NCELLS-10 (or so, where 10 is the number of cells that
existing applications have grabbed already; your mileage may vary).

So, if you want to allocate all of the colormap cells, you'll need to 
create a new colormap.  From last Friday's note:

>        visual = /* select the proper visual if DefaultVisual isn't right */
>        cmap = XCreateColormap (dpy, RootWindow (dpy, scr), visual, All);
>
> The visual determines what sort of colormap should be allocated.  This is 
> necessary for running on displays that provide more than one type of window
> (for example: 24 bit DirectColor and 16 bit PseudoColor, or 8 bit PseudoColor
> and 1 bit StaticGray).

Useful readings:
	Xlib manual, Section 3.1, Visual Types
		     Section 5.1, Colormap Functions
		     Section 9.2, Manipulating Standard Colormaps
	ICCCM

This topic clearly needs to be added to the list of Tutorials to be written....

Jim Fulton
MIT X Consortium