diff options
author | Lars Ingebrigtsen <larsi@gnus.org> | 2021-03-12 02:37:10 +0100 |
---|---|---|
committer | Lars Ingebrigtsen <larsi@gnus.org> | 2021-03-12 02:37:10 +0100 |
commit | 5dff53f5da4f17d74a0ad2cd7ec0a736aa5111f7 (patch) | |
tree | fcbed253917168c3efa191e5a15e98185125d89d /lisp/image.el | |
parent | fd3705adf9fe73dfd5becfe4afbd4673e71942b8 (diff) | |
download | emacs-5dff53f5da4f17d74a0ad2cd7ec0a736aa5111f7.tar.gz |
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/image.el')
-rw-r--r-- | lisp/image.el | 51 |
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." (const :tag "Automatically compute" auto)) :version "26.1") +(defcustom image-transform-smoothing #'image--default-smoothing + "Whether to do smoothing when applying transforms to images. +Common transforms are rescaling and rotation. + +Valid values are nil (no smoothing), t (smoothing) or a predicate +function that is called with the image specification and should return +either nil or non-nil." + :type '(choice (const :tag "Do smoothing" t) + (const :tag "No smoothing" nil) + function) + :version "28.1") + (defcustom image-use-external-converter nil "If non-nil, `create-image' will use external converters for exotic formats. Emacs 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 type 'png data-p t))) (when (image-type-available-p type) - (append (list 'image :type type (if data-p :data :file) file-or-data) - (and (not (plist-get props :scale)) - (list :scale - (image-compute-scaling-factor image-scaling-factor))) - props))) + (let ((image + (append (list 'image :type type (if data-p :data :file) + file-or-data) + (and (not (plist-get props :scale)) + ;; Add default scaling. + (list :scale + (image-compute-scaling-factor + image-scaling-factor))) + props))) + ;; Add default smoothing. + (unless (plist-member props :transform-smoothing) + (setq image (nconc image + (list :transform-smoothing + (pcase image-transform-smoothing + ('t t) + ('nil nil) + (func (funcall func image))))))) + image))) + +(defun image--default-smoothing (image) + "Say whether IMAGE should be smoothed when transformed." + (let* ((props (nthcdr 5 image)) + (scaling (plist-get props :scale)) + (rotation (plist-get props :rotation))) + (cond + ;; We always smooth when scaling down and small upwards scaling. + ((and scaling (< scaling 2)) + t) + ;; Smooth when doing non-90-degree rotation + ((and rotation + (or (not (zerop (mod rotation 1))) + (not (zerop (% (truncate rotation) 90))))) + t) + (t nil)))) (defun image--set-property (image property value) "Set PROPERTY in IMAGE to VALUE. |