mirror of
https://github.com/bwssytems/ha-bridge.git
synced 2025-12-16 18:24:36 +00:00
Fininshed Testing color RGB to int for LIFX
This commit is contained in:
@@ -266,29 +266,7 @@ public class ColorDecode {
|
||||
rgb = convertCTtoRGB((Integer) colorData.getData());
|
||||
}
|
||||
|
||||
double r = (double) rgb.get(0);
|
||||
double g = (double) rgb.get(1);
|
||||
double b = (double) rgb.get(2);
|
||||
r /= (double) 0xFF;
|
||||
g /= (double) 0xFF;
|
||||
b /= (double) 0xFF;
|
||||
double max = Math.max(Math.max(r, g), b), min = Math.min(Math.min(r, g), b);
|
||||
double h = 0;
|
||||
double d = max - min;
|
||||
|
||||
if (max == min) {
|
||||
h = 0;
|
||||
} else {
|
||||
if (max == r) {
|
||||
h = ((g - b) / d + (g < b ? 6 : 0));
|
||||
} else if (max == g) {
|
||||
h = ((b - r) / d + 2);
|
||||
} else if (max == b) {
|
||||
h = ((r - g) / d + 4);
|
||||
}
|
||||
h = Math.round(h * 60);
|
||||
}
|
||||
int rgbIntVal = (int) ((256 + 176 - Math.floor(h / 360.0 * 255.0)) % 256);
|
||||
int rgbIntVal = Integer.parseInt(String.format("%02X%02X%02X", rgb.get(0), rgb.get(1), rgb.get(2)), 16);
|
||||
log.debug("Convert RGB to int. Result: " + rgbIntVal + " RGB Values: " + rgb.get(0) + " " + rgb.get(1) + " "
|
||||
+ rgb.get(2));
|
||||
return rgbIntVal;
|
||||
|
||||
@@ -7,6 +7,7 @@ import java.util.List;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import com.bwssystems.HABridge.hue.ColorData;
|
||||
import com.bwssystems.HABridge.hue.ColorDecode;
|
||||
|
||||
public class ConvertCIEColorTestCase {
|
||||
@@ -21,6 +22,10 @@ public class ConvertCIEColorTestCase {
|
||||
assertDecode.add(1, 47);
|
||||
assertDecode.add(2, 43);
|
||||
Assert.assertEquals(colorDecode, assertDecode);
|
||||
|
||||
ColorData colorData = new ColorData(ColorData.ColorMode.XY, xy);
|
||||
int rgbIntVal = ColorDecode.getIntRGB(colorData, 254);
|
||||
Assert.assertEquals(rgbIntVal, 16723755);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user