Esempio n. 1
0
	hsl_colour hsl_colour::from_rgb(const colour& aColour)
	{
		double hue, saturation, lightness;
		double r = aColour.red() / 255.0, g = aColour.green() / 255.0, b = aColour.blue() / 255.0;
		double M = std::max(std::max(r, g), b);
		double m = std::min(std::min(r, g), b);
		double c = M - m;
		double h2;
		if (c == 0.0)
			h2 = undefined_hue();
		else if (M == r)
			h2 = std::fmod((g - b) / c, 6.0);
		else if (M == g)
			h2 = (b - r) / c + 2.0;
		else if (M == b)
			h2 = (r - g) / c + 4.0;
		else
			h2 = undefined_hue();
		if (h2 != undefined_hue())
		{
			hue = 60.0 * h2;
			if (hue < 0.0)
				hue += 360.0;
		}
		else
			hue = undefined_hue();
		lightness = 0.5f * (M + m);
		lightness = std::max(std::min(lightness, 1.0), 0.0);
		if (c == 0.0)
			saturation = 0.0;
		else
			saturation = c / (1.0 - std::abs(2.0 * lightness - 1.0));
		saturation = std::max(std::min(saturation, 1.0), 0.0);
		return hsl_colour(hue, saturation, lightness);
	}
Esempio n. 2
0
	hsv_colour hsv_colour::from_rgb(const colour& aColour)
	{
		double hue, saturation, value;
		double r = aColour.red() / 255.0, g = aColour.green() / 255.0, b = aColour.blue() / 255.0;
		double M = std::max(std::max(r, g), b);
		double m = std::min(std::min(r, g), b);
		double c = M - m;
		double h2;
		if (c == 0.0)
			h2 = undefined_hue();
		else if (M == r)
			h2 = std::fmod((g - b) / c, 6.0);
		else if (M == g)
			h2 = (b - r) / c + 2.0;
		else if (M == b)
			h2 = (r - g) / c + 4.0;
		else
			h2 = undefined_hue();
		if (h2 != undefined_hue())
		{
			hue = 60.0 * h2;
			if (hue < 0.0)
				hue += 360.0;
		}
		else
			hue = undefined_hue();
		value = M;
		value = std::max(std::min(value, 1.0), 0.0);
		if (c == 0.0)
			saturation = 0.0;
		else
			saturation = c / value;
		saturation = std::max(std::min(saturation, 1.0), 0.0);
		return hsv_colour(hue, saturation, value, aColour.alpha() / 255.0);
	}
Esempio n. 3
0
static void SetColour ( const colour& col )
{
	if (sizeof(col) == sizeof(float) * 4)
	{
		glColor4fv((const GLfloat*)&col);
	}
	else
	{
		glColor4f(col.red(), col.green(), col.blue(), col.alpha());
	}
}