CiColor PhilipsHueLight::rgbToCiColor(float red, float green, float blue) {
	// Apply gamma correction.
	float r = (red > 0.04045f) ? powf((red + 0.055f) / (1.0f + 0.055f), 2.4f) : (red / 12.92f);
	float g = (green > 0.04045f) ? powf((green + 0.055f) / (1.0f + 0.055f), 2.4f) : (green / 12.92f);
	float b = (blue > 0.04045f) ? powf((blue + 0.055f) / (1.0f + 0.055f), 2.4f) : (blue / 12.92f);
	// Convert to XYZ space.
	float X = r * 0.649926f + g * 0.103455f + b * 0.197109f;
	float Y = r * 0.234327f + g * 0.743075f + b * 0.022598f;
	float Z = r * 0.0000000f + g * 0.053077f + b * 1.035763f;
	// Convert to x,y space.
	float cx = X / (X + Y + Z);
	float cy = Y / (X + Y + Z);
	if (std::isnan(cx)) {
		cx = 0.0f;
	}
	if (std::isnan(cy)) {
		cy = 0.0f;
	}
	// RGB to HSV/B Conversion after gamma correction use V for brightness, not Y from XYZ Space.
	float bri = fmax(fmax(r, g), b);
	CiColor xy = { cx, cy, bri };
	// Check if the given XY value is within the color reach of our lamps.
	if (!isPointInLampsReach(xy)) {
		// It seems the color is out of reach let's find the closes color we can produce with our lamp and send this XY value out.
		CiColor pAB = getClosestPointToPoint(colorSpace.red, colorSpace.green, xy);
		CiColor pAC = getClosestPointToPoint(colorSpace.blue, colorSpace.red, xy);
		CiColor pBC = getClosestPointToPoint(colorSpace.green, colorSpace.blue, xy);
		// Get the distances per point and see which point is closer to our Point.
		float dAB = getDistanceBetweenTwoPoints(xy, pAB);
		float dAC = getDistanceBetweenTwoPoints(xy, pAC);
		float dBC = getDistanceBetweenTwoPoints(xy, pBC);
		float lowest = dAB;
		CiColor closestPoint = pAB;
		if (dAC < lowest) {
			lowest = dAC;
			closestPoint = pAC;
		}
		if (dBC < lowest) {
			lowest = dBC;
			closestPoint = pBC;
		}
		// Change the xy value to a value which is within the reach of the lamp.
		xy.x = closestPoint.x;
		xy.y = closestPoint.y;
	}
	return xy;
}
Пример #2
0
MyLines::MyLines(float x11, float y11, float  x22, float  y22, float anglee){
	x1 = x11;
	x2 = x22;
	y1 = y11;
	y2 = y22;


	slope = (y22 - y11) / (x22 - x11);

	angle = anglee;
	midpointX = (x2 + x1) / 2;
	midpointY = (y2 + y1) / 2;
	length = getDistanceBetweenTwoPoints(x1, y1, x2, y2);
	ceilLength = ceil(length);
}