Merge from trunk
[bpt/emacs.git] / src / image.c
index c39a9ef..b37ba39 100644 (file)
@@ -1,7 +1,5 @@
 /* Functions for image support on window system.
-   Copyright (C) 1989, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000,
-                 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010,
-                2011 Free Software Foundation, Inc.
+   Copyright (C) 1989, 1992-2011 Free Software Foundation, Inc.
 
 This file is part of GNU Emacs.
 
@@ -22,10 +20,7 @@ along with GNU Emacs.  If not, see <http://www.gnu.org/licenses/>.  */
 #include <stdio.h>
 #include <math.h>
 #include <ctype.h>
-
-#ifdef HAVE_UNISTD_H
 #include <unistd.h>
-#endif
 
 #ifdef HAVE_PNG
 #if defined HAVE_LIBPNG_PNG_H
@@ -127,10 +122,6 @@ typedef struct ns_bitmap_record Bitmap_Record;
 #endif /* HAVE_NS */
 
 
-/* Search path for bitmap files.  */
-
-Lisp_Object Vx_bitmap_file_path;
-
 /* The symbol `postscript' identifying images of this type.  */
 
 Lisp_Object Qpostscript;
@@ -357,7 +348,7 @@ x_create_bitmap_from_file (struct frame *f, Lisp_Object file)
     {
       if (dpyinfo->bitmaps[id].refcount
          && dpyinfo->bitmaps[id].file
-         && !strcmp (dpyinfo->bitmaps[id].file, (char *) SDATA (file)))
+         && !strcmp (dpyinfo->bitmaps[id].file, SSDATA (file)))
        {
          ++dpyinfo->bitmaps[id].refcount;
          return id + 1;
@@ -370,7 +361,7 @@ x_create_bitmap_from_file (struct frame *f, Lisp_Object file)
     return -1;
   emacs_close (fd);
 
-  filename = (char *) SDATA (found);
+  filename = SSDATA (found);
 
   result = XReadBitmapFile (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f),
                            filename, &width, &height, &bitmap, &xhot, &yhot);
@@ -385,7 +376,7 @@ x_create_bitmap_from_file (struct frame *f, Lisp_Object file)
   dpyinfo->bitmaps[id - 1].depth = 1;
   dpyinfo->bitmaps[id - 1].height = height;
   dpyinfo->bitmaps[id - 1].width = width;
-  strcpy (dpyinfo->bitmaps[id - 1].file, SDATA (file));
+  strcpy (dpyinfo->bitmaps[id - 1].file, SSDATA (file));
 
   return id;
 #endif /* HAVE_X_WINDOWS */
@@ -559,19 +550,11 @@ x_create_bitmap_mask (struct frame *f, int id)
                            Image types
  ***********************************************************************/
 
-/* Value is the number of elements of vector VECTOR.  */
-
-#define DIM(VECTOR)    (sizeof (VECTOR) / sizeof *(VECTOR))
-
 /* List of supported image types.  Use define_image_type to add new
    types.  Use lookup_image_type to find a type for a given symbol.  */
 
 static struct image_type *image_types;
 
-/* A list of symbols, one for each supported image type.  */
-
-Lisp_Object Vimage_types;
-
 /* Cache for delayed-loading image types.  */
 
 static Lisp_Object Vimage_type_cache;
@@ -590,11 +573,6 @@ Lisp_Object QCindex, QCmatrix, QCcolor_adjustment, QCmask, QCgeometry, QCcrop, Q
 
 Lisp_Object Qlaplace, Qemboss, Qedge_detection, Qheuristic;
 
-/* Time in seconds after which images should be removed from the cache
-   if not displayed.  */
-
-Lisp_Object Vimage_cache_eviction_delay;
-
 /* Function prototypes.  */
 
 static Lisp_Object define_image_type (struct image_type *type, int loaded);
