The intent of this patch is to make gimpressionist PDB-friendly. To do so
it:
1. Implements the non-interactive running logic.
2. Adds another PDB function, this time accepting a (Gimpressionist)
preset to use as an argument.
Consider it as a special gift for me just in time for GimpCon.
Regards,
Shlomi Fish
----------------------------------------------------------------------
Shlomi Fish shlomif@xxxxxxxxxxxxxxxxxxx
Home Page: http://shlomif.il.eu.org/
You are banished! You are banished! You are banished!
Hey? I'm just kidding!
--- vanilla/gimp/plug-ins/gimpressionist/presets.c 2004-05-28 19:36:52.538631904 +0300
+++ gimp/plug-ins/gimpressionist/presets.c 2004-06-23 15:32:39.509130992 +0300
@@ -278,6 +278,37 @@
return 0;
}
+int select_preset(char * preset)
+{
+ int ret = SELECT_PRESET_OK;
+ /* I'm copying this behavior as is. As it seems applying the
+ * factury_defaults preset does nothing, which I'm not sure
+ * if that was what the author intended.
+ * -- Shlomi Fish
+ */
+ if (strcmp (preset, factory_defaults))
+ {
+ gchar *rel = g_build_filename ("Presets", preset, NULL);
+ gchar *abs = findfile (rel);
+
+ g_free (rel);
+
+ if (abs)
+ {
+ if (loadpreset (abs))
+ {
+ ret = SELECT_PRESET_LOAD_FAILED;
+ }
+ g_free (abs);
+ }
+ else
+ {
+ ret = SELECT_PRESET_FILE_NOT_FOUND;
+ }
+ }
+ return ret;
+}
+
static void applypreset(GtkWidget *w, GtkTreeSelection *selection)
{
GtkTreeIter iter;
@@ -289,19 +320,7 @@
gtk_tree_model_get (model, &iter, 0, &preset, -1);
- if (strcmp (preset, factory_defaults))
- {
- gchar *rel = g_build_filename ("Presets", preset, NULL);
- gchar *abs = findfile (rel);
-
- g_free (rel);
-
- if (abs)
- {
- loadpreset (abs);
- g_free (abs);
- }
- }
+ select_preset(preset);
restorevals ();
--- vanilla/gimp/plug-ins/gimpressionist/gimpressionist.h 2004-05-28 19:36:52.474641632 +0300
+++ gimp/plug-ins/gimpressionist/gimpressionist.h 2004-06-23 15:31:52.672251280 +0300
@@ -182,3 +182,12 @@
void create_sizemap_dialog(void);
double getsiz(double x, double y, int from);
+
+enum SELECT_PRESET_RETURN_VALUES
+{
+ SELECT_PRESET_OK = 0,
+ SELECT_PRESET_FILE_NOT_FOUND = -1,
+ SELECT_PRESET_LOAD_FAILED = -2,
+};
+
+int select_preset(char * preset);
--- vanilla/gimp/plug-ins/gimpressionist/gimp.c 2004-05-28 19:36:52.467642696 +0300
+++ gimp/plug-ins/gimpressionist/gimp.c 2004-06-23 17:36:24.064427024 +0300
@@ -89,6 +89,8 @@
MAIN()
+#define USE_PRESET_PROC_NAME "plug_in_gimpressionist_use_preset"
+
static void
query(void)
{
@@ -99,6 +101,15 @@
{ GIMP_PDB_DRAWABLE, "drawable", "Input drawable" },
};
+ static GimpParamDef use_preset_args[] =
+ {
+ { GIMP_PDB_INT32, "run_mode", "Interactive" },
+ { GIMP_PDB_IMAGE, "image", "Input image" },
+ { GIMP_PDB_DRAWABLE, "drawable", "Input drawable" },
+ { GIMP_PDB_STRING, "preset", "Preset Name" },
+ };
+
+
gimp_install_procedure (PLUG_IN_NAME,
"Performs various artistic operations on an image",
"Performs various artistic operations on an image",
@@ -110,6 +121,19 @@
GIMP_PLUGIN,
G_N_ELEMENTS (args), 0,
args, NULL);
+
+ gimp_install_procedure (USE_PRESET_PROC_NAME,
+ "Performs various artistic operations on an image using a preset",
+ "Performs various artistic operations on an image using a preset",
+ "Shlomi Fish <shlomif@xxxxxxxxxxx>",
+ "Shlomi Fish",
+ "v0.2, June 2004",
+ N_("_GIMPressionist by Preset..."),
+ "RGB*, GRAY*",
+ GIMP_PLUGIN,
+ G_N_ELEMENTS (use_preset_args), 0,
+ use_preset_args, NULL);
+
gimp_plugin_menu_register (PLUG_IN_NAME,
N_("<Image>/Filters/Artistic"));
@@ -132,9 +156,18 @@
static GimpParam values[1];
GimpRunMode run_mode;
GimpPDBStatusType status;
+ gboolean with_specified_preset;
status = GIMP_PDB_SUCCESS;
run_mode = param[0].data.d_int32;
+ if (!strcmp(name, USE_PRESET_PROC_NAME))
+ {
+ with_specified_preset = TRUE;
+ }
+ else
+ {
+ with_specified_preset = FALSE;
+ }
values[0].type = GIMP_PDB_STATUS;
values[0].data.d_status = status;
@@ -153,15 +186,27 @@
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:
+ case GIMP_RUN_NONINTERACTIVE:
gimpressionist_get_data(PLUG_IN_NAME, &pcvals);
- if(!create_gimpressionist())
- return;
+ if (run_mode == GIMP_RUN_INTERACTIVE)
+ {
+ if(!create_gimpressionist())
+ return;
+ }
break;
+/* TODO: Remove after it was verified to be OK */
+#if 0
case GIMP_RUN_NONINTERACTIVE:
g_message ("GIMP_RUN_NONINTERACTIVE not implemented yet!");
status = GIMP_PDB_EXECUTION_ERROR;
- break;
+ break;
+#endif
case GIMP_RUN_WITH_LAST_VALS:
gimpressionist_get_data(PLUG_IN_NAME, &pcvals);
break;
@@ -173,11 +218,31 @@
(gimp_drawable_is_rgb(drawable->drawable_id) ||
gimp_drawable_is_gray(drawable->drawable_id)))
{
- gimpressionist_main();
- gimp_displays_flush ();
- if (run_mode == GIMP_RUN_INTERACTIVE)
- gimp_set_data(PLUG_IN_NAME, &pcvals, sizeof(gimpressionist_vals_t));
+ if (with_specified_preset)
+ {
+ /* If select_preset fails - set to an error */
+ if (select_preset(param[3].data.d_string))
+ {
+ 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.
+ * -- Shlomi Fish
+ * */
+ pcvals.run = TRUE;
+ }
+
+ if (status == GIMP_PDB_SUCCESS)
+ {
+ gimpressionist_main();
+ gimp_displays_flush ();
+
+ if (run_mode == GIMP_RUN_INTERACTIVE)
+ gimp_set_data(PLUG_IN_NAME, &pcvals, sizeof(gimpressionist_vals_t));
+ }
}
else if (status == GIMP_PDB_SUCCESS)
{