]> code.delx.au - gnu-emacs/blobdiff - lisp/image.el
Auto-commit of generated files.
[gnu-emacs] / lisp / image.el
index a47e945c26ab006de7fa075fbbeb69d0d3e4695a..ec7b41bf12660c86d9ce7c680c8a66f4e066a404 100644 (file)
@@ -1,6 +1,6 @@
 ;;; image.el --- image API
 
-;; Copyright (C) 1998-2012 Free Software Foundation, Inc.
+;; Copyright (C) 1998-2013 Free Software Foundation, Inc.
 
 ;; Maintainer: FSF
 ;; Keywords: multimedia
@@ -308,8 +308,14 @@ be determined."
   "Determine the type of image file FILE from its name.
 Value is a symbol specifying the image type, or nil if type cannot
 be determined."
-  (assoc-default file image-type-file-name-regexps 'string-match-p))
-
+  (let (type first)
+    (catch 'found
+      (dolist (elem image-type-file-name-regexps first)
+       (when (string-match-p (car elem) file)
+         (if (image-type-available-p (setq type (cdr elem)))
+             (throw 'found type)
+           ;; If nothing seems to be supported, return first type that matched.
+           (or first (setq first type))))))))
 
 ;;;###autoload
 (defun image-type (source &optional type data-p)
@@ -346,7 +352,7 @@ Optional DATA-P non-nil means SOURCE is a string containing image data."
   "Return non-nil if image type TYPE is available.
 Image types are symbols like `xbm' or `jpeg'."
   (and (fboundp 'init-image-library)
-       (init-image-library type dynamic-library-alist)))
+       (init-image-library type)))
 
 
 ;;;###autoload
@@ -423,7 +429,7 @@ means display it in the right marginal area."
   "Insert IMAGE into current buffer at point.
 IMAGE is displayed by inserting STRING into the current buffer
 with a `display' property whose value is the image.  STRING
-defaults to the empty string if you omit it.
+defaults to a single space if you omit it.
 AREA is where to display the image.  AREA nil or omitted means
 display it in the text area, a value of `left-margin' means
 display it in the left marginal area, a value of `right-margin'
@@ -461,8 +467,8 @@ height of the image; integer values are taken as pixel values."
 (defun insert-sliced-image (image &optional string area rows cols)
   "Insert IMAGE into current buffer at point.
 IMAGE is displayed by inserting STRING into the current buffer
-with a `display' property whose value is the image.  STRING is
-defaulted if you omit it.
+with a `display' property whose value is the image.  The default
+STRING is a single space.
 AREA is where to display the image.  AREA nil or omitted means
 display it in the text area, a value of `left-margin' means
 display it in the left marginal area, a value of `right-margin'
@@ -600,25 +606,25 @@ Example:
 \f
 ;;; Animated image API
 
-(defconst image-animated-types '(gif)
-  "List of supported animated image types.")
-
-(defun image-animated-p (image)
-  "Return non-nil if IMAGE can be animated.
-To be capable of being animated, an image must be of a type
-listed in `image-animated-types', and contain more than one
-sub-image, with a specified animation delay.  The actual return
-value is a cons (NIMAGES . DELAY), where NIMAGES is the number
-of sub-images in the animated image and DELAY is the delay in
-seconds until the next sub-image should be displayed."
-  (cond
-   ((memq (plist-get (cdr image) :type) image-animated-types)
-    (let* ((metadata (image-metadata image))
-          (images (plist-get metadata 'count))
-          (delay (plist-get metadata 'delay)))
-      (when (and images (> images 1) (numberp delay))
-       (if (< delay 0) (setq delay 0.1))
-       (cons images delay))))))
+(defvar image-default-frame-delay 0.1
+  "Default interval in seconds between frames of a multi-frame image.
+Only used if the image does not specify a value.")
+
+(defun image-multi-frame-p (image)
+  "Return non-nil if IMAGE contains more than one frame.
+The actual return value is a cons (NIMAGES . DELAY), where NIMAGES is
+the number of frames (or sub-images) in the image and DELAY is the delay
+in seconds that the image specifies between each frame.  DELAY may be nil,
+in which case you might want to use `image-default-frame-delay'."
+  (let* ((metadata (image-metadata image))
+        (images (plist-get metadata 'count))
+        (delay (plist-get metadata 'delay)))
+    (when (and images (> images 1))
+      (if (or (not (numberp delay)) (< delay 0))
+         (setq delay image-default-frame-delay))
+      (cons images delay))))
+
+(define-obsolete-function-alias 'image-animated-p 'image-multi-frame-p "24.4")
 
 ;; "Destructively"?
 (defun image-animate (image &optional index limit)
@@ -629,7 +635,7 @@ With optional INDEX, begin animating from that animation frame.
 LIMIT specifies how long to animate the image.  If omitted or
 nil, play the animation until the end.  If t, loop forever.  If a
 number, play until that number of seconds has elapsed."
-  (let ((animation (image-animated-p image))
+  (let ((animation (image-multi-frame-p image))
        timer)
     (when animation
       (if (setq timer (image-animate-timer image))
@@ -645,14 +651,31 @@ number, play until that number of seconds has elapsed."
     (while tail
       (setq timer (car tail)
            tail (cdr tail))
-      (if (and (eq (aref timer 5) 'image-animate-timeout)
-              (eq (car-safe (aref timer 6)) image))
+      (if (and (eq (timer--function timer) 'image-animate-timeout)
+              (eq (car-safe (timer--args timer)) image))
          (setq tail nil)
        (setq timer nil)))
     timer))
 
+(defconst image-minimum-frame-delay 0.01
+  "Minimum interval in seconds between frames of an animated image.")
+
+(defun image-current-frame (image)
+  "The current frame number of IMAGE, indexed from 0."
+  (or (plist-get (cdr image) :index) 0))
+
+(defun image-show-frame (image n &optional nocheck)
+  "Show frame N of IMAGE.
+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."
+  (unless nocheck
+    (if (< n 0) (setq n 0)
+      (setq n (min n (1- (car (image-multi-frame-p image)))))))
+  (plist-put (cdr image) :index n)
+  (force-window-update))
+
 ;; 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
 ;; argument?
 (defun image-animate-timeout (image n count time-elapsed limit)
@@ -664,16 +687,16 @@ TIME-ELAPSED is the total time that has elapsed since
 LIMIT determines when to stop.  If t, loop forever.  If nil, stop
  after displaying the last animation frame.  Otherwise, stop
  after LIMIT seconds have elapsed.
-The minimum delay between successive frames is 0.01s."
-  (plist-put (cdr image) :index n)
-  (force-window-update)
+The minimum delay between successive frames is `image-minimum-frame-delay'."
+  (image-show-frame image n t)
   (setq n (1+ n))
   (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
         ;; stated delay time.
-        (delay (max (+ (cdr animation) time (- (float-time)))
-                    0.01))
+        (delay (max (+ (or (cdr animation) image-default-frame-delay)
+                       time (- (float-time)))
+                    image-minimum-frame-delay))
         done)
     (if (>= n count)
        (if limit
@@ -747,7 +770,10 @@ If Emacs is compiled without ImageMagick support, this does nothing."
          (push (cons re 'image-mode) auto-mode-alist))
        (if itfnr-elt
            (setcar itfnr-elt re)
-         (push (cons re 'imagemagick) image-type-file-name-regexps)))
+         ;; Append to `image-type-file-name-regexps', so that we
+         ;; preferentially use specialized image libraries.
+         (add-to-list 'image-type-file-name-regexps
+                      (cons re 'imagemagick) t)))
       (setq imagemagick--file-regexp re))))
 
 (defcustom imagemagick-types-inhibit
@@ -771,7 +797,7 @@ has no effect."
   :set (lambda (symbol value)
         (set-default symbol value)
         (imagemagick-register-types))
-  :version "24.2"
+  :version "24.3"
   :group 'image)
 
 (defcustom imagemagick-enabled-types
@@ -795,7 +821,7 @@ to enable all types that ImageMagick supports.
 
 The variable `imagemagick-types-inhibit' overrides this variable.
 
-If you change this without outside of Customize, you must call
+If you change this without using customize, you must call
 `imagemagick-register-types' afterwards.
 
 If Emacs is compiled without ImageMagick support, this variable
@@ -809,7 +835,7 @@ has no effect."
   :set (lambda (symbol value)
         (set-default symbol value)
         (imagemagick-register-types))
-  :version "24.2"
+  :version "24.3"
   :group 'image)
 
 (imagemagick-register-types)