--- rxvt-unicode/src/rxvtimg.C 2012/06/03 10:01:32 1.2 +++ rxvt-unicode/src/rxvtimg.C 2012/06/03 18:14:13 1.4 @@ -3,20 +3,44 @@ #if HAVE_IMG -rxvt_img::rxvt_img (rxvt_screen *screen, Pixmap *pm, XRenderPictFormat *format, int width, int height) -: s(screen), pm(pixmap) w(width), h(height), format(format) +rxvt_img::rxvt_img (rxvt_screen *screen, XRenderPictFormat *format, int width, int height) +: s(screen), w(width), h(height), format(format), shared(false) { + pm = XCreatePixmap (s->display->dpy, s->display->root, w, h, format->depth); } -rxvt_img::rxvt_img (rxvt_screen *screen, GdkPixbuf *pixbuf, - int x, int y, int width, int height) -: s(screen), w(width), h(height) +rxvt_img::rxvt_img (rxvt_screen *screen, XRenderPictFormat *format, int width, int height, Pixmap pixmap) +: s(screen), pm(pixmap), w(width), h(height), format(format), shared(false) { } +rxvt_img * +rxvt_img::new_from_file (rxvt_screen *s, const char *filename) +{ + GError *err; + GdkPixbuf *pb = gdk_pixbuf_new_from_file (filename, &err); + + if (!pb) + return 0; + + int w = gdk_pixbuf_get_width (pb); + int h = gdk_pixbuf_get_height (pb); + + rxvt_img *img = new rxvt_img ( + s, + XRenderFindStandardFormat (s->display->dpy, gdk_pixbuf_get_has_alpha (pb) ? PictStandardARGB32 : PictStandardRGB24), + gdk_pixbuf_get_width (pb), + gdk_pixbuf_get_height (pb) + ); + + img->render (pb, 0, 0, w, h, 0, 0); + + return img; +} + rxvt_img::~rxvt_img () { - if (pm) + if (!shared) XFreePixmap (s->display->dpy, pm); } @@ -27,14 +51,56 @@ gcv.foreground = c; GC gc = XCreateGC (s->display->dpy, pm, GCForeground, &gcv); XFillRectangle (s->display->dpy, pm, gc, 0, 0, w, h); + XFreeGC (s->display->dpy, gc); } -rxvt_img *copy () +void +rxvt_img::blur (int rh, int rv) +{ + //TODO +} + +void +rxvt_img::brightness (double r, double g, double b, double a) { - Pixmap pm2 = XCreatePixmap (s->display->dpy, pm, w, h, depth); - XCopyArea (s->display->dpy, pm, pm2, 0, 0, w, h, 0, 0); - return new rxvt_img (s, pm2, format, w, h); + //TODO } +void +rxvt_img::contrast (double r, double g, double b, double a) +{ + //TODO +} + +void +rxvt_img::render (GdkPixbuf *pixbuf, int src_x, int src_y, int width, int height, int dst_x, int dst_y) +{ + //TODO +} + +rxvt_img * +rxvt_img::copy () +{ + GC gc = XCreateGC (s->display->dpy, pm, 0, 0); + Pixmap pm2 = XCreatePixmap (s->display->dpy, pm, w, h, format->depth); + XCopyArea (s->display->dpy, pm, pm2, gc, 0, 0, w, h, 0, 0); + XFreeGC (s->display->dpy, gc); + return new rxvt_img (s, format, w, h, pm2); +} + +rxvt_img * +rxvt_img::transform (int new_width, int new_height, double matrix[16]) +{ + //TODO +} + +rxvt_img * +rxvt_img::scale (int new_width, int new_height) +{ + // use transform + //TODO +} + + #endif