ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/rxvt-unicode/src/rxvtimg.C
(Generate patch)

Comparing rxvt-unicode/src/rxvtimg.C (file contents):
Revision 1.98 by root, Sun Jun 17 21:58:18 2012 UTC vs.
Revision 1.102 by root, Sat Jul 7 07:00:17 2012 UTC

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
175 void mask (bool rgb = true, int x = 1, int y = 1) 175 void mask (bool rgb = true, int w = 1, int h = 1)
176 { 176 {
177 Pixmap pixmap = XCreatePixmap (dpy, srcimg->pm, x, y, rgb ? 32 : 8); 177 Pixmap pixmap = XCreatePixmap (dpy, srcimg->pm, w, h, rgb ? 32 : 8);
178 178
179 XRenderPictFormat *format = XRenderFindStandardFormat (dpy, rgb ? PictStandardARGB32 : PictStandardA8); 179 XRenderPictFormat *format = XRenderFindStandardFormat (dpy, rgb ? PictStandardARGB32 : PictStandardA8);
180 XRenderPictureAttributes pa; 180 XRenderPictureAttributes pa;
181 pa.repeat = RepeatNormal; 181 pa.repeat = RepeatNormal;
182 pa.component_alpha = rgb; 182 pa.component_alpha = rgb;
476 pm = pm2; 476 pm = pm2;
477 ref = new pixref (ref->w, ref->h); 477 ref = new pixref (ref->w, ref->h);
478} 478}
479 479
480void 480void
481rxvt_img::fill (const rgba &c) 481rxvt_img::fill (const rgba &c, int x, int y, int w, int h)
482{ 482{
483 XRenderColor rc = { c.r, c.g, c.b, c.a }; 483 XRenderColor rc = { c.r, c.g, c.b, c.a };
484 484
485 Display *dpy = s->dpy; 485 Display *dpy = s->dpy;
486 Picture src = picture (); 486 Picture src = picture ();
487 XRenderFillRectangle (dpy, PictOpSrc, src, &rc, 0, 0, w, h); 487 XRenderFillRectangle (dpy, PictOpSrc, src, &rc, x, y, w, h);
488 XRenderFreePicture (dpy, src); 488 XRenderFreePicture (dpy, src);
489}
490
491void
492rxvt_img::fill (const rgba &c)
493{
494 fill (c, 0, 0, w, h);
489} 495}
490 496
491void 497void
492rxvt_img::add_alpha () 498rxvt_img::add_alpha ()
493{ 499{
586 XRenderFreePicture (dpy, src); 592 XRenderFreePicture (dpy, src);
587 XRenderFreePicture (dpy, dst); 593 XRenderFreePicture (dpy, dst);
588 XRenderFreePicture (dpy, tmp); 594 XRenderFreePicture (dpy, tmp);
589 595
590 return img; 596 return img;
597}
598
599rxvt_img *
600rxvt_img::muladd (nv mul, nv add)
601{
602 // STEP 1: double the image width, fill all odd columns with white (==1)
603
604 composer cc (this, new rxvt_img (s, format, 0, 0, w * 2, h, repeat));
605
606 // why the hell does XRenderSetPictureTransform want a writable matrix :(
607 // that keeps us from just static const'ing this matrix.
608 XTransform h_double = {
609 32768, 0, 0,
610 0, 65536, 0,
611 0, 0, 65536
612 };
613
614 XRenderSetPictureFilter (cc.dpy, cc.src, "nearest", 0, 0);
615 XRenderSetPictureTransform (cc.dpy, cc.src, &h_double);
616 XRenderComposite (cc.dpy, PictOpSrc, cc.src, None, cc.dst, 0, 0, 0, 0, 0, 0, w * 2, h);
617
618 cc.mask (false, 2, 1);
619
620 static const XRenderColor c0 = { 0, 0, 0, 0 };
621 XRenderFillRectangle (cc.dpy, PictOpSrc, cc.msk, &c0, 0, 0, 1, 1);
622 static const XRenderColor c1 = { 65535, 65535, 65535, 65535 };
623 XRenderFillRectangle (cc.dpy, PictOpSrc, cc.msk, &c1, 1, 0, 1, 1);
624
625 Picture white = XRenderCreateSolidFill (cc.dpy, &c1);
626
627 XRenderComposite (cc.dpy, PictOpOver, white, cc.msk, cc.dst, 0, 0, 0, 0, 0, 0, w * 2, h);
628
629 XRenderFreePicture (cc.dpy, white);
630
631 // STEP 2: convolve the image with a 3x1 filter
632 // a 2x1 filter would obviously suffice, but given the total lack of specification
633 // for xrender, I expect different xrender implementations to randomly diverge.
634 // we also halve the image, and hope for the best (again, for lack of specs).
635 composer cc2 (cc.dstimg);
636
637 XFixed kernel [] = {
638 XDoubleToFixed (3), XDoubleToFixed (1),
639 XDoubleToFixed (0), XDoubleToFixed (mul), XDoubleToFixed (add)
640 };
641
642 XTransform h_halve = {
643 131072, 0, 0,
644 0, 65536, 0,
645 0, 0, 65536
646 };
647
648 XRenderSetPictureFilter (cc.dpy, cc2.src, "nearest", 0, 0);
649 XRenderSetPictureTransform (cc.dpy, cc2.src, &h_halve);
650 XRenderSetPictureFilter (cc.dpy, cc2.src, FilterConvolution, kernel, ecb_array_length (kernel));
651
652 XRenderComposite (cc.dpy, PictOpSrc, cc2.src, None, cc2.dst, 0, 0, 0, 0, 0, 0, w * 2, h);
653
654 return cc2;
591} 655}
592 656
593ecb_noinline static void 657ecb_noinline static void
594extract (int32_t cl0, int32_t cl1, int32_t &c, unsigned short &xc) 658extract (int32_t cl0, int32_t cl1, int32_t &c, unsigned short &xc)
595{ 659{
701rxvt_img::reify () 765rxvt_img::reify ()
702{ 766{
703 if (x == 0 && y == 0 && w == ref->w && h == ref->h) 767 if (x == 0 && y == 0 && w == ref->w && h == ref->h)
704 return clone (); 768 return clone ();
705 769
706 Display *dpy = s->dpy;
707
708 // add an alpha channel if... 770 // add an alpha channel if...
709 bool alpha = !format->direct.alphaMask // pixmap has none yet 771 bool alpha = !format->direct.alphaMask // pixmap has none yet
710 && (x || y) // we need one because of non-zero offset 772 && (x || y) // we need one because of non-zero offset
711 && repeat == RepeatNone; // and we have no good pixels to fill with 773 && repeat == RepeatNone; // and we have no good pixels to fill with
712 774
713 composer cc (this, new rxvt_img (s, alpha ? find_alpha_format_for (s->dpy, format) : format, 775 composer cc (this, new rxvt_img (s, alpha ? find_alpha_format_for (s->dpy, format) : format,
714 0, 0, w, h, repeat)); 776 0, 0, w, h, repeat));
715 777
716 if (alpha) 778 if (repeat == RepeatNone)
717 { 779 {
718 XRenderColor rc = { 0, 0, 0, 0 }; 780 XRenderColor rc = { 0, 0, 0, 0 };
719 XRenderFillRectangle (cc.dpy, PictOpSrc, cc.dst, &rc, 0, 0, w, h);//TODO: split into four fillrectangles 781 XRenderFillRectangle (cc.dpy, PictOpSrc, cc.dst, &rc, 0, 0, w, h);//TODO: split into four fillrectangles
720 XRenderComposite (cc.dpy, PictOpSrc, cc.src, None, cc.dst, 0, 0, 0, 0, x, y, ref->w, ref->h); 782 XRenderComposite (cc.dpy, PictOpSrc, cc.src, None, cc.dst, 0, 0, 0, 0, x, y, ref->w, ref->h);
721 } 783 }
815} 877}
816 878
817rxvt_img * 879rxvt_img *
818rxvt_img::rotate (int cx, int cy, nv phi) 880rxvt_img::rotate (int cx, int cy, nv phi)
819{ 881{
820#if 0
821 { c, -s, cx - c * cx + s * cy },
822 { s, c, cy - s * cx - c * cy },
823 { 0, 0, 1 }
824#endif
825
826 move (-cx, -cy); 882 move (-cx, -cy);
827 rxvt_img *img = transform (mat3x3::rotate (phi)); 883 rxvt_img *img = transform (mat3x3::rotate (phi));
828 move ( cx, cy); 884 move ( cx, cy);
829 img->move (cx, cy); 885 img->move (cx, cy);
830 886
868} 924}
869 925
870rxvt_img * 926rxvt_img *
871rxvt_img::filter (const char *name, int nparams, nv *params) 927rxvt_img::filter (const char *name, int nparams, nv *params)
872{ 928{
873 rxvt_img *img = new_empty ();
874
875 composer cc (img); 929 composer cc (this);
876 930
877 XFixed *xparams = rxvt_temp_buf<XFixed> (nparams); 931 XFixed *xparams = rxvt_temp_buf<XFixed> (nparams);
878 932
879 for (int i = 0; i < nparams; ++i) 933 for (int i = 0; i < nparams; ++i)
880 xparams [i] = XDoubleToFixed (params [i]); 934 xparams [i] = XDoubleToFixed (params [i]);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines