… | |
… | |
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 | |
6 | |
7 | rxvt_img::rxvt_img (rxvt_screen *screen, XRenderPictFormat *format, int x, int y, int width, int height) |
7 | 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(RepeatNormal), |
8 | : s(screen), x(x), y(y), w(width), h(height), format(format), repeat(repeat), |
9 | pm(0), ref(0) |
9 | pm(0), ref(0) |
10 | { |
10 | { |
11 | } |
11 | } |
12 | |
12 | |
13 | rxvt_img::rxvt_img (const rxvt_img &img) |
13 | rxvt_img::rxvt_img (const rxvt_img &img) |
… | |
… | |
114 | |
114 | |
115 | XRenderPictureAttributes pa; |
115 | XRenderPictureAttributes pa; |
116 | pa.repeat = repeat; |
116 | pa.repeat = repeat; |
117 | Picture pic = XRenderCreatePicture (dpy, pm, format, CPRepeat, &pa); |
117 | Picture pic = XRenderCreatePicture (dpy, pm, format, CPRepeat, &pa); |
118 | |
118 | |
119 | XRectangle clip = { -x, -y, min (w, ref->w), min (h, ref->h) }; |
|
|
120 | XRenderSetPictureClipRectangles (dpy, pic, 0, 0, &clip, 1); |
|
|
121 | |
|
|
122 | return pic; |
119 | return pic; |
123 | } |
120 | } |
124 | |
121 | |
125 | void |
122 | void |
126 | rxvt_img::unshare () |
123 | rxvt_img::unshare () |
… | |
… | |
179 | |
176 | |
180 | Display *dpy = s->display->dpy; |
177 | Display *dpy = s->display->dpy; |
181 | int size = max (rh, rv) * 2 + 1; |
178 | int size = max (rh, rv) * 2 + 1; |
182 | double *kernel = (double *)malloc (size * sizeof (double)); |
179 | double *kernel = (double *)malloc (size * sizeof (double)); |
183 | XFixed *params = (XFixed *)malloc ((size + 2) * sizeof (XFixed)); |
180 | XFixed *params = (XFixed *)malloc ((size + 2) * sizeof (XFixed)); |
184 | rxvt_img *img = new rxvt_img (s, format, x, y, w, h); |
181 | rxvt_img *img = new rxvt_img (s, format, x, y, w, h, repeat); |
185 | img->alloc (); |
182 | img->alloc (); |
186 | |
183 | |
187 | Picture src = src_picture (); |
184 | Picture src = src_picture (); |
188 | |
185 | |
189 | XRenderPictureAttributes pa; |
186 | XRenderPictureAttributes pa; |
… | |
… | |
397 | } |
394 | } |
398 | |
395 | |
399 | rxvt_img * |
396 | rxvt_img * |
400 | rxvt_img::reify () |
397 | rxvt_img::reify () |
401 | { |
398 | { |
402 | rxvt_img *img = new rxvt_img (s, format, 0, 0, w, h); |
399 | if (x == 0 && y == 0 && w == ref->w && h == ref->h) |
|
|
400 | return clone (); |
|
|
401 | |
|
|
402 | Display *dpy = s->display->dpy; |
|
|
403 | |
|
|
404 | bool alpha = !format->direct.alphaMask |
|
|
405 | && (x || y) |
|
|
406 | && repeat == RepeatNone; |
|
|
407 | |
|
|
408 | rxvt_img *img = new rxvt_img (s, alpha ? XRenderFindStandardFormat (dpy, PictStandardARGB32) : format, 0, 0, w, h, repeat); |
403 | img->alloc (); |
409 | img->alloc (); |
404 | |
|
|
405 | // todo, if x==0 and y==0 and w==real width we could clone |
|
|
406 | // but that involves an rtt to find pixmap width. |
|
|
407 | |
|
|
408 | Display *dpy = s->display->dpy; |
|
|
409 | |
410 | |
410 | Picture src = src_picture (); |
411 | Picture src = src_picture (); |
411 | Picture dst = XRenderCreatePicture (dpy, img->pm, img->format, 0, 0); |
412 | Picture dst = XRenderCreatePicture (dpy, img->pm, img->format, 0, 0); |
412 | |
413 | |
|
|
414 | if (alpha) |
|
|
415 | { |
|
|
416 | XRenderColor rc = { 0, 0, 0, 0 }; |
|
|
417 | XRenderFillRectangle (dpy, PictOpSrc, dst, &rc, 0, 0, w, h); |
|
|
418 | XRenderComposite (dpy, PictOpSrc, src, None, dst, 0, 0, 0, 0, -x, -y, ref->w, ref->h); |
|
|
419 | } |
|
|
420 | else |
413 | XRenderComposite (dpy, PictOpSrc, src, None, dst, x, y, 0, 0, 0, 0, w, h); |
421 | XRenderComposite (dpy, PictOpSrc, src, None, dst, x, y, 0, 0, 0, 0, w, h); |
414 | |
422 | |
415 | XRenderFreePicture (dpy, src); |
423 | XRenderFreePicture (dpy, src); |
416 | XRenderFreePicture (dpy, dst); |
424 | XRenderFreePicture (dpy, dst); |
417 | |
425 | |
418 | return img; |
426 | return img; |
419 | } |
427 | } |
420 | |
428 | |
421 | rxvt_img * |
429 | rxvt_img * |
422 | rxvt_img::sub_rect (int x, int y, int width, int height) |
430 | rxvt_img::sub_rect (int x, int y, int width, int height) |
423 | { |
431 | { |
424 | rxvt_img *img = clone (); |
432 | rxvt_img *img = clone (); |
425 | |
|
|
426 | //TODO: width > w, must reify |
|
|
427 | |
433 | |
428 | img->x += x; |
434 | img->x += x; |
429 | img->y += y; |
435 | img->y += y; |
|
|
436 | |
|
|
437 | if (w != width || h != height) |
|
|
438 | { |
430 | img->w = width; |
439 | img->w = width; |
431 | img->h = height; |
440 | img->h = height; |
|
|
441 | |
|
|
442 | rxvt_img *img2 = img->reify (); |
|
|
443 | delete img; |
|
|
444 | img = img2; |
|
|
445 | } |
432 | |
446 | |
433 | return img; |
447 | return img; |
434 | } |
448 | } |
435 | |
449 | |
436 | rxvt_img * |
450 | rxvt_img * |
437 | rxvt_img::transform (int new_width, int new_height, double matrix[9]) |
451 | rxvt_img::transform (int new_width, int new_height, double matrix[9]) |
438 | { |
452 | { |
439 | rxvt_img *img = new rxvt_img (s, format, 0, 0, new_width, new_height); |
453 | rxvt_img *img = new rxvt_img (s, format, 0, 0, new_width, new_height, repeat); |
440 | img->alloc (); |
454 | img->alloc (); |
441 | |
455 | |
442 | Display *dpy = s->display->dpy; |
456 | Display *dpy = s->display->dpy; |
443 | Picture src = src_picture (); |
457 | Picture src = src_picture (); |
444 | Picture dst = XRenderCreatePicture (dpy, img->pm, img->format, 0, 0); |
458 | Picture dst = XRenderCreatePicture (dpy, img->pm, img->format, 0, 0); |
… | |
… | |
469 | w / (double)new_width, 0, 0, |
483 | w / (double)new_width, 0, 0, |
470 | 0, h / (double)new_height, 0, |
484 | 0, h / (double)new_height, 0, |
471 | 0, 0, 1 |
485 | 0, 0, 1 |
472 | }; |
486 | }; |
473 | |
487 | |
|
|
488 | int old_repeat_mode = repeat; |
|
|
489 | repeat = RepeatPad; // not right, but xrender can't proeprly scale it seems |
|
|
490 | |
474 | return transform (new_width, new_height, matrix); |
491 | rxvt_img *img = transform (new_width, new_height, matrix); |
|
|
492 | |
|
|
493 | repeat = old_repeat_mode; |
|
|
494 | img->repeat = repeat; |
|
|
495 | |
|
|
496 | return img; |
475 | } |
497 | } |
476 | |
498 | |
477 | rxvt_img * |
499 | rxvt_img * |
478 | rxvt_img::rotate (int new_width, int new_height, int x, int y, double phi) |
500 | rxvt_img::rotate (int new_width, int new_height, int x, int y, double phi) |
479 | { |
501 | { |
… | |
… | |
493 | rxvt_img::convert_to (XRenderPictFormat *new_format, const rxvt_color &bg) |
515 | rxvt_img::convert_to (XRenderPictFormat *new_format, const rxvt_color &bg) |
494 | { |
516 | { |
495 | if (new_format == format) |
517 | if (new_format == format) |
496 | return clone (); |
518 | return clone (); |
497 | |
519 | |
498 | rxvt_img *img = new rxvt_img (s, new_format, 0, 0, w, h); |
520 | rxvt_img *img = new rxvt_img (s, new_format, 0, 0, w, h, repeat); |
499 | img->alloc (); |
521 | img->alloc (); |
|
|
522 | |
|
|
523 | printf ("convert %d to %d\n", format->direct.alphaMask, new_format->direct.alphaMask);//D |
500 | |
524 | |
501 | Display *dpy = s->display->dpy; |
525 | Display *dpy = s->display->dpy; |
502 | Picture src = src_picture (); |
526 | Picture src = src_picture (); |
503 | Picture dst = XRenderCreatePicture (dpy, img->pm, new_format, 0, 0); |
527 | Picture dst = XRenderCreatePicture (dpy, img->pm, new_format, 0, 0); |
504 | int op = PictOpSrc; |
528 | int op = PictOpSrc; |
… | |
… | |
526 | rxvt_img * |
550 | rxvt_img * |
527 | rxvt_img::blend (rxvt_img *img, double factor) |
551 | rxvt_img::blend (rxvt_img *img, double factor) |
528 | { |
552 | { |
529 | rxvt_img *img2 = clone (); |
553 | rxvt_img *img2 = clone (); |
530 | Display *dpy = s->display->dpy; |
554 | Display *dpy = s->display->dpy; |
531 | Picture src = src_picture (); |
555 | Picture src = img->src_picture (); |
532 | Picture dst = XRenderCreatePicture (dpy, img2->pm, img2->format, 0, 0); |
556 | Picture dst = XRenderCreatePicture (dpy, img2->pm, img2->format, 0, 0); |
533 | Picture mask = create_xrender_mask (dpy, img->pm, False); |
557 | Picture mask = create_xrender_mask (dpy, img->pm, False); |
534 | |
558 | |
535 | XRenderColor mask_c; |
559 | XRenderColor mask_c; |
536 | |
560 | |