Commit 5c6b8e9f authored by Sven Neumann's avatar Sven Neumann Committed by Sven Neumann

added the possibility to specify a clip rectangle.

2005-08-08  Sven Neumann  <sven@gimp.org>

	* app/core/gimpscanconvert.[ch]: added the possibility to specify
	a clip rectangle.

	* app/base/siox.c (find_max_blob): use g_try_malloc().
parent 6ed08d11
2005-08-08 Sven Neumann <sven@gimp.org>
* app/core/gimpscanconvert.[ch]: added the possibility to specify
a clip rectangle.
* app/base/siox.c (find_max_blob): use g_try_malloc().
2005-08-08 Sven Neumann <sven@gimp.org>
* app/base/siox.c (find_max_blob): optimizations.
......
......@@ -571,9 +571,9 @@ find_max_blob (TileManager *mask,
gint width,
gint height)
{
GQueue *q = g_queue_new ();
gint length = width * height;
gint *labelfield = g_new0 (gint, length);
GQueue *q;
gint *labels;
glong size;
PixelRegion region;
gpointer pr;
gint row, col;
......@@ -581,6 +581,19 @@ find_max_blob (TileManager *mask,
gint maxblob = 1;
gint maxregion = 0;
/* FIXME: this function uses an insane amount of memory */
size = width * height * sizeof (gint);
labels = g_try_malloc (size);
if (! labels)
{
g_warning ("%s: couldn't allocate %ld bytes", G_STRFUNC, size);
return;
}
memset (labels, 0, size);
q = g_queue_new ();
pixel_region_init (&region, mask, x, y, width, height, FALSE);
for (pr = pixel_regions_register (1, &region);
......@@ -599,12 +612,12 @@ find_max_blob (TileManager *mask,
{
gint regioncount = 0;
if (labelfield[i])
if (labels[i])
continue;
if (! (*d & 0x80))
{
labelfield[i] = -1;
labels[i] = -1;
continue;
}
......@@ -617,7 +630,7 @@ find_max_blob (TileManager *mask,
gint pos_y;
guchar val;
if (labelfield[pos])
if (labels[pos])
continue;
pos_x = pos % width;
......@@ -627,25 +640,25 @@ find_max_blob (TileManager *mask,
if (val & 0x80)
{
labelfield[pos] = curlabel;
labels[pos] = curlabel;
regioncount++;
if (pos_x + 1 < width && ! labelfield[pos + 1])
if (pos_x + 1 < width && ! labels[pos + 1])
g_queue_push_tail (q, GINT_TO_POINTER (pos + 1));
if (pos_x > 0 && ! labelfield[pos - 1])
if (pos_x > 0 && ! labels[pos - 1])
g_queue_push_tail (q, GINT_TO_POINTER (pos - 1));
if (pos_y + 1 < height && ! labelfield[pos + width])
if (pos_y + 1 < height && ! labels[pos + width])
g_queue_push_tail (q, GINT_TO_POINTER (pos + width));
if (pos_y > 0 && ! labelfield[pos - width])
if (pos_y > 0 && ! labels[pos - width])
g_queue_push_tail (q, GINT_TO_POINTER (pos - width));
}
else
{
labelfield[pos] = -1;
labels[pos] = -1;
}
}
......@@ -680,16 +693,14 @@ find_max_blob (TileManager *mask,
gint i = index;
for (col = 0; col < region.w; col++, d++, i++)
{
*d = (labelfield[i] == maxblob) ? 255 : 0;
}
*d = (labels[i] == maxblob) ? 255 : 0;
data += region.rowstride;
index += width;
}
}
g_free (labelfield);
g_free (labels);
}
static inline void
......
......@@ -39,6 +39,12 @@ struct _GimpScanConvert
{
gdouble ratio_xy;
gboolean clip;
gint clip_x;
gint clip_y;
gint clip_w;
gint clip_h;
/* stuff necessary for the _add_polygons API... :-/ */
gboolean got_first;
gboolean need_closing;
......@@ -125,6 +131,22 @@ gimp_scan_convert_set_pixel_ratio (GimpScanConvert *sc,
}
void
gimp_scan_convert_set_clip_rectangle (GimpScanConvert *sc,
gint x,
gint y,
gint width,
gint height)
{
g_return_if_fail (sc != NULL);
sc->clip = TRUE;
sc->clip_x = x;
sc->clip_y = y;
sc->clip_w = width;
sc->clip_h = height;
}
/* Add "n_points" from "points" to the polygon currently being
* described by "scan_converter". DEPRECATED.
*/
......@@ -502,16 +524,27 @@ gimp_scan_convert_render_internal (GimpScanConvert *sc,
PixelRegion maskPR;
gpointer pr;
gpointer callback;
gint x, y;
gint width, height;
gimp_scan_convert_finish (sc);
if (!sc->svp)
return;
pixel_region_init (&maskPR, tile_manager, 0, 0,
tile_manager_width (tile_manager),
tile_manager_height (tile_manager),
TRUE);
x = 0;
y = 0;
width = tile_manager_width (tile_manager);
height = tile_manager_height (tile_manager);
if (sc->clip &&
! gimp_rectangle_intersect (x, y, width, height,
sc->clip_x, sc->clip_y,
sc->clip_w, sc->clip_h,
&x, &y, &width, &height))
return;
pixel_region_init (&maskPR, tile_manager, x, y, width, height, TRUE);
g_return_if_fail (maskPR.bytes == 1);
......@@ -533,10 +566,8 @@ gimp_scan_convert_render_internal (GimpScanConvert *sc,
sc->x1 = off_x + maskPR.x + maskPR.w;
art_svp_render_aa (sc->svp,
sc->x0,
off_y + maskPR.y,
sc->x1,
off_y + maskPR.y + maskPR.h,
sc->x0, off_y + maskPR.y,
sc->x1, off_y + maskPR.y + maskPR.h,
callback, sc);
}
}
......@@ -620,7 +651,9 @@ gimp_scan_convert_render_callback (gpointer user_data,
{
GimpScanConvert *sc = user_data;
gint cur_value = start_value;
gint k, run_x0, run_x1;
gint run_x0;
gint run_x1;
gint k;
#define VALUE_TO_PIXEL(x) (sc->antialias ? \
((x) >> 16) : \
......
......@@ -31,6 +31,12 @@ void gimp_scan_convert_free (GimpScanConvert *scan_converter)
void gimp_scan_convert_set_pixel_ratio (GimpScanConvert *sc,
gdouble ratio_xy);
void gimp_scan_convert_set_clip_rectangle (GimpScanConvert *sc,
gint x,
gint y,
gint width,
gint height);
/* Add "npoints" from "pointlist" to the polygon currently being
* described by "scan_converter". DEPRECATED.
*/
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment