Class RGBColor

All Implemented Interfaces:
Color, ModeledColor<RGBColor.Component>

public class RGBColor extends AbstractModeledColor<RGBColor.Component>
Encapsulates a color value of the sRGB color space.
Author:
Garret Wilson
See Also:
  • Field Details

    • TRANSPARENT

      public static final RGBColor TRANSPARENT
      Definition of a transparent RGB color.
    • ALICE_BLUE

      public static final RGBColor ALICE_BLUE
      RGB color definition.
    • ANTIQUE_WHITE

      public static final RGBColor ANTIQUE_WHITE
      RGB color definition.
    • AQUA

      public static final RGBColor AQUA
      RGB color definition.
    • AQUA_MARINE

      public static final RGBColor AQUA_MARINE
      RGB color definition.
    • AZURE

      public static final RGBColor AZURE
      RGB color definition.
    • BEIGE

      public static final RGBColor BEIGE
      RGB color definition.
    • BISQUE

      public static final RGBColor BISQUE
      RGB color definition.
    • BLACK

      public static final RGBColor BLACK
      RGB color definition.
    • BLANCHE_DALMOND

      public static final RGBColor BLANCHE_DALMOND
      RGB color definition.
    • BLUE

      public static final RGBColor BLUE
      RGB color definition.
    • BLUE_VIOLET

      public static final RGBColor BLUE_VIOLET
      RGB color definition.
    • BROWN

      public static final RGBColor BROWN
      RGB color definition.
    • BURLY_WOOD

      public static final RGBColor BURLY_WOOD
      RGB color definition.
    • CADET_BLUE

      public static final RGBColor CADET_BLUE
      RGB color definition.
    • CHARTREUSE

      public static final RGBColor CHARTREUSE
      RGB color definition.
    • CHOCOLATE

      public static final RGBColor CHOCOLATE
      RGB color definition.
    • CORAL

      public static final RGBColor CORAL
      RGB color definition.
    • CORNFLOWER_BLUE

      public static final RGBColor CORNFLOWER_BLUE
      RGB color definition.
    • CORNSILK

      public static final RGBColor CORNSILK
      RGB color definition.
    • CRIMSON

      public static final RGBColor CRIMSON
      RGB color definition.
    • CYAN

      public static final RGBColor CYAN
      RGB color definition.
    • DARK_BLUE

      public static final RGBColor DARK_BLUE
      RGB color definition.
    • DARK_CYAN

      public static final RGBColor DARK_CYAN
      RGB color definition.
    • DARK_GOLDEN_ROD

      public static final RGBColor DARK_GOLDEN_ROD
      RGB color definition.
    • DARK_GRAY

      public static final RGBColor DARK_GRAY
      RGB color definition.
    • DARK_GREEN

      public static final RGBColor DARK_GREEN
      RGB color definition.
    • DARK_KHAKI

      public static final RGBColor DARK_KHAKI
      RGB color definition.
    • DARK_MAGENTA

      public static final RGBColor DARK_MAGENTA
      RGB color definition.
    • DARK_OLIVE_GREEN

      public static final RGBColor DARK_OLIVE_GREEN
      RGB color definition.
    • DARK_ORANGE

      public static final RGBColor DARK_ORANGE
      RGB color definition.
    • DARK_ORCHID

      public static final RGBColor DARK_ORCHID
      RGB color definition.
    • DARK_RED

      public static final RGBColor DARK_RED
      RGB color definition.
    • DARK_SALMON

      public static final RGBColor DARK_SALMON
      RGB color definition.
    • DARK_SEA_GREEN

      public static final RGBColor DARK_SEA_GREEN
      RGB color definition.
    • DARK_SLATE_BLUE

      public static final RGBColor DARK_SLATE_BLUE
      RGB color definition.
    • DARK_SLATE_GRAY

      public static final RGBColor DARK_SLATE_GRAY
      RGB color definition.
    • DARK_TURQUOISE

      public static final RGBColor DARK_TURQUOISE
      RGB color definition.
    • DARK_VIOLET

      public static final RGBColor DARK_VIOLET
      RGB color definition.
    • DEEP_PINK

      public static final RGBColor DEEP_PINK
      RGB color definition.
    • DEEP_SKY_BLUE

      public static final RGBColor DEEP_SKY_BLUE
      RGB color definition.
    • DIM_GRAY

      public static final RGBColor DIM_GRAY
      RGB color definition.
    • DODGER_BLUE

      public static final RGBColor DODGER_BLUE
      RGB color definition.
    • FELDSPAR

      public static final RGBColor FELDSPAR
      RGB color definition.
    • FIRE_BRICK

      public static final RGBColor FIRE_BRICK
      RGB color definition.
    • FLORAL_WHITE

      public static final RGBColor FLORAL_WHITE
      RGB color definition.
    • FOREST_GREEN

      public static final RGBColor FOREST_GREEN
      RGB color definition.
    • FUCHSIA

      public static final RGBColor FUCHSIA
      RGB color definition.
    • GAINSBORO

      public static final RGBColor GAINSBORO
      RGB color definition.
    • GHOST_WHITE

      public static final RGBColor GHOST_WHITE
      RGB color definition.
    • GOLD

      public static final RGBColor GOLD
      RGB color definition.
    • GOLDEN_ROD

      public static final RGBColor GOLDEN_ROD
      RGB color definition.
    • GRAY

      public static final RGBColor GRAY
      RGB color definition.
    • GREEN

      public static final RGBColor GREEN
      RGB color definition.
    • GREEN_YELLOW

      public static final RGBColor GREEN_YELLOW
      RGB color definition.
    • HONEY_DEW

      public static final RGBColor HONEY_DEW
      RGB color definition.
    • HOT_PINK

      public static final RGBColor HOT_PINK
      RGB color definition.
    • INDIAN_RED

      public static final RGBColor INDIAN_RED
      RGB color definition.
    • INDIGO

      public static final RGBColor INDIGO
      RGB color definition.
    • IVORY

      public static final RGBColor IVORY
      RGB color definition.
    • KHAKI

      public static final RGBColor KHAKI
      RGB color definition.
    • LAVENDER

      public static final RGBColor LAVENDER
      RGB color definition.
    • LAVENDER_BLUSH

      public static final RGBColor LAVENDER_BLUSH
      RGB color definition.
    • LAWN_GREEN

      public static final RGBColor LAWN_GREEN
      RGB color definition.
    • LEMON_CHIFFON

      public static final RGBColor LEMON_CHIFFON
      RGB color definition.
    • LIGHT_BLUE

      public static final RGBColor LIGHT_BLUE
      RGB color definition.
    • LIGHT_CORAL

      public static final RGBColor LIGHT_CORAL
      RGB color definition.
    • LIGHT_CYAN

      public static final RGBColor LIGHT_CYAN
      RGB color definition.
    • LIGHT_GOLDEN_ROD_YELLOW

      public static final RGBColor LIGHT_GOLDEN_ROD_YELLOW
      RGB color definition.
    • LIGHT_GREY

      public static final RGBColor LIGHT_GREY
      RGB color definition.
    • LIGHT_GREEN

      public static final RGBColor LIGHT_GREEN
      RGB color definition.
    • LIGHT_PINK

      public static final RGBColor LIGHT_PINK
      RGB color definition.
    • LIGHT_SALMON

      public static final RGBColor LIGHT_SALMON
      RGB color definition.
    • LIGHT_SEA_GREEN

      public static final RGBColor LIGHT_SEA_GREEN
      RGB color definition.
    • LIGHT_SKY_BLUE

      public static final RGBColor LIGHT_SKY_BLUE
      RGB color definition.
    • LIGHT_SLATE_BLUE

      public static final RGBColor LIGHT_SLATE_BLUE
      RGB color definition.
    • LIGHT_SLATE_GRAY

      public static final RGBColor LIGHT_SLATE_GRAY
      RGB color definition.
    • LIGHT_STEEL_BLUE

      public static final RGBColor LIGHT_STEEL_BLUE
      RGB color definition.
    • LIGHT_YELLOW

      public static final RGBColor LIGHT_YELLOW
      RGB color definition.
    • LIME

      public static final RGBColor LIME
      RGB color definition.
    • LIME_GREEN

      public static final RGBColor LIME_GREEN
      RGB color definition.
    • LINEN

      public static final RGBColor LINEN
      RGB color definition.
    • MAGENTA

      public static final RGBColor MAGENTA
      RGB color definition.
    • MAROON

      public static final RGBColor MAROON
      RGB color definition.
    • MEDIUM_AQUA_MARINE

      public static final RGBColor MEDIUM_AQUA_MARINE
      RGB color definition.
    • MEDIU_MBLUE

      public static final RGBColor MEDIU_MBLUE
      RGB color definition.
    • MEDIUM_ORCHID

      public static final RGBColor MEDIUM_ORCHID
      RGB color definition.
    • MEDIUM_PURPLE

      public static final RGBColor MEDIUM_PURPLE
      RGB color definition.
    • MEDIUM_SEA_GREEN

      public static final RGBColor MEDIUM_SEA_GREEN
      RGB color definition.
    • MEDIUM_SLATE_BLUE

      public static final RGBColor MEDIUM_SLATE_BLUE
      RGB color definition.
    • MEDIUM_SPRING_GREEN

      public static final RGBColor MEDIUM_SPRING_GREEN
      RGB color definition.
    • MEDIUM_TURQUOISE

      public static final RGBColor MEDIUM_TURQUOISE
      RGB color definition.
    • MEDIUM_VIOLET_RED

      public static final RGBColor MEDIUM_VIOLET_RED
      RGB color definition.
    • MIDNIGHT_BLUE

      public static final RGBColor MIDNIGHT_BLUE
      RGB color definition.
    • MINT_CREAM

      public static final RGBColor MINT_CREAM
      RGB color definition.
    • MISTY_ROSE

      public static final RGBColor MISTY_ROSE
      RGB color definition.
    • MOCCASIN

      public static final RGBColor MOCCASIN
      RGB color definition.
    • OLD_LACE

      public static final RGBColor OLD_LACE
      RGB color definition.
    • OLIVE

      public static final RGBColor OLIVE
      RGB color definition.
    • OLIVE_DRAB

      public static final RGBColor OLIVE_DRAB
      RGB color definition.
    • ORANGE

      public static final RGBColor ORANGE
      RGB color definition.
    • ORANGE_RED

      public static final RGBColor ORANGE_RED
      RGB color definition.
    • ORCHID

      public static final RGBColor ORCHID
      RGB color definition.
    • PALE_GOLDEN_ROD

      public static final RGBColor PALE_GOLDEN_ROD
      RGB color definition.
    • PALE_GREEN

      public static final RGBColor PALE_GREEN
      RGB color definition.
    • PALE_TURQUOISE

      public static final RGBColor PALE_TURQUOISE
      RGB color definition.
    • PALE_VIOLET_RED

      public static final RGBColor PALE_VIOLET_RED
      RGB color definition.
    • PAPAYA_WHIP

      public static final RGBColor PAPAYA_WHIP
      RGB color definition.
    • PEACH_PUFF

      public static final RGBColor PEACH_PUFF
      RGB color definition.
    • PERU

      public static final RGBColor PERU
      RGB color definition.
    • PINK

      public static final RGBColor PINK
      RGB color definition.
    • PLUM

      public static final RGBColor PLUM
      RGB color definition.
    • POWDER_BLUE

      public static final RGBColor POWDER_BLUE
      RGB color definition.
    • PURPLE

      public static final RGBColor PURPLE
      RGB color definition.
    • RED

      public static final RGBColor RED
      RGB color definition.
    • ROSY_BROWN

      public static final RGBColor ROSY_BROWN
      RGB color definition.
    • ROYAL_BLUE

      public static final RGBColor ROYAL_BLUE
      RGB color definition.
    • SADDLE_BROWN

      public static final RGBColor SADDLE_BROWN
      RGB color definition.
    • SALMON

      public static final RGBColor SALMON
      RGB color definition.
    • SANDY_BROWN

      public static final RGBColor SANDY_BROWN
      RGB color definition.
    • SEA_GREEN

      public static final RGBColor SEA_GREEN
      RGB color definition.
    • SEA_SHELL

      public static final RGBColor SEA_SHELL
      RGB color definition.
    • SIENNA

      public static final RGBColor SIENNA
      RGB color definition.
    • SILVER

      public static final RGBColor SILVER
      RGB color definition.
    • SKY_BLUE

      public static final RGBColor SKY_BLUE
      RGB color definition.
    • SLATE_BLUE

      public static final RGBColor SLATE_BLUE
      RGB color definition.
    • SLATE_GRAY

      public static final RGBColor SLATE_GRAY
      RGB color definition.
    • SNOW

      public static final RGBColor SNOW
      RGB color definition.
    • SPRING_GREEN

      public static final RGBColor SPRING_GREEN
      RGB color definition.
    • STEEL_BLUE

      public static final RGBColor STEEL_BLUE
      RGB color definition.
    • TAN

      public static final RGBColor TAN
      RGB color definition.
    • TEAL

      public static final RGBColor TEAL
      RGB color definition.
    • THISTLE

      public static final RGBColor THISTLE
      RGB color definition.
    • TOMATO

      public static final RGBColor TOMATO
      RGB color definition.
    • TURQUOISE

      public static final RGBColor TURQUOISE
      RGB color definition.
    • VIOLET

      public static final RGBColor VIOLET
      RGB color definition.
    • VIOLET_RED

      public static final RGBColor VIOLET_RED
      RGB color definition.
    • WHEAT

      public static final RGBColor WHEAT
      RGB color definition.
    • WHITE

      public static final RGBColor WHITE
      RGB color definition.
    • WHITE_SMOKE

      public static final RGBColor WHITE_SMOKE
      RGB color definition.
    • YELLOW

      public static final RGBColor YELLOW
      RGB color definition.
    • YELLOW_GREEN

      public static final RGBColor YELLOW_GREEN
      RGB color definition.
  • Constructor Details

    • RGBColor

      public RGBColor(CharSequence charSequence)
      Creates an RGB color from the specified string representation. This representation can be in one of the following forms:
      • colorname, one of the HTML color names, which must be in all lowercase without delimiters, such as "aliceblue".
      • #rgb, with hexadecimal representation of color components without regard to case.
      • #rrggbb, with hexadecimal representation of color components without regard to case.
      This method also recognizes the transparent color name as equivalent to rgba(0, 0, 0, 0), or black with zero alpha. In most instances, the valueOf(CharSequence) static method is preferred for string-based construction, as it allows singleton instances of named RGB colors to be used.
      Parameters:
      charSequence - The character sequence representation of a color, either a lowercase name of a standard HTML color, or a three or six-digit hex code beginning with '#'.
      Throws:
      NullPointerException - if the given string is null.
      IllegalArgumentException - if a color cannot be determined from the given string.
    • RGBColor

      public RGBColor(int rgb)
      Creates an opaque sRGB color from the specified sRGB color value. Any alpha present is ignored and replaced with alpha of 0xFF.
      Parameters:
      rgb - The color value composed of 8 bits each of red, green, and blue.
    • RGBColor

      public RGBColor(int argb, boolean hasAlpha)
      Creates an sRGB color from the specified sRGB color value and alpha indication.
      Parameters:
      argb - The color value composed of 8 bits each of alpha, red, green, and blue (0xAARRGGBB).
      hasAlpha - true if the given value contains alpha information, else false if default opaque alpha should be added.
    • RGBColor

      public RGBColor(int red, int green, int blue)
      Creates an opaque sRGB color with the specified absolute red, green, and blue component values. The alpha component will be set to its maximum (0xFF).
      Parameters:
      red - The red component on an absolute scale in the range (0x00-0xFF).
      green - The green component on an absolute scale in the range (0x00-0xFF).
      blue - The blue component on an absolute scale in the range (0x00-0xFF).
      Throws:
      IllegalArgumentException - if one of the values is outside the range (0x00-0xFF).
    • RGBColor

      public RGBColor(int red, int green, int blue, int alpha)
      Creates an sRGB color with the specified absolute red, green, blue, and alpha component values.
      Parameters:
      red - The red component on an absolute scale in the range (0x00-0xFF).
      green - The green component on an absolute scale in the range (0x00-0xFF).
      blue - The blue component on an absolute scale in the range (0x00-0xFF).
      alpha - The alpha component on an absolute scale in the range (0x00-0xFF).
      Throws:
      IllegalArgumentException - if one of the values is outside the range (0x00-0xFF).
    • RGBColor

      public RGBColor(double red, double green, double blue)
      Creates an opaque sRGB color with the specified red, green, and blue component values. The alpha component will be set to its maximum (1.0).
      Parameters:
      red - The red component.
      green - The green component.
      blue - The blue component.
      Throws:
      IllegalArgumentException - if one of the values is outside the range (0.0-1.0).
    • RGBColor

      public RGBColor(double red, double green, double blue, double alpha)
      Creates an sRGB color with the specified red, green, blue, and alpha component values.
      Parameters:
      red - The red component.
      green - The green component.
      blue - The blue component.
      alpha - The alpha component.
      Throws:
      IllegalArgumentException - if one of the values is outside the range (0.0-1.0).
  • Method Details

    • getRed

      public double getRed()
      Returns:
      The red component value.
    • getAbsoluteRed8

      public int getAbsoluteRed8()
      Returns:
      The absolute red value at a depth of 8 bits.
    • getGreen

      public double getGreen()
      Returns:
      The green component value.
    • getAbsoluteGreen8

      public int getAbsoluteGreen8()
      Returns:
      The absolute green value at a depth of 8 bits.
    • getBlue

      public double getBlue()
      Returns:
      The blue component value.
    • getAbsoluteBlue8

      public int getAbsoluteBlue8()
      Returns:
      The absolute blue value at a depth of 8 bits.
    • getAlpha

      public double getAlpha()
      Returns:
      The alpha component value.
    • getAbsoluteAlpha8

      public int getAbsoluteAlpha8()
      Returns:
      The absolute alpha value at a depth of 8 bits.
    • asHSL

      public HSLColor asHSL()
      Returns:
      The color in the HSL color space.
    • asRGB

      public RGBColor asRGB()
      Returns:
      The color in the RGB color space.
    • valueOf

      public static RGBColor valueOf(CharSequence charSequence)
      Creates an RGB color from a string representation. This representation can be in one of the following forms:
      • colorname, one of the HTML color names, which must be in all lowercase without delimiters, such as "aliceblue".
      • #rgb, with hexadecimal representation of color components without regard to case.
      • #rrggbb, with hexadecimal representation of color components without regard to case.
      • rgb(red,green,blue), with decimal representation with a depth of eight bits (0-255).
      • rgb(red%,green%,blue%), with decimal component values multiplied by 100 (0.0-100.0%).
      • rgba(red,green,blue,alpha), with decimal representation with a depth of eight bits (0-255).
      • rgba(red%,green%,blue%,alpha%), with decimal component values multiplied by 100 (0.0%-100.0%).
      This method also recognizes the transparent color name as equivalent to rgba(0, 0, 0, 0), or black with zero alpha.
      Parameters:
      charSequence - The character sequence representation of an RGB color.
      Returns:
      An RGB color object representing the color represented by the given string.
      Throws:
      NullPointerException - if the given string is null.
      IllegalArgumentException - if a color cannot be determined from the given string.