Java 类java.awt.Transparency 实例源码

项目:openjdk-jdk10    文件:TIFFDecompressor.java   
/**
 * Create a {@code ComponentColorModel} for use in creating
 * an {@code ImageTypeSpecifier}.
 */
// This code was inspired by the method of the same name in
// javax.imageio.ImageTypeSpecifier
static ColorModel createComponentCM(ColorSpace colorSpace,
                                    int numBands,
                                    int[] bitsPerSample,
                                    int dataType,
                                    boolean hasAlpha,
                                    boolean isAlphaPremultiplied) {
    int transparency =
        hasAlpha ? Transparency.TRANSLUCENT : Transparency.OPAQUE;

    return new ComponentColorModel(colorSpace,
                                   bitsPerSample,
                                   hasAlpha,
                                   isAlphaPremultiplied,
                                   transparency,
                                   dataType);
}
项目:jdk8u-jdk    文件:D3DVolatileSurfaceManager.java   
public D3DVolatileSurfaceManager(SunVolatileImage vImg, Object context) {
    super(vImg, context);

    /*
     * We will attempt to accelerate this image only under the
     * following conditions:
     *   - the image is opaque OR
     *   - the image is translucent AND
     *       - the GraphicsConfig supports the FBO extension OR
     *       - the GraphicsConfig has a stored alpha channel
     */
    int transparency = vImg.getTransparency();
    D3DGraphicsDevice gd = (D3DGraphicsDevice)
        vImg.getGraphicsConfig().getDevice();
    accelerationEnabled =
        (transparency == Transparency.OPAQUE) ||
        (transparency == Transparency.TRANSLUCENT &&
         (gd.isCapPresent(CAPS_RT_PLAIN_ALPHA) ||
          gd.isCapPresent(CAPS_RT_TEXTURE_ALPHA)));
}
项目:jdk8u-jdk    文件:D3DSurfaceData.java   
private boolean initSurfaceNow() {
    boolean isOpaque = (getTransparency() == Transparency.OPAQUE);
    switch (type) {
        case RT_PLAIN:
            return initRTSurface(getNativeOps(), isOpaque);
        case TEXTURE:
            return initTexture(getNativeOps(), false/*isRTT*/, isOpaque);
        case RT_TEXTURE:
            return initTexture(getNativeOps(), true/*isRTT*/,  isOpaque);
        // REMIND: we may want to pass the exact type to the native
        // level here so that we could choose the right presentation
        // interval for the frontbuffer (immediate vs v-synced)
        case WINDOW:
        case FLIP_BACKBUFFER:
            return initFlipBackbuffer(getNativeOps(), peer.getData(),
                                      backBuffersNum, swapEffect,
                                      syncType.id());
        default:
            return false;
    }
}
项目:openjdk-jdk10    文件:D3DSurfaceData.java   
private boolean initSurfaceNow() {
    boolean isOpaque = (getTransparency() == Transparency.OPAQUE);
    switch (type) {
        case RT_PLAIN:
            return initRTSurface(getNativeOps(), isOpaque);
        case TEXTURE:
            return initTexture(getNativeOps(), false/*isRTT*/, isOpaque);
        case RT_TEXTURE:
            return initTexture(getNativeOps(), true/*isRTT*/,  isOpaque);
        // REMIND: we may want to pass the exact type to the native
        // level here so that we could choose the right presentation
        // interval for the frontbuffer (immediate vs v-synced)
        case WINDOW:
        case FLIP_BACKBUFFER:
            return initFlipBackbuffer(getNativeOps(), peer.getData(),
                                      backBuffersNum, swapEffect,
                                      syncType.id());
        default:
            return false;
    }
}
项目:jdk8u-jdk    文件:SourceClippingBlitTest.java   
static void initImage(GraphicsConfiguration gc, Image image) {
    Graphics g = image.getGraphics();
    g.setColor(Color.RED);
    int w = image.getWidth(null);
    int h = image.getHeight(null);
    g.fillRect(0, 0, w, h);
    g.dispose();

    // need to 'accelerate' the image
    if (dstImage == null) {
        dstImage =
            gc.createCompatibleVolatileImage(TESTW, TESTH,
                                             Transparency.OPAQUE);
    }
    dstImage.validate(gc);
    g = dstImage.getGraphics();
    g.drawImage(image, 0, 0, null);
    g.drawImage(image, 0, 0, null);
    g.drawImage(image, 0, 0, null);
}
项目:jdk8u-jdk    文件:D3DGraphicsConfig.java   
@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;
    }
}
项目:jdk8u-jdk    文件:X11VolatileSurfaceManager.java   
public X11VolatileSurfaceManager(SunVolatileImage vImg, Object context) {
    super(vImg, context);

    // We only accelerated opaque vImages currently
    accelerationEnabled = X11SurfaceData.isAccelerationEnabled() &&
        (vImg.getTransparency() == Transparency.OPAQUE);

    if ((context != null) && !accelerationEnabled) {
        // if we're wrapping a backbuffer drawable, we must ensure that
        // the accelerated surface is initialized up front, regardless
        // of whether acceleration is enabled. But we need to set
        // the  accelerationEnabled field to true to reflect that this
        // SM is actually accelerated.
        accelerationEnabled = true;
        sdAccel = initAcceleratedSurface();
        sdCurrent = sdAccel;

        if (sdBackup != null) {
            // release the system memory backup surface, as we won't be
            // needing it in this case
            sdBackup = null;
        }
    }
}
项目:OpenJSharp    文件:DrawImage.java   
protected boolean scaleSurfaceData(SunGraphics2D sg,
                                   Region clipRegion,
                                   SurfaceData srcData,
                                   SurfaceData dstData,
                                   SurfaceType srcType,
                                   SurfaceType dstType,
                                   int sx1, int sy1,
                                   int sx2, int sy2,
                                   double dx1, double dy1,
                                   double dx2, double dy2)
{
    CompositeType comp = sg.imageComp;
    if (CompositeType.SrcOverNoEa.equals(comp) &&
        (srcData.getTransparency() == Transparency.OPAQUE))
    {
        comp = CompositeType.SrcNoEa;
    }

    ScaledBlit blit = ScaledBlit.getFromCache(srcType, comp, dstType);
    if (blit != null) {
        blit.Scale(srcData, dstData, sg.composite, clipRegion,
                   sx1, sy1, sx2, sy2, dx1, dy1, dx2, dy2);
        return true;
    }
    return false;
}
项目:jdk8u-jdk    文件:D3DRenderer.java   
void copyArea(SunGraphics2D sg2d,
              int x, int y, int w, int h, int dx, int dy)
{
    rq.lock();
    try {
        int ctxflags =
            sg2d.surfaceData.getTransparency() == Transparency.OPAQUE ?
                D3DContext.SRC_IS_OPAQUE : D3DContext.NO_CONTEXT_FLAGS;
        D3DSurfaceData dstData;
        try {
            dstData = (D3DSurfaceData)sg2d.surfaceData;
        } catch (ClassCastException e) {
            throw new InvalidPipeException("wrong surface data type: " + sg2d.surfaceData);
        }
        D3DContext.validateContext(dstData, dstData,
                                   sg2d.getCompClip(), sg2d.composite,
                                   null, null, null, ctxflags);

        rq.ensureCapacity(28);
        buf.putInt(COPY_AREA);
        buf.putInt(x).putInt(y).putInt(w).putInt(h);
        buf.putInt(dx).putInt(dy);
    } finally {
        rq.unlock();
    }
}
项目:openjdk-jdk10    文件:ComponentColorModelEqualsTest.java   
private static void testConstructor2() {
    /*
     * verify equality with constructor
     * ComponentColorModel(ColorSpace colorSpace,
     *                  boolean hasAlpha,
     *                  boolean isAlphaPremultiplied,
     *                  int transparency,
     *                  int transferType)
     */
    ComponentColorModel model1 =
        new ComponentColorModel(ColorSpace.getInstance(ColorSpace.CS_sRGB),
                                false,
                                false,
                                Transparency.OPAQUE,
                                DataBuffer.TYPE_BYTE);
    ComponentColorModel model2 =
        new ComponentColorModel(ColorSpace.getInstance(ColorSpace.CS_sRGB),
                                false,
                                false,
                                Transparency.OPAQUE,
                                DataBuffer.TYPE_BYTE);
    verifyEquals(model1, model2);
}
项目:OpenJSharp    文件:OGLRenderer.java   
void copyArea(SunGraphics2D sg2d,
              int x, int y, int w, int h, int dx, int dy)
{
    rq.lock();
    try {
        int ctxflags =
            sg2d.surfaceData.getTransparency() == Transparency.OPAQUE ?
                OGLContext.SRC_IS_OPAQUE : OGLContext.NO_CONTEXT_FLAGS;
        OGLSurfaceData dstData;
        try {
            dstData = (OGLSurfaceData)sg2d.surfaceData;
        } catch (ClassCastException e) {
            throw new InvalidPipeException("wrong surface data type: " + sg2d.surfaceData);
        }
        OGLContext.validateContext(dstData, dstData,
                                   sg2d.getCompClip(), sg2d.composite,
                                   null, null, null, ctxflags);

        rq.ensureCapacity(28);
        buf.putInt(COPY_AREA);
        buf.putInt(x).putInt(y).putInt(w).putInt(h);
        buf.putInt(dx).putInt(dy);
    } finally {
        rq.unlock();
    }
}
项目:jdk8u-jdk    文件:CGLGraphicsConfig.java   
@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;
    }
}
项目:openjdk-jdk10    文件:ComponentColorModelEqualsTest.java   
private static void testConstructor1() {
    /*
     * verify equality with constructor
     * ComponentColorModel(ColorSpace colorSpace,
     *                  int[] bits,
     *                  boolean hasAlpha,
     *                  boolean isAlphaPremultiplied,
     *                  int transparency,
     *                  int transferType)
     */
    ComponentColorModel model1 =
        new ComponentColorModel(ColorSpace.getInstance(ColorSpace.CS_sRGB),
                                new int[] {8, 8, 8},
                                false,
                                false,
                                Transparency.OPAQUE,
                                DataBuffer.TYPE_BYTE);
    ComponentColorModel model2 =
        new ComponentColorModel(ColorSpace.getInstance(ColorSpace.CS_sRGB),
                                new int[] {8, 8, 8},
                                false,
                                false,
                                Transparency.OPAQUE,
                                DataBuffer.TYPE_BYTE);
    verifyEquals(model1, model2);
}
项目:OpenJSharp    文件:CGLVolatileSurfaceManager.java   
public CGLVolatileSurfaceManager(SunVolatileImage vImg, Object context) {
    super(vImg, context);

    /*
     * We will attempt to accelerate this image only under the
     * following conditions:
     *   - the image is opaque OR
     *   - the image is translucent AND
     *       - the GraphicsConfig supports the FBO extension OR
     *       - the GraphicsConfig has a stored alpha channel
     */
    int transparency = vImg.getTransparency();
    CGLGraphicsConfig gc = (CGLGraphicsConfig)vImg.getGraphicsConfig();
    accelerationEnabled =
        (transparency == Transparency.OPAQUE) ||
        ((transparency == Transparency.TRANSLUCENT) &&
         (gc.isCapPresent(CAPS_EXT_FBOBJECT) ||
          gc.isCapPresent(CAPS_STORED_ALPHA)));
}
项目:OpenJSharp    文件:WGLVolatileSurfaceManager.java   
public WGLVolatileSurfaceManager(SunVolatileImage vImg, Object context) {
    super(vImg, context);

    /*
     * We will attempt to accelerate this image only under the
     * following conditions:
     *   - the image is opaque OR
     *   - the image is translucent AND
     *       - the GraphicsConfig supports the FBO extension OR
     *       - the GraphicsConfig has a stored alpha channel
     */
    int transparency = vImg.getTransparency();
    WGLGraphicsConfig gc = (WGLGraphicsConfig)vImg.getGraphicsConfig();
    accelerationEnabled =
        (transparency == Transparency.OPAQUE) ||
        ((transparency == Transparency.TRANSLUCENT) &&
         (gc.isCapPresent(CAPS_EXT_FBOBJECT) ||
          gc.isCapPresent(CAPS_STORED_ALPHA)));
}
项目:OpenJSharp    文件:GLXGraphicsConfig.java   
@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;
    }
}
项目:jdk8u-jdk    文件:CGLVolatileSurfaceManager.java   
public CGLVolatileSurfaceManager(SunVolatileImage vImg, Object context) {
    super(vImg, context);

    /*
     * We will attempt to accelerate this image only under the
     * following conditions:
     *   - the image is opaque OR
     *   - the image is translucent AND
     *       - the GraphicsConfig supports the FBO extension OR
     *       - the GraphicsConfig has a stored alpha channel
     */
    int transparency = vImg.getTransparency();
    CGLGraphicsConfig gc = (CGLGraphicsConfig)vImg.getGraphicsConfig();
    accelerationEnabled =
        (transparency == Transparency.OPAQUE) ||
        ((transparency == Transparency.TRANSLUCENT) &&
         (gc.isCapPresent(CAPS_EXT_FBOBJECT) ||
          gc.isCapPresent(CAPS_STORED_ALPHA)));
}
项目:OpenJSharp    文件:GLXVolatileSurfaceManager.java   
public GLXVolatileSurfaceManager(SunVolatileImage vImg, Object context) {
    super(vImg, context);

    /*
     * We will attempt to accelerate this image only under the
     * following conditions:
     *   - the image is opaque OR
     *   - the image is translucent AND
     *       - the GraphicsConfig supports the FBO extension OR
     *       - the GraphicsConfig has a stored alpha channel
     */
    int transparency = vImg.getTransparency();
    GLXGraphicsConfig gc = (GLXGraphicsConfig)vImg.getGraphicsConfig();
    accelerationEnabled =
        (transparency == Transparency.OPAQUE) ||
        ((transparency == Transparency.TRANSLUCENT) &&
         (gc.isCapPresent(CAPS_EXT_FBOBJECT) ||
          gc.isCapPresent(CAPS_STORED_ALPHA)));
}
项目:jdk8u-jdk    文件:WGLGraphicsConfig.java   
@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;
    }
}
项目:DicomViewer    文件:OpenCLWithJOCL.java   
BufferedImage createFloatBufferedImage(int w, int h, int bands) {
    // Define dimensions and layout of the image
    //int bands = 4; // 4 bands for ARGB, 3 for RGB etc
    int[] bandOffsets = {0, 1, 2, 3}; // length == bands, 0 == R, 1 == G, 2 == B and 3 == A

    // Create a TYPE_FLOAT sample model (specifying how the pixels are stored)
    SampleModel sampleModel = new PixelInterleavedSampleModel(DataBuffer.TYPE_FLOAT, w, h, bands, w  * bands, bandOffsets);
    // ...and data buffer (where the pixels are stored)
    DataBuffer buffer = new DataBufferFloat(w * h * bands);

    // Wrap it in a writable raster
    WritableRaster raster = Raster.createWritableRaster(sampleModel, buffer, null);

    // Create a color model compatible with this sample model/raster (TYPE_FLOAT)
    // Note that the number of bands must equal the number of color components in the 
    // color space (3 for RGB) + 1 extra band if the color model contains alpha 
    ColorSpace colorSpace = ColorSpace.getInstance(ColorSpace.CS_sRGB);
    ColorModel colorModel = new ComponentColorModel(colorSpace, true, false, Transparency.TRANSLUCENT, DataBuffer.TYPE_FLOAT);

    // And finally create an image with this raster
    return new BufferedImage(colorModel, raster, colorModel.isAlphaPremultiplied(), null);
}
项目:JuggleMasterPro    文件:ColorChooserDropDownJButton.java   
@Override final public void paintComponent(Graphics objPgraphics) {

        // Draw a colored rectangle in place of the button :
        final BufferedImage imgLbuffer =
                                            Constants.objS_GRAPHICS_CONFIGURATION.createCompatibleImage(ColorChooserDropDownJButton.intS_SIZE,
                                                                                                        ColorChooserDropDownJButton.intS_SIZE,
                                                                                                        Transparency.OPAQUE);
        final Graphics2D objLgraphics2D = (Graphics2D) imgLbuffer.getGraphics();
        final Color objLcolor = this.getGammaColor();
        objLgraphics2D.setColor(objLcolor);
        objLgraphics2D.fillRect(1, 1, ColorChooserDropDownJButton.intS_SIZE - 2, ColorChooserDropDownJButton.intS_SIZE - 2);
        if (this.isEnabled()) {
            final Image imgL =
                                Tools.isLightColor(objLcolor) ? (this.objGjWindow.isVisible() ? this.imgGupB : this.imgGdownB)
                                                                : (this.objGjWindow.isVisible() ? this.imgGupW : this.imgGdownW);
            if (imgL != null) {
                objLgraphics2D.drawImage(imgL, 0, 0, null);
            }
        }
        objLgraphics2D.setColor(this.isEnabled() ? Color.DARK_GRAY : Color.LIGHT_GRAY);
        objLgraphics2D.drawRect(0, 0, ColorChooserDropDownJButton.intS_SIZE, ColorChooserDropDownJButton.intS_SIZE);
        objLgraphics2D.dispose();
        objPgraphics.drawImage(imgLbuffer, 0, 0, null);
    }
