aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--etc/NEWS6
-rw-r--r--lisp/image.el60
2 files changed, 48 insertions, 18 deletions
diff --git a/etc/NEWS b/etc/NEWS
index dab42d83cc5..f10573b86b3 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -1880,6 +1880,12 @@ Emacs buffers, like indentation and the like. The new ert function
1880 1880
1881* Incompatible Lisp Changes in Emacs 29.1 1881* Incompatible Lisp Changes in Emacs 29.1
1882 1882
1883---
1884** 'find-image' now uses 'create-image'.
1885This means that images found through 'find-image' also has
1886auto-scaling applied. (This only makes a difference on HiDPI
1887displays.)
1888
1883+++ 1889+++
1884** Changes to "raw" in-memory xbm images are specified. 1890** Changes to "raw" in-memory xbm images are specified.
1885Some years back Emacs gained the ability to scale images, and you 1891Some years back Emacs gained the ability to scale images, and you
diff --git a/lisp/image.el b/lisp/image.el
index 1b684d5c57a..24d1c2d1698 100644
--- a/lisp/image.el
+++ b/lisp/image.el
@@ -764,13 +764,15 @@ SPECS is a list of image specifications.
764 764
765Each image specification in SPECS is a property list. The contents of 765Each image specification in SPECS is a property list. The contents of
766a specification are image type dependent. All specifications must at 766a specification are image type dependent. All specifications must at
767least contain the properties `:type TYPE' and either `:file FILE' or 767least contain the either the property `:file FILE' or `:data DATA',
768`:data DATA', where TYPE is a symbol specifying the image type, 768where FILE is the file to load the image from, and DATA is a string
769e.g. `xbm', FILE is the file to load the image from, and DATA is a 769containing the actual image data. If the property `:type TYPE' is
770string containing the actual image data. The specification whose TYPE 770omitted or nil, try to determine the image type from its first few
771is supported, and FILE exists, is used to construct the image 771bytes of image data. If that doesn’t work, and the property `:file
772specification to be returned. Return nil if no specification is 772FILE' provide a file name, use its file extension as image type. If
773satisfied. 773the property `:type TYPE' is provided, it must match the actual type
774determined for FILE or DATA by `create-image'. Return nil if no
775specification is satisfied.
774 776
775If CACHE is non-nil, results are cached and returned on subsequent calls. 777If CACHE is non-nil, results are cached and returned on subsequent calls.
776 778
@@ -785,22 +787,44 @@ Image files should not be larger than specified by `max-image-size'."
785 (let* ((spec (car specs)) 787 (let* ((spec (car specs))
786 (type (plist-get spec :type)) 788 (type (plist-get spec :type))
787 (data (plist-get spec :data)) 789 (data (plist-get spec :data))
788 (file (plist-get spec :file)) 790 (file (plist-get spec :file)))
789 found) 791 (cond
790 (when (image-type-available-p type) 792 ((stringp file)
791 (cond ((stringp file) 793 (when (setq file (image-search-load-path file))
792 (if (setq found (image-search-load-path file)) 794 ;; At this point, remove the :type and :file properties.
793 (setq image 795 ;; `create-image' will set them depending on image file.
794 (cons 'image (plist-put (copy-sequence spec) 796 (setq image (cons 'image (copy-sequence spec)))
795 :file found))))) 797 (setf (image-property image :type) nil)
796 ((not (null data)) 798 (setf (image-property image :file) nil)
797 (setq image (cons 'image spec))))) 799 (and (setq image (ignore-errors
800 (apply #'create-image file nil nil
801 (cdr image))))
802 ;; Ensure, if a type has been provided, it is
803 ;; consistent with the type returned by
804 ;; `create-image'. If not, return nil.
805 (not (null type))
806 (not (eq type (image-property image :type)))
807 (setq image nil))))
808 ((not (null data))
809 ;; At this point, remove the :type and :data properties.
810 ;; `create-image' will set them depending on image data.
811 (setq image (cons 'image (copy-sequence spec)))
812 (setf (image-property image :type) nil)
813 (setf (image-property image :data) nil)
814 (and (setq image (ignore-errors
815 (apply #'create-image data nil t
816 (cdr image))))
817 ;; Ensure, if a type has been provided, it is
818 ;; consistent with the type returned by
819 ;; `create-image'. If not, return nil.
820 (not (null type))
821 (not (eq type (image-property image :type)))
822 (setq image nil))))
798 (setq specs (cdr specs)))) 823 (setq specs (cdr specs))))
799 (when cache 824 (when cache
800 (setf (gethash orig-specs find-image--cache) image)) 825 (setf (gethash orig-specs find-image--cache) image))
801 image))) 826 image)))
802 827
803
804;;;###autoload 828;;;###autoload
805(defmacro defimage (symbol specs &optional doc) 829(defmacro defimage (symbol specs &optional doc)
806 "Define SYMBOL as an image, and return SYMBOL. 830 "Define SYMBOL as an image, and return SYMBOL.