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);
}
}
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.");
}
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);
}
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;
}
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);
}
}
Aggregations