[gegl] handlers: Register MIME types for loaders



commit 8c940a9730a009340462d33cca4a45dd0a05d736
Author: Martin Blanchard <tchaik gmx com>
Date:   Fri Jan 15 22:25:14 2016 +0100

    handlers: Register MIME types for loaders
    
    Register MIME types together with filename's extension for
    image file loading operations. Port entire GEGL to the new
    gegl_operation_handlers_* API. gegl:jp2-load now detects '.jpf'
    files, gegl:jpg-save now recognise '.jpeg' filenames.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=760493

 operations/common/gegl-buffer-load-op.c |    3 +-
 operations/common/gegl-buffer-save-op.c |    3 +-
 operations/common/save.c                |    2 +-
 operations/core/load.c                  |    4 +-
 operations/external/exr-load.cpp        |    5 ++-
 operations/external/exr-save.cc         |    3 +-
 operations/external/jp2-load.c          |   10 +++++-
 operations/external/jpg-load.c          |    8 ++++-
 operations/external/jpg-save.c          |    5 ++-
 operations/external/npy-save.c          |    3 +-
 operations/external/png-load.c          |    5 ++-
 operations/external/png-save.c          |    3 +-
 operations/external/ppm-load.c          |   17 +++++++++--
 operations/external/ppm-save.c          |    3 +-
 operations/external/raw-load.c          |   48 +++++++++++++++++++++++++------
 operations/external/rgbe-load.c         |    8 ++++-
 operations/external/rgbe-save.c         |    6 ++-
 operations/external/svg-load.c          |   11 ++++++-
 operations/external/tiff-load.c         |   10 +++++-
 operations/external/tiff-save.c         |    6 ++-
 operations/external/webp-load.c         |    5 ++-
 operations/external/webp-save.c         |    3 +-
 operations/workshop/rawbayer-load.c     |    6 ++-
 tests/simple/test-misc.c                |   37 ++++++++++++++++++-----
 24 files changed, 164 insertions(+), 50 deletions(-)
---
diff --git a/operations/common/gegl-buffer-load-op.c b/operations/common/gegl-buffer-load-op.c
index cc05860..65bafd6 100644
--- a/operations/common/gegl-buffer-load-op.c
+++ b/operations/common/gegl-buffer-load-op.c
@@ -89,7 +89,8 @@ gegl_op_class_init (GeglOpClass *klass)
     "description", _("GeglBuffer file loader."),
     NULL);
 
-  gegl_extension_handler_register_loader (".gegl", "gegl:gegl-buffer-load");
+  gegl_operation_handlers_register_loader (
+    ".gegl", "gegl:gegl-buffer-load");
 }
 
 #endif
diff --git a/operations/common/gegl-buffer-save-op.c b/operations/common/gegl-buffer-save-op.c
index 2198618..9590e00 100644
--- a/operations/common/gegl-buffer-save-op.c
+++ b/operations/common/gegl-buffer-save-op.c
@@ -63,7 +63,8 @@ gegl_op_class_init (GeglOpClass *klass)
     "description", _("GeglBuffer file writer."),
     NULL);
 
-  gegl_extension_handler_register_saver (".gegl", "gegl:gegl-buffer-save");
+  gegl_operation_handlers_register_saver (
+    ".gegl", "gegl:gegl-buffer-save");
 }
 
 #endif
diff --git a/operations/common/save.c b/operations/common/save.c
index 1c78c43..725be4f 100644
--- a/operations/common/save.c
+++ b/operations/common/save.c
@@ -73,7 +73,7 @@ gegl_save_set_saver (GeglOperation *operation)
    */
   g_assert (o->path);
   extension = strrchr (o->path, '.');
