@Override public SortedMap<String, PrimitiveType> getConstituents() { TreeMap<String, PrimitiveType> map = new TreeMap<>(); map.put(KEY_HUE, getHue()); map.put(KEY_SATURATION, getSaturation()); map.put(KEY_BRIGHTNESS, getBrightness()); return map; }
@Override public <T extends State> @Nullable T as(@Nullable Class<T> target) { if (target == OnOffType.class) { // if brightness is not completely off, we consider the state to be on return target.cast(getBrightness().equals(PercentType.ZERO) ? OnOffType.OFF : OnOffType.ON); } else if (target == DecimalType.class) { return target.cast(new DecimalType( getBrightness().toBigDecimal().divide(BigDecimal.valueOf(100), 8, RoundingMode.UP))); } else if (target == PercentType.class) { return target.cast(new PercentType(getBrightness().toBigDecimal())); } else { return defaultConversion(target); } } }
@Override public String toFullString() { return getHue() + "," + getSaturation() + "," + getBrightness(); }
case 0: case 6: red = getBrightness(); green = c; blue = a; case 1: red = b; green = getBrightness(); blue = a; break; case 2: red = a; green = getBrightness(); blue = c; break; red = a; green = b; blue = getBrightness(); break; case 4: red = c; green = a; blue = getBrightness(); break; case 5: red = getBrightness(); green = a;
@Override public boolean equals(@Nullable Object obj) { if (this == obj) { return true; } if (obj == null) { return false; } if (!(obj instanceof HSBType)) { return false; } HSBType other = (HSBType) obj; if (!getHue().equals(other.getHue()) || !getSaturation().equals(other.getSaturation()) || !getBrightness().equals(other.getBrightness())) { return false; } return true; }
@Override public int hashCode() { int tmp = 10000 * getHue().hashCode(); tmp += 100 * getSaturation().hashCode(); tmp += getBrightness().hashCode(); return tmp; }
/** * 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()) }; }
@Override public SortedMap<String, PrimitiveType> getConstituents() { TreeMap<String, PrimitiveType> map = new TreeMap<>(); map.put(KEY_HUE, getHue()); map.put(KEY_SATURATION, getSaturation()); map.put(KEY_BRIGHTNESS, getBrightness()); return map; }
@Override public <T extends State> @Nullable T as(@Nullable Class<T> target) { if (target == OnOffType.class) { // if brightness is not completely off, we consider the state to be on return target.cast(getBrightness().equals(PercentType.ZERO) ? OnOffType.OFF : OnOffType.ON); } else if (target == DecimalType.class) { return target.cast(new DecimalType( getBrightness().toBigDecimal().divide(BigDecimal.valueOf(100), 8, RoundingMode.UP))); } else if (target == PercentType.class) { return target.cast(new PercentType(getBrightness().toBigDecimal())); } else { return defaultConversion(target); } } }
private void updateColorHSB(DecimalType hue, PercentType saturation) { // Extra temp variable to avoid thread sync concurrency issues on currentHSB HSBType oldHSB = currentHSB; HSBType newHSB = new HSBType(hue, saturation, oldHSB.getBrightness()); currentHSB = newHSB; if (currentState.get() && lastColorMode != ColorModeEnum.COLORTEMPERATURE) { updateChannelState(newHSB); } }
case 0: case 6: red = getBrightness(); green = c; blue = a; case 1: red = b; green = getBrightness(); blue = a; break; case 2: red = a; green = getBrightness(); blue = c; break; red = a; green = b; blue = getBrightness(); break; case 4: red = c; green = a; blue = getBrightness(); break; case 5: red = getBrightness(); green = a;
@Override public String toFullString() { return getHue() + "," + getSaturation() + "," + getBrightness(); }
@Override public boolean equals(@Nullable Object obj) { if (this == obj) { return true; } if (obj == null) { return false; } if (!(obj instanceof HSBType)) { return false; } HSBType other = (HSBType) obj; if (!getHue().equals(other.getHue()) || !getSaturation().equals(other.getSaturation()) || !getBrightness().equals(other.getBrightness())) { return false; } return true; }
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(); }
@Override public int hashCode() { int tmp = 10000 * getHue().hashCode(); tmp += 100 * getSaturation().hashCode(); tmp += getBrightness().hashCode(); return tmp; }
/** * 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 changeColorHueSaturation(HSBType color) throws InterruptedException, ExecutionException { HSBType oldHSB = currentHSB; currentHSB = new HSBType(color.getHue(), color.getSaturation(), oldHSB.getBrightness()); int hue = (int) (color.getHue().floatValue() * 254.0f / 360.0f + 0.5f); int saturation = percentToLevel(color.getSaturation()); clusterColorControl .moveToHueAndSaturationCommand(hue, saturation, configLevelControl.getDefaultTransitionTime()).get(); }
HSBType current = currentHSB; HSBType color = (HSBType) command; PercentType brightness = color.getBrightness(); if (brightness.intValue() != currentHSB.getBrightness().intValue()) { changeBrightness(brightness); if (changeColor && delayedColorChange) {
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()); }