From ee345ba376f15069c076fb0f8d1100ad6d4a62ce Mon Sep 17 00:00:00 2001 From: Alberto Griggio Date: Mon, 2 Jul 2018 17:41:50 +0200 Subject: [PATCH 1/2] histmatching: use fewer points in the auto-matched curve makes editing the curve by hand much easier --- rtengine/histmatching.cc | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/rtengine/histmatching.cc b/rtengine/histmatching.cc index 0faa8c357..5db504816 100644 --- a/rtengine/histmatching.cc +++ b/rtengine/histmatching.cc @@ -100,7 +100,6 @@ void mappingToCurve(const std::vector &mapping, std::vector &curve) { curve.clear(); - const int npoints = 8; int idx = 15; for (; idx < int(mapping.size()); ++idx) { if (mapping[idx] >= idx) { @@ -114,7 +113,6 @@ void mappingToCurve(const std::vector &mapping, std::vector &curve) } } } - int step = std::max(int(mapping.size())/npoints, 1); auto coord = [](int v) -> double { return double(v)/255.0; }; auto doit = @@ -147,9 +145,17 @@ void mappingToCurve(const std::vector &mapping, std::vector &curve) while (start < idx && (mapping[start] < 0 || start < idx / 2)) { ++start; } - - doit(start, idx, idx > step ? step : idx / 2, true); - doit(idx, int(mapping.size()), step, idx - step > step / 2 && std::abs(curve[curve.size()-2] - coord(idx)) > 0.01); + + const int npoints = 8; + int step = std::max(int(mapping.size())/npoints, 1); + int end = mapping.size(); + if (idx <= end / 3) { + doit(start, idx, idx / 2, true); + doit(idx, end, (end - idx) / 3, false); + } else { + doit(start, idx, idx > step ? step : idx / 2, true); + doit(idx, int(mapping.size()), step, idx - step > step / 2 && std::abs(curve[curve.size()-2] - coord(idx)) > 0.01); + } if (curve.size() > 2 && (1 - curve[curve.size()-2] <= step / (256.0 * 3))) { curve.pop_back(); From eedad21326328321150fcbaf773f982a10403f47 Mon Sep 17 00:00:00 2001 From: Alberto Griggio Date: Tue, 10 Jul 2018 11:05:35 +0200 Subject: [PATCH 2/2] histmatching: use the same amount of pixels for the matching regardless of the image orientation --- rtengine/histmatching.cc | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/rtengine/histmatching.cc b/rtengine/histmatching.cc index 5db504816..de02881b6 100644 --- a/rtengine/histmatching.cc +++ b/rtengine/histmatching.cc @@ -51,7 +51,7 @@ CdfInfo getCdf(const IImage8 &img) for (int y = 0; y < img.getHeight(); ++y) { for (int x = 0; x < img.getWidth(); ++x) { - int lum = LIM(0, int(Color::rgbLuminance(float(img.r(y, x)), float(img.g(y, x)), float(img.b(y, x)))), 255); + int lum = LIM(int(Color::rgbLuminance(float(img.r(y, x)), float(img.g(y, x)), float(img.b(y, x)))), 0, 255); ++ret.cdf[lum]; } } @@ -206,6 +206,9 @@ void RawImageSource::getAutoMatchedToneCurve(const ColorManagementParams &cp, st int fw, fh; getFullSize(fw, fh, TR_NONE); + if (getRotateDegree() == 90 || getRotateDegree() == 270) { + std::swap(fw, fh); + } int skip = 3; if (settings->verbose) {