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 ;; Created: 1995/12/15
11 ;; Renamed: 1997/2/21 from tm-image.el
13 ;; Keywords: image, picture, X-Face, MIME, multimedia, mail, news
15 ;; This file is part of SEMI (Showy Emacs MIME Interfaces).
17 ;; This program is free software; you can redistribute it and/or
18 ;; modify it under the terms of the GNU General Public License as
19 ;; published by the Free Software Foundation; either version 2, or (at
20 ;; your option) any later version.
22 ;; This program is distributed in the hope that it will be useful, but
23 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
24 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
25 ;; General Public License for more details.
27 ;; You should have received a copy of the GNU General Public License
28 ;; along with GNU XEmacs; see the file COPYING. If not, write to the
29 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
30 ;; Boston, MA 02111-1307, USA.
33 ;; If you use this program with MULE, please install
34 ;; etl8x16-bitmap.bdf font included in tl package.
38 (eval-when-compile (require 'cl))
40 (eval-when-compile (require 'static))
46 (defsubst mime-image-normalize-xbm-buffer (buffer)
49 (let ((case-fold-search t) width height xbytes right margin)
50 (goto-char (point-min))
51 (or (re-search-forward "_width[\t ]+\\([0-9]+\\)" nil t)
52 (error "!! Illegal xbm file format in the buffer: %s"
54 (setq width (string-to-int (match-string 1))
55 xbytes (/ (+ width 7) 8))
56 (goto-char (point-min))
57 (or (re-search-forward "_height[\t ]+\\([0-9]+\\)" nil t)
58 (error "!! Illegal xbm file format in the buffer: %s"
60 (setq height (string-to-int (match-string 1)))
61 (goto-char (point-min))
62 (re-search-forward "0x[0-9a-f][0-9a-f],")
63 (delete-region (point-min) (match-beginning 0))
64 (goto-char (point-min))
65 (while (re-search-forward "[\n\r\t ,;}]" nil t)
67 (goto-char (point-min))
68 (while (re-search-forward "0x" nil t)
69 (replace-match "\\x" nil t))
70 (goto-char (point-min))
71 (insert "(" (number-to-string width) " "
72 (number-to-string height) " \"")
73 (goto-char (point-max))
75 (goto-char (point-min))
76 (read (current-buffer)))))
78 (static-if (featurep 'xemacs)
80 (defun mime-image-type-available-p (type)
81 (memq type (image-instantiator-format-list)))
83 (defun mime-image-create (file-or-data &optional type data-p &rest props)
84 (when (and data-p (eq type 'xbm))
88 (mime-image-normalize-xbm-buffer (current-buffer)))))
91 (if (and type (mime-image-type-available-p type))
93 (list type (if data-p :data :file) file-or-data)
96 (if (nothing-image-instance-p (glyph-image-instance glyph)) nil
99 (defun mime-image-insert (image &optional string area)
100 (let ((extent (make-extent (point)
104 (set-extent-property extent 'invisible t)
105 (set-extent-end-glyph extent image))))
109 (defalias 'mime-image-type-available-p 'image-type-available-p)
110 (defun mime-image-create
111 (file-or-data &optional type data-p &rest props)
112 (if (and data-p (eq type 'xbm))
114 (insert file-or-data)
116 (mime-image-normalize-xbm-buffer (current-buffer)))
117 (apply #'create-image (nth 2 file-or-data) type data-p
119 (list :width (car file-or-data)
120 :height (nth 1 file-or-data))
122 (apply #'create-image file-or-data type data-p props)))
123 (defalias 'mime-image-insert 'insert-image))
127 (require (if (featurep 'mule) 'bitmap ""))
128 (defun mime-image-read-xbm-buffer (buffer)
130 (mapconcat #'bitmap-compose
131 (append (bitmap-decode-xbm
132 (bitmap-read-xbm-buffer
133 (current-buffer))) nil) "\n")
135 (defun mime-image-insert (image &optional string area)
138 (defalias 'mime-image-read-xbm-buffer
139 'mime-image-normalize-xbm-buffer)
140 (defun mime-image-insert (image &optional string area)
142 (narrow-to-region (point)(point))
143 (let ((face (gensym "mii")))
144 (or (facep face) (make-face face))
145 (set-face-stipple face image)
146 (let ((row (make-string (/ (car image) (frame-char-width)) ? ))
147 (height (/ (nth 1 image) (frame-char-height)))
150 (set-text-properties (point) (progn (insert row)(point))
153 (setq i (1+ i)))))))))
155 (defun mime-image-type-available-p (type)
158 (defun mime-image-create (file-or-data &optional type data-p &rest props)
159 (when (or (null type) (eq type 'xbm))
162 (insert file-or-data)
163 (insert-file-contents file-or-data))
164 (mime-image-read-xbm-buffer (current-buffer))))))))
166 (defvar mime-image-format-alist
173 (image x-xpixmap xpm)
176 (dolist (rule mime-image-format-alist)
177 (when (mime-image-type-available-p (nth 2 rule))
178 (ctree-set-calist-strictly
179 'mime-preview-condition
180 (list (cons 'type (car rule))(cons 'subtype (nth 1 rule))
182 (cons 'body-presentation-method #'mime-display-image)
183 (cons 'image-format (nth 2 rule))))))
186 ;;; @ content filter for images
188 ;; (for XEmacs 19.12 or later)
190 (defun mime-display-image (entity situation)
191 (message "Decoding image...")
193 (let ((format (cdr (assq 'image-format situation)))
196 (mime-image-create (mime-entity-content entity)
199 (message "Invalid glyph!")
201 (mime-image-insert image)
203 (message "Decoding image...done"))))
210 (provide 'mime-image)
212 ;;; mime-image.el ends here