Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.unix.programmer > #1012 > unrolled thread

X11: Get red, green and blue values from a pixel value

Started bytm <thomas.mertes@gmx.at>
First post2011-07-24 13:02 -0700
Last post2011-07-25 13:20 +0100
Articles 3 — 3 participants

Back to article view | Back to comp.unix.programmer


Contents

  X11: Get red, green and blue values from a pixel value tm <thomas.mertes@gmx.at> - 2011-07-24 13:02 -0700
    Re: X11: Get red, green and blue values from a pixel value pacman@kosh.dhis.org (Alan Curry) - 2011-07-25 01:09 +0000
      Re: X11: Get red, green and blue values from a pixel value Nobody <nobody@nowhere.com> - 2011-07-25 13:20 +0100

#1012 — X11: Get red, green and blue values from a pixel value

Fromtm <thomas.mertes@gmx.at>
Date2011-07-24 13:02 -0700
SubjectX11: Get red, green and blue values from a pixel value
Message-ID<45ec449a-9e02-451b-8d4e-6ad67d13afd0@g16g2000yqg.googlegroups.com>
Hello,

after retrieving a pixel from a window with XGetImage and
XGetPixel (I know of the bad performance, of getting single
pixels), I need to get the red, green and blue values of that
pixel. In other words: I want to define the function:

  void drwPixelToRgb (long int pixel, unsigned int *red_val,
      unsigned int *green_val, unsigned int *blue_val);

which should take the pixel and fill *red_val, *green_val and
*blue_val.

I have a solution when a TrueColor system is used.
I determine the color system with:

  mydisplay = XOpenDisplay("");
  myscreen = DefaultScreen(mydisplay);
  default_visual = XDefaultVisual(mydisplay, myscreen);
  if (default_visual->c_class == TrueColor) {
    ...

In case of a TrueColor system I use a strategy based on
red_mask, green_mask and blue_mask of the default_visual
to determine red_value, green_value and blue_value.

But I have no idea to get red_value, green_value and
blue_value for other color systems.

Many thanks in advance.


Greetings Thomas Mertes

--
Seed7 Homepage:  http://seed7.sourceforge.net
Seed7 - The extensible programming language: User defined statements
and operators, abstract data types, templates without special
syntax, OO with interfaces and multiple dispatch, statically typed,
interpreted or compiled, portable, runs under linux/unix/windows.

[toc] | [next] | [standalone]


#1017

Frompacman@kosh.dhis.org (Alan Curry)
Date2011-07-25 01:09 +0000
Message-ID<j0ifob$j50$1@speranza.aioe.org>
In reply to#1012
In article <45ec449a-9e02-451b-8d4e-6ad67d13afd0@g16g2000yqg.googlegroups.com>,
tm  <thomas.mertes@gmx.at> wrote:
>Hello,
>
>after retrieving a pixel from a window with XGetImage and
>XGetPixel (I know of the bad performance, of getting single
>pixels), I need to get the red, green and blue values of that
>pixel. In other words: I want to define the function:
>
>  void drwPixelToRgb (long int pixel, unsigned int *red_val,
>      unsigned int *green_val, unsigned int *blue_val);
>
[...]
>
>In case of a TrueColor system I use a strategy based on
>red_mask, green_mask and blue_mask of the default_visual
>to determine red_value, green_value and blue_value.
>
>But I have no idea to get red_value, green_value and
>blue_value for other color systems.

The mask fields that you're using with TrueColor also apply to DirectColor.
With DirectColor there is an extra layer of indirection but I'm not sure how
to use it or whether anyone ever does. All the code I've found treats it
exactly the same as TrueColor.

For the others, use XQueryColor. XQueryColors if you need a lot of them in a
single burst.

-- 
Alan Curry

[toc] | [prev] | [next] | [standalone]


#1023

FromNobody <nobody@nowhere.com>
Date2011-07-25 13:20 +0100
Message-ID<pan.2011.07.25.12.20.28.412000@nowhere.com>
In reply to#1017
On Mon, 25 Jul 2011 01:09:31 +0000, Alan Curry wrote:

>>But I have no idea to get red_value, green_value and
>>blue_value for other color systems.
> 
> The mask fields that you're using with TrueColor also apply to DirectColor.
> With DirectColor there is an extra layer of indirection but I'm not sure how
> to use it or whether anyone ever does. All the code I've found treats it
> exactly the same as TrueColor.

DirectColor is the bastard child of PseudoColor and TrueColor.

Like PseudoColor, it relies upon a palette (Colormap). Like TrueColor,
each pixel value is composed of distinct red, green and blue components.
Each component is used as an index into the palette, and the corresponding
component from the palette entry is used as the intensity for that
component. So the palette is essentially 3 separate intensity ramps, one
for each component.

When faced with a DirectColor visual, most code either gives up or creates
an "identity" palette, e.g.:

	Colormap colormap = XCreateColormap(dpy, win, visual, AllocAll);
	int n = 1 << visinfo->bits_per_rgb;
	for (i = 0; i < n; i++){
	    XColor color;
	    color.pixel = i;
	    color.red = color.green = color.blue = i * 0xFFFF / (n - 1);
	    color.flags = DoRed | DoGreen | DoBlue; XStoreColor(dpy, colormap,
	    color);
	}
	XSetWindowColormap(dpy, win, colormap);

From then on, it can treat DirectColor like TrueColor.

[toc] | [prev] | [standalone]


Back to top | Article view | comp.unix.programmer


csiph-web