/** * Returns the xyY values representing this object's color in CIE XY color model. * Conversion from sRGB to CIE XY using D65 reference white * xy pair contains color information * Y represents relative luminance * * @param HSBType color object * @return PercentType[x, y, Y] values in the CIE XY color model */ public PercentType[] toXY() { // This makes sure we keep color information even if brightness is zero PercentType sRGB[] = new HSBType(getHue(), getSaturation(), PercentType.HUNDRED).toRGB(); float r = gammaDecompress(sRGB[0].floatValue() / 100.0f); float g = gammaDecompress(sRGB[1].floatValue() / 100.0f); float b = gammaDecompress(sRGB[2].floatValue() / 100.0f); float X = r * Rgb2Xy[0][0] + g * Rgb2Xy[0][1] + b * Rgb2Xy[0][2]; float Y = r * Rgb2Xy[1][0] + g * Rgb2Xy[1][1] + b * Rgb2Xy[1][2]; float Z = r * Rgb2Xy[2][0] + g * Rgb2Xy[2][1] + b * Rgb2Xy[2][2]; float x = X / (X + Y + Z); float y = Y / (X + Y + Z); return new PercentType[] { new PercentType(Float.valueOf(x * 100.0f).toString()), new PercentType(Float.valueOf(y * 100.0f).toString()), new PercentType(Float.valueOf(Y * getBrightness().floatValue()).toString()) }; }
/** * Converts a {@link PercentType} to an 8 bit level scaled between 0 and 254 * * @param percent the {@link PercentType} to convert * @return a scaled value between 0 and 254 */ protected int percentToLevel(PercentType percent) { return (int) (percent.floatValue() * 254.0f / 100.0f + 0.5f); }
private int scaleColor(PercentType value) { return (int) (value.floatValue() * 255.0 / 100.0); } }
@ActionDoc(text = "gets the master volume", returns = "volume as a float in the range [0,1]") public static float getMasterVolume() throws IOException { return AudioActionService.audioManager.getVolume(null).floatValue() / 100f; }
/** * Returns the xyY values representing this object's color in CIE XY color model. * Conversion from sRGB to CIE XY using D65 reference white * xy pair contains color information * Y represents relative luminance * * @param HSBType color object * @return PercentType[x, y, Y] values in the CIE XY color model */ public PercentType[] toXY() { // This makes sure we keep color information even if brightness is zero PercentType sRGB[] = new HSBType(getHue(), getSaturation(), PercentType.HUNDRED).toRGB(); float r = gammaDecompress(sRGB[0].floatValue() / 100.0f); float g = gammaDecompress(sRGB[1].floatValue() / 100.0f); float b = gammaDecompress(sRGB[2].floatValue() / 100.0f); float X = r * Rgb2Xy[0][0] + g * Rgb2Xy[0][1] + b * Rgb2Xy[0][2]; float Y = r * Rgb2Xy[1][0] + g * Rgb2Xy[1][1] + b * Rgb2Xy[1][2]; float Z = r * Rgb2Xy[2][0] + g * Rgb2Xy[2][1] + b * Rgb2Xy[2][2]; float x = X / (X + Y + Z); float y = Y / (X + Y + Z); return new PercentType[] { new PercentType(Float.valueOf(x * 100.0f).toString()), new PercentType(Float.valueOf(y * 100.0f).toString()), new PercentType(Float.valueOf(Y * getBrightness().floatValue()).toString()) }; }
private void changeColorXY(HSBType color) throws InterruptedException, ExecutionException { PercentType xy[] = color.toXY(); HSBType oldHSB = currentHSB; currentHSB = new HSBType(color.getHue(), color.getSaturation(), oldHSB.getBrightness()); logger.debug("{}: Change Color HSV ({}, {}, {}) -> XY ({}, {})", endpoint.getIeeeAddress(), color.getHue(), color.getSaturation(), oldHSB.getBrightness(), xy[0], xy[1]); int x = (int) (xy[0].floatValue() / 100.0f * 65536.0f + 0.5f); // up to 65279 int y = (int) (xy[1].floatValue() / 100.0f * 65536.0f + 0.5f); // up to 65279 clusterColorControl.moveToColorCommand(x, y, configLevelControl.getDefaultTransitionTime()).get(); }
private void updateColorXY(PercentType x, PercentType y) { HSBType color = HSBType.fromXY(x.floatValue() / 100.0f, y.floatValue() / 100.0f); logger.debug("{}: Update Color XY ({}, {}) -> HSV ({}, {}, {})", endpoint.getIeeeAddress(), x.toString(), y.toString(), color.getHue(), color.getSaturation(), currentHSB.getBrightness()); updateColorHSB(color.getHue(), color.getSaturation()); }