[gimp] app: add gimp_drawable_filter_set_override_constraints()



commit b9a801f7d4a5b1b821859b8b91279903fdc74750
Author: Ell <ell_se yahoo com>
Date:   Wed Jan 15 23:34:19 2020 +0200

    app: add gimp_drawable_filter_set_override_constraints()
    
    In GimpDrawableFilter, add a
    gimp_drawable_filter_set_override_constraints() function, which
    allows bypassing certain constraints applied to the filter, based
    on the drawable type and state.
    
    Yes, this is a bit of a hack, added mostly as a quick-and-dirty way
    to allow us to add filters to layer masks that affect their
    bounding box, in preparation for composited transform previews.

 app/core/gimpdrawablefilter.c | 46 ++++++++++++++++++++++++++++++++++++++-----
 app/core/gimpdrawablefilter.h |  4 ++++
 2 files changed, 45 insertions(+), 5 deletions(-)
---
diff --git a/app/core/gimpdrawablefilter.c b/app/core/gimpdrawablefilter.c
index e4461a635a..dad6934390 100644
--- a/app/core/gimpdrawablefilter.c
+++ b/app/core/gimpdrawablefilter.c
@@ -81,6 +81,8 @@ struct _GimpDrawableFilter
   gboolean                color_managed;
   gboolean                gamma_hack;
 
+  gboolean                override_constraints;
+
   GeglRectangle           filter_area;
   gboolean                filter_clip;
 
@@ -454,6 +456,25 @@ gimp_drawable_filter_set_gamma_hack (GimpDrawableFilter *filter,
     }
 }
 
+void
+gimp_drawable_filter_set_override_constraints (GimpDrawableFilter *filter,
+                                               gboolean            override_constraints)
+{
+  g_return_if_fail (GIMP_IS_DRAWABLE_FILTER (filter));
+
+  if (override_constraints != filter->override_constraints)
+    {
+      filter->override_constraints = override_constraints;
+
+      gimp_drawable_filter_sync_affect (filter);
+      gimp_drawable_filter_sync_format (filter);
+      gimp_drawable_filter_sync_clip   (filter, TRUE);
+
+      if (gimp_drawable_filter_is_filtering (filter))
+        gimp_drawable_filter_update_drawable (filter, NULL);
+    }
+}
+
 void
 gimp_drawable_filter_apply (GimpDrawableFilter  *filter,
                             const GeglRectangle *area)
@@ -532,7 +553,10 @@ gimp_drawable_filter_sync_clip (GimpDrawableFilter *filter,
 {
   gboolean clip;
 
-  clip = gimp_item_get_clip (GIMP_ITEM (filter->drawable), filter->clip);
+  if (filter->override_constraints)
+    clip = filter->clip;
+  else
+    clip = gimp_item_get_clip (GIMP_ITEM (filter->drawable), filter->clip);
 
   if (! clip)
     {
@@ -787,7 +811,14 @@ gimp_drawable_filter_sync_affect (GimpDrawableFilter *filter)
 {
   gimp_applicator_set_affect (
     filter->applicator,
-    gimp_drawable_get_active_mask (filter->drawable));
+    filter->override_constraints ?
+
+      GIMP_COMPONENT_MASK_RED   |
+      GIMP_COMPONENT_MASK_GREEN |
+      GIMP_COMPONENT_MASK_BLUE  |
+      GIMP_COMPONENT_MASK_ALPHA :
+
+      gimp_drawable_get_active_mask (filter->drawable));
 }
 
 static void
@@ -795,10 +826,15 @@ gimp_drawable_filter_sync_format (GimpDrawableFilter *filter)
 {
   const Babl *format;
 
-  if (filter->add_alpha && GIMP_IS_LAYER (filter->drawable))
-    format = gimp_drawable_get_format_with_alpha (filter->drawable);
+  if (filter->add_alpha &&
+      (GIMP_IS_LAYER (filter->drawable) || filter->override_constraints))
+    {
+      format = gimp_drawable_get_format_with_alpha (filter->drawable);
+    }
   else
-    format = gimp_drawable_get_format (filter->drawable);
+    {
+      format = gimp_drawable_get_format (filter->drawable);
+    }
 
   gimp_applicator_set_output_format (filter->applicator, format);
 }
diff --git a/app/core/gimpdrawablefilter.h b/app/core/gimpdrawablefilter.h
index 14bb699359..44c74c7f81 100644
--- a/app/core/gimpdrawablefilter.h
+++ b/app/core/gimpdrawablefilter.h
@@ -79,6 +79,10 @@ void       gimp_drawable_filter_set_add_alpha  (GimpDrawableFilter  *filter,
 void       gimp_drawable_filter_set_gamma_hack (GimpDrawableFilter  *filter,
                                                 gboolean             gamma_hack);
 
+void       gimp_drawable_filter_set_override_constraints
+                                               (GimpDrawableFilter  *filter,
+                                                gboolean             override_constraints);
+
 void       gimp_drawable_filter_apply          (GimpDrawableFilter  *filter,
                                                 const GeglRectangle *area);
 


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