[gimp] app: add gimp_layer_mode_get_included_region()



commit a67135658edc06e7058dd9c11330724ee41983dc
Author: Ell <ell_se yahoo com>
Date:   Thu May 11 15:46:59 2017 -0400

    app: add gimp_layer_mode_get_included_region()
    
    Takes a layer mode and a composite mode, and returns the region
    included in the composition.
    
    Use this function in GimpOperationLayerMode, instead of testing
    for specific composite modes directly.  Will also be used by
    the next commit.
    
    Indentation cleanup in gimp_layer_modes.h

 app/operations/layer-modes/gimp-layer-modes.c      |   26 +++++++++
 app/operations/layer-modes/gimp-layer-modes.h      |   56 ++++++++++---------
 .../layer-modes/gimpoperationlayermode.c           |   21 ++++----
 3 files changed, 66 insertions(+), 37 deletions(-)
---
diff --git a/app/operations/layer-modes/gimp-layer-modes.c b/app/operations/layer-modes/gimp-layer-modes.c
index 0ce18a2..2a34b19 100644
--- a/app/operations/layer-modes/gimp-layer-modes.c
+++ b/app/operations/layer-modes/gimp-layer-modes.c
@@ -1440,3 +1440,29 @@ gimp_layer_mode_get_format (GimpLayerMode        mode,
 
   g_return_val_if_reached (babl_format ("RGBA float"));
 }
+
+GimpLayerCompositeRegion
+gimp_layer_mode_get_included_region (GimpLayerMode          mode,
+                                     GimpLayerCompositeMode composite_mode)
+{
+  if (composite_mode == GIMP_LAYER_COMPOSITE_AUTO)
+    composite_mode = gimp_layer_mode_get_composite_mode (mode);
+
+  switch (composite_mode)
+    {
+    case GIMP_LAYER_COMPOSITE_SRC_OVER:
+      return GIMP_LAYER_COMPOSITE_REGION_UNION;
+
+    case GIMP_LAYER_COMPOSITE_SRC_ATOP:
+      return GIMP_LAYER_COMPOSITE_REGION_DESTINATION;
+
+    case GIMP_LAYER_COMPOSITE_DST_ATOP:
+      return GIMP_LAYER_COMPOSITE_REGION_SOURCE;
+
+    case GIMP_LAYER_COMPOSITE_SRC_IN:
+      return GIMP_LAYER_COMPOSITE_REGION_INTERSECTION;
+
+    default:
+      g_return_val_if_reached (GIMP_LAYER_COMPOSITE_REGION_INTERSECTION);
+    }
+}
diff --git a/app/operations/layer-modes/gimp-layer-modes.h b/app/operations/layer-modes/gimp-layer-modes.h
index 9b49fb6..3661a93 100644
--- a/app/operations/layer-modes/gimp-layer-modes.h
+++ b/app/operations/layer-modes/gimp-layer-modes.h
@@ -23,45 +23,47 @@
 #define __GIMP_LAYER_MODES_H__
 
 
-void                     gimp_layer_modes_init               (void);
+void                       gimp_layer_modes_init                      (void);
 
-gboolean                 gimp_layer_mode_is_legacy           (GimpLayerMode        mode);
+gboolean                   gimp_layer_mode_is_legacy                  (GimpLayerMode           mode);
 
-gboolean          gimp_layer_mode_is_blend_space_mutable     (GimpLayerMode        mode);
-gboolean          gimp_layer_mode_is_composite_space_mutable (GimpLayerMode        mode);
-gboolean          gimp_layer_mode_is_composite_mode_mutable  (GimpLayerMode        mode);
+gboolean                   gimp_layer_mode_is_blend_space_mutable     (GimpLayerMode           mode);
+gboolean                   gimp_layer_mode_is_composite_space_mutable (GimpLayerMode           mode);
+gboolean                   gimp_layer_mode_is_composite_mode_mutable  (GimpLayerMode           mode);
 
-gboolean                 gimp_layer_mode_is_subtractive      (GimpLayerMode        mode);
+gboolean                   gimp_layer_mode_is_subtractive             (GimpLayerMode           mode);
 
-GimpLayerColorSpace      gimp_layer_mode_get_blend_space     (GimpLayerMode        mode);
-GimpLayerColorSpace      gimp_layer_mode_get_composite_space (GimpLayerMode        mode);
-GimpLayerCompositeMode   gimp_layer_mode_get_composite_mode  (GimpLayerMode        mode);
-GimpLayerCompositeMode   gimp_layer_mode_get_paint_composite_mode
-                                                             (GimpLayerMode        mode);
+GimpLayerColorSpace        gimp_layer_mode_get_blend_space            (GimpLayerMode           mode);
+GimpLayerColorSpace        gimp_layer_mode_get_composite_space        (GimpLayerMode           mode);
+GimpLayerCompositeMode     gimp_layer_mode_get_composite_mode         (GimpLayerMode           mode);
+GimpLayerCompositeMode     gimp_layer_mode_get_paint_composite_mode   (GimpLayerMode           mode);
 
