[gimp] plug-ins: port file-raw-data to GimpPlugIn and libgmp objects



commit ee5a93f36842c678c5581c7d423f8c9e45914749
Author: Michael Natterer <mitch gimp org>
Date:   Sat Aug 24 12:33:18 2019 +0200

    plug-ins: port file-raw-data to GimpPlugIn and libgmp objects

 plug-ins/common/Makefile.am     |   2 -
 plug-ins/common/file-raw-data.c | 997 +++++++++++++++++++---------------------
 plug-ins/common/plugin-defs.pl  |   2 +-
 3 files changed, 464 insertions(+), 537 deletions(-)
---
diff --git a/plug-ins/common/Makefile.am b/plug-ins/common/Makefile.am
index 8086fe8d49..1199cd530e 100644
--- a/plug-ins/common/Makefile.am
+++ b/plug-ins/common/Makefile.am
@@ -1061,8 +1061,6 @@ file_psp_LDADD = \
        $(INTLLIBS)             \
        $(file_psp_RC)
 
-file_raw_data_CPPFLAGS = $(AM_CPPFLAGS) -DGIMP_DEPRECATED_REPLACE_NEW_API
-
 file_raw_data_SOURCES = \
        file-raw-data.c
 
diff --git a/plug-ins/common/file-raw-data.c b/plug-ins/common/file-raw-data.c
index 8f232b6b76..9b50233b25 100644
--- a/plug-ins/common/file-raw-data.c
+++ b/plug-ins/common/file-raw-data.c
@@ -49,15 +49,13 @@
 #define LOAD_PROC         "file-raw-load"
 #define LOAD_HGT_PROC     "file-hgt-load"
 #define SAVE_PROC         "file-raw-save"
-#define SAVE_PROC2        "file-raw-save2"
-#define GET_DEFAULTS_PROC "file-raw-get-defaults"
-#define SET_DEFAULTS_PROC "file-raw-set-defaults"
 #define PLUG_IN_BINARY    "file-raw-data"
 #define PLUG_IN_ROLE      "gimp-file-raw-data"
 #define PREVIEW_SIZE      350
 
 #define RAW_DEFAULTS_PARASITE  "raw-save-defaults"
 
+
 #define GIMP_PLUGIN_HGT_LOAD_ERROR gimp_plugin_hgt_load_error_quark ()
 
 typedef enum
@@ -71,6 +69,7 @@ gimp_plugin_hgt_load_error_quark (void)
   return g_quark_from_static_string ("gimp-plugin-hgt-load-error-quark");
 }
 
