Search in sources :

Example 16 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 17 with ConvolveOp

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

the class EdgeNoOpCrash method crashTest.

private static void crashTest() {
    Raster src = createSrcRaster();
    WritableRaster dst = createDstRaster();
    ConvolveOp op = createConvolveOp(ConvolveOp.EDGE_NO_OP);
    try {
        op.filter(src, dst);
    } catch (ImagingOpException e) {
    /*
             * The test pair of source and destination rasters
             * may cause failure of the medialib convolution routine,
             * so this exception is expected.
             *
             * The JVM crash is the only manifestation of this
             * test failure.
             */
    }
    System.out.println("Test PASSED.");
}
Also used : WritableRaster(java.awt.image.WritableRaster) Raster(java.awt.image.Raster) WritableRaster(java.awt.image.WritableRaster) ImagingOpException(java.awt.image.ImagingOpException) ConvolveOp(java.awt.image.ConvolveOp)

Example 18 with ConvolveOp

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

the class MlibOpsTest method getConvolveOp.

private static BufferedImageOp getConvolveOp() {
    int kw = 3;
    int kh = 3;
    int size = kw * kh;
    float[] kdata = new float[size];
    Arrays.fill(kdata, 1.0f / size);
    Kernel k = new Kernel(kw, kh, kdata);
    return new ConvolveOp(k);
}
Also used : ConvolveOp(java.awt.image.ConvolveOp) Kernel(java.awt.image.Kernel) RadialGradientPaint(java.awt.RadialGradientPaint)

Example 19 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)

Example 20 with ConvolveOp

use of java.awt.image.ConvolveOp in project Spark by igniterealtime.

the class RoundLabel method paintComponent.

protected void paintComponent(Graphics g) {
    super.paintComponent(g);
    Graphics2D g2 = (Graphics2D) g;
    g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    int vWidth = getWidth();
    int vHeight = getHeight();
    // Calculate the size of the button
    int vButtonHeight = vHeight - (inset * 2);
    int vButtonWidth = vWidth - (inset * 2);
    BufferedImage vBuffer = new BufferedImage(vWidth, vHeight, BufferedImage.TYPE_INT_RGB);
    Graphics2D bg = vBuffer.createGraphics();
    bg.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    // Paint the background of the button
    bg.setColor(Color.white);
    bg.fillRect(0, 0, vWidth, vHeight);
    // Create the gradient paint for the first layer of the button
    Color vGradientStartColor = buttonColor;
    Color vGradientEndColor = buttonColor;
    Paint vPaint = new GradientPaint(0, inset, vGradientStartColor, 0, vButtonHeight, vGradientEndColor, false);
    bg.setPaint(vPaint);
    // Paint the first layer of the button
    // , vArcSize, vArcSize);
    bg.fillRect(inset, inset, vButtonWidth, vButtonHeight);
    // Calulate the size of the second layer of the button
    int vHighlightInset = 2;
    int vButtonHighlightHeight = vButtonHeight - (vHighlightInset * 2);
    int vButtonHighlightWidth = vButtonWidth - (vHighlightInset * 2);
    bg.setClip(new RoundRectangle2D.Float(inset + vHighlightInset, inset + vHighlightInset, vButtonHighlightWidth, vButtonHighlightHeight / 2, vButtonHighlightHeight / 3, vButtonHighlightHeight / 3));
    // bg.fillRoundRect(inset + vHighlightInset, inset + vHighlightInset, vButtonHighlightWidth, vButtonHighlightHeight, vHighlightArcSize, vHighlightArcSize);
    // Blur the button
    ConvolveOp vBlurOp = new ConvolveOp(new Kernel(3, 3, BLUR));
    BufferedImage vBlurredBase = vBlurOp.filter(vBuffer, null);
    // Draw our aqua button
    g2.drawImage(vBlurredBase, 0, 0, null);
    // Draw the text (if any)
    if (text != null) {
        g2.setColor(foregroundColor);
        Font vFont = g2.getFont().deriveFont((float) (((float) vButtonHeight) * .6));
        g2.setFont(vFont);
        FontMetrics vMetrics = g2.getFontMetrics();
        Rectangle2D vStringBounds = vMetrics.getStringBounds(text, g2);
        float x = (float) ((vWidth / 2) - (vStringBounds.getWidth() / 2));
        float y = (float) ((vHeight / 2) + (vStringBounds.getHeight() / 2)) - vMetrics.getDescent();
        g2.drawString(text, x, y);
    }
}
Also used : Color(java.awt.Color) RoundRectangle2D(java.awt.geom.RoundRectangle2D) Rectangle2D(java.awt.geom.Rectangle2D) RoundRectangle2D(java.awt.geom.RoundRectangle2D) GradientPaint(java.awt.GradientPaint) Paint(java.awt.Paint) GradientPaint(java.awt.GradientPaint) Paint(java.awt.Paint) GradientPaint(java.awt.GradientPaint) BufferedImage(java.awt.image.BufferedImage) Font(java.awt.Font) Graphics2D(java.awt.Graphics2D) FontMetrics(java.awt.FontMetrics) ConvolveOp(java.awt.image.ConvolveOp) Kernel(java.awt.image.Kernel)

Aggregations

ConvolveOp (java.awt.image.ConvolveOp)26 Kernel (java.awt.image.Kernel)21 BufferedImage (java.awt.image.BufferedImage)15 Color (java.awt.Color)4 GradientPaint (java.awt.GradientPaint)4 Graphics2D (java.awt.Graphics2D)4 LookupOp (java.awt.image.LookupOp)4 Font (java.awt.Font)3 FontMetrics (java.awt.FontMetrics)3 Rectangle2D (java.awt.geom.Rectangle2D)3 RoundRectangle2D (java.awt.geom.RoundRectangle2D)3 Point (java.awt.Point)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 JPEGEncodeParam (com.sun.image.codec.jpeg.JPEGEncodeParam)1 JPEGImageEncoder (com.sun.image.codec.jpeg.JPEGImageEncoder)1