diff options
| author | Gerd Moellmann | 2001-08-08 10:54:12 +0000 |
|---|---|---|
| committer | Gerd Moellmann | 2001-08-08 10:54:12 +0000 |
| commit | 8a8ef149d07a98d1ddc09e60fb6edfe81b717373 (patch) | |
| tree | 43b232842105963f41253de57a44fac24232de2f | |
| parent | 057b57f6f9710e7e2a09dcb768f0e069bef16fc0 (diff) | |
| download | emacs-8a8ef149d07a98d1ddc09e60fb6edfe81b717373.tar.gz emacs-8a8ef149d07a98d1ddc09e60fb6edfe81b717373.zip | |
(image-type-regexps): Allow predicates. Change the way
JPEG images are recognized.
(image-jpeg-p): New function.
(image-type-from-data): Handle predicates in image-type-regexps.
| -rw-r--r-- | lisp/ChangeLog | 5 | ||||
| -rw-r--r-- | lisp/image.el | 36 |
2 files changed, 36 insertions, 5 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog index dd16b459da7..d314b7f29dd 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog | |||
| @@ -1,5 +1,10 @@ | |||
| 1 | 2001-08-08 Gerd Moellmann <gerd@gnu.org> | 1 | 2001-08-08 Gerd Moellmann <gerd@gnu.org> |
| 2 | 2 | ||
| 3 | * image.el (image-type-regexps): Allow predicates. Change the way | ||
| 4 | JPEG images are recognized. | ||
| 5 | (image-jpeg-p): New function. | ||
| 6 | (image-type-from-data): Handle predicates in image-type-regexps. | ||
| 7 | |||
| 3 | * emacs-lisp/edebug.el (edebug-read-function): Fix handling of | 8 | * emacs-lisp/edebug.el (edebug-read-function): Fix handling of |
| 4 | #:, #x, #o, and similar constructs. | 9 | #:, #x, #o, and similar constructs. |
| 5 | 10 | ||
diff --git a/lisp/image.el b/lisp/image.el index e0d19f5b776..9603f1ea95c 100644 --- a/lisp/image.el +++ b/lisp/image.el | |||
| @@ -34,15 +34,37 @@ | |||
| 34 | '(("\\`/\\*.*XPM.\\*/" . xpm) | 34 | '(("\\`/\\*.*XPM.\\*/" . xpm) |
| 35 | ("\\`P[1-6]" . pbm) | 35 | ("\\`P[1-6]" . pbm) |
| 36 | ("\\`GIF8" . gif) | 36 | ("\\`GIF8" . gif) |
| 37 | ;; The following is from JPEG File Interchange Format, Version 1.02. | ||
| 38 | ("\\`\xff\xd8\xff\xe0..JFIF\0" . jpeg) | ||
| 39 | ("\\`\211PNG\r\n" . png) | 37 | ("\\`\211PNG\r\n" . png) |
| 40 | ("\\`#define" . xbm) | 38 | ("\\`#define" . xbm) |
| 41 | ("\\`\\(MM\0\\*\\)\\|\\(II\\*\0\\)" . tiff) | 39 | ("\\`\\(MM\0\\*\\)\\|\\(II\\*\0\\)" . tiff) |
| 42 | ("\\`%!PS" . postscript)) | 40 | ("\\`%!PS" . postscript) |
| 41 | ("\\`\xff\xd8" . (image-jpeg-p . jpeg))) | ||
| 43 | "Alist of (REGEXP . IMAGE-TYPE) pairs used to auto-detect image types. | 42 | "Alist of (REGEXP . IMAGE-TYPE) pairs used to auto-detect image types. |
| 44 | When the first bytes of an image file match REGEXP, it is assumed to | 43 | When the first bytes of an image file match REGEXP, it is assumed to |
| 45 | be of image type IMAGE-TYPE.") | 44 | be of image type IMAGE-TYPE if IMAGE-TYPE is a symbol. If not a symbol, |
| 45 | IMAGE-TYPE must be a pair (PREDICATE . TYPE). PREDICATE is called | ||
| 46 | with one argument, a string containing the image data. If PREDICATE returns | ||
| 47 | a non-nil value, TYPE is the image's type ") | ||
| 48 | |||
| 49 | |||
| 50 | (defun image-jpeg-p (data) | ||
| 51 | "Value is non-nil if DATA, a string, consists of JFIF image data." | ||
| 52 | (when (string-match "\\`\xff\xd8" data) | ||
| 53 | (catch 'jfif | ||
| 54 | (let ((len (length data)) (i 2)) | ||
| 55 | (while (< i len) | ||
| 56 | (when (/= (aref data i) #xff) | ||
| 57 | (throw 'jfif nil)) | ||
| 58 | (setq i (1+ i)) | ||
| 59 | (when (>= (+ i 2) len) | ||
| 60 | (throw 'jfif nil)) | ||
| 61 | (let ((nbytes (+ (lsh (aref data (+ i 1)) 8) | ||
| 62 | (aref data (+ i 2))))) | ||
| 63 | (when (= (aref data i) #xe0) | ||
| 64 | ;; APP0 LEN1 LEN2 "JFIF\0" | ||
| 65 | (throw 'jfif (string-match "\\`\xe0..JFIF\0" | ||
| 66 | (substring data i (+ i 10))))) | ||
| 67 | (setq i (+ i nbytes)))))))) | ||
| 46 | 68 | ||
| 47 | 69 | ||
| 48 | ;;;###autoload | 70 | ;;;###autoload |
| @@ -55,7 +77,11 @@ be determined." | |||
| 55 | (while (and types (null type)) | 77 | (while (and types (null type)) |
| 56 | (let ((regexp (car (car types))) | 78 | (let ((regexp (car (car types))) |
| 57 | (image-type (cdr (car types)))) | 79 | (image-type (cdr (car types)))) |
| 58 | (when (string-match regexp data) | 80 | (when (or (and (symbolp image-type) |
| 81 | (string-match regexp data)) | ||
| 82 | (and (consp image-type) | ||
| 83 | (funcall (car image-type) data) | ||
| 84 | (setq image-type (cdr image-type)))) | ||
| 59 | (setq type image-type)) | 85 | (setq type image-type)) |
| 60 | (setq types (cdr types)))) | 86 | (setq types (cdr types)))) |
| 61 | type)) | 87 | type)) |