1c6b281
From 1b08ac44c4459e3a4cb0a84541cde05df92b6afb Mon Sep 17 00:00:00 2001
1c6b281
From: =?UTF-8?q?Fl=C3=B6ssie?= <floessie.mail@gmail.com>
1c6b281
Date: Wed, 3 Apr 2019 19:41:36 +0200
1c6b281
Subject: [PATCH] Fix potential bug in histogram matching (#5249)
1c6b281
1c6b281
---
1c6b281
 rtengine/histmatching.cc | 16 ++++++++--------
1c6b281
 1 file changed, 8 insertions(+), 8 deletions(-)
1c6b281
1c6b281
diff --git a/rtengine/histmatching.cc b/rtengine/histmatching.cc
1c6b281
index 79c40fba3..e48f2017a 100644
1c6b281
--- a/rtengine/histmatching.cc
1c6b281
+++ b/rtengine/histmatching.cc
1c6b281
@@ -69,7 +69,7 @@ CdfInfo getCdf(const IImage8 &img)
1c6b281
         sum += ret.cdf[i];
1c6b281
         ret.cdf[i] = sum;
1c6b281
     }
1c6b281
-    
1c6b281
+
1c6b281
     return ret;
1c6b281
 }
1c6b281
 
1c6b281
@@ -101,7 +101,7 @@ int findMatch(int val, const std::vector<int> &cdf, int j)
1c6b281
 void mappingToCurve(const std::vector<int> &mapping, std::vector<double> &curve)
1c6b281
 {
1c6b281
     curve.clear();
1c6b281
-    
1c6b281
+
1c6b281
     int idx = 15;
1c6b281
     for (; idx < int(mapping.size()); ++idx) {
1c6b281
         if (mapping[idx] >= idx) {
1c6b281
@@ -160,7 +160,7 @@ void mappingToCurve(const std::vector<int> &mapping, std::vector<double> &curve)
1c6b281
         doit(start, idx, idx > step ? step : idx / 2, true);
1c6b281
         doit(idx, end, step, idx - step > step / 2 && std::abs(curve[curve.size()-2] - coord(idx)) > 0.01);
1c6b281
     }
1c6b281
-    
1c6b281
+
1c6b281
     if (curve.size() > 2 && (1 - curve[curve.size()-2] <= coord(step) / 3)) {
1c6b281
         curve.pop_back();
1c6b281
         curve.pop_back();
1c6b281
@@ -179,7 +179,7 @@ void mappingToCurve(const std::vector<int> &mapping, std::vector<double> &curve)
1c6b281
             return (x - xa) / (xb - xa) * (yb - ya) + ya;
1c6b281
         };
1c6b281
     idx = -1;
1c6b281
-    for (size_t i = curve.size()-1; i > 0; i -= 2) {
1c6b281
+    for (ssize_t i = curve.size()-1; i > 0; i -= 2) {
1c6b281
         if (curve[i] <= 0.f) {
1c6b281
             idx = i+1;
1c6b281
             break;
1c6b281
@@ -207,7 +207,7 @@ void mappingToCurve(const std::vector<int> &mapping, std::vector<double> &curve)
1c6b281
             }
1c6b281
         }
1c6b281
     }
1c6b281
-        
1c6b281
+
1c6b281
     if (curve.size() < 4) {
1c6b281
         curve = { DCT_Linear }; // not enough points, fall back to linear
1c6b281
     } else {
1c6b281
@@ -233,7 +233,7 @@ void mappingToCurve(const std::vector<int> &mapping, std::vector<double> &curve)
1c6b281
 void RawImageSource::getAutoMatchedToneCurve(const ColorManagementParams &cp, std::vector<double> &outCurve)
1c6b281
 {
1c6b281
     BENCHFUN
1c6b281
-        
1c6b281
+
1c6b281
     if (settings->verbose) {
1c6b281
         std::cout << "performing histogram matching for " << getFileName() << " on the embedded thumbnail" << std::endl;
1c6b281
     }
1c6b281
@@ -275,7 +275,7 @@ void RawImageSource::getAutoMatchedToneCurve(const ColorManagementParams &cp, st
1c6b281
     neutral.raw.bayersensor.method = RAWParams::BayerSensor::getMethodString(RAWParams::BayerSensor::Method::FAST);
1c6b281
     neutral.raw.xtranssensor.method = RAWParams::XTransSensor::getMethodString(RAWParams::XTransSensor::Method::FAST);
1c6b281
     neutral.icm.outputProfile = ColorManagementParams::NoICMString;
1c6b281
-    
1c6b281
+
1c6b281
     std::unique_ptr<IImage8> source;
1c6b281
     {
1c6b281
         RawMetaDataLocation rml;
1c6b281
@@ -307,7 +307,7 @@ void RawImageSource::getAutoMatchedToneCurve(const ColorManagementParams &cp, st
1c6b281
             std::cout << "histogram matching: extracted embedded thumbnail" << std::endl;
1c6b281
         }
1c6b281
     }
1c6b281
-    
1c6b281
+
1c6b281
     std::unique_ptr<IImage8> target;
1c6b281
     {
1c6b281
         RawMetaDataLocation rml;