Ashish
Ashish

Reputation: 31

How to implement exposure image filter using fabricjs basefilter?

I would like to know how can we implement exposure filter in fabric js.After some R&D I came to know that we can implement a custom filter in fabricjs using basefilter but I am not aware of the calculation to be used to implement exposure filter for an image.Any help is appreciated!

Upvotes: 1

Views: 621

Answers (1)

AndreaBogazzi
AndreaBogazzi

Reputation: 14741

Exposure filter is generally a gamma filter.

given a gamma value you want to correct, the alghoritm generally look like this:

applyTo() {
    for (let i = 0; i < length; i += 4) {
        data[i] = Math.pow(data[i] / 255, adjustment) * 255;
        data[i + 1] = Math.pow(data[i + 1] / 255, adjustment) * 255;
        data[i + 2] = Math.pow(data[i + 2] / 255, adjustment) * 255;
    }
}

where data is the imageData.data of your image.

Where adjustment is 1/gamma. So for gamma of 1.5 you adjustment will look like 1/1.5

Upvotes: 1

Related Questions