Re: Any RGB macro in Gtk?



Googled and found a macro...

#define  RGB(R,G,B) {(R<<16)|(G<<8)|B,(R*65535)/255,(G*65535)/255,(B*65535)/255}

I have tried it with a handful of rgb values and it works (used gtk_widget_modify_bg to change the surface colour of some dialogs), like

 GdkColor col = RGB(0,0,255);
 gtk_widget_modify_bg ( dlg , GTK_STATE_NORMAL , &col );
 

A few changes were needed to my api. For example, on Windows I returned colorrefs as int function values. That is not possible for GdkColor structs, so I changed the api to return a COLORREF parameter instead with   

typedef GdkColor COLORREF;   // for Gtk
typedef int COLORREF;        // for Windows

 
It works, but I still don't understand colours...

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?

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?
 




--- 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



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