35 for (y = 0; y <
height; y++) {
37 guint32 *src = (
void *) src_data;
39 for (x = 0; x <
width; x++) {
40 guint alpha = src[x] >> 24;
43 dest_data[x * 4 + 0] = 0;
44 dest_data[x * 4 + 1] = 0;
45 dest_data[x * 4 + 2] = 0;
47 dest_data[x * 4 + 0] = (((src[x] & 0xff0000) >> 16) * 255 + alpha / 2) / alpha;
48 dest_data[x * 4 + 1] = (((src[x] & 0x00ff00) >> 8) * 255 + alpha / 2) / alpha;
49 dest_data[x * 4 + 2] = (((src[x] & 0x0000ff) >> 0) * 255 + alpha / 2) / alpha;
51 dest_data[x * 4 + 3] = alpha;
54 src_data += src_stride;
55 dest_data += dest_stride;
64 cairo_surface_t *scsurface;
69 pixbuf = gdk_pixbuf_new(GDK_COLORSPACE_RGB,
true, 8, scwidth, scheight);
74 memset(gdk_pixbuf_get_pixels(pixbuf),
76 gdk_pixbuf_get_rowstride(pixbuf) * (
size_t)scheight);
79 cairo_surface_flush(surface);
82 width = cairo_image_surface_get_width(surface);
83 height = cairo_image_surface_get_height(surface);
86 scsurface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, scwidth, scheight);
87 if (cairo_surface_status(scsurface) != CAIRO_STATUS_SUCCESS) {
88 cairo_surface_destroy(scsurface);
89 g_object_unref(pixbuf);
90 NSLOG(netsurf, INFO,
"Surface creation failed");
94 cr = cairo_create(scsurface);
97 cairo_scale(cr, (
double)scwidth /
width, (
double)scheight /
height);
98 cairo_set_source_surface(cr, surface, 0, 0);
104 cairo_pattern_set_extend(cairo_get_source(cr), CAIRO_EXTEND_REFLECT);
107 cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE);
116 gdk_pixbuf_get_rowstride(pixbuf),
117 cairo_image_surface_get_data(scsurface),
118 cairo_image_surface_get_stride(scsurface),
121 cairo_surface_destroy(scsurface);
GdkPixbuf * nsgdk_pixbuf_get_from_surface(cairo_surface_t *surface, int scwidth, int scheight)
obtain a pixbuf of the specified size from a cairo surface.
static void convert_alpha(guchar *dest_data, int dest_stride, guchar *src_data, int src_stride, int width, int height)
GDK support functions for missing interfaces.
#define NSLOG(catname, level, logmsg, args...)
Interface to utility string handling.