[gimp] app: in gimp:replace, implement GeglOperation::get_bounding_box()



commit 998f89e3cbbe6242f48da29879bdeab13403bb79
Author: Ell <ell_se yahoo com>
Date:   Thu Aug 1 23:39:51 2019 +0300

    app: in gimp:replace, implement GeglOperation::get_bounding_box()
    
    ... similarly to gimp:layer-mode, however, assume the destnation
    (backdrop) is not included when the layer's opacity is 1, and
    there's no mask.

 app/operations/layer-modes/gimpoperationreplace.c | 55 +++++++++++++++++++++++
 1 file changed, 55 insertions(+)
---
diff --git a/app/operations/layer-modes/gimpoperationreplace.c 
b/app/operations/layer-modes/gimpoperationreplace.c
index 18111fd402..3e844e3477 100644
--- a/app/operations/layer-modes/gimpoperationreplace.c
+++ b/app/operations/layer-modes/gimpoperationreplace.c
@@ -30,6 +30,7 @@
 #include "gimpoperationreplace.h"
 
 
+static GeglRectangle              gimp_operation_replace_get_bounding_box    (GeglOperation        *op);
 static gboolean                   gimp_operation_replace_parent_process      (GeglOperation        *op,
                                                                               GeglOperationContext *context,
                                                                               const gchar          
*output_prop,
@@ -64,6 +65,7 @@ gimp_operation_replace_class_init (GimpOperationReplaceClass *klass)
                                  "description", "GIMP replace mode operation",
                                  NULL);
 
+  operation_class->get_bounding_box     = gimp_operation_replace_get_bounding_box;
   operation_class->process              = gimp_operation_replace_parent_process;
 
   layer_mode_class->process             = gimp_operation_replace_process;
@@ -75,6 +77,59 @@ gimp_operation_replace_init (GimpOperationReplace *self)
 {
 }
 
+static GeglRectangle
+gimp_operation_replace_get_bounding_box (GeglOperation *op)
+{
+  GimpOperationLayerMode   *self     = (gpointer) op;
+  GeglRectangle            *in_rect;
+  GeglRectangle            *aux_rect;
+  GeglRectangle            *aux2_rect;
+  GeglRectangle             src_rect = {};
+  GeglRectangle             dst_rect = {};
+  GeglRectangle             result;
+  GimpLayerCompositeRegion  included_region;
+
+  in_rect   = gegl_operation_source_get_bounding_box (op, "input");
+  aux_rect  = gegl_operation_source_get_bounding_box (op, "aux");
+  aux2_rect = gegl_operation_source_get_bounding_box (op, "aux2");
+
+  if (in_rect)
+    dst_rect = *in_rect;
+
+  if (aux_rect)
+    {
+      src_rect = *aux_rect;
+
+      if (aux2_rect)
+        gegl_rectangle_intersect (&src_rect, &src_rect, aux2_rect);
+    }
+
+  if (self->is_last_node)
+    {
+      included_region = GIMP_LAYER_COMPOSITE_REGION_SOURCE;
+    }
+  else
+    {
+      included_region = gimp_layer_mode_get_included_region (self->layer_mode,
+                                                             self->composite_mode);
+    }
+
+  if (self->opacity == 0.0)
+    included_region &= ~GIMP_LAYER_COMPOSITE_REGION_SOURCE;
+  else if (self->opacity == 1.0 && ! aux2_rect)
+    included_region &= ~GIMP_LAYER_COMPOSITE_REGION_DESTINATION;
+
+  gegl_rectangle_intersect (&result, &src_rect, &dst_rect);
+
+  if (included_region & GIMP_LAYER_COMPOSITE_REGION_SOURCE)
+    gegl_rectangle_bounding_box (&result, &result, &src_rect);
+
+  if (included_region & GIMP_LAYER_COMPOSITE_REGION_DESTINATION)
+    gegl_rectangle_bounding_box (&result, &result, &dst_rect);
+
+  return result;
+}
+
 static gboolean
 gimp_operation_replace_parent_process (GeglOperation        *op,
                                        GeglOperationContext *context,


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