From e45e01ee8e8fa9b4a6a35d7cf41b2e5a670dc272 Mon Sep 17 00:00:00 2001 From: Norman Feske Date: Wed, 1 Jul 2015 11:19:12 +0200 Subject: [PATCH] gems: HSV-to-RGB color-conversion function --- repos/gems/include/gems/color_hsv.h | 46 +++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 repos/gems/include/gems/color_hsv.h diff --git a/repos/gems/include/gems/color_hsv.h b/repos/gems/include/gems/color_hsv.h new file mode 100644 index 0000000000..0c3df824f4 --- /dev/null +++ b/repos/gems/include/gems/color_hsv.h @@ -0,0 +1,46 @@ +/* + * \brief Color-conversion between HSV and RGB color spaces + * \date 2015-07-01 + * \author Norman Feske + */ + +/* + * Copyright (C) 2015 Genode Labs GmbH + * + * This file is part of the Genode OS framework, which is distributed + * under the terms of the GNU General Public License version 2. + */ + +#ifndef _INCLUDE__GEMS__COLOR_HSV_H_ +#define _INCLUDE__GEMS__COLOR_HSV_H_ + +#include + +/** + * Create color from specified hue, saturation, and value + */ +static inline Genode::Color color_from_hsv(unsigned h, unsigned s, unsigned v) +{ + typedef Genode::Color Color; + + if (s == 0) + return Color(v, v, v); + + unsigned char const region = h / 43; + unsigned char const remainder = (h - (region*43)) * 6; + unsigned char const p = (v*(255 - s)) >> 8, + q = (v*(255 - ((s*remainder) >> 8))) >> 8, + t = (v*(255 - ((s*(255 - remainder)) >> 8))) >> 8; + + switch (region) { + case 0: return Color(v, t, p); + case 1: return Color(q, v, p); + case 2: return Color(p, v, t); + case 3: return Color(p, q, v); + case 4: return Color(t, p, v); + } + + return Color(v, p, q); +} + +#endif /* _INCLUDE__GEMS__COLOR_HSV_H_ */