[Top][All Lists]

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

Re: using libmagic in Emacs?

From: Juri Linkov
Subject: Re: using libmagic in Emacs?
Date: Tue, 25 Aug 2009 23:36:04 +0300
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1.50 (x86_64-pc-linux-gnu)

>     The problem is that `image-jpeg-p' in image.el refuses to accept
>     non-JFIF JPEG image files whereas Emacs can correctly display them
>     when tests in `image-jpeg-p' are ignored.
>     Using libmagic means looking only for 2 bytes 0xffd8 (a magic number
>     of JPEG files) as described by the magic number file:
>       0       beshort         0xffd8          JPEG image data
>     It seems this is enough to determine JPEG files.  But I'm not confident
>     about removing additional tests from `image-jpeg-p'.  We could keep the
>     current rules in image.el as a fall-back when libmagic is not available.
> Whatever we do with the function `image-jpeg-p', we could easily make
> Emacs test these two bytes.  It makes no sense to install code to link
> with libmagic just to handle that and a few other similar things.

The following patch changes `image-type-header-regexps' to test only
two bytes of the JPEG magic number:

Index: lisp/image.el
RCS file: /sources/emacs/emacs/lisp/image.el,v
retrieving revision 1.87
diff -u -r1.87 image.el
--- lisp/image.el       24 Feb 2009 10:29:00 -0000      1.87
+++ lisp/image.el       25 Aug 2009 20:33:16 -0000
@@ -43,7 +43,7 @@
 static \\(unsigned \\)?char \\1_bits" . xbm)
     ("\\`\\(?:MM\0\\*\\|II\\*\0\\)" . tiff)
     ("\\`[\t\n\r ]*%!PS" . postscript)
-    ("\\`\xff\xd8" . (image-jpeg-p . jpeg))
+    ("\\`\xff\xd8" . jpeg)
     (,(let* ((incomment-re "\\(?:[^-]\\|-[^-]\\)")
             (comment-re (concat "\\(?:!--" incomment-re "*-->[ \t\r\n]*<\\)")))
        (concat "\\(?:<\\?xml[ \t\r\n]+[^>]*>\\)?[ \t\r\n]*<"

Juri Linkov

reply via email to

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