PulpCore

pulpcore.image
Class Colors

java.lang.Object
  extended by pulpcore.image.Colors

public class Colors
extends Object

The Colors class provides convenience methods to create packed, 32-bit ARGB colors.


Field Summary
static int BLACK
          The color black.
static int BLUE
          The color blue.
static int CYAN
          The color cyan.
static int DARKGRAY
          The color dark black.
static int GRAY
          The color gray.
static int GREEN
          The color green.
static int LIGHTGRAY
          The color light gray.
static int MAGENTA
          The color magenta.
static int ORANGE
          The color orange.
static int PURPLE
          The color purple.
static int RED
          The color red.
static int TRANSPARENT
          Fully transparent color.
static int WHITE
          The color white.
static int YELLOW
          The color yellow.
 
Method Summary
static int brighter(int color)
          Creates a brighter version of the specified color.
static int darker(int color)
          Creates a darker version of the specified color.
static int getAlpha(int color)
          Gets the alpha component of a 32-bit ARGB color.
static int getBlue(int color)
          Gets the blue component of a 32-bit ARGB color.
static int getBrightness(int color)
          Gets the brightness of a 32-bit ARGB color.
static int getGreen(int color)
          Gets the green component of a 32-bit ARGB color.
static int getHue(int color)
          Gets the hue of a 32-bit ARGB color.
static int getRed(int color)
          Gets the red component of a 32-bit ARGB color.
static int getSaturation(int color)
          Gets the saturation of a 32-bit ARGB color.
static int gray(int gray)
          Creates an opaque gray color.
static int gray(int gray, int alpha)
          Creates a translucent gray color.
static int hsb(int h, int s, int b)
          Creates an opaque color.
static int hsba(int h, int s, int b, int alpha)
          Creates a color with alpha.
static int HSBtoRGB(int ahsbColor)
          Converts a packed, 32-bit HSB (hue, saturation, brightness) color to RGB (red, green, blue).
static int hue(int h)
          Creates a fully bright, fully saturated opaque color with the specified hue.
static int hue(int h, int alpha)
          Creates a fully bright, fully saturated color with the specified hue.
static boolean isGray(int color)
          Checks if a 32-bit ARGB color is a gray color, from 0 (black) to 255 (white).
static int premultiply(int argbColor)
          Converts an ARGB color to a premultiplied ARGB color.
static int premultiply(int rgbColor, int alpha)
          Premultiples an RGB color with the specified alpha.
static int rgb(int rgb)
          Creates an opaque color.
static int rgb(int rgb, boolean hasAlpha)
          Creates a color.
static int rgb(int r, int g, int b)
          Creates an opaque color.
static int rgba(int rgb, int alpha)
          Creates a color with alpha.
static int rgba(int r, int g, int b, int alpha)
          Creates a color with alpha.
static int RGBtoHSB(int argbColor)
          Converts a a packed, 32-bit RGB (red, green, blue) color to HSB (hue, saturation, brightness).
static String RGBtoString(int color)
          Returns a string representation of the specified color.
static int unpremultiply(int preARGBColor)
          Converts a premultiplied ARGB color to an ARGB color.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

TRANSPARENT

public static final int TRANSPARENT
Fully transparent color. Same as gray(0, 0).


BLACK

public static final int BLACK
The color black. Same as gray(0).


WHITE

public static final int WHITE
The color white. Same as gray(255).


LIGHTGRAY

public static final int LIGHTGRAY
The color light gray. Same as gray(192).


GRAY

public static final int GRAY
The color gray. Same as gray(128).


DARKGRAY

public static final int DARKGRAY
The color dark black. Same as gray(64).


RED

public static final int RED
The color red. Same as rgb(255, 0 0).


ORANGE

public static final int ORANGE
The color orange. Same as rgb(255, 200, 0).


YELLOW

public static final int YELLOW
The color yellow. Same as rgb(255, 255, 0).


GREEN

public static final int GREEN
The color green. Same as rgb(0, 255, 0).


