diff options
Diffstat (limited to 'lisp/image.el')
| -rw-r--r-- | lisp/image.el | 46 |
1 files changed, 28 insertions, 18 deletions
diff --git a/lisp/image.el b/lisp/image.el index c4304782327..f4ed4e79fc0 100644 --- a/lisp/image.el +++ b/lisp/image.el | |||
| @@ -1017,20 +1017,34 @@ has no effect." | |||
| 1017 | If N is 3, then the image size will be increased by 30%. The | 1017 | If N is 3, then the image size will be increased by 30%. The |
| 1018 | default is 20%." | 1018 | default is 20%." |
| 1019 | (interactive "P") | 1019 | (interactive "P") |
| 1020 | (funcall image--change-size-function | 1020 | ;; Wait for a bit of idle-time before actually performing the change, |
| 1021 | (if n | 1021 | ;; so as to batch together sequences of closely consecutive size changes. |
| 1022 | (1+ (/ (prefix-numeric-value n) 10.0)) | 1022 | ;; `image--change-size' just changes one value in a plist. The actual |
| 1023 | 1.2))) | 1023 | ;; image resizing happens later during redisplay. So if those |
| 1024 | ;; consecutive calls happen without any redisplay between them, | ||
| 1025 | ;; the costly operation of image resizing should happen only once. | ||
| 1026 | (run-with-idle-timer 0.3 nil | ||
| 1027 | #'image--change-size | ||
| 1028 | (if n | ||
| 1029 | (1+ (/ (prefix-numeric-value n) 10.0)) | ||
| 1030 | 1.2))) | ||
| 1024 | 1031 | ||
| 1025 | (defun image-decrease-size (&optional n) | 1032 | (defun image-decrease-size (&optional n) |
| 1026 | "Decrease the image size by a factor of N. | 1033 | "Decrease the image size by a factor of N. |
| 1027 | If N is 3, then the image size will be decreased by 30%. The | 1034 | If N is 3, then the image size will be decreased by 30%. The |
| 1028 | default is 20%." | 1035 | default is 20%." |
| 1029 | (interactive "P") | 1036 | (interactive "P") |
| 1030 | (funcall image--change-size-function | 1037 | ;; Wait for a bit of idle-time before actually performing the change, |
| 1031 | (if n | 1038 | ;; so as to batch together sequences of closely consecutive size changes. |
| 1032 | (- 1 (/ (prefix-numeric-value n) 10.0)) | 1039 | ;; `image--change-size' just changes one value in a plist. The actual |
| 1033 | 0.8))) | 1040 | ;; image resizing happens later during redisplay. So if those |
| 1041 | ;; consecutive calls happen without any redisplay between them, | ||
| 1042 | ;; the costly operation of image resizing should happen only once. | ||
| 1043 | (run-with-idle-timer 0.3 nil | ||
| 1044 | #'image--change-size | ||
| 1045 | (if n | ||
| 1046 | (- 1 (/ (prefix-numeric-value n) 10.0)) | ||
| 1047 | 0.8))) | ||
| 1034 | 1048 | ||
| 1035 | (defun image-mouse-increase-size (&optional event) | 1049 | (defun image-mouse-increase-size (&optional event) |
| 1036 | "Increase the image size using the mouse." | 1050 | "Increase the image size using the mouse." |
| @@ -1065,16 +1079,12 @@ default is 20%." | |||
| 1065 | (plist-put (cdr image) :type 'imagemagick)) | 1079 | (plist-put (cdr image) :type 'imagemagick)) |
| 1066 | image)) | 1080 | image)) |
| 1067 | 1081 | ||
| 1068 | (defvar image--change-size-function | 1082 | (defun image--change-size (factor) |
| 1069 | (debounce-reduce 0.3 1 | 1083 | (let* ((image (image--get-imagemagick-and-warn)) |
| 1070 | (lambda (state factor) | 1084 | (new-image (image--image-without-parameters image)) |
| 1071 | (* state factor)) | 1085 | (scale (image--current-scaling image new-image))) |
| 1072 | (lambda (factor) | 1086 | (setcdr image (cdr new-image)) |
| 1073 | (let* ((image (image--get-imagemagick-and-warn)) | 1087 | (plist-put (cdr image) :scale (* scale factor)))) |
| 1074 | (new-image (image--image-without-parameters image)) | ||
| 1075 | (scale (image--current-scaling image new-image))) | ||
| 1076 | (setcdr image (cdr new-image)) | ||
| 1077 | (plist-put (cdr image) :scale (* scale factor)))))) | ||
| 1078 | 1088 | ||
| 1079 | (defun image--image-without-parameters (image) | 1089 | (defun image--image-without-parameters (image) |
| 1080 | (cons (pop image) | 1090 | (cons (pop image) |