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.37 by root, Thu Jun 7 09:25:23 2012 UTC vs.
Revision 1.46 by root, Thu Jun 7 18:07:42 2012 UTC

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
7rxvt_img::rxvt_img (rxvt_screen *screen, XRenderPictFormat *format, int x, int y, int width, int height) 7rxvt_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
13rxvt_img::rxvt_img (const rxvt_img &img) 13rxvt_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;
391rxvt_img::clone () 391rxvt_img::clone ()
392{ 392{
393 return new rxvt_img (*this); 393 return new rxvt_img (*this);
394} 394}
395 395
396
397static XRenderPictFormat *
398find_alpha_format_for (Display *dpy, XRenderPictFormat *format)
399{
400 if (format->direct.alphaMask)
401 return format; // already has alpha
402
403 // try to find a suitable alpha format, one bit alpha is enough for our purposes
404 if (format->type == PictTypeDirect)
405 for (int n = 0; XRenderPictFormat *f = XRenderFindFormat (dpy, 0, 0, n); ++n)
406 if (f->direct.alphaMask
407 && f->type == PictTypeDirect
408 && ecb_popcount32 (f->direct.redMask ) >= ecb_popcount32 (format->direct.redMask )
409 && ecb_popcount32 (f->direct.greenMask) >= ecb_popcount32 (format->direct.greenMask)
410 && ecb_popcount32 (f->direct.blueMask ) >= ecb_popcount32 (format->direct.blueMask ))
411 return f;
412
413 // should be a very good fallback
414 return XRenderFindStandardFormat (dpy, PictStandardARGB32);
415}
416
396rxvt_img * 417rxvt_img *
397rxvt_img::reify () 418rxvt_img::reify ()
398{ 419{
399 if (x == 0 && y == 0 && w == ref->w && h == ref->h) 420 if (x == 0 && y == 0 && w == ref->w && h == ref->h)
400 return clone (); 421 return clone ();
401 422
402 rxvt_img *img = new rxvt_img (s, format, 0, 0, w, h); 423 Display *dpy = s->display->dpy;
424
425 bool alpha = !format->direct.alphaMask
426 && (x || y)
427 && repeat == RepeatNone;
428
429 rxvt_img *img = new rxvt_img (s, alpha ? find_alpha_format_for (dpy, format) : format, 0, 0, w, h, repeat);
403 img->alloc (); 430 img->alloc ();
404
405 Display *dpy = s->display->dpy;
406 431
407 Picture src = src_picture (); 432 Picture src = src_picture ();
408 Picture dst = XRenderCreatePicture (dpy, img->pm, img->format, 0, 0); 433 Picture dst = XRenderCreatePicture (dpy, img->pm, img->format, 0, 0);
409 434
435 if (alpha)
436 {
437 XRenderColor rc = { 0, 0, 0, 0 };
438 XRenderFillRectangle (dpy, PictOpSrc, dst, &rc, 0, 0, w, h);//TODO: split into four fillrectangles
439 XRenderComposite (dpy, PictOpSrc, src, None, dst, 0, 0, 0, 0, -x, -y, ref->w, ref->h);
440 }
441 else
410 XRenderComposite (dpy, PictOpSrc, src, None, dst, x, y, 0, 0, 0, 0, w, h); 442 XRenderComposite (dpy, PictOpSrc, src, None, dst, x, y, 0, 0, 0, 0, w, h);
411 443
412 XRenderFreePicture (dpy, src); 444 XRenderFreePicture (dpy, src);
413 XRenderFreePicture (dpy, dst); 445 XRenderFreePicture (dpy, dst);
414 446
415 return img; 447 return img;
416} 448}
426 if (w != width || h != height) 458 if (w != width || h != height)
427 { 459 {
428 img->w = width; 460 img->w = width;
429 img->h = height; 461 img->h = height;
430 462
431 img->reify (); 463 rxvt_img *img2 = img->reify ();
464 delete img;
465 img = img2;
432 } 466 }
433 467
434 return img; 468 return img;
435} 469}
436 470
437rxvt_img * 471rxvt_img *
438rxvt_img::transform (int new_width, int new_height, double matrix[9]) 472rxvt_img::transform (int new_width, int new_height, double matrix[9])
439{ 473{
440 rxvt_img *img = new rxvt_img (s, format, 0, 0, new_width, new_height); 474 rxvt_img *img = new rxvt_img (s, format, 0, 0, new_width, new_height, repeat);
441 img->alloc (); 475 img->alloc ();
442 476
443 Display *dpy = s->display->dpy; 477 Display *dpy = s->display->dpy;
444 Picture src = src_picture (); 478 Picture src = src_picture ();
445 Picture dst = XRenderCreatePicture (dpy, img->pm, img->format, 0, 0); 479 Picture dst = XRenderCreatePicture (dpy, img->pm, img->format, 0, 0);
448 482
449 for (int i = 0; i < 3; ++i) 483 for (int i = 0; i < 3; ++i)
450 for (int j = 0; j < 3; ++j) 484 for (int j = 0; j < 3; ++j)
451 xfrm.matrix [i][j] = XDoubleToFixed (matrix [i * 3 + j]); 485 xfrm.matrix [i][j] = XDoubleToFixed (matrix [i * 3 + j]);
452 486
487#if 0
453 xfrm.matrix [0][2] += XDoubleToFixed (x);//TODO 488 xfrm.matrix [0][2] -= XDoubleToFixed (x);//TODO
454 xfrm.matrix [0][3] += XDoubleToFixed (y); 489 xfrm.matrix [1][2] -= XDoubleToFixed (y);
490#endif
455 491
456 XRenderSetPictureFilter (dpy, src, "good", 0, 0); 492 XRenderSetPictureFilter (dpy, src, "good", 0, 0);
457 XRenderSetPictureTransform (dpy, src, &xfrm); 493 XRenderSetPictureTransform (dpy, src, &xfrm);
458 XRenderComposite (dpy, PictOpSrc, src, None, dst, 0, 0, 0, 0, 0, 0, new_width, new_height); 494 XRenderComposite (dpy, PictOpSrc, src, None, dst, 0, 0, 0, 0, 0, 0, new_width, new_height);
459 495
464} 500}
465 501
466rxvt_img * 502rxvt_img *
467rxvt_img::scale (int new_width, int new_height) 503rxvt_img::scale (int new_width, int new_height)
468{ 504{
505 if (w == new_width && h == new_height)
506 return clone ();
507
469 double matrix[9] = { 508 double matrix[9] = {
470 w / (double)new_width, 0, 0, 509 w / (double)new_width, 0, 0,
471 0, h / (double)new_height, 0, 510 0, h / (double)new_height, 0,
472 0, 0, 1 511 0, 0, 1
473 }; 512 };
474 513
514 int old_repeat_mode = repeat;
515 repeat = RepeatPad; // not right, but xrender can't proeprly scale it seems
516
475 return transform (new_width, new_height, matrix); 517 rxvt_img *img = transform (new_width, new_height, matrix);
518
519 repeat = old_repeat_mode;
520 img->repeat = repeat;
521
522 return img;
476} 523}
477 524
478rxvt_img * 525rxvt_img *
479rxvt_img::rotate (int new_width, int new_height, int x, int y, double phi) 526rxvt_img::rotate (int new_width, int new_height, int x, int y, double phi)
480{ 527{
489 536
490 return transform (new_width, new_height, matrix); 537 return transform (new_width, new_height, matrix);
491} 538}
492 539
493rxvt_img * 540rxvt_img *
494rxvt_img::convert_to (XRenderPictFormat *new_format, const rxvt_color &bg) 541rxvt_img::convert_format (XRenderPictFormat *new_format, const rxvt_color &bg)
495{ 542{
496 if (new_format == format) 543 if (new_format == format)
497 return clone (); 544 return clone ();
498 545
499 rxvt_img *img = new rxvt_img (s, new_format, 0, 0, w, h); 546 rxvt_img *img = new rxvt_img (s, new_format, x, y, w, h, repeat);
500 img->alloc (); 547 img->alloc ();
501 548
502 Display *dpy = s->display->dpy; 549 Display *dpy = s->display->dpy;
503 Picture src = src_picture (); 550 Picture src = src_picture ();
504 Picture dst = XRenderCreatePicture (dpy, img->pm, new_format, 0, 0); 551 Picture dst = XRenderCreatePicture (dpy, img->pm, new_format, 0, 0);
527rxvt_img * 574rxvt_img *
528rxvt_img::blend (rxvt_img *img, double factor) 575rxvt_img::blend (rxvt_img *img, double factor)
529{ 576{
530 rxvt_img *img2 = clone (); 577 rxvt_img *img2 = clone ();
531 Display *dpy = s->display->dpy; 578 Display *dpy = s->display->dpy;
532 Picture src = src_picture (); 579 Picture src = img->src_picture ();
533 Picture dst = XRenderCreatePicture (dpy, img2->pm, img2->format, 0, 0); 580 Picture dst = XRenderCreatePicture (dpy, img2->pm, img2->format, 0, 0);
534 Picture mask = create_xrender_mask (dpy, img->pm, False); 581 Picture mask = create_xrender_mask (dpy, img->pm, False);
535 582
536 XRenderColor mask_c; 583 XRenderColor mask_c;
537 584

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines