home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.windows.x
- Path: sparky!uunet!noc.near.net!gateway!pictel!oj
- From: oj@pictel.com (Oliver Jones)
- Subject: Re: X graphics question
- Message-ID: <1992Jul24.202159.8199@pictel.com>
- Keywords: Ximage, pixmap
- Organization: PictureTel Corporation
- References: <4774@calmasd.Prime.COM>
- Distribution: usa
- Date: Fri, 24 Jul 1992 20:21:59 GMT
- Lines: 61
-
- In article <4774@calmasd.Prime.COM> sas@calmasd.Prime.COM (Shirley Sloper) writes:
- >
- >The application displays a 512x512 pixel image and
- >updates areas of the image. The graphics module receives
- >one row at a time to display. The data consists of
- >an array of colormap indices, the column and row of the first
- >pixel to display and the number of pixels to display.
-
- >I am currently creating an Ximage of width count and height 1,
- >putting the image in the window, and then destroying the
- >image.
-
- >This works, but there's a better way, right?
-
- What you're doing is pretty good. From the point of view of the
- volume of data sent over the X protocol, it's almost optimal. (You
- could save maybe 2-3 percent by buffering up the whole image into a
- single XPutImage request.)
-
- You don't need to create and destroy the XImage structure for every
- scan line, however. The fundamental thing to understand about the
- XImage structure is that it serves as a wrapper, or
- image-descriptor-block, for an array of pixels in your client
- program's memory. The array of pixels in your client is one
- byte-per-pixel. You could do something like this (warning...
- untested!)
-
- raster_write_row(pixelBuf, count, x, y)
- char *pixelBuf;
- int count,x,y;
- {
- static XImage * i = 0;
-
- if (i == 0) {
- /*
- * create a suitable XImage structure for
- * use with 8-bit-per-pixel image data.
- */
- i = XCreateImage (dpy, vis, 8, ZPixmap,
- 0, pixelBuf, count, 1, 8, count);
- }
-
- /*
- * point the pre-existing XImage structure to the
- * data being passed in to this call to raster_write_row
- */
- i->width = count;
- i->data = pixelBuf;
-
- /* Out with the data */
- XPutImage (dpy, win, gc, i, 0,0, x,y,count,1);
- }
-
- >How does the image relate to a pixmap?
-
- An XImage structure lives in your client's memory space, whereas a
- pixmap lives in the server. XPutImage can be used to move data from
- an XImage structure in your client to a pixmap or a window in the
- server.
-
- Oliver Jones
-