Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Levels filter #35

Open
srdjanarsic opened this issue Jul 7, 2016 · 2 comments
Open

Levels filter #35

srdjanarsic opened this issue Jul 7, 2016 · 2 comments

Comments

@srdjanarsic
Copy link

I am impressed with this library.
What it's missing for me, is a levels filter https://docs.gimp.org/en/gimp-tool-levels.html
Do you plan to add this kind of filter?

@srdjanarsic
Copy link
Author

srdjanarsic commented Jul 7, 2016

I found exact code in this class. https://github.com/talentedmrjones/Javascript-Canvas-Tools/blob/master/canvasTools.js

So the parameters for this filter are: gama(0-1), input(0-255) and output(0-255). This is the exact photoshop like levels adjustment, so it will be very useful.

This peace of code do a magic:

`

,Adjustments:{
    levels:{
        defaults:{
            gamma:1
            ,input:{
                min:0
                ,max:255
            },
            output:{
                min:0
                ,max:255
            }
        }
        ,method:function(o,r,g,b,a){
            var minInput = o.input.min/255
            ,maxInput = o.input.max/255
            ,minOutput = o.output.min/255
            ,maxOutput = o.output.max/255
            p=[]
            ;
            // in these cases, DRY code adversely affected performance by adding yet another function call.
            // profiling shows that calling the calculation directly is significantly faster
            p[0]=(minOutput+(maxOutput-minOutput)*Pow(Min(Max((r/255)-minInput, 0.0) / (maxInput-minInput), 1.0),(1/o.gamma)))*255;
            p[1]=(minOutput+(maxOutput-minOutput)*Pow(Min(Max((g/255)-minInput, 0.0) / (maxInput-minInput), 1.0),(1/o.gamma)))*255;
            p[2]=(minOutput+(maxOutput-minOutput)*Pow(Min(Max((b/255)-minInput, 0.0) / (maxInput-minInput), 1.0),(1/o.gamma)))*255;
            p[3]=a;

            return p;
        }
    }// levels  
} // Adjustments

`

@the-didi the-didi mentioned this issue Oct 23, 2023
@the-didi
Copy link

#62

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants