colormap on TRUECOLOR visual.



Hello, ...

i did a small graphical toolkit using gtk+, and wrapping the gdk_draw stuff.

I had a function that get the color associated with a pixel of an image.

i do a :

	cmap = gdk_colormap_get_system ();

and later, i allocate a color to the colormap with :

	GdkColor *col;
	col = malloc(GdkColor);
	col->red=65535;
	col->green=col->blue=0;
	gdk_colormap_alloc_color (cmap, col, FALSE, TRUE)
	gdk_gc_set_foreground (gc, col);


and draw with it onto a pixmap with :

	gdk_draw_point (pixmap, gc, x, y);

When i want to get the color of a given pixel of the pixmap, i do the
following:

	GdkColor *getted_col;
	img = gdk_image_get (pixmap, 0, 0, x+1, y+1);
	pixel = gdk_image_get_pixel (img, x, y);
	getted_col = cmap->colors[pixel];

This worked fine on my sun ultra1 under solaris, who had pseudo color visuals,
but now that i have a linux box with a G400, i have truecolor visuals (at
least that is what fbset tells me) and the colors field of the colormap is
null, and thus i get a nice segfault when accesing  cmap->colors[pixel].

This is very disturbing.

I understand that in a truecolor visual, the color is written directly to the
pixmap, and thus i think that the pixel returned is directly the color wanted,
or something similar (a white pixel gives me 16777215 and a red one gives me
16711680).

Did i understand things correctly, and is this normal behavior (since
truecolor visual don't have colormaps) and in this case should there not be
some kind of function for getting the color associated with a given pixel ?
something like :

GdkColor *gdk_colormap_get_color (GdkColormap *colormap, guint pixel);

Or am i supposed to check in which kind of visual i am and handle this stuff
myself ? I don't think this would be correct to do.

or maybe did i understand all wrong what is going on here ? In which case,
what is the correct way of doing things ?

Friendly,

Sven LUTHER



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