--- rxvt-unicode/src/rxvtimg.C 2012/06/03 18:49:55 1.6 +++ rxvt-unicode/src/rxvtimg.C 2012/06/04 15:15:49 1.11 @@ -20,11 +20,11 @@ rxvt_img * rxvt_img::new_from_file (rxvt_screen *s, const char *filename) { - GError *err; + GError *err = 0; GdkPixbuf *pb = gdk_pixbuf_new_from_file (filename, &err); if (!pb) - return 0; + rxvt_fatal ("rxvt_img::new_from_file: %s\n", err->message); rxvt_img *img = new rxvt_img ( s, @@ -45,6 +45,20 @@ } void +rxvt_img::unshare () +{ + if (!shared) + return; + + rxvt_img *img = clone (); + + ::swap (pm , img->pm); + ::swap (shared, img->shared); + + delete img; +} + +void rxvt_img::fill (const rxvt_color &c) { XGCValues gcv; @@ -193,7 +207,7 @@ } rxvt_img * -rxvt_img::copy () +rxvt_img::clone () { GC gc = XCreateGC (s->display->dpy, pm, 0, 0); Pixmap pm2 = XCreatePixmap (s->display->dpy, pm, w, h, format->depth); @@ -203,7 +217,7 @@ } rxvt_img * -rxvt_img::transform (int new_width, int new_height, double matrix[16]) +rxvt_img::transform (int new_width, int new_height, int repeat, double matrix[9]) { //TODO } @@ -211,10 +225,31 @@ rxvt_img * rxvt_img::scale (int new_width, int new_height) { - // use transform - //TODO + double matrix[9] = { + new_width / (double)w, 0, 0, + 0, new_height / (double)h, 0, + 0, 0, 1 + }; + + return transform (new_width, new_height, RepeatNormal, matrix); } +rxvt_img * +rxvt_img::convert_to (XRenderPictFormat *new_format) +{ + rxvt_img *img = new rxvt_img (s, new_format, w, h); + + Display *dpy = s->display->dpy; + Picture src = XRenderCreatePicture (dpy, pm, format, 0, 0); + Picture dst = XRenderCreatePicture (dpy, img->pm, new_format, 0, 0); + + XRenderComposite (dpy, PictOpSrc, src, None, dst, 0, 0, 0, 0, 0, 0, w, h); + + XRenderFreePicture (dpy, src); + XRenderFreePicture (dpy, dst); + + return img; +} #endif