diff --git a/src/main/java/com/bwssystems/HABridge/hue/ColorDecode.java b/src/main/java/com/bwssystems/HABridge/hue/ColorDecode.java index 3d39362..86421de 100644 --- a/src/main/java/com/bwssystems/HABridge/hue/ColorDecode.java +++ b/src/main/java/com/bwssystems/HABridge/hue/ColorDecode.java @@ -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; diff --git a/src/test/java/com/bwssystems/color/test/ConvertCIEColorTestCase.java b/src/test/java/com/bwssystems/color/test/ConvertCIEColorTestCase.java index d3e04d8..4824597 100644 --- a/src/test/java/com/bwssystems/color/test/ConvertCIEColorTestCase.java +++ b/src/test/java/com/bwssystems/color/test/ConvertCIEColorTestCase.java @@ -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); } }