Index: layersel/layersel.c =================================================================== --- layersel/layersel.c (revision 8498) +++ layersel/layersel.c (revision 8499) @@ -57,13 +57,22 @@ p[3] = a; \ } while(0) -static GtkWidget *test_pixbuf_pixel_manipulated(int filled) +static guint hex2bin_(char c) { + if ((c >= '0') && (c <= '9')) return c - '0'; + if ((c >= 'a') && (c <= 'z')) return c - 'a' + 10; + if ((c >= 'A') && (c <= 'Z')) return c - 'A' + 10; + return 0; /* syntax error... */ +} + +#define hex2bin(str) ((hex2bin_((str)[0])) << 4 | hex2bin_((str)[1])) + +static GtkWidget *test_pixbuf_pixel_manipulated(int filled, const char *rgb) +{ GdkPixbuf *pixbuf; GtkWidget *image; gint width, height, max_height; guchar *pixels; - guint32 color = 0x00ff00ff; /* Green */ guint r, g, b, a; guint w; guchar *p; @@ -72,11 +81,12 @@ width = gdk_pixbuf_get_width(pixbuf); /* 16 here, obviously */ max_height = height = gdk_pixbuf_get_height(pixbuf); pixels = gdk_pixbuf_get_pixels(pixbuf); + /* Fill the whole rectangle with color */ - r = (color & 0xff000000) >> 24; - g = (color & 0x00ff0000) >> 16; - b = (color & 0x0000ff00) >> 8; - a = (color & 0x000000ff); + r = hex2bin(rgb+1); + g = hex2bin(rgb+3); + b = hex2bin(rgb+5); + a = 0xff; while (height--) { w = width; @@ -123,10 +133,10 @@ gtk_container_add(GTK_CONTAINER(event_box), label); g_signal_connect(event_box, "button-press-event", G_CALLBACK(group_button_press_cb), NULL); - image = test_pixbuf_pixel_manipulated(0); + image = test_pixbuf_pixel_manipulated(0, "#ff0000"); gtk_box_pack_start(GTK_BOX(box), image, FALSE, FALSE, 0); gtk_box_pack_start(GTK_BOX(box), gtk_vseparator_new(), FALSE, FALSE, 2); - image = test_pixbuf_pixel_manipulated(1); + image = test_pixbuf_pixel_manipulated(1, "#00ff00"); gtk_box_pack_start(GTK_BOX(box), image, FALSE, FALSE, 0); label = gtk_label_new("layer_1"); gtk_box_pack_start(GTK_BOX(box), label, FALSE, FALSE, 0);