Commit 9d19bf2a authored by Michael Natterer's avatar Michael Natterer 😴 Committed by Michael Natterer

plug-ins/gimpressionist/Makefile.am applied patch from Shlomi Fish that

2004-07-02  Michael Natterer  <mitch@gimp.org>

	* plug-ins/gimpressionist/Makefile.am
	* plug-ins/gimpressionist/*.[ch]: applied patch from Shlomi Fish
	that massively cleans up gimppressionist (touching all files and
	addding some new ones) and adds a simple PDB interface for
	selecting one of the previously created presets.
	Fixes bugs #145191, #144913 and #144922.
parent ccff34dc
2004-07-02 Michael Natterer <mitch@gimp.org>
* plug-ins/gimpressionist/Makefile.am
* plug-ins/gimpressionist/*.[ch]: applied patch from Shlomi Fish
that massively cleans up gimppressionist (touching all files and
addding some new ones) and adds a simple PDB interface for
selecting one of the previously created presets.
Fixes bugs #145191, #144913 and #144922.
2004-07-01 Sven Neumann <sven@gimp.org>
* configure.in: bumped version number to 2.1.2.
......
......@@ -28,23 +28,29 @@ libexec_PROGRAMS = gimpressionist
gimpressionist_sources = \
brush.c \
color.h \
color.c \
general.h \
general.c \
gimp.c \
gimpressionist.c \
gimpressionist.h \
globals.c \
orientation.c \
orientmap.c \
paper.c \
placement.h \
placement.c \
plasma.c \
ppmtool.c \
ppmtool.h \
presets.c \
preview.h \
preview.c \
repaint.c \
size.c \
sizemap.c
sizemap.c \
utils.c
gimpressionist_built_sources = logo-pixbuf.h
gimpressionist.c: logo-pixbuf.h
......
......@@ -28,24 +28,41 @@
#include <libgimp/stdplugins-intl.h>
GtkWidget *brushlist = NULL;
GtkObject *brushreliefadjust = NULL;
GtkObject *brushaspectadjust = NULL;
GtkObject *brushgammaadjust = NULL;
gint brushfile = 2;
ppm_t brushppm = {0, 0, NULL};
static GtkWidget *brushprev = NULL;
static GtkListStore *brushstore = NULL;
static GtkWidget *brushlist = NULL;
static GtkObject *brushreliefadjust = NULL;
static GtkObject *brushaspectadjust = NULL;
static GtkObject *brushgammaadjust = NULL;
void brush_restore(void)
{
reselect (brushlist, pcvals.selectedbrush);
gtk_adjustment_set_value (GTK_ADJUSTMENT(brushgammaadjust), pcvals.brushgamma);
gtk_adjustment_set_value (GTK_ADJUSTMENT(brushreliefadjust), pcvals.brushrelief);
gtk_adjustment_set_value (GTK_ADJUSTMENT(brushaspectadjust), pcvals.brushaspect);
}
void brush_store(void)
{
pcvals.brushgamma = GTK_ADJUSTMENT(brushgammaadjust)->value;
}
static void updatebrushprev (const char *fn);
static gboolean colorfile (const char *fn)
static gboolean file_is_color (const char *fn)
{
return fn && strstr(fn, ".ppm");
}
void set_colorbrushes (const gchar *fn)
{
pcvals.colorbrushes = file_is_color(fn);
}
static void
brushdmenuselect (GtkWidget *widget,
gpointer data)
......@@ -58,7 +75,7 @@ brushdmenuselect (GtkWidget *widget,
gint x, y;
ppm_t *p;
gint x1, y1, x2, y2;
gint row, col;
gint row;
GimpDrawable *drawable;
gint rowstride;
......@@ -72,7 +89,9 @@ brushdmenuselect (GtkWidget *widget,
if (brushfile)
{
/* unselectall(brushlist); */
#if 0
unselectall(brushlist);
#endif
if (GTK_IS_WIDGET (presetsavebutton))
gtk_widget_set_sensitive (GTK_WIDGET (presetsavebutton), FALSE);
}
......@@ -105,43 +124,23 @@ brushdmenuselect (GtkWidget *widget,
gimp_pixel_rgn_get_row (&src_rgn, src_row, x1, y, (x2 - x1));
memcpy(p->col + row*rowstride, src_row, bpr);
}
} else if(bpp > 3) { /* RGBA */
} else { /* RGBA (bpp > 3) GrayA (bpp == 2) or Gray */
gboolean is_gray = ((bpp > 3) ? TRUE : FALSE);
for(row = 0, y = y1; y < y2; row++, y++) {
guchar *tmprow = p->col + row * rowstride;
guchar *tmprow_ptr;
gimp_pixel_rgn_get_row (&src_rgn, src_row, x1, y, (x2 - x1));
src = src_row;
for (col = 0, x = x1; x < x2; col++, x++) {
int k = col * 3;
tmprow[k+0] = src[0];
tmprow[k+1] = src[1];
tmprow[k+2] = src[2];
src += src_rgn.bpp;
}
}
} else if(bpp == 2) { /* GrayA */
for(row = 0, y = y1; y < y2; row++, y++) {
guchar *tmprow = p->col + row * rowstride;
gimp_pixel_rgn_get_row (&src_rgn, src_row, x1, y, (x2 - x1));
src = src_row;
for (col = 0, x = x1; x < x2; col++, x++) {
int k = col * 3;
tmprow[k+0] = src[0];
tmprow[k+1] = src[0];
tmprow[k+2] = src[0];
src += src_rgn.bpp;
}
}
} else { /* Gray */
for(row = 0, y = y1; y < y2; row++, y++) {
guchar *tmprow = p->col + row * rowstride;
gimp_pixel_rgn_get_row (&src_rgn, src_row, x1, y, (x2 - x1));
src = src_row;
for (col = 0, x = x1; x < x2; col++, x++) {
int k = col * 3;
tmprow[k+0] = src[0];
tmprow[k+1] = src[0];
tmprow[k+2] = src[0];
src += src_rgn.bpp;
tmprow_ptr = tmprow;
/* Possible micro-optimization here:
* src_end = src + src_rgn.bpp * (x2-x1);
* for( ; src < src_end ; src += src_rgn.bpp)
* */
for (x = x1; x < x2; x++) {
*(tmprow_ptr++) = src[0];
*(tmprow_ptr++) = src[is_gray ? 1 : 0];
*(tmprow_ptr++) = src[is_gray ? 2 : 0];
src += src_rgn.bpp;
}
}
}
......@@ -154,6 +153,7 @@ brushdmenuselect (GtkWidget *widget,
updatebrushprev(NULL);
}
#if 0
void dummybrushdmenuselect(GtkWidget *w, gpointer data)
{
if(brushppm.col)
......@@ -162,6 +162,7 @@ void dummybrushdmenuselect(GtkWidget *w, gpointer data)
brushfile = 0;
updatebrushprev(NULL);
}
#endif
static void
brushlistrefresh (void)
......@@ -237,6 +238,10 @@ validdrawable (gint32 imageid,
gimp_drawable_is_gray (drawableid));
}
/*
* This function caches the last result. Call it with fn as NULL, to
* free the arguments.
* */
void
reloadbrush (const gchar *fn,
ppm_t *p)
......@@ -244,13 +249,21 @@ reloadbrush (const gchar *fn,
static char lastfn[256] = "";
static ppm_t cache = {0,0,NULL};
if (fn == NULL)
{
killppm(&cache);
lastfn[0] = '\0';
return;
}
if (strcmp(fn, lastfn))
{
g_strlcpy (lastfn, fn, sizeof (lastfn));
killppm(&cache);
loadppm (fn, &cache);
}
copyppm(&cache, p);
pcvals.colorbrushes = colorfile(fn);
set_colorbrushes(fn);
}
static void
......@@ -263,7 +276,7 @@ padbrush (ppm_t *p,
int right = (width - p->width) - left;
int top = (height - p->height) / 2;
int bottom = (height - p->height) - top;
pad(p, left, right, top, bottom, black);
ppm_pad(p, left, right, top, bottom, black);
}
static void
......@@ -291,7 +304,7 @@ updatebrushprev (const gchar *fn)
else if(brushppm.col)
copyppm(&brushppm, &p);
pcvals.colorbrushes = colorfile(fn);
set_colorbrushes(fn);
sc = GTK_ADJUSTMENT(brushgammaadjust)->value;
if(sc != 1.0)
......
......@@ -10,6 +10,7 @@
#include <libgimp/gimpui.h>
#include "gimpressionist.h"
#include "color.h"
#include "libgimp/stdplugins-intl.h"
......@@ -17,12 +18,14 @@
#define NUMCOLORRADIO 2
static GtkWidget *colorradio[NUMCOLORRADIO];
GtkObject *colornoiseadjust = NULL;
void colorchange(int num)
void color_type_restore(void)
{
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(colorradio[num]), TRUE);
gtk_toggle_button_set_active (
GTK_TOGGLE_BUTTON(colorradio[pcvals.colortype]),
TRUE
);
}
void create_colorpage(GtkNotebook *notebook)
......@@ -42,24 +45,23 @@ void create_colorpage(GtkNotebook *notebook)
&pcvals.colortype, 0,
_("A_verage under brush"),
0, &colorradio[0],
COLOR_TYPE_AVERAGE, &colorradio[COLOR_TYPE_AVERAGE],
_("C_enter of brush"),
1, &colorradio[1],
COLOR_TYPE_CENTER, &colorradio[COLOR_TYPE_CENTER],
NULL);
gimp_help_set_help_data
(colorradio[0],
(colorradio[COLOR_TYPE_AVERAGE],
_("Color is computed from the average of all pixels under the brush"),
NULL);
gimp_help_set_help_data
(colorradio[1],
(colorradio[COLOR_TYPE_CENTER],
_("Samples the color from the pixel in the center of the brush"), NULL);
gtk_box_pack_start(GTK_BOX (vbox), frame, FALSE, FALSE, 0);
gtk_widget_show(frame);
gtk_toggle_button_set_active
(GTK_TOGGLE_BUTTON (colorradio[pcvals.colortype]), TRUE);
color_type_restore();
table = gtk_table_new (1, 3, FALSE);
gtk_table_set_col_spacings (GTK_TABLE (table), 6);
......@@ -74,7 +76,7 @@ void create_colorpage(GtkNotebook *notebook)
TRUE, 0, 0,
_("Adds random noise to the color"),
NULL);
g_signal_connect (brushdensityadjust, "value_changed",
g_signal_connect (colornoiseadjust, "value_changed",
G_CALLBACK (gimp_double_adjustment_update),
&pcvals.colornoise);
......
#ifndef __COLOR_H
#define __COLOR_H
enum COLOR_TYPE_ENUM
{
COLOR_TYPE_AVERAGE = 0,
COLOR_TYPE_CENTER = 1,
};
void color_type_restore(void);
#endif /* #ifndef __COLOR_H */
......@@ -13,46 +13,82 @@
#define COLORBUTTONWIDTH 30
#define COLORBUTTONHEIGHT 20
GtkObject *generaldarkedgeadjust = NULL;
GtkWidget *generalpaintedges = NULL;
GtkWidget *generaltileable = NULL;
GtkWidget *generaldropshadow = NULL;
GtkWidget *generalcolbutton;
GtkObject *generalshadowadjust = NULL;
GtkObject *generalshadowdepth = NULL;
GtkObject *generalshadowblur = NULL;
GtkObject *devthreshadjust = NULL;
#define NUMGENERALBGRADIO 4
static GtkWidget *generalbgradio[NUMGENERALBGRADIO];
static GtkWidget *generalpaintedges = NULL;
static GtkObject *generaldarkedgeadjust = NULL;
static GtkWidget *generaltileable;
static GtkWidget *generaldropshadow = NULL;
static GtkWidget *generalcolbutton;
static GtkObject *generalshadowadjust = NULL;
static GtkObject *generalshadowdepth = NULL;
static GtkObject *generalshadowblur = NULL;
static int normalize_bg(int n)
{
return (!img_has_alpha && (n == 3)) ? 1 : n;
}
static void general_bg_store(GtkWidget *wg, void *d)
{
pcvals.generalbgtype = normalize_bg (GPOINTER_TO_INT (d));
}
void general_store(void)
{
pcvals.generalpaintedges = GTK_TOGGLE_BUTTON(generalpaintedges)->active;
pcvals.generaldarkedge = GTK_ADJUSTMENT(generaldarkedgeadjust)->value;
pcvals.generaltileable = GTK_TOGGLE_BUTTON(generaltileable)->active;
pcvals.generaldropshadow = GTK_TOGGLE_BUTTON(generaldropshadow)->active;
pcvals.generalshadowdarkness = GTK_ADJUSTMENT(generalshadowadjust)->value;
pcvals.generalshadowdepth = GTK_ADJUSTMENT(generalshadowdepth)->value;
pcvals.generalshadowblur = GTK_ADJUSTMENT(generalshadowblur)->value;
}
void generalbgchange(GtkWidget *wg, void *d, int num)
void general_restore(void)
{
int n;
if(wg) {
n = GPOINTER_TO_INT (d);
if(!img_has_alpha && (n == 3))
n = 1;
pcvals.generalbgtype = n;
} else {
n = num;
if(!img_has_alpha && (n == 3))
n = 1;
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(generalbgradio[n]), TRUE);
}
gtk_toggle_button_set_active (
GTK_TOGGLE_BUTTON (
generalbgradio[normalize_bg (pcvals.generalbgtype)]
),
TRUE
);
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(generalpaintedges), pcvals.generalpaintedges);
gtk_adjustment_set_value(GTK_ADJUSTMENT(generaldarkedgeadjust), pcvals.generaldarkedge);
gtk_adjustment_set_value(GTK_ADJUSTMENT(generalshadowadjust), pcvals.generalshadowdarkness);
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(generaldropshadow), pcvals.generaldropshadow);
gtk_adjustment_set_value(GTK_ADJUSTMENT(generalshadowdepth), pcvals.generalshadowdepth);
gtk_adjustment_set_value(GTK_ADJUSTMENT(generalshadowblur), pcvals.generalshadowblur);
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(generaltileable), pcvals.generaltileable);
gimp_color_button_set_color (GIMP_COLOR_BUTTON(generalcolbutton),
&pcvals.color);
}
static void selectcolor(GtkWidget *widget, gpointer data)
{
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(generalbgradio[0]), TRUE);
gtk_toggle_button_set_active (
GTK_TOGGLE_BUTTON(generalbgradio[BG_TYPE_SOLID]),
TRUE
);
}
static GtkWidget *create_general_button (GtkWidget *box, int idx,
gchar *label, gchar *help_string,
GSList **radio_group
)
{
return create_radio_button (box, idx, general_bg_store, label,
help_string, radio_group, generalbgradio);
}
void create_generalpage(GtkNotebook *notebook)
{
GtkWidget *box1, *box2, *box3, *box4, *thispage;
GtkWidget *label, *tmpw, *frame, *table;
GSList * radio_group = NULL;
label = gtk_label_new_with_mnemonic (_("_General"));
......@@ -68,34 +104,25 @@ void create_generalpage(GtkNotebook *notebook)
gtk_container_add (GTK_CONTAINER(frame), box3);
gtk_widget_show (box3);
generalbgradio[1] = tmpw = gtk_radio_button_new_with_label(NULL,
_("Keep original"));
gtk_widget_show(tmpw);
gtk_box_pack_start(GTK_BOX (box3), tmpw, FALSE, FALSE, 0);
g_signal_connect(tmpw, "clicked",
G_CALLBACK (generalbgchange), GINT_TO_POINTER (1));
gimp_help_set_help_data
(tmpw, _("Preserve the original image as a background"), NULL);
create_general_button(box3, BG_TYPE_KEEP_ORIGINAL, _("Keep original"),
_("Preserve the original image as a background"),
&radio_group
);
generalbgradio[2] = tmpw = gtk_radio_button_new_with_label(gtk_radio_button_get_group(GTK_RADIO_BUTTON(tmpw)), _("From paper"));
gtk_box_pack_start(GTK_BOX(box3), tmpw, FALSE, FALSE, 0);
gtk_widget_show(tmpw);
g_signal_connect(tmpw, "clicked",
G_CALLBACK (generalbgchange), GINT_TO_POINTER (2));
gimp_help_set_help_data
(tmpw, _("Copy the texture of the selected paper as a background"), NULL);
create_general_button(box3, BG_TYPE_FROM_PAPER, _("From paper"),
_("Copy the texture of the selected paper as a background"),
&radio_group
);
box4 = gtk_hbox_new (FALSE, 6);
gtk_box_pack_start(GTK_BOX(box3), box4, FALSE, FALSE, 0);
gtk_widget_show(box4);
generalbgradio[0] = tmpw = gtk_radio_button_new_with_label(gtk_radio_button_get_group(GTK_RADIO_BUTTON(tmpw)), _("Solid"));
gtk_box_pack_start(GTK_BOX(box4), tmpw, FALSE, FALSE, 0);
gtk_widget_show(tmpw);
g_signal_connect(tmpw, "clicked",
G_CALLBACK (generalbgchange), GINT_TO_POINTER (0));
gimp_help_set_help_data
(tmpw, _("Solid colored background"), NULL);
create_general_button(box4, BG_TYPE_SOLID, _("Solid"),
_("Solid colored background"),
&radio_group
);
generalcolbutton = gimp_color_button_new (_("Color"),
COLORBUTTONWIDTH,
......@@ -110,13 +137,12 @@ void create_generalpage(GtkNotebook *notebook)
gtk_box_pack_start(GTK_BOX(box4), generalcolbutton, FALSE, FALSE, 0);
gtk_widget_show (generalcolbutton);
generalbgradio[3] = tmpw = gtk_radio_button_new_with_label(gtk_radio_button_get_group(GTK_RADIO_BUTTON(generalbgradio[0])), _("Transparent"));
gtk_box_pack_start(GTK_BOX(box3), tmpw, FALSE, FALSE, 0);
gtk_widget_show(tmpw);
g_signal_connect(tmpw, "clicked",
G_CALLBACK (generalbgchange), GINT_TO_POINTER (3));
gimp_help_set_help_data
(tmpw, _("Use a transparent background; Only the strokes painted will be visible"), NULL);
tmpw =
create_general_button(box3, BG_TYPE_TRANSPARENT, _("Transparent"),
_("Use a transparent background; Only the strokes painted will be visible"),
&radio_group
);
if(!img_has_alpha)
gtk_widget_set_sensitive (tmpw, FALSE);
......
#ifndef __GENERAL_H
#define __GENERAL_H
void general_restore(void);
void general_store(void);
#endif /* #ifndef __GENERAL_H */
......@@ -11,6 +11,7 @@
#include "ppmtool.h"
#include "gimpressionist.h"
#include "preview.h"
#include "libgimp/stdplugins-intl.h"
......@@ -22,10 +23,6 @@ static void run (const gchar *name,
GimpParam **return_vals);
static void gimpressionist_main (void);
void repaint (ppm_t *p, ppm_t *a);
int create_gimpressionist (void);
gboolean img_has_alpha = FALSE;
GimpPlugInInfo PLUG_IN_INFO = {
NULL, /* init_proc */
......@@ -34,57 +31,6 @@ GimpPlugInInfo PLUG_IN_INFO = {
run /* run_proc */
}; /* PLUG_IN_INFO */
gimpressionist_vals_t pcvals;
gimpressionist_vals_t defaultpcvals = {
4,
0.0,
60.0,
0,
12.0,
20.0,
20.0,
1.0,
1,
0.1,
0.0,
30.0,
0,
0,
"defaultbrush.pgm",
"defaultpaper.pgm",
{0,0,0,1.0},
1,
0,
{ { 0.5, 0.5, 0.0, 0.0, 1.0, 1.0, 0 } },
1,
0,
0.0,
0.0,
1.0,
0,
0,
0,
0,
0,
20.0,
1,
10.0,
20.0,
0,
0.1,
{ { 0.5, 0.5, 50.0, 1.0 } },
1,
1.0,
0,
10,
4,
0, 0.0
};
static GimpDrawable *drawable;
MAIN()
......@@ -97,6 +43,7 @@ query(void)
{ 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,
......@@ -116,10 +63,10 @@ query(void)
}
static void
gimpressionist_get_data (char *name, gpointer ptr)
gimpressionist_get_data (void)
{
pcvals = defaultpcvals;
gimp_get_data (name, ptr);
restore_default_values();
gimp_get_data (PLUG_IN_NAME, &pcvals);
}
static void
......@@ -132,9 +79,21 @@ run (const gchar *name,
static GimpParam values[1];
GimpRunMode run_mode;
GimpPDBStatusType status;
gboolean with_specified_preset;
gchar *preset_name;
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;
......@@ -153,17 +112,20 @@ run (const gchar *name,
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:
gimpressionist_get_data(PLUG_IN_NAME, &pcvals);
if(!create_gimpressionist())
return;
break;
case GIMP_RUN_NONINTERACTIVE:
g_message ("GIMP_RUN_NONINTERACTIVE not implemented yet!");
status = GIMP_PDB_EXECUTION_ERROR;
break;
case GIMP_RUN_WITH_LAST_VALS:
gimpressionist_get_data(PLUG_IN_NAME, &pcvals);
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;
......@@ -173,18 +135,49 @@ run (const gchar *name,
(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(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_NAME, &pcvals, sizeof(gimpressionist_vals_t));
}
}
else if (status == GIMP_PDB_SUCCESS)
{
status = GIMP_PDB_EXECUTION_ERROR;
}
/* Resources Cleanup */
g_rand_free (gr);
free_parsepath_cache();
reloadbrush(NULL, NULL);
preview_free_resources();
values[0].data.d_status = status;
......
......@@ -12,6 +12,15 @@
#include <libgimp/gimpui.h>
#include "gimpressionist.h"
/*
* The Page Specific Imports
* */
#include "color.h"
#include "general.h"
#include "placement.h"
#include "preview.h"
#include "size.h"
#include "ppmtool.h"