Search in sources :

Example 1 with RescaleOp

use of java.awt.image.RescaleOp in project poi by apache.

the class HwmfSLImageRenderer method getImage.

@Override
public BufferedImage getImage(Dimension dim) {
    if (image == null) {
        return new BufferedImage(1, 1, BufferedImage.TYPE_INT_ARGB);
    }
    BufferedImage bufImg = new BufferedImage((int) dim.getWidth(), (int) dim.getHeight(), BufferedImage.TYPE_INT_ARGB);
    Graphics2D g = bufImg.createGraphics();
    g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    g.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
    g.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC);
    g.setRenderingHint(RenderingHints.KEY_FRACTIONALMETRICS, RenderingHints.VALUE_FRACTIONALMETRICS_ON);
    image.draw(g, new Rectangle2D.Double(0, 0, dim.getWidth(), dim.getHeight()));
    g.dispose();
    if (alpha != 0) {
        BufferedImage newImg = new BufferedImage((int) dim.getWidth(), (int) dim.getHeight(), BufferedImage.TYPE_INT_ARGB);
        g = newImg.createGraphics();
        RescaleOp op = new RescaleOp(new float[] { 1.0f, 1.0f, 1.0f, (float) alpha }, new float[] { 0, 0, 0, 0 }, null);
        g.drawImage(bufImg, op, 0, 0);
        g.dispose();
        bufImg = newImg;
    }
    return bufImg;
}
Also used : RescaleOp(java.awt.image.RescaleOp) Rectangle2D(java.awt.geom.Rectangle2D) BufferedImage(java.awt.image.BufferedImage) Graphics2D(java.awt.Graphics2D)

Example 2 with RescaleOp

use of java.awt.image.RescaleOp in project jdk8u_jdk by JetBrains.

the class D3DBufImgOps method renderImageWithOp.

/**
     * This method is called from D3DDrawImage.transformImage() only.  It
     * validates the provided BufferedImageOp to determine whether the op
     * is one that can be accelerated by the D3D pipeline.  If the operation
     * cannot be completed for any reason, this method returns false;
     * otherwise, the given BufferedImage is rendered to the destination
     * using the provided BufferedImageOp and this method returns true.
     */
static boolean renderImageWithOp(SunGraphics2D sg, BufferedImage img, BufferedImageOp biop, int x, int y) {
    // is supported, and that its properties are acceleratable)
    if (biop instanceof ConvolveOp) {
        if (!isConvolveOpValid((ConvolveOp) biop)) {
            return false;
        }
    } else if (biop instanceof RescaleOp) {
        if (!isRescaleOpValid((RescaleOp) biop, img)) {
            return false;
        }
    } else if (biop instanceof LookupOp) {
        if (!isLookupOpValid((LookupOp) biop, img)) {
            return false;
        }
    } else {
        // No acceleration for other BufferedImageOps (yet)
        return false;
    }
    SurfaceData dstData = sg.surfaceData;
    if (!(dstData instanceof D3DSurfaceData) || (sg.interpolationType == AffineTransformOp.TYPE_BICUBIC) || (sg.compositeState > SunGraphics2D.COMP_ALPHA)) {
        return false;
    }
    SurfaceData srcData = dstData.getSourceSurfaceData(img, sg.TRANSFORM_ISIDENT, CompositeType.SrcOver, null);
    if (!(srcData instanceof D3DSurfaceData)) {
        // REMIND: this hack tries to ensure that we have a cached texture
        srcData = dstData.getSourceSurfaceData(img, sg.TRANSFORM_ISIDENT, CompositeType.SrcOver, null);
        if (!(srcData instanceof D3DSurfaceData)) {
            return false;
        }
    }
    // Verify that the source surface is actually a texture and that
    // shaders are supported
    D3DSurfaceData d3dSrc = (D3DSurfaceData) srcData;
    D3DGraphicsDevice gd = (D3DGraphicsDevice) d3dSrc.getDeviceConfiguration().getDevice();
    if (d3dSrc.getType() != D3DSurfaceData.TEXTURE || !gd.isCapPresent(CAPS_LCD_SHADER)) {
        return false;
    }
    int sw = img.getWidth();
    int sh = img.getHeight();
    D3DBlitLoops.IsoBlit(srcData, dstData, img, biop, sg.composite, sg.getCompClip(), sg.transform, sg.interpolationType, 0, 0, sw, sh, x, y, x + sw, y + sh, true);
    return true;
}
Also used : RescaleOp(java.awt.image.RescaleOp) SurfaceData(sun.java2d.SurfaceData) ConvolveOp(java.awt.image.ConvolveOp) LookupOp(java.awt.image.LookupOp)

