--- rxvt-unicode/src/rxvtimg.h 2012/06/07 07:53:12 1.17 +++ rxvt-unicode/src/rxvtimg.h 2012/06/17 17:06:47 1.42 @@ -1,43 +1,78 @@ +/*----------------------------------------------------------------------* + * File: rxvtimg.h + *----------------------------------------------------------------------* + * + * All portions of code are copyright by their respective author/s. + * Copyright (c) 2012 Marc Lehmann + * Copyright (c) 2012 Emanuele Giaquinta + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + *---------------------------------------------------------------------*/ + #ifndef IMG_H #define IMG_H -#if HAVE_BG_PIXMAP && BG_IMAGE_FROM_FILE && ENABLE_TRANSPARENCY && HAVE_PIXBUF +#if HAVE_BG_PIXMAP #define HAVE_IMG 1 #endif #if HAVE_IMG -#define float_to_component(d) ((d) * 65535.99) +#define float_to_component(d) (int32_t)((d) * 65535.99) #include -class rxvt_img +struct rxvt_img { - void alloc (); - void destroy (); + typedef double nv; + + // *could* also hold the Pixmap itself + struct pixref + { + int cnt; + int w, h; + bool ours; // false if we don't own the pixmap at all + + pixref (int w, int h) + : cnt(1), w(w), h(h), ours(true) + { + } + }; -public: rxvt_screen *s; Pixmap pm; - int *refcnt; // shared refcnt + pixref *ref; // shared refcnt int x, y, w, h, repeat; XRenderPictFormat *format; - rxvt_img (rxvt_screen *screen, XRenderPictFormat *format, int width, int height); + rxvt_img (rxvt_screen *screen, XRenderPictFormat *format, int x, int y, int width, int height, int repeat = RepeatNormal); rxvt_img (const rxvt_img &img); + void alloc (); - //rxvt_img (rxvt_screen *screen, XRenderPictFormat *format, int width, int height, Pixmap pixmap); +# if HAVE_PIXBUF + static rxvt_img *new_from_pixbuf (rxvt_screen *s, GdkPixbuf *pb); // from pixbuf + static rxvt_img *new_from_file (rxvt_screen *s, const char *filename); // via pixbuf +# endif static rxvt_img *new_from_root (rxvt_screen *s); // get root pixmap - static rxvt_img *new_from_file (rxvt_screen *s, const char *filename); // from pixbuf ~rxvt_img (); - // TODO: steal should not do what it does, and this todo should be more specific Pixmap steal () { - Pixmap retval = pm; - pm = None; - return retval; + ref->ours = false; + return pm; } // inplace @@ -53,11 +88,15 @@ } void unshare (); // prepare for write - void fill (const rxvt_color &c); - void brightness (unsigned short r, unsigned short g, unsigned short b, unsigned short a); - void contrast (unsigned short r, unsigned short g, unsigned short b, unsigned short a); + void fill (const rgba &c); + void add_alpha (); + //void linear_gradient (const XLinearGradient *gradient, const XFixed *stops, const XRenderColor *colors, int nstops); + //void radial_gradient (const XRadialGradient *gradient, const XFixed *stops, const XRenderColor *colors, int nstops); + //void conical_gradient (const XConicalGradient *gradient, const XFixed *stops, const XRenderColor *colors, int nstops); + void brightness (int32_t r, int32_t g, int32_t b, int32_t a); + void contrast (int32_t r, int32_t g, int32_t b, int32_t a); - void brightness (double r, double g, double b, double a = 1.) + void brightness (nv r, nv g, nv b, nv a = 1.) { brightness (float_to_component (r), float_to_component (g), @@ -65,7 +104,7 @@ float_to_component (a)); } - void contrast (double r, double g, double b, double a = 1.) + void contrast (nv r, nv g, nv b, nv a = 1.) { contrast (float_to_component (r), float_to_component (g), @@ -73,17 +112,36 @@ float_to_component (a)); } - bool render_pixbuf (GdkPixbuf *pixbuf, int src_x, int src_y, int width, int height, int dst_x, int dst_y); + void draw (rxvt_img *img, int op = PictOpOver, nv mask = 1.); +#if 0 + void draw (rxvt_img *img, int op = PictOpOver, nv mask = 1., + nv px, nv py, nv qx, nv qy, nv rx, nv ry, nv sx, nv sy); +#endif // copy + rxvt_img *reify (); // make x, y 0, make real width/height rxvt_img *blur (int rh, int rv); rxvt_img *clone (); rxvt_img *sub_rect (int x, int y, int width, int height); - rxvt_img *transform (int new_width, int new_height, double matrix[9]); + rxvt_img *transform (const nv matrix[3][3]); rxvt_img *scale (int new_width, int new_height); - rxvt_img *rotate (int new_width, int new_height, int x, int y, double phi); - rxvt_img *convert_to (XRenderPictFormat *format, const rxvt_color &bg); - rxvt_img *blend (rxvt_img *img, double factor); + rxvt_img *rotate (int cx, int cy, nv phi); + rxvt_img *convert_format (XRenderPictFormat *format, const rgba &bg); + rxvt_img *blend (rxvt_img *img, nv factor = 1.); + + // egregiuous helper category + rxvt_img *replace (rxvt_img *&p) + { + delete p; + p = this; + return this; + } + +private: + + void destroy (); + Picture picture (); + rxvt_img *transform (const nv *matrix); }; #endif