Add heightmap web util command

This commit is contained in:
Jesse Boyd
2018-09-07 06:40:13 +10:00
parent 594d72d2fe
commit 7af1b3dcc8
5 changed files with 85 additions and 16 deletions

View File

@ -32,6 +32,7 @@ import java.util.concurrent.ForkJoinPool;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicLong;
import java.util.function.BiConsumer;
import java.util.function.Consumer;
import java.util.regex.Pattern;
import java.util.zip.*;
import javax.imageio.ImageIO;
@ -889,7 +890,7 @@ public class MainUtil {
return isInSubDirectory(dir, file.getParentFile());
}
public static void iterateFiles(File directory, RunnableVal<File> task) {
public static void iterateFiles(File directory, Consumer<File> task) {
if (directory.exists()) {
File[] files = directory.listFiles();
if (null != files) {
@ -897,7 +898,7 @@ public class MainUtil {
if (files[i].isDirectory()) {
iterateFiles(files[i], task);
} else {
task.run(files[i]);
task.accept(files[i]);
}
}
}
@ -1054,9 +1055,9 @@ public class MainUtil {
public static void deleteOlder(File directory, final long timeDiff, boolean printDebug) {
final long now = System.currentTimeMillis();
ForkJoinPool pool = new ForkJoinPool();
iterateFiles(directory, new RunnableVal<File>() {
iterateFiles(directory, new Consumer<File>() {
@Override
public void run(File file) {
public void accept(File file) {
long age = now - file.lastModified();
if (age > timeDiff) {
pool.submit(() -> file.delete());

View File

@ -32,14 +32,14 @@ public class ImageUtil {
}
int type = (img.getTransparency() == Transparency.OPAQUE) ?
BufferedImage.TYPE_INT_RGB : BufferedImage.TYPE_INT_ARGB;
BufferedImage ret = (BufferedImage)img;
BufferedImage ret = img;
int w, h;
if (higherQuality) {
// Use multi-step technique: start with original size, then
// scale down in multiple passes with drawImage()
// until the target size is reached
w = img.getWidth();
h = img.getHeight();
w = ret.getWidth();
h = ret.getHeight();
} else {
// Use one-step technique: scale directly from original
// size to target size with a single drawImage() call
@ -53,14 +53,14 @@ public class ImageUtil {
if (w < targetWidth) {
w = targetWidth;
}
}
} else if (w < targetWidth) w = targetWidth;
if (higherQuality && h > targetHeight) {
h /= 2;
if (h < targetHeight) {
h = targetHeight;
}
}
} else if (h < targetHeight) h = targetHeight;
BufferedImage tmp = new BufferedImage(w, h, type);
Graphics2D g2 = tmp.createGraphics();