[gimp] plug-ins: port file-xwd to GimpPlugIn and libgimp objects
- From: Michael Natterer <mitch src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gimp] plug-ins: port file-xwd to GimpPlugIn and libgimp objects
- Date: Sat, 24 Aug 2019 14:47:05 +0000 (UTC)
commit 44ebcee901f25180b8b9b04f6d26474919557f0d
Author: Michael Natterer <mitch gimp org>
Date: Sat Aug 24 16:46:40 2019 +0200
plug-ins: port file-xwd to GimpPlugIn and libgimp objects
plug-ins/common/Makefile.am | 2 -
plug-ins/common/file-xwd.c | 726 +++++++++++++++++++++--------------------
plug-ins/common/plugin-defs.pl | 2 +-
3 files changed, 372 insertions(+), 358 deletions(-)
---
diff --git a/plug-ins/common/Makefile.am b/plug-ins/common/Makefile.am
index 6916ea7a5b..aca8e3e9a5 100644
--- a/plug-ins/common/Makefile.am
+++ b/plug-ins/common/Makefile.am
@@ -1209,8 +1209,6 @@ file_xpm_LDADD = \
$(INTLLIBS) \
$(file_xpm_RC)
-file_xwd_CPPFLAGS = $(AM_CPPFLAGS) -DGIMP_DEPRECATED_REPLACE_NEW_API
-
file_xwd_SOURCES = \
file-xwd.c
diff --git a/plug-ins/common/file-xwd.c b/plug-ins/common/file-xwd.c
index 4a233917d1..c0bd1a2c33 100644
--- a/plug-ins/common/file-xwd.c
+++ b/plug-ins/common/file-xwd.c
@@ -135,313 +135,326 @@ typedef struct
#define XWDHDR_PAD 0 /* Total number of padding bytes for XWD header */
#define XWDCOL_PAD 0 /* Total number of padding bytes for each XWD color */
-/* 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 gboolean save_image (GFile *file,
- gint32 image_ID,
- gint32 drawable_ID,
- GError **error);
-static gint32 create_new_image (const gchar *filename,
- guint width,
- guint height,
- GimpImageBaseType type,
- GimpImageType gdtype,
- gint32 *layer_ID,
- GeglBuffer **buffer);
-
-static int set_pixelmap (gint ncols,
- L_XWDCOLOR *xwdcol,
- PIXEL_MAP *pixelmap);
-static gboolean get_pixelmap (L_CARD32 pixelval,
- PIXEL_MAP *pixelmap,
- guchar *red,
- guchar *green,
- guchar *glue);
-
-static void set_bw_color_table (gint32 image_ID);
-static void set_color_table (gint32 image_ID,
- L_XWDFILEHEADER *xwdhdr,
- L_XWDCOLOR *xwdcolmap);
-
-static gint32 load_xwd_f2_d1_b1 (const gchar *filename,
- FILE *ifp,
- L_XWDFILEHEADER *xwdhdr,
- L_XWDCOLOR *xwdcolmap);
-static gint32 load_xwd_f2_d8_b8 (const gchar *filename,
- FILE *ifp,
- L_XWDFILEHEADER *xwdhdr,
- L_XWDCOLOR *xwdcolmap);
-static gint32 load_xwd_f2_d16_b16 (const gchar *filename,
- FILE *ifp,
- L_XWDFILEHEADER *xwdhdr,
- L_XWDCOLOR *xwdcolmap);
-static gint32 load_xwd_f2_d24_b32 (const gchar *filename,
- FILE *ifp,
- L_XWDFILEHEADER *xwdhdr,
- L_XWDCOLOR *xwdcolmap,
- GError **error);
-static gint32 load_xwd_f2_d32_b32 (const gchar *filename,
- FILE *ifp,
- L_XWDFILEHEADER *xwdhdr,
- L_XWDCOLOR *xwdcolmap);
-static gint32 load_xwd_f1_d24_b1 (const gchar *filename,
- FILE *ifp,
- L_XWDFILEHEADER *xwdhdr,
- L_XWDCOLOR *xwdcolmap,
- GError **error);
-
-static L_CARD32 read_card32 (FILE *ifp,
- gint *err);
-static L_CARD16 read_card16 (FILE *ifp,
- gint *err);
-static L_CARD8 read_card8 (FILE *ifp,
- gint *err);
-
-static gboolean write_card32 (GOutputStream *output,
- L_CARD32 c,
- GError **error);
-static gboolean write_card16 (GOutputStream *output,
- L_CARD32 c,
- GError **error);
-static gboolean write_card8 (GOutputStream *output,
- L_CARD32 c,
- GError **error);
-
-static void read_xwd_header (FILE *ifp,
- L_XWDFILEHEADER *xwdhdr);
-
-static gboolean write_xwd_header (GOutputStream *output,
- L_XWDFILEHEADER *xwdhdr,
- GError **error);
-
-static void read_xwd_cols (FILE *ifp,
- L_XWDFILEHEADER *xwdhdr,
- L_XWDCOLOR *xwdcolmap);
-
-static gboolean write_xwd_cols (GOutputStream *output,
- L_XWDFILEHEADER *xwdhdr,
- L_XWDCOLOR *colormap,
- GError **error);
-
-static gint save_index (GOutputStream *output,
- gint32 image_ID,
- gint32 drawable_ID,
- gboolean gray,
- GError **error);
-static gint save_rgb (GOutputStream *output,
- gint32 image_ID,
- gint32 drawable_ID,
- GError **error);
-
-
-const GimpPlugInInfo PLUG_IN_INFO =
+
+typedef struct _Xwd Xwd;
+typedef struct _XwdClass XwdClass;
+
+struct _Xwd
+{
+ GimpPlugIn parent_instance;
+};
+
+struct _XwdClass
{
- NULL, /* init_proc */
- NULL, /* quit_proc */
- query, /* query_proc */
- run, /* run_proc */
+ GimpPlugInClass parent_class;
};
-MAIN ()
+#define XWD_TYPE (xwd_get_type ())
+#define XWD (obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), XWD_TYPE, Xwd))
+
+GType xwd_get_type (void) G_GNUC_CONST;
+
+static GList * xwd_query_procedures (GimpPlugIn *plug_in);
+static GimpProcedure * xwd_create_procedure (GimpPlugIn *plug_in,
+ const gchar *name);
+
+static GimpValueArray * xwd_load (GimpProcedure *procedure,
+ GimpRunMode run_mode,
+ GFile *file,
+ const GimpValueArray *args,
+ gpointer run_data);
+static GimpValueArray * xwd_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,
+ GimpImage *image,
+ GimpDrawable *drawable,
+ GError **error);
+static GimpImage * create_new_image (const gchar *filename,
+ guint width,
+ guint height,
+ GimpImageBaseType type,
+ GimpImageType gdtype,
+ GimpLayer **layer,
+ GeglBuffer **buffer);
+
+static int set_pixelmap (gint ncols,
+ L_XWDCOLOR *xwdcol,
+ PIXEL_MAP *pixelmap);
+static gboolean get_pixelmap (L_CARD32 pixelval,
+ PIXEL_MAP *pixelmap,
+ guchar *red,
+ guchar *green,
+ guchar *glue);
+
+static void set_bw_color_table (GimpImage *image);
+static void set_color_table (GimpImage *image,
+ L_XWDFILEHEADER *xwdhdr,
+ L_XWDCOLOR *xwdcolmap);
+
+static GimpImage * load_xwd_f2_d1_b1 (const gchar *filename,
+ FILE *ifp,
+ L_XWDFILEHEADER *xwdhdr,
+ L_XWDCOLOR *xwdcolmap);
+static GimpImage * load_xwd_f2_d8_b8 (const gchar *filename,
+ FILE *ifp,
+ L_XWDFILEHEADER *xwdhdr,
+ L_XWDCOLOR *xwdcolmap);
+static GimpImage * load_xwd_f2_d16_b16 (const gchar *filename,
+ FILE *ifp,
+ L_XWDFILEHEADER *xwdhdr,
+ L_XWDCOLOR *xwdcolmap);
+static GimpImage * load_xwd_f2_d24_b32 (const gchar *filename,
+ FILE *ifp,
+ L_XWDFILEHEADER *xwdhdr,
+ L_XWDCOLOR *xwdcolmap,
+ GError **error);
+static GimpImage * load_xwd_f2_d32_b32 (const gchar *filename,
+ FILE *ifp,
+ L_XWDFILEHEADER *xwdhdr,
+ L_XWDCOLOR *xwdcolmap);
+static GimpImage * load_xwd_f1_d24_b1 (const gchar *filename,
+ FILE *ifp,
+ L_XWDFILEHEADER *xwdhdr,
+ L_XWDCOLOR *xwdcolmap,
+ GError **error);
+
+static L_CARD32 read_card32 (FILE *ifp,
+ gint *err);
+static L_CARD16 read_card16 (FILE *ifp,
+ gint *err);
+static L_CARD8 read_card8 (FILE *ifp,
+ gint *err);
+
+static gboolean write_card32 (GOutputStream *output,
+ L_CARD32 c,
+ GError **error);
+static gboolean write_card16 (GOutputStream *output,
+ L_CARD32 c,
+ GError **error);
+static gboolean write_card8 (GOutputStream *output,
+ L_CARD32 c,
+ GError **error);
+
+static void read_xwd_header (FILE *ifp,
+ L_XWDFILEHEADER *xwdhdr);
+
+static gboolean write_xwd_header (GOutputStream *output,
+ L_XWDFILEHEADER *xwdhdr,
+ GError **error);
+
+static void read_xwd_cols (FILE *ifp,
+ L_XWDFILEHEADER *xwdhdr,
+ L_XWDCOLOR *xwdcolmap);
+
+static gboolean write_xwd_cols (GOutputStream *output,
+ L_XWDFILEHEADER *xwdhdr,
+ L_XWDCOLOR *colormap,
+ GError **error);
+
+static gint save_index (GOutputStream *output,
+ GimpImage *image,
+ GimpDrawable *drawable,
+ gboolean gray,
+ GError **error);
+static gint save_rgb (GOutputStream *output,
+ GimpImage *image,
+ GimpDrawable *drawable,
+ GError **error);
+
+
+G_DEFINE_TYPE (Xwd, xwd, GIMP_TYPE_PLUG_IN)
+
+GIMP_MAIN (XWD_TYPE)
static void
-query (void)
+xwd_class_init (XwdClass *klass)
{
- 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" }
- };
+ GimpPlugInClass *plug_in_class = GIMP_PLUG_IN_CLASS (klass);
- 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 the image in" },
- { GIMP_PDB_STRING, "raw-filename", "The name of the file to export the image in" }
- };
-
- gimp_install_procedure (LOAD_PROC,
- "Loads files in the XWD (X Window Dump) format",
- "Loads files in the XWD (X Window Dump) format. "
- "XWD image files are produced by the program xwd. "
- "Xwd is an X Window System window dumping utility.",
- "Peter Kirchgessner",
- "Peter Kirchgessner",
- "1996",
- N_("X window dump"),
- 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-xwindowdump");
- gimp_register_magic_load_handler (LOAD_PROC,
- "xwd",
- "",
- "4,long,0x00000007");
-
- gimp_install_procedure (SAVE_PROC,
- "Exports files in the XWD (X Window Dump) format",
- "XWD exporting handles all image types except "
- "those with alpha channels.",
- "Peter Kirchgessner",
- "Peter Kirchgessner",
- "1996",
- N_("X window dump"),
- "RGB, GRAY, INDEXED",
- GIMP_PLUGIN,
- G_N_ELEMENTS (save_args), 0,
- save_args, NULL);
-
- gimp_register_file_handler_mime (SAVE_PROC, "image/x-xwindowdump");
- gimp_register_file_handler_remote (SAVE_PROC);
- gimp_register_save_handler (SAVE_PROC, "xwd", "");
+ plug_in_class->query_procedures = xwd_query_procedures;
+ plug_in_class->create_procedure = xwd_create_procedure;
}
static void
-run (const gchar *name,
- gint nparams,
- const GimpParam *param,
- gint *nreturn_vals,
- GimpParam **return_vals)
+xwd_init (Xwd *xwd)
{
- static GimpParam values[2];
- GimpRunMode run_mode;
- GimpPDBStatusType status = GIMP_PDB_SUCCESS;
- gint32 image_ID;
- gint32 drawable_ID;
- GimpExportReturn export = GIMP_EXPORT_CANCEL;
- GError *error = NULL;
+}
- run_mode = param[0].data.d_int32;
+static GList *
+xwd_query_procedures (GimpPlugIn *plug_in)
+{
+ GList *list = NULL;
- INIT_I18N ();
- gegl_init (NULL, NULL);
+ list = g_list_append (list, g_strdup (LOAD_PROC));
+ list = g_list_append (list, g_strdup (SAVE_PROC));
- *nreturn_vals = 1;
- *return_vals = values;
+ return list;
+}
- values[0].type = GIMP_PDB_STATUS;
- values[0].data.d_status = GIMP_PDB_EXECUTION_ERROR;
+static GimpProcedure *
+xwd_create_procedure (GimpPlugIn *plug_in,
+ const gchar *name)
+{
+ GimpProcedure *procedure = NULL;
- if (strcmp (name, LOAD_PROC) == 0)
+ if (! strcmp (name, LOAD_PROC))
{
- image_ID = load_image (param[1].data.d_string, &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;
- }
+ procedure = gimp_load_procedure_new (plug_in, name, GIMP_PLUGIN,
+ xwd_load, NULL, NULL);
+
+ gimp_procedure_set_menu_label (procedure, N_("X window dump"));
+
+ gimp_procedure_set_documentation (procedure,
+ "Loads files in the XWD (X Window Dump) "
+ "format",
+ "Loads files in the XWD (X Window Dump) "
+ "format. XWD image files are produced "
+ "by the program xwd. Xwd is an X Window "
+ "System window dumping utility.",
+ name);
+ gimp_procedure_set_attribution (procedure,
+ "Peter Kirchgessner",
+ "Peter Kirchgessner",
+ "1996");
+
+ gimp_file_procedure_set_mime_types (GIMP_FILE_PROCEDURE (procedure),
+ "image/x-xwindowdump");
+ gimp_file_procedure_set_extensions (GIMP_FILE_PROCEDURE (procedure),
+ "xwd");
+ gimp_file_procedure_set_magics (GIMP_FILE_PROCEDURE (procedure),
+ "4,long,0x00000007");
}
- else if (strcmp (name, SAVE_PROC) == 0)
+ else if (! strcmp (name, SAVE_PROC))
{
- image_ID = param[1].data.d_int32;
- drawable_ID = param[2].data.d_int32;
+ procedure = gimp_save_procedure_new (plug_in, name, GIMP_PLUGIN,
+ xwd_save, NULL, NULL);
+
+ gimp_procedure_set_image_types (procedure, "RGB, GRAY, INDEXED");
+
+ gimp_procedure_set_menu_label (procedure, N_("X window dump"));
+
+ gimp_procedure_set_documentation (procedure,
+ "Exports files in the XWD (X Window "
+ "Dump) format",
+ "XWD exporting handles all image "
+ "types except those with alpha channels.",
+ name);
+ gimp_procedure_set_attribution (procedure,
+ "Peter Kirchgessner",
+ "Peter Kirchgessner",
+ "1996");
+
+ gimp_file_procedure_set_handles_remote (GIMP_FILE_PROCEDURE (procedure),
+ TRUE);
+ gimp_file_procedure_set_mime_types (GIMP_FILE_PROCEDURE (procedure),
+ "image/x-xwindowdump");
+ gimp_file_procedure_set_extensions (GIMP_FILE_PROCEDURE (procedure),
+ "xwd");
+ }
- /* eventually export the image */
- switch (run_mode)
- {
- case GIMP_RUN_INTERACTIVE:
- case GIMP_RUN_WITH_LAST_VALS:
- gimp_ui_init (PLUG_IN_BINARY, FALSE);
+ return procedure;
+}
- export = gimp_export_image (&image_ID, &drawable_ID, "XWD",
- GIMP_EXPORT_CAN_HANDLE_RGB |
- GIMP_EXPORT_CAN_HANDLE_GRAY |
- GIMP_EXPORT_CAN_HANDLE_INDEXED);
+static GimpValueArray *
+xwd_load (GimpProcedure *procedure,
+ GimpRunMode run_mode,
+ GFile *file,
+ const GimpValueArray *args,
+ gpointer run_data)
+{
+ GimpValueArray *return_vals;
+ GimpImage *image;
+ gchar *filename;
+ GError *error = NULL;
- if (export == GIMP_EXPORT_CANCEL)
- {
- values[0].data.d_status = GIMP_PDB_CANCEL;
- return;
- }
- break;
+ INIT_I18N ();
+ gegl_init (NULL, NULL);
- default:
- break;
- }
+ filename = g_file_get_path (file);
- switch (run_mode)
- {
- case GIMP_RUN_INTERACTIVE:
- case GIMP_RUN_WITH_LAST_VALS:
- /* No additional data to retrieve */
- break;
+ image = load_image (filename, &error);
- case GIMP_RUN_NONINTERACTIVE:
- /* Make sure all the arguments are there! */
- if (nparams != 5)
- status = GIMP_PDB_CALLING_ERROR;
- break;
+ g_free (filename);
- default:
- break;
- }
+ if (! image)
+ return gimp_procedure_new_return_values (procedure,
+ GIMP_PDB_EXECUTION_ERROR,
+ error);
- if (status == GIMP_PDB_SUCCESS)
- {
- GFile *file = g_file_new_for_uri (param[3].data.d_string);
+ return_vals = gimp_procedure_new_return_values (procedure,
+ GIMP_PDB_SUCCESS,
+ NULL);
- if (! save_image (file, image_ID, drawable_ID, &error))
- {
- status = GIMP_PDB_EXECUTION_ERROR;
- }
+ GIMP_VALUES_SET_IMAGE (return_vals, 1, image);
- g_object_unref (file);
- }
+ return return_vals;
+}
- if (export == GIMP_EXPORT_EXPORT)
- gimp_image_delete (image_ID);
- }
- else
+static GimpValueArray *
+xwd_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;
+
+ INIT_I18N ();
+ gegl_init (NULL, NULL);
+
+ switch (run_mode)
{
- status = GIMP_PDB_CANCEL;
+ case GIMP_RUN_INTERACTIVE:
+ case GIMP_RUN_WITH_LAST_VALS:
+ gimp_ui_init (PLUG_IN_BINARY, FALSE);
+
+ export = gimp_export_image (&image, &drawable, "XWD",
+ GIMP_EXPORT_CAN_HANDLE_RGB |
+ GIMP_EXPORT_CAN_HANDLE_GRAY |
+ GIMP_EXPORT_CAN_HANDLE_INDEXED);
+
+ if (export == GIMP_EXPORT_CANCEL)
+ return gimp_procedure_new_return_values (procedure,
+ GIMP_PDB_CANCEL,
+ NULL);
+ break;
+
+ default:
+ break;
}
- if (status != GIMP_PDB_SUCCESS && error)
+ if (! save_image (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);
+ return gimp_procedure_new_return_values (procedure, status, error);
+}
-static gint32
+static GimpImage *
load_image (const gchar *filename,
GError **error)
{
FILE *ifp = NULL;
gint depth, bpp;
- gint32 image_ID = -1;
+ GimpImage *image = NULL;
L_XWDFILEHEADER xwdhdr;
L_XWDCOLOR *xwdcolmap = NULL;
@@ -552,51 +565,52 @@ load_image (const gchar *filename,
depth = xwdhdr.l_pixmap_depth;
bpp = xwdhdr.l_bits_per_pixel;
- image_ID = -1;
+ image = NULL;
+
switch (xwdhdr.l_pixmap_format)
{
case 0: /* Single plane bitmap */
if ((depth == 1) && (bpp == 1))
{ /* Can be performed by format 2 loader */
- image_ID = load_xwd_f2_d1_b1 (filename, ifp, &xwdhdr, xwdcolmap);
+ image = load_xwd_f2_d1_b1 (filename, ifp, &xwdhdr, xwdcolmap);
}
break;
case 1: /* Single plane pixmap */
if ((depth <= 24) && (bpp == 1))
{
- image_ID = load_xwd_f1_d24_b1 (filename, ifp, &xwdhdr, xwdcolmap,
- error);
+ image = load_xwd_f1_d24_b1 (filename, ifp, &xwdhdr, xwdcolmap,
+ error);
}
break;
case 2: /* Multiplane pixmaps */
if ((depth == 1) && (bpp == 1))
{
- image_ID = load_xwd_f2_d1_b1 (filename, ifp, &xwdhdr, xwdcolmap);
+ image = load_xwd_f2_d1_b1 (filename, ifp, &xwdhdr, xwdcolmap);
}
else if ((depth <= 8) && (bpp == 8))
{
- image_ID = load_xwd_f2_d8_b8 (filename, ifp, &xwdhdr, xwdcolmap);
+ image = load_xwd_f2_d8_b8 (filename, ifp, &xwdhdr, xwdcolmap);
}
else if ((depth <= 16) && (bpp == 16))
{
- image_ID = load_xwd_f2_d16_b16 (filename, ifp, &xwdhdr, xwdcolmap);
+ image = load_xwd_f2_d16_b16 (filename, ifp, &xwdhdr, xwdcolmap);
}
else if ((depth <= 24) && ((bpp == 24) || (bpp == 32)))
{
- image_ID = load_xwd_f2_d24_b32 (filename, ifp, &xwdhdr, xwdcolmap,
+ image = load_xwd_f2_d24_b32 (filename, ifp, &xwdhdr, xwdcolmap,
error);
}
else if ((depth <= 32) && (bpp == 32))
{
- image_ID = load_xwd_f2_d32_b32 (filename, ifp, &xwdhdr, xwdcolmap);
+ image = load_xwd_f2_d32_b32 (filename, ifp, &xwdhdr, xwdcolmap);
}
break;
}
gimp_progress_update (1.0);
- if (image_ID == -1 && ! (error && *error))
+ if (! image && ! (error && *error))
g_set_error (error, G_FILE_ERROR, G_FILE_ERROR_FAILED,
_("XWD-file %s has format %d, depth %d and bits per pixel %d. "
"Currently this is not supported."),
@@ -605,32 +619,28 @@ load_image (const gchar *filename,
out:
if (ifp)
- {
- fclose (ifp);
- }
+ fclose (ifp);
if (xwdcolmap)
- {
- g_free (xwdcolmap);
- }
+ g_free (xwdcolmap);
- return image_ID;
+ return image;
}
static gboolean
-save_image (GFile *file,
- gint32 image_ID,
- gint32 drawable_ID,
- GError **error)
+save_image (GFile *file,
+ GimpImage *image,
+ GimpDrawable *drawable,
+ GError **error)
{
GOutputStream *output;
GimpImageType drawable_type;
gboolean success;
- drawable_type = gimp_drawable_type (drawable_ID);
+ drawable_type = gimp_drawable_type (drawable);
/* Make sure we're not exporting an image with an alpha channel */
- if (gimp_drawable_has_alpha (drawable_ID))
+ if (gimp_drawable_has_alpha (drawable))
{
g_set_error_literal (error, G_FILE_ERROR, G_FILE_ERROR_FAILED,
_("Cannot export images with alpha channels."));
@@ -664,15 +674,15 @@ save_image (GFile *file,
switch (drawable_type)
{
case GIMP_INDEXED_IMAGE:
- success = save_index (output, image_ID, drawable_ID, FALSE, error);
+ success = save_index (output, image, drawable, FALSE, error);
break;
case GIMP_GRAY_IMAGE:
- success = save_index (output, image_ID, drawable_ID, TRUE, error);
+ success = save_index (output, image, drawable, TRUE, error);
break;
case GIMP_RGB_IMAGE:
- success = save_rgb (output, image_ID, drawable_ID, error);
+ success = save_rgb (output, image, drawable, error);
break;
default:
@@ -1144,7 +1154,7 @@ get_pixelmap (L_CARD32 pixelval,
static void
-set_bw_color_table (gint32 image_ID)
+set_bw_color_table (GimpImage *image)
{
static guchar BWColorMap[2*3] = { 255, 255, 255, 0, 0, 0 };
@@ -1152,7 +1162,7 @@ set_bw_color_table (gint32 image_ID)
g_printf ("Set GIMP b/w-colortable:\n");
#endif
- gimp_image_set_colormap (image_ID, BWColorMap, 2);
+ gimp_image_set_colormap (image, BWColorMap, 2);
}
@@ -1221,7 +1231,7 @@ init_color_table256 (L_XWDFILEHEADER *xwdhdr,
static void
-set_color_table (gint32 image_ID,
+set_color_table (GimpImage *image,
L_XWDFILEHEADER *xwdhdr,
L_XWDCOLOR *xwdcolmap)
@@ -1258,42 +1268,42 @@ set_color_table (gint32 image_ID,
ColorMap[j*3], ColorMap[j*3+1], ColorMap[j*3+2]);
#endif
- gimp_image_set_colormap (image_ID, ColorMap, 256);
+ gimp_image_set_colormap (image, ColorMap, 256);
}
-/* Create an image. Sets layer_ID, drawable and rgn. Returns image_ID */
-static gint32
+/* Create an image. Sets layer, drawable and rgn. Returns image */
+static GimpImage *
create_new_image (const gchar *filename,
guint width,
guint height,
GimpImageBaseType type,
GimpImageType gdtype,
- gint32 *layer_ID,
+ GimpLayer **layer,
GeglBuffer **buffer)
{
- gint32 image_ID;
+ GimpImage *image;
- image_ID = gimp_image_new (width, height, type);
- gimp_image_set_filename (image_ID, filename);
+ image = gimp_image_new (width, height, type);
+ gimp_image_set_filename (image, filename);
- *layer_ID = gimp_layer_new (image_ID, "Background", width, height,
- gdtype,
- 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,
+ gdtype,
+ 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));
- return image_ID;
+ return image;
}
/* Load XWD with pixmap_format 2, pixmap_depth 1, bits_per_pixel 1 */
-static gint32
+static GimpImage *
load_xwd_f2_d1_b1 (const gchar *filename,
FILE *ifp,
L_XWDFILEHEADER *xwdhdr,
@@ -1308,7 +1318,8 @@ load_xwd_f2_d1_b1 (const gchar *filename,
guchar bit2byte[256 * 8];
guchar *data, *scanline;
gint err = 0;
- gint32 layer_ID, image_ID;
+ GimpImage *image;
+ GimpLayer *layer;
GeglBuffer *buffer;
#ifdef XWD_DEBUG
@@ -1318,8 +1329,8 @@ load_xwd_f2_d1_b1 (const gchar *filename,
width = xwdhdr->l_pixmap_width;
height = xwdhdr->l_pixmap_height;
- image_ID = create_new_image (filename, width, height, GIMP_INDEXED,
- GIMP_INDEXED_IMAGE, &layer_ID, &buffer);
+ image = create_new_image (filename, width, height, GIMP_INDEXED,
+ GIMP_INDEXED_IMAGE, &layer, &buffer);
tile_height = gimp_tile_height ();
data = g_malloc (tile_height * width);
@@ -1331,9 +1342,9 @@ load_xwd_f2_d1_b1 (const gchar *filename,
ncols = xwdhdr->l_ncolors;
if (ncols < 2)
- set_bw_color_table (image_ID);
+ set_bw_color_table (image);
else
- set_color_table (image_ID, xwdhdr, xwdcolmap);
+ set_color_table (image, xwdhdr, xwdcolmap);
temp = (gchar *) bit2byte;
@@ -1430,13 +1441,13 @@ load_xwd_f2_d1_b1 (const gchar *filename,
g_object_unref (buffer);
- return err ? -1 : image_ID;
+ return err ? NULL : image;
}
/* Load XWD with pixmap_format 2, pixmap_depth 8, bits_per_pixel 8 */
-static gint32
+static GimpImage *
load_xwd_f2_d8_b8 (const gchar *filename,
FILE *ifp,
L_XWDFILEHEADER *xwdhdr,
@@ -1447,7 +1458,8 @@ load_xwd_f2_d8_b8 (const gchar *filename,
gint grayscale;
guchar *dest, *data;
gint err = 0;
- gint32 layer_ID, image_ID;
+ GimpImage *image;
+ GimpLayer *layer;
GeglBuffer *buffer;
#ifdef XWD_DEBUG
@@ -1473,10 +1485,10 @@ load_xwd_f2_d8_b8 (const gchar *filename,
grayscale = (j == 256);
}
- image_ID = create_new_image (filename, width, height,
- grayscale ? GIMP_GRAY : GIMP_INDEXED,
- grayscale ? GIMP_GRAY_IMAGE : GIMP_INDEXED_IMAGE,
- &layer_ID, &buffer);
+ image = create_new_image (filename, width, height,
+ grayscale ? GIMP_GRAY : GIMP_INDEXED,
+ grayscale ? GIMP_GRAY_IMAGE : GIMP_INDEXED_IMAGE,
+ &layer, &buffer);
tile_height = gimp_tile_height ();
data = g_malloc (tile_height * width);
@@ -1486,9 +1498,9 @@ load_xwd_f2_d8_b8 (const gchar *filename,
ncols = xwdhdr->l_colormap_entries;
if (xwdhdr->l_ncolors < ncols) ncols = xwdhdr->l_ncolors;
if (ncols < 2)
- set_bw_color_table (image_ID);
+ set_bw_color_table (image);
else
- set_color_table (image_ID, xwdhdr, xwdcolmap);
+ set_color_table (image, xwdhdr, xwdcolmap);
}
linepad = xwdhdr->l_bytes_per_line - xwdhdr->l_pixmap_width;
@@ -1533,13 +1545,13 @@ load_xwd_f2_d8_b8 (const gchar *filename,
g_object_unref (buffer);
- return err ? -1 : image_ID;
+ return err ? NULL : image;
}
/* Load XWD with pixmap_format 2, pixmap_depth up to 16, bits_per_pixel 16 */
-static gint32
+static GimpImage *
load_xwd_f2_d16_b16 (const gchar *filename,
FILE *ifp,
L_XWDFILEHEADER *xwdhdr,
@@ -1555,7 +1567,8 @@ load_xwd_f2_d16_b16 (const gchar *filename,
gulong maxval;
guchar *ColorMap, *cm, *data;
gint err = 0;
- gint32 layer_ID, image_ID;
+ GimpImage *image;
+ GimpLayer *layer;
GeglBuffer *buffer;
#ifdef XWD_DEBUG
@@ -1565,8 +1578,8 @@ load_xwd_f2_d16_b16 (const gchar *filename,
width = xwdhdr->l_pixmap_width;
height = xwdhdr->l_pixmap_height;
- image_ID = create_new_image (filename, width, height, GIMP_RGB,
- GIMP_RGB_IMAGE, &layer_ID, &buffer);
+ image = create_new_image (filename, width, height, GIMP_RGB,
+ GIMP_RGB_IMAGE, &layer, &buffer);
tile_height = gimp_tile_height ();
data = g_malloc (tile_height * width * 3);
@@ -1692,13 +1705,13 @@ load_xwd_f2_d16_b16 (const gchar *filename,
g_object_unref (buffer);
- return err ? -1 : image_ID;
+ return err ? NULL : image;
}
/* Load XWD with pixmap_format 2, pixmap_depth up to 24, bits_per_pixel 24/32 */
-static gint32
+static GimpImage *
load_xwd_f2_d24_b32 (const gchar *filename,
FILE *ifp,
L_XWDFILEHEADER *xwdhdr,
@@ -1717,7 +1730,8 @@ load_xwd_f2_d24_b32 (const gchar *filename,
guchar *data;
PIXEL_MAP pixel_map;
gint err = 0;
- gint32 layer_ID, image_ID;
+ GimpImage *image;
+ GimpLayer *layer;
GeglBuffer *buffer;
#ifdef XWD_DEBUG
@@ -1761,11 +1775,11 @@ load_xwd_f2_d24_b32 (const gchar *filename,
g_set_error (error, G_FILE_ERROR, G_FILE_ERROR_FAILED,
_("XWD-file %s is corrupt."),
gimp_filename_to_utf8 (filename));
- return -1;
+ return NULL;
}
- image_ID = create_new_image (filename, width, height, GIMP_RGB,
- GIMP_RGB_IMAGE, &layer_ID, &buffer);
+ image = create_new_image (filename, width, height, GIMP_RGB,
+ GIMP_RGB_IMAGE, &layer, &buffer);
tile_height = gimp_tile_height ();
data = g_malloc (tile_height * width * 3);
@@ -1907,12 +1921,12 @@ load_xwd_f2_d24_b32 (const gchar *filename,
g_object_unref (buffer);
- return err ? -1 : image_ID;
+ return err ? NULL : image;
}
/* Load XWD with pixmap_format 2, pixmap_depth up to 32, bits_per_pixel 32 */
-static gint32
+static GimpImage *
load_xwd_f2_d32_b32 (const gchar *filename,
FILE *ifp,
L_XWDFILEHEADER *xwdhdr,
@@ -1930,7 +1944,8 @@ load_xwd_f2_d32_b32 (const gchar *filename,
guchar *data;
PIXEL_MAP pixel_map;
gint err = 0;
- gint32 layer_ID, image_ID;
+ GimpImage *image;
+ GimpLayer *layer;
GeglBuffer *buffer;
#ifdef XWD_DEBUG
@@ -1940,8 +1955,8 @@ load_xwd_f2_d32_b32 (const gchar *filename,
width = xwdhdr->l_pixmap_width;
height = xwdhdr->l_pixmap_height;
- image_ID = create_new_image (filename, width, height, GIMP_RGB,
- GIMP_RGBA_IMAGE, &layer_ID, &buffer);
+ image = create_new_image (filename, width, height, GIMP_RGB,
+ GIMP_RGBA_IMAGE, &layer, &buffer);
tile_height = gimp_tile_height ();
data = g_malloc (tile_height * width * 4);
@@ -2065,12 +2080,12 @@ load_xwd_f2_d32_b32 (const gchar *filename,
g_object_unref (buffer);
- return err ? -1 : image_ID;
+ return err ? NULL : image;
}
/* Load XWD with pixmap_format 1, pixmap_depth up to 24, bits_per_pixel 1 */
-static gint32
+static GimpImage *
load_xwd_f1_d24_b1 (const gchar *filename,
FILE *ifp,
L_XWDFILEHEADER *xwdhdr,
@@ -2093,7 +2108,8 @@ load_xwd_f1_d24_b1 (const gchar *filename,
L_CARD32 pixelval;
PIXEL_MAP pixel_map;
gint err = 0;
- gint32 layer_ID, image_ID;
+ GimpImage *image;
+ GimpLayer *layer;
GeglBuffer *buffer;
#ifdef XWD_DEBUG
@@ -2102,7 +2118,7 @@ load_xwd_f1_d24_b1 (const gchar *filename,
xwddata = g_malloc (xwdhdr->l_bytes_per_line);
if (xwddata == NULL)
- return -1;
+ return NULL;
width = xwdhdr->l_pixmap_width;
height = xwdhdr->l_pixmap_height;
@@ -2159,7 +2175,7 @@ load_xwd_f1_d24_b1 (const gchar *filename,
g_set_error (error, G_FILE_ERROR, G_FILE_ERROR_FAILED,
_("XWD-file %s is corrupt."),
gimp_filename_to_utf8 (filename));
- return -1;
+ return NULL;
}
/* Set map-arrays for red, green, blue */
@@ -2171,10 +2187,10 @@ load_xwd_f1_d24_b1 (const gchar *filename,
bluemap[blue] = (blue * 255) / maxblue;
}
- image_ID = create_new_image (filename, width, height,
- indexed ? GIMP_INDEXED : GIMP_RGB,
- indexed ? GIMP_INDEXED_IMAGE : GIMP_RGB_IMAGE,
- &layer_ID, &buffer);
+ image = create_new_image (filename, width, height,
+ indexed ? GIMP_INDEXED : GIMP_RGB,
+ indexed ? GIMP_INDEXED_IMAGE : GIMP_RGB_IMAGE,
+ &layer, &buffer);
tile_height = gimp_tile_height ();
data = g_malloc (tile_height * width * bytes_per_pixel);
@@ -2186,9 +2202,9 @@ load_xwd_f1_d24_b1 (const gchar *filename,
if (indexed)
{
if (ncols < 2)
- set_bw_color_table (image_ID);
+ set_bw_color_table (image);
else
- set_color_table (image_ID, xwdhdr, xwdcolmap);
+ set_color_table (image, xwdhdr, xwdcolmap);
}
else
{
@@ -2328,14 +2344,14 @@ load_xwd_f1_d24_b1 (const gchar *filename,
g_object_unref (buffer);
- return err ? -1 : image_ID;
+ return err ? NULL : image;
}
static gboolean
save_index (GOutputStream *output,
- gint32 image_ID,
- gint32 drawable_ID,
+ GimpImage *image,
+ GimpDrawable *drawable,
gboolean gray,
GError **error)
{
@@ -2356,7 +2372,7 @@ save_index (GOutputStream *output,
g_printf ("save_index ()\n");
#endif
- 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);
tile_height = gimp_tile_height ();
@@ -2394,7 +2410,7 @@ save_index (GOutputStream *output,
else
{
vclass = 3;
- cmap = gimp_image_get_colormap (image_ID, &ncolors);
+ cmap = gimp_image_get_colormap (image, &ncolors);
for (j = 0; j < ncolors; j++)
{
@@ -2480,8 +2496,8 @@ save_index (GOutputStream *output,
static gboolean
save_rgb (GOutputStream *output,
- gint32 image_ID,
- gint32 drawable_ID,
+ GimpImage *image,
+ GimpDrawable *drawable,
GError **error)
{
gint height, width;
@@ -2499,7 +2515,7 @@ save_rgb (GOutputStream *output,
g_printf ("save_rgb ()\n");
#endif
- 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);
tile_height = gimp_tile_height ();
diff --git a/plug-ins/common/plugin-defs.pl b/plug-ins/common/plugin-defs.pl
index ba9b505028..8ebc596881 100644
--- a/plug-ins/common/plugin-defs.pl
+++ b/plug-ins/common/plugin-defs.pl
@@ -50,7 +50,7 @@
'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 },
+ 'file-xwd' => { ui => 1, gegl => 1 },
'film' => { ui => 1, gegl => 1 },
'gradient-map' => { gegl => 1, old_api => 1 },
'grid' => { ui => 1, gegl => 1 },
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]