#include "KernelParams.h" float linear_interpolate(float output, QList x, QList 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 ¶ms) { float output = input + params.gain; QList log_input_level = {0, params.app_min_log_input_level, params.app_max_log_input_level, params.max_log_input_level}; QList 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; }