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.83 by root, Thu Jun 14 18:06:15 2012 UTC vs.
Revision 1.84 by root, Thu Jun 14 18:19:11 2012 UTC

280 280
281 delete img; 281 delete img;
282} 282}
283 283
284static void 284static void
285get_gaussian_kernel (int radius, int width, double *kernel, XFixed *params) 285get_gaussian_kernel (int radius, int width, rxvt_img::nv *kernel, XFixed *params)
286{ 286{
287 double sigma = radius / 2.0; 287 rxvt_img::nv sigma = radius / 2.0;
288 double scale = sqrt (2.0 * M_PI) * sigma; 288 rxvt_img::nv scale = sqrt (2.0 * M_PI) * sigma;
289 double sum = 0.0; 289 rxvt_img::nv sum = 0.0;
290 290
291 for (int i = 0; i < width; i++) 291 for (int i = 0; i < width; i++)
292 { 292 {
293 double x = i - width / 2; 293 rxvt_img::nv x = i - width / 2;
294 kernel[i] = exp (-(x * x) / (2.0 * sigma * sigma)) / scale; 294 kernel[i] = exp (-(x * x) / (2.0 * sigma * sigma)) / scale;
295 sum += kernel[i]; 295 sum += kernel[i];
296 } 296 }
297 297
298 params[0] = XDoubleToFixed (width); 298 params[0] = XDoubleToFixed (width);
308 if (!(s->display->flags & DISPLAY_HAS_RENDER_CONV)) 308 if (!(s->display->flags & DISPLAY_HAS_RENDER_CONV))
309 return clone (); 309 return clone ();
310 310
311 Display *dpy = s->display->dpy; 311 Display *dpy = s->display->dpy;
312 int size = max (rh, rv) * 2 + 1; 312 int size = max (rh, rv) * 2 + 1;
313 double *kernel = (double *)malloc (size * sizeof (double)); 313 nv *kernel = (nv *)malloc (size * sizeof (nv));
314 XFixed *params = (XFixed *)malloc ((size + 2) * sizeof (XFixed)); 314 XFixed *params = (XFixed *)malloc ((size + 2) * sizeof (XFixed));
315 rxvt_img *img = new rxvt_img (s, format, x, y, w, h, repeat); 315 rxvt_img *img = new rxvt_img (s, format, x, y, w, h, repeat);
316 img->alloc (); 316 img->alloc ();
317 317
318 XRenderPictureAttributes pa; 318 XRenderPictureAttributes pa;
538 538
539 return img; 539 return img;
540} 540}
541 541
542static void 542static void
543mat_invert (double mat[3][3], double (&inv)[3][3]) 543mat_invert (rxvt_img::nv mat[3][3], rxvt_img::nv (&inv)[3][3])
544{ 544{
545 double s0 = mat [2][2] * mat [1][1] - mat [2][1] * mat [1][2]; 545 rxvt_img::nv s0 = mat [2][2] * mat [1][1] - mat [2][1] * mat [1][2];
546 double s1 = mat [2][1] * mat [0][2] - mat [2][2] * mat [0][1]; 546 rxvt_img::nv s1 = mat [2][1] * mat [0][2] - mat [2][2] * mat [0][1];
547 double s2 = mat [1][2] * mat [0][1] - mat [1][1] * mat [0][2]; 547 rxvt_img::nv s2 = mat [1][2] * mat [0][1] - mat [1][1] * mat [0][2];
548 548
549 double invdet = 1. / (mat [0][0] * s0 + mat [1][0] * s1 + mat [2][0] * s2); 549 rxvt_img::nv invdet = 1. / (mat [0][0] * s0 + mat [1][0] * s1 + mat [2][0] * s2);
550 550
551 inv [0][0] = invdet * s0; 551 inv [0][0] = invdet * s0;
552 inv [0][1] = invdet * s1; 552 inv [0][1] = invdet * s1;
553 inv [0][2] = invdet * s2; 553 inv [0][2] = invdet * s2;
554 554
559 inv [2][0] = invdet * (mat [2][1] * mat [1][0] - mat [2][0] * mat [1][1]); 559 inv [2][0] = invdet * (mat [2][1] * mat [1][0] - mat [2][0] * mat [1][1]);
560 inv [2][1] = invdet * (mat [2][0] * mat [0][1] - mat [2][1] * mat [0][0]); 560 inv [2][1] = invdet * (mat [2][0] * mat [0][1] - mat [2][1] * mat [0][0]);
561 inv [2][2] = invdet * (mat [1][1] * mat [0][0] - mat [1][0] * mat [0][1]); 561 inv [2][2] = invdet * (mat [1][1] * mat [0][0] - mat [1][0] * mat [0][1]);
562} 562}
563 563
564static double 564static rxvt_img::nv
565mat_apply (double mat[3][3], int i, double x, double y) 565mat_apply (rxvt_img::nv mat[3][3], int i, rxvt_img::nv x, rxvt_img::nv y)
566{ 566{
567 double v = mat [i][0] * x + mat [i][1] * y + mat [i][2]; 567 rxvt_img::nv v = mat [i][0] * x + mat [i][1] * y + mat [i][2];
568 double w = mat [2][0] * x + mat [2][1] * y + mat [2][2]; 568 rxvt_img::nv w = mat [2][0] * x + mat [2][1] * y + mat [2][2];
569 569
570 return v * (1. / w); 570 return v * (1. / w);
571} 571}
572 572
573rxvt_img * 573rxvt_img *
574rxvt_img::transform (double matrix[3][3]) 574rxvt_img::transform (nv matrix[3][3])
575{ 575{
576 // find new offset 576 // find new offset
577 int ox = mat_apply (matrix, 0, x, y); 577 int ox = mat_apply (matrix, 0, x, y);
578 int oy = mat_apply (matrix, 1, x, y); 578 int oy = mat_apply (matrix, 1, x, y);
579 579
580 // calculate new pixel bounding box coordinates 580 // calculate new pixel bounding box coordinates
581 double d [2], rmin[2], rmax[2]; 581 nv d [2], rmin[2], rmax[2];
582 582
583 for (int i = 0; i < 2; ++i) 583 for (int i = 0; i < 2; ++i)
584 { 584 {
585 double v; 585 nv v;
586 v = mat_apply (matrix, i, 0, 0); rmin [i] = rmax [i] = v; d [i] = v; 586 v = mat_apply (matrix, i, 0, 0); rmin [i] = rmax [i] = v; d [i] = v;
587 v = mat_apply (matrix, i, w, 0); min_it (rmin [i], v); max_it (rmax [i], v); 587 v = mat_apply (matrix, i, w, 0); min_it (rmin [i], v); max_it (rmax [i], v);
588 v = mat_apply (matrix, i, 0, h); min_it (rmin [i], v); max_it (rmax [i], v); 588 v = mat_apply (matrix, i, 0, h); min_it (rmin [i], v); max_it (rmax [i], v);
589 v = mat_apply (matrix, i, w, h); min_it (rmin [i], v); max_it (rmax [i], v); 589 v = mat_apply (matrix, i, w, h); min_it (rmin [i], v); max_it (rmax [i], v);
590 } 590 }
593 int dy = floor (rmin [1]); 593 int dy = floor (rmin [1]);
594 594
595 int new_width = ceil (rmax [0] - dx); 595 int new_width = ceil (rmax [0] - dx);
596 int new_height = ceil (rmax [1] - dy); 596 int new_height = ceil (rmax [1] - dy);
597 597
598 double inv[3][3]; 598 nv inv[3][3];
599 mat_invert (matrix, inv); 599 mat_invert (matrix, inv);
600 600
601 rxvt_img *img = new rxvt_img (s, format, ox - dx - d [0], oy - dy - d [1], new_width, new_height, repeat); 601 rxvt_img *img = new rxvt_img (s, format, ox - dx - d [0], oy - dy - d [1], new_width, new_height, repeat);
602 img->alloc (); 602 img->alloc ();
603 603
625rxvt_img::scale (int new_width, int new_height) 625rxvt_img::scale (int new_width, int new_height)
626{ 626{
627 if (w == new_width && h == new_height) 627 if (w == new_width && h == new_height)
628 return clone (); 628 return clone ();
629 629
630 double matrix[3][3] = { 630 nv matrix[3][3] = {
631 { new_width / (double)w, 0, 0 }, 631 { new_width / (nv)w, 0, 0 },
632 { 0, new_height / (double)h, 0 }, 632 { 0, new_height / (nv)h, 0 },
633 { 0, 0, 1 } 633 { 0, 0, 1 }
634 }; 634 };
635 635
636 int old_repeat_mode = repeat; 636 int old_repeat_mode = repeat;
637 repeat = RepeatPad; // not right, but xrender can't properly scale it seems 637 repeat = RepeatPad; // not right, but xrender can't properly scale it seems
638 638
643 643
644 return img; 644 return img;
645} 645}
646 646
647rxvt_img * 647rxvt_img *
648rxvt_img::rotate (int cx, int cy, double phi) 648rxvt_img::rotate (int cx, int cy, nv phi)
649{ 649{
650 double s = sin (phi); 650 nv s = sin (phi);
651 double c = cos (phi); 651 nv c = cos (phi);
652 652
653 double matrix[3][3] = { 653 nv matrix[3][3] = {
654 { c, -s, cx - c * cx + s * cy }, 654 { c, -s, cx - c * cx + s * cy },
655 { s, c, cy - s * cx - c * cy }, 655 { s, c, cy - s * cx - c * cy },
656 { 0, 0, 1 } 656 { 0, 0, 1 }
657 //{ c, -s, 0 }, 657 //{ c, -s, 0 },
658 //{ s, c, 0 }, 658 //{ s, c, 0 },
697 697
698 return img; 698 return img;
699} 699}
700 700
701rxvt_img * 701rxvt_img *
702rxvt_img::blend (rxvt_img *img, double factor) 702rxvt_img::blend (rxvt_img *img, nv factor)
703{ 703{
704 rxvt_img *img2 = clone (); 704 rxvt_img *img2 = clone ();
705 Display *dpy = s->display->dpy; 705 Display *dpy = s->display->dpy;
706 Picture src = img->src_picture (); 706 Picture src = img->src_picture ();
707 Picture dst = XRenderCreatePicture (dpy, img2->pm, img2->format, 0, 0); 707 Picture dst = XRenderCreatePicture (dpy, img2->pm, img2->format, 0, 0);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines