Changeset 3001

Show
Ignore:
Timestamp:
02/19/03 20:12:19 (6 years ago)
Author:
miyoshi
Message:

(image-type-from-file-header): Make temporary buffer
unibyte. This code is imported from emacs-21.3.50.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • work/cvs2svn/lisp/ChangeLog.Meadow

    r2990 r3001  
     12003-02-19  MIYOSHI Masanori  <miyoshi@boreas.dti.ne.jp> 
     2 
     3        * image.el (image-type-from-file-header): Make temporary buffer 
     4        unibyte. This code is imported from emacs-21.3.50. 
     5 
    162003-02-12  MIYOSHI Masanori  <miyoshi@boreas.dti.ne.jp> 
    27 
  • work/cvs2svn/lisp/image.el

    r2403 r3001  
    3232 
    3333(defconst image-type-regexps 
    34   '(("^/\\*.*XPM.\\*/" . xpm) 
    35     ("^P[1-6]" . pbm) 
    36     ("^GIF8" . gif) 
    37     ("JFIF" . jpeg) 
    38     ("^\211PNG\r\n" . png
    39     ("^#define" . xbm
    40     ("^\\(MM\0\\*\\)\\|\\(II\\*\0\\)" . tiff
    41     ("^%!PS" . postscript)) 
     34  '(("\\`/[\t\n\r ]*\\*.*XPM.\\*/" . xpm) 
     35    ("\\`P[1-6]" . pbm) 
     36    ("\\`GIF8" . gif) 
     37    ("\\`\211PNG\r\n" . png) 
     38    ("\\`[\t\n\r ]*#define" . xbm
     39    ("\\`\\(MM\0\\*\\|II\\*\0\\)" . tiff
     40    ("\\`[\t\n\r ]*%!PS" . postscript
     41    ("\\`\xff\xd8" . (image-jpeg-p . jpeg))) 
    4242  "Alist of (REGEXP . IMAGE-TYPE) pairs used to auto-detect image types. 
    4343When the first bytes of an image file match REGEXP, it is assumed to 
    44 be of image type IMAGE-TYPE.") 
     44be of image type IMAGE-TYPE if IMAGE-TYPE is a symbol.  If not a symbol, 
     45IMAGE-TYPE must be a pair (PREDICATE . TYPE).  PREDICATE is called 
     46with one argument, a string containing the image data.  If PREDICATE returns 
     47a 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                (code (aref data i))) 
     64            (when (and (>= code #xe0) (<= code #xef)) 
     65              ;; APP0 LEN1 LEN2 "JFIF\0" 
     66              (throw 'jfif  
     67                     (string-match "JFIF" (substring data i (+ i nbytes))))) 
     68            (setq i (+ i 1 nbytes)))))))) 
    4569 
    4670 
     
    5579      (let ((regexp (car (car types))) 
    5680            (image-type (cdr (car types)))) 
    57         (when (string-match regexp data) 
     81        (when (or (and (symbolp image-type) 
     82                       (string-match regexp data)) 
     83                  (and (consp image-type) 
     84                       (funcall (car image-type) data) 
     85                       (setq image-type (cdr image-type)))) 
    5886          (setq type image-type)) 
    5987        (setq types (cdr types)))) 
     
    7098  (setq file (expand-file-name file)) 
    7199  (let ((header (with-temp-buffer 
     100                  (set-buffer-multibyte nil) 
    72101                  (insert-file-contents-literally file nil 0 256) 
    73102                  (buffer-string))))