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 ;; Maintainer: MORIOKA Tomohiko <morioka@jaist.ac.jp>
10 ;; Renamed: 1997/2/21 from tm-image.el
12 ;; Keywords: image, picture, X-Face, MIME, multimedia, mail, news
14 ;; This file is part of SEMI (Suite of Emacs MIME Interfaces).
16 ;; This program is free software; you can redistribute it and/or
17 ;; modify it under the terms of the GNU General Public License as
18 ;; published by the Free Software Foundation; either version 2, or (at
19 ;; your option) any later version.
21 ;; This program is distributed in the hope that it will be useful, but
22 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
23 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
24 ;; General Public License for more details.
26 ;; You should have received a copy of the GNU General Public License
27 ;; along with GNU XEmacs; see the file COPYING. If not, write to the
28 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
29 ;; Boston, MA 02111-1307, USA.
32 ;; If you use this program with MULE, please install
33 ;; etl8x16-bitmap.bdf font included in tl package.
40 (cond ((featurep 'xemacs)
43 (defun-maybe image-inline-p (format)
44 (or (memq format image-native-formats)
47 (image-converter-chain format native)
52 (image-register-netpbm-utilities)
53 (image-register-converter 'pic 'ppm "pictoppm")
54 (image-register-converter 'mag 'ppm "magtoppm")
56 (defun bitmap-insert-xbm-file (file)
57 (let ((gl (make-glyph (list (cons 'x file))))
58 (e (make-extent (point) (point)))
60 (set-extent-end-glyph e gl)
66 (autoload 'highlight-headers "highlight-headers")
68 (defun mime-preview-x-face-function-use-highlight-headers ()
69 (highlight-headers (point-min) (re-search-forward "^$" nil t) t)
72 (add-hook 'mime-view-content-header-filter-hook
73 'mime-preview-x-face-function-use-highlight-headers)
77 ;; for MULE 2.* or mule merged EMACS
78 (require 'x-face-mule)
80 (defvar image-native-formats '(xbm))
82 (defun-maybe image-inline-p (format)
83 (memq format image-native-formats)
86 (defun-maybe image-normalize (format data)
88 (vector 'xbm ':data data)
94 (if (exec-installed-p uncompface-program exec-path)
95 (add-hook 'mime-view-content-header-filter-hook
96 'x-face-decode-message-header)
100 (or (fboundp 'image-invalid-glyph-p)
101 (defsubst image-invalid-glyph-p (glyph)
102 (or (null (aref glyph 0))
103 (null (aref glyph 2))
104 (equal (aref glyph 2) "")
108 (defvar mime-view-image-converter-alist nil)
112 (let ((ctype (car rule))
115 (if (image-inline-p format)
117 (set-alist 'mime-view-content-filter-alist
119 (function mime-view-filter-for-image))
120 (set-alist 'mime-view-image-converter-alist
123 'mime-view-visible-media-type-list
127 '(("image/jpeg" . jpeg)
129 ("image/tiff" . tiff)
130 ("image/x-tiff" . tiff)
132 ("image/x-xbm" . xbm)
133 ("image/x-xpixmap" . xpm)
134 ("image/x-pic" . pic)
135 ("image/x-mag" . mag)
139 (defvar mime-view-ps-to-gif-command "pstogif")
142 ;;; @ content filter for images
144 ;; (for XEmacs 19.12 or later)
146 (defun mime-view-filter-for-image (ctype params encoding)
147 (let ((beg (point-min))
149 (remove-text-properties beg end '(face nil))
150 (message "Decoding image...")
151 (mime-decode-region beg end encoding)
152 (let* ((minor (cdr (assoc ctype mime-view-image-converter-alist)))
153 (gl (image-normalize minor (buffer-string)))
155 (delete-region (point-min)(point-max))
156 (cond ((image-invalid-glyph-p gl)
158 (message "Invalid glyph!")
160 ((eq (aref gl 0) 'xbm)
163 (expand-file-name "tm" mime-temp-directory))))
165 (write-region (point-min)(point-max) xbm-file)
166 (message "Decoding image...")
167 (delete-region (point-min)(point-max))
168 (bitmap-insert-xbm-file xbm-file)
169 (delete-file xbm-file)
171 (message "Decoding image... done")
174 (setq gl (make-glyph gl))
175 (setq e (make-extent (point) (point)))
176 (set-extent-end-glyph e gl)
177 (message "Decoding image... done")
184 ;;; @ content filter for Postscript
186 ;; (for XEmacs 19.14 or later)
188 (defun mime-view-filter-for-application/postscript (ctype params encoding)
189 (let* ((beg (point-min)) (end (point-max))
191 (make-temp-name (expand-file-name "tm" mime-temp-directory)))
192 (ps-file (concat file-base ".ps"))
193 (gif-file (concat file-base ".gif"))
195 (remove-text-properties beg end '(face nil))
196 (message "Decoding Postscript...")
197 (mime-decode-region beg end encoding)
198 (write-region (point-min)(point-max) ps-file)
199 (message "Decoding Postscript...")
200 (delete-region (point-min)(point-max))
201 (call-process mime-view-ps-to-gif-command nil nil nil ps-file)
202 (set-extent-end-glyph (make-extent (point) (point))
203 (make-glyph (vector 'gif :file gif-file)))
204 (message "Decoding Postscript... done")
205 (delete-file ps-file)
206 (delete-file gif-file)
209 ;; If you would like to display inline Postscript image, please
210 ;; activate following:
212 ;; (set-alist 'mime-view-content-filter-alist
213 ;; "application/postscript"
214 ;; (function mime-view-filter-for-application/postscript))
216 ;; (if (featurep 'gif)
218 ;; 'mime-view-visible-media-type-list "application/postscript")
225 (provide 'mime-image)
227 ;;; mime-image.el ends here