… | |
… | |
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 | |
251 | 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) |
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 | |
|
|
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 | |
257 | rxvt_img::rxvt_img (const rxvt_img &img) |
263 | rxvt_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 | |
263 | rxvt_img * |
269 | rxvt_img * |
… | |
… | |
392 | } |
398 | } |
393 | |
399 | |
394 | rxvt_img * |
400 | rxvt_img * |
395 | rxvt_img::new_from_file (rxvt_screen *s, const char *filename) |
401 | rxvt_img::new_from_file (rxvt_screen *s, const char *filename) |
396 | { |
402 | { |
397 | GError *err = 0; |
403 | GError *err; |
398 | GdkPixbuf *pb = gdk_pixbuf_new_from_file (filename, &err); |
404 | GdkPixbuf *pb = gdk_pixbuf_new_from_file (filename, &err); |
399 | |
405 | |
400 | if (!pb) |
406 | if (!pb) |
|
|
407 | try |
|
|
408 | { |
401 | 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 | } |
402 | |
416 | |
403 | rxvt_img *img = new_from_pixbuf (s, pb); |
417 | rxvt_img *img = new_from_pixbuf (s, pb); |
404 | |
418 | |
405 | g_object_unref (pb); |
419 | g_object_unref (pb); |
406 | |
420 | |
… | |
… | |
414 | { |
428 | { |
415 | if (--ref->cnt) |
429 | if (--ref->cnt) |
416 | return; |
430 | return; |
417 | |
431 | |
418 | if (pm && ref->ours) |
432 | if (pm && ref->ours) |
419 | XFreePixmap (s->dpy, pm); |
433 | XFreePixmap (d->dpy, pm); |
420 | |
434 | |
421 | delete ref; |
435 | delete ref; |
422 | } |
436 | } |
423 | |
437 | |
424 | rxvt_img::~rxvt_img () |
438 | rxvt_img::~rxvt_img () |
… | |
… | |
427 | } |
441 | } |
428 | |
442 | |
429 | void |
443 | void |
430 | rxvt_img::alloc () |
444 | rxvt_img::alloc () |
431 | { |
445 | { |
432 | pm = XCreatePixmap (s->dpy, s->display->root, w, h, format->depth); |
446 | pm = XCreatePixmap (d->dpy, d->root, w, h, format->depth); |
433 | ref = new pixref (w, h); |
447 | ref = new pixref (w, h); |
434 | } |
448 | } |
435 | |
449 | |
436 | rxvt_img * |
450 | rxvt_img * |
437 | rxvt_img::new_empty () |
451 | rxvt_img::new_empty () |
438 | { |
452 | { |
439 | 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); |
440 | img->alloc (); |
454 | img->alloc (); |
441 | |
455 | |
442 | return img; |
456 | return img; |
443 | } |
457 | } |
444 | |
458 | |
445 | Picture |
459 | Picture |
446 | rxvt_img::picture () |
460 | rxvt_img::picture () |
447 | { |
461 | { |
448 | Display *dpy = s->dpy; |
462 | Display *dpy = d->dpy; |
449 | |
463 | |
450 | XRenderPictureAttributes pa; |
464 | XRenderPictureAttributes pa; |
451 | pa.repeat = repeat; |
465 | pa.repeat = repeat; |
452 | Picture pic = XRenderCreatePicture (dpy, pm, format, CPRepeat, &pa); |
466 | Picture pic = XRenderCreatePicture (dpy, pm, format, CPRepeat, &pa); |
453 | |
467 | |
… | |
… | |
458 | rxvt_img::unshare () |
472 | rxvt_img::unshare () |
459 | { |
473 | { |
460 | if (ref->cnt == 1 && ref->ours) |
474 | if (ref->cnt == 1 && ref->ours) |
461 | return; |
475 | return; |
462 | |
476 | |
463 | 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); |
464 | GC gc = XCreateGC (s->dpy, pm, 0, 0); |
478 | GC gc = XCreateGC (d->dpy, pm, 0, 0); |
465 | 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); |
466 | XFreeGC (s->dpy, gc); |
480 | XFreeGC (d->dpy, gc); |
467 | |
481 | |
468 | destroy (); |
482 | destroy (); |
469 | |
483 | |
470 | pm = pm2; |
484 | pm = pm2; |
471 | ref = new pixref (ref->w, ref->h); |
485 | ref = new pixref (ref->w, ref->h); |
… | |
… | |
474 | void |
488 | void |
475 | 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) |
476 | { |
490 | { |
477 | XRenderColor rc = { c.r, c.g, c.b, c.a }; |
491 | XRenderColor rc = { c.r, c.g, c.b, c.a }; |
478 | |
492 | |
479 | Display *dpy = s->dpy; |
493 | Display *dpy = d->dpy; |
480 | Picture src = picture (); |
494 | Picture src = picture (); |
481 | XRenderFillRectangle (dpy, PictOpSrc, src, &rc, x, y, w, h); |
495 | XRenderFillRectangle (dpy, PictOpSrc, src, &rc, x, y, w, h); |
482 | XRenderFreePicture (dpy, src); |
496 | XRenderFreePicture (dpy, src); |
483 | } |
497 | } |
484 | |
498 | |
… | |
… | |
492 | rxvt_img::add_alpha () |
506 | rxvt_img::add_alpha () |
493 | { |
507 | { |
494 | if (format->direct.alphaMask) |
508 | if (format->direct.alphaMask) |
495 | return; |
509 | return; |
496 | |
510 | |
497 | 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)); |
498 | |
512 | |
499 | 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); |
500 | |
514 | |
501 | rxvt_img *img = cc; |
515 | rxvt_img *img = cc; |
502 | |
516 | |
… | |
… | |
528 | } |
542 | } |
529 | |
543 | |
530 | rxvt_img * |
544 | rxvt_img * |
531 | rxvt_img::blur (int rh, int rv) |
545 | rxvt_img::blur (int rh, int rv) |
532 | { |
546 | { |
533 | if (!(s->display->flags & DISPLAY_HAS_RENDER_CONV)) |
547 | if (!(d->flags & DISPLAY_HAS_RENDER_CONV)) |
534 | return clone (); |
548 | return clone (); |
535 | |
549 | |
536 | Display *dpy = s->dpy; |
550 | Display *dpy = d->dpy; |
537 | int size = max (rh, rv) * 2 + 1; |
551 | int size = max (rh, rv) * 2 + 1; |
538 | nv *kernel = (nv *)malloc (size * sizeof (nv)); |
552 | nv *kernel = (nv *)malloc (size * sizeof (nv)); |
539 | XFixed *params = rxvt_temp_buf<XFixed> (size + 2); |
553 | XFixed *params = rxvt_temp_buf<XFixed> (size + 2); |
540 | rxvt_img *img = new_empty (); |
554 | rxvt_img *img = new_empty (); |
541 | |
555 | |
… | |
… | |
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 | composer cc (this, new rxvt_img (d, format, 0, 0, w * 2, h, repeat)); |
598 | |
612 | |
599 | // why the hell does XRenderSetPictureTransform want a writable matrix :( |
613 | // why the hell does XRenderSetPictureTransform want a writable matrix :( |
600 | // that keeps us from just static const'ing this matrix. |
614 | // that keeps us from just static const'ing this matrix. |
601 | XTransform h_double = { |
615 | XTransform h_double = { |
602 | 0x08000, 0, 0, |
616 | 0x08000, 0, 0, |
… | |
… | |
669 | void |
683 | void |
670 | rxvt_img::brightness (int32_t r, int32_t g, int32_t b, int32_t a) |
684 | rxvt_img::brightness (int32_t r, int32_t g, int32_t b, int32_t a) |
671 | { |
685 | { |
672 | unshare (); |
686 | unshare (); |
673 | |
687 | |
674 | Display *dpy = s->dpy; |
688 | Display *dpy = d->dpy; |
675 | Picture dst = XRenderCreatePicture (dpy, pm, format, 0, 0); |
689 | Picture dst = XRenderCreatePicture (dpy, pm, format, 0, 0); |
676 | |
690 | |
677 | // loop should not be needed for brightness, as only -1..1 makes sense |
691 | // loop should not be needed for brightness, as only -1..1 makes sense |
678 | //while (r | g | b | a) |
692 | //while (r | g | b | a) |
679 | { |
693 | { |
… | |
… | |
763 | // add an alpha channel if... |
777 | // add an alpha channel if... |
764 | bool alpha = !format->direct.alphaMask // pixmap has none yet |
778 | bool alpha = !format->direct.alphaMask // pixmap has none yet |
765 | && (x || y) // we need one because of non-zero offset |
779 | && (x || y) // we need one because of non-zero offset |
766 | && repeat == RepeatNone; // and we have no good pixels to fill with |
780 | && repeat == RepeatNone; // and we have no good pixels to fill with |
767 | |
781 | |
768 | composer cc (this, new rxvt_img (s, alpha ? find_alpha_format_for (s->dpy, format) : format, |
782 | composer cc (this, new rxvt_img (d, alpha ? find_alpha_format_for (d->dpy, format) : format, |
769 | 0, 0, w, h, repeat)); |
783 | 0, 0, w, h, repeat)); |
770 | |
784 | |
771 | if (repeat == RepeatNone) |
785 | if (repeat == RepeatNone) |
772 | { |
786 | { |
773 | XRenderColor rc = { 0, 0, 0, 0 }; |
787 | XRenderColor rc = { 0, 0, 0, 0 }; |
… | |
… | |
835 | int new_width = ceil (rmax [0] - rmin [0]); |
849 | int new_width = ceil (rmax [0] - rmin [0]); |
836 | int new_height = ceil (rmax [1] - rmin [1]); |
850 | int new_height = ceil (rmax [1] - rmin [1]); |
837 | |
851 | |
838 | mat3x3 inv = (mat3x3::translate (-x, -y) * m * mat3x3::translate (x, y)).inverse (); |
852 | mat3x3 inv = (mat3x3::translate (-x, -y) * m * mat3x3::translate (x, y)).inverse (); |
839 | |
853 | |
840 | composer cc (this, new rxvt_img (s, format, nx, ny, new_width, new_height, repeat)); |
854 | composer cc (this, new rxvt_img (d, format, nx, ny, new_width, new_height, repeat)); |
841 | |
855 | |
842 | XTransform xfrm; |
856 | XTransform xfrm; |
843 | |
857 | |
844 | for (int i = 0; i < 3; ++i) |
858 | for (int i = 0; i < 3; ++i) |
845 | for (int j = 0; j < 3; ++j) |
859 | for (int j = 0; j < 3; ++j) |
… | |
… | |
884 | rxvt_img::convert_format (XRenderPictFormat *new_format, const rgba &bg) |
898 | rxvt_img::convert_format (XRenderPictFormat *new_format, const rgba &bg) |
885 | { |
899 | { |
886 | if (new_format == format) |
900 | if (new_format == format) |
887 | return clone (); |
901 | return clone (); |
888 | |
902 | |
889 | composer cc (this, new rxvt_img (s, new_format, x, y, w, h, repeat)); |
903 | composer cc (this, new rxvt_img (d, new_format, x, y, w, h, repeat)); |
890 | |
904 | |
891 | int op = PictOpSrc; |
905 | int op = PictOpSrc; |
892 | |
906 | |
893 | if (format->direct.alphaMask && !new_format->direct.alphaMask) |
907 | if (format->direct.alphaMask && !new_format->direct.alphaMask) |
894 | { |
908 | { |