[gimp] plug-ins: port file-gegl to GimpPlugIn and libgimp objects
- From: Michael Natterer <mitch src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gimp] plug-ins: port file-gegl to GimpPlugIn and libgimp objects
- Date: Sun, 25 Aug 2019 17:31:34 +0000 (UTC)
commit 0ee329bd440503dbf076a0ddb0f0645085916839
Author: Michael Natterer <mitch gimp org>
Date: Sun Aug 25 18:15:04 2019 +0200
plug-ins: port file-gegl to GimpPlugIn and libgimp objects
plug-ins/common/Makefile.am | 2 -
plug-ins/common/file-gegl.c | 390 +++++++++++++++++++++--------------------
plug-ins/common/plugin-defs.pl | 2 +-
3 files changed, 201 insertions(+), 193 deletions(-)
---
diff --git a/plug-ins/common/Makefile.am b/plug-ins/common/Makefile.am
index e744033785..8cb6df5bbc 100644
--- a/plug-ins/common/Makefile.am
+++ b/plug-ins/common/Makefile.am
@@ -678,8 +678,6 @@ file_gbr_LDADD = \
$(INTLLIBS) \
$(file_gbr_RC)
-file_gegl_CPPFLAGS = $(AM_CPPFLAGS) -DGIMP_DEPRECATED_REPLACE_NEW_API
-
file_gegl_SOURCES = \
file-gegl.c
diff --git a/plug-ins/common/file-gegl.c b/plug-ins/common/file-gegl.c
index a7ac234e94..9e3d70b160 100644
--- a/plug-ins/common/file-gegl.c
+++ b/plug-ins/common/file-gegl.c
@@ -53,18 +53,53 @@ struct _FileFormat
};
-static void query (void);
-static void run (const gchar *name,
- gint nparams,
- const GimpParam *param,
- gint *nreturn_vals,
- GimpParam **return_vals);
-static gint32 load_image (const gchar *filename,
- GError **error);
-static gboolean save_image (const gchar *filename,
- gint32 image_ID,
- gint32 drawable_ID,
- GError **error);
+typedef struct _Goat Goat;
+typedef struct _GoatClass GoatClass;
+
+struct _Goat
+{
+ GimpPlugIn parent_instance;
+};
+
+struct _GoatClass
+{
+ GimpPlugInClass parent_class;
+};
+
+
+#define GOAT_TYPE (goat_get_type ())
+#define GOAT (obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GOAT_TYPE, Goat))
+
+GType goat_get_type (void) G_GNUC_CONST;
+
+static GList * goat_query_procedures (GimpPlugIn *plug_in);
+static GimpProcedure * goat_create_procedure (GimpPlugIn *plug_in,
+ const gchar *name);
+
+static GimpValueArray * goat_load (GimpProcedure *procedure,
+ GimpRunMode run_mode,
+ GFile *file,
+ const GimpValueArray *args,
+ gpointer run_data);
+static GimpValueArray * goat_save (GimpProcedure *procedure,
+ GimpRunMode run_mode,
+ GimpImage *image,
+ GimpDrawable *drawable,
+ GFile *file,
+ const GimpValueArray *args,
+ gpointer run_data);
+
+static GimpImage * load_image (const gchar *filename,
+ GError **error);
+static gboolean save_image (const gchar *filename,
+ GimpImage *image,
+ GimpDrawable *drawable,
+ GError **error);
+
+
+G_DEFINE_TYPE (Goat, goat, GIMP_TYPE_PLUG_IN)
+
+GIMP_MAIN (GOAT_TYPE)
static const FileFormat file_formats[] =
@@ -99,209 +134,183 @@ static const FileFormat file_formats[] =
};
-const GimpPlugInInfo PLUG_IN_INFO =
+static void
+goat_class_init (GoatClass *klass)
{
- NULL, /* init_proc */
- NULL, /* quit_proc */
- query, /* query proc */
- run, /* run_proc */
-};
+ GimpPlugInClass *plug_in_class = GIMP_PLUG_IN_CLASS (klass);
-MAIN ()
+ plug_in_class->query_procedures = goat_query_procedures;
+ plug_in_class->create_procedure = goat_create_procedure;
+}
static void
-query (void)
+goat_init (Goat *goat)
{
- 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 entered" },
- };
+}
- static const GimpParamDef load_return_vals[] =
- {
- { GIMP_PDB_IMAGE, "image", "Output image" }
- };
+static GList *
+goat_query_procedures (GimpPlugIn *plug_in)
+{
+ GList *list = NULL;
+ gint i;
- 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" }
- };
+ for (i = 0; i < G_N_ELEMENTS (file_formats); i++)
+ {
+ const FileFormat *format = &file_formats[i];
+
+ if (format->load_proc)
+ list = g_list_append (list, g_strdup (format->load_proc));
- gint i;
+ if (format->save_proc)
+ list = g_list_append (list, g_strdup (format->save_proc));
+ }
+
+ return list;
+}
+
+static GimpProcedure *
+goat_create_procedure (GimpPlugIn *plug_in,
+ const gchar *name)
+{
+ GimpProcedure *procedure = NULL;
+ gint i;
for (i = 0; i < G_N_ELEMENTS (file_formats); i++)
{
const FileFormat *format = &file_formats[i];
- if (format->load_proc)
+ if (! g_strcmp0 (name, format->load_proc))
{
- gimp_install_procedure (format->load_proc,
- format->load_blurb,
- format->load_help,
- "Simon Budig",
- "Simon Budig",
- "2012",
- format->file_type,
- NULL,
- GIMP_PLUGIN,
- G_N_ELEMENTS (load_args),
- G_N_ELEMENTS (load_return_vals),
- load_args, load_return_vals);
-
- gimp_register_file_handler_mime (format->load_proc,
- format->mime_type);
- gimp_register_magic_load_handler (format->load_proc,
- format->extensions,
- "",
- format->magic);
+ procedure = gimp_load_procedure_new (plug_in, name, GIMP_PLUGIN,
+ goat_load,
+ (gpointer) format, NULL);
+
+ gimp_procedure_set_menu_label (procedure, format->file_type);
+
+ gimp_procedure_set_documentation (procedure,
+ format->load_blurb,
+ format->load_help,
+ name);
+
+ gimp_file_procedure_set_mime_types (GIMP_FILE_PROCEDURE (procedure),
+ format->mime_type);
+ gimp_file_procedure_set_extensions (GIMP_FILE_PROCEDURE (procedure),
+ format->extensions);
+ gimp_file_procedure_set_magics (GIMP_FILE_PROCEDURE (procedure),
+ format->magic);
}
-
- if (format->save_proc)
+ else if (! g_strcmp0 (name, format->save_proc))
{
- gimp_install_procedure (format->save_proc,
- format->save_blurb,
- format->save_help,
- "Simon Budig",
- "Simon Budig",
- "2012",
- format->file_type,
- "*",
- GIMP_PLUGIN,
- G_N_ELEMENTS (save_args), 0,
- save_args, NULL);
-
- gimp_register_file_handler_mime (format->save_proc,
- format->mime_type);
- gimp_register_save_handler (format->save_proc,
- format->extensions, "");
+ procedure = gimp_save_procedure_new (plug_in, name, GIMP_PLUGIN,
+ goat_save,
+ (gpointer) format, NULL);
+
+ gimp_procedure_set_image_types (procedure, "*");
+
+ gimp_procedure_set_menu_label (procedure, format->file_type);
+
+ gimp_procedure_set_documentation (procedure,
+ format->save_blurb,
+ format->save_help,
+ name);
+
+ gimp_file_procedure_set_mime_types (GIMP_FILE_PROCEDURE (procedure),
+ format->mime_type);
+ gimp_file_procedure_set_extensions (GIMP_FILE_PROCEDURE (procedure),
+ format->extensions);
}
}
+
+ return procedure;
}
-static void
-run (const gchar *name,
- gint nparams,
- const GimpParam *param,
- gint *nreturn_vals,
- GimpParam **return_vals)
+static GimpValueArray *
+goat_load (GimpProcedure *procedure,
+ GimpRunMode run_mode,
+ GFile *file,
+ const GimpValueArray *args,
+ gpointer run_data)
{
- static GimpParam values[2];
- GimpPDBStatusType status = GIMP_PDB_SUCCESS;
- GimpRunMode run_mode;
- gint image_ID;
- gint drawable_ID;
- GError *error = NULL;
- gint i;
+ GimpValueArray *return_vals;
+ GimpImage *image;
+ GError *error = NULL;
INIT_I18N ();
gegl_init (NULL, NULL);
- run_mode = param[0].data.d_int32;
+ image = load_image (g_file_get_path (file), &error);
- *nreturn_vals = 1;
- *return_vals = values;
+ if (! image)
+ return gimp_procedure_new_return_values (procedure,
+ GIMP_PDB_EXECUTION_ERROR,
+ error);
- values[0].type = GIMP_PDB_STATUS;
- values[0].data.d_status = GIMP_PDB_EXECUTION_ERROR;
+ return_vals = gimp_procedure_new_return_values (procedure,
+ GIMP_PDB_SUCCESS,
+ NULL);
- for (i = 0; i < G_N_ELEMENTS (file_formats); i++)
- {
- const FileFormat *format = &file_formats[i];
+ GIMP_VALUES_SET_IMAGE (return_vals, 1, image);
- if (format->load_proc && !strcmp (name, format->load_proc))
- {
- GFile *file = g_file_new_for_uri (param[1].data.d_string);
+ return return_vals;
+}
- image_ID = load_image (g_file_get_path (file), &error);
+static GimpValueArray *
+goat_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;
- if (image_ID != -1)
- {
- *nreturn_vals = 2;
- values[1].type = GIMP_PDB_IMAGE;
- values[1].data.d_image = image_ID;
- }
- else
- {
- status = GIMP_PDB_EXECUTION_ERROR;
- }
+ INIT_I18N ();
+ gegl_init (NULL, NULL);
- break;
- }
- else if (format->save_proc && !strcmp (name, format->save_proc))
- {
- GFile *file = g_file_new_for_uri (param[3].data.d_string);
-
- GimpExportReturn export = GIMP_EXPORT_CANCEL;
-
- image_ID = param[1].data.d_int32;
- drawable_ID = param[2].data.d_int32;
-
- /* eventually export the image */
- 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, "GEGL",
- GIMP_EXPORT_CAN_HANDLE_RGB |
- GIMP_EXPORT_CAN_HANDLE_GRAY |
- GIMP_EXPORT_CAN_HANDLE_INDEXED |
- GIMP_EXPORT_CAN_HANDLE_ALPHA);
-
- if (export == GIMP_EXPORT_CANCEL)
- {
- *nreturn_vals = 1;
- values[0].data.d_status = GIMP_PDB_CANCEL;
- return;
- }
- break;
-
- default:
- break;
- }
-
- if (! save_image (g_file_get_path (file),
- image_ID, drawable_ID,
- &error))
- {
- status = GIMP_PDB_EXECUTION_ERROR;
- }
-
- if (export == GIMP_EXPORT_EXPORT)
- gimp_image_delete (image_ID);
-
- break;
- }
+ 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, &drawable, "GEGL",
+ GIMP_EXPORT_CAN_HANDLE_RGB |
+ GIMP_EXPORT_CAN_HANDLE_GRAY |
+ GIMP_EXPORT_CAN_HANDLE_INDEXED |
+ GIMP_EXPORT_CAN_HANDLE_ALPHA);
+
+ if (export == GIMP_EXPORT_CANCEL)
+ return gimp_procedure_new_return_values (procedure,
+ GIMP_PDB_CANCEL,
+ NULL);
+ break;
+
+ default:
+ break;
}
- if (i == G_N_ELEMENTS (file_formats))
- status = GIMP_PDB_CALLING_ERROR;
-
- if (status != GIMP_PDB_SUCCESS && error)
+ if (! save_image (g_file_get_path (file),
+ image, drawable,
+ &error))
{
- *nreturn_vals = 2;
- values[1].type = GIMP_PDB_STRING;
- values[1].data.d_string = error->message;
+ status = GIMP_PDB_EXECUTION_ERROR;
}
- values[0].data.d_status = status;
+ if (export == GIMP_EXPORT_EXPORT)
+ gimp_image_delete (image);
- gegl_exit ();
+ return gimp_procedure_new_return_values (procedure, status, error);
}
-static gint32
+static GimpImage *
load_image (const gchar *filename,
GError **error)
{
- gint32 image_ID = -1;
- gint32 layer_ID;
+ GimpImage *image;
+ GimpLayer *layer;
GimpImageType image_type;
GimpImageBaseType base_type;
GimpPrecision precision;
@@ -340,7 +349,7 @@ load_image (const gchar *filename,
g_set_error (error, G_FILE_ERROR, G_FILE_ERROR_FAILED,
_("Could not open '%s'"),
gimp_filename_to_utf8 (filename));
- return -1;
+ return NULL;
}
gimp_progress_update (0.33);
@@ -425,18 +434,19 @@ load_image (const gchar *filename,
}
- image_ID = gimp_image_new_with_precision (width, height,
- base_type, precision);
- gimp_image_set_filename (image_ID, filename);
+ image = gimp_image_new_with_precision (width, height,
+ base_type, precision);
+ gimp_image_set_filename (image, filename);
+
+ layer = gimp_layer_new (image,
+ _("Background"),
+ width, height,
+ image_type,
+ 100,
+ gimp_image_get_default_new_layer_mode (image));
+ gimp_image_insert_layer (image, layer, NULL, 0);
- layer_ID = gimp_layer_new (image_ID,
- _("Background"),
- width, height,
- image_type,
- 100,
- gimp_image_get_default_new_layer_mode (image_ID));
- gimp_image_insert_layer (image_ID, layer_ID, -1, 0);
- dest_buf = gimp_drawable_get_buffer (layer_ID);
+ dest_buf = gimp_drawable_get_buffer (GIMP_DRAWABLE (layer));
gimp_progress_update (0.66);
@@ -447,21 +457,21 @@ load_image (const gchar *filename,
gimp_progress_update (1.0);
- return image_ID;
+ return image;
}
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)
{
GeglNode *graph;
GeglNode *source;
GeglNode *sink;
GeglBuffer *src_buf;
- src_buf = gimp_drawable_get_buffer (drawable_ID);
+ src_buf = gimp_drawable_get_buffer (drawable);
graph = gegl_node_new ();
diff --git a/plug-ins/common/plugin-defs.pl b/plug-ins/common/plugin-defs.pl
index a8837ec268..ff3211296a 100644
--- a/plug-ins/common/plugin-defs.pl
+++ b/plug-ins/common/plugin-defs.pl
@@ -23,7 +23,7 @@
'file-desktop-link' => { gio => 1 },
'file-dicom' => { ui => 1, gegl => 1, cflags => '-fno-strict-aliasing' },
'file-gbr' => { ui => 1, gegl => 1 },
- 'file-gegl' => { ui => 1, gegl => 1, old_api => 1 },
+ 'file-gegl' => { ui => 1, gegl => 1 },
'file-gif-load' => { gegl => 1 },
'file-gif-save' => { ui => 1, gegl => 1 },
'file-gih' => { ui => 1, gegl => 1 },
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]