]> 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 special-mode-map)
376 (set-keymap-parent map image-map)
377 (define-key map "\C-c\C-c" 'image-toggle-display)
378 (define-key map "\C-c\C-x" 'image-toggle-hex-display)
379 (define-key map (kbd "SPC") 'image-scroll-up)
380 (define-key map (kbd "S-SPC") 'image-scroll-down)
381 (define-key map (kbd "DEL") 'image-scroll-down)
382 (define-key map (kbd "RET") 'image-toggle-animation)
383 (define-key map "F" 'image-goto-frame)
384 (define-key map "f" 'image-next-frame)
385 (define-key map "b" 'image-previous-frame)
386 (define-key map "n" 'image-next-file)
387 (define-key map "p" 'image-previous-file)
388 (define-key map "a+" 'image-increase-speed)
389 (define-key map "a-" 'image-decrease-speed)
390 (define-key map "a0" 'image-reset-speed)
391 (define-key map "ar" 'image-reverse-speed)
392 (define-key map "k" 'image-kill-buffer)
393 (define-key map [remap forward-char] 'image-forward-hscroll)
394 (define-key map [remap backward-char] 'image-backward-hscroll)
395 (define-key map [remap right-char] 'image-forward-hscroll)
396 (define-key map [remap left-char] 'image-backward-hscroll)
397 (define-key map [remap previous-line] 'image-previous-line)
398 (define-key map [remap next-line] 'image-next-line)
399 (define-key map [remap scroll-up] 'image-scroll-up)
400 (define-key map [remap scroll-down] 'image-scroll-down)
401 (define-key map [remap scroll-up-command] 'image-scroll-up)
402 (define-key map [remap scroll-down-command] 'image-scroll-down)
403 (define-key map [remap move-beginning-of-line] 'image-bol)
404 (define-key map [remap move-end-of-line] 'image-eol)
405 (define-key map [remap beginning-of-buffer] 'image-bob)
406 (define-key map [remap end-of-buffer] 'image-eob)
407 (easy-menu-define image-mode-menu map "Menu for Image mode."
408 '("Image"
409 ["Show as Text" image-toggle-display :active t
410 :help "Show image as text"]
411 ["Show as Hex" image-toggle-hex-display :active t
412 :help "Show image as hex"]
413 "--"
414 ["Fit to Window Height" image-transform-fit-to-height
415 :visible (eq image-type 'imagemagick)
416 :help "Resize image to match the window height"]
417 ["Fit to Window Width" image-transform-fit-to-width
418 :visible (eq image-type 'imagemagick)
419 :help "Resize image to match the window width"]
420 ["Rotate Image..." image-transform-set-rotation
421 :visible (eq image-type 'imagemagick)
422 :help "Rotate the image"]
423 ["Reset Transformations" image-transform-reset
424 :visible (eq image-type 'imagemagick)
425 :help "Reset all image transformations"]
426 "--"
427 ["Show Thumbnails"
428 (lambda ()
429 (interactive)
430 (image-dired default-directory))
431 :active default-directory
432 :help "Show thumbnails for all images in this directory"]
433 ["Next Image" image-next-file :active buffer-file-name
434 :help "Move to next image in this directory"]
435 ["Previous Image" image-previous-file :active buffer-file-name
436 :help "Move to previous image in this directory"]
437 "--"
438 ["Fit Frame to Image" image-mode-fit-frame :active t
439 :help "Resize frame to match image"]
440 "--"
441 ["Animate Image" image-toggle-animation :style toggle
442 :selected (let ((image (image-get-display-property)))
443 (and image (image-animate-timer image)))
444 :active image-multi-frame
445 :help "Toggle image animation"]
446 ["Loop Animation"
447 (lambda () (interactive)
448 (setq image-animate-loop (not image-animate-loop))
449 ;; FIXME this is a hacky way to make it affect a currently
450 ;; animating image.
451 (when (let ((image (image-get-display-property)))
452 (and image (image-animate-timer image)))
453 (image-toggle-animation)
454 (image-toggle-animation)))
455 :style toggle :selected image-animate-loop
456 :active image-multi-frame
457 :help "Animate images once, or forever?"]
458 ["Reverse Animation" image-reverse-speed
459 :style toggle :selected (let ((image (image-get-display-property)))
460 (and image (<
461 (image-animate-get-speed image)
462 0)))
463 :active image-multi-frame
464 :help "Reverse direction of this image's animation?"]
465 ["Speed Up Animation" image-increase-speed
466 :active image-multi-frame
467 :help "Speed up this image's animation"]
468 ["Slow Down Animation" image-decrease-speed
469 :active image-multi-frame
470 :help "Slow down this image's animation"]
471 ["Reset Animation Speed" image-reset-speed
472 :active image-multi-frame
473 :help "Reset the speed of this image's animation"]
474 ["Next Frame" image-next-frame :active image-multi-frame
475 :help "Show the next frame of this image"]
476 ["Previous Frame" image-previous-frame :active image-multi-frame
477 :help "Show the previous frame of this image"]
478 ["Goto Frame..." image-goto-frame :active image-multi-frame
479 :help "Show a specific frame of this image"]
480 ))
481 map)
482 "Mode keymap for `image-mode'.")
483
484 (defvar image-minor-mode-map
485 (let ((map (make-sparse-keymap)))
486 (define-key map "\C-c\C-c" 'image-toggle-display)
487 (define-key map "\C-c\C-x" 'image-toggle-hex-display)
488 map)
489 "Mode keymap for `image-minor-mode'.")
490
491 (defvar bookmark-make-record-function)
492
493 (put 'image-mode 'mode-class 'special)
494
495 ;;;###autoload
496 (defun image-mode ()
497 "Major mode for image files.
498 You can use \\<image-mode-map>\\[image-toggle-display] or \\<image-mode-map>\\[image-toggle-hex-display]
499 to toggle between display as an image and display as text or hex.
500
501 Key bindings:
502 \\{image-mode-map}"
503 (interactive)
504 (condition-case err
505 (progn
506 (unless (display-images-p)
507 (error "Display does not support images"))
508
509 (kill-all-local-variables)
510 (setq major-mode 'image-mode)
511
512 (if (not (image-get-display-property))
513 (progn
514 (image-toggle-display-image)
515 ;; If attempt to display the image fails.
516 (if (not (image-get-display-property))
517 (error "Invalid image")))
518 ;; Set next vars when image is already displayed but local
519 ;; variables were cleared by kill-all-local-variables
520 (setq cursor-type nil truncate-lines t
521 image-type (plist-get (cdr (image-get-display-property)) :type)))
522
523 (setq mode-name (if image-type (format "Image[%s]" image-type) "Image"))
524 (use-local-map image-mode-map)
525
526 ;; Use our own bookmarking function for images.
527 (setq-local bookmark-make-record-function
528 #'image-bookmark-make-record)
529
530 ;; Keep track of [vh]scroll when switching buffers
531 (image-mode-setup-winprops)
532
533 (add-hook 'change-major-mode-hook 'image-toggle-display-text nil t)
534 (add-hook 'after-revert-hook 'image-after-revert-hook nil t)
535 (run-mode-hooks 'image-mode-hook)
536 (let ((image (image-get-display-property))
537 (msg1 (substitute-command-keys
538 "Type \\[image-toggle-display] or \\[image-toggle-hex-display] to view the image as "))
539 animated)
540 (cond
541 ((null image)
542 (message "%s" (concat msg1 "an image.")))
543 ((setq animated (image-multi-frame-p image))
544 (setq image-multi-frame t
545 mode-line-process
546 `(:eval
547 (concat " "
548 (propertize
549 (format "[%s/%s]"
550 (1+ (image-current-frame ',image))
551 ,(car animated))
552 'help-echo "Frames
553 mouse-1: Next frame
554 mouse-3: Previous frame"
555 'mouse-face 'mode-line-highlight
556 'local-map
557 '(keymap
558 (mode-line
559 keymap
560 (down-mouse-1 . image-next-frame)
561 (down-mouse-3 . image-previous-frame)))))))
562 (message "%s"
563 (concat msg1 "text. This image has multiple frames.")))
564 ;;; (substitute-command-keys
565 ;;; "\\[image-toggle-animation] to animate."))))
566 (t
567 (message "%s" (concat msg1 "text or hex."))))))
568
569 (error
570 (image-mode-as-text)
571 (funcall
572 (if (called-interactively-p 'any) 'error 'message)
573 "Cannot display image: %s" (cdr err)))))
574
575 ;;;###autoload
576 (define-minor-mode image-minor-mode
577 "Toggle Image minor mode in this buffer.
578 With a prefix argument ARG, enable Image minor mode if ARG is
579 positive, and disable it otherwise. If called from Lisp, enable
580 the mode if ARG is omitted or nil.
581
582 Image minor mode provides the key \\<image-mode-map>\\[image-toggle-display],
583 to switch back to `image-mode' and display an image file as the
584 actual image."
585 nil (:eval (if image-type (format " Image[%s]" image-type) " Image"))
586 image-minor-mode-map
587 :group 'image
588 :version "22.1"
589 (if image-minor-mode
590 (add-hook 'change-major-mode-hook (lambda () (image-minor-mode -1)) nil t)))
591
592 ;;;###autoload
593 (defun image-mode-to-text ()
594 "Set a non-image mode as major mode in combination with image minor mode.
595 A non-mage major mode found from `auto-mode-alist' or fundamental mode
596 displays an image file as text."
597 ;; image-mode-as-text = normal-mode + image-minor-mode
598 (let ((previous-image-type image-type)) ; preserve `image-type'
599 (if image-mode-previous-major-mode
600 ;; Restore previous major mode that was already found by this
601 ;; function and cached in `image-mode-previous-major-mode'
602 (funcall image-mode-previous-major-mode)
603 (let ((auto-mode-alist
604 (delq nil (mapcar
605 (lambda (elt)
606 (unless (memq (or (car-safe (cdr elt)) (cdr elt))
607 '(image-mode image-mode-maybe image-mode-as-text))
608 elt))
609 auto-mode-alist)))
610 (magic-fallback-mode-alist
611 (delq nil (mapcar
612 (lambda (elt)
613 (unless (memq (or (car-safe (cdr elt)) (cdr elt))
614 '(image-mode image-mode-maybe image-mode-as-text))
615 elt))
616 magic-fallback-mode-alist))))
617 (normal-mode)
618 (setq-local image-mode-previous-major-mode major-mode)))
619 ;; Restore `image-type' after `kill-all-local-variables' in `normal-mode'.
620 (setq image-type previous-image-type)
621 ;; Enable image minor mode with `C-c C-c'.
622 (image-minor-mode 1)
623 ;; Show the image file as text.
624 (image-toggle-display-text)))
625
626 (defun image-mode-as-hex ()
627 "Set a non-image mode as major mode in combination with image minor mode.
628 A non-mage major mode found from `auto-mode-alist' or fundamental mode
629 displays an image file as hex. `image-minor-mode' provides the key
630 \\<image-mode-map>\\[image-toggle-hex-display] to switch back to `image-mode'
631 to display an image file as the actual image.
632
633 You can use `image-mode-as-hex' in `auto-mode-alist' when you want to
634 to display an image file as hex initially.
635
636 See commands `image-mode' and `image-minor-mode' for more information
637 on these modes."
638 (interactive)
639 (image-mode-to-text)
640 ;; Turn on hexl-mode
641 (hexl-mode)
642 (message "%s" (concat
643 (substitute-command-keys
644 "Type \\[image-toggle-hex-display] or \\[image-toggle-display] to view the image as ")
645 (if (image-get-display-property)
646 "hex" "an image or text") ".")))
647
648 (defun image-mode-as-text ()
649 "Set a non-image mode as major mode in combination with image minor mode.
650 A non-image major mode found from `auto-mode-alist' or Fundamental mode
651 displays an image file as text. `image-minor-mode' provides the key
652 \\<image-mode-map>\\[image-toggle-display] to switch back to `image-mode'
653 to display an image file as the actual image.
654
655 You can use `image-mode-as-text' in `auto-mode-alist' when you want
656 to display an image file as text initially.
657
658 See commands `image-mode' and `image-minor-mode' for more information
659 on these modes."
660 (interactive)
661 (image-mode-to-text)
662 (message "%s" (concat
663 (substitute-command-keys
664 "Type \\[image-toggle-display] or \\[image-toggle-hex-display] to view the image as ")
665 (if (image-get-display-property)
666 "text" "an image or hex") ".")))
667
668 (define-obsolete-function-alias 'image-mode-maybe 'image-mode "23.2")
669
670 (defun image-toggle-display-text ()
671 "Show the image file as text.
672 Remove text properties that display the image."
673 (let ((inhibit-read-only t)
674 (buffer-undo-list t)
675 (modified (buffer-modified-p)))
676 (remove-list-of-text-properties (point-min) (point-max)
677 '(display read-nonsticky ;; intangible
678 read-only front-sticky))
679 (set-buffer-modified-p modified)
680 (if (called-interactively-p 'any)
681 (message "Repeat this command to go back to displaying the image"))))
682
683 (defvar archive-superior-buffer)
684 (defvar tar-superior-buffer)
685 (declare-function image-flush "image.c" (spec &optional frame))
686
687 (defun image-toggle-display-image ()
688 "Show the image of the image file.
689 Turn the image data into a real image, but only if the whole file
690 was inserted."
691 (unless (derived-mode-p 'image-mode)
692 (error "The buffer is not in Image mode"))
693 (let* ((filename (buffer-file-name))
694 (data-p (not (and filename
695 (file-readable-p filename)
696 (not (file-remote-p filename))
697 (not (buffer-modified-p))
698 (not (and (boundp 'archive-superior-buffer)
699 archive-superior-buffer))
700 (not (and (boundp 'tar-superior-buffer)
701 tar-superior-buffer))
702 ;; This means the buffer holds the
703 ;; decrypted content (bug#21870).
704 (not (and (boundp 'epa-file-encrypt-to)
705 (local-variable-p
706 'epa-file-encrypt-to))))))
707 (file-or-data (if data-p
708 (string-make-unibyte
709 (buffer-substring-no-properties (point-min) (point-max)))
710 filename))
711 ;; If we have a `fit-width' or a `fit-height', don't limit
712 ;; the size of the image to the window size.
713 (edges (and (null image-transform-resize)
714 (window-inside-pixel-edges
715 (get-buffer-window (current-buffer)))))
716 (type (if (fboundp 'imagemagick-types)
717 'imagemagick
718 (image-type file-or-data nil data-p)))
719 (image (if (not edges)
720 (create-image file-or-data type data-p)
721 (create-image file-or-data type data-p
722 :max-width (- (nth 2 edges) (nth 0 edges))
723 :max-height (- (nth 3 edges) (nth 1 edges)))))
724 (inhibit-read-only t)
725 (buffer-undo-list t)
726 (modified (buffer-modified-p))
727 props)
728
729 ;; Discard any stale image data before looking it up again.
730 (image-flush image)
731 (setq image (append image (image-transform-properties image)))
732 (setq props
733 `(display ,image
734 ;; intangible ,image
735 rear-nonsticky (display) ;; intangible
736 read-only t front-sticky (read-only)))
737
738 (let ((buffer-file-truename nil)) ; avoid changing dir mtime by lock_file
739 (add-text-properties (point-min) (point-max) props)
740 (restore-buffer-modified-p modified))
741 ;; Inhibit the cursor when the buffer contains only an image,
742 ;; because cursors look very strange on top of images.
743 (setq cursor-type nil)
744 ;; This just makes the arrow displayed in the right fringe
745 ;; area look correct when the image is wider than the window.
746 (setq truncate-lines t)
747 ;; Disable adding a newline at the end of the image file when it
748 ;; is written with, e.g., C-x C-w.
749 (if (coding-system-equal (coding-system-base buffer-file-coding-system)
750 'no-conversion)
751 (setq-local find-file-literally t))
752 ;; Allow navigation of large images.
753 (setq-local auto-hscroll-mode nil)
754 (setq image-type type)
755 (if (eq major-mode 'image-mode)
756 (setq mode-name (format "Image[%s]" type)))
757 (image-transform-check-size)
758 (if (called-interactively-p 'any)
759 (message "Repeat this command to go back to displaying the file as text"))))
760
761 (defun image-toggle-hex-display ()
762 "Toggle between image and hex display."
763 (interactive)
764 (if (image-get-display-property)
765 (image-mode-as-hex)
766 (if (eq major-mode 'fundamental-mode)
767 (image-mode-as-hex)
768 (image-mode))))
769
770 (defun image-toggle-display ()
771 "Toggle between image and text display.
772
773 If the current buffer is displaying an image file as an image,
774 call `image-mode-as-text' to switch to text or hex display.
775 Otherwise, display the image by calling `image-mode'"
776 (interactive)
777 (if (image-get-display-property)
778 (image-mode-as-text)
779 (if (eq major-mode 'hexl-mode)
780 (image-mode-as-text)
781 (image-mode))))
782
783 (defun image-kill-buffer ()
784 "Kill the current buffer."
785 (interactive)
786 (kill-buffer (current-buffer)))
787
788 (defun image-after-revert-hook ()
789 (when (image-get-display-property)
790 (image-toggle-display-text)
791 ;; Update image display.
792 (mapc (lambda (window) (redraw-frame (window-frame window)))
793 (get-buffer-window-list (current-buffer) 'nomini 'visible))
794 (image-toggle-display-image)))
795
796 \f
797 ;;; Animated images
798
799 (defcustom image-animate-loop nil
800 "Non-nil means animated images loop forever, rather than playing once."
801 :type 'boolean
802 :version "24.1"
803 :group 'image)
804
805 (defun image-toggle-animation ()
806 "Start or stop animating the current image.
807 If `image-animate-loop' is non-nil, animation loops forever.
808 Otherwise it plays once, then stops."
809 (interactive)
810 (let ((image (image-get-display-property))
811 animation)
812 (cond
813 ((null image)
814 (error "No image is present"))
815 ((null (setq animation (image-multi-frame-p image)))
816 (message "No image animation."))
817 (t
818 (let ((timer (image-animate-timer image)))
819 (if timer
820 (cancel-timer timer)
821 (let ((index (plist-get (cdr image) :index)))
822 ;; If we're at the end, restart.
823 (and index
824 (>= index (1- (car animation)))
825 (setq index nil))
826 (image-animate image index
827 (if image-animate-loop t)))))))))
828
829 (defun image--set-speed (speed &optional multiply)
830 "Set speed of an animated image to SPEED.
831 If MULTIPLY is non-nil, treat SPEED as a multiplication factor.
832 If SPEED is `reset', reset the magnitude of the speed to 1."
833 (let ((image (image-get-display-property)))
834 (cond
835 ((null image)
836 (error "No image is present"))
837 ((null image-multi-frame)
838 (message "No image animation."))
839 (t
840 (if (eq speed 'reset)
841 (setq speed (if (< (image-animate-get-speed image) 0)
842 -1 1)
843 multiply nil))
844 (image-animate-set-speed image speed multiply)
845 ;; FIXME Hack to refresh an active image.
846 (when (image-animate-timer image)
847 (image-toggle-animation)
848 (image-toggle-animation))
849 (message "Image speed is now %s" (image-animate-get-speed image))))))
850
851 (defun image-increase-speed ()
852 "Increase the speed of current animated image by a factor of 2."
853 (interactive)
854 (image--set-speed 2 t))
855
856 (defun image-decrease-speed ()
857 "Decrease the speed of current animated image by a factor of 2."
858 (interactive)
859 (image--set-speed 0.5 t))
860
861 (defun image-reverse-speed ()
862 "Reverse the animation of the current image."
863 (interactive)
864 (image--set-speed -1 t))
865
866 (defun image-reset-speed ()
867 "Reset the animation speed of the current image."
868 (interactive)
869 (image--set-speed 'reset))
870
871 (defun image-goto-frame (n &optional relative)
872 "Show frame N of a multi-frame image.
873 Optional argument OFFSET non-nil means interpret N as relative to the
874 current frame. Frames are indexed from 1."
875 (interactive
876 (list (or current-prefix-arg
877 (read-number "Show frame number: "))))
878 (let ((image (image-get-display-property)))
879 (cond
880 ((null image)
881 (error "No image is present"))
882 ((null image-multi-frame)
883 (message "No image animation."))
884 (t
885 (image-show-frame image
886 (if relative
887 (+ n (image-current-frame image))
888 (1- n)))))))
889
890 (defun image-next-frame (&optional n)
891 "Switch to the next frame of a multi-frame image.
892 With optional argument N, switch to the Nth frame after the current one.
893 If N is negative, switch to the Nth frame before the current one."
894 (interactive "p")
895 (image-goto-frame n t))
896
897 (defun image-previous-frame (&optional n)
898 "Switch to the previous frame of a multi-frame image.
899 With optional argument N, switch to the Nth frame before the current one.
900 If N is negative, switch to the Nth frame after the current one."
901 (interactive "p")
902 (image-next-frame (- n)))
903
904 \f
905 ;;; Switching to the next/previous image
906
907 (defun image-next-file (&optional n)
908 "Visit the next image in the same directory as the current image file.
909 With optional argument N, visit the Nth image file after the
910 current one, in cyclic alphabetical order.
911
912 This command visits the specified file via `find-alternate-file',
913 replacing the current Image mode buffer."
914 (interactive "p")
915 (unless (derived-mode-p 'image-mode)
916 (error "The buffer is not in Image mode"))
917 (unless buffer-file-name
918 (error "The current image is not associated with a file"))
919 (let* ((file (file-name-nondirectory buffer-file-name))
920 (images (image-mode--images-in-directory file))
921 (idx 0))
922 (catch 'image-visit-next-file
923 (dolist (f images)
924 (if (string= f file)
925 (throw 'image-visit-next-file (1+ idx)))
926 (setq idx (1+ idx))))
927 (setq idx (mod (+ idx (or n 1)) (length images)))
928 (find-alternate-file (nth idx images))))
929
930 (defun image-previous-file (&optional n)
931 "Visit the preceding image in the same directory as the current file.
932 With optional argument N, visit the Nth image file preceding the
933 current one, in cyclic alphabetical order.
934
935 This command visits the specified file via `find-alternate-file',
936 replacing the current Image mode buffer."
937 (interactive "p")
938 (image-next-file (- n)))
939
940 (defun image-mode--images-in-directory (file)
941 (let* ((dir (file-name-directory buffer-file-name))
942 (files (directory-files dir nil
943 (image-file-name-regexp) t)))
944 ;; Add the current file to the list of images if necessary, in
945 ;; case it does not match `image-file-name-regexp'.
946 (unless (member file files)
947 (push file files))
948 (sort files 'string-lessp)))
949
950 \f
951 ;;; Support for bookmark.el
952 (declare-function bookmark-make-record-default
953 "bookmark" (&optional no-file no-context posn))
954 (declare-function bookmark-prop-get "bookmark" (bookmark prop))
955 (declare-function bookmark-default-handler "bookmark" (bmk))
956
957 (defun image-bookmark-make-record ()
958 `(,@(bookmark-make-record-default nil 'no-context 0)
959 (image-type . ,image-type)
960 (handler . image-bookmark-jump)))
961
962 ;;;###autoload
963 (defun image-bookmark-jump (bmk)
964 ;; This implements the `handler' function interface for record type
965 ;; returned by `bookmark-make-record-function', which see.
966 (prog1 (bookmark-default-handler bmk)
967 (when (not (string= image-type (bookmark-prop-get bmk 'image-type)))
968 (image-toggle-display))))
969 \f
970
971 ;; Not yet implemented.
972 ;; (defvar image-transform-minor-mode-map
973 ;; (let ((map (make-sparse-keymap)))
974 ;; ;; (define-key map [(control ?+)] 'image-scale-in)
975 ;; ;; (define-key map [(control ?-)] 'image-scale-out)
976 ;; ;; (define-key map [(control ?=)] 'image-scale-none)
977 ;; ;; (define-key map "c f h" 'image-scale-fit-height)
978 ;; ;; (define-key map "c ]" 'image-rotate-right)
979 ;; map)
980 ;; "Minor mode keymap `image-transform-mode'.")
981 ;;
982 ;; (define-minor-mode image-transform-mode
983 ;; "Minor mode for scaling and rotating images.
984 ;; With a prefix argument ARG, enable the mode if ARG is positive,
985 ;; and disable it otherwise. If called from Lisp, enable the mode
986 ;; if ARG is omitted or nil. This minor mode requires Emacs to have
987 ;; been compiled with ImageMagick support."
988 ;; nil "image-transform" image-transform-minor-mode-map)
989
990
991 (defsubst image-transform-width (width height)
992 "Return the bounding box width of a rotated WIDTH x HEIGHT rectangle.
993 The rotation angle is the value of `image-transform-rotation' in degrees."
994 (let ((angle (degrees-to-radians image-transform-rotation)))
995 ;; Assume, w.l.o.g., that the vertices of the rectangle have the
996 ;; coordinates (+-w/2, +-h/2) and that (0, 0) is the center of the
997 ;; rotation by the angle A. The projections onto the first axis
998 ;; of the vertices of the rotated rectangle are +- (w/2) cos A +-
999 ;; (h/2) sin A, and the difference between the largest and the
1000 ;; smallest of the four values is the expression below.
1001 (+ (* width (abs (cos angle))) (* height (abs (sin angle))))))
1002
1003 ;; The following comment and code snippet are from
1004 ;; ImageMagick-6.7.4-4/magick/distort.c
1005
1006 ;; /* Set the output image geometry to calculated 'best fit'.
1007 ;; Yes this tends to 'over do' the file image size, ON PURPOSE!
1008 ;; Do not do this for DePolar which needs to be exact for virtual tiling.
1009 ;; */
1010 ;; if ( fix_bounds ) {
1011 ;; geometry.x = (ssize_t) floor(min.x-0.5);
1012 ;; geometry.y = (ssize_t) floor(min.y-0.5);
1013 ;; geometry.width=(size_t) ceil(max.x-geometry.x+0.5);
1014 ;; geometry.height=(size_t) ceil(max.y-geometry.y+0.5);
1015 ;; }
1016
1017 ;; Other parts of the same file show that here the origin is in the
1018 ;; left lower corner of the image rectangle, the center of the
1019 ;; rotation is the center of the rectangle and min.x and max.x
1020 ;; (resp. min.y and max.y) are the smallest and the largest of the
1021 ;; projections of the vertices onto the first (resp. second) axis.
1022
1023 (defun image-transform-fit-width (width height length)
1024 "Return (w . h) so that a rotated w x h image has exactly width LENGTH.
1025 The rotation angle is the value of `image-transform-rotation'.
1026 Write W for WIDTH and H for HEIGHT. Then the w x h rectangle is
1027 an \"approximately uniformly\" scaled W x H rectangle, which
1028 currently means that w is one of floor(s W) + {0, 1, -1} and h is
1029 floor(s H), where s can be recovered as the value of `image-transform-scale'.
1030 The value of `image-transform-rotation' may be replaced by
1031 a slightly different angle. Currently this is done for values
1032 close to a multiple of 90, see `image-transform-right-angle-fudge'."
1033 (cond ((< (abs (- (mod (+ image-transform-rotation 90) 180) 90))
1034 image-transform-right-angle-fudge)
1035 (cl-assert (not (zerop width)) t)
1036 (setq image-transform-rotation
1037 (float (round image-transform-rotation))
1038 image-transform-scale (/ (float length) width))
1039 (cons length nil))
1040 ((< (abs (- (mod (+ image-transform-rotation 45) 90) 45))
1041 image-transform-right-angle-fudge)
1042 (cl-assert (not (zerop height)) t)
1043 (setq image-transform-rotation
1044 (float (round image-transform-rotation))
1045 image-transform-scale (/ (float length) height))
1046 (cons nil length))
1047 (t
1048 (cl-assert (not (and (zerop width) (zerop height))) t)
1049 (setq image-transform-scale
1050 (/ (float (1- length)) (image-transform-width width height)))
1051 ;; Assume we have a w x h image and an angle A, and let l =
1052 ;; l(w, h) = w |cos A| + h |sin A|, which is the actual width
1053 ;; of the bounding box of the rotated image, as calculated by
1054 ;; `image-transform-width'. The code snippet quoted above
1055 ;; means that ImageMagick puts the rotated image in
1056 ;; a bounding box of width L = 2 ceil((w+l+1)/2) - w.
1057 ;; Elementary considerations show that this is equivalent to
1058 ;; L - w being even and L-3 < l(w, h) <= L-1. In our case, L is
1059 ;; the given `length' parameter and our job is to determine
1060 ;; reasonable values for w and h which satisfy these
1061 ;; conditions.
1062 (let ((w (floor (* image-transform-scale width)))
1063 (h (floor (* image-transform-scale height))))
1064 ;; Let w and h as bound above. Then l(w, h) <= l(s W, s H)
1065 ;; = L-1 < l(w+1, h+1) = l(w, h) + l(1, 1) <= l(w, h) + 2,
1066 ;; hence l(w, h) > (L-1) - 2 = L-3.
1067 (cons
1068 (cond ((= (mod w 2) (mod length 2))
1069 w)
1070 ;; l(w+1, h) >= l(w, h) > L-3, but does l(w+1, h) <=
1071 ;; L-1 hold?
1072 ((<= (image-transform-width (1+ w) h) (1- length))
1073 (1+ w))
1074 ;; No, it doesn't, but this implies that l(w-1, h) =
1075 ;; l(w+1, h) - l(2, 0) >= l(w+1, h) - 2 > (L-1) -
1076 ;; 2 = L-3. Clearly, l(w-1, h) <= l(w, h) <= L-1.
1077 (t
1078 (1- w)))
1079 h)))))
1080
1081 (defun image-transform-check-size ()
1082 "Check that the image exactly fits the width/height of the window.
1083
1084 Do this for an image of type `imagemagick' to make sure that the
1085 elisp code matches the way ImageMagick computes the bounding box
1086 of a rotated image."
1087 (when (and (not (numberp image-transform-resize))
1088 (boundp 'image-type)
1089 (eq image-type 'imagemagick))
1090 (let ((size (image-display-size (image-get-display-property) t)))
1091 (cond ((eq image-transform-resize 'fit-width)
1092 (cl-assert (= (car size)
1093 (- (nth 2 (window-inside-pixel-edges))
1094 (nth 0 (window-inside-pixel-edges))))
1095 t))
1096 ((eq image-transform-resize 'fit-height)
1097 (cl-assert (= (cdr size)
1098 (- (nth 3 (window-inside-pixel-edges))
1099 (nth 1 (window-inside-pixel-edges))))
1100 t))))))
1101
1102 (defun image-transform-properties (spec)
1103 "Return rescaling/rotation properties for image SPEC.
1104 These properties are determined by the Image mode variables
1105 `image-transform-resize' and `image-transform-rotation'. The
1106 return value is suitable for appending to an image spec.
1107
1108 Rescaling and rotation properties only take effect if Emacs is
1109 compiled with ImageMagick support."
1110 (setq image-transform-scale 1.0)
1111 (when (or image-transform-resize
1112 (/= image-transform-rotation 0.0))
1113 ;; Note: `image-size' looks up and thus caches the untransformed
1114 ;; image. There's no easy way to prevent that.
1115 (let* ((size (image-size spec t))
1116 (resized
1117 (cond
1118 ((numberp image-transform-resize)
1119 (unless (= image-transform-resize 1)
1120 (setq image-transform-scale image-transform-resize)
1121 (cons nil (floor (* image-transform-resize (cdr size))))))
1122 ((eq image-transform-resize 'fit-width)
1123 (image-transform-fit-width
1124 (car size) (cdr size)
1125 (- (nth 2 (window-inside-pixel-edges))
1126 (nth 0 (window-inside-pixel-edges)))))
1127 ((eq image-transform-resize 'fit-height)
1128 (let ((res (image-transform-fit-width
1129 (cdr size) (car size)
1130 (- (nth 3 (window-inside-pixel-edges))
1131 (nth 1 (window-inside-pixel-edges))))))
1132 (cons (cdr res) (car res)))))))
1133 `(,@(when (car resized)
1134 (list :width (car resized)))
1135 ,@(when (cdr resized)
1136 (list :height (cdr resized)))
1137 ,@(unless (= 0.0 image-transform-rotation)
1138 (list :rotation image-transform-rotation))))))
1139
1140 (defun image-transform-set-scale (scale)
1141 "Prompt for a number, and resize the current image by that amount.
1142 This command has no effect unless Emacs is compiled with
1143 ImageMagick support."
1144 (interactive "nScale: ")
1145 (setq image-transform-resize scale)
1146 (image-toggle-display-image))
1147
1148 (defun image-transform-fit-to-height ()
1149 "Fit the current image to the height of the current window.
1150 This command has no effect unless Emacs is compiled with
1151 ImageMagick support."
1152 (interactive)
1153 (setq image-transform-resize 'fit-height)
1154 (image-toggle-display-image))
1155
1156 (defun image-transform-fit-to-width ()
1157 "Fit the current image to the width of the current window.
1158 This command has no effect unless Emacs is compiled with
1159 ImageMagick support."
1160 (interactive)
1161 (setq image-transform-resize 'fit-width)
1162 (image-toggle-display-image))
1163
1164 (defun image-transform-set-rotation (rotation)
1165 "Prompt for an angle ROTATION, and rotate the image by that amount.
1166 ROTATION should be in degrees. This command has no effect unless
1167 Emacs is compiled with ImageMagick support."
1168 (interactive "nRotation angle (in degrees): ")
1169 (setq image-transform-rotation (float (mod rotation 360)))
1170 (image-toggle-display-image))
1171
1172 (defun image-transform-reset ()
1173 "Display the current image with the default size and rotation.
1174 This command has no effect unless Emacs is compiled with
1175 ImageMagick support."
1176 (interactive)
1177 (setq image-transform-resize nil
1178 image-transform-rotation 0.0
1179 image-transform-scale 1)
1180 (image-toggle-display-image))
1181
1182 (provide 'image-mode)
1183
1184 ;;; image-mode.el ends here