home *** CD-ROM | disk | FTP | other *** search
Java Source | 1998-03-20 | 3.8 KB | 145 lines |
- /*
- * @(#)Kernel.java 1.9 98/03/18
- *
- * Copyright 1997 by Sun Microsystems, Inc.,
- * 901 San Antonio Road, Palo Alto, California, 94303, U.S.A.
- * All rights reserved.
- *
- * This software is the confidential and proprietary information
- * of Sun Microsystems, Inc. ("Confidential Information"). You
- * shall not disclose such Confidential Information and shall use
- * it only in accordance with the terms of the license agreement
- * you entered into with Sun.
- */
-
- package java.awt.image;
-
-
- /**
- * This class defines a Kernel object. A kernel is a matrix describing
- * how a given pixel and its surrounding pixels affect the value of the
- * given pixel in a filtering operation.
- *
- * @see ConvolveOp
- * @version 10 Feb 1997
- */
- public class Kernel {
- private int width;
- private int height;
- private int xOrigin;
- private int yOrigin;
- private float data[];
-
- private static native void initIDs();
- static {
- ColorModel.loadLibraries();
- initIDs();
- }
-
- /**
- * Default 3x3 kernels
- */
-
- /**
- * 3x3 Sharpening kernel:<pre>
- * -1 -1 -1
- * -1 9 -1
- * -1 -1 -1</pre>
- */
- public static final float[] SHARPEN3x3_1 = {-1.f, -1.f, -1.f,
- -1.f, 9.f, -1.f,
- -1.f, -1.f, -1.f};
- /**
- * 3x3 Sharpening kernel:<pre>
- * 1 -2 1
- * -2 5 -2
- * 1 -2 1</pre>
- */
-
- public static final float[] SHARPEN3x3_2 = { 1.f, -2.f, 1.f,
- -2.f, 5.f, -2.f,
- 1.f, -2.f, 1.f};
-
- /**
- * 3x3 Sharpening kernel:<pre>
- * 0 -1 0
- * -1 5 -1
- * 0 -1 0</pre>
- */
- public static final float[] SHARPEN3x3_3 = { 0.f, -1.f, 0.f,
- -1.f, 5.f, -1.f,
- 0.f, -1.f, 0.f};
-
-
- /**
- * Create a Kernel object from an array of floats. The data array
- * is copied.
- * @param width Width of the kernel.
- * @param height Height of the kernel.
- * @param data Kernel data in row major order.
- */
- public Kernel(int width, int height, float data[]) {
- this.width = width;
- this.height = height;
- this.xOrigin = width>>1;
- this.yOrigin = height>>1;
- int len = width*height;
- if (data.length < len) {
- throw new IllegalArgumentException("Data array too small "+
- "(is "+data.length+
- " and should be "+len);
- }
- this.data = new float[len];
- System.arraycopy(data, 0, this.data, 0, len);
-
- }
-
- /**
- * Returns the X origin.
- */
- final public int getXOrigin(){
- return xOrigin;
- }
-
- /**
- * Returns the Y origin.
- */
- final public int getYOrigin() {
- return yOrigin;
- }
-
- /**
- * Returns the width
- */
- final public int getWidth() {
- return width;
- }
-
- /**
- * Returns the height
- */
- final public int getHeight() {
- return height;
- }
-
- /**
- * Returns the kernel data in row major order.
- * @param data If non-null, will contain the returned kernel data.
- */
- final public float[] getKernelData(float[] data) {
- if (data == null) {
- data = new float[this.data.length];
- }
- else if (data.length < this.data.length) {
- throw new IllegalArgumentException("Data array too small "+
- "(should be "+this.data.length+
- " but is "+
- data.length+" )");
- }
- System.arraycopy(this.data, 0, data, 0, this.data.length);
-
- return data;
- }
-
- }
-