[gimp] plug-ins: port file-psd to GimpPlugIn



commit 293d909cf4bd113ff10e3897e24a8aa0dc96a2c6
Author: Michael Natterer <mitch gimp org>
Date:   Sun Aug 18 00:26:13 2019 +0200

    plug-ins: port file-psd to GimpPlugIn
    
    and remove all save arguments, they are completely unused, wtf?

 plug-ins/file-psd/psd.c | 648 ++++++++++++++++++++++++++----------------------
 1 file changed, 348 insertions(+), 300 deletions(-)
---
diff --git a/plug-ins/file-psd/psd.c b/plug-ins/file-psd/psd.c
index 083a5a9444..95965358de 100644
--- a/plug-ins/file-psd/psd.c
+++ b/plug-ins/file-psd/psd.c
@@ -33,353 +33,401 @@
 #include "libgimp/stdplugins-intl.h"
 
 
-/*  Local function prototypes  */
+typedef struct _Psd      Psd;
+typedef struct _PsdClass PsdClass;
 
-static void  query (void);
-static void  run   (const gchar     *name,
-                    gint             nparams,
-                    const GimpParam *param,
-                    gint            *nreturn_vals,
-                    GimpParam      **return_vals);
-
-
-/*  Local variables  */
+struct _Psd
+{
+  GimpPlugIn      parent_instance;
+};
 
-GimpPlugInInfo PLUG_IN_INFO =
+struct _PsdClass
 {
-  NULL,  /* init_proc  */
-  NULL,  /* quit_proc  */
-  query, /* query_proc */
-  run,   /* run_proc   */
+  GimpPlugInClass parent_class;
 };
 
 
-MAIN ()
+#define PSD_TYPE  (psd_get_type ())
+#define PSD (obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), PSD_TYPE, Psd))
+
+GType                   psd_get_type         (void) G_GNUC_CONST;
+
+static GList          * psd_query_procedures (GimpPlugIn           *plug_in);
+static GimpProcedure  * psd_create_procedure (GimpPlugIn           *plug_in,
+                                              const gchar          *name);
+
+static GimpValueArray * psd_load             (GimpProcedure        *procedure,
+                                              GimpRunMode           run_mode,
+                                              GFile                *file,
+                                              const GimpValueArray *args,
+                                              gpointer              run_data);
+static GimpValueArray * psd_load_thumb       (GimpProcedure        *procedure,
+                                              const GimpValueArray *args,
+                                              gpointer              run_data);
+static GimpValueArray * psd_save             (GimpProcedure        *procedure,
+                                              GimpRunMode           run_mode,
+                                              gint32                image_id,
+                                              gint32                drawable_id,
+                                              GFile                *file,
+                                              const GimpValueArray *args,
+                                              gpointer              run_data);
+
+
+G_DEFINE_TYPE (Psd, psd, GIMP_TYPE_PLUG_IN)
+
+GIMP_MAIN (PSD_TYPE)
+
 
 static void
-query (void)
+psd_class_init (PsdClass *klass)
 {
-  /* File Load */
-  static const GimpParamDef load_args[] =
-  {
-    { GIMP_PDB_INT32,  "run-mode",     "The run mode { RUN-INTERACTIVE (0), RUN-NONINTERACTIVE (1) }" },
-    { GIMP_PDB_STRING, "filename",     "The name of the file to load" },
-    { GIMP_PDB_STRING, "raw-filename", "The name of the file to load" }
-  };
-
-  static const GimpParamDef load_return_vals[] =
-  {
-    { GIMP_PDB_IMAGE, "image", "Output image" }
-  };
-
-  /* Thumbnail Load */
-  static const GimpParamDef thumb_args[] =
-  {
-    { GIMP_PDB_STRING, "filename",     "The name of the file to load"  },
-    { GIMP_PDB_INT32,  "thumb-size",   "Preferred thumbnail size"      }
-  };
-
-  static const GimpParamDef thumb_return_vals[] =
-  {
-    { GIMP_PDB_IMAGE,  "image",        "Thumbnail image"               },
-    { GIMP_PDB_INT32,  "image-width",  "Width of full-sized image"     },
-    { GIMP_PDB_INT32,  "image-height", "Height of full-sized image"    }
-  };
-
-  /* File save */
-  static const GimpParamDef save_args[] =
-  {
-    { GIMP_PDB_INT32,    "run-mode",     "The run mode { RUN-INTERACTIVE (0), RUN-NONINTERACTIVE (1) }" },
-    { GIMP_PDB_IMAGE,    "image",        "Input image" },
-    { GIMP_PDB_DRAWABLE, "drawable",     "Drawable to save" },
-    { GIMP_PDB_STRING,   "filename",     "The name of the file to save the image in" },
-    { GIMP_PDB_STRING,   "raw-filename", "The name of the file to save the image in" },
-    { GIMP_PDB_INT32,    "compression",  "Compression type: { NONE (0), LZW (1), PACKBITS (2)" },
-    { GIMP_PDB_INT32,    "fill-order",   "Fill Order: { MSB to LSB (0), LSB to MSB (1)" }
-  };
-
-  /* File load */
-  gimp_install_procedure (LOAD_PROC,
-                          "Loads images from the Photoshop PSD file format",
-                          "This plug-in loads images in Adobe "
-                          "Photoshop (TM) native PSD format.",
-                          "John Marshall",
-                          "John Marshall",
-                          "2007",
-                          N_("Photoshop image"),
-                          NULL,
-                          GIMP_PLUGIN,
-                          G_N_ELEMENTS (load_args),
-                          G_N_ELEMENTS (load_return_vals),
-                          load_args, load_return_vals);
-
-  gimp_register_file_handler_mime (LOAD_PROC, "image/x-psd");
-  gimp_register_magic_load_handler (LOAD_PROC,
-                                    "psd",
-                                    "",
-                                    "0,string,8BPS");
-
-  /* File load (merged) */
-  gimp_install_procedure (LOAD_MERGED_PROC,
-                          "Loads merged images from the Photoshop PSD file format",
-                          "This plug-in loads the merged image data in Adobe "
-                          "Photoshop (TM) native PSD format.",
-                          "Ell",
-                          "Ell",
-                          "2018",
-                          N_("Photoshop image (merged)"),
-                          NULL,
-                          GIMP_PLUGIN,
-                          G_N_ELEMENTS (load_args),
-                          G_N_ELEMENTS (load_return_vals),
-                          load_args, load_return_vals);
-
-  gimp_register_file_handler_priority (LOAD_MERGED_PROC, +1);
-  gimp_register_file_handler_mime (LOAD_MERGED_PROC, "image/x-psd");
-  gimp_register_magic_load_handler (LOAD_MERGED_PROC,
-                                    "psd",
-                                    "",
-                                    "0,string,8BPS");
-
-  /* Thumbnail load */
-  gimp_install_procedure (LOAD_THUMB_PROC,
-                          "Loads thumbnails from the Photoshop PSD file format",
-                          "This plug-in loads thumbnail images from Adobe "
-                          "Photoshop (TM) native PSD format files.",
-                          "John Marshall",
-                          "John Marshall",
-                          "2007",
-                          NULL,
-                          NULL,
-                          GIMP_PLUGIN,
-                          G_N_ELEMENTS (thumb_args),
-                          G_N_ELEMENTS (thumb_return_vals),
-                          thumb_args, thumb_return_vals);
-
-  gimp_register_thumbnail_loader (LOAD_PROC, LOAD_THUMB_PROC);
-
-  gimp_install_procedure (SAVE_PROC,
-                          "saves files in the Photoshop(tm) PSD file format",
-                          "This filter saves files of Adobe Photoshop(tm) native PSD format.  These files 
may be of any image type supported by GIMP, with or without layers, layer masks, aux channels and guides.",
-                          "Monigotes",
-                          "Monigotes",
-                          "2000",
-                          N_("Photoshop image"),
-                          "RGB*, GRAY*, INDEXED*",
-                          GIMP_PLUGIN,
-                          G_N_ELEMENTS (save_args), 0,
-                          save_args, NULL);
-
-  gimp_register_file_handler_mime (SAVE_PROC, "image/x-psd");
-  gimp_register_save_handler (SAVE_PROC, "psd", "");
+  GimpPlugInClass *plug_in_class = GIMP_PLUG_IN_CLASS (klass);
+
+  plug_in_class->query_procedures = psd_query_procedures;
+  plug_in_class->create_procedure = psd_create_procedure;
 }
 
 static void
