[gimp/gimp-2-10] app: improve gimp_channel_clear()



commit 4c22313ce6a0814c66d7ea42e1d07defc4cf3bfc
Author: Ell <ell_se yahoo com>
Date:   Thu Jan 17 15:05:37 2019 -0500

    app: improve gimp_channel_clear()
    
    When clearing a channel, do nothing if the channel is already
    empty; otherwise, align the cleared rectangle to the channel
    buffer's tile grid, so that all affected tiles are dropped, rather
    than zeroed.  Furthermore, only update the affected region of the
    channel.
    
    (cherry picked from commit ac5e4f4c33688498e197a75e40a82f7349253af8)

 app/core/gimpchannel.c | 33 +++++++++++++++++++++++++--------
 1 file changed, 25 insertions(+), 8 deletions(-)
---
diff --git a/app/core/gimpchannel.c b/app/core/gimpchannel.c
index 774fe09db4..cef462ba7b 100644
--- a/app/core/gimpchannel.c
+++ b/app/core/gimpchannel.c
@@ -36,6 +36,7 @@
 #include "gegl/gimp-gegl-loops.h"
 #include "gegl/gimp-gegl-mask.h"
 #include "gegl/gimp-gegl-nodes.h"
+#include "gegl/gimp-gegl-utils.h"
 
 #include "gimp.h"
 #include "gimp-utils.h"
@@ -1255,6 +1256,13 @@ gimp_channel_real_clear (GimpChannel *channel,
                          const gchar *undo_desc,
                          gboolean     push_undo)
 {
+  GeglBuffer    *buffer;
+  GeglRectangle  rect;
+  GeglRectangle  aligned_rect;
+
+  if (channel->bounds_known && channel->empty)
+    return;
+
   if (push_undo)
     {
       if (! undo_desc)
@@ -1263,19 +1271,27 @@ gimp_channel_real_clear (GimpChannel *channel,
       gimp_channel_push_undo (channel, undo_desc);
     }
 
-  if (channel->bounds_known && ! channel->empty)
+  buffer = gimp_drawable_get_buffer (GIMP_DRAWABLE (channel));
+
+  if (channel->bounds_known)
     {
-      gegl_buffer_clear (gimp_drawable_get_buffer (GIMP_DRAWABLE (channel)),
-                         GEGL_RECTANGLE (channel->x1, channel->y1,
-                                         channel->x2 - channel->x1,
-                                         channel->y2 - channel->y1));
+      rect.x      = channel->x1;
+      rect.y      = channel->y1;
+      rect.width  = channel->x2 - channel->x1;
+      rect.height = channel->y2 - channel->y1;
     }
   else
     {
-      gegl_buffer_clear (gimp_drawable_get_buffer (GIMP_DRAWABLE (channel)),
-                         NULL);
+      rect.x      = 0;
+      rect.y      = 0;
+      rect.width  = gimp_item_get_width  (GIMP_ITEM (channel));
+      rect.height = gimp_item_get_height (GIMP_ITEM (channel));
     }
 
+  gimp_gegl_rectangle_align_to_tile_grid (&aligned_rect, &rect, buffer);
+
+  gegl_buffer_clear (buffer, &aligned_rect);
+
   /*  we know the bounds  */
   channel->bounds_known = TRUE;
   channel->empty        = TRUE;
@@ -1284,7 +1300,8 @@ gimp_channel_real_clear (GimpChannel *channel,
   channel->x2           = gimp_item_get_width  (GIMP_ITEM (channel));
   channel->y2           = gimp_item_get_height (GIMP_ITEM (channel));
 
-  gimp_drawable_update (GIMP_DRAWABLE (channel), 0, 0, -1, -1);
+  gimp_drawable_update (GIMP_DRAWABLE (channel),
+                        rect.x, rect.y, rect.width, rect.height);
 }
 
 static void


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