[comp.windows.x] help with colormaps

anderdla@CS.UOREGON.EDU (02/25/90)

First of all, I don't read this newsgroup so don't flame me if I'm 
dredging up an old topic.

I am having troubles with colormaps.  What I am working on is an
application that will display run-length-encoded files (ala Utah).
We have getX11, but this program uses the default colormap and 
dithering to accomplish the imaging.  I actually want to analyze the
colors in the picture and construct a colormap on the fly.  Constructing
the colormap is not a problem.  I can't figure out how to use it.  I have
tried two things:

i)  cmap=XCreateColormap(display,window,visual,AllocAll);

	Whenever I use AllocAll in this call it does something funky
	to display.  The side effect is that it bombs when it hits
	XNextEvent(display,&e).  Reason?

ii) cmap=XCreateColormap(display,window,visual,AllocNone);

	Now how do I allocate colorcells?  The XStoreColors and
	XInstallColormap calls work fine, but when I try using these
	colors they're private(this makes sense to me, I need to
	acquire some of these cells for my own private use, right?).

	It seems that XAllocColorCells is too complicated for my
	purposes.  What's all the plane_masks crap for?  All I want
	is a given number of cells (say 256) and their pixel numbers
	that I can assign RGB values to in the colormap.  There must
	be an easy way to do this!

By the way, I was reading in the Xlib programming manual by Nye that you
can specify 0 for nplanes and ncolors for the number of cells you want and
it will give you that many cells w/o the bullshit.  It didn`t seem to work
for any value of ncolors (I put it in a loop from 256 down to 0).  This
is on p. 189 of the book in case anyone wants to double check or refute
(I wish you would!) this.

Finally, when I actually do get around to building the virtual colormap
successfully, do I use XInstallColormap or XSetWindowColormap?  In case
you need to know, we are running X11/NeWS and OpenWindows on Sun Sparcs
(Sun4).

Thanks in advance for any assisstance.


--------------------------------------------------------------------

                   ______  ___                       
Darren Anderson     \     \  |    _       anderdla@cs.uoregon.edu
1656 Walnut St.      |     | |   / \                   
Eugene, Ore. 97403   |     | |  /___\      "MTV is like this very
                    /_____/  | /     \      big advertising agency,
                            /______   \     and its only client is 
                           /       \   \    itself."
                                                      
--------------------------------------------------------------------

converse@EXPO.LCS.MIT.EDU (Donna Converse) (02/27/90)

> Constructing the colormap is not a problem.  I can't figure out how to
> use it.  I have tried two things:
> 
> i)  cmap=XCreateColormap(display,window,visual,AllocAll);
> 
> 	Whenever I use AllocAll in this call it does something funky
> 	to display.  The side effect is that it bombs when it hits
> 	XNextEvent(display,&e).  Reason?

Hmmm.... Does something funky to display.... bombs....   hmmm...  my crystal
ball suggests that perhaps you're specifying a visual type that doesn't 
allow read/write allocation. Try reading about visuals, try using the function
XGetVisualInfo or XMatchVisualInfo, try looking for error messages and try using
a debugger.


> ii) cmap=XCreateColormap(display,window,visual,AllocNone);

      with the following (paraphrased by the answerer):
      XAllocColorCells(display, cmap, False, NULL, 0, pixels, ncolors);

> It didn`t seem to work
> for any value of ncolors (I put it in a loop from 256 down to 0).

Maybe the colormap was created with a visual type that doesn't allow read/write
allocation from the colormap.  


> Finally, when I actually do get around to building the virtual colormap
> successfully, do I use XInstallColormap or XSetWindowColormap?

XSetWindowColormap.


Donna Converse
converse@expo.lcs.mit.edu

kent@wsl.dec.com (Christopher A. Kent) (02/28/90)

I'm pretty sure that the default Visual for X11/NeWS is StaticColor,
which means that colormaps are not changeable. Try to find a PseudoColor
Visual and use that.

Chris Kent	Western Software Laboratory	Digital Equipment Corporation
kent@decwrl.dec.com	decwrl!kent			(415) 853-6639

BUCKHOLTZ_G%RMC.CA@mitvma.mit.EDU (06/25/91)

Hi!
      I have been experiencing problems with setting the colormap
resource on my Motif Widgets. My goal is to make a gray scale
colourmap for my image processing application. I create a colourmap
with the following command:
cmap = XCreateColormap(dpy,win,vix,AllocAll);

      I then try to set the colormap resource using XtSetValues.
When I do this I get the following error:
X Toolkit Warning: Cannot allocat colomap entry for "white"
X Protocol error: BadValue, integer parameter out of range for operateio
Major opcode of failed request: 91 (X_QueryColors)
Minor opcode of failed request: 0
Resource ik in failed request: 0x7537dc08
Serial number of failed request: 724
Current serial number in output stream: 724

      I can buy the warning that a colormap entry "white" cannot
be allocated since I have declared that I have allocated all of the
colour cells when I created the colourmap. I don't know what could
be generating the BadValue error though.

      Any hints or thoughts are appreciated.

                  bye,
                        Glenn