… | |
… | |
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) |
… | |
… | |
176 | |
176 | |
177 | Display *dpy = s->display->dpy; |
177 | Display *dpy = s->display->dpy; |
178 | int size = max (rh, rv) * 2 + 1; |
178 | int size = max (rh, rv) * 2 + 1; |
179 | double *kernel = (double *)malloc (size * sizeof (double)); |
179 | double *kernel = (double *)malloc (size * sizeof (double)); |
180 | XFixed *params = (XFixed *)malloc ((size + 2) * sizeof (XFixed)); |
180 | XFixed *params = (XFixed *)malloc ((size + 2) * sizeof (XFixed)); |
181 | 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); |
182 | img->alloc (); |
182 | img->alloc (); |
183 | |
183 | |
184 | Picture src = src_picture (); |
184 | Picture src = src_picture (); |
185 | |
185 | |
186 | XRenderPictureAttributes pa; |
186 | XRenderPictureAttributes pa; |
… | |
… | |
397 | rxvt_img::reify () |
397 | rxvt_img::reify () |
398 | { |
398 | { |
399 | if (x == 0 && y == 0 && w == ref->w && h == ref->h) |
399 | if (x == 0 && y == 0 && w == ref->w && h == ref->h) |
400 | return clone (); |
400 | return clone (); |
401 | |
401 | |
402 | rxvt_img *img = new rxvt_img (s, format, 0, 0, w, h); |
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 | Display *dpy = s->display->dpy; |
|
|
406 | |
410 | |
407 | Picture src = src_picture (); |
411 | Picture src = src_picture (); |
408 | Picture dst = XRenderCreatePicture (dpy, img->pm, img->format, 0, 0); |
412 | Picture dst = XRenderCreatePicture (dpy, img->pm, img->format, 0, 0); |
409 | |
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 |
410 | 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); |
411 | |
422 | |
412 | XRenderFreePicture (dpy, src); |
423 | XRenderFreePicture (dpy, src); |
413 | XRenderFreePicture (dpy, dst); |
424 | XRenderFreePicture (dpy, dst); |
414 | |
425 | |
415 | return img; |
426 | return img; |
416 | } |
427 | } |
… | |
… | |
437 | } |
448 | } |
438 | |
449 | |
439 | rxvt_img * |
450 | rxvt_img * |
440 | 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]) |
441 | { |
452 | { |
442 | 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); |
443 | img->alloc (); |
454 | img->alloc (); |
444 | |
455 | |
445 | Display *dpy = s->display->dpy; |
456 | Display *dpy = s->display->dpy; |
446 | Picture src = src_picture (); |
457 | Picture src = src_picture (); |
447 | Picture dst = XRenderCreatePicture (dpy, img->pm, img->format, 0, 0); |
458 | Picture dst = XRenderCreatePicture (dpy, img->pm, img->format, 0, 0); |
… | |
… | |
466 | } |
477 | } |
467 | |
478 | |
468 | rxvt_img * |
479 | rxvt_img * |
469 | rxvt_img::scale (int new_width, int new_height) |
480 | rxvt_img::scale (int new_width, int new_height) |
470 | { |
481 | { |
|
|
482 | if (w == new_width && h == new_height) |
|
|
483 | return clone (); |
|
|
484 | |
471 | double matrix[9] = { |
485 | double matrix[9] = { |
472 | w / (double)new_width, 0, 0, |
486 | w / (double)new_width, 0, 0, |
473 | 0, h / (double)new_height, 0, |
487 | 0, h / (double)new_height, 0, |
474 | 0, 0, 1 |
488 | 0, 0, 1 |
475 | }; |
489 | }; |
476 | |
490 | |
|
|
491 | int old_repeat_mode = repeat; |
|
|
492 | repeat = RepeatPad; // not right, but xrender can't proeprly scale it seems |
|
|
493 | |
477 | return transform (new_width, new_height, matrix); |
494 | rxvt_img *img = transform (new_width, new_height, matrix); |
|
|
495 | |
|
|
496 | repeat = old_repeat_mode; |
|
|
497 | img->repeat = repeat; |
|
|
498 | |
|
|
499 | return img; |
478 | } |
500 | } |
479 | |
501 | |
480 | rxvt_img * |
502 | rxvt_img * |
481 | rxvt_img::rotate (int new_width, int new_height, int x, int y, double phi) |
503 | rxvt_img::rotate (int new_width, int new_height, int x, int y, double phi) |
482 | { |
504 | { |
… | |
… | |
496 | rxvt_img::convert_to (XRenderPictFormat *new_format, const rxvt_color &bg) |
518 | rxvt_img::convert_to (XRenderPictFormat *new_format, const rxvt_color &bg) |
497 | { |
519 | { |
498 | if (new_format == format) |
520 | if (new_format == format) |
499 | return clone (); |
521 | return clone (); |
500 | |
522 | |
501 | rxvt_img *img = new rxvt_img (s, new_format, 0, 0, w, h); |
523 | rxvt_img *img = new rxvt_img (s, new_format, 0, 0, w, h, repeat); |
502 | img->alloc (); |
524 | img->alloc (); |
|
|
525 | |
|
|
526 | printf ("convert %d to %d\n", format->direct.alphaMask, new_format->direct.alphaMask);//D |
503 | |
527 | |
504 | Display *dpy = s->display->dpy; |
528 | Display *dpy = s->display->dpy; |
505 | Picture src = src_picture (); |
529 | Picture src = src_picture (); |
506 | Picture dst = XRenderCreatePicture (dpy, img->pm, new_format, 0, 0); |
530 | Picture dst = XRenderCreatePicture (dpy, img->pm, new_format, 0, 0); |
507 | int op = PictOpSrc; |
531 | int op = PictOpSrc; |