1 |
/* |
/* |
2 |
ColorUtil.java |
ColorUtil.java |
3 |
* |
* |
4 |
* Copyright (c) 2001, Ted Nelson and Tuomas Lukka |
* Copyright (c) 2001-2002, Ted Nelson and Tuomas Lukka |
5 |
* |
* |
6 |
* You may use and distribute under the terms of either the GNU Lesser |
* You may use and distribute under the terms of either the GNU Lesser |
7 |
* General Public License, either version 2 of the license or, |
* General Public License, either version 2 of the license or, |
59 |
return res; |
return res; |
60 |
} |
} |
61 |
|
|
62 |
|
|
63 |
public static String colorGLString(Color c) { |
public static String colorGLString(Color c) { |
64 |
//float[] f = c.getRGBColorComponents(null); |
//float[] f = c.getRGBColorComponents(null); |
65 |
//return ""+f[0]+" "+f[1]+" "+f[2]; |
//return ""+f[0]+" "+f[1]+" "+f[2]; |
77 |
((value & GREEN_MASK) >> 8) / 255f + " " + |
((value & GREEN_MASK) >> 8) / 255f + " " + |
78 |
(value & BLUE_MASK) / 255f; |
(value & BLUE_MASK) / 255f; |
79 |
} |
} |
80 |
|
|
81 |
|
/** Get the average color of an array of colors. |
82 |
|
*/ |
83 |
|
public static Color avgColor(int[] colors) { |
84 |
|
float r = 0, g = 0, b = 0; |
85 |
|
for(int i=0; i<colors.length; i++) { |
86 |
|
int c = colors[i]; |
87 |
|
r += (c >> 16) & 0xff; |
88 |
|
g += (c >> 8) & 0xff; |
89 |
|
b += (c >> 0) & 0xff; |
90 |
|
} |
91 |
|
r /= colors.length; |
92 |
|
g /= colors.length; |
93 |
|
b /= colors.length; |
94 |
|
r /= 255; |
95 |
|
g /= 255; |
96 |
|
b /= 255; |
97 |
|
return new Color(r, g, b); |
98 |
|
} |
99 |
} |
} |