Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOlga Khlopkova <o.khlopkova@corp.mail.ru>2020-10-02 12:46:35 +0300
committermpimenov <mpimenov@users.noreply.github.com>2020-10-02 15:22:14 +0300
commitc23418eb221ddbc4d5ef51a605094277744eca19 (patch)
treeae9291424e937e6ef215fddf46c02ead39b7cadf /transit
parente52d0ef59acb8057f2881c3c4415b9aaad8f31e2 (diff)
[transit] cmetric for measuring of colors distance.
Diffstat (limited to 'transit')
-rw-r--r--transit/world_feed/color_picker.cpp20
-rw-r--r--transit/world_feed/color_picker.hpp1
2 files changed, 18 insertions, 3 deletions
diff --git a/transit/world_feed/color_picker.cpp b/transit/world_feed/color_picker.cpp
index b1e70e0846..395dbe9d99 100644
--- a/transit/world_feed/color_picker.cpp
+++ b/transit/world_feed/color_picker.cpp
@@ -16,11 +16,25 @@ std::tuple<double, double, double> GetColors(dp::Color const & color)
return {color.GetRedF(), color.GetGreenF(), color.GetBlueF()};
}
-double GetSquareDistance(dp::Color const & color1, dp::Color const & color2)
+double GetDistance(dp::Color const & color1, dp::Color const & color2)
{
auto [r1, g1, b1] = GetColors(color1);
auto [r2, g2, b2] = GetColors(color2);
- return (r1 - r2) * (r1 - r2) + (g1 - g2) * (g1 - g2) + (b1 - b2) * (b1 - b2);
+
+ // We use the cmetric (Color metric) for calculating the distance between two colors.
+ // https://en.wikipedia.org/wiki/Color_difference
+ // It reflects human perception of closest match for a specific colour. The formula weights RGB
+ // values to better fit eye perception and performs well at proper determinations of colors
+ // contributions, brightness of these colors, and degree to which human vision has less tolerance
+ // for these colors.
+ double const redMean = (r1 + r2) / 2.0;
+
+ double const redDelta = r1 - r2;
+ double const greenDelta = g1 - g2;
+ double const blueDelta = b1 - b2;
+
+ return (2.0 + redMean / 256.0) * redDelta * redDelta + 4 * greenDelta * greenDelta +
+ (2.0 + (255.0 - redMean) / 256.0) * blueDelta * blueDelta;
}
} // namespace
@@ -60,7 +74,7 @@ std::string ColorPicker::GetNearestColor(std::string const & rgb)
for (auto const & [name, transitColor] : m_drapeClearColors)
{
- if (double const dist = GetSquareDistance(color, transitColor); dist < minDist)
+ if (double const dist = GetDistance(color, transitColor); dist < minDist)
{
minDist = dist;
nearestColor = name;
diff --git a/transit/world_feed/color_picker.hpp b/transit/world_feed/color_picker.hpp
index 5f3318e557..1814624bef 100644
--- a/transit/world_feed/color_picker.hpp
+++ b/transit/world_feed/color_picker.hpp
@@ -12,6 +12,7 @@ class ColorPicker
{
public:
ColorPicker();
+ // Picks the closest match for the |rgb| color from our transit palette.
std::string GetNearestColor(std::string const & rgb);
private: