Created
October 6, 2019 09:33
-
-
Save MiniDigger/608d775c745ed8034584afc40e8f201f to your computer and use it in GitHub Desktop.
Upscale Resource packs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.awt.image.BufferedImage; | |
import java.awt.image.RescaleOp; | |
import java.io.IOException; | |
import java.nio.file.FileVisitResult; | |
import java.nio.file.Files; | |
import java.nio.file.Path; | |
import java.nio.file.SimpleFileVisitor; | |
import java.nio.file.attribute.BasicFileAttributes; | |
import java.util.Arrays; | |
import java.util.concurrent.atomic.AtomicInteger; | |
import javax.imageio.ImageIO; | |
class Scratch { | |
public static void main(String[] args) throws IOException { | |
Arrays.stream(new String[]{"Dyescape", "BeforeDawn"}).parallel().forEach(name -> { | |
Arrays.stream(new double[]{1.0f, 1.1f, 1.2f, 1.3f, 1.4f, 1.5f, 1.6f, 1.7f}).parallel().forEach(factor -> { | |
try { | |
new Scratch(name, (float) factor); | |
} catch (IOException e) { | |
e.printStackTrace(); | |
} | |
}); | |
}); | |
} | |
public Scratch(String name, float factor) throws IOException { | |
Path input = Path.of("C:\\Users\\Martin\\AppData\\Roaming\\.minecraft\\resourcepacks\\" + name); | |
Path output = Path.of("C:\\Users\\Martin\\AppData\\Roaming\\.minecraft\\resourcepacks\\" + name + "-Bright-" + factor); | |
if (!Files.isDirectory(output)) { | |
Files.walkFileTree(input, new SimpleFileVisitor<Path>() { | |
@Override | |
public FileVisitResult preVisitDirectory(final Path dir, final BasicFileAttributes attrs) throws IOException { | |
Files.createDirectories(output.resolve(input.relativize(dir))); | |
return FileVisitResult.CONTINUE; | |
} | |
@Override | |
public FileVisitResult visitFile(final Path file, | |
final BasicFileAttributes attrs) throws IOException { | |
Files.copy(file, output.resolve(input.relativize(file))); | |
return FileVisitResult.CONTINUE; | |
} | |
}); | |
} | |
Path inputFolder = input.resolve("assets\\minecraft\\textures\\block"); | |
Path outputFolder = output.resolve("assets\\minecraft\\textures\\block"); | |
AtomicInteger i = new AtomicInteger(); | |
Files.list(inputFolder).parallel().forEach(path -> { | |
try { | |
BufferedImage in = ImageIO.read(path.toFile()); | |
if (in == null) return; | |
BufferedImage out = brighten(in, factor); | |
ImageIO.write(out, "png", outputFolder.resolve(path.getFileName()).toFile()); | |
i.incrementAndGet(); | |
} catch (Exception e) { | |
e.printStackTrace(); | |
} | |
}); | |
System.out.println("wrote " + i + " files"); | |
} | |
private BufferedImage brighten(BufferedImage image, float factor) { | |
try { | |
float[] factors = new float[]{ | |
factor, factor, factor, 1f | |
}; | |
float[] offsets = new float[]{ | |
0.0f, 0.0f, 0.0f, 0.0f | |
}; | |
RescaleOp op = new RescaleOp(factors, offsets, null); | |
return op.filter(image, null); | |
} catch (IllegalArgumentException ex) { | |
float[] factors = new float[]{ | |
1.4f, 1.4f, 1.4f | |
}; | |
float[] offsets = new float[]{ | |
0.0f, 0.0f, 0.0f | |
}; | |
RescaleOp op = new RescaleOp(factors, offsets, null); | |
return op.filter(image, null); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment