1 ;;; mime-image.el --- mime-view filter to display images
3 ;; Copyright (C) 1995,1996,1997 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 ;; $Id: mime-image.el,v 0.11 1997-05-27 03:11:47 morioka Exp $
14 ;; Keywords: image, picture, X-Face, MIME, multimedia, mail, news
16 ;; This file is part of XEmacs.
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.
45 (defun-maybe image-inline-p (format)
46 (or (memq format image-native-formats)
49 (image-converter-chain format native)
54 (image-register-netpbm-utilities)
55 (image-register-converter 'pic 'ppm "pictoppm")
56 (image-register-converter 'mag 'ppm "magtoppm")
58 (defun bitmap-insert-xbm-file (file)
59 (let ((gl (make-glyph (list (cons 'x file))))
60 (e (make-extent (point) (point)))
62 (set-extent-end-glyph e gl)
68 (autoload 'highlight-headers "highlight-headers")
70 (defun mime-preview/x-face-function-use-highlight-headers ()
71 (highlight-headers (point-min) (re-search-forward "^$" nil t) t)
74 (add-hook 'mime-view-content-header-filter-hook
75 'mime-preview/x-face-function-use-highlight-headers)
79 ;; for MULE 2.* or mule merged EMACS
80 (require 'x-face-mule)
82 (defvar image-native-formats '(xbm))
84 (defun-maybe image-inline-p (format)
85 (memq format image-native-formats)
88 (defun-maybe image-normalize (format data)
90 (vector 'xbm ':data data)
96 (if (file-installed-p uncompface-program exec-path)
97 (add-hook 'mime-view-content-header-filter-hook
98 'x-face-decode-message-header)
102 (or (fboundp 'image-invalid-glyph-p)
103 (defsubst image-invalid-glyph-p (glyph)
104 (or (null (aref glyph 0))
105 (null (aref glyph 2))
106 (equal (aref glyph 2) "")
110 (defvar mime-view-image-converter-alist nil)
114 (let ((ctype (car rule))
117 (if (image-inline-p format)
119 (set-alist 'mime-view-content-filter-alist
121 (function mime-view-filter-for-image))
122 (set-alist 'mime-view-image-converter-alist
125 'mime-view-visible-media-type-list
129 '(("image/jpeg" . jpeg)
131 ("image/tiff" . tiff)
132 ("image/x-tiff" . tiff)
134 ("image/x-xbm" . xbm)
135 ("image/x-xpixmap" . xpm)
136 ("image/x-pic" . pic)
137 ("image/x-mag" . mag)
141 (defvar mime-view-ps-to-gif-command "pstogif")
144 ;;; @ content filter for images
146 ;; (for XEmacs 19.12 or later)
148 (defun mime-view-filter-for-image (ctype params encoding)
149 (let ((beg (point-min))
151 (remove-text-properties beg end '(face nil))
152 (message "Decoding image...")
153 (mime-decode-region beg end encoding)
154 (let* ((minor (cdr (assoc ctype mime-view-image-converter-alist)))
155 (gl (image-normalize minor (buffer-string)))
157 (delete-region (point-min)(point-max))
158 (cond ((image-invalid-glyph-p gl)
160 (message "Invalid glyph!")
162 ((eq (aref gl 0) 'xbm)
165 (expand-file-name "tm" mime-temp-directory))))
167 (write-region (point-min)(point-max) xbm-file)
168 (message "Decoding image...")
169 (delete-region (point-min)(point-max))
170 (bitmap-insert-xbm-file xbm-file)
171 (delete-file xbm-file)
173 (message "Decoding image... done")
176 (setq gl (make-glyph gl))
177 (setq e (make-extent (point) (point)))
178 (set-extent-end-glyph e gl)
179 (message "Decoding image... done")
186 ;;; @ content filter for Postscript
188 ;; (for XEmacs 19.14 or later)
190 (defun mime-view-filter-for-application/postscript (ctype params encoding)
191 (let* ((beg (point-min)) (end (point-max))
193 (make-temp-name (expand-file-name "tm" mime-temp-directory)))
194 (ps-file (concat file-base ".ps"))
195 (gif-file (concat file-base ".gif"))
197 (remove-text-properties beg end '(face nil))
198 (message "Decoding Postscript...")
199 (mime-decode-region beg end encoding)
200 (write-region (point-min)(point-max) ps-file)
201 (message "Decoding Postscript...")
202 (delete-region (point-min)(point-max))
203 (call-process mime-view-ps-to-gif-command nil nil nil ps-file)
204 (set-extent-end-glyph (make-extent (point) (point))
205 (make-glyph (vector 'gif :file gif-file)))
206 (message "Decoding Postscript... done")
207 (delete-file ps-file)
208 (delete-file gif-file)
211 (set-alist 'mime-view-content-filter-alist
212 "application/postscript"
213 (function mime-view-filter-for-application/postscript))
216 (add-to-list 'mime-view-visible-media-type-list "application/postscript")
223 (provide 'mime-image)
225 ;;; mime-image.el ends here