Java Code Examples for java.awt.image.ColorModel#OPAQUE

The following examples show how to use java.awt.image.ColorModel#OPAQUE . 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: LosslessFactoryTest.java    From sambox with Apache License 2.0 6 votes vote down vote up
public void testCreateLosslessFrom16Bit() throws IOException
{
    PDDocument document = new PDDocument();
    BufferedImage image = ImageIO.read(this.getClass().getResourceAsStream("png.png"));

    ColorSpace targetCS = ColorSpace.getInstance(ColorSpace.CS_sRGB);
    int dataBufferType = DataBuffer.TYPE_USHORT;
    final ColorModel colorModel = new ComponentColorModel(targetCS, false, false,
            ColorModel.OPAQUE, dataBufferType);
    WritableRaster targetRaster = Raster.createInterleavedRaster(dataBufferType,
            image.getWidth(), image.getHeight(), targetCS.getNumComponents(), new Point(0, 0));
    BufferedImage img16Bit = new BufferedImage(colorModel, targetRaster, false,
            new Hashtable());
    ColorConvertOp op = new ColorConvertOp(image.getColorModel().getColorSpace(), targetCS,
            null);
    op.filter(image, img16Bit);

    PDImageXObject ximage = LosslessFactory.createFromImage(img16Bit);
    validate(ximage, 16, img16Bit.getWidth(), img16Bit.getHeight(), "png",
            PDDeviceRGB.INSTANCE.getName());
    checkIdent(image, ximage.getImage());
    doWritePDF(document, ximage, testResultsDir, "misc-16bit.pdf");
}
 
Example 2
Source File: JFIFMarkerSegment.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
BufferedImage getThumbnail(ImageInputStream iis,
                           JPEGImageReader reader)
    throws IOException {
    iis.mark();
    iis.seek(streamPos);
    DataBufferByte buffer = new DataBufferByte(getLength());
    readByteBuffer(iis,
                   buffer.getData(),
                   reader,
                   1.0F,
                   0.0F);
    iis.reset();

    WritableRaster raster =
        Raster.createInterleavedRaster(buffer,
                                       thumbWidth,
                                       thumbHeight,
                                       thumbWidth*3,
                                       3,
                                       new int [] {0, 1, 2},
                                       null);
    ColorModel cm = new ComponentColorModel(JPEG.JCS.sRGB,
                                            false,
                                            false,
                                            ColorModel.OPAQUE,
                                            DataBuffer.TYPE_BYTE);
    return new BufferedImage(cm,
                             raster,
                             false,
                             null);
}
 
Example 3
Source File: JFIFMarkerSegment.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
BufferedImage getThumbnail(ImageInputStream iis,
                           JPEGImageReader reader)
    throws IOException {
    iis.mark();
    iis.seek(streamPos);
    DataBufferByte buffer = new DataBufferByte(getLength());
    readByteBuffer(iis,
                   buffer.getData(),
                   reader,
                   1.0F,
                   0.0F);
    iis.reset();

    WritableRaster raster =
        Raster.createInterleavedRaster(buffer,
                                       thumbWidth,
                                       thumbHeight,
                                       thumbWidth*3,
                                       3,
                                       new int [] {0, 1, 2},
                                       null);
    ColorModel cm = new ComponentColorModel(JPEG.JCS.sRGB,
                                            false,
                                            false,
                                            ColorModel.OPAQUE,
                                            DataBuffer.TYPE_BYTE);
    return new BufferedImage(cm,
                             raster,
                             false,
                             null);
}
 
Example 4
Source File: JFIFMarkerSegment.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
BufferedImage getThumbnail(ImageInputStream iis,
                           JPEGImageReader reader)
    throws IOException {
    iis.mark();
    iis.seek(streamPos);
    DataBufferByte buffer = new DataBufferByte(getLength());
    readByteBuffer(iis,
                   buffer.getData(),
                   reader,
                   1.0F,
                   0.0F);
    iis.reset();

    WritableRaster raster =
        Raster.createInterleavedRaster(buffer,
                                       thumbWidth,
                                       thumbHeight,
                                       thumbWidth*3,
                                       3,
                                       new int [] {0, 1, 2},
                                       null);
    ColorModel cm = new ComponentColorModel(JPEG.JCS.sRGB,
                                            false,
                                            false,
                                            ColorModel.OPAQUE,
                                            DataBuffer.TYPE_BYTE);
    return new BufferedImage(cm,
                             raster,
                             false,
                             null);
}
 
Example 5
Source File: JFIFMarkerSegment.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
BufferedImage getThumbnail(ImageInputStream iis,
                           JPEGImageReader reader)
    throws IOException {
    iis.mark();
    iis.seek(streamPos);
    DataBufferByte buffer = new DataBufferByte(getLength());
    readByteBuffer(iis,
                   buffer.getData(),
                   reader,
                   1.0F,
                   0.0F);
    iis.reset();

    WritableRaster raster =
        Raster.createInterleavedRaster(buffer,
                                       thumbWidth,
                                       thumbHeight,
                                       thumbWidth*3,
                                       3,
                                       new int [] {0, 1, 2},
                                       null);
    ColorModel cm = new ComponentColorModel(JPEG.JCS.sRGB,
                                            false,
                                            false,
                                            ColorModel.OPAQUE,
                                            DataBuffer.TYPE_BYTE);
    return new BufferedImage(cm,
                             raster,
                             false,
                             null);
}
 
Example 6
Source File: JFIFMarkerSegment.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
BufferedImage getThumbnail(ImageInputStream iis,
                           JPEGImageReader reader)
    throws IOException {
    iis.mark();
    iis.seek(streamPos);
    DataBufferByte buffer = new DataBufferByte(getLength());
    readByteBuffer(iis,
                   buffer.getData(),
                   reader,
                   1.0F,
                   0.0F);
    iis.reset();

    WritableRaster raster =
        Raster.createInterleavedRaster(buffer,
                                       thumbWidth,
                                       thumbHeight,
                                       thumbWidth*3,
                                       3,
                                       new int [] {0, 1, 2},
                                       null);
    ColorModel cm = new ComponentColorModel(JPEG.JCS.sRGB,
                                            false,
                                            false,
                                            ColorModel.OPAQUE,
                                            DataBuffer.TYPE_BYTE);
    return new BufferedImage(cm,
                             raster,
                             false,
                             null);
}
 
Example 7
Source File: JFIFMarkerSegment.java    From JDKSourceCode1.8 with MIT License 5 votes vote down vote up
BufferedImage getThumbnail(ImageInputStream iis,
                           JPEGImageReader reader)
    throws IOException {
    iis.mark();
    iis.seek(streamPos);
    DataBufferByte buffer = new DataBufferByte(getLength());
    readByteBuffer(iis,
                   buffer.getData(),
                   reader,
                   1.0F,
                   0.0F);
    iis.reset();

    WritableRaster raster =
        Raster.createInterleavedRaster(buffer,
                                       thumbWidth,
                                       thumbHeight,
                                       thumbWidth*3,
                                       3,
                                       new int [] {0, 1, 2},
                                       null);
    ColorModel cm = new ComponentColorModel(JPEG.JCS.sRGB,
                                            false,
                                            false,
                                            ColorModel.OPAQUE,
                                            DataBuffer.TYPE_BYTE);
    return new BufferedImage(cm,
                             raster,
                             false,
                             null);
}
 
Example 8
Source File: JFIFMarkerSegment.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
BufferedImage getThumbnail(ImageInputStream iis,
                           JPEGImageReader reader)
    throws IOException {
    iis.mark();
    iis.seek(streamPos);
    DataBufferByte buffer = new DataBufferByte(getLength());
    readByteBuffer(iis,
                   buffer.getData(),
                   reader,
                   1.0F,
                   0.0F);
    iis.reset();

    WritableRaster raster =
        Raster.createInterleavedRaster(buffer,
                                       thumbWidth,
                                       thumbHeight,
                                       thumbWidth*3,
                                       3,
                                       new int [] {0, 1, 2},
                                       null);
    ColorModel cm = new ComponentColorModel(JPEG.JCS.sRGB,
                                            false,
                                            false,
                                            ColorModel.OPAQUE,
                                            DataBuffer.TYPE_BYTE);
    return new BufferedImage(cm,
                             raster,
                             false,
                             null);
}
 
