[gimp/gimp-2-10] app: set/clear component-mask alpha-bit of alpha-less drawables, to make mask uniform



commit 353951a44f888d6629eb8fb3a8bef8f6b6703bf2
Author: Ell <ell_se yahoo com>
Date:   Sat Feb 16 12:56:20 2019 -0500

    app: set/clear component-mask alpha-bit of alpha-less drawables, to make mask uniform
    
    In gimp_drawable_get_active_mask(), when the drawable doesn't have
    an alpha channel, set or clear the mask's alpha bit, according to
    the state of the other bits, so that it never gets in the way of a
    fully set/clear mask.  The value of the alpha bit doesn't matter
    when there's no alpha channel, however, having a uniform mask
    allows us to skip component masking altogether.
    
    Additionally, provide a default implementation for
    GimpDrawable::get_active_mask() which returns a full mask, and
    remove the equivalent implementation for GimpChannel.
    
    (cherry picked from commit 1b900bfa166c240d08002325d74c1a39518e8f6f)

 app/core/gimpchannel.c  | 10 ----------
 app/core/gimpdrawable.c | 34 ++++++++++++++++++++++++++++------
 2 files changed, 28 insertions(+), 16 deletions(-)
---
diff --git a/app/core/gimpchannel.c b/app/core/gimpchannel.c
index cef462ba7b..e3f37d8f43 100644
--- a/app/core/gimpchannel.c
+++ b/app/core/gimpchannel.c
@@ -159,8 +159,6 @@ static void       gimp_channel_convert_type  (GimpDrawable      *drawable,
 static void gimp_channel_invalidate_boundary   (GimpDrawable       *drawable);
 static void gimp_channel_get_active_components (GimpDrawable       *drawable,
                                                 gboolean           *active);
-static GimpComponentMask
-                  gimp_channel_get_active_mask (GimpDrawable      *drawable);
 
 static void      gimp_channel_set_buffer     (GimpDrawable        *drawable,
                                               gboolean             push_undo,
@@ -293,7 +291,6 @@ gimp_channel_class_init (GimpChannelClass *klass)
   drawable_class->convert_type          = gimp_channel_convert_type;
   drawable_class->invalidate_boundary   = gimp_channel_invalidate_boundary;
   drawable_class->get_active_components = gimp_channel_get_active_components;
-  drawable_class->get_active_mask       = gimp_channel_get_active_mask;
   drawable_class->set_buffer            = gimp_channel_set_buffer;
 
   klass->boundary       = gimp_channel_real_boundary;
@@ -1009,13 +1006,6 @@ gimp_channel_get_active_components (GimpDrawable *drawable,
   active[ALPHA_G] = FALSE;
 }
 
-static GimpComponentMask
-gimp_channel_get_active_mask (GimpDrawable *drawable)
-{
-  /*  Return all, because that skips the component mask op when painting  */
-  return GIMP_COMPONENT_MASK_ALL;
-}
-
 static void
 gimp_channel_set_buffer (GimpDrawable *drawable,
                          gboolean      push_undo,
diff --git a/app/core/gimpdrawable.c b/app/core/gimpdrawable.c
index aa6f4789fc..228adffe5b 100644
--- a/app/core/gimpdrawable.c
+++ b/app/core/gimpdrawable.c
@@ -167,6 +167,9 @@ static gint64  gimp_drawable_real_estimate_memsize (GimpDrawable      *drawable,
                                                     gint               width,
                                                     gint               height);
 
+static GimpComponentMask
+                gimp_drawable_real_get_active_mask (GimpDrawable      *drawable);
+
 static void       gimp_drawable_real_convert_type  (GimpDrawable      *drawable,
                                                     GimpImage         *dest_image,
                                                     const Babl        *new_format,
@@ -280,7 +283,7 @@ gimp_drawable_class_init (GimpDrawableClass *klass)
   klass->estimate_memsize         = gimp_drawable_real_estimate_memsize;
   klass->invalidate_boundary      = NULL;
   klass->get_active_components    = NULL;
-  klass->get_active_mask          = NULL;
+  klass->get_active_mask          = gimp_drawable_real_get_active_mask;
   klass->convert_type             = gimp_drawable_real_convert_type;
   klass->apply_buffer             = gimp_drawable_real_apply_buffer;
   klass->get_buffer               = gimp_drawable_real_get_buffer;
@@ -770,6 +773,13 @@ gimp_drawable_real_estimate_memsize (GimpDrawable      *drawable,
   return (gint64) babl_format_get_bytes_per_pixel (format) * width * height;
 }
 
+static GimpComponentMask
+gimp_drawable_real_get_active_mask (GimpDrawable *drawable)
+{
+  /*  Return all, because that skips the component mask op when painting  */
+  return GIMP_COMPONENT_MASK_ALL;
+}
+
 /* FIXME: this default impl is currently unused because no subclass
  * chains up. the goal is to handle the almost identical subclass code
  * here again.
@@ -1104,16 +1114,28 @@ gimp_drawable_get_active_components (GimpDrawable *drawable,
 GimpComponentMask
 gimp_drawable_get_active_mask (GimpDrawable *drawable)
 {
-  GimpDrawableClass *drawable_class;
+  GimpComponentMask mask;
 
   g_return_val_if_fail (GIMP_IS_DRAWABLE (drawable), 0);
 
-  drawable_class = GIMP_DRAWABLE_GET_CLASS (drawable);
+  mask = GIMP_DRAWABLE_GET_CLASS (drawable)->get_active_mask (drawable);
 
-  if (drawable_class->get_active_mask)
-    return drawable_class->get_active_mask (drawable);
+  /* if the drawable doesn't have an alpha channel, the value of the mask's
+   * alpha-bit doesn't matter, however, we'd like to have a fully-clear or
+   * fully-set mask whenever possible, since it allows us to skip component
+   * masking altogether.  we therefore set or clear the alpha bit, depending on
+   * the state of the other bits, so that it never gets in the way of a uniform
+   * mask.
+   */
+  if (! gimp_drawable_has_alpha (drawable))
+    {
+      if (mask & ~GIMP_COMPONENT_MASK_ALPHA)
+        mask |= GIMP_COMPONENT_MASK_ALPHA;
+      else
+        mask &= ~GIMP_COMPONENT_MASK_ALPHA;
+    }
 
-  return 0;
+  return mask;
 }
 
 void


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