|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object prefuse.util.ColorLib
public class ColorLib
Library routines for processing color values. The standard color representation used by prefuse is to store each color as single primitive integer value, using 32 bits to represent 4 8-bit color channels: red, green, blue, and alpha (transparency). An alpha value of 0 indicates complete transparency while a maximum value (255) indicated complete opacity. The layout of the bit is as follows, moving from most significant bit on the left to least significant bit on the right:
AAAAAAAARRRRRRRRGGGGGGGBBBBBBBB
This class also maintains methods for mapping these values to actual
Java Color
instances; a cache is maintained for
quick-lookups, avoiding the need to continually allocate new Color
instances.
Finally, this class also contains routine for creating color palettes for use in visualization.
Field Summary | |
---|---|
static float[] |
CATEGORY_HUES
Default palette of category hues. |
static int |
DEFAULT_MAP_SIZE
The default length of a color palette if its size is not otherwise specified. |
static char |
HEX_PREFIX
|
Constructor Summary | |
---|---|
ColorLib()
|
Method Summary | |
---|---|
static int |
alpha(int color)
Get the alpha component of the given color. |
static int |
blue(int color)
Get the blue component of the given color. |
static int |
brighter(int c)
Get a brighter shade of an input color. |
static void |
clearCache()
Clear the Color object cache. |
static int |
color(java.awt.Color c)
Get the color code for the given Color instance. |
static int |
darker(int c)
Get a darker shade of an input color. |
static int |
desaturate(int c)
Get a desaturated shade of an input color. |
static int |
getCacheLookupCount()
Get the number of cache lookups to the Color object cache. |
static int |
getCacheMissCount()
Get the number of cache misses to the Color object cache. |
static int[] |
getCategoryPalette(int size)
Returns a color palette of given size tries to provide colors appropriate as category labels. |
static int[] |
getCategoryPalette(int size,
float s1,
float s2,
float b,
float a)
Returns a color palette of given size tries to provide colors appropriate as category labels. |
static java.awt.Color |
getColor(float r,
float g,
float b)
Get a Java Color object for the given red, green, and blue values as floating point numbers in the range 0-1.0. |
static java.awt.Color |
getColor(float r,
float g,
float b,
float a)
Get a Java Color object for the given red, green, blue, and alpha values as floating point numbers in the range 0-1.0. |
static java.awt.Color |
getColor(int rgba)
Get a Java Color object for the given color code value. |
static java.awt.Color |
getColor(int r,
int g,
int b)
Get a Java Color object for the given red, green, and blue values. |
static java.awt.Color |
getColor(int r,
int g,
int b,
int a)
Get a Java Color object for the given red, green, and blue values. |
static int[] |
getCoolPalette()
Returns a color palette of default size that uses a "cool", blue-heavy color scheme. |
static int[] |
getCoolPalette(int size)
Returns a color palette that uses a "cool", blue-heavy color scheme. |
static java.awt.Color |
getGrayscale(int v)
Get a Java Color object for the given grayscale value. |
static int[] |
getGrayscalePalette()
Returns a color palette of default size that ranges from white to black through shades of gray. |
static int[] |
getGrayscalePalette(int size)
Returns a color palette of specified size that ranges from white to black through shades of gray. |
static int[] |
getHotPalette()
Returns a color map of default size that moves from black to red to yellow to white. |
static int[] |
getHotPalette(int size)
Returns a color map that moves from black to red to yellow to white. |
static int[] |
getHSBPalette()
Returns a color palette of default size that cycles through the hues of the HSB (Hue/Saturation/Brightness) color space at full saturation and brightness. |
static int[] |
getHSBPalette(int size,
float s,
float b)
Returns a color palette of given size that cycles through the hues of the HSB (Hue/Saturation/Brightness) color space. |
static int[] |
getInterpolatedPalette(int c1,
int c2)
Returns a color palette of default size that ranges from one given color to the other. |
static int[] |
getInterpolatedPalette(int size,
int c1,
int c2)
Returns a color palette of given size that ranges from one given color to the other. |
static int |
gray(int v)
Get the color code for the given grayscale value. |
static int |
gray(int v,
int a)
Get the color code for the given grayscale value. |
static int |
green(int color)
Get the green component of the given color. |
static int |
hex(java.lang.String hex)
Parse a hexadecimal String as a color code. |
static int |
hsb(float h,
float s,
float b)
Get the color code for the given hue, saturation, and brightness values, translating from HSB color space to RGB color space. |
static int |
hsba(float h,
float s,
float b,
float a)
Get the color code for the given hue, saturation, and brightness values, translating from HSB color space to RGB color space. |
static int |
interp(int c1,
int c2,
double frac)
Interpolate between two color values by the given mixing proportion. |
static int |
red(int color)
Get the red component of the given color. |
static int |
rgb(int r,
int g,
int b)
Get the color code for the given red, green, and blue values. |
static int |
rgba(float r,
float g,
float b,
float a)
Get the color code for the given red, green, blue, and alpha values as floating point numbers in the range 0-1.0. |
static int |
rgba(int r,
int g,
int b,
int a)
Get the color code for the given red, green, blue, and alpha values. |
static int |
saturate(int c,
float saturation)
Set the saturation of an input color. |
static int |
setAlpha(int c,
int alpha)
Set the alpha component of the given color. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final char HEX_PREFIX
public static final float[] CATEGORY_HUES
public static final int DEFAULT_MAP_SIZE
Constructor Detail |
---|
public ColorLib()
Method Detail |
---|
public static int rgb(int r, int g, int b)
r
- the red color component (in the range 0-255)g
- the green color component (in the range 0-255)b
- the blue color component (in the range 0-255)
public static int gray(int v)
v
- the grayscale value (in the range 0-255, 0 is
black and 255 is white)
public static int gray(int v, int a)
v
- the grayscale value (in the range 0-255, 0 is
black and 255 is white)a
- the alpha (transparency) value (in the range 0-255)
public static int hex(java.lang.String hex)
hex
- the color code value as a hexadecimal String
public static int hsb(float h, float s, float b)
h
- the hue value (in the range 0-1.0). This represents the
actual color hue (blue, green, purple, etc).s
- the saturation value (in the range 0-1.0). This represents
"how much" of the color is included. Lower values can result in
more grayed out or pastel colors.b
- the brightness value (in the range 0-1.0). This represents
how dark or light the color is.
public static int hsba(float h, float s, float b, float a)
h
- the hue value (in the range 0-1.0). This represents the
actual color hue (blue, green, purple, etc).s
- the saturation value (in the range 0-1.0). This represents
"how much" of the color is included. Lower values can result in
more grayed out or pastel colors.b
- the brightness value (in the range 0-1.0). This represents
how dark or light the color is.a
- the alpha value (in the range 0-1.0). This represents the
transparency of the color.
public static int rgba(int r, int g, int b, int a)
r
- the red color component (in the range 0-255)g
- the green color component (in the range 0-255)b
- the blue color component (in the range 0-255)a
- the alpha (transparency) component (in the range 0-255)
public static int rgba(float r, float g, float b, float a)
r
- the red color component (in the range 0-1.0)g
- the green color component (in the range 0-1.0)b
- the blue color component (in the range 0-1.0)a
- the alpha (transparency) component (in the range 0-1.0)
public static int color(java.awt.Color c)
c
- the Java Color instance
public static int red(int color)
color
- the color code
public static int green(int color)
color
- the color code
public static int blue(int color)
color
- the color code
public static int alpha(int color)
color
- the color code
public static int setAlpha(int c, int alpha)
c
- the color codealpha
- the alpha value to set
public static java.awt.Color getColor(float r, float g, float b, float a)
r
- the red color component (in the range 0-1.0)g
- the green color component (in the range 0-1.0)b
- the blue color component (in the range 0-1.0)a
- the alpha (transparency) component (in the range 0-1.0)
public static java.awt.Color getColor(float r, float g, float b)
r
- the red color component (in the range 0-1.0)g
- the green color component (in the range 0-1.0)b
- the blue color component (in the range 0-1.0)
public static java.awt.Color getColor(int r, int g, int b, int a)
r
- the red color component (in the range 0-255)g
- the green color component (in the range 0-255)b
- the blue color component (in the range 0-255)a
- the alpa (transparency) component (in the range 0-255)
public static java.awt.Color getColor(int r, int g, int b)
r
- the red color component (in the range 0-255)g
- the green color component (in the range 0-255)b
- the blue color component (in the range 0-255)
public static java.awt.Color getGrayscale(int v)
v
- the grayscale value (in the range 0-255, 0 is
black and 255 is white)
public static java.awt.Color getColor(int rgba)
rgba
- the integer color code containing red, green,
blue, and alpha channel information
public static int getCacheMissCount()
public static int getCacheLookupCount()
public static void clearCache()
public static int interp(int c1, int c2, double frac)
c1
- the starting colorc2
- the target colorfrac
- a fraction between 0 and 1.0 controlling the interpolation
amount.
public static int darker(int c)
c
- a color code
public static int brighter(int c)
c
- a color code
public static int desaturate(int c)
c
- a color code
public static int saturate(int c, float saturation)
c
- a color codesaturation
- the new sautration value
public static int[] getCoolPalette(int size)
size
- the size of the color palette
public static int[] getCoolPalette()
public static int[] getHotPalette(int size)
size
- the size of the color palette
public static int[] getHotPalette()
public static int[] getCategoryPalette(int size, float s1, float s2, float b, float a)
size
- the size of the color palettes1
- the initial saturation to uses2
- the final (most distant) saturation to useb
- the brightness value to usea
- the alpha value to usepublic static int[] getCategoryPalette(int size)
size
- the size of the color palettepublic static int[] getHSBPalette(int size, float s, float b)
size
- the size of the color palettes
- the saturation value to useb
- the brightness value to use
public static int[] getHSBPalette()
public static int[] getInterpolatedPalette(int size, int c1, int c2)
size
- the size of the color palettec1
- the initial color in the color mapc2
- the final color in the color map
public static int[] getInterpolatedPalette(int c1, int c2)
c1
- the initial color in the color mapc2
- the final color in the color map
public static int[] getGrayscalePalette(int size)
size
- the size of the color palette
public static int[] getGrayscalePalette()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |