[gegl] operations/core/load: Detect local ARWs and CR2s as RAW, not TIFF



commit 80d6967f3202bd724421a4b457c8ff84ab3e1960
Author: Debarshi Ray <debarshir gnome org>
Date:   Fri Feb 3 02:10:26 2017 +0100

    operations/core/load: Detect local ARWs and CR2s as RAW, not TIFF
    
    This changes the content type guessing for local paths to match the
    logic in GLib so that our interpretation of the content matches with
    those of other components. We need to first look at the filename and
    sniff the content only if it is inconclusive.
    
    The code path dealing with URIs wasn't touched because the impact
    wasn't clear.
    
    Fallout from 442f6832701c4fba63a3564e6dd5ff1b9583a3a6
    
    https://bugzilla.gnome.org/show_bug.cgi?id=771961

 operations/core/load.c |   79 +++++++++++++++++++++++++++++++++++-------------
 1 files changed, 58 insertions(+), 21 deletions(-)
---
diff --git a/operations/core/load.c b/operations/core/load.c
index bb44bd5..6c528d3 100644
--- a/operations/core/load.c
+++ b/operations/core/load.c
@@ -168,33 +168,70 @@ do_setup (GeglOperation *operation, const gchar *path, const gchar *uri)
 
   g_assert (stream != NULL);
 
-  if (!read_from_stream (stream, &buffer, &size, &error))
+  if (load_from_uri)
     {
-      g_warning ("%s", error->message);
-      g_clear_error (&error);
-      goto cleanup;
+      if (!read_from_stream (stream, &buffer, &size, &error))
+        {
+          g_warning ("%s", error->message);
+          g_clear_error (&error);
+          goto cleanup;
+        }
+
+      content_type = g_content_type_guess (NULL, buffer, size, &uncertain);
+      if ((!g_str_has_prefix (content_type, "image/") &&
+           !g_str_has_prefix (content_type, ".")) || uncertain)
+        {
+          g_free (content_type);
+
+          if (gegl_gio_uri_is_datauri (uri))
+            {
+              content_type = gegl_gio_datauri_get_content_type (uri);
+            }
+          else
+            {
+              content_type = g_content_type_guess (filename,
+                                                   buffer,
+                                                   size,
+                                                   NULL);
+            }
+        }
+    }
+  else
+    {
+      /* This should match the logic in glib/gio/glocalfileinfo.c for local
+       * files. Otherwise, our interpretation of the content won't match
+       * with those of other components. Contrary to what we might expect,
+       * GLib first looks at the filename, and sniffs the content only
+       * if it is inconclusive.
+       */
+
+      content_type = g_content_type_guess (filename, NULL, 0, &uncertain);
+      if ((!g_str_has_prefix (content_type, "image/") &&
+           !g_str_has_prefix (content_type, ".")) || uncertain)
+        {
+          g_free (content_type);
+
+          if (!read_from_stream (stream, &buffer, &size, &error))
+            {
+              g_warning ("%s", error->message);
+              g_clear_error (&error);
+              goto cleanup;
+            }
+
+          content_type = g_content_type_guess (filename, buffer, size, NULL);
+        }
     }
 
-  content_type = g_content_type_guess (NULL, buffer, size, &uncertain);
-  if ((!g_str_has_prefix (content_type, "image/") &&
-       !g_str_has_prefix (content_type, ".")) || uncertain)
+  if (!gegl_gio_uri_is_datauri (uri) &&
+      !g_str_has_prefix (content_type, "image/") &&
+      !g_str_has_prefix (content_type, "."))
     {
       g_free (content_type);
-      if (load_from_uri && gegl_gio_uri_is_datauri (uri))
-        content_type = gegl_gio_datauri_get_content_type (uri);
+
+      if (g_strrstr (filename, ".") != NULL)
+        content_type = g_strdup (g_strrstr (filename, "."));
       else
-      {
-        content_type = g_content_type_guess (filename, buffer, size, NULL);
-        if (!g_str_has_prefix (content_type, "image/") &&
-            !g_str_has_prefix (content_type, "."))
-          {
-            g_free (content_type);
-            if (g_strrstr (filename, ".") != NULL)
-              content_type = g_strdup (g_strrstr (filename, "."));
-            else
-              content_type = NULL;
-          }
-      }
+        content_type = NULL;
     }
 
   handler = gegl_operation_handlers_get_loader (content_type);


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