[shotwell] JPEG sniffer to recognize all possible SOFn marker



commit e5d8222947ce84b2b11b1549e4c181eb0afb6c9d
Author: Jens Georg <mail jensge org>
Date:   Mon Feb 17 20:52:58 2020 +0100

    JPEG sniffer to recognize all possible SOFn marker
    
    Turn's out there's more than just SOF0 (FFC0) - wonder how I could miss
    that in the document I used.
    
    Fixes #211

 src/photos/JfifSupport.vala | 15 ++++++++++++---
 1 file changed, 12 insertions(+), 3 deletions(-)
---
diff --git a/src/photos/JfifSupport.vala b/src/photos/JfifSupport.vala
index c9b687d8..05b7de9a 100644
--- a/src/photos/JfifSupport.vala
+++ b/src/photos/JfifSupport.vala
@@ -145,12 +145,12 @@ public class JfifSniffer : GdkSniffer {
         }
 
         length = Jpeg.read_marker_2(dins, out marker);
-        while (marker != Jpeg.Marker.SOF && length > 0) {
+        while (!marker.is_sof() && length > 0) {
             (dins as Seekable).seek(length, SeekType.CUR, null);
             length = Jpeg.read_marker_2(dins, out marker);
         }
 
-        if (marker == SOF) {
+        if (marker.is_sof()) {
             if (length < 6) {
                 is_corrupted = true;
                 return null;
@@ -212,7 +212,6 @@ namespace Jpeg {
         
         SOI = 0xD8,
         EOI = 0xD9,
-        SOF = 0xC0,
         
         APP0 = 0xE0,
         APP1 = 0xE1;
@@ -220,6 +219,16 @@ namespace Jpeg {
         public uint8 get_byte() {
             return (uint8) this;
         }
+
+        public bool is_sof() {
+            // FFCn is SOF unless n is a multiple of 4 > 0 (FFC4, FFC8, FFCC)
+            if ((this & 0xC0) != 0xC0) {
+                return false;
+            }
+
+            var variant = this & 0x0F;
+            return variant == 0 || variant % 4 != 0;
+        }
     }
     
     public enum Quality {


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