Re: Sigsegv when attempting to access a color struct value.



"Ian King" <king eiffel com> writes:

> I have the following code that works perfectly when running locally, but
> fails when run as a remote client (when using the same pixmap).  Can anyone
> help?
> 
> This is approximate what my code is doing, ignore any incorrect casting as I
> am using a wrapper library in Eiffel to access gtk c external functions.
> 
> 
> 1) a_gdkimage = gdk_image_get (a_gtk_pixmap, 0, 0, width, height);
> 2) a_colormap = gdk_colormap_get_system ();
> 3) a_pixel = gdk_image_get_pixel (a_gdkimage, 0, 0);
> 4) a_color = (a_colormap->colors) + (a_pixel * sizeof (GdkColor));
> 
> The value of  'a_pixel'  is 16777215.  When I try to access the red value
> from the returned color (line 4), I receive a segmentation violation signal,
> but only if the client is ran remotely.  Is it anything to do with getting
> the gdkimage from the pixmap?
> 
> Thanks for your time.

colormap->colors[] is only useful for pseudo-color displays.
You may find this function from GTK+-2.0 useful.

Regards,
                                        Owen

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]