gimp/plug-ins/gimpressionist/gimp.c

500 lines
14 KiB
C
Raw Normal View History

/* GIMP - The GNU Image Manipulation Program
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "config.h"
1999-08-26 22:29:37 +00:00
#include <string.h>
1999-08-26 22:29:37 +00:00
#include <gtk/gtk.h>
#include <libgimp/gimp.h>
1999-08-26 22:29:37 +00:00
#include "ppmtool.h"
#include "infile.h"
1999-08-26 22:29:37 +00:00
#include "gimpressionist.h"
#include "preview.h"
#include "brush.h"
#include "presets.h"
#include "random.h"
#include "orientmap.h"
#include "size.h"
#include "libgimp/stdplugins-intl.h"
1999-08-26 22:29:37 +00:00
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);
1999-08-26 22:29:37 +00:00
const GimpPlugInInfo PLUG_IN_INFO = {
1999-08-26 22:29:37 +00:00
NULL, /* init_proc */
NULL, /* quit_proc */
query, /* query_proc */
run /* run_proc */
}; /* PLUG_IN_INFO */
static GimpDrawable *drawable;
static ppm_t infile = {0, 0, NULL};
static ppm_t inalpha = {0, 0, NULL};
void
infile_copy_to_ppm (ppm_t * p)
{
if (!PPM_IS_INITED (&infile))
grabarea ();
ppm_copy (&infile, p);
}
void
infile_copy_alpha_to_ppm (ppm_t * p)
{
ppm_copy (&inalpha, p);
}
1999-08-26 22:29:37 +00:00
MAIN ()
removed our own action_area API and use GtkDialog's one. Create all 2003-11-06 Michael Natterer <mitch@gimp.org> * libgimpwidgets/gimpdialog.[ch]: removed our own action_area API and use GtkDialog's one. Create all dialogs without separator. Changed almost everything else too. Fixes bug #125143. * libgimpwidgets/gimpquerybox.c * libgimpwidgets/gimpunitmenu.c: changed accordingly. * libgimp/gimpexport.[ch]: ditto. Renamed enum GimpExportReturnType to GimpExportReturn. * libgimp/gimpcompat.h: added a #define for the old name. * themes/Default/gtkrc: increased action_area border to 6 pixels. * app/display/gimpdisplayshell-filter-dialog.c * app/display/gimpdisplayshell-scale.c * app/display/gimpprogress.c * app/gui/brush-select.c * app/gui/channels-commands.c * app/gui/color-notebook.c * app/gui/convert-dialog.c * app/gui/file-new-dialog.c * app/gui/font-select.c * app/gui/gradient-editor-commands.c * app/gui/gradient-select.c * app/gui/grid-dialog.c * app/gui/image-commands.c * app/gui/info-window.c * app/gui/layers-commands.c * app/gui/module-browser.c * app/gui/offset-dialog.c * app/gui/palette-import-dialog.c * app/gui/palette-select.c * app/gui/pattern-select.c * app/gui/preferences-dialog.c * app/gui/qmask-commands.c * app/gui/resize-dialog.c * app/gui/resolution-calibrate-dialog.c * app/gui/stroke-dialog.c * app/gui/templates-commands.c * app/gui/user-install-dialog.c * app/gui/vectors-commands.c * app/tools/gimpcolorpickertool.c * app/tools/gimpcroptool.c * app/tools/gimpimagemaptool.c * app/tools/gimpmeasuretool.c * app/tools/gimptransformtool.c * app/widgets/gimptexteditor.c * app/widgets/gimptooldialog.[ch] * app/widgets/gimpviewabledialog.[ch] * app/widgets/gimpwidgets-utils.c: changed accordingly and increased the dialogs' outer borders to 6 pixels all over the place. * plug-ins/*/*.c: changed accordingly. The plug-ins may be arbitrarily broken, I tested none of them.
2003-11-06 15:27:05 +00:00
1999-08-26 22:29:37 +00:00
static void
query (void)
1999-08-26 22:29:37 +00:00
{
static const GimpParamDef args[] =
Cleaned up and improved the message system: 2003-06-13 Michael Natterer <mitch@gimp.org> Cleaned up and improved the message system: * app/core/gimp.[ch]: added "const gchar *domain" to GimpMessageFunc (a NULL domain means the message is from the GIMP core, everything else is a plug-in). * app/errors.c: pass "domain == NULL" to gimp_message(). * tools/pdbgen/pdb/message.pdb: derive the message domain from the current plug-in's menu_path (evil hack but works reasonably well). * app/pdb/message_cmds.c: regenerated. * app/widgets/gimpwidgets-utils.[ch] (gimp_message_box): added a header showing the message domain and changed the dialog layout to follow the HIG more closely. * app/gui/error-console-dialog.[ch]: removed. * app/widgets/gimperrorconsole.[ch] * app/gui/error-console-commands.[ch] * app/gui/error-console-menu.[ch]: new files containing a re-implementation of the error console dialog. * app/gui/Makefile.am * app/gui/dialogs-constructors.c * app/gui/gui.c * app/gui/menus.c * app/widgets/Makefile.am * app/widgets/widgets-types.h: changed accordingly. * app/display/gimpprogress.c: added more spacing and removed the separator (more HIG compliant). * plug-ins/[most plug-ins].c: Changed lots of messages and progress strings: - Removed plug-in names from messages since that's automatically covered by "domain" now. - Put all filenames in ''. - Changed "Loading" to "Opening". - Added "..." to all progress messages. - Cleaned up all file open/save error messages to look the same and include g_strerror(errno). - Removed special casing for progress bars and *always* show them, not only if run_mode != GIMP_RUN_NONINTERACTIVE (we can't expect all plug-ins to do this correctly but need to hack the core to sort out unwanted progress bars). Unrelated: - Cleaned up indentation, spacing, #includes, coding style and other stuff while I was at all these files.
2003-06-13 14:37:00 +00:00
{
{ GIMP_PDB_INT32, "run-mode", "The run mode { RUN-INTERACTIVE (0) }" },
Cleaned up and improved the message system: 2003-06-13 Michael Natterer <mitch@gimp.org> Cleaned up and improved the message system: * app/core/gimp.[ch]: added "const gchar *domain" to GimpMessageFunc (a NULL domain means the message is from the GIMP core, everything else is a plug-in). * app/errors.c: pass "domain == NULL" to gimp_message(). * tools/pdbgen/pdb/message.pdb: derive the message domain from the current plug-in's menu_path (evil hack but works reasonably well). * app/pdb/message_cmds.c: regenerated. * app/widgets/gimpwidgets-utils.[ch] (gimp_message_box): added a header showing the message domain and changed the dialog layout to follow the HIG more closely. * app/gui/error-console-dialog.[ch]: removed. * app/widgets/gimperrorconsole.[ch] * app/gui/error-console-commands.[ch] * app/gui/error-console-menu.[ch]: new files containing a re-implementation of the error console dialog. * app/gui/Makefile.am * app/gui/dialogs-constructors.c * app/gui/gui.c * app/gui/menus.c * app/widgets/Makefile.am * app/widgets/widgets-types.h: changed accordingly. * app/display/gimpprogress.c: added more spacing and removed the separator (more HIG compliant). * plug-ins/[most plug-ins].c: Changed lots of messages and progress strings: - Removed plug-in names from messages since that's automatically covered by "domain" now. - Put all filenames in ''. - Changed "Loading" to "Opening". - Added "..." to all progress messages. - Cleaned up all file open/save error messages to look the same and include g_strerror(errno). - Removed special casing for progress bars and *always* show them, not only if run_mode != GIMP_RUN_NONINTERACTIVE (we can't expect all plug-ins to do this correctly but need to hack the core to sort out unwanted progress bars). Unrelated: - Cleaned up indentation, spacing, #includes, coding style and other stuff while I was at all these files.
2003-06-13 14:37:00 +00:00
{ GIMP_PDB_IMAGE, "image", "Input image" },
{ GIMP_PDB_DRAWABLE, "drawable", "Input drawable" },
{ GIMP_PDB_STRING, "preset", "Preset Name" },
Cleaned up and improved the message system: 2003-06-13 Michael Natterer <mitch@gimp.org> Cleaned up and improved the message system: * app/core/gimp.[ch]: added "const gchar *domain" to GimpMessageFunc (a NULL domain means the message is from the GIMP core, everything else is a plug-in). * app/errors.c: pass "domain == NULL" to gimp_message(). * tools/pdbgen/pdb/message.pdb: derive the message domain from the current plug-in's menu_path (evil hack but works reasonably well). * app/pdb/message_cmds.c: regenerated. * app/widgets/gimpwidgets-utils.[ch] (gimp_message_box): added a header showing the message domain and changed the dialog layout to follow the HIG more closely. * app/gui/error-console-dialog.[ch]: removed. * app/widgets/gimperrorconsole.[ch] * app/gui/error-console-commands.[ch] * app/gui/error-console-menu.[ch]: new files containing a re-implementation of the error console dialog. * app/gui/Makefile.am * app/gui/dialogs-constructors.c * app/gui/gui.c * app/gui/menus.c * app/widgets/Makefile.am * app/widgets/widgets-types.h: changed accordingly. * app/display/gimpprogress.c: added more spacing and removed the separator (more HIG compliant). * plug-ins/[most plug-ins].c: Changed lots of messages and progress strings: - Removed plug-in names from messages since that's automatically covered by "domain" now. - Put all filenames in ''. - Changed "Loading" to "Opening". - Added "..." to all progress messages. - Cleaned up all file open/save error messages to look the same and include g_strerror(errno). - Removed special casing for progress bars and *always* show them, not only if run_mode != GIMP_RUN_NONINTERACTIVE (we can't expect all plug-ins to do this correctly but need to hack the core to sort out unwanted progress bars). Unrelated: - Cleaned up indentation, spacing, #includes, coding style and other stuff while I was at all these files.
2003-06-13 14:37:00 +00:00
};
1999-08-26 22:29:37 +00:00
gimp_install_procedure (PLUG_IN_PROC,
N_("Performs various artistic operations"),
"Performs various artistic operations on an image",
"Vidar Madsen <vidar@prosalg.no>",
"Vidar Madsen",
PLUG_IN_VERSION,
N_("_GIMPressionist..."),
"RGB*, GRAY*",
GIMP_PLUGIN,
Cleaned up and improved the message system: 2003-06-13 Michael Natterer <mitch@gimp.org> Cleaned up and improved the message system: * app/core/gimp.[ch]: added "const gchar *domain" to GimpMessageFunc (a NULL domain means the message is from the GIMP core, everything else is a plug-in). * app/errors.c: pass "domain == NULL" to gimp_message(). * tools/pdbgen/pdb/message.pdb: derive the message domain from the current plug-in's menu_path (evil hack but works reasonably well). * app/pdb/message_cmds.c: regenerated. * app/widgets/gimpwidgets-utils.[ch] (gimp_message_box): added a header showing the message domain and changed the dialog layout to follow the HIG more closely. * app/gui/error-console-dialog.[ch]: removed. * app/widgets/gimperrorconsole.[ch] * app/gui/error-console-commands.[ch] * app/gui/error-console-menu.[ch]: new files containing a re-implementation of the error console dialog. * app/gui/Makefile.am * app/gui/dialogs-constructors.c * app/gui/gui.c * app/gui/menus.c * app/widgets/Makefile.am * app/widgets/widgets-types.h: changed accordingly. * app/display/gimpprogress.c: added more spacing and removed the separator (more HIG compliant). * plug-ins/[most plug-ins].c: Changed lots of messages and progress strings: - Removed plug-in names from messages since that's automatically covered by "domain" now. - Put all filenames in ''. - Changed "Loading" to "Opening". - Added "..." to all progress messages. - Cleaned up all file open/save error messages to look the same and include g_strerror(errno). - Removed special casing for progress bars and *always* show them, not only if run_mode != GIMP_RUN_NONINTERACTIVE (we can't expect all plug-ins to do this correctly but need to hack the core to sort out unwanted progress bars). Unrelated: - Cleaned up indentation, spacing, #includes, coding style and other stuff while I was at all these files.
2003-06-13 14:37:00 +00:00
G_N_ELEMENTS (args), 0,
args, NULL);
}
1999-08-26 22:29:37 +00:00
static void
gimpressionist_get_data (void)
1999-08-26 22:29:37 +00:00
{
restore_default_values ();
gimp_get_data (PLUG_IN_PROC, &pcvals);
1999-08-26 22:29:37 +00:00
}
static void
run (const gchar *name,
gint nparams,
const GimpParam *param,
gint *nreturn_vals,
GimpParam **return_vals)
1999-08-26 22:29:37 +00:00
{
static GimpParam values[2];
Cleaned up and improved the message system: 2003-06-13 Michael Natterer <mitch@gimp.org> Cleaned up and improved the message system: * app/core/gimp.[ch]: added "const gchar *domain" to GimpMessageFunc (a NULL domain means the message is from the GIMP core, everything else is a plug-in). * app/errors.c: pass "domain == NULL" to gimp_message(). * tools/pdbgen/pdb/message.pdb: derive the message domain from the current plug-in's menu_path (evil hack but works reasonably well). * app/pdb/message_cmds.c: regenerated. * app/widgets/gimpwidgets-utils.[ch] (gimp_message_box): added a header showing the message domain and changed the dialog layout to follow the HIG more closely. * app/gui/error-console-dialog.[ch]: removed. * app/widgets/gimperrorconsole.[ch] * app/gui/error-console-commands.[ch] * app/gui/error-console-menu.[ch]: new files containing a re-implementation of the error console dialog. * app/gui/Makefile.am * app/gui/dialogs-constructors.c * app/gui/gui.c * app/gui/menus.c * app/widgets/Makefile.am * app/widgets/widgets-types.h: changed accordingly. * app/display/gimpprogress.c: added more spacing and removed the separator (more HIG compliant). * plug-ins/[most plug-ins].c: Changed lots of messages and progress strings: - Removed plug-in names from messages since that's automatically covered by "domain" now. - Put all filenames in ''. - Changed "Loading" to "Opening". - Added "..." to all progress messages. - Cleaned up all file open/save error messages to look the same and include g_strerror(errno). - Removed special casing for progress bars and *always* show them, not only if run_mode != GIMP_RUN_NONINTERACTIVE (we can't expect all plug-ins to do this correctly but need to hack the core to sort out unwanted progress bars). Unrelated: - Cleaned up indentation, spacing, #includes, coding style and other stuff while I was at all these files.
2003-06-13 14:37:00 +00:00
GimpRunMode run_mode;
GimpPDBStatusType status;
gboolean with_specified_preset;
gchar *preset_name = NULL;
1999-08-26 22:29:37 +00:00
Cleaned up and improved the message system: 2003-06-13 Michael Natterer <mitch@gimp.org> Cleaned up and improved the message system: * app/core/gimp.[ch]: added "const gchar *domain" to GimpMessageFunc (a NULL domain means the message is from the GIMP core, everything else is a plug-in). * app/errors.c: pass "domain == NULL" to gimp_message(). * tools/pdbgen/pdb/message.pdb: derive the message domain from the current plug-in's menu_path (evil hack but works reasonably well). * app/pdb/message_cmds.c: regenerated. * app/widgets/gimpwidgets-utils.[ch] (gimp_message_box): added a header showing the message domain and changed the dialog layout to follow the HIG more closely. * app/gui/error-console-dialog.[ch]: removed. * app/widgets/gimperrorconsole.[ch] * app/gui/error-console-commands.[ch] * app/gui/error-console-menu.[ch]: new files containing a re-implementation of the error console dialog. * app/gui/Makefile.am * app/gui/dialogs-constructors.c * app/gui/gui.c * app/gui/menus.c * app/widgets/Makefile.am * app/widgets/widgets-types.h: changed accordingly. * app/display/gimpprogress.c: added more spacing and removed the separator (more HIG compliant). * plug-ins/[most plug-ins].c: Changed lots of messages and progress strings: - Removed plug-in names from messages since that's automatically covered by "domain" now. - Put all filenames in ''. - Changed "Loading" to "Opening". - Added "..." to all progress messages. - Cleaned up all file open/save error messages to look the same and include g_strerror(errno). - Removed special casing for progress bars and *always* show them, not only if run_mode != GIMP_RUN_NONINTERACTIVE (we can't expect all plug-ins to do this correctly but need to hack the core to sort out unwanted progress bars). Unrelated: - Cleaned up indentation, spacing, #includes, coding style and other stuff while I was at all these files.
2003-06-13 14:37:00 +00:00
status = GIMP_PDB_SUCCESS;
1999-08-26 22:29:37 +00:00
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;
}
}
1999-08-26 22:29:37 +00:00
Cleaned up and improved the message system: 2003-06-13 Michael Natterer <mitch@gimp.org> Cleaned up and improved the message system: * app/core/gimp.[ch]: added "const gchar *domain" to GimpMessageFunc (a NULL domain means the message is from the GIMP core, everything else is a plug-in). * app/errors.c: pass "domain == NULL" to gimp_message(). * tools/pdbgen/pdb/message.pdb: derive the message domain from the current plug-in's menu_path (evil hack but works reasonably well). * app/pdb/message_cmds.c: regenerated. * app/widgets/gimpwidgets-utils.[ch] (gimp_message_box): added a header showing the message domain and changed the dialog layout to follow the HIG more closely. * app/gui/error-console-dialog.[ch]: removed. * app/widgets/gimperrorconsole.[ch] * app/gui/error-console-commands.[ch] * app/gui/error-console-menu.[ch]: new files containing a re-implementation of the error console dialog. * app/gui/Makefile.am * app/gui/dialogs-constructors.c * app/gui/gui.c * app/gui/menus.c * app/widgets/Makefile.am * app/widgets/widgets-types.h: changed accordingly. * app/display/gimpprogress.c: added more spacing and removed the separator (more HIG compliant). * plug-ins/[most plug-ins].c: Changed lots of messages and progress strings: - Removed plug-in names from messages since that's automatically covered by "domain" now. - Put all filenames in ''. - Changed "Loading" to "Opening". - Added "..." to all progress messages. - Cleaned up all file open/save error messages to look the same and include g_strerror(errno). - Removed special casing for progress bars and *always* show them, not only if run_mode != GIMP_RUN_NONINTERACTIVE (we can't expect all plug-ins to do this correctly but need to hack the core to sort out unwanted progress bars). Unrelated: - Cleaned up indentation, spacing, #includes, coding style and other stuff while I was at all these files.
2003-06-13 14:37:00 +00:00
values[0].type = GIMP_PDB_STATUS;
1999-08-26 22:29:37 +00:00
values[0].data.d_status = status;
*nreturn_vals = 1;
Cleaned up and improved the message system: 2003-06-13 Michael Natterer <mitch@gimp.org> Cleaned up and improved the message system: * app/core/gimp.[ch]: added "const gchar *domain" to GimpMessageFunc (a NULL domain means the message is from the GIMP core, everything else is a plug-in). * app/errors.c: pass "domain == NULL" to gimp_message(). * tools/pdbgen/pdb/message.pdb: derive the message domain from the current plug-in's menu_path (evil hack but works reasonably well). * app/pdb/message_cmds.c: regenerated. * app/widgets/gimpwidgets-utils.[ch] (gimp_message_box): added a header showing the message domain and changed the dialog layout to follow the HIG more closely. * app/gui/error-console-dialog.[ch]: removed. * app/widgets/gimperrorconsole.[ch] * app/gui/error-console-commands.[ch] * app/gui/error-console-menu.[ch]: new files containing a re-implementation of the error console dialog. * app/gui/Makefile.am * app/gui/dialogs-constructors.c * app/gui/gui.c * app/gui/menus.c * app/widgets/Makefile.am * app/widgets/widgets-types.h: changed accordingly. * app/display/gimpprogress.c: added more spacing and removed the separator (more HIG compliant). * plug-ins/[most plug-ins].c: Changed lots of messages and progress strings: - Removed plug-in names from messages since that's automatically covered by "domain" now. - Put all filenames in ''. - Changed "Loading" to "Opening". - Added "..." to all progress messages. - Cleaned up all file open/save error messages to look the same and include g_strerror(errno). - Removed special casing for progress bars and *always* show them, not only if run_mode != GIMP_RUN_NONINTERACTIVE (we can't expect all plug-ins to do this correctly but need to hack the core to sort out unwanted progress bars). Unrelated: - Cleaned up indentation, spacing, #includes, coding style and other stuff while I was at all these files.
2003-06-13 14:37:00 +00:00
*return_vals = values;
1999-08-26 22:29:37 +00:00
INIT_I18N ();
1999-08-26 22:29:37 +00:00
/* Get the active drawable info */
Cleaned up and improved the message system: 2003-06-13 Michael Natterer <mitch@gimp.org> Cleaned up and improved the message system: * app/core/gimp.[ch]: added "const gchar *domain" to GimpMessageFunc (a NULL domain means the message is from the GIMP core, everything else is a plug-in). * app/errors.c: pass "domain == NULL" to gimp_message(). * tools/pdbgen/pdb/message.pdb: derive the message domain from the current plug-in's menu_path (evil hack but works reasonably well). * app/pdb/message_cmds.c: regenerated. * app/widgets/gimpwidgets-utils.[ch] (gimp_message_box): added a header showing the message domain and changed the dialog layout to follow the HIG more closely. * app/gui/error-console-dialog.[ch]: removed. * app/widgets/gimperrorconsole.[ch] * app/gui/error-console-commands.[ch] * app/gui/error-console-menu.[ch]: new files containing a re-implementation of the error console dialog. * app/gui/Makefile.am * app/gui/dialogs-constructors.c * app/gui/gui.c * app/gui/menus.c * app/widgets/Makefile.am * app/widgets/widgets-types.h: changed accordingly. * app/display/gimpprogress.c: added more spacing and removed the separator (more HIG compliant). * plug-ins/[most plug-ins].c: Changed lots of messages and progress strings: - Removed plug-in names from messages since that's automatically covered by "domain" now. - Put all filenames in ''. - Changed "Loading" to "Opening". - Added "..." to all progress messages. - Cleaned up all file open/save error messages to look the same and include g_strerror(errno). - Removed special casing for progress bars and *always* show them, not only if run_mode != GIMP_RUN_NONINTERACTIVE (we can't expect all plug-ins to do this correctly but need to hack the core to sort out unwanted progress bars). Unrelated: - Cleaned up indentation, spacing, #includes, coding style and other stuff while I was at all these files.
2003-06-13 14:37:00 +00:00
drawable = gimp_drawable_get (param[2].data.d_drawable);
img_has_alpha = gimp_drawable_has_alpha (drawable->drawable_id);
1999-08-26 22:29:37 +00:00
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. */
if (! gimp_drawable_mask_intersect (drawable->drawable_id,
&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.");
gimp_drawable_detach (drawable);
return;
}
}
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:
case GIMP_RUN_WITH_LAST_VALS:
gimpressionist_get_data ();
if (run_mode == GIMP_RUN_INTERACTIVE)
{
if (!create_gimpressionist ())
return;
}
break;
default:
status = GIMP_PDB_EXECUTION_ERROR;
break;
}
if ((status == GIMP_PDB_SUCCESS) &&
(gimp_drawable_is_rgb (drawable->drawable_id) ||
gimp_drawable_is_gray (drawable->drawable_id)))
{
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;
}
1999-08-26 22:29:37 +00:00
/* Resources Cleanup */
g_rand_free (random_generator);
free_parsepath_cache ();
brush_reload (NULL, NULL);
preview_free_resources ();
brush_free ();
preset_free ();
orientation_map_free_resources ();
size_map_free_resources ();
1999-08-26 22:29:37 +00:00
values[0].data.d_status = status;
gimp_drawable_detach (drawable);
1999-08-26 22:29:37 +00:00
}
void
grabarea (void)
1999-08-26 22:29:37 +00:00
{
GimpPixelRgn src_rgn;
ppm_t *p;
gint x1, y1;
gint x, y;
gint width, height;
gint row, col;
gint rowstride;
gpointer pr;
1999-08-26 22:29:37 +00:00
if (! gimp_drawable_mask_intersect (drawable->drawable_id,
&x1, &y1, &width, &height))
return;
ppm_new (&infile, width, height);
1999-08-26 22:29:37 +00:00
p = &infile;
if (gimp_drawable_has_alpha (drawable->drawable_id))
ppm_new (&inalpha, width, height);
1999-08-26 22:29:37 +00:00
1999-08-29 21:06:26 +00:00
rowstride = p->width * 3;
gimp_pixel_rgn_init (&src_rgn,
drawable, x1, y1, width, height, FALSE, FALSE);
1999-08-26 22:29:37 +00:00
for (pr = gimp_pixel_rgns_register (1, &src_rgn);
pr != NULL;
pr = gimp_pixel_rgns_process (pr))
{
const guchar *src = src_rgn.data;
switch (src_rgn.bpp)
{
case 1:
for (y = 0, row = src_rgn.y - y1; y < src_rgn.h; y++, row++)
{
const guchar *s = src;
guchar *tmprow = p->col + row * rowstride;
for (x = 0, col = src_rgn.x - x1; x < src_rgn.w; x++, col++)
{
gint k = col * 3;
tmprow[k + 0] = s[0];
tmprow[k + 1] = s[0];
tmprow[k + 2] = s[0];
s++;
}
src += src_rgn.rowstride;
}
break;
case 2:
for (y = 0, row = src_rgn.y - y1; y < src_rgn.h; y++, row++)
{
const guchar *s = src;
guchar *tmprow = p->col + row * rowstride;
guchar *tmparow = inalpha.col + row * rowstride;
for (x = 0, col = src_rgn.x - x1; x < src_rgn.w; x++, col++)
{
gint k = col * 3;
tmprow[k + 0] = s[0];
tmprow[k + 1] = s[0];
tmprow[k + 2] = s[0];
tmparow[k] = 255 - s[1];
s += 2;
}
src += src_rgn.rowstride;
}
break;
case 3:
col = src_rgn.x - x1;
for (y = 0, row = src_rgn.y - y1; y < src_rgn.h; y++, row++)
{
memcpy (p->col + row * rowstride + col * 3, src, src_rgn.w * 3);
src += src_rgn.rowstride;
}
break;
case 4:
for (y = 0, row = src_rgn.y - y1; y < src_rgn.h; y++, row++)
{
const guchar *s = src;
guchar *tmprow = p->col + row * rowstride;
guchar *tmparow = inalpha.col + row * rowstride;
for (x = 0, col = src_rgn.x - x1; x < src_rgn.w; x++, col++)
{
gint k = col * 3;
tmprow[k + 0] = s[0];
tmprow[k + 1] = s[1];
tmprow[k + 2] = s[2];
tmparow[k] = 255 - s[3];
s += 4;
}
src += src_rgn.rowstride;
}
break;
}
1999-08-26 22:29:37 +00:00
}
}
static void
gimpressionist_main (void)
1999-08-26 22:29:37 +00:00
{
GimpPixelRgn dest_rgn;
ppm_t *p;
gint x1, y1;
gint x, y;
gint width, height;
gint row, col;
gint rowstride;
gint count;
glong done;
glong total;
gpointer pr;
1999-08-26 22:29:37 +00:00
if (! gimp_drawable_mask_intersect (drawable->drawable_id,
&x1, &y1, &width, &height))
return;
total = width * height;
1999-08-26 22:29:37 +00:00
gimp_progress_init (_("Painting"));
1999-08-26 22:29:37 +00:00
if (! PPM_IS_INITED (&infile))
grabarea ();
1999-08-26 22:29:37 +00:00
repaint (&infile, (img_has_alpha) ? &inalpha : NULL);
1999-08-26 22:29:37 +00:00
p = &infile;
1999-08-29 21:06:26 +00:00
rowstride = p->width * 3;
gimp_pixel_rgn_init (&dest_rgn,
drawable, x1, y1, width, height, TRUE, TRUE);
for (pr = gimp_pixel_rgns_register (1, &dest_rgn), count = 0, done = 0;
pr != NULL;
pr = gimp_pixel_rgns_process (pr), count++)
{
guchar *dest = dest_rgn.data;
1999-08-26 22:29:37 +00:00
switch (dest_rgn.bpp)
{
case 1:
for (y = 0, row = dest_rgn.y - y1; y < dest_rgn.h; y++, row++)
{
guchar *d = dest;
const guchar *tmprow = p->col + row * rowstride;
1999-08-26 22:29:37 +00:00
for (x = 0, col = dest_rgn.x - x1; x < dest_rgn.w; x++, col++)
{
gint k = col * 3;
*d++ = GIMP_RGB_LUMINANCE (tmprow[k + 0],
tmprow[k + 1],
tmprow[k + 2]);
}
dest += dest_rgn.rowstride;
}
break;
case 2:
for (y = 0, row = dest_rgn.y - y1; y < dest_rgn.h; y++, row++)
{
guchar *d = dest;
const guchar *tmprow = p->col + row * rowstride;
const guchar *tmparow = inalpha.col + row * rowstride;
for (x = 0, col = dest_rgn.x - x1; x < dest_rgn.w; x++, col++)
{
gint k = col * 3;
gint value = GIMP_RGB_LUMINANCE (tmprow[k + 0],
tmprow[k + 1],
tmprow[k + 2]);
d[0] = value;
d[1] = 255 - tmparow[k];
d += 2;
}
dest += dest_rgn.rowstride;
}
break;
1999-08-26 22:29:37 +00:00
case 3:
col = dest_rgn.x - x1;
for (y = 0, row = dest_rgn.y - y1; y < dest_rgn.h; y++, row++)
{
memcpy (dest, p->col + row * rowstride + col * 3, dest_rgn.w * 3);
dest += dest_rgn.rowstride;
}
break;
1999-08-26 22:29:37 +00:00
case 4:
for (y = 0, row = dest_rgn.y - y1; y < dest_rgn.h; y++, row++)
{
guchar *d = dest;
const guchar *tmprow = p->col + row * rowstride;
const guchar *tmparow = inalpha.col + row * rowstride;
for (x = 0, col = dest_rgn.x - x1; x < dest_rgn.w; x++, col++)
{
gint k = col * 3;
d[0] = tmprow[k + 0];
d[1] = tmprow[k + 1];
d[2] = tmprow[k + 2];
d[3] = 255 - tmparow[k];
d += 4;
}
dest += dest_rgn.rowstride;
}
break;
}
1999-08-26 22:29:37 +00:00
done += dest_rgn.w * dest_rgn.h;
if (count % 16 == 0)
gimp_progress_update (0.8 + 0.2 * done / total);
}
1999-08-26 22:29:37 +00:00
gimp_progress_update (1.0);
1999-08-26 22:29:37 +00:00
gimp_drawable_flush (drawable);
gimp_drawable_merge_shadow (drawable->drawable_id, TRUE);
gimp_drawable_update (drawable->drawable_id, x1, y1, width, height);
1999-08-26 22:29:37 +00:00
}