项目:openjdk-jdk10    文件:Win32GraphicsConfig.java   
/**
 * 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;
    }
}
项目:incubator-netbeans    文件:ImageUtilities.java   
/** Creates BufferedImage with Transparency.TRANSLUCENT */
static final java.awt.image.BufferedImage createBufferedImage(int width, int height) {
    if (Utilities.isMac()) {
        return new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB_PRE);
    }

    ColorModel model = colorModel(java.awt.Transparency.TRANSLUCENT);
    java.awt.image.BufferedImage buffImage = new java.awt.image.BufferedImage(
            model, model.createCompatibleWritableRaster(width, height), model.isAlphaPremultiplied(), null
        );

    return buffImage;
}
项目:incubator-netbeans    文件:ComboTest.java   
/** Creates BufferedImage 16x16 and Transparency.BITMASK */
private static final BufferedImage createBufferedImage(int width, int height) {
    ColorModel model = GraphicsEnvironment.getLocalGraphicsEnvironment().
            getDefaultScreenDevice().getDefaultConfiguration().getColorModel(Transparency.BITMASK);
    BufferedImage buffImage = new BufferedImage(model,
            model.createCompatibleWritableRaster(width, height), model.isAlphaPremultiplied(), null);
    return buffImage;
}
项目:incubator-netbeans    文件:EditableDisplayerTest.java   
/** Creates BufferedImage 16x16 and Transparency.BITMASK */
private static final BufferedImage createBufferedImage(int width, int height) {
    ColorModel model = GraphicsEnvironment.getLocalGraphicsEnvironment().
            getDefaultScreenDevice().getDefaultConfiguration().getColorModel(Transparency.BITMASK);
    BufferedImage buffImage = new BufferedImage(model,
            model.createCompatibleWritableRaster(width, height), model.isAlphaPremultiplied(), null);
    return buffImage;
}
项目:openjdk-jdk10    文件:X11SurfaceDataProxy.java   
@Override
public boolean isSupportedOperation(SurfaceData srcData,
                                    int txtype,
                                    CompositeType comp,
                                    Color bgColor)
{
    // These could probably be combined into a single
    // nested if, but the logic is easier to follow this way.

    // we don't have X11 scale loops, so always use
    // software surface in case of scaling
    if (txtype >= SunGraphics2D.TRANSFORM_TRANSLATESCALE) {
        return false;
    }

    if (bgColor != null &&
        bgColor.getTransparency() != Transparency.OPAQUE)
    {
        return false;
    }

    // for transparent images SrcNoEa+bgColor has the
    // same effect as SrcOverNoEa+bgColor, so we allow
    // copying from pixmap SD using accelerated blitbg loops:
    // SrcOver will be changed to SrcNoEa in DrawImage.blitSD
    if (CompositeType.SrcOverNoEa.equals(comp) ||
        (CompositeType.SrcNoEa.equals(comp) &&
         bgColor != null))
    {
        return true;
    }

    return false;
}
项目:jdk8u-jdk    文件:DrawImage.java   
protected static boolean isBgOperation(SurfaceData srcData, Color bgColor) {
    // If we cannot get the srcData, then cannot assume anything about
    // the image
    return ((srcData == null) ||
            ((bgColor != null) &&
             (srcData.getTransparency() != Transparency.OPAQUE)));
}
项目:BrainControl    文件:BgRenderer.java   
public BgRenderer(Level level, GraphicsConfiguration graphicsConfiguration, int width, int height, int distance) {
    this.distance = distance;
    this.width = width;
    this.height = height;

    this.level = level;
    image = graphicsConfiguration.createCompatibleImage(width, height, Transparency.TRANSLUCENT);
    g = (Graphics2D) image.getGraphics();
    g.setComposite(AlphaComposite.Src);

    updateArea(0, 0, width, height);
}
项目:openjdk-jdk10    文件:D3DGraphicsConfig.java   
/**
 * {@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;
}
项目:opentest    文件:ImageUtil.java   
public static BufferedImage cloneImageRegion(BufferedImage srcImg, int x, int y, int width, int height) {
    int imgType = (srcImg.getTransparency() == Transparency.OPAQUE)
            ? BufferedImage.TYPE_INT_RGB
            : BufferedImage.TYPE_INT_ARGB;
    BufferedImage newImage = new BufferedImage(width, height, imgType);
    Graphics2D g2 = newImage.createGraphics();
    g2.drawImage(srcImg.getSubimage(x, y, width, height), 0, 0, null);
    g2.dispose();

    return newImage;
}
项目:jdk8u-jdk    文件:BMPSubsamplingTest.java   
private BufferedImage create3ByteImage(int[] nBits, int[] bOffs) {
    ColorSpace cs = ColorSpace.getInstance(ColorSpace.CS_sRGB);
    ColorModel colorModel =
        new ComponentColorModel(cs, nBits,
                                false, false,
                                Transparency.OPAQUE,
                                DataBuffer.TYPE_BYTE);
    WritableRaster raster =
        Raster.createInterleavedRaster(DataBuffer.TYPE_BYTE,
                                       w, h,
                                       w*3, 3,
                                       bOffs, null);
    return new BufferedImage(colorModel, raster, false, null);
}
项目:openjdk-jdk10    文件:GLXGraphicsConfig.java   
/**
 * Creates a new hidden-acceleration image of the given width and height
 * that is associated with the target Component.
 */
@Override
public Image createAcceleratedImage(Component target,
                                    int width, int height)
{
    ColorModel model = getColorModel(Transparency.OPAQUE);
    WritableRaster wr =
        model.createCompatibleWritableRaster(width, height);
    return new OffScreenImage(target, model, wr,
                              model.isAlphaPremultiplied());
}
项目:openjdk-jdk10    文件:RenderToCustomBufferTest.java   
private static BufferedImage createCustomBuffer() {
    ColorSpace cs = ColorSpace.getInstance(ColorSpace.CS_sRGB);
    ColorModel cm = new ComponentColorModel(cs, false, false,
            Transparency.OPAQUE, DataBuffer.TYPE_FLOAT);
    WritableRaster wr = cm.createCompatibleWritableRaster(width, height);

    return new BufferedImage(cm, wr, false, null);
}
项目:openjdk-jdk10    文件:SunVolatileImage.java   
private SunVolatileImage(Component comp,
                         GraphicsConfiguration graphicsConfig,
                         int width, int height, Object context,
                         ImageCapabilities caps)
{
    this(comp, graphicsConfig,
         width, height, context, Transparency.OPAQUE, caps, UNDEFINED);
}
项目:jdk8u-jdk    文件:Win32GraphicsConfig.java   
/**
 * 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;
    }
}
项目:openjdk-jdk10    文件:X11GraphicsConfig.java   
public static ComponentColorModel createABGRCCM() {
    ColorSpace cs = ColorSpace.getInstance(ColorSpace.CS_sRGB);
    int[] nBits = {8, 8, 8, 8};
    int[] bOffs = {3, 2, 1, 0};
    return new ComponentColorModel(cs, nBits, true, true,
                                   Transparency.TRANSLUCENT,
                                   DataBuffer.TYPE_BYTE);
}
项目:jdk8u-jdk    文件:ColCvtAlpha.java   
public static void main(String args[]) {
    BufferedImage src
        = new BufferedImage(1, 10, BufferedImage.TYPE_INT_ARGB);

    // Set src pixel values
    Color pelColor = new Color(100, 100, 100, 128);
    for (int i = 0; i < 10; i++) {
        src.setRGB(0, i, pelColor.getRGB());
    }

    ColorModel cm = new ComponentColorModel
        (ColorSpace.getInstance(ColorSpace.CS_GRAY),
         new int [] {8,8}, true,
         src.getColorModel().isAlphaPremultiplied(),
         Transparency.TRANSLUCENT,
         DataBuffer.TYPE_BYTE);

    SampleModel sm = new PixelInterleavedSampleModel
        (DataBuffer.TYPE_BYTE, 100, 100, 2, 200,
         new int [] { 0, 1 });

    WritableRaster wr = Raster.createWritableRaster(sm, new Point(0,0));

    BufferedImage dst =
        new BufferedImage(cm, wr, cm.isAlphaPremultiplied(), null);
    dst = dst.getSubimage(0, 0, 1, 10);

    ColorConvertOp op = new ColorConvertOp(null);

    op.filter(src, dst);

    for (int i = 0; i < 10; i++) {
        if (((dst.getRGB(0, i) >> 24) & 0xff) != 128) {
            throw new RuntimeException(
                "Incorrect destination alpha value.");
        }
    }

}
项目:OpenJSharp    文件:SunGraphics2D.java   
/**
 * Sets the Paint in the current graphics state.
 * @param paint The Paint object to be used to generate color in
 * the rendering process.
 * @see java.awt.Graphics#setColor
 * @see GradientPaint
 * @see TexturePaint
 */
