Search in sources :

Example 1 with ImageRepresentation

use of sun.awt.image.ImageRepresentation in project jdk8u_jdk by JetBrains.

the class DrawImage method scaleImage.

public boolean scaleImage(SunGraphics2D sg, Image img, int x, int y, int width, int height, Color bgColor, ImageObserver observer) {
    if (!(img instanceof ToolkitImage)) {
        return scaleImage(sg, img, x, y, width, height, bgColor);
    } else {
        ToolkitImage sunimg = (ToolkitImage) img;
        if (!imageReady(sunimg, observer)) {
            return false;
        }
        ImageRepresentation ir = sunimg.getImageRep();
        return ir.drawToBufImage(sg, sunimg, x, y, width, height, bgColor, observer);
    }
}
Also used : ImageRepresentation(sun.awt.image.ImageRepresentation) ToolkitImage(sun.awt.image.ToolkitImage)

Example 2 with ImageRepresentation

use of sun.awt.image.ImageRepresentation in project jdk8u_jdk by JetBrains.

the class HTMLCodec method imageToPlatformBytes.

@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);
}
Also used : ColorSpace(java.awt.color.ColorSpace) ComponentColorModel(java.awt.image.ComponentColorModel) DataBufferByte(java.awt.image.DataBufferByte) BufferedImage(java.awt.image.BufferedImage) Graphics2D(java.awt.Graphics2D) ImageRepresentation(sun.awt.image.ImageRepresentation) DirectColorModel(java.awt.image.DirectColorModel) ComponentColorModel(java.awt.image.ComponentColorModel) ColorModel(java.awt.image.ColorModel) WritableRaster(java.awt.image.WritableRaster) AffineTransform(java.awt.geom.AffineTransform) ToolkitImage(sun.awt.image.ToolkitImage)

Example 3 with ImageRepresentation

use of sun.awt.image.ImageRepresentation in project jdk8u_jdk by JetBrains.

the class ToolkitImage method reconstruct.

private synchronized void reconstruct(int flags) {
    if ((flags & ~availinfo) != 0) {
        if ((availinfo & ImageObserver.ERROR) != 0) {
            return;
        }
        ImageRepresentation ir = getImageRep();
        ir.startProduction();
        while ((flags & ~availinfo) != 0) {
            try {
                wait();
            } catch (InterruptedException e) {
                Thread.currentThread().interrupt();
                return;
            }
            if ((availinfo & ImageObserver.ERROR) != 0) {
                return;
            }
        }
    }
}
Also used : ImageRepresentation(sun.awt.image.ImageRepresentation)

Example 4 with ImageRepresentation

use of sun.awt.image.ImageRepresentation in project jdk8u_jdk by JetBrains.

the class ToolkitImage method addWatcher.

private synchronized void addWatcher(ImageObserver iw, boolean load) {
    if ((availinfo & ImageObserver.ERROR) != 0) {
        if (iw != null) {
            iw.imageUpdate(this, ImageObserver.ERROR | ImageObserver.ABORT, -1, -1, -1, -1);
        }
        return;
    }
    ImageRepresentation ir = getImageRep();
    ir.addWatcher(iw);
    if (load) {
        ir.startProduction();
    }
}
Also used : ImageRepresentation(sun.awt.image.ImageRepresentation)

Example 5 with ImageRepresentation

use of sun.awt.image.ImageRepresentation in project jdk8u_jdk by JetBrains.

the class DrawImage method copyImage.

public boolean copyImage(SunGraphics2D sg, Image img, int x, int y, Color bgColor, ImageObserver observer) {
    if (!(img instanceof ToolkitImage)) {
        return copyImage(sg, img, x, y, bgColor);
    } else {
        ToolkitImage sunimg = (ToolkitImage) img;
        if (!imageReady(sunimg, observer)) {
            return false;
        }
        ImageRepresentation ir = sunimg.getImageRep();
        return ir.drawToBufImage(sg, sunimg, x, y, bgColor, observer);
    }
}
Also used : ImageRepresentation(sun.awt.image.ImageRepresentation) ToolkitImage(sun.awt.image.ToolkitImage)

Aggregations

ImageRepresentation (sun.awt.image.ImageRepresentation)11 ToolkitImage (sun.awt.image.ToolkitImage)7 Graphics2D (java.awt.Graphics2D)1 ColorSpace (java.awt.color.ColorSpace)1 AffineTransform (java.awt.geom.AffineTransform)1 BufferedImage (java.awt.image.BufferedImage)1 ColorModel (java.awt.image.ColorModel)1 ComponentColorModel (java.awt.image.ComponentColorModel)1 DataBufferByte (java.awt.image.DataBufferByte)1 DirectColorModel (java.awt.image.DirectColorModel)1 WritableRaster (java.awt.image.WritableRaster)1 IntegerComponentRaster (sun.awt.image.IntegerComponentRaster)1