Commit 2da93d69 authored by Michael Natterer's avatar Michael Natterer 😴 Committed by Michael Natterer

app/core/gimpchannel.[ch] (gimp_channel_boundary)

2003-08-30  Michael Natterer  <mitch@gimp.org>

	* app/core/gimpchannel.[ch] (gimp_channel_boundary)
	* app/core/gimpimage-mask.[ch] (gimp_image_mask_boundary)
	* app/core/gimplayer-floating-sel.[ch] (floating_sel_boundary):
	return const BoundSeg arrays because they are cached and not newly
	allocated.

	* app/base/boundary.[ch] (sort_boundary)
	* app/tools/gimpdrawtool.[ch] (gimp_draw_tool_draw_boundary):
	take const BoundSeg arrays.

	* app/core/gimpimage-mask.c (gimp_image_mask_stroke)
	* app/display/gimpdisplayshell-selection.c
	* app/tools/gimpeditselectiontool.c (init_edit_selection):
	changed accordingly.
parent c42641fe
2003-08-30 Michael Natterer <mitch@gimp.org>
* app/core/gimpchannel.[ch] (gimp_channel_boundary)
* app/core/gimpimage-mask.[ch] (gimp_image_mask_boundary)
* app/core/gimplayer-floating-sel.[ch] (floating_sel_boundary):
return const BoundSeg arrays because they are cached and not newly
allocated.
* app/base/boundary.[ch] (sort_boundary)
* app/tools/gimpdrawtool.[ch] (gimp_draw_tool_draw_boundary):
take const BoundSeg arrays.
* app/core/gimpimage-mask.c (gimp_image_mask_stroke)
* app/display/gimpdisplayshell-selection.c
* app/tools/gimpeditselectiontool.c (init_edit_selection):
changed accordingly.
2003-08-30 Michael Natterer <mitch@gimp.org>
Fixed & cleaned up paint function registration to work without
......@@ -462,18 +462,17 @@ find_mask_boundary (PixelRegion *maskPR,
/************************/
/* Sorting a Boundary */
static int find_segment (BoundSeg *, int, int, int);
static int
find_segment (BoundSeg *segs,
gint ns,
gint x,
gint y)
static gint
find_segment (const BoundSeg *segs,
gint ns,
gint x,
gint y)
{
gint index;
for (index = 0; index < ns; index++)
if (((segs[index].x1 == x && segs[index].y1 == y) || (segs[index].x2 == x && segs[index].y2 == y)) &&
if (((segs[index].x1 == x && segs[index].y1 == y) ||
(segs[index].x2 == x && segs[index].y2 == y)) &&
segs[index].visited == FALSE)
return index;
......@@ -482,25 +481,26 @@ find_segment (BoundSeg *segs,
BoundSeg *
sort_boundary (BoundSeg *segs,
gint ns,
gint *num_groups)
sort_boundary (const BoundSeg *segs,
gint ns,
gint *num_groups)
{
gint i;
gint index;
gint x, y;
gint startx, starty;
gint empty = (num_segs == 0);
gboolean empty = (num_segs == 0);
BoundSeg *new_segs;
index = 0;
index = 0;
new_segs = NULL;
for (i = 0; i < ns; i++)
segs[i].visited = FALSE;
((BoundSeg *) segs)[i].visited = FALSE;
num_segs = 0;
num_segs = 0;
*num_groups = 0;
while (! empty)
{
empty = TRUE;
......@@ -519,7 +519,7 @@ sort_boundary (BoundSeg *segs,
make_seg (segs[index].x1, segs[index].y1,
segs[index].x2, segs[index].y2,
segs[index].open);
segs[index].visited = TRUE;
((BoundSeg *) segs)[index].visited = TRUE;
startx = segs[index].x1;
starty = segs[index].y1;
......@@ -546,7 +546,7 @@ sort_boundary (BoundSeg *segs,
y = segs[index].y1;
}
segs[index].visited = TRUE;
((BoundSeg *) segs)[index].visited = TRUE;
}
if (x != startx || y != starty)
......
......@@ -42,17 +42,17 @@ struct _BoundSeg
};
BoundSeg * find_mask_boundary (PixelRegion *maskPR,
gint *num_elems,
BoundaryType type,
gint x1,
gint y1,
gint x2,
gint y2,
guchar threshold);
BoundSeg * sort_boundary (BoundSeg *segs,
gint num_segs,
gint *num_groups);
BoundSeg * find_mask_boundary (PixelRegion *maskPR,
gint *num_elems,
BoundaryType type,
gint x1,
gint y1,
gint x2,
gint y2,
guchar threshold);
BoundSeg * sort_boundary (const BoundSeg *segs,
gint num_segs,
gint *num_groups);
#endif /* __BOUNDARY_H__ */
......@@ -522,7 +522,7 @@ gimp_channel_validate (TileManager *tm,
Tile *tile)
{
/* Set the contents of the tile to empty */
memset (tile_data_pointer (tile, 0, 0),
memset (tile_data_pointer (tile, 0, 0),
TRANSPARENT_OPACITY, tile_size (tile));
}
......@@ -644,7 +644,7 @@ gimp_channel_new_from_component (GimpImage *gimage,
return channel;
}
void
void
gimp_channel_set_color (GimpChannel *channel,
const GimpRGB *color,
gboolean push_undo)
......@@ -775,15 +775,15 @@ gimp_channel_new_mask (GimpImage *gimage,
}
gboolean
gimp_channel_boundary (GimpChannel *mask,
BoundSeg **segs_in,
BoundSeg **segs_out,
gint *num_segs_in,
gint *num_segs_out,
gint x1,
gint y1,
gint x2,
gint y2)
gimp_channel_boundary (GimpChannel *mask,
const BoundSeg **segs_in,
const BoundSeg **segs_out,
gint *num_segs_in,
gint *num_segs_out,
gint x1,
gint y1,
gint x2,
gint y2)
{
gint x3, y3, x4, y4;
PixelRegion bPR;
......@@ -1311,7 +1311,7 @@ gimp_channel_combine_ellipse (GimpChannel *mask,
val = (int) (255 * (1 - (dist + 0.5)));
else
val = 0;
if (last != val && last)
{
switch (op)
......@@ -1662,7 +1662,7 @@ gimp_channel_invert (GimpChannel *mask,
0, 0,
GIMP_ITEM (mask)->width,
GIMP_ITEM (mask)->height, TRUE);
lut = invert_lut_new (1);
pixel_regions_process_parallel ((p_func) gimp_lut_process_inline, lut,
......@@ -1745,7 +1745,7 @@ gimp_channel_grow (GimpChannel *mask,
if (radius_x < 0 || radius_y < 0)
return;
if (! gimp_channel_bounds (mask, &x1, &y1, &x2, &y2))
return;
......@@ -1804,7 +1804,7 @@ gimp_channel_shrink (GimpChannel *mask,
if (radius_x < 0 || radius_y < 0)
return;
if (! gimp_channel_bounds (mask, &x1, &y1, &x2, &y2))
return;
......
......@@ -88,7 +88,7 @@ void gimp_channel_set_opacity (GimpChannel *channel,
void gimp_channel_get_color (const GimpChannel *channel,
GimpRGB *color);
void gimp_channel_set_color (GimpChannel *channel,
void gimp_channel_set_color (GimpChannel *channel,
const GimpRGB *color,
gboolean push_undo);
......@@ -104,8 +104,8 @@ GimpChannel * gimp_channel_new_mask (GimpImage *gimage,
gint height);
gboolean gimp_channel_boundary (GimpChannel *mask,
BoundSeg **segs_in,
BoundSeg **segs_out,
const BoundSeg **segs_in,
const BoundSeg **segs_out,
gint *num_segs_in,
gint *num_segs_out,
gint x1,
......@@ -117,8 +117,8 @@ gboolean gimp_channel_bounds (GimpChannel *mask,
gint *y1,
gint *x2,
gint *y2);
gint gimp_channel_value (GimpChannel *mask,
gint x,
gint gimp_channel_value (GimpChannel *mask,
gint x,
gint y);
gboolean gimp_channel_is_empty (GimpChannel *mask);
......
......@@ -522,7 +522,7 @@ gimp_channel_validate (TileManager *tm,
Tile *tile)
{
/* Set the contents of the tile to empty */
memset (tile_data_pointer (tile, 0, 0),
memset (tile_data_pointer (tile, 0, 0),
TRANSPARENT_OPACITY, tile_size (tile));
}
......@@ -644,7 +644,7 @@ gimp_channel_new_from_component (GimpImage *gimage,
return channel;
}
void
void
gimp_channel_set_color (GimpChannel *channel,
const GimpRGB *color,
gboolean push_undo)
......@@ -775,15 +775,15 @@ gimp_channel_new_mask (GimpImage *gimage,
}
gboolean
gimp_channel_boundary (GimpChannel *mask,
BoundSeg **segs_in,
BoundSeg **segs_out,
gint *num_segs_in,
gint *num_segs_out,
gint x1,
gint y1,
gint x2,
gint y2)
gimp_channel_boundary (GimpChannel *mask,
const BoundSeg **segs_in,
const BoundSeg **segs_out,
gint *num_segs_in,
gint *num_segs_out,
gint x1,
gint y1,
gint x2,
gint y2)
{
gint x3, y3, x4, y4;
PixelRegion bPR;
......@@ -1311,7 +1311,7 @@ gimp_channel_combine_ellipse (GimpChannel *mask,
val = (int) (255 * (1 - (dist + 0.5)));
else
val = 0;
if (last != val && last)
{
switch (op)
......@@ -1662,7 +1662,7 @@ gimp_channel_invert (GimpChannel *mask,
0, 0,
GIMP_ITEM (mask)->width,
GIMP_ITEM (mask)->height, TRUE);
lut = invert_lut_new (1);
pixel_regions_process_parallel ((p_func) gimp_lut_process_inline, lut,
......@@ -1745,7 +1745,7 @@ gimp_channel_grow (GimpChannel *mask,
if (radius_x < 0 || radius_y < 0)
return;
if (! gimp_channel_bounds (mask, &x1, &y1, &x2, &y2))
return;
......@@ -1804,7 +1804,7 @@ gimp_channel_shrink (GimpChannel *mask,
if (radius_x < 0 || radius_y < 0)
return;
if (! gimp_channel_bounds (mask, &x1, &y1, &x2, &y2))
return;
......
......@@ -88,7 +88,7 @@ void gimp_channel_set_opacity (GimpChannel *channel,
void gimp_channel_get_color (const GimpChannel *channel,
GimpRGB *color);
void gimp_channel_set_color (GimpChannel *channel,
void gimp_channel_set_color (GimpChannel *channel,
const GimpRGB *color,
gboolean push_undo);
......@@ -104,8 +104,8 @@ GimpChannel * gimp_channel_new_mask (GimpImage *gimage,
gint height);
gboolean gimp_channel_boundary (GimpChannel *mask,
BoundSeg **segs_in,
BoundSeg **segs_out,
const BoundSeg **segs_in,
const BoundSeg **segs_out,
gint *num_segs_in,
gint *num_segs_out,
gint x1,
......@@ -117,8 +117,8 @@ gboolean gimp_channel_bounds (GimpChannel *mask,
gint *y1,
gint *x2,
gint *y2);
gint gimp_channel_value (GimpChannel *mask,
gint x,
gint gimp_channel_value (GimpChannel *mask,
gint x,
gint y);
gboolean gimp_channel_is_empty (GimpChannel *mask);
......
......@@ -57,16 +57,14 @@ static gboolean gimp_image_mask_stroking = FALSE;
/* public functions */
gboolean
gimp_image_mask_boundary (GimpImage *gimage,
BoundSeg **segs_in,
BoundSeg **segs_out,
gint *num_segs_in,
gint *num_segs_out)
gimp_image_mask_boundary (GimpImage *gimage,
const BoundSeg **segs_in,
const BoundSeg **segs_out,
gint *num_segs_in,
gint *num_segs_out)
{
GimpDrawable *d;
GimpDrawable *drawable;
GimpLayer *layer;
gint x1, y1;
gint x2, y2;
g_return_val_if_fail (GIMP_IS_IMAGE (gimage), FALSE);
g_return_val_if_fail (segs_in != NULL, FALSE);
......@@ -96,18 +94,24 @@ gimp_image_mask_boundary (GimpImage *gimage,
return TRUE;
}
/* Otherwise, return the boundary...if a channel is active */
else if ((d = gimp_image_active_drawable (gimage)) &&
GIMP_IS_CHANNEL (d))
else if ((drawable = gimp_image_active_drawable (gimage)) &&
GIMP_IS_CHANNEL (drawable))
{
/* Otherwise, return the boundary...if a channel is active */
return gimp_channel_boundary (gimp_image_get_mask (gimage),
segs_in, segs_out,
num_segs_in, num_segs_out,
0, 0, gimage->width, gimage->height);
}
/* if a layer is active, we return multiple boundaries based on the extents */
else if ((layer = gimp_image_get_active_layer (gimage)))
{
/* If a layer is active, we return multiple boundaries based
* on the extents
*/
gint x1, y1;
gint x2, y2;
gint off_x, off_y;
gimp_item_offsets (GIMP_ITEM (layer), &off_x, &off_y);
......@@ -126,10 +130,11 @@ gimp_image_mask_boundary (GimpImage *gimage,
}
else
{
*segs_in = NULL;
*segs_out = NULL;
*num_segs_in = 0;
*segs_in = NULL;
*segs_out = NULL;
*num_segs_in = 0;
*num_segs_out = 0;
return FALSE;
}
}
......@@ -623,14 +628,14 @@ gimp_image_mask_stroke (GimpImage *gimage,
GimpDrawable *drawable,
GimpContext *context)
{
BoundSeg *bs_in;
BoundSeg *bs_out;
gint num_segs_in;
gint num_segs_out;
GimpToolInfo *tool_info;
GimpPaintInfo *paint_info;
GimpPaintCore *core;
gboolean retval;
const BoundSeg *bs_in;
const BoundSeg *bs_out;
gint num_segs_in;
gint num_segs_out;
GimpToolInfo *tool_info;
GimpPaintInfo *paint_info;
GimpPaintCore *core;
gboolean retval;
g_return_val_if_fail (GIMP_IS_IMAGE (gimage), FALSE);
g_return_val_if_fail (GIMP_IS_DRAWABLE (drawable), FALSE);
......
......@@ -20,76 +20,76 @@
#define __GIMP_IMAGE_MASK_H__
gboolean gimp_image_mask_boundary (GimpImage *gimage,
BoundSeg **segs_in,
BoundSeg **segs_out,
gint *num_segs_in,
gint *num_segs_out);
gboolean gimp_image_mask_bounds (GimpImage *gimage,
gint *x1,
gint *y1,
gint *x2,
gint *y2);
void gimp_image_mask_invalidate (GimpImage *gimage);
gint gimp_image_mask_value (GimpImage *gimage,
gint x,
gint y);
gboolean gimp_image_mask_is_empty (GimpImage *gimage);
TileManager * gimp_image_mask_extract (GimpImage *gimage,
GimpDrawable *drawable,
gboolean cut_image,
gboolean keep_indexed,
gboolean add_alpha);
GimpLayer * gimp_image_mask_float (GimpImage *gimage,
GimpDrawable *drawable,
gboolean cut_image,
gint off_x,
gint off_y);
void gimp_image_mask_push_undo (GimpImage *gimage,
const gchar *undo_desc);
void gimp_image_mask_feather (GimpImage *gimage,
gdouble feather_radius_x,
gdouble feather_radius_y);
void gimp_image_mask_sharpen (GimpImage *gimage);
void gimp_image_mask_clear (GimpImage *gimage,
const gchar *undo_name);
void gimp_image_mask_all (GimpImage *gimage);
void gimp_image_mask_invert (GimpImage *gimage);
void gimp_image_mask_border (GimpImage *gimage,
gint border_radius_x,
gint border_radius_y);
void gimp_image_mask_grow (GimpImage *gimage,
gint grow_pixels_x,
gint grow_pixels_y);
void gimp_image_mask_shrink (GimpImage *gimage,
gint shrink_pixels_x,
gint shrink_pixels_y,
gboolean edge_lock);
void gimp_image_mask_translate (GimpImage *gimage,
gint off_x,
gint off_y,
gboolean push_undo);
void gimp_image_mask_load (GimpImage *gimage,
GimpChannel *channel);
GimpChannel * gimp_image_mask_save (GimpImage *gimage);
gboolean gimp_image_mask_stroke (GimpImage *gimage,
GimpDrawable *drawable,
GimpContext *context);
gboolean gimp_image_mask_boundary (GimpImage *gimage,
const BoundSeg **segs_in,
const BoundSeg **segs_out,
gint *num_segs_in,
gint *num_segs_out);
gboolean gimp_image_mask_bounds (GimpImage *gimage,
gint *x1,
gint *y1,
gint *x2,
gint *y2);
void gimp_image_mask_invalidate (GimpImage *gimage);
gint gimp_image_mask_value (GimpImage *gimage,
gint x,
gint y);
gboolean gimp_image_mask_is_empty (GimpImage *gimage);
TileManager * gimp_image_mask_extract (GimpImage *gimage,
GimpDrawable *drawable,
gboolean cut_image,
gboolean keep_indexed,
gboolean add_alpha);
GimpLayer * gimp_image_mask_float (GimpImage *gimage,
GimpDrawable *drawable,
gboolean cut_image,
gint off_x,
gint off_y);
void gimp_image_mask_push_undo (GimpImage *gimage,
const gchar *undo_desc);
void gimp_image_mask_feather (GimpImage *gimage,
gdouble feather_radius_x,
gdouble feather_radius_y);
void gimp_image_mask_sharpen (GimpImage *gimage);
void gimp_image_mask_clear (GimpImage *gimage,
const gchar *undo_name);
void gimp_image_mask_all (GimpImage *gimage);
void gimp_image_mask_invert (GimpImage *gimage);
void gimp_image_mask_border (GimpImage *gimage,
gint border_radius_x,
gint border_radius_y);
void gimp_image_mask_grow (GimpImage *gimage,
gint grow_pixels_x,
gint grow_pixels_y);
void gimp_image_mask_shrink (GimpImage *gimage,
gint shrink_pixels_x,
gint shrink_pixels_y,
gboolean edge_lock);
void gimp_image_mask_translate (GimpImage *gimage,
gint off_x,
gint off_y,
gboolean push_undo);
void gimp_image_mask_load (GimpImage *gimage,
GimpChannel *channel);
GimpChannel * gimp_image_mask_save (GimpImage *gimage);
gboolean gimp_image_mask_stroke (GimpImage *gimage,
GimpDrawable *drawable,
GimpContext *context);
#endif /* __GIMP_IMAGE_MASK_H__ */
......@@ -238,7 +238,7 @@ floating_sel_to_layer (GimpLayer *layer)
0, 0,
GIMP_ITEM (layer)->width,
GIMP_ITEM (layer)->height);
gimp_image_floating_selection_changed (gimage);
}
......@@ -496,7 +496,7 @@ floating_sel_composite (GimpLayer *layer,
}
}
BoundSeg *
const BoundSeg *
floating_sel_boundary (GimpLayer *layer,
gint *n_segs)
{
......
......@@ -20,35 +20,35 @@
#define __GIMP_LAYER_FLOATING_SEL_H__
void floating_sel_attach (GimpLayer *layer,
GimpDrawable *drawable);
void floating_sel_remove (GimpLayer *layer);
void floating_sel_anchor (GimpLayer *layer);
void floating_sel_reset (GimpLayer *layer);
void floating_sel_to_layer (GimpLayer *layer);
void floating_sel_store (GimpLayer *layer,
gint x,
gint y,
gint w,
gint h);
void floating_sel_restore (GimpLayer *layer,
gint x,
gint y,
gint w,
gint h);
void floating_sel_rigor (GimpLayer *layer,
gboolean push_undo);
void floating_sel_relax (GimpLayer *layer,