Commit 4bdf25da authored by BST 1999 Andy Thomas's avatar BST 1999 Andy Thomas Committed by Andy Thomas

Changed:-

Wed Apr  7 22:44:02 BST 1999 Andy Thomas <alt@gimp.org>

	Changed:-

	* app/curves.c
	* app/image_map.c
	* app/image_map.h

	Curves dialog now has "interactive feedback". Press and drag the
	mouse button in the image window and a marker will appear in the
	curves dialog showing the channel value at that point.
parent 393b1fd5
Wed Apr 7 22:44:02 BST 1999 Andy Thomas <alt@gimp.org>
Changed:-
* app/curves.c
* app/image_map.c
* app/image_map.h
Curves dialog now has "interactive feedback". Press and drag the
mouse button in the image window and a marker will appear in the
curves dialog showing the channel value at that point.
Wed Apr 7 00:50:13 MEST 1999 Sven Neumann <sven@gimp.org>
* app/rect_select.c: when using fixed_size selections create the
......
......@@ -97,6 +97,7 @@ struct _CurvesDialog
int curve_type;
int points[5][17][2];
unsigned char curve[5][256];
int col_value[5];
GimpLut *lut;
};
......@@ -197,9 +198,73 @@ curves_button_press (Tool *tool,
gpointer gdisp_ptr)
{
GDisplay *gdisp;
GimpDrawable * drawable;
gdisp = gdisp_ptr;
tool->drawable = gimage_active_drawable (gdisp->gimage);
drawable = gimage_active_drawable (gdisp->gimage);
if(drawable != tool->drawable)
{
active_tool->preserve = TRUE;
image_map_abort (curves_dialog->image_map);
active_tool->preserve = FALSE;
curves_dialog->drawable = tool->drawable = drawable;
curves_dialog->color = drawable_color (drawable);
curves_dialog->image_map = image_map_create (gdisp, drawable);
}
if(tool)
tool->state = ACTIVE;
}
static void
curves_colour_update(Tool *tool,
GDisplay *gdisp,
GimpDrawable *drawable,
gint x,
gint y)
{
unsigned char *color;
int offx, offy;
int has_alpha;
int is_indexed;
int sample_type;
int maxval;
if(!tool || tool->state != ACTIVE)
return;
drawable_offsets (drawable, &offx, &offy);
x -= offx;
y -= offy;
if (!(color = image_map_get_color_at(curves_dialog->image_map, x, y)))
return;
sample_type = gimp_drawable_type(drawable);
is_indexed = gimp_drawable_indexed (drawable);
has_alpha = TYPE_HAS_ALPHA(sample_type);
curves_dialog->col_value[HISTOGRAM_RED] = color[RED_PIX];
curves_dialog->col_value[HISTOGRAM_GREEN] = color[GREEN_PIX];
curves_dialog->col_value[HISTOGRAM_BLUE] = color[BLUE_PIX];
if (has_alpha)
{
curves_dialog->col_value [HISTOGRAM_ALPHA] = color[3];
}
if (is_indexed)
curves_dialog->col_value [HISTOGRAM_ALPHA] = color[4];
maxval = MAXIMUM(color[RED_PIX],color[GREEN_PIX]);
curves_dialog->col_value[HISTOGRAM_VALUE] = MAXIMUM(maxval,color[BLUE_PIX]);
g_free(color);
curves_update (curves_dialog, GRAPH | DRAW);
}
static void
......@@ -207,6 +272,19 @@ curves_button_release (Tool *tool,
GdkEventButton *bevent,
gpointer gdisp_ptr)
{
gint x, y;
GimpDrawable * drawable;
GDisplay *gdisp;
gdisp = (GDisplay *) gdisp_ptr;
if(!curves_dialog ||
!gdisp ||
!(drawable = gimage_active_drawable (gdisp->gimage)))
return;
gdisplay_untransform_coords (gdisp, bevent->x, bevent->y, &x, &y, FALSE, FALSE);
curves_colour_update(tool,gdisp,drawable,x,y);
}
static void
......@@ -214,6 +292,19 @@ curves_motion (Tool *tool,
GdkEventMotion *mevent,
gpointer gdisp_ptr)
{
GDisplay *gdisp;
gint x, y;
GimpDrawable * drawable;
gdisp = (GDisplay *) gdisp_ptr;
if(!curves_dialog ||
!gdisp ||
!(drawable = gimage_active_drawable (gdisp->gimage)))
return;
gdisplay_untransform_coords (gdisp, mevent->x, mevent->y, &x, &y, FALSE, FALSE);
curves_colour_update(tool,gdisp,drawable,x,y);
}
static void
......@@ -433,6 +524,10 @@ curves_new_dialog ()
for (i = 0; i < 5; i++)
for (j = 0; j < 256; j++)
cd->curve[i][j] = j;
for(i = 0; i < (sizeof(cd->col_value)/sizeof(cd->col_value[0])); i++)
cd->col_value[i] = 0;
cd->lut = gimp_lut_new();
for (i = 0; i < 5; i++)
......@@ -662,6 +757,11 @@ curves_update (CurvesDialog *cd,
RADIUS * 2, RADIUS * 2, 0, 23040);
}
/* draw the colour line */
gdk_draw_line(cd->pixmap, cd->graph->style->black_gc,
cd->col_value[cd->channel],RADIUS,
cd->col_value[cd->channel],GRAPH_HEIGHT + RADIUS);
gdk_draw_pixmap (cd->graph->window, cd->graph->style->black_gc, cd->pixmap,
0, 0, 0, 0, GRAPH_WIDTH + RADIUS * 2, GRAPH_HEIGHT + RADIUS * 2);
}
......@@ -1124,6 +1224,8 @@ curves_graph_events (GtkWidget *widget,
}
curves_update (cd, GRAPH | XRANGE_TOP | DRAW);
gtk_grab_add(widget);
break;
case GDK_BUTTON_RELEASE:
......@@ -1132,6 +1234,9 @@ curves_graph_events (GtkWidget *widget,
if (cd->preview)
curves_preview (cd);
gtk_grab_remove(widget);
break;
case GDK_MOTION_NOTIFY:
......
......@@ -300,3 +300,51 @@ image_map_abort (ImageMap image_map)
g_free (_image_map);
}
unsigned char *
image_map_get_color_at (ImageMap image_map, int x, int y)
{
Tile *tile;
unsigned char *src;
unsigned char *dest;
_ImageMap *_image_map;
if(!image_map)
return NULL;
_image_map = (_ImageMap *) image_map;
/* Check if done damage to original image */
if(!_image_map->undo_tiles)
return (gimp_drawable_get_color_at(_image_map->drawable,x,y));
if (!image_map ||
(!gimp_drawable_gimage(_image_map->drawable) &&
gimp_drawable_indexed(_image_map->drawable))
|| x < 0 || y < 0 )
{
return NULL;
}
dest = g_new(unsigned char, 5);
tile = tile_manager_get_tile (_image_map->undo_tiles, x, y,
TRUE, FALSE);
src = tile_data_pointer (tile, x % TILE_WIDTH, y % TILE_HEIGHT);
gimp_image_get_color (gimp_drawable_gimage(_image_map->drawable),
gimp_drawable_type (_image_map->drawable), dest, src);
if(TYPE_HAS_ALPHA(gimp_drawable_type (_image_map->drawable)))
dest[3] = src[gimp_drawable_bytes (_image_map->drawable) - 1];
else
dest[3] = 255;
if (gimp_drawable_indexed(_image_map->drawable))
dest[4] = src[0];
else
dest[4] = 0;
tile_release (tile, FALSE);
return dest;
}
......@@ -34,5 +34,6 @@ ImageMap image_map_create (void *, GimpDrawable *);
void image_map_apply (ImageMap, ImageMapApplyFunc, void *);
void image_map_commit (ImageMap);
void image_map_abort (ImageMap);
unsigned char *image_map_get_color_at (ImageMap, int, int);
#endif /* __IMAGE_MAP_H__ */
......@@ -97,6 +97,7 @@ struct _CurvesDialog
int curve_type;
int points[5][17][2];
unsigned char curve[5][256];
int col_value[5];
GimpLut *lut;
};
......@@ -197,9 +198,73 @@ curves_button_press (Tool *tool,
gpointer gdisp_ptr)
{
GDisplay *gdisp;
GimpDrawable * drawable;
gdisp = gdisp_ptr;
tool->drawable = gimage_active_drawable (gdisp->gimage);
drawable = gimage_active_drawable (gdisp->gimage);
if(drawable != tool->drawable)
{
active_tool->preserve = TRUE;
image_map_abort (curves_dialog->image_map);
active_tool->preserve = FALSE;
curves_dialog->drawable = tool->drawable = drawable;
curves_dialog->color = drawable_color (drawable);
curves_dialog->image_map = image_map_create (gdisp, drawable);
}
if(tool)
tool->state = ACTIVE;
}
static void
curves_colour_update(Tool *tool,
GDisplay *gdisp,
GimpDrawable *drawable,
gint x,
gint y)
{
unsigned char *color;
int offx, offy;
int has_alpha;
int is_indexed;
int sample_type;
int maxval;
if(!tool || tool->state != ACTIVE)
return;
drawable_offsets (drawable, &offx, &offy);
x -= offx;
y -= offy;
if (!(color = image_map_get_color_at(curves_dialog->image_map, x, y)))
return;
sample_type = gimp_drawable_type(drawable);
is_indexed = gimp_drawable_indexed (drawable);
has_alpha = TYPE_HAS_ALPHA(sample_type);
curves_dialog->col_value[HISTOGRAM_RED] = color[RED_PIX];
curves_dialog->col_value[HISTOGRAM_GREEN] = color[GREEN_PIX];
curves_dialog->col_value[HISTOGRAM_BLUE] = color[BLUE_PIX];
if (has_alpha)
{
curves_dialog->col_value [HISTOGRAM_ALPHA] = color[3];
}
if (is_indexed)
curves_dialog->col_value [HISTOGRAM_ALPHA] = color[4];
maxval = MAXIMUM(color[RED_PIX],color[GREEN_PIX]);
curves_dialog->col_value[HISTOGRAM_VALUE] = MAXIMUM(maxval,color[BLUE_PIX]);
g_free(color);
curves_update (curves_dialog, GRAPH | DRAW);
}
static void
......@@ -207,6 +272,19 @@ curves_button_release (Tool *tool,
GdkEventButton *bevent,
gpointer gdisp_ptr)
{
gint x, y;
GimpDrawable * drawable;
GDisplay *gdisp;
gdisp = (GDisplay *) gdisp_ptr;
if(!curves_dialog ||
!gdisp ||
!(drawable = gimage_active_drawable (gdisp->gimage)))
return;
gdisplay_untransform_coords (gdisp, bevent->x, bevent->y, &x, &y, FALSE, FALSE);
curves_colour_update(tool,gdisp,drawable,x,y);
}
static void
......@@ -214,6 +292,19 @@ curves_motion (Tool *tool,
GdkEventMotion *mevent,
gpointer gdisp_ptr)
{
GDisplay *gdisp;
gint x, y;
GimpDrawable * drawable;
gdisp = (GDisplay *) gdisp_ptr;
if(!curves_dialog ||
!gdisp ||
!(drawable = gimage_active_drawable (gdisp->gimage)))
return;
gdisplay_untransform_coords (gdisp, mevent->x, mevent->y, &x, &y, FALSE, FALSE);
curves_colour_update(tool,gdisp,drawable,x,y);
}
static void
......@@ -433,6 +524,10 @@ curves_new_dialog ()
for (i = 0; i < 5; i++)
for (j = 0; j < 256; j++)
cd->curve[i][j] = j;
for(i = 0; i < (sizeof(cd->col_value)/sizeof(cd->col_value[0])); i++)
cd->col_value[i] = 0;
cd->lut = gimp_lut_new();
for (i = 0; i < 5; i++)
......@@ -662,6 +757,11 @@ curves_update (CurvesDialog *cd,
RADIUS * 2, RADIUS * 2, 0, 23040);
}
/* draw the colour line */
gdk_draw_line(cd->pixmap, cd->graph->style->black_gc,
cd->col_value[cd->channel],RADIUS,
cd->col_value[cd->channel],GRAPH_HEIGHT + RADIUS);
gdk_draw_pixmap (cd->graph->window, cd->graph->style->black_gc, cd->pixmap,
0, 0, 0, 0, GRAPH_WIDTH + RADIUS * 2, GRAPH_HEIGHT + RADIUS * 2);
}
......@@ -1124,6 +1224,8 @@ curves_graph_events (GtkWidget *widget,
}
curves_update (cd, GRAPH | XRANGE_TOP | DRAW);
gtk_grab_add(widget);
break;
case GDK_BUTTON_RELEASE:
......@@ -1132,6 +1234,9 @@ curves_graph_events (GtkWidget *widget,
if (cd->preview)
curves_preview (cd);
gtk_grab_remove(widget);
break;
case GDK_MOTION_NOTIFY:
......
......@@ -300,3 +300,51 @@ image_map_abort (ImageMap image_map)
g_free (_image_map);
}
unsigned char *
image_map_get_color_at (ImageMap image_map, int x, int y)
{
Tile *tile;
unsigned char *src;
unsigned char *dest;
_ImageMap *_image_map;
if(!image_map)
return NULL;
_image_map = (_ImageMap *) image_map;
/* Check if done damage to original image */
if(!_image_map->undo_tiles)
return (gimp_drawable_get_color_at(_image_map->drawable,x,y));
if (!image_map ||
(!gimp_drawable_gimage(_image_map->drawable) &&
gimp_drawable_indexed(_image_map->drawable))
|| x < 0 || y < 0 )
{
return NULL;
}
dest = g_new(unsigned char, 5);
tile = tile_manager_get_tile (_image_map->undo_tiles, x, y,
TRUE, FALSE);
src = tile_data_pointer (tile, x % TILE_WIDTH, y % TILE_HEIGHT);
gimp_image_get_color (gimp_drawable_gimage(_image_map->drawable),
gimp_drawable_type (_image_map->drawable), dest, src);
if(TYPE_HAS_ALPHA(gimp_drawable_type (_image_map->drawable)))
dest[3] = src[gimp_drawable_bytes (_image_map->drawable) - 1];
else
dest[3] = 255;
if (gimp_drawable_indexed(_image_map->drawable))
dest[4] = src[0];
else
dest[4] = 0;
tile_release (tile, FALSE);
return dest;
}
......@@ -34,5 +34,6 @@ ImageMap image_map_create (void *, GimpDrawable *);
void image_map_apply (ImageMap, ImageMapApplyFunc, void *);
void image_map_commit (ImageMap);
void image_map_abort (ImageMap);
unsigned char *image_map_get_color_at (ImageMap, int, int);
#endif /* __IMAGE_MAP_H__ */
......@@ -97,6 +97,7 @@ struct _CurvesDialog
int curve_type;
int points[5][17][2];
unsigned char curve[5][256];
int col_value[5];
GimpLut *lut;
};
......@@ -197,9 +198,73 @@ curves_button_press (Tool *tool,
gpointer gdisp_ptr)
{
GDisplay *gdisp;
GimpDrawable * drawable;
gdisp = gdisp_ptr;
tool->drawable = gimage_active_drawable (gdisp->gimage);
drawable = gimage_active_drawable (gdisp->gimage);
if(drawable != tool->drawable)
{
active_tool->preserve = TRUE;
image_map_abort (curves_dialog->image_map);
active_tool->preserve = FALSE;
curves_dialog->drawable = tool->drawable = drawable;
curves_dialog->color = drawable_color (drawable);
curves_dialog->image_map = image_map_create (gdisp, drawable);
}
if(tool)
tool->state = ACTIVE;
}
static void
curves_colour_update(Tool *tool,
GDisplay *gdisp,
GimpDrawable *drawable,
gint x,
gint y)
{
unsigned char *color;
int offx, offy;
int has_alpha;
int is_indexed;
int sample_type;
int maxval;
if(!tool || tool->state != ACTIVE)
return;
drawable_offsets (drawable, &offx, &offy);
x -= offx;
y -= offy;
if (!(color = image_map_get_color_at(curves_dialog->image_map, x, y)))
return;
sample_type = gimp_drawable_type(drawable);
is_indexed = gimp_drawable_indexed (drawable);
has_alpha = TYPE_HAS_ALPHA(sample_type);
curves_dialog->col_value[HISTOGRAM_RED] = color[RED_PIX];
curves_dialog->col_value[HISTOGRAM_GREEN] = color[GREEN_PIX];
curves_dialog->col_value[HISTOGRAM_BLUE] = color[BLUE_PIX];
if (has_alpha)
{
curves_dialog->col_value [HISTOGRAM_ALPHA] = color[3];
}
if (is_indexed)
curves_dialog->col_value [HISTOGRAM_ALPHA] = color[4];
maxval = MAXIMUM(color[RED_PIX],color[GREEN_PIX]);
curves_dialog->col_value[HISTOGRAM_VALUE] = MAXIMUM(maxval,color[BLUE_PIX]);
g_free(color);
curves_update (curves_dialog, GRAPH | DRAW);
}
static void
......@@ -207,6 +272,19 @@ curves_button_release (Tool *tool,
GdkEventButton *bevent,
gpointer gdisp_ptr)
{
gint x, y;
GimpDrawable * drawable;
GDisplay *gdisp;
gdisp = (GDisplay *) gdisp_ptr;
if(!curves_dialog ||
!gdisp ||
!(drawable = gimage_active_drawable (gdisp->gimage)))
return;
gdisplay_untransform_coords (gdisp, bevent->x, bevent->y, &x, &y, FALSE, FALSE);
curves_colour_update(tool,gdisp,drawable,x,y);
}
static void
......@@ -214,6 +292,19 @@ curves_motion (Tool *tool,
GdkEventMotion *mevent,
gpointer gdisp_ptr)
{
GDisplay *gdisp;
gint x, y;
GimpDrawable * drawable;
gdisp = (GDisplay *) gdisp_ptr;
if(!curves_dialog ||
!gdisp ||
!(drawable = gimage_active_drawable (gdisp->gimage)))
return;
gdisplay_untransform_coords (gdisp, mevent->x, mevent->y, &x, &y, FALSE, FALSE);
curves_colour_update(tool,gdisp,drawable,x,y);
}
static void
......@@ -433,6 +524,10 @@ curves_new_dialog ()
for (i = 0; i < 5; i++)
for (j = 0; j < 256; j++)
cd->curve[i][j] = j;
for(i = 0; i < (sizeof(cd->col_value)/sizeof(cd->col_value[0])); i++)
cd->col_value[i] = 0;
cd->lut = gimp_lut_new();
for (i = 0; i < 5; i++)
......@@ -662,6 +757,11 @@ curves_update (CurvesDialog *cd,
RADIUS * 2, RADIUS * 2, 0, 23040);
}
/* draw the colour line */
gdk_draw_line(cd->pixmap, cd->graph->style->black_gc,
cd->col_value[cd->channel],RADIUS,
cd->col_value[cd->channel],GRAPH_HEIGHT + RADIUS);
gdk_draw_pixmap (cd->graph->window, cd->graph->style->black_gc, cd->pixmap,
0, 0, 0, 0, GRAPH_WIDTH + RADIUS * 2, GRAPH_HEIGHT + RADIUS * 2);
}
......@@ -1124,6 +1224,8 @@ curves_graph_events (GtkWidget *widget,
}
curves_update (cd, GRAPH | XRANGE_TOP | DRAW);
gtk_grab_add(widget);
break;
case GDK_BUTTON_RELEASE:
......@@ -1132,6 +1234,9 @@ curves_graph_events (GtkWidget *widget,
if (cd->preview)
curves_preview (cd);
gtk_grab_remove(widget);
break;
case GDK_MOTION_NOTIFY:
......
......@@ -97,6 +97,7 @@ struct _CurvesDialog
int curve_type;
int points[5][17][2];
unsigned char curve[5][256];
int col_value[5];
GimpLut *lut;
};
......@@ -197,9 +198,73 @@ curves_button_press (Tool *tool,
gpointer gdisp_ptr)
{
GDisplay *gdisp;
GimpDrawable * drawable;
gdisp = gdisp_ptr;
tool->drawable = gimage_active_drawable (gdisp->gimage);
drawable = gimage_active_drawable (gdisp->gimage);
if(drawable != tool->drawable)
{
active_tool->preserve = TRUE;
image_map_abort (curves_dialog->image_map);
active_tool->preserve = FALSE;
curves_dialog->drawable = tool->drawable = drawable;
curves_dialog->color = drawable_color (drawable);
curves_dialog->image_map = image_map_create (gdisp, drawable);
}
if(tool)
tool->state = ACTIVE;
}
static void
curves_colour_update(Tool *tool,
GDisplay *gdisp,
GimpDrawable *drawable,
gint x,
gint y)
{
unsigned char *color;
int offx, offy;
int has_alpha;
int is_indexed;
int sample_type;
int maxval;
if(!tool || tool->state != ACTIVE)
return;
drawable_offsets (drawable, &offx, &offy);
x -= offx;
y -= offy;
if (!(color = image_map_get_color_at(curves_dialog->image_map, x, y)))
return;
sample_type = gimp_drawable_type(drawable);
is_indexed = gimp_drawable_indexed (drawable);
has_alpha = TYPE_HAS_ALPHA(sample_type);
curves_dialog->col_value[HISTOGRAM_RED] = color[RED_PIX];
curves_dialog->col_value[HISTOGRAM_GREEN] = color[GREEN_PIX];
curves_dialog->col_value[HISTOGRAM_BLUE] = color[BLUE_PIX];
if (has_alpha)
{
curves_dialog->col_value [HISTOGRAM_ALPHA] = color[3];
}
if (is_indexed)
curves_dialog->col_value [HISTOGRAM_ALPHA] = color[4];