… | |
… | |
5 | #if HAVE_IMG |
5 | #if HAVE_IMG |
6 | |
6 | |
7 | #define float_to_component(d) ((d) * 65535.99) |
7 | #define float_to_component(d) ((d) * 65535.99) |
8 | |
8 | |
9 | rxvt_img::rxvt_img (rxvt_screen *screen, XRenderPictFormat *format, int width, int height) |
9 | rxvt_img::rxvt_img (rxvt_screen *screen, XRenderPictFormat *format, int width, int height) |
10 | : s(screen), w(width), h(height), format(format), shared(false) |
10 | : s(screen), x(0), y(0), w(width), h(height), format(format), repeat(RepeatNormal), shared(false) |
11 | { |
11 | { |
12 | pm = XCreatePixmap (s->display->dpy, s->display->root, w, h, format->depth); |
12 | pm = XCreatePixmap (s->display->dpy, s->display->root, w, h, format->depth); |
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), x(0), y(0), w(width), h(height), format(format), repeat(RepeatNormal), shared(false), pm(pixmap) |
17 | { |
17 | { |
18 | } |
18 | } |
19 | |
19 | |
20 | rxvt_img * |
20 | rxvt_img * |
21 | rxvt_img::new_from_root (rxvt_screen *s) |
21 | rxvt_img::new_from_root (rxvt_screen *s) |
… | |
… | |
64 | gdk_pixbuf_get_width (pb), |
64 | gdk_pixbuf_get_width (pb), |
65 | gdk_pixbuf_get_height (pb) |
65 | gdk_pixbuf_get_height (pb) |
66 | ); |
66 | ); |
67 | |
67 | |
68 | img->render_pixbuf (pb, 0, 0, img->w, img->h, 0, 0); |
68 | img->render_pixbuf (pb, 0, 0, img->w, img->h, 0, 0); |
|
|
69 | |
|
|
70 | g_object_unref (pb); |
69 | |
71 | |
70 | return img; |
72 | return img; |
71 | } |
73 | } |
72 | |
74 | |
73 | rxvt_img::~rxvt_img () |
75 | rxvt_img::~rxvt_img () |
… | |
… | |
350 | |
352 | |
351 | return img; |
353 | return img; |
352 | } |
354 | } |
353 | |
355 | |
354 | rxvt_img * |
356 | rxvt_img * |
355 | rxvt_img::sub_rect (int x, int y, int width, int height, int repeat) |
357 | rxvt_img::sub_rect (int x, int y, int width, int height) |
356 | { |
358 | { |
357 | rxvt_img *img = new rxvt_img (s, format, width, height); |
359 | rxvt_img *img = new rxvt_img (s, format, width, height); |
358 | |
360 | |
359 | Display *dpy = s->display->dpy; |
361 | Display *dpy = s->display->dpy; |
360 | XRenderPictureAttributes pa; |
362 | XRenderPictureAttributes pa; |
… | |
… | |
369 | |
371 | |
370 | return img; |
372 | return img; |
371 | } |
373 | } |
372 | |
374 | |
373 | rxvt_img * |
375 | rxvt_img * |
374 | rxvt_img::transform (int new_width, int new_height, double matrix[9], int repeat) |
376 | rxvt_img::transform (int new_width, int new_height, double matrix[9]) |
375 | { |
377 | { |
376 | 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); |
377 | |
379 | |
378 | Display *dpy = s->display->dpy; |
380 | Display *dpy = s->display->dpy; |
379 | XRenderPictureAttributes pa; |
381 | XRenderPictureAttributes pa; |
… | |
… | |
408 | |
410 | |
409 | return transform (new_width, new_height, matrix); |
411 | return transform (new_width, new_height, matrix); |
410 | } |
412 | } |
411 | |
413 | |
412 | rxvt_img * |
414 | rxvt_img * |
413 | rxvt_img::rotate (int new_width, int new_height, int x, int y, double phi, int repeat) |
415 | rxvt_img::rotate (int new_width, int new_height, int x, int y, double phi) |
414 | { |
416 | { |
415 | double s = sin (phi); |
417 | double s = sin (phi); |
416 | double c = cos (phi); |
418 | double c = cos (phi); |
417 | |
419 | |
418 | double matrix[9] = { |
420 | double matrix[9] = { |
419 | c, -s, -c * x + s * y + x, |
421 | c, -s, -c * x + s * y + x, |
420 | s, c, -s * x - c * y + y, |
422 | s, c, -s * x - c * y + y, |
421 | 0, 0, 1 |
423 | 0, 0, 1 |
422 | }; |
424 | }; |
423 | |
425 | |
424 | return transform (new_width, new_height, matrix, repeat); |
426 | return transform (new_width, new_height, matrix); |
425 | } |
427 | } |
426 | |
428 | |
427 | rxvt_img * |
429 | rxvt_img * |
428 | rxvt_img::convert_to (XRenderPictFormat *new_format) |
430 | rxvt_img::convert_to (XRenderPictFormat *new_format, const rxvt_color &bg) |
429 | { |
431 | { |
430 | rxvt_img *img = new rxvt_img (s, new_format, w, h); |
432 | rxvt_img *img = new rxvt_img (s, new_format, w, h); |
431 | |
433 | |
432 | Display *dpy = s->display->dpy; |
434 | Display *dpy = s->display->dpy; |
433 | Picture src = XRenderCreatePicture (dpy, pm, format, 0, 0); |
435 | Picture src = XRenderCreatePicture (dpy, pm, format, 0, 0); |
434 | Picture dst = XRenderCreatePicture (dpy, img->pm, new_format, 0, 0); |
436 | Picture dst = XRenderCreatePicture (dpy, img->pm, new_format, 0, 0); |
|
|
437 | int op = PictOpSrc; |
435 | |
438 | |
|
|
439 | if (format->direct.alphaMask && !new_format->direct.alphaMask) |
|
|
440 | { |
|
|
441 | // does it have to be that complicated |
|
|
442 | rgba c; |
|
|
443 | bg.get (c); |
|
|
444 | |
|
|
445 | XRenderColor rc = { c.r, c.g, c.b, 0xffff }; |
|
|
446 | XRenderFillRectangle (dpy, PictOpSrc, dst, &rc, 0, 0, w, h); |
|
|
447 | |
|
|
448 | op = PictOpOver; |
|
|
449 | } |
|
|
450 | |
436 | XRenderComposite (dpy, PictOpSrc, src, None, dst, 0, 0, 0, 0, 0, 0, w, h); |
451 | XRenderComposite (dpy, op, src, None, dst, 0, 0, 0, 0, 0, 0, w, h); |
437 | |
452 | |
438 | XRenderFreePicture (dpy, src); |
453 | XRenderFreePicture (dpy, src); |
439 | XRenderFreePicture (dpy, dst); |
454 | XRenderFreePicture (dpy, dst); |
440 | |
455 | |
441 | return img; |
456 | return img; |