[gimp/metadata-browser] Bug 155733 - need to check return values of gimp_drawable_mask_bounds()
- From: Roman Joost <romanofski src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gimp/metadata-browser] Bug 155733 - need to check return values of gimp_drawable_mask_bounds()
- Date: Wed, 12 Sep 2012 22:55:30 +0000 (UTC)
commit f7d74f5e35d341e787b2f7a628fb7373d3d70c4a
Author: Ville Sokk <embassyhill gmail com>
Date: Fri Feb 17 19:56:11 2012 +0200
Bug 155733 - need to check return values of gimp_drawable_mask_bounds()
Mask intersect fixes for some plug-ins.
plug-ins/common/edge-sobel.c | 29 ++++++++---------
plug-ins/common/noise-randomize.c | 42 ++++++++++++-------------
plug-ins/fractal-explorer/fractal-explorer.c | 15 ++++-----
plug-ins/maze/maze.c | 18 ++++++-----
plug-ins/maze/maze.h | 4 +-
plug-ins/pagecurl/pagecurl.c | 32 ++++++++-----------
6 files changed, 66 insertions(+), 74 deletions(-)
---
diff --git a/plug-ins/common/edge-sobel.c b/plug-ins/common/edge-sobel.c
index f6b0c83..90fb41d 100644
--- a/plug-ins/common/edge-sobel.c
+++ b/plug-ins/common/edge-sobel.c
@@ -353,24 +353,23 @@ sobel (GimpDrawable *drawable,
guchar *next_row, *nr;
guchar *tmp;
gint row, col;
- gint x1, y1, x2, y2;
+ gint x, y;
gboolean alpha;
gint counter;
guchar *preview_buffer = NULL;
if (preview)
{
- gimp_preview_get_position (preview, &x1, &y1);
+ gimp_preview_get_position (preview, &x, &y);
gimp_preview_get_size (preview, &width, &height);
- x2 = x1 + width;
- y2 = y1 + height;
}
else
{
- gimp_drawable_mask_bounds (drawable->drawable_id, &x1, &y1, &x2, &y2);
+ if (! gimp_drawable_mask_intersect (drawable->drawable_id,
+ &x, &y, &width, &height))
+ return;
+
gimp_progress_init (_("Sobel edge detecting"));
- width = x2 - x1;
- height = y2 - y1;
}
/* Get the size of the input image. (This will/must be the same
@@ -405,14 +404,14 @@ sobel (GimpDrawable *drawable,
cr = cur_row + bytes;
nr = next_row + bytes;
- sobel_prepare_row (&srcPR, pr, x1, y1 - 1, width);
- sobel_prepare_row (&srcPR, cr, x1, y1, width);
+ sobel_prepare_row (&srcPR, pr, x, y - 1, width);
+ sobel_prepare_row (&srcPR, cr, x, y, width);
counter =0;
/* loop through the rows, applying the sobel convolution */
- for (row = y1; row < y2; row++)
+ for (row = y; row < y + height; row++)
{
/* prepare the next row */
- sobel_prepare_row (&srcPR, nr, x1, row + 1, width);
+ sobel_prepare_row (&srcPR, nr, x, row + 1, width);
d = dest;
for (col = 0; col < width * bytes; col++)
@@ -450,16 +449,16 @@ sobel (GimpDrawable *drawable,
/* store the dest */
if (preview)
{
- memcpy (preview_buffer + width * (row - y1) * bytes,
+ memcpy (preview_buffer + width * (row - y) * bytes,
dest,
width * bytes);
}
else
{
- gimp_pixel_rgn_set_row (&destPR, dest, x1, row, width);
+ gimp_pixel_rgn_set_row (&destPR, dest, x, row, width);
if ((row % 20) == 0)
- gimp_progress_update ((double) row / (double) (y2 - y1));
+ gimp_progress_update ((double) row / (double) height);
}
}
@@ -474,7 +473,7 @@ sobel (GimpDrawable *drawable,
/* update the sobeled region */
gimp_drawable_flush (drawable);
gimp_drawable_merge_shadow (drawable->drawable_id, TRUE);
- gimp_drawable_update (drawable->drawable_id, x1, y1, width, height);
+ gimp_drawable_update (drawable->drawable_id, x, y, width, height);
}
g_free (prev_row);
diff --git a/plug-ins/common/noise-randomize.c b/plug-ins/common/noise-randomize.c
index c439801..c095132 100644
--- a/plug-ins/common/noise-randomize.c
+++ b/plug-ins/common/noise-randomize.c
@@ -480,22 +480,20 @@ randomize (GimpDrawable *drawable,
guchar *next_row, *nr;
guchar *tmp;
gint row, col;
- gint x1, y1, x2, y2;
+ gint x, y;
gint cnt;
gint i, j, k;
if (preview)
{
- gimp_preview_get_position (preview, &x1, &y1);
+ gimp_preview_get_position (preview, &x, &y);
gimp_preview_get_size (preview, &width, &height);
- x2 = x1 + width;
- y2 = y1 + height;
}
else
{
- gimp_drawable_mask_bounds (drawable->drawable_id, &x1, &y1, &x2, &y2);
- width = (x2 - x1);
- height = (y2 - y1);
+ if (! gimp_drawable_mask_intersect (drawable->drawable_id,
+ &x, &y, &width, &height))
+ return;
}
bytes = drawable->bpp;
@@ -503,17 +501,17 @@ randomize (GimpDrawable *drawable,
/*
* allocate row buffers
*/
- prev_row = g_new (guchar, (x2 - x1 + 2) * bytes);
- cur_row = g_new (guchar, (x2 - x1 + 2) * bytes);
- next_row = g_new (guchar, (x2 - x1 + 2) * bytes);
- dest = g_new (guchar, (x2 - x1) * bytes);
+ prev_row = g_new (guchar, (width + 2) * bytes);
+ cur_row = g_new (guchar, (width + 2) * bytes);
+ next_row = g_new (guchar, (width + 2) * bytes);
+ dest = g_new (guchar, width * bytes);
/*
* initialize the pixel regions
*/
- gimp_pixel_rgn_init (&srcPR, drawable, x1, y1, width, height, FALSE, FALSE);
- gimp_pixel_rgn_init (&destPR, drawable, x1, y1, width, height, TRUE, TRUE);
- gimp_pixel_rgn_init (&destPR2, drawable, x1, y1, width, height, TRUE, TRUE);
+ gimp_pixel_rgn_init (&srcPR, drawable, x, y, width, height, FALSE, FALSE);
+ gimp_pixel_rgn_init (&destPR, drawable, x, y, width, height, TRUE, TRUE);
+ gimp_pixel_rgn_init (&destPR2, drawable, x, y, width, height, TRUE, TRUE);
sp = &srcPR;
dp = &destPR;
tp = NULL;
@@ -527,18 +525,18 @@ randomize (GimpDrawable *drawable,
/*
* prepare the first row and previous row
*/
- randomize_prepare_row (sp, pr, x1, y1 - 1, (x2 - x1));
- randomize_prepare_row (sp, cr, x1, y1, (x2 - x1));
+ randomize_prepare_row (sp, pr, x, y - 1, width);
+ randomize_prepare_row (sp, cr, x, y, width);
/*
* loop through the rows, applying the selected convolution
*/
- for (row = y1; row < y2; row++)
+ for (row = y; row < y + height; row++)
{
/* prepare the next row */
- randomize_prepare_row (sp, nr, x1, row + 1, (x2 - x1));
+ randomize_prepare_row (sp, nr, x, row + 1, width);
d = dest;
- for (col = 0; col < (x2 - x1); col++)
+ for (col = 0; col < width; col++)
{
if (g_rand_int_range (gr, 0, 100) <= (gint) pivals.rndm_pct)
{
@@ -636,7 +634,7 @@ randomize (GimpDrawable *drawable,
* Save the modified row, shuffle the row pointers, and every
* so often, update the progress meter.
*/
- gimp_pixel_rgn_set_row (dp, dest, x1, row, (x2 - x1));
+ gimp_pixel_rgn_set_row (dp, dest, x, row, width);
tmp = pr;
pr = cr;
@@ -646,7 +644,7 @@ randomize (GimpDrawable *drawable,
if (! preview && PROG_UPDATE_TIME)
{
gdouble base = (gdouble) cnt / pivals.rndm_rcount;
- gdouble inc = (gdouble) row / ((y2 - y1) * pivals.rndm_rcount);
+ gdouble inc = (gdouble) row / (height * pivals.rndm_rcount);
gimp_progress_update (base + inc);
}
@@ -687,7 +685,7 @@ randomize (GimpDrawable *drawable,
{
gimp_drawable_flush (drawable);
gimp_drawable_merge_shadow (drawable->drawable_id, TRUE);
- gimp_drawable_update (drawable->drawable_id, x1, y1, (x2 - x1), (y2 - y1));
+ gimp_drawable_update (drawable->drawable_id, x, y, width, height);
}
/*
diff --git a/plug-ins/fractal-explorer/fractal-explorer.c b/plug-ins/fractal-explorer/fractal-explorer.c
index 6576940..f2b4c26 100644
--- a/plug-ins/fractal-explorer/fractal-explorer.c
+++ b/plug-ins/fractal-explorer/fractal-explorer.c
@@ -82,10 +82,8 @@ gdouble xbild;
gdouble ybild;
gdouble xdiff;
gdouble ydiff;
-gint sel_x1;
-gint sel_y1;
-gint sel_x2;
-gint sel_y2;
+gint sel_x;
+gint sel_y;
gint preview_width;
gint preview_height;
gdouble *gg;
@@ -281,11 +279,10 @@ run (const gchar *name,
/* Get the specified drawable */
drawable = gimp_drawable_get (param[2].data.d_drawable);
- gimp_drawable_mask_bounds (drawable->drawable_id,
- &sel_x1, &sel_y1, &sel_x2, &sel_y2);
-
- sel_width = sel_x2 - sel_x1;
- sel_height = sel_y2 - sel_y1;
+ if (! gimp_drawable_mask_intersect (drawable->drawable_id,
+ &sel_x, &sel_y,
+ &sel_width, &sel_height))
+ return;
/* Calculate preview size */
if (sel_width > sel_height)
diff --git a/plug-ins/maze/maze.c b/plug-ins/maze/maze.c
index 05e67cd..d0881f9 100644
--- a/plug-ins/maze/maze.c
+++ b/plug-ins/maze/maze.c
@@ -92,8 +92,8 @@ MazeValues mvals =
GRand *gr;
-guint sel_w;
-guint sel_h;
+gint sel_w;
+gint sel_h;
MAIN ()
@@ -147,7 +147,7 @@ run (const gchar *name,
GimpDrawable *drawable;
GimpRunMode run_mode;
GimpPDBStatusType status = GIMP_PDB_SUCCESS;
- gint x1, y1, x2, y2;
+ gint x, y;
#ifdef MAZE_DEBUG
g_print("maze PID: %d\n",getpid());
@@ -166,17 +166,19 @@ run (const gchar *name,
drawable = gimp_drawable_get (param[2].data.d_drawable);
+ /* get the selection width and height for the GUI. Return if the
+ * selection and drawable do not intersect.
+ */
+ if (! gimp_drawable_mask_intersect (drawable->drawable_id,
+ &x, &y, &sel_w, &sel_h))
+ return;
+
switch (run_mode)
{
case GIMP_RUN_INTERACTIVE:
/* Possibly retrieve data */
gimp_get_data (PLUG_IN_PROC, &mvals);
- /* The interface needs to know the dimensions of the image... */
- gimp_drawable_mask_bounds (drawable->drawable_id, &x1, &y1, &x2, &y2);
- sel_w = x2 - x1;
- sel_h = y2 - y1;
-
/* Acquire info with a dialog */
if (! maze_dialog ())
{
diff --git a/plug-ins/maze/maze.h b/plug-ins/maze/maze.h
index 8d5bc8a..18eaf9f 100644
--- a/plug-ins/maze/maze.h
+++ b/plug-ins/maze/maze.h
@@ -60,8 +60,8 @@ enum CellTypes {
};
extern MazeValues mvals;
-extern guint sel_w;
-extern guint sel_h;
+extern gint sel_w;
+extern gint sel_h;
extern GRand *gr;
diff --git a/plug-ins/pagecurl/pagecurl.c b/plug-ins/pagecurl/pagecurl.c
index 18ea698..9609529 100644
--- a/plug-ins/pagecurl/pagecurl.c
+++ b/plug-ins/pagecurl/pagecurl.c
@@ -159,7 +159,7 @@ static const guint8 *curl_pixbufs[] =
static GtkWidget *curl_image = NULL;
-static gint sel_x1, sel_y1, sel_x2, sel_y2;
+static gint sel_x, sel_y;
static gint true_sel_width, true_sel_height;
static gint sel_width, sel_height;
static gint drawable_position;
@@ -262,8 +262,10 @@ run (const gchar *name,
drawable_id = param[2].data.d_drawable;
image_id = param[1].data.d_image;
- if (gimp_drawable_is_rgb (drawable_id)
- || gimp_drawable_is_gray (drawable_id))
+ if ((gimp_drawable_is_rgb (drawable_id) ||
+ gimp_drawable_is_gray (drawable_id)) &&
+ gimp_drawable_mask_intersect (drawable_id, &sel_x, &sel_y,
+ &true_sel_width, &true_sel_height))
{
switch (run_mode)
{
@@ -648,13 +650,6 @@ init_calculation (gint32 drawable_id)
image_layers[drawable_position] != drawable_id)
drawable_position++;
- /* Get the bounds of the active selection */
- gimp_drawable_mask_bounds (drawable_id,
- &sel_x1, &sel_y1, &sel_x2, &sel_y2);
-
- true_sel_width = sel_x2 - sel_x1;
- true_sel_height = sel_y2 - sel_y1;
-
switch (curl.orientation)
{
case CURL_ORIENTATION_VERTICAL:
@@ -747,7 +742,7 @@ do_curl_effect (gint32 drawable_id)
gimp_drawable_fill (curl_layer->drawable_id, GIMP_TRANSPARENT_FILL);
gimp_drawable_offsets (drawable_id, &x1, &y1);
- gimp_layer_set_offsets (curl_layer->drawable_id, sel_x1 + x1, sel_y1 + y1);
+ gimp_layer_set_offsets (curl_layer->drawable_id, sel_x + x1, sel_y + y1);
gimp_tile_cache_ntiles (2 * (curl_layer->width / gimp_tile_width () + 1));
gimp_pixel_rgn_init (&dest_rgn, curl_layer,
@@ -941,10 +936,10 @@ clear_curled_region (gint32 drawable_id)
gimp_tile_cache_ntiles (2 * (drawable->width / gimp_tile_width () + 1));
gimp_pixel_rgn_init (&src_rgn, drawable,
- sel_x1, sel_y1, true_sel_width, true_sel_height,
+ sel_x, sel_y, true_sel_width, true_sel_height,
FALSE, FALSE);
gimp_pixel_rgn_init (&dest_rgn, drawable,
- sel_x1, sel_y1, true_sel_width, true_sel_height,
+ sel_x, sel_y, true_sel_width, true_sel_height,
TRUE, TRUE);
alpha_pos = dest_rgn.bpp - 1;
@@ -967,16 +962,16 @@ clear_curled_region (gint32 drawable_id)
{
case CURL_ORIENTATION_VERTICAL:
x = (CURL_EDGE_RIGHT (curl.edge) ?
- x1 - sel_x1 : sel_width - 1 - (x1 - sel_x1));
+ x1 - sel_x : sel_width - 1 - (x1 - sel_x));
y = (CURL_EDGE_UPPER (curl.edge) ?
- y1 - sel_y1 : sel_height - 1 - (y1 - sel_y1));
+ y1 - sel_y : sel_height - 1 - (y1 - sel_y));
break;
case CURL_ORIENTATION_HORIZONTAL:
x = (CURL_EDGE_LOWER (curl.edge) ?
- y1 - sel_y1 : sel_width - 1 - (y1 - sel_y1));
+ y1 - sel_y : sel_width - 1 - (y1 - sel_y));
y = (CURL_EDGE_LEFT (curl.edge) ?
- x1 - sel_x1 : sel_height - 1 - (x1 - sel_x1));
+ x1 - sel_x : sel_height - 1 - (x1 - sel_x));
break;
}
@@ -1012,7 +1007,8 @@ clear_curled_region (gint32 drawable_id)
gimp_drawable_flush (drawable);
gimp_drawable_merge_shadow (drawable_id, TRUE);
gimp_drawable_update (drawable_id,
- sel_x1, sel_y1, true_sel_width, true_sel_height);
+ sel_x, sel_y,
+ true_sel_width, true_sel_height);
gimp_drawable_detach (drawable);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]