-  handler   = extension ? gegl_extension_handler_get_saver (extension) : NULL;
+  handler   = extension ? gegl_operation_handlers_get_saver (extension) : NULL;
 
   if (handler)
     {
diff --git a/operations/core/load.c b/operations/core/load.c
index 8689cfa..93416eb 100644
--- a/operations/core/load.c
+++ b/operations/core/load.c
@@ -88,7 +88,7 @@ do_setup (GeglOperation *operation, const gchar *new_path, const gchar *new_uri)
             extension = g_strdup(strrchr (new_uri, '.'));
 
         if (extension)
-            handler = gegl_extension_handler_get_loader (extension);
+            handler = gegl_operation_handlers_get_loader (extension);
         gegl_node_set (self->load, "operation", handler, NULL);
         gegl_node_set (self->load, "uri", new_uri, NULL);
 
@@ -121,7 +121,7 @@ do_setup (GeglOperation *operation, const gchar *new_path, const gchar *new_uri)
         else
         {
           if (extension)
-            handler = gegl_extension_handler_get_loader (extension);
+            handler = gegl_operation_handlers_get_loader (extension);
           gegl_node_set (self->load,
                          "operation", handler,
                          NULL);
diff --git a/operations/external/exr-load.cpp b/operations/external/exr-load.cpp
index 4183d9c..16e634f 100644
--- a/operations/external/exr-load.cpp
+++ b/operations/external/exr-load.cpp
@@ -684,7 +684,10 @@ gegl_op_class_init (GeglOpClass *klass)
     "categories"  , "hidden",
     "description" , "EXR image loader.", NULL);
 
-  gegl_extension_handler_register_loader (".exr", "gegl:exr-load");
+  gegl_operation_handlers_register_loader (
+    "image/x-exr", "gegl:exr-load");
+  gegl_operation_handlers_register_loader (
+    ".exr", "gegl:exr-load");
 }
 
 #endif
diff --git a/operations/external/exr-save.cc b/operations/external/exr-save.cc
index 873e1a6..70df96f 100644
--- a/operations/external/exr-save.cc
+++ b/operations/external/exr-save.cc
@@ -254,7 +254,8 @@ static void gegl_op_class_init (GeglOpClass *klass)
     "description" , "OpenEXR image saver",
     NULL);
 
-  gegl_extension_handler_register_saver (".exr", "gegl:exr-save");
+  gegl_operation_handlers_register_saver (
+    ".exr", "gegl:exr-save");
 }
 
 #endif
diff --git a/operations/external/jp2-load.c b/operations/external/jp2-load.c
index 8d8f366..6f6a68a 100644
--- a/operations/external/jp2-load.c
+++ b/operations/external/jp2-load.c
@@ -532,8 +532,14 @@ gegl_op_class_init (GeglOpClass *klass)
     "description", _("JPEG 2000 image loader using jasper."),
     NULL);
 
-  gegl_extension_handler_register_loader (".jp2", "gegl:jp2-load");
-  gegl_extension_handler_register_loader (".jpx", "gegl:jp2-load");
+  gegl_operation_handlers_register_loader (
+    "image/jp2", "gegl:jp2-load");
+  gegl_operation_handlers_register_loader (
+    ".jp2", "gegl:jp2-load");
+  gegl_operation_handlers_register_loader (
+    ".jpf", "gegl:jp2-load");
+  gegl_operation_handlers_register_loader (
+    ".jpx", "gegl:jp2-load");
 }
 
 #endif
diff --git a/operations/external/jpg-load.c b/operations/external/jpg-load.c
index 80cfc35..85f5b60 100644
--- a/operations/external/jpg-load.c
+++ b/operations/external/jpg-load.c
@@ -370,8 +370,12 @@ gegl_op_class_init (GeglOpClass *klass)
 /*  static gboolean done=FALSE;
     if (done)
       return; */
-  gegl_extension_handler_register_loader (".jpg", "gegl:jpg-load");
-  gegl_extension_handler_register_loader (".jpeg", "gegl:jpg-load");
+  gegl_operation_handlers_register_loader (
+    "image/jpeg", "gegl:jpg-load");
+  gegl_operation_handlers_register_loader (
+    ".jpeg", "gegl:jpg-load");
+  gegl_operation_handlers_register_loader (
+    ".jpg", "gegl:jpg-load");
 /*  done = TRUE; */
 }
 #endif
