[gimp] app: fix out-of-bounds rendering when alpha channel is invisible



commit da701ffc3a4b412cc7f898bbbe5a20ef9c72887e
Author: Ell <ell_se yahoo com>
Date:   Wed Sep 4 17:48:06 2019 +0300

    app: fix out-of-bounds rendering when alpha channel is invisible
    
    When the image's alpha channel is invisible, paint regions outside
    the image contents as black, instead of using a checkboard pattern.
    This is especially notable when viewing the image in "show all"
    mode.

 app/display/gimpdisplayshell-draw.c     | 12 +++++++++++-
 app/display/gimpdisplayshell-handlers.c | 19 +++++++++++++++++++
 2 files changed, 30 insertions(+), 1 deletion(-)
---
diff --git a/app/display/gimpdisplayshell-draw.c b/app/display/gimpdisplayshell-draw.c
index ccc14005eb..8562c1d928 100644
--- a/app/display/gimpdisplayshell-draw.c
+++ b/app/display/gimpdisplayshell-draw.c
@@ -29,6 +29,7 @@
 
 #include "core/gimp-cairo.h"
 #include "core/gimp-utils.h"
+#include "core/gimpimage.h"
 
 #include "gimpcanvas.h"
 #include "gimpcanvas-style.h"
@@ -95,9 +96,13 @@ void
 gimp_display_shell_draw_checkerboard (GimpDisplayShell *shell,
                                       cairo_t          *cr)
 {
+  GimpImage *image;
+
   g_return_if_fail (GIMP_IS_DISPLAY_SHELL (shell));
   g_return_if_fail (cr != NULL);
 
+  image = gimp_display_get_image (shell->display);
+
   if (G_UNLIKELY (! shell->checkerboard))
     {
       GimpCheckSize  check_size;
@@ -122,7 +127,12 @@ gimp_display_shell_draw_checkerboard (GimpDisplayShell *shell,
     }
 
   cairo_translate (cr, - shell->offset_x, - shell->offset_y);
-  cairo_set_source (cr, shell->checkerboard);
+
+  if (gimp_image_get_component_visible (image, GIMP_CHANNEL_ALPHA))
+    cairo_set_source (cr, shell->checkerboard);
+  else
+    cairo_set_source_rgb (cr, 0.0, 0.0, 0.0);
+
   cairo_paint (cr);
 }
 
diff --git a/app/display/gimpdisplayshell-handlers.c b/app/display/gimpdisplayshell-handlers.c
index fbd86ebfc4..f307d6ef0e 100644
--- a/app/display/gimpdisplayshell-handlers.c
+++ b/app/display/gimpdisplayshell-handlers.c
@@ -91,6 +91,10 @@ static void   gimp_display_shell_name_changed_handler       (GimpImage        *i
 static void   gimp_display_shell_selection_invalidate_handler
                                                             (GimpImage        *image,
                                                              GimpDisplayShell *shell);
+static void   gimp_display_shell_component_visibility_changed_handler
+                                                            (GimpImage        *image,
+                                                             GimpChannelType   channel,
+                                                             GimpDisplayShell *shell);
 static void   gimp_display_shell_size_changed_detailed_handler
                                                             (GimpImage        *image,
                                                              gint              previous_origin_x,
@@ -221,6 +225,9 @@ gimp_display_shell_connect (GimpDisplayShell *shell)
   g_signal_connect (image, "selection-invalidate",
                     G_CALLBACK (gimp_display_shell_selection_invalidate_handler),
                     shell);
+  g_signal_connect (image, "component-visibility-changed",
+                    G_CALLBACK (gimp_display_shell_component_visibility_changed_handler),
+                    shell);
   g_signal_connect (image, "size-changed-detailed",
                     G_CALLBACK (gimp_display_shell_size_changed_detailed_handler),
                     shell);
@@ -546,6 +553,9 @@ gimp_display_shell_disconnect (GimpDisplayShell *shell)
   g_signal_handlers_disconnect_by_func (image,
                                         gimp_display_shell_resolution_changed_handler,
                                         shell);
+  g_signal_handlers_disconnect_by_func (image,
+                                        gimp_display_shell_component_visibility_changed_handler,
+                                        shell);
   g_signal_handlers_disconnect_by_func (image,
                                         gimp_display_shell_size_changed_detailed_handler,
                                         shell);
@@ -800,6 +810,15 @@ gimp_display_shell_sample_point_move_handler (GimpImage        *image,
   gimp_canvas_sample_point_set (item, x, y);
 }
 
+static void
+gimp_display_shell_component_visibility_changed_handler (GimpImage        *image,
+                                                         GimpChannelType   channel,
+                                                         GimpDisplayShell *shell)
+{
+  if (channel == GIMP_CHANNEL_ALPHA && shell->show_all)
+    gimp_display_shell_expose_full (shell);
+}
+
 static void
 gimp_display_shell_size_changed_detailed_handler (GimpImage        *image,
                                                   gint              previous_origin_x,


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