|
|
1 | #include <string.h> |
1 | #include <math.h> |
2 | #include <math.h> |
2 | #include "../config.h" |
3 | #include "../config.h" |
3 | #include "rxvt.h" |
4 | #include "rxvt.h" |
4 | |
5 | |
5 | #if HAVE_IMG |
6 | #if HAVE_IMG |
|
|
7 | |
|
|
8 | typedef rxvt_img::nv nv; |
|
|
9 | |
|
|
10 | struct mat3x3 |
|
|
11 | { |
|
|
12 | nv v[3][3]; |
|
|
13 | |
|
|
14 | mat3x3 () |
|
|
15 | { |
|
|
16 | } |
|
|
17 | |
|
|
18 | mat3x3 (nv matrix[3][3]) |
|
|
19 | { |
|
|
20 | memcpy (v, matrix, sizeof (v)); |
|
|
21 | } |
|
|
22 | |
|
|
23 | mat3x3 (nv v11, nv v12, nv v13, nv v21, nv v22, nv v23, nv v31, nv v32, nv v33) |
|
|
24 | { |
|
|
25 | v[0][0] = v11; v[0][1] = v12; v[0][2] = v13; |
|
|
26 | v[1][0] = v21; v[1][1] = v22; v[1][2] = v23; |
|
|
27 | v[2][0] = v31; v[2][1] = v32; v[2][2] = v33; |
|
|
28 | } |
|
|
29 | |
|
|
30 | mat3x3 invert (); |
|
|
31 | |
|
|
32 | nv *operator [](int i) { return &v[i][0]; } |
|
|
33 | const nv *operator [](int i) const { return &v[i][0]; } |
|
|
34 | |
|
|
35 | // quite inefficient, hopefully gcc pulls the w calc out of any loops |
|
|
36 | nv apply1 (int i, nv x, nv y) |
|
|
37 | { |
|
|
38 | mat3x3 &m = *this; |
|
|
39 | |
|
|
40 | nv v = m[i][0] * x + m[i][1] * y + m[i][2]; |
|
|
41 | nv w = m[2][0] * x + m[2][1] * y + m[2][2]; |
|
|
42 | |
|
|
43 | return v * (1. / w); |
|
|
44 | } |
|
|
45 | |
|
|
46 | static mat3x3 translate (nv x, nv y); |
|
|
47 | }; |
|
|
48 | |
|
|
49 | mat3x3 |
|
|
50 | mat3x3::invert () |
|
|
51 | { |
|
|
52 | mat3x3 &m = *this; |
|
|
53 | mat3x3 inv; |
|
|
54 | |
|
|
55 | nv s0 = m[2][2] * m[1][1] - m[2][1] * m[1][2]; |
|
|
56 | nv s1 = m[2][1] * m[0][2] - m[2][2] * m[0][1]; |
|
|
57 | nv s2 = m[1][2] * m[0][1] - m[1][1] * m[0][2]; |
|
|
58 | |
|
|
59 | nv invdet = 1. / (m[0][0] * s0 + m[1][0] * s1 + m[2][0] * s2); |
|
|
60 | |
|
|
61 | inv[0][0] = invdet * s0; |
|
|
62 | inv[0][1] = invdet * s1; |
|
|
63 | inv[0][2] = invdet * s2; |
|
|
64 | |
|
|
65 | inv[1][0] = invdet * (m[2][0] * m[1][2] - m[2][2] * m[1][0]); |
|
|
66 | inv[1][1] = invdet * (m[2][2] * m[0][0] - m[2][0] * m[0][2]); |
|
|
67 | inv[1][2] = invdet * (m[1][0] * m[0][2] - m[1][2] * m[0][0]); |
|
|
68 | |
|
|
69 | inv[2][0] = invdet * (m[2][1] * m[1][0] - m[2][0] * m[1][1]); |
|
|
70 | inv[2][1] = invdet * (m[2][0] * m[0][1] - m[2][1] * m[0][0]); |
|
|
71 | inv[2][2] = invdet * (m[1][1] * m[0][0] - m[1][0] * m[0][1]); |
|
|
72 | |
|
|
73 | return inv; |
|
|
74 | } |
|
|
75 | |
|
|
76 | static mat3x3 |
|
|
77 | operator *(const mat3x3 &a, const mat3x3 &b) |
|
|
78 | { |
|
|
79 | mat3x3 r; |
|
|
80 | |
|
|
81 | for (int i = 0; i < 3; ++i) |
|
|
82 | for (int j = 0; j < 3; ++j) |
|
|
83 | r[i][j] = a[i][0] * b[0][j] |
|
|
84 | + a[i][1] * b[1][j] |
|
|
85 | + a[i][2] * b[2][j]; |
|
|
86 | |
|
|
87 | return r; |
|
|
88 | } |
|
|
89 | |
|
|
90 | mat3x3 |
|
|
91 | mat3x3::translate (nv x, nv y) |
|
|
92 | { |
|
|
93 | return mat3x3 ( |
|
|
94 | 1, 0, x, |
|
|
95 | 0, 1, y, |
|
|
96 | 0, 0, 1 |
|
|
97 | ); |
|
|
98 | } |
|
|
99 | |
|
|
100 | #if 0 |
|
|
101 | struct pict |
|
|
102 | { |
|
|
103 | Display *dpy; |
|
|
104 | Picture pic; |
|
|
105 | |
|
|
106 | operator Picture () const |
|
|
107 | { |
|
|
108 | return pic; |
|
|
109 | } |
|
|
110 | |
|
|
111 | pict () |
|
|
112 | : pic (0) |
|
|
113 | { |
|
|
114 | } |
|
|
115 | |
|
|
116 | pict (rxvt_img *img, XRenderPictFormat *format = 0) |
|
|
117 | : dpy (img->s->display->dpy) |
|
|
118 | { |
|
|
119 | XRenderPictureAttributes pa; |
|
|
120 | pa.repeat = img->repeat; |
|
|
121 | pic = XRenderCreatePicture (dpy, img->pm, format ? format : img->format, CPRepeat, &pa); |
|
|
122 | } |
|
|
123 | |
|
|
124 | ~pict () |
|
|
125 | { |
|
|
126 | if (pic) |
|
|
127 | XRenderFreePicture (dpy, pic); |
|
|
128 | } |
|
|
129 | }; |
|
|
130 | #endif |
|
|
131 | |
|
|
132 | static XRenderPictFormat * |
|
|
133 | find_alpha_format_for (Display *dpy, XRenderPictFormat *format) |
|
|
134 | { |
|
|
135 | if (format->direct.alphaMask) |
|
|
136 | return format; // already has alpha |
|
|
137 | |
|
|
138 | // try to find a suitable alpha format, one bit alpha is enough for our purposes |
|
|
139 | if (format->type == PictTypeDirect) |
|
|
140 | for (int n = 0; XRenderPictFormat *f = XRenderFindFormat (dpy, 0, 0, n); ++n) |
|
|
141 | if (f->direct.alphaMask |
|
|
142 | && f->type == PictTypeDirect |
|
|
143 | && ecb_popcount32 (f->direct.redMask ) >= ecb_popcount32 (format->direct.redMask ) |
|
|
144 | && ecb_popcount32 (f->direct.greenMask) >= ecb_popcount32 (format->direct.greenMask) |
|
|
145 | && ecb_popcount32 (f->direct.blueMask ) >= ecb_popcount32 (format->direct.blueMask )) |
|
|
146 | return f; |
|
|
147 | |
|
|
148 | // should be a very good fallback |
|
|
149 | return XRenderFindStandardFormat (dpy, PictStandardARGB32); |
|
|
150 | } |
6 | |
151 | |
7 | rxvt_img::rxvt_img (rxvt_screen *screen, XRenderPictFormat *format, int x, int y, int width, int height, int repeat) |
152 | 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), |
153 | : s(screen), x(x), y(y), w(width), h(height), format(format), repeat(repeat), |
9 | pm(0), ref(0) |
154 | pm(0), ref(0) |
10 | { |
155 | { |
… | |
… | |
195 | pm = XCreatePixmap (s->display->dpy, s->display->root, w, h, format->depth); |
340 | pm = XCreatePixmap (s->display->dpy, s->display->root, w, h, format->depth); |
196 | ref = new pixref (w, h); |
341 | ref = new pixref (w, h); |
197 | } |
342 | } |
198 | |
343 | |
199 | Picture |
344 | Picture |
200 | rxvt_img::src_picture () |
345 | rxvt_img::picture () |
201 | { |
346 | { |
202 | Display *dpy = s->display->dpy; |
347 | Display *dpy = s->display->dpy; |
203 | |
348 | |
204 | XRenderPictureAttributes pa; |
349 | XRenderPictureAttributes pa; |
205 | pa.repeat = repeat; |
350 | pa.repeat = repeat; |
… | |
… | |
224 | pm = pm2; |
369 | pm = pm2; |
225 | ref = new pixref (ref->w, ref->h); |
370 | ref = new pixref (ref->w, ref->h); |
226 | } |
371 | } |
227 | |
372 | |
228 | void |
373 | void |
229 | rxvt_img::fill (const rxvt_color &c) |
374 | rxvt_img::fill (const rgba &c) |
230 | { |
375 | { |
231 | rgba cc; |
|
|
232 | c.get (cc); |
|
|
233 | XRenderColor rc = { cc.r, cc.g, cc.b, cc.a }; |
376 | XRenderColor rc = { c.r, c.g, c.b, c.a }; |
234 | |
377 | |
235 | Display *dpy = s->display->dpy; |
378 | Display *dpy = s->display->dpy; |
236 | Picture src = src_picture (); |
379 | Picture src = picture (); |
237 | XRenderFillRectangle (dpy, PictOpSrc, src, &rc, 0, 0, w, h); |
380 | XRenderFillRectangle (dpy, PictOpSrc, src, &rc, 0, 0, w, h); |
238 | XRenderFreePicture (dpy, src); |
381 | XRenderFreePicture (dpy, src); |
239 | } |
382 | } |
240 | |
383 | |
|
|
384 | void |
|
|
385 | rxvt_img::add_alpha () |
|
|
386 | { |
|
|
387 | if (format->direct.alphaMask) |
|
|
388 | return; |
|
|
389 | |
|
|
390 | Display *dpy = s->display->dpy; |
|
|
391 | |
|
|
392 | rxvt_img *img = new rxvt_img (s, find_alpha_format_for (dpy, format), x, y, w, h, repeat); |
|
|
393 | img->alloc (); |
|
|
394 | |
|
|
395 | Picture src = picture (); |
|
|
396 | Picture dst = XRenderCreatePicture (dpy, img->pm, img->format, 0, 0); |
|
|
397 | |
|
|
398 | XRenderComposite (dpy, PictOpSrc, src, None, dst, 0, 0, 0, 0, 0, 0, w, h); |
|
|
399 | |
|
|
400 | XRenderFreePicture (dpy, src); |
|
|
401 | XRenderFreePicture (dpy, dst); |
|
|
402 | |
|
|
403 | ::swap (img->ref, ref); |
|
|
404 | ::swap (img->pm , pm ); |
|
|
405 | |
|
|
406 | delete img; |
|
|
407 | } |
|
|
408 | |
241 | static void |
409 | static void |
242 | get_gaussian_kernel (int radius, int width, double *kernel, XFixed *params) |
410 | get_gaussian_kernel (int radius, int width, nv *kernel, XFixed *params) |
243 | { |
411 | { |
244 | double sigma = radius / 2.0; |
412 | nv sigma = radius / 2.0; |
245 | double scale = sqrt (2.0 * M_PI) * sigma; |
413 | nv scale = sqrt (2.0 * M_PI) * sigma; |
246 | double sum = 0.0; |
414 | nv sum = 0.0; |
247 | |
415 | |
248 | for (int i = 0; i < width; i++) |
416 | for (int i = 0; i < width; i++) |
249 | { |
417 | { |
250 | double x = i - width / 2; |
418 | nv x = i - width / 2; |
251 | kernel[i] = exp (-(x * x) / (2.0 * sigma * sigma)) / scale; |
419 | kernel[i] = exp (-(x * x) / (2.0 * sigma * sigma)) / scale; |
252 | sum += kernel[i]; |
420 | sum += kernel[i]; |
253 | } |
421 | } |
254 | |
422 | |
255 | params[0] = XDoubleToFixed (width); |
423 | params[0] = XDoubleToFixed (width); |
… | |
… | |
265 | if (!(s->display->flags & DISPLAY_HAS_RENDER_CONV)) |
433 | if (!(s->display->flags & DISPLAY_HAS_RENDER_CONV)) |
266 | return clone (); |
434 | return clone (); |
267 | |
435 | |
268 | Display *dpy = s->display->dpy; |
436 | Display *dpy = s->display->dpy; |
269 | int size = max (rh, rv) * 2 + 1; |
437 | int size = max (rh, rv) * 2 + 1; |
270 | double *kernel = (double *)malloc (size * sizeof (double)); |
438 | nv *kernel = (nv *)malloc (size * sizeof (nv)); |
271 | XFixed *params = (XFixed *)malloc ((size + 2) * sizeof (XFixed)); |
439 | XFixed *params = (XFixed *)malloc ((size + 2) * sizeof (XFixed)); |
272 | rxvt_img *img = new rxvt_img (s, format, x, y, w, h, repeat); |
440 | rxvt_img *img = new rxvt_img (s, format, x, y, w, h, repeat); |
273 | img->alloc (); |
441 | img->alloc (); |
274 | |
442 | |
275 | XRenderPictureAttributes pa; |
443 | XRenderPictureAttributes pa; |
… | |
… | |
397 | if (r < 0 || g < 0 || b < 0 || a < 0) |
565 | if (r < 0 || g < 0 || b < 0 || a < 0) |
398 | rxvt_fatal ("rxvt_img::contrast does not support negative values.\n"); |
566 | rxvt_fatal ("rxvt_img::contrast does not support negative values.\n"); |
399 | |
567 | |
400 | rxvt_img *img = new rxvt_img (s, format, x, y, w, h, repeat); |
568 | rxvt_img *img = new rxvt_img (s, format, x, y, w, h, repeat); |
401 | img->alloc (); |
569 | img->alloc (); |
402 | |
570 | img->fill (rgba (0, 0, 0, 0)); |
403 | { |
|
|
404 | rxvt_color empty; |
|
|
405 | empty.set (s, rgba (0, 0, 0, 0)); |
|
|
406 | img->fill (empty); |
|
|
407 | } |
|
|
408 | |
571 | |
409 | // premultiply (yeah, these are not exact, sue me or fix it) |
572 | // premultiply (yeah, these are not exact, sue me or fix it) |
410 | r = (r * (a >> 8)) >> 8; |
573 | r = (r * (a >> 8)) >> 8; |
411 | g = (g * (a >> 8)) >> 8; |
574 | g = (g * (a >> 8)) >> 8; |
412 | b = (b * (a >> 8)) >> 8; |
575 | b = (b * (a >> 8)) >> 8; |
413 | |
576 | |
414 | Display *dpy = s->display->dpy; |
577 | Display *dpy = s->display->dpy; |
415 | |
578 | |
416 | Picture src = src_picture (); |
579 | Picture src = picture (); |
417 | Picture dst = XRenderCreatePicture (dpy, img->pm, format, 0, 0); |
580 | Picture dst = XRenderCreatePicture (dpy, img->pm, format, 0, 0); |
418 | Picture mul = create_xrender_mask (dpy, pm, True, True); |
581 | Picture mul = create_xrender_mask (dpy, pm, True, True); |
419 | |
582 | |
420 | //TODO: this operator does not yet implement some useful contrast |
583 | //TODO: this operator does not yet implement some useful contrast |
421 | while (r | g | b | a) |
584 | while (r | g | b | a) |
… | |
… | |
438 | ::swap (img->pm , pm ); |
601 | ::swap (img->pm , pm ); |
439 | |
602 | |
440 | delete img; |
603 | delete img; |
441 | } |
604 | } |
442 | |
605 | |
|
|
606 | void |
|
|
607 | rxvt_img::draw (rxvt_img *img, int op, nv mask) |
|
|
608 | { |
|
|
609 | unshare (); |
|
|
610 | |
|
|
611 | Display *dpy = s->display->dpy; |
|
|
612 | Picture src = img->picture (); |
|
|
613 | Picture dst = picture (); |
|
|
614 | Picture mask_p = 0; |
|
|
615 | |
|
|
616 | if (mask != 1.) |
|
|
617 | { |
|
|
618 | mask_p = create_xrender_mask (dpy, img->pm, False, False); |
|
|
619 | XRenderColor mask_c = { 0, 0, 0, float_to_component (mask) }; |
|
|
620 | XRenderFillRectangle (dpy, PictOpSrc, mask, &mask_c, 0, 0, 1, 1); |
|
|
621 | } |
|
|
622 | |
|
|
623 | XRenderComposite (dpy, op, src, mask_p, dst, x - img->x, y - img->y, 0, 0, 0, 0, w, h); |
|
|
624 | |
|
|
625 | XRenderFreePicture (dpy, src); |
|
|
626 | XRenderFreePicture (dpy, dst); |
|
|
627 | |
|
|
628 | if (mask_p) |
|
|
629 | XRenderFreePicture (dpy, mask_p); |
|
|
630 | } |
|
|
631 | |
443 | rxvt_img * |
632 | rxvt_img * |
444 | rxvt_img::clone () |
633 | rxvt_img::clone () |
445 | { |
634 | { |
446 | return new rxvt_img (*this); |
635 | return new rxvt_img (*this); |
447 | } |
|
|
448 | |
|
|
449 | static XRenderPictFormat * |
|
|
450 | find_alpha_format_for (Display *dpy, XRenderPictFormat *format) |
|
|
451 | { |
|
|
452 | if (format->direct.alphaMask) |
|
|
453 | return format; // already has alpha |
|
|
454 | |
|
|
455 | // try to find a suitable alpha format, one bit alpha is enough for our purposes |
|
|
456 | if (format->type == PictTypeDirect) |
|
|
457 | for (int n = 0; XRenderPictFormat *f = XRenderFindFormat (dpy, 0, 0, n); ++n) |
|
|
458 | if (f->direct.alphaMask |
|
|
459 | && f->type == PictTypeDirect |
|
|
460 | && ecb_popcount32 (f->direct.redMask ) >= ecb_popcount32 (format->direct.redMask ) |
|
|
461 | && ecb_popcount32 (f->direct.greenMask) >= ecb_popcount32 (format->direct.greenMask) |
|
|
462 | && ecb_popcount32 (f->direct.blueMask ) >= ecb_popcount32 (format->direct.blueMask )) |
|
|
463 | return f; |
|
|
464 | |
|
|
465 | // should be a very good fallback |
|
|
466 | return XRenderFindStandardFormat (dpy, PictStandardARGB32); |
|
|
467 | } |
636 | } |
468 | |
637 | |
469 | rxvt_img * |
638 | rxvt_img * |
470 | rxvt_img::reify () |
639 | rxvt_img::reify () |
471 | { |
640 | { |
… | |
… | |
480 | && repeat == RepeatNone; // and we have no good pixels to fill with |
649 | && repeat == RepeatNone; // and we have no good pixels to fill with |
481 | |
650 | |
482 | rxvt_img *img = new rxvt_img (s, alpha ? find_alpha_format_for (dpy, format) : format, 0, 0, w, h, repeat); |
651 | rxvt_img *img = new rxvt_img (s, alpha ? find_alpha_format_for (dpy, format) : format, 0, 0, w, h, repeat); |
483 | img->alloc (); |
652 | img->alloc (); |
484 | |
653 | |
485 | Picture src = src_picture (); |
654 | Picture src = picture (); |
486 | Picture dst = XRenderCreatePicture (dpy, img->pm, img->format, 0, 0); |
655 | Picture dst = XRenderCreatePicture (dpy, img->pm, img->format, 0, 0); |
487 | |
656 | |
488 | if (alpha) |
657 | if (alpha) |
489 | { |
658 | { |
490 | XRenderColor rc = { 0, 0, 0, 0 }; |
659 | XRenderColor rc = { 0, 0, 0, 0 }; |
491 | XRenderFillRectangle (dpy, PictOpSrc, dst, &rc, 0, 0, w, h);//TODO: split into four fillrectangles |
660 | XRenderFillRectangle (dpy, PictOpSrc, dst, &rc, 0, 0, w, h);//TODO: split into four fillrectangles |
492 | XRenderComposite (dpy, PictOpSrc, src, None, dst, 0, 0, 0, 0, -x, -y, ref->w, ref->h); |
661 | XRenderComposite (dpy, PictOpSrc, src, None, dst, 0, 0, 0, 0, x, y, ref->w, ref->h); |
493 | } |
662 | } |
494 | else |
663 | else |
495 | XRenderComposite (dpy, PictOpSrc, src, None, dst, x, y, 0, 0, 0, 0, w, h); |
664 | XRenderComposite (dpy, PictOpSrc, src, None, dst, -x, -y, 0, 0, 0, 0, w, h); |
496 | |
665 | |
497 | XRenderFreePicture (dpy, src); |
666 | XRenderFreePicture (dpy, src); |
498 | XRenderFreePicture (dpy, dst); |
667 | XRenderFreePicture (dpy, dst); |
499 | |
668 | |
500 | return img; |
669 | return img; |
… | |
… | |
503 | rxvt_img * |
672 | rxvt_img * |
504 | rxvt_img::sub_rect (int x, int y, int width, int height) |
673 | rxvt_img::sub_rect (int x, int y, int width, int height) |
505 | { |
674 | { |
506 | rxvt_img *img = clone (); |
675 | rxvt_img *img = clone (); |
507 | |
676 | |
508 | img->x += x; |
677 | img->x -= x; |
509 | img->y += y; |
678 | img->y -= y; |
510 | |
679 | |
511 | if (w != width || h != height) |
680 | if (w != width || h != height) |
512 | { |
681 | { |
513 | img->w = width; |
682 | img->w = width; |
514 | img->h = height; |
683 | img->h = height; |
… | |
… | |
520 | |
689 | |
521 | return img; |
690 | return img; |
522 | } |
691 | } |
523 | |
692 | |
524 | rxvt_img * |
693 | rxvt_img * |
525 | rxvt_img::transform (int new_width, int new_height, double matrix[9]) |
694 | rxvt_img::transform (nv matrix[3][3]) |
526 | { |
695 | { |
|
|
696 | // calculate new pixel bounding box coordinates |
|
|
697 | nv r[2], rmin[2], rmax[2]; |
|
|
698 | |
|
|
699 | mat3x3 m (matrix); |
|
|
700 | |
|
|
701 | for (int i = 0; i < 2; ++i) |
|
|
702 | { |
|
|
703 | nv v; |
|
|
704 | |
|
|
705 | v = m.apply1 (i, 0+x, 0+y); rmin [i] = rmax [i] = v; r [i] = v; |
|
|
706 | v = m.apply1 (i, w+x, 0+y); min_it (rmin [i], v); max_it (rmax [i], v); |
|
|
707 | v = m.apply1 (i, 0+x, h+y); min_it (rmin [i], v); max_it (rmax [i], v); |
|
|
708 | v = m.apply1 (i, w+x, h+y); min_it (rmin [i], v); max_it (rmax [i], v); |
|
|
709 | } |
|
|
710 | |
|
|
711 | float sx = rmin [0] - x; |
|
|
712 | float sy = rmin [1] - y; |
|
|
713 | |
|
|
714 | // TODO: adjust matrix for subpixel accuracy |
|
|
715 | int nx = floor (rmin [0]); |
|
|
716 | int ny = floor (rmin [1]); |
|
|
717 | |
|
|
718 | int new_width = ceil (rmax [0] - rmin [0]); |
|
|
719 | int new_height = ceil (rmax [1] - rmin [1]); |
|
|
720 | |
|
|
721 | m = mat3x3::translate (-x, -y) * m * mat3x3::translate (x, y); |
|
|
722 | |
|
|
723 | mat3x3 inv = m.invert (); |
|
|
724 | |
527 | rxvt_img *img = new rxvt_img (s, format, 0, 0, new_width, new_height, repeat); |
725 | rxvt_img *img = new rxvt_img (s, format, nx, ny, new_width, new_height, repeat); |
528 | img->alloc (); |
726 | img->alloc (); |
529 | |
727 | |
530 | Display *dpy = s->display->dpy; |
728 | Display *dpy = s->display->dpy; |
531 | Picture src = src_picture (); |
729 | Picture src = picture (); |
532 | Picture dst = XRenderCreatePicture (dpy, img->pm, img->format, 0, 0); |
730 | Picture dst = XRenderCreatePicture (dpy, img->pm, img->format, 0, 0); |
533 | |
731 | |
534 | XTransform xfrm; |
732 | XTransform xfrm; |
535 | |
733 | |
536 | for (int i = 0; i < 3; ++i) |
734 | for (int i = 0; i < 3; ++i) |
537 | for (int j = 0; j < 3; ++j) |
735 | for (int j = 0; j < 3; ++j) |
538 | xfrm.matrix [i][j] = XDoubleToFixed (matrix [i * 3 + j]); |
736 | xfrm.matrix [i][j] = XDoubleToFixed (inv [i][j]); |
539 | |
|
|
540 | xfrm.matrix [0][2] -= XDoubleToFixed (x);//TODO |
|
|
541 | xfrm.matrix [1][2] -= XDoubleToFixed (y); |
|
|
542 | |
737 | |
543 | XRenderSetPictureFilter (dpy, src, "good", 0, 0); |
738 | XRenderSetPictureFilter (dpy, src, "good", 0, 0); |
544 | XRenderSetPictureTransform (dpy, src, &xfrm); |
739 | XRenderSetPictureTransform (dpy, src, &xfrm); |
545 | XRenderComposite (dpy, PictOpSrc, src, None, dst, 0, 0, 0, 0, 0, 0, new_width, new_height); |
740 | XRenderComposite (dpy, PictOpSrc, src, None, dst, sx, sy, 0, 0, 0, 0, new_width, new_height); |
|
|
741 | #if 1 |
|
|
742 | { |
|
|
743 | XRenderColor rc = { 65535,0,0,65535 }; |
|
|
744 | XRenderFillRectangle (dpy, PictOpSrc, dst, &rc, 0, 0, new_width, new_height); |
|
|
745 | }{ |
|
|
746 | XRenderColor rc = { 0,0,0,65535 }; |
|
|
747 | XRenderFillRectangle (dpy, PictOpSrc, dst, &rc, 1, 1, new_width - 2, new_height - 2); |
|
|
748 | } |
|
|
749 | XRenderComposite (dpy, PictOpOver, src, None, dst, sx, sy, 0, 0, 0, 0, new_width, new_height); |
|
|
750 | #endif |
546 | |
751 | |
547 | XRenderFreePicture (dpy, src); |
752 | XRenderFreePicture (dpy, src); |
548 | XRenderFreePicture (dpy, dst); |
753 | XRenderFreePicture (dpy, dst); |
549 | |
754 | |
550 | return img; |
755 | return img; |
… | |
… | |
554 | rxvt_img::scale (int new_width, int new_height) |
759 | rxvt_img::scale (int new_width, int new_height) |
555 | { |
760 | { |
556 | if (w == new_width && h == new_height) |
761 | if (w == new_width && h == new_height) |
557 | return clone (); |
762 | return clone (); |
558 | |
763 | |
559 | double matrix[9] = { |
764 | nv matrix[3][3] = { |
560 | w / (double)new_width, 0, 0, |
765 | { new_width / (nv)w, 0, 0 }, |
561 | 0, h / (double)new_height, 0, |
766 | { 0, new_height / (nv)h, 0 }, |
562 | 0, 0, 1 |
767 | { 0, 0, 1 } |
563 | }; |
768 | }; |
564 | |
769 | |
565 | int old_repeat_mode = repeat; |
770 | int old_repeat_mode = repeat; |
566 | repeat = RepeatPad; // not right, but xrender can't proeprly scale it seems |
771 | repeat = RepeatPad; // not right, but xrender can't properly scale it seems |
567 | |
772 | |
568 | rxvt_img *img = transform (new_width, new_height, matrix); |
773 | rxvt_img *img = transform (matrix); |
569 | |
774 | |
570 | repeat = old_repeat_mode; |
775 | repeat = old_repeat_mode; |
571 | img->repeat = repeat; |
776 | img->repeat = repeat; |
572 | |
777 | |
573 | return img; |
778 | return img; |
574 | } |
779 | } |
575 | |
780 | |
576 | rxvt_img * |
781 | rxvt_img * |
577 | rxvt_img::rotate (int new_width, int new_height, int x, int y, double phi) |
782 | rxvt_img::rotate (int cx, int cy, nv phi) |
578 | { |
783 | { |
579 | double s = sin (phi); |
784 | nv s = sin (phi); |
580 | double c = cos (phi); |
785 | nv c = cos (phi); |
581 | |
786 | |
582 | double matrix[9] = { |
787 | nv matrix[3][3] = { |
|
|
788 | #if 0 |
583 | c, -s, -c * x + s * y + x, |
789 | { c, -s, cx - c * cx + s * cy }, |
584 | s, c, -s * x - c * y + y, |
790 | { s, c, cy - s * cx - c * cy }, |
585 | 0, 0, 1 |
791 | { 0, 0, 1 } |
|
|
792 | #else |
|
|
793 | { c, -s, 0 }, |
|
|
794 | { s, c, 0 }, |
|
|
795 | { 0, 0, 1 } |
|
|
796 | #endif |
586 | }; |
797 | }; |
587 | |
798 | |
588 | return transform (new_width, new_height, matrix); |
799 | move (-cx, -cy); |
589 | } |
800 | rxvt_img *img = transform (matrix); |
|
|
801 | move ( cx, cy); |
|
|
802 | img->move (cx, cy); |
590 | |
803 | |
|
|
804 | return img; |
|
|
805 | } |
|
|
806 | |
591 | rxvt_img * |
807 | rxvt_img * |
592 | rxvt_img::convert_format (XRenderPictFormat *new_format, const rxvt_color &bg) |
808 | rxvt_img::convert_format (XRenderPictFormat *new_format, const rgba &bg) |
593 | { |
809 | { |
594 | if (new_format == format) |
810 | if (new_format == format) |
595 | return clone (); |
811 | return clone (); |
596 | |
812 | |
597 | rxvt_img *img = new rxvt_img (s, new_format, x, y, w, h, repeat); |
813 | rxvt_img *img = new rxvt_img (s, new_format, x, y, w, h, repeat); |
598 | img->alloc (); |
814 | img->alloc (); |
599 | |
815 | |
600 | Display *dpy = s->display->dpy; |
816 | Display *dpy = s->display->dpy; |
601 | Picture src = src_picture (); |
817 | Picture src = picture (); |
602 | Picture dst = XRenderCreatePicture (dpy, img->pm, new_format, 0, 0); |
818 | Picture dst = XRenderCreatePicture (dpy, img->pm, new_format, 0, 0); |
603 | int op = PictOpSrc; |
819 | int op = PictOpSrc; |
604 | |
820 | |
605 | if (format->direct.alphaMask && !new_format->direct.alphaMask) |
821 | if (format->direct.alphaMask && !new_format->direct.alphaMask) |
606 | { |
822 | { |
607 | // does it have to be that complicated |
823 | // does it have to be that complicated |
608 | rgba c; |
|
|
609 | bg.get (c); |
|
|
610 | |
|
|
611 | XRenderColor rc = { c.r, c.g, c.b, 0xffff }; |
824 | XRenderColor rc = { bg.r, bg.g, bg.b, bg.a }; |
612 | XRenderFillRectangle (dpy, PictOpSrc, dst, &rc, 0, 0, w, h); |
825 | XRenderFillRectangle (dpy, PictOpSrc, dst, &rc, 0, 0, w, h); |
613 | |
826 | |
614 | op = PictOpOver; |
827 | op = PictOpOver; |
615 | } |
828 | } |
616 | |
829 | |
… | |
… | |
621 | |
834 | |
622 | return img; |
835 | return img; |
623 | } |
836 | } |
624 | |
837 | |
625 | rxvt_img * |
838 | rxvt_img * |
626 | rxvt_img::blend (rxvt_img *img, double factor) |
839 | rxvt_img::blend (rxvt_img *img, nv factor) |
627 | { |
840 | { |
628 | rxvt_img *img2 = clone (); |
841 | rxvt_img *img2 = clone (); |
629 | Display *dpy = s->display->dpy; |
842 | Display *dpy = s->display->dpy; |
630 | Picture src = img->src_picture (); |
843 | Picture src = img->picture (); |
631 | Picture dst = XRenderCreatePicture (dpy, img2->pm, img2->format, 0, 0); |
844 | Picture dst = XRenderCreatePicture (dpy, img2->pm, img2->format, 0, 0); |
632 | Picture mask = create_xrender_mask (dpy, img->pm, False, False); |
845 | Picture mask = create_xrender_mask (dpy, img->pm, False, False); |
633 | |
846 | |
634 | XRenderColor mask_c; |
847 | XRenderColor mask_c; |
635 | |
848 | |