… | |
… | |
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 | #define float_to_component(d) ((d) * 65535.99) |
|
|
8 | |
|
|
9 | rxvt_img::rxvt_img (rxvt_screen *screen, XRenderPictFormat *format, int width, int height) |
7 | rxvt_img::rxvt_img (rxvt_screen *screen, XRenderPictFormat *format, int x, int y, int width, int height, int repeat) |
10 | : s(screen), w(width), h(height), format(format), shared(false) |
8 | : s(screen), x(x), y(y), w(width), h(height), format(format), repeat(repeat), |
|
|
9 | pm(0), ref(0) |
11 | { |
10 | { |
12 | pm = XCreatePixmap (s->display->dpy, s->display->root, w, h, format->depth); |
|
|
13 | } |
11 | } |
14 | |
12 | |
|
|
13 | 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) |
|
|
15 | { |
|
|
16 | ++ref->cnt; |
|
|
17 | } |
|
|
18 | |
|
|
19 | #if 0 |
15 | rxvt_img::rxvt_img (rxvt_screen *screen, XRenderPictFormat *format, int width, int height, Pixmap pixmap) |
20 | rxvt_img::rxvt_img (rxvt_screen *screen, XRenderPictFormat *format, int width, int height, Pixmap pixmap) |
16 | : s(screen), pm(pixmap), w(width), h(height), format(format), shared(false) |
21 | : s(screen), x(0), y(0), w(width), h(height), format(format), repeat(RepeatNormal), shared(false), pm(pixmap) |
17 | { |
22 | { |
18 | } |
23 | } |
|
|
24 | #endif |
19 | |
25 | |
20 | rxvt_img * |
26 | rxvt_img * |
21 | rxvt_img::new_from_root (rxvt_screen *s) |
27 | rxvt_img::new_from_root (rxvt_screen *s) |
22 | { |
28 | { |
23 | Display *dpy = s->display->dpy; |
29 | Display *dpy = s->display->dpy; |
… | |
… | |
37 | return 0; |
43 | return 0; |
38 | |
44 | |
39 | rxvt_img *img = new rxvt_img ( |
45 | rxvt_img *img = new rxvt_img ( |
40 | s, |
46 | s, |
41 | XRenderFindVisualFormat (dpy, DefaultVisual (dpy, s->display->screen)), |
47 | XRenderFindVisualFormat (dpy, DefaultVisual (dpy, s->display->screen)), |
|
|
48 | 0, |
|
|
49 | 0, |
42 | root_pm_w, |
50 | root_pm_w, |
43 | root_pm_h, |
51 | root_pm_h |
44 | root_pixmap |
|
|
45 | ); |
52 | ); |
46 | |
53 | |
47 | img->shared = true; |
54 | img->pm = root_pixmap; |
|
|
55 | img->ref = new pixref (root_pm_w, root_pm_h); |
|
|
56 | img->ref->ours = false; |
48 | |
57 | |
49 | return img; |
58 | return img; |
50 | } |
59 | } |
51 | |
60 | |
52 | rxvt_img * |
61 | rxvt_img * |
… | |
… | |
59 | rxvt_fatal ("rxvt_img::new_from_file: %s\n", err->message); |
68 | rxvt_fatal ("rxvt_img::new_from_file: %s\n", err->message); |
60 | |
69 | |
61 | rxvt_img *img = new rxvt_img ( |
70 | rxvt_img *img = new rxvt_img ( |
62 | s, |
71 | s, |
63 | XRenderFindStandardFormat (s->display->dpy, gdk_pixbuf_get_has_alpha (pb) ? PictStandardARGB32 : PictStandardRGB24), |
72 | XRenderFindStandardFormat (s->display->dpy, gdk_pixbuf_get_has_alpha (pb) ? PictStandardARGB32 : PictStandardRGB24), |
|
|
73 | 0, |
|
|
74 | 0, |
64 | gdk_pixbuf_get_width (pb), |
75 | gdk_pixbuf_get_width (pb), |
65 | gdk_pixbuf_get_height (pb) |
76 | gdk_pixbuf_get_height (pb) |
66 | ); |
77 | ); |
67 | |
78 | img->alloc (); |
68 | img->render_pixbuf (pb, 0, 0, img->w, img->h, 0, 0); |
79 | img->render_pixbuf (pb, 0, 0, img->w, img->h, 0, 0); |
69 | |
80 | |
|
|
81 | g_object_unref (pb); |
|
|
82 | |
|
|
83 | return img; |
|
|
84 | } |
|
|
85 | |
|
|
86 | void |
|
|
87 | rxvt_img::destroy () |
|
|
88 | { |
|
|
89 | if (--ref->cnt) |
70 | return img; |
90 | return; |
|
|
91 | |
|
|
92 | if (pm && ref->ours) |
|
|
93 | XFreePixmap (s->display->dpy, pm); |
|
|
94 | |
|
|
95 | delete ref; |
71 | } |
96 | } |
72 | |
97 | |
73 | rxvt_img::~rxvt_img () |
98 | rxvt_img::~rxvt_img () |
74 | { |
99 | { |
75 | if (!shared) |
100 | destroy (); |
76 | XFreePixmap (s->display->dpy, pm); |
101 | } |
|
|
102 | |
|
|
103 | void |
|
|
104 | rxvt_img::alloc () |
|
|
105 | { |
|
|
106 | pm = XCreatePixmap (s->display->dpy, s->display->root, w, h, format->depth); |
|
|
107 | ref = new pixref (w, h); |
|
|
108 | } |
|
|
109 | |
|
|
110 | Picture |
|
|
111 | rxvt_img::src_picture () |
|
|
112 | { |
|
|
113 | Display *dpy = s->display->dpy; |
|
|
114 | |
|
|
115 | XRenderPictureAttributes pa; |
|
|
116 | pa.repeat = repeat; |
|
|
117 | Picture pic = XRenderCreatePicture (dpy, pm, format, CPRepeat, &pa); |
|
|
118 | |
|
|
119 | return pic; |
77 | } |
120 | } |
78 | |
121 | |
79 | void |
122 | void |
80 | rxvt_img::unshare () |
123 | rxvt_img::unshare () |
81 | { |
124 | { |
82 | if (!shared) |
125 | if (ref->cnt == 1 && ref->ours) |
83 | return; |
126 | return; |
84 | |
127 | |
85 | rxvt_img *img = clone (); |
128 | //TODO: maybe should reify instead |
|
|
129 | Pixmap pm2 = XCreatePixmap (s->display->dpy, s->display->root, ref->w, ref->h, format->depth); |
|
|
130 | GC gc = XCreateGC (s->display->dpy, pm, 0, 0); |
|
|
131 | XCopyArea (s->display->dpy, pm, pm2, gc, 0, 0, ref->w, ref->h, 0, 0); |
|
|
132 | XFreeGC (s->display->dpy, gc); |
86 | |
133 | |
87 | ::swap (pm , img->pm); |
134 | destroy (); |
88 | ::swap (shared, img->shared); |
|
|
89 | |
135 | |
90 | delete img; |
136 | pm = pm2; |
|
|
137 | ref = new pixref (ref->w, ref->h); |
91 | } |
138 | } |
92 | |
139 | |
93 | void |
140 | void |
94 | rxvt_img::fill (const rxvt_color &c) |
141 | rxvt_img::fill (const rxvt_color &c) |
95 | { |
142 | { |
… | |
… | |
129 | |
176 | |
130 | Display *dpy = s->display->dpy; |
177 | Display *dpy = s->display->dpy; |
131 | int size = max (rh, rv) * 2 + 1; |
178 | int size = max (rh, rv) * 2 + 1; |
132 | double *kernel = (double *)malloc (size * sizeof (double)); |
179 | double *kernel = (double *)malloc (size * sizeof (double)); |
133 | XFixed *params = (XFixed *)malloc ((size + 2) * sizeof (XFixed)); |
180 | XFixed *params = (XFixed *)malloc ((size + 2) * sizeof (XFixed)); |
134 | rxvt_img *img = new rxvt_img (s, format, w, h); |
181 | rxvt_img *img = new rxvt_img (s, format, x, y, w, h, repeat); |
|
|
182 | img->alloc (); |
|
|
183 | |
|
|
184 | Picture src = src_picture (); |
135 | |
185 | |
136 | XRenderPictureAttributes pa; |
186 | XRenderPictureAttributes pa; |
137 | |
|
|
138 | pa.repeat = RepeatPad; |
187 | pa.repeat = RepeatPad; |
139 | Picture src = XRenderCreatePicture (dpy, pm , format, CPRepeat, &pa); |
|
|
140 | Picture dst = XRenderCreatePicture (dpy, img->pm, format, CPRepeat, &pa); |
188 | Picture dst = XRenderCreatePicture (dpy, img->pm, format, CPRepeat, &pa); |
141 | |
189 | |
142 | Pixmap tmp_pm = XCreatePixmap (dpy, pm, w, h, format->depth); |
190 | Pixmap tmp_pm = XCreatePixmap (dpy, pm, w, h, format->depth); |
143 | Picture tmp = XRenderCreatePicture (dpy, tmp_pm , format, CPRepeat, &pa); |
191 | Picture tmp = XRenderCreatePicture (dpy, tmp_pm , format, CPRepeat, &pa); |
144 | XFreePixmap (dpy, tmp_pm); |
192 | XFreePixmap (dpy, tmp_pm); |
… | |
… | |
198 | |
246 | |
199 | return mask; |
247 | return mask; |
200 | } |
248 | } |
201 | |
249 | |
202 | void |
250 | void |
203 | rxvt_img::brightness (double r, double g, double b, double a) |
251 | rxvt_img::brightness (unsigned short r, unsigned short g, unsigned short b, unsigned short a) |
204 | { |
252 | { |
205 | Display *dpy = s->display->dpy; |
253 | Display *dpy = s->display->dpy; |
206 | Picture src = create_xrender_mask (dpy, pm, True); |
254 | Picture src = create_xrender_mask (dpy, pm, True); |
207 | Picture dst = XRenderCreatePicture (dpy, pm, format, 0, 0); |
255 | Picture dst = XRenderCreatePicture (dpy, pm, format, 0, 0); |
208 | |
256 | |
209 | XRenderColor mask_c; |
257 | XRenderColor mask_c; |
210 | mask_c.red = float_to_component (r); |
258 | mask_c.red = r; |
211 | mask_c.green = float_to_component (g); |
259 | mask_c.green = g; |
212 | mask_c.blue = float_to_component (b); |
260 | mask_c.blue = b; |
213 | mask_c.alpha = float_to_component (a); |
261 | mask_c.alpha = a; |
214 | XRenderFillRectangle (dpy, PictOpSrc, src, &mask_c, 0, 0, 1, 1); |
262 | XRenderFillRectangle (dpy, PictOpSrc, src, &mask_c, 0, 0, 1, 1); |
215 | |
263 | |
216 | XRenderComposite (dpy, PictOpAdd, src, None, dst, 0, 0, 0, 0, 0, 0, w, h); |
264 | XRenderComposite (dpy, PictOpAdd, src, None, dst, 0, 0, 0, 0, 0, 0, w, h); |
|
|
265 | |
|
|
266 | XRenderFreePicture (dpy, src); |
|
|
267 | XRenderFreePicture (dpy, dst); |
217 | } |
268 | } |
218 | |
269 | |
219 | void |
270 | void |
220 | rxvt_img::contrast (double r, double g, double b, double a) |
271 | rxvt_img::contrast (unsigned short r, unsigned short g, unsigned short b, unsigned short a) |
221 | { |
272 | { |
222 | if (!(s->display->flags & DISPLAY_HAS_RENDER_MUL)) |
273 | if (!(s->display->flags & DISPLAY_HAS_RENDER_MUL)) |
223 | return; |
274 | return; |
224 | |
275 | |
225 | Display *dpy = s->display->dpy; |
276 | Display *dpy = s->display->dpy; |
226 | Picture src = create_xrender_mask (dpy, pm, True); |
277 | Picture src = create_xrender_mask (dpy, pm, True); |
227 | Picture dst = XRenderCreatePicture (dpy, pm, format, 0, 0); |
278 | Picture dst = XRenderCreatePicture (dpy, pm, format, 0, 0); |
228 | |
279 | |
229 | XRenderColor mask_c; |
280 | XRenderColor mask_c; |
230 | mask_c.red = float_to_component (r); |
281 | mask_c.red = r; |
231 | mask_c.green = float_to_component (g); |
282 | mask_c.green = g; |
232 | mask_c.blue = float_to_component (b); |
283 | mask_c.blue = b; |
233 | mask_c.alpha = float_to_component (a); |
284 | mask_c.alpha = a; |
234 | XRenderFillRectangle (dpy, PictOpSrc, src, &mask_c, 0, 0, 1, 1); |
285 | XRenderFillRectangle (dpy, PictOpSrc, src, &mask_c, 0, 0, 1, 1); |
235 | |
286 | |
236 | XRenderComposite (dpy, PictOpMultiply, src, None, dst, 0, 0, 0, 0, 0, 0, w, h); |
287 | XRenderComposite (dpy, PictOpMultiply, src, None, dst, 0, 0, 0, 0, 0, 0, w, h); |
|
|
288 | |
|
|
289 | XRenderFreePicture (dpy, src); |
|
|
290 | XRenderFreePicture (dpy, dst); |
237 | } |
291 | } |
238 | |
292 | |
239 | bool |
293 | bool |
240 | rxvt_img::render_pixbuf (GdkPixbuf *pixbuf, int src_x, int src_y, int width, int height, int dst_x, int dst_y) |
294 | rxvt_img::render_pixbuf (GdkPixbuf *pixbuf, int src_x, int src_y, int width, int height, int dst_x, int dst_y) |
241 | { |
295 | { |
… | |
… | |
285 | |
339 | |
286 | int rowstride = gdk_pixbuf_get_rowstride (pixbuf); |
340 | int rowstride = gdk_pixbuf_get_rowstride (pixbuf); |
287 | int channels = gdk_pixbuf_get_n_channels (pixbuf); |
341 | int channels = gdk_pixbuf_get_n_channels (pixbuf); |
288 | unsigned char *row = gdk_pixbuf_get_pixels (pixbuf) + src_y * rowstride + src_x * channels; |
342 | unsigned char *row = gdk_pixbuf_get_pixels (pixbuf) + src_y * rowstride + src_x * channels; |
289 | char *line = ximage->data; |
343 | char *line = ximage->data; |
290 | |
|
|
291 | rgba c (0, 0, 0); |
|
|
292 | |
|
|
293 | if (channels == 4 && alpha_mask == 0) |
|
|
294 | { |
|
|
295 | //pix_colors[Color_bg].get (c); |
|
|
296 | //TODO |
|
|
297 | c.r = 0xffff; c.g = 0xc0c0; c.b = 0xcbcb;//D |
|
|
298 | c.r >>= 8; |
|
|
299 | c.g >>= 8; |
|
|
300 | c.b >>= 8; |
|
|
301 | } |
|
|
302 | |
344 | |
303 | for (int y = 0; y < height; y++) |
345 | for (int y = 0; y < height; y++) |
304 | { |
346 | { |
305 | for (int x = 0; x < width; x++) |
347 | for (int x = 0; x < width; x++) |
306 | { |
348 | { |
… | |
… | |
309 | unsigned char r, g, b, a; |
351 | unsigned char r, g, b, a; |
310 | |
352 | |
311 | if (channels == 4) |
353 | if (channels == 4) |
312 | { |
354 | { |
313 | a = pixel[3]; |
355 | a = pixel[3]; |
314 | r = (pixel[0] * a + c.r * (0xff - a)) / 0xff; |
356 | r = pixel[0] * a / 0xff; |
315 | g = (pixel[1] * a + c.g * (0xff - a)) / 0xff; |
357 | g = pixel[1] * a / 0xff; |
316 | b = (pixel[2] * a + c.b * (0xff - a)) / 0xff; |
358 | b = pixel[2] * a / 0xff; |
317 | } |
359 | } |
318 | else |
360 | else |
319 | { |
361 | { |
320 | a = 0xff; |
362 | a = 0xff; |
321 | r = pixel[0]; |
363 | r = pixel[0]; |
… | |
… | |
346 | } |
388 | } |
347 | |
389 | |
348 | rxvt_img * |
390 | rxvt_img * |
349 | rxvt_img::clone () |
391 | rxvt_img::clone () |
350 | { |
392 | { |
351 | rxvt_img *img = new rxvt_img (s, format, w, h); |
393 | return new rxvt_img (*this); |
352 | |
|
|
353 | GC gc = XCreateGC (s->display->dpy, pm, 0, 0); |
|
|
354 | XCopyArea (s->display->dpy, pm, img->pm, gc, 0, 0, w, h, 0, 0); |
|
|
355 | XFreeGC (s->display->dpy, gc); |
|
|
356 | |
|
|
357 | return img; |
|
|
358 | } |
394 | } |
359 | |
395 | |
360 | rxvt_img * |
396 | rxvt_img * |
361 | rxvt_img::sub_rect (int x, int y, int width, int height, int repeat) |
397 | rxvt_img::reify () |
362 | { |
398 | { |
363 | rxvt_img *img = new rxvt_img (s, format, width, height); |
399 | if (x == 0 && y == 0 && w == ref->w && h == ref->h) |
|
|
400 | return clone (); |
364 | |
401 | |
365 | Display *dpy = s->display->dpy; |
402 | Display *dpy = s->display->dpy; |
366 | XRenderPictureAttributes pa; |
403 | |
367 | pa.repeat = repeat; |
404 | bool alpha = !format->direct.alphaMask |
368 | Picture src = XRenderCreatePicture (dpy, pm, format, CPRepeat, &pa); |
405 | && (x || y) |
|
|
406 | && repeat == RepeatNone; |
|
|
407 | |
|
|
408 | rxvt_img *img = new rxvt_img (s, alpha ? XRenderFindStandardFormat (dpy, PictStandardARGB32) : format, 0, 0, w, h, repeat); |
|
|
409 | img->alloc (); |
|
|
410 | |
|
|
411 | Picture src = src_picture (); |
369 | Picture dst = XRenderCreatePicture (dpy, img->pm, img->format, 0, 0); |
412 | Picture dst = XRenderCreatePicture (dpy, img->pm, img->format, 0, 0); |
370 | |
413 | |
|
|
414 | if (alpha) |
|
|
415 | { |
|
|
416 | XRenderColor rc = { 0, 0, 0, 0 }; |
|
|
417 | XRenderFillRectangle (dpy, PictOpSrc, dst, &rc, 0, 0, w, h); |
|
|
418 | XRenderComposite (dpy, PictOpSrc, src, None, dst, 0, 0, 0, 0, -x, -y, ref->w, ref->h); |
|
|
419 | } |
|
|
420 | else |
371 | XRenderComposite (dpy, PictOpSrc, src, None, dst, x, y, 0, 0, 0, 0, width, height); |
421 | XRenderComposite (dpy, PictOpSrc, src, None, dst, x, y, 0, 0, 0, 0, w, h); |
372 | |
422 | |
373 | XRenderFreePicture (dpy, src); |
|
|
374 | XRenderFreePicture (dpy, dst); |
423 | XRenderFreePicture (dpy, src); |
|
|
424 | XRenderFreePicture (dpy, dst); |
375 | |
425 | |
376 | return img; |
426 | return img; |
377 | } |
427 | } |
378 | |
428 | |
379 | rxvt_img * |
429 | rxvt_img * |
|
|
430 | rxvt_img::sub_rect (int x, int y, int width, int height) |
|
|
431 | { |
|
|
432 | rxvt_img *img = clone (); |
|
|
433 | |
|
|
434 | img->x += x; |
|
|
435 | img->y += y; |
|
|
436 | |
|
|
437 | if (w != width || h != height) |
|
|
438 | { |
|
|
439 | img->w = width; |
|
|
440 | img->h = height; |
|
|
441 | |
|
|
442 | rxvt_img *img2 = img->reify (); |
|
|
443 | delete img; |
|
|
444 | img = img2; |
|
|
445 | } |
|
|
446 | |
|
|
447 | return img; |
|
|
448 | } |
|
|
449 | |
|
|
450 | rxvt_img * |
380 | rxvt_img::transform (int new_width, int new_height, double matrix[9], int repeat) |
451 | rxvt_img::transform (int new_width, int new_height, double matrix[9]) |
381 | { |
452 | { |
382 | rxvt_img *img = new rxvt_img (s, format, new_width, new_height); |
453 | rxvt_img *img = new rxvt_img (s, format, 0, 0, new_width, new_height, repeat); |
|
|
454 | img->alloc (); |
383 | |
455 | |
384 | Display *dpy = s->display->dpy; |
456 | Display *dpy = s->display->dpy; |
385 | XRenderPictureAttributes pa; |
457 | Picture src = src_picture (); |
386 | pa.repeat = repeat; |
|
|
387 | Picture src = XRenderCreatePicture (dpy, pm, format, CPRepeat, &pa); |
|
|
388 | Picture dst = XRenderCreatePicture (dpy, img->pm, img->format, 0, 0); |
458 | Picture dst = XRenderCreatePicture (dpy, img->pm, img->format, 0, 0); |
389 | |
459 | |
390 | XTransform xfrm; |
460 | XTransform xfrm; |
391 | |
461 | |
392 | for (int i = 0; i < 3; ++i) |
462 | for (int i = 0; i < 3; ++i) |
393 | for (int j = 0; j < 3; ++j) |
463 | for (int j = 0; j < 3; ++j) |
394 | xfrm.matrix [i][j] = XDoubleToFixed (matrix [i * 3 + j]); |
464 | xfrm.matrix [i][j] = XDoubleToFixed (matrix [i * 3 + j]); |
|
|
465 | |
|
|
466 | xfrm.matrix [0][2] += XDoubleToFixed (x);//TODO |
|
|
467 | xfrm.matrix [0][3] += XDoubleToFixed (y); |
395 | |
468 | |
396 | XRenderSetPictureFilter (dpy, src, "good", 0, 0); |
469 | XRenderSetPictureFilter (dpy, src, "good", 0, 0); |
397 | XRenderSetPictureTransform (dpy, src, &xfrm); |
470 | XRenderSetPictureTransform (dpy, src, &xfrm); |
398 | XRenderComposite (dpy, PictOpSrc, src, None, dst, 0, 0, 0, 0, 0, 0, new_width, new_height); |
471 | XRenderComposite (dpy, PictOpSrc, src, None, dst, 0, 0, 0, 0, 0, 0, new_width, new_height); |
399 | |
472 | |
… | |
… | |
410 | w / (double)new_width, 0, 0, |
483 | w / (double)new_width, 0, 0, |
411 | 0, h / (double)new_height, 0, |
484 | 0, h / (double)new_height, 0, |
412 | 0, 0, 1 |
485 | 0, 0, 1 |
413 | }; |
486 | }; |
414 | |
487 | |
|
|
488 | int old_repeat_mode = repeat; |
|
|
489 | repeat = RepeatPad; // not right, but xrender can't proeprly scale it seems |
|
|
490 | |
415 | return transform (new_width, new_height, matrix); |
491 | rxvt_img *img = transform (new_width, new_height, matrix); |
416 | } |
|
|
417 | |
492 | |
|
|
493 | repeat = old_repeat_mode; |
|
|
494 | img->repeat = repeat; |
|
|
495 | |
|
|
496 | return img; |
|
|
497 | } |
|
|
498 | |
418 | rxvt_img * |
499 | rxvt_img * |
419 | rxvt_img::rotate (int new_width, int new_height, int x, int y, double phi, int repeat) |
500 | rxvt_img::rotate (int new_width, int new_height, int x, int y, double phi) |
420 | { |
501 | { |
421 | double s = sin (phi); |
502 | double s = sin (phi); |
422 | double c = cos (phi); |
503 | double c = cos (phi); |
423 | |
504 | |
424 | double matrix[9] = { |
505 | double matrix[9] = { |
425 | c, -s, -c * x + s * y + x, |
506 | c, -s, -c * x + s * y + x, |
426 | s, c, -s * x - c * y + y, |
507 | s, c, -s * x - c * y + y, |
427 | 0, 0, 1 |
508 | 0, 0, 1 |
428 | }; |
509 | }; |
429 | |
510 | |
430 | return transform (new_width, new_height, matrix, repeat); |
511 | return transform (new_width, new_height, matrix); |
431 | } |
512 | } |
432 | |
513 | |
433 | rxvt_img * |
514 | rxvt_img * |
434 | rxvt_img::convert_to (XRenderPictFormat *new_format) |
515 | rxvt_img::convert_to (XRenderPictFormat *new_format, const rxvt_color &bg) |
435 | { |
516 | { |
|
|
517 | if (new_format == format) |
|
|
518 | return clone (); |
|
|
519 | |
436 | rxvt_img *img = new rxvt_img (s, new_format, w, h); |
520 | rxvt_img *img = new rxvt_img (s, new_format, 0, 0, w, h, repeat); |
|
|
521 | img->alloc (); |
437 | |
522 | |
|
|
523 | printf ("convert %d to %d\n", format->direct.alphaMask, new_format->direct.alphaMask);//D |
|
|
524 | |
438 | Display *dpy = s->display->dpy; |
525 | Display *dpy = s->display->dpy; |
439 | Picture src = XRenderCreatePicture (dpy, pm, format, 0, 0); |
526 | Picture src = src_picture (); |
440 | Picture dst = XRenderCreatePicture (dpy, img->pm, new_format, 0, 0); |
527 | Picture dst = XRenderCreatePicture (dpy, img->pm, new_format, 0, 0); |
|
|
528 | int op = PictOpSrc; |
441 | |
529 | |
|
|
530 | if (format->direct.alphaMask && !new_format->direct.alphaMask) |
|
|
531 | { |
|
|
532 | // does it have to be that complicated |
|
|
533 | rgba c; |
|
|
534 | bg.get (c); |
|
|
535 | |
|
|
536 | XRenderColor rc = { c.r, c.g, c.b, 0xffff }; |
|
|
537 | XRenderFillRectangle (dpy, PictOpSrc, dst, &rc, 0, 0, w, h); |
|
|
538 | |
|
|
539 | op = PictOpOver; |
|
|
540 | } |
|
|
541 | |
442 | XRenderComposite (dpy, PictOpSrc, src, None, dst, 0, 0, 0, 0, 0, 0, w, h); |
542 | XRenderComposite (dpy, op, src, None, dst, 0, 0, 0, 0, 0, 0, w, h); |
443 | |
543 | |
444 | XRenderFreePicture (dpy, src); |
|
|
445 | XRenderFreePicture (dpy, dst); |
544 | XRenderFreePicture (dpy, src); |
|
|
545 | XRenderFreePicture (dpy, dst); |
446 | |
546 | |
|
|
547 | return img; |
|
|
548 | } |
|
|
549 | |
|
|
550 | rxvt_img * |
|
|
551 | rxvt_img::blend (rxvt_img *img, double factor) |
|
|
552 | { |
|
|
553 | rxvt_img *img2 = clone (); |
|
|
554 | Display *dpy = s->display->dpy; |
|
|
555 | Picture src = img->src_picture (); |
|
|
556 | Picture dst = XRenderCreatePicture (dpy, img2->pm, img2->format, 0, 0); |
|
|
557 | Picture mask = create_xrender_mask (dpy, img->pm, False); |
|
|
558 | |
|
|
559 | XRenderColor mask_c; |
|
|
560 | |
|
|
561 | mask_c.alpha = float_to_component (factor); |
|
|
562 | mask_c.red = |
|
|
563 | mask_c.green = |
|
|
564 | mask_c.blue = 0; |
|
|
565 | XRenderFillRectangle (dpy, PictOpSrc, mask, &mask_c, 0, 0, 1, 1); |
|
|
566 | |
|
|
567 | XRenderComposite (dpy, PictOpOver, src, mask, dst, 0, 0, 0, 0, 0, 0, w, h); |
|
|
568 | |
|
|
569 | XRenderFreePicture (dpy, src); |
|
|
570 | XRenderFreePicture (dpy, dst); |
|
|
571 | XRenderFreePicture (dpy, mask); |
|
|
572 | |
447 | return img; |
573 | return img2; |
448 | } |
574 | } |
449 | |
575 | |
450 | #endif |
576 | #endif |
451 | |
577 | |