Auto Levels calculates wrong lightness value, which leads to crash of RT, Issue 2325 / Credits: Hombre, Ingo
This commit is contained in:
@@ -874,6 +874,8 @@ void CurveFactory::curveCL ( bool & clcutili,const std::vector<double>& clcurveP
|
|||||||
if (contr>0.00001 || contr<-0.00001) {
|
if (contr>0.00001 || contr<-0.00001) {
|
||||||
utili=true;
|
utili=true;
|
||||||
|
|
||||||
|
DiagonalCurve* contrastcurve = NULL;
|
||||||
|
|
||||||
// compute mean luminance of the image with the curve applied
|
// compute mean luminance of the image with the curve applied
|
||||||
int sum = 0;
|
int sum = 0;
|
||||||
float avg = 0;
|
float avg = 0;
|
||||||
@@ -883,31 +885,47 @@ void CurveFactory::curveCL ( bool & clcutili,const std::vector<double>& clcurveP
|
|||||||
//sqavg += dcurve[i]*dcurve[i] * histogram[i];
|
//sqavg += dcurve[i]*dcurve[i] * histogram[i];
|
||||||
sum += histogram[i];
|
sum += histogram[i];
|
||||||
}
|
}
|
||||||
avg /= sum;
|
if(sum) {
|
||||||
//sqavg /= sum;
|
avg /= sum;
|
||||||
//float stddev = sqrt(sqavg-avg*avg);
|
//sqavg /= sum;
|
||||||
// printf("avg=%f\n",avg);
|
//float stddev = sqrt(sqavg-avg*avg);
|
||||||
|
// printf("avg=%f\n",avg);
|
||||||
|
|
||||||
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||||
std::vector<double> contrastcurvePoints;
|
std::vector<double> contrastcurvePoints;
|
||||||
contrastcurvePoints.resize(9);
|
contrastcurvePoints.resize(9);
|
||||||
contrastcurvePoints.at(0) = double(DCT_NURBS);
|
contrastcurvePoints.at(0) = double(DCT_NURBS);
|
||||||
|
|
||||||
contrastcurvePoints.at(1) = 0.; // black point. Value in [0 ; 1] range
|
contrastcurvePoints.at(1) = 0.; // black point. Value in [0 ; 1] range
|
||||||
contrastcurvePoints.at(2) = 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(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(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(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(6) = avg+(1-avg)*(0.6+contr/250.0); // value at shoulder point
|
||||||
|
|
||||||
contrastcurvePoints.at(7) = 1.; // white point
|
contrastcurvePoints.at(7) = 1.; // white point
|
||||||
contrastcurvePoints.at(8) = 1.; // value at white point
|
contrastcurvePoints.at(8) = 1.; // value at white point
|
||||||
|
|
||||||
DiagonalCurve* contrastcurve = new DiagonalCurve (contrastcurvePoints, CURVES_MIN_POLY_POINTS/skip);
|
contrastcurve = new DiagonalCurve (contrastcurvePoints, CURVES_MIN_POLY_POINTS/skip);
|
||||||
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||||
|
} else {
|
||||||
|
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||||
|
// sum has an invalid value (next to 0, producing a division by zero, so we create a fake contrast curve, producing a white image
|
||||||
|
std::vector<double> contrastcurvePoints;
|
||||||
|
contrastcurvePoints.resize(5);
|
||||||
|
contrastcurvePoints.at(0) = double(DCT_NURBS);
|
||||||
|
|
||||||
|
contrastcurvePoints.at(1) = 0.; // black point. Value in [0 ; 1] range
|
||||||
|
contrastcurvePoints.at(2) = 1.; // black point. Value in [0 ; 1] range
|
||||||
|
|
||||||
|
contrastcurvePoints.at(3) = 1.; // white point
|
||||||
|
contrastcurvePoints.at(4) = 1.; // value at white point
|
||||||
|
|
||||||
|
contrastcurve = new DiagonalCurve (contrastcurvePoints, CURVES_MIN_POLY_POINTS/skip);
|
||||||
|
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||||
|
}
|
||||||
// apply contrast enhancement
|
// apply contrast enhancement
|
||||||
for (int i=0; i<32768; i++) {
|
for (int i=0; i<32768; i++) {
|
||||||
dcurve[i] = contrastcurve->getVal (dcurve[i]);
|
dcurve[i] = contrastcurve->getVal (dcurve[i]);
|
||||||
|
@@ -4290,6 +4290,7 @@ fclose(f);*/
|
|||||||
if (expcomp<0.0) expcomp = 0.0;*/
|
if (expcomp<0.0) expcomp = 0.0;*/
|
||||||
if (expcomp<-5.0) expcomp = -5.0;
|
if (expcomp<-5.0) expcomp = -5.0;
|
||||||
if (expcomp>12.0) expcomp = 12.0;
|
if (expcomp>12.0) expcomp = 12.0;
|
||||||
|
bright = max(-100,min(bright,100));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user