diff --git a/operations/external/jpg-save.c b/operations/external/jpg-save.c
index 8e0ec43..d4ee516 100644
--- a/operations/external/jpg-save.c
+++ b/operations/external/jpg-save.c
@@ -198,7 +198,10 @@ gegl_op_class_init (GeglOpClass *klass)
     _("JPEG image saver, using libjpeg"),
     NULL);
 
-  gegl_extension_handler_register_saver (".jpg", "gegl:jpg-save");
+  gegl_operation_handlers_register_saver (
+    ".jpeg", "gegl:jpg-save");
+  gegl_operation_handlers_register_saver (
+    ".jpg", "gegl:jpg-save");
 }
 
 #endif
diff --git a/operations/external/npy-save.c b/operations/external/npy-save.c
index 3a2dbda..8e2947b 100644
--- a/operations/external/npy-save.c
+++ b/operations/external/npy-save.c
@@ -145,7 +145,8 @@ gegl_op_class_init (GeglOpClass *klass)
         _("NPY image saver (Numerical python file saver.)"),
         NULL);
 
-  gegl_extension_handler_register_saver (".npy", "gegl:npy-save");
+  gegl_operation_handlers_register_saver (
+    ".npy", "gegl:npy-save");
 }
 
 #endif
diff --git a/operations/external/png-load.c b/operations/external/png-load.c
index 0761453..6455db8 100644
--- a/operations/external/png-load.c
+++ b/operations/external/png-load.c
@@ -502,7 +502,10 @@ gegl_op_class_init (GeglOpClass *klass)
 /*  static gboolean done=FALSE;
     if (done)
       return; */
-  gegl_extension_handler_register_loader (".png", "gegl:png-load");
+  gegl_operation_handlers_register_loader (
+    "image/png", "gegl:png-load");
+  gegl_operation_handlers_register_loader (
+    ".png", "gegl:png-load");
 /*  done = TRUE; */
 }
 
diff --git a/operations/external/png-save.c b/operations/external/png-save.c
index b0bacd7..7553ddc 100644
--- a/operations/external/png-save.c
+++ b/operations/external/png-save.c
@@ -231,7 +231,8 @@ gegl_op_class_init (GeglOpClass *klass)
         _("PNG image saver, using libpng"),
         NULL);
 
-  gegl_extension_handler_register_saver (".png", "gegl:png-save");
+  gegl_operation_handlers_register_saver (
+    ".png", "gegl:png-save");
 }
 
 #endif
diff --git a/operations/external/ppm-load.c b/operations/external/ppm-load.c
index 1552e19..11d9f9e 100644
--- a/operations/external/ppm-load.c
+++ b/operations/external/ppm-load.c
@@ -383,9 +383,20 @@ gegl_op_class_init (GeglOpClass *klass)
     "description",  _("PPM image loader."),
     NULL);
 
-  gegl_extension_handler_register_loader (".ppm", "gegl:ppm-load");
-  gegl_extension_handler_register_loader (".pgm", "gegl:ppm-load");
-  gegl_extension_handler_register_loader (".pnm", "gegl:ppm-load");
+  gegl_operation_handlers_register_loader (
+    "image/x-portable-pixmap", "gegl:ppm-load");
+  gegl_operation_handlers_register_loader (
+    ".ppm", "gegl:ppm-load");
+
+  gegl_operation_handlers_register_loader (
+    "image/x-portable-graymap:", "gegl:ppm-load");
+  gegl_operation_handlers_register_loader (
+    ".pgm", "gegl:ppm-load");
+
+  gegl_operation_handlers_register_loader (
+    "image/x-portable-anymap", "gegl:ppm-load");
+  gegl_operation_handlers_register_loader (
+    ".pnm", "gegl:ppm-load");
 }
 
 #endif
diff --git a/operations/external/ppm-save.c b/operations/external/ppm-save.c
index ba5d6b9..f365089 100644
--- a/operations/external/ppm-save.c
+++ b/operations/external/ppm-save.c
@@ -192,7 +192,8 @@ gegl_op_class_init (GeglOpClass *klass)
         _("PPM image saver (Portable pixmap saver.)"),
         NULL);
 
