+/**
+ * gdk_colormap_query_color:
+ * @colormap: a #GdkColormap
+ * @pixel: pixel value in hardware display format
+ * @result: #GdkColor with red, green, blue fields initialized
+ *
+ * Locates the RGB color in @colormap corresponding to the given
+ * hardware pixel @pixel. @pixel must be a valid pixel in the
+ * colormap; it's a programmer error to call this function with a
+ * pixel which is not in the colormap. Hardware pixels are normally
+ * obtained from gdk_colormap_alloc_colors(), or from a #GdkImage. (A
+ * #GdkImage contains image data in hardware format, a #GdkPixbuf
+ * contains image data in a canonical 24-bit RGB format.)
+ *
+ * This function is rarely useful; it's used for example to
+ * implement the eyedropper feature in #GtkColorSelection.
+ *
+ **/
+void
+gdk_colormap_query_color (GdkColormap *colormap,
+ gulong pixel,
+ GdkColor *result)
+{
+ XColor xcolor;
+ GdkVisual *visual;
+ GdkColormapPrivateX11 *private;
+
+ g_return_if_fail (GDK_IS_COLORMAP (colormap));
+
+ private = GDK_COLORMAP_PRIVATE_DATA (colormap);
+
+ visual = gdk_colormap_get_visual (colormap);
+
+ switch (visual->type) {
+ case GDK_VISUAL_DIRECT_COLOR:
+ case GDK_VISUAL_TRUE_COLOR:
+ result->red = 65535. * (double)((pixel & visual->red_mask) >> visual->red_shift) / ((1 << visual->red_prec) - 1);
+ result->green = 65535. * (double)((pixel & visual->green_mask) >> visual->green_shift) / ((1 << visual->green_prec) - 1);
+ result->blue = 65535. * (double)((pixel & visual->blue_mask) >> visual->blue_shift) / ((1 << visual->blue_prec) - 1);
+ break;
+ case GDK_VISUAL_STATIC_GRAY:
+ case GDK_VISUAL_GRAYSCALE:
+ result->red = result->green = result->blue = 65535. * (double)pixel/((1<<visual->depth) - 1);
+ break;
+ case GDK_VISUAL_STATIC_COLOR:
+ xcolor.pixel = pixel;
+ if (!private->screen->closed)
+ {
+ XQueryColor (GDK_SCREEN_XDISPLAY (private->screen), private->xcolormap, &xcolor);
+ result->red = xcolor.red;
+ result->green = xcolor.green;
+ result->blue = xcolor.blue;
+ }
+ else
+ result->red = result->green = result->blue = 0;
+ break;
+ case GDK_VISUAL_PSEUDO_COLOR:
+ g_return_if_fail (pixel < colormap->size);
+ result->red = colormap->colors[pixel].red;
+ result->green = colormap->colors[pixel].green;
+ result->blue = colormap->colors[pixel].blue;
+ break;
+ default:
+ g_assert_not_reached ();
+ break;
+ }
+}
+
+/**
+ * gdk_color_change:
+ * @colormap: a #GdkColormap.
+ * @color: a #GdkColor, with the color to change
+ * in the <structfield>pixel</structfield> field,
+ * and the new value in the remaining fields.
+ *
+ * Changes the value of a color that has already
+ * been allocated. If @colormap is not a private
+ * colormap, then the color must have been allocated
+ * using gdk_colormap_alloc_colors() with the
+ * @writeable set to %TRUE.
+ *
+ * Return value: %TRUE if the color was successfully changed.
+ **/