home *** CD-ROM | disk | FTP | other *** search
/ vsiftp.vmssoftware.com / VSIPUBLIC@vsiftp.vmssoftware.com.tar / FREEWARE / FREEWARE40.ZIP / xtron-1_1a / xpm2pixmap.c < prev    next >
C/C++ Source or Header  |  1995-04-16  |  2KB  |  66 lines

  1. /* xpm2pixmap.c - xtron v1.1 routine to convert from xpm to pixmap
  2.  *
  3.  *   Copyright (C) 1995 Rhett D. Jacobs <rhett@hotel.canberra.edu.au>
  4.  *
  5.  *  This program is free software; you can redistribute it and/or modify
  6.  *  it under the terms of the GNU General Public License as published by
  7.  *  the Free Software Foundation; either version 1, or (at your option)
  8.  *  any later version.
  9.  *
  10.  *  This program is distributed in the hope that it will be useful,
  11.  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  12.  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13.  *  GNU General Public License for more details.
  14.  *
  15.  *  You should have received a copy of the GNU General Public License
  16.  *  along with this program; if not, write to the Free Software
  17.  *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  18.  *
  19.  *  Last Modified: 16/4/95
  20.  */
  21.  
  22. #include "xpm2pixmap.h"
  23.  
  24. extern Window main_window;
  25. extern Display *display;
  26. extern int screen;
  27.  
  28. /* ReadXPM is copyright (c) 1994 Alex Brown All Rights Reserved. Used by permission. */
  29. Pixmap ReadXPM(char *filename)
  30. {
  31.   Window root;
  32.   Pixmap rootXpm;
  33.   char real_filename[MAX_PATH_LEN];
  34.   XWindowAttributes root_attr;
  35.   XpmAttributes xpm_attributes;
  36.   int val;
  37.   char resfilename[MAX_PATH_LEN];
  38.  
  39.   PixmapsDIR(resfilename);
  40.  
  41.   strcpy(real_filename, resfilename);
  42.   strcat(real_filename, filename);
  43.  
  44.   root = RootWindow(display, screen);
  45.   XGetWindowAttributes(display,root,&root_attr); 
  46.   xpm_attributes.colormap = root_attr.colormap;
  47.   xpm_attributes.valuemask = XpmSize | XpmReturnPixels|XpmColormap;
  48.  
  49.   if((val = XpmReadFileToPixmap(display, root, real_filename,
  50.                                 &rootXpm, NULL,
  51.                     &xpm_attributes))!= XpmSuccess) {
  52.     if(val == XpmOpenFailed)    
  53.       fprintf(stderr, "Couldn't open pixmap file %s\n", real_filename);
  54.     else if(val == XpmColorFailed)
  55.       fprintf(stderr, "Couldn't allocated required colors\n");
  56.     else if(val == XpmFileInvalid)
  57.       fprintf(stderr, "Invalid Format for an Xpm File\n");
  58.     else if(val == XpmColorError)
  59.       fprintf(stderr, "Invalid Color specified in Xpm FIle\n");
  60.     else if(val == XpmNoMemory)
  61.       fprintf(stderr, "Insufficient Memory\n");
  62.     return -1;
  63.   }
  64.   return(rootXpm);
  65. }
  66.