[comp.windows.x] XImage help

jwz@lucid.com (Jamie Zawinski) (04/07/91)

Say I've got an XImage structure that I've read from a file.
What's the best way to display that in a window, when the 
current display doesn't necessarily have the same depth as
the XImage does?  Let's assume the display is at least as
deep as the image.

I am under the (hopefully mistaken!) impression that I have to
do a pixel-by-pixel iteration, copying one image into another,
in order to do do this.  But I can't get that to work either;
this code corrupts the image (slants it, lines too long...)

    new_image = XCreateImage(dpy,
			     DefaultVisual(dpy, scr),
			     DefaultDepth(dpy, scr),
			     ZPixmap, old_image->xoffset,
			     XtMalloc(old_image->bytes_per_line *
				      old_image->height *
				      old_image->depth),
			     old_image->width, old_image->height,
			     old_image->bitmap_pad,
			     old_image->bytes_per_line);
    for (r = 0; r < old_image->height; ++r)
      for (s = 0; s < old_image->width; ++s)
	 XPutPixel (new_image, s, r, XGetPixel(old_image, s, r));

I tried XYPixmap as well, same effect.  What am I doing wrong?

		-- Jamie

ch@siet02.sietec.de (Chitty) (04/10/91)

Thanks for the suggestions.  Passing in bytes-per-line as 0 fixed the skewing
problem.  Then there was a bit/byte-order problem which I fixed by tweaking
the appropriate slots in the image.  Now I'm still fighting with the colors,
though.  Like, I'm allocating the right colors (with XAllocColor), and
remapping the image to have pixel values that correspond to the cmap cells
that wee allocated, but it's still using the wrong colors.  
	
Hint
====
      Have a close look at your bits_per_rgb for your X Server. Thus the
server will use only the significant bits as specified in this field.
Set your color map based on these entry. All the best
for e.g. depth = 8 and bits_per_rgb = 4
  bit configuration will be
  
  X X X X V V V V

  X - Don't Care
  V - Valid Bits

Thus one can have only 16 different entries.
 

===================================================================
Name : Chittaranjan Keswani        Sietec, West Berlin
Address : ch@siet02.sietec.de      (Internet)
          ..!sietec1!siet02!ch@unido.uucp (UUCP)
===================================================================

mayoff@cs.utexas.edu (Robert Mayoff) (04/11/91)

In article <JWZ.91Apr7030728@thalidomide.lucid.com> jwz@lucid.com (Jamie Zawinski) writes:
>Say I've got an XImage structure that I've read from a file.
>What's the best way to display that in a window, when the 
>current display doesn't necessarily have the same depth as
>the XImage does?  Let's assume the display is at least as
>deep as the image.

I haven't tried this yet (although I'm working on a program with a
similar problem, so I will soon), but I'd suggest that you simply
create a pixmap with the same depth as the image, and XPutImage to that
auxiliary pixmap.  Then just XCopyPlane from the auxiliary pixmap to
your window.
-- 
/_  rob		<mayoff@cs.utexas.edu>
 /_ Fun things to do with UNIX (#2 in a series):
  / echo "rsh `hostname` -n source eat.cpu &" > eat.cpu; source eat.cpu