comparison src/w32fns.c @ 49540:a38733d32d73

(DrawText): Kludge to avoid a redefinition on Windows when including gif_lib.h. (init_gif_functions): New function. (gif_load): Sync with xfns.c version. Adjust colors for Windows. Disable color table lookups. Call gif library functions through pointers determined at runtime. (init_external_image_libraries): Try to load libungif.dll.
author Juanma Barranquero <lekktu@gmail.com>
date Fri, 31 Jan 2003 07:20:13 +0000
parents 356642af7816
children 954b23b1037b
comparison
equal deleted inserted replaced
49539:1ad5bfbb831a 49540:a38733d32d73
12917 GIF 12917 GIF
12918 ***********************************************************************/ 12918 ***********************************************************************/
12919 12919
12920 #if HAVE_GIF 12920 #if HAVE_GIF
12921 12921
12922 #define DrawText gif_DrawText
12922 #include <gif_lib.h> 12923 #include <gif_lib.h>
12924 #undef DrawText
12923 12925
12924 static int gif_image_p P_ ((Lisp_Object object)); 12926 static int gif_image_p P_ ((Lisp_Object object));
12925 static int gif_load P_ ((struct frame *f, struct image *img)); 12927 static int gif_load P_ ((struct frame *f, struct image *img));
12926 12928
12927 /* The symbol `gif' identifying images of this type. */ 12929 /* The symbol `gif' identifying images of this type. */
12973 gif_load, 12975 gif_load,
12974 x_clear_image, 12976 x_clear_image,
12975 NULL 12977 NULL
12976 }; 12978 };
12977 12979
12980
12981 /* GIF library details. */
12982 DEF_IMGLIB_FN (DGifCloseFile);
12983 DEF_IMGLIB_FN (DGifSlurp);
12984 DEF_IMGLIB_FN (DGifOpen);
12985 DEF_IMGLIB_FN (DGifOpenFileName);
12986
12987 static int
12988 init_gif_functions (library)
12989 HMODULE library;
12990 {
12991 LOAD_IMGLIB_FN (library, DGifCloseFile);
12992 LOAD_IMGLIB_FN (library, DGifSlurp);
12993 LOAD_IMGLIB_FN (library, DGifOpen);
12994 LOAD_IMGLIB_FN (library, DGifOpenFileName);
12995 return 1;
12996 }
12997
12998
12978 /* Return non-zero if OBJECT is a valid GIF image specification. */ 12999 /* Return non-zero if OBJECT is a valid GIF image specification. */
12979 13000
12980 static int 13001 static int
12981 gif_image_p (object) 13002 gif_image_p (object)
12982 Lisp_Object object; 13003 Lisp_Object object;
13059 UNGCPRO; 13080 UNGCPRO;
13060 return 0; 13081 return 0;
13061 } 13082 }
13062 13083
13063 /* Open the GIF file. */ 13084 /* Open the GIF file. */
13064 gif = DGifOpenFileName (SDATA (file)); 13085 gif = fn_DGifOpenFileName (SDATA (file));
13065 if (gif == NULL) 13086 if (gif == NULL)
13066 { 13087 {
13067 image_error ("Cannot open `%s'", file, Qnil); 13088 image_error ("Cannot open `%s'", file, Qnil);
13068 UNGCPRO; 13089 UNGCPRO;
13069 return 0; 13090 return 0;
13075 current_gif_memory_src = &memsrc; 13096 current_gif_memory_src = &memsrc;
13076 memsrc.bytes = SDATA (specified_data); 13097 memsrc.bytes = SDATA (specified_data);
13077 memsrc.len = SBYTES (specified_data); 13098 memsrc.len = SBYTES (specified_data);
13078 memsrc.index = 0; 13099 memsrc.index = 0;
13079 13100
13080 gif = DGifOpen(&memsrc, gif_read_from_memory); 13101 gif = fn_DGifOpen(&memsrc, gif_read_from_memory);
13081 if (!gif) 13102 if (!gif)
13082 { 13103 {
13083 image_error ("Cannot open memory source `%s'", img->spec, Qnil); 13104 image_error ("Cannot open memory source `%s'", img->spec, Qnil);
13084 UNGCPRO; 13105 UNGCPRO;
13085 return 0; 13106 return 0;
13086 } 13107 }
13087 } 13108 }
13088 13109
13089 /* Read entire contents. */ 13110 /* Read entire contents. */
13090 rc = DGifSlurp (gif); 13111 rc = fn_DGifSlurp (gif);
13091 if (rc == GIF_ERROR) 13112 if (rc == GIF_ERROR)
13092 { 13113 {
13093 image_error ("Error reading `%s'", img->spec, Qnil); 13114 image_error ("Error reading `%s'", img->spec, Qnil);
13094 DGifCloseFile (gif); 13115 fn_DGifCloseFile (gif);
13095 UNGCPRO; 13116 UNGCPRO;
13096 return 0; 13117 return 0;
13097 } 13118 }
13098 13119
13099 image = image_spec_value (img->spec, QCindex, NULL); 13120 image = image_spec_value (img->spec, QCindex, NULL);
13100 ino = INTEGERP (image) ? XFASTINT (image) : 0; 13121 ino = INTEGERP (image) ? XFASTINT (image) : 0;
13101 if (ino >= gif->ImageCount) 13122 if (ino >= gif->ImageCount)
13102 { 13123 {
13103 image_error ("Invalid image number `%s' in image `%s'", 13124 image_error ("Invalid image number `%s' in image `%s'",
13104 image, img->spec); 13125 image, img->spec);
13105 DGifCloseFile (gif); 13126 fn_DGifCloseFile (gif);
13106 UNGCPRO; 13127 UNGCPRO;
13107 return 0; 13128 return 0;
13108 } 13129 }
13109 13130
13110 width = img->width = gif->SWidth; 13131 width = img->width = max (gif->SWidth, gif->Image.Left + gif->Image.Width);
13111 height = img->height = gif->SHeight; 13132 height = img->height = max (gif->SHeight, gif->Image.Top + gif->Image.Height);
13112 13133
13113 /* Create the X image and pixmap. */ 13134 /* Create the X image and pixmap. */
13114 if (!x_create_x_image_and_pixmap (f, width, height, 0, &ximg, &img->pixmap)) 13135 if (!x_create_x_image_and_pixmap (f, width, height, 0, &ximg, &img->pixmap))
13115 { 13136 {
13116 DGifCloseFile (gif); 13137 fn_DGifCloseFile (gif);
13117 UNGCPRO; 13138 UNGCPRO;
13118 return 0; 13139 return 0;
13119 } 13140 }
13120 13141
13121 /* Allocate colors. */ 13142 /* Allocate colors. */
13122 gif_color_map = gif->SavedImages[ino].ImageDesc.ColorMap; 13143 gif_color_map = gif->SavedImages[ino].ImageDesc.ColorMap;
13123 if (!gif_color_map) 13144 if (!gif_color_map)
13124 gif_color_map = gif->SColorMap; 13145 gif_color_map = gif->SColorMap;
13146 #if 0 /* TODO: Color tables */
13125 init_color_table (); 13147 init_color_table ();
13148 #endif
13126 bzero (pixel_colors, sizeof pixel_colors); 13149 bzero (pixel_colors, sizeof pixel_colors);
13127 13150
13128 for (i = 0; i < gif_color_map->ColorCount; ++i) 13151 for (i = 0; i < gif_color_map->ColorCount; ++i)
13129 { 13152 {
13130 int r = gif_color_map->Colors[i].Red << 8; 13153 int r = gif_color_map->Colors[i].Red;
13131 int g = gif_color_map->Colors[i].Green << 8; 13154 int g = gif_color_map->Colors[i].Green;
13132 int b = gif_color_map->Colors[i].Blue << 8; 13155 int b = gif_color_map->Colors[i].Blue;
13156 #if 0 /* TODO: Color tables */
13133 pixel_colors[i] = lookup_rgb_color (f, r, g, b); 13157 pixel_colors[i] = lookup_rgb_color (f, r, g, b);
13134 } 13158 #else
13135 13159 pixel_colors[i] = PALETTERGB (r, g, b);
13160 #endif
13161 }
13162
13163 #if 0 /* TODO: Color tables */
13136 img->colors = colors_in_color_table (&img->ncolors); 13164 img->colors = colors_in_color_table (&img->ncolors);
13137 free_color_table (); 13165 free_color_table ();
13166 #endif
13138 13167
13139 /* Clear the part of the screen image that are not covered by 13168 /* Clear the part of the screen image that are not covered by
13140 the image from the GIF file. Full animated GIF support 13169 the image from the GIF file. Full animated GIF support
13141 requires more than can be done here (see the gif89 spec, 13170 requires more than can be done here (see the gif89 spec,
13142 disposal methods). Let's simply assume that the part 13171 disposal methods). Let's simply assume that the part
13203 int i = raster[y* image_width + x]; 13232 int i = raster[y* image_width + x];
13204 XPutPixel (ximg, x + image_left, y + image_top, pixel_colors[i]); 13233 XPutPixel (ximg, x + image_left, y + image_top, pixel_colors[i]);
13205 } 13234 }
13206 } 13235 }
13207 13236
13208 DGifCloseFile (gif); 13237 fn_DGifCloseFile (gif);
13209 13238
13210 /* Maybe fill in the background field while we have ximg handy. */ 13239 /* Maybe fill in the background field while we have ximg handy. */
13211 if (NILP (image_spec_value (img->spec, QCbackground, NULL))) 13240 if (NILP (image_spec_value (img->spec, QCbackground, NULL)))
13212 IMAGE_BACKGROUND (img, f, ximg); 13241 IMAGE_BACKGROUND (img, f, ximg);
13213 13242
15692 #if HAVE_TIFF 15721 #if HAVE_TIFF
15693 define_image_type (&tiff_type); 15722 define_image_type (&tiff_type);
15694 #endif 15723 #endif
15695 15724
15696 #if HAVE_GIF 15725 #if HAVE_GIF
15697 define_image_type (&gif_type); 15726 if (library = LoadLibrary ("libungif.dll"))
15727 {
15728 if (init_gif_functions (library))
15729 define_image_type (&gif_type);
15730 }
15698 #endif 15731 #endif
15699 15732
15700 #if HAVE_PNG 15733 #if HAVE_PNG
15701 /* Ensure zlib is loaded. Try debug version first. */ 15734 /* Ensure zlib is loaded. Try debug version first. */
15702 if (!LoadLibrary ("zlibd.dll")) 15735 if (!LoadLibrary ("zlibd.dll"))