-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathmain.aardio
389 lines (357 loc) · 19.9 KB
/
main.aardio
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
import fsys.dlg
import process
import win.ui
import win.ui.tooltip
/*DSG{{*/
mainForm = win.form(cls="RIMG_GUI_FORM";text="rimage_gui";right=587;bottom=497;border="thin";max=false)
mainForm.add(
auto_delete={cls="checkbox";text="删除原件 DelOriginal";left=274;top=375;right=458;bottom=400;bgcolor=65535;color=255;font=LOGFONT(h=-16;name='微软雅黑');z=21};
backup_original={cls="checkbox";text="保存备份 BackupOriginal";left=30;top=376;right=244;bottom=401;bgcolor=65535;color=255;font=LOGFONT(h=-16;name='微软雅黑');z=23};
check_O_resize={cls="checkbox";text="不变 Original";left=423;top=174;right=528;bottom=193;checked=1;font=LOGFONT(h=-13;name='微软雅黑');z=24};
combobox_resize_filter={cls="combobox";left=453;top=260;right=546;bottom=280;edge=1;font=LOGFONT(h=-14;name='微软雅黑');items={"lanczos3";"nearest";"box";"bilinear";"hamming";"catmull-rom";"mitchell"};mode="dropdown";z=25};
edit_color_d={cls="edit";text="100";left=538;top=122;right=575;bottom=147;align="center";edge=1;font=LOGFONT(h=-16;name='微软雅黑');num=1;z=16};
edit_color_q={cls="edit";text="100";left=538;top=73;right=574;bottom=98;align="center";edge=1;font=LOGFONT(h=-16;name='微软雅黑');num=1;z=11};
edit_o_dir={cls="edit";left=155;top=466;right=461;bottom=491;autovscroll=false;disabled=1;edge=1;font=LOGFONT(h=-14;name='微软雅黑');readonly=1;z=9};
edit_o_quality={cls="edit";text="85";left=538;top=23;right=575;bottom=48;align="center";edge=1;font=LOGFONT(h=-16;name='微软雅黑');num=1;z=6};
edit_o_subfolder={cls="edit";left=412;top=406;right=499;bottom=431;autovscroll=false;disabled=1;edge=1;font=LOGFONT(h=-14;name='微软雅黑');z=27};
edit_resize={cls="edit";text="参数ResizeArgs";left=423;top=200;right=575;bottom=225;disabled=1;edge=1;font=LOGFONT(h=-16;name='微软雅黑');z=29};
edit_suffix={cls="edit";text="_updated";left=96;top=308;right=186;bottom=333;align="center";edge=1;font=LOGFONT(h=-16;name='微软雅黑');z=18};
edit_thread={cls="edit";text="4";left=290;top=308;right=327;bottom=333;align="center";edge=1;font=LOGFONT(h=-16;name='微软雅黑');num=1;z=13};
file_list={cls="listbox";left=7;top=31;right=414;bottom=295;acceptfiles=1;edge=1;font=LOGFONT(h=-14;name='微软雅黑');hscroll=1;items={};vscroll=1;z=19};
out_format={cls="combobox";left=478;top=307;right=565;bottom=333;edge=1;font=LOGFONT(h=-16;name='微软雅黑');items={"jpg";"png";"jxl";"webp";"avif"};mode="dropdown";z=8};
preserve_structure={cls="checkbox";text="原目录输出 OutputInOriginalDir";left=274;top=346;right=542;bottom=371;bgcolor=65535;checked=1;color=255;font=LOGFONT(h=-16;name='微软雅黑');z=22};
process_show={cls="edit";left=7;top=436;right=461;bottom=461;autovscroll=false;edge=1;font=LOGFONT(h=-14;name='微软雅黑');multiline=1;readonly=1;vscroll=1;z=14};
resize_box={cls="groupbox";text="Resize_choose";left=419;top=155;right=583;bottom=287;edge=1;font=LOGFONT(name='微软雅黑');z=1};
show_hide={cls="checkbox";text="隐藏执行 HiddenExecute";left=30;top=346;right=243;bottom=371;bgcolor=65535;checked=1;color=255;font=LOGFONT(h=-16;name='微软雅黑');z=20};
start_cov={cls="button";text="开始 Start";left=468;top=436;right=581;bottom=491;border=1;default=1;font=LOGFONT(h=-17;name='微软雅黑');z=4};
static_dithering={cls="static";text="颜色抖动
Dithering";left=417;top=112;right=530;bottom=158;align="center";font=LOGFONT(h=-16;name='微软雅黑');notify=1;transparent=1;z=15};
static_file_list={cls="static";text="文件列表 File list";left=7;top=4;right=141;bottom=29;align="center";center=1;font=LOGFONT(h=-16;name='微软雅黑');notify=1;transparent=1;z=3};
static_out_dir={cls="static";text="输出目录 Out-Dir:";left=7;top=466;right=155;bottom=491;align="center";center=1;font=LOGFONT(h=-16;name='微软雅黑');notify=1;transparent=1;z=2};
static_out_format={cls="static";text="输出格式
Out-Format";left=359;top=299;right=472;bottom=340;align="center";font=LOGFONT(h=-16;name='微软雅黑');notify=1;transparent=1;z=7};
static_out_quailty={cls="static";text="输出质量
Out-Quality";left=417;top=13;right=530;bottom=59;align="center";font=LOGFONT(h=-16;name='微软雅黑');notify=1;transparent=1;z=5};
static_quantization={cls="static";text="量化程度
Quantization";left=417;top=63;right=530;bottom=109;align="center";font=LOGFONT(h=-16;name='微软雅黑');notify=1;transparent=1;z=10};
static_resize={cls="static";text="缩放算法 ResizeFilter";left=429;top=232;right=571;bottom=258;align="center";center=1;font=LOGFONT(h=-13;name='微软雅黑');notify=1;transparent=1;z=26};
static_suffix={cls="static";text="输出后缀
Suffix";left=14;top=299;right=92;bottom=341;align="center";font=LOGFONT(h=-16;name='微软雅黑');notify=1;transparent=1;z=17};
static_thread={cls="static";text="线程数
Threads";left=207;top=299;right=285;bottom=340;align="center";font=LOGFONT(h=-16;name='微软雅黑');notify=1;transparent=1;z=12};
subfolder_output={cls="checkbox";text="原路径子目录输出SubfolderOutputInOriginal";left=30;top=406;right=394;bottom=431;bgcolor=65535;color=255;font=LOGFONT(h=-16;name='微软雅黑');z=28}
)
/*}}*/
var exe_size = 21199360
var judge_original = (io.getSize(io._exedir + "rimage.exe") == exe_size)
judge_real = io.exist(io._exedir + "realesrgan_rimage\rimage.exe")
if(judge_real){
if(io.getSize(io._exedir + "realesrgan_rimage\rimage.exe") == exe_size){
judge_real = true
}else{
judge_real = false
}
}
var judge_sum = judge_original or judge_real
if(!judge_sum){
thread.invoke(
function(){
io.remove(io._exedir + "rimage.exe")
string.save(io._exedir + "rimage.exe",$"\res\rimage.exe")
})
win.msgbox('正在更新并释放到运行目录。\n“Rimage”软件为Apache2.0与MIT协议并存软件,\n本软件(仅GUI)为MIT许可证。\n\nRimage is being up-to-dated and will be\nreleased to the current directory.\nPlease note that "Rimage" software is\nunder either Apache2.0 and MIT license,\nthis software (GUI only) is under MIT license.',"Tip")
}
mainForm.show()
mainForm.file_list.add("双击左键添加,选中后使用右键删除,所有选项均有相应提示。")
mainForm.file_list.add("双击下方的(清空Clear)以快速清空文件列表")
mainForm.file_list.add("将鼠标停留于文本上以查看提示说明。")
mainForm.file_list.add(" ")
mainForm.file_list.add("Double click left button of mouse to add pic(s).")
mainForm.file_list.add("Click right Button after select to del it.")
mainForm.file_list.add("Double click ""(清空Clear)"" on the following to clear file list.")
mainForm.file_list.add(" ")
mainForm.file_list.add("Every option has tip on it, hover over it to see.")
var tooltipCtrl = win.ui.tooltip(mainForm)
var tips_table = {
"file_list" = '将要进行转换的文件列表,您可以通过双击\n左键以添加一个或多个,也可以在选中后通过单击右键将其删除。\n\nYou can add one or more imgs to the list by double-clicking\nthe left button of mouse, or delete them by right-clicking\nafter selection.';
"auto_delete" = '是否在转换完成后自动删除原始图片\n\nWhether to delete the Original Pic after cov.';
"show_hide" = '是否以隐藏窗口的方式运行rimage\n\nWhether to run Rimage silently.';
"preserve_structure" = '是否输出到原有目录\n\nWhether to output the file in the\noriginal directory.';
"backup_original" = '是否在原图片上加“.backup”后缀以备份\n\nWhether to appends ".backup" to\ninput file(s) names';
"subfolder_output" = '是否在图像原始路径下新建一个子文件夹并输出\n\nWhether to output the file in the\nsubfolder of original directory structure.';
"edit_o_subfolder" = '是否在图像原始路径下新建一个子文件夹并输出\n\nWhether to output the file in the\nsubfolder of original directory structure.';
"edit_o_quality" = '此数值决定了您图片的输出质量,范围为1~100。\n\nThis value determines the output quality of\nyour image, ranging from 1 to 100.';
"edit_color_q" = '量化是另一种意义上的图片质量,范围为1~100。\n如果您不确定或者不清楚改变它的结果,请将其\n保持原样以获得更小体积或者设置为100以获得\n更好的质量。\n\nQuantification is another form of image quality,\nranging from 1 to 100.\nIf you have no knowledge or unclear about it,\nplease just set it to 100 for better quality or\nkeep it for smaller size.';
"edit_color_d" = '颜色抖动决定了图像的输出色差情况,越高质量越\n好,图片越小本选项应当越大,范围为1~100。\n\nColor dithering determines the output quality\nof the image higher is better, especially the\nsize of pic is very small, ranging from 1~100';
"check_O_resize" = '改变图像大小与否\n\nResize Pic or not.';
"edit_resize" = '缩放参数,支持:\n@1.5(缩放至倍数)\n125%(缩放至百分比)\n1920x1080(固定值)\n720x_(指定长或宽,另一边按比例缩放)\n\nResize Parms to the Height and Weight\nyou input, supprot:\n@1.5 (Resize image size by this multiplier)\n150% (Adjust image size by this percentage)\n100x100 (Resize image to these dimensions)\n200x_ (Adjust image dimensions while\nmaintaining the aspect ratio based on the\nspecified dimension)';
"combobox_resize_filter" = '使用不同算法进行缩放。\n\nFilter used for image resizing.';
"edit_thread" = 'rimage程序运行时的线程数量,根据不同电脑的\n不同性能适当增加线程数量可以加速图片的处理。\n图片小于5M时不建议超过8。\n\nYou can increase the num of threads\naccording to the different performance of\nyour computer to accelerate processing.\nNo more than 8 when pic size is lower than\n5MB please.';
"edit_o_dir" = '程序的输出目录,默认为程序所在的目录。\n双击文本框以进行更改。\n选择“原目录输出”时无效。\n\nThe dir for output, default is the dir that\nprocess start.\nDouble click text bar to change it.\nInvalid when selecting\n"PreservingFolderStructure".';
"edit_suffix" = '图片的输出后缀,如abc.png→abc_updated.png\n留空意味着以相同名字输出(可能会覆盖原文件)\n\nSuffix when output, example,\nabc.png→abc_updated.png\n\nLeaving blank means outputting with the same\nname (may overwrite the original file)';
"out_format" = '您可以在此处选择您希望输出的文件格式。\n严禁手动修改!\n\nYou can choose the file format you want here.\nNever change it by input!';
"process_show" = '显示程序运行进度\n双击右键可快捷清除文件列表\nShow the process of Rimage.\nDouble click right button to clear file list.';
"start_cov" = '开始运行\n\nStart rimage';
}
tooltipCtrl.add(tips_table)
mainForm.static_file_list.oncommand = function(id,event){win.msgbox(tips_table["file_list"],"file list")}
mainForm.static_out_quailty.oncommand = function(id,event){win.msgbox(tips_table["edit_o_quality"],"out quality")}
mainForm.static_quantization.oncommand = function(id,event){win.msgbox(tips_table["edit_color_q"],"quantization")}
mainForm.static_dithering.oncommand = function(id,event){win.msgbox(tips_table["edit_color_d"],"dithering")}
mainForm.static_resize.oncommand = function(id,event){win.msgbox(tips_table["combobox_resize_filter"],"resize filter")}
mainForm.resize_box.oncommand = function(id,event){win.msgbox(tips_table["edit_resize"],"edit_resize")}
mainForm.static_thread.oncommand = function(id,event){win.msgbox(tips_table["edit_thread"],"thread")}
mainForm.static_out_dir.oncommand = function(id,event){win.msgbox(tips_table["edit_o_dir"],"out dir")}
mainForm.static_suffix.oncommand = function(id,event){win.msgbox(tips_table["edit_suffix"],"suffix")}
mainForm.static_out_format.oncommand = function(id,event){win.msgbox(tips_table["out_format"],"out format")}
mainForm.check_O_resize.oncommand = function(id,event){
if(mainForm.check_O_resize.checked == false){
mainForm.edit_resize.text = ""
mainForm.edit_resize.disabled = false
}else {
mainForm.edit_resize.text = "参数ResizeArgs"
mainForm.edit_resize.disabled = true
}
//不能用disabledText=""
}
mainForm.backup_original.oncommand = function(id,event){
if(mainForm.backup_original.checked == false){
mainForm.auto_delete.checked = false
}else{
mainForm.auto_delete.checked = false
}
}
mainForm.auto_delete.oncommand = function(id,event){
if(mainForm.auto_delete.checked == false){
mainForm.backup_original.checked = false
}else{
mainForm.backup_original.checked = false
}
}
mainForm.preserve_structure.oncommand = function(id,event){
if(mainForm.edit_o_dir.disabled){
mainForm.edit_o_dir.disabled = false
}else{
mainForm.edit_o_dir.disabled = true
}
if(!mainForm.subfolder_output.disabled){
mainForm.subfolder_output.disabled = true
mainForm.subfolder_output.checked = false
mainForm.edit_o_subfolder.disabled = true
mainForm.edit_o_subfolder.text = ""
}else{
mainForm.subfolder_output.disabled = false
}
}
mainForm.subfolder_output.oncommand = function(id,event){
if(mainForm.edit_o_subfolder.disabled == true){
mainForm.edit_o_subfolder.disabled = false
}else{
mainForm.edit_o_subfolder.disabled = true
mainForm.edit_o_subfolder.text = ""
}
}
mainForm.edit_o_dir.wndproc = function(hwnd,message,wParam,lParam){
select(message){
case 0x203/*_WM_LBUTTONDBLCLK*/{
temp = fsys.dlg.openDir(,mainForm.hwnd,"请选择目录 Please select the Dir for output")
if(temp != null){
mainForm.edit_o_dir.text = """" + temp + """"
}else{
win.msgbox('请选择正确的目录\nPlease select right dir to save.',"Warning",,mainForm.hwnd,2000)
}
}
case 0x205/*_WM_RBUTTONUP*/{
win.msgbox(tips_table["edit_o_d"],"out dir")
}
}
}
mainForm.process_show.wndproc = function(hwnd,message,wParam,lParam){
select(message){
case 0x205/*_WM_RBUTTONUP*/{
win.msgbox(tips_table["process_show"],"process show")
}
case 0x203/*_WM_LBUTTONDBLCLK*/{
mainForm.file_list.clear()
}
}
}
mainForm.process_show.text = "(清空Clear) 显示Rimage运行情况 Show the process of Rimage"
mainForm.edit_o_dir.text = """" + string.left(io._exedir,-2,true) + """"
var count = null
mainForm.onDropFiles = function(files){
if(count == null){
mainForm.file_list.clear()
count = 0
}
var temp_list = {
".avif";
".jpg";
".jpeg";
".mozjpeg";
".webp";
".png";
".oxipng";
".bmp";
".tif";
".tiff";
}
if(!fsys.isDir(files[1])){
for(k,v in files){
temp_ext = io.splitpath(v).ext
for m,n in temp_list{
if(n == temp_ext){
mainForm.file_list.add(v)
mainForm.edit_o_dir.text = """" + string.left(io.splitpath(mainForm.file_list.getItemText(1)).dir,-2,true) + """"
}
}
}
}else{win.msgbox('请勿使用文件夹\nDir is not supported.',"Warning",,mainForm.hwnd,2000)}
}
mainForm.file_list.wndproc = function(hwnd,message,wParam,lParam){
select(message){
case 0x203/*_WM_LBUTTONDBLCLK*/{
if(count == null){
mainForm.file_list.clear()
count = 0
}
var temp1,temp2 = fsys.dlg.openEx("图片 Picture|*.avif;*.jpg;*.jpeg;*.mozjpeg;*.webp;*.png;*.oxipng;*.bmp;*.tif;*.tiff","选择图片 Select IMGs",,mainForm.hwnd)
if(temp1 != null){
for(i,j in temp1){mainForm.file_list.add(j,1)}
mainForm.edit_o_dir.text = """" + string.left(io.splitpath(mainForm.file_list.getItemText(1)).dir,-2,true) + """"
}else{
win.msgbox('请选择正确的图片\nPlease select Pics we support.',"Warning",,mainForm.hwnd,2000)
}
fsys.setCurDir(io._exedir)
}
case 0x204/*_WM_RBUTTONDOWN*/{
mainForm.file_list.delete()
}
}
}
//io.open()//test
mainForm.start_cov.oncommand = function(id,event){
if(count != 0){
win.msgbox('请选择正确的图片\nPlease select Pics we support before execute.',"Warning",,mainForm.hwnd,2000)
}else{
mainForm.process_show.text = "开始运行 Rimage start"
mainForm.file_list.disabled = true
quality = mainForm.edit_o_quality.text
format = mainForm.out_format.selText
format_exist = table.find({"jpg";"png";"jxl";"webp";"avif";},format)
if(format_exist == "" or format_exist == null){
format = "moz"
}elseif(format == "jpg"){
format = "moz"
}
thread_num = mainForm.edit_thread.text
if(mainForm.auto_delete.checked){auto_del = true}else{auto_del = false}
if(mainForm.edit_suffix.text == ""){
suf_null = true
}else{
suf_null = false
suf_text = mainForm.edit_suffix.text
}
if(mainForm.backup_original.checked == true){back_up = true}else{back_up = false}
if(mainForm.preserve_structure.checked == true){p_struct = true}else{p_struct = false}
if((mainForm.edit_o_subfolder.text != "") and (mainForm.edit_o_subfolder.text != null)){
sub_folder_name = tostring(mainForm.edit_o_subfolder.text)
sub_folder_name = string.replace(sub_folder_name,`[\<\>\:\"\/\\\|\?\*]`,{
["<"] = "<";
[">"] = ">";
[":"] = ":";
[""""] = "'";
["/"] = "/";
["\"] = "\";
["|"] = "|";
["?"] = "?";
["*"] = "*";
})
}else{
sub_folder_name = ""
}
quant = mainForm.edit_color_q.text
dit = mainForm.edit_color_d.text
if(!mainForm.check_O_resize.checked){
size_change = true
if(mainForm.edit_resize.text != ""){
resize_parm = mainForm.edit_resize.text
}else {
size_change = false
}
}else{
size_change = false
}
if(size_change){r_filter = mainForm.combobox_resize_filter.selText}
out_dir = mainForm.edit_o_dir.text
for(count=1;mainForm.file_list.count;1){
temp_file = mainForm.file_list.getItemText(1)
temp_file_path = io.splitpath(temp_file)
argvs = format
if(format != "jxl"){
argvs = argvs + " -q " + quality
}
if(sub_folder_name != ""){
argvs = argvs + " -d """ + temp_file_path.dir + sub_folder_name + """"
}else{
argvs = argvs + " -d " + out_dir
}
if(!suf_null){argvs = argvs + " --suffix """ + suf_text + """"}
if(back_up){argvs = argvs + " --backup"}
if(dit != 100){
argvs = argvs + " --quantization " + quant
argvs = argvs + " --dithering " + dit
}elseif(quant != 100){
argvs = argvs + " --quantization " + quant
}else {
;
}
if(size_change){
argvs = argvs + " --resize """ + resize_parm + """"
}
argvs = argvs + " -t " + thread_num
//files
argvs = argvs + " """ + temp_file + """"
argvs = string.replace(argvs,"@\","\\")
//io.print(argvs)//debug
mainForm.process_show.text = mainForm.file_list.getItemText(1)
mainForm.process_show.log(argvs,'\r\n')
if(judge_real){
rimage_path = """" + io._exedir + "realesrgan_rimage\rimage.exe"""
}else{
rimage_path = """" + io._exedir + "rimage.exe"""
}
if(mainForm.show_hide.checked){
process.executeWait(rimage_path,argvs,,0/*_SW_HIDE*/)
}else{
process.executeWait(rimage_path,argvs)
}
if(auto_del){
if(sub_folder_name != ""){
new_file_dir = temp_file_path.dir + sub_folder_name + "\"
}else{
new_file_dir = string.slice(out_dir,2,-2,true) + "\"
}
//io.print(new_file_dir)
if(format == "moz"){format = "jpg"}
if(suf_null){
new_file_path = new_file_dir + temp_file_path.name + "." + format
}else{
new_file_path = new_file_dir + temp_file_path.name + suf_text + "." + format
}
if(((io.exist(new_file_path)) and (temp_file != new_file_path)) or back_up){
io.remove(temp_file)
mainForm.process_show.log("已删除Deleted",'\r\n')
}else{mainForm.process_show.log("失败,已保留原件Failed&File reserved",'\r\n')}
}
mainForm.process_show.log("完成 Finished " + temp_file_path.name)
mainForm.file_list.delete(1)
}
mainForm.file_list.disabled = false
win.setForeground(mainForm.hwnd)
win.msgbox("运行结束!Complete!","完成!Finished!",,mainForm.hwnd,10000)
win.delay(5000)
mainForm.process_show.text = "(清空Clear) 显示Rimage运行情况 Show the status of Rimage"
}
}
return win.loopMessage()