[gimp/gimp-2-10] pdb: fix image-mask transforms



commit 75d3276aa7f762e02f45f49a1c16585b1b7b3c1a
Author: Ell <ell_se yahoo com>
Date:   Fri Aug 9 22:18:24 2019 +0300

    pdb: fix image-mask transforms
    
    In the various PDB transform functions, avoid erroneously creating
    a floating selection when transforming the image mask, and rather
    transform the mask normally.

 app/pdb/drawable-transform-cmds.c | 187 ++++++++++++++++++++++++--------------
 app/pdb/item-transform-cmds.c     |  63 +++++++++----
 app/pdb/transform-tools-cmds.c    |  72 +++++++++------
 pdb/groups/drawable_transform.pdb |  43 ++++++---
 pdb/groups/item_transform.pdb     |  21 +++--
 pdb/groups/transform_tools.pdb    |  72 +++++++++------
 6 files changed, 296 insertions(+), 162 deletions(-)
---
diff --git a/app/pdb/drawable-transform-cmds.c b/app/pdb/drawable-transform-cmds.c
index ea469a7c2a..60e0919406 100644
--- a/app/pdb/drawable-transform-cmds.c
+++ b/app/pdb/drawable-transform-cmds.c
@@ -80,11 +80,15 @@ drawable_transform_flip_simple_invoker (GimpProcedure         *procedure,
       if (success &&
           gimp_item_mask_intersect (GIMP_ITEM (drawable), &x, &y, &width, &height))
         {
+          GimpImage   *image = gimp_item_get_image (GIMP_ITEM (drawable));
+          GimpChannel *mask  = gimp_image_get_mask (image);
+
           gimp_transform_get_flip_axis (x, y, width, height,
                                         flip_type, auto_center, &axis);
 
-          if (! gimp_viewable_get_children (GIMP_VIEWABLE (drawable)) &&
-              ! gimp_channel_is_empty (gimp_image_get_mask (gimp_item_get_image (GIMP_ITEM (drawable)))))
+          if (drawable != GIMP_DRAWABLE (mask)                        &&
+              ! gimp_viewable_get_children (GIMP_VIEWABLE (drawable)) &&
+              ! gimp_channel_is_empty (mask))
             {
               if (! gimp_drawable_transform_flip (drawable, context,
                                                   flip_type, axis, clip_result))
@@ -151,8 +155,10 @@ drawable_transform_flip_invoker (GimpProcedure         *procedure,
       if (success &&
           gimp_item_mask_intersect (GIMP_ITEM (drawable), &x, &y, &width, &height))
         {
-          GimpMatrix3 matrix;
-          gint        off_x, off_y;
+          GimpImage   *image = gimp_item_get_image (GIMP_ITEM (drawable));
+          GimpChannel *mask  = gimp_image_get_mask (image);
+          GimpMatrix3  matrix;
+          gint         off_x, off_y;
 
           gimp_item_get_offset (GIMP_ITEM (drawable), &off_x, &off_y);
 
@@ -167,8 +173,9 @@ drawable_transform_flip_invoker (GimpProcedure         *procedure,
           if (progress)
             gimp_progress_start (progress, FALSE, _("Flipping"));
 
-          if (! gimp_viewable_get_children (GIMP_VIEWABLE (drawable)) &&
-              ! gimp_channel_is_empty (gimp_image_get_mask (gimp_item_get_image (GIMP_ITEM (drawable)))))
+          if (drawable != GIMP_DRAWABLE (mask)                        &&
+              ! gimp_viewable_get_children (GIMP_VIEWABLE (drawable)) &&
+              ! gimp_channel_is_empty (mask))
             {
               if (! gimp_drawable_transform_affine (drawable, context,
                                                     &matrix, transform_direction,
@@ -239,9 +246,11 @@ drawable_transform_flip_default_invoker (GimpProcedure         *procedure,
       if (success &&
           gimp_item_mask_intersect (GIMP_ITEM (drawable), &x, &y, &width, &height))
         {
-          GimpMatrix3           matrix;
-          GimpInterpolationType interpolation_type = GIMP_INTERPOLATION_NONE;
-          gint                  off_x, off_y;
+          GimpImage             *image = gimp_item_get_image (GIMP_ITEM (drawable));
+          GimpChannel           *mask  = gimp_image_get_mask (image);
+          GimpMatrix3            matrix;
+          GimpInterpolationType  interpolation_type = GIMP_INTERPOLATION_NONE;
+          gint                   off_x, off_y;
 
           gimp_item_get_offset (GIMP_ITEM (drawable), &off_x, &off_y);
 
@@ -259,8 +268,9 @@ drawable_transform_flip_default_invoker (GimpProcedure         *procedure,
           if (progress)
             gimp_progress_start (progress, FALSE, _("Flipping"));
 
-          if (! gimp_viewable_get_children (GIMP_VIEWABLE (drawable)) &&
-              ! gimp_channel_is_empty (gimp_image_get_mask (gimp_item_get_image (GIMP_ITEM (drawable)))))
+          if (drawable != GIMP_DRAWABLE (mask)                        &&
+              ! gimp_viewable_get_children (GIMP_VIEWABLE (drawable)) &&
+              ! gimp_channel_is_empty (mask))
             {
               if (! gimp_drawable_transform_affine (drawable, context,
                                                     &matrix, GIMP_TRANSFORM_FORWARD,
@@ -342,8 +352,10 @@ drawable_transform_perspective_invoker (GimpProcedure         *procedure,
       if (success &&
           gimp_item_mask_intersect (GIMP_ITEM (drawable), &x, &y, &width, &height))
         {
-          GimpMatrix3 matrix;
-          gint        off_x, off_y;
+          GimpImage   *image = gimp_item_get_image (GIMP_ITEM (drawable));
+          GimpChannel *mask  = gimp_image_get_mask (image);
+          GimpMatrix3  matrix;
+          gint         off_x, off_y;
 
           gimp_item_get_offset (GIMP_ITEM (drawable), &off_x, &off_y);
 
@@ -360,8 +372,9 @@ drawable_transform_perspective_invoker (GimpProcedure         *procedure,
           if (progress)
             gimp_progress_start (progress, FALSE, _("Perspective"));
 
-          if (! gimp_viewable_get_children (GIMP_VIEWABLE (drawable)) &&
-              ! gimp_channel_is_empty (gimp_image_get_mask (gimp_item_get_image (GIMP_ITEM (drawable)))))
+          if (drawable != GIMP_DRAWABLE (mask)                        &&
+              ! gimp_viewable_get_children (GIMP_VIEWABLE (drawable)) &&
+              ! gimp_channel_is_empty (mask))
             {
               if (! gimp_drawable_transform_affine (drawable, context,
                                                     &matrix, transform_direction,
@@ -440,9 +453,11 @@ drawable_transform_perspective_default_invoker (GimpProcedure         *procedure
       if (success &&
           gimp_item_mask_intersect (GIMP_ITEM (drawable), &x, &y, &width, &height))
         {
-          GimpMatrix3           matrix;
-          GimpInterpolationType interpolation_type = GIMP_INTERPOLATION_NONE;
-          gint                  off_x, off_y;
+          GimpImage             *image = gimp_item_get_image (GIMP_ITEM (drawable));
+          GimpChannel           *mask  = gimp_image_get_mask (image);
+          GimpMatrix3            matrix;
+          GimpInterpolationType  interpolation_type = GIMP_INTERPOLATION_NONE;
+          gint                   off_x, off_y;
 
           gimp_item_get_offset (GIMP_ITEM (drawable), &off_x, &off_y);
 
@@ -462,8 +477,9 @@ drawable_transform_perspective_default_invoker (GimpProcedure         *procedure
           if (progress)
             gimp_progress_start (progress, FALSE, _("Perspective"));
 
-          if (! gimp_viewable_get_children (GIMP_VIEWABLE (drawable)) &&
-              ! gimp_channel_is_empty (gimp_image_get_mask (gimp_item_get_image (GIMP_ITEM (drawable)))))
+          if (drawable != GIMP_DRAWABLE (mask)                        &&
+              ! gimp_viewable_get_children (GIMP_VIEWABLE (drawable)) &&
+              ! gimp_channel_is_empty (mask))
             {
               if (! gimp_drawable_transform_affine (drawable, context,
                                                     &matrix, GIMP_TRANSFORM_FORWARD,
@@ -532,14 +548,17 @@ drawable_transform_rotate_simple_invoker (GimpProcedure         *procedure,
       if (success &&
           gimp_item_mask_intersect (GIMP_ITEM (drawable), &x, &y, &width, &height))
         {
-          gdouble cx = center_x;
-          gdouble cy = center_y;
+          GimpImage   *image = gimp_item_get_image (GIMP_ITEM (drawable));
+          GimpChannel *mask  = gimp_image_get_mask (image);
+          gdouble      cx    = center_x;
+          gdouble      cy    = center_y;
 
           gimp_transform_get_rotate_center (x, y, width, height,
                                             auto_center, &cx, &cy);
 
-          if (! gimp_viewable_get_children (GIMP_VIEWABLE (drawable)) &&
-              ! gimp_channel_is_empty (gimp_image_get_mask (gimp_item_get_image (GIMP_ITEM (drawable)))))
+          if (drawable != GIMP_DRAWABLE (mask)                        &&
+              ! gimp_viewable_get_children (GIMP_VIEWABLE (drawable)) &&
+              ! gimp_channel_is_empty (mask))
             {
               if (! gimp_drawable_transform_rotate (drawable, context,
                                                     rotate_type, cx, cy,
@@ -608,8 +627,10 @@ drawable_transform_rotate_invoker (GimpProcedure         *procedure,
       if (success &&
           gimp_item_mask_intersect (GIMP_ITEM (drawable), &x, &y, &width, &height))
         {
-          GimpMatrix3 matrix;
-          gint        off_x, off_y;
+          GimpImage   *image = gimp_item_get_image (GIMP_ITEM (drawable));
+          GimpChannel *mask  = gimp_image_get_mask (image);
+          GimpMatrix3  matrix;
+          gint         off_x, off_y;
 
           gimp_item_get_offset (GIMP_ITEM (drawable), &off_x, &off_y);
 
@@ -628,8 +649,9 @@ drawable_transform_rotate_invoker (GimpProcedure         *procedure,
           if (progress)
             gimp_progress_start (progress, FALSE, _("Rotating"));
 
-          if (! gimp_viewable_get_children (GIMP_VIEWABLE (drawable)) &&
-              ! gimp_channel_is_empty (gimp_image_get_mask (gimp_item_get_image (GIMP_ITEM (drawable)))))
+          if (drawable != GIMP_DRAWABLE (mask)                        &&
+              ! gimp_viewable_get_children (GIMP_VIEWABLE (drawable)) &&
+              ! gimp_channel_is_empty (mask))
             {
               if (! gimp_drawable_transform_affine (drawable, context,
                                                     &matrix, transform_direction,
@@ -700,9 +722,11 @@ drawable_transform_rotate_default_invoker (GimpProcedure         *procedure,
       if (success &&
           gimp_item_mask_intersect (GIMP_ITEM (drawable), &x, &y, &width, &height))
         {
-          GimpMatrix3           matrix;
-          GimpInterpolationType interpolation_type = GIMP_INTERPOLATION_NONE;
-          gint                  off_x, off_y;
+          GimpImage             *image = gimp_item_get_image (GIMP_ITEM (drawable));
+          GimpChannel           *mask  = gimp_image_get_mask (image);
+          GimpMatrix3            matrix;
+          GimpInterpolationType  interpolation_type = GIMP_INTERPOLATION_NONE;
+          gint                   off_x, off_y;
 
           gimp_item_get_offset (GIMP_ITEM (drawable), &off_x, &off_y);
 
@@ -724,8 +748,9 @@ drawable_transform_rotate_default_invoker (GimpProcedure         *procedure,
           if (progress)
             gimp_progress_start (progress, FALSE, _("Rotating"));
 
-          if (! gimp_viewable_get_children (GIMP_VIEWABLE (drawable)) &&
-              ! gimp_channel_is_empty (gimp_image_get_mask (gimp_item_get_image (GIMP_ITEM (drawable)))))
+          if (drawable != GIMP_DRAWABLE (mask)                        &&
+              ! gimp_viewable_get_children (GIMP_VIEWABLE (drawable)) &&
+              ! gimp_channel_is_empty (mask))
             {
               if (! gimp_drawable_transform_affine (drawable, context,
                                                     &matrix, GIMP_TRANSFORM_FORWARD,
@@ -798,8 +823,10 @@ drawable_transform_scale_invoker (GimpProcedure         *procedure,
       if (success &&
           gimp_item_mask_intersect (GIMP_ITEM (drawable), &x, &y, &width, &height))
         {
-          GimpMatrix3 matrix;
-          gint        off_x, off_y;
+          GimpImage   *image = gimp_item_get_image (GIMP_ITEM (drawable));
+          GimpChannel *mask  = gimp_image_get_mask (image);
+          GimpMatrix3  matrix;
+          gint         off_x, off_y;
 
           gimp_item_get_offset (GIMP_ITEM (drawable), &off_x, &off_y);
 
@@ -815,8 +842,9 @@ drawable_transform_scale_invoker (GimpProcedure         *procedure,
           if (progress)
             gimp_progress_start (progress, FALSE, _("Scaling"));
 
-          if (! gimp_viewable_get_children (GIMP_VIEWABLE (drawable)) &&
-              ! gimp_channel_is_empty (gimp_image_get_mask (gimp_item_get_image (GIMP_ITEM (drawable)))))
+          if (drawable != GIMP_DRAWABLE (mask)                        &&
+              ! gimp_viewable_get_children (GIMP_VIEWABLE (drawable)) &&
+              ! gimp_channel_is_empty (mask))
             {
               if (! gimp_drawable_transform_affine (drawable, context,
                                                     &matrix, transform_direction,
@@ -887,9 +915,11 @@ drawable_transform_scale_default_invoker (GimpProcedure         *procedure,
       if (success &&
           gimp_item_mask_intersect (GIMP_ITEM (drawable), &x, &y, &width, &height))
         {
-          GimpMatrix3           matrix;
-          GimpInterpolationType interpolation_type = GIMP_INTERPOLATION_NONE;
-          gint                  off_x, off_y;
+          GimpImage             *image = gimp_item_get_image (GIMP_ITEM (drawable));
+          GimpChannel           *mask  = gimp_image_get_mask (image);
+          GimpMatrix3            matrix;
+          GimpInterpolationType  interpolation_type = GIMP_INTERPOLATION_NONE;
+          gint                   off_x, off_y;
 
           gimp_item_get_offset (GIMP_ITEM (drawable), &off_x, &off_y);
 
@@ -908,8 +938,9 @@ drawable_transform_scale_default_invoker (GimpProcedure         *procedure,
           if (progress)
             gimp_progress_start (progress, FALSE, _("Scaling"));
 
-          if (! gimp_viewable_get_children (GIMP_VIEWABLE (drawable)) &&
-              ! gimp_channel_is_empty (gimp_image_get_mask (gimp_item_get_image (GIMP_ITEM (drawable)))))
+          if (drawable != GIMP_DRAWABLE (mask)                        &&
+              ! gimp_viewable_get_children (GIMP_VIEWABLE (drawable)) &&
+              ! gimp_channel_is_empty (mask))
             {
               if (! gimp_drawable_transform_affine (drawable, context,
                                                     &matrix, GIMP_TRANSFORM_FORWARD,
@@ -979,8 +1010,10 @@ drawable_transform_shear_invoker (GimpProcedure         *procedure,
       if (success &&
           gimp_item_mask_intersect (GIMP_ITEM (drawable), &x, &y, &width, &height))
         {
-          GimpMatrix3 matrix;
-          gint        off_x, off_y;
+          GimpImage   *image = gimp_item_get_image (GIMP_ITEM (drawable));
+          GimpChannel *mask  = gimp_image_get_mask (image);
+          GimpMatrix3  matrix;
+          gint         off_x, off_y;
 
           gimp_item_get_offset (GIMP_ITEM (drawable), &off_x, &off_y);
 
@@ -996,8 +1029,9 @@ drawable_transform_shear_invoker (GimpProcedure         *procedure,
           if (progress)
             gimp_progress_start (progress, FALSE, _("Shearing"));
 
-          if (! gimp_viewable_get_children (GIMP_VIEWABLE (drawable)) &&
-              ! gimp_channel_is_empty (gimp_image_get_mask (gimp_item_get_image (GIMP_ITEM (drawable)))))
+          if (drawable != GIMP_DRAWABLE (mask)                        &&
+              ! gimp_viewable_get_children (GIMP_VIEWABLE (drawable)) &&
+              ! gimp_channel_is_empty (mask))
             {
               if (! gimp_drawable_transform_affine (drawable, context,
                                                     &matrix, transform_direction,
@@ -1064,9 +1098,11 @@ drawable_transform_shear_default_invoker (GimpProcedure         *procedure,
       if (success &&
           gimp_item_mask_intersect (GIMP_ITEM (drawable), &x, &y, &width, &height))
         {
-          GimpMatrix3           matrix;
-          GimpInterpolationType interpolation_type = GIMP_INTERPOLATION_NONE;
-          gint                  off_x, off_y;
+          GimpImage             *image = gimp_item_get_image (GIMP_ITEM (drawable));
+          GimpChannel           *mask  = gimp_image_get_mask (image);
+          GimpMatrix3            matrix;
+          GimpInterpolationType  interpolation_type = GIMP_INTERPOLATION_NONE;
+          gint                   off_x, off_y;
 
           gimp_item_get_offset (GIMP_ITEM (drawable), &off_x, &off_y);
 
@@ -1085,8 +1121,9 @@ drawable_transform_shear_default_invoker (GimpProcedure         *procedure,
           if (progress)
             gimp_progress_start (progress, FALSE, _("Shearing"));
 
-          if (! gimp_viewable_get_children (GIMP_VIEWABLE (drawable)) &&
-              ! gimp_channel_is_empty (gimp_image_get_mask (gimp_item_get_image (GIMP_ITEM (drawable)))))
+          if (drawable != GIMP_DRAWABLE (mask)                        &&
+              ! gimp_viewable_get_children (GIMP_VIEWABLE (drawable)) &&
+              ! gimp_channel_is_empty (mask))
             {
               if (! gimp_drawable_transform_affine (drawable, context,
                                                     &matrix, GIMP_TRANSFORM_FORWARD,
@@ -1166,8 +1203,10 @@ drawable_transform_2d_invoker (GimpProcedure         *procedure,
       if (success &&
           gimp_item_mask_intersect (GIMP_ITEM (drawable), &x, &y, &width, &height))
         {
-          GimpMatrix3 matrix;
-          gint        off_x, off_y;
+          GimpImage   *image = gimp_item_get_image (GIMP_ITEM (drawable));
+          GimpChannel *mask  = gimp_image_get_mask (image);
+          GimpMatrix3  matrix;
+          gint         off_x, off_y;
 
           gimp_item_get_offset (GIMP_ITEM (drawable), &off_x, &off_y);
 
@@ -1184,8 +1223,9 @@ drawable_transform_2d_invoker (GimpProcedure         *procedure,
           if (progress)
             gimp_progress_start (progress, FALSE, _("2D Transform"));
 
-          if (! gimp_viewable_get_children (GIMP_VIEWABLE (drawable)) &&
-              ! gimp_channel_is_empty (gimp_image_get_mask (gimp_item_get_image (GIMP_ITEM (drawable)))))
+          if (drawable != GIMP_DRAWABLE (mask)                        &&
+              ! gimp_viewable_get_children (GIMP_VIEWABLE (drawable)) &&
+              ! gimp_channel_is_empty (mask))
             {
               if (! gimp_drawable_transform_affine (drawable, context,
                                                     &matrix, transform_direction,
@@ -1262,9 +1302,11 @@ drawable_transform_2d_default_invoker (GimpProcedure         *procedure,
       if (success &&
           gimp_item_mask_intersect (GIMP_ITEM (drawable), &x, &y, &width, &height))
         {
-          GimpMatrix3           matrix;
-          GimpInterpolationType interpolation_type = GIMP_INTERPOLATION_NONE;
-          gint                  off_x, off_y;
+          GimpImage             *image = gimp_item_get_image (GIMP_ITEM (drawable));
+          GimpChannel           *mask  = gimp_image_get_mask (image);
+          GimpMatrix3            matrix;
+          GimpInterpolationType  interpolation_type = GIMP_INTERPOLATION_NONE;
+          gint                   off_x, off_y;
 
           gimp_item_get_offset (GIMP_ITEM (drawable), &off_x, &off_y);
 
@@ -1284,8 +1326,9 @@ drawable_transform_2d_default_invoker (GimpProcedure         *procedure,
           if (progress)
             gimp_progress_start (progress, FALSE, _("2D Transforming"));
 
-          if (! gimp_viewable_get_children (GIMP_VIEWABLE (drawable)) &&
-              ! gimp_channel_is_empty (gimp_image_get_mask (gimp_item_get_image (GIMP_ITEM (drawable)))))
+          if (drawable != GIMP_DRAWABLE (mask)                        &&
+              ! gimp_viewable_get_children (GIMP_VIEWABLE (drawable)) &&
+              ! gimp_channel_is_empty (mask))
             {
               if (! gimp_drawable_transform_affine (drawable, context,
                                                     &matrix, GIMP_TRANSFORM_FORWARD,
@@ -1369,8 +1412,10 @@ drawable_transform_matrix_invoker (GimpProcedure         *procedure,
       if (success &&
           gimp_item_mask_intersect (GIMP_ITEM (drawable), &x, &y, &width, &height))
         {
-          GimpMatrix3 matrix;
-          gint        off_x, off_y;
+          GimpImage   *image = gimp_item_get_image (GIMP_ITEM (drawable));
+          GimpChannel *mask  = gimp_image_get_mask (image);
+          GimpMatrix3  matrix;
+          gint         off_x, off_y;
 
           gimp_item_get_offset (GIMP_ITEM (drawable), &off_x, &off_y);
 
@@ -1391,8 +1436,9 @@ drawable_transform_matrix_invoker (GimpProcedure         *procedure,
           if (progress)
             gimp_progress_start (progress, FALSE, _("2D Transforming"));
 
-          if (! gimp_viewable_get_children (GIMP_VIEWABLE (drawable)) &&
-              ! gimp_channel_is_empty (gimp_image_get_mask (gimp_item_get_image (GIMP_ITEM (drawable)))))
+          if (drawable != GIMP_DRAWABLE (mask)                        &&
+              ! gimp_viewable_get_children (GIMP_VIEWABLE (drawable)) &&
+              ! gimp_channel_is_empty (mask))
             {
               if (! gimp_drawable_transform_affine (drawable, context,
                                                     &matrix, transform_direction,
@@ -1473,9 +1519,11 @@ drawable_transform_matrix_default_invoker (GimpProcedure         *procedure,
       if (success &&
           gimp_item_mask_intersect (GIMP_ITEM (drawable), &x, &y, &width, &height))
         {
-          GimpMatrix3           matrix;
-          GimpInterpolationType interpolation_type = GIMP_INTERPOLATION_NONE;
-          gint                  off_x, off_y;
+          GimpImage             *image = gimp_item_get_image (GIMP_ITEM (drawable));
+          GimpChannel           *mask  = gimp_image_get_mask (image);
+          GimpMatrix3            matrix;
+          GimpInterpolationType  interpolation_type = GIMP_INTERPOLATION_NONE;
+          gint                   off_x, off_y;
 
           gimp_item_get_offset (GIMP_ITEM (drawable), &off_x, &off_y);
 
@@ -1499,8 +1547,9 @@ drawable_transform_matrix_default_invoker (GimpProcedure         *procedure,
           if (progress)
             gimp_progress_start (progress, FALSE, _("2D Transforming"));
 
-          if (! gimp_viewable_get_children (GIMP_VIEWABLE (drawable)) &&
-              ! gimp_channel_is_empty (gimp_image_get_mask (gimp_item_get_image (GIMP_ITEM (drawable)))))
+          if (drawable != GIMP_DRAWABLE (mask)                        &&
+              ! gimp_viewable_get_children (GIMP_VIEWABLE (drawable)) &&
+              ! gimp_channel_is_empty (mask))
             {
               if (! gimp_drawable_transform_affine (drawable, context,
                                                     &matrix, GIMP_TRANSFORM_FORWARD,
diff --git a/app/pdb/item-transform-cmds.c b/app/pdb/item-transform-cmds.c
index ca1eb771f4..bcf210e3fe 100644
--- a/app/pdb/item-transform-cmds.c
+++ b/app/pdb/item-transform-cmds.c
@@ -125,6 +125,8 @@ item_transform_flip_simple_invoker (GimpProcedure         *procedure,
           gimp_item_mask_intersect (item, &x, &y, &width, &height))
         {
           GimpPDBContext *pdb_context = GIMP_PDB_CONTEXT (context);
+          GimpImage      *image       = gimp_item_get_image (item);
+          GimpChannel    *mask        = gimp_image_get_mask (image);
           gint            off_x, off_y;
 
           gimp_item_get_offset (item, &off_x, &off_y);
@@ -134,9 +136,10 @@ item_transform_flip_simple_invoker (GimpProcedure         *procedure,
           gimp_transform_get_flip_axis (x, y, width, height,
                                         flip_type, auto_center, &axis);
 
-          if (GIMP_IS_DRAWABLE (item) &&
+          if (GIMP_IS_DRAWABLE (item)                             &&
+              item != GIMP_ITEM (mask)                            &&
               ! gimp_viewable_get_children (GIMP_VIEWABLE (item)) &&
-              ! gimp_channel_is_empty (gimp_image_get_mask (gimp_item_get_image (item))))
+              ! gimp_channel_is_empty (mask))
             {
               GimpDrawable *drawable;
 
@@ -208,6 +211,8 @@ item_transform_flip_invoker (GimpProcedure         *procedure,
           gimp_item_mask_intersect (item, &x, &y, &width, &height))
         {
           GimpPDBContext *pdb_context = GIMP_PDB_CONTEXT (context);
+          GimpImage      *image       = gimp_item_get_image (item);
+          GimpChannel    *mask        = gimp_image_get_mask (image);
           GimpMatrix3     matrix;
           gint            off_x, off_y;
 
@@ -222,9 +227,10 @@ item_transform_flip_invoker (GimpProcedure         *procedure,
           if (progress)
             gimp_progress_start (progress, FALSE, _("Flipping"));
 
-          if (GIMP_IS_DRAWABLE (item) &&
+          if (GIMP_IS_DRAWABLE (item)                             &&
+              item != GIMP_ITEM (mask)                            &&
               ! gimp_viewable_get_children (GIMP_VIEWABLE (item)) &&
-              ! gimp_channel_is_empty (gimp_image_get_mask (gimp_item_get_image (item))))
+              ! gimp_channel_is_empty (mask))
             {
               GimpDrawable *drawable;
 
@@ -314,6 +320,8 @@ item_transform_perspective_invoker (GimpProcedure         *procedure,
           gimp_item_mask_intersect (item, &x, &y, &width, &height))
         {
           GimpPDBContext *pdb_context = GIMP_PDB_CONTEXT (context);
+          GimpImage      *image       = gimp_item_get_image (item);
+          GimpChannel    *mask        = gimp_image_get_mask (image);
           GimpMatrix3     matrix;
           gint            off_x, off_y;
 
@@ -331,9 +339,10 @@ item_transform_perspective_invoker (GimpProcedure         *procedure,
           if (progress)
             gimp_progress_start (progress, FALSE, _("Perspective"));
 
-          if (GIMP_IS_DRAWABLE (item) &&
+          if (GIMP_IS_DRAWABLE (item)                             &&
+              item != GIMP_ITEM (mask)                            &&
               ! gimp_viewable_get_children (GIMP_VIEWABLE (item)) &&
-              ! gimp_channel_is_empty (gimp_image_get_mask (gimp_item_get_image (item))))
+              ! gimp_channel_is_empty (mask))
             {
               GimpDrawable *drawable;
 
@@ -415,6 +424,8 @@ item_transform_rotate_simple_invoker (GimpProcedure         *procedure,
           gimp_item_mask_intersect (item, &x, &y, &width, &height))
         {
           GimpPDBContext *pdb_context = GIMP_PDB_CONTEXT (context);
+          GimpImage      *image       = gimp_item_get_image (item);
+          GimpChannel    *mask        = gimp_image_get_mask (image);
           gint            off_x, off_y;
 
           gimp_item_get_offset (item, &off_x, &off_y);
@@ -424,9 +435,10 @@ item_transform_rotate_simple_invoker (GimpProcedure         *procedure,
           gimp_transform_get_rotate_center (x, y, width, height,
                                             auto_center, &center_x, &center_y);
 
-          if (GIMP_IS_DRAWABLE (item) &&
+          if (GIMP_IS_DRAWABLE (item)                             &&
+              item != GIMP_ITEM (mask)                            &&
               ! gimp_viewable_get_children (GIMP_VIEWABLE (item)) &&
-              ! gimp_channel_is_empty (gimp_image_get_mask (gimp_item_get_image (item))))
+              ! gimp_channel_is_empty (mask))
             {
               GimpDrawable *drawable;
 
@@ -502,6 +514,8 @@ item_transform_rotate_invoker (GimpProcedure         *procedure,
           gimp_item_mask_intersect (item, &x, &y, &width, &height))
         {
           GimpPDBContext *pdb_context = GIMP_PDB_CONTEXT (context);
+          GimpImage      *image       = gimp_item_get_image (item);
+          GimpChannel    *mask        = gimp_image_get_mask (image);
           GimpMatrix3     matrix;
           gint            off_x, off_y;
 
@@ -521,9 +535,10 @@ item_transform_rotate_invoker (GimpProcedure         *procedure,
           if (progress)
             gimp_progress_start (progress, FALSE, _("Rotating"));
 
-          if (GIMP_IS_DRAWABLE (item) &&
+          if (GIMP_IS_DRAWABLE (item)                             &&
+              item != GIMP_ITEM (mask)                            &&
               ! gimp_viewable_get_children (GIMP_VIEWABLE (item)) &&
-              ! gimp_channel_is_empty (gimp_image_get_mask (gimp_item_get_image (item))))
+              ! gimp_channel_is_empty (mask))
             {
               GimpDrawable *drawable;
 
@@ -606,6 +621,8 @@ item_transform_scale_invoker (GimpProcedure         *procedure,
           gimp_item_mask_intersect (item, &x, &y, &width, &height))
         {
           GimpPDBContext *pdb_context = GIMP_PDB_CONTEXT (context);
+          GimpImage      *image       = gimp_item_get_image (item);
+          GimpChannel    *mask        = gimp_image_get_mask (image);
           GimpMatrix3     matrix;
           gint            off_x, off_y;
 
@@ -622,9 +639,10 @@ item_transform_scale_invoker (GimpProcedure         *procedure,
           if (progress)
             gimp_progress_start (progress, FALSE, _("Scaling"));
 
-          if (GIMP_IS_DRAWABLE (item) &&
+          if (GIMP_IS_DRAWABLE (item)                             &&
+              item != GIMP_ITEM (mask)                            &&
               ! gimp_viewable_get_children (GIMP_VIEWABLE (item)) &&
-              ! gimp_channel_is_empty (gimp_image_get_mask (gimp_item_get_image (item))))
+              ! gimp_channel_is_empty (mask))
             {
               GimpDrawable *drawable;
 
@@ -702,6 +720,8 @@ item_transform_shear_invoker (GimpProcedure         *procedure,
           gimp_item_mask_intersect (item, &x, &y, &width, &height))
         {
           GimpPDBContext *pdb_context = GIMP_PDB_CONTEXT (context);
+          GimpImage      *image       = gimp_item_get_image (item);
+          GimpChannel    *mask        = gimp_image_get_mask (image);
           GimpMatrix3     matrix;
           gint            off_x, off_y;
 
@@ -718,9 +738,10 @@ item_transform_shear_invoker (GimpProcedure         *procedure,
           if (progress)
             gimp_progress_start (progress, FALSE, _("Shearing"));
 
-          if (GIMP_IS_DRAWABLE (item) &&
+          if (GIMP_IS_DRAWABLE (item)                             &&
+              item != GIMP_ITEM (mask)                            &&
               ! gimp_viewable_get_children (GIMP_VIEWABLE (item)) &&
-              ! gimp_channel_is_empty (gimp_image_get_mask (gimp_item_get_image (item))))
+              ! gimp_channel_is_empty (mask))
             {
               GimpDrawable *drawable;
 
@@ -808,6 +829,8 @@ item_transform_2d_invoker (GimpProcedure         *procedure,
           gimp_item_mask_intersect (item, &x, &y, &width, &height))
         {
           GimpPDBContext *pdb_context = GIMP_PDB_CONTEXT (context);
+          GimpImage      *image       = gimp_item_get_image (item);
+          GimpChannel    *mask        = gimp_image_get_mask (image);
           GimpMatrix3     matrix;
           gint            off_x, off_y;
 
@@ -825,9 +848,10 @@ item_transform_2d_invoker (GimpProcedure         *procedure,
           if (progress)
             gimp_progress_start (progress, FALSE, _("2D Transform"));
 
-          if (GIMP_IS_DRAWABLE (item) &&
+          if (GIMP_IS_DRAWABLE (item)                             &&
+              item != GIMP_ITEM (mask)                            &&
               ! gimp_viewable_get_children (GIMP_VIEWABLE (item)) &&
-              ! gimp_channel_is_empty (gimp_image_get_mask (gimp_item_get_image (item))))
+              ! gimp_channel_is_empty (mask))
             {
               GimpDrawable *drawable;
 
@@ -919,6 +943,8 @@ item_transform_matrix_invoker (GimpProcedure         *procedure,
           gimp_item_mask_intersect (item, &x, &y, &width, &height))
         {
           GimpPDBContext *pdb_context = GIMP_PDB_CONTEXT (context);
+          GimpImage      *image       = gimp_item_get_image (item);
+          GimpChannel    *mask        = gimp_image_get_mask (image);
           GimpMatrix3     matrix;
           gint            off_x, off_y;
 
@@ -940,9 +966,10 @@ item_transform_matrix_invoker (GimpProcedure         *procedure,
           if (progress)
             gimp_progress_start (progress, FALSE, _("2D Transforming"));
 
-          if (GIMP_IS_DRAWABLE (item) &&
+          if (GIMP_IS_DRAWABLE (item)                             &&
+              item != GIMP_ITEM (mask)                            &&
               ! gimp_viewable_get_children (GIMP_VIEWABLE (item)) &&
-              ! gimp_channel_is_empty (gimp_image_get_mask (gimp_item_get_image (item))))
+              ! gimp_channel_is_empty (mask))
             {
               GimpDrawable *drawable;
 
diff --git a/app/pdb/transform-tools-cmds.c b/app/pdb/transform-tools-cmds.c
index cefa0debc6..793b10a287 100644
--- a/app/pdb/transform-tools-cmds.c
+++ b/app/pdb/transform-tools-cmds.c
@@ -74,13 +74,16 @@ flip_invoker (GimpProcedure         *procedure,
       if (success &&
           gimp_item_mask_intersect (GIMP_ITEM (drawable), &x, &y, &width, &height))
         {
-          gdouble axis;
+          GimpImage   *image = gimp_item_get_image (GIMP_ITEM (drawable));
+          GimpChannel *mask  = gimp_image_get_mask (image);
+          gdouble      axis;
 
           gimp_transform_get_flip_axis (x, y, width, height,
                                         flip_type, TRUE, &axis);
 
-          if (! gimp_viewable_get_children (GIMP_VIEWABLE (drawable)) &&
-              ! gimp_channel_is_empty (gimp_image_get_mask (gimp_item_get_image (GIMP_ITEM (drawable)))))
+          if (drawable != GIMP_DRAWABLE (mask)                        &&
+              ! gimp_viewable_get_children (GIMP_VIEWABLE (drawable)) &&
+              ! gimp_channel_is_empty (mask))
             {
               if (! gimp_drawable_transform_flip (drawable, context,
                                                   flip_type, axis, FALSE))
@@ -149,9 +152,11 @@ perspective_invoker (GimpProcedure         *procedure,
       if (success &&
           gimp_item_mask_intersect (GIMP_ITEM (drawable), &x, &y, &width, &height))
         {
-          GimpMatrix3           matrix;
-          GimpInterpolationType interpolation_type = GIMP_INTERPOLATION_NONE;
-          gint                  off_x, off_y;
+          GimpImage             *image = gimp_item_get_image (GIMP_ITEM (drawable));
+          GimpChannel           *mask  = gimp_image_get_mask (image);
+          GimpMatrix3            matrix;
+          GimpInterpolationType  interpolation_type = GIMP_INTERPOLATION_NONE;
+          gint                   off_x, off_y;
 
           gimp_item_get_offset (GIMP_ITEM (drawable), &off_x, &off_y);
 
@@ -171,8 +176,9 @@ perspective_invoker (GimpProcedure         *procedure,
           if (progress)
             gimp_progress_start (progress, FALSE, _("Perspective"));
 
-          if (! gimp_viewable_get_children (GIMP_VIEWABLE (drawable)) &&
-              ! gimp_channel_is_empty (gimp_image_get_mask (gimp_item_get_image (GIMP_ITEM (drawable)))))
+          if (drawable != GIMP_DRAWABLE (mask)                        &&
+              ! gimp_viewable_get_children (GIMP_VIEWABLE (drawable)) &&
+              ! gimp_channel_is_empty (mask))
             {
               if (! gimp_drawable_transform_affine (drawable, context,
                                                     &matrix,
@@ -235,9 +241,11 @@ rotate_invoker (GimpProcedure         *procedure,
       if (success &&
           gimp_item_mask_intersect (GIMP_ITEM (drawable), &x, &y, &width, &height))
         {
-          GimpMatrix3           matrix;
-          GimpInterpolationType interpolation_type = GIMP_INTERPOLATION_NONE;
-          gint                  off_x, off_y;
+          GimpImage             *image = gimp_item_get_image (GIMP_ITEM (drawable));
+          GimpChannel           *mask  = gimp_image_get_mask (image);
+          GimpMatrix3            matrix;
+          GimpInterpolationType  interpolation_type = GIMP_INTERPOLATION_NONE;
+          gint                   off_x, off_y;
 
           gimp_item_get_offset (GIMP_ITEM (drawable), &off_x, &off_y);
 
@@ -256,8 +264,9 @@ rotate_invoker (GimpProcedure         *procedure,
           if (progress)
             gimp_progress_start (progress, FALSE, _("Rotating"));
 
-          if (! gimp_viewable_get_children (GIMP_VIEWABLE (drawable)) &&
-              ! gimp_channel_is_empty (gimp_image_get_mask (gimp_item_get_image (GIMP_ITEM (drawable)))))
+          if (drawable != GIMP_DRAWABLE (mask)                        &&
+              ! gimp_viewable_get_children (GIMP_VIEWABLE (drawable)) &&
+              ! gimp_channel_is_empty (mask))
             {
               if (! gimp_drawable_transform_affine (drawable, context,
                                                     &matrix,
@@ -327,9 +336,11 @@ scale_invoker (GimpProcedure         *procedure,
       if (success &&
           gimp_item_mask_intersect (GIMP_ITEM (drawable), &x, &y, &width, &height))
         {
-          GimpMatrix3           matrix;
-          GimpInterpolationType interpolation_type = GIMP_INTERPOLATION_NONE;
-          gint                  off_x, off_y;
+          GimpImage             *image = gimp_item_get_image (GIMP_ITEM (drawable));
+          GimpChannel           *mask  = gimp_image_get_mask (image);
+          GimpMatrix3            matrix;
+          GimpInterpolationType  interpolation_type = GIMP_INTERPOLATION_NONE;
+          gint                   off_x, off_y;
 
           gimp_item_get_offset (GIMP_ITEM (drawable), &off_x, &off_y);
 
@@ -348,8 +359,9 @@ scale_invoker (GimpProcedure         *procedure,
           if (progress)
             gimp_progress_start (progress, FALSE, _("Scaling"));
 
-          if (! gimp_viewable_get_children (GIMP_VIEWABLE (drawable)) &&
-              ! gimp_channel_is_empty (gimp_image_get_mask (gimp_item_get_image (GIMP_ITEM (drawable)))))
+          if (drawable != GIMP_DRAWABLE (mask)                        &&
+              ! gimp_viewable_get_children (GIMP_VIEWABLE (drawable)) &&
+              ! gimp_channel_is_empty (mask))
             {
               if (! gimp_drawable_transform_affine (drawable, context,
                                                     &matrix,
@@ -414,9 +426,11 @@ shear_invoker (GimpProcedure         *procedure,
       if (success &&
           gimp_item_mask_intersect (GIMP_ITEM (drawable), &x, &y, &width, &height))
         {
-          GimpMatrix3           matrix;
-          GimpInterpolationType interpolation_type = GIMP_INTERPOLATION_NONE;
-          gint                  off_x, off_y;
+          GimpImage             *image = gimp_item_get_image (GIMP_ITEM (drawable));
+          GimpChannel           *mask  = gimp_image_get_mask (image);
+          GimpMatrix3            matrix;
+          GimpInterpolationType  interpolation_type = GIMP_INTERPOLATION_NONE;
+          gint                   off_x, off_y;
 
           gimp_item_get_offset (GIMP_ITEM (drawable), &off_x, &off_y);
 
@@ -435,8 +449,9 @@ shear_invoker (GimpProcedure         *procedure,
           if (progress)
             gimp_progress_start (progress, FALSE, _("Shearing"));
 
-          if (! gimp_viewable_get_children (GIMP_VIEWABLE (drawable)) &&
-              ! gimp_channel_is_empty (gimp_image_get_mask (gimp_item_get_image (GIMP_ITEM (drawable)))))
+          if (drawable != GIMP_DRAWABLE (mask)                        &&
+              ! gimp_viewable_get_children (GIMP_VIEWABLE (drawable)) &&
+              ! gimp_channel_is_empty (mask))
             {
               if (! gimp_drawable_transform_affine (drawable, context,
                                                     &matrix,
@@ -511,8 +526,10 @@ transform_2d_invoker (GimpProcedure         *procedure,
       if (success &&
           gimp_item_mask_intersect (GIMP_ITEM (drawable), &x, &y, &width, &height))
         {
-          GimpMatrix3           matrix;
-          GimpInterpolationType interpolation_type = GIMP_INTERPOLATION_NONE;
+          GimpImage             *image = gimp_item_get_image (GIMP_ITEM (drawable));
+          GimpChannel           *mask  = gimp_image_get_mask (image);
+          GimpMatrix3            matrix;
+          GimpInterpolationType  interpolation_type = GIMP_INTERPOLATION_NONE;
 
           /* Assemble the transformation matrix */
           gimp_matrix3_identity  (&matrix);
@@ -527,8 +544,9 @@ transform_2d_invoker (GimpProcedure         *procedure,
           if (progress)
             gimp_progress_start (progress, FALSE, _("2D Transform"));
 
-          if (! gimp_viewable_get_children (GIMP_VIEWABLE (drawable)) &&
-              ! gimp_channel_is_empty (gimp_image_get_mask (gimp_item_get_image (GIMP_ITEM (drawable)))))
+          if (drawable != GIMP_DRAWABLE (mask)                        &&
+              ! gimp_viewable_get_children (GIMP_VIEWABLE (drawable)) &&
+              ! gimp_channel_is_empty (mask))
             {
               if (! gimp_drawable_transform_affine (drawable, context,
                                                     &matrix, GIMP_TRANSFORM_FORWARD,
diff --git a/pdb/groups/drawable_transform.pdb b/pdb/groups/drawable_transform.pdb
index 8d5707ab74..92953a8d3e 100644
--- a/pdb/groups/drawable_transform.pdb
+++ b/pdb/groups/drawable_transform.pdb
@@ -45,8 +45,10 @@ sub transform_invoke {
   if (success &&
       gimp_item_mask_intersect (GIMP_ITEM (drawable), &x, &y, &width, &height))
     {
-      GimpMatrix3 matrix;
-      gint        off_x, off_y;
+      GimpImage   *image = gimp_item_get_image (GIMP_ITEM (drawable));
+      GimpChannel *mask  = gimp_image_get_mask (image);
+      GimpMatrix3  matrix;
+      gint         off_x, off_y;
 
       gimp_item_get_offset (GIMP_ITEM (drawable), &off_x, &off_y);
 
@@ -59,8 +61,9 @@ $assemble_matrix
       if (progress)
         gimp_progress_start (progress, FALSE, _(\"$progress_text\"));
 
-      if (! gimp_viewable_get_children (GIMP_VIEWABLE (drawable)) &&
-          ! gimp_channel_is_empty (gimp_image_get_mask (gimp_item_get_image (GIMP_ITEM (drawable)))))
+      if (drawable != GIMP_DRAWABLE (mask)                        &&
+          ! gimp_viewable_get_children (GIMP_VIEWABLE (drawable)) &&
+          ! gimp_channel_is_empty (mask))
         {
           if (! gimp_drawable_transform_affine (drawable, context,
                                                 &matrix, transform_direction,
@@ -110,9 +113,11 @@ sub transform_default_invoke {
   if (success &&
       gimp_item_mask_intersect (GIMP_ITEM (drawable), &x, &y, &width, &height))
     {
-      GimpMatrix3           matrix;
-      GimpInterpolationType interpolation_type = GIMP_INTERPOLATION_NONE;
-      gint                  off_x, off_y;
+      GimpImage             *image = gimp_item_get_image (GIMP_ITEM (drawable));
+      GimpChannel           *mask  = gimp_image_get_mask (image);
+      GimpMatrix3            matrix;
+      GimpInterpolationType  interpolation_type = GIMP_INTERPOLATION_NONE;
+      gint                   off_x, off_y;
 
       gimp_item_get_offset (GIMP_ITEM (drawable), &off_x, &off_y);
 
@@ -128,8 +133,9 @@ $assemble_matrix
       if (progress)
         gimp_progress_start (progress, FALSE, _(\"$progress_text\"));
 
-      if (! gimp_viewable_get_children (GIMP_VIEWABLE (drawable)) &&
-          ! gimp_channel_is_empty (gimp_image_get_mask (gimp_item_get_image (GIMP_ITEM (drawable)))))
+      if (drawable != GIMP_DRAWABLE (mask)                        &&
+          ! gimp_viewable_get_children (GIMP_VIEWABLE (drawable)) &&
+          ! gimp_channel_is_empty (mask))
         {
           if (! gimp_drawable_transform_affine (drawable, context,
                                                 &matrix, GIMP_TRANSFORM_FORWARD,
@@ -195,11 +201,15 @@ sub drawable_transform_flip_simple {
   if (success &&
       gimp_item_mask_intersect (GIMP_ITEM (drawable), &x, &y, &width, &height))
     {
+      GimpImage   *image = gimp_item_get_image (GIMP_ITEM (drawable));
+      GimpChannel *mask  = gimp_image_get_mask (image);
+
       gimp_transform_get_flip_axis (x, y, width, height,
                                     flip_type, auto_center, &axis);
 
-      if (! gimp_viewable_get_children (GIMP_VIEWABLE (drawable)) &&
-          ! gimp_channel_is_empty (gimp_image_get_mask (gimp_item_get_image (GIMP_ITEM (drawable)))))
+      if (drawable != GIMP_DRAWABLE (mask)                        &&
+          ! gimp_viewable_get_children (GIMP_VIEWABLE (drawable)) &&
+          ! gimp_channel_is_empty (mask))
         {
           if (! gimp_drawable_transform_flip (drawable, context,
                                               flip_type, axis, clip_result))
@@ -441,14 +451,17 @@ sub drawable_transform_rotate_simple {
   if (success &&
       gimp_item_mask_intersect (GIMP_ITEM (drawable), &x, &y, &width, &height))
     {
-      gdouble cx = center_x;
-      gdouble cy = center_y;
+      GimpImage   *image = gimp_item_get_image (GIMP_ITEM (drawable));
+      GimpChannel *mask  = gimp_image_get_mask (image);
+      gdouble      cx    = center_x;
+      gdouble      cy    = center_y;
 
       gimp_transform_get_rotate_center (x, y, width, height,
                                         auto_center, &cx, &cy);
 
-      if (! gimp_viewable_get_children (GIMP_VIEWABLE (drawable)) &&
-          ! gimp_channel_is_empty (gimp_image_get_mask (gimp_item_get_image (GIMP_ITEM (drawable)))))
+      if (drawable != GIMP_DRAWABLE (mask)                        &&
+          ! gimp_viewable_get_children (GIMP_VIEWABLE (drawable)) &&
+          ! gimp_channel_is_empty (mask))
         {
           if (! gimp_drawable_transform_rotate (drawable, context,
                                                 rotate_type, cx, cy,
diff --git a/pdb/groups/item_transform.pdb b/pdb/groups/item_transform.pdb
index 9cf3a28034..81ee4175ef 100644
--- a/pdb/groups/item_transform.pdb
+++ b/pdb/groups/item_transform.pdb
@@ -48,6 +48,8 @@ $success_check
       gimp_item_mask_intersect (item, &x, &y, &width, &height))
     {
       GimpPDBContext *pdb_context = GIMP_PDB_CONTEXT (context);
+      GimpImage      *image       = gimp_item_get_image (item);
+      GimpChannel    *mask        = gimp_image_get_mask (image);
       GimpMatrix3     matrix;
       gint            off_x, off_y;
 
@@ -61,9 +63,10 @@ $assemble_matrix
       if (progress)
         gimp_progress_start (progress, FALSE, _(\"$progress_text\"));
 
-      if (GIMP_IS_DRAWABLE (item) &&
+      if (GIMP_IS_DRAWABLE (item)                             &&
+          item != GIMP_ITEM (mask)                            &&
           ! gimp_viewable_get_children (GIMP_VIEWABLE (item)) &&
-          ! gimp_channel_is_empty (gimp_image_get_mask (gimp_item_get_image (item))))
+          ! gimp_channel_is_empty (mask))
         {
           GimpDrawable *drawable;
 
@@ -223,6 +226,8 @@ HELP
       gimp_item_mask_intersect (item, &x, &y, &width, &height))
     {
       GimpPDBContext *pdb_context = GIMP_PDB_CONTEXT (context);
+      GimpImage      *image       = gimp_item_get_image (item);
+      GimpChannel    *mask        = gimp_image_get_mask (image);
       gint            off_x, off_y;
 
       gimp_item_get_offset (item, &off_x, &off_y);
@@ -232,9 +237,10 @@ HELP
       gimp_transform_get_flip_axis (x, y, width, height,
                                     flip_type, auto_center, &axis);
 
-      if (GIMP_IS_DRAWABLE (item) &&
+      if (GIMP_IS_DRAWABLE (item)                             &&
+          item != GIMP_ITEM (mask)                            &&
           ! gimp_viewable_get_children (GIMP_VIEWABLE (item)) &&
-          ! gimp_channel_is_empty (gimp_image_get_mask (gimp_item_get_image (item))))
+          ! gimp_channel_is_empty (mask))
         {
           GimpDrawable *drawable;
 
@@ -471,6 +477,8 @@ HELP
       gimp_item_mask_intersect (item, &x, &y, &width, &height))
     {
       GimpPDBContext *pdb_context = GIMP_PDB_CONTEXT (context);
+      GimpImage      *image       = gimp_item_get_image (item);
+      GimpChannel    *mask        = gimp_image_get_mask (image);
       gint            off_x, off_y;
 
       gimp_item_get_offset (item, &off_x, &off_y);
@@ -480,9 +488,10 @@ HELP
       gimp_transform_get_rotate_center (x, y, width, height,
                                         auto_center, &center_x, &center_y);
 
-      if (GIMP_IS_DRAWABLE (item) &&
+      if (GIMP_IS_DRAWABLE (item)                             &&
+          item != GIMP_ITEM (mask)                            &&
           ! gimp_viewable_get_children (GIMP_VIEWABLE (item)) &&
-          ! gimp_channel_is_empty (gimp_image_get_mask (gimp_item_get_image (item))))
+          ! gimp_channel_is_empty (mask))
         {
           GimpDrawable *drawable;
 
diff --git a/pdb/groups/transform_tools.pdb b/pdb/groups/transform_tools.pdb
index cdfa32e83a..9e7dd6251e 100644
--- a/pdb/groups/transform_tools.pdb
+++ b/pdb/groups/transform_tools.pdb
@@ -44,13 +44,16 @@ sub flip {
   if (success &&
       gimp_item_mask_intersect (GIMP_ITEM (drawable), &x, &y, &width, &height))
     {
-      gdouble axis;
+      GimpImage   *image = gimp_item_get_image (GIMP_ITEM (drawable));
+      GimpChannel *mask  = gimp_image_get_mask (image);
+      gdouble      axis;
 
       gimp_transform_get_flip_axis (x, y, width, height,
                                     flip_type, TRUE, &axis);
 
-      if (! gimp_viewable_get_children (GIMP_VIEWABLE (drawable)) &&
-          ! gimp_channel_is_empty (gimp_image_get_mask (gimp_item_get_image (GIMP_ITEM (drawable)))))
+      if (drawable != GIMP_DRAWABLE (mask)                        &&
+          ! gimp_viewable_get_children (GIMP_VIEWABLE (drawable)) &&
+          ! gimp_channel_is_empty (mask))
         {
           if (! gimp_drawable_transform_flip (drawable, context,
                                               flip_type, axis, FALSE))
@@ -121,9 +124,11 @@ sub perspective {
   if (success &&
       gimp_item_mask_intersect (GIMP_ITEM (drawable), &x, &y, &width, &height))
     {
-      GimpMatrix3           matrix;
-      GimpInterpolationType interpolation_type = GIMP_INTERPOLATION_NONE;
-      gint                  off_x, off_y;
+      GimpImage             *image = gimp_item_get_image (GIMP_ITEM (drawable));
+      GimpChannel           *mask  = gimp_image_get_mask (image);
+      GimpMatrix3            matrix;
+      GimpInterpolationType  interpolation_type = GIMP_INTERPOLATION_NONE;
+      gint                   off_x, off_y;
 
       gimp_item_get_offset (GIMP_ITEM (drawable), &off_x, &off_y);
 
@@ -143,8 +148,9 @@ sub perspective {
       if (progress)
         gimp_progress_start (progress, FALSE, _("Perspective"));
 
-      if (! gimp_viewable_get_children (GIMP_VIEWABLE (drawable)) &&
-          ! gimp_channel_is_empty (gimp_image_get_mask (gimp_item_get_image (GIMP_ITEM (drawable)))))
+      if (drawable != GIMP_DRAWABLE (mask)                        &&
+          ! gimp_viewable_get_children (GIMP_VIEWABLE (drawable)) &&
+          ! gimp_channel_is_empty (mask))
         {
           if (! gimp_drawable_transform_affine (drawable, context,
                                                 &matrix,
@@ -201,9 +207,11 @@ sub rotate {
   if (success &&
       gimp_item_mask_intersect (GIMP_ITEM (drawable), &x, &y, &width, &height))
     {
-      GimpMatrix3           matrix;
-      GimpInterpolationType interpolation_type = GIMP_INTERPOLATION_NONE;
-      gint                  off_x, off_y;
+      GimpImage             *image = gimp_item_get_image (GIMP_ITEM (drawable));
+      GimpChannel           *mask  = gimp_image_get_mask (image);
+      GimpMatrix3            matrix;
+      GimpInterpolationType  interpolation_type = GIMP_INTERPOLATION_NONE;
+      gint                   off_x, off_y;
 
       gimp_item_get_offset (GIMP_ITEM (drawable), &off_x, &off_y);
 
@@ -222,8 +230,9 @@ sub rotate {
       if (progress)
         gimp_progress_start (progress, FALSE, _("Rotating"));
 
-      if (! gimp_viewable_get_children (GIMP_VIEWABLE (drawable)) &&
-          ! gimp_channel_is_empty (gimp_image_get_mask (gimp_item_get_image (GIMP_ITEM (drawable)))))
+      if (drawable != GIMP_DRAWABLE (mask)                        &&
+          ! gimp_viewable_get_children (GIMP_VIEWABLE (drawable)) &&
+          ! gimp_channel_is_empty (mask))
         {
           if (! gimp_drawable_transform_affine (drawable, context,
                                                 &matrix,
@@ -291,9 +300,11 @@ sub scale {
   if (success &&
       gimp_item_mask_intersect (GIMP_ITEM (drawable), &x, &y, &width, &height))
     {
-      GimpMatrix3           matrix;
-      GimpInterpolationType interpolation_type = GIMP_INTERPOLATION_NONE;
-      gint                  off_x, off_y;
+      GimpImage             *image = gimp_item_get_image (GIMP_ITEM (drawable));
+      GimpChannel           *mask  = gimp_image_get_mask (image);
+      GimpMatrix3            matrix;
+      GimpInterpolationType  interpolation_type = GIMP_INTERPOLATION_NONE;
+      gint                   off_x, off_y;
 
       gimp_item_get_offset (GIMP_ITEM (drawable), &off_x, &off_y);
 
@@ -312,8 +323,9 @@ sub scale {
       if (progress)
         gimp_progress_start (progress, FALSE, _("Scaling"));
 
-      if (! gimp_viewable_get_children (GIMP_VIEWABLE (drawable)) &&
-          ! gimp_channel_is_empty (gimp_image_get_mask (gimp_item_get_image (GIMP_ITEM (drawable)))))
+      if (drawable != GIMP_DRAWABLE (mask)                        &&
+          ! gimp_viewable_get_children (GIMP_VIEWABLE (drawable)) &&
+          ! gimp_channel_is_empty (mask))
         {
           if (! gimp_drawable_transform_affine (drawable, context,
                                                 &matrix,
@@ -373,9 +385,11 @@ sub shear {
   if (success &&
       gimp_item_mask_intersect (GIMP_ITEM (drawable), &x, &y, &width, &height))
     {
-      GimpMatrix3           matrix;
-      GimpInterpolationType interpolation_type = GIMP_INTERPOLATION_NONE;
-      gint                  off_x, off_y;
+      GimpImage             *image = gimp_item_get_image (GIMP_ITEM (drawable));
+      GimpChannel           *mask  = gimp_image_get_mask (image);
+      GimpMatrix3            matrix;
+      GimpInterpolationType  interpolation_type = GIMP_INTERPOLATION_NONE;
+      gint                   off_x, off_y;
 
       gimp_item_get_offset (GIMP_ITEM (drawable), &off_x, &off_y);
 
@@ -394,8 +408,9 @@ sub shear {
       if (progress)
         gimp_progress_start (progress, FALSE, _("Shearing"));
 
-      if (! gimp_viewable_get_children (GIMP_VIEWABLE (drawable)) &&
-          ! gimp_channel_is_empty (gimp_image_get_mask (gimp_item_get_image (GIMP_ITEM (drawable)))))
+      if (drawable != GIMP_DRAWABLE (mask)                        &&
+          ! gimp_viewable_get_children (GIMP_VIEWABLE (drawable)) &&
+          ! gimp_channel_is_empty (mask))
         {
           if (! gimp_drawable_transform_affine (drawable, context,
                                                 &matrix,
@@ -464,8 +479,10 @@ sub transform_2d {
   if (success &&
       gimp_item_mask_intersect (GIMP_ITEM (drawable), &x, &y, &width, &height))
     {
-      GimpMatrix3           matrix;
-      GimpInterpolationType interpolation_type = GIMP_INTERPOLATION_NONE;
+      GimpImage             *image = gimp_item_get_image (GIMP_ITEM (drawable));
+      GimpChannel           *mask  = gimp_image_get_mask (image);
+      GimpMatrix3            matrix;
+      GimpInterpolationType  interpolation_type = GIMP_INTERPOLATION_NONE;
 
       /* Assemble the transformation matrix */
       gimp_matrix3_identity  (&matrix);
@@ -480,8 +497,9 @@ sub transform_2d {
       if (progress)
         gimp_progress_start (progress, FALSE, _("2D Transform"));
 
-      if (! gimp_viewable_get_children (GIMP_VIEWABLE (drawable)) &&
-          ! gimp_channel_is_empty (gimp_image_get_mask (gimp_item_get_image (GIMP_ITEM (drawable)))))
+      if (drawable != GIMP_DRAWABLE (mask)                        &&
+          ! gimp_viewable_get_children (GIMP_VIEWABLE (drawable)) &&
+          ! gimp_channel_is_empty (mask))
         {
           if (! gimp_drawable_transform_affine (drawable, context,
                                                 &matrix, GIMP_TRANSFORM_FORWARD,


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]