mirror of
https://github.com/EngineHub/WorldEdit.git
synced 2024-12-27 05:00:08 +08:00
Copy Kernel class to WorldEdit to avoid loading AWT.
Java 8's Kernel statically loads the AWT library, which can apparently cause some issues on some systems, for some reason. Either way, there is no need to load AWT if it's not needed (Java pls).
This commit is contained in:
parent
10da4a4786
commit
66aa881b0c
@ -19,8 +19,6 @@
|
||||
|
||||
package com.sk89q.worldedit.math.convolution;
|
||||
|
||||
import java.awt.image.Kernel;
|
||||
|
||||
/**
|
||||
* A Gaussian Kernel generator (2D bellcurve).
|
||||
*/
|
||||
|
@ -19,8 +19,6 @@
|
||||
|
||||
package com.sk89q.worldedit.math.convolution;
|
||||
|
||||
import java.awt.image.Kernel;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
/**
|
||||
|
@ -0,0 +1,75 @@
|
||||
/*
|
||||
* WorldEdit, a Minecraft world manipulation toolkit
|
||||
* Copyright (C) sk89q <http://www.sk89q.com>
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
@ -19,8 +19,6 @@
|
||||
|
||||
package com.sk89q.worldedit.math.convolution;
|
||||
|
||||
import java.awt.image.Kernel;
|
||||
|
||||
/**
|
||||
* A linear Kernel generator (all cells weight the same)
|
||||
*/
|
||||
|
Loading…
Reference in New Issue
Block a user