PackedColorModelpublic abstract class PackedColorModel extends ColorModel The class PackedColorModel represents a color model where the components are
just the red, green, and blue bands, plus an alpha band if alpha is
supported. |
Fields Summary |
---|
int[] | componentMasksThe component masks. | int[] | offsetsThe offsets. | float[] | scalesThe scales. |
Constructors Summary |
---|
public PackedColorModel(ColorSpace space, int bits, int[] colorMaskArray, int alphaMask, boolean isAlphaPremultiplied, int trans, int transferType)Instantiates a new packed color model.
super(bits, createBits(colorMaskArray, alphaMask), space, (alphaMask == 0 ? false : true),
isAlphaPremultiplied, trans, validateTransferType(transferType));
if (pixel_bits < 1 || pixel_bits > 32) {
// awt.236=The bits is less than 1 or greater than 32
throw new IllegalArgumentException(Messages.getString("awt.236")); //$NON-NLS-1$
}
componentMasks = new int[numComponents];
for (int i = 0; i < numColorComponents; i++) {
componentMasks[i] = colorMaskArray[i];
}
if (hasAlpha) {
componentMasks[numColorComponents] = alphaMask;
if (this.bits[numColorComponents] == 1) {
transparency = Transparency.BITMASK;
}
}
parseComponents();
| public PackedColorModel(ColorSpace space, int bits, int rmask, int gmask, int bmask, int amask, boolean isAlphaPremultiplied, int trans, int transferType)Instantiates a new packed color model.
super(bits, createBits(rmask, gmask, bmask, amask), space, (amask == 0 ? false : true),
isAlphaPremultiplied, trans, validateTransferType(transferType));
if (pixel_bits < 1 || pixel_bits > 32) {
// awt.236=The bits is less than 1 or greater than 32
throw new IllegalArgumentException(Messages.getString("awt.236")); //$NON-NLS-1$
}
if (cs.getType() != ColorSpace.TYPE_RGB) {
// awt.239=The space is not a TYPE_RGB space
throw new IllegalArgumentException(Messages.getString("awt.239")); //$NON-NLS-1$
}
for (int i = 0; i < numColorComponents; i++) {
if (cs.getMinValue(i) != 0.0f || cs.getMaxValue(i) != 1.0f) {
// awt.23A=The min/max normalized component values are not
// 0.0/1.0
throw new IllegalArgumentException(Messages.getString("awt.23A")); //$NON-NLS-1$
}
}
componentMasks = new int[numComponents];
componentMasks[0] = rmask;
componentMasks[1] = gmask;
componentMasks[2] = bmask;
if (hasAlpha) {
componentMasks[3] = amask;
if (this.bits[3] == 1) {
transparency = Transparency.BITMASK;
}
}
parseComponents();
|
Methods Summary |
---|
private static int | countCompBits(int compMask)Count comp bits.
int bits = 0;
if (compMask != 0) {
// Deleting final zeros
while ((compMask & 1) == 0) {
compMask >>>= 1;
}
// Counting component bits
while ((compMask & 1) == 1) {
compMask >>>= 1;
bits++;
}
}
if (compMask != 0) {
return -1;
}
return bits;
| private static int[] | createBits(int rmask, int gmask, int bmask, int amask)Creates the bits.
int numComp;
if (amask == 0) {
numComp = 3;
} else {
numComp = 4;
}
int bits[] = new int[numComp];
bits[0] = countCompBits(rmask);
if (bits[0] < 0) {
// awt.23D=The mask of the red component is not contiguous
throw new IllegalArgumentException(Messages.getString("awt.23D")); //$NON-NLS-1$
}
bits[1] = countCompBits(gmask);
if (bits[1] < 0) {
// awt.23E=The mask of the green component is not contiguous
throw new IllegalArgumentException(Messages.getString("awt.23E")); //$NON-NLS-1$
}
bits[2] = countCompBits(bmask);
if (bits[2] < 0) {
// awt.23F=The mask of the blue component is not contiguous
throw new IllegalArgumentException(Messages.getString("awt.23F")); //$NON-NLS-1$
}
if (amask != 0) {
bits[3] = countCompBits(amask);
if (bits[3] < 0) {
// awt.23C=The mask of the alpha component is not contiguous
throw new IllegalArgumentException(Messages.getString("awt.23C")); //$NON-NLS-1$
}
}
return bits;
| private static int[] | createBits(int[] colorMaskArray, int alphaMask)Creates the bits.
int bits[];
int numComp;
if (alphaMask == 0) {
numComp = colorMaskArray.length;
} else {
numComp = colorMaskArray.length + 1;
}
bits = new int[numComp];
int i = 0;
for (; i < colorMaskArray.length; i++) {
bits[i] = countCompBits(colorMaskArray[i]);
if (bits[i] < 0) {
// awt.23B=The mask of the {0} component is not contiguous
throw new IllegalArgumentException(Messages.getString("awt.23B", i)); //$NON-NLS-1$
}
}
if (i < numComp) {
bits[i] = countCompBits(alphaMask);
if (bits[i] < 0) {
// awt.23C=The mask of the alpha component is not contiguous
throw new IllegalArgumentException(Messages.getString("awt.23C")); //$NON-NLS-1$
}
}
return bits;
| public java.awt.image.SampleModel | createCompatibleSampleModel(int w, int h)
return new SinglePixelPackedSampleModel(transferType, w, h, componentMasks);
| public boolean | equals(java.lang.Object obj)
if (obj == null) {
return false;
}
if (!(obj instanceof PackedColorModel)) {
return false;
}
PackedColorModel cm = (PackedColorModel)obj;
return (pixel_bits == cm.getPixelSize() && transferType == cm.getTransferType()
&& cs.getType() == cm.getColorSpace().getType() && hasAlpha == cm.hasAlpha()
&& isAlphaPremultiplied == cm.isAlphaPremultiplied()
&& transparency == cm.getTransparency()
&& numColorComponents == cm.getNumColorComponents()
&& numComponents == cm.getNumComponents()
&& Arrays.equals(bits, cm.getComponentSize()) && Arrays.equals(componentMasks, cm
.getMasks()));
| public java.awt.image.WritableRaster | getAlphaRaster(java.awt.image.WritableRaster raster)
if (!hasAlpha) {
return null;
}
int x = raster.getMinX();
int y = raster.getMinY();
int w = raster.getWidth();
int h = raster.getHeight();
int band[] = new int[1];
band[0] = raster.getNumBands() - 1;
return raster.createWritableChild(x, y, w, h, x, y, band);
| public final int | getMask(int index)Gets the bitmask corresponding to the specified color component.
return componentMasks[index];
| public final int[] | getMasks()Gets the bitmasks of the components.
return (componentMasks.clone());
| public boolean | isCompatibleSampleModel(java.awt.image.SampleModel sm)
if (sm == null) {
return false;
}
if (!(sm instanceof SinglePixelPackedSampleModel)) {
return false;
}
SinglePixelPackedSampleModel esm = (SinglePixelPackedSampleModel)sm;
return ((esm.getNumBands() == numComponents) && (esm.getTransferType() == transferType) && Arrays
.equals(esm.getBitMasks(), componentMasks));
| private void | parseComponents()Parses the components.
offsets = new int[numComponents];
scales = new float[numComponents];
for (int i = 0; i < numComponents; i++) {
int off = 0;
int mask = componentMasks[i];
while ((mask & 1) == 0) {
mask >>>= 1;
off++;
}
offsets[i] = off;
if (bits[i] == 0) {
scales[i] = 256.0f; // May be any value different from zero,
// because will dividing by zero
} else {
scales[i] = 255.0f / maxValues[i];
}
}
| private static int | validateTransferType(int transferType)Validate transfer type.
if (transferType != DataBuffer.TYPE_BYTE && transferType != DataBuffer.TYPE_USHORT
&& transferType != DataBuffer.TYPE_INT) {
// awt.240=The transferType not is one of DataBuffer.TYPE_BYTE,
// DataBuffer.TYPE_USHORT or DataBuffer.TYPE_INT
throw new IllegalArgumentException(Messages.getString("awt.240")); //$NON-NLS-1$
}
return transferType;
|
|