rnd-19980904-1
[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_Image(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     printf("--> '%s' gets own colormap\n", filename);
68
69     XSetWindowColormap(display, window, ximageinfo->cmap);
70   }
71
72   /* convert XImage to Pixmap */
73   if ((pixmap = ximageToPixmap(display, window, ximageinfo)) == None)
74   {
75     fprintf(stderr, "Cannot convert XImage to Pixmap.\n");
76     exit(1);
77   }
78
79
80   printf("test_picture_count == %d\n", test_picture_count);
81
82
83   test_pix[test_picture_count] = pixmap;
84
85
86   /* create mono image for masking */
87   image_mask = monochrome(image);
88
89   /* convert internal image structure to X11 XImage */
90   if (!(ximageinfo_mask = imageToXImage(display, screen, visual, depth,
91                                         image_mask)))
92   {
93     fprintf(stderr, "Cannot convert Image to XImage.\n");
94     exit(1);
95   }
96
97   /* convert XImage to Pixmap */
98   if ((pixmap_mask = ximageToPixmap(display, window, ximageinfo_mask)) == None)
99   {
100     fprintf(stderr, "Cannot convert XImage to Pixmap.\n");
101     exit(1);
102   }
103
104
105   test_clipmask[test_picture_count] = pixmap_mask;
106
107   test_picture_count++;
108
109
110   return(GIF_Success);
111 }
112
113 #endif