changeset 25628:98e238950125

(x_build_heuristic_mask): Accept a list `(R G B)' as background color specification instead of an integer. (image-cache-eviction-delay): Replaces image-eviction-seconds. (Vimage_cache_eviction_delay): Replaces Vimage_eviction_seconds. (clear_image_cache, syms_of_xfns): Use it. (Qpostscript): Replaces Qghostscript. (gs_type): Use it. (gs_image_p): Ditto. (syms_of_xfns): Initialize Qpostscript.
author Gerd Moellmann <gerd@gnu.org>
date Fri, 10 Sep 1999 16:19:34 +0000
parents 157324e02b30
children ddc2a0543928
files src/xfns.c
diffstat 1 files changed, 52 insertions(+), 23 deletions(-) [+]
line wrap: on
line diff
--- a/src/xfns.c	Fri Sep 10 16:19:33 1999 +0000
+++ b/src/xfns.c	Fri Sep 10 16:19:34 1999 +0000
@@ -5460,7 +5460,7 @@
 /* Time in seconds after which images should be removed from the cache
    if not displayed.  */
 
-Lisp_Object Vimage_eviction_seconds;
+Lisp_Object Vimage_cache_eviction_delay;
 
 /* Function prototypes.  */
 
@@ -5989,14 +5989,14 @@
 {
   struct image_cache *c = FRAME_X_IMAGE_CACHE (f);
 
-  if (c && INTEGERP (Vimage_eviction_seconds))
+  if (c && INTEGERP (Vimage_cache_eviction_delay))
     {
       EMACS_TIME t;
       unsigned long old;
       int i, any_freed_p = 0;
 
       EMACS_GET_TIME (t);
-      old = EMACS_SECS (t) - XFASTINT (Vimage_eviction_seconds);
+      old = EMACS_SECS (t) - XFASTINT (Vimage_cache_eviction_delay);
       
       for (i = 0; i < c->used; ++i)
 	{
@@ -7516,10 +7516,10 @@
 
 /* Build a mask for image IMG which is used on frame F.  FILE is the
    name of an image file, for error messages.  HOW determines how to
-   determine the background color of IMG.  If it is an integer, take
-   that as the pixel value of the background.  Otherwise, determine
-   the background color of IMG heuristically.  Value is non-zero
-   if successful.  */
+   determine the background color of IMG.  If it is a list '(R G B)',
+   with R, G, and B being integers >= 0, take that as the color of the
+   background.  Otherwise, determine the background color of IMG
+   heuristically.  Value is non-zero if successful. */
 
 static int
 x_build_heuristic_mask (f, file, img, how)
@@ -7531,7 +7531,7 @@
   Display *dpy = FRAME_X_DISPLAY (f);
   Window win = FRAME_X_WINDOW (f);
   XImage *ximg, *mask_img;
-  int x, y, rc;
+  int x, y, rc, look_at_corners_p;
   unsigned long bg;
 
   BLOCK_INPUT;
@@ -7549,12 +7549,41 @@
   ximg = XGetImage (dpy, img->pixmap, 0, 0, img->width, img->height,
 		    ~0, ZPixmap);
 
-  /* Determine the background color of ximg.  If HOW is an integer,
-     take that as a pixel color.  Otherwise, try to determine the
-     color heuristically.  */
-  if (NATNUMP (how))
-    bg = XFASTINT (how);
-  else
+  /* Determine the background color of ximg.  If HOW is `(R G B)'
+     take that as color.  Otherwise, try to determine the color
+     heuristically. */
+  look_at_corners_p = 1;
+  
+  if (CONSP (how))
+    {
+      int rgb[3], i = 0;
+
+      while (i < 3
+	     && CONSP (how)
+	     && NATNUMP (XCAR (how)))
+	{
+	  rgb[i] = XFASTINT (XCAR (how)) & 0xffff;
+	  how = XCDR (how);
+	}
+
+      if (i == 3 && NILP (how))
+	{
+	  char color_name[30];
+	  XColor exact, color;
+	  Colormap cmap;
+
+	  sprintf (color_name, "#%04x%04x%04x", rgb[0], rgb[1], rgb[2]);
+	  
+	  cmap = DefaultColormapOfScreen (FRAME_X_SCREEN (f));
+	  if (XLookupColor (dpy, cmap, color_name, &exact, &color))
+	    {
+	      bg = color.pixel;
+	      look_at_corners_p = 0;
+	    }
+	}
+    }
+  
+  if (look_at_corners_p)
     {
       unsigned long corners[4];
       int i, best_count;
@@ -8990,9 +9019,9 @@
 static int gs_load P_ ((struct frame *f, struct image *img));
 static void gs_clear_image P_ ((struct frame *f, struct image *img));
 
-/* The symbol `ghostscript' identifying images of this type.  */
-
-Lisp_Object Qghostscript;
+/* The symbol `postscript' identifying images of this type.  */
+
+Lisp_Object Qpostscript;
 
 /* Keyword symbols.  */
 
@@ -9038,7 +9067,7 @@
 
 static struct image_type gs_type =
 {
-  &Qghostscript,
+  &Qpostscript,
   gs_image_p,
   gs_load,
   gs_clear_image,
@@ -9072,7 +9101,7 @@
   
   bcopy (gs_format, fmt, sizeof fmt);
   
-  if (!parse_image_spec (object, fmt, GS_LAST, Qghostscript, 1)
+  if (!parse_image_spec (object, fmt, GS_LAST, Qpostscript, 1)
       || (fmt[GS_ASCENT].count 
 	  && XFASTINT (fmt[GS_ASCENT].value) > 100))
     return 0;
@@ -10289,12 +10318,12 @@
 Chinese, Japanese, and Korean.");
   Vx_pixel_size_width_font_regexp = Qnil;
 
-  DEFVAR_LISP ("image-eviction-seconds", &Vimage_eviction_seconds,
+  DEFVAR_LISP ("image-cache-eviction-delay", &Vimage_cache_eviction_delay,
      "Time after which cached images are removed from the cache.\n\
 When an image has not been displayed this many seconds, remove it\n\
 from the image cache.  Value must be an integer or nil with nil\n\
 meaning don't clear the cache.");
-  Vimage_eviction_seconds = make_number (30 * 60);
+  Vimage_cache_eviction_delay = make_number (30 * 60);
 
   DEFVAR_LISP ("image-types", &Vimage_types,
      "List of supported image types.\n\
@@ -10390,8 +10419,8 @@
   staticpro (&QCmargin);
   QCrelief = intern (":relief");
   staticpro (&QCrelief);
-  Qghostscript = intern ("ghostscript");
-  staticpro (&Qghostscript);
+  Qpostscript = intern ("postscript");
+  staticpro (&Qpostscript);
   QCloader = intern (":loader");
   staticpro (&QCloader);
   QCbounding_box = intern (":bounding-box");