[comp.windows.x] Viewing 8-bit grayscale images via libXView

rowe@cme.nist.gov (Walter Rowe) (12/05/90)

I have flat binary files (not sun rasterfiles) which are images in
8-bit grayscale.  I want to be able to view these images in a canvas
created via XView.  I have the canvas, et al, on the screen but can't
seem to get the images to appear in the window.

Can someone who has done something like this lend me a hand?  I would
*greatly* appreciate it.

Basically, I want to read in this file of 8-bit grayscale values and
slap it into the canvas.  Do I need to create a ColorMap Segment (CMS)
and associate it with the window?  Do I need to use XCreateImage()?
Am I even close?  Once the picture is in there, I merely want to click
the mouse SELECT button to see the actual value of a pixel at the
current mouse position.  I have this much, but can't make the images
show up in the canvas.

Help?

adv{THANKS}ance

wpr
---
Walter Rowe           rowe@cme.nist.gov         ...!uunet!cme-durer!rowe

cflatter@ZIA.AOC.NRAO.EDU (Chris Flatters) (12/06/90)

> Basically, I want to read in this file of 8-bit grayscale values and
> slap it into the canvas.  Do I need to create a ColorMap Segment (CMS)
> and associate it with the window?  Do I need to use XCreateImage()?
> Am I even close? 

The natural way to do this is to:

1: Create a canvas with the WIN_DYNAMIC_VISUAL attribute set to TRUE
   and CANVAS_X_PAINT_WINDOW set to TRUE.

2: Create a 256-colour CMS, fill it with a linear ramp and associate
   it with your canvas.

3: Create an Image structure with XCreateImage().  Note that the image
   depth should match the depth of the canvas.  Do not assume 8 if
   you want your code to be portable.  Use ZPixmap format.
   
4: Fill in the image data.  Note that if your file contains a pixel
   value p then the corresponding pixel value in the image data should
   be cms_index_table[p] where cms_index_table is the array correspomding
   to the CMS_INDEX_TABLE attribute of your CMS.  In the case of an 8-bit
   display the mapping should be trivial but it would be unwise to
   count on it.  You should normally use XPutPixel to set the pixel
   values but you might want to check for the special case of 8-bit
   displays and optimize that by inserting the pixels directly into
   the image data array (avoiding XPutPixel for other depths is
   sufficiently complicated that it generally isn't worth the effort).

5: Call your canvas repaint procedure.

Your canvas repaint procedure should call XPutImage() to display the
image to the canvas paint window(s).

You can also use the X colour model directly if you do not want to
mess with the CMS package: there is nothing to stop you associating
a colormap with the canvas paint window.  This is sometimes useful
as it gives you rather more control over what is happening.

Finally, if you do the above, the CMS for your canvas will obliterate
everything else on the screen when it gets swapped in.  You might want
to consider compressing the output range to be more sociable.

			Chris Flatters