[gimp] app: improve gimp_gegl_mask_combine_rect()



commit 8a6e1c907dbb9bc790257dee4485f947798b125d
Author: Ell <ell_se yahoo com>
Date:   Tue Mar 19 16:17:47 2019 -0400

    app: improve gimp_gegl_mask_combine_rect()
    
    Simplify the code, and add support for CHANNEL_OP_INTERSECT.

 app/gegl/gimp-gegl-mask-combine.cc | 37 ++++++++++++++++++++++++-------------
 1 file changed, 24 insertions(+), 13 deletions(-)
---
diff --git a/app/gegl/gimp-gegl-mask-combine.cc b/app/gegl/gimp-gegl-mask-combine.cc
index 76a29db67f..c945dc9a76 100644
--- a/app/gegl/gimp-gegl-mask-combine.cc
+++ b/app/gegl/gimp-gegl-mask-combine.cc
@@ -42,24 +42,35 @@ gimp_gegl_mask_combine_rect (GeglBuffer     *mask,
                              gint            w,
                              gint            h)
 {
-  GeglColor *color;
+  GeglRectangle rect;
+  gfloat        value;
 
   g_return_val_if_fail (GEGL_IS_BUFFER (mask), FALSE);
 
-  if (! gimp_rectangle_intersect (x, y, w, h,
-                                  0, 0,
-                                  gegl_buffer_get_width  (mask),
-                                  gegl_buffer_get_height (mask),
-                                  &x, &y, &w, &h))
-    return FALSE;
+  if (! gegl_rectangle_intersect (&rect,
+                                  GEGL_RECTANGLE (x, y, w, h),
+                                  gegl_buffer_get_abyss (mask)))
+    {
+      return FALSE;
+    }
 
-  if (op == GIMP_CHANNEL_OP_ADD || op == GIMP_CHANNEL_OP_REPLACE)
-    color = gegl_color_new ("#fff");
-  else
-    color = gegl_color_new ("#000");
+  switch (op)
+    {
+    case GIMP_CHANNEL_OP_REPLACE:
+    case GIMP_CHANNEL_OP_ADD:
+      value = 1.0f;
+      break;
+
+    case GIMP_CHANNEL_OP_SUBTRACT:
+      value = 0.0f;
+      break;
+
+    case GIMP_CHANNEL_OP_INTERSECT:
+      return TRUE;
+    }
 
-  gegl_buffer_set_color (mask, GEGL_RECTANGLE (x, y, w, h), color);
-  g_object_unref (color);
+  gegl_buffer_set_color_from_pixel (mask, &rect, &value,
+                                    babl_format ("Y float"));
 
   return TRUE;
 }


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