From cb48cef8be2c4a1e6b891f55fc1b08fd0976084a Mon Sep 17 00:00:00 2001 From: Michael Natterer Date: Tue, 19 Oct 2004 22:52:04 +0000 Subject: [PATCH] added gimp_drawable_mask_intersect() which returns the same bounding box 2004-10-20 Michael Natterer * app/core/gimpdrawable.[ch]: added gimp_drawable_mask_intersect() which returns the same bounding box as gimp_drawable_mask_bounds(), but returns TRUE only if there is a non-empty intersection between the drawable and the selection, or no selection at all. It also returns the intersection as x,y,width,height instead of the eeky x1,y1,x2,y2. * app/core/gimp-edit.c * app/core/gimpdrawable-blend.c * app/core/gimpdrawable-bucket-fill.c * app/core/gimpdrawable-desaturate.c * app/core/gimpdrawable-equalize.c * app/core/gimpdrawable-histogram.c * app/core/gimpdrawable-invert.c * app/core/gimpdrawable-stroke.c * app/core/gimpimagemap.c * app/core/gimpselection.c * tools/pdbgen/pdb/color.pdb * tools/pdbgen/pdb/transform_tools.pdb: either switch from gimp_drawable_mask_bounds() to _intersect() or check the return values of _mask_bounds() manually to avoid operations on empty areas. Return successfully because it's a nop, not a failure. Fixes bug #155733 for the core. * app/pdb/color_cmds.c * app/pdb/transform_tools_cmds.c: regenerated. --- ChangeLog | 29 ++ app/core/gimp-edit.c | 24 +- app/core/gimpdrawable-blend.c | 23 +- app/core/gimpdrawable-bucket-fill.c | 9 +- app/core/gimpdrawable-desaturate.c | 12 +- app/core/gimpdrawable-equalize.c | 21 +- app/core/gimpdrawable-histogram.c | 6 +- app/core/gimpdrawable-invert.c | 16 +- app/core/gimpdrawable-stroke.c | 24 +- app/core/gimpdrawable.c | 73 +++- app/core/gimpdrawable.h | 13 +- app/core/gimpimagemap.c | 52 +-- app/core/gimpselection.c | 9 +- app/pdb/color_cmds.c | 553 ++++++++++++++------------- app/pdb/transform_tools_cmds.c | 185 ++++----- tools/pdbgen/pdb/color.pdb | 534 ++++++++++++++------------ tools/pdbgen/pdb/transform_tools.pdb | 185 ++++----- 17 files changed, 971 insertions(+), 797 deletions(-) diff --git a/ChangeLog b/ChangeLog index 1bd1af4610..bcc7c4a9e8 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,32 @@ +2004-10-20 Michael Natterer + + * app/core/gimpdrawable.[ch]: added gimp_drawable_mask_intersect() + which returns the same bounding box as gimp_drawable_mask_bounds(), + but returns TRUE only if there is a non-empty intersection between + the drawable and the selection, or no selection at all. It also + returns the intersection as x,y,width,height instead of the + eeky x1,y1,x2,y2. + + * app/core/gimp-edit.c + * app/core/gimpdrawable-blend.c + * app/core/gimpdrawable-bucket-fill.c + * app/core/gimpdrawable-desaturate.c + * app/core/gimpdrawable-equalize.c + * app/core/gimpdrawable-histogram.c + * app/core/gimpdrawable-invert.c + * app/core/gimpdrawable-stroke.c + * app/core/gimpimagemap.c + * app/core/gimpselection.c + * tools/pdbgen/pdb/color.pdb + * tools/pdbgen/pdb/transform_tools.pdb: either switch from + gimp_drawable_mask_bounds() to _intersect() or check the return + values of _mask_bounds() manually to avoid operations on empty + areas. Return successfully because it's a nop, not a failure. + Fixes bug #155733 for the core. + + * app/pdb/color_cmds.c + * app/pdb/transform_tools_cmds.c: regenerated. + 2004-10-19 Michael Natterer * app/tools/gimptextoptions.c (gimp_text_options_gui): removed diff --git a/app/core/gimp-edit.c b/app/core/gimp-edit.c index 6e2d139b74..e2f2aec573 100644 --- a/app/core/gimp-edit.c +++ b/app/core/gimp-edit.c @@ -130,10 +130,6 @@ gimp_edit_paste (GimpImage *gimage, if (! layer) return NULL; - /* Start a group undo */ - gimp_image_undo_group_start (gimage, GIMP_UNDO_GROUP_EDIT_PASTE, - _("Paste")); - if (drawable) { /* if pasting to a drawable */ @@ -198,6 +194,10 @@ gimp_edit_paste (GimpImage *gimage, GIMP_ITEM (layer)->offset_x = offset_x; GIMP_ITEM (layer)->offset_y = offset_y; + /* Start a group undo */ + gimp_image_undo_group_start (gimage, GIMP_UNDO_GROUP_EDIT_PASTE, + _("Paste")); + /* If there is a selection mask clear it-- * this might not always be desired, but in general, * it seems like the correct behavior. @@ -388,15 +388,13 @@ gimp_edit_fill_internal (GimpImage *gimage, { TileManager *buf_tiles; PixelRegion bufPR; - gint x1, y1, x2, y2; + gint x, y, width, height; gint tiles_bytes; guchar col[MAX_CHANNELS]; TempBuf *pat_buf = NULL; gboolean new_buf; - gimp_drawable_mask_bounds (drawable, &x1, &y1, &x2, &y2); - - if (x1 == x2 || y1 == y2) + if (! gimp_drawable_mask_intersect (drawable, &x, &y, &width, &height)) return TRUE; /* nothing to do, but the fill succeded */ tiles_bytes = gimp_drawable_bytes (drawable); @@ -440,9 +438,9 @@ gimp_edit_fill_internal (GimpImage *gimage, return TRUE; /* nothing to do, but the fill succeded */ } - buf_tiles = tile_manager_new (x2 - x1, y2 - y1, tiles_bytes); + buf_tiles = tile_manager_new (width, height, tiles_bytes); - pixel_region_init (&bufPR, buf_tiles, 0, 0, x2 - x1, y2 - y1, TRUE); + pixel_region_init (&bufPR, buf_tiles, 0, 0, width, height, TRUE); if (pat_buf) { @@ -459,17 +457,17 @@ gimp_edit_fill_internal (GimpImage *gimage, color_region (&bufPR, col); } - pixel_region_init (&bufPR, buf_tiles, 0, 0, x2 - x1, y2 - y1, FALSE); + pixel_region_init (&bufPR, buf_tiles, 0, 0, width, height, FALSE); gimp_drawable_apply_region (drawable, &bufPR, TRUE, undo_desc, GIMP_OPACITY_OPAQUE, (fill_type == GIMP_TRANSPARENT_FILL) ? GIMP_ERASE_MODE : GIMP_NORMAL_MODE, - NULL, x1, y1); + NULL, x, y); tile_manager_unref (buf_tiles); - gimp_drawable_update (drawable, x1, y1, x2 - x1, y2 - y1); + gimp_drawable_update (drawable, x, y, width, height); return TRUE; } diff --git a/app/core/gimpdrawable-blend.c b/app/core/gimpdrawable-blend.c index eabaf51ba8..9aea546180 100644 --- a/app/core/gimpdrawable-blend.c +++ b/app/core/gimpdrawable-blend.c @@ -191,7 +191,7 @@ gimp_drawable_blend (GimpDrawable *drawable, TileManager *buf_tiles; PixelRegion bufPR; gint bytes; - gint x1, y1, x2, y2; + gint x, y, width, height; g_return_if_fail (GIMP_IS_DRAWABLE (drawable)); g_return_if_fail (GIMP_IS_CONTEXT (context)); @@ -201,9 +201,10 @@ gimp_drawable_blend (GimpDrawable *drawable, g_return_if_fail (GIMP_IS_IMAGE (gimage)); - gimp_set_busy (gimage->gimp); + if (! gimp_drawable_mask_intersect (drawable, &x, &y, &width, &height)) + return; - gimp_drawable_mask_bounds (drawable, &x1, &y1, &x2, &y2); + gimp_set_busy (gimage->gimp); bytes = gimp_drawable_bytes (drawable); @@ -213,15 +214,15 @@ gimp_drawable_blend (GimpDrawable *drawable, bytes += 1; } - buf_tiles = tile_manager_new ((x2 - x1), (y2 - y1), bytes); - pixel_region_init (&bufPR, buf_tiles, 0, 0, (x2 - x1), (y2 - y1), TRUE); + buf_tiles = tile_manager_new (width, height, bytes); + pixel_region_init (&bufPR, buf_tiles, 0, 0, width, height, TRUE); gradient_fill_region (gimage, drawable, context, - &bufPR, (x2 - x1), (y2 - y1), + &bufPR, width, height, blend_mode, gradient_type, offset, repeat, reverse, supersample, max_depth, threshold, dither, - (startx - x1), (starty - y1), - (endx - x1), (endy - y1), + (startx - x), (starty - y), + (endx - x), (endy - y), progress); if (distR.tiles) @@ -230,14 +231,14 @@ gimp_drawable_blend (GimpDrawable *drawable, distR.tiles = NULL; } - pixel_region_init (&bufPR, buf_tiles, 0, 0, (x2 - x1), (y2 - y1), FALSE); + pixel_region_init (&bufPR, buf_tiles, 0, 0, width, height, FALSE); gimp_drawable_apply_region (drawable, &bufPR, TRUE, _("Blend"), opacity, paint_mode, - NULL, x1, y1); + NULL, x, y); /* update the image */ - gimp_drawable_update (drawable, x1, y1, x2 - x1, y2 - y1); + gimp_drawable_update (drawable, x, y, width, height); /* free the temporary buffer */ tile_manager_unref (buf_tiles); diff --git a/app/core/gimpdrawable-bucket-fill.c b/app/core/gimpdrawable-bucket-fill.c index c8fe50fed0..7448e62898 100644 --- a/app/core/gimpdrawable-bucket-fill.c +++ b/app/core/gimpdrawable-bucket-fill.c @@ -138,6 +138,12 @@ gimp_drawable_bucket_fill_full (GimpDrawable *drawable, g_return_if_fail (GIMP_IS_IMAGE (gimage)); + bytes = gimp_drawable_bytes (drawable); + selection = gimp_drawable_mask_bounds (drawable, &x1, &y1, &x2, &y2); + + if ((x1 == x2) || (y1 == y2)) + return; + if (fill_mode == GIMP_FG_BUCKET_FILL || fill_mode == GIMP_BG_BUCKET_FILL) { @@ -164,9 +170,6 @@ gimp_drawable_bucket_fill_full (GimpDrawable *drawable, gimp_set_busy (gimage->gimp); - bytes = gimp_drawable_bytes (drawable); - selection = gimp_drawable_mask_bounds (drawable, &x1, &y1, &x2, &y2); - /* Do a seed bucket fill...To do this, calculate a new * contiguous region. If there is a selection, calculate the * intersection of this region with the existing selection. diff --git a/app/core/gimpdrawable-desaturate.c b/app/core/gimpdrawable-desaturate.c index 08a8edaa06..db0eb54156 100644 --- a/app/core/gimpdrawable-desaturate.c +++ b/app/core/gimpdrawable-desaturate.c @@ -41,18 +41,20 @@ gimp_drawable_desaturate (GimpDrawable *drawable) gint lightness, min, max; gboolean has_alpha; gpointer pr; - gint x1, y1, x2, y2; + gint x, y, width, height; g_return_if_fail (GIMP_IS_DRAWABLE (drawable)); g_return_if_fail (gimp_drawable_is_rgb (drawable)); has_alpha = gimp_drawable_has_alpha (drawable); - gimp_drawable_mask_bounds (drawable, &x1, &y1, &x2, &y2); + + if (gimp_drawable_mask_intersect (drawable, &x, &y, &width, &height)) + return; pixel_region_init (&srcPR, gimp_drawable_data (drawable), - x1, y1, (x2 - x1), (y2 - y1), FALSE); + x, y, width, height, FALSE); pixel_region_init (&destPR, gimp_drawable_shadow (drawable), - x1, y1, (x2 - x1), (y2 - y1), TRUE); + x, y, width, height, TRUE); for (pr = pixel_regions_register (2, &srcPR, &destPR); pr != NULL; @@ -94,5 +96,5 @@ gimp_drawable_desaturate (GimpDrawable *drawable) gimp_drawable_merge_shadow (drawable, TRUE, _("Desaturate")); - gimp_drawable_update (drawable, x1, y1, (x2 - x1), (y2 - y1)); + gimp_drawable_update (drawable, x, y, width, height); } diff --git a/app/core/gimpdrawable-equalize.c b/app/core/gimpdrawable-equalize.c index 4e9a318ccc..66f24af305 100644 --- a/app/core/gimpdrawable-equalize.c +++ b/app/core/gimpdrawable-equalize.c @@ -44,20 +44,19 @@ gimp_drawable_equalize (GimpDrawable *drawable, gboolean mask_only) { PixelRegion srcPR, destPR; - guchar *mask; gint bytes; - gint x1, y1, x2, y2; + gint x, y, width, height; GimpHistogram *hist; GimpLut *lut; GimpImage *gimage; g_return_if_fail (GIMP_IS_DRAWABLE (drawable)); - mask = NULL; - - bytes = gimp_drawable_bytes (drawable); - gimage = gimp_item_get_image (GIMP_ITEM (drawable)); + bytes = gimp_drawable_bytes (drawable); + + if (! gimp_drawable_mask_intersect (drawable, &x, &y, &width, &height)) + return; hist = gimp_histogram_new (GIMP_BASE_CONFIG (gimage->gimp->config)); gimp_drawable_calculate_histogram (drawable, hist); @@ -66,14 +65,12 @@ gimp_drawable_equalize (GimpDrawable *drawable, lut = eq_histogram_lut_new (hist, bytes); /* Apply the histogram */ - gimp_drawable_mask_bounds (drawable, &x1, &y1, &x2, &y2); - pixel_region_init (&srcPR, gimp_drawable_data (drawable), - x1, y1, (x2 - x1), (y2 - y1), FALSE); + x, y, width, height, FALSE); pixel_region_init (&destPR, gimp_drawable_shadow (drawable), - x1, y1, (x2 - x1), (y2 - y1), TRUE); + x, y, width, height, TRUE); - pixel_regions_process_parallel ((p_func) gimp_lut_process, lut, + pixel_regions_process_parallel ((p_func) gimp_lut_process, lut, 2, &srcPR, &destPR); gimp_lut_free (lut); @@ -81,5 +78,5 @@ gimp_drawable_equalize (GimpDrawable *drawable, gimp_drawable_merge_shadow (drawable, TRUE, _("Equalize")); - gimp_drawable_update (drawable, x1, y1, (x2 - x1), (y2 - y1)); + gimp_drawable_update (drawable, x, y, width, height); } diff --git a/app/core/gimpdrawable-histogram.c b/app/core/gimpdrawable-histogram.c index 25eb2272d1..3f4370b60a 100644 --- a/app/core/gimpdrawable-histogram.c +++ b/app/core/gimpdrawable-histogram.c @@ -38,13 +38,16 @@ gimp_drawable_calculate_histogram (GimpDrawable *drawable, PixelRegion region; PixelRegion mask; gint x1, y1, x2, y2; - gint off_x, off_y; gboolean have_mask; g_return_if_fail (GIMP_IS_DRAWABLE (drawable)); g_return_if_fail (histogram != NULL); have_mask = gimp_drawable_mask_bounds (drawable, &x1, &y1, &x2, &y2); + + if ((x1 == x2) || (y1 == y2)) + return; + pixel_region_init (®ion, gimp_drawable_data (drawable), x1, y1, (x2 - x1), (y2 - y1), FALSE); @@ -52,6 +55,7 @@ gimp_drawable_calculate_histogram (GimpDrawable *drawable, { GimpChannel *sel_mask; GimpImage *gimage; + gint off_x, off_y; gimage = gimp_item_get_image (GIMP_ITEM (drawable)); sel_mask = gimp_image_get_mask (gimage); diff --git a/app/core/gimpdrawable-invert.c b/app/core/gimpdrawable-invert.c index 19a926e605..ad5e1a9b34 100644 --- a/app/core/gimpdrawable-invert.c +++ b/app/core/gimpdrawable-invert.c @@ -37,25 +37,25 @@ void gimp_drawable_invert (GimpDrawable *drawable) { PixelRegion srcPR, destPR; - gint x1, y1, x2, y2; + gint x, y, width, height; GimpLut *lut; + if (! gimp_drawable_mask_intersect (drawable, &x, &y, &width, &height)) + return; + lut = invert_lut_new (gimp_drawable_bytes (drawable)); - gimp_drawable_mask_bounds (drawable, &x1, &y1, &x2, &y2); pixel_region_init (&srcPR, gimp_drawable_data (drawable), - x1, y1, (x2 - x1), (y2 - y1), FALSE); + x, y, width, height, FALSE); pixel_region_init (&destPR, gimp_drawable_shadow (drawable), - x1, y1, (x2 - x1), (y2 - y1), TRUE); + x, y, width, height, TRUE); - pixel_regions_process_parallel ((p_func)gimp_lut_process, lut, + pixel_regions_process_parallel ((p_func)gimp_lut_process, lut, 2, &srcPR, &destPR); gimp_lut_free (lut); gimp_drawable_merge_shadow (drawable, TRUE, _("Invert")); - gimp_drawable_update (drawable, - x1, y1, - (x2 - x1), (y2 - y1)); + gimp_drawable_update (drawable, x, y, width, height); } diff --git a/app/core/gimpdrawable-stroke.c b/app/core/gimpdrawable-stroke.c index 292210c1a4..99d48ca2bc 100644 --- a/app/core/gimpdrawable-stroke.c +++ b/app/core/gimpdrawable-stroke.c @@ -205,7 +205,8 @@ gimp_drawable_stroke_scan_convert (GimpDrawable *drawable, GimpStrokeOptions *options, GimpScanConvert *scan_convert) { - /* Stroke options */ + GimpContext *context = GIMP_CONTEXT (options); + GimpImage *gimage; gdouble width; TileManager *base; TileManager *mask; @@ -214,28 +215,11 @@ gimp_drawable_stroke_scan_convert (GimpDrawable *drawable, gint off_x, off_y; guchar bg[1] = { 0, }; PixelRegion maskPR, basePR; - GimpContext *context; - GimpImage *gimage; - - context = GIMP_CONTEXT (options); gimage = gimp_item_get_image (GIMP_ITEM (drawable)); - /* what area do we operate on? */ - if (! gimp_channel_is_empty (gimp_image_get_mask (gimage))) - { - gint x2, y2; - - gimp_drawable_mask_bounds (drawable, &x, &y, &x2, &y2); - w = x2 - x; - h = y2 - y; - } - else - { - x = y = 0; - w = gimp_item_width (GIMP_ITEM (drawable)); - h = gimp_item_height (GIMP_ITEM (drawable)); - } + if (! gimp_drawable_mask_intersect (drawable, &x, &y, &w, &h)) + return; gimp_item_offsets (GIMP_ITEM (drawable), &off_x, &off_y); diff --git a/app/core/gimpdrawable.c b/app/core/gimpdrawable.c index 4cf76ed232..99efe18dd9 100644 --- a/app/core/gimpdrawable.c +++ b/app/core/gimpdrawable.c @@ -1065,8 +1065,7 @@ gimp_drawable_merge_shadow (GimpDrawable *drawable, const gchar *undo_desc) { GimpImage *gimage; - PixelRegion shadowPR; - gint x1, y1, x2, y2; + gint x, y, width, height; g_return_if_fail (GIMP_IS_DRAWABLE (drawable)); @@ -1079,13 +1078,17 @@ gimp_drawable_merge_shadow (GimpDrawable *drawable, * extents of the selection mask, as it cannot extend beyond * them. */ - gimp_drawable_mask_bounds (drawable, &x1, &y1, &x2, &y2); - pixel_region_init (&shadowPR, gimage->shadow, - x1, y1, (x2 - x1), (y2 - y1), FALSE); - gimp_drawable_apply_region (drawable, &shadowPR, - push_undo, undo_desc, - GIMP_OPACITY_OPAQUE, GIMP_REPLACE_MODE, - NULL, x1, y1); + if (gimp_drawable_mask_intersect (drawable, &x, &y, &width, &height)) + { + PixelRegion shadowPR; + + pixel_region_init (&shadowPR, gimage->shadow, + x, y, width, height, FALSE); + gimp_drawable_apply_region (drawable, &shadowPR, + push_undo, undo_desc, + GIMP_OPACITY_OPAQUE, GIMP_REPLACE_MODE, + NULL, x, y); + } } void @@ -1214,10 +1217,10 @@ gimp_drawable_mask_bounds (GimpDrawable *drawable, g_return_val_if_fail (y2 != NULL, FALSE); item = GIMP_ITEM (drawable); - gimage = gimp_item_get_image (item); - g_return_val_if_fail (gimage != NULL, FALSE); + g_return_val_if_fail (gimp_item_is_attached (item), FALSE); + gimage = gimp_item_get_image (item); selection = gimp_image_get_mask (gimage); if (GIMP_DRAWABLE (selection) != drawable && @@ -1243,6 +1246,54 @@ gimp_drawable_mask_bounds (GimpDrawable *drawable, return FALSE; } +gboolean +gimp_drawable_mask_intersect (GimpDrawable *drawable, + gint *x, + gint *y, + gint *width, + gint *height) +{ + GimpItem *item; + GimpImage *gimage; + GimpChannel *selection; + + g_return_val_if_fail (GIMP_IS_DRAWABLE (drawable), FALSE); + g_return_val_if_fail (x != NULL, FALSE); + g_return_val_if_fail (y != NULL, FALSE); + g_return_val_if_fail (width != NULL, FALSE); + g_return_val_if_fail (height != NULL, FALSE); + + item = GIMP_ITEM (drawable); + + g_return_val_if_fail (gimp_item_is_attached (item), FALSE); + + gimage = gimp_item_get_image (item); + selection = gimp_image_get_mask (gimage); + + if (GIMP_DRAWABLE (selection) != drawable && + gimp_channel_bounds (selection, x, y, width, height)) + { + gint off_x, off_y; + + gimp_item_offsets (item, &off_x, &off_y); + + return gimp_rectangle_intersect (*x - off_x, *y - off_y, + *width - *x, *height - *y, + 0, 0, + gimp_item_width (item), + gimp_item_height (item), + x, y, + width, height); + } + + *x = 0; + *y = 0; + *width = gimp_item_width (item); + *height = gimp_item_height (item); + + return TRUE; +} + gboolean gimp_drawable_has_alpha (const GimpDrawable *drawable) { diff --git a/app/core/gimpdrawable.h b/app/core/gimpdrawable.h index 44fbf6cb84..18a6a82205 100644 --- a/app/core/gimpdrawable.h +++ b/app/core/gimpdrawable.h @@ -189,10 +189,15 @@ void gimp_drawable_fill_by_type (GimpDrawable *drawable, GimpFillType fill_type); gboolean gimp_drawable_mask_bounds (GimpDrawable *drawable, - gint *x1, - gint *y1, - gint *x2, - gint *y2); + gint *x1, + gint *y1, + gint *x2, + gint *y2); +gboolean gimp_drawable_mask_intersect (GimpDrawable *drawable, + gint *x, + gint *y, + gint *width, + gint *height); gboolean gimp_drawable_has_alpha (const GimpDrawable *drawable); GimpImageType gimp_drawable_type (const GimpDrawable *drawable); diff --git a/app/core/gimpimagemap.c b/app/core/gimpimagemap.c index 38b5024dfb..ba1618274f 100644 --- a/app/core/gimpimagemap.c +++ b/app/core/gimpimagemap.c @@ -275,10 +275,10 @@ gimp_image_map_apply (GimpImageMap *image_map, GimpImageMapApplyFunc apply_func, gpointer apply_data) { - gint x1, y1; - gint x2, y2; - gint offset_x, offset_y; + gint x, y; gint width, height; + gint undo_offset_x, undo_offset_y; + gint undo_width, undo_height; g_return_if_fail (GIMP_IS_IMAGE_MAP (image_map)); g_return_if_fail (apply_func != NULL); @@ -301,33 +301,38 @@ gimp_image_map_apply (GimpImageMap *image_map, return; /* The application should occur only within selection bounds */ - gimp_drawable_mask_bounds (image_map->drawable, &x1, &y1, &x2, &y2); - - if ((x2 - x1 < 1) || (y2 - y1 < 1)) + if (! gimp_drawable_mask_intersect (image_map->drawable, + &x, &y, &width, &height)) return; /* If undo tiles don't exist, or change size, (re)allocate */ if (image_map->undo_tiles) { - offset_x = image_map->undo_offset_x; - offset_y = image_map->undo_offset_y; - width = tile_manager_width (image_map->undo_tiles); - height = tile_manager_height (image_map->undo_tiles); + undo_offset_x = image_map->undo_offset_x; + undo_offset_y = image_map->undo_offset_y; + undo_width = tile_manager_width (image_map->undo_tiles); + undo_height = tile_manager_height (image_map->undo_tiles); } else { - offset_x = offset_y = width = height = 0; + undo_offset_x = 0; + undo_offset_y = 0; + undo_width = 0; + undo_height = 0; } if (! image_map->undo_tiles || - offset_x != x1 || offset_y != y1 || - width != (x2 - x1) || height != (y2 - y1)) + undo_offset_x != x || + undo_offset_y != y || + undo_width != width || + undo_height != height) { /* If either the extents changed or the tiles don't exist, * allocate new */ if (! image_map->undo_tiles || - width != (x2 - x1) || height != (y2 - y1)) + undo_width != width || + undo_height != height) { /* Destroy old tiles */ if (image_map->undo_tiles) @@ -335,44 +340,45 @@ gimp_image_map_apply (GimpImageMap *image_map, /* Allocate new tiles */ image_map->undo_tiles = - tile_manager_new ((x2 - x1), (y2 - y1), + tile_manager_new (width, height, gimp_drawable_bytes (image_map->drawable)); } /* Copy from the image to the new tiles */ pixel_region_init (&image_map->srcPR, gimp_drawable_data (image_map->drawable), - x1, y1, (x2 - x1), (y2 - y1), FALSE); + x, y, width, height, FALSE); pixel_region_init (&image_map->destPR, image_map->undo_tiles, - 0, 0, (x2 - x1), (y2 - y1), TRUE); + 0, 0, width, height, TRUE); copy_region (&image_map->srcPR, &image_map->destPR); /* Set the offsets */ - image_map->undo_offset_x = x1; - image_map->undo_offset_y = y1; + image_map->undo_offset_x = x; + image_map->undo_offset_y = y; } else /* image_map->undo_tiles exist AND drawable dimensions have not changed... */ { /* Reset to initial drawable conditions. */ /* Copy from the backup undo tiles to the drawable */ pixel_region_init (&image_map->srcPR, image_map->undo_tiles, - 0, 0, width, height, FALSE); + 0, 0, undo_width, undo_height, FALSE); pixel_region_init (&image_map->destPR, gimp_drawable_data (image_map->drawable), - offset_x, offset_y, width, height, TRUE); + undo_offset_x, undo_offset_y, + undo_width, undo_height, TRUE); copy_region (&image_map->srcPR, &image_map->destPR); } /* Configure the src from the drawable data */ pixel_region_init (&image_map->srcPR, image_map->undo_tiles, - 0, 0, (x2 - x1), (y2 - y1), FALSE); + 0, 0, width, height, FALSE); /* Configure the dest as the shadow buffer */ pixel_region_init (&image_map->destPR, gimp_drawable_shadow (image_map->drawable), - x1, y1, (x2 - x1), (y2 - y1), TRUE); + x, y, width, height, TRUE); /* Apply the image transformation to the pixels */ image_map->PRI = pixel_regions_register (2, diff --git a/app/core/gimpselection.c b/app/core/gimpselection.c index d4562dff46..7882bedcab 100644 --- a/app/core/gimpselection.c +++ b/app/core/gimpselection.c @@ -652,8 +652,8 @@ gimp_selection_extract (GimpChannel *selection, GimpImageBaseType base_type = GIMP_RGB; gint bytes = 0; gint x1, y1, x2, y2; - gint off_x, off_y; gboolean non_empty; + gint off_x, off_y; g_return_val_if_fail (GIMP_IS_SELECTION (selection), NULL); g_return_val_if_fail (GIMP_IS_DRAWABLE (drawable), NULL); @@ -668,7 +668,7 @@ gimp_selection_extract (GimpChannel *selection, * actual selection mask */ non_empty = gimp_drawable_mask_bounds (drawable, &x1, &y1, &x2, &y2); - if (non_empty && (!(x2 - x1) || !(y2 - y1))) + if (non_empty && ((x1 == x2) || (y1 == y2))) { g_message (_("Unable to cut or copy because the " "selected region is empty.")); @@ -803,9 +803,8 @@ gimp_selection_float (GimpChannel *selection, GimpImage *gimage; GimpLayer *layer; TileManager *tiles; + gint x1, y1, x2, y2; gboolean non_empty; - gint x1, y1; - gint x2, y2; g_return_val_if_fail (GIMP_IS_SELECTION (selection), NULL); g_return_val_if_fail (GIMP_IS_DRAWABLE (drawable), NULL); @@ -816,7 +815,7 @@ gimp_selection_float (GimpChannel *selection, /* Make sure there is a region to float... */ non_empty = gimp_drawable_mask_bounds (drawable, &x1, &y1, &x2, &y2); - if (! non_empty || (x2 - x1) == 0 || (y2 - y1) == 0) + if (! non_empty || (x1 == x2) || (y1 == y2)) { g_message (_("Cannot float selection because the " "selected region is empty.")); diff --git a/app/pdb/color_cmds.c b/app/pdb/color_cmds.c index fae59e8e90..c669c22949 100644 --- a/app/pdb/color_cmds.c +++ b/app/pdb/color_cmds.c @@ -91,10 +91,6 @@ brightness_contrast_invoker (Gimp *gimp, GimpDrawable *drawable; gint32 brightness; gint32 contrast; - GimpImage *gimage; - GimpLut *lut; - PixelRegion srcPR, destPR; - int x1, y1, x2, y2; drawable = (GimpDrawable *) gimp_item_get_by_ID (gimp, args[0].value.pdb_int); if (! (GIMP_IS_DRAWABLE (drawable) && ! gimp_item_is_removed (GIMP_ITEM (drawable)))) @@ -115,27 +111,31 @@ brightness_contrast_invoker (Gimp *gimp, if (success) { - gimage = gimp_item_get_image (GIMP_ITEM (drawable)); - - lut = brightness_contrast_lut_new (brightness / 255.0, - contrast / 127.0, - gimp_drawable_bytes (drawable)); + gint x, y, width, height; /* The application should occur only within selection bounds */ - gimp_drawable_mask_bounds (drawable, &x1, &y1, &x2, &y2); + if (gimp_drawable_mask_intersect (drawable, &x, &y, &width, &height)) + { + GimpLut *lut; + PixelRegion srcPR, destPR; - pixel_region_init (&srcPR, gimp_drawable_data (drawable), - x1, y1, (x2 - x1), (y2 - y1), FALSE); - pixel_region_init (&destPR, gimp_drawable_shadow (drawable), - x1, y1, (x2 - x1), (y2 - y1), TRUE); + lut = brightness_contrast_lut_new (brightness / 255.0, + contrast / 127.0, + gimp_drawable_bytes (drawable)); - pixel_regions_process_parallel ((p_func) gimp_lut_process, lut, 2, - &srcPR, &destPR); + pixel_region_init (&srcPR, gimp_drawable_data (drawable), + x, y, width, height, FALSE); + pixel_region_init (&destPR, gimp_drawable_shadow (drawable), + x, y, width, height, TRUE); - gimp_lut_free (lut); + pixel_regions_process_parallel ((p_func) gimp_lut_process, lut, 2, + &srcPR, &destPR); - gimp_drawable_merge_shadow (drawable, TRUE, _("Brightness-Contrast")); - gimp_drawable_update (drawable, x1, y1, (x2 - x1), (y2 - y1)); + gimp_lut_free (lut); + + gimp_drawable_merge_shadow (drawable, TRUE, _("Brightness-Contrast")); + gimp_drawable_update (drawable, x, y, width, height); + } } } @@ -192,10 +192,6 @@ levels_invoker (Gimp *gimp, gdouble gamma; gint32 low_output; gint32 high_output; - PixelRegion srcPR, destPR; - Levels l; - gint x1, y1, x2, y2; - GimpLut *lut; drawable = (GimpDrawable *) gimp_item_get_by_ID (gimp, args[0].value.pdb_int); if (! (GIMP_IS_DRAWABLE (drawable) && ! gimp_item_is_removed (GIMP_ITEM (drawable)))) @@ -236,41 +232,49 @@ levels_invoker (Gimp *gimp, if (success) { - /* FIXME: hack */ - if (gimp_drawable_is_gray (drawable) && channel == GIMP_HISTOGRAM_ALPHA) - channel = 1; - - lut = gimp_lut_new (); - - levels_init (&l); - - l.low_input[channel] = low_input; - l.high_input[channel] = high_input; - l.gamma[channel] = gamma; - l.low_output[channel] = low_output; - l.high_output[channel] = high_output; - - /* setup the lut */ - gimp_lut_setup (lut, - (GimpLutFunc) levels_lut_func, - &l, - gimp_drawable_bytes (drawable)); + gint x, y, width, height; /* The application should occur only within selection bounds */ - gimp_drawable_mask_bounds (drawable, &x1, &y1, &x2, &y2); + if (gimp_drawable_mask_intersect (drawable, &x, &y, &width, &height)) + { + PixelRegion srcPR, destPR; + Levels l; + GimpLut *lut; - pixel_region_init (&srcPR, gimp_drawable_data (drawable), - x1, y1, (x2 - x1), (y2 - y1), FALSE); - pixel_region_init (&destPR, gimp_drawable_shadow (drawable), - x1, y1, (x2 - x1), (y2 - y1), TRUE); + /* FIXME: hack */ + if (gimp_drawable_is_gray (drawable) && + channel == GIMP_HISTOGRAM_ALPHA) + channel = 1; - pixel_regions_process_parallel ((p_func) gimp_lut_process, lut, 2, - &srcPR, &destPR); + lut = gimp_lut_new (); - gimp_lut_free (lut); + levels_init (&l); - gimp_drawable_merge_shadow (drawable, TRUE, _("Levels")); - gimp_drawable_update (drawable, x1, y1, (x2 - x1), (y2 - y1)); + l.low_input[channel] = low_input; + l.high_input[channel] = high_input; + l.gamma[channel] = gamma; + l.low_output[channel] = low_output; + l.high_output[channel] = high_output; + + /* setup the lut */ + gimp_lut_setup (lut, + (GimpLutFunc) levels_lut_func, + &l, + gimp_drawable_bytes (drawable)); + + pixel_region_init (&srcPR, gimp_drawable_data (drawable), + x, y, width, height, FALSE); + pixel_region_init (&destPR, gimp_drawable_shadow (drawable), + x, y, width, height, TRUE); + + pixel_regions_process_parallel ((p_func) gimp_lut_process, lut, 2, + &srcPR, &destPR); + + gimp_lut_free (lut); + + gimp_drawable_merge_shadow (drawable, TRUE, _("Levels")); + gimp_drawable_update (drawable, x, y, width, height); + } } } @@ -341,12 +345,6 @@ levels_auto_invoker (Gimp *gimp, { gboolean success = TRUE; GimpDrawable *drawable; - PixelRegion srcPR, destPR; - Levels levels; - gint x1, y1, x2, y2; - GimpLut *lut; - GimpImage *image; - GimpHistogram *hist; drawable = (GimpDrawable *) gimp_item_get_by_ID (gimp, args[0].value.pdb_int); if (! (GIMP_IS_DRAWABLE (drawable) && ! gimp_item_is_removed (GIMP_ITEM (drawable)))) @@ -359,39 +357,46 @@ levels_auto_invoker (Gimp *gimp, if (success) { - /* Build the histogram */ - image = gimp_item_get_image (GIMP_ITEM (drawable)); - hist = gimp_histogram_new (GIMP_BASE_CONFIG (image->gimp->config)); - - gimp_drawable_calculate_histogram (drawable, hist); - - /* Calculate the levels */ - levels_init (&levels); - levels_auto (&levels, hist, ! gimp_drawable_is_gray (drawable)); - - /* Set up the lut */ - lut = gimp_lut_new (); - gimp_lut_setup (lut, - (GimpLutFunc) levels_lut_func, - &levels, - gimp_drawable_bytes (drawable)); + gint x, y, width, height; /* The application should occur only within selection bounds */ - gimp_drawable_mask_bounds (drawable, &x1, &y1, &x2, &y2); + if (gimp_drawable_mask_intersect (drawable, &x, &y, &width, &height)) + { + PixelRegion srcPR, destPR; + Levels levels; + GimpLut *lut; + GimpHistogram *hist; - pixel_region_init (&srcPR, gimp_drawable_data (drawable), - x1, y1, (x2 - x1), (y2 - y1), FALSE); - pixel_region_init (&destPR, gimp_drawable_shadow (drawable), - x1, y1, (x2 - x1), (y2 - y1), TRUE); + /* Build the histogram */ + hist = gimp_histogram_new (GIMP_BASE_CONFIG (gimp->config)); - pixel_regions_process_parallel ((p_func) gimp_lut_process, lut, 2, - &srcPR, &destPR); + gimp_drawable_calculate_histogram (drawable, hist); - gimp_lut_free (lut); - gimp_histogram_free (hist); + /* Calculate the levels */ + levels_init (&levels); + levels_auto (&levels, hist, ! gimp_drawable_is_gray (drawable)); - gimp_drawable_merge_shadow (drawable, TRUE, _("Levels")); - gimp_drawable_update (drawable, x1, y1, (x2 - x1), (y2 - y1)); + /* Set up the lut */ + lut = gimp_lut_new (); + gimp_lut_setup (lut, + (GimpLutFunc) levels_lut_func, + &levels, + gimp_drawable_bytes (drawable)); + + pixel_region_init (&srcPR, gimp_drawable_data (drawable), + x, y, width, height, FALSE); + pixel_region_init (&destPR, gimp_drawable_shadow (drawable), + x, y, width, height, TRUE); + + pixel_regions_process_parallel ((p_func) gimp_lut_process, lut, 2, + &srcPR, &destPR); + + gimp_lut_free (lut); + gimp_histogram_free (hist); + + gimp_drawable_merge_shadow (drawable, TRUE, _("Levels")); + gimp_drawable_update (drawable, x, y, width, height); + } } } @@ -433,10 +438,6 @@ posterize_invoker (Gimp *gimp, gboolean success = TRUE; GimpDrawable *drawable; gint32 levels; - GimpImage *gimage; - GimpLut *lut; - PixelRegion srcPR, destPR; - int x1, y1, x2, y2; drawable = (GimpDrawable *) gimp_item_get_by_ID (gimp, args[0].value.pdb_int); if (! (GIMP_IS_DRAWABLE (drawable) && ! gimp_item_is_removed (GIMP_ITEM (drawable)))) @@ -453,25 +454,29 @@ posterize_invoker (Gimp *gimp, if (success) { - gimage = gimp_item_get_image (GIMP_ITEM (drawable)); - - lut = posterize_lut_new (levels, gimp_drawable_bytes (drawable)); + gint x, y, width, height; /* The application should occur only within selection bounds */ - gimp_drawable_mask_bounds (drawable, &x1, &y1, &x2, &y2); + if (gimp_drawable_mask_intersect (drawable, &x, &y, &width, &height)) + { + GimpLut *lut; + PixelRegion srcPR, destPR; - pixel_region_init (&srcPR, gimp_drawable_data (drawable), - x1, y1, (x2 - x1), (y2 - y1), FALSE); - pixel_region_init (&destPR, gimp_drawable_shadow (drawable), - x1, y1, (x2 - x1), (y2 - y1), TRUE); + lut = posterize_lut_new (levels, gimp_drawable_bytes (drawable)); - pixel_regions_process_parallel ((p_func) gimp_lut_process, lut, 2, - &srcPR, &destPR); + pixel_region_init (&srcPR, gimp_drawable_data (drawable), + x, y, width, height, FALSE); + pixel_region_init (&destPR, gimp_drawable_shadow (drawable), + x, y, width, height, TRUE); - gimp_lut_free (lut); + pixel_regions_process_parallel ((p_func) gimp_lut_process, lut, 2, + &srcPR, &destPR); - gimp_drawable_merge_shadow (drawable, TRUE, _("Posterize")); - gimp_drawable_update (drawable, x1, y1, (x2 - x1), (y2 - y1)); + gimp_lut_free (lut); + + gimp_drawable_merge_shadow (drawable, TRUE, _("Posterize")); + gimp_drawable_update (drawable, x, y, width, height); + } } } @@ -678,11 +683,6 @@ curves_spline_invoker (Gimp *gimp, gint32 channel; gint32 num_points; guint8 *control_pts; - Curves c; - gint x1, y1, x2, y2; - gint j; - PixelRegion srcPR, destPR; - GimpLut *lut; drawable = (GimpDrawable *) gimp_item_get_by_ID (gimp, args[0].value.pdb_int); if (! (GIMP_IS_DRAWABLE (drawable) && ! gimp_item_is_removed (GIMP_ITEM (drawable)))) @@ -709,46 +709,55 @@ curves_spline_invoker (Gimp *gimp, if (success) { - /* FIXME: hack */ - if (gimp_drawable_is_gray (drawable) && channel == GIMP_HISTOGRAM_ALPHA) - channel = 1; - - lut = gimp_lut_new (); - - curves_init (&c); - - /* unset the last point */ - c.points[channel][CURVES_NUM_POINTS - 1][0] = -1; - c.points[channel][CURVES_NUM_POINTS - 1][1] = -1; - - for (j = 0; j < num_points / 2; j++) - { - c.points[channel][j][0] = control_pts[j * 2]; - c.points[channel][j][1] = control_pts[j * 2 + 1]; - } - - curves_calculate_curve (&c, channel); - - gimp_lut_setup (lut, - (GimpLutFunc) curves_lut_func, - &c, - gimp_drawable_bytes (drawable)); + gint x, y, width, height; /* The application should occur only within selection bounds */ - gimp_drawable_mask_bounds (drawable, &x1, &y1, &x2, &y2); + if (gimp_drawable_mask_intersect (drawable, &x, &y, &width, &height)) + { + Curves c; + gint j; + PixelRegion srcPR, destPR; + GimpLut *lut; - pixel_region_init (&srcPR, gimp_drawable_data (drawable), - x1, y1, (x2 - x1), (y2 - y1), FALSE); - pixel_region_init (&destPR, gimp_drawable_shadow (drawable), - x1, y1, (x2 - x1), (y2 - y1), TRUE); + /* FIXME: hack */ + if (gimp_drawable_is_gray (drawable) && + channel == GIMP_HISTOGRAM_ALPHA) + channel = 1; - pixel_regions_process_parallel ((p_func) gimp_lut_process, lut, 2, - &srcPR, &destPR); + lut = gimp_lut_new (); - gimp_lut_free (lut); + curves_init (&c); - gimp_drawable_merge_shadow (drawable, TRUE, _("Curves")); - gimp_drawable_update (drawable, x1, y1, (x2 - x1), (y2 - y1)); + /* unset the last point */ + c.points[channel][CURVES_NUM_POINTS - 1][0] = -1; + c.points[channel][CURVES_NUM_POINTS - 1][1] = -1; + + for (j = 0; j < num_points / 2; j++) + { + c.points[channel][j][0] = control_pts[j * 2]; + c.points[channel][j][1] = control_pts[j * 2 + 1]; + } + + curves_calculate_curve (&c, channel); + + gimp_lut_setup (lut, + (GimpLutFunc) curves_lut_func, + &c, + gimp_drawable_bytes (drawable)); + + pixel_region_init (&srcPR, gimp_drawable_data (drawable), + x, y, width, height, FALSE); + pixel_region_init (&destPR, gimp_drawable_shadow (drawable), + x, y, width, height, TRUE); + + pixel_regions_process_parallel ((p_func) gimp_lut_process, lut, 2, + &srcPR, &destPR); + + gimp_lut_free (lut); + + gimp_drawable_merge_shadow (drawable, TRUE, _("Curves")); + gimp_drawable_update (drawable, x, y, width, height); + } } } @@ -807,11 +816,6 @@ curves_explicit_invoker (Gimp *gimp, gint32 channel; gint32 num_bytes; guint8 *curve; - Curves c; - gint x1, y1, x2, y2; - gint j; - PixelRegion srcPR, destPR; - GimpLut *lut; drawable = (GimpDrawable *) gimp_item_get_by_ID (gimp, args[0].value.pdb_int); if (! (GIMP_IS_DRAWABLE (drawable) && ! gimp_item_is_removed (GIMP_ITEM (drawable)))) @@ -838,37 +842,46 @@ curves_explicit_invoker (Gimp *gimp, if (success) { - /* FIXME: hack */ - if (gimp_drawable_is_gray (drawable) && channel == GIMP_HISTOGRAM_ALPHA) - channel = 1; - - lut = gimp_lut_new (); - - curves_init (&c); - - for (j = 0; j < 256; j++) - c.curve[channel][j] = curve[j]; - - gimp_lut_setup (lut, - (GimpLutFunc) curves_lut_func, - &c, - gimp_drawable_bytes (drawable)); + gint x, y, width, height; /* The application should occur only within selection bounds */ - gimp_drawable_mask_bounds (drawable, &x1, &y1, &x2, &y2); + if (gimp_drawable_mask_intersect (drawable, &x, &y, &width, &height)) + { + Curves c; + gint j; + PixelRegion srcPR, destPR; + GimpLut *lut; - pixel_region_init (&srcPR, gimp_drawable_data (drawable), - x1, y1, (x2 - x1), (y2 - y1), FALSE); - pixel_region_init (&destPR, gimp_drawable_shadow (drawable), - x1, y1, (x2 - x1), (y2 - y1), TRUE); + /* FIXME: hack */ + if (gimp_drawable_is_gray (drawable) && + channel == GIMP_HISTOGRAM_ALPHA) + channel = 1; - pixel_regions_process_parallel ((p_func) gimp_lut_process, lut, 2, - &srcPR, &destPR); + lut = gimp_lut_new (); - gimp_lut_free (lut); + curves_init (&c); - gimp_drawable_merge_shadow (drawable, TRUE, _("Curves")); - gimp_drawable_update (drawable, x1, y1, (x2 - x1), (y2 - y1)); + for (j = 0; j < 256; j++) + c.curve[channel][j] = curve[j]; + + gimp_lut_setup (lut, + (GimpLutFunc) curves_lut_func, + &c, + gimp_drawable_bytes (drawable)); + + pixel_region_init (&srcPR, gimp_drawable_data (drawable), + x, y, width, height, FALSE); + pixel_region_init (&destPR, gimp_drawable_shadow (drawable), + x, y, width, height, TRUE); + + pixel_regions_process_parallel ((p_func) gimp_lut_process, lut, 2, + &srcPR, &destPR); + + gimp_lut_free (lut); + + gimp_drawable_merge_shadow (drawable, TRUE, _("Curves")); + gimp_drawable_update (drawable, x, y, width, height); + } } } @@ -929,10 +942,6 @@ color_balance_invoker (Gimp *gimp, gdouble cyan_red; gdouble magenta_green; gdouble yellow_blue; - ColorBalance cb; - PixelRegionIterator *pr; - PixelRegion srcPR, destPR; - gint x1, y1, x2, y2; drawable = (GimpDrawable *) gimp_item_get_by_ID (gimp, args[0].value.pdb_int); if (! (GIMP_IS_DRAWABLE (drawable) && ! gimp_item_is_removed (GIMP_ITEM (drawable)))) @@ -963,33 +972,40 @@ color_balance_invoker (Gimp *gimp, if (success) { - color_balance_init (&cb); - - cb.preserve_luminosity = preserve_lum; - - cb.cyan_red[transfer_mode] = cyan_red; - cb.magenta_green[transfer_mode] = magenta_green; - cb.yellow_blue[transfer_mode] = yellow_blue; - - color_balance_create_lookup_tables (&cb); + gint x, y, width, height; /* The application should occur only within selection bounds */ - gimp_drawable_mask_bounds (drawable, &x1, &y1, &x2, &y2); - - pixel_region_init (&srcPR, gimp_drawable_data (drawable), - x1, y1, (x2 - x1), (y2 - y1), FALSE); - pixel_region_init (&destPR, gimp_drawable_shadow (drawable), - x1, y1, (x2 - x1), (y2 - y1), TRUE); - - for (pr = pixel_regions_register (2, &srcPR, &destPR); - pr; - pr = pixel_regions_process (pr)) + if (gimp_drawable_mask_intersect (drawable, &x, &y, &width, &height)) { - color_balance (&srcPR, &destPR, &cb); - } + ColorBalance cb; + PixelRegionIterator *pr; + PixelRegion srcPR, destPR; - gimp_drawable_merge_shadow (drawable, TRUE, _("Color Balance")); - gimp_drawable_update (drawable, x1, y1, (x2 - x1), (y2 - y1)); + color_balance_init (&cb); + + cb.preserve_luminosity = preserve_lum; + + cb.cyan_red[transfer_mode] = cyan_red; + cb.magenta_green[transfer_mode] = magenta_green; + cb.yellow_blue[transfer_mode] = yellow_blue; + + color_balance_create_lookup_tables (&cb); + + pixel_region_init (&srcPR, gimp_drawable_data (drawable), + x, y, width, height, FALSE); + pixel_region_init (&destPR, gimp_drawable_shadow (drawable), + x, y, width, height, TRUE); + + for (pr = pixel_regions_register (2, &srcPR, &destPR); + pr; + pr = pixel_regions_process (pr)) + { + color_balance (&srcPR, &destPR, &cb); + } + + gimp_drawable_merge_shadow (drawable, TRUE, _("Color Balance")); + gimp_drawable_update (drawable, x, y, width, height); + } } } @@ -1058,10 +1074,6 @@ colorize_invoker (Gimp *gimp, gdouble hue; gdouble saturation; gdouble lightness; - Colorize colors; - PixelRegionIterator *pr; - PixelRegion srcPR, destPR; - gint x1, y1, x2, y2; drawable = (GimpDrawable *) gimp_item_get_by_ID (gimp, args[0].value.pdb_int); if (! (GIMP_IS_DRAWABLE (drawable) && ! gimp_item_is_removed (GIMP_ITEM (drawable)))) @@ -1086,31 +1098,38 @@ colorize_invoker (Gimp *gimp, if (success) { - colorize_init (&colors); - - colors.hue = hue; - colors.saturation = saturation; - colors.lightness = lightness; - - colorize_calculate (&colors); + gint x, y, width, height; /* The application should occur only within selection bounds */ - gimp_drawable_mask_bounds (drawable, &x1, &y1, &x2, &y2); - - pixel_region_init (&srcPR, gimp_drawable_data (drawable), - x1, y1, (x2 - x1), (y2 - y1), FALSE); - pixel_region_init (&destPR, gimp_drawable_shadow (drawable), - x1, y1, (x2 - x1), (y2 - y1), TRUE); - - for (pr = pixel_regions_register (2, &srcPR, &destPR); - pr; - pr = pixel_regions_process (pr)) + if (gimp_drawable_mask_intersect (drawable, &x, &y, &width, &height)) { - colorize (&srcPR, &destPR, &colors); - } + Colorize colors; + PixelRegionIterator *pr; + PixelRegion srcPR, destPR; - gimp_drawable_merge_shadow (drawable, TRUE, _("Colorize")); - gimp_drawable_update (drawable, x1, y1, (x2 - x1), (y2 - y1)); + colorize_init (&colors); + + colors.hue = hue; + colors.saturation = saturation; + colors.lightness = lightness; + + colorize_calculate (&colors); + + pixel_region_init (&srcPR, gimp_drawable_data (drawable), + x, y, width, height, FALSE); + pixel_region_init (&destPR, gimp_drawable_shadow (drawable), + x, y, width, height, TRUE); + + for (pr = pixel_regions_register (2, &srcPR, &destPR); + pr; + pr = pixel_regions_process (pr)) + { + colorize (&srcPR, &destPR, &colors); + } + + gimp_drawable_merge_shadow (drawable, TRUE, _("Colorize")); + gimp_drawable_update (drawable, x, y, width, height); + } } } @@ -1327,10 +1346,6 @@ hue_saturation_invoker (Gimp *gimp, gdouble hue_offset; gdouble lightness; gdouble saturation; - HueSaturation hs; - PixelRegionIterator *pr; - PixelRegion srcPR, destPR; - gint x1, y1, x2, y2; drawable = (GimpDrawable *) gimp_item_get_by_ID (gimp, args[0].value.pdb_int); if (! (GIMP_IS_DRAWABLE (drawable) && ! gimp_item_is_removed (GIMP_ITEM (drawable)))) @@ -1359,32 +1374,39 @@ hue_saturation_invoker (Gimp *gimp, if (success) { - hue_saturation_init (&hs); - - hs.hue[hue_range] = hue_offset; - hs.lightness[hue_range] = lightness; - hs.saturation[hue_range] = saturation; - - /* Calculate the transfer arrays */ - hue_saturation_calculate_transfers (&hs); + gint x, y, width, height; /* The application should occur only within selection bounds */ - gimp_drawable_mask_bounds (drawable, &x1, &y1, &x2, &y2); - - pixel_region_init (&srcPR, gimp_drawable_data (drawable), - x1, y1, (x2 - x1), (y2 - y1), FALSE); - pixel_region_init (&destPR, gimp_drawable_shadow (drawable), - x1, y1, (x2 - x1), (y2 - y1), TRUE); - - for (pr = pixel_regions_register (2, &srcPR, &destPR); - pr; - pr = pixel_regions_process (pr)) + if (gimp_drawable_mask_intersect (drawable, &x, &y, &width, &height)) { - hue_saturation (&srcPR, &destPR, &hs); - } + HueSaturation hs; + PixelRegionIterator *pr; + PixelRegion srcPR, destPR; - gimp_drawable_merge_shadow (drawable, TRUE, _("Hue-Saturation")); - gimp_drawable_update (drawable, x1, y1, (x2 - x1), (y2 - y1)); + hue_saturation_init (&hs); + + hs.hue[hue_range] = hue_offset; + hs.lightness[hue_range] = lightness; + hs.saturation[hue_range] = saturation; + + /* Calculate the transfer arrays */ + hue_saturation_calculate_transfers (&hs); + + pixel_region_init (&srcPR, gimp_drawable_data (drawable), + x, y, width, height, FALSE); + pixel_region_init (&destPR, gimp_drawable_shadow (drawable), + x, y, width, height, TRUE); + + for (pr = pixel_regions_register (2, &srcPR, &destPR); + pr; + pr = pixel_regions_process (pr)) + { + hue_saturation (&srcPR, &destPR, &hs); + } + + gimp_drawable_merge_shadow (drawable, TRUE, _("Hue-Saturation")); + gimp_drawable_update (drawable, x, y, width, height); + } } } @@ -1447,9 +1469,6 @@ threshold_invoker (Gimp *gimp, GimpDrawable *drawable; gint32 low_threshold; gint32 high_threshold; - Threshold tr; - gint x1, y1, x2, y2; - PixelRegion srcPR, destPR; drawable = (GimpDrawable *) gimp_item_get_by_ID (gimp, args[0].value.pdb_int); if (! (GIMP_IS_DRAWABLE (drawable) && ! gimp_item_is_removed (GIMP_ITEM (drawable)))) @@ -1470,23 +1489,29 @@ threshold_invoker (Gimp *gimp, if (success) { - tr.color = gimp_drawable_is_rgb (drawable); - tr.low_threshold = low_threshold; - tr.high_threshold = high_threshold; + gint x, y, width, height; /* The application should occur only within selection bounds */ - gimp_drawable_mask_bounds (drawable, &x1, &y1, &x2, &y2); + if (gimp_drawable_mask_intersect (drawable, &x, &y, &width, &height)) + { + Threshold tr; + PixelRegion srcPR, destPR; - pixel_region_init (&srcPR, gimp_drawable_data (drawable), - x1, y1, (x2 - x1), (y2 - y1), FALSE); - pixel_region_init (&destPR, gimp_drawable_shadow (drawable), - x1, y1, (x2 - x1), (y2 - y1), TRUE); + tr.color = gimp_drawable_is_rgb (drawable); + tr.low_threshold = low_threshold; + tr.high_threshold = high_threshold; - pixel_regions_process_parallel ((p_func) threshold_2, &tr, 2, - &srcPR, &destPR); + pixel_region_init (&srcPR, gimp_drawable_data (drawable), + x, y, width, height, FALSE); + pixel_region_init (&destPR, gimp_drawable_shadow (drawable), + x, y, width, height, TRUE); - gimp_drawable_merge_shadow (drawable, TRUE, _("Threshold")); - gimp_drawable_update (drawable, x1, y1, (x2 - x1), (y2 - y1)); + pixel_regions_process_parallel ((p_func) threshold_2, &tr, 2, + &srcPR, &destPR); + + gimp_drawable_merge_shadow (drawable, TRUE, _("Threshold")); + gimp_drawable_update (drawable, x, y, width, height); + } } } diff --git a/app/pdb/transform_tools_cmds.c b/app/pdb/transform_tools_cmds.c index 7ca611353e..cce75ccf43 100644 --- a/app/pdb/transform_tools_cmds.c +++ b/app/pdb/transform_tools_cmds.c @@ -170,36 +170,39 @@ perspective_invoker (Gimp *gimp, if (success) { - gint x1, y1, x2, y2; - GimpMatrix3 matrix; - GimpInterpolationType interpolation_type; + gint x, y, width, height; - gimp_drawable_mask_bounds (drawable, &x1, &y1, &x2, &y2); + if (gimp_drawable_mask_intersect (drawable, &x, &y, &width, &height)) + { + GimpMatrix3 matrix; + GimpInterpolationType interpolation_type; - /* Assemble the transformation matrix */ - gimp_transform_matrix_perspective (x1, y1, x2, y2, - trans_info[X0], trans_info[Y0], - trans_info[X1], trans_info[Y1], - trans_info[X2], trans_info[Y2], - trans_info[X3], trans_info[Y3], - &matrix); + /* Assemble the transformation matrix */ + gimp_transform_matrix_perspective (x, y, x + width, y + height, + trans_info[X0], trans_info[Y0], + trans_info[X1], trans_info[Y1], + trans_info[X2], trans_info[Y2], + trans_info[X3], trans_info[Y3], + &matrix); - if (interpolation) - interpolation_type = gimp->config->interpolation_type; - else - interpolation_type = GIMP_INTERPOLATION_NONE; + if (interpolation) + interpolation_type = gimp->config->interpolation_type; + else + interpolation_type = GIMP_INTERPOLATION_NONE; - if (progress) - gimp_progress_start (progress, _("Perspective..."), FALSE); + if (progress) + gimp_progress_start (progress, _("Perspective..."), FALSE); - /* Perspective the selection */ - success = gimp_drawable_transform_affine (drawable, context, - &matrix, GIMP_TRANSFORM_FORWARD, - interpolation_type, TRUE, 3, - FALSE, progress); + /* Perspective the selection */ + success = gimp_drawable_transform_affine (drawable, context, + &matrix, + GIMP_TRANSFORM_FORWARD, + interpolation_type, TRUE, 3, + FALSE, progress); - if (progress) - gimp_progress_end (progress); + if (progress) + gimp_progress_end (progress); + } } } @@ -318,31 +321,35 @@ rotate_invoker (Gimp *gimp, if (success) { - gint x1, y1, x2, y2; - GimpMatrix3 matrix; - GimpInterpolationType interpolation_type; + gint x, y, width, height; - gimp_drawable_mask_bounds (drawable, &x1, &y1, &x2, &y2); + if (gimp_drawable_mask_intersect (drawable, &x, &y, &width, &height)) + { + GimpMatrix3 matrix; + GimpInterpolationType interpolation_type; - /* Assemble the transformation matrix */ - gimp_transform_matrix_rotate (x1, y1, x2, y2, angle, &matrix); + /* Assemble the transformation matrix */ + gimp_transform_matrix_rotate (x, y, x + width, y + height, + angle, &matrix); - if (interpolation) - interpolation_type = gimp->config->interpolation_type; - else - interpolation_type = GIMP_INTERPOLATION_NONE; + if (interpolation) + interpolation_type = gimp->config->interpolation_type; + else + interpolation_type = GIMP_INTERPOLATION_NONE; - if (progress) - gimp_progress_start (progress, _("Rotating..."), FALSE); + if (progress) + gimp_progress_start (progress, _("Rotating..."), FALSE); - /* Rotate the selection */ - success = gimp_drawable_transform_affine (drawable, context, - &matrix, GIMP_TRANSFORM_FORWARD, - interpolation_type, FALSE, 3, - FALSE, progress); + /* Rotate the selection */ + success = gimp_drawable_transform_affine (drawable, context, + &matrix, + GIMP_TRANSFORM_FORWARD, + interpolation_type, FALSE, 3, + FALSE, progress); - if (progress) - gimp_progress_end (progress); + if (progress) + gimp_progress_end (progress); + } } } @@ -433,34 +440,37 @@ scale_invoker (Gimp *gimp, if (success) { - gint x1, y1, x2, y2; - GimpMatrix3 matrix; - GimpInterpolationType interpolation_type; + gint x, y, width, height; - gimp_drawable_mask_bounds (drawable, &x1, &y1, &x2, &y2); + if (gimp_drawable_mask_intersect (drawable, &x, &y, &width, &height)) + { + GimpMatrix3 matrix; + GimpInterpolationType interpolation_type; - /* Assemble the transformation matrix */ - gimp_transform_matrix_scale (x1, y1, x2, y2, - trans_info[X0], trans_info[Y0], - trans_info[X1], trans_info[Y1], - &matrix); + /* Assemble the transformation matrix */ + gimp_transform_matrix_scale (x, y, x + width, y + height, + trans_info[X0], trans_info[Y0], + trans_info[X1], trans_info[Y1], + &matrix); - if (interpolation) - interpolation_type = gimp->config->interpolation_type; - else - interpolation_type = GIMP_INTERPOLATION_NONE; + if (interpolation) + interpolation_type = gimp->config->interpolation_type; + else + interpolation_type = GIMP_INTERPOLATION_NONE; - if (progress) - gimp_progress_start (progress, _("Scaling..."), FALSE); + if (progress) + gimp_progress_start (progress, _("Scaling..."), FALSE); - /* Scale the selection */ - success = gimp_drawable_transform_affine (drawable, context, - &matrix, GIMP_TRANSFORM_FORWARD, - interpolation_type, TRUE, 3, - FALSE, progress); + /* Scale the selection */ + success = gimp_drawable_transform_affine (drawable, context, + &matrix, + GIMP_TRANSFORM_FORWARD, + interpolation_type, TRUE, 3, + FALSE, progress); - if (progress) - gimp_progress_end (progress); + if (progress) + gimp_progress_end (progress); + } } } @@ -563,33 +573,36 @@ shear_invoker (Gimp *gimp, if (success) { - gint x1, y1, x2, y2; - GimpMatrix3 matrix; - GimpInterpolationType interpolation_type; + gint x, y, width, height; - gimp_drawable_mask_bounds (drawable, &x1, &y1, &x2, &y2); + if (gimp_drawable_mask_intersect (drawable, &x, &y, &width, &height)) + { + GimpMatrix3 matrix; + GimpInterpolationType interpolation_type; - /* Assemble the transformation matrix */ - gimp_transform_matrix_shear (x1, y1, x2, y2, - shear_type, magnitude, - &matrix); + /* Assemble the transformation matrix */ + gimp_transform_matrix_shear (x, y, x + width, y + height, + shear_type, magnitude, + &matrix); - if (interpolation) - interpolation_type = gimp->config->interpolation_type; - else - interpolation_type = GIMP_INTERPOLATION_NONE; + if (interpolation) + interpolation_type = gimp->config->interpolation_type; + else + interpolation_type = GIMP_INTERPOLATION_NONE; - if (progress) - gimp_progress_start (progress, _("Shearing..."), FALSE); + if (progress) + gimp_progress_start (progress, _("Shearing..."), FALSE); - /* Shear the selection */ - success = gimp_drawable_transform_affine (drawable, context, - &matrix, GIMP_TRANSFORM_FORWARD, - interpolation_type, FALSE, 3, - FALSE, progress); + /* Shear the selection */ + success = gimp_drawable_transform_affine (drawable, context, + &matrix, + GIMP_TRANSFORM_FORWARD, + interpolation_type, FALSE, 3, + FALSE, progress); - if (progress) - gimp_progress_end (progress); + if (progress) + gimp_progress_end (progress); + } } } diff --git a/tools/pdbgen/pdb/color.pdb b/tools/pdbgen/pdb/color.pdb index d9789682b6..7b1347fe0c 100644 --- a/tools/pdbgen/pdb/color.pdb +++ b/tools/pdbgen/pdb/color.pdb @@ -48,8 +48,6 @@ HELP } %invoke = ( - vars => [ 'GimpImage *gimage', 'GimpLut *lut', - 'PixelRegion srcPR, destPR', 'int x1, y1, x2, y2' ], code => <<'CODE' { if (gimp_drawable_is_indexed (drawable)) @@ -57,27 +55,31 @@ HELP if (success) { - gimage = gimp_item_get_image (GIMP_ITEM (drawable)); - - lut = brightness_contrast_lut_new (brightness / 255.0, - contrast / 127.0, - gimp_drawable_bytes (drawable)); + gint x, y, width, height; /* The application should occur only within selection bounds */ - gimp_drawable_mask_bounds (drawable, &x1, &y1, &x2, &y2); + if (gimp_drawable_mask_intersect (drawable, &x, &y, &width, &height)) + { + GimpLut *lut; + PixelRegion srcPR, destPR; - pixel_region_init (&srcPR, gimp_drawable_data (drawable), - x1, y1, (x2 - x1), (y2 - y1), FALSE); - pixel_region_init (&destPR, gimp_drawable_shadow (drawable), - x1, y1, (x2 - x1), (y2 - y1), TRUE); + lut = brightness_contrast_lut_new (brightness / 255.0, + contrast / 127.0, + gimp_drawable_bytes (drawable)); - pixel_regions_process_parallel ((p_func) gimp_lut_process, lut, 2, - &srcPR, &destPR); + pixel_region_init (&srcPR, gimp_drawable_data (drawable), + x, y, width, height, FALSE); + pixel_region_init (&destPR, gimp_drawable_shadow (drawable), + x, y, width, height, TRUE); - gimp_lut_free (lut); + pixel_regions_process_parallel ((p_func) gimp_lut_process, lut, 2, + &srcPR, &destPR); - gimp_drawable_merge_shadow (drawable, TRUE, _("Brightness-Contrast")); - gimp_drawable_update (drawable, x1, y1, (x2 - x1), (y2 - y1)); + gimp_lut_free (lut); + + gimp_drawable_merge_shadow (drawable, TRUE, _("Brightness-Contrast")); + gimp_drawable_update (drawable, x, y, width, height); + } } } CODE @@ -120,8 +122,6 @@ HELP %invoke = ( headers => [ qw("base/levels.h") ], - vars => [ 'PixelRegion srcPR, destPR', 'Levels l', 'gint x1, y1, x2, y2', - 'GimpLut *lut' ], code => <<'CODE' { if (gimp_drawable_is_indexed (drawable) || @@ -133,41 +133,49 @@ HELP if (success) { - /* FIXME: hack */ - if (gimp_drawable_is_gray (drawable) && channel == GIMP_HISTOGRAM_ALPHA) - channel = 1; - - lut = gimp_lut_new (); - - levels_init (&l); - - l.low_input[channel] = low_input; - l.high_input[channel] = high_input; - l.gamma[channel] = gamma; - l.low_output[channel] = low_output; - l.high_output[channel] = high_output; - - /* setup the lut */ - gimp_lut_setup (lut, - (GimpLutFunc) levels_lut_func, - &l, - gimp_drawable_bytes (drawable)); + gint x, y, width, height; /* The application should occur only within selection bounds */ - gimp_drawable_mask_bounds (drawable, &x1, &y1, &x2, &y2); + if (gimp_drawable_mask_intersect (drawable, &x, &y, &width, &height)) + { + PixelRegion srcPR, destPR; + Levels l; + GimpLut *lut; - pixel_region_init (&srcPR, gimp_drawable_data (drawable), - x1, y1, (x2 - x1), (y2 - y1), FALSE); - pixel_region_init (&destPR, gimp_drawable_shadow (drawable), - x1, y1, (x2 - x1), (y2 - y1), TRUE); + /* FIXME: hack */ + if (gimp_drawable_is_gray (drawable) && + channel == GIMP_HISTOGRAM_ALPHA) + channel = 1; - pixel_regions_process_parallel ((p_func) gimp_lut_process, lut, 2, - &srcPR, &destPR); + lut = gimp_lut_new (); - gimp_lut_free (lut); + levels_init (&l); - gimp_drawable_merge_shadow (drawable, TRUE, _("Levels")); - gimp_drawable_update (drawable, x1, y1, (x2 - x1), (y2 - y1)); + l.low_input[channel] = low_input; + l.high_input[channel] = high_input; + l.gamma[channel] = gamma; + l.low_output[channel] = low_output; + l.high_output[channel] = high_output; + + /* setup the lut */ + gimp_lut_setup (lut, + (GimpLutFunc) levels_lut_func, + &l, + gimp_drawable_bytes (drawable)); + + pixel_region_init (&srcPR, gimp_drawable_data (drawable), + x, y, width, height, FALSE); + pixel_region_init (&destPR, gimp_drawable_shadow (drawable), + x, y, width, height, TRUE); + + pixel_regions_process_parallel ((p_func) gimp_lut_process, lut, 2, + &srcPR, &destPR); + + gimp_lut_free (lut); + + gimp_drawable_merge_shadow (drawable, TRUE, _("Levels")); + gimp_drawable_update (drawable, x, y, width, height); + } } } CODE @@ -195,12 +203,6 @@ HELP %invoke = ( headers => [ qw("base/levels.h" "base/gimphistogram.h" "core/gimpdrawable-histogram.h") ], - vars => [ 'PixelRegion srcPR, destPR', - 'Levels levels', - 'gint x1, y1, x2, y2', - 'GimpLut *lut', - 'GimpImage *image', - 'GimpHistogram *hist' ], code => <<'CODE' { if (gimp_drawable_is_indexed (drawable)) @@ -208,39 +210,46 @@ HELP if (success) { - /* Build the histogram */ - image = gimp_item_get_image (GIMP_ITEM (drawable)); - hist = gimp_histogram_new (GIMP_BASE_CONFIG (image->gimp->config)); - - gimp_drawable_calculate_histogram (drawable, hist); - - /* Calculate the levels */ - levels_init (&levels); - levels_auto (&levels, hist, ! gimp_drawable_is_gray (drawable)); - - /* Set up the lut */ - lut = gimp_lut_new (); - gimp_lut_setup (lut, - (GimpLutFunc) levels_lut_func, - &levels, - gimp_drawable_bytes (drawable)); + gint x, y, width, height; /* The application should occur only within selection bounds */ - gimp_drawable_mask_bounds (drawable, &x1, &y1, &x2, &y2); + if (gimp_drawable_mask_intersect (drawable, &x, &y, &width, &height)) + { + PixelRegion srcPR, destPR; + Levels levels; + GimpLut *lut; + GimpHistogram *hist; - pixel_region_init (&srcPR, gimp_drawable_data (drawable), - x1, y1, (x2 - x1), (y2 - y1), FALSE); - pixel_region_init (&destPR, gimp_drawable_shadow (drawable), - x1, y1, (x2 - x1), (y2 - y1), TRUE); + /* Build the histogram */ + hist = gimp_histogram_new (GIMP_BASE_CONFIG (gimp->config)); - pixel_regions_process_parallel ((p_func) gimp_lut_process, lut, 2, - &srcPR, &destPR); + gimp_drawable_calculate_histogram (drawable, hist); - gimp_lut_free (lut); - gimp_histogram_free (hist); + /* Calculate the levels */ + levels_init (&levels); + levels_auto (&levels, hist, ! gimp_drawable_is_gray (drawable)); - gimp_drawable_merge_shadow (drawable, TRUE, _("Levels")); - gimp_drawable_update (drawable, x1, y1, (x2 - x1), (y2 - y1)); + /* Set up the lut */ + lut = gimp_lut_new (); + gimp_lut_setup (lut, + (GimpLutFunc) levels_lut_func, + &levels, + gimp_drawable_bytes (drawable)); + + pixel_region_init (&srcPR, gimp_drawable_data (drawable), + x, y, width, height, FALSE); + pixel_region_init (&destPR, gimp_drawable_shadow (drawable), + x, y, width, height, TRUE); + + pixel_regions_process_parallel ((p_func) gimp_lut_process, lut, 2, + &srcPR, &destPR); + + gimp_lut_free (lut); + gimp_histogram_free (hist); + + gimp_drawable_merge_shadow (drawable, TRUE, _("Levels")); + gimp_drawable_update (drawable, x, y, width, height); + } } } CODE @@ -265,8 +274,6 @@ HELP ); %invoke = ( - vars => [ 'GimpImage *gimage', 'GimpLut *lut', - 'PixelRegion srcPR, destPR', 'int x1, y1, x2, y2' ], code => <<'CODE' { if (gimp_drawable_is_indexed (drawable)) @@ -274,25 +281,29 @@ HELP if (success) { - gimage = gimp_item_get_image (GIMP_ITEM (drawable)); - - lut = posterize_lut_new (levels, gimp_drawable_bytes (drawable)); + gint x, y, width, height; /* The application should occur only within selection bounds */ - gimp_drawable_mask_bounds (drawable, &x1, &y1, &x2, &y2); + if (gimp_drawable_mask_intersect (drawable, &x, &y, &width, &height)) + { + GimpLut *lut; + PixelRegion srcPR, destPR; - pixel_region_init (&srcPR, gimp_drawable_data (drawable), - x1, y1, (x2 - x1), (y2 - y1), FALSE); - pixel_region_init (&destPR, gimp_drawable_shadow (drawable), - x1, y1, (x2 - x1), (y2 - y1), TRUE); + lut = posterize_lut_new (levels, gimp_drawable_bytes (drawable)); - pixel_regions_process_parallel ((p_func) gimp_lut_process, lut, 2, - &srcPR, &destPR); + pixel_region_init (&srcPR, gimp_drawable_data (drawable), + x, y, width, height, FALSE); + pixel_region_init (&destPR, gimp_drawable_shadow (drawable), + x, y, width, height, TRUE); - gimp_lut_free (lut); + pixel_regions_process_parallel ((p_func) gimp_lut_process, lut, 2, + &srcPR, &destPR); - gimp_drawable_merge_shadow (drawable, TRUE, _("Posterize")); - gimp_drawable_update (drawable, x1, y1, (x2 - x1), (y2 - y1)); + gimp_lut_free (lut); + + gimp_drawable_merge_shadow (drawable, TRUE, _("Posterize")); + gimp_drawable_update (drawable, x, y, width, height); + } } } CODE @@ -411,8 +422,6 @@ HELP %invoke = ( headers => [ qw("base/curves.h") ], - vars => [ 'Curves c', 'gint x1, y1, x2, y2', 'gint j', - 'PixelRegion srcPR, destPR', 'GimpLut *lut' ], code => <<'CODE' { if (gimp_drawable_is_indexed (drawable) || (num_points & 1) || @@ -424,46 +433,55 @@ HELP if (success) { - /* FIXME: hack */ - if (gimp_drawable_is_gray (drawable) && channel == GIMP_HISTOGRAM_ALPHA) - channel = 1; - - lut = gimp_lut_new (); - - curves_init (&c); - - /* unset the last point */ - c.points[channel][CURVES_NUM_POINTS - 1][0] = -1; - c.points[channel][CURVES_NUM_POINTS - 1][1] = -1; - - for (j = 0; j < num_points / 2; j++) - { - c.points[channel][j][0] = control_pts[j * 2]; - c.points[channel][j][1] = control_pts[j * 2 + 1]; - } - - curves_calculate_curve (&c, channel); - - gimp_lut_setup (lut, - (GimpLutFunc) curves_lut_func, - &c, - gimp_drawable_bytes (drawable)); + gint x, y, width, height; /* The application should occur only within selection bounds */ - gimp_drawable_mask_bounds (drawable, &x1, &y1, &x2, &y2); + if (gimp_drawable_mask_intersect (drawable, &x, &y, &width, &height)) + { + Curves c; + gint j; + PixelRegion srcPR, destPR; + GimpLut *lut; - pixel_region_init (&srcPR, gimp_drawable_data (drawable), - x1, y1, (x2 - x1), (y2 - y1), FALSE); - pixel_region_init (&destPR, gimp_drawable_shadow (drawable), - x1, y1, (x2 - x1), (y2 - y1), TRUE); + /* FIXME: hack */ + if (gimp_drawable_is_gray (drawable) && + channel == GIMP_HISTOGRAM_ALPHA) + channel = 1; - pixel_regions_process_parallel ((p_func) gimp_lut_process, lut, 2, - &srcPR, &destPR); + lut = gimp_lut_new (); - gimp_lut_free (lut); + curves_init (&c); - gimp_drawable_merge_shadow (drawable, TRUE, _("Curves")); - gimp_drawable_update (drawable, x1, y1, (x2 - x1), (y2 - y1)); + /* unset the last point */ + c.points[channel][CURVES_NUM_POINTS - 1][0] = -1; + c.points[channel][CURVES_NUM_POINTS - 1][1] = -1; + + for (j = 0; j < num_points / 2; j++) + { + c.points[channel][j][0] = control_pts[j * 2]; + c.points[channel][j][1] = control_pts[j * 2 + 1]; + } + + curves_calculate_curve (&c, channel); + + gimp_lut_setup (lut, + (GimpLutFunc) curves_lut_func, + &c, + gimp_drawable_bytes (drawable)); + + pixel_region_init (&srcPR, gimp_drawable_data (drawable), + x, y, width, height, FALSE); + pixel_region_init (&destPR, gimp_drawable_shadow (drawable), + x, y, width, height, TRUE); + + pixel_regions_process_parallel ((p_func) gimp_lut_process, lut, 2, + &srcPR, &destPR); + + gimp_lut_free (lut); + + gimp_drawable_merge_shadow (drawable, TRUE, _("Curves")); + gimp_drawable_update (drawable, x, y, width, height); + } } } CODE @@ -496,8 +514,6 @@ HELP %invoke = ( headers => [ qw("base/curves.h") ], - vars => [ 'Curves c', 'gint x1, y1, x2, y2', 'gint j', - 'PixelRegion srcPR, destPR', 'GimpLut *lut' ], code => <<'CODE' { if (gimp_drawable_is_indexed (drawable) || (num_bytes != 256) || @@ -509,37 +525,46 @@ HELP if (success) { - /* FIXME: hack */ - if (gimp_drawable_is_gray (drawable) && channel == GIMP_HISTOGRAM_ALPHA) - channel = 1; + gint x, y, width, height; - lut = gimp_lut_new (); - - curves_init (&c); - - for (j = 0; j < 256; j++) - c.curve[channel][j] = curve[j]; - - gimp_lut_setup (lut, - (GimpLutFunc) curves_lut_func, - &c, - gimp_drawable_bytes (drawable)); - /* The application should occur only within selection bounds */ - gimp_drawable_mask_bounds (drawable, &x1, &y1, &x2, &y2); + if (gimp_drawable_mask_intersect (drawable, &x, &y, &width, &height)) + { + Curves c; + gint j; + PixelRegion srcPR, destPR; + GimpLut *lut; - pixel_region_init (&srcPR, gimp_drawable_data (drawable), - x1, y1, (x2 - x1), (y2 - y1), FALSE); - pixel_region_init (&destPR, gimp_drawable_shadow (drawable), - x1, y1, (x2 - x1), (y2 - y1), TRUE); + /* FIXME: hack */ + if (gimp_drawable_is_gray (drawable) && + channel == GIMP_HISTOGRAM_ALPHA) + channel = 1; - pixel_regions_process_parallel ((p_func) gimp_lut_process, lut, 2, - &srcPR, &destPR); + lut = gimp_lut_new (); - gimp_lut_free (lut); + curves_init (&c); - gimp_drawable_merge_shadow (drawable, TRUE, _("Curves")); - gimp_drawable_update (drawable, x1, y1, (x2 - x1), (y2 - y1)); + for (j = 0; j < 256; j++) + c.curve[channel][j] = curve[j]; + + gimp_lut_setup (lut, + (GimpLutFunc) curves_lut_func, + &c, + gimp_drawable_bytes (drawable)); + + pixel_region_init (&srcPR, gimp_drawable_data (drawable), + x, y, width, height, FALSE); + pixel_region_init (&destPR, gimp_drawable_shadow (drawable), + x, y, width, height, TRUE); + + pixel_regions_process_parallel ((p_func) gimp_lut_process, lut, 2, + &srcPR, &destPR); + + gimp_lut_free (lut); + + gimp_drawable_merge_shadow (drawable, TRUE, _("Curves")); + gimp_drawable_update (drawable, x, y, width, height); + } } } CODE @@ -579,8 +604,6 @@ HELP %invoke = ( headers => [ qw("base/color-balance.h") ], - vars => [ 'ColorBalance cb', 'PixelRegionIterator *pr', - 'PixelRegion srcPR, destPR', 'gint x1, y1, x2, y2' ], code => <<'CODE' { if (gimp_drawable_is_indexed (drawable)) @@ -588,33 +611,40 @@ HELP if (success) { - color_balance_init (&cb); - - cb.preserve_luminosity = preserve_lum; - - cb.cyan_red[transfer_mode] = cyan_red; - cb.magenta_green[transfer_mode] = magenta_green; - cb.yellow_blue[transfer_mode] = yellow_blue; - - color_balance_create_lookup_tables (&cb); + gint x, y, width, height; /* The application should occur only within selection bounds */ - gimp_drawable_mask_bounds (drawable, &x1, &y1, &x2, &y2); - - pixel_region_init (&srcPR, gimp_drawable_data (drawable), - x1, y1, (x2 - x1), (y2 - y1), FALSE); - pixel_region_init (&destPR, gimp_drawable_shadow (drawable), - x1, y1, (x2 - x1), (y2 - y1), TRUE); - - for (pr = pixel_regions_register (2, &srcPR, &destPR); - pr; - pr = pixel_regions_process (pr)) + if (gimp_drawable_mask_intersect (drawable, &x, &y, &width, &height)) { - color_balance (&srcPR, &destPR, &cb); - } + ColorBalance cb; + PixelRegionIterator *pr; + PixelRegion srcPR, destPR; - gimp_drawable_merge_shadow (drawable, TRUE, _("Color Balance")); - gimp_drawable_update (drawable, x1, y1, (x2 - x1), (y2 - y1)); + color_balance_init (&cb); + + cb.preserve_luminosity = preserve_lum; + + cb.cyan_red[transfer_mode] = cyan_red; + cb.magenta_green[transfer_mode] = magenta_green; + cb.yellow_blue[transfer_mode] = yellow_blue; + + color_balance_create_lookup_tables (&cb); + + pixel_region_init (&srcPR, gimp_drawable_data (drawable), + x, y, width, height, FALSE); + pixel_region_init (&destPR, gimp_drawable_shadow (drawable), + x, y, width, height, TRUE); + + for (pr = pixel_regions_register (2, &srcPR, &destPR); + pr; + pr = pixel_regions_process (pr)) + { + color_balance (&srcPR, &destPR, &cb); + } + + gimp_drawable_merge_shadow (drawable, TRUE, _("Color Balance")); + gimp_drawable_update (drawable, x, y, width, height); + } } } CODE @@ -646,8 +676,6 @@ HELP %invoke = ( headers => [ qw("base/colorize.h") ], - vars => [ 'Colorize colors', 'PixelRegionIterator *pr', - 'PixelRegion srcPR, destPR', 'gint x1, y1, x2, y2' ], code => <<'CODE' { if (! gimp_drawable_is_rgb (drawable)) @@ -655,31 +683,38 @@ HELP if (success) { - colorize_init (&colors); - - colors.hue = hue; - colors.saturation = saturation; - colors.lightness = lightness; - - colorize_calculate (&colors); + gint x, y, width, height; /* The application should occur only within selection bounds */ - gimp_drawable_mask_bounds (drawable, &x1, &y1, &x2, &y2); - - pixel_region_init (&srcPR, gimp_drawable_data (drawable), - x1, y1, (x2 - x1), (y2 - y1), FALSE); - pixel_region_init (&destPR, gimp_drawable_shadow (drawable), - x1, y1, (x2 - x1), (y2 - y1), TRUE); - - for (pr = pixel_regions_register (2, &srcPR, &destPR); - pr; - pr = pixel_regions_process (pr)) + if (gimp_drawable_mask_intersect (drawable, &x, &y, &width, &height)) { - colorize (&srcPR, &destPR, &colors); - } + Colorize colors; + PixelRegionIterator *pr; + PixelRegion srcPR, destPR; - gimp_drawable_merge_shadow (drawable, TRUE, _("Colorize")); - gimp_drawable_update (drawable, x1, y1, (x2 - x1), (y2 - y1)); + colorize_init (&colors); + + colors.hue = hue; + colors.saturation = saturation; + colors.lightness = lightness; + + colorize_calculate (&colors); + + pixel_region_init (&srcPR, gimp_drawable_data (drawable), + x, y, width, height, FALSE); + pixel_region_init (&destPR, gimp_drawable_shadow (drawable), + x, y, width, height, TRUE); + + for (pr = pixel_regions_register (2, &srcPR, &destPR); + pr; + pr = pixel_regions_process (pr)) + { + colorize (&srcPR, &destPR, &colors); + } + + gimp_drawable_merge_shadow (drawable, TRUE, _("Colorize")); + gimp_drawable_update (drawable, x, y, width, height); + } } } CODE @@ -803,8 +838,6 @@ HELP %invoke = ( headers => [ qw("base/hue-saturation.h") ], - vars => [ 'HueSaturation hs', 'PixelRegionIterator *pr', - 'PixelRegion srcPR, destPR', 'gint x1, y1, x2, y2' ], code => <<'CODE' { if (gimp_drawable_is_indexed (drawable)) @@ -812,32 +845,39 @@ HELP if (success) { - hue_saturation_init (&hs); - - hs.hue[hue_range] = hue_offset; - hs.lightness[hue_range] = lightness; - hs.saturation[hue_range] = saturation; - - /* Calculate the transfer arrays */ - hue_saturation_calculate_transfers (&hs); + gint x, y, width, height; /* The application should occur only within selection bounds */ - gimp_drawable_mask_bounds (drawable, &x1, &y1, &x2, &y2); - - pixel_region_init (&srcPR, gimp_drawable_data (drawable), - x1, y1, (x2 - x1), (y2 - y1), FALSE); - pixel_region_init (&destPR, gimp_drawable_shadow (drawable), - x1, y1, (x2 - x1), (y2 - y1), TRUE); - - for (pr = pixel_regions_register (2, &srcPR, &destPR); - pr; - pr = pixel_regions_process (pr)) + if (gimp_drawable_mask_intersect (drawable, &x, &y, &width, &height)) { - hue_saturation (&srcPR, &destPR, &hs); - } + HueSaturation hs; + PixelRegionIterator *pr; + PixelRegion srcPR, destPR; - gimp_drawable_merge_shadow (drawable, TRUE, _("Hue-Saturation")); - gimp_drawable_update (drawable, x1, y1, (x2 - x1), (y2 - y1)); + hue_saturation_init (&hs); + + hs.hue[hue_range] = hue_offset; + hs.lightness[hue_range] = lightness; + hs.saturation[hue_range] = saturation; + + /* Calculate the transfer arrays */ + hue_saturation_calculate_transfers (&hs); + + pixel_region_init (&srcPR, gimp_drawable_data (drawable), + x, y, width, height, FALSE); + pixel_region_init (&destPR, gimp_drawable_shadow (drawable), + x, y, width, height, TRUE); + + for (pr = pixel_regions_register (2, &srcPR, &destPR); + pr; + pr = pixel_regions_process (pr)) + { + hue_saturation (&srcPR, &destPR, &hs); + } + + gimp_drawable_merge_shadow (drawable, TRUE, _("Hue-Saturation")); + gimp_drawable_update (drawable, x, y, width, height); + } } } CODE @@ -864,8 +904,6 @@ HELP %invoke = ( headers => [ qw("base/threshold.h") ], - vars => [ 'Threshold tr', 'gint x1, y1, x2, y2', - 'PixelRegion srcPR, destPR' ], code => <<'CODE' { if (gimp_drawable_is_indexed (drawable) || (low_threshold >= high_threshold)) @@ -873,23 +911,29 @@ HELP if (success) { - tr.color = gimp_drawable_is_rgb (drawable); - tr.low_threshold = low_threshold; - tr.high_threshold = high_threshold; + gint x, y, width, height; /* The application should occur only within selection bounds */ - gimp_drawable_mask_bounds (drawable, &x1, &y1, &x2, &y2); + if (gimp_drawable_mask_intersect (drawable, &x, &y, &width, &height)) + { + Threshold tr; + PixelRegion srcPR, destPR; - pixel_region_init (&srcPR, gimp_drawable_data (drawable), - x1, y1, (x2 - x1), (y2 - y1), FALSE); - pixel_region_init (&destPR, gimp_drawable_shadow (drawable), - x1, y1, (x2 - x1), (y2 - y1), TRUE); + tr.color = gimp_drawable_is_rgb (drawable); + tr.low_threshold = low_threshold; + tr.high_threshold = high_threshold; - pixel_regions_process_parallel ((p_func) threshold_2, &tr, 2, - &srcPR, &destPR); + pixel_region_init (&srcPR, gimp_drawable_data (drawable), + x, y, width, height, FALSE); + pixel_region_init (&destPR, gimp_drawable_shadow (drawable), + x, y, width, height, TRUE); - gimp_drawable_merge_shadow (drawable, TRUE, _("Threshold")); - gimp_drawable_update (drawable, x1, y1, (x2 - x1), (y2 - y1)); + pixel_regions_process_parallel ((p_func) threshold_2, &tr, 2, + &srcPR, &destPR); + + gimp_drawable_merge_shadow (drawable, TRUE, _("Threshold")); + gimp_drawable_update (drawable, x, y, width, height); + } } } CODE diff --git a/tools/pdbgen/pdb/transform_tools.pdb b/tools/pdbgen/pdb/transform_tools.pdb index 8fe9c53c6a..88d0ff0d73 100644 --- a/tools/pdbgen/pdb/transform_tools.pdb +++ b/tools/pdbgen/pdb/transform_tools.pdb @@ -130,36 +130,39 @@ HELP if (success) { - gint x1, y1, x2, y2; - GimpMatrix3 matrix; - GimpInterpolationType interpolation_type; + gint x, y, width, height; - gimp_drawable_mask_bounds (drawable, &x1, &y1, &x2, &y2); + if (gimp_drawable_mask_intersect (drawable, &x, &y, &width, &height)) + { + GimpMatrix3 matrix; + GimpInterpolationType interpolation_type; - /* Assemble the transformation matrix */ - gimp_transform_matrix_perspective (x1, y1, x2, y2, - trans_info[X0], trans_info[Y0], - trans_info[X1], trans_info[Y1], - trans_info[X2], trans_info[Y2], - trans_info[X3], trans_info[Y3], - &matrix); + /* Assemble the transformation matrix */ + gimp_transform_matrix_perspective (x, y, x + width, y + height, + trans_info[X0], trans_info[Y0], + trans_info[X1], trans_info[Y1], + trans_info[X2], trans_info[Y2], + trans_info[X3], trans_info[Y3], + &matrix); - if (interpolation) - interpolation_type = gimp->config->interpolation_type; - else - interpolation_type = GIMP_INTERPOLATION_NONE; + if (interpolation) + interpolation_type = gimp->config->interpolation_type; + else + interpolation_type = GIMP_INTERPOLATION_NONE; - if (progress) - gimp_progress_start (progress, _("Perspective..."), FALSE); + if (progress) + gimp_progress_start (progress, _("Perspective..."), FALSE); - /* Perspective the selection */ - success = gimp_drawable_transform_affine (drawable, context, - &matrix, GIMP_TRANSFORM_FORWARD, - interpolation_type, TRUE, 3, - FALSE, progress); + /* Perspective the selection */ + success = gimp_drawable_transform_affine (drawable, context, + &matrix, + GIMP_TRANSFORM_FORWARD, + interpolation_type, TRUE, 3, + FALSE, progress); - if (progress) - gimp_progress_end (progress); + if (progress) + gimp_progress_end (progress); + } } } CODE @@ -201,31 +204,35 @@ HELP if (success) { - gint x1, y1, x2, y2; - GimpMatrix3 matrix; - GimpInterpolationType interpolation_type; + gint x, y, width, height; - gimp_drawable_mask_bounds (drawable, &x1, &y1, &x2, &y2); + if (gimp_drawable_mask_intersect (drawable, &x, &y, &width, &height)) + { + GimpMatrix3 matrix; + GimpInterpolationType interpolation_type; - /* Assemble the transformation matrix */ - gimp_transform_matrix_rotate (x1, y1, x2, y2, angle, &matrix); + /* Assemble the transformation matrix */ + gimp_transform_matrix_rotate (x, y, x + width, y + height, + angle, &matrix); - if (interpolation) - interpolation_type = gimp->config->interpolation_type; - else - interpolation_type = GIMP_INTERPOLATION_NONE; + if (interpolation) + interpolation_type = gimp->config->interpolation_type; + else + interpolation_type = GIMP_INTERPOLATION_NONE; - if (progress) - gimp_progress_start (progress, _("Rotating..."), FALSE); + if (progress) + gimp_progress_start (progress, _("Rotating..."), FALSE); - /* Rotate the selection */ - success = gimp_drawable_transform_affine (drawable, context, - &matrix, GIMP_TRANSFORM_FORWARD, - interpolation_type, FALSE, 3, - FALSE, progress); + /* Rotate the selection */ + success = gimp_drawable_transform_affine (drawable, context, + &matrix, + GIMP_TRANSFORM_FORWARD, + interpolation_type, FALSE, 3, + FALSE, progress); - if (progress) - gimp_progress_end (progress); + if (progress) + gimp_progress_end (progress); + } } } CODE @@ -278,34 +285,37 @@ HELP if (success) { - gint x1, y1, x2, y2; - GimpMatrix3 matrix; - GimpInterpolationType interpolation_type; + gint x, y, width, height; - gimp_drawable_mask_bounds (drawable, &x1, &y1, &x2, &y2); + if (gimp_drawable_mask_intersect (drawable, &x, &y, &width, &height)) + { + GimpMatrix3 matrix; + GimpInterpolationType interpolation_type; - /* Assemble the transformation matrix */ - gimp_transform_matrix_scale (x1, y1, x2, y2, - trans_info[X0], trans_info[Y0], - trans_info[X1], trans_info[Y1], - &matrix); + /* Assemble the transformation matrix */ + gimp_transform_matrix_scale (x, y, x + width, y + height, + trans_info[X0], trans_info[Y0], + trans_info[X1], trans_info[Y1], + &matrix); - if (interpolation) - interpolation_type = gimp->config->interpolation_type; - else - interpolation_type = GIMP_INTERPOLATION_NONE; + if (interpolation) + interpolation_type = gimp->config->interpolation_type; + else + interpolation_type = GIMP_INTERPOLATION_NONE; - if (progress) - gimp_progress_start (progress, _("Scaling..."), FALSE); + if (progress) + gimp_progress_start (progress, _("Scaling..."), FALSE); - /* Scale the selection */ - success = gimp_drawable_transform_affine (drawable, context, - &matrix, GIMP_TRANSFORM_FORWARD, - interpolation_type, TRUE, 3, - FALSE, progress); + /* Scale the selection */ + success = gimp_drawable_transform_affine (drawable, context, + &matrix, + GIMP_TRANSFORM_FORWARD, + interpolation_type, TRUE, 3, + FALSE, progress); - if (progress) - gimp_progress_end (progress); + if (progress) + gimp_progress_end (progress); + } } } CODE @@ -352,33 +362,36 @@ HELP if (success) { - gint x1, y1, x2, y2; - GimpMatrix3 matrix; - GimpInterpolationType interpolation_type; + gint x, y, width, height; - gimp_drawable_mask_bounds (drawable, &x1, &y1, &x2, &y2); + if (gimp_drawable_mask_intersect (drawable, &x, &y, &width, &height)) + { + GimpMatrix3 matrix; + GimpInterpolationType interpolation_type; - /* Assemble the transformation matrix */ - gimp_transform_matrix_shear (x1, y1, x2, y2, - shear_type, magnitude, - &matrix); + /* Assemble the transformation matrix */ + gimp_transform_matrix_shear (x, y, x + width, y + height, + shear_type, magnitude, + &matrix); - if (interpolation) - interpolation_type = gimp->config->interpolation_type; - else - interpolation_type = GIMP_INTERPOLATION_NONE; + if (interpolation) + interpolation_type = gimp->config->interpolation_type; + else + interpolation_type = GIMP_INTERPOLATION_NONE; - if (progress) - gimp_progress_start (progress, _("Shearing..."), FALSE); + if (progress) + gimp_progress_start (progress, _("Shearing..."), FALSE); - /* Shear the selection */ - success = gimp_drawable_transform_affine (drawable, context, - &matrix, GIMP_TRANSFORM_FORWARD, - interpolation_type, FALSE, 3, - FALSE, progress); + /* Shear the selection */ + success = gimp_drawable_transform_affine (drawable, context, + &matrix, + GIMP_TRANSFORM_FORWARD, + interpolation_type, FALSE, 3, + FALSE, progress); - if (progress) - gimp_progress_end (progress); + if (progress) + gimp_progress_end (progress); + } } } CODE