| Method from java.awt.Color Detail: |
public static int HSBtoRGB(float hue,
float saturation,
float brightness) {
float fr, fg, fb;
if(saturation == 0) {
fr = fg = fb = brightness;
} else {
float H = (hue - (float)Math.floor(hue)) * 6;
int I = (int) Math.floor(H);
float F = H - I;
float M = brightness * (1 - saturation);
float N = brightness * (1 - saturation * F);
float K = brightness * (1 - saturation * (1 - F));
switch(I) {
case 0:
fr = brightness; fg = K; fb = M; break;
case 1:
fr = N; fg = brightness; fb = M; break;
case 2:
fr = M; fg = brightness; fb = K; break;
case 3:
fr = M; fg = N; fb = brightness; break;
case 4:
fr = K; fg = M; fb = brightness; break;
case 5:
fr = brightness; fg = M; fb = N; break;
default:
fr = fb = fg = 0; // impossible, to supress compiler error
}
}
int r = (int) (fr * 255. + 0.5);
int g = (int) (fg * 255. + 0.5);
int b = (int) (fb * 255. + 0.5);
return (r < < 16) | (g < < 8) | b | 0xFF000000;
}
|
public static float[] RGBtoHSB(int r,
int g,
int b,
float[] hsbvals) {
if(hsbvals == null) {
hsbvals = new float[3];
}
int V = Math.max(b, Math.max(r, g));
int temp = Math.min(b, Math.min(r, g));
float H, S, B;
B = V/255.f;
if(V == temp) {
H = S = 0;
} else {
S = (V - temp)/((float)V);
float Cr = (V - r) / (float)(V - temp);
float Cg = (V - g) / (float)(V - temp);
float Cb = (V - b) / (float)(V - temp);
if (r == V) {
H = Cb - Cg;
} else if (g == V) {
H = 2 + Cr - Cb;
} else {
H = 4 + Cg - Cr;
}
H /= 6.f;
if(H < 0) {
H++;
}
}
hsbvals[0] = H;
hsbvals[1] = S;
hsbvals[2] = B;
return hsbvals;
}
|
public Color brighter() {
int r = getRed();
int b = getBlue();
int g = getGreen();
if(r == 0 && b == 0 && g == 0) {
return new Color(MIN_SCALABLE, MIN_SCALABLE, MIN_SCALABLE);
}
if(r < MIN_SCALABLE && r != 0) {
r = MIN_SCALABLE;
} else {
r = (int) (r/SCALE_FACTOR);
r = (r > 255) ? 255 : r;
}
if(b < MIN_SCALABLE && b != 0) {
b = MIN_SCALABLE;
} else {
b = (int) (b/SCALE_FACTOR);
b = (b > 255) ? 255 : b;
}
if(g < MIN_SCALABLE && g != 0) {
g = MIN_SCALABLE;
} else {
g = (int) (g/SCALE_FACTOR);
g = (g > 255) ? 255 : g;
}
return new Color(r, g, b);
}
|
public PaintContext createContext(ColorModel cm,
Rectangle r,
Rectangle2D r2d,
AffineTransform xform,
RenderingHints rhs) {
if(currentPaintContext != null) {
return currentPaintContext;
}
currentPaintContext = new Color.ColorPaintContext(value);
return currentPaintContext;
}
|
public Color darker() {
return new Color(
(int)(getRed()*SCALE_FACTOR),
(int)(getGreen()*SCALE_FACTOR),
(int)(getBlue()*SCALE_FACTOR));
}
|
public static Color decode(String nm) throws NumberFormatException {
Integer integer = Integer.decode(nm);
return new Color(integer.intValue());
}
|
public boolean equals(Object obj) {
if(obj instanceof Color) {
return ((Color)obj).value == this.value;
}
return false;
}
|
public int getAlpha() {
return (value > > 24) & 0xFF;
}
|
public int getBlue() {
return value & 0xFF;
}
|
public static Color getColor(String nm) {
Integer integer = Integer.getInteger(nm);
if (integer == null) {
return null;
}
return new Color(integer.intValue());
}
|
public static Color getColor(String nm,
Color def) {
Integer integer = Integer.getInteger(nm);
if (integer == null) {
return def;
}
return new Color(integer.intValue());
}
|
public static Color getColor(String nm,
int def) {
Integer integer = Integer.getInteger(nm);
if (integer == null) {
return new Color(def);
}
return new Color(integer.intValue());
}
|
public float[] getColorComponents(float[] components) {
if(fvalue == null) {
return getRGBColorComponents(components);
}
if(components == null) {
components = new float[fvalue.length];
}
for(int i=0; i< fvalue.length; i++) {
components[i] = fvalue[i];
}
return components;
}
|
public float[] getColorComponents(ColorSpace colorSpace,
float[] components) {
float[] cieXYZComponents = getColorSpace().toCIEXYZ(getColorComponents(null));
float[] csComponents = colorSpace.fromCIEXYZ(cieXYZComponents);
if(components == null) {
return csComponents;
}
for(int i=0; i< csComponents.length; i++) {
components[i] = csComponents[i];
}
return components;
}
|
public ColorSpace getColorSpace() {
if (cs == null) {
cs = ColorSpace.getInstance(ColorSpace.CS_sRGB);
}
return cs;
}
|
public float[] getComponents(float[] components) {
if(fvalue == null) {
return getRGBComponents(components);
}
int nColorComps = fvalue.length;
if(components == null) {
components = new float[nColorComps+1];
}
getColorComponents(components);
components[nColorComps] = falpha;
return components;
}
|
public float[] getComponents(ColorSpace colorSpace,
float[] components) {
int nComps = colorSpace.getNumComponents();
if(components == null) {
components = new float[nComps+1];
}
getColorComponents(colorSpace, components);
if(frgbvalue != null) {
components[nComps] = falpha;
} else {
components[nComps] = getAlpha()/255f;
}
return components;
}
|
public int getGreen() {
return (value > > 8) & 0xFF;
}
|
public static Color getHSBColor(float h,
float s,
float b) {
return new Color(HSBtoRGB(h, s, b));
}
|
public int getRGB() {
return value;
}
|
public float[] getRGBColorComponents(float[] components) {
if(components == null) {
components = new float[3];
}
if(frgbvalue != null) {
components[2] = frgbvalue[2];
components[1] = frgbvalue[1];
components[0] = frgbvalue[0];
} else {
components[2] = getBlue()/255f;
components[1] = getGreen()/255f;
components[0] = getRed()/255f;
}
return components;
}
|
public float[] getRGBComponents(float[] components) {
if(components == null) {
components = new float[4];
}
if(frgbvalue != null) {
components[3] = falpha;
} else {
components[3] = getAlpha()/255f;
}
getRGBColorComponents(components);
return components;
}
|
public int getRed() {
return (value > > 16) & 0xFF;
}
|
public int getTransparency() {
switch(getAlpha()) {
case 0xff:
return Transparency.OPAQUE;
case 0:
return Transparency.BITMASK;
default:
return Transparency.TRANSLUCENT;
}
}
|
public int hashCode() {
return value;
}
|
public String toString() {
/*
The format of the string is based on 1.5 release behavior which
can be revealed using the following code:
Color c = new Color(1, 2, 3);
System.out.println(c);
*/
return getClass().getName() +
"[r=" + getRed() + //$NON-NLS-1$
",g=" + getGreen() + //$NON-NLS-1$
",b=" + getBlue() + //$NON-NLS-1$
"]"; //$NON-NLS-1$
}
|