Speedup for Colour toning methods 'Colour Balance' and 'Saturation 2 colours'

This commit is contained in:
heckflosse 2018-01-14 16:18:23 +01:00
parent cbcb096339
commit a618e3dc7b

View File

@ -3514,15 +3514,15 @@ void ImProcFunctions::rgbProc (Imagefloat* working, LabImage* lab, PipetteBuffer
} }
*/ */
float RedLow = (100.f + float (params->colorToning.redlow)) / 100.f; //printf("Rel=%f\n",RedLow); float RedLow = params->colorToning.redlow / 100.f;
float GreenLow = (100.f + float (params->colorToning.greenlow)) / 100.f; //printf("Gre=%f\n",GreenLow); float GreenLow = params->colorToning.greenlow / 100.f;
float BlueLow = (100.f + float (params->colorToning.bluelow)) / 100.f; //printf("Blu=%f\n",BlueLow); float BlueLow = params->colorToning.bluelow / 100.f;
float RedMed = (100.f + float (params->colorToning.redmed)) / 100.f; float RedMed = params->colorToning.redmed / 100.f;
float GreenMed = (100.f + float (params->colorToning.greenmed)) / 100.f; float GreenMed = params->colorToning.greenmed / 100.f;
float BlueMed = (100.f + float (params->colorToning.bluemed)) / 100.f; float BlueMed = params->colorToning.bluemed / 100.f;
float RedHigh = (100.f + float (params->colorToning.redhigh)) / 100.f; //printf("RedH=%f\n",RedHigh); float RedHigh = params->colorToning.redhigh / 100.f;
float GreenHigh = (100.f + float (params->colorToning.greenhigh)) / 100.f; float GreenHigh = params->colorToning.greenhigh / 100.f;
float BlueHigh = (100.f + float (params->colorToning.bluehigh)) / 100.f; float BlueHigh = params->colorToning.bluehigh / 100.f;
float SatLow = float (params->colorToning.shadowsColSat.getBottom()) / 100.f; float SatLow = float (params->colorToning.shadowsColSat.getBottom()) / 100.f;
float SatHigh = float (params->colorToning.hlColSat.getBottom()) / 100.f; float SatHigh = float (params->colorToning.hlColSat.getBottom()) / 100.f;
@ -4016,8 +4016,8 @@ void ImProcFunctions::rgbProc (Imagefloat* working, LabImage* lab, PipetteBuffer
float rl, gl, bl; float rl, gl, bl;
float xh, yh, zh; float xh, yh, zh;
float xl, yl, zl; float xl, yl, zl;
const float iplow = (float)ctColorCurve.low; const float iplow = ctColorCurve.low;
const float iphigh = (float)ctColorCurve.high; const float iphigh = ctColorCurve.high;
//2 colours //2 colours
ctColorCurve.getVal (iphigh, xh, yh, zh); ctColorCurve.getVal (iphigh, xh, yh, zh);
ctColorCurve.getVal (iplow, xl, yl, zl); ctColorCurve.getVal (iplow, xl, yl, zl);
@ -4033,70 +4033,42 @@ void ImProcFunctions::rgbProc (Imagefloat* working, LabImage* lab, PipetteBuffer
const float krh = rh / (rh + gh + bh); const float krh = rh / (rh + gh + bh);
const float kgh = gh / (rh + gh + bh); const float kgh = gh / (rh + gh + bh);
const float kbh = bh / (rh + gh + bh); const float kbh = bh / (rh + gh + bh);
strProtect = pow_F(strProtect, 0.4f);
constexpr int mode = 0;
for (int i = istart, ti = 0; i < tH; i++, ti++) { for (int i = istart, ti = 0; i < tH; i++, ti++) {
for (int j = jstart, tj = 0; j < tW; j++, tj++) { for (int j = jstart, tj = 0; j < tW; j++, tj++) {
int mode = 0;
toning2col(rtemp[ti * TS + tj], gtemp[ti * TS + tj], btemp[ti * TS + tj], rtemp[ti * TS + tj], gtemp[ti * TS + tj], btemp[ti * TS + tj], iplow, iphigh, krl, kgl, kbl, krh, kgh, kbh, SatLow, SatHigh, balanS, balanH, reducac, mode, preser, strProtect); toning2col(rtemp[ti * TS + tj], gtemp[ti * TS + tj], btemp[ti * TS + tj], rtemp[ti * TS + tj], gtemp[ti * TS + tj], btemp[ti * TS + tj], iplow, iphigh, krl, kgl, kbl, krh, kgh, kbh, SatLow, SatHigh, balanS, balanH, reducac, mode, preser, strProtect);
} }
} }
} }
// color toning with colour // colour toning with colour
else if (params->colorToning.method == "Splitco") { else if (params->colorToning.method == "Splitco") {
/* constexpr float reducac = 0.3f;
#if 1 constexpr int mode = 0;
for (int i=istart,ti=0; i<tH; i++,ti++) { strProtect = pow_F(strProtect, 0.4f);
for (int j=jstart,tj=0; j<tW; j++,tj++) {
float r = rtemp[ti*TS+tj];
float g = gtemp[ti*TS+tj];
float b = btemp[ti*TS+tj];
float ro,go,bo;
labtoning (r, g, b, ro, go, bo, 1, 0, 1, satLimit, satLimitOpacity, ctColorCurve, ctOpacityCurve, clToningcurve, cl2Toningcurve, 0.f, 1.f, wp, wip);
rtemp[ti*TS+tj] = CLIP(ro);//I used CLIP because there is a little bug in gamutLchonly that return 65536.ii intead of 65535 ==> crash
gtemp[ti*TS+tj] = CLIP(go);
btemp[ti*TS+tj] = CLIP(bo);
}
}
#else
*/
float reducac = 0.3f;
int preser = 0;
//bool execbal = params->colorToning.method=="Splitbal";
if (params->colorToning.lumamode) {
preser = 1;
}
for (int i = istart, ti = 0; i < tH; i++, ti++) { for (int i = istart, ti = 0; i < tH; i++, ti++) {
for (int j = jstart, tj = 0; j < tW; j++, tj++) { for (int j = jstart, tj = 0; j < tW; j++, tj++) {
float r = rtemp[ti * TS + tj]; const float r = rtemp[ti * TS + tj];
float g = gtemp[ti * TS + tj]; const float g = gtemp[ti * TS + tj];
float b = btemp[ti * TS + tj]; const float b = btemp[ti * TS + tj];
float lumbefore = 0.299f * r + 0.587f * g + 0.114f * b;
float ro, go, bo; float ro, go, bo;
int mode = 0; toningsmh(r, g, b, ro, go, bo, RedLow, GreenLow, BlueLow, RedMed, GreenMed, BlueMed, RedHigh, GreenHigh, BlueHigh, reducac, mode, strProtect);
toningsmh (r, g, b, ro, go, bo, RedLow, GreenLow, BlueLow, RedMed, GreenMed, BlueMed, RedHigh, GreenHigh, BlueHigh, reducac, mode, strProtect);
float lumafter = 0.299f * ro + 0.587f * go + 0.114f * bo;
float preserv = 1.f;
if (preser == 1) { if (params->colorToning.lumamode) {
preserv = lumbefore / lumafter; const float lumbefore = 0.299f * r + 0.587f * g + 0.114f * b;
const float lumafter = 0.299f * ro + 0.587f * go + 0.114f * bo;
const float preserv = lumbefore / lumafter;
ro *= preserv;
go *= preserv;
bo *= preserv;
} }
ro *= preserv; rtemp[ti * TS + tj] = CLIP(ro);
go *= preserv; gtemp[ti * TS + tj] = CLIP(go);
bo *= preserv; btemp[ti * TS + tj] = CLIP(bo);
ro = CLIP (ro);
go = CLIP (go);
bo = CLIP (bo);
rtemp[ti * TS + tj] = ro;
gtemp[ti * TS + tj] = go;
btemp[ti * TS + tj] = bo;
} }
} }
//#endif
} }
//colortoning with shift color XYZ or Lch //colortoning with shift color XYZ or Lch
@ -4676,69 +4648,41 @@ void ImProcFunctions::rgbProc (Imagefloat* working, LabImage* lab, PipetteBuffer
} }
} }
//colortoning with black and white //colour toning with black and white
if (hasColorToning) { if (hasColorToning) {
if (params->colorToning.method == "Splitco") { if (params->colorToning.method == "Splitco") {
/* constexpr float reducac = 0.5f;
#if 1 constexpr int mode = 1;
for (int i=istart,ti=0; i<tH; i++,ti++) {
for (int j=jstart,tj=0; j<tW; j++,tj++) {
float r = rtemp[ti*TS+tj];
float g = gtemp[ti*TS+tj];
float b = btemp[ti*TS+tj];
float ro,go,bo;
labtoning (r, g, b, ro, go, bo, 1, 0, 1, satLimit, satLimitOpacity, ctColorCurve, ctOpacityCurve, clToningcurve, cl2Toningcurve, 0.f, 1.f, wp, wip);
rtemp[ti*TS+tj] = CLIP(ro);//I used CLIP because there is a little bug in gamutLchonly that return 65536.ii intead of 65535 ==> crash
gtemp[ti*TS+tj] = CLIP(go);
btemp[ti*TS+tj] = CLIP(bo);
}
}
#else
*/
int preser = 0;
if (params->colorToning.lumamode) {
preser = 1;
}
float reducac = 0.3f;
#ifdef _OPENMP #ifdef _OPENMP
#pragma omp parallel for schedule(dynamic, 5) #pragma omp parallel for schedule(dynamic, 5)
#endif #endif
for (int i = 0; i < tH; i++) { for (int i = 0; i < tH; i++) {
for (int j = 0; j < tW; j++) { for (int j = 0; j < tW; j++) {
float r = tmpImage->r (i, j); const float r = tmpImage->r (i, j);
float g = tmpImage->g (i, j); const float g = tmpImage->g (i, j);
float b = tmpImage->b (i, j); const float b = tmpImage->b (i, j);
float lumbefore = 0.299f * r + 0.587f * g + 0.114f * b; const float lumbefore = 0.299f * r + 0.587f * g + 0.114f * b;
if (lumbefore < 65000.f && lumbefore > 500.f) { //reduct artifacts for highlights an extrem shadows if (lumbefore < 65000.f && lumbefore > 500.f) { //reduce artefacts for highlights and extreme shadows
float ro, go, bo; float ro, go, bo;
int mode = 1; toningsmh(r, g, b, ro, go, bo, RedLow, GreenLow, BlueLow, RedMed, GreenMed, BlueMed, RedHigh, GreenHigh, BlueHigh, reducac, mode, strProtect);
toningsmh (r, g, b, ro, go, bo, RedLow, GreenLow, BlueLow, RedMed, GreenMed, BlueMed, RedHigh, GreenHigh, BlueHigh, reducac, mode, strProtect);
float lumafter = 0.299f * ro + 0.587f * go + 0.114f * bo;
float preserv = 1.f;
if (preser == 1) { if (params->colorToning.lumamode) {
preserv = lumbefore / lumafter; const float lumafter = 0.299f * ro + 0.587f * go + 0.114f * bo;
const float preserv = lumbefore / lumafter;
ro *= preserv;
go *= preserv;
bo *= preserv;
} }
ro *= preserv; tmpImage->r(i, j) = CLIP(ro);
go *= preserv; tmpImage->g(i, j) = CLIP(go);
bo *= preserv; tmpImage->b(i, j) = CLIP(bo);
ro = CLIP (ro);
go = CLIP (go);
bo = CLIP (bo);
tmpImage->r (i, j) = ro;
tmpImage->g (i, j) = go;
tmpImage->b (i, j) = bo;
} }
} }
} }
//#endif
} }
else if (params->colorToning.method == "Splitlr") { else if (params->colorToning.method == "Splitlr") {
@ -4775,14 +4719,14 @@ void ImProcFunctions::rgbProc (Imagefloat* working, LabImage* lab, PipetteBuffer
const float krh = rh / (rh + gh + bh); const float krh = rh / (rh + gh + bh);
const float kgh = gh / (rh + gh + bh); const float kgh = gh / (rh + gh + bh);
const float kbh = bh / (rh + gh + bh); const float kbh = bh / (rh + gh + bh);
strProtect = pow_F(strProtect, 0.4f);
constexpr int mode = 1;
#ifdef _OPENMP #ifdef _OPENMP
#pragma omp parallel for schedule(dynamic, 5) #pragma omp parallel for schedule(dynamic, 5)
#endif #endif
for (int i = 0; i < tH; i++) { for (int i = 0; i < tH; i++) {
for (int j = 0; j < tW; j++) { for (int j = 0; j < tW; j++) {
int mode = 1;
toning2col(tmpImage->r(i, j), tmpImage->g(i, j), tmpImage->b(i, j), tmpImage->r(i, j), tmpImage->g(i, j), tmpImage->b(i, j), iplow, iphigh, krl, kgl, kbl, krh, kgh, kbh, SatLow, SatHigh, balanS, balanH, reducac, mode, preser, strProtect); toning2col(tmpImage->r(i, j), tmpImage->g(i, j), tmpImage->b(i, j), tmpImage->r(i, j), tmpImage->g(i, j), tmpImage->b(i, j), iplow, iphigh, krl, kgl, kbl, krh, kgh, kbh, SatLow, SatHigh, balanS, balanH, reducac, mode, preser, strProtect);
} }
} }
@ -5031,130 +4975,101 @@ void ImProcFunctions::secondeg_begin (float reducac, float vend, float &aam, flo
* @param ro red output values [0..65535] * @param ro red output values [0..65535]
* @param go green output values [0..65535] * @param go green output values [0..65535]
* @param bo blue output values [0..65535] * @param bo blue output values [0..65535]
* @param RedLow [0..1] value after transformations of sliders [-100..100] for shadows * @param RedLow [-1..1] value after transformations of sliders [-100..100] for shadows
* @param GreenLow [0..1] value after transformations of sliders [-100..100] for shadows * @param GreenLow [-1..1] value after transformations of sliders [-100..100] for shadows
* @param BlueLow [0..1] value after transformations of sliders [-100..100] for shadows * @param BlueLow [-1..1] value after transformations of sliders [-100..100] for shadows
* @param RedMed [0..1] value after transformations of sliders [-100..100] for midtones * @param RedMed [-1..1] value after transformations of sliders [-100..100] for midtones
* @param GreenMed [0..1] value after transformations of sliders [-100..100] for midtones * @param GreenMed [-1..1] value after transformations of sliders [-100..100] for midtones
* @param BlueMed [0..1] value after transformations of sliders [-100..100] for midtones * @param BlueMed [-1..1] value after transformations of sliders [-100..100] for midtones
* @param RedHigh [0..1] value after transformations of sliders [-100..100] for highlights * @param RedHigh [-1..1] value after transformations of sliders [-100..100] for highlights
* @param GreenHigh [0..1] value after transformations of sliders [-100..100] for highlights * @param GreenHigh [-1..1] value after transformations of sliders [-100..100] for highlights
* @param BlueHigh [0..1] value after transformations of sliders [-100..100] for highlights * @param BlueHigh [-1..1] value after transformations of sliders [-100..100] for highlights
* @param reducac value of the reduction in the middle of the range for second degree increse or decrease action * @param reducac value of the reduction in the middle of the range for second degree increse or decrease action
* @param mode ? * @param mode 0 = colour, 1 = Black and White
* @param preser whether to preserve luminance (if 1) or not * @param strProtect ?
**/ **/
void ImProcFunctions::toningsmh (float r, float g, float b, float &ro, float &go, float &bo, float RedLow, float GreenLow, float BlueLow, float RedMed, float GreenMed, float BlueMed, float RedHigh, float GreenHigh, float BlueHigh, float reducac, int mode, float strProtect) void ImProcFunctions::toningsmh(float r, float g, float b, float &ro, float &go, float &bo, float RedLow, float GreenLow, float BlueLow, float RedMed, float GreenMed, float BlueMed, float RedHigh, float GreenHigh, float BlueHigh, float reducac, int mode, float strProtect)
{ {
float bmu = mode == 1 ? 0.5f : 0.4f; const float v = max(r, g, b) / 65535.f;
float RedL = 1.f + (RedLow - 1.f) * 0.4f;
float GreenL = 1.f + (GreenLow - 1.f) * 0.4f;
float BlueL = 1.f + (BlueLow - 1.f) * bmu;
float h, s, v;
Color::rgb2hsv (r, g, b, h, s, v);
float ksat = 1.f;
float ksatlow = 1.f;
// float s_0=0.55f;
// float s_1=0.85f;
/*
if(mode==0) {//color
if(s < s_0) ksat=SQR((1.f/s_0)*s);
if(s > s_1) ksat=SQR((1.f/(s_1-1.f))*s - (1.f/(s_1-1.f)));
}
*/
float kl = 1.f; float kl = 1.f;
float rlo = 1.f; //0.4 0.5 float rlo; //0.4 0.5
float rlm = 1.5f; //1.1 float rlm; //1.1
float rlh = 2.2f; //1.1 float rlh; //1.1
float rlob = bmu; //for BW old mode float rlob; //for BW old mode
if (mode == 0) { //color if (mode == 0) { //colour
rlo *= pow_F (strProtect, 0.4f); //0.5 ==> 0.75 rlo = rlob = strProtect; //0.5 ==> 0.75
rlh *= pow_F (strProtect, 0.4f); rlh = 2.2f * strProtect;
rlm *= pow_F (strProtect, 0.4f); rlm = 1.5f * strProtect;
constexpr float v0 = 0.15f;
//second degree
if (v > v0) {
float aa, bb, cc;
secondeg_end (reducac, v0, aa, bb, cc);
kl = aa * v * v + bb * v + cc; //verified ==> exact
} else {
float aab, bbb;
secondeg_begin (0.7f, v0, aab, bbb);
kl = aab * v * v + bbb * v;
}
} else { //bw coefficient to preserve same results as before for satlimtopacity = 0.5 (default) } else { //bw coefficient to preserve same results as before for satlimtopacity = 0.5 (default)
rlo = strProtect * 0.8f; //0.4 rlo = strProtect * 0.8f; //0.4
rlob = strProtect; //0.5 rlob = strProtect; //0.5
rlm = strProtect * 2.2f; //1.1 rlm = strProtect * 2.2f; //1.1
rlh = strProtect * 2.4f; //1.2 rlh = strProtect * 2.4f; //1.2
}
if (mode == 0) {
rlob = rlo;
}
//fixed value of reducac=0.3
//secondeg_end (reducac, v0, aa, bb, cc);
if (mode == 1) {
reducac = 0.5f; //black and white mode
if (v > 0.15f) { if (v > 0.15f) {
kl = (-1.f / 0.85f) * v + (1.f) / 0.85f; //Low light ==> decrease action after v=0.15 kl = (-1.f / 0.85f) * v + 1.f / 0.85f; //Low light ==> decrease action after v=0.15
}
} else { //color
float v0 = 0.15f;
//second degree
float aa, bb, cc;
secondeg_end (reducac, v0, aa, bb, cc);
float aab, bbb;
secondeg_begin (0.7f, v0, aab, bbb);
if (v > v0) {
kl = aa * v * v + bb * v + cc; //verified ==> exact
} else if (mode == 0) {
kl = aab * v * v + bbb * v; //ksatlow=ksat;
} }
} }
if (RedLow != 1.f) { {
RedL = 1.f + (RedLow - 1.f) * kl * ksat * rlo; //0.4 const float corr = 20000.f * RedLow * kl * rlo;
if (RedLow > 0.f) {
if (RedLow >= 1.f) { g -= corr;
g -= 20000.f * (RedL - 1.f) * ksatlow; b -= corr;
b -= 20000.f * (RedL - 1.f) * ksatlow;
} else { } else {
r += 20000.f * (RedL - 1.f) * ksatlow; r += corr;
} }
r = CLIP (r); r = CLIP(r);
g = CLIP (g); g = CLIP(g);
b = CLIP (b); b = CLIP(b);
} }
if (GreenLow != 1.f) { {
GreenL = 1.f + (GreenLow - 1.f) * kl * ksat * rlo; //0.4 const float corr = 20000.f * GreenLow * kl * rlo;
if (GreenLow > 0.f) {
if (GreenLow >= 1.f) { r -= corr;
r -= 20000.f * (GreenL - 1.f) * ksatlow; b -= corr;
b -= 20000.f * (GreenL - 1.f) * ksatlow;
} else { } else {
g += 20000.f * (GreenL - 1.f) * ksatlow; g += corr;
} }
r = CLIP (r); r = CLIP(r);
b = CLIP (b); b = CLIP(b);
g = CLIP (g); g = CLIP(g);
} }
if (BlueLow != 1.f) {
BlueL = 1.f + (BlueLow - 1.f) * kl * ksat * rlob;
if (BlueLow >= 1.f) { {
r -= 20000.f * (BlueL - 1.f) * ksatlow; const float corr = 20000.f * BlueLow * kl * rlob;
g -= 20000.f * (BlueL - 1.f) * ksatlow;
if (BlueLow > 0.f) {
r -= corr;
g -= corr;
} else { } else {
b += 20000.f * (BlueL - 1.f) * ksatlow; b += corr;
} }
r = CLIP (r); r = CLIP(r);
g = CLIP (g); g = CLIP(g);
b = CLIP (b); b = CLIP(b);
} }
// mid tones // mid tones
float km; float km;
float v0m = 0.5f; //max action constexpr float v0m = 0.5f; //max action
if (v < v0m) { if (v < v0m) {
float aam, bbm; float aam, bbm;
@ -5168,134 +5083,112 @@ void ImProcFunctions::toningsmh (float r, float g, float b, float &ro, float &go
km = aamm * v * v + bbmm * v + ccmm; //verification good km = aamm * v * v + bbmm * v + ccmm; //verification good
} }
float RedM = 1.f + (RedMed - 1.f) * rlm; {
const float RedM = RedMed * km * rlm;
if (RedMed != 1.f) { if (RedMed > 0.f) {
RedM = 1.f + (RedMed - 1.f) * km * rlm; r += 20000.f * RedM;
g -= 10000.f * RedM;
if (RedMed >= 1.f) { b -= 10000.f * RedM;
r += 20000.f * (RedM - 1.f);
g -= 10000.f * (RedM - 1.f);
b -= 10000.f * (RedM - 1.f);
r = CLIP (r);
g = CLIP (g);
b = CLIP (b);
} else { } else {
r += 10000.f * (RedM - 1.f); r += 10000.f * RedM;
g -= 20000.f * (RedM - 1.f); g -= 20000.f * RedM;
b -= 20000.f * (RedM - 1.f); b -= 20000.f * RedM;
r = CLIP (r);
g = CLIP (g);
b = CLIP (b);
} }
r = CLIP(r);
g = CLIP(g);
b = CLIP(b);
} }
float GreenM = 1.f + (GreenMed - 1.f) * rlm; {
const float GreenM = GreenMed * km * rlm;
if (GreenMed != 1.f) { if (GreenMed > 0.f) {
GreenM = 1.f + (GreenMed - 1.f) * km * rlm; r -= 10000.f * GreenM;
g += 20000.f * GreenM;
if (GreenMed >= 1.f) { b -= 10000.f * GreenM;
r -= 10000.f * (GreenM - 1.f);
g += 20000.f * (GreenM - 1.f);
b -= 10000.f * (GreenM - 1.f);
r = CLIP (r);
g = CLIP (g);
b = CLIP (b);
} else { } else {
r -= 20000.f * (GreenM - 1.f); r -= 20000.f * GreenM;
g += 10000.f * (GreenM - 1.f); g += 10000.f * GreenM;
b -= 20000.f * (GreenM - 1.f); b -= 20000.f * GreenM;
r = CLIP (r);
g = CLIP (g);
b = CLIP (b);
} }
r = CLIP(r);
g = CLIP(g);
b = CLIP(b);
} }
float BlueM = 1.f + (BlueMed - 1.f) * rlm; {
const float BlueM = BlueMed * km * rlm;
if (BlueMed != 1.f) { if (BlueMed > 0.f) {
BlueM = 1.f + (BlueMed - 1.f) * km * rlm; r -= 10000.f * BlueM;
g -= 10000.f * BlueM;
if (BlueMed >= 1.f) { b += 20000.f * BlueM;
r -= 10000.f * (BlueM - 1.f);
g -= 10000.f * (BlueM - 1.f);
b += 20000.f * (BlueM - 1.f);
r = CLIP (r);
g = CLIP (g);
b = CLIP (b);
} else { } else {
r -= 20000.f * (BlueM - 1.f); r -= 20000.f * BlueM;
g -= 20000.f * (BlueM - 1.f); g -= 20000.f * BlueM;
b += 10000.f * (BlueM - 1.f); b += 10000.f * BlueM;
r = CLIP (r);
g = CLIP (g);
b = CLIP (b);
} }
r = CLIP(r);
g = CLIP(g);
b = CLIP(b);
} }
//high tones //high tones
float kh; constexpr float v00 = 0.8f; //max action
kh = 1.f;
float v00 = 0.8f; //max action
float aa0, bb0; float aa0, bb0;
secondeg_begin (reducac, v00, aa0, bb0); secondeg_begin (reducac, v00, aa0, bb0);
// float hmu=1.5f;
// if(mode==1) hmu=1.2f;//for BW old mode
if (v > v00) { float kh;
kh = (-1.f / (1.f - v00)) * v + (1.f) / (1.f - v00); //High tones if (v > v00) { //max action
kh = (1.f - v) / (1.f - v00); //High tones
} else { } else {
kh = aa0 * v * v + bb0 * v; //verification = good kh = v * (aa0 * v + bb0); //verification = good
} }
float RedH = 1.f + (RedHigh - 1.f) * rlh; {
float GreenH = 1.f + (GreenHigh - 1.f) * rlh; const float corr = 20000.f * RedHigh * kh * rlh; //1.2
float BlueH = 1.f + (BlueHigh - 1.f) * rlh; //1.2
if (RedHigh != 1.f) { if (RedHigh > 0.f) {
RedH = 1.f + (RedHigh - 1.f) * kh * rlh; //1.2 r += corr;
if (RedHigh >= 1.f) {
r += 20000.f * (RedH - 1.f);
r = CLIP (r);
} else { } else {
g -= 20000.f * (RedH - 1.f); g -= corr;
b -= 20000.f * (RedH - 1.f); b -= corr;
} }
g = CLIP (g); r = CLIP(r);
b = CLIP (b); g = CLIP(g);
b = CLIP(b);
} }
if (GreenHigh != 1.f) { {
GreenH = 1.f + (GreenHigh - 1.f) * kh * rlh; //1.2 const float corr = 20000.f * GreenHigh * kh * rlh; //1.2
if (GreenHigh >= 1.f) { if (GreenHigh > 0.f) {
g += 20000.f * (GreenH - 1.f); g += corr;
g = CLIP (g);
} else { } else {
r -= 20000.f * (GreenH - 1.f); r -= corr;
b -= 20000.f * (GreenH - 1.f); b -= corr;
} }
r = CLIP (r); r = CLIP(r);
b = CLIP (b); g = CLIP(g);
b = CLIP(b);
} }
if (BlueHigh != 1.f) { {
BlueH = 1.f + (BlueHigh - 1.f) * kh * rlh; //1.2 const float corr = 20000.f * BlueHigh * kh * rlh; //1.2
if (BlueHigh >= 1.f) { if (BlueHigh > 0.f) {
b += 20000.f * (BlueH - 1.f); b += corr;
b = CLIP (b);
} else { } else {
r -= 20000.f * (BlueH - 1.f); r -= corr;
g -= 20000.f * (BlueH - 1.f); g -= corr;
} }
r = CLIP (r); r = CLIP(r);
g = CLIP (g); g = CLIP(g);
b = CLIP(b);
} }
ro = r; ro = r;
@ -5320,8 +5213,8 @@ void ImProcFunctions::toning2col (float r, float g, float b, float &ro, float &g
const float lumbefore = 0.299f * r + 0.587f * g + 0.114f * b; const float lumbefore = 0.299f * r + 0.587f * g + 0.114f * b;
const float v = max(r, g, b) / 65535.f; const float v = max(r, g, b) / 65535.f;
const float rlo = pow_F (strProtect, 0.4f); //0.5 ==> 0.75 transfered value for more action const float rlo = strProtect; //0.5 ==> 0.75 transfered value for more action
const float rlh = 2.2f * pow_F (strProtect, 0.4f); const float rlh = 2.2f * strProtect;
//low tones //low tones
//second degree //second degree
@ -5352,24 +5245,24 @@ void ImProcFunctions::toning2col (float r, float g, float b, float &ro, float &g
b -= factor * krl; b -= factor * krl;
} }
g = CLIP (g); g = CLIP(g);
b = CLIP (b); b = CLIP(b);
if (kgl > 0.f) { if (kgl > 0.f) {
r -= factor * kgl; r -= factor * kgl;
b -= factor * kgl; b -= factor * kgl;
} }
r = CLIP (r); r = CLIP(r);
b = CLIP (b); b = CLIP(b);
if (kbl > 0.f) { if (kbl > 0.f) {
r -= factor * kbl; r -= factor * kbl;
g -= factor * kbl; g -= factor * kbl;
} }
r = CLIP (r); r = CLIP(r);
g = CLIP (g); g = CLIP(g);
} }
//high tones //high tones