+
 typedef enum
 {
   RAW_RGB,          /* RGB Image */
@@ -128,69 +127,104 @@ typedef struct
 {
   FILE         *fp;        /* pointer to the already open file */
   GeglBuffer   *buffer;    /* gimp drawable buffer             */
-  gint32        image_id;  /* gimp image id                    */
+  GimpImage    *image;     /* gimp image                       */
   guchar        cmap[768]; /* color map for indexed images     */
 } RawGimpData;
 
 
-static void              query                     (void);
-static void              run                       (const gchar      *name,
-                                                    gint              nparams,
-                                                    const GimpParam  *param,
-                                                    gint             *nreturn_vals,
-                                                    GimpParam       **return_vals);
+typedef struct _Raw      Raw;
+typedef struct _RawClass RawClass;
+
+struct _Raw
+{
+  GimpPlugIn      parent_instance;
+};
+
+struct _RawClass
+{
+  GimpPlugInClass parent_class;
+};
+
+
+#define RAW_TYPE  (raw_get_type ())
+#define RAW (obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), RAW_TYPE, Raw))
+
+GType                   raw_get_type         (void) G_GNUC_CONST;
+
+static GList          * raw_query_procedures (GimpPlugIn           *plug_in);
+static GimpProcedure  * raw_create_procedure (GimpPlugIn           *plug_in,
+                                              const gchar          *name);
+
+static GimpValueArray * raw_load             (GimpProcedure        *procedure,
+                                              GimpRunMode           run_mode,
+                                              GFile                *file,
+                                              const GimpValueArray *args,
+                                              gpointer              run_data);
+static GimpValueArray * raw_save             (GimpProcedure        *procedure,
+                                              GimpRunMode           run_mode,
+                                              GimpImage            *image,
+                                              GimpDrawable         *drawable,
+                                              GFile                *file,
+                                              const GimpValueArray *args,
+                                              gpointer              run_data);
 
 /* prototypes for the new load functions */
-static gboolean          raw_load_standard         (RawGimpData      *data,
-                                                    gint              bpp);
-static gboolean          raw_load_gray             (RawGimpData      *data,
-                                                    gint              bpp,
-                                                    gint              bitspp);
-static gboolean          raw_load_rgb565           (RawGimpData      *data,
-                                                    RawType           type);
-static gboolean          raw_load_planar           (RawGimpData      *data);
-static gboolean          raw_load_palette          (RawGimpData      *data,
-                                                    const gchar      *palette_filename);
+static gboolean         raw_load_standard    (RawGimpData          *data,
+                                              gint                  bpp);
+static gboolean         raw_load_gray        (RawGimpData          *data,
+                                              gint                  bpp,
+                                              gint                  bitspp);
+static gboolean         raw_load_rgb565      (RawGimpData          *data,
+                                              RawType               type);
+static gboolean         raw_load_planar      (RawGimpData          *data);
+static gboolean         raw_load_palette     (RawGimpData          *data,
+                                              const gchar          *palette_filename);
 
 /* support functions */
-static goffset           get_file_info             (const gchar      *filename);
-static void              raw_read_row              (FILE             *fp,
-                                                    guchar           *buf,
-                                                    gint32            offset,
-                                                    gint32            size);
-static int               mmap_read                 (gint              fd,
-                                                    gpointer          buf,
-                                                    gint32            len,
-                                                    gint32            pos,
-                                                    gint              rowstride);
-static void              rgb_565_to_888            (guint16          *in,
-                                                    guchar           *out,
-                                                    gint32            num_pixels,
-                                                    RawType           type);
-
-static gint32            load_image                (const gchar      *filename,
-                                                    GError          **error);
-static gboolean          save_image                (const gchar      *filename,
-                                                    gint32            image_id,
-                                                    gint32            drawable_id,
-                                                    GError          **error);
+static goffset          get_file_info        (const gchar          *filename);
+static void             raw_read_row         (FILE                 *fp,
+                                              guchar               *buf,
+                                              gint32                offset,
+                                              gint32                size);
+static int              mmap_read            (gint                  fd,
+                                              gpointer              buf,
+                                              gint32                len,
+                                              gint32                pos,
+                                              gint                  rowstride);
+static void             rgb_565_to_888       (guint16              *in,
+                                              guchar               *out,
+                                              gint32                num_pixels,
+                                              RawType               type);
+
+static GimpImage      * load_image           (const gchar          *filename,
+                                              GError              **error);
+static gboolean         save_image           (const gchar          *filename,
+                                              GimpImage            *image,
+                                              GimpDrawable         *drawable,
+                                              GError              **error);
 
 /* gui functions */
-static void              preview_update_size       (GimpPreviewArea  *preview);
-static void              preview_update            (GimpPreviewArea  *preview);
-static void              palette_update            (GimpPreviewArea  *preview);
-static gboolean          load_dialog               (const gchar      *filename,
-                                                    gboolean          is_hgt);
-static gboolean          save_dialog               (gint32            image_id);
-static void              save_dialog_response      (GtkWidget        *widget,
-                                                    gint              response_id,
-                                                    gpointer          data);
-static void              palette_callback          (GtkFileChooser   *button,
-                                                    GimpPreviewArea  *preview);
-
-static void              load_defaults             (void);
-static void              save_defaults             (void);
-static void              load_gui_defaults         (RawSaveGui        *rg);
+static void             preview_update_size  (GimpPreviewArea      *preview);
+static void             preview_update       (GimpPreviewArea      *preview);
+static void             palette_update       (GimpPreviewArea      *preview);
+static gboolean         load_dialog          (const gchar          *filename,
+                                              gboolean              is_hgt);
+static gboolean         save_dialog          (GimpImage            *image);
+static void             save_dialog_response (GtkWidget            *widget,
+                                              gint                  response_id,
+                                              gpointer              data);
+static void             palette_callback     (GtkFileChooser       *button,
+                                              GimpPreviewArea      *preview);
+
+static void             load_defaults        (void);
+static void             save_defaults        (void);
+static void             load_gui_defaults    (RawSaveGui            *rg);
+
+
+G_DEFINE_TYPE (Raw, raw, GIMP_TYPE_PLUG_IN)
+
+GIMP_MAIN (RAW_TYPE)
+
 
 static RawConfig *runtime             = NULL;
 static gchar     *palfile             = NULL;
@@ -198,14 +232,6 @@ static gint       preview_fd          = -1;
 static guchar     preview_cmap[1024];
 static gboolean   preview_cmap_update = TRUE;
 
-const GimpPlugInInfo PLUG_IN_INFO =
-{
-  NULL,   /* init_proc  */
-  NULL,   /* quit_proc  */
-  query,  /* query_proc */
-  run,    /* run_proc   */
-};
-
 static const RawSaveVals defaults =
 {
   RAW_RGB,
@@ -214,507 +240,410 @@ static const RawSaveVals defaults =
 
 static RawSaveVals rawvals;
 
-MAIN()
 
 static void
-query (void)
+raw_class_init (RawClass *klass)
 {
-  static const GimpParamDef load_args[] =
-  {
-    { GIMP_PDB_INT32,  "run-mode",     "The run mode { RUN-INTERACTIVE (0) }"                  },
-    { GIMP_PDB_STRING, "filename",     "The name of the file to load" },
-    { GIMP_PDB_STRING, "raw-filename", "The name entered"             }
-  };
-
-  static const GimpParamDef load_hgt_args[] =
-  {
-    { GIMP_PDB_INT32,  "run-mode",     "The run mode { RUN-INTERACTIVE (0) }"    },
-    { GIMP_PDB_STRING, "filename",     "The name of the file to load"            },
-    { GIMP_PDB_STRING, "raw-filename", "The name entered"                        },
-    { GIMP_PDB_INT32,  "samplespacing", "The sample spacing of the data. "
-                                         "Only supported values are 0, 1 and 3 "
-                                         "(respectively auto-detect, SRTM-1 "
-                                         "and SRTM-3 data)"                      },
-  };
-
-  static const GimpParamDef load_return_vals[] =
-  {
-    { GIMP_PDB_IMAGE, "image", "Output image" }
-  };
-
-#define COMMON_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 entered"             }
-
-#define CONFIG_ARGS \
-    { GIMP_PDB_INT32,    "image-type",   "The image type { RAW_RGB (0), RAW_PLANAR (3) }" }, \
-    { GIMP_PDB_INT32,    "palette-type", "The palette type { RAW_PALETTE_RGB (0), RAW_PALETTE_BGR (1) }" }
-
-  static const GimpParamDef save_args[] =
-  {
-    COMMON_SAVE_ARGS
-  };
-
-  static const GimpParamDef save_args2[] =
-  {
-    COMMON_SAVE_ARGS,
-    CONFIG_ARGS
-  };
-
-  static const GimpParamDef save_get_defaults_return_vals[] =
-  {
-    CONFIG_ARGS
-  };
-
-  static const GimpParamDef save_args_set_defaults[] =
-  {
-    CONFIG_ARGS
-  };
-
-  gimp_install_procedure (LOAD_PROC,
-                          "Load raw images, specifying image information",
-                          "Load raw images, specifying image information",
-                          "timecop, pg futureware at",
-                          "timecop, pg futureware at",
-                          "Aug 2004",
-                          N_("Raw image data"),
-                          NULL,
-                          GIMP_PLUGIN,
-                          G_N_ELEMENTS (load_args),
-                          G_N_ELEMENTS (load_return_vals),
-                          load_args, load_return_vals);
-  gimp_register_load_handler (LOAD_PROC, "data", "");
-
-  gimp_install_procedure (LOAD_HGT_PROC,
-                          "Load HGT data as images",
-                          "Load Digital Elevation Model data in HGT format "
-                          "from the Shuttle Radar Topography Mission as "
-                          "images. Though the output image will be RGB, all "
-                          "colors are grayscale by default and the contrast "
-                          "will be quite low on most earth relief. Therefore "
-                          "You will likely want to remap elevation to colors "
-                          "as a second step, for instance with the \"Gradient "
-                          "Map\" plug-in.",
-                          "",
-                          "",
-                          "2017-12-09",
-                          N_("Digital Elevation Model data"),
-                          NULL,
-                          GIMP_PLUGIN,
-                          G_N_ELEMENTS (load_hgt_args),
-                          G_N_ELEMENTS (load_return_vals),
-                          load_hgt_args, load_return_vals);
-  gimp_register_load_handler (LOAD_HGT_PROC, "hgt", "");
-
-  gimp_install_procedure (SAVE_PROC,
-                          "Dump images to disk in raw format",
-                          "This plug-in dumps images to disk in raw format, "
-                          "using the default settings stored as a parasite.",
-                          "timecop, pg futureware at",
-                          "timecop, pg futureware at",
-                          "Aug 2004",
-                          N_("Raw image data"),
-                          "INDEXED, GRAY, RGB, RGBA",
-                          GIMP_PLUGIN,
-                          G_N_ELEMENTS (save_args), 0,
-                          save_args, NULL);
-
-  gimp_install_procedure (SAVE_PROC2,
-                          "Dump images to disk in raw format",
-                          "Dump images to disk in raw format",
-                          "Björn Kautler, Bjoern Kautler net",
-                          "Björn Kautler, Bjoern Kautler net",
-                          "April 2014",
-                          N_("Raw image data"),
-                          "INDEXED, GRAY, RGB, RGBA",
-                          GIMP_PLUGIN,
-                          G_N_ELEMENTS (save_args2), 0,
-                          save_args2, NULL);
-
-  gimp_register_save_handler (SAVE_PROC2, "data,raw", "");
-
-  gimp_install_procedure (GET_DEFAULTS_PROC,
-                          "Get the current set of defaults used by the "
-                          "raw image data dump plug-in",
-                          "This procedure returns the current set of "
-                          "defaults stored as a parasite for the raw "
-                          "image data dump plug-in. "
-                          "These defaults are used to seed the UI, by the "
-                          "file_raw_save_defaults procedure, and by "
-                          "gimp_file_save when it detects to use RAW.",
-                          "Björn Kautler, Bjoern Kautler net",
-                          "Björn Kautler, Bjoern Kautler net",
-                          "April 2014",
-                          NULL,
-                          NULL,
-                          GIMP_PLUGIN,
-                          0, G_N_ELEMENTS (save_get_defaults_return_vals),
-                          NULL, save_get_defaults_return_vals);
-
-  gimp_install_procedure (SET_DEFAULTS_PROC,
-                          "Set the current set of defaults used by the "
-                          "raw image dump plug-in",
-                          "This procedure sets the current set of defaults "
-                          "stored as a parasite for the raw image data dump plug-in. "
-                          "These defaults are used to seed the UI, by the "
-                          "file_raw_save_defaults procedure, and by "
-                          "gimp_file_save when it detects to use RAW.",
-                          "Björn Kautler, Bjoern Kautler net",
-                          "Björn Kautler, Bjoern Kautler net",
-                          "April 2014",
-                          NULL,
-                          NULL,
-                          GIMP_PLUGIN,
-                          G_N_ELEMENTS (save_args_set_defaults), 0,
-                          save_args_set_defaults, NULL);
+  GimpPlugInClass *plug_in_class = GIMP_PLUG_IN_CLASS (klass);
+
+  plug_in_class->query_procedures = raw_query_procedures;
+  plug_in_class->create_procedure = raw_create_procedure;
 }
 
 static void
-run (const gchar      *name,
-     gint              nparams,
-     const GimpParam  *param,
-     gint             *nreturn_vals,
-     GimpParam       **return_vals)
+raw_init (Raw *raw)
+{
+}
+
+static GList *
+raw_query_procedures (GimpPlugIn *plug_in)
+{
+  GList *list = NULL;
+
+  list = g_list_append (list, g_strdup (LOAD_PROC));
+  list = g_list_append (list, g_strdup (LOAD_HGT_PROC));
+  list = g_list_append (list, g_strdup (SAVE_PROC));
+
+  return list;
+}
+
+static GimpProcedure *
+raw_create_procedure (GimpPlugIn  *plug_in,
+                      const gchar *name)
 {
-  static GimpParam   values[3];
-  GimpRunMode        run_mode;
+  GimpProcedure *procedure = NULL;
+
+  if (! strcmp (name, LOAD_PROC))
+    {
+      procedure = gimp_load_procedure_new (plug_in, name, GIMP_PLUGIN,
+                                           raw_load, NULL, NULL);
+
+      gimp_procedure_set_menu_label (procedure, N_("Raw image data"));
+
+      gimp_procedure_set_documentation (procedure,
+                                        "Load raw images, specifying image "
+                                        "information",
+                                        "Load raw images, specifying image "
+                                        "information",
+                                        name);
+      gimp_procedure_set_attribution (procedure,
+                                      "timecop, pg futureware at",
+                                      "timecop, pg futureware at",
+                                      "Aug 2004");
+
+      gimp_file_procedure_set_extensions (GIMP_FILE_PROCEDURE (procedure),
+                                          "data");
+    }
+  else if (! strcmp (name, LOAD_HGT_PROC))
+    {
+      procedure = gimp_load_procedure_new (plug_in, name, GIMP_PLUGIN,
+                                           raw_load, NULL, NULL);
+
+      gimp_procedure_set_menu_label (procedure,
+                                     N_("Digital Elevation Model data"));
+
+      gimp_procedure_set_documentation (procedure,
+                                        "Load HGT data as images",
+                                        "Load Digital Elevation Model data "
+                                        "in HGT format from the Shuttle Radar "
+                                        "Topography Mission as images. Though "
+                                        "the output image will be RGB, all "
+                                        "colors are grayscale by default and "
+                                        "the contrast will be quite low on "
+                                        "most earth relief. Therefore You "
+                                        "will likely want to remap elevation "
+                                        "to colors as a second step, for "
+                                        "instance with the \"Gradient Map\" "
+                                        "plug-in.",
+                                        name);
+      gimp_procedure_set_attribution (procedure,
+                                      NULL, NULL,
+                                      "2017-12-09");
+
+      gimp_file_procedure_set_extensions (GIMP_FILE_PROCEDURE (procedure),
+                                          "hgt");
+
+      GIMP_PROC_ARG_INT (procedure, "sample-spacing",
+                         "Sample spacing",
+                         "The sample spacing of the data. "
+                         "(0: auto-detect, 1: SRTM-1, 2: SRTM-3 data)",
+                         0, 2, 0,
+                         G_PARAM_READWRITE);
+    }
+  else if (! strcmp (name, SAVE_PROC))
+    {
+      procedure = gimp_save_procedure_new (plug_in, name, GIMP_PLUGIN,
+                                           raw_save, NULL, NULL);
+
+      gimp_procedure_set_image_types (procedure, "INDEXED, GRAY, RGB, RGBA");
+
+      gimp_procedure_set_menu_label (procedure, N_("Raw image data"));
+
+      gimp_procedure_set_documentation (procedure,
+                                        "Dump images to disk in raw format",
+                                        "Dump images to disk in raw format",
+                                        name);
+      gimp_procedure_set_attribution (procedure,
+                                      "Björn Kautler, Bjoern Kautler net",
+                                      "Björn Kautler, Bjoern Kautler net",
+                                      "April 2014");
+
+      gimp_file_procedure_set_extensions (GIMP_FILE_PROCEDURE (procedure),
+                                          "data,raw");
+
+      GIMP_PROC_ARG_INT (procedure, "image-type",
+                         "Image type",
+                         "The image type { RAW_RGB (0), RAW_PLANAR (3) }",
+                         0, 3, 0,
+                         G_PARAM_READWRITE);
+
+      GIMP_PROC_ARG_INT (procedure, "palette-type",
+                         "Palette type",
+                         "The palette type "
+                         "{ RAW_PALETTE_RGB (0), RAW_PALETTE_BGR (1) }",
+                         0, 1, 0,
+                         G_PARAM_READWRITE);
+    }
+
+  return procedure;
+}
+
+static GimpValueArray *
+raw_load (GimpProcedure        *procedure,
+          GimpRunMode           run_mode,
+          GFile                *file,
+          const GimpValueArray *args,
+          gpointer              run_data)
+{
+  GimpValueArray    *return_vals;
+  gboolean           is_hgt;
   GimpPDBStatusType  status = GIMP_PDB_SUCCESS;
+  GimpImage         *image  = NULL;
   GError            *error  = NULL;
-  gint32             image_id;
-  gint32             drawable_id;
-  GimpExportReturn   export = GIMP_EXPORT_CANCEL;
 
   INIT_I18N ();
   gegl_init (NULL, NULL);
 
-  *nreturn_vals = 1;
-  *return_vals  = values;
-
-  values[0].type          = GIMP_PDB_STATUS;
-  values[0].data.d_status = GIMP_PDB_EXECUTION_ERROR;
+  is_hgt = (! strcmp (gimp_procedure_get_name (procedure), LOAD_HGT_PROC));
 
-  if (strcmp (name, LOAD_PROC) == 0 ||
-      strcmp (name, LOAD_HGT_PROC) == 0)
-    {
-      GFile *file = g_file_new_for_uri (param[1].data.d_string);
+  /* allocate config structure and fill with defaults */
+  runtime = g_new0 (RawConfig, 1);
 
-      gboolean is_hgt = (strcmp (name, LOAD_HGT_PROC) == 0);
+  runtime->file_offset    = 0;
+  runtime->palette_offset = 0;
+  runtime->palette_type   = RAW_PALETTE_RGB;
 
-      run_mode = param[0].data.d_int32;
+  if (is_hgt)
+    {
+      FILE  *fp;
+      glong  pos;
+      gint   hgt_size;
 
-      /* allocate config structure and fill with defaults */
-      runtime = g_new0 (RawConfig, 1);
+      runtime->image_type = RAW_GRAY_16BPP_SBE;
 
-      runtime->file_offset    = 0;
-      runtime->palette_offset = 0;
-      runtime->palette_type   = RAW_PALETTE_RGB;
-      if (is_hgt)
+      fp = g_fopen (g_file_get_path (file), "rb");
+      if (! fp)
         {
-          FILE  *fp;
-          glong  pos;
-          gint   hgt_size;
+          g_set_error (&error, G_FILE_ERROR, g_file_error_from_errno (errno),
+                       _("Could not open '%s' for size verification: %s"),
+                       gimp_file_get_utf8_name (file),
+                       g_strerror (errno));
 
-          runtime->image_type   = RAW_GRAY_16BPP_SBE;
+          status = GIMP_PDB_EXECUTION_ERROR;
+        }
+      else
+        {
+          fseek (fp, 0, SEEK_END);
+          pos = ftell (fp);
 
-          fp = g_fopen (g_file_get_path (file), "rb");
-          if (! fp)
+          /* HGT files have always the same size, either 1201*1201
+           * or 3601*3601 of 16-bit values.
+           */
+          if (pos == 1201*1201*2)
+            {
+              hgt_size = 1201;
+            }
+          else if (pos == 3601*3601*2)
             {
-              g_set_error (&error, G_FILE_ERROR, g_file_error_from_errno (errno),
-                           _("Could not open '%s' for size verification: %s"),
-                           gimp_file_get_utf8_name (file),
-                           g_strerror (errno));
-              status = GIMP_PDB_EXECUTION_ERROR;
+              hgt_size = 3601;
             }
           else
             {
-              fseek (fp, 0, SEEK_END);
-              pos = ftell (fp);
-
-              /* HGT files have always the same size, either 1201*1201
-               * or 3601*3601 of 16-bit values.
+              /* As a special exception, if the file looks like an HGT
+               * format from extension, yet it doesn't have the right
+               * size, we will degrade a bit the experience by adding
+               * sample spacing choice.
                */
-              if (pos == 1201*1201*2)
-                {
-                  hgt_size = 1201;
-                }
-              else if (pos == 3601*3601*2)
-                {
-                  hgt_size = 3601;
-                }
-              else
-                {
-                  /* As a special exception, if the file looks like an HGT
-                   * format from extension, yet it doesn't have the right
-                   * size, we will degrade a bit the experience by
-                   * adding sample spacing choice.
-                   */
-                  hgt_size = 0;
-                }
-              runtime->image_width  = hgt_size;
-              runtime->image_height = hgt_size;
-
-              fclose (fp);
+              hgt_size = 0;
             }
-        }
-      else
-        {
-          runtime->image_width  = PREVIEW_SIZE;
-          runtime->image_height = PREVIEW_SIZE;
-          runtime->image_type   = RAW_RGB;
-        }
 
-      if (run_mode == GIMP_RUN_INTERACTIVE)
-        {
-          if (! is_hgt)
-            gimp_get_data (LOAD_PROC, runtime);
+          runtime->image_width  = hgt_size;
+          runtime->image_height = hgt_size;
 
-          preview_fd = g_open (g_file_get_path (file), O_RDONLY, 0);
-          if (preview_fd < 0)
-            {
-              g_set_error (&error,
-                           G_FILE_ERROR, g_file_error_from_errno (errno),
-                           _("Could not open '%s' for reading: %s"),
-                           gimp_file_get_utf8_name (file),
-                           g_strerror (errno));
+          fclose (fp);
+        }
+    }
+  else
+    {
+      runtime->image_width  = PREVIEW_SIZE;
+      runtime->image_height = PREVIEW_SIZE;
+      runtime->image_type   = RAW_RGB;
+    }
 
-              status = GIMP_PDB_EXECUTION_ERROR;
-            }
-          else
-            {
-              if (! load_dialog (g_file_get_path (file), is_hgt))
-                status = GIMP_PDB_CANCEL;
+  if (run_mode == GIMP_RUN_INTERACTIVE)
+    {
+      if (! is_hgt)
+        gimp_get_data (LOAD_PROC, runtime);
 
-              close (preview_fd);
-            }
-        }
-      else if (is_hgt) /* HGT file in non-interactive mode. */
+      preview_fd = g_open (g_file_get_path (file), O_RDONLY, 0);
+      if (preview_fd < 0)
         {
-          gint32 sample_spacing = param[3].data.d_int32;
+          g_set_error (&error,
+                       G_FILE_ERROR, g_file_error_from_errno (errno),
+                       _("Could not open '%s' for reading: %s"),
+                       gimp_file_get_utf8_name (file),
+                       g_strerror (errno));
 
-          if (sample_spacing != 0 &&
-              sample_spacing != 1 &&
-              sample_spacing != 3)
-            {
-              status = GIMP_PDB_CALLING_ERROR;
-              g_set_error (&error,
-                           GIMP_PLUGIN_HGT_LOAD_ERROR, GIMP_PLUGIN_HGT_LOAD_ARGUMENT_ERROR,
-                           _("%d is not a valid sample spacing. "
-                             "Valid values are: 0 (auto-detect), 1 and 3."),
-                           sample_spacing);
-            }
-          else
-            {
-              switch (sample_spacing)
-                {
-                case 0:
-                  /* Auto-detection already occurred. Let's just check if
-                   *it was successful.
-                   */
-                  if (runtime->image_width != 1201 &&
-                      runtime->image_width != 3601)
-                    {
-                      status = GIMP_PDB_CALLING_ERROR;
-                      g_set_error (&error,
-                                   G_FILE_ERROR, G_FILE_ERROR_INVAL,
-                                   _("Auto-detection of sample spacing failed. "
-                                     "\"%s\" does not appear to be a valid HGT file "
-                                     "or its variant is not supported yet. "
-                                     "Supported HGT files are: SRTM-1 and SRTM-3. "
-                                     "If you know the variant, run with argument 1 or 3."),
-                                   gimp_file_get_utf8_name (file));
-                    }
-                  break;
-                case 1:
-                  runtime->image_width  = 3601;
-                  runtime->image_height = 3601;
-                  break;
-                default: /* 3 */
-                  runtime->image_width  = 1201;
-                  runtime->image_height = 1201;
-                  break;
-                }
-              status = GIMP_PDB_SUCCESS;
-            }
+          status = GIMP_PDB_EXECUTION_ERROR;
         }
       else
         {
-          /* we only run interactively due to the nature of this plugin.
-           * things like generate preview etc like to call us non-
-           * interactively.  here we stop that.
-           */
-          status = GIMP_PDB_CALLING_ERROR;
+          if (! load_dialog (g_file_get_path (file), is_hgt))
+            status = GIMP_PDB_CANCEL;
+
+          close (preview_fd);
         }
+    }
+  else if (is_hgt) /* HGT file in non-interactive mode. */
+    {
+      gint32 sample_spacing = GIMP_VALUES_GET_INT (args, 0);
 
-      /* we are okay, and the user clicked OK in the load dialog */
-      if (status == GIMP_PDB_SUCCESS)
+      if (sample_spacing != 0 &&
+          sample_spacing != 1 &&
+          sample_spacing != 3)
         {
-          image_id = load_image (g_file_get_path (file), &error);
+          g_set_error (&error,
+                       GIMP_PLUGIN_HGT_LOAD_ERROR, GIMP_PLUGIN_HGT_LOAD_ARGUMENT_ERROR,
+                       _("%d is not a valid sample spacing. "
+                         "Valid values are: 0 (auto-detect), 1 and 3."),
+                       sample_spacing);
 
-          if (image_id != -1)
+          status = GIMP_PDB_CALLING_ERROR;
+        }
+      else
+        {
+          switch (sample_spacing)
             {
-              if (! is_hgt)
-                gimp_set_data (LOAD_PROC, runtime, sizeof (RawConfig));
+            case 0:
+              /* Auto-detection already occurred. Let's just check if
+               *it was successful.
+               */
+              if (runtime->image_width != 1201 &&
+                  runtime->image_width != 3601)
+                {
+                  g_set_error (&error,
+                               G_FILE_ERROR, G_FILE_ERROR_INVAL,
+                               _("Auto-detection of sample spacing failed. "
+                                 "\"%s\" does not appear to be a valid HGT file "
+                                 "or its variant is not supported yet. "
+                                 "Supported HGT files are: SRTM-1 and SRTM-3. "
+                                 "If you know the variant, run with argument 1 or 3."),
+                               gimp_file_get_utf8_name (file));
 
-              *nreturn_vals = 2;
-              values[1].type         = GIMP_PDB_IMAGE;
-              values[1].data.d_image = image_id;
-            }
-          else
-            {
-              status = GIMP_PDB_EXECUTION_ERROR;
+                  status = GIMP_PDB_CALLING_ERROR;
+                }
+              break;
+
+            case 1:
+              runtime->image_width  = 3601;
+              runtime->image_height = 3601;
+              break;
+
+            default: /* 3 */
+              runtime->image_width  = 1201;
+              runtime->image_height = 1201;
+              break;
             }
         }
-      if (status != GIMP_PDB_SUCCESS && error)
+    }
+  else
+    {
+      /* we only run interactively due to the nature of this plugin.
+       * things like generate preview etc like to call us non-
+       * interactively.  here we stop that.
+       */
+      status = GIMP_PDB_CALLING_ERROR;
+    }
+
+  /* we are okay, and the user clicked OK in the load dialog */
+  if (status == GIMP_PDB_SUCCESS)
+    {
+      image = load_image (g_file_get_path (file), &error);
+
+      if (image)
         {
-          g_warning ("Loading \"%s\" failed with error: %s",
-                     gimp_file_get_utf8_name (file),
-                     error->message);
+          if (! is_hgt)
+            gimp_set_data (LOAD_PROC, runtime, sizeof (RawConfig));
         }
-
-      g_free (runtime);
     }
-  else if (strcmp (name, SAVE_PROC) == 0 ||
-           strcmp (name, SAVE_PROC2) == 0)
+
+  if (status != GIMP_PDB_SUCCESS && error)
     {
-      GFile *file = g_file_new_for_uri (param[3].data.d_string);
+      g_printerr ("Loading \"%s\" failed with error: %s",
+                  gimp_file_get_utf8_name (file),
+                  error->message);
+    }
 
-      run_mode    = param[0].data.d_int32;
-      image_id    = param[1].data.d_int32;
-      drawable_id = param[2].data.d_int32;
+  g_free (runtime);
 
-      load_defaults ();
+  if (! image)
+    return gimp_procedure_new_return_values (procedure, status, error);
 
-      /* export the image */
-      export = gimp_export_image (&image_id, &drawable_id, "RAW",
-                                  GIMP_EXPORT_CAN_HANDLE_RGB     |
-                                  GIMP_EXPORT_CAN_HANDLE_GRAY    |
-                                  GIMP_EXPORT_CAN_HANDLE_INDEXED |
-                                  GIMP_EXPORT_CAN_HANDLE_ALPHA);
+  return_vals = gimp_procedure_new_return_values (procedure,
+                                                  GIMP_PDB_SUCCESS,
+                                                  NULL);
 
-      if (export == GIMP_EXPORT_CANCEL)
-        {
-          *nreturn_vals = 1;
-          values[0].data.d_status = GIMP_PDB_CANCEL;
-          return;
-        }
+  GIMP_VALUES_SET_IMAGE (return_vals, 1, image);
 
-      switch (run_mode)
-        {
-        case GIMP_RUN_INTERACTIVE:
-          /*
-           * Possibly retrieve data...
-           */
-          gimp_get_data (SAVE_PROC, &rawvals);
+  return return_vals;
+}
 
-          /*
-           * Then acquire information with a dialog...
-           */
-          if (! save_dialog (image_id))
-            status = GIMP_PDB_CANCEL;
-          break;
+static GimpValueArray *
+raw_save (GimpProcedure        *procedure,
+          GimpRunMode           run_mode,
+          GimpImage            *image,
+          GimpDrawable         *drawable,
+          GFile                *file,
+          const GimpValueArray *args,
+          gpointer              run_data)
+{
+  GimpPDBStatusType  status = GIMP_PDB_SUCCESS;
+  GimpExportReturn   export = GIMP_EXPORT_CANCEL;
+  GError            *error  = NULL;
 
-        case GIMP_RUN_NONINTERACTIVE:
-          /*
-           * Make sure all the arguments are there!
-           */
-          if (nparams != 5)
-            {
-              if (nparams != 7)
-                {
-                  status = GIMP_PDB_CALLING_ERROR;
-                }
-              else
-                {
-                  rawvals.image_type   = param[5].data.d_int32;
-                  rawvals.palette_type = param[6].data.d_int32;
-
-                  if (((rawvals.image_type != RAW_RGB) && (rawvals.image_type != RAW_PLANAR)) ||
-                      ((rawvals.palette_type != RAW_PALETTE_RGB) && (rawvals.palette_type != 
RAW_PALETTE_BGR)))
-                    {
-                      status = GIMP_PDB_CALLING_ERROR;
-                    }
-                }
-            }
-          break;
+  INIT_I18N ();
+  gegl_init (NULL, NULL);
 
-        case GIMP_RUN_WITH_LAST_VALS:
-          /*
-           * Possibly retrieve data...
-           */
-          gimp_get_data (SAVE_PROC, &rawvals);
-          break;
+  load_defaults ();
 
-        default:
-          break;
-        }
+  /* export the image */
+  export = gimp_export_image (&image, &drawable, "RAW",
+                              GIMP_EXPORT_CAN_HANDLE_RGB     |
+                              GIMP_EXPORT_CAN_HANDLE_GRAY    |
+                              GIMP_EXPORT_CAN_HANDLE_INDEXED |
+                              GIMP_EXPORT_CAN_HANDLE_ALPHA);
 
-      if (status == GIMP_PDB_SUCCESS)
-        {
-          if (save_image (g_file_get_path (file),
-                          image_id, drawable_id, &error))
-            {
-              gimp_set_data (SAVE_PROC, &rawvals, sizeof (rawvals));
-            }
-          else
-            {
-              status = GIMP_PDB_EXECUTION_ERROR;
-            }
-        }
+  if (export == GIMP_EXPORT_CANCEL)
+    return gimp_procedure_new_return_values (procedure,
+                                             GIMP_PDB_CANCEL,
+                                             NULL);
 
-      if (export == GIMP_EXPORT_EXPORT)
-        gimp_image_delete (image_id);
-    }
-  else if (strcmp (name, GET_DEFAULTS_PROC) == 0)
+  switch (run_mode)
     {
-      load_defaults ();
+    case GIMP_RUN_INTERACTIVE:
+      gimp_get_data (SAVE_PROC, &rawvals);
 
-      *nreturn_vals = 3;
+      if (! save_dialog (image))
+        status = GIMP_PDB_CANCEL;
+      break;
 
-#define SET_VALUE(index, field)        G_STMT_START { \
- values[(index)].type = GIMP_PDB_INT32;        \
- values[(index)].data.d_int32 = rawvals.field; \
-} G_STMT_END
+    case GIMP_RUN_NONINTERACTIVE:
+      rawvals.image_type   = GIMP_VALUES_GET_INT (args, 0);
+      rawvals.palette_type = GIMP_VALUES_GET_INT (args, 1);
 
-      SET_VALUE (1, image_type);
-      SET_VALUE (2, palette_type);
+      if ((rawvals.image_type != RAW_RGB) && (rawvals.image_type != RAW_PLANAR))
+        {
+          status = GIMP_PDB_CALLING_ERROR;
+        }
+      break;
 
-#undef SET_VALUE
+    case GIMP_RUN_WITH_LAST_VALS:
+      gimp_get_data (SAVE_PROC, &rawvals);
+      break;
+
+    default:
+      break;
     }
-  else if (strcmp (name, SET_DEFAULTS_PROC) == 0)
+
+  if (status == GIMP_PDB_SUCCESS)
     {
-      if (nparams == 2)
+      if (save_image (g_file_get_path (file),
+                      image, drawable, &error))
         {
-          load_defaults ();
-
-          rawvals.image_type     = param[0].data.d_int32;
-          rawvals.palette_type   = param[1].data.d_int32;
-
-          save_defaults ();
+          gimp_set_data (SAVE_PROC, &rawvals, sizeof (rawvals));
         }
       else
         {
-          status = GIMP_PDB_CALLING_ERROR;
+          status = GIMP_PDB_EXECUTION_ERROR;
         }
     }
-  else
-    {
-      status = GIMP_PDB_CALLING_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);
 
-  values[0].data.d_status = status;
+  return gimp_procedure_new_return_values (procedure, status, error);
 }
 