public void setPaint(Paint paint) {
    if (paint instanceof Color) {
        setColor((Color) paint);
        return;
    }
    if (paint == null || this.paint == paint) {
        return;
    }
    this.paint = paint;
    if (imageComp == CompositeType.SrcOverNoEa) {
        // special case where compState depends on opacity of paint
        if (paint.getTransparency() == Transparency.OPAQUE) {
            if (compositeState != COMP_ISCOPY) {
                compositeState = COMP_ISCOPY;
            }
        } else {
            if (compositeState == COMP_ISCOPY) {
                compositeState = COMP_ALPHA;
            }
        }
    }
    Class<? extends Paint> paintClass = paint.getClass();
    if (paintClass == GradientPaint.class) {
        paintState = PAINT_GRADIENT;
    } else if (paintClass == LinearGradientPaint.class) {
        paintState = PAINT_LIN_GRADIENT;
    } else if (paintClass == RadialGradientPaint.class) {
        paintState = PAINT_RAD_GRADIENT;
    } else if (paintClass == TexturePaint.class) {
        paintState = PAINT_TEXTURE;
    } else {
        paintState = PAINT_CUSTOM;
    }
    validFontInfo = false;
    invalidatePipe();
}
项目:jdk8u-jdk    文件:ImageTests.java   
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));
}
项目:jdk8u-jdk    文件:D3DGraphicsConfig.java   
/**
 * {@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;
}