1 |
#include "../config.h" |
2 |
#include "rxvt.h" |
3 |
|
4 |
#if HAVE_IMG |
5 |
|
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) |
13 |
: s(screen), pm(pixmap), w(width), h(height), format(format), shared(false) |
14 |
{ |
15 |
} |
16 |
|
17 |
rxvt_img * |
18 |
rxvt_img::new_from_file (rxvt_screen *s, const char *filename) |
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; |
39 |
} |
40 |
|
41 |
rxvt_img::~rxvt_img () |
42 |
{ |
43 |
if (!shared) |
44 |
XFreePixmap (s->display->dpy, pm); |
45 |
} |
46 |
|
47 |
void |
48 |
rxvt_img::fill (const rxvt_color &c) |
49 |
{ |
50 |
XGCValues gcv; |
51 |
gcv.foreground = c; |
52 |
GC gc = XCreateGC (s->display->dpy, pm, GCForeground, &gcv); |
53 |
XFillRectangle (s->display->dpy, pm, gc, 0, 0, w, h); |
54 |
XFreeGC (s->display->dpy, gc); |
55 |
} |
56 |
|
57 |
void |
58 |
rxvt_img::blur (int rh, int rv) |
59 |
{ |
60 |
//TODO |
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 |
|
104 |
|
105 |
#endif |
106 |
|