1 | #ifndef IMG_H |
1 | #ifndef IMG_H |
2 | #define IMG_H |
2 | #define IMG_H |
3 | |
3 | |
4 | #if HAVE_BG_PIXMAP && BG_IMAGE_FROM_FILE && ENABLE_TRANSPARENCY && HAVE_PIXBUF |
4 | #if HAVE_BG_PIXMAP |
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) |
10 | #define float_to_component(d) (int32_t)((d) * 65535.99) |
11 | |
11 | |
12 | #include <X11/extensions/Xrender.h> |
12 | #include <X11/extensions/Xrender.h> |
13 | |
13 | |
14 | class rxvt_img |
14 | class rxvt_img |
15 | { |
15 | { |
16 | void alloc (); |
|
|
17 | void destroy (); |
16 | void destroy (); |
|
|
17 | Picture src_picture (); |
18 | |
18 | |
19 | public: |
19 | public: |
|
|
20 | typedef double nv; |
|
|
21 | |
|
|
22 | // *could* also hold the Pixmap itself |
|
|
23 | struct pixref |
|
|
24 | { |
|
|
25 | int cnt; |
|
|
26 | int w, h; |
|
|
27 | bool ours; // false if we don't own the pixmap at all |
|
|
28 | |
|
|
29 | pixref (int w, int h) |
|
|
30 | : cnt(1), w(w), h(h), ours(true) |
|
|
31 | { |
|
|
32 | } |
|
|
33 | }; |
|
|
34 | |
20 | rxvt_screen *s; |
35 | rxvt_screen *s; |
21 | Pixmap pm; |
36 | Pixmap pm; |
22 | int *refcnt; // shared refcnt |
37 | pixref *ref; // shared refcnt |
23 | int x, y, w, h, repeat; |
38 | int x, y, w, h, repeat; |
24 | XRenderPictFormat *format; |
39 | XRenderPictFormat *format; |
25 | |
40 | |
26 | rxvt_img (rxvt_screen *screen, XRenderPictFormat *format, int width, int height); |
41 | rxvt_img (rxvt_screen *screen, XRenderPictFormat *format, int x, int y, int width, int height, int repeat = RepeatNormal); |
27 | rxvt_img (const rxvt_img &img); |
42 | rxvt_img (const rxvt_img &img); |
|
|
43 | void alloc (); |
28 | |
44 | |
29 | //rxvt_img (rxvt_screen *screen, XRenderPictFormat *format, int width, int height, Pixmap pixmap); |
45 | # if HAVE_PIXBUF |
|
|
46 | static rxvt_img *new_from_pixbuf (rxvt_screen *s, GdkPixbuf *pb); // from pixbuf |
|
|
47 | static rxvt_img *new_from_file (rxvt_screen *s, const char *filename); // via pixbuf |
|
|
48 | # endif |
30 | static rxvt_img *new_from_root (rxvt_screen *s); // get root pixmap |
49 | static rxvt_img *new_from_root (rxvt_screen *s); // get root pixmap |
31 | static rxvt_img *new_from_file (rxvt_screen *s, const char *filename); // from pixbuf |
|
|
32 | |
50 | |
33 | ~rxvt_img (); |
51 | ~rxvt_img (); |
34 | |
52 | |
35 | // TODO: steal should not do what it does, and this todo should be more specific |
|
|
36 | Pixmap steal () |
53 | Pixmap steal () |
37 | { |
54 | { |
38 | Pixmap retval = pm; |
55 | ref->ours = false; |
39 | pm = None; |
|
|
40 | return retval; |
56 | return pm; |
41 | } |
57 | } |
42 | |
58 | |
43 | // inplace |
59 | // inplace |
44 | void move (int dx, int dy) |
60 | void move (int dx, int dy) |
45 | { |
61 | { |
46 | x += dx; |
62 | x -= dx; |
47 | y += dy; |
63 | y -= dy; |
48 | } |
64 | } |
49 | |
65 | |
50 | void repeat_mode (int repeat) |
66 | void repeat_mode (int repeat) |
51 | { |
67 | { |
52 | this->repeat = repeat; |
68 | this->repeat = repeat; |
53 | } |
69 | } |
54 | |
70 | |
55 | void unshare (); // prepare for write |
71 | void unshare (); // prepare for write |
56 | void fill (const rxvt_color &c); |
72 | void fill (const rgba &c); |
57 | void brightness (unsigned short r, unsigned short g, unsigned short b, unsigned short a); |
73 | void add_alpha (); |
58 | void contrast (unsigned short r, unsigned short g, unsigned short b, unsigned short a); |
74 | //void linear_gradient (const XLinearGradient *gradient, const XFixed *stops, const XRenderColor *colors, int nstops); |
|
|
75 | //void radial_gradient (const XRadialGradient *gradient, const XFixed *stops, const XRenderColor *colors, int nstops); |
|
|
76 | //void conical_gradient (const XConicalGradient *gradient, const XFixed *stops, const XRenderColor *colors, int nstops); |
|
|
77 | void brightness (int32_t r, int32_t g, int32_t b, int32_t a); |
|
|
78 | void contrast (int32_t r, int32_t g, int32_t b, int32_t a); |
59 | |
79 | |
60 | void brightness (double r, double g, double b, double a = 1.) |
80 | void brightness (nv r, nv g, nv b, nv a = 1.) |
61 | { |
81 | { |
62 | brightness (float_to_component (r), |
82 | brightness (float_to_component (r), |
63 | float_to_component (g), |
83 | float_to_component (g), |
64 | float_to_component (b), |
84 | float_to_component (b), |
65 | float_to_component (a)); |
85 | float_to_component (a)); |
66 | } |
86 | } |
67 | |
87 | |
68 | void contrast (double r, double g, double b, double a = 1.) |
88 | void contrast (nv r, nv g, nv b, nv a = 1.) |
69 | { |
89 | { |
70 | contrast (float_to_component (r), |
90 | contrast (float_to_component (r), |
71 | float_to_component (g), |
91 | float_to_component (g), |
72 | float_to_component (b), |
92 | float_to_component (b), |
73 | float_to_component (a)); |
93 | float_to_component (a)); |
74 | } |
94 | } |
75 | |
95 | |
76 | bool render_pixbuf (GdkPixbuf *pixbuf, int src_x, int src_y, int width, int height, int dst_x, int dst_y); |
|
|
77 | |
|
|
78 | // copy |
96 | // copy |
|
|
97 | rxvt_img *reify (); // make x, y 0, make real width/height |
79 | rxvt_img *blur (int rh, int rv); |
98 | rxvt_img *blur (int rh, int rv); |
80 | rxvt_img *clone (); |
99 | rxvt_img *clone (); |
81 | rxvt_img *sub_rect (int x, int y, int width, int height); |
100 | 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]); |
101 | rxvt_img *transform (nv matrix[3][3]); |
83 | rxvt_img *scale (int new_width, int new_height); |
102 | rxvt_img *scale (int new_width, int new_height); |
84 | rxvt_img *rotate (int new_width, int new_height, int x, int y, double phi); |
103 | rxvt_img *rotate (int cx, int cy, nv phi); |
85 | rxvt_img *convert_to (XRenderPictFormat *format, const rxvt_color &bg); |
104 | rxvt_img *convert_format (XRenderPictFormat *format, const rgba &bg); |
86 | rxvt_img *blend (rxvt_img *img, double factor); |
105 | rxvt_img *blend (rxvt_img *img, nv factor = 1.); |
|
|
106 | |
|
|
107 | // egregiuous helper category |
|
|
108 | rxvt_img *replace (rxvt_img *&p) |
|
|
109 | { |
|
|
110 | delete p; |
|
|
111 | p = this; |
|
|
112 | return this; |
|
|
113 | } |
87 | }; |
114 | }; |
88 | |
115 | |
89 | #endif |
116 | #endif |
90 | |
117 | |
91 | #endif |
118 | #endif |