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.94 by root, Fri Jun 15 18:10:40 2012 UTC vs.
Revision 1.97 by sf-exg, Sun Jun 17 17:06:47 2012 UTC

1/*----------------------------------------------------------------------*
2 * File: rxvtimg.C
3 *----------------------------------------------------------------------*
4 *
5 * All portions of code are copyright by their respective author/s.
6 * Copyright (c) 2012 Marc Lehmann <schmorp@schmorp.de>
7 * Copyright (c) 2012 Emanuele Giaquinta <e.giaquinta@glauco.it>
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22 *---------------------------------------------------------------------*/
23
1#include <string.h> 24#include <string.h>
2#include <math.h> 25#include <math.h>
3#include "../config.h" 26#include "../config.h"
4#include "rxvt.h" 27#include "rxvt.h"
5 28
16 39
17 mat3x3 () 40 mat3x3 ()
18 { 41 {
19 } 42 }
20 43
21 mat3x3 (nv matrix[3][3]) 44 mat3x3 (const nv *matrix)
22 { 45 {
23 memcpy (v, matrix, sizeof (v)); 46 memcpy (v, matrix, sizeof (v));
24 } 47 }
25 48
26 mat3x3 (nv v11, nv v12, nv v13, nv v21, nv v22, nv v23, nv v31, nv v32, nv v33) 49 mat3x3 (nv v11, nv v12, nv v13, nv v21, nv v22, nv v23, nv v31, nv v32, nv v33)
33 mat3x3 invert (); 56 mat3x3 invert ();
34 57
35 nv *operator [](int i) { return &v[i][0]; } 58 nv *operator [](int i) { return &v[i][0]; }
36 const nv *operator [](int i) const { return &v[i][0]; } 59 const nv *operator [](int i) const { return &v[i][0]; }
37 60
61 operator const nv * () const { return &v[0][0]; }
62 operator nv * () { return &v[0][0]; }
63
38 // quite inefficient, hopefully gcc pulls the w calc out of any loops 64 // quite inefficient, hopefully gcc pulls the w calc out of any loops
39 nv apply1 (int i, nv x, nv y) 65 nv apply1 (int i, nv x, nv y)
40 { 66 {
41 mat3x3 &m = *this; 67 mat3x3 &m = *this;
42 68
45 71
46 return v * (1. / w); 72 return v * (1. / w);
47 } 73 }
48 74
49 static mat3x3 translate (nv x, nv y); 75 static mat3x3 translate (nv x, nv y);
76 static mat3x3 scale (nv s, nv t);
77 static mat3x3 rotate (nv phi);
50 }; 78 };
51 79
52 mat3x3 80 mat3x3
53 mat3x3::invert () 81 mat3x3::invert ()
54 { 82 {
95 { 123 {
96 return mat3x3 ( 124 return mat3x3 (
97 1, 0, x, 125 1, 0, x,
98 0, 1, y, 126 0, 1, y,
99 0, 0, 1 127 0, 0, 1
128 );
129 }
130
131 mat3x3
132 mat3x3::scale (nv s, nv t)
133 {
134 return mat3x3 (
135 s, 0, 0,
136 0, t, 0,
137 0, 0, 1
138 );
139 }
140
141 // clockwise
142 mat3x3
143 mat3x3::rotate (nv phi)
144 {
145 nv s = sin (phi);
146 nv c = cos (phi);
147
148 return mat3x3 (
149 c, -s, 0,
150 s, c, 0,
151 0, 0, 1
100 ); 152 );
101 } 153 }
102 154
103} 155}
104 156
264 uint8_t r = *src++; 316 uint8_t r = *src++;
265 uint8_t g = *src++; 317 uint8_t g = *src++;
266 uint8_t b = *src++; 318 uint8_t b = *src++;
267 319
268 uint32_t v = (255 << 24) | (r << 16) | (g << 8) | b; 320 uint32_t v = (255 << 24) | (r << 16) | (g << 8) | b;
269 321
270 if (ecb_big_endian () ? !byte_order_mismatch : byte_order_mismatch) 322 if (ecb_big_endian () ? !byte_order_mismatch : byte_order_mismatch)
271 v = ecb_bswap32 (v); 323 v = ecb_bswap32 (v);
272 324
273 *dst++ = v; 325 *dst++ = v;
274 } 326 }
397 rxvt_img *img = new rxvt_img (s, find_alpha_format_for (dpy, format), x, y, w, h, repeat); 449 rxvt_img *img = new rxvt_img (s, find_alpha_format_for (dpy, format), x, y, w, h, repeat);
398 img->alloc (); 450 img->alloc ();
399 451
400 Picture src = picture (); 452 Picture src = picture ();
401 Picture dst = XRenderCreatePicture (dpy, img->pm, img->format, 0, 0); 453 Picture dst = XRenderCreatePicture (dpy, img->pm, img->format, 0, 0);
402 454
403 XRenderComposite (dpy, PictOpSrc, src, None, dst, 0, 0, 0, 0, 0, 0, w, h); 455 XRenderComposite (dpy, PictOpSrc, src, None, dst, 0, 0, 0, 0, 0, 0, w, h);
404 456
405 XRenderFreePicture (dpy, src); 457 XRenderFreePicture (dpy, src);
406 XRenderFreePicture (dpy, dst); 458 XRenderFreePicture (dpy, dst);
407 459
615 667
616 Display *dpy = s->display->dpy; 668 Display *dpy = s->display->dpy;
617 Picture src = img->picture (); 669 Picture src = img->picture ();
618 Picture dst = picture (); 670 Picture dst = picture ();
619 Picture mask_p = 0; 671 Picture mask_p = 0;
620 672
621 if (mask != 1.) 673 if (mask != 1.)
622 { 674 {
623 mask_p = create_xrender_mask (dpy, img->pm, False, False); 675 mask_p = create_xrender_mask (dpy, img->pm, False, False);
624 XRenderColor mask_c = { 0, 0, 0, float_to_component (mask) }; 676 XRenderColor mask_c = { 0, 0, 0, float_to_component (mask) };
625 XRenderFillRectangle (dpy, PictOpSrc, mask, &mask_c, 0, 0, 1, 1); 677 XRenderFillRectangle (dpy, PictOpSrc, mask, &mask_c, 0, 0, 1, 1);
656 rxvt_img *img = new rxvt_img (s, alpha ? find_alpha_format_for (dpy, format) : format, 0, 0, w, h, repeat); 708 rxvt_img *img = new rxvt_img (s, alpha ? find_alpha_format_for (dpy, format) : format, 0, 0, w, h, repeat);
657 img->alloc (); 709 img->alloc ();
658 710
659 Picture src = picture (); 711 Picture src = picture ();
660 Picture dst = XRenderCreatePicture (dpy, img->pm, img->format, 0, 0); 712 Picture dst = XRenderCreatePicture (dpy, img->pm, img->format, 0, 0);
661 713
662 if (alpha) 714 if (alpha)
663 { 715 {
664 XRenderColor rc = { 0, 0, 0, 0 }; 716 XRenderColor rc = { 0, 0, 0, 0 };
665 XRenderFillRectangle (dpy, PictOpSrc, dst, &rc, 0, 0, w, h);//TODO: split into four fillrectangles 717 XRenderFillRectangle (dpy, PictOpSrc, dst, &rc, 0, 0, w, h);//TODO: split into four fillrectangles
666 XRenderComposite (dpy, PictOpSrc, src, None, dst, 0, 0, 0, 0, x, y, ref->w, ref->h); 718 XRenderComposite (dpy, PictOpSrc, src, None, dst, 0, 0, 0, 0, x, y, ref->w, ref->h);
694 746
695 return img; 747 return img;
696} 748}
697 749
698rxvt_img * 750rxvt_img *
699rxvt_img::transform (nv matrix[3][3]) 751rxvt_img::transform (const nv matrix[3][3])
700{ 752{
753 return transform (mat3x3 (&matrix[0][0]));
754}
755
756rxvt_img *
757rxvt_img::transform (const nv *matrix)
758{
759 mat3x3 m (matrix);
760
701 // calculate new pixel bounding box coordinates 761 // calculate new pixel bounding box coordinates
702 nv r[2], rmin[2], rmax[2]; 762 nv r[2], rmin[2], rmax[2];
703
704 mat3x3 m (matrix);
705 763
706 for (int i = 0; i < 2; ++i) 764 for (int i = 0; i < 2; ++i)
707 { 765 {
708 nv v; 766 nv v;
709 767
754rxvt_img::scale (int new_width, int new_height) 812rxvt_img::scale (int new_width, int new_height)
755{ 813{
756 if (w == new_width && h == new_height) 814 if (w == new_width && h == new_height)
757 return clone (); 815 return clone ();
758 816
759 nv matrix[3][3] = {
760 { new_width / (nv)w, 0, 0 },
761 { 0, new_height / (nv)h, 0 },
762 { 0, 0, 1 }
763 };
764
765 int old_repeat_mode = repeat; 817 int old_repeat_mode = repeat;
766 repeat = RepeatPad; // not right, but xrender can't properly scale it seems 818 repeat = RepeatPad; // not right, but xrender can't properly scale it seems
767 819
768 rxvt_img *img = transform (matrix); 820 rxvt_img *img = transform (mat3x3::scale (new_width / (nv)w, new_height / (nv)h));
769 821
770 repeat = old_repeat_mode; 822 repeat = old_repeat_mode;
771 img->repeat = repeat; 823 img->repeat = repeat;
772 824
773 return img; 825 return img;
774} 826}
775 827
776rxvt_img * 828rxvt_img *
777rxvt_img::rotate (int cx, int cy, nv phi) 829rxvt_img::rotate (int cx, int cy, nv phi)
778{ 830{
779 nv s = sin (phi);
780 nv c = cos (phi);
781
782 nv matrix[3][3] = {
783#if 0 831#if 0
784 { c, -s, cx - c * cx + s * cy }, 832 { c, -s, cx - c * cx + s * cy },
785 { s, c, cy - s * cx - c * cy }, 833 { s, c, cy - s * cx - c * cy },
786 { 0, 0, 1 } 834 { 0, 0, 1 }
787#else
788 { c, -s, 0 },
789 { s, c, 0 },
790 { 0, 0, 1 }
791#endif 835#endif
792 };
793 836
794 move (-cx, -cy); 837 move (-cx, -cy);
795 rxvt_img *img = transform (matrix); 838 rxvt_img *img = transform (mat3x3::rotate (phi));
796 move ( cx, cy); 839 move ( cx, cy);
797 img->move (cx, cy); 840 img->move (cx, cy);
798 841
799 return img; 842 return img;
800} 843}

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines