[gimp] app: add GimpDrawable::supports_alpha() vfunc



commit 5e1eba68e203266a17a1161133f956f3627450ce
Author: Ell <ell_se yahoo com>
Date:   Fri Jan 17 11:24:31 2020 +0200

    app: add GimpDrawable::supports_alpha() vfunc
    
    Add a new GimpDrawable::supports_alpha() virtual function, and a
    corresponding gimp_drawable_supports_alpha() function, which
    determine if the drawable supports an alpha channel.  The default
    implementation returns FALSE, and GimpLayer overrides it to return
    TRUE.

 app/core/gimpdrawable.c | 18 ++++++++++++++++++
 app/core/gimpdrawable.h |  3 +++
 app/core/gimplayer.c    |  8 ++++++++
 3 files changed, 29 insertions(+)
---
diff --git a/app/core/gimpdrawable.c b/app/core/gimpdrawable.c
index 6349a31b81..43620b052f 100644
--- a/app/core/gimpdrawable.c
+++ b/app/core/gimpdrawable.c
@@ -172,6 +172,9 @@ static void       gimp_drawable_real_update_all    (GimpDrawable      *drawable)
 static GimpComponentMask
                 gimp_drawable_real_get_active_mask (GimpDrawable      *drawable);
 
+static gboolean   gimp_drawable_real_supports_alpha
+                                                   (GimpDrawable     *drawable);
+
 static void       gimp_drawable_real_convert_type  (GimpDrawable      *drawable,
                                                     GimpImage         *dest_image,
                                                     const Babl        *new_format,
@@ -302,6 +305,7 @@ gimp_drawable_class_init (GimpDrawableClass *klass)
   klass->invalidate_boundary      = NULL;
   klass->get_active_components    = NULL;
   klass->get_active_mask          = gimp_drawable_real_get_active_mask;
+  klass->supports_alpha           = gimp_drawable_real_supports_alpha;
   klass->convert_type             = gimp_drawable_real_convert_type;
   klass->apply_buffer             = gimp_drawable_real_apply_buffer;
   klass->get_buffer               = gimp_drawable_real_get_buffer;
@@ -838,6 +842,12 @@ gimp_drawable_real_get_active_mask (GimpDrawable *drawable)
   return GIMP_COMPONENT_MASK_ALL;
 }
 
+static gboolean
+gimp_drawable_real_supports_alpha (GimpDrawable *drawable)
+{
+  return FALSE;
+}
+
 /* FIXME: this default impl is currently unused because no subclass
  * chains up. the goal is to handle the almost identical subclass code
  * here again.
@@ -1232,6 +1242,14 @@ gimp_drawable_get_active_mask (GimpDrawable *drawable)
   return mask;
 }
 
+gboolean
+gimp_drawable_supports_alpha (GimpDrawable *drawable)
+{
+  g_return_val_if_fail (GIMP_IS_DRAWABLE (drawable), FALSE);
+
+  return GIMP_DRAWABLE_GET_CLASS (drawable)->supports_alpha (drawable);
+}
+
 void
 gimp_drawable_convert_type (GimpDrawable      *drawable,
                             GimpImage         *dest_image,
diff --git a/app/core/gimpdrawable.h b/app/core/gimpdrawable.h
index b18f8dfc0f..eb8000241a 100644
--- a/app/core/gimpdrawable.h
+++ b/app/core/gimpdrawable.h
@@ -64,6 +64,7 @@ struct _GimpDrawableClass
   void          (* get_active_components) (GimpDrawable         *drawable,
                                            gboolean             *active);
   GimpComponentMask (* get_active_mask)   (GimpDrawable         *drawable);
+  gboolean      (* supports_alpha)        (GimpDrawable         *drawable);
   void          (* convert_type)          (GimpDrawable         *drawable,
                                            GimpImage            *dest_image,
                                            const Babl           *new_format,
@@ -136,6 +137,8 @@ void         gimp_drawable_get_active_components (GimpDrawable       *drawable,
                                                   gboolean           *active);
 GimpComponentMask gimp_drawable_get_active_mask  (GimpDrawable       *drawable);
 
+gboolean        gimp_drawable_supports_alpha     (GimpDrawable       *drawable);
+
 void            gimp_drawable_convert_type       (GimpDrawable       *drawable,
                                                   GimpImage          *dest_image,
                                                   GimpImageBaseType   new_base_type,
diff --git a/app/core/gimplayer.c b/app/core/gimplayer.c
index ab32fd4ddf..38bb4f6612 100644
--- a/app/core/gimplayer.c
+++ b/app/core/gimplayer.c
@@ -183,6 +183,7 @@ static gint64     gimp_layer_estimate_memsize   (GimpDrawable       *drawable,
                                                  GimpComponentType   component_type,
                                                  gint                width,
                                                  gint                height);
+static gboolean   gimp_layer_supports_alpha     (GimpDrawable       *drawable);
 static void       gimp_layer_convert_type       (GimpDrawable       *drawable,
                                                  GimpImage          *dest_image,
                                                  const Babl         *new_format,
@@ -447,6 +448,7 @@ gimp_layer_class_init (GimpLayerClass *klass)
 
   drawable_class->alpha_changed         = gimp_layer_alpha_changed;
   drawable_class->estimate_memsize      = gimp_layer_estimate_memsize;
+  drawable_class->supports_alpha        = gimp_layer_supports_alpha;
   drawable_class->convert_type          = gimp_layer_convert_type;
   drawable_class->invalidate_boundary   = gimp_layer_invalidate_boundary;
   drawable_class->get_active_components = gimp_layer_get_active_components;
@@ -1356,6 +1358,12 @@ gimp_layer_estimate_memsize (GimpDrawable      *drawable,
                                                                width, height);
 }
 
+static gboolean
+gimp_layer_supports_alpha (GimpDrawable *drawable)
+{
+  return TRUE;
+}
+
 static void
 gimp_layer_convert_type (GimpDrawable     *drawable,
                          GimpImage        *dest_image,


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