Commits vergleichen
2 Commits
Autor | SHA1 | Datum | |
---|---|---|---|
|
ebf4ae4219 | ||
|
c1236dbc0e |
@ -30,6 +30,7 @@ import org.bukkit.map.MapPalette;
|
||||
|
||||
import java.awt.*;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.awt.image.WritableRaster;
|
||||
import java.lang.reflect.Field;
|
||||
|
||||
public class CustomMap {
|
||||
@ -42,6 +43,50 @@ public class CustomMap {
|
||||
throw new IllegalArgumentException("Image height must be a multiple of 128");
|
||||
}
|
||||
|
||||
final double multiplier1 = 7 / 16.0;
|
||||
final double multiplier2 = 3 / 16.0;
|
||||
final double multiplier3 = 5 / 16.0;
|
||||
final double multiplier4 = 1 / 16.0;
|
||||
WritableRaster raster = image.getRaster();
|
||||
int numBands = raster.getNumBands();
|
||||
int[] pixels = raster.getPixels(0, 0, image.getWidth(), image.getHeight(), new int[image.getWidth() * image.getHeight() * numBands]);
|
||||
for (int y = 0; y < image.getHeight(); y++) {
|
||||
for (int x = 0; x < image.getWidth(); x++) {
|
||||
int red = pixels[(y * image.getWidth() + x) * numBands];
|
||||
int green = pixels[(y * image.getWidth() + x) * numBands + 1];
|
||||
int blue = pixels[(y * image.getWidth() + x) * numBands + 2];
|
||||
Color nearest = getNearest(new Color(red, green, blue));
|
||||
pixels[(y * image.getWidth() + x) * numBands] = nearest.getRed();
|
||||
pixels[(y * image.getWidth() + x) * numBands + 1] = nearest.getGreen();
|
||||
pixels[(y * image.getWidth() + x) * numBands + 2] = nearest.getBlue();
|
||||
|
||||
int quantErrorRed = red - nearest.getRed();
|
||||
int quantErrorGreen = green - nearest.getGreen();
|
||||
int quantErrorBlue = blue - nearest.getBlue();
|
||||
if (x < image.getWidth() - 1) {
|
||||
pixels[(y * image.getWidth() + x + 1) * numBands] = clamp((int) (pixels[(y * image.getWidth() + x + 1) * numBands] + quantErrorRed * multiplier1));
|
||||
pixels[(y * image.getWidth() + x + 1) * numBands + 1] = clamp((int) (pixels[(y * image.getWidth() + x + 1) * numBands + 1] + quantErrorGreen * multiplier1));
|
||||
pixels[(y * image.getWidth() + x + 1) * numBands + 2] = clamp((int) (pixels[(y * image.getWidth() + x + 1) * numBands + 2] + quantErrorBlue * multiplier1));
|
||||
}
|
||||
if (x > 0) {
|
||||
pixels[(y * image.getWidth() + x - 1) * numBands] = clamp((int) (pixels[(y * image.getWidth() + x - 1) * numBands] + quantErrorRed * multiplier2));
|
||||
pixels[(y * image.getWidth() + x - 1) * numBands + 1] = clamp((int) (pixels[(y * image.getWidth() + x - 1) * numBands + 1] + quantErrorGreen * multiplier2));
|
||||
pixels[(y * image.getWidth() + x - 1) * numBands + 2] = clamp((int) (pixels[(y * image.getWidth() + x - 1) * numBands + 2] + quantErrorBlue * multiplier2));
|
||||
}
|
||||
if (y < image.getHeight() - 1) {
|
||||
pixels[((y + 1) * image.getWidth() + x) * numBands] = clamp((int) (pixels[((y + 1) * image.getWidth() + x) * numBands] + quantErrorRed * multiplier3));
|
||||
pixels[((y + 1) * image.getWidth() + x) * numBands + 1] = clamp((int) (pixels[((y + 1) * image.getWidth() + x) * numBands + 1] + quantErrorGreen * multiplier3));
|
||||
pixels[((y + 1) * image.getWidth() + x) * numBands + 2] = clamp((int) (pixels[((y + 1) * image.getWidth() + x) * numBands + 2] + quantErrorBlue * multiplier3));
|
||||
if (x < image.getWidth() - 1) {
|
||||
pixels[((y + 1) * image.getWidth() + x + 1) * numBands] = clamp((int) (pixels[((y + 1) * image.getWidth() + x + 1) * numBands] + quantErrorRed * multiplier4));
|
||||
pixels[((y + 1) * image.getWidth() + x + 1) * numBands + 1] = clamp((int) (pixels[((y + 1) * image.getWidth() + x + 1) * numBands + 1] + quantErrorGreen * multiplier4));
|
||||
pixels[((y + 1) * image.getWidth() + x + 1) * numBands + 2] = clamp((int) (pixels[((y + 1) * image.getWidth() + x + 1) * numBands + 2] + quantErrorBlue * multiplier4));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
raster.setPixels(0, 0, image.getWidth(), image.getHeight(), pixels);
|
||||
|
||||
BufferedImage bufferedImage = new BufferedImage(image.getWidth(), image.getHeight(), BufferedImage.TYPE_INT_RGB);
|
||||
for (int y = 0; y < image.getHeight(); y++) {
|
||||
for (int x = 0; x < image.getWidth(); x++) {
|
||||
|
In neuem Issue referenzieren
Einen Benutzer sperren