Index: gtk+//ChangeLog
===================================================================
RCS file: /export/cvs/gnome-2.0/gtk+/ChangeLog,v
retrieving revision 1.26
diff -p -u -5 -r1.26 ChangeLog
--- gtk+//ChangeLog	2002/03/31 22:13:35	1.26
+++ gtk+//ChangeLog	2002/04/03 06:22:31
@@ -1,5 +1,16 @@
+Wed Apr 3  12:28:15 2002  Shivram U  <shivaram.upadhyayula@wipro.com>
+
+	* gdk/gdkpixbuf-drawable.c (gdk_pixbuf_get_from_drawable),
+	(gdk_pixbuf_get_from_image), (rgbconvert), (convert_real_slow):
+	Check if depth of the source is not equal to the depth of the colormap
+	passed. Fixes #75597.
+
+	* gdk/x11/gdkcolor-x11.c (gdk_colormap_sync): Fill up the colors array
+	for DirectColor visual class too. (gdk_colormap_get_system): If the
+	visual class is DirectColor calling gdk_colormap_sync().
+
 Sat Mar 30 15:19:24 2002  Kristian Rietveld  <kris@gtk.org>
 
 	* gtk/gtktreemodelsort.c: revert the latest stamp increment changes,
 	as it broke stuff for trees
 
