From 33a389cd0ca4ea795f01008765ad40a53631e004 Mon Sep 17 00:00:00 2001 From: Ell Date: Fri, 9 Aug 2019 21:51:27 +0300 Subject: [PATCH] app, pdb: use gimp_item_get_clip() everywhere Remove the special clipping-mode handling for channels throughout the transform (and drawable-filter) code, and rather use gimp_item_get_clip(), added in the previous commit, instead. As mentioned in the previous commit, we only modify the clipping mode in top-level code, while having lower-level code use the clipping mode as-is. This not only hides the actual clipping-mode logic from the transform code, but, in particular, allows code performing transformation internally to use arbitrary clipping modes. Also, this commit fixes a bunch of PDB bugs all over the place :) --- app/actions/drawable-commands.c | 12 +++--- app/core/gimpchannel.c | 68 ------------------------------- app/core/gimpdrawable-transform.c | 60 --------------------------- app/core/gimpdrawable-transform.h | 4 -- app/core/gimpdrawablefilter.c | 8 +--- app/core/gimpimage-item-list.c | 25 +++++++++--- app/core/gimpitem-linked.c | 19 +-------- app/pdb/item-transform-cmds.c | 27 ++++++++---- app/tools/gimpfiltertool.c | 2 +- app/tools/gimpfliptool.c | 16 ++------ app/tools/gimptransformtool.c | 36 +++------------- pdb/groups/item_transform.pdb | 9 ++-- 12 files changed, 61 insertions(+), 225 deletions(-) diff --git a/app/actions/drawable-commands.c b/app/actions/drawable-commands.c index 1a20aace4a..7ea70e8b6d 100644 --- a/app/actions/drawable-commands.c +++ b/app/actions/drawable-commands.c @@ -257,7 +257,8 @@ drawable_flip_cmd_callback (GimpAction *action, } else { - gimp_item_flip (item, context, orientation, axis, FALSE); + gimp_item_flip (item, context, orientation, axis, + gimp_item_get_clip (item, FALSE)); } gimp_image_flush (image); @@ -274,7 +275,6 @@ drawable_rotate_cmd_callback (GimpAction *action, GimpItem *item; gint off_x, off_y; gdouble center_x, center_y; - gboolean clip_result = FALSE; GimpRotationType rotation_type; return_if_no_drawable (image, drawable, data); return_if_no_context (context, data); @@ -288,9 +288,6 @@ drawable_rotate_cmd_callback (GimpAction *action, center_x = ((gdouble) off_x + (gdouble) gimp_item_get_width (item) / 2.0); center_y = ((gdouble) off_y + (gdouble) gimp_item_get_height (item) / 2.0); - if (GIMP_IS_CHANNEL (item)) - clip_result = TRUE; - if (gimp_item_get_linked (item)) { gimp_item_linked_rotate (item, context, rotation_type, @@ -298,8 +295,9 @@ drawable_rotate_cmd_callback (GimpAction *action, } else { - gimp_item_rotate (item, context, rotation_type, - center_x, center_y, clip_result); + gimp_item_rotate (item, context, + rotation_type, center_x, center_y, + gimp_item_get_clip (item, FALSE)); } gimp_image_flush (image); diff --git a/app/core/gimpchannel.c b/app/core/gimpchannel.c index c40097e8ca..6ec93d3c12 100644 --- a/app/core/gimpchannel.c +++ b/app/core/gimpchannel.c @@ -111,24 +111,6 @@ static void gimp_channel_resize (GimpItem *item, gint new_height, gint offset_x, gint offset_y); -static void gimp_channel_flip (GimpItem *item, - GimpContext *context, - GimpOrientationType flip_type, - gdouble axis, - gboolean flip_result); -static void gimp_channel_rotate (GimpItem *item, - GimpContext *context, - GimpRotationType flip_type, - gdouble center_x, - gdouble center_y, - gboolean flip_result); -static void gimp_channel_transform (GimpItem *item, - GimpContext *context, - const GimpMatrix3 *matrix, - GimpTransformDirection direction, - GimpInterpolationType interpolation_type, - GimpTransformResize clip_result, - GimpProgress *progress); static GimpTransformResize gimp_channel_get_clip (GimpItem *item, GimpTransformResize clip_result); @@ -267,9 +249,6 @@ gimp_channel_class_init (GimpChannelClass *klass) item_class->translate = gimp_channel_translate; item_class->scale = gimp_channel_scale; item_class->resize = gimp_channel_resize; - item_class->flip = gimp_channel_flip; - item_class->rotate = gimp_channel_rotate; - item_class->transform = gimp_channel_transform; item_class->get_clip = gimp_channel_get_clip; item_class->fill = gimp_channel_fill; item_class->stroke = gimp_channel_stroke; @@ -775,53 +754,6 @@ gimp_channel_resize (GimpItem *item, } } -static void -gimp_channel_flip (GimpItem *item, - GimpContext *context, - GimpOrientationType flip_type, - gdouble axis, - gboolean clip_result) -{ - if (G_TYPE_FROM_INSTANCE (item) == GIMP_TYPE_CHANNEL) - clip_result = TRUE; - - GIMP_ITEM_CLASS (parent_class)->flip (item, context, flip_type, axis, - clip_result); -} - -static void -gimp_channel_rotate (GimpItem *item, - GimpContext *context, - GimpRotationType rotate_type, - gdouble center_x, - gdouble center_y, - gboolean clip_result) -{ - /* don't default to clip_result == TRUE here */ - - GIMP_ITEM_CLASS (parent_class)->rotate (item, context, - rotate_type, center_x, center_y, - clip_result); -} - -static void -gimp_channel_transform (GimpItem *item, - GimpContext *context, - const GimpMatrix3 *matrix, - GimpTransformDirection direction, - GimpInterpolationType interpolation_type, - GimpTransformResize clip_result, - GimpProgress *progress) -{ - if (G_TYPE_FROM_INSTANCE (item) == GIMP_TYPE_CHANNEL) - clip_result = TRUE; - - GIMP_ITEM_CLASS (parent_class)->transform (item, context, matrix, direction, - interpolation_type, - clip_result, - progress); -} - static GimpTransformResize gimp_channel_get_clip (GimpItem *item, GimpTransformResize clip_result) diff --git a/app/core/gimpdrawable-transform.c b/app/core/gimpdrawable-transform.c index 60958a3444..386e60c31c 100644 --- a/app/core/gimpdrawable-transform.c +++ b/app/core/gimpdrawable-transform.c @@ -64,41 +64,6 @@ /* public functions */ -GimpTransformResize -gimp_drawable_transform_get_effective_clip (GimpDrawable *drawable, - GeglBuffer *orig_buffer, - GimpTransformResize clip_result) -{ - g_return_val_if_fail (GIMP_IS_DRAWABLE (drawable), clip_result); - g_return_val_if_fail (gimp_item_is_attached (GIMP_ITEM (drawable)), - clip_result); - g_return_val_if_fail (orig_buffer == NULL || GEGL_IS_BUFFER (orig_buffer), - clip_result); - - /* Always clip unfloated buffers since they must keep their size */ - if (GIMP_IS_CHANNEL (drawable)) - { - if (orig_buffer) - { - if (! babl_format_has_alpha (gegl_buffer_get_format (orig_buffer))) - clip_result = GIMP_TRANSFORM_RESIZE_CLIP; - } - else - { - GimpImage *image = gimp_item_get_image (GIMP_ITEM (drawable)); - GimpChannel *mask = gimp_image_get_mask (image); - - if (GIMP_CHANNEL (drawable) == mask || - gimp_channel_is_empty (mask)) - { - clip_result = GIMP_TRANSFORM_RESIZE_CLIP; - } - } - } - - return clip_result; -} - GeglBuffer * gimp_drawable_transform_buffer_affine (GimpDrawable *drawable, GimpContext *context, @@ -146,17 +111,6 @@ gimp_drawable_transform_buffer_affine (GimpDrawable *drawable, u2 = u1 + gegl_buffer_get_width (orig_buffer); v2 = v1 + gegl_buffer_get_height (orig_buffer); - /* Don't modify the clipping mode of layer masks here, so that, - * when transformed together with their layer, they match the - * layer's clipping mode. - */ - if (G_TYPE_FROM_INSTANCE (drawable) == GIMP_TYPE_CHANNEL) - { - clip_result = gimp_drawable_transform_get_effective_clip (drawable, - orig_buffer, - clip_result); - } - /* Find the bounding coordinates of target */ gimp_transform_resize_boundary (&m, clip_result, u1, v1, u2, v2, @@ -788,10 +742,6 @@ gimp_drawable_transform_affine (GimpDrawable *drawable, gint new_offset_y; GimpColorProfile *profile; - clip_result = gimp_drawable_transform_get_effective_clip (drawable, - orig_buffer, - clip_result); - /* also transform the mask if we are transforming an entire layer */ if (GIMP_IS_LAYER (drawable) && gimp_layer_get_mask (GIMP_LAYER (drawable)) && @@ -876,11 +826,6 @@ gimp_drawable_transform_flip (GimpDrawable *drawable, gint new_offset_y; GimpColorProfile *profile; - /* always clip unfloated buffers so they keep their size */ - if (GIMP_IS_CHANNEL (drawable) && - ! babl_format_has_alpha (gegl_buffer_get_format (orig_buffer))) - clip_result = TRUE; - /* also transform the mask if we are transforming an entire layer */ if (GIMP_IS_LAYER (drawable) && gimp_layer_get_mask (GIMP_LAYER (drawable)) && @@ -961,11 +906,6 @@ gimp_drawable_transform_rotate (GimpDrawable *drawable, gint new_offset_y; GimpColorProfile *profile; - /* always clip unfloated buffers so they keep their size */ - if (GIMP_IS_CHANNEL (drawable) && - ! babl_format_has_alpha (gegl_buffer_get_format (orig_buffer))) - clip_result = TRUE; - /* also transform the mask if we are transforming an entire layer */ if (GIMP_IS_LAYER (drawable) && gimp_layer_get_mask (GIMP_LAYER (drawable)) && diff --git a/app/core/gimpdrawable-transform.h b/app/core/gimpdrawable-transform.h index fec177b42d..8cdd53f8c1 100644 --- a/app/core/gimpdrawable-transform.h +++ b/app/core/gimpdrawable-transform.h @@ -19,10 +19,6 @@ #define __GIMP_DRAWABLE_TRANSFORM_H__ -GimpTransformResize gimp_drawable_transform_get_effective_clip (GimpDrawable *drawable, - GeglBuffer *orig_buffer, - GimpTransformResize clip_result); - GeglBuffer * gimp_drawable_transform_buffer_affine (GimpDrawable *drawable, GimpContext *context, GeglBuffer *orig_buffer, diff --git a/app/core/gimpdrawablefilter.c b/app/core/gimpdrawablefilter.c index 276f04877f..47ac516ac2 100644 --- a/app/core/gimpdrawablefilter.c +++ b/app/core/gimpdrawablefilter.c @@ -505,13 +505,9 @@ static void gimp_drawable_filter_sync_clip (GimpDrawableFilter *filter, gboolean sync_region) { - gboolean clip = filter->clip; + gboolean clip; - if (! clip) - { - if (! GIMP_IS_LAYER (filter->drawable)) - clip = TRUE; - } + clip = gimp_item_get_clip (GIMP_ITEM (filter->drawable), filter->clip); if (! clip) { diff --git a/app/core/gimpimage-item-list.c b/app/core/gimpimage-item-list.c index a8a8714042..4efd8a1e73 100644 --- a/app/core/gimpimage-item-list.c +++ b/app/core/gimpimage-item-list.c @@ -161,8 +161,13 @@ gimp_image_item_list_flip (GimpImage *image, } for (l = list; l; l = g_list_next (l)) - gimp_item_flip (GIMP_ITEM (l->data), context, - flip_type, axis, clip_result); + { + GimpItem *item = l->data; + + gimp_item_flip (item, context, + flip_type, axis, + gimp_item_get_clip (item, clip_result)); + } if (list->next) { @@ -200,8 +205,13 @@ gimp_image_item_list_rotate (GimpImage *image, } for (l = list; l; l = g_list_next (l)) - gimp_item_rotate (GIMP_ITEM (l->data), context, - rotate_type, center_x, center_y, clip_result); + { + GimpItem *item = l->data; + + gimp_item_rotate (item, context, + rotate_type, center_x, center_y, + gimp_item_get_clip (item, clip_result)); + } if (list->next) { @@ -251,13 +261,16 @@ gimp_image_item_list_transform (GimpImage *image, for (l = list; l; l = g_list_next (l)) { + GimpItem *item = l->data; + if (queue) gimp_object_queue_pop (queue); - gimp_item_transform (GIMP_ITEM (l->data), context, + gimp_item_transform (item, context, matrix, direction, interpolation_type, - clip_result, progress); + gimp_item_get_clip (item, clip_result), + progress); } if (list->next) diff --git a/app/core/gimpitem-linked.c b/app/core/gimpitem-linked.c index e1ff330cc7..9c876e3829 100644 --- a/app/core/gimpitem-linked.c +++ b/app/core/gimpitem-linked.c @@ -134,7 +134,6 @@ gimp_item_linked_rotate (GimpItem *item, { GimpImage *image; GList *items; - GList *channels; g_return_if_fail (GIMP_IS_ITEM (item)); g_return_if_fail (GIMP_IS_CONTEXT (context)); @@ -144,30 +143,14 @@ gimp_item_linked_rotate (GimpItem *item, image = gimp_item_get_image (item); items = gimp_image_item_list_get_list (image, - GIMP_ITEM_TYPE_LAYERS | - GIMP_ITEM_TYPE_VECTORS, + GIMP_ITEM_TYPE_ALL, GIMP_ITEM_SET_LINKED); items = gimp_image_item_list_filter (items); - channels = gimp_image_item_list_get_list (image, - GIMP_ITEM_TYPE_CHANNELS, - GIMP_ITEM_SET_LINKED); - channels = gimp_image_item_list_filter (channels); - - if (items && channels) - gimp_image_undo_group_start (image, GIMP_UNDO_GROUP_TRANSFORM, - C_("undo-type", "Rotate Items")); - gimp_image_item_list_rotate (image, items, context, rotate_type, center_x, center_y, clip_result); - gimp_image_item_list_rotate (image, channels, context, - rotate_type, center_x, center_y, TRUE); - - if (items && channels) - gimp_image_undo_group_end (image); g_list_free (items); - g_list_free (channels); } void diff --git a/app/pdb/item-transform-cmds.c b/app/pdb/item-transform-cmds.c index a4e103cf4d..ca1eb771f4 100644 --- a/app/pdb/item-transform-cmds.c +++ b/app/pdb/item-transform-cmds.c @@ -159,7 +159,8 @@ item_transform_flip_simple_invoker (GimpProcedure *procedure, { gimp_item_flip (item, context, flip_type, axis, - pdb_context->transform_resize); + gimp_item_get_clip ( + item, pdb_context->transform_resize)); } } } @@ -252,7 +253,8 @@ item_transform_flip_invoker (GimpProcedure *procedure, gimp_item_transform (item, context, &matrix, pdb_context->transform_direction, pdb_context->interpolation, - pdb_context->transform_resize, + gimp_item_get_clip ( + item, pdb_context->transform_resize), progress); } @@ -360,7 +362,8 @@ item_transform_perspective_invoker (GimpProcedure *procedure, gimp_item_transform (item, context, &matrix, pdb_context->transform_direction, pdb_context->interpolation, - pdb_context->transform_resize, + gimp_item_get_clip ( + item, pdb_context->transform_resize), progress); } @@ -450,7 +453,8 @@ item_transform_rotate_simple_invoker (GimpProcedure *procedure, gimp_item_rotate (item, context, rotate_type, center_x, center_y, - pdb_context->transform_resize); + gimp_item_get_clip ( + item, pdb_context->transform_resize)); } } } @@ -548,7 +552,8 @@ item_transform_rotate_invoker (GimpProcedure *procedure, gimp_item_transform (item, context, &matrix, pdb_context->transform_direction, pdb_context->interpolation, - pdb_context->transform_resize, + gimp_item_get_clip ( + item, pdb_context->transform_resize), progress); } @@ -648,7 +653,8 @@ item_transform_scale_invoker (GimpProcedure *procedure, gimp_item_transform (item, context, &matrix, pdb_context->transform_direction, pdb_context->interpolation, - pdb_context->transform_resize, + gimp_item_get_clip ( + item, pdb_context->transform_resize), progress); } @@ -743,7 +749,8 @@ item_transform_shear_invoker (GimpProcedure *procedure, gimp_item_transform (item, context, &matrix, pdb_context->transform_direction, pdb_context->interpolation, - pdb_context->transform_resize, + gimp_item_get_clip ( + item, pdb_context->transform_resize), progress); } @@ -849,7 +856,8 @@ item_transform_2d_invoker (GimpProcedure *procedure, gimp_item_transform (item, context, &matrix, pdb_context->transform_direction, pdb_context->interpolation, - pdb_context->transform_resize, + gimp_item_get_clip ( + item, pdb_context->transform_resize), progress); } @@ -963,7 +971,8 @@ item_transform_matrix_invoker (GimpProcedure *procedure, gimp_item_transform (item, context, &matrix, pdb_context->transform_direction, pdb_context->interpolation, - pdb_context->transform_resize, + gimp_item_get_clip ( + item, pdb_context->transform_resize), progress); } diff --git a/app/tools/gimpfiltertool.c b/app/tools/gimpfiltertool.c index d0dd38b2d3..0bf2991344 100644 --- a/app/tools/gimpfiltertool.c +++ b/app/tools/gimpfiltertool.c @@ -1147,7 +1147,7 @@ gimp_filter_tool_update_dialog (GimpFilterTool *filter_tool) { gtk_widget_set_visible ( filter_tool->clip_combo, - GIMP_IS_LAYER (tool->drawable) && + gimp_item_get_clip (GIMP_ITEM (tool->drawable), FALSE) == FALSE && ! gimp_gegl_node_is_point_operation (filter_tool->operation)); gtk_widget_hide (filter_tool->region_combo); diff --git a/app/tools/gimpfliptool.c b/app/tools/gimpfliptool.c index 49cc9a1247..24688d7a73 100644 --- a/app/tools/gimpfliptool.c +++ b/app/tools/gimpfliptool.c @@ -371,16 +371,9 @@ gimp_flip_tool_transform (GimpTransformTool *tr_tool, if (orig_buffer) { /* this happens when transforming a selection cut out of a - * normal drawable, or the selection + * normal drawable */ - /* always clip the selection and unfloated channels - * so they keep their size - */ - if (GIMP_IS_CHANNEL (active_item) && - ! babl_format_has_alpha (gegl_buffer_get_format (orig_buffer))) - clip_result = TRUE; - ret = gimp_drawable_transform_buffer_flip (GIMP_DRAWABLE (active_item), context, orig_buffer, @@ -396,11 +389,6 @@ gimp_flip_tool_transform (GimpTransformTool *tr_tool, { /* this happens for entire drawables, paths and layer groups */ - /* always clip layer masks so they keep their size - */ - if (GIMP_IS_CHANNEL (active_item)) - clip_result = TRUE; - if (gimp_item_get_linked (active_item)) { gimp_item_linked_flip (active_item, context, @@ -408,6 +396,8 @@ gimp_flip_tool_transform (GimpTransformTool *tr_tool, } else { + clip_result = gimp_item_get_clip (active_item, clip_result); + gimp_item_flip (active_item, context, flip_type, axis, clip_result); } diff --git a/app/tools/gimptransformtool.c b/app/tools/gimptransformtool.c index 8d9785c25d..6aaef2ee75 100644 --- a/app/tools/gimptransformtool.c +++ b/app/tools/gimptransformtool.c @@ -149,16 +149,9 @@ gimp_transform_tool_real_transform (GimpTransformTool *tr_tool, if (orig_buffer) { /* this happens when transforming a selection cut out of a - * normal drawable, or the selection + * normal drawable */ - /* always clip the selection and unfloated channels - * so they keep their size - */ - if (GIMP_IS_CHANNEL (active_item) && - ! babl_format_has_alpha (gegl_buffer_get_format (orig_buffer))) - clip = GIMP_TRANSFORM_RESIZE_CLIP; - ret = gimp_drawable_transform_buffer_affine (GIMP_DRAWABLE (active_item), context, orig_buffer, @@ -188,10 +181,7 @@ gimp_transform_tool_real_transform (GimpTransformTool *tr_tool, } else { - /* always clip layer masks so they keep their size - */ - if (GIMP_IS_CHANNEL (active_item)) - clip = GIMP_TRANSFORM_RESIZE_CLIP; + clip = gimp_item_get_clip (active_item, clip); gimp_item_transform (active_item, context, &tr_tool->transform, @@ -271,14 +261,13 @@ gimp_transform_tool_confirm (GimpTransformTool *tr_tool, orig_bounds.width = gimp_item_get_width (item); orig_bounds.height = gimp_item_get_height (item); + + clip = gimp_item_get_clip (item, clip); } else { orig_bounds = selection_bounds; } - - clip = gimp_drawable_transform_get_effective_clip ( - GIMP_DRAWABLE (item), NULL, clip); } else { @@ -286,7 +275,7 @@ gimp_transform_tool_confirm (GimpTransformTool *tr_tool, &orig_bounds.x, &orig_bounds.y, &orig_bounds.width, &orig_bounds.height); - clip = GIMP_TRANSFORM_RESIZE_ADJUST; + clip = gimp_item_get_clip (item, clip); } gimp_transform_resize_boundary (&transform, clip, @@ -692,9 +681,6 @@ gimp_transform_tool_transform (GimpTransformTool *tr_tool, break; case GIMP_TRANSFORM_TYPE_SELECTION: - orig_buffer = g_object_ref (gimp_drawable_get_buffer (GIMP_DRAWABLE (active_item))); - break; - case GIMP_TRANSFORM_TYPE_PATH: break; } @@ -729,17 +715,7 @@ gimp_transform_tool_transform (GimpTransformTool *tr_tool, } break; - case GIMP_TRANSFORM_TYPE_SELECTION: - if (new_buffer) - { - gimp_channel_push_undo (GIMP_CHANNEL (active_item), NULL); - - gimp_drawable_set_buffer (GIMP_DRAWABLE (active_item), - FALSE, NULL, new_buffer); - g_object_unref (new_buffer); - } - break; - + case GIMP_TRANSFORM_TYPE_SELECTION: case GIMP_TRANSFORM_TYPE_PATH: /* Nothing to be done */ break; diff --git a/pdb/groups/item_transform.pdb b/pdb/groups/item_transform.pdb index f5d93735a6..9cf3a28034 100644 --- a/pdb/groups/item_transform.pdb +++ b/pdb/groups/item_transform.pdb @@ -92,7 +92,8 @@ $assemble_matrix gimp_item_transform (item, context, &matrix, pdb_context->transform_direction, pdb_context->interpolation, - pdb_context->transform_resize, + gimp_item_get_clip ( + item, pdb_context->transform_resize), progress); } @@ -256,7 +257,8 @@ HELP { gimp_item_flip (item, context, flip_type, axis, - pdb_context->transform_resize); + gimp_item_get_clip ( + item, pdb_context->transform_resize)); } } } @@ -507,7 +509,8 @@ HELP gimp_item_rotate (item, context, rotate_type, center_x, center_y, - pdb_context->transform_resize); + gimp_item_get_clip ( + item, pdb_context->transform_resize)); } } }