--- rxvt-unicode/src/rxvtimg.C 2012/07/14 08:27:55 1.104 +++ rxvt-unicode/src/rxvtimg.C 2019/09/17 18:31:32 1.112 @@ -8,7 +8,7 @@ * * 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 + * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, @@ -166,7 +166,7 @@ else if (!this->dstimg->pm) // somewhat unsatisfying this->dstimg->alloc (); - dpy = srcimg->s->dpy; + dpy = srcimg->d->dpy; src = srcimg->picture (); dst = this->dstimg->picture (); } @@ -190,11 +190,12 @@ // CreateSolidFill creates a very very very weird picture void mask (const rgba &c) { + // the casts are needed in C++11 (see 8.5.1) XRenderColor rc = { - c.r * c.a / 65535, - c.g * c.a / 65535, - c.b * c.a / 65535, - c.a + (unsigned short)(c.r * c.a / 65535), + (unsigned short)(c.g * c.a / 65535), + (unsigned short)(c.b * c.a / 65535), + c.a }; msk = XRenderCreateSolidFill (dpy, &rc); ecb_assume (msk); @@ -203,10 +204,10 @@ void fill (const rgba &c) { XRenderColor rc = { - c.r * c.a / 65535, - c.g * c.a / 65535, - c.b * c.a / 65535, - c.a + (unsigned short)(c.r * c.a / 65535), + (unsigned short)(c.g * c.a / 65535), + (unsigned short)(c.b * c.a / 65535), + c.a }; XRenderFillRectangle (dpy, PictOpSrc, msk, &rc, 0, 0, 1, 1); @@ -248,13 +249,19 @@ } rxvt_img::rxvt_img (rxvt_screen *screen, XRenderPictFormat *format, int x, int y, int width, int height, int repeat) -: s(screen), x(x), y(y), w(width), h(height), format(format), repeat(repeat), +: d(screen->display), x(x), y(y), w(width), h(height), format(format), repeat(repeat), + pm(0), ref(0) +{ +} + +rxvt_img::rxvt_img (rxvt_display *display, XRenderPictFormat *format, int x, int y, int width, int height, int repeat) +: d(display), x(x), y(y), w(width), h(height), format(format), repeat(repeat), pm(0), ref(0) { } rxvt_img::rxvt_img (const rxvt_img &img) -: s(img.s), x(img.x), y(img.y), w(img.w), h(img.h), format(img.format), repeat(img.repeat), pm(img.pm), ref(img.ref) +: d(img.d), x(img.x), y(img.y), w(img.w), h(img.h), format(img.format), repeat(img.repeat), pm(img.pm), ref(img.ref) { ++ref->cnt; } @@ -397,7 +404,15 @@ GdkPixbuf *pb = gdk_pixbuf_new_from_file (filename, &err); if (!pb) - rxvt_fatal ("rxvt_img::new_from_file: %s\n", err->message); + try + { + rxvt_fatal ("rxvt_img::new_from_file: %s\n", err->message); + } + catch (...) + { + g_error_free (err); + throw; + } rxvt_img *img = new_from_pixbuf (s, pb); @@ -415,7 +430,7 @@ return; if (pm && ref->ours) - XFreePixmap (s->dpy, pm); + XFreePixmap (d->dpy, pm); delete ref; } @@ -428,14 +443,14 @@ void rxvt_img::alloc () { - pm = XCreatePixmap (s->dpy, s->display->root, w, h, format->depth); + pm = XCreatePixmap (d->dpy, d->root, w, h, format->depth); ref = new pixref (w, h); } rxvt_img * rxvt_img::new_empty () { - rxvt_img *img = new rxvt_img (s, format, x, y, w, h, repeat); + rxvt_img *img = new rxvt_img (d, format, x, y, w, h, repeat); img->alloc (); return img; @@ -444,7 +459,7 @@ Picture rxvt_img::picture () { - Display *dpy = s->dpy; + Display *dpy = d->dpy; XRenderPictureAttributes pa; pa.repeat = repeat; @@ -459,10 +474,10 @@ if (ref->cnt == 1 && ref->ours) return; - Pixmap pm2 = XCreatePixmap (s->dpy, s->display->root, ref->w, ref->h, format->depth); - GC gc = XCreateGC (s->dpy, pm, 0, 0); - XCopyArea (s->dpy, pm, pm2, gc, 0, 0, ref->w, ref->h, 0, 0); - XFreeGC (s->dpy, gc); + Pixmap pm2 = XCreatePixmap (d->dpy, d->root, ref->w, ref->h, format->depth); + GC gc = XCreateGC (d->dpy, pm, 0, 0); + XCopyArea (d->dpy, pm, pm2, gc, 0, 0, ref->w, ref->h, 0, 0); + XFreeGC (d->dpy, gc); destroy (); @@ -475,7 +490,7 @@ { XRenderColor rc = { c.r, c.g, c.b, c.a }; - Display *dpy = s->dpy; + Display *dpy = d->dpy; Picture src = picture (); XRenderFillRectangle (dpy, PictOpSrc, src, &rc, x, y, w, h); XRenderFreePicture (dpy, src); @@ -493,7 +508,7 @@ if (format->direct.alphaMask) return; - composer cc (this, new rxvt_img (s, find_alpha_format_for (s->dpy, format), x, y, w, h, repeat)); + composer cc (this, new rxvt_img (d, find_alpha_format_for (d->dpy, format), x, y, w, h, repeat)); XRenderComposite (cc.dpy, PictOpSrc, cc.src, None, cc.dst, 0, 0, 0, 0, 0, 0, w, h); @@ -529,13 +544,13 @@ rxvt_img * rxvt_img::blur (int rh, int rv) { - if (!(s->display->flags & DISPLAY_HAS_RENDER_CONV)) + if (!(d->flags & DISPLAY_HAS_RENDER_CONV)) return clone (); - Display *dpy = s->dpy; + Display *dpy = d->dpy; int size = max (rh, rv) * 2 + 1; nv *kernel = (nv *)malloc (size * sizeof (nv)); - XFixed *params = (XFixed *)malloc ((size + 2) * sizeof (XFixed)); + XFixed *params = rxvt_temp_buf (size + 2); rxvt_img *img = new_empty (); XRenderPictureAttributes pa; @@ -580,7 +595,6 @@ } free (kernel); - free (params); XRenderFreePicture (dpy, src); XRenderFreePicture (dpy, dst); @@ -594,7 +608,7 @@ { // STEP 1: double the image width, fill all odd columns with white (==1) - composer cc (this, new rxvt_img (s, format, 0, 0, w * 2, h, repeat)); + composer cc (this, new rxvt_img (d, format, 0, 0, w * 2, h, repeat)); // why the hell does XRenderSetPictureTransform want a writable matrix :( // that keeps us from just static const'ing this matrix. @@ -671,7 +685,7 @@ { unshare (); - Display *dpy = s->dpy; + Display *dpy = d->dpy; Picture dst = XRenderCreatePicture (dpy, pm, format, 0, 0); // loop should not be needed for brightness, as only -1..1 makes sense @@ -765,7 +779,7 @@ && (x || y) // we need one because of non-zero offset && repeat == RepeatNone; // and we have no good pixels to fill with - composer cc (this, new rxvt_img (s, alpha ? find_alpha_format_for (s->dpy, format) : format, + composer cc (this, new rxvt_img (d, alpha ? find_alpha_format_for (d->dpy, format) : format, 0, 0, w, h, repeat)); if (repeat == RepeatNone) @@ -837,7 +851,7 @@ mat3x3 inv = (mat3x3::translate (-x, -y) * m * mat3x3::translate (x, y)).inverse (); - composer cc (this, new rxvt_img (s, format, nx, ny, new_width, new_height, repeat)); + composer cc (this, new rxvt_img (d, format, nx, ny, new_width, new_height, repeat)); XTransform xfrm; @@ -886,7 +900,7 @@ if (new_format == format) return clone (); - composer cc (this, new rxvt_img (s, new_format, x, y, w, h, repeat)); + composer cc (this, new rxvt_img (d, new_format, x, y, w, h, repeat)); int op = PictOpSrc; @@ -917,6 +931,40 @@ } rxvt_img * +rxvt_img::shade (nv factor, rgba c) +{ + clamp_it (factor, -1., 1.); + factor++; + + if (factor > 1) + { + c.r = c.r * (2 - factor); + c.g = c.g * (2 - factor); + c.b = c.b * (2 - factor); + } + else + { + c.r = c.r * factor; + c.g = c.g * factor; + c.b = c.b * factor; + } + + rxvt_img *img = this->tint (c); + + if (factor > 1) + { + c.a = 0xffff; + c.r = + c.g = + c.b = 0xffff * (factor - 1); + + img->brightness (c.r, c.g, c.b, c.a); + } + + return img; +} + +rxvt_img * rxvt_img::filter (const char *name, int nparams, nv *params) { composer cc (this);