f26ba5a1702349551b61668052e84b0a4919bbef
[rocksndiamonds.git] / src / gifload.c
1 /***********************************************************
2 *  Rocks'n'Diamonds -- McDuffin Strikes Back!              *
3 *----------------------------------------------------------*
4 *  ©1995 Artsoft Development                               *
5 *        Holger Schemel                                    *
6 *        33659 Bielefeld-Senne                             *
7 *        Telefon: (0521) 493245                            *
8 *        eMail: aeglos@valinor.owl.de                      *
9 *               aeglos@uni-paderborn.de                    *
10 *               q99492@pbhrzx.uni-paderborn.de             *
11 *----------------------------------------------------------*
12 *  gifload.c                                               *
13 ***********************************************************/
14
15 #ifndef MSDOS
16 #include "gifload.h"
17
18 #include "xli.h"
19
20
21
22 extern Pixmap           test_pix[];
23 extern Pixmap           test_clipmask[];
24 extern int              test_picture_count;
25
26
27
28
29 int Read_GIF_to_Pixmaps(Display *display, Window window, char *filename)
30 {
31   Image *image, *image_mask;
32   XImageInfo *ximageinfo, *ximageinfo_mask;
33   Pixmap pixmap, pixmap_mask;
34   int screen;
35   Visual *visual;
36   unsigned int depth;
37
38   /* load GIF file */
39   if (!(image = gifLoad(filename)))
40   {
41     printf("Loading GIF image failed -- maybe no GIF...\n");
42     exit(1);
43   }
44
45   if (image->depth > 8)
46   {
47     printf("Sorry, GIFs with more than 256 colors are not supported.\n");
48     exit(1);
49   }
50
51   /* minimize colormap */
52   compress(image);
53
54   screen = DefaultScreen(display);
55   visual = DefaultVisual(display, screen);
56   depth = DefaultDepth(display, screen);
57
58   /* convert internal image structure to X11 XImage */
59   if (!(ximageinfo = imageToXImage(display, screen, visual, depth, image)))
60   {
61     fprintf(stderr, "Cannot convert Image to XImage.\n");
62     exit(1);
63   }
64
65   if (ximageinfo->cmap != DefaultColormap(display, screen))
66   {
67     /*
68     printf("--> '%s' gets own colormap\n", filename);
69     */
70
71     XSetWindowColormap(display, window, ximageinfo->cmap);
72   }
73
74   /* convert XImage to Pixmap */
75   if ((pixmap = ximageToPixmap(display, window, ximageinfo)) == None)
76   {
77     fprintf(stderr, "Cannot convert XImage to Pixmap.\n");
78     exit(1);
79   }
80
81   /*
82   printf("test_picture_count == %d\n", test_picture_count);
83   */
84
85   test_pix[test_picture_count] = pixmap;
86
87
88   /* create mono image for masking */
89   image_mask = monochrome(image);
90
91   /* convert internal image structure to X11 XImage */
92   if (!(ximageinfo_mask = imageToXImage(display, screen, visual, depth,
93                                         image_mask)))
94   {
95     fprintf(stderr, "Cannot convert Image to XImage.\n");
96     exit(1);
97   }
98
99   /* convert XImage to Pixmap */
100   if ((pixmap_mask = ximageToPixmap(display, window, ximageinfo_mask)) == None)
101   {
102     fprintf(stderr, "Cannot convert XImage to Pixmap.\n");
103     exit(1);
104   }
105
106
107   test_clipmask[test_picture_count] = pixmap_mask;
108
109   test_picture_count++;
110
111
112   return(GIF_Success);
113 }
114
115 #endif