changeset 31693:8e9fb2a048ac

(x_clear_image_1): New function. (x_clear_image): Use it. (x_from_xcolors): Use x_clear_image_1; don't free the image's mask.
author Gerd Moellmann <gerd@gnu.org>
date Mon, 18 Sep 2000 13:17:55 +0000
parents ca8dfb4718e6
children 97c48afc4c5a
files src/xfns.c
diffstat 1 files changed, 48 insertions(+), 34 deletions(-) [+]
line wrap: on
line diff
--- a/src/xfns.c	Mon Sep 18 12:25:57 2000 +0000
+++ b/src/xfns.c	Mon Sep 18 13:17:55 2000 +0000
@@ -5478,7 +5478,7 @@
 
   /* If IMG doesn't have a pixmap yet, load it now, using the image
      type dependent loader function.  */
-  if (img->pixmap == 0 && !img->load_failed_p)
+  if (img->pixmap == None && !img->load_failed_p)
     img->load_failed_p = img->type->load (f, img) == 0;
 }
      
@@ -5513,12 +5513,47 @@
 		  Helper functions for X image types
  ***********************************************************************/
 
+static void x_clear_image_1 P_ ((struct frame *, struct image *, int,
+				 int, int));
 static void x_clear_image P_ ((struct frame *f, struct image *img));
 static unsigned long x_alloc_image_color P_ ((struct frame *f,
 					      struct image *img,
 					      Lisp_Object color_name,
 					      unsigned long dflt));
 
+
+/* Clear X resources of image IMG on frame F.  PIXMAP_P non-zero means
+   free the pixmap if any.  MASK_P non-zero means clear the mask
+   pixmap if any.  COLORS_P non-zero means free colors allocated for
+   the image, if any.  */
+
+static void
+x_clear_image_1 (f, img, pixmap_p, mask_p, colors_p)
+     struct frame *f;
+     struct image *img;
+     int pixmap_p, mask_p, colors_p;
+{
+  if (pixmap_p && img->pixmap)
+    {
+      XFreePixmap (FRAME_X_DISPLAY (f), img->pixmap);
+      img->pixmap = None;
+    }
+
+  if (mask_p && img->mask)
+    {
+      XFreePixmap (FRAME_X_DISPLAY (f), img->mask);
+      img->mask = None;
+    }
+      
+  if (colors_p && img->ncolors)
+    {
+      x_free_colors (f, img->colors, img->ncolors);
+      xfree (img->colors);
+      img->colors = NULL;
+      img->ncolors = 0;
+    }
+}
+
 /* Free X resources of image IMG which is used on frame F.  */
 
 static void
@@ -5527,27 +5562,7 @@
      struct image *img;
 {
   BLOCK_INPUT;
-  
-  if (img->pixmap)
-    {
-      XFreePixmap (FRAME_X_DISPLAY (f), img->pixmap);
-      img->pixmap = 0;
-    }
-
-  if (img->mask)
-    {
-      XFreePixmap (FRAME_X_DISPLAY (f), img->mask);
-      img->mask = 0;
-    }
-      
-  if (img->ncolors)
-    {
-      x_free_colors (f, img->colors, img->ncolors);
-      xfree (img->colors);
-      img->colors = NULL;
-      img->ncolors = 0;
-    }
-  
+  x_clear_image_1 (f, img, 1, 1, 1);
   UNBLOCK_INPUT;
 }
 
@@ -5837,7 +5852,7 @@
 		  else if (NILP (mask) && found_p && img->mask)
 		    {
 		      XFreePixmap (FRAME_X_DISPLAY (f), img->mask);
-		      img->mask = 0;
+		      img->mask = None;
 		    }
     		}
 	    }
@@ -5865,9 +5880,8 @@
 				      Fplist_get (tem, QCcolor_adjustment));
 		}
 	    }
-
 	}
-      
+
       UNBLOCK_INPUT;
       xassert (!interrupt_input_blocked);
     }
@@ -5990,7 +6004,7 @@
 
   /* Allocate a pixmap of the same size.  */
   *pixmap = XCreatePixmap (display, window, width, height, depth);
-  if (*pixmap == 0)
+  if (*pixmap == None)
     {
       x_destroy_x_image (*ximg);
       *ximg = NULL;
@@ -6575,7 +6589,7 @@
 				       depth);
       xfree (data);
 
-      if (img->pixmap == 0)
+      if (img->pixmap == None)
 	{
 	  x_clear_image (f, img);
 	  image_error ("Unable to create X pixmap for `%s'", img->spec, Qnil);
@@ -7454,7 +7468,7 @@
       }
 
   xfree (colors);
-  x_clear_image (f, img);
+  x_clear_image_1 (f, img, 1, 0, 1);
 
   x_put_x_image (f, oimg, pixmap, img->width, img->height);
   x_destroy_x_image (oimg);
@@ -7611,7 +7625,7 @@
      struct image *img;
 {
   struct x_display_info *dpyinfo = FRAME_X_DISPLAY_INFO (f);
-  
+
   if (dpyinfo->n_planes >= 2)
     {
       /* Color (or grayscale).  Convert to gray, and equalize.  Just
@@ -7684,9 +7698,9 @@
   if (img->mask)
     {
       XFreePixmap (FRAME_X_DISPLAY (f), img->mask);
-      img->mask = 0;
-    }
-  
+      img->mask = None;
+    }
+
   /* Create an image and pixmap serving as mask.  */
   rc = x_create_x_image_and_pixmap (f, img->width, img->height, 1,
 				    &mask_img, &img->mask);
@@ -8471,7 +8485,7 @@
     {
       x_destroy_x_image (ximg);
       XFreePixmap (FRAME_X_DISPLAY (f), img->pixmap);
-      img->pixmap = 0;
+      img->pixmap = None;
       goto error;
     }
 
@@ -9691,7 +9705,7 @@
   img->height = in_height * FRAME_X_DISPLAY_INFO (f)->resy;
 
   /* Create the pixmap.  */
-  xassert (img->pixmap == 0);
+  xassert (img->pixmap == None);
   img->pixmap = XCreatePixmap (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f),
 			       img->width, img->height,
 			       DefaultDepthOfScreen (FRAME_X_SCREEN (f)));