… | |
… | |
13 | } |
13 | } |
14 | |
14 | |
15 | rxvt_img::rxvt_img (rxvt_screen *screen, XRenderPictFormat *format, int width, int height, Pixmap pixmap) |
15 | rxvt_img::rxvt_img (rxvt_screen *screen, XRenderPictFormat *format, int width, int height, Pixmap pixmap) |
16 | : s(screen), pm(pixmap), w(width), h(height), format(format), shared(false) |
16 | : s(screen), pm(pixmap), w(width), h(height), format(format), shared(false) |
17 | { |
17 | { |
|
|
18 | } |
|
|
19 | |
|
|
20 | rxvt_img * |
|
|
21 | rxvt_img::new_from_root (rxvt_screen *s) |
|
|
22 | { |
|
|
23 | Display *dpy = s->display->dpy; |
|
|
24 | unsigned int root_pm_w, root_pm_h; |
|
|
25 | Pixmap root_pixmap = s->display->get_pixmap_property (s->display->xa[XA_XROOTPMAP_ID]); |
|
|
26 | if (root_pixmap == None) |
|
|
27 | root_pixmap = s->display->get_pixmap_property (s->display->xa[XA_ESETROOT_PMAP_ID]); |
|
|
28 | |
|
|
29 | if (root_pixmap == None) |
|
|
30 | return 0; |
|
|
31 | |
|
|
32 | Window wdummy; |
|
|
33 | int idummy; |
|
|
34 | unsigned int udummy; |
|
|
35 | |
|
|
36 | if (!XGetGeometry (dpy, root_pixmap, &wdummy, &idummy, &idummy, &root_pm_w, &root_pm_h, &udummy, &udummy)) |
|
|
37 | return 0; |
|
|
38 | |
|
|
39 | rxvt_img *img = new rxvt_img ( |
|
|
40 | s, |
|
|
41 | XRenderFindVisualFormat (dpy, DefaultVisual (dpy, s->display->screen)), |
|
|
42 | root_pm_w, |
|
|
43 | root_pm_h, |
|
|
44 | root_pixmap |
|
|
45 | ); |
|
|
46 | |
|
|
47 | img->shared = true; |
|
|
48 | |
|
|
49 | return img; |
18 | } |
50 | } |
19 | |
51 | |
20 | rxvt_img * |
52 | rxvt_img * |
21 | rxvt_img::new_from_file (rxvt_screen *s, const char *filename) |
53 | rxvt_img::new_from_file (rxvt_screen *s, const char *filename) |
22 | { |
54 | { |
… | |
… | |
310 | } |
342 | } |
311 | |
343 | |
312 | rxvt_img * |
344 | rxvt_img * |
313 | rxvt_img::clone () |
345 | rxvt_img::clone () |
314 | { |
346 | { |
|
|
347 | rxvt_img *img = new rxvt_img (s, format, w, h); |
|
|
348 | |
315 | GC gc = XCreateGC (s->display->dpy, pm, 0, 0); |
349 | GC gc = XCreateGC (s->display->dpy, pm, 0, 0); |
316 | Pixmap pm2 = XCreatePixmap (s->display->dpy, pm, w, h, format->depth); |
|
|
317 | XCopyArea (s->display->dpy, pm, pm2, gc, 0, 0, w, h, 0, 0); |
350 | XCopyArea (s->display->dpy, pm, img->pm, gc, 0, 0, w, h, 0, 0); |
318 | XFreeGC (s->display->dpy, gc); |
351 | XFreeGC (s->display->dpy, gc); |
319 | return new rxvt_img (s, format, w, h, pm2); |
|
|
320 | } |
|
|
321 | |
352 | |
|
|
353 | return img; |
|
|
354 | } |
|
|
355 | |
322 | rxvt_img * |
356 | rxvt_img * |
|
|
357 | rxvt_img::sub_rect (int x, int y, int width, int height, int repeat) |
|
|
358 | { |
|
|
359 | rxvt_img *img = new rxvt_img (s, format, width, height); |
|
|
360 | |
|
|
361 | Display *dpy = s->display->dpy; |
|
|
362 | XRenderPictureAttributes pa; |
|
|
363 | pa.repeat = repeat; |
|
|
364 | Picture src = XRenderCreatePicture (dpy, pm, format, CPRepeat, &pa); |
|
|
365 | Picture dst = XRenderCreatePicture (dpy, img->pm, img->format, 0, 0); |
|
|
366 | |
|
|
367 | XRenderComposite (dpy, PictOpSrc, src, None, dst, x, y, 0, 0, 0, 0, width, height); |
|
|
368 | |
|
|
369 | XRenderFreePicture (dpy, src); |
|
|
370 | XRenderFreePicture (dpy, dst); |
|
|
371 | |
|
|
372 | return img; |
|
|
373 | } |
|
|
374 | |
|
|
375 | rxvt_img * |
323 | rxvt_img::transform (int new_width, int new_height, int repeat, double matrix[9]) |
376 | rxvt_img::transform (int new_width, int new_height, double matrix[9], int repeat) |
324 | { |
377 | { |
325 | rxvt_img *img = new rxvt_img (s, format, new_width, new_height); |
378 | rxvt_img *img = new rxvt_img (s, format, new_width, new_height); |
326 | |
379 | |
327 | Display *dpy = s->display->dpy; |
380 | Display *dpy = s->display->dpy; |
328 | XRenderPictureAttributes pa; |
381 | XRenderPictureAttributes pa; |
… | |
… | |
353 | w / (double)new_width, 0, 0, |
406 | w / (double)new_width, 0, 0, |
354 | 0, h / (double)new_height, 0, |
407 | 0, h / (double)new_height, 0, |
355 | 0, 0, 1 |
408 | 0, 0, 1 |
356 | }; |
409 | }; |
357 | |
410 | |
358 | return transform (new_width, new_height, RepeatNormal, matrix); |
411 | return transform (new_width, new_height, matrix); |
359 | } |
412 | } |
360 | |
413 | |
361 | rxvt_img * |
414 | rxvt_img * |
362 | rxvt_img::rotate (int new_width, int new_height, int repeat, int x, int y, double phi) |
415 | rxvt_img::rotate (int new_width, int new_height, int x, int y, double phi, int repeat) |
363 | { |
416 | { |
364 | double s = sin (phi); |
417 | double s = sin (phi); |
365 | double c = cos (phi); |
418 | double c = cos (phi); |
366 | |
419 | |
367 | double matrix[9] = { |
420 | double matrix[9] = { |
368 | c, -s, -c * x + s * y + x, |
421 | c, -s, -c * x + s * y + x, |
369 | s, c, -s * x - c * y + y, |
422 | s, c, -s * x - c * y + y, |
370 | 0, 0, 1 |
423 | 0, 0, 1 |
371 | }; |
424 | }; |
372 | |
425 | |
373 | return transform (new_width, new_height, repeat, matrix); |
426 | return transform (new_width, new_height, matrix, repeat); |
374 | } |
427 | } |
375 | |
428 | |
376 | rxvt_img * |
429 | rxvt_img * |
377 | rxvt_img::convert_to (XRenderPictFormat *new_format) |
430 | rxvt_img::convert_to (XRenderPictFormat *new_format) |
378 | { |
431 | { |