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.36 by root, Thu Jun 7 08:45:34 2012 UTC vs.
Revision 1.45 by root, Thu Jun 7 17:21:56 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;
397rxvt_img::reify () 397rxvt_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);//TODO: split into four fillrectangles
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}
417 428
418rxvt_img * 429rxvt_img *
419rxvt_img::sub_rect (int x, int y, int width, int height) 430rxvt_img::sub_rect (int x, int y, int width, int height)
420{ 431{
421 bool need_reify = w < width || h < height;
422
423 rxvt_img *img = clone (); 432 rxvt_img *img = clone ();
424 433
425 img->x += x; 434 img->x += x;
426 img->y += y; 435 img->y += y;
436
437 if (w != width || h != height)
438 {
427 img->w = width; 439 img->w = width;
428 img->h = height; 440 img->h = height;
429 441
430 if (need_reify) 442 rxvt_img *img2 = img->reify ();
431 img->reify (); 443 delete img;
444 img = img2;
445 }
432 446
433 return img; 447 return img;
434} 448}
435 449
436rxvt_img * 450rxvt_img *
437rxvt_img::transform (int new_width, int new_height, double matrix[9]) 451rxvt_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);
447 461
448 for (int i = 0; i < 3; ++i) 462 for (int i = 0; i < 3; ++i)
449 for (int j = 0; j < 3; ++j) 463 for (int j = 0; j < 3; ++j)
450 xfrm.matrix [i][j] = XDoubleToFixed (matrix [i * 3 + j]); 464 xfrm.matrix [i][j] = XDoubleToFixed (matrix [i * 3 + j]);
451 465
466#if 0
452 xfrm.matrix [0][2] += XDoubleToFixed (x);//TODO 467 xfrm.matrix [0][2] -= XDoubleToFixed (x);//TODO
453 xfrm.matrix [0][3] += XDoubleToFixed (y); 468 xfrm.matrix [1][2] -= XDoubleToFixed (y);
469#endif
454 470
455 XRenderSetPictureFilter (dpy, src, "good", 0, 0); 471 XRenderSetPictureFilter (dpy, src, "good", 0, 0);
456 XRenderSetPictureTransform (dpy, src, &xfrm); 472 XRenderSetPictureTransform (dpy, src, &xfrm);
457 XRenderComposite (dpy, PictOpSrc, src, None, dst, 0, 0, 0, 0, 0, 0, new_width, new_height); 473 XRenderComposite (dpy, PictOpSrc, src, None, dst, 0, 0, 0, 0, 0, 0, new_width, new_height);
458 474
463} 479}
464 480
465rxvt_img * 481rxvt_img *
466rxvt_img::scale (int new_width, int new_height) 482rxvt_img::scale (int new_width, int new_height)
467{ 483{
484 if (w == new_width && h == new_height)
485 return clone ();
486
468 double matrix[9] = { 487 double matrix[9] = {
469 w / (double)new_width, 0, 0, 488 w / (double)new_width, 0, 0,
470 0, h / (double)new_height, 0, 489 0, h / (double)new_height, 0,
471 0, 0, 1 490 0, 0, 1
472 }; 491 };
473 492
493 int old_repeat_mode = repeat;
494 repeat = RepeatPad; // not right, but xrender can't proeprly scale it seems
495
474 return transform (new_width, new_height, matrix); 496 rxvt_img *img = transform (new_width, new_height, matrix);
497
498 repeat = old_repeat_mode;
499 img->repeat = repeat;
500
501 return img;
475} 502}
476 503
477rxvt_img * 504rxvt_img *
478rxvt_img::rotate (int new_width, int new_height, int x, int y, double phi) 505rxvt_img::rotate (int new_width, int new_height, int x, int y, double phi)
479{ 506{
488 515
489 return transform (new_width, new_height, matrix); 516 return transform (new_width, new_height, matrix);
490} 517}
491 518
492rxvt_img * 519rxvt_img *
493rxvt_img::convert_to (XRenderPictFormat *new_format, const rxvt_color &bg) 520rxvt_img::convert_format (XRenderPictFormat *new_format, const rxvt_color &bg)
494{ 521{
495 if (new_format == format) 522 if (new_format == format)
496 return clone (); 523 return clone ();
497 524
498 rxvt_img *img = new rxvt_img (s, new_format, 0, 0, w, h); 525 rxvt_img *img = new rxvt_img (s, new_format, x, y, w, h, repeat);
499 img->alloc (); 526 img->alloc ();
500 527
501 Display *dpy = s->display->dpy; 528 Display *dpy = s->display->dpy;
502 Picture src = src_picture (); 529 Picture src = src_picture ();
503 Picture dst = XRenderCreatePicture (dpy, img->pm, new_format, 0, 0); 530 Picture dst = XRenderCreatePicture (dpy, img->pm, new_format, 0, 0);
526rxvt_img * 553rxvt_img *
527rxvt_img::blend (rxvt_img *img, double factor) 554rxvt_img::blend (rxvt_img *img, double factor)
528{ 555{
529 rxvt_img *img2 = clone (); 556 rxvt_img *img2 = clone ();
530 Display *dpy = s->display->dpy; 557 Display *dpy = s->display->dpy;
531 Picture src = src_picture (); 558 Picture src = img->src_picture ();
532 Picture dst = XRenderCreatePicture (dpy, img2->pm, img2->format, 0, 0); 559 Picture dst = XRenderCreatePicture (dpy, img2->pm, img2->format, 0, 0);
533 Picture mask = create_xrender_mask (dpy, img->pm, False); 560 Picture mask = create_xrender_mask (dpy, img->pm, False);
534 561
535 XRenderColor mask_c; 562 XRenderColor mask_c;
536 563

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines