Search in sources :

Example 16 with DataBufferInt

use of java.awt.image.DataBufferInt in project jdk8u_jdk by JetBrains.

the class MultipleGradientPaintContext method getRaster.

/**
     * {@inheritDoc}
     */
public final Raster getRaster(int x, int y, int w, int h) {
    // If working raster is big enough, reuse it. Otherwise,
    // build a large enough new one.
    Raster raster = saved;
    if (raster == null || raster.getWidth() < w || raster.getHeight() < h) {
        raster = getCachedRaster(model, w, h);
        saved = raster;
    }
    // Access raster internal int array. Because we use a DirectColorModel,
    // we know the DataBuffer is of type DataBufferInt and the SampleModel
    // is SinglePixelPackedSampleModel.
    // Adjust for initial offset in DataBuffer and also for the scanline
    // stride.
    // These calls make the DataBuffer non-acceleratable, but the
    // Raster is never Stable long enough to accelerate anyway...
    DataBufferInt rasterDB = (DataBufferInt) raster.getDataBuffer();
    int[] pixels = rasterDB.getData(0);
    int off = rasterDB.getOffset();
    int scanlineStride = ((SinglePixelPackedSampleModel) raster.getSampleModel()).getScanlineStride();
    int adjust = scanlineStride - w;
    // delegate to subclass
    fillRaster(pixels, off, adjust, x, y, w, h);
    return raster;
}
Also used : Raster(java.awt.image.Raster) WritableRaster(java.awt.image.WritableRaster) SinglePixelPackedSampleModel(java.awt.image.SinglePixelPackedSampleModel) DataBufferInt(java.awt.image.DataBufferInt)

Example 17 with DataBufferInt

use of java.awt.image.DataBufferInt in project jdk8u_jdk by JetBrains.

the class PathGraphics method hasTransparentPixels.

/**
     * Return true if the BufferedImage argument has non-opaque
     * bits in it and therefore can not be directly rendered by
     * GDI. Return false if the image is opaque. If this function
     * can not tell for sure whether the image has transparent
     * pixels then it assumes that it does.
     */
protected boolean hasTransparentPixels(BufferedImage bufferedImage) {
    ColorModel colorModel = bufferedImage.getColorModel();
    boolean hasTransparency = colorModel == null ? true : colorModel.getTransparency() != ColorModel.OPAQUE;
    /*
         * For the default INT ARGB check the image to see if any pixels are
         * really transparent. If there are no transparent pixels then the
         * transparency of the color model can be ignored.
         * We assume that IndexColorModel images have already been
         * checked for transparency and will be OPAQUE unless they actually
         * have transparent pixels present.
         */
    if (hasTransparency && bufferedImage != null) {
        if (bufferedImage.getType() == BufferedImage.TYPE_INT_ARGB || bufferedImage.getType() == BufferedImage.TYPE_INT_ARGB_PRE) {
            DataBuffer db = bufferedImage.getRaster().getDataBuffer();
            SampleModel sm = bufferedImage.getRaster().getSampleModel();
            if (db instanceof DataBufferInt && sm instanceof SinglePixelPackedSampleModel) {
                SinglePixelPackedSampleModel psm = (SinglePixelPackedSampleModel) sm;
                // Stealing the data array for reading only...
                int[] int_data = SunWritableRaster.stealData((DataBufferInt) db, 0);
                int x = bufferedImage.getMinX();
                int y = bufferedImage.getMinY();
                int w = bufferedImage.getWidth();
                int h = bufferedImage.getHeight();
                int stride = psm.getScanlineStride();
                boolean hastranspixel = false;
                for (int j = y; j < y + h; j++) {
                    int yoff = j * stride;
                    for (int i = x; i < x + w; i++) {
                        if ((int_data[yoff + i] & 0xff000000) != 0xff000000) {
                            hastranspixel = true;
                            break;
                        }
                    }
                    if (hastranspixel) {
                        break;
                    }
                }
                if (hastranspixel == false) {
                    hasTransparency = false;
                }
            }
        }
    }
    return hasTransparency;
}
Also used : SampleModel(java.awt.image.SampleModel) SinglePixelPackedSampleModel(java.awt.image.SinglePixelPackedSampleModel) IndexColorModel(java.awt.image.IndexColorModel) ColorModel(java.awt.image.ColorModel) SinglePixelPackedSampleModel(java.awt.image.SinglePixelPackedSampleModel) DataBufferInt(java.awt.image.DataBufferInt) Paint(java.awt.Paint) DataBuffer(java.awt.image.DataBuffer)

