generated from Nigh/ahk-autoupdate-template
-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.ahk
250 lines (217 loc) · 6.76 KB
/
app.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
SetWorkingDir(A_ScriptDir)
#SingleInstance force
#include meta.ahk
;@Ahk2Exe-SetName %appName%
;@Ahk2Exe-SetVersion %version%
;@Ahk2Exe-SetMainIcon icon.ico
;@Ahk2Exe-ExeName %appName%
#include prod.ahk
; if you need admin privilege, enable it.
if(0)
{
UAC()
}
#include update.ahk
setTray()
OnExit(trueExit)
; ===============================================================
; ===============================================================
; your code below
DirCreate(A_Temp "\CYKSM\models_realesrgan")
FileInstall(".\realesrgan-ncnn-vulkan.exe", A_Temp "\CYKSM\rn-vulkan.exe", 1)
FileInstall(".\vcomp140.dll", A_Temp "\CYKSM\vcomp140.dll", 1)
FileInstall(".\vcomp140d.dll", A_Temp "\CYKSM\vcomp140d.dll", 1)
FileInstall(".\models_realesrgan\realesrgan-x4plus-anime.bin", A_Temp "\CYKSM\models_realesrgan\realesrgan-x4plus-anime.bin", 1)
FileInstall(".\models_realesrgan\realesrgan-x4plus-anime.param", A_Temp "\CYKSM\models_realesrgan\realesrgan-x4plus-anime.param", 1)
MonitorGet(0, &Left, &Top, &Right, &Bottom)
DPIScale := A_ScreenDPI / 96
DPIScaled(n) {
return Round(n * DPIScale)
}
DPIScaledFont(n) {
return Round(n * (DPIScale ** 0.5))
}
Screen_Height:=Bottom-Top
Screen_Width:=Right-Left
gui_margin := DPIScaled(10)
#include Gdip_All.ahk
pGDI := Gdip_Startup()
Class anime4x
{
static state := 0
static afterfunc := ""
static callbackfunc := ""
static inputfile := ""
static outputfile := ""
static input_bitmap := ""
static output_bitmap := ""
static inputpath(inputfile) {
this.inputfile := inputfile
this.input_bitmap:=Gdip_CreateBitmapFromFile(this.inputfile)
Return this.input_bitmap
}
static outputpath(outputfile) {
this.outputfile := outputfile
}
static after(func) {
this.afterfunc := func
}
static callback(func) {
this.callbackfunc := func
}
static go() {
if not FileExist(this.inputfile) {
MsgBox "未找到输入图片,请重新拖入"
return
}
if FileExist(this.outputfile) {
FileDelete this.outputfile
}
this.state := 1
SetTimer(this.callbackfunc, 150)
RunWait(A_Temp '\CYKSM\rn-vulkan.exe -i "' this.inputfile '" -o "' this.outputfile '" -n realesrgan-x4plus-anime -m models_realesrgan',,"Hide")
SetTimer(this.callbackfunc, 0)
this.state := 0
this.output_bitmap:=Gdip_CreateBitmapFromFile(this.outputfile)
SetTimer(this.afterfunc, -1)
}
}
mygui:=Gui("-AlwaysOnTop -Owner -DpiScale")
myGui.OnEvent("Close", myGui_Close)
myGui.OnEvent("DropFiles", mygui_DropFiles)
mygui.SetFont("s32 Q5", "Meiryo")
mygui.Add("Text","x20 y10 Section","次元克赛马")
mygui.SetFont("s10 Q5", "Meiryo")
mygui.Add("Text","x+20 y+-52","v" . version)
mygui.Add("Link","xp y+0",'bilibili: <a href="https://space.bilibili.com/895523">TecNico</a>')
mygui.Add("Link","xp y+0",'GitHub: <a href="https://github.com/Nigh">xianii</a>')
mygui.Add("Text","x50 yp","二次元反向马赛克工具")
mygui.SetFont("s10 Q5 Bold", "Meiryo")
ori_label:=mygui.Add("Text","x20 y+10 w400 h20 center", "原图")
new_label:=mygui.Add("Text","x+10 yp w400 h20 center", "转换后")
ori_pic:=mygui.Add("Picture", "x20 y+0 w400 h400 0xE 0x200 0x800000 -0x40")
new_pic:=mygui.Add("Picture", "x+10 w400 h400 0xE 0x200 0x800000 -0x40")
ori_size:=mygui.Add("Text","x20 y+0 w400 h20 center", "NULL")
new_size:=mygui.Add("Text","x+10 yp w400 h20 center", "NULL")
runBtn:=mygui.Add("Button", "x20 y+10 w810 r3 Disabled", "转换")
runBtn.OnEvent("Click", generate)
generate(btn, *) {
btn.Enabled:=false
btn.Text := "转换中"
ends(){
global new_pic, ori_pic, new_size
btn.Text:="转换"
Gdip_GetImageDimensions(anime4x.output_bitmap, &W, &H)
new_size.Text := W "x" H
mygui_ctrl_show_pic(new_pic, anime4x.output_bitmap)
btn.gui.Opt("+OwnDialogs")
MsgBox("转换完成,已保存为`n" anime4x.outputfile)
}
proc() {
if(StrLen(btn.Text)<19) {
btn.Text:="< " btn.Text " >"
} else {
btn.Text:="转换中"
}
}
anime4x.callback(proc)
anime4x.after(ends)
anime4x.go()
}
mygui.Show("AutoSize")
Return
mygui_set_pic_size(picW, picH)
{
global Screen_Width, Screen_Height, ori_pic, new_pic, ori_label, new_label, ori_size, new_size, runBtn, gui_margin
ratio := picW / picH
minW:=DPIScaled(400)
minH:=DPIScaled(400)
maxW:=0.4*Screen_Width
maxH:=0.6*Screen_Height
percent := 1
percent := Min(percent, maxH / picH)
percent := Min(percent, maxW / picW)
percent *= Min(maxW / (picH * percent * ratio), 1)
ctrlH := Round(picH * percent) + 0
ctrlW := Round(ctrlH * ratio) + 0
ori_label.Move(gui_margin, , ctrlW, 20)
new_label.Move(gui_margin+gui_margin+ctrlW, , ctrlW, 20)
ori_pic.Move(gui_margin, , ctrlW, ctrlH)
new_pic.Move(gui_margin+gui_margin+ctrlW, , ctrlW, ctrlH)
ori_pic.GetPos(,&y)
ori_size.Move(gui_margin, y+ctrlH, ctrlW, 20)
new_size.Move(gui_margin+gui_margin+ctrlW, y+ctrlH, ctrlW, 20)
runBtn.Move(gui_margin, y+ctrlH+gui_margin+20, 2*ctrlW+gui_margin)
new_pic.gui.Show("AutoSize xCenter yCenter")
ori_label.Redraw()
new_label.Redraw()
new_pic.Redraw()
ori_pic.Redraw()
ori_size.Redraw()
new_size.Redraw()
Return percent
}
mygui_ctrl_show_pic(GuiCtrlObj, pBitmap)
{
Gdip_GetImageDimensions(pBitmap, &W, &H)
percent := mygui_set_pic_size(W, H)
picW:=W*percent
picH:=H*percent
; GuiCtrlObj.GetPos(,, &ctrlW, &ctrlH)
pBitmapShow := Gdip_CreateBitmap(picW, picH)
G := Gdip_GraphicsFromImage(pBitmapShow)
Gdip_SetSmoothingMode(G, 4)
Gdip_SetInterpolationMode(G, 7)
Gdip_DrawImage(G, pBitmap, 0, 0, picW, picH)
hBitmapShow := Gdip_CreateHBITMAPFromBitmap(pBitmapShow)
SetImage(GuiCtrlObj.hwnd, hBitmapShow)
Gdip_DeleteGraphics(G), Gdip_DisposeImage(pBitmapShow), DeleteObject(hBitmapShow)
Gdip_DisposeImage(pBitmap)
}
mygui_DropFiles(GuiObj, GuiCtrlObj, FileArray, X, Y) {
global ori_pic, new_pic, ori_size, new_size, runBtn
GuiObj.Opt("+OwnDialogs")
if(FileArray.Length>1) {
MsgBox "一次只能拖进一个文件哦"
Return
}
SplitPath(FileArray[1],,,&Ext)
if(anime4x.inputpath(FileArray[1])<=0||!RegExMatch(Ext, "i)(jpg|jpeg|png|jfif)$")) {
MsgBox "无效的图片文件"
} else {
runBtn.Enabled:=True
Gdip_GetImageDimensions(anime4x.input_bitmap, &W, &H)
mygui_ctrl_show_pic(ori_pic ,anime4x.input_bitmap)
ori_size.Text := W "x" H
new_size.Text := "NULL"
SetImage(new_pic.hwnd, 0)
SplitPath(FileArray[1],,,,&name)
anime4x.outputpath(A_ScriptDir "\" name "_4x.png")
}
}
mygui_Close(thisGui) {
trueExit(0, 0)
}
trueExit(ExitReason, ExitCode){
global pGDI
Gdip_Shutdown(pGDI)
ExitApp
}
; ===============================================================
; ===============================================================
UAC()
{
full_command_line := DllCall("GetCommandLine", "str")
if not (A_IsAdmin or RegExMatch(full_command_line, " /restart(?!\S)")) {
try
{
if A_IsCompiled
Run '*RunAs "' A_ScriptFullPath '" /restart'
else
Run '*RunAs "' A_AhkPath '" /restart "' A_ScriptFullPath '"'
}
ExitApp
}
}
#include tray.ahk