@@ -788,7 +766,7 @@ parse_image_spec (Lisp_Object spec, struct image_keyword *keywords,
 
       /* Find key in KEYWORDS.  Error if not found.  */
       for (i = 0; i < nkeywords; ++i)
-       if (strcmp (keywords[i].name, SDATA (SYMBOL_NAME (key))) == 0)
+       if (strcmp (keywords[i].name, SSDATA (SYMBOL_NAME (key))) == 0)
          break;
 
       if (i == nkeywords)
@@ -853,9 +831,7 @@ parse_image_spec (Lisp_Object spec, struct image_keyword *keywords,
 
        case IMAGE_FUNCTION_VALUE:
          value = indirect_function (value);
-         if (SUBRP (value)
-             || COMPILEDP (value)
-             || (CONSP (value) && EQ (XCAR (value), Qlambda)))
+         if (!NILP (Ffunctionp (value)))
            break;
          return 0;
 
@@ -1006,8 +982,6 @@ static void free_image (struct frame *f, struct image *img);
 static int check_image_size (struct frame *f, int width, int height);
 
 #define MAX_IMAGE_SIZE 6.0
-Lisp_Object Vmax_image_size;
-
 /* Allocate and return a new image structure for image specification
    SPEC.  SPEC has a hash value of HASH.  */
 
@@ -1161,7 +1135,7 @@ static RGB_PIXEL_COLOR
 four_corners_best (XImagePtr_or_DC ximg, int *corners,
                   unsigned long width, unsigned long height)
 {
-  RGB_PIXEL_COLOR corner_pixels[4], best;
+  RGB_PIXEL_COLOR corner_pixels[4], best IF_LINT (= 0);
   int i, best_count;
 
   if (corners && corners[BOT_CORNER] >= 0)
@@ -1386,7 +1360,7 @@ x_alloc_image_color (struct frame *f, struct image *img, Lisp_Object color_name,
 
   xassert (STRINGP (color_name));
 
-  if (x_defined_color (f, SDATA (color_name), &color, 1))
+  if (x_defined_color (f, SSDATA (color_name), &color, 1))
     {
       /* This isn't called frequently so we get away with simply
         reallocating the color vector to the needed size, here.  */
@@ -1513,7 +1487,7 @@ free_image_cache (struct frame *f)
    If image-cache-eviction-delay is non-nil, this frees images in the cache
    which weren't displayed for at least that many seconds.  */
 
-void
+static void
 clear_image_cache (struct frame *f, Lisp_Object filter)
 {
   struct image_cache *c = FRAME_IMAGE_CACHE (f);
@@ -1581,9 +1555,9 @@ clear_image_cache (struct frame *f, Lisp_Object filter)
 
          FOR_EACH_FRAME (tail, frame)
            {
-             struct frame *f = XFRAME (frame);
-             if (FRAME_IMAGE_CACHE (f) == c)
-               clear_current_matrices (f);
+             struct frame *fr = XFRAME (frame);
+             if (FRAME_IMAGE_CACHE (fr) == c)
+               clear_current_matrices (fr);
            }
 
          ++windows_or_buffers_changed;
@@ -1916,7 +1890,7 @@ mark_image_cache (struct image_cache *c)
 #ifdef HAVE_NTGUI
 
 /* Macro for defining functions that will be loaded from image DLLs.  */
-#define DEF_IMGLIB_FN(func,args) int (FAR CDECL *fn_##func)args
+#define DEF_IMGLIB_FN(rettype,func,args) rettype (FAR CDECL *fn_##func)args
 
 /* Macro for loading those image functions from the library.  */
 #define LOAD_IMGLIB_FN(lib,func) {                                     \
@@ -2246,7 +2220,7 @@ static int xbm_load_image (struct frame *f, struct image *img,
 static int xbm_image_p (Lisp_Object object);
 static int xbm_read_bitmap_data (struct frame *f,
                                  unsigned char *, unsigned char *,
-                                 int *, int *, unsigned char **, int);
+                                 int *, int *, char **, int);
 static int xbm_file_p (Lisp_Object);
 
 
@@ -2634,7 +2608,7 @@ Create_Pixmap_From_Bitmap_Data (struct frame *f, struct image *img, char *data,
 
 static int
 xbm_read_bitmap_data (struct frame *f, unsigned char *contents, unsigned char *end,
-                     int *width, int *height, unsigned char **data,
+                     int *width, int *height, char **data,
                      int inhibit_image_error)
 {
   unsigned char *s = contents;
@@ -2642,7 +2616,7 @@ xbm_read_bitmap_data (struct frame *f, unsigned char *contents, unsigned char *e
   int padding_p = 0;
   int v10 = 0;
   int bytes_per_line, i, nbytes;
-  unsigned char *p;
+  char *p;
   int value;
   int LA1;
 
@@ -2675,11 +2649,11 @@ xbm_read_bitmap_data (struct frame *f, unsigned char *contents, unsigned char *e
 
       if (LA1 == XBM_TK_NUMBER)
        {
-          char *p = strrchr (buffer, '_');
-         p = p ? p + 1 : buffer;
-          if (strcmp (p, "width") == 0)
+         char *q = strrchr (buffer, '_');
+         q = q ? q + 1 : buffer;
+         if (strcmp (q, "width") == 0)
            *width = value;
-          else if (strcmp (p, "height") == 0)
+         else if (strcmp (q, "height") == 0)
            *height = value;
        }
       expect (XBM_TK_NUMBER);
@@ -2726,7 +2700,7 @@ xbm_read_bitmap_data (struct frame *f, unsigned char *contents, unsigned char *e
 
   bytes_per_line = (*width + 7) / 8 + padding_p;
   nbytes = bytes_per_line * *height;
-  p = *data = (unsigned char *) xmalloc (nbytes);
+  p = *data = (char *) xmalloc (nbytes);
 
   if (v10)
     {
@@ -2788,7 +2762,7 @@ xbm_load_image (struct frame *f, struct image *img, unsigned char *contents,
                unsigned char *end)
 {
   int rc;
-  unsigned char *data;
+  char *data;
   int success_p = 0;
 
   rc = xbm_read_bitmap_data (f, contents, end, &img->width, &img->height,
@@ -2877,7 +2851,7 @@ xbm_load (struct frame *f, struct image *img)
          return 0;
        }
 
-      contents = slurp_file (SDATA (file), &size);
+      contents = slurp_file (SSDATA (file), &size);
       if (contents == NULL)
        {
          image_error ("Error loading XBM image `%s'", img->spec, Qnil);
@@ -2954,9 +2928,9 @@ xbm_load (struct frame *f, struct image *img)
                }
            }
          else if (STRINGP (data))
-           bits = SDATA (data);
+           bits = SSDATA (data);
          else
-           bits = XBOOL_VECTOR (data)->data;
+           bits = (char *) XBOOL_VECTOR (data)->data;
 
 #ifdef WINDOWSNT
           {
@@ -3271,12 +3245,12 @@ xpm_free_colors (Display *dpy, Colormap cmap, Pixel *pixels, int npixels, void *
 
 /* XPM library details.  */
 
-DEF_IMGLIB_FN (XpmFreeAttributes, (XpmAttributes *));
-DEF_IMGLIB_FN (XpmCreateImageFromBuffer, (Display *, char *, xpm_XImage **,
+DEF_IMGLIB_FN (void, XpmFreeAttributes, (XpmAttributes *));
+DEF_IMGLIB_FN (int, XpmCreateImageFromBuffer, (Display *, char *, xpm_XImage **,
                                          xpm_XImage **, XpmAttributes *));
-DEF_IMGLIB_FN (XpmReadFileToImage, (Display *, char *, xpm_XImage **,
+DEF_IMGLIB_FN (int, XpmReadFileToImage, (Display *, char *, xpm_XImage **,
                                    xpm_XImage **, XpmAttributes *));
-DEF_IMGLIB_FN (XImageFree, (xpm_XImage *));
+DEF_IMGLIB_FN (void, XImageFree, (xpm_XImage *));
 
 static int
 init_xpm_functions (Lisp_Object libraries)
@@ -3352,7 +3326,7 @@ x_create_bitmap_from_xpm_data (struct frame *f, const char **bits)
   attrs.valuemask |= XpmColormap;
 
   rc = XpmCreatePixmapFromData (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f),
-                               bits, &bitmap, &mask, &attrs);
+                               (char **) bits, &bitmap, &mask, &attrs);
   if (rc != XpmSuccess)
     {
       XpmFreeAttributes (&attrs);
@@ -3449,11 +3423,12 @@ xpm_load (struct frame *f, struct image *img)
        {
          Lisp_Object name;
          Lisp_Object color;
+         char *empty_string = (char *) "";
 
          if (!CONSP (XCAR (tail)))
            {
-             xpm_syms[i].name = "";
-             xpm_syms[i].value = "";
+             xpm_syms[i].name = empty_string;
+             xpm_syms[i].value = empty_string;
              continue;
            }
          name = XCAR (XCAR (tail));
@@ -3461,17 +3436,17 @@ xpm_load (struct frame *f, struct image *img)
          if (STRINGP (name))
            {
              xpm_syms[i].name = (char *) alloca (SCHARS (name) + 1);
-             strcpy (xpm_syms[i].name, SDATA (name));
+             strcpy (xpm_syms[i].name, SSDATA (name));
            }
          else
-           xpm_syms[i].name = "";
+           xpm_syms[i].name = empty_string;
          if (STRINGP (color))
            {
              xpm_syms[i].value = (char *) alloca (SCHARS (color) + 1);
-             strcpy (xpm_syms[i].value, SDATA (color));
+             strcpy (xpm_syms[i].value, SSDATA (color));
            }
          else
-           xpm_syms[i].value = "";
+           xpm_syms[i].value = empty_string;
        }
     }
 
@@ -3511,7 +3486,7 @@ xpm_load (struct frame *f, struct image *img)
                                  &attrs);
 #else
       rc = XpmReadFileToPixmap (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f),
-                               SDATA (file), &img->pixmap, &img->mask,
+                               SSDATA (file), &img->pixmap, &img->mask,
                                &attrs);
 #endif /* HAVE_NTGUI */
     }
@@ -3534,7 +3509,7 @@ xpm_load (struct frame *f, struct image *img)
                                        &attrs);
 #else
       rc = XpmCreatePixmapFromBuffer (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f),
-                                     SDATA (buffer),
+                                     SSDATA (buffer),
                                      &img->pixmap, &img->mask,
                                      &attrs);
 #endif /* HAVE_NTGUI */
@@ -3926,7 +3901,7 @@ xpm_load_image (struct frame *f,
 
   while (num_colors-- > 0)
     {
-      unsigned char *color, *max_color;
+      char *color, *max_color;
       int key, next_key, max_key = 0;
       Lisp_Object symbol_color = Qnil, color_val;
       XColor cdef;
@@ -3978,7 +3953,7 @@ xpm_load_image (struct frame *f,
 
          if (CONSP (specified_color) && STRINGP (XCDR (specified_color)))
            {
-             if (xstrcasecmp (SDATA (XCDR (specified_color)), "None") == 0)
+             if (xstrcasecmp (SSDATA (XCDR (specified_color)), "None") == 0)
                color_val = Qt;
              else if (x_defined_color (f, SDATA (XCDR (specified_color)),
                                        &cdef, 0))
@@ -4410,11 +4385,6 @@ static void x_detect_edges (struct frame *, struct image *, int[9], int);
 static void XPutPixel (XImagePtr , int, int, COLORREF);
 #endif /* HAVE_NTGUI */
 
-/* Non-zero means draw a cross on images having `:conversion
-   disabled'.  */
-
-int cross_disabled_images;
-
 /* Edge detection matrices for different edge-detection
    strategies.  */
 
@@ -4513,7 +4483,6 @@ static void
 XPutPixel (XImagePtr ximg, int x, int y, COLORREF color)
 {
   int width = ximg->info.bmiHeader.biWidth;
-  int height = ximg->info.bmiHeader.biHeight;
   unsigned char * pixel;
 
   /* True color images.  */
@@ -4632,14 +4601,14 @@ x_detect_edges (struct frame *f, struct image *img, int *matrix, int color_adjus
 
       for (x = 1; x < img->width - 1; ++x, ++p)
        {
-         int r, g, b, y1, x1;
+         int r, g, b, yy, xx;
 
          r = g = b = i = 0;
-         for (y1 = y - 1; y1 < y + 2; ++y1)
-           for (x1 = x - 1; x1 < x + 2; ++x1, ++i)
+         for (yy = y - 1; yy < y + 2; ++yy)
+           for (xx = x - 1; xx < x + 2; ++xx, ++i)
              if (matrix[i])
                {
-                 XColor *t = COLOR (colors, x1, y1);
+                 XColor *t = COLOR (colors, xx, yy);
                  r += matrix[i] * t->red;
                  g += matrix[i] * t->green;
                  b += matrix[i] * t->blue;
@@ -4715,7 +4684,7 @@ x_edge_detection (struct frame *f, struct image *img, Lisp_Object matrix,
     color_adjust = make_number (0xffff / 2);
 
   if (i == 9 && NUMBERP (color_adjust))
-    x_detect_edges (f, img, trans, (int) XFLOATINT (color_adjust));
+    x_detect_edges (f, img, trans, XFLOATINT (color_adjust));
 }
 
 
@@ -5126,7 +5095,7 @@ pbm_load (struct frame *f, struct image *img)
          return 0;
        }
 
-      contents = slurp_file (SDATA (file), &size);
+      contents = slurp_file (SSDATA (file), &size);
       if (contents == NULL)
        {
          image_error ("Error reading `%s'", file, Qnil);
@@ -5444,31 +5413,36 @@ png_image_p (Lisp_Object object)
 #ifdef HAVE_NTGUI
 /* PNG library details.  */
 
-DEF_IMGLIB_FN (png_get_io_ptr, (png_structp));
-DEF_IMGLIB_FN (png_sig_cmp, (png_bytep, png_size_t, png_size_t));
-DEF_IMGLIB_FN (png_create_read_struct, (png_const_charp, png_voidp,
-                                       png_error_ptr, png_error_ptr));
-DEF_IMGLIB_FN (png_create_info_struct, (png_structp));
-DEF_IMGLIB_FN (png_destroy_read_struct, (png_structpp, png_infopp, png_infopp));
-DEF_IMGLIB_FN (png_set_read_fn, (png_structp, png_voidp, png_rw_ptr));
-DEF_IMGLIB_FN (png_set_sig_bytes, (png_structp, int));
-DEF_IMGLIB_FN (png_read_info, (png_structp, png_infop));
-DEF_IMGLIB_FN (png_get_IHDR, (png_structp, png_infop,
+DEF_IMGLIB_FN (png_voidp, png_get_io_ptr, (png_structp));
+DEF_IMGLIB_FN (int, png_sig_cmp, (png_bytep, png_size_t, png_size_t));
+DEF_IMGLIB_FN (png_structp, png_create_read_struct, (png_const_charp, png_voidp,
+                                                    png_error_ptr, png_error_ptr));
+DEF_IMGLIB_FN (png_infop, png_create_info_struct, (png_structp));
+DEF_IMGLIB_FN (void, png_destroy_read_struct, (png_structpp, png_infopp, png_infopp));
+DEF_IMGLIB_FN (void, png_set_read_fn, (png_structp, png_voidp, png_rw_ptr));
+DEF_IMGLIB_FN (void, png_set_sig_bytes, (png_structp, int));
+DEF_IMGLIB_FN (void, png_read_info, (png_structp, png_infop));
+DEF_IMGLIB_FN (png_uint_32, png_get_IHDR, (png_structp, png_infop,
                              png_uint_32 *, png_uint_32 *,
                              int *, int *, int *, int *, int *));
-DEF_IMGLIB_FN (png_get_valid, (png_structp, png_infop, png_uint_32));
-DEF_IMGLIB_FN (png_set_strip_16, (png_structp));
-DEF_IMGLIB_FN (png_set_expand, (png_structp));
-DEF_IMGLIB_FN (png_set_gray_to_rgb, (png_structp));
-DEF_IMGLIB_FN (png_set_background, (png_structp, png_color_16p,
+DEF_IMGLIB_FN (png_uint_32, png_get_valid, (png_structp, png_infop, png_uint_32));
+DEF_IMGLIB_FN (void, png_set_strip_16, (png_structp));
+DEF_IMGLIB_FN (void, png_set_expand, (png_structp));
+DEF_IMGLIB_FN (void, png_set_gray_to_rgb, (png_structp));
+DEF_IMGLIB_FN (void, png_set_background, (png_structp, png_color_16p,
                                    int, int, double));
-DEF_IMGLIB_FN (png_get_bKGD, (png_structp, png_infop, png_color_16p *));
-DEF_IMGLIB_FN (png_read_update_info, (png_structp, png_infop));
-DEF_IMGLIB_FN (png_get_channels, (png_structp, png_infop));
-DEF_IMGLIB_FN (png_get_rowbytes, (png_structp, png_infop));
-DEF_IMGLIB_FN (png_read_image, (png_structp, png_bytepp));
-DEF_IMGLIB_FN (png_read_end, (png_structp, png_infop));
-DEF_IMGLIB_FN (png_error, (png_structp, png_const_charp));
+DEF_IMGLIB_FN (png_uint_32, png_get_bKGD, (png_structp, png_infop, png_color_16p *));
+DEF_IMGLIB_FN (void, png_read_update_info, (png_structp, png_infop));
+DEF_IMGLIB_FN (png_byte, png_get_channels, (png_structp, png_infop));
+DEF_IMGLIB_FN (png_size_t, png_get_rowbytes, (png_structp, png_infop));
+DEF_IMGLIB_FN (void, png_read_image, (png_structp, png_bytepp));
+DEF_IMGLIB_FN (void, png_read_end, (png_structp, png_infop));
+DEF_IMGLIB_FN (void, png_error, (png_structp, png_const_charp));
+
+#if (PNG_LIBPNG_VER >= 10500)
+DEF_IMGLIB_FN (void, png_longjmp, (png_structp, int));
+DEF_IMGLIB_FN (jmp_buf *, png_set_longjmp_fn, (png_structp, png_longjmp_ptr, size_t));
+#endif /* libpng version >= 1.5 */
 
 static int
 init_png_functions (Lisp_Object libraries)
@@ -5500,6 +5474,12 @@ init_png_functions (Lisp_Object libraries)
   LOAD_IMGLIB_FN (library, png_read_image);
   LOAD_IMGLIB_FN (library, png_read_end);
   LOAD_IMGLIB_FN (library, png_error);
+
+#if (PNG_LIBPNG_VER >= 10500)
+  LOAD_IMGLIB_FN (library, png_longjmp);
+  LOAD_IMGLIB_FN (library, png_set_longjmp_fn);
+#endif /* libpng version >= 1.5 */
+
   return 1;
 }
 #else
@@ -5526,11 +5506,28 @@ init_png_functions (Lisp_Object libraries)
 #define fn_png_read_end                        png_read_end
 #define fn_png_error                   png_error
 
+#if (PNG_LIBPNG_VER >= 10500)
+#define fn_png_longjmp                 png_longjmp
+#define fn_png_set_longjmp_fn          png_set_longjmp_fn
+#endif /* libpng version >= 1.5 */
+
 #endif /* HAVE_NTGUI */
 
+
+#if (PNG_LIBPNG_VER < 10500)
+#define PNG_LONGJMP(ptr) (longjmp ((ptr)->jmpbuf, 1))
+#define PNG_JMPBUF(ptr) ((ptr)->jmpbuf)
+#else
+/* In libpng version 1.5, the jmpbuf member is hidden. (Bug#7908)  */
+#define PNG_LONGJMP(ptr) (fn_png_longjmp ((ptr), 1))
+#define PNG_JMPBUF(ptr) \
+  (*fn_png_set_longjmp_fn((ptr), longjmp, sizeof (jmp_buf)))
+#endif
+
 /* Error and warning handlers installed when the PNG library
    is initialized.  */
 
+static void my_png_error (png_struct *, const char *) NO_RETURN;
 static void
 my_png_error (png_struct *png_ptr, const char *msg)
 {
@@ -5538,7 +5535,7 @@ my_png_error (png_struct *png_ptr, const char *msg)
   /* Avoid compiler warning about deprecated direct access to
      png_ptr's fields in libpng versions 1.4.x.  */
   image_error ("PNG error: %s", build_string (msg), Qnil);
-  longjmp (png_ptr->jmpbuf, 1);
+  PNG_LONGJMP (png_ptr);
 }
 
 
@@ -5628,7 +5625,7 @@ png_load (struct frame *f, struct image *img)
        }
 
       /* Open the image file.  */
-      fp = fopen (SDATA (file), "rb");
+      fp = fopen (SSDATA (file), "rb");
       if (!fp)
        {
          image_error ("Cannot open image file `%s'", file, Qnil);
@@ -5669,19 +5666,17 @@ png_load (struct frame *f, struct image *img)
       tbr.bytes += sizeof (sig);
     }
 
-  /* Initialize read and info structs for PNG lib.  Casting return
-     value avoids a GCC warning on W32.  */
-  png_ptr = (png_structp)fn_png_create_read_struct (PNG_LIBPNG_VER_STRING,
-                                                   NULL, my_png_error,
-                                                   my_png_warning);
+  /* Initialize read and info structs for PNG lib.  */
+  png_ptr = fn_png_create_read_struct (PNG_LIBPNG_VER_STRING,
+                                      NULL, my_png_error,
+                                      my_png_warning);
   if (!png_ptr)
     {
       if (fp) fclose (fp);
       return 0;
     }
 
-  /* Casting return value avoids a GCC warning on W32.  */
-  info_ptr = (png_infop)fn_png_create_info_struct (png_ptr);
+  info_ptr = fn_png_create_info_struct (png_ptr);
   if (!info_ptr)
     {
       fn_png_destroy_read_struct (&png_ptr, NULL, NULL);
@@ -5689,8 +5684,7 @@ png_load (struct frame *f, struct image *img)
       return 0;
     }
 
-  /* Casting return value avoids a GCC warning on W32.  */
-  end_info = (png_infop)fn_png_create_info_struct (png_ptr);
+  end_info = fn_png_create_info_struct (png_ptr);
   if (!end_info)
     {
       fn_png_destroy_read_struct (&png_ptr, &info_ptr, NULL);
@@ -5700,7 +5694,7 @@ png_load (struct frame *f, struct image *img)
 
   /* Set error jump-back.  We come back here when the PNG library
      detects an error.  */
-  if (setjmp (png_ptr->jmpbuf))
+  if (setjmp (PNG_JMPBUF (png_ptr)))
     {
     error:
       if (png_ptr)
@@ -5765,7 +5759,7 @@ png_load (struct frame *f, struct image *img)
        /* The user specified `:background', use that.  */
        {
          XColor color;
-         if (x_defined_color (f, SDATA (specified_bg), &color, 0))
+         if (x_defined_color (f, SSDATA (specified_bg), &color, 0))
            {
              png_color_16 user_bg;
 
@@ -6033,7 +6027,6 @@ jpeg_image_p (Lisp_Object object)
 /* Work around a warning about HAVE_STDLIB_H being redefined in
    jconfig.h.  */
 #ifdef HAVE_STDLIB_H
-#define HAVE_STDLIB_H_1
 #undef HAVE_STDLIB_H
 #endif /* HAVE_STLIB_H */
 
@@ -6053,14 +6046,14 @@ jpeg_image_p (Lisp_Object object)
 #ifdef HAVE_NTGUI
 
 /* JPEG library details.  */
-DEF_IMGLIB_FN (jpeg_CreateDecompress, (j_decompress_ptr, int, size_t));
-DEF_IMGLIB_FN (jpeg_start_decompress, (j_decompress_ptr));
-DEF_IMGLIB_FN (jpeg_finish_decompress, (j_decompress_ptr));
-DEF_IMGLIB_FN (jpeg_destroy_decompress, (j_decompress_ptr));
-DEF_IMGLIB_FN (jpeg_read_header, (j_decompress_ptr, boolean));
-DEF_IMGLIB_FN (jpeg_read_scanlines, (j_decompress_ptr, JSAMPARRAY, JDIMENSION));
-DEF_IMGLIB_FN (jpeg_std_error, (struct jpeg_error_mgr *));
-DEF_IMGLIB_FN (jpeg_resync_to_restart, (j_decompress_ptr, int));
+DEF_IMGLIB_FN (void, jpeg_CreateDecompress, (j_decompress_ptr, int, size_t));
+DEF_IMGLIB_FN (boolean, jpeg_start_decompress, (j_decompress_ptr));
+DEF_IMGLIB_FN (boolean, jpeg_finish_decompress, (j_decompress_ptr));
+DEF_IMGLIB_FN (void, jpeg_destroy_decompress, (j_decompress_ptr));
+DEF_IMGLIB_FN (int, jpeg_read_header, (j_decompress_ptr, boolean));
+DEF_IMGLIB_FN (JDIMENSION, jpeg_read_scanlines, (j_decompress_ptr, JSAMPARRAY, JDIMENSION));
+DEF_IMGLIB_FN (struct jpeg_error_mgr *, jpeg_std_error, (struct jpeg_error_mgr *));
+DEF_IMGLIB_FN (boolean, jpeg_resync_to_restart, (j_decompress_ptr, int));
 
 static int
 init_jpeg_functions (Lisp_Object libraries)
@@ -6109,6 +6102,7 @@ struct my_jpeg_error_mgr
 };
 
 
+static void my_error_exit (j_common_ptr) NO_RETURN;
 static void
 my_error_exit (j_common_ptr cinfo)
 {
@@ -6346,7 +6340,7 @@ jpeg_load (struct frame *f, struct image *img)
          return 0;
        }
 
-      fp = fopen (SDATA (file), "rb");
+      fp = fopen (SSDATA (file), "rb");
       if (fp == NULL)
        {
          image_error ("Cannot open `%s'", file, Qnil);
@@ -6360,9 +6354,8 @@ jpeg_load (struct frame *f, struct image *img)
     }
 
   /* Customize libjpeg's error handling to call my_error_exit when an
-     error is detected.  This function will perform a longjmp.
-     Casting return value avoids a GCC warning on W32.  */
-  cinfo.err = (struct jpeg_error_mgr *)fn_jpeg_std_error (&mgr.pub);
+     error is detected.  This function will perform a longjmp.  */
+  cinfo.err = fn_jpeg_std_error (&mgr.pub);
   mgr.pub.error_exit = my_error_exit;
 
   if ((rc = setjmp (mgr.setjmp_buffer)) != 0)
@@ -6370,10 +6363,10 @@ jpeg_load (struct frame *f, struct image *img)
       if (rc == 1)
        {
          /* Called from my_error_exit.  Display a JPEG error.  */
-         char buffer[JMSG_LENGTH_MAX];
-         cinfo.err->format_message ((j_common_ptr) &cinfo, buffer);
+         char buf[JMSG_LENGTH_MAX];
+         cinfo.err->format_message ((j_common_ptr) &cinfo, buf);
          image_error ("Error reading JPEG image `%s': %s", img->spec,
-                      build_string (buffer));
+                      build_string (buf));
        }
 
       /* Close the input file and destroy the JPEG object.  */
@@ -6586,17 +6579,17 @@ tiff_image_p (Lisp_Object object)
 #ifdef HAVE_NTGUI
 
 /* TIFF library details.  */
-DEF_IMGLIB_FN (TIFFSetErrorHandler, (TIFFErrorHandler));
-DEF_IMGLIB_FN (TIFFSetWarningHandler, (TIFFErrorHandler));
-DEF_IMGLIB_FN (TIFFOpen, (const char *, const char *));
-DEF_IMGLIB_FN (TIFFClientOpen, (const char *, const char *, thandle_t,
+DEF_IMGLIB_FN (TIFFErrorHandler, TIFFSetErrorHandler, (TIFFErrorHandler));
+DEF_IMGLIB_FN (TIFFErrorHandler, TIFFSetWarningHandler, (TIFFErrorHandler));
+DEF_IMGLIB_FN (TIFF *, TIFFOpen, (const char *, const char *));
+DEF_IMGLIB_FN (TIFF *, TIFFClientOpen, (const char *, const char *, thandle_t,
                                TIFFReadWriteProc, TIFFReadWriteProc,
                                TIFFSeekProc, TIFFCloseProc, TIFFSizeProc,
                                TIFFMapFileProc, TIFFUnmapFileProc));
-DEF_IMGLIB_FN (TIFFGetField, (TIFF *, ttag_t, ...));
-DEF_IMGLIB_FN (TIFFReadRGBAImage, (TIFF *, uint32, uint32, uint32 *, int));
-DEF_IMGLIB_FN (TIFFClose, (TIFF *));
-DEF_IMGLIB_FN (TIFFSetDirectory, (TIFF *, tdir_t));
+DEF_IMGLIB_FN (int, TIFFGetField, (TIFF *, ttag_t, ...));
+DEF_IMGLIB_FN (int, TIFFReadRGBAImage, (TIFF *, uint32, uint32, uint32 *, int));
+DEF_IMGLIB_FN (void, TIFFClose, (TIFF *));
+DEF_IMGLIB_FN (int, TIFFSetDirectory, (TIFF *, tdir_t));
 
 static int
 init_tiff_functions (Lisp_Object libraries)
@@ -6758,7 +6751,7 @@ tiff_load (struct frame *f, struct image *img)
   TIFF *tiff;
   int width, height, x, y, count;
   uint32 *buf;
-  int rc, rc2;
+  int rc;
   XImagePtr ximg;
   tiff_memory_source memsrc;
   Lisp_Object image;
@@ -6779,9 +6772,8 @@ tiff_load (struct frame *f, struct image *img)
          return 0;
        }
 
-      /* Try to open the image file.  Casting return value avoids a
-        GCC warning on W32.  */
-      tiff = (TIFF *)fn_TIFFOpen (SDATA (file), "r");
+      /* Try to open the image file.  */
+      tiff = fn_TIFFOpen (SSDATA (file), "r");
       if (tiff == NULL)
        {
          image_error ("Cannot open `%s'", file, Qnil);
@@ -6801,16 +6793,14 @@ tiff_load (struct frame *f, struct image *img)
       memsrc.len = SBYTES (specified_data);
       memsrc.index = 0;
 
-      /* Casting arguments return value avoids a GCC warning on W32.  */
-      tiff = (TIFF *)fn_TIFFClientOpen ("memory_source", "r",
-                                       (thandle_t) &memsrc,
-                                       (TIFFReadWriteProc) tiff_read_from_memory,
-                                       (TIFFReadWriteProc) tiff_write_from_memory,
-                                       tiff_seek_in_memory,
-                                       tiff_close_memory,
-                                       tiff_size_of_memory,
-                                       tiff_mmap_memory,
-                                       tiff_unmap_memory);
+      tiff = fn_TIFFClientOpen ("memory_source", "r", (thandle_t)&memsrc,
+                               (TIFFReadWriteProc) tiff_read_from_memory,
+                               (TIFFReadWriteProc) tiff_write_from_memory,
+                               tiff_seek_in_memory,
+                               tiff_close_memory,
+                               tiff_size_of_memory,
+                               tiff_mmap_memory,
+                               tiff_unmap_memory);
 
       if (!tiff)
        {
@@ -6849,8 +6839,8 @@ tiff_load (struct frame *f, struct image *img)
   rc = fn_TIFFReadRGBAImage (tiff, width, height, buf, 0);
 
   /* Count the number of images in the file.  */
-  for (count = 1, rc2 = 1; rc2; count++)
-    rc2 = fn_TIFFSetDirectory (tiff, count);
+  for (count = 1; fn_TIFFSetDirectory (tiff, count); count++)
+    continue;
 
   if (count > 1)
     img->data.lisp_val = Fcons (Qcount,
@@ -7039,10 +7029,10 @@ gif_image_p (Lisp_Object object)
 #ifdef HAVE_NTGUI
 
 /* GIF library details.  */
-DEF_IMGLIB_FN (DGifCloseFile, (GifFileType *));
-DEF_IMGLIB_FN (DGifSlurp, (GifFileType *));
-DEF_IMGLIB_FN (DGifOpen, (void *, InputFunc));
-DEF_IMGLIB_FN (DGifOpenFileName, (const char *));
+DEF_IMGLIB_FN (int, DGifCloseFile, (GifFileType *));
+DEF_IMGLIB_FN (int, DGifSlurp, (GifFileType *));
+DEF_IMGLIB_FN (GifFileType *, DGifOpen, (void *, InputFunc));
+DEF_IMGLIB_FN (GifFileType *, DGifOpenFileName, (const char *));
 
 static int
 init_gif_functions (Lisp_Object libraries)
@@ -7112,7 +7102,7 @@ gif_load (struct frame *f, struct image *img)
   Lisp_Object file, specified_file;
   Lisp_Object specified_data;
   int rc, width, height, x, y, i;
-  boolean transparent_p;
+  boolean transparent_p = 0;
   XImagePtr ximg;
   ColorMapObject *gif_color_map;
   unsigned long pixel_colors[256];
@@ -7121,7 +7111,7 @@ gif_load (struct frame *f, struct image *img)
   int ino, image_height, image_width;
   gif_memory_source memsrc;
   unsigned char *raster;
-  unsigned int transparency_color_index;
+  unsigned int transparency_color_index IF_LINT (= 0);
 
   specified_file = image_spec_value (img->spec, QCfile, NULL);
   specified_data = image_spec_value (img->spec, QCdata, NULL);
@@ -7135,9 +7125,8 @@ gif_load (struct frame *f, struct image *img)
          return 0;
        }
 
-      /* Open the GIF file.  Casting return value avoids a GCC warning
-        on W32.  */
-      gif = (GifFileType *)fn_DGifOpenFileName (SDATA (file));
+      /* Open the GIF file.  */
+      gif = fn_DGifOpenFileName (SSDATA (file));
       if (gif == NULL)
        {
          image_error ("Cannot open `%s'", file, Qnil);
@@ -7158,8 +7147,7 @@ gif_load (struct frame *f, struct image *img)
       memsrc.len = SBYTES (specified_data);
       memsrc.index = 0;
 
-      /* Casting return value avoids a GCC warning on W32.  */
-      gif = (GifFileType *) fn_DGifOpen (&memsrc, gif_read_from_memory);
+      gif = fn_DGifOpen (&memsrc, gif_read_from_memory);
       if (!gif)
        {
          image_error ("Cannot open memory source `%s'", img->spec, Qnil);
@@ -7311,9 +7299,9 @@ gif_load (struct frame *f, struct image *img)
 
          for (x = 0; x < image_width; x++)
            {
-             int i = raster[(y * image_width) + x];
+             int c = raster[(y * image_width) + x];
              XPutPixel (ximg, x + img->corners[LEFT_CORNER],
-                        row + img->corners[TOP_CORNER], pixel_colors[i]);
+                        row + img->corners[TOP_CORNER], pixel_colors[c]);
            }
 
          row += interlace_increment[pass];
@@ -7324,9 +7312,9 @@ gif_load (struct frame *f, struct image *img)
       for (y = 0; y < image_height; ++y)
        for (x = 0; x < image_width; ++x)
          {
-           int i = raster[y * image_width + x];
+           int c = raster[y * image_width + x];
            XPutPixel (ximg, x + img->corners[LEFT_CORNER],
-                      y + img->corners[TOP_CORNER], pixel_colors[i]);
+                      y + img->corners[TOP_CORNER], pixel_colors[c]);
          }
     }
 
@@ -7383,13 +7371,10 @@ gif_load (struct frame *f, struct image *img)
                                 imagemagick
 ***********************************************************************/
 #if defined (HAVE_IMAGEMAGICK)
-Lisp_Object Vimagemagick_render_type;
 
 /* The symbol `imagemagick' identifying images of this type.  */
 
 Lisp_Object Qimagemagick;
-Lisp_Object Vimagemagick_render_type;
-
 /* Indices of image specification fields in imagemagick_format, below.  */
 
 enum imagemagick_keyword_index
@@ -7522,7 +7507,7 @@ imagemagick_load_image (/* Pointer to emacs frame structure.  */
      image to see how many sub-images it contains. Pinging is faster
      than loading the image to find out things about it.  */
 
-  /* MagickWandGenesis() initializes the imagemagick library.  */
+  /* `MagickWandGenesis' initializes the imagemagick environment.  */
   MagickWandGenesis ();
   image = image_spec_value (img->spec, QCindex, NULL);
   ino = INTEGERP (image) ? XFASTINT (image) : 0;
@@ -7810,6 +7795,7 @@ imagemagick_load_image (/* Pointer to emacs frame structure.  */
 
   /* Final cleanup. image_wand should be the only resource left. */
   DestroyMagickWand (image_wand);
+  /* `MagickWandTerminus' terminates the imagemagick environment.  */
   MagickWandTerminus ();
 
   return 1;
@@ -8009,25 +7995,25 @@ svg_image_p (Lisp_Object object)
 #ifdef HAVE_NTGUI
 
 /* SVG library functions.  */
-DEF_IMGLIB_FN (rsvg_handle_new);
-DEF_IMGLIB_FN (rsvg_handle_get_dimensions);
-DEF_IMGLIB_FN (rsvg_handle_write);
-DEF_IMGLIB_FN (rsvg_handle_close);
-DEF_IMGLIB_FN (rsvg_handle_get_pixbuf);
-DEF_IMGLIB_FN (rsvg_handle_free);
-
-DEF_IMGLIB_FN (gdk_pixbuf_get_width);
-DEF_IMGLIB_FN (gdk_pixbuf_get_height);
-DEF_IMGLIB_FN (gdk_pixbuf_get_pixels);
-DEF_IMGLIB_FN (gdk_pixbuf_get_rowstride);
-DEF_IMGLIB_FN (gdk_pixbuf_get_colorspace);
-DEF_IMGLIB_FN (gdk_pixbuf_get_n_channels);
-DEF_IMGLIB_FN (gdk_pixbuf_get_has_alpha);
-DEF_IMGLIB_FN (gdk_pixbuf_get_bits_per_sample);
-
-DEF_IMGLIB_FN (g_type_init);
-DEF_IMGLIB_FN (g_object_unref);
-DEF_IMGLIB_FN (g_error_free);
+DEF_IMGLIB_FN (RsvgHandle *, rsvg_handle_new);
+DEF_IMGLIB_FN (void, rsvg_handle_get_dimensions);
+DEF_IMGLIB_FN (gboolean, rsvg_handle_write);
+DEF_IMGLIB_FN (gboolean, rsvg_handle_close);
+DEF_IMGLIB_FN (GdkPixbuf *, rsvg_handle_get_pixbuf);
+DEF_IMGLIB_FN (void, rsvg_handle_free);
+
+DEF_IMGLIB_FN (int, gdk_pixbuf_get_width);
+DEF_IMGLIB_FN (int, gdk_pixbuf_get_height);
+DEF_IMGLIB_FN (guchar *, gdk_pixbuf_get_pixels);
+DEF_IMGLIB_FN (int, gdk_pixbuf_get_rowstride);
+DEF_IMGLIB_FN (GdkColorspace, gdk_pixbuf_get_colorspace);
+DEF_IMGLIB_FN (int, gdk_pixbuf_get_n_channels);
+DEF_IMGLIB_FN (gboolean, gdk_pixbuf_get_has_alpha);
+DEF_IMGLIB_FN (int, gdk_pixbuf_get_bits_per_sample);
+
+DEF_IMGLIB_FN (void, g_type_init);
+DEF_IMGLIB_FN (void, g_object_unref);
+DEF_IMGLIB_FN (void, g_error_free);
 
 Lisp_Object Qgdk_pixbuf, Qglib, Qgobject;
 
@@ -8174,7 +8160,7 @@ svg_load_image (struct frame *f,         /* Pointer to emacs frame structure.  *
      gnome type library functions.  */
   fn_g_type_init ();
   /* Make a handle to a new rsvg object.  */
-  rsvg_handle = (RsvgHandle *) fn_rsvg_handle_new ();
+  rsvg_handle = fn_rsvg_handle_new ();
 
   /* Parse the contents argument and fill in the rsvg_handle.  */
   fn_rsvg_handle_write (rsvg_handle, contents, size, &error);
@@ -8194,14 +8180,14 @@ svg_load_image (struct frame *f,         /* Pointer to emacs frame structure.  *
 
   /* We can now get a valid pixel buffer from the svg file, if all
      went ok.  */
-  pixbuf = (GdkPixbuf *) fn_rsvg_handle_get_pixbuf (rsvg_handle);
+  pixbuf = fn_rsvg_handle_get_pixbuf (rsvg_handle);
   if (!pixbuf) goto rsvg_error;
   fn_g_object_unref (rsvg_handle);
 
   /* Extract some meta data from the svg handle.  */
   width     = fn_gdk_pixbuf_get_width (pixbuf);
   height    = fn_gdk_pixbuf_get_height (pixbuf);
-  pixels    = (const guint8 *) fn_gdk_pixbuf_get_pixels (pixbuf);
+  pixels    = fn_gdk_pixbuf_get_pixels (pixbuf);
   rowstride = fn_gdk_pixbuf_get_rowstride (pixbuf);
 
   /* Validate the svg meta data.  */
@@ -8713,13 +8699,13 @@ syms_of_image (void)
 
   /* Must be defined now becase we're going to update it below, while
      defining the supported image types.  */
-  DEFVAR_LISP ("image-types", &Vimage_types,
+  DEFVAR_LISP ("image-types", Vimage_types,
     doc: /* List of potentially supported image types.
 Each element of the list is a symbol for an image type, like 'jpeg or 'png.
 To check whether it is really supported, use `image-type-available-p'.  */);
   Vimage_types = Qnil;
 
-  DEFVAR_LISP ("max-image-size", &Vmax_image_size,
+  DEFVAR_LISP ("max-image-size", Vmax_image_size,
     doc: /* Maximum size of images.
 Emacs will not load an image into memory if its pixel width or
 pixel height exceeds this limit.
@@ -8803,11 +8789,13 @@ non-numeric, there is no explicit limit on the size of images.  */);
 #ifdef HAVE_NTGUI
   Qlibpng_version = intern_c_string ("libpng-version");
   staticpro (&Qlibpng_version);
+  Fset (Qlibpng_version,
 #if HAVE_PNG
-  SET_SYMBOL_VAL (XSYMBOL (Qlibpng_version), make_number (PNG_LIBPNG_VER));
+       make_number (PNG_LIBPNG_VER)
 #else
-  SET_SYMBOL_VAL (XSYMBOL (Qlibpng_version), make_number (-1));
+       make_number (-1)
 #endif
+       );
 #endif
 
 #if defined (HAVE_XPM) || defined (HAVE_NS)
@@ -8876,17 +8864,17 @@ non-numeric, there is no explicit limit on the size of images.  */);
   defsubr (&Slookup_image);
 #endif
 
-  DEFVAR_BOOL ("cross-disabled-images", &cross_disabled_images,
+  DEFVAR_BOOL ("cross-disabled-images", cross_disabled_images,
     doc: /* Non-nil means always draw a cross over disabled images.
 Disabled images are those having a `:conversion disabled' property.
 A cross is always drawn on black & white displays.  */);
   cross_disabled_images = 0;
 
-  DEFVAR_LISP ("x-bitmap-file-path", &Vx_bitmap_file_path,
+  DEFVAR_LISP ("x-bitmap-file-path", Vx_bitmap_file_path,
     doc: /* List of directories to search for window system bitmap files.  */);
   Vx_bitmap_file_path = decode_env_path ((char *) 0, PATH_BITMAPS);
 
-  DEFVAR_LISP ("image-cache-eviction-delay", &Vimage_cache_eviction_delay,
+  DEFVAR_LISP ("image-cache-eviction-delay", Vimage_cache_eviction_delay,
     doc: /* Maximum time after which images are removed from the cache.
 When an image has not been displayed this many seconds, Emacs
 automatically removes it from the image cache.  If the cache contains
@@ -8896,7 +8884,7 @@ The value can also be nil, meaning the cache is never cleared.
 The function `clear-image-cache' disregards this variable.  */);
   Vimage_cache_eviction_delay = make_number (300);
 #ifdef HAVE_IMAGEMAGICK
-  DEFVAR_LISP ("imagemagick-render-type", &Vimagemagick_render_type,
+  DEFVAR_LISP ("imagemagick-render-type", Vimagemagick_render_type,
                doc: /* Choose between ImageMagick render methods.  */);
 #endif
 
@@ -8906,6 +8894,3 @@ void
 init_image (void)
 {
 }
-
-/* arch-tag: 123c2a5e-14a8-4c53-ab95-af47d7db49b9
-   (do not change this comment) */