Class ColorUtil

java.lang.Object
org.oscim.utils.ColorUtil

public class ColorUtil extends Object
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static int
    blend(int color1, int color2, float mix)
    Blend two colors.
    static int
    desaturate(int color)
     
    static int
    hslToRgb(double h, double s, double l)
     
    static int
    hslToRgb(double h, double s, double l, Vec3 out)
    Converts an HSL color value to RGB.
    static int
    hsvToRgb(double h, double s, double v)
     
    static int
    hsvToRgb(double h, double s, double v, Vec3 out)
    Converts an HSV color value to RGB.
    static int
    modHsv(int color, double hue, double saturation, double value, boolean relative)
     
    static Vec3
    rgbToHsl(double r, double g, double b)
     
    static Vec3
    rgbToHsl(double r, double g, double b, Vec3 out)
    Converts an RGB color value to HSL.
    static Vec3
    rgbToHsv(double r, double g, double b)
     
    static Vec3
    rgbToHsv(double r, double g, double b, Vec3 out)
    Converts an RGB color value to HSV.
    static int
    saturate(int color, double saturation)
     
    static int
    saturate(int color, double saturation, boolean relative)
     
    static int
    setHue(int color, double hue)
     
    static int
    shiftHue(int color, double hue)
     

    Methods inherited from class java.lang.Object

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

    • ColorUtil

      public ColorUtil()
  • Method Details

    • desaturate

      public static int desaturate(int color)
    • saturate

      public static int saturate(int color, double saturation)
    • setHue

      public static int setHue(int color, double hue)
    • shiftHue

      public static int shiftHue(int color, double hue)
    • saturate

      public static int saturate(int color, double saturation, boolean relative)
    • modHsv

      public static int modHsv(int color, double hue, double saturation, double value, boolean relative)
      Parameters:
      hue - the hue from 0 to 1 (exclusive) 0: no color shift 0.5: opposite hue
      saturation - the saturation 0 to 1: desaturate 1 to 2: saturate
      value - the lightness 0 to 1: darken 1 to 2: lighten
      relative - indicate if colors are modified relative to their values (e.g black not changes if relative)
    • rgbToHsl

      public static Vec3 rgbToHsl(double r, double g, double b, Vec3 out)
      Converts an RGB color value to HSL. Conversion formula adapted from http://en.wikipedia.org/wiki/HSL_color_space. Assumes r, g, and b are contained in the set [0, 255] and returns h, s, and l in the set [0, 1].
      Parameters:
      Number - r The red color value
      Number - g The green color value
      Number - b The blue color value
      Returns:
      Array The HSL representation
    • rgbToHsl

      public static Vec3 rgbToHsl(double r, double g, double b)
    • hslToRgb

      public static int hslToRgb(double h, double s, double l, Vec3 out)
      Converts an HSL color value to RGB. Conversion formula adapted from http://en.wikipedia.org/wiki/HSL_color_space. Assumes h, s, and l are contained in the set [0, 1] and returns r, g, and b in the set [0, 255].
      Parameters:
      Number - h The hue
      Number - s The saturation
      Number - l The lightness
      Returns:
      Array The RGB representation
    • rgbToHsv

      public static Vec3 rgbToHsv(double r, double g, double b, Vec3 out)
      Converts an RGB color value to HSV. Conversion formula adapted from http://en.wikipedia.org/wiki/HSV_color_space. Assumes r, g, and b are contained in the set [0, 255] and returns h, s, and v in the set [0, 1].
      Parameters:
      Number - r The red color value
      Number - g The green color value
      Number - b The blue color value
      Returns:
      Array The HSV representation
    • rgbToHsv

      public static Vec3 rgbToHsv(double r, double g, double b)
    • hsvToRgb

      public static int hsvToRgb(double h, double s, double v, Vec3 out)
      Converts an HSV color value to RGB. Conversion formula adapted from http://en.wikipedia.org/wiki/HSV_color_space. Assumes h, s, and v are contained in the set [0, 1] and returns r, g, and b in the set [0, 255].
      Parameters:
      h - The hue
      s - The saturation
      v - The value
      out - result rgb, may be ommited
      Returns:
      Array The RGB representation
    • hsvToRgb

      public static int hsvToRgb(double h, double s, double v)
    • hslToRgb

      public static int hslToRgb(double h, double s, double l)
    • blend

      public static int blend(int color1, int color2, float mix)
      Blend two colors.
      Parameters:
      color1 - the first color
      color2 - the second color
      mix - the mixing proportion in range 0 to 1
      Returns:
      the blended color