Java Code Examples for sun.awt.image.SunWritableRaster#stealData()

The following examples show how to use sun.awt.image.SunWritableRaster#stealData() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CImage.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
private BufferedImage toImage(int srcWidth, int srcHeight, int dstWidth, int dstHeight) {
    final BufferedImage bimg = new BufferedImage(dstWidth, dstHeight, BufferedImage.TYPE_INT_ARGB_PRE);
    final DataBufferInt dbi = (DataBufferInt)bimg.getRaster().getDataBuffer();
    final int[] buffer = SunWritableRaster.stealData(dbi, 0);
    nativeCopyNSImageIntoArray(ptr, buffer, srcWidth, srcHeight, dstWidth, dstHeight);
    SunWritableRaster.markDirty(dbi);
    return bimg;
}
 
Example 2
Source File: SplashScreen.java    From Java8CN with Apache License 2.0 5 votes vote down vote up
/**
 * Updates the splash window with current contents of the overlay image.
 *
 * @throws IllegalStateException if the overlay image does not exist;
 *         for example, if {@code createGraphics} has never been called,
 *         or if the splash screen has already been closed
 */
public void update() throws IllegalStateException {
    BufferedImage image;
    synchronized (SplashScreen.class) {
        checkVisible();
        image = this.image;
    }
    if (image == null) {
        throw new IllegalStateException("no overlay image available");
    }
    DataBuffer buf = image.getRaster().getDataBuffer();
    if (!(buf instanceof DataBufferInt)) {
        throw new AssertionError("Overlay image DataBuffer is of invalid type == "+buf.getClass().getName());
    }
    int numBanks = buf.getNumBanks();
    if (numBanks!=1) {
        throw new AssertionError("Invalid number of banks =="+numBanks+" in overlay image DataBuffer");
    }
    if (!(image.getSampleModel() instanceof SinglePixelPackedSampleModel)) {
        throw new AssertionError("Overlay image has invalid sample model == "+image.getSampleModel().getClass().getName());
    }
    SinglePixelPackedSampleModel sm = (SinglePixelPackedSampleModel)image.getSampleModel();
    int scanlineStride = sm.getScanlineStride();
    Rectangle rect = image.getRaster().getBounds();
    // Note that we steal the data array here, but just for reading
    // so we do not need to mark the DataBuffer dirty...
    int[] data = SunWritableRaster.stealData((DataBufferInt)buf, 0);
    synchronized(SplashScreen.class) {
        checkVisible();
        _update(splashPtr, data, rect.x, rect.y, rect.width, rect.height, scanlineStride);
    }
}
 
Example 3
Source File: SplashScreen.java    From Bytecoder with Apache License 2.0 5 votes vote down vote up
/**
 * Updates the splash window with current contents of the overlay image.
 *
 * @throws IllegalStateException if the overlay image does not exist;
 *         for example, if {@code createGraphics} has never been called,
 *         or if the splash screen has already been closed
 */
public void update() throws IllegalStateException {
    BufferedImage image;
    synchronized (SplashScreen.class) {
        checkVisible();
        image = this.image;
    }
    if (image == null) {
        throw new IllegalStateException("no overlay image available");
    }
    DataBuffer buf = image.getRaster().getDataBuffer();
    if (!(buf instanceof DataBufferInt)) {
        throw new AssertionError("Overlay image DataBuffer is of invalid type == "+buf.getClass().getName());
    }
    int numBanks = buf.getNumBanks();
    if (numBanks!=1) {
        throw new AssertionError("Invalid number of banks =="+numBanks+" in overlay image DataBuffer");
    }
    if (!(image.getSampleModel() instanceof SinglePixelPackedSampleModel)) {
        throw new AssertionError("Overlay image has invalid sample model == "+image.getSampleModel().getClass().getName());
    }
    SinglePixelPackedSampleModel sm = (SinglePixelPackedSampleModel)image.getSampleModel();
    int scanlineStride = sm.getScanlineStride();
    Rectangle rect = image.getRaster().getBounds();
    // Note that we steal the data array here, but just for reading
    // so we do not need to mark the DataBuffer dirty...
    int[] data = SunWritableRaster.stealData((DataBufferInt)buf, 0);
    synchronized(SplashScreen.class) {
        checkVisible();
        _update(splashPtr, data, rect.x, rect.y, rect.width, rect.height, scanlineStride);
    }
}
 
Example 4
Source File: CImage.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
private BufferedImage toImage(int srcWidth, int srcHeight, int dstWidth, int dstHeight) {
    final BufferedImage bimg = new BufferedImage(dstWidth, dstHeight, BufferedImage.TYPE_INT_ARGB_PRE);
    final DataBufferInt dbi = (DataBufferInt)bimg.getRaster().getDataBuffer();
    final int[] buffer = SunWritableRaster.stealData(dbi, 0);
    execute(ptr->nativeCopyNSImageIntoArray(ptr, buffer, srcWidth, srcHeight, dstWidth, dstHeight));
    SunWritableRaster.markDirty(dbi);
    return bimg;
}
 
