1 | #include "../config.h" |
1 | #include "../config.h" |
2 | #include "rxvt.h" |
2 | #include "rxvt.h" |
3 | |
3 | |
4 | #if HAVE_IMG |
4 | #if HAVE_IMG |
5 | |
5 | |
6 | rxvt_img::rxvt_img (rxvt_screen *screen, Pixmap *pm, XRenderPictFormat *format, int width, int height) |
6 | rxvt_img::rxvt_img (rxvt_screen *screen, XRenderPictFormat *format, int width, int height) |
|
|
7 | : s(screen), w(width), h(height), format(format), shared(false) |
|
|
8 | { |
|
|
9 | pm = XCreatePixmap (s->display->dpy, s->display->root, w, h, format->depth); |
|
|
10 | } |
|
|
11 | |
|
|
12 | rxvt_img::rxvt_img (rxvt_screen *screen, XRenderPictFormat *format, int width, int height, Pixmap pixmap) |
7 | : s(screen), pm(pixmap) w(width), h(height), format(format) |
13 | : s(screen), pm(pixmap), w(width), h(height), format(format), shared(false) |
8 | { |
14 | { |
9 | } |
15 | } |
10 | |
16 | |
11 | rxvt_img::rxvt_img (rxvt_screen *screen, GdkPixbuf *pixbuf, |
17 | rxvt_img * |
12 | int x, int y, int width, int height) |
18 | rxvt_img::new_from_file (rxvt_screen *s, const char *filename) |
13 | : s(screen), w(width), h(height) |
|
|
14 | { |
19 | { |
|
|
20 | GError *err; |
|
|
21 | GdkPixbuf *pb = gdk_pixbuf_new_from_file (filename, &err); |
|
|
22 | |
|
|
23 | if (!pb) |
|
|
24 | return 0; |
|
|
25 | |
|
|
26 | int w = gdk_pixbuf_get_width (pb); |
|
|
27 | int h = gdk_pixbuf_get_height (pb); |
|
|
28 | |
|
|
29 | rxvt_img *img = new rxvt_img ( |
|
|
30 | s, |
|
|
31 | XRenderFindStandardFormat (s->display->dpy, gdk_pixbuf_get_has_alpha (pb) ? PictStandardARGB32 : PictStandardRGB24), |
|
|
32 | gdk_pixbuf_get_width (pb), |
|
|
33 | gdk_pixbuf_get_height (pb) |
|
|
34 | ); |
|
|
35 | |
|
|
36 | img->render (pb, 0, 0, w, h, 0, 0); |
|
|
37 | |
|
|
38 | return img; |
15 | } |
39 | } |
16 | |
40 | |
17 | rxvt_img::~rxvt_img () |
41 | rxvt_img::~rxvt_img () |
18 | { |
42 | { |
19 | if (pm) |
43 | if (!shared) |
20 | XFreePixmap (s->display->dpy, pm); |
44 | XFreePixmap (s->display->dpy, pm); |
21 | } |
45 | } |
22 | |
46 | |
23 | void |
47 | void |
24 | rxvt_img::fill (const rxvt_color &c) |
48 | rxvt_img::fill (const rxvt_color &c) |
25 | { |
49 | { |
26 | XGCValues gcv; |
50 | XGCValues gcv; |
27 | gcv.foreground = c; |
51 | gcv.foreground = c; |
28 | GC gc = XCreateGC (s->display->dpy, pm, GCForeground, &gcv); |
52 | GC gc = XCreateGC (s->display->dpy, pm, GCForeground, &gcv); |
29 | XFillRectangle (s->display->dpy, pm, gc, 0, 0, w, h); |
53 | XFillRectangle (s->display->dpy, pm, gc, 0, 0, w, h); |
|
|
54 | XFreeGC (s->display->dpy, gc); |
30 | } |
55 | } |
31 | |
56 | |
32 | rxvt_img *copy () |
57 | void |
|
|
58 | rxvt_img::blur (int rh, int rv) |
33 | { |
59 | { |
34 | Pixmap pm2 = XCreatePixmap (s->display->dpy, pm, w, h, depth); |
60 | //TODO |
35 | XCopyArea (s->display->dpy, pm, pm2, 0, 0, w, h, 0, 0); |
|
|
36 | return new rxvt_img (s, pm2, format, w, h); |
|
|
37 | } |
61 | } |
|
|
62 | |
|
|
63 | void |
|
|
64 | rxvt_img::brightness (double r, double g, double b, double a) |
|
|
65 | { |
|
|
66 | //TODO |
|
|
67 | } |
|
|
68 | |
|
|
69 | void |
|
|
70 | rxvt_img::contrast (double r, double g, double b, double a) |
|
|
71 | { |
|
|
72 | //TODO |
|
|
73 | } |
|
|
74 | |
|
|
75 | void |
|
|
76 | rxvt_img::render (GdkPixbuf *pixbuf, int src_x, int src_y, int width, int height, int dst_x, int dst_y) |
|
|
77 | { |
|
|
78 | //TODO |
|
|
79 | } |
|
|
80 | |
|
|
81 | rxvt_img * |
|
|
82 | rxvt_img::copy () |
|
|
83 | { |
|
|
84 | GC gc = XCreateGC (s->display->dpy, pm, 0, 0); |
|
|
85 | Pixmap pm2 = XCreatePixmap (s->display->dpy, pm, w, h, format->depth); |
|
|
86 | XCopyArea (s->display->dpy, pm, pm2, gc, 0, 0, w, h, 0, 0); |
|
|
87 | XFreeGC (s->display->dpy, gc); |
|
|
88 | return new rxvt_img (s, format, w, h, pm2); |
|
|
89 | } |
|
|
90 | |
|
|
91 | rxvt_img * |
|
|
92 | rxvt_img::transform (int new_width, int new_height, double matrix[16]) |
|
|
93 | { |
|
|
94 | //TODO |
|
|
95 | } |
|
|
96 | |
|
|
97 | rxvt_img * |
|
|
98 | rxvt_img::scale (int new_width, int new_height) |
|
|
99 | { |
|
|
100 | // use transform |
|
|
101 | //TODO |
|
|
102 | } |
|
|
103 | |
38 | |
104 | |
39 | #endif |
105 | #endif |
40 | |
106 | |