… | |
… | |
5 | #define HAVE_IMG 1 |
5 | #define HAVE_IMG 1 |
6 | #endif |
6 | #endif |
7 | |
7 | |
8 | #if HAVE_IMG |
8 | #if HAVE_IMG |
9 | |
9 | |
|
|
10 | #define float_to_component(d) ((d) * 65535.99) |
|
|
11 | |
10 | #include <X11/extensions/Xrender.h> |
12 | #include <X11/extensions/Xrender.h> |
11 | |
13 | |
12 | struct rxvt_img |
14 | class rxvt_img |
13 | { |
15 | { |
|
|
16 | void alloc (); |
|
|
17 | void destroy (); |
|
|
18 | |
|
|
19 | public: |
14 | rxvt_screen *s; |
20 | rxvt_screen *s; |
15 | Pixmap pm; |
21 | Pixmap pm; |
16 | int w, h; |
22 | int *refcnt; // shared refcnt |
|
|
23 | int x, y, w, h, repeat; |
17 | XRenderPictFormat *format; |
24 | XRenderPictFormat *format; |
18 | bool shared; // true if we don't own it |
|
|
19 | |
25 | |
20 | rxvt_img (rxvt_screen *screen, XRenderPictFormat *format, int width, int height); |
26 | rxvt_img (rxvt_screen *screen, XRenderPictFormat *format, int width, int height); |
|
|
27 | rxvt_img (const rxvt_img &img); |
|
|
28 | |
21 | rxvt_img (rxvt_screen *screen, XRenderPictFormat *format, int width, int height, Pixmap pixmap); |
29 | //rxvt_img (rxvt_screen *screen, XRenderPictFormat *format, int width, int height, Pixmap pixmap); |
22 | static rxvt_img *new_from_root (rxvt_screen *s); // get root pixmap |
30 | static rxvt_img *new_from_root (rxvt_screen *s); // get root pixmap |
23 | static rxvt_img *new_from_file (rxvt_screen *s, const char *filename); // from pixbuf |
31 | static rxvt_img *new_from_file (rxvt_screen *s, const char *filename); // from pixbuf |
24 | |
32 | |
25 | ~rxvt_img (); |
33 | ~rxvt_img (); |
26 | |
34 | |
|
|
35 | // TODO: steal should not do what it does, and this todo should be more specific |
27 | Pixmap steal () |
36 | Pixmap steal () |
28 | { |
37 | { |
29 | shared = true; |
38 | Pixmap retval = pm; |
|
|
39 | pm = None; |
30 | return pm; |
40 | return retval; |
31 | } |
41 | } |
32 | |
42 | |
33 | // inplace |
43 | // inplace |
34 | void unshare (); // create a copy of the pixmap if !shared |
44 | void move (int dx, int dy) |
|
|
45 | { |
|
|
46 | x += dx; |
|
|
47 | y += dy; |
|
|
48 | } |
|
|
49 | |
|
|
50 | void repeat_mode (int repeat) |
|
|
51 | { |
|
|
52 | this->repeat = repeat; |
|
|
53 | } |
|
|
54 | |
|
|
55 | void unshare (); // prepare for write |
35 | void fill (const rxvt_color &c); |
56 | void fill (const rxvt_color &c); |
36 | void blur (int rh, int rv); |
57 | void brightness (unsigned short r, unsigned short g, unsigned short b, unsigned short a); |
|
|
58 | void contrast (unsigned short r, unsigned short g, unsigned short b, unsigned short a); |
|
|
59 | |
37 | void brightness (double r, double g, double b, double a = 1.); |
60 | void brightness (double r, double g, double b, double a = 1.) |
|
|
61 | { |
|
|
62 | brightness (float_to_component (r), |
|
|
63 | float_to_component (g), |
|
|
64 | float_to_component (b), |
|
|
65 | float_to_component (a)); |
|
|
66 | } |
|
|
67 | |
38 | void contrast (double r, double g, double b, double a = 1.); |
68 | void contrast (double r, double g, double b, double a = 1.) |
|
|
69 | { |
|
|
70 | contrast (float_to_component (r), |
|
|
71 | float_to_component (g), |
|
|
72 | float_to_component (b), |
|
|
73 | float_to_component (a)); |
|
|
74 | } |
|
|
75 | |
39 | bool render_pixbuf (GdkPixbuf *pixbuf, int src_x, int src_y, int width, int height, int dst_x, int dst_y); |
76 | bool render_pixbuf (GdkPixbuf *pixbuf, int src_x, int src_y, int width, int height, int dst_x, int dst_y); |
40 | |
77 | |
41 | // copy |
78 | // copy |
|
|
79 | rxvt_img *blur (int rh, int rv); |
42 | rxvt_img *clone (); |
80 | rxvt_img *clone (); |
|
|
81 | rxvt_img *sub_rect (int x, int y, int width, int height); |
|
|
82 | rxvt_img *transform (int new_width, int new_height, double matrix[9]); |
43 | rxvt_img *scale (int new_width, int new_height); |
83 | rxvt_img *scale (int new_width, int new_height); |
44 | rxvt_img *transform (int new_width, int new_height, int repeat, double matrix[9]); |
84 | rxvt_img *rotate (int new_width, int new_height, int x, int y, double phi); |
45 | rxvt_img *convert_to (XRenderPictFormat *format); |
85 | rxvt_img *convert_to (XRenderPictFormat *format, const rxvt_color &bg); |
|
|
86 | rxvt_img *blend (rxvt_img *img, double factor); |
46 | }; |
87 | }; |
47 | |
88 | |
48 | #endif |
89 | #endif |
49 | |
90 | |
50 | #endif |
91 | #endif |