Solving issue 2342: "Information needed for the color conversion methods of the Color class" ; done by jdesmis

This commit is contained in:
Hombre
2014-04-20 02:28:15 +02:00
parent 83df32e659
commit 2d3e9166f4
2 changed files with 499 additions and 57 deletions

View File

@@ -699,14 +699,6 @@ namespace rtengine {
a = (500.0 * (fx - fy) );
b = (200.0 * (fy - fz) );
}
double Color::f2xyz(double f) {
const double epsilonExpInv3 = 6.0/29.0;
const double kappaInv = 27.0/24389.0; // inverse of kappa
return (f > epsilonExpInv3) ? f*f*f : (116. * f - 16.) * kappaInv;
}
/*
* Gamut mapping algorithm

View File

@@ -119,97 +119,442 @@ public:
static void init ();
static void cleanup ();
/**
* @brief Extract luminance "sRGB" from red/green/blue values
* The range of the r, g and b channel has no importance ([0 ; 1] or [0 ; 65535]...) ; r,g,b can be negatives or > max, but must be in "sRGB"
* @param r red channel
* @param g green channel
* @param b blue channel
* @return luminance value
*/
// xyz_sRGBD65 : conversion matrix from XYZ to sRGB for D65 illuminant: we use diagonal values
static float rgbLuminance(float r, float g, float b) { return r*float(xyz_sRGBd65[1][0]) + g*float(xyz_sRGBd65[1][1]) + b*float(xyz_sRGBd65[1][2]); }
static double rgbLuminance(double r, double g, double b) { return r*xyz_sRGBd65[1][0] + g*xyz_sRGBd65[1][1] + b*xyz_sRGBd65[1][2]; }
/**
* @brief Convert red/green/blue to hue/saturation/luminance
* @param r red channel [0 ; 65535]
* @param g green channel [0 ; 65535]
* @param b blue channel [0 ; 65535]
* @param h hue channel [0 ; 1] (return value)
* @param s saturation channel [0 ; 1] (return value)
* @param l luminance channel [0; 1] (return value)
*/
static void rgb2hsl (float r, float g, float b, float &h, float &s, float &l);
/**
* @brief Convert hue/saturation/luminance in red/green/blue
* @param h hue channel [0 ; 1]
* @param s saturation channel [0 ; 1]
* @param l luminance channel [0 ; 1]
* @param r red channel [0 ; 65535] (return value)
* @param g green channel [0 ; 65535] (return value)
* @param b blue channel [0 ; 65535] (return value)
*/
static void hsl2rgb (float h, float s, float l, float &r, float &g, float &b);
/**
* @brief Convert red green blue to hue saturation value
* @param r red channel [0 ; 65535]
* @param g green channel [0 ; 65535]
* @param b blue channel [0 ; 65535]
* @param h hue channel [0 ; 1] (return value)
* @param s saturation channel [0 ; 1] (return value)
* @param v value channel [0 ; 1] (return value)
*/
static void rgb2hsv (float r, float g, float b, float &h, float &s, float &v);
/**
* @brief Convert hue saturation value in red green blue
* @param h hue channel [0 ; 1]
* @param s saturation channel [0 ; 1]
* @param v value channel [0 ; 1]
* @param r red channel [0 ; 65535] (return value)
* @param g green channel [0 ; 65535] (return value)
* @param b blue channel [0 ; 65535] (return value)
*/
static void hsv2rgb (float h, float s, float v, float &r, float &g, float &b);
static void hsv2rgb (float h, float s, float v, int &r, int &g, int &b);
/**
* @brief Convert hue saturation value in red green blue
* @param h hue channel [0 ; 1]
* @param s saturation channel [0 ; 1]
* @param v value channel [0 ; 1]
* @param r red channel [0 ; 1] (return value)
* @param g green channel [0 ; 1] (return value)
* @param b blue channel [0 ; 1] (return value)
*/
static void hsv2rgb01 (float h, float s, float v, float &r, float &g, float &b);
/**
* @brief Convert xyz to red/green/blue
* Color space : sRGB - illuminant D50 - use matrix sRGB_xyz[]
* @param x X coordinate [0 ; 1] or [0 ; 65535]
* @param y Y coordinate [0 ; 1] or [0 ; 65535]
* @param z Z coordinate [0 ; 1] or [0 ; 65535]
* @param r red channel [same range than xyz channel] (return value)
* @param g green channel [same range than xyz channel] (return value)
* @param b blue channel [same range than xyz channel] (return value)
*/
static void xyz2srgb (float x, float y, float z, float &r, float &g, float &b);
/**
* @brief Convert xyz to red/green/blue
* Color space : Prophoto - illuminant D50 - use the Prophoto_xyz[] matrix
* @param x X coordinate [0 ; 1] or [0 ; 65535]
* @param y Y coordinate [0 ; 1] or [0 ; 65535]
* @param z Z coordinate [0 ; 1] or [0 ; 65535]
* @param r red channel [same range than xyz channel] (return value)
* @param g green channel [same range than xyz channel] (return value)
* @param b blue channel [same range than xyz channel] (return value)
*/
static void xyz2Prophoto (float x, float y, float z, float &r, float &g, float &b);
/**
* @brief Convert rgb in xyz
* Color space : Prophoto - illuminant D50 - use matrix xyz_prophoto[]
* @param r red channel [0 ; 1] or [0 ; 65535] (return value)
* @param g green channel [0 ; 1] or [0 ; 65535] (return value)
* @param b blue channel [0 ; 1] or [0 ; 65535] (return value)
* @param x X coordinate [same range than xyz channel]
* @param y Y coordinate [same range than xyz channel]
* @param z Z coordinate [same range than xyz channel]
*/
static void Prophotoxyz (float r, float g, float b, float &x, float &y, float &z);
/**
* @brief Convert xyz in rgb
* Color space : undefined - use adhoc matrix: rgb_xyz[3][3] (iccmatrice.h) in function of working space
* @param x X coordinate [0 ; 1] or [0 ; 65535]
* @param y Y coordinate [0 ; 1] or [0 ; 65535]
* @param z Z coordinate [0 ; 1] or [0 ; 65535]
* @param r red channel [same range than xyz channel] (return value)
* @param g green channel [same range than xyz channel] (return value)
* @param b blue channel [same range than xyz channel] (return value)
* @param rgb_xyz[3][3] transformation matrix to use for the conversion
*/
static void xyz2rgb (float x, float y, float z, float &r, float &g, float &b, double rgb_xyz[3][3]);
static void xyz2rgb (float x, float y, float z, float &r, float &g, float &b, float rgb_xyz[3][3]);
/**
* @brief Convert rgb in xyz
* Color space : undefined - use matrix adhoc : xyz_rgb[3][3] (iccmatrice.h) in function of working space
* @param r red channel [0 ; 1] or [0 ; 65535]
* @param g green channel [0 ; 1] or [0 ; 65535]
* @param b blue channel [0 ; 1] or [0 ; 65535]
* @param x X coordinate [same range than rgb channel] (return value)
* @param y Y coordinate [same range than rgb channel] (return value)
* @param z Z coordinate [same range than rgb channel] (return value)
* @param xyz_rgb[3][3] transformation matrix to use for the conversion
*/
static void rgbxyz (float r, float g, float b, float &x, float &y, float &z, double xyz_rgb[3][3]);
/**
* @brief Convert Lab in xyz
* @param L L channel [0 ; 32768] ; L can be negative rarely or superior 32768
* @param a channel [-42000 ; +42000] ; can be more than 42000
* @param b channel [-42000 ; +42000] ; can be more than 42000
* @param x X coordinate [0 ; 65535] ; can be negative! (return value)
* @param y Y coordinate [0 ; 65535] ; can be negative! (return value)
* @param z Z coordinate [0 ; 65535] ; can be negative! (return value)
*/
static void Lab2XYZ(float L, float a, float b, float &x, float &y, float &z);
/**
* @brief Convert xyz in Lab
* @param x X coordinate [0 ; 65535] ; can be negative or superior to 65535
* @param y Y coordinate [0 ; 65535] ; can be negative or superior to 65535
* @param z Z coordinate [0 ; 65535] ; can be negative or superior to 65535
* @param L L channel [0 ; 32768] ; L can be negative rarely or superior 32768 (return value)
* @param a channel [-42000 ; +42000] ; can be more than 42000 (return value)
* @param b channel [-42000 ; +42000] ; can be more than 42000 (return value)
*/
static void XYZ2Lab(float X, float Y, float Z, float &L, float &a, float &b);
/**
* @brief Convert Lab in Yuv
* @param L L channel [0 ; 32768] ; L can be negative rarely or superior 32768
* @param a channel [-42000 ; +42000] ; can be more than 42000
* @param b channel [-42000 ; +42000] ; can be more than 42000
* @param Y luminance channel [0 ; 65535] (return value)
* @param u red chrominance channel [0 ; 65535] (return value)
* @param v blue chrominance channel [0 ; 65535] (return value)
*/
static void Lab2Yuv(float L, float a, float b, float &Y, float &u, float &v);
/**
* @brief Convert Yuv in Lab
* @param Y luminance channel [0 ; 65535]
* @param u red chrominance channel [0 ; 65535]
* @param v blue chrominance channel [0 ; 65535]
* @param L L channel [0 ; 32768] ; L can be negative rarely or superior 32768 (return value)
* @param a channel [-42000 ; +42000] ; can be more than 42000 (return value)
* @param b channel [-42000 ; +42000] ; can be more than 42000 (return value)
*/
static void Yuv2Lab(float Y, float u, float v, float &L, float &a, float &b, double wp[3][3]);
static double f2xyz(double f);
/**
* @brief Return "f" in function of CIE's kappa and epsilon constants
* @param f f can be fx fy fz where:
* fx=a/500 + fy a=chroma green red [-128 ; +128]
* fy=(L+16)/116 L=luminance [0 ; 100]
* fz=fy-b/200 b=chroma blue yellow [-128 ; +128]
*/
static inline double f2xyz(double f) {
const double epsilonExpInv3 = 6.0/29.0;
const double kappaInv = 27.0/24389.0; // inverse of kappa
return (f > epsilonExpInv3) ? f*f*f : (116. * f - 16.) * kappaInv;
}
static inline float f2xyz(float f) {
const float epsilonExpInv3 = 6.0f/29.0f;
const float kappaInv = 27.0f/24389.0f; // inverse of kappa
return (f > epsilonExpInv3) ? f*f*f : (116.f * f - 16.f) * kappaInv;
}
/**
* @brief Get the gamma curves' parameters used by LCMS2
* @param pwr gamma value [>1]
* @param ts slope [0 ; 20]
* @param mode [always 0]
* @imax imax [always 0]
* @param gamma0 used in ip2Lab2rgb [0 ; 1], usually near 0.5 (return value)
* @param gamma1 used in ip2Lab2rgb [0 ; 20], can be superior to 20, but it's quite unusual(return value)
* @param gamma2 used in ip2Lab2rgb [0 ; 1], usually near 0.03(return value)
* @param gamma3 used in ip2Lab2rgb [0 ; 1], usually near 0.003(return value)
* @param gamma4 used in ip2Lab2rgb [0 ; 1], usually near 0.03(return value)
* @param gamma5 used in ip2Lab2rgb [0 ; 1], usually near 0.5 (return value)
*/
static void calcGamma (double pwr, double ts, int mode, int imax, double &gamma0, double &gamma1, double &gamma2, double &gamma3, double &gamma4,double &gamma5);
/**
* @brief Used by Black and White to correct gamma for each channel red, green and blue channel
* @param r red channel input and output value [0 ; 65535]
* @param g green channel input and output value [0 ; 65535]
* @param b blue channel input and output value [0 ; 65535]
* @param gammabwr gamma value for red channel [>0]
* @param gammabwg gamma value for red channel [>0]
* @param gammabwb gamma value for red channel [>0]
*/
static void trcGammaBW (float &r, float &g, float &b, float gammabwr, float gammabwg, float gammabwb);
/** @brief Compute the B&W constants for the Black and White processing and its GUI
* @param setting main mode
* @param filter string of the filter effect to use
* @param algo choice between linear and special for OYCPM colors
* @param mixerRed red channel value of the channel mixer [-100 ; +200]
* @param mixerGreen green channel value of the channel mixer [-100 ; +200]
* @param mixerBlue blue channel value of the channel mixer [-100 ; +200]
* @param mixerOrange orange channel value of the channel mixer [-100 ; +200]
* @param mixerYellow yellow channel value of the channel mixer [-100 ; +200]
* @param mixerCyan cyan channel value of the channel mixer [-100 ; +200]
* @param mixerPurple purple channel value of the channel mixer [-100 ; +200]
* @param mixerMagenta magenta channel value of the channel mixer [-100 ; +200]
* @param autoc automatic mode of the channel mixer
* @param complement adjust complementary channel
* @param kcorec in absolute mode, value to correct the mixer [1 ; 3], usually near 1 (return value)
* @param rrm red channel of the mixer (return value)
* @param ggm green channel of the mixer (return value)
* @param bbm blue channel of the mixer (return value)
*/
static void computeBWMixerConstants (const Glib::ustring &setting, const Glib::ustring &filter, const Glib::ustring &algo, float &mixerRed, float &mixerGreen,
float &mixerBlue, float mixerOrange, float mixerYellow, float mixerCyan, float mixerPurple, float mixerMagenta,
bool autoc, bool complement, float &kcorec, double &rrm, double &ggm, double &bbm);
// standard srgb gamma and its inverse
/**
* @brief sRGB gamma
* See also calcGamma above with the following values: pwr=2.4 ts=12.92 mode=0.003041 imax=0.055011
* @param x red, green or blue channel's value [0 ; 1]
* @return the gamma modified's value [0 ; 1]
*/
static inline double gamma2 (double x) { // g3 1+g4
return x <= 0.003041 ? x*12.92 : 1.055011*exp(log(x)/sRGBGammaCurve)-0.055011;
}
/**
* @brief Inverse sRGB gamma
* See also calcGamma above with the following values: pwr=2.4 ts=12.92 mode=0.003041 imax=0.055011
* @param x red, green or blue channel's value [0 ; 1]
* @return the inverse gamma modified's value [0 ; 1]
*/
static inline double igamma2 (double x) { //g2
return x <= 0.039293 ? x/12.92 : exp(log((x+0.055011)/1.055011)*sRGBGammaCurve);
}
/**
* @brief Get the gamma value for Gamma=5.5 Slope=10
* @param x red, green or blue channel's value [0 ; 1]
* @return the gamma modified's value [0 ; 1]
*/
static inline double gamma55 (double x) { // g3 1+g4
return x <= 0.013189 ? x*10.0 : 1.593503*exp(log(x)/5.5)-0.593503;// 5.5 10
return x <= 0.013189 ? x*10.0 : 1.593503*exp(log(x)/5.5)-0.593503;// 5.5 10
}
/**
* @brief Get the inverse gamma value for Gamma=5.5 Slope=10
* @param x red, green or blue channel's value [0 ; 1]
* @return the inverse gamma modified's value [0 ; 1]
*/
static inline double igamma55 (double x) { //g2
return x <= 0.131889 ? x/10.0 : exp(log((x+0.593503)/1.593503)*5.5); // 5.5 10
return x <= 0.131889 ? x/10.0 : exp(log((x+0.593503)/1.593503)*5.5); // 5.5 10
}
/**
* @brief Get the gamma value for Gamma=4 Slope=5
* @param x red, green or blue channel's value [0 ; 1]
* @return the gamma modified's value [0 ; 1]
*/
static inline double gamma4 (double x) { // g3 1+g4
return x <= 0.03089 ? x*5.0 : 1.478793*exp(log(x)/4.1)-0.478793;// 4 5
return x <= 0.03089 ? x*5.0 : 1.478793*exp(log(x)/4.1)-0.478793;// 4 5
}
/**
* @brief Get the inverse gamma value for Gamma=4 Slope=5
* @param x red, green or blue channel's value [0 ; 1]
* @return the inverse gamma modified's value [0 ; 1]
*/
static inline double igamma4 (double x) { //g2
return x <= 0.154449 ? x/5.0 : exp(log((x+0.478793)/1.478793)*4.1);// 4 5
return x <= 0.154449 ? x/5.0 : exp(log((x+0.478793)/1.478793)*4.1);// 4 5
}
/*
/*
* @brief Get the gamma value for Gamma=2.2 Slope=4.5
* @param x red, green or blue channel's value [0 ; 1]
* @return the gamma modified's value [0 ; 1]
*
static inline double gamma709 (double x) {
return x <= 0.0176 ? x*4.5 : 1.0954*exp(log(x)/2.2)-0.0954;
}
* @brief Get the inverse gamma value for Gamma=2.2 Slope=4.5
* @param x red, green or blue channel's value [0 ; 1]
* @return the inverse gamma modified's value [0 ; 1]
*
static inline double igamma709 (double x) {
return x <= 0.0795 ? x/4.5 : exp(log((x+0.0954)/1.0954)*2.2);
}
*/
/**
* @brief Get the gamma value for Gamma=2.4 Slope=17
* @param x red, green or blue channel's value [0 ; 1]
* @return the gamma modified's value [0 ; 1]
*/
static inline double gamma24_17 (double x) {
return x <= 0.001867 ? x*17.0 : 1.044445*exp(log(x)/2.4)-0.044445;
}
/**
* @brief Get the inverse gamma value for Gamma=2.4 Slope=17
* @param x red, green or blue channel's value [0 ; 1]
* @return the inverse gamma modified's value [0 ; 1]
*/
static inline double igamma24_17 (double x) {
return x <= 0.031746 ? x/17.0 : exp(log((x+0.044445)/1.044445)*2.4);
}
}
/**
* @brief Get the gamma value for Gamma=2.6 Slope=11
* @param x red, green or blue channel's value [0 ; 1]
* @return the gamma modified's value [0 ; 1]
*/
static inline double gamma26_11 (double x) {
return x <= 0.004921 ? x*11.0 : 1.086603*exp(log(x)/2.6)-0.086603;
}
/**
* @brief Get the inverse gamma value for Gamma=2.6 Slope=11
* @param x red, green or blue channel's value [0 ; 1]
* @return the inverse gamma modified's value [0 ; 1]
*/
static inline double igamma26_11 (double x) {
return x <= 0.054127 ? x/11.0 : exp(log((x+0.086603)/1.086603)*2.6);
}
}
// gamma function with adjustable parameters
//same as above with values calculate with Calcgamma above
// X range 0..1
static inline double gamma (double x, double gamma, double start, double slope, double mul, double add){
return (x <= start ? x*slope : exp(log(x)/gamma)*mul-add);
}
static inline double igamma (double x, double gamma, double start, double slope, double mul, double add){
return (x <= start*slope ? x/slope : exp(log((x+add)/mul)*gamma) );
}
static inline double gamman (double x, double gamma){//gamma standard without slope...
/**
* @brief Very basic gamma
* @param x red, green or blue channel's value [0 ; 1]
* @param gamma gamma value [1 ; 5]
* @return the gamma modified's value [0 ; 1]
*/
static inline double gamman (double x, double gamma) { //standard gamma without slope...
return (x =exp(log(x)/gamma));
}
static inline double igamman (double x, double gamma){//inverse gamma standard without slope...
/**
* @brief Very simply inverse gamma
* @param x red, green or blue channel's value [0 ; 1]
* @param gamma gamma value [1 ; 5]
* @return the inverse gamma modified's value [0 ; 1]
*/
static inline double igamman (double x, double gamma){ //standard inverse gamma without slope...
return (x = exp(log(x)*gamma) );
}
// gamma functions on [0,65535] based on look-up tables
static inline float gamma_srgb (char x) { return gammatab_srgb[x]; }
static inline float gamma (char x) { return gammatab[x]; }
static inline float igamma_srgb (char x) { return igammatab_srgb[x]; }
static inline float gamma_srgb (int x) { return gammatab_srgb[x]; }
static inline float gamma (int x) { return gammatab[x]; }
static inline float igamma_srgb (int x) { return igammatab_srgb[x]; }
/**
* @brief Get the gamma value out of look-up tables
* Calculated with gamma function above. e.g. :
* for (int i=0; i<65536; i++)
* gammatab_srgb[i] = (65535.0 * gamma2 (i/65535.0));
* @param x [0 ; 1]
* @return the gamma modified's value [0 ; 65535]
*/
static inline float gamma_srgb (char x) { return gammatab_srgb[x]; }
static inline float gamma (char x) { return gammatab[x]; }
static inline float igamma_srgb (char x) { return igammatab_srgb[x]; }
static inline float gamma_srgb (int x) { return gammatab_srgb[x]; }
static inline float gamma (int x) { return gammatab[x]; }
static inline float igamma_srgb (int x) { return igammatab_srgb[x]; }
static inline float gamma_srgb (float x) { return gammatab_srgb[x]; }
static inline float gamma (float x) { return gammatab[x]; }
static inline float igamma_srgb (float x) { return igammatab_srgb[x]; }
@@ -217,56 +562,161 @@ public:
//static inline float gamma (double x) { return gammatab[x]; }
//static inline float igamma_srgb (double x) { return igammatab_srgb[x]; }
//Jacques's Munsell correction
// -------------------------------- Jacques's Munsell correction
/**
* @brief Corrects the color (hue) depending on chromaticity and luminance changes
*
* To use in a "for" or "do while" statement.
*
* @param lumaMuns true => luminance correction (for delta L > 10) and chroma correction ; false => only chroma
* @param Lprov1 luminance after [0 ; 100]
* @param Loldd luminance before [0 ; 100]
* @param HH hue before [-PI ; +PI]
* @param Chprov1 chroma after [0 ; 180 (can be superior)]
* @param CC chroma before [0 ; 180]
* @param corectionHuechroma hue correction depending on chromaticity (saturation), in radians [0 ; 0.45] (return value)
* @param correctlum hue correction depending on luminance (brightness, contrast,...), in radians [0 ; 0.45] (return value)
* @param munsDbgInfo (Debug target only) object to collect informations
*/
#ifdef _DEBUG
static void AllMunsellLch (bool lumaMuns, float Lprov1, float Loldd, float HH, float Chprov1, float CC, float &correctionHueChroma, float &correctlum, MunsellDebugInfo* munsDbgInfo);
static void gamutLchonly (float HH, float &Lprov1, float &Chprov1, float &R, float &G, float &B, double wip[3][3], const bool isHLEnabled, const float lowerCoef, const float higherCoef, bool &neg, bool &more_rgb);
#else
static void AllMunsellLch (bool lumaMuns, float Lprov1, float Loldd, float HH, float Chprov1, float CC, float &correctionHueChroma, float &correctlum);
#endif
/**
* @brief Correct chromaticity and luminance so that the color stays in the working profile's gamut
*
* This function puts the data (Lab) in the gamut of "working profile":
* it returns the corrected values of the chromaticity and luminance
*
* @param HH : hue, in radians [-PI ; +PI]
* @param Lprov1 : input luminance value, sent back corrected [0 ; 100] (input & output value)
* @param Chprov1: input chroma value, sent back corrected [0 ; 180 (can be superior)] (input & output value)
* @param R red value of the corrected color [0 ; 65535 but can be negative or superior to 65535] (return value)
* @param G green value of the corrected color [0 ; 65535 but can be negative or superior to 65535] (return value)
* @param B blue value of the corrected color [0 ; 65535 but can be negative or superior to 65535] (return value)
* @param wip working profile
* @param isHLEnabled true if "Highlight Reconstruction " is enabled
* @param lowerCoef a float number between [0.95 ; 1.0[
* The nearest it is from 1.0, the more precise it will be, and the longer too as more iteration will be necessary
* @param higherCoef a float number between [0.95 ; 1.0[
* The nearest it is from 1.0, the more precise it will be, and the longer too as more iteration will be necessary
* @param neg (Debug target only) to calculate iterations for negatives values
* @param moreRGB (Debug target only) to calculate iterations for values >65535
*/
#ifdef _DEBUG
static void gamutLchonly (float HH, float &Lprov1, float &Chprov1, float &R, float &G, float &B, double wip[3][3], const bool isHLEnabled, const float lowerCoef, const float higherCoef, bool &neg, bool &more_rgb);
#else
static void gamutLchonly (float HH, float &Lprov1, float &Chprov1, float &R, float &G, float &B, double wip[3][3], const bool isHLEnabled, const float lowerCoef, const float higherCoef);
#endif
/**
* @brief Munsell gamut correction
*
* This function is the overall Munsell's corrections, but only on global statement. It may be better to use local statement with AllMunsellLch.
* Not for use in a "for" or "do while" loop
* They are named accordingly : gamutLchonly and AllMunsellLch
* It can be used before and after treatment (saturation, gamma, luminance, ...)
*
* @param lab input and output image
* L channel's usual range is [0 ; 100], but values can be negative or >100
* a and b channel's range is usually [-128 ; +128], but values can be >128
* @param Lold luminance before [same range than lab.L]
* @param Cold chrominance before [0 ; 180 (can be superior)]
* @param corMuns performs Munsell correction
* @param lumaMuns whether to apply luma correction or not (used only if corMuns=true)
* true: apply luma + chroma Munsell correction if delta L > 10;
* false: leaves luma untouched
* @param gamut performs gamutLch
* @param working working profile's name
* @param multiThread whether to parallelize the loop or not
*/
static void LabGamutMunsell (LabImage *lab, float *Lold, float *Cold, bool corMunsell, bool lumaMuns, bool isHLEnabled, bool gamut, const Glib::ustring &working, bool multiThread );
/*
* @brief Skin tone protection factor
* Skin colors: mixed from NX2 skin color palette, Von Luschan, and photos of white, black, yellow people...
* There are some little exceptions, but it should cover 99% case.
* Pay attention to white balance, and do not change hue and saturation, upstream of the modification
* Used by vibrance
* @param lum luma value [0 ; 100]
* @param hue hue value [-PI ; +PI]
* @param chrom chroma value [0 ; 180]
* @param satreduc [0.1 ; 1] (return value)
* @param chromx [0 or 1], actually only 0 is used
*/
static void SkinSat (float lum, float hue, float chrom, float &satreduc, int chromx);//jacques Skin color
/**
* @brief Munsell Lch correction
* Find the right LUT and calculate the correction
* @param lum luma value [0 ; 100]
* @param hue hue value [-PI ; +PI]
* @param chrom chroma value [0 ; 180]
* @param memChprov store chroma [0 ; 180]
* @param correction correction value, in radians [0 ; 0.45]
* @param lbe hue in function of chroma, in radian [-PI ; +PI]
* @param zone [1 ; 4] 1=PB correction + sky 2=red yellow correction 3=Green yellow correction 4=Red purple correction
* @param correctL true=enable the Luminance correction
*/
static void MunsellLch (float lum, float hue, float chrom, float memChprov, float &correction, int zone, float &lbe, bool &correctL);//jacques: Munsell correction
// end Munsell
// -------------------------------- end Munsell
static void scalered ( float rstprotection, float param, float limit, float HH, float deltaHH, float &scale, float &scaleext);
static void transitred (float HH, float Chprov1, float dred, float factorskin, float protect_red, float factorskinext, float deltaHH, float factorsat, float &factor);
static void skinred ( double J, double h, double sres, double Sp, float dred, float protect_red, int sk, float rstprotection, float ko, double &s);
static void skinredfloat ( float J, float h, float sres, float Sp, float dred, float protect_red, int sk, float rstprotection, float ko, float &s);
// static void scaleredcdbl ( float skinprot, float param, float limit, float HH, float deltaHH, float &scale,float &scaleext);
static void SkinSatcdbl (float lum, float hue, float chrom, float skinprot, float &scale, bool ciec, bool neg, float b_l, float t_l, float t_r, float b_r, int choice);
static void SkinSatcdbl (float lum, float hue, float chrom, float skinprot, float &scale, bool ciec, bool neg, float b_l, float t_l, float t_r, float b_r, int choice);
//void gamutmap(LabImage* );
/**
* @brief Gamut correction in the XYZ color space
* @param X X channel input value and corrected output value [0 ; 65535]
* @param Y Y channel input value and corrected output value [0 ; 65535]
* @param Z Z channel input value and corrected output value [0 ; 65535]
* @param p working profile
*/
static void gamutmap(float &X, float &Y, float &Z, const double p[3][3]);
/**
* @brief Get HSV's hue from the Lab's hue
* @param HH Lab's hue value, in radians [-PI ; +PI]
* @return HSV's hue value [0 ; 1]
*/
static inline double huelab_to_huehsv2 (float HH){
//hr=translate Hue Lab value (-Pi +Pi) in approximative hr (hsv values) (0 1) [red 1/6 yellow 1/6 green 1/6 cyan 1/6 blue 1/6 magenta 1/6 ]
// with multi linear correspondances (I expect there is no error !!)
double hr = 0.0;
//allways put h between 0 and 1
//hr=translate Hue Lab value (-Pi +Pi) in approximative hr (hsv values) (0 1) [red 1/6 yellow 1/6 green 1/6 cyan 1/6 blue 1/6 magenta 1/6 ]
// with multi linear correspondances (I expect there is no error !!)
double hr = 0.0;
//allways put h between 0 and 1
if (HH>=0.f && HH < 0.6f) hr=0.11666*(double) HH + 0.93; //hr 0.93 1. full red
else if (HH>=0.6f && HH < 1.4f) hr=0.1125*double(HH) - 0.0675; //hr 0.0 0.09 red yellow orange
else if (HH>=1.4f && HH < 2.f) hr=0.2666*double(HH) - 0.2833; //hr 0.09 0.25 orange yellow
else if (HH>=2.f && HH < 3.14159f) hr=0.1489*double(HH) - 0.04785; //hr 0.25 0.42 yellow green green
else if (HH>=-3.14159f && HH < -2.8f) hr=0.23419*double(HH) +1.1557; //hr 0.42 0.5 green
else if (HH>=-2.8f && HH < -2.3f) hr=0.16*double(HH) + 0.948; //hr 0.5 0.58 cyan
else if (HH>=-2.3f && HH < -0.9f) hr=0.12143*double(HH)+ 0.85928; //hr 0.58 0.75 blue blue-sky
else if (HH>=-0.9f && HH < -0.1f) hr=0.2125*double(HH) + 0.94125; //hr 0.75 0.92 purple magenta
else if (HH>=-0.1f && HH < 0.f) hr=0.1*double(HH) + 0.93; //hr 0.92 0.93 red
// in case of !
if (hr<0.0) hr += 1.0;
else if(hr>1.0) hr -= 1.0;
return (hr);
}
static inline float f2xyz(float f) {
const float epsilonExpInv3 = 6.0/29.0;
const float kappaInv = 27.0/24389.0; // inverse of kappa
return (f > epsilonExpInv3) ? f*f*f : (116 * f - 16) * kappaInv;
if (HH>=0.f && HH < 0.6f ) hr=0.11666*double(HH) + 0.93; //hr 0.93 1.00 full red
else if (HH>=0.6f && HH < 1.4f ) hr=0.1125 *double(HH) - 0.0675; //hr 0.00 0.09 red yellow orange
else if (HH>=1.4f && HH < 2.f ) hr=0.2666 *double(HH) - 0.2833; //hr 0.09 0.25 orange yellow
else if (HH>=2.f && HH < 3.14159f) hr=0.1489 *double(HH) - 0.04785; //hr 0.25 0.42 yellow green green
else if (HH>=-3.14159f && HH < -2.8f ) hr=0.23419*double(HH) + 1.1557; //hr 0.42 0.50 green
else if (HH>=-2.8f && HH < -2.3f ) hr=0.16 *double(HH) + 0.948; //hr 0.50 0.58 cyan
else if (HH>=-2.3f && HH < -0.9f ) hr=0.12143*double(HH) + 0.85928; //hr 0.58 0.75 blue blue-sky
else if (HH>=-0.9f && HH < -0.1f ) hr=0.2125 *double(HH) + 0.94125; //hr 0.75 0.92 purple magenta
else if (HH>=-0.1f && HH < 0.f ) hr=0.1 *double(HH) + 0.93; //hr 0.92 0.93 red
// in case of !
if (hr<0.0) hr += 1.0;
else if(hr>1.0) hr -= 1.0;
return (hr);
}
};