-run (const gchar      *name,
-     gint              nparams,
-     const GimpParam  *param,
-     gint             *nreturn_vals,
-     GimpParam       **return_vals)
+psd_init (Psd *psd)
+{
+}
+
+static GList *
+psd_query_procedures (GimpPlugIn *plug_in)
 {
-  static GimpParam  values[4];
-  GimpRunMode       run_mode;
-  GimpPDBStatusType status = GIMP_PDB_SUCCESS;
-  gint32            image_ID;
-  GError           *error  = NULL;
+  GList *list = NULL;
 
-  run_mode = param[0].data.d_int32;
+  list = g_list_append (list, g_strdup (LOAD_PROC));
+  list = g_list_append (list, g_strdup (LOAD_MERGED_PROC));
+  list = g_list_append (list, g_strdup (LOAD_THUMB_PROC));
+  list = g_list_append (list, g_strdup (SAVE_PROC));
+
+  return list;
+}
+
+static GimpProcedure *
+psd_create_procedure (GimpPlugIn  *plug_in,
+                      const gchar *name)
+{
+  GimpProcedure *procedure = NULL;
+
+  if (! strcmp (name, LOAD_PROC))
+    {
+      procedure = gimp_load_procedure_new (plug_in, name, GIMP_PLUGIN,
+                                           psd_load, NULL, NULL);
+
+      gimp_procedure_set_menu_label (procedure, N_("Photoshop image"));
+
+      gimp_procedure_set_documentation (procedure,
+                                        "Loads images from the Photoshop "
+                                        "PSD file format",
+                                        "This plug-in loads images in Adobe "
+                                        "Photoshop (TM) native PSD format.",
+                                        name);
+      gimp_procedure_set_attribution (procedure,
+                                      "John Marshall",
+                                      "John Marshall",
+                                      "2007");
+
+      gimp_file_procedure_set_mime_types (GIMP_FILE_PROCEDURE (procedure),
+                                          "image/x-psd");
+      gimp_file_procedure_set_extensions (GIMP_FILE_PROCEDURE (procedure),
+                                          "psd");
+      gimp_file_procedure_set_magics (GIMP_FILE_PROCEDURE (procedure),
+                                      "0,string,8BPS");
+
+      gimp_load_procedure_set_thumbnail_loader (GIMP_LOAD_PROCEDURE (procedure),
+                                                LOAD_THUMB_PROC);
+    }
+  else if (! strcmp (name, LOAD_MERGED_PROC))
+    {
+      procedure = gimp_load_procedure_new (plug_in, name, GIMP_PLUGIN,
+                                           psd_load, NULL, NULL);
+
+      gimp_procedure_set_menu_label (procedure, N_("Photoshop image (merged)"));
+
+      gimp_procedure_set_documentation (procedure,
+                                        "Loads images from the Photoshop "
+                                        "PSD file format",
+                                        "This plug-in loads the merged image "
+                                        "data in Adobe Photoshop (TM) native "
+                                        "PSD format.",
+                                        name);
+      gimp_procedure_set_attribution (procedure,
+                                      "Ell",
+                                      "Ell",
+                                      "2018");
+
+      gimp_file_procedure_set_mime_types (GIMP_FILE_PROCEDURE (procedure),
+                                          "image/x-psd");
+      gimp_file_procedure_set_extensions (GIMP_FILE_PROCEDURE (procedure),
+                                          "psd");
+      gimp_file_procedure_set_magics (GIMP_FILE_PROCEDURE (procedure),
+                                      "0,string,8BPS");
+      gimp_file_procedure_set_priority (GIMP_FILE_PROCEDURE (procedure), +1);
+
+      gimp_load_procedure_set_thumbnail_loader (GIMP_LOAD_PROCEDURE (procedure),
+                                                LOAD_THUMB_PROC);
+    }
+  else if (! strcmp (name, LOAD_THUMB_PROC))
+    {
+      procedure = gimp_procedure_new (plug_in, name, GIMP_PLUGIN,
+                                      psd_load_thumb, NULL, NULL);
+
+      gimp_procedure_set_documentation (procedure,
+                                        "Loads thumbnails from the "
+                                        "Photoshop PSD file format",
+                                        "This plug-in loads thumbnail images "
+                                        "from Adobe Photoshop (TM) native "
+                                        "PSD format files.",
+                                        name);
+      gimp_procedure_set_attribution (procedure,
+                                      "John Marshall",
+                                      "John Marshall",
+                                      "2007");
+
+      gimp_procedure_add_argument (procedure,
+                                   gimp_param_spec_string ("filename",
+                                                           "Filename",
+                                                           "Name of the file "
+                                                           "to load",
+                                                           FALSE, TRUE, FALSE,
+                                                           NULL,
+                                                           GIMP_PARAM_READWRITE));
+      gimp_procedure_add_argument (procedure,
+                                   g_param_spec_int ("thumb-size",
+                                                     "Thumb Size",
+                                                     "Preferred thumbnail size",
+                                                     16, 2014, 256,
+                                                     GIMP_PARAM_READWRITE));
+
+      gimp_procedure_add_return_value (procedure,
+                                       gimp_param_spec_image_id ("image",
+                                                                 "Image",
+                                                                 "Thumbnail image",
+                                                                 FALSE,
+                                                                 GIMP_PARAM_READWRITE));
+      gimp_procedure_add_return_value (procedure,
+                                       g_param_spec_int ("image-width",
+                                                         "Image width",
+                                                         "Width of the "
+                                                         "full-sized image",
+                                                         1, GIMP_MAX_IMAGE_SIZE, 1,
+                                                         GIMP_PARAM_READWRITE));
+      gimp_procedure_add_return_value (procedure,
+                                       g_param_spec_int ("image-height",
+                                                         "Image height",
+                                                         "Height of the "
+                                                         "full-sized image",
+                                                         1, GIMP_MAX_IMAGE_SIZE, 1,
+                                                         GIMP_PARAM_READWRITE));
+    }
+  else if (! strcmp (name, SAVE_PROC))
+    {
+      procedure = gimp_save_procedure_new (plug_in, name, GIMP_PLUGIN,
+                                           psd_save, NULL, NULL);
+
+      gimp_procedure_set_image_types (procedure, "*");
+
+      gimp_procedure_set_menu_label (procedure, N_("Photoshop image"));
+
+      gimp_procedure_set_documentation (procedure,
+                                        "Saves files in the Photoshop(tm) "
+                                        "PSD file format",
+                                        "This filter saves files of Adobe "
+                                        "Photoshop(tm) native PSD format. "
+                                        "These files may be of any image type "
+                                        "supported by GIMP, with or without "
+                                        "layers, layer masks, aux channels "
+                                        "and guides.",
+                                        name);
+      gimp_procedure_set_attribution (procedure,
+                                      "Monigotes",
+                                      "Monigotes",
+                                      "2000");
+
+      gimp_file_procedure_set_mime_types (GIMP_FILE_PROCEDURE (procedure),
+                                          "image/x-psd");
+      gimp_file_procedure_set_extensions (GIMP_FILE_PROCEDURE (procedure),
+                                          "psd");
+    }
+
+  return procedure;
+}
+
+static GimpValueArray *
+psd_load (GimpProcedure        *procedure,
+          GimpRunMode           run_mode,
+          GFile                *file,
+          const GimpValueArray *args,
+          gpointer              run_data)
+{
+  GimpValueArray *return_vals;
+  gboolean        resolution_loaded = FALSE;
+  gboolean        profile_loaded    = FALSE;
+  gboolean        interactive;
+  gint32          image_id;
+  GimpMetadata   *metadata;
+  GError         *error = NULL;
 
   INIT_I18N ();
   gegl_init (NULL, NULL);
 
-  *nreturn_vals = 1;
-  *return_vals  = values;
+  switch (run_mode)
+    {
+    case GIMP_RUN_INTERACTIVE:
+    case GIMP_RUN_WITH_LAST_VALS:
+      gimp_ui_init (PLUG_IN_BINARY, FALSE);
+      interactive = TRUE;
+      break;
+    default:
+      interactive = FALSE;
+      break;
+    }
+
+  image_id = load_image (g_file_get_path (file),
+                         strcmp (gimp_procedure_get_name (procedure),
+                                 LOAD_MERGED_PROC) == 0,
+                         &resolution_loaded,
+                         &profile_loaded,
+                         &error);
 
-  values[0].type          = GIMP_PDB_STATUS;
-  values[0].data.d_status = GIMP_PDB_EXECUTION_ERROR;
+  if (image_id < 1)
+    return gimp_procedure_new_return_values (procedure,
+                                             GIMP_PDB_EXECUTION_ERROR,
+                                             error);
 
-  if (strcmp (name, LOAD_PROC) == 0 ||
-      strcmp (name, LOAD_MERGED_PROC) == 0)
+  metadata = gimp_image_metadata_load_prepare (image_id, "image/x-psd",
+                                               file, NULL);
+  if (metadata)
     {
-      gboolean resolution_loaded = FALSE;
-      gboolean profile_loaded    = FALSE;
-      gboolean interactive;
+      GimpMetadataLoadFlags flags = GIMP_METADATA_LOAD_ALL;
 
-      switch (run_mode)
-        {
-        case GIMP_RUN_INTERACTIVE:
-        case GIMP_RUN_WITH_LAST_VALS:
-          gimp_ui_init (PLUG_IN_BINARY, FALSE);
-          interactive = TRUE;
-          break;
-        default:
-          interactive = FALSE;
-          break;
-        }
+      if (resolution_loaded)
+        flags &= ~GIMP_METADATA_LOAD_RESOLUTION;
 
-      image_ID = load_image (param[1].data.d_string,
-                             strcmp (name, LOAD_MERGED_PROC) == 0,
-                             &resolution_loaded,
-                             &profile_loaded,
-                             &error);
+      if (profile_loaded)
+        flags &= ~GIMP_METADATA_LOAD_COLORSPACE;
 
-      if (image_ID != -1)
-        {
-          GFile        *file = g_file_new_for_path (param[1].data.d_string);
-          GimpMetadata *metadata;
+      gimp_image_metadata_load_finish (image_id, "image/x-psd",
+                                       metadata, flags,
+                                       interactive);
 
-          metadata = gimp_image_metadata_load_prepare (image_ID, "image/x-psd",
-                                                       file, NULL);
+      g_object_unref (metadata);
+    }
 
-          if (metadata)
-            {
-              GimpMetadataLoadFlags flags = GIMP_METADATA_LOAD_ALL;
+  return_vals = gimp_procedure_new_return_values (procedure,
+                                                  GIMP_PDB_SUCCESS,
+                                                  NULL);
 
-              if (resolution_loaded)
-                flags &= ~GIMP_METADATA_LOAD_RESOLUTION;
+  gimp_value_set_image_id (gimp_value_array_index (return_vals, 1),
+                           image_id);
 
-              if (profile_loaded)
-                flags &= ~GIMP_METADATA_LOAD_COLORSPACE;
+  return return_vals;
+}
 
-              gimp_image_metadata_load_finish (image_ID, "image/x-psd",
-                                               metadata, flags,
-                                               interactive);
+static GimpValueArray *
+psd_load_thumb (GimpProcedure        *procedure,
+                const GimpValueArray *args,
+                gpointer              run_data)
+{
+  GimpValueArray *return_vals;
+  const gchar    *filename;
+  gint            width  = 0;
+  gint            height = 0;
+  gint32          image_id;
+  GError         *error = NULL;
 
-              g_object_unref (metadata);
-            }
+  INIT_I18N ();
+  gegl_init (NULL, NULL);
 
-          g_object_unref (file);
+  filename = g_value_get_string (gimp_value_array_index (args, 0));
 
-          *nreturn_vals = 2;
-          values[1].type         = GIMP_PDB_IMAGE;
-          values[1].data.d_image = image_ID;
-        }
-      else
-        {
-          status = GIMP_PDB_EXECUTION_ERROR;
-        }
-    }
-  else if (strcmp (name, LOAD_THUMB_PROC) == 0)
-    {
-      if (nparams < 2)
-        {
-          status = GIMP_PDB_CALLING_ERROR;
-        }
-      else
-        {
-          const gchar *filename = param[0].data.d_string;
-          gint         width    = 0;
-          gint         height   = 0;
-
-          image_ID = load_thumbnail_image (filename, &width, &height, &error);
-
-          if (image_ID != -1)
-            {
-              *nreturn_vals = 4;
-              values[1].type         = GIMP_PDB_IMAGE;
-              values[1].data.d_image = image_ID;
-              values[2].type         = GIMP_PDB_INT32;
-              values[2].data.d_int32 = width;
-              values[3].type         = GIMP_PDB_INT32;
-              values[3].data.d_int32 = height;
-            }
-          else
-            {
-              status = GIMP_PDB_EXECUTION_ERROR;
-            }
-        }
-    }
-  else if (strcmp (name, SAVE_PROC) == 0)
-    {
-      gint32                 drawable_id;
-      GimpMetadata          *metadata;
-      GimpMetadataSaveFlags  metadata_flags;
-      GimpExportReturn       export = GIMP_EXPORT_IGNORE;
+  image_id = load_thumbnail_image (filename,&width, &height, &error);
 
-      IFDBG(2) g_debug ("\n---------------- %s ----------------\n",
-                        param[3].data.d_string);
+  if (image_id < 1)
+    return gimp_procedure_new_return_values (procedure,
+                                             GIMP_PDB_EXECUTION_ERROR,
+                                             error);
 
-      image_ID    = param[1].data.d_int32;
-      drawable_id = param[2].data.d_int32;
+  return_vals = gimp_procedure_new_return_values (procedure,
+                                                  GIMP_PDB_SUCCESS,
+                                                  NULL);
 
-      switch (run_mode)
-        {
-        case GIMP_RUN_INTERACTIVE:
-        case GIMP_RUN_WITH_LAST_VALS:
-          gimp_ui_init (PLUG_IN_BINARY, FALSE);
-
-          export = gimp_export_image (&image_ID, &drawable_id, "PSD",
-                                      GIMP_EXPORT_CAN_HANDLE_RGB     |
-                                      GIMP_EXPORT_CAN_HANDLE_GRAY    |
-                                      GIMP_EXPORT_CAN_HANDLE_INDEXED |
-                                      GIMP_EXPORT_CAN_HANDLE_ALPHA   |
-                                      GIMP_EXPORT_CAN_HANDLE_LAYERS  |
-                                      GIMP_EXPORT_CAN_HANDLE_LAYER_MASKS);
-
-          if (export == GIMP_EXPORT_CANCEL)
-            {
-              values[0].data.d_status = GIMP_PDB_CANCEL;
-              return;
-            }
-          break;
-
-        default:
-          break;
-        }
+  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);
+
+  return return_vals;
+}
 