Index: gtk+//gdk/gdkpixbuf-drawable.c
===================================================================
RCS file: /export/cvs/gnome-2.0/gtk+/gdk/gdkpixbuf-drawable.c,v
retrieving revision 1.1.1.1
diff -p -u -5 -r1.1.1.1 gdkpixbuf-drawable.c
--- gtk+//gdk/gdkpixbuf-drawable.c	2002/03/05 20:41:38	1.1.1.1
+++ gtk+//gdk/gdkpixbuf-drawable.c	2002/04/03 06:22:31
@@ -1215,10 +1215,15 @@ convert_real_slow (GdkImage    *image,
   int i;
 
   bpl = image->bpl;
   v = gdk_colormap_get_visual(cmap);
 
+  if (image->depth != v->depth)
+    {
+      return;
+    } 
+ 
   d(printf("rgb  mask/shift/prec = %x:%x:%x %d:%d:%d  %d:%d:%d\n",
 	   v->red_mask, v->green_mask, v->blue_mask,
 	   v->red_shift, v->green_shift, v->blue_shift,
 	   v->red_prec, v->green_prec, v->blue_prec));
 
@@ -1324,12 +1329,18 @@ rgbconvert (GdkImage    *image,
         bitmap1 (image, pixels, rowstride,
                   x, y, x + width, y + height);
       
       return;
     }
-  
+
   v = gdk_colormap_get_visual (cmap);
+
+  if (image->depth != v->depth)
+    {
+      return;
+    } 
+ 
   bank = 5; /* default fallback converter */
   index = (image->byte_order == GDK_MSB_FIRST) | (alpha != 0) << 1;
   
   d(printf("masks = %x:%x:%x\n", v->red_mask, v->green_mask, v->blue_mask));
   d(printf("image depth = %d, bits per pixel = %d\n", image->depth, image->bits_per_pixel));
@@ -1519,11 +1530,19 @@ gdk_pixbuf_get_from_drawable (GdkPixbuf 
       g_warning ("%s: Source drawable has no colormap; either pass "
                  "in a colormap, or set the colormap on the drawable "
                  "with gdk_drawable_set_colormap()", G_STRLOC);
       return NULL;
     }
-  
+ 
+  if (cmap != NULL && depth != cmap->visual->depth)
+    {
+      g_warning ("%s: Depth of the source drawable is %d where as "
+                 "the visual depth of the colormap passed is %d",
+                 G_STRLOC, depth, cmap->visual->depth);
+      return NULL;
+    } 
+ 
   /* Coordinate sanity checks */
   
   if (GDK_IS_PIXMAP (src))
     {
       gdk_drawable_get_size (src, &src_width, &src_height);
@@ -1619,10 +1638,18 @@ gdk_pixbuf_get_from_image (GdkPixbuf   *
                  "in a colormap, or set the colormap on the image "
                  "with gdk_image_set_colormap()", G_STRLOC);
       return NULL;
     }
   
+  if (cmap != NULL && src->depth != cmap->visual->depth)
+    {
+      g_warning ("%s: Depth of the Source image is %d where as "
+                 "the visual depth of the colormap passed is %d",
+                 G_STRLOC, src->depth, cmap->visual->depth);
+      return NULL;
+    } 
+ 
   /* Coordinate sanity checks */
 
   g_return_val_if_fail (src_x >= 0 && src_y >= 0, NULL);
   g_return_val_if_fail (src_x + width <= src->width && src_y + height <= src->height, NULL);
 
Index: gtk+//gdk/x11/gdkcolor-x11.c
===================================================================
RCS file: /export/cvs/gnome-2.0/gtk+/gdk/x11/gdkcolor-x11.c,v
retrieving revision 1.1.1.1
diff -p -u -5 -r1.1.1.1 gdkcolor-x11.c
--- gtk+//gdk/x11/gdkcolor-x11.c	2002/03/05 20:41:43	1.1.1.1
+++ gtk+//gdk/x11/gdkcolor-x11.c	2002/04/03 06:22:31
@@ -248,19 +248,23 @@ gdk_colormap_new (GdkVisual *visual,
   return colormap;
 }
 
 #define MIN_SYNC_TIME 2
 
+#define lowbit(x) ((x) & (~(x) + 1))
+
 static void
 gdk_colormap_sync (GdkColormap *colormap,
 		   gboolean     force)
 {
   time_t current_time;
   GdkColormapPrivateX11 *private = GDK_COLORMAP_PRIVATE_DATA (colormap);
   XColor *xpalette;
   gint nlookup;
   gint i;
+  unsigned short red, green, blue, red1, green1, blue1;
+  Visual *xvisual;
   
   g_return_if_fail (GDK_IS_COLORMAP (colormap));
 
   current_time = time (NULL);
   if (!force && ((current_time - private->last_sync_time) < MIN_SYNC_TIME))
@@ -268,34 +272,75 @@ gdk_colormap_sync (GdkColormap *colormap
 
   private->last_sync_time = current_time;
 
   nlookup = 0;
   xpalette = g_new (XColor, colormap->size);
-  
-  for (i = 0; i < colormap->size; i++)
-    {
-      if (!private->info || private->info[i].ref_count == 0)
-	{
-	  xpalette[nlookup].pixel = i;
-	  xpalette[nlookup].red = 0;
-	  xpalette[nlookup].green = 0;
-	  xpalette[nlookup].blue = 0;
-	  nlookup++;
-	}
+ 
+  switch (colormap->visual->type ) {
+    case GDK_VISUAL_GRAYSCALE:
+    case GDK_VISUAL_PSEUDO_COLOR:
+    case GDK_VISUAL_STATIC_GRAY:
+    case GDK_VISUAL_STATIC_COLOR:
+      for (i = 0; i < colormap->size; i++)
+      {
+        if (!private->info || private->info[i].ref_count == 0)
+        {
+          xpalette[nlookup].pixel = i;
+          xpalette[nlookup].red = 0;
+          xpalette[nlookup].green = 0;
+          xpalette[nlookup].blue = 0;
+          nlookup++;
+        }
+      }
+      break;
+    case GDK_VISUAL_DIRECT_COLOR:
+    case GDK_VISUAL_TRUE_COLOR:
+      xvisual = ((GdkVisualPrivate*) colormap->visual)->xvisual;
+      nlookup = xvisual->map_entries;
+
+      red = green = blue = 0;
+      red1 = lowbit(xvisual->red_mask);
+      green1 = lowbit(xvisual->green_mask);
+      blue1 = lowbit(xvisual->blue_mask);
+
+      for (i=0; i<nlookup; i++)
+      {
+        xpalette[i].pixel = red|green|blue;
+        xpalette[i].pad = 0;
+        red += red1;
+        if (red > xvisual->red_mask)
+          red = 0;
+          green += green1;
+        if (green > xvisual->green_mask)
+          green = 0;
+          blue += blue1;
+        if (blue > xvisual->blue_mask)
+          blue = 0;
+      } 
     }
   
   XQueryColors (gdk_display, private->xcolormap, xpalette, nlookup);
   
   for (i = 0; i < nlookup; i++)
+  {
+    gulong pixel = xpalette[i].pixel;
+    if ((colormap->visual->type != GDK_VISUAL_DIRECT_COLOR) && (colormap->visual->type != GDK_VISUAL_TRUE_COLOR)) 
     {
-      gulong pixel = xpalette[i].pixel;
       colormap->colors[pixel].pixel = pixel;
       colormap->colors[pixel].red = xpalette[i].red;
       colormap->colors[pixel].green = xpalette[i].green;
       colormap->colors[pixel].blue = xpalette[i].blue;
     }
-  
+    else 
+    {
+      colormap->colors[i].pixel = pixel;
+      colormap->colors[i].red = xpalette[i].red;
+      colormap->colors[i].green = xpalette[i].green;
+      colormap->colors[i].blue = xpalette[i].blue;
+    }
+  }
+ 
   g_free (xpalette);
 }
 		   
 
 GdkColormap*
@@ -329,14 +374,14 @@ gdk_colormap_get_system (void)
 	  private->hash = g_hash_table_new ((GHashFunc) gdk_color_hash,
 					    (GEqualFunc) gdk_color_equal);
 	  /* Fall through */
 	case GDK_VISUAL_STATIC_GRAY:
 	case GDK_VISUAL_STATIC_COLOR:
+	case GDK_VISUAL_DIRECT_COLOR:
 	  colormap->colors = g_new (GdkColor, colormap->size);
 	  gdk_colormap_sync (colormap, TRUE);
 	  
-	case GDK_VISUAL_DIRECT_COLOR:
 	case GDK_VISUAL_TRUE_COLOR:
 	  break;
 	}
 
       gdk_colormap_add (colormap);
