aboutsummaryrefslogtreecommitdiffstats
path: root/lisp
diff options
context:
space:
mode:
authorLars Ingebrigtsen2021-03-12 02:37:10 +0100
committerLars Ingebrigtsen2021-03-12 02:37:10 +0100
commit5dff53f5da4f17d74a0ad2cd7ec0a736aa5111f7 (patch)
treefcbed253917168c3efa191e5a15e98185125d89d /lisp
parentfd3705adf9fe73dfd5becfe4afbd4673e71942b8 (diff)
downloademacs-5dff53f5da4f17d74a0ad2cd7ec0a736aa5111f7.tar.gz
emacs-5dff53f5da4f17d74a0ad2cd7ec0a736aa5111f7.zip
Add a new `image-transform-smoothing' user option
* doc/lispref/display.texi (Image Descriptors): Document it. * lisp/image.el (image-transform-smoothing): New user option. (create-image): Use it. (image--default-smoothing): New function.
Diffstat (limited to 'lisp')
-rw-r--r--lisp/image.el51
1 files changed, 46 insertions, 5 deletions
diff --git a/lisp/image.el b/lisp/image.el
index 6955a90de77..4ede1fbf375 100644
--- a/lisp/image.el
+++ b/lisp/image.el
@@ -141,6 +141,18 @@ based on the font pixel size."
141 (const :tag "Automatically compute" auto)) 141 (const :tag "Automatically compute" auto))
142 :version "26.1") 142 :version "26.1")
143 143
144(defcustom image-transform-smoothing #'image--default-smoothing
145 "Whether to do smoothing when applying transforms to images.
146Common transforms are rescaling and rotation.
147
148Valid values are nil (no smoothing), t (smoothing) or a predicate
149function that is called with the image specification and should return
150either nil or non-nil."
151 :type '(choice (const :tag "Do smoothing" t)
152 (const :tag "No smoothing" nil)
153 function)
154 :version "28.1")
155
144(defcustom image-use-external-converter nil 156(defcustom image-use-external-converter nil
145 "If non-nil, `create-image' will use external converters for exotic formats. 157 "If non-nil, `create-image' will use external converters for exotic formats.
146Emacs handles most of the common image formats (SVG, JPEG, PNG, GIF 158Emacs handles most of the common image formats (SVG, JPEG, PNG, GIF
@@ -485,11 +497,40 @@ Image file names that are not absolute are searched for in the
485 type 'png 497 type 'png
486 data-p t))) 498 data-p t)))
487 (when (image-type-available-p type) 499 (when (image-type-available-p type)
488 (append (list 'image :type type (if data-p :data :file) file-or-data) 500 (let ((image
489 (and (not (plist-get props :scale)) 501 (append (list 'image :type type (if data-p :data :file)
490 (list :scale 502 file-or-data)
491 (image-compute-scaling-factor image-scaling-factor))) 503 (and (not (plist-get props :scale))
492 props))) 504 ;; Add default scaling.
505 (list :scale
506 (image-compute-scaling-factor
507 image-scaling-factor)))
508 props)))
509 ;; Add default smoothing.
510 (unless (plist-member props :transform-smoothing)
511 (setq image (nconc image
512 (list :transform-smoothing
513 (pcase image-transform-smoothing
514 ('t t)
515 ('nil nil)
516 (func (funcall func image)))))))
517 image)))
518
519(defun image--default-smoothing (image)
520 "Say whether IMAGE should be smoothed when transformed."
521 (let* ((props (nthcdr 5 image))
522 (scaling (plist-get props :scale))
523 (rotation (plist-get props :rotation)))
524 (cond
525 ;; We always smooth when scaling down and small upwards scaling.
526 ((and scaling (< scaling 2))
527 t)
528 ;; Smooth when doing non-90-degree rotation
529 ((and rotation
530 (or (not (zerop (mod rotation 1)))
531 (not (zerop (% (truncate rotation) 90)))))
532 t)
533 (t nil))))
493 534
494(defun image--set-property (image property value) 535(defun image--set-property (image property value)
495 "Set PROPERTY in IMAGE to VALUE. 536 "Set PROPERTY in IMAGE to VALUE.