Re: GdkColor and GdkGC question
- From: Havoc Pennington <hp redhat com>
- To: Andrei Zmievski <andrei ispi net>
- Cc: gtk-list gnome org
- Subject: Re: GdkColor and GdkGC question
- Date: 23 Feb 2001 11:57:33 -0500
Andrei Zmievski <andrei ispi net> writes:
>
> When I do gdk_gc_get_values() to retrieve the GC values, the
> 'foreground' value which is a GdkColor, for example, only has pixel
> member set properly - red, green, and blue are not. What is the proper
> way to obtain RGB values for a certain pixel value?
>
>From GTK 2, can cut-and-paste into GTK 1.2 as far as I see, but have
to include gdk/gdkx.h.
void
gdk_colormap_query_color (GdkColormap *colormap,
gulong pixel,
GdkColor *result)
{
XColor xcolor;
GdkVisual *visual;
g_return_if_fail (GDK_IS_COLORMAP (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;
XQueryColor (GDK_DISPLAY (), GDK_COLORMAP_XCOLORMAP (colormap),
&xcolor);
result->red = xcolor.red;
result->green = xcolor.green;
result->blue = xcolor.blue;
break;
case GDK_VISUAL_PSEUDO_COLOR:
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;
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]