Example 5
Source File: SplashScreen.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Updates the splash window with current contents of the overlay image.
 *
 * @throws IllegalStateException if the overlay image does not exist;
 *         for example, if {@code createGraphics} has never been called,
 *         or if the splash screen has already been closed
 */
public void update() throws IllegalStateException {
    BufferedImage image;
    synchronized (SplashScreen.class) {
        checkVisible();
        image = this.image;
    }
    if (image == null) {
        throw new IllegalStateException("no overlay image available");
    }
    DataBuffer buf = image.getRaster().getDataBuffer();
    if (!(buf instanceof DataBufferInt)) {
        throw new AssertionError("Overlay image DataBuffer is of invalid type == "+buf.getClass().getName());
    }
    int numBanks = buf.getNumBanks();
    if (numBanks!=1) {
        throw new AssertionError("Invalid number of banks =="+numBanks+" in overlay image DataBuffer");
    }
    if (!(image.getSampleModel() instanceof SinglePixelPackedSampleModel)) {
        throw new AssertionError("Overlay image has invalid sample model == "+image.getSampleModel().getClass().getName());
    }
    SinglePixelPackedSampleModel sm = (SinglePixelPackedSampleModel)image.getSampleModel();
    int scanlineStride = sm.getScanlineStride();
    Rectangle rect = image.getRaster().getBounds();
    // Note that we steal the data array here, but just for reading
    // so we do not need to mark the DataBuffer dirty...
    int[] data = SunWritableRaster.stealData((DataBufferInt)buf, 0);
    synchronized(SplashScreen.class) {
        checkVisible();
        _update(splashPtr, data, rect.x, rect.y, rect.width, rect.height, scanlineStride);
    }
}
 
Example 6
Source File: CImage.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
private BufferedImage toImage(int srcWidth, int srcHeight, int dstWidth, int dstHeight) {
    final BufferedImage bimg = new BufferedImage(dstWidth, dstHeight, BufferedImage.TYPE_INT_ARGB_PRE);
    final DataBufferInt dbi = (DataBufferInt)bimg.getRaster().getDataBuffer();
    final int[] buffer = SunWritableRaster.stealData(dbi, 0);
    execute(ptr->nativeCopyNSImageIntoArray(ptr, buffer, srcWidth, srcHeight, dstWidth, dstHeight));
    SunWritableRaster.markDirty(dbi);
    return bimg;
}
 
Example 7
Source File: CImage.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
/** @return A BufferedImage created from nsImagePtr, or null. */
public BufferedImage toImage() {
    if (ptr == 0) return null;

    final Dimension2D size = nativeGetNSImageSize(ptr);
    final int w = (int)size.getWidth();
    final int h = (int)size.getHeight();

    final BufferedImage bimg = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB_PRE);
    final DataBufferInt dbi = (DataBufferInt)bimg.getRaster().getDataBuffer();
    final int[] buffer = SunWritableRaster.stealData(dbi, 0);
    nativeCopyNSImageIntoArray(ptr, buffer, w, h);
    SunWritableRaster.markDirty(dbi);
    return bimg;
}
 
Example 8
Source File: SplashScreen.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Updates the splash window with current contents of the overlay image.
 *
 * @throws IllegalStateException if the overlay image does not exist;
 *         for example, if {@code createGraphics} has never been called,
 *         or if the splash screen has already been closed
 */
public void update() throws IllegalStateException {
    BufferedImage image;
    synchronized (SplashScreen.class) {
        checkVisible();
        image = this.image;
    }
    if (image == null) {
        throw new IllegalStateException("no overlay image available");
    }
    DataBuffer buf = image.getRaster().getDataBuffer();
    if (!(buf instanceof DataBufferInt)) {
        throw new AssertionError("Overlay image DataBuffer is of invalid type == "+buf.getClass().getName());
    }
    int numBanks = buf.getNumBanks();
    if (numBanks!=1) {
        throw new AssertionError("Invalid number of banks =="+numBanks+" in overlay image DataBuffer");
    }
    if (!(image.getSampleModel() instanceof SinglePixelPackedSampleModel)) {
        throw new AssertionError("Overlay image has invalid sample model == "+image.getSampleModel().getClass().getName());
    }
    SinglePixelPackedSampleModel sm = (SinglePixelPackedSampleModel)image.getSampleModel();
    int scanlineStride = sm.getScanlineStride();
    Rectangle rect = image.getRaster().getBounds();
    // Note that we steal the data array here, but just for reading
    // so we do not need to mark the DataBuffer dirty...
    int[] data = SunWritableRaster.stealData((DataBufferInt)buf, 0);
    synchronized(SplashScreen.class) {
        checkVisible();
        _update(splashPtr, data, rect.x, rect.y, rect.width, rect.height, scanlineStride);
    }
}
 
