33{
34 std::string best_match_id = "";
35 int best_color_distance = 0xffffffff;
36
38 if (p.is_visible && p.is_compatible &&
39
42
43
44 unsigned int target_color_value = std::stoul(color_rgba.substr(0, color_rgba.length() - 2), nullptr, 16);
45
46 std::string p_color = p.config.opt_string("default_filament_colour", 0u);
47 unsigned int p_color_value;
48 if (!p_color.empty()) {
49 size_t hash_pos = p_color.find("#");
50 p_color_value = std::stoul(p_color.substr(hash_pos != std::string::npos ? hash_pos + 1 : 0), nullptr, 16);
51 } else {
52
53
54
55 p_color_value = 0;
56 }
57
58
59 int dr = ((target_color_value & 0xff) - (p_color_value & 0xff));
60 int dg = (((target_color_value >> 8) & 0xff) - ((p_color_value >> 8) & 0xff));
61 int db = (((target_color_value >> 16) & 0xff) - ((p_color_value >> 16) & 0xff));
62 unsigned int distance = dr * dr + dg * dg + db * db;
63
64 if (distance < best_color_distance) {
65 best_color_distance = distance;
66 best_match_id = p.filament_id;
67 }
68 }
69 }
70 return best_match_id;
71}
std::string & opt_string(const t_config_option_key &opt_key, bool create=false)
Definition Config.hpp:3042
const std::deque< Preset > & get_presets() const
Definition Preset.hpp:781
const Preset * get_preset_base(const Preset &child) const
Definition Preset.cpp:3693
DynamicPrintConfig config
Definition Preset.hpp:300
zaa_minimize_perimeter_height filament_type((ConfigOptionBools, filament_soluble))((ConfigOptionStrings