Commit bdbb45d8 authored by Garry R. Osgood's avatar Garry R. Osgood Committed by Garry R. Osgood
Browse files

gimp/app/by_color_select.c gimp/app/color_picker.c gimp/app/gimpdrawable.c

2000-02-27 Garry R. Osgood <gosgood@idt.net>

* gimp/app/by_color_select.c
* gimp/app/color_picker.c
* gimp/app/gimpdrawable.c
* gimp/app/image_map.c
* gimp/app/paint_core.c
Inadvertent logic error in g_return_val_if_fail()
style sanity checks implemented in
gimp_drawable_get_color_at() gave rise to
segment violation reported in #6624;
error admitted out-of-bounds x&y that
do not map to tiles. Closes #6624.
GTK-critical warnings which result from
this new sanity check require that
gimp_drawable_get_color_at() clients
perform initial culling of out-of-bounds
x & y coordinates.
parent c56b60e8
2000-02-28 02:40-GMT Garry R. Osgood <gosgood@idt.net>
* gimp/app/by_color_select.c
* gimp/app/color_picker.c
* gimp/app/gimpdrawable.c
* gimp/app/image_map.c
* gimp/app/paint_core.c
Inadvertent logic error in g_return_val_if_fail()
style sanity checks implemented in
gimp_drawable_get_color_at() gave rise to
segment violation reported in #6624;
error admitted out-of-bounds x&y that
do not map to tiles. Closes #6624.
GTK-critical warnings which result from
this new sanity check require that
gimp_drawable_get_color_at() clients
perform initial culling of out-of-bounds
x & y coordinates.
2000-02-28 Michael Natterer <mitch@gimp.org>
 
