You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

42 lines
1.1 KiB

#include "KernelParams.h"
float linear_interpolate(float output, QList<float> x, QList<float> y, qint32 num)
{
float slop = 0.0f;
if(output <= x[0])
{
output = y[0];
}
else if(output >= x[num - 1])
{
output = y[num - 1];
}
else
{
for(qint32 i = 1; i < num; i++)
{
if(output < x[i])
{
slop = (y[i] - y[i - 1]) / (x[i] - x[i - 1]);
output = y[i - 1] + ((output - x[i - 1]) * slop);
break;
}
}
}
return output;
}
float DynamicContrast(float input, DynamicContrastParameters &params)
{
float output = input + params.gain;
QList<float> log_input_level = {0, params.app_min_log_input_level, params.app_max_log_input_level, params.max_log_input_level};
QList<float> output_level = {0, params.min_output_level, params.max_output_level, 255};
output = linear_interpolate(output, log_input_level, output_level, ARRAY_SIZE(output_level));
output = linear_interpolate(output, params.const_piecewise_x, params.const_piecewise_y, ARRAY_SIZE(params.const_piecewise_x));
return output;
}