Example 3 with RescaleOp

use of java.awt.image.RescaleOp in project jdk8u_jdk by JetBrains.

the class OGLBufImgOps method renderImageWithOp.

/**
     * This method is called from OGLDrawImage.transformImage() only.  It
     * validates the provided BufferedImageOp to determine whether the op
     * is one that can be accelerated by the OGL pipeline.  If the operation
     * cannot be completed for any reason, this method returns false;
     * otherwise, the given BufferedImage is rendered to the destination
     * using the provided BufferedImageOp and this method returns true.
     */
static boolean renderImageWithOp(SunGraphics2D sg, BufferedImage img, BufferedImageOp biop, int x, int y) {
    // is supported, and that its properties are acceleratable)
    if (biop instanceof ConvolveOp) {
        if (!isConvolveOpValid((ConvolveOp) biop)) {
            return false;
        }
    } else if (biop instanceof RescaleOp) {
        if (!isRescaleOpValid((RescaleOp) biop, img)) {
            return false;
        }
    } else if (biop instanceof LookupOp) {
        if (!isLookupOpValid((LookupOp) biop, img)) {
            return false;
        }
    } else {
        // No acceleration for other BufferedImageOps (yet)
        return false;
    }
    SurfaceData dstData = sg.surfaceData;
    if (!(dstData instanceof OGLSurfaceData) || (sg.interpolationType == AffineTransformOp.TYPE_BICUBIC) || (sg.compositeState > SunGraphics2D.COMP_ALPHA)) {
        return false;
    }
    SurfaceData srcData = dstData.getSourceSurfaceData(img, SunGraphics2D.TRANSFORM_ISIDENT, CompositeType.SrcOver, null);
    if (!(srcData instanceof OGLSurfaceData)) {
        // REMIND: this hack tries to ensure that we have a cached texture
        srcData = dstData.getSourceSurfaceData(img, SunGraphics2D.TRANSFORM_ISIDENT, CompositeType.SrcOver, null);
        if (!(srcData instanceof OGLSurfaceData)) {
            return false;
        }
    }
    // Verify that the source surface is actually a texture and
    // that the operation is supported
    OGLSurfaceData oglSrc = (OGLSurfaceData) srcData;
    OGLGraphicsConfig gc = oglSrc.getOGLGraphicsConfig();
    if (oglSrc.getType() != OGLSurfaceData.TEXTURE || !gc.isCapPresent(CAPS_EXT_BIOP_SHADER)) {
        return false;
    }
    int sw = img.getWidth();
    int sh = img.getHeight();
    OGLBlitLoops.IsoBlit(srcData, dstData, img, biop, sg.composite, sg.getCompClip(), sg.transform, sg.interpolationType, 0, 0, sw, sh, x, y, x + sw, y + sh, true);
    return true;
}
Also used : RescaleOp(java.awt.image.RescaleOp) SurfaceData(sun.java2d.SurfaceData) ConvolveOp(java.awt.image.ConvolveOp) LookupOp(java.awt.image.LookupOp)

Example 4 with RescaleOp

use of java.awt.image.RescaleOp in project cytoscape-impl by cytoscape.

the class ImageAnnotationImpl method resizeImage.

// Returns a resizeImaged high quality BufferedImage
private BufferedImage resizeImage(int width, int height) {
    if (image == null) {
        if (width == 0)
            width = 1;
        if (height == 0)
            height = 1;
        return new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
    }
    int type = image.getType() == 0 ? BufferedImage.TYPE_INT_RGB : image.getType();
    if (height == 0)
        height++;
    if (width == 0)
        width++;
    BufferedImage adjustedImage = image;
    // Handle image adjustments
    if (contrast != 0 || brightness != 0) {
        BufferedImage source = image;
        // This only works for RGB
        if (type != BufferedImage.TYPE_INT_RGB) {
            BufferedImage rgbImage = new BufferedImage(image.getWidth(), image.getHeight(), BufferedImage.TYPE_INT_RGB);
            Graphics2D g = rgbImage.createGraphics();
            g.drawImage(image, 0, 0, image.getWidth(), image.getHeight(), this);
            source = rgbImage;
        }
        adjustedImage = new BufferedImage(image.getWidth(), image.getHeight(), BufferedImage.TYPE_INT_RGB);
        // Do Brightness first...
        // offset goes from -255 - 255 for RGB
        float offset = (float) brightness * 255.0f / 100.0f;
        RescaleOp op = new RescaleOp(1.0f, offset, null);
        op.filter(source, adjustedImage);
        float scaleFactor = 1.0f;
        // scaleFactor goes from 0-4.0 with a
        if (contrast <= 0) {
            scaleFactor = 1.0f + ((float) contrast) / 100.0f;
        } else
            scaleFactor = 1.0f + ((float) contrast) * 3.0f / 100.0f;
        op = new RescaleOp(scaleFactor, 0.0f, null);
        op.filter(adjustedImage, adjustedImage);
    }
    BufferedImage newImage = new BufferedImage(width, height, type);
    Graphics2D g = newImage.createGraphics();
    g.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR);
    g.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
    g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    g.drawImage(adjustedImage, 0, 0, width, height, this);
    g.dispose();
    return newImage;
}
Also used : RescaleOp(java.awt.image.RescaleOp) BufferedImage(java.awt.image.BufferedImage) Paint(java.awt.Paint) Graphics2D(java.awt.Graphics2D)

Example 5 with RescaleOp

use of java.awt.image.RescaleOp in project CCEmuX by CCEmuX.

the class TerminalComponent method drawChar.

private void drawChar(AWTTerminalFont font, Graphics g, char c, int x, int y, int color) {
    if (c == '\0' || Character.isSpaceChar(c))
        // nothing to do here
        return;
    Rectangle r = font.getCharCoords(c);
    Color colour = paletteCacher.getColor(color);
    BufferedImage charImg = null;
    float[] zero = new float[4];
    try {
        charImg = charImgCache.get(Pair.of(c, colour), () -> {
            float[] rgb = new float[4];
            colour.getRGBComponents(rgb);
            RescaleOp rop = new RescaleOp(rgb, zero, null);
            GraphicsConfiguration gc = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().getDefaultConfiguration();
            BufferedImage img = font.getBitmap().getSubimage(r.x, r.y, r.width, r.height);
            BufferedImage pixel = gc.createCompatibleImage(r.width, r.height, Transparency.TRANSLUCENT);
            Graphics ig = pixel.getGraphics();
            ig.drawImage(img, 0, 0, null);
            ig.dispose();
            rop.filter(pixel, pixel);
            return pixel;
        });
    } catch (ExecutionException e) {
        log.error("Could not retrieve char image from cache!", e);
    }
    g.drawImage(charImg, x, y, pixelWidth, pixelHeight, null);
}
Also used : RescaleOp(java.awt.image.RescaleOp) Graphics(java.awt.Graphics) Color(java.awt.Color) Rectangle(java.awt.Rectangle) ExecutionException(java.util.concurrent.ExecutionException) BufferedImage(java.awt.image.BufferedImage) GraphicsConfiguration(java.awt.GraphicsConfiguration)

Aggregations

RescaleOp (java.awt.image.RescaleOp)22 BufferedImage (java.awt.image.BufferedImage)16 Graphics2D (java.awt.Graphics2D)3 ArrayList (java.util.ArrayList)3 List (java.util.List)3 Color (java.awt.Color)2 BufferedImageOp (java.awt.image.BufferedImageOp)2 ConvolveOp (java.awt.image.ConvolveOp)2 LookupOp (java.awt.image.LookupOp)2 SurfaceData (sun.java2d.SurfaceData)2 Dimension (java.awt.Dimension)1 Graphics (java.awt.Graphics)1 GraphicsConfiguration (java.awt.GraphicsConfiguration)1 Paint (java.awt.Paint)1 Rectangle (java.awt.Rectangle)1 Rectangle2D (java.awt.geom.Rectangle2D)1 ColorConvertOp (java.awt.image.ColorConvertOp)1 File (java.io.File)1 URL (java.net.URL)1 ExecutionException (java.util.concurrent.ExecutionException)1