-  gegl_extension_handler_register_saver (".ppm", "gegl:ppm-save");
+  gegl_operation_handlers_register_saver (
+    ".ppm", "gegl:ppm-save");
 }
 
 #endif
diff --git a/operations/external/raw-load.c b/operations/external/raw-load.c
index 8ce0a2f..bbdbb02 100644
--- a/operations/external/raw-load.c
+++ b/operations/external/raw-load.c
@@ -244,15 +244,45 @@ gegl_op_class_init (GeglOpClass *klass)
   if (done)
     return;
 
-  /* query libopenraw instead. need a new API */
-  gegl_extension_handler_register_loader (".pef", "gegl:raw-load");
-  gegl_extension_handler_register_loader (".nef", "gegl:raw-load");
-  gegl_extension_handler_register_loader (".raf", "gegl:raw-load");
-  gegl_extension_handler_register_loader (".orf", "gegl:raw-load");
-  gegl_extension_handler_register_loader (".erf", "gegl:raw-load");
-  gegl_extension_handler_register_loader (".mrw", "gegl:raw-load");
-  gegl_extension_handler_register_loader (".crw", "gegl:raw-load");
-  gegl_extension_handler_register_loader (".cr2", "gegl:raw-load");
+  gegl_operation_handlers_register_loader (
+    "image/x-pentax-pef", "gegl:raw-load");
+  gegl_operation_handlers_register_loader (
+    ".pef", "gegl:raw-load");
+
+  gegl_operation_handlers_register_loader (
+    "image/x-nikon-nef", "gegl:raw-load");
+  gegl_operation_handlers_register_loader (
+    ".nef", "gegl:raw-load");
+
+  gegl_operation_handlers_register_loader (
+    "image/x-fuji-raf", "gegl:raw-load");
+  gegl_operation_handlers_register_loader (
+    ".raf", "gegl:raw-load");
+
+  gegl_operation_handlers_register_loader (
+    "image/x-olympus-orf", "gegl:raw-load");
+  gegl_operation_handlers_register_loader (
+    ".orf", "gegl:raw-load");
+
+  gegl_operation_handlers_register_loader (
+    "image/x-epson-erf", "gegl:raw-load");
+  gegl_operation_handlers_register_loader (
+    ".erf", "gegl:raw-load");
+
+  gegl_operation_handlers_register_loader (
+    "image/x-minolta-mrw", "gegl:raw-load");
+  gegl_operation_handlers_register_loader (
+    ".mrw", "gegl:raw-load");
+
+  gegl_operation_handlers_register_loader (
+    "image/x-canon-crw", "gegl:raw-load");
+  gegl_operation_handlers_register_loader (
+    ".crw", "gegl:raw-load");
+
+  gegl_operation_handlers_register_loader (
+    "image/x-canon-cr2", "gegl:raw-load");
+  gegl_operation_handlers_register_loader (
+    ".cr2", "gegl:raw-load");
 
   done = TRUE;
 }
diff --git a/operations/external/rgbe-load.c b/operations/external/rgbe-load.c
index f3af9da..02eee67 100644
--- a/operations/external/rgbe-load.c
+++ b/operations/external/rgbe-load.c
@@ -137,8 +137,12 @@ gegl_op_class_init (GeglOpClass *klass)
     "description" , _("RGBE image loader (Radiance HDR format)."),
     NULL);
 
-  gegl_extension_handler_register_loader (".hdr", "gegl:rgbe-load");
-  gegl_extension_handler_register_loader (".pic", "gegl:rgbe-load");
+  gegl_operation_handlers_register_loader (
+    "image/vnd.radiance", "gegl:rgbe-load");
+  gegl_operation_handlers_register_loader (
+    ".hdr", "gegl:rgbe-load");
+  gegl_operation_handlers_register_loader (
+    ".pic", "gegl:rgbe-load");
 }
 
 #endif
