HSBType extends PercentType implements ComplexType, State, Command { public PercentType[] toXY() { 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 tmpX = r * RGB2XY[0][0] + g * RGB2XY[0][1] + b * RGB2XY[0][2]; float tmpY = r * RGB2XY[1][0] + g * RGB2XY[1][1] + b * RGB2XY[1][2]; float tmpZ = r * RGB2XY[2][0] + g * RGB2XY[2][1] + b * RGB2XY[2][2]; float x = tmpX / (tmpX + tmpY + tmpZ); float y = tmpY / (tmpX + tmpY + tmpZ); return new PercentType[] { new PercentType(Float.valueOf(x * 100.0f).toString()), new PercentType(Float.valueOf(y * 100.0f).toString()), new PercentType(Float.valueOf(tmpY * getBrightness().floatValue()).toString()) }; } HSBType();  HSBType(DecimalType h, PercentType s, PercentType b);  HSBType(String value); static HSBType valueOf(String value); static HSBType fromRGB(int r, int g, int b); static HSBType fromXY(float x, float y); @Override SortedMap<String, PrimitiveType> getConstituents(); DecimalType getHue(); PercentType getSaturation(); PercentType getBrightness(); PercentType getRed(); PercentType getGreen(); PercentType getBlue(); int getRGB(); @Override String toString(); @Override String toFullString(); @Override int hashCode(); @Override boolean equals(@Nullable Object obj); PercentType[] toRGB(); PercentType[] toXY(); @Override T as(@Nullable Class<T> target); static final String KEY_HUE; static final String KEY_SATURATION; static final String KEY_BRIGHTNESS; static final HSBType BLACK; static final HSBType WHITE; static final HSBType RED; static final HSBType GREEN; static final HSBType BLUE; }
@Test public void testConversionToXY() { HSBType hsb = new HSBType("220,90,50"); PercentType[] xy = hsb.toXY(); assertEquals(new PercentType("16.969364"), xy[0]); assertEquals(new PercentType("12.379659"), xy[1]); }