42
static const cairo_user_data_key_t cairo_key;
46
static cairo_surface_t *
47
thunar_gdk_cairo_create_surface (const GdkPixbuf *pixbuf)
56
cairo_format_t format;
57
cairo_surface_t *surface;
62
_thunar_return_val_if_fail (GDK_IS_PIXBUF (pixbuf), NULL);
64
/* get pixbuf information */
65
width = gdk_pixbuf_get_width (pixbuf);
66
height = gdk_pixbuf_get_height (pixbuf);
67
gdk_pixels = gdk_pixbuf_get_pixels (pixbuf);
68
gdk_rowstride = gdk_pixbuf_get_rowstride (pixbuf);
69
n_channels = gdk_pixbuf_get_n_channels (pixbuf);
72
format = CAIRO_FORMAT_RGB24;
74
format = CAIRO_FORMAT_ARGB32;
76
/* prepare pixel data and surface */
77
cairo_stride = cairo_format_stride_for_width (format, width);
78
cairo_pixels = g_malloc (height * cairo_stride);
79
surface = cairo_image_surface_create_for_data (cairo_pixels, format,
80
width, height, cairo_stride);
81
cairo_surface_set_user_data (surface, &cairo_key, cairo_pixels, g_free);
84
if (G_UNLIKELY (n_channels == 3))
86
for (j = height; j; j--)
94
#if G_BYTE_ORDER == G_LITTLE_ENDIAN
107
gdk_pixels += gdk_rowstride;
108
cairo_pixels += cairo_stride;
113
#define MULT(d,c,a) G_STMT_START { guint t = c * a + 0x7f; d = ((t >> 8) + t) >> 8; } G_STMT_END
114
for (j = height; j; j--)
122
#if G_BYTE_ORDER == G_LITTLE_ENDIAN
123
MULT(q[0], p[2], p[3]);
124
MULT(q[1], p[1], p[3]);
125
MULT(q[2], p[0], p[3]);
129
MULT(q[1], p[0], p[3]);
130
MULT(q[2], p[1], p[3]);
131
MULT(q[3], p[2], p[3]);
138
gdk_pixels += gdk_rowstride;
139
cairo_pixels += cairo_stride;
43
150
* thunar_gdk_screen_open:
44
151
* @display_name : a fully qualified display name.
242
* thunar_gdk_cairo_set_source_pixbuf:
243
* cr : a Cairo context
244
* pixbuf : a GdkPixbuf
245
* pixbuf_x : X coordinate of location to place upper left corner of pixbuf
246
* pixbuf_y : Y coordinate of location to place upper left corner of pixbuf
248
* Works like gdk_cairo_set_source_pixbuf but we try to cache the surface
249
* on the pixbuf, which is efficient within Thunar because we also share
250
* the pixbufs using the icon cache.
253
thunar_gdk_cairo_set_source_pixbuf (cairo_t *cr,
258
cairo_surface_t *surface;
259
static GQuark surface_quark = 0;
261
if (G_UNLIKELY (surface_quark == 0))
262
surface_quark = g_quark_from_static_string ("thunar-gdk-surface");
264
/* peek if there is already a surface */
265
surface = g_object_get_qdata (G_OBJECT (pixbuf), surface_quark);
268
/* create a new surface */
269
surface = thunar_gdk_cairo_create_surface (pixbuf);
271
/* store the pixbuf on the pixbuf */
272
g_object_set_qdata_full (G_OBJECT (pixbuf), surface_quark,
273
surface, (GDestroyNotify) cairo_surface_destroy);
277
cairo_set_source_surface (cr, surface, pixbuf_x, pixbuf_y);