… | |
… | |
6 | * Copyright (c) 2012 Marc Lehmann <schmorp@schmorp.de> |
6 | * Copyright (c) 2012 Marc Lehmann <schmorp@schmorp.de> |
7 | * Copyright (c) 2012 Emanuele Giaquinta <e.giaquinta@glauco.it> |
7 | * Copyright (c) 2012 Emanuele Giaquinta <e.giaquinta@glauco.it> |
8 | * |
8 | * |
9 | * This program is free software; you can redistribute it and/or modify |
9 | * This program is free software; you can redistribute it and/or modify |
10 | * it under the terms of the GNU General Public License as published by |
10 | * it under the terms of the GNU General Public License as published by |
11 | * the Free Software Foundation; either version 2 of the License, or |
11 | * the Free Software Foundation; either version 3 of the License, or |
12 | * (at your option) any later version. |
12 | * (at your option) any later version. |
13 | * |
13 | * |
14 | * This program is distributed in the hope that it will be useful, |
14 | * This program is distributed in the hope that it will be useful, |
15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
… | |
… | |
164 | if (!this->dstimg) |
164 | if (!this->dstimg) |
165 | this->dstimg = srcimg->new_empty (); |
165 | this->dstimg = srcimg->new_empty (); |
166 | else if (!this->dstimg->pm) // somewhat unsatisfying |
166 | else if (!this->dstimg->pm) // somewhat unsatisfying |
167 | this->dstimg->alloc (); |
167 | this->dstimg->alloc (); |
168 | |
168 | |
169 | dpy = srcimg->s->dpy; |
169 | dpy = srcimg->d->dpy; |
170 | src = srcimg->picture (); |
170 | src = srcimg->picture (); |
171 | dst = this->dstimg->picture (); |
171 | dst = this->dstimg->picture (); |
172 | } |
172 | } |
173 | |
173 | |
174 | ecb_noinline |
174 | ecb_noinline |
… | |
… | |
188 | } |
188 | } |
189 | |
189 | |
190 | // CreateSolidFill creates a very very very weird picture |
190 | // CreateSolidFill creates a very very very weird picture |
191 | void mask (const rgba &c) |
191 | void mask (const rgba &c) |
192 | { |
192 | { |
|
|
193 | // the casts are needed in C++11 (see 8.5.1) |
193 | XRenderColor rc = { |
194 | XRenderColor rc = { |
194 | c.r * c.a / 65535, |
195 | (unsigned short)(c.r * c.a / 65535), |
195 | c.g * c.a / 65535, |
196 | (unsigned short)(c.g * c.a / 65535), |
196 | c.b * c.a / 65535, |
197 | (unsigned short)(c.b * c.a / 65535), |
197 | c.a |
198 | c.a |
198 | }; |
199 | }; |
199 | msk = XRenderCreateSolidFill (dpy, &rc); |
200 | msk = XRenderCreateSolidFill (dpy, &rc); |
200 | ecb_assume (msk); |
201 | ecb_assume (msk); |
201 | } |
202 | } |
202 | |
203 | |
203 | void fill (const rgba &c) |
204 | void fill (const rgba &c) |
204 | { |
205 | { |
205 | XRenderColor rc = { |
206 | XRenderColor rc = { |
206 | c.r * c.a / 65535, |
207 | (unsigned short)(c.r * c.a / 65535), |
207 | c.g * c.a / 65535, |
208 | (unsigned short)(c.g * c.a / 65535), |
208 | c.b * c.a / 65535, |
209 | (unsigned short)(c.b * c.a / 65535), |
209 | c.a |
210 | c.a |
210 | }; |
211 | }; |
211 | |
212 | |
212 | XRenderFillRectangle (dpy, PictOpSrc, msk, &rc, 0, 0, 1, 1); |
213 | XRenderFillRectangle (dpy, PictOpSrc, msk, &rc, 0, 0, 1, 1); |
213 | } |
214 | } |
214 | |
215 | |
… | |
… | |
246 | // should be a very good fallback |
247 | // should be a very good fallback |
247 | return XRenderFindStandardFormat (dpy, PictStandardARGB32); |
248 | return XRenderFindStandardFormat (dpy, PictStandardARGB32); |
248 | } |
249 | } |
249 | |
250 | |
250 | rxvt_img::rxvt_img (rxvt_screen *screen, XRenderPictFormat *format, int x, int y, int width, int height, int repeat) |
251 | rxvt_img::rxvt_img (rxvt_screen *screen, XRenderPictFormat *format, int x, int y, int width, int height, int repeat) |
251 | : s(screen), x(x), y(y), w(width), h(height), format(format), repeat(repeat), |
252 | : d(screen->display), x(x), y(y), w(width), h(height), format(format), repeat(repeat), |
252 | pm(0), ref(0) |
253 | pm(0), ref(0) |
253 | { |
254 | { |
254 | } |
255 | } |
255 | |
256 | |
|
|
257 | rxvt_img::rxvt_img (rxvt_display *display, XRenderPictFormat *format, int x, int y, int width, int height, int repeat) |
|
|
258 | : d(display), x(x), y(y), w(width), h(height), format(format), repeat(repeat), |
|
|
259 | pm(0), ref(0) |
|
|
260 | { |
|
|
261 | } |
|
|
262 | |
256 | rxvt_img::rxvt_img (const rxvt_img &img) |
263 | rxvt_img::rxvt_img (const rxvt_img &img) |
257 | : s(img.s), x(img.x), y(img.y), w(img.w), h(img.h), format(img.format), repeat(img.repeat), pm(img.pm), ref(img.ref) |
264 | : d(img.d), x(img.x), y(img.y), w(img.w), h(img.h), format(img.format), repeat(img.repeat), pm(img.pm), ref(img.ref) |
258 | { |
265 | { |
259 | ++ref->cnt; |
266 | ++ref->cnt; |
260 | } |
267 | } |
261 | |
268 | |
262 | rxvt_img * |
269 | rxvt_img * |
… | |
… | |
395 | { |
402 | { |
396 | GError *err = 0; |
403 | GError *err = 0; |
397 | GdkPixbuf *pb = gdk_pixbuf_new_from_file (filename, &err); |
404 | GdkPixbuf *pb = gdk_pixbuf_new_from_file (filename, &err); |
398 | |
405 | |
399 | if (!pb) |
406 | if (!pb) |
|
|
407 | try |
|
|
408 | { |
400 | rxvt_fatal ("rxvt_img::new_from_file: %s\n", err->message); |
409 | rxvt_fatal ("rxvt_img::new_from_file: %s\n", err->message); |
|
|
410 | } |
|
|
411 | catch (...) |
|
|
412 | { |
|
|
413 | g_error_free (err); |
|
|
414 | throw; |
|
|
415 | } |
401 | |
416 | |
402 | rxvt_img *img = new_from_pixbuf (s, pb); |
417 | rxvt_img *img = new_from_pixbuf (s, pb); |
403 | |
418 | |
404 | g_object_unref (pb); |
419 | g_object_unref (pb); |
405 | |
420 | |
… | |
… | |
413 | { |
428 | { |
414 | if (--ref->cnt) |
429 | if (--ref->cnt) |
415 | return; |
430 | return; |
416 | |
431 | |
417 | if (pm && ref->ours) |
432 | if (pm && ref->ours) |
418 | XFreePixmap (s->dpy, pm); |
433 | XFreePixmap (d->dpy, pm); |
419 | |
434 | |
420 | delete ref; |
435 | delete ref; |
421 | } |
436 | } |
422 | |
437 | |
423 | rxvt_img::~rxvt_img () |
438 | rxvt_img::~rxvt_img () |
… | |
… | |
426 | } |
441 | } |
427 | |
442 | |
428 | void |
443 | void |
429 | rxvt_img::alloc () |
444 | rxvt_img::alloc () |
430 | { |
445 | { |
431 | pm = XCreatePixmap (s->dpy, s->display->root, w, h, format->depth); |
446 | pm = XCreatePixmap (d->dpy, d->root, w, h, format->depth); |
432 | ref = new pixref (w, h); |
447 | ref = new pixref (w, h); |
433 | } |
448 | } |
434 | |
449 | |
435 | rxvt_img * |
450 | rxvt_img * |
436 | rxvt_img::new_empty () |
451 | rxvt_img::new_empty () |
437 | { |
452 | { |
438 | rxvt_img *img = new rxvt_img (s, format, x, y, w, h, repeat); |
453 | rxvt_img *img = new rxvt_img (d, format, x, y, w, h, repeat); |
439 | img->alloc (); |
454 | img->alloc (); |
440 | |
455 | |
441 | return img; |
456 | return img; |
442 | } |
457 | } |
443 | |
458 | |
444 | Picture |
459 | Picture |
445 | rxvt_img::picture () |
460 | rxvt_img::picture () |
446 | { |
461 | { |
447 | Display *dpy = s->dpy; |
462 | Display *dpy = d->dpy; |
448 | |
463 | |
449 | XRenderPictureAttributes pa; |
464 | XRenderPictureAttributes pa; |
450 | pa.repeat = repeat; |
465 | pa.repeat = repeat; |
451 | Picture pic = XRenderCreatePicture (dpy, pm, format, CPRepeat, &pa); |
466 | Picture pic = XRenderCreatePicture (dpy, pm, format, CPRepeat, &pa); |
452 | |
467 | |
… | |
… | |
457 | rxvt_img::unshare () |
472 | rxvt_img::unshare () |
458 | { |
473 | { |
459 | if (ref->cnt == 1 && ref->ours) |
474 | if (ref->cnt == 1 && ref->ours) |
460 | return; |
475 | return; |
461 | |
476 | |
462 | Pixmap pm2 = XCreatePixmap (s->dpy, s->display->root, ref->w, ref->h, format->depth); |
477 | Pixmap pm2 = XCreatePixmap (d->dpy, d->root, ref->w, ref->h, format->depth); |
463 | GC gc = XCreateGC (s->dpy, pm, 0, 0); |
478 | GC gc = XCreateGC (d->dpy, pm, 0, 0); |
464 | XCopyArea (s->dpy, pm, pm2, gc, 0, 0, ref->w, ref->h, 0, 0); |
479 | XCopyArea (d->dpy, pm, pm2, gc, 0, 0, ref->w, ref->h, 0, 0); |
465 | XFreeGC (s->dpy, gc); |
480 | XFreeGC (d->dpy, gc); |
466 | |
481 | |
467 | destroy (); |
482 | destroy (); |
468 | |
483 | |
469 | pm = pm2; |
484 | pm = pm2; |
470 | ref = new pixref (ref->w, ref->h); |
485 | ref = new pixref (ref->w, ref->h); |
… | |
… | |
473 | void |
488 | void |
474 | rxvt_img::fill (const rgba &c, int x, int y, int w, int h) |
489 | rxvt_img::fill (const rgba &c, int x, int y, int w, int h) |
475 | { |
490 | { |
476 | XRenderColor rc = { c.r, c.g, c.b, c.a }; |
491 | XRenderColor rc = { c.r, c.g, c.b, c.a }; |
477 | |
492 | |
478 | Display *dpy = s->dpy; |
493 | Display *dpy = d->dpy; |
479 | Picture src = picture (); |
494 | Picture src = picture (); |
480 | XRenderFillRectangle (dpy, PictOpSrc, src, &rc, x, y, w, h); |
495 | XRenderFillRectangle (dpy, PictOpSrc, src, &rc, x, y, w, h); |
481 | XRenderFreePicture (dpy, src); |
496 | XRenderFreePicture (dpy, src); |
482 | } |
497 | } |
483 | |
498 | |
… | |
… | |
491 | rxvt_img::add_alpha () |
506 | rxvt_img::add_alpha () |
492 | { |
507 | { |
493 | if (format->direct.alphaMask) |
508 | if (format->direct.alphaMask) |
494 | return; |
509 | return; |
495 | |
510 | |
496 | composer cc (this, new rxvt_img (s, find_alpha_format_for (s->dpy, format), x, y, w, h, repeat)); |
511 | composer cc (this, new rxvt_img (d, find_alpha_format_for (d->dpy, format), x, y, w, h, repeat)); |
497 | |
512 | |
498 | XRenderComposite (cc.dpy, PictOpSrc, cc.src, None, cc.dst, 0, 0, 0, 0, 0, 0, w, h); |
513 | XRenderComposite (cc.dpy, PictOpSrc, cc.src, None, cc.dst, 0, 0, 0, 0, 0, 0, w, h); |
499 | |
514 | |
500 | rxvt_img *img = cc; |
515 | rxvt_img *img = cc; |
501 | |
516 | |
… | |
… | |
527 | } |
542 | } |
528 | |
543 | |
529 | rxvt_img * |
544 | rxvt_img * |
530 | rxvt_img::blur (int rh, int rv) |
545 | rxvt_img::blur (int rh, int rv) |
531 | { |
546 | { |
532 | if (!(s->display->flags & DISPLAY_HAS_RENDER_CONV)) |
547 | if (!(d->flags & DISPLAY_HAS_RENDER_CONV)) |
533 | return clone (); |
548 | return clone (); |
534 | |
549 | |
535 | Display *dpy = s->dpy; |
550 | Display *dpy = d->dpy; |
536 | int size = max (rh, rv) * 2 + 1; |
551 | int size = max (rh, rv) * 2 + 1; |
537 | nv *kernel = (nv *)malloc (size * sizeof (nv)); |
552 | nv *kernel = (nv *)malloc (size * sizeof (nv)); |
538 | XFixed *params = (XFixed *)malloc ((size + 2) * sizeof (XFixed)); |
553 | XFixed *params = rxvt_temp_buf<XFixed> (size + 2); |
539 | rxvt_img *img = new_empty (); |
554 | rxvt_img *img = new_empty (); |
540 | |
555 | |
541 | XRenderPictureAttributes pa; |
556 | XRenderPictureAttributes pa; |
542 | pa.repeat = RepeatPad; |
557 | pa.repeat = RepeatPad; |
543 | Picture src = XRenderCreatePicture (dpy, pm, format, CPRepeat, &pa); |
558 | Picture src = XRenderCreatePicture (dpy, pm, format, CPRepeat, &pa); |
… | |
… | |
578 | 0, 0, |
593 | 0, 0, |
579 | w, h); |
594 | w, h); |
580 | } |
595 | } |
581 | |
596 | |
582 | free (kernel); |
597 | free (kernel); |
583 | free (params); |
|
|
584 | |
598 | |
585 | XRenderFreePicture (dpy, src); |
599 | XRenderFreePicture (dpy, src); |
586 | XRenderFreePicture (dpy, dst); |
600 | XRenderFreePicture (dpy, dst); |
587 | XRenderFreePicture (dpy, tmp); |
601 | XRenderFreePicture (dpy, tmp); |
588 | |
602 | |
… | |
… | |
592 | rxvt_img * |
606 | rxvt_img * |
593 | rxvt_img::muladd (nv mul, nv add) |
607 | rxvt_img::muladd (nv mul, nv add) |
594 | { |
608 | { |
595 | // STEP 1: double the image width, fill all odd columns with white (==1) |
609 | // STEP 1: double the image width, fill all odd columns with white (==1) |
596 | |
610 | |
597 | composer cc (this, new rxvt_img (s, format, 0, 0, w * 2, h, repeat)); |
611 | rxvt_img *img = new rxvt_img (d, format, 0, 0, w * 2, h, repeat); |
|
|
612 | composer cc (this, img); |
598 | |
613 | |
599 | // why the hell does XRenderSetPictureTransform want a writable matrix :( |
614 | // why the hell does XRenderSetPictureTransform want a writable matrix :( |
600 | // that keeps us from just static const'ing this matrix. |
615 | // that keeps us from just static const'ing this matrix. |
601 | XTransform h_double = { |
616 | XTransform h_double = { |
602 | 0x8000, 0, 0, |
617 | 0x08000, 0, 0, |
603 | 0, 0x1000, 0, |
618 | 0, 0x10000, 0, |
604 | 0, 0, 0x1000 |
619 | 0, 0, 0x10000 |
605 | }; |
620 | }; |
606 | |
621 | |
607 | XRenderSetPictureFilter (cc.dpy, cc.src, "nearest", 0, 0); |
622 | XRenderSetPictureFilter (cc.dpy, cc.src, "nearest", 0, 0); |
608 | XRenderSetPictureTransform (cc.dpy, cc.src, &h_double); |
623 | XRenderSetPictureTransform (cc.dpy, cc.src, &h_double); |
609 | XRenderComposite (cc.dpy, PictOpSrc, cc.src, None, cc.dst, 0, 0, 0, 0, 0, 0, w * 2, h); |
624 | XRenderComposite (cc.dpy, PictOpSrc, cc.src, None, cc.dst, 0, 0, 0, 0, 0, 0, w * 2, h); |
… | |
… | |
623 | |
638 | |
624 | // STEP 2: convolve the image with a 3x1 filter |
639 | // STEP 2: convolve the image with a 3x1 filter |
625 | // a 2x1 filter would obviously suffice, but given the total lack of specification |
640 | // a 2x1 filter would obviously suffice, but given the total lack of specification |
626 | // for xrender, I expect different xrender implementations to randomly diverge. |
641 | // for xrender, I expect different xrender implementations to randomly diverge. |
627 | // we also halve the image, and hope for the best (again, for lack of specs). |
642 | // we also halve the image, and hope for the best (again, for lack of specs). |
628 | composer cc2 (cc.dstimg); |
643 | composer cc2 (img); |
629 | |
644 | |
630 | XFixed kernel [] = { |
645 | XFixed kernel [] = { |
631 | XDoubleToFixed (3), XDoubleToFixed (1), |
646 | XDoubleToFixed (3), XDoubleToFixed (1), |
632 | XDoubleToFixed (0), XDoubleToFixed (mul), XDoubleToFixed (add) |
647 | XDoubleToFixed (0), XDoubleToFixed (mul), XDoubleToFixed (add) |
633 | }; |
648 | }; |
634 | |
649 | |
635 | XTransform h_halve = { |
650 | XTransform h_halve = { |
636 | 0x2000, 0, 0, |
651 | 0x20000, 0, 0, |
637 | 0, 0x1000, 0, |
652 | 0, 0x10000, 0, |
638 | 0, 0, 0x1000 |
653 | 0, 0, 0x10000 |
639 | }; |
654 | }; |
640 | |
655 | |
641 | XRenderSetPictureFilter (cc.dpy, cc2.src, "nearest", 0, 0); |
656 | XRenderSetPictureFilter (cc.dpy, cc2.src, "nearest", 0, 0); |
642 | XRenderSetPictureTransform (cc.dpy, cc2.src, &h_halve); |
657 | XRenderSetPictureTransform (cc.dpy, cc2.src, &h_halve); |
643 | XRenderSetPictureFilter (cc.dpy, cc2.src, FilterConvolution, kernel, ecb_array_length (kernel)); |
658 | XRenderSetPictureFilter (cc.dpy, cc2.src, FilterConvolution, kernel, ecb_array_length (kernel)); |
644 | |
659 | |
645 | XRenderComposite (cc.dpy, PictOpSrc, cc2.src, None, cc2.dst, 0, 0, 0, 0, 0, 0, w * 2, h); |
660 | XRenderComposite (cc.dpy, PictOpSrc, cc2.src, None, cc2.dst, 0, 0, 0, 0, 0, 0, w * 2, h); |
|
|
661 | |
|
|
662 | delete img; |
646 | |
663 | |
647 | return cc2; |
664 | return cc2; |
648 | } |
665 | } |
649 | |
666 | |
650 | ecb_noinline static void |
667 | ecb_noinline static void |
… | |
… | |
669 | void |
686 | void |
670 | rxvt_img::brightness (int32_t r, int32_t g, int32_t b, int32_t a) |
687 | rxvt_img::brightness (int32_t r, int32_t g, int32_t b, int32_t a) |
671 | { |
688 | { |
672 | unshare (); |
689 | unshare (); |
673 | |
690 | |
674 | Display *dpy = s->dpy; |
691 | Display *dpy = d->dpy; |
675 | Picture dst = XRenderCreatePicture (dpy, pm, format, 0, 0); |
692 | Picture dst = XRenderCreatePicture (dpy, pm, format, 0, 0); |
676 | |
693 | |
677 | // loop should not be needed for brightness, as only -1..1 makes sense |
694 | // loop should not be needed for brightness, as only -1..1 makes sense |
678 | //while (r | g | b | a) |
695 | //while (r | g | b | a) |
679 | { |
696 | { |
680 | unsigned short xr, xg, xb, xa; |
|
|
681 | XRenderColor mask_c; |
697 | XRenderColor mask_c; |
682 | |
698 | |
683 | if (extract (0, 65535, r, g, b, a, mask_c.red, mask_c.green, mask_c.blue, mask_c.alpha)) |
699 | if (extract (0, 65535, r, g, b, a, mask_c.red, mask_c.green, mask_c.blue, mask_c.alpha)) |
684 | XRenderFillRectangle (dpy, PictOpAdd, dst, &mask_c, 0, 0, w, h); |
700 | XRenderFillRectangle (dpy, PictOpAdd, dst, &mask_c, 0, 0, w, h); |
685 | |
701 | |
… | |
… | |
717 | cc.mask (true); |
733 | cc.mask (true); |
718 | |
734 | |
719 | //TODO: this operator does not yet implement some useful contrast |
735 | //TODO: this operator does not yet implement some useful contrast |
720 | while (r | g | b | a) |
736 | while (r | g | b | a) |
721 | { |
737 | { |
722 | unsigned short xr, xg, xb, xa; |
|
|
723 | XRenderColor mask_c; |
738 | XRenderColor mask_c; |
724 | |
739 | |
725 | if (extract (0, 65535, r, g, b, a, mask_c.red, mask_c.green, mask_c.blue, mask_c.alpha)) |
740 | if (extract (0, 65535, r, g, b, a, mask_c.red, mask_c.green, mask_c.blue, mask_c.alpha)) |
726 | { |
741 | { |
727 | XRenderFillRectangle (cc.dpy, PictOpSrc, cc.msk, &mask_c, 0, 0, 1, 1); |
742 | XRenderFillRectangle (cc.dpy, PictOpSrc, cc.msk, &mask_c, 0, 0, 1, 1); |
… | |
… | |
763 | // add an alpha channel if... |
778 | // add an alpha channel if... |
764 | bool alpha = !format->direct.alphaMask // pixmap has none yet |
779 | bool alpha = !format->direct.alphaMask // pixmap has none yet |
765 | && (x || y) // we need one because of non-zero offset |
780 | && (x || y) // we need one because of non-zero offset |
766 | && repeat == RepeatNone; // and we have no good pixels to fill with |
781 | && repeat == RepeatNone; // and we have no good pixels to fill with |
767 | |
782 | |
768 | composer cc (this, new rxvt_img (s, alpha ? find_alpha_format_for (s->dpy, format) : format, |
783 | composer cc (this, new rxvt_img (d, alpha ? find_alpha_format_for (d->dpy, format) : format, |
769 | 0, 0, w, h, repeat)); |
784 | 0, 0, w, h, repeat)); |
770 | |
785 | |
771 | if (repeat == RepeatNone) |
786 | if (repeat == RepeatNone) |
772 | { |
787 | { |
773 | XRenderColor rc = { 0, 0, 0, 0 }; |
788 | XRenderColor rc = { 0, 0, 0, 0 }; |
… | |
… | |
835 | int new_width = ceil (rmax [0] - rmin [0]); |
850 | int new_width = ceil (rmax [0] - rmin [0]); |
836 | int new_height = ceil (rmax [1] - rmin [1]); |
851 | int new_height = ceil (rmax [1] - rmin [1]); |
837 | |
852 | |
838 | mat3x3 inv = (mat3x3::translate (-x, -y) * m * mat3x3::translate (x, y)).inverse (); |
853 | mat3x3 inv = (mat3x3::translate (-x, -y) * m * mat3x3::translate (x, y)).inverse (); |
839 | |
854 | |
840 | composer cc (this, new rxvt_img (s, format, nx, ny, new_width, new_height, repeat)); |
855 | composer cc (this, new rxvt_img (d, format, nx, ny, new_width, new_height, repeat)); |
841 | |
856 | |
842 | XTransform xfrm; |
857 | XTransform xfrm; |
843 | |
858 | |
844 | for (int i = 0; i < 3; ++i) |
859 | for (int i = 0; i < 3; ++i) |
845 | for (int j = 0; j < 3; ++j) |
860 | for (int j = 0; j < 3; ++j) |
… | |
… | |
884 | rxvt_img::convert_format (XRenderPictFormat *new_format, const rgba &bg) |
899 | rxvt_img::convert_format (XRenderPictFormat *new_format, const rgba &bg) |
885 | { |
900 | { |
886 | if (new_format == format) |
901 | if (new_format == format) |
887 | return clone (); |
902 | return clone (); |
888 | |
903 | |
889 | composer cc (this, new rxvt_img (s, new_format, x, y, w, h, repeat)); |
904 | composer cc (this, new rxvt_img (d, new_format, x, y, w, h, repeat)); |
890 | |
905 | |
891 | int op = PictOpSrc; |
906 | int op = PictOpSrc; |
892 | |
907 | |
893 | if (format->direct.alphaMask && !new_format->direct.alphaMask) |
908 | if (format->direct.alphaMask && !new_format->direct.alphaMask) |
894 | { |
909 | { |
… | |
… | |
915 | |
930 | |
916 | return cc; |
931 | return cc; |
917 | } |
932 | } |
918 | |
933 | |
919 | rxvt_img * |
934 | rxvt_img * |
|
|
935 | rxvt_img::shade (nv factor, rgba c) |
|
|
936 | { |
|
|
937 | clamp_it (factor, -1., 1.); |
|
|
938 | factor++; |
|
|
939 | |
|
|
940 | if (factor > 1) |
|
|
941 | { |
|
|
942 | c.r = c.r * (2 - factor); |
|
|
943 | c.g = c.g * (2 - factor); |
|
|
944 | c.b = c.b * (2 - factor); |
|
|
945 | } |
|
|
946 | else |
|
|
947 | { |
|
|
948 | c.r = c.r * factor; |
|
|
949 | c.g = c.g * factor; |
|
|
950 | c.b = c.b * factor; |
|
|
951 | } |
|
|
952 | |
|
|
953 | rxvt_img *img = this->tint (c); |
|
|
954 | |
|
|
955 | if (factor > 1) |
|
|
956 | { |
|
|
957 | c.a = 0xffff; |
|
|
958 | c.r = |
|
|
959 | c.g = |
|
|
960 | c.b = 0xffff * (factor - 1); |
|
|
961 | |
|
|
962 | img->brightness (c.r, c.g, c.b, c.a); |
|
|
963 | } |
|
|
964 | |
|
|
965 | return img; |
|
|
966 | } |
|
|
967 | |
|
|
968 | rxvt_img * |
920 | rxvt_img::filter (const char *name, int nparams, nv *params) |
969 | rxvt_img::filter (const char *name, int nparams, nv *params) |
921 | { |
970 | { |
922 | composer cc (this); |
971 | composer cc (this); |
923 | |
972 | |
924 | XFixed *xparams = rxvt_temp_buf<XFixed> (nparams); |
973 | XFixed *xparams = rxvt_temp_buf<XFixed> (nparams); |