Replace all x^(1/3) with std::cbrt(x)

This commit is contained in:
heckflosse 2016-02-25 16:50:21 +01:00
parent bf66671a6d
commit 1b220543f3
6 changed files with 38 additions and 37 deletions

View File

@ -328,7 +328,7 @@ double Ciecam02::calculate_fl_from_la_ciecam02( double la )
k = k * k;
k = k * k;
return (0.2 * k * la5) + (0.1 * (1.0 - k) * (1.0 - k) * pow(la5, 1.0 / 3.0));
return (0.2 * k * la5) + (0.1 * (1.0 - k) * (1.0 - k) * std::cbrt(la5));
}
float Ciecam02::calculate_fl_from_la_ciecam02float( float la )
@ -340,7 +340,7 @@ float Ciecam02::calculate_fl_from_la_ciecam02float( float la )
k = k * k;
k = k * k;
return (0.2f * k * la5) + (0.1f * (1.0f - k) * (1.0f - k) * pow_F(la5, 1.0f / 3.0f));
return (0.2f * k * la5) + (0.1f * (1.0f - k) * (1.0f - k) * std::cbrt(la5));
}
double Ciecam02::achromatic_response_to_white( double x, double y, double z, double d, double fl, double nbb, int gamu )

View File

@ -171,7 +171,7 @@ void Color::init ()
for (int i = 0; i < maxindex; i++) {
if (i > eps_max) {
cachef[i] = 327.68 * exp(1.0 / 3.0 * log((double)i / MAXVALF) );
cachef[i] = 327.68 * std::cbrt((double)i / MAXVALF);
} else {
cachef[i] = 327.68 * ((kappa * i / MAXVALF + 16.0) / 116.0);
}
@ -1512,9 +1512,9 @@ void Color::Yuv2Lab(float Yin, float u, float v, float &L, float &a, float &b, d
gamutmap(X, Y, Z, wp);
float fx = (X <= 65535.0 ? cachef[X] : (327.68 * exp(log(X / MAXVALF) / 3.0 )));
float fy = (Y <= 65535.0 ? cachef[Y] : (327.68 * exp(log(Y / MAXVALF) / 3.0 )));
float fz = (Z <= 65535.0 ? cachef[Z] : (327.68 * exp(log(Z / MAXVALF) / 3.0 )));
float fx = (X <= 65535.0 ? cachef[X] : (327.68 * std::cbrt(X / MAXVALF)));
float fy = (Y <= 65535.0 ? cachef[Y] : (327.68 * std::cbrt(Y / MAXVALF)));
float fz = (Z <= 65535.0 ? cachef[Z] : (327.68 * std::cbrt(Z / MAXVALF)));
L = (116.0 * fy - 5242.88); //5242.88=16.0*327.68;
a = (500.0 * (fx - fy) );
@ -1560,7 +1560,7 @@ void Color::XYZ2Luv (float X, float Y, float Z, float &L, float &u, float &v)
Z /= 65535.f;
if (Y > float(eps)) {
L = 116.f * pow(Y, 1.f / 3.f) - 16.f;
L = 116.f * std::cbrt(Y) - 16.f;
} else {
L = float(kappa) * Y;
}

View File

@ -1414,19 +1414,19 @@ void ColorTemp::temp2mul (double temp, double green, double equal, double& rmul,
// xr, yr , zr > epsilon
if(xr[i] > epsilon) {
fx[i] = pow(xr[i], 0.333);
fx[i] = std::cbrt(xr[i]);
} else {
fx[i] = (903.3 * xr[i] + 16.0) / 116.0;
}
if(yr[i] > epsilon) {
fy[i] = pow(yr[i], 0.333);
fy[i] = std::cbrt(yr[i]);
} else {
fy[i] = (903.3 * yr[i] + 16.0) / 116.0;
}
if(zr[i] > epsilon) {
fz[i] = pow(zr[i], 0.333);
fz[i] = std::cbrt(zr[i]);
} else {
fz[i] = (903.3 * zr[i] + 16.0) / 116.0;
}
@ -1663,19 +1663,19 @@ void ColorTemp::temp2mul (double temp, double green, double equal, double& rmul,
// xr, yr , zr > epsilon
if(xr[i] > epsilon) {
fx[i] = pow(xr[i], 0.333);
fx[i] = std::cbrt(xr[i]);
} else {
fx[i] = (903.3 * xr[i] + 16.0) / 116.0;
}
if(yr[i] > epsilon) {
fy[i] = pow(yr[i], 0.333);
fy[i] = std::cbrt(yr[i]);
} else {
fy[i] = (903.3 * yr[i] + 16.0) / 116.0;
}
if(zr[i] > epsilon) {
fz[i] = pow(zr[i], 0.333);
fz[i] = std::cbrt(zr[i]);
} else {
fz[i] = (903.3 * zr[i] + 16.0) / 116.0;
}
@ -1695,19 +1695,19 @@ void ColorTemp::temp2mul (double temp, double green, double equal, double& rmul,
//
if(xr[i] > epsilon) {
fx[i] = pow(xr[i], 0.333);
fx[i] = std::cbrt(xr[i]);
} else {
fx[i] = (903.3 * xr[i] + 16.0) / 116.0;
}
if(yr[i] > epsilon) {
fy[i] = pow(yr[i], 0.333);
fy[i] = std::cbrt(yr[i]);
} else {
fy[i] = (903.3 * yr[i] + 16.0) / 116.0;
}
if(zr[i] > epsilon) {
fz[i] = pow(zr[i], 0.333);
fz[i] = std::cbrt(zr[i]);
} else {
fz[i] = (903.3 * zr[i] + 16.0) / 116.0;
}

View File

@ -90,17 +90,17 @@ void RawImageSource::eahd_demosaic ()
threshold = (int)(0.008856 * MAXVALD);
for (int i = 0; i < maxindex; i++) {
cache[i] = exp(1.0 / 3.0 * log(double(i) / MAXVALD));
cache[i] = std::cbrt(double(i) / MAXVALD);
}
// end of cielab preparation
const JaggedArray<float>
rh (W, 3), gh (W, 4), bh (W, 3),
rv (W, 3), gv (W, 4), bv (W, 3),
lLh (W, 3), lah (W, 3), lbh (W, 3),
lLv (W, 3), lav (W, 3), lbv (W, 3),
homh (W, 3), homv (W, 3);
rh (W, 3), gh (W, 4), bh (W, 3),
rv (W, 3), gv (W, 4), bv (W, 3),
lLh (W, 3), lah (W, 3), lbh (W, 3),
lLv (W, 3), lav (W, 3), lbv (W, 3),
homh (W, 3), homv (W, 3);
// interpolate first two lines
interpolate_row_g (gh[0], gv[0], 0);
@ -2703,7 +2703,7 @@ void RawImageSource::ahd_demosaic(int winx, int winy, int winw, int winh)
for (i = 0; i < 0x10000; i++) {
r = (double)i / 65535.0;
cbrt[i] = r > 0.008856 ? pow(r, 0.333333333) : 7.787 * r + 16 / 116.0;
cbrt[i] = r > 0.008856 ? std::cbrt(r) : 7.787 * r + 16 / 116.0;
}
for (i = 0; i < 3; i++)

View File

@ -3779,9 +3779,9 @@ void ImProcFunctions::rgbProc (Imagefloat* working, LabImage* lab, PipetteBuffer
y = toxyz[1][0] * r1 + toxyz[1][1] * g1 + toxyz[1][2] * b1;
z = toxyz[2][0] * r1 + toxyz[2][1] * g1 + toxyz[2][2] * b1;
fx = (x < 65535.0f ? Color::cachef[std::max(x, 0.f)] : (327.68f * float(exp(log(x / MAXVALF) / 3.0f ))));
fy = (y < 65535.0f ? Color::cachef[std::max(y, 0.f)] : (327.68f * float(exp(log(y / MAXVALF) / 3.0f ))));
fz = (z < 65535.0f ? Color::cachef[std::max(z, 0.f)] : (327.68f * float(exp(log(z / MAXVALF) / 3.0f ))));
fx = (x < 65535.0f ? Color::cachef[std::max(x, 0.f)] : 327.68f * std::cbrt(x / MAXVALF));
fy = (y < 65535.0f ? Color::cachef[std::max(y, 0.f)] : 327.68f * std::cbrt(y / MAXVALF));
fz = (z < 65535.0f ? Color::cachef[std::max(z, 0.f)] : 327.68f * std::cbrt(z / MAXVALF));
L_1 = (116.0f * fy - 5242.88f); //5242.88=16.0*327.68;
a_1 = (500.0f * (fx - fy) );
@ -3809,7 +3809,7 @@ void ImProcFunctions::rgbProc (Imagefloat* working, LabImage* lab, PipetteBuffer
// Luminosity after
// only Luminance in Lab
yy = toxyz[1][0] * r2 + toxyz[1][1] * g2 + toxyz[1][2] * b2;
fyy = (yy < 65535.0f ? Color::cachef[std::max(yy, 0.f)] : (327.68f * float(exp(log(yy / MAXVALF) / 3.0f ))));
fyy = (yy < 65535.0f ? Color::cachef[std::max(yy, 0.f)] : 327.68f * std::cbrt(yy / MAXVALF));
L_2 = (116.0f * fyy - 5242.88f);
//gamut control
@ -4402,9 +4402,9 @@ void ImProcFunctions::rgbProc (Imagefloat* working, LabImage* lab, PipetteBuffer
float fx, fy, fz;
fx = (x < 65535.0f ? Color::cachef[std::max(x, 0.f)] : (327.68f * float(exp(log(x / MAXVALF) / 3.0f ))));
fy = (y < 65535.0f ? Color::cachef[std::max(y, 0.f)] : (327.68f * float(exp(log(y / MAXVALF) / 3.0f ))));
fz = (z < 65535.0f ? Color::cachef[std::max(z, 0.f)] : (327.68f * float(exp(log(z / MAXVALF) / 3.0f ))));
fx = (x < 65535.0f ? Color::cachef[std::max(x, 0.f)] : 327.68f * std::cbrt(x / MAXVALF));
fy = (y < 65535.0f ? Color::cachef[std::max(y, 0.f)] : 327.68f * std::cbrt(y / MAXVALF));
fz = (z < 65535.0f ? Color::cachef[std::max(z, 0.f)] : 327.68f * std::cbrt(z / MAXVALF));
lab->L[i][j] = (116.0f * fy - 5242.88f); //5242.88=16.0*327.68;
lab->a[i][j] = (500.0f * (fx - fy) );
@ -4852,9 +4852,9 @@ void ImProcFunctions::rgbProc (Imagefloat* working, LabImage* lab, PipetteBuffer
float fx, fy, fz;
fx = (x < 65535.0f ? Color::cachef[std::max(x, 0.f)] : (327.68f * float(exp(log(x / MAXVALF) / 3.0f ))));
fy = (y < 65535.0f ? Color::cachef[std::max(y, 0.f)] : (327.68f * float(exp(log(y / MAXVALF) / 3.0f ))));
fz = (z < 65535.0f ? Color::cachef[std::max(z, 0.f)] : (327.68f * float(exp(log(z / MAXVALF) / 3.0f ))));
fx = (x < 65535.0f ? Color::cachef[std::max(x, 0.f)] : 327.68f * std::cbrt(x / MAXVALF));
fy = (y < 65535.0f ? Color::cachef[std::max(y, 0.f)] : 327.68f * std::cbrt(y / MAXVALF));
fz = (z < 65535.0f ? Color::cachef[std::max(z, 0.f)] : 327.68f * std::cbrt(z / MAXVALF));
lab->L[i][j] = (116.0f * fy - 5242.88f); //5242.88=16.0*327.68;
lab->a[i][j] = (500.0f * (fx - fy) );

View File

@ -1422,6 +1422,7 @@ SSEFUNCTION int RawImageSource::findHotDeadPixels( PixelsMap &bpMap, float thres
}
#else
// 25 fabs function calls and 25 float additions without SSE
for (int mm = rr - 2; mm <= rr + 2; mm++) {
for (int nn = cc - 2; nn <= cc + 2; nn++) {
@ -4209,14 +4210,14 @@ void RawImageSource::HLRecovery_CIELab (float* rin, float* gin, float* bin, floa
float go = min(g, maxval);
float bo = min(b, maxval);
float yy = xyz_cam[1][0] * r + xyz_cam[1][1] * g + xyz_cam[1][2] * b;
float fy = (yy < 65535.0 ? Color::cachef[yy] / 327.68 : (exp(log(yy / MAXVALD) / 3.0 )));
float fy = (yy < 65535.0 ? Color::cachef[yy] / 327.68 : std::cbrt(yy / MAXVALD));
// compute LCH decompostion of the clipped pixel (only color information, thus C and H will be used)
float x = xyz_cam[0][0] * ro + xyz_cam[0][1] * go + xyz_cam[0][2] * bo;
float y = xyz_cam[1][0] * ro + xyz_cam[1][1] * go + xyz_cam[1][2] * bo;
float z = xyz_cam[2][0] * ro + xyz_cam[2][1] * go + xyz_cam[2][2] * bo;
x = (x < 65535.0 ? Color::cachef[x] / 327.68 : (exp(log(x / MAXVALD) / 3.0 )));
y = (y < 65535.0 ? Color::cachef[y] / 327.68 : (exp(log(y / MAXVALD) / 3.0 )));
z = (z < 65535.0 ? Color::cachef[z] / 327.68 : (exp(log(z / MAXVALD) / 3.0 )));
x = (x < 65535.0 ? Color::cachef[x] / 327.68 : std::cbrt(x / MAXVALD));
y = (y < 65535.0 ? Color::cachef[y] / 327.68 : std::cbrt(y / MAXVALD));
z = (z < 65535.0 ? Color::cachef[z] / 327.68 : std::cbrt(z / MAXVALD));
// convert back to rgb
double fz = fy - y + z;
double fx = fy + x - y;