-
Notifications
You must be signed in to change notification settings - Fork 0
/
Gui Dark.ahk
426 lines (335 loc) · 12.1 KB
/
Gui Dark.ahk
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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn ; Enable warnings to assist with detecting common errors.
SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.
#NoTrayIcon
#SingleInstance Force
#Include %A_ScriptDir%\DarkGui\Class_ImageButton.ahk
#Include %A_ScriptDir%\DarkGui\UseGDIP.ahk
Menu, tray, Icon , UpscaleUI.ico
DetectHiddenWindows, ON
upscaler:=A_ScriptDir . "realesrgan-ncnn-vulkan.exe"
;--------------------------------UI start---------------------------
Gui, Destroy
Gui, New , HwndCustomUpscale, UpscaleUI
DllCall("dwmapi\DwmSetWindowAttribute", "ptr", CustomUpscale, "int", "20", "int*", true, "int", 4)
GuiColor := "0x171717"
GuiElementsColor := "0x333333"
Gui, Font, s10 q4, ;Poppins
Gui, Color, %GuiColor%, %GuiElementsColor%
ImageButton.SetGuiColor(GuiColor)
Opt1 := [0, GuiElementsColor, , "White", 7, , 0x555555, 1]
Opt2 := [ , 0x414141]
Gui, Add, Text, x25 y20 w280 h20 +Center cwhite, Select an action.
Gui, Add, Button, hwndHBT1 vUpscale gUpscale x25 w134 h30 , Real-plus
ImageButton.Create(HBT1, Opt1, Opt2, , , Opt5)
Gui, Add, Button, hwndHBT1 vAnimeUpscale gAnimeUpscale x+12 wp hp , Anime
ImageButton.Create(HBT1, Opt1, Opt2, , , Opt5)
Gui, Add, Button, hwndHBT1 vRealSRUpscale gRealSRUpscale x25 y+12 wp hp , Real
ImageButton.Create(HBT1, Opt1, Opt2, , , Opt5)
Gui, Add, Button, hwndHBT1 vBSRGANUpscale gBSRGANUpscale x+12 wp hp , BSRGAN
ImageButton.Create(HBT1, Opt1, Opt2, , , Opt5)
Gui, Add, CheckBox, Checked vEnhaTran x26 y+15 h20 w20,
Gui, Add, Text, x+-0 y+-18 w95 h20 +Left cwhite gCheckbox, clean transp.
Gui, Add, Text, x+-15 y+-20 w110 h20 +Right cwhite, Scale:
Gui, Add, Button, x+5 y+-25 w60 h26 hwndHBT1 vBackground1,
ImageButton.Create(HBT1, Opt1, Opt1, , , Opt1)
Gui, Add, Edit, x+-56 y+-21 h16 w55 +Center -E0x200 -Border cwhite
Gui, Add, UpDown, Hidden vImageScale Range100-400, 400
Gui, Add, Picture, x+-14 y+-21 gUpRound, DarkGui\UpRound.png
Gui, Add, Picture, y+-0 gDownRound, DarkGui\DownRound.png
Gui, Add, Button, hwndHBT1 vAnimeVideoUpscale gAnimeVideoUpscale x25 y+30 w280 h30 , Anime Video Upscale
ImageButton.Create(HBT1, Opt1, Opt2, , , Opt5)
Gui, Add, CheckBox, Checked vFFMPEG x26 y+15 h20 w20,
Gui, Add, Text, x+-0 y+-18 w95 h20 +Left cwhite gCheckbox2, installed ffmpeg
Gui, Add, Text, x+0 y+-20 w110 h20 +Right cwhite, Scale:
Gui, Add, Button, x+5 y+-25 w45 h26 hwndHBT1 vBackground2,
ImageButton.Create(HBT1, Opt1, Opt1, , , Opt1)
Gui, Add, Edit, x+-41 y+-21 h16 w40 +Center -E0x200 -Border cwhite
Gui, Add, UpDown, Hidden vscale Range2-4, 4
Gui, Add, Picture, x+-14 y+-21 gUpRound2, DarkGui\UpRound.png
Gui, Add, Picture, y+-0 gDownRound2, DarkGui\DownRound.png
Gui, Add, Text, vProgressText x25 y+30 w280 h16 cwhite, Progress:
Gui, Add, Button, hwndHBT1 x25 y+8 w280 h22 vBackground3,
ImageButton.Create(HBT1, Opt1, Opt2, , , Opt5)
Gui, Add, Progress, x+-279 y+-21 w278 h20 Background%GuiElementsColor% c005FB8 vProgress, 0
loop 3
GuiControl, Disable, % "Background" . A_Index
;ControlFocus, Button1, AniRip ahk_class AutoHotkeyGUI
gui margin,25,25
Gui, Show, hide
Gui, Show
Return
UpRound:
Gui, Submit, NoHide
GuiControl, , ImageScale, % ImageScale + 25
return
DownRound:
Gui, Submit, NoHide
GuiControl, , ImageScale, % ImageScale - 25
return
UpRound2:
Gui, Submit, NoHide
GuiControl, , scale, % scale + 1
return
DownRound2:
Gui, Submit, NoHide
GuiControl, , scale, % scale - 1
return
Checkbox:
Gui, Submit, NoHide
GuiControl, , EnhaTran, % EnhaTran * (- 1) + 1
return
Checkbox2:
Gui, Submit, NoHide
GuiControl, , FFMPEG, % FFMPEG * (- 1) + 1
return
;-------------------------------------Drop files on GUI---------------------------------
GuiDropFiles:
Gui, Submit, NoHide
inputArray := []
outputArray := []
outputArray1 := []
outputArray2 := []
outputArray3 := []
outputArray4 := []
if (A_GuiControl = "Upscale") {
model:="realesrgan-x4plus"
fileExt:="_x4"
}
else if (A_GuiControl = "BSRGANUpscale") {
model:="bsrgan-x4"
fileExt:="_x4BSRGAN"
}
else if (A_GuiControl = "RealSRUpscale") {
model:="realsrgan-x4"
fileExt:="_x4real"
}
else if (A_GuiControl = "AnimeVideoUpscale") {
fileExt:="_x4video"
}
else if (A_GuiControl = "Progress") {
fileExt:="all"
}
else {
model:="realesrgan-x4plus-anime"
fileExt:="_x4anime"
}
Loop, Parse, A_GuiEvent, `n
{
if (fileExt!="_x4video" and IsImageFile(A_LoopField)) {
inputArray.Push(A_LoopField)
RegExMatch(A_LoopField, "(.*)(\..*)", SubPart)
;if SubPart2=".webp"
; SubPart2=".png"
if (fileExt="all") {
outPath1:=SubPart1 . "_x4" . SubPart2
outPath2:=SubPart1 . "_x4BSRGAN" . SubPart2
outPath3:=SubPart1 . "_x4real" . SubPart2
outPath4:=SubPart1 . "_x4anime" . SubPart2
outputArray1.Push(outPath1)
outputArray2.Push(outPath2)
outputArray3.Push(outPath3)
outputArray4.Push(outPath4)
}
else {
outPath:=SubPart1 . fileExt . SubPart2
outputArray.Push(outPath)
}
}
else if (fileExt="_x4video" and IsVideoFile(A_LoopField)) {
inputArray.Push(A_LoopField)
RegExMatch(A_LoopField, "(.*)(\..*)", SubPart)
outPath:=SubPart1 . fileExt . SubPart2
outputArray.Push(outPath)
}
else if (fileExt!="_x4video")
msgbox %A_LoopField% `n`nThis file type is not supported. `nSupported file types are: png, jpg, webp`nThe program will skip this file.
else if (fileExt="_x4video")
msgbox %A_LoopField% `n`nThis file type is not supported. `nSupported file types are: mp4, mkv`nThe program will skip this file.
}
if (fileExt="_x4video")
upscaleVideo(scale)
else if (fileExt="all") {
outputArray:=outputArray1
upscale("realesrgan-x4plus")
GuiControl,, Progress, 0
GuiControl,, ProgressText, Progress:
outputArray:=outputArray2
upscale("bsrgan-x4")
GuiControl,, Progress, 0
GuiControl,, ProgressText, Progress:
outputArray:=outputArray3
upscale("realsrgan-x4")
GuiControl,, Progress, 0
GuiControl,, ProgressText, Progress:
outputArray:=outputArray4
upscale("realesrgan-x4plus-anime")
}
else
upscale(model)
return
;-------------------------------------Image Upscale via Buttons---------------------------------
Upscale:
createArray("\Upscale_x4\")
upscale("realesrgan-x4plus-anime")
Return
AnimeUpscale:
createArray("\Upscale_x4Anime\")
upscale("realesrgan-x4plus-anime")
Return
BSRGANUpscale:
createArray("\Upscale_x4BSRGAN\")
upscale("bsrgan-x4")
Return
RealSRUpscale:
createArray("\Upscale_x4RealSR\")
upscale("realsrgan-x4")
Return
createArray(folderName) {
global inputArray := []
global outputArray := []
FileSelectFile, imagesToUpscale , M 1, Image File, Select the Images you want to Upscale, Images (*.png; *.jpg; *.webp)
loop,parse,imagesToUpscale,`n,`r
{
if (A_Index = 1) {
path:=A_loopfield
continue
}
if IsImageFile(A_LoopField) {
inputArray.Push(path . "\" . A_loopfield)
outputArray.Push(path . folderName . A_loopfield)
}
else
msgbox %A_LoopField% `n`nThis file type is not supported. `nSupported file types are: png, jpg, webp`nThe program will skip this file.
}
}
;-------------------------------------Image Upscale Funktion---------------------------------
upscale(model) {
Gui, Submit, NoHide
global inputArray
global outputArray
global EnhaTran
global ImageScale
numberOfFiles := inputArray.MaxIndex()
GuiControl,, Progress, 0
GuiControl,, ProgressText, Progress: 0`% (0/%numberOfFiles%)
Loop %numberOfFiles% {
input:=inputArray[A_Index]
output:=outputArray[A_Index]
RunWait, "realesrgan-ncnn-vulkan.exe" -i "%input%" -o "%output%" -n %model%, , Hide
;if (IsImageFile(input)=3) {
; RunWait, %ComSpec% /c ImageMagick-7.1.0-62-portable-Q16-HDRI-x64\magick.exe "%input%" Temp\pngConvert.png, ,Hide
; input:="Temp\pngConvert.png"
;}
if (IsImageFile(input)>1 and EnhaTran=1) {
RunWait, %ComSpec% /c ImageMagick-7.1.0-62-portable-Q16-HDRI-x64\identify.exe -format '`%[channels]' "%input%" >>Temp\alpha.txt, ,Hide
FileRead, isAlpha, Temp\alpha.txt
if inStr(isAlpha, "a") {
RunWait, %ComSpec% /c ImageMagick-7.1.0-62-portable-Q16-HDRI-x64\convert.exe "%input%" -alpha extract Temp\alpha.png, ,Hide
RunWait, "realesrgan-ncnn-vulkan.exe" -i Temp\alpha.png -o Temp\alphaUpscale.png -n %model%, , Hide
RunWait, %ComSpec% /c ImageMagick-7.1.0-62-portable-Q16-HDRI-x64\convert.exe "%output%" Temp\alphaUpscale.png -alpha off -compose copy_opacity -composite "%output%", ,Hide
}
}
if (ImageScale < 400) {
ImageScale:=ImageScale/4
RunWait, %ComSpec% /c ImageMagick-7.1.0-62-portable-Q16-HDRI-x64\magick.exe "%output%" -resize %ImageScale%`% "%output%", ,Hide
}
varProgress:=Ceil(A_Index/numberOfFiles*100)
GuiControl,, Progress, %varProgress%
GuiControl,, ProgressText, Progress: %varProgress%`% (%A_Index%/%numberOfFiles%)
}
}
;-------------------------------------Video Upscale via Buttons---------------------------------
AnimeVideoUpscale:
Gui, Submit, NoHide
;FileRemoveDir, tmp_frames, 1
;FileRemoveDir, out_frames, 1
; select Video
FileSelectFile, videosToUpscale , M 1, Video File, Select the Videos you want to Upscale, Videos (*.mp4; *.mkv)
if ErrorLevel
return
;count how many videos to upscale
inputArray:=[]
outputArray:=[]
loop,parse,videosToUpscale,`n,`r
{
if (A_Index = 1) {
path:=A_loopfield
continue
}
if IsVideoFile(A_LoopField) {
inputArray.Push(path . "\" . A_loopfield)
outputArray.Push(path . "\Upscale_Video\" . A_loopfield)
}
else
msgbox %A_LoopField% `n`nThis file type is not supported. `nSupported file types are: mp4, mkv`nThe program will skip this file.
}
if (path!="") {
FileCreateDir, %path%\Upscale_Video
}
upscaleVideo(scale)
Return
;-------------------------------------Video Upscale Funktion---------------------------------
upscaleVideo(scale) {
global inputArray
global outputArray
global FFMPEG
FileCreateDir, tmp_frames
FileCreateDir, out_frames
numberOfFiles:=inputArray.MaxIndex()
GuiControl,, Progress, 0
GuiControl,, ProgressText, Progress: 0`% (0/%numberOfFiles%)
Loop % numberOfFiles {
input:=inputArray[A_Index]
output:=outputArray[A_Index]
;FileDelete, %output%
if (FFMPEG=0)
RunWait, "FFmpeg\bin\ffmpeg.exe" -i "%input%" -qscale:v 1 -qmin 1 -qmax 1 -vsync 0 "tmp_frames/frame`%08d.jpg", , Hide
else
RunWait, ffmpeg -i "%input%" -qscale:v 1 -qmin 1 -qmax 1 -vsync 0 "tmp_frames/frame`%08d.jpg", , Hide
varProgress:=Ceil(A_Index*0.33/numberOfFiles*100)
GuiControl,, Progress, %varProgress%
GuiControl,, ProgressText, % "Progress: " . varProgress . "%" . " (" A_Index-1 . "/" . numberOfFiles . ")"
RunWait, realesrgan-ncnn-vulkan.exe -i tmp_frames -o out_frames -n realesr-animevideov3 -s %scale% -f jpg, , Hide
varProgress:=Ceil(A_Index*0.66/numberOfFiles*100)
GuiControl,, Progress, %varProgress%
GuiControl,, ProgressText, % "Progress: " . varProgress . "%" . " (" A_Index-1 . "/" . numberOfFiles . ")"
if (FFMPEG=0)
RunWait, "FFmpeg\bin\ffmpeg.exe" -i out_frames/frame`%08d.jpg -i "%input%" -map 0:v:0 -map 1:a:0 -c:a copy -c:v libx264 -r 23.98 -pix_fmt yuv420p "%output%", , Hide
else
RunWait, ffmpeg -i out_frames/frame`%08d.jpg -i "%input%" -map 0:v:0 -map 1:a:0 -c:a copy -c:v libx264 -r 23.98 -pix_fmt yuv420p "%output%", , Hide
varProgress:=Ceil(A_Index/numberOfFiles*100)
GuiControl,, Progress, %varProgress%
GuiControl,, ProgressText, Progress: %varProgress%`% (%A_Index%/%numberOfFiles%)
}
}
IsImageFile(filePath) {
; Split the file path by the dot character
Array := StrSplit(filePath , ".")
; Get the last part of the split string, which should be the file extension
fileExt := Array[Array.MaxIndex()]
; Check if it's an image file
if (fileExt = "jpg")
return 1
else if (fileExt = "png")
return 2
else if (fileExt = "webp")
return 3
else
return 0
}
IsVideoFile(filePath) {
; Split the file path by the dot character
Array := StrSplit(filePath , ".")
; Get the last part of the split string, which should be the file extension
fileExt := Array[Array.MaxIndex()]
; Check if it's an image file
if (fileExt = "mp4" or fileExt = "mkv")
return 1
else
return 0
}
GuiClose:
ExitApp
return