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.9 1997-03-16 01:02:03 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-preview/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)
140 (defvar mime-view-ps-to-gif-command "pstogif")
143 ;;; @ content filter for images
145 ;; (for XEmacs 19.12 or later)
147 (defun mime-preview/filter-for-image (ctype params encoding)
148 (let ((beg (point-min))
150 (remove-text-properties beg end '(face nil))
151 (message "Decoding image...")
152 (mime-decode-region beg end encoding)
153 (let* ((minor (cdr (assoc ctype mime-view-image-converter-alist)))
154 (gl (image-normalize minor (buffer-string)))
156 (delete-region (point-min)(point-max))
157 (cond ((image-invalid-glyph-p gl)
159 (message "Invalid glyph!")
161 ((eq (aref gl 0) 'xbm)
164 (expand-file-name "tm" mime-temp-directory))))
166 (write-region (point-min)(point-max) xbm-file)
167 (message "Decoding image...")
168 (delete-region (point-min)(point-max))
169 (bitmap-insert-xbm-file xbm-file)
170 (delete-file xbm-file)
172 (message "Decoding image... done")
175 (setq gl (make-glyph gl))
176 (setq e (make-extent (point) (point)))
177 (set-extent-end-glyph e gl)
178 (message "Decoding image... done")
185 ;;; @ content filter for Postscript
187 ;; (for XEmacs 19.14 or later)
189 (defun mime-preview/filter-for-application/postscript (ctype params encoding)
190 (let* ((beg (point-min)) (end (point-max))
192 (make-temp-name (expand-file-name "tm" mime-temp-directory)))
193 (ps-file (concat file-base ".ps"))
194 (gif-file (concat file-base ".gif"))
196 (remove-text-properties beg end '(face nil))
197 (message "Decoding Postscript...")
198 (mime-decode-region beg end encoding)
199 (write-region (point-min)(point-max) ps-file)
200 (message "Decoding Postscript...")
201 (delete-region (point-min)(point-max))
202 (call-process mime-view-ps-to-gif-command nil nil nil ps-file)
203 (set-extent-end-glyph (make-extent (point) (point))
204 (make-glyph (vector 'gif :file gif-file)))
205 (message "Decoding Postscript... done")
206 (delete-file ps-file)
207 (delete-file gif-file)
210 (set-alist 'mime-view-content-filter-alist
211 "application/postscript"
212 (function mime-preview/filter-for-application/postscript))
215 (add-to-list 'mime-view-visible-media-type-list "application/postscript")
222 (provide 'mime-image)
224 ;;; mime-image.el ends here