* libgimp/gimpfileselection.c
......
......@@ -396,35 +396,39 @@ by_color_select_button_release (Tool *tool,
gdisplay_untransform_coords (gdisp, by_color_sel->x, by_color_sel->y,
&x, &y, FALSE, use_offsets);
/* Get the start color */
if (by_color_options->sample_merged)
if( x >= 0 && x < gimp_drawable_width (drawable) &&
y >= 0 && y < gimp_drawable_height (drawable))
{
if (!(color = gimp_image_get_color_at (gdisp->gimage, x, y)))
return;
}
else
{
if (!(color = gimp_drawable_get_color_at (drawable, x, y)))
return;
}
/* Get the start color */
if (by_color_options->sample_merged)
{
if (!(color = gimp_image_get_color_at (gdisp->gimage, x, y)))
return;
}
else
{
if (!(color = gimp_drawable_get_color_at (drawable, x, y)))
return;
}
/* select the area */
by_color_select (gdisp->gimage, drawable, color,
by_color_dialog->threshold,
by_color_sel->operation,
by_color_options->antialias,
by_color_options->feather,
by_color_options->feather_radius,
by_color_options->sample_merged);
/* select the area */
by_color_select (gdisp->gimage, drawable, color,
by_color_dialog->threshold,
by_color_sel->operation,
by_color_options->antialias,
by_color_options->feather,
by_color_options->feather_radius,
by_color_options->sample_merged);
g_free (color);
g_free (color);
/* show selection on all views */
gdisplays_flush ();
/* show selection on all views */
gdisplays_flush ();
/* update the preview window */
by_color_select_render (by_color_dialog, gdisp->gimage);
by_color_select_draw (by_color_dialog, gdisp->gimage);
/* update the preview window */
by_color_select_render (by_color_dialog, gdisp->gimage);
by_color_select_draw (by_color_dialog, gdisp->gimage);
}
}
}
......
......@@ -477,6 +477,7 @@ pick_color_do (GimpImage *gimage,
GetColorFunc get_color_func;
GtkObject *get_color_obj;
if (!drawable && !sample_merged)
return FALSE;
......@@ -503,9 +504,16 @@ pick_color_do (GimpImage *gimage,
has_alpha = TYPE_HAS_ALPHA (sample_type);
if (!(color = (*get_color_func) (get_color_obj, x, y)))
return FALSE;
if( x >= 0 && x < gimp_drawable_width (drawable) &&
y >= 0 && y < gimp_drawable_height (drawable))
{
if (!(color = (*get_color_func) (get_color_obj, x, y)))
return FALSE;
}
else
{
return FALSE;
}
if (sample_average)
{
gint i, j;
......
......@@ -426,8 +426,8 @@ gimp_drawable_get_color_at (GimpDrawable *drawable,
g_return_val_if_fail (GIMP_IS_DRAWABLE (drawable), NULL);
g_return_val_if_fail (gimp_drawable_gimage (drawable), NULL);
g_return_val_if_fail (!gimp_drawable_is_indexed (drawable), NULL);
g_return_val_if_fail (x >= 0 || x < drawable->width ||
y >= 0 || y < drawable->height, NULL);
g_return_val_if_fail (x >= 0 && x < drawable->width &&
y >= 0 && y < drawable->height, NULL);
dest = g_new (guchar, 5);
......
......@@ -312,39 +312,47 @@ image_map_get_color_at (ImageMap image_map, int x, int y)
_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_is_indexed(_image_map->drawable)) ||
x < 0 || y < 0 ||
x >= _image_map->undo_tiles->width ||
y >= _image_map->undo_tiles->height)
{
return NULL;
}
if( x >= 0 && x < gimp_drawable_width (_image_map->drawable) &&
y >= 0 && y < gimp_drawable_height (_image_map->drawable))
{
/* 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_is_indexed(_image_map->drawable)) ||
x < 0 || y < 0 ||
x >= _image_map->undo_tiles->width ||
y >= _image_map->undo_tiles->height)
{
return NULL;
}
dest = g_new(unsigned char, 5);
dest = g_new(unsigned char, 5);
tile = tile_manager_get_tile (_image_map->undo_tiles, x, y,
TRUE, FALSE);
tile = tile_manager_get_tile (_image_map->undo_tiles, x, y,
TRUE, FALSE);
src = tile_data_pointer (tile, x % TILE_WIDTH, y % TILE_HEIGHT);
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);
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_is_indexed(_image_map->drawable))
dest[4] = src[0];
else
dest[4] = 0;
tile_release (tile, FALSE);
return dest;
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_is_indexed(_image_map->drawable))
dest[4] = src[0];
else
dest[4] = 0;
tile_release (tile, FALSE);
return dest;
}
else /* out of bounds error */
{
return NULL;
}
}
......@@ -426,8 +426,8 @@ gimp_drawable_get_color_at (GimpDrawable *drawable,
g_return_val_if_fail (GIMP_IS_DRAWABLE (drawable), NULL);
g_return_val_if_fail (gimp_drawable_gimage (drawable), NULL);
g_return_val_if_fail (!gimp_drawable_is_indexed (drawable), NULL);
g_return_val_if_fail (x >= 0 || x < drawable->width ||
y >= 0 || y < drawable->height, NULL);
g_return_val_if_fail (x >= 0 && x < drawable->width &&
y >= 0 && y < drawable->height, NULL);
dest = g_new (guchar, 5);
......
......@@ -312,39 +312,47 @@ image_map_get_color_at (ImageMap image_map, int x, int y)
_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_is_indexed(_image_map->drawable)) ||
x < 0 || y < 0 ||
x >= _image_map->undo_tiles->width ||
y >= _image_map->undo_tiles->height)
{
return NULL;
}
if( x >= 0 && x < gimp_drawable_width (_image_map->drawable) &&
y >= 0 && y < gimp_drawable_height (_image_map->drawable))
{
/* 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_is_indexed(_image_map->drawable)) ||
x < 0 || y < 0 ||
x >= _image_map->undo_tiles->width ||
y >= _image_map->undo_tiles->height)
{
return NULL;
}
dest = g_new(unsigned char, 5);
dest = g_new(unsigned char, 5);
tile = tile_manager_get_tile (_image_map->undo_tiles, x, y,
TRUE, FALSE);
tile = tile_manager_get_tile (_image_map->undo_tiles, x, y,
TRUE, FALSE);
src = tile_data_pointer (tile, x % TILE_WIDTH, y % TILE_HEIGHT);
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);
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_is_indexed(_image_map->drawable))
dest[4] = src[0];
else
dest[4] = 0;
tile_release (tile, FALSE);
return dest;
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_is_indexed(_image_map->drawable))
dest[4] = src[0];
else
dest[4] = 0;
tile_release (tile, FALSE);
return dest;
}
else /* out of bounds error */
{
return NULL;
}
}
......@@ -161,20 +161,24 @@ paint_core_sample_color (GimpDrawable *drawable,
{
guchar *color;
if ((color = gimp_drawable_get_color_at (drawable, x, y)))
if( x >= 0 && x < gimp_drawable_width (drawable) &&
y >= 0 && y < gimp_drawable_height (drawable))
{
if ((state & GDK_CONTROL_MASK))
gimp_context_set_foreground (gimp_context_get_user (),
color[RED_PIX],
color[GREEN_PIX],
color[BLUE_PIX]);
else
gimp_context_set_background (gimp_context_get_user (),
color[RED_PIX],
color[GREEN_PIX],
color[BLUE_PIX]);
if ((color = gimp_drawable_get_color_at (drawable, x, y)))
{
if ((state & GDK_CONTROL_MASK))
gimp_context_set_foreground (gimp_context_get_user (),
color[RED_PIX],
color[GREEN_PIX],
color[BLUE_PIX]);
else
gimp_context_set_background (gimp_context_get_user (),
color[RED_PIX],
color[GREEN_PIX],
color[BLUE_PIX]);
g_free (color);
g_free (color);
}
}
}
......
......@@ -396,35 +396,39 @@ by_color_select_button_release (Tool *tool,
gdisplay_untransform_coords (gdisp, by_color_sel->x, by_color_sel->y,
&x, &y, FALSE, use_offsets);
/* Get the start color */
if (by_color_options->sample_merged)
if( x >= 0 && x < gimp_drawable_width (drawable) &&
y >= 0 && y < gimp_drawable_height (drawable))
{
if (!(color = gimp_image_get_color_at (gdisp->gimage, x, y)))
return;
}
else
{
if (!(color = gimp_drawable_get_color_at (drawable, x, y)))
return;
}
/* Get the start color */
if (by_color_options->sample_merged)
{
if (!(color = gimp_image_get_color_at (gdisp->gimage, x, y)))
return;
}
else
{
if (!(color = gimp_drawable_get_color_at (drawable, x, y)))
return;
}
/* select the area */
by_color_select (gdisp->gimage, drawable, color,
by_color_dialog->threshold,
by_color_sel->operation,
by_color_options->antialias,
by_color_options->feather,
by_color_options->feather_radius,
by_color_options->sample_merged);
/* select the area */
by_color_select (gdisp->gimage, drawable, color,
by_color_dialog->threshold,
by_color_sel->operation,
by_color_options->antialias,
by_color_options->feather,
by_color_options->feather_radius,
by_color_options->sample_merged);
g_free (color);
g_free (color);
/* show selection on all views */
gdisplays_flush ();
/* show selection on all views */
gdisplays_flush ();
/* update the preview window */
by_color_select_render (by_color_dialog, gdisp->gimage);
by_color_select_draw (by_color_dialog, gdisp->gimage);
/* update the preview window */
by_color_select_render (by_color_dialog, gdisp->gimage);
by_color_select_draw (by_color_dialog, gdisp->gimage);
}
}
}
......
......@@ -477,6 +477,7 @@ pick_color_do (GimpImage *gimage,
GetColorFunc get_color_func;
GtkObject *get_color_obj;
if (!drawable && !sample_merged)
return FALSE;
......@@ -503,9 +504,16 @@ pick_color_do (GimpImage *gimage,
has_alpha = TYPE_HAS_ALPHA (sample_type);
if (!(color = (*get_color_func) (get_color_obj, x, y)))
return FALSE;
if( x >= 0 && x < gimp_drawable_width (drawable) &&
y >= 0 && y < gimp_drawable_height (drawable))
{
if (!(color = (*get_color_func) (get_color_obj, x, y)))
return FALSE;
}
else
{
return FALSE;
}
if (sample_average)
{
gint i, j;
......
......@@ -396,35 +396,39 @@ by_color_select_button_release (Tool *tool,
gdisplay_untransform_coords (gdisp, by_color_sel->x, by_color_sel->y,
&x, &y, FALSE, use_offsets);
/* Get the start color */
if (by_color_options->sample_merged)
if( x >= 0 && x < gimp_drawable_width (drawable) &&
y >= 0 && y < gimp_drawable_height (drawable))
{
if (!(color = gimp_image_get_color_at (gdisp->gimage, x, y)))
return;
}
else
{
if (!(color = gimp_drawable_get_color_at (drawable, x, y)))
return;
}
/* Get the start color */
if (by_color_options->sample_merged)
{
if (!(color = gimp_image_get_color_at (gdisp->gimage, x, y)))
return;
}
else
{
if (!(color = gimp_drawable_get_color_at (drawable, x, y)))
return;
}
/* select the area */
by_color_select (gdisp->gimage, drawable, color,
by_color_dialog->threshold,
by_color_sel->operation,
by_color_options->antialias,
by_color_options->feather,
by_color_options->feather_radius,
by_color_options->sample_merged);
/* select the area */
by_color_select (gdisp->gimage, drawable, color,
by_color_dialog->threshold,
by_color_sel->operation,
by_color_options->antialias,
by_color_options->feather,
by_color_options->feather_radius,
by_color_options->sample_merged);
g_free (color);
g_free (color);
/* show selection on all views */
gdisplays_flush ();
/* show selection on all views */
gdisplays_flush ();
/* update the preview window */
by_color_select_render (by_color_dialog, gdisp->gimage);
by_color_select_draw (by_color_dialog, gdisp->gimage);
/* update the preview window */
by_color_select_render (by_color_dialog, gdisp->gimage);
by_color_select_draw (by_color_dialog, gdisp->gimage);
}
}
}
......
......@@ -161,20 +161,24 @@ paint_core_sample_color (GimpDrawable *drawable,
{
guchar *color;
if ((color = gimp_drawable_get_color_at (drawable, x, y)))
if( x >= 0 && x < gimp_drawable_width (drawable) &&
y >= 0 && y < gimp_drawable_height (drawable))
{
if ((state & GDK_CONTROL_MASK))
gimp_context_set_foreground (gimp_context_get_user (),
color[RED_PIX],
color[GREEN_PIX],
color[BLUE_PIX]);
else
gimp_context_set_background (gimp_context_get_user (),
color[RED_PIX],
color[GREEN_PIX],
color[BLUE_PIX]);
if ((color = gimp_drawable_get_color_at (drawable, x, y)))
{
if ((state & GDK_CONTROL_MASK))
gimp_context_set_foreground (gimp_context_get_user (),
color[RED_PIX],
color[GREEN_PIX],
color[BLUE_PIX]);
else
gimp_context_set_background (gimp_context_get_user (),
color[RED_PIX],
color[GREEN_PIX],
color[BLUE_PIX]);
g_free (color);
g_free (color);
}
}
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment