Java Code Examples for java.awt.image.ColorModel#getTransparency()
The following examples show how to use
java.awt.image.ColorModel#getTransparency() .
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: RenderableUtil.java From jasperreports with GNU Lesser General Public License v3.0 | 6 votes |
/** * */ public Renderable getRenderable(Image img, OnErrorTypeEnum onErrorType) throws JRException { ImageTypeEnum type = ImageTypeEnum.JPEG; if (img instanceof RenderedImage) { ColorModel colorModel = ((RenderedImage) img).getColorModel(); //if the image has transparency, encode as PNG if (colorModel.hasAlpha() && colorModel.getTransparency() != Transparency.OPAQUE) { type = ImageTypeEnum.PNG; } } return getRenderable(img, type, onErrorType); }
Example 2
Source File: TexturePaintContext.java From dragonwell8_jdk with GNU General Public License v2.0 | 5 votes |
public ByteFilter(ByteInterleavedRaster srcRas, ColorModel cm, AffineTransform xform, int maxw) { super((cm.getTransparency() == Transparency.OPAQUE ? xrgbmodel : argbmodel), xform, srcRas.getWidth(), srcRas.getHeight(), maxw); this.inPalette = new int[256]; ((IndexColorModel) cm).getRGBs(this.inPalette); this.srcRas = srcRas; this.inData = srcRas.getDataStorage(); this.inSpan = srcRas.getScanlineStride(); this.inOff = srcRas.getDataOffset(0); }
Example 3
Source File: TexturePaintContext.java From jdk8u-jdk with GNU General Public License v2.0 | 5 votes |
public ByteFilter(ByteInterleavedRaster srcRas, ColorModel cm, AffineTransform xform, int maxw) { super((cm.getTransparency() == Transparency.OPAQUE ? xrgbmodel : argbmodel), xform, srcRas.getWidth(), srcRas.getHeight(), maxw); this.inPalette = new int[256]; ((IndexColorModel) cm).getRGBs(this.inPalette); this.srcRas = srcRas; this.inData = srcRas.getDataStorage(); this.inSpan = srcRas.getScanlineStride(); this.inOff = srcRas.getDataOffset(0); }
Example 4
Source File: TexturePaintContext.java From jdk8u-jdk with GNU General Public License v2.0 | 5 votes |
public ByteFilter(ByteInterleavedRaster srcRas, ColorModel cm, AffineTransform xform, int maxw) { super((cm.getTransparency() == Transparency.OPAQUE ? xrgbmodel : argbmodel), xform, srcRas.getWidth(), srcRas.getHeight(), maxw); this.inPalette = new int[256]; ((IndexColorModel) cm).getRGBs(this.inPalette); this.srcRas = srcRas; this.inData = srcRas.getDataStorage(); this.inSpan = srcRas.getScanlineStride(); this.inOff = srcRas.getDataOffset(0); }
Example 5
Source File: TexturePaintContext.java From jdk8u_jdk with GNU General Public License v2.0 | 5 votes |
public ByteFilter(ByteInterleavedRaster srcRas, ColorModel cm, AffineTransform xform, int maxw) { super((cm.getTransparency() == Transparency.OPAQUE ? xrgbmodel : argbmodel), xform, srcRas.getWidth(), srcRas.getHeight(), maxw); this.inPalette = new int[256]; ((IndexColorModel) cm).getRGBs(this.inPalette); this.srcRas = srcRas; this.inData = srcRas.getDataStorage(); this.inSpan = srcRas.getScanlineStride(); this.inOff = srcRas.getDataOffset(0); }
Example 6
Source File: TexturePaintContext.java From openjdk-8 with GNU General Public License v2.0 | 5 votes |
public ByteFilter(ByteInterleavedRaster srcRas, ColorModel cm, AffineTransform xform, int maxw) { super((cm.getTransparency() == Transparency.OPAQUE ? xrgbmodel : argbmodel), xform, srcRas.getWidth(), srcRas.getHeight(), maxw); this.inPalette = new int[256]; ((IndexColorModel) cm).getRGBs(this.inPalette); this.srcRas = srcRas; this.inData = srcRas.getDataStorage(); this.inSpan = srcRas.getScanlineStride(); this.inOff = srcRas.getDataOffset(0); }
Example 7
Source File: D3DSurfaceData.java From jdk8u-dev-jdk with GNU General Public License v2.0 | 5 votes |
/** * Creates a SurfaceData object representing an off-screen buffer (either * a plain surface or Texture). */ public static D3DSurfaceData createData(D3DGraphicsConfig gc, int width, int height, ColorModel cm, Image image, int type) { if (type == RT_TEXTURE) { boolean isOpaque = cm.getTransparency() == Transparency.OPAQUE; int cap = isOpaque ? CAPS_RT_TEXTURE_OPAQUE : CAPS_RT_TEXTURE_ALPHA; if (!gc.getD3DDevice().isCapPresent(cap)) { type = RT_PLAIN; } } D3DSurfaceData ret = null; try { ret = new D3DSurfaceData(null, gc, width, height, image, cm, 0, SWAP_DISCARD, VSYNC_DEFAULT, type); } catch (InvalidPipeException ipe) { // try again - we might have ran out of vram, and rt textures // could take up more than a plain surface, so it might succeed if (type == RT_TEXTURE) { // If a RT_TEXTURE was requested do not attempt to create a // plain surface. (note that RT_TEXTURE can only be requested // from a VI so the cast is safe) if (((SunVolatileImage)image).getForcedAccelSurfaceType() != RT_TEXTURE) { type = RT_PLAIN; ret = new D3DSurfaceData(null, gc, width, height, image, cm, 0, SWAP_DISCARD, VSYNC_DEFAULT, type); } } } return ret; }
Example 8
Source File: TexturePaintContext.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 5 votes |
public ByteFilter(ByteInterleavedRaster srcRas, ColorModel cm, AffineTransform xform, int maxw) { super((cm.getTransparency() == Transparency.OPAQUE ? xrgbmodel : argbmodel), xform, srcRas.getWidth(), srcRas.getHeight(), maxw); this.inPalette = new int[256]; ((IndexColorModel) cm).getRGBs(this.inPalette); this.srcRas = srcRas; this.inData = srcRas.getDataStorage(); this.inSpan = srcRas.getScanlineStride(); this.inOff = srcRas.getDataOffset(0); }
Example 9
Source File: D3DSurfaceData.java From jdk8u-jdk with GNU General Public License v2.0 | 5 votes |
/** * Creates a SurfaceData object representing an off-screen buffer (either * a plain surface or Texture). */ public static D3DSurfaceData createData(D3DGraphicsConfig gc, int width, int height, ColorModel cm, Image image, int type) { if (type == RT_TEXTURE) { boolean isOpaque = cm.getTransparency() == Transparency.OPAQUE; int cap = isOpaque ? CAPS_RT_TEXTURE_OPAQUE : CAPS_RT_TEXTURE_ALPHA; if (!gc.getD3DDevice().isCapPresent(cap)) { type = RT_PLAIN; } } D3DSurfaceData ret = null; try { ret = new D3DSurfaceData(null, gc, width, height, image, cm, 0, SWAP_DISCARD, VSYNC_DEFAULT, type); } catch (InvalidPipeException ipe) { // try again - we might have ran out of vram, and rt textures // could take up more than a plain surface, so it might succeed if (type == RT_TEXTURE) { // If a RT_TEXTURE was requested do not attempt to create a // plain surface. (note that RT_TEXTURE can only be requested // from a VI so the cast is safe) if (((SunVolatileImage)image).getForcedAccelSurfaceType() != RT_TEXTURE) { type = RT_PLAIN; ret = new D3DSurfaceData(null, gc, width, height, image, cm, 0, SWAP_DISCARD, VSYNC_DEFAULT, type); } } } return ret; }
Example 10
Source File: PathGraphics.java From openjdk-jdk9 with GNU General Public License v2.0 | 4 votes |
/** * 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 11
Source File: X11SurfaceDataProxy.java From jdk8u60 with GNU General Public License v2.0 | 4 votes |
public static SurfaceDataProxy createProxy(SurfaceData srcData, X11GraphicsConfig dstConfig) { if (srcData instanceof X11SurfaceData) { // srcData must be a VolatileImage which either matches // our visual or not - either way we do not cache it... return UNCACHED; } ColorModel cm = srcData.getColorModel(); int transparency = cm.getTransparency(); if (transparency == Transparency.OPAQUE) { return new Opaque(dstConfig); } else if (transparency == Transparency.BITMASK) { // 4673490: updateBitmask() only handles ICMs with 8-bit indices if ((cm instanceof IndexColorModel) && cm.getPixelSize() == 8) { return new Bitmask(dstConfig); } // The only other ColorModel handled by updateBitmask() is // a DCM where the alpha bit, and only the alpha bit, is in // the top 8 bits if (cm instanceof DirectColorModel) { DirectColorModel dcm = (DirectColorModel) cm; int colormask = (dcm.getRedMask() | dcm.getGreenMask() | dcm.getBlueMask()); int alphamask = dcm.getAlphaMask(); if ((colormask & 0xff000000) == 0 && (alphamask & 0xff000000) != 0) { return new Bitmask(dstConfig); } } } // For whatever reason, this image is not a good candidate for // caching in a pixmap so we return the non-caching (non-)proxy. return UNCACHED; }
Example 12
Source File: X11SurfaceDataProxy.java From hottub with GNU General Public License v2.0 | 4 votes |
public static SurfaceDataProxy createProxy(SurfaceData srcData, X11GraphicsConfig dstConfig) { if (srcData instanceof X11SurfaceData) { // srcData must be a VolatileImage which either matches // our visual or not - either way we do not cache it... return UNCACHED; } ColorModel cm = srcData.getColorModel(); int transparency = cm.getTransparency(); if (transparency == Transparency.OPAQUE) { return new Opaque(dstConfig); } else if (transparency == Transparency.BITMASK) { // 4673490: updateBitmask() only handles ICMs with 8-bit indices if ((cm instanceof IndexColorModel) && cm.getPixelSize() == 8) { return new Bitmask(dstConfig); } // The only other ColorModel handled by updateBitmask() is // a DCM where the alpha bit, and only the alpha bit, is in // the top 8 bits if (cm instanceof DirectColorModel) { DirectColorModel dcm = (DirectColorModel) cm; int colormask = (dcm.getRedMask() | dcm.getGreenMask() | dcm.getBlueMask()); int alphamask = dcm.getAlphaMask(); if ((colormask & 0xff000000) == 0 && (alphamask & 0xff000000) != 0) { return new Bitmask(dstConfig); } } } // For whatever reason, this image is not a good candidate for // caching in a pixmap so we return the non-caching (non-)proxy. return UNCACHED; }
Example 13
Source File: X11SurfaceDataProxy.java From openjdk-jdk9 with GNU General Public License v2.0 | 4 votes |
public static SurfaceDataProxy createProxy(SurfaceData srcData, X11GraphicsConfig dstConfig) { if (srcData instanceof X11SurfaceData) { // srcData must be a VolatileImage which either matches // our visual or not - either way we do not cache it... return UNCACHED; } ColorModel cm = srcData.getColorModel(); int transparency = cm.getTransparency(); if (transparency == Transparency.OPAQUE) { return new Opaque(dstConfig); } else if (transparency == Transparency.BITMASK) { // 4673490: updateBitmask() only handles ICMs with 8-bit indices if ((cm instanceof IndexColorModel) && cm.getPixelSize() == 8) { return new Bitmask(dstConfig); } // The only other ColorModel handled by updateBitmask() is // a DCM where the alpha bit, and only the alpha bit, is in // the top 8 bits if (cm instanceof DirectColorModel) { DirectColorModel dcm = (DirectColorModel) cm; int colormask = (dcm.getRedMask() | dcm.getGreenMask() | dcm.getBlueMask()); int alphamask = dcm.getAlphaMask(); if ((colormask & 0xff000000) == 0 && (alphamask & 0xff000000) != 0) { return new Bitmask(dstConfig); } } } // For whatever reason, this image is not a good candidate for // caching in a pixmap so we return the non-caching (non-)proxy. return UNCACHED; }
Example 14
Source File: X11SurfaceDataProxy.java From openjdk-jdk8u with GNU General Public License v2.0 | 4 votes |
public static SurfaceDataProxy createProxy(SurfaceData srcData, X11GraphicsConfig dstConfig) { if (srcData instanceof X11SurfaceData) { // srcData must be a VolatileImage which either matches // our visual or not - either way we do not cache it... return UNCACHED; } ColorModel cm = srcData.getColorModel(); int transparency = cm.getTransparency(); if (transparency == Transparency.OPAQUE) { return new Opaque(dstConfig); } else if (transparency == Transparency.BITMASK) { // 4673490: updateBitmask() only handles ICMs with 8-bit indices if ((cm instanceof IndexColorModel) && cm.getPixelSize() == 8) { return new Bitmask(dstConfig); } // The only other ColorModel handled by updateBitmask() is // a DCM where the alpha bit, and only the alpha bit, is in // the top 8 bits if (cm instanceof DirectColorModel) { DirectColorModel dcm = (DirectColorModel) cm; int colormask = (dcm.getRedMask() | dcm.getGreenMask() | dcm.getBlueMask()); int alphamask = dcm.getAlphaMask(); if ((colormask & 0xff000000) == 0 && (alphamask & 0xff000000) != 0) { return new Bitmask(dstConfig); } } } // For whatever reason, this image is not a good candidate for // caching in a pixmap so we return the non-caching (non-)proxy. return UNCACHED; }
Example 15
Source File: X11SurfaceDataProxy.java From jdk8u-dev-jdk with GNU General Public License v2.0 | 4 votes |
public static SurfaceDataProxy createProxy(SurfaceData srcData, X11GraphicsConfig dstConfig) { if (srcData instanceof X11SurfaceData) { // srcData must be a VolatileImage which either matches // our visual or not - either way we do not cache it... return UNCACHED; } ColorModel cm = srcData.getColorModel(); int transparency = cm.getTransparency(); if (transparency == Transparency.OPAQUE) { return new Opaque(dstConfig); } else if (transparency == Transparency.BITMASK) { // 4673490: updateBitmask() only handles ICMs with 8-bit indices if ((cm instanceof IndexColorModel) && cm.getPixelSize() == 8) { return new Bitmask(dstConfig); } // The only other ColorModel handled by updateBitmask() is // a DCM where the alpha bit, and only the alpha bit, is in // the top 8 bits if (cm instanceof DirectColorModel) { DirectColorModel dcm = (DirectColorModel) cm; int colormask = (dcm.getRedMask() | dcm.getGreenMask() | dcm.getBlueMask()); int alphamask = dcm.getAlphaMask(); if ((colormask & 0xff000000) == 0 && (alphamask & 0xff000000) != 0) { return new Bitmask(dstConfig); } } } // For whatever reason, this image is not a good candidate for // caching in a pixmap so we return the non-caching (non-)proxy. return UNCACHED; }
Example 16
Source File: ImageRepresentation.java From jdk8u-jdk with GNU General Public License v2.0 | 4 votes |
public void setColorModel(ColorModel model) { if (src != null) { src.checkSecurity(null, false); } srcModel = model; // Check to see if model is INT_RGB if (model instanceof IndexColorModel) { if (model.getTransparency() == model.TRANSLUCENT) { // REMIND: // Probably need to composite anyway so force ARGB cmodel = ColorModel.getRGBdefault(); srcLUT = null; } else { IndexColorModel icm = (IndexColorModel) model; numSrcLUT = icm.getMapSize(); srcLUT = new int[Math.max(numSrcLUT, 256)]; icm.getRGBs(srcLUT); srcLUTtransIndex = icm.getTransparentPixel(); cmodel = model; } } else { if (cmodel == null) { cmodel = model; srcLUT = null; } else if (model instanceof DirectColorModel) { // If it is INT_RGB or INT_ARGB, use the model DirectColorModel dcm = (DirectColorModel) model; if ((dcm.getRedMask() == 0xff0000) && (dcm.getGreenMask() == 0xff00) && (dcm.getBlueMask() == 0x00ff)) { cmodel = model; srcLUT = null; } } } isSameCM = (cmodel == model); }
Example 17
Source File: ImageRepresentation.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 4 votes |
public void setColorModel(ColorModel model) { if (src != null) { src.checkSecurity(null, false); } srcModel = model; // Check to see if model is INT_RGB if (model instanceof IndexColorModel) { if (model.getTransparency() == model.TRANSLUCENT) { // REMIND: // Probably need to composite anyway so force ARGB cmodel = ColorModel.getRGBdefault(); srcLUT = null; } else { IndexColorModel icm = (IndexColorModel) model; numSrcLUT = icm.getMapSize(); srcLUT = new int[Math.max(numSrcLUT, 256)]; icm.getRGBs(srcLUT); srcLUTtransIndex = icm.getTransparentPixel(); cmodel = model; } } else { if (cmodel == null) { cmodel = model; srcLUT = null; } else if (model instanceof DirectColorModel) { // If it is INT_RGB or INT_ARGB, use the model DirectColorModel dcm = (DirectColorModel) model; if ((dcm.getRedMask() == 0xff0000) && (dcm.getGreenMask() == 0xff00) && (dcm.getBlueMask() == 0x00ff)) { cmodel = model; srcLUT = null; } } } isSameCM = (cmodel == model); }
Example 18
Source File: PathGraphics.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 4 votes |
protected boolean isBitmaskTransparency(BufferedImage bufferedImage) { ColorModel colorModel = bufferedImage.getColorModel(); return (colorModel != null && colorModel.getTransparency() == ColorModel.BITMASK); }
Example 19
Source File: PathGraphics.java From TencentKona-8 with GNU General Public License v2.0 | 4 votes |
protected boolean isBitmaskTransparency(BufferedImage bufferedImage) { ColorModel colorModel = bufferedImage.getColorModel(); return (colorModel != null && colorModel.getTransparency() == ColorModel.BITMASK); }
Example 20
Source File: PathGraphics.java From openjdk-8-source with GNU General Public License v2.0 | 4 votes |
/** * 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; }