CYAN

public static final int CYAN
The color cyan. Same as rgb(0, 255, 255).


BLUE

public static final int BLUE
The color blue. Same as rgb(0, 0, 255).


PURPLE

public static final int PURPLE
The color purple. Same as rgb(162, 0, 255).


MAGENTA

public static final int MAGENTA
The color magenta. Same as rgb(255, 0, 255).

Method Detail

gray

public static int gray(int gray)
Creates an opaque gray color.

Parameters:
gray - the gray value from 0 (black) to 255 (white).
Returns:
a packed 32-bit ARGB color.

gray

public static int gray(int gray,
                       int alpha)
Creates a translucent gray color.

Parameters:
gray - the gray value from 0 (black) to 255 (white).
alpha - the opacity from 0 (transparent) to 255 (opaque).
Returns:
a packed 32-bit ARGB color.

rgb

public static int rgb(int rgb)
Creates an opaque color. This method ensures the alpha is set to 255 (opaque).

Parameters:
rgb - a packed 32-bit ARGB color.
Returns:
a packed 32-bit ARGB color with the alpha set to 255 (opaque).

rgb

public static int rgb(int rgb,
                      boolean hasAlpha)
Creates a color. If hasAlpha is true, this method returns rgb without modification. Otherwise, this method sets the alpha to 255 (opaque).

Parameters:
rgb - a packed 32-bit ARGB color.
hasAlpha - flag indicating the rgb param has alpha or not.
Returns:
a packed 32-bit ARGB color with the alpha set.

rgba

public static int rgba(int rgb,
                       int alpha)
Creates a color with alpha. The original color's alpha value, if any, is ignored.

Parameters:
rgb - a packed 32-bit ARGB color.
alpha - the alpha component, from 0 (transparent) to 255 (opaque).
Returns:
a packed 32-bit ARGB color.

rgb

public static int rgb(int r,
                      int g,
                      int b)
Creates an opaque color.

Parameters:
r - the red component, from 0 to 255.
g - the green component, from 0 to 255.
b - the blue component, from 0 to 255.
Returns:
a packed 32-bit ARGB color with the alpha set to 255 (opaque).

rgba

public static int rgba(int r,
                       int g,
                       int b,
                       int alpha)
Creates a color with alpha.

Parameters:
r - the red component, from 0 to 255.
g - the green component, from 0 to 255.
b - the blue component, from 0 to 255.
alpha - the alpha component, from 0 (transparent) to 255 (opaque).
Returns:
a packed 32-bit ARGB color.

hue

public static int hue(int h)
Creates a fully bright, fully saturated opaque color with the specified hue.

Parameters:
h - the hue, from 0 to 255.
Returns:
a packed 32-bit ARGB color with the alpha set to 255 (opaque).

hue

public static int hue(int h,
                      int alpha)
Creates a fully bright, fully saturated color with the specified hue.

Parameters:
h - the hue, from 0 to 255.
alpha - the alpha component, from 0 (transparent) to 255 (opaque).
Returns:
a packed 32-bit ARGB color.

hsb

public static int hsb(int h,
                      int s,
                      int b)
Creates an opaque color.

Parameters:
h - the hue, from 0 to 255.
s - the saturation, from 0 to 255.
b - the brightness, from 0 to 255.
Returns:
a packed 32-bit ARGB color with the alpha set to 255 (opaque).

hsba

public static int hsba(int h,
                       int s,
                       int b,
                       int alpha)
Creates a color with alpha.

Parameters:
h - the hue, from 0 to 255.
s - the saturation, from 0 to 255.
b - the brightness, from 0 to 255.
alpha - the alpha component, from 0 (transparent) to 255 (opaque).
Returns:
a packed 32-bit ARGB color.

getAlpha

public static int getAlpha(int color)
Gets the alpha component of a 32-bit ARGB color.

Parameters:
color - a 32-bit ARGB color.
Returns:
the alpha component, from 0 to 255.

