[comp.windows.x] Colormap problems with R3

ddickey@gonzo.eta.com (Dan A. Dickey) (11/09/88)

Hello, I'm having some problems with changing the colormap in my program.
Here is what I'm doing:
	XCreateColormap()
	XAllocColorCells()
	XStoreColors()
	XSetWindowColormap()
	XInstallColormap()
	XPutImage()

At this point, when I get Colormap.UninstalledEvent, I call XInstallColormap()
again.  First problem is that uwm keeps removing my colormap.  So I killed
uwm on that screen.  Q1: I'd rather have uwm around, anyway to tell it not
to worry about the colormap, that I'll change it back when I'm done?

Anyways, when uwm is around and creating havok for me, my window uses
the default colormap when my mouse is NOT in my window, but just pointing
at the root or somewhere else.  When I move the mouse into my window, the
whole window goes black.  Or off.  I can't tell which.  Q2: Anyone know
anything about this?

At the moment, I suspect some problem with the GC used in my XPutImage()
call.  The image I'm putting is a ZPixmap, depth 8, etc, etc...a Sun cgfour.
The GC foreground is 0, color "white".  The background is 1, color "black".
The particular color map I'm creating is an attempt to duplicate monochrome
on the color screen, with the various pixels between 2-255 either white
or black, according to some formula.  The reason for this is that then it
is very easy to map mandelbrot sets of 256 iterations to these various
"colors".
If you feel you can help me, please do so.  If you need some more information
to help you out, I'd be glad to give it to you.  Mail to:
	ddickey@gonzo.eta.com		-Dan A. Dickey

BTW:  XPutPixel() is EXTREMELY slow to call for images of any significant
size (800 x 800), at least on Sun type hardware (Big-endian are they?)
as the code in XImUtil.c swaps everything around all over the place ANY
time it needs to do something.   I've produced a new Set8Pixel() that
takes the place of XPutPixel() for my "particular" application...it reduced
my time of createing a 512 x 512 image from over 3 minutes to under 10 seconds.
Best thing of all is, no assembly code.  This is for REAL monochrome screens.
Color is even simpler, in my "particular" application.
Dan A. Dickey    ddickey@gonzo.eta.com

ddickey@gonzo.ETA.COM (Dan A. Dickey) (11/09/88)

In article <835@nic.MR.NET> I wrote:
>whole window goes black.  Or off.  I can't tell which.  Q2: Anyone know
       ^^^^^^  I meant screen.  The Whole SCREEN goes black, or off.
Dan A. Dickey    ddickey@gonzo.eta.com

ddickey@gonzo.ETA.COM (Dan A. Dickey) (11/09/88)

Some more information here....

It seems I can't store colors into my colormap.  Or can't query them,
I'm not real sure.  Here is what's happening:

	mono_cmap = XCreateColormap(d, w, defaultvisual, AllocAll);
I get a valid map back.
Since I have AllocAll on, XAllocColorCells(...) fails, presumably this
is ok.  I used to do AllocNone and XAllocColorCells() would work, but according
to the source, it looked like this allocated read-only cells.
So, I no longer allocate color cells, I'm assuming that the AllocAll in
the XCreateColormap() does this for me.

I go on and:
	XStoreColor(d, mono_cmap, &def[i]);
256 times...after setting up def of course.  No failures here that I can see.
pixel 0 has red, green, and blue set to 255.
pixel 1 has red, green, and blue set to 0.

Then, I query pixel 0 and pixel 1:
	XQueryColor(d, mono_cmap, &def[0]);
	XQueryColor(d, mono_cmap, &def[1]);
The red, green, and blue values are zero!  (flags looks right though)


Q3:  What is going on?  Where is my mistake? 
Dan A. Dickey    ddickey@gonzo.eta.com

ddickey@gonzo.ETA.COM (Dan A. Dickey) (11/09/88)

In article <837@nic.MR.NET> ddickey@gonzo.UUCP (Dan A. Dickey) writes:
>Some more information here....
>pixel 0 has red, green, and blue set to 255.
>pixel 1 has red, green, and blue set to 0.

Ha! Silly me...this is what I get for copying suntools pixrect code.
All my values needed to be multiplied by 256.  Somewhere down the
line they get divided by 256.  Everything resulting in 0.  All black.
voila!

>Q3:  What is going on?  Where is my mistake? 
I Did RTFM...but, it also help to understand it.  It probably took me about
5 times reading the same page...the one about RGB values between 0 and 64K.

Anyways...thanks for all your help.
Dan A. Dickey    ddickey@gonzo.eta.com

keith@EXPO.LCS.MIT.EDU (Keith Packard) (11/09/88)

> Hello, I'm having some problems with changing the colormap in my program.
> Here is what I'm doing:
>
>	XCreateColormap()
>	XAllocColorCells()
>	XStoreColors()
>	XSetWindowColormap()
>	XInstallColormap()
>	XPutImage()


The window manager is responsible for managing shared resources
in the server (like screen real-estate, colormaps and the keyboard).

To support this, some support was put into uwm to manage colormaps.  It's
pretty primitive as the ICCCM isn't ready yet.  All that it does
is notice colormap change events on top-level windows and track the
keyboard focus, installing the colormap for the current window.

If you simply remove the XInstallColormap call from your application,
uwm will automatically notice the colormap change for the window and
act accordingly.

Problems arise when the colormap you created is not associated
with the top-level window.  Simply make the top-level window
*also* use the new colormap and uwm will play ball.  The ICCCM will
address this issue directly, and propose mechanisms for managing
different colormaps for sub-windows.

Unfortunately, no other window managers track colormaps, so you
might want to add code which optionally installs the new
colormap (bleah).  Eventually, you should expect all window managers
to conform to the ICCCM proposal, in which case you would never
call XInstallColormap in an application.

						Keith Packard
						MIT X Consortium
						(617) 253-1428
						keith@EXPO.LCS.MIT.EDU