1 7 8 package java.awt.image; 9 10 11 22 public class Kernel implements Cloneable { 23 private int width; 24 private int height; 25 private int xOrigin; 26 private int yOrigin; 27 private float data[]; 28 29 private static native void initIDs(); 30 static { 31 ColorModel.loadLibraries(); 32 initIDs(); 33 } 34 35 49 public Kernel(int width, int height, float data[]) { 50 this.width = width; 51 this.height = height; 52 this.xOrigin = (width-1)>>1; 53 this.yOrigin = (height-1)>>1; 54 int len = width*height; 55 if (data.length < len) { 56 throw new IllegalArgumentException ("Data array too small "+ 57 "(is "+data.length+ 58 " and should be "+len); 59 } 60 this.data = new float[len]; 61 System.arraycopy(data, 0, this.data, 0, len); 62 63 } 64 65 69 final public int getXOrigin(){ 70 return xOrigin; 71 } 72 73 77 final public int getYOrigin() { 78 return yOrigin; 79 } 80 81 85 final public int getWidth() { 86 return width; 87 } 88 89 93 final public int getHeight() { 94 return height; 95 } 96 97 109 final public float[] getKernelData(float[] data) { 110 if (data == null) { 111 data = new float[this.data.length]; 112 } 113 else if (data.length < this.data.length) { 114 throw new IllegalArgumentException ("Data array too small "+ 115 "(should be "+this.data.length+ 116 " but is "+ 117 data.length+" )"); 118 } 119 System.arraycopy(this.data, 0, data, 0, this.data.length); 120 121 return data; 122 } 123 124 128 public Object clone() { 129 try { 130 return super.clone(); 131 } catch (CloneNotSupportedException e) { 132 throw new InternalError (); 134 } 135 } 136 } 137 138 139 140 141 142 143 | Popular Tags |