下面列出了java.awt.Transparency#BITMASK 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
@Override
public ColorModel getColorModel(int transparency) {
switch (transparency) {
case Transparency.OPAQUE:
// REMIND: once the ColorModel spec is changed, this should be
// an opaque premultiplied DCM...
return new DirectColorModel(24, 0xff0000, 0xff00, 0xff);
case Transparency.BITMASK:
return new DirectColorModel(25, 0xff0000, 0xff00, 0xff, 0x1000000);
case Transparency.TRANSLUCENT:
ColorSpace cs = ColorSpace.getInstance(ColorSpace.CS_sRGB);
return new DirectColorModel(cs, 32,
0xff0000, 0xff00, 0xff, 0xff000000,
true, DataBuffer.TYPE_INT);
default:
return null;
}
}
@Override
public ColorModel getColorModel(int transparency) {
switch (transparency) {
case Transparency.OPAQUE:
// REMIND: once the ColorModel spec is changed, this should be
// an opaque premultiplied DCM...
return new DirectColorModel(24, 0xff0000, 0xff00, 0xff);
case Transparency.BITMASK:
return new DirectColorModel(25, 0xff0000, 0xff00, 0xff, 0x1000000);
case Transparency.TRANSLUCENT:
ColorSpace cs = ColorSpace.getInstance(ColorSpace.CS_sRGB);
return new DirectColorModel(cs, 32,
0xff0000, 0xff00, 0xff, 0xff000000,
true, DataBuffer.TYPE_INT);
default:
return null;
}
}
@Override
public ColorModel getColorModel(int transparency) {
switch (transparency) {
case Transparency.OPAQUE:
// REMIND: once the ColorModel spec is changed, this should be
// an opaque premultiplied DCM...
return new DirectColorModel(24, 0xff0000, 0xff00, 0xff);
case Transparency.BITMASK:
return new DirectColorModel(25, 0xff0000, 0xff00, 0xff, 0x1000000);
case Transparency.TRANSLUCENT:
ColorSpace cs = ColorSpace.getInstance(ColorSpace.CS_sRGB);
return new DirectColorModel(cs, 32,
0xff0000, 0xff00, 0xff, 0xff000000,
true, DataBuffer.TYPE_INT);
default:
return null;
}
}
@Override
public ColorModel getColorModel(int transparency) {
switch (transparency) {
case Transparency.OPAQUE:
// REMIND: once the ColorModel spec is changed, this should be
// an opaque premultiplied DCM...
return new DirectColorModel(24, 0xff0000, 0xff00, 0xff);
case Transparency.BITMASK:
return new DirectColorModel(25, 0xff0000, 0xff00, 0xff, 0x1000000);
case Transparency.TRANSLUCENT:
ColorSpace cs = ColorSpace.getInstance(ColorSpace.CS_sRGB);
return new DirectColorModel(cs, 32,
0xff0000, 0xff00, 0xff, 0xff000000,
true, DataBuffer.TYPE_INT);
default:
return null;
}
}
public TriStateImageType(Group parent, String nodename, String desc,
int transparency)
{
super(parent, nodename, desc);
setHorizontal();
new DrawableImage(this, Transparency.OPAQUE, true);
new DrawableImage(this, Transparency.BITMASK,
(transparency != Transparency.OPAQUE));
new DrawableImage(this, Transparency.TRANSLUCENT,
(transparency == Transparency.TRANSLUCENT));
}
/**
* {@inheritDoc}
*
* @see sun.java2d.pipe.hw.AccelGraphicsConfig#createCompatibleVolatileImage
*/
@Override
public VolatileImage
createCompatibleVolatileImage(int width, int height,
int transparency, int type)
{
if (type == FLIP_BACKBUFFER || type == WINDOW || type == UNDEFINED ||
transparency == Transparency.BITMASK)
{
return null;
}
if (type == FBOBJECT) {
if (!isCapPresent(CAPS_EXT_FBOBJECT)) {
return null;
}
} else if (type == PBUFFER) {
boolean isOpaque = transparency == Transparency.OPAQUE;
if (!isOpaque && !isCapPresent(CAPS_STORED_ALPHA)) {
return null;
}
}
SunVolatileImage vi = new AccelTypedVolatileImage(this, width, height,
transparency, type);
Surface sd = vi.getDestSurface();
if (!(sd instanceof AccelSurface) ||
((AccelSurface)sd).getType() != type)
{
vi.flush();
vi = null;
}
return vi;
}
public TriStateImageType(Group parent, String nodename, String desc,
int transparency)
{
super(parent, nodename, desc);
setHorizontal();
new DrawableImage(this, Transparency.OPAQUE, true);
new DrawableImage(this, Transparency.BITMASK,
(transparency != Transparency.OPAQUE));
new DrawableImage(this, Transparency.TRANSLUCENT,
(transparency == Transparency.TRANSLUCENT));
}
/**
* Returns the color model associated with this configuration that
* supports the specified transparency.
*/
public ColorModel getColorModel(int transparency) {
switch (transparency) {
case Transparency.OPAQUE:
return getColorModel();
case Transparency.BITMASK:
return new DirectColorModel(25, 0xff0000, 0xff00, 0xff, 0x1000000);
case Transparency.TRANSLUCENT:
return ColorModel.getRGBdefault();
default:
return null;
}
}
@Override
public VolatileImage createCompatibleVolatileImage(int width, int height,
int transparency,
int type) {
if (type == FLIP_BACKBUFFER || type == WINDOW || type == UNDEFINED ||
transparency == Transparency.BITMASK)
{
return null;
}
if (type == FBOBJECT) {
if (!isCapPresent(CAPS_EXT_FBOBJECT)) {
return null;
}
} else if (type == PBUFFER) {
boolean isOpaque = transparency == Transparency.OPAQUE;
if (!isOpaque && !isCapPresent(CAPS_STORED_ALPHA)) {
return null;
}
}
SunVolatileImage vi = new AccelTypedVolatileImage(this, width, height,
transparency, type);
Surface sd = vi.getDestSurface();
if (!(sd instanceof AccelSurface) ||
((AccelSurface)sd).getType() != type)
{
vi.flush();
vi = null;
}
return vi;
}
@Override
public VolatileImage createCompatibleVolatileImage(int width, int height,
int transparency,
int type) {
if (type == FLIP_BACKBUFFER || type == WINDOW || type == UNDEFINED ||
transparency == Transparency.BITMASK)
{
return null;
}
if (type == FBOBJECT) {
if (!isCapPresent(CAPS_EXT_FBOBJECT)) {
return null;
}
} else if (type == PBUFFER) {
boolean isOpaque = transparency == Transparency.OPAQUE;
if (!isOpaque && !isCapPresent(CAPS_STORED_ALPHA)) {
return null;
}
}
SunVolatileImage vi = new AccelTypedVolatileImage(this, width, height,
transparency, type);
Surface sd = vi.getDestSurface();
if (!(sd instanceof AccelSurface) ||
((AccelSurface)sd).getType() != type)
{
vi.flush();
vi = null;
}
return vi;
}
/**
* {@inheritDoc}
*
* @see sun.java2d.pipe.hw.AccelGraphicsConfig#createCompatibleVolatileImage
*/
@Override
public VolatileImage
createCompatibleVolatileImage(int width, int height,
int transparency, int type)
{
if (type == FLIP_BACKBUFFER || type == WINDOW || type == UNDEFINED ||
transparency == Transparency.BITMASK)
{
return null;
}
boolean isOpaque = transparency == Transparency.OPAQUE;
if (type == RT_TEXTURE) {
int cap = isOpaque ? CAPS_RT_TEXTURE_OPAQUE : CAPS_RT_TEXTURE_ALPHA;
if (!device.isCapPresent(cap)) {
return null;
}
} else if (type == RT_PLAIN) {
if (!isOpaque && !device.isCapPresent(CAPS_RT_PLAIN_ALPHA)) {
return null;
}
}
SunVolatileImage vi = new AccelTypedVolatileImage(this, width, height,
transparency, type);
Surface sd = vi.getDestSurface();
if (!(sd instanceof AccelSurface) ||
((AccelSurface)sd).getType() != type)
{
vi.flush();
vi = null;
}
return vi;
}
/**
* {@inheritDoc}
*
* @see sun.java2d.pipe.hw.AccelGraphicsConfig#createCompatibleVolatileImage
*/
@Override
public VolatileImage
createCompatibleVolatileImage(int width, int height,
int transparency, int type)
{
if (type == FLIP_BACKBUFFER || type == WINDOW || type == UNDEFINED ||
transparency == Transparency.BITMASK)
{
return null;
}
if (type == FBOBJECT) {
if (!isCapPresent(CAPS_EXT_FBOBJECT)) {
return null;
}
} else if (type == PBUFFER) {
boolean isOpaque = transparency == Transparency.OPAQUE;
if (!isOpaque && !isCapPresent(CAPS_STORED_ALPHA)) {
return null;
}
}
SunVolatileImage vi = new AccelTypedVolatileImage(this, width, height,
transparency, type);
Surface sd = vi.getDestSurface();
if (!(sd instanceof AccelSurface) ||
((AccelSurface)sd).getType() != type)
{
vi.flush();
vi = null;
}
return vi;
}
/**
* Returns the color model associated with this configuration that
* supports the specified transparency.
*/
public ColorModel getColorModel(int transparency) {
switch (transparency) {
case Transparency.OPAQUE:
return getColorModel();
case Transparency.BITMASK:
return new DirectColorModel(25, 0xff0000, 0xff00, 0xff, 0x1000000);
case Transparency.TRANSLUCENT:
return ColorModel.getRGBdefault();
default:
return null;
}
}
public BmByteIndexBufImg() {
super(bufimgsrcroot,
"ByteIndexedBm",
"8-bit Transparent Indexed Image",
Transparency.BITMASK);
}
public int getTransparency() {
return Transparency.BITMASK;
}
public static SurfaceDataProxy createProxy(SurfaceData srcData,
X11GraphicsConfig dstConfig)
{
if (srcData instanceof X11SurfaceData) {
// srcData must be a VolatileImage which either matches
// our visual or not - either way we do not cache it...
return UNCACHED;
}
ColorModel cm = srcData.getColorModel();
int transparency = cm.getTransparency();
if (transparency == Transparency.OPAQUE) {
return new Opaque(dstConfig);
} else if (transparency == Transparency.BITMASK) {
// 4673490: updateBitmask() only handles ICMs with 8-bit indices
if ((cm instanceof IndexColorModel) && cm.getPixelSize() == 8) {
return new Bitmask(dstConfig);
}
// The only other ColorModel handled by updateBitmask() is
// a DCM where the alpha bit, and only the alpha bit, is in
// the top 8 bits
if (cm instanceof DirectColorModel) {
DirectColorModel dcm = (DirectColorModel) cm;
int colormask = (dcm.getRedMask() |
dcm.getGreenMask() |
dcm.getBlueMask());
int alphamask = dcm.getAlphaMask();
if ((colormask & 0xff000000) == 0 &&
(alphamask & 0xff000000) != 0)
{
return new Bitmask(dstConfig);
}
}
}
// For whatever reason, this image is not a good candidate for
// caching in a pixmap so we return the non-caching (non-)proxy.
return UNCACHED;
}
public BmByteIndexBufImg() {
super(bufimgsrcroot,
"ByteIndexedBm",
"8-bit Transparent Indexed Image",
Transparency.BITMASK);
}
public static SurfaceType getSurfaceType(X11GraphicsConfig gc,
int transparency,
boolean pixmapSurface)
{
boolean transparent = (transparency == Transparency.BITMASK);
SurfaceType sType;
ColorModel cm = gc.getColorModel();
switch (cm.getPixelSize()) {
case 24:
if (gc.getBitsPerPixel() == 24) {
if (cm instanceof DirectColorModel) {
// 4517321: We will always use ThreeByteBgr for 24 bpp
// surfaces, regardless of the pixel masks reported by
// X11. Despite ambiguity in the X11 spec in how 24 bpp
// surfaces are treated, it appears that the best
// SurfaceType for these configurations (including
// some Matrox Millenium and ATI Radeon boards) is
// ThreeByteBgr.
sType = transparent ? X11SurfaceData.ThreeByteBgrX11_BM : X11SurfaceData.ThreeByteBgrX11;
} else {
throw new sun.java2d.InvalidPipeException("Unsupported bit " +
"depth/cm combo: " +
cm.getPixelSize() +
", " + cm);
}
break;
}
// Fall through for 32 bit case
case 32:
if (cm instanceof DirectColorModel) {
if (((SunToolkit)java.awt.Toolkit.getDefaultToolkit()
).isTranslucencyCapable(gc) && !pixmapSurface)
{
sType = X11SurfaceData.IntArgbPreX11;
} else {
if (((DirectColorModel)cm).getRedMask() == 0xff0000) {
sType = transparent ? X11SurfaceData.IntRgbX11_BM :
X11SurfaceData.IntRgbX11;
} else {
sType = transparent ? X11SurfaceData.IntBgrX11_BM :
X11SurfaceData.IntBgrX11;
}
}
} else if (cm instanceof ComponentColorModel) {
sType = X11SurfaceData.FourByteAbgrPreX11;
} else {
throw new sun.java2d.InvalidPipeException("Unsupported bit " +
"depth/cm combo: " +
cm.getPixelSize() +
", " + cm);
}
break;
case 15:
sType = transparent ? X11SurfaceData.UShort555RgbX11_BM : X11SurfaceData.UShort555RgbX11;
break;
case 16:
if ((cm instanceof DirectColorModel) &&
(((DirectColorModel)cm).getGreenMask() == 0x3e0))
{
// fix for 4352984: Riva128 on Linux
sType = transparent ? X11SurfaceData.UShort555RgbX11_BM : X11SurfaceData.UShort555RgbX11;
} else {
sType = transparent ? X11SurfaceData.UShort565RgbX11_BM : X11SurfaceData.UShort565RgbX11;
}
break;
case 12:
if (cm instanceof IndexColorModel) {
sType = transparent ?
X11SurfaceData.UShortIndexedX11_BM :
X11SurfaceData.UShortIndexedX11;
} else {
throw new sun.java2d.InvalidPipeException("Unsupported bit " +
"depth: " +
cm.getPixelSize() +
" cm="+cm);
}
break;
case 8:
if (cm.getColorSpace().getType() == ColorSpace.TYPE_GRAY &&
cm instanceof ComponentColorModel) {
sType = transparent ? X11SurfaceData.ByteGrayX11_BM : X11SurfaceData.ByteGrayX11;
} else if (cm instanceof IndexColorModel &&
isOpaqueGray((IndexColorModel)cm)) {
sType = transparent ? X11SurfaceData.Index8GrayX11_BM : X11SurfaceData.Index8GrayX11;
} else {
sType = transparent ? X11SurfaceData.ByteIndexedX11_BM : X11SurfaceData.ByteIndexedOpaqueX11;
}
break;
default:
throw new sun.java2d.InvalidPipeException("Unsupported bit " +
"depth: " +
cm.getPixelSize());
}
return sType;
}
/**
* Constructs a <code>PackedColorModel</code> from a color mask array,
* which specifies which bits in an <code>int</code> pixel representation
* contain each of the color samples, and an alpha mask. Color
* components are in the specified <code>ColorSpace</code>. The length of
* <code>colorMaskArray</code> should be the number of components in
* the <code>ColorSpace</code>. All of the bits in each mask
* must be contiguous and fit in the specified number of least significant
* bits of an <code>int</code> pixel representation. If the
* <code>alphaMask</code> is 0, there is no alpha. If there is alpha,
* the <code>boolean</code> <code>isAlphaPremultiplied</code> specifies
* how to interpret color and alpha samples in pixel values. If the
* <code>boolean</code> is <code>true</code>, color samples are assumed
* to have been multiplied by the alpha sample. The transparency,
* <code>trans</code>, specifies what alpha values can be represented
* by this color model. The transfer type is the type of primitive
* array used to represent pixel values.
* @param space the specified <code>ColorSpace</code>
* @param bits the number of bits in the pixel values
* @param colorMaskArray array that specifies the masks representing
* the bits of the pixel values that represent the color
* components
* @param alphaMask specifies the mask representing
* the bits of the pixel values that represent the alpha
* component
* @param isAlphaPremultiplied <code>true</code> if color samples are
* premultiplied by the alpha sample; <code>false</code> otherwise
* @param trans specifies the alpha value that can be represented by
* this color model
* @param transferType the type of array used to represent pixel values
* @throws IllegalArgumentException if <code>bits</code> is less than
* 1 or greater than 32
*/
public PackedColorModel (ColorSpace space, int bits,
int[] colorMaskArray, int alphaMask,
boolean isAlphaPremultiplied,
int trans, int transferType) {
super(bits, PackedColorModel.createBitsArray(colorMaskArray,
alphaMask),
space, (alphaMask == 0 ? false : true),
isAlphaPremultiplied, trans, transferType);
if (bits < 1 || bits > 32) {
throw new IllegalArgumentException("Number of bits must be between"
+" 1 and 32.");
}
maskArray = new int[numComponents];
maskOffsets = new int[numComponents];
scaleFactors = new float[numComponents];
for (int i=0; i < numColorComponents; i++) {
// Get the mask offset and #bits
DecomposeMask(colorMaskArray[i], i, space.getName(i));
}
if (alphaMask != 0) {
DecomposeMask(alphaMask, numColorComponents, "alpha");
if (nBits[numComponents-1] == 1) {
transparency = Transparency.BITMASK;
}
}
}
/**
* Constructs a <code>PackedColorModel</code> from the specified
* masks which indicate which bits in an <code>int</code> pixel
* representation contain the alpha, red, green and blue color samples.
* Color components are in the specified <code>ColorSpace</code>, which
* must be of type ColorSpace.TYPE_RGB. All of the bits in each
* mask must be contiguous and fit in the specified number of
* least significant bits of an <code>int</code> pixel representation. If
* <code>amask</code> is 0, there is no alpha. If there is alpha,
* the <code>boolean</code> <code>isAlphaPremultiplied</code>
* specifies how to interpret color and alpha samples
* in pixel values. If the <code>boolean</code> is <code>true</code>,
* color samples are assumed to have been multiplied by the alpha sample.
* The transparency, <code>trans</code>, specifies what alpha values
* can be represented by this color model.
* The transfer type is the type of primitive array used to represent
* pixel values.
* @param space the specified <code>ColorSpace</code>
* @param bits the number of bits in the pixel values
* @param rmask specifies the mask representing
* the bits of the pixel values that represent the red
* color component
* @param gmask specifies the mask representing
* the bits of the pixel values that represent the green
* color component
* @param bmask specifies the mask representing
* the bits of the pixel values that represent
* the blue color component
* @param amask specifies the mask representing
* the bits of the pixel values that represent
* the alpha component
* @param isAlphaPremultiplied <code>true</code> if color samples are
* premultiplied by the alpha sample; <code>false</code> otherwise
* @param trans specifies the alpha value that can be represented by
* this color model
* @param transferType the type of array used to represent pixel values
* @throws IllegalArgumentException if <code>space</code> is not a
* TYPE_RGB space
* @see ColorSpace
*/
public PackedColorModel(ColorSpace space, int bits, int rmask, int gmask,
int bmask, int amask,
boolean isAlphaPremultiplied,
int trans, int transferType) {
super (bits, PackedColorModel.createBitsArray(rmask, gmask, bmask,
amask),
space, (amask == 0 ? false : true),
isAlphaPremultiplied, trans, transferType);
if (space.getType() != ColorSpace.TYPE_RGB) {
throw new IllegalArgumentException("ColorSpace must be TYPE_RGB.");
}
maskArray = new int[numComponents];
maskOffsets = new int[numComponents];
scaleFactors = new float[numComponents];
DecomposeMask(rmask, 0, "red");
DecomposeMask(gmask, 1, "green");
DecomposeMask(bmask, 2, "blue");
if (amask != 0) {
DecomposeMask(amask, 3, "alpha");
if (nBits[3] == 1) {
transparency = Transparency.BITMASK;
}
}
}