-
 /* get file size from a filename */
 static goffset
 get_file_info (const gchar *filename)
@@ -1119,7 +1048,7 @@ raw_load_palette (RawGimpData *data,
         }
     }
 
-  gimp_image_set_colormap (data->image_id, data->cmap, 256);
+  gimp_image_set_colormap (data->image, data->cmap, 256);
 
   return TRUE;
 }
@@ -1127,27 +1056,27 @@ raw_load_palette (RawGimpData *data,
 /* end new image handle functions */
 
 static gboolean
-save_image (const gchar  *filename,
-            gint32        image_id,
-            gint32        drawable_id,
-            GError      **error)
+save_image (const gchar   *filename,
+            GimpImage     *image,
+            GimpDrawable  *drawable,
+            GError       **error)
 {
-  GeglBuffer       *buffer;
-  const Babl       *format = NULL;
-  guchar           *cmap   = NULL;  /* colormap for indexed images */
-  guchar           *buf;
-  guchar           *components[4] = { 0, };
-  gint              n_components;
-  gint32            width, height, bpp;
-  FILE             *fp;
-  gint              i, j, c;
-  gint              palsize = 0;
-  gboolean          ret = FALSE;
+  GeglBuffer *buffer;
+  const Babl *format = NULL;
+  guchar     *cmap   = NULL;  /* colormap for indexed images */
+  guchar     *buf;
+  guchar     *components[4] = { 0, };
+  gint        n_components;
+  gint32      width, height, bpp;
+  FILE       *fp;
+  gint        i, j, c;
+  gint        palsize = 0;
+  gboolean    ret = FALSE;
 
   /* get info about the current image */
-  buffer = gimp_drawable_get_buffer (drawable_id);
+  buffer = gimp_drawable_get_buffer (drawable);
 
-  switch (gimp_drawable_type (drawable_id))
+  switch (gimp_drawable_type (drawable))
     {
     case GIMP_RGB_IMAGE:
       format = babl_format ("R'G'B' u8");
@@ -1167,15 +1096,15 @@ save_image (const gchar  *filename,
 
     case GIMP_INDEXED_IMAGE:
     case GIMP_INDEXEDA_IMAGE:
-      format = gimp_drawable_get_format (drawable_id);
+      format = gimp_drawable_get_format (drawable);
       break;
     }
 
   n_components = babl_format_get_n_components (format);
   bpp          = babl_format_get_bytes_per_pixel (format);
 
-  if (gimp_drawable_is_indexed (drawable_id))
-    cmap = gimp_image_get_colormap (image_id, &palsize);
+  if (gimp_drawable_is_indexed (drawable))
+    cmap = gimp_image_get_colormap (image, &palsize);
 
   width  = gegl_buffer_get_width  (buffer);
   height = gegl_buffer_get_height (buffer);
@@ -1281,16 +1210,16 @@ save_image (const gchar  *filename,
   return ret;
 }
 
-static gint32
+static GimpImage *
 load_image (const gchar  *filename,
             GError      **error)
 {
   RawGimpData       *data;
-  gint32             layer_id = -1;
-  GimpImageType      ltype    = GIMP_RGB_IMAGE;
-  GimpImageBaseType  itype    = GIMP_RGB;
+  GimpLayer         *layer = NULL;
+  GimpImageType      ltype = GIMP_RGB_IMAGE;
+  GimpImageBaseType  itype = GIMP_RGB;
   goffset            size;
-  gint               bpp = 0;
+  gint               bpp    = 0;
   gint               bitspp = 8;
 
   data = g_new0 (RawGimpData, 1);
@@ -1304,7 +1233,7 @@ load_image (const gchar  *filename,
       g_set_error (error, G_FILE_ERROR, g_file_error_from_errno (errno),
                    _("Could not open '%s' for reading: %s"),
                    gimp_filename_to_utf8 (filename), g_strerror (errno));
-      return -1;
+      return NULL;
     }
 
   size = get_file_info (filename);
@@ -1384,23 +1313,23 @@ load_image (const gchar  *filename,
     runtime->image_height = size / runtime->image_width / bpp * 8 / bitspp;
 
   if (runtime->image_type >= RAW_GRAY_16BPP_BE)
-    data->image_id = gimp_image_new_with_precision (runtime->image_width,
-                                                    runtime->image_height,
-                                                    itype,
-                                                    GIMP_PRECISION_U16_NON_LINEAR);
+    data->image = gimp_image_new_with_precision (runtime->image_width,
+                                                 runtime->image_height,
+                                                 itype,
+                                                 GIMP_PRECISION_U16_NON_LINEAR);
   else
-    data->image_id = gimp_image_new (runtime->image_width,
-                                     runtime->image_height,
-                                     itype);
-  gimp_image_set_filename (data->image_id, filename);
-  layer_id = gimp_layer_new (data->image_id, _("Background"),
-                             runtime->image_width, runtime->image_height,
-                             ltype,
-                             100,
-                             gimp_image_get_default_new_layer_mode (data->image_id));
-  gimp_image_insert_layer (data->image_id, layer_id, -1, 0);
-
-  data->buffer = gimp_drawable_get_buffer (layer_id);
+    data->image = gimp_image_new (runtime->image_width,
+                                  runtime->image_height,
+                                  itype);
+  gimp_image_set_filename (data->image, filename);
+  layer = gimp_layer_new (data->image, _("Background"),
+                          runtime->image_width, runtime->image_height,
+                          ltype,
+                          100,
+                          gimp_image_get_default_new_layer_mode (data->image));
+  gimp_image_insert_layer (data->image, layer, NULL, 0);
+
+  data->buffer = gimp_drawable_get_buffer (GIMP_DRAWABLE (layer));
 
   switch (runtime->image_type)
     {
@@ -1451,7 +1380,7 @@ load_image (const gchar  *filename,
 
   g_object_unref (data->buffer);
 
-  return data->image_id;
+  return data->image;
 }
 
 
@@ -2107,7 +2036,7 @@ radio_button_init (GtkBuilder  *builder,
 }
 
 static gboolean
-save_dialog (gint32 image_id)
+save_dialog (GimpImage *image)
 {
   RawSaveGui  rg;
   GtkWidget  *dialog;
diff --git a/plug-ins/common/plugin-defs.pl b/plug-ins/common/plugin-defs.pl
index ba4d11108d..d795e6293a 100644
--- a/plug-ins/common/plugin-defs.pl
+++ b/plug-ins/common/plugin-defs.pl
@@ -42,7 +42,7 @@
     'file-pdf-save' => { ui => 1, gegl => 1, optional => 1, libs => 'CAIRO_PDF_LIBS', cflags => 
'CAIRO_PDF_CFLAGS', old_api => 1 },
     'file-ps' => { ui => 1, gegl => 1, optional => 1, libs => 'GS_LIBS' },
     'file-psp' => { ui => 1, gegl => 1, libs => 'Z_LIBS', old_api => 1 },
-    'file-raw-data' => { ui => 1, gegl => 1, old_api => 1 },
+    'file-raw-data' => { ui => 1, gegl => 1 },
     'file-sunras' => { ui => 1, gegl => 1, old_api => 1 },
     'file-svg' => { ui => 1, gegl => 1, libs => 'SVG_LIBS', cflags => 'SVG_CFLAGS' },
     'file-tga' => { ui => 1, gegl => 1, old_api => 1 },


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