author | tvaleev |
Thu, 04 Oct 2018 12:40:55 -0700 | |
changeset 52248 | 2e330da7cbf4 |
parent 47216 | 71c04702a3d5 |
permissions | -rw-r--r-- |
2 | 1 |
/* |
52248
2e330da7cbf4
8211300: Convert C-style array declarations in JDK client code
tvaleev
parents:
47216
diff
changeset
|
2 |
* Copyright (c) 1997, 2018, Oracle and/or its affiliates. All rights reserved. |
2 | 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 |
|
5506 | 7 |
* published by the Free Software Foundation. Oracle designates this |
2 | 8 |
* particular file as subject to the "Classpath" exception as provided |
5506 | 9 |
* by Oracle in the LICENSE file that accompanied this code. |
2 | 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 |
* |
|
5506 | 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. |
|
2 | 24 |
*/ |
25 |
||
26 |
package java.awt.image; |
|
27 |
||
28 |
||
29 |
/** |
|
35667 | 30 |
* The {@code Kernel} class defines a matrix that describes how a |
2 | 31 |
* specified pixel and its surrounding pixels affect the value |
32 |
* computed for the pixel's position in the output image of a filtering |
|
33 |
* operation. The X origin and Y origin indicate the kernel matrix element |
|
34 |
* that corresponds to the pixel position for which an output value is |
|
35 |
* being computed. |
|
36 |
* |
|
37 |
* @see ConvolveOp |
|
38 |
*/ |
|
39 |
public class Kernel implements Cloneable { |
|
40 |
private int width; |
|
41 |
private int height; |
|
42 |
private int xOrigin; |
|
43 |
private int yOrigin; |
|
52248
2e330da7cbf4
8211300: Convert C-style array declarations in JDK client code
tvaleev
parents:
47216
diff
changeset
|
44 |
private float[] data; |
2 | 45 |
|
46 |
private static native void initIDs(); |
|
47 |
static { |
|
48 |
ColorModel.loadLibraries(); |
|
49 |
initIDs(); |
|
50 |
} |
|
51 |
||
52 |
/** |
|
35667 | 53 |
* Constructs a {@code Kernel} object from an array of floats. |
54 |
* The first {@code width}*{@code height} elements of |
|
55 |
* the {@code data} array are copied. |
|
56 |
* If the length of the {@code data} array is less |
|
57 |
* than width*height, an {@code IllegalArgumentException} is thrown. |
|
2 | 58 |
* The X origin is (width-1)/2 and the Y origin is (height-1)/2. |
59 |
* @param width width of the kernel |
|
60 |
* @param height height of the kernel |
|
61 |
* @param data kernel data in row major order |
|
35667 | 62 |
* @throws IllegalArgumentException if the length of {@code data} |
63 |
* is less than the product of {@code width} and |
|
64 |
* {@code height} |
|
2 | 65 |
*/ |
52248
2e330da7cbf4
8211300: Convert C-style array declarations in JDK client code
tvaleev
parents:
47216
diff
changeset
|
66 |
public Kernel(int width, int height, float[] data) { |
2 | 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 |
/** |
|
35667 | 83 |
* Returns the X origin of this {@code Kernel}. |
2 | 84 |
* @return the X origin. |
85 |
*/ |
|
32865
f9cb6e427f9e
8136783: Run blessed-modifier-order script on java.desktop
prr
parents:
25859
diff
changeset
|
86 |
public final int getXOrigin(){ |
2 | 87 |
return xOrigin; |
88 |
} |
|
89 |
||
90 |
/** |
|
35667 | 91 |
* Returns the Y origin of this {@code Kernel}. |
2 | 92 |
* @return the Y origin. |
93 |
*/ |
|
32865
f9cb6e427f9e
8136783: Run blessed-modifier-order script on java.desktop
prr
parents:
25859
diff
changeset
|
94 |
public final int getYOrigin() { |
2 | 95 |
return yOrigin; |
96 |
} |
|
97 |
||
98 |
/** |
|
35667 | 99 |
* Returns the width of this {@code Kernel}. |
100 |
* @return the width of this {@code Kernel}. |
|
2 | 101 |
*/ |
32865
f9cb6e427f9e
8136783: Run blessed-modifier-order script on java.desktop
prr
parents:
25859
diff
changeset
|
102 |
public final int getWidth() { |
2 | 103 |
return width; |
104 |
} |
|
105 |
||
106 |
/** |
|
35667 | 107 |
* Returns the height of this {@code Kernel}. |
108 |
* @return the height of this {@code Kernel}. |
|
2 | 109 |
*/ |
32865
f9cb6e427f9e
8136783: Run blessed-modifier-order script on java.desktop
prr
parents:
25859
diff
changeset
|
110 |
public final int getHeight() { |
2 | 111 |
return height; |
112 |
} |
|
113 |
||
114 |
/** |
|
115 |
* Returns the kernel data in row major order. |
|
35667 | 116 |
* The {@code data} array is returned. If {@code data} |
117 |
* is {@code null}, a new array is allocated. |
|
2 | 118 |
* @param data if non-null, contains the returned kernel data |
35667 | 119 |
* @return the {@code data} array containing the kernel data |
120 |
* in row major order or, if {@code data} is |
|
121 |
* {@code null}, a newly allocated array containing |
|
2 | 122 |
* the kernel data in row major order |
35667 | 123 |
* @throws IllegalArgumentException if {@code data} is less |
124 |
* than the size of this {@code Kernel} |
|
2 | 125 |
*/ |
32865
f9cb6e427f9e
8136783: Run blessed-modifier-order script on java.desktop
prr
parents:
25859
diff
changeset
|
126 |
public final float[] getKernelData(float[] data) { |
2 | 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 { |
|
147 |
return super.clone(); |
|
148 |
} catch (CloneNotSupportedException e) { |
|
149 |
// this shouldn't happen, since we are Cloneable |
|
10419
12c063b39232
7084245: Update usages of InternalError to use exception chaining
sherman
parents:
5506
diff
changeset
|
150 |
throw new InternalError(e); |
2 | 151 |
} |
152 |
} |
|
153 |
} |