aboutsummaryrefslogtreecommitdiffstats
path: root/lisp/image.el
diff options
context:
space:
mode:
authorGlenn Morris2013-02-16 11:56:50 -0800
committerGlenn Morris2013-02-16 11:56:50 -0800
commited8d7fcaa2965216d44388fd00a757c8d55e7395 (patch)
tree8e04c2457944d8e829c1eacd5eadcf68d0ad0ba6 /lisp/image.el
parent783b7b7551b197fdcfd384ac4a3d93302a073eaf (diff)
downloademacs-ed8d7fcaa2965216d44388fd00a757c8d55e7395.tar.gz
emacs-ed8d7fcaa2965216d44388fd00a757c8d55e7395.zip
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
Diffstat (limited to 'lisp/image.el')
-rw-r--r--lisp/image.el45
1 files changed, 21 insertions, 24 deletions
diff --git a/lisp/image.el b/lisp/image.el
index 22c6bdf4207..b91d136443d 100644
--- a/lisp/image.el
+++ b/lisp/image.el
@@ -606,29 +606,25 @@ Example:
606 606
607;;; Animated image API 607;;; Animated image API
608 608
609(defconst image-animated-types '(gif)
610 "List of supported animated image types.")
611
612(defvar image-default-frame-delay 0.1 609(defvar image-default-frame-delay 0.1
613 "Default interval in seconds between frames of a multi-frame image. 610 "Default interval in seconds between frames of a multi-frame image.
614Only used if the image does not specify a value.") 611Only used if the image does not specify a value.")
615 612
616(defun image-animated-p (image) 613(defun image-multi-frame-p (image)
617 "Return non-nil if IMAGE can be animated. 614 "Return non-nil if IMAGE contains more than one frame.
618To be capable of being animated, an image must be of a type 615The actual return value is a cons (NIMAGES . DELAY), where NIMAGES is
619listed in `image-animated-types', and contain more than one 616the number of frames (or sub-images) in the image and DELAY is the delay
620sub-image, with a specified animation delay. The actual return 617in seconds that the image specifies between each frame. DELAY may be nil,
621value is a cons (NIMAGES . DELAY), where NIMAGES is the number 618in which case you might want to use `image-default-frame-delay'."
622of sub-images in the animated image and DELAY is the delay in 619 (let* ((metadata (image-metadata image))
623seconds until the next sub-image should be displayed." 620 (images (plist-get metadata 'count))
624 (cond 621 (delay (plist-get metadata 'delay)))
625 ((memq (plist-get (cdr image) :type) image-animated-types) 622 (when (and images (> images 1))
626 (let* ((metadata (image-metadata image)) 623 (if (or (not (numberp delay)) (< delay 0))
627 (images (plist-get metadata 'count)) 624 (setq delay image-default-frame-delay))
628 (delay (plist-get metadata 'delay))) 625 (cons images delay))))
629 (when (and images (> images 1) (numberp delay)) 626
630 (if (< delay 0) (setq delay image-default-frame-delay)) 627(define-obsolete-function-alias 'image-animated-p 'image-multi-frame-p "24.4")
631 (cons images delay))))))
632 628
633;; "Destructively"? 629;; "Destructively"?
634(defun image-animate (image &optional index limit) 630(defun image-animate (image &optional index limit)
@@ -639,7 +635,7 @@ With optional INDEX, begin animating from that animation frame.
639LIMIT specifies how long to animate the image. If omitted or 635LIMIT specifies how long to animate the image. If omitted or
640nil, play the animation until the end. If t, loop forever. If a 636nil, play the animation until the end. If t, loop forever. If a
641number, play until that number of seconds has elapsed." 637number, play until that number of seconds has elapsed."
642 (let ((animation (image-animated-p image)) 638 (let ((animation (image-multi-frame-p image))
643 timer) 639 timer)
644 (when animation 640 (when animation
645 (if (setq timer (image-animate-timer image)) 641 (if (setq timer (image-animate-timer image))
@@ -673,13 +669,13 @@ Frames are indexed from 0. Optional argument NOCHECK non-nil means
673do not check N is within the range of frames present in the image." 669do not check N is within the range of frames present in the image."
674 (unless nocheck 670 (unless nocheck
675 (if (< n 0) (setq n 0) 671 (if (< n 0) (setq n 0)
676 (setq n (min n (1- (car (image-animated-p image))))))) 672 (setq n (min n (1- (car (image-multi-frame-p image)))))))
677 (plist-put (cdr image) :index n) 673 (plist-put (cdr image) :index n)
678 (setq image-current-frame n) 674 (setq image-current-frame n)
679 (force-window-update)) 675 (force-window-update))
680 676
681;; FIXME? The delay may not be the same for different sub-images, 677;; FIXME? The delay may not be the same for different sub-images,
682;; hence we need to call image-animated-p to return it. 678;; hence we need to call image-multi-frame-p to return it.
683;; But it also returns count, so why do we bother passing that as an 679;; But it also returns count, so why do we bother passing that as an
684;; argument? 680;; argument?
685(defun image-animate-timeout (image n count time-elapsed limit) 681(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 (image-nth-frame image n t) 691 (image-nth-frame image n t)
696 (setq n (1+ n)) 692 (setq n (1+ n))
697 (let* ((time (float-time)) 693 (let* ((time (float-time))
698 (animation (image-animated-p image)) 694 (animation (image-multi-frame-p image))
699 ;; Subtract off the time we took to load the image from the 695 ;; Subtract off the time we took to load the image from the
700 ;; stated delay time. 696 ;; stated delay time.
701 (delay (max (+ (cdr animation) time (- (float-time))) 697 (delay (max (+ (or (cdr animation) image-default-frame-delay)
698 time (- (float-time)))
702 image-minimum-frame-delay)) 699 image-minimum-frame-delay))
703 done) 700 done)
704 (if (>= n count) 701 (if (>= n count)