| 104 | auto const kRGBAToPredefined = buildRGBAToPredefined(); |
| 105 | |
| 106 | PredefinedColor MapPredefinedColor(uint32_t rgba) |
| 107 | { |
| 108 | auto closestColor = kRGBAToPredefined[0].predefinedColor; |
| 109 | auto minDistance = std::numeric_limits<int>::max(); |
| 110 | for (auto const & [rgbaGarmin, color] : kRGBAToPredefined) |
| 111 | { |
| 112 | auto const distance = ColorDistance(rgba, rgbaGarmin); |
| 113 | |
| 114 | if (distance == 0) |
| 115 | return color; // Exact match. |
| 116 | |
| 117 | if (distance < minDistance) |
| 118 | { |
| 119 | minDistance = distance; |
| 120 | closestColor = color; |
| 121 | } |
| 122 | } |
| 123 | return closestColor; |
| 124 | } |
| 125 | |
| 126 | // Garmin extensions spec: https://www8.garmin.com/xmlschemas/GpxExtensionsv3.xsd |
| 127 | // Color mapping: https://help.locusmap.eu/topic/extend-garmin-gpx-compatibilty |
no test coverage detected