Example 18 with DataBufferInt

use of java.awt.image.DataBufferInt in project jdk8u_jdk by JetBrains.

the class JLightweightFrame method resizeBuffer.

private void resizeBuffer(int width, int height, int newScaleFactor) {
    bbImage = new BufferedImage(width * newScaleFactor, height * newScaleFactor, BufferedImage.TYPE_INT_ARGB_PRE);
    int[] pixels = ((DataBufferInt) bbImage.getRaster().getDataBuffer()).getData();
    if (copyBufferEnabled) {
        syncCopyBuffer(true, 0, 0, width, height, newScaleFactor);
        pixels = copyBuffer;
    }
    content.imageBufferReset(pixels, 0, 0, width, height, width * newScaleFactor, newScaleFactor);
}
Also used : DataBufferInt(java.awt.image.DataBufferInt) BufferedImage(java.awt.image.BufferedImage)

Example 19 with DataBufferInt

use of java.awt.image.DataBufferInt in project jdk8u_jdk by JetBrains.

the class JLightweightFrame method syncCopyBuffer.

private void syncCopyBuffer(boolean reset, int x, int y, int w, int h, int scale) {
    content.paintLock();
    try {
        int[] srcBuffer = ((DataBufferInt) bbImage.getRaster().getDataBuffer()).getData();
        if (reset) {
            copyBuffer = new int[srcBuffer.length];
        }
        int linestride = bbImage.getWidth();
        x *= scale;
        y *= scale;
        w *= scale;
        h *= scale;
        for (int i = 0; i < h; i++) {
            int from = (y + i) * linestride + x;
            System.arraycopy(srcBuffer, from, copyBuffer, from, w);
        }
    } finally {
        content.paintUnlock();
    }
}
Also used : DataBufferInt(java.awt.image.DataBufferInt) Point(java.awt.Point)

Example 20 with DataBufferInt

use of java.awt.image.DataBufferInt in project jmonkeyengine by jMonkeyEngine.

the class Screenshots method convertScreenShot2.

public static void convertScreenShot2(IntBuffer bgraBuf, BufferedImage out) {
    WritableRaster wr = out.getRaster();
    DataBufferInt db = (DataBufferInt) wr.getDataBuffer();
    int[] cpuArray = db.getData();
    bgraBuf.clear();
    bgraBuf.get(cpuArray);
//        int width  = wr.getWidth();
//        int height = wr.getHeight();
//
//        // flip the components the way AWT likes them
//        for (int y = 0; y < height / 2; y++){
//            for (int x = 0; x < width; x++){
//                int inPtr  = (y * width + x);
//                int outPtr = ((height-y-1) * width + x);
//                int pixel = cpuArray[inPtr];
//                cpuArray[inPtr] = cpuArray[outPtr];
//                cpuArray[outPtr] = pixel;
//            }
//        }
}
Also used : WritableRaster(java.awt.image.WritableRaster) DataBufferInt(java.awt.image.DataBufferInt)

Aggregations

DataBufferInt (java.awt.image.DataBufferInt)37 BufferedImage (java.awt.image.BufferedImage)22 DataBuffer (java.awt.image.DataBuffer)15 DataBufferByte (java.awt.image.DataBufferByte)12 DataBufferShort (java.awt.image.DataBufferShort)10 Graphics2D (java.awt.Graphics2D)9 SinglePixelPackedSampleModel (java.awt.image.SinglePixelPackedSampleModel)8 WritableRaster (java.awt.image.WritableRaster)8 SampleModel (java.awt.image.SampleModel)7 DataBufferUShort (java.awt.image.DataBufferUShort)6 MultiPixelPackedSampleModel (java.awt.image.MultiPixelPackedSampleModel)6 Point (java.awt.Point)5 ComponentSampleModel (java.awt.image.ComponentSampleModel)5 Rectangle (java.awt.Rectangle)4 IndexColorModel (java.awt.image.IndexColorModel)4 ColorModel (java.awt.image.ColorModel)3 DirectColorModel (java.awt.image.DirectColorModel)3 ByteBuffer (java.nio.ByteBuffer)3 Raster (java.awt.image.Raster)2 IOException (java.io.IOException)2