I am writing a GTK+
application that is using Pango
text attributes to determine the color and other aspects of the text written onto a GtkLabel
using something like this:
attributes = pango_attr_list_new();
pango_attr_list_insert(attributes, pango_attr_foreground_new( G_MAXUINT16, G_MAXUINT16, G_MAXUINT16));
pango_attr_list_insert(attributes, pango_attr_size_new (18 * PANGO_SCALE));
pango_attr_list_insert(attributes, pango_attr_weight_new( PANGO_WEIGHT_BOLD ));
lblTotalCredits = gtk_label_new(NULL);
gtk_label_set_text(GTK_LABEL(lblTotalCredits),"0");
gtk_label_set_attributes(GTK_LABEL(lblTotalCredits), attributes);
pango_attr_foreground_new()
expects each color component ( R,G,B ) to by 16 bits. Using Photoshop or other image processing tools I can find the color I want to use, but the R,G,B values are displayed as 8 bit R,G,B components.
How do I convert the 8 bit R,G,B values to the equivalent 16 bit R,G,B values so I end up with the same color?
For example, a golden color is specified as RGB ( 229, 202, 115 ) or hex e5ca73. How do I convert that so that each color component is 16 bits for pango
functions?
8bit max: 0xFF
16bit max: 0xFFFF
convert (I use red as a demo) (untested):
guint32 colorhex = 0xe5ca73;
const guint8 red8 = (guint8)((colorhex & 0xFF0000) >> 16);
// guint16 red16 = (guint16)(((guint32)(r * 0xFFFF / 0xFF)) & 0xFFFF);
guint16 red16 = ((guint16)red8 << 8) | red8;