39 |
package java.awt.image; |
package java.awt.image; |
40 |
|
|
41 |
/** |
/** |
|
* |
|
42 |
* @author C. Brian Jones (cbj@gnu.org) |
* @author C. Brian Jones (cbj@gnu.org) |
43 |
*/ |
*/ |
44 |
public class IndexColorModel extends ColorModel |
public class IndexColorModel extends ColorModel |
46 |
private int map_size; |
private int map_size; |
47 |
private boolean opaque; |
private boolean opaque; |
48 |
private int trans = -1; |
private int trans = -1; |
|
|
|
49 |
private int[] rgb; |
private int[] rgb; |
50 |
|
|
51 |
/** |
/** |
61 |
* @param blues the blue component of all colors |
* @param blues the blue component of all colors |
62 |
*/ |
*/ |
63 |
public IndexColorModel(int bits, int size, byte[] reds, byte[] greens, |
public IndexColorModel(int bits, int size, byte[] reds, byte[] greens, |
64 |
byte[] blues) { |
byte[] blues) |
65 |
|
{ |
66 |
this(bits, size, reds, greens, blues, (byte[])null); |
this(bits, size, reds, greens, blues, (byte[])null); |
67 |
} |
} |
68 |
|
|
80 |
* @param trans the index of the transparent color |
* @param trans the index of the transparent color |
81 |
*/ |
*/ |
82 |
public IndexColorModel(int bits, int size, byte[] reds, byte[] greens, |
public IndexColorModel(int bits, int size, byte[] reds, byte[] greens, |
83 |
byte[] blues, int trans) { |
byte[] blues, int trans) |
84 |
|
{ |
85 |
this(bits, size, reds, greens, blues, (byte[])null); |
this(bits, size, reds, greens, blues, (byte[])null); |
86 |
this.trans = trans; |
this.trans = trans; |
87 |
} |
} |
100 |
* @param alphas the alpha component of all colors |
* @param alphas the alpha component of all colors |
101 |
*/ |
*/ |
102 |
public IndexColorModel(int bits, int size, byte[] reds, byte[] greens, |
public IndexColorModel(int bits, int size, byte[] reds, byte[] greens, |
103 |
byte[] blues, byte[] alphas) { |
byte[] blues, byte[] alphas) |
104 |
|
{ |
105 |
super(bits); |
super(bits); |
106 |
map_size = size; |
map_size = size; |
107 |
opaque = (alphas == null); |
opaque = (alphas == null); |
108 |
|
|
109 |
rgb = new int[size]; |
rgb = new int[size]; |
110 |
if (alphas == null) { |
if (alphas == null) |
111 |
for (int i = 0; i < size; i++) { |
{ |
112 |
rgb[i] = 0xff000000 | |
for (int i = 0; i < size; i++) |
113 |
((reds[i] & 0xff) << 16) | |
{ |
114 |
((greens[i] & 0xff) << 8) | |
rgb[i] = (0xff000000 |
115 |
(blues[i] & 0xff); |
| ((reds[i] & 0xff) << 16) |
116 |
|
| ((greens[i] & 0xff) << 8) |
117 |
|
| (blues[i] & 0xff)); |
118 |
} |
} |
119 |
} |
} |
120 |
else { |
else |
121 |
for (int i = 0; i < size; i++) { |
{ |
122 |
rgb[i] = ((alphas[i] & 0xff) << 24 | |
for (int i = 0; i < size; i++) |
123 |
((reds[i] & 0xff) << 16) | |
{ |
124 |
((greens[i] & 0xff) << 8) | |
rgb[i] = ((alphas[i] & 0xff) << 24 |
125 |
(blues[i] & 0xff)); |
| ((reds[i] & 0xff) << 16) |
126 |
|
| ((greens[i] & 0xff) << 8) |
127 |
|
| (blues[i] & 0xff)); |
128 |
} |
} |
129 |
} |
} |
130 |
} |
} |
142 |
* @param hasAlpha <code>cmap</code> has alpha values |
* @param hasAlpha <code>cmap</code> has alpha values |
143 |
*/ |
*/ |
144 |
public IndexColorModel(int bits, int size, byte[] cmap, int start, |
public IndexColorModel(int bits, int size, byte[] cmap, int start, |
145 |
boolean hasAlpha) { |
boolean hasAlpha) |
146 |
|
{ |
147 |
this(bits, size, cmap, start, hasAlpha, -1); |
this(bits, size, cmap, start, hasAlpha, -1); |
148 |
} |
} |
149 |
|
|
161 |
* @param trans the index of the transparent color |
* @param trans the index of the transparent color |
162 |
*/ |
*/ |
163 |
public IndexColorModel(int bits, int size, byte[] cmap, int start, |
public IndexColorModel(int bits, int size, byte[] cmap, int start, |
164 |
boolean hasAlpha, int trans) { |
boolean hasAlpha, int trans) |
165 |
|
{ |
166 |
super(bits); |
super(bits); |
167 |
map_size = size; |
map_size = size; |
168 |
opaque = !hasAlpha; |
opaque = !hasAlpha; |
169 |
this.trans = trans; |
this.trans = trans; |
170 |
} |
} |
171 |
|
|
172 |
public final int getMapSize() { |
public final int getMapSize () |
173 |
|
{ |
174 |
return map_size; |
return map_size; |
175 |
} |
} |
176 |
|
|
177 |
/** |
/** |
178 |
* Get the index of the transparent color in this color model |
* Get the index of the transparent color in this color model |
179 |
*/ |
*/ |
180 |
public final int getTransparentPixel() { |
public final int getTransparentPixel () |
181 |
|
{ |
182 |
return trans; |
return trans; |
183 |
} |
} |
184 |
|
|
185 |
/** |
/** |
186 |
* <br> |
* <br> |
187 |
*/ |
*/ |
188 |
public final void getReds(byte[] r) { |
public final void getReds (byte[] r) |
189 |
|
{ |
190 |
getComponents( r, 2 ); |
getComponents( r, 2 ); |
191 |
} |
} |
192 |
|
|
193 |
/** |
/** |
194 |
* <br> |
* <br> |
195 |
*/ |
*/ |
196 |
public final void getGreens(byte[] g) { |
public final void getGreens (byte[] g) |
197 |
|
{ |
198 |
getComponents( g, 1 ); |
getComponents( g, 1 ); |
199 |
} |
} |
200 |
|
|
201 |
/** |
/** |
202 |
* <br> |
* <br> |
203 |
*/ |
*/ |
204 |
public final void getBlues(byte[] b) { |
public final void getBlues (byte[] b) |
205 |
|
{ |
206 |
getComponents( b, 0 ); |
getComponents( b, 0 ); |
207 |
} |
} |
208 |
|
|
209 |
/** |
/** |
210 |
* <br> |
* <br> |
211 |
*/ |
*/ |
212 |
public final void getAlphas(byte[] a) { |
public final void getAlphas (byte[] a) |
213 |
|
{ |
214 |
getComponents( a, 3 ); |
getComponents( a, 3 ); |
215 |
} |
} |
216 |
|
|
223 |
|
|
224 |
/** |
/** |
225 |
* Get the red component of the given pixel. |
* Get the red component of the given pixel. |
|
* <br> |
|
226 |
*/ |
*/ |
227 |
public final int getRed(int pixel) { |
public final int getRed (int pixel) |
228 |
|
{ |
229 |
if( pixel < map_size ) |
if( pixel < map_size ) |
230 |
return (int)(( generateMask( 2 ) & rgb[pixel]) >> (2 * pixel_bits ) ); |
return (int)(( generateMask( 2 ) & rgb[pixel]) >> (2 * pixel_bits ) ); |
231 |
|
|
232 |
return 0; |
return 0; |
233 |
} |
} |
234 |
|
|
235 |
/** |
/** |
236 |
* Get the green component of the given pixel. |
* Get the green component of the given pixel. |
|
* <br> |
|
237 |
*/ |
*/ |
238 |
public final int getGreen(int pixel) { |
public final int getGreen (int pixel) |
239 |
|
{ |
240 |
if( pixel < map_size ) |
if( pixel < map_size ) |
241 |
return (int)(( generateMask( 1 ) & rgb[pixel]) >> (1 * pixel_bits ) ); |
return (int)(( generateMask( 1 ) & rgb[pixel]) >> (1 * pixel_bits ) ); |
242 |
|
|
243 |
return 0; |
return 0; |
244 |
} |
} |
245 |
|
|
246 |
/** |
/** |
247 |
* Get the blue component of the given pixel. |
* Get the blue component of the given pixel. |
|
* <br> |
|
248 |
*/ |
*/ |
249 |
public final int getBlue(int pixel) { |
public final int getBlue (int pixel) |
250 |
|
{ |
251 |
if( pixel < map_size ) |
if( pixel < map_size ) |
252 |
return (int)( generateMask( 0 ) & rgb[pixel]); |
return (int)( generateMask( 0 ) & rgb[pixel]); |
253 |
|
|
254 |
return 0; |
return 0; |
255 |
} |
} |
256 |
|
|
257 |
/** |
/** |
258 |
* Get the alpha component of the given pixel. |
* Get the alpha component of the given pixel. |
|
* <br> |
|
259 |
*/ |
*/ |
260 |
public final int getAlpha(int pixel) { |
public final int getAlpha (int pixel) |
261 |
|
{ |
262 |
if( pixel < map_size ) |
if( pixel < map_size ) |
263 |
return (int)(( generateMask( 3 ) & rgb[pixel]) >> (3 * pixel_bits ) ); |
return (int)(( generateMask( 3 ) & rgb[pixel]) >> (3 * pixel_bits ) ); |
264 |
|
|
265 |
return 0; |
return 0; |
266 |
} |
} |
267 |
|
|
268 |
/** |
/** |
269 |
* Get the RGB color value of the given pixel using the default |
* Get the RGB color value of the given pixel using the default |
270 |
* RGB color model. |
* RGB color model. |
|
* <br> |
|
271 |
* |
* |
272 |
* @param pixel a pixel value |
* @param pixel a pixel value |
273 |
*/ |
*/ |
274 |
public final int getRGB(int pixel) { |
public final int getRGB (int pixel) |
275 |
|
{ |
276 |
if( pixel < map_size ) |
if( pixel < map_size ) |
277 |
return rgb[pixel]; |
return rgb[pixel]; |
278 |
|
|
279 |
return 0; |
return 0; |
280 |
} |
} |
281 |
|
|