Skip to content

Commit

Permalink
add new feature
Browse files Browse the repository at this point in the history
  • Loading branch information
Mikachu2333 authored Oct 28, 2023
1 parent f618fc1 commit fee7718
Showing 1 changed file with 48 additions and 44 deletions.
92 changes: 48 additions & 44 deletions main.aardio
Original file line number Diff line number Diff line change
@@ -1,24 +1,27 @@
import fsys.dlg
import gdip
import process
import process.popen
import sevenZip.decoder2
import win.ui
/*DSG{{*/
mainForm = win.form(cls="RIMG_GUI_FORM";text="RealesrganRimagePicImprove";right=587;bottom=394;border="thin";max=false)
mainForm = win.form(cls="RIMG_GUI_FORM";text="RealesrganRimagePicImprove";right=587;bottom=412;border="thin";max=false)
mainForm.add(
auto_delete={cls="checkbox";text="删除原件";left=486;top=123;right=580;bottom=148;bgcolor=65535;color=255;font=LOGFONT(h=-16;name='微软雅黑');z=10};
auto_improve={cls="checkbox";text="自动缩小";left=486;top=39;right=580;bottom=64;bgcolor=65535;checked=1;color=255;font=LOGFONT(h=-16;name='微软雅黑');z=13};
edit_o_d={cls="edit";left=158;top=362;right=477;bottom=387;autovscroll=false;edge=1;font=LOGFONT(h=-14;name='微软雅黑');readonly=1;z=9};
edit_o_q={cls="edit";text="95";left=509;top=229;right=555;bottom=254;align="center";edge=1;font=LOGFONT(h=-16;name='微软雅黑');multiline=1;num=1;z=6};
file_list={cls="listbox";left=8;top=35;right=477;bottom=327;edge=1;font=LOGFONT(h=-14;name='微软雅黑');hscroll=1;items={};vscroll=1;z=2};
out_format={cls="combobox";left=495;top=293;right=570;bottom=319;edge=1;font=LOGFONT(h=-16;name='微软雅黑');items={"jpg";"png";"webp";"avif"};mode="dropdown";z=8};
process_show={cls="edit";left=9;top=334;right=477;bottom=356;autovscroll=false;edge=1;font=LOGFONT(h=-14;name='微软雅黑');readonly=1;z=12};
show_hide={cls="checkbox";text="隐藏执行";left=486;top=80;right=580;bottom=105;bgcolor=65535;checked=1;color=255;font=LOGFONT(h=-16;name='微软雅黑');z=11};
start_cov={cls="button";text="开始";left=482;top=334;right=580;bottom=387;border=1;default=1;font=LOGFONT(h=-17;name='微软雅黑');z=4};
static_file_list={cls="static";text="文件列表 File list";left=3;top=7;right=137;bottom=32;align="center";center=1;font=LOGFONT(h=-16;name='微软雅黑');notify=1;transparent=1;z=3};
static_out_dir={cls="static";text="输出目录 Out-Dir:";left=10;top=362;right=158;bottom=387;align="center";center=1;font=LOGFONT(h=-16;name='微软雅黑');notify=1;transparent=1;z=1};
static_out_format={cls="static";text="输出格式";left=495;top=265;right=570;bottom=290;align="center";center=1;font=LOGFONT(h=-16;name='微软雅黑');notify=1;transparent=1;z=7};
static_out_quailty={cls="static";text="输出质量";left=495;top=201;right=570;bottom=226;align="center";center=1;font=LOGFONT(h=-16;name='微软雅黑');notify=1;transparent=1;z=5}
auto_del={cls="checkbox";text="删除原图";left=486;top=119;right=580;bottom=144;bgcolor=65535;color=255;font=LOGFONT(h=-16;name='微软雅黑');z=10};
auto_improve={cls="checkbox";text="自动缩小";left=486;top=39;right=580;bottom=64;bgcolor=65535;checked=1;color=255;font=LOGFONT(h=-16;name='微软雅黑');z=12};
edit_o_d={cls="edit";left=158;top=381;right=477;bottom=406;autovscroll=false;clip=1;edge=1;font=LOGFONT(h=-14;name='微软雅黑');readonly=1;z=15};
edit_o_q={cls="edit";text="95";left=508;top=184;right=554;bottom=209;align="center";edge=1;font=LOGFONT(h=-16;name='微软雅黑');multiline=1;num=1;z=7};
file_list={cls="listbox";left=8;top=35;right=479;bottom=329;edge=1;font=LOGFONT(h=-14;name='微软雅黑');hscroll=1;items={};vscroll=1;z=3};
out_format={cls="combobox";left=495;top=301;right=570;bottom=327;edge=1;font=LOGFONT(h=-16;name='微软雅黑');items={"jpg";"png";"webp";"avif"};mode="dropdown";z=9};
process_show={cls="edit";left=8;top=327;right=477;bottom=378;clip=1;clipch=1;edge=1;font=LOGFONT(h=-14;name='微软雅黑');multiline=1;readonly=1;z=1};
show_hide={cls="checkbox";text="隐藏执行";left=486;top=78;right=580;bottom=103;bgcolor=65535;checked=1;color=255;font=LOGFONT(h=-16;name='微软雅黑');z=11};
size_to={cls="combobox";left=508;top=243;right=554;bottom=269;edge=1;font=LOGFONT(h=-16;name='微软雅黑');items={"2";"1";"4"};mode="dropdown";z=14};
start_cov={cls="button";text="开始";left=482;top=344;right=580;bottom=397;border=1;default=1;font=LOGFONT(h=-17;name='微软雅黑');z=5};
static={cls="static";text="放大倍数";left=494;top=215;right=569;bottom=240;align="center";center=1;font=LOGFONT(h=-16;name='微软雅黑');notify=1;transparent=1;z=13};
static_file_list={cls="static";text="文件列表 File list";left=3;top=7;right=137;bottom=32;align="center";center=1;font=LOGFONT(h=-16;name='微软雅黑');notify=1;transparent=1;z=4};
static_out_dir={cls="static";text="输出目录 Out-Dir:";left=10;top=381;right=158;bottom=406;align="center";center=1;font=LOGFONT(h=-16;name='微软雅黑');notify=1;transparent=1;z=2};
static_out_format={cls="static";text="输出格式";left=495;top=273;right=570;bottom=298;align="center";center=1;font=LOGFONT(h=-16;name='微软雅黑');notify=1;transparent=1;z=8};
static_out_quailty={cls="static";text="输出质量";left=494;top=156;right=569;bottom=181;align="center";center=1;font=LOGFONT(h=-16;name='微软雅黑');notify=1;transparent=1;z=6}
)
/*}}*/

Expand Down Expand Up @@ -56,23 +59,9 @@ mainForm.edit_o_d.wndproc = function(hwnd,message,wParam,lParam){
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.onDropFiles = function(files){
if(count == null){
mainForm.file_list.clear()
count = 0
}
for(k,v in files){mainForm.file_list.add(v)}
mainForm.edit_o_d.text = """" + string.left(io.splitpath(mainForm.file_list.getItemText(1)).dir,-2,true) + """"
}



mainForm.edit_o_d.text = """" + string.left(io._exedir,-2,true) + """"

var count = null
Expand Down Expand Up @@ -104,7 +93,7 @@ mainForm.file_list.wndproc = function(hwnd,message,wParam,lParam){
mainForm.file_list.clear()
count = 0
}
var temp1,temp2 = fsys.dlg.openEx("图片 Picture|*.png;*.jpg;*.jpeg;*.webp;*.avif;*.oxipng;*.mozjpeg","选择图片 Select IMGs",,mainForm.hwnd)
var temp1,temp2 = fsys.dlg.openEx("图片 Picture|*.png;*.jpg;*.jpeg","选择图片 Select IMGs",,mainForm.hwnd)
if(temp1 != null){
for(i,j in temp1){mainForm.file_list.add(j,1)}
mainForm.edit_o_d.text = """" + string.left(io.splitpath(mainForm.file_list.getItemText(1)).dir,-2,true) + """"
Expand All @@ -118,54 +107,69 @@ mainForm.file_list.wndproc = function(hwnd,message,wParam,lParam){
}
}


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.file_list.disabled = true
pic_re_size = mainForm.size_to.selText
quality = mainForm.edit_o_q.text
format = mainForm.out_format.selText
if(mainForm.auto_delete.checked == true){auto_del = true}else{auto_del = false}
if(mainForm.auto_del.checked == true){del = true}else{del = false}
out_dir = string.slice(mainForm.edit_o_d.text,2,-2,true)
auto_hide = mainForm.show_hide.checked
auto_size = mainForm.auto_improve.checked
auto_del = mainForm.auto_delete.checked
for(count=1;mainForm.file_list.count;1){
temp_file = string.replace(mainForm.file_list.getItemText(1),"@\","\\")
var pic_num = mainForm.file_list.count
var file_list_tab = {}
for(count=1;pic_num;1){
temp_file = mainForm.file_list.getItemText(1)
file_list_tab[count*2-1] = temp_file
temp_file = string.replace(temp_file,"@\","\\")
temp_filename = io.splitpath(temp_file).name
file_list_tab[count*2] = temp_filename
test_gdip = gdip.bitmap(temp_file)
argvs = "-i """ + temp_file + """ -o """ + out_dir + "\" + temp_filename + "_out.png"" -n realesrgan-x4plus-anime"
mainForm.process_show.text = "RealModel开始 " + temp_filename
if(auto_hide){
process.executeWait(io._exedir + "realesrgan_rimage\realesrgan-ncnn-vulkan.exe",argvs,,0/*_SW_HIDE*/)
var prcs, err = process.popen(io._exedir + "realesrgan_rimage\realesrgan-ncnn-vulkan.exe",argvs)
prcs.codepage = 65001
prcs.logResponse(mainForm.process_show)
prcs.waitOne()
}else{
process.executeWait(io._exedir + "realesrgan_rimage\realesrgan-ncnn-vulkan.exe",argvs,,)
}
if(auto_size){
argvs = """" + string.replace((out_dir + "\" + temp_filename + "_out.png"),"@\","\\") + """ -t 4 -q " + quality
argvs = argvs + " --quantization 100 --dithering 100 -s _updated"
argvs = argvs + " -f " + format
argvs = argvs + " --width " + test_gdip.width + " --height " + test_gdip.height
argvs = argvs + " --width " + math.roundToEven((test_gdip.width * pic_re_size),0) + " --height " + math.roundToEven((test_gdip.height * pic_re_size),0)
argvs = argvs + " -o """ + out_dir + """"
test_gdip.dispose()
mainForm.process_show.text = "Rimage开始 " + temp_filename
if(auto_hide){
process.executeWait("""" + io._exedir + "realesrgan_rimage\rimage.exe""",argvs,,0/*_SW_HIDE*/)
}else{
process.executeWait("""" + io._exedir + "realesrgan_rimage\rimage.exe""",argvs,,)
}
io.remove((out_dir + "\" + temp_filename + "_out.png"))
mainForm.process_show.text = "Rimage结束 "+ temp_filename
}

if(auto_del){
new_file_path = string.slice(out_dir,2,-2,true) + "\" + io.splitpath(temp_file).name + suf_text + "." + format
if(io.exist(new_file_path)){
io.remove(mainForm.file_list.getItemText(1))
mainForm.process_show.text = "已删除Deleted"
}else{mainForm.process_show.text = "失败,已保留原件Failed&File reserved"}
}
mainForm.process_show.text = "成功Success " + temp_filename

mainForm.file_list.delete(1)
}


for(m,n in file_list_tab){
if(m%2 == 0){
io.remove((out_dir + "\" + n + "_out.png"))
}else{
if(del){
io.remove(n)
}
}
}
mainForm.file_list.disabled = false
win.setForeground(mainForm.hwnd)
win.msgbox("转换完毕!Complete!","成功Success",,mainForm.hwnd,10000)
mainForm.process_show.text = "(清空Clear) 显示Rimage运行情况 Show the process of Rimage"
Expand Down

0 comments on commit fee7718

Please sign in to comment.