fixed bug #5176 (smudge tool crash)

--Sven
This commit is contained in:
Sven Neumann
2000-01-14 18:45:36 +00:00
parent d498e73578
commit baf3933a9d
7 changed files with 220 additions and 182 deletions

View File

@ -1,3 +1,9 @@
Fri Jan 14 19:43:01 CET 2000 Sven Neumann <sven@gimp.org>
* app/paint_core.h: use ToolFlags enum instead of int
* app/smudge.c: fixed bug #5176 (smudge tool crash)
2000-01-14 Michael Natterer <mitch@gimp.org> 2000-01-14 Michael Natterer <mitch@gimp.org>
* app/info_window.c: * app/info_window.c:

View File

@ -55,7 +55,6 @@ struct _SmudgeOptions
gdouble rate; gdouble rate;
gdouble rate_d; gdouble rate_d;
GtkObject *rate_w; GtkObject *rate_w;
}; };
static PixelRegion accumPR; static PixelRegion accumPR;
@ -70,7 +69,7 @@ static gdouble non_gui_rate;
/* function prototypes */ /* function prototypes */
static void smudge_motion (PaintCore *, PaintPressureOptions *, static void smudge_motion (PaintCore *, PaintPressureOptions *,
gdouble, GimpDrawable *); gdouble, GimpDrawable *);
static void smudge_init (PaintCore *, GimpDrawable *); static gboolean smudge_init (PaintCore *, GimpDrawable *);
static void smudge_finish (PaintCore *, GimpDrawable *); static void smudge_finish (PaintCore *, GimpDrawable *);
static void smudge_nonclipped_painthit_coords (PaintCore *paint_core, static void smudge_nonclipped_painthit_coords (PaintCore *paint_core,
@ -143,17 +142,24 @@ smudge_paint_func (PaintCore *paint_core,
GimpDrawable *drawable, GimpDrawable *drawable,
int state) int state)
{ {
/* initialization fails if the user starts outside the drawable */
static gboolean initialized = FALSE;
switch (state) switch (state)
{ {
case INIT_PAINT: case INIT_PAINT:
smudge_init (paint_core, drawable); initialized = smudge_init (paint_core, drawable);
break; break;
case MOTION_PAINT: case MOTION_PAINT:
if (!initialized)
initialized = smudge_init (paint_core, drawable);
if (initialized)
smudge_motion (paint_core, smudge_options->paint_options.pressure_options, smudge_motion (paint_core, smudge_options->paint_options.pressure_options,
smudge_options->rate, drawable); smudge_options->rate, drawable);
break; break;
case FINISH_PAINT: case FINISH_PAINT:
smudge_finish (paint_core, drawable); smudge_finish (paint_core, drawable);
initialized = FALSE;
break; break;
} }
@ -185,7 +191,7 @@ smudge_nonclipped_painthit_coords (PaintCore *paint_core,
*h = paint_core->brush->mask->height + 2; *h = paint_core->brush->mask->height + 2;
} }
static void static gboolean
smudge_init (PaintCore *paint_core, smudge_init (PaintCore *paint_core,
GimpDrawable *drawable) GimpDrawable *drawable)
{ {
@ -196,30 +202,29 @@ smudge_init (PaintCore *paint_core,
gint was_clipped; gint was_clipped;
guchar *do_fill = NULL; guchar *do_fill = NULL;
/* adjust the x and y coordinates to the upper left corner of the brush */
smudge_nonclipped_painthit_coords (paint_core, &x, &y, &w, &h);
if (! (gimage = drawable_gimage (drawable))) if (! (gimage = drawable_gimage (drawable)))
return; return FALSE;
/* If the image type is indexed, don't smudge */ /* If the image type is indexed, don't smudge */
if ((drawable_type (drawable) == INDEXED_GIMAGE) || if ((drawable_type (drawable) == INDEXED_GIMAGE) ||
(drawable_type (drawable) == INDEXEDA_GIMAGE)) (drawable_type (drawable) == INDEXEDA_GIMAGE))
return; return FALSE;
area = paint_core_get_paint_area (paint_core, drawable, 1.0); area = paint_core_get_paint_area (paint_core, drawable, 1.0);
if (!area) if (!area)
was_clipped = TRUE; return FALSE;
else if (x != area->x || y != area->y || w != area->width || h != area->height)
/* adjust the x and y coordinates to the upper left corner of the brush */
smudge_nonclipped_painthit_coords (paint_core, &x, &y, &w, &h);
if (x != area->x || y != area->y || w != area->width || h != area->height)
was_clipped = TRUE; was_clipped = TRUE;
else else
was_clipped = FALSE; was_clipped = FALSE;
if (!area) return;
/* When clipped, accum_data may contain pixels that map to /* When clipped, accum_data may contain pixels that map to
off-canvas pixels of the under-the- brush image, particularly off-canvas pixels of the under-the-brush image, particulary
when the brush image contains an edge or corner of the when the brush image contains an edge or corner of the
image. These off-canvas pixels are not a part of the current image. These off-canvas pixels are not a part of the current
composite, but may be composited in later generations. do_fill composite, but may be composited in later generations. do_fill
@ -229,10 +234,10 @@ smudge_init (PaintCore *paint_core,
if (was_clipped) if (was_clipped)
do_fill = gimp_drawable_get_color_at (drawable, do_fill = gimp_drawable_get_color_at (drawable,
(gint)paint_core->curx, CLAMP ((gint) paint_core->curx, 0, gimp_drawable_width (drawable) - 1),
(gint) paint_core->cury); CLAMP ((gint) paint_core->cury, 0, gimp_drawable_height (drawable) - 1));
smudge_allocate_accum_buffer (w, h, drawable_bytes(drawable), do_fill); smudge_allocate_accum_buffer (w, h, gimp_drawable_bytes (drawable), do_fill);
accumPR.x = area->x - x; accumPR.x = area->x - x;
accumPR.y = area->y - y; accumPR.y = area->y - y;
@ -258,7 +263,10 @@ smudge_init (PaintCore *paint_core,
+ accumPR.rowstride * accumPR.y + accumPR.rowstride * accumPR.y
+ accumPR.x * accumPR.bytes; + accumPR.x * accumPR.bytes;
if(do_fill) g_free(do_fill); if (do_fill)
g_free(do_fill);
return TRUE;
} }
static void static void

View File

@ -95,7 +95,7 @@ struct _paint_core
int pick_colors; /* pick color if ctrl or alt is pressed */ int pick_colors; /* pick color if ctrl or alt is pressed */
int pick_state; /* was ctrl or alt pressed when clicked? */ int pick_state; /* was ctrl or alt pressed when clicked? */
int flags; /* tool flags, see ToolFlags above */ ToolFlags flags; /* tool flags, see ToolFlags above */
guint context_id; /* for the statusbar */ guint context_id; /* for the statusbar */
}; };

View File

@ -55,7 +55,6 @@ struct _SmudgeOptions
gdouble rate; gdouble rate;
gdouble rate_d; gdouble rate_d;
GtkObject *rate_w; GtkObject *rate_w;
}; };
static PixelRegion accumPR; static PixelRegion accumPR;
@ -70,7 +69,7 @@ static gdouble non_gui_rate;
/* function prototypes */ /* function prototypes */
static void smudge_motion (PaintCore *, PaintPressureOptions *, static void smudge_motion (PaintCore *, PaintPressureOptions *,
gdouble, GimpDrawable *); gdouble, GimpDrawable *);
static void smudge_init (PaintCore *, GimpDrawable *); static gboolean smudge_init (PaintCore *, GimpDrawable *);
static void smudge_finish (PaintCore *, GimpDrawable *); static void smudge_finish (PaintCore *, GimpDrawable *);
static void smudge_nonclipped_painthit_coords (PaintCore *paint_core, static void smudge_nonclipped_painthit_coords (PaintCore *paint_core,
@ -143,17 +142,24 @@ smudge_paint_func (PaintCore *paint_core,
GimpDrawable *drawable, GimpDrawable *drawable,
int state) int state)
{ {
/* initialization fails if the user starts outside the drawable */
static gboolean initialized = FALSE;
switch (state) switch (state)
{ {
case INIT_PAINT: case INIT_PAINT:
smudge_init (paint_core, drawable); initialized = smudge_init (paint_core, drawable);
break; break;
case MOTION_PAINT: case MOTION_PAINT:
if (!initialized)
initialized = smudge_init (paint_core, drawable);
if (initialized)
smudge_motion (paint_core, smudge_options->paint_options.pressure_options, smudge_motion (paint_core, smudge_options->paint_options.pressure_options,
smudge_options->rate, drawable); smudge_options->rate, drawable);
break; break;
case FINISH_PAINT: case FINISH_PAINT:
smudge_finish (paint_core, drawable); smudge_finish (paint_core, drawable);
initialized = FALSE;
break; break;
} }
@ -185,7 +191,7 @@ smudge_nonclipped_painthit_coords (PaintCore *paint_core,
*h = paint_core->brush->mask->height + 2; *h = paint_core->brush->mask->height + 2;
} }
static void static gboolean
smudge_init (PaintCore *paint_core, smudge_init (PaintCore *paint_core,
GimpDrawable *drawable) GimpDrawable *drawable)
{ {
@ -196,30 +202,29 @@ smudge_init (PaintCore *paint_core,
gint was_clipped; gint was_clipped;
guchar *do_fill = NULL; guchar *do_fill = NULL;
/* adjust the x and y coordinates to the upper left corner of the brush */
smudge_nonclipped_painthit_coords (paint_core, &x, &y, &w, &h);
if (! (gimage = drawable_gimage (drawable))) if (! (gimage = drawable_gimage (drawable)))
return; return FALSE;
/* If the image type is indexed, don't smudge */ /* If the image type is indexed, don't smudge */
if ((drawable_type (drawable) == INDEXED_GIMAGE) || if ((drawable_type (drawable) == INDEXED_GIMAGE) ||
(drawable_type (drawable) == INDEXEDA_GIMAGE)) (drawable_type (drawable) == INDEXEDA_GIMAGE))
return; return FALSE;
area = paint_core_get_paint_area (paint_core, drawable, 1.0); area = paint_core_get_paint_area (paint_core, drawable, 1.0);
if (!area) if (!area)
was_clipped = TRUE; return FALSE;
else if (x != area->x || y != area->y || w != area->width || h != area->height)
/* adjust the x and y coordinates to the upper left corner of the brush */
smudge_nonclipped_painthit_coords (paint_core, &x, &y, &w, &h);
if (x != area->x || y != area->y || w != area->width || h != area->height)
was_clipped = TRUE; was_clipped = TRUE;
else else
was_clipped = FALSE; was_clipped = FALSE;
if (!area) return;
/* When clipped, accum_data may contain pixels that map to /* When clipped, accum_data may contain pixels that map to
off-canvas pixels of the under-the- brush image, particularly off-canvas pixels of the under-the-brush image, particulary
when the brush image contains an edge or corner of the when the brush image contains an edge or corner of the
image. These off-canvas pixels are not a part of the current image. These off-canvas pixels are not a part of the current
composite, but may be composited in later generations. do_fill composite, but may be composited in later generations. do_fill
@ -229,10 +234,10 @@ smudge_init (PaintCore *paint_core,
if (was_clipped) if (was_clipped)
do_fill = gimp_drawable_get_color_at (drawable, do_fill = gimp_drawable_get_color_at (drawable,
(gint)paint_core->curx, CLAMP ((gint) paint_core->curx, 0, gimp_drawable_width (drawable) - 1),
(gint) paint_core->cury); CLAMP ((gint) paint_core->cury, 0, gimp_drawable_height (drawable) - 1));
smudge_allocate_accum_buffer (w, h, drawable_bytes(drawable), do_fill); smudge_allocate_accum_buffer (w, h, gimp_drawable_bytes (drawable), do_fill);
accumPR.x = area->x - x; accumPR.x = area->x - x;
accumPR.y = area->y - y; accumPR.y = area->y - y;
@ -258,7 +263,10 @@ smudge_init (PaintCore *paint_core,
+ accumPR.rowstride * accumPR.y + accumPR.rowstride * accumPR.y
+ accumPR.x * accumPR.bytes; + accumPR.x * accumPR.bytes;
if(do_fill) g_free(do_fill); if (do_fill)
g_free(do_fill);
return TRUE;
} }
static void static void

View File

@ -55,7 +55,6 @@ struct _SmudgeOptions
gdouble rate; gdouble rate;
gdouble rate_d; gdouble rate_d;
GtkObject *rate_w; GtkObject *rate_w;
}; };
static PixelRegion accumPR; static PixelRegion accumPR;
@ -70,7 +69,7 @@ static gdouble non_gui_rate;
/* function prototypes */ /* function prototypes */
static void smudge_motion (PaintCore *, PaintPressureOptions *, static void smudge_motion (PaintCore *, PaintPressureOptions *,
gdouble, GimpDrawable *); gdouble, GimpDrawable *);
static void smudge_init (PaintCore *, GimpDrawable *); static gboolean smudge_init (PaintCore *, GimpDrawable *);
static void smudge_finish (PaintCore *, GimpDrawable *); static void smudge_finish (PaintCore *, GimpDrawable *);
static void smudge_nonclipped_painthit_coords (PaintCore *paint_core, static void smudge_nonclipped_painthit_coords (PaintCore *paint_core,
@ -143,17 +142,24 @@ smudge_paint_func (PaintCore *paint_core,
GimpDrawable *drawable, GimpDrawable *drawable,
int state) int state)
{ {
/* initialization fails if the user starts outside the drawable */
static gboolean initialized = FALSE;
switch (state) switch (state)
{ {
case INIT_PAINT: case INIT_PAINT:
smudge_init (paint_core, drawable); initialized = smudge_init (paint_core, drawable);
break; break;
case MOTION_PAINT: case MOTION_PAINT:
if (!initialized)
initialized = smudge_init (paint_core, drawable);
if (initialized)
smudge_motion (paint_core, smudge_options->paint_options.pressure_options, smudge_motion (paint_core, smudge_options->paint_options.pressure_options,
smudge_options->rate, drawable); smudge_options->rate, drawable);
break; break;
case FINISH_PAINT: case FINISH_PAINT:
smudge_finish (paint_core, drawable); smudge_finish (paint_core, drawable);
initialized = FALSE;
break; break;
} }
@ -185,7 +191,7 @@ smudge_nonclipped_painthit_coords (PaintCore *paint_core,
*h = paint_core->brush->mask->height + 2; *h = paint_core->brush->mask->height + 2;
} }
static void static gboolean
smudge_init (PaintCore *paint_core, smudge_init (PaintCore *paint_core,
GimpDrawable *drawable) GimpDrawable *drawable)
{ {
@ -196,30 +202,29 @@ smudge_init (PaintCore *paint_core,
gint was_clipped; gint was_clipped;
guchar *do_fill = NULL; guchar *do_fill = NULL;
/* adjust the x and y coordinates to the upper left corner of the brush */
smudge_nonclipped_painthit_coords (paint_core, &x, &y, &w, &h);
if (! (gimage = drawable_gimage (drawable))) if (! (gimage = drawable_gimage (drawable)))
return; return FALSE;
/* If the image type is indexed, don't smudge */ /* If the image type is indexed, don't smudge */
if ((drawable_type (drawable) == INDEXED_GIMAGE) || if ((drawable_type (drawable) == INDEXED_GIMAGE) ||
(drawable_type (drawable) == INDEXEDA_GIMAGE)) (drawable_type (drawable) == INDEXEDA_GIMAGE))
return; return FALSE;
area = paint_core_get_paint_area (paint_core, drawable, 1.0); area = paint_core_get_paint_area (paint_core, drawable, 1.0);
if (!area) if (!area)
was_clipped = TRUE; return FALSE;
else if (x != area->x || y != area->y || w != area->width || h != area->height)
/* adjust the x and y coordinates to the upper left corner of the brush */
smudge_nonclipped_painthit_coords (paint_core, &x, &y, &w, &h);
if (x != area->x || y != area->y || w != area->width || h != area->height)
was_clipped = TRUE; was_clipped = TRUE;
else else
was_clipped = FALSE; was_clipped = FALSE;
if (!area) return;
/* When clipped, accum_data may contain pixels that map to /* When clipped, accum_data may contain pixels that map to
off-canvas pixels of the under-the- brush image, particularly off-canvas pixels of the under-the-brush image, particulary
when the brush image contains an edge or corner of the when the brush image contains an edge or corner of the
image. These off-canvas pixels are not a part of the current image. These off-canvas pixels are not a part of the current
composite, but may be composited in later generations. do_fill composite, but may be composited in later generations. do_fill
@ -229,10 +234,10 @@ smudge_init (PaintCore *paint_core,
if (was_clipped) if (was_clipped)
do_fill = gimp_drawable_get_color_at (drawable, do_fill = gimp_drawable_get_color_at (drawable,
(gint)paint_core->curx, CLAMP ((gint) paint_core->curx, 0, gimp_drawable_width (drawable) - 1),
(gint) paint_core->cury); CLAMP ((gint) paint_core->cury, 0, gimp_drawable_height (drawable) - 1));
smudge_allocate_accum_buffer (w, h, drawable_bytes(drawable), do_fill); smudge_allocate_accum_buffer (w, h, gimp_drawable_bytes (drawable), do_fill);
accumPR.x = area->x - x; accumPR.x = area->x - x;
accumPR.y = area->y - y; accumPR.y = area->y - y;
@ -258,7 +263,10 @@ smudge_init (PaintCore *paint_core,
+ accumPR.rowstride * accumPR.y + accumPR.rowstride * accumPR.y
+ accumPR.x * accumPR.bytes; + accumPR.x * accumPR.bytes;
if(do_fill) g_free(do_fill); if (do_fill)
g_free(do_fill);
return TRUE;
} }
static void static void

View File

@ -95,7 +95,7 @@ struct _paint_core
int pick_colors; /* pick color if ctrl or alt is pressed */ int pick_colors; /* pick color if ctrl or alt is pressed */
int pick_state; /* was ctrl or alt pressed when clicked? */ int pick_state; /* was ctrl or alt pressed when clicked? */
int flags; /* tool flags, see ToolFlags above */ ToolFlags flags; /* tool flags, see ToolFlags above */
guint context_id; /* for the statusbar */ guint context_id; /* for the statusbar */
}; };

View File

@ -55,7 +55,6 @@ struct _SmudgeOptions
gdouble rate; gdouble rate;
gdouble rate_d; gdouble rate_d;
GtkObject *rate_w; GtkObject *rate_w;
}; };
static PixelRegion accumPR; static PixelRegion accumPR;
@ -70,7 +69,7 @@ static gdouble non_gui_rate;
/* function prototypes */ /* function prototypes */
static void smudge_motion (PaintCore *, PaintPressureOptions *, static void smudge_motion (PaintCore *, PaintPressureOptions *,
gdouble, GimpDrawable *); gdouble, GimpDrawable *);
static void smudge_init (PaintCore *, GimpDrawable *); static gboolean smudge_init (PaintCore *, GimpDrawable *);
static void smudge_finish (PaintCore *, GimpDrawable *); static void smudge_finish (PaintCore *, GimpDrawable *);
static void smudge_nonclipped_painthit_coords (PaintCore *paint_core, static void smudge_nonclipped_painthit_coords (PaintCore *paint_core,
@ -143,17 +142,24 @@ smudge_paint_func (PaintCore *paint_core,
GimpDrawable *drawable, GimpDrawable *drawable,
int state) int state)
{ {
/* initialization fails if the user starts outside the drawable */
static gboolean initialized = FALSE;
switch (state) switch (state)
{ {
case INIT_PAINT: case INIT_PAINT:
smudge_init (paint_core, drawable); initialized = smudge_init (paint_core, drawable);
break; break;
case MOTION_PAINT: case MOTION_PAINT:
if (!initialized)
initialized = smudge_init (paint_core, drawable);
if (initialized)
smudge_motion (paint_core, smudge_options->paint_options.pressure_options, smudge_motion (paint_core, smudge_options->paint_options.pressure_options,
smudge_options->rate, drawable); smudge_options->rate, drawable);
break; break;
case FINISH_PAINT: case FINISH_PAINT:
smudge_finish (paint_core, drawable); smudge_finish (paint_core, drawable);
initialized = FALSE;
break; break;
} }
@ -185,7 +191,7 @@ smudge_nonclipped_painthit_coords (PaintCore *paint_core,
*h = paint_core->brush->mask->height + 2; *h = paint_core->brush->mask->height + 2;
} }
static void static gboolean
smudge_init (PaintCore *paint_core, smudge_init (PaintCore *paint_core,
GimpDrawable *drawable) GimpDrawable *drawable)
{ {
@ -196,30 +202,29 @@ smudge_init (PaintCore *paint_core,
gint was_clipped; gint was_clipped;
guchar *do_fill = NULL; guchar *do_fill = NULL;
/* adjust the x and y coordinates to the upper left corner of the brush */
smudge_nonclipped_painthit_coords (paint_core, &x, &y, &w, &h);
if (! (gimage = drawable_gimage (drawable))) if (! (gimage = drawable_gimage (drawable)))
return; return FALSE;
/* If the image type is indexed, don't smudge */ /* If the image type is indexed, don't smudge */
if ((drawable_type (drawable) == INDEXED_GIMAGE) || if ((drawable_type (drawable) == INDEXED_GIMAGE) ||
(drawable_type (drawable) == INDEXEDA_GIMAGE)) (drawable_type (drawable) == INDEXEDA_GIMAGE))
return; return FALSE;
area = paint_core_get_paint_area (paint_core, drawable, 1.0); area = paint_core_get_paint_area (paint_core, drawable, 1.0);
if (!area) if (!area)
was_clipped = TRUE; return FALSE;
else if (x != area->x || y != area->y || w != area->width || h != area->height)
/* adjust the x and y coordinates to the upper left corner of the brush */
smudge_nonclipped_painthit_coords (paint_core, &x, &y, &w, &h);
if (x != area->x || y != area->y || w != area->width || h != area->height)
was_clipped = TRUE; was_clipped = TRUE;
else else
was_clipped = FALSE; was_clipped = FALSE;
if (!area) return;
/* When clipped, accum_data may contain pixels that map to /* When clipped, accum_data may contain pixels that map to
off-canvas pixels of the under-the- brush image, particularly off-canvas pixels of the under-the-brush image, particulary
when the brush image contains an edge or corner of the when the brush image contains an edge or corner of the
image. These off-canvas pixels are not a part of the current image. These off-canvas pixels are not a part of the current
composite, but may be composited in later generations. do_fill composite, but may be composited in later generations. do_fill
@ -229,10 +234,10 @@ smudge_init (PaintCore *paint_core,
if (was_clipped) if (was_clipped)
do_fill = gimp_drawable_get_color_at (drawable, do_fill = gimp_drawable_get_color_at (drawable,
(gint)paint_core->curx, CLAMP ((gint) paint_core->curx, 0, gimp_drawable_width (drawable) - 1),
(gint) paint_core->cury); CLAMP ((gint) paint_core->cury, 0, gimp_drawable_height (drawable) - 1));
smudge_allocate_accum_buffer (w, h, drawable_bytes(drawable), do_fill); smudge_allocate_accum_buffer (w, h, gimp_drawable_bytes (drawable), do_fill);
accumPR.x = area->x - x; accumPR.x = area->x - x;
accumPR.y = area->y - y; accumPR.y = area->y - y;
@ -258,7 +263,10 @@ smudge_init (PaintCore *paint_core,
+ accumPR.rowstride * accumPR.y + accumPR.rowstride * accumPR.y
+ accumPR.x * accumPR.bytes; + accumPR.x * accumPR.bytes;
if(do_fill) g_free(do_fill); if (do_fill)
g_free(do_fill);
return TRUE;
} }
static void static void