ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/rxvt-unicode/src/rxvtimg.C
(Generate patch)

Comparing rxvt-unicode/src/rxvtimg.C (file contents):
Revision 1.19 by root, Tue Jun 5 13:39:26 2012 UTC vs.
Revision 1.42 by root, Thu Jun 7 11:52:26 2012 UTC

2#include "../config.h" 2#include "../config.h"
3#include "rxvt.h" 3#include "rxvt.h"
4 4
5#if HAVE_IMG 5#if HAVE_IMG
6 6
7#define float_to_component(d) ((d) * 65535.99)
8
9rxvt_img::rxvt_img (rxvt_screen *screen, XRenderPictFormat *format, int width, int height) 7rxvt_img::rxvt_img (rxvt_screen *screen, XRenderPictFormat *format, int x, int y, int width, int height, int repeat)
10: s(screen), w(width), h(height), format(format), shared(false) 8: s(screen), x(x), y(y), w(width), h(height), format(format), repeat(repeat),
9 pm(0), ref(0)
11{ 10{
12 pm = XCreatePixmap (s->display->dpy, s->display->root, w, h, format->depth);
13} 11}
14 12
13rxvt_img::rxvt_img (const rxvt_img &img)
14: s(img.s), x(img.x), y(img.y), w(img.w), h(img.h), format(img.format), repeat(img.repeat), pm(img.pm), ref(img.ref)
15{
16 ++ref->cnt;
17}
18
19#if 0
15rxvt_img::rxvt_img (rxvt_screen *screen, XRenderPictFormat *format, int width, int height, Pixmap pixmap) 20rxvt_img::rxvt_img (rxvt_screen *screen, XRenderPictFormat *format, int width, int height, Pixmap pixmap)
16: s(screen), pm(pixmap), w(width), h(height), format(format), shared(false) 21: s(screen), x(0), y(0), w(width), h(height), format(format), repeat(RepeatNormal), shared(false), pm(pixmap)
17{ 22{
23}
24#endif
25
26rxvt_img *
27rxvt_img::new_from_root (rxvt_screen *s)
28{
29 Display *dpy = s->display->dpy;
30 unsigned int root_pm_w, root_pm_h;
31 Pixmap root_pixmap = s->display->get_pixmap_property (s->display->xa[XA_XROOTPMAP_ID]);
32 if (root_pixmap == None)
33 root_pixmap = s->display->get_pixmap_property (s->display->xa[XA_ESETROOT_PMAP_ID]);
34
35 if (root_pixmap == None)
36 return 0;
37
38 Window wdummy;
39 int idummy;
40 unsigned int udummy;
41
42 if (!XGetGeometry (dpy, root_pixmap, &wdummy, &idummy, &idummy, &root_pm_w, &root_pm_h, &udummy, &udummy))
43 return 0;
44
45 rxvt_img *img = new rxvt_img (
46 s,
47 XRenderFindVisualFormat (dpy, DefaultVisual (dpy, s->display->screen)),
48 0,
49 0,
50 root_pm_w,
51 root_pm_h
52 );
53
54 img->pm = root_pixmap;
55 img->ref = new pixref (root_pm_w, root_pm_h);
56 img->ref->ours = false;
57
58 return img;
18} 59}
19 60
20rxvt_img * 61rxvt_img *
21rxvt_img::new_from_file (rxvt_screen *s, const char *filename) 62rxvt_img::new_from_file (rxvt_screen *s, const char *filename)
22{ 63{
27 rxvt_fatal ("rxvt_img::new_from_file: %s\n", err->message); 68 rxvt_fatal ("rxvt_img::new_from_file: %s\n", err->message);
28 69
29 rxvt_img *img = new rxvt_img ( 70 rxvt_img *img = new rxvt_img (
30 s, 71 s,
31 XRenderFindStandardFormat (s->display->dpy, gdk_pixbuf_get_has_alpha (pb) ? PictStandardARGB32 : PictStandardRGB24), 72 XRenderFindStandardFormat (s->display->dpy, gdk_pixbuf_get_has_alpha (pb) ? PictStandardARGB32 : PictStandardRGB24),
73 0,
74 0,
32 gdk_pixbuf_get_width (pb), 75 gdk_pixbuf_get_width (pb),
33 gdk_pixbuf_get_height (pb) 76 gdk_pixbuf_get_height (pb)
34 ); 77 );
35 78 img->alloc ();
36 img->render_pixbuf (pb, 0, 0, img->w, img->h, 0, 0); 79 img->render_pixbuf (pb, 0, 0, img->w, img->h, 0, 0);
37 80
81 g_object_unref (pb);
82
83 return img;
84}
85
86void
87rxvt_img::destroy ()
88{
89 if (--ref->cnt)
38 return img; 90 return;
91
92 if (pm && ref->ours)
93 XFreePixmap (s->display->dpy, pm);
94
95 delete ref;
39} 96}
40 97
41rxvt_img::~rxvt_img () 98rxvt_img::~rxvt_img ()
42{ 99{
43 if (!shared) 100 destroy ();
44 XFreePixmap (s->display->dpy, pm); 101}
102
103void
104rxvt_img::alloc ()
105{
106 pm = XCreatePixmap (s->display->dpy, s->display->root, w, h, format->depth);
107 ref = new pixref (w, h);
108}
109
110Picture
111rxvt_img::src_picture ()
112{
113 Display *dpy = s->display->dpy;
114
115 XRenderPictureAttributes pa;
116 pa.repeat = repeat;
117 Picture pic = XRenderCreatePicture (dpy, pm, format, CPRepeat, &pa);
118
119 return pic;
45} 120}
46 121
47void 122void
48rxvt_img::unshare () 123rxvt_img::unshare ()
49{ 124{
50 if (!shared) 125 if (ref->cnt == 1 && ref->ours)
51 return; 126 return;
52 127
53 rxvt_img *img = clone (); 128 //TODO: maybe should reify instead
129 Pixmap pm2 = XCreatePixmap (s->display->dpy, s->display->root, ref->w, ref->h, format->depth);
130 GC gc = XCreateGC (s->display->dpy, pm, 0, 0);
131 XCopyArea (s->display->dpy, pm, pm2, gc, 0, 0, ref->w, ref->h, 0, 0);
132 XFreeGC (s->display->dpy, gc);
54 133
55 ::swap (pm , img->pm); 134 destroy ();
56 ::swap (shared, img->shared);
57 135
58 delete img; 136 pm = pm2;
137 ref = new pixref (ref->w, ref->h);
59} 138}
60 139
61void 140void
62rxvt_img::fill (const rxvt_color &c) 141rxvt_img::fill (const rxvt_color &c)
63{ 142{
87 166
88 for (int i = 0; i < width; i++) 167 for (int i = 0; i < width; i++)
89 params[i+2] = XDoubleToFixed (kernel[i] / sum); 168 params[i+2] = XDoubleToFixed (kernel[i] / sum);
90} 169}
91 170
92void 171rxvt_img *
93rxvt_img::blur (int rh, int rv) 172rxvt_img::blur (int rh, int rv)
94{ 173{
95 if (!(s->display->flags & DISPLAY_HAS_RENDER_CONV)) 174 if (!(s->display->flags & DISPLAY_HAS_RENDER_CONV))
96 return; 175 return clone ();
97 176
98 Display *dpy = s->display->dpy; 177 Display *dpy = s->display->dpy;
99 int size = max (rh, rv) * 2 + 1; 178 int size = max (rh, rv) * 2 + 1;
100 double *kernel = (double *)malloc (size * sizeof (double)); 179 double *kernel = (double *)malloc (size * sizeof (double));
101 XFixed *params = (XFixed *)malloc ((size + 2) * sizeof (XFixed)); 180 XFixed *params = (XFixed *)malloc ((size + 2) * sizeof (XFixed));
181 rxvt_img *img = new rxvt_img (s, format, x, y, w, h, repeat);
182 img->alloc ();
183
184 Picture src = src_picture ();
102 185
103 XRenderPictureAttributes pa; 186 XRenderPictureAttributes pa;
104
105 pa.repeat = RepeatPad; 187 pa.repeat = RepeatPad;
106 Picture src = XRenderCreatePicture (dpy, pm , format, CPRepeat, &pa); 188 Picture dst = XRenderCreatePicture (dpy, img->pm, format, CPRepeat, &pa);
189
107 Pixmap tmp = XCreatePixmap (dpy, pm, w, h, format->depth); 190 Pixmap tmp_pm = XCreatePixmap (dpy, pm, w, h, format->depth);
108 Picture dst = XRenderCreatePicture (dpy, tmp, format, CPRepeat, &pa); 191 Picture tmp = XRenderCreatePicture (dpy, tmp_pm , format, CPRepeat, &pa);
109 XFreePixmap (dpy, tmp); 192 XFreePixmap (dpy, tmp_pm);
110 193
111 if (kernel && params) 194 if (kernel && params)
112 { 195 {
113 size = rh * 2 + 1; 196 size = rh * 2 + 1;
114 get_gaussian_kernel (rh, size, kernel, params); 197 get_gaussian_kernel (rh, size, kernel, params);
115 198
116 XRenderSetPictureFilter (dpy, src, FilterConvolution, params, size+2); 199 XRenderSetPictureFilter (dpy, src, FilterConvolution, params, size+2);
117 XRenderComposite (dpy, 200 XRenderComposite (dpy,
118 PictOpSrc, 201 PictOpSrc,
119 src, 202 src,
203 None,
204 tmp,
205 0, 0,
206 0, 0,
207 0, 0,
208 w, h);
209
210 size = rv * 2 + 1;
211 get_gaussian_kernel (rv, size, kernel, params);
212 ::swap (params[0], params[1]);
213
214 XRenderSetPictureFilter (dpy, src, FilterConvolution, params, size+2);
215 XRenderComposite (dpy,
216 PictOpSrc,
217 tmp,
120 None, 218 None,
121 dst, 219 dst,
122 0, 0, 220 0, 0,
123 0, 0, 221 0, 0,
124 0, 0, 222 0, 0,
125 w, h); 223 w, h);
126
127 ::swap (src, dst);
128
129 size = rv * 2 + 1;
130 get_gaussian_kernel (rv, size, kernel, params);
131 ::swap (params[0], params[1]);
132
133 XRenderSetPictureFilter (dpy, src, FilterConvolution, params, size+2);
134 XRenderComposite (dpy,
135 PictOpSrc,
136 src,
137 None,
138 dst,
139 0, 0,
140 0, 0,
141 0, 0,
142 w, h);
143 } 224 }
144 225
145 free (kernel); 226 free (kernel);
146 free (params); 227 free (params);
147 XRenderFreePicture (dpy, src); 228 XRenderFreePicture (dpy, src);
148 XRenderFreePicture (dpy, dst); 229 XRenderFreePicture (dpy, dst);
230 XRenderFreePicture (dpy, tmp);
231
232 return img;
149} 233}
150 234
151static Picture 235static Picture
152create_xrender_mask (Display *dpy, Drawable drawable, Bool argb) 236create_xrender_mask (Display *dpy, Drawable drawable, Bool argb)
153{ 237{
162 246
163 return mask; 247 return mask;
164} 248}
165 249
166void 250void
167rxvt_img::brightness (double r, double g, double b, double a) 251rxvt_img::brightness (unsigned short r, unsigned short g, unsigned short b, unsigned short a)
168{ 252{
169 Display *dpy = s->display->dpy; 253 Display *dpy = s->display->dpy;
170 Picture src = create_xrender_mask (dpy, pm, True); 254 Picture src = create_xrender_mask (dpy, pm, True);
171 Picture dst = XRenderCreatePicture (dpy, pm, format, 0, 0); 255 Picture dst = XRenderCreatePicture (dpy, pm, format, 0, 0);
172 256
173 XRenderColor mask_c; 257 XRenderColor mask_c;
174 mask_c.red = float_to_component (r); 258 mask_c.red = r;
175 mask_c.green = float_to_component (g); 259 mask_c.green = g;
176 mask_c.blue = float_to_component (b); 260 mask_c.blue = b;
177 mask_c.alpha = float_to_component (a); 261 mask_c.alpha = a;
178 XRenderFillRectangle (dpy, PictOpSrc, src, &mask_c, 0, 0, 1, 1); 262 XRenderFillRectangle (dpy, PictOpSrc, src, &mask_c, 0, 0, 1, 1);
179 263
180 XRenderComposite (dpy, PictOpAdd, src, None, dst, 0, 0, 0, 0, 0, 0, w, h); 264 XRenderComposite (dpy, PictOpAdd, src, None, dst, 0, 0, 0, 0, 0, 0, w, h);
265
266 XRenderFreePicture (dpy, src);
267 XRenderFreePicture (dpy, dst);
181} 268}
182 269
183void 270void
184rxvt_img::contrast (double r, double g, double b, double a) 271rxvt_img::contrast (unsigned short r, unsigned short g, unsigned short b, unsigned short a)
185{ 272{
186 if (!(s->display->flags & DISPLAY_HAS_RENDER_MUL)) 273 if (!(s->display->flags & DISPLAY_HAS_RENDER_MUL))
187 return; 274 return;
188 275
189 Display *dpy = s->display->dpy; 276 Display *dpy = s->display->dpy;
190 Picture src = create_xrender_mask (dpy, pm, True); 277 Picture src = create_xrender_mask (dpy, pm, True);
191 Picture dst = XRenderCreatePicture (dpy, pm, format, 0, 0); 278 Picture dst = XRenderCreatePicture (dpy, pm, format, 0, 0);
192 279
193 XRenderColor mask_c; 280 XRenderColor mask_c;
194 mask_c.red = float_to_component (r); 281 mask_c.red = r;
195 mask_c.green = float_to_component (g); 282 mask_c.green = g;
196 mask_c.blue = float_to_component (b); 283 mask_c.blue = b;
197 mask_c.alpha = float_to_component (a); 284 mask_c.alpha = a;
198 XRenderFillRectangle (dpy, PictOpSrc, src, &mask_c, 0, 0, 1, 1); 285 XRenderFillRectangle (dpy, PictOpSrc, src, &mask_c, 0, 0, 1, 1);
199 286
200 XRenderComposite (dpy, PictOpMultiply, src, None, dst, 0, 0, 0, 0, 0, 0, w, h); 287 XRenderComposite (dpy, PictOpMultiply, src, None, dst, 0, 0, 0, 0, 0, 0, w, h);
288
289 XRenderFreePicture (dpy, src);
290 XRenderFreePicture (dpy, dst);
201} 291}
202 292
203bool 293bool
204rxvt_img::render_pixbuf (GdkPixbuf *pixbuf, int src_x, int src_y, int width, int height, int dst_x, int dst_y) 294rxvt_img::render_pixbuf (GdkPixbuf *pixbuf, int src_x, int src_y, int width, int height, int dst_x, int dst_y)
205{ 295{
249 339
250 int rowstride = gdk_pixbuf_get_rowstride (pixbuf); 340 int rowstride = gdk_pixbuf_get_rowstride (pixbuf);
251 int channels = gdk_pixbuf_get_n_channels (pixbuf); 341 int channels = gdk_pixbuf_get_n_channels (pixbuf);
252 unsigned char *row = gdk_pixbuf_get_pixels (pixbuf) + src_y * rowstride + src_x * channels; 342 unsigned char *row = gdk_pixbuf_get_pixels (pixbuf) + src_y * rowstride + src_x * channels;
253 char *line = ximage->data; 343 char *line = ximage->data;
254
255 rgba c (0, 0, 0);
256
257 if (channels == 4 && alpha_mask == 0)
258 {
259 //pix_colors[Color_bg].get (c);
260 //TODO
261 c.r = 0xffff; c.g = 0xc0c0; c.b = 0xcbcb;//D
262 c.r >>= 8;
263 c.g >>= 8;
264 c.b >>= 8;
265 }
266 344
267 for (int y = 0; y < height; y++) 345 for (int y = 0; y < height; y++)
268 { 346 {
269 for (int x = 0; x < width; x++) 347 for (int x = 0; x < width; x++)
270 { 348 {
273 unsigned char r, g, b, a; 351 unsigned char r, g, b, a;
274 352
275 if (channels == 4) 353 if (channels == 4)
276 { 354 {
277 a = pixel[3]; 355 a = pixel[3];
278 r = (pixel[0] * a + c.r * (0xff - a)) / 0xff; 356 r = pixel[0] * a / 0xff;
279 g = (pixel[1] * a + c.g * (0xff - a)) / 0xff; 357 g = pixel[1] * a / 0xff;
280 b = (pixel[2] * a + c.b * (0xff - a)) / 0xff; 358 b = pixel[2] * a / 0xff;
281 } 359 }
282 else 360 else
283 { 361 {
284 a = 0xff; 362 a = 0xff;
285 r = pixel[0]; 363 r = pixel[0];
310} 388}
311 389
312rxvt_img * 390rxvt_img *
313rxvt_img::clone () 391rxvt_img::clone ()
314{ 392{
315 rxvt_img *img = new rxvt_img (s, format, w, h); 393 return new rxvt_img (*this);
316
317 GC gc = XCreateGC (s->display->dpy, pm, 0, 0);
318 XCopyArea (s->display->dpy, pm, img->pm, gc, 0, 0, w, h, 0, 0);
319 XFreeGC (s->display->dpy, gc);
320} 394}
321 395
322rxvt_img * 396rxvt_img *
323rxvt_img::sub_rect (int x, int y, int width, int height, int repeat) 397rxvt_img::reify ()
324{ 398{
325 rxvt_img *img = new rxvt_img (s, format, width, height); 399 if (x == 0 && y == 0 && w == ref->w && h == ref->h)
400 return clone ();
326 401
327 Display *dpy = s->display->dpy; 402 Display *dpy = s->display->dpy;
328 XRenderPictureAttributes pa; 403
329 pa.repeat = repeat; 404 bool alpha = !format->direct.alphaMask
330 Picture src = XRenderCreatePicture (dpy, pm, format, CPRepeat, &pa); 405 && (x || y)
406 && repeat == RepeatNone;
407
408 rxvt_img *img = new rxvt_img (s, alpha ? XRenderFindStandardFormat (dpy, PictStandardARGB32) : format, 0, 0, w, h, repeat);
409 img->alloc ();
410
411 Picture src = src_picture ();
331 Picture dst = XRenderCreatePicture (dpy, img->pm, img->format, 0, 0); 412 Picture dst = XRenderCreatePicture (dpy, img->pm, img->format, 0, 0);
332 413
414 if (alpha)
415 {
416 XRenderColor rc = { 0, 0, 0, 0 };
417 XRenderFillRectangle (dpy, PictOpSrc, dst, &rc, 0, 0, w, h);
418 XRenderComposite (dpy, PictOpSrc, src, None, dst, 0, 0, 0, 0, -x, -y, ref->w, ref->h);
419 }
420 else
333 XRenderComposite (dpy, PictOpSrc, src, None, dst, x, y, 0, 0, 0, 0, width, height); 421 XRenderComposite (dpy, PictOpSrc, src, None, dst, x, y, 0, 0, 0, 0, w, h);
334 422
335 XRenderFreePicture (dpy, src);
336 XRenderFreePicture (dpy, dst); 423 XRenderFreePicture (dpy, src);
424 XRenderFreePicture (dpy, dst);
337 425
338 return img; 426 return img;
339} 427}
340 428
341rxvt_img * 429rxvt_img *
430rxvt_img::sub_rect (int x, int y, int width, int height)
431{
432 rxvt_img *img = clone ();
433
434 img->x += x;
435 img->y += y;
436
437 if (w != width || h != height)
438 {
439 img->w = width;
440 img->h = height;
441
442 rxvt_img *img2 = img->reify ();
443 delete img;
444 img = img2;
445 }
446
447 return img;
448}
449
450rxvt_img *
342rxvt_img::transform (int new_width, int new_height, double matrix[9], int repeat) 451rxvt_img::transform (int new_width, int new_height, double matrix[9])
343{ 452{
344 rxvt_img *img = new rxvt_img (s, format, new_width, new_height); 453 rxvt_img *img = new rxvt_img (s, format, 0, 0, new_width, new_height, repeat);
454 img->alloc ();
345 455
346 Display *dpy = s->display->dpy; 456 Display *dpy = s->display->dpy;
347 XRenderPictureAttributes pa; 457 Picture src = src_picture ();
348 pa.repeat = repeat;
349 Picture src = XRenderCreatePicture (dpy, pm, format, CPRepeat, &pa);
350 Picture dst = XRenderCreatePicture (dpy, img->pm, img->format, 0, 0); 458 Picture dst = XRenderCreatePicture (dpy, img->pm, img->format, 0, 0);
351 459
352 XTransform xfrm; 460 XTransform xfrm;
353 461
354 for (int i = 0; i < 3; ++i) 462 for (int i = 0; i < 3; ++i)
355 for (int j = 0; j < 3; ++j) 463 for (int j = 0; j < 3; ++j)
356 xfrm.matrix [i][j] = XDoubleToFixed (matrix [i * 3 + j]); 464 xfrm.matrix [i][j] = XDoubleToFixed (matrix [i * 3 + j]);
465
466 xfrm.matrix [0][2] += XDoubleToFixed (x);//TODO
467 xfrm.matrix [0][3] += XDoubleToFixed (y);
357 468
358 XRenderSetPictureFilter (dpy, src, "good", 0, 0); 469 XRenderSetPictureFilter (dpy, src, "good", 0, 0);
359 XRenderSetPictureTransform (dpy, src, &xfrm); 470 XRenderSetPictureTransform (dpy, src, &xfrm);
360 XRenderComposite (dpy, PictOpSrc, src, None, dst, 0, 0, 0, 0, 0, 0, new_width, new_height); 471 XRenderComposite (dpy, PictOpSrc, src, None, dst, 0, 0, 0, 0, 0, 0, new_width, new_height);
361 472
372 w / (double)new_width, 0, 0, 483 w / (double)new_width, 0, 0,
373 0, h / (double)new_height, 0, 484 0, h / (double)new_height, 0,
374 0, 0, 1 485 0, 0, 1
375 }; 486 };
376 487
488 int old_repeat_mode = repeat;
489 repeat = RepeatPad; // not right, but xrender can't proeprly scale it seems
490
377 return transform (new_width, new_height, matrix); 491 rxvt_img *img = transform (new_width, new_height, matrix);
378}
379 492
493 repeat = old_repeat_mode;
494 img->repeat = repeat;
495
496 return img;
497}
498
380rxvt_img * 499rxvt_img *
381rxvt_img::rotate (int new_width, int new_height, int x, int y, double phi, int repeat) 500rxvt_img::rotate (int new_width, int new_height, int x, int y, double phi)
382{ 501{
383 double s = sin (phi); 502 double s = sin (phi);
384 double c = cos (phi); 503 double c = cos (phi);
385 504
386 double matrix[9] = { 505 double matrix[9] = {
387 c, -s, -c * x + s * y + x, 506 c, -s, -c * x + s * y + x,
388 s, c, -s * x - c * y + y, 507 s, c, -s * x - c * y + y,
389 0, 0, 1 508 0, 0, 1
390 }; 509 };
391 510
392 return transform (new_width, new_height, matrix, repeat); 511 return transform (new_width, new_height, matrix);
393} 512}
394 513
395rxvt_img * 514rxvt_img *
396rxvt_img::convert_to (XRenderPictFormat *new_format) 515rxvt_img::convert_to (XRenderPictFormat *new_format, const rxvt_color &bg)
397{ 516{
517 if (new_format == format)
518 return clone ();
519
398 rxvt_img *img = new rxvt_img (s, new_format, w, h); 520 rxvt_img *img = new rxvt_img (s, new_format, 0, 0, w, h, repeat);
521 img->alloc ();
399 522
523 printf ("convert %d to %d\n", format->direct.alphaMask, new_format->direct.alphaMask);//D
524
400 Display *dpy = s->display->dpy; 525 Display *dpy = s->display->dpy;
401 Picture src = XRenderCreatePicture (dpy, pm, format, 0, 0); 526 Picture src = src_picture ();
402 Picture dst = XRenderCreatePicture (dpy, img->pm, new_format, 0, 0); 527 Picture dst = XRenderCreatePicture (dpy, img->pm, new_format, 0, 0);
528 int op = PictOpSrc;
403 529
530 if (format->direct.alphaMask && !new_format->direct.alphaMask)
531 {
532 // does it have to be that complicated
533 rgba c;
534 bg.get (c);
535
536 XRenderColor rc = { c.r, c.g, c.b, 0xffff };
537 XRenderFillRectangle (dpy, PictOpSrc, dst, &rc, 0, 0, w, h);
538
539 op = PictOpOver;
540 }
541
404 XRenderComposite (dpy, PictOpSrc, src, None, dst, 0, 0, 0, 0, 0, 0, w, h); 542 XRenderComposite (dpy, op, src, None, dst, 0, 0, 0, 0, 0, 0, w, h);
405 543
406 XRenderFreePicture (dpy, src);
407 XRenderFreePicture (dpy, dst); 544 XRenderFreePicture (dpy, src);
545 XRenderFreePicture (dpy, dst);
408 546
547 return img;
548}
549
550rxvt_img *
551rxvt_img::blend (rxvt_img *img, double factor)
552{
553 rxvt_img *img2 = clone ();
554 Display *dpy = s->display->dpy;
555 Picture src = img->src_picture ();
556 Picture dst = XRenderCreatePicture (dpy, img2->pm, img2->format, 0, 0);
557 Picture mask = create_xrender_mask (dpy, img->pm, False);
558
559 XRenderColor mask_c;
560
561 mask_c.alpha = float_to_component (factor);
562 mask_c.red =
563 mask_c.green =
564 mask_c.blue = 0;
565 XRenderFillRectangle (dpy, PictOpSrc, mask, &mask_c, 0, 0, 1, 1);
566
567 XRenderComposite (dpy, PictOpOver, src, mask, dst, 0, 0, 0, 0, 0, 0, w, h);
568
569 XRenderFreePicture (dpy, src);
570 XRenderFreePicture (dpy, dst);
571 XRenderFreePicture (dpy, mask);
572
409 return img; 573 return img2;
410} 574}
411 575
412#endif 576#endif
413 577

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines