Dieser Commit ist enthalten in:
Ursprung
254a56c8c3
Commit
838c67e3e6
@ -123,7 +123,7 @@ public class CustomMap implements Listener {
|
|||||||
private void run() throws IOException {
|
private void run() throws IOException {
|
||||||
BufferedImage bufferedImage = ImageIO.read(mapFile);
|
BufferedImage bufferedImage = ImageIO.read(mapFile);
|
||||||
|
|
||||||
Set<Point>[] patches = new Set[256];
|
Set<Integer>[] patches = new Set[256];
|
||||||
for (int patch = 0; patch < patches.length; patch++) {
|
for (int patch = 0; patch < patches.length; patch++) {
|
||||||
patches[patch] = new HashSet<>();
|
patches[patch] = new HashSet<>();
|
||||||
}
|
}
|
||||||
@ -136,21 +136,25 @@ public class CustomMap implements Listener {
|
|||||||
double blue = color.getBlue() / 255.0;
|
double blue = color.getBlue() / 255.0;
|
||||||
double luminance = Math.sqrt(0.299 * red * red + 0.587 * green * green + 0.114 * blue * blue);
|
double luminance = Math.sqrt(0.299 * red * red + 0.587 * green * green + 0.114 * blue * blue);
|
||||||
luminance *= 255;
|
luminance *= 255;
|
||||||
patches[(int) luminance].add(new Point(x, y));
|
patches[(int) luminance].add(x << 16 | y);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int patch = 0; patch < patches.length; patch++) {
|
for (int patch = 0; patch < patches.length; patch++) {
|
||||||
Set<Point> points = patches[patch];
|
Set<Integer> points = patches[patch];
|
||||||
if (points.isEmpty()) continue;
|
if (points.isEmpty()) continue;
|
||||||
BufferedImage patchImage = new BufferedImage(bufferedImage.getWidth(), bufferedImage.getHeight(), BufferedImage.TYPE_INT_ARGB);
|
BufferedImage patchImage = new BufferedImage(bufferedImage.getWidth(), bufferedImage.getHeight(), BufferedImage.TYPE_INT_ARGB);
|
||||||
points.forEach(point -> {
|
points.forEach(point -> {
|
||||||
patchImage.setRGB(point.getX(), point.getY(), bufferedImage.getRGB(point.getX(), point.getY()));
|
int x = point >>> 16;
|
||||||
|
int y = point & 0xFFFF;
|
||||||
|
patchImage.setRGB(x, y, bufferedImage.getRGB(x, y));
|
||||||
});
|
});
|
||||||
floodFill(patchImage);
|
floodFill(patchImage);
|
||||||
dither(patchImage);
|
dither(patchImage);
|
||||||
points.forEach(point -> {
|
points.forEach(point -> {
|
||||||
bufferedImage.setRGB(point.getX(), point.getY(), patchImage.getRGB(point.getX(), point.getY()));
|
int x = point >>> 16;
|
||||||
|
int y = point & 0xFFFF;
|
||||||
|
bufferedImage.setRGB(x, y, patchImage.getRGB(x, y));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -191,32 +195,34 @@ public class CustomMap implements Listener {
|
|||||||
WritableRaster alpha = bufferedImage.getAlphaRaster();
|
WritableRaster alpha = bufferedImage.getAlphaRaster();
|
||||||
int[] data = alpha.getPixels(0, 0, bufferedImage.getWidth(), bufferedImage.getHeight(), new int[bufferedImage.getWidth() * bufferedImage.getHeight()]);
|
int[] data = alpha.getPixels(0, 0, bufferedImage.getWidth(), bufferedImage.getHeight(), new int[bufferedImage.getWidth() * bufferedImage.getHeight()]);
|
||||||
for (int i = 0; i < 5; i++) {
|
for (int i = 0; i < 5; i++) {
|
||||||
Set<Point> changes = new HashSet<>();
|
Set<Integer> changes = new HashSet<>();
|
||||||
for (int y = 0; y < bufferedImage.getHeight(); y++) {
|
for (int y = 0; y < bufferedImage.getHeight(); y++) {
|
||||||
for (int x = 0; x < bufferedImage.getWidth(); x++) {
|
for (int x = 0; x < bufferedImage.getWidth(); x++) {
|
||||||
if (data[y * bufferedImage.getWidth() + x] == 0) continue;
|
if (data[y * bufferedImage.getWidth() + x] == 0) continue;
|
||||||
int color = bufferedImage.getRGB(x, y);
|
int color = bufferedImage.getRGB(x, y);
|
||||||
if (x > 0 && data[y * bufferedImage.getWidth() + x - 1] == 0) {
|
if (x > 0 && data[y * bufferedImage.getWidth() + x - 1] == 0) {
|
||||||
bufferedImage.setRGB(x - 1, y, color);
|
bufferedImage.setRGB(x - 1, y, color);
|
||||||
changes.add(new Point(x - 1, y));
|
changes.add((x - 1) << 16 | y);
|
||||||
}
|
}
|
||||||
if (x < bufferedImage.getWidth() - 1 && data[y * bufferedImage.getWidth() + x + 1] == 0) {
|
if (x < bufferedImage.getWidth() - 1 && data[y * bufferedImage.getWidth() + x + 1] == 0) {
|
||||||
bufferedImage.setRGB(x + 1, y, color);
|
bufferedImage.setRGB(x + 1, y, color);
|
||||||
changes.add(new Point(x + 1, y));
|
changes.add((x + 1) << 16 | y);
|
||||||
}
|
}
|
||||||
if (y > 0 && data[(y - 1) * bufferedImage.getWidth() + x] == 0) {
|
if (y > 0 && data[(y - 1) * bufferedImage.getWidth() + x] == 0) {
|
||||||
bufferedImage.setRGB(x, y - 1, color);
|
bufferedImage.setRGB(x, y - 1, color);
|
||||||
changes.add(new Point(x, y - 1));
|
changes.add(x << 16 | (y - 1));
|
||||||
}
|
}
|
||||||
if (y < bufferedImage.getHeight() - 1 && data[(y + 1) * bufferedImage.getWidth() + x] == 0) {
|
if (y < bufferedImage.getHeight() - 1 && data[(y + 1) * bufferedImage.getWidth() + x] == 0) {
|
||||||
bufferedImage.setRGB(x, y + 1, color);
|
bufferedImage.setRGB(x, y + 1, color);
|
||||||
changes.add(new Point(x, y + 1));
|
changes.add(x << 16 | (y + 1));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (changes.isEmpty()) return;
|
if (changes.isEmpty()) return;
|
||||||
changes.forEach(point -> {
|
changes.forEach(point -> {
|
||||||
data[point.getY() * bufferedImage.getWidth() + point.getX()] = 255;
|
int x = point >>> 16;
|
||||||
|
int y = point & 0xFFFF;
|
||||||
|
data[y * bufferedImage.getWidth() + x] = 255;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,20 +0,0 @@
|
|||||||
package de.steamwar.lobby.map;
|
|
||||||
|
|
||||||
public class Point {
|
|
||||||
|
|
||||||
private int x;
|
|
||||||
private int y;
|
|
||||||
|
|
||||||
public Point(int x, int y) {
|
|
||||||
this.x = x;
|
|
||||||
this.y = y;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getX() {
|
|
||||||
return x;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getY() {
|
|
||||||
return y;
|
|
||||||
}
|
|
||||||
}
|
|
In neuem Issue referenzieren
Einen Benutzer sperren