@@ -36,8 +36,7 @@ int LedDevicePhilipsHue::write(const std::vector<ColorRgb> & ledValues) {
36
36
// Get lamp.
37
37
HueLamp& lamp = lamps.at (idx);
38
38
// Scale colors from [0, 255] to [0, 1] and convert to xy space.
39
- ColorPoint xy;
40
- rgbToXYBrightness (color.red / 255 .0f , color.green / 255 .0f , color.blue / 255 .0f , lamp, xy);
39
+ ColorPoint xy = rgbToXYBrightness (color.red / 255 .0f , color.green / 255 .0f , color.blue / 255 .0f , lamp);
41
40
// Write color if color has been changed.
42
41
if (xy != lamp.color ) {
43
42
// Send adjust color command in JSON format.
@@ -192,7 +191,7 @@ float LedDevicePhilipsHue::getDistanceBetweenTwoPoints(ColorPoint p1, ColorPoint
192
191
return sqrt (dx * dx + dy * dy);
193
192
}
194
193
195
- void LedDevicePhilipsHue::rgbToXYBrightness (float red, float green, float blue, HueLamp lamp, ColorPoint& xy ) {
194
+ ColorPoint LedDevicePhilipsHue::rgbToXYBrightness (float red, float green, float blue, HueLamp lamp) {
196
195
// Apply gamma correction.
197
196
float r = (red > 0 .04045f ) ? powf ((red + 0 .055f ) / (1 .0f + 0 .055f ), 2 .4f ) : (red / 12 .92f );
198
197
float g = (green > 0 .04045f ) ? powf ((green + 0 .055f ) / (1 .0f + 0 .055f ), 2 .4f ) : (green / 12 .92f );
@@ -202,16 +201,15 @@ void LedDevicePhilipsHue::rgbToXYBrightness(float red, float green, float blue,
202
201
float Y = r * 0 .234327f + g * 0 .743075f + b * 0 .022598f ;
203
202
float Z = r * 0 .0000000f + g * 0 .053077f + b * 1 .035763f ;
204
203
// Convert to x,y space.
205
- float cx = X / (X + Y + Z + 0 . 0000001f );
206
- float cy = Y / (X + Y + Z + 0 . 0000001f );
204
+ float cx = X / (X + Y + Z);
205
+ float cy = Y / (X + Y + Z);
207
206
if (isnan (cx)) {
208
207
cx = 0 .0f ;
209
208
}
210
209
if (isnan (cy)) {
211
210
cy = 0 .0f ;
212
211
}
213
- xy.x = cx;
214
- xy.y = cy;
212
+ ColorPoint xy = {cx, cy};
215
213
// Check if the given XY value is within the color reach of our lamps.
216
214
if (!isPointInLampsReach (lamp, xy)) {
217
215
// It seems the color is out of reach let's find the closes colour we can produce with our lamp and send this XY value out.
@@ -242,11 +240,11 @@ void LedDevicePhilipsHue::rgbToXYBrightness(float red, float green, float blue,
242
240
243
241
HueLamp::HueLamp (unsigned int id, QString originalState, QString modelId) :
244
242
id(id), originalState(originalState) {
245
- // / Hue system model ids.
243
+ // Hue system model ids.
246
244
const std::set<QString> HUE_BULBS_MODEL_IDS = { " LCT001" , " LCT002" , " LCT003" };
247
245
const std::set<QString> LIVING_COLORS_MODEL_IDS = { " LLC001" , " LLC005" , " LLC006" , " LLC007" , " LLC011" , " LLC012" ,
248
246
" LLC013" , " LST001" };
249
- // / Find id in the sets and set the appropiate color space.
247
+ // Find id in the sets and set the appropiate color space.
250
248
if (HUE_BULBS_MODEL_IDS.find (modelId) != HUE_BULBS_MODEL_IDS.end ()) {
251
249
colorSpace.red = {0 .675f , 0 .322f };
252
250
colorSpace.green = {0 .4091f , 0 .518f };
@@ -260,7 +258,7 @@ HueLamp::HueLamp(unsigned int id, QString originalState, QString modelId) :
260
258
colorSpace.green = {0 .0f , 1 .0f };
261
259
colorSpace.blue = {0 .0f , 0 .0f };
262
260
}
263
- // / Initialize color with black
261
+ // Initialize color with black
264
262
color = {0 .0f , 0 .0f , 0 .0f };
265
263
}
266
264
0 commit comments