home *** CD-ROM | disk | FTP | other *** search
/ vsiftp.vmssoftware.com / VSIPUBLIC@vsiftp.vmssoftware.com.tar / FREEWARE / FREEWARE40.ZIP / xjig / imgbuff.c < prev    next >
C/C++ Source or Header  |  1996-07-17  |  2KB  |  83 lines

  1.  
  2. #ifndef _global_h
  3. #    include "global.h"
  4. #endif
  5. #ifndef _imgbuff_h
  6. #    include "imgbuff.H"
  7. #endif
  8.  
  9. ImageBuffer::ImageBuffer() {
  10.     ximage=0;
  11.     width=0;
  12.     height=0;
  13. #ifdef USE_MIT_SHM
  14. int    major,minor;
  15. Bool    pmaps;
  16.  
  17.     shm=(shared)?XShmQueryVersion(dpy,&major,&minor,&pmaps):0;
  18.     if (shm&&verbose)    {
  19.         printf( "--- using shared memory extension V%d.%d %s\n", major, minor,
  20.                     ((pmaps)?"(shared pixmaps supported)":"") );
  21.     }
  22. #endif
  23. }
  24.  
  25. ImageBuffer::~ImageBuffer() {
  26.     FreeData();
  27. }
  28.  
  29. void ImageBuffer::FreeData() {
  30.     if (ximage) {
  31. #ifdef USE_MIT_SHM
  32.         if (shm) {
  33.             XShmDetach(dpy,&shminfo);
  34.             XDestroyImage(ximage);
  35.             shmdt(shminfo.shmaddr);
  36.             shmctl(shminfo.shmid, IPC_RMID, 0 );
  37.         }
  38.         else
  39. #endif
  40.         {
  41.             free( ximage->data );
  42.             ximage->data = 0L;
  43.             XDestroyImage(ximage);
  44.         }
  45.         ximage=0;
  46.     }
  47. }
  48.  
  49. void ImageBuffer::AllocData(int w, int h, int bpp8) {
  50.     FreeData();
  51.     width  = w;
  52.     height = h;
  53.  
  54. #ifdef USE_MIT_SHM
  55.     if (shm) {
  56.         ximage = XShmCreateImage(dpy, DefaultVisual(dpy,scr),
  57.             DefaultDepth(dpy,scr), ZPixmap, NULL, &shminfo, width, height );
  58.         shminfo.shmid    = shmget(IPC_PRIVATE, ximage->bytes_per_line * ximage->height, IPC_CREAT|0777);
  59.         shminfo.shmaddr  = ximage->data = (char*)shmat(shminfo.shmid,0,0);
  60.         shminfo.readOnly = False;
  61.         XShmAttach(dpy,&shminfo);
  62.     }
  63.     else
  64. #endif
  65.     {
  66.         char *data=(char*)malloc(width*height*bpp8);
  67.         ximage = XCreateImage(dpy, DefaultVisual(dpy,scr),
  68.             DefaultDepth(dpy,scr), ZPixmap, 0,
  69.             data, width, height, (8*bpp8), width*bpp8 );
  70.     }
  71. }
  72.  
  73.  
  74. XImage *ImageBuffer::Init(int w,int h,int bpp8) {
  75.     // w+=10; h+=10;
  76.     if (w>width||h>height) {
  77.         FreeData();
  78.         AllocData(w,h,bpp8);
  79.     }
  80.     return ximage;
  81. }
  82.  
  83.