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 | |
|
|
7 | static XRenderPictFormat * |
|
|
8 | find_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 | |
7 | rxvt_img::rxvt_img (rxvt_screen *screen, XRenderPictFormat *format, int x, int y, int width, int height, int repeat) |
27 | rxvt_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 | { |
… | |
… | |
234 | Picture src = src_picture (); |
254 | Picture src = src_picture (); |
235 | XRenderFillRectangle (dpy, PictOpSrc, src, &rc, 0, 0, w, h); |
255 | XRenderFillRectangle (dpy, PictOpSrc, src, &rc, 0, 0, w, h); |
236 | XRenderFreePicture (dpy, src); |
256 | XRenderFreePicture (dpy, src); |
237 | } |
257 | } |
238 | |
258 | |
|
|
259 | void |
|
|
260 | rxvt_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; |
|
|
282 | } |
|
|
283 | |
239 | static void |
284 | static void |
240 | get_gaussian_kernel (int radius, int width, double *kernel, XFixed *params) |
285 | get_gaussian_kernel (int radius, int width, double *kernel, XFixed *params) |
241 | { |
286 | { |
242 | double sigma = radius / 2.0; |
287 | double sigma = radius / 2.0; |
243 | double scale = sqrt (2.0 * M_PI) * sigma; |
288 | double scale = sqrt (2.0 * M_PI) * sigma; |
… | |
… | |
437 | rxvt_img::clone () |
482 | rxvt_img::clone () |
438 | { |
483 | { |
439 | return new rxvt_img (*this); |
484 | return new rxvt_img (*this); |
440 | } |
485 | } |
441 | |
486 | |
442 | static XRenderPictFormat * |
|
|
443 | find_alpha_format_for (Display *dpy, XRenderPictFormat *format) |
|
|
444 | { |
|
|
445 | if (format->direct.alphaMask) |
|
|
446 | return format; // already has alpha |
|
|
447 | |
|
|
448 | // try to find a suitable alpha format, one bit alpha is enough for our purposes |
|
|
449 | if (format->type == PictTypeDirect) |
|
|
450 | for (int n = 0; XRenderPictFormat *f = XRenderFindFormat (dpy, 0, 0, n); ++n) |
|
|
451 | if (f->direct.alphaMask |
|
|
452 | && f->type == PictTypeDirect |
|
|
453 | && ecb_popcount32 (f->direct.redMask ) >= ecb_popcount32 (format->direct.redMask ) |
|
|
454 | && ecb_popcount32 (f->direct.greenMask) >= ecb_popcount32 (format->direct.greenMask) |
|
|
455 | && ecb_popcount32 (f->direct.blueMask ) >= ecb_popcount32 (format->direct.blueMask )) |
|
|
456 | return f; |
|
|
457 | |
|
|
458 | // should be a very good fallback |
|
|
459 | return XRenderFindStandardFormat (dpy, PictStandardARGB32); |
|
|
460 | } |
|
|
461 | |
|
|
462 | rxvt_img * |
487 | rxvt_img * |
463 | rxvt_img::reify () |
488 | rxvt_img::reify () |
464 | { |
489 | { |
465 | if (x == 0 && y == 0 && w == ref->w && h == ref->h) |
490 | if (x == 0 && y == 0 && w == ref->w && h == ref->h) |
466 | return clone (); |
491 | return clone (); |