Cleaner implementation of the gamma array (more C++11)

This commit is contained in:
Hombre 2016-08-31 23:40:27 +02:00
parent 72db91b574
commit d31de41f68
9 changed files with 81 additions and 94 deletions

View File

@ -1469,13 +1469,13 @@ void Color::calcGamma (double pwr, double ts, int mode, int imax, GammaValues &g
}
if (!mode--) {
gamma.gamma0 = g[0];
gamma.gamma1 = g[1];
gamma.gamma2 = g[2];
gamma.gamma3 = g[3];
gamma.gamma4 = g[4];
gamma.gamma5 = g[5];
gamma.gamma6 = 0.;
gamma[0] = g[0];
gamma[1] = g[1];
gamma[2] = g[2];
gamma[3] = g[3];
gamma[4] = g[4];
gamma[5] = g[5];
gamma[6] = 0.;
return;
}
}

View File

@ -30,6 +30,8 @@
namespace rtengine
{
typedef std::array<double, 7> GammaValues;
#ifdef _DEBUG
class MunsellDebugInfo
@ -95,17 +97,6 @@ private:
#endif
public:
class GammaValues {
public:
double gamma0;
double gamma1;
double gamma2;
double gamma3;
double gamma4;
double gamma5;
double gamma6;
};
typedef enum Channel {
CHANNEL_RED = 1 << 0,
CHANNEL_GREEN = 1 << 1,

View File

@ -363,83 +363,79 @@ cmsHPROFILE ICCStore::workingSpaceGamma (const Glib::ustring& name) const
}
}
void ICCStore::getGammaArray(const procparams::ColorManagementParams &icm, Color::GammaValues &ga)
void ICCStore::getGammaArray(const procparams::ColorManagementParams &icm, GammaValues &ga)
{
const double eps = 0.000000001; // not divide by zero
if (!icm.freegamma) {//if Free gamma not selected
// gamma : ga[0],ga[1],ga[2],ga[3],ga[4],ga[5] by calcul
if(icm.gamma == "BT709_g2.2_s4.5") {
ga.gamma0 = 2.22; //BT709 2.2 4.5 - my preferred as D.Coffin
ga.gamma1 = 0.909995;
ga.gamma2 = 0.090005;
ga.gamma3 = 0.222222;
ga.gamma4 = 0.081071;
ga.gamma5 = 0.0;
ga[0] = 2.22; //BT709 2.2 4.5 - my preferred as D.Coffin
ga[1] = 0.909995;
ga[2] = 0.090005;
ga[3] = 0.222222;
ga[4] = 0.081071;
} else if (icm.gamma == "sRGB_g2.4_s12.92") {
ga.gamma0 = 2.40; //sRGB 2.4 12.92 - RT default as Lightroom
ga.gamma1 = 0.947858;
ga.gamma2 = 0.052142;
ga.gamma3 = 0.077399;
ga.gamma4 = 0.039293;
ga.gamma5 = 0.0;
ga[0] = 2.40; //sRGB 2.4 12.92 - RT default as Lightroom
ga[1] = 0.947858;
ga[2] = 0.052142;
ga[3] = 0.077399;
ga[4] = 0.039293;
} else if (icm.gamma == "High_g1.3_s3.35") {
ga.gamma0 = 1.3 ; //for high dynamic images
ga.gamma1 = 0.998279;
ga.gamma2 = 0.001721;
ga.gamma3 = 0.298507;
ga.gamma4 = 0.005746;
ga.gamma5 = 0.0;
ga[0] = 1.3 ; //for high dynamic images
ga[1] = 0.998279;
ga[2] = 0.001721;
ga[3] = 0.298507;
ga[4] = 0.005746;
} else if (icm.gamma == "Low_g2.6_s6.9") {
ga.gamma0 = 2.6 ; //gamma 2.6 variable : for low contrast images
ga.gamma1 = 0.891161;
ga.gamma2 = 0.108839;
ga.gamma3 = 0.144928;
ga.gamma4 = 0.076332;
ga.gamma5 = 0.0;
} else if (icm.gamma == "linear_g1.0") {
ga.gamma0 = 1.0; //gamma=1 linear : for high dynamic images (cf : D.Coffin...)
ga.gamma1 = 1.;
ga.gamma2 = 0.;
ga.gamma3 = 1. / eps;
ga.gamma4 = 0.;
ga.gamma5 = 0.0;
ga[0] = 2.6 ; //gamma 2.6 variable : for low contrast images
ga[1] = 0.891161;
ga[2] = 0.108839;
ga[3] = 0.144928;
ga[4] = 0.076332;
} else if (icm.gamma == "standard_g2.2") {
ga.gamma0 = 2.2; //gamma=2.2 (as gamma of Adobe, Widegamut...)
ga.gamma1 = 1.;
ga.gamma2 = 0.;
ga.gamma3 = 1. / eps;
ga.gamma4 = 0.;
ga.gamma5 = 0.0;
ga[0] = 2.2; //gamma=2.2 (as gamma of Adobe, Widegamut...)
ga[1] = 1.;
ga[2] = 0.;
ga[3] = 1. / eps;
ga[4] = 0.;
} else if (icm.gamma == "standard_g1.8") {
ga.gamma0 = 1.8; //gamma=1.8 (as gamma of Prophoto)
ga.gamma1 = 1.;
ga.gamma2 = 0.;
ga.gamma3 = 1. / eps;
ga.gamma4 = 0.;
ga.gamma5 = 0.0;
ga[0] = 1.8; //gamma=1.8 (as gamma of Prophoto)
ga[1] = 1.;
ga[2] = 0.;
ga[3] = 1. / eps;
ga[4] = 0.;
} else /* if (icm.gamma == "linear_g1.0") */ {
ga[0] = 1.0; //gamma=1 linear : for high dynamic images (cf : D.Coffin...)
ga[1] = 1.;
ga[2] = 0.;
ga[3] = 1. / eps;
ga[4] = 0.;
}
ga[5] = 0.0;
ga[6] = 0.0;
} else { //free gamma selected
Color::GammaValues g_a; //gamma parameters
GammaValues g_a; //gamma parameters
double pwr = 1.0 / icm.gampos;
double ts = icm.slpos;
double slope = icm.slpos == 0 ? eps : icm.slpos;
int mode = 0, imax = 0;
Color::calcGamma(pwr, ts, mode, imax, g_a); // call to calcGamma with selected gamma and slope : return parameters for LCMS2
ga.gamma4 = g_a.gamma3 * ts;
ga[4] = g_a[3] * ts;
//printf("g_a.gamma0=%f g_a.gamma1=%f g_a.gamma2=%f g_a.gamma3=%f g_a.gamma4=%f\n", g_a.gamma0,g_a.gamma1,g_a.gamma2,g_a.gamma3,g_a.gamma4);
ga.gamma0 = icm.gampos;
ga.gamma1 = 1. / (1.0 + g_a.gamma4);
ga.gamma2 = g_a.gamma4 / (1.0 + g_a.gamma4);
ga.gamma3 = 1. / slope;
ga.gamma5 = 0.0;
ga[0] = icm.gampos;
ga[1] = 1. / (1.0 + g_a[4]);
ga[2] = g_a[4] / (1.0 + g_a[4]);
ga[3] = 1. / slope;
ga[5] = 0.0;
ga[6] = 0.0;
//printf("ga[0]=%f ga[1]=%f ga[2]=%f ga[3]=%f ga[4]=%f\n", ga[0],ga[1],ga[2],ga[3],ga[4]);
}
}
cmsHPROFILE ICCStore::createGammaProfile (const procparams::ColorManagementParams &icm, Color::GammaValues &ga) {
cmsHPROFILE ICCStore::createGammaProfile (const procparams::ColorManagementParams &icm, GammaValues &ga) {
float p[6]; //primaries
ga.gamma6 = 0.0;
ga[6] = 0.0;
enum class ColorTemp {
D50 = 5003, // for Widegamut, Prophoto Best, Beta -> D50
@ -520,7 +516,7 @@ cmsHPROFILE ICCStore::createGammaProfile (const procparams::ColorManagementParam
cmsToneCurve* GammaTRC[3];
// 7 parameters for smoother curves
cmsFloat64Number Parameters[7] = { ga.gamma0, ga.gamma1, ga.gamma2, ga.gamma3, ga.gamma4, ga.gamma5, ga.gamma6 } ;
cmsFloat64Number Parameters[7] = { ga[0], ga[1], ga[2], ga[3], ga[4], ga[5], ga[6] } ;
cmsWhitePointFromTemp(&xyD, (double)temp);
GammaTRC[0] = GammaTRC[1] = GammaTRC[2] = cmsBuildParametricToneCurve(NULL, 5, Parameters); //5 = smoother than 4
@ -531,7 +527,7 @@ cmsHPROFILE ICCStore::createGammaProfile (const procparams::ColorManagementParam
return oprofdef;
}
cmsHPROFILE ICCStore::createCustomGammaOutputProfile (const procparams::ColorManagementParams &icm, Color::GammaValues &ga) {
cmsHPROFILE ICCStore::createCustomGammaOutputProfile (const procparams::ColorManagementParams &icm, GammaValues &ga) {
bool pro = false;
Glib::ustring outProfile;
cmsHPROFILE outputProfile = nullptr;
@ -590,7 +586,7 @@ cmsHPROFILE ICCStore::createCustomGammaOutputProfile (const procparams::ColorMan
}
// 7 parameters for smoother curves
cmsFloat64Number Parameters[7] = { ga.gamma0, ga.gamma1, ga.gamma2, ga.gamma3, ga.gamma4, ga.gamma5, ga.gamma6 };
cmsFloat64Number Parameters[7] = { ga[0], ga[1], ga[2], ga[3], ga[4], ga[5], ga[6] };
//change desc Tag , to "free gamma", or "BT709", etc.
cmsMLU *mlu;

View File

@ -88,11 +88,11 @@ public:
void init (const Glib::ustring& usrICCDir, const Glib::ustring& stdICCDir);
static void getGammaArray(const procparams::ColorManagementParams &icm, Color::GammaValues &ga);
static void getGammaArray(const procparams::ColorManagementParams &icm, GammaValues &ga);
static cmsHPROFILE makeStdGammaProfile (cmsHPROFILE iprof);
static cmsHPROFILE createFromMatrix (const double matrix[3][3], bool gamma = false, const Glib::ustring& name = Glib::ustring());
static cmsHPROFILE createGammaProfile (const procparams::ColorManagementParams &icm, Color::GammaValues &ga);
static cmsHPROFILE createCustomGammaOutputProfile (const procparams::ColorManagementParams &icm, Color::GammaValues &ga);
static cmsHPROFILE createGammaProfile (const procparams::ColorManagementParams &icm, GammaValues &ga);
static cmsHPROFILE createCustomGammaOutputProfile (const procparams::ColorManagementParams &icm, GammaValues &ga);
// Main monitors standard profile name, from OS
void findDefaultMonitorProfile ();

View File

@ -92,13 +92,13 @@ void ImProcFunctions::updateColorProfiles (const ColorManagementParams& icm, con
if (softProof) {
cmsHPROFILE oprof;
if(icm.gamma != "default" || icm.freegamma) { // if select gamma output between BT709, sRGB, linear, low, high, 2.2 , 1.8
Color::GammaValues ga;
GammaValues ga;
iccStore->getGammaArray(icm, ga);
oprof = iccStore->createGammaProfile (icm, ga);
}
else if (!icm.output.empty() && icm.output != ColorManagementParams::NoICMString) {
if(icm.gamma != "default" || icm.freegamma) { // if select gamma output between BT709, sRGB, linear, low, high, 2.2 , 1.8
Color::GammaValues ga;
GammaValues ga;
iccStore->getGammaArray(icm, ga);
oprof = iccStore->createCustomGammaOutputProfile (icm, ga);
} else {

View File

@ -362,7 +362,7 @@ public:
void BadpixelsLab(LabImage * src, LabImage * dst, double radius, int thresh, int mode, float b_l, float t_l, float t_r, float b_r, float skinprot, float chrom);
Image8* lab2rgb (LabImage* lab, int cx, int cy, int cw, int ch, const procparams::ColorManagementParams &icm);
Image16* lab2rgb16 (LabImage* lab, int cx, int cy, int cw, int ch, const procparams::ColorManagementParams &icm, bool bw, Color::GammaValues *ga=NULL);
Image16* lab2rgb16 (LabImage* lab, int cx, int cy, int cw, int ch, const procparams::ColorManagementParams &icm, bool bw, GammaValues *ga=NULL);
// CieImage *ciec;
bool transCoord (int W, int H, int x, int y, int w, int h, int& xv, int& yv, int& wv, int& hv, double ascaleDef = -1, const LCPMapper *pLCPMap = NULL);

View File

@ -280,7 +280,7 @@ Image8* ImProcFunctions::lab2rgb (LabImage* lab, int cx, int cy, int cw, int ch,
* If a custom gamma profile can be created, divide by 327.68, convert to xyz and apply the custom gamma transform
* otherwise divide by 327.68, convert to xyz and apply the sRGB transform, before converting with gamma2curve
*/
Image16* ImProcFunctions::lab2rgb16 (LabImage* lab, int cx, int cy, int cw, int ch, const procparams::ColorManagementParams &icm, bool bw, Color::GammaValues *ga)
Image16* ImProcFunctions::lab2rgb16 (LabImage* lab, int cx, int cy, int cw, int ch, const procparams::ColorManagementParams &icm, bool bw, GammaValues *ga)
{
//gamutmap(lab);

View File

@ -1973,7 +1973,7 @@ void RawImageSource::retinexPrepareBuffers(ColorManagementParams cmp, RetinexPar
} else if(retinexParams.gammaretinex == "hig") {
retinexgamtab = &(Color::gammatab_145_3);
} else if(retinexParams.gammaretinex == "fre") {
Color::GammaValues g_a;
GammaValues g_a;
double pwr = 1.0 / retinexParams.gam;
double gamm = retinexParams.gam;
double ts = retinexParams.slope;
@ -1991,14 +1991,14 @@ void RawImageSource::retinexPrepareBuffers(ColorManagementParams cmp, RetinexPar
double add;
if(gamm2 < 1.) {
start = g_a.gamma2;
add = g_a.gamma4;
start = g_a[2];
add = g_a[4];
} else {
start = g_a.gamma3;
add = g_a.gamma4;
start = g_a[3];
add = g_a[4];
}
double mul = 1. + g_a.gamma4;
double mul = 1. + g_a[4];
lutTonereti(65536);
@ -2245,7 +2245,7 @@ void RawImageSource::retinex(ColorManagementParams cmp, RetinexParams deh, ToneC
} else if(deh.gammaretinex == "hig") {
retinexigamtab = &(Color::igammatab_145_3);
} else if(deh.gammaretinex == "fre") {
Color::GammaValues g_a;
GammaValues g_a;
double pwr = 1.0 / deh.gam;
double gamm = deh.gam;
double gamm2 = gamm;
@ -2258,16 +2258,16 @@ void RawImageSource::retinex(ColorManagementParams cmp, RetinexParams deh, ToneC
Color::calcGamma(pwr, ts, mode, imax, g_a); // call to calcGamma with selected gamma and slope
double mul = 1. + g_a.gamma4;
double mul = 1. + g_a[4];
double add;
double start;
if(gamm2 < 1.) {
start = g_a.gamma3;
add = g_a.gamma3;
start = g_a[3];
add = g_a[3];
} else {
add = g_a.gamma4;
start = g_a.gamma2;
add = g_a[4];
start = g_a[2];
}
// printf("g_a0=%f g_a1=%f g_a2=%f g_a3=%f g_a4=%f\n", g_a0,g_a1,g_a2,g_a3,g_a4);

View File

@ -1162,7 +1162,7 @@ IImage16* processImage (ProcessingJob* pjob, int& errorCode, ProgressListener* p
if(params.icm.gamma != "default" || params.icm.freegamma) { // if select gamma output between BT709, sRGB, linear, low, high, 2.2 , 1.8
Color::GammaValues ga;
GammaValues ga;
// if(params.blackwhite.enabled) params.toneCurve.hrenabled=false;
readyImg = ipf.lab2rgb16 (labView, cx, cy, cw, ch, params.icm, bwonly, &ga);
customGamma = true;