[comp.windows.x] pixels -> Pixmap

kmont@hpindda.HP.COM (Kevin Montgomery) (05/26/89)

	A slight thought question:  You have an array of pixel values
called pic[MAX_X, MAX_Y] that contain values 0-63.  The value 0 corresponds
to black, the value 63 corresponds to white, and there is a grey-scale 
in-between.  You know how the set the colormap to the grey scale, so the
values in the array map directly to lookup table values.  The question
is:  Using X11, what is the best way to put these values into a pixmap
to display.  There are a few options:

	1) play data manipulation games to massage the data into a 
	   Pixmap structure.

	2) create 63 images for pixel values, then store these in the 
	   pixmap using XPutImage().

	3) allocate enough space in the pixmap and use XSetBackgroundPixel()
	   for each pixel.

	4) bag the pixmap idea and write directly to a window.

	5) bag the whole idea and follow the Bagwan.

I'd like to think (1) was the answer, but writing the routines could be
a bitch, especially when one only has the XLib Programming Ref as a doc.
If (1) is the way to go, does someone have a function laying around that'll
do such a conversion?  Is there a way I'm missing?  Given that this is such 
an easy problem, I'd think it should be easy to do, but in practice...

					thanks in advance,
					  kevbop

rws@EXPO.LCS.MIT.EDU (05/26/89)

You probably want to get the data into an XImage structure.  Then you
can either XPutImage (parts of) it directly into a window each time you
need it, or you can XPutImage it into a pixmap and then XCopyArea out
of that when you need to.

The XImage interface is, uh, broken (to be polite).  After you call
XCreateImage, you may have to manually frob some structure components,
depending on exactly what your data format is.  Read through Section 10.9
of the Xlib manual.  You can either try to create an image with the
"natural" format of your array, or you can create an image and then
use XPutPixel to fill it.  If your image format doesn't match the server's,
there will be a conversion cost paid in each XPutImage.  Which route is
better depends on how many times you expect to call XPutImage.