mirror of https://github.com/GNOME/gimp.git
applied patch from Tobias Lenz that plugs a memleak and yields another
2006-01-07 Sven Neumann <sven@gimp.org> * app/base/siox.c: applied patch from Tobias Lenz that plugs a memleak and yields another small speedup.
This commit is contained in:
parent
3412048579
commit
c2b2573550
|
@ -1,3 +1,8 @@
|
||||||
|
2006-01-07 Sven Neumann <sven@gimp.org>
|
||||||
|
|
||||||
|
* app/base/siox.c: applied patch from Tobias Lenz that plugs a
|
||||||
|
memleak and yields another small speedup.
|
||||||
|
|
||||||
2006-01-06 Sven Neumann <sven@gimp.org>
|
2006-01-06 Sven Neumann <sven@gimp.org>
|
||||||
|
|
||||||
* gimptool-2.0.in: if available use pkg-config to determine
|
* gimptool-2.0.in: if available use pkg-config to determine
|
||||||
|
|
198
app/base/siox.c
198
app/base/siox.c
|
@ -164,7 +164,7 @@ stageone (lab *points,
|
||||||
gint depth,
|
gint depth,
|
||||||
gint *clusters,
|
gint *clusters,
|
||||||
const gfloat *limits,
|
const gfloat *limits,
|
||||||
gint dims)
|
const gint dims)
|
||||||
{
|
{
|
||||||
gint curdim = depth % dims;
|
gint curdim = depth % dims;
|
||||||
gfloat min, max;
|
gfloat min, max;
|
||||||
|
@ -248,10 +248,10 @@ stagetwo (lab *points,
|
||||||
gint left,
|
gint left,
|
||||||
gint right,
|
gint right,
|
||||||
gint depth,
|
gint depth,
|
||||||
GSList **clusters,
|
gint *clusters,
|
||||||
const gfloat *limits,
|
const gfloat *limits,
|
||||||
gfloat threshold,
|
const gfloat threshold,
|
||||||
gint dims)
|
const gint dims)
|
||||||
{
|
{
|
||||||
gint curdim = depth % dims;
|
gint curdim = depth % dims;
|
||||||
gfloat min, max;
|
gfloat min, max;
|
||||||
|
@ -310,25 +310,27 @@ stagetwo (lab *points,
|
||||||
|
|
||||||
if (sum >= threshold)
|
if (sum >= threshold)
|
||||||
{
|
{
|
||||||
lab *point = g_new0 (lab, 1);
|
const gint c = right - left;
|
||||||
|
gfloat l = 0;
|
||||||
|
gfloat a = 0;
|
||||||
|
gfloat b = 0;
|
||||||
|
|
||||||
for (i = left; i < right; i++)
|
for (; left < right; ++left)
|
||||||
{
|
{
|
||||||
point->l += points[i].l;
|
l += points[left].l;
|
||||||
point->a += points[i].a;
|
a += points[left].a;
|
||||||
point->b += points[i].b;
|
b += points[left].b;
|
||||||
}
|
}
|
||||||
|
|
||||||
point->l /= right - left;
|
points[*clusters].l = l / c;
|
||||||
point->a /= right - left;
|
points[*clusters].a = a / c;
|
||||||
point->b /= right - left;
|
points[*clusters].b = b / c;
|
||||||
|
++(*clusters);
|
||||||
|
|
||||||
#ifdef SIOX_DEBUG
|
#ifdef SIOX_DEBUG
|
||||||
g_printerr ("siox.c: cluster=%f, %f, %f sum=%d\n",
|
g_printerr ("siox.c: cluster=%f, %f, %f sum=%d\n",
|
||||||
point->l, point->a, point->b, sum);
|
l, a, b, sum);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
*clusters = g_slist_prepend (*clusters, (gpointer)point);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -356,12 +358,10 @@ create_signature (lab *input,
|
||||||
gint length,
|
gint length,
|
||||||
gint *returnlength,
|
gint *returnlength,
|
||||||
const gfloat *limits,
|
const gfloat *limits,
|
||||||
gint dims)
|
const gint dims)
|
||||||
{
|
{
|
||||||
GSList *clusters = NULL;
|
gint size1 = 0;
|
||||||
lab *rval;
|
gint size2 = 0;
|
||||||
gint size = 0;
|
|
||||||
gint i;
|
|
||||||
|
|
||||||
if (length < 1)
|
if (length < 1)
|
||||||
{
|
{
|
||||||
|
@ -369,33 +369,21 @@ create_signature (lab *input,
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
stageone (input, 0, length, 0, &size, limits, dims);
|
stageone (input, 0, length, 0, &size1, limits, dims);
|
||||||
|
|
||||||
#ifdef SIOX_DEBUG
|
#ifdef SIOX_DEBUG
|
||||||
g_printerr ("siox.c: step #1 -> %d clusters\n", size);
|
g_printerr ("siox.c: step #1 -> %d clusters\n", size1);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
clusters = NULL;
|
stagetwo (input, 0, size1, 0, &size2, limits, length * 0.001, dims);
|
||||||
|
|
||||||
stagetwo (input, 0, size, 0, &clusters, limits, length * 0.001f, dims);
|
*returnlength = size2;
|
||||||
|
|
||||||
size = g_slist_length(clusters);
|
|
||||||
rval = g_new (lab, size);
|
|
||||||
|
|
||||||
i = 0;
|
|
||||||
while (clusters != NULL)
|
|
||||||
{
|
|
||||||
rval[i++] = *((lab*) clusters->data);
|
|
||||||
clusters = g_slist_delete_link (clusters, clusters);
|
|
||||||
}
|
|
||||||
|
|
||||||
*returnlength = size;
|
|
||||||
|
|
||||||
#ifdef SIOX_DEBUG
|
#ifdef SIOX_DEBUG
|
||||||
g_printerr ("siox.c: step #2 -> %d clusters\n", returnlength[0]);
|
g_printerr ("siox.c: step #2 -> %d clusters\n", *returnlength);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
return rval;
|
return g_memdup (input, size2 * sizeof (lab));
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Smoothes mask by delegation to paint-funcs.c */
|
/* Smoothes mask by delegation to paint-funcs.c */
|
||||||
|
@ -593,7 +581,7 @@ find_max_blob (TileManager *mask,
|
||||||
gint y,
|
gint y,
|
||||||
gint width,
|
gint width,
|
||||||
gint height,
|
gint height,
|
||||||
gint sizeFactorToKeep)
|
const gint sizeFactorToKeep)
|
||||||
{
|
{
|
||||||
GSList *list = NULL;
|
GSList *list = NULL;
|
||||||
PixelRegion region;
|
PixelRegion region;
|
||||||
|
@ -766,7 +754,7 @@ siox_init (TileManager *pixels,
|
||||||
state->fgsiglen = 0;
|
state->fgsiglen = 0;
|
||||||
state->bpp = tile_manager_bpp (pixels);
|
state->bpp = tile_manager_bpp (pixels);
|
||||||
state->cache = g_hash_table_new_full (g_direct_hash,
|
state->cache = g_hash_table_new_full (g_direct_hash,
|
||||||
g_direct_equal, NULL, g_free);
|
NULL, NULL, g_free);
|
||||||
|
|
||||||
cpercep_init ();
|
cpercep_init ();
|
||||||
|
|
||||||
|
@ -890,11 +878,13 @@ siox_foreground_extract (SioxState *state,
|
||||||
surebgcount, surefgcount);
|
surebgcount, surefgcount);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
surebg = g_new (lab, surebgcount);
|
if (refinement & SIOX_REFINEMENT_ADD_FOREGROUND)
|
||||||
surefg = g_new (lab, surefgcount);
|
surefg = g_new (lab, surefgcount);
|
||||||
|
|
||||||
|
if (refinement & SIOX_REFINEMENT_ADD_BACKGROUND)
|
||||||
|
surebg = g_new (lab, surebgcount);
|
||||||
|
|
||||||
i = 0;
|
i = 0;
|
||||||
j = 0;
|
|
||||||
|
|
||||||
siox_progress_update (progress_callback, progress_data, 0.1);
|
siox_progress_update (progress_callback, progress_data, 0.1);
|
||||||
|
|
||||||
|
@ -905,33 +895,91 @@ siox_foreground_extract (SioxState *state,
|
||||||
pixel_region_init (&mapPR, mask,
|
pixel_region_init (&mapPR, mask,
|
||||||
x, y, width, height, FALSE);
|
x, y, width, height, FALSE);
|
||||||
|
|
||||||
for (pr = pixel_regions_register (2, &srcPR, &mapPR);
|
pr = pixel_regions_register (2, &srcPR, &mapPR);
|
||||||
pr != NULL; pr = pixel_regions_process (pr))
|
|
||||||
|
if (! (refinement & SIOX_REFINEMENT_ADD_FOREGROUND))
|
||||||
{
|
{
|
||||||
const guchar *src = srcPR.data;
|
for (;pr != NULL; pr = pixel_regions_process (pr))
|
||||||
const guchar *map = mapPR.data;
|
|
||||||
|
|
||||||
for (row = 0; row < srcPR.h; row++)
|
|
||||||
{
|
{
|
||||||
const guchar *s = src;
|
const guchar *src = srcPR.data;
|
||||||
const guchar *m = map;
|
const guchar *map = mapPR.data;
|
||||||
|
|
||||||
for (col = 0; col < srcPR.w; col++, m++, s += state->bpp)
|
for (row = 0; row < srcPR.h; row++)
|
||||||
{
|
{
|
||||||
if (*m < SIOX_LOW)
|
const guchar *s = src;
|
||||||
{
|
const guchar *m = map;
|
||||||
calc_lab (s, state->bpp, state->colormap, surebg + i);
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
else if (*m > SIOX_HIGH)
|
|
||||||
{
|
|
||||||
calc_lab (s, state->bpp, state->colormap, surefg + j);
|
|
||||||
j++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
src += srcPR.rowstride;
|
for (col = 0; col < srcPR.w; col++, m++, s += state->bpp)
|
||||||
map += mapPR.rowstride;
|
{
|
||||||
|
if (*m < SIOX_LOW)
|
||||||
|
{
|
||||||
|
calc_lab (s, state->bpp, state->colormap, surebg + i);
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
src += srcPR.rowstride;
|
||||||
|
map += mapPR.rowstride;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (! (refinement & SIOX_REFINEMENT_ADD_BACKGROUND))
|
||||||
|
{
|
||||||
|
for (;pr != NULL; pr = pixel_regions_process (pr))
|
||||||
|
{
|
||||||
|
const guchar *src = srcPR.data;
|
||||||
|
const guchar *map = mapPR.data;
|
||||||
|
|
||||||
|
for (row = 0; row < srcPR.h; row++)
|
||||||
|
{
|
||||||
|
const guchar *s = src;
|
||||||
|
const guchar *m = map;
|
||||||
|
|
||||||
|
for (col = 0; col < srcPR.w; col++, m++, s += state->bpp)
|
||||||
|
{
|
||||||
|
if (*m > SIOX_HIGH)
|
||||||
|
{
|
||||||
|
calc_lab (s, state->bpp, state->colormap, surefg + i);
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
src += srcPR.rowstride;
|
||||||
|
map += mapPR.rowstride;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else /* both changed */
|
||||||
|
{
|
||||||
|
j = 0;
|
||||||
|
|
||||||
|
for (;pr != NULL; pr = pixel_regions_process (pr))
|
||||||
|
{
|
||||||
|
const guchar *src = srcPR.data;
|
||||||
|
const guchar *map = mapPR.data;
|
||||||
|
|
||||||
|
for (row = 0; row < srcPR.h; row++)
|
||||||
|
{
|
||||||
|
const guchar *s = src;
|
||||||
|
const guchar *m = map;
|
||||||
|
|
||||||
|
for (col = 0; col < srcPR.w; col++, m++, s += state->bpp)
|
||||||
|
{
|
||||||
|
if (*m < SIOX_LOW)
|
||||||
|
{
|
||||||
|
calc_lab (s, state->bpp, state->colormap, surebg + i);
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
else if (*m > SIOX_HIGH)
|
||||||
|
{
|
||||||
|
calc_lab (s, state->bpp, state->colormap, surefg + j);
|
||||||
|
j++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
src += srcPR.rowstride;
|
||||||
|
map += mapPR.rowstride;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -939,6 +987,7 @@ siox_foreground_extract (SioxState *state,
|
||||||
|
|
||||||
if (refinement & SIOX_REFINEMENT_ADD_BACKGROUND)
|
if (refinement & SIOX_REFINEMENT_ADD_BACKGROUND)
|
||||||
{
|
{
|
||||||
|
|
||||||
/* Create color signature for the background */
|
/* Create color signature for the background */
|
||||||
state->bgsig = create_signature (surebg, surebgcount,
|
state->bgsig = create_signature (surebg, surebgcount,
|
||||||
&state->bgsiglen, limits,
|
&state->bgsiglen, limits,
|
||||||
|
@ -976,12 +1025,13 @@ siox_foreground_extract (SioxState *state,
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
pixel_region_init (&srcPR, state->pixels,
|
pixel_region_init (&srcPR, state->pixels,
|
||||||
x - state->offset_x, y -state-> offset_y, width, height,
|
x - state->offset_x, y - state->offset_y, width, height,
|
||||||
FALSE);
|
FALSE);
|
||||||
pixel_region_init (&mapPR, mask, x, y, width, height, TRUE);
|
pixel_region_init (&mapPR, mask, x, y, width, height, TRUE);
|
||||||
|
|
||||||
for (pr = pixel_regions_register (2, &srcPR, &mapPR);
|
for (pr = pixel_regions_register (2, &srcPR, &mapPR);
|
||||||
pr != NULL; pr = pixel_regions_process (pr))
|
pr != NULL;
|
||||||
|
pr = pixel_regions_process (pr))
|
||||||
{
|
{
|
||||||
const guchar *src = srcPR.data;
|
const guchar *src = srcPR.data;
|
||||||
guchar *map = mapPR.data;
|
guchar *map = mapPR.data;
|
||||||
|
@ -1058,7 +1108,6 @@ siox_foreground_extract (SioxState *state,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
cr->bgdist = minbg;
|
|
||||||
cr->fgdist = minfg;
|
cr->fgdist = minfg;
|
||||||
|
|
||||||
g_hash_table_insert (state->cache, GINT_TO_POINTER (key), cr);
|
g_hash_table_insert (state->cache, GINT_TO_POINTER (key), cr);
|
||||||
|
@ -1152,7 +1201,8 @@ siox_drb (SioxState *state,
|
||||||
brushradius * 2, brushradius * 2, TRUE);
|
brushradius * 2, brushradius * 2, TRUE);
|
||||||
|
|
||||||
for (pr = pixel_regions_register (2, &srcPR, &mapPR);
|
for (pr = pixel_regions_register (2, &srcPR, &mapPR);
|
||||||
pr != NULL; pr = pixel_regions_process (pr))
|
pr != NULL;
|
||||||
|
pr = pixel_regions_process (pr))
|
||||||
{
|
{
|
||||||
const guchar *src = srcPR.data;
|
const guchar *src = srcPR.data;
|
||||||
guchar *map = mapPR.data;
|
guchar *map = mapPR.data;
|
||||||
|
@ -1199,7 +1249,6 @@ siox_drb (SioxState *state,
|
||||||
alpha = 0.0; /* avoid div by zero */
|
alpha = 0.0; /* avoid div by zero */
|
||||||
else
|
else
|
||||||
alpha = 1.0 - MIN (mindistfg / mindistbg, 1.0);
|
alpha = 1.0 - MIN (mindistfg / mindistbg, 1.0);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (alpha < threshold)
|
if (alpha < threshold)
|
||||||
|
@ -1207,15 +1256,16 @@ siox_drb (SioxState *state,
|
||||||
/* background with a certain confidence
|
/* background with a certain confidence
|
||||||
* to be decided by user.
|
* to be decided by user.
|
||||||
*/
|
*/
|
||||||
alpha = 0.0;
|
*m = 0;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
*m = (gint) (255.999 * alpha);
|
||||||
}
|
}
|
||||||
|
|
||||||
*m = (gint) 255 *alpha;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
src += srcPR.rowstride;
|
src += srcPR.rowstride;
|
||||||
map += mapPR.rowstride;
|
map += mapPR.rowstride;
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue