aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorChong Yidong2007-06-03 00:23:33 +0000
committerChong Yidong2007-06-03 00:23:33 +0000
commitd3c35d17036e0b9f409e26a0491989a336849a4f (patch)
tree91cc02503fc2c061531f0876c8ba8694bdcb7192 /src
parentd94df25b2d0193b1a0130e160d8fe19cb4e0645c (diff)
downloademacs-d3c35d17036e0b9f409e26a0491989a336849a4f.tar.gz
emacs-d3c35d17036e0b9f409e26a0491989a336849a4f.zip
(search_image_cache): New function. Require background
color match if background color is unspecified in the image spec. (uncache_image, lookup_image): Use it.
Diffstat (limited to 'src')
-rw-r--r--src/image.c55
1 files changed, 36 insertions, 19 deletions
diff --git a/src/image.c b/src/image.c
index 11f4425136c..789de0223be 100644
--- a/src/image.c
+++ b/src/image.c
@@ -1609,6 +1609,7 @@ x_alloc_image_color (f, img, color_name, dflt)
1609 Image Cache 1609 Image Cache
1610 ***********************************************************************/ 1610 ***********************************************************************/
1611 1611
1612static struct image *search_image_cache P_ ((struct frame *, Lisp_Object, unsigned));
1612static void cache_image P_ ((struct frame *f, struct image *img)); 1613static void cache_image P_ ((struct frame *f, struct image *img));
1613static void postprocess_image P_ ((struct frame *, struct image *)); 1614static void postprocess_image P_ ((struct frame *, struct image *));
1614 1615
@@ -1631,24 +1632,47 @@ make_image_cache ()
1631} 1632}
1632 1633
1633 1634
1634/* Search frame F for an images with spec SPEC, and free it. */ 1635/* Find an image matching SPEC in the cache, and return it. If no
1635 1636 image is found, return NULL. */
1636static void 1637static struct image *
1637uncache_image (f, spec) 1638search_image_cache (f, spec, hash)
1638 struct frame *f; 1639 struct frame *f;
1639 Lisp_Object spec; 1640 Lisp_Object spec;
1641 unsigned hash;
1640{ 1642{
1641 struct image_cache *c = FRAME_X_IMAGE_CACHE (f);
1642 struct image *img; 1643 struct image *img;
1643 unsigned hash = sxhash (spec, 0); 1644 struct image_cache *c = FRAME_X_IMAGE_CACHE (f);
1645 Lisp_Object specified_bg = image_spec_value (spec, QCbackground, NULL);
1644 int i = hash % IMAGE_CACHE_BUCKETS_SIZE; 1646 int i = hash % IMAGE_CACHE_BUCKETS_SIZE;
1645 1647
1648 /* If the image spec does not specify a background color, the cached
1649 image must have the same background color as the current frame.
1650 The following code be improved. For example, jpeg does not
1651 support transparency, but currently a jpeg image spec won't match
1652 a cached spec created with a different frame background. The
1653 extra memory usage is probably negligible in practice. */
1654 if (!c) return NULL;
1655
1646 for (img = c->buckets[i]; img; img = img->next) 1656 for (img = c->buckets[i]; img; img = img->next)
1647 if (img->hash == hash && !NILP (Fequal (img->spec, spec))) 1657 if (img->hash == hash
1648 { 1658 && !NILP (Fequal (img->spec, spec))
1649 free_image (f, img); 1659 && (STRINGP (specified_bg)
1650 break; 1660 || img->background == FRAME_BACKGROUND_PIXEL (f)))
1651 } 1661 break;
1662 return img;
1663}
1664
1665
1666/* Search frame F for an image with spec SPEC, and free it. */
1667
1668static void
1669uncache_image (f, spec)
1670 struct frame *f;
1671 Lisp_Object spec;
1672{
1673 struct image *img = search_image_cache (f, spec, sxhash (spec, 0));
1674 if (img)
1675 free_image (f, img);
1652} 1676}
1653 1677
1654 1678
@@ -1875,9 +1899,7 @@ lookup_image (f, spec)
1875 struct frame *f; 1899 struct frame *f;
1876 Lisp_Object spec; 1900 Lisp_Object spec;
1877{ 1901{
1878 struct image_cache *c = FRAME_X_IMAGE_CACHE (f);
1879 struct image *img; 1902 struct image *img;
1880 int i;
1881 unsigned hash; 1903 unsigned hash;
1882 struct gcpro gcpro1; 1904 struct gcpro gcpro1;
1883 EMACS_TIME now; 1905 EMACS_TIME now;
@@ -1891,12 +1913,7 @@ lookup_image (f, spec)
1891 1913
1892 /* Look up SPEC in the hash table of the image cache. */ 1914 /* Look up SPEC in the hash table of the image cache. */
1893 hash = sxhash (spec, 0); 1915 hash = sxhash (spec, 0);
1894 i = hash % IMAGE_CACHE_BUCKETS_SIZE; 1916 img = search_image_cache (f, spec, hash);
1895
1896 for (img = c->buckets[i]; img; img = img->next)
1897 if (img->hash == hash && !NILP (Fequal (img->spec, spec)))
1898 break;
1899
1900 if (img && img->load_failed_p) 1917 if (img && img->load_failed_p)
1901 { 1918 {
1902 free_image (f, img); 1919 free_image (f, img);