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