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.74 by root, Sat Jun 9 19:20:04 2012 UTC vs.
Revision 1.84 by root, Thu Jun 14 18:19:11 2012 UTC

1#include <math.h> 1#include <math.h>
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
7static XRenderPictFormat *
8find_alpha_format_for (Display *dpy, XRenderPictFormat *format)
9{
10 if (format->direct.alphaMask)
11 return format; // already has alpha
12
13 // try to find a suitable alpha format, one bit alpha is enough for our purposes
14 if (format->type == PictTypeDirect)
15 for (int n = 0; XRenderPictFormat *f = XRenderFindFormat (dpy, 0, 0, n); ++n)
16 if (f->direct.alphaMask
17 && f->type == PictTypeDirect
18 && ecb_popcount32 (f->direct.redMask ) >= ecb_popcount32 (format->direct.redMask )
19 && ecb_popcount32 (f->direct.greenMask) >= ecb_popcount32 (format->direct.greenMask)
20 && ecb_popcount32 (f->direct.blueMask ) >= ecb_popcount32 (format->direct.blueMask ))
21 return f;
22
23 // should be a very good fallback
24 return XRenderFindStandardFormat (dpy, PictStandardARGB32);
25}
6 26
7rxvt_img::rxvt_img (rxvt_screen *screen, XRenderPictFormat *format, int x, int y, int width, int height, int repeat) 27rxvt_img::rxvt_img (rxvt_screen *screen, XRenderPictFormat *format, int x, int y, int width, int height, int repeat)
8: s(screen), x(x), y(y), w(width), h(height), format(format), repeat(repeat), 28: s(screen), x(x), y(y), w(width), h(height), format(format), repeat(repeat),
9 pm(0), ref(0) 29 pm(0), ref(0)
10{ 30{
50 70
51 return img; 71 return img;
52} 72}
53 73
54# if HAVE_PIXBUF 74# if HAVE_PIXBUF
75
55rxvt_img * 76rxvt_img *
56rxvt_img::new_from_pixbuf (rxvt_screen *s, GdkPixbuf *pb) 77rxvt_img::new_from_pixbuf (rxvt_screen *s, GdkPixbuf *pb)
57{ 78{
58 Display *dpy = s->display->dpy; 79 Display *dpy = s->display->dpy;
59 80
63 if (width > 32767 || height > 32767) // well, we *could* upload in chunks 84 if (width > 32767 || height > 32767) // well, we *could* upload in chunks
64 rxvt_fatal ("rxvt_img::new_from_pixbuf: image too big (maximum size 32768x32768).\n"); 85 rxvt_fatal ("rxvt_img::new_from_pixbuf: image too big (maximum size 32768x32768).\n");
65 86
66 // since we require rgb24/argb32 formats from xrender we assume 87 // since we require rgb24/argb32 formats from xrender we assume
67 // that both 24 and 32 bpp MUST be supported by any screen that supports xrender 88 // that both 24 and 32 bpp MUST be supported by any screen that supports xrender
68 int depth = gdk_pixbuf_get_has_alpha (pb) ? 32 : 24;
69 89
70 int byte_order = ecb_big_endian () ? MSBFirst : LSBFirst; 90 int byte_order = ecb_big_endian () ? MSBFirst : LSBFirst;
71 91
72 XImage xi; 92 XImage xi;
73 93
77 xi.format = ZPixmap; 97 xi.format = ZPixmap;
78 xi.byte_order = ImageByteOrder (dpy); 98 xi.byte_order = ImageByteOrder (dpy);
79 xi.bitmap_unit = 0; //XY only, unused 99 xi.bitmap_unit = 0; //XY only, unused
80 xi.bitmap_bit_order = 0; //XY only, unused 100 xi.bitmap_bit_order = 0; //XY only, unused
81 xi.bitmap_pad = BitmapPad (dpy); 101 xi.bitmap_pad = BitmapPad (dpy);
82 xi.depth = depth; 102 xi.depth = 32;
83 xi.bytes_per_line = 0; 103 xi.bytes_per_line = 0;
84 xi.bits_per_pixel = 32; //Z only 104 xi.bits_per_pixel = 32; //Z only
85 xi.red_mask = 0x00000000; //Z only, unused 105 xi.red_mask = 0x00000000; //Z only, unused
86 xi.green_mask = 0x00000000; //Z only, unused 106 xi.green_mask = 0x00000000; //Z only, unused
87 xi.blue_mask = 0x00000000; //Z only, unused 107 xi.blue_mask = 0x00000000; //Z only, unused
96 rxvt_fatal ("rxvt_img::new_from_pixbuf: image too big for Xlib.\n"); 116 rxvt_fatal ("rxvt_img::new_from_pixbuf: image too big for Xlib.\n");
97 117
98 xi.data = (char *)rxvt_malloc (height * xi.bytes_per_line); 118 xi.data = (char *)rxvt_malloc (height * xi.bytes_per_line);
99 119
100 int rowstride = gdk_pixbuf_get_rowstride (pb); 120 int rowstride = gdk_pixbuf_get_rowstride (pb);
101 121 bool pb_has_alpha = gdk_pixbuf_get_has_alpha (pb);
102 assert (3 + (depth == 32) == gdk_pixbuf_get_n_channels (pb));
103 unsigned char *row = gdk_pixbuf_get_pixels (pb); 122 unsigned char *row = gdk_pixbuf_get_pixels (pb);
123
104 char *line = xi.data; 124 char *line = xi.data;
105 125
106 for (int y = 0; y < height; y++) 126 for (int y = 0; y < height; y++)
107 { 127 {
108 unsigned char *src = row; 128 unsigned char *src = row;
109 uint32_t *dst = (uint32_t *)line; 129 uint32_t *dst = (uint32_t *)line;
110 130
111 if (depth == 24) 131 if (!pb_has_alpha)
112 for (int x = 0; x < width; x++) 132 for (int x = 0; x < width; x++)
113 { 133 {
114 uint8_t r = *src++; 134 uint8_t r = *src++;
115 uint8_t g = *src++; 135 uint8_t g = *src++;
116 uint8_t b = *src++; 136 uint8_t b = *src++;
117 137
118 uint32_t v = (r << 16) | (g << 8) | b; 138 uint32_t v = (255 << 24) | (r << 16) | (g << 8) | b;
119 139
120 if (ecb_big_endian () ? !byte_order_mismatch : byte_order_mismatch) 140 if (ecb_big_endian () ? !byte_order_mismatch : byte_order_mismatch)
121 v = ecb_bswap32 (v); 141 v = ecb_bswap32 (v);
122 142
123 *dst++ = v; 143 *dst++ = v;
140 160
141 row += rowstride; 161 row += rowstride;
142 line += xi.bytes_per_line; 162 line += xi.bytes_per_line;
143 } 163 }
144 164
145 rxvt_img *img = new rxvt_img (s, XRenderFindStandardFormat (dpy, depth == 24 ? PictStandardRGB24 : PictStandardARGB32), 0, 0, width, height); 165 rxvt_img *img = new rxvt_img (s, XRenderFindStandardFormat (dpy, PictStandardARGB32), 0, 0, width, height);
146 img->alloc (); 166 img->alloc ();
147 167
148 GC gc = XCreateGC (dpy, img->pm, 0, 0); 168 GC gc = XCreateGC (dpy, img->pm, 0, 0);
149 XPutImage (dpy, img->pm, gc, &xi, 0, 0, 0, 0, width, height); 169 XPutImage (dpy, img->pm, gc, &xi, 0, 0, 0, 0, width, height);
150 XFreeGC (dpy, gc); 170 XFreeGC (dpy, gc);
167 187
168 g_object_unref (pb); 188 g_object_unref (pb);
169 189
170 return img; 190 return img;
171} 191}
192
172# endif 193# endif
173 194
174void 195void
175rxvt_img::destroy () 196rxvt_img::destroy ()
176{ 197{
223 pm = pm2; 244 pm = pm2;
224 ref = new pixref (ref->w, ref->h); 245 ref = new pixref (ref->w, ref->h);
225} 246}
226 247
227void 248void
228rxvt_img::fill (const rxvt_color &c) 249rxvt_img::fill (const rgba &c)
229{ 250{
230 XGCValues gcv; 251 XRenderColor rc = { c.r, c.g, c.b, c.a };
231 gcv.foreground = c; 252
232 GC gc = XCreateGC (s->display->dpy, pm, GCForeground, &gcv); 253 Display *dpy = s->display->dpy;
233 XFillRectangle (s->display->dpy, pm, gc, 0, 0, w, h); 254 Picture src = src_picture ();
234 XFreeGC (s->display->dpy, gc); 255 XRenderFillRectangle (dpy, PictOpSrc, src, &rc, 0, 0, w, h);
256 XRenderFreePicture (dpy, src);
257}
258
259void
260rxvt_img::add_alpha ()
261{
262 if (format->direct.alphaMask)
263 return;
264
265 Display *dpy = s->display->dpy;
266
267 rxvt_img *img = new rxvt_img (s, find_alpha_format_for (dpy, format), x, y, w, h, repeat);
268 img->alloc ();
269
270 Picture src = src_picture ();
271 Picture dst = XRenderCreatePicture (dpy, img->pm, img->format, 0, 0);
272
273 XRenderComposite (dpy, PictOpSrc, src, None, dst, 0, 0, 0, 0, 0, 0, w, h);
274
275 XRenderFreePicture (dpy, src);
276 XRenderFreePicture (dpy, dst);
277
278 ::swap (img->ref, ref);
279 ::swap (img->pm , pm );
280
281 delete img;
235} 282}
236 283
237static void 284static void
238get_gaussian_kernel (int radius, int width, double *kernel, XFixed *params) 285get_gaussian_kernel (int radius, int width, rxvt_img::nv *kernel, XFixed *params)
239{ 286{
240 double sigma = radius / 2.0; 287 rxvt_img::nv sigma = radius / 2.0;
241 double scale = sqrt (2.0 * M_PI) * sigma; 288 rxvt_img::nv scale = sqrt (2.0 * M_PI) * sigma;
242 double sum = 0.0; 289 rxvt_img::nv sum = 0.0;
243 290
244 for (int i = 0; i < width; i++) 291 for (int i = 0; i < width; i++)
245 { 292 {
246 double x = i - width / 2; 293 rxvt_img::nv x = i - width / 2;
247 kernel[i] = exp (-(x * x) / (2.0 * sigma * sigma)) / scale; 294 kernel[i] = exp (-(x * x) / (2.0 * sigma * sigma)) / scale;
248 sum += kernel[i]; 295 sum += kernel[i];
249 } 296 }
250 297
251 params[0] = XDoubleToFixed (width); 298 params[0] = XDoubleToFixed (width);
261 if (!(s->display->flags & DISPLAY_HAS_RENDER_CONV)) 308 if (!(s->display->flags & DISPLAY_HAS_RENDER_CONV))
262 return clone (); 309 return clone ();
263 310
264 Display *dpy = s->display->dpy; 311 Display *dpy = s->display->dpy;
265 int size = max (rh, rv) * 2 + 1; 312 int size = max (rh, rv) * 2 + 1;
266 double *kernel = (double *)malloc (size * sizeof (double)); 313 nv *kernel = (nv *)malloc (size * sizeof (nv));
267 XFixed *params = (XFixed *)malloc ((size + 2) * sizeof (XFixed)); 314 XFixed *params = (XFixed *)malloc ((size + 2) * sizeof (XFixed));
268 rxvt_img *img = new rxvt_img (s, format, x, y, w, h, repeat); 315 rxvt_img *img = new rxvt_img (s, format, x, y, w, h, repeat);
269 img->alloc (); 316 img->alloc ();
270 317
271 XRenderPictureAttributes pa; 318 XRenderPictureAttributes pa;
309 w, h); 356 w, h);
310 } 357 }
311 358
312 free (kernel); 359 free (kernel);
313 free (params); 360 free (params);
361
314 XRenderFreePicture (dpy, src); 362 XRenderFreePicture (dpy, src);
315 XRenderFreePicture (dpy, dst); 363 XRenderFreePicture (dpy, dst);
316 XRenderFreePicture (dpy, tmp); 364 XRenderFreePicture (dpy, tmp);
317 365
318 return img; 366 return img;
319} 367}
320 368
321static Picture 369static Picture
322create_xrender_mask (Display *dpy, Drawable drawable, Bool argb) 370create_xrender_mask (Display *dpy, Drawable drawable, Bool argb, Bool component_alpha)
323{ 371{
324 Pixmap pixmap = XCreatePixmap (dpy, drawable, 1, 1, argb ? 32 : 8); 372 Pixmap pixmap = XCreatePixmap (dpy, drawable, 1, 1, argb ? 32 : 8);
325 373
326 XRenderPictFormat *format = XRenderFindStandardFormat (dpy, argb ? PictStandardARGB32 : PictStandardA8); 374 XRenderPictFormat *format = XRenderFindStandardFormat (dpy, argb ? PictStandardARGB32 : PictStandardA8);
327 XRenderPictureAttributes pa; 375 XRenderPictureAttributes pa;
328 pa.repeat = RepeatNormal; 376 pa.repeat = RepeatNormal;
377 pa.component_alpha = component_alpha;
329 Picture mask = XRenderCreatePicture (dpy, pixmap, format, CPRepeat, &pa); 378 Picture mask = XRenderCreatePicture (dpy, pixmap, format, CPRepeat | CPComponentAlpha, &pa);
330 379
331 XFreePixmap (dpy, pixmap); 380 XFreePixmap (dpy, pixmap);
332 381
333 return mask; 382 return mask;
334} 383}
391 if (r < 0 || g < 0 || b < 0 || a < 0) 440 if (r < 0 || g < 0 || b < 0 || a < 0)
392 rxvt_fatal ("rxvt_img::contrast does not support negative values.\n"); 441 rxvt_fatal ("rxvt_img::contrast does not support negative values.\n");
393 442
394 rxvt_img *img = new rxvt_img (s, format, x, y, w, h, repeat); 443 rxvt_img *img = new rxvt_img (s, format, x, y, w, h, repeat);
395 img->alloc (); 444 img->alloc ();
396 445 img->fill (rgba (0, 0, 0, 0));
397 {
398 rxvt_color empty;
399 empty.set (s, rgba (0, 0, 0, 0));
400 img->fill (empty);
401 }
402 446
403 // premultiply (yeah, these are not exact, sue me or fix it) 447 // premultiply (yeah, these are not exact, sue me or fix it)
404 r = (r * (a >> 8)) >> 8; 448 r = (r * (a >> 8)) >> 8;
405 g = (g * (a >> 8)) >> 8; 449 g = (g * (a >> 8)) >> 8;
406 b = (b * (a >> 8)) >> 8; 450 b = (b * (a >> 8)) >> 8;
407 451
408 Display *dpy = s->display->dpy; 452 Display *dpy = s->display->dpy;
409 453
410 Picture src = src_picture (); 454 Picture src = src_picture ();
411 Picture dst = XRenderCreatePicture (dpy, img->pm, format, 0, 0); 455 Picture dst = XRenderCreatePicture (dpy, img->pm, format, 0, 0);
412 Picture mul = create_xrender_mask (dpy, pm, True); 456 Picture mul = create_xrender_mask (dpy, pm, True, True);
413
414 XRenderPictureAttributes pa;
415 pa.component_alpha = 1;
416 XRenderChangePicture (dpy, mul, CPComponentAlpha, &pa);
417 457
418 //TODO: this operator does not yet implement some useful contrast 458 //TODO: this operator does not yet implement some useful contrast
419 while (r | g | b | a) 459 while (r | g | b | a)
420 { 460 {
421 unsigned short xr, xg, xb, xa; 461 unsigned short xr, xg, xb, xa;
442rxvt_img::clone () 482rxvt_img::clone ()
443{ 483{
444 return new rxvt_img (*this); 484 return new rxvt_img (*this);
445} 485}
446 486
447static XRenderPictFormat *
448find_alpha_format_for (Display *dpy, XRenderPictFormat *format)
449{
450 if (format->direct.alphaMask)
451 return format; // already has alpha
452
453 // try to find a suitable alpha format, one bit alpha is enough for our purposes
454 if (format->type == PictTypeDirect)
455 for (int n = 0; XRenderPictFormat *f = XRenderFindFormat (dpy, 0, 0, n); ++n)
456 if (f->direct.alphaMask
457 && f->type == PictTypeDirect
458 && ecb_popcount32 (f->direct.redMask ) >= ecb_popcount32 (format->direct.redMask )
459 && ecb_popcount32 (f->direct.greenMask) >= ecb_popcount32 (format->direct.greenMask)
460 && ecb_popcount32 (f->direct.blueMask ) >= ecb_popcount32 (format->direct.blueMask ))
461 return f;
462
463 // should be a very good fallback
464 return XRenderFindStandardFormat (dpy, PictStandardARGB32);
465}
466
467rxvt_img * 487rxvt_img *
468rxvt_img::reify () 488rxvt_img::reify ()
469{ 489{
470 if (x == 0 && y == 0 && w == ref->w && h == ref->h) 490 if (x == 0 && y == 0 && w == ref->w && h == ref->h)
471 return clone (); 491 return clone ();
517 } 537 }
518 538
519 return img; 539 return img;
520} 540}
521 541
522rxvt_img * 542static void
523rxvt_img::transform (int new_width, int new_height, double matrix[9]) 543mat_invert (rxvt_img::nv mat[3][3], rxvt_img::nv (&inv)[3][3])
524{ 544{
545 rxvt_img::nv s0 = mat [2][2] * mat [1][1] - mat [2][1] * mat [1][2];
546 rxvt_img::nv s1 = mat [2][1] * mat [0][2] - mat [2][2] * mat [0][1];
547 rxvt_img::nv s2 = mat [1][2] * mat [0][1] - mat [1][1] * mat [0][2];
548
549 rxvt_img::nv invdet = 1. / (mat [0][0] * s0 + mat [1][0] * s1 + mat [2][0] * s2);
550
551 inv [0][0] = invdet * s0;
552 inv [0][1] = invdet * s1;
553 inv [0][2] = invdet * s2;
554
555 inv [1][0] = invdet * (mat [2][0] * mat [1][2] - mat [2][2] * mat [1][0]);
556 inv [1][1] = invdet * (mat [2][2] * mat [0][0] - mat [2][0] * mat [0][2]);
557 inv [1][2] = invdet * (mat [1][0] * mat [0][2] - mat [1][2] * mat [0][0]);
558
559 inv [2][0] = invdet * (mat [2][1] * mat [1][0] - mat [2][0] * mat [1][1]);
560 inv [2][1] = invdet * (mat [2][0] * mat [0][1] - mat [2][1] * mat [0][0]);
561 inv [2][2] = invdet * (mat [1][1] * mat [0][0] - mat [1][0] * mat [0][1]);
562}
563
564static rxvt_img::nv
565mat_apply (rxvt_img::nv mat[3][3], int i, rxvt_img::nv x, rxvt_img::nv y)
566{
567 rxvt_img::nv v = mat [i][0] * x + mat [i][1] * y + mat [i][2];
568 rxvt_img::nv w = mat [2][0] * x + mat [2][1] * y + mat [2][2];
569
570 return v * (1. / w);
571}
572
573rxvt_img *
574rxvt_img::transform (nv matrix[3][3])
575{
576 // find new offset
577 int ox = mat_apply (matrix, 0, x, y);
578 int oy = mat_apply (matrix, 1, x, y);
579
580 // calculate new pixel bounding box coordinates
581 nv d [2], rmin[2], rmax[2];
582
583 for (int i = 0; i < 2; ++i)
584 {
585 nv v;
586 v = mat_apply (matrix, i, 0, 0); rmin [i] = rmax [i] = v; d [i] = v;
587 v = mat_apply (matrix, i, w, 0); min_it (rmin [i], v); max_it (rmax [i], v);
588 v = mat_apply (matrix, i, 0, h); min_it (rmin [i], v); max_it (rmax [i], v);
589 v = mat_apply (matrix, i, w, h); min_it (rmin [i], v); max_it (rmax [i], v);
590 }
591
592 int dx = floor (rmin [0]);
593 int dy = floor (rmin [1]);
594
595 int new_width = ceil (rmax [0] - dx);
596 int new_height = ceil (rmax [1] - dy);
597
598 nv inv[3][3];
599 mat_invert (matrix, inv);
600
525 rxvt_img *img = new rxvt_img (s, format, 0, 0, new_width, new_height, repeat); 601 rxvt_img *img = new rxvt_img (s, format, ox - dx - d [0], oy - dy - d [1], new_width, new_height, repeat);
526 img->alloc (); 602 img->alloc ();
527 603
528 Display *dpy = s->display->dpy; 604 Display *dpy = s->display->dpy;
529 Picture src = src_picture (); 605 Picture src = src_picture ();
530 Picture dst = XRenderCreatePicture (dpy, img->pm, img->format, 0, 0); 606 Picture dst = XRenderCreatePicture (dpy, img->pm, img->format, 0, 0);
531 607
532 XTransform xfrm; 608 XTransform xfrm;
533 609
534 for (int i = 0; i < 3; ++i) 610 for (int i = 0; i < 3; ++i)
535 for (int j = 0; j < 3; ++j) 611 for (int j = 0; j < 3; ++j)
536 xfrm.matrix [i][j] = XDoubleToFixed (matrix [i * 3 + j]); 612 xfrm.matrix [i][j] = XDoubleToFixed (inv [i][j]);
537
538 xfrm.matrix [0][2] -= XDoubleToFixed (x);//TODO
539 xfrm.matrix [1][2] -= XDoubleToFixed (y);
540 613
541 XRenderSetPictureFilter (dpy, src, "good", 0, 0); 614 XRenderSetPictureFilter (dpy, src, "good", 0, 0);
542 XRenderSetPictureTransform (dpy, src, &xfrm); 615 XRenderSetPictureTransform (dpy, src, &xfrm);
543 XRenderComposite (dpy, PictOpSrc, src, None, dst, 0, 0, 0, 0, 0, 0, new_width, new_height); 616 XRenderComposite (dpy, PictOpSrc, src, None, dst, dx, dy, 0, 0, 0, 0, new_width, new_height);
544 617
545 XRenderFreePicture (dpy, src); 618 XRenderFreePicture (dpy, src);
546 XRenderFreePicture (dpy, dst); 619 XRenderFreePicture (dpy, dst);
547 620
548 return img; 621 return img;
552rxvt_img::scale (int new_width, int new_height) 625rxvt_img::scale (int new_width, int new_height)
553{ 626{
554 if (w == new_width && h == new_height) 627 if (w == new_width && h == new_height)
555 return clone (); 628 return clone ();
556 629
557 double matrix[9] = { 630 nv matrix[3][3] = {
558 w / (double)new_width, 0, 0, 631 { new_width / (nv)w, 0, 0 },
559 0, h / (double)new_height, 0, 632 { 0, new_height / (nv)h, 0 },
560 0, 0, 1 633 { 0, 0, 1 }
561 }; 634 };
562 635
563 int old_repeat_mode = repeat; 636 int old_repeat_mode = repeat;
564 repeat = RepeatPad; // not right, but xrender can't proeprly scale it seems 637 repeat = RepeatPad; // not right, but xrender can't properly scale it seems
565 638
566 rxvt_img *img = transform (new_width, new_height, matrix); 639 rxvt_img *img = transform (matrix);
567 640
568 repeat = old_repeat_mode; 641 repeat = old_repeat_mode;
569 img->repeat = repeat; 642 img->repeat = repeat;
570 643
571 return img; 644 return img;
572} 645}
573 646
574rxvt_img * 647rxvt_img *
575rxvt_img::rotate (int new_width, int new_height, int x, int y, double phi) 648rxvt_img::rotate (int cx, int cy, nv phi)
576{ 649{
577 double s = sin (phi); 650 nv s = sin (phi);
578 double c = cos (phi); 651 nv c = cos (phi);
579 652
580 double matrix[9] = { 653 nv matrix[3][3] = {
581 c, -s, -c * x + s * y + x, 654 { c, -s, cx - c * cx + s * cy },
582 s, c, -s * x - c * y + y, 655 { s, c, cy - s * cx - c * cy },
583 0, 0, 1 656 { 0, 0, 1 }
657 //{ c, -s, 0 },
658 //{ s, c, 0 },
659 //{ 0, 0, 1 }
584 }; 660 };
585 661
586 return transform (new_width, new_height, matrix); 662 //move (-cx, -cy);
587} 663 rxvt_img *img = transform (matrix);
664 //move ( cx, cy);
665 //img->move (cx, cy);
588 666
667 return img;
668}
669
589rxvt_img * 670rxvt_img *
590rxvt_img::convert_format (XRenderPictFormat *new_format, const rxvt_color &bg) 671rxvt_img::convert_format (XRenderPictFormat *new_format, const rgba &bg)
591{ 672{
592 if (new_format == format) 673 if (new_format == format)
593 return clone (); 674 return clone ();
594 675
595 rxvt_img *img = new rxvt_img (s, new_format, x, y, w, h, repeat); 676 rxvt_img *img = new rxvt_img (s, new_format, x, y, w, h, repeat);
601 int op = PictOpSrc; 682 int op = PictOpSrc;
602 683
603 if (format->direct.alphaMask && !new_format->direct.alphaMask) 684 if (format->direct.alphaMask && !new_format->direct.alphaMask)
604 { 685 {
605 // does it have to be that complicated 686 // does it have to be that complicated
606 rgba c;
607 bg.get (c);
608
609 XRenderColor rc = { c.r, c.g, c.b, 0xffff }; 687 XRenderColor rc = { bg.r, bg.g, bg.b, bg.a };
610 XRenderFillRectangle (dpy, PictOpSrc, dst, &rc, 0, 0, w, h); 688 XRenderFillRectangle (dpy, PictOpSrc, dst, &rc, 0, 0, w, h);
611 689
612 op = PictOpOver; 690 op = PictOpOver;
613 } 691 }
614 692
619 697
620 return img; 698 return img;
621} 699}
622 700
623rxvt_img * 701rxvt_img *
624rxvt_img::blend (rxvt_img *img, double factor) 702rxvt_img::blend (rxvt_img *img, nv factor)
625{ 703{
626 rxvt_img *img2 = clone (); 704 rxvt_img *img2 = clone ();
627 Display *dpy = s->display->dpy; 705 Display *dpy = s->display->dpy;
628 Picture src = img->src_picture (); 706 Picture src = img->src_picture ();
629 Picture dst = XRenderCreatePicture (dpy, img2->pm, img2->format, 0, 0); 707 Picture dst = XRenderCreatePicture (dpy, img2->pm, img2->format, 0, 0);
630 708 Picture mask = create_xrender_mask (dpy, img->pm, False, False);
631 Pixmap pixmap = XCreatePixmap (dpy, img->pm, 1, 1, 8);
632 XRenderPictFormat *format = XRenderFindStandardFormat (dpy, PictStandardA8);
633 XRenderPictureAttributes pa;
634 pa.repeat = True;
635 Picture mask = XRenderCreatePicture (dpy, pixmap, format, CPRepeat, &pa);
636 XFreePixmap (dpy, pixmap);
637 709
638 XRenderColor mask_c; 710 XRenderColor mask_c;
639 711
640 mask_c.alpha = float_to_component (factor); 712 mask_c.alpha = float_to_component (factor);
641 mask_c.red = 713 mask_c.red =

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines