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 | #if 0 |
|
|
8 | struct pict |
|
|
9 | { |
|
|
10 | Display *dpy; |
|
|
11 | Picture pic; |
|
|
12 | |
|
|
13 | operator Picture () const |
|
|
14 | { |
|
|
15 | return pic; |
|
|
16 | } |
|
|
17 | |
|
|
18 | pict () |
|
|
19 | : pic (0) |
|
|
20 | { |
|
|
21 | } |
|
|
22 | |
|
|
23 | pict (rxvt_img *img, XRenderPictFormat *format = 0) |
|
|
24 | : dpy (img->s->display->dpy) |
|
|
25 | { |
|
|
26 | XRenderPictureAttributes pa; |
|
|
27 | pa.repeat = img->repeat; |
|
|
28 | pic = XRenderCreatePicture (dpy, img->pm, format ? format : img->format, CPRepeat, &pa); |
|
|
29 | } |
|
|
30 | |
|
|
31 | ~pict () |
|
|
32 | { |
|
|
33 | if (pic) |
|
|
34 | XRenderFreePicture (dpy, pic); |
|
|
35 | } |
|
|
36 | }; |
|
|
37 | #endif |
|
|
38 | |
|
|
39 | static XRenderPictFormat * |
|
|
40 | find_alpha_format_for (Display *dpy, XRenderPictFormat *format) |
|
|
41 | { |
|
|
42 | if (format->direct.alphaMask) |
|
|
43 | return format; // already has alpha |
|
|
44 | |
|
|
45 | // try to find a suitable alpha format, one bit alpha is enough for our purposes |
|
|
46 | if (format->type == PictTypeDirect) |
|
|
47 | for (int n = 0; XRenderPictFormat *f = XRenderFindFormat (dpy, 0, 0, n); ++n) |
|
|
48 | if (f->direct.alphaMask |
|
|
49 | && f->type == PictTypeDirect |
|
|
50 | && ecb_popcount32 (f->direct.redMask ) >= ecb_popcount32 (format->direct.redMask ) |
|
|
51 | && ecb_popcount32 (f->direct.greenMask) >= ecb_popcount32 (format->direct.greenMask) |
|
|
52 | && ecb_popcount32 (f->direct.blueMask ) >= ecb_popcount32 (format->direct.blueMask )) |
|
|
53 | return f; |
|
|
54 | |
|
|
55 | // should be a very good fallback |
|
|
56 | return XRenderFindStandardFormat (dpy, PictStandardARGB32); |
|
|
57 | } |
6 | |
58 | |
7 | rxvt_img::rxvt_img (rxvt_screen *screen, XRenderPictFormat *format, int x, int y, int width, int height, int repeat) |
59 | 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), |
60 | : s(screen), x(x), y(y), w(width), h(height), format(format), repeat(repeat), |
9 | pm(0), ref(0) |
61 | pm(0), ref(0) |
10 | { |
62 | { |
… | |
… | |
195 | pm = XCreatePixmap (s->display->dpy, s->display->root, w, h, format->depth); |
247 | pm = XCreatePixmap (s->display->dpy, s->display->root, w, h, format->depth); |
196 | ref = new pixref (w, h); |
248 | ref = new pixref (w, h); |
197 | } |
249 | } |
198 | |
250 | |
199 | Picture |
251 | Picture |
200 | rxvt_img::src_picture () |
252 | rxvt_img::picture () |
201 | { |
253 | { |
202 | Display *dpy = s->display->dpy; |
254 | Display *dpy = s->display->dpy; |
203 | |
255 | |
204 | XRenderPictureAttributes pa; |
256 | XRenderPictureAttributes pa; |
205 | pa.repeat = repeat; |
257 | pa.repeat = repeat; |
… | |
… | |
224 | pm = pm2; |
276 | pm = pm2; |
225 | ref = new pixref (ref->w, ref->h); |
277 | ref = new pixref (ref->w, ref->h); |
226 | } |
278 | } |
227 | |
279 | |
228 | void |
280 | void |
229 | rxvt_img::fill (const rxvt_color &c) |
281 | rxvt_img::fill (const rgba &c) |
230 | { |
282 | { |
231 | rgba cc; |
|
|
232 | c.get (cc); |
|
|
233 | XRenderColor rc = { cc.r, cc.g, cc.b, cc.a }; |
283 | XRenderColor rc = { c.r, c.g, c.b, c.a }; |
234 | |
284 | |
235 | Display *dpy = s->display->dpy; |
285 | Display *dpy = s->display->dpy; |
236 | Picture src = src_picture (); |
286 | Picture src = picture (); |
237 | XRenderFillRectangle (dpy, PictOpSrc, src, &rc, 0, 0, w, h); |
287 | XRenderFillRectangle (dpy, PictOpSrc, src, &rc, 0, 0, w, h); |
238 | XRenderFreePicture (dpy, src); |
288 | XRenderFreePicture (dpy, src); |
239 | } |
289 | } |
240 | |
290 | |
|
|
291 | void |
|
|
292 | rxvt_img::add_alpha () |
|
|
293 | { |
|
|
294 | if (format->direct.alphaMask) |
|
|
295 | return; |
|
|
296 | |
|
|
297 | Display *dpy = s->display->dpy; |
|
|
298 | |
|
|
299 | rxvt_img *img = new rxvt_img (s, find_alpha_format_for (dpy, format), x, y, w, h, repeat); |
|
|
300 | img->alloc (); |
|
|
301 | |
|
|
302 | Picture src = picture (); |
|
|
303 | Picture dst = XRenderCreatePicture (dpy, img->pm, img->format, 0, 0); |
|
|
304 | |
|
|
305 | XRenderComposite (dpy, PictOpSrc, src, None, dst, 0, 0, 0, 0, 0, 0, w, h); |
|
|
306 | |
|
|
307 | XRenderFreePicture (dpy, src); |
|
|
308 | XRenderFreePicture (dpy, dst); |
|
|
309 | |
|
|
310 | ::swap (img->ref, ref); |
|
|
311 | ::swap (img->pm , pm ); |
|
|
312 | |
|
|
313 | delete img; |
|
|
314 | } |
|
|
315 | |
241 | static void |
316 | static void |
242 | get_gaussian_kernel (int radius, int width, double *kernel, XFixed *params) |
317 | get_gaussian_kernel (int radius, int width, rxvt_img::nv *kernel, XFixed *params) |
243 | { |
318 | { |
244 | double sigma = radius / 2.0; |
319 | rxvt_img::nv sigma = radius / 2.0; |
245 | double scale = sqrt (2.0 * M_PI) * sigma; |
320 | rxvt_img::nv scale = sqrt (2.0 * M_PI) * sigma; |
246 | double sum = 0.0; |
321 | rxvt_img::nv sum = 0.0; |
247 | |
322 | |
248 | for (int i = 0; i < width; i++) |
323 | for (int i = 0; i < width; i++) |
249 | { |
324 | { |
250 | double x = i - width / 2; |
325 | rxvt_img::nv x = i - width / 2; |
251 | kernel[i] = exp (-(x * x) / (2.0 * sigma * sigma)) / scale; |
326 | kernel[i] = exp (-(x * x) / (2.0 * sigma * sigma)) / scale; |
252 | sum += kernel[i]; |
327 | sum += kernel[i]; |
253 | } |
328 | } |
254 | |
329 | |
255 | params[0] = XDoubleToFixed (width); |
330 | params[0] = XDoubleToFixed (width); |
… | |
… | |
265 | if (!(s->display->flags & DISPLAY_HAS_RENDER_CONV)) |
340 | if (!(s->display->flags & DISPLAY_HAS_RENDER_CONV)) |
266 | return clone (); |
341 | return clone (); |
267 | |
342 | |
268 | Display *dpy = s->display->dpy; |
343 | Display *dpy = s->display->dpy; |
269 | int size = max (rh, rv) * 2 + 1; |
344 | int size = max (rh, rv) * 2 + 1; |
270 | double *kernel = (double *)malloc (size * sizeof (double)); |
345 | nv *kernel = (nv *)malloc (size * sizeof (nv)); |
271 | XFixed *params = (XFixed *)malloc ((size + 2) * sizeof (XFixed)); |
346 | XFixed *params = (XFixed *)malloc ((size + 2) * sizeof (XFixed)); |
272 | rxvt_img *img = new rxvt_img (s, format, x, y, w, h, repeat); |
347 | rxvt_img *img = new rxvt_img (s, format, x, y, w, h, repeat); |
273 | img->alloc (); |
348 | img->alloc (); |
274 | |
349 | |
275 | XRenderPictureAttributes pa; |
350 | XRenderPictureAttributes pa; |
… | |
… | |
397 | if (r < 0 || g < 0 || b < 0 || a < 0) |
472 | if (r < 0 || g < 0 || b < 0 || a < 0) |
398 | rxvt_fatal ("rxvt_img::contrast does not support negative values.\n"); |
473 | rxvt_fatal ("rxvt_img::contrast does not support negative values.\n"); |
399 | |
474 | |
400 | rxvt_img *img = new rxvt_img (s, format, x, y, w, h, repeat); |
475 | rxvt_img *img = new rxvt_img (s, format, x, y, w, h, repeat); |
401 | img->alloc (); |
476 | img->alloc (); |
402 | |
477 | 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 | |
478 | |
409 | // premultiply (yeah, these are not exact, sue me or fix it) |
479 | // premultiply (yeah, these are not exact, sue me or fix it) |
410 | r = (r * (a >> 8)) >> 8; |
480 | r = (r * (a >> 8)) >> 8; |
411 | g = (g * (a >> 8)) >> 8; |
481 | g = (g * (a >> 8)) >> 8; |
412 | b = (b * (a >> 8)) >> 8; |
482 | b = (b * (a >> 8)) >> 8; |
413 | |
483 | |
414 | Display *dpy = s->display->dpy; |
484 | Display *dpy = s->display->dpy; |
415 | |
485 | |
416 | Picture src = src_picture (); |
486 | Picture src = picture (); |
417 | Picture dst = XRenderCreatePicture (dpy, img->pm, format, 0, 0); |
487 | Picture dst = XRenderCreatePicture (dpy, img->pm, format, 0, 0); |
418 | Picture mul = create_xrender_mask (dpy, pm, True, True); |
488 | Picture mul = create_xrender_mask (dpy, pm, True, True); |
419 | |
489 | |
420 | //TODO: this operator does not yet implement some useful contrast |
490 | //TODO: this operator does not yet implement some useful contrast |
421 | while (r | g | b | a) |
491 | while (r | g | b | a) |
… | |
… | |
438 | ::swap (img->pm , pm ); |
508 | ::swap (img->pm , pm ); |
439 | |
509 | |
440 | delete img; |
510 | delete img; |
441 | } |
511 | } |
442 | |
512 | |
|
|
513 | void |
|
|
514 | rxvt_img::draw (rxvt_img *img, int op, nv mask) |
|
|
515 | { |
|
|
516 | unshare (); |
|
|
517 | |
|
|
518 | Display *dpy = s->display->dpy; |
|
|
519 | Picture src = img->picture (); |
|
|
520 | Picture dst = picture (); |
|
|
521 | Picture mask_p = 0; |
|
|
522 | |
|
|
523 | if (mask != 1.) |
|
|
524 | { |
|
|
525 | mask_p = create_xrender_mask (dpy, img->pm, False, False); |
|
|
526 | XRenderColor mask_c = { 0, 0, 0, float_to_component (mask) }; |
|
|
527 | XRenderFillRectangle (dpy, PictOpSrc, mask, &mask_c, 0, 0, 1, 1); |
|
|
528 | } |
|
|
529 | |
|
|
530 | XRenderComposite (dpy, op, src, mask_p, dst, x - img->x, y - img->y, 0, 0, 0, 0, w, h); |
|
|
531 | |
|
|
532 | XRenderFreePicture (dpy, src); |
|
|
533 | XRenderFreePicture (dpy, dst); |
|
|
534 | |
|
|
535 | if (mask_p) |
|
|
536 | XRenderFreePicture (dpy, mask_p); |
|
|
537 | } |
|
|
538 | |
443 | rxvt_img * |
539 | rxvt_img * |
444 | rxvt_img::clone () |
540 | rxvt_img::clone () |
445 | { |
541 | { |
446 | return new rxvt_img (*this); |
542 | 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 | } |
543 | } |
468 | |
544 | |
469 | rxvt_img * |
545 | rxvt_img * |
470 | rxvt_img::reify () |
546 | rxvt_img::reify () |
471 | { |
547 | { |
… | |
… | |
480 | && repeat == RepeatNone; // and we have no good pixels to fill with |
556 | && repeat == RepeatNone; // and we have no good pixels to fill with |
481 | |
557 | |
482 | rxvt_img *img = new rxvt_img (s, alpha ? find_alpha_format_for (dpy, format) : format, 0, 0, w, h, repeat); |
558 | rxvt_img *img = new rxvt_img (s, alpha ? find_alpha_format_for (dpy, format) : format, 0, 0, w, h, repeat); |
483 | img->alloc (); |
559 | img->alloc (); |
484 | |
560 | |
485 | Picture src = src_picture (); |
561 | Picture src = picture (); |
486 | Picture dst = XRenderCreatePicture (dpy, img->pm, img->format, 0, 0); |
562 | Picture dst = XRenderCreatePicture (dpy, img->pm, img->format, 0, 0); |
487 | |
563 | |
488 | if (alpha) |
564 | if (alpha) |
489 | { |
565 | { |
490 | XRenderColor rc = { 0, 0, 0, 0 }; |
566 | XRenderColor rc = { 0, 0, 0, 0 }; |
491 | XRenderFillRectangle (dpy, PictOpSrc, dst, &rc, 0, 0, w, h);//TODO: split into four fillrectangles |
567 | 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); |
568 | XRenderComposite (dpy, PictOpSrc, src, None, dst, 0, 0, 0, 0, x, y, ref->w, ref->h); |
493 | } |
569 | } |
494 | else |
570 | else |
495 | XRenderComposite (dpy, PictOpSrc, src, None, dst, x, y, 0, 0, 0, 0, w, h); |
571 | XRenderComposite (dpy, PictOpSrc, src, None, dst, -x, -y, 0, 0, 0, 0, w, h); |
496 | |
572 | |
497 | XRenderFreePicture (dpy, src); |
573 | XRenderFreePicture (dpy, src); |
498 | XRenderFreePicture (dpy, dst); |
574 | XRenderFreePicture (dpy, dst); |
499 | |
575 | |
500 | return img; |
576 | return img; |
… | |
… | |
503 | rxvt_img * |
579 | rxvt_img * |
504 | rxvt_img::sub_rect (int x, int y, int width, int height) |
580 | rxvt_img::sub_rect (int x, int y, int width, int height) |
505 | { |
581 | { |
506 | rxvt_img *img = clone (); |
582 | rxvt_img *img = clone (); |
507 | |
583 | |
508 | img->x += x; |
584 | img->x -= x; |
509 | img->y += y; |
585 | img->y -= y; |
510 | |
586 | |
511 | if (w != width || h != height) |
587 | if (w != width || h != height) |
512 | { |
588 | { |
513 | img->w = width; |
589 | img->w = width; |
514 | img->h = height; |
590 | img->h = height; |
… | |
… | |
519 | } |
595 | } |
520 | |
596 | |
521 | return img; |
597 | return img; |
522 | } |
598 | } |
523 | |
599 | |
524 | rxvt_img * |
600 | typedef rxvt_img::nv matrix[3][3]; |
525 | rxvt_img::transform (double matrix[9], int new_width, int new_height) |
|
|
526 | { |
|
|
527 | rxvt_img *img = new rxvt_img (s, format, 0, 0, new_width, new_height, repeat); |
|
|
528 | img->alloc (); |
|
|
529 | |
601 | |
530 | Display *dpy = s->display->dpy; |
602 | static void |
531 | Picture src = src_picture (); |
603 | mat_invert (matrix mat, rxvt_img::nv (&inv)[3][3]) |
532 | Picture dst = XRenderCreatePicture (dpy, img->pm, img->format, 0, 0); |
604 | { |
|
|
605 | rxvt_img::nv s0 = mat [2][2] * mat [1][1] - mat [2][1] * mat [1][2]; |
|
|
606 | rxvt_img::nv s1 = mat [2][1] * mat [0][2] - mat [2][2] * mat [0][1]; |
|
|
607 | rxvt_img::nv s2 = mat [1][2] * mat [0][1] - mat [1][1] * mat [0][2]; |
533 | |
608 | |
534 | XTransform xfrm; |
609 | rxvt_img::nv invdet = 1. / (mat [0][0] * s0 + mat [1][0] * s1 + mat [2][0] * s2); |
535 | |
610 | |
|
|
611 | inv [0][0] = invdet * s0; |
|
|
612 | inv [0][1] = invdet * s1; |
|
|
613 | inv [0][2] = invdet * s2; |
|
|
614 | |
|
|
615 | inv [1][0] = invdet * (mat [2][0] * mat [1][2] - mat [2][2] * mat [1][0]); |
|
|
616 | inv [1][1] = invdet * (mat [2][2] * mat [0][0] - mat [2][0] * mat [0][2]); |
|
|
617 | inv [1][2] = invdet * (mat [1][0] * mat [0][2] - mat [1][2] * mat [0][0]); |
|
|
618 | |
|
|
619 | inv [2][0] = invdet * (mat [2][1] * mat [1][0] - mat [2][0] * mat [1][1]); |
|
|
620 | inv [2][1] = invdet * (mat [2][0] * mat [0][1] - mat [2][1] * mat [0][0]); |
|
|
621 | inv [2][2] = invdet * (mat [1][1] * mat [0][0] - mat [1][0] * mat [0][1]); |
|
|
622 | } |
|
|
623 | |
|
|
624 | static rxvt_img::nv |
|
|
625 | mat_apply (matrix mat, int i, rxvt_img::nv x, rxvt_img::nv y) |
|
|
626 | { |
|
|
627 | rxvt_img::nv v = mat [i][0] * x + mat [i][1] * y + mat [i][2]; |
|
|
628 | rxvt_img::nv w = mat [2][0] * x + mat [2][1] * y + mat [2][2]; |
|
|
629 | |
|
|
630 | return v * (1. / w); |
|
|
631 | } |
|
|
632 | |
|
|
633 | static void |
|
|
634 | mat_mult (matrix a, matrix b, matrix r) |
|
|
635 | { |
536 | for (int i = 0; i < 3; ++i) |
636 | for (int i = 0; i < 3; ++i) |
537 | for (int j = 0; j < 3; ++j) |
637 | for (int j = 0; j < 3; ++j) |
|
|
638 | r [i][j] = a [i][0] * b [0][j] |
|
|
639 | + a [i][1] * b [1][j] |
|
|
640 | + a [i][2] * b [2][j]; |
|
|
641 | } |
|
|
642 | |
|
|
643 | static void |
|
|
644 | mat_trans (rxvt_img::nv x, rxvt_img::nv y, matrix mat) |
|
|
645 | { |
|
|
646 | mat [0][0] = 1; mat [0][1] = 0; mat [0][2] = x; |
|
|
647 | mat [1][0] = 0; mat [1][1] = 1; mat [1][2] = y; |
|
|
648 | mat [2][0] = 0; mat [2][1] = 0; mat [2][2] = 1; |
|
|
649 | } |
|
|
650 | |
|
|
651 | rxvt_img * |
|
|
652 | rxvt_img::transform (nv matrix[3][3]) |
|
|
653 | { |
|
|
654 | // calculate new pixel bounding box coordinates |
|
|
655 | nv r[2], rmin[2], rmax[2]; |
|
|
656 | |
|
|
657 | for (int i = 0; i < 2; ++i) |
|
|
658 | { |
|
|
659 | nv v; |
|
|
660 | |
|
|
661 | v = mat_apply (matrix, i, 0+x, 0+y); rmin [i] = rmax [i] = v; r [i] = v; |
|
|
662 | v = mat_apply (matrix, i, w+x, 0+y); min_it (rmin [i], v); max_it (rmax [i], v); |
|
|
663 | v = mat_apply (matrix, i, 0+x, h+y); min_it (rmin [i], v); max_it (rmax [i], v); |
|
|
664 | v = mat_apply (matrix, i, w+x, h+y); min_it (rmin [i], v); max_it (rmax [i], v); |
|
|
665 | } |
|
|
666 | |
|
|
667 | float sx = rmin [0] - x; |
|
|
668 | float sy = rmin [1] - y; |
|
|
669 | |
|
|
670 | // TODO: adjust matrix for subpixel accuracy |
|
|
671 | int nx = floor (rmin [0]); |
|
|
672 | int ny = floor (rmin [1]); |
|
|
673 | |
|
|
674 | int new_width = ceil (rmax [0] - rmin [0]); |
|
|
675 | int new_height = ceil (rmax [1] - rmin [1]); |
|
|
676 | |
|
|
677 | ::matrix tr, tmp; |
|
|
678 | mat_trans (x, y, tr); |
|
|
679 | mat_mult (matrix, tr, tmp); |
|
|
680 | mat_trans (-x, -y, tr); |
|
|
681 | mat_mult (tr, tmp, matrix); |
|
|
682 | |
|
|
683 | ::matrix inv; |
|
|
684 | mat_invert (matrix, inv); |
|
|
685 | |
|
|
686 | rxvt_img *img = new rxvt_img (s, format, nx, ny, new_width, new_height, repeat); |
|
|
687 | img->alloc (); |
|
|
688 | |
|
|
689 | Display *dpy = s->display->dpy; |
|
|
690 | Picture src = picture (); |
|
|
691 | Picture dst = XRenderCreatePicture (dpy, img->pm, img->format, 0, 0); |
|
|
692 | |
|
|
693 | XTransform xfrm; |
|
|
694 | |
|
|
695 | for (int i = 0; i < 3; ++i) |
|
|
696 | for (int j = 0; j < 3; ++j) |
538 | xfrm.matrix [i][j] = XDoubleToFixed (matrix [i * 3 + j]); |
697 | 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 | |
698 | |
543 | XRenderSetPictureFilter (dpy, src, "good", 0, 0); |
699 | XRenderSetPictureFilter (dpy, src, "good", 0, 0); |
544 | XRenderSetPictureTransform (dpy, src, &xfrm); |
700 | XRenderSetPictureTransform (dpy, src, &xfrm); |
545 | XRenderComposite (dpy, PictOpSrc, src, None, dst, 0, 0, 0, 0, 0, 0, new_width, new_height); |
701 | XRenderComposite (dpy, PictOpSrc, src, None, dst, sx, sy, 0, 0, 0, 0, new_width, new_height); |
|
|
702 | #if 1 |
|
|
703 | { |
|
|
704 | XRenderColor rc = { 65535,0,0,65535 }; |
|
|
705 | XRenderFillRectangle (dpy, PictOpSrc, dst, &rc, 0, 0, new_width, new_height); |
|
|
706 | }{ |
|
|
707 | XRenderColor rc = { 0,0,0,65535 }; |
|
|
708 | XRenderFillRectangle (dpy, PictOpSrc, dst, &rc, 1, 1, new_width - 2, new_height - 2); |
|
|
709 | } |
|
|
710 | XRenderComposite (dpy, PictOpOver, src, None, dst, sx, sy, 0, 0, 0, 0, new_width, new_height); |
|
|
711 | #endif |
546 | |
712 | |
547 | XRenderFreePicture (dpy, src); |
713 | XRenderFreePicture (dpy, src); |
548 | XRenderFreePicture (dpy, dst); |
714 | XRenderFreePicture (dpy, dst); |
549 | |
715 | |
550 | return img; |
716 | return img; |
… | |
… | |
554 | rxvt_img::scale (int new_width, int new_height) |
720 | rxvt_img::scale (int new_width, int new_height) |
555 | { |
721 | { |
556 | if (w == new_width && h == new_height) |
722 | if (w == new_width && h == new_height) |
557 | return clone (); |
723 | return clone (); |
558 | |
724 | |
559 | double matrix[9] = { |
725 | nv matrix[3][3] = { |
560 | w / (double)new_width, 0, 0, |
726 | { new_width / (nv)w, 0, 0 }, |
561 | 0, h / (double)new_height, 0, |
727 | { 0, new_height / (nv)h, 0 }, |
562 | 0, 0, 1 |
728 | { 0, 0, 1 } |
563 | }; |
729 | }; |
564 | |
730 | |
565 | int old_repeat_mode = repeat; |
731 | int old_repeat_mode = repeat; |
566 | repeat = RepeatPad; // not right, but xrender can't properly scale it seems |
732 | repeat = RepeatPad; // not right, but xrender can't properly scale it seems |
567 | |
733 | |
568 | rxvt_img *img = transform (matrix, new_width, new_height); |
734 | rxvt_img *img = transform (matrix); |
569 | |
735 | |
570 | repeat = old_repeat_mode; |
736 | repeat = old_repeat_mode; |
571 | img->repeat = repeat; |
737 | img->repeat = repeat; |
572 | |
738 | |
573 | return img; |
739 | return img; |
574 | } |
740 | } |
575 | |
741 | |
576 | rxvt_img * |
742 | rxvt_img * |
577 | rxvt_img::rotate (int x, int y, double phi, int new_width, int new_height) |
743 | rxvt_img::rotate (int cx, int cy, nv phi) |
578 | { |
744 | { |
579 | double s = sin (phi); |
745 | nv s = sin (phi); |
580 | double c = cos (phi); |
746 | nv c = cos (phi); |
581 | |
747 | |
582 | double matrix[9] = { |
748 | nv matrix[3][3] = { |
|
|
749 | #if 0 |
583 | c, -s, -c * x + s * y + x, |
750 | { c, -s, cx - c * cx + s * cy }, |
584 | s, c, -s * x - c * y + y, |
751 | { s, c, cy - s * cx - c * cy }, |
585 | 0, 0, 1 |
752 | { 0, 0, 1 } |
|
|
753 | #else |
|
|
754 | { c, -s, 0 }, |
|
|
755 | { s, c, 0 }, |
|
|
756 | { 0, 0, 1 } |
|
|
757 | #endif |
586 | }; |
758 | }; |
587 | |
759 | |
588 | return transform (matrix, new_width, new_height); |
760 | move (-cx, -cy); |
589 | } |
761 | rxvt_img *img = transform (matrix); |
|
|
762 | move ( cx, cy); |
|
|
763 | img->move (cx, cy); |
590 | |
764 | |
|
|
765 | return img; |
|
|
766 | } |
|
|
767 | |
591 | rxvt_img * |
768 | rxvt_img * |
592 | rxvt_img::convert_format (XRenderPictFormat *new_format, const rxvt_color &bg) |
769 | rxvt_img::convert_format (XRenderPictFormat *new_format, const rgba &bg) |
593 | { |
770 | { |
594 | if (new_format == format) |
771 | if (new_format == format) |
595 | return clone (); |
772 | return clone (); |
596 | |
773 | |
597 | rxvt_img *img = new rxvt_img (s, new_format, x, y, w, h, repeat); |
774 | rxvt_img *img = new rxvt_img (s, new_format, x, y, w, h, repeat); |
598 | img->alloc (); |
775 | img->alloc (); |
599 | |
776 | |
600 | Display *dpy = s->display->dpy; |
777 | Display *dpy = s->display->dpy; |
601 | Picture src = src_picture (); |
778 | Picture src = picture (); |
602 | Picture dst = XRenderCreatePicture (dpy, img->pm, new_format, 0, 0); |
779 | Picture dst = XRenderCreatePicture (dpy, img->pm, new_format, 0, 0); |
603 | int op = PictOpSrc; |
780 | int op = PictOpSrc; |
604 | |
781 | |
605 | if (format->direct.alphaMask && !new_format->direct.alphaMask) |
782 | if (format->direct.alphaMask && !new_format->direct.alphaMask) |
606 | { |
783 | { |
607 | // does it have to be that complicated |
784 | // 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 }; |
785 | XRenderColor rc = { bg.r, bg.g, bg.b, bg.a }; |
612 | XRenderFillRectangle (dpy, PictOpSrc, dst, &rc, 0, 0, w, h); |
786 | XRenderFillRectangle (dpy, PictOpSrc, dst, &rc, 0, 0, w, h); |
613 | |
787 | |
614 | op = PictOpOver; |
788 | op = PictOpOver; |
615 | } |
789 | } |
616 | |
790 | |
… | |
… | |
621 | |
795 | |
622 | return img; |
796 | return img; |
623 | } |
797 | } |
624 | |
798 | |
625 | rxvt_img * |
799 | rxvt_img * |
626 | rxvt_img::blend (rxvt_img *img, double factor) |
800 | rxvt_img::blend (rxvt_img *img, nv factor) |
627 | { |
801 | { |
628 | rxvt_img *img2 = clone (); |
802 | rxvt_img *img2 = clone (); |
629 | Display *dpy = s->display->dpy; |
803 | Display *dpy = s->display->dpy; |
630 | Picture src = img->src_picture (); |
804 | Picture src = img->picture (); |
631 | Picture dst = XRenderCreatePicture (dpy, img2->pm, img2->format, 0, 0); |
805 | Picture dst = XRenderCreatePicture (dpy, img2->pm, img2->format, 0, 0); |
632 | Picture mask = create_xrender_mask (dpy, img->pm, False, False); |
806 | Picture mask = create_xrender_mask (dpy, img->pm, False, False); |
633 | |
807 | |
634 | XRenderColor mask_c; |
808 | XRenderColor mask_c; |
635 | |
809 | |