applied a patch from Eric Cheung that changes the function to use a GQueue

2004-08-28  Sven Neumann  <sven@gimp.org>

	* app/core/gimpimage-contiguous-region.c
	(find_contiguous_region_helper): applied a patch from Eric Cheung
	that changes the function to use a GQueue to implement recursion
	instead of recursive function calls. Fixes bug #151124.

	* plug-ins/common/noisify.c (noisify_dialog): left-align the
	preview.
This commit is contained in:
Sven Neumann 2004-08-28 11:48:00 +00:00 committed by Sven Neumann
parent 52bf83ee69
commit 804788c120
3 changed files with 74 additions and 37 deletions

View File

@ -1,3 +1,13 @@
2004-08-28 Sven Neumann <sven@gimp.org>
* app/core/gimpimage-contiguous-region.c
(find_contiguous_region_helper): applied a patch from Eric Cheung
that changes the function to use a GQueue to implement recursion
instead of recursive function calls. Fixes bug #151124.
* plug-ins/common/noisify.c (noisify_dialog): left-align the
preview.
2004-08-28 Sven Neumann <sven@gimp.org>
* app/widgets/gimphelp-ids.h

View File

@ -508,37 +508,64 @@ find_contiguous_region_helper (GimpImage *gimage,
gint y,
guchar *col)
{
gint start, end, i;
gint val;
gint start, end;
gint new_start, new_end;
gint val;
Tile *tile;
GQueue *coord_stack;
Tile *tile;
coord_stack = g_queue_new();
if (x < 0 || x >= src->w) return;
if (y < 0 || y >= src->h) return;
/* To avoid excessive memory allocation (y, start, end) tuples are
* stored in interleaved format:
*
* [y1] [start1] [end1] [y2] [start2] [end2]
*/
g_queue_push_tail (coord_stack, GINT_TO_POINTER (y));
g_queue_push_tail (coord_stack, GINT_TO_POINTER (x - 1));
g_queue_push_tail (coord_stack, GINT_TO_POINTER (x + 1));
tile = tile_manager_get_tile (mask->tiles, x, y, TRUE, FALSE);
val = *(guchar *)(tile_data_pointer (tile,
x % TILE_WIDTH, y % TILE_HEIGHT));
tile_release (tile, FALSE);
if (val != 0)
return;
src->x = x;
src->y = y;
if (! find_contiguous_segment (gimage, col, src, mask, src->w, src->bytes,
src_type, has_alpha, select_transparent,
antialias, threshold,
x, &start, &end))
return;
for (i = start + 1; i < end; i++)
do
{
find_contiguous_region_helper (gimage, mask, src, src_type, has_alpha,
select_transparent, antialias, threshold,
i, y - 1, col);
find_contiguous_region_helper (gimage, mask, src, src_type, has_alpha,
select_transparent, antialias, threshold,
i, y + 1, col);
y = GPOINTER_TO_INT (g_queue_pop_head (coord_stack));
start = GPOINTER_TO_INT (g_queue_pop_head (coord_stack));
end = GPOINTER_TO_INT (g_queue_pop_head (coord_stack));
for (x = start + 1; x < end; x++)
{
tile = tile_manager_get_tile (mask->tiles, x, y, TRUE, FALSE);
val = *(guchar *) (tile_data_pointer (tile,
x % TILE_WIDTH,
y % TILE_HEIGHT));
tile_release (tile, FALSE);
if (val != 0)
continue;
src->x = x;
src->y = y;
if (! find_contiguous_segment (gimage, col, src, mask, src->w,
src->bytes, src_type, has_alpha,
select_transparent, antialias,
threshold, x, &new_start, &new_end))
continue;
if (y + 1 < src->h)
{
g_queue_push_tail (coord_stack, GINT_TO_POINTER (y + 1));
g_queue_push_tail (coord_stack, GINT_TO_POINTER (new_start));
g_queue_push_tail (coord_stack, GINT_TO_POINTER (new_end));
}
if (y - 1 >= 0)
{
g_queue_push_tail (coord_stack, GINT_TO_POINTER (y - 1));
g_queue_push_tail (coord_stack, GINT_TO_POINTER (new_start));
g_queue_push_tail (coord_stack, GINT_TO_POINTER (new_end));
}
}
}
while (!g_queue_is_empty (coord_stack));
g_queue_free (coord_stack);
}

View File

@ -286,7 +286,7 @@ noisify (GimpDrawable *drawable,
guchar *preview_src, *preview_dst;
GimpPixelRgn src_rgn;
gint i;
preview_src = g_new (guchar, preview_width * preview_height * preview_bpp);
preview_dst = g_new (guchar, preview_width * preview_height * preview_bpp);
@ -303,7 +303,7 @@ noisify (GimpDrawable *drawable,
preview_dst + i * preview_bpp,
preview_bpp,
gr);
gimp_preview_area_draw (GIMP_PREVIEW_AREA (preview),
0, 0, preview_width, preview_height,
gimp_drawable_type (drawable->drawable_id),
@ -378,7 +378,7 @@ noisify_dialog (GimpDrawable *drawable,
{
GtkWidget *dlg;
GtkWidget *vbox;
GtkWidget *alignment;
GtkWidget *hbox;
GtkWidget *ptable;
GtkWidget *frame;
GtkWidget *scrollbar;
@ -401,14 +401,14 @@ noisify_dialog (GimpDrawable *drawable,
gtk_container_set_border_width (GTK_CONTAINER (vbox), 12);
gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dlg)->vbox), vbox, TRUE, TRUE, 0);
gtk_widget_show (vbox);
/* preview */
alignment = gtk_alignment_new (0.5, 0.5, 0.0, 0.0);
gtk_box_pack_start (GTK_BOX (vbox), alignment, FALSE, FALSE, 0);
gtk_widget_show (alignment);
hbox = gtk_hbox_new (FALSE, 0);
gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, FALSE, 0);
gtk_widget_show (hbox);
ptable = gtk_table_new (2, 2, FALSE);
gtk_container_add (GTK_CONTAINER (alignment), ptable);
gtk_box_pack_start (GTK_BOX (hbox), ptable, FALSE, FALSE, 0);
gtk_widget_show (ptable);
frame = gtk_frame_new (NULL);
@ -464,7 +464,7 @@ noisify_dialog (GimpDrawable *drawable,
gtk_box_pack_start (GTK_BOX (vbox), toggle, FALSE, FALSE, 0);
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (toggle), nvals.independent);
gtk_widget_show (toggle);
g_signal_connect (toggle, "toggled",
G_CALLBACK (gimp_toggle_button_update),
&nvals.independent);