ac64df6aba0a0ce9c79877fda0a4496c1f2a4de1
[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 #ifdef DEBUG
21 /*
22 #define DEBUG_TIMING
23 */
24 #endif
25
26
27
28 extern long Counter(void);
29
30
31
32 int Read_GIF_to_Pixmaps(Display *display, Window window, char *filename,
33                         Pixmap *pixmap, Pixmap *pixmap_mask)
34 {
35   Image *image, *image_mask;
36   XImageInfo *ximageinfo, *ximageinfo_mask;
37   int screen;
38   Visual *visual;
39   unsigned int depth;
40
41 #ifdef DEBUG_TIMING
42   long count1, count2;
43   count1 = Counter();
44 #endif
45
46   /* load GIF file */
47   if (!(image = gifLoad(filename)))
48   {
49     printf("Loading GIF image failed -- maybe no GIF...\n");
50     exit(1);
51   }
52
53 #ifdef DEBUG_TIMING
54   count2 = Counter();
55   printf("   LOADING '%s' IN %.2f SECONDS\n",
56          filename, (float)(count2-count1)/1000.0);
57   count1 = Counter();
58 #endif
59
60   if (image->depth > 8)
61   {
62     printf("Sorry, GIFs with more than 256 colors are not supported.\n");
63     exit(1);
64   }
65
66   /* minimize colormap */
67   compress(image);
68
69 #ifdef DEBUG_TIMING
70   count2 = Counter();
71   printf("   COMPRESSING IMAGE COLORMAP IN %.2f SECONDS\n",
72          (float)(count2-count1)/1000.0);
73   count1 = Counter();
74 #endif
75
76   screen = DefaultScreen(display);
77   visual = DefaultVisual(display, screen);
78   depth = DefaultDepth(display, screen);
79
80   /* convert internal image structure to X11 XImage */
81   if (!(ximageinfo = imageToXImage(display, screen, visual, depth, image)))
82   {
83     fprintf(stderr, "Cannot convert Image to XImage.\n");
84     exit(1);
85   }
86
87 #ifdef DEBUG_TIMING
88   count2 = Counter();
89   printf("   CONVERTING IMAGE TO XIMAGE IN %.2f SECONDS\n",
90          (float)(count2-count1)/1000.0);
91   count1 = Counter();
92 #endif
93
94   if (ximageinfo->cmap != DefaultColormap(display, screen))
95     XSetWindowColormap(display, window, ximageinfo->cmap);
96
97   /* convert XImage to Pixmap */
98   if ((*pixmap = ximageToPixmap(display, window, ximageinfo)) == None)
99   {
100     fprintf(stderr, "Cannot convert XImage to Pixmap.\n");
101     exit(1);
102   }
103
104 #ifdef DEBUG_TIMING
105   count2 = Counter();
106   printf("   CONVERTING IMAGE TO PIXMAP IN %.2f SECONDS\n",
107          (float)(count2-count1)/1000.0);
108   count1 = Counter();
109 #endif
110
111   /* create mono image for masking */
112   image_mask = monochrome(image);
113
114 #ifdef DEBUG_TIMING
115   count2 = Counter();
116   printf("   CONVERTING IMAGE TO MASK IN %.2f SECONDS\n",
117          (float)(count2-count1)/1000.0);
118   count1 = Counter();
119 #endif
120
121   /* convert internal image structure to X11 XImage */
122   if (!(ximageinfo_mask = imageToXImage(display, screen, visual, depth,
123                                         image_mask)))
124   {
125     fprintf(stderr, "Cannot convert Image to XImage.\n");
126     exit(1);
127   }
128
129 #ifdef DEBUG_TIMING
130   count2 = Counter();
131   printf("   CONVERTING MASK TO XIMAGE IN %.2f SECONDS\n",
132          (float)(count2-count1)/1000.0);
133   count1 = Counter();
134 #endif
135
136   /* convert XImage to Pixmap */
137   if ((*pixmap_mask = ximageToPixmap(display, window, ximageinfo_mask)) == None)
138   {
139     fprintf(stderr, "Cannot convert XImage to Pixmap.\n");
140     exit(1);
141   }
142
143 #ifdef DEBUG_TIMING
144   count2 = Counter();
145   printf("   CONVERTING MASK TO PIXMAP IN %.2f SECONDS\n",
146          (float)(count2-count1)/1000.0);
147   count1 = Counter();
148 #endif
149
150   return(GIF_Success);
151 }
152
153 #endif