diff --git a/plug-ins/gimpressionist/brush.c b/plug-ins/gimpressionist/brush.c index 495fc5c5f4..7af32532b7 100644 --- a/plug-ins/gimpressionist/brush.c +++ b/plug-ins/gimpressionist/brush.c @@ -93,18 +93,18 @@ set_colorbrushes (const gchar *fn) } static const Babl * -get_u8_format (gint32 drawable_id) +get_u8_format (GimpDrawable *drawable) { - if (gimp_drawable_is_rgb (drawable_id)) + if (gimp_drawable_is_rgb (drawable)) { - if (gimp_drawable_has_alpha (drawable_id)) + if (gimp_drawable_has_alpha (drawable)) return babl_format ("R'G'B'A u8"); else return babl_format ("R'G'B' u8"); } else { - if (gimp_drawable_has_alpha (drawable_id)) + if (gimp_drawable_has_alpha (drawable)) return babl_format ("Y'A u8"); else return babl_format ("Y' u8"); @@ -115,21 +115,24 @@ static void brushdmenuselect (GtkWidget *widget, gpointer data) { - GeglBuffer *src_buffer; - const Babl *format; - guchar *src_row; - guchar *src; - gint bpp; - gint x, y; - ppm_t *p; - gint x1, y1, w, h; - gint row; - gint32 drawable_id; - gint rowstride; + GeglBuffer *src_buffer; + const Babl *format; + guchar *src_row; + guchar *src; + gint bpp; + gint x, y; + ppm_t *p; + gint x1, y1, w, h; + gint row; + gint32 drawable_id = -1; + GimpDrawable *drawable; + gint rowstride; gimp_int_combo_box_get_active (GIMP_INT_COMBO_BOX (widget), &drawable_id); - if (drawable_id == -1) + drawable = GIMP_DRAWABLE (gimp_item_get_by_id (drawable_id)); + + if (! drawable) return; if (brush_from_file == 2) @@ -146,10 +149,10 @@ brushdmenuselect (GtkWidget *widget, gtk_adjustment_set_value (brush_gamma_adjust, 1.0); gtk_adjustment_set_value (brush_aspect_adjust, 0.0); - if (! gimp_drawable_mask_intersect (drawable_id, &x1, &y1, &w, &h)) + if (! gimp_drawable_mask_intersect (drawable, &x1, &y1, &w, &h)) return; - format = get_u8_format (drawable_id); + format = get_u8_format (drawable); bpp = babl_format_get_bytes_per_pixel (format); ppm_kill (&brushppm); @@ -160,7 +163,7 @@ brushdmenuselect (GtkWidget *widget, src_row = g_new (guchar, w * bpp); - src_buffer = gimp_drawable_get_buffer (drawable_id); + src_buffer = gimp_drawable_get_buffer (drawable); if (bpp == 3) { /* RGB */ @@ -220,17 +223,6 @@ brushdmenuselect (GtkWidget *widget, update_brush_preview (NULL); } -#if 0 -void -dummybrushdmenuselect (GtkWidget *w, gpointer data) -{ - ppm_kill (&brushppm); - ppm_new (&brushppm, 10,10); - brush_from_file = 0; - update_brush_preview (NULL); -} -#endif - static void brushlistrefresh (void) { @@ -306,12 +298,12 @@ savebrush (GtkWidget *wg, } static gboolean -validdrawable (gint32 imageid, - gint32 drawableid, - gpointer data) +validdrawable (GimpImage *image, + GimpItem *item, + gpointer data) { - return (gimp_drawable_is_rgb (drawableid) || - gimp_drawable_is_gray (drawableid)); + return (gimp_drawable_is_rgb (GIMP_DRAWABLE (item)) || + gimp_drawable_is_gray (GIMP_DRAWABLE (item))); } /* diff --git a/plug-ins/gimpressionist/gimp.c b/plug-ins/gimpressionist/gimp.c index 97bf3d8129..0b66bb3f2e 100644 --- a/plug-ins/gimpressionist/gimp.c +++ b/plug-ins/gimpressionist/gimp.c @@ -33,30 +33,110 @@ #include "orientmap.h" #include "size.h" - #include "libgimp/stdplugins-intl.h" -static void query (void); -static void run (const gchar *name, - gint nparams, - const GimpParam *param, - gint *nreturn_vals, - GimpParam **return_vals); -static void gimpressionist_main (void); + +typedef struct _Gimpressionist Gimpressionist; +typedef struct _GimpressionistClass GimpressionistClass; + +struct _Gimpressionist +{ + GimpPlugIn parent_instance; +}; + +struct _GimpressionistClass +{ + GimpPlugInClass parent_class; +}; -const GimpPlugInInfo PLUG_IN_INFO = { - NULL, /* init_proc */ - NULL, /* quit_proc */ - query, /* query_proc */ - run /* run_proc */ -}; /* PLUG_IN_INFO */ +#define GIMPRESSIONIST_TYPE (gimpressionist_get_type ()) +#define GIMPRESSIONIST (obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GIMPRESSIONIST_TYPE, Gimpressionist)) + +GType gimpressionist_get_type (void) G_GNUC_CONST; + +static GList * gimpressionist_query_procedures (GimpPlugIn *plug_in); +static GimpProcedure * gimpressionist_create_procedure (GimpPlugIn *plug_in, + const gchar *name); + +static GimpValueArray * gimpressionist_run (GimpProcedure *procedure, + GimpRunMode run_mode, + GimpImage *image, + GimpDrawable *drawable, + const GimpValueArray *args, + gpointer run_data); + +static void gimpressionist_main (void); + + +G_DEFINE_TYPE (Gimpressionist, gimpressionist, GIMP_TYPE_PLUG_IN) + +GIMP_MAIN (GIMPRESSIONIST_TYPE) + static GimpDrawable *drawable; static ppm_t infile = { 0, 0, NULL }; static ppm_t inalpha = { 0, 0, NULL }; +static void +gimpressionist_class_init (GimpressionistClass *klass) +{ + GimpPlugInClass *plug_in_class = GIMP_PLUG_IN_CLASS (klass); + + plug_in_class->query_procedures = gimpressionist_query_procedures; + plug_in_class->create_procedure = gimpressionist_create_procedure; +} + +static void +gimpressionist_init (Gimpressionist *gimpressionist) +{ +} + +static GList * +gimpressionist_query_procedures (GimpPlugIn *plug_in) +{ + return g_list_append (NULL, g_strdup (PLUG_IN_PROC)); +} + +static GimpProcedure * +gimpressionist_create_procedure (GimpPlugIn *plug_in, + const gchar *name) +{ + GimpProcedure *procedure = NULL; + + if (! strcmp (name, PLUG_IN_PROC)) + { + procedure = gimp_image_procedure_new (plug_in, name, + GIMP_PDB_PROC_TYPE_PLUGIN, + gimpressionist_run, NULL, NULL); + + gimp_procedure_set_image_types (procedure, "RGB*, GRAY*"); + + gimp_procedure_set_menu_label (procedure, N_("_GIMPressionist...")); + gimp_procedure_add_menu_path (procedure, "/Filters/Artistic"); + + gimp_procedure_set_documentation (procedure, + N_("Performs various artistic " + "operations"), + "Performs various artistic operations " + "on an image", + name); + gimp_procedure_set_attribution (procedure, + "Vidar Madsen ", + "Vidar Madsen", + PLUG_IN_VERSION); + + GIMP_PROC_ARG_STRING (procedure, "preset", + "Preset", + "Preset Name", + NULL, + G_PARAM_READWRITE); + } + + return procedure; +} + void infile_copy_to_ppm (ppm_t * p) { @@ -72,167 +152,95 @@ infile_copy_alpha_to_ppm (ppm_t * p) ppm_copy (&inalpha, p); } -MAIN () - -static void -query (void) +static GimpValueArray * +gimpressionist_run (GimpProcedure *procedure, + GimpRunMode run_mode, + GimpImage *image, + GimpDrawable *_drawable, + const GimpValueArray *args, + gpointer run_data) { - static const GimpParamDef args[] = - { - { GIMP_PDB_INT32, "run-mode", "The run mode { RUN-INTERACTIVE (0) }" }, - { GIMP_PDB_IMAGE, "image", "Input image" }, - { GIMP_PDB_DRAWABLE, "drawable", "Input drawable" }, - { GIMP_PDB_STRING, "preset", "Preset Name" }, - }; - - gimp_install_procedure (PLUG_IN_PROC, - N_("Performs various artistic operations"), - "Performs various artistic operations on an image", - "Vidar Madsen ", - "Vidar Madsen", - PLUG_IN_VERSION, - N_("_GIMPressionist..."), - "RGB*, GRAY*", - GIMP_PDB_PROC_TYPE_PLUGIN, - G_N_ELEMENTS (args), 0, - args, NULL); - - gimp_plugin_menu_register (PLUG_IN_PROC, "/Filters/Artistic"); -} - -static void -gimpressionist_get_data (void) -{ - restore_default_values (); - gimp_get_data (PLUG_IN_PROC, &pcvals); -} - -static void -run (const gchar *name, - gint nparams, - const GimpParam *param, - gint *nreturn_vals, - GimpParam **return_vals) -{ - static GimpParam values[2]; - GimpRunMode run_mode; - GimpPDBStatusType status; - gboolean with_specified_preset; - gchar *preset_name = NULL; - - status = GIMP_PDB_SUCCESS; - run_mode = param[0].data.d_int32; - with_specified_preset = FALSE; - - if (nparams > 3) - { - preset_name = param[3].data.d_string; - if (strcmp (preset_name, "")) - { - with_specified_preset = TRUE; - } - } - - values[0].type = GIMP_PDB_STATUS; - values[0].data.d_status = status; - - *nreturn_vals = 1; - *return_vals = values; + const gchar *preset_name; INIT_I18N (); gegl_init (NULL, NULL); - /* Get the active drawable info */ + drawable = _drawable; - drawable = GIMP_DRAWABLE (gimp_item_get_by_id (param[2].data.d_drawable)); img_has_alpha = gimp_drawable_has_alpha (drawable); random_generator = g_rand_new (); - /* - * Check precondition before we open a dialog: Is there a selection - * that intersects, OR is there no selection (use entire drawable.) - */ { - gint x1, y1, width, height; /* Not used. */ + gint x1, y1, width, height; if (! gimp_drawable_mask_intersect (drawable, &x1, &y1, &width, &height)) { - values[0].data.d_status = GIMP_PDB_EXECUTION_ERROR; - *nreturn_vals = 2; - values[1].type = GIMP_PDB_STRING; - values[1].data.d_string = _("The selection does not intersect " - "the active layer or mask."); - - return; + return gimp_procedure_new_return_values (procedure, + GIMP_PDB_SUCCESS, + NULL); } } + restore_default_values (); switch (run_mode) { - /* - * Note: there's a limitation here. Running this plug-in before the - * interactive plug-in was run will cause it to crash, because the - * data is uninitialized. - * */ case GIMP_RUN_INTERACTIVE: + gimp_get_data (PLUG_IN_PROC, &pcvals); + + if (! create_gimpressionist ()) + { + return gimp_procedure_new_return_values (procedure, + GIMP_PDB_CANCEL, + NULL); + } + break; + case GIMP_RUN_NONINTERACTIVE: + preset_name = GIMP_VALUES_GET_STRING (args, 0); + + if (select_preset (preset_name)) + { + return gimp_procedure_new_return_values (procedure, + GIMP_PDB_EXECUTION_ERROR, + NULL); + } + break; + case GIMP_RUN_WITH_LAST_VALS: - gimpressionist_get_data (); + gimp_get_data (PLUG_IN_PROC, &pcvals); + break; + } + + /* It seems that the value of the run variable is stored in the + * preset. I don't know if it's a bug or a feature, but I just work + * here and am anxious to get a working version. So I'm setting it + * to the correct value here. + * + * It also seems that defaultpcvals have this erroneous value as + * well, so it gets set to FALSE as well. Thus it is always set to + * TRUE upon a non-interactive run. -- Shlomi Fish + */ + pcvals.run = TRUE; + + if (gimp_drawable_is_rgb (drawable) || + gimp_drawable_is_gray (drawable)) + { + gimpressionist_main (); + + if (run_mode != GIMP_RUN_NONINTERACTIVE) + gimp_displays_flush (); + if (run_mode == GIMP_RUN_INTERACTIVE) - { - if (!create_gimpressionist ()) - return; - } - break; - default: - status = GIMP_PDB_EXECUTION_ERROR; - break; + gimp_set_data (PLUG_IN_PROC, &pcvals, sizeof (gimpressionist_vals_t)); } - if ((status == GIMP_PDB_SUCCESS) && - (gimp_drawable_is_rgb (drawable) || - gimp_drawable_is_gray (drawable))) + else { - - if (with_specified_preset) - { - /* If select_preset fails - set to an error */ - if (select_preset (preset_name)) - { - status = GIMP_PDB_EXECUTION_ERROR; - } - } - /* It seems that the value of the run variable is stored in - * the preset. I don't know if it's a bug or a feature, but - * I just work here and am anxious to get a working version. - * So I'm setting it to the correct value here. - * - * It also seems that defaultpcvals have this erroneous - * value as well, so it gets set to FALSE as well. Thus it - * is always set to TRUE upon a non-interactive run. - * -- Shlomi Fish - * */ - if (run_mode == GIMP_RUN_NONINTERACTIVE) - { - pcvals.run = TRUE; - } - - if (status == GIMP_PDB_SUCCESS) - { - gimpressionist_main (); - gimp_displays_flush (); - - if (run_mode == GIMP_RUN_INTERACTIVE) - gimp_set_data (PLUG_IN_PROC, - &pcvals, - sizeof (gimpressionist_vals_t)); - } - } - else if (status == GIMP_PDB_SUCCESS) - { - status = GIMP_PDB_EXECUTION_ERROR; + return gimp_procedure_new_return_values (procedure, + GIMP_PDB_EXECUTION_ERROR, + NULL); } /* Resources Cleanup */ @@ -245,7 +253,7 @@ run (const gchar *name, orientation_map_free_resources (); size_map_free_resources (); - values[0].data.d_status = status; +return gimp_procedure_new_return_values (procedure, GIMP_PDB_SUCCESS, NULL); } static const Babl *