|
|
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 | namespace |
|
|
11 | { |
|
|
12 | |
|
|
13 | struct mat3x3 |
|
|
14 | { |
|
|
15 | nv v[3][3]; |
|
|
16 | |
|
|
17 | mat3x3 () |
|
|
18 | { |
|
|
19 | } |
|
|
20 | |
|
|
21 | mat3x3 (const nv *matrix) |
|
|
22 | { |
|
|
23 | memcpy (v, matrix, sizeof (v)); |
|
|
24 | } |
|
|
25 | |
|
|
26 | mat3x3 (nv v11, nv v12, nv v13, nv v21, nv v22, nv v23, nv v31, nv v32, nv v33) |
|
|
27 | { |
|
|
28 | v[0][0] = v11; v[0][1] = v12; v[0][2] = v13; |
|
|
29 | v[1][0] = v21; v[1][1] = v22; v[1][2] = v23; |
|
|
30 | v[2][0] = v31; v[2][1] = v32; v[2][2] = v33; |
|
|
31 | } |
|
|
32 | |
|
|
33 | mat3x3 invert (); |
|
|
34 | |
|
|
35 | nv *operator [](int i) { return &v[i][0]; } |
|
|
36 | const nv *operator [](int i) const { return &v[i][0]; } |
|
|
37 | |
|
|
38 | operator const nv * () const { return &v[0][0]; } |
|
|
39 | operator nv * () { return &v[0][0]; } |
|
|
40 | |
|
|
41 | // quite inefficient, hopefully gcc pulls the w calc out of any loops |
|
|
42 | nv apply1 (int i, nv x, nv y) |
|
|
43 | { |
|
|
44 | mat3x3 &m = *this; |
|
|
45 | |
|
|
46 | nv v = m[i][0] * x + m[i][1] * y + m[i][2]; |
|
|
47 | nv w = m[2][0] * x + m[2][1] * y + m[2][2]; |
|
|
48 | |
|
|
49 | return v * (1. / w); |
|
|
50 | } |
|
|
51 | |
|
|
52 | static mat3x3 translate (nv x, nv y); |
|
|
53 | static mat3x3 scale (nv s, nv t); |
|
|
54 | static mat3x3 rotate (nv phi); |
|
|
55 | }; |
|
|
56 | |
|
|
57 | mat3x3 |
|
|
58 | mat3x3::invert () |
|
|
59 | { |
|
|
60 | mat3x3 &m = *this; |
|
|
61 | mat3x3 inv; |
|
|
62 | |
|
|
63 | nv s0 = m[2][2] * m[1][1] - m[2][1] * m[1][2]; |
|
|
64 | nv s1 = m[2][1] * m[0][2] - m[2][2] * m[0][1]; |
|
|
65 | nv s2 = m[1][2] * m[0][1] - m[1][1] * m[0][2]; |
|
|
66 | |
|
|
67 | nv invdet = 1. / (m[0][0] * s0 + m[1][0] * s1 + m[2][0] * s2); |
|
|
68 | |
|
|
69 | inv[0][0] = invdet * s0; |
|
|
70 | inv[0][1] = invdet * s1; |
|
|
71 | inv[0][2] = invdet * s2; |
|
|
72 | |
|
|
73 | inv[1][0] = invdet * (m[2][0] * m[1][2] - m[2][2] * m[1][0]); |
|
|
74 | inv[1][1] = invdet * (m[2][2] * m[0][0] - m[2][0] * m[0][2]); |
|
|
75 | inv[1][2] = invdet * (m[1][0] * m[0][2] - m[1][2] * m[0][0]); |
|
|
76 | |
|
|
77 | inv[2][0] = invdet * (m[2][1] * m[1][0] - m[2][0] * m[1][1]); |
|
|
78 | inv[2][1] = invdet * (m[2][0] * m[0][1] - m[2][1] * m[0][0]); |
|
|
79 | inv[2][2] = invdet * (m[1][1] * m[0][0] - m[1][0] * m[0][1]); |
|
|
80 | |
|
|
81 | return inv; |
|
|
82 | } |
|
|
83 | |
|
|
84 | static mat3x3 |
|
|
85 | operator *(const mat3x3 &a, const mat3x3 &b) |
|
|
86 | { |
|
|
87 | mat3x3 r; |
|
|
88 | |
|
|
89 | for (int i = 0; i < 3; ++i) |
|
|
90 | for (int j = 0; j < 3; ++j) |
|
|
91 | r[i][j] = a[i][0] * b[0][j] |
|
|
92 | + a[i][1] * b[1][j] |
|
|
93 | + a[i][2] * b[2][j]; |
|
|
94 | |
|
|
95 | return r; |
|
|
96 | } |
|
|
97 | |
|
|
98 | mat3x3 |
|
|
99 | mat3x3::translate (nv x, nv y) |
|
|
100 | { |
|
|
101 | return mat3x3 ( |
|
|
102 | 1, 0, x, |
|
|
103 | 0, 1, y, |
|
|
104 | 0, 0, 1 |
|
|
105 | ); |
|
|
106 | } |
|
|
107 | |
|
|
108 | mat3x3 |
|
|
109 | mat3x3::scale (nv s, nv t) |
|
|
110 | { |
|
|
111 | return mat3x3 ( |
|
|
112 | s, 0, 0, |
|
|
113 | 0, t, 0, |
|
|
114 | 0, 0, 1 |
|
|
115 | ); |
|
|
116 | } |
|
|
117 | |
|
|
118 | // clockwise |
|
|
119 | mat3x3 |
|
|
120 | mat3x3::rotate (nv phi) |
|
|
121 | { |
|
|
122 | nv s = sin (phi); |
|
|
123 | nv c = cos (phi); |
|
|
124 | |
|
|
125 | return mat3x3 ( |
|
|
126 | c, -s, 0, |
|
|
127 | s, c, 0, |
|
|
128 | 0, 0, 1 |
|
|
129 | ); |
|
|
130 | } |
|
|
131 | |
|
|
132 | } |
|
|
133 | |
|
|
134 | #if 0 |
|
|
135 | struct pict |
|
|
136 | { |
|
|
137 | Display *dpy; |
|
|
138 | Picture pic; |
|
|
139 | |
|
|
140 | operator Picture () const |
|
|
141 | { |
|
|
142 | return pic; |
|
|
143 | } |
|
|
144 | |
|
|
145 | pict () |
|
|
146 | : pic (0) |
|
|
147 | { |
|
|
148 | } |
|
|
149 | |
|
|
150 | pict (rxvt_img *img, XRenderPictFormat *format = 0) |
|
|
151 | : dpy (img->s->display->dpy) |
|
|
152 | { |
|
|
153 | XRenderPictureAttributes pa; |
|
|
154 | pa.repeat = img->repeat; |
|
|
155 | pic = XRenderCreatePicture (dpy, img->pm, format ? format : img->format, CPRepeat, &pa); |
|
|
156 | } |
|
|
157 | |
|
|
158 | ~pict () |
|
|
159 | { |
|
|
160 | if (pic) |
|
|
161 | XRenderFreePicture (dpy, pic); |
|
|
162 | } |
|
|
163 | }; |
|
|
164 | #endif |
6 | |
165 | |
7 | static XRenderPictFormat * |
166 | static XRenderPictFormat * |
8 | find_alpha_format_for (Display *dpy, XRenderPictFormat *format) |
167 | find_alpha_format_for (Display *dpy, XRenderPictFormat *format) |
9 | { |
168 | { |
10 | if (format->direct.alphaMask) |
169 | if (format->direct.alphaMask) |
… | |
… | |
215 | pm = XCreatePixmap (s->display->dpy, s->display->root, w, h, format->depth); |
374 | pm = XCreatePixmap (s->display->dpy, s->display->root, w, h, format->depth); |
216 | ref = new pixref (w, h); |
375 | ref = new pixref (w, h); |
217 | } |
376 | } |
218 | |
377 | |
219 | Picture |
378 | Picture |
220 | rxvt_img::src_picture () |
379 | rxvt_img::picture () |
221 | { |
380 | { |
222 | Display *dpy = s->display->dpy; |
381 | Display *dpy = s->display->dpy; |
223 | |
382 | |
224 | XRenderPictureAttributes pa; |
383 | XRenderPictureAttributes pa; |
225 | pa.repeat = repeat; |
384 | pa.repeat = repeat; |
… | |
… | |
249 | rxvt_img::fill (const rgba &c) |
408 | rxvt_img::fill (const rgba &c) |
250 | { |
409 | { |
251 | XRenderColor rc = { c.r, c.g, c.b, c.a }; |
410 | XRenderColor rc = { c.r, c.g, c.b, c.a }; |
252 | |
411 | |
253 | Display *dpy = s->display->dpy; |
412 | Display *dpy = s->display->dpy; |
254 | Picture src = src_picture (); |
413 | Picture src = picture (); |
255 | XRenderFillRectangle (dpy, PictOpSrc, src, &rc, 0, 0, w, h); |
414 | XRenderFillRectangle (dpy, PictOpSrc, src, &rc, 0, 0, w, h); |
256 | XRenderFreePicture (dpy, src); |
415 | XRenderFreePicture (dpy, src); |
257 | } |
416 | } |
258 | |
417 | |
259 | void |
418 | void |
… | |
… | |
265 | Display *dpy = s->display->dpy; |
424 | Display *dpy = s->display->dpy; |
266 | |
425 | |
267 | rxvt_img *img = new rxvt_img (s, find_alpha_format_for (dpy, format), x, y, w, h, repeat); |
426 | rxvt_img *img = new rxvt_img (s, find_alpha_format_for (dpy, format), x, y, w, h, repeat); |
268 | img->alloc (); |
427 | img->alloc (); |
269 | |
428 | |
270 | Picture src = src_picture (); |
429 | Picture src = picture (); |
271 | Picture dst = XRenderCreatePicture (dpy, img->pm, img->format, 0, 0); |
430 | Picture dst = XRenderCreatePicture (dpy, img->pm, img->format, 0, 0); |
272 | |
431 | |
273 | XRenderComposite (dpy, PictOpSrc, src, None, dst, 0, 0, 0, 0, 0, 0, w, h); |
432 | XRenderComposite (dpy, PictOpSrc, src, None, dst, 0, 0, 0, 0, 0, 0, w, h); |
274 | |
433 | |
275 | XRenderFreePicture (dpy, src); |
434 | XRenderFreePicture (dpy, src); |
… | |
… | |
280 | |
439 | |
281 | delete img; |
440 | delete img; |
282 | } |
441 | } |
283 | |
442 | |
284 | static void |
443 | static void |
285 | get_gaussian_kernel (int radius, int width, double *kernel, XFixed *params) |
444 | get_gaussian_kernel (int radius, int width, nv *kernel, XFixed *params) |
286 | { |
445 | { |
287 | double sigma = radius / 2.0; |
446 | nv sigma = radius / 2.0; |
288 | double scale = sqrt (2.0 * M_PI) * sigma; |
447 | nv scale = sqrt (2.0 * M_PI) * sigma; |
289 | double sum = 0.0; |
448 | nv sum = 0.0; |
290 | |
449 | |
291 | for (int i = 0; i < width; i++) |
450 | for (int i = 0; i < width; i++) |
292 | { |
451 | { |
293 | double x = i - width / 2; |
452 | nv x = i - width / 2; |
294 | kernel[i] = exp (-(x * x) / (2.0 * sigma * sigma)) / scale; |
453 | kernel[i] = exp (-(x * x) / (2.0 * sigma * sigma)) / scale; |
295 | sum += kernel[i]; |
454 | sum += kernel[i]; |
296 | } |
455 | } |
297 | |
456 | |
298 | params[0] = XDoubleToFixed (width); |
457 | params[0] = XDoubleToFixed (width); |
… | |
… | |
308 | if (!(s->display->flags & DISPLAY_HAS_RENDER_CONV)) |
467 | if (!(s->display->flags & DISPLAY_HAS_RENDER_CONV)) |
309 | return clone (); |
468 | return clone (); |
310 | |
469 | |
311 | Display *dpy = s->display->dpy; |
470 | Display *dpy = s->display->dpy; |
312 | int size = max (rh, rv) * 2 + 1; |
471 | int size = max (rh, rv) * 2 + 1; |
313 | double *kernel = (double *)malloc (size * sizeof (double)); |
472 | nv *kernel = (nv *)malloc (size * sizeof (nv)); |
314 | XFixed *params = (XFixed *)malloc ((size + 2) * sizeof (XFixed)); |
473 | XFixed *params = (XFixed *)malloc ((size + 2) * sizeof (XFixed)); |
315 | rxvt_img *img = new rxvt_img (s, format, x, y, w, h, repeat); |
474 | rxvt_img *img = new rxvt_img (s, format, x, y, w, h, repeat); |
316 | img->alloc (); |
475 | img->alloc (); |
317 | |
476 | |
318 | XRenderPictureAttributes pa; |
477 | XRenderPictureAttributes pa; |
… | |
… | |
449 | g = (g * (a >> 8)) >> 8; |
608 | g = (g * (a >> 8)) >> 8; |
450 | b = (b * (a >> 8)) >> 8; |
609 | b = (b * (a >> 8)) >> 8; |
451 | |
610 | |
452 | Display *dpy = s->display->dpy; |
611 | Display *dpy = s->display->dpy; |
453 | |
612 | |
454 | Picture src = src_picture (); |
613 | Picture src = picture (); |
455 | Picture dst = XRenderCreatePicture (dpy, img->pm, format, 0, 0); |
614 | Picture dst = XRenderCreatePicture (dpy, img->pm, format, 0, 0); |
456 | Picture mul = create_xrender_mask (dpy, pm, True, True); |
615 | Picture mul = create_xrender_mask (dpy, pm, True, True); |
457 | |
616 | |
458 | //TODO: this operator does not yet implement some useful contrast |
617 | //TODO: this operator does not yet implement some useful contrast |
459 | while (r | g | b | a) |
618 | while (r | g | b | a) |
… | |
… | |
476 | ::swap (img->pm , pm ); |
635 | ::swap (img->pm , pm ); |
477 | |
636 | |
478 | delete img; |
637 | delete img; |
479 | } |
638 | } |
480 | |
639 | |
|
|
640 | void |
|
|
641 | rxvt_img::draw (rxvt_img *img, int op, nv mask) |
|
|
642 | { |
|
|
643 | unshare (); |
|
|
644 | |
|
|
645 | Display *dpy = s->display->dpy; |
|
|
646 | Picture src = img->picture (); |
|
|
647 | Picture dst = picture (); |
|
|
648 | Picture mask_p = 0; |
|
|
649 | |
|
|
650 | if (mask != 1.) |
|
|
651 | { |
|
|
652 | mask_p = create_xrender_mask (dpy, img->pm, False, False); |
|
|
653 | XRenderColor mask_c = { 0, 0, 0, float_to_component (mask) }; |
|
|
654 | XRenderFillRectangle (dpy, PictOpSrc, mask, &mask_c, 0, 0, 1, 1); |
|
|
655 | } |
|
|
656 | |
|
|
657 | XRenderComposite (dpy, op, src, mask_p, dst, x - img->x, y - img->y, 0, 0, 0, 0, w, h); |
|
|
658 | |
|
|
659 | XRenderFreePicture (dpy, src); |
|
|
660 | XRenderFreePicture (dpy, dst); |
|
|
661 | |
|
|
662 | if (mask_p) |
|
|
663 | XRenderFreePicture (dpy, mask_p); |
|
|
664 | } |
|
|
665 | |
481 | rxvt_img * |
666 | rxvt_img * |
482 | rxvt_img::clone () |
667 | rxvt_img::clone () |
483 | { |
668 | { |
484 | return new rxvt_img (*this); |
669 | return new rxvt_img (*this); |
485 | } |
670 | } |
… | |
… | |
498 | && repeat == RepeatNone; // and we have no good pixels to fill with |
683 | && repeat == RepeatNone; // and we have no good pixels to fill with |
499 | |
684 | |
500 | rxvt_img *img = new rxvt_img (s, alpha ? find_alpha_format_for (dpy, format) : format, 0, 0, w, h, repeat); |
685 | rxvt_img *img = new rxvt_img (s, alpha ? find_alpha_format_for (dpy, format) : format, 0, 0, w, h, repeat); |
501 | img->alloc (); |
686 | img->alloc (); |
502 | |
687 | |
503 | Picture src = src_picture (); |
688 | Picture src = picture (); |
504 | Picture dst = XRenderCreatePicture (dpy, img->pm, img->format, 0, 0); |
689 | Picture dst = XRenderCreatePicture (dpy, img->pm, img->format, 0, 0); |
505 | |
690 | |
506 | if (alpha) |
691 | if (alpha) |
507 | { |
692 | { |
508 | XRenderColor rc = { 0, 0, 0, 0 }; |
693 | XRenderColor rc = { 0, 0, 0, 0 }; |
509 | XRenderFillRectangle (dpy, PictOpSrc, dst, &rc, 0, 0, w, h);//TODO: split into four fillrectangles |
694 | XRenderFillRectangle (dpy, PictOpSrc, dst, &rc, 0, 0, w, h);//TODO: split into four fillrectangles |
510 | XRenderComposite (dpy, PictOpSrc, src, None, dst, 0, 0, 0, 0, -x, -y, ref->w, ref->h); |
695 | XRenderComposite (dpy, PictOpSrc, src, None, dst, 0, 0, 0, 0, x, y, ref->w, ref->h); |
511 | } |
696 | } |
512 | else |
697 | else |
513 | XRenderComposite (dpy, PictOpSrc, src, None, dst, x, y, 0, 0, 0, 0, w, h); |
698 | XRenderComposite (dpy, PictOpSrc, src, None, dst, -x, -y, 0, 0, 0, 0, w, h); |
514 | |
699 | |
515 | XRenderFreePicture (dpy, src); |
700 | XRenderFreePicture (dpy, src); |
516 | XRenderFreePicture (dpy, dst); |
701 | XRenderFreePicture (dpy, dst); |
517 | |
702 | |
518 | return img; |
703 | return img; |
… | |
… | |
521 | rxvt_img * |
706 | rxvt_img * |
522 | rxvt_img::sub_rect (int x, int y, int width, int height) |
707 | rxvt_img::sub_rect (int x, int y, int width, int height) |
523 | { |
708 | { |
524 | rxvt_img *img = clone (); |
709 | rxvt_img *img = clone (); |
525 | |
710 | |
526 | img->x += x; |
711 | img->x -= x; |
527 | img->y += y; |
712 | img->y -= y; |
528 | |
713 | |
529 | if (w != width || h != height) |
714 | if (w != width || h != height) |
530 | { |
715 | { |
531 | img->w = width; |
716 | img->w = width; |
532 | img->h = height; |
717 | img->h = height; |
… | |
… | |
537 | } |
722 | } |
538 | |
723 | |
539 | return img; |
724 | return img; |
540 | } |
725 | } |
541 | |
726 | |
542 | static void |
|
|
543 | mat_invert (double mat[3][3], double (&inv)[3][3]) |
|
|
544 | { |
|
|
545 | double s0 = mat [2][2] * mat [1][1] - mat [2][1] * mat [1][2]; |
|
|
546 | double s1 = mat [2][1] * mat [0][2] - mat [2][2] * mat [0][1]; |
|
|
547 | double s2 = mat [1][2] * mat [0][1] - mat [1][1] * mat [0][2]; |
|
|
548 | |
|
|
549 | double 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 | |
|
|
564 | static double |
|
|
565 | mat_apply (double mat[3][3], int i, double x, double y) |
|
|
566 | { |
|
|
567 | double v = mat [i][0] * x + mat [i][1] * y + mat [i][2]; |
|
|
568 | double w = mat [2][0] * x + mat [2][1] * y + mat [2][2]; |
|
|
569 | |
|
|
570 | return v * (1. / w); |
|
|
571 | } |
|
|
572 | |
|
|
573 | rxvt_img * |
727 | rxvt_img * |
574 | rxvt_img::transform (double matrix[3][3]) |
728 | rxvt_img::transform (const nv matrix[3][3]) |
575 | { |
729 | { |
576 | // find new offset |
730 | return transform (mat3x3 (&matrix[0][0])); |
577 | int ox = mat_apply (matrix, 0, x, y); |
731 | } |
578 | int oy = mat_apply (matrix, 1, x, y); |
732 | |
|
|
733 | rxvt_img * |
|
|
734 | rxvt_img::transform (const nv *matrix) |
|
|
735 | { |
|
|
736 | mat3x3 m (matrix); |
579 | |
737 | |
580 | // calculate new pixel bounding box coordinates |
738 | // calculate new pixel bounding box coordinates |
581 | double d [2], rmin[2], rmax[2]; |
739 | nv r[2], rmin[2], rmax[2]; |
582 | |
740 | |
583 | for (int i = 0; i < 2; ++i) |
741 | for (int i = 0; i < 2; ++i) |
584 | { |
742 | { |
585 | double v; |
743 | nv v; |
|
|
744 | |
586 | v = mat_apply (matrix, i, 0, 0); rmin [i] = rmax [i] = v; d [i] = v; |
745 | v = m.apply1 (i, 0+x, 0+y); rmin [i] = rmax [i] = v; r [i] = v; |
587 | v = mat_apply (matrix, i, w, 0); min_it (rmin [i], v); max_it (rmax [i], v); |
746 | v = m.apply1 (i, w+x, 0+y); 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); |
747 | v = m.apply1 (i, 0+x, h+y); 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); |
748 | v = m.apply1 (i, w+x, h+y); min_it (rmin [i], v); max_it (rmax [i], v); |
590 | } |
749 | } |
591 | |
750 | |
|
|
751 | float sx = rmin [0] - x; |
|
|
752 | float sy = rmin [1] - y; |
|
|
753 | |
|
|
754 | // TODO: adjust matrix for subpixel accuracy |
592 | int dx = floor (rmin [0]); |
755 | int nx = floor (rmin [0]); |
593 | int dy = floor (rmin [1]); |
756 | int ny = floor (rmin [1]); |
594 | |
757 | |
595 | int new_width = ceil (rmax [0] - dx); |
758 | int new_width = ceil (rmax [0] - rmin [0]); |
596 | int new_height = ceil (rmax [1] - dy); |
759 | int new_height = ceil (rmax [1] - rmin [1]); |
597 | |
760 | |
598 | double inv[3][3]; |
761 | m = mat3x3::translate (-x, -y) * m * mat3x3::translate (x, y); |
599 | mat_invert (matrix, inv); |
|
|
600 | |
762 | |
|
|
763 | mat3x3 inv = m.invert (); |
|
|
764 | |
601 | rxvt_img *img = new rxvt_img (s, format, ox - dx - d [0], oy - dy - d [1], new_width, new_height, repeat); |
765 | rxvt_img *img = new rxvt_img (s, format, nx, ny, new_width, new_height, repeat); |
602 | img->alloc (); |
766 | img->alloc (); |
603 | |
767 | |
604 | Display *dpy = s->display->dpy; |
768 | Display *dpy = s->display->dpy; |
605 | Picture src = src_picture (); |
769 | Picture src = picture (); |
606 | Picture dst = XRenderCreatePicture (dpy, img->pm, img->format, 0, 0); |
770 | Picture dst = XRenderCreatePicture (dpy, img->pm, img->format, 0, 0); |
607 | |
771 | |
608 | XTransform xfrm; |
772 | XTransform xfrm; |
609 | |
773 | |
610 | for (int i = 0; i < 3; ++i) |
774 | for (int i = 0; i < 3; ++i) |
611 | for (int j = 0; j < 3; ++j) |
775 | for (int j = 0; j < 3; ++j) |
612 | xfrm.matrix [i][j] = XDoubleToFixed (inv [i][j]); |
776 | xfrm.matrix [i][j] = XDoubleToFixed (inv [i][j]); |
613 | |
777 | |
614 | XRenderSetPictureFilter (dpy, src, "good", 0, 0); |
778 | XRenderSetPictureFilter (dpy, src, "good", 0, 0); |
615 | XRenderSetPictureTransform (dpy, src, &xfrm); |
779 | XRenderSetPictureTransform (dpy, src, &xfrm); |
616 | XRenderComposite (dpy, PictOpSrc, src, None, dst, dx, dy, 0, 0, 0, 0, new_width, new_height); |
780 | XRenderComposite (dpy, PictOpSrc, src, None, dst, sx, sy, 0, 0, 0, 0, new_width, new_height); |
617 | |
781 | |
618 | XRenderFreePicture (dpy, src); |
782 | XRenderFreePicture (dpy, src); |
619 | XRenderFreePicture (dpy, dst); |
783 | XRenderFreePicture (dpy, dst); |
620 | |
784 | |
621 | return img; |
785 | return img; |
… | |
… | |
625 | rxvt_img::scale (int new_width, int new_height) |
789 | rxvt_img::scale (int new_width, int new_height) |
626 | { |
790 | { |
627 | if (w == new_width && h == new_height) |
791 | if (w == new_width && h == new_height) |
628 | return clone (); |
792 | return clone (); |
629 | |
793 | |
630 | double matrix[3][3] = { |
|
|
631 | { new_width / (double)w, 0, 0 }, |
|
|
632 | { 0, new_height / (double)h, 0 }, |
|
|
633 | { 0, 0, 1 } |
|
|
634 | }; |
|
|
635 | |
|
|
636 | int old_repeat_mode = repeat; |
794 | int old_repeat_mode = repeat; |
637 | repeat = RepeatPad; // not right, but xrender can't properly scale it seems |
795 | repeat = RepeatPad; // not right, but xrender can't properly scale it seems |
638 | |
796 | |
639 | rxvt_img *img = transform (matrix); |
797 | rxvt_img *img = transform (mat3x3::scale (new_width / (nv)w, new_height / (nv)h)); |
640 | |
798 | |
641 | repeat = old_repeat_mode; |
799 | repeat = old_repeat_mode; |
642 | img->repeat = repeat; |
800 | img->repeat = repeat; |
643 | |
801 | |
644 | return img; |
802 | return img; |
645 | } |
803 | } |
646 | |
804 | |
647 | rxvt_img * |
805 | rxvt_img * |
648 | rxvt_img::rotate (int cx, int cy, double phi) |
806 | rxvt_img::rotate (int cx, int cy, nv phi) |
649 | { |
807 | { |
650 | double s = sin (phi); |
808 | #if 0 |
651 | double c = cos (phi); |
|
|
652 | |
|
|
653 | double matrix[3][3] = { |
|
|
654 | { c, -s, cx - c * cx + s * cy }, |
809 | { c, -s, cx - c * cx + s * cy }, |
655 | { s, c, cy - s * cx - c * cy }, |
810 | { s, c, cy - s * cx - c * cy }, |
656 | { 0, 0, 1 } |
811 | { 0, 0, 1 } |
657 | //{ c, -s, 0 }, |
812 | #endif |
658 | //{ s, c, 0 }, |
|
|
659 | //{ 0, 0, 1 } |
|
|
660 | }; |
|
|
661 | |
813 | |
662 | //move (-cx, -cy); |
814 | move (-cx, -cy); |
663 | rxvt_img *img = transform (matrix); |
815 | rxvt_img *img = transform (mat3x3::rotate (phi)); |
664 | //move ( cx, cy); |
816 | move ( cx, cy); |
665 | //img->move (cx, cy); |
817 | img->move (cx, cy); |
666 | |
818 | |
667 | return img; |
819 | return img; |
668 | } |
820 | } |
669 | |
821 | |
670 | rxvt_img * |
822 | rxvt_img * |
… | |
… | |
675 | |
827 | |
676 | rxvt_img *img = new rxvt_img (s, new_format, x, y, w, h, repeat); |
828 | rxvt_img *img = new rxvt_img (s, new_format, x, y, w, h, repeat); |
677 | img->alloc (); |
829 | img->alloc (); |
678 | |
830 | |
679 | Display *dpy = s->display->dpy; |
831 | Display *dpy = s->display->dpy; |
680 | Picture src = src_picture (); |
832 | Picture src = picture (); |
681 | Picture dst = XRenderCreatePicture (dpy, img->pm, new_format, 0, 0); |
833 | Picture dst = XRenderCreatePicture (dpy, img->pm, new_format, 0, 0); |
682 | int op = PictOpSrc; |
834 | int op = PictOpSrc; |
683 | |
835 | |
684 | if (format->direct.alphaMask && !new_format->direct.alphaMask) |
836 | if (format->direct.alphaMask && !new_format->direct.alphaMask) |
685 | { |
837 | { |
… | |
… | |
697 | |
849 | |
698 | return img; |
850 | return img; |
699 | } |
851 | } |
700 | |
852 | |
701 | rxvt_img * |
853 | rxvt_img * |
702 | rxvt_img::blend (rxvt_img *img, double factor) |
854 | rxvt_img::blend (rxvt_img *img, nv factor) |
703 | { |
855 | { |
704 | rxvt_img *img2 = clone (); |
856 | rxvt_img *img2 = clone (); |
705 | Display *dpy = s->display->dpy; |
857 | Display *dpy = s->display->dpy; |
706 | Picture src = img->src_picture (); |
858 | Picture src = img->picture (); |
707 | Picture dst = XRenderCreatePicture (dpy, img2->pm, img2->format, 0, 0); |
859 | Picture dst = XRenderCreatePicture (dpy, img2->pm, img2->format, 0, 0); |
708 | Picture mask = create_xrender_mask (dpy, img->pm, False, False); |
860 | Picture mask = create_xrender_mask (dpy, img->pm, False, False); |
709 | |
861 | |
710 | XRenderColor mask_c; |
862 | XRenderColor mask_c; |
711 | |
863 | |