Bill Skaggs <weskaggs@primate.ucdavis.edu>

* app/tools/gimpcurvestool.c: try again to revert.
This commit is contained in:
William Skaggs 2004-06-22 21:09:26 +00:00
parent a45025f60f
commit 546359f914
2 changed files with 171 additions and 259 deletions

View File

@ -1,3 +1,7 @@
2004-06-22 Bill Skaggs <weskaggs@primate.ucdavis.edu>
* app/tools/gimpcurvestool.c: try again to revert.
2004-06-22 Bill Skaggs <weskaggs@primate.ucdavis.edu>
* app/tools/gimpcurvestool.c: reverted.

View File

@ -26,7 +26,6 @@
#include "libgimpcolor/gimpcolor.h"
#include "libgimpwidgets/gimpwidgets.h"
#include "libgimpbase/gimpenv.h"
#include "tools-types.h"
@ -124,10 +123,7 @@ static gboolean curves_graph_events (GtkWidget *widget,
static gboolean curves_graph_expose (GtkWidget *widget,
GdkEventExpose *eevent,
GimpCurvesTool *tool);
static void gimp_curves_tool_store_settings (GtkWidget *widget,
gpointer data);
static void gimp_curves_tool_recall_settings (GtkWidget *widget,
gpointer data);
static GimpImageMapToolClass *parent_class = NULL;
@ -161,18 +157,18 @@ gimp_curves_tool_get_type (void)
static const GTypeInfo tool_info =
{
sizeof (GimpCurvesToolClass),
(GBaseInitFunc) NULL,
(GBaseFinalizeFunc) NULL,
(GClassInitFunc) gimp_curves_tool_class_init,
NULL, /* class_finalize */
NULL, /* class_data */
sizeof (GimpCurvesTool),
0, /* n_preallocs */
(GInstanceInitFunc) gimp_curves_tool_init,
(GBaseInitFunc) NULL,
(GBaseFinalizeFunc) NULL,
(GClassInitFunc) gimp_curves_tool_class_init,
NULL, /* class_finalize */
NULL, /* class_data */
sizeof (GimpCurvesTool),
0, /* n_preallocs */
(GInstanceInitFunc) gimp_curves_tool_init,
};
tool_type = g_type_register_static (GIMP_TYPE_IMAGE_MAP_TOOL,
"GimpCurvesTool",
"GimpCurvesTool",
&tool_info, 0);
}
@ -271,7 +267,7 @@ gimp_curves_tool_finalize (GObject *object)
static gboolean
gimp_curves_tool_initialize (GimpTool *tool,
GimpDisplay *gdisp)
GimpDisplay *gdisp)
{
GimpCurvesTool *c_tool = GIMP_CURVES_TOOL (tool);
GimpDrawable *drawable;
@ -305,12 +301,6 @@ gimp_curves_tool_initialize (GimpTool *tool,
GIMP_TOOL_CLASS (parent_class)->initialize (tool, gdisp);
GIMP_IMAGE_MAP_OPTIONS (tool->tool_info->tool_options)->settings
= g_build_filename (gimp_directory (),
GIMP_IMAGE_MAP_TOOL_GET_CLASS (tool)->settings_name,
G_DIR_SEPARATOR_S,
NULL);
/* always pick colors */
gimp_color_tool_enable (GIMP_COLOR_TOOL (tool),
GIMP_COLOR_OPTIONS (tool->tool_info->tool_options));
@ -337,8 +327,8 @@ static void
gimp_curves_tool_button_release (GimpTool *tool,
GimpCoords *coords,
guint32 time,
GdkModifierType state,
GimpDisplay *gdisp)
GdkModifierType state,
GimpDisplay *gdisp)
{
GimpCurvesTool *c_tool = GIMP_CURVES_TOOL (tool);
GimpDrawable *drawable;
@ -368,9 +358,9 @@ gimp_curves_tool_button_release (GimpTool *tool,
static void
gimp_curves_tool_color_picked (GimpColorTool *color_tool,
GimpImageType sample_type,
GimpRGB *color,
gint color_index)
GimpImageType sample_type,
GimpRGB *color,
gint color_index)
{
GimpCurvesTool *tool;
GimpDrawable *drawable;
@ -398,9 +388,9 @@ gimp_curves_tool_color_picked (GimpColorTool *color_tool,
static void
curves_add_point (GimpCurvesTool *tool,
gint x,
gint y,
gint cchan)
gint x,
gint y,
gint cchan)
{
/* Add point onto the curve */
gint closest_point = 0;
@ -415,17 +405,17 @@ curves_add_point (GimpCurvesTool *tool,
distance = G_MAXINT;
for (i = 0; i < 17; i++)
{
if (tool->curves->points[cchan][i][0] != -1)
if (abs (curvex - tool->curves->points[cchan][i][0]) < distance)
{
distance = abs (curvex - tool->curves->points[cchan][i][0]);
closest_point = i;
}
}
{
if (tool->curves->points[cchan][i][0] != -1)
if (abs (curvex - tool->curves->points[cchan][i][0]) < distance)
{
distance = abs (curvex - tool->curves->points[cchan][i][0]);
closest_point = i;
}
}
if (distance > MIN_DISTANCE)
closest_point = (curvex + 8) / 16;
closest_point = (curvex + 8) / 16;
tool->curves->points[cchan][closest_point][0] = curvex;
tool->curves->points[cchan][closest_point][1] = tool->curves->curve[cchan][curvex];
@ -443,9 +433,9 @@ gimp_curves_tool_map (GimpImageMapTool *image_map_tool)
GimpCurvesTool *tool = GIMP_CURVES_TOOL (image_map_tool);
gimp_lut_setup (tool->lut,
(GimpLutFunc) curves_lut_func,
(GimpLutFunc) curves_lut_func,
tool->curves,
gimp_drawable_bytes (image_map_tool->drawable));
gimp_drawable_bytes (image_map_tool->drawable));
gimp_image_map_apply (image_map_tool->image_map,
(GimpImageMapApplyFunc) gimp_lut_process_2,
@ -522,7 +512,7 @@ gimp_curves_tool_dialog (GimpImageMapTool *image_map_tool)
/* The left color bar */
vbox2 = gtk_vbox_new (FALSE, 0);
gtk_table_attach (GTK_TABLE (table), vbox2, 0, 1, 0, 1,
GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0);
GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0);
gtk_widget_show (vbox2);
frame = gtk_frame_new (NULL);
@ -539,7 +529,7 @@ gimp_curves_tool_dialog (GimpImageMapTool *image_map_tool)
frame = gtk_frame_new (NULL);
gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_IN);
gtk_table_attach (GTK_TABLE (table), frame, 1, 2, 0, 1,
GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0);
GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0);
gtk_widget_show (frame);
tool->graph = gimp_histogram_view_new (FALSE);
@ -559,8 +549,8 @@ gimp_curves_tool_dialog (GimpImageMapTool *image_map_tool)
gtk_widget_show (tool->graph);
g_signal_connect (tool->graph, "event",
G_CALLBACK (curves_graph_events),
tool);
G_CALLBACK (curves_graph_events),
tool);
g_signal_connect_after (tool->graph, "expose_event",
G_CALLBACK (curves_graph_expose),
tool);
@ -572,7 +562,7 @@ gimp_curves_tool_dialog (GimpImageMapTool *image_map_tool)
/* The bottom color bar */
hbox2 = gtk_hbox_new (FALSE, 0);
gtk_table_attach (GTK_TABLE (table), hbox2, 1, 2, 1, 2,
GTK_EXPAND | GTK_FILL, GTK_FILL, 0, 0);
GTK_EXPAND | GTK_FILL, GTK_FILL, 0, 0);
gtk_widget_show (hbox2);
frame = gtk_frame_new (NULL);
@ -605,15 +595,11 @@ gimp_curves_tool_dialog (GimpImageMapTool *image_map_tool)
gtk_box_pack_start (GTK_BOX (hbox), frame, FALSE, FALSE, 0);
gtk_widget_show (frame);
vbox = gtk_vbox_new (FALSE, 0);
gtk_container_add (GTK_CONTAINER (frame), vbox);
gtk_widget_show (vbox);
bbox = gtk_hbutton_box_new ();
gtk_container_set_border_width (GTK_CONTAINER (bbox), 2);
gtk_box_set_spacing (GTK_BOX (bbox), 4);
gtk_button_box_set_layout (GTK_BUTTON_BOX (bbox), GTK_BUTTONBOX_SPREAD);
gtk_box_pack_start (GTK_BOX (vbox), bbox, FALSE, FALSE, 0);
gtk_container_add (GTK_CONTAINER (frame), bbox);
gtk_widget_show (bbox);
gtk_box_pack_start (GTK_BOX (bbox), image_map_tool->load_button,
@ -628,41 +614,16 @@ gimp_curves_tool_dialog (GimpImageMapTool *image_map_tool)
_("Save curves settings to file"), NULL);
gtk_widget_show (image_map_tool->save_button);
bbox = gtk_hbutton_box_new ();
gtk_container_set_border_width (GTK_CONTAINER (bbox), 2);
gtk_box_set_spacing (GTK_BOX (bbox), 4);
gtk_button_box_set_layout (GTK_BUTTON_BOX (bbox), GTK_BUTTONBOX_SPREAD);
gtk_box_pack_start (GTK_BOX (vbox), bbox, FALSE, FALSE, 0);
gtk_widget_show (bbox);
button = gtk_button_new_with_mnemonic (_("S_tore"));
gtk_box_pack_start (GTK_BOX (bbox), button, FALSE, FALSE, 0);
g_signal_connect (button, "clicked",
G_CALLBACK (gimp_curves_tool_store_settings),
tool);
gimp_help_set_help_data (button,
_("Remember curve temporarily"), NULL);
gtk_widget_show (button);
button = gtk_button_new_with_mnemonic (_("_Recall"));
gtk_box_pack_start (GTK_BOX (bbox), button, FALSE, FALSE, 0);
g_signal_connect (button, "clicked",
G_CALLBACK (gimp_curves_tool_recall_settings),
tool);
gimp_help_set_help_data (button,
_("Recall most recently stored curve"), NULL);
gtk_widget_show (button);
/* The radio box for selecting the curve type */
frame = gimp_frame_new (_("Curve Type"));
gtk_box_pack_end (GTK_BOX (hbox), frame, FALSE, FALSE, 0);
gtk_widget_show (frame);
hbox = gimp_enum_stock_box_new (GIMP_TYPE_CURVE_TYPE,
"gimp-curve", GTK_ICON_SIZE_MENU,
G_CALLBACK (curves_curve_type_callback),
tool,
&tool->curve_type);
"gimp-curve", GTK_ICON_SIZE_MENU,
G_CALLBACK (curves_curve_type_callback),
tool,
&tool->curve_type);
gtk_widget_style_get (bbox, "child_internal_pad_x", &padding, NULL);
@ -712,15 +673,15 @@ gimp_curves_tool_settings_load (GimpImageMapTool *image_map_tool,
for (i = 0; i < 5; i++)
{
for (j = 0; j < 17; j++)
{
fields = fscanf (file, "%d %d ", &index[i][j], &value[i][j]);
if (fields != 2)
{
{
fields = fscanf (file, "%d %d ", &index[i][j], &value[i][j]);
if (fields != 2)
{
/* FIXME: should have a helpful error message here */
g_printerr ("fields != 2");
return FALSE;
}
}
g_printerr ("fields != 2");
return FALSE;
}
}
}
for (i = 0; i < 5; i++)
@ -728,10 +689,10 @@ gimp_curves_tool_settings_load (GimpImageMapTool *image_map_tool,
tool->curves->curve_type[i] = GIMP_CURVE_SMOOTH;
for (j = 0; j < 17; j++)
{
tool->curves->points[i][j][0] = index[i][j];
tool->curves->points[i][j][1] = value[i][j];
}
{
tool->curves->points[i][j][0] = index[i][j];
tool->curves->points[i][j][1] = value[i][j];
}
}
for (i = 0; i < 5; i++)
@ -740,7 +701,7 @@ gimp_curves_tool_settings_load (GimpImageMapTool *image_map_tool,
curves_update (tool, ALL);
gimp_int_radio_group_set_active (GTK_RADIO_BUTTON (tool->curve_type),
GIMP_CURVE_SMOOTH);
GIMP_CURVE_SMOOTH);
return TRUE;
}
@ -757,14 +718,14 @@ gimp_curves_tool_settings_save (GimpImageMapTool *image_map_tool,
for (i = 0; i < 5; i++)
if (tool->curves->curve_type[i] == GIMP_CURVE_FREE)
{
/* pick representative points from the curve
/* pick representative points from the curve
and make them control points */
for (j = 0; j <= 8; j++)
{
index = CLAMP0255 (j * 32);
tool->curves->points[i][j * 2][0] = index;
tool->curves->points[i][j * 2][1] = tool->curves->curve[i][index];
}
for (j = 0; j <= 8; j++)
{
index = CLAMP0255 (j * 32);
tool->curves->points[i][j * 2][0] = index;
tool->curves->points[i][j * 2][1] = tool->curves->curve[i][index];
}
}
fprintf (file, "# GIMP Curves File\n");
@ -772,7 +733,7 @@ gimp_curves_tool_settings_save (GimpImageMapTool *image_map_tool,
for (i = 0; i < 5; i++)
{
for (j = 0; j < 17; j++)
fprintf (file, "%d %d ",
fprintf (file, "%d %d ",
tool->curves->points[i][j][0],
tool->curves->points[i][j][1]);
@ -782,63 +743,10 @@ gimp_curves_tool_settings_save (GimpImageMapTool *image_map_tool,
return TRUE;
}
static void
gimp_curves_tool_store_settings (GtkWidget *widget,
gpointer data)
{
GimpImageMapTool *tool = (GimpImageMapTool *)data;
gchar *tmp;
FILE *fp;
tmp = g_build_filename (gimp_directory (),
GIMP_IMAGE_MAP_TOOL_GET_CLASS (tool)->settings_name,
G_DIR_SEPARATOR_S,
".stored-curve",
NULL);
fp = fopen (tmp, "w");
if (!fp)
{
g_message ("Unable to open file for curves store.");
return;
}
gimp_curves_tool_settings_save (tool, (gpointer)fp);
fclose (fp);
g_free (tmp);
}
static void
gimp_curves_tool_recall_settings (GtkWidget *widget,
gpointer data)
{
GimpImageMapTool *tool = (GimpImageMapTool *)data;
gchar *tmp;
FILE *fp;
tmp = g_build_filename (gimp_directory (),
GIMP_IMAGE_MAP_TOOL_GET_CLASS (tool)->settings_name,
G_DIR_SEPARATOR_S,
".stored-curve",
NULL);
fp = fopen (tmp, "r");
if (!fp)
{
g_message ("Unable to open file for curves recall.");
return;
}
gimp_curves_tool_settings_load (tool, (gpointer)fp);
fclose (fp);
g_free (tmp);
}
/* TODO: preview alpha channel stuff correctly. -- austin, 20/May/99 */
static void
curves_update (GimpCurvesTool *tool,
gint update)
gint update)
{
GimpHistogramChannel channel;
@ -860,24 +768,24 @@ curves_update (GimpCurvesTool *tool,
if (update & XRANGE)
{
switch (channel)
{
case GIMP_HISTOGRAM_VALUE:
case GIMP_HISTOGRAM_ALPHA:
{
case GIMP_HISTOGRAM_VALUE:
case GIMP_HISTOGRAM_ALPHA:
gimp_color_bar_set_buffers (GIMP_COLOR_BAR (tool->xrange),
tool->curves->curve[channel],
tool->curves->curve[channel],
tool->curves->curve[channel]);
break;
break;
case GIMP_HISTOGRAM_RED:
case GIMP_HISTOGRAM_GREEN:
case GIMP_HISTOGRAM_BLUE:
case GIMP_HISTOGRAM_RED:
case GIMP_HISTOGRAM_GREEN:
case GIMP_HISTOGRAM_BLUE:
gimp_color_bar_set_buffers (GIMP_COLOR_BAR (tool->xrange),
tool->curves->curve[GIMP_HISTOGRAM_RED],
tool->curves->curve[GIMP_HISTOGRAM_GREEN],
tool->curves->curve[GIMP_HISTOGRAM_BLUE]);
break;
}
break;
}
}
if (update & YRANGE)
@ -888,7 +796,7 @@ curves_update (GimpCurvesTool *tool,
static void
curves_channel_callback (GtkWidget *widget,
GimpCurvesTool *tool)
GimpCurvesTool *tool)
{
gimp_int_combo_box_get_active (GIMP_INT_COMBO_BOX (widget),
(gint *) &tool->channel);
@ -949,7 +857,7 @@ curves_menu_visible_func (GtkTreeModel *model,
static void
curves_curve_type_callback (GtkWidget *widget,
GimpCurvesTool *tool)
GimpCurvesTool *tool)
{
GimpCurveType curve_type;
@ -985,8 +893,8 @@ curves_curve_type_callback (GtkWidget *widget,
static gboolean
curves_graph_events (GtkWidget *widget,
GdkEvent *event,
GimpCurvesTool *tool)
GdkEvent *event,
GimpCurvesTool *tool)
{
static GimpCursorType cursor_type = GDK_TOP_LEFT_ARROW;
@ -1017,11 +925,11 @@ curves_graph_events (GtkWidget *widget,
for (i = 0, closest_point = 0; i < 17; i++)
{
if (tool->curves->points[tool->channel][i][0] != -1)
if (abs (x - tool->curves->points[tool->channel][i][0]) < distance)
{
distance = abs (x - tool->curves->points[tool->channel][i][0]);
closest_point = i;
}
if (abs (x - tool->curves->points[tool->channel][i][0]) < distance)
{
distance = abs (x - tool->curves->points[tool->channel][i][0]);
closest_point = i;
}
}
if (distance > MIN_DISTANCE)
@ -1038,35 +946,35 @@ curves_graph_events (GtkWidget *widget,
new_cursor = GDK_TCROSS;
switch (tool->curves->curve_type[tool->channel])
{
case GIMP_CURVE_SMOOTH:
/* determine the leftmost and rightmost points */
tool->leftmost = -1;
for (i = closest_point - 1; i >= 0; i--)
if (tool->curves->points[tool->channel][i][0] != -1)
{
tool->leftmost = tool->curves->points[tool->channel][i][0];
break;
}
tool->rightmost = 256;
for (i = closest_point + 1; i < 17; i++)
if (tool->curves->points[tool->channel][i][0] != -1)
{
tool->rightmost = tool->curves->points[tool->channel][i][0];
break;
}
{
case GIMP_CURVE_SMOOTH:
/* determine the leftmost and rightmost points */
tool->leftmost = -1;
for (i = closest_point - 1; i >= 0; i--)
if (tool->curves->points[tool->channel][i][0] != -1)
{
tool->leftmost = tool->curves->points[tool->channel][i][0];
break;
}
tool->rightmost = 256;
for (i = closest_point + 1; i < 17; i++)
if (tool->curves->points[tool->channel][i][0] != -1)
{
tool->rightmost = tool->curves->points[tool->channel][i][0];
break;
}
tool->grab_point = closest_point;
tool->curves->points[tool->channel][tool->grab_point][0] = x;
tool->curves->points[tool->channel][tool->grab_point][1] = 255 - y;
break;
tool->grab_point = closest_point;
tool->curves->points[tool->channel][tool->grab_point][0] = x;
tool->curves->points[tool->channel][tool->grab_point][1] = 255 - y;
break;
case GIMP_CURVE_FREE:
tool->curves->curve[tool->channel][x] = 255 - y;
tool->grab_point = x;
tool->last = y;
break;
}
case GIMP_CURVE_FREE:
tool->curves->curve[tool->channel][x] = 255 - y;
tool->grab_point = x;
tool->last = y;
break;
}
curves_calculate_curve (tool->curves, tool->channel);
@ -1090,83 +998,83 @@ curves_graph_events (GtkWidget *widget,
mevent = (GdkEventMotion *) event;
switch (tool->curves->curve_type[tool->channel])
{
case GIMP_CURVE_SMOOTH:
/* If no point is grabbed... */
if (tool->grab_point == -1)
{
if (tool->curves->points[tool->channel][closest_point][0] != -1)
new_cursor = GDK_FLEUR;
else
new_cursor = GDK_TCROSS;
}
/* Else, drag the grabbed point */
else
{
new_cursor = GDK_TCROSS;
{
case GIMP_CURVE_SMOOTH:
/* If no point is grabbed... */
if (tool->grab_point == -1)
{
if (tool->curves->points[tool->channel][closest_point][0] != -1)
new_cursor = GDK_FLEUR;
else
new_cursor = GDK_TCROSS;
}
/* Else, drag the grabbed point */
else
{
new_cursor = GDK_TCROSS;
tool->curves->points[tool->channel][tool->grab_point][0] = -1;
tool->curves->points[tool->channel][tool->grab_point][0] = -1;
if (x > tool->leftmost && x < tool->rightmost)
{
closest_point = (x + 8) / 16;
if (tool->curves->points[tool->channel][closest_point][0] == -1)
tool->grab_point = closest_point;
if (x > tool->leftmost && x < tool->rightmost)
{
closest_point = (x + 8) / 16;
if (tool->curves->points[tool->channel][closest_point][0] == -1)
tool->grab_point = closest_point;
tool->curves->points[tool->channel][tool->grab_point][0] = x;
tool->curves->points[tool->channel][tool->grab_point][1] = 255 - y;
}
tool->curves->points[tool->channel][tool->grab_point][0] = x;
tool->curves->points[tool->channel][tool->grab_point][1] = 255 - y;
}
curves_calculate_curve (tool->curves, tool->channel);
}
break;
curves_calculate_curve (tool->curves, tool->channel);
}
break;
case GIMP_CURVE_FREE:
if (tool->grab_point != -1)
{
if (tool->grab_point > x)
{
x1 = x;
x2 = tool->grab_point;
y1 = y;
y2 = tool->last;
}
else
{
x1 = tool->grab_point;
x2 = x;
y1 = tool->last;
y2 = y;
}
case GIMP_CURVE_FREE:
if (tool->grab_point != -1)
{
if (tool->grab_point > x)
{
x1 = x;
x2 = tool->grab_point;
y1 = y;
y2 = tool->last;
}
else
{
x1 = tool->grab_point;
x2 = x;
y1 = tool->last;
y2 = y;
}
if (x2 != x1)
for (i = x1; i <= x2; i++)
tool->curves->curve[tool->channel][i] = 255 - (y1 + ((y2 - y1) * (i - x1)) / (x2 - x1));
else
tool->curves->curve[tool->channel][x] = 255 - y;
if (x2 != x1)
for (i = x1; i <= x2; i++)
tool->curves->curve[tool->channel][i] = 255 - (y1 + ((y2 - y1) * (i - x1)) / (x2 - x1));
else
tool->curves->curve[tool->channel][x] = 255 - y;
tool->grab_point = x;
tool->last = y;
}
tool->grab_point = x;
tool->last = y;
}
if (mevent->state & GDK_BUTTON1_MASK)
new_cursor = GDK_TCROSS;
else
new_cursor = GDK_PENCIL;
if (mevent->state & GDK_BUTTON1_MASK)
new_cursor = GDK_TCROSS;
else
new_cursor = GDK_PENCIL;
break;
}
break;
}
if (new_cursor != cursor_type)
{
cursor_type = new_cursor;
{
cursor_type = new_cursor;
gimp_cursor_set (tool->graph,
GIMP_GUI_CONFIG (GIMP_TOOL (tool)->tool_info->gimp->config)->cursor_format,
cursor_type,
GIMP_TOOL_CURSOR_NONE,
GIMP_CURSOR_MODIFIER_NONE);
}
}
tool->cursor_x = x;
tool->cursor_y = y;