Re: Any RGB macro in Gtk?



Paul,

Thanks for your info. It made me recall some Xlib graphics info that I collected some years ago but never read including this tutorial: 

http://users.actcom.co.il/~choo/lupg/tutorials/xlib-programming/xlib-programming-2.html#color

which is great and provide some answers to questions Q1 to Q4.

Below is an attempt to answer my own questions using the info from the tutorial. Please confirm, add, modify or refute.


Q1. the pixel component of the GdkColor struct is (R<<16)|(G<<8)|B, but is the other way around in the Windows RGB macro R|(G<<16)|(B<<16). I am puzzled by this. I am also puzzled by the pixel value being 32 bits (r,g,b,alpha) while the combined size of the r,g,b intensities is 48. Why is this?

A colormap is a palette, i.e. a lookup table of colours. 0 is the index of the first colour and 1 is the index of the second and so on. The pixel component of the GdkColor is the index into the list of colours defined for the palette and the r,g and b components describe the full colour at a palette index. The index for the RGB macro is a 24-bit int built by shifting the byte-wide r,g and b components..
I am guessing Xlib and Windows put the colours into the palettes in different order and that accounts for the difference in building the index for the RGB macros. True?
    

Q2. while googling I came across this for GdkColor: 'the programmer provides the r,g and b intensities and GDK fills in the pixel component.' When does GDK do this? By what functions?

By functions gdk_colormap_alloc_colors () and gdk_colormap_alloc_color ()
and gdk_parse_color().


Q3. I have tried reading about Colormaps and Colors in the GDK reference manual, but I am getting stuck on the basics. For example in the Description what does this mean: 'A colormap is an object that contains the mapping between the color values stored in memory and the RGB values that are used to display color values. In general, colormaps only contain significant information for pseudo-color visuals, but even for other visual types, a colormap object is required in some circumstances.' Does it mean 'a colormap is a list of GdkColors like a palette'?  Is the RGB value mentioned in the description the pixel component in the GdkColor?

This description is not very helpful to someone with gtk background only. People with Xlib colour knowledge would understand it of course and would probably not need it.


Q4. For GdkColor the manual says 'the GdkColor structure is used to describe an allocated or unallocated color'. What does allocated and unallocated color mean?

'allocated' means there is a full colour defined for an index of the lookup palette. 'unallocated' means there is no colour yet or that the full colour value has been removed from the palette index by gdk_colormap_free_colors.





--- On Sun, 15/8/10, Paul Davis <paul linuxaudiosystems com> wrote:

From: Paul Davis <paul linuxaudiosystems com>
Subject: Re: Any RGB macro in Gtk?
To: "Ken Resander" <kresander yahoo com>
Cc: gtk-list gnome org
Date: Sunday, 15 August, 2010, 10:48 PM



On Sat, Aug 14, 2010 at 8:38 AM, Ken Resander <kresander yahoo com> wrote:


 
Q2. while googling I came across this for GdkColor: 'the programmer provides the r,g and b intensities and GDK fills in the pixel component.' When does GDK do this? By what functions?

Q3. I have tried reading about Colormaps and Colors in the GDK reference manual, but I am getting stuck on the basics. For example in the Description what does this mean: 'A colormap is an object that contains the mapping between the color values stored in memory and the RGB values that are used to display color values. In general, colormaps only contain significant information for pseudo-color visuals, but even for other visual types, a colormap object is required in some circumstances.' Does it mean 'a colormap is a list of GdkColors like a palette'?  Is the RGB value mentioned in the description the pixel component in the GdkColor?

Q4. For GdkColor the manual says 'the GdkColor structure is used to describe an allocated or unallocated color'. What does allocated and unallocated color mean?

Q5. The Colormaps and Colors Reference contains several functions, but I did not use any of them. It still worked with the colours coming out the way I expected. When are these functions used/needed? Or are they becoming obsolete?


they are not obsolete, but they represent a deeper "model" of how color rendering works on a framebuffer display than most developers will ever need. its generally just fine for you to think in terms of "i need a red color, so i'll create it, and then use that to draw with". this actually is not what happens deeper in the graphics stack, and because X Window (the first platform that GDK was written on) tends to expose these "deeper" concepts, they've shown up in GDK too.

there are some places where the difference between "i need red, so i'll create it and use it" and what actually happens does matter, but if you only write applications with GTK and don't tend to hack on GTK itself, you will probably need to worry about them.

--p

 
 




--- On Fri, 13/8/10, Ken Resander <kresander yahoo com> wrote:

From: Ken Resander <kresander yahoo com>
Subject: Any RGB macro in Gtk?
To: gtk-list gnome org
Date: Friday, 13 August, 2010, 6:48 PM


I would like to port some Windows programs to Ubuntu+Gtk. These contain several large colour lookup tables using the Windows RGB macro. For example:

static COLALTINFO safealts [ NUMCOLITEMS ]
   =
   {
   { RGB(0xF0,0xF8,0xFF),RGB(0xFF,0xFF,0xFF) ,RGB(0x00,0x00,0x00) },
   { RGB(0xFA,0xEB,0xD7),RGB(0xFF,0xFF,0xCC) ,RGB(0x00,0x00,0x00) },
   ....

I have not done any drawing yet with Gtk and don't know how colours work, but there are thousands of RGB macro calls and it would very tedious and error prone if I have to change them manually. I really don't want to touch the RGB colour values in the lookup tables, but I probably would have change the COLALTINFO definition to match the way Gtk represents colour.

Is there a RGB macro in Gtk/Gdk, or can such macro be written?
 
P.S.
The Windows RGB macro builds a 24-bit int constant (COLORREF).
and is defined as follows:

#define RGB(r, g ,b)  ((DWORD) (((BYTE) (r) | \
                      ((WORD) (g) << 8)) | \
                      (((DWORD) (BYTE) (b)) << 16)))



-----Inline Attachment Follows-----


_______________________________________________
gtk-list mailing list
gtk-list gnome org
http://mail.gnome.org/mailman/listinfo/gtk-list


_______________________________________________
gtk-list mailing list
gtk-list gnome org
http://mail.gnome.org/mailman/listinfo/gtk-list





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