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