1 ;;; mime-image.el --- mime-view filter to display images
3 ;; Copyright (C) 1995,1996,1997,1998 MORIOKA Tomohiko
4 ;; Copyright (C) 1996 Dan Rich
6 ;; Author: MORIOKA Tomohiko <morioka@jaist.ac.jp>
7 ;; Dan Rich <drich@morpheus.corp.sgi.com>
8 ;; Daiki Ueno <ueno@ueda.info.waseda.ac.jp>
9 ;; Katsumi Yamaoka <yamaoka@jpl.org>
10 ;; Maintainer: MORIOKA Tomohiko <morioka@jaist.ac.jp>
11 ;; Created: 1995/12/15
12 ;; Renamed: 1997/2/21 from tm-image.el
14 ;; Keywords: image, picture, X-Face, MIME, multimedia, mail, news
16 ;; This file is part of SEMI (Showy Emacs MIME Interfaces).
18 ;; This program is free software; you can redistribute it and/or
19 ;; modify it under the terms of the GNU General Public License as
20 ;; published by the Free Software Foundation; either version 2, or (at
21 ;; your option) any later version.
23 ;; This program is distributed in the hope that it will be useful, but
24 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
25 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
26 ;; General Public License for more details.
28 ;; You should have received a copy of the GNU General Public License
29 ;; along with GNU XEmacs; see the file COPYING. If not, write to the
30 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
31 ;; Boston, MA 02111-1307, USA.
34 ;; If you use this program with MULE, please install
35 ;; etl8x16-bitmap.bdf font included in tl package.
39 (eval-when-compile (require 'static))
50 (defun-maybe image-inline-p (format)
51 (or (memq format image-native-formats)
54 (image-converter-chain format native)
59 (image-register-netpbm-utilities)
60 (image-register-converter 'pic 'ppm "pictoppm")
61 (image-register-converter 'mag 'ppm "magtoppm")
63 (defun image-insert-at-point (image)
64 (let ((e (make-extent (point) (point))))
65 (set-extent-end-glyph e (make-glyph image))))
67 (defsubst-maybe image-invalid-glyph-p (glyph)
68 (or (null (aref glyph 0))
70 (equal (aref glyph 2) "")
76 (autoload 'bitmap-insert-xbm-buffer "bitmap")
79 (static-if (fboundp 'image-type-available-p)
80 (defalias-maybe 'image-inline-p 'image-type-available-p)
81 (defvar image-native-formats '(xbm))
82 (defun-maybe image-inline-p (format)
83 (memq format image-native-formats)))
85 (defun-maybe image-normalize (format data)
86 (if (memq format '(xbm xpm))
87 (list 'image ':type format ':data data)
90 (expand-file-name "tm" temporary-file-directory))))
93 (write-region-as-binary (point-min)(point-max) image-file))
94 (list 'image ':type format ':file image-file)
97 (defun image-insert-at-point (image)
98 (static-if (fboundp 'insert-image)
101 (static-if (condition-case nil
102 (progn (insert-image '(image)) nil)
103 (wrong-number-of-arguments t))
104 (insert-image image "x")
105 (insert-image image))
107 (save-window-excursion
108 (set-window-buffer (selected-window)(current-buffer))
110 (let ((file (plist-get (cdr image) ':file)))
111 (and file (file-exists-p file)
114 (when (eq (plist-get (cdr image) ':type) 'xbm)
116 (narrow-to-region (point)(point))
117 (insert (plist-get (cdr image) ':data))
118 (let ((mark (set-marker (make-marker) (point))))
119 (bitmap-insert-xbm-buffer (current-buffer))
120 (delete-region (point-min) mark))
123 (defsubst-maybe image-invalid-glyph-p (glyph)
124 (not (eq 'image (nth 0 glyph))))
132 ((module-installed-p 'highlight-headers)
134 (autoload 'highlight-headers "highlight-headers"))
136 (defun mime-preview-x-face-function-use-highlight-headers ()
137 (highlight-headers (point-min) (re-search-forward "^$" nil t) t)
139 (add-hook 'mime-display-header-hook
140 'mime-preview-x-face-function-use-highlight-headers)
143 (require 'x-face-mule)
144 (when (exec-installed-p uncompface-program exec-path)
145 (add-hook 'mime-display-header-hook
146 'x-face-decode-message-header))
149 (defvar mime-image-format-alist
156 (image x-xpixmap xpm)
161 (dolist (rule mime-image-format-alist)
162 (let ((type (car rule))
163 (subtype (nth 1 rule))
164 (format (nth 2 rule)))
165 (when (image-inline-p format)
166 (ctree-set-calist-strictly
167 'mime-preview-condition
168 (list (cons 'type type)(cons 'subtype subtype)
170 (cons 'body-presentation-method #'mime-display-image)
171 (cons 'image-format format))
175 ;;; @ content filter for images
177 ;; (for XEmacs 19.12 or later)
180 (defmacro mime-image-normalize-xbm (entity)
182 (mime-insert-entity-content (, entity))
183 (let ((cur (current-buffer))
185 (goto-char (point-min))
186 (search-forward "width ")
187 (setq width (read cur))
188 (goto-char (point-min))
189 (search-forward "height ")
190 (setq height (read cur))
191 (goto-char (point-min))
193 (delete-region (point-min) (point))
196 (delete-region (1- (point)) (point-max))
198 (goto-char (point-min))
199 (while (re-search-forward "[^\"0-9A-FXa-fx]+" nil t)
201 (goto-char (point-min))
202 (while (search-forward "0x" nil t)
203 (replace-match "\\\\x"))
204 (goto-char (point-min))
205 (, (if (featurep 'xemacs)
206 (` (vector 'xbm :data
207 (list width height (read cur))))
208 '(` (image :type xbm :width (, width) :height (, height)
209 :data (, (read cur))))))))))
212 (defun mime-display-image (entity situation)
213 (message "Decoding image...")
214 (let* ((format (cdr (assq 'image-format situation)))
215 (image (if (or (featurep 'xemacs) (boundp 'image-types))
217 (mime-image-normalize-xbm entity)
218 (image-normalize format (mime-entity-content entity)))
219 (image-normalize format (mime-entity-content entity)))))
220 (if (image-invalid-glyph-p image)
221 (message "Invalid glyph!")
222 (image-insert-at-point image)
223 (message "Decoding image... done")))
224 (static-when (featurep 'xemacs)
231 (provide 'mime-image)
233 ;;; mime-image.el ends here