< prev index next >
src/java.desktop/share/classes/java/awt/image/IndexColorModel.java
Print this page
*** 1,7 ****
/*
! * Copyright (c) 1995, 2017, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
--- 1,7 ----
/*
! * Copyright (c) 1995, 2018, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
*** 122,132 ****
* @see ColorSpace
* @see DataBuffer
*
*/
public class IndexColorModel extends ColorModel {
! private int rgb[];
private int map_size;
private int pixel_mask;
private int transparent_index = -1;
private boolean allgrayopaque;
private BigInteger validBits;
--- 122,132 ----
* @see ColorSpace
* @see DataBuffer
*
*/
public class IndexColorModel extends ColorModel {
! private int[] rgb;
private int map_size;
private int pixel_mask;
private int transparent_index = -1;
private boolean allgrayopaque;
private BigInteger validBits;
*** 164,174 ****
* than 1 or greater than 16
* @throws IllegalArgumentException if {@code size} is less
* than 1
*/
public IndexColorModel(int bits, int size,
! byte r[], byte g[], byte b[]) {
super(bits, opaqueBits,
ColorSpace.getInstance(ColorSpace.CS_sRGB),
false, false, OPAQUE,
ColorModel.getDefaultTransferType(bits));
if (bits < 1 || bits > 16) {
--- 164,174 ----
* than 1 or greater than 16
* @throws IllegalArgumentException if {@code size} is less
* than 1
*/
public IndexColorModel(int bits, int size,
! byte[] r, byte[] g, byte[] b) {
super(bits, opaqueBits,
ColorSpace.getInstance(ColorSpace.CS_sRGB),
false, false, OPAQUE,
ColorModel.getDefaultTransferType(bits));
if (bits < 1 || bits > 16) {
*** 204,214 ****
* 1 or greater than 16
* @throws IllegalArgumentException if {@code size} is less than
* 1
*/
public IndexColorModel(int bits, int size,
! byte r[], byte g[], byte b[], int trans) {
super(bits, opaqueBits,
ColorSpace.getInstance(ColorSpace.CS_sRGB),
false, false, OPAQUE,
ColorModel.getDefaultTransferType(bits));
if (bits < 1 || bits > 16) {
--- 204,214 ----
* 1 or greater than 16
* @throws IllegalArgumentException if {@code size} is less than
* 1
*/
public IndexColorModel(int bits, int size,
! byte[] r, byte[] g, byte[] b, int trans) {
super(bits, opaqueBits,
ColorSpace.getInstance(ColorSpace.CS_sRGB),
false, false, OPAQUE,
ColorModel.getDefaultTransferType(bits));
if (bits < 1 || bits > 16) {
*** 243,253 ****
* than 1 or greater than 16
* @throws IllegalArgumentException if {@code size} is less
* than 1
*/
public IndexColorModel(int bits, int size,
! byte r[], byte g[], byte b[], byte a[]) {
super (bits, alphaBits,
ColorSpace.getInstance(ColorSpace.CS_sRGB),
true, false, TRANSLUCENT,
ColorModel.getDefaultTransferType(bits));
if (bits < 1 || bits > 16) {
--- 243,253 ----
* than 1 or greater than 16
* @throws IllegalArgumentException if {@code size} is less
* than 1
*/
public IndexColorModel(int bits, int size,
! byte[] r, byte[] g, byte[] b, byte[] a) {
super (bits, alphaBits,
ColorSpace.getInstance(ColorSpace.CS_sRGB),
true, false, TRANSLUCENT,
ColorModel.getDefaultTransferType(bits));
if (bits < 1 || bits > 16) {
*** 282,292 ****
* @throws IllegalArgumentException if {@code bits} is less
* than 1 or greater than 16
* @throws IllegalArgumentException if {@code size} is less
* than 1
*/
! public IndexColorModel(int bits, int size, byte cmap[], int start,
boolean hasalpha) {
this(bits, size, cmap, start, hasalpha, -1);
if (bits < 1 || bits > 16) {
throw new IllegalArgumentException("Number of bits must be between"
+" 1 and 16.");
--- 282,292 ----
* @throws IllegalArgumentException if {@code bits} is less
* than 1 or greater than 16
* @throws IllegalArgumentException if {@code size} is less
* than 1
*/
! public IndexColorModel(int bits, int size, byte[] cmap, int start,
boolean hasalpha) {
this(bits, size, cmap, start, hasalpha, -1);
if (bits < 1 || bits > 16) {
throw new IllegalArgumentException("Number of bits must be between"
+" 1 and 16.");
*** 319,329 ****
* @throws IllegalArgumentException if {@code bits} is less than
* 1 or greater than 16
* @throws IllegalArgumentException if {@code size} is less than
* 1
*/
! public IndexColorModel(int bits, int size, byte cmap[], int start,
boolean hasalpha, int trans) {
// REMIND: This assumes the ordering: RGB[A]
super(bits, opaqueBits,
ColorSpace.getInstance(ColorSpace.CS_sRGB),
false, false, OPAQUE,
--- 319,329 ----
* @throws IllegalArgumentException if {@code bits} is less than
* 1 or greater than 16
* @throws IllegalArgumentException if {@code size} is less than
* 1
*/
! public IndexColorModel(int bits, int size, byte[] cmap, int start,
boolean hasalpha, int trans) {
// REMIND: This assumes the ordering: RGB[A]
super(bits, opaqueBits,
ColorSpace.getInstance(ColorSpace.CS_sRGB),
false, false, OPAQUE,
*** 404,414 ****
* @throws IllegalArgumentException if {@code transferType} is not
* one of {@code DataBuffer.TYPE_BYTE} or
* {@code DataBuffer.TYPE_USHORT}
*/
public IndexColorModel(int bits, int size,
! int cmap[], int start,
boolean hasalpha, int trans, int transferType) {
// REMIND: This assumes the ordering: RGB[A]
super(bits, opaqueBits,
ColorSpace.getInstance(ColorSpace.CS_sRGB),
false, false, OPAQUE,
--- 404,414 ----
* @throws IllegalArgumentException if {@code transferType} is not
* one of {@code DataBuffer.TYPE_BYTE} or
* {@code DataBuffer.TYPE_USHORT}
*/
public IndexColorModel(int bits, int size,
! int[] cmap, int start,
boolean hasalpha, int trans, int transferType) {
// REMIND: This assumes the ordering: RGB[A]
super(bits, opaqueBits,
ColorSpace.getInstance(ColorSpace.CS_sRGB),
false, false, OPAQUE,
*** 470,480 ****
* one of {@code DataBuffer.TYPE_BYTE} or
* {@code DataBuffer.TYPE_USHORT}
*
* @since 1.3
*/
! public IndexColorModel(int bits, int size, int cmap[], int start,
int transferType, BigInteger validBits) {
super (bits, alphaBits,
ColorSpace.getInstance(ColorSpace.CS_sRGB),
true, false, TRANSLUCENT,
transferType);
--- 470,480 ----
* one of {@code DataBuffer.TYPE_BYTE} or
* {@code DataBuffer.TYPE_USHORT}
*
* @since 1.3
*/
! public IndexColorModel(int bits, int size, int[] cmap, int start,
int transferType, BigInteger validBits) {
super (bits, alphaBits,
ColorSpace.getInstance(ColorSpace.CS_sRGB),
true, false, TRANSLUCENT,
transferType);
*** 505,515 ****
setRGBs(size, cmap, start, true);
calculatePixelMask();
}
! private void setRGBs(int size, byte r[], byte g[], byte b[], byte a[]) {
if (size < 1) {
throw new IllegalArgumentException("Map size ("+size+
") must be >= 1");
}
map_size = size;
--- 505,515 ----
setRGBs(size, cmap, start, true);
calculatePixelMask();
}
! private void setRGBs(int size, byte[] r, byte[] g, byte[] b, byte[] a) {
if (size < 1) {
throw new IllegalArgumentException("Map size ("+size+
") must be >= 1");
}
map_size = size;
*** 542,552 ****
}
this.allgrayopaque = allgray;
setTransparency(transparency);
}
! private void setRGBs(int size, int cmap[], int start, boolean hasalpha) {
map_size = size;
rgb = new int[calcRealMapSize(pixel_bits, size)];
int j = start;
int transparency = OPAQUE;
boolean allgray = true;
--- 542,552 ----
}
this.allgrayopaque = allgray;
setTransparency(transparency);
}
! private void setRGBs(int size, int[] cmap, int start, boolean hasalpha) {
map_size = size;
rgb = new int[calcRealMapSize(pixel_bits, size)];
int j = start;
int transparency = OPAQUE;
boolean allgray = true;
*** 661,671 ****
* Only the initial entries of the array as specified by
* {@link #getMapSize() getMapSize} are written.
* @param r the specified array into which the elements of the
* array of red color components are copied
*/
! public final void getReds(byte r[]) {
for (int i = 0; i < map_size; i++) {
r[i] = (byte) (rgb[i] >> 16);
}
}
--- 661,671 ----
* Only the initial entries of the array as specified by
* {@link #getMapSize() getMapSize} are written.
* @param r the specified array into which the elements of the
* array of red color components are copied
*/
! public final void getReds(byte[] r) {
for (int i = 0; i < map_size; i++) {
r[i] = (byte) (rgb[i] >> 16);
}
}
*** 674,684 ****
* Only the initial entries of the array as specified by
* {@code getMapSize} are written.
* @param g the specified array into which the elements of the
* array of green color components are copied
*/
! public final void getGreens(byte g[]) {
for (int i = 0; i < map_size; i++) {
g[i] = (byte) (rgb[i] >> 8);
}
}
--- 674,684 ----
* Only the initial entries of the array as specified by
* {@code getMapSize} are written.
* @param g the specified array into which the elements of the
* array of green color components are copied
*/
! public final void getGreens(byte[] g) {
for (int i = 0; i < map_size; i++) {
g[i] = (byte) (rgb[i] >> 8);
}
}
*** 687,697 ****
* Only the initial entries of the array as specified by
* {@code getMapSize} are written.
* @param b the specified array into which the elements of the
* array of blue color components are copied
*/
! public final void getBlues(byte b[]) {
for (int i = 0; i < map_size; i++) {
b[i] = (byte) rgb[i];
}
}
--- 687,697 ----
* Only the initial entries of the array as specified by
* {@code getMapSize} are written.
* @param b the specified array into which the elements of the
* array of blue color components are copied
*/
! public final void getBlues(byte[] b) {
for (int i = 0; i < map_size; i++) {
b[i] = (byte) rgb[i];
}
}
*** 700,710 ****
* specified array. Only the initial entries of the array as specified
* by {@code getMapSize} are written.
* @param a the specified array into which the elements of the
* array of alpha components are copied
*/
! public final void getAlphas(byte a[]) {
for (int i = 0; i < map_size; i++) {
a[i] = (byte) (rgb[i] >> 24);
}
}
--- 700,710 ----
* specified array. Only the initial entries of the array as specified
* by {@code getMapSize} are written.
* @param a the specified array into which the elements of the
* array of alpha components are copied
*/
! public final void getAlphas(byte[] a) {
for (int i = 0; i < map_size; i++) {
a[i] = (byte) (rgb[i] >> 24);
}
}
*** 717,727 ****
* written.
* @param rgb the specified array into which the converted ARGB
* values from this array of color and alpha components
* are copied.
*/
! public final void getRGBs(int rgb[]) {
System.arraycopy(this.rgb, 0, rgb, 0, map_size);
}
private void setTransparentPixel(int trans) {
if (trans >= 0 && trans < map_size) {
--- 717,727 ----
* written.
* @param rgb the specified array into which the converted ARGB
* values from this array of color and alpha components
* are copied.
*/
! public final void getRGBs(int[] rgb) {
System.arraycopy(this.rgb, 0, rgb, 0, map_size);
}
private void setTransparentPixel(int trans) {
if (trans >= 0 && trans < map_size) {
*** 839,849 ****
public final int getRGB(int pixel) {
return rgb[pixel & pixel_mask];
}
private static final int CACHESIZE = 40;
! private int lookupcache[] = new int[CACHESIZE];
/**
* Returns a data element array representation of a pixel in this
* ColorModel, given an integer pixel representation in the
* default RGB color model. This array can then be passed to the
--- 839,849 ----
public final int getRGB(int pixel) {
return rgb[pixel & pixel_mask];
}
private static final int CACHESIZE = 40;
! private int[] lookupcache = new int[CACHESIZE];
/**
* Returns a data element array representation of a pixel in this
* ColorModel, given an integer pixel representation in the
* default RGB color model. This array can then be passed to the
*** 943,953 ****
// likely to be fairly common in opaque colormaps
// so first we will do a quick search for an
// exact match.
int smallestError = Integer.MAX_VALUE;
! int lut[] = this.rgb;
int lutrgb;
for (int i=0; i < map_size; i++) {
lutrgb = lut[i];
if (lutrgb == rgb && lutrgb != 0) {
pix = i;
--- 943,953 ----
// likely to be fairly common in opaque colormaps
// so first we will do a quick search for an
// exact match.
int smallestError = Integer.MAX_VALUE;
! int[] lut = this.rgb;
int lutrgb;
for (int i=0; i < map_size; i++) {
lutrgb = lut[i];
if (lutrgb == rgb && lutrgb != 0) {
pix = i;
*** 990,1000 ****
// color components in the distance calculations.
// Look for closest match using a 4 component
// Euclidean distance formula.
int smallestError = Integer.MAX_VALUE;
! int lut[] = this.rgb;
for (int i=0; i < map_size; i++) {
int lutrgb = lut[i];
if (lutrgb == rgb) {
if (validBits != null && !validBits.testBit(i)) {
continue;
--- 990,1000 ----
// color components in the distance calculations.
// Look for closest match using a 4 component
// Euclidean distance formula.
int smallestError = Integer.MAX_VALUE;
! int[] lut = this.rgb;
for (int i=0; i < map_size; i++) {
int lutrgb = lut[i];
if (lutrgb == rgb) {
if (validBits != null && !validBits.testBit(i)) {
continue;
*** 1160,1178 ****
*/
public int[] getComponents(Object pixel, int[] components, int offset) {
int intpixel;
switch (transferType) {
case DataBuffer.TYPE_BYTE:
! byte bdata[] = (byte[])pixel;
intpixel = bdata[0] & 0xff;
break;
case DataBuffer.TYPE_USHORT:
! short sdata[] = (short[])pixel;
intpixel = sdata[0] & 0xffff;
break;
case DataBuffer.TYPE_INT:
! int idata[] = (int[])pixel;
intpixel = idata[0];
break;
default:
throw new UnsupportedOperationException("This method has not been "+
"implemented for transferType " + transferType);
--- 1160,1178 ----
*/
public int[] getComponents(Object pixel, int[] components, int offset) {
int intpixel;
switch (transferType) {
case DataBuffer.TYPE_BYTE:
! byte[] bdata = (byte[])pixel;
intpixel = bdata[0] & 0xff;
break;
case DataBuffer.TYPE_USHORT:
! short[] sdata = (short[])pixel;
intpixel = sdata[0] & 0xffff;
break;
case DataBuffer.TYPE_INT:
! int[] idata = (int[])pixel;
intpixel = idata[0];
break;
default:
throw new UnsupportedOperationException("This method has not been "+
"implemented for transferType " + transferType);
*** 1215,1233 ****
}
Object inData = getDataElements(rgb, null);
int pixel;
switch (transferType) {
case DataBuffer.TYPE_BYTE:
! byte bdata[] = (byte[])inData;
pixel = bdata[0] & 0xff;
break;
case DataBuffer.TYPE_USHORT:
! short sdata[] = (short[])inData;
pixel = sdata[0];
break;
case DataBuffer.TYPE_INT:
! int idata[] = (int[])inData;
pixel = idata[0];
break;
default:
throw new UnsupportedOperationException("This method has not been "+
"implemented for transferType " + transferType);
--- 1215,1233 ----
}
Object inData = getDataElements(rgb, null);
int pixel;
switch (transferType) {
case DataBuffer.TYPE_BYTE:
! byte[] bdata = (byte[])inData;
pixel = bdata[0] & 0xff;
break;
case DataBuffer.TYPE_USHORT:
! short[] sdata = (short[])inData;
pixel = sdata[0];
break;
case DataBuffer.TYPE_INT:
! int[] idata = (int[])inData;
pixel = idata[0];
break;
default:
throw new UnsupportedOperationException("This method has not been "+
"implemented for transferType " + transferType);
< prev index next >