Bug 155733 - need to check return values of gimp_drawable_mask_bounds()

Mask intersect fix for photocopy plug-in.
This commit is contained in:
Louis Benazet 2015-09-15 20:33:51 +02:00 committed by Michael Natterer
parent a3f2b1ab68
commit e7715dca35
1 changed files with 12 additions and 16 deletions

View File

@ -273,7 +273,7 @@ photocopy (GimpDrawable *drawable,
{ {
GimpPixelRgn src_rgn, dest_rgn; GimpPixelRgn src_rgn, dest_rgn;
GimpPixelRgn *pr; GimpPixelRgn *pr;
gint width, height; gint x, y, width, height;
gint bytes; gint bytes;
gboolean has_alpha; gboolean has_alpha;
guchar *dest1; guchar *dest1;
@ -288,7 +288,6 @@ photocopy (GimpDrawable *drawable,
gdouble bd_p2[5], bd_m2[5]; gdouble bd_p2[5], bd_m2[5];
gdouble *val_p1, *val_m1, *vp1, *vm1; gdouble *val_p1, *val_m1, *vp1, *vm1;
gdouble *val_p2, *val_m2, *vp2, *vm2; gdouble *val_p2, *val_m2, *vp2, *vm2;
gint x1, y1;
gint i, j; gint i, j;
gint row, col; gint row, col;
gint terms; gint terms;
@ -306,17 +305,14 @@ photocopy (GimpDrawable *drawable,
if (preview) if (preview)
{ {
gimp_preview_get_position (preview, &x1, &y1); gimp_preview_get_position (preview, &x, &y);
gimp_preview_get_size (preview, &width, &height); gimp_preview_get_size (preview, &width, &height);
} }
else else
{ {
gint x2, y2; if (! gimp_drawable_mask_intersect (drawable->drawable_id,
&x, &y, &width, &height))
gimp_drawable_mask_bounds (drawable->drawable_id, &x1, &y1, &x2, &y2); return;
width = x2 - x1;
height = y2 - y1;
} }
bytes = drawable->bpp; bytes = drawable->bpp;
@ -334,14 +330,14 @@ photocopy (GimpDrawable *drawable,
max_progress = width * height * 3; max_progress = width * height * 3;
gimp_pixel_rgn_init (&src_rgn, drawable, gimp_pixel_rgn_init (&src_rgn, drawable,
x1, y1, width, height, FALSE, FALSE); x, y, width, height, FALSE, FALSE);
for (pr = gimp_pixel_rgns_register (1, &src_rgn); for (pr = gimp_pixel_rgns_register (1, &src_rgn);
pr != NULL; pr != NULL;
pr = gimp_pixel_rgns_process (pr)) pr = gimp_pixel_rgns_process (pr))
{ {
guchar *src_ptr = src_rgn.data; guchar *src_ptr = src_rgn.data;
guchar *dest_ptr = dest1 + (src_rgn.y - y1) * width + (src_rgn.x - x1); guchar *dest_ptr = dest1 + (src_rgn.y - y) * width + (src_rgn.x - x);
for (row = 0; row < src_rgn.h; row++) for (row = 0; row < src_rgn.h; row++)
{ {
@ -529,8 +525,8 @@ photocopy (GimpDrawable *drawable,
ramp_up = compute_ramp (dest1, dest2, width * height, 1.0 - pvals.pct_white, 0); ramp_up = compute_ramp (dest1, dest2, width * height, 1.0 - pvals.pct_white, 0);
/* Initialize the pixel regions. */ /* Initialize the pixel regions. */
gimp_pixel_rgn_init (&src_rgn, drawable, x1, y1, width, height, FALSE, FALSE); gimp_pixel_rgn_init (&src_rgn, drawable, x, y, width, height, FALSE, FALSE);
gimp_pixel_rgn_init (&dest_rgn, drawable, x1, y1, width, height, gimp_pixel_rgn_init (&dest_rgn, drawable, x, y, width, height,
(preview == NULL), TRUE); (preview == NULL), TRUE);
pr = gimp_pixel_rgns_register (2, &src_rgn, &dest_rgn); pr = gimp_pixel_rgns_register (2, &src_rgn, &dest_rgn);
@ -539,8 +535,8 @@ photocopy (GimpDrawable *drawable,
{ {
guchar *src_ptr = src_rgn.data; guchar *src_ptr = src_rgn.data;
guchar *dest_ptr = dest_rgn.data; guchar *dest_ptr = dest_rgn.data;
guchar *blur_ptr = dest1 + (src_rgn.y - y1) * width + (src_rgn.x - x1); guchar *blur_ptr = dest1 + (src_rgn.y - y) * width + (src_rgn.x - x);
guchar *avg_ptr = dest2 + (src_rgn.y - y1) * width + (src_rgn.x - x1); guchar *avg_ptr = dest2 + (src_rgn.y - y) * width + (src_rgn.x - x);
gdouble diff, mult; gdouble diff, mult;
gdouble lightness = 0.0; gdouble lightness = 0.0;
@ -621,7 +617,7 @@ photocopy (GimpDrawable *drawable,
/* merge the shadow, update the drawable */ /* merge the shadow, update the drawable */
gimp_drawable_flush (drawable); gimp_drawable_flush (drawable);
gimp_drawable_merge_shadow (drawable->drawable_id, TRUE); 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);
} }
/* free up buffers */ /* free up buffers */