Class LightModel.RgbcwMath

java.lang.Object
org.openhab.core.util.LightModel.RgbcwMath
Enclosing class:
LightModel

public static class LightModel.RgbcwMath extends Object
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
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static 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.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • RgbcwMath

      public RgbcwMath()
  • Method Details

    • rgb2rgbcw

      public static double[] rgb2rgbcw(double[] rgb) throws IllegalArgumentException
      Composes an RGBCW from the given RGB. Calls rgb2rgbcw(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' where RGB' 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' where RGB' 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 see COOL_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 see WARM_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

      public static double[] rgbcw2rgb(double[] rgbcw) throws IllegalArgumentException
      Decomposes the given RGBCW to an RGB. Calls rgbcw2rgb(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 see COOL_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 see WARM_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]