Skip to content

Instantly share code, notes, and snippets.

@pichfl
Created December 13, 2012 10:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pichfl/4275655 to your computer and use it in GitHub Desktop.
Save pichfl/4275655 to your computer and use it in GitHub Desktop.
Softlight calculation
CGFloat calculateSoftlight(CGFloat a, CGFloat b) {
// via http://en.wikipedia.org/wiki/Blend_modes#Soft_Light
CGFloat f;
if ( b <= 0.5 ) {
f = a - (1 - 2 * b) * a * (1 - a);
} else {
CGFloat g;
if (a <= 0.25) {
g = ((16 * a - 12) * a + 4) * a;
} else {
g = sqrt(a);
}
f = a + (2 * b - 1) * (g - a);
}
return f;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment