Re: XForms: XPutImage and Xforms; Please Help ME!!!!

Steve Lamont (
Thu, 16 Oct 97 06:50:08 PDT

To subscribers of the xforms list from (Steve Lamont) :

> How can I view an image (Ximage) using "XPutImage" (Xlib) inside a Free
> Objetc or (new object classes) and using the internal Color Map of
> Xforms???

You should be able to just call XPutImage() directly. Just figure out
where in the Free Object you're going to display your image, calculate
the coordinates relative to the origin of the Form, and do it. If
you don't have a TrueColor Visual available, they you're going to have
do deal with converting your colors in your image into color indices.
The Colormap is available in the fl_state structure for the active

Refer to the writeup on color in the Drawing Objects chapter of the
manual for details on translating between X colors and XForms colors.

You may have to deal with color quantization if you're dealing with
images that have more colors than are available in the XForms
colormap. See the excellent article "A Simple Method for Color
Quantization: Octree Quantization" by Michael Gervautz and Werner
Purgathofer in Graphics Gems (first volume), pp. 287-293, for more
exposition on this topic than I can provide here.

Finally, you may wish to consider creating an offscreen Pixmap for
your image or images if the server has sufficient resource to handle
them. You can then use XPutImage() to write the image data to the
Pixmap rather than to Free Object directly. You would then use
XCopyArea() to copy the contents of the Pixmap to the Free Object.
The advantage of this two step process is that when you have to redraw
the same image for some reason (Expose events, etc.) you do not have
to push the pixels from the client (your application) and the server
again. Pixmaps stay on the server side of the connection and are
copied by the server in a generally very efficient manner (perhaps
hardware BITBLT whereas XPutImage() has to grovel through the innards
of Xlib, through the connection, and finally through all the server

Another possible approach, by the way, is to use a Canvas rather than
a Free Object. If you create a Pixmap as briefly outlined above, you
can then attach the Pixmap to the Canvas's Window by setting the
Background Pixmap attribute of the Window. The advantage to this
approach is that the server handles redrawing the Pixmap to the Window
for you with no intervention on the part of the client.


To unsubscribe, send the message "unsubscribe" to or see
Xforms Home Page:
List Archive: