[gimp/gimp-2-10] app: optimize gimp_gegl_mask_is_empty()



commit 5807ca820bce8d6c9acbb114199d9d28e44271da
Author: Ell <ell_se yahoo com>
Date:   Tue Jan 1 06:28:12 2019 -0500

    app: optimize gimp_gegl_mask_is_empty()
    
    ... by using the mask's native format, and gegl_memeq_zero().
    
    (cherry picked from commit 986a298a07fdcd2c1fb3d5fcb5a967920ed9944d)

 app/gegl/gimp-gegl-mask.c | 19 +++++++++----------
 1 file changed, 9 insertions(+), 10 deletions(-)
---
diff --git a/app/gegl/gimp-gegl-mask.c b/app/gegl/gimp-gegl-mask.c
index 311b05879d..e67ae11590 100644
--- a/app/gegl/gimp-gegl-mask.c
+++ b/app/gegl/gimp-gegl-mask.c
@@ -134,25 +134,24 @@ gboolean
 gimp_gegl_mask_is_empty (GeglBuffer *buffer)
 {
   GeglBufferIterator *iter;
+  const Babl         *format;
+  gint                bpp;
 
   g_return_val_if_fail (GEGL_IS_BUFFER (buffer), FALSE);
 
-  iter = gegl_buffer_iterator_new (buffer, NULL, 0, babl_format ("Y float"),
+  format = gegl_buffer_get_format (buffer);
+  bpp    = babl_format_get_bytes_per_pixel (format);
+
+  iter = gegl_buffer_iterator_new (buffer, NULL, 0, format,
                                    GEGL_ACCESS_READ, GEGL_ABYSS_NONE, 1);
 
   while (gegl_buffer_iterator_next (iter))
     {
-      gfloat *data = iter->items[0].data;
-      gint    i;
-
-      for (i = 0; i < iter->length; i++)
+      if (! gegl_memeq_zero (iter->items[0].data, bpp * iter->length))
         {
-          if (data[i])
-            {
-              gegl_buffer_iterator_stop (iter);
+          gegl_buffer_iterator_stop (iter);
 
-              return FALSE;
-            }
+          return FALSE;
         }
     }
 


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