@@ -116,7 +116,6 @@ public void initialize(URL url, ResourceBundle resourceBundle) {
116
116
117
117
// Final values
118
118
final String [] files = new String []{"PNG" , "JPG" };
119
- final String [] waifus = new String []{"CAFFE" , "VULKAN" };
120
119
caffeModels = new String []{"cunet" , "upresnet10" , "upconv_7_anime_style_art_rgb" , "upconv_7_photo" , "anime_style_art_rgb" , "photo" , "anime_style_art_y" };
121
120
vulkanModels = new String []{"models-cunet" , "models-upconv_7_anime_style_art_rgb" , "models-upconv_7_photo" };
122
121
final String [] actions = new String []{"STITCHSPLIT" , "STITCH" , "SPLIT" , "SMARTSPLIT" };
@@ -130,22 +129,22 @@ public void initialize(URL url, ResourceBundle resourceBundle) {
130
129
File f4 = new File (watermarkPath );
131
130
132
131
// Checks to make sure the config is not null or has any invalid values
133
- if (inputPath == null || f1 == null || !f1 .isDirectory ()) {
132
+ if (inputPath == null || !f1 .isDirectory ()) {
134
133
inputPath = System .getProperty ("user.home" ) + File .separator ;
135
134
setConfig ("inputPath" , inputPath );
136
135
}
137
- if (outputPath == null || f2 == null || !f2 .isDirectory ()) {
136
+ if (outputPath == null || !f2 .isDirectory ()) {
138
137
outputPath = System .getProperty ("user.home" ) + File .separator ;
139
138
setConfig ("outputPath" , outputPath );
140
139
}
141
140
if (getConfig ("waifuPath" ) != null ) {
142
141
waifuField .setText (waifuPath );
143
142
}
144
- if (imagePath == null || f3 == null || !f3 .isDirectory ()) {
143
+ if (imagePath == null || !f3 .isDirectory ()) {
145
144
imagePath = System .getProperty ("user.home" ) + File .separator ;
146
145
setConfig ("imagePath" , imagePath );
147
146
}
148
- if (watermarkPath == null || f4 == null || !f4 .isDirectory ()) {
147
+ if (watermarkPath == null || !f4 .isDirectory ()) {
149
148
watermarkPath = System .getProperty ("user.home" ) + File .separator ;
150
149
setConfig ("watermarkPath" , watermarkPath );
151
150
}
@@ -165,7 +164,7 @@ public void initialize(URL url, ResourceBundle resourceBundle) {
165
164
fileOption = "PNG" ;
166
165
setConfig ("fileOption" , "PNG" );
167
166
}
168
- if (waifuPath == null || ! Arrays . asList ( waifus ). contains ( waifuPath ) ) {
167
+ if (waifuPath == null ) {
169
168
waifuPath = "NOT FOUND" ;
170
169
setConfig ("waifuPath" , "NOT FOUND" );
171
170
waifuField .setText ("" );
@@ -306,6 +305,10 @@ else if (files.size() == 1 && (stitchSplit.isSelected() || stitch.isSelected()))
306
305
inputImagesBTN .setPrefWidth (100.0 );
307
306
inputImagesBTN .setTranslateX (0 );
308
307
inputImagesBTN .setTranslateY (0 );
308
+
309
+ if (stitchSplit .isSelected ()) {
310
+ stitchSplitOptions .setDisable (false );
311
+ }
309
312
}
310
313
311
314
// No image has been selected yet
@@ -737,15 +740,15 @@ public void onWatermark() throws IOException {
737
740
if (greyOption .isSelected ()) {
738
741
ImageFilter imageFilter = new GrayFilter (true , 5 );
739
742
ImageProducer producer = new FilteredImageSource (watermark .getSource (), imageFilter );
740
- watermark = toBufferedImage ( Toolkit .getDefaultToolkit ().createImage (producer ) );
743
+ watermark = ( BufferedImage ) Toolkit .getDefaultToolkit ().createImage (producer );
741
744
}
742
745
743
746
// Rescales the image
744
747
double ratio = (double ) watermark .getWidth () / watermark .getHeight ();
745
748
Image tempImage = watermark .getScaledInstance (image .getWidth () / 5 ,
746
749
(int )(image .getWidth () / 5 * ratio ), Image .SCALE_DEFAULT );
747
750
748
- watermark = toBufferedImage ( tempImage ) ;
751
+ watermark = ( BufferedImage ) tempImage ;
749
752
750
753
// Asks how many times the watermark will show up
751
754
TextInputDialog input = new TextInputDialog ();
@@ -826,9 +829,9 @@ else if (option.equalsIgnoreCase(options[2]) || option.equalsIgnoreCase(options[
826
829
splitType = 2 ;
827
830
}
828
831
829
- int num = askSplitImages ();
830
832
// Split horizontally or vertically
831
833
if (splitType == 1 || splitType == 2 ) {
834
+ int num = askSplitImages ();
832
835
splitHelper (image , num , splitType == 1 );
833
836
834
837
// Finished message
@@ -842,9 +845,18 @@ else if (option.equalsIgnoreCase(options[2]) || option.equalsIgnoreCase(options[
842
845
843
846
// Smart split
844
847
if (splitType == 0 ) {
845
- doSmartSplit (image );
848
+ smartSplitHelper (image );
849
+ Alert a = new Alert (Alert .AlertType .INFORMATION );
850
+ a .setHeaderText ("Stitching and Splitting Complete!" );
851
+ if (denoiseBox .isSelected () && scaleBox .isSelected ()) {
852
+ a .setContentText ("Images have been stitched and split and been denoised with level " + (int ) denoiseSlider .getValue () + " and scaled by " + (int ) Math .pow (2 , scaleSlider .getValue ()) + "!" );
853
+ } else if (denoiseBox .isSelected () && !scaleBox .isSelected ()) {
854
+ a .setContentText ("Images have been stitched and split and denoised with level " + (int ) denoiseSlider .getValue ());
855
+ } else if (!denoiseBox .isSelected () && scaleBox .isSelected ()) {
856
+ a .setContentText ("Images have been stitched and split and been scaled by " + scaleSlider .getValue () + "!" );
857
+ }
858
+ a .showAndWait ();
846
859
}
847
-
848
860
}
849
861
850
862
// Stitches an ArrayList of images vertically/horizontally
@@ -862,7 +874,7 @@ public void doStitch(ArrayList<BufferedImage> images) throws IOException {
862
874
}
863
875
864
876
Alert a = new Alert (Alert .AlertType .CONFIRMATION );
865
- a .setHeaderText (null );
877
+ a .setHeaderText ("Stitching Complete!" );
866
878
a .setContentText (files .size () + " images were successfully stitched!" );
867
879
a .showAndWait ();
868
880
}
@@ -898,62 +910,22 @@ public void doImageSplit(BufferedImage image) throws IOException {
898
910
899
911
// Finished message
900
912
Alert a = new Alert (Alert .AlertType .CONFIRMATION );
901
- a .setHeaderText (null );
913
+ a .setHeaderText ("Splitting Complete!" );
902
914
a .setContentText ("Successfully split into " + num + " images!" );
903
915
a .showAndWait ();
904
916
}
905
917
906
918
// Splits a BufferedImage by space (row of same colored pixels)
907
- public void doSmartSplit (BufferedImage source ) throws IOException {
908
- int num = askSplitImages ();
909
-
910
- // Approximate size of each image
911
- int startHeight = source .getHeight () / num ;
912
- ArrayList <Integer > splitHeights = new ArrayList <>();
913
- splitHeights .add (0 );
914
-
915
- for (int i = startHeight ; i < source .getHeight (); i ++ ) {
916
- for (int j = 0 ; j < source .getWidth () - 1 ; j ++) {
917
- Color c1 = getColor (source .getRGB (j , i ));
918
- Color c2 = getColor (source .getRGB (j + 1 , i ));
919
-
920
- // Checks if the row of pixels is the same color, if not, moves 1 pixel down
921
- if (!(c1 .getAlpha () == c2 .getAlpha () && c1 .getRed () == c2 .getRed () && c1 .getGreen () == c2 .getGreen () && c1 .getBlue () == c2 .getBlue ())) {
922
- break ;
923
- }
924
- // Otherwise, it saves the height to split, and moves to the next part
925
- if (j +1 == source .getWidth () - 1 ) {
926
- splitHeights .add (i );
927
- i += startHeight ;
928
- break ;
929
- }
930
- }
931
- }
932
-
933
- // Adds the remainder of the image to the array
934
- if (splitHeights .get (splitHeights .size () - 1 ) != source .getHeight ()) {
935
- splitHeights .add (source .getHeight ());
936
- }
937
-
938
- new File (outputPath + File .separator + "StitchTool" + File .separator ).mkdirs ();
939
-
940
- // Exports the images into a folder
941
- for (int i = 0 ; i < splitHeights .size () - 1 ; i ++) {
942
- File f = new File (outputPath + File .separator + "StitchTool" + File .separator + nameField .getText () + (i +1 ) + "." + fileOption );
943
- ImageIO .write (source .getSubimage (0 , splitHeights .get (i ), source .getWidth (), splitHeights .get (i +1 ) - splitHeights .get (i )), fileOption , f );
944
- if (waifuHelper (f )) {
945
- f .delete ();
946
- }
947
- }
919
+ public void doSmartSplit (BufferedImage image ) throws IOException {
920
+ int numImages = smartSplitHelper (image );
948
921
949
922
// Finished message
950
923
Alert a = new Alert (Alert .AlertType .CONFIRMATION );
951
- a .setHeaderText (null );
952
- int numImages = splitHeights .size () - 1 ;
924
+ a .setHeaderText ("Smart Split" );
953
925
if (numImages == 1 ) {
954
926
a .setContentText ("Unable to smart split!" );
955
927
} else {
956
- a .setContentText (splitHeights . size () - 1 + " images were successfully created!" );
928
+ a .setContentText (numImages + " images were successfully created!" );
957
929
}
958
930
a .showAndWait ();
959
931
}
@@ -1105,6 +1077,62 @@ public void splitHelper(BufferedImage image, int num, boolean hor) {
1105
1077
}
1106
1078
}
1107
1079
1080
+ // Smart split and waifus as necessary
1081
+ public int smartSplitHelper (BufferedImage image ) {
1082
+ int c = 0 ;
1083
+ int num = askSplitImages ();
1084
+
1085
+ // Approximate size of each image
1086
+ int startHeight = image .getHeight () / num ;
1087
+ ArrayList <Integer > splitHeights = new ArrayList <>();
1088
+ splitHeights .add (0 );
1089
+
1090
+ for (int i = startHeight ; i < image .getHeight (); i ++ ) {
1091
+ for (int j = 0 ; j < image .getWidth () - 1 ; j ++) {
1092
+ Color c1 = getColor (image .getRGB (j , i ));
1093
+ Color c2 = getColor (image .getRGB (j + 1 , i ));
1094
+
1095
+ // Checks if the row of pixels is the same color, if not, moves 1 pixel down
1096
+ if (!(c1 .getAlpha () == c2 .getAlpha () && c1 .getRed () == c2 .getRed () && c1 .getGreen () == c2 .getGreen () && c1 .getBlue () == c2 .getBlue ())) {
1097
+ break ;
1098
+ }
1099
+ // Otherwise, it saves the height to split, and moves to the next part
1100
+ if (j +1 == image .getWidth () - 1 ) {
1101
+ splitHeights .add (i );
1102
+ i += startHeight ;
1103
+ c ++;
1104
+ break ;
1105
+ }
1106
+ }
1107
+ }
1108
+
1109
+ // Adds the remainder of the image to the array
1110
+ if (splitHeights .get (splitHeights .size () - 1 ) != image .getHeight ()) {
1111
+ splitHeights .add (image .getHeight ());
1112
+ }
1113
+
1114
+ outputPath = outputPath + File .separator + "StitchTool" + File .separator ;
1115
+ new File (outputPath ).mkdirs ();
1116
+ outputField .setText (outputPath );
1117
+
1118
+ // Exports the images into a folder
1119
+ try {
1120
+ for (int i = 0 ; i < splitHeights .size () - 1 ; i ++) {
1121
+ nameField .setText (nameField .getText () + "_" + (i + 1 ));
1122
+ File f = new File (outputPath + nameField .getText () + "." + fileOption );
1123
+
1124
+ ImageIO .write (image .getSubimage (0 , splitHeights .get (i ), image .getWidth (), splitHeights .get (i + 1 ) - splitHeights .get (i )), fileOption , f );
1125
+ if (waifuHelper (f )) {
1126
+ f .delete ();
1127
+ }
1128
+ nameField .setText (nameField .getText ().substring (0 , nameField .getLength () - 2 ));
1129
+ }
1130
+ } catch (IOException ex ) {
1131
+ ex .printStackTrace ();
1132
+ }
1133
+ return c ;
1134
+ }
1135
+
1108
1136
// Waifu2X the image
1109
1137
public boolean waifuHelper (File f ) {
1110
1138
// If the waifu2x.exe is not found
@@ -1157,7 +1185,7 @@ public boolean waifuHelper(File f) {
1157
1185
cmd .add ("-i" );
1158
1186
cmd .add ("\" " + f .getAbsolutePath () + "\" " );
1159
1187
cmd .add ("-o" );
1160
- cmd .add ("\" " + outputField .getText () + nameField .getText () + "." + fileOption + "\" " );
1188
+ cmd .add ("\" " + outputField .getText () + nameField .getText () + "_waifu ." + fileOption + "\" " );
1161
1189
1162
1190
if (waifuPath .contains ("CAFFE" )) {
1163
1191
// NOISE AND SCALE
@@ -1224,16 +1252,18 @@ else if (waifuPath.contains("VULKAN")) {
1224
1252
a .showAndWait ();
1225
1253
}
1226
1254
1227
- Alert a = new Alert (Alert .AlertType .INFORMATION );
1228
- a .setHeaderText (null );
1229
- if (denoiseBox .isSelected () && scaleBox .isSelected ()) {
1230
- a .setContentText ("Image has been denoised with level " + (int )denoiseSlider .getValue () + " and scaled by " + (int )Math .pow (2 , sf ) + "!" );
1231
- } else if (denoiseBox .isSelected () && !scaleBox .isSelected ()) {
1232
- a .setContentText ("Image has been denoised with level " + (int )denoiseSlider .getValue ());
1233
- } else if (!denoiseBox .isSelected () && scaleBox .isSelected ()) {
1234
- a .setContentText ("Image has been scaled by " + sf + "!" );
1255
+ if (!stitchSplit .isSelected () && !smartSplit .isSelected ()) {
1256
+ Alert a = new Alert (Alert .AlertType .INFORMATION );
1257
+ a .setHeaderText (null );
1258
+ if (denoiseBox .isSelected () && scaleBox .isSelected ()) {
1259
+ a .setContentText ("Image has been denoised with level " + (int ) denoiseSlider .getValue () + " and scaled by " + (int ) Math .pow (2 , sf ) + "!" );
1260
+ } else if (denoiseBox .isSelected () && !scaleBox .isSelected ()) {
1261
+ a .setContentText ("Image has been denoised with level " + (int ) denoiseSlider .getValue ());
1262
+ } else if (!denoiseBox .isSelected () && scaleBox .isSelected ()) {
1263
+ a .setContentText ("Image has been scaled by " + sf + "!" );
1264
+ }
1265
+ a .showAndWait ();
1235
1266
}
1236
- a .showAndWait ();
1237
1267
return true ;
1238
1268
}
1239
1269
@@ -1280,23 +1310,6 @@ public static final class FileNameComparator implements Comparator<String> {
1280
1310
}
1281
1311
}
1282
1312
1283
- // Converts Image to BufferedImage
1284
- public BufferedImage toBufferedImage (Image img ) {
1285
- if (img instanceof BufferedImage ) {
1286
- return (BufferedImage ) img ;
1287
- }
1288
-
1289
- // Create a buffered image with transparency
1290
- BufferedImage image = new BufferedImage (img .getWidth (null ), img .getHeight (null ), BufferedImage .TYPE_INT_ARGB );
1291
-
1292
- // Draw the image on to the buffered image
1293
- Graphics2D bGr = image .createGraphics ();
1294
- bGr .drawImage (img , 0 , 0 , null );
1295
- bGr .dispose ();
1296
-
1297
- return image ;
1298
- }
1299
-
1300
1313
// Creates a new JFrame that uses the ScrollPanel
1301
1314
public void previewImage (JFrame f , BufferedImage source , int num ) {
1302
1315
int height = source .getHeight ();
@@ -1309,7 +1322,7 @@ public void previewImage(JFrame f, BufferedImage source, int num) {
1309
1322
previewImage .getGraphics ().drawImage (tempImage , 0 , 0 , null );
1310
1323
1311
1324
// Creates a new JFrame window
1312
- JPanel p = new ScrollPanel (toBufferedImage ( previewImage ) , num );
1325
+ JPanel p = new ScrollPanel (previewImage , num );
1313
1326
f .setContentPane (p );
1314
1327
f .setResizable (false );
1315
1328
f .setSize (700 , 700 );
0 commit comments