-      metadata = gimp_image_metadata_save_prepare (image_ID,
-                                                   "image/x-psd",
-                                                   &metadata_flags);
+static GimpValueArray *
+psd_save (GimpProcedure        *procedure,
+          GimpRunMode           run_mode,
+          gint32                image_id,
+          gint32                drawable_id,
+          GFile                *file,
+          const GimpValueArray *args,
+          gpointer              run_data)
+{
+  GimpPDBStatusType      status = GIMP_PDB_SUCCESS;
+  GimpMetadata          *metadata;
+  GimpMetadataSaveFlags  metadata_flags;
+  GimpExportReturn       export = GIMP_EXPORT_IGNORE;
+  GError                *error = NULL;
 
-      if (save_image (param[3].data.d_string, image_ID, &error))
-        {
-          if (metadata)
-            {
-              GFile *file;
+  INIT_I18N ();
+  gegl_init (NULL, NULL);
 
-              gimp_metadata_set_bits_per_sample (metadata, 8);
+  switch (run_mode)
+    {
+    case GIMP_RUN_INTERACTIVE:
+    case GIMP_RUN_WITH_LAST_VALS:
+      gimp_ui_init (PLUG_IN_BINARY, FALSE);
+
+      export = gimp_export_image (&image_id, &drawable_id, "PSD",
+                                  GIMP_EXPORT_CAN_HANDLE_RGB     |
+                                  GIMP_EXPORT_CAN_HANDLE_GRAY    |
+                                  GIMP_EXPORT_CAN_HANDLE_INDEXED |
+                                  GIMP_EXPORT_CAN_HANDLE_ALPHA   |
+                                  GIMP_EXPORT_CAN_HANDLE_LAYERS  |
+                                  GIMP_EXPORT_CAN_HANDLE_LAYER_MASKS);
+
+      if (export == GIMP_EXPORT_CANCEL)
+        return gimp_procedure_new_return_values (procedure, GIMP_PDB_CANCEL,
+                                                 NULL);
+      break;
+
+    default:
+      break;
+    }
 
-              file = g_file_new_for_path (param[3].data.d_string);
-              gimp_image_metadata_save_finish (image_ID,
+  metadata = gimp_image_metadata_save_prepare (image_id,
                                                "image/x-psd",
-                                               metadata, metadata_flags,
-                                               file, NULL);
-              g_object_unref (file);
-            }
+                                               &metadata_flags);
 
-          values[0].data.d_status = GIMP_PDB_SUCCESS;
-        }
-      else
+  if (save_image (g_file_get_path (file), image_id, &error))
+    {
+      if (metadata)
         {
-          values[0].data.d_status = GIMP_PDB_EXECUTION_ERROR;
-
-          if (error)
-            {
-              *nreturn_vals = 2;
-              values[1].type          = GIMP_PDB_STRING;
-              values[1].data.d_string = error->message;
-            }
-        }
-
-      if (export == GIMP_EXPORT_EXPORT)
-        gimp_image_delete (image_ID);
+          gimp_metadata_set_bits_per_sample (metadata, 8);
 
-      if (metadata)
-        g_object_unref (metadata);
+          gimp_image_metadata_save_finish (image_id,
+                                           "image/x-psd",
+                                           metadata, metadata_flags,
+                                           file, NULL);
+        }
     }
-
-  /* Unknown procedure */
   else
     {
-      status = GIMP_PDB_CALLING_ERROR;
+      status = GIMP_PDB_EXECUTION_ERROR;
     }
 
-  if (status != GIMP_PDB_SUCCESS && error)
-    {
-      *nreturn_vals = 2;
-      values[1].type          = GIMP_PDB_STRING;
-      values[1].data.d_string = error->message;
-    }
+  if (export == GIMP_EXPORT_EXPORT)
+    gimp_image_delete (image_id);
+
+  if (metadata)
+    g_object_unref (metadata);
 
-  values[0].data.d_status = status;
+  return gimp_procedure_new_return_values (procedure, status, error);
 }


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