diff --git a/lib/pbio/src/color/util.c b/lib/pbio/src/color/util.c index 40b73e7d5..265546c03 100644 --- a/lib/pbio/src/color/util.c +++ b/lib/pbio/src/color/util.c @@ -5,6 +5,7 @@ #include +// Cost function between two colors a and b. The lower, the closer they are. int32_t pbio_get_hsv_cost(const pbio_color_hsv_t *x, const pbio_color_hsv_t *c) { // Calculate the hue error @@ -32,7 +33,8 @@ int32_t pbio_get_hsv_cost(const pbio_color_hsv_t *x, const pbio_color_hsv_t *c) return hue_error * hue_error + 5 * saturation_error * saturation_error + 2 * value_error * value_error; } -int32_t pbio_get_cone_cost(const pbio_color_hsv_t *hsv_a, const pbio_color_hsv_t *hsv_b) { +// gets squared cartesian distance between hsv colors mapped into a chroma-value-cone +int32_t pbio_get_cone_cost(const pbio_color_hsv_t *hsv_a, const pbio_color_hsv_t *hsv_b, const int32_t chroma_weight) { pbio_color_hsv_fix16_t a, b; pbio_color_hsv_to_fix16(hsv_a, &a); diff --git a/pybricks/util_pb/pb_color_map.c b/pybricks/util_pb/pb_color_map.c index 8772db06c..71d46885d 100644 --- a/pybricks/util_pb/pb_color_map.c +++ b/pybricks/util_pb/pb_color_map.c @@ -68,11 +68,6 @@ void pb_color_map_save_default(mp_obj_t *color_map) { *color_map = MP_OBJ_FROM_PTR(&pb_color_map_default); } -// Cost function between two colors a and b. The lower, the closer they are. -static int32_t get_hsv_cost(const pbio_color_hsv_t *a, const pbio_color_hsv_t *b) { - return pbio_get_cone_cost(a, b); -} - // Get a discrete color that matches the given hsv values most closely mp_obj_t pb_color_map_get_color(mp_obj_t *color_map, pbio_color_hsv_t *hsv) { @@ -90,7 +85,7 @@ mp_obj_t pb_color_map_get_color(mp_obj_t *color_map, pbio_color_hsv_t *hsv) { for (size_t i = 0; i < n; i++) { // Evaluate the cost function - cost_now = get_hsv_cost(hsv, pb_type_Color_get_hsv(colors[i])); + cost_now = pbio_get_hsv_cost(hsv, pb_type_Color_get_hsv(colors[i])); // If cost is less than before, update the minimum and the match if (cost_now < cost_min) {