Java Code Examples for java.awt.image.ColorModel#getPixelSize()
The following examples show how to use
java.awt.image.ColorModel#getPixelSize() .
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: Picture.java From audiveris with GNU Affero General Public License v3.0 | 6 votes |
private BufferedImage checkImage (BufferedImage img) throws ImageFormatException { // Check image format img = adjustImageFormat(img); // Check pixel size and compute grayFactor accordingly ColorModel colorModel = img.getColorModel(); int pixelSize = colorModel.getPixelSize(); logger.debug("colorModel={} pixelSize={}", colorModel, pixelSize); // if (pixelSize == 1) { // grayFactor = 1; // } else if (pixelSize <= 8) { // grayFactor = (int) Math.rint(128 / Math.pow(2, pixelSize - 1)); // } else if (pixelSize <= 16) { // grayFactor = (int) Math.rint(32768 / Math.pow(2, pixelSize - 1)); // } else { // throw new RuntimeException("Unsupported pixel size: " + pixelSize); // } // // logger.debug("grayFactor={}", grayFactor); return img; }
Example 2
Source File: GenericImageSinglePassIterator.java From pumpernickel with MIT License | 6 votes |
/** * Determine if the argument uses one gray byte for storage. */ private boolean isGray(ColorModel model) { if (model.getTransferType() != DataBuffer.TYPE_BYTE || model.getPixelSize() != 8) return false; // There has to be a better way to do this, but I don't know what // that is... if (scratchArray == null || scratchArray.length < 1) { scratchArray = new byte[1]; } scratchArray[0] = (byte) (255); if (model.getRGB(scratchArray) != 0xffffffff) { return false; } scratchArray[0] = (byte) (0x88); if (model.getRGB(scratchArray) != 0xff888888) { return false; } scratchArray[0] = (byte) (0x00); if (model.getRGB(scratchArray) != 0xff000000) { return false; } return true; }
Example 3
Source File: GDIWindowSurfaceData.java From jdk8u-dev-jdk with GNU General Public License v2.0 | 5 votes |
private GDIWindowSurfaceData(WComponentPeer peer, SurfaceType sType) { super(sType, peer.getDeviceColorModel()); ColorModel cm = peer.getDeviceColorModel(); this.peer = peer; int rMask = 0, gMask = 0, bMask = 0; int depth; switch (cm.getPixelSize()) { case 32: case 24: if (cm instanceof DirectColorModel) { depth = 32; } else { depth = 24; } break; default: depth = cm.getPixelSize(); } if (cm instanceof DirectColorModel) { DirectColorModel dcm = (DirectColorModel)cm; rMask = dcm.getRedMask(); gMask = dcm.getGreenMask(); bMask = dcm.getBlueMask(); } this.graphicsConfig = (Win32GraphicsConfig) peer.getGraphicsConfiguration(); this.solidloops = graphicsConfig.getSolidLoops(sType); Win32GraphicsDevice gd = (Win32GraphicsDevice)graphicsConfig.getDevice(); initOps(peer, depth, rMask, gMask, bMask, gd.getScreen()); setBlitProxyKey(graphicsConfig.getProxyKey()); }
Example 4
Source File: GDIWindowSurfaceData.java From openjdk-jdk8u with GNU General Public License v2.0 | 5 votes |
private GDIWindowSurfaceData(WComponentPeer peer, SurfaceType sType) { super(sType, peer.getDeviceColorModel()); ColorModel cm = peer.getDeviceColorModel(); this.peer = peer; int rMask = 0, gMask = 0, bMask = 0; int depth; switch (cm.getPixelSize()) { case 32: case 24: if (cm instanceof DirectColorModel) { depth = 32; } else { depth = 24; } break; default: depth = cm.getPixelSize(); } if (cm instanceof DirectColorModel) { DirectColorModel dcm = (DirectColorModel)cm; rMask = dcm.getRedMask(); gMask = dcm.getGreenMask(); bMask = dcm.getBlueMask(); } this.graphicsConfig = (Win32GraphicsConfig) peer.getGraphicsConfiguration(); this.solidloops = graphicsConfig.getSolidLoops(sType); Win32GraphicsDevice gd = (Win32GraphicsDevice)graphicsConfig.getDevice(); initOps(peer, depth, rMask, gMask, bMask, gd.getScreen()); setBlitProxyKey(graphicsConfig.getProxyKey()); }
Example 5
Source File: Picture.java From libreveris with GNU Lesser General Public License v3.0 | 5 votes |
/** * Check if the image format (and especially its color model) is * properly handled by Audiveris. * * @throws ImageFormatException is the format is not supported */ private void checkImageFormat () throws ImageFormatException { ColorModel colorModel = image.getColorModel(); int pixelSize = colorModel.getPixelSize(); boolean hasAlpha = colorModel.hasAlpha(); logger.debug("{}", colorModel); if (pixelSize == 1) { ///image = binaryToGray(image); // Only if rotation is needed! implicitForeground = 0; } // Check nb of bands SampleModel sampleModel = image.getSampleModel(); int numBands = sampleModel.getNumBands(); logger.debug("numBands={}", numBands); if (numBands == 1) { // Pixel gray value. Nothing to do } else if ((numBands == 2) && hasAlpha) { // Pixel + alpha // Discard alpha (TODO: check if premultiplied!!!) image = JAI.create("bandselect", image, new int[]{}); } else if ((numBands == 3) && !hasAlpha) { // RGB image = RGBToGray(image); } else if ((numBands == 4) && hasAlpha) { // RGB + alpha image = RGBAToGray(image); } else { throw new ImageFormatException( "Unsupported sample model numBands=" + numBands); } }
Example 6
Source File: X11SurfaceData.java From dragonwell8_jdk with GNU General Public License v2.0 | 5 votes |
protected X11SurfaceData(X11ComponentPeer peer, X11GraphicsConfig gc, SurfaceType sType, ColorModel cm) { super(sType, cm); this.peer = peer; this.graphicsConfig = gc; this.solidloops = graphicsConfig.getSolidLoops(sType); this.depth = cm.getPixelSize(); initOps(peer, graphicsConfig, depth); if (isAccelerationEnabled()) { setBlitProxyKey(gc.getProxyKey()); } }
Example 7
Source File: GDIWindowSurfaceData.java From openjdk-8-source with GNU General Public License v2.0 | 5 votes |
private GDIWindowSurfaceData(WComponentPeer peer, SurfaceType sType) { super(sType, peer.getDeviceColorModel()); ColorModel cm = peer.getDeviceColorModel(); this.peer = peer; int rMask = 0, gMask = 0, bMask = 0; int depth; switch (cm.getPixelSize()) { case 32: case 24: if (cm instanceof DirectColorModel) { depth = 32; } else { depth = 24; } break; default: depth = cm.getPixelSize(); } if (cm instanceof DirectColorModel) { DirectColorModel dcm = (DirectColorModel)cm; rMask = dcm.getRedMask(); gMask = dcm.getGreenMask(); bMask = dcm.getBlueMask(); } this.graphicsConfig = (Win32GraphicsConfig) peer.getGraphicsConfiguration(); this.solidloops = graphicsConfig.getSolidLoops(sType); Win32GraphicsDevice gd = (Win32GraphicsDevice)graphicsConfig.getDevice(); initOps(peer, depth, rMask, gMask, bMask, gd.getScreen()); setBlitProxyKey(graphicsConfig.getProxyKey()); }
Example 8
Source File: X11SurfaceData.java From jdk8u-jdk with GNU General Public License v2.0 | 5 votes |
protected X11SurfaceData(X11ComponentPeer peer, X11GraphicsConfig gc, SurfaceType sType, ColorModel cm) { super(sType, cm); this.peer = peer; this.graphicsConfig = gc; this.solidloops = graphicsConfig.getSolidLoops(sType); this.depth = cm.getPixelSize(); initOps(peer, graphicsConfig, depth); if (isAccelerationEnabled()) { setBlitProxyKey(gc.getProxyKey()); } }
Example 9
Source File: X11SurfaceData.java From jdk8u-jdk with GNU General Public License v2.0 | 5 votes |
protected X11SurfaceData(X11ComponentPeer peer, X11GraphicsConfig gc, SurfaceType sType, ColorModel cm) { super(sType, cm); this.peer = peer; this.graphicsConfig = gc; this.solidloops = graphicsConfig.getSolidLoops(sType); this.depth = cm.getPixelSize(); initOps(peer, graphicsConfig, depth); if (isAccelerationEnabled()) { setBlitProxyKey(gc.getProxyKey()); } }
Example 10
Source File: GenericImageSinglePassIterator.java From pumpernickel with MIT License | 5 votes |
/** * Determine if the argument uses 3 BGR bytes for storage. */ private boolean isBGR(ColorModel model) { if (model.getTransferType() != DataBuffer.TYPE_BYTE || model.getPixelSize() != 24) return false; // There has to be a better way to do this, but I don't know what // that is... if (scratchArray == null || scratchArray.length < 3) { scratchArray = new byte[3]; } scratchArray[0] = (byte) (255); scratchArray[1] = (byte) (0); scratchArray[2] = (byte) (0); if (model.getRGB(scratchArray) != 0xffff0000) { return false; } scratchArray[0] = (byte) (0); scratchArray[1] = (byte) (255); scratchArray[2] = (byte) (0); if (model.getRGB(scratchArray) != 0xff00ff00) { return false; } scratchArray[0] = (byte) (0); scratchArray[1] = (byte) (0); scratchArray[2] = (byte) (255); if (model.getRGB(scratchArray) != 0xff0000ff) { return false; } return true; }
Example 11
Source File: GDIWindowSurfaceData.java From hottub with GNU General Public License v2.0 | 5 votes |
public static SurfaceType getSurfaceType(ColorModel cm) { switch (cm.getPixelSize()) { case 32: case 24: if (cm instanceof DirectColorModel) { if (((DirectColorModel)cm).getRedMask() == 0xff0000) { return IntRgbGdi; } else { return SurfaceType.IntRgbx; } } else { return ThreeByteBgrGdi; } case 15: return Ushort555RgbGdi; case 16: if ((cm instanceof DirectColorModel) && (((DirectColorModel)cm).getBlueMask() == 0x3e)) { return SurfaceType.Ushort555Rgbx; } else { return Ushort565RgbGdi; } case 8: if (cm.getColorSpace().getType() == ColorSpace.TYPE_GRAY && cm instanceof ComponentColorModel) { return SurfaceType.ByteGray; } else if (cm instanceof IndexColorModel && isOpaqueGray((IndexColorModel)cm)) { return SurfaceType.Index8Gray; } else { return SurfaceType.ByteIndexedOpaque; } default: throw new sun.java2d.InvalidPipeException("Unsupported bit " + "depth: " + cm.getPixelSize()); } }
Example 12
Source File: GDIWindowSurfaceData.java From jdk8u60 with GNU General Public License v2.0 | 5 votes |
private GDIWindowSurfaceData(WComponentPeer peer, SurfaceType sType) { super(sType, peer.getDeviceColorModel()); ColorModel cm = peer.getDeviceColorModel(); this.peer = peer; int rMask = 0, gMask = 0, bMask = 0; int depth; switch (cm.getPixelSize()) { case 32: case 24: if (cm instanceof DirectColorModel) { depth = 32; } else { depth = 24; } break; default: depth = cm.getPixelSize(); } if (cm instanceof DirectColorModel) { DirectColorModel dcm = (DirectColorModel)cm; rMask = dcm.getRedMask(); gMask = dcm.getGreenMask(); bMask = dcm.getBlueMask(); } this.graphicsConfig = (Win32GraphicsConfig) peer.getGraphicsConfiguration(); this.solidloops = graphicsConfig.getSolidLoops(sType); Win32GraphicsDevice gd = (Win32GraphicsDevice)graphicsConfig.getDevice(); initOps(peer, depth, rMask, gMask, bMask, gd.getScreen()); setBlitProxyKey(graphicsConfig.getProxyKey()); }
Example 13
Source File: X11SurfaceData.java From jdk8u_jdk with GNU General Public License v2.0 | 5 votes |
protected X11SurfaceData(X11ComponentPeer peer, X11GraphicsConfig gc, SurfaceType sType, ColorModel cm) { super(sType, cm); this.peer = peer; this.graphicsConfig = gc; this.solidloops = graphicsConfig.getSolidLoops(sType); this.depth = cm.getPixelSize(); initOps(peer, graphicsConfig, depth); if (isAccelerationEnabled()) { setBlitProxyKey(gc.getProxyKey()); } }
Example 14
Source File: GDIWindowSurfaceData.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
private GDIWindowSurfaceData(WComponentPeer peer, SurfaceType sType) { super(sType, peer.getDeviceColorModel()); ColorModel cm = peer.getDeviceColorModel(); this.peer = peer; int rMask = 0, gMask = 0, bMask = 0; int depth; switch (cm.getPixelSize()) { case 32: case 24: if (cm instanceof DirectColorModel) { depth = 32; } else { depth = 24; } break; default: depth = cm.getPixelSize(); } if (cm instanceof DirectColorModel) { DirectColorModel dcm = (DirectColorModel)cm; rMask = dcm.getRedMask(); gMask = dcm.getGreenMask(); bMask = dcm.getBlueMask(); } this.graphicsConfig = (Win32GraphicsConfig) peer.getGraphicsConfiguration(); this.solidloops = graphicsConfig.getSolidLoops(sType); Win32GraphicsDevice gd = graphicsConfig.getDevice(); scaleX = gd.getDefaultScaleX(); scaleY = gd.getDefaultScaleY(); initOps(peer, depth, rMask, gMask, bMask, gd.getScreen()); setBlitProxyKey(graphicsConfig.getProxyKey()); }
Example 15
Source File: X11SurfaceDataProxy.java From jdk8u-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: X11SurfaceDataProxy.java From TencentKona-8 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 17
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 18
Source File: X11SurfaceData.java From openjdk-8 with GNU General Public License v2.0 | 4 votes |
public static SurfaceType getSurfaceType(X11GraphicsConfig gc, int transparency, boolean pixmapSurface) { boolean transparent = (transparency == Transparency.BITMASK); SurfaceType sType; ColorModel cm = gc.getColorModel(); switch (cm.getPixelSize()) { case 24: if (gc.getBitsPerPixel() == 24) { if (cm instanceof DirectColorModel) { // 4517321: We will always use ThreeByteBgr for 24 bpp // surfaces, regardless of the pixel masks reported by // X11. Despite ambiguity in the X11 spec in how 24 bpp // surfaces are treated, it appears that the best // SurfaceType for these configurations (including // some Matrox Millenium and ATI Radeon boards) is // ThreeByteBgr. sType = transparent ? X11SurfaceData.ThreeByteBgrX11_BM : X11SurfaceData.ThreeByteBgrX11; } else { throw new sun.java2d.InvalidPipeException("Unsupported bit " + "depth/cm combo: " + cm.getPixelSize() + ", " + cm); } break; } // Fall through for 32 bit case case 32: if (cm instanceof DirectColorModel) { if (((SunToolkit)java.awt.Toolkit.getDefaultToolkit() ).isTranslucencyCapable(gc) && !pixmapSurface) { sType = X11SurfaceData.IntArgbPreX11; } else { if (((DirectColorModel)cm).getRedMask() == 0xff0000) { sType = transparent ? X11SurfaceData.IntRgbX11_BM : X11SurfaceData.IntRgbX11; } else { sType = transparent ? X11SurfaceData.IntBgrX11_BM : X11SurfaceData.IntBgrX11; } } } else if (cm instanceof ComponentColorModel) { sType = X11SurfaceData.FourByteAbgrPreX11; } else { throw new sun.java2d.InvalidPipeException("Unsupported bit " + "depth/cm combo: " + cm.getPixelSize() + ", " + cm); } break; case 15: sType = transparent ? X11SurfaceData.UShort555RgbX11_BM : X11SurfaceData.UShort555RgbX11; break; case 16: if ((cm instanceof DirectColorModel) && (((DirectColorModel)cm).getGreenMask() == 0x3e0)) { // fix for 4352984: Riva128 on Linux sType = transparent ? X11SurfaceData.UShort555RgbX11_BM : X11SurfaceData.UShort555RgbX11; } else { sType = transparent ? X11SurfaceData.UShort565RgbX11_BM : X11SurfaceData.UShort565RgbX11; } break; case 12: if (cm instanceof IndexColorModel) { sType = transparent ? X11SurfaceData.UShortIndexedX11_BM : X11SurfaceData.UShortIndexedX11; } else { throw new sun.java2d.InvalidPipeException("Unsupported bit " + "depth: " + cm.getPixelSize() + " cm="+cm); } break; case 8: if (cm.getColorSpace().getType() == ColorSpace.TYPE_GRAY && cm instanceof ComponentColorModel) { sType = transparent ? X11SurfaceData.ByteGrayX11_BM : X11SurfaceData.ByteGrayX11; } else if (cm instanceof IndexColorModel && isOpaqueGray((IndexColorModel)cm)) { sType = transparent ? X11SurfaceData.Index8GrayX11_BM : X11SurfaceData.Index8GrayX11; } else { sType = transparent ? X11SurfaceData.ByteIndexedX11_BM : X11SurfaceData.ByteIndexedOpaqueX11; } break; default: throw new sun.java2d.InvalidPipeException("Unsupported bit " + "depth: " + cm.getPixelSize()); } return sType; }
Example 19
Source File: GraphicsDevice.java From jdk8u-dev-jdk with GNU General Public License v2.0 | 3 votes |
/** * Returns the current display mode of this * <code>GraphicsDevice</code>. * The returned display mode is allowed to have a refresh rate * {@link DisplayMode#REFRESH_RATE_UNKNOWN} if it is indeterminate. * Likewise, the returned display mode is allowed to have a bit depth * {@link DisplayMode#BIT_DEPTH_MULTI} if it is indeterminate or if multiple * bit depths are supported. * @return the current display mode of this graphics device. * @see #setDisplayMode(DisplayMode) * @since 1.4 */ public DisplayMode getDisplayMode() { GraphicsConfiguration gc = getDefaultConfiguration(); Rectangle r = gc.getBounds(); ColorModel cm = gc.getColorModel(); return new DisplayMode(r.width, r.height, cm.getPixelSize(), 0); }
Example 20
Source File: GraphicsDevice.java From jdk1.8-source-analysis with Apache License 2.0 | 3 votes |
/** * Returns the current display mode of this * <code>GraphicsDevice</code>. * The returned display mode is allowed to have a refresh rate * {@link DisplayMode#REFRESH_RATE_UNKNOWN} if it is indeterminate. * Likewise, the returned display mode is allowed to have a bit depth * {@link DisplayMode#BIT_DEPTH_MULTI} if it is indeterminate or if multiple * bit depths are supported. * @return the current display mode of this graphics device. * @see #setDisplayMode(DisplayMode) * @since 1.4 */ public DisplayMode getDisplayMode() { GraphicsConfiguration gc = getDefaultConfiguration(); Rectangle r = gc.getBounds(); ColorModel cm = gc.getColorModel(); return new DisplayMode(r.width, r.height, cm.getPixelSize(), 0); }