Search in sources :

Example 6 with SinglePixelPackedSampleModel

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

the class BMPImageReader method read32Bit.

private void read32Bit(int[] idata) throws IOException {
    if (noTransform) {
        int j = isBottomUp ? (height - 1) * width : 0;
        for (int i = 0; i < height; i++) {
            if (abortRequested()) {
                break;
            }
            iis.readFully(idata, j, width);
            j += isBottomUp ? -width : width;
            processImageUpdate(bi, 0, i, destinationRegion.width, 1, 1, 1, new int[] { 0 });
            processImageProgress(100.0F * i / destinationRegion.height);
        }
    } else {
        int[] buf = new int[width];
        int lineStride = ((SinglePixelPackedSampleModel) sampleModel).getScanlineStride();
        if (isBottomUp) {
            int lastLine = sourceRegion.y + (destinationRegion.height - 1) * scaleY;
            iis.skipBytes(width * (height - 1 - lastLine) << 2);
        } else
            iis.skipBytes(width * sourceRegion.y << 2);
        int skipLength = width * (scaleY - 1) << 2;
        int k = destinationRegion.y * lineStride;
        if (isBottomUp)
            k += (destinationRegion.height - 1) * lineStride;
        k += destinationRegion.x;
        for (int j = 0, y = sourceRegion.y; j < destinationRegion.height; j++, y += scaleY) {
            if (abortRequested())
                break;
            iis.readFully(buf, 0, width);
            for (int i = 0, m = sourceRegion.x; i < destinationRegion.width; i++, m += scaleX) {
                //get the bit and assign to the data buffer of the raster
                idata[k + i] = buf[m];
            }
            k += isBottomUp ? -lineStride : lineStride;
            iis.skipBytes(skipLength);
            processImageUpdate(bi, 0, j, destinationRegion.width, 1, 1, 1, new int[] { 0 });
            processImageProgress(100.0F * j / destinationRegion.height);
        }
    }
}
Also used : SinglePixelPackedSampleModel(java.awt.image.SinglePixelPackedSampleModel) Point(java.awt.Point)

Example 7 with SinglePixelPackedSampleModel

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

the class BMPImageReader method read16Bit.

private void read16Bit(short[] sdata) throws IOException {
    // Padding bytes at the end of each scanline
    // width * bitsPerPixel should be divisible by 32
    int padding = width * 2 % 4;
    if (padding != 0)
        padding = 4 - padding;
    int lineLength = width + padding / 2;
    if (noTransform) {
        int j = isBottomUp ? (height - 1) * width : 0;
        for (int i = 0; i < height; i++) {
            if (abortRequested()) {
                break;
            }
            iis.readFully(sdata, j, width);
            iis.skipBytes(padding);
            j += isBottomUp ? -width : width;
            processImageUpdate(bi, 0, i, destinationRegion.width, 1, 1, 1, new int[] { 0 });
            processImageProgress(100.0F * i / destinationRegion.height);
        }
    } else {
        short[] buf = new short[lineLength];
        int lineStride = ((SinglePixelPackedSampleModel) sampleModel).getScanlineStride();
        if (isBottomUp) {
            int lastLine = sourceRegion.y + (destinationRegion.height - 1) * scaleY;
            iis.skipBytes(lineLength * (height - 1 - lastLine) << 1);
        } else
            iis.skipBytes(lineLength * sourceRegion.y << 1);
        int skipLength = lineLength * (scaleY - 1) << 1;
        int k = destinationRegion.y * lineStride;
        if (isBottomUp)
            k += (destinationRegion.height - 1) * lineStride;
        k += destinationRegion.x;
        for (int j = 0, y = sourceRegion.y; j < destinationRegion.height; j++, y += scaleY) {
            if (abortRequested())
                break;
            iis.readFully(buf, 0, lineLength);
            for (int i = 0, m = sourceRegion.x; i < destinationRegion.width; i++, m += scaleX) {
                //get the bit and assign to the data buffer of the raster
                sdata[k + i] = buf[m];
            }
            k += isBottomUp ? -lineStride : lineStride;
            iis.skipBytes(skipLength);
            processImageUpdate(bi, 0, j, destinationRegion.width, 1, 1, 1, new int[] { 0 });
            processImageProgress(100.0F * j / destinationRegion.height);
        }
    }
}
Also used : SinglePixelPackedSampleModel(java.awt.image.SinglePixelPackedSampleModel) Point(java.awt.Point)

Example 8 with SinglePixelPackedSampleModel

use of java.awt.image.SinglePixelPackedSampleModel 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 9 with SinglePixelPackedSampleModel

use of java.awt.image.SinglePixelPackedSampleModel 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 10 with SinglePixelPackedSampleModel

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

the class D3DSurfaceData method getRaster.

public synchronized Raster getRaster(int x, int y, int w, int h) {
    if (wrn == null) {
        DirectColorModel dcm = (DirectColorModel) getColorModel();
        SampleModel smHw;
        int dataType = 0;
        int scanStride = width;
        if (dcm.getPixelSize() > 16) {
            dataType = DataBuffer.TYPE_INT;
        } else {
            // 15, 16
            dataType = DataBuffer.TYPE_USHORT;
        }
        // note that we have to use the surface width and height here,
        // not the passed w,h
        smHw = new SinglePixelPackedSampleModel(dataType, width, height, scanStride, dcm.getMasks());
        DataBuffer dbn = new D3DDataBufferNative(this, dataType, width, height);
        wrn = WritableRasterNative.createNativeRaster(smHw, dbn);
    }
    return wrn;
}
Also used : SampleModel(java.awt.image.SampleModel) SinglePixelPackedSampleModel(java.awt.image.SinglePixelPackedSampleModel) DirectColorModel(java.awt.image.DirectColorModel) SinglePixelPackedSampleModel(java.awt.image.SinglePixelPackedSampleModel) DataBuffer(java.awt.image.DataBuffer)

Aggregations

SinglePixelPackedSampleModel (java.awt.image.SinglePixelPackedSampleModel)15 Point (java.awt.Point)7 MultiPixelPackedSampleModel (java.awt.image.MultiPixelPackedSampleModel)7 SampleModel (java.awt.image.SampleModel)7 DirectColorModel (java.awt.image.DirectColorModel)6 ComponentSampleModel (java.awt.image.ComponentSampleModel)5 DataBuffer (java.awt.image.DataBuffer)5 IndexColorModel (java.awt.image.IndexColorModel)5 ColorModel (java.awt.image.ColorModel)4 DataBufferInt (java.awt.image.DataBufferInt)4 Rectangle (java.awt.Rectangle)2 ColorSpace (java.awt.color.ColorSpace)2 BandedSampleModel (java.awt.image.BandedSampleModel)2 ComponentColorModel (java.awt.image.ComponentColorModel)2 PixelInterleavedSampleModel (java.awt.image.PixelInterleavedSampleModel)2 Raster (java.awt.image.Raster)2 WritableRaster (java.awt.image.WritableRaster)2 Paint (java.awt.Paint)1 ICC_ColorSpace (java.awt.color.ICC_ColorSpace)1 DataBufferByte (java.awt.image.DataBufferByte)1