Skip to content

Commit 9f1e9e2

Browse files
committed
ship committtttt
1 parent d056c62 commit 9f1e9e2

File tree

5 files changed

+108
-15
lines changed

5 files changed

+108
-15
lines changed

src/main/java/file2image/ConvertWindow.java

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,9 @@ public class ConvertWindow extends Stage {
2222
protected final TextArea log = new TextArea();
2323
protected final StringBuilder logText = new StringBuilder("Log Start");
2424
public final double totalBytes;
25-
public double amount;
25+
public double amount;
2626
protected final Timer timer = new Timer();
27+
private String lastCustomMessage = "";
2728

2829
public void dispose() {
2930
setOnCloseRequest(new EventHandler<WindowEvent>() {
@@ -38,6 +39,23 @@ public void handle(WindowEvent event) {
3839
close();
3940
}
4041

42+
public void addLog(String message, double xdivby, double y) {
43+
Platform.runLater(() -> {
44+
45+
if (!("Wrote pixel: " + String.valueOf((long) amount) + "/"
46+
+ String.valueOf((long) totalBytes) + "\n").equals(lastCustomMessage))
47+
logText.insert(0, message + ": " + String.valueOf((long) xdivby) + "/"
48+
+ String.valueOf((long) y) + "\n");
49+
if (logText.length() > 1000) {
50+
logText.setLength(500);
51+
}
52+
if (lastCustomMessage.equals("Wrote pixel: " + String.valueOf((long) amount) + "/"
53+
+ String.valueOf((long) totalBytes) + "\n"))
54+
lastCustomMessage = "Wrote pixel: " + String.valueOf((long) amount) + "/"
55+
+ String.valueOf((long) totalBytes) + "\n";
56+
});
57+
}
58+
4159
public void setBytesRead(double amount) {
4260
this.amount = amount;
4361
}
@@ -58,16 +76,17 @@ public void run() {
5876
log.setText(logText.toString());
5977

6078
prog.setProgress((amount / totalBytes));
79+
6180
logText.insert(0, "Wrote pixel: " + String.valueOf((long) amount) + "/"
6281
+ String.valueOf((long) totalBytes) + "\n");
6382
if (logText.length() > 1000) {
6483
logText.setLength(500);
6584
}
66-
//System.out.println(prog.getProgress());
85+
// System.out.println(prog.getProgress());
6786
});
6887
}
6988

70-
}, 0, 1);
89+
}, 0, 5);
7190

