1 /* 2 * Copyright (c) 1997, 2000, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. Oracle designates this 8 * particular file as subject to the "Classpath" exception as provided 9 * by Oracle in the LICENSE file that accompanied this code. 10 * 11 * This code is distributed in the hope that it will be useful, but WITHOUT 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 * version 2 for more details (a copy is included in the LICENSE file that 15 * accompanied this code). 16 * 17 * You should have received a copy of the GNU General Public License version 18 * 2 along with this work; if not, write to the Free Software Foundation, 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 * 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 * or visit www.oracle.com if you need additional information or have any 23 * questions. 24 */ 25 26 package java.awt.image; 27 28 import java.awt.color.ICC_Profile; 29 import java.awt.geom.Rectangle2D; 30 import java.awt.Rectangle; 31 import java.awt.RenderingHints; 32 import java.awt.geom.Point2D; 33 import javax.tools.annotation.GenerateNativeHeader; 34 import sun.awt.image.ImagingLib; 35 36 /** 37 * This class implements a convolution from the source 38 * to the destination. 39 * Convolution using a convolution kernel is a spatial operation that 40 * computes the output pixel from an input pixel by multiplying the kernel 41 * with the surround of the input pixel. 42 * This allows the output pixel to be affected by the immediate neighborhood 43 * in a way that can be mathematically specified with a kernel. 44 *<p> 45 * This class operates with BufferedImage data in which color components are 46 * premultiplied with the alpha component. If the Source BufferedImage has 47 * an alpha component, and the color components are not premultiplied with 48 * the alpha component, then the data are premultiplied before being 49 * convolved. If the Destination has color components which are not 50 * premultiplied, then alpha is divided out before storing into the 51 * Destination (if alpha is 0, the color components are set to 0). If the 52 * Destination has no alpha component, then the resulting alpha is discarded 53 * after first dividing it out of the color components. 54 * <p> 55 * Rasters are treated as having no alpha channel. If the above treatment 56 * of the alpha channel in BufferedImages is not desired, it may be avoided 57 * by getting the Raster of a source BufferedImage and using the filter method 58 * of this class which works with Rasters. 59 * <p> 60 * If a RenderingHints object is specified in the constructor, the 61 * color rendering hint and the dithering hint may be used when color 62 * conversion is required. 63 *<p> 64 * Note that the Source and the Destination may not be the same object. 65 * @see Kernel 66 * @see java.awt.RenderingHints#KEY_COLOR_RENDERING 67 * @see java.awt.RenderingHints#KEY_DITHERING 68 */ 69 /* No native methods here, but the constants are needed in the supporting JNI code */ 70 @GenerateNativeHeader 71 public class ConvolveOp implements BufferedImageOp, RasterOp { 72 Kernel kernel; 73 int edgeHint; 74 RenderingHints hints; 75 /** 76 * Edge condition constants. 77 */ 78 79 /** 80 * Pixels at the edge of the destination image are set to zero. This 81 * is the default. 82 */ 83 84 public static final int EDGE_ZERO_FILL = 0; 85 86 /** 87 * Pixels at the edge of the source image are copied to 88 * the corresponding pixels in the destination without modification. 89 */ 90 public static final int EDGE_NO_OP = 1; 91 92 /** 93 * Constructs a ConvolveOp given a Kernel, an edge condition, and a 94 * RenderingHints object (which may be null). 95 * @param kernel the specified <code>Kernel</code> 96 * @param edgeCondition the specified edge condition 97 * @param hints the specified <code>RenderingHints</code> object 98 * @see Kernel 99 * @see #EDGE_NO_OP 100 * @see #EDGE_ZERO_FILL 101 * @see java.awt.RenderingHints 102 */ 103 public ConvolveOp(Kernel kernel, int edgeCondition, RenderingHints hints) { 104 this.kernel = kernel; 105 this.edgeHint = edgeCondition; 106 this.hints = hints; 107 } 108 109 /** 110 * Constructs a ConvolveOp given a Kernel. The edge condition | 1 /* 2 * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. Oracle designates this 8 * particular file as subject to the "Classpath" exception as provided 9 * by Oracle in the LICENSE file that accompanied this code. 10 * 11 * This code is distributed in the hope that it will be useful, but WITHOUT 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 * version 2 for more details (a copy is included in the LICENSE file that 15 * accompanied this code). 16 * 17 * You should have received a copy of the GNU General Public License version 18 * 2 along with this work; if not, write to the Free Software Foundation, 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 * 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 * or visit www.oracle.com if you need additional information or have any 23 * questions. 24 */ 25 26 package java.awt.image; 27 28 import java.awt.color.ICC_Profile; 29 import java.awt.geom.Rectangle2D; 30 import java.awt.Rectangle; 31 import java.awt.RenderingHints; 32 import java.awt.geom.Point2D; 33 import java.lang.annotation.Native; 34 import sun.awt.image.ImagingLib; 35 36 /** 37 * This class implements a convolution from the source 38 * to the destination. 39 * Convolution using a convolution kernel is a spatial operation that 40 * computes the output pixel from an input pixel by multiplying the kernel 41 * with the surround of the input pixel. 42 * This allows the output pixel to be affected by the immediate neighborhood 43 * in a way that can be mathematically specified with a kernel. 44 *<p> 45 * This class operates with BufferedImage data in which color components are 46 * premultiplied with the alpha component. If the Source BufferedImage has 47 * an alpha component, and the color components are not premultiplied with 48 * the alpha component, then the data are premultiplied before being 49 * convolved. If the Destination has color components which are not 50 * premultiplied, then alpha is divided out before storing into the 51 * Destination (if alpha is 0, the color components are set to 0). If the 52 * Destination has no alpha component, then the resulting alpha is discarded 53 * after first dividing it out of the color components. 54 * <p> 55 * Rasters are treated as having no alpha channel. If the above treatment 56 * of the alpha channel in BufferedImages is not desired, it may be avoided 57 * by getting the Raster of a source BufferedImage and using the filter method 58 * of this class which works with Rasters. 59 * <p> 60 * If a RenderingHints object is specified in the constructor, the 61 * color rendering hint and the dithering hint may be used when color 62 * conversion is required. 63 *<p> 64 * Note that the Source and the Destination may not be the same object. 65 * @see Kernel 66 * @see java.awt.RenderingHints#KEY_COLOR_RENDERING 67 * @see java.awt.RenderingHints#KEY_DITHERING 68 */ 69 public class ConvolveOp implements BufferedImageOp, RasterOp { 70 Kernel kernel; 71 int edgeHint; 72 RenderingHints hints; 73 /** 74 * Edge condition constants. 75 */ 76 77 /** 78 * Pixels at the edge of the destination image are set to zero. This 79 * is the default. 80 */ 81 82 @Native public static final int EDGE_ZERO_FILL = 0; 83 84 /** 85 * Pixels at the edge of the source image are copied to 86 * the corresponding pixels in the destination without modification. 87 */ 88 @Native public static final int EDGE_NO_OP = 1; 89 90 /** 91 * Constructs a ConvolveOp given a Kernel, an edge condition, and a 92 * RenderingHints object (which may be null). 93 * @param kernel the specified <code>Kernel</code> 94 * @param edgeCondition the specified edge condition 95 * @param hints the specified <code>RenderingHints</code> object 96 * @see Kernel 97 * @see #EDGE_NO_OP 98 * @see #EDGE_ZERO_FILL 99 * @see java.awt.RenderingHints 100 */ 101 public ConvolveOp(Kernel kernel, int edgeCondition, RenderingHints hints) { 102 this.kernel = kernel; 103 this.edgeHint = edgeCondition; 104 this.hints = hints; 105 } 106 107 /** 108 * Constructs a ConvolveOp given a Kernel. The edge condition |