166 |
* @param cmap packed color components |
* @param cmap packed color components |
167 |
* @param start the offset of the first color component in <code>cmap</code> |
* @param start the offset of the first color component in <code>cmap</code> |
168 |
* @param hasAlpha <code>cmap</code> has alpha values |
* @param hasAlpha <code>cmap</code> has alpha values |
169 |
|
* @throws IllegalArgumentException if bits < 1, bits > 16, or size < 1. |
170 |
*/ |
*/ |
171 |
public IndexColorModel (int bits, int size, byte[] cmap, int start, |
public IndexColorModel (int bits, int size, byte[] cmap, int start, |
172 |
boolean hasAlpha) |
boolean hasAlpha) |
175 |
} |
} |
176 |
|
|
177 |
/** |
/** |
178 |
* Each array much contain <code>size</code> elements. For each |
* Construct an IndexColorModel from an array of red, green, blue, and |
179 |
* array, the i-th color is described by reds[i], greens[i], |
* optional alpha components. The component values are interleaved as RGB(A). |
180 |
* blues[i], alphas[i], unless alphas is not specified, then all the |
* |
|
* colors are opaque except for the transparent color. |
|
|
* |
|
181 |
* @param bits the number of bits needed to represent <code>size</code> colors |
* @param bits the number of bits needed to represent <code>size</code> colors |
182 |
* @param size the number of colors in the color map |
* @param size the number of colors in the color map |
183 |
* @param cmap packed color components |
* @param cmap interleaved color components |
184 |
* @param start the offset of the first color component in <code>cmap</code> |
* @param start the offset of the first color component in <code>cmap</code> |
185 |
* @param hasAlpha <code>cmap</code> has alpha values |
* @param hasAlpha <code>cmap</code> has alpha values |
186 |
* @param trans the index of the transparent color |
* @param trans the index of the transparent color |
187 |
|
* @throws IllegalArgumentException if bits < 1, bits > 16, or size < 1. |
188 |
*/ |
*/ |
189 |
public IndexColorModel (int bits, int size, byte[] cmap, int start, |
public IndexColorModel (int bits, int size, byte[] cmap, int start, |
190 |
boolean hasAlpha, int trans) |
boolean hasAlpha, int trans) |
191 |
{ |
{ |
192 |
super (bits); |
super (bits); |
193 |
|
if (bits > 16) |
194 |
|
throw new IllegalArgumentException("bits > 16"); |
195 |
|
if (size < 1) |
196 |
|
throw new IllegalArgumentException("size < 1"); |
197 |
map_size = size; |
map_size = size; |
198 |
opaque = !hasAlpha; |
opaque = !hasAlpha; |
199 |
this.trans = trans; |
this.trans = trans; |
200 |
|
|
201 |
|
rgb = new int[size]; |
202 |
|
if (hasAlpha) |
203 |
|
{ |
204 |
|
for (int i = 0; i < size; i++) |
205 |
|
rgb[i] = |
206 |
|
// alpha |
207 |
|
((cmap[4 * i + 3 + start] & 0xff) << 24 |
208 |
|
// red |
209 |
|
| ((cmap[4 * i + start] & 0xff) << 16) |
210 |
|
// green |
211 |
|
| ((cmap[4 * i + 1 + start] & 0xff) << 8) |
212 |
|
// blue |
213 |
|
| (cmap[4 * i + 2 + start] & 0xff)); |
214 |
|
} |
215 |
|
else |
216 |
|
{ |
217 |
|
for (int i = 0; i < size; i++) |
218 |
|
rgb[i] = (0xff000000 |
219 |
|
// red |
220 |
|
| ((cmap[3 * i + start] & 0xff) << 16) |
221 |
|
// green |
222 |
|
| ((cmap[3 * i + 1 + start] & 0xff) << 8) |
223 |
|
// blue |
224 |
|
| (cmap[3 * i + 2 + start] & 0xff)); |
225 |
|
} |
226 |
|
|
227 |
// Generate a bigint with 1's for every pixel |
// Generate a bigint with 1's for every pixel |
228 |
validBits = validBits.setBit(size).subtract(BigInteger.ONE); |
validBits = validBits.setBit(size).subtract(BigInteger.ONE); |
229 |
} |
} |
230 |
|
|
231 |
/** |
/** |
232 |
* Each array much contain <code>size</code> elements. For each |
* Construct an IndexColorModel from an array of <code>size</code> packed |
233 |
* array, the i-th color is described by reds[i], greens[i], |
* colors. Each int element contains 8-bit red, green, blue, and optional |
234 |
* blues[i], alphas[i], unless alphas is not specified, then all the |
* alpha values packed in order. If hasAlpha is false, then all the colors |
235 |
* colors are opaque except for the transparent color. |
* are opaque except for the transparent color. |
236 |
* |
* |
237 |
* @param bits the number of bits needed to represent <code>size</code> colors |
* @param bits the number of bits needed to represent <code>size</code> colors |
238 |
* @param size the number of colors in the color map |
* @param size the number of colors in the color map |
241 |
* @param hasAlpha <code>cmap</code> has alpha values |
* @param hasAlpha <code>cmap</code> has alpha values |
242 |
* @param trans the index of the transparent color |
* @param trans the index of the transparent color |
243 |
* @param transferType DataBuffer.TYPE_BYTE or DataBuffer.TYPE_USHORT |
* @param transferType DataBuffer.TYPE_BYTE or DataBuffer.TYPE_USHORT |
244 |
|
* @throws IllegalArgumentException if bits < 1, bits > 16, or size < 1. |
245 |
|
* @throws IllegalArgumentException if transferType is something other than |
246 |
|
* TYPE_BYTE or TYPE_USHORT. |
247 |
*/ |
*/ |
248 |
public IndexColorModel (int bits, int size, byte[] cmap, int start, |
public IndexColorModel (int bits, int size, int[] cmap, int start, |
249 |
boolean hasAlpha, int trans, int transferType) |
boolean hasAlpha, int trans, int transferType) |
250 |
{ |
{ |
251 |
super(bits * 4, // total bits, sRGB, four channels |
super(bits * 4, // total bits, sRGB, four channels |
257 |
if (transferType != DataBuffer.TYPE_BYTE |
if (transferType != DataBuffer.TYPE_BYTE |
258 |
&& transferType != DataBuffer.TYPE_USHORT) |
&& transferType != DataBuffer.TYPE_USHORT) |
259 |
throw new IllegalArgumentException(); |
throw new IllegalArgumentException(); |
260 |
|
if (bits > 16) |
261 |
|
throw new IllegalArgumentException("bits > 16"); |
262 |
|
if (size < 1) |
263 |
|
throw new IllegalArgumentException("size < 1"); |
264 |
map_size = size; |
map_size = size; |
265 |
opaque = !hasAlpha; |
opaque = !hasAlpha; |
266 |
this.trans = trans; |
this.trans = trans; |
267 |
|
|
268 |
|
rgb = new int[size]; |
269 |
|
if (!hasAlpha) |
270 |
|
for (int i = 0; i < size; i++) |
271 |
|
rgb[i] = cmap[i + start] | 0xff000000; |
272 |
|
else |
273 |
|
System.arraycopy(cmap, start, rgb, 0, size); |
274 |
|
|
275 |
// Generate a bigint with 1's for every pixel |
// Generate a bigint with 1's for every pixel |
276 |
validBits = validBits.setBit(size).subtract(BigInteger.ONE); |
validBits = validBits.setBit(size).subtract(BigInteger.ONE); |
277 |
} |
} |
293 |
* @param cmap packed color components |
* @param cmap packed color components |
294 |
* @param start the offset of the first color component in <code>cmap</code> |
* @param start the offset of the first color component in <code>cmap</code> |
295 |
* @param transferType DataBuffer.TYPE_BYTE or DataBuffer.TYPE_USHORT |
* @param transferType DataBuffer.TYPE_BYTE or DataBuffer.TYPE_USHORT |
296 |
|
* @throws IllegalArgumentException if bits < 1, bits > 16, or size < 1. |
297 |
|
* @throws IllegalArgumentException if transferType is something other than |
298 |
|
* TYPE_BYTE or TYPE_USHORT. |
299 |
*/ |
*/ |
300 |
public IndexColorModel (int bits, int size, int[] cmap, int start, |
public IndexColorModel (int bits, int size, int[] cmap, int start, |
301 |
int transferType, BigInteger validBits) |
int transferType, BigInteger validBits) |
309 |
if (transferType != DataBuffer.TYPE_BYTE |
if (transferType != DataBuffer.TYPE_BYTE |
310 |
&& transferType != DataBuffer.TYPE_USHORT) |
&& transferType != DataBuffer.TYPE_USHORT) |
311 |
throw new IllegalArgumentException(); |
throw new IllegalArgumentException(); |
312 |
|
if (bits > 16) |
313 |
|
throw new IllegalArgumentException("bits > 16"); |
314 |
|
if (size < 1) |
315 |
|
throw new IllegalArgumentException("size < 1"); |
316 |
map_size = size; |
map_size = size; |
317 |
opaque = false; |
opaque = false; |
318 |
this.trans = -1; |
this.trans = -1; |
319 |
this.validBits = validBits; |
this.validBits = validBits; |
320 |
|
|
321 |
|
rgb = new int[size]; |
322 |
|
if (!hasAlpha) |
323 |
|
for (int i = 0; i < size; i++) |
324 |
|
rgb[i] = cmap[i + start] | 0xff000000; |
325 |
|
else |
326 |
|
System.arraycopy(cmap, start, rgb, 0, size); |
327 |
} |
} |
328 |
|
|
329 |
public final int getMapSize () |
public final int getMapSize () |