… | |
… | |
316 | XRenderFreePicture (dpy, tmp); |
316 | XRenderFreePicture (dpy, tmp); |
317 | |
317 | |
318 | return img; |
318 | return img; |
319 | } |
319 | } |
320 | |
320 | |
|
|
321 | static Picture |
|
|
322 | create_xrender_mask (Display *dpy, Drawable drawable, Bool argb, Bool component_alpha) |
|
|
323 | { |
|
|
324 | Pixmap pixmap = XCreatePixmap (dpy, drawable, 1, 1, argb ? 32 : 8); |
|
|
325 | |
|
|
326 | XRenderPictFormat *format = XRenderFindStandardFormat (dpy, argb ? PictStandardARGB32 : PictStandardA8); |
|
|
327 | XRenderPictureAttributes pa; |
|
|
328 | pa.repeat = RepeatNormal; |
|
|
329 | pa.component_alpha = component_alpha; |
|
|
330 | Picture mask = XRenderCreatePicture (dpy, pixmap, format, CPRepeat | CPComponentAlpha, &pa); |
|
|
331 | |
|
|
332 | XFreePixmap (dpy, pixmap); |
|
|
333 | |
|
|
334 | return mask; |
|
|
335 | } |
|
|
336 | |
321 | static void |
337 | static void |
322 | extract (int32_t cl0, int32_t cl1, int32_t &c, unsigned short &xc) |
338 | extract (int32_t cl0, int32_t cl1, int32_t &c, unsigned short &xc) |
323 | { |
339 | { |
324 | int32_t x = clamp (c, cl0, cl1); |
340 | int32_t x = clamp (c, cl0, cl1); |
325 | c -= x; |
341 | c -= x; |
… | |
… | |
365 | XRenderFillRectangle (dpy, PictOpAdd, dst, &mask_c, 0, 0, w, h); |
381 | XRenderFillRectangle (dpy, PictOpAdd, dst, &mask_c, 0, 0, w, h); |
366 | XRenderFillRectangle (dpy, PictOpDifference, dst, &mask_w, 0, 0, w, h); |
382 | XRenderFillRectangle (dpy, PictOpDifference, dst, &mask_w, 0, 0, w, h); |
367 | } |
383 | } |
368 | } |
384 | } |
369 | |
385 | |
370 | |
|
|
371 | XRenderFreePicture (dpy, dst); |
386 | XRenderFreePicture (dpy, dst); |
372 | } |
387 | } |
373 | |
388 | |
374 | void |
389 | void |
375 | rxvt_img::contrast (int32_t r, int32_t g, int32_t b, int32_t a) |
390 | rxvt_img::contrast (int32_t r, int32_t g, int32_t b, int32_t a) |
376 | { |
391 | { |
377 | if (!(s->display->flags & DISPLAY_HAS_RENDER_MUL)) |
392 | if (r < 0 || g < 0 || b < 0 || a < 0) |
|
|
393 | rxvt_fatal ("rxvt_img::contrast does not support negative values.\n"); |
|
|
394 | |
|
|
395 | rxvt_img *img = new rxvt_img (s, format, x, y, w, h, repeat); |
|
|
396 | img->alloc (); |
|
|
397 | |
378 | { |
398 | { |
379 | rxvt_warn ("rxvt_img::contrast operation not supported on this display, RENDER extension too old.\n"); |
399 | rxvt_color empty; |
380 | return; |
400 | empty.set (s, rgba (0, 0, 0, 0)); |
|
|
401 | img->fill (empty); |
381 | } |
402 | } |
382 | |
403 | |
383 | unshare (); |
404 | // premultiply (yeah, these are not exact, sue me or fix it) |
|
|
405 | r = (r * (a >> 8)) >> 8; |
|
|
406 | g = (g * (a >> 8)) >> 8; |
|
|
407 | b = (b * (a >> 8)) >> 8; |
384 | |
408 | |
385 | Display *dpy = s->display->dpy; |
409 | Display *dpy = s->display->dpy; |
|
|
410 | |
|
|
411 | Picture src = src_picture (); |
386 | Picture dst = XRenderCreatePicture (dpy, pm, format, 0, 0); |
412 | Picture dst = XRenderCreatePicture (dpy, img->pm, format, 0, 0); |
|
|
413 | Picture mul = create_xrender_mask (dpy, pm, True, True); |
387 | |
414 | |
|
|
415 | //TODO: this operator does not yet implement some useful contrast |
|
|
416 | while (r | g | b | a) |
|
|
417 | { |
|
|
418 | unsigned short xr, xg, xb, xa; |
388 | XRenderColor mask_c; |
419 | XRenderColor mask_c; |
389 | mask_c.red = r; |
420 | |
390 | mask_c.green = g; |
421 | if (extract (0, 65535, r, g, b, a, mask_c.red, mask_c.green, mask_c.blue, mask_c.alpha)) |
391 | mask_c.blue = b; |
422 | { |
392 | mask_c.alpha = a; |
|
|
393 | XRenderFillRectangle (dpy, PictOpMultiply, dst, &mask_c, 0, 0, w, h); |
423 | XRenderFillRectangle (dpy, PictOpSrc, mul, &mask_c, 0, 0, 1, 1); |
|
|
424 | XRenderComposite (dpy, PictOpAdd, src, mul, dst, 0, 0, 0, 0, 0, 0, w, h); |
|
|
425 | } |
|
|
426 | } |
394 | |
427 | |
|
|
428 | XRenderFreePicture (dpy, mul); |
395 | XRenderFreePicture (dpy, dst); |
429 | XRenderFreePicture (dpy, dst); |
|
|
430 | XRenderFreePicture (dpy, src); |
|
|
431 | |
|
|
432 | ::swap (img->ref, ref); |
|
|
433 | ::swap (img->pm , pm ); |
|
|
434 | |
|
|
435 | delete img; |
396 | } |
436 | } |
397 | |
437 | |
398 | rxvt_img * |
438 | rxvt_img * |
399 | rxvt_img::clone () |
439 | rxvt_img::clone () |
400 | { |
440 | { |
… | |
… | |
582 | { |
622 | { |
583 | rxvt_img *img2 = clone (); |
623 | rxvt_img *img2 = clone (); |
584 | Display *dpy = s->display->dpy; |
624 | Display *dpy = s->display->dpy; |
585 | Picture src = img->src_picture (); |
625 | Picture src = img->src_picture (); |
586 | Picture dst = XRenderCreatePicture (dpy, img2->pm, img2->format, 0, 0); |
626 | Picture dst = XRenderCreatePicture (dpy, img2->pm, img2->format, 0, 0); |
587 | |
627 | Picture mask = create_xrender_mask (dpy, img->pm, False, False); |
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); |
|
|
594 | |
628 | |
595 | XRenderColor mask_c; |
629 | XRenderColor mask_c; |
596 | |
630 | |
597 | mask_c.alpha = float_to_component (factor); |
631 | mask_c.alpha = float_to_component (factor); |
598 | mask_c.red = |
632 | mask_c.red = |