getRed

public static int getRed(int color)
Gets the red component of a 32-bit ARGB color.

Parameters:
color - a 32-bit ARGB color.
Returns:
the red component, from 0 to 255.

getGreen

public static int getGreen(int color)
Gets the green component of a 32-bit ARGB color.

Parameters:
color - a 32-bit ARGB color.
Returns:
the green component, from 0 to 255.

getBlue

public static int getBlue(int color)
Gets the blue component of a 32-bit ARGB color.

Parameters:
color - a 32-bit ARGB color.
Returns:
the blue component, from 0 to 255.

getHue

public static int getHue(int color)
Gets the hue of a 32-bit ARGB color.

Parameters:
color - a 32-bit ARGB color.
Returns:
the hue, from 0 to 255.

getSaturation

public static int getSaturation(int color)
Gets the saturation of a 32-bit ARGB color.

Parameters:
color - a 32-bit ARGB color.
Returns:
the saturation, from 0 to 255.

getBrightness

public static int getBrightness(int color)
Gets the brightness of a 32-bit ARGB color.

Parameters:
color - a 32-bit ARGB color.
Returns:
the brightness, from 0 to 255.

isGray

public static boolean isGray(int color)
Checks if a 32-bit ARGB color is a gray color, from 0 (black) to 255 (white).

Parameters:
color - a 32-bit ARGB color.
Returns:
true if the color is gray.

brighter

public static int brighter(int color)
Creates a brighter version of the specified color. The alpha is not modified.

Parameters:
color - a 32-bit ARGB color.
Returns:
a brighter version of the 32-bit ARGB color.

darker

public static int darker(int color)
Creates a darker version of the specified color. The alpha is not modified.

Parameters:
color - a 32-bit ARGB color.
Returns:
a darker version of the 32-bit ARGB color.

RGBtoString

public static String RGBtoString(int color)
Returns a string representation of the specified color.

Parameters:
color - a 32-bit ARGB color.
Returns:
a string representation of the color.

RGBtoHSB

public static int RGBtoHSB(int argbColor)
Converts a a packed, 32-bit RGB (red, green, blue) color to HSB (hue, saturation, brightness). The hue, saturation, and brightness are in the range 0 - 255. The alpha value, if any, is not modified.
        int hsb = Colors.RGBtoHSB(rgb);
        int h = (hsb >> 16) & 0xff;
        int s = (hsb >> 8) & 0xff;
        int b = hsb & 0xff;
        

Parameters:
argbColor - a 32-bit ARGB color.
Returns:
a 32-bit AHSB color.
See Also:
HSBtoRGB(int)

HSBtoRGB

public static int HSBtoRGB(int ahsbColor)
Converts a packed, 32-bit HSB (hue, saturation, brightness) color to RGB (red, green, blue). The alpha value, if any, is not modified.
        int rgb = Colors.HSBtoRGB(hsb);
        int r = (rgb >> 16) & 0xff;
        int g = (rgb >> 8) & 0xff;
        int b = rgb & 0xff;
        

Parameters:
ahsbColor - a 32-bit AHSB color.
Returns:
a 32-bit ARGB color.
See Also:
RGBtoHSB(int)

premultiply

public static int premultiply(int argbColor)
Converts an ARGB color to a premultiplied ARGB color.

Parameters:
argbColor - the ARGB color to premultiply
Returns:
the premultiplied ARGB color

premultiply

public static int premultiply(int rgbColor,
                              int alpha)
Premultiples an RGB color with the specified alpha.

Parameters:
rgbColor - the RGB color to premultiply
alpha - the alpha value, from 0 to 255
Returns:
the premultiplied ARGB color

unpremultiply

public static int unpremultiply(int preARGBColor)
Converts a premultiplied ARGB color to an ARGB color.

Parameters:
preARGBColor - the premultiplied ARGB color to premultiply
Returns:
the converted ARGB color

PulpCore

Copyright © 2007-2009 Interactive Pulp, LLC.