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.108 by sf-exg, Fri Nov 7 13:45:55 2014 UTC vs.
Revision 1.109 by sf-exg, Sat Jul 15 08:16:31 2017 UTC

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
247 // should be a very good fallback 247 // should be a very good fallback
248 return XRenderFindStandardFormat (dpy, PictStandardARGB32); 248 return XRenderFindStandardFormat (dpy, PictStandardARGB32);
249} 249}
250 250
251rxvt_img::rxvt_img (rxvt_screen *screen, XRenderPictFormat *format, int x, int y, int width, int height, int repeat) 251rxvt_img::rxvt_img (rxvt_screen *screen, XRenderPictFormat *format, int x, int y, int width, int height, int repeat)
252: 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),
253 pm(0), ref(0) 253 pm(0), ref(0)
254{ 254{
255} 255}
256 256
257rxvt_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
257rxvt_img::rxvt_img (const rxvt_img &img) 263rxvt_img::rxvt_img (const rxvt_img &img)
258: 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)
259{ 265{
260 ++ref->cnt; 266 ++ref->cnt;
261} 267}
262 268
263rxvt_img * 269rxvt_img *
414{ 420{
415 if (--ref->cnt) 421 if (--ref->cnt)
416 return; 422 return;
417 423
418 if (pm && ref->ours) 424 if (pm && ref->ours)
419 XFreePixmap (s->dpy, pm); 425 XFreePixmap (d->dpy, pm);
420 426
421 delete ref; 427 delete ref;
422} 428}
423 429
424rxvt_img::~rxvt_img () 430rxvt_img::~rxvt_img ()
427} 433}
428 434
429void 435void
430rxvt_img::alloc () 436rxvt_img::alloc ()
431{ 437{
432 pm = XCreatePixmap (s->dpy, s->display->root, w, h, format->depth); 438 pm = XCreatePixmap (d->dpy, d->root, w, h, format->depth);
433 ref = new pixref (w, h); 439 ref = new pixref (w, h);
434} 440}
435 441
436rxvt_img * 442rxvt_img *
437rxvt_img::new_empty () 443rxvt_img::new_empty ()
438{ 444{
439 rxvt_img *img = new rxvt_img (s, format, x, y, w, h, repeat); 445 rxvt_img *img = new rxvt_img (d, format, x, y, w, h, repeat);
440 img->alloc (); 446 img->alloc ();
441 447
442 return img; 448 return img;
443} 449}
444 450
445Picture 451Picture
446rxvt_img::picture () 452rxvt_img::picture ()
447{ 453{
448 Display *dpy = s->dpy; 454 Display *dpy = d->dpy;
449 455
450 XRenderPictureAttributes pa; 456 XRenderPictureAttributes pa;
451 pa.repeat = repeat; 457 pa.repeat = repeat;
452 Picture pic = XRenderCreatePicture (dpy, pm, format, CPRepeat, &pa); 458 Picture pic = XRenderCreatePicture (dpy, pm, format, CPRepeat, &pa);
453 459
458rxvt_img::unshare () 464rxvt_img::unshare ()
459{ 465{
460 if (ref->cnt == 1 && ref->ours) 466 if (ref->cnt == 1 && ref->ours)
461 return; 467 return;
462 468
463 Pixmap pm2 = XCreatePixmap (s->dpy, s->display->root, ref->w, ref->h, format->depth); 469 Pixmap pm2 = XCreatePixmap (d->dpy, d->root, ref->w, ref->h, format->depth);
464 GC gc = XCreateGC (s->dpy, pm, 0, 0); 470 GC gc = XCreateGC (d->dpy, pm, 0, 0);
465 XCopyArea (s->dpy, pm, pm2, gc, 0, 0, ref->w, ref->h, 0, 0); 471 XCopyArea (d->dpy, pm, pm2, gc, 0, 0, ref->w, ref->h, 0, 0);
466 XFreeGC (s->dpy, gc); 472 XFreeGC (d->dpy, gc);
467 473
468 destroy (); 474 destroy ();
469 475
470 pm = pm2; 476 pm = pm2;
471 ref = new pixref (ref->w, ref->h); 477 ref = new pixref (ref->w, ref->h);
474void 480void
475rxvt_img::fill (const rgba &c, int x, int y, int w, int h) 481rxvt_img::fill (const rgba &c, int x, int y, int w, int h)
476{ 482{
477 XRenderColor rc = { c.r, c.g, c.b, c.a }; 483 XRenderColor rc = { c.r, c.g, c.b, c.a };
478 484
479 Display *dpy = s->dpy; 485 Display *dpy = d->dpy;
480 Picture src = picture (); 486 Picture src = picture ();
481 XRenderFillRectangle (dpy, PictOpSrc, src, &rc, x, y, w, h); 487 XRenderFillRectangle (dpy, PictOpSrc, src, &rc, x, y, w, h);
482 XRenderFreePicture (dpy, src); 488 XRenderFreePicture (dpy, src);
483} 489}
484 490
492rxvt_img::add_alpha () 498rxvt_img::add_alpha ()
493{ 499{
494 if (format->direct.alphaMask) 500 if (format->direct.alphaMask)
495 return; 501 return;
496 502
497 composer cc (this, new rxvt_img (s, find_alpha_format_for (s->dpy, format), x, y, w, h, repeat)); 503 composer cc (this, new rxvt_img (d, find_alpha_format_for (d->dpy, format), x, y, w, h, repeat));
498 504
499 XRenderComposite (cc.dpy, PictOpSrc, cc.src, None, cc.dst, 0, 0, 0, 0, 0, 0, w, h); 505 XRenderComposite (cc.dpy, PictOpSrc, cc.src, None, cc.dst, 0, 0, 0, 0, 0, 0, w, h);
500 506
501 rxvt_img *img = cc; 507 rxvt_img *img = cc;
502 508
528} 534}
529 535
530rxvt_img * 536rxvt_img *
531rxvt_img::blur (int rh, int rv) 537rxvt_img::blur (int rh, int rv)
532{ 538{
533 if (!(s->display->flags & DISPLAY_HAS_RENDER_CONV)) 539 if (!(d->flags & DISPLAY_HAS_RENDER_CONV))
534 return clone (); 540 return clone ();
535 541
536 Display *dpy = s->dpy; 542 Display *dpy = d->dpy;
537 int size = max (rh, rv) * 2 + 1; 543 int size = max (rh, rv) * 2 + 1;
538 nv *kernel = (nv *)malloc (size * sizeof (nv)); 544 nv *kernel = (nv *)malloc (size * sizeof (nv));
539 XFixed *params = rxvt_temp_buf<XFixed> (size + 2); 545 XFixed *params = rxvt_temp_buf<XFixed> (size + 2);
540 rxvt_img *img = new_empty (); 546 rxvt_img *img = new_empty ();
541 547
592rxvt_img * 598rxvt_img *
593rxvt_img::muladd (nv mul, nv add) 599rxvt_img::muladd (nv mul, nv add)
594{ 600{
595 // STEP 1: double the image width, fill all odd columns with white (==1) 601 // STEP 1: double the image width, fill all odd columns with white (==1)
596 602
597 composer cc (this, new rxvt_img (s, format, 0, 0, w * 2, h, repeat)); 603 composer cc (this, new rxvt_img (d, format, 0, 0, w * 2, h, repeat));
598 604
599 // why the hell does XRenderSetPictureTransform want a writable matrix :( 605 // why the hell does XRenderSetPictureTransform want a writable matrix :(
600 // that keeps us from just static const'ing this matrix. 606 // that keeps us from just static const'ing this matrix.
601 XTransform h_double = { 607 XTransform h_double = {
602 0x08000, 0, 0, 608 0x08000, 0, 0,
669void 675void
670rxvt_img::brightness (int32_t r, int32_t g, int32_t b, int32_t a) 676rxvt_img::brightness (int32_t r, int32_t g, int32_t b, int32_t a)
671{ 677{
672 unshare (); 678 unshare ();
673 679
674 Display *dpy = s->dpy; 680 Display *dpy = d->dpy;
675 Picture dst = XRenderCreatePicture (dpy, pm, format, 0, 0); 681 Picture dst = XRenderCreatePicture (dpy, pm, format, 0, 0);
676 682
677 // loop should not be needed for brightness, as only -1..1 makes sense 683 // loop should not be needed for brightness, as only -1..1 makes sense
678 //while (r | g | b | a) 684 //while (r | g | b | a)
679 { 685 {
763 // add an alpha channel if... 769 // add an alpha channel if...
764 bool alpha = !format->direct.alphaMask // pixmap has none yet 770 bool alpha = !format->direct.alphaMask // pixmap has none yet
765 && (x || y) // we need one because of non-zero offset 771 && (x || y) // we need one because of non-zero offset
766 && repeat == RepeatNone; // and we have no good pixels to fill with 772 && repeat == RepeatNone; // and we have no good pixels to fill with
767 773
768 composer cc (this, new rxvt_img (s, alpha ? find_alpha_format_for (s->dpy, format) : format, 774 composer cc (this, new rxvt_img (d, alpha ? find_alpha_format_for (d->dpy, format) : format,
769 0, 0, w, h, repeat)); 775 0, 0, w, h, repeat));
770 776
771 if (repeat == RepeatNone) 777 if (repeat == RepeatNone)
772 { 778 {
773 XRenderColor rc = { 0, 0, 0, 0 }; 779 XRenderColor rc = { 0, 0, 0, 0 };
835 int new_width = ceil (rmax [0] - rmin [0]); 841 int new_width = ceil (rmax [0] - rmin [0]);
836 int new_height = ceil (rmax [1] - rmin [1]); 842 int new_height = ceil (rmax [1] - rmin [1]);
837 843
838 mat3x3 inv = (mat3x3::translate (-x, -y) * m * mat3x3::translate (x, y)).inverse (); 844 mat3x3 inv = (mat3x3::translate (-x, -y) * m * mat3x3::translate (x, y)).inverse ();
839 845
840 composer cc (this, new rxvt_img (s, format, nx, ny, new_width, new_height, repeat)); 846 composer cc (this, new rxvt_img (d, format, nx, ny, new_width, new_height, repeat));
841 847
842 XTransform xfrm; 848 XTransform xfrm;
843 849
844 for (int i = 0; i < 3; ++i) 850 for (int i = 0; i < 3; ++i)
845 for (int j = 0; j < 3; ++j) 851 for (int j = 0; j < 3; ++j)
884rxvt_img::convert_format (XRenderPictFormat *new_format, const rgba &bg) 890rxvt_img::convert_format (XRenderPictFormat *new_format, const rgba &bg)
885{ 891{
886 if (new_format == format) 892 if (new_format == format)
887 return clone (); 893 return clone ();
888 894
889 composer cc (this, new rxvt_img (s, new_format, x, y, w, h, repeat)); 895 composer cc (this, new rxvt_img (d, new_format, x, y, w, h, repeat));
890 896
891 int op = PictOpSrc; 897 int op = PictOpSrc;
892 898
893 if (format->direct.alphaMask && !new_format->direct.alphaMask) 899 if (format->direct.alphaMask && !new_format->direct.alphaMask)
894 { 900 {

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines