diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/math/convolution/GaussianKernel.java b/worldedit-core/src/main/java/com/sk89q/worldedit/math/convolution/GaussianKernel.java index bc8b647f7..bb38201d2 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/math/convolution/GaussianKernel.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/math/convolution/GaussianKernel.java @@ -19,8 +19,6 @@ package com.sk89q.worldedit.math.convolution; -import java.awt.image.Kernel; - /** * A Gaussian Kernel generator (2D bellcurve). */ diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/math/convolution/HeightMapFilter.java b/worldedit-core/src/main/java/com/sk89q/worldedit/math/convolution/HeightMapFilter.java index 93f4f7c06..f58899fb4 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/math/convolution/HeightMapFilter.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/math/convolution/HeightMapFilter.java @@ -19,8 +19,6 @@ package com.sk89q.worldedit.math.convolution; -import java.awt.image.Kernel; - import static com.google.common.base.Preconditions.checkNotNull; /** diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/math/convolution/Kernel.java b/worldedit-core/src/main/java/com/sk89q/worldedit/math/convolution/Kernel.java new file mode 100644 index 000000000..efc051b63 --- /dev/null +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/math/convolution/Kernel.java @@ -0,0 +1,75 @@ +/* + * WorldEdit, a Minecraft world manipulation toolkit + * Copyright (C) sk89q + * Copyright (C) WorldEdit team and contributors + * + * This program is free software: you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by the + * Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License + * for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . + */ + +package com.sk89q.worldedit.math.convolution; + +/* + * This class was originally part of the JDK, java.awt.image.Kernel, + * and has been modified to not load the entire AWT toolkit, since + * that was apparently added in Java 8, even though this class + * is completely standalone. + */ +public class Kernel { + + private int width; + private int height; + private int xOrigin; + private int yOrigin; + private float[] data; + + public Kernel(int width, int height, float[] data) { + this.width = width; + this.height = height; + this.xOrigin = (width - 1) >> 1; + this.yOrigin = (height - 1) >> 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); + } + + public final int getXOrigin() { + return xOrigin; + } + + public final int getYOrigin() { + return yOrigin; + } + + public final int getWidth() { + return width; + } + + public final int getHeight() { + return height; + } + + public final 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; + } + +} \ No newline at end of file diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/math/convolution/LinearKernel.java b/worldedit-core/src/main/java/com/sk89q/worldedit/math/convolution/LinearKernel.java index 3e31c199e..1de8dec57 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/math/convolution/LinearKernel.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/math/convolution/LinearKernel.java @@ -19,8 +19,6 @@ package com.sk89q.worldedit.math.convolution; -import java.awt.image.Kernel; - /** * A linear Kernel generator (all cells weight the same) */