… | |
… | |
49 | img->ref->ours = false; |
49 | img->ref->ours = false; |
50 | |
50 | |
51 | return img; |
51 | return img; |
52 | } |
52 | } |
53 | |
53 | |
|
|
54 | # if HAVE_PIXBUF |
54 | rxvt_img * |
55 | rxvt_img * |
55 | rxvt_img::new_from_pixbuf (rxvt_screen *s, GdkPixbuf *pb) |
56 | rxvt_img::new_from_pixbuf (rxvt_screen *s, GdkPixbuf *pb) |
56 | { |
57 | { |
57 | Display *dpy = s->display->dpy; |
58 | Display *dpy = s->display->dpy; |
58 | |
59 | |
… | |
… | |
166 | |
167 | |
167 | g_object_unref (pb); |
168 | g_object_unref (pb); |
168 | |
169 | |
169 | return img; |
170 | return img; |
170 | } |
171 | } |
|
|
172 | # endif |
171 | |
173 | |
172 | void |
174 | void |
173 | rxvt_img::destroy () |
175 | rxvt_img::destroy () |
174 | { |
176 | { |
175 | if (--ref->cnt) |
177 | if (--ref->cnt) |
… | |
… | |
314 | XRenderFreePicture (dpy, tmp); |
316 | XRenderFreePicture (dpy, tmp); |
315 | |
317 | |
316 | return img; |
318 | return img; |
317 | } |
319 | } |
318 | |
320 | |
319 | static Picture |
|
|
320 | create_xrender_mask (Display *dpy, Drawable drawable, Bool argb) |
|
|
321 | { |
|
|
322 | Pixmap pixmap = XCreatePixmap (dpy, drawable, 1, 1, argb ? 32 : 8); |
|
|
323 | |
|
|
324 | XRenderPictFormat *format = XRenderFindStandardFormat (dpy, argb ? PictStandardARGB32 : PictStandardA8); |
|
|
325 | XRenderPictureAttributes pa; |
|
|
326 | pa.repeat = True; |
|
|
327 | Picture mask = XRenderCreatePicture (dpy, pixmap, format, CPRepeat, &pa); |
|
|
328 | |
|
|
329 | XFreePixmap (dpy, pixmap); |
|
|
330 | |
|
|
331 | return mask; |
|
|
332 | } |
|
|
333 | |
|
|
334 | static void |
321 | static void |
335 | extract (int32_t cl0, int32_t cl1, int32_t &c, unsigned short &xc) |
322 | extract (int32_t cl0, int32_t cl1, int32_t &c, unsigned short &xc) |
336 | { |
323 | { |
337 | int32_t x = clamp (c, cl0, cl1); |
324 | int32_t x = clamp (c, cl0, cl1); |
338 | c -= x; |
325 | c -= x; |
… | |
… | |
357 | |
344 | |
358 | Display *dpy = s->display->dpy; |
345 | Display *dpy = s->display->dpy; |
359 | Picture dst = XRenderCreatePicture (dpy, pm, format, 0, 0); |
346 | Picture dst = XRenderCreatePicture (dpy, pm, format, 0, 0); |
360 | |
347 | |
361 | // loop should not be needed for brightness, as only -1..1 makes sense |
348 | // loop should not be needed for brightness, as only -1..1 makes sense |
362 | |
|
|
363 | while (r | g | b | a) |
349 | //while (r | g | b | a) |
364 | { |
350 | { |
365 | unsigned short xr, xg, xb, xa; |
351 | unsigned short xr, xg, xb, xa; |
366 | XRenderColor mask_c; |
352 | XRenderColor mask_c; |
367 | |
353 | |
368 | if (extract (0, 65535, r, g, b, a, mask_c.red, mask_c.green, mask_c.blue, mask_c.alpha)) |
354 | if (extract (0, 65535, r, g, b, a, mask_c.red, mask_c.green, mask_c.blue, mask_c.alpha)) |
… | |
… | |
370 | |
356 | |
371 | if (extract (-65535, 0, r, g, b, a, mask_c.red, mask_c.green, mask_c.blue, mask_c.alpha)) |
357 | if (extract (-65535, 0, r, g, b, a, mask_c.red, mask_c.green, mask_c.blue, mask_c.alpha)) |
372 | { |
358 | { |
373 | XRenderColor mask_w = { 65535, 65535, 65535, 65535 }; |
359 | XRenderColor mask_w = { 65535, 65535, 65535, 65535 }; |
374 | XRenderFillRectangle (dpy, PictOpDifference, dst, &mask_w, 0, 0, w, h); |
360 | XRenderFillRectangle (dpy, PictOpDifference, dst, &mask_w, 0, 0, w, h); |
375 | mask_c.red = -mask_c.red; |
361 | mask_c.red = -mask_c.red; //TODO: verify that doing clamp, assign, and negation does the right thing |
376 | mask_c.green = -mask_c.green; |
362 | mask_c.green = -mask_c.green; |
377 | mask_c.blue = -mask_c.blue; |
363 | mask_c.blue = -mask_c.blue; |
378 | mask_c.alpha = -mask_c.alpha; |
364 | mask_c.alpha = -mask_c.alpha; |
379 | XRenderFillRectangle (dpy, PictOpAdd, dst, &mask_c, 0, 0, w, h); |
365 | XRenderFillRectangle (dpy, PictOpAdd, dst, &mask_c, 0, 0, w, h); |
380 | XRenderFillRectangle (dpy, PictOpDifference, dst, &mask_w, 0, 0, w, h); |
366 | XRenderFillRectangle (dpy, PictOpDifference, dst, &mask_w, 0, 0, w, h); |
… | |
… | |
395 | } |
381 | } |
396 | |
382 | |
397 | unshare (); |
383 | unshare (); |
398 | |
384 | |
399 | Display *dpy = s->display->dpy; |
385 | Display *dpy = s->display->dpy; |
400 | Picture src = create_xrender_mask (dpy, pm, True); |
|
|
401 | Picture dst = XRenderCreatePicture (dpy, pm, format, 0, 0); |
386 | Picture dst = XRenderCreatePicture (dpy, pm, format, 0, 0); |
402 | |
387 | |
403 | XRenderColor mask_c; |
388 | XRenderColor mask_c; |
404 | mask_c.red = r; |
389 | mask_c.red = r; |
405 | mask_c.green = g; |
390 | mask_c.green = g; |
406 | mask_c.blue = b; |
391 | mask_c.blue = b; |
407 | mask_c.alpha = a; |
392 | mask_c.alpha = a; |
408 | XRenderFillRectangle (dpy, PictOpSrc, src, &mask_c, 0, 0, 1, 1); |
393 | XRenderFillRectangle (dpy, PictOpMultiply, dst, &mask_c, 0, 0, w, h); |
409 | |
394 | |
410 | XRenderComposite (dpy, PictOpMultiply, src, None, dst, 0, 0, 0, 0, 0, 0, w, h); |
|
|
411 | |
|
|
412 | XRenderFreePicture (dpy, src); |
|
|
413 | XRenderFreePicture (dpy, dst); |
395 | XRenderFreePicture (dpy, dst); |
414 | } |
396 | } |
415 | |
397 | |
416 | rxvt_img * |
398 | rxvt_img * |
417 | rxvt_img::clone () |
399 | rxvt_img::clone () |
… | |
… | |
600 | { |
582 | { |
601 | rxvt_img *img2 = clone (); |
583 | rxvt_img *img2 = clone (); |
602 | Display *dpy = s->display->dpy; |
584 | Display *dpy = s->display->dpy; |
603 | Picture src = img->src_picture (); |
585 | Picture src = img->src_picture (); |
604 | Picture dst = XRenderCreatePicture (dpy, img2->pm, img2->format, 0, 0); |
586 | Picture dst = XRenderCreatePicture (dpy, img2->pm, img2->format, 0, 0); |
605 | Picture mask = create_xrender_mask (dpy, img->pm, False); |
587 | |
|
|
588 | Pixmap pixmap = XCreatePixmap (dpy, img->pm, 1, 1, 8); |
|
|
589 | XRenderPictFormat *format = XRenderFindStandardFormat (dpy, PictStandardA8); |
|
|
590 | XRenderPictureAttributes pa; |
|
|
591 | pa.repeat = True; |
|
|
592 | Picture mask = XRenderCreatePicture (dpy, pixmap, format, CPRepeat, &pa); |
|
|
593 | XFreePixmap (dpy, pixmap); |
606 | |
594 | |
607 | XRenderColor mask_c; |
595 | XRenderColor mask_c; |
608 | |
596 | |
609 | mask_c.alpha = float_to_component (factor); |
597 | mask_c.alpha = float_to_component (factor); |
610 | mask_c.red = |
598 | mask_c.red = |