Search in sources :

Example 6 with ConvolveOp

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

the class ImagingLib method filter.

public static WritableRaster filter(RasterOp op, Raster src, WritableRaster dst) {
    if (useLib == false) {
        return null;
    }
    // Create the destination tile
    if (dst == null) {
        dst = op.createCompatibleDestRaster(src);
    }
    WritableRaster retRaster = null;
    switch(getNativeOpIndex(op.getClass())) {
        case LOOKUP_OP:
            // REMIND: Fix this!
            LookupTable table = ((LookupOp) op).getTable();
            if (table.getOffset() != 0) {
                // Right now the native code doesn't support offsets
                return null;
            }
            if (table instanceof ByteLookupTable) {
                ByteLookupTable bt = (ByteLookupTable) table;
                if (lookupByteRaster(src, dst, bt.getTable()) > 0) {
                    retRaster = dst;
                }
            }
            break;
        case AFFINE_OP:
            AffineTransformOp bOp = (AffineTransformOp) op;
            double[] matrix = new double[6];
            bOp.getTransform().getMatrix(matrix);
            if (transformRaster(src, dst, matrix, bOp.getInterpolationType()) > 0) {
                retRaster = dst;
            }
            break;
        case CONVOLVE_OP:
            ConvolveOp cOp = (ConvolveOp) op;
            if (convolveRaster(src, dst, cOp.getKernel(), cOp.getEdgeCondition()) > 0) {
                retRaster = dst;
            }
            break;
        default:
            break;
    }
    if (retRaster != null) {
        SunWritableRaster.markDirty(retRaster);
    }
    return retRaster;
}
Also used : WritableRaster(java.awt.image.WritableRaster) ByteLookupTable(java.awt.image.ByteLookupTable) LookupTable(java.awt.image.LookupTable) ConvolveOp(java.awt.image.ConvolveOp) LookupOp(java.awt.image.LookupOp) ByteLookupTable(java.awt.image.ByteLookupTable) AffineTransformOp(java.awt.image.AffineTransformOp)

Example 7 with ConvolveOp

use of java.awt.image.ConvolveOp 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 8 with ConvolveOp

use of java.awt.image.ConvolveOp 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 9 with ConvolveOp

use of java.awt.image.ConvolveOp in project libgdx by libgdx.

the class ShadowEffect method blur.

private void blur(BufferedImage image) {
    float[] matrix = GAUSSIAN_BLUR_KERNELS[blurKernelSize - 1];
    Kernel gaussianBlur1 = new Kernel(matrix.length, 1, matrix);
    Kernel gaussianBlur2 = new Kernel(1, matrix.length, matrix);
    RenderingHints hints = new RenderingHints(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_SPEED);
    ConvolveOp gaussianOp1 = new ConvolveOp(gaussianBlur1, ConvolveOp.EDGE_NO_OP, hints);
    ConvolveOp gaussianOp2 = new ConvolveOp(gaussianBlur2, ConvolveOp.EDGE_NO_OP, hints);
    BufferedImage scratchImage = EffectUtil.getScratchImage();
    for (int i = 0; i < blurPasses; i++) {
        gaussianOp1.filter(image, scratchImage);
        gaussianOp2.filter(scratchImage, image);
    }
}
Also used : ConvolveOp(java.awt.image.ConvolveOp) Kernel(java.awt.image.Kernel) RenderingHints(java.awt.RenderingHints) BufferedImage(java.awt.image.BufferedImage)

Example 10 with ConvolveOp

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

the class ImagingLib method filter.

public static BufferedImage filter(BufferedImageOp op, BufferedImage src, BufferedImage dst) {
    if (verbose) {
        System.out.println("in filter and op is " + op + "bufimage is " + src + " and " + dst);
    }
    if (useLib == false) {
        return null;
    }
    // Create the destination image
    if (dst == null) {
        dst = op.createCompatibleDestImage(src, null);
    }
    BufferedImage retBI = null;
    switch(getNativeOpIndex(op.getClass())) {
        case LOOKUP_OP:
            // REMIND: Fix this!
            LookupTable table = ((LookupOp) op).getTable();
            if (table.getOffset() != 0) {
                // Right now the native code doesn't support offsets
                return null;
            }
            if (table instanceof ByteLookupTable) {
                ByteLookupTable bt = (ByteLookupTable) table;
                if (lookupByteBI(src, dst, bt.getTable()) > 0) {
                    retBI = dst;
                }
            }
            break;
        case AFFINE_OP:
            AffineTransformOp bOp = (AffineTransformOp) op;
            double[] matrix = new double[6];
            AffineTransform xform = bOp.getTransform();
            bOp.getTransform().getMatrix(matrix);
            if (transformBI(src, dst, matrix, bOp.getInterpolationType()) > 0) {
                retBI = dst;
            }
            break;
        case CONVOLVE_OP:
            ConvolveOp cOp = (ConvolveOp) op;
            if (convolveBI(src, dst, cOp.getKernel(), cOp.getEdgeCondition()) > 0) {
                retBI = dst;
            }
            break;
        default:
            break;
    }
    if (retBI != null) {
        SunWritableRaster.markDirty(retBI);
    }
    return retBI;
}
Also used : ByteLookupTable(java.awt.image.ByteLookupTable) LookupTable(java.awt.image.LookupTable) AffineTransform(java.awt.geom.AffineTransform) ConvolveOp(java.awt.image.ConvolveOp) LookupOp(java.awt.image.LookupOp) ByteLookupTable(java.awt.image.ByteLookupTable) BufferedImage(java.awt.image.BufferedImage) AffineTransformOp(java.awt.image.AffineTransformOp)

Aggregations

ConvolveOp (java.awt.image.ConvolveOp)12 Kernel (java.awt.image.Kernel)7 BufferedImage (java.awt.image.BufferedImage)5 LookupOp (java.awt.image.LookupOp)4 Color (java.awt.Color)3 GradientPaint (java.awt.GradientPaint)3 Graphics2D (java.awt.Graphics2D)3 Font (java.awt.Font)2 FontMetrics (java.awt.FontMetrics)2 Rectangle2D (java.awt.geom.Rectangle2D)2 RoundRectangle2D (java.awt.geom.RoundRectangle2D)2 AffineTransformOp (java.awt.image.AffineTransformOp)2 ByteLookupTable (java.awt.image.ByteLookupTable)2 LookupTable (java.awt.image.LookupTable)2 RescaleOp (java.awt.image.RescaleOp)2 WritableRaster (java.awt.image.WritableRaster)2 SurfaceData (sun.java2d.SurfaceData)2 BasicStroke (java.awt.BasicStroke)1 Point (java.awt.Point)1 RadialGradientPaint (java.awt.RadialGradientPaint)1