Java Code Examples for java.awt.image.ConvolveOp#filter()
The following examples show how to use
java.awt.image.ConvolveOp#filter() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ImageComparisonUtil.java From image-comparison with Apache License 2.0 | 6 votes |
/** * Convert image to buffered image. * * @param img the object of the image to be converted to buffered image. * @return the converted buffered image. */ public static BufferedImage toBufferedImage(Image img) { if (img instanceof BufferedImage) { return (BufferedImage) img; } float softenFactor = 0.05f; final Image temp = new ImageIcon(img).getImage(); final BufferedImage bufferedImage = new BufferedImage( temp.getWidth(null), temp.getHeight(null), BufferedImage.TYPE_INT_RGB); final Graphics g = bufferedImage.createGraphics(); g.setColor(Color.white); g.fillRect(0, 0, temp.getWidth(null), temp.getHeight(null)); g.drawImage(temp, 0, 0, null); g.dispose(); final float[] softenArray = {0, softenFactor, 0, softenFactor, 1 - (softenFactor * 4), softenFactor, 0, softenFactor, 0}; final Kernel kernel = new Kernel(3, 3, softenArray); final ConvolveOp cOp = new ConvolveOp(kernel, ConvolveOp.EDGE_NO_OP, null); return cOp.filter(bufferedImage, null); }
Example 2
Source File: EdgeNoOpCrash.java From jdk8u_jdk with GNU General Public License v2.0 | 6 votes |
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."); }
Example 3
Source File: EdgeNoOpCrash.java From openjdk-8 with GNU General Public License v2.0 | 6 votes |
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."); }
Example 4
Source File: EdgeNoOpCrash.java From openjdk-8-source with GNU General Public License v2.0 | 6 votes |
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."); }
Example 5
Source File: EdgeNoOpCrash.java From hottub with GNU General Public License v2.0 | 6 votes |
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."); }
Example 6
Source File: EdgeNoOpCrash.java From jdk8u-jdk with GNU General Public License v2.0 | 6 votes |
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."); }
Example 7
Source File: EdgeNoOpCrash.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 6 votes |
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."); }
Example 8
Source File: EdgeNoOpCrash.java From dragonwell8_jdk with GNU General Public License v2.0 | 6 votes |
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."); }
Example 9
Source File: EdgeNoOpCrash.java From openjdk-jdk8u with GNU General Public License v2.0 | 6 votes |
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."); }
Example 10
Source File: EdgeNoOpCrash.java From jdk8u60 with GNU General Public License v2.0 | 6 votes |
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."); }
Example 11
Source File: EdgeNoOpCrash.java From TencentKona-8 with GNU General Public License v2.0 | 6 votes |
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."); }
Example 12
Source File: ShadowEffect.java From slick2d-maven with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * Apply blurring to the generate image * * @param image The image to be blurred */ 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); } }
Example 13
Source File: ImageToolkit.java From jump-jump-game with Apache License 2.0 | 5 votes |
public static final BufferedImage dlur(BufferedImage oBi) { int imageWidth = oBi.getWidth(); int imageHeight = oBi.getHeight(); BufferedImage nBi = new BufferedImage(imageWidth, imageHeight, BufferedImage.TYPE_3BYTE_BGR); float[] data = { 0.0625f, 0.125f, 0.0625f, 0.125f, 0.125f, 0.125f, 0.0625f, 0.125f, 0.0625f }; Kernel kernel = new Kernel(3, 3, data); ConvolveOp co = new ConvolveOp(kernel, ConvolveOp.EDGE_NO_OP, null); co.filter(oBi, nBi); return nBi; }
Example 14
Source File: VistaSearchDialog.java From filthy-rich-clients with BSD 3-Clause "New" or "Revised" License | 5 votes |
public VistaSearchDialog(JFrame frame) { Container contentPane = frame.getRootPane(); image = GraphicsUtilities.createCompatibleTranslucentImage(contentPane.getWidth() + 2 * (int) BLUR_SIZE, contentPane.getHeight() + 2 * (int) BLUR_SIZE); Graphics2D g2 = image.createGraphics(); g2.translate(BLUR_SIZE, BLUR_SIZE); contentPane.paint(g2); g2.translate(-BLUR_SIZE, -BLUR_SIZE); g2.dispose(); // 1.5 second vs 0.3 second // long start = System.currentTimeMillis(); image = changeImageWidth(image, image.getWidth() / 2); ConvolveOp gaussianFilter = getGaussianBlurFilter(BLUR_SIZE, true); image = gaussianFilter.filter(image, null); gaussianFilter = getGaussianBlurFilter(BLUR_SIZE, false); image = gaussianFilter.filter(image, null); ColorTintFilter colorMixFilter = new ColorTintFilter(Color.WHITE, 0.4f); image = colorMixFilter.filter(image, null); image = changeImageWidth(image, image.getWidth() * 2); // System.out.println("time = " + // ((System.currentTimeMillis() - start) / 1000.0f)); setBorder(new DropShadowBorder(Color.BLACK, 0, 11, .2f, 16, false, true, true, true)); setLayout(new BorderLayout()); initComponents(); }
Example 15
Source File: ImageConvolution.java From MyBox with Apache License 2.0 | 5 votes |
public static BufferedImage applyConvolveOp(BufferedImage source, ConvolveOp imageOp) { if (source == null || imageOp == null) { return source; } int width = source.getWidth(); int height = source.getHeight(); int imageType = source.getType(); if (imageType == BufferedImage.TYPE_CUSTOM) { imageType = BufferedImage.TYPE_INT_ARGB; } BufferedImage target = new BufferedImage(width, height, imageType); imageOp.filter(source, target); return target; }
Example 16
Source File: ApplicationFrame.java From filthy-rich-clients with BSD 3-Clause "New" or "Revised" License | 5 votes |
private void buildConvolveOpTab(JTabbedPane tabbedPane) { BufferedImage dstImage = null; float[] sharpen = new float[] { 0.0f, -1.0f, 0.0f, -1.0f, 5.0f, -1.0f, 0.0f, -1.0f, 0.0f }; Kernel kernel = new Kernel(3, 3, sharpen); ConvolveOp op = new ConvolveOp(kernel); dstImage = op.filter(sourceImage, null); tabbedPane.add("Convolve", new JLabel(new ImageIcon(dstImage))); }
Example 17
Source File: ToolImageResize.java From protools with Apache License 2.0 | 4 votes |
/** * 缩放gif图片 * * @param originalFile * 原图片 * @param resizedFile * 缩放后的图片 * @param newWidth * 宽度 * @param quality * 缩放比例 (等比例) * * @throws IOException */ private static void resize(File originalFile, File resizedFile, int newWidth, float quality) throws IOException { if (quality < 0 || quality > 1) { throw new IllegalArgumentException("Quality has to be between 0 and 1"); } ImageIcon ii = new ImageIcon(originalFile.getCanonicalPath()); Image i = ii.getImage(); Image resizedImage = null; int iWidth = i.getWidth(null); int iHeight = i.getHeight(null); if (iWidth > iHeight) { resizedImage = i.getScaledInstance(newWidth, (newWidth * iHeight) / iWidth, Image.SCALE_SMOOTH); } else { resizedImage = i.getScaledInstance((newWidth * iWidth) / iHeight, newWidth, Image.SCALE_SMOOTH); } // This code ensures that all the pixels in the image are loaded. Image temp = new ImageIcon(resizedImage).getImage(); // Create the buffered image. BufferedImage bufferedImage = new BufferedImage(temp.getWidth(null), temp.getHeight(null), BufferedImage.TYPE_INT_RGB); // Copy image to buffered image. Graphics g = bufferedImage.createGraphics(); // Clear background and paint the image. g.setColor(Color.white); g.fillRect(0, 0, temp.getWidth(null), temp.getHeight(null)); g.drawImage(temp, 0, 0, null); g.dispose(); // Soften. float softenFactor = 0.05f; float[] softenArray = {0, softenFactor, 0, softenFactor, 1 - (softenFactor * 4), softenFactor, 0, softenFactor, 0}; Kernel kernel = new Kernel(3, 3, softenArray); ConvolveOp cOp = new ConvolveOp(kernel, ConvolveOp.EDGE_NO_OP, null); bufferedImage = cOp.filter(bufferedImage, null); // Write the jpeg to a file. try ( FileOutputStream out = new FileOutputStream(resizedFile)) { ImageWriter imageWriter = ImageIO.getImageWritersBySuffix("jpg").next(); ImageOutputStream ios = ImageIO.createImageOutputStream(out); imageWriter.setOutput(ios); //and metadata IIOMetadata imageMetaData = imageWriter.getDefaultImageMetadata(new ImageTypeSpecifier(bufferedImage), null); JPEGImageWriteParam jpegParams = (JPEGImageWriteParam) imageWriter.getDefaultWriteParam(); jpegParams.setCompressionMode(JPEGImageWriteParam.MODE_EXPLICIT); jpegParams.setCompressionQuality(quality); imageWriter.write(imageMetaData, new IIOImage(bufferedImage, null, null), jpegParams); } }
Example 18
Source File: NoiseFactory.java From radiance with BSD 3-Clause "New" or "Revised" License | 4 votes |
/** * Returns a noise image. * * @param skin The skin to use for rendering the image. * @param width Image width. * @param height Image height. * @param xFactor X stretch factor. * @param yFactor Y stretch factor. * @param hasConstantZ Indication whether the Z is constant. * @param noiseFilter Noise filter to apply. * @param toBlur Indication whether the resulting image should be blurred. * @param isPreview Indication whether the image is in preview mode. * @return Noise image. */ public static BufferedImage getNoiseImage(SubstanceSkin skin, int width, int height, double xFactor, double yFactor, boolean hasConstantZ, NoiseFilter noiseFilter, boolean toBlur, boolean isPreview) { SubstanceColorScheme scheme = skin.getWatermarkColorScheme(); Color c1 = scheme.getWatermarkDarkColor(); // c1 = new Color(255, 0, 0, 0); // System.out.println(c1.getAlpha()); // Color c2 = scheme.getWatermarkStampColor(); Color c3 = scheme.getWatermarkLightColor(); BufferedImage dst = NeonCortex.getBlankImage(width, height); // // new BufferedImage(width, height, // BufferedImage.TYPE_INT_ARGB); // Borrow from Sebastien Petrucci fast blur code - direct access // to the raster data int[] dstBuffer = ((DataBufferInt) dst.getRaster().getDataBuffer()) .getData(); // System.out.println((dstBuffer[0] >>> 24) & 0xFF); int imageWidth = dst.getWidth(); int imageHeight = dst.getHeight(); double m2 = xFactor * imageWidth * xFactor * imageWidth + yFactor * imageHeight * yFactor * imageHeight; int pos = 0; for (int j = 0; j < imageHeight; j++) { double jj = yFactor * j; for (int i = 0; i < imageWidth; i++) { double ii = xFactor * i; double z = hasConstantZ ? 1.0 : Math.sqrt(m2 - ii * ii - jj * jj); double noise = 0.5 + 0.5 * PerlinNoiseGenerator .noise(ii, jj, z); if (noiseFilter != null) noise = noiseFilter.apply(i, j, z, noise); double likeness = Math.max(0.0, Math.min(1.0, 2.0 * noise)); // likeness = 0.0; dstBuffer[pos++] = SubstanceColorUtilities.getInterpolatedRGB( c3, c1, likeness); } } // System.out.println((dstBuffer[0] >>> 24) & 0xFF); if (toBlur) { float edgeBlur = 0.08f / (float) NeonCortex.getScaleFactor(); ConvolveOp convolve = new ConvolveOp(new Kernel(3, 3, new float[] { edgeBlur, edgeBlur, edgeBlur, edgeBlur, 1.06f - 8 * edgeBlur, edgeBlur, edgeBlur, edgeBlur, edgeBlur }), ConvolveOp.EDGE_NO_OP, null); dst = convolve.filter(dst, NeonCortex.getBlankImage(width, height)); } return dst; }
Example 19
Source File: NoiseFactory.java From radiance with BSD 3-Clause "New" or "Revised" License | 4 votes |
/** * Returns a noise image. * * @param scheme * The color scheme to use for rendering the image. * @param width * Image width. * @param height * Image height. * @param xFactor * X stretch factor. * @param yFactor * Y stretch factor. * @param hasConstantZ * Indication whether the Z is constant. * @param toBlur * Indication whether the resulting image should be blurred. * @return Noise image. */ public static BufferedImage getNoiseImage(SubstanceColorScheme scheme, int width, int height, double xFactor, double yFactor, boolean hasConstantZ, boolean toBlur) { Color c1 = scheme.getWatermarkDarkColor(); // c1 = new Color(255, 0, 0, 0); // System.out.println(c1.getAlpha()); // Color c2 = scheme.getWatermarkStampColor(); Color c3 = scheme.getWatermarkLightColor(); // Note that we are starting with non-hi DPI aware image for creating the // source for the noise BufferedImage dst = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB); // Borrow from Sebastien Petrucci fast blur code - direct access // to the raster data int[] dstBuffer = ((DataBufferInt) dst.getRaster().getDataBuffer()) .getData(); // System.out.println((dstBuffer[0] >>> 24) & 0xFF); double m2 = xFactor * width * xFactor * width + yFactor * height * yFactor * height; int pos = 0; for (int j = 0; j < height; j++) { double jj = yFactor * j; for (int i = 0; i < width; i++) { double ii = xFactor * i; double z = hasConstantZ ? 1.0 : Math.sqrt(m2 - ii * ii - jj * jj); double noise = 0.5 + 0.5 * PerlinNoiseGenerator.noise(ii, jj, z); double likeness = Math.max(0.0, Math.min(1.0, 2.0 * noise)); // likeness = 0.0; dstBuffer[pos++] = SubstanceColorUtilities.getInterpolatedRGB( c3, c1, likeness); } } // System.out.println((dstBuffer[0] >>> 24) & 0xFF); if (toBlur) { // and staying here with non-hi DPI aware image for blurred noise ConvolveOp convolve = new ConvolveOp(new Kernel(3, 3, new float[] { .08f, .08f, .08f, .08f, .38f, .08f, .08f, .08f, .08f }), ConvolveOp.EDGE_NO_OP, null); dst = convolve.filter(dst, null); } // and now returning an image that is hi DPI aware if needed if (NeonCortex.getScaleFactor() > 1.0) { BufferedImage result = SubstanceCoreUtilities.getBlankImage(width, height); Graphics2D g2d = result.createGraphics(); g2d.drawImage(dst, 0, 0, null); g2d.dispose(); return result; } else { return dst; } }
Example 20
Source File: ProjectCalendarOptionPageProvider.java From ganttproject with GNU General Public License v3.0 | 4 votes |
@Override public Component buildPageComponent() { final GanttLanguage i18n = GanttLanguage.getInstance(); final Box result = Box.createVerticalBox(); myWeekendsPanel = new WeekendsSettingsPanel(getProject(), getUiFacade()); myWeekendsPanel.setAlignmentX(Component.LEFT_ALIGNMENT); myWeekendsPanel.initialize(); result.add(myWeekendsPanel); result.add(Box.createVerticalStrut(15)); myProjectStart = getProject().getTaskManager().getProjectStart(); myProjectStartOption = new DefaultDateOption("project.startDate", myProjectStart) { private TimeDuration getMoveDuration() { return getProject().getTaskManager().createLength(getProject().getTimeUnitStack().getDefaultTimeUnit(), getInitialValue(), getValue()); } @Override public void setValue(Date value) { super.setValue(value); TimeDuration moveDuration = getMoveDuration(); if (moveDuration.getLength() != 0) { updateMoveOptions(moveDuration); } } @Override public void commit() { super.commit(); if (!isChanged()) { return; } try { moveProject(getMoveDuration()); } catch (AlgorithmException e) { getUiFacade().showErrorDialog(e); } } }; myMoveOptionsPanel = Box.createVerticalBox(); myMoveOptionsPanel.setAlignmentX(Component.LEFT_ALIGNMENT); Box dateComponent = Box.createHorizontalBox(); OptionsPageBuilder builder = new OptionsPageBuilder(); dateComponent.add(new JLabel(i18n.getText(builder.getI18N().getCanonicalOptionLabelKey(myProjectStartOption)))); dateComponent.add(Box.createHorizontalStrut(3)); dateComponent.add(builder.createDateComponent(myProjectStartOption)); dateComponent.setAlignmentX(Component.LEFT_ALIGNMENT); myMoveOptionsPanel.add(dateComponent); myMoveOptionsPanel.add(Box.createVerticalStrut(5)); myMoveStrategyPanelWrapper = new JPanel(new BorderLayout()) { @Override public void paint(Graphics g) { if (isEnabled()) { super.paint(g); return; } final BufferedImage buf = new BufferedImage(getWidth(), getHeight(), BufferedImage.TYPE_INT_RGB); super.paint(buf.getGraphics()); final float[] my_kernel = { 0.0625f, 0.125f, 0.0625f, 0.125f, 0.25f, 0.125f, 0.0625f, 0.125f, 0.0625f }; final ConvolveOp op = new ConvolveOp(new Kernel(3, 3, my_kernel), ConvolveOp.EDGE_NO_OP, null); Image img = op.filter(buf, null); g.drawImage(img, 0, 0, null); } }; myMoveStrategyPanelWrapper.setAlignmentX(Component.LEFT_ALIGNMENT); myMoveAllTasks = new JRadioButton(i18n.getText("project.calendar.moveAll.label")); myMoveAllTasks.setAlignmentX(Component.LEFT_ALIGNMENT); myMoveStartingTasks = new JRadioButton(MessageFormat.format(i18n.getText("project.calendar.moveSome.label"), i18n.formatDate(CalendarFactory.createGanttCalendar(myProjectStart)))); myMoveStartingTasks.setAlignmentX(Component.LEFT_ALIGNMENT); ButtonGroup moveGroup = new ButtonGroup(); moveGroup.add(myMoveAllTasks); moveGroup.add(myMoveStartingTasks); moveGroup.setSelected(myMoveAllTasks.getModel(), true); Box moveStrategyPanel = Box.createVerticalBox(); myMoveDurationLabel = new JLabel(); myMoveDurationLabel.setAlignmentX(Component.LEFT_ALIGNMENT); moveStrategyPanel.add(myMoveDurationLabel); moveStrategyPanel.add(myMoveAllTasks); moveStrategyPanel.add(myMoveStartingTasks); myMoveStrategyPanelWrapper.add(moveStrategyPanel, BorderLayout.CENTER); myMoveOptionsPanel.add(Box.createVerticalStrut(3)); myMoveOptionsPanel.add(myMoveStrategyPanelWrapper); UIUtil.createTitle(myMoveOptionsPanel, i18n.getText("project.calendar.move.title")); result.add(myMoveOptionsPanel); updateMoveOptions(getProject().getTaskManager().createLength(0)); return OptionPageProviderBase.wrapContentComponent(result, getCanonicalPageTitle(), null); }