Example 9
Source File: SplashScreen.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Updates the splash window with current contents of the overlay image.
 *
 * @throws IllegalStateException if the overlay image does not exist;
 *         for example, if {@code createGraphics} has never been called,
 *         or if the splash screen has already been closed
 */
public void update() throws IllegalStateException {
    BufferedImage image;
    synchronized (SplashScreen.class) {
        checkVisible();
        image = this.image;
    }
    if (image == null) {
        throw new IllegalStateException("no overlay image available");
    }
    DataBuffer buf = image.getRaster().getDataBuffer();
    if (!(buf instanceof DataBufferInt)) {
        throw new AssertionError("Overlay image DataBuffer is of invalid type == "+buf.getClass().getName());
    }
    int numBanks = buf.getNumBanks();
    if (numBanks!=1) {
        throw new AssertionError("Invalid number of banks =="+numBanks+" in overlay image DataBuffer");
    }
    if (!(image.getSampleModel() instanceof SinglePixelPackedSampleModel)) {
        throw new AssertionError("Overlay image has invalid sample model == "+image.getSampleModel().getClass().getName());
    }
    SinglePixelPackedSampleModel sm = (SinglePixelPackedSampleModel)image.getSampleModel();
    int scanlineStride = sm.getScanlineStride();
    Rectangle rect = image.getRaster().getBounds();
    // Note that we steal the data array here, but just for reading
    // so we do not need to mark the DataBuffer dirty...
    int[] data = SunWritableRaster.stealData((DataBufferInt)buf, 0);
    synchronized(SplashScreen.class) {
        checkVisible();
        _update(splashPtr, data, rect.x, rect.y, rect.width, rect.height, scanlineStride);
    }
}
 
Example 10
Source File: SplashScreen.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Updates the splash window with current contents of the overlay image.
 *
 * @throws IllegalStateException if the overlay image does not exist;
 *         for example, if {@code createGraphics} has never been called,
 *         or if the splash screen has already been closed
 */
public void update() throws IllegalStateException {
    BufferedImage image;
    synchronized (SplashScreen.class) {
        checkVisible();
        image = this.image;
    }
    if (image == null) {
        throw new IllegalStateException("no overlay image available");
    }
    DataBuffer buf = image.getRaster().getDataBuffer();
    if (!(buf instanceof DataBufferInt)) {
        throw new AssertionError("Overlay image DataBuffer is of invalid type == "+buf.getClass().getName());
    }
    int numBanks = buf.getNumBanks();
    if (numBanks!=1) {
        throw new AssertionError("Invalid number of banks =="+numBanks+" in overlay image DataBuffer");
    }
    if (!(image.getSampleModel() instanceof SinglePixelPackedSampleModel)) {
        throw new AssertionError("Overlay image has invalid sample model == "+image.getSampleModel().getClass().getName());
    }
    SinglePixelPackedSampleModel sm = (SinglePixelPackedSampleModel)image.getSampleModel();
    int scanlineStride = sm.getScanlineStride();
    Rectangle rect = image.getRaster().getBounds();
    // Note that we steal the data array here, but just for reading
    // so we do not need to mark the DataBuffer dirty...
    int[] data = SunWritableRaster.stealData((DataBufferInt)buf, 0);
    synchronized(SplashScreen.class) {
        checkVisible();
        _update(splashPtr, data, rect.x, rect.y, rect.width, rect.height, scanlineStride);
    }
}
 
Example 11
Source File: CImage.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
private BufferedImage toImage(int srcWidth, int srcHeight, int dstWidth, int dstHeight) {
    final BufferedImage bimg = new BufferedImage(dstWidth, dstHeight, BufferedImage.TYPE_INT_ARGB_PRE);
    final DataBufferInt dbi = (DataBufferInt)bimg.getRaster().getDataBuffer();
    final int[] buffer = SunWritableRaster.stealData(dbi, 0);
    execute(ptr->nativeCopyNSImageIntoArray(ptr, buffer, srcWidth, srcHeight, dstWidth, dstHeight));
    SunWritableRaster.markDirty(dbi);
    return bimg;
}
 
Example 12
Source File: SplashScreen.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Updates the splash window with current contents of the overlay image.
 *
 * @throws IllegalStateException if the overlay image does not exist;
 *         for example, if {@code createGraphics} has never been called,
 *         or if the splash screen has already been closed
 */
