mortie / swaylock-effects

Swaylock, with fancy effects
MIT License
698 stars 44 forks source link

new effect suggestion: dim #102

Open redxtech opened 1 year ago

redxtech commented 1 year ago

i used to use a fork of i3lock that had a dimblur effect option.

it would be great to be able to combine the existing blur effect with a new dim effect.

would this be reasonable to add?

CcydtN commented 9 months ago

I think you can achieve a similar effect using effect-vignette. Set "factor" as 0 and "base" as the dim ratio (0 -- black, 1 -- original color)

Here is a clip of the related code, you can look at it and see if it match your needs. If you want more detail, this code is in effect.c, at line 326.

double xf = (x * 1.0) / width;
double yf = (y * 1.0) / height;
double vignette_factor = base + factor * 16 * xf * yf * (1.0 - xf) * (1.0 - yf);

r = (int)(r * vignette_factor) & 0xFF;
g = (int)(g * vignette_factor) & 0xFF;
b = (int)(b * vignette_factor) & 0xFF;