preliminary cleanup before implementing a preview.

* plug-ins/common/convmatrix.c: preliminary cleanup before
  implementing a preview.
This commit is contained in:
David Odin 2005-04-10 20:48:00 +00:00
parent ada9dc2ae5
commit e876b395ba
2 changed files with 252 additions and 243 deletions

View File

@ -1,3 +1,8 @@
2005-04-10 DindinX <dindinx@gimp.org>
* plug-ins/common/convmatrix.c: preliminary cleanup before
implementing a preview.
2005-04-10 Sven Neumann <sven@gimp.org>
* app/actions/drawable-commands.h: removed duplicate function

View File

@ -72,8 +72,6 @@ typedef enum
MIRROR
} BorderMode;
static GimpDrawable *drawable;
static gchar * const channel_labels[] =
{
N_("Gr_ey"),
@ -98,11 +96,15 @@ static void run (const gchar *name,
gint *nreturn_vals,
GimpParam **return_vals);
static gboolean dialog (void);
static gboolean convmatrix_dialog (GimpDrawable *drawable);
static void convmatrix (void);
static void check_config (void);
static void convmatrix (GimpDrawable *drawable);
static void check_config (GimpDrawable *drawable);
static gfloat calcmatrix (guchar **srcrow,
gint xoff,
gint i,
GimpDrawable *drawable);
GimpPlugInInfo PLUG_IN_INFO =
{
@ -112,7 +114,6 @@ GimpPlugInInfo PLUG_IN_INFO =
run, /* run_proc */
};
static gint bytes;
static gboolean run_flag = FALSE;
typedef struct
@ -123,7 +124,7 @@ typedef struct
gint alpha_alg;
BorderMode bmode;
gint channels[5];
gint autoset;
gboolean autoset;
} config;
static const config default_config =
@ -140,7 +141,7 @@ static const config default_config =
1, /* Alpha-handling algorithm */
CLEAR, /* border-mode */
{ 1, 1, 1, 1, 1 }, /* Channels mask */
0 /* autoset */
FALSE /* autoset */
};
static config my_config;
@ -204,6 +205,7 @@ run (const gchar *name,
GimpRunMode run_mode;
GimpPDBStatusType status = GIMP_PDB_SUCCESS;
gint x, y;
GimpDrawable *drawable;
INIT_I18N ();
@ -263,7 +265,7 @@ run (const gchar *name,
my_config.bmode = param[10].data.d_int32;
check_config ();
check_config (drawable);
}
}
else
@ -275,9 +277,9 @@ run (const gchar *name,
/* Oh boy. We get to do a dialog box, because we can't really
* expect the user to set us up with the right values using gdb.
*/
check_config ();
check_config (drawable);
if (! dialog ())
if (! convmatrix_dialog (drawable))
{
/* The dialog was closed, or something similarly evil happened. */
status = GIMP_PDB_EXECUTION_ERROR;
@ -294,8 +296,7 @@ run (const gchar *name,
gimp_progress_init (_("Applying convolution"));
gimp_tile_cache_ntiles (2 * (drawable->width /
gimp_tile_width () + 1));
convmatrix ();
convmatrix (drawable);
if (run_mode != GIMP_RUN_NONINTERACTIVE)
gimp_displays_flush ();
@ -457,7 +458,8 @@ my_get_row (GimpPixelRgn *PR,
static gfloat
calcmatrix (guchar **srcrow,
gint xoff,
gint i)
gint i,
GimpDrawable *drawable)
{
static gfloat matrixsum = 0;
static gint bytes = 0;
@ -504,7 +506,7 @@ calcmatrix (guchar **srcrow,
}
static void
convmatrix (void)
convmatrix (GimpDrawable *drawable)
{
GimpPixelRgn srcPR, destPR;
gint width, height, row, col;
@ -517,6 +519,7 @@ convmatrix (void)
gfloat sum;
gint xoff;
gint chanmask[4];
gint bytes;
/* Get the input area. This is the bounding box of the selection in
* the image (or the entire image if there is no selection). Only
@ -572,7 +575,7 @@ convmatrix (void)
if (chanmask[i] <= 0)
sum = srcrow[2][xoff + 2 * bytes];
else
sum = calcmatrix(srcrow, xoff, i);
sum = calcmatrix(srcrow, xoff, i, drawable);
destrow[2][xoff]= (guchar) CLAMP (sum, 0, 255);
xoff++;
@ -625,7 +628,8 @@ fprint (gfloat f,
g_snprintf (buffer, len, "%.7f", f);
buffer[len - 1] = '\0';
for (t = 0; t < len - 1 && buffer[t] != '.'; t++);
for (t = 0; t < len - 1 && buffer[t] != '.'; t++)
;
i = t + 1;
@ -751,13 +755,13 @@ check_matrix (void)
static void
response_callback (GtkWidget *widget,
gint response_id,
gpointer data)
GimpDrawable *drawable)
{
switch (response_id)
{
case RESPONSE_RESET:
my_config = default_config;
check_config ();
check_config (drawable);
redraw_all ();
break;
@ -772,7 +776,7 @@ response_callback (GtkWidget *widget,
/* Checks that the configuration is valid for the image type */
static void
check_config (void)
check_config (GimpDrawable *drawable)
{
gint i;
@ -849,9 +853,9 @@ my_bmode_callback (GtkWidget *widget,
}
static gboolean
dialog (void)
convmatrix_dialog (GimpDrawable *drawable)
{
GtkWidget *dlg;
GtkWidget *dialog;
GtkWidget *main_hbox;
GtkWidget *table;
GtkWidget *label;
@ -866,7 +870,7 @@ dialog (void)
gimp_ui_init ("convmatrix", FALSE);
dlg = gimp_dialog_new (_("Convolution Matrix"), "convmatrix",
dialog = gimp_dialog_new (_("Convolution Matrix"), "convmatrix",
NULL, 0,
gimp_standard_help_func, "plug-in-convmatrix",
@ -876,22 +880,15 @@ dialog (void)
NULL);
gtk_dialog_set_alternative_button_order (GTK_DIALOG (dlg),
gtk_dialog_set_alternative_button_order (GTK_DIALOG (dialog),
RESPONSE_RESET,
GTK_RESPONSE_OK,
GTK_RESPONSE_CANCEL,
-1);
g_signal_connect (dlg, "response",
G_CALLBACK (response_callback),
NULL);
g_signal_connect (dlg, "destroy",
G_CALLBACK (gtk_main_quit),
NULL);
main_hbox = gtk_hbox_new (FALSE, 12);
gtk_container_set_border_width (GTK_CONTAINER (main_hbox), 12);
gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dlg)->vbox), main_hbox,
gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog)->vbox), main_hbox,
TRUE, TRUE, 0);
vbox = gtk_vbox_new (FALSE, 12);
@ -1056,7 +1053,14 @@ dialog (void)
gtk_widget_show (main_hbox);
gtk_widget_show (dlg);
g_signal_connect (dialog, "response",
G_CALLBACK (response_callback),
drawable);
g_signal_connect (dialog, "destroy",
G_CALLBACK (gtk_main_quit),
NULL);
gtk_widget_show (dialog);
redraw_all ();
gtk_widget_set_sensitive (my_widgets.bmode[CLEAR],