BradLarson/GPUImage — pull request #566 by karlvr (2012-10-18 19:31:22+00:00)
Title: Tone curves: prevent overflow

I have reproduced the same fault that was reported by Ordinary (https://github.com/BradLarson/GPUImage/issues/559) and I have applied their fix and successfully corrected it.

A similar fault was reported (https://github.com/BradLarson/GPUImage/issues/205) and that fix appears to have been included in the tone curves filter, however the overflow was still possible.

This is a curve that exhibits the problem. You will see colour overflows:

GPUImageToneCurveFilter *curves = [[GPUImageToneCurveFilter alloc] init];
[curves setRgbCompositeControlPoints:@[[NSValue valueWithCGPoint:CGPointMake(.066666667, 0)],
[NSValue valueWithCGPoint:CGPointMake(.741176471, 1.0)]]];

I believe the problem will appear with any curve that has a flat top like this.

The commit applies Ordinary's fix, corrects this and appears to match the behaviour in Photoshop (or similar).