Commit d5d99e5c authored by Michael Natterer's avatar Michael Natterer Committed by Michael Natterer

app/brightness_contrast.c app/by_color_select.c app/curves.c

1999-06-23  Michael Natterer  <mitschel@cs.tu-berlin.de>

	* app/brightness_contrast.c
	* app/by_color_select.c
	* app/curves.c
	* app/disp_callbacks.c
	* app/histogram_tool.c
	* app/hue_saturation.c
	* app/levels.c
	* app/posterize.c
	* app/threshold.c:

	Factored out the cleaning up code to the tool dialog's "cancel"
	callbacks because they are called from every function which is
	aborting the tool. This should fix the remaining segfaults.

	I probably killed a feature of "Levels". The tool wanted to
	preserve it's drawable all the time, so it was possible to select
	colors from other displays. If this was the intended behaviour,
	please flame me and I will try to set the "preserve" flag
	correctly.

	* plug-ins/common/Makefile.am: "struc" was in the Makefile but not
	in the directory.
parent ac73ea58
1999-06-23 Michael Natterer <mitschel@cs.tu-berlin.de>
* app/brightness_contrast.c
* app/by_color_select.c
* app/curves.c
* app/disp_callbacks.c
* app/histogram_tool.c
* app/hue_saturation.c
* app/levels.c
* app/posterize.c
* app/threshold.c:
Factored out the cleaning up code to the tool dialog's "cancel"
callbacks because they are called from every function which is
aborting the tool. This should fix the remaining segfaults.
I probably killed a feature of "Levels". The tool wanted to
preserve it's drawable all the time, so it was possible to select
colors from other displays. If this was the intended behaviour,
please flame me and I will try to set the "preserve" flag
correctly.
* plug-ins/common/Makefile.am: "struc" was in the Makefile but not
in the directory.
Wed Jun 23 02:00:23 PDT 1999 Manish Singh <yosh@gimp.org>
* plugin reorganization
......
......@@ -42,8 +42,9 @@
#define DRAW 0x10
#define ALL 0xFF
/* NB: take care when changing these values: make sure the curve[] array in
* curves.h is large enough. */
/* NB: take care when changing these values: make sure the curve[] array in
* curves.h is large enough.
*/
#define GRAPH_WIDTH 256
#define GRAPH_HEIGHT 256
#define XRANGE_WIDTH 256
......@@ -98,26 +99,27 @@ static void curves_motion (Tool *, GdkEventMotion *, gpointer);
static void curves_cursor_update (Tool *, GdkEventMotion *, gpointer);
static void curves_control (Tool *, ToolAction, gpointer);
static CurvesDialog * curves_new_dialog (void);
static void curves_update (CurvesDialog *, int);
static void curves_plot_curve (CurvesDialog *, int, int, int, int);
static void curves_preview (CurvesDialog *);
static void curves_value_callback (GtkWidget *, gpointer);
static void curves_red_callback (GtkWidget *, gpointer);
static void curves_green_callback (GtkWidget *, gpointer);
static void curves_blue_callback (GtkWidget *, gpointer);
static void curves_alpha_callback (GtkWidget *, gpointer);
static void curves_smooth_callback (GtkWidget *, gpointer);
static void curves_free_callback (GtkWidget *, gpointer);
static void curves_reset_callback (GtkWidget *, gpointer);
static void curves_ok_callback (GtkWidget *, gpointer);
static void curves_cancel_callback (GtkWidget *, gpointer);
static gint curves_delete_callback (GtkWidget *, GdkEvent *, gpointer);
static void curves_preview_update (GtkWidget *, gpointer);
static gint curves_xrange_events (GtkWidget *, GdkEvent *, CurvesDialog *);
static gint curves_yrange_events (GtkWidget *, GdkEvent *, CurvesDialog *);
static gint curves_graph_events (GtkWidget *, GdkEvent *, CurvesDialog *);
static void curves_CR_compose (CRMatrix, CRMatrix, CRMatrix);
static CurvesDialog * curves_new_dialog (void);
static void curves_update (CurvesDialog *, int);
static void curves_plot_curve (CurvesDialog *, int, int, int, int);
static void curves_preview (CurvesDialog *);
static void curves_value_callback (GtkWidget *, gpointer);
static void curves_red_callback (GtkWidget *, gpointer);
static void curves_green_callback (GtkWidget *, gpointer);
static void curves_blue_callback (GtkWidget *, gpointer);
static void curves_alpha_callback (GtkWidget *, gpointer);
static void curves_smooth_callback (GtkWidget *, gpointer);
static void curves_free_callback (GtkWidget *, gpointer);
static void curves_reset_callback (GtkWidget *, gpointer);
static void curves_ok_callback (GtkWidget *, gpointer);
static void curves_cancel_callback (GtkWidget *, gpointer);
static gint curves_delete_callback (GtkWidget *, GdkEvent *, gpointer);
static void curves_preview_update (GtkWidget *, gpointer);
static gint curves_xrange_events (GtkWidget *, GdkEvent *, CurvesDialog *);
static gint curves_yrange_events (GtkWidget *, GdkEvent *, CurvesDialog *);
static gint curves_graph_events (GtkWidget *, GdkEvent *, CurvesDialog *);
static void curves_CR_compose (CRMatrix, CRMatrix, CRMatrix);
/* curves machinery */
......@@ -338,27 +340,17 @@ curves_control (Tool *tool,
ToolAction action,
gpointer gdisp_ptr)
{
Curves * _curves;
_curves = (Curves *) tool->private;
switch (action)
{
case PAUSE :
case PAUSE:
break;
case RESUME :
case RESUME:
break;
case HALT :
case HALT:
if (curves_dialog)
{
active_tool->preserve = TRUE;
image_map_abort (curves_dialog->image_map);
active_tool->preserve = FALSE;
curves_dialog->image_map = NULL;
curves_cancel_callback (NULL, (gpointer) curves_dialog);
}
curves_cancel_callback (NULL, (gpointer) curves_dialog);
break;
default:
......@@ -395,9 +387,8 @@ tools_new_curves ()
tool->modifier_key_func = standard_modifier_key_func;
tool->cursor_update_func = curves_cursor_update;
tool->control_func = curves_control;
tool->preserve = TRUE;
tool->gdisp_ptr = NULL;
tool->drawable = NULL;
tool->preserve = FALSE;
return tool;
}
......@@ -416,14 +407,6 @@ tools_free_curves (Tool *tool)
g_free (_curves);
}
/* the action area structure */
static ActionAreaItem action_items[] =
{
{ N_("Reset"), curves_reset_callback, NULL, NULL },
{ N_("OK"), curves_ok_callback, NULL, NULL },
{ N_("Cancel"), curves_cancel_callback, NULL, NULL }
};
static MenuItem channel_items[] =
{
{ N_("Value"), 0, 0, curves_value_callback, NULL, NULL, NULL },
......@@ -434,13 +417,6 @@ static MenuItem channel_items[] =
{ NULL, 0, 0, NULL, NULL, NULL, NULL }
};
static MenuItem curve_type_items[] =
{
{ N_("Smooth"), 0, 0, curves_smooth_callback, NULL, NULL, NULL },
{ N_("Free"), 0, 0, curves_free_callback, NULL, NULL, NULL },
{ NULL, 0, 0, NULL, NULL, NULL, NULL }
};
void
curves_initialize (GDisplay *gdisp)
{
......@@ -514,10 +490,13 @@ curves_free ()
active_tool->preserve = TRUE;
image_map_abort (curves_dialog->image_map);
active_tool->preserve = FALSE;
curves_dialog->image_map = NULL;
}
if (curves_dialog->pixmap)
gdk_pixmap_unref (curves_dialog->pixmap);
gtk_widget_destroy (curves_dialog->shell);
}
}
......@@ -541,6 +520,20 @@ curves_new_dialog ()
GtkWidget *table;
int i, j;
static ActionAreaItem action_items[] =
{
{ N_("Reset"), curves_reset_callback, NULL, NULL },
{ N_("OK"), curves_ok_callback, NULL, NULL },
{ N_("Cancel"), curves_cancel_callback, NULL, NULL }
};
static MenuItem curve_type_items[] =
{
{ N_("Smooth"), 0, 0, curves_smooth_callback, NULL, NULL, NULL },
{ N_("Free"), 0, 0, curves_free_callback, NULL, NULL, NULL },
{ NULL, 0, 0, NULL, NULL, NULL, NULL }
};
cd = g_malloc (sizeof (CurvesDialog));
cd->preview = TRUE;
cd->curve_type = SMOOTH;
......@@ -1198,10 +1191,10 @@ curves_cancel_callback (GtkWidget *widget,
active_tool->preserve = TRUE;
image_map_abort (cd->image_map);
active_tool->preserve = FALSE;
cd->image_map = NULL;
gdisplays_flush ();
}
cd->image_map = NULL;
}
static gint
......
......@@ -270,10 +270,6 @@ hue_saturation_control (Tool *tool,
ToolAction action,
gpointer gdisp_ptr)
{
HueSaturation * color_bal;
color_bal = (HueSaturation *) tool->private;
switch (action)
{
case PAUSE:
......@@ -284,13 +280,7 @@ hue_saturation_control (Tool *tool,
case HALT:
if (hue_saturation_dialog)
{
active_tool->preserve = TRUE;
image_map_abort (hue_saturation_dialog->image_map);
active_tool->preserve = FALSE;
hue_saturation_dialog->image_map = NULL;
hue_saturation_cancel_callback (NULL, (gpointer) hue_saturation_dialog);
}
hue_saturation_cancel_callback (NULL, (gpointer) hue_saturation_dialog);
break;
default:
......@@ -394,9 +384,9 @@ hue_saturation_free ()
}
}
/****************************/
/* Select by Color dialog */
/****************************/
/***************************/
/* Hue-Saturation dialog */
/***************************/
static HueSaturationDialog *
hue_saturation_new_dialog ()
......@@ -421,7 +411,8 @@ hue_saturation_new_dialog ()
{ N_("OK"), hue_saturation_ok_callback, NULL, NULL },
{ N_("Cancel"), hue_saturation_cancel_callback, NULL, NULL }
};
char *hue_partition_names[7] =
char *hue_partition_names[] =
{
N_("Master"),
N_("R"),
......@@ -431,7 +422,8 @@ hue_saturation_new_dialog ()
N_("B"),
N_("M")
};
ActionCallback hue_partition_callbacks[7] =
ActionCallback hue_partition_callbacks[] =
{
hue_saturation_master_callback,
hue_saturation_R_callback,
......@@ -779,10 +771,10 @@ hue_saturation_cancel_callback (GtkWidget *widget,
active_tool->preserve = TRUE;
image_map_abort (hsd->image_map);
active_tool->preserve = FALSE;
hsd->image_map = NULL;
gdisplays_flush ();
}
hsd->image_map = NULL;
}
static void
......
......@@ -56,6 +56,7 @@ static void threshold_cursor_update (Tool *, GdkEventMotion *, gpointer);
static void threshold_control (Tool *, ToolAction, gpointer);
static ThresholdDialog * threshold_new_dialog (void);
static void threshold_preview (ThresholdDialog *);
static void threshold_ok_callback (GtkWidget *, gpointer);
static void threshold_cancel_callback (GtkWidget *, gpointer);
......@@ -198,10 +199,6 @@ threshold_control (Tool *tool,
ToolAction action,
gpointer gdisp_ptr)
{
Threshold * thresh;
thresh = (Threshold *) tool->private;
switch (action)
{
case PAUSE:
......@@ -212,13 +209,7 @@ threshold_control (Tool *tool,
case HALT:
if (threshold_dialog)
{
active_tool->preserve = TRUE;
image_map_abort (threshold_dialog->image_map);
active_tool->preserve = FALSE;
threshold_dialog->image_map = NULL;
threshold_cancel_callback (NULL, (gpointer) threshold_dialog);
}
threshold_cancel_callback (NULL, (gpointer) threshold_dialog);
break;
default:
......@@ -315,16 +306,9 @@ threshold_initialize (GDisplay *gdisp)
}
/****************************/
/* Select by Color dialog */
/****************************/
/* the action area structure */
static ActionAreaItem action_items[] =
{
{ N_("OK"), threshold_ok_callback, NULL, NULL },
{ N_("Cancel"), threshold_cancel_callback, NULL, NULL }
};
/**********************/
/* Threshold dialog */
/**********************/
static ThresholdDialog *
threshold_new_dialog ()
......@@ -336,6 +320,12 @@ threshold_new_dialog ()
GtkWidget *frame;
GtkWidget *toggle;
static ActionAreaItem action_items[] =
{
{ N_("OK"), threshold_ok_callback, NULL, NULL },
{ N_("Cancel"), threshold_cancel_callback, NULL, NULL }
};
td = g_malloc (sizeof (ThresholdDialog));
td->preview = TRUE;
td->low_threshold = 127;
......@@ -490,10 +480,10 @@ threshold_cancel_callback (GtkWidget *widget,
active_tool->preserve = TRUE;
image_map_abort (td->image_map);
active_tool->preserve = FALSE;
td->image_map = NULL;
gdisplays_flush ();
}
td->image_map = NULL;
}
static void
......
......@@ -88,7 +88,8 @@ static void brightness_contrast_motion (Tool *, GdkEventMotion *, gpoi
static void brightness_contrast_cursor_update (Tool *, GdkEventMotion *, gpointer);
static void brightness_contrast_control (Tool *, ToolAction, gpointer);
static BrightnessContrastDialog * brightness_contrast_new_dialog (void);
static BrightnessContrastDialog * brightness_contrast_new_dialog (void);
static void brightness_contrast_update (BrightnessContrastDialog *, int);
static void brightness_contrast_preview (BrightnessContrastDialog *);
static void brightness_contrast_ok_callback (GtkWidget *, gpointer);
......@@ -154,13 +155,7 @@ brightness_contrast_control (Tool *tool,
case HALT:
if (brightness_contrast_dialog)
{
active_tool->preserve = TRUE;
image_map_abort (brightness_contrast_dialog->image_map);
active_tool->preserve = TRUE;
brightness_contrast_dialog->image_map = NULL;
brightness_contrast_cancel_callback (NULL, (gpointer) brightness_contrast_dialog);
}
brightness_contrast_cancel_callback (NULL, (gpointer) brightness_contrast_dialog);
break;
default:
......@@ -252,13 +247,6 @@ brightness_contrast_initialize (GDisplay *gdisp)
/* Brightness Contrast dialog */
/********************************/
/* the action area structure */
static ActionAreaItem action_items[] =
{
{ N_("OK"), brightness_contrast_ok_callback, NULL, NULL },
{ N_("Cancel"), brightness_contrast_cancel_callback, NULL, NULL }
};
static BrightnessContrastDialog *
brightness_contrast_new_dialog ()
{
......@@ -271,6 +259,12 @@ brightness_contrast_new_dialog ()
GtkWidget *toggle;
GtkObject *data;
static ActionAreaItem action_items[] =
{
{ N_("OK"), brightness_contrast_ok_callback, NULL, NULL },
{ N_("Cancel"), brightness_contrast_cancel_callback, NULL, NULL }
};
bcd = g_malloc (sizeof (BrightnessContrastDialog));
bcd->preview = TRUE;
......@@ -487,10 +481,10 @@ brightness_contrast_cancel_callback (GtkWidget *widget,
active_tool->preserve = TRUE;
image_map_abort (bcd->image_map);
active_tool->preserve = FALSE;
bcd->image_map = NULL;
gdisplays_flush ();
}
bcd->image_map = NULL;
}
static void
......
......@@ -80,6 +80,7 @@ static void by_color_select_cursor_update (Tool *, GdkEventMotion *, gpointer);
static void by_color_select_control (Tool *, ToolAction, gpointer);
static ByColorDialog * by_color_select_new_dialog (void);
static void by_color_select_render (ByColorDialog *, GImage *);
static void by_color_select_draw (ByColorDialog *, GImage *);
static gint by_color_select_preview_events (GtkWidget *, GdkEventButton *,
......@@ -428,10 +429,6 @@ by_color_select_control (Tool *tool,
ToolAction action,
gpointer gdisp_ptr)
{
ByColorSelect * by_color_sel;
by_color_sel = (ByColorSelect *) tool->private;
switch (action)
{
case PAUSE :
......@@ -442,13 +439,7 @@ by_color_select_control (Tool *tool,
case HALT :
if (by_color_dialog)
{
if (by_color_dialog->gimage &&
gimp_set_have (image_context, by_color_dialog->gimage))
by_color_dialog->gimage->by_color_select = FALSE;
by_color_dialog->gimage = NULL;
by_color_select_close_callback (NULL, (gpointer) by_color_dialog);
}
by_color_select_close_callback (NULL, (gpointer) by_color_dialog);
break;
default:
......@@ -515,11 +506,7 @@ tools_free_by_color_select (Tool *tool)
/* Close the color select dialog */
if (by_color_dialog)
{
if (by_color_dialog->gimage)
by_color_dialog->gimage->by_color_select = FALSE;
by_color_select_close_callback (NULL, (gpointer) by_color_dialog);
}
by_color_select_close_callback (NULL, (gpointer) by_color_dialog);
g_free (by_color_sel);
}
......@@ -565,14 +552,16 @@ by_color_select_new_dialog ()
GtkObject *data;
GSList *group = NULL;
int i;
char *button_names[4] =
char *button_names[] =
{
N_("Replace"),
N_("Add"),
N_("Subtract"),
N_("Intersect")
};
int button_values[4] =
int button_values[] =
{
REPLACE,
ADD,
......@@ -898,6 +887,13 @@ by_color_select_close_callback (GtkWidget *widget,
bcd = (ByColorDialog *) client_data;
if (GTK_WIDGET_VISIBLE (bcd->shell))
gtk_widget_hide (bcd->shell);
if (bcd->gimage &&
gimp_set_have (image_context, bcd->gimage))
{
bcd->gimage->by_color_select = FALSE;
bcd->gimage = NULL;
}
}
static void
......
......@@ -42,8 +42,9 @@
#define DRAW 0x10
#define ALL 0xFF
/* NB: take care when changing these values: make sure the curve[] array in
* curves.h is large enough. */
/* NB: take care when changing these values: make sure the curve[] array in
* curves.h is large enough.
*/
#define GRAPH_WIDTH 256
#define GRAPH_HEIGHT 256
#define XRANGE_WIDTH 256
......@@ -98,26 +99,27 @@ static void curves_motion (Tool *, GdkEventMotion *, gpointer);
static void curves_cursor_update (Tool *, GdkEventMotion *, gpointer);
static void curves_control (Tool *, ToolAction, gpointer);
static CurvesDialog * curves_new_dialog (void);
static void curves_update (CurvesDialog *, int);
static void curves_plot_curve (CurvesDialog *, int, int, int, int);
static void curves_preview (CurvesDialog *);
static void curves_value_callback (GtkWidget *, gpointer);
static void curves_red_callback (GtkWidget *, gpointer);
static void curves_green_callback (GtkWidget *, gpointer);
static void curves_blue_callback (GtkWidget *, gpointer);
static void curves_alpha_callback (GtkWidget *, gpointer);
static void curves_smooth_callback (GtkWidget *, gpointer);
static void curves_free_callback (GtkWidget *, gpointer);
static void curves_reset_callback (GtkWidget *, gpointer);
static void curves_ok_callback (GtkWidget *, gpointer);
static void curves_cancel_callback (GtkWidget *, gpointer);
static gint curves_delete_callback (GtkWidget *, GdkEvent *, gpointer);
static void curves_preview_update (GtkWidget *, gpointer);
static gint curves_xrange_events (GtkWidget *, GdkEvent *, CurvesDialog *);
static gint curves_yrange_events (GtkWidget *, GdkEvent *, CurvesDialog *);
static gint curves_graph_events (GtkWidget *, GdkEvent *, CurvesDialog *);
static void curves_CR_compose (CRMatrix, CRMatrix, CRMatrix);
static CurvesDialog * curves_new_dialog (void);
static void curves_update (CurvesDialog *, int);
static void curves_plot_curve (CurvesDialog *, int, int, int, int);
static void curves_preview (CurvesDialog *);
static void curves_value_callback (GtkWidget *, gpointer);
static void curves_red_callback (GtkWidget *, gpointer);
static void curves_green_callback (GtkWidget *, gpointer);
static void curves_blue_callback (GtkWidget *, gpointer);
static void curves_alpha_callback (GtkWidget *, gpointer);
static void curves_smooth_callback (GtkWidget *, gpointer);
static void curves_free_callback (GtkWidget *, gpointer);
static void curves_reset_callback (GtkWidget *, gpointer);
static void curves_ok_callback (GtkWidget *, gpointer);
static void curves_cancel_callback (GtkWidget *, gpointer);
static gint curves_delete_callback (GtkWidget *, GdkEvent *, gpointer);
static void curves_preview_update (GtkWidget *, gpointer);
static gint curves_xrange_events (GtkWidget *, GdkEvent *, CurvesDialog *);
static gint curves_yrange_events (GtkWidget *, GdkEvent *, CurvesDialog *);
static gint curves_graph_events (GtkWidget *, GdkEvent *, CurvesDialog *);
static void curves_CR_compose (CRMatrix, CRMatrix, CRMatrix);
/* curves machinery */
......@@ -338,27 +340,17 @@ curves_control (Tool *tool,
ToolAction action,
gpointer gdisp_ptr)
{
Curves * _curves;
_curves = (Curves *) tool->private;
switch (action)
{
case PAUSE :
case PAUSE:
break;
case RESUME :
case RESUME:
break;
case HALT :
case HALT:
if (curves_dialog)
{
active_tool->preserve = TRUE;
image_map_abort (curves_dialog->image_map);
active_tool->preserve = FALSE;
curves_dialog->image_map = NULL;
curves_cancel_callback (NULL, (gpointer) curves_dialog);
}
curves_cancel_callback (NULL, (gpointer) curves_dialog);
break;
default:
......@@ -395,9 +387,8 @@ tools_new_curves ()
tool->modifier_key_func = standard_modifier_key_func;
tool->cursor_update_func = curves_cursor_update;
tool->control_func = curves_control;
tool->preserve = TRUE;
tool->gdisp_ptr = NULL;
tool->drawable = NULL;
tool->preserve = FALSE;
return tool;
}
......@@ -416,14 +407,6 @@ tools_free_curves (Tool *tool)
g_free (_curves);
}
/* the action area structure */
static ActionAreaItem action_items[] =
{
{ N_("Reset"), curves_reset_callback, NULL, NULL },
{ N_("OK"), curves_ok_callback, NULL, NULL },
{ N_("Cancel"), curves_cancel_callback, NULL, NULL }
};
static MenuItem channel_items[] =
{
{ N_("Value"), 0, 0, curves_value_callback, NULL, NULL, NULL },
......@@ -434,13 +417,6 @@ static MenuItem channel_items[] =
{ NULL, 0, 0, NULL, NULL, NULL, NULL }
};
static MenuItem curve_type_items[] =
{
{ N_("Smooth"), 0, 0, curves_smooth_callback, NULL, NULL, NULL },
{ N_("Free"), 0, 0, curves_free_callback, NULL, NULL, NULL },
{ NULL, 0, 0, NULL, NULL, NULL, NULL }
};
void
curves_initialize (GDisplay *gdisp)
{
......@@ -514,10 +490,13 @@ curves_free ()
active_tool->preserve = TRUE;
image_map_abort (curves_dialog->image_map);
active_tool->preserve = FALSE;
curves_dialog->image_map = NULL;
}
if (curves_dialog->pixmap)
gdk_pixmap_unref (curves_dialog->pixmap);
gtk_widget_destroy (curves_dialog->shell);
}
}
......@@ -541,6 +520,20 @@ curves_new_dialog ()
GtkWidget *table;
int i, j;
static ActionAreaItem action_items[] =
{
{ N_("Reset"), curves_reset_callback, NULL, NULL },