Package org.openhab.core.util
Class LightModel.RgbcwMath
java.lang.Object
org.openhab.core.util.LightModel.RgbcwMath
- Enclosing class:
LightModel
Internal: a class containing mathematical utility methods that convert between RGB and RGBCW color arrays
based on the RGB main values and the RGB sub- component values of the cool and warm white LEDs.
Note: it is intended to move this class to the
ColorUtil utility class, but let's keep it here
for the time being in order to simplify testing and code review.-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic double[]rgb2rgbcw(double[] rgb) Composes an RGBCW from the given RGB.static double[]rgb2rgbcw(double[] rgb, double[] coolProfile, double[] warmProfile) Composes an RGBCW from the given RGB.static double[]rgbcw2rgb(double[] rgbcw) Decomposes the given RGBCW to an RGB.static double[]rgbcw2rgb(double[] rgbcw, double[] coolProfile, double[] warmProfile) Decomposes the given RGBCW to an RGB.
-
Constructor Details
-
RgbcwMath
public RgbcwMath()
-
-
Method Details
-
rgb2rgbcw
Composes an RGBCW from the given RGB. Callsrgb2rgbcw(double[], double[], double[])with default LED profiles. The result depends on the main input RGB values and the RGB sub- component contributions of the cold and warm white LEDs. It solves to find the maximum usable C and W scalar values such that none of the RGB' channels become negative. It solves for C and W such that:RGB ≈ C * coolProfile + W * warmProfile + RGB'whereRGB'is the remaining RGB after subtracting the scaled cool and warm LED contributions.- Parameters:
rgb- a 3-element array of double: [R,G,B].- Returns:
- a 5-element array of double: [R',G',B',C,W], where R', G', B' are the remaining RGB values and C and W are the calculated cold and warm white values.
- Throws:
IllegalArgumentException- if the input array length is not 3, or if any of its values are outside the range [0.0..1.0]
-
rgb2rgbcw
public static double[] rgb2rgbcw(double[] rgb, double[] coolProfile, double[] warmProfile) throws IllegalArgumentException Composes an RGBCW from the given RGB. The result depends on the main input RGB values and the RGB sub- component contributions of the cold and warm white LEDs. It solves to find the maximum usable C and W scalar values such that none of the RGB' channels become negative. It solves for C and W such that:RGB ≈ C * coolProfile + W * warmProfile + RGB'whereRGB'is the remaining RGB after subtracting the scaled cool and warm LED contributions.- Parameters:
rgb- a 3-element array of double: [R,G,B].coolProfile- the cool white LED RGB profile, a normalized 3-element [R,G,B] array in the range [0.0..1.0]. For example seeCOOL_PROFILE.warmProfile- the warm white LED RGB profile, a normalized 3-element [R,G,B] array in the range [0.0..1.0]. For example seeWARM_PROFILE.- Returns:
- a 5-element array of double: [R',G',B',C,W], where R', G', B' are the remaining RGB values and C and W are the calculated cold and warm white values.
- Throws:
IllegalArgumentException- if the input array length is not 3, or if any of its values are outside the range [0.0..1.0]
-
rgbcw2rgb
Decomposes the given RGBCW to an RGB. Callsrgbcw2rgb(double[], double[], double[])with default LED profiles. The result comprises the main input RGB values plus the RGB sub- component contributions of the cold and warm white LEDs.- Parameters:
rgbcw- a 5-element array of double: [R,G,B,C,W], where R, G, B are the RGB values and C and W are the cold and warm white LED RGB profile contributions.- Returns:
- double[] a 3-element array of double: [R,G,B].
- Throws:
IllegalArgumentException- if the input array length is not 5, or if any its values are outside the range [0.0..1.0]
-
rgbcw2rgb
public static double[] rgbcw2rgb(double[] rgbcw, double[] coolProfile, double[] warmProfile) throws IllegalArgumentException Decomposes the given RGBCW to an RGB. The result comprises the main input RGB values plus the RGB sub- component contributions of the cold and warm white LEDs.- Parameters:
rgbcw- a 5-element array of double: [R,G,B,C,W], where R, G, B are the RGB values and C and W are the cold and warm white LED RGB profile contributions.coolProfile- the cool white LED RGB profile, a normalized 3-element [R,G,B] array in the range [0.0..1.0]. For example seeCOOL_PROFILE.warmProfile- the warm white LED RGB profile, a normalized 3-element [R,G,B] array in the range [0.0..1.0]. For example seeWARM_PROFILE.- Returns:
- double[] a 3-element array of double: [R,G,B].
- Throws:
IllegalArgumentException- if the input array length is not 5, or if any its values are outside the range [0.0..1.0]
-