66 public Kernel(int width, int height, float data[]) { 67 this.width = width; 68 this.height = height; 69 this.xOrigin = (width-1)>>1; 70 this.yOrigin = (height-1)>>1; 71 int len = width*height; 72 if (data.length < len) { 73 throw new IllegalArgumentException("Data array too small "+ 74 "(is "+data.length+ 75 " and should be "+len); 76 } 77 this.data = new float[len]; 78 System.arraycopy(data, 0, this.data, 0, len); 79 80 } 81 82 /** 83 * Returns the X origin of this <code>Kernel</code>. 84 * @return the X origin. 85 */ 86 final public int getXOrigin(){ 87 return xOrigin; 88 } 89 90 /** 91 * Returns the Y origin of this <code>Kernel</code>. 92 * @return the Y origin. 93 */ 94 final public int getYOrigin() { 95 return yOrigin; 96 } 97 98 /** 99 * Returns the width of this <code>Kernel</code>. 100 * @return the width of this <code>Kernel</code>. 101 */ 102 final public int getWidth() { 103 return width; 104 } 105 106 /** 107 * Returns the height of this <code>Kernel</code>. 108 * @return the height of this <code>Kernel</code>. 109 */ 110 final public int getHeight() { 111 return height; 112 } 113 114 /** 115 * Returns the kernel data in row major order. 116 * The <code>data</code> array is returned. If <code>data</code> 117 * is <code>null</code>, a new array is allocated. 118 * @param data if non-null, contains the returned kernel data 119 * @return the <code>data</code> array containing the kernel data 120 * in row major order or, if <code>data</code> is 121 * <code>null</code>, a newly allocated array containing 122 * the kernel data in row major order 123 * @throws IllegalArgumentException if <code>data</code> is less 124 * than the size of this <code>Kernel</code> 125 */ 126 final public float[] getKernelData(float[] data) { 127 if (data == null) { 128 data = new float[this.data.length]; 129 } 130 else if (data.length < this.data.length) { 131 throw new IllegalArgumentException("Data array too small "+ 132 "(should be "+this.data.length+ 133 " but is "+ 134 data.length+" )"); 135 } 136 System.arraycopy(this.data, 0, data, 0, this.data.length); 137 138 return data; 139 } 140 141 /** 142 * Clones this object. 143 * @return a clone of this object. 144 */ 145 public Object clone() { 146 try { | 66 public Kernel(int width, int height, float data[]) { 67 this.width = width; 68 this.height = height; 69 this.xOrigin = (width-1)>>1; 70 this.yOrigin = (height-1)>>1; 71 int len = width*height; 72 if (data.length < len) { 73 throw new IllegalArgumentException("Data array too small "+ 74 "(is "+data.length+ 75 " and should be "+len); 76 } 77 this.data = new float[len]; 78 System.arraycopy(data, 0, this.data, 0, len); 79 80 } 81 82 /** 83 * Returns the X origin of this <code>Kernel</code>. 84 * @return the X origin. 85 */ 86 public final int getXOrigin(){ 87 return xOrigin; 88 } 89 90 /** 91 * Returns the Y origin of this <code>Kernel</code>. 92 * @return the Y origin. 93 */ 94 public final int getYOrigin() { 95 return yOrigin; 96 } 97 98 /** 99 * Returns the width of this <code>Kernel</code>. 100 * @return the width of this <code>Kernel</code>. 101 */ 102 public final int getWidth() { 103 return width; 104 } 105 106 /** 107 * Returns the height of this <code>Kernel</code>. 108 * @return the height of this <code>Kernel</code>. 109 */ 110 public final int getHeight() { 111 return height; 112 } 113 114 /** 115 * Returns the kernel data in row major order. 116 * The <code>data</code> array is returned. If <code>data</code> 117 * is <code>null</code>, a new array is allocated. 118 * @param data if non-null, contains the returned kernel data 119 * @return the <code>data</code> array containing the kernel data 120 * in row major order or, if <code>data</code> is 121 * <code>null</code>, a newly allocated array containing 122 * the kernel data in row major order 123 * @throws IllegalArgumentException if <code>data</code> is less 124 * than the size of this <code>Kernel</code> 125 */ 126 public final float[] getKernelData(float[] data) { 127 if (data == null) { 128 data = new float[this.data.length]; 129 } 130 else if (data.length < this.data.length) { 131 throw new IllegalArgumentException("Data array too small "+ 132 "(should be "+this.data.length+ 133 " but is "+ 134 data.length+" )"); 135 } 136 System.arraycopy(this.data, 0, data, 0, this.data.length); 137 138 return data; 139 } 140 141 /** 142 * Clones this object. 143 * @return a clone of this object. 144 */ 145 public Object clone() { 146 try { |