Formatted all .cc and .h code in rtengine, rtexif and rtgui using astyle

This commit is contained in:
DrSlony
2015-08-11 11:55:03 +02:00
parent effb46c3e1
commit 0e0cfb9b25
452 changed files with 133354 additions and 99460 deletions

View File

@@ -41,13 +41,19 @@ extern const Settings* settings;
void Ciecam02::curvecolor(double satind, double satval, double &sres, double parsat)
{
if (satind >=0.0) {
sres = (1.-(satind)/100.)*satval+(satind)/100.*(1.-SQR(SQR(1.-min(satval,1.0))));
if (sres>parsat) { sres=parsat; }
if (sres<0.) { sres=0.; }
if (satind >= 0.0) {
sres = (1. - (satind) / 100.) * satval + (satind) / 100.*(1. - SQR(SQR(1. - min(satval, 1.0))));
if (sres > parsat) {
sres = parsat;
}
if (sres < 0.) {
sres = 0.;
}
} else {
if (satind < -0.1) {
sres = satval*(1.+(satind)/100.);
sres = satval * (1. + (satind) / 100.);
}
}
}
@@ -58,13 +64,14 @@ void Ciecam02::curvecolorfloat(float satind, float satval, float &sres, float pa
if (satval >= 1.f) { // The calculation below goes wrong direction when satval > 1
sres = satval;
} else {
sres = (1.f-(satind)/100.f)*satval+(satind)/100.f*(1.f-SQR(SQR(1.f-min(satval,1.0f))));
sres = (1.f - (satind) / 100.f) * satval + (satind) / 100.f * (1.f - SQR(SQR(1.f - min(satval, 1.0f))));
}
if (sres>parsat) {
sres = max(parsat,satval);
if (sres > parsat) {
sres = max(parsat, satval);
}
} else if (satind < 0.f) {
sres = satval*(1.f+(satind)/100.f);
sres = satval * (1.f + (satind) / 100.f);
} else { // satind == 0 means we don't want to change the value at all
sres = satval;
}
@@ -72,11 +79,11 @@ void Ciecam02::curvecolorfloat(float satind, float satval, float &sres, float pa
void Ciecam02::curveJ (double br, double contr, int db, LUTf & outCurve, LUTu & histogram )
{
LUTf dcurve(65536,0);
int skip=1;
LUTf dcurve(65536, 0);
int skip = 1;
// check if brightness curve is needed
if (br>0.00001 || br<-0.00001) {
if (br > 0.00001 || br < -0.00001) {
std::vector<double> brightcurvePoints;
brightcurvePoints.resize(9);
@@ -85,26 +92,27 @@ void Ciecam02::curveJ (double br, double contr, int db, LUTf & outCurve, LUTu &
brightcurvePoints.at(1) = 0.; // black point. Value in [0 ; 1] range
brightcurvePoints.at(2) = 0.; // black point. Value in [0 ; 1] range
if (br>0) {
if (br > 0) {
brightcurvePoints.at(3) = 0.1; // toe point
brightcurvePoints.at(4) = 0.1+br/150.0; //value at toe point
brightcurvePoints.at(4) = 0.1 + br / 150.0; //value at toe point
brightcurvePoints.at(5) = 0.7; // shoulder point
brightcurvePoints.at(6) = min(1.0,0.7+br/300.0); //value at shoulder point
brightcurvePoints.at(6) = min(1.0, 0.7 + br / 300.0); //value at shoulder point
} else {
brightcurvePoints.at(3) = 0.1-br/150.0; // toe point
brightcurvePoints.at(3) = 0.1 - br / 150.0; // toe point
brightcurvePoints.at(4) = 0.1; // value at toe point
brightcurvePoints.at(5) = min(1.0,0.7-br/300.0); // shoulder point
brightcurvePoints.at(5) = min(1.0, 0.7 - br / 300.0); // shoulder point
brightcurvePoints.at(6) = 0.7; // value at shoulder point
}
brightcurvePoints.at(7) = 1.; // white point
brightcurvePoints.at(8) = 1.; // value at white point
DiagonalCurve* brightcurve = new DiagonalCurve (brightcurvePoints, CURVES_MIN_POLY_POINTS/skip);
DiagonalCurve* brightcurve = new DiagonalCurve (brightcurvePoints, CURVES_MIN_POLY_POINTS / skip);
// Applying brightness curve
for (int i=0; i<32768; i++) {
for (int i = 0; i < 32768; i++) {
// change to [0,1] range
float val = (float)i / 32767.0;
@@ -115,27 +123,30 @@ void Ciecam02::curveJ (double br, double contr, int db, LUTf & outCurve, LUTu &
// store result in a temporary array
dcurve[i] = CLIPD(val);
}
delete brightcurve;
} else {
// for (int i=0; i<32768; i++) { // L values range up to 32767, higher values are for highlight overflow
for (int i=0; i<(32768*db); i++) { // L values range up to 32767, higher values are for highlight overflow
// for (int i=0; i<32768; i++) { // L values range up to 32767, higher values are for highlight overflow
for (int i = 0; i < (32768 * db); i++) { // L values range up to 32767, higher values are for highlight overflow
// set the identity curve in the temporary array
dcurve[i] = (float)i / (db*32768.0f);
dcurve[i] = (float)i / (db * 32768.0f);
}
}
if (contr>0.00001 || contr<-0.00001) {
if (contr > 0.00001 || contr < -0.00001) {
// compute mean luminance of the image with the curve applied
int sum = 0;
float avg = 0;
//float sqavg = 0;
for (int i=0; i<32768; i++) {
for (int i = 0; i < 32768; i++) {
avg += dcurve[i] * histogram[i];//approximation for average : usage of L (lab) instead of J
sum += histogram[i];
}
avg /= sum;
std::vector<double> contrastcurvePoints;
contrastcurvePoints.resize(9);
@@ -144,19 +155,19 @@ void Ciecam02::curveJ (double br, double contr, int db, LUTf & outCurve, LUTu &
contrastcurvePoints.at(1) = 0.; // black point. Value in [0 ; 1] range
contrastcurvePoints.at(2) = 0.; // black point. Value in [0 ; 1] range
contrastcurvePoints.at(3) = avg-avg*(0.6-contr/250.0); // toe point
contrastcurvePoints.at(4) = avg-avg*(0.6+contr/250.0); // value at toe point
contrastcurvePoints.at(3) = avg - avg * (0.6 - contr / 250.0); // toe point
contrastcurvePoints.at(4) = avg - avg * (0.6 + contr / 250.0); // value at toe point
contrastcurvePoints.at(5) = avg+(1-avg)*(0.6-contr/250.0); // shoulder point
contrastcurvePoints.at(6) = avg+(1-avg)*(0.6+contr/250.0); // value at shoulder point
contrastcurvePoints.at(5) = avg + (1 - avg) * (0.6 - contr / 250.0); // shoulder point
contrastcurvePoints.at(6) = avg + (1 - avg) * (0.6 + contr / 250.0); // value at shoulder point
contrastcurvePoints.at(7) = 1.; // white point
contrastcurvePoints.at(8) = 1.; // value at white point
DiagonalCurve* contrastcurve = new DiagonalCurve (contrastcurvePoints, CURVES_MIN_POLY_POINTS/skip);
DiagonalCurve* contrastcurve = new DiagonalCurve (contrastcurvePoints, CURVES_MIN_POLY_POINTS / skip);
// apply contrast enhancement
for (int i=0; i<(32768*db); i++) {
for (int i = 0; i < (32768 * db); i++) {
dcurve[i] = contrastcurve->getVal (dcurve[i]);
}
@@ -164,16 +175,18 @@ void Ciecam02::curveJ (double br, double contr, int db, LUTf & outCurve, LUTu &
}
// for (int i=0; i<32768; i++) outCurve[i] = 32768.0*dcurve[i];
for (int i=0; i<(db*32768); i++) { outCurve[i] = db*32768.0*dcurve[i]; }
for (int i = 0; i < (db * 32768); i++) {
outCurve[i] = db * 32768.0 * dcurve[i];
}
}
void Ciecam02::curveJfloat (float br, float contr, int db, LUTf & outCurve, LUTu & histogram )
{
LUTf dcurve(65536,0);
int skip=1;
LUTf dcurve(65536, 0);
int skip = 1;
// check if brightness curve is needed
if (br>0.00001f || br<-0.00001f) {
if (br > 0.00001f || br < -0.00001f) {
std::vector<double> brightcurvePoints;
brightcurvePoints.resize(9);
@@ -182,26 +195,27 @@ void Ciecam02::curveJfloat (float br, float contr, int db, LUTf & outCurve, LUTu
brightcurvePoints.at(1) = 0.f; // black point. Value in [0 ; 1] range
brightcurvePoints.at(2) = 0.f; // black point. Value in [0 ; 1] range
if (br>0) {
if (br > 0) {
brightcurvePoints.at(3) = 0.1f; // toe point
brightcurvePoints.at(4) = 0.1f+br/150.0f; //value at toe point
brightcurvePoints.at(4) = 0.1f + br / 150.0f; //value at toe point
brightcurvePoints.at(5) = 0.7f; // shoulder point
brightcurvePoints.at(6) = min(1.0f,0.7f+br/300.0f); //value at shoulder point
brightcurvePoints.at(6) = min(1.0f, 0.7f + br / 300.0f); //value at shoulder point
} else {
brightcurvePoints.at(3) = 0.1f-br/150.0f; // toe point
brightcurvePoints.at(3) = 0.1f - br / 150.0f; // toe point
brightcurvePoints.at(4) = 0.1f; // value at toe point
brightcurvePoints.at(5) = min(1.0f,0.7f-br/300.0f); // shoulder point
brightcurvePoints.at(5) = min(1.0f, 0.7f - br / 300.0f); // shoulder point
brightcurvePoints.at(6) = 0.7f; // value at shoulder point
}
brightcurvePoints.at(7) = 1.f; // white point
brightcurvePoints.at(8) = 1.f; // value at white point
DiagonalCurve* brightcurve = new DiagonalCurve (brightcurvePoints, CURVES_MIN_POLY_POINTS/skip);
DiagonalCurve* brightcurve = new DiagonalCurve (brightcurvePoints, CURVES_MIN_POLY_POINTS / skip);
// Applying brightness curve
for (int i=0; i<32768; i++) {
for (int i = 0; i < 32768; i++) {
// change to [0,1] range
float val = (float)i / 32767.0f;
@@ -212,27 +226,30 @@ void Ciecam02::curveJfloat (float br, float contr, int db, LUTf & outCurve, LUTu
// store result in a temporary array
dcurve[i] = CLIPD(val);
}
delete brightcurve;
} else {
// for (int i=0; i<32768; i++) { // L values range up to 32767, higher values are for highlight overflow
for (int i=0; i<(32768*db); i++) { // L values range up to 32767, higher values are for highlight overflow
// for (int i=0; i<32768; i++) { // L values range up to 32767, higher values are for highlight overflow
for (int i = 0; i < (32768 * db); i++) { // L values range up to 32767, higher values are for highlight overflow
// set the identity curve in the temporary array
dcurve[i] = (float)i / (db*32768.0f);
dcurve[i] = (float)i / (db * 32768.0f);
}
}
if (contr>0.00001f || contr<-0.00001f) {
if (contr > 0.00001f || contr < -0.00001f) {
// compute mean luminance of the image with the curve applied
int sum = 0;
float avg = 0;
//float sqavg = 0;
for (int i=0; i<32768; i++) {
for (int i = 0; i < 32768; i++) {
avg += dcurve[i] * histogram[i];//approximation for average : usage of L (lab) instead of J
sum += histogram[i];
}
avg /= sum;
//printf("avg=%f\n",avg);
std::vector<double> contrastcurvePoints;
@@ -242,19 +259,19 @@ void Ciecam02::curveJfloat (float br, float contr, int db, LUTf & outCurve, LUTu
contrastcurvePoints.at(1) = 0.f; // black point. Value in [0 ; 1] range
contrastcurvePoints.at(2) = 0.f; // black point. Value in [0 ; 1] range
contrastcurvePoints.at(3) = avg-avg*(0.6f-contr/250.0f); // toe point
contrastcurvePoints.at(4) = avg-avg*(0.6f+contr/250.0f); // value at toe point
contrastcurvePoints.at(3) = avg - avg * (0.6f - contr / 250.0f); // toe point
contrastcurvePoints.at(4) = avg - avg * (0.6f + contr / 250.0f); // value at toe point
contrastcurvePoints.at(5) = avg+(1-avg)*(0.6f-contr/250.0f); // shoulder point
contrastcurvePoints.at(6) = avg+(1-avg)*(0.6f+contr/250.0f); // value at shoulder point
contrastcurvePoints.at(5) = avg + (1 - avg) * (0.6f - contr / 250.0f); // shoulder point
contrastcurvePoints.at(6) = avg + (1 - avg) * (0.6f + contr / 250.0f); // value at shoulder point
contrastcurvePoints.at(7) = 1.f; // white point
contrastcurvePoints.at(8) = 1.f; // value at white point
DiagonalCurve* contrastcurve = new DiagonalCurve (contrastcurvePoints, CURVES_MIN_POLY_POINTS/skip);
DiagonalCurve* contrastcurve = new DiagonalCurve (contrastcurvePoints, CURVES_MIN_POLY_POINTS / skip);
// apply contrast enhancement
for (int i=0; i<(32768*db); i++) {
for (int i = 0; i < (32768 * db); i++) {
dcurve[i] = contrastcurve->getVal (dcurve[i]);
}
@@ -262,7 +279,9 @@ void Ciecam02::curveJfloat (float br, float contr, int db, LUTf & outCurve, LUTu
}
// for (int i=0; i<32768; i++) outCurve[i] = 32768.0*dcurve[i];
for (int i=0; i<(db*32768); i++) { outCurve[i] = db*32768.0f*dcurve[i]; }
for (int i = 0; i < (db * 32768); i++) {
outCurve[i] = db * 32768.0f * dcurve[i];
}
}
/**
@@ -330,7 +349,7 @@ double Ciecam02::achromatic_response_to_white( double x, double y, double z, dou
double rc, gc, bc;
double rp, gp, bp;
double rpa, gpa, bpa;
gamu=1;
gamu = 1;
xyz_to_cat02( r, g, b, x, y, z, gamu );
rc = r * (((y * d) / r) + (1.0 - d));
@@ -338,10 +357,11 @@ double Ciecam02::achromatic_response_to_white( double x, double y, double z, dou
bc = b * (((y * d) / b) + (1.0 - d));
cat02_to_hpe( rp, gp, bp, rc, gc, bc, gamu );
if (gamu==1) { //gamut correction M.H.Brill S.Susstrunk
rp=MAXR(rp,0.0);
gp=MAXR(gp,0.0);
bp=MAXR(bp,0.0);
if (gamu == 1) { //gamut correction M.H.Brill S.Susstrunk
rp = MAXR(rp, 0.0);
gp = MAXR(gp, 0.0);
bp = MAXR(bp, 0.0);
}
rpa = nonlinear_adaptation( rp, fl );
@@ -357,7 +377,7 @@ float Ciecam02::achromatic_response_to_whitefloat( float x, float y, float z, fl
float rc, gc, bc;
float rp, gp, bp;
float rpa, gpa, bpa;
gamu=1;
gamu = 1;
xyz_to_cat02float( r, g, b, x, y, z, gamu );
rc = r * (((y * d) / r) + (1.0f - d));
@@ -365,10 +385,11 @@ float Ciecam02::achromatic_response_to_whitefloat( float x, float y, float z, fl
bc = b * (((y * d) / b) + (1.0f - d));
cat02_to_hpefloat( rp, gp, bp, rc, gc, bc, gamu );
if (gamu==1) { //gamut correction M.H.Brill S.Susstrunk
rp=MAXR(rp,0.0f);
gp=MAXR(gp,0.0f);
bp=MAXR(bp,0.0f);
if (gamu == 1) { //gamut correction M.H.Brill S.Susstrunk
rp = MAXR(rp, 0.0f);
gp = MAXR(gp, 0.0f);
bp = MAXR(bp, 0.0f);
}
rpa = nonlinear_adaptationfloat( rp, fl );
@@ -380,16 +401,17 @@ float Ciecam02::achromatic_response_to_whitefloat( float x, float y, float z, fl
void Ciecam02::xyz_to_cat02( double &r, double &g, double &b, double x, double y, double z, int gamu )
{
gamu=1;
if (gamu==0) {
gamu = 1;
if (gamu == 0) {
r = ( 0.7328 * x) + (0.4296 * y) - (0.1624 * z);
g = (-0.7036 * x) + (1.6975 * y) + (0.0061 * z);
b = ( 0.0030 * x) + (0.0136 * y) + (0.9834 * z);
} else if (gamu==1) { //gamut correction M.H.Brill S.Susstrunk
} else if (gamu == 1) { //gamut correction M.H.Brill S.Susstrunk
//r = ( 0.7328 * x) + (0.4296 * y) - (0.1624 * z);
//g = (-0.7036 * x) + (1.6975 * y) + (0.0061 * z);
//b = ( 0.0000 * x) + (0.0000 * y) + (1.0000 * z);
r = ( 1.007245 * x) + (0.011136* y) - (0.018381 * z);//Changjun Li
r = ( 1.007245 * x) + (0.011136 * y) - (0.018381 * z); //Changjun Li
g = (-0.318061 * x) + (1.314589 * y) + (0.003471 * z);
b = ( 0.0000 * x) + (0.0000 * y) + (1.0000 * z);
}
@@ -397,16 +419,17 @@ void Ciecam02::xyz_to_cat02( double &r, double &g, double &b, double x, double y
void Ciecam02::xyz_to_cat02float( float &r, float &g, float &b, float x, float y, float z, int gamu )
{
gamu=1;
if (gamu==0) {
gamu = 1;
if (gamu == 0) {
r = ( 0.7328f * x) + (0.4296f * y) - (0.1624f * z);
g = (-0.7036f * x) + (1.6975f * y) + (0.0061f * z);
b = ( 0.0030f * x) + (0.0136f * y) + (0.9834f * z);
} else if (gamu==1) { //gamut correction M.H.Brill S.Susstrunk
} else if (gamu == 1) { //gamut correction M.H.Brill S.Susstrunk
//r = ( 0.7328 * x) + (0.4296 * y) - (0.1624 * z);
//g = (-0.7036 * x) + (1.6975 * y) + (0.0061 * z);
//b = ( 0.0000 * x) + (0.0000 * y) + (1.0000 * z);
r = ( 1.007245f * x) + (0.011136f* y) - (0.018381f * z);//Changjun Li
r = ( 1.007245f * x) + (0.011136f * y) - (0.018381f * z); //Changjun Li
g = (-0.318061f * x) + (1.314589f * y) + (0.003471f * z);
b = ( 0.0000f * x) + (0.0000f * y) + (1.0000f * z);
}
@@ -423,17 +446,18 @@ void Ciecam02::xyz_to_cat02float( vfloat &r, vfloat &g, vfloat &b, vfloat x, vfl
void Ciecam02::cat02_to_xyz( double &x, double &y, double &z, double r, double g, double b, int gamu )
{
gamu=1;
if (gamu==0) {
gamu = 1;
if (gamu == 0) {
x = ( 1.096124 * r) - (0.278869 * g) + (0.182745 * b);
y = ( 0.454369 * r) + (0.473533 * g) + (0.072098 * b);
z = (-0.009628 * r) - (0.005698 * g) + (1.015326 * b);
} else if (gamu==1) { //gamut correction M.H.Brill S.Susstrunk
} else if (gamu == 1) { //gamut correction M.H.Brill S.Susstrunk
//x = ( 1.0978566 * r) - (0.277843 * g) + (0.179987 * b);
//y = ( 0.455053 * r) + (0.473938 * g) + (0.0710096* b);
//z = ( 0.000000 * r) - (0.000000 * g) + (1.000000 * b);
x = ( 0.99015849 * r) - (0.00838772* g) + (0.018229217 * b);//Changjun Li
y = ( 0.239565979 * r) + (0.758664642 * g) + (0.001770137* b);
x = ( 0.99015849 * r) - (0.00838772 * g) + (0.018229217 * b); //Changjun Li
y = ( 0.239565979 * r) + (0.758664642 * g) + (0.001770137 * b);
z = ( 0.000000 * r) - (0.000000 * g) + (1.000000 * b);
}
}
@@ -441,17 +465,18 @@ void Ciecam02::cat02_to_xyz( double &x, double &y, double &z, double r, double g
#ifndef __SSE2__
void Ciecam02::cat02_to_xyzfloat( float &x, float &y, float &z, float r, float g, float b, int gamu )
{
gamu=1;
if (gamu==0) {
gamu = 1;
if (gamu == 0) {
x = ( 1.096124f * r) - (0.278869f * g) + (0.182745f * b);
y = ( 0.454369f * r) + (0.473533f * g) + (0.072098f * b);
z = (-0.009628f * r) - (0.005698f * g) + (1.015326f * b);
} else if (gamu==1) { //gamut correction M.H.Brill S.Susstrunk
} else if (gamu == 1) { //gamut correction M.H.Brill S.Susstrunk
//x = ( 1.0978566 * r) - (0.277843 * g) + (0.179987 * b);
//y = ( 0.455053 * r) + (0.473938 * g) + (0.0710096* b);
//z = ( 0.000000 * r) - (0.000000 * g) + (1.000000 * b);
x = ( 0.99015849f * r) - (0.00838772f* g) + (0.018229217f * b);//Changjun Li
y = ( 0.239565979f * r) + (0.758664642f * g) + (0.001770137f* b);
x = ( 0.99015849f * r) - (0.00838772f * g) + (0.018229217f * b); //Changjun Li
y = ( 0.239565979f * r) + (0.758664642f * g) + (0.001770137f * b);
z = ( 0.000000f * r) - (0.000000f * g) + (1.000000f * b);
}
}
@@ -459,8 +484,8 @@ void Ciecam02::cat02_to_xyzfloat( float &x, float &y, float &z, float r, float g
void Ciecam02::cat02_to_xyzfloat( vfloat &x, vfloat &y, vfloat &z, vfloat r, vfloat g, vfloat b )
{
//gamut correction M.H.Brill S.Susstrunk
x = ( F2V(0.99015849f) * r) - (F2V(0.00838772f)* g) + (F2V(0.018229217f) * b);//Changjun Li
y = ( F2V(0.239565979f) * r) + (F2V(0.758664642f) * g) + (F2V(0.001770137f)* b);
x = ( F2V(0.99015849f) * r) - (F2V(0.00838772f) * g) + (F2V(0.018229217f) * b); //Changjun Li
y = ( F2V(0.239565979f) * r) + (F2V(0.758664642f) * g) + (F2V(0.001770137f) * b);
z = b;
}
#endif
@@ -490,29 +515,31 @@ void Ciecam02::hpe_to_xyzfloat( vfloat &x, vfloat &y, vfloat &z, vfloat r, vfloa
void Ciecam02::cat02_to_hpe( double &rh, double &gh, double &bh, double r, double g, double b, int gamu )
{
gamu=1;
if (gamu==0) {
gamu = 1;
if (gamu == 0) {
rh = ( 0.7409792 * r) + (0.2180250 * g) + (0.0410058 * b);
gh = ( 0.2853532 * r) + (0.6242014 * g) + (0.0904454 * b);
bh = (-0.0096280 * r) - (0.0056980 * g) + (1.0153260 * b);
} else if (gamu==1) { //Changjun Li
rh = ( 0.550930835 * r) + (0.519435987* g) - ( 0.070356303* b);
} else if (gamu == 1) { //Changjun Li
rh = ( 0.550930835 * r) + (0.519435987 * g) - ( 0.070356303 * b);
gh = ( 0.055954056 * r) + (0.89973132 * g) + (0.044315524 * b);
bh = (0.0 * r) - (0.0* g) + (1.0 * b);
bh = (0.0 * r) - (0.0 * g) + (1.0 * b);
}
}
void Ciecam02::cat02_to_hpefloat( float &rh, float &gh, float &bh, float r, float g, float b, int gamu )
{
gamu=1;
if (gamu==0) {
gamu = 1;
if (gamu == 0) {
rh = ( 0.7409792f * r) + (0.2180250f * g) + (0.0410058f * b);
gh = ( 0.2853532f * r) + (0.6242014f * g) + (0.0904454f * b);
bh = (-0.0096280f * r) - (0.0056980f * g) + (1.0153260f * b);
} else if (gamu==1) { //Changjun Li
rh = ( 0.550930835f * r) + (0.519435987f* g) - ( 0.070356303f* b);
} else if (gamu == 1) { //Changjun Li
rh = ( 0.550930835f * r) + (0.519435987f * g) - ( 0.070356303f * b);
gh = ( 0.055954056f * r) + (0.89973132f * g) + (0.044315524f * b);
bh = (0.0f * r) - (0.0f* g) + (1.0f * b);
bh = (0.0f * r) - (0.0f * g) + (1.0f * b);
}
}
@@ -520,7 +547,7 @@ void Ciecam02::cat02_to_hpefloat( float &rh, float &gh, float &bh, float r, floa
void Ciecam02::cat02_to_hpefloat( vfloat &rh, vfloat &gh, vfloat &bh, vfloat r, vfloat g, vfloat b)
{
//Changjun Li
rh = ( F2V(0.550930835f) * r) + (F2V(0.519435987f)* g) - ( F2V(0.070356303f)* b);
rh = ( F2V(0.550930835f) * r) + (F2V(0.519435987f) * g) - ( F2V(0.070356303f) * b);
gh = ( F2V(0.055954056f) * r) + (F2V(0.89973132f) * g) + (F2V(0.044315524f) * b);
bh = b;
}
@@ -570,12 +597,13 @@ void Ciecam02::calculate_ab( double &aa, double &bb, double h, double e, double
double sinh = sin( hrad );
double cosh = cos( hrad );
double x = (a / nbb) + 0.305;
double p3 = 21.0/20.0;
double p3 = 21.0 / 20.0;
if ( fabs( sinh ) >= fabs( cosh ) ) {
bb = ((0.32787 * x) * (2.0 + p3)) /
((e / (t * sinh)) -
// ((0.32145 - 0.63507 - (p3 * 0.15681)) * (cosh / sinh)) -
// (0.20527 - 0.18603 - (p3 * 4.49038)));
// ((0.32145 - 0.63507 - (p3 * 0.15681)) * (cosh / sinh)) -
// (0.20527 - 0.18603 - (p3 * 4.49038)));
((-0.31362 - (p3 * 0.15681)) * (cosh / sinh)) -
(0.01924 - (p3 * 4.49038)));
@@ -583,8 +611,8 @@ void Ciecam02::calculate_ab( double &aa, double &bb, double h, double e, double
} else {
aa = ((0.32787 * x) * (2.0 + p3)) /
((e / (t * cosh)) -
// (0.32145 - 0.63507 - (p3 * 0.15681)) -
// ((0.20527 - 0.18603 - (p3 * 4.49038)) * (sinh / cosh)));
// (0.32145 - 0.63507 - (p3 * 0.15681)) -
// ((0.20527 - 0.18603 - (p3 * 4.49038)) * (sinh / cosh)));
(-0.31362 - (p3 * 0.15681)) -
((0.01924 - (p3 * 4.49038)) * (sinh / cosh)));
@@ -600,14 +628,16 @@ void Ciecam02::calculate_abfloat( float &aa, float &bb, float h, float e, float
float x = (a / nbb) + 0.305f;
float p3 = 1.05f;
bool swapValues = fabs( sinh ) > fabs( cosh );
if (swapValues) {
std::swap(sinh,cosh);
std::swap(sinh, cosh);
}
float c1 = 1.f;
float c2 = sinh / cosh;
if (swapValues) {
std::swap(c1,c2);
std::swap(c1, c2);
}
float div = ((e / (t * cosh)) - (-0.31362f - (p3 * 0.15681f)) * c1 - ((0.01924f - (p3 * 4.49038f)) * (c2)));
@@ -624,7 +654,7 @@ void Ciecam02::calculate_abfloat( float &aa, float &bb, float h, float e, float
bb = (aa * sinh) / cosh;
if (swapValues) {
std::swap(aa,bb);
std::swap(aa, bb);
}
}
#else
@@ -638,9 +668,9 @@ void Ciecam02::calculate_abfloat( vfloat &aa, vfloat &bb, vfloat h, vfloat e, vf
vmask swapMask = vmaskf_gt(vabsf(sinh), vabsf(cosh));
vswap(swapMask, sinh, cosh);
vfloat c1 = F2V(1.f);
vfloat c2 = sinh/cosh;
vfloat c2 = sinh / cosh;
vswap(swapMask, c1, c2);
vfloat div = ((e / (t * cosh)) - (F2V(-0.31362f) - (p3 * F2V(0.15681f))) * c1 - ((F2V(0.01924f) - (p3 * F2V(4.49038f))) * (c2)));
// for large values of t the above calculation can change its sign which results in a hue shift of 180 degree
// so we have to check the sign to avoid this shift.
@@ -663,16 +693,25 @@ void Ciecam02::initcam1(double gamu, double yb, double pilotd, double f, double
double &cz, double &aw, double &wh, double &pfl, double &fl, double &c)
{
n = yb / yw;
if (pilotd==2.0) { d = d_factor( f, la ); }
else { d=pilotd; }
if (pilotd == 2.0) {
d = d_factor( f, la );
} else {
d = pilotd;
}
fl = calculate_fl_from_la_ciecam02( la );
nbb = ncb = 0.725 * pow( 1.0 / n, 0.2 );
cz = 1.48 + sqrt( n );
aw = achromatic_response_to_white( xw, yw, zw, d, fl, nbb, gamu );
wh =( 4.0 / c ) * ( aw + 4.0 ) * pow( fl, 0.25 );
wh = ( 4.0 / c ) * ( aw + 4.0 ) * pow( fl, 0.25 );
pfl = pow( fl, 0.25 );
#ifdef _DEBUG
if (settings->verbose) { printf("Source double d=%f aw=%f fl=%f wh=%f\n",d,aw,fl,wh); }
if (settings->verbose) {
printf("Source double d=%f aw=%f fl=%f wh=%f\n", d, aw, fl, wh);
}
#endif
}
@@ -680,16 +719,25 @@ void Ciecam02::initcam1float(float gamu, float yb, float pilotd, float f, float
float &cz, float &aw, float &wh, float &pfl, float &fl, float &c)
{
n = yb / yw;
if (pilotd==2.0) { d = d_factorfloat( f, la ); }
else { d=pilotd; }
if (pilotd == 2.0) {
d = d_factorfloat( f, la );
} else {
d = pilotd;
}
fl = calculate_fl_from_la_ciecam02float( la );
nbb = ncb = 0.725f * pow_F( 1.0f / n, 0.2f );
cz = 1.48f + sqrt( n );
aw = achromatic_response_to_whitefloat( xw, yw, zw, d, fl, nbb, gamu );
wh =( 4.0f / c ) * ( aw + 4.0f ) * pow_F( fl, 0.25f );
wh = ( 4.0f / c ) * ( aw + 4.0f ) * pow_F( fl, 0.25f );
pfl = pow_F( fl, 0.25f );
#ifdef _DEBUG
if (settings->verbose) { printf("Source float d=%f aw=%f fl=%f wh=%f c=%f awc=%f\n",d,aw,fl,wh,c,(4.f/c)*(aw+4.f)); }
if (settings->verbose) {
printf("Source float d=%f aw=%f fl=%f wh=%f c=%f awc=%f\n", d, aw, fl, wh, c, (4.f / c) * (aw + 4.f));
}
#endif
}
@@ -703,7 +751,11 @@ void Ciecam02::initcam2(double gamu, double yb, double f, double la, double xw,
cz = 1.48 + sqrt( n );
aw = achromatic_response_to_white( xw, yw, zw, d, fl, nbb, gamu );
#ifdef _DEBUG
if (settings->verbose) { printf("Viewing double d=%f aw=%f fl=%f n=%f\n",d,aw,fl,n); }
if (settings->verbose) {
printf("Viewing double d=%f aw=%f fl=%f n=%f\n", d, aw, fl, n);
}
#endif
}
@@ -717,11 +769,15 @@ void Ciecam02::initcam2float(float gamu, float yb, float f, float la, float xw,
cz = 1.48f + sqrt( n );
aw = achromatic_response_to_whitefloat( xw, yw, zw, d, fl, nbb, gamu );
#ifdef _DEBUG
if (settings->verbose) { printf("Viewing float d=%f aw=%f fl=%f n=%f\n",d,aw,fl,n); }
if (settings->verbose) {
printf("Viewing float d=%f aw=%f fl=%f n=%f\n", d, aw, fl, n);
}
#endif
}
void Ciecam02::xyz2jchqms_ciecam02( double &J, double &C, double &h, double &Q, double &M, double &s,double &aw, double &fl, double &wh,
void Ciecam02::xyz2jchqms_ciecam02( double &J, double &C, double &h, double &Q, double &M, double &s, double &aw, double &fl, double &wh,
double x, double y, double z, double xw, double yw, double zw,
double yb, double la, double f, double c, double nc, double pilotd, int gamu , double n, double nbb, double ncb, double pfl, double cz, double d)
{
@@ -733,7 +789,7 @@ void Ciecam02::xyz2jchqms_ciecam02( double &J, double &C, double &h, double &Q,
double a, ca, cb;
double e, t;
double myh;
gamu=1;
gamu = 1;
xyz_to_cat02( r, g, b, x, y, z, gamu );
xyz_to_cat02( rw, gw, bw, xw, yw, zw, gamu );
rc = r * (((yw * d) / rw) + (1.0 - d));
@@ -741,11 +797,13 @@ void Ciecam02::xyz2jchqms_ciecam02( double &J, double &C, double &h, double &Q,
bc = b * (((yw * d) / bw) + (1.0 - d));
cat02_to_hpe( rp, gp, bp, rc, gc, bc, gamu );
if (gamu==1) { //gamut correction M.H.Brill S.Susstrunk
rp=MAXR(rp,0.0);
gp=MAXR(gp,0.0);
bp=MAXR(bp,0.0);
if (gamu == 1) { //gamut correction M.H.Brill S.Susstrunk
rp = MAXR(rp, 0.0);
gp = MAXR(gp, 0.0);
bp = MAXR(bp, 0.0);
}
rpa = nonlinear_adaptation( rp, fl );
gpa = nonlinear_adaptation( gp, fl );
bpa = nonlinear_adaptation( bp, fl );
@@ -754,7 +812,11 @@ void Ciecam02::xyz2jchqms_ciecam02( double &J, double &C, double &h, double &Q,
cb = (1.0 / 9.0) * (rpa + gpa - (2.0 * bpa));
myh = (180.0 / M_PI) * atan2( cb, ca );
if ( myh < 0.0 ) { myh += 360.0; }
if ( myh < 0.0 ) {
myh += 360.0;
}
//we can also calculate H, if necessary...but it's using time...for what usage ?
/*double temp;
if(myh<20.14) {
@@ -779,7 +841,11 @@ void Ciecam02::xyz2jchqms_ciecam02( double &J, double &C, double &h, double &Q,
}
*/
a = ((2.0 * rpa) + gpa + ((1.0 / 20.0) * bpa) - 0.305) * nbb;
if (gamu==1) { a=MAXR(a,0.0); }//gamut correction M.H.Brill S.Susstrunk
if (gamu == 1) {
a = MAXR(a, 0.0); //gamut correction M.H.Brill S.Susstrunk
}
J = 100.0 * pow( a / aw, c * cz );
e = ((12500.0 / 13.0) * nc * ncb) * (cos( ((myh * M_PI) / 180.0) + 2.0 ) + 3.8);
@@ -794,7 +860,7 @@ void Ciecam02::xyz2jchqms_ciecam02( double &J, double &C, double &h, double &Q,
h = myh;
}
void Ciecam02::xyz2jchqms_ciecam02float( float &J, float &C, float &h, float &Q, float &M, float &s,float &aw, float &fl, float &wh,
void Ciecam02::xyz2jchqms_ciecam02float( float &J, float &C, float &h, float &Q, float &M, float &s, float &aw, float &fl, float &wh,
float x, float y, float z, float xw, float yw, float zw,
float yb, float la, float f, float c, float nc, float pilotd, int gamu, float pow1, float nbb, float ncb, float pfl, float cz, float d)
@@ -807,7 +873,7 @@ void Ciecam02::xyz2jchqms_ciecam02float( float &J, float &C, float &h, float &Q,
float a, ca, cb;
float e, t;
float myh;
gamu=1;
gamu = 1;
xyz_to_cat02float( r, g, b, x, y, z, gamu );
xyz_to_cat02float( rw, gw, bw, xw, yw, zw, gamu );
rc = r * (((yw * d) / rw) + (1.0 - d));
@@ -815,11 +881,13 @@ void Ciecam02::xyz2jchqms_ciecam02float( float &J, float &C, float &h, float &Q,
bc = b * (((yw * d) / bw) + (1.0 - d));
cat02_to_hpefloat( rp, gp, bp, rc, gc, bc, gamu );
if (gamu==1) { //gamut correction M.H.Brill S.Susstrunk
rp=MAXR(rp,0.0f);
gp=MAXR(gp,0.0f);
bp=MAXR(bp,0.0f);
if (gamu == 1) { //gamut correction M.H.Brill S.Susstrunk
rp = MAXR(rp, 0.0f);
gp = MAXR(gp, 0.0f);
bp = MAXR(bp, 0.0f);
}
rpa = nonlinear_adaptationfloat( rp, fl );
gpa = nonlinear_adaptationfloat( gp, fl );
bpa = nonlinear_adaptationfloat( bp, fl );
@@ -828,13 +896,15 @@ void Ciecam02::xyz2jchqms_ciecam02float( float &J, float &C, float &h, float &Q,
cb = (0.11111111f) * (rpa + gpa - (2.0f * bpa));
myh = xatan2f( cb, ca );
if ( myh < 0.0f ) {
myh += (2.f * M_PI);
}
a = ((2.0f * rpa) + gpa + (0.05f * bpa) - 0.305f) * nbb;
if (gamu==1) {
a=MAXR(a,0.0f); //gamut correction M.H.Brill S.Susstrunk
if (gamu == 1) {
a = MAXR(a, 0.0f); //gamut correction M.H.Brill S.Susstrunk
}
J = pow_F( a / aw, c * cz * 0.5f);
@@ -874,9 +944,9 @@ void Ciecam02::xyz2jchqms_ciecam02float( vfloat &J, vfloat &C, vfloat &h, vfloat
cat02_to_hpefloat( rp, gp, bp, rc, gc, bc);
//gamut correction M.H.Brill S.Susstrunk
rp = _mm_max_ps(rp,ZEROV);
gp = _mm_max_ps(gp,ZEROV);
bp = _mm_max_ps(bp,ZEROV);
rp = _mm_max_ps(rp, ZEROV);
gp = _mm_max_ps(gp, ZEROV);
bp = _mm_max_ps(bp, ZEROV);
rpa = nonlinear_adaptationfloat( rp, fl );
gpa = nonlinear_adaptationfloat( gp, fl );
bpa = nonlinear_adaptationfloat( bp, fl );
@@ -891,7 +961,7 @@ void Ciecam02::xyz2jchqms_ciecam02float( vfloat &J, vfloat &C, vfloat &h, vfloat
myh = vself(vmaskf_lt(myh, ZEROV), temp, myh);
a = ((rpa + rpa) + gpa + (F2V(0.05f) * bpa) - F2V(0.305f)) * nbb;
a = _mm_max_ps(a,ZEROV); //gamut correction M.H.Brill S.Susstrunk
a = _mm_max_ps(a, ZEROV); //gamut correction M.H.Brill S.Susstrunk
J = pow_F( a / aw, c * cz * F2V(0.5f));
@@ -903,7 +973,7 @@ void Ciecam02::xyz2jchqms_ciecam02float( vfloat &J, vfloat &C, vfloat &h, vfloat
Q = wh * J;
J *= J * F2V(100.0f);
M = C * pfl;
Q = _mm_max_ps(Q,F2V(0.0001f)); // avoid division by zero
Q = _mm_max_ps(Q, F2V(0.0001f)); // avoid division by zero
s = F2V(100.0f) * _mm_sqrt_ps( M / Q );
h = (myh * F2V(180.f)) / F2V(M_PI);
}
@@ -920,7 +990,7 @@ void Ciecam02::jch2xyz_ciecam02( double &x, double &y, double &z, double J, doub
double rw, gw, bw;
double a, ca, cb;
double e, t;
gamu=1;
gamu = 1;
xyz_to_cat02( rw, gw, bw, xw, yw, zw, gamu );
e = ((12500.0 / 13.0) * nc * ncb) * (cos( ((h * M_PI) / 180.0) + 2.0 ) + 3.8);
a = pow( J / 100.0, 1.0 / (c * cz) ) * aw;
@@ -954,7 +1024,7 @@ void Ciecam02::jch2xyz_ciecam02float( float &x, float &y, float &z, float J, flo
float rw, gw, bw;
float a, ca, cb;
float e, t;
gamu=1;
gamu = 1;
xyz_to_cat02float( rw, gw, bw, xw, yw, zw, gamu );
e = ((961.53846f) * nc * ncb) * (xcosf( ((h * M_PI) / 180.0f) + 2.0f ) + 3.8f);
a = pow_F( J / 100.0f, 1.0f / (c * cz) ) * aw;
@@ -1015,15 +1085,27 @@ void Ciecam02::jch2xyz_ciecam02float( vfloat &x, vfloat &y, vfloat &z, vfloat J,
double Ciecam02::nonlinear_adaptation( double c, double fl )
{
double p;
if (c<0.0) { p = pow( (-1.0*fl * c) / 100.0, 0.42 ); return ((-1.0*400.0 * p) / (27.13 + p)) + 0.1;}
else {p = pow( (fl * c) / 100.0, 0.42 ); return ((400.0 * p) / (27.13 + p)) + 0.1;}
if (c < 0.0) {
p = pow( (-1.0 * fl * c) / 100.0, 0.42 );
return ((-1.0 * 400.0 * p) / (27.13 + p)) + 0.1;
} else {
p = pow( (fl * c) / 100.0, 0.42 );
return ((400.0 * p) / (27.13 + p)) + 0.1;
}
}
float Ciecam02::nonlinear_adaptationfloat( float c, float fl )
{
float p;
if (c<0.0f) { p = pow_F( (-1.0f*fl * c) / 100.0f, 0.42f ); return ((-1.0f*400.0f * p) / (27.13f + p)) + 0.1f;}
else {p = pow_F( (fl * c) / 100.0f, 0.42f ); return ((400.0f * p) / (27.13f + p)) + 0.1f;}
if (c < 0.0f) {
p = pow_F( (-1.0f * fl * c) / 100.0f, 0.42f );
return ((-1.0f * 400.0f * p) / (27.13f + p)) + 0.1f;
} else {
p = pow_F( (fl * c) / 100.0f, 0.42f );
return ((400.0f * p) / (27.13f + p)) + 0.1f;
}
}
#ifdef __SSE2__
@@ -1031,8 +1113,8 @@ vfloat Ciecam02::nonlinear_adaptationfloat( vfloat c, vfloat fl )
{
vfloat c100 = F2V(100.f);
vfloat czd42 = F2V(0.42f);
vfloat c400 = vmulsignf(F2V(400.f),c);
fl = vmulsignf(fl,c);
vfloat c400 = vmulsignf(F2V(400.f), c);
fl = vmulsignf(fl, c);
vfloat p = pow_F( (fl * c) / c100, czd42 );
vfloat c27d13 = F2V(27.13);
vfloat czd1 = F2V(0.1f);
@@ -1043,23 +1125,31 @@ vfloat Ciecam02::nonlinear_adaptationfloat( vfloat c, vfloat fl )
double Ciecam02::inverse_nonlinear_adaptation( double c, double fl )
{
int c1;
if (c-0.1 < 0.0) { c1=-1; }
else { c1=1; }
return c1*(100.0 / fl) * pow( (27.13 * fabs( c - 0.1 )) / (400.0 - fabs( c - 0.1 )), 1.0 / 0.42 );
if (c - 0.1 < 0.0) {
c1 = -1;
} else {
c1 = 1;
}
return c1 * (100.0 / fl) * pow( (27.13 * fabs( c - 0.1 )) / (400.0 - fabs( c - 0.1 )), 1.0 / 0.42 );
}
#ifndef __SSE2__
float Ciecam02::inverse_nonlinear_adaptationfloat( float c, float fl )
{
c -= 0.1f;
if (c < 0.f) {
fl *= -1.f;
if (c < -399.99f) { // avoid nan values
c = -399.99f;
}
} else if (c > 399.99f) { // avoid nan values
c = 399.99f;
}
return (100.0f / fl) * pow_F( (27.13f * fabsf( c )) / (400.0f - fabsf( c )), 2.38095238f );
}
@@ -1067,7 +1157,7 @@ float Ciecam02::inverse_nonlinear_adaptationfloat( float c, float fl )
vfloat Ciecam02::inverse_nonlinear_adaptationfloat( vfloat c, vfloat fl )
{
c -= F2V(0.1f);
fl = vmulsignf(fl,c);
fl = vmulsignf(fl, c);
c = vabsf(c);
c = _mm_min_ps( c, F2V(399.99f));
return (F2V(100.0f) / fl) * pow_F( (F2V(27.13f) * c) / (F2V(400.0f) - c), F2V(2.38095238f) );