From c8bcbb89a20f718649504813349eefb3418e6459 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fl=C3=B6ssie?= Date: Tue, 18 Sep 2018 20:19:03 +0200 Subject: [PATCH] Say a few words about `weight` in `SaveFormatPanel::init()` --- rtgui/saveformatpanel.cc | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/rtgui/saveformatpanel.cc b/rtgui/saveformatpanel.cc index d5654241d..b147c5d70 100644 --- a/rtgui/saveformatpanel.cc +++ b/rtgui/saveformatpanel.cc @@ -130,11 +130,23 @@ void SaveFormatPanel::init (SaveFormat &sf) std::pair index; for (std::size_t i = 0; i < sf_templates.size(); ++i) { + // Without relating the other SaveFormat fields to the + // SaveFormat::format by additional logic the best + // way is computing a weight for fitting the input + // to one of the sf_templates. + // The format field must match exactly, tiffBits, + // tiffFloat, and pngBits fields all weigh the same. + // By providing sane sets of parameters in getFormat() + // we have perfect matches. If the parameters were + // tampered with, some entry within SaveFormat::format + // will be selected, which will be consistent again. + const int weight = 10 * (sf.format == sf_templates[i].second.format) + (sf.tiffBits == sf_templates[i].second.tiffBits) + (sf.tiffFloat == sf_templates[i].second.tiffFloat) + (sf.pngBits == sf_templates[i].second.pngBits); + if (weight > index.first) { index = {weight, i}; }