annotate lisp/image.el @ 112334:7e12e8b5864c

Merge from mainline.
author Paul Eggert <eggert@cs.ucla.edu>
date Mon, 17 Jan 2011 11:47:38 -0800
parents 61f7601898b1
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
25003
bb68fe3c72f8 New file.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1 ;;; image.el --- image API
bb68fe3c72f8 New file.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
2
112284
61f7601898b1 Refill some copyright headers.
Glenn Morris <rgm@gnu.org>
parents: 112278
diff changeset
3 ;; Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006,
61f7601898b1 Refill some copyright headers.
Glenn Morris <rgm@gnu.org>
parents: 112278
diff changeset
4 ;; 2007, 2008, 2009, 2010, 2011 Free Software Foundation, Inc.
42316
b1023d722287 Add Maintainer header.
Pavel Janík <Pavel@Janik.cz>
parents: 38884
diff changeset
5
b1023d722287 Add Maintainer header.
Pavel Janík <Pavel@Janik.cz>
parents: 38884
diff changeset
6 ;; Maintainer: FSF
25309
6842eb73559c Add Keywords.
Dave Love <fx@gnu.org>
parents: 25003
diff changeset
7 ;; Keywords: multimedia
110015
280c8ae2476d Add "Package:" file headers to denote built-in packages.
Chong Yidong <cyd@stupidchicken.com>
parents: 109874
diff changeset
8 ;; Package: emacs
25003
bb68fe3c72f8 New file.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
9
bb68fe3c72f8 New file.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
10 ;; This file is part of GNU Emacs.
bb68fe3c72f8 New file.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
11
94678
ee5932bf781d Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents: 87649
diff changeset
12 ;; GNU Emacs is free software: you can redistribute it and/or modify
25003
bb68fe3c72f8 New file.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
13 ;; it under the terms of the GNU General Public License as published by
94678
ee5932bf781d Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents: 87649
diff changeset
14 ;; the Free Software Foundation, either version 3 of the License, or
ee5932bf781d Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents: 87649
diff changeset
15 ;; (at your option) any later version.
25003
bb68fe3c72f8 New file.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
16
bb68fe3c72f8 New file.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
17 ;; GNU Emacs is distributed in the hope that it will be useful,
bb68fe3c72f8 New file.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
18 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
bb68fe3c72f8 New file.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
bb68fe3c72f8 New file.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
20 ;; GNU General Public License for more details.
bb68fe3c72f8 New file.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
21
bb68fe3c72f8 New file.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
22 ;; You should have received a copy of the GNU General Public License
94678
ee5932bf781d Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents: 87649
diff changeset
23 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
25003
bb68fe3c72f8 New file.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
24
bb68fe3c72f8 New file.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
25 ;;; Commentary:
bb68fe3c72f8 New file.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
26
bb68fe3c72f8 New file.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
27 ;;; Code:
bb68fe3c72f8 New file.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
28
32166
e3be69cf6c81 (image): New group.
Miles Bader <miles@gnu.org>
parents: 31635
diff changeset
29
e3be69cf6c81 (image): New group.
Miles Bader <miles@gnu.org>
parents: 31635
diff changeset
30 (defgroup image ()
e3be69cf6c81 (image): New group.
Miles Bader <miles@gnu.org>
parents: 31635
diff changeset
31 "Image support."
e3be69cf6c81 (image): New group.
Miles Bader <miles@gnu.org>
parents: 31635
diff changeset
32 :group 'multimedia)
e3be69cf6c81 (image): New group.
Miles Bader <miles@gnu.org>
parents: 31635
diff changeset
33
108746
24d486687f54 Rename image-refresh to image-flush.
Chong Yidong <cyd@stupidchicken.com>
parents: 107719
diff changeset
34 (defalias 'image-refresh 'image-flush)
32166
e3be69cf6c81 (image): New group.
Miles Bader <miles@gnu.org>
parents: 31635
diff changeset
35
66296
941b6508462f (image-type-header-regexps): Rename from image-type-regexps.
Kim F. Storm <storm@cua.dk>
parents: 66196
diff changeset
36 (defconst image-type-header-regexps
82835
de6e597c221b (image-type-header-regexps): Use more complex regexp for svg.
Juri Linkov <juri@jurta.org>
parents: 82734
diff changeset
37 `(("\\`/[\t\n\r ]*\\*.*XPM.\\*/" . xpm)
74972
94afc7cac404 (image-type-header-regexps, image-type-from-data, image-type-from-buffer,
Juanma Barranquero <lekktu@gmail.com>
parents: 74916
diff changeset
38 ("\\`P[1-6][[:space:]]+\\(?:#.*[[:space:]]+\\)*[0-9]+[[:space:]]+[0-9]+" . pbm)
75472
ad8f4e060e53 (image-type-header-regexps): Make GIF regex more specific.
Richard M. Stallman <rms@gnu.org>
parents: 75347
diff changeset
39 ("\\`GIF8[79]a" . gif)
74972
94afc7cac404 (image-type-header-regexps, image-type-from-data, image-type-from-buffer,
Juanma Barranquero <lekktu@gmail.com>
parents: 74916
diff changeset
40 ("\\`\x89PNG\r\n\x1a\n" . png)
99876
e8248a7b666d (image-type-header-regexps): Recognize more xbm format
Andreas Schwab <schwab@suse.de>
parents: 96380
diff changeset
41 ("\\`[\t\n\r ]*#define \\([a-z0-9_]+\\)_width [0-9]+\n\
e8248a7b666d (image-type-header-regexps): Recognize more xbm format
Andreas Schwab <schwab@suse.de>
parents: 96380
diff changeset
42 #define \\1_height [0-9]+\n\\(\
e8248a7b666d (image-type-header-regexps): Recognize more xbm format
Andreas Schwab <schwab@suse.de>
parents: 96380
diff changeset
43 #define \\1_x_hot [0-9]+\n\
e8248a7b666d (image-type-header-regexps): Recognize more xbm format
Andreas Schwab <schwab@suse.de>
parents: 96380
diff changeset
44 #define \\1_y_hot [0-9]+\n\\)?\
e8248a7b666d (image-type-header-regexps): Recognize more xbm format
Andreas Schwab <schwab@suse.de>
parents: 96380
diff changeset
45 static \\(unsigned \\)?char \\1_bits" . xbm)
74972
94afc7cac404 (image-type-header-regexps, image-type-from-data, image-type-from-buffer,
Juanma Barranquero <lekktu@gmail.com>
parents: 74916
diff changeset
46 ("\\`\\(?:MM\0\\*\\|II\\*\0\\)" . tiff)
94afc7cac404 (image-type-header-regexps, image-type-from-data, image-type-from-buffer,
Juanma Barranquero <lekktu@gmail.com>
parents: 74916
diff changeset
47 ("\\`[\t\n\r ]*%!PS" . postscript)
104690
d3d94e331386 (image-type-header-regexps): Use only JPEG magic number
Juri Linkov <juri@jurta.org>
parents: 102236
diff changeset
48 ("\\`\xff\xd8" . jpeg) ; used to be (image-jpeg-p . jpeg)
82835
de6e597c221b (image-type-header-regexps): Use more complex regexp for svg.
Juri Linkov <juri@jurta.org>
parents: 82734
diff changeset
49 (,(let* ((incomment-re "\\(?:[^-]\\|-[^-]\\)")
de6e597c221b (image-type-header-regexps): Use more complex regexp for svg.
Juri Linkov <juri@jurta.org>
parents: 82734
diff changeset
50 (comment-re (concat "\\(?:!--" incomment-re "*-->[ \t\r\n]*<\\)")))
de6e597c221b (image-type-header-regexps): Use more complex regexp for svg.
Juri Linkov <juri@jurta.org>
parents: 82734
diff changeset
51 (concat "\\(?:<\\?xml[ \t\r\n]+[^>]*>\\)?[ \t\r\n]*<"
de6e597c221b (image-type-header-regexps): Use more complex regexp for svg.
Juri Linkov <juri@jurta.org>
parents: 82734
diff changeset
52 comment-re "*"
de6e597c221b (image-type-header-regexps): Use more complex regexp for svg.
Juri Linkov <juri@jurta.org>
parents: 82734
diff changeset
53 "\\(?:!DOCTYPE[ \t\r\n]+[^>]*>[ \t\r\n]*<[ \t\r\n]*" comment-re "*\\)?"
de6e597c221b (image-type-header-regexps): Use more complex regexp for svg.
Juri Linkov <juri@jurta.org>
parents: 82734
diff changeset
54 "[Ss][Vv][Gg]"))
de6e597c221b (image-type-header-regexps): Use more complex regexp for svg.
Juri Linkov <juri@jurta.org>
parents: 82734
diff changeset
55 . svg)
de6e597c221b (image-type-header-regexps): Use more complex regexp for svg.
Juri Linkov <juri@jurta.org>
parents: 82734
diff changeset
56 )
74972
94afc7cac404 (image-type-header-regexps, image-type-from-data, image-type-from-buffer,
Juanma Barranquero <lekktu@gmail.com>
parents: 74916
diff changeset
57 "Alist of (REGEXP . IMAGE-TYPE) pairs used to auto-detect image types.
25003
bb68fe3c72f8 New file.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
58 When the first bytes of an image file match REGEXP, it is assumed to
74972
94afc7cac404 (image-type-header-regexps, image-type-from-data, image-type-from-buffer,
Juanma Barranquero <lekktu@gmail.com>
parents: 74916
diff changeset
59 be of image type IMAGE-TYPE if IMAGE-TYPE is a symbol. If not a symbol,
94afc7cac404 (image-type-header-regexps, image-type-from-data, image-type-from-buffer,
Juanma Barranquero <lekktu@gmail.com>
parents: 74916
diff changeset
60 IMAGE-TYPE must be a pair (PREDICATE . TYPE). PREDICATE is called
94afc7cac404 (image-type-header-regexps, image-type-from-data, image-type-from-buffer,
Juanma Barranquero <lekktu@gmail.com>
parents: 74916
diff changeset
61 with one argument, a string containing the image data. If PREDICATE returns
94afc7cac404 (image-type-header-regexps, image-type-from-data, image-type-from-buffer,
Juanma Barranquero <lekktu@gmail.com>
parents: 74916
diff changeset
62 a non-nil value, TYPE is the image's type.")
38732
24fe4f884e82 (image-type-regexps): Allow predicates. Change the way
Gerd Moellmann <gerd@gnu.org>
parents: 38711
diff changeset
63
66296
941b6508462f (image-type-header-regexps): Rename from image-type-regexps.
Kim F. Storm <storm@cua.dk>
parents: 66196
diff changeset
64 (defconst image-type-file-name-regexps
941b6508462f (image-type-header-regexps): Rename from image-type-regexps.
Kim F. Storm <storm@cua.dk>
parents: 66196
diff changeset
65 '(("\\.png\\'" . png)
941b6508462f (image-type-header-regexps): Rename from image-type-regexps.
Kim F. Storm <storm@cua.dk>
parents: 66196
diff changeset
66 ("\\.gif\\'" . gif)
941b6508462f (image-type-header-regexps): Rename from image-type-regexps.
Kim F. Storm <storm@cua.dk>
parents: 66196
diff changeset
67 ("\\.jpe?g\\'" . jpeg)
941b6508462f (image-type-header-regexps): Rename from image-type-regexps.
Kim F. Storm <storm@cua.dk>
parents: 66196
diff changeset
68 ("\\.bmp\\'" . bmp)
941b6508462f (image-type-header-regexps): Rename from image-type-regexps.
Kim F. Storm <storm@cua.dk>
parents: 66196
diff changeset
69 ("\\.xpm\\'" . xpm)
941b6508462f (image-type-header-regexps): Rename from image-type-regexps.
Kim F. Storm <storm@cua.dk>
parents: 66196
diff changeset
70 ("\\.pbm\\'" . pbm)
941b6508462f (image-type-header-regexps): Rename from image-type-regexps.
Kim F. Storm <storm@cua.dk>
parents: 66196
diff changeset
71 ("\\.xbm\\'" . xbm)
941b6508462f (image-type-header-regexps): Rename from image-type-regexps.
Kim F. Storm <storm@cua.dk>
parents: 66196
diff changeset
72 ("\\.ps\\'" . postscript)
82835
de6e597c221b (image-type-header-regexps): Use more complex regexp for svg.
Juri Linkov <juri@jurta.org>
parents: 82734
diff changeset
73 ("\\.tiff?\\'" . tiff)
de6e597c221b (image-type-header-regexps): Use more complex regexp for svg.
Juri Linkov <juri@jurta.org>
parents: 82734
diff changeset
74 ("\\.svgz?\\'" . svg)
de6e597c221b (image-type-header-regexps): Use more complex regexp for svg.
Juri Linkov <juri@jurta.org>
parents: 82734
diff changeset
75 )
66296
941b6508462f (image-type-header-regexps): Rename from image-type-regexps.
Kim F. Storm <storm@cua.dk>
parents: 66196
diff changeset
76 "Alist of (REGEXP . IMAGE-TYPE) pairs used to identify image files.
941b6508462f (image-type-header-regexps): Rename from image-type-regexps.
Kim F. Storm <storm@cua.dk>
parents: 66196
diff changeset
77 When the name of an image file match REGEXP, it is assumed to
941b6508462f (image-type-header-regexps): Rename from image-type-regexps.
Kim F. Storm <storm@cua.dk>
parents: 66196
diff changeset
78 be of image type IMAGE-TYPE.")
941b6508462f (image-type-header-regexps): Rename from image-type-regexps.
Kim F. Storm <storm@cua.dk>
parents: 66196
diff changeset
79
75744
53fa6ea37e3a (image-type-auto-detectable): Don't autodetect x[pb]m.
Chong Yidong <cyd@stupidchicken.com>
parents: 75472
diff changeset
80 ;; We rely on `auto-mode-alist' to detect xbm and xpm files, instead
53fa6ea37e3a (image-type-auto-detectable): Don't autodetect x[pb]m.
Chong Yidong <cyd@stupidchicken.com>
parents: 75472
diff changeset
81 ;; of content autodetection. Their contents are just C code, so it is
53fa6ea37e3a (image-type-auto-detectable): Don't autodetect x[pb]m.
Chong Yidong <cyd@stupidchicken.com>
parents: 75472
diff changeset
82 ;; easy to generate false matches.
74972
94afc7cac404 (image-type-header-regexps, image-type-from-data, image-type-from-buffer,
Juanma Barranquero <lekktu@gmail.com>
parents: 74916
diff changeset
83 (defvar image-type-auto-detectable
94afc7cac404 (image-type-header-regexps, image-type-from-data, image-type-from-buffer,
Juanma Barranquero <lekktu@gmail.com>
parents: 74916
diff changeset
84 '((pbm . t)
75744
53fa6ea37e3a (image-type-auto-detectable): Don't autodetect x[pb]m.
Chong Yidong <cyd@stupidchicken.com>
parents: 75472
diff changeset
85 (xbm . nil)
74972
94afc7cac404 (image-type-header-regexps, image-type-from-data, image-type-from-buffer,
Juanma Barranquero <lekktu@gmail.com>
parents: 74916
diff changeset
86 (bmp . maybe)
94afc7cac404 (image-type-header-regexps, image-type-from-data, image-type-from-buffer,
Juanma Barranquero <lekktu@gmail.com>
parents: 74916
diff changeset
87 (gif . maybe)
94afc7cac404 (image-type-header-regexps, image-type-from-data, image-type-from-buffer,
Juanma Barranquero <lekktu@gmail.com>
parents: 74916
diff changeset
88 (png . maybe)
75744
53fa6ea37e3a (image-type-auto-detectable): Don't autodetect x[pb]m.
Chong Yidong <cyd@stupidchicken.com>
parents: 75472
diff changeset
89 (xpm . nil)
74972
94afc7cac404 (image-type-header-regexps, image-type-from-data, image-type-from-buffer,
Juanma Barranquero <lekktu@gmail.com>
parents: 74916
diff changeset
90 (jpeg . maybe)
94afc7cac404 (image-type-header-regexps, image-type-from-data, image-type-from-buffer,
Juanma Barranquero <lekktu@gmail.com>
parents: 74916
diff changeset
91 (tiff . maybe)
82835
de6e597c221b (image-type-header-regexps): Use more complex regexp for svg.
Juri Linkov <juri@jurta.org>
parents: 82734
diff changeset
92 (svg . maybe)
74972
94afc7cac404 (image-type-header-regexps, image-type-from-data, image-type-from-buffer,
Juanma Barranquero <lekktu@gmail.com>
parents: 74916
diff changeset
93 (postscript . nil))
94afc7cac404 (image-type-header-regexps, image-type-from-data, image-type-from-buffer,
Juanma Barranquero <lekktu@gmail.com>
parents: 74916
diff changeset
94 "Alist of (IMAGE-TYPE . AUTODETECT) pairs used to auto-detect image files.
94afc7cac404 (image-type-header-regexps, image-type-from-data, image-type-from-buffer,
Juanma Barranquero <lekktu@gmail.com>
parents: 74916
diff changeset
95 \(See `image-type-auto-detected-p').
94afc7cac404 (image-type-header-regexps, image-type-from-data, image-type-from-buffer,
Juanma Barranquero <lekktu@gmail.com>
parents: 74916
diff changeset
96
94afc7cac404 (image-type-header-regexps, image-type-from-data, image-type-from-buffer,
Juanma Barranquero <lekktu@gmail.com>
parents: 74916
diff changeset
97 AUTODETECT can be
94afc7cac404 (image-type-header-regexps, image-type-from-data, image-type-from-buffer,
Juanma Barranquero <lekktu@gmail.com>
parents: 74916
diff changeset
98 - t always auto-detect.
94afc7cac404 (image-type-header-regexps, image-type-from-data, image-type-from-buffer,
Juanma Barranquero <lekktu@gmail.com>
parents: 74916
diff changeset
99 - nil never auto-detect.
94afc7cac404 (image-type-header-regexps, image-type-from-data, image-type-from-buffer,
Juanma Barranquero <lekktu@gmail.com>
parents: 74916
diff changeset
100 - maybe auto-detect only if the image type is available
94afc7cac404 (image-type-header-regexps, image-type-from-data, image-type-from-buffer,
Juanma Barranquero <lekktu@gmail.com>
parents: 74916
diff changeset
101 (see `image-type-available-p').")
66296
941b6508462f (image-type-header-regexps): Rename from image-type-regexps.
Kim F. Storm <storm@cua.dk>
parents: 66196
diff changeset
102
104978
a4c2188bd87d * startup.el (tutorial-directory): Make it a defcustom.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 104690
diff changeset
103 (defcustom image-load-path
a4c2188bd87d * startup.el (tutorial-directory): Make it a defcustom.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 104690
diff changeset
104 (list (file-name-as-directory (expand-file-name "images" data-directory))
a4c2188bd87d * startup.el (tutorial-directory): Make it a defcustom.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 104690
diff changeset
105 'data-directory 'load-path)
65544
78d74ef1436b 2005-09-15 Chong Yidong <cyd@stupidchicken.com>
Chong Yidong <cyd@stupidchicken.com>
parents: 64762
diff changeset
106 "List of locations in which to search for image files.
65599
39114a2ae201 (image-load-path): Use symbol `data-directory' instead of its value,
Chong Yidong <cyd@stupidchicken.com>
parents: 65544
diff changeset
107 If an element is a string, it defines a directory to search.
39114a2ae201 (image-load-path): Use symbol `data-directory' instead of its value,
Chong Yidong <cyd@stupidchicken.com>
parents: 65544
diff changeset
108 If an element is a variable symbol whose value is a string, that
39114a2ae201 (image-load-path): Use symbol `data-directory' instead of its value,
Chong Yidong <cyd@stupidchicken.com>
parents: 65544
diff changeset
109 value defines a directory to search.
39114a2ae201 (image-load-path): Use symbol `data-directory' instead of its value,
Chong Yidong <cyd@stupidchicken.com>
parents: 65544
diff changeset
110 If an element is a variable symbol whose value is a list, the
104978
a4c2188bd87d * startup.el (tutorial-directory): Make it a defcustom.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 104690
diff changeset
111 value is used as a list of directories to search."
a4c2188bd87d * startup.el (tutorial-directory): Make it a defcustom.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 104690
diff changeset
112 :type '(repeat (choice directory variable))
a4c2188bd87d * startup.el (tutorial-directory): Make it a defcustom.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 104690
diff changeset
113 :initialize 'custom-initialize-delay)
66307
ca953a3dbdf1 (image-load-path): Use eval-at-startup to initialize.
Richard M. Stallman <rms@gnu.org>
parents: 66296
diff changeset
114
69471
6f07bf99b6f8 (image-load-path-for-library): Pass value of path rather than symbol.
Bill Wohler <wohler@newt.com>
parents: 69365
diff changeset
115
69365
0a2d89023fde (image-load-path-for-library): Merged changes from Reiner. Add
Bill Wohler <wohler@newt.com>
parents: 69360
diff changeset
116 (defun image-load-path-for-library (library image &optional path no-error)
69569
dd7f85a6af09 (image-load-path-for-library): Shorten first line in docstring.
Bill Wohler <wohler@newt.com>
parents: 69535
diff changeset
117 "Return a suitable search path for images used by LIBRARY.
69360
e5e4303f8050 (image-load-path-for-library): Merge at least three functions from
Bill Wohler <wohler@newt.com>
parents: 68651
diff changeset
118
69535
3feef8dfbff5 (image-load-path-for-library): Minor docstring fix.
Bill Wohler <wohler@newt.com>
parents: 69516
diff changeset
119 It searches for IMAGE in `image-load-path' (excluding
69516
e419733d5cf6 (image-load-path-for-library): Prefer user's images in
Bill Wohler <wohler@newt.com>
parents: 69493
diff changeset
120 \"`data-directory'/images\") and `load-path', followed by a path
e419733d5cf6 (image-load-path-for-library): Prefer user's images in
Bill Wohler <wohler@newt.com>
parents: 69493
diff changeset
121 suitable for LIBRARY, which includes \"../../etc/images\" and
e419733d5cf6 (image-load-path-for-library): Prefer user's images in
Bill Wohler <wohler@newt.com>
parents: 69493
diff changeset
122 \"../etc/images\" relative to the library file itself, and then
e419733d5cf6 (image-load-path-for-library): Prefer user's images in
Bill Wohler <wohler@newt.com>
parents: 69493
diff changeset
123 in \"`data-directory'/images\".
69360
e5e4303f8050 (image-load-path-for-library): Merge at least three functions from
Bill Wohler <wohler@newt.com>
parents: 68651
diff changeset
124
69471
6f07bf99b6f8 (image-load-path-for-library): Pass value of path rather than symbol.
Bill Wohler <wohler@newt.com>
parents: 69365
diff changeset
125 Then this function returns a list of directories which contains
6f07bf99b6f8 (image-load-path-for-library): Pass value of path rather than symbol.
Bill Wohler <wohler@newt.com>
parents: 69365
diff changeset
126 first the directory in which IMAGE was found, followed by the
102236
eeef2e7e9171 * image.el (image-load-path-for-library, insert-sliced-image):
Juanma Barranquero <lekktu@gmail.com>
parents: 100908
diff changeset
127 value of `load-path'. If PATH is given, it is used instead of
69471
6f07bf99b6f8 (image-load-path-for-library): Pass value of path rather than symbol.
Bill Wohler <wohler@newt.com>
parents: 69365
diff changeset
128 `load-path'.
69365
0a2d89023fde (image-load-path-for-library): Merged changes from Reiner. Add
Bill Wohler <wohler@newt.com>
parents: 69360
diff changeset
129
69471
6f07bf99b6f8 (image-load-path-for-library): Pass value of path rather than symbol.
Bill Wohler <wohler@newt.com>
parents: 69365
diff changeset
130 If NO-ERROR is non-nil and a suitable path can't be found, don't
102236
eeef2e7e9171 * image.el (image-load-path-for-library, insert-sliced-image):
Juanma Barranquero <lekktu@gmail.com>
parents: 100908
diff changeset
131 signal an error. Instead, return a list of directories as before,
69471
6f07bf99b6f8 (image-load-path-for-library): Pass value of path rather than symbol.
Bill Wohler <wohler@newt.com>
parents: 69365
diff changeset
132 except that nil appears in place of the image directory.
69360
e5e4303f8050 (image-load-path-for-library): Merge at least three functions from
Bill Wohler <wohler@newt.com>
parents: 68651
diff changeset
133
e5e4303f8050 (image-load-path-for-library): Merge at least three functions from
Bill Wohler <wohler@newt.com>
parents: 68651
diff changeset
134 Here is an example that uses a common idiom to provide
e5e4303f8050 (image-load-path-for-library): Merge at least three functions from
Bill Wohler <wohler@newt.com>
parents: 68651
diff changeset
135 compatibility with versions of Emacs that lack the variable
e5e4303f8050 (image-load-path-for-library): Merge at least three functions from
Bill Wohler <wohler@newt.com>
parents: 68651
diff changeset
136 `image-load-path':
e5e4303f8050 (image-load-path-for-library): Merge at least three functions from
Bill Wohler <wohler@newt.com>
parents: 68651
diff changeset
137
69493
4f9233243d97 (image-load-path-for-library): Fix example by not recommending that
Bill Wohler <wohler@newt.com>
parents: 69471
diff changeset
138 ;; Shush compiler.
4f9233243d97 (image-load-path-for-library): Fix example by not recommending that
Bill Wohler <wohler@newt.com>
parents: 69471
diff changeset
139 (defvar image-load-path)
69471
6f07bf99b6f8 (image-load-path-for-library): Pass value of path rather than symbol.
Bill Wohler <wohler@newt.com>
parents: 69365
diff changeset
140
6f07bf99b6f8 (image-load-path-for-library): Pass value of path rather than symbol.
Bill Wohler <wohler@newt.com>
parents: 69365
diff changeset
141 (let* ((load-path (image-load-path-for-library \"mh-e\" \"mh-logo.xpm\"))
69493
4f9233243d97 (image-load-path-for-library): Fix example by not recommending that
Bill Wohler <wohler@newt.com>
parents: 69471
diff changeset
142 (image-load-path (cons (car load-path)
4f9233243d97 (image-load-path-for-library): Fix example by not recommending that
Bill Wohler <wohler@newt.com>
parents: 69471
diff changeset
143 (when (boundp 'image-load-path)
4f9233243d97 (image-load-path-for-library): Fix example by not recommending that
Bill Wohler <wohler@newt.com>
parents: 69471
diff changeset
144 image-load-path))))
69471
6f07bf99b6f8 (image-load-path-for-library): Pass value of path rather than symbol.
Bill Wohler <wohler@newt.com>
parents: 69365
diff changeset
145 (mh-tool-bar-folder-buttons-init))"
69360
e5e4303f8050 (image-load-path-for-library): Merge at least three functions from
Bill Wohler <wohler@newt.com>
parents: 68651
diff changeset
146 (unless library (error "No library specified"))
e5e4303f8050 (image-load-path-for-library): Merge at least three functions from
Bill Wohler <wohler@newt.com>
parents: 68651
diff changeset
147 (unless image (error "No image specified"))
69516
e419733d5cf6 (image-load-path-for-library): Prefer user's images in
Bill Wohler <wohler@newt.com>
parents: 69493
diff changeset
148 (let (image-directory image-directory-load-path)
e419733d5cf6 (image-load-path-for-library): Prefer user's images in
Bill Wohler <wohler@newt.com>
parents: 69493
diff changeset
149 ;; Check for images in image-load-path or load-path.
e419733d5cf6 (image-load-path-for-library): Prefer user's images in
Bill Wohler <wohler@newt.com>
parents: 69493
diff changeset
150 (let ((img image)
e419733d5cf6 (image-load-path-for-library): Prefer user's images in
Bill Wohler <wohler@newt.com>
parents: 69493
diff changeset
151 (dir (or
e419733d5cf6 (image-load-path-for-library): Prefer user's images in
Bill Wohler <wohler@newt.com>
parents: 69493
diff changeset
152 ;; Images in image-load-path.
e419733d5cf6 (image-load-path-for-library): Prefer user's images in
Bill Wohler <wohler@newt.com>
parents: 69493
diff changeset
153 (image-search-load-path image)
e419733d5cf6 (image-load-path-for-library): Prefer user's images in
Bill Wohler <wohler@newt.com>
parents: 69493
diff changeset
154 ;; Images in load-path.
e419733d5cf6 (image-load-path-for-library): Prefer user's images in
Bill Wohler <wohler@newt.com>
parents: 69493
diff changeset
155 (locate-library image)))
e419733d5cf6 (image-load-path-for-library): Prefer user's images in
Bill Wohler <wohler@newt.com>
parents: 69493
diff changeset
156 parent)
e419733d5cf6 (image-load-path-for-library): Prefer user's images in
Bill Wohler <wohler@newt.com>
parents: 69493
diff changeset
157 ;; Since the image might be in a nested directory (for
e419733d5cf6 (image-load-path-for-library): Prefer user's images in
Bill Wohler <wohler@newt.com>
parents: 69493
diff changeset
158 ;; example, mail/attach.pbm), adjust `image-directory'
e419733d5cf6 (image-load-path-for-library): Prefer user's images in
Bill Wohler <wohler@newt.com>
parents: 69493
diff changeset
159 ;; accordingly.
e419733d5cf6 (image-load-path-for-library): Prefer user's images in
Bill Wohler <wohler@newt.com>
parents: 69493
diff changeset
160 (when dir
e419733d5cf6 (image-load-path-for-library): Prefer user's images in
Bill Wohler <wohler@newt.com>
parents: 69493
diff changeset
161 (setq dir (file-name-directory dir))
e419733d5cf6 (image-load-path-for-library): Prefer user's images in
Bill Wohler <wohler@newt.com>
parents: 69493
diff changeset
162 (while (setq parent (file-name-directory img))
e419733d5cf6 (image-load-path-for-library): Prefer user's images in
Bill Wohler <wohler@newt.com>
parents: 69493
diff changeset
163 (setq img (directory-file-name parent)
e419733d5cf6 (image-load-path-for-library): Prefer user's images in
Bill Wohler <wohler@newt.com>
parents: 69493
diff changeset
164 dir (expand-file-name "../" dir))))
e419733d5cf6 (image-load-path-for-library): Prefer user's images in
Bill Wohler <wohler@newt.com>
parents: 69493
diff changeset
165 (setq image-directory-load-path dir))
e419733d5cf6 (image-load-path-for-library): Prefer user's images in
Bill Wohler <wohler@newt.com>
parents: 69493
diff changeset
166
e419733d5cf6 (image-load-path-for-library): Prefer user's images in
Bill Wohler <wohler@newt.com>
parents: 69493
diff changeset
167 ;; If `image-directory-load-path' isn't Emacs' image directory,
e419733d5cf6 (image-load-path-for-library): Prefer user's images in
Bill Wohler <wohler@newt.com>
parents: 69493
diff changeset
168 ;; it's probably a user preference, so use it. Then use a
e419733d5cf6 (image-load-path-for-library): Prefer user's images in
Bill Wohler <wohler@newt.com>
parents: 69493
diff changeset
169 ;; relative setting if possible; otherwise, use
e419733d5cf6 (image-load-path-for-library): Prefer user's images in
Bill Wohler <wohler@newt.com>
parents: 69493
diff changeset
170 ;; `image-directory-load-path'.
69360
e5e4303f8050 (image-load-path-for-library): Merge at least three functions from
Bill Wohler <wohler@newt.com>
parents: 68651
diff changeset
171 (cond
69516
e419733d5cf6 (image-load-path-for-library): Prefer user's images in
Bill Wohler <wohler@newt.com>
parents: 69493
diff changeset
172 ;; User-modified image-load-path?
e419733d5cf6 (image-load-path-for-library): Prefer user's images in
Bill Wohler <wohler@newt.com>
parents: 69493
diff changeset
173 ((and image-directory-load-path
e419733d5cf6 (image-load-path-for-library): Prefer user's images in
Bill Wohler <wohler@newt.com>
parents: 69493
diff changeset
174 (not (equal image-directory-load-path
e419733d5cf6 (image-load-path-for-library): Prefer user's images in
Bill Wohler <wohler@newt.com>
parents: 69493
diff changeset
175 (file-name-as-directory
e419733d5cf6 (image-load-path-for-library): Prefer user's images in
Bill Wohler <wohler@newt.com>
parents: 69493
diff changeset
176 (expand-file-name "images" data-directory)))))
e419733d5cf6 (image-load-path-for-library): Prefer user's images in
Bill Wohler <wohler@newt.com>
parents: 69493
diff changeset
177 (setq image-directory image-directory-load-path))
69360
e5e4303f8050 (image-load-path-for-library): Merge at least three functions from
Bill Wohler <wohler@newt.com>
parents: 68651
diff changeset
178 ;; Try relative setting.
e5e4303f8050 (image-load-path-for-library): Merge at least three functions from
Bill Wohler <wohler@newt.com>
parents: 68651
diff changeset
179 ((let (library-name d1ei d2ei)
e5e4303f8050 (image-load-path-for-library): Merge at least three functions from
Bill Wohler <wohler@newt.com>
parents: 68651
diff changeset
180 ;; First, find library in the load-path.
e5e4303f8050 (image-load-path-for-library): Merge at least three functions from
Bill Wohler <wohler@newt.com>
parents: 68651
diff changeset
181 (setq library-name (locate-library library))
e5e4303f8050 (image-load-path-for-library): Merge at least three functions from
Bill Wohler <wohler@newt.com>
parents: 68651
diff changeset
182 (if (not library-name)
e5e4303f8050 (image-load-path-for-library): Merge at least three functions from
Bill Wohler <wohler@newt.com>
parents: 68651
diff changeset
183 (error "Cannot find library %s in load-path" library))
e5e4303f8050 (image-load-path-for-library): Merge at least three functions from
Bill Wohler <wohler@newt.com>
parents: 68651
diff changeset
184 ;; And then set image-directory relative to that.
e5e4303f8050 (image-load-path-for-library): Merge at least three functions from
Bill Wohler <wohler@newt.com>
parents: 68651
diff changeset
185 (setq
e5e4303f8050 (image-load-path-for-library): Merge at least three functions from
Bill Wohler <wohler@newt.com>
parents: 68651
diff changeset
186 ;; Go down 2 levels.
69516
e419733d5cf6 (image-load-path-for-library): Prefer user's images in
Bill Wohler <wohler@newt.com>
parents: 69493
diff changeset
187 d2ei (file-name-as-directory
e419733d5cf6 (image-load-path-for-library): Prefer user's images in
Bill Wohler <wohler@newt.com>
parents: 69493
diff changeset
188 (expand-file-name
e419733d5cf6 (image-load-path-for-library): Prefer user's images in
Bill Wohler <wohler@newt.com>
parents: 69493
diff changeset
189 (concat (file-name-directory library-name) "../../etc/images")))
69360
e5e4303f8050 (image-load-path-for-library): Merge at least three functions from
Bill Wohler <wohler@newt.com>
parents: 68651
diff changeset
190 ;; Go down 1 level.
69516
e419733d5cf6 (image-load-path-for-library): Prefer user's images in
Bill Wohler <wohler@newt.com>
parents: 69493
diff changeset
191 d1ei (file-name-as-directory
e419733d5cf6 (image-load-path-for-library): Prefer user's images in
Bill Wohler <wohler@newt.com>
parents: 69493
diff changeset
192 (expand-file-name
e419733d5cf6 (image-load-path-for-library): Prefer user's images in
Bill Wohler <wohler@newt.com>
parents: 69493
diff changeset
193 (concat (file-name-directory library-name) "../etc/images"))))
69360
e5e4303f8050 (image-load-path-for-library): Merge at least three functions from
Bill Wohler <wohler@newt.com>
parents: 68651
diff changeset
194 (setq image-directory
e5e4303f8050 (image-load-path-for-library): Merge at least three functions from
Bill Wohler <wohler@newt.com>
parents: 68651
diff changeset
195 ;; Set it to nil if image is not found.
e5e4303f8050 (image-load-path-for-library): Merge at least three functions from
Bill Wohler <wohler@newt.com>
parents: 68651
diff changeset
196 (cond ((file-exists-p (expand-file-name image d2ei)) d2ei)
e5e4303f8050 (image-load-path-for-library): Merge at least three functions from
Bill Wohler <wohler@newt.com>
parents: 68651
diff changeset
197 ((file-exists-p (expand-file-name image d1ei)) d1ei)))))
69516
e419733d5cf6 (image-load-path-for-library): Prefer user's images in
Bill Wohler <wohler@newt.com>
parents: 69493
diff changeset
198 ;; Use Emacs' image directory.
e419733d5cf6 (image-load-path-for-library): Prefer user's images in
Bill Wohler <wohler@newt.com>
parents: 69493
diff changeset
199 (image-directory-load-path
e419733d5cf6 (image-load-path-for-library): Prefer user's images in
Bill Wohler <wohler@newt.com>
parents: 69493
diff changeset
200 (setq image-directory image-directory-load-path))
69365
0a2d89023fde (image-load-path-for-library): Merged changes from Reiner. Add
Bill Wohler <wohler@newt.com>
parents: 69360
diff changeset
201 (no-error
0a2d89023fde (image-load-path-for-library): Merged changes from Reiner. Add
Bill Wohler <wohler@newt.com>
parents: 69360
diff changeset
202 (message "Could not find image %s for library %s" image library))
69360
e5e4303f8050 (image-load-path-for-library): Merge at least three functions from
Bill Wohler <wohler@newt.com>
parents: 68651
diff changeset
203 (t
e5e4303f8050 (image-load-path-for-library): Merge at least three functions from
Bill Wohler <wohler@newt.com>
parents: 68651
diff changeset
204 (error "Could not find image %s for library %s" image library)))
e5e4303f8050 (image-load-path-for-library): Merge at least three functions from
Bill Wohler <wohler@newt.com>
parents: 68651
diff changeset
205
69471
6f07bf99b6f8 (image-load-path-for-library): Pass value of path rather than symbol.
Bill Wohler <wohler@newt.com>
parents: 69365
diff changeset
206 ;; Return an augmented `path' or `load-path'.
6f07bf99b6f8 (image-load-path-for-library): Pass value of path rather than symbol.
Bill Wohler <wohler@newt.com>
parents: 69365
diff changeset
207 (nconc (list image-directory)
6f07bf99b6f8 (image-load-path-for-library): Pass value of path rather than symbol.
Bill Wohler <wohler@newt.com>
parents: 69365
diff changeset
208 (delete image-directory (copy-sequence (or path load-path))))))
6f07bf99b6f8 (image-load-path-for-library): Pass value of path rather than symbol.
Bill Wohler <wohler@newt.com>
parents: 69365
diff changeset
209
69360
e5e4303f8050 (image-load-path-for-library): Merge at least three functions from
Bill Wohler <wohler@newt.com>
parents: 68651
diff changeset
210
38732
24fe4f884e82 (image-type-regexps): Allow predicates. Change the way
Gerd Moellmann <gerd@gnu.org>
parents: 38711
diff changeset
211 (defun image-jpeg-p (data)
46810
65ad7b458435 (image-jpeg-p): Accept "Exif" marker.
Richard M. Stallman <rms@gnu.org>
parents: 43834
diff changeset
212 "Value is non-nil if DATA, a string, consists of JFIF image data.
65ad7b458435 (image-jpeg-p): Accept "Exif" marker.
Richard M. Stallman <rms@gnu.org>
parents: 43834
diff changeset
213 We accept the tag Exif because that is the same format."
96380
044f3969e191 (image-jpeg-p): Don't fail if the arg cannot be converted to unibyte.
Juanma Barranquero <lekktu@gmail.com>
parents: 96253
diff changeset
214 (setq data (ignore-errors (string-to-unibyte data)))
044f3969e191 (image-jpeg-p): Don't fail if the arg cannot be converted to unibyte.
Juanma Barranquero <lekktu@gmail.com>
parents: 96253
diff changeset
215 (when (and data (string-match-p "\\`\xff\xd8" data))
38732
24fe4f884e82 (image-type-regexps): Allow predicates. Change the way
Gerd Moellmann <gerd@gnu.org>
parents: 38711
diff changeset
216 (catch 'jfif
24fe4f884e82 (image-type-regexps): Allow predicates. Change the way
Gerd Moellmann <gerd@gnu.org>
parents: 38711
diff changeset
217 (let ((len (length data)) (i 2))
24fe4f884e82 (image-type-regexps): Allow predicates. Change the way
Gerd Moellmann <gerd@gnu.org>
parents: 38711
diff changeset
218 (while (< i len)
24fe4f884e82 (image-type-regexps): Allow predicates. Change the way
Gerd Moellmann <gerd@gnu.org>
parents: 38711
diff changeset
219 (when (/= (aref data i) #xff)
24fe4f884e82 (image-type-regexps): Allow predicates. Change the way
Gerd Moellmann <gerd@gnu.org>
parents: 38711
diff changeset
220 (throw 'jfif nil))
24fe4f884e82 (image-type-regexps): Allow predicates. Change the way
Gerd Moellmann <gerd@gnu.org>
parents: 38711
diff changeset
221 (setq i (1+ i))
24fe4f884e82 (image-type-regexps): Allow predicates. Change the way
Gerd Moellmann <gerd@gnu.org>
parents: 38711
diff changeset
222 (when (>= (+ i 2) len)
24fe4f884e82 (image-type-regexps): Allow predicates. Change the way
Gerd Moellmann <gerd@gnu.org>
parents: 38711
diff changeset
223 (throw 'jfif nil))
24fe4f884e82 (image-type-regexps): Allow predicates. Change the way
Gerd Moellmann <gerd@gnu.org>
parents: 38711
diff changeset
224 (let ((nbytes (+ (lsh (aref data (+ i 1)) 8)
38776
a679a282d5cb (image-jpeg-p): Test for APPn markers in the range
Gerd Moellmann <gerd@gnu.org>
parents: 38746
diff changeset
225 (aref data (+ i 2))))
a679a282d5cb (image-jpeg-p): Test for APPn markers in the range
Gerd Moellmann <gerd@gnu.org>
parents: 38746
diff changeset
226 (code (aref data i)))
a679a282d5cb (image-jpeg-p): Test for APPn markers in the range
Gerd Moellmann <gerd@gnu.org>
parents: 38746
diff changeset
227 (when (and (>= code #xe0) (<= code #xef))
38732
24fe4f884e82 (image-type-regexps): Allow predicates. Change the way
Gerd Moellmann <gerd@gnu.org>
parents: 38711
diff changeset
228 ;; APP0 LEN1 LEN2 "JFIF\0"
49588
37645a051842 Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 48130
diff changeset
229 (throw 'jfif
96380
044f3969e191 (image-jpeg-p): Don't fail if the arg cannot be converted to unibyte.
Juanma Barranquero <lekktu@gmail.com>
parents: 96253
diff changeset
230 (string-match-p "JFIF\\|Exif"
044f3969e191 (image-jpeg-p): Don't fail if the arg cannot be converted to unibyte.
Juanma Barranquero <lekktu@gmail.com>
parents: 96253
diff changeset
231 (substring data i (min (+ i nbytes) len)))))
38746
0fc8e4a27edc (image-type-regexps): Allow whitespace at the start
Gerd Moellmann <gerd@gnu.org>
parents: 38732
diff changeset
232 (setq i (+ i 1 nbytes))))))))
25003
bb68fe3c72f8 New file.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
233
bb68fe3c72f8 New file.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
234
bb68fe3c72f8 New file.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
235 ;;;###autoload
27073
aad0a025b1e3 (defimage): Handle specifications containing :data
Gerd Moellmann <gerd@gnu.org>
parents: 27059
diff changeset
236 (defun image-type-from-data (data)
aad0a025b1e3 (defimage): Handle specifications containing :data
Gerd Moellmann <gerd@gnu.org>
parents: 27059
diff changeset
237 "Determine the image type from image data DATA.
aad0a025b1e3 (defimage): Handle specifications containing :data
Gerd Moellmann <gerd@gnu.org>
parents: 27059
diff changeset
238 Value is a symbol specifying the image type or nil if type cannot
aad0a025b1e3 (defimage): Handle specifications containing :data
Gerd Moellmann <gerd@gnu.org>
parents: 27059
diff changeset
239 be determined."
66296
941b6508462f (image-type-header-regexps): Rename from image-type-regexps.
Kim F. Storm <storm@cua.dk>
parents: 66196
diff changeset
240 (let ((types image-type-header-regexps)
27073
aad0a025b1e3 (defimage): Handle specifications containing :data
Gerd Moellmann <gerd@gnu.org>
parents: 27059
diff changeset
241 type)
66296
941b6508462f (image-type-header-regexps): Rename from image-type-regexps.
Kim F. Storm <storm@cua.dk>
parents: 66196
diff changeset
242 (while types
27073
aad0a025b1e3 (defimage): Handle specifications containing :data
Gerd Moellmann <gerd@gnu.org>
parents: 27059
diff changeset
243 (let ((regexp (car (car types)))
74972
94afc7cac404 (image-type-header-regexps, image-type-from-data, image-type-from-buffer,
Juanma Barranquero <lekktu@gmail.com>
parents: 74916
diff changeset
244 (image-type (cdr (car types))))
66296
941b6508462f (image-type-header-regexps): Rename from image-type-regexps.
Kim F. Storm <storm@cua.dk>
parents: 66196
diff changeset
245 (if (or (and (symbolp image-type)
96380
044f3969e191 (image-jpeg-p): Don't fail if the arg cannot be converted to unibyte.
Juanma Barranquero <lekktu@gmail.com>
parents: 96253
diff changeset
246 (string-match-p regexp data))
66296
941b6508462f (image-type-header-regexps): Rename from image-type-regexps.
Kim F. Storm <storm@cua.dk>
parents: 66196
diff changeset
247 (and (consp image-type)
941b6508462f (image-type-header-regexps): Rename from image-type-regexps.
Kim F. Storm <storm@cua.dk>
parents: 66196
diff changeset
248 (funcall (car image-type) data)
941b6508462f (image-type-header-regexps): Rename from image-type-regexps.
Kim F. Storm <storm@cua.dk>
parents: 66196
diff changeset
249 (setq image-type (cdr image-type))))
941b6508462f (image-type-header-regexps): Rename from image-type-regexps.
Kim F. Storm <storm@cua.dk>
parents: 66196
diff changeset
250 (setq type image-type
941b6508462f (image-type-header-regexps): Rename from image-type-regexps.
Kim F. Storm <storm@cua.dk>
parents: 66196
diff changeset
251 types nil)
941b6508462f (image-type-header-regexps): Rename from image-type-regexps.
Kim F. Storm <storm@cua.dk>
parents: 66196
diff changeset
252 (setq types (cdr types)))))
941b6508462f (image-type-header-regexps): Rename from image-type-regexps.
Kim F. Storm <storm@cua.dk>
parents: 66196
diff changeset
253 type))
941b6508462f (image-type-header-regexps): Rename from image-type-regexps.
Kim F. Storm <storm@cua.dk>
parents: 66196
diff changeset
254
941b6508462f (image-type-header-regexps): Rename from image-type-regexps.
Kim F. Storm <storm@cua.dk>
parents: 66196
diff changeset
255
941b6508462f (image-type-header-regexps): Rename from image-type-regexps.
Kim F. Storm <storm@cua.dk>
parents: 66196
diff changeset
256 ;;;###autoload
74972
94afc7cac404 (image-type-header-regexps, image-type-from-data, image-type-from-buffer,
Juanma Barranquero <lekktu@gmail.com>
parents: 74916
diff changeset
257 (defun image-type-from-buffer ()
66296
941b6508462f (image-type-header-regexps): Rename from image-type-regexps.
Kim F. Storm <storm@cua.dk>
parents: 66196
diff changeset
258 "Determine the image type from data in the current buffer.
74972
94afc7cac404 (image-type-header-regexps, image-type-from-data, image-type-from-buffer,
Juanma Barranquero <lekktu@gmail.com>
parents: 74916
diff changeset
259 Value is a symbol specifying the image type or nil if type cannot
94afc7cac404 (image-type-header-regexps, image-type-from-data, image-type-from-buffer,
Juanma Barranquero <lekktu@gmail.com>
parents: 74916
diff changeset
260 be determined."
66296
941b6508462f (image-type-header-regexps): Rename from image-type-regexps.
Kim F. Storm <storm@cua.dk>
parents: 66196
diff changeset
261 (let ((types image-type-header-regexps)
941b6508462f (image-type-header-regexps): Rename from image-type-regexps.
Kim F. Storm <storm@cua.dk>
parents: 66196
diff changeset
262 type
941b6508462f (image-type-header-regexps): Rename from image-type-regexps.
Kim F. Storm <storm@cua.dk>
parents: 66196
diff changeset
263 (opoint (point)))
941b6508462f (image-type-header-regexps): Rename from image-type-regexps.
Kim F. Storm <storm@cua.dk>
parents: 66196
diff changeset
264 (goto-char (point-min))
941b6508462f (image-type-header-regexps): Rename from image-type-regexps.
Kim F. Storm <storm@cua.dk>
parents: 66196
diff changeset
265 (while types
941b6508462f (image-type-header-regexps): Rename from image-type-regexps.
Kim F. Storm <storm@cua.dk>
parents: 66196
diff changeset
266 (let ((regexp (car (car types)))
74972
94afc7cac404 (image-type-header-regexps, image-type-from-data, image-type-from-buffer,
Juanma Barranquero <lekktu@gmail.com>
parents: 74916
diff changeset
267 (image-type (cdr (car types)))
66296
941b6508462f (image-type-header-regexps): Rename from image-type-regexps.
Kim F. Storm <storm@cua.dk>
parents: 66196
diff changeset
268 data)
941b6508462f (image-type-header-regexps): Rename from image-type-regexps.
Kim F. Storm <storm@cua.dk>
parents: 66196
diff changeset
269 (if (or (and (symbolp image-type)
96380
044f3969e191 (image-jpeg-p): Don't fail if the arg cannot be converted to unibyte.
Juanma Barranquero <lekktu@gmail.com>
parents: 96253
diff changeset
270 (looking-at-p regexp))
66296
941b6508462f (image-type-header-regexps): Rename from image-type-regexps.
Kim F. Storm <storm@cua.dk>
parents: 66196
diff changeset
271 (and (consp image-type)
941b6508462f (image-type-header-regexps): Rename from image-type-regexps.
Kim F. Storm <storm@cua.dk>
parents: 66196
diff changeset
272 (funcall (car image-type)
941b6508462f (image-type-header-regexps): Rename from image-type-regexps.
Kim F. Storm <storm@cua.dk>
parents: 66196
diff changeset
273 (or data
941b6508462f (image-type-header-regexps): Rename from image-type-regexps.
Kim F. Storm <storm@cua.dk>
parents: 66196
diff changeset
274 (setq data
941b6508462f (image-type-header-regexps): Rename from image-type-regexps.
Kim F. Storm <storm@cua.dk>
parents: 66196
diff changeset
275 (buffer-substring
941b6508462f (image-type-header-regexps): Rename from image-type-regexps.
Kim F. Storm <storm@cua.dk>
parents: 66196
diff changeset
276 (point-min)
941b6508462f (image-type-header-regexps): Rename from image-type-regexps.
Kim F. Storm <storm@cua.dk>
parents: 66196
diff changeset
277 (min (point-max)
941b6508462f (image-type-header-regexps): Rename from image-type-regexps.
Kim F. Storm <storm@cua.dk>
parents: 66196
diff changeset
278 (+ (point-min) 256))))))
941b6508462f (image-type-header-regexps): Rename from image-type-regexps.
Kim F. Storm <storm@cua.dk>
parents: 66196
diff changeset
279 (setq image-type (cdr image-type))))
74972
94afc7cac404 (image-type-header-regexps, image-type-from-data, image-type-from-buffer,
Juanma Barranquero <lekktu@gmail.com>
parents: 74916
diff changeset
280 (setq type image-type
66296
941b6508462f (image-type-header-regexps): Rename from image-type-regexps.
Kim F. Storm <storm@cua.dk>
parents: 66196
diff changeset
281 types nil)
941b6508462f (image-type-header-regexps): Rename from image-type-regexps.
Kim F. Storm <storm@cua.dk>
parents: 66196
diff changeset
282 (setq types (cdr types)))))
941b6508462f (image-type-header-regexps): Rename from image-type-regexps.
Kim F. Storm <storm@cua.dk>
parents: 66196
diff changeset
283 (goto-char opoint)
27073
aad0a025b1e3 (defimage): Handle specifications containing :data
Gerd Moellmann <gerd@gnu.org>
parents: 27059
diff changeset
284 type))
aad0a025b1e3 (defimage): Handle specifications containing :data
Gerd Moellmann <gerd@gnu.org>
parents: 27059
diff changeset
285
aad0a025b1e3 (defimage): Handle specifications containing :data
Gerd Moellmann <gerd@gnu.org>
parents: 27059
diff changeset
286
aad0a025b1e3 (defimage): Handle specifications containing :data
Gerd Moellmann <gerd@gnu.org>
parents: 27059
diff changeset
287 ;;;###autoload
25003
bb68fe3c72f8 New file.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
288 (defun image-type-from-file-header (file)
bb68fe3c72f8 New file.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
289 "Determine the type of image file FILE from its first few bytes.
bb68fe3c72f8 New file.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
290 Value is a symbol specifying the image type, or nil if type cannot
bb68fe3c72f8 New file.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
291 be determined."
66296
941b6508462f (image-type-header-regexps): Rename from image-type-regexps.
Kim F. Storm <storm@cua.dk>
parents: 66196
diff changeset
292 (unless (or (file-readable-p file)
941b6508462f (image-type-header-regexps): Rename from image-type-regexps.
Kim F. Storm <storm@cua.dk>
parents: 66196
diff changeset
293 (file-name-absolute-p file))
941b6508462f (image-type-header-regexps): Rename from image-type-regexps.
Kim F. Storm <storm@cua.dk>
parents: 66196
diff changeset
294 (setq file (image-search-load-path file)))
941b6508462f (image-type-header-regexps): Rename from image-type-regexps.
Kim F. Storm <storm@cua.dk>
parents: 66196
diff changeset
295 (and file
941b6508462f (image-type-header-regexps): Rename from image-type-regexps.
Kim F. Storm <storm@cua.dk>
parents: 66196
diff changeset
296 (file-readable-p file)
941b6508462f (image-type-header-regexps): Rename from image-type-regexps.
Kim F. Storm <storm@cua.dk>
parents: 66196
diff changeset
297 (with-temp-buffer
941b6508462f (image-type-header-regexps): Rename from image-type-regexps.
Kim F. Storm <storm@cua.dk>
parents: 66196
diff changeset
298 (set-buffer-multibyte nil)
941b6508462f (image-type-header-regexps): Rename from image-type-regexps.
Kim F. Storm <storm@cua.dk>
parents: 66196
diff changeset
299 (insert-file-contents-literally file nil 0 256)
74972
94afc7cac404 (image-type-header-regexps, image-type-from-data, image-type-from-buffer,
Juanma Barranquero <lekktu@gmail.com>
parents: 74916
diff changeset
300 (image-type-from-buffer))))
66296
941b6508462f (image-type-header-regexps): Rename from image-type-regexps.
Kim F. Storm <storm@cua.dk>
parents: 66196
diff changeset
301
941b6508462f (image-type-header-regexps): Rename from image-type-regexps.
Kim F. Storm <storm@cua.dk>
parents: 66196
diff changeset
302
941b6508462f (image-type-header-regexps): Rename from image-type-regexps.
Kim F. Storm <storm@cua.dk>
parents: 66196
diff changeset
303 ;;;###autoload
941b6508462f (image-type-header-regexps): Rename from image-type-regexps.
Kim F. Storm <storm@cua.dk>
parents: 66196
diff changeset
304 (defun image-type-from-file-name (file)
941b6508462f (image-type-header-regexps): Rename from image-type-regexps.
Kim F. Storm <storm@cua.dk>
parents: 66196
diff changeset
305 "Determine the type of image file FILE from its name.
941b6508462f (image-type-header-regexps): Rename from image-type-regexps.
Kim F. Storm <storm@cua.dk>
parents: 66196
diff changeset
306 Value is a symbol specifying the image type, or nil if type cannot
941b6508462f (image-type-header-regexps): Rename from image-type-regexps.
Kim F. Storm <storm@cua.dk>
parents: 66196
diff changeset
307 be determined."
96380
044f3969e191 (image-jpeg-p): Don't fail if the arg cannot be converted to unibyte.
Juanma Barranquero <lekktu@gmail.com>
parents: 96253
diff changeset
308 (assoc-default file image-type-file-name-regexps 'string-match-p))
25003
bb68fe3c72f8 New file.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
309
bb68fe3c72f8 New file.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
310
bb68fe3c72f8 New file.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
311 ;;;###autoload
81013
b808e2e86f98 (image-type-from-file-name, image-type): Simplify.
Chong Yidong <cyd@stupidchicken.com>
parents: 75744
diff changeset
312 (defun image-type (source &optional type data-p)
70170
de6c9508749d (image-type): New defun split out of create-image.
Kim F. Storm <storm@cua.dk>
parents: 69569
diff changeset
313 "Determine and return image type.
81013
b808e2e86f98 (image-type-from-file-name, image-type): Simplify.
Chong Yidong <cyd@stupidchicken.com>
parents: 75744
diff changeset
314 SOURCE is an image file name or image data.
70170
de6c9508749d (image-type): New defun split out of create-image.
Kim F. Storm <storm@cua.dk>
parents: 69569
diff changeset
315 Optional TYPE is a symbol describing the image type. If TYPE is omitted
de6c9508749d (image-type): New defun split out of create-image.
Kim F. Storm <storm@cua.dk>
parents: 69569
diff changeset
316 or nil, try to determine the image type from its first few bytes
81013
b808e2e86f98 (image-type-from-file-name, image-type): Simplify.
Chong Yidong <cyd@stupidchicken.com>
parents: 75744
diff changeset
317 of image data. If that doesn't work, and SOURCE is a file name,
70170
de6c9508749d (image-type): New defun split out of create-image.
Kim F. Storm <storm@cua.dk>
parents: 69569
diff changeset
318 use its file extension as image type.
81013
b808e2e86f98 (image-type-from-file-name, image-type): Simplify.
Chong Yidong <cyd@stupidchicken.com>
parents: 75744
diff changeset
319 Optional DATA-P non-nil means SOURCE is a string containing image data."
b808e2e86f98 (image-type-from-file-name, image-type): Simplify.
Chong Yidong <cyd@stupidchicken.com>
parents: 75744
diff changeset
320 (when (and (not data-p) (not (stringp source)))
b808e2e86f98 (image-type-from-file-name, image-type): Simplify.
Chong Yidong <cyd@stupidchicken.com>
parents: 75744
diff changeset
321 (error "Invalid image file name `%s'" source))
70170
de6c9508749d (image-type): New defun split out of create-image.
Kim F. Storm <storm@cua.dk>
parents: 69569
diff changeset
322 (unless type
81013
b808e2e86f98 (image-type-from-file-name, image-type): Simplify.
Chong Yidong <cyd@stupidchicken.com>
parents: 75744
diff changeset
323 (setq type (if data-p
b808e2e86f98 (image-type-from-file-name, image-type): Simplify.
Chong Yidong <cyd@stupidchicken.com>
parents: 75744
diff changeset
324 (image-type-from-data source)
b808e2e86f98 (image-type-from-file-name, image-type): Simplify.
Chong Yidong <cyd@stupidchicken.com>
parents: 75744
diff changeset
325 (or (image-type-from-file-header source)
b808e2e86f98 (image-type-from-file-name, image-type): Simplify.
Chong Yidong <cyd@stupidchicken.com>
parents: 75744
diff changeset
326 (image-type-from-file-name source))))
b808e2e86f98 (image-type-from-file-name, image-type): Simplify.
Chong Yidong <cyd@stupidchicken.com>
parents: 75744
diff changeset
327 (or type (error "Cannot determine image type")))
85072
c27859b68484 (image-type): Check if image-types is bound to not fail on tty.
Juri Linkov <juri@jurta.org>
parents: 84949
diff changeset
328 (or (memq type (and (boundp 'image-types) image-types))
81013
b808e2e86f98 (image-type-from-file-name, image-type): Simplify.
Chong Yidong <cyd@stupidchicken.com>
parents: 75744
diff changeset
329 (error "Invalid image type `%s'" type))
70170
de6c9508749d (image-type): New defun split out of create-image.
Kim F. Storm <storm@cua.dk>
parents: 69569
diff changeset
330 type)
de6c9508749d (image-type): New defun split out of create-image.
Kim F. Storm <storm@cua.dk>
parents: 69569
diff changeset
331
74972
94afc7cac404 (image-type-header-regexps, image-type-from-data, image-type-from-buffer,
Juanma Barranquero <lekktu@gmail.com>
parents: 74916
diff changeset
332
110967
188673195616 Rename `image-library-alist' to `dynamic-library-alist'.
Juanma Barranquero <lekktu@gmail.com>
parents: 110914
diff changeset
333 (define-obsolete-variable-alias
188673195616 Rename `image-library-alist' to `dynamic-library-alist'.
Juanma Barranquero <lekktu@gmail.com>
parents: 110914
diff changeset
334 'image-library-alist
188673195616 Rename `image-library-alist' to `dynamic-library-alist'.
Juanma Barranquero <lekktu@gmail.com>
parents: 110914
diff changeset
335 'dynamic-library-alist "24.1")
95841
b4e36ff621b3 Add some compiler declarations, for builds without X.
Glenn Morris <rgm@gnu.org>
parents: 94678
diff changeset
336
70170
de6c9508749d (image-type): New defun split out of create-image.
Kim F. Storm <storm@cua.dk>
parents: 69569
diff changeset
337 ;;;###autoload
25003
bb68fe3c72f8 New file.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
338 (defun image-type-available-p (type)
62816
f5a3eeaf3d70 (image-library-alist): Moved to image.c.
Juanma Barranquero <lekktu@gmail.com>
parents: 60688
diff changeset
339 "Return non-nil if image type TYPE is available.
25003
bb68fe3c72f8 New file.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
340 Image types are symbols like `xbm' or `jpeg'."
56106
5b3f0e4cf47f (image-library-alist): New variable to map image types to external
Juanma Barranquero <lekktu@gmail.com>
parents: 55167
diff changeset
341 (and (fboundp 'init-image-library)
110967
188673195616 Rename `image-library-alist' to `dynamic-library-alist'.
Juanma Barranquero <lekktu@gmail.com>
parents: 110914
diff changeset
342 (init-image-library type dynamic-library-alist)))
25003
bb68fe3c72f8 New file.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
343
66296
941b6508462f (image-type-header-regexps): Rename from image-type-regexps.
Kim F. Storm <storm@cua.dk>
parents: 66196
diff changeset
344
25003
bb68fe3c72f8 New file.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
345 ;;;###autoload
74972
94afc7cac404 (image-type-header-regexps, image-type-from-data, image-type-from-buffer,
Juanma Barranquero <lekktu@gmail.com>
parents: 74916
diff changeset
346 (defun image-type-auto-detected-p ()
78492
7c8949dbfa0d Replace `iff' in doc-strings and comments.
Glenn Morris <rgm@gnu.org>
parents: 78236
diff changeset
347 "Return t if the current buffer contains an auto-detectable image.
77873
b2375f70c499 (image-type-auto-detected-p): Don't scan auto-mode-alist.
Chong Yidong <cyd@stupidchicken.com>
parents: 75744
diff changeset
348 This function is intended to be used from `magic-fallback-mode-alist'.
74972
94afc7cac404 (image-type-header-regexps, image-type-from-data, image-type-from-buffer,
Juanma Barranquero <lekktu@gmail.com>
parents: 74916
diff changeset
349
77873
b2375f70c499 (image-type-auto-detected-p): Don't scan auto-mode-alist.
Chong Yidong <cyd@stupidchicken.com>
parents: 75744
diff changeset
350 The buffer is considered to contain an auto-detectable image if
b2375f70c499 (image-type-auto-detected-p): Don't scan auto-mode-alist.
Chong Yidong <cyd@stupidchicken.com>
parents: 75744
diff changeset
351 its beginning matches an image type in `image-type-header-regexps',
84944
186e9ba3989a (image-type-auto-detected-p): Doc fix. Don't detect an image if it is
Glenn Morris <rgm@gnu.org>
parents: 82835
diff changeset
352 and that image type is present in `image-type-auto-detectable' with a
186e9ba3989a (image-type-auto-detected-p): Doc fix. Don't detect an image if it is
Glenn Morris <rgm@gnu.org>
parents: 82835
diff changeset
353 non-nil value. If that value is non-nil, but not t, then the image type
186e9ba3989a (image-type-auto-detected-p): Doc fix. Don't detect an image if it is
Glenn Morris <rgm@gnu.org>
parents: 82835
diff changeset
354 must be available."
74972
94afc7cac404 (image-type-header-regexps, image-type-from-data, image-type-from-buffer,
Juanma Barranquero <lekktu@gmail.com>
parents: 74916
diff changeset
355 (let* ((type (image-type-from-buffer))
94afc7cac404 (image-type-header-regexps, image-type-from-data, image-type-from-buffer,
Juanma Barranquero <lekktu@gmail.com>
parents: 74916
diff changeset
356 (auto (and type (cdr (assq type image-type-auto-detectable)))))
94afc7cac404 (image-type-header-regexps, image-type-from-data, image-type-from-buffer,
Juanma Barranquero <lekktu@gmail.com>
parents: 74916
diff changeset
357 (and auto
77873
b2375f70c499 (image-type-auto-detected-p): Don't scan auto-mode-alist.
Chong Yidong <cyd@stupidchicken.com>
parents: 75744
diff changeset
358 (or (eq auto t) (image-type-available-p type)))))
74972
94afc7cac404 (image-type-header-regexps, image-type-from-data, image-type-from-buffer,
Juanma Barranquero <lekktu@gmail.com>
parents: 74916
diff changeset
359
94afc7cac404 (image-type-header-regexps, image-type-from-data, image-type-from-buffer,
Juanma Barranquero <lekktu@gmail.com>
parents: 74916
diff changeset
360
94afc7cac404 (image-type-header-regexps, image-type-from-data, image-type-from-buffer,
Juanma Barranquero <lekktu@gmail.com>
parents: 74916
diff changeset
361 ;;;###autoload
27073
aad0a025b1e3 (defimage): Handle specifications containing :data
Gerd Moellmann <gerd@gnu.org>
parents: 27059
diff changeset
362 (defun create-image (file-or-data &optional type data-p &rest props)
aad0a025b1e3 (defimage): Handle specifications containing :data
Gerd Moellmann <gerd@gnu.org>
parents: 27059
diff changeset
363 "Create an image.
aad0a025b1e3 (defimage): Handle specifications containing :data
Gerd Moellmann <gerd@gnu.org>
parents: 27059
diff changeset
364 FILE-OR-DATA is an image file name or image data.
25003
bb68fe3c72f8 New file.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
365 Optional TYPE is a symbol describing the image type. If TYPE is omitted
27073
aad0a025b1e3 (defimage): Handle specifications containing :data
Gerd Moellmann <gerd@gnu.org>
parents: 27059
diff changeset
366 or nil, try to determine the image type from its first few bytes
aad0a025b1e3 (defimage): Handle specifications containing :data
Gerd Moellmann <gerd@gnu.org>
parents: 27059
diff changeset
367 of image data. If that doesn't work, and FILE-OR-DATA is a file name,
34378
5ae7af279df7 (create-image): Doc fix; spotted by Per Cederqvist <ceder@lysator.liu.se>.
Eli Zaretskii <eliz@gnu.org>
parents: 32166
diff changeset
368 use its file extension as image type.
27073
aad0a025b1e3 (defimage): Handle specifications containing :data
Gerd Moellmann <gerd@gnu.org>
parents: 27059
diff changeset
369 Optional DATA-P non-nil means FILE-OR-DATA is a string containing image data.
25003
bb68fe3c72f8 New file.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
370 Optional PROPS are additional image attributes to assign to the image,
31635
208d8385ccae (create-image): Doc fix.
Gerd Moellmann <gerd@gnu.org>
parents: 30952
diff changeset
371 like, e.g. `:mask MASK'.
66196
2e59eea25fcf * image.el (create-image, find-image): Mention max-image-size in
Chong Yidong <cyd@stupidchicken.com>
parents: 65599
diff changeset
372 Value is the image created, or nil if images of type TYPE are not supported.
2e59eea25fcf * image.el (create-image, find-image): Mention max-image-size in
Chong Yidong <cyd@stupidchicken.com>
parents: 65599
diff changeset
373
82734
8c182b8c81d6 (create-image): Doc fix.
Glenn Morris <rgm@gnu.org>
parents: 82521
diff changeset
374 Images should not be larger than specified by `max-image-size'.
8c182b8c81d6 (create-image): Doc fix.
Glenn Morris <rgm@gnu.org>
parents: 82521
diff changeset
375
8c182b8c81d6 (create-image): Doc fix.
Glenn Morris <rgm@gnu.org>
parents: 82521
diff changeset
376 Image file names that are not absolute are searched for in the
8c182b8c81d6 (create-image): Doc fix.
Glenn Morris <rgm@gnu.org>
parents: 82521
diff changeset
377 \"images\" sub-directory of `data-directory' and
8c182b8c81d6 (create-image): Doc fix.
Glenn Morris <rgm@gnu.org>
parents: 82521
diff changeset
378 `x-bitmap-file-path' (in that order)."
8c182b8c81d6 (create-image): Doc fix.
Glenn Morris <rgm@gnu.org>
parents: 82521
diff changeset
379 ;; It is x_find_image_file in image.c that sets the search path.
70170
de6c9508749d (image-type): New defun split out of create-image.
Kim F. Storm <storm@cua.dk>
parents: 69569
diff changeset
380 (setq type (image-type file-or-data type data-p))
25003
bb68fe3c72f8 New file.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
381 (when (image-type-available-p type)
27073
aad0a025b1e3 (defimage): Handle specifications containing :data
Gerd Moellmann <gerd@gnu.org>
parents: 27059
diff changeset
382 (append (list 'image :type type (if data-p :data :file) file-or-data)
aad0a025b1e3 (defimage): Handle specifications containing :data
Gerd Moellmann <gerd@gnu.org>
parents: 27059
diff changeset
383 props)))
25003
bb68fe3c72f8 New file.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
384
bb68fe3c72f8 New file.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
385
bb68fe3c72f8 New file.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
386 ;;;###autoload
29470
7bde123bed95 (find-image): Doc fix. Return nil if image not found.
Dave Love <fx@gnu.org>
parents: 28958
diff changeset
387 (defun put-image (image pos &optional string area)
25617
697b28471784 (put-image): Remove optional buffer parameter.
Gerd Moellmann <gerd@gnu.org>
parents: 25309
diff changeset
388 "Put image IMAGE in front of POS in the current buffer.
25003
bb68fe3c72f8 New file.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
389 IMAGE must be an image created with `create-image' or `defimage'.
25816
2d53a03a3baa (put-image, insert-image): Add string argument.
Gerd Moellmann <gerd@gnu.org>
parents: 25617
diff changeset
390 IMAGE is displayed by putting an overlay into the current buffer with a
2d53a03a3baa (put-image, insert-image): Add string argument.
Gerd Moellmann <gerd@gnu.org>
parents: 25617
diff changeset
391 `before-string' STRING that has a `display' property whose value is the
29470
7bde123bed95 (find-image): Doc fix. Return nil if image not found.
Dave Love <fx@gnu.org>
parents: 28958
diff changeset
392 image. STRING is defaulted if you omit it.
25003
bb68fe3c72f8 New file.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
393 POS may be an integer or marker.
bb68fe3c72f8 New file.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
394 AREA is where to display the image. AREA nil or omitted means
bb68fe3c72f8 New file.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
395 display it in the text area, a value of `left-margin' means
bb68fe3c72f8 New file.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
396 display it in the left marginal area, a value of `right-margin'
25816
2d53a03a3baa (put-image, insert-image): Add string argument.
Gerd Moellmann <gerd@gnu.org>
parents: 25617
diff changeset
397 means display it in the right marginal area."
29626
ecb96a7369d3 Fix last change to be in insert-image as intended.
Dave Love <fx@gnu.org>
parents: 29624
diff changeset
398 (unless string (setq string "x"))
25617
697b28471784 (put-image): Remove optional buffer parameter.
Gerd Moellmann <gerd@gnu.org>
parents: 25309
diff changeset
399 (let ((buffer (current-buffer)))
29470
7bde123bed95 (find-image): Doc fix. Return nil if image not found.
Dave Love <fx@gnu.org>
parents: 28958
diff changeset
400 (unless (eq (car-safe image) 'image)
25617
697b28471784 (put-image): Remove optional buffer parameter.
Gerd Moellmann <gerd@gnu.org>
parents: 25309
diff changeset
401 (error "Not an image: %s" image))
697b28471784 (put-image): Remove optional buffer parameter.
Gerd Moellmann <gerd@gnu.org>
parents: 25309
diff changeset
402 (unless (or (null area) (memq area '(left-margin right-margin)))
697b28471784 (put-image): Remove optional buffer parameter.
Gerd Moellmann <gerd@gnu.org>
parents: 25309
diff changeset
403 (error "Invalid area %s" area))
25816
2d53a03a3baa (put-image, insert-image): Add string argument.
Gerd Moellmann <gerd@gnu.org>
parents: 25617
diff changeset
404 (setq string (copy-sequence string))
25617
697b28471784 (put-image): Remove optional buffer parameter.
Gerd Moellmann <gerd@gnu.org>
parents: 25309
diff changeset
405 (let ((overlay (make-overlay pos pos buffer))
25816
2d53a03a3baa (put-image, insert-image): Add string argument.
Gerd Moellmann <gerd@gnu.org>
parents: 25617
diff changeset
406 (prop (if (null area) image (list (list 'margin area) image))))
2d53a03a3baa (put-image, insert-image): Add string argument.
Gerd Moellmann <gerd@gnu.org>
parents: 25617
diff changeset
407 (put-text-property 0 (length string) 'display prop string)
25617
697b28471784 (put-image): Remove optional buffer parameter.
Gerd Moellmann <gerd@gnu.org>
parents: 25309
diff changeset
408 (overlay-put overlay 'put-image t)
697b28471784 (put-image): Remove optional buffer parameter.
Gerd Moellmann <gerd@gnu.org>
parents: 25309
diff changeset
409 (overlay-put overlay 'before-string string))))
25003
bb68fe3c72f8 New file.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
410
bb68fe3c72f8 New file.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
411
bb68fe3c72f8 New file.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
412 ;;;###autoload
55033
a7dfcd60873e (insert-image): Add optional SLICE arg.
Kim F. Storm <storm@cua.dk>
parents: 52401
diff changeset
413 (defun insert-image (image &optional string area slice)
25003
bb68fe3c72f8 New file.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
414 "Insert IMAGE into current buffer at point.
25816
2d53a03a3baa (put-image, insert-image): Add string argument.
Gerd Moellmann <gerd@gnu.org>
parents: 25617
diff changeset
415 IMAGE is displayed by inserting STRING into the current buffer
29470
7bde123bed95 (find-image): Doc fix. Return nil if image not found.
Dave Love <fx@gnu.org>
parents: 28958
diff changeset
416 with a `display' property whose value is the image. STRING is
7bde123bed95 (find-image): Doc fix. Return nil if image not found.
Dave Love <fx@gnu.org>
parents: 28958
diff changeset
417 defaulted if you omit it.
25003
bb68fe3c72f8 New file.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
418 AREA is where to display the image. AREA nil or omitted means
bb68fe3c72f8 New file.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
419 display it in the text area, a value of `left-margin' means
bb68fe3c72f8 New file.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
420 display it in the left marginal area, a value of `right-margin'
55033
a7dfcd60873e (insert-image): Add optional SLICE arg.
Kim F. Storm <storm@cua.dk>
parents: 52401
diff changeset
421 means display it in the right marginal area.
a7dfcd60873e (insert-image): Add optional SLICE arg.
Kim F. Storm <storm@cua.dk>
parents: 52401
diff changeset
422 SLICE specifies slice of IMAGE to insert. SLICE nil or omitted
a7dfcd60873e (insert-image): Add optional SLICE arg.
Kim F. Storm <storm@cua.dk>
parents: 52401
diff changeset
423 means insert whole image. SLICE is a list (X Y WIDTH HEIGHT)
a7dfcd60873e (insert-image): Add optional SLICE arg.
Kim F. Storm <storm@cua.dk>
parents: 52401
diff changeset
424 specifying the X and Y positions and WIDTH and HEIGHT of image area
a7dfcd60873e (insert-image): Add optional SLICE arg.
Kim F. Storm <storm@cua.dk>
parents: 52401
diff changeset
425 to insert. A float value 0.0 - 1.0 means relative to the width or
a7dfcd60873e (insert-image): Add optional SLICE arg.
Kim F. Storm <storm@cua.dk>
parents: 52401
diff changeset
426 height of the image; integer values are taken as pixel values."
29626
ecb96a7369d3 Fix last change to be in insert-image as intended.
Dave Love <fx@gnu.org>
parents: 29624
diff changeset
427 ;; Use a space as least likely to cause trouble when it's a hidden
ecb96a7369d3 Fix last change to be in insert-image as intended.
Dave Love <fx@gnu.org>
parents: 29624
diff changeset
428 ;; character in the buffer.
ecb96a7369d3 Fix last change to be in insert-image as intended.
Dave Love <fx@gnu.org>
parents: 29624
diff changeset
429 (unless string (setq string " "))
29470
7bde123bed95 (find-image): Doc fix. Return nil if image not found.
Dave Love <fx@gnu.org>
parents: 28958
diff changeset
430 (unless (eq (car-safe image) 'image)
25003
bb68fe3c72f8 New file.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
431 (error "Not an image: %s" image))
bb68fe3c72f8 New file.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
432 (unless (or (null area) (memq area '(left-margin right-margin)))
bb68fe3c72f8 New file.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
433 (error "Invalid area %s" area))
29607
42d156d8d8eb (insert-image): Save a little consing.
Dave Love <fx@gnu.org>
parents: 29470
diff changeset
434 (if area
42d156d8d8eb (insert-image): Save a little consing.
Dave Love <fx@gnu.org>
parents: 29470
diff changeset
435 (setq image (list (list 'margin area) image))
42d156d8d8eb (insert-image): Save a little consing.
Dave Love <fx@gnu.org>
parents: 29470
diff changeset
436 ;; Cons up a new spec equal but not eq to `image' so that
42d156d8d8eb (insert-image): Save a little consing.
Dave Love <fx@gnu.org>
parents: 29470
diff changeset
437 ;; inserting it twice in a row (adjacently) displays two copies of
42d156d8d8eb (insert-image): Save a little consing.
Dave Love <fx@gnu.org>
parents: 29470
diff changeset
438 ;; the image. Don't try to avoid this by looking at the display
42d156d8d8eb (insert-image): Save a little consing.
Dave Love <fx@gnu.org>
parents: 29470
diff changeset
439 ;; properties on either side so that we DTRT more often with
42d156d8d8eb (insert-image): Save a little consing.
Dave Love <fx@gnu.org>
parents: 29470
diff changeset
440 ;; cut-and-paste. (Yanking killed image text next to another copy
42d156d8d8eb (insert-image): Save a little consing.
Dave Love <fx@gnu.org>
parents: 29470
diff changeset
441 ;; of it loses anyway.)
42d156d8d8eb (insert-image): Save a little consing.
Dave Love <fx@gnu.org>
parents: 29470
diff changeset
442 (setq image (cons 'image (cdr image))))
25816
2d53a03a3baa (put-image, insert-image): Add string argument.
Gerd Moellmann <gerd@gnu.org>
parents: 25617
diff changeset
443 (let ((start (point)))
2d53a03a3baa (put-image, insert-image): Add string argument.
Gerd Moellmann <gerd@gnu.org>
parents: 25617
diff changeset
444 (insert string)
2d53a03a3baa (put-image, insert-image): Add string argument.
Gerd Moellmann <gerd@gnu.org>
parents: 25617
diff changeset
445 (add-text-properties start (point)
55033
a7dfcd60873e (insert-image): Add optional SLICE arg.
Kim F. Storm <storm@cua.dk>
parents: 52401
diff changeset
446 `(display ,(if slice
a7dfcd60873e (insert-image): Add optional SLICE arg.
Kim F. Storm <storm@cua.dk>
parents: 52401
diff changeset
447 (list (cons 'slice slice) image)
a7dfcd60873e (insert-image): Add optional SLICE arg.
Kim F. Storm <storm@cua.dk>
parents: 52401
diff changeset
448 image) rear-nonsticky (display)))))
a7dfcd60873e (insert-image): Add optional SLICE arg.
Kim F. Storm <storm@cua.dk>
parents: 52401
diff changeset
449
a7dfcd60873e (insert-image): Add optional SLICE arg.
Kim F. Storm <storm@cua.dk>
parents: 52401
diff changeset
450
60688
b0de8a447a79 (insert-sliced-image): Add autoload cookie.
Richard M. Stallman <rms@gnu.org>
parents: 59276
diff changeset
451 ;;;###autoload
55033
a7dfcd60873e (insert-image): Add optional SLICE arg.
Kim F. Storm <storm@cua.dk>
parents: 52401
diff changeset
452 (defun insert-sliced-image (image &optional string area rows cols)
57196
090c23fa222c (insert-sliced-image): Add doc string.
Kim F. Storm <storm@cua.dk>
parents: 56189
diff changeset
453 "Insert IMAGE into current buffer at point.
090c23fa222c (insert-sliced-image): Add doc string.
Kim F. Storm <storm@cua.dk>
parents: 56189
diff changeset
454 IMAGE is displayed by inserting STRING into the current buffer
090c23fa222c (insert-sliced-image): Add doc string.
Kim F. Storm <storm@cua.dk>
parents: 56189
diff changeset
455 with a `display' property whose value is the image. STRING is
090c23fa222c (insert-sliced-image): Add doc string.
Kim F. Storm <storm@cua.dk>
parents: 56189
diff changeset
456 defaulted if you omit it.
090c23fa222c (insert-sliced-image): Add doc string.
Kim F. Storm <storm@cua.dk>
parents: 56189
diff changeset
457 AREA is where to display the image. AREA nil or omitted means
090c23fa222c (insert-sliced-image): Add doc string.
Kim F. Storm <storm@cua.dk>
parents: 56189
diff changeset
458 display it in the text area, a value of `left-margin' means
090c23fa222c (insert-sliced-image): Add doc string.
Kim F. Storm <storm@cua.dk>
parents: 56189
diff changeset
459 display it in the left marginal area, a value of `right-margin'
090c23fa222c (insert-sliced-image): Add doc string.
Kim F. Storm <storm@cua.dk>
parents: 56189
diff changeset
460 means display it in the right marginal area.
102236
eeef2e7e9171 * image.el (image-load-path-for-library, insert-sliced-image):
Juanma Barranquero <lekktu@gmail.com>
parents: 100908
diff changeset
461 The image is automatically split into ROWS x COLS slices."
55033
a7dfcd60873e (insert-image): Add optional SLICE arg.
Kim F. Storm <storm@cua.dk>
parents: 52401
diff changeset
462 (unless string (setq string " "))
a7dfcd60873e (insert-image): Add optional SLICE arg.
Kim F. Storm <storm@cua.dk>
parents: 52401
diff changeset
463 (unless (eq (car-safe image) 'image)
a7dfcd60873e (insert-image): Add optional SLICE arg.
Kim F. Storm <storm@cua.dk>
parents: 52401
diff changeset
464 (error "Not an image: %s" image))
a7dfcd60873e (insert-image): Add optional SLICE arg.
Kim F. Storm <storm@cua.dk>
parents: 52401
diff changeset
465 (unless (or (null area) (memq area '(left-margin right-margin)))
a7dfcd60873e (insert-image): Add optional SLICE arg.
Kim F. Storm <storm@cua.dk>
parents: 52401
diff changeset
466 (error "Invalid area %s" area))
a7dfcd60873e (insert-image): Add optional SLICE arg.
Kim F. Storm <storm@cua.dk>
parents: 52401
diff changeset
467 (if area
a7dfcd60873e (insert-image): Add optional SLICE arg.
Kim F. Storm <storm@cua.dk>
parents: 52401
diff changeset
468 (setq image (list (list 'margin area) image))
a7dfcd60873e (insert-image): Add optional SLICE arg.
Kim F. Storm <storm@cua.dk>
parents: 52401
diff changeset
469 ;; Cons up a new spec equal but not eq to `image' so that
a7dfcd60873e (insert-image): Add optional SLICE arg.
Kim F. Storm <storm@cua.dk>
parents: 52401
diff changeset
470 ;; inserting it twice in a row (adjacently) displays two copies of
a7dfcd60873e (insert-image): Add optional SLICE arg.
Kim F. Storm <storm@cua.dk>
parents: 52401
diff changeset
471 ;; the image. Don't try to avoid this by looking at the display
a7dfcd60873e (insert-image): Add optional SLICE arg.
Kim F. Storm <storm@cua.dk>
parents: 52401
diff changeset
472 ;; properties on either side so that we DTRT more often with
a7dfcd60873e (insert-image): Add optional SLICE arg.
Kim F. Storm <storm@cua.dk>
parents: 52401
diff changeset
473 ;; cut-and-paste. (Yanking killed image text next to another copy
a7dfcd60873e (insert-image): Add optional SLICE arg.
Kim F. Storm <storm@cua.dk>
parents: 52401
diff changeset
474 ;; of it loses anyway.)
a7dfcd60873e (insert-image): Add optional SLICE arg.
Kim F. Storm <storm@cua.dk>
parents: 52401
diff changeset
475 (setq image (cons 'image (cdr image))))
a7dfcd60873e (insert-image): Add optional SLICE arg.
Kim F. Storm <storm@cua.dk>
parents: 52401
diff changeset
476 (let ((x 0.0) (dx (/ 1.0001 (or cols 1)))
a7dfcd60873e (insert-image): Add optional SLICE arg.
Kim F. Storm <storm@cua.dk>
parents: 52401
diff changeset
477 (y 0.0) (dy (/ 1.0001 (or rows 1))))
a7dfcd60873e (insert-image): Add optional SLICE arg.
Kim F. Storm <storm@cua.dk>
parents: 52401
diff changeset
478 (while (< y 1.0)
a7dfcd60873e (insert-image): Add optional SLICE arg.
Kim F. Storm <storm@cua.dk>
parents: 52401
diff changeset
479 (while (< x 1.0)
a7dfcd60873e (insert-image): Add optional SLICE arg.
Kim F. Storm <storm@cua.dk>
parents: 52401
diff changeset
480 (let ((start (point)))
a7dfcd60873e (insert-image): Add optional SLICE arg.
Kim F. Storm <storm@cua.dk>
parents: 52401
diff changeset
481 (insert string)
a7dfcd60873e (insert-image): Add optional SLICE arg.
Kim F. Storm <storm@cua.dk>
parents: 52401
diff changeset
482 (add-text-properties start (point)
a7dfcd60873e (insert-image): Add optional SLICE arg.
Kim F. Storm <storm@cua.dk>
parents: 52401
diff changeset
483 `(display ,(list (list 'slice x y dx dy) image)
a7dfcd60873e (insert-image): Add optional SLICE arg.
Kim F. Storm <storm@cua.dk>
parents: 52401
diff changeset
484 rear-nonsticky (display)))
a7dfcd60873e (insert-image): Add optional SLICE arg.
Kim F. Storm <storm@cua.dk>
parents: 52401
diff changeset
485 (setq x (+ x dx))))
a7dfcd60873e (insert-image): Add optional SLICE arg.
Kim F. Storm <storm@cua.dk>
parents: 52401
diff changeset
486 (setq x 0.0
a7dfcd60873e (insert-image): Add optional SLICE arg.
Kim F. Storm <storm@cua.dk>
parents: 52401
diff changeset
487 y (+ y dy))
59276
d50d807507e0 (insert-sliced-image): Use t for line-height property.
Kim F. Storm <storm@cua.dk>
parents: 57196
diff changeset
488 (insert (propertize "\n" 'line-height t)))))
55033
a7dfcd60873e (insert-image): Add optional SLICE arg.
Kim F. Storm <storm@cua.dk>
parents: 52401
diff changeset
489
26007
774b2504710b (insert-image): Copy the image spec and add an intangible property.
Dave Love <fx@gnu.org>
parents: 25872
diff changeset
490
25003
bb68fe3c72f8 New file.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
491
bb68fe3c72f8 New file.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
492 ;;;###autoload
bb68fe3c72f8 New file.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
493 (defun remove-images (start end &optional buffer)
bb68fe3c72f8 New file.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
494 "Remove images between START and END in BUFFER.
bb68fe3c72f8 New file.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
495 Remove only images that were put in BUFFER with calls to `put-image'.
bb68fe3c72f8 New file.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
496 BUFFER nil or omitted means use the current buffer."
bb68fe3c72f8 New file.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
497 (unless buffer
bb68fe3c72f8 New file.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
498 (setq buffer (current-buffer)))
bb68fe3c72f8 New file.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
499 (let ((overlays (overlays-in start end)))
bb68fe3c72f8 New file.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
500 (while overlays
bb68fe3c72f8 New file.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
501 (let ((overlay (car overlays)))
bb68fe3c72f8 New file.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
502 (when (overlay-get overlay 'put-image)
25857
fdc2bd91cf63 (defimage): Remove redundant code. Substitute file on image plist.
Dave Love <fx@gnu.org>
parents: 25816
diff changeset
503 (delete-overlay overlay)))
fdc2bd91cf63 (defimage): Remove redundant code. Substitute file on image plist.
Dave Love <fx@gnu.org>
parents: 25816
diff changeset
504 (setq overlays (cdr overlays)))))
25003
bb68fe3c72f8 New file.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
505
66296
941b6508462f (image-type-header-regexps): Rename from image-type-regexps.
Kim F. Storm <storm@cua.dk>
parents: 66196
diff changeset
506 (defun image-search-load-path (file &optional path)
941b6508462f (image-type-header-regexps): Rename from image-type-regexps.
Kim F. Storm <storm@cua.dk>
parents: 66196
diff changeset
507 (unless path
941b6508462f (image-type-header-regexps): Rename from image-type-regexps.
Kim F. Storm <storm@cua.dk>
parents: 66196
diff changeset
508 (setq path image-load-path))
941b6508462f (image-type-header-regexps): Rename from image-type-regexps.
Kim F. Storm <storm@cua.dk>
parents: 66196
diff changeset
509 (let (element found filename)
65544
78d74ef1436b 2005-09-15 Chong Yidong <cyd@stupidchicken.com>
Chong Yidong <cyd@stupidchicken.com>
parents: 64762
diff changeset
510 (while (and (not found) (consp path))
65599
39114a2ae201 (image-load-path): Use symbol `data-directory' instead of its value,
Chong Yidong <cyd@stupidchicken.com>
parents: 65544
diff changeset
511 (setq element (car path))
65544
78d74ef1436b 2005-09-15 Chong Yidong <cyd@stupidchicken.com>
Chong Yidong <cyd@stupidchicken.com>
parents: 64762
diff changeset
512 (cond
65599
39114a2ae201 (image-load-path): Use symbol `data-directory' instead of its value,
Chong Yidong <cyd@stupidchicken.com>
parents: 65544
diff changeset
513 ((stringp element)
65544
78d74ef1436b 2005-09-15 Chong Yidong <cyd@stupidchicken.com>
Chong Yidong <cyd@stupidchicken.com>
parents: 64762
diff changeset
514 (setq found
78d74ef1436b 2005-09-15 Chong Yidong <cyd@stupidchicken.com>
Chong Yidong <cyd@stupidchicken.com>
parents: 64762
diff changeset
515 (file-readable-p
66296
941b6508462f (image-type-header-regexps): Rename from image-type-regexps.
Kim F. Storm <storm@cua.dk>
parents: 66196
diff changeset
516 (setq filename (expand-file-name file element)))))
65599
39114a2ae201 (image-load-path): Use symbol `data-directory' instead of its value,
Chong Yidong <cyd@stupidchicken.com>
parents: 65544
diff changeset
517 ((and (symbolp element) (boundp element))
39114a2ae201 (image-load-path): Use symbol `data-directory' instead of its value,
Chong Yidong <cyd@stupidchicken.com>
parents: 65544
diff changeset
518 (setq element (symbol-value element))
39114a2ae201 (image-load-path): Use symbol `data-directory' instead of its value,
Chong Yidong <cyd@stupidchicken.com>
parents: 65544
diff changeset
519 (cond
39114a2ae201 (image-load-path): Use symbol `data-directory' instead of its value,
Chong Yidong <cyd@stupidchicken.com>
parents: 65544
diff changeset
520 ((stringp element)
39114a2ae201 (image-load-path): Use symbol `data-directory' instead of its value,
Chong Yidong <cyd@stupidchicken.com>
parents: 65544
diff changeset
521 (setq found
39114a2ae201 (image-load-path): Use symbol `data-directory' instead of its value,
Chong Yidong <cyd@stupidchicken.com>
parents: 65544
diff changeset
522 (file-readable-p
66296
941b6508462f (image-type-header-regexps): Rename from image-type-regexps.
Kim F. Storm <storm@cua.dk>
parents: 66196
diff changeset
523 (setq filename (expand-file-name file element)))))
65599
39114a2ae201 (image-load-path): Use symbol `data-directory' instead of its value,
Chong Yidong <cyd@stupidchicken.com>
parents: 65544
diff changeset
524 ((consp element)
66296
941b6508462f (image-type-header-regexps): Rename from image-type-regexps.
Kim F. Storm <storm@cua.dk>
parents: 66196
diff changeset
525 (if (setq filename (image-search-load-path file element))
65599
39114a2ae201 (image-load-path): Use symbol `data-directory' instead of its value,
Chong Yidong <cyd@stupidchicken.com>
parents: 65544
diff changeset
526 (setq found t))))))
65544
78d74ef1436b 2005-09-15 Chong Yidong <cyd@stupidchicken.com>
Chong Yidong <cyd@stupidchicken.com>
parents: 64762
diff changeset
527 (setq path (cdr path)))
66296
941b6508462f (image-type-header-regexps): Rename from image-type-regexps.
Kim F. Storm <storm@cua.dk>
parents: 66196
diff changeset
528 (if found filename)))
25003
bb68fe3c72f8 New file.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
529
bb68fe3c72f8 New file.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
530 ;;;###autoload
28721
b4ea18c92e38 (find-image): New function.
Gerd Moellmann <gerd@gnu.org>
parents: 27921
diff changeset
531 (defun find-image (specs)
b4ea18c92e38 (find-image): New function.
Gerd Moellmann <gerd@gnu.org>
parents: 27921
diff changeset
532 "Find an image, choosing one of a list of image specifications.
25003
bb68fe3c72f8 New file.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
533
29470
7bde123bed95 (find-image): Doc fix. Return nil if image not found.
Dave Love <fx@gnu.org>
parents: 28958
diff changeset
534 SPECS is a list of image specifications.
25003
bb68fe3c72f8 New file.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
535
bb68fe3c72f8 New file.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
536 Each image specification in SPECS is a property list. The contents of
bb68fe3c72f8 New file.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
537 a specification are image type dependent. All specifications must at
27059
6bb2a4a0413e * image.el (defimage): Images with the :data keyword should be considered valid as well.
William M. Perry <wmperry@aventail.com>
parents: 26007
diff changeset
538 least contain the properties `:type TYPE' and either `:file FILE' or
6bb2a4a0413e * image.el (defimage): Images with the :data keyword should be considered valid as well.
William M. Perry <wmperry@aventail.com>
parents: 26007
diff changeset
539 `:data DATA', where TYPE is a symbol specifying the image type,
6bb2a4a0413e * image.el (defimage): Images with the :data keyword should be considered valid as well.
William M. Perry <wmperry@aventail.com>
parents: 26007
diff changeset
540 e.g. `xbm', FILE is the file to load the image from, and DATA is a
29470
7bde123bed95 (find-image): Doc fix. Return nil if image not found.
Dave Love <fx@gnu.org>
parents: 28958
diff changeset
541 string containing the actual image data. The specification whose TYPE
7bde123bed95 (find-image): Doc fix. Return nil if image not found.
Dave Love <fx@gnu.org>
parents: 28958
diff changeset
542 is supported, and FILE exists, is used to construct the image
7bde123bed95 (find-image): Doc fix. Return nil if image not found.
Dave Love <fx@gnu.org>
parents: 28958
diff changeset
543 specification to be returned. Return nil if no specification is
7bde123bed95 (find-image): Doc fix. Return nil if image not found.
Dave Love <fx@gnu.org>
parents: 28958
diff changeset
544 satisfied.
7bde123bed95 (find-image): Doc fix. Return nil if image not found.
Dave Love <fx@gnu.org>
parents: 28958
diff changeset
545
66196
2e59eea25fcf * image.el (create-image, find-image): Mention max-image-size in
Chong Yidong <cyd@stupidchicken.com>
parents: 65599
diff changeset
546 The image is looked for in `image-load-path'.
2e59eea25fcf * image.el (create-image, find-image): Mention max-image-size in
Chong Yidong <cyd@stupidchicken.com>
parents: 65599
diff changeset
547
2e59eea25fcf * image.el (create-image, find-image): Mention max-image-size in
Chong Yidong <cyd@stupidchicken.com>
parents: 65599
diff changeset
548 Image files should not be larger than specified by `max-image-size'."
25003
bb68fe3c72f8 New file.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
549 (let (image)
bb68fe3c72f8 New file.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
550 (while (and specs (null image))
bb68fe3c72f8 New file.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
551 (let* ((spec (car specs))
27073
aad0a025b1e3 (defimage): Handle specifications containing :data
Gerd Moellmann <gerd@gnu.org>
parents: 27059
diff changeset
552 (type (plist-get spec :type))
27059
6bb2a4a0413e * image.el (defimage): Images with the :data keyword should be considered valid as well.
William M. Perry <wmperry@aventail.com>
parents: 26007
diff changeset
553 (data (plist-get spec :data))
27921
ea0a2a4f20b7 (defimage): Look for image files in load-path.
Gerd Moellmann <gerd@gnu.org>
parents: 27075
diff changeset
554 (file (plist-get spec :file))
ea0a2a4f20b7 (defimage): Look for image files in load-path.
Gerd Moellmann <gerd@gnu.org>
parents: 27075
diff changeset
555 found)
27073
aad0a025b1e3 (defimage): Handle specifications containing :data
Gerd Moellmann <gerd@gnu.org>
parents: 27059
diff changeset
556 (when (image-type-available-p type)
aad0a025b1e3 (defimage): Handle specifications containing :data
Gerd Moellmann <gerd@gnu.org>
parents: 27059
diff changeset
557 (cond ((stringp file)
66296
941b6508462f (image-type-header-regexps): Rename from image-type-regexps.
Kim F. Storm <storm@cua.dk>
parents: 66196
diff changeset
558 (if (setq found (image-search-load-path file))
65544
78d74ef1436b 2005-09-15 Chong Yidong <cyd@stupidchicken.com>
Chong Yidong <cyd@stupidchicken.com>
parents: 64762
diff changeset
559 (setq image
78d74ef1436b 2005-09-15 Chong Yidong <cyd@stupidchicken.com>
Chong Yidong <cyd@stupidchicken.com>
parents: 64762
diff changeset
560 (cons 'image (plist-put (copy-sequence spec)
78d74ef1436b 2005-09-15 Chong Yidong <cyd@stupidchicken.com>
Chong Yidong <cyd@stupidchicken.com>
parents: 64762
diff changeset
561 :file found)))))
27075
893ec72bd6b1 (create-image, defimage): Don't assume image data is a
Gerd Moellmann <gerd@gnu.org>
parents: 27073
diff changeset
562 ((not (null data))
27073
aad0a025b1e3 (defimage): Handle specifications containing :data
Gerd Moellmann <gerd@gnu.org>
parents: 27059
diff changeset
563 (setq image (cons 'image spec)))))
aad0a025b1e3 (defimage): Handle specifications containing :data
Gerd Moellmann <gerd@gnu.org>
parents: 27059
diff changeset
564 (setq specs (cdr specs))))
28721
b4ea18c92e38 (find-image): New function.
Gerd Moellmann <gerd@gnu.org>
parents: 27921
diff changeset
565 image))
b4ea18c92e38 (find-image): New function.
Gerd Moellmann <gerd@gnu.org>
parents: 27921
diff changeset
566
b4ea18c92e38 (find-image): New function.
Gerd Moellmann <gerd@gnu.org>
parents: 27921
diff changeset
567
b4ea18c92e38 (find-image): New function.
Gerd Moellmann <gerd@gnu.org>
parents: 27921
diff changeset
568 ;;;###autoload
b4ea18c92e38 (find-image): New function.
Gerd Moellmann <gerd@gnu.org>
parents: 27921
diff changeset
569 (defmacro defimage (symbol specs &optional doc)
b4ea18c92e38 (find-image): New function.
Gerd Moellmann <gerd@gnu.org>
parents: 27921
diff changeset
570 "Define SYMBOL as an image.
b4ea18c92e38 (find-image): New function.
Gerd Moellmann <gerd@gnu.org>
parents: 27921
diff changeset
571
b4ea18c92e38 (find-image): New function.
Gerd Moellmann <gerd@gnu.org>
parents: 27921
diff changeset
572 SPECS is a list of image specifications. DOC is an optional
b4ea18c92e38 (find-image): New function.
Gerd Moellmann <gerd@gnu.org>
parents: 27921
diff changeset
573 documentation string.
b4ea18c92e38 (find-image): New function.
Gerd Moellmann <gerd@gnu.org>
parents: 27921
diff changeset
574
b4ea18c92e38 (find-image): New function.
Gerd Moellmann <gerd@gnu.org>
parents: 27921
diff changeset
575 Each image specification in SPECS is a property list. The contents of
b4ea18c92e38 (find-image): New function.
Gerd Moellmann <gerd@gnu.org>
parents: 27921
diff changeset
576 a specification are image type dependent. All specifications must at
b4ea18c92e38 (find-image): New function.
Gerd Moellmann <gerd@gnu.org>
parents: 27921
diff changeset
577 least contain the properties `:type TYPE' and either `:file FILE' or
b4ea18c92e38 (find-image): New function.
Gerd Moellmann <gerd@gnu.org>
parents: 27921
diff changeset
578 `:data DATA', where TYPE is a symbol specifying the image type,
b4ea18c92e38 (find-image): New function.
Gerd Moellmann <gerd@gnu.org>
parents: 27921
diff changeset
579 e.g. `xbm', FILE is the file to load the image from, and DATA is a
b4ea18c92e38 (find-image): New function.
Gerd Moellmann <gerd@gnu.org>
parents: 27921
diff changeset
580 string containing the actual image data. The first image
b4ea18c92e38 (find-image): New function.
Gerd Moellmann <gerd@gnu.org>
parents: 27921
diff changeset
581 specification whose TYPE is supported, and FILE exists, is used to
b4ea18c92e38 (find-image): New function.
Gerd Moellmann <gerd@gnu.org>
parents: 27921
diff changeset
582 define SYMBOL.
b4ea18c92e38 (find-image): New function.
Gerd Moellmann <gerd@gnu.org>
parents: 27921
diff changeset
583
b4ea18c92e38 (find-image): New function.
Gerd Moellmann <gerd@gnu.org>
parents: 27921
diff changeset
584 Example:
b4ea18c92e38 (find-image): New function.
Gerd Moellmann <gerd@gnu.org>
parents: 27921
diff changeset
585
b4ea18c92e38 (find-image): New function.
Gerd Moellmann <gerd@gnu.org>
parents: 27921
diff changeset
586 (defimage test-image ((:type xpm :file \"~/test1.xpm\")
b4ea18c92e38 (find-image): New function.
Gerd Moellmann <gerd@gnu.org>
parents: 27921
diff changeset
587 (:type xbm :file \"~/test1.xbm\")))"
66402
ade0d81f63a9 (defimage): Add `doc-string' declaration.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 66307
diff changeset
588 (declare (doc-string 3))
28721
b4ea18c92e38 (find-image): New function.
Gerd Moellmann <gerd@gnu.org>
parents: 27921
diff changeset
589 `(defvar ,symbol (find-image ',specs) ,doc))
25003
bb68fe3c72f8 New file.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
590
107360
8d9bcdbc2a6e Animated image API.
Juri Linkov <juri@jurta.org>
parents: 106815
diff changeset
591
8d9bcdbc2a6e Animated image API.
Juri Linkov <juri@jurta.org>
parents: 106815
diff changeset
592 ;;; Animated image API
25003
bb68fe3c72f8 New file.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
593
107360
8d9bcdbc2a6e Animated image API.
Juri Linkov <juri@jurta.org>
parents: 106815
diff changeset
594 (defcustom image-animate-max-time 30
8d9bcdbc2a6e Animated image API.
Juri Linkov <juri@jurta.org>
parents: 106815
diff changeset
595 "Time in seconds to animate images."
8d9bcdbc2a6e Animated image API.
Juri Linkov <juri@jurta.org>
parents: 106815
diff changeset
596 :type 'integer
107369
f2fb364fb3ba Minor animated image housekeeping.
Glenn Morris <rgm@gnu.org>
parents: 107360
diff changeset
597 :version "24.1"
107360
8d9bcdbc2a6e Animated image API.
Juri Linkov <juri@jurta.org>
parents: 106815
diff changeset
598 :group 'image)
8d9bcdbc2a6e Animated image API.
Juri Linkov <juri@jurta.org>
parents: 106815
diff changeset
599
8d9bcdbc2a6e Animated image API.
Juri Linkov <juri@jurta.org>
parents: 106815
diff changeset
600 (defconst image-animated-types '(gif)
8d9bcdbc2a6e Animated image API.
Juri Linkov <juri@jurta.org>
parents: 106815
diff changeset
601 "List of supported animated image types.")
8d9bcdbc2a6e Animated image API.
Juri Linkov <juri@jurta.org>
parents: 106815
diff changeset
602
8d9bcdbc2a6e Animated image API.
Juri Linkov <juri@jurta.org>
parents: 106815
diff changeset
603 ;;;###autoload
8d9bcdbc2a6e Animated image API.
Juri Linkov <juri@jurta.org>
parents: 106815
diff changeset
604 (defun create-animated-image (file-or-data &optional type data-p &rest props)
8d9bcdbc2a6e Animated image API.
Juri Linkov <juri@jurta.org>
parents: 106815
diff changeset
605 "Create an animated image.
8d9bcdbc2a6e Animated image API.
Juri Linkov <juri@jurta.org>
parents: 106815
diff changeset
606 FILE-OR-DATA is an image file name or image data.
8d9bcdbc2a6e Animated image API.
Juri Linkov <juri@jurta.org>
parents: 106815
diff changeset
607 Optional TYPE is a symbol describing the image type. If TYPE is omitted
8d9bcdbc2a6e Animated image API.
Juri Linkov <juri@jurta.org>
parents: 106815
diff changeset
608 or nil, try to determine the image type from its first few bytes
8d9bcdbc2a6e Animated image API.
Juri Linkov <juri@jurta.org>
parents: 106815
diff changeset
609 of image data. If that doesn't work, and FILE-OR-DATA is a file name,
8d9bcdbc2a6e Animated image API.
Juri Linkov <juri@jurta.org>
parents: 106815
diff changeset
610 use its file extension as image type.
8d9bcdbc2a6e Animated image API.
Juri Linkov <juri@jurta.org>
parents: 106815
diff changeset
611 Optional DATA-P non-nil means FILE-OR-DATA is a string containing image data.
8d9bcdbc2a6e Animated image API.
Juri Linkov <juri@jurta.org>
parents: 106815
diff changeset
612 Optional PROPS are additional image attributes to assign to the image,
8d9bcdbc2a6e Animated image API.
Juri Linkov <juri@jurta.org>
parents: 106815
diff changeset
613 like, e.g. `:mask MASK'.
8d9bcdbc2a6e Animated image API.
Juri Linkov <juri@jurta.org>
parents: 106815
diff changeset
614 Value is the image created, or nil if images of type TYPE are not supported.
8d9bcdbc2a6e Animated image API.
Juri Linkov <juri@jurta.org>
parents: 106815
diff changeset
615
8d9bcdbc2a6e Animated image API.
Juri Linkov <juri@jurta.org>
parents: 106815
diff changeset
616 Images should not be larger than specified by `max-image-size'."
8d9bcdbc2a6e Animated image API.
Juri Linkov <juri@jurta.org>
parents: 106815
diff changeset
617 (setq type (image-type file-or-data type data-p))
8d9bcdbc2a6e Animated image API.
Juri Linkov <juri@jurta.org>
parents: 106815
diff changeset
618 (when (image-type-available-p type)
8d9bcdbc2a6e Animated image API.
Juri Linkov <juri@jurta.org>
parents: 106815
diff changeset
619 (let* ((animate (memq type image-animated-types))
8d9bcdbc2a6e Animated image API.
Juri Linkov <juri@jurta.org>
parents: 106815
diff changeset
620 (image
8d9bcdbc2a6e Animated image API.
Juri Linkov <juri@jurta.org>
parents: 106815
diff changeset
621 (append (list 'image :type type (if data-p :data :file) file-or-data)
109833
5883fc00b976 create-animated-image: Don't add heuristic mask to image (Bug#6839).
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 108778
diff changeset
622 (if animate '(:index 0))
107360
8d9bcdbc2a6e Animated image API.
Juri Linkov <juri@jurta.org>
parents: 106815
diff changeset
623 props)))
8d9bcdbc2a6e Animated image API.
Juri Linkov <juri@jurta.org>
parents: 106815
diff changeset
624 (if animate
8d9bcdbc2a6e Animated image API.
Juri Linkov <juri@jurta.org>
parents: 106815
diff changeset
625 (image-animate-start image))
8d9bcdbc2a6e Animated image API.
Juri Linkov <juri@jurta.org>
parents: 106815
diff changeset
626 image)))
8d9bcdbc2a6e Animated image API.
Juri Linkov <juri@jurta.org>
parents: 106815
diff changeset
627
8d9bcdbc2a6e Animated image API.
Juri Linkov <juri@jurta.org>
parents: 106815
diff changeset
628 (defun image-animate-timer (image)
8d9bcdbc2a6e Animated image API.
Juri Linkov <juri@jurta.org>
parents: 106815
diff changeset
629 "Return the animation timer for image IMAGE."
8d9bcdbc2a6e Animated image API.
Juri Linkov <juri@jurta.org>
parents: 106815
diff changeset
630 ;; See cancel-function-timers
8d9bcdbc2a6e Animated image API.
Juri Linkov <juri@jurta.org>
parents: 106815
diff changeset
631 (let ((tail timer-list) timer)
8d9bcdbc2a6e Animated image API.
Juri Linkov <juri@jurta.org>
parents: 106815
diff changeset
632 (while tail
8d9bcdbc2a6e Animated image API.
Juri Linkov <juri@jurta.org>
parents: 106815
diff changeset
633 (setq timer (car tail)
8d9bcdbc2a6e Animated image API.
Juri Linkov <juri@jurta.org>
parents: 106815
diff changeset
634 tail (cdr tail))
8d9bcdbc2a6e Animated image API.
Juri Linkov <juri@jurta.org>
parents: 106815
diff changeset
635 (if (and (eq (aref timer 5) #'image-animate-timeout)
8d9bcdbc2a6e Animated image API.
Juri Linkov <juri@jurta.org>
parents: 106815
diff changeset
636 (consp (aref timer 6))
8d9bcdbc2a6e Animated image API.
Juri Linkov <juri@jurta.org>
parents: 106815
diff changeset
637 (eq (car (aref timer 6)) image))
8d9bcdbc2a6e Animated image API.
Juri Linkov <juri@jurta.org>
parents: 106815
diff changeset
638 (setq tail nil)
8d9bcdbc2a6e Animated image API.
Juri Linkov <juri@jurta.org>
parents: 106815
diff changeset
639 (setq timer nil)))
8d9bcdbc2a6e Animated image API.
Juri Linkov <juri@jurta.org>
parents: 106815
diff changeset
640 timer))
8d9bcdbc2a6e Animated image API.
Juri Linkov <juri@jurta.org>
parents: 106815
diff changeset
641
8d9bcdbc2a6e Animated image API.
Juri Linkov <juri@jurta.org>
parents: 106815
diff changeset
642 (defun image-animate-start (image &optional max-time)
8d9bcdbc2a6e Animated image API.
Juri Linkov <juri@jurta.org>
parents: 106815
diff changeset
643 "Start animation of image IMAGE.
8d9bcdbc2a6e Animated image API.
Juri Linkov <juri@jurta.org>
parents: 106815
diff changeset
644 Optional second arg MAX-TIME is number of seconds to animate image,
8d9bcdbc2a6e Animated image API.
Juri Linkov <juri@jurta.org>
parents: 106815
diff changeset
645 or t to animate infinitely."
8d9bcdbc2a6e Animated image API.
Juri Linkov <juri@jurta.org>
parents: 106815
diff changeset
646 (let ((anim (image-animated-p image))
8d9bcdbc2a6e Animated image API.
Juri Linkov <juri@jurta.org>
parents: 106815
diff changeset
647 timer tmo)
8d9bcdbc2a6e Animated image API.
Juri Linkov <juri@jurta.org>
parents: 106815
diff changeset
648 (when anim
8d9bcdbc2a6e Animated image API.
Juri Linkov <juri@jurta.org>
parents: 106815
diff changeset
649 (if (setq timer (image-animate-timer image))
8d9bcdbc2a6e Animated image API.
Juri Linkov <juri@jurta.org>
parents: 106815
diff changeset
650 (setcar (nthcdr 3 (aref timer 6)) max-time)
8d9bcdbc2a6e Animated image API.
Juri Linkov <juri@jurta.org>
parents: 106815
diff changeset
651 (setq tmo (* (cdr anim) 0.01))
8d9bcdbc2a6e Animated image API.
Juri Linkov <juri@jurta.org>
parents: 106815
diff changeset
652 (setq max-time (or max-time image-animate-max-time))
8d9bcdbc2a6e Animated image API.
Juri Linkov <juri@jurta.org>
parents: 106815
diff changeset
653 (run-with-timer tmo nil #'image-animate-timeout
8d9bcdbc2a6e Animated image API.
Juri Linkov <juri@jurta.org>
parents: 106815
diff changeset
654 image 1 (car anim)
8d9bcdbc2a6e Animated image API.
Juri Linkov <juri@jurta.org>
parents: 106815
diff changeset
655 (if (numberp max-time)
8d9bcdbc2a6e Animated image API.
Juri Linkov <juri@jurta.org>
parents: 106815
diff changeset
656 (- max-time tmo)
8d9bcdbc2a6e Animated image API.
Juri Linkov <juri@jurta.org>
parents: 106815
diff changeset
657 max-time))))))
8d9bcdbc2a6e Animated image API.
Juri Linkov <juri@jurta.org>
parents: 106815
diff changeset
658
8d9bcdbc2a6e Animated image API.
Juri Linkov <juri@jurta.org>
parents: 106815
diff changeset
659 (defun image-animate-stop (image)
8d9bcdbc2a6e Animated image API.
Juri Linkov <juri@jurta.org>
parents: 106815
diff changeset
660 "Stop animation of image."
8d9bcdbc2a6e Animated image API.
Juri Linkov <juri@jurta.org>
parents: 106815
diff changeset
661 (let ((timer (image-animate-timer image)))
8d9bcdbc2a6e Animated image API.
Juri Linkov <juri@jurta.org>
parents: 106815
diff changeset
662 (when timer
8d9bcdbc2a6e Animated image API.
Juri Linkov <juri@jurta.org>
parents: 106815
diff changeset
663 (cancel-timer timer))))
8d9bcdbc2a6e Animated image API.
Juri Linkov <juri@jurta.org>
parents: 106815
diff changeset
664
8d9bcdbc2a6e Animated image API.
Juri Linkov <juri@jurta.org>
parents: 106815
diff changeset
665 (defun image-animate-timeout (image ino count time-left)
8d9bcdbc2a6e Animated image API.
Juri Linkov <juri@jurta.org>
parents: 106815
diff changeset
666 (if (>= ino count)
8d9bcdbc2a6e Animated image API.
Juri Linkov <juri@jurta.org>
parents: 106815
diff changeset
667 (setq ino 0))
8d9bcdbc2a6e Animated image API.
Juri Linkov <juri@jurta.org>
parents: 106815
diff changeset
668 (plist-put (cdr image) :index ino)
8d9bcdbc2a6e Animated image API.
Juri Linkov <juri@jurta.org>
parents: 106815
diff changeset
669 (force-window-update)
8d9bcdbc2a6e Animated image API.
Juri Linkov <juri@jurta.org>
parents: 106815
diff changeset
670 (let ((anim (image-animated-p image)) tmo)
8d9bcdbc2a6e Animated image API.
Juri Linkov <juri@jurta.org>
parents: 106815
diff changeset
671 (when anim
8d9bcdbc2a6e Animated image API.
Juri Linkov <juri@jurta.org>
parents: 106815
diff changeset
672 (setq tmo (* (cdr anim) 0.01))
8d9bcdbc2a6e Animated image API.
Juri Linkov <juri@jurta.org>
parents: 106815
diff changeset
673 (unless (and (= ino 0) (numberp time-left) (< time-left tmo))
8d9bcdbc2a6e Animated image API.
Juri Linkov <juri@jurta.org>
parents: 106815
diff changeset
674 (run-with-timer tmo nil #'image-animate-timeout
8d9bcdbc2a6e Animated image API.
Juri Linkov <juri@jurta.org>
parents: 106815
diff changeset
675 image (1+ ino) count
8d9bcdbc2a6e Animated image API.
Juri Linkov <juri@jurta.org>
parents: 106815
diff changeset
676 (if (numberp time-left)
8d9bcdbc2a6e Animated image API.
Juri Linkov <juri@jurta.org>
parents: 106815
diff changeset
677 (- time-left tmo)
8d9bcdbc2a6e Animated image API.
Juri Linkov <juri@jurta.org>
parents: 106815
diff changeset
678 time-left))))))
8d9bcdbc2a6e Animated image API.
Juri Linkov <juri@jurta.org>
parents: 106815
diff changeset
679
8d9bcdbc2a6e Animated image API.
Juri Linkov <juri@jurta.org>
parents: 106815
diff changeset
680 (defun image-animated-p (image)
8d9bcdbc2a6e Animated image API.
Juri Linkov <juri@jurta.org>
parents: 106815
diff changeset
681 "Return non-nil if image is animated.
8d9bcdbc2a6e Animated image API.
Juri Linkov <juri@jurta.org>
parents: 106815
diff changeset
682 Actually, return value is a cons (IMAGES . DELAY) where IMAGES
8d9bcdbc2a6e Animated image API.
Juri Linkov <juri@jurta.org>
parents: 106815
diff changeset
683 is the number of sub-images in the animated image, and DELAY
8d9bcdbc2a6e Animated image API.
Juri Linkov <juri@jurta.org>
parents: 106815
diff changeset
684 is the delay in 100ths of a second until the next sub-image
8d9bcdbc2a6e Animated image API.
Juri Linkov <juri@jurta.org>
parents: 106815
diff changeset
685 shall be displayed."
8d9bcdbc2a6e Animated image API.
Juri Linkov <juri@jurta.org>
parents: 106815
diff changeset
686 (cond
8d9bcdbc2a6e Animated image API.
Juri Linkov <juri@jurta.org>
parents: 106815
diff changeset
687 ((eq (plist-get (cdr image) :type) 'gif)
107719
9c0ed2d6731a Rename `image-extension-data' to `image-metadata'.
Juri Linkov <juri@jurta.org>
parents: 107369
diff changeset
688 (let* ((metadata (image-metadata image))
9c0ed2d6731a Rename `image-extension-data' to `image-metadata'.
Juri Linkov <juri@jurta.org>
parents: 107369
diff changeset
689 (images (plist-get metadata 'count))
9c0ed2d6731a Rename `image-extension-data' to `image-metadata'.
Juri Linkov <juri@jurta.org>
parents: 107369
diff changeset
690 (extdata (plist-get metadata 'extension-data))
108778
6c819187f088 * image.el (image-animated-p): When delay between animated images is 0,
Juri Linkov <juri@jurta.org>
parents: 108746
diff changeset
691 (anim (plist-get extdata #xF9))
6c819187f088 * image.el (image-animated-p): When delay between animated images is 0,
Juri Linkov <juri@jurta.org>
parents: 108746
diff changeset
692 (tmo (and (integerp images) (> images 1)
6c819187f088 * image.el (image-animated-p): When delay between animated images is 0,
Juri Linkov <juri@jurta.org>
parents: 108746
diff changeset
693 (stringp anim) (>= (length anim) 4)
6c819187f088 * image.el (image-animated-p): When delay between animated images is 0,
Juri Linkov <juri@jurta.org>
parents: 108746
diff changeset
694 (+ (aref anim 1) (* (aref anim 2) 256)))))
6c819187f088 * image.el (image-animated-p): When delay between animated images is 0,
Juri Linkov <juri@jurta.org>
parents: 108746
diff changeset
695 (when tmo
6c819187f088 * image.el (image-animated-p): When delay between animated images is 0,
Juri Linkov <juri@jurta.org>
parents: 108746
diff changeset
696 (if (eq tmo 0) (setq tmo 10))
6c819187f088 * image.el (image-animated-p): When delay between animated images is 0,
Juri Linkov <juri@jurta.org>
parents: 108746
diff changeset
697 (cons images tmo))))))
107360
8d9bcdbc2a6e Animated image API.
Juri Linkov <juri@jurta.org>
parents: 106815
diff changeset
698
8d9bcdbc2a6e Animated image API.
Juri Linkov <juri@jurta.org>
parents: 106815
diff changeset
699
109861
8e0241dfb81c cosmetics, and changing of defconst to defcustom
Joakim <joakim@localhost.localdomain>
parents: 109860
diff changeset
700 (defcustom imagemagick-types-inhibit
8e0241dfb81c cosmetics, and changing of defconst to defcustom
Joakim <joakim@localhost.localdomain>
parents: 109860
diff changeset
701 '(C HTML HTM TXT PDF)
110284
60d36a04fc87 Tiny image.el fixes.
Glenn Morris <rgm@gnu.org>
parents: 110015
diff changeset
702 ;; FIXME what are the possible options?
60d36a04fc87 Tiny image.el fixes.
Glenn Morris <rgm@gnu.org>
parents: 110015
diff changeset
703 ;; Are these actually file-name extensions?
60d36a04fc87 Tiny image.el fixes.
Glenn Morris <rgm@gnu.org>
parents: 110015
diff changeset
704 ;; Why are these upper-case when eg image-types is lower-case?
60d36a04fc87 Tiny image.el fixes.
Glenn Morris <rgm@gnu.org>
parents: 110015
diff changeset
705 "Types the ImageMagick loader should not try to handle."
60d36a04fc87 Tiny image.el fixes.
Glenn Morris <rgm@gnu.org>
parents: 110015
diff changeset
706 :type '(choice (const :tag "Let ImageMagick handle all the types it can" nil)
60d36a04fc87 Tiny image.el fixes.
Glenn Morris <rgm@gnu.org>
parents: 110015
diff changeset
707 (repeat symbol))
60d36a04fc87 Tiny image.el fixes.
Glenn Morris <rgm@gnu.org>
parents: 110015
diff changeset
708 :version "24.1"
60d36a04fc87 Tiny image.el fixes.
Glenn Morris <rgm@gnu.org>
parents: 110015
diff changeset
709 :group 'image)
109849
28a8c62b8ee7 imagemagick patch5 + minor mods
joakim <joakim@exodia>
parents: 107719
diff changeset
710
28a8c62b8ee7 imagemagick patch5 + minor mods
joakim <joakim@exodia>
parents: 107719
diff changeset
711 ;;;###autoload
109853
fe07c47cf7a7 merge and fixes
Joakim <joakim@localhost.localdomain>
parents: 109849
diff changeset
712 (defun imagemagick-register-types ()
110284
60d36a04fc87 Tiny image.el fixes.
Glenn Morris <rgm@gnu.org>
parents: 110015
diff changeset
713 "Register the file types that ImageMagick is able to handle."
109858
73108272ef0b changed looping according to feedback from stefan monnier
Joakim <joakim@localhost.localdomain>
parents: 109853
diff changeset
714 (let ((im-types (imagemagick-types)))
109860
c92f5e6103a8 mostly cosmetic, moving { instances, changing indentation accordingly.
Joakim <joakim@localhost.localdomain>
parents: 109859
diff changeset
715 (dolist (im-inhibit imagemagick-types-inhibit)
109858
73108272ef0b changed looping according to feedback from stefan monnier
Joakim <joakim@localhost.localdomain>
parents: 109853
diff changeset
716 (setq im-types (remove im-inhibit im-types)))
109860
c92f5e6103a8 mostly cosmetic, moving { instances, changing indentation accordingly.
Joakim <joakim@localhost.localdomain>
parents: 109859
diff changeset
717 (dolist (im-type im-types)
109858
73108272ef0b changed looping according to feedback from stefan monnier
Joakim <joakim@localhost.localdomain>
parents: 109853
diff changeset
718 (let ((extension (downcase (symbol-name im-type))))
109849
28a8c62b8ee7 imagemagick patch5 + minor mods
joakim <joakim@exodia>
parents: 107719
diff changeset
719 (push
110284
60d36a04fc87 Tiny image.el fixes.
Glenn Morris <rgm@gnu.org>
parents: 110015
diff changeset
720 (cons (concat "\\." extension "\\'") 'image-mode)
109849
28a8c62b8ee7 imagemagick patch5 + minor mods
joakim <joakim@exodia>
parents: 107719
diff changeset
721 auto-mode-alist)
28a8c62b8ee7 imagemagick patch5 + minor mods
joakim <joakim@exodia>
parents: 107719
diff changeset
722 (push
110284
60d36a04fc87 Tiny image.el fixes.
Glenn Morris <rgm@gnu.org>
parents: 110015
diff changeset
723 (cons (concat "\\." extension "\\'") 'imagemagick)
109858
73108272ef0b changed looping according to feedback from stefan monnier
Joakim <joakim@localhost.localdomain>
parents: 109853
diff changeset
724 image-type-file-name-regexps)))))
25003
bb68fe3c72f8 New file.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
725
bb68fe3c72f8 New file.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
726 (provide 'image)
bb68fe3c72f8 New file.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
727
25872
6ae50308e8a3 Fix footer comment.
Dave Love <fx@gnu.org>
parents: 25857
diff changeset
728 ;;; image.el ends here