home *** CD-ROM | disk | FTP | other *** search
/ ftp.cs.arizona.edu / ftp.cs.arizona.edu.tar / ftp.cs.arizona.edu / icon / historic / v941.tgz / icon.v941src.tar / icon.v941src / src / xpm / XpmCrPFData.c < prev    next >
C/C++ Source or Header  |  2000-07-29  |  3KB  |  93 lines

  1. /* Copyright 1990-92 GROUPE BULL -- See license conditions in file COPYRIGHT */
  2. /*****************************************************************************\
  3. * XpmCrPFData.c:                                                              *
  4. *                                                                             *
  5. *  XPM library                                                                *
  6. *  Parse an Xpm array and create the pixmap and possibly its mask             *
  7. *                                                                             *
  8. *  Developed by Arnaud Le Hors                                                *
  9. \*****************************************************************************/
  10.  
  11. #include "xpmP.h"
  12.  
  13. int
  14. XpmCreatePixmapFromData(display, d, data, pixmap_return,
  15.             shapemask_return, attributes)
  16.     Display *display;
  17.     Drawable d;
  18.     char **data;
  19.     Pixmap *pixmap_return;
  20.     Pixmap *shapemask_return;
  21.     XpmAttributes *attributes;
  22. {
  23.     XImage *image, **imageptr = NULL;
  24.     XImage *shapeimage, **shapeimageptr = NULL;
  25.     int ErrorStatus;
  26.     XGCValues gcv;
  27.     GC gc;
  28.  
  29.     /*
  30.      * initialize return values 
  31.      */
  32.     if (pixmap_return) {
  33.     *pixmap_return = 0;
  34.     imageptr = ℑ
  35.     }
  36.     if (shapemask_return) {
  37.     *shapemask_return = 0;
  38.     shapeimageptr = &shapeimage;
  39.     }
  40.  
  41.     /*
  42.      * create the images 
  43.      */
  44.     ErrorStatus = XpmCreateImageFromData(display, data, imageptr,
  45.                      shapeimageptr, attributes);
  46.     if (ErrorStatus < 0)
  47.     return (ErrorStatus);
  48.  
  49.     /*
  50.      * create the pixmaps 
  51.      */
  52.     if (imageptr && image) {
  53.     *pixmap_return = XCreatePixmap(display, d, image->width,
  54.                        image->height, image->depth);
  55.     gcv.function = GXcopy;
  56.     gc = XCreateGC(display, *pixmap_return, GCFunction, &gcv);
  57.  
  58.     XPutImage(display, *pixmap_return, gc, image, 0, 0, 0, 0,
  59.           image->width, image->height);
  60.  
  61. #ifdef Debug
  62.     /*
  63.      * XDestroyImage free the image data but mnemosyne don't know about it
  64.      * so I free them by hand to avoid mnemalyse report it as lost data.
  65.      */
  66.     free(image->data);
  67. #endif
  68.     XDestroyImage(image);
  69.     XFreeGC(display, gc);
  70.     }
  71.     if (shapeimageptr && shapeimage) {
  72.     *shapemask_return = XCreatePixmap(display, d, shapeimage->width,
  73.                       shapeimage->height,
  74.                       shapeimage->depth);
  75.     gcv.function = GXcopy;
  76.     gc = XCreateGC(display, *shapemask_return, GCFunction, &gcv);
  77.  
  78.     XPutImage(display, *shapemask_return, gc, shapeimage, 0, 0, 0, 0,
  79.           shapeimage->width, shapeimage->height);
  80.  
  81. #ifdef Debug
  82.     /*
  83.      * XDestroyImage free the image data but mnemosyne don't know about it
  84.      * so I free them by hand to avoid mnemalyse report it as lost data.
  85.      */
  86.     free(shapeimage->data);
  87. #endif
  88.     XDestroyImage(shapeimage);
  89.     XFreeGC(display, gc);
  90.     }
  91.     return (ErrorStatus);
  92. }
  93.