I need to apply exposure filter similar to this one https://pinetools.com/change-image-exposure in order to darken everything except the brightest points/colors.
I can achieve a similar result by changing the gamma with the following algorithm, but only with really high values, for example 50 and more, which is probably work-around and bad practice due to the huge exponential value.
Is there a better way to achieve the same result without bad practice? I'll be glad if you point me in the right direction.
const gamma = 50;
for (let i = 0; i < data.length; i += 4) {
data[i] = 255 * Math.pow(data[i] / 255, gamma); // Red
data[i + 1] = 255 * Math.pow(data[i + 1] / 255, gamma); // Green
data[i + 2] = 255 * Math.pow(data[i + 2] / 255, gamma); // Blue
}
Note: Similar things can be achieved with the library http://camanjs.com/, but I only need just one filter, so it seems unnecessary to me.