Example 9
Source File: JFIFMarkerSegment.java    From jdk1.8-source-analysis with Apache License 2.0 5 votes vote down vote up
BufferedImage getThumbnail(ImageInputStream iis,
                           JPEGImageReader reader)
    throws IOException {
    iis.mark();
    iis.seek(streamPos);
    DataBufferByte buffer = new DataBufferByte(getLength());
    readByteBuffer(iis,
                   buffer.getData(),
                   reader,
                   1.0F,
                   0.0F);
    iis.reset();

    WritableRaster raster =
        Raster.createInterleavedRaster(buffer,
                                       thumbWidth,
                                       thumbHeight,
                                       thumbWidth*3,
                                       3,
                                       new int [] {0, 1, 2},
                                       null);
    ColorModel cm = new ComponentColorModel(JPEG.JCS.sRGB,
                                            false,
                                            false,
                                            ColorModel.OPAQUE,
                                            DataBuffer.TYPE_BYTE);
    return new BufferedImage(cm,
                             raster,
                             false,
                             null);
}
 
Example 10
Source File: JFIFMarkerSegment.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
BufferedImage getThumbnail(ImageInputStream iis,
                           JPEGImageReader reader)
    throws IOException {
    iis.mark();
    iis.seek(streamPos);
    DataBufferByte buffer = new DataBufferByte(getLength());
    readByteBuffer(iis,
                   buffer.getData(),
                   reader,
                   1.0F,
                   0.0F);
    iis.reset();

    WritableRaster raster =
        Raster.createInterleavedRaster(buffer,
                                       thumbWidth,
                                       thumbHeight,
                                       thumbWidth*3,
                                       3,
                                       new int [] {0, 1, 2},
                                       null);
    ColorModel cm = new ComponentColorModel(JPEG.JCS.sRGB,
                                            false,
                                            false,
                                            ColorModel.OPAQUE,
                                            DataBuffer.TYPE_BYTE);
    return new BufferedImage(cm,
                             raster,
                             false,
                             null);
}
 
Example 11
Source File: JFIFMarkerSegment.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
BufferedImage getThumbnail(ImageInputStream iis,
                           JPEGImageReader reader)
    throws IOException {
    iis.mark();
    iis.seek(streamPos);
    DataBufferByte buffer = new DataBufferByte(getLength());
    readByteBuffer(iis,
                   buffer.getData(),
                   reader,
                   1.0F,
                   0.0F);
    iis.reset();

    WritableRaster raster =
        Raster.createInterleavedRaster(buffer,
                                       thumbWidth,
                                       thumbHeight,
                                       thumbWidth*3,
                                       3,
                                       new int [] {0, 1, 2},
                                       null);
    ColorModel cm = new ComponentColorModel(JPEG.JCS.sRGB,
                                            false,
                                            false,
                                            ColorModel.OPAQUE,
                                            DataBuffer.TYPE_BYTE);
    return new BufferedImage(cm,
                             raster,
                             false,
                             null);
}
 
Example 12
Source File: JFIFMarkerSegment.java    From Bytecoder with Apache License 2.0 5 votes vote down vote up
BufferedImage getThumbnail(ImageInputStream iis,
                           JPEGImageReader reader)
    throws IOException {
    iis.mark();
    iis.seek(streamPos);
    DataBufferByte buffer = new DataBufferByte(getLength());
    readByteBuffer(iis,
                   buffer.getData(),
                   reader,
                   1.0F,
                   0.0F);
    iis.reset();

    WritableRaster raster =
        Raster.createInterleavedRaster(buffer,
                                       thumbWidth,
                                       thumbHeight,
                                       thumbWidth*3,
                                       3,
                                       new int [] {0, 1, 2},
                                       null);
    ColorModel cm = new ComponentColorModel(JPEG.JCS.sRGB,
                                            false,
                                            false,
                                            ColorModel.OPAQUE,
                                            DataBuffer.TYPE_BYTE);
    return new BufferedImage(cm,
                             raster,
                             false,
                             null);
}
 
Example 13
Source File: PathGraphics.java    From jdk8u-dev-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 14
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 15
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 16
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;
}
 
Example 17
Source File: PathGraphics.java    From openjdk-jdk8u 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 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 19
Source File: PathGraphics.java    From jdk8u60 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 dragonwell8_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;
}