… | |
… | |
2 | #include "../config.h" |
2 | #include "../config.h" |
3 | #include "rxvt.h" |
3 | #include "rxvt.h" |
4 | |
4 | |
5 | #if HAVE_IMG |
5 | #if HAVE_IMG |
6 | |
6 | |
|
|
7 | #if 0 |
|
|
8 | struct pict |
|
|
9 | { |
|
|
10 | Display *dpy; |
|
|
11 | Picture pic; |
|
|
12 | |
|
|
13 | operator Picture () const |
|
|
14 | { |
|
|
15 | return pic; |
|
|
16 | } |
|
|
17 | |
|
|
18 | pict () |
|
|
19 | : pic (0) |
|
|
20 | { |
|
|
21 | } |
|
|
22 | |
|
|
23 | pict (rxvt_img *img, XRenderPictFormat *format = 0) |
|
|
24 | : dpy (img->s->display->dpy) |
|
|
25 | { |
|
|
26 | XRenderPictureAttributes pa; |
|
|
27 | pa.repeat = img->repeat; |
|
|
28 | pic = XRenderCreatePicture (dpy, img->pm, format ? format : img->format, CPRepeat, &pa); |
|
|
29 | } |
|
|
30 | |
|
|
31 | ~pict () |
|
|
32 | { |
|
|
33 | if (pic) |
|
|
34 | XRenderFreePicture (dpy, pic); |
|
|
35 | } |
|
|
36 | }; |
|
|
37 | #endif |
|
|
38 | |
|
|
39 | static XRenderPictFormat * |
|
|
40 | find_alpha_format_for (Display *dpy, XRenderPictFormat *format) |
|
|
41 | { |
|
|
42 | if (format->direct.alphaMask) |
|
|
43 | return format; // already has alpha |
|
|
44 | |
|
|
45 | // try to find a suitable alpha format, one bit alpha is enough for our purposes |
|
|
46 | if (format->type == PictTypeDirect) |
|
|
47 | for (int n = 0; XRenderPictFormat *f = XRenderFindFormat (dpy, 0, 0, n); ++n) |
|
|
48 | if (f->direct.alphaMask |
|
|
49 | && f->type == PictTypeDirect |
|
|
50 | && ecb_popcount32 (f->direct.redMask ) >= ecb_popcount32 (format->direct.redMask ) |
|
|
51 | && ecb_popcount32 (f->direct.greenMask) >= ecb_popcount32 (format->direct.greenMask) |
|
|
52 | && ecb_popcount32 (f->direct.blueMask ) >= ecb_popcount32 (format->direct.blueMask )) |
|
|
53 | return f; |
|
|
54 | |
|
|
55 | // should be a very good fallback |
|
|
56 | return XRenderFindStandardFormat (dpy, PictStandardARGB32); |
|
|
57 | } |
|
|
58 | |
7 | rxvt_img::rxvt_img (rxvt_screen *screen, XRenderPictFormat *format, int x, int y, int width, int height, int repeat) |
59 | rxvt_img::rxvt_img (rxvt_screen *screen, XRenderPictFormat *format, int x, int y, int width, int height, int repeat) |
8 | : s(screen), x(x), y(y), w(width), h(height), format(format), repeat(repeat), |
60 | : s(screen), x(x), y(y), w(width), h(height), format(format), repeat(repeat), |
9 | pm(0), ref(0) |
61 | pm(0), ref(0) |
10 | { |
62 | { |
11 | } |
63 | } |
… | |
… | |
13 | rxvt_img::rxvt_img (const rxvt_img &img) |
65 | rxvt_img::rxvt_img (const rxvt_img &img) |
14 | : 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) |
66 | : 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) |
15 | { |
67 | { |
16 | ++ref->cnt; |
68 | ++ref->cnt; |
17 | } |
69 | } |
18 | |
|
|
19 | #if 0 |
|
|
20 | rxvt_img::rxvt_img (rxvt_screen *screen, XRenderPictFormat *format, int width, int height, Pixmap pixmap) |
|
|
21 | : s(screen), x(0), y(0), w(width), h(height), format(format), repeat(RepeatNormal), shared(false), pm(pixmap) |
|
|
22 | { |
|
|
23 | } |
|
|
24 | #endif |
|
|
25 | |
70 | |
26 | rxvt_img * |
71 | rxvt_img * |
27 | rxvt_img::new_from_root (rxvt_screen *s) |
72 | rxvt_img::new_from_root (rxvt_screen *s) |
28 | { |
73 | { |
29 | Display *dpy = s->display->dpy; |
74 | Display *dpy = s->display->dpy; |
… | |
… | |
56 | img->ref->ours = false; |
101 | img->ref->ours = false; |
57 | |
102 | |
58 | return img; |
103 | return img; |
59 | } |
104 | } |
60 | |
105 | |
|
|
106 | # if HAVE_PIXBUF |
|
|
107 | |
61 | rxvt_img * |
108 | rxvt_img * |
62 | rxvt_img::new_from_pixbuf (rxvt_screen *s, GdkPixbuf *pb) |
109 | rxvt_img::new_from_pixbuf (rxvt_screen *s, GdkPixbuf *pb) |
63 | { |
110 | { |
64 | Display *dpy = s->display->dpy; |
111 | Display *dpy = s->display->dpy; |
65 | |
112 | |
… | |
… | |
69 | if (width > 32767 || height > 32767) // well, we *could* upload in chunks |
116 | if (width > 32767 || height > 32767) // well, we *could* upload in chunks |
70 | rxvt_fatal ("rxvt_img::new_from_pixbuf: image too big (maximum size 32768x32768).\n"); |
117 | rxvt_fatal ("rxvt_img::new_from_pixbuf: image too big (maximum size 32768x32768).\n"); |
71 | |
118 | |
72 | // since we require rgb24/argb32 formats from xrender we assume |
119 | // since we require rgb24/argb32 formats from xrender we assume |
73 | // that both 24 and 32 bpp MUST be supported by any screen that supports xrender |
120 | // that both 24 and 32 bpp MUST be supported by any screen that supports xrender |
74 | int depth = gdk_pixbuf_get_has_alpha (pb) ? 32 : 24; |
121 | |
|
|
122 | int byte_order = ecb_big_endian () ? MSBFirst : LSBFirst; |
75 | |
123 | |
76 | XImage xi; |
124 | XImage xi; |
77 | |
125 | |
78 | xi.width = width; |
126 | xi.width = width; |
79 | xi.height = height; |
127 | xi.height = height; |
80 | xi.xoffset = 0; |
128 | xi.xoffset = 0; |
81 | xi.format = ZPixmap; |
129 | xi.format = ZPixmap; |
82 | xi.byte_order = LSBFirst; // maybe go for host byte order, because servers are usually local? |
130 | xi.byte_order = ImageByteOrder (dpy); |
83 | xi.bitmap_unit = 32; //XY only, unused |
131 | xi.bitmap_unit = 0; //XY only, unused |
84 | xi.bitmap_bit_order = LSBFirst; //XY only, unused |
132 | xi.bitmap_bit_order = 0; //XY only, unused |
85 | xi.bitmap_pad = BitmapPad (dpy); |
133 | xi.bitmap_pad = BitmapPad (dpy); |
86 | xi.depth = depth; |
134 | xi.depth = 32; |
87 | xi.bytes_per_line = 0; |
135 | xi.bytes_per_line = 0; |
88 | xi.bits_per_pixel = 32; //Z only |
136 | xi.bits_per_pixel = 32; //Z only |
89 | xi.red_mask = 0x000000ff; //Z only |
137 | xi.red_mask = 0x00000000; //Z only, unused |
90 | xi.green_mask = 0x0000ff00; //Z only |
138 | xi.green_mask = 0x00000000; //Z only, unused |
91 | xi.blue_mask = 0x00ff0000; //Z only |
139 | xi.blue_mask = 0x00000000; //Z only, unused |
92 | xi.obdata = 0; // probbaly unused |
140 | xi.obdata = 0; // probably unused |
|
|
141 | |
|
|
142 | bool byte_order_mismatch = byte_order != xi.byte_order; |
93 | |
143 | |
94 | if (!XInitImage (&xi)) |
144 | if (!XInitImage (&xi)) |
95 | rxvt_fatal ("unable to initialise ximage, please report.\n"); |
145 | rxvt_fatal ("unable to initialise ximage, please report.\n"); |
96 | |
146 | |
97 | if (height > INT_MAX / xi.bytes_per_line) |
147 | if (height > INT_MAX / xi.bytes_per_line) |
98 | rxvt_fatal ("rxvt_img::new_from_pixbuf: image too big for Xlib.\n"); |
148 | rxvt_fatal ("rxvt_img::new_from_pixbuf: image too big for Xlib.\n"); |
99 | |
149 | |
100 | xi.data = (char *)rxvt_malloc (height * xi.bytes_per_line); |
150 | xi.data = (char *)rxvt_malloc (height * xi.bytes_per_line); |
101 | |
151 | |
102 | int rowstride = gdk_pixbuf_get_rowstride (pb); |
152 | int rowstride = gdk_pixbuf_get_rowstride (pb); |
103 | |
153 | bool pb_has_alpha = gdk_pixbuf_get_has_alpha (pb); |
104 | assert (3 + (depth == 32) == gdk_pixbuf_get_n_channels (pb)); |
|
|
105 | unsigned char *row = gdk_pixbuf_get_pixels (pb); |
154 | unsigned char *row = gdk_pixbuf_get_pixels (pb); |
|
|
155 | |
106 | char *line = xi.data; |
156 | char *line = xi.data; |
107 | |
157 | |
108 | for (int y = 0; y < height; y++) |
158 | for (int y = 0; y < height; y++) |
109 | { |
159 | { |
110 | unsigned char *src = row; |
160 | unsigned char *src = row; |
111 | uint32_t *dst = (uint32_t *)line; |
161 | uint32_t *dst = (uint32_t *)line; |
112 | |
162 | |
113 | if (depth == 24) |
163 | if (!pb_has_alpha) |
114 | for (int x = 0; x < width; x++) |
164 | for (int x = 0; x < width; x++) |
115 | { |
165 | { |
116 | uint8_t r = *src++; |
166 | uint8_t r = *src++; |
117 | uint8_t g = *src++; |
167 | uint8_t g = *src++; |
118 | uint8_t b = *src++; |
168 | uint8_t b = *src++; |
119 | |
169 | |
120 | uint32_t v = r | (g << 8) | (b << 16); |
170 | uint32_t v = (255 << 24) | (r << 16) | (g << 8) | b; |
121 | |
171 | |
122 | if (ecb_big_endian ()) |
172 | if (ecb_big_endian () ? !byte_order_mismatch : byte_order_mismatch) |
123 | v = ecb_bswap32 (v); |
173 | v = ecb_bswap32 (v); |
124 | |
174 | |
125 | *dst++ = v; |
175 | *dst++ = v; |
126 | } |
176 | } |
127 | else |
177 | else |
… | |
… | |
130 | uint32_t v = *(uint32_t *)src; src += 4; |
180 | uint32_t v = *(uint32_t *)src; src += 4; |
131 | |
181 | |
132 | if (ecb_big_endian ()) |
182 | if (ecb_big_endian ()) |
133 | v = ecb_bswap32 (v); |
183 | v = ecb_bswap32 (v); |
134 | |
184 | |
|
|
185 | v = ecb_rotl32 (v, 8); // abgr to bgra |
|
|
186 | |
|
|
187 | if (!byte_order_mismatch) |
|
|
188 | v = ecb_bswap32 (v); |
|
|
189 | |
135 | *dst++ = v; |
190 | *dst++ = v; |
136 | } |
191 | } |
137 | |
192 | |
138 | row += rowstride; |
193 | row += rowstride; |
139 | line += xi.bytes_per_line; |
194 | line += xi.bytes_per_line; |
140 | } |
195 | } |
141 | |
196 | |
142 | rxvt_img *img = new rxvt_img (s, XRenderFindStandardFormat (dpy, depth == 24 ? PictStandardRGB24 : PictStandardARGB32), 0, 0, width, height); |
197 | rxvt_img *img = new rxvt_img (s, XRenderFindStandardFormat (dpy, PictStandardARGB32), 0, 0, width, height); |
143 | img->alloc (); |
198 | img->alloc (); |
144 | |
199 | |
145 | GC gc = XCreateGC (dpy, img->pm, 0, 0); |
200 | GC gc = XCreateGC (dpy, img->pm, 0, 0); |
146 | XPutImage (dpy, img->pm, gc, &xi, 0, 0, 0, 0, width, height); |
201 | XPutImage (dpy, img->pm, gc, &xi, 0, 0, 0, 0, width, height); |
147 | XFreeGC (dpy, gc); |
202 | XFreeGC (dpy, gc); |
… | |
… | |
165 | g_object_unref (pb); |
220 | g_object_unref (pb); |
166 | |
221 | |
167 | return img; |
222 | return img; |
168 | } |
223 | } |
169 | |
224 | |
|
|
225 | # endif |
|
|
226 | |
170 | void |
227 | void |
171 | rxvt_img::destroy () |
228 | rxvt_img::destroy () |
172 | { |
229 | { |
173 | if (--ref->cnt) |
230 | if (--ref->cnt) |
174 | return; |
231 | return; |
… | |
… | |
190 | pm = XCreatePixmap (s->display->dpy, s->display->root, w, h, format->depth); |
247 | pm = XCreatePixmap (s->display->dpy, s->display->root, w, h, format->depth); |
191 | ref = new pixref (w, h); |
248 | ref = new pixref (w, h); |
192 | } |
249 | } |
193 | |
250 | |
194 | Picture |
251 | Picture |
195 | rxvt_img::src_picture () |
252 | rxvt_img::picture () |
196 | { |
253 | { |
197 | Display *dpy = s->display->dpy; |
254 | Display *dpy = s->display->dpy; |
198 | |
255 | |
199 | XRenderPictureAttributes pa; |
256 | XRenderPictureAttributes pa; |
200 | pa.repeat = repeat; |
257 | pa.repeat = repeat; |
… | |
… | |
207 | rxvt_img::unshare () |
264 | rxvt_img::unshare () |
208 | { |
265 | { |
209 | if (ref->cnt == 1 && ref->ours) |
266 | if (ref->cnt == 1 && ref->ours) |
210 | return; |
267 | return; |
211 | |
268 | |
212 | //TODO: maybe should reify instead |
|
|
213 | Pixmap pm2 = XCreatePixmap (s->display->dpy, s->display->root, ref->w, ref->h, format->depth); |
269 | Pixmap pm2 = XCreatePixmap (s->display->dpy, s->display->root, ref->w, ref->h, format->depth); |
214 | GC gc = XCreateGC (s->display->dpy, pm, 0, 0); |
270 | GC gc = XCreateGC (s->display->dpy, pm, 0, 0); |
215 | XCopyArea (s->display->dpy, pm, pm2, gc, 0, 0, ref->w, ref->h, 0, 0); |
271 | XCopyArea (s->display->dpy, pm, pm2, gc, 0, 0, ref->w, ref->h, 0, 0); |
216 | XFreeGC (s->display->dpy, gc); |
272 | XFreeGC (s->display->dpy, gc); |
217 | |
273 | |
… | |
… | |
220 | pm = pm2; |
276 | pm = pm2; |
221 | ref = new pixref (ref->w, ref->h); |
277 | ref = new pixref (ref->w, ref->h); |
222 | } |
278 | } |
223 | |
279 | |
224 | void |
280 | void |
225 | rxvt_img::fill (const rxvt_color &c) |
281 | rxvt_img::fill (const rgba &c) |
226 | { |
282 | { |
227 | XGCValues gcv; |
283 | XRenderColor rc = { c.r, c.g, c.b, c.a }; |
228 | gcv.foreground = c; |
284 | |
229 | GC gc = XCreateGC (s->display->dpy, pm, GCForeground, &gcv); |
285 | Display *dpy = s->display->dpy; |
230 | XFillRectangle (s->display->dpy, pm, gc, 0, 0, w, h); |
286 | Picture src = picture (); |
231 | XFreeGC (s->display->dpy, gc); |
287 | XRenderFillRectangle (dpy, PictOpSrc, src, &rc, 0, 0, w, h); |
|
|
288 | XRenderFreePicture (dpy, src); |
|
|
289 | } |
|
|
290 | |
|
|
291 | void |
|
|
292 | rxvt_img::add_alpha () |
|
|
293 | { |
|
|
294 | if (format->direct.alphaMask) |
|
|
295 | return; |
|
|
296 | |
|
|
297 | Display *dpy = s->display->dpy; |
|
|
298 | |
|
|
299 | rxvt_img *img = new rxvt_img (s, find_alpha_format_for (dpy, format), x, y, w, h, repeat); |
|
|
300 | img->alloc (); |
|
|
301 | |
|
|
302 | Picture src = picture (); |
|
|
303 | Picture dst = XRenderCreatePicture (dpy, img->pm, img->format, 0, 0); |
|
|
304 | |
|
|
305 | XRenderComposite (dpy, PictOpSrc, src, None, dst, 0, 0, 0, 0, 0, 0, w, h); |
|
|
306 | |
|
|
307 | XRenderFreePicture (dpy, src); |
|
|
308 | XRenderFreePicture (dpy, dst); |
|
|
309 | |
|
|
310 | ::swap (img->ref, ref); |
|
|
311 | ::swap (img->pm , pm ); |
|
|
312 | |
|
|
313 | delete img; |
232 | } |
314 | } |
233 | |
315 | |
234 | static void |
316 | static void |
235 | get_gaussian_kernel (int radius, int width, double *kernel, XFixed *params) |
317 | get_gaussian_kernel (int radius, int width, rxvt_img::nv *kernel, XFixed *params) |
236 | { |
318 | { |
237 | double sigma = radius / 2.0; |
319 | rxvt_img::nv sigma = radius / 2.0; |
238 | double scale = sqrt (2.0 * M_PI) * sigma; |
320 | rxvt_img::nv scale = sqrt (2.0 * M_PI) * sigma; |
239 | double sum = 0.0; |
321 | rxvt_img::nv sum = 0.0; |
240 | |
322 | |
241 | for (int i = 0; i < width; i++) |
323 | for (int i = 0; i < width; i++) |
242 | { |
324 | { |
243 | double x = i - width / 2; |
325 | rxvt_img::nv x = i - width / 2; |
244 | kernel[i] = exp (-(x * x) / (2.0 * sigma * sigma)) / scale; |
326 | kernel[i] = exp (-(x * x) / (2.0 * sigma * sigma)) / scale; |
245 | sum += kernel[i]; |
327 | sum += kernel[i]; |
246 | } |
328 | } |
247 | |
329 | |
248 | params[0] = XDoubleToFixed (width); |
330 | params[0] = XDoubleToFixed (width); |
… | |
… | |
258 | if (!(s->display->flags & DISPLAY_HAS_RENDER_CONV)) |
340 | if (!(s->display->flags & DISPLAY_HAS_RENDER_CONV)) |
259 | return clone (); |
341 | return clone (); |
260 | |
342 | |
261 | Display *dpy = s->display->dpy; |
343 | Display *dpy = s->display->dpy; |
262 | int size = max (rh, rv) * 2 + 1; |
344 | int size = max (rh, rv) * 2 + 1; |
263 | double *kernel = (double *)malloc (size * sizeof (double)); |
345 | nv *kernel = (nv *)malloc (size * sizeof (nv)); |
264 | XFixed *params = (XFixed *)malloc ((size + 2) * sizeof (XFixed)); |
346 | XFixed *params = (XFixed *)malloc ((size + 2) * sizeof (XFixed)); |
265 | rxvt_img *img = new rxvt_img (s, format, x, y, w, h, repeat); |
347 | rxvt_img *img = new rxvt_img (s, format, x, y, w, h, repeat); |
266 | img->alloc (); |
348 | img->alloc (); |
267 | |
349 | |
268 | Picture src = src_picture (); |
|
|
269 | |
|
|
270 | XRenderPictureAttributes pa; |
350 | XRenderPictureAttributes pa; |
271 | pa.repeat = RepeatPad; |
351 | pa.repeat = RepeatPad; |
272 | Picture dst = XRenderCreatePicture (dpy, img->pm, format, CPRepeat, &pa); |
352 | Picture src = XRenderCreatePicture (dpy, pm, format, CPRepeat, &pa); |
|
|
353 | Picture dst = XRenderCreatePicture (dpy, img->pm, format, 0, 0); |
273 | |
354 | |
274 | Pixmap tmp_pm = XCreatePixmap (dpy, pm, w, h, format->depth); |
355 | Pixmap tmp_pm = XCreatePixmap (dpy, pm, w, h, format->depth); |
275 | Picture tmp = XRenderCreatePicture (dpy, tmp_pm , format, CPRepeat, &pa); |
356 | Picture tmp = XRenderCreatePicture (dpy, tmp_pm , format, CPRepeat, &pa); |
276 | XFreePixmap (dpy, tmp_pm); |
357 | XFreePixmap (dpy, tmp_pm); |
277 | |
358 | |
… | |
… | |
293 | |
374 | |
294 | size = rv * 2 + 1; |
375 | size = rv * 2 + 1; |
295 | get_gaussian_kernel (rv, size, kernel, params); |
376 | get_gaussian_kernel (rv, size, kernel, params); |
296 | ::swap (params[0], params[1]); |
377 | ::swap (params[0], params[1]); |
297 | |
378 | |
298 | XRenderSetPictureFilter (dpy, src, FilterConvolution, params, size+2); |
379 | XRenderSetPictureFilter (dpy, tmp, FilterConvolution, params, size+2); |
299 | XRenderComposite (dpy, |
380 | XRenderComposite (dpy, |
300 | PictOpSrc, |
381 | PictOpSrc, |
301 | tmp, |
382 | tmp, |
302 | None, |
383 | None, |
303 | dst, |
384 | dst, |
… | |
… | |
307 | w, h); |
388 | w, h); |
308 | } |
389 | } |
309 | |
390 | |
310 | free (kernel); |
391 | free (kernel); |
311 | free (params); |
392 | free (params); |
|
|
393 | |
312 | XRenderFreePicture (dpy, src); |
394 | XRenderFreePicture (dpy, src); |
313 | XRenderFreePicture (dpy, dst); |
395 | XRenderFreePicture (dpy, dst); |
314 | XRenderFreePicture (dpy, tmp); |
396 | XRenderFreePicture (dpy, tmp); |
315 | |
397 | |
316 | return img; |
398 | return img; |
317 | } |
399 | } |
318 | |
400 | |
319 | static Picture |
401 | static Picture |
320 | create_xrender_mask (Display *dpy, Drawable drawable, Bool argb) |
402 | create_xrender_mask (Display *dpy, Drawable drawable, Bool argb, Bool component_alpha) |
321 | { |
403 | { |
322 | Pixmap pixmap = XCreatePixmap (dpy, drawable, 1, 1, argb ? 32 : 8); |
404 | Pixmap pixmap = XCreatePixmap (dpy, drawable, 1, 1, argb ? 32 : 8); |
323 | |
405 | |
324 | XRenderPictFormat *format = XRenderFindStandardFormat (dpy, argb ? PictStandardARGB32 : PictStandardA8); |
406 | XRenderPictFormat *format = XRenderFindStandardFormat (dpy, argb ? PictStandardARGB32 : PictStandardA8); |
325 | XRenderPictureAttributes pa; |
407 | XRenderPictureAttributes pa; |
326 | pa.repeat = True; |
408 | pa.repeat = RepeatNormal; |
|
|
409 | pa.component_alpha = component_alpha; |
327 | Picture mask = XRenderCreatePicture (dpy, pixmap, format, CPRepeat, &pa); |
410 | Picture mask = XRenderCreatePicture (dpy, pixmap, format, CPRepeat | CPComponentAlpha, &pa); |
328 | |
411 | |
329 | XFreePixmap (dpy, pixmap); |
412 | XFreePixmap (dpy, pixmap); |
330 | |
413 | |
331 | return mask; |
414 | return mask; |
332 | } |
415 | } |
333 | |
416 | |
|
|
417 | static void |
|
|
418 | extract (int32_t cl0, int32_t cl1, int32_t &c, unsigned short &xc) |
|
|
419 | { |
|
|
420 | int32_t x = clamp (c, cl0, cl1); |
|
|
421 | c -= x; |
|
|
422 | xc = x; |
|
|
423 | } |
|
|
424 | |
|
|
425 | static bool |
|
|
426 | extract (int32_t cl0, int32_t cl1, int32_t &r, int32_t &g, int32_t &b, int32_t &a, unsigned short &xr, unsigned short &xg, unsigned short &xb, unsigned short &xa) |
|
|
427 | { |
|
|
428 | extract (cl0, cl1, r, xr); |
|
|
429 | extract (cl0, cl1, g, xg); |
|
|
430 | extract (cl0, cl1, b, xb); |
|
|
431 | extract (cl0, cl1, a, xa); |
|
|
432 | |
|
|
433 | return xr | xg | xb | xa; |
|
|
434 | } |
|
|
435 | |
334 | void |
436 | void |
335 | rxvt_img::brightness (unsigned short r, unsigned short g, unsigned short b, unsigned short a) |
437 | rxvt_img::brightness (int32_t r, int32_t g, int32_t b, int32_t a) |
336 | { |
438 | { |
|
|
439 | unshare (); |
|
|
440 | |
337 | Display *dpy = s->display->dpy; |
441 | Display *dpy = s->display->dpy; |
338 | Picture src = create_xrender_mask (dpy, pm, True); |
|
|
339 | Picture dst = XRenderCreatePicture (dpy, pm, format, 0, 0); |
442 | Picture dst = XRenderCreatePicture (dpy, pm, format, 0, 0); |
340 | |
443 | |
|
|
444 | // loop should not be needed for brightness, as only -1..1 makes sense |
|
|
445 | //while (r | g | b | a) |
|
|
446 | { |
|
|
447 | unsigned short xr, xg, xb, xa; |
341 | XRenderColor mask_c; |
448 | XRenderColor mask_c; |
342 | mask_c.red = r; |
449 | |
343 | mask_c.green = g; |
450 | if (extract (0, 65535, r, g, b, a, mask_c.red, mask_c.green, mask_c.blue, mask_c.alpha)) |
344 | mask_c.blue = b; |
|
|
345 | mask_c.alpha = a; |
|
|
346 | XRenderFillRectangle (dpy, PictOpSrc, src, &mask_c, 0, 0, 1, 1); |
451 | XRenderFillRectangle (dpy, PictOpAdd, dst, &mask_c, 0, 0, w, h); |
347 | |
452 | |
348 | XRenderComposite (dpy, PictOpAdd, src, None, dst, 0, 0, 0, 0, 0, 0, w, h); |
453 | if (extract (-65535, 0, r, g, b, a, mask_c.red, mask_c.green, mask_c.blue, mask_c.alpha)) |
|
|
454 | { |
|
|
455 | XRenderColor mask_w = { 65535, 65535, 65535, 65535 }; |
|
|
456 | XRenderFillRectangle (dpy, PictOpDifference, dst, &mask_w, 0, 0, w, h); |
|
|
457 | mask_c.red = -mask_c.red; //TODO: verify that doing clamp, assign, and negation does the right thing |
|
|
458 | mask_c.green = -mask_c.green; |
|
|
459 | mask_c.blue = -mask_c.blue; |
|
|
460 | mask_c.alpha = -mask_c.alpha; |
|
|
461 | XRenderFillRectangle (dpy, PictOpAdd, dst, &mask_c, 0, 0, w, h); |
|
|
462 | XRenderFillRectangle (dpy, PictOpDifference, dst, &mask_w, 0, 0, w, h); |
|
|
463 | } |
|
|
464 | } |
349 | |
465 | |
350 | XRenderFreePicture (dpy, src); |
|
|
351 | XRenderFreePicture (dpy, dst); |
466 | XRenderFreePicture (dpy, dst); |
352 | } |
467 | } |
353 | |
468 | |
354 | void |
469 | void |
355 | rxvt_img::contrast (unsigned short r, unsigned short g, unsigned short b, unsigned short a) |
470 | rxvt_img::contrast (int32_t r, int32_t g, int32_t b, int32_t a) |
356 | { |
471 | { |
357 | if (!(s->display->flags & DISPLAY_HAS_RENDER_MUL)) |
472 | if (r < 0 || g < 0 || b < 0 || a < 0) |
358 | return; |
473 | rxvt_fatal ("rxvt_img::contrast does not support negative values.\n"); |
359 | |
474 | |
|
|
475 | rxvt_img *img = new rxvt_img (s, format, x, y, w, h, repeat); |
|
|
476 | img->alloc (); |
|
|
477 | img->fill (rgba (0, 0, 0, 0)); |
|
|
478 | |
|
|
479 | // premultiply (yeah, these are not exact, sue me or fix it) |
|
|
480 | r = (r * (a >> 8)) >> 8; |
|
|
481 | g = (g * (a >> 8)) >> 8; |
|
|
482 | b = (b * (a >> 8)) >> 8; |
|
|
483 | |
360 | Display *dpy = s->display->dpy; |
484 | Display *dpy = s->display->dpy; |
361 | Picture src = create_xrender_mask (dpy, pm, True); |
485 | |
|
|
486 | Picture src = picture (); |
362 | Picture dst = XRenderCreatePicture (dpy, pm, format, 0, 0); |
487 | Picture dst = XRenderCreatePicture (dpy, img->pm, format, 0, 0); |
|
|
488 | Picture mul = create_xrender_mask (dpy, pm, True, True); |
363 | |
489 | |
|
|
490 | //TODO: this operator does not yet implement some useful contrast |
|
|
491 | while (r | g | b | a) |
|
|
492 | { |
|
|
493 | unsigned short xr, xg, xb, xa; |
364 | XRenderColor mask_c; |
494 | XRenderColor mask_c; |
365 | mask_c.red = r; |
495 | |
366 | mask_c.green = g; |
496 | if (extract (0, 65535, r, g, b, a, mask_c.red, mask_c.green, mask_c.blue, mask_c.alpha)) |
367 | mask_c.blue = b; |
497 | { |
368 | mask_c.alpha = a; |
|
|
369 | XRenderFillRectangle (dpy, PictOpSrc, src, &mask_c, 0, 0, 1, 1); |
498 | XRenderFillRectangle (dpy, PictOpSrc, mul, &mask_c, 0, 0, 1, 1); |
370 | |
|
|
371 | XRenderComposite (dpy, PictOpMultiply, src, None, dst, 0, 0, 0, 0, 0, 0, w, h); |
499 | XRenderComposite (dpy, PictOpAdd, src, mul, dst, 0, 0, 0, 0, 0, 0, w, h); |
|
|
500 | } |
|
|
501 | } |
372 | |
502 | |
|
|
503 | XRenderFreePicture (dpy, mul); |
373 | XRenderFreePicture (dpy, src); |
504 | XRenderFreePicture (dpy, dst); |
374 | XRenderFreePicture (dpy, dst); |
505 | XRenderFreePicture (dpy, src); |
|
|
506 | |
|
|
507 | ::swap (img->ref, ref); |
|
|
508 | ::swap (img->pm , pm ); |
|
|
509 | |
|
|
510 | delete img; |
|
|
511 | } |
|
|
512 | |
|
|
513 | void |
|
|
514 | rxvt_img::draw (rxvt_img *img, int op, nv mask) |
|
|
515 | { |
|
|
516 | unshare (); |
|
|
517 | |
|
|
518 | Display *dpy = s->display->dpy; |
|
|
519 | Picture src = img->picture (); |
|
|
520 | Picture dst = picture (); |
|
|
521 | Picture mask_p = 0; |
|
|
522 | |
|
|
523 | if (mask != 1.) |
|
|
524 | { |
|
|
525 | mask_p = create_xrender_mask (dpy, img->pm, False, False); |
|
|
526 | XRenderColor mask_c = { 0, 0, 0, float_to_component (mask) }; |
|
|
527 | XRenderFillRectangle (dpy, PictOpSrc, mask, &mask_c, 0, 0, 1, 1); |
|
|
528 | } |
|
|
529 | |
|
|
530 | XRenderComposite (dpy, op, src, mask_p, dst, x - img->x, y - img->y, 0, 0, 0, 0, w, h); |
|
|
531 | |
|
|
532 | XRenderFreePicture (dpy, src); |
|
|
533 | XRenderFreePicture (dpy, dst); |
|
|
534 | |
|
|
535 | if (mask_p) |
|
|
536 | XRenderFreePicture (dpy, mask_p); |
375 | } |
537 | } |
376 | |
538 | |
377 | rxvt_img * |
539 | rxvt_img * |
378 | rxvt_img::clone () |
540 | rxvt_img::clone () |
379 | { |
541 | { |
380 | return new rxvt_img (*this); |
542 | return new rxvt_img (*this); |
381 | } |
|
|
382 | |
|
|
383 | static XRenderPictFormat * |
|
|
384 | find_alpha_format_for (Display *dpy, XRenderPictFormat *format) |
|
|
385 | { |
|
|
386 | if (format->direct.alphaMask) |
|
|
387 | return format; // already has alpha |
|
|
388 | |
|
|
389 | // try to find a suitable alpha format, one bit alpha is enough for our purposes |
|
|
390 | if (format->type == PictTypeDirect) |
|
|
391 | for (int n = 0; XRenderPictFormat *f = XRenderFindFormat (dpy, 0, 0, n); ++n) |
|
|
392 | if (f->direct.alphaMask |
|
|
393 | && f->type == PictTypeDirect |
|
|
394 | && ecb_popcount32 (f->direct.redMask ) >= ecb_popcount32 (format->direct.redMask ) |
|
|
395 | && ecb_popcount32 (f->direct.greenMask) >= ecb_popcount32 (format->direct.greenMask) |
|
|
396 | && ecb_popcount32 (f->direct.blueMask ) >= ecb_popcount32 (format->direct.blueMask )) |
|
|
397 | return f; |
|
|
398 | |
|
|
399 | // should be a very good fallback |
|
|
400 | return XRenderFindStandardFormat (dpy, PictStandardARGB32); |
|
|
401 | } |
543 | } |
402 | |
544 | |
403 | rxvt_img * |
545 | rxvt_img * |
404 | rxvt_img::reify () |
546 | rxvt_img::reify () |
405 | { |
547 | { |
406 | if (x == 0 && y == 0 && w == ref->w && h == ref->h) |
548 | if (x == 0 && y == 0 && w == ref->w && h == ref->h) |
407 | return clone (); |
549 | return clone (); |
408 | |
550 | |
409 | Display *dpy = s->display->dpy; |
551 | Display *dpy = s->display->dpy; |
410 | |
552 | |
|
|
553 | // add an alpha channel if... |
411 | bool alpha = !format->direct.alphaMask |
554 | bool alpha = !format->direct.alphaMask // pixmap has none yet |
412 | && (x || y) |
555 | && (x || y) // we need one because of non-zero offset |
413 | && repeat == RepeatNone; |
556 | && repeat == RepeatNone; // and we have no good pixels to fill with |
414 | |
557 | |
415 | rxvt_img *img = new rxvt_img (s, alpha ? find_alpha_format_for (dpy, format) : format, 0, 0, w, h, repeat); |
558 | rxvt_img *img = new rxvt_img (s, alpha ? find_alpha_format_for (dpy, format) : format, 0, 0, w, h, repeat); |
416 | img->alloc (); |
559 | img->alloc (); |
417 | |
560 | |
418 | Picture src = src_picture (); |
561 | Picture src = picture (); |
419 | Picture dst = XRenderCreatePicture (dpy, img->pm, img->format, 0, 0); |
562 | Picture dst = XRenderCreatePicture (dpy, img->pm, img->format, 0, 0); |
420 | |
563 | |
421 | if (alpha) |
564 | if (alpha) |
422 | { |
565 | { |
423 | XRenderColor rc = { 0, 0, 0, 0 }; |
566 | XRenderColor rc = { 0, 0, 0, 0 }; |
424 | XRenderFillRectangle (dpy, PictOpSrc, dst, &rc, 0, 0, w, h);//TODO: split into four fillrectangles |
567 | XRenderFillRectangle (dpy, PictOpSrc, dst, &rc, 0, 0, w, h);//TODO: split into four fillrectangles |
425 | XRenderComposite (dpy, PictOpSrc, src, None, dst, 0, 0, 0, 0, -x, -y, ref->w, ref->h); |
568 | XRenderComposite (dpy, PictOpSrc, src, None, dst, 0, 0, 0, 0, x, y, ref->w, ref->h); |
426 | } |
569 | } |
427 | else |
570 | else |
428 | XRenderComposite (dpy, PictOpSrc, src, None, dst, x, y, 0, 0, 0, 0, w, h); |
571 | XRenderComposite (dpy, PictOpSrc, src, None, dst, -x, -y, 0, 0, 0, 0, w, h); |
429 | |
572 | |
430 | XRenderFreePicture (dpy, src); |
573 | XRenderFreePicture (dpy, src); |
431 | XRenderFreePicture (dpy, dst); |
574 | XRenderFreePicture (dpy, dst); |
432 | |
575 | |
433 | return img; |
576 | return img; |
… | |
… | |
436 | rxvt_img * |
579 | rxvt_img * |
437 | rxvt_img::sub_rect (int x, int y, int width, int height) |
580 | rxvt_img::sub_rect (int x, int y, int width, int height) |
438 | { |
581 | { |
439 | rxvt_img *img = clone (); |
582 | rxvt_img *img = clone (); |
440 | |
583 | |
441 | img->x += x; |
584 | img->x -= x; |
442 | img->y += y; |
585 | img->y -= y; |
443 | |
586 | |
444 | if (w != width || h != height) |
587 | if (w != width || h != height) |
445 | { |
588 | { |
446 | img->w = width; |
589 | img->w = width; |
447 | img->h = height; |
590 | img->h = height; |
… | |
… | |
452 | } |
595 | } |
453 | |
596 | |
454 | return img; |
597 | return img; |
455 | } |
598 | } |
456 | |
599 | |
457 | rxvt_img * |
600 | static void |
458 | rxvt_img::transform (int new_width, int new_height, double matrix[9]) |
601 | mat_invert (rxvt_img::nv mat[3][3], rxvt_img::nv (&inv)[3][3]) |
459 | { |
602 | { |
|
|
603 | rxvt_img::nv s0 = mat [2][2] * mat [1][1] - mat [2][1] * mat [1][2]; |
|
|
604 | rxvt_img::nv s1 = mat [2][1] * mat [0][2] - mat [2][2] * mat [0][1]; |
|
|
605 | rxvt_img::nv s2 = mat [1][2] * mat [0][1] - mat [1][1] * mat [0][2]; |
|
|
606 | |
|
|
607 | rxvt_img::nv invdet = 1. / (mat [0][0] * s0 + mat [1][0] * s1 + mat [2][0] * s2); |
|
|
608 | |
|
|
609 | inv [0][0] = invdet * s0; |
|
|
610 | inv [0][1] = invdet * s1; |
|
|
611 | inv [0][2] = invdet * s2; |
|
|
612 | |
|
|
613 | inv [1][0] = invdet * (mat [2][0] * mat [1][2] - mat [2][2] * mat [1][0]); |
|
|
614 | inv [1][1] = invdet * (mat [2][2] * mat [0][0] - mat [2][0] * mat [0][2]); |
|
|
615 | inv [1][2] = invdet * (mat [1][0] * mat [0][2] - mat [1][2] * mat [0][0]); |
|
|
616 | |
|
|
617 | inv [2][0] = invdet * (mat [2][1] * mat [1][0] - mat [2][0] * mat [1][1]); |
|
|
618 | inv [2][1] = invdet * (mat [2][0] * mat [0][1] - mat [2][1] * mat [0][0]); |
|
|
619 | inv [2][2] = invdet * (mat [1][1] * mat [0][0] - mat [1][0] * mat [0][1]); |
|
|
620 | } |
|
|
621 | |
|
|
622 | static rxvt_img::nv |
|
|
623 | mat_apply (rxvt_img::nv mat[3][3], int i, rxvt_img::nv x, rxvt_img::nv y) |
|
|
624 | { |
|
|
625 | rxvt_img::nv v = mat [i][0] * x + mat [i][1] * y + mat [i][2]; |
|
|
626 | rxvt_img::nv w = mat [2][0] * x + mat [2][1] * y + mat [2][2]; |
|
|
627 | |
|
|
628 | return v * (1. / w); |
|
|
629 | } |
|
|
630 | |
|
|
631 | rxvt_img * |
|
|
632 | rxvt_img::transform (nv matrix[3][3]) |
|
|
633 | { |
|
|
634 | // find new offset |
|
|
635 | int ox = mat_apply (matrix, 0, -x, -y); |
|
|
636 | int oy = mat_apply (matrix, 1, -x, -y); |
|
|
637 | |
|
|
638 | // calculate new pixel bounding box coordinates |
|
|
639 | nv d [2], rmin[2], rmax[2]; |
|
|
640 | |
|
|
641 | for (int i = 0; i < 2; ++i) |
|
|
642 | { |
|
|
643 | nv v; |
|
|
644 | v = mat_apply (matrix, i, 0, 0); rmin [i] = rmax [i] = v; d [i] = v; |
|
|
645 | v = mat_apply (matrix, i, w, 0); min_it (rmin [i], v); max_it (rmax [i], v); |
|
|
646 | v = mat_apply (matrix, i, 0, h); min_it (rmin [i], v); max_it (rmax [i], v); |
|
|
647 | v = mat_apply (matrix, i, w, h); min_it (rmin [i], v); max_it (rmax [i], v); |
|
|
648 | } |
|
|
649 | |
|
|
650 | int dx = floor (rmin [0]); |
|
|
651 | int dy = floor (rmin [1]); |
|
|
652 | |
|
|
653 | int new_width = ceil (rmax [0] - dx); |
|
|
654 | int new_height = ceil (rmax [1] - dy); |
|
|
655 | |
|
|
656 | nv inv[3][3]; |
|
|
657 | mat_invert (matrix, inv); |
|
|
658 | |
460 | rxvt_img *img = new rxvt_img (s, format, 0, 0, new_width, new_height, repeat); |
659 | rxvt_img *img = new rxvt_img (s, format, ox - dx - d [0], oy - dy - d [1], new_width, new_height, repeat); |
461 | img->alloc (); |
660 | img->alloc (); |
462 | |
661 | |
463 | Display *dpy = s->display->dpy; |
662 | Display *dpy = s->display->dpy; |
464 | Picture src = src_picture (); |
663 | Picture src = picture (); |
465 | Picture dst = XRenderCreatePicture (dpy, img->pm, img->format, 0, 0); |
664 | Picture dst = XRenderCreatePicture (dpy, img->pm, img->format, 0, 0); |
466 | |
665 | |
467 | XTransform xfrm; |
666 | XTransform xfrm; |
468 | |
667 | |
469 | for (int i = 0; i < 3; ++i) |
668 | for (int i = 0; i < 3; ++i) |
470 | for (int j = 0; j < 3; ++j) |
669 | for (int j = 0; j < 3; ++j) |
471 | xfrm.matrix [i][j] = XDoubleToFixed (matrix [i * 3 + j]); |
670 | xfrm.matrix [i][j] = XDoubleToFixed (inv [i][j]); |
472 | |
|
|
473 | #if 0 |
|
|
474 | xfrm.matrix [0][2] -= XDoubleToFixed (x);//TODO |
|
|
475 | xfrm.matrix [1][2] -= XDoubleToFixed (y); |
|
|
476 | #endif |
|
|
477 | |
671 | |
478 | XRenderSetPictureFilter (dpy, src, "good", 0, 0); |
672 | XRenderSetPictureFilter (dpy, src, "good", 0, 0); |
479 | XRenderSetPictureTransform (dpy, src, &xfrm); |
673 | XRenderSetPictureTransform (dpy, src, &xfrm); |
480 | XRenderComposite (dpy, PictOpSrc, src, None, dst, 0, 0, 0, 0, 0, 0, new_width, new_height); |
674 | XRenderComposite (dpy, PictOpSrc, src, None, dst, dx, dy, 0, 0, 0, 0, new_width, new_height); |
481 | |
675 | |
482 | XRenderFreePicture (dpy, src); |
676 | XRenderFreePicture (dpy, src); |
483 | XRenderFreePicture (dpy, dst); |
677 | XRenderFreePicture (dpy, dst); |
484 | |
678 | |
485 | return img; |
679 | return img; |
… | |
… | |
489 | rxvt_img::scale (int new_width, int new_height) |
683 | rxvt_img::scale (int new_width, int new_height) |
490 | { |
684 | { |
491 | if (w == new_width && h == new_height) |
685 | if (w == new_width && h == new_height) |
492 | return clone (); |
686 | return clone (); |
493 | |
687 | |
494 | double matrix[9] = { |
688 | nv matrix[3][3] = { |
495 | w / (double)new_width, 0, 0, |
689 | { new_width / (nv)w, 0, 0 }, |
496 | 0, h / (double)new_height, 0, |
690 | { 0, new_height / (nv)h, 0 }, |
497 | 0, 0, 1 |
691 | { 0, 0, 1 } |
498 | }; |
692 | }; |
499 | |
693 | |
500 | int old_repeat_mode = repeat; |
694 | int old_repeat_mode = repeat; |
501 | repeat = RepeatPad; // not right, but xrender can't proeprly scale it seems |
695 | repeat = RepeatPad; // not right, but xrender can't properly scale it seems |
502 | |
696 | |
503 | rxvt_img *img = transform (new_width, new_height, matrix); |
697 | rxvt_img *img = transform (matrix); |
504 | |
698 | |
505 | repeat = old_repeat_mode; |
699 | repeat = old_repeat_mode; |
506 | img->repeat = repeat; |
700 | img->repeat = repeat; |
507 | |
701 | |
508 | return img; |
702 | return img; |
509 | } |
703 | } |
510 | |
704 | |
511 | rxvt_img * |
705 | rxvt_img * |
512 | rxvt_img::rotate (int new_width, int new_height, int x, int y, double phi) |
706 | rxvt_img::rotate (int cx, int cy, nv phi) |
513 | { |
707 | { |
514 | double s = sin (phi); |
708 | nv s = sin (phi); |
515 | double c = cos (phi); |
709 | nv c = cos (phi); |
516 | |
710 | |
517 | double matrix[9] = { |
711 | nv matrix[3][3] = { |
518 | c, -s, -c * x + s * y + x, |
712 | { c, -s, cx - c * cx + s * cy }, |
519 | s, c, -s * x - c * y + y, |
713 | { s, c, cy - s * cx - c * cy }, |
520 | 0, 0, 1 |
714 | { 0, 0, 1 } |
|
|
715 | //{ c, -s, 0 }, |
|
|
716 | //{ s, c, 0 }, |
|
|
717 | //{ 0, 0, 1 } |
521 | }; |
718 | }; |
522 | |
719 | |
523 | return transform (new_width, new_height, matrix); |
720 | //move (-cx, -cy); |
524 | } |
721 | rxvt_img *img = transform (matrix); |
|
|
722 | //move ( cx, cy); |
|
|
723 | //img->move (cx, cy); |
525 | |
724 | |
|
|
725 | return img; |
|
|
726 | } |
|
|
727 | |
526 | rxvt_img * |
728 | rxvt_img * |
527 | rxvt_img::convert_format (XRenderPictFormat *new_format, const rxvt_color &bg) |
729 | rxvt_img::convert_format (XRenderPictFormat *new_format, const rgba &bg) |
528 | { |
730 | { |
529 | if (new_format == format) |
731 | if (new_format == format) |
530 | return clone (); |
732 | return clone (); |
531 | |
733 | |
532 | rxvt_img *img = new rxvt_img (s, new_format, x, y, w, h, repeat); |
734 | rxvt_img *img = new rxvt_img (s, new_format, x, y, w, h, repeat); |
533 | img->alloc (); |
735 | img->alloc (); |
534 | |
736 | |
535 | Display *dpy = s->display->dpy; |
737 | Display *dpy = s->display->dpy; |
536 | Picture src = src_picture (); |
738 | Picture src = picture (); |
537 | Picture dst = XRenderCreatePicture (dpy, img->pm, new_format, 0, 0); |
739 | Picture dst = XRenderCreatePicture (dpy, img->pm, new_format, 0, 0); |
538 | int op = PictOpSrc; |
740 | int op = PictOpSrc; |
539 | |
741 | |
540 | if (format->direct.alphaMask && !new_format->direct.alphaMask) |
742 | if (format->direct.alphaMask && !new_format->direct.alphaMask) |
541 | { |
743 | { |
542 | // does it have to be that complicated |
744 | // does it have to be that complicated |
543 | rgba c; |
|
|
544 | bg.get (c); |
|
|
545 | |
|
|
546 | XRenderColor rc = { c.r, c.g, c.b, 0xffff }; |
745 | XRenderColor rc = { bg.r, bg.g, bg.b, bg.a }; |
547 | XRenderFillRectangle (dpy, PictOpSrc, dst, &rc, 0, 0, w, h); |
746 | XRenderFillRectangle (dpy, PictOpSrc, dst, &rc, 0, 0, w, h); |
548 | |
747 | |
549 | op = PictOpOver; |
748 | op = PictOpOver; |
550 | } |
749 | } |
551 | |
750 | |
… | |
… | |
556 | |
755 | |
557 | return img; |
756 | return img; |
558 | } |
757 | } |
559 | |
758 | |
560 | rxvt_img * |
759 | rxvt_img * |
561 | rxvt_img::blend (rxvt_img *img, double factor) |
760 | rxvt_img::blend (rxvt_img *img, nv factor) |
562 | { |
761 | { |
563 | rxvt_img *img2 = clone (); |
762 | rxvt_img *img2 = clone (); |
564 | Display *dpy = s->display->dpy; |
763 | Display *dpy = s->display->dpy; |
565 | Picture src = img->src_picture (); |
764 | Picture src = img->picture (); |
566 | Picture dst = XRenderCreatePicture (dpy, img2->pm, img2->format, 0, 0); |
765 | Picture dst = XRenderCreatePicture (dpy, img2->pm, img2->format, 0, 0); |
567 | Picture mask = create_xrender_mask (dpy, img->pm, False); |
766 | Picture mask = create_xrender_mask (dpy, img->pm, False, False); |
568 | |
767 | |
569 | XRenderColor mask_c; |
768 | XRenderColor mask_c; |
570 | |
769 | |
571 | mask_c.alpha = float_to_component (factor); |
770 | mask_c.alpha = float_to_component (factor); |
572 | mask_c.red = |
771 | mask_c.red = |