[gnome-control-center] um-user: Use GdkCairo operations to draw on the pixbuf
- From: Jasper St. Pierre <jstpierre src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-control-center] um-user: Use GdkCairo operations to draw on the pixbuf
- Date: Wed, 22 Aug 2012 06:36:02 +0000 (UTC)
commit eaef6e5d50140fd7ff9803f79c71e6ccfca18838
Author: Jasper St. Pierre <jstpierre mecheye net>
Date: Tue Aug 14 17:14:10 2012 -0300
um-user: Use GdkCairo operations to draw on the pixbuf
Remove a bunch of bit twiddling code.
https://bugzilla.gnome.org/show_bug.cgi?id=682391
panels/user-accounts/um-user.c | 139 +--------------------------------------
1 files changed, 4 insertions(+), 135 deletions(-)
---
diff --git a/panels/user-accounts/um-user.c b/panels/user-accounts/um-user.c
index 479b132..3b84cae 100644
--- a/panels/user-accounts/um-user.c
+++ b/panels/user-accounts/um-user.c
@@ -381,119 +381,6 @@ check_user_file (const char *filename,
return TRUE;
}
-static cairo_surface_t *
-surface_from_pixbuf (GdkPixbuf *pixbuf)
-{
- cairo_surface_t *surface;
- cairo_t *cr;
-
- surface = cairo_image_surface_create (gdk_pixbuf_get_has_alpha (pixbuf) ?
- CAIRO_FORMAT_ARGB32 : CAIRO_FORMAT_RGB24,
- gdk_pixbuf_get_width (pixbuf),
- gdk_pixbuf_get_height (pixbuf));
- cr = cairo_create (surface);
- gdk_cairo_set_source_pixbuf (cr, pixbuf, 0, 0);
- cairo_paint (cr);
- cairo_destroy (cr);
-
- return surface;
-}
-
-/**
- * go_cairo_convert_data_to_pixbuf:
- * @src: a pointer to pixel data in cairo format
- * @dst: a pointer to pixel data in pixbuf format
- * @width: image width
- * @height: image height
- * @rowstride: data rowstride
- *
- * Converts the pixel data stored in @src in CAIRO_FORMAT_ARGB32 cairo format
- * to GDK_COLORSPACE_RGB pixbuf format and move them
- * to @dst. If @src == @dst, pixel are converted in place.
- **/
-
-static void
-go_cairo_convert_data_to_pixbuf (unsigned char *dst,
- unsigned char const *src,
- int width,
- int height,
- int rowstride)
-{
- int i,j;
- unsigned int t;
- unsigned char a, b, c;
-
- g_return_if_fail (dst != NULL);
-
-#define MULT(d,c,a,t) G_STMT_START { t = (a)? c * 255 / a: 0; d = t;} G_STMT_END
-
- if (src == dst || src == NULL) {
- for (i = 0; i < height; i++) {
- for (j = 0; j < width; j++) {
-#if G_BYTE_ORDER == G_LITTLE_ENDIAN
- MULT(a, dst[2], dst[3], t);
- MULT(b, dst[1], dst[3], t);
- MULT(c, dst[0], dst[3], t);
- dst[0] = a;
- dst[1] = b;
- dst[2] = c;
-#else
- MULT(a, dst[1], dst[0], t);
- MULT(b, dst[2], dst[0], t);
- MULT(c, dst[3], dst[0], t);
- dst[3] = dst[0];
- dst[0] = a;
- dst[1] = b;
- dst[2] = c;
-#endif
- dst += 4;
- }
- dst += rowstride - width * 4;
- }
- } else {
- for (i = 0; i < height; i++) {
- for (j = 0; j < width; j++) {
-#if G_BYTE_ORDER == G_LITTLE_ENDIAN
- MULT(dst[0], src[2], src[3], t);
- MULT(dst[1], src[1], src[3], t);
- MULT(dst[2], src[0], src[3], t);
- dst[3] = src[3];
-#else
- MULT(dst[0], src[1], src[0], t);
- MULT(dst[1], src[2], src[0], t);
- MULT(dst[2], src[3], src[0], t);
- dst[3] = src[0];
-#endif
- src += 4;
- dst += 4;
- }
- src += rowstride - width * 4;
- dst += rowstride - width * 4;
- }
- }
-#undef MULT
-}
-
-static void
-cairo_to_pixbuf (guint8 *src_data,
- GdkPixbuf *dst_pixbuf)
-{
- unsigned char *src;
- unsigned char *dst;
- guint w;
- guint h;
- guint rowstride;
-
- w = gdk_pixbuf_get_width (dst_pixbuf);
- h = gdk_pixbuf_get_height (dst_pixbuf);
- rowstride = gdk_pixbuf_get_rowstride (dst_pixbuf);
-
- dst = gdk_pixbuf_get_pixels (dst_pixbuf);
- src = src_data;
-
- go_cairo_convert_data_to_pixbuf (dst, src, w, h, rowstride);
-}
-
static GdkPixbuf *
frame_pixbuf (GdkPixbuf *source)
{
@@ -502,10 +389,8 @@ frame_pixbuf (GdkPixbuf *source)
cairo_surface_t *surface;
guint w;
guint h;
- guint rowstride;
int frame_width;
double radius;
- guint8 *data;
frame_width = 2;
@@ -513,21 +398,8 @@ frame_pixbuf (GdkPixbuf *source)
h = gdk_pixbuf_get_height (source) + frame_width * 2;
radius = w / 10;
- dest = gdk_pixbuf_new (GDK_COLORSPACE_RGB,
- TRUE,
- 8,
- w,
- h);
- rowstride = gdk_pixbuf_get_rowstride (dest);
-
-
- data = g_new0 (guint8, h * rowstride);
-
- surface = cairo_image_surface_create_for_data (data,
- CAIRO_FORMAT_ARGB32,
- w,
- h,
- rowstride);
+ surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32,
+ w, h);
cr = cairo_create (surface);
cairo_surface_destroy (surface);
@@ -540,15 +412,12 @@ frame_pixbuf (GdkPixbuf *source)
cairo_set_source_rgba (cr, 0.5, 0.5, 0.5, 0.3);
cairo_fill_preserve (cr);
- surface = surface_from_pixbuf (source);
- cairo_set_source_surface (cr, surface, frame_width, frame_width);
+ gdk_cairo_set_source_pixbuf (cr, source, frame_width, frame_width);
cairo_fill (cr);
- cairo_surface_destroy (surface);
- cairo_to_pixbuf (data, dest);
+ dest = gdk_pixbuf_get_from_surface (surface, 0, 0, w, h);
cairo_destroy (cr);
- g_free (data);
return dest;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]