diff --git a/rtengine/diagonalcurves.cc b/rtengine/diagonalcurves.cc index 23c1fba47..b2ac7414e 100644 --- a/rtengine/diagonalcurves.cc +++ b/rtengine/diagonalcurves.cc @@ -289,7 +289,8 @@ inline double catmull_rom_tj(double ti, double xi, double yi, double xj, double yj) { - return sqrt(sqrt(pow2(xj-xi) + pow2(yj-yi))) + ti; + static constexpr double alpha = 0.25; + return pow(sqrt(pow2(xj-xi) + pow2(yj-yi)), alpha) + ti; } @@ -303,7 +304,7 @@ inline void catmull_rom_spline(int n_points, { res_x.reserve(n_points); res_y.reserve(n_points); - + double t0 = 0; double t1 = catmull_rom_tj(t0, p0_x, p0_y, p1_x, p1_y); double t2 = catmull_rom_tj(t1, p1_x, p1_y, p2_x, p2_y); @@ -359,15 +360,13 @@ void catmull_rom_chain(int n_points, int n_cp, double *x, double *y, std::vector &res_x, std::vector &res_y) { static const double epsilon = 1e-5; - // double xr = x[1] - x[0]; - // double yr = y[1] - y[0]; - double xr = x[n_cp-1] - x[0]; - double yr = y[n_cp-1] - y[0]; - double x_first = x[0] - xr * 0.1; + double xr = x[1] - x[0]; + double yr = y[1] - y[0]; + double x_first = x[0] - xr * 0.01; double y_first = xr > epsilon ? (yr / xr) * (x_first - x[0]) + y[0] : y[0]; - // xr = x[n_cp-1] - x[n_cp-2]; - // yr = y[n_cp-1] - x[n_cp-2]; - double x_last = x[n_cp-1] + xr * 0.1; + xr = x[n_cp-1] - x[n_cp-2]; + yr = y[n_cp-1] - x[n_cp-2]; + double x_last = x[n_cp-1] + xr * 0.01; double y_last = xr > epsilon ? (yr / xr) * (x_last - x[0]) + y[0] : y[0]; int segments = n_cp - 1; diff --git a/rtengine/histmatching.cc b/rtengine/histmatching.cc index 184152ac8..d4f236d0e 100644 --- a/rtengine/histmatching.cc +++ b/rtengine/histmatching.cc @@ -221,20 +221,26 @@ void mappingToCurve(const std::vector &mapping, std::vector &curve) curve = { DCT_Linear }; // not enough points, fall back to linear } else { CubicSplineCurve c(curve); - curve.pop_back(); - curve.pop_back(); - double gap = coord(step); - while (1 - curve[curve.size()-2] > gap) { - double x = curve[curve.size()-2] + gap; - if (1 - x <= gap / 3) { - break; - } + double mid = coord(idx); + double x = 0.0; + constexpr double shgap = 0.075; + curve = { DCT_Spline }; + while (mid - x > shgap / 2) { curve.push_back(x); curve.push_back(c.getVal(x)); + x += shgap; + } + curve.push_back(mid); + curve.push_back(c.getVal(mid)); + constexpr double hlgap = 0.2; + x = mid + hlgap; + while (1 - x > hlgap / 2) { + curve.push_back(x); + curve.push_back(c.getVal(x)); + x += hlgap; } curve.push_back(1.0); curve.push_back(1.0); - curve.insert(curve.begin(), DCT_Spline); } }