… | |
… | |
18 | } |
18 | } |
19 | |
19 | |
20 | rxvt_img * |
20 | rxvt_img * |
21 | rxvt_img::new_from_file (rxvt_screen *s, const char *filename) |
21 | rxvt_img::new_from_file (rxvt_screen *s, const char *filename) |
22 | { |
22 | { |
23 | GError *err; |
23 | GError *err = 0; |
24 | GdkPixbuf *pb = gdk_pixbuf_new_from_file (filename, &err); |
24 | GdkPixbuf *pb = gdk_pixbuf_new_from_file (filename, &err); |
25 | |
25 | |
26 | if (!pb) |
26 | if (!pb) |
27 | return 0; |
27 | rxvt_fatal ("rxvt_img::new_from_file: %s\n", err->message); |
28 | |
28 | |
29 | rxvt_img *img = new rxvt_img ( |
29 | rxvt_img *img = new rxvt_img ( |
30 | s, |
30 | s, |
31 | XRenderFindStandardFormat (s->display->dpy, gdk_pixbuf_get_has_alpha (pb) ? PictStandardARGB32 : PictStandardRGB24), |
31 | XRenderFindStandardFormat (s->display->dpy, gdk_pixbuf_get_has_alpha (pb) ? PictStandardARGB32 : PictStandardRGB24), |
32 | gdk_pixbuf_get_width (pb), |
32 | gdk_pixbuf_get_width (pb), |
… | |
… | |
43 | if (!shared) |
43 | if (!shared) |
44 | XFreePixmap (s->display->dpy, pm); |
44 | XFreePixmap (s->display->dpy, pm); |
45 | } |
45 | } |
46 | |
46 | |
47 | void |
47 | void |
|
|
48 | rxvt_img::unshare () |
|
|
49 | { |
|
|
50 | if (!shared) |
|
|
51 | return; |
|
|
52 | |
|
|
53 | rxvt_img *img = clone (); |
|
|
54 | |
|
|
55 | ::swap (pm , img->pm); |
|
|
56 | ::swap (shared, img->shared); |
|
|
57 | |
|
|
58 | delete img; |
|
|
59 | } |
|
|
60 | |
|
|
61 | void |
48 | rxvt_img::fill (const rxvt_color &c) |
62 | rxvt_img::fill (const rxvt_color &c) |
49 | { |
63 | { |
50 | XGCValues gcv; |
64 | XGCValues gcv; |
51 | gcv.foreground = c; |
65 | gcv.foreground = c; |
52 | GC gc = XCreateGC (s->display->dpy, pm, GCForeground, &gcv); |
66 | GC gc = XCreateGC (s->display->dpy, pm, GCForeground, &gcv); |
… | |
… | |
191 | { |
205 | { |
192 | //TODO |
206 | //TODO |
193 | } |
207 | } |
194 | |
208 | |
195 | rxvt_img * |
209 | rxvt_img * |
196 | rxvt_img::copy () |
210 | rxvt_img::clone () |
197 | { |
211 | { |
198 | GC gc = XCreateGC (s->display->dpy, pm, 0, 0); |
212 | GC gc = XCreateGC (s->display->dpy, pm, 0, 0); |
199 | Pixmap pm2 = XCreatePixmap (s->display->dpy, pm, w, h, format->depth); |
213 | Pixmap pm2 = XCreatePixmap (s->display->dpy, pm, w, h, format->depth); |
200 | XCopyArea (s->display->dpy, pm, pm2, gc, 0, 0, w, h, 0, 0); |
214 | XCopyArea (s->display->dpy, pm, pm2, gc, 0, 0, w, h, 0, 0); |
201 | XFreeGC (s->display->dpy, gc); |
215 | XFreeGC (s->display->dpy, gc); |
202 | return new rxvt_img (s, format, w, h, pm2); |
216 | return new rxvt_img (s, format, w, h, pm2); |
203 | } |
217 | } |
204 | |
218 | |
205 | rxvt_img * |
219 | rxvt_img * |
206 | rxvt_img::transform (int new_width, int new_height, double matrix[16]) |
220 | rxvt_img::transform (int new_width, int new_height, int repeat, double matrix[9]) |
207 | { |
221 | { |
208 | //TODO |
|
|
209 | } |
|
|
210 | |
|
|
211 | rxvt_img * |
|
|
212 | rxvt_img::scale (int new_width, int new_height) |
|
|
213 | { |
|
|
214 | // use transform |
|
|
215 | //TODO |
|
|
216 | } |
|
|
217 | |
|
|
218 | rxvt_img * |
|
|
219 | rxvt_img::convert_to (XRenderPictFormat *new_format) |
|
|
220 | { |
|
|
221 | rxvt_img *img = new rxvt_img (s,new_format,w, h); |
222 | rxvt_img *img = new rxvt_img (s, format, new_width, new_height); |
222 | |
223 | |
223 | Display *dpy = s->display->dpy; |
224 | Display *dpy = s->display->dpy; |
|
|
225 | XRenderPictureAttributes pa; |
|
|
226 | pa.repeat = repeat; |
224 | Picture src = XRenderCreatePicture (dpy, pm, format, 0, 0); |
227 | Picture src = XRenderCreatePicture (dpy, pm, format, CPRepeat, &pa); |
225 | Picture dst = XRenderCreatePicture (dpy, img->pm, new_format, 0, 0); |
228 | Picture dst = XRenderCreatePicture (dpy, img->pm, img->format, 0, 0); |
226 | |
229 | |
|
|
230 | XTransform xfrm; |
|
|
231 | |
|
|
232 | for (int i = 0; i < 3; ++i) |
|
|
233 | for (int j = 0; j < 3; ++j) |
|
|
234 | xfrm.matrix [i][j] = XDoubleToFixed (matrix [i * 3 + j]); |
|
|
235 | |
|
|
236 | XRenderSetPictureTransform (dpy, src, &xfrm); |
227 | XRenderComposite (dpy, PictOpSrc, src, None, dst, 0, 0, 0, 0, 0, 0, w, h); |
237 | XRenderComposite (dpy, PictOpSrc, src, None, dst, 0, 0, 0, 0, 0, 0, new_width, new_height); |
228 | |
238 | |
229 | XRenderFreePicture (dpy, src); |
239 | XRenderFreePicture (dpy, src); |
230 | XRenderFreePicture (dpy, dst); |
240 | XRenderFreePicture (dpy, dst); |
231 | |
241 | |
232 | return img; |
242 | return img; |
233 | } |
243 | } |
234 | |
244 | |
|
|
245 | rxvt_img * |
|
|
246 | rxvt_img::scale (int new_width, int new_height) |
|
|
247 | { |
|
|
248 | double matrix[9] = { |
|
|
249 | new_width / (double)w, 0, 0, |
|
|
250 | 0, new_height / (double)h, 0, |
|
|
251 | 0, 0, 1 |
|
|
252 | }; |
|
|
253 | |
|
|
254 | return transform (new_width, new_height, RepeatNormal, matrix); |
|
|
255 | } |
|
|
256 | |
|
|
257 | rxvt_img * |
|
|
258 | rxvt_img::convert_to (XRenderPictFormat *new_format) |
|
|
259 | { |
|
|
260 | rxvt_img *img = new rxvt_img (s, new_format, w, h); |
|
|
261 | |
|
|
262 | Display *dpy = s->display->dpy; |
|
|
263 | Picture src = XRenderCreatePicture (dpy, pm, format, 0, 0); |
|
|
264 | Picture dst = XRenderCreatePicture (dpy, img->pm, new_format, 0, 0); |
|
|
265 | |
|
|
266 | XRenderComposite (dpy, PictOpSrc, src, None, dst, 0, 0, 0, 0, 0, 0, w, h); |
|
|
267 | |
|
|
268 | XRenderFreePicture (dpy, src); |
|
|
269 | XRenderFreePicture (dpy, dst); |
|
|
270 | |
|
|
271 | return img; |
|
|
272 | } |
|
|
273 | |
235 | #endif |
274 | #endif |
236 | |
275 | |