-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathImageCompiler.java
More file actions
99 lines (83 loc) · 2.72 KB
/
ImageCompiler.java
File metadata and controls
99 lines (83 loc) · 2.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
import java.awt.Graphics2D;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.util.LinkedList;
import java.util.List;
import javax.imageio.ImageIO;
public class ImageCompiler {
public static BufferedImage getTheImage() {
return new BufferedImage(128, 128, BufferedImage.TYPE_INT_ARGB);
}
public static int makeImages(BufferedImage workingImage, File destination, File[][] allLayers, int startIndex, int currentNumber) throws IOException {
File[] currentLayer = allLayers[startIndex];
for (File f : currentLayer) {
if (f.isFile()) {
BufferedImage myImage = ImageIO.read(f);
BufferedImage myWork = getTheImage();
Graphics2D myGraphics = myWork.createGraphics();
myGraphics.drawImage(workingImage, 0, 0, 128, 128, null);
myGraphics.drawImage(myImage, 0, 0, 128, 128, null);
myGraphics.dispose();
if (startIndex == allLayers.length - 1) {
File finalDestination = destination.toPath().resolve(String.valueOf(currentNumber++) + ".png").toFile();
ImageIO.write(myWork, "png", finalDestination);
} else {
currentNumber = makeImages(myWork, destination, allLayers, startIndex + 1, currentNumber);
}
}
}
return currentNumber;
}
public static void main(String[] args) {
String location = args[0];
File base = null;
File output = null;
File folder = new File(location);
List<File> partFolders = new LinkedList<>();
for(File file: folder.listFiles()) {
if (file.isDirectory()) {
if (file.getName().equalsIgnoreCase("base")) {
base = file;
} else if (file.getName().equalsIgnoreCase("output")) {
output = file;
} else {
partFolders.add(file);
}
}
}
List<List<File>> allParts = new LinkedList<>();
for (File file : partFolders) {
LinkedList<File> files = new LinkedList<>();
allParts.add(files);
for(File imageFile : file.listFiles()) {
if (imageFile.isFile()) {
files.add(imageFile);
}
}
}
File[][] allFiles = new File[allParts.size()][];
int i = 0;
for (List<File> list : allParts) {
allFiles[i] = new File[list.size()];
int j = 0;
for (File f : list) {
allFiles[i][j++] = f;
}
i++;
}
try {
for (File f : base.listFiles()) {
BufferedImage baseImage = ImageIO.read(f);
long startTime = System.nanoTime();
int result = makeImages(baseImage, output, allFiles, 0, 0);
long endTime = System.nanoTime();
System.out.println("Created Images: " + result);
System.out.println("Elapsted Time: " + ((endTime - startTime) / 1000.0 / 1000.0 / 1000.0) + " seconds");
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}