Package org.openhab.core.util
Class ColorUtil
java.lang.Object
org.openhab.core.util.ColorUtil
The
ColorUtil
is responsible for converting different color formats.
The implementation of HSB/CIE conversion is based work from Erik Baauw for the
Homebridge
project.- Author:
- Jan N. Klug - Initial contribution, Holger Friedrich - Transfer RGB color conversion from HSBType, improve RGB conversion, restructuring, Chris Jackson - Added fromRGB (moved from HSBType), Andrew Fiddian-Green - Extensive revamp to fix bugs and improve accuracy
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic final record
Color gamutstatic class
Class for points in the CIE xy color space -
Field Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic int[]
static PercentType[]
hsbToRgbPercent
(HSBType hsb) static int[]
static PercentType[]
hsbToRgbwPercent
(HSBType hsb) static int
static double[]
static double[]
hsbToXY
(HSBType hsb, ColorUtil.Gamut gamut) static HSBType
rgbToHsb
(int[] rgbw) static HSBType
rgbToHsb
(PercentType[] rgbw) static HSBType
xyToHsb
(double[] xy) static HSBType
xyToHsb
(double[] xyY, ColorUtil.Gamut gamut)
-
Field Details
-
DEFAULT_GAMUT
-
-
Method Details
-
hsbToRgb
Transform HSV basedHSBType
to sRGB. This function does rounding to integer valued components. It is the preferred way of doing HSB to RGB conversion. See also:hsbToRgbPercent(HSBType)
,hsbToRgbw(HSBType)
,hsbTosRgb(HSBType)
- Parameters:
hsb
- anHSBType
value.- Returns:
- array of three int with the RGB values in the range 0 to 255.
-
hsbToRgbw
Transform HSV basedHSBType
to sRGB. This function does rounding to integer valued components. It is the preferred way of doing HSB to RGBW conversion. See also:hsbToRgbPercent(HSBType)
,hsbToRgbwPercent(HSBType)
,hsbTosRgb(HSBType)
- Parameters:
hsb
- anHSBType
value.- Returns:
- array of four int with the RGBW values in the range 0 to 255.
-
hsbToRgbPercent
Transform HSV basedHSBType
to sRGB. This function does not round the components. For conversion to integer values in the range 0 to 255 usehsbToRgb(HSBType)
. See also:hsbToRgb(HSBType)
,hsbTosRgb(HSBType)
,hsbToRgbwPercent(HSBType)
- Parameters:
hsb
- anHSBType
value.- Returns:
- array of three
PercentType
with the RGB values in the range 0 to 100 percent.
-
hsbToRgbwPercent
Transform HSV basedHSBType
to RGBW. See Converting RGB to RGBW. This function does not round the components. For conversion to integer values in the range 0 to 255 usehsbToRgb(HSBType)
. See also:hsbToRgb(HSBType)
,hsbTosRgb(HSBType)
,hsbToRgbPercent(HSBType)
- Parameters:
hsb
- anHSBType
value.- Returns:
- array of four
PercentType
with the RGBW values in the range 0 to 100 percent.
-
hsbTosRgb
Transform HSV basedHSBType
to the RGB value representing the color in the default sRGB color model. (Bits 24-31 are alpha, 16-23 are red, 8-15 are green, 0-7 are blue). See also:hsbToRgb(HSBType)
,hsbToRgbPercent(HSBType)
- Parameters:
hsb
- anHSBType
value.- Returns:
- the RGB value of the color in the default sRGB color model.
-
hsbToXY
- Parameters:
hsb
- anHSBType
value.- Returns:
- array of three double with the closest matching CIE 1931 x,y,Y in the range 0.0000 to 1.0000
-
hsbToXY
- Parameters:
hsb
- anHSBType
value.gamut
- the color Gamut supported by the light.- Returns:
- array of three or four double with the closest matching CIE 1931 x,y,Y in the range 0.0000 to 1.0000 - plus an optional extra empty element to flag if the xyY result has been forced inside the given Gamut.
-
rgbToHsb
- Parameters:
rgbw
- array of three or four int with the RGB(W) values in the range 0 to 255.- Returns:
- the corresponding
HSBType
. - Throws:
IllegalArgumentException
- when input array has wrong size or exceeds allowed value range.
-
rgbToHsb
- Parameters:
rgbw
- array of three or fourPercentType
with the RGB(W) values in the range 0 to 100 percent.- Returns:
- the corresponding
HSBType
. - Throws:
IllegalArgumentException
- when input array has wrong size or exceeds allowed value range.
-
xyToHsb
- Parameters:
xy
- array of double with CIE 1931 x,y[,Y] in the range 0.0000 to 1.0000Y
value is optional.- Returns:
- the corresponding
HSBType
. - Throws:
IllegalArgumentException
- when input array has wrong size or exceeds allowed value range.
-
xyToHsb
- Parameters:
xyY
- array of double with CIE 1931 x,y[,Y] in the range 0.0000 to 1.0000Y
value is optional.gamut
- the color Gamut supported by the light.- Returns:
- the corresponding
HSBType
. - Throws:
IllegalArgumentException
- when input array has wrong size or exceeds allowed value range
-