diff --git a/operations/external/rgbe-save.c b/operations/external/rgbe-save.c
index bfd0db9..99b56db 100644
--- a/operations/external/rgbe-save.c
+++ b/operations/external/rgbe-save.c
@@ -87,8 +87,10 @@ gegl_op_class_init (GeglOpClass *klass)
         _("RGBE image saver (Radiance HDR format)"),
     NULL);
 
-  gegl_extension_handler_register_saver (".hdr", "gegl:rgbe-save");
-  gegl_extension_handler_register_saver (".pic", "gegl:rgbe-save");
+  gegl_operation_handlers_register_saver (
+    ".hdr", "gegl:rgbe-save");
+  gegl_operation_handlers_register_saver (
+    ".pic", "gegl:rgbe-save");
 }
 
 #endif
diff --git a/operations/external/svg-load.c b/operations/external/svg-load.c
index fe8e338..fbfbf3c 100644
--- a/operations/external/svg-load.c
+++ b/operations/external/svg-load.c
@@ -294,8 +294,15 @@ gegl_op_class_init (GeglOpClass *klass)
     "description" , _("Load an SVG file using librsvg"),
     NULL);
 
-  gegl_extension_handler_register_loader (".svg", "gegl:svg-load");
-  gegl_extension_handler_register_loader (".svgz", "gegl:svg-load");
+  gegl_operation_handlers_register_loader (
+    "image/svg+xml", "gegl:svg-load");
+  gegl_operation_handlers_register_loader (
+    ".svg", "gegl:svg-load");
+
+  gegl_operation_handlers_register_loader (
+    "image/svg+xml-compressed", "gegl:svg-load");
+  gegl_operation_handlers_register_loader (
+    ".svgz", "gegl:svg-load");
 }
 
 #endif
diff --git a/operations/external/tiff-load.c b/operations/external/tiff-load.c
index a190247..f129b94 100644
--- a/operations/external/tiff-load.c
+++ b/operations/external/tiff-load.c
@@ -869,8 +869,14 @@ gegl_op_class_init(GeglOpClass *klass)
     "description", _("TIFF image loader using libtiff"),
     NULL);
 
-  gegl_extension_handler_register_loader(".tiff", "gegl:tiff-load");
-  gegl_extension_handler_register_loader(".tif", "gegl:tiff-load");
+  gegl_operation_handlers_register_loader(
+    "image/tiff", "gegl:tiff-load");
+  gegl_operation_handlers_register_loader(
+    "image/x-tiff-multipage", "gegl:tiff-load");
+  gegl_operation_handlers_register_loader(
+    ".tiff", "gegl:tiff-load");
+  gegl_operation_handlers_register_loader(
+    ".tif", "gegl:tiff-load");
 }
 
 #endif
diff --git a/operations/external/tiff-save.c b/operations/external/tiff-save.c
index f0ce688..1bdd940 100644
--- a/operations/external/tiff-save.c
+++ b/operations/external/tiff-save.c
@@ -623,8 +623,10 @@ gegl_op_class_init(GeglOpClass *klass)
     "description", _("TIFF image saver using libtiff"),
     NULL);
 
-  gegl_extension_handler_register_saver(".tiff", "gegl:tiff-save");
-  gegl_extension_handler_register_saver(".tif", "gegl:tiff-save");
+  gegl_operation_handlers_register_saver(
+    ".tiff", "gegl:tiff-save");
+  gegl_operation_handlers_register_saver(
+    ".tif", "gegl:tiff-save");
 }
 
 #endif
diff --git a/operations/external/webp-load.c b/operations/external/webp-load.c
index 1dece66..3b0b455 100644
--- a/operations/external/webp-load.c
+++ b/operations/external/webp-load.c
@@ -348,7 +348,10 @@ gegl_op_class_init (GeglOpClass *klass)
     "description" , _("WebP image loader."),
     NULL);
 
-  gegl_extension_handler_register_loader (".webp", "gegl:webp-load");
+  gegl_operation_handlers_register_loader (
+    "image/webp", "gegl:webp-load");
+  gegl_operation_handlers_register_loader (
+    ".webp", "gegl:webp-load");
 }
 
 #endif
