]> git.lyx.org Git - features.git/commitdiff
Fix JPEG format detection
authorJulien Rioux <jrioux@lyx.org>
Sat, 13 Jul 2013 14:10:27 +0000 (16:10 +0200)
committerVincent van Ravesteijn <vfr@lyx.org>
Sat, 13 Jul 2013 14:14:58 +0000 (16:14 +0200)
Detect JPEG files using the magic number FF D8 (so-called SOI marker)
instead of the string JFIF, which does not appear in all JPEG files.

src/Format.cpp

index 485715b6e3b23911d622c31897856467f748bd0e..1ee64116ff6d0a16772dafa5890326a2c8a96100 100644 (file)
@@ -206,7 +206,7 @@ string guessFormatFromContents(FileName const & fn)
        // FIG  #FIG...
        // FITS ...BITPIX...
        // GIF  GIF...
-       // JPG  JFIF
+       // JPG  \377\330...     (0xFFD8)
        // PDF  %PDF-...
        // PNG  .PNG...
        // PBM  P1... or P4     (B/W)
@@ -280,6 +280,9 @@ string guessFormatFromContents(FileName const & fn)
                        } else if (stamp == "BM") {
                                format =  "bmp";
 
+                       } else if (stamp == "\377\330") {
+                               format =  "jpg";
+
                        } else if (stamp == "\001\332") {
                                format =  "sgi";
 
@@ -335,9 +338,6 @@ string guessFormatFromContents(FileName const & fn)
                else if (contains(str, "Grace"))
                        format = "agr";
 
-               else if (contains(str, "JFIF"))
-                       format = "jpg";
-
                else if (contains(str, "%PDF"))
                        // autodetect pdf format for graphics inclusion
                        format = "pdf6";