[gimp/wip/Jehan/classy-GIMP: 10/17] plug-ins: port file-raw plug-ins to GimpImage/GimpDrawable.



commit e762abe1c251a6b391fbf55bdfeb87e097ea89e9
Author: Jehan <jehan girinstud io>
Date:   Wed Aug 14 16:51:03 2019 +0200

    plug-ins: port file-raw plug-ins to GimpImage/GimpDrawable.

 plug-ins/file-raw/Makefile.am        |  1 -
 plug-ins/file-raw/file-darktable.c   | 85 ++++++++++++++++++------------------
 plug-ins/file-raw/file-rawtherapee.c | 66 ++++++++++++++--------------
 3 files changed, 76 insertions(+), 76 deletions(-)
---
diff --git a/plug-ins/file-raw/Makefile.am b/plug-ins/file-raw/Makefile.am
index c2d88fae0c..934ae6187a 100644
--- a/plug-ins/file-raw/Makefile.am
+++ b/plug-ins/file-raw/Makefile.am
@@ -25,7 +25,6 @@ rt_libexecdir = $(gimpplugindir)/plug-ins/file-rawtherapee
 rp_libexecdir = $(gimpplugindir)/plug-ins/file-raw-placeholder
 
 AM_CPPFLAGS = \
-       -DGIMP_DEPRECATED_REPLACE_NEW_API \
        -I$(top_srcdir) \
        -I$(includedir) \
        $(GTK_CFLAGS)   \
diff --git a/plug-ins/file-raw/file-darktable.c b/plug-ins/file-raw/file-darktable.c
index e16210b685..02287a36c6 100644
--- a/plug-ins/file-raw/file-darktable.c
+++ b/plug-ins/file-raw/file-darktable.c
@@ -67,10 +67,10 @@ static GimpValueArray * darktable_load_thumb       (GimpProcedure        *proced
                                                     const GimpValueArray *args,
                                                     gpointer              run_data);
 
