[gimp/soc-2009-siox-drb] 8.1
- From: Jie Ding <jieding src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [gimp/soc-2009-siox-drb] 8.1
- Date: Sun, 2 Aug 2009 01:43:00 +0000 (UTC)
commit 0242b6803a8bc2137c1fa0854faa3fdbc39c836d
Author: Jie Ding <jieding src gnome org>
Date: Sun Aug 2 09:39:31 2009 +0800
8.1
app/base/siox.c | 168 ++++++++++++++--------------
app/core/gimpdrawable-foreground-extract.c | 25 ----
app/tools/gimpforegroundselecttool.c | 20 ++--
3 files changed, 97 insertions(+), 116 deletions(-)
---
diff --git a/app/base/siox.c b/app/base/siox.c
index 6a24ac3..b55e12f 100644
--- a/app/base/siox.c
+++ b/app/base/siox.c
@@ -1310,12 +1310,6 @@ siox_drb (SioxState *state,
clustersize = get_clustersize (limits);
- if (optionsrefinement & SIOX_DRB_ADD)
- g_hash_table_foreach_remove(state->cache,siox_cache_remove_bg,NULL);
- if (optionsrefinement & SIOX_DRB_SUBTRACT)
- g_hash_table_foreach_remove(state->cache,siox_cache_remove_fg,NULL);
- if (optionsrefinement & SIOX_DRB_CHANGE_THRESHOLD)
- optionsrefinement = SIOX_DRB_RECALCULATE;
pixel_region_init (&srcPR, state->pixels,
x - state->offset_x, y - state->offset_y, state->width, state->height,
@@ -1431,105 +1425,113 @@ siox_drb (SioxState *state,
MULTIBLOB_DEFAULT_SIZEFACTOR : MULTIBLOB_ONE_BLOB_ONLY);
dilate_mask (mask, x, y, state->width, state->height);
-
-/*pixel_region_init (&srcPR, state->pixels,
- x - brush_radius, y - brush_radius, brush_radius * 2,
- brush_radius * 2, FALSE);
-
- pixel_region_init (&mapPR, mask, x - brush_radius, y - brush_radius,
- brush_radius * 2, brush_radius * 2, TRUE);
+
+ if (optionsrefinement & SIOX_DRB_ADD)
+ g_hash_table_foreach_remove(state->cache,siox_cache_remove_bg,NULL);
+ if (optionsrefinement & SIOX_DRB_SUBTRACT)
+ g_hash_table_foreach_remove(state->cache,siox_cache_remove_fg,NULL);
+ if (optionsrefinement & SIOX_DRB_CHANGE_THRESHOLD)
+ optionsrefinement = SIOX_DRB_RECALCULATE;
+ if (optionsrefinement & (SIOX_DRB_ADD |
+ SIOX_DRB_SUBTRACT))
+ {
+ /*pixel_region_init (&srcPR, state->pixels,
+ x - brush_radius, y - brush_radius, brush_radius * 2,
+ brush_radius * 2, FALSE);
+ pixel_region_init (&mapPR, mask, x - brush_radius, y - brush_radius,
+ brush_radius * 2, brush_radius * 2, TRUE);
- pixel_region_init (&srcPR, state->pixels,
- x , y , brush_radius * 2, brush_radius * 2, FALSE);
- pixel_region_init (&mapPR, mask, x, y,
- brush_radius * 2,
- brush_radius * 2, TRUE);
-*/
+ pixel_region_init (&srcPR, state->pixels,
+ x , y , brush_radius * 2, brush_radius * 2, FALSE);
+ pixel_region_init (&mapPR, mask, x, y,
+ brush_radius * 2,
+ brush_radius * 2, TRUE);
+ */
- pixel_region_init (&srcPR, state->pixels,
- x , y , state->width, state->height, FALSE);
- pixel_region_init (&mapPR, mask, x, y,
- brush_radius * 2,
- brush_radius * 2, TRUE);
-
- for (pr = pixel_regions_register (2, &srcPR, &mapPR);
- pr != NULL;
- pr = pixel_regions_process (pr))
- {
- const guchar *src = srcPR.data;
- guchar *map = mapPR.data;
+ pixel_region_init (&srcPR, state->pixels,
+ x , y , state->width, state->height, FALSE);
+ pixel_region_init (&mapPR, mask, x, y,
+ brush_radius * 2,
+ brush_radius * 2, TRUE);
- for (row = 0; row < srcPR.h; row++)
+ for (pr = pixel_regions_register (2, &srcPR, &mapPR);
+ pr != NULL;
+ pr = pixel_regions_process (pr))
{
- const guchar *s = src;
- guchar *m = map;
+ const guchar *src = srcPR.data;
+ guchar *map = mapPR.data;
- for (col = 0; col < srcPR.w; col++, m++, s += state->bpp)
+ for (row = 0; row < srcPR.h; row++)
{
- gint key;
- classresult *cr;
- gfloat mindistbg;
- gfloat mindistfg;
- gfloat alpha;
+ const guchar *s = src;
+ guchar *m = map;
- key = create_key (s, state->bpp, state->colormap);
- cr = g_hash_table_lookup (state->cache, GINT_TO_POINTER (key));
+ for (col = 0; col < srcPR.w; col++, m++, s += state->bpp)
+ {
+ gint key;
+ classresult *cr;
+ gfloat mindistbg;
+ gfloat mindistfg;
+ gfloat alpha;
- if (! cr)
- continue; /* Unknown color -
- can only be sure background or sure forground */
+ key = create_key (s, state->bpp, state->colormap);
+ cr = g_hash_table_lookup (state->cache, GINT_TO_POINTER (key));
- mindistbg = (gfloat) sqrt (cr->bgdist);
- mindistfg = (gfloat) sqrt (cr->fgdist);
+ if (! cr)
+ continue; /* Unknown color -
+ can only be sure background or sure forground */
- if (optionsrefinement & SIOX_DRB_ADD)
- {
- if (*m > SIOX_HIGH)
- continue;
+ mindistbg = (gfloat) sqrt (cr->bgdist);
+ mindistfg = (gfloat) sqrt (cr->fgdist);
- if (mindistfg == 0.0)
+ if (optionsrefinement & SIOX_DRB_ADD)
{
- alpha = 1.0; /* avoid div by zero */
+ if (*m > SIOX_HIGH)
+ continue;
+
+ if (mindistfg == 0.0)
+ {
+ alpha = 1.0; /* avoid div by zero */
+ }
+ else
+ {
+ gdouble d = mindistbg / mindistfg;
+
+ alpha = MIN (d, 1.0);
+ }
}
- else
+ else if (optionsrefinement & SIOX_DRB_SUBTRACT) /*if (brush_mode == SIOX_DRB_SUBTRACT)*/
{
- gdouble d = mindistbg / mindistfg;
+ if (*m < SIOX_LOW)
+ continue;
- alpha = MIN (d, 1.0);
+ if (mindistbg == 0.0)
+ {
+ alpha = 0.0; /* avoid div by zero */
+ }
+ else
+ {
+ gdouble d = mindistfg / mindistbg;
+
+ alpha = 1.0 - MIN (d, 1.0);
+ }
}
- }
- else if (optionsrefinement & SIOX_DRB_SUBTRACT) /*if (brush_mode == SIOX_DRB_SUBTRACT)*/
- {
- if (*m < SIOX_HIGH)
- continue;
-
- if (mindistbg == 0.0)
+
+ if (alpha < threshold)
{
- alpha = 0.0; /* avoid div by zero */
+ /* background with a certain confidence
+ * to be decided by user.
+ */
+ *m = 0;
}
else
{
- gdouble d = mindistfg / mindistbg;
-
- alpha = 1.0 - MIN (d, 1.0);
+ *m = (gint) (255.999 * alpha);
}
}
-
- if (alpha < threshold)
- {
- /* background with a certain confidence
- * to be decided by user.
- */
- *m = 0;
- }
- else
- {
- *m = (gint) (255.999 * alpha);
- }
-
- }
- src += srcPR.rowstride;
- map += mapPR.rowstride;
+ src += srcPR.rowstride;
+ map += mapPR.rowstride;
+ }
}
}
}
diff --git a/app/core/gimpdrawable-foreground-extract.c b/app/core/gimpdrawable-foreground-extract.c
index 9ee2822..e104f3c 100644
--- a/app/core/gimpdrawable-foreground-extract.c
+++ b/app/core/gimpdrawable-foreground-extract.c
@@ -189,32 +189,7 @@ gimp_drawable_foreground_extract_siox_done (SioxState *state)
siox_done (state);
}
-/*
-void
-gimp_drawable_foreground_extract_siox_drb (TileManager *mask,
- SioxState *state,
- SioxDRBType optionsrefinement,
- gfloat optionsthreshold,
- gint radius,
- GimpProgress *progress)
-{
- gint x = (state->x);
- gint y = (state->y);
- gint brush_mode;
- if (optionsrefinement == SIOX_DRB_ADD)
- brush_mode = 0;
- else if(optionsrefinement == SIOX_DRB_SUBTRACT)
- brush_mode = 1;
- siox_drb (state,
- mask,
- x,y,
- radius,
- brush_mode,
- optionsthreshold);
-}
-
-*/
diff --git a/app/tools/gimpforegroundselecttool.c b/app/tools/gimpforegroundselecttool.c
index 08ad958..763f67a 100644
--- a/app/tools/gimpforegroundselecttool.c
+++ b/app/tools/gimpforegroundselecttool.c
@@ -57,7 +57,8 @@
typedef struct
{
gint width;
- gboolean background;
+ gboolean background;
+ gboolean refinement;
gint num_points;
GimpVector2 *points;
} FgSelectStroke;
@@ -715,11 +716,14 @@ gimp_foreground_select_tool_select (GimpFreeSelectTool *free_sel,
const GimpVector2 *points;
gint n_points;
gint radius;
-
+ GimpDisplayShell *shell;
+
drawable = gimp_image_get_active_drawable (image);
fg_select = GIMP_FOREGROUND_SELECT_TOOL (free_sel);
options = GIMP_FOREGROUND_SELECT_TOOL_GET_OPTIONS (free_sel);
-
+ shell = GIMP_DISPLAY_SHELL (display->shell);
+ radius = (options->stroke_width / shell->scale_y) / 2;
+
if (fg_select->idle_id)
{
g_source_remove (fg_select->idle_id);
@@ -776,7 +780,7 @@ gimp_foreground_select_tool_select (GimpFreeSelectTool *free_sel,
options->sensitivity,
! options->contiguous,
options->drb,
- options->stroke_width/2,
+ radius,
GIMP_PROGRESS (display));
fg_select->refinement = SIOX_REFINEMENT_NO_CHANGE;
@@ -952,7 +956,7 @@ else if (options->drb)
stroke = g_slice_new (FgSelectStroke);
- stroke->background = options->refinement;
+ stroke->refinement = options->refinement;
stroke->width = ROUND ((gdouble) options->stroke_width / shell->scale_y);
stroke->num_points = fg_select->drbsignal->len;
stroke->points = (GimpVector2 *) g_array_free (fg_select->drbsignal, FALSE);
@@ -961,9 +965,9 @@ else if (options->drb)
fg_select->drbsignals = g_list_append (fg_select->drbsignals, stroke);
- fg_select->drbrefinement |= (stroke->background?
- SIOX_DRB_ADD :
- SIOX_DRB_SUBTRACT);
+ fg_select->drbrefinement |= (stroke->refinement?
+ SIOX_DRB_SUBTRACT :
+ SIOX_DRB_ADD);
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]