mirror of
https://github.com/genodelabs/genode.git
synced 2024-12-19 13:47:56 +00:00
gems: HSV-to-RGB color-conversion function
This commit is contained in:
parent
fd45a70acc
commit
e45e01ee8e
46
repos/gems/include/gems/color_hsv.h
Normal file
46
repos/gems/include/gems/color_hsv.h
Normal file
@ -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 <util/color.h>
|
||||
|
||||
/**
|
||||
* 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_ */
|
Loading…
Reference in New Issue
Block a user