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.42 by root, Thu Jun 7 11:52:26 2012 UTC vs.
Revision 1.46 by root, Thu Jun 7 18:07:42 2012 UTC

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 ();
403 424
404 bool alpha = !format->direct.alphaMask 425 bool alpha = !format->direct.alphaMask
405 && (x || y) 426 && (x || y)
406 && repeat == RepeatNone; 427 && repeat == RepeatNone;
407 428
408 rxvt_img *img = new rxvt_img (s, alpha ? XRenderFindStandardFormat (dpy, PictStandardARGB32) : format, 0, 0, w, h, repeat); 429 rxvt_img *img = new rxvt_img (s, alpha ? find_alpha_format_for (dpy, format) : format, 0, 0, w, h, repeat);
409 img->alloc (); 430 img->alloc ();
410 431
411 Picture src = src_picture (); 432 Picture src = src_picture ();
412 Picture dst = XRenderCreatePicture (dpy, img->pm, img->format, 0, 0); 433 Picture dst = XRenderCreatePicture (dpy, img->pm, img->format, 0, 0);
413 434
414 if (alpha) 435 if (alpha)
415 { 436 {
416 XRenderColor rc = { 0, 0, 0, 0 }; 437 XRenderColor rc = { 0, 0, 0, 0 };
417 XRenderFillRectangle (dpy, PictOpSrc, dst, &rc, 0, 0, w, h); 438 XRenderFillRectangle (dpy, PictOpSrc, dst, &rc, 0, 0, w, h);//TODO: split into four fillrectangles
418 XRenderComposite (dpy, PictOpSrc, src, None, dst, 0, 0, 0, 0, -x, -y, ref->w, ref->h); 439 XRenderComposite (dpy, PictOpSrc, src, None, dst, 0, 0, 0, 0, -x, -y, ref->w, ref->h);
419 } 440 }
420 else 441 else
421 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);
422 443
461 482
462 for (int i = 0; i < 3; ++i) 483 for (int i = 0; i < 3; ++i)
463 for (int j = 0; j < 3; ++j) 484 for (int j = 0; j < 3; ++j)
464 xfrm.matrix [i][j] = XDoubleToFixed (matrix [i * 3 + j]); 485 xfrm.matrix [i][j] = XDoubleToFixed (matrix [i * 3 + j]);
465 486
487#if 0
466 xfrm.matrix [0][2] += XDoubleToFixed (x);//TODO 488 xfrm.matrix [0][2] -= XDoubleToFixed (x);//TODO
467 xfrm.matrix [0][3] += XDoubleToFixed (y); 489 xfrm.matrix [1][2] -= XDoubleToFixed (y);
490#endif
468 491
469 XRenderSetPictureFilter (dpy, src, "good", 0, 0); 492 XRenderSetPictureFilter (dpy, src, "good", 0, 0);
470 XRenderSetPictureTransform (dpy, src, &xfrm); 493 XRenderSetPictureTransform (dpy, src, &xfrm);
471 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);
472 495
477} 500}
478 501
479rxvt_img * 502rxvt_img *
480rxvt_img::scale (int new_width, int new_height) 503rxvt_img::scale (int new_width, int new_height)
481{ 504{
505 if (w == new_width && h == new_height)
506 return clone ();
507
482 double matrix[9] = { 508 double matrix[9] = {
483 w / (double)new_width, 0, 0, 509 w / (double)new_width, 0, 0,
484 0, h / (double)new_height, 0, 510 0, h / (double)new_height, 0,
485 0, 0, 1 511 0, 0, 1
486 }; 512 };
510 536
511 return transform (new_width, new_height, matrix); 537 return transform (new_width, new_height, matrix);
512} 538}
513 539
514rxvt_img * 540rxvt_img *
515rxvt_img::convert_to (XRenderPictFormat *new_format, const rxvt_color &bg) 541rxvt_img::convert_format (XRenderPictFormat *new_format, const rxvt_color &bg)
516{ 542{
517 if (new_format == format) 543 if (new_format == format)
518 return clone (); 544 return clone ();
519 545
520 rxvt_img *img = new rxvt_img (s, new_format, 0, 0, w, h, repeat); 546 rxvt_img *img = new rxvt_img (s, new_format, x, y, w, h, repeat);
521 img->alloc (); 547 img->alloc ();
522
523 printf ("convert %d to %d\n", format->direct.alphaMask, new_format->direct.alphaMask);//D
524 548
525 Display *dpy = s->display->dpy; 549 Display *dpy = s->display->dpy;
526 Picture src = src_picture (); 550 Picture src = src_picture ();
527 Picture dst = XRenderCreatePicture (dpy, img->pm, new_format, 0, 0); 551 Picture dst = XRenderCreatePicture (dpy, img->pm, new_format, 0, 0);
528 int op = PictOpSrc; 552 int op = PictOpSrc;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines