mirror of
https://github.com/brl/mutter.git
synced 2024-11-25 09:30:45 -05:00
Add support for "colorize" image attribute.
2002-02-07 Anders Carlsson <andersca@gnu.org> * src/theme-parser.c: (parse_draw_op_element): Add support for "colorize" image attribute. * src/theme.c: (colorize_pixbuf): New function that colorizes a pixbuf. (pos_tokenize): Allow "\n" as a whitespace character. (meta_draw_op_free): Free colorize_spec; (draw_op_as_pixbuf): Colorize image if needed. * src/theme.h: Add colorize_spec to struct.
This commit is contained in:
parent
7279f2a9cd
commit
f33a46072b
16
ChangeLog
16
ChangeLog
@ -1,3 +1,19 @@
|
|||||||
|
2002-02-07 Anders Carlsson <andersca@gnu.org>
|
||||||
|
|
||||||
|
* src/theme-parser.c: (parse_draw_op_element):
|
||||||
|
Add support for "colorize" image attribute.
|
||||||
|
|
||||||
|
* src/theme.c: (colorize_pixbuf):
|
||||||
|
New function that colorizes a pixbuf.
|
||||||
|
|
||||||
|
(pos_tokenize): Allow "\n" as a whitespace character.
|
||||||
|
|
||||||
|
(meta_draw_op_free): Free colorize_spec;
|
||||||
|
|
||||||
|
(draw_op_as_pixbuf): Colorize image if needed.
|
||||||
|
|
||||||
|
* src/theme.h: Add colorize_spec to struct.
|
||||||
|
|
||||||
2002-02-07 Anders Carlsson <andersca@gnu.org>
|
2002-02-07 Anders Carlsson <andersca@gnu.org>
|
||||||
|
|
||||||
* src/themes/Crux/metacity-theme-1.xml: Add maximized and
|
* src/themes/Crux/metacity-theme-1.xml: Add maximized and
|
||||||
|
@ -1991,14 +1991,17 @@ parse_draw_op_element (GMarkupParseContext *context,
|
|||||||
const char *width;
|
const char *width;
|
||||||
const char *height;
|
const char *height;
|
||||||
const char *alpha;
|
const char *alpha;
|
||||||
|
const char *colorize;
|
||||||
double alpha_val;
|
double alpha_val;
|
||||||
GdkPixbuf *pixbuf;
|
GdkPixbuf *pixbuf;
|
||||||
|
MetaColorSpec *colorize_spec = NULL;
|
||||||
|
|
||||||
if (!locate_attributes (context, element_name, attribute_names, attribute_values,
|
if (!locate_attributes (context, element_name, attribute_names, attribute_values,
|
||||||
error,
|
error,
|
||||||
"x", &x, "y", &y,
|
"x", &x, "y", &y,
|
||||||
"width", &width, "height", &height,
|
"width", &width, "height", &height,
|
||||||
"alpha", &alpha, "filename", &filename,
|
"alpha", &alpha, "filename", &filename,
|
||||||
|
"colorize", &colorize,
|
||||||
NULL))
|
NULL))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@ -2064,9 +2067,21 @@ parse_draw_op_element (GMarkupParseContext *context,
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (colorize)
|
||||||
|
{
|
||||||
|
colorize_spec = meta_color_spec_new_from_string (colorize, error);
|
||||||
|
|
||||||
|
if (colorize == NULL)
|
||||||
|
{
|
||||||
|
add_context_to_error (error, context);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
op = meta_draw_op_new (META_DRAW_IMAGE);
|
op = meta_draw_op_new (META_DRAW_IMAGE);
|
||||||
|
|
||||||
op->data.image.pixbuf = pixbuf;
|
op->data.image.pixbuf = pixbuf;
|
||||||
|
op->data.image.colorize_spec = colorize_spec;
|
||||||
op->data.image.x = optimize_expression (info->theme, x);
|
op->data.image.x = optimize_expression (info->theme, x);
|
||||||
op->data.image.y = optimize_expression (info->theme, y);
|
op->data.image.y = optimize_expression (info->theme, y);
|
||||||
op->data.image.width = optimize_expression (info->theme, width);
|
op->data.image.width = optimize_expression (info->theme, width);
|
||||||
|
65
src/theme.c
65
src/theme.c
@ -42,6 +42,48 @@
|
|||||||
#define ALPHA_TO_UCHAR(d) ((unsigned char) ((d) * 255))
|
#define ALPHA_TO_UCHAR(d) ((unsigned char) ((d) * 255))
|
||||||
|
|
||||||
#define DEBUG_FILL_STRUCT(s) memset ((s), 0xef, sizeof (*(s)))
|
#define DEBUG_FILL_STRUCT(s) memset ((s), 0xef, sizeof (*(s)))
|
||||||
|
#define INTENSITY(r, g, b) (r * 0.30 + g * 0.59 + b * 0.11)
|
||||||
|
|
||||||
|
static GdkPixbuf *
|
||||||
|
colorize_pixbuf (GdkPixbuf *orig, GdkColor *new_color)
|
||||||
|
{
|
||||||
|
GdkPixbuf *pixbuf;
|
||||||
|
double intensity;
|
||||||
|
int x, y;
|
||||||
|
guchar r, g, b;
|
||||||
|
guchar *src, *dest;
|
||||||
|
|
||||||
|
r = new_color->red / 256;
|
||||||
|
g = new_color->green / 256;
|
||||||
|
b = new_color->blue / 256;
|
||||||
|
|
||||||
|
pixbuf = gdk_pixbuf_new (gdk_pixbuf_get_colorspace (orig), gdk_pixbuf_get_has_alpha (orig),
|
||||||
|
gdk_pixbuf_get_bits_per_sample (orig),
|
||||||
|
gdk_pixbuf_get_width (orig), gdk_pixbuf_get_height (orig));
|
||||||
|
|
||||||
|
for (y = 0; y < gdk_pixbuf_get_height (pixbuf); y++)
|
||||||
|
{
|
||||||
|
src = gdk_pixbuf_get_pixels (orig) + y * gdk_pixbuf_get_rowstride (orig);
|
||||||
|
dest = gdk_pixbuf_get_pixels (pixbuf) + y * gdk_pixbuf_get_rowstride (pixbuf);
|
||||||
|
|
||||||
|
for (x = 0; x < gdk_pixbuf_get_width (pixbuf); x++) {
|
||||||
|
|
||||||
|
intensity = INTENSITY (src[0], src[1], src[2]) / 255.0;
|
||||||
|
|
||||||
|
dest[0] = (guchar)(r * intensity);
|
||||||
|
dest[1] = g * intensity;
|
||||||
|
dest[2] = b * intensity;
|
||||||
|
|
||||||
|
if (gdk_pixbuf_get_has_alpha (orig))
|
||||||
|
dest[3] = src[3];
|
||||||
|
|
||||||
|
src += gdk_pixbuf_get_has_alpha (orig) ? 4 : 3;
|
||||||
|
dest += gdk_pixbuf_get_has_alpha (pixbuf) ? 4 : 3;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return pixbuf;
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
color_composite (const GdkColor *bg,
|
color_composite (const GdkColor *bg,
|
||||||
@ -1088,6 +1130,7 @@ pos_tokenize (const char *expr,
|
|||||||
|
|
||||||
case ' ':
|
case ' ':
|
||||||
case '\t':
|
case '\t':
|
||||||
|
case '\n':
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
@ -2106,6 +2149,8 @@ meta_draw_op_free (MetaDrawOp *op)
|
|||||||
case META_DRAW_IMAGE:
|
case META_DRAW_IMAGE:
|
||||||
if (op->data.image.pixbuf)
|
if (op->data.image.pixbuf)
|
||||||
g_object_unref (G_OBJECT (op->data.image.pixbuf));
|
g_object_unref (G_OBJECT (op->data.image.pixbuf));
|
||||||
|
if (op->data.image.colorize_spec)
|
||||||
|
meta_color_spec_free (op->data.image.colorize_spec);
|
||||||
g_free (op->data.image.x);
|
g_free (op->data.image.x);
|
||||||
g_free (op->data.image.y);
|
g_free (op->data.image.y);
|
||||||
g_free (op->data.image.width);
|
g_free (op->data.image.width);
|
||||||
@ -2395,14 +2440,32 @@ draw_op_as_pixbuf (const MetaDrawOp *op,
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
|
||||||
case META_DRAW_IMAGE:
|
case META_DRAW_IMAGE:
|
||||||
|
{
|
||||||
|
if (op->data.image.colorize_spec)
|
||||||
|
{
|
||||||
|
GdkPixbuf *tmp_pixbuf;
|
||||||
|
GdkColor color;
|
||||||
|
|
||||||
|
meta_color_spec_render (op->data.image.colorize_spec,
|
||||||
|
widget, &color);
|
||||||
|
tmp_pixbuf = colorize_pixbuf (op->data.image.pixbuf,
|
||||||
|
&color);
|
||||||
|
|
||||||
|
pixbuf = scale_and_alpha_pixbuf (tmp_pixbuf,
|
||||||
|
op->data.image.alpha,
|
||||||
|
width, height);
|
||||||
|
g_object_unref (tmp_pixbuf);
|
||||||
|
}
|
||||||
|
else
|
||||||
{
|
{
|
||||||
pixbuf = scale_and_alpha_pixbuf (op->data.image.pixbuf,
|
pixbuf = scale_and_alpha_pixbuf (op->data.image.pixbuf,
|
||||||
op->data.image.alpha,
|
op->data.image.alpha,
|
||||||
width, height);
|
width, height);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
case META_DRAW_GTK_ARROW:
|
case META_DRAW_GTK_ARROW:
|
||||||
case META_DRAW_GTK_BOX:
|
case META_DRAW_GTK_BOX:
|
||||||
|
@ -253,6 +253,7 @@ struct _MetaDrawOp
|
|||||||
} gradient;
|
} gradient;
|
||||||
|
|
||||||
struct {
|
struct {
|
||||||
|
MetaColorSpec *colorize_spec;
|
||||||
GdkPixbuf *pixbuf;
|
GdkPixbuf *pixbuf;
|
||||||
double alpha;
|
double alpha;
|
||||||
char *x;
|
char *x;
|
||||||
|
Loading…
Reference in New Issue
Block a user