[gegl] matting-{global, levin}: use input bounding box as output bounding box



commit 378cd512c35fe2eb255492f90b503a67ab38d7a3
Author: Ell <ell_se yahoo com>
Date:   Mon Feb 3 21:05:36 2020 +0200

    matting-{global,levin}: use input bounding box as output bounding box
    
    In gegl:matting-{global,levin}, use the input bounding box as the
    output bounding box, instead of letting GeglOperationComposer use
    the union of the input and aux bounding boxes.  This fixes a
    segfault when the two bounding boxes are different.
    
    See issue gimp#4174.

 operations/common/matting-global.c  | 39 ++++++++++++++++++++++++++++---------
 operations/external/matting-levin.c | 39 +++++++++++++++++++++++++++++--------
 2 files changed, 61 insertions(+), 17 deletions(-)
---
diff --git a/operations/common/matting-global.c b/operations/common/matting-global.c
index ce6394a3d..800e7a35b 100644
--- a/operations/common/matting-global.c
+++ b/operations/common/matting-global.c
@@ -81,21 +81,40 @@ matting_prepare (GeglOperation *operation)
   gegl_operation_set_format (operation, "output", out_format);
 }
 
+static GeglRectangle
+matting_get_bounding_box (GeglOperation *operation)
+{
+  GeglRectangle  result  = {};
+  GeglRectangle *in_rect = gegl_operation_source_get_bounding_box (operation,
+                                                                   "input");
+
+  if (in_rect)
+    result = *in_rect;
+
+  return result;
+}
+
+static GeglRectangle
+matting_get_invalidated_by_change (GeglOperation       *operation,
+                                   const gchar         *input_pad,
+                                   const GeglRectangle *roi)
+{
+  return matting_get_bounding_box (operation);
+}
+
 static GeglRectangle
 matting_get_required_for_output (GeglOperation       *operation,
                                  const gchar         *input_pad,
                                  const GeglRectangle *roi)
 {
-  GeglRectangle result = *gegl_operation_source_get_bounding_box (operation,
-                                                                  "input");
-  return result;
+  return matting_get_bounding_box (operation);
 }
 
 static GeglRectangle
 matting_get_cached_region (GeglOperation * operation,
                            const GeglRectangle * roi)
 {
-  return *gegl_operation_source_get_bounding_box (operation, "input");
+  return matting_get_bounding_box (operation);
 }
 
 typedef struct {
@@ -567,11 +586,13 @@ gegl_op_class_init (GeglOpClass *klass)
   composer_class  = GEGL_OPERATION_COMPOSER_CLASS (klass);
   operation_class = GEGL_OPERATION_CLASS (klass);
 
-  composer_class->process                  = matting_process;
-  operation_class->prepare                 = matting_prepare;
-  operation_class->get_required_for_output = matting_get_required_for_output;
-  operation_class->get_cached_region       = matting_get_cached_region;
-  operation_class->threaded                = FALSE;
+  composer_class->process                    = matting_process;
+  operation_class->prepare                   = matting_prepare;
+  operation_class->get_bounding_box          = matting_get_bounding_box;
+  operation_class->get_invalidated_by_change = matting_get_invalidated_by_change;
+  operation_class->get_required_for_output   = matting_get_required_for_output;
+  operation_class->get_cached_region         = matting_get_cached_region;
+  operation_class->threaded                  = FALSE;
 
   gegl_operation_class_set_keys (operation_class,
     "name"       , "gegl:matting-global",
diff --git a/operations/external/matting-levin.c b/operations/external/matting-levin.c
index 0d1cccb77..24755fb67 100644
--- a/operations/external/matting-levin.c
+++ b/operations/external/matting-levin.c
@@ -235,14 +235,35 @@ matting_prepare (GeglOperation *operation)
 }
 
 
+static GeglRectangle
+matting_get_bounding_box (GeglOperation *operation)
+{
+  GeglRectangle  result  = {};
+  GeglRectangle *in_rect = gegl_operation_source_get_bounding_box (operation,
+                                                                   "input");
+
+  if (in_rect)
+    result = *in_rect;
+
+  return result;
+}
+
+
+static GeglRectangle
+matting_get_invalidated_by_change (GeglOperation       *operation,
+                                   const gchar         *input_pad,
+                                   const GeglRectangle *roi)
+{
+  return matting_get_bounding_box (operation);
+}
+
+
 static GeglRectangle
 matting_get_required_for_output (GeglOperation       *operation,
                                  const gchar         *input_pad,
                                  const GeglRectangle *roi)
 {
-  GeglRectangle result = *gegl_operation_source_get_bounding_box (operation,
-                                                                  "input");
-  return result;
+  return matting_get_bounding_box (operation);
 }
 
 
@@ -250,7 +271,7 @@ static GeglRectangle
 matting_get_cached_region (GeglOperation * operation,
                            const GeglRectangle * roi)
 {
-  return *gegl_operation_source_get_bounding_box (operation, "input");
+  return matting_get_bounding_box (operation);
 }
 
 
@@ -1445,10 +1466,12 @@ gegl_op_class_init (GeglOpClass *klass)
 
   composer_class->process = matting_process;
 
-  operation_class->prepare                 = matting_prepare;
-  operation_class->get_required_for_output = matting_get_required_for_output;
-  operation_class->get_cached_region       = matting_get_cached_region;
-  operation_class->threaded                = FALSE;
+  operation_class->prepare                   = matting_prepare;
+  operation_class->get_bounding_box          = matting_get_bounding_box;
+  operation_class->get_invalidated_by_change = matting_get_invalidated_by_change;
+  operation_class->get_required_for_output   = matting_get_required_for_output;
+  operation_class->get_cached_region         = matting_get_cached_region;
+  operation_class->threaded                  = FALSE;
 
   gegl_operation_class_set_keys (operation_class,
   "name",         "gegl:matting-levin",


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