Java Code Examples for sun.awt.image.ImageRepresentation#reconstruct()
The following examples show how to use
sun.awt.image.ImageRepresentation#reconstruct() .
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: IconInfo.java From jdk8u_jdk with GNU General Public License v2.0 | 5 votes |
public IconInfo(Image image) { this.image = image; if (image instanceof ToolkitImage) { ImageRepresentation ir = ((ToolkitImage)image).getImageRep(); ir.reconstruct(ImageObserver.ALLBITS); this.width = ir.getWidth(); this.height = ir.getHeight(); } else { this.width = image.getWidth(null); this.height = image.getHeight(null); } this.scaledWidth = width; this.scaledHeight = height; this.rawLength = width * height + 2; }
Example 2
Source File: IconInfo.java From TencentKona-8 with GNU General Public License v2.0 | 5 votes |
public IconInfo(Image image) { this.image = image; if (image instanceof ToolkitImage) { ImageRepresentation ir = ((ToolkitImage)image).getImageRep(); ir.reconstruct(ImageObserver.ALLBITS); this.width = ir.getWidth(); this.height = ir.getHeight(); } else { this.width = image.getWidth(null); this.height = image.getHeight(null); } this.scaledWidth = width; this.scaledHeight = height; this.rawLength = width * height + 2; }
Example 3
Source File: IconInfo.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 5 votes |
public IconInfo(Image image) { this.image = image; if (image instanceof ToolkitImage) { ImageRepresentation ir = ((ToolkitImage)image).getImageRep(); ir.reconstruct(ImageObserver.ALLBITS); this.width = ir.getWidth(); this.height = ir.getHeight(); } else { this.width = image.getWidth(null); this.height = image.getHeight(null); } this.scaledWidth = width; this.scaledHeight = height; this.rawLength = width * height + 2; }
Example 4
Source File: IconInfo.java From hottub with GNU General Public License v2.0 | 5 votes |
public IconInfo(Image image) { this.image = image; if (image instanceof ToolkitImage) { ImageRepresentation ir = ((ToolkitImage)image).getImageRep(); ir.reconstruct(ImageObserver.ALLBITS); this.width = ir.getWidth(); this.height = ir.getHeight(); } else { this.width = image.getWidth(null); this.height = image.getHeight(null); } this.scaledWidth = width; this.scaledHeight = height; this.rawLength = width * height + 2; }
Example 5
Source File: IconInfo.java From jdk8u-jdk with GNU General Public License v2.0 | 5 votes |
public IconInfo(Image image) { this.image = image; if (image instanceof ToolkitImage) { ImageRepresentation ir = ((ToolkitImage)image).getImageRep(); ir.reconstruct(ImageObserver.ALLBITS); this.width = ir.getWidth(); this.height = ir.getHeight(); } else { this.width = image.getWidth(null); this.height = image.getHeight(null); } this.scaledWidth = width; this.scaledHeight = height; this.rawLength = width * height + 2; }
Example 6
Source File: IconInfo.java From Bytecoder with Apache License 2.0 | 5 votes |
public IconInfo(Image image) { this.image = image; if (image instanceof ToolkitImage) { ImageRepresentation ir = ((ToolkitImage)image).getImageRep(); ir.reconstruct(ImageObserver.ALLBITS); this.width = ir.getWidth(); this.height = ir.getHeight(); } else { this.width = image.getWidth(null); this.height = image.getHeight(null); } this.scaledWidth = width; this.scaledHeight = height; this.rawLength = getScaledRawLength(width, height); }
Example 7
Source File: WCustomCursor.java From jdk8u60 with GNU General Public License v2.0 | 4 votes |
@Override protected void createNativeCursor(Image im, int[] pixels, int w, int h, int xHotSpot, int yHotSpot) { BufferedImage bimage = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB); Graphics g = bimage.getGraphics(); try { if (im instanceof ToolkitImage) { ImageRepresentation ir = ((ToolkitImage)im).getImageRep(); ir.reconstruct(ImageObserver.ALLBITS); } g.drawImage(im, 0, 0, w, h, null); } finally { g.dispose(); } Raster raster = bimage.getRaster(); DataBuffer buffer = raster.getDataBuffer(); // REMIND: native code should use ScanStride _AND_ width int data[] = ((DataBufferInt)buffer).getData(); byte[] andMask = new byte[w * h / 8]; int npixels = pixels.length; for (int i = 0; i < npixels; i++) { int ibyte = i / 8; int omask = 1 << (7 - (i % 8)); if ((pixels[i] & 0xff000000) == 0) { // Transparent bit andMask[ibyte] |= omask; } } { int ficW = raster.getWidth(); if( raster instanceof IntegerComponentRaster ) { ficW = ((IntegerComponentRaster)raster).getScanlineStride(); } createCursorIndirect( ((DataBufferInt)bimage.getRaster().getDataBuffer()).getData(), andMask, ficW, raster.getWidth(), raster.getHeight(), xHotSpot, yHotSpot); } }
Example 8
Source File: WCustomCursor.java From jdk8u-jdk with GNU General Public License v2.0 | 4 votes |
@Override protected void createNativeCursor(Image im, int[] pixels, int w, int h, int xHotSpot, int yHotSpot) { BufferedImage bimage = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB); Graphics g = bimage.getGraphics(); try { if (im instanceof ToolkitImage) { ImageRepresentation ir = ((ToolkitImage)im).getImageRep(); ir.reconstruct(ImageObserver.ALLBITS); } g.drawImage(im, 0, 0, w, h, null); } finally { g.dispose(); } Raster raster = bimage.getRaster(); DataBuffer buffer = raster.getDataBuffer(); // REMIND: native code should use ScanStride _AND_ width int data[] = ((DataBufferInt)buffer).getData(); byte[] andMask = new byte[w * h / 8]; int npixels = pixels.length; for (int i = 0; i < npixels; i++) { int ibyte = i / 8; int omask = 1 << (7 - (i % 8)); if ((pixels[i] & 0xff000000) == 0) { // Transparent bit andMask[ibyte] |= omask; } } { int ficW = raster.getWidth(); if( raster instanceof IntegerComponentRaster ) { ficW = ((IntegerComponentRaster)raster).getScanlineStride(); } createCursorIndirect( ((DataBufferInt)bimage.getRaster().getDataBuffer()).getData(), andMask, ficW, raster.getWidth(), raster.getHeight(), xHotSpot, yHotSpot); } }
Example 9
Source File: WCustomCursor.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 4 votes |
@Override protected void createNativeCursor(Image im, int[] pixels, int w, int h, int xHotSpot, int yHotSpot) { BufferedImage bimage = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB); Graphics g = bimage.getGraphics(); try { if (im instanceof ToolkitImage) { ImageRepresentation ir = ((ToolkitImage)im).getImageRep(); ir.reconstruct(ImageObserver.ALLBITS); } g.drawImage(im, 0, 0, w, h, null); } finally { g.dispose(); } Raster raster = bimage.getRaster(); DataBuffer buffer = raster.getDataBuffer(); // REMIND: native code should use ScanStride _AND_ width int data[] = ((DataBufferInt)buffer).getData(); byte[] andMask = new byte[w * h / 8]; int npixels = pixels.length; for (int i = 0; i < npixels; i++) { int ibyte = i / 8; int omask = 1 << (7 - (i % 8)); if ((pixels[i] & 0xff000000) == 0) { // Transparent bit andMask[ibyte] |= omask; } } { int ficW = raster.getWidth(); if( raster instanceof IntegerComponentRaster ) { ficW = ((IntegerComponentRaster)raster).getScanlineStride(); } createCursorIndirect( ((DataBufferInt)bimage.getRaster().getDataBuffer()).getData(), andMask, ficW, raster.getWidth(), raster.getHeight(), xHotSpot, yHotSpot); } }
Example 10
Source File: WDataTransferer.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 4 votes |
@Override protected byte[] imageToPlatformBytes(Image image, long format) throws IOException { String mimeType = null; if (format == CF_PNG) { mimeType = "image/png"; } else if (format == CF_JFIF) { mimeType = "image/jpeg"; } if (mimeType != null) { return imageToStandardBytes(image, mimeType); } int width = 0; int height = 0; if (image instanceof ToolkitImage) { ImageRepresentation ir = ((ToolkitImage)image).getImageRep(); ir.reconstruct(ImageObserver.ALLBITS); width = ir.getWidth(); height = ir.getHeight(); } else { width = image.getWidth(null); height = image.getHeight(null); } // Fix for 4919639. // Some Windows native applications (e.g. clipbrd.exe) do not handle // 32-bpp DIBs correctly. // As a workaround we switched to 24-bpp DIBs. // MSDN prescribes that the bitmap array for a 24-bpp should consist of // 3-byte triplets representing blue, green and red components of a // pixel respectively. Additionally each scan line must be padded with // zeroes to end on a LONG data-type boundary. LONG is always 32-bit. // We render the given Image to a BufferedImage of type TYPE_3BYTE_BGR // with non-default scanline stride and pass the resulting data buffer // to the native code to fill the BITMAPINFO structure. int mod = (width * 3) % 4; int pad = mod > 0 ? 4 - mod : 0; ColorSpace cs = ColorSpace.getInstance(ColorSpace.CS_sRGB); int[] nBits = {8, 8, 8}; int[] bOffs = {2, 1, 0}; ColorModel colorModel = new ComponentColorModel(cs, nBits, false, false, Transparency.OPAQUE, DataBuffer.TYPE_BYTE); WritableRaster raster = Raster.createInterleavedRaster(DataBuffer.TYPE_BYTE, width, height, width * 3 + pad, 3, bOffs, null); BufferedImage bimage = new BufferedImage(colorModel, raster, false, null); // Some Windows native applications (e.g. clipbrd.exe) do not understand // top-down DIBs. // So we flip the image vertically and create a bottom-up DIB. AffineTransform imageFlipTransform = new AffineTransform(1, 0, 0, -1, 0, height); Graphics2D g2d = bimage.createGraphics(); try { g2d.drawImage(image, imageFlipTransform, null); } finally { g2d.dispose(); } DataBufferByte buffer = (DataBufferByte)raster.getDataBuffer(); byte[] imageData = buffer.getData(); return imageDataToPlatformImageBytes(imageData, width, height, format); }
Example 11
Source File: WCustomCursor.java From jdk8u-dev-jdk with GNU General Public License v2.0 | 4 votes |
@Override protected void createNativeCursor(Image im, int[] pixels, int w, int h, int xHotSpot, int yHotSpot) { BufferedImage bimage = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB); Graphics g = bimage.getGraphics(); try { if (im instanceof ToolkitImage) { ImageRepresentation ir = ((ToolkitImage)im).getImageRep(); ir.reconstruct(ImageObserver.ALLBITS); } g.drawImage(im, 0, 0, w, h, null); } finally { g.dispose(); } Raster raster = bimage.getRaster(); DataBuffer buffer = raster.getDataBuffer(); // REMIND: native code should use ScanStride _AND_ width int data[] = ((DataBufferInt)buffer).getData(); byte[] andMask = new byte[w * h / 8]; int npixels = pixels.length; for (int i = 0; i < npixels; i++) { int ibyte = i / 8; int omask = 1 << (7 - (i % 8)); if ((pixels[i] & 0xff000000) == 0) { // Transparent bit andMask[ibyte] |= omask; } } { int ficW = raster.getWidth(); if( raster instanceof IntegerComponentRaster ) { ficW = ((IntegerComponentRaster)raster).getScanlineStride(); } createCursorIndirect( ((DataBufferInt)bimage.getRaster().getDataBuffer()).getData(), andMask, ficW, raster.getWidth(), raster.getHeight(), xHotSpot, yHotSpot); } }
Example 12
Source File: WCustomCursor.java From openjdk-jdk8u with GNU General Public License v2.0 | 4 votes |
@Override protected void createNativeCursor(Image im, int[] pixels, int w, int h, int xHotSpot, int yHotSpot) { BufferedImage bimage = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB); Graphics g = bimage.getGraphics(); try { if (im instanceof ToolkitImage) { ImageRepresentation ir = ((ToolkitImage)im).getImageRep(); ir.reconstruct(ImageObserver.ALLBITS); } g.drawImage(im, 0, 0, w, h, null); } finally { g.dispose(); } Raster raster = bimage.getRaster(); DataBuffer buffer = raster.getDataBuffer(); // REMIND: native code should use ScanStride _AND_ width int data[] = ((DataBufferInt)buffer).getData(); byte[] andMask = new byte[w * h / 8]; int npixels = pixels.length; for (int i = 0; i < npixels; i++) { int ibyte = i / 8; int omask = 1 << (7 - (i % 8)); if ((pixels[i] & 0xff000000) == 0) { // Transparent bit andMask[ibyte] |= omask; } } { int ficW = raster.getWidth(); if( raster instanceof IntegerComponentRaster ) { ficW = ((IntegerComponentRaster)raster).getScanlineStride(); } createCursorIndirect( ((DataBufferInt)bimage.getRaster().getDataBuffer()).getData(), andMask, ficW, raster.getWidth(), raster.getHeight(), xHotSpot, yHotSpot); } }
Example 13
Source File: WDataTransferer.java From jdk8u-jdk with GNU General Public License v2.0 | 4 votes |
@Override protected byte[] imageToPlatformBytes(Image image, long format) throws IOException { String mimeType = null; if (format == CF_PNG) { mimeType = "image/png"; } else if (format == CF_JFIF) { mimeType = "image/jpeg"; } if (mimeType != null) { return imageToStandardBytes(image, mimeType); } int width = 0; int height = 0; if (image instanceof ToolkitImage) { ImageRepresentation ir = ((ToolkitImage)image).getImageRep(); ir.reconstruct(ImageObserver.ALLBITS); width = ir.getWidth(); height = ir.getHeight(); } else { width = image.getWidth(null); height = image.getHeight(null); } // Fix for 4919639. // Some Windows native applications (e.g. clipbrd.exe) do not handle // 32-bpp DIBs correctly. // As a workaround we switched to 24-bpp DIBs. // MSDN prescribes that the bitmap array for a 24-bpp should consist of // 3-byte triplets representing blue, green and red components of a // pixel respectively. Additionally each scan line must be padded with // zeroes to end on a LONG data-type boundary. LONG is always 32-bit. // We render the given Image to a BufferedImage of type TYPE_3BYTE_BGR // with non-default scanline stride and pass the resulting data buffer // to the native code to fill the BITMAPINFO structure. int mod = (width * 3) % 4; int pad = mod > 0 ? 4 - mod : 0; ColorSpace cs = ColorSpace.getInstance(ColorSpace.CS_sRGB); int[] nBits = {8, 8, 8}; int[] bOffs = {2, 1, 0}; ColorModel colorModel = new ComponentColorModel(cs, nBits, false, false, Transparency.OPAQUE, DataBuffer.TYPE_BYTE); WritableRaster raster = Raster.createInterleavedRaster(DataBuffer.TYPE_BYTE, width, height, width * 3 + pad, 3, bOffs, null); BufferedImage bimage = new BufferedImage(colorModel, raster, false, null); // Some Windows native applications (e.g. clipbrd.exe) do not understand // top-down DIBs. // So we flip the image vertically and create a bottom-up DIB. AffineTransform imageFlipTransform = new AffineTransform(1, 0, 0, -1, 0, height); Graphics2D g2d = bimage.createGraphics(); try { g2d.drawImage(image, imageFlipTransform, null); } finally { g2d.dispose(); } DataBufferByte buffer = (DataBufferByte)raster.getDataBuffer(); byte[] imageData = buffer.getData(); return imageDataToPlatformImageBytes(imageData, width, height, format); }
Example 14
Source File: WCustomCursor.java From jdk8u_jdk with GNU General Public License v2.0 | 4 votes |
@Override protected void createNativeCursor(Image im, int[] pixels, int w, int h, int xHotSpot, int yHotSpot) { BufferedImage bimage = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB); Graphics g = bimage.getGraphics(); try { if (im instanceof ToolkitImage) { ImageRepresentation ir = ((ToolkitImage)im).getImageRep(); ir.reconstruct(ImageObserver.ALLBITS); } g.drawImage(im, 0, 0, w, h, null); } finally { g.dispose(); } Raster raster = bimage.getRaster(); DataBuffer buffer = raster.getDataBuffer(); // REMIND: native code should use ScanStride _AND_ width int data[] = ((DataBufferInt)buffer).getData(); byte[] andMask = new byte[w * h / 8]; int npixels = pixels.length; for (int i = 0; i < npixels; i++) { int ibyte = i / 8; int omask = 1 << (7 - (i % 8)); if ((pixels[i] & 0xff000000) == 0) { // Transparent bit andMask[ibyte] |= omask; } } { int ficW = raster.getWidth(); if( raster instanceof IntegerComponentRaster ) { ficW = ((IntegerComponentRaster)raster).getScanlineStride(); } createCursorIndirect( ((DataBufferInt)bimage.getRaster().getDataBuffer()).getData(), andMask, ficW, raster.getWidth(), raster.getHeight(), xHotSpot, yHotSpot); } }
Example 15
Source File: XIconWindow.java From jdk8u60 with GNU General Public License v2.0 | 4 votes |
void setIconImage(Image img) { if (img == null) { //if image is null, reset to default image replaceImage(null); replaceMask(null); } else { //get image size int width; int height; if (img instanceof ToolkitImage) { ImageRepresentation ir = ((ToolkitImage)img).getImageRep(); ir.reconstruct(ImageObserver.ALLBITS); width = ir.getWidth(); height = ir.getHeight(); } else { width = img.getWidth(null); height = img.getHeight(null); } Dimension iconSize = getIconSize(width, height); if (iconSize != null) { if (log.isLoggable(PlatformLogger.Level.FINEST)) { log.finest("Icon size: {0}", iconSize); } iconWidth = iconSize.width; iconHeight = iconSize.height; } else { log.finest("Error calculating image size"); iconWidth = 0; iconHeight = 0; } replaceImage(img); replaceMask(img); } //create icon window and set XWMHints XToolkit.awtLock(); try { AwtGraphicsConfigData adata = parent.getGraphicsConfigurationData(); awtImageData awtImage = adata.get_awtImage(0); XVisualInfo visInfo = adata.get_awt_visInfo(); XWMHints hints = parent.getWMHints(); window = hints.get_icon_window(); if (window == 0) { log.finest("Icon window wasn't set"); XCreateWindowParams params = getDelayedParams(); params.add(BORDER_PIXEL, Long.valueOf(XToolkit.getAwtDefaultFg())); params.add(BACKGROUND_PIXMAP, iconPixmap); params.add(COLORMAP, adata.get_awt_cmap()); params.add(DEPTH, awtImage.get_Depth()); params.add(VISUAL_CLASS, (int)XConstants.InputOutput); params.add(VISUAL, visInfo.get_visual()); params.add(VALUE_MASK, XConstants.CWBorderPixel | XConstants.CWColormap | XConstants.CWBackPixmap); params.add(PARENT_WINDOW, XlibWrapper.RootWindow(XToolkit.getDisplay(), visInfo.get_screen())); params.add(BOUNDS, new Rectangle(0, 0, iconWidth, iconHeight)); params.remove(DELAYED); init(params); if (getWindow() == 0) { log.finest("Can't create new icon window"); } else { log.finest("Created new icon window"); } } if (getWindow() != 0) { XlibWrapper.XSetWindowBackgroundPixmap(XToolkit.getDisplay(), getWindow(), iconPixmap); XlibWrapper.XClearWindow(XToolkit.getDisplay(), getWindow()); } // Provide both pixmap and window, WM or Taskbar will use the one they find more appropriate long newFlags = hints.get_flags() | XUtilConstants.IconPixmapHint | XUtilConstants.IconMaskHint; if (getWindow() != 0) { newFlags |= XUtilConstants.IconWindowHint; } hints.set_flags(newFlags); hints.set_icon_pixmap(iconPixmap); hints.set_icon_mask(iconMask); hints.set_icon_window(getWindow()); XlibWrapper.XSetWMHints(XToolkit.getDisplay(), parent.getShell(), hints.pData); log.finest("Set icon window hint"); } finally { XToolkit.awtUnlock(); } }
Example 16
Source File: XIconWindow.java From openjdk-jdk9 with GNU General Public License v2.0 | 4 votes |
void setIconImage(Image img) { if (img == null) { //if image is null, reset to default image replaceImage(null); replaceMask(null); } else { //get image size int width; int height; if (img instanceof ToolkitImage) { ImageRepresentation ir = ((ToolkitImage)img).getImageRep(); ir.reconstruct(ImageObserver.ALLBITS); width = ir.getWidth(); height = ir.getHeight(); } else { width = img.getWidth(null); height = img.getHeight(null); } Dimension iconSize = getIconSize(width, height); if (iconSize != null) { if (log.isLoggable(PlatformLogger.Level.FINEST)) { log.finest("Icon size: {0}", iconSize); } iconWidth = iconSize.width; iconHeight = iconSize.height; } else { log.finest("Error calculating image size"); iconWidth = 0; iconHeight = 0; } replaceImage(img); replaceMask(img); } //create icon window and set XWMHints XToolkit.awtLock(); try { AwtGraphicsConfigData adata = parent.getGraphicsConfigurationData(); awtImageData awtImage = adata.get_awtImage(0); XVisualInfo visInfo = adata.get_awt_visInfo(); XWMHints hints = parent.getWMHints(); window = hints.get_icon_window(); if (window == 0) { log.finest("Icon window wasn't set"); XCreateWindowParams params = getDelayedParams(); params.add(BORDER_PIXEL, Long.valueOf(XToolkit.getAwtDefaultFg())); params.add(BACKGROUND_PIXMAP, iconPixmap); params.add(COLORMAP, adata.get_awt_cmap()); params.add(DEPTH, awtImage.get_Depth()); params.add(VISUAL_CLASS, XConstants.InputOutput); params.add(VISUAL, visInfo.get_visual()); params.add(VALUE_MASK, XConstants.CWBorderPixel | XConstants.CWColormap | XConstants.CWBackPixmap); params.add(PARENT_WINDOW, XlibWrapper.RootWindow(XToolkit.getDisplay(), visInfo.get_screen())); params.add(BOUNDS, new Rectangle(0, 0, iconWidth, iconHeight)); params.remove(DELAYED); init(params); if (getWindow() == 0) { log.finest("Can't create new icon window"); } else { log.finest("Created new icon window"); } } if (getWindow() != 0) { XlibWrapper.XSetWindowBackgroundPixmap(XToolkit.getDisplay(), getWindow(), iconPixmap); XlibWrapper.XClearWindow(XToolkit.getDisplay(), getWindow()); } // Provide both pixmap and window, WM or Taskbar will use the one they find more appropriate long newFlags = hints.get_flags() | XUtilConstants.IconPixmapHint | XUtilConstants.IconMaskHint; if (getWindow() != 0) { newFlags |= XUtilConstants.IconWindowHint; } hints.set_flags(newFlags); hints.set_icon_pixmap(iconPixmap); hints.set_icon_mask(iconMask); hints.set_icon_window(getWindow()); XlibWrapper.XSetWMHints(XToolkit.getDisplay(), parent.getShell(), hints.pData); log.finest("Set icon window hint"); } finally { XToolkit.awtUnlock(); } }
Example 17
Source File: WDataTransferer.java From openjdk-jdk9 with GNU General Public License v2.0 | 4 votes |
@Override protected byte[] imageToPlatformBytes(Image image, long format) throws IOException { String mimeType = null; if (format == CF_PNG) { mimeType = "image/png"; } else if (format == CF_JFIF) { mimeType = "image/jpeg"; } if (mimeType != null) { return imageToStandardBytes(image, mimeType); } int width = 0; int height = 0; if (image instanceof ToolkitImage) { ImageRepresentation ir = ((ToolkitImage)image).getImageRep(); ir.reconstruct(ImageObserver.ALLBITS); width = ir.getWidth(); height = ir.getHeight(); } else { width = image.getWidth(null); height = image.getHeight(null); } // Fix for 4919639. // Some Windows native applications (e.g. clipbrd.exe) do not handle // 32-bpp DIBs correctly. // As a workaround we switched to 24-bpp DIBs. // MSDN prescribes that the bitmap array for a 24-bpp should consist of // 3-byte triplets representing blue, green and red components of a // pixel respectively. Additionally each scan line must be padded with // zeroes to end on a LONG data-type boundary. LONG is always 32-bit. // We render the given Image to a BufferedImage of type TYPE_3BYTE_BGR // with non-default scanline stride and pass the resulting data buffer // to the native code to fill the BITMAPINFO structure. int mod = (width * 3) % 4; int pad = mod > 0 ? 4 - mod : 0; ColorSpace cs = ColorSpace.getInstance(ColorSpace.CS_sRGB); int[] nBits = {8, 8, 8}; int[] bOffs = {2, 1, 0}; ColorModel colorModel = new ComponentColorModel(cs, nBits, false, false, Transparency.OPAQUE, DataBuffer.TYPE_BYTE); WritableRaster raster = Raster.createInterleavedRaster(DataBuffer.TYPE_BYTE, width, height, width * 3 + pad, 3, bOffs, null); BufferedImage bimage = new BufferedImage(colorModel, raster, false, null); // Some Windows native applications (e.g. clipbrd.exe) do not understand // top-down DIBs. // So we flip the image vertically and create a bottom-up DIB. AffineTransform imageFlipTransform = new AffineTransform(1, 0, 0, -1, 0, height); Graphics2D g2d = bimage.createGraphics(); try { g2d.drawImage(image, imageFlipTransform, null); } finally { g2d.dispose(); } DataBufferByte buffer = (DataBufferByte)raster.getDataBuffer(); byte[] imageData = buffer.getData(); return imageDataToPlatformImageBytes(imageData, width, height, format); }
Example 18
Source File: WDataTransferer.java From TencentKona-8 with GNU General Public License v2.0 | 4 votes |
@Override protected byte[] imageToPlatformBytes(Image image, long format) throws IOException { String mimeType = null; if (format == CF_PNG) { mimeType = "image/png"; } else if (format == CF_JFIF) { mimeType = "image/jpeg"; } if (mimeType != null) { return imageToStandardBytes(image, mimeType); } int width = 0; int height = 0; if (image instanceof ToolkitImage) { ImageRepresentation ir = ((ToolkitImage)image).getImageRep(); ir.reconstruct(ImageObserver.ALLBITS); width = ir.getWidth(); height = ir.getHeight(); } else { width = image.getWidth(null); height = image.getHeight(null); } // Fix for 4919639. // Some Windows native applications (e.g. clipbrd.exe) do not handle // 32-bpp DIBs correctly. // As a workaround we switched to 24-bpp DIBs. // MSDN prescribes that the bitmap array for a 24-bpp should consist of // 3-byte triplets representing blue, green and red components of a // pixel respectively. Additionally each scan line must be padded with // zeroes to end on a LONG data-type boundary. LONG is always 32-bit. // We render the given Image to a BufferedImage of type TYPE_3BYTE_BGR // with non-default scanline stride and pass the resulting data buffer // to the native code to fill the BITMAPINFO structure. int mod = (width * 3) % 4; int pad = mod > 0 ? 4 - mod : 0; ColorSpace cs = ColorSpace.getInstance(ColorSpace.CS_sRGB); int[] nBits = {8, 8, 8}; int[] bOffs = {2, 1, 0}; ColorModel colorModel = new ComponentColorModel(cs, nBits, false, false, Transparency.OPAQUE, DataBuffer.TYPE_BYTE); WritableRaster raster = Raster.createInterleavedRaster(DataBuffer.TYPE_BYTE, width, height, width * 3 + pad, 3, bOffs, null); BufferedImage bimage = new BufferedImage(colorModel, raster, false, null); // Some Windows native applications (e.g. clipbrd.exe) do not understand // top-down DIBs. // So we flip the image vertically and create a bottom-up DIB. AffineTransform imageFlipTransform = new AffineTransform(1, 0, 0, -1, 0, height); Graphics2D g2d = bimage.createGraphics(); try { g2d.drawImage(image, imageFlipTransform, null); } finally { g2d.dispose(); } DataBufferByte buffer = (DataBufferByte)raster.getDataBuffer(); byte[] imageData = buffer.getData(); return imageDataToPlatformImageBytes(imageData, width, height, format); }
Example 19
Source File: WCustomCursor.java From dragonwell8_jdk with GNU General Public License v2.0 | 4 votes |
@Override protected void createNativeCursor(Image im, int[] pixels, int w, int h, int xHotSpot, int yHotSpot) { BufferedImage bimage = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB); Graphics g = bimage.getGraphics(); try { if (im instanceof ToolkitImage) { ImageRepresentation ir = ((ToolkitImage)im).getImageRep(); ir.reconstruct(ImageObserver.ALLBITS); } g.drawImage(im, 0, 0, w, h, null); } finally { g.dispose(); } Raster raster = bimage.getRaster(); DataBuffer buffer = raster.getDataBuffer(); // REMIND: native code should use ScanStride _AND_ width int data[] = ((DataBufferInt)buffer).getData(); byte[] andMask = new byte[w * h / 8]; int npixels = pixels.length; for (int i = 0; i < npixels; i++) { int ibyte = i / 8; int omask = 1 << (7 - (i % 8)); if ((pixels[i] & 0xff000000) == 0) { // Transparent bit andMask[ibyte] |= omask; } } { int ficW = raster.getWidth(); if( raster instanceof IntegerComponentRaster ) { ficW = ((IntegerComponentRaster)raster).getScanlineStride(); } createCursorIndirect( ((DataBufferInt)bimage.getRaster().getDataBuffer()).getData(), andMask, ficW, raster.getWidth(), raster.getHeight(), xHotSpot, yHotSpot); } }
Example 20
Source File: WDataTransferer.java From jdk8u-jdk with GNU General Public License v2.0 | 4 votes |
@Override protected byte[] imageToPlatformBytes(Image image, long format) throws IOException { String mimeType = null; if (format == CF_PNG) { mimeType = "image/png"; } else if (format == CF_JFIF) { mimeType = "image/jpeg"; } if (mimeType != null) { return imageToStandardBytes(image, mimeType); } int width = 0; int height = 0; if (image instanceof ToolkitImage) { ImageRepresentation ir = ((ToolkitImage)image).getImageRep(); ir.reconstruct(ImageObserver.ALLBITS); width = ir.getWidth(); height = ir.getHeight(); } else { width = image.getWidth(null); height = image.getHeight(null); } // Fix for 4919639. // Some Windows native applications (e.g. clipbrd.exe) do not handle // 32-bpp DIBs correctly. // As a workaround we switched to 24-bpp DIBs. // MSDN prescribes that the bitmap array for a 24-bpp should consist of // 3-byte triplets representing blue, green and red components of a // pixel respectively. Additionally each scan line must be padded with // zeroes to end on a LONG data-type boundary. LONG is always 32-bit. // We render the given Image to a BufferedImage of type TYPE_3BYTE_BGR // with non-default scanline stride and pass the resulting data buffer // to the native code to fill the BITMAPINFO structure. int mod = (width * 3) % 4; int pad = mod > 0 ? 4 - mod : 0; ColorSpace cs = ColorSpace.getInstance(ColorSpace.CS_sRGB); int[] nBits = {8, 8, 8}; int[] bOffs = {2, 1, 0}; ColorModel colorModel = new ComponentColorModel(cs, nBits, false, false, Transparency.OPAQUE, DataBuffer.TYPE_BYTE); WritableRaster raster = Raster.createInterleavedRaster(DataBuffer.TYPE_BYTE, width, height, width * 3 + pad, 3, bOffs, null); BufferedImage bimage = new BufferedImage(colorModel, raster, false, null); // Some Windows native applications (e.g. clipbrd.exe) do not understand // top-down DIBs. // So we flip the image vertically and create a bottom-up DIB. AffineTransform imageFlipTransform = new AffineTransform(1, 0, 0, -1, 0, height); Graphics2D g2d = bimage.createGraphics(); try { g2d.drawImage(image, imageFlipTransform, null); } finally { g2d.dispose(); } DataBufferByte buffer = (DataBufferByte)raster.getDataBuffer(); byte[] imageData = buffer.getData(); return imageDataToPlatformImageBytes(imageData, width, height, format); }