Created
June 26, 2011 06:14
-
-
Save ashmind/1047302 to your computer and use it in GitHub Desktop.
gamma_curve method from dcraw
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void CLASS gamma_curve (double pwr, double ts, int mode, int imax) | |
{ | |
int i; | |
double g[6], bnd[2]={0,0}, r; | |
g[0] = pwr; | |
g[1] = ts; | |
g[2] = g[3] = g[4] = 0; | |
bnd[g[1] >= 1] = 1; | |
if (g[1] && (g[1]-1)*(g[0]-1) <= 0) { | |
for (i=0; i < 48; i++) { | |
g[2] = (bnd[0] + bnd[1])/2; | |
if (g[0]) bnd[(pow(g[2]/g[1],-g[0]) - 1)/g[0] - 1/g[2] > -1] = g[2]; | |
else bnd[g[2]/exp(1-1/g[2]) < g[1]] = g[2]; | |
} | |
g[3] = g[2] / g[1]; | |
if (g[0]) g[4] = g[2] * (1/g[0] - 1); | |
} | |
if (g[0]) g[5] = 1 / (g[1]*SQR(g[3])/2 - g[4]*(1 - g[3]) + | |
(1 - pow(g[3],1+g[0]))*(1 + g[4])/(1 + g[0])) - 1; | |
else g[5] = 1 / (g[1]*SQR(g[3])/2 + 1 | |
- g[2] - g[3] - g[2]*g[3]*(log(g[3]) - 1)) - 1; | |
if (!mode--) { | |
memcpy (gamm, g, sizeof gamm); | |
return; | |
} | |
for (i=0; i < 0x10000; i++) { | |
curve[i] = 0xffff; | |
if ((r = (double) i / imax) < 1) | |
curve[i] = 0x10000 * ( mode | |
? (r < g[3] ? r*g[1] : (g[0] ? pow( r,g[0])*(1+g[4])-g[4] : log(r)*g[2]+1)) | |
: (r < g[2] ? r/g[1] : (g[0] ? pow((r+g[4])/(1+g[4]),1/g[0]) : exp((r-1)/g[2])))); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment