[Xfce4-commits] <ristretto:master> Improve rendering of the 'checkered background' for transparent images.

Stephan Arts noreply at xfce.org
Sat Aug 27 14:40:05 CEST 2011


Updating branch refs/heads/master
         to f6c5507d34e9c17ca229849c426056d216105355 (commit)
       from e7d2a9082e66526ab245a030fd5da9fc83e913b1 (commit)

commit f6c5507d34e9c17ca229849c426056d216105355
Author: Stephan Arts <stephan at xfce.org>
Date:   Fri Aug 26 21:23:30 2011 +0200

    Improve rendering of the 'checkered background' for transparent images.

 src/image_viewer.c |   29 ++++++++++++++++++++---------
 1 files changed, 20 insertions(+), 9 deletions(-)

diff --git a/src/image_viewer.c b/src/image_viewer.c
index a8374f8..b72a098 100644
--- a/src/image_viewer.c
+++ b/src/image_viewer.c
@@ -49,6 +49,8 @@ struct _RsttoImageViewerPriv
 {
     GFile                       *file;
     RsttoSettings               *settings;
+    GdkVisual                   *visual;
+    GdkColormap                 *colormap;
 
     RsttoImageViewerTransaction *transaction;
     GdkPixbuf                   *pixbuf;
@@ -220,6 +222,8 @@ rstto_image_viewer_init(RsttoImageViewer *viewer)
     viewer->priv->settings = rstto_settings_new();
     viewer->priv->image_width = 0;
     viewer->priv->image_height = 0;
+    viewer->priv->visual = gdk_rgb_get_visual();
+    viewer->priv->colormap = gdk_colormap_new (viewer->priv->visual, TRUE);
 
     g_signal_connect (G_OBJECT(viewer->priv->settings), "notify::bgcolor", G_CALLBACK (cb_rstto_image_viewer_bgcolor_changed), viewer);
     g_signal_connect (G_OBJECT(viewer->priv->settings), "notify::bgcolor-override", G_CALLBACK (cb_rstto_image_viewer_bgcolor_changed), viewer);
@@ -657,12 +661,19 @@ rstto_image_viewer_paint_checkers (RsttoImageViewer *viewer,
 {
     gint x, y;
     gint block_width, block_height;
-    GdkColor color;
+    GdkColor color_a;
+    GdkColor color_b;
 
-    /* This is to remind me of a bug in this function, 
-     * the top-left square is colored red, it shouldn't
-     */
-    color.pixel = 0xeeee0000;
+    color_a.red   = 0xcccc;
+    color_a.green = 0xcccc;
+    color_a.blue  = 0xcccc;
+
+    color_b.red   = 0xdddd;
+    color_b.green = 0xdddd;
+    color_b.blue  = 0xdddd;
+
+    gdk_colormap_alloc_color (viewer->priv->colormap, &color_a, FALSE, TRUE);
+    gdk_colormap_alloc_color (viewer->priv->colormap, &color_b, FALSE, TRUE);
 
     for(x = 0; x <= width/10; ++x)
     {
@@ -676,7 +687,6 @@ rstto_image_viewer_paint_checkers (RsttoImageViewer *viewer,
         }
         for(y = 0; y <= height/10; ++y)
         {
-            gdk_gc_set_foreground(gc, &color);
             if(y == height/10)
             {
                 block_height = height-10*y;
@@ -686,12 +696,13 @@ rstto_image_viewer_paint_checkers (RsttoImageViewer *viewer,
                 block_height = 10;
             }
 
-            if((y%2?x%2:!(x%2))) {
-                color.pixel = 0xcccccccc;
+            if ((y%2?x%2:!(x%2)))
+            {
+                gdk_gc_set_foreground(gc, &color_a);
             }
             else
             {
-                color.pixel = 0xdddddddd;
+                gdk_gc_set_foreground(gc, &color_b);
             }
 
             gdk_draw_rectangle(GDK_DRAWABLE(drawable),


More information about the Xfce4-commits mailing list