-static gint32           load_image                 (const gchar          *filename,
+static GimpImage      * load_image                 (const gchar          *filename,
                                                     GimpRunMode           run_mode,
                                                     GError              **error);
-static gint32           load_thumbnail_image       (const gchar          *filename,
+static GimpImage      * load_thumbnail_image       (const gchar          *filename,
                                                     gint                  thumb_size,
                                                     gint                 *width,
                                                     gint                 *height,
@@ -255,11 +255,11 @@ darktable_create_procedure (GimpPlugIn  *plug_in,
                                                      GIMP_PARAM_READWRITE));
 
       gimp_procedure_add_return_value (procedure,
-                                       gimp_param_spec_image_id ("image",
-                                                                 "Image",
-                                                                 "Thumbnail image",
-                                                                 FALSE,
-                                                                 GIMP_PARAM_READWRITE));
+                                       g_param_spec_object ("image",
+                                                            "Image",
+                                                            "Thumbnail image",
+                                                            GIMP_TYPE_IMAGE,
+                                                            GIMP_PARAM_READWRITE));
       gimp_procedure_add_return_value (procedure,
                                        g_param_spec_int ("image-width",
                                                          "Image width",
@@ -340,18 +340,18 @@ darktable_load (GimpProcedure        *procedure,
 {
   GimpValueArray *return_vals;
   gchar          *filename;
-  gint32          image_id;
+  GimpImage      *image;
   GError         *error = NULL;
 
   INIT_I18N ();
 
   filename = g_file_get_path (file);
 
-  image_id = load_image (filename, run_mode, &error);
+  image = load_image (filename, run_mode, &error);
 
   g_free (filename);
 
-  if (image_id < 1)
+  if (! image)
     return gimp_procedure_new_return_values (procedure,
                                              GIMP_PDB_EXECUTION_ERROR,
                                              error);
@@ -360,8 +360,8 @@ darktable_load (GimpProcedure        *procedure,
                                                   GIMP_PDB_SUCCESS,
                                                   NULL);
 
-  gimp_value_set_image_id (gimp_value_array_index (return_vals, 1),
-                           image_id);
+  g_value_set_object (gimp_value_array_index (return_vals, 1),
+                      image);
 
   return return_vals;
 }
@@ -375,7 +375,7 @@ darktable_load_thumb (GimpProcedure        *procedure,
   const gchar    *filename;
   gint            width;
   gint            height;
-  gint32          image_id;
+  GimpImage      *image = NULL;
   GValue          value = G_VALUE_INIT;
   GError         *error = NULL;
 
@@ -385,9 +385,9 @@ darktable_load_thumb (GimpProcedure        *procedure,
   width    = g_value_get_int    (gimp_value_array_index (args, 1));
   height   = width;
 
-  image_id = load_thumbnail_image (filename, width, &width, &height, &error);
+  image = load_thumbnail_image (filename, width, &width, &height, &error);
 
-  if (image_id < 1)
+  if (! image)
     return gimp_procedure_new_return_values (procedure,
                                              GIMP_PDB_EXECUTION_ERROR,
                                              error);
@@ -396,9 +396,9 @@ darktable_load_thumb (GimpProcedure        *procedure,
                                                   GIMP_PDB_SUCCESS,
                                                   NULL);
 
-  gimp_value_set_image_id (gimp_value_array_index (return_vals, 1), image_id);
-  g_value_set_int         (gimp_value_array_index (return_vals, 2), width);
-  g_value_set_int         (gimp_value_array_index (return_vals, 3), height);
+  g_value_set_object (gimp_value_array_index (return_vals, 1), image);
+  g_value_set_int    (gimp_value_array_index (return_vals, 2), width);
+  g_value_set_int    (gimp_value_array_index (return_vals, 3), height);
 
   g_value_init (&value, GIMP_TYPE_IMAGE_TYPE);
   g_value_set_enum (&value, GIMP_RGB_IMAGE);
@@ -413,22 +413,22 @@ darktable_load_thumb (GimpProcedure        *procedure,
   return return_vals;
 }
 
-static gint32
+static GimpImage *
 load_image (const gchar  *filename,
             GimpRunMode   run_mode,
             GError      **error)
 {
-  gint32  image_ID           = -1;
-  GFile  *lua_file           = gimp_data_directory_file ("file-raw",
-                                                         "file-darktable-export-on-exit.lua",
-                                                         NULL);
-  gchar  *lua_script         = g_file_get_path (lua_file);
-  gchar  *lua_script_escaped = g_strescape (lua_script, "");
-  gchar  *lua_quoted         = g_shell_quote (lua_script_escaped);
-  gchar  *lua_cmd            = g_strdup_printf ("dofile(%s)", lua_quoted);
-  gchar  *filename_out       = gimp_temp_name ("exr");
-  gchar  *export_filename    = g_strdup_printf ("lua/export_on_exit/export_filename=%s",
-                                                filename_out);
+  GimpImage *image              = NULL;
+  GFile     *lua_file           = gimp_data_directory_file ("file-raw",
+                                                            "file-darktable-export-on-exit.lua",
+                                                            NULL);
+  gchar     *lua_script         = g_file_get_path (lua_file);
+  gchar     *lua_script_escaped = g_strescape (lua_script, "");
+  gchar     *lua_quoted         = g_shell_quote (lua_script_escaped);
+  gchar     *lua_cmd            = g_strdup_printf ("dofile(%s)", lua_quoted);
+  gchar     *filename_out       = gimp_temp_name ("exr");
+  gchar     *export_filename    = g_strdup_printf ("lua/export_on_exit/export_filename=%s",
+                                                   filename_out);
 
   gchar *darktable_stdout    = NULL;
   gchar *darktable_stderr    = NULL;
@@ -483,9 +483,9 @@ load_image (const gchar  *filename,
                     NULL,
                     error))
     {
-      image_ID = gimp_file_load (run_mode, filename_out, filename_out);
-      if (image_ID != -1)
-        gimp_image_set_filename (image_ID, filename);
+      image = gimp_file_load (run_mode, filename_out, filename_out);
+      if (image)
+        gimp_image_set_filename (image, filename);
     }
 
   if (debug_prints)
@@ -508,17 +508,18 @@ load_image (const gchar  *filename,
 
   gimp_progress_update (1.0);
 
-  return image_ID;
+  return image;
 }
 
-static gint32
+static GimpImage *
 load_thumbnail_image (const gchar   *filename,
                       gint           thumb_size,
                       gint          *width,
                       gint          *height,
                       GError       **error)
 {
-  gint32  image_ID           = -1;
+  GimpImage *image           = NULL;
+
   gchar  *filename_out       = gimp_temp_name ("jpg");
   gchar  *size               = g_strdup_printf ("%d", thumb_size);
   GFile  *lua_file           = gimp_data_directory_file ("file-raw",
@@ -573,10 +574,10 @@ load_thumbnail_image (const gchar   *filename,
     {
       gimp_progress_update (0.5);
 
-      image_ID = gimp_file_load (GIMP_RUN_NONINTERACTIVE,
-                                 filename_out,
-                                 filename_out);
-      if (image_ID != -1)
+      image = gimp_file_load (GIMP_RUN_NONINTERACTIVE,
+                              filename_out,
+                              filename_out);
+      if (image)
         {
           /* the size reported by raw files isn't precise,
            * but it should be close enough to get an idea.
@@ -588,7 +589,7 @@ load_thumbnail_image (const gchar   *filename,
             sscanf (start_of_size, "[dt4gimp] %d %d", width, height);
 
           /* is this needed for thumbnails? */
-          gimp_image_set_filename (image_ID, filename);
+          gimp_image_set_filename (image, filename);
         }
     }
 
@@ -601,5 +602,5 @@ load_thumbnail_image (const gchar   *filename,
   g_free (darktable_stdout);
   g_free (exec_path);
 
-  return image_ID;
+  return image;
 }
diff --git a/plug-ins/file-raw/file-rawtherapee.c b/plug-ins/file-raw/file-rawtherapee.c
index bb9dfff69d..7470782d23 100644
--- a/plug-ins/file-raw/file-rawtherapee.c
+++ b/plug-ins/file-raw/file-rawtherapee.c
@@ -68,10 +68,10 @@ static GimpValueArray * rawtherapee_load_thumb       (GimpProcedure        *proc
                                                       const GimpValueArray *args,
                                                       gpointer              run_data);
 
-static gint32           load_image                   (const gchar          *filename,
+static GimpImage      * load_image                   (const gchar          *filename,
                                                       GimpRunMode           run_mode,
                                                       GError              **error);
-static gint32           load_thumbnail_image         (const gchar          *filename,
+static GimpImage      * load_thumbnail_image         (const gchar          *filename,
                                                       gint                  thumb_size,
                                                       GError              **error);
 
@@ -277,18 +277,18 @@ rawtherapee_load (GimpProcedure        *procedure,
 {
   GimpValueArray *return_vals;
   gchar          *filename;
-  gint32          image_id;
+  GimpImage      *image;
   GError         *error = NULL;
 
   INIT_I18N ();
 
   filename = g_file_get_path (file);
 
-  image_id = load_image (filename, run_mode, &error);
+  image = load_image (filename, run_mode, &error);
 
   g_free (filename);
 
-  if (image_id < 1)
+  if (! image)
     return gimp_procedure_new_return_values (procedure,
                                              GIMP_PDB_EXECUTION_ERROR,
                                              error);
@@ -297,8 +297,8 @@ rawtherapee_load (GimpProcedure        *procedure,
                                                   GIMP_PDB_SUCCESS,
                                                   NULL);
 
-  gimp_value_set_image_id (gimp_value_array_index (return_vals, 1),
-                           image_id);
+  g_value_set_object (gimp_value_array_index (return_vals, 1),
+                      image);
 
   return return_vals;
 }
@@ -311,7 +311,7 @@ rawtherapee_load_thumb (GimpProcedure        *procedure,
   GimpValueArray *return_vals;
   const gchar    *filename;
   gint            size;
-  gint32          image_id;
+  GimpImage      *image;
   GValue          value = G_VALUE_INIT;
   GError         *error = NULL;
 
@@ -320,9 +320,9 @@ rawtherapee_load_thumb (GimpProcedure        *procedure,
   filename = g_value_get_string (gimp_value_array_index (args, 0));
   size     = g_value_get_int    (gimp_value_array_index (args, 1));
 
-  image_id = load_thumbnail_image (filename, size, &error);
+  image = load_thumbnail_image (filename, size, &error);
 
-  if (image_id < 1)
+  if (! image)
     return gimp_procedure_new_return_values (procedure,
                                              GIMP_PDB_EXECUTION_ERROR,
                                              error);
@@ -331,7 +331,7 @@ rawtherapee_load_thumb (GimpProcedure        *procedure,
                                                   GIMP_PDB_SUCCESS,
                                                   NULL);
 
-  gimp_value_set_image_id (gimp_value_array_index (return_vals, 1), image_id);
+  g_value_set_object (gimp_value_array_index (return_vals, 1), image);
 
   g_value_init (&value, GIMP_TYPE_IMAGE_TYPE);
   g_value_set_enum (&value, GIMP_RGB_IMAGE);
@@ -346,17 +346,17 @@ rawtherapee_load_thumb (GimpProcedure        *procedure,
   return return_vals;
 }
 
-static gint32
+static GimpImage *
 load_image (const gchar  *filename,
             GimpRunMode   run_mode,
             GError      **error)
 {
-  gint32    image_ID           = -1;
-  gchar    *filename_out       = gimp_temp_name ("tif");
-  gchar    *rawtherapee_stdout = NULL;
+  GimpImage *image              = NULL;
+  gchar     *filename_out       = gimp_temp_name ("tif");
+  gchar     *rawtherapee_stdout = NULL;
 
-  gboolean  search_path        = FALSE;
-  gchar    *exec_path          = file_raw_get_executable_path ("rawtherapee", NULL,
+  gboolean   search_path        = FALSE;
+  gchar     *exec_path          = file_raw_get_executable_path ("rawtherapee", NULL,
                                                                "RAWTHERAPEE_EXECUTABLE",
                                                                "com.rawtherapee.rawtherapee",
                                                                REGISTRY_KEY_BASE,
@@ -388,9 +388,9 @@ load_image (const gchar  *filename,
                     NULL,
                     error))
     {
-      image_ID = gimp_file_load (run_mode, filename_out, filename_out);
-      if (image_ID != -1)
-        gimp_image_set_filename (image_ID, filename);
+      image = gimp_file_load (run_mode, filename_out, filename_out);
+      if (image)
+        gimp_image_set_filename (image, filename);
     }
 
   /*if (rawtherapee_stdout) printf ("%s\n", rawtherapee_stdout);*/
@@ -402,19 +402,19 @@ load_image (const gchar  *filename,
 
   gimp_progress_update (1.0);
 
-  return image_ID;
+  return image;
 }
 
-static gint32
+static GimpImage *
 load_thumbnail_image (const gchar   *filename,
                       gint           thumb_size,
                       GError       **error)
 {
-  gint32  image_ID         = -1;
-  gchar  *filename_out     = gimp_temp_name ("jpg");
-  gchar  *thumb_pp3        = gimp_temp_name ("pp3");
-  FILE   *thumb_pp3_f      = fopen (thumb_pp3, "w");
-  gchar  *rawtherapee_stdout = NULL;
+  GimpImage *image            = NULL;
+  gchar     *filename_out     = gimp_temp_name ("jpg");
+  gchar     *thumb_pp3        = gimp_temp_name ("pp3");
+  FILE      *thumb_pp3_f      = fopen (thumb_pp3, "w");
+  gchar     *rawtherapee_stdout = NULL;
   const char *pp3_content =
     "[Version]\n"
     "AppVersion=5.0\n"
@@ -507,13 +507,13 @@ load_thumbnail_image (const gchar   *filename,
     {
       gimp_progress_update (0.5);
 
-      image_ID = gimp_file_load (GIMP_RUN_NONINTERACTIVE,
-                                 filename_out,
-                                 filename_out);
-      if (image_ID != -1)
+      image = gimp_file_load (GIMP_RUN_NONINTERACTIVE,
+                              filename_out,
+                              filename_out);
+      if (image)
         {
           /* is this needed for thumbnails? */
-          gimp_image_set_filename (image_ID, filename);
+          gimp_image_set_filename (image, filename);
         }
     }
 
@@ -528,5 +528,5 @@ load_thumbnail_image (const gchar   *filename,
   g_free (rawtherapee_stdout);
   g_free (exec_path);
 
-  return image_ID;
+  return image;
 }


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