[gtk-list] [patch] bug corrections for transparent pixmap in gdkpixmap.c




This patch corrects a couple of bugs in the gtkpixmap.c file which have
been introduced in the 971109 version.

  if (mask)
    {
      GdkColor tmp_color;

      *mask = gdk_pixmap_new (window, width, height, 1);
      gc = gdk_gc_new (*mask);

      tmp_color.pixel = 0;
                       ~~~
      gdk_gc_set_foreground (gc, &tmp_color);
      gdk_draw_rectangle (*mask, gc, TRUE, 0, 0, -1, -1);

      tmp_color.pixel = ~((gulong) 0);
                       ~~~~~~~~~~~~~~~
      gdk_gc_set_foreground (gc, &tmp_color);
    }


The author suppose that the black color is the first in the colormap
and that the white color is the last one.
This is be true for linux in true-color (depth 15-32).
If you're in pseudo-color (256 colors) the black color is the entry 0
(right), and white the entry 1 (oops). Maybe X can handle this for a
bitmap (1 plane).
But he real problem is that on a SUN (or HP, I don't remember), these
2 entries are swapped: 0 is white, and black is 1. So your mask is
inverted...
I don't like gdk_color_white/black() either, but unfortunatly we'll have
to stick to this solution until we find a better one :(.


I also added a default transparent color for the *creat_from_xpm* 
functions. The user must provide a color for the transparent one
(what for? it's transparent) and the function does not test if this
parameter is valid (seg. fault if it's NULL). So, now if s.o doesn't 
provide a transparent color (NULL pointer), a default color is used
(white).


diff file against 971109 version following...

Patrice.



diff -cr gtk+-971109.orig/gdk/gdkpixmap.c gtk+-971109/gdk/gdkpixmap.c
*** gtk+-971109.orig/gdk/gdkpixmap.c	Tue Nov  4 08:36:33 1997
--- gtk+-971109/gdk/gdkpixmap.c	Mon Nov 10 20:17:19 1997
***************
*** 353,358 ****
--- 353,359 ----
    GdkColormap *colormap;
    GdkVisual *visual;
    GdkGC *gc;
+   GdkColor tmp_color;
    gint width, height, num_cols, cpp, cnt, n, ns, xcnt, ycnt;
    gchar *buffer = NULL, *color_name = NULL, pixel_str[32];
    guint buffer_size = 0;
***************
*** 380,385 ****
--- 381,392 ----
                colormap = gdk_window_get_colormap (window);
                visual = gdk_window_get_visual (window);
  
+ 	      if (transparent_color == NULL) 
+ 		{
+ 		  gdk_color_white (colormap, &tmp_color);
+ 		  transparent_color = &tmp_color;
+ 		}
+ 
                for (cnt = 0; cnt < num_cols; cnt++)
                  {
                    gdk_pixmap_seek_char (infile, '"');
***************
*** 420,435 ****
  	      gc = NULL;
  	      if (mask)
  		{
- 		  GdkColor tmp_color;
- 
  		  *mask = gdk_pixmap_new (window, width, height, 1);
  		  gc = gdk_gc_new (*mask);
  
! 		  tmp_color.pixel = 0;
  		  gdk_gc_set_foreground (gc, &tmp_color);
  		  gdk_draw_rectangle (*mask, gc, TRUE, 0, 0, -1, -1);
  
! 		  tmp_color.pixel = ~((gulong) 0);
  		  gdk_gc_set_foreground (gc, &tmp_color);
  		}
  
--- 427,440 ----
  	      gc = NULL;
  	      if (mask)
  		{
  		  *mask = gdk_pixmap_new (window, width, height, 1);
  		  gc = gdk_gc_new (*mask);
  
! 		  gdk_color_black (colormap, &tmp_color);
  		  gdk_gc_set_foreground (gc, &tmp_color);
  		  gdk_draw_rectangle (*mask, gc, TRUE, 0, 0, -1, -1);
  
! 		  gdk_color_white (colormap, &tmp_color);
  		  gdk_gc_set_foreground (gc, &tmp_color);
  		}
  
***************
*** 504,509 ****
--- 509,515 ----
    GdkColormap *colormap;
    GdkVisual *visual;
    GdkGC *gc;
+   GdkColor tmp_color;
    gint width, height, num_cols, cpp, cnt, n, ns, xcnt, ycnt, i;
    gchar *buffer, *color_name = NULL, pixel_str[32];
    _GdkPixmapColor *colors = NULL, *color = NULL;
***************
*** 521,526 ****
--- 527,538 ----
    colormap = gdk_window_get_colormap (window);
    visual = gdk_window_get_visual (window);
  
+   if (transparent_color == NULL) 
+     {
+       gdk_color_white (colormap, &tmp_color);
+       transparent_color = &tmp_color;
+     }
+ 
    for (cnt = 0; cnt < num_cols; cnt++)
      {
        buffer = data[i++];
***************
*** 559,574 ****
    gc = NULL;
    if (mask)
      {
-       GdkColor tmp_color;
- 
        *mask = gdk_pixmap_new (window, width, height, 1);
        gc = gdk_gc_new (*mask);
  
!       tmp_color.pixel = 0;
        gdk_gc_set_foreground (gc, &tmp_color);
        gdk_draw_rectangle (*mask, gc, TRUE, 0, 0, -1, -1);
  
!       tmp_color.pixel = ~((gulong) 0);
        gdk_gc_set_foreground (gc, &tmp_color);
      }
  
--- 571,584 ----
    gc = NULL;
    if (mask)
      {
        *mask = gdk_pixmap_new (window, width, height, 1);
        gc = gdk_gc_new (*mask);
  
!       gdk_color_black (colormap, &tmp_color);
        gdk_gc_set_foreground (gc, &tmp_color);
        gdk_draw_rectangle (*mask, gc, TRUE, 0, 0, -1, -1);
  
!       gdk_color_white (colormap, &tmp_color);
        gdk_gc_set_foreground (gc, &tmp_color);
      }
  



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