[gimp/gimp-2-10] app: add gimp_drawable_filter_set_override_constraints()



commit 6d7e18ff8a7e0a00bb957d1edde6888e392a72b3
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 ea9bd2f420..c9f83642b1 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;
 
@@ -487,6 +489,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)
@@ -565,7 +586,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)
     {
@@ -820,7 +844,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
@@ -828,10 +859,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 6b8a3a43b9..b8584dd6b2 100644
--- a/app/core/gimpdrawablefilter.h
+++ b/app/core/gimpdrawablefilter.h
@@ -82,6 +82,10 @@ void       gimp_drawable_filter_set_color_managed
 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]