From 3079c2a1716e856e15d90c275a9e4cbf781690b7 Mon Sep 17 00:00:00 2001 From: Rainer Kartmann <rainer.kartmann@kit.edu> Date: Mon, 30 Mar 2020 17:55:08 +0200 Subject: [PATCH] Add interpol::linear_hsv() --- SimoxUtility/color/interpolation.cpp | 10 ++++++++++ SimoxUtility/color/interpolation.h | 4 ++++ 2 files changed, 14 insertions(+) diff --git a/SimoxUtility/color/interpolation.cpp b/SimoxUtility/color/interpolation.cpp index e3624cd34..ff9ca6ee3 100644 --- a/SimoxUtility/color/interpolation.cpp +++ b/SimoxUtility/color/interpolation.cpp @@ -1,5 +1,7 @@ #include "interpolation.h" +#include "hsv.h" + namespace simox::color { @@ -9,4 +11,12 @@ namespace simox::color return Color(((1 - t) * lhs.to_vector4f() + t * rhs.to_vector4f()).eval()); } + + Color linear_hsv(float t, const Color& lhs, const Color& rhs) + { + const Eigen::Vector3f lhs_hsv = rgb_to_hsv(lhs.to_vector3f()); + const Eigen::Vector3f rhs_hsv = rgb_to_hsv(rhs.to_vector3f()); + return Color(hsv_to_rgb(((1 - t) * lhs_hsv + t * rhs_hsv).eval())); + } + } diff --git a/SimoxUtility/color/interpolation.h b/SimoxUtility/color/interpolation.h index 08bb88418..50795caaa 100644 --- a/SimoxUtility/color/interpolation.h +++ b/SimoxUtility/color/interpolation.h @@ -6,8 +6,12 @@ namespace simox::color::interpol { + /// Interpolate linearly in RGB space. Color linear(float t, const Color& lhs, const Color& rhs); + /// Interpolate linearly in HSV space. (`lhs` and `rhs` are expected to be RGB.) + Color linear_hsv(float t, const Color& lhs, const Color& rhs); + } -- GitLab