home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #16 / NN_1992_16.iso / spool / comp / windows / x / 14364 < prev    next >
Encoding:
Text File  |  1992-07-25  |  2.3 KB  |  74 lines

  1. Newsgroups: comp.windows.x
  2. Path: sparky!uunet!noc.near.net!gateway!pictel!oj
  3. From: oj@pictel.com (Oliver Jones)
  4. Subject: Re: X graphics question
  5. Message-ID: <1992Jul24.202159.8199@pictel.com>
  6. Keywords: Ximage, pixmap
  7. Organization: PictureTel Corporation
  8. References: <4774@calmasd.Prime.COM>
  9. Distribution: usa
  10. Date: Fri, 24 Jul 1992 20:21:59 GMT
  11. Lines: 61
  12.  
  13. In article <4774@calmasd.Prime.COM> sas@calmasd.Prime.COM (Shirley Sloper) writes:
  14. >
  15. >The application displays a 512x512 pixel image and 
  16. >updates areas of the image.  The graphics module receives
  17. >one row at a time to display. The data consists of
  18. >an array of colormap indices, the column and row of the first
  19. >pixel to display and the number of pixels to display. 
  20.  
  21. >I am currently creating an Ximage of width count and height 1, 
  22. >putting the image in the window, and then destroying the 
  23. >image.  
  24.  
  25. >This works, but there's a better way, right?
  26.  
  27. What you're doing is pretty good.  From the point of view of the
  28. volume of data sent over the X protocol, it's almost optimal.  (You
  29. could save maybe 2-3 percent by buffering up the whole image into a
  30. single XPutImage request.)
  31.  
  32. You don't need to create and destroy the XImage structure for every
  33. scan line, however.  The fundamental thing to understand about the
  34. XImage structure is that it serves as a wrapper, or
  35. image-descriptor-block, for an array of pixels in your client
  36. program's memory.  The array of pixels in your client is one
  37. byte-per-pixel.  You could do something like this (warning...
  38. untested!)
  39.  
  40. raster_write_row(pixelBuf, count, x, y)
  41.     char    *pixelBuf;
  42.     int     count,x,y;
  43. {
  44.   static XImage * i = 0;
  45.  
  46.   if (i == 0) {
  47.         /* 
  48.          * create a suitable XImage structure for
  49.          * use with 8-bit-per-pixel image data.
  50.          */
  51.     i = XCreateImage (dpy, vis, 8, ZPixmap,
  52.                       0, pixelBuf, count, 1, 8, count);
  53.   } 
  54.  
  55.   /* 
  56.    * point the pre-existing XImage structure to the
  57.    * data being passed in to this call to raster_write_row
  58.    */
  59.   i->width = count;
  60.   i->data = pixelBuf;
  61.  
  62.   /* Out with the data */
  63.   XPutImage (dpy, win, gc, i, 0,0, x,y,count,1);
  64. }
  65.   
  66. >How does the image relate to a pixmap?
  67.  
  68. An XImage structure lives in your client's memory space, whereas a
  69. pixmap lives in the server.  XPutImage can be used to move data from
  70. an XImage structure in your client to a pixmap or a window in the
  71. server.
  72.  
  73. Oliver Jones
  74.