]> code.delx.au - gnu-emacs/blob - lisp/image-mode.el
Merge from origin/emacs-25
[gnu-emacs] / lisp / image-mode.el
1 ;;; image-mode.el --- support for visiting image files -*- lexical-binding: t -*-
2 ;;
3 ;; Copyright (C) 2005-2016 Free Software Foundation, Inc.
4 ;;
5 ;; Author: Richard Stallman <rms@gnu.org>
6 ;; Keywords: multimedia
7 ;; Package: emacs
8
9 ;; This file is part of GNU Emacs.
10
11 ;; GNU Emacs is free software: you can redistribute it and/or modify
12 ;; it under the terms of the GNU General Public License as published by
13 ;; the Free Software Foundation, either version 3 of the License, or
14 ;; (at your option) any later version.
15
16 ;; GNU Emacs is distributed in the hope that it will be useful,
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 ;; GNU General Public License for more details.
20
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
23
24 ;;; Commentary:
25
26 ;; Defines a major mode for visiting image files
27 ;; that allows conversion between viewing the text of the file,
28 ;; hex of the file and viewing the file as an image. Viewing the image
29 ;; works by putting a `display' text-property on the
30 ;; image data, with the image-data still present underneath; if the
31 ;; resulting buffer file is saved to another name it will correctly save
32 ;; the image data to the new file.
33
34 ;; Todo:
35
36 ;; Consolidate with doc-view to make them work on directories of images or on
37 ;; image files containing various "pages".
38
39 ;;; Code:
40
41 (require 'image)
42 (eval-when-compile (require 'cl-lib))
43
44 ;;; Image mode window-info management.
45
46 (defvar-local image-mode-winprops-alist t)
47
48 (defvar image-mode-new-window-functions nil
49 "Special hook run when image data is requested in a new window.
50 It is called with one argument, the initial WINPROPS.")
51
52 ;; FIXME this doesn't seem mature yet. Document in manual when it is.
53 (defvar image-transform-resize nil
54 "The image resize operation.
55 Its value should be one of the following:
56 - nil, meaning no resizing.
57 - `fit-height', meaning to fit the image to the window height.
58 - `fit-width', meaning to fit the image to the window width.
59 - A number, which is a scale factor (the default size is 1).")
60
61 (defvar image-transform-scale 1.0
62 "The scale factor of the image being displayed.")
63
64 (defvar image-transform-rotation 0.0
65 "Rotation angle for the image in the current Image mode buffer.")
66
67 (defvar image-transform-right-angle-fudge 0.0001
68 "Snap distance to a multiple of a right angle.
69 There's no deep theory behind the default value, it should just
70 be somewhat larger than ImageMagick's MagickEpsilon.")
71
72 (defun image-mode-winprops (&optional window cleanup)
73 "Return winprops of WINDOW.
74 A winprops object has the shape (WINDOW . ALIST).
75 WINDOW defaults to `selected-window' if it displays the current buffer, and
76 otherwise it defaults to t, used for times when the buffer is not displayed."
77 (cond ((null window)
78 (setq window
79 (if (eq (current-buffer) (window-buffer)) (selected-window) t)))
80 ((eq window t))
81 ((not (windowp window))
82 (error "Not a window: %s" window)))
83 (when cleanup
84 (setq image-mode-winprops-alist
85 (delq nil (mapcar (lambda (winprop)
86 (let ((w (car-safe winprop)))
87 (if (or (not (windowp w)) (window-live-p w))
88 winprop)))
89 image-mode-winprops-alist))))
90 (let ((winprops (assq window image-mode-winprops-alist)))
91 ;; For new windows, set defaults from the latest.
92 (if winprops
93 ;; Move window to front.
94 (setq image-mode-winprops-alist
95 (cons winprops (delq winprops image-mode-winprops-alist)))
96 (setq winprops (cons window
97 (copy-alist (cdar image-mode-winprops-alist))))
98 ;; Add winprops before running the hook, to avoid inf-loops if the hook
99 ;; triggers window-configuration-change-hook.
100 (setq image-mode-winprops-alist
101 (cons winprops image-mode-winprops-alist))
102 (run-hook-with-args 'image-mode-new-window-functions winprops))
103 winprops))
104
105 (defun image-mode-window-get (prop &optional winprops)
106 (declare (gv-setter (lambda (val)
107 `(image-mode-window-put ,prop ,val ,winprops))))
108 (unless (consp winprops) (setq winprops (image-mode-winprops winprops)))
109 (cdr (assq prop (cdr winprops))))
110
111 (defun image-mode-window-put (prop val &optional winprops)
112 (unless (consp winprops) (setq winprops (image-mode-winprops winprops)))
113 (unless (eq t (car winprops))
114 (image-mode-window-put prop val t))
115 (setcdr winprops (cons (cons prop val)
116 (delq (assq prop (cdr winprops)) (cdr winprops)))))
117
118 (defun image-set-window-vscroll (vscroll)
119 (setf (image-mode-window-get 'vscroll) vscroll)
120 (set-window-vscroll (selected-window) vscroll))
121
122 (defun image-set-window-hscroll (ncol)
123 (setf (image-mode-window-get 'hscroll) ncol)
124 (set-window-hscroll (selected-window) ncol))
125
126 (defun image-mode-reapply-winprops ()
127 ;; When set-window-buffer, set hscroll and vscroll to what they were
128 ;; last time the image was displayed in this window.
129 (when (listp image-mode-winprops-alist)
130 ;; Beware: this call to image-mode-winprops can't be optimized away,
131 ;; because it not only gets the winprops data but sets it up if needed
132 ;; (e.g. it's used by doc-view to display the image in a new window).
133 (let* ((winprops (image-mode-winprops nil t))
134 (hscroll (image-mode-window-get 'hscroll winprops))
135 (vscroll (image-mode-window-get 'vscroll winprops)))
136 (when (image-get-display-property) ;Only do it if we display an image!
137 (if hscroll (set-window-hscroll (selected-window) hscroll))
138 (if vscroll (set-window-vscroll (selected-window) vscroll))))))
139
140 (defun image-mode-setup-winprops ()
141 ;; Record current scroll settings.
142 (unless (listp image-mode-winprops-alist)
143 (setq image-mode-winprops-alist nil))
144 (add-hook 'window-configuration-change-hook
145 'image-mode-reapply-winprops nil t))
146
147 ;;; Image scrolling functions
148
149 (defun image-get-display-property ()
150 (get-char-property (point-min) 'display
151 ;; There might be different images for different displays.
152 (if (eq (window-buffer) (current-buffer))
153 (selected-window))))
154
155 (declare-function image-size "image.c" (spec &optional pixels frame))
156 (declare-function xwidget-info "xwidget.c" (xwidget))
157 (declare-function xwidget-at "xwidget.el" (pos))
158
159 (defun image-display-size (spec &optional pixels frame)
160 "Wrapper around `image-size', handling slice display properties.
161 Like `image-size', the return value is (WIDTH . HEIGHT).
162 WIDTH and HEIGHT are in canonical character units if PIXELS is
163 nil, and in pixel units if PIXELS is non-nil.
164
165 If SPEC is an image display property, this function is equivalent to
166 `image-size'. If SPEC represents an xwidget object, defer to `xwidget-info'.
167 If SPEC is a list of properties containing `image' and `slice' properties,
168 return the display size taking the slice property into account. If the list
169 contains `image' but not `slice', return the `image-size' of the specified
170 image."
171 (cond ((eq (car spec) 'xwidget)
172 (let ((xwi (xwidget-info (xwidget-at (point-min)))))
173 (cons (aref xwi 2) (aref xwi 3))))
174 ((eq (car spec) 'image)
175 (image-size spec pixels frame))
176 (t (let ((image (assoc 'image spec))
177 (slice (assoc 'slice spec)))
178 (cond ((and image slice)
179 (if pixels
180 (cons (nth 3 slice) (nth 4 slice))
181 (cons (/ (float (nth 3 slice)) (frame-char-width frame))
182 (/ (float (nth 4 slice))
183 (frame-char-height frame)))))
184 (image
185 (image-size image pixels frame))
186 (t
187 (error "Invalid image specification: %s" spec)))))))
188
189 (defun image-forward-hscroll (&optional n)
190 "Scroll image in current window to the left by N character widths.
191 Stop if the right edge of the image is reached."
192 (interactive "p")
193 (cond ((= n 0) nil)
194 ((< n 0)
195 (image-set-window-hscroll (max 0 (+ (window-hscroll) n))))
196 (t
197 (let* ((image (image-get-display-property))
198 (edges (window-inside-edges))
199 (win-width (- (nth 2 edges) (nth 0 edges)))
200 (img-width (ceiling (car (image-display-size image)))))
201 (image-set-window-hscroll (min (max 0 (- img-width win-width))
202 (+ n (window-hscroll))))))))
203
204 (defun image-backward-hscroll (&optional n)
205 "Scroll image in current window to the right by N character widths.
206 Stop if the left edge of the image is reached."
207 (interactive "p")
208 (image-forward-hscroll (- n)))
209
210 (defun image-next-line (n)
211 "Scroll image in current window upward by N lines.
212 Stop if the bottom edge of the image is reached."
213 (interactive "p")
214 (cond ((= n 0) nil)
215 ((< n 0)
216 (image-set-window-vscroll (max 0 (+ (window-vscroll) n))))
217 (t
218 (let* ((image (image-get-display-property))
219 (edges (window-inside-edges))
220 (win-height (- (nth 3 edges) (nth 1 edges)))
221 (img-height (ceiling (cdr (image-display-size image)))))
222 (image-set-window-vscroll (min (max 0 (- img-height win-height))
223 (+ n (window-vscroll))))))))
224
225 (defun image-previous-line (&optional n)
226 "Scroll image in current window downward by N lines.
227 Stop if the top edge of the image is reached."
228 (interactive "p")
229 (image-next-line (- n)))
230
231 (defun image-scroll-up (&optional n)
232 "Scroll image in current window upward by N lines.
233 Stop if the bottom edge of the image is reached.
234 If ARG is omitted or nil, scroll upward by a near full screen.
235 A near full screen is `next-screen-context-lines' less than a full screen.
236 Negative ARG means scroll downward.
237 If ARG is the atom `-', scroll downward by nearly full screen.
238 When calling from a program, supply as argument a number, nil, or `-'."
239 (interactive "P")
240 (cond ((null n)
241 (let* ((edges (window-inside-edges))
242 (win-height (- (nth 3 edges) (nth 1 edges))))
243 (image-next-line
244 (max 0 (- win-height next-screen-context-lines)))))
245 ((eq n '-)
246 (let* ((edges (window-inside-edges))
247 (win-height (- (nth 3 edges) (nth 1 edges))))
248 (image-next-line
249 (min 0 (- next-screen-context-lines win-height)))))
250 (t (image-next-line (prefix-numeric-value n)))))
251
252 (defun image-scroll-down (&optional n)
253 "Scroll image in current window downward by N lines.
254 Stop if the top edge of the image is reached.
255 If ARG is omitted or nil, scroll downward by a near full screen.
256 A near full screen is `next-screen-context-lines' less than a full screen.
257 Negative ARG means scroll upward.
258 If ARG is the atom `-', scroll upward by nearly full screen.
259 When calling from a program, supply as argument a number, nil, or `-'."
260 (interactive "P")
261 (cond ((null n)
262 (let* ((edges (window-inside-edges))
263 (win-height (- (nth 3 edges) (nth 1 edges))))
264 (image-next-line
265 (min 0 (- next-screen-context-lines win-height)))))
266 ((eq n '-)
267 (let* ((edges (window-inside-edges))
268 (win-height (- (nth 3 edges) (nth 1 edges))))
269 (image-next-line
270 (max 0 (- win-height next-screen-context-lines)))))
271 (t (image-next-line (- (prefix-numeric-value n))))))
272
273 (defun image-bol (arg)
274 "Scroll horizontally to the left edge of the image in the current window.
275 With argument ARG not nil or 1, move forward ARG - 1 lines first,
276 stopping if the top or bottom edge of the image is reached."
277 (interactive "p")
278 (and arg
279 (/= (setq arg (prefix-numeric-value arg)) 1)
280 (image-next-line (- arg 1)))
281 (image-set-window-hscroll 0))
282
283 (defun image-eol (arg)
284 "Scroll horizontally to the right edge of the image in the current window.
285 With argument ARG not nil or 1, move forward ARG - 1 lines first,
286 stopping if the top or bottom edge of the image is reached."
287 (interactive "p")
288 (and arg
289 (/= (setq arg (prefix-numeric-value arg)) 1)
290 (image-next-line (- arg 1)))
291 (let* ((image (image-get-display-property))
292 (edges (window-inside-edges))
293 (win-width (- (nth 2 edges) (nth 0 edges)))
294 (img-width (ceiling (car (image-display-size image)))))
295 (image-set-window-hscroll (max 0 (- img-width win-width)))))
296
297 (defun image-bob ()
298 "Scroll to the top-left corner of the image in the current window."
299 (interactive)
300 (image-set-window-hscroll 0)
301 (image-set-window-vscroll 0))
302
303 (defun image-eob ()
304 "Scroll to the bottom-right corner of the image in the current window."
305 (interactive)
306 (let* ((image (image-get-display-property))
307 (edges (window-inside-edges))
308 (win-width (- (nth 2 edges) (nth 0 edges)))
309 (img-width (ceiling (car (image-display-size image))))
310 (win-height (- (nth 3 edges) (nth 1 edges)))
311 (img-height (ceiling (cdr (image-display-size image)))))
312 (image-set-window-hscroll (max 0 (- img-width win-width)))
313 (image-set-window-vscroll (max 0 (- img-height win-height)))))
314
315 ;; Adjust frame and image size.
316
317 (defun image-mode-fit-frame (&optional frame toggle)
318 "Fit FRAME to the current image.
319 If FRAME is omitted or nil, it defaults to the selected frame.
320 All other windows on the frame are deleted.
321
322 If called interactively, or if TOGGLE is non-nil, toggle between
323 fitting FRAME to the current image and restoring the size and
324 window configuration prior to the last `image-mode-fit-frame'
325 call."
326 (interactive (list nil t))
327 (let* ((buffer (current-buffer))
328 (display (image-get-display-property))
329 (size (image-display-size display))
330 (saved (frame-parameter frame 'image-mode-saved-params))
331 (window-configuration (current-window-configuration frame))
332 (width (frame-width frame))
333 (height (frame-height frame)))
334 (with-selected-frame (or frame (selected-frame))
335 (if (and toggle saved
336 (= (caar saved) width)
337 (= (cdar saved) height))
338 (progn
339 (set-frame-width frame (car (nth 1 saved)))
340 (set-frame-height frame (cdr (nth 1 saved)))
341 (set-window-configuration (nth 2 saved))
342 (set-frame-parameter frame 'image-mode-saved-params nil))
343 (delete-other-windows)
344 (switch-to-buffer buffer t t)
345 (let* ((edges (window-inside-edges))
346 (inner-width (- (nth 2 edges) (nth 0 edges)))
347 (inner-height (- (nth 3 edges) (nth 1 edges))))
348 (set-frame-width frame (+ (ceiling (car size))
349 width (- inner-width)))
350 (set-frame-height frame (+ (ceiling (cdr size))
351 height (- inner-height)))
352 ;; The frame size after the above `set-frame-*' calls may
353 ;; differ from what we specified, due to window manager
354 ;; interference. We have to call `frame-width' and
355 ;; `frame-height' to get the actual results.
356 (set-frame-parameter frame 'image-mode-saved-params
357 (list (cons (frame-width)
358 (frame-height))
359 (cons width height)
360 window-configuration)))))))
361
362 ;;; Image Mode setup
363
364 (defvar-local image-type nil
365 "The image type for the current Image mode buffer.")
366
367 (defvar-local image-multi-frame nil
368 "Non-nil if image for the current Image mode buffer has multiple frames.")
369
370 (defvar image-mode-previous-major-mode nil
371 "Internal variable to keep the previous non-image major mode.")
372
373 (defvar image-mode-map
374 (let ((map (make-sparse-keymap)))
375 (set-keymap-parent map image-map)
376 (define-key map "\C-c\C-c" 'image-toggle-display)
377 (define-key map "\C-c\C-x" 'image-toggle-hex-display)
378 (define-key map (kbd "SPC") 'image-scroll-up)
379 (define-key map (kbd "S-SPC") 'image-scroll-down)
380 (define-key map (kbd "DEL") 'image-scroll-down)
381 (define-key map (kbd "RET") 'image-toggle-animation)
382 (define-key map "F" 'image-goto-frame)
383 (define-key map "f" 'image-next-frame)
384 (define-key map "b" 'image-previous-frame)
385 (define-key map "n" 'image-next-file)
386 (define-key map "p" 'image-previous-file)
387 (define-key map "a+" 'image-increase-speed)
388 (define-key map "a-" 'image-decrease-speed)
389 (define-key map "a0" 'image-reset-speed)
390 (define-key map "ar" 'image-reverse-speed)
391 (define-key map "k" 'image-kill-buffer)
392 (define-key map [remap forward-char] 'image-forward-hscroll)
393 (define-key map [remap backward-char] 'image-backward-hscroll)
394 (define-key map [remap right-char] 'image-forward-hscroll)
395 (define-key map [remap left-char] 'image-backward-hscroll)
396 (define-key map [remap previous-line] 'image-previous-line)
397 (define-key map [remap next-line] 'image-next-line)
398 (define-key map [remap scroll-up] 'image-scroll-up)
399 (define-key map [remap scroll-down] 'image-scroll-down)
400 (define-key map [remap scroll-up-command] 'image-scroll-up)
401 (define-key map [remap scroll-down-command] 'image-scroll-down)
402 (define-key map [remap move-beginning-of-line] 'image-bol)
403 (define-key map [remap move-end-of-line] 'image-eol)
404 (define-key map [remap beginning-of-buffer] 'image-bob)
405 (define-key map [remap end-of-buffer] 'image-eob)
406 (easy-menu-define image-mode-menu map "Menu for Image mode."
407 '("Image"
408 ["Show as Text" image-toggle-display :active t
409 :help "Show image as text"]
410 ["Show as Hex" image-toggle-hex-display :active t
411 :help "Show image as hex"]
412 "--"
413 ["Fit to Window Height" image-transform-fit-to-height
414 :visible (eq image-type 'imagemagick)
415 :help "Resize image to match the window height"]
416 ["Fit to Window Width" image-transform-fit-to-width
417 :visible (eq image-type 'imagemagick)
418 :help "Resize image to match the window width"]
419 ["Rotate Image..." image-transform-set-rotation
420 :visible (eq image-type 'imagemagick)
421 :help "Rotate the image"]
422 ["Reset Transformations" image-transform-reset
423 :visible (eq image-type 'imagemagick)
424 :help "Reset all image transformations"]
425 "--"
426 ["Show Thumbnails"
427 (lambda ()
428 (interactive)
429 (image-dired default-directory))
430 :active default-directory
431 :help "Show thumbnails for all images in this directory"]
432 ["Next Image" image-next-file :active buffer-file-name
433 :help "Move to next image in this directory"]
434 ["Previous Image" image-previous-file :active buffer-file-name
435 :help "Move to previous image in this directory"]
436 "--"
437 ["Fit Frame to Image" image-mode-fit-frame :active t
438 :help "Resize frame to match image"]
439 "--"
440 ["Animate Image" image-toggle-animation :style toggle
441 :selected (let ((image (image-get-display-property)))
442 (and image (image-animate-timer image)))
443 :active image-multi-frame
444 :help "Toggle image animation"]
445 ["Loop Animation"
446 (lambda () (interactive)
447 (setq image-animate-loop (not image-animate-loop))
448 ;; FIXME this is a hacky way to make it affect a currently
449 ;; animating image.
450 (when (let ((image (image-get-display-property)))
451 (and image (image-animate-timer image)))
452 (image-toggle-animation)
453 (image-toggle-animation)))
454 :style toggle :selected image-animate-loop
455 :active image-multi-frame
456 :help "Animate images once, or forever?"]
457 ["Reverse Animation" image-reverse-speed
458 :style toggle :selected (let ((image (image-get-display-property)))
459 (and image (<
460 (image-animate-get-speed image)
461 0)))
462 :active image-multi-frame
463 :help "Reverse direction of this image's animation?"]
464 ["Speed Up Animation" image-increase-speed
465 :active image-multi-frame
466 :help "Speed up this image's animation"]
467 ["Slow Down Animation" image-decrease-speed
468 :active image-multi-frame
469 :help "Slow down this image's animation"]
470 ["Reset Animation Speed" image-reset-speed
471 :active image-multi-frame
472 :help "Reset the speed of this image's animation"]
473 ["Next Frame" image-next-frame :active image-multi-frame
474 :help "Show the next frame of this image"]
475 ["Previous Frame" image-previous-frame :active image-multi-frame
476 :help "Show the previous frame of this image"]
477 ["Goto Frame..." image-goto-frame :active image-multi-frame
478 :help "Show a specific frame of this image"]
479 ))
480 (make-composed-keymap (list map image-map) special-mode-map))
481 "Mode keymap for `image-mode'.")
482
483 (defvar image-minor-mode-map
484 (let ((map (make-sparse-keymap)))
485 (define-key map "\C-c\C-c" 'image-toggle-display)
486 (define-key map "\C-c\C-x" 'image-toggle-hex-display)
487 map)
488 "Mode keymap for `image-minor-mode'.")
489
490 (defvar bookmark-make-record-function)
491
492 (put 'image-mode 'mode-class 'special)
493
494 ;;;###autoload
495 (defun image-mode ()
496 "Major mode for image files.
497 You can use \\<image-mode-map>\\[image-toggle-display] or \\<image-mode-map>\\[image-toggle-hex-display]
498 to toggle between display as an image and display as text or hex.
499
500 Key bindings:
501 \\{image-mode-map}"
502 (interactive)
503 (condition-case err
504 (progn
505 (unless (display-images-p)
506 (error "Display does not support images"))
507
508 (kill-all-local-variables)
509 (setq major-mode 'image-mode)
510
511 (if (not (image-get-display-property))
512 (progn
513 (image-toggle-display-image)
514 ;; If attempt to display the image fails.
515 (if (not (image-get-display-property))
516 (error "Invalid image")))
517 ;; Set next vars when image is already displayed but local
518 ;; variables were cleared by kill-all-local-variables
519 (setq cursor-type nil truncate-lines t
520 image-type (plist-get (cdr (image-get-display-property)) :type)))
521
522 (setq mode-name (if image-type (format "Image[%s]" image-type) "Image"))
523 (use-local-map image-mode-map)
524
525 ;; Use our own bookmarking function for images.
526 (setq-local bookmark-make-record-function
527 #'image-bookmark-make-record)
528
529 ;; Keep track of [vh]scroll when switching buffers
530 (image-mode-setup-winprops)
531
532 (add-hook 'change-major-mode-hook 'image-toggle-display-text nil t)
533 (add-hook 'after-revert-hook 'image-after-revert-hook nil t)
534 (run-mode-hooks 'image-mode-hook)
535 (let ((image (image-get-display-property))
536 (msg1 (substitute-command-keys
537 "Type \\[image-toggle-display] or \\[image-toggle-hex-display] to view the image as "))
538 animated)
539 (cond
540 ((null image)
541 (message "%s" (concat msg1 "an image.")))
542 ((setq animated (image-multi-frame-p image))
543 (setq image-multi-frame t
544 mode-line-process
545 `(:eval
546 (concat " "
547 (propertize
548 (format "[%s/%s]"
549 (1+ (image-current-frame ',image))
550 ,(car animated))
551 'help-echo "Frames
552 mouse-1: Next frame
553 mouse-3: Previous frame"
554 'mouse-face 'mode-line-highlight
555 'local-map
556 '(keymap
557 (mode-line
558 keymap
559 (down-mouse-1 . image-next-frame)
560 (down-mouse-3 . image-previous-frame)))))))
561 (message "%s"
562 (concat msg1 "text. This image has multiple frames.")))
563 ;;; (substitute-command-keys
564 ;;; "\\[image-toggle-animation] to animate."))))
565 (t
566 (message "%s" (concat msg1 "text or hex."))))))
567
568 (error
569 (image-mode-as-text)
570 (funcall
571 (if (called-interactively-p 'any) 'error 'message)
572 "Cannot display image: %s" (cdr err)))))
573
574 ;;;###autoload
575 (define-minor-mode image-minor-mode
576 "Toggle Image minor mode in this buffer.
577 With a prefix argument ARG, enable Image minor mode if ARG is
578 positive, and disable it otherwise. If called from Lisp, enable
579 the mode if ARG is omitted or nil.
580
581 Image minor mode provides the key \\<image-mode-map>\\[image-toggle-display],
582 to switch back to `image-mode' and display an image file as the
583 actual image."
584 nil (:eval (if image-type (format " Image[%s]" image-type) " Image"))
585 image-minor-mode-map
586 :group 'image
587 :version "22.1"
588 (if image-minor-mode
589 (add-hook 'change-major-mode-hook (lambda () (image-minor-mode -1)) nil t)))
590
591 ;;;###autoload
592 (defun image-mode-to-text ()
593 "Set a non-image mode as major mode in combination with image minor mode.
594 A non-mage major mode found from `auto-mode-alist' or fundamental mode
595 displays an image file as text."
596 ;; image-mode-as-text = normal-mode + image-minor-mode
597 (let ((previous-image-type image-type)) ; preserve `image-type'
598 (if image-mode-previous-major-mode
599 ;; Restore previous major mode that was already found by this
600 ;; function and cached in `image-mode-previous-major-mode'
601 (funcall image-mode-previous-major-mode)
602 (let ((auto-mode-alist
603 (delq nil (mapcar
604 (lambda (elt)
605 (unless (memq (or (car-safe (cdr elt)) (cdr elt))
606 '(image-mode image-mode-maybe image-mode-as-text))
607 elt))
608 auto-mode-alist)))
609 (magic-fallback-mode-alist
610 (delq nil (mapcar
611 (lambda (elt)
612 (unless (memq (or (car-safe (cdr elt)) (cdr elt))
613 '(image-mode image-mode-maybe image-mode-as-text))
614 elt))
615 magic-fallback-mode-alist))))
616 (normal-mode)
617 (setq-local image-mode-previous-major-mode major-mode)))
618 ;; Restore `image-type' after `kill-all-local-variables' in `normal-mode'.
619 (setq image-type previous-image-type)
620 ;; Enable image minor mode with `C-c C-c'.
621 (image-minor-mode 1)
622 ;; Show the image file as text.
623 (image-toggle-display-text)))
624
625 (defun image-mode-as-hex ()
626 "Set a non-image mode as major mode in combination with image minor mode.
627 A non-mage major mode found from `auto-mode-alist' or fundamental mode
628 displays an image file as hex. `image-minor-mode' provides the key
629 \\<image-mode-map>\\[image-toggle-hex-display] to switch back to `image-mode'
630 to display an image file as the actual image.
631
632 You can use `image-mode-as-hex' in `auto-mode-alist' when you want to
633 to display an image file as hex initially.
634
635 See commands `image-mode' and `image-minor-mode' for more information
636 on these modes."
637 (interactive)
638 (image-mode-to-text)
639 ;; Turn on hexl-mode
640 (hexl-mode)
641 (message "%s" (concat
642 (substitute-command-keys
643 "Type \\[image-toggle-hex-display] or \\[image-toggle-display] to view the image as ")
644 (if (image-get-display-property)
645 "hex" "an image or text") ".")))
646
647 (defun image-mode-as-text ()
648 "Set a non-image mode as major mode in combination with image minor mode.
649 A non-image major mode found from `auto-mode-alist' or Fundamental mode
650 displays an image file as text. `image-minor-mode' provides the key
651 \\<image-mode-map>\\[image-toggle-display] to switch back to `image-mode'
652 to display an image file as the actual image.
653
654 You can use `image-mode-as-text' in `auto-mode-alist' when you want
655 to display an image file as text initially.
656
657 See commands `image-mode' and `image-minor-mode' for more information
658 on these modes."
659 (interactive)
660 (image-mode-to-text)
661 (message "%s" (concat
662 (substitute-command-keys
663 "Type \\[image-toggle-display] or \\[image-toggle-hex-display] to view the image as ")
664 (if (image-get-display-property)
665 "text" "an image or hex") ".")))
666
667 (define-obsolete-function-alias 'image-mode-maybe 'image-mode "23.2")
668
669 (defun image-toggle-display-text ()
670 "Show the image file as text.
671 Remove text properties that display the image."
672 (let ((inhibit-read-only t)
673 (buffer-undo-list t)
674 (modified (buffer-modified-p)))
675 (remove-list-of-text-properties (point-min) (point-max)
676 '(display read-nonsticky ;; intangible
677 read-only front-sticky))
678 (set-buffer-modified-p modified)
679 (if (called-interactively-p 'any)
680 (message "Repeat this command to go back to displaying the image"))))
681
682 (defvar archive-superior-buffer)
683 (defvar tar-superior-buffer)
684 (declare-function image-flush "image.c" (spec &optional frame))
685
686 (defun image-toggle-display-image ()
687 "Show the image of the image file.
688 Turn the image data into a real image, but only if the whole file
689 was inserted."
690 (unless (derived-mode-p 'image-mode)
691 (error "The buffer is not in Image mode"))
692 (let* ((filename (buffer-file-name))
693 (data-p (not (and filename
694 (file-readable-p filename)
695 (not (file-remote-p filename))
696 (not (buffer-modified-p))
697 (not (and (boundp 'archive-superior-buffer)
698 archive-superior-buffer))
699 (not (and (boundp 'tar-superior-buffer)
700 tar-superior-buffer))
701 ;; This means the buffer holds the
702 ;; decrypted content (bug#21870).
703 (not (and (boundp 'epa-file-encrypt-to)
704 (local-variable-p
705 'epa-file-encrypt-to))))))
706 (file-or-data (if data-p
707 (string-make-unibyte
708 (buffer-substring-no-properties (point-min) (point-max)))
709 filename))
710 ;; If we have a `fit-width' or a `fit-height', don't limit
711 ;; the size of the image to the window size.
712 (edges (and (null image-transform-resize)
713 (window-inside-pixel-edges
714 (get-buffer-window (current-buffer)))))
715 (type (if (fboundp 'imagemagick-types)
716 'imagemagick
717 (image-type file-or-data nil data-p)))
718 (image (if (not edges)
719 (create-image file-or-data type data-p)
720 (create-image file-or-data type data-p
721 :max-width (- (nth 2 edges) (nth 0 edges))
722 :max-height (- (nth 3 edges) (nth 1 edges)))))
723 (inhibit-read-only t)
724 (buffer-undo-list t)
725 (modified (buffer-modified-p))
726 props)
727
728 ;; Discard any stale image data before looking it up again.
729 (image-flush image)
730 (setq image (append image (image-transform-properties image)))
731 (setq props
732 `(display ,image
733 ;; intangible ,image
734 rear-nonsticky (display) ;; intangible
735 read-only t front-sticky (read-only)))
736
737 (let ((buffer-file-truename nil)) ; avoid changing dir mtime by lock_file
738 (add-text-properties (point-min) (point-max) props)
739 (restore-buffer-modified-p modified))
740 ;; Inhibit the cursor when the buffer contains only an image,
741 ;; because cursors look very strange on top of images.
742 (setq cursor-type nil)
743 ;; This just makes the arrow displayed in the right fringe
744 ;; area look correct when the image is wider than the window.
745 (setq truncate-lines t)
746 ;; Disable adding a newline at the end of the image file when it
747 ;; is written with, e.g., C-x C-w.
748 (if (coding-system-equal (coding-system-base buffer-file-coding-system)
749 'no-conversion)
750 (setq-local find-file-literally t))
751 ;; Allow navigation of large images.
752 (setq-local auto-hscroll-mode nil)
753 (setq image-type type)
754 (if (eq major-mode 'image-mode)
755 (setq mode-name (format "Image[%s]" type)))
756 (image-transform-check-size)
757 (if (called-interactively-p 'any)
758 (message "Repeat this command to go back to displaying the file as text"))))
759
760 (defun image-toggle-hex-display ()
761 "Toggle between image and hex display."
762 (interactive)
763 (if (image-get-display-property)
764 (image-mode-as-hex)
765 (if (eq major-mode 'fundamental-mode)
766 (image-mode-as-hex)
767 (image-mode))))
768
769 (defun image-toggle-display ()
770 "Toggle between image and text display.
771
772 If the current buffer is displaying an image file as an image,
773 call `image-mode-as-text' to switch to text or hex display.
774 Otherwise, display the image by calling `image-mode'"
775 (interactive)
776 (if (image-get-display-property)
777 (image-mode-as-text)
778 (if (eq major-mode 'hexl-mode)
779 (image-mode-as-text)
780 (image-mode))))
781
782 (defun image-kill-buffer ()
783 "Kill the current buffer."
784 (interactive)
785 (kill-buffer (current-buffer)))
786
787 (defun image-after-revert-hook ()
788 (when (image-get-display-property)
789 (image-toggle-display-text)
790 ;; Update image display.
791 (mapc (lambda (window) (redraw-frame (window-frame window)))
792 (get-buffer-window-list (current-buffer) 'nomini 'visible))
793 (image-toggle-display-image)))
794
795 \f
796 ;;; Animated images
797
798 (defcustom image-animate-loop nil
799 "Non-nil means animated images loop forever, rather than playing once."
800 :type 'boolean
801 :version "24.1"
802 :group 'image)
803
804 (defun image-toggle-animation ()
805 "Start or stop animating the current image.
806 If `image-animate-loop' is non-nil, animation loops forever.
807 Otherwise it plays once, then stops."
808 (interactive)
809 (let ((image (image-get-display-property))
810 animation)
811 (cond
812 ((null image)
813 (error "No image is present"))
814 ((null (setq animation (image-multi-frame-p image)))
815 (message "No image animation."))
816 (t
817 (let ((timer (image-animate-timer image)))
818 (if timer
819 (cancel-timer timer)
820 (let ((index (plist-get (cdr image) :index)))
821 ;; If we're at the end, restart.
822 (and index
823 (>= index (1- (car animation)))
824 (setq index nil))
825 (image-animate image index
826 (if image-animate-loop t)))))))))
827
828 (defun image--set-speed (speed &optional multiply)
829 "Set speed of an animated image to SPEED.
830 If MULTIPLY is non-nil, treat SPEED as a multiplication factor.
831 If SPEED is `reset', reset the magnitude of the speed to 1."
832 (let ((image (image-get-display-property)))
833 (cond
834 ((null image)
835 (error "No image is present"))
836 ((null image-multi-frame)
837 (message "No image animation."))
838 (t
839 (if (eq speed 'reset)
840 (setq speed (if (< (image-animate-get-speed image) 0)
841 -1 1)
842 multiply nil))
843 (image-animate-set-speed image speed multiply)
844 ;; FIXME Hack to refresh an active image.
845 (when (image-animate-timer image)
846 (image-toggle-animation)
847 (image-toggle-animation))
848 (message "Image speed is now %s" (image-animate-get-speed image))))))
849
850 (defun image-increase-speed ()
851 "Increase the speed of current animated image by a factor of 2."
852 (interactive)
853 (image--set-speed 2 t))
854
855 (defun image-decrease-speed ()
856 "Decrease the speed of current animated image by a factor of 2."
857 (interactive)
858 (image--set-speed 0.5 t))
859
860 (defun image-reverse-speed ()
861 "Reverse the animation of the current image."
862 (interactive)
863 (image--set-speed -1 t))
864
865 (defun image-reset-speed ()
866 "Reset the animation speed of the current image."
867 (interactive)
868 (image--set-speed 'reset))
869
870 (defun image-goto-frame (n &optional relative)
871 "Show frame N of a multi-frame image.
872 Optional argument OFFSET non-nil means interpret N as relative to the
873 current frame. Frames are indexed from 1."
874 (interactive
875 (list (or current-prefix-arg
876 (read-number "Show frame number: "))))
877 (let ((image (image-get-display-property)))
878 (cond
879 ((null image)
880 (error "No image is present"))
881 ((null image-multi-frame)
882 (message "No image animation."))
883 (t
884 (image-show-frame image
885 (if relative
886 (+ n (image-current-frame image))
887 (1- n)))))))
888
889 (defun image-next-frame (&optional n)
890 "Switch to the next frame of a multi-frame image.
891 With optional argument N, switch to the Nth frame after the current one.
892 If N is negative, switch to the Nth frame before the current one."
893 (interactive "p")
894 (image-goto-frame n t))
895
896 (defun image-previous-frame (&optional n)
897 "Switch to the previous frame of a multi-frame image.
898 With optional argument N, switch to the Nth frame before the current one.
899 If N is negative, switch to the Nth frame after the current one."
900 (interactive "p")
901 (image-next-frame (- n)))
902
903 \f
904 ;;; Switching to the next/previous image
905
906 (defun image-next-file (&optional n)
907 "Visit the next image in the same directory as the current image file.
908 With optional argument N, visit the Nth image file after the
909 current one, in cyclic alphabetical order.
910
911 This command visits the specified file via `find-alternate-file',
912 replacing the current Image mode buffer."
913 (interactive "p")
914 (unless (derived-mode-p 'image-mode)
915 (error "The buffer is not in Image mode"))
916 (unless buffer-file-name
917 (error "The current image is not associated with a file"))
918 (let* ((file (file-name-nondirectory buffer-file-name))
919 (images (image-mode--images-in-directory file))
920 (idx 0))
921 (catch 'image-visit-next-file
922 (dolist (f images)
923 (if (string= f file)
924 (throw 'image-visit-next-file (1+ idx)))
925 (setq idx (1+ idx))))
926 (setq idx (mod (+ idx (or n 1)) (length images)))
927 (find-alternate-file (nth idx images))))
928
929 (defun image-previous-file (&optional n)
930 "Visit the preceding image in the same directory as the current file.
931 With optional argument N, visit the Nth image file preceding the
932 current one, in cyclic alphabetical order.
933
934 This command visits the specified file via `find-alternate-file',
935 replacing the current Image mode buffer."
936 (interactive "p")
937 (image-next-file (- n)))
938
939 (defun image-mode--images-in-directory (file)
940 (let* ((dir (file-name-directory buffer-file-name))
941 (files (directory-files dir nil
942 (image-file-name-regexp) t)))
943 ;; Add the current file to the list of images if necessary, in
944 ;; case it does not match `image-file-name-regexp'.
945 (unless (member file files)
946 (push file files))
947 (sort files 'string-lessp)))
948
949 \f
950 ;;; Support for bookmark.el
951 (declare-function bookmark-make-record-default
952 "bookmark" (&optional no-file no-context posn))
953 (declare-function bookmark-prop-get "bookmark" (bookmark prop))
954 (declare-function bookmark-default-handler "bookmark" (bmk))
955
956 (defun image-bookmark-make-record ()
957 `(,@(bookmark-make-record-default nil 'no-context 0)
958 (image-type . ,image-type)
959 (handler . image-bookmark-jump)))
960
961 ;;;###autoload
962 (defun image-bookmark-jump (bmk)
963 ;; This implements the `handler' function interface for record type
964 ;; returned by `bookmark-make-record-function', which see.
965 (prog1 (bookmark-default-handler bmk)
966 (when (not (string= image-type (bookmark-prop-get bmk 'image-type)))
967 (image-toggle-display))))
968 \f
969
970 ;; Not yet implemented.
971 ;; (defvar image-transform-minor-mode-map
972 ;; (let ((map (make-sparse-keymap)))
973 ;; ;; (define-key map [(control ?+)] 'image-scale-in)
974 ;; ;; (define-key map [(control ?-)] 'image-scale-out)
975 ;; ;; (define-key map [(control ?=)] 'image-scale-none)
976 ;; ;; (define-key map "c f h" 'image-scale-fit-height)
977 ;; ;; (define-key map "c ]" 'image-rotate-right)
978 ;; map)
979 ;; "Minor mode keymap `image-transform-mode'.")
980 ;;
981 ;; (define-minor-mode image-transform-mode
982 ;; "Minor mode for scaling and rotating images.
983 ;; With a prefix argument ARG, enable the mode if ARG is positive,
984 ;; and disable it otherwise. If called from Lisp, enable the mode
985 ;; if ARG is omitted or nil. This minor mode requires Emacs to have
986 ;; been compiled with ImageMagick support."
987 ;; nil "image-transform" image-transform-minor-mode-map)
988
989
990 (defsubst image-transform-width (width height)
991 "Return the bounding box width of a rotated WIDTH x HEIGHT rectangle.
992 The rotation angle is the value of `image-transform-rotation' in degrees."
993 (let ((angle (degrees-to-radians image-transform-rotation)))
994 ;; Assume, w.l.o.g., that the vertices of the rectangle have the
995 ;; coordinates (+-w/2, +-h/2) and that (0, 0) is the center of the
996 ;; rotation by the angle A. The projections onto the first axis
997 ;; of the vertices of the rotated rectangle are +- (w/2) cos A +-
998 ;; (h/2) sin A, and the difference between the largest and the
999 ;; smallest of the four values is the expression below.
1000 (+ (* width (abs (cos angle))) (* height (abs (sin angle))))))
1001
1002 ;; The following comment and code snippet are from
1003 ;; ImageMagick-6.7.4-4/magick/distort.c
1004
1005 ;; /* Set the output image geometry to calculated 'best fit'.
1006 ;; Yes this tends to 'over do' the file image size, ON PURPOSE!
1007 ;; Do not do this for DePolar which needs to be exact for virtual tiling.
1008 ;; */
1009 ;; if ( fix_bounds ) {
1010 ;; geometry.x = (ssize_t) floor(min.x-0.5);
1011 ;; geometry.y = (ssize_t) floor(min.y-0.5);
1012 ;; geometry.width=(size_t) ceil(max.x-geometry.x+0.5);
1013 ;; geometry.height=(size_t) ceil(max.y-geometry.y+0.5);
1014 ;; }
1015
1016 ;; Other parts of the same file show that here the origin is in the
1017 ;; left lower corner of the image rectangle, the center of the
1018 ;; rotation is the center of the rectangle and min.x and max.x
1019 ;; (resp. min.y and max.y) are the smallest and the largest of the
1020 ;; projections of the vertices onto the first (resp. second) axis.
1021
1022 (defun image-transform-fit-width (width height length)
1023 "Return (w . h) so that a rotated w x h image has exactly width LENGTH.
1024 The rotation angle is the value of `image-transform-rotation'.
1025 Write W for WIDTH and H for HEIGHT. Then the w x h rectangle is
1026 an \"approximately uniformly\" scaled W x H rectangle, which
1027 currently means that w is one of floor(s W) + {0, 1, -1} and h is
1028 floor(s H), where s can be recovered as the value of `image-transform-scale'.
1029 The value of `image-transform-rotation' may be replaced by
1030 a slightly different angle. Currently this is done for values
1031 close to a multiple of 90, see `image-transform-right-angle-fudge'."
1032 (cond ((< (abs (- (mod (+ image-transform-rotation 90) 180) 90))
1033 image-transform-right-angle-fudge)
1034 (cl-assert (not (zerop width)) t)
1035 (setq image-transform-rotation
1036 (float (round image-transform-rotation))
1037 image-transform-scale (/ (float length) width))
1038 (cons length nil))
1039 ((< (abs (- (mod (+ image-transform-rotation 45) 90) 45))
1040 image-transform-right-angle-fudge)
1041 (cl-assert (not (zerop height)) t)
1042 (setq image-transform-rotation
1043 (float (round image-transform-rotation))
1044 image-transform-scale (/ (float length) height))
1045 (cons nil length))
1046 (t
1047 (cl-assert (not (and (zerop width) (zerop height))) t)
1048 (setq image-transform-scale
1049 (/ (float (1- length)) (image-transform-width width height)))
1050 ;; Assume we have a w x h image and an angle A, and let l =
1051 ;; l(w, h) = w |cos A| + h |sin A|, which is the actual width
1052 ;; of the bounding box of the rotated image, as calculated by
1053 ;; `image-transform-width'. The code snippet quoted above
1054 ;; means that ImageMagick puts the rotated image in
1055 ;; a bounding box of width L = 2 ceil((w+l+1)/2) - w.
1056 ;; Elementary considerations show that this is equivalent to
1057 ;; L - w being even and L-3 < l(w, h) <= L-1. In our case, L is
1058 ;; the given `length' parameter and our job is to determine
1059 ;; reasonable values for w and h which satisfy these
1060 ;; conditions.
1061 (let ((w (floor (* image-transform-scale width)))
1062 (h (floor (* image-transform-scale height))))
1063 ;; Let w and h as bound above. Then l(w, h) <= l(s W, s H)
1064 ;; = L-1 < l(w+1, h+1) = l(w, h) + l(1, 1) <= l(w, h) + 2,
1065 ;; hence l(w, h) > (L-1) - 2 = L-3.
1066 (cons
1067 (cond ((= (mod w 2) (mod length 2))
1068 w)
1069 ;; l(w+1, h) >= l(w, h) > L-3, but does l(w+1, h) <=
1070 ;; L-1 hold?
1071 ((<= (image-transform-width (1+ w) h) (1- length))
1072 (1+ w))
1073 ;; No, it doesn't, but this implies that l(w-1, h) =
1074 ;; l(w+1, h) - l(2, 0) >= l(w+1, h) - 2 > (L-1) -
1075 ;; 2 = L-3. Clearly, l(w-1, h) <= l(w, h) <= L-1.
1076 (t
1077 (1- w)))
1078 h)))))
1079
1080 (defun image-transform-check-size ()
1081 "Check that the image exactly fits the width/height of the window.
1082
1083 Do this for an image of type `imagemagick' to make sure that the
1084 elisp code matches the way ImageMagick computes the bounding box
1085 of a rotated image."
1086 (when (and (not (numberp image-transform-resize))
1087 (boundp 'image-type)
1088 (eq image-type 'imagemagick))
1089 (let ((size (image-display-size (image-get-display-property) t)))
1090 (cond ((eq image-transform-resize 'fit-width)
1091 (cl-assert (= (car size)
1092 (- (nth 2 (window-inside-pixel-edges))
1093 (nth 0 (window-inside-pixel-edges))))
1094 t))
1095 ((eq image-transform-resize 'fit-height)
1096 (cl-assert (= (cdr size)
1097 (- (nth 3 (window-inside-pixel-edges))
1098 (nth 1 (window-inside-pixel-edges))))
1099 t))))))
1100
1101 (defun image-transform-properties (spec)
1102 "Return rescaling/rotation properties for image SPEC.
1103 These properties are determined by the Image mode variables
1104 `image-transform-resize' and `image-transform-rotation'. The
1105 return value is suitable for appending to an image spec.
1106
1107 Rescaling and rotation properties only take effect if Emacs is
1108 compiled with ImageMagick support."
1109 (setq image-transform-scale 1.0)
1110 (when (or image-transform-resize
1111 (/= image-transform-rotation 0.0))
1112 ;; Note: `image-size' looks up and thus caches the untransformed
1113 ;; image. There's no easy way to prevent that.
1114 (let* ((size (image-size spec t))
1115 (resized
1116 (cond
1117 ((numberp image-transform-resize)
1118 (unless (= image-transform-resize 1)
1119 (setq image-transform-scale image-transform-resize)
1120 (cons nil (floor (* image-transform-resize (cdr size))))))
1121 ((eq image-transform-resize 'fit-width)
1122 (image-transform-fit-width
1123 (car size) (cdr size)
1124 (- (nth 2 (window-inside-pixel-edges))
1125 (nth 0 (window-inside-pixel-edges)))))
1126 ((eq image-transform-resize 'fit-height)
1127 (let ((res (image-transform-fit-width
1128 (cdr size) (car size)
1129 (- (nth 3 (window-inside-pixel-edges))
1130 (nth 1 (window-inside-pixel-edges))))))
1131 (cons (cdr res) (car res)))))))
1132 `(,@(when (car resized)
1133 (list :width (car resized)))
1134 ,@(when (cdr resized)
1135 (list :height (cdr resized)))
1136 ,@(unless (= 0.0 image-transform-rotation)
1137 (list :rotation image-transform-rotation))))))
1138
1139 (defun image-transform-set-scale (scale)
1140 "Prompt for a number, and resize the current image by that amount.
1141 This command has no effect unless Emacs is compiled with
1142 ImageMagick support."
1143 (interactive "nScale: ")
1144 (setq image-transform-resize scale)
1145 (image-toggle-display-image))
1146
1147 (defun image-transform-fit-to-height ()
1148 "Fit the current image to the height of the current window.
1149 This command has no effect unless Emacs is compiled with
1150 ImageMagick support."
1151 (interactive)
1152 (setq image-transform-resize 'fit-height)
1153 (image-toggle-display-image))
1154
1155 (defun image-transform-fit-to-width ()
1156 "Fit the current image to the width of the current window.
1157 This command has no effect unless Emacs is compiled with
1158 ImageMagick support."
1159 (interactive)
1160 (setq image-transform-resize 'fit-width)
1161 (image-toggle-display-image))
1162
1163 (defun image-transform-set-rotation (rotation)
1164 "Prompt for an angle ROTATION, and rotate the image by that amount.
1165 ROTATION should be in degrees. This command has no effect unless
1166 Emacs is compiled with ImageMagick support."
1167 (interactive "nRotation angle (in degrees): ")
1168 (setq image-transform-rotation (float (mod rotation 360)))
1169 (image-toggle-display-image))
1170
1171 (defun image-transform-reset ()
1172 "Display the current image with the default size and rotation.
1173 This command has no effect unless Emacs is compiled with
1174 ImageMagick support."
1175 (interactive)
1176 (setq image-transform-resize nil
1177 image-transform-rotation 0.0
1178 image-transform-scale 1)
1179 (image-toggle-display-image))
1180
1181 (provide 'image-mode)
1182
1183 ;;; image-mode.el ends here