-const gchar            * gimp_layer_mode_get_operation       (GimpLayerMode        mode);
+const gchar              * gimp_layer_mode_get_operation              (GimpLayerMode           mode);
 
-GimpLayerModeFunc        gimp_layer_mode_get_function        (GimpLayerMode        mode);
+GimpLayerModeFunc          gimp_layer_mode_get_function               (GimpLayerMode           mode);
 
-GimpLayerModeContext     gimp_layer_mode_get_context         (GimpLayerMode        mode);
+GimpLayerModeContext       gimp_layer_mode_get_context                (GimpLayerMode           mode);
 
-GimpLayerMode          * gimp_layer_mode_get_context_array   (GimpLayerMode        mode,
-                                                              GimpLayerModeContext context,
-                                                              gint                *n_modes);
+GimpLayerMode            * gimp_layer_mode_get_context_array          (GimpLayerMode           mode,
+                                                                       GimpLayerModeContext    context,
+                                                                       gint                   *n_modes);
 
-GimpLayerModeGroup       gimp_layer_mode_get_group           (GimpLayerMode        mode);
+GimpLayerModeGroup         gimp_layer_mode_get_group                  (GimpLayerMode           mode);
 
-const GimpLayerMode    * gimp_layer_mode_get_group_array     (GimpLayerModeGroup   group,
-                                                              gint                *n_modes);
+const GimpLayerMode      * gimp_layer_mode_get_group_array            (GimpLayerModeGroup      group,
+                                                                       gint                   *n_modes);
 
-gboolean                 gimp_layer_mode_get_for_group       (GimpLayerMode        old_mode,
-                                                              GimpLayerModeGroup   new_group,
-                                                              GimpLayerMode       *new_mode);
+gboolean                   gimp_layer_mode_get_for_group              (GimpLayerMode           old_mode,
+                                                                       GimpLayerModeGroup      new_group,
+                                                                       GimpLayerMode          *new_mode);
 
-const Babl             * gimp_layer_mode_get_format          (GimpLayerMode        mode,
-                                                              GimpLayerColorSpace  composite_space,
-                                                              GimpLayerColorSpace  blend_space,
-                                                              const Babl          *preferred_format);
+const Babl               * gimp_layer_mode_get_format                 (GimpLayerMode           mode,
+                                                                       GimpLayerColorSpace     
composite_space,
+                                                                       GimpLayerColorSpace     blend_space,
+                                                                       const Babl             
*preferred_format);
+
+GimpLayerCompositeRegion   gimp_layer_mode_get_included_region        (GimpLayerMode           mode,
+                                                                       GimpLayerCompositeMode  
composite_mode);
 
 
 #endif /* __GIMP_LAYER_MODES_H__ */
diff --git a/app/operations/layer-modes/gimpoperationlayermode.c 
b/app/operations/layer-modes/gimpoperationlayermode.c
index 505b32f..83e7a31 100644
--- a/app/operations/layer-modes/gimpoperationlayermode.c
+++ b/app/operations/layer-modes/gimpoperationlayermode.c
@@ -375,11 +375,12 @@ gimp_operation_layer_mode_process (GeglOperation        *operation,
                                    const GeglRectangle  *result,
                                    gint                  level)
 {
-  GimpOperationLayerMode *point = GIMP_OPERATION_LAYER_MODE (operation);
-  GObject                *input;
-  GObject                *aux;
-  gboolean                has_input;
-  gboolean                has_aux;
+  GimpOperationLayerMode   *point = GIMP_OPERATION_LAYER_MODE (operation);
+  GObject                  *input;
+  GObject                  *aux;
+  gboolean                  has_input;
+  gboolean                  has_aux;
+  GimpLayerCompositeRegion  included_region;
 
   /* get the raw values.  this does not increase the reference count. */
   input = gegl_operation_context_get_object (context, "input");
@@ -402,13 +403,14 @@ gimp_operation_layer_mode_process (GeglOperation        *operation,
                               gegl_buffer_get_extent (GEGL_BUFFER (aux)),
                               result);
 
+  included_region = gimp_layer_mode_get_included_region (point->layer_mode,
+                                                         point->composite_mode);
+
   /* if there's no 'input' ... */
   if (! has_input)
     {
       /* ... and there's 'aux', and the composite mode includes it ... */
-      if (has_aux &&
-          (point->composite_mode == GIMP_LAYER_COMPOSITE_SRC_OVER ||
-           point->composite_mode == GIMP_LAYER_COMPOSITE_DST_ATOP))
+      if (has_aux && (included_region & GIMP_LAYER_COMPOSITE_REGION_SOURCE))
         {
           GimpLayerCompositeRegion affected_region;
 
@@ -445,8 +447,7 @@ gimp_operation_layer_mode_process (GeglOperation        *operation,
   else if (! has_aux)
     {
       /* ... and the composite mode includes 'input' ... */
-      if (point->composite_mode == GIMP_LAYER_COMPOSITE_SRC_OVER ||
-          point->composite_mode == GIMP_LAYER_COMPOSITE_SRC_ATOP)
+      if (included_region & GIMP_LAYER_COMPOSITE_REGION_DESTINATION)
         {
           GimpLayerCompositeRegion affected_region;
 


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