7291
log.textProperty().addListener(c -> {
7392
// log.setScrollTop(Double.MIN_VALUE);

src/main/java/file2image/Launcher.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ public void start(Stage primaryStage) throws Exception {
9595

9696
Label sortingModeLabel = new Label("Sorting Mode:");
9797
ComboBox<SortingMode> sortingModeSelection = new ComboBox<SortingMode>();
98-
sortingModeSelection.getItems().addAll(SortingMode.none,SortingMode.brightness);
98+
sortingModeSelection.getItems().addAll(SortingMode.none,SortingMode.brightness,SortingMode.hue,SortingMode.red,SortingMode.green,SortingMode.blue);
9999
sortingModeSelection.setValue(sortingModeSelection.getItems().get(0));
100100

101101
HBox inputStuff = new HBox(8, inputFilePathField, inputFileButton);
@@ -104,10 +104,12 @@ public void start(Stage primaryStage) throws Exception {
104104
outputStuff.setAlignment(Pos.CENTER);
105105
HBox methodStuff = new HBox(8, methodText, methodSelection,sortingModeLabel,sortingModeSelection);
106106
methodStuff.setAlignment(Pos.CENTER);
107+
HBox sortingStuff = new HBox(8 );
108+
sortingStuff.setAlignment(Pos.CENTER);
107109

108110
convertButton.setMinSize(380, 30);
109111

110-
VBox stuff = new VBox(10, inputStuff, outputStuff, methodStuff, convertButton);
112+
VBox stuff = new VBox(10, inputStuff, outputStuff, methodStuff,sortingStuff, convertButton);
111113
stuff.setAlignment(Pos.TOP_CENTER);
112114
stuff.setPadding(new Insets(20, 0, 0, 0));
113115

src/main/java/file2image/data/SortingMode.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
public enum SortingMode {
44
none,
55
brightness,
6+
hue,
67
red,
78
green,
89
blue

src/main/java/file2image/methods/Intensity.java

Lines changed: 39 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public void Start(Scene scene, File Input, Path Output, SortingMode sorting) {
3636
});
3737
int pixelAmount = (int) (Files.size(Input.toPath()) / 3);
3838
// byte[] InputBytes = Files.readAllBytes(Input.toPath()); too much ram
39-
System.out.println(pixelAmount);
39+
//System.out.println(pixelAmount);
4040
int dimension = (int) Math.ceil(Math.sqrt(pixelAmount));
4141
BufferedImage BI = new BufferedImage(dimension, dimension, BufferedImage.TYPE_INT_RGB);
4242
File outFile = Output.toFile();
@@ -56,13 +56,13 @@ public void Start(Scene scene, File Input, Path Output, SortingMode sorting) {
5656

5757
if (convRef[0] != null)
5858
convRef[0].setBytesRead(bytesread);
59-
System.out.println(index);
60-
System.out.println(line);
59+
//System.out.println(index);
60+
//System.out.println(line);
6161
if (index >= dimension) {
6262
line++;
6363
index = 0;
64-
System.out.println(index);
65-
System.out.println(line);
64+
//System.out.println(index);
65+
//System.out.println(line);
6666
}
6767

6868
int intensity = Math
@@ -82,6 +82,40 @@ public void Start(Scene scene, File Input, Path Output, SortingMode sorting) {
8282

8383
if (!outFile.exists())
8484
outFile.createNewFile();
85+
int lastColor = 0;
86+
int currentColor = 0;
87+
88+
int passes = 1000;
89+
90+
switch (sorting) {
91+
case SortingMode.brightness:
92+
for (int col = 0; col < BI.getWidth(); col++) {
93+
for (int i = 0; i < passes; i++) {
94+
convRef[0].addLog("Sorting pass", i * col, passes * BI.getWidth());
95+
for (int y = 1; y < BI.getHeight(); y++) {
96+
lastColor = currentColor;
97+
currentColor = BI.getRGB(col, y);
98+
99+
int r = (currentColor >> 16) & 0xFF;
100+
int g = (currentColor >> 8) & 0xFF;
101+
int b = currentColor & 0xFF;
102+
103+
int re = (lastColor >> 16) & 0xFF;
104+
int gr = (lastColor >> 8) & 0xFF;
105+
int bl = lastColor & 0xFF;
106+
107+
if ((r + g + b) < (re + gr + bl)) {
108+
BI.setRGB(col, y, lastColor);
109+
BI.setRGB(col, y - 1, currentColor);
110+
}
111+
}
112+
}
113+
}
114+
break;
115+
116+
default:
117+
break;
118+
}
85119
} catch (Exception e) {
86120
e.printStackTrace();
87121
}

src/main/java/file2image/methods/PureByte.java

Lines changed: 42 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public void Start(Scene scene, File Input, Path Output, SortingMode sorting) {
3636
});
3737
int pixelAmount = (int) (Files.size(Input.toPath()) / 3);
3838
// byte[] InputBytes = Files.readAllBytes(Input.toPath()); too much ram
39-
System.out.println(pixelAmount);
39+
//System.out.println(pixelAmount);
4040
int dimension = (int) Math.ceil(Math.sqrt(pixelAmount));
4141
BufferedImage BI = new BufferedImage(dimension, dimension, BufferedImage.TYPE_INT_RGB);
4242
File outFile = Output.toFile();
@@ -80,10 +80,13 @@ public void Start(Scene scene, File Input, Path Output, SortingMode sorting) {
8080
int lastColor = 0;
8181
int currentColor = 0;
8282

83+
int passes = 1000;
84+
8385
switch (sorting) {
8486
case SortingMode.brightness:
8587
for (int col = 0; col < BI.getWidth(); col++) {
86-
for (int i = 0; i < 200; i++) {
88+
for (int i = 0; i < passes; i++) {
89+
convRef[0].addLog("Sorting pass", i * col, passes * BI.getWidth());
8790
for (int y = 1; y < BI.getHeight(); y++) {
8891
lastColor = currentColor;
8992
currentColor = BI.getRGB(col, y);
@@ -107,7 +110,8 @@ public void Start(Scene scene, File Input, Path Output, SortingMode sorting) {
107110

108111
case SortingMode.red:
109112
for (int col = 0; col < BI.getWidth(); col++) {
110-
for (int i = 0; i < 200; i++) {
113+
for (int i = 0; i < passes; i++) {
114+
convRef[0].addLog("Sorting pass", i * col, passes * BI.getWidth());
111115
for (int y = 1; y < BI.getHeight(); y++) {
112116
lastColor = currentColor;
113117
currentColor = BI.getRGB(col, y);
@@ -127,7 +131,8 @@ public void Start(Scene scene, File Input, Path Output, SortingMode sorting) {
127131

128132
case SortingMode.green:
129133
for (int col = 0; col < BI.getWidth(); col++) {
130-
for (int i = 0; i < 200; i++) {
134+
for (int i = 0; i < passes; i++) {
135+
convRef[0].addLog("Sorting pass", i * col, passes * BI.getWidth());
131136
for (int y = 1; y < BI.getHeight(); y++) {
132137
lastColor = currentColor;
133138
currentColor = BI.getRGB(col, y);
@@ -147,7 +152,8 @@ public void Start(Scene scene, File Input, Path Output, SortingMode sorting) {
147152

148153
case SortingMode.blue:
149154
for (int col = 0; col < BI.getWidth(); col++) {
150-
for (int i = 0; i < 200; i++) {
155+
for (int i = 0; i < passes; i++) {
156+
convRef[0].addLog("Sorting pass", i * col, passes * BI.getWidth());
151157
for (int y = 1; y < BI.getHeight(); y++) {
152158
lastColor = currentColor;
153159
currentColor = BI.getRGB(col, y);
@@ -165,6 +171,37 @@ public void Start(Scene scene, File Input, Path Output, SortingMode sorting) {
165171
}
166172
break;
167173

174+
case SortingMode.hue:
175+
for (int col = 0; col < BI.getWidth(); col++) {
176+
for (int i = 0; i < passes; i++) {
177+
convRef[0].addLog("Sorting pass", i * col, passes * BI.getWidth());
178+
for (int y = 1; y < BI.getHeight(); y++) {
179+
lastColor = currentColor;
180+
currentColor = BI.getRGB(col, y);
181+
182+
int r = (currentColor >> 16) & 0xFF;
183+
int g = (currentColor >> 8) & 0xFF;
184+
int b = currentColor & 0xFF;
185+
186+
int re = (lastColor >> 16) & 0xFF;
187+
int gr = (lastColor >> 8) & 0xFF;
188+
int bl = lastColor & 0xFF;
189+
190+
float[] currentHSB = Color.RGBtoHSB(r, g, b, null);
191+
float currenthue = currentHSB[0]; // 0.0 to 1.0
192+
193+
float[] lastHSB = Color.RGBtoHSB(re, gr, bl, null);
194+
float lasthue = lastHSB[0]; // 0.0 to 1.0
195+
196+
if ((currenthue) < (lasthue)) {
197+
BI.setRGB(col, y, lastColor);
198+
BI.setRGB(col, y - 1, currentColor);
199+
}
200+
}
201+
}
202+
}
203+
break;
204+
168205
default:
169206
break;
170207
}

0 commit comments

Comments
 (0)