[gimp] plug-ins: port file-xbm to GimpPlugIn and libgimp objects
- From: Michael Natterer <mitch src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gimp] plug-ins: port file-xbm to GimpPlugIn and libgimp objects
- Date: Sat, 24 Aug 2019 08:59:23 +0000 (UTC)
commit 9f3bc2bd7a6aa11c02851ad9b4613abe7f012f56
Author: Michael Natterer <mitch gimp org>
Date: Sat Aug 24 10:58:34 2019 +0200
plug-ins: port file-xbm to GimpPlugIn and libgimp objects
plug-ins/common/Makefile.am | 2 -
plug-ins/common/file-xbm.c | 738 +++++++++++++++++++++--------------------
plug-ins/common/plugin-defs.pl | 2 +-
3 files changed, 386 insertions(+), 356 deletions(-)
---
diff --git a/plug-ins/common/Makefile.am b/plug-ins/common/Makefile.am
index 26797ba99e..8086fe8d49 100644
--- a/plug-ins/common/Makefile.am
+++ b/plug-ins/common/Makefile.am
@@ -1163,8 +1163,6 @@ file_wmf_LDADD = \
$(INTLLIBS) \
$(file_wmf_RC)
-file_xbm_CPPFLAGS = $(AM_CPPFLAGS) -DGIMP_DEPRECATED_REPLACE_NEW_API
-
file_xbm_SOURCES = \
file-xbm.c
diff --git a/plug-ins/common/file-xbm.c b/plug-ins/common/file-xbm.c
index 8eb3c7de46..c8bd7f7e7b 100644
--- a/plug-ins/common/file-xbm.c
+++ b/plug-ins/common/file-xbm.c
@@ -54,7 +54,6 @@
#define PLUG_IN_BINARY "file-xbm"
#define PLUG_IN_ROLE "gimp-file-xbm"
-
/* Wear your GIMP with pride! */
#define DEFAULT_USE_COMMENT TRUE
#define MAX_COMMENT 72
@@ -67,6 +66,7 @@
/* Whether or not to export as X10 bitmap. */
#define DEFAULT_X10_FORMAT FALSE
+
typedef struct _XBMSaveVals
{
gchar comment[MAX_COMMENT + 1];
@@ -79,6 +79,75 @@ typedef struct _XBMSaveVals
gchar mask_ext[MAX_MASK_EXT + 1];
} XBMSaveVals;
+
+typedef struct _Xbm Xbm;
+typedef struct _XbmClass XbmClass;
+
+struct _Xbm
+{
+ GimpPlugIn parent_instance;
+};
+
+struct _XbmClass
+{
+ GimpPlugInClass parent_class;
+};
+
+
+#define XBM_TYPE (xbm_get_type ())
+#define XBM (obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), XBM_TYPE, Xbm))
+
+GType xbm_get_type (void) G_GNUC_CONST;
+
+static GList * xbm_query_procedures (GimpPlugIn *plug_in);
+static GimpProcedure * xbm_create_procedure (GimpPlugIn *plug_in,
+ const gchar *name);
+
+static GimpValueArray * xbm_load (GimpProcedure *procedure,
+ GimpRunMode run_mode,
+ GFile *file,
+ const GimpValueArray *args,
+ gpointer run_data);
+static GimpValueArray * xbm_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 (GFile *file,
+ const gchar *prefix,
+ const gchar *comment,
+ gboolean save_mask,
+ GimpImage *image,
+ GimpDrawable *drawable,
+ GError **error);
+static gboolean save_dialog (GimpDrawable *drawable);
+
+static gboolean print (GOutputStream *output,
+ GError **error,
+ const gchar *format,
+ ...) G_GNUC_PRINTF (3, 4);
+
+#if 0
+/* DISABLED - see http://bugzilla.gnome.org/show_bug.cgi?id=82763 */
+static void comment_entry_callback (GtkWidget *widget,
+ gpointer data);
+#endif
+static void prefix_entry_callback (GtkWidget *widget,
+ gpointer data);
+static void mask_ext_entry_callback (GtkWidget *widget,
+ gpointer data);
+
+
+G_DEFINE_TYPE (Xbm, xbm, GIMP_TYPE_PLUG_IN)
+
+GIMP_MAIN (XBM_TYPE)
+
+
static XBMSaveVals xsvals =
{
"###", /* comment */
@@ -91,122 +160,169 @@ static XBMSaveVals xsvals =
"-mask"
};
+#ifdef VERBOSE
+static int verbose = VERBOSE;
+#endif
-/* Declare some local functions.
- */
-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 gint save_image (GFile *file,
- const gchar *prefix,
- const gchar *comment,
- gboolean save_mask,
- gint32 image_ID,
- gint32 drawable_ID,
- GError **error);
-static gboolean save_dialog (gint32 drawable_ID);
-
-static gboolean print (GOutputStream *output,
- GError **error,
- const gchar *format,
- ...) G_GNUC_PRINTF (3, 4);
-#if 0
-/* DISABLED - see http://bugzilla.gnome.org/show_bug.cgi?id=82763 */
-static void comment_entry_callback (GtkWidget *widget,
- gpointer data);
-#endif
-static void prefix_entry_callback (GtkWidget *widget,
- gpointer data);
-static void mask_ext_entry_callback (GtkWidget *widget,
- gpointer data);
+static void
+xbm_class_init (XbmClass *klass)
+{
+ GimpPlugInClass *plug_in_class = GIMP_PLUG_IN_CLASS (klass);
+ plug_in_class->query_procedures = xbm_query_procedures;
+ plug_in_class->create_procedure = xbm_create_procedure;
+}
-const GimpPlugInInfo PLUG_IN_INFO =
+static void
+xbm_init (Xbm *xbm)
{
- NULL, /* init_proc */
- NULL, /* quit_proc */
- query, /* query_proc */
- run, /* run_proc */
-};
+}
-MAIN ()
+static GList *
+xbm_query_procedures (GimpPlugIn *plug_in)
+{
+ GList *list = NULL;
-#ifdef VERBOSE
-static int verbose = VERBOSE;
-#endif
+ list = g_list_append (list, g_strdup (LOAD_PROC));
+ list = g_list_append (list, g_strdup (SAVE_PROC));
+ return list;
+}
-static void
-query (void)
+static GimpProcedure *
+xbm_create_procedure (GimpPlugIn *plug_in,
+ const gchar *name)
{
- 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" }
- };
+ GimpProcedure *procedure = NULL;
- static const GimpParamDef load_return_vals[] =
- {
- { GIMP_PDB_IMAGE, "image", "Output image" }
- };
+ if (! strcmp (name, LOAD_PROC))
+ {
+ procedure = gimp_load_procedure_new (plug_in, name, GIMP_PLUGIN,
+ xbm_load, NULL, NULL);
+
+ gimp_procedure_set_menu_label (procedure, N_("X BitMap image"));
+
+ gimp_procedure_set_documentation (procedure,
+ "Load a file in X10 or X11 bitmap "
+ "(XBM) file format",
+ "Load a file in X10 or X11 bitmap "
+ "(XBM) file format. XBM is a lossless "
+ "format for flat black-and-white "
+ "(two color indexed) images.",
+ name);
+ gimp_procedure_set_attribution (procedure,
+ "Gordon Matzigkeit",
+ "Gordon Matzigkeit",
+ "1998");
+
+ gimp_file_procedure_set_mime_types (GIMP_FILE_PROCEDURE (procedure),
+ "image/x-xbitmap");
+ gimp_file_procedure_set_extensions (GIMP_FILE_PROCEDURE (procedure),
+ "xbm,icon,bitmap");
+ }
+ else if (! strcmp (name, SAVE_PROC))
+ {
+ procedure = gimp_save_procedure_new (plug_in, name, GIMP_PLUGIN,
+ xbm_save, NULL, NULL);
+
+ gimp_procedure_set_image_types (procedure, "INDEXED");
+
+ gimp_procedure_set_menu_label (procedure, N_("X BitMap image"));
+
+ gimp_procedure_set_documentation (procedure,
+ "Export a file in X10 or X11 bitmap "
+ "(XBM) file format",
+ "Export a file in X10 or X11 bitmap "
+ "(XBM) file format. XBM is a lossless "
+ "format for flat black-and-white "
+ "(two color indexed) images.",
+ name);
+ gimp_procedure_set_attribution (procedure,
+ "Gordon Matzigkeit",
+ "Gordon Matzigkeit",
+ "1998");
+
+ gimp_file_procedure_set_handles_remote (GIMP_FILE_PROCEDURE (procedure),
+ TRUE);
+ gimp_file_procedure_set_mime_types (GIMP_FILE_PROCEDURE (procedure),
+ "image/x-xbitmap");
+ gimp_file_procedure_set_extensions (GIMP_FILE_PROCEDURE (procedure),
+ "xbm,icon,bitmap");
+
+ GIMP_PROC_ARG_STRING (procedure, "comment",
+ "Comment",
+ "Image description (maximum 72 bytes)",
+ "Created with GIMP",
+ G_PARAM_READWRITE);
+
+ GIMP_PROC_ARG_BOOLEAN (procedure, "x10",
+ "X10",
+ "Export in X10 format",
+ DEFAULT_X10_FORMAT,
+ G_PARAM_READWRITE);
+
+ GIMP_PROC_ARG_INT (procedure, "x-hot",
+ "X hot",
+ "X coordinate of hotspot",
+ 0, GIMP_MAX_IMAGE_SIZE, 0,
+ G_PARAM_READWRITE);
+
+ GIMP_PROC_ARG_INT (procedure, "y-hot",
+ "Y hot",
+ "Y coordinate of hotspot",
+ 0, GIMP_MAX_IMAGE_SIZE, 0,
+ G_PARAM_READWRITE);
+
+ GIMP_PROC_ARG_STRING (procedure, "prefix",
+ "Prefix",
+ "Identifier prefix [determined from filename]",
+ DEFAULT_PREFIX,
+ G_PARAM_READWRITE);
+
+ GIMP_PROC_ARG_BOOLEAN (procedure, "write-mask",
+ "Write mask",
+ "Write extra mask file",
+ FALSE,
+ G_PARAM_READWRITE);
+
+ GIMP_PROC_ARG_STRING (procedure, "mask-suffix",
+ "Mask suffix",
+ "Suffix of the mask file",
+ "-mask",
+ G_PARAM_READWRITE);
+ }
- 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 export" },
- { GIMP_PDB_STRING, "filename", "The name of the file to export" },
- { GIMP_PDB_STRING, "raw-filename", "The name entered" },
- { GIMP_PDB_STRING, "comment", "Image description (maximum 72 bytes)" },
- { GIMP_PDB_INT32, "x10", "Export in X10 format" },
- { GIMP_PDB_INT32, "x-hot", "X coordinate of hotspot" },
- { GIMP_PDB_INT32, "y-hot", "Y coordinate of hotspot" },
- { GIMP_PDB_STRING, "prefix", "Identifier prefix [determined from filename]"},
- { GIMP_PDB_INT32, "write-mask", "(0 = ignore, 1 = save as extra file)" },
- { GIMP_PDB_STRING, "mask-extension", "Extension of the mask file" }
- } ;
-
- gimp_install_procedure (LOAD_PROC,
- "Load a file in X10 or X11 bitmap (XBM) file format",
- "Load a file in X10 or X11 bitmap (XBM) file format. XBM is a lossless format for
flat black-and-white (two color indexed) images.",
- "Gordon Matzigkeit",
- "Gordon Matzigkeit",
- "1998",
- N_("X BitMap 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-xbitmap");
- gimp_register_load_handler (LOAD_PROC,
- "xbm,icon,bitmap",
- "");
-
- gimp_install_procedure (SAVE_PROC,
- "Export a file in X10 or X11 bitmap (XBM) file format",
- "Export a file in X10 or X11 bitmap (XBM) file format. XBM is a lossless format
for flat black-and-white (two color indexed) images.",
- "Gordon Matzigkeit",
- "Gordon Matzigkeit",
- "1998",
- N_("X BitMap image"),
- "INDEXED",
- GIMP_PLUGIN,
- G_N_ELEMENTS (save_args), 0,
- save_args, NULL);
-
- gimp_register_file_handler_mime (SAVE_PROC, "image/x-xbitmap");
- gimp_register_file_handler_remote (SAVE_PROC);
- gimp_register_save_handler (SAVE_PROC, "xbm,icon,bitmap", "");
+ return procedure;
+}
+
+static GimpValueArray *
+xbm_load (GimpProcedure *procedure,
+ GimpRunMode run_mode,
+ GFile *file,
+ const GimpValueArray *args,
+ gpointer run_data)
+{
+ GimpValueArray *return_vals;
+ GimpPDBStatusType status = GIMP_PDB_SUCCESS;
+ GimpImage *image;
+ GError *error = NULL;
+
+ INIT_I18N ();
+ gegl_init (NULL, NULL);
+
+ image = load_image (g_file_get_path (file), &error);
+
+ if (! image)
+ return gimp_procedure_new_return_values (procedure, status, error);
+
+ return_vals = gimp_procedure_new_return_values (procedure,
+ GIMP_PDB_SUCCESS,
+ NULL);
+
+ GIMP_VALUES_SET_IMAGE (return_vals, 1, image);
+
+ return return_vals;
}
static gchar *
@@ -235,260 +351,177 @@ init_prefix (const gchar *filename)
return xsvals.prefix;
}
-static void
-run (const gchar *name,
- gint nparams,
- const GimpParam *param,
- gint *nreturn_vals,
- GimpParam **return_vals)
+static GimpValueArray *
+xbm_save (GimpProcedure *procedure,
+ GimpRunMode run_mode,
+ GimpImage *image,
+ GimpDrawable *drawable,
+ GFile *file,
+ const GimpValueArray *args,
+ gpointer run_data)
{
- static GimpParam values[2];
- GimpRunMode run_mode;
GimpPDBStatusType status = GIMP_PDB_SUCCESS;
- gint32 image_ID;
- gint32 drawable_ID;
- GimpParasite *parasite = NULL;
+ GimpExportReturn export = GIMP_EXPORT_CANCEL;
gchar *mask_basename = NULL;
GError *error = NULL;
- GimpExportReturn export = GIMP_EXPORT_CANCEL;
INIT_I18N ();
gegl_init (NULL, NULL);
- g_strlcpy (xsvals.comment, "Created with GIMP", MAX_COMMENT);
-
- run_mode = param[0].data.d_int32;
-
- *nreturn_vals = 1;
- *return_vals = values;
-
- values[0].type = GIMP_PDB_STATUS;
- values[0].data.d_status = GIMP_PDB_EXECUTION_ERROR;
-
-#ifdef VERBOSE
- if (verbose)
- printf ("XBM: RUN %s\n", name);
-#endif
-
- if (strcmp (name, LOAD_PROC) == 0)
+ switch (run_mode)
{
- GFile *file = g_file_new_for_uri (param[1].data.d_string);
-
- image_ID = load_image (g_file_get_path (file), &error);
-
- 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;
- }
+ case GIMP_RUN_INTERACTIVE:
+ case GIMP_RUN_WITH_LAST_VALS:
+ gimp_ui_init (PLUG_IN_BINARY, FALSE);
+
+ export = gimp_export_image (&image, &drawable, "XBM",
+ GIMP_EXPORT_CAN_HANDLE_BITMAP |
+ GIMP_EXPORT_CAN_HANDLE_ALPHA);
+
+ if (export == GIMP_EXPORT_CANCEL)
+ return gimp_procedure_new_return_values (procedure,
+ GIMP_PDB_CANCEL,
+ NULL);
+ break;
+
+ default:
+ break;
}
- else if (strcmp (name, SAVE_PROC) == 0)
- {
- image_ID = param[1].data.d_int32;
- drawable_ID = param[2].data.d_int32;
-
- 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, "XBM",
- GIMP_EXPORT_CAN_HANDLE_BITMAP |
- GIMP_EXPORT_CAN_HANDLE_ALPHA);
-
- if (export == GIMP_EXPORT_CANCEL)
- {
- values[0].data.d_status = GIMP_PDB_CANCEL;
- return;
- }
- break;
+ switch (run_mode)
+ {
+ case GIMP_RUN_INTERACTIVE:
+ case GIMP_RUN_WITH_LAST_VALS:
+ gimp_get_data (SAVE_PROC, &xsvals);
- default:
- break;
- }
+ /* Always override the prefix with the filename. */
+ mask_basename = g_strdup (init_prefix (g_file_get_path (file)));
+ break;
- switch (run_mode)
- {
- case GIMP_RUN_INTERACTIVE:
- case GIMP_RUN_WITH_LAST_VALS:
- /* Possibly retrieve data */
- gimp_get_data (SAVE_PROC, &xsvals);
+ case GIMP_RUN_NONINTERACTIVE:
+ g_strlcpy (xsvals.comment, GIMP_VALUES_GET_STRING (args, 0),
+ MAX_COMMENT);
- /* Always override the prefix with the filename. */
- mask_basename = g_strdup (init_prefix (param[3].data.d_string));
- break;
+ xsvals.x10_format = GIMP_VALUES_GET_BOOLEAN (args, 1);
+ xsvals.x_hot = GIMP_VALUES_GET_INT (args, 2);
+ xsvals.y_hot = GIMP_VALUES_GET_INT (args, 3);
+ xsvals.use_hot = xsvals.x_hot != 0 || xsvals.y_hot != 0;
- case GIMP_RUN_NONINTERACTIVE:
- /* Make sure all the required arguments are there! */
- if (nparams < 5)
- {
- status = GIMP_PDB_CALLING_ERROR;
- }
- else
- {
- gint i = 5;
+ mask_basename = g_strdup (init_prefix (g_file_get_path (file)));
- if (nparams > i)
- g_strlcpy (xsvals.comment, param[i].data.d_string,
- MAX_COMMENT);
+ g_strlcpy (xsvals.prefix, GIMP_VALUES_GET_STRING (args, 4),
+ MAX_PREFIX);
- i ++;
- if (nparams > i)
- xsvals.x10_format = (param[i].data.d_int32) ? TRUE : FALSE;
+ xsvals.write_mask = GIMP_VALUES_GET_BOOLEAN (args, 5);
+ g_strlcpy (xsvals.mask_ext, GIMP_VALUES_GET_STRING (args, 6),
+ MAX_MASK_EXT);
+ break;
- i += 2;
- if (nparams > i)
- {
- /* They've asked for a hotspot. */
- xsvals.use_hot = TRUE;
- xsvals.x_hot = param[i - 1].data.d_int32;
- xsvals.y_hot = param[i].data.d_int32;
- }
+ default:
+ break;
+ }
- mask_basename = g_strdup (init_prefix (param[3].data.d_string));
+ if (run_mode == GIMP_RUN_INTERACTIVE)
+ {
+ GimpParasite *parasite;
- i ++;
- if (nparams > i)
- g_strlcpy (xsvals.prefix, param[i].data.d_string,
- MAX_PREFIX);
+ /* Get the parasites */
+ parasite = gimp_image_get_parasite (image, "gimp-comment");
- i += 2;
- if (nparams > i)
- {
- xsvals.write_mask = param[i - 1].data.d_int32;
- g_strlcpy (xsvals.mask_ext, param[i].data.d_string,
- MAX_MASK_EXT);
- }
+ if (parasite)
+ {
+ gint size = gimp_parasite_data_size (parasite);
- i ++;
- /* Too many arguments. */
- if (nparams > i)
- status = GIMP_PDB_CALLING_ERROR;
- }
- break;
+ g_strlcpy (xsvals.comment,
+ gimp_parasite_data (parasite),
+ MIN (size, MAX_COMMENT));
- default:
- break;
+ gimp_parasite_free (parasite);
}
- if (run_mode == GIMP_RUN_INTERACTIVE)
+ parasite = gimp_image_get_parasite (image, "hot-spot");
+
+ if (parasite)
{
- /* Get the parasites */
- parasite = gimp_image_get_parasite (image_ID, "gimp-comment");
+ gint x, y;
- if (parasite)
+ if (sscanf (gimp_parasite_data (parasite), "%i %i", &x, &y) == 2)
{
- gint size = gimp_parasite_data_size (parasite);
-
- g_strlcpy (xsvals.comment,
- gimp_parasite_data (parasite),
- MIN (size, MAX_COMMENT));
-
- gimp_parasite_free (parasite);
+ xsvals.use_hot = TRUE;
+ xsvals.x_hot = x;
+ xsvals.y_hot = y;
}
- parasite = gimp_image_get_parasite (image_ID, "hot-spot");
-
- if (parasite)
- {
- gint x, y;
-
- if (sscanf (gimp_parasite_data (parasite), "%i %i", &x, &y) == 2)
- {
- xsvals.use_hot = TRUE;
- xsvals.x_hot = x;
- xsvals.y_hot = y;
- }
- gimp_parasite_free (parasite);
- }
-
- /* Acquire information with a dialog */
- if (! save_dialog (drawable_ID))
- status = GIMP_PDB_CANCEL;
+ gimp_parasite_free (parasite);
}
- if (status == GIMP_PDB_SUCCESS)
- {
- GFile *file = g_file_new_for_uri (param[3].data.d_string);
- GFile *mask_file;
- GFile *dir;
- gchar *mask_prefix;
- gchar *temp;
+ if (! save_dialog (drawable))
+ return gimp_procedure_new_return_values (procedure,
+ GIMP_PDB_CANCEL,
+ NULL);
+ }
- dir = g_file_get_parent (file);
- temp = g_strdup_printf ("%s%s.xbm", mask_basename, xsvals.mask_ext);
+ if (status == GIMP_PDB_SUCCESS)
+ {
+ GFile *mask_file;
+ GFile *dir;
+ gchar *mask_prefix;
+ gchar *temp;
- mask_file = g_file_get_child (dir, temp);
+ dir = g_file_get_parent (file);
+ temp = g_strdup_printf ("%s%s.xbm", mask_basename, xsvals.mask_ext);
- g_free (temp);
- g_object_unref (dir);
+ mask_file = g_file_get_child (dir, temp);
- /* Change any non-alphanumeric prefix characters to underscores. */
- for (temp = xsvals.prefix; *temp; temp++)
- if (! g_ascii_isalnum (*temp))
- *temp = '_';
+ g_free (temp);
+ g_object_unref (dir);
- mask_prefix = g_strdup_printf ("%s%s",
- xsvals.prefix, xsvals.mask_ext);
+ /* Change any non-alphanumeric prefix characters to underscores. */
+ for (temp = xsvals.prefix; *temp; temp++)
+ if (! g_ascii_isalnum (*temp))
+ *temp = '_';
- for (temp = mask_prefix; *temp; temp++)
- if (! g_ascii_isalnum (*temp))
- *temp = '_';
+ mask_prefix = g_strdup_printf ("%s%s",
+ xsvals.prefix, xsvals.mask_ext);
- if (save_image (file,
- xsvals.prefix,
- xsvals.comment,
- FALSE,
- image_ID, drawable_ID,
- &error)
-
- && (! xsvals.write_mask ||
- save_image (mask_file,
- mask_prefix,
- xsvals.comment,
- TRUE,
- image_ID, drawable_ID,
- &error)))
- {
- /* Store xsvals data */
- gimp_set_data (SAVE_PROC, &xsvals, sizeof (xsvals));
- }
- else
- {
- status = GIMP_PDB_EXECUTION_ERROR;
- }
+ for (temp = mask_prefix; *temp; temp++)
+ if (! g_ascii_isalnum (*temp))
+ *temp = '_';
- g_free (mask_prefix);
- g_free (mask_basename);
+ if (save_image (file,
+ xsvals.prefix,
+ xsvals.comment,
+ FALSE,
+ image, drawable,
+ &error)
- g_object_unref (file);
- g_object_unref (mask_file);
+ && (! xsvals.write_mask ||
+ save_image (mask_file,
+ mask_prefix,
+ xsvals.comment,
+ TRUE,
+ image, drawable,
+ &error)))
+ {
+ /* Store xsvals data */
+ gimp_set_data (SAVE_PROC, &xsvals, sizeof (xsvals));
+ }
+ else
+ {
+ status = GIMP_PDB_EXECUTION_ERROR;
}
- if (export == GIMP_EXPORT_EXPORT)
- gimp_image_delete (image_ID);
- }
- else
- {
- status = GIMP_PDB_CALLING_ERROR;
- }
+ g_free (mask_prefix);
+ g_free (mask_basename);
- if (status != GIMP_PDB_SUCCESS && error)
- {
- *nreturn_vals = 2;
- values[1].type = GIMP_PDB_STRING;
- values[1].data.d_string = error->message;
+ g_object_unref (mask_file);
}
- values[0].data.d_status = status;
-}
+ if (export == GIMP_EXPORT_EXPORT)
+ gimp_image_delete (image);
+ return gimp_procedure_new_return_values (procedure, status, error);
+}
/* Return the value of a digit. */
static gint
@@ -707,15 +740,14 @@ get_int (FILE *fp)
return val;
}
-
-static gint32
+static GimpImage *
load_image (const gchar *filename,
GError **error)
{
FILE *fp;
GeglBuffer *buffer;
- gint32 image_ID;
- gint32 layer_ID;
+ GimpImage *image;
+ GimpLayer *layer;
guchar *data;
gint intbits;
gint width = 0;
@@ -741,7 +773,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;
}
comment = fgetcomment (fp);
@@ -822,7 +854,7 @@ load_image (const gchar *filename,
g_message (_("'%s':\nCould not read header (ftell == %ld)"),
gimp_filename_to_utf8 (filename), ftell (fp));
fclose (fp);
- return -1;
+ return NULL;
}
if (width <= 0)
@@ -830,7 +862,7 @@ load_image (const gchar *filename,
g_message (_("'%s':\nNo image width specified"),
gimp_filename_to_utf8 (filename));
fclose (fp);
- return -1;
+ return NULL;
}
if (width > GIMP_MAX_IMAGE_SIZE)
@@ -838,7 +870,7 @@ load_image (const gchar *filename,
g_message (_("'%s':\nImage width is larger than GIMP can handle"),
gimp_filename_to_utf8 (filename));
fclose (fp);
- return -1;
+ return NULL;
}
if (height <= 0)
@@ -846,7 +878,7 @@ load_image (const gchar *filename,
g_message (_("'%s':\nNo image height specified"),
gimp_filename_to_utf8 (filename));
fclose (fp);
- return -1;
+ return NULL;
}
if (height > GIMP_MAX_IMAGE_SIZE)
@@ -854,7 +886,7 @@ load_image (const gchar *filename,
g_message (_("'%s':\nImage height is larger than GIMP can handle"),
gimp_filename_to_utf8 (filename));
fclose (fp);
- return -1;
+ return NULL;
}
if (intbits == 0)
@@ -862,11 +894,11 @@ load_image (const gchar *filename,
g_message (_("'%s':\nNo image data type specified"),
gimp_filename_to_utf8 (filename));
fclose (fp);
- return -1;
+ return NULL;
}
- image_ID = gimp_image_new (width, height, GIMP_INDEXED);
- gimp_image_set_filename (image_ID, filename);
+ image = gimp_image_new (width, height, GIMP_INDEXED);
+ gimp_image_set_filename (image, filename);
if (comment)
{
@@ -875,7 +907,7 @@ load_image (const gchar *filename,
parasite = gimp_parasite_new ("gimp-comment",
GIMP_PARASITE_PERSISTENT,
strlen (comment) + 1, (gpointer) comment);
- gimp_image_attach_parasite (image_ID, parasite);
+ gimp_image_attach_parasite (image, parasite);
gimp_parasite_free (parasite);
g_free (comment);
@@ -894,22 +926,22 @@ load_image (const gchar *filename,
GIMP_PARASITE_PERSISTENT,
strlen (str) + 1, (gpointer) str);
g_free (str);
- gimp_image_attach_parasite (image_ID, parasite);
+ gimp_image_attach_parasite (image, parasite);
gimp_parasite_free (parasite);
}
/* Set a black-and-white colormap. */
- gimp_image_set_colormap (image_ID, cmap, 2);
+ gimp_image_set_colormap (image, cmap, 2);
- layer_ID = gimp_layer_new (image_ID,
- _("Background"),
- width, height,
- GIMP_INDEXED_IMAGE,
- 100,
- gimp_image_get_default_new_layer_mode (image_ID));
- gimp_image_insert_layer (image_ID, layer_ID, -1, 0);
+ layer = gimp_layer_new (image,
+ _("Background"),
+ width, height,
+ GIMP_INDEXED_IMAGE,
+ 100,
+ gimp_image_get_default_new_layer_mode (image));
+ gimp_image_insert_layer (image, layer, NULL, 0);
- buffer = gimp_drawable_get_buffer (layer_ID);
+ buffer = gimp_drawable_get_buffer (GIMP_DRAWABLE (layer));
/* Allocate the data. */
tileheight = gimp_tile_height ();
@@ -960,17 +992,17 @@ load_image (const gchar *filename,
gimp_progress_update (1.0);
- return image_ID;
+ return image;
}
static gboolean
-save_image (GFile *file,
- const gchar *prefix,
- const gchar *comment,
- gboolean save_mask,
- gint32 image_ID,
- gint32 drawable_ID,
- GError **error)
+save_image (GFile *file,
+ const gchar *prefix,
+ const gchar *comment,
+ gboolean save_mask,
+ GimpImage *image,
+ GimpDrawable *drawable,
+ GError **error)
{
GOutputStream *output;
GeglBuffer *buffer;
@@ -991,9 +1023,9 @@ save_image (GFile *file,
g_printerr ("%s: save_image '%s'\n", G_STRFUNC, prefix);
#endif
- cmap = gimp_image_get_colormap (image_ID, &colors);
+ cmap = gimp_image_get_colormap (image, &colors);
- if (! gimp_drawable_is_indexed (drawable_ID) || colors > 2)
+ if (! gimp_drawable_is_indexed (drawable) || colors > 2)
{
/* The image is not black-and-white. */
g_message (_("The image which you are trying to export as "
@@ -1004,7 +1036,7 @@ save_image (GFile *file,
return FALSE;
}
- has_alpha = gimp_drawable_has_alpha (drawable_ID);
+ has_alpha = gimp_drawable_has_alpha (drawable);
if (! has_alpha && save_mask)
{
@@ -1013,10 +1045,10 @@ save_image (GFile *file,
return FALSE;
}
- buffer = gimp_drawable_get_buffer (drawable_ID);
+ buffer = gimp_drawable_get_buffer (drawable);
width = gegl_buffer_get_width (buffer);
height = gegl_buffer_get_height (buffer);
- bpp = gimp_drawable_bpp (drawable_ID);
+ bpp = gimp_drawable_bpp (drawable);
/* Figure out which color is black, and which is white. */
dark = 0;
@@ -1230,7 +1262,7 @@ save_image (GFile *file,
}
static gboolean
-save_dialog (gint32 drawable_ID)
+save_dialog (GimpDrawable *drawable)
{
GtkWidget *dialog;
GtkWidget *frame;
@@ -1317,7 +1349,7 @@ save_dialog (gint32 drawable_ID)
G_BINDING_SYNC_CREATE);
adj = gtk_adjustment_new (xsvals.x_hot, 0,
- gimp_drawable_width (drawable_ID) - 1,
+ gimp_drawable_width (drawable) - 1,
1, 10, 0);
spinbutton = gimp_spin_button_new (adj, 1.0, 0);
gtk_spin_button_set_numeric (GTK_SPIN_BUTTON (spinbutton), TRUE);
@@ -1330,7 +1362,7 @@ save_dialog (gint32 drawable_ID)
&xsvals.x_hot);
adj = gtk_adjustment_new (xsvals.y_hot, 0,
- gimp_drawable_height (drawable_ID) - 1,
+ gimp_drawable_height (drawable) - 1,
1, 10, 0);
spinbutton = gimp_spin_button_new (adj, 1.0, 0);
gtk_spin_button_set_numeric (GTK_SPIN_BUTTON (spinbutton), TRUE);
@@ -1376,7 +1408,7 @@ save_dialog (gint32 drawable_ID)
entry, "sensitive",
G_BINDING_SYNC_CREATE);
- gtk_widget_set_sensitive (frame, gimp_drawable_has_alpha (drawable_ID));
+ gtk_widget_set_sensitive (frame, gimp_drawable_has_alpha (drawable));
/* Done. */
gtk_widget_show (vbox);
diff --git a/plug-ins/common/plugin-defs.pl b/plug-ins/common/plugin-defs.pl
index 2376f5168a..ba4d11108d 100644
--- a/plug-ins/common/plugin-defs.pl
+++ b/plug-ins/common/plugin-defs.pl
@@ -47,7 +47,7 @@
'file-svg' => { ui => 1, gegl => 1, libs => 'SVG_LIBS', cflags => 'SVG_CFLAGS' },
'file-tga' => { ui => 1, gegl => 1, old_api => 1 },
'file-wmf' => { ui => 1, gegl => 1, optional => 1, libs => 'WMF_LIBS', cflags => 'WMF_CFLAGS' },
- 'file-xbm' => { ui => 1, gegl => 1, old_api => 1 },
+ 'file-xbm' => { ui => 1, gegl => 1 },
'file-xmc' => { ui => 1, gegl => 1, optional => 1, libs => 'XMC_LIBS' },
'file-xpm' => { ui => 1, gegl => 1, optional => 1, libs => 'XPM_LIBS', old_api => 1 },
'file-xwd' => { ui => 1, gegl => 1, old_api => 1 },
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]