Blob Blame History Raw
From 1b08ac44c4459e3a4cb0a84541cde05df92b6afb Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Fl=C3=B6ssie?= <floessie.mail@gmail.com>
Date: Wed, 3 Apr 2019 19:41:36 +0200
Subject: [PATCH] Fix potential bug in histogram matching (#5249)

---
 rtengine/histmatching.cc | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)

diff --git a/rtengine/histmatching.cc b/rtengine/histmatching.cc
index 79c40fba3..e48f2017a 100644
--- a/rtengine/histmatching.cc
+++ b/rtengine/histmatching.cc
@@ -69,7 +69,7 @@ CdfInfo getCdf(const IImage8 &img)
         sum += ret.cdf[i];
         ret.cdf[i] = sum;
     }
-    
+
     return ret;
 }
 
@@ -101,7 +101,7 @@ int findMatch(int val, const std::vector<int> &cdf, int j)
 void mappingToCurve(const std::vector<int> &mapping, std::vector<double> &curve)
 {
     curve.clear();
-    
+
     int idx = 15;
     for (; idx < int(mapping.size()); ++idx) {
         if (mapping[idx] >= idx) {
@@ -160,7 +160,7 @@ void mappingToCurve(const std::vector<int> &mapping, std::vector<double> &curve)
         doit(start, idx, idx > step ? step : idx / 2, true);
         doit(idx, end, step, idx - step > step / 2 && std::abs(curve[curve.size()-2] - coord(idx)) > 0.01);
     }
-    
+
     if (curve.size() > 2 && (1 - curve[curve.size()-2] <= coord(step) / 3)) {
         curve.pop_back();
         curve.pop_back();
@@ -179,7 +179,7 @@ void mappingToCurve(const std::vector<int> &mapping, std::vector<double> &curve)
             return (x - xa) / (xb - xa) * (yb - ya) + ya;
         };
     idx = -1;
-    for (size_t i = curve.size()-1; i > 0; i -= 2) {
+    for (ssize_t i = curve.size()-1; i > 0; i -= 2) {
         if (curve[i] <= 0.f) {
             idx = i+1;
             break;
@@ -207,7 +207,7 @@ void mappingToCurve(const std::vector<int> &mapping, std::vector<double> &curve)
             }
         }
     }
-        
+
     if (curve.size() < 4) {
         curve = { DCT_Linear }; // not enough points, fall back to linear
     } else {
@@ -233,7 +233,7 @@ void mappingToCurve(const std::vector<int> &mapping, std::vector<double> &curve)
 void RawImageSource::getAutoMatchedToneCurve(const ColorManagementParams &cp, std::vector<double> &outCurve)
 {
     BENCHFUN
-        
+
     if (settings->verbose) {
         std::cout << "performing histogram matching for " << getFileName() << " on the embedded thumbnail" << std::endl;
     }
@@ -275,7 +275,7 @@ void RawImageSource::getAutoMatchedToneCurve(const ColorManagementParams &cp, st
     neutral.raw.bayersensor.method = RAWParams::BayerSensor::getMethodString(RAWParams::BayerSensor::Method::FAST);
     neutral.raw.xtranssensor.method = RAWParams::XTransSensor::getMethodString(RAWParams::XTransSensor::Method::FAST);
     neutral.icm.outputProfile = ColorManagementParams::NoICMString;
-    
+
     std::unique_ptr<IImage8> source;
     {
         RawMetaDataLocation rml;
@@ -307,7 +307,7 @@ void RawImageSource::getAutoMatchedToneCurve(const ColorManagementParams &cp, st
             std::cout << "histogram matching: extracted embedded thumbnail" << std::endl;
         }
     }
-    
+
     std::unique_ptr<IImage8> target;
     {
         RawMetaDataLocation rml;