Commit ed8d7fca authored by Glenn Morris's avatar Glenn Morris
Browse files

Generalize "animated" images to "multi-frame" images

* lisp/image.el (image-animated-types): Remove.
(image-multi-frame-p): Rename from image-animated-p, and generalize.
(image-animated-p): Make obsolete alias.
(image-animate, image-nth-frame, image-animate-timeout):
Use image-multi-frame-p.
(image-animate-timeout): If no delay, use image-default-frame-delay.

* lisp/image-mode.el (image-mode, image-toggle-animation):
Use image-multi-frame-p.
(image-mode): Adjust startup message for a multi-frame image.

* lisp/gnus/shr.el (shr-put-image): Only animate images that specify a delay.
This is consistent with the old image-animated-p behavior.

* etc/NEWS: Add placeholder for this.

Fixes: debbugs:10739
parent 783b7b75
...@@ -145,6 +145,8 @@ directory, respectively. ...@@ -145,6 +145,8 @@ directory, respectively.
`f' (`image-next-frame') and `b' (`image-previous-frame') visit the `f' (`image-next-frame') and `b' (`image-previous-frame') visit the
next or previous frame. `F' (`image-goto-frame') shows a specific frame. next or previous frame. `F' (`image-goto-frame') shows a specific frame.
*** `image-animated-p' is now `image-multi-frame-p'.
--- ---
*** The command `image-mode-fit-frame' deletes other windows. *** The command `image-mode-fit-frame' deletes other windows.
When toggling, it restores the frame's previous window configuration. When toggling, it restores the frame's previous window configuration.
......
2013-02-16 Glenn Morris <rgm@gnu.org> 2013-02-16 Glenn Morris <rgm@gnu.org>
   
* image.el (image-animated-types): Remove.
(image-multi-frame-p): Rename from image-animated-p, and generalize.
(image-animated-p): Make obsolete alias.
(image-animate, image-nth-frame, image-animate-timeout):
Use image-multi-frame-p.
(image-animate-timeout): If no delay, use image-default-frame-delay.
* image-mode.el (image-mode, image-toggle-animation):
Use image-multi-frame-p. (Bug#763, bug#10739)
(image-mode): Adjust startup message for a multi-frame image.
* image-mode.el (image-mode-map): Give it a menu. * image-mode.el (image-mode-map): Give it a menu.
   
2013-02-16 Michael Albinus <michael.albinus@gmx.de> 2013-02-16 Michael Albinus <michael.albinus@gmx.de>
......
2013-02-16 Glenn Morris <rgm@gnu.org>
* shr.el (shr-put-image): Only animate images that specify a delay.
This is consistent with the old image-animated-p behavior.
2013-02-14 Katsumi Yamaoka <yamaoka@jpl.org> 2013-02-14 Katsumi Yamaoka <yamaoka@jpl.org>
   
* gnus-util.el (gnus-define-keys): Convert [?\S-\ ] to [(shift space)] * gnus-util.el (gnus-define-keys): Convert [?\S-\ ] to [(shift space)]
......
...@@ -615,7 +615,8 @@ size, and full-buffer size." ...@@ -615,7 +615,8 @@ size, and full-buffer size."
(overlay-put overlay 'face 'default))) (overlay-put overlay 'face 'default)))
(insert-image image (or alt "*"))) (insert-image image (or alt "*")))
(put-text-property start (point) 'image-size size) (put-text-property start (point) 'image-size size)
(when (image-animated-p image) ;; Only animate multi-frame things that specify a delay. FIXME?
(when (cdr (image-animated-p image))
(image-animate image nil 60))) (image-animate image nil 60)))
image) image)
(insert alt))) (insert alt)))
......
...@@ -464,7 +464,7 @@ to toggle between display as an image and display as text." ...@@ -464,7 +464,7 @@ to toggle between display as an image and display as text."
(cond (cond
((null image) ((null image)
(message "%s" (concat msg1 "an image."))) (message "%s" (concat msg1 "an image.")))
((setq animated (image-animated-p image)) ((setq animated (image-multi-frame-p image))
(setq image-current-frame (or (plist-get (cdr image) :index) 0) (setq image-current-frame (or (plist-get (cdr image) :index) 0)
mode-line-process mode-line-process
`(:eval (propertize (format " [%s/%s]" `(:eval (propertize (format " [%s/%s]"
...@@ -472,9 +472,9 @@ to toggle between display as an image and display as text." ...@@ -472,9 +472,9 @@ to toggle between display as an image and display as text."
,(car animated)) ,(car animated))
'help-echo "Frame number"))) 'help-echo "Frame number")))
(message "%s" (message "%s"
(concat msg1 "text, or " (concat msg1 "text. This image has multiple frames.")))
(substitute-command-keys ;;; (substitute-command-keys
"\\[image-toggle-animation] to animate.")))) ;;; "\\[image-toggle-animation] to animate."))))
(t (t
(message "%s" (concat msg1 "text.")))))) (message "%s" (concat msg1 "text."))))))
...@@ -663,7 +663,7 @@ Otherwise it plays once, then stops." ...@@ -663,7 +663,7 @@ Otherwise it plays once, then stops."
(cond (cond
((null image) ((null image)
(error "No image is present")) (error "No image is present"))
((null (setq animation (image-animated-p image))) ((null (setq animation (image-multi-frame-p image)))
(message "No image animation.")) (message "No image animation."))
(t (t
(let ((timer (image-animate-timer image))) (let ((timer (image-animate-timer image)))
......
...@@ -606,29 +606,25 @@ Example: ...@@ -606,29 +606,25 @@ Example:
;;; Animated image API ;;; Animated image API
(defconst image-animated-types '(gif)
"List of supported animated image types.")
(defvar image-default-frame-delay 0.1 (defvar image-default-frame-delay 0.1
"Default interval in seconds between frames of a multi-frame image. "Default interval in seconds between frames of a multi-frame image.
Only used if the image does not specify a value.") Only used if the image does not specify a value.")
(defun image-animated-p (image) (defun image-multi-frame-p (image)
"Return non-nil if IMAGE can be animated. "Return non-nil if IMAGE contains more than one frame.
To be capable of being animated, an image must be of a type The actual return value is a cons (NIMAGES . DELAY), where NIMAGES is
listed in `image-animated-types', and contain more than one the number of frames (or sub-images) in the image and DELAY is the delay
sub-image, with a specified animation delay. The actual return in seconds that the image specifies between each frame. DELAY may be nil,
value is a cons (NIMAGES . DELAY), where NIMAGES is the number in which case you might want to use `image-default-frame-delay'."
of sub-images in the animated image and DELAY is the delay in (let* ((metadata (image-metadata image))
seconds until the next sub-image should be displayed." (images (plist-get metadata 'count))
(cond (delay (plist-get metadata 'delay)))
((memq (plist-get (cdr image) :type) image-animated-types) (when (and images (> images 1))
(let* ((metadata (image-metadata image)) (if (or (not (numberp delay)) (< delay 0))
(images (plist-get metadata 'count)) (setq delay image-default-frame-delay))
(delay (plist-get metadata 'delay))) (cons images delay))))
(when (and images (> images 1) (numberp delay))
(if (< delay 0) (setq delay image-default-frame-delay)) (define-obsolete-function-alias 'image-animated-p 'image-multi-frame-p "24.4")
(cons images delay))))))
;; "Destructively"? ;; "Destructively"?
(defun image-animate (image &optional index limit) (defun image-animate (image &optional index limit)
...@@ -639,7 +635,7 @@ With optional INDEX, begin animating from that animation frame. ...@@ -639,7 +635,7 @@ With optional INDEX, begin animating from that animation frame.
LIMIT specifies how long to animate the image. If omitted or LIMIT specifies how long to animate the image. If omitted or
nil, play the animation until the end. If t, loop forever. If a nil, play the animation until the end. If t, loop forever. If a
number, play until that number of seconds has elapsed." number, play until that number of seconds has elapsed."
(let ((animation (image-animated-p image)) (let ((animation (image-multi-frame-p image))
timer) timer)
(when animation (when animation
(if (setq timer (image-animate-timer image)) (if (setq timer (image-animate-timer image))
...@@ -673,13 +669,13 @@ Frames are indexed from 0. Optional argument NOCHECK non-nil means ...@@ -673,13 +669,13 @@ Frames are indexed from 0. Optional argument NOCHECK non-nil means
do not check N is within the range of frames present in the image." do not check N is within the range of frames present in the image."
(unless nocheck (unless nocheck
(if (< n 0) (setq n 0) (if (< n 0) (setq n 0)
(setq n (min n (1- (car (image-animated-p image))))))) (setq n (min n (1- (car (image-multi-frame-p image)))))))
(plist-put (cdr image) :index n) (plist-put (cdr image) :index n)
(setq image-current-frame n) (setq image-current-frame n)
(force-window-update)) (force-window-update))
;; FIXME? The delay may not be the same for different sub-images, ;; FIXME? The delay may not be the same for different sub-images,
;; hence we need to call image-animated-p to return it. ;; hence we need to call image-multi-frame-p to return it.
;; But it also returns count, so why do we bother passing that as an ;; But it also returns count, so why do we bother passing that as an
;; argument? ;; argument?
(defun image-animate-timeout (image n count time-elapsed limit) (defun image-animate-timeout (image n count time-elapsed limit)
...@@ -695,10 +691,11 @@ The minimum delay between successive frames is `image-minimum-frame-delay'." ...@@ -695,10 +691,11 @@ The minimum delay between successive frames is `image-minimum-frame-delay'."
(image-nth-frame image n t) (image-nth-frame image n t)
(setq n (1+ n)) (setq n (1+ n))
(let* ((time (float-time)) (let* ((time (float-time))
(animation (image-animated-p image)) (animation (image-multi-frame-p image))
;; Subtract off the time we took to load the image from the ;; Subtract off the time we took to load the image from the
;; stated delay time. ;; stated delay time.
(delay (max (+ (cdr animation) time (- (float-time))) (delay (max (+ (or (cdr animation) image-default-frame-delay)
time (- (float-time)))
image-minimum-frame-delay)) image-minimum-frame-delay))
done) done)
(if (>= n count) (if (>= n count)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment