File: ColorUtils.cpp

package info (click to toggle)
structure-synth 1.5.0-2
  • links: PTS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 2,268 kB
  • ctags: 1,966
  • sloc: cpp: 10,209; python: 164; makefile: 71; sh: 15
file content (32 lines) | stat: -rw-r--r-- 944 bytes parent folder | download | duplicates (10)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#include "ColorUtils.h"
#include "../Logging/Logging.h"

using namespace SyntopiaCore::Math;
using namespace SyntopiaCore::Logging;


namespace SyntopiaCore {
	namespace Misc {	

		SyntopiaCore::Math::Vector3f ColorUtils::HSVtoRGB(SyntopiaCore::Math::Vector3f hsv) {
			/// Implementation based on: http://en.wikipedia.org/wiki/HSV_color_space
			if (hsv[0] >= 360) hsv[0]-=360;
			int Hi = (int)(hsv[0] / 60) % 6;
			double f = (hsv[0] /  60) - Hi;
			double p = hsv[2]*(1-hsv[1]);
			double q = hsv[2]*(1-f*hsv[1]);
			double t = hsv[2]*(1-(1-f)*hsv[1]);
			if (Hi == 0) return Vector3f(hsv[2],t,p);
			if (Hi == 1) return Vector3f(q,hsv[2],p);
			if (Hi == 2) return Vector3f(p,hsv[2],t);
			if (Hi == 3) return Vector3f(p,q,hsv[2]);
			if (Hi == 4) return Vector3f(t,p,hsv[2]);
			if (Hi == 5) return Vector3f(hsv[2],p,q);
			WARNING("ColorUtils::HSVtoRGB failed");
			return Vector3f(0,0,0);
		}
		
	
	}
}