2
2
using System . Drawing ;
3
3
using System . Drawing . Drawing2D ;
4
4
using System . IO ;
5
+ using System . Numerics ;
5
6
using System . Security . AccessControl ;
6
7
using System . Windows . Forms ;
7
8
using Cupscale . IO ;
@@ -20,6 +21,11 @@ public enum Mode { Basic, Interp, Chain, Advanced }
20
21
private static ComboBox outputFormat ;
21
22
private static ComboBox overwrite ;
22
23
24
+ public static Image currentOriginal ;
25
+ public static Image currentOutput ;
26
+
27
+ public static int currentScale = 1 ;
28
+
23
29
public static void Init ( ImageBox imgBox , ComboBox basicModelBox , ComboBox formatBox , ComboBox overwriteBox )
24
30
{
25
31
previewImg = imgBox ;
@@ -60,14 +66,14 @@ public static async void UpscaleImage()
60
66
Cancel ( "I/O Error" ) ;
61
67
return ;
62
68
}
63
- ImageProcessing . ConvertImages ( ImageProcessing . Format . PngFast , ! Config . GetBool ( "alpha" ) , true , true ) ;
69
+ UpscaleProcessing . ConvertImages ( UpscaleProcessing . Format . PngFast , ! Config . GetBool ( "alpha" ) , true , true ) ;
64
70
string mdl = GetMdl ( ) ;
65
71
if ( string . IsNullOrWhiteSpace ( mdl ) )
66
72
{
67
73
Cancel ( "Model Not Found" ) ;
68
74
return ;
69
75
}
70
- await ESRGAN . UpscaleBasic ( Paths . imgInPath , Paths . imgOutPath , mdl , Config . Get ( "tilesize" ) , bool . Parse ( Config . Get ( "alpha" ) ) ) ;
76
+ await ESRGAN . UpscaleBasic ( Paths . imgInPath , Paths . imgOutPath , mdl , Config . Get ( "tilesize" ) , bool . Parse ( Config . Get ( "alpha" ) ) , ESRGAN . PreviewMode . None ) ;
71
77
Postprocessing ( ) ;
72
78
AddModelSuffix ( Paths . imgOutPath ) ;
73
79
CopyImagesToOriginalLocation ( ) ;
@@ -109,17 +115,17 @@ static async void Postprocessing()
109
115
await Program . PutTaskDelay ( ) ;
110
116
Logger . Log ( "Postprocessing - outputFormat.SelectedIndex = " + outputFormat . SelectedIndex ) ;
111
117
if ( outputFormat . SelectedIndex == 0 )
112
- ImageProcessing . ChangeOutputExtensions ( "png" ) ;
118
+ UpscaleProcessing . ChangeOutputExtensions ( "png" ) ;
113
119
if ( outputFormat . SelectedIndex == 1 )
114
- ImageProcessing . ConvertImagesToOriginalFormat ( ) ;
120
+ UpscaleProcessing . ConvertImagesToOriginalFormat ( ) ;
115
121
if ( outputFormat . SelectedIndex == 2 )
116
- ImageProcessing . ConvertImages ( ImageProcessing . Format . JpegHigh ) ;
122
+ UpscaleProcessing . ConvertImages ( UpscaleProcessing . Format . JpegHigh ) ;
117
123
if ( outputFormat . SelectedIndex == 3 )
118
- ImageProcessing . ConvertImages ( ImageProcessing . Format . JpegMed ) ;
124
+ UpscaleProcessing . ConvertImages ( UpscaleProcessing . Format . JpegMed ) ;
119
125
if ( outputFormat . SelectedIndex == 4 )
120
- ImageProcessing . ConvertImages ( ImageProcessing . Format . WeppyHigh ) ;
126
+ UpscaleProcessing . ConvertImages ( UpscaleProcessing . Format . WeppyHigh ) ;
121
127
if ( outputFormat . SelectedIndex == 5 )
122
- ImageProcessing . ConvertImages ( ImageProcessing . Format . WeppyLow ) ;
128
+ UpscaleProcessing . ConvertImages ( UpscaleProcessing . Format . WeppyLow ) ;
123
129
}
124
130
125
131
static void AddModelSuffix ( string path )
@@ -147,9 +153,11 @@ static void CopyImagesToOriginalLocation()
147
153
public static async void UpscalePreview ( bool fullImage = false )
148
154
{
149
155
Program . mainForm . SetPreviewProgress ( 3f , "Preparing..." ) ;
150
- if ( fullImage )
156
+ ESRGAN . PreviewMode prevMode = ESRGAN . PreviewMode . Cutout ;
157
+ if ( fullImage )
151
158
{
152
- if ( ! IOUtils . TryCopy ( Program . lastFilename , Path . Combine ( Paths . previewPath , "preview.png" ) , true ) ) return ;
159
+ prevMode = ESRGAN . PreviewMode . FullImage ;
160
+ if ( ! IOUtils . TryCopy ( Program . lastFilename , Path . Combine ( Paths . previewPath , "preview.png" ) , true ) ) return ;
153
161
}
154
162
else
155
163
{
@@ -160,7 +168,7 @@ public static async void UpscalePreview(bool fullImage = false)
160
168
string mdl = GetMdl ( ) ;
161
169
if ( string . IsNullOrWhiteSpace ( mdl ) ) return ;
162
170
Logger . Log ( Paths . previewPath + " - " + Paths . previewOutPath + " - " + mdl + " - " + Config . Get ( "tilesize" ) + " - " + bool . Parse ( Config . Get ( "alpha" ) ) ) ;
163
- await ESRGAN . UpscaleBasic ( Paths . previewPath , Paths . previewOutPath , mdl , Config . Get ( "tilesize" ) , bool . Parse ( Config . Get ( "alpha" ) ) , isPreview : true ) ;
171
+ await ESRGAN . UpscaleBasic ( Paths . previewPath , Paths . previewOutPath , mdl , Config . Get ( "tilesize" ) , bool . Parse ( Config . Get ( "alpha" ) ) , prevMode ) ;
164
172
}
165
173
}
166
174
@@ -194,18 +202,17 @@ public static Bitmap GetCurrentRegion() // thx ieu
194
202
double zoomFactor = previewImg . ZoomFactor ;
195
203
int num3 = ( int ) Math . Round ( SystemInformation . VerticalScrollBarWidth / zoomFactor ) ;
196
204
int num4 = ( int ) Math . Round ( SystemInformation . HorizontalScrollBarHeight / zoomFactor ) ;
197
- Size size = previewImg . Image . Size ;
198
205
int num5 = ( int ) Math . Round ( sourceImageRegion . Width * zoomFactor ) ;
199
206
int num6 = ( int ) Math . Round ( sourceImageRegion . Height * zoomFactor ) ;
200
- Size size2 = previewImg . GetInsideViewPort ( ) . Size ;
207
+ Size size = previewImg . GetInsideViewPort ( ) . Size ;
201
208
Logger . Log ( "Saving current region to bitmap. Offset: " + previewImg . AutoScrollPosition . X + "x" + previewImg . AutoScrollPosition . Y ) ;
202
209
PreviewMerger . offsetX = ( float ) previewImg . AutoScrollPosition . X / ( float ) previewImg . ZoomFactor ;
203
210
PreviewMerger . offsetY = ( float ) previewImg . AutoScrollPosition . Y / ( float ) previewImg . ZoomFactor ;
204
- if ( num5 <= size2 . Width )
211
+ if ( num5 <= size . Width )
205
212
{
206
213
num3 = 0 ;
207
214
}
208
- if ( num6 <= size2 . Height )
215
+ if ( num6 <= size . Height )
209
216
{
210
217
num4 = 0 ;
211
218
}
@@ -222,5 +229,29 @@ public static Bitmap GetCurrentRegion() // thx ieu
222
229
}
223
230
return bitmap ;
224
231
}
232
+
233
+ public static SizeF GetCutoutSize ( )
234
+ {
235
+ SizeF cutoutSize = previewImg . GetSourceImageRegion ( ) . Size ;
236
+ cutoutSize . Width = ( int ) Math . Round ( cutoutSize . Width ) ;
237
+ cutoutSize . Height = ( int ) Math . Round ( cutoutSize . Height ) ;
238
+ return cutoutSize ;
239
+ }
240
+
241
+ public static void ResetCachedImages ( )
242
+ {
243
+ currentOriginal = null ;
244
+ currentOutput = null ;
245
+ }
246
+
247
+ public static void UpdatePreviewLabels ( Label zoom , Label size , Label cutout )
248
+ {
249
+ int currScale = currentScale ;
250
+ int cutoutW = ( int ) GetCutoutSize ( ) . Width ;
251
+ int cutoutH = ( int ) GetCutoutSize ( ) . Height ;
252
+ zoom . Text = "Zoom: " + previewImg . Zoom + "% (Original: " + previewImg . Zoom * currScale + "%)" ;
253
+ size . Text = "Size: " + previewImg . Image . Width + "x" + previewImg . Image . Height + " (Original: " + previewImg . Image . Width / currScale + "x" + previewImg . Image . Height / currScale + ")" ;
254
+ cutout . Text = "Cutout: " + cutoutW + "x" + cutoutH + " (Original: " + cutoutW / currScale + "x" + cutoutH / currScale + ")" ; // + "% - Unscaled Size: " + previewImg.Image.Size * currScale + "%";
255
+ }
225
256
}
226
257
}
0 commit comments