net.returnvoid.color

## Class ColorHelper

- java.lang.Object
- - net.returnvoid.color.ColorHelper

-     public class ColorHelper
      extends java.lang.Object

  A collection of static functions in relationship to RColor and ColorDifference.
  Author:
    Diana Lange

- - ### Method Summary

    All Methods Static Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `static boolean` | `contains(RColor ref, java.util.ArrayList<RColor> colors)` Checks if ref is member of colors.
    `static boolean` | `contains(RColor ref, RColor[] colors)` Checks if ref is member of colors.
    `static void` | `convert(java.util.ArrayList<RColor> colors, ColorSpace target)` Converts the input colors c into the given color space.
    `static void` | `convert(RColor[] colors, ColorSpace target)` Converts the input colors c into the given color space.
    `static RColor` | `convert(RColor c, ColorDifferenceMeasure m)` Converts the input color c into a appropriate color model defined by the ColorDifferenceMeasure.
    `static RColor` | `convert(RColor c, ColorSpace target)` Converts the input color c into the given target color space.
    `static java.util.ArrayList<RColor>` | `copy(java.util.ArrayList<RColor> colors)` Creates a copy array of the given input.
    `static RColor[]` | `copy(RColor[] colors)` Creates a copy array of the given input.
    `static int` | `getColor(float... paramters)` Converts input values to a color.
    `static int` | `getColor(java.lang.String hex)` Converts a String, containing a hexadecimal number, to a color.
    `static java.lang.Float` | `getLoss(RColor rvMean, java.util.ArrayList<RColor> colors, ColorDifferenceMeasure m)` Calculates the loss - the mean distance of all members of colors to rvMean.
    `static java.lang.Float` | `getLoss(RColor rvMean, java.util.ArrayList<RColor> colors, ColorDifferenceMeasure m, int start, int end)` Calculates the loss - the mean distance of all members of colors to rvMean.
    `static java.lang.Float` | `getLoss(RColor rvMean, RColor[] colors, ColorDifferenceMeasure m)` Calculates the loss - the mean distance of all members of colors to rvMean.
    `static java.lang.Float` | `getLoss(RColor rvMean, RColor[] colors, ColorDifferenceMeasure m, int start, int end)` Calculates the loss - the mean distance of all members of colors to rvMean.
    `static RColor` | `getMeanColor(java.util.ArrayList<RColor> colors, ColorDifferenceMeasure m)` Returns the mean color of the given set colors using the color space defined by the ColorDifferenceMeasure m, e.g RGBEuclidean is mapped to RGBColor.
    `static RColor` | `getMeanColor(java.util.ArrayList<RColor> colors, ColorSpace space)` Returns the mean color of the given set colors using the color space defined by space.
    `static RColor` | `getMeanColor(ColorDifferenceMeasure m, RColor... colors)` Returns the mean color of the given set colors using the color space defined by the ColorDifferenceMeasure m, e.g RGBEuclidean is mapped to RGBColor.
    `static RColor` | `getMeanColor(RColor[] colors, ColorDifferenceMeasure m)` Returns the mean color of the given set colors using the color space defined by the ColorDifferenceMeasure m, e.g RGBEuclidean is mapped to RGBColor.
    `static RColor` | `getMeanColor(RColor[] colors, ColorSpace space)` Returns the mean color of the given set colors using the color space defined by space.
    `static int` | `getRandomColor()` Creates a random opaque color.
    `static RColor` | `lerpColors(RColor c1, RColor c2, float amt)` Lerps the two input colors and creates a new color.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Method Detail

    - #### copy

          public static RColor[] copy(RColor[] colors)

      Creates a copy array of the given input.
      Parameters:
        `colors` - A set of colors.
      Returns:
        The (true) copy of the given set.

    - #### copy

          public static java.util.ArrayList<RColor> copy(java.util.ArrayList<RColor> colors)

      Creates a copy array of the given input.
      Parameters:
        `colors` - A set of colors.
      Returns:
        The (true) copy of the given set.

    - #### getLoss

          public static java.lang.Float getLoss(RColor rvMean,
                                                RColor[] colors,
                                                ColorDifferenceMeasure m)

      Calculates the loss - the mean distance of all members of colors to rvMean.
      Parameters:
        `rvMean` - A base color which will be used to calculate the distance to.
        `colors` - Colors.
        `m` - The measure which defines how the loss is calculated and which color model will be used.
      Returns:
        The mean loss value.

    - #### getLoss

          public static java.lang.Float getLoss(RColor rvMean,
                                                RColor[] colors,
                                                ColorDifferenceMeasure m,
                                                int start,
                                                int end)

      Calculates the loss - the mean distance of all members of colors to rvMean. With start and end a subset is defined. Just this subset will be used to calculate the loss. start and end should be in the array range; otherwise this will produce an ArrayIndexOutOfBounds Exception.
      Parameters:
        `rvMean` - A base color which will be used to calculate the distance to.
        `colors` - Colors.
        `m` - The measure which defines how the loss is calculated and which color model will be used.
        `start` - Start index of the subset of the input colors (start < end). start will be member of the subset.
        `end` - End index of the subset of the input colors (start < end). end will not be member of the subset.
      Returns:
        The mean loss value.

    - #### getLoss

          public static java.lang.Float getLoss(RColor rvMean,
                                                java.util.ArrayList<RColor> colors,
                                                ColorDifferenceMeasure m)

      Calculates the loss - the mean distance of all members of colors to rvMean.
      Parameters:
        `rvMean` - A base color which will be used to calculate the distance to.
        `colors` - Colors.
        `m` - The measure which defines how the loss is calculated and which color model will be used.
      Returns:
        The mean loss value.

    - #### getLoss

          public static java.lang.Float getLoss(RColor rvMean,
                                                java.util.ArrayList<RColor> colors,
                                                ColorDifferenceMeasure m,
                                                int start,
                                                int end)

      Calculates the loss - the mean distance of all members of colors to rvMean. With start and end a subset is defined. Just this subset will be used to calculate the loss. start and end should be in the array range; otherwise this will produce an ArrayIndexOutOfBounds Exception.
      Parameters:
        `rvMean` - A base color which will be used to calculate the distance to.
        `colors` - Colors.
        `m` - The measure which defines how the loss is calculated and which color model will be used.
        `start` - Start index of the subset of the input colors (start < end). start will be member of the subset.
        `end` - End index of the subset of the input colors (start < end). end will not be member of the subset.
      Returns:
        The mean loss value.

    - #### getMeanColor

          public static RColor getMeanColor(ColorDifferenceMeasure m,
                                            RColor... colors)

      Returns the mean color of the given set colors using the color space defined by the ColorDifferenceMeasure m, e.g RGBEuclidean is mapped to RGBColor.
      Parameters:
        `m` - A ColorDifferenceMeasure.
        `colors` - A set of colors (not null, one or more colors).
      Returns:
        A mean color (member of space).

    - #### getMeanColor

          public static RColor getMeanColor(RColor[] colors,
                                            ColorDifferenceMeasure m)

      Returns the mean color of the given set colors using the color space defined by the ColorDifferenceMeasure m, e.g RGBEuclidean is mapped to RGBColor.
      Parameters:
        `colors` - A set of colors (not null, one or more colors).
        `m` - A ColorDifferenceMeasure.
      Returns:
        A mean color (member of space).

    - #### getMeanColor

          public static RColor getMeanColor(java.util.ArrayList<RColor> colors,
                                            ColorDifferenceMeasure m)

      Returns the mean color of the given set colors using the color space defined by the ColorDifferenceMeasure m, e.g RGBEuclidean is mapped to RGBColor.
      Parameters:
        `colors` - A set of colors (not null, one or more colors).
        `m` - A ColorDifferenceMeasure.
      Returns:
        A mean color (member of space).

    - #### getMeanColor

          public static RColor getMeanColor(RColor[] colors,
                                            ColorSpace space)

      Returns the mean color of the given set colors using the color space defined by space.
      Parameters:
        `colors` - A set of colors (not null, one or more colors).
        `space` - A color space.
      Returns:
        A mean color (member of space).

    - #### getMeanColor

          public static RColor getMeanColor(java.util.ArrayList<RColor> colors,
                                            ColorSpace space)

      Returns the mean color of the given set colors using the color space defined by space.
      Parameters:
        `colors` - A set of colors (not null, one or more colors).
        `space` - A color space.
      Returns:
        A mean color (member of space).

    - #### lerpColors

          public static RColor lerpColors(RColor c1,
                                          RColor c2,
                                          float amt)

      Lerps the two input colors and creates a new color. The values of the colors will be interpolated linear. The interpolation is defined by the amt parameter. For amt=0 the outcome will be input1, for amt=1 the outcome will be input2. Uses the lerp function of the class of c1 (e.g. of c1 is a RGBColor, RGBColor.lerpColors() will be executed).
      Parameters:
        `c1` - The first color.
        `c2` - The second color.
        `amt` - The lerping value [0, 1].
      Returns:
        A new 'mixed' color.

    - #### convert

          public static RColor convert(RColor c,
                                       ColorSpace target)

      Converts the input color c into the given target color space.
      Parameters:
        `c` - The color which should be converted.
        `target` - The color space to convert to.
      Returns:
        The converted color.

    - #### convert

          public static RColor convert(RColor c,
                                       ColorDifferenceMeasure m)

      Converts the input color c into a appropriate color model defined by the ColorDifferenceMeasure. E.G. if the ColorDifferenceMeasure is RGBEuclidean distance the resulting type of the output color will be RGBColor. If the color is already member of the right color space, the function will return the input color.
      Parameters:
        `c` - The color which should be converted.
        `m` - The color difference measure.
      Returns:
        The converted color.

    - #### convert

          public static void convert(RColor[] colors,
                                     ColorSpace target)

      Converts the input colors c into the given color space. Uses just cA OR cL. Not both. One of aColors / lColors should be null, the other one should
      Parameters:
        `colors` - The colors which should be converted.
        `target` - The target color space.

    - #### convert

          public static void convert(java.util.ArrayList<RColor> colors,
                                     ColorSpace target)

      Converts the input colors c into the given color space. Uses just cA OR cL. Not both. One of aColors / lColors should be null, the other one should
      Parameters:
        `colors` - The colors which should be converted.
        `target` - The target color space.

    - #### contains

          public static boolean contains(RColor ref,
                                         RColor[] colors)

      Checks if ref is member of colors.
      Parameters:
        `ref` - A color or null.
        `colors` - Colors (Not null, members might be null)
      Returns:
        True if ref is member of the given set. Otherwise false.

    - #### contains

          public static boolean contains(RColor ref,
                                         java.util.ArrayList<RColor> colors)

      Checks if ref is member of colors.
      Parameters:
        `ref` - A color or null.
        `colors` - Colors (Not null, members might be null)
      Returns:
        True if ref is member of the given set. Otherwise false.

    - #### getRandomColor

          public static int getRandomColor()

      Creates a random opaque color.
      Returns:
        The int color representation of the random color.

    - #### getColor

          public static int getColor(java.lang.String hex)

      Converts a String, containing a hexadecimal number, to a color. The String should be in form of "FF0000" or "#FF0000" or "AAFF0000" or "#AAFF0000" (first two characters for transparency).
      Parameters:
        `hex` - A string containing a hexadecimal number.
      Returns:
        The int color representation of the color of the given String.

    - #### getColor

          public static int getColor(float... paramters)

      Converts input values to a color.
      Parameters:
        `paramters` - Either [gray], [gray, alpha] or [r, g, b] or [r, g, b, alpha].
      Returns:
        The int color representation of the input.