diff --git a/operations/external/webp-save.c b/operations/external/webp-save.c
index a48462e..469d83f 100644
--- a/operations/external/webp-save.c
+++ b/operations/external/webp-save.c
@@ -197,7 +197,8 @@ gegl_op_class_init (GeglOpClass *klass)
     "description", _("WebP image saver"),
      NULL);
 
-  gegl_extension_handler_register_saver (".webp", "gegl:webp-save");
+  gegl_operation_handlers_register_saver (
+    ".webp", "gegl:webp-save");
 }
 
 #endif
diff --git a/operations/workshop/rawbayer-load.c b/operations/workshop/rawbayer-load.c
index c059b82..9014df1 100644
--- a/operations/workshop/rawbayer-load.c
+++ b/operations/workshop/rawbayer-load.c
@@ -159,8 +159,10 @@ gegl_op_class_init (GeglOpClass *klass)
           " is apparently buggy)"),
         NULL);
 
-  gegl_extension_handler_register_loader (".rawbayer", "gegl:rawbayer-load");
-  gegl_extension_handler_register_loader (".rawbayerS", "gegl:rawbayer-load");
+  gegl_operation_handlers_register_loader (
+    ".rawbayer", "gegl:rawbayer-load");
+  gegl_operation_handlers_register_loader (
+    ".rawbayerS", "gegl:rawbayer-load");
 }
 
 #endif
diff --git a/tests/simple/test-misc.c b/tests/simple/test-misc.c
index bf461f4..8ab0ecf 100644
--- a/tests/simple/test-misc.c
+++ b/tests/simple/test-misc.c
@@ -24,18 +24,35 @@
 #define FAILURE -1
 
 static int
+test_misc_case_sensitive_mime_handler (void)
+{
+  gint result = SUCCESS;
+  const gchar *handler = "gegl:foo-handler";
+  const gchar *mime = "image/fooext";
+  const gchar *received_handler = NULL;
+
+  gegl_operation_handlers_register_loader (mime, handler);
+
+  received_handler = gegl_operation_handlers_get_loader (mime);
+  if (! strcmp (received_handler, handler) == 0)
+    result = FAILURE;
+
+  return result;
+}
+
+static int
 test_misc_case_insensitive_extension_handler (void)
 {
   gint result = SUCCESS;
   const gchar *handler = "gegl:foo-handler";
-  const gchar *lowercase = "fooext";
-  const gchar *uppercase = "FOOEXT";
+  const gchar *lowercase = ".fooext";
+  const gchar *uppercase = ".FOOEXT";
   const gchar *received_handler = NULL;
 
-  gegl_extension_handler_register_loader (lowercase, handler);
+  gegl_operation_handlers_register_loader (lowercase, handler);
 
   /* Make sure comparisions are case insensitive */
-  received_handler = gegl_extension_handler_get_loader (uppercase);
+  received_handler = gegl_operation_handlers_get_loader (uppercase);
   if (! strcmp (received_handler, handler) == 0)
     result = FAILURE;
 
@@ -47,14 +64,15 @@ test_misc_save_handler (void)
 {
   gint result = SUCCESS;
   const gchar *handler = "gegl:bar-handler";
-  const gchar *ext = "barext";
+  const gchar *ext = ".barext";
   const gchar *received_handler = NULL;
 
-  gegl_extension_handler_register_saver (ext, handler);
-  received_handler = gegl_extension_handler_get_saver (ext);
+  gegl_operation_handlers_register_saver (ext, handler);
+
+  received_handler = gegl_operation_handlers_get_saver (ext);
   if (! strcmp (received_handler, handler) == 0)
     result = FAILURE;
-  
+
   return result;
 }
 
@@ -64,6 +82,9 @@ int main(int argc, char *argv[])
   gint result = SUCCESS;
 
   if (result == SUCCESS)
+    result = test_misc_case_sensitive_mime_handler ();
+
+  if (result == SUCCESS)
     result = test_misc_case_insensitive_extension_handler ();
 
   if (result == SUCCESS)


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