[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Exif JPEG files

From: Alex Schroeder
Subject: Exif JPEG files
Date: Sat, 22 Feb 2003 14:29:26 +0100
User-agent: Gnus/5.090016 (Oort Gnus v0.16) Emacs/21.2.92

Emacs cannot read JPG files from my digital camera, because they are
not JFIF files but EXIF files.  Here is the file output for two
different images:

~/pics $ file alex-face.jpg
alex-face.jpg: JPEG image data, JFIF standard 1.01, resolution (DPI), "Created 
with The GIMPÿÛ", 72 x 72
~/pics $ file 2003-02-22/cimg0012.jpg
2003-02-22/cimg0012.jpg: JPEG image data, EXIF standard 0.77, 42 x 0

The trivial fix for me was to change the regexp in string-match of

(defun image-jpeg-p (data)
  "Value is non-nil if DATA, a string, consists of JFIF or Exif image data."
  (when (string-match "\\`\xff\xd8" data)
    (catch 'jpeg
      (let ((len (length data)) (i 2))
        (while (< i len)
          (when (/= (aref data i) #xff)
            (throw 'jpeg nil))
          (setq i (1+ i))
          (when (>= (+ i 2) len)
            (throw 'jpeg nil))
          (let ((nbytes (+ (lsh (aref data (+ i 1)) 8)
                           (aref data (+ i 2))))
                (code (aref data i)))
            (when (and (>= code #xe0) (<= code #xef))
              ;; APP0 LEN1 LEN2 "JFIF\0"
              (throw 'jpeg 
                     (string-match "JFIF\\|Exif"
                                   (substring data i (+ i nbytes)))))
            (setq i (+ i 1 nbytes))))))))

The beginning of data looks like this, where I have replaced ^@ with "^@":

(substring data 0 19)

I must confess that I don't really understand the innermost let,
though:  i is 3, nbytes is 36024, and code is 225.  (lenth data) is
77773.  Do we really have to scan the entire first half of the file?

Anyway, the above changes work for me.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]