public void update() throws IllegalStateException {
    BufferedImage image;
    synchronized (SplashScreen.class) {
        checkVisible();
        image = this.image;
    }
    if (image == null) {
        throw new IllegalStateException("no overlay image available");
    }
    DataBuffer buf = image.getRaster().getDataBuffer();
    if (!(buf instanceof DataBufferInt)) {
        throw new AssertionError("Overlay image DataBuffer is of invalid type == "+buf.getClass().getName());
    }
    int numBanks = buf.getNumBanks();
    if (numBanks!=1) {
        throw new AssertionError("Invalid number of banks =="+numBanks+" in overlay image DataBuffer");
    }
    if (!(image.getSampleModel() instanceof SinglePixelPackedSampleModel)) {
        throw new AssertionError("Overlay image has invalid sample model == "+image.getSampleModel().getClass().getName());
    }
    SinglePixelPackedSampleModel sm = (SinglePixelPackedSampleModel)image.getSampleModel();
    int scanlineStride = sm.getScanlineStride();
    Rectangle rect = image.getRaster().getBounds();
    // Note that we steal the data array here, but just for reading
    // so we do not need to mark the DataBuffer dirty...
    int[] data = SunWritableRaster.stealData((DataBufferInt)buf, 0);
    synchronized(SplashScreen.class) {
        checkVisible();
        _update(splashPtr, data, rect.x, rect.y, rect.width, rect.height, scanlineStride);
    }
}
 
Example 13
Source File: CImage.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
private BufferedImage toImage(int srcWidth, int srcHeight, int dstWidth, int dstHeight) {
    final BufferedImage bimg = new BufferedImage(dstWidth, dstHeight, BufferedImage.TYPE_INT_ARGB_PRE);
    final DataBufferInt dbi = (DataBufferInt)bimg.getRaster().getDataBuffer();
    final int[] buffer = SunWritableRaster.stealData(dbi, 0);
    execute(ptr->nativeCopyNSImageIntoArray(ptr, buffer, srcWidth, srcHeight, dstWidth, dstHeight));
    SunWritableRaster.markDirty(dbi);
    return bimg;
}
 
Example 14
Source File: CImage.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
private BufferedImage toImage(int srcWidth, int srcHeight, int dstWidth, int dstHeight) {
    final BufferedImage bimg = new BufferedImage(dstWidth, dstHeight, BufferedImage.TYPE_INT_ARGB_PRE);
    final DataBufferInt dbi = (DataBufferInt)bimg.getRaster().getDataBuffer();
    final int[] buffer = SunWritableRaster.stealData(dbi, 0);
    execute(ptr->nativeCopyNSImageIntoArray(ptr, buffer, srcWidth, srcHeight, dstWidth, dstHeight));
    SunWritableRaster.markDirty(dbi);
    return bimg;
}
 
Example 15
Source File: SplashScreen.java    From jdk-1.7-annotated with Apache License 2.0 5 votes vote down vote up
/**
 * Updates the splash window with current contents of the overlay image.
 *
 * @throws IllegalStateException if the overlay image does not exist;
 *         for example, if {@code createGraphics} has never been called,
 *         or if the splash screen has already been closed
 */
public void update() throws IllegalStateException {
    BufferedImage image;
    synchronized (SplashScreen.class) {
        checkVisible();
        image = this.image;
    }
    if (image == null) {
        throw new IllegalStateException("no overlay image available");
    }
    DataBuffer buf = image.getRaster().getDataBuffer();
    if (!(buf instanceof DataBufferInt)) {
        throw new AssertionError("Overlay image DataBuffer is of invalid type == "+buf.getClass().getName());
    }
    int numBanks = buf.getNumBanks();
    if (numBanks!=1) {
        throw new AssertionError("Invalid number of banks =="+numBanks+" in overlay image DataBuffer");
    }
    if (!(image.getSampleModel() instanceof SinglePixelPackedSampleModel)) {
        throw new AssertionError("Overlay image has invalid sample model == "+image.getSampleModel().getClass().getName());
    }
    SinglePixelPackedSampleModel sm = (SinglePixelPackedSampleModel)image.getSampleModel();
    int scanlineStride = sm.getScanlineStride();
    Rectangle rect = image.getRaster().getBounds();
    // Note that we steal the data array here, but just for reading
    // so we do not need to mark the DataBuffer dirty...
    int[] data = SunWritableRaster.stealData((DataBufferInt)buf, 0);
    synchronized(SplashScreen.class) {
        checkVisible();
        _update(splashPtr, data, rect.x, rect.y, rect.width, rect.height, scanlineStride);
    }
}
 
Example 16
Source File: PathGraphics.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * 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;
}
 
Example 17
Source File: PathGraphics.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
/**
 * 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;
}
 
Example 18
Source File: PathGraphics.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
/**
 * 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;
}
 
Example 19
Source File: PathGraphics.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
/**
 * 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;
}
 
Example 20
Source File: PathGraphics.java    From Bytecoder with Apache License 2.0 4 votes vote down vote up
/**
 * 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;
}