… | |
… | |
280 | |
280 | |
281 | delete img; |
281 | delete img; |
282 | } |
282 | } |
283 | |
283 | |
284 | static void |
284 | static void |
285 | get_gaussian_kernel (int radius, int width, double *kernel, XFixed *params) |
285 | get_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 | |
542 | static void |
542 | static void |
543 | mat_invert (double mat[3][3], double (&inv)[3][3]) |
543 | mat_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 | |
564 | static double |
564 | static rxvt_img::nv |
565 | mat_apply (double mat[3][3], int i, double x, double y) |
565 | mat_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 | |
573 | rxvt_img * |
573 | rxvt_img * |
574 | rxvt_img::transform (double matrix[3][3]) |
574 | rxvt_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 | |
… | |
… | |
625 | rxvt_img::scale (int new_width, int new_height) |
625 | rxvt_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 | |
647 | rxvt_img * |
647 | rxvt_img * |
648 | rxvt_img::rotate (int cx, int cy, double phi) |
648 | rxvt_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 | |
701 | rxvt_img * |
701 | rxvt_img * |
702 | rxvt_img::blend (rxvt_img *img, double factor) |
702 | rxvt_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); |