Fix fontification bugs with constructors and const.
[bpt/emacs.git] / lisp / image.el
index 804dc3a..91cc3ad 100644 (file)
@@ -99,6 +99,14 @@ AUTODETECT can be
  - maybe  auto-detect only if the image type is available
            (see `image-type-available-p').")
 
+(defvar image-format-suffixes
+  '((image/x-icon "ico"))
+  "Alist of MIME Content-Type headers to file name suffixes.
+This is used as a hint by the ImageMagick library when detecting
+image types.  If `create-image' is called with a :format
+matching found in this alist, the ImageMagick library will be
+told that the data would have this suffix if saved to a file.")
+
 (defcustom image-load-path
   (list (file-name-as-directory (expand-file-name "images" data-directory))
         'data-directory 'load-path)
@@ -283,6 +291,7 @@ be determined."
          (setq types (cdr types)))))
     (goto-char opoint)
     (and type
+        (boundp 'image-types)
         (memq type image-types)
         type)))
 
@@ -616,13 +625,14 @@ 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))))
+  (when (fboundp 'image-metadata)
+    (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)))))
 
 (defun image-animated-p (image)
   "Like `image-multi-frame-p', but returns nil if no delay is specified."
@@ -679,6 +689,19 @@ do not check N is within the range of frames present in the image."
   (plist-put (cdr image) :index n)
   (force-window-update))
 
+(defun image-animate-get-speed (image)
+  "Return the speed factor for animating IMAGE."
+  (or (plist-get (cdr image) :speed) 1))
+
+(defun image-animate-set-speed (image value &optional multiply)
+  "Set the speed factor for animating IMAGE to VALUE.
+With optional argument MULTIPLY non-nil, treat VALUE as a
+multiplication factor for the current value."
+  (plist-put (cdr image) :speed
+            (if multiply
+                (* value (image-animate-get-speed image))
+              value)))
+
 ;; FIXME? The delay may not be the same for different sub-images,
 ;; 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
@@ -692,21 +715,28 @@ 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 `image-minimum-frame-delay'."
+The minimum delay between successive frames is `image-minimum-frame-delay'.
+
+If the image has a non-nil :speed property, it acts as a multiplier
+for the animation speed.  A negative value means to animate in reverse."
   (image-show-frame image n t)
-  (setq n (1+ n))
-  (let* ((time (float-time))
+  (let* ((speed (image-animate-get-speed image))
+        (time (float-time))
         (animation (image-multi-frame-p image))
         ;; Subtract off the time we took to load the image from the
         ;; stated delay time.
-        (delay (max (+ (or (cdr animation) image-default-frame-delay)
+        (delay (max (+ (* (or (cdr animation) image-default-frame-delay)
+                          (/ 1 (abs speed)))
                        time (- (float-time)))
                     image-minimum-frame-delay))
         done)
-    (if (>= n count)
-       (if limit
-           (setq n 0)
-         (setq done t)))
+    (setq n (if (< speed 0)
+               (1- n)
+             (1+ n)))
+    (if limit
+       (cond ((>= n count) (setq n 0))
+             ((< n 0) (setq n (1- count))))
+      (and (or (>= n count) (< n 0)) (setq done t)))
     (setq time-elapsed (+ delay time-elapsed))
     (if (numberp limit)
        (setq done (>= time-elapsed limit)))