unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* Exif JPEG files
@ 2003-02-22 13:29 Alex Schroeder
  0 siblings, 0 replies; only message in thread
From: Alex Schroeder @ 2003-02-22 13:29 UTC (permalink / raw)


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
image-jpeg-p:

(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)
"\377\330\377\341\214\270Exif^@^@MM^@*^@^@^@"

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.

Alex.

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2003-02-22 13:29 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2003-02-22 13:29 Exif JPEG files Alex Schroeder

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).