[gimp] app: add gimp_gegl_clear()



commit 2e3eab7fbdf110f0bd2673408807e947b581f2a5
Author: Ell <ell_se yahoo com>
Date:   Sun Dec 2 02:47:06 2018 -0500

    app: add gimp_gegl_clear()
    
    ... which clears the alpha component of a given buffer region,
    i.e., it makes the region transparent, while preserving color
    information.  This corresponds to the "edit-clear" action.

 app/gegl/gimp-gegl-loops.cc | 52 +++++++++++++++++++++++++++++++++++++++++++++
 app/gegl/gimp-gegl-loops.h  |  3 +++
 2 files changed, 55 insertions(+)
---
diff --git a/app/gegl/gimp-gegl-loops.cc b/app/gegl/gimp-gegl-loops.cc
index 0fba7766b2..1a23b1bd3b 100644
--- a/app/gegl/gimp-gegl-loops.cc
+++ b/app/gegl/gimp-gegl-loops.cc
@@ -93,6 +93,58 @@ gimp_gegl_buffer_copy (GeglBuffer          *src_buffer,
     }
 }
 
+void
+gimp_gegl_clear (GeglBuffer          *buffer,
+                 const GeglRectangle *rect)
+{
+  const Babl *format;
+  gint        bpp;
+  gint        n_components;
+  gint        bpc;
+  gint        alpha_offset;
+
+  g_return_if_fail (GEGL_IS_BUFFER (buffer));
+
+  if (! rect)
+    rect = gegl_buffer_get_extent (buffer);
+
+  format = gegl_buffer_get_format (buffer);
+
+  if (! babl_format_has_alpha (format))
+    return;
+
+  bpp          = babl_format_get_bytes_per_pixel (format);
+  n_components = babl_format_get_n_components (format);
+  bpc          = bpp / n_components;
+  alpha_offset = (n_components - 1) * bpc;
+
+  gegl_parallel_distribute_area (
+    rect, PIXELS_PER_THREAD,
+    [=] (const GeglRectangle *area)
+    {
+      GeglBufferIterator *iter;
+
+      iter = gegl_buffer_iterator_new (buffer, rect, 0, format,
+                                       GEGL_ACCESS_READWRITE, GEGL_ABYSS_NONE,
+                                       1);
+
+      while (gegl_buffer_iterator_next (iter))
+        {
+          guint8 *data = (guint8 *) iter->items[0].data;
+          gint    i;
+
+          data += alpha_offset;
+
+          for (i = 0; i < iter->length; i++)
+            {
+              memset (data, 0, bpc);
+
+              data += bpp;
+            }
+        }
+    });
+}
+
 void
 gimp_gegl_convolve (GeglBuffer          *src_buffer,
                     const GeglRectangle *src_rect,
diff --git a/app/gegl/gimp-gegl-loops.h b/app/gegl/gimp-gegl-loops.h
index 566fe39f76..bf7fae8035 100644
--- a/app/gegl/gimp-gegl-loops.h
+++ b/app/gegl/gimp-gegl-loops.h
@@ -28,6 +28,9 @@ void   gimp_gegl_buffer_copy           (GeglBuffer               *src_buffer,
                                         GeglBuffer               *dest_buffer,
                                         const GeglRectangle      *dest_rect);
 
+void   gimp_gegl_clear                 (GeglBuffer               *buffer,
+                                        const GeglRectangle      *rect);
+
 /*  this is a pretty stupid port of concolve_region() that only works
  *  on a linear source buffer
  */


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