[gimp] plug-ins: port compose
- From: Michael Natterer <mitch src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gimp] plug-ins: port compose
- Date: Thu, 29 Aug 2019 17:23:09 +0000 (UTC)
commit c765fb2b6a8cb81cbcb5854e448300345c3df002
Author: Michael Natterer <mitch gimp org>
Date: Thu Aug 29 19:22:50 2019 +0200
plug-ins: port compose
plug-ins/common/Makefile.am | 2 -
plug-ins/common/compose.c | 889 ++++++++++++++++++++++-------------------
plug-ins/common/plugin-defs.pl | 2 +-
3 files changed, 485 insertions(+), 408 deletions(-)
---
diff --git a/plug-ins/common/Makefile.am b/plug-ins/common/Makefile.am
index 1f1766ee11..c9a4f9440b 100644
--- a/plug-ins/common/Makefile.am
+++ b/plug-ins/common/Makefile.am
@@ -388,8 +388,6 @@ colormap_remap_LDADD = \
$(INTLLIBS) \
$(colormap_remap_RC)
-compose_CPPFLAGS = $(AM_CPPFLAGS) -DGIMP_DEPRECATED_REPLACE_NEW_API
-
compose_SOURCES = \
compose.c
diff --git a/plug-ins/common/compose.c b/plug-ins/common/compose.c
index 902375b673..ea245e7fa6 100644
--- a/plug-ins/common/compose.c
+++ b/plug-ins/common/compose.c
@@ -55,12 +55,13 @@
typedef struct
{
+ gboolean is_object;
+
union
- {
- gint32 ID; /* Image ID of input images or drawable */
- guchar val; /* Mask value to compose with */
- } comp;
- gboolean is_ID;
+ {
+ gpointer object; /* Input images or drawable */
+ guchar val; /* Mask value to compose with */
+ } comp;
} ComposeInput;
/* Description of a component */
@@ -86,64 +87,113 @@ typedef struct
} COMPOSE_DSC;
+typedef struct
+{
+ ComposeInput inputs[MAX_COMPOSE_IMAGES]; /* Image or mask value of input */
+ gchar compose_type[32]; /* type of composition */
+ gboolean do_recompose;
+ GimpLayer *source_layer; /* for recomposing */
+} ComposeVals;
-/* Declare local functions
- */
-static void query (void);
-static void run (const gchar *name,
- gint nparams,
- const GimpParam *param,
- gint *nreturn_vals,
- GimpParam **return_vals);
+/* Dialog structure */
+typedef struct
+{
+ gint width, height; /* Size of selected image */
+
+ GtkWidget *channel_label[MAX_COMPOSE_IMAGES]; /* The labels to change */
+ GtkWidget *channel_icon[MAX_COMPOSE_IMAGES]; /* The icons */
+ GtkWidget *channel_menu[MAX_COMPOSE_IMAGES]; /* The menus */
+ GtkWidget *color_scales[MAX_COMPOSE_IMAGES]; /* The values color scales */
+ GtkWidget *color_spins[MAX_COMPOSE_IMAGES]; /* The values spin buttons */
+
+ ComposeInput selected[MAX_COMPOSE_IMAGES]; /* Image Ids or mask values from menus */
+
+ gint compose_idx; /* Compose type */
+} ComposeInterface;
+
+
+typedef struct _Compose Compose;
+typedef struct _ComposeClass ComposeClass;
+
+struct _Compose
+{
+ GimpPlugIn parent_instance;
+};
+
+struct _ComposeClass
+{
+ GimpPlugInClass parent_class;
+};
+
+
+#define COMPOSE_TYPE (compose_get_type ())
+#define COMPOSE (obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), COMPOSE_TYPE, Compose))
+
+GType compose_get_type (void) G_GNUC_CONST;
+
+static GList * compose_query_procedures (GimpPlugIn *plug_in);
+static GimpProcedure * compose_create_procedure (GimpPlugIn *plug_in,
+ const gchar *name);
+
+static GimpValueArray * compose_run (GimpProcedure *procedure,
+ GimpRunMode run_mode,
+ GimpImage *image,
+ GimpDrawable *drawable,
+ const GimpValueArray *args,
+ gpointer run_data);
+
+static void cpn_affine_transform (GeglBuffer *buffer,
+ gdouble min,
+ gdouble max);
+
+static void fill_buffer_from_components (GeglBuffer *temp[MAX_COMPOSE_IMAGES],
+ GeglBuffer *dst,
+ gint num_cpn,
+ ComposeInput *inputs,
+ gdouble mask_vals[MAX_COMPOSE_IMAGES]);
-static void cpn_affine_transform (GeglBuffer *buffer,
- gdouble min,
- gdouble max);
+static void perform_composition (COMPOSE_DSC curr_compose_dsc,
+ GeglBuffer *buffer_src[MAX_COMPOSE_IMAGES],
+ GeglBuffer *buffer_dst,
+ ComposeInput *inputs,
+ gint num_images);
-static void fill_buffer_from_components (GeglBuffer *temp[MAX_COMPOSE_IMAGES],
- GeglBuffer *dst,
- gint num_cpn,
- ComposeInput *inputs,
- gdouble mask_vals[MAX_COMPOSE_IMAGES]);
+static GimpImage * compose (const gchar *compose_type,
+ ComposeInput *inputs,
+ gboolean compose_by_drawable);
-static void perform_composition (COMPOSE_DSC curr_compose_dsc,
- GeglBuffer *buffer_src[MAX_COMPOSE_IMAGES],
- GeglBuffer *buffer_dst,
- ComposeInput *inputs,
- gint num_images);
+static GimpImage * create_new_image (const gchar *filename,
+ guint width,
+ guint height,
+ GimpImageType gdtype,
+ GimpPrecision precision,
+ GimpLayer **layer,
+ GeglBuffer **buffer);
-static gint32 compose (const gchar *compose_type,
- ComposeInput *inputs,
- gboolean compose_by_drawable);
+static gboolean compose_dialog (const gchar *compose_type,
+ GimpDrawable *drawable);
-static gint32 create_new_image (const gchar *filename,
- guint width,
- guint height,
- GimpImageType gdtype,
- GimpPrecision precision,
- gint32 *layer_ID,
- GeglBuffer **drawable);
+static gboolean check_gray (GimpImage *image,
+ GimpItem *drawable,
+ gpointer data);
-static gboolean compose_dialog (const gchar *compose_type,
- gint32 drawable_ID);
+static void combo_callback (GimpIntComboBox *cbox,
+ gpointer data);
-static gboolean check_gray (gint32 image_id,
- gint32 drawable_id,
- gpointer data);
+static void scale_callback (GtkAdjustment *adj,
+ ComposeInput *input);
-static void combo_callback (GimpIntComboBox *cbox,
- gpointer data);
+static void check_response (GtkWidget *dialog,
+ gint response,
+ gpointer data);
-static void scale_callback (GtkAdjustment *adj,
- ComposeInput *input);
+static void type_combo_callback (GimpIntComboBox *combo,
+ gpointer data);
-static void check_response (GtkWidget *dialog,
- gint response,
- gpointer data);
-static void type_combo_callback (GimpIntComboBox *combo,
- gpointer data);
+G_DEFINE_TYPE (Compose, compose, GIMP_TYPE_PLUG_IN)
+GIMP_MAIN (COMPOSE_TYPE)
/* Decompositions availables.
@@ -278,45 +328,12 @@ static COMPOSE_DSC compose_dsc[] =
"ycbcr709F-compose" }
};
-
-typedef struct
-{
- ComposeInput inputs[MAX_COMPOSE_IMAGES]; /* Image IDs or mask value of input */
- gchar compose_type[32]; /* type of composition */
- gboolean do_recompose;
- gint32 source_layer_ID; /* for recomposing */
-} ComposeVals;
-
-/* Dialog structure */
-typedef struct
-{
- gint width, height; /* Size of selected image */
-
- GtkWidget *channel_label[MAX_COMPOSE_IMAGES]; /* The labels to change */
- GtkWidget *channel_icon[MAX_COMPOSE_IMAGES]; /* The icons */
- GtkWidget *channel_menu[MAX_COMPOSE_IMAGES]; /* The menus */
- GtkWidget *color_scales[MAX_COMPOSE_IMAGES]; /* The values color scales */
- GtkWidget *color_spins[MAX_COMPOSE_IMAGES]; /* The values spin buttons */
-
- ComposeInput selected[MAX_COMPOSE_IMAGES]; /* Image Ids or mask values from menus */
-
- gint compose_idx; /* Compose type */
-} ComposeInterface;
-
-const GimpPlugInInfo PLUG_IN_INFO =
-{
- NULL, /* init_proc */
- NULL, /* quit_proc */
- query, /* query_proc */
- run, /* run_proc */
-};
-
static ComposeVals composevals =
{
- {{{ 0 }}}, /* Image IDs of images to compose or mask values */
- "rgb", /* Type of composition */
- FALSE, /* Do recompose */
- -1 /* source layer ID */
+ {{ 0, }}, /* Image IDs of images to compose or mask values */
+ "rgb", /* Type of composition */
+ FALSE, /* Do recompose */
+ NULL /* source layer */
};
static ComposeInterface composeint =
@@ -327,58 +344,44 @@ static ComposeInterface composeint =
{ NULL }, /* Menu Widgets */
{ NULL }, /* Color Scale Widgets */
{ NULL }, /* Color Spin Widgets */
- {{{ 0 }}}, /* Image Ids or mask values from menus */
+ {{ 0, }}, /* Image Ids or mask values from menus */
0 /* Compose type */
};
-MAIN ()
+static void
+compose_class_init (ComposeClass *klass)
+{
+ GimpPlugInClass *plug_in_class = GIMP_PLUG_IN_CLASS (klass);
+ plug_in_class->query_procedures = compose_query_procedures;
+ plug_in_class->create_procedure = compose_create_procedure;
+}
static void
-query (void)
+compose_init (Compose *compose)
{
- static GimpParamDef args[] =
- {
- { GIMP_PDB_INT32, "run-mode", "The run mode { RUN-INTERACTIVE (0), RUN-NONINTERACTIVE (1) }" },
- { GIMP_PDB_IMAGE, "image1", "First input image" },
- { GIMP_PDB_DRAWABLE, "drawable", "Input drawable (not used)" },
- { GIMP_PDB_IMAGE, "image2", "Second input image" },
- { GIMP_PDB_IMAGE, "image3", "Third input image" },
- { GIMP_PDB_IMAGE, "image4", "Fourth input image" },
- { GIMP_PDB_STRING, "compose-type", NULL }
- };
-
- static const GimpParamDef return_vals[] =
- {
- { GIMP_PDB_IMAGE, "new_image", "Output image" }
- };
+}
- static GimpParamDef drw_args[] =
- {
- { GIMP_PDB_INT32, "run-mode", "The run mode { RUN-INTERACTIVE (0), RUN-NONINTERACTIVE (1) }" },
- { GIMP_PDB_IMAGE, "image1", "First input image (not used)" },
- { GIMP_PDB_DRAWABLE, "drawable1", "First input drawable" },
- { GIMP_PDB_DRAWABLE, "drawable2", "Second input drawable" },
- { GIMP_PDB_DRAWABLE, "drawable3", "Third input drawable" },
- { GIMP_PDB_DRAWABLE, "drawable4", "Fourth input drawable" },
- { GIMP_PDB_STRING, "compose-type", NULL }
- };
-
- static const GimpParamDef drw_return_vals[] =
- {
- { GIMP_PDB_IMAGE, "new_image", "Output image" }
- };
+static GList *
+compose_query_procedures (GimpPlugIn *plug_in)
+{
+ GList *list = NULL;
- static const GimpParamDef recompose_args[] =
- {
- { GIMP_PDB_INT32, "run-mode", "The run mode { RUN-INTERACTIVE (0), RUN-NONINTERACTIVE (1) }" },
- { GIMP_PDB_IMAGE, "image", "Image to recompose from" },
- { GIMP_PDB_DRAWABLE, "drawable", "Not used" },
- };
+ list = g_list_append (list, g_strdup (COMPOSE_PROC));
+ list = g_list_append (list, g_strdup (DRAWABLE_COMPOSE_PROC));
+ list = g_list_append (list, g_strdup (RECOMPOSE_PROC));
- GString *type_desc;
- gint i;
+ return list;
+}
+
+static GimpProcedure *
+compose_create_procedure (GimpPlugIn *plug_in,
+ const gchar *name)
+{
+ GimpProcedure *procedure = NULL;
+ GString *type_desc;
+ gint i;
type_desc = g_string_new ("What to compose: ");
g_string_append_c (type_desc, '"');
@@ -393,128 +396,229 @@ query (void)
g_string_append_c (type_desc, '"');
}
- args[6].description = type_desc->str;
- drw_args[6].description = type_desc->str;
-
- gimp_install_procedure (COMPOSE_PROC,
- N_("Create an image using multiple gray images as color channels"),
- "This function creates a new image from "
- "multiple gray images",
- "Peter Kirchgessner",
- "Peter Kirchgessner (peter kirchgessner net)",
- "1997",
- N_("C_ompose..."),
- "GRAY*",
- GIMP_PLUGIN,
- G_N_ELEMENTS (args),
- G_N_ELEMENTS (return_vals),
- args, return_vals);
-
- gimp_plugin_menu_register (COMPOSE_PROC, "<Image>/Colors/Components");
-
- gimp_install_procedure (DRAWABLE_COMPOSE_PROC,
- "Compose an image from multiple drawables of gray images",
- "This function creates a new image from "
- "multiple drawables of gray images",
- "Peter Kirchgessner",
- "Peter Kirchgessner (peter kirchgessner net)",
- "1998",
- NULL, /* It is not available in interactive mode */
- "GRAY*",
- GIMP_PLUGIN,
- G_N_ELEMENTS (drw_args),
- G_N_ELEMENTS (drw_return_vals),
- drw_args, drw_return_vals);
-
- gimp_install_procedure (RECOMPOSE_PROC,
- N_("Recompose an image that was previously decomposed"),
- "This function recombines the grayscale layers produced "
- "by Decompose into a single RGB or RGBA layer, and "
- "replaces the originally decomposed layer with the "
- "result.",
- "Bill Skaggs",
- "Bill Skaggs",
- "2004",
- N_("R_ecompose"),
- "GRAY*",
- GIMP_PLUGIN,
- G_N_ELEMENTS (recompose_args), 0,
- recompose_args, NULL);
-
- gimp_plugin_menu_register (RECOMPOSE_PROC, "<Image>/Colors/Components");
+ if (! strcmp (name, COMPOSE_PROC))
+ {
+ procedure = gimp_image_procedure_new (plug_in, name, GIMP_PLUGIN,
+ compose_run, NULL, NULL);
+
+ gimp_procedure_set_image_types (procedure, "GRAY*");
+
+ gimp_procedure_set_menu_label (procedure, N_("C_ompose..."));
+ gimp_procedure_add_menu_path (procedure, "<Image>/Colors/Components");
+
+ gimp_procedure_set_documentation (procedure,
+ N_("Create an image using multiple "
+ "gray images as color channels"),
+ "This function creates a new image from "
+ "multiple gray images",
+ name);
+ gimp_procedure_set_attribution (procedure,
+ "Peter Kirchgessner",
+ "Peter Kirchgessner (peter kirchgessner net)",
+ "1997");
+
+ GIMP_PROC_ARG_IMAGE (procedure, "image-2",
+ "Image 2",
+ "Second input image",
+ TRUE,
+ G_PARAM_READWRITE);
+
+ GIMP_PROC_ARG_IMAGE (procedure, "image-3",
+ "Image 3",
+ "Third input image",
+ TRUE,
+ G_PARAM_READWRITE);
+
+ GIMP_PROC_ARG_IMAGE (procedure, "image-4",
+ "Image 4",
+ "Fourth input image",
+ TRUE,
+ G_PARAM_READWRITE);
+
+ GIMP_PROC_ARG_STRING (procedure, "compose-type",
+ "Compose type",
+ type_desc->str,
+ NULL,
+ G_PARAM_READWRITE);
+
+ GIMP_PROC_VAL_IMAGE (procedure, "new-image",
+ "New image",
+ "Output image",
+ FALSE,
+ G_PARAM_READWRITE);
+ }
+ else if (! strcmp (name, DRAWABLE_COMPOSE_PROC))
+ {
+ procedure = gimp_image_procedure_new (plug_in, name, GIMP_PLUGIN,
+ compose_run, NULL, NULL);
+
+ gimp_procedure_set_image_types (procedure, "GRAY*");
+
+ gimp_procedure_set_documentation (procedure,
+ "Compose an image from multiple "
+ "drawables of gray images",
+ "This function creates a new image from "
+ "multiple drawables of gray images",
+ name);
+ gimp_procedure_set_attribution (procedure,
+ "Peter Kirchgessner",
+ "Peter Kirchgessner (peter kirchgessner net)",
+ "1998");
+
+ GIMP_PROC_ARG_DRAWABLE (procedure, "drawable-2",
+ "Drawable 2",
+ "Second input drawable",
+ TRUE,
+ G_PARAM_READWRITE);
+
+ GIMP_PROC_ARG_DRAWABLE (procedure, "drawable-3",
+ "Drawable 3",
+ "Third input drawable",
+ TRUE,
+ G_PARAM_READWRITE);
+
+ GIMP_PROC_ARG_DRAWABLE (procedure, "drawable-4",
+ "Drawable 4",
+ "Fourth input drawable",
+ TRUE,
+ G_PARAM_READWRITE);
+
+ GIMP_PROC_ARG_STRING (procedure, "compose-type",
+ "Compose type",
+ type_desc->str,
+ NULL,
+ G_PARAM_READWRITE);
+
+ GIMP_PROC_VAL_IMAGE (procedure, "new-image",
+ "New image",
+ "Output image",
+ FALSE,
+ G_PARAM_READWRITE);
+ }
+ else if (! strcmp (name, RECOMPOSE_PROC))
+ {
+ procedure = gimp_image_procedure_new (plug_in, name, GIMP_PLUGIN,
+ compose_run, NULL, NULL);
+
+ gimp_procedure_set_image_types (procedure, "GRAY*");
+
+ gimp_procedure_set_menu_label (procedure, N_("R_ecompose"));
+ gimp_procedure_add_menu_path (procedure, "<Image>/Colors/Components");
+
+ gimp_procedure_set_documentation (procedure,
+ N_("Recompose an image that was "
+ "previously decomposed"),
+ "This function recombines the grayscale "
+ "layers produced by Decompose "
+ "into a single RGB or RGBA layer, and "
+ "replaces the originally decomposed "
+ "layer with the result.",
+ name);
+ gimp_procedure_set_attribution (procedure,
+ "Bill Skaggs",
+ "Bill Skaggs",
+ "2004");
+ }
g_string_free (type_desc, TRUE);
-}
+ return procedure;
+}
-static void
-run (const gchar *name,
- gint nparams,
- const GimpParam *param,
- gint *nreturn_vals,
- GimpParam **return_vals)
+static GimpValueArray *
+compose_run (GimpProcedure *procedure,
+ GimpRunMode run_mode,
+ GimpImage *image,
+ GimpDrawable *drawable,
+ const GimpValueArray *args,
+ gpointer run_data)
{
- static GimpParam values[2];
- GimpPDBStatusType status = GIMP_PDB_SUCCESS;
- GimpRunMode run_mode;
- gint32 image_ID;
- gint32 drawable_ID = -1;
- gint compose_by_drawable;
- gint i;
+ GimpValueArray *return_vals;
+ const gchar *name = gimp_procedure_get_name (procedure);
+ gint compose_by_drawable;
+ gint i;
INIT_I18N ();
gegl_init (NULL, NULL);
- run_mode = param[0].data.d_int32;
- compose_by_drawable = (strcmp (name, DRAWABLE_COMPOSE_PROC) == 0);
+ compose_by_drawable = ! strcmp (name, DRAWABLE_COMPOSE_PROC);
- *nreturn_vals = 1;
- *return_vals = values;
-
- values[0].type = GIMP_PDB_STATUS;
- values[0].data.d_status = status;
- values[1].type = GIMP_PDB_IMAGE;
- values[1].data.d_int32 = -1;
-
- if (strcmp (name, RECOMPOSE_PROC) == 0)
+ if (! strcmp (name, RECOMPOSE_PROC))
{
- GimpParasite *parasite = gimp_image_get_parasite (param[1].data.d_image,
+ GimpParasite *parasite = gimp_image_get_parasite (image,
"decompose-data");
if (! parasite)
{
g_message (_("You can only run 'Recompose' if the active image "
"was originally produced by 'Decompose'."));
- status = GIMP_PDB_EXECUTION_ERROR;
+
+ return gimp_procedure_new_return_values (procedure,
+ GIMP_PDB_EXECUTION_ERROR,
+ NULL);
}
else
{
+ gint source;
+ gint input[4] = { 0, };
gint nret;
nret = sscanf (gimp_parasite_data (parasite),
"source=%d type=%31s %d %d %d %d",
- &composevals.source_layer_ID,
+ &source,
composevals.compose_type,
- &composevals.inputs[0].comp.ID,
- &composevals.inputs[1].comp.ID,
- &composevals.inputs[2].comp.ID,
- &composevals.inputs[3].comp.ID);
+ input,
+ input + 1,
+ input + 2,
+ input + 3);
gimp_parasite_free (parasite);
- for (i = 0; i < MAX_COMPOSE_IMAGES; i++)
- composevals.inputs[i].is_ID = TRUE;
-
if (nret < 5)
{
g_message (_("Error scanning 'decompose-data' parasite: "
"too few layers found"));
- status = GIMP_PDB_EXECUTION_ERROR;
+
+ return gimp_procedure_new_return_values (procedure,
+ GIMP_PDB_EXECUTION_ERROR,
+ NULL);
}
- else
+
+ compose_by_drawable = TRUE;
+
+ composevals.do_recompose = TRUE;
+ composevals.source_layer = GIMP_LAYER (gimp_item_get_by_id (source));
+
+ if (! composevals.source_layer)
{
- composevals.do_recompose = TRUE;
- compose_by_drawable = TRUE;
+ g_message (_("Cannot recompose: Specified source layer ID %d "
+ "not found"),
+ source);
+
+ return gimp_procedure_new_return_values (procedure,
+ GIMP_PDB_EXECUTION_ERROR,
+ NULL);
+ }
+
+ for (i = 0; i < MAX_COMPOSE_IMAGES; i++)
+ {
+ composevals.inputs[i].is_object = TRUE;
+ composevals.inputs[i].comp.object = gimp_item_get_by_id (input[i]);
+
+ /* fourth input is optional */
+ if (i == 2 && nret == 5)
+ break;
+
+ if (! composevals.inputs[i].comp.object)
+ {
+ g_message (_("Cannot recompose: Specified layer #%d ID %d "
+ "not found"),
+ i + 1, input[i]);
+
+ return gimp_procedure_new_return_values (procedure,
+ GIMP_PDB_EXECUTION_ERROR,
+ NULL);
+ }
}
}
}
@@ -525,75 +629,74 @@ run (const gchar *name,
switch (run_mode)
{
case GIMP_RUN_INTERACTIVE:
- /* Possibly retrieve data */
gimp_get_data (name, &composevals);
compose_by_drawable = TRUE;
- /* The dialog is now drawable based. Get a drawable-ID of the image */
- if (strcmp (name, COMPOSE_PROC) == 0)
+ /* Get a drawable-ID of the image */
+ if (! strcmp (name, COMPOSE_PROC))
{
- gint32 *layer_list;
- gint nlayers;
+ GimpLayer **layers;
+ gint nlayers;
- layer_list = gimp_image_get_layers (param[1].data.d_int32,
- &nlayers);
- if ((layer_list == NULL) || (nlayers <= 0))
+ layers = gimp_image_get_layers (image, &nlayers);
+
+ if (! layers)
{
g_message (_("Could not get layers for image %d"),
- (gint) param[1].data.d_int32);
- return;
+ (gint) gimp_image_get_id (image));
+
+ return gimp_procedure_new_return_values (procedure,
+ GIMP_PDB_EXECUTION_ERROR,
+ NULL);
}
- drawable_ID = layer_list[0];
- g_free (layer_list);
- }
- else
- {
- drawable_ID = param[2].data.d_int32;
- }
+ drawable = GIMP_DRAWABLE (layers[0]);
- /* First acquire information with a dialog */
- if (! compose_dialog (composevals.compose_type, drawable_ID))
- return;
+ g_free (layers);
+ }
+ if (! compose_dialog (composevals.compose_type, drawable))
+ return gimp_procedure_new_return_values (procedure,
+ GIMP_PDB_CANCEL,
+ NULL);
break;
case GIMP_RUN_NONINTERACTIVE:
- /* Make sure all the arguments are there! */
- if (nparams < 7)
+ if (compose_by_drawable)
{
- status = GIMP_PDB_CALLING_ERROR;
+ composevals.inputs[0].comp.object = drawable;
+ composevals.inputs[1].comp.object = GIMP_VALUES_GET_DRAWABLE (args, 0);
+ composevals.inputs[2].comp.object = GIMP_VALUES_GET_DRAWABLE (args, 1);
+ composevals.inputs[3].comp.object = GIMP_VALUES_GET_DRAWABLE (args, 2);
}
else
{
- composevals.inputs[0].comp.ID = (compose_by_drawable ?
- param[2].data.d_int32 :
- param[1].data.d_int32);
- composevals.inputs[1].comp.ID = param[3].data.d_int32;
- composevals.inputs[2].comp.ID = param[4].data.d_int32;
- composevals.inputs[3].comp.ID = param[5].data.d_int32;
+ composevals.inputs[0].comp.object = image;
+ composevals.inputs[1].comp.object = GIMP_VALUES_GET_IMAGE (args, 0);
+ composevals.inputs[2].comp.object = GIMP_VALUES_GET_IMAGE (args, 1);
+ composevals.inputs[3].comp.object = GIMP_VALUES_GET_IMAGE (args, 2);
+ }
- g_strlcpy (composevals.compose_type, param[6].data.d_string,
- sizeof (composevals.compose_type));
+ g_strlcpy (composevals.compose_type,
+ GIMP_VALUES_GET_STRING (args, 3),
+ sizeof (composevals.compose_type));
- for (i = 0; i < MAX_COMPOSE_IMAGES; i++)
+ for (i = 0; i < MAX_COMPOSE_IMAGES; i++)
+ {
+ if (! composevals.inputs[i].comp.object)
{
- if (composevals.inputs[i].comp.ID == -1)
- {
- composevals.inputs[i].is_ID = FALSE;
- composevals.inputs[i].comp.val = 0;
- }
- else
- {
- composevals.inputs[i].is_ID = TRUE;
- }
+ composevals.inputs[i].is_object = FALSE;
+ composevals.inputs[i].comp.val = 0;
+ }
+ else
+ {
+ composevals.inputs[i].is_object = TRUE;
}
}
break;
case GIMP_RUN_WITH_LAST_VALS:
- /* Possibly retrieve data */
gimp_get_data (name, &composevals);
compose_by_drawable = TRUE;
@@ -604,44 +707,41 @@ run (const gchar *name,
}
}
- if (status == GIMP_PDB_SUCCESS)
- {
- gimp_progress_init (_("Composing"));
+ gimp_progress_init (_("Composing"));
- image_ID = compose (composevals.compose_type,
- composevals.inputs,
- compose_by_drawable);
+ image = compose (composevals.compose_type,
+ composevals.inputs,
+ compose_by_drawable);
- if (image_ID < 0)
- {
- status = GIMP_PDB_EXECUTION_ERROR;
- }
- else
- {
- values[1].data.d_int32 = image_ID;
+ if (! image)
+ return gimp_procedure_new_return_values (procedure,
+ GIMP_PDB_EXECUTION_ERROR,
+ NULL);
- if (composevals.do_recompose)
- {
- gimp_displays_flush ();
- }
- else
- {
- gimp_image_undo_enable (image_ID);
- gimp_image_clean_all (image_ID);
-
- if (run_mode != GIMP_RUN_NONINTERACTIVE)
- gimp_display_new (image_ID);
- }
- }
+ if (composevals.do_recompose)
+ {
+ gimp_displays_flush ();
+ }
+ else
+ {
+ gimp_image_undo_enable (image);
+ gimp_image_clean_all (image);
- /* Store data */
- if (run_mode == GIMP_RUN_INTERACTIVE)
- gimp_set_data (name, &composevals, sizeof (ComposeVals));
+ if (run_mode != GIMP_RUN_NONINTERACTIVE)
+ gimp_display_new (image);
}
- *nreturn_vals = composevals.do_recompose ? 1 : 2;
+ if (run_mode == GIMP_RUN_INTERACTIVE)
+ gimp_set_data (name, &composevals, sizeof (ComposeVals));
+
+ return_vals = gimp_procedure_new_return_values (procedure,
+ GIMP_PDB_SUCCESS,
+ NULL);
+
+ if (strcmp (name, RECOMPOSE_PROC))
+ GIMP_VALUES_SET_IMAGE (return_vals, 1, image);
- values[0].data.d_status = status;
+ return return_vals;
}
static void
@@ -686,7 +786,7 @@ fill_buffer_from_components (GeglBuffer *temp[MAX_COMPOSE_IMAGES],
for (j = 0; j < num_cpn; j++)
{
- if (inputs[j].is_ID)
+ if (inputs[j].is_object)
gegl_buffer_iterator_add (gi, temp[j], NULL, 0, NULL,
GEGL_ACCESS_READ, GEGL_ABYSS_NONE);
}
@@ -699,7 +799,7 @@ fill_buffer_from_components (GeglBuffer *temp[MAX_COMPOSE_IMAGES],
count = 1;
for (j = 0; j < num_cpn; j++)
- if (inputs[j].is_ID)
+ if (inputs[j].is_object)
src_data[j] = (gdouble*) gi->items[count++].data;
for (k = 0; k < gi->length; k++)
@@ -708,7 +808,7 @@ fill_buffer_from_components (GeglBuffer *temp[MAX_COMPOSE_IMAGES],
for (j = 0; j < num_cpn; j++)
{
- if (inputs[j].is_ID)
+ if (inputs[j].is_object)
dst_data[pos+j] = src_data[j][k];
else
dst_data[pos+j] = mask_vals[j];
@@ -746,7 +846,7 @@ perform_composition (COMPOSE_DSC curr_compose_dsc,
else
gray_format = babl_format ("Y double");
- if (! inputs[i].is_ID)
+ if (! inputs[i].is_object)
{
const Babl *fish = babl_fish (babl_format ("Y' u8"), gray_format);
@@ -789,14 +889,14 @@ perform_composition (COMPOSE_DSC curr_compose_dsc,
gegl_buffer_copy (dst_temp, NULL, GEGL_ABYSS_NONE, buffer_dst, NULL);
for (i = 0; i< num_images; i++)
- if (inputs[i].is_ID)
+ if (inputs[i].is_object)
g_object_unref (temp[i]);
g_object_unref (dst_temp);
}
/* Compose an image from several gray-images */
-static gint32
+static GimpImage *
compose (const gchar *compose_type,
ComposeInput *inputs,
gboolean compose_by_drawable)
@@ -805,8 +905,9 @@ compose (const gchar *compose_type,
gint num_images, compose_idx;
gint i, j;
gint num_layers;
- gint32 layer_ID_dst, image_ID_dst;
- gint first_ID;
+ GimpLayer *layer_dst;
+ GimpImage *image_dst;
+ gint first_object;
GimpImageType gdtype_dst;
GeglBuffer *buffer_src[MAX_COMPOSE_IMAGES];
GeglBuffer *buffer_dst;
@@ -824,88 +925,74 @@ compose (const gchar *compose_type,
}
if (compose_idx < 0)
- return -1;
+ return NULL;
num_images = compose_dsc[compose_idx].num_images;
/* Check that at least one image or one drawable is provided */
- first_ID = -1;
+ first_object = -1;
for (i = 0; i < num_images; i++)
{
- if (inputs[i].is_ID)
+ if (inputs[i].is_object)
{
- first_ID = i;
+ first_object = i;
break;
}
}
- if (-1 == first_ID)
+ if (first_object == -1)
{
g_message (_("At least one image is needed to compose"));
- return -1;
+ return NULL;
}
/* Check image sizes */
if (compose_by_drawable)
{
- gint32 first_image = gimp_item_get_image (inputs[first_ID].comp.ID);
+ GimpImage *first_image = gimp_item_get_image (inputs[first_object].comp.object);
- if (! gimp_item_is_valid (inputs[first_ID].comp.ID))
- {
- g_message (_("Specified layer %d not found"),
- inputs[first_ID].comp.ID);
- return -1;
- }
-
- width = gimp_drawable_width (inputs[first_ID].comp.ID);
- height = gimp_drawable_height (inputs[first_ID].comp.ID);
+ width = gimp_drawable_width (inputs[first_object].comp.object);
+ height = gimp_drawable_height (inputs[first_object].comp.object);
precision = gimp_image_get_precision (first_image);
- for (j = first_ID + 1; j < num_images; j++)
+ for (j = first_object + 1; j < num_images; j++)
{
- if (inputs[j].is_ID)
+ if (inputs[j].is_object)
{
- if (! gimp_item_is_valid (inputs[j].comp.ID))
- {
- g_message (_("Specified layer %d not found"),
- inputs[j].comp.ID);
- return -1;
- }
-
- if ((width != gimp_drawable_width (inputs[j].comp.ID)) ||
- (height != gimp_drawable_height (inputs[j].comp.ID)))
+ if ((width != gimp_drawable_width (inputs[j].comp.object)) ||
+ (height != gimp_drawable_height (inputs[j].comp.object)))
{
g_message (_("Drawables have different size"));
- return -1;
+ return NULL;
}
}
}
for (j = 0; j < num_images; j++)
{
- if (inputs[j].is_ID)
- buffer_src[j] = gimp_drawable_get_buffer (inputs[j].comp.ID);
+ if (inputs[j].is_object)
+ buffer_src[j] = gimp_drawable_get_buffer (inputs[j].comp.object);
else
buffer_src[j] = NULL;
}
}
- else /* Compose by image ID */
+ else /* Compose by image */
{
- width = gimp_image_width (inputs[first_ID].comp.ID);
- height = gimp_image_height (inputs[first_ID].comp.ID);
+ width = gimp_image_width (inputs[first_object].comp.object);
+ height = gimp_image_height (inputs[first_object].comp.object);
- precision = gimp_image_get_precision (inputs[first_ID].comp.ID);
+ precision = gimp_image_get_precision (inputs[first_object].comp.object);
- for (j = first_ID + 1; j < num_images; j++)
+ for (j = first_object + 1; j < num_images; j++)
{
- if (inputs[j].is_ID)
+ if (inputs[j].is_object)
{
- if ((width != gimp_image_width (inputs[j].comp.ID)) ||
- (height != gimp_image_height (inputs[j].comp.ID)))
+ if ((width != gimp_image_width (inputs[j].comp.object)) ||
+ (height != gimp_image_height (inputs[j].comp.object)))
{
g_message (_("Images have different size"));
- return -1;
+ return NULL;
}
}
}
@@ -913,21 +1000,21 @@ compose (const gchar *compose_type,
/* Get first layer/drawable for all input images */
for (j = 0; j < num_images; j++)
{
- if (inputs[j].is_ID)
+ if (inputs[j].is_object)
{
- gint32 *layers;
+ GimpLayer **layers;
/* Get first layer of image */
- layers = gimp_image_get_layers (inputs[j].comp.ID, &num_layers);
+ layers = gimp_image_get_layers (inputs[j].comp.object, &num_layers);
- if (! layers || (num_layers <= 0))
+ if (! layers)
{
g_message (_("Error in getting layer IDs"));
- return -1;
+ return NULL;
}
/* Get drawable for layer */
- buffer_src[j] = gimp_drawable_get_buffer (layers[0]);
+ buffer_src[j] = gimp_drawable_get_buffer (GIMP_DRAWABLE (layers[0]));
g_free (layers);
}
}
@@ -936,34 +1023,26 @@ compose (const gchar *compose_type,
/* Unless recomposing, create new image */
if (composevals.do_recompose)
{
- layer_ID_dst = composevals.source_layer_ID;
-
- if (! gimp_item_is_valid (layer_ID_dst))
- {
- g_message (_("Unable to recompose, source layer not found"));
- return -1;
- }
-
- image_ID_dst = gimp_item_get_image (layer_ID_dst);
-
- buffer_dst = gimp_drawable_get_shadow_buffer (layer_ID_dst);
+ layer_dst = composevals.source_layer;
+ image_dst = gimp_item_get_image (GIMP_ITEM (layer_dst));
+ buffer_dst = gimp_drawable_get_shadow_buffer (GIMP_DRAWABLE (layer_dst));
}
else
{
gdtype_dst = ((babl_model (compose_dsc[compose_idx].babl_model) == babl_model ("RGBA")) ?
GIMP_RGBA_IMAGE : GIMP_RGB_IMAGE);
- image_ID_dst = create_new_image (compose_dsc[compose_idx].filename,
- width, height, gdtype_dst, precision,
- &layer_ID_dst, &buffer_dst);
+ image_dst = create_new_image (compose_dsc[compose_idx].filename,
+ width, height, gdtype_dst, precision,
+ &layer_dst, &buffer_dst);
}
if (! compose_by_drawable)
{
gdouble xres, yres;
- gimp_image_get_resolution (inputs[first_ID].comp.ID, &xres, &yres);
- gimp_image_set_resolution (image_ID_dst, xres, yres);
+ gimp_image_get_resolution (inputs[first_object].comp.object, &xres, &yres);
+ gimp_image_set_resolution (image_dst, xres, yres);
}
perform_composition (compose_dsc[compose_idx],
@@ -976,35 +1055,35 @@ compose (const gchar *compose_type,
for (j = 0; j < num_images; j++)
{
- if (inputs[j].is_ID)
+ if (inputs[j].is_object)
g_object_unref (buffer_src[j]);
}
g_object_unref (buffer_dst);
if (composevals.do_recompose)
- gimp_drawable_merge_shadow (layer_ID_dst, TRUE);
+ gimp_drawable_merge_shadow (GIMP_DRAWABLE (layer_dst), TRUE);
- gimp_drawable_update (layer_ID_dst, 0, 0,
- gimp_drawable_width (layer_ID_dst),
- gimp_drawable_height (layer_ID_dst));
+ gimp_drawable_update (GIMP_DRAWABLE (layer_dst), 0, 0,
+ gimp_drawable_width (GIMP_DRAWABLE (layer_dst)),
+ gimp_drawable_height (GIMP_DRAWABLE (layer_dst)));
- return image_ID_dst;
+ return image_dst;
}
-/* Create an image. Sets layer_ID, drawable and rgn. Returns image_ID */
-static gint32
+/* Create an image. Sets layer_ID, drawable and rgn. Returns image */
+static GimpImage *
create_new_image (const gchar *filename,
guint width,
guint height,
GimpImageType gdtype,
GimpPrecision precision,
- gint32 *layer_ID,
+ GimpLayer **layer,
GeglBuffer **buffer)
{
- gint32 image_ID;
- GimpImageBaseType gitype;
+ GimpImage *image;
+ GimpImageBaseType gitype;
if ((gdtype == GIMP_GRAY_IMAGE) || (gdtype == GIMP_GRAYA_IMAGE))
gitype = GIMP_GRAY;
@@ -1013,26 +1092,26 @@ create_new_image (const gchar *filename,
else
gitype = GIMP_RGB;
- image_ID = gimp_image_new_with_precision (width, height, gitype, precision);
+ image = gimp_image_new_with_precision (width, height, gitype, precision);
- gimp_image_undo_disable (image_ID);
- gimp_image_set_filename (image_ID, filename);
+ gimp_image_undo_disable (image);
+ 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;
}
static gboolean
-compose_dialog (const gchar *compose_type,
- gint32 drawable_ID)
+compose_dialog (const gchar *compose_type,
+ GimpDrawable *drawable)
{
GtkWidget *dialog;
GtkWidget *main_vbox;
@@ -1043,7 +1122,7 @@ compose_dialog (const gchar *compose_type,
GtkWidget *combo;
GtkWidget *grid;
GtkSizeGroup *size_group;
- gint32 *layer_list;
+ GimpLayer **layer_list;
gint nlayers;
gint j;
gboolean run;
@@ -1060,12 +1139,12 @@ compose_dialog (const gchar *compose_type,
}
/* Save original image width/height */
- composeint.width = gimp_drawable_width (drawable_ID);
- composeint.height = gimp_drawable_height (drawable_ID);
+ composeint.width = gimp_drawable_width (drawable);
+ composeint.height = gimp_drawable_height (drawable);
gimp_ui_init (PLUG_IN_BINARY, TRUE);
- layer_list = gimp_image_get_layers (gimp_item_get_image (drawable_ID),
+ layer_list = gimp_image_get_layers (gimp_item_get_image (GIMP_ITEM (drawable)),
&nlayers);
dialog = gimp_dialog_new (_("Compose"), PLUG_IN_ROLE,
@@ -1181,14 +1260,14 @@ compose_dialog (const gchar *compose_type,
nlayers >= compose_dsc[composeint.compose_idx].num_images &&
j < nlayers)
{
- composeint.selected[j].comp.ID = layer_list[j];
+ composeint.selected[j].comp.object = layer_list[j];
}
else
{
- composeint.selected[j].comp.ID = drawable_ID;
+ composeint.selected[j].comp.object = drawable;
}
- composeint.selected[j].is_ID = TRUE;
+ composeint.selected[j].is_object = TRUE;
combo = gimp_drawable_combo_box_new (check_gray, NULL, NULL);
composeint.channel_menu[j] = combo;
@@ -1224,7 +1303,7 @@ compose_dialog (const gchar *compose_type,
* combo_callback has any scale and spinbutton to work with
*/
gimp_int_combo_box_connect (GIMP_INT_COMBO_BOX (combo),
- composeint.selected[j].comp.ID,
+ gimp_item_get_id (composeint.selected[j].comp.object),
G_CALLBACK (combo_callback),
GINT_TO_POINTER (j), NULL);
}
@@ -1249,10 +1328,10 @@ compose_dialog (const gchar *compose_type,
for (j = 0; j < MAX_COMPOSE_IMAGES; j++)
{
- composevals.inputs[j].is_ID = composeint.selected[j].is_ID;
+ composevals.inputs[j].is_object = composeint.selected[j].is_object;
- if (composevals.inputs[j].is_ID)
- composevals.inputs[j].comp.ID = composeint.selected[j].comp.ID;
+ if (composevals.inputs[j].is_object)
+ composevals.inputs[j].comp.object = composeint.selected[j].comp.object;
else
composevals.inputs[j].comp.val = composeint.selected[j].comp.val;
}
@@ -1267,14 +1346,14 @@ compose_dialog (const gchar *compose_type,
/* Compose interface functions */
static gboolean
-check_gray (gint32 image_id,
- gint32 drawable_id,
- gpointer data)
+check_gray (GimpImage *image,
+ GimpItem *drawable,
+ gpointer data)
{
- return ((gimp_image_base_type (image_id) == GIMP_GRAY) &&
- (gimp_image_width (image_id) == composeint.width) &&
- (gimp_image_height (image_id) == composeint.height));
+ return ((gimp_image_base_type (image) == GIMP_GRAY) &&
+ (gimp_image_width (image) == composeint.width) &&
+ (gimp_image_height (image) == composeint.height));
}
static void
@@ -1294,7 +1373,7 @@ check_response (GtkWidget *dialog,
for (i = 0; i < nb; i++)
{
- if (composeint.selected[i].is_ID)
+ if (composeint.selected[i].is_object)
{
has_image = TRUE;
break;
@@ -1339,17 +1418,17 @@ combo_callback (GimpIntComboBox *widget,
gtk_widget_set_sensitive (composeint.color_scales[n], TRUE);
gtk_widget_set_sensitive (composeint.color_spins[n], TRUE);
- composeint.selected[n].is_ID = FALSE;
- composeint.selected[n].comp.val =
- gtk_range_get_value (GTK_RANGE (composeint.color_scales[n]));
+ composeint.selected[n].is_object = FALSE;
+ composeint.selected[n].comp.val =
+ gtk_range_get_value (GTK_RANGE (composeint.color_scales[n]));
}
else
{
gtk_widget_set_sensitive (composeint.color_scales[n], FALSE);
gtk_widget_set_sensitive (composeint.color_spins[n], FALSE);
- composeint.selected[n].is_ID = TRUE;
- composeint.selected[n].comp.ID = id;
+ composeint.selected[n].is_object = TRUE;
+ composeint.selected[n].comp.object = gimp_item_get_by_id (id);
}
}
@@ -1400,7 +1479,7 @@ type_combo_callback (GimpIntComboBox *combo,
combo4 = (compose_dsc[compose_idx].num_images == 4);
gtk_widget_set_sensitive (composeint.channel_menu[3], combo4);
- scale4 = combo4 && !composeint.selected[3].is_ID;
+ scale4 = combo4 && !composeint.selected[3].is_object;
gtk_widget_set_sensitive (composeint.color_scales[3], scale4);
gtk_widget_set_sensitive (composeint.color_spins[3], scale4);
}
diff --git a/plug-ins/common/plugin-defs.pl b/plug-ins/common/plugin-defs.pl
index 657683aa75..b6eda61dec 100644
--- a/plug-ins/common/plugin-defs.pl
+++ b/plug-ins/common/plugin-defs.pl
@@ -8,7 +8,7 @@
'checkerboard' => { ui => 1, gegl => 1 },
'cml-explorer' => { ui => 1, gegl => 1, old_api => 1 },
'colormap-remap' => { ui => 1, gegl => 1 },
- 'compose' => { ui => 1, gegl => 1, old_api => 1 },
+ 'compose' => { ui => 1, gegl => 1 },
'contrast-retinex' => { ui => 1, gegl => 1 },
'crop-zealous' => { gegl => 1, old_api => 1 },
'curve-bend' => { ui => 1, gegl => 1, old_api => 1 },
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]