[gegl] operations: add is_available() implementation to gegl:magick-load.



commit 55513597dcbeb092d30d8d7aa00ae32b441ae35e
Author: Jehan <jehan girinstud io>
Date:   Fri Jan 7 21:57:03 2022 +0100

    operations: add is_available() implementation to gegl:magick-load.
    
    Similar to how we hide gegl:introspect, gegl:magick-load should not be
    made available when Image-Magick's convert CLI tool is not present.

 operations/common/magick-load.c | 26 +++++++++++++++++++++++---
 1 file changed, 23 insertions(+), 3 deletions(-)
---
diff --git a/operations/common/magick-load.c b/operations/common/magick-load.c
index 0224db47d..36ab0ab6a 100644
--- a/operations/common/magick-load.c
+++ b/operations/common/magick-load.c
@@ -38,7 +38,11 @@ property_file_path (path, _("File"), "/tmp/gegl-logo.svg")
 static void
 load_cache (GeglProperties *op_magick_load)
 {
-  if (!op_magick_load->user_data)
+  gchar *convert;
+
+  convert = g_find_program_in_path ("convert");
+
+  if (convert && !op_magick_load->user_data)
     {
       gchar    *filename;
       GeglNode *graph, *sink, *loader;
@@ -47,7 +51,7 @@ load_cache (GeglProperties *op_magick_load)
       /* ImageMagick backed fallback FIXME: make this robust.
        * maybe use pipes in a manner similar to the raw loader,
        * or at least use a properly unique filename  */
-      char     *argv[4]  = {"convert", NULL, NULL, NULL};
+      char     *argv[4]  = {convert, NULL, NULL, NULL};
 
       filename = g_build_filename (g_get_tmp_dir (), "gegl-magick.png", NULL);
 
@@ -77,6 +81,8 @@ load_cache (GeglProperties *op_magick_load)
       g_object_unref (graph);
       g_free (filename);
     }
+
+  g_free (convert);
 }
 
 static GeglRectangle
@@ -119,6 +125,19 @@ process (GeglOperation         *operation,
   return  TRUE;
 }
 
+static gboolean
+gegl_magick_load_is_available (void)
+{
+  gchar    *convert;
+  gboolean  found = FALSE;
+
+  convert = g_find_program_in_path ("convert");
+  found = (convert != NULL);
+  g_free (convert);
+
+  return found;
+}
+
 static void finalize (GObject *object)
 {
   GeglOperation *op = (void*) object;
@@ -141,8 +160,9 @@ gegl_op_class_init (GeglOpClass *klass)
   object_class->finalize = finalize;
 
   operation_class->process = process;
-  operation_class->get_bounding_box = get_bounding_box;
+  operation_class->get_bounding_box  = get_bounding_box;
   operation_class->get_cached_region = get_cached_region;;
+  operation_class->is_available      = gegl_magick_load_is_available;
 
   gegl_operation_class_set_keys (operation_class,
         "name"       , "gegl:magick-load",


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