diff options
author | marha <marha@users.sourceforge.net> | 2012-12-10 08:33:13 +0100 |
---|---|---|
committer | marha <marha@users.sourceforge.net> | 2012-12-10 08:33:13 +0100 |
commit | 0328076efb5ff6e62152c09e38d0d11f7931d07b (patch) | |
tree | ce71cf0fe95186671dc75862c2ced47f4735214f /pixman/demos/gtk-utils.c | |
parent | e82692e521240c5f8592f9ce56c9d5b3d68870ec (diff) | |
download | vcxsrv-0328076efb5ff6e62152c09e38d0d11f7931d07b.tar.gz vcxsrv-0328076efb5ff6e62152c09e38d0d11f7931d07b.tar.bz2 vcxsrv-0328076efb5ff6e62152c09e38d0d11f7931d07b.zip |
fontconfig libX11 mesa pixman git update 10 dec 2012
libX11 9833489e6c3829a1e835bc0a11f028fc180809e4
mesa 17f5dc57306b8f5079304701e455bf4b927d3cae
pixman 8ca4e144724ba2041bc5ef077ccf6d24e7cf4d1f
fontconfig 608c5b590bd3428dfcd30f3d68ee8b7131e2f019
Diffstat (limited to 'pixman/demos/gtk-utils.c')
-rw-r--r-- | pixman/demos/gtk-utils.c | 66 |
1 files changed, 66 insertions, 0 deletions
diff --git a/pixman/demos/gtk-utils.c b/pixman/demos/gtk-utils.c index 8291a1ed2..d7e946ded 100644 --- a/pixman/demos/gtk-utils.c +++ b/pixman/demos/gtk-utils.c @@ -3,6 +3,72 @@ #include "../test/utils.h" #include "gtk-utils.h" +pixman_image_t * +pixman_image_from_file (const char *filename, pixman_format_code_t format) +{ + GdkPixbuf *pixbuf; + pixman_image_t *image; + int width, height; + uint32_t *data, *d; + uint8_t *gdk_data; + int n_channels; + int j, i; + int stride; + + if (!(pixbuf = gdk_pixbuf_new_from_file (filename, NULL))) + return NULL; + + image = NULL; + + width = gdk_pixbuf_get_width (pixbuf); + height = gdk_pixbuf_get_height (pixbuf); + n_channels = gdk_pixbuf_get_n_channels (pixbuf); + gdk_data = gdk_pixbuf_get_pixels (pixbuf); + stride = gdk_pixbuf_get_rowstride (pixbuf); + + if (!(data = malloc (width * height * sizeof (uint32_t)))) + goto out; + + d = data; + for (j = 0; j < height; ++j) + { + uint8_t *gdk_line = gdk_data; + + for (i = 0; i < width; ++i) + { + int r, g, b, a; + uint32_t pixel; + + r = gdk_line[0]; + g = gdk_line[1]; + b = gdk_line[2]; + + if (n_channels == 4) + a = gdk_line[3]; + else + a = 0xff; + + r = (r * a + 127) / 255; + g = (g * a + 127) / 255; + b = (b * a + 127) / 255; + + pixel = (a << 24) | (r << 16) | (g << 8) | b; + + *d++ = pixel; + gdk_line += n_channels; + } + + gdk_data += stride; + } + + image = pixman_image_create_bits ( + format, width, height, data, width * 4); + +out: + g_object_unref (pixbuf); + return image; +} + GdkPixbuf * pixbuf_from_argb32 (uint32_t *bits, int width, |