Skip to content

Commit

Permalink
StitchTool v4.0.6
Browse files Browse the repository at this point in the history
Fixed a bug where multiple underscores would be put in names when smart splitting.

Denoise and scale checkboxes will retain history

Fixed a bug where running waifu2x standalone didn't show an alert box

Fixed a bug where running waifu2x vulkan would do ^2 of the scale.
  • Loading branch information
Aeonss committed Apr 3, 2022
1 parent be4008e commit ad349ef
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 13 deletions.
2 changes: 0 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,6 @@ splitter</u></strong> and an <strong><u>integrated denoiser and upscaler</u></st
## 🤖 &nbsp; To Do
* Squash all the bugs!
* Add a recursive feature for stitch/split (Folders within folders)
* Add config for remembering denoise level and scale
* Fix any waifu bugs
* Add config for remembering collapsed sections
* Resize fields with windows
* Fix weird bug with checkbox field misaligning
Expand Down
46 changes: 36 additions & 10 deletions src/Controller.java
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ public class Controller implements Initializable {
private String actionOption;
private String ssOption;
private String fileOption;
private String lastDenoise;
private String lastScale;

private ObservableList<String> modelList;
private String[] caffeModels;
Expand Down Expand Up @@ -108,6 +110,9 @@ public Controller() {
actionOption = Util.getConfig("actionOption");
ssOption = Util.getConfig("ssOption");
fileOption = Util.getConfig("fileOption");
lastDenoise = Util.getConfig("lastDenoise");
lastScale = Util.getConfig("lastScale");

files = new ArrayList<>();
}

Expand Down Expand Up @@ -173,6 +178,14 @@ public void initialize(URL url, ResourceBundle resourceBundle) {
Util.setConfig("waifuPath", "NOT FOUND");
waifuField.setText("");
}
if (lastDenoise == null) {
lastDenoise = "no";
Util.setConfig("lastDenoise", "no");
}
if (lastScale == null) {
lastScale = "no";
Util.setConfig("lastScale", "no");
}

// Default setups
outputField.setText(outputPath);
Expand Down Expand Up @@ -273,6 +286,18 @@ else if (actionOption.equalsIgnoreCase("HORIZONTAL")) {
fileOptions.setValue("JPG");
}

if (lastDenoise.equalsIgnoreCase("no")) {
denoiseBox.setSelected(false);
} else {
denoiseBox.setSelected(true);
}

if (lastScale.equalsIgnoreCase("no")) {
scaleBox.setSelected(false);
} else {
scaleBox.setSelected(true);
}

// Updates GUI
updateGUI();
onDenoise();
Expand Down Expand Up @@ -535,8 +560,10 @@ public void onDenoise() {
if (denoiseBox.isSelected()) {
denoiseSlider.setDisable(false);
modelOptions.setDisable(false);
Util.setConfig("lastDenoise", "yes");
} else {
denoiseSlider.setDisable(true);
Util.setConfig("lastDenoise", "no");
}
if (!denoiseBox.isSelected() && !scaleBox.isSelected()) {
modelOptions.setDisable(true);
Expand All @@ -550,6 +577,7 @@ public void onScale() {
scaleHeightField.setDisable(false);
scaleWidthField.setDisable(false);
modelOptions.setDisable(false);
Util.setConfig("lastScale", "yes");

// Width and height are only enabled for caffe
if (waifuPath.contains("vulkan")) {
Expand All @@ -563,6 +591,7 @@ public void onScale() {
scaleSlider.setDisable(true);
scaleHeightField.setDisable(true);
scaleWidthField.setDisable(true);
Util.setConfig("lastScale", "no");
}
if (!denoiseBox.isSelected() && !scaleBox.isSelected()) {
modelOptions.setDisable(true);
Expand Down Expand Up @@ -1128,14 +1157,12 @@ public int smartSplitHelper(BufferedImage image) {
// Exports the images into a folder
try {
for (int i = 0; i < splitHeights.size() - 1; i++) {
nameField.setText(nameField.getText() + "_" + (i + 1));
File f = new File(outputPath + nameField.getText() + "." + fileOption);
File f = new File(outputPath + nameField.getText() + "_" + (i + 1) + "." + fileOption);

ImageIO.write(image.getSubimage(0, splitHeights.get(i), image.getWidth(), splitHeights.get(i + 1) - splitHeights.get(i)), fileOption, f);
if (waifuHelper(f)) {
f.delete();
}
nameField.setText(nameField.getText().substring(0, nameField.getLength() - 2));
}
} catch (IOException ex) {
ex.printStackTrace();
Expand All @@ -1146,6 +1173,8 @@ public int smartSplitHelper(BufferedImage image) {
// Waifu2X the image
public boolean waifuHelper(File f) {

boolean waifuAlone = false;

// If the waifu2x.exe is not found
if (waifuPath.equalsIgnoreCase("NOT FOUND") || (!denoiseBox.isSelected() && !scaleBox.isSelected())) {
return false;
Expand All @@ -1171,6 +1200,7 @@ public boolean waifuHelper(File f) {

// If f is null, ask user to select image
if (f == null) {
waifuAlone = true;
// Ask user to select image
FileChooser input = new FileChooser();
input.setTitle("Select image to Waifu2X");
Expand Down Expand Up @@ -1245,7 +1275,7 @@ else if (waifuPath.contains("vulkan")) {
}
if (scaleBox.isSelected()) {
cmd.add("-s");
cmd.add(Math.pow(2, sf) + "");
cmd.add(sf + "");
}
cmd.add("-m");
cmd.add(new File(waifuField.getText()).getParent() + File.separator + modelOptions.getValue());
Expand All @@ -1263,7 +1293,7 @@ else if (waifuPath.contains("vulkan")) {
a.showAndWait();
}

if (!stitchSplit.isSelected() && !smartSplit.isSelected()) {
if (waifuAlone) {
Alert a = new Alert(Alert.AlertType.INFORMATION);
a.setHeaderText(null);
if (denoiseBox.isSelected() && scaleBox.isSelected()) {
Expand All @@ -1276,11 +1306,7 @@ else if (waifuPath.contains("vulkan")) {
a.showAndWait();
}

for (int i = 1; i < cmd.size(); i++) {
System.out.print(cmd + " ");
}
System.out.println("END");

System.out.print(cmd + "\n");

return true;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Stitch.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
import java.util.Properties;

public class Stitch extends Application {
private final String version = "4.0.2";
private final String version = "4.0.6";

public static void main(String[] args) {
launch(args);
Expand Down

0 comments on commit ad349ef

Please sign in to comment.