diff options
author | Chris Wilson <chris@chris-wilson.co.uk> | 2011-07-02 13:53:10 +0100 |
---|---|---|
committer | Chris Wilson <chris@chris-wilson.co.uk> | 2011-07-02 13:53:10 +0100 |
commit | 3e9ed76f78cbe62193adf1fc5dd6b3a165ca8a91 (patch) | |
tree | 4b338131de68b04dccddff0eb3a98e08dda5f70e /spiral-demo.c | |
parent | 42c4abee1677ed1109ac4c5f02de731ecda5b696 (diff) |
Share the common gdk-pixbuf to cairo_image_surface routine
Diffstat (limited to 'spiral-demo.c')
-rw-r--r-- | spiral-demo.c | 79 |
1 files changed, 0 insertions, 79 deletions
diff --git a/spiral-demo.c b/spiral-demo.c index 8fe7ff9..b6977c6 100644 --- a/spiral-demo.c +++ b/spiral-demo.c @@ -7,7 +7,6 @@ #include <string.h> #include <math.h> -#include <gdk-pixbuf/gdk-pixbuf.h> #include "demo.h" static struct source{ @@ -59,84 +58,6 @@ fps_draw (cairo_t *cr, const char *name, cairo_show_text (cr, buf); } -static cairo_surface_t * -_cairo_image_surface_create_from_pixbuf(const GdkPixbuf *pixbuf) -{ - gint width = gdk_pixbuf_get_width (pixbuf); - gint height = gdk_pixbuf_get_height (pixbuf); - guchar *gdk_pixels = gdk_pixbuf_get_pixels (pixbuf); - int gdk_rowstride = gdk_pixbuf_get_rowstride (pixbuf); - int n_channels = gdk_pixbuf_get_n_channels (pixbuf); - int cairo_stride; - guchar *cairo_pixels; - cairo_format_t format; - cairo_surface_t *surface; - int j; - - if (n_channels == 3) - format = CAIRO_FORMAT_RGB24; - else - format = CAIRO_FORMAT_ARGB32; - - surface = cairo_image_surface_create(format, width, height); - if (cairo_surface_status(surface)) - return surface; - - cairo_stride = cairo_image_surface_get_stride (surface); - cairo_pixels = cairo_image_surface_get_data(surface); - - for (j = height; j; j--) { - guchar *p = gdk_pixels; - guchar *q = cairo_pixels; - - if (n_channels == 3) { - guchar *end = p + 3 * width; - - while (p < end) { -#if G_BYTE_ORDER == G_LITTLE_ENDIAN - q[0] = p[2]; - q[1] = p[1]; - q[2] = p[0]; -#else - q[1] = p[0]; - q[2] = p[1]; - q[3] = p[2]; -#endif - p += 3; - q += 4; - } - } else { - guchar *end = p + 4 * width; - guint t1,t2,t3; - -#define MULT(d,c,a,t) G_STMT_START { t = c * a + 0x7f; d = ((t >> 8) + t) >> 8; } G_STMT_END - - while (p < end) { -#if G_BYTE_ORDER == G_LITTLE_ENDIAN - MULT(q[0], p[2], p[3], t1); - MULT(q[1], p[1], p[3], t2); - MULT(q[2], p[0], p[3], t3); - q[3] = p[3]; -#else - q[0] = p[3]; - MULT(q[1], p[0], p[3], t1); - MULT(q[2], p[1], p[3], t2); - MULT(q[3], p[2], p[3], t3); -#endif - - p += 4; - q += 4; - } -#undef MULT - } - - gdk_pixels += gdk_rowstride; - cairo_pixels += cairo_stride; - } - - return surface; -} - static int load_sources_file(const char *filename, cairo_surface_t *target) { GdkPixbuf *pb; |