From 38b13ed886f50d861798e8cad3cc056f04173415 Mon Sep 17 00:00:00 2001 From: AaronFeng753 <52553688+AaronFeng753@users.noreply.github.com> Date: Sun, 2 May 2021 06:23:17 +0800 Subject: [PATCH] Rename SRC Folder --- .../FFmpeg_Encoders_List_waifu2xEX.bat | 0 .../NFSound_Waifu2xEX.mp3 | Bin ...y_6b5b848b-c6b5-49fc-98b9-312103aae1dc.dat | 0 .../TitleImage.png | Bin .../Waifu2x-Extension-QT-Launcher.pro | 0 .../Waifu2x-Extension-QT-Launcher.pro.user | 0 .../icon/icon.ico | Bin .../icon/icon_main.png | Bin .../Waifu2x-Extension-QT-Launcher/main.cpp | 0 .../mainwindow.cpp | 0 .../mainwindow.h | 0 .../mainwindow.ui | 0 .../Waifu2x-Extension-QT-Launcher/pic.qrc | 0 .../Waifu2x-Extension-QT/AnimatedPNG.cpp | 0 .../Waifu2x-Extension-QT/Anime4K.cpp | 4350 +-- .../CompatibilityTest.cpp | 0 .../Current_File_Progress.cpp | 254 +- .../Waifu2x-Extension-QT/CustomResolution.cpp | 896 +- .../Waifu2x-Extension-QT/Donate.cpp | 0 .../Waifu2x-Extension-QT/Finish_Action.cpp | 0 .../Frame_Interpolation.cpp | 0 .../Waifu2x-Extension-QT/OtherPic.qrc | 10 +- .../OtherPic/AspectRatioStrategy.jpg | Bin .../Waifu2x-Extension-QT/Right-click_Menu.cpp | 0 ...y_3d7bd0e1-f8ab-4ddc-a52a-15db18477d2f.dat | 0 .../Waifu2x-Extension-QT/SystemTrayIcon.cpp | 0 .../Waifu2x-Extension-QT.pro | 186 +- .../Waifu2x-Extension-QT.pro.user | 692 +- .../Waifu2x-Extension-QT.pro.user.hLgbqF | 0 .../Waifu2x-Extension-QT/Web_Activities.cpp | 0 .../Waifu2x-Extension-QT/backgroundImage.qrc | 10 +- .../Waifu2x-Extension-QT/checkupdate.cpp | 378 +- .../Waifu2x-Extension-QT/donate.qrc | 10 +- .../donate/Donate_QRCode.jpg | Bin .../Waifu2x-Extension-QT/files.cpp | 1258 +- .../Waifu2x-Extension-QT/gif.cpp | 620 +- .../Waifu2x-Extension-QT/icon.qrc | 108 +- .../Waifu2x-Extension-QT/icon/About.png | Bin .../Waifu2x-Extension-QT/icon/AddNewFile.png | Bin .../icon/AddNewFile_disabled.png | Bin .../icon/AddNewFile_hover.png | Bin .../Waifu2x-Extension-QT/icon/AddSetting.png | Bin .../Waifu2x-Extension-QT/icon/Apply.png | Bin .../icon/BackgroudMode.png | Bin .../Waifu2x-Extension-QT/icon/ClearList.png | Bin .../icon/ClearList_disabled.png | Bin .../icon/ClearList_hover.png | Bin .../icon/CompatibilityTest.png | Bin .../icon/EngineSettings.png | Bin .../Waifu2x-Extension-QT/icon/Exit.png | Bin .../Waifu2x-Extension-QT/icon/Home.png | Bin .../Waifu2x-Extension-QT/icon/Minimize.png | Bin .../icon/Pause_SysTray.png | Bin .../icon/Read_FileList.png | Bin .../icon/Read_FileList_disabled.png | Bin .../icon/Read_FileList_hover.png | Bin .../Waifu2x-Extension-QT/icon/RemoveFile.png | Bin .../Waifu2x-Extension-QT/icon/RemoveItem.png | Bin .../icon/RemoveItem_disabled.png | Bin .../icon/RemoveItem_hover.png | Bin .../icon/ResizeFilesListSplitter.png | Bin .../icon/ResizeFilesListSplitter_disabled.png | Bin .../icon/ResizeFilesListSplitter_hover.png | Bin .../icon/Save_FileList.png | Bin .../icon/Save_FileList_disabled.png | Bin .../icon/Save_FileList_hover.png | Bin .../icon/SendFeedback.png | Bin .../Waifu2x-Extension-QT/icon/ShowWindow.png | Bin .../icon/Start_SysTray.png | Bin .../icon/TurnOffScreen.png | Bin .../icon/TurnOffScreen_disabled.png | Bin .../icon/TurnOffScreen_hover.png | Bin .../icon/VideoSettings.png | Bin .../Waifu2x-Extension-QT/icon/cancel.png | Bin .../icon/donateTabIcon.png | Bin .../icon/donateTabIcon_1.png | Bin .../Waifu2x-Extension-QT/icon/gif_Rmenu.png | Bin .../Waifu2x-Extension-QT/icon/icon.ico | Bin .../Waifu2x-Extension-QT/icon/icon_main.png | Bin .../Waifu2x-Extension-QT/icon/opne_folder.png | Bin .../Waifu2x-Extension-QT/icon/patreon.png | Bin .../icon/patreon_sysTray.png | Bin .../icon/pause-button.png | Bin .../Waifu2x-Extension-QT/icon/paypal.png | Bin .../icon/picture_Rmenu.png | Bin .../Waifu2x-Extension-QT/icon/refresh.png | Bin .../Waifu2x-Extension-QT/icon/video_Rmenu.png | Bin .../Waifu2x-Extension-QT/icon/view_file.png | Bin .../Waifu2x-Extension-QT/image.cpp | 0 .../Waifu2x-Extension-QT/language_Chinese.qm | Bin .../Waifu2x-Extension-QT/language_Chinese.ts | 0 .../Waifu2x-Extension-QT/language_English.qm | Bin .../Waifu2x-Extension-QT/language_English.ts | 0 .../language_TraditionalChinese.qm | Bin .../language_TraditionalChinese.ts | 0 .../Waifu2x-Extension-QT/main.cpp | 170 +- .../Waifu2x-Extension-QT/mainwindow.cpp | 4224 +-- .../Waifu2x-Extension-QT/mainwindow.h | 2186 +- .../Waifu2x-Extension-QT/mainwindow.ui | 22454 ++++++++-------- .../Waifu2x-Extension-QT/progressBar.cpp | 118 +- .../realsr_ncnn_vulkan.cpp | 4362 +-- .../Waifu2x-Extension-QT/settings.cpp | 1306 +- .../Waifu2x-Extension-QT/srmd-cuda.cpp | 0 .../Waifu2x-Extension-QT/srmd_ncnn_vulkan.cpp | 4544 ++-- .../Waifu2x-Extension-QT/table.cpp | 1766 +- .../Waifu2x-Extension-QT/textBrowser.cpp | 108 +- .../topsupporterslist.cpp | 0 .../Waifu2x-Extension-QT/topsupporterslist.h | 0 .../Waifu2x-Extension-QT/topsupporterslist.ui | 0 .../Waifu2x-Extension-QT/video.cpp | 2730 +- .../Waifu2x-Extension-QT/waifu2x.cpp | 2702 +- .../Waifu2x-Extension-QT/waifu2x_caffe.cpp | 4308 +-- .../waifu2x_converter.cpp | 4280 +-- .../waifu2x_ncnn_vulkan.cpp | 4458 +-- 114 files changed, 34244 insertions(+), 34244 deletions(-) rename {SRC => SRC_v3.41.01-beta}/FFmpeg_Encoders_List_waifu2xEX.bat (100%) rename {SRC => SRC_v3.41.01-beta}/NFSound_Waifu2xEX.mp3 (100%) rename {SRC => SRC_v3.41.01-beta}/Waifu2x-Extension-QT-Launcher/SyncToy_6b5b848b-c6b5-49fc-98b9-312103aae1dc.dat (100%) rename {SRC => SRC_v3.41.01-beta}/Waifu2x-Extension-QT-Launcher/TitleImage.png (100%) rename {SRC => SRC_v3.41.01-beta}/Waifu2x-Extension-QT-Launcher/Waifu2x-Extension-QT-Launcher.pro (100%) rename {SRC => SRC_v3.41.01-beta}/Waifu2x-Extension-QT-Launcher/Waifu2x-Extension-QT-Launcher.pro.user (100%) rename {SRC => SRC_v3.41.01-beta}/Waifu2x-Extension-QT-Launcher/icon/icon.ico (100%) rename {SRC => SRC_v3.41.01-beta}/Waifu2x-Extension-QT-Launcher/icon/icon_main.png (100%) rename {SRC => SRC_v3.41.01-beta}/Waifu2x-Extension-QT-Launcher/main.cpp (100%) rename {SRC => SRC_v3.41.01-beta}/Waifu2x-Extension-QT-Launcher/mainwindow.cpp (100%) rename {SRC => SRC_v3.41.01-beta}/Waifu2x-Extension-QT-Launcher/mainwindow.h (100%) rename {SRC => SRC_v3.41.01-beta}/Waifu2x-Extension-QT-Launcher/mainwindow.ui (100%) rename {SRC => SRC_v3.41.01-beta}/Waifu2x-Extension-QT-Launcher/pic.qrc (100%) rename {SRC => SRC_v3.41.01-beta}/Waifu2x-Extension-QT/AnimatedPNG.cpp (100%) rename {SRC => SRC_v3.41.01-beta}/Waifu2x-Extension-QT/Anime4K.cpp (97%) rename {SRC => SRC_v3.41.01-beta}/Waifu2x-Extension-QT/CompatibilityTest.cpp (100%) rename {SRC => SRC_v3.41.01-beta}/Waifu2x-Extension-QT/Current_File_Progress.cpp (97%) rename {SRC => SRC_v3.41.01-beta}/Waifu2x-Extension-QT/CustomResolution.cpp (97%) rename {SRC => SRC_v3.41.01-beta}/Waifu2x-Extension-QT/Donate.cpp (100%) rename {SRC => SRC_v3.41.01-beta}/Waifu2x-Extension-QT/Finish_Action.cpp (100%) rename {SRC => SRC_v3.41.01-beta}/Waifu2x-Extension-QT/Frame_Interpolation.cpp (100%) rename {SRC => SRC_v3.41.01-beta}/Waifu2x-Extension-QT/OtherPic.qrc (96%) rename {SRC => SRC_v3.41.01-beta}/Waifu2x-Extension-QT/OtherPic/AspectRatioStrategy.jpg (100%) rename {SRC => SRC_v3.41.01-beta}/Waifu2x-Extension-QT/Right-click_Menu.cpp (100%) rename {SRC => SRC_v3.41.01-beta}/Waifu2x-Extension-QT/SyncToy_3d7bd0e1-f8ab-4ddc-a52a-15db18477d2f.dat (100%) rename {SRC => SRC_v3.41.01-beta}/Waifu2x-Extension-QT/SystemTrayIcon.cpp (100%) rename {SRC => SRC_v3.41.01-beta}/Waifu2x-Extension-QT/Waifu2x-Extension-QT.pro (96%) rename {SRC => SRC_v3.41.01-beta}/Waifu2x-Extension-QT/Waifu2x-Extension-QT.pro.user (98%) rename {SRC => SRC_v3.41.01-beta}/Waifu2x-Extension-QT/Waifu2x-Extension-QT.pro.user.hLgbqF (100%) rename {SRC => SRC_v3.41.01-beta}/Waifu2x-Extension-QT/Web_Activities.cpp (100%) rename {SRC => SRC_v3.41.01-beta}/Waifu2x-Extension-QT/backgroundImage.qrc (95%) rename {SRC => SRC_v3.41.01-beta}/Waifu2x-Extension-QT/checkupdate.cpp (97%) rename {SRC => SRC_v3.41.01-beta}/Waifu2x-Extension-QT/donate.qrc (95%) rename {SRC => SRC_v3.41.01-beta}/Waifu2x-Extension-QT/donate/Donate_QRCode.jpg (100%) rename {SRC => SRC_v3.41.01-beta}/Waifu2x-Extension-QT/files.cpp (96%) rename {SRC => SRC_v3.41.01-beta}/Waifu2x-Extension-QT/gif.cpp (97%) rename {SRC => SRC_v3.41.01-beta}/Waifu2x-Extension-QT/icon.qrc (97%) rename {SRC => SRC_v3.41.01-beta}/Waifu2x-Extension-QT/icon/About.png (100%) rename {SRC => SRC_v3.41.01-beta}/Waifu2x-Extension-QT/icon/AddNewFile.png (100%) rename {SRC => SRC_v3.41.01-beta}/Waifu2x-Extension-QT/icon/AddNewFile_disabled.png (100%) rename {SRC => SRC_v3.41.01-beta}/Waifu2x-Extension-QT/icon/AddNewFile_hover.png (100%) rename {SRC => SRC_v3.41.01-beta}/Waifu2x-Extension-QT/icon/AddSetting.png (100%) rename {SRC => SRC_v3.41.01-beta}/Waifu2x-Extension-QT/icon/Apply.png (100%) rename {SRC => SRC_v3.41.01-beta}/Waifu2x-Extension-QT/icon/BackgroudMode.png (100%) rename {SRC => SRC_v3.41.01-beta}/Waifu2x-Extension-QT/icon/ClearList.png (100%) rename {SRC => SRC_v3.41.01-beta}/Waifu2x-Extension-QT/icon/ClearList_disabled.png (100%) rename {SRC => SRC_v3.41.01-beta}/Waifu2x-Extension-QT/icon/ClearList_hover.png (100%) rename {SRC => SRC_v3.41.01-beta}/Waifu2x-Extension-QT/icon/CompatibilityTest.png (100%) rename {SRC => SRC_v3.41.01-beta}/Waifu2x-Extension-QT/icon/EngineSettings.png (100%) rename {SRC => SRC_v3.41.01-beta}/Waifu2x-Extension-QT/icon/Exit.png (100%) rename {SRC => SRC_v3.41.01-beta}/Waifu2x-Extension-QT/icon/Home.png (100%) rename {SRC => SRC_v3.41.01-beta}/Waifu2x-Extension-QT/icon/Minimize.png (100%) rename {SRC => SRC_v3.41.01-beta}/Waifu2x-Extension-QT/icon/Pause_SysTray.png (100%) rename {SRC => SRC_v3.41.01-beta}/Waifu2x-Extension-QT/icon/Read_FileList.png (100%) rename {SRC => SRC_v3.41.01-beta}/Waifu2x-Extension-QT/icon/Read_FileList_disabled.png (100%) rename {SRC => SRC_v3.41.01-beta}/Waifu2x-Extension-QT/icon/Read_FileList_hover.png (100%) rename {SRC => SRC_v3.41.01-beta}/Waifu2x-Extension-QT/icon/RemoveFile.png (100%) rename {SRC => SRC_v3.41.01-beta}/Waifu2x-Extension-QT/icon/RemoveItem.png (100%) rename {SRC => SRC_v3.41.01-beta}/Waifu2x-Extension-QT/icon/RemoveItem_disabled.png (100%) rename {SRC => SRC_v3.41.01-beta}/Waifu2x-Extension-QT/icon/RemoveItem_hover.png (100%) rename {SRC => SRC_v3.41.01-beta}/Waifu2x-Extension-QT/icon/ResizeFilesListSplitter.png (100%) rename {SRC => SRC_v3.41.01-beta}/Waifu2x-Extension-QT/icon/ResizeFilesListSplitter_disabled.png (100%) rename {SRC => SRC_v3.41.01-beta}/Waifu2x-Extension-QT/icon/ResizeFilesListSplitter_hover.png (100%) rename {SRC => SRC_v3.41.01-beta}/Waifu2x-Extension-QT/icon/Save_FileList.png (100%) rename {SRC => SRC_v3.41.01-beta}/Waifu2x-Extension-QT/icon/Save_FileList_disabled.png (100%) rename {SRC => SRC_v3.41.01-beta}/Waifu2x-Extension-QT/icon/Save_FileList_hover.png (100%) rename {SRC => SRC_v3.41.01-beta}/Waifu2x-Extension-QT/icon/SendFeedback.png (100%) rename {SRC => SRC_v3.41.01-beta}/Waifu2x-Extension-QT/icon/ShowWindow.png (100%) rename {SRC => SRC_v3.41.01-beta}/Waifu2x-Extension-QT/icon/Start_SysTray.png (100%) rename {SRC => SRC_v3.41.01-beta}/Waifu2x-Extension-QT/icon/TurnOffScreen.png (100%) rename {SRC => SRC_v3.41.01-beta}/Waifu2x-Extension-QT/icon/TurnOffScreen_disabled.png (100%) rename {SRC => SRC_v3.41.01-beta}/Waifu2x-Extension-QT/icon/TurnOffScreen_hover.png (100%) rename {SRC => SRC_v3.41.01-beta}/Waifu2x-Extension-QT/icon/VideoSettings.png (100%) rename {SRC => SRC_v3.41.01-beta}/Waifu2x-Extension-QT/icon/cancel.png (100%) rename {SRC => SRC_v3.41.01-beta}/Waifu2x-Extension-QT/icon/donateTabIcon.png (100%) rename {SRC => SRC_v3.41.01-beta}/Waifu2x-Extension-QT/icon/donateTabIcon_1.png (100%) rename {SRC => SRC_v3.41.01-beta}/Waifu2x-Extension-QT/icon/gif_Rmenu.png (100%) rename {SRC => SRC_v3.41.01-beta}/Waifu2x-Extension-QT/icon/icon.ico (100%) rename {SRC => SRC_v3.41.01-beta}/Waifu2x-Extension-QT/icon/icon_main.png (100%) rename {SRC => SRC_v3.41.01-beta}/Waifu2x-Extension-QT/icon/opne_folder.png (100%) rename {SRC => SRC_v3.41.01-beta}/Waifu2x-Extension-QT/icon/patreon.png (100%) rename {SRC => SRC_v3.41.01-beta}/Waifu2x-Extension-QT/icon/patreon_sysTray.png (100%) rename {SRC => SRC_v3.41.01-beta}/Waifu2x-Extension-QT/icon/pause-button.png (100%) rename {SRC => SRC_v3.41.01-beta}/Waifu2x-Extension-QT/icon/paypal.png (100%) rename {SRC => SRC_v3.41.01-beta}/Waifu2x-Extension-QT/icon/picture_Rmenu.png (100%) rename {SRC => SRC_v3.41.01-beta}/Waifu2x-Extension-QT/icon/refresh.png (100%) rename {SRC => SRC_v3.41.01-beta}/Waifu2x-Extension-QT/icon/video_Rmenu.png (100%) rename {SRC => SRC_v3.41.01-beta}/Waifu2x-Extension-QT/icon/view_file.png (100%) rename {SRC => SRC_v3.41.01-beta}/Waifu2x-Extension-QT/image.cpp (100%) rename {SRC => SRC_v3.41.01-beta}/Waifu2x-Extension-QT/language_Chinese.qm (100%) rename {SRC => SRC_v3.41.01-beta}/Waifu2x-Extension-QT/language_Chinese.ts (100%) rename {SRC => SRC_v3.41.01-beta}/Waifu2x-Extension-QT/language_English.qm (100%) rename {SRC => SRC_v3.41.01-beta}/Waifu2x-Extension-QT/language_English.ts (100%) rename {SRC => SRC_v3.41.01-beta}/Waifu2x-Extension-QT/language_TraditionalChinese.qm (100%) rename {SRC => SRC_v3.41.01-beta}/Waifu2x-Extension-QT/language_TraditionalChinese.ts (100%) rename {SRC => SRC_v3.41.01-beta}/Waifu2x-Extension-QT/main.cpp (97%) rename {SRC => SRC_v3.41.01-beta}/Waifu2x-Extension-QT/mainwindow.cpp (97%) rename {SRC => SRC_v3.41.01-beta}/Waifu2x-Extension-QT/mainwindow.h (97%) rename {SRC => SRC_v3.41.01-beta}/Waifu2x-Extension-QT/mainwindow.ui (97%) rename {SRC => SRC_v3.41.01-beta}/Waifu2x-Extension-QT/progressBar.cpp (96%) rename {SRC => SRC_v3.41.01-beta}/Waifu2x-Extension-QT/realsr_ncnn_vulkan.cpp (97%) rename {SRC => SRC_v3.41.01-beta}/Waifu2x-Extension-QT/settings.cpp (98%) rename {SRC => SRC_v3.41.01-beta}/Waifu2x-Extension-QT/srmd-cuda.cpp (100%) rename {SRC => SRC_v3.41.01-beta}/Waifu2x-Extension-QT/srmd_ncnn_vulkan.cpp (97%) rename {SRC => SRC_v3.41.01-beta}/Waifu2x-Extension-QT/table.cpp (97%) rename {SRC => SRC_v3.41.01-beta}/Waifu2x-Extension-QT/textBrowser.cpp (97%) rename {SRC => SRC_v3.41.01-beta}/Waifu2x-Extension-QT/topsupporterslist.cpp (100%) rename {SRC => SRC_v3.41.01-beta}/Waifu2x-Extension-QT/topsupporterslist.h (100%) rename {SRC => SRC_v3.41.01-beta}/Waifu2x-Extension-QT/topsupporterslist.ui (100%) rename {SRC => SRC_v3.41.01-beta}/Waifu2x-Extension-QT/video.cpp (97%) rename {SRC => SRC_v3.41.01-beta}/Waifu2x-Extension-QT/waifu2x.cpp (97%) rename {SRC => SRC_v3.41.01-beta}/Waifu2x-Extension-QT/waifu2x_caffe.cpp (97%) rename {SRC => SRC_v3.41.01-beta}/Waifu2x-Extension-QT/waifu2x_converter.cpp (97%) rename {SRC => SRC_v3.41.01-beta}/Waifu2x-Extension-QT/waifu2x_ncnn_vulkan.cpp (97%) diff --git a/SRC/FFmpeg_Encoders_List_waifu2xEX.bat b/SRC_v3.41.01-beta/FFmpeg_Encoders_List_waifu2xEX.bat similarity index 100% rename from SRC/FFmpeg_Encoders_List_waifu2xEX.bat rename to SRC_v3.41.01-beta/FFmpeg_Encoders_List_waifu2xEX.bat diff --git a/SRC/NFSound_Waifu2xEX.mp3 b/SRC_v3.41.01-beta/NFSound_Waifu2xEX.mp3 similarity index 100% rename from SRC/NFSound_Waifu2xEX.mp3 rename to SRC_v3.41.01-beta/NFSound_Waifu2xEX.mp3 diff --git a/SRC/Waifu2x-Extension-QT-Launcher/SyncToy_6b5b848b-c6b5-49fc-98b9-312103aae1dc.dat b/SRC_v3.41.01-beta/Waifu2x-Extension-QT-Launcher/SyncToy_6b5b848b-c6b5-49fc-98b9-312103aae1dc.dat similarity index 100% rename from SRC/Waifu2x-Extension-QT-Launcher/SyncToy_6b5b848b-c6b5-49fc-98b9-312103aae1dc.dat rename to SRC_v3.41.01-beta/Waifu2x-Extension-QT-Launcher/SyncToy_6b5b848b-c6b5-49fc-98b9-312103aae1dc.dat diff --git a/SRC/Waifu2x-Extension-QT-Launcher/TitleImage.png b/SRC_v3.41.01-beta/Waifu2x-Extension-QT-Launcher/TitleImage.png similarity index 100% rename from SRC/Waifu2x-Extension-QT-Launcher/TitleImage.png rename to SRC_v3.41.01-beta/Waifu2x-Extension-QT-Launcher/TitleImage.png diff --git a/SRC/Waifu2x-Extension-QT-Launcher/Waifu2x-Extension-QT-Launcher.pro b/SRC_v3.41.01-beta/Waifu2x-Extension-QT-Launcher/Waifu2x-Extension-QT-Launcher.pro similarity index 100% rename from SRC/Waifu2x-Extension-QT-Launcher/Waifu2x-Extension-QT-Launcher.pro rename to SRC_v3.41.01-beta/Waifu2x-Extension-QT-Launcher/Waifu2x-Extension-QT-Launcher.pro diff --git a/SRC/Waifu2x-Extension-QT-Launcher/Waifu2x-Extension-QT-Launcher.pro.user b/SRC_v3.41.01-beta/Waifu2x-Extension-QT-Launcher/Waifu2x-Extension-QT-Launcher.pro.user similarity index 100% rename from SRC/Waifu2x-Extension-QT-Launcher/Waifu2x-Extension-QT-Launcher.pro.user rename to SRC_v3.41.01-beta/Waifu2x-Extension-QT-Launcher/Waifu2x-Extension-QT-Launcher.pro.user diff --git a/SRC/Waifu2x-Extension-QT-Launcher/icon/icon.ico b/SRC_v3.41.01-beta/Waifu2x-Extension-QT-Launcher/icon/icon.ico similarity index 100% rename from SRC/Waifu2x-Extension-QT-Launcher/icon/icon.ico rename to SRC_v3.41.01-beta/Waifu2x-Extension-QT-Launcher/icon/icon.ico diff --git a/SRC/Waifu2x-Extension-QT-Launcher/icon/icon_main.png b/SRC_v3.41.01-beta/Waifu2x-Extension-QT-Launcher/icon/icon_main.png similarity index 100% rename from SRC/Waifu2x-Extension-QT-Launcher/icon/icon_main.png rename to SRC_v3.41.01-beta/Waifu2x-Extension-QT-Launcher/icon/icon_main.png diff --git a/SRC/Waifu2x-Extension-QT-Launcher/main.cpp b/SRC_v3.41.01-beta/Waifu2x-Extension-QT-Launcher/main.cpp similarity index 100% rename from SRC/Waifu2x-Extension-QT-Launcher/main.cpp rename to SRC_v3.41.01-beta/Waifu2x-Extension-QT-Launcher/main.cpp diff --git a/SRC/Waifu2x-Extension-QT-Launcher/mainwindow.cpp b/SRC_v3.41.01-beta/Waifu2x-Extension-QT-Launcher/mainwindow.cpp similarity index 100% rename from SRC/Waifu2x-Extension-QT-Launcher/mainwindow.cpp rename to SRC_v3.41.01-beta/Waifu2x-Extension-QT-Launcher/mainwindow.cpp diff --git a/SRC/Waifu2x-Extension-QT-Launcher/mainwindow.h b/SRC_v3.41.01-beta/Waifu2x-Extension-QT-Launcher/mainwindow.h similarity index 100% rename from SRC/Waifu2x-Extension-QT-Launcher/mainwindow.h rename to SRC_v3.41.01-beta/Waifu2x-Extension-QT-Launcher/mainwindow.h diff --git a/SRC/Waifu2x-Extension-QT-Launcher/mainwindow.ui b/SRC_v3.41.01-beta/Waifu2x-Extension-QT-Launcher/mainwindow.ui similarity index 100% rename from SRC/Waifu2x-Extension-QT-Launcher/mainwindow.ui rename to SRC_v3.41.01-beta/Waifu2x-Extension-QT-Launcher/mainwindow.ui diff --git a/SRC/Waifu2x-Extension-QT-Launcher/pic.qrc b/SRC_v3.41.01-beta/Waifu2x-Extension-QT-Launcher/pic.qrc similarity index 100% rename from SRC/Waifu2x-Extension-QT-Launcher/pic.qrc rename to SRC_v3.41.01-beta/Waifu2x-Extension-QT-Launcher/pic.qrc diff --git a/SRC/Waifu2x-Extension-QT/AnimatedPNG.cpp b/SRC_v3.41.01-beta/Waifu2x-Extension-QT/AnimatedPNG.cpp similarity index 100% rename from SRC/Waifu2x-Extension-QT/AnimatedPNG.cpp rename to SRC_v3.41.01-beta/Waifu2x-Extension-QT/AnimatedPNG.cpp diff --git a/SRC/Waifu2x-Extension-QT/Anime4K.cpp b/SRC_v3.41.01-beta/Waifu2x-Extension-QT/Anime4K.cpp similarity index 97% rename from SRC/Waifu2x-Extension-QT/Anime4K.cpp rename to SRC_v3.41.01-beta/Waifu2x-Extension-QT/Anime4K.cpp index 6911635..7cda3cb 100644 --- a/SRC/Waifu2x-Extension-QT/Anime4K.cpp +++ b/SRC_v3.41.01-beta/Waifu2x-Extension-QT/Anime4K.cpp @@ -1,2175 +1,2175 @@ -/* - Copyright (C) 2021 Aaron Feng - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU Affero General Public License as published - by the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Affero General Public License for more details. - - You should have received a copy of the GNU Affero General Public License - along with this program. If not, see . - - My Github homepage: https://github.com/AaronFeng753 -*/ -#include "mainwindow.h" -#include "ui_mainwindow.h" -/* -处理图片 -*/ -int MainWindow::Anime4k_Image(int rowNum,bool ReProcess_MissingAlphaChannel) -{ - //============================= 读取设置 ================================ - int ScaleRatio = 0; - int denoiseLevel = ui->spinBox_DenoiseLevel_image->value();//获取降噪等级 - bool isDenoiseEnabled = (denoiseLevel != -1);//若降噪等级等于-1就是没启用降噪 - bool DelOriginal = (ui->checkBox_DelOriginal->isChecked()||ui->checkBox_ReplaceOriginalFile->isChecked()); - bool PreserveAlphaChannel = Imgae_hasAlphaChannel(rowNum); - QString OutPutPath_Final =""; - //========================= 拆解map得到参数 ============================= - emit Send_Table_image_ChangeStatus_rowNumInt_statusQString(rowNum, "Processing"); - QString SourceFile_fullPath = Table_model_image->item(rowNum,2)->text(); - if(!QFile::exists(SourceFile_fullPath)) - { - emit Send_TextBrowser_NewMessage(tr("Error occured when processing [")+SourceFile_fullPath+tr("]. Error: [File does not exist.]")); - emit Send_Table_image_ChangeStatus_rowNumInt_statusQString(rowNum, "Failed"); - emit Send_progressbar_Add(); - mutex_ThreadNumRunning.lock(); - ThreadNumRunning--; - mutex_ThreadNumRunning.unlock();//线程数量统计-1 - return 0; - } - //========= 转换到 PNG ========= - QString SourceFile_fullPath_Original = SourceFile_fullPath; - SourceFile_fullPath = Imgae_PreProcess(SourceFile_fullPath_Original,ReProcess_MissingAlphaChannel); - //================================ - // 自定义分辨率设定 - //================================ - bool CustRes_isEnabled = false; - int CustRes_height=0; - int CustRes_width=0; - if(CustRes_isContained(SourceFile_fullPath_Original)) - { - CustRes_isEnabled=true; - QMap Res_map = CustRes_getResMap(SourceFile_fullPath_Original);//res_map["fullpath"],["height"],["width"] - ScaleRatio = CustRes_CalNewScaleRatio(SourceFile_fullPath,Res_map["height"].toInt(),Res_map["width"].toInt()); - if(ScaleRatio==0) - { - emit Send_TextBrowser_NewMessage(tr("Error occured when processing [")+SourceFile_fullPath_Original+tr("]. Error: [The resolution of the source file cannot be read, so the image cannot be scaled to a custom resolution.]")); - emit Send_Table_image_ChangeStatus_rowNumInt_statusQString(rowNum, "Failed"); - emit Send_progressbar_Add(); - mutex_ThreadNumRunning.lock(); - ThreadNumRunning--; - mutex_ThreadNumRunning.unlock();//线程数量统计-1 - return 0; - } - CustRes_height=Res_map["height"].toInt(); - CustRes_width=Res_map["width"].toInt(); - } - else - { - double ScaleRatio_double_tmp = ui->doubleSpinBox_ScaleRatio_image->value(); - if(ScaleRatio_double_tmp == (int)ScaleRatio_double_tmp) - { - ScaleRatio = qRound(ScaleRatio_double_tmp); - } - else - { - CustRes_isEnabled=true; - QMap Res_map = DoubleScaleRatio_Cal_NewScaleRatio_NewHW(SourceFile_fullPath,ScaleRatio_double_tmp); - //==== - if(Res_map.isEmpty()) - { - emit Send_TextBrowser_NewMessage(tr("Error occured when processing [")+SourceFile_fullPath+tr("]. Error: [Unable to read the resolution of the source file.]")); - emit Send_Table_image_ChangeStatus_rowNumInt_statusQString(rowNum, "Failed"); - emit Send_progressbar_Add(); - mutex_ThreadNumRunning.lock(); - ThreadNumRunning--; - mutex_ThreadNumRunning.unlock();//线程数量统计-1 - return 0; - } - //==== - ScaleRatio = Res_map["ScaleRatio"].toInt(); - CustRes_height = Res_map["Height_new"].toInt(); - CustRes_width = Res_map["width_new"].toInt(); - } - } - //======================================================= - QFileInfo fileinfo(SourceFile_fullPath); - QString SourceFile_fullPath_FileName = file_getBaseName(SourceFile_fullPath); - QString SourceFile_fullPath_FileExt = fileinfo.suffix(); - QString SourceFile_fullPath_FolderPath = file_getFolderPath(fileinfo); - QString OutPut_Path = SourceFile_fullPath_FolderPath + "/" + SourceFile_fullPath_FileName + "_waifu2x_"+QString::number(ScaleRatio, 10)+"x_"+SourceFile_fullPath_FileExt+".png"; - if(isDenoiseEnabled == true) - { - OutPut_Path = SourceFile_fullPath_FolderPath + "/" + SourceFile_fullPath_FileName + "_waifu2x_"+QString::number(ScaleRatio, 10)+"x_"+QString::number(denoiseLevel, 10)+"n_"+SourceFile_fullPath_FileExt+".png"; - } - else - { - OutPut_Path = SourceFile_fullPath_FolderPath + "/" + SourceFile_fullPath_FileName + "_waifu2x_"+QString::number(ScaleRatio, 10)+"x_"+SourceFile_fullPath_FileExt+".png"; - } - //============================== 放大 ======================================= - QProcess *Waifu2x = new QProcess(); - QString CMD = "\"" + Anime4k_ProgramPath + "\" -i \"" + SourceFile_fullPath + "\" -o \"" + OutPut_Path + "\" -z " + QString::number(ScaleRatio, 10) + HDNDenoiseLevel_image + Anime4k_ReadSettings(PreserveAlphaChannel); - //======== - for(int retry=0; retry<(ui->spinBox_retry->value()+ForceRetryCount); retry++) - { - Waifu2x->start(CMD); - while(!Waifu2x->waitForStarted(100)&&!QProcess_stop) {} - while(!Waifu2x->waitForFinished(500)&&!QProcess_stop) - { - if(waifu2x_STOP) - { - Waifu2x->close(); - QFile::remove(OutPut_Path); - emit Send_Table_image_ChangeStatus_rowNumInt_statusQString(rowNum, "Interrupted"); - mutex_ThreadNumRunning.lock(); - ThreadNumRunning--; - mutex_ThreadNumRunning.unlock(); - return 0; - } - } - DelTrash_ForceRetry_Anime4k(OutPut_Path);//删除强制关闭导致生成的垃圾缓存文件 - if(QFile::exists(OutPut_Path))//判断是否成功输出目标文件 - { - break; - } - else - { - if(retry==ui->spinBox_retry->value()+(ForceRetryCount-1))break; - Delay_sec_sleep(5); - emit Send_TextBrowser_NewMessage(tr("Automatic retry, please wait.")); - } - } - //======== - if(QFile::exists(OutPut_Path)==false) - { - if(SourceFile_fullPath_Original!=SourceFile_fullPath) - { - QFile::remove(SourceFile_fullPath); - } - emit Send_TextBrowser_NewMessage(tr("Error occured when processing [")+SourceFile_fullPath_Original+tr("]. Error: [Unable to scale the picture.]")); - emit Send_Table_image_ChangeStatus_rowNumInt_statusQString(rowNum, "Failed"); - emit Send_progressbar_Add(); - mutex_ThreadNumRunning.lock(); - ThreadNumRunning--; - mutex_ThreadNumRunning.unlock(); - return 0; - } - //============================ 调整大小 ==================================================== - if(CustRes_isEnabled == true) - { - do - { - QImage qimage_adj(OutPut_Path); - //读取放大后的图片并调整大小 - QImage qimage_adj_scaled = qimage_adj.scaled(CustRes_width,CustRes_height,CustRes_AspectRatioMode,Qt::SmoothTransformation); - QImageWriter qimageW_adj; - qimageW_adj.setFormat("png"); - qimageW_adj.setFileName(OutPut_Path); - if(qimageW_adj.canWrite()) - { - qimageW_adj.write(qimage_adj_scaled); - } - if(!QFile::exists(OutPut_Path)) - { - emit Send_TextBrowser_NewMessage(tr("Error occured when processing [")+SourceFile_fullPath+tr("]. Error: [Unable to resize the scaled picture to the target size]")); - emit Send_Table_image_ChangeStatus_rowNumInt_statusQString(rowNum, "Failed"); - emit Send_progressbar_Add(); - mutex_ThreadNumRunning.lock(); - ThreadNumRunning--; - mutex_ThreadNumRunning.unlock();//线程数量统计-1 - return 0; - } - } - while(false); - QString OutPut_Path_CustRes = SourceFile_fullPath_FolderPath + "/" + SourceFile_fullPath_FileName + "_waifu2x_"+QString::number(CustRes_width, 10)+"x"+QString::number(CustRes_height, 10)+"_"+SourceFile_fullPath_FileExt+".png"; - QFile::remove(OutPut_Path_CustRes); - QFile::rename(OutPut_Path,OutPut_Path_CustRes); - //=========================== 另存为JPG&压缩JPG =========================================== - OutPutPath_Final = SaveImageAs_FormatAndQuality(SourceFile_fullPath_Original,OutPut_Path_CustRes,isDenoiseEnabled,denoiseLevel); - } - else - { - //=========================== 另存为JPG&压缩JPG =========================================== - OutPutPath_Final = SaveImageAs_FormatAndQuality(SourceFile_fullPath_Original,OutPut_Path,isDenoiseEnabled,denoiseLevel); - } - //================== 检查是否丢失了透明通道 ===================== - if(ReProcess_MissingAlphaChannel==false) - { - QImage QImage_Final(OutPutPath_Final); - if(PreserveAlphaChannel == true && QImage_Final.hasAlphaChannel() == false && ui->checkBox_AutoDetectAlphaChannel->isChecked()) - { - QFile::remove(OutPutPath_Final); - emit Send_TextBrowser_NewMessage(tr("Since the Alpha channel in the resulting image is lost, this image will be reprocessed to fix it:[")+SourceFile_fullPath_Original+tr("].\nIf the reprocessing happens a lot, you should consider enable [Always pre-process images with Alpha Channel] in [Additional settings].")); - return Anime4k_Image(rowNum,true); - } - } - //============================= 删除原文件 & 更新table status ============================ - if(SourceFile_fullPath_Original!=SourceFile_fullPath) - { - QFile::remove(SourceFile_fullPath); - } - if(DelOriginal == true) - { - if(ReplaceOriginalFile(SourceFile_fullPath_Original,OutPutPath_Final)==false) - { - if(QAction_checkBox_MoveToRecycleBin_checkBox_DelOriginal->isChecked()) - { - file_MoveToTrash(SourceFile_fullPath_Original); - } - else - { - QFile::remove(SourceFile_fullPath_Original); - } - } - emit Send_Table_image_ChangeStatus_rowNumInt_statusQString(rowNum, "Finished, original file deleted"); - } - else - { - emit Send_Table_image_ChangeStatus_rowNumInt_statusQString(rowNum, "Finished"); - } - //========== 移动到输出路径 ========= - if(ui->checkBox_OutPath_isEnabled->isChecked()) - { - MoveFileToOutputPath(OutPutPath_Final,SourceFile_fullPath_Original); - } - //============================ 更新进度条 ================================= - emit Send_progressbar_Add(); - //=========================== 更新线程数量统计============================== - mutex_ThreadNumRunning.lock(); - ThreadNumRunning--; - mutex_ThreadNumRunning.unlock();//线程数量统计-1 - //======= - return 0; -} -/* -处理GIF -*/ -int MainWindow::Anime4k_GIF(int rowNum) -{ - //============================= 读取设置 ================================ - int ScaleRatio = ui->doubleSpinBox_ScaleRatio_gif->value(); - bool DelOriginal = (ui->checkBox_DelOriginal->isChecked()||ui->checkBox_ReplaceOriginalFile->isChecked()); - int Sub_gif_ThreadNumRunning = 0; - QString OutPutPath_Final =""; - //========================= 拆解map得到参数 ============================= - emit Send_Table_gif_ChangeStatus_rowNumInt_statusQString(rowNum, "Processing"); - QString SourceFile_fullPath = Table_model_gif->item(rowNum,2)->text(); - if(!QFile::exists(SourceFile_fullPath)) - { - emit Send_TextBrowser_NewMessage(tr("Error occured when processing [")+SourceFile_fullPath+tr("]. Error: [File does not exist.]")); - emit Send_Table_gif_ChangeStatus_rowNumInt_statusQString(rowNum, "Failed"); - emit Send_progressbar_Add(); - return 0; - } - //========================== - bool CustRes_isEnabled = false; - int CustRes_height=0; - int CustRes_width=0; - if(CustRes_isContained(SourceFile_fullPath)) - { - CustRes_isEnabled=true; - QMap Res_map = CustRes_getResMap(SourceFile_fullPath);//res_map["fullpath"],["height"],["width"] - CustRes_height=Res_map["height"].toInt(); - CustRes_width=Res_map["width"].toInt(); - } - //========================== - QFileInfo fileinfo(SourceFile_fullPath); - QString file_name = file_getBaseName(SourceFile_fullPath); - QString file_ext = fileinfo.suffix(); - QString file_path = file_getFolderPath(fileinfo); - QString ResGIFPath = file_path + "/" + file_name + "_waifu2x_"+QString::number(ScaleRatio, 10)+"x.gif"; - //=========================== 获取帧时间 ==================================== - int GIF_Duration = Gif_getDuration(SourceFile_fullPath); - if(GIF_Duration==0)//检查是否成功获取duration - { - emit Send_TextBrowser_NewMessage(tr("Error occured when processing [")+SourceFile_fullPath+tr("]. Error: [Can't get Duration value of GIF file.]")); - emit Send_Table_gif_ChangeStatus_rowNumInt_statusQString(rowNum, "Failed"); - //file_DelDir(SplitFramesFolderPath); - emit Send_progressbar_Add(); - return 0;//如果启用stop位,则直接return - } - //============================== 拆分 ========================================== - QString SplitFramesFolderPath = file_path+"/"+file_name+"_SplitFrames_W2xEX";//拆分后存储frame的文件夹 - Gif_splitGif(SourceFile_fullPath,SplitFramesFolderPath); - //============================== 扫描获取文件名 =============================== - QStringList Frame_fileName_list = file_getFileNames_in_Folder_nofilter(SplitFramesFolderPath); - if(Frame_fileName_list.isEmpty())//检查是否成功拆分gif - { - emit Send_TextBrowser_NewMessage(tr("Error occured when processing [")+SourceFile_fullPath+tr("]. Error: [Can't split GIF into frames.]")); - emit Send_Table_gif_ChangeStatus_rowNumInt_statusQString(rowNum, "Failed"); - file_DelDir(SplitFramesFolderPath); - emit Send_progressbar_Add(); - return 0;//如果启用stop位,则直接return - } - //===========建立存储放大后frame的文件夹=========== - QString ScaledFramesFolderPath = SplitFramesFolderPath+"/ScaledFrames_W2xEX"; - if(file_isDirExist(ScaledFramesFolderPath)) - { - file_DelDir(ScaledFramesFolderPath); - file_mkDir(ScaledFramesFolderPath); - } - else - { - file_mkDir(ScaledFramesFolderPath); - } - //=============================开始放大========================== - //启动进度条 - emit Send_CurrentFileProgress_Start(file_name+"."+file_ext,Frame_fileName_list.size()); - FileProgressWatch_isEnabled=true; - QFuture FileProgressWatch_QFuture = QtConcurrent::run(this, &MainWindow::CurrentFileProgress_WatchFolderFileNum, ScaledFramesFolderPath);//启动waifu2x 主线程 - if(ui->checkBox_ShowInterPro->isChecked()==false) - { - FileProgressWatch_isEnabled=false; - FileProgressWatch_QFuture.cancel(); - emit Send_CurrentFileProgress_Stop(); - } - //=======获取显卡信息======== - int NumOfGPU = 1; - if(ui->checkBox_SpecifyGPU_Anime4k->isChecked()==true) - { - NumOfGPU = Get_NumOfGPU_Anime4k(); - } - //============创建显卡文件夹=========== - QStringList GPU_SplitFramesFolderPath_List; - for(int i = 0; i < NumOfGPU; i++) - { - QString GPU_SplitFramesFolderPath = SplitFramesFolderPath+"/"+"GPU_"+QString::number(i); - if(file_isDirExist(GPU_SplitFramesFolderPath)) - { - file_DelDir(GPU_SplitFramesFolderPath); - file_mkDir(GPU_SplitFramesFolderPath); - } - else - { - file_mkDir(GPU_SplitFramesFolderPath); - } - GPU_SplitFramesFolderPath_List.append(GPU_SplitFramesFolderPath); - } - int TotalFramesNum = Frame_fileName_list.size(); - int FramesNumForEachGPU = TotalFramesNum/NumOfGPU; - if(FramesNumForEachGPU<1)FramesNumForEachGPU=1; - int start_num=0; - for(int x = 0; x < GPU_SplitFramesFolderPath_List.size(); x++) - { - if(x==GPU_SplitFramesFolderPath_List.size()-1)FramesNumForEachGPU=TotalFramesNum; - QStringList file_waitformove = Frame_fileName_list.mid(start_num,FramesNumForEachGPU); - for(int i = 0; i < file_waitformove.size(); i++) - { - QString FileName = file_waitformove.at(i); - QFile::rename(SplitFramesFolderPath+"/"+FileName,GPU_SplitFramesFolderPath_List.at(x)+"/"+FileName); - } - start_num+=FramesNumForEachGPU; - } - //=== - QMap Sub_Thread_info; - Sub_Thread_info["ScaledFramesFolderPath"]=ScaledFramesFolderPath; - if(CustRes_isEnabled == true) - { - Sub_Thread_info["ScaleRatio"] = QString("%1").arg(CustRes_CalNewScaleRatio(SourceFile_fullPath,CustRes_height,CustRes_width)); - } - else - { - Sub_Thread_info["ScaleRatio"] = QString("%1").arg(qRound(ui->doubleSpinBox_ScaleRatio_gif->value())); - } - //========================= - bool Frame_failed = false;//放大失败标志 - //========================= - for(int i = 0; i < GPU_SplitFramesFolderPath_List.size(); i++) - { - Sub_Thread_info["SplitFramesFolderPath"]=GPU_SplitFramesFolderPath_List.at(i); - mutex_SubThreadNumRunning.lock(); - Sub_gif_ThreadNumRunning++; - mutex_SubThreadNumRunning.unlock(); - QtConcurrent::run(this,&MainWindow::Anime4k_GIF_scale,Sub_Thread_info,&Sub_gif_ThreadNumRunning,&Frame_failed); - while (Sub_gif_ThreadNumRunning >= NumOfGPU) - { - Delay_msec_sleep(500); - } - if(waifu2x_STOP) - { - while (Sub_gif_ThreadNumRunning > 0) - { - Delay_msec_sleep(500); - } - FileProgressWatch_isEnabled=false; - FileProgressWatch_QFuture.cancel(); - file_DelDir(SplitFramesFolderPath); - emit Send_Table_gif_ChangeStatus_rowNumInt_statusQString(rowNum, "Interrupted"); - return 0;//如果启用stop位,则直接return - } - if(Frame_failed) - { - FileProgressWatch_isEnabled=false; - FileProgressWatch_QFuture.cancel(); - emit Send_TextBrowser_NewMessage(tr("Error occured when processing [")+SourceFile_fullPath+tr("]. Error: [Failed to scale frames.]")); - emit Send_Table_gif_ChangeStatus_rowNumInt_statusQString(rowNum, "Failed"); - file_DelDir(SplitFramesFolderPath); - emit Send_progressbar_Add(); - return 0;//如果启用stop位,则直接return - } - } - while (Sub_gif_ThreadNumRunning!=0) - { - Delay_msec_sleep(500); - } - FileProgressWatch_isEnabled=false; - FileProgressWatch_QFuture.cancel(); - emit Send_CurrentFileProgress_Stop(); - //======================= 检查是否成功放大所有帧 =========================== - QStringList Frame_fileName_list_scaled = file_getFileNames_in_Folder_nofilter(ScaledFramesFolderPath); - if(Frame_fileName_list.size()!=Frame_fileName_list_scaled.size()) - { - emit Send_TextBrowser_NewMessage(tr("Error occured when processing [")+SourceFile_fullPath+tr("]. Error: [Failed to scale frames.]")); - emit Send_Table_gif_ChangeStatus_rowNumInt_statusQString(rowNum, "Failed"); - file_DelDir(SplitFramesFolderPath); - emit Send_progressbar_Add(); - return 0;//如果启用stop位,则直接return - } - //======================================== 组装 ====================================================== - if(CustRes_isEnabled) - { - ResGIFPath = file_path + "/" + file_name + "_waifu2x_"+QString::number(CustRes_width, 10)+"x"+QString::number(CustRes_height,10)+".gif"; - } - //======================= - // 修改文件名,添加降噪等级 - //======================= - int denoiseLevel = ui->spinBox_DenoiseLevel_gif->value(); - if(denoiseLevel != -1) - { - QFileInfo fileinfo_tmp(ResGIFPath); - ResGIFPath = file_getFolderPath(fileinfo_tmp) + "/" + file_getBaseName(ResGIFPath) + "_"+QString::number(denoiseLevel, 10)+"n.gif"; - } - //====================== - Gif_assembleGif(ResGIFPath,ScaledFramesFolderPath,GIF_Duration,CustRes_isEnabled,CustRes_height,CustRes_width,false,""); - if(!QFile::exists(ResGIFPath)) - { - emit Send_TextBrowser_NewMessage(tr("Error occured when processing [")+SourceFile_fullPath+tr("]. Error: [Unable to assemble gif.]")); - emit Send_Table_gif_ChangeStatus_rowNumInt_statusQString(rowNum, "Failed"); - file_DelDir(SplitFramesFolderPath); - emit Send_progressbar_Add(); - return 0;//如果启用stop位,则直接return - } - OutPutPath_Final = ResGIFPath; - //======================================= 优化gif =================================================== - if(ui->checkBox_OptGIF->isChecked() == true) - { - QFileInfo fileinfo_tmp(OutPutPath_Final); - QString ResGIFPath_compressed = file_getFolderPath(fileinfo_tmp) + "/" + file_getBaseName(OutPutPath_Final) + "_opt.gif"; - OutPutPath_Final = Gif_compressGif(ResGIFPath,ResGIFPath_compressed); - } - //============================== 删除缓存文件 ==================================================== - file_DelDir(SplitFramesFolderPath); - //============================= 删除原文件 & & 更新table status ============================ - if(DelOriginal) - { - if(ReplaceOriginalFile(SourceFile_fullPath,OutPutPath_Final)==false) - { - if(QAction_checkBox_MoveToRecycleBin_checkBox_DelOriginal->isChecked()) - { - file_MoveToTrash(SourceFile_fullPath); - } - else - { - QFile::remove(SourceFile_fullPath); - } - } - emit Send_Table_gif_ChangeStatus_rowNumInt_statusQString(rowNum, "Finished, original file deleted"); - } - else - { - emit Send_Table_gif_ChangeStatus_rowNumInt_statusQString(rowNum, "Finished"); - } - //========== 移动到输出路径 ========= - if(ui->checkBox_OutPath_isEnabled->isChecked()) - { - MoveFileToOutputPath(OutPutPath_Final,SourceFile_fullPath); - } - //============================ 更新进度条 ================================= - emit Send_progressbar_Add(); - //=========================== ============================== - return 0; -} -/* -Anime4k GIF放大子线程 -放大,修改大小 -*/ -int MainWindow::Anime4k_GIF_scale(QMap Sub_Thread_info,int *Sub_gif_ThreadNumRunning,bool *Frame_failed) -{ - bool AllFinished=true; - QString SplitFramesFolderPath = Sub_Thread_info["SplitFramesFolderPath"]; - QString ScaledFramesFolderPath = Sub_Thread_info["ScaledFramesFolderPath"]; - //================== - // 生成输出文件列表 - //================== - QStringList OutPutFilesFullPathList; - do - { - QStringList InputFilesNameList = file_getFileNames_in_Folder_nofilter(SplitFramesFolderPath); - for(int i=0; ispinBox_retry->value()+ForceRetryCount); retry++) - { - Anime4k->start(CMD); - while(!Anime4k->waitForStarted(100)&&!QProcess_stop) {} - while(!Anime4k->waitForFinished(500)&&!QProcess_stop) - { - if(waifu2x_STOP) - { - Anime4k->close(); - mutex_SubThreadNumRunning.lock(); - *Sub_gif_ThreadNumRunning=*Sub_gif_ThreadNumRunning-1; - mutex_SubThreadNumRunning.unlock(); - return 0; - } - } - AllFinished = true; - for(int i=0; ispinBox_retry->value()+(ForceRetryCount-1))break; - Delay_sec_sleep(5); - emit Send_TextBrowser_NewMessage(tr("Automatic retry, please wait.")); - AllFinished=false; - break; - } - } - if(AllFinished == true)break; - } - //========= - AllFinished = true; - for(int i=0; idoubleSpinBox_ScaleRatio_video->value(); - bool DelOriginal = (ui->checkBox_DelOriginal->isChecked()||ui->checkBox_ReplaceOriginalFile->isChecked()); - bool isCacheExists = false; - bool isVideoConfigChanged = true; - int Sub_video_ThreadNumRunning = 0; - //========================= 拆解map得到参数 ============================= - emit Send_Table_video_ChangeStatus_rowNumInt_statusQString(rowNum, "Processing"); - QString SourceFile_fullPath = Table_model_video->item(rowNum,2)->text(); - if(!QFile::exists(SourceFile_fullPath)) - { - emit Send_TextBrowser_NewMessage(tr("Error occured when processing [")+SourceFile_fullPath+tr("]. Error: [File does not exist.]")); - emit Send_Table_video_ChangeStatus_rowNumInt_statusQString(rowNum, "Failed"); - emit Send_progressbar_Add(); - return 0; - } - //========================== - QFileInfo fileinfo(SourceFile_fullPath); - QString file_name = file_getBaseName(SourceFile_fullPath); - QString file_ext = fileinfo.suffix(); - QString file_path = file_getFolderPath(fileinfo); - //=================================================================== - //生成mp4 - QString video_mp4_fullpath=video_To_CFRMp4(SourceFile_fullPath); - if(!QFile::exists(video_mp4_fullpath))//检查是否成功生成mp4 - { - emit Send_TextBrowser_NewMessage(tr("Error occured when processing [")+SourceFile_fullPath+tr("]. Error: [Cannot convert video format to mp4.]")); - emit Send_Table_video_ChangeStatus_rowNumInt_statusQString(rowNum, "Failed"); - emit Send_progressbar_Add(); - return 0;//如果启用stop位,则直接return - } - QString AudioPath = file_path+"/Audio_"+file_name+"_"+file_ext+"_W2xEX.wav";//音频 - QString SplitFramesFolderPath = file_path+"/"+file_name+"_"+file_ext+"_SplitFrames_W2xEX";//拆分后存储frame的文件夹 - QString ScaledFramesFolderPath = SplitFramesFolderPath+"/ScaledFrames_W2xEX";//存储放大后的帧 - //========================== - // 读取自定义分辨率设定 - //========================== - bool CustRes_isEnabled = false; - int CustRes_height=0; - int CustRes_width=0; - if(CustRes_isContained(SourceFile_fullPath)) - { - CustRes_isEnabled=true; - QMap Res_map = CustRes_getResMap(SourceFile_fullPath);//res_map["fullpath"],["height"],["width"] - CustRes_height=Res_map["height"].toInt(); - CustRes_width=Res_map["width"].toInt(); - } - //========================== - // 检测之前的视频配置文件 - //========================== - QString VideoConfiguration_fullPath = file_path+"/VideoConfiguration_"+file_name+"_"+file_ext+"_Waifu2xEX.ini"; - if(QFile::exists(VideoConfiguration_fullPath)) - { - QSettings *configIniRead = new QSettings(VideoConfiguration_fullPath, QSettings::IniFormat); - configIniRead->setIniCodec(QTextCodec::codecForName("UTF-8")); - //=================== 加载之前存储的视频信息 ========================= - int ScaleRatio_old = configIniRead->value("/VideoConfiguration/ScaleRatio").toInt(); - bool CustRes_isEnabled_old = configIniRead->value("/VideoConfiguration/CustRes_isEnabled").toBool(); - int CustRes_height_old = configIniRead->value("/VideoConfiguration/CustRes_height").toInt(); - int CustRes_width_old = configIniRead->value("/VideoConfiguration/CustRes_width").toInt(); - QString EngineName_old = configIniRead->value("/VideoConfiguration/EngineName").toString(); - bool isProcessBySegment_old = configIniRead->value("/VideoConfiguration/isProcessBySegment").toBool(); - //=================== 比对信息 ================================ - if(EngineName_old=="anime4k") - { - if(CustRes_isEnabled_old==false&&CustRes_isEnabled==false) - { - if(ScaleRatio_old!=ScaleRatio) - { - isVideoConfigChanged=true; - } - else - { - isVideoConfigChanged=false; - } - } - else - { - if(CustRes_isEnabled_old==true&&CustRes_isEnabled==true) - { - if(CustRes_height_old!=CustRes_height||CustRes_width_old!=CustRes_width) - { - isVideoConfigChanged=true; - } - else - { - isVideoConfigChanged=false; - } - } - else - { - isVideoConfigChanged=true; - } - } - if(isProcessBySegment_old==true) - { - isVideoConfigChanged=true; - } - } - else - { - isVideoConfigChanged=true; - } - } - else - { - emit Send_video_write_VideoConfiguration(VideoConfiguration_fullPath,ScaleRatio,0,CustRes_isEnabled,CustRes_height,CustRes_width,"anime4k",false,"","",ui->groupBox_FrameInterpolation->isChecked(),0); - } - //======================= - // 检测缓存是否存在 - //======================= - if(QFile::exists(video_mp4_fullpath)&&file_isDirExist(SplitFramesFolderPath)&&file_isDirExist(ScaledFramesFolderPath)&&QFile::exists(VideoConfiguration_fullPath)) - { - if(!isVideoConfigChanged) - { - isCacheExists=true; - emit Send_TextBrowser_NewMessage(tr("The previous video cache file is detected and processing of the previous video cache will continue. If you want to restart processing of the current video:[")+SourceFile_fullPath+tr("], delete the cache manually.")); - } - else - { - isCacheExists=false; - //======== - QFile::remove(VideoConfiguration_fullPath); - file_DelDir(SplitFramesFolderPath); - QFile::remove(AudioPath); - DelVfiDir(video_mp4_fullpath); - emit Send_video_write_VideoConfiguration(VideoConfiguration_fullPath,ScaleRatio,0,CustRes_isEnabled,CustRes_height,CustRes_width,"anime4k",false,"","",ui->groupBox_FrameInterpolation->isChecked(),0); - //======= - emit Send_TextBrowser_NewMessage(tr("The previous video cache file was detected, but because you changed the settings about the video resolution, the previous cache will be deleted and processing of the video:[")+SourceFile_fullPath+tr("] will restart.")); - } - } - else - { - isCacheExists=false; - //======== - QFile::remove(VideoConfiguration_fullPath); - file_DelDir(SplitFramesFolderPath); - QFile::remove(AudioPath); - DelVfiDir(video_mp4_fullpath); - emit Send_video_write_VideoConfiguration(VideoConfiguration_fullPath,ScaleRatio,0,CustRes_isEnabled,CustRes_height,CustRes_width,"anime4k",false,"","",ui->groupBox_FrameInterpolation->isChecked(),0); - //======== - } - //========================================== - // 拆分(正常) - //========================================== - if(!isCacheExists) - { - if(file_isDirExist(SplitFramesFolderPath)) - { - file_DelDir(SplitFramesFolderPath); - file_mkDir(SplitFramesFolderPath); - } - else - { - file_mkDir(SplitFramesFolderPath); - } - QFile::remove(AudioPath); - video_video2images(video_mp4_fullpath,SplitFramesFolderPath,AudioPath); - if(waifu2x_STOP) - { - emit Send_Table_video_ChangeStatus_rowNumInt_statusQString(rowNum, "Interrupted"); - return 0;//如果启用stop位,则直接return - } - } - //============================== 扫描获取文件名 =============================== - QStringList Frame_fileName_list = file_getFileNames_in_Folder_nofilter(SplitFramesFolderPath); - if(!isCacheExists) - { - if(Frame_fileName_list.isEmpty())//检查是否成功拆分为帧 - { - emit Send_TextBrowser_NewMessage(tr("Error occured when processing [")+SourceFile_fullPath+tr("]. Error: [Unable to split video into pictures.]")); - emit Send_Table_video_ChangeStatus_rowNumInt_statusQString(rowNum, "Failed"); - emit Send_progressbar_Add(); - return 0;//如果启用stop位,则直接return - } - } - //============================== 放大 ======================================= - //===========建立存储放大后frame的文件夹=========== - if(!isCacheExists) - { - if(file_isDirExist(ScaledFramesFolderPath)) - { - file_DelDir(ScaledFramesFolderPath); - file_mkDir(ScaledFramesFolderPath); - } - else - { - file_mkDir(ScaledFramesFolderPath); - } - } - //==========开始放大========================== - emit Send_CurrentFileProgress_Start(file_name+"."+file_ext,(Frame_fileName_list.size()+file_getFileNames_in_Folder_nofilter(ScaledFramesFolderPath).size())); - FileProgressWatch_isEnabled=true; - QFuture FileProgressWatch_QFuture = QtConcurrent::run(this, &MainWindow::CurrentFileProgress_WatchFolderFileNum, ScaledFramesFolderPath);//启动waifu2x 主线程 - if(ui->checkBox_ShowInterPro->isChecked()==false) - { - FileProgressWatch_isEnabled=false; - FileProgressWatch_QFuture.cancel(); - emit Send_CurrentFileProgress_Stop(); - } - //=======获取显卡信息======== - int NumOfGPU = 1; - if(ui->checkBox_SpecifyGPU_Anime4k->isChecked()==true) - { - NumOfGPU = Get_NumOfGPU_Anime4k(); - } - //============创建显卡文件夹=========== - QStringList GPU_SplitFramesFolderPath_List; - for(int i = 0; i < NumOfGPU; i++) - { - QString GPU_SplitFramesFolderPath = SplitFramesFolderPath+"/"+"GPU_"+QString::number(i); - if(file_isDirExist(GPU_SplitFramesFolderPath)==false) - { - file_DelDir(GPU_SplitFramesFolderPath); - file_mkDir(GPU_SplitFramesFolderPath); - } - else - { - file_mkDir(GPU_SplitFramesFolderPath); - } - GPU_SplitFramesFolderPath_List.append(GPU_SplitFramesFolderPath); - } - int TotalFramesNum = Frame_fileName_list.size(); - int FramesNumForEachGPU = TotalFramesNum/NumOfGPU; - if(FramesNumForEachGPU<1)FramesNumForEachGPU=1; - int start_num=0; - for(int x = 0; x < GPU_SplitFramesFolderPath_List.size(); x++) - { - if(x==GPU_SplitFramesFolderPath_List.size()-1)FramesNumForEachGPU=TotalFramesNum; - QStringList file_waitformove = Frame_fileName_list.mid(start_num,FramesNumForEachGPU); - for(int i = 0; i < file_waitformove.size(); i++) - { - QString FileName = file_waitformove.at(i); - QFile::rename(SplitFramesFolderPath+"/"+FileName,GPU_SplitFramesFolderPath_List.at(x)+"/"+FileName); - } - start_num+=FramesNumForEachGPU; - } - //========================= - bool Frame_failed = false;//放大失败标志 - QMap Sub_Thread_info; - Sub_Thread_info["ScaledFramesFolderPath"]=ScaledFramesFolderPath; - if(CustRes_isEnabled == true) - { - Sub_Thread_info["ScaleRatio"] = QString("%1").arg(CustRes_CalNewScaleRatio(video_mp4_fullpath,CustRes_height,CustRes_width)); - } - else - { - Sub_Thread_info["ScaleRatio"] = QString("%1").arg(ScaleRatio); - } - //========================= - for(int i = 0; i < GPU_SplitFramesFolderPath_List.size(); i++) - { - Sub_Thread_info["SplitFramesFolderPath"]=GPU_SplitFramesFolderPath_List.at(i); - mutex_SubThreadNumRunning.lock(); - Sub_video_ThreadNumRunning++; - mutex_SubThreadNumRunning.unlock(); - QtConcurrent::run(this,&MainWindow::Anime4k_Video_scale,Sub_Thread_info,&Sub_video_ThreadNumRunning,&Frame_failed); - while (Sub_video_ThreadNumRunning >= NumOfGPU) - { - Delay_msec_sleep(500); - } - if(waifu2x_STOP) - { - while (Sub_video_ThreadNumRunning > 0) - { - Delay_msec_sleep(500); - } - FileProgressWatch_isEnabled=false; - FileProgressWatch_QFuture.cancel(); - Restore_SplitFramesFolderPath(SplitFramesFolderPath,GPU_SplitFramesFolderPath_List); - emit Send_Table_video_ChangeStatus_rowNumInt_statusQString(rowNum, "Interrupted"); - return 0;//如果启用stop位,则直接return - } - if(Frame_failed) - { - FileProgressWatch_isEnabled=false; - FileProgressWatch_QFuture.cancel(); - Restore_SplitFramesFolderPath(SplitFramesFolderPath,GPU_SplitFramesFolderPath_List); - emit Send_TextBrowser_NewMessage(tr("Error occured when processing [")+SourceFile_fullPath+tr("]. Error: [Failed to scale frames.]")); - emit Send_Table_video_ChangeStatus_rowNumInt_statusQString(rowNum, "Failed"); - emit Send_progressbar_Add(); - return 0;//如果启用stop位,则直接return - } - } - while (Sub_video_ThreadNumRunning!=0) - { - Delay_msec_sleep(500); - } - FileProgressWatch_isEnabled=false; - FileProgressWatch_QFuture.cancel(); - emit Send_CurrentFileProgress_Stop(); - //================ 扫描放大后的帧文件数量,判断是否放大成功 ======================= - QStringList Frame_fileName_list_scaled = file_getFileNames_in_Folder_nofilter(ScaledFramesFolderPath); - if(Frame_fileName_list_scaled.size()spinBox_DenoiseLevel_video->value(); - if(denoiseLevel != -1) - { - denoiseLevel_inName_str = QString::number(denoiseLevel,10)+"n_"; - } - //生成最终视频文件名 - QString video_mp4_scaled_fullpath = ""; - if(CustRes_isEnabled == true) - { - video_mp4_scaled_fullpath = file_path+"/"+file_name+"_waifu2x_"+QString::number(CustRes_width,10)+"x"+QString::number(CustRes_height,10)+"_"+denoiseLevel_inName_str+file_ext+".mp4"; - } - else - { - video_mp4_scaled_fullpath = file_path+"/"+file_name+"_waifu2x_"+QString::number(ScaleRatio,10)+"x_"+denoiseLevel_inName_str+file_ext+".mp4"; - } - video_images2video(video_mp4_fullpath,video_mp4_scaled_fullpath,ScaledFramesFolderPath,AudioPath,CustRes_isEnabled,CustRes_height,CustRes_width,false); - if(QFile::exists(video_mp4_scaled_fullpath)==false)//检查是否成功成功生成视频 - { - if(waifu2x_STOP) - { - emit Send_Table_video_ChangeStatus_rowNumInt_statusQString(rowNum, "Interrupted"); - return 0;//如果启用stop位,则直接return - } - emit Send_TextBrowser_NewMessage(tr("Error occured when processing [")+SourceFile_fullPath+tr("]. Error: [Unable to assemble pictures into videos.]")); - emit Send_Table_video_ChangeStatus_rowNumInt_statusQString(rowNum, "Failed"); - emit Send_progressbar_Add(); - return 0;//如果启用stop位,则直接return - } - //============================== 删除缓存文件 ==================================================== - if(ui->checkBox_KeepVideoCache->isChecked()==false) - { - QFile::remove(VideoConfiguration_fullPath); - file_DelDir(SplitFramesFolderPath); - QFile::remove(AudioPath); - if(SourceFile_fullPath!=video_mp4_fullpath)QFile::remove(video_mp4_fullpath); - } - else - { - DelOriginal=false; - } - //============================= 删除原文件 & & 更新table status ============================ - if(DelOriginal) - { - if(ReplaceOriginalFile(SourceFile_fullPath,video_mp4_scaled_fullpath)==false) - { - if(QAction_checkBox_MoveToRecycleBin_checkBox_DelOriginal->isChecked()) - { - file_MoveToTrash(SourceFile_fullPath); - } - else - { - QFile::remove(SourceFile_fullPath); - } - } - emit Send_Table_video_ChangeStatus_rowNumInt_statusQString(rowNum, "Finished, original file deleted"); - } - else - { - emit Send_Table_video_ChangeStatus_rowNumInt_statusQString(rowNum, "Finished"); - } - //========== 移动到输出路径 ========= - if(ui->checkBox_OutPath_isEnabled->isChecked()) - { - MoveFileToOutputPath(video_mp4_scaled_fullpath,SourceFile_fullPath); - } - //============================ 更新进度条 ================================= - emit Send_progressbar_Add(); - //=========================== ============================== - return 0; -} -/* -#### 分段处理 #### -调用Anime4k处理视频 -读取设置,拆分,创建放大子线程,组装视频 -*/ -int MainWindow::Anime4k_Video_BySegment(int rowNum) -{ - //============================= 读取设置 ================================ - int ScaleRatio = ui->doubleSpinBox_ScaleRatio_video->value(); - bool DelOriginal = (ui->checkBox_DelOriginal->isChecked()||ui->checkBox_ReplaceOriginalFile->isChecked()); - bool isCacheExists = false; - bool isVideoConfigChanged = true; - int Sub_video_ThreadNumRunning = 0; - int SegmentDuration = ui->spinBox_SegmentDuration->value(); - //========================= 拆解map得到参数 ============================= - emit Send_Table_video_ChangeStatus_rowNumInt_statusQString(rowNum, "Processing"); - QString SourceFile_fullPath = Table_model_video->item(rowNum,2)->text(); - if(!QFile::exists(SourceFile_fullPath)) - { - emit Send_TextBrowser_NewMessage(tr("Error occured when processing [")+SourceFile_fullPath+tr("]. Error: [File does not exist.]")); - emit Send_Table_video_ChangeStatus_rowNumInt_statusQString(rowNum, "Failed"); - emit Send_progressbar_Add(); - return 0; - } - //========================== - QFileInfo fileinfo(SourceFile_fullPath); - QString file_name = file_getBaseName(SourceFile_fullPath); - QString file_ext = fileinfo.suffix(); - QString file_path = file_getFolderPath(fileinfo); - //=================================================================== - //生成mp4 - QString video_mp4_fullpath=video_To_CFRMp4(SourceFile_fullPath); - if(!QFile::exists(video_mp4_fullpath))//检查是否成功生成mp4 - { - emit Send_TextBrowser_NewMessage(tr("Error occured when processing [")+SourceFile_fullPath+tr("]. Error: [Cannot convert video format to mp4.]")); - emit Send_Table_video_ChangeStatus_rowNumInt_statusQString(rowNum, "Failed"); - emit Send_progressbar_Add(); - return 0;//如果启用stop位,则直接return - } - //============= 读取自定义分辨率 ============= - bool CustRes_isEnabled = false; - int CustRes_height=0; - int CustRes_width=0; - if(CustRes_isContained(SourceFile_fullPath)) - { - CustRes_isEnabled=true; - QMap Res_map = CustRes_getResMap(SourceFile_fullPath);//res_map["fullpath"],["height"],["width"] - CustRes_height=Res_map["height"].toInt(); - CustRes_width=Res_map["width"].toInt(); - } - //================= - QString AudioPath = file_path+"/Audio_"+file_name+"_"+file_ext+"_W2xEX.wav";//音频 - QString SplitFramesFolderPath = file_path+"/"+file_name+"_"+file_ext+"_SplitFrames_W2xEX";//拆分后存储frame的文件夹 - QString ScaledFramesFolderPath = SplitFramesFolderPath+"/ScaledFrames_W2xEX";//存储放大后的帧 - //=== - QString VideoClipsFolderPath = "";//存储视频片段的文件夹(完整路径) - QString DateStr = ""; - do - { - DateStr = video_getClipsFolderNo(); - VideoClipsFolderPath = file_path+"/"+DateStr+"_VideoClipsWaifu2xEX";//存储视频片段的文件夹(完整路径) - } - while(file_isDirExist(VideoClipsFolderPath)); - QString VideoClipsFolderName = DateStr+"_VideoClipsWaifu2xEX";//存储视频片段的文件夹(名称) - //========================== - // 检测之前的视频配置文件 - //========================== - QString VideoConfiguration_fullPath = file_path+"/VideoConfiguration_"+file_name+"_"+file_ext+"_Waifu2xEX.ini"; - if(QFile::exists(VideoConfiguration_fullPath)) - { - QSettings *configIniRead = new QSettings(VideoConfiguration_fullPath, QSettings::IniFormat); - configIniRead->setIniCodec(QTextCodec::codecForName("UTF-8")); - //=================== 加载之前存储的视频信息 ========================= - int ScaleRatio_old = configIniRead->value("/VideoConfiguration/ScaleRatio").toInt(); - bool CustRes_isEnabled_old = configIniRead->value("/VideoConfiguration/CustRes_isEnabled").toBool(); - int CustRes_height_old = configIniRead->value("/VideoConfiguration/CustRes_height").toInt(); - int CustRes_width_old = configIniRead->value("/VideoConfiguration/CustRes_width").toInt(); - QString EngineName_old = configIniRead->value("/VideoConfiguration/EngineName").toString(); - bool isProcessBySegment_old = configIniRead->value("/VideoConfiguration/isProcessBySegment").toBool(); - bool isVideoFrameInterpolationEnabled_old = configIniRead->value("/VideoConfiguration/isVideoFrameInterpolationEnabled").toBool(); - int MultipleOfFPS_old = configIniRead->value("/VideoConfiguration/MultipleOfFPS").toInt(); - //=================== 比对信息 ================================ - if(EngineName_old=="anime4k") - { - if(CustRes_isEnabled_old==false&&CustRes_isEnabled==false) - { - if(ScaleRatio_old!=ScaleRatio) - { - isVideoConfigChanged=true; - } - else - { - isVideoConfigChanged=false; - } - } - else - { - if(CustRes_isEnabled_old==true&&CustRes_isEnabled==true) - { - if(CustRes_height_old!=CustRes_height||CustRes_width_old!=CustRes_width) - { - isVideoConfigChanged=true; - } - else - { - isVideoConfigChanged=false; - } - } - else - { - isVideoConfigChanged=true; - } - } - if(isProcessBySegment_old == false) - { - isVideoConfigChanged=true; - } - if(isVideoFrameInterpolationEnabled_old != ui->groupBox_FrameInterpolation->isChecked()) - { - isVideoConfigChanged=true; - } - if(MultipleOfFPS_old != ui->spinBox_MultipleOfFPS_VFI->value() && ui->groupBox_FrameInterpolation->isChecked()) - { - isVideoConfigChanged=true; - } - } - else - { - isVideoConfigChanged=true; - } - //============ 修正文件夹名称 ============= - QString VideoClipsFolderPath_old = configIniRead->value("/VideoConfiguration/VideoClipsFolderPath").toString(); - QString VideoClipsFolderName_old = configIniRead->value("/VideoConfiguration/VideoClipsFolderName").toString(); - file_mkDir(VideoClipsFolderPath_old); - if(file_isDirExist(VideoClipsFolderPath_old)==true) - { - VideoClipsFolderPath = VideoClipsFolderPath_old; - VideoClipsFolderName = VideoClipsFolderName_old; - } - } - else - { - emit Send_video_write_VideoConfiguration(VideoConfiguration_fullPath,ScaleRatio,0,CustRes_isEnabled,CustRes_height,CustRes_width,"anime4k",true,VideoClipsFolderPath,VideoClipsFolderName,ui->groupBox_FrameInterpolation->isChecked(),ui->spinBox_MultipleOfFPS_VFI->value()); - } - //======================= - // 检测缓存是否存在 - //======================= - if(file_isDirExist(SplitFramesFolderPath)) - { - if(!isVideoConfigChanged) - { - isCacheExists=true; - emit Send_TextBrowser_NewMessage(tr("The previous video cache file is detected and processing of the previous video cache will continue. If you want to restart processing of the current video:[")+SourceFile_fullPath+tr("], delete the cache manually.")); - } - else - { - isCacheExists=false; - //======== - QFile::remove(VideoConfiguration_fullPath); - file_DelDir(SplitFramesFolderPath); - file_DelDir(VideoClipsFolderPath); - QFile::remove(AudioPath); - DelVfiDir(video_mp4_fullpath); - emit Send_video_write_VideoConfiguration(VideoConfiguration_fullPath,ScaleRatio,0,CustRes_isEnabled,CustRes_height,CustRes_width,"anime4k",true,VideoClipsFolderPath,VideoClipsFolderName,ui->groupBox_FrameInterpolation->isChecked(),ui->spinBox_MultipleOfFPS_VFI->value()); - //======= - emit Send_TextBrowser_NewMessage(tr("The previous video cache file was detected, but because you changed the settings about the video resolution, the previous cache will be deleted and processing of the video:[")+SourceFile_fullPath+tr("] will restart.")); - } - } - else - { - isCacheExists=false; - //======== - QFile::remove(VideoConfiguration_fullPath); - file_DelDir(SplitFramesFolderPath); - file_DelDir(VideoClipsFolderPath); - QFile::remove(AudioPath); - DelVfiDir(video_mp4_fullpath); - emit Send_video_write_VideoConfiguration(VideoConfiguration_fullPath,ScaleRatio,0,CustRes_isEnabled,CustRes_height,CustRes_width,"anime4k",true,VideoClipsFolderPath,VideoClipsFolderName,ui->groupBox_FrameInterpolation->isChecked(),ui->spinBox_MultipleOfFPS_VFI->value()); - //======== - } - /*==================================== - 提取音频 - ======================================*/ - if(!QFile::exists(AudioPath)) - { - video_get_audio(video_mp4_fullpath,AudioPath); - } - //================================== 开始分段处理视频 ================================================= - int StartTime = 0;//起始时间(秒) - int VideoDuration = video_get_duration(video_mp4_fullpath); - bool isSplitComplete = false; - bool isScaleComplete = false; - /* - ============================================ - 开始之前先读取进度 - ============================================ - */ - int OLD_SegmentDuration=-1; - bool read_OLD_SegmentDuration =false; - int LastVideoClipNo = -1; - if(QFile::exists(VideoConfiguration_fullPath)) - { - QSettings *configIniRead = new QSettings(VideoConfiguration_fullPath, QSettings::IniFormat); - configIniRead->setIniCodec(QTextCodec::codecForName("UTF-8")); - //=================== 加载进度 ========================= - StartTime = configIniRead->value("/Progress/StartTime").toInt(); - isSplitComplete = configIniRead->value("/Progress/isSplitComplete").toBool(); - isScaleComplete = configIniRead->value("/Progress/isScaleComplete").toBool(); - OLD_SegmentDuration = configIniRead->value("/Progress/OLDSegmentDuration").toInt(); - LastVideoClipNo = configIniRead->value("/Progress/LastVideoClipNo").toInt(); - } - if(OLD_SegmentDuration>0) - { - read_OLD_SegmentDuration = true; - } - /* - 加载进度条 - */ - int SegmentDuration_tmp_progressbar = 0; - if(read_OLD_SegmentDuration) - { - SegmentDuration_tmp_progressbar = OLD_SegmentDuration; - } - else - { - SegmentDuration_tmp_progressbar = SegmentDuration; - } - if(ui->checkBox_ShowInterPro->isChecked()&&VideoDuration>SegmentDuration_tmp_progressbar) - { - emit Send_CurrentFileProgress_Start(file_name+"."+file_ext,VideoDuration); - if(StartTime>0) - { - emit Send_CurrentFileProgress_progressbar_Add_SegmentDuration(StartTime); - } - } - /* - ============================================ - 正式开始处理 - ============================================ - */ - int SegmentDuration_tmp=0; - int TimeLeft_tmp=0; - while(VideoDuration>StartTime) - { - /*========================== - 计算视频片段时间 - ==========================*/ - TimeLeft_tmp = VideoDuration-StartTime; - if((TimeLeft_tmp)>=SegmentDuration) - { - SegmentDuration_tmp = SegmentDuration; - } - else - { - SegmentDuration_tmp = TimeLeft_tmp; - } - if(read_OLD_SegmentDuration) - { - SegmentDuration_tmp = OLD_SegmentDuration; - read_OLD_SegmentDuration=false; - } - /*========================== - 拆分视频片段 - ==========================*/ - if(isSplitComplete==false) - { - if(file_isDirExist(SplitFramesFolderPath)) - { - file_DelDir(SplitFramesFolderPath); - file_mkDir(SplitFramesFolderPath); - } - else - { - file_mkDir(SplitFramesFolderPath); - } - video_video2images_ProcessBySegment(video_mp4_fullpath,SplitFramesFolderPath,StartTime,SegmentDuration_tmp); - if(waifu2x_STOP) - { - emit Send_Table_video_ChangeStatus_rowNumInt_statusQString(rowNum, "Interrupted"); - return 0;//如果启用stop位,则直接return - } - } - /*========================== - 处理视频片段的帧 - ==========================*/ - if(isScaleComplete==false) - { - //============================== 扫描获取文件名 =============================== - QStringList Frame_fileName_list = file_getFileNames_in_Folder_nofilter(SplitFramesFolderPath); - if(isSplitComplete==false) - { - if(Frame_fileName_list.isEmpty())//检查是否成功拆分为帧 - { - emit Send_TextBrowser_NewMessage(tr("Error occured when processing [")+SourceFile_fullPath+tr("]. Error: [Unable to split video into pictures.]")); - emit Send_Table_video_ChangeStatus_rowNumInt_statusQString(rowNum, "Failed"); - emit Send_progressbar_Add(); - return 0;//如果启用stop位,则直接return - } - } - /* - 记录进度 - 帧拆分成功 - */ - emit Send_video_write_Progress_ProcessBySegment(VideoConfiguration_fullPath,StartTime,true,false,SegmentDuration_tmp,LastVideoClipNo); - //============================== 放大 ======================================= - //===========建立存储放大后frame的文件夹=========== - if(isSplitComplete==false) - { - if(file_isDirExist(ScaledFramesFolderPath)) - { - file_DelDir(ScaledFramesFolderPath); - file_mkDir(ScaledFramesFolderPath); - } - else - { - file_mkDir(ScaledFramesFolderPath); - } - } - //==========开始放大========================== - FileProgressWatch_isEnabled=true; - QFuture FileProgressWatch_QFuture = QtConcurrent::run(this, &MainWindow::CurrentFileProgress_WatchFolderFileNum_Textbrower, SourceFile_fullPath,ScaledFramesFolderPath,Frame_fileName_list.size()+file_getFileNames_in_Folder_nofilter(ScaledFramesFolderPath).size()); - if(ui->checkBox_ShowInterPro->isChecked()==false) - { - FileProgressWatch_isEnabled=false; - FileProgressWatch_QFuture.cancel(); - } - //=======获取显卡信息======== - int NumOfGPU = 1; - if(ui->checkBox_SpecifyGPU_Anime4k->isChecked()==true) - { - NumOfGPU = Get_NumOfGPU_Anime4k(); - } - //============创建显卡文件夹=========== - QStringList GPU_SplitFramesFolderPath_List; - for(int i = 0; i < NumOfGPU; i++) - { - QString GPU_SplitFramesFolderPath = SplitFramesFolderPath+"/"+"GPU_"+QString::number(i); - if(file_isDirExist(GPU_SplitFramesFolderPath)==false) - { - file_DelDir(GPU_SplitFramesFolderPath); - file_mkDir(GPU_SplitFramesFolderPath); - } - else - { - file_mkDir(GPU_SplitFramesFolderPath); - } - GPU_SplitFramesFolderPath_List.append(GPU_SplitFramesFolderPath); - } - int TotalFramesNum = Frame_fileName_list.size(); - int FramesNumForEachGPU = TotalFramesNum/NumOfGPU; - if(FramesNumForEachGPU<1)FramesNumForEachGPU=1; - int start_num=0; - for(int x = 0; x < GPU_SplitFramesFolderPath_List.size(); x++) - { - if(x==GPU_SplitFramesFolderPath_List.size()-1)FramesNumForEachGPU=TotalFramesNum; - QStringList file_waitformove = Frame_fileName_list.mid(start_num,FramesNumForEachGPU); - for(int i = 0; i < file_waitformove.size(); i++) - { - QString FileName = file_waitformove.at(i); - QFile::rename(SplitFramesFolderPath+"/"+FileName,GPU_SplitFramesFolderPath_List.at(x)+"/"+FileName); - } - start_num+=FramesNumForEachGPU; - } - //========================= - bool Frame_failed = false;//放大失败标志 - QMap Sub_Thread_info; - Sub_Thread_info["ScaledFramesFolderPath"]=ScaledFramesFolderPath; - if(CustRes_isEnabled == true) - { - Sub_Thread_info["ScaleRatio"] = QString("%1").arg(CustRes_CalNewScaleRatio(video_mp4_fullpath,CustRes_height,CustRes_width)); - } - else - { - Sub_Thread_info["ScaleRatio"] = QString("%1").arg(ScaleRatio); - } - //========================= - for(int i = 0; i < GPU_SplitFramesFolderPath_List.size(); i++) - { - Sub_Thread_info["SplitFramesFolderPath"]=GPU_SplitFramesFolderPath_List.at(i); - mutex_SubThreadNumRunning.lock(); - Sub_video_ThreadNumRunning++; - mutex_SubThreadNumRunning.unlock(); - QtConcurrent::run(this,&MainWindow::Anime4k_Video_scale,Sub_Thread_info,&Sub_video_ThreadNumRunning,&Frame_failed); - while (Sub_video_ThreadNumRunning >= NumOfGPU) - { - Delay_msec_sleep(500); - } - if(waifu2x_STOP) - { - while (Sub_video_ThreadNumRunning > 0) - { - Delay_msec_sleep(500); - } - FileProgressWatch_isEnabled=false; - FileProgressWatch_QFuture.cancel(); - Restore_SplitFramesFolderPath(SplitFramesFolderPath,GPU_SplitFramesFolderPath_List); - emit Send_Table_video_ChangeStatus_rowNumInt_statusQString(rowNum, "Interrupted"); - return 0;//如果启用stop位,则直接return - } - if(Frame_failed) - { - FileProgressWatch_isEnabled=false; - FileProgressWatch_QFuture.cancel(); - Restore_SplitFramesFolderPath(SplitFramesFolderPath,GPU_SplitFramesFolderPath_List); - emit Send_TextBrowser_NewMessage(tr("Error occured when processing [")+SourceFile_fullPath+tr("]. Error: [Failed to scale frames.]")); - emit Send_Table_video_ChangeStatus_rowNumInt_statusQString(rowNum, "Failed"); - emit Send_progressbar_Add(); - return 0;//如果启用stop位,则直接return - } - } - while (Sub_video_ThreadNumRunning!=0) - { - Delay_msec_sleep(500); - } - FileProgressWatch_isEnabled=false; - FileProgressWatch_QFuture.cancel(); - //================ 扫描放大后的帧文件数量,判断是否放大成功 ======================= - QStringList Frame_fileName_list_scaled = file_getFileNames_in_Folder_nofilter(ScaledFramesFolderPath); - if(Frame_fileName_list_scaled.size()checkBox_ShowInterPro->isChecked()) - { - emit Send_CurrentFileProgress_progressbar_Add_SegmentDuration(SegmentDuration_tmp); - } - StartTime+=SegmentDuration_tmp; - isSplitComplete = false; - isScaleComplete = false; - LastVideoClipNo=VideoClipNo; - emit Send_video_write_Progress_ProcessBySegment(VideoConfiguration_fullPath,StartTime,false,false,-1,VideoClipNo); - } - emit Send_CurrentFileProgress_Stop(); - //====================================================== - // 组装(片段到成片) - //====================================================== - //确定是否插入降噪值 - QString denoiseLevel_inName_str = ""; - int denoiseLevel = ui->spinBox_DenoiseLevel_video->value(); - if(denoiseLevel != -1) - { - denoiseLevel_inName_str = QString::number(denoiseLevel,10)+"n_"; - } - //生成最终视频名称 - QString video_mp4_scaled_fullpath = ""; - if(CustRes_isEnabled) - { - video_mp4_scaled_fullpath = file_path+"/"+file_name+"_waifu2x_"+QString::number(CustRes_width,10)+"x"+QString::number(CustRes_height,10)+"_"+denoiseLevel_inName_str+file_ext+".mp4"; - } - else - { - video_mp4_scaled_fullpath = file_path+"/"+file_name+"_waifu2x_"+QString::number(ScaleRatio,10)+"x_"+denoiseLevel_inName_str+file_ext+".mp4"; - } - QFile::remove(video_mp4_scaled_fullpath); - video_AssembleVideoClips(VideoClipsFolderPath,VideoClipsFolderName,video_mp4_scaled_fullpath,AudioPath); - if(QFile::exists(video_mp4_scaled_fullpath)==false)//检查是否成功生成视频 - { - if(waifu2x_STOP) - { - emit Send_Table_video_ChangeStatus_rowNumInt_statusQString(rowNum, "Interrupted"); - return 0;//如果启用stop位,则直接return - } - emit Send_TextBrowser_NewMessage(tr("Error occured when processing [")+SourceFile_fullPath+tr("]. Error: [Unable to assemble video clips.]")); - emit Send_Table_video_ChangeStatus_rowNumInt_statusQString(rowNum, "Failed"); - emit Send_progressbar_Add(); - return 0;//如果启用stop位,则直接return - } - //============================== 删除缓存文件 ==================================================== - if(ui->checkBox_KeepVideoCache->isChecked()==false) - { - QFile::remove(VideoConfiguration_fullPath); - file_DelDir(SplitFramesFolderPath); - file_DelDir(VideoClipsFolderPath); - QFile::remove(AudioPath); - if(SourceFile_fullPath!=video_mp4_fullpath)QFile::remove(video_mp4_fullpath); - } - else - { - DelOriginal=false; - } - //============================= 删除原文件 & & 更新table status ============================ - if(DelOriginal) - { - if(ReplaceOriginalFile(SourceFile_fullPath,video_mp4_scaled_fullpath)==false) - { - if(QAction_checkBox_MoveToRecycleBin_checkBox_DelOriginal->isChecked()) - { - file_MoveToTrash(SourceFile_fullPath); - } - else - { - QFile::remove(SourceFile_fullPath); - } - } - emit Send_Table_video_ChangeStatus_rowNumInt_statusQString(rowNum, "Finished, original file deleted"); - } - else - { - emit Send_Table_video_ChangeStatus_rowNumInt_statusQString(rowNum, "Finished"); - } - //========== 移动到输出路径 ========= - if(ui->checkBox_OutPath_isEnabled->isChecked()) - { - MoveFileToOutputPath(video_mp4_scaled_fullpath,SourceFile_fullPath); - } - //============================ 更新进度条 ================================= - emit Send_progressbar_Add(); - //=========================== ============================== - return 0; -} -/* -Anime4k视频放大子线程 -放大,修改大小 -*/ -int MainWindow::Anime4k_Video_scale(QMap Sub_Thread_info,int *Sub_video_ThreadNumRunning,bool *Frame_failed) -{ - bool AllFinished=true; - QString SplitFramesFolderPath = Sub_Thread_info["SplitFramesFolderPath"]; - QString ScaledFramesFolderPath = Sub_Thread_info["ScaledFramesFolderPath"]; - //=========== - QStringList OutPutFilesFullPathList; - do - { - QStringList InputFilesNameList = file_getFileNames_in_Folder_nofilter(SplitFramesFolderPath); - for(int i=0; ispinBox_retry->value()+ForceRetryCount); retry++) - { - Anime4k->start(CMD); - while(!Anime4k->waitForStarted(100)&&!QProcess_stop) {} - while(!Anime4k->waitForFinished(500)&&!QProcess_stop) - { - if(waifu2x_STOP) - { - QStringList FinfishedFileList = WaitForEngineIO(OutPutFilesFullPathList); - Anime4k->close(); - //============ - QString file_fullpath_tmp=""; - QString file_name=""; - QString file_ext=""; - for(int i=0; ispinBox_retry->value()+(ForceRetryCount-1))break; - Delay_sec_sleep(5); - emit Send_TextBrowser_NewMessage(tr("Automatic retry, please wait.")); - AllFinished=false; - break; - } - } - if(AllFinished== true)break; - } - //========= - AllFinished = true; - for(int i=0; icheckBox_FastMode_Anime4K->isChecked()) - { - Anime4k_Settings_str.append("-f "); - } - //GPU加速 - if(ui->checkBox_GPUMode_Anime4K->isChecked()) - { - Anime4k_Settings_str.append("-q "); - //加载GPGPU模式 - QString GPGPU_Model = ui->comboBox_GPGPUModel_A4k->currentText().toLower().trimmed(); - Anime4k_Settings_str.append("-M "+GPGPU_Model+" "); - //加载OpenCL选项 - if(GPGPU_Model=="opencl") - { - if(ui->checkBox_OpenCLParallelIO_A4k->isChecked())Anime4k_Settings_str.append("-P "); - Anime4k_Settings_str.append("-Q "+QString::number(ui->spinBox_OpenCLCommandQueues_A4k->value(),10)+" "); - } - } - //ACNet - if(ui->checkBox_ACNet_Anime4K->isChecked()) - { - Anime4k_Settings_str.append("-w ");//启用acnet - if(ui->checkBox_HDNMode_Anime4k->isChecked()) - { - Anime4k_Settings_str.append("-H ");//启用HDN - } - return Anime4k_Settings_str; - } - //============= 非ACNET选项 =========== - //Passes - Anime4k_Settings_str.append("-p "+QString::number(ui->spinBox_Passes_Anime4K->value(),10)+" "); - //Push color count - Anime4k_Settings_str.append("-n "+QString::number(ui->spinBox_PushColorCount_Anime4K->value(),10)+" "); - //Push color strength - Anime4k_Settings_str.append("-c "+QString::number(ui->doubleSpinBox_PushColorStrength_Anime4K->value(),'f',2)+" "); - //Push gradient strength - Anime4k_Settings_str.append("-g "+QString::number(ui->doubleSpinBox_PushGradientStrength_Anime4K->value(),'f',2)+" "); - //Pre-processing - if(ui->checkBox_EnablePreProcessing_Anime4k->isChecked()) - { - Anime4k_Settings_str.append("-b "); - uint8_t PreProcessingFilters = 0; - //读取滤镜选择情况 - if (ui->checkBox_MedianBlur_Pre_Anime4k->isChecked()) - { - PreProcessingFilters|=1; - } - if (ui->checkBox_MeanBlur_Pre_Anime4k->isChecked()) - { - PreProcessingFilters|=2; - } - if (ui->checkBox_CASSharping_Pre_Anime4k->isChecked()) - { - PreProcessingFilters|=4; - } - if (ui->checkBox_GaussianBlurWeak_Pre_Anime4k->isChecked()) - { - PreProcessingFilters|=8; - } - if (ui->checkBox_GaussianBlur_Pre_Anime4k->isChecked()) - { - PreProcessingFilters|=16; - } - if (ui->checkBox_BilateralFilter_Pre_Anime4k->isChecked()) - { - PreProcessingFilters|=32; - } - if (ui->checkBox_BilateralFilterFaster_Pre_Anime4k->isChecked()) - { - PreProcessingFilters|=64; - } - //生成添加滤镜指令 - if(PreProcessingFilters!=0) - { - Anime4k_Settings_str.append("-r "+QString::number(PreProcessingFilters,10)+" "); - } - else - { - Anime4k_Settings_str.append("-r 4 "); - } - } - //Post-processing - if(ui->checkBox_EnablePostProcessing_Anime4k->isChecked()) - { - Anime4k_Settings_str.append("-a "); - uint8_t PostProcessingFilters = 0; - //读取滤镜选择情况 - if (ui->checkBox_MedianBlur_Post_Anime4k->isChecked()) - { - PostProcessingFilters|=1; - } - if (ui->checkBox_MeanBlur_Post_Anime4k->isChecked()) - { - PostProcessingFilters|=2; - } - if (ui->checkBox_CASSharping_Post_Anime4k->isChecked()) - { - PostProcessingFilters|=4; - } - if (ui->checkBox_GaussianBlurWeak_Post_Anime4k->isChecked()) - { - PostProcessingFilters|=8; - } - if (ui->checkBox_GaussianBlur_Post_Anime4k->isChecked()) - { - PostProcessingFilters|=16; - } - if (ui->checkBox_BilateralFilter_Post_Anime4k->isChecked()) - { - PostProcessingFilters|=32; - } - if (ui->checkBox_BilateralFilterFaster_Post_Anime4k->isChecked()) - { - PostProcessingFilters|=64; - } - //生成添加滤镜指令 - if(PostProcessingFilters!=0) - { - Anime4k_Settings_str.append("-e "+QString::number(PostProcessingFilters,10)+" "); - } - else - { - Anime4k_Settings_str.append("-e 4 "); - } - } - return Anime4k_Settings_str; -} -/* -Anime4k -读取配置生成配置string -*/ -QString MainWindow::Anime4k_ReadSettings(bool PreserveAlphaChannel) -{ - QString Anime4k_Settings_str = ""; - //================================= - Anime4k_Settings_str.append(Anime4k_PreLoad_Settings_Str); - //保留透明通道 - if(PreserveAlphaChannel) - { - Anime4k_Settings_str.append("-A ");//保留透明通道 - } - //GPU加速 - if(ui->checkBox_GPUMode_Anime4K->isChecked()) - { - //指定GPU - if(ui->checkBox_SpecifyGPU_Anime4k->isChecked()) - { - Anime4k_Settings_str.append(Anime4k_GetGPUInfo()+" "); - } - } - //================================= - return Anime4k_Settings_str; -} - -QString MainWindow::Anime4k_GetGPUInfo() -{ - GetGPUInfo_QMutex_Anime4k.lock(); - //==== - QStringList GPU_List = ui->lineEdit_GPUs_Anime4k->text().trimmed().remove(" ").remove(" ").split(":"); - GPU_List.removeDuplicates(); - GPU_List.removeAll(""); - //==== - int MAX_GPU_ID_Anime4k = GPU_List.size()-1; - if(GPU_ID_Anime4k_GetGPUInfo>MAX_GPU_ID_Anime4k) - { - GPU_ID_Anime4k_GetGPUInfo=0; - } - //====== - QString GPUInfo=""; - QStringList PID_DID = GPU_List.at(GPU_ID_Anime4k_GetGPUInfo).split(","); - PID_DID.removeAll(""); - if(PID_DID.size()==2) - { - GPUInfo = "-h "+PID_DID.at(0).trimmed()+" -d "+PID_DID.at(1).trimmed(); - } - else - { - GPUInfo = "-h 0 -d 0"; - } - //====== - GPU_ID_Anime4k_GetGPUInfo++; - if(GPU_ID_Anime4k_GetGPUInfo>MAX_GPU_ID_Anime4k) - { - GPU_ID_Anime4k_GetGPUInfo=0; - } - //====== - GetGPUInfo_QMutex_Anime4k.unlock(); - return GPUInfo; -} -/* -列出可用的GPUs -*/ -void MainWindow::on_pushButton_ListGPUs_Anime4k_clicked() -{ - QtConcurrent::run(this, &MainWindow::ListGPUs_Anime4k); -} - -void MainWindow::ListGPUs_Anime4k() -{ - QString cmd = "\"" + Anime4k_ProgramPath + "\" -l"; - ExecuteCMD_batFile(cmd.replace("%","%%")+"\n title = GPU List for Anime4K @ Waifu2x-Extension-GUI\n pause",false); -} - -void MainWindow::on_lineEdit_GPUs_Anime4k_editingFinished() -{ - QString Format_str="0123456789:,"; - QString GPUs_str = ui->lineEdit_GPUs_Anime4k->text().trimmed().replace(":",":").replace(",",",").remove(" ").remove(" "); - for (int i=0; ilineEdit_GPUs_Anime4k->setText(GPUs_str); -} - -void MainWindow::on_pushButton_VerifyGPUsConfig_Anime4k_clicked() -{ - on_lineEdit_GPUs_Anime4k_editingFinished(); - QStringList GPU_List = ui->lineEdit_GPUs_Anime4k->text().trimmed().remove(" ").remove(" ").split(":"); - GPU_List.removeDuplicates(); - GPU_List.removeAll(""); - //====== - QString VerRes = ""; - //====== - for (int i=0; isetWindowTitle(tr("GPUs List according to your configuration")); - MSG->setText(VerRes); - MSG->setIcon(QMessageBox::Information); - MSG->setModal(true); - MSG->show(); - //====== - emit Send_TextBrowser_NewMessage(tr("\nAnime4k GPUs List(user configuration):\n")+VerRes.trimmed()); -} - -/* -删除强制重试时生成的垃圾缓存文件 -*/ -void MainWindow::DelTrash_ForceRetry_Anime4k(QString OutPut_Path) -{ - if(isForceRetryClicked)//判断是否触发强制重试,若触发,直接删除垃圾缓存 - { - QFile::remove(OutPut_Path); - isForceRetryClicked_QMutex.lock(); - isForceRetryClicked=false; - isForceRetryClicked_QMutex.unlock(); - } - return; -} -//阻断其他线程重置是否强制重试的标记,并检测anime4k是否正在运行 -void MainWindow::isForceRetryClicked_SetTrue_Block_Anime4k() -{ - isForceRetryClicked_QMutex.lock(); - isForceRetryClicked=true; - Delay_sec_sleep(5); - QProcess Get_tasklist; - do - { - Get_tasklist.start("tasklist /fo csv"); - while(!Get_tasklist.waitForStarted(100)) {} - while(!Get_tasklist.waitForFinished(100)) {} - if(Get_tasklist.readAllStandardOutput().contains("Anime4K_waifu2xEX.exe")==false) - { - break; - } - Delay_sec_sleep(1); - } - while(true); - isForceRetryClicked_QMutex.unlock(); - emit Send_SetEnable_pushButton_ForceRetry_self(); -} - -void MainWindow::DenoiseLevelSpinboxSetting_Anime4k() -{ - if(ui->checkBox_ACNet_Anime4K->isChecked()&&ui->checkBox_HDNMode_Anime4k->isChecked()) - { - if(ui->comboBox_Engine_Image->currentIndex()==3) - { - ui->spinBox_DenoiseLevel_image->setRange(1,3); - ui->spinBox_DenoiseLevel_image->setValue(1); - ui->spinBox_DenoiseLevel_image->setEnabled(1); - ui->spinBox_DenoiseLevel_image->setToolTip(tr("Range:1~3")); - ui->label_ImageDenoiseLevel->setToolTip(tr("Range:1~3")); - } - if(ui->comboBox_Engine_GIF->currentIndex()==3) - { - ui->spinBox_DenoiseLevel_gif->setRange(1,3); - ui->spinBox_DenoiseLevel_gif->setValue(1); - ui->spinBox_DenoiseLevel_gif->setEnabled(1); - ui->spinBox_DenoiseLevel_gif->setToolTip(tr("Range:1~3")); - ui->label_GIFDenoiseLevel->setToolTip(tr("Range:1~3")); - } - if(ui->comboBox_Engine_Video->currentIndex()==2) - { - ui->spinBox_DenoiseLevel_video->setRange(1,3); - ui->spinBox_DenoiseLevel_video->setValue(1); - ui->spinBox_DenoiseLevel_video->setEnabled(1); - ui->spinBox_DenoiseLevel_video->setToolTip(tr("Range:1~3")); - ui->label_VideoDenoiseLevel->setToolTip(tr("Range:1~3")); - } - } - else - { - if(ui->comboBox_Engine_Image->currentIndex()==3) - { - ui->spinBox_DenoiseLevel_image->setRange(-1,0); - ui->spinBox_DenoiseLevel_image->setValue(-1); - ui->spinBox_DenoiseLevel_image->setEnabled(0); - ui->spinBox_DenoiseLevel_image->setToolTip(tr("Due to current settings, you can\'t adjust denoise level.")); - ui->label_ImageDenoiseLevel->setToolTip(tr("Due to current settings, you can\'t adjust denoise level.")); - } - if(ui->comboBox_Engine_GIF->currentIndex()==3) - { - ui->spinBox_DenoiseLevel_gif->setRange(-1,0); - ui->spinBox_DenoiseLevel_gif->setValue(-1); - ui->spinBox_DenoiseLevel_gif->setEnabled(0); - ui->spinBox_DenoiseLevel_gif->setToolTip(tr("Due to current settings, you can\'t adjust denoise level.")); - ui->label_GIFDenoiseLevel->setToolTip(tr("Due to current settings, you can\'t adjust denoise level.")); - } - if(ui->comboBox_Engine_Video->currentIndex()==2) - { - ui->spinBox_DenoiseLevel_video->setRange(-1,0); - ui->spinBox_DenoiseLevel_video->setValue(-1); - ui->spinBox_DenoiseLevel_video->setEnabled(0); - ui->spinBox_DenoiseLevel_video->setToolTip(tr("Due to current settings, you can\'t adjust denoise level.")); - ui->label_VideoDenoiseLevel->setToolTip(tr("Due to current settings, you can\'t adjust denoise level.")); - } - } -} -/* -获取可用显卡数量 -*/ -int MainWindow::Get_NumOfGPU_Anime4k() -{ - QStringList GPU_List = ui->lineEdit_GPUs_Anime4k->text().trimmed().remove(" ").remove(" ").split(":"); - GPU_List.removeDuplicates(); - GPU_List.removeAll(""); - int GPUNum = 0; - QStringList PID_DID; - for (int i=0; i FileProgressWatch_QFuture = QtConcurrent::run(this, &MainWindow::CurrentFileProgress_WatchFolderFileNum, scaledFramesFolder);//启动waifu2x 主线程 - if(ui->checkBox_ShowInterPro->isChecked()==false) - { - FileProgressWatch_isEnabled=false; - FileProgressWatch_QFuture.cancel(); - emit Send_CurrentFileProgress_Stop(); - } - //=======获取显卡信息======== - int NumOfGPU = 1; - if(ui->checkBox_SpecifyGPU_Anime4k->isChecked()==true) - { - NumOfGPU = Get_NumOfGPU_Anime4k(); - } - //============创建显卡文件夹=========== - QStringList GPU_splitFramesFolder_List; - for(int i = 0; i < NumOfGPU; i++) - { - QString GPU_splitFramesFolder = splitFramesFolder+"/"+"GPU_"+QString::number(i); - if(file_isDirExist(GPU_splitFramesFolder)) - { - file_DelDir(GPU_splitFramesFolder); - file_mkDir(GPU_splitFramesFolder); - } - else - { - file_mkDir(GPU_splitFramesFolder); - } - GPU_splitFramesFolder_List.append(GPU_splitFramesFolder); - } - int TotalFramesNum = framesFileName_qStrList.size(); - int FramesNumForEachGPU = TotalFramesNum/NumOfGPU; - if(FramesNumForEachGPU<1)FramesNumForEachGPU=1; - int start_num=0; - for(int x = 0; x < GPU_splitFramesFolder_List.size(); x++) - { - if(x==GPU_splitFramesFolder_List.size()-1)FramesNumForEachGPU=TotalFramesNum; - QStringList file_waitformove = framesFileName_qStrList.mid(start_num,FramesNumForEachGPU); - for(int i = 0; i < file_waitformove.size(); i++) - { - QString FileName = file_waitformove.at(i); - QFile::rename(splitFramesFolder+"/"+FileName,GPU_splitFramesFolder_List.at(x)+"/"+FileName); - } - start_num+=FramesNumForEachGPU; - } - //=== - QMap Sub_Thread_info; - Sub_Thread_info["scaledFramesFolder"]=scaledFramesFolder; - if(CustRes_isContained(sourceFileFullPath)) - { - QMap Res_map = CustRes_getResMap(sourceFileFullPath);//res_map["fullpath"],["height"],["width"] - Sub_Thread_info["ScaleRatio"] = QString("%1").arg(CustRes_CalNewScaleRatio(sourceFileFullPath,Res_map["height"].toInt(),Res_map["width"].toInt())); - } - else - { - Sub_Thread_info["ScaleRatio"] = QString("%1").arg(qRound(ui->doubleSpinBox_ScaleRatio_gif->value())); - } - //========================= - bool Frame_failed = false;//放大失败标志 - int Sub_gif_ThreadNumRunning=0;//正在运行的线程数量 - //========================= - for(int i = 0; i < GPU_splitFramesFolder_List.size(); i++) - { - Sub_Thread_info["splitFramesFolder"]=GPU_splitFramesFolder_List.at(i); - mutex_SubThreadNumRunning.lock(); - Sub_gif_ThreadNumRunning++; - mutex_SubThreadNumRunning.unlock(); - QtConcurrent::run(this,&MainWindow::Anime4k_APNG_scale,Sub_Thread_info,&Sub_gif_ThreadNumRunning,&Frame_failed); - while (Sub_gif_ThreadNumRunning >= NumOfGPU) - { - Delay_msec_sleep(500); - } - if(waifu2x_STOP) - { - while (Sub_gif_ThreadNumRunning > 0) - { - Delay_msec_sleep(500); - } - FileProgressWatch_isEnabled=false; - FileProgressWatch_QFuture.cancel(); - return false; - } - if(Frame_failed) - { - FileProgressWatch_isEnabled=false; - FileProgressWatch_QFuture.cancel(); - emit Send_TextBrowser_NewMessage(tr("Error occured when processing [")+sourceFileFullPath+tr("]. Error: [Failed to scale frames.]")); - return false; - } - } - while (Sub_gif_ThreadNumRunning!=0) - { - Delay_msec_sleep(500); - } - FileProgressWatch_isEnabled=false; - FileProgressWatch_QFuture.cancel(); - emit Send_CurrentFileProgress_Stop(); - //======================= 检查是否成功放大所有帧 =========================== - QStringList framesFileName_qStrList_scaled = file_getFileNames_in_Folder_nofilter(scaledFramesFolder); - if(framesFileName_qStrList.size()!=framesFileName_qStrList_scaled.size()) - { - emit Send_TextBrowser_NewMessage(tr("Error occured when processing [")+sourceFileFullPath+tr("]. Error: [Failed to scale frames.]")); - return false; - } - //============================================================ - //组装apng - APNG_Frames2APNG(sourceFileFullPath, scaledFramesFolder, resultFileFullPath, false); - return true; -} -/* -Anime4k APNG 放大子线程 -*/ -int MainWindow::Anime4k_APNG_scale(QMap Sub_Thread_info,int *Sub_gif_ThreadNumRunning,bool *Frame_failed) -{ - bool AllFinished=true; - QString splitFramesFolder = Sub_Thread_info["splitFramesFolder"]; - QString scaledFramesFolder = Sub_Thread_info["scaledFramesFolder"]; - //================== - // 生成输出文件列表 - //================== - QStringList OutPutFilesFullPathList; - do - { - QStringList InputFilesNameList = file_getFileNames_in_Folder_nofilter(splitFramesFolder); - for(int i=0; ispinBox_retry->value()+ForceRetryCount); retry++) - { - Anime4k->start(CMD); - while(!Anime4k->waitForStarted(100)&&!QProcess_stop) {} - while(!Anime4k->waitForFinished(500)&&!QProcess_stop) - { - if(waifu2x_STOP) - { - Anime4k->close(); - mutex_SubThreadNumRunning.lock(); - *Sub_gif_ThreadNumRunning=*Sub_gif_ThreadNumRunning-1; - mutex_SubThreadNumRunning.unlock(); - return 0; - } - } - AllFinished = true; - for(int i=0; ispinBox_retry->value()+(ForceRetryCount-1))break; - Delay_sec_sleep(5); - emit Send_TextBrowser_NewMessage(tr("Automatic retry, please wait.")); - AllFinished=false; - break; - } - } - if(AllFinished == true)break; - } - //========= - AllFinished = true; - for(int i=0; i. + + My Github homepage: https://github.com/AaronFeng753 +*/ +#include "mainwindow.h" +#include "ui_mainwindow.h" +/* +处理图片 +*/ +int MainWindow::Anime4k_Image(int rowNum,bool ReProcess_MissingAlphaChannel) +{ + //============================= 读取设置 ================================ + int ScaleRatio = 0; + int denoiseLevel = ui->spinBox_DenoiseLevel_image->value();//获取降噪等级 + bool isDenoiseEnabled = (denoiseLevel != -1);//若降噪等级等于-1就是没启用降噪 + bool DelOriginal = (ui->checkBox_DelOriginal->isChecked()||ui->checkBox_ReplaceOriginalFile->isChecked()); + bool PreserveAlphaChannel = Imgae_hasAlphaChannel(rowNum); + QString OutPutPath_Final =""; + //========================= 拆解map得到参数 ============================= + emit Send_Table_image_ChangeStatus_rowNumInt_statusQString(rowNum, "Processing"); + QString SourceFile_fullPath = Table_model_image->item(rowNum,2)->text(); + if(!QFile::exists(SourceFile_fullPath)) + { + emit Send_TextBrowser_NewMessage(tr("Error occured when processing [")+SourceFile_fullPath+tr("]. Error: [File does not exist.]")); + emit Send_Table_image_ChangeStatus_rowNumInt_statusQString(rowNum, "Failed"); + emit Send_progressbar_Add(); + mutex_ThreadNumRunning.lock(); + ThreadNumRunning--; + mutex_ThreadNumRunning.unlock();//线程数量统计-1 + return 0; + } + //========= 转换到 PNG ========= + QString SourceFile_fullPath_Original = SourceFile_fullPath; + SourceFile_fullPath = Imgae_PreProcess(SourceFile_fullPath_Original,ReProcess_MissingAlphaChannel); + //================================ + // 自定义分辨率设定 + //================================ + bool CustRes_isEnabled = false; + int CustRes_height=0; + int CustRes_width=0; + if(CustRes_isContained(SourceFile_fullPath_Original)) + { + CustRes_isEnabled=true; + QMap Res_map = CustRes_getResMap(SourceFile_fullPath_Original);//res_map["fullpath"],["height"],["width"] + ScaleRatio = CustRes_CalNewScaleRatio(SourceFile_fullPath,Res_map["height"].toInt(),Res_map["width"].toInt()); + if(ScaleRatio==0) + { + emit Send_TextBrowser_NewMessage(tr("Error occured when processing [")+SourceFile_fullPath_Original+tr("]. Error: [The resolution of the source file cannot be read, so the image cannot be scaled to a custom resolution.]")); + emit Send_Table_image_ChangeStatus_rowNumInt_statusQString(rowNum, "Failed"); + emit Send_progressbar_Add(); + mutex_ThreadNumRunning.lock(); + ThreadNumRunning--; + mutex_ThreadNumRunning.unlock();//线程数量统计-1 + return 0; + } + CustRes_height=Res_map["height"].toInt(); + CustRes_width=Res_map["width"].toInt(); + } + else + { + double ScaleRatio_double_tmp = ui->doubleSpinBox_ScaleRatio_image->value(); + if(ScaleRatio_double_tmp == (int)ScaleRatio_double_tmp) + { + ScaleRatio = qRound(ScaleRatio_double_tmp); + } + else + { + CustRes_isEnabled=true; + QMap Res_map = DoubleScaleRatio_Cal_NewScaleRatio_NewHW(SourceFile_fullPath,ScaleRatio_double_tmp); + //==== + if(Res_map.isEmpty()) + { + emit Send_TextBrowser_NewMessage(tr("Error occured when processing [")+SourceFile_fullPath+tr("]. Error: [Unable to read the resolution of the source file.]")); + emit Send_Table_image_ChangeStatus_rowNumInt_statusQString(rowNum, "Failed"); + emit Send_progressbar_Add(); + mutex_ThreadNumRunning.lock(); + ThreadNumRunning--; + mutex_ThreadNumRunning.unlock();//线程数量统计-1 + return 0; + } + //==== + ScaleRatio = Res_map["ScaleRatio"].toInt(); + CustRes_height = Res_map["Height_new"].toInt(); + CustRes_width = Res_map["width_new"].toInt(); + } + } + //======================================================= + QFileInfo fileinfo(SourceFile_fullPath); + QString SourceFile_fullPath_FileName = file_getBaseName(SourceFile_fullPath); + QString SourceFile_fullPath_FileExt = fileinfo.suffix(); + QString SourceFile_fullPath_FolderPath = file_getFolderPath(fileinfo); + QString OutPut_Path = SourceFile_fullPath_FolderPath + "/" + SourceFile_fullPath_FileName + "_waifu2x_"+QString::number(ScaleRatio, 10)+"x_"+SourceFile_fullPath_FileExt+".png"; + if(isDenoiseEnabled == true) + { + OutPut_Path = SourceFile_fullPath_FolderPath + "/" + SourceFile_fullPath_FileName + "_waifu2x_"+QString::number(ScaleRatio, 10)+"x_"+QString::number(denoiseLevel, 10)+"n_"+SourceFile_fullPath_FileExt+".png"; + } + else + { + OutPut_Path = SourceFile_fullPath_FolderPath + "/" + SourceFile_fullPath_FileName + "_waifu2x_"+QString::number(ScaleRatio, 10)+"x_"+SourceFile_fullPath_FileExt+".png"; + } + //============================== 放大 ======================================= + QProcess *Waifu2x = new QProcess(); + QString CMD = "\"" + Anime4k_ProgramPath + "\" -i \"" + SourceFile_fullPath + "\" -o \"" + OutPut_Path + "\" -z " + QString::number(ScaleRatio, 10) + HDNDenoiseLevel_image + Anime4k_ReadSettings(PreserveAlphaChannel); + //======== + for(int retry=0; retry<(ui->spinBox_retry->value()+ForceRetryCount); retry++) + { + Waifu2x->start(CMD); + while(!Waifu2x->waitForStarted(100)&&!QProcess_stop) {} + while(!Waifu2x->waitForFinished(500)&&!QProcess_stop) + { + if(waifu2x_STOP) + { + Waifu2x->close(); + QFile::remove(OutPut_Path); + emit Send_Table_image_ChangeStatus_rowNumInt_statusQString(rowNum, "Interrupted"); + mutex_ThreadNumRunning.lock(); + ThreadNumRunning--; + mutex_ThreadNumRunning.unlock(); + return 0; + } + } + DelTrash_ForceRetry_Anime4k(OutPut_Path);//删除强制关闭导致生成的垃圾缓存文件 + if(QFile::exists(OutPut_Path))//判断是否成功输出目标文件 + { + break; + } + else + { + if(retry==ui->spinBox_retry->value()+(ForceRetryCount-1))break; + Delay_sec_sleep(5); + emit Send_TextBrowser_NewMessage(tr("Automatic retry, please wait.")); + } + } + //======== + if(QFile::exists(OutPut_Path)==false) + { + if(SourceFile_fullPath_Original!=SourceFile_fullPath) + { + QFile::remove(SourceFile_fullPath); + } + emit Send_TextBrowser_NewMessage(tr("Error occured when processing [")+SourceFile_fullPath_Original+tr("]. Error: [Unable to scale the picture.]")); + emit Send_Table_image_ChangeStatus_rowNumInt_statusQString(rowNum, "Failed"); + emit Send_progressbar_Add(); + mutex_ThreadNumRunning.lock(); + ThreadNumRunning--; + mutex_ThreadNumRunning.unlock(); + return 0; + } + //============================ 调整大小 ==================================================== + if(CustRes_isEnabled == true) + { + do + { + QImage qimage_adj(OutPut_Path); + //读取放大后的图片并调整大小 + QImage qimage_adj_scaled = qimage_adj.scaled(CustRes_width,CustRes_height,CustRes_AspectRatioMode,Qt::SmoothTransformation); + QImageWriter qimageW_adj; + qimageW_adj.setFormat("png"); + qimageW_adj.setFileName(OutPut_Path); + if(qimageW_adj.canWrite()) + { + qimageW_adj.write(qimage_adj_scaled); + } + if(!QFile::exists(OutPut_Path)) + { + emit Send_TextBrowser_NewMessage(tr("Error occured when processing [")+SourceFile_fullPath+tr("]. Error: [Unable to resize the scaled picture to the target size]")); + emit Send_Table_image_ChangeStatus_rowNumInt_statusQString(rowNum, "Failed"); + emit Send_progressbar_Add(); + mutex_ThreadNumRunning.lock(); + ThreadNumRunning--; + mutex_ThreadNumRunning.unlock();//线程数量统计-1 + return 0; + } + } + while(false); + QString OutPut_Path_CustRes = SourceFile_fullPath_FolderPath + "/" + SourceFile_fullPath_FileName + "_waifu2x_"+QString::number(CustRes_width, 10)+"x"+QString::number(CustRes_height, 10)+"_"+SourceFile_fullPath_FileExt+".png"; + QFile::remove(OutPut_Path_CustRes); + QFile::rename(OutPut_Path,OutPut_Path_CustRes); + //=========================== 另存为JPG&压缩JPG =========================================== + OutPutPath_Final = SaveImageAs_FormatAndQuality(SourceFile_fullPath_Original,OutPut_Path_CustRes,isDenoiseEnabled,denoiseLevel); + } + else + { + //=========================== 另存为JPG&压缩JPG =========================================== + OutPutPath_Final = SaveImageAs_FormatAndQuality(SourceFile_fullPath_Original,OutPut_Path,isDenoiseEnabled,denoiseLevel); + } + //================== 检查是否丢失了透明通道 ===================== + if(ReProcess_MissingAlphaChannel==false) + { + QImage QImage_Final(OutPutPath_Final); + if(PreserveAlphaChannel == true && QImage_Final.hasAlphaChannel() == false && ui->checkBox_AutoDetectAlphaChannel->isChecked()) + { + QFile::remove(OutPutPath_Final); + emit Send_TextBrowser_NewMessage(tr("Since the Alpha channel in the resulting image is lost, this image will be reprocessed to fix it:[")+SourceFile_fullPath_Original+tr("].\nIf the reprocessing happens a lot, you should consider enable [Always pre-process images with Alpha Channel] in [Additional settings].")); + return Anime4k_Image(rowNum,true); + } + } + //============================= 删除原文件 & 更新table status ============================ + if(SourceFile_fullPath_Original!=SourceFile_fullPath) + { + QFile::remove(SourceFile_fullPath); + } + if(DelOriginal == true) + { + if(ReplaceOriginalFile(SourceFile_fullPath_Original,OutPutPath_Final)==false) + { + if(QAction_checkBox_MoveToRecycleBin_checkBox_DelOriginal->isChecked()) + { + file_MoveToTrash(SourceFile_fullPath_Original); + } + else + { + QFile::remove(SourceFile_fullPath_Original); + } + } + emit Send_Table_image_ChangeStatus_rowNumInt_statusQString(rowNum, "Finished, original file deleted"); + } + else + { + emit Send_Table_image_ChangeStatus_rowNumInt_statusQString(rowNum, "Finished"); + } + //========== 移动到输出路径 ========= + if(ui->checkBox_OutPath_isEnabled->isChecked()) + { + MoveFileToOutputPath(OutPutPath_Final,SourceFile_fullPath_Original); + } + //============================ 更新进度条 ================================= + emit Send_progressbar_Add(); + //=========================== 更新线程数量统计============================== + mutex_ThreadNumRunning.lock(); + ThreadNumRunning--; + mutex_ThreadNumRunning.unlock();//线程数量统计-1 + //======= + return 0; +} +/* +处理GIF +*/ +int MainWindow::Anime4k_GIF(int rowNum) +{ + //============================= 读取设置 ================================ + int ScaleRatio = ui->doubleSpinBox_ScaleRatio_gif->value(); + bool DelOriginal = (ui->checkBox_DelOriginal->isChecked()||ui->checkBox_ReplaceOriginalFile->isChecked()); + int Sub_gif_ThreadNumRunning = 0; + QString OutPutPath_Final =""; + //========================= 拆解map得到参数 ============================= + emit Send_Table_gif_ChangeStatus_rowNumInt_statusQString(rowNum, "Processing"); + QString SourceFile_fullPath = Table_model_gif->item(rowNum,2)->text(); + if(!QFile::exists(SourceFile_fullPath)) + { + emit Send_TextBrowser_NewMessage(tr("Error occured when processing [")+SourceFile_fullPath+tr("]. Error: [File does not exist.]")); + emit Send_Table_gif_ChangeStatus_rowNumInt_statusQString(rowNum, "Failed"); + emit Send_progressbar_Add(); + return 0; + } + //========================== + bool CustRes_isEnabled = false; + int CustRes_height=0; + int CustRes_width=0; + if(CustRes_isContained(SourceFile_fullPath)) + { + CustRes_isEnabled=true; + QMap Res_map = CustRes_getResMap(SourceFile_fullPath);//res_map["fullpath"],["height"],["width"] + CustRes_height=Res_map["height"].toInt(); + CustRes_width=Res_map["width"].toInt(); + } + //========================== + QFileInfo fileinfo(SourceFile_fullPath); + QString file_name = file_getBaseName(SourceFile_fullPath); + QString file_ext = fileinfo.suffix(); + QString file_path = file_getFolderPath(fileinfo); + QString ResGIFPath = file_path + "/" + file_name + "_waifu2x_"+QString::number(ScaleRatio, 10)+"x.gif"; + //=========================== 获取帧时间 ==================================== + int GIF_Duration = Gif_getDuration(SourceFile_fullPath); + if(GIF_Duration==0)//检查是否成功获取duration + { + emit Send_TextBrowser_NewMessage(tr("Error occured when processing [")+SourceFile_fullPath+tr("]. Error: [Can't get Duration value of GIF file.]")); + emit Send_Table_gif_ChangeStatus_rowNumInt_statusQString(rowNum, "Failed"); + //file_DelDir(SplitFramesFolderPath); + emit Send_progressbar_Add(); + return 0;//如果启用stop位,则直接return + } + //============================== 拆分 ========================================== + QString SplitFramesFolderPath = file_path+"/"+file_name+"_SplitFrames_W2xEX";//拆分后存储frame的文件夹 + Gif_splitGif(SourceFile_fullPath,SplitFramesFolderPath); + //============================== 扫描获取文件名 =============================== + QStringList Frame_fileName_list = file_getFileNames_in_Folder_nofilter(SplitFramesFolderPath); + if(Frame_fileName_list.isEmpty())//检查是否成功拆分gif + { + emit Send_TextBrowser_NewMessage(tr("Error occured when processing [")+SourceFile_fullPath+tr("]. Error: [Can't split GIF into frames.]")); + emit Send_Table_gif_ChangeStatus_rowNumInt_statusQString(rowNum, "Failed"); + file_DelDir(SplitFramesFolderPath); + emit Send_progressbar_Add(); + return 0;//如果启用stop位,则直接return + } + //===========建立存储放大后frame的文件夹=========== + QString ScaledFramesFolderPath = SplitFramesFolderPath+"/ScaledFrames_W2xEX"; + if(file_isDirExist(ScaledFramesFolderPath)) + { + file_DelDir(ScaledFramesFolderPath); + file_mkDir(ScaledFramesFolderPath); + } + else + { + file_mkDir(ScaledFramesFolderPath); + } + //=============================开始放大========================== + //启动进度条 + emit Send_CurrentFileProgress_Start(file_name+"."+file_ext,Frame_fileName_list.size()); + FileProgressWatch_isEnabled=true; + QFuture FileProgressWatch_QFuture = QtConcurrent::run(this, &MainWindow::CurrentFileProgress_WatchFolderFileNum, ScaledFramesFolderPath);//启动waifu2x 主线程 + if(ui->checkBox_ShowInterPro->isChecked()==false) + { + FileProgressWatch_isEnabled=false; + FileProgressWatch_QFuture.cancel(); + emit Send_CurrentFileProgress_Stop(); + } + //=======获取显卡信息======== + int NumOfGPU = 1; + if(ui->checkBox_SpecifyGPU_Anime4k->isChecked()==true) + { + NumOfGPU = Get_NumOfGPU_Anime4k(); + } + //============创建显卡文件夹=========== + QStringList GPU_SplitFramesFolderPath_List; + for(int i = 0; i < NumOfGPU; i++) + { + QString GPU_SplitFramesFolderPath = SplitFramesFolderPath+"/"+"GPU_"+QString::number(i); + if(file_isDirExist(GPU_SplitFramesFolderPath)) + { + file_DelDir(GPU_SplitFramesFolderPath); + file_mkDir(GPU_SplitFramesFolderPath); + } + else + { + file_mkDir(GPU_SplitFramesFolderPath); + } + GPU_SplitFramesFolderPath_List.append(GPU_SplitFramesFolderPath); + } + int TotalFramesNum = Frame_fileName_list.size(); + int FramesNumForEachGPU = TotalFramesNum/NumOfGPU; + if(FramesNumForEachGPU<1)FramesNumForEachGPU=1; + int start_num=0; + for(int x = 0; x < GPU_SplitFramesFolderPath_List.size(); x++) + { + if(x==GPU_SplitFramesFolderPath_List.size()-1)FramesNumForEachGPU=TotalFramesNum; + QStringList file_waitformove = Frame_fileName_list.mid(start_num,FramesNumForEachGPU); + for(int i = 0; i < file_waitformove.size(); i++) + { + QString FileName = file_waitformove.at(i); + QFile::rename(SplitFramesFolderPath+"/"+FileName,GPU_SplitFramesFolderPath_List.at(x)+"/"+FileName); + } + start_num+=FramesNumForEachGPU; + } + //=== + QMap Sub_Thread_info; + Sub_Thread_info["ScaledFramesFolderPath"]=ScaledFramesFolderPath; + if(CustRes_isEnabled == true) + { + Sub_Thread_info["ScaleRatio"] = QString("%1").arg(CustRes_CalNewScaleRatio(SourceFile_fullPath,CustRes_height,CustRes_width)); + } + else + { + Sub_Thread_info["ScaleRatio"] = QString("%1").arg(qRound(ui->doubleSpinBox_ScaleRatio_gif->value())); + } + //========================= + bool Frame_failed = false;//放大失败标志 + //========================= + for(int i = 0; i < GPU_SplitFramesFolderPath_List.size(); i++) + { + Sub_Thread_info["SplitFramesFolderPath"]=GPU_SplitFramesFolderPath_List.at(i); + mutex_SubThreadNumRunning.lock(); + Sub_gif_ThreadNumRunning++; + mutex_SubThreadNumRunning.unlock(); + QtConcurrent::run(this,&MainWindow::Anime4k_GIF_scale,Sub_Thread_info,&Sub_gif_ThreadNumRunning,&Frame_failed); + while (Sub_gif_ThreadNumRunning >= NumOfGPU) + { + Delay_msec_sleep(500); + } + if(waifu2x_STOP) + { + while (Sub_gif_ThreadNumRunning > 0) + { + Delay_msec_sleep(500); + } + FileProgressWatch_isEnabled=false; + FileProgressWatch_QFuture.cancel(); + file_DelDir(SplitFramesFolderPath); + emit Send_Table_gif_ChangeStatus_rowNumInt_statusQString(rowNum, "Interrupted"); + return 0;//如果启用stop位,则直接return + } + if(Frame_failed) + { + FileProgressWatch_isEnabled=false; + FileProgressWatch_QFuture.cancel(); + emit Send_TextBrowser_NewMessage(tr("Error occured when processing [")+SourceFile_fullPath+tr("]. Error: [Failed to scale frames.]")); + emit Send_Table_gif_ChangeStatus_rowNumInt_statusQString(rowNum, "Failed"); + file_DelDir(SplitFramesFolderPath); + emit Send_progressbar_Add(); + return 0;//如果启用stop位,则直接return + } + } + while (Sub_gif_ThreadNumRunning!=0) + { + Delay_msec_sleep(500); + } + FileProgressWatch_isEnabled=false; + FileProgressWatch_QFuture.cancel(); + emit Send_CurrentFileProgress_Stop(); + //======================= 检查是否成功放大所有帧 =========================== + QStringList Frame_fileName_list_scaled = file_getFileNames_in_Folder_nofilter(ScaledFramesFolderPath); + if(Frame_fileName_list.size()!=Frame_fileName_list_scaled.size()) + { + emit Send_TextBrowser_NewMessage(tr("Error occured when processing [")+SourceFile_fullPath+tr("]. Error: [Failed to scale frames.]")); + emit Send_Table_gif_ChangeStatus_rowNumInt_statusQString(rowNum, "Failed"); + file_DelDir(SplitFramesFolderPath); + emit Send_progressbar_Add(); + return 0;//如果启用stop位,则直接return + } + //======================================== 组装 ====================================================== + if(CustRes_isEnabled) + { + ResGIFPath = file_path + "/" + file_name + "_waifu2x_"+QString::number(CustRes_width, 10)+"x"+QString::number(CustRes_height,10)+".gif"; + } + //======================= + // 修改文件名,添加降噪等级 + //======================= + int denoiseLevel = ui->spinBox_DenoiseLevel_gif->value(); + if(denoiseLevel != -1) + { + QFileInfo fileinfo_tmp(ResGIFPath); + ResGIFPath = file_getFolderPath(fileinfo_tmp) + "/" + file_getBaseName(ResGIFPath) + "_"+QString::number(denoiseLevel, 10)+"n.gif"; + } + //====================== + Gif_assembleGif(ResGIFPath,ScaledFramesFolderPath,GIF_Duration,CustRes_isEnabled,CustRes_height,CustRes_width,false,""); + if(!QFile::exists(ResGIFPath)) + { + emit Send_TextBrowser_NewMessage(tr("Error occured when processing [")+SourceFile_fullPath+tr("]. Error: [Unable to assemble gif.]")); + emit Send_Table_gif_ChangeStatus_rowNumInt_statusQString(rowNum, "Failed"); + file_DelDir(SplitFramesFolderPath); + emit Send_progressbar_Add(); + return 0;//如果启用stop位,则直接return + } + OutPutPath_Final = ResGIFPath; + //======================================= 优化gif =================================================== + if(ui->checkBox_OptGIF->isChecked() == true) + { + QFileInfo fileinfo_tmp(OutPutPath_Final); + QString ResGIFPath_compressed = file_getFolderPath(fileinfo_tmp) + "/" + file_getBaseName(OutPutPath_Final) + "_opt.gif"; + OutPutPath_Final = Gif_compressGif(ResGIFPath,ResGIFPath_compressed); + } + //============================== 删除缓存文件 ==================================================== + file_DelDir(SplitFramesFolderPath); + //============================= 删除原文件 & & 更新table status ============================ + if(DelOriginal) + { + if(ReplaceOriginalFile(SourceFile_fullPath,OutPutPath_Final)==false) + { + if(QAction_checkBox_MoveToRecycleBin_checkBox_DelOriginal->isChecked()) + { + file_MoveToTrash(SourceFile_fullPath); + } + else + { + QFile::remove(SourceFile_fullPath); + } + } + emit Send_Table_gif_ChangeStatus_rowNumInt_statusQString(rowNum, "Finished, original file deleted"); + } + else + { + emit Send_Table_gif_ChangeStatus_rowNumInt_statusQString(rowNum, "Finished"); + } + //========== 移动到输出路径 ========= + if(ui->checkBox_OutPath_isEnabled->isChecked()) + { + MoveFileToOutputPath(OutPutPath_Final,SourceFile_fullPath); + } + //============================ 更新进度条 ================================= + emit Send_progressbar_Add(); + //=========================== ============================== + return 0; +} +/* +Anime4k GIF放大子线程 +放大,修改大小 +*/ +int MainWindow::Anime4k_GIF_scale(QMap Sub_Thread_info,int *Sub_gif_ThreadNumRunning,bool *Frame_failed) +{ + bool AllFinished=true; + QString SplitFramesFolderPath = Sub_Thread_info["SplitFramesFolderPath"]; + QString ScaledFramesFolderPath = Sub_Thread_info["ScaledFramesFolderPath"]; + //================== + // 生成输出文件列表 + //================== + QStringList OutPutFilesFullPathList; + do + { + QStringList InputFilesNameList = file_getFileNames_in_Folder_nofilter(SplitFramesFolderPath); + for(int i=0; ispinBox_retry->value()+ForceRetryCount); retry++) + { + Anime4k->start(CMD); + while(!Anime4k->waitForStarted(100)&&!QProcess_stop) {} + while(!Anime4k->waitForFinished(500)&&!QProcess_stop) + { + if(waifu2x_STOP) + { + Anime4k->close(); + mutex_SubThreadNumRunning.lock(); + *Sub_gif_ThreadNumRunning=*Sub_gif_ThreadNumRunning-1; + mutex_SubThreadNumRunning.unlock(); + return 0; + } + } + AllFinished = true; + for(int i=0; ispinBox_retry->value()+(ForceRetryCount-1))break; + Delay_sec_sleep(5); + emit Send_TextBrowser_NewMessage(tr("Automatic retry, please wait.")); + AllFinished=false; + break; + } + } + if(AllFinished == true)break; + } + //========= + AllFinished = true; + for(int i=0; idoubleSpinBox_ScaleRatio_video->value(); + bool DelOriginal = (ui->checkBox_DelOriginal->isChecked()||ui->checkBox_ReplaceOriginalFile->isChecked()); + bool isCacheExists = false; + bool isVideoConfigChanged = true; + int Sub_video_ThreadNumRunning = 0; + //========================= 拆解map得到参数 ============================= + emit Send_Table_video_ChangeStatus_rowNumInt_statusQString(rowNum, "Processing"); + QString SourceFile_fullPath = Table_model_video->item(rowNum,2)->text(); + if(!QFile::exists(SourceFile_fullPath)) + { + emit Send_TextBrowser_NewMessage(tr("Error occured when processing [")+SourceFile_fullPath+tr("]. Error: [File does not exist.]")); + emit Send_Table_video_ChangeStatus_rowNumInt_statusQString(rowNum, "Failed"); + emit Send_progressbar_Add(); + return 0; + } + //========================== + QFileInfo fileinfo(SourceFile_fullPath); + QString file_name = file_getBaseName(SourceFile_fullPath); + QString file_ext = fileinfo.suffix(); + QString file_path = file_getFolderPath(fileinfo); + //=================================================================== + //生成mp4 + QString video_mp4_fullpath=video_To_CFRMp4(SourceFile_fullPath); + if(!QFile::exists(video_mp4_fullpath))//检查是否成功生成mp4 + { + emit Send_TextBrowser_NewMessage(tr("Error occured when processing [")+SourceFile_fullPath+tr("]. Error: [Cannot convert video format to mp4.]")); + emit Send_Table_video_ChangeStatus_rowNumInt_statusQString(rowNum, "Failed"); + emit Send_progressbar_Add(); + return 0;//如果启用stop位,则直接return + } + QString AudioPath = file_path+"/Audio_"+file_name+"_"+file_ext+"_W2xEX.wav";//音频 + QString SplitFramesFolderPath = file_path+"/"+file_name+"_"+file_ext+"_SplitFrames_W2xEX";//拆分后存储frame的文件夹 + QString ScaledFramesFolderPath = SplitFramesFolderPath+"/ScaledFrames_W2xEX";//存储放大后的帧 + //========================== + // 读取自定义分辨率设定 + //========================== + bool CustRes_isEnabled = false; + int CustRes_height=0; + int CustRes_width=0; + if(CustRes_isContained(SourceFile_fullPath)) + { + CustRes_isEnabled=true; + QMap Res_map = CustRes_getResMap(SourceFile_fullPath);//res_map["fullpath"],["height"],["width"] + CustRes_height=Res_map["height"].toInt(); + CustRes_width=Res_map["width"].toInt(); + } + //========================== + // 检测之前的视频配置文件 + //========================== + QString VideoConfiguration_fullPath = file_path+"/VideoConfiguration_"+file_name+"_"+file_ext+"_Waifu2xEX.ini"; + if(QFile::exists(VideoConfiguration_fullPath)) + { + QSettings *configIniRead = new QSettings(VideoConfiguration_fullPath, QSettings::IniFormat); + configIniRead->setIniCodec(QTextCodec::codecForName("UTF-8")); + //=================== 加载之前存储的视频信息 ========================= + int ScaleRatio_old = configIniRead->value("/VideoConfiguration/ScaleRatio").toInt(); + bool CustRes_isEnabled_old = configIniRead->value("/VideoConfiguration/CustRes_isEnabled").toBool(); + int CustRes_height_old = configIniRead->value("/VideoConfiguration/CustRes_height").toInt(); + int CustRes_width_old = configIniRead->value("/VideoConfiguration/CustRes_width").toInt(); + QString EngineName_old = configIniRead->value("/VideoConfiguration/EngineName").toString(); + bool isProcessBySegment_old = configIniRead->value("/VideoConfiguration/isProcessBySegment").toBool(); + //=================== 比对信息 ================================ + if(EngineName_old=="anime4k") + { + if(CustRes_isEnabled_old==false&&CustRes_isEnabled==false) + { + if(ScaleRatio_old!=ScaleRatio) + { + isVideoConfigChanged=true; + } + else + { + isVideoConfigChanged=false; + } + } + else + { + if(CustRes_isEnabled_old==true&&CustRes_isEnabled==true) + { + if(CustRes_height_old!=CustRes_height||CustRes_width_old!=CustRes_width) + { + isVideoConfigChanged=true; + } + else + { + isVideoConfigChanged=false; + } + } + else + { + isVideoConfigChanged=true; + } + } + if(isProcessBySegment_old==true) + { + isVideoConfigChanged=true; + } + } + else + { + isVideoConfigChanged=true; + } + } + else + { + emit Send_video_write_VideoConfiguration(VideoConfiguration_fullPath,ScaleRatio,0,CustRes_isEnabled,CustRes_height,CustRes_width,"anime4k",false,"","",ui->groupBox_FrameInterpolation->isChecked(),0); + } + //======================= + // 检测缓存是否存在 + //======================= + if(QFile::exists(video_mp4_fullpath)&&file_isDirExist(SplitFramesFolderPath)&&file_isDirExist(ScaledFramesFolderPath)&&QFile::exists(VideoConfiguration_fullPath)) + { + if(!isVideoConfigChanged) + { + isCacheExists=true; + emit Send_TextBrowser_NewMessage(tr("The previous video cache file is detected and processing of the previous video cache will continue. If you want to restart processing of the current video:[")+SourceFile_fullPath+tr("], delete the cache manually.")); + } + else + { + isCacheExists=false; + //======== + QFile::remove(VideoConfiguration_fullPath); + file_DelDir(SplitFramesFolderPath); + QFile::remove(AudioPath); + DelVfiDir(video_mp4_fullpath); + emit Send_video_write_VideoConfiguration(VideoConfiguration_fullPath,ScaleRatio,0,CustRes_isEnabled,CustRes_height,CustRes_width,"anime4k",false,"","",ui->groupBox_FrameInterpolation->isChecked(),0); + //======= + emit Send_TextBrowser_NewMessage(tr("The previous video cache file was detected, but because you changed the settings about the video resolution, the previous cache will be deleted and processing of the video:[")+SourceFile_fullPath+tr("] will restart.")); + } + } + else + { + isCacheExists=false; + //======== + QFile::remove(VideoConfiguration_fullPath); + file_DelDir(SplitFramesFolderPath); + QFile::remove(AudioPath); + DelVfiDir(video_mp4_fullpath); + emit Send_video_write_VideoConfiguration(VideoConfiguration_fullPath,ScaleRatio,0,CustRes_isEnabled,CustRes_height,CustRes_width,"anime4k",false,"","",ui->groupBox_FrameInterpolation->isChecked(),0); + //======== + } + //========================================== + // 拆分(正常) + //========================================== + if(!isCacheExists) + { + if(file_isDirExist(SplitFramesFolderPath)) + { + file_DelDir(SplitFramesFolderPath); + file_mkDir(SplitFramesFolderPath); + } + else + { + file_mkDir(SplitFramesFolderPath); + } + QFile::remove(AudioPath); + video_video2images(video_mp4_fullpath,SplitFramesFolderPath,AudioPath); + if(waifu2x_STOP) + { + emit Send_Table_video_ChangeStatus_rowNumInt_statusQString(rowNum, "Interrupted"); + return 0;//如果启用stop位,则直接return + } + } + //============================== 扫描获取文件名 =============================== + QStringList Frame_fileName_list = file_getFileNames_in_Folder_nofilter(SplitFramesFolderPath); + if(!isCacheExists) + { + if(Frame_fileName_list.isEmpty())//检查是否成功拆分为帧 + { + emit Send_TextBrowser_NewMessage(tr("Error occured when processing [")+SourceFile_fullPath+tr("]. Error: [Unable to split video into pictures.]")); + emit Send_Table_video_ChangeStatus_rowNumInt_statusQString(rowNum, "Failed"); + emit Send_progressbar_Add(); + return 0;//如果启用stop位,则直接return + } + } + //============================== 放大 ======================================= + //===========建立存储放大后frame的文件夹=========== + if(!isCacheExists) + { + if(file_isDirExist(ScaledFramesFolderPath)) + { + file_DelDir(ScaledFramesFolderPath); + file_mkDir(ScaledFramesFolderPath); + } + else + { + file_mkDir(ScaledFramesFolderPath); + } + } + //==========开始放大========================== + emit Send_CurrentFileProgress_Start(file_name+"."+file_ext,(Frame_fileName_list.size()+file_getFileNames_in_Folder_nofilter(ScaledFramesFolderPath).size())); + FileProgressWatch_isEnabled=true; + QFuture FileProgressWatch_QFuture = QtConcurrent::run(this, &MainWindow::CurrentFileProgress_WatchFolderFileNum, ScaledFramesFolderPath);//启动waifu2x 主线程 + if(ui->checkBox_ShowInterPro->isChecked()==false) + { + FileProgressWatch_isEnabled=false; + FileProgressWatch_QFuture.cancel(); + emit Send_CurrentFileProgress_Stop(); + } + //=======获取显卡信息======== + int NumOfGPU = 1; + if(ui->checkBox_SpecifyGPU_Anime4k->isChecked()==true) + { + NumOfGPU = Get_NumOfGPU_Anime4k(); + } + //============创建显卡文件夹=========== + QStringList GPU_SplitFramesFolderPath_List; + for(int i = 0; i < NumOfGPU; i++) + { + QString GPU_SplitFramesFolderPath = SplitFramesFolderPath+"/"+"GPU_"+QString::number(i); + if(file_isDirExist(GPU_SplitFramesFolderPath)==false) + { + file_DelDir(GPU_SplitFramesFolderPath); + file_mkDir(GPU_SplitFramesFolderPath); + } + else + { + file_mkDir(GPU_SplitFramesFolderPath); + } + GPU_SplitFramesFolderPath_List.append(GPU_SplitFramesFolderPath); + } + int TotalFramesNum = Frame_fileName_list.size(); + int FramesNumForEachGPU = TotalFramesNum/NumOfGPU; + if(FramesNumForEachGPU<1)FramesNumForEachGPU=1; + int start_num=0; + for(int x = 0; x < GPU_SplitFramesFolderPath_List.size(); x++) + { + if(x==GPU_SplitFramesFolderPath_List.size()-1)FramesNumForEachGPU=TotalFramesNum; + QStringList file_waitformove = Frame_fileName_list.mid(start_num,FramesNumForEachGPU); + for(int i = 0; i < file_waitformove.size(); i++) + { + QString FileName = file_waitformove.at(i); + QFile::rename(SplitFramesFolderPath+"/"+FileName,GPU_SplitFramesFolderPath_List.at(x)+"/"+FileName); + } + start_num+=FramesNumForEachGPU; + } + //========================= + bool Frame_failed = false;//放大失败标志 + QMap Sub_Thread_info; + Sub_Thread_info["ScaledFramesFolderPath"]=ScaledFramesFolderPath; + if(CustRes_isEnabled == true) + { + Sub_Thread_info["ScaleRatio"] = QString("%1").arg(CustRes_CalNewScaleRatio(video_mp4_fullpath,CustRes_height,CustRes_width)); + } + else + { + Sub_Thread_info["ScaleRatio"] = QString("%1").arg(ScaleRatio); + } + //========================= + for(int i = 0; i < GPU_SplitFramesFolderPath_List.size(); i++) + { + Sub_Thread_info["SplitFramesFolderPath"]=GPU_SplitFramesFolderPath_List.at(i); + mutex_SubThreadNumRunning.lock(); + Sub_video_ThreadNumRunning++; + mutex_SubThreadNumRunning.unlock(); + QtConcurrent::run(this,&MainWindow::Anime4k_Video_scale,Sub_Thread_info,&Sub_video_ThreadNumRunning,&Frame_failed); + while (Sub_video_ThreadNumRunning >= NumOfGPU) + { + Delay_msec_sleep(500); + } + if(waifu2x_STOP) + { + while (Sub_video_ThreadNumRunning > 0) + { + Delay_msec_sleep(500); + } + FileProgressWatch_isEnabled=false; + FileProgressWatch_QFuture.cancel(); + Restore_SplitFramesFolderPath(SplitFramesFolderPath,GPU_SplitFramesFolderPath_List); + emit Send_Table_video_ChangeStatus_rowNumInt_statusQString(rowNum, "Interrupted"); + return 0;//如果启用stop位,则直接return + } + if(Frame_failed) + { + FileProgressWatch_isEnabled=false; + FileProgressWatch_QFuture.cancel(); + Restore_SplitFramesFolderPath(SplitFramesFolderPath,GPU_SplitFramesFolderPath_List); + emit Send_TextBrowser_NewMessage(tr("Error occured when processing [")+SourceFile_fullPath+tr("]. Error: [Failed to scale frames.]")); + emit Send_Table_video_ChangeStatus_rowNumInt_statusQString(rowNum, "Failed"); + emit Send_progressbar_Add(); + return 0;//如果启用stop位,则直接return + } + } + while (Sub_video_ThreadNumRunning!=0) + { + Delay_msec_sleep(500); + } + FileProgressWatch_isEnabled=false; + FileProgressWatch_QFuture.cancel(); + emit Send_CurrentFileProgress_Stop(); + //================ 扫描放大后的帧文件数量,判断是否放大成功 ======================= + QStringList Frame_fileName_list_scaled = file_getFileNames_in_Folder_nofilter(ScaledFramesFolderPath); + if(Frame_fileName_list_scaled.size()spinBox_DenoiseLevel_video->value(); + if(denoiseLevel != -1) + { + denoiseLevel_inName_str = QString::number(denoiseLevel,10)+"n_"; + } + //生成最终视频文件名 + QString video_mp4_scaled_fullpath = ""; + if(CustRes_isEnabled == true) + { + video_mp4_scaled_fullpath = file_path+"/"+file_name+"_waifu2x_"+QString::number(CustRes_width,10)+"x"+QString::number(CustRes_height,10)+"_"+denoiseLevel_inName_str+file_ext+".mp4"; + } + else + { + video_mp4_scaled_fullpath = file_path+"/"+file_name+"_waifu2x_"+QString::number(ScaleRatio,10)+"x_"+denoiseLevel_inName_str+file_ext+".mp4"; + } + video_images2video(video_mp4_fullpath,video_mp4_scaled_fullpath,ScaledFramesFolderPath,AudioPath,CustRes_isEnabled,CustRes_height,CustRes_width,false); + if(QFile::exists(video_mp4_scaled_fullpath)==false)//检查是否成功成功生成视频 + { + if(waifu2x_STOP) + { + emit Send_Table_video_ChangeStatus_rowNumInt_statusQString(rowNum, "Interrupted"); + return 0;//如果启用stop位,则直接return + } + emit Send_TextBrowser_NewMessage(tr("Error occured when processing [")+SourceFile_fullPath+tr("]. Error: [Unable to assemble pictures into videos.]")); + emit Send_Table_video_ChangeStatus_rowNumInt_statusQString(rowNum, "Failed"); + emit Send_progressbar_Add(); + return 0;//如果启用stop位,则直接return + } + //============================== 删除缓存文件 ==================================================== + if(ui->checkBox_KeepVideoCache->isChecked()==false) + { + QFile::remove(VideoConfiguration_fullPath); + file_DelDir(SplitFramesFolderPath); + QFile::remove(AudioPath); + if(SourceFile_fullPath!=video_mp4_fullpath)QFile::remove(video_mp4_fullpath); + } + else + { + DelOriginal=false; + } + //============================= 删除原文件 & & 更新table status ============================ + if(DelOriginal) + { + if(ReplaceOriginalFile(SourceFile_fullPath,video_mp4_scaled_fullpath)==false) + { + if(QAction_checkBox_MoveToRecycleBin_checkBox_DelOriginal->isChecked()) + { + file_MoveToTrash(SourceFile_fullPath); + } + else + { + QFile::remove(SourceFile_fullPath); + } + } + emit Send_Table_video_ChangeStatus_rowNumInt_statusQString(rowNum, "Finished, original file deleted"); + } + else + { + emit Send_Table_video_ChangeStatus_rowNumInt_statusQString(rowNum, "Finished"); + } + //========== 移动到输出路径 ========= + if(ui->checkBox_OutPath_isEnabled->isChecked()) + { + MoveFileToOutputPath(video_mp4_scaled_fullpath,SourceFile_fullPath); + } + //============================ 更新进度条 ================================= + emit Send_progressbar_Add(); + //=========================== ============================== + return 0; +} +/* +#### 分段处理 #### +调用Anime4k处理视频 +读取设置,拆分,创建放大子线程,组装视频 +*/ +int MainWindow::Anime4k_Video_BySegment(int rowNum) +{ + //============================= 读取设置 ================================ + int ScaleRatio = ui->doubleSpinBox_ScaleRatio_video->value(); + bool DelOriginal = (ui->checkBox_DelOriginal->isChecked()||ui->checkBox_ReplaceOriginalFile->isChecked()); + bool isCacheExists = false; + bool isVideoConfigChanged = true; + int Sub_video_ThreadNumRunning = 0; + int SegmentDuration = ui->spinBox_SegmentDuration->value(); + //========================= 拆解map得到参数 ============================= + emit Send_Table_video_ChangeStatus_rowNumInt_statusQString(rowNum, "Processing"); + QString SourceFile_fullPath = Table_model_video->item(rowNum,2)->text(); + if(!QFile::exists(SourceFile_fullPath)) + { + emit Send_TextBrowser_NewMessage(tr("Error occured when processing [")+SourceFile_fullPath+tr("]. Error: [File does not exist.]")); + emit Send_Table_video_ChangeStatus_rowNumInt_statusQString(rowNum, "Failed"); + emit Send_progressbar_Add(); + return 0; + } + //========================== + QFileInfo fileinfo(SourceFile_fullPath); + QString file_name = file_getBaseName(SourceFile_fullPath); + QString file_ext = fileinfo.suffix(); + QString file_path = file_getFolderPath(fileinfo); + //=================================================================== + //生成mp4 + QString video_mp4_fullpath=video_To_CFRMp4(SourceFile_fullPath); + if(!QFile::exists(video_mp4_fullpath))//检查是否成功生成mp4 + { + emit Send_TextBrowser_NewMessage(tr("Error occured when processing [")+SourceFile_fullPath+tr("]. Error: [Cannot convert video format to mp4.]")); + emit Send_Table_video_ChangeStatus_rowNumInt_statusQString(rowNum, "Failed"); + emit Send_progressbar_Add(); + return 0;//如果启用stop位,则直接return + } + //============= 读取自定义分辨率 ============= + bool CustRes_isEnabled = false; + int CustRes_height=0; + int CustRes_width=0; + if(CustRes_isContained(SourceFile_fullPath)) + { + CustRes_isEnabled=true; + QMap Res_map = CustRes_getResMap(SourceFile_fullPath);//res_map["fullpath"],["height"],["width"] + CustRes_height=Res_map["height"].toInt(); + CustRes_width=Res_map["width"].toInt(); + } + //================= + QString AudioPath = file_path+"/Audio_"+file_name+"_"+file_ext+"_W2xEX.wav";//音频 + QString SplitFramesFolderPath = file_path+"/"+file_name+"_"+file_ext+"_SplitFrames_W2xEX";//拆分后存储frame的文件夹 + QString ScaledFramesFolderPath = SplitFramesFolderPath+"/ScaledFrames_W2xEX";//存储放大后的帧 + //=== + QString VideoClipsFolderPath = "";//存储视频片段的文件夹(完整路径) + QString DateStr = ""; + do + { + DateStr = video_getClipsFolderNo(); + VideoClipsFolderPath = file_path+"/"+DateStr+"_VideoClipsWaifu2xEX";//存储视频片段的文件夹(完整路径) + } + while(file_isDirExist(VideoClipsFolderPath)); + QString VideoClipsFolderName = DateStr+"_VideoClipsWaifu2xEX";//存储视频片段的文件夹(名称) + //========================== + // 检测之前的视频配置文件 + //========================== + QString VideoConfiguration_fullPath = file_path+"/VideoConfiguration_"+file_name+"_"+file_ext+"_Waifu2xEX.ini"; + if(QFile::exists(VideoConfiguration_fullPath)) + { + QSettings *configIniRead = new QSettings(VideoConfiguration_fullPath, QSettings::IniFormat); + configIniRead->setIniCodec(QTextCodec::codecForName("UTF-8")); + //=================== 加载之前存储的视频信息 ========================= + int ScaleRatio_old = configIniRead->value("/VideoConfiguration/ScaleRatio").toInt(); + bool CustRes_isEnabled_old = configIniRead->value("/VideoConfiguration/CustRes_isEnabled").toBool(); + int CustRes_height_old = configIniRead->value("/VideoConfiguration/CustRes_height").toInt(); + int CustRes_width_old = configIniRead->value("/VideoConfiguration/CustRes_width").toInt(); + QString EngineName_old = configIniRead->value("/VideoConfiguration/EngineName").toString(); + bool isProcessBySegment_old = configIniRead->value("/VideoConfiguration/isProcessBySegment").toBool(); + bool isVideoFrameInterpolationEnabled_old = configIniRead->value("/VideoConfiguration/isVideoFrameInterpolationEnabled").toBool(); + int MultipleOfFPS_old = configIniRead->value("/VideoConfiguration/MultipleOfFPS").toInt(); + //=================== 比对信息 ================================ + if(EngineName_old=="anime4k") + { + if(CustRes_isEnabled_old==false&&CustRes_isEnabled==false) + { + if(ScaleRatio_old!=ScaleRatio) + { + isVideoConfigChanged=true; + } + else + { + isVideoConfigChanged=false; + } + } + else + { + if(CustRes_isEnabled_old==true&&CustRes_isEnabled==true) + { + if(CustRes_height_old!=CustRes_height||CustRes_width_old!=CustRes_width) + { + isVideoConfigChanged=true; + } + else + { + isVideoConfigChanged=false; + } + } + else + { + isVideoConfigChanged=true; + } + } + if(isProcessBySegment_old == false) + { + isVideoConfigChanged=true; + } + if(isVideoFrameInterpolationEnabled_old != ui->groupBox_FrameInterpolation->isChecked()) + { + isVideoConfigChanged=true; + } + if(MultipleOfFPS_old != ui->spinBox_MultipleOfFPS_VFI->value() && ui->groupBox_FrameInterpolation->isChecked()) + { + isVideoConfigChanged=true; + } + } + else + { + isVideoConfigChanged=true; + } + //============ 修正文件夹名称 ============= + QString VideoClipsFolderPath_old = configIniRead->value("/VideoConfiguration/VideoClipsFolderPath").toString(); + QString VideoClipsFolderName_old = configIniRead->value("/VideoConfiguration/VideoClipsFolderName").toString(); + file_mkDir(VideoClipsFolderPath_old); + if(file_isDirExist(VideoClipsFolderPath_old)==true) + { + VideoClipsFolderPath = VideoClipsFolderPath_old; + VideoClipsFolderName = VideoClipsFolderName_old; + } + } + else + { + emit Send_video_write_VideoConfiguration(VideoConfiguration_fullPath,ScaleRatio,0,CustRes_isEnabled,CustRes_height,CustRes_width,"anime4k",true,VideoClipsFolderPath,VideoClipsFolderName,ui->groupBox_FrameInterpolation->isChecked(),ui->spinBox_MultipleOfFPS_VFI->value()); + } + //======================= + // 检测缓存是否存在 + //======================= + if(file_isDirExist(SplitFramesFolderPath)) + { + if(!isVideoConfigChanged) + { + isCacheExists=true; + emit Send_TextBrowser_NewMessage(tr("The previous video cache file is detected and processing of the previous video cache will continue. If you want to restart processing of the current video:[")+SourceFile_fullPath+tr("], delete the cache manually.")); + } + else + { + isCacheExists=false; + //======== + QFile::remove(VideoConfiguration_fullPath); + file_DelDir(SplitFramesFolderPath); + file_DelDir(VideoClipsFolderPath); + QFile::remove(AudioPath); + DelVfiDir(video_mp4_fullpath); + emit Send_video_write_VideoConfiguration(VideoConfiguration_fullPath,ScaleRatio,0,CustRes_isEnabled,CustRes_height,CustRes_width,"anime4k",true,VideoClipsFolderPath,VideoClipsFolderName,ui->groupBox_FrameInterpolation->isChecked(),ui->spinBox_MultipleOfFPS_VFI->value()); + //======= + emit Send_TextBrowser_NewMessage(tr("The previous video cache file was detected, but because you changed the settings about the video resolution, the previous cache will be deleted and processing of the video:[")+SourceFile_fullPath+tr("] will restart.")); + } + } + else + { + isCacheExists=false; + //======== + QFile::remove(VideoConfiguration_fullPath); + file_DelDir(SplitFramesFolderPath); + file_DelDir(VideoClipsFolderPath); + QFile::remove(AudioPath); + DelVfiDir(video_mp4_fullpath); + emit Send_video_write_VideoConfiguration(VideoConfiguration_fullPath,ScaleRatio,0,CustRes_isEnabled,CustRes_height,CustRes_width,"anime4k",true,VideoClipsFolderPath,VideoClipsFolderName,ui->groupBox_FrameInterpolation->isChecked(),ui->spinBox_MultipleOfFPS_VFI->value()); + //======== + } + /*==================================== + 提取音频 + ======================================*/ + if(!QFile::exists(AudioPath)) + { + video_get_audio(video_mp4_fullpath,AudioPath); + } + //================================== 开始分段处理视频 ================================================= + int StartTime = 0;//起始时间(秒) + int VideoDuration = video_get_duration(video_mp4_fullpath); + bool isSplitComplete = false; + bool isScaleComplete = false; + /* + ============================================ + 开始之前先读取进度 + ============================================ + */ + int OLD_SegmentDuration=-1; + bool read_OLD_SegmentDuration =false; + int LastVideoClipNo = -1; + if(QFile::exists(VideoConfiguration_fullPath)) + { + QSettings *configIniRead = new QSettings(VideoConfiguration_fullPath, QSettings::IniFormat); + configIniRead->setIniCodec(QTextCodec::codecForName("UTF-8")); + //=================== 加载进度 ========================= + StartTime = configIniRead->value("/Progress/StartTime").toInt(); + isSplitComplete = configIniRead->value("/Progress/isSplitComplete").toBool(); + isScaleComplete = configIniRead->value("/Progress/isScaleComplete").toBool(); + OLD_SegmentDuration = configIniRead->value("/Progress/OLDSegmentDuration").toInt(); + LastVideoClipNo = configIniRead->value("/Progress/LastVideoClipNo").toInt(); + } + if(OLD_SegmentDuration>0) + { + read_OLD_SegmentDuration = true; + } + /* + 加载进度条 + */ + int SegmentDuration_tmp_progressbar = 0; + if(read_OLD_SegmentDuration) + { + SegmentDuration_tmp_progressbar = OLD_SegmentDuration; + } + else + { + SegmentDuration_tmp_progressbar = SegmentDuration; + } + if(ui->checkBox_ShowInterPro->isChecked()&&VideoDuration>SegmentDuration_tmp_progressbar) + { + emit Send_CurrentFileProgress_Start(file_name+"."+file_ext,VideoDuration); + if(StartTime>0) + { + emit Send_CurrentFileProgress_progressbar_Add_SegmentDuration(StartTime); + } + } + /* + ============================================ + 正式开始处理 + ============================================ + */ + int SegmentDuration_tmp=0; + int TimeLeft_tmp=0; + while(VideoDuration>StartTime) + { + /*========================== + 计算视频片段时间 + ==========================*/ + TimeLeft_tmp = VideoDuration-StartTime; + if((TimeLeft_tmp)>=SegmentDuration) + { + SegmentDuration_tmp = SegmentDuration; + } + else + { + SegmentDuration_tmp = TimeLeft_tmp; + } + if(read_OLD_SegmentDuration) + { + SegmentDuration_tmp = OLD_SegmentDuration; + read_OLD_SegmentDuration=false; + } + /*========================== + 拆分视频片段 + ==========================*/ + if(isSplitComplete==false) + { + if(file_isDirExist(SplitFramesFolderPath)) + { + file_DelDir(SplitFramesFolderPath); + file_mkDir(SplitFramesFolderPath); + } + else + { + file_mkDir(SplitFramesFolderPath); + } + video_video2images_ProcessBySegment(video_mp4_fullpath,SplitFramesFolderPath,StartTime,SegmentDuration_tmp); + if(waifu2x_STOP) + { + emit Send_Table_video_ChangeStatus_rowNumInt_statusQString(rowNum, "Interrupted"); + return 0;//如果启用stop位,则直接return + } + } + /*========================== + 处理视频片段的帧 + ==========================*/ + if(isScaleComplete==false) + { + //============================== 扫描获取文件名 =============================== + QStringList Frame_fileName_list = file_getFileNames_in_Folder_nofilter(SplitFramesFolderPath); + if(isSplitComplete==false) + { + if(Frame_fileName_list.isEmpty())//检查是否成功拆分为帧 + { + emit Send_TextBrowser_NewMessage(tr("Error occured when processing [")+SourceFile_fullPath+tr("]. Error: [Unable to split video into pictures.]")); + emit Send_Table_video_ChangeStatus_rowNumInt_statusQString(rowNum, "Failed"); + emit Send_progressbar_Add(); + return 0;//如果启用stop位,则直接return + } + } + /* + 记录进度 + 帧拆分成功 + */ + emit Send_video_write_Progress_ProcessBySegment(VideoConfiguration_fullPath,StartTime,true,false,SegmentDuration_tmp,LastVideoClipNo); + //============================== 放大 ======================================= + //===========建立存储放大后frame的文件夹=========== + if(isSplitComplete==false) + { + if(file_isDirExist(ScaledFramesFolderPath)) + { + file_DelDir(ScaledFramesFolderPath); + file_mkDir(ScaledFramesFolderPath); + } + else + { + file_mkDir(ScaledFramesFolderPath); + } + } + //==========开始放大========================== + FileProgressWatch_isEnabled=true; + QFuture FileProgressWatch_QFuture = QtConcurrent::run(this, &MainWindow::CurrentFileProgress_WatchFolderFileNum_Textbrower, SourceFile_fullPath,ScaledFramesFolderPath,Frame_fileName_list.size()+file_getFileNames_in_Folder_nofilter(ScaledFramesFolderPath).size()); + if(ui->checkBox_ShowInterPro->isChecked()==false) + { + FileProgressWatch_isEnabled=false; + FileProgressWatch_QFuture.cancel(); + } + //=======获取显卡信息======== + int NumOfGPU = 1; + if(ui->checkBox_SpecifyGPU_Anime4k->isChecked()==true) + { + NumOfGPU = Get_NumOfGPU_Anime4k(); + } + //============创建显卡文件夹=========== + QStringList GPU_SplitFramesFolderPath_List; + for(int i = 0; i < NumOfGPU; i++) + { + QString GPU_SplitFramesFolderPath = SplitFramesFolderPath+"/"+"GPU_"+QString::number(i); + if(file_isDirExist(GPU_SplitFramesFolderPath)==false) + { + file_DelDir(GPU_SplitFramesFolderPath); + file_mkDir(GPU_SplitFramesFolderPath); + } + else + { + file_mkDir(GPU_SplitFramesFolderPath); + } + GPU_SplitFramesFolderPath_List.append(GPU_SplitFramesFolderPath); + } + int TotalFramesNum = Frame_fileName_list.size(); + int FramesNumForEachGPU = TotalFramesNum/NumOfGPU; + if(FramesNumForEachGPU<1)FramesNumForEachGPU=1; + int start_num=0; + for(int x = 0; x < GPU_SplitFramesFolderPath_List.size(); x++) + { + if(x==GPU_SplitFramesFolderPath_List.size()-1)FramesNumForEachGPU=TotalFramesNum; + QStringList file_waitformove = Frame_fileName_list.mid(start_num,FramesNumForEachGPU); + for(int i = 0; i < file_waitformove.size(); i++) + { + QString FileName = file_waitformove.at(i); + QFile::rename(SplitFramesFolderPath+"/"+FileName,GPU_SplitFramesFolderPath_List.at(x)+"/"+FileName); + } + start_num+=FramesNumForEachGPU; + } + //========================= + bool Frame_failed = false;//放大失败标志 + QMap Sub_Thread_info; + Sub_Thread_info["ScaledFramesFolderPath"]=ScaledFramesFolderPath; + if(CustRes_isEnabled == true) + { + Sub_Thread_info["ScaleRatio"] = QString("%1").arg(CustRes_CalNewScaleRatio(video_mp4_fullpath,CustRes_height,CustRes_width)); + } + else + { + Sub_Thread_info["ScaleRatio"] = QString("%1").arg(ScaleRatio); + } + //========================= + for(int i = 0; i < GPU_SplitFramesFolderPath_List.size(); i++) + { + Sub_Thread_info["SplitFramesFolderPath"]=GPU_SplitFramesFolderPath_List.at(i); + mutex_SubThreadNumRunning.lock(); + Sub_video_ThreadNumRunning++; + mutex_SubThreadNumRunning.unlock(); + QtConcurrent::run(this,&MainWindow::Anime4k_Video_scale,Sub_Thread_info,&Sub_video_ThreadNumRunning,&Frame_failed); + while (Sub_video_ThreadNumRunning >= NumOfGPU) + { + Delay_msec_sleep(500); + } + if(waifu2x_STOP) + { + while (Sub_video_ThreadNumRunning > 0) + { + Delay_msec_sleep(500); + } + FileProgressWatch_isEnabled=false; + FileProgressWatch_QFuture.cancel(); + Restore_SplitFramesFolderPath(SplitFramesFolderPath,GPU_SplitFramesFolderPath_List); + emit Send_Table_video_ChangeStatus_rowNumInt_statusQString(rowNum, "Interrupted"); + return 0;//如果启用stop位,则直接return + } + if(Frame_failed) + { + FileProgressWatch_isEnabled=false; + FileProgressWatch_QFuture.cancel(); + Restore_SplitFramesFolderPath(SplitFramesFolderPath,GPU_SplitFramesFolderPath_List); + emit Send_TextBrowser_NewMessage(tr("Error occured when processing [")+SourceFile_fullPath+tr("]. Error: [Failed to scale frames.]")); + emit Send_Table_video_ChangeStatus_rowNumInt_statusQString(rowNum, "Failed"); + emit Send_progressbar_Add(); + return 0;//如果启用stop位,则直接return + } + } + while (Sub_video_ThreadNumRunning!=0) + { + Delay_msec_sleep(500); + } + FileProgressWatch_isEnabled=false; + FileProgressWatch_QFuture.cancel(); + //================ 扫描放大后的帧文件数量,判断是否放大成功 ======================= + QStringList Frame_fileName_list_scaled = file_getFileNames_in_Folder_nofilter(ScaledFramesFolderPath); + if(Frame_fileName_list_scaled.size()checkBox_ShowInterPro->isChecked()) + { + emit Send_CurrentFileProgress_progressbar_Add_SegmentDuration(SegmentDuration_tmp); + } + StartTime+=SegmentDuration_tmp; + isSplitComplete = false; + isScaleComplete = false; + LastVideoClipNo=VideoClipNo; + emit Send_video_write_Progress_ProcessBySegment(VideoConfiguration_fullPath,StartTime,false,false,-1,VideoClipNo); + } + emit Send_CurrentFileProgress_Stop(); + //====================================================== + // 组装(片段到成片) + //====================================================== + //确定是否插入降噪值 + QString denoiseLevel_inName_str = ""; + int denoiseLevel = ui->spinBox_DenoiseLevel_video->value(); + if(denoiseLevel != -1) + { + denoiseLevel_inName_str = QString::number(denoiseLevel,10)+"n_"; + } + //生成最终视频名称 + QString video_mp4_scaled_fullpath = ""; + if(CustRes_isEnabled) + { + video_mp4_scaled_fullpath = file_path+"/"+file_name+"_waifu2x_"+QString::number(CustRes_width,10)+"x"+QString::number(CustRes_height,10)+"_"+denoiseLevel_inName_str+file_ext+".mp4"; + } + else + { + video_mp4_scaled_fullpath = file_path+"/"+file_name+"_waifu2x_"+QString::number(ScaleRatio,10)+"x_"+denoiseLevel_inName_str+file_ext+".mp4"; + } + QFile::remove(video_mp4_scaled_fullpath); + video_AssembleVideoClips(VideoClipsFolderPath,VideoClipsFolderName,video_mp4_scaled_fullpath,AudioPath); + if(QFile::exists(video_mp4_scaled_fullpath)==false)//检查是否成功生成视频 + { + if(waifu2x_STOP) + { + emit Send_Table_video_ChangeStatus_rowNumInt_statusQString(rowNum, "Interrupted"); + return 0;//如果启用stop位,则直接return + } + emit Send_TextBrowser_NewMessage(tr("Error occured when processing [")+SourceFile_fullPath+tr("]. Error: [Unable to assemble video clips.]")); + emit Send_Table_video_ChangeStatus_rowNumInt_statusQString(rowNum, "Failed"); + emit Send_progressbar_Add(); + return 0;//如果启用stop位,则直接return + } + //============================== 删除缓存文件 ==================================================== + if(ui->checkBox_KeepVideoCache->isChecked()==false) + { + QFile::remove(VideoConfiguration_fullPath); + file_DelDir(SplitFramesFolderPath); + file_DelDir(VideoClipsFolderPath); + QFile::remove(AudioPath); + if(SourceFile_fullPath!=video_mp4_fullpath)QFile::remove(video_mp4_fullpath); + } + else + { + DelOriginal=false; + } + //============================= 删除原文件 & & 更新table status ============================ + if(DelOriginal) + { + if(ReplaceOriginalFile(SourceFile_fullPath,video_mp4_scaled_fullpath)==false) + { + if(QAction_checkBox_MoveToRecycleBin_checkBox_DelOriginal->isChecked()) + { + file_MoveToTrash(SourceFile_fullPath); + } + else + { + QFile::remove(SourceFile_fullPath); + } + } + emit Send_Table_video_ChangeStatus_rowNumInt_statusQString(rowNum, "Finished, original file deleted"); + } + else + { + emit Send_Table_video_ChangeStatus_rowNumInt_statusQString(rowNum, "Finished"); + } + //========== 移动到输出路径 ========= + if(ui->checkBox_OutPath_isEnabled->isChecked()) + { + MoveFileToOutputPath(video_mp4_scaled_fullpath,SourceFile_fullPath); + } + //============================ 更新进度条 ================================= + emit Send_progressbar_Add(); + //=========================== ============================== + return 0; +} +/* +Anime4k视频放大子线程 +放大,修改大小 +*/ +int MainWindow::Anime4k_Video_scale(QMap Sub_Thread_info,int *Sub_video_ThreadNumRunning,bool *Frame_failed) +{ + bool AllFinished=true; + QString SplitFramesFolderPath = Sub_Thread_info["SplitFramesFolderPath"]; + QString ScaledFramesFolderPath = Sub_Thread_info["ScaledFramesFolderPath"]; + //=========== + QStringList OutPutFilesFullPathList; + do + { + QStringList InputFilesNameList = file_getFileNames_in_Folder_nofilter(SplitFramesFolderPath); + for(int i=0; ispinBox_retry->value()+ForceRetryCount); retry++) + { + Anime4k->start(CMD); + while(!Anime4k->waitForStarted(100)&&!QProcess_stop) {} + while(!Anime4k->waitForFinished(500)&&!QProcess_stop) + { + if(waifu2x_STOP) + { + QStringList FinfishedFileList = WaitForEngineIO(OutPutFilesFullPathList); + Anime4k->close(); + //============ + QString file_fullpath_tmp=""; + QString file_name=""; + QString file_ext=""; + for(int i=0; ispinBox_retry->value()+(ForceRetryCount-1))break; + Delay_sec_sleep(5); + emit Send_TextBrowser_NewMessage(tr("Automatic retry, please wait.")); + AllFinished=false; + break; + } + } + if(AllFinished== true)break; + } + //========= + AllFinished = true; + for(int i=0; icheckBox_FastMode_Anime4K->isChecked()) + { + Anime4k_Settings_str.append("-f "); + } + //GPU加速 + if(ui->checkBox_GPUMode_Anime4K->isChecked()) + { + Anime4k_Settings_str.append("-q "); + //加载GPGPU模式 + QString GPGPU_Model = ui->comboBox_GPGPUModel_A4k->currentText().toLower().trimmed(); + Anime4k_Settings_str.append("-M "+GPGPU_Model+" "); + //加载OpenCL选项 + if(GPGPU_Model=="opencl") + { + if(ui->checkBox_OpenCLParallelIO_A4k->isChecked())Anime4k_Settings_str.append("-P "); + Anime4k_Settings_str.append("-Q "+QString::number(ui->spinBox_OpenCLCommandQueues_A4k->value(),10)+" "); + } + } + //ACNet + if(ui->checkBox_ACNet_Anime4K->isChecked()) + { + Anime4k_Settings_str.append("-w ");//启用acnet + if(ui->checkBox_HDNMode_Anime4k->isChecked()) + { + Anime4k_Settings_str.append("-H ");//启用HDN + } + return Anime4k_Settings_str; + } + //============= 非ACNET选项 =========== + //Passes + Anime4k_Settings_str.append("-p "+QString::number(ui->spinBox_Passes_Anime4K->value(),10)+" "); + //Push color count + Anime4k_Settings_str.append("-n "+QString::number(ui->spinBox_PushColorCount_Anime4K->value(),10)+" "); + //Push color strength + Anime4k_Settings_str.append("-c "+QString::number(ui->doubleSpinBox_PushColorStrength_Anime4K->value(),'f',2)+" "); + //Push gradient strength + Anime4k_Settings_str.append("-g "+QString::number(ui->doubleSpinBox_PushGradientStrength_Anime4K->value(),'f',2)+" "); + //Pre-processing + if(ui->checkBox_EnablePreProcessing_Anime4k->isChecked()) + { + Anime4k_Settings_str.append("-b "); + uint8_t PreProcessingFilters = 0; + //读取滤镜选择情况 + if (ui->checkBox_MedianBlur_Pre_Anime4k->isChecked()) + { + PreProcessingFilters|=1; + } + if (ui->checkBox_MeanBlur_Pre_Anime4k->isChecked()) + { + PreProcessingFilters|=2; + } + if (ui->checkBox_CASSharping_Pre_Anime4k->isChecked()) + { + PreProcessingFilters|=4; + } + if (ui->checkBox_GaussianBlurWeak_Pre_Anime4k->isChecked()) + { + PreProcessingFilters|=8; + } + if (ui->checkBox_GaussianBlur_Pre_Anime4k->isChecked()) + { + PreProcessingFilters|=16; + } + if (ui->checkBox_BilateralFilter_Pre_Anime4k->isChecked()) + { + PreProcessingFilters|=32; + } + if (ui->checkBox_BilateralFilterFaster_Pre_Anime4k->isChecked()) + { + PreProcessingFilters|=64; + } + //生成添加滤镜指令 + if(PreProcessingFilters!=0) + { + Anime4k_Settings_str.append("-r "+QString::number(PreProcessingFilters,10)+" "); + } + else + { + Anime4k_Settings_str.append("-r 4 "); + } + } + //Post-processing + if(ui->checkBox_EnablePostProcessing_Anime4k->isChecked()) + { + Anime4k_Settings_str.append("-a "); + uint8_t PostProcessingFilters = 0; + //读取滤镜选择情况 + if (ui->checkBox_MedianBlur_Post_Anime4k->isChecked()) + { + PostProcessingFilters|=1; + } + if (ui->checkBox_MeanBlur_Post_Anime4k->isChecked()) + { + PostProcessingFilters|=2; + } + if (ui->checkBox_CASSharping_Post_Anime4k->isChecked()) + { + PostProcessingFilters|=4; + } + if (ui->checkBox_GaussianBlurWeak_Post_Anime4k->isChecked()) + { + PostProcessingFilters|=8; + } + if (ui->checkBox_GaussianBlur_Post_Anime4k->isChecked()) + { + PostProcessingFilters|=16; + } + if (ui->checkBox_BilateralFilter_Post_Anime4k->isChecked()) + { + PostProcessingFilters|=32; + } + if (ui->checkBox_BilateralFilterFaster_Post_Anime4k->isChecked()) + { + PostProcessingFilters|=64; + } + //生成添加滤镜指令 + if(PostProcessingFilters!=0) + { + Anime4k_Settings_str.append("-e "+QString::number(PostProcessingFilters,10)+" "); + } + else + { + Anime4k_Settings_str.append("-e 4 "); + } + } + return Anime4k_Settings_str; +} +/* +Anime4k +读取配置生成配置string +*/ +QString MainWindow::Anime4k_ReadSettings(bool PreserveAlphaChannel) +{ + QString Anime4k_Settings_str = ""; + //================================= + Anime4k_Settings_str.append(Anime4k_PreLoad_Settings_Str); + //保留透明通道 + if(PreserveAlphaChannel) + { + Anime4k_Settings_str.append("-A ");//保留透明通道 + } + //GPU加速 + if(ui->checkBox_GPUMode_Anime4K->isChecked()) + { + //指定GPU + if(ui->checkBox_SpecifyGPU_Anime4k->isChecked()) + { + Anime4k_Settings_str.append(Anime4k_GetGPUInfo()+" "); + } + } + //================================= + return Anime4k_Settings_str; +} + +QString MainWindow::Anime4k_GetGPUInfo() +{ + GetGPUInfo_QMutex_Anime4k.lock(); + //==== + QStringList GPU_List = ui->lineEdit_GPUs_Anime4k->text().trimmed().remove(" ").remove(" ").split(":"); + GPU_List.removeDuplicates(); + GPU_List.removeAll(""); + //==== + int MAX_GPU_ID_Anime4k = GPU_List.size()-1; + if(GPU_ID_Anime4k_GetGPUInfo>MAX_GPU_ID_Anime4k) + { + GPU_ID_Anime4k_GetGPUInfo=0; + } + //====== + QString GPUInfo=""; + QStringList PID_DID = GPU_List.at(GPU_ID_Anime4k_GetGPUInfo).split(","); + PID_DID.removeAll(""); + if(PID_DID.size()==2) + { + GPUInfo = "-h "+PID_DID.at(0).trimmed()+" -d "+PID_DID.at(1).trimmed(); + } + else + { + GPUInfo = "-h 0 -d 0"; + } + //====== + GPU_ID_Anime4k_GetGPUInfo++; + if(GPU_ID_Anime4k_GetGPUInfo>MAX_GPU_ID_Anime4k) + { + GPU_ID_Anime4k_GetGPUInfo=0; + } + //====== + GetGPUInfo_QMutex_Anime4k.unlock(); + return GPUInfo; +} +/* +列出可用的GPUs +*/ +void MainWindow::on_pushButton_ListGPUs_Anime4k_clicked() +{ + QtConcurrent::run(this, &MainWindow::ListGPUs_Anime4k); +} + +void MainWindow::ListGPUs_Anime4k() +{ + QString cmd = "\"" + Anime4k_ProgramPath + "\" -l"; + ExecuteCMD_batFile(cmd.replace("%","%%")+"\n title = GPU List for Anime4K @ Waifu2x-Extension-GUI\n pause",false); +} + +void MainWindow::on_lineEdit_GPUs_Anime4k_editingFinished() +{ + QString Format_str="0123456789:,"; + QString GPUs_str = ui->lineEdit_GPUs_Anime4k->text().trimmed().replace(":",":").replace(",",",").remove(" ").remove(" "); + for (int i=0; ilineEdit_GPUs_Anime4k->setText(GPUs_str); +} + +void MainWindow::on_pushButton_VerifyGPUsConfig_Anime4k_clicked() +{ + on_lineEdit_GPUs_Anime4k_editingFinished(); + QStringList GPU_List = ui->lineEdit_GPUs_Anime4k->text().trimmed().remove(" ").remove(" ").split(":"); + GPU_List.removeDuplicates(); + GPU_List.removeAll(""); + //====== + QString VerRes = ""; + //====== + for (int i=0; isetWindowTitle(tr("GPUs List according to your configuration")); + MSG->setText(VerRes); + MSG->setIcon(QMessageBox::Information); + MSG->setModal(true); + MSG->show(); + //====== + emit Send_TextBrowser_NewMessage(tr("\nAnime4k GPUs List(user configuration):\n")+VerRes.trimmed()); +} + +/* +删除强制重试时生成的垃圾缓存文件 +*/ +void MainWindow::DelTrash_ForceRetry_Anime4k(QString OutPut_Path) +{ + if(isForceRetryClicked)//判断是否触发强制重试,若触发,直接删除垃圾缓存 + { + QFile::remove(OutPut_Path); + isForceRetryClicked_QMutex.lock(); + isForceRetryClicked=false; + isForceRetryClicked_QMutex.unlock(); + } + return; +} +//阻断其他线程重置是否强制重试的标记,并检测anime4k是否正在运行 +void MainWindow::isForceRetryClicked_SetTrue_Block_Anime4k() +{ + isForceRetryClicked_QMutex.lock(); + isForceRetryClicked=true; + Delay_sec_sleep(5); + QProcess Get_tasklist; + do + { + Get_tasklist.start("tasklist /fo csv"); + while(!Get_tasklist.waitForStarted(100)) {} + while(!Get_tasklist.waitForFinished(100)) {} + if(Get_tasklist.readAllStandardOutput().contains("Anime4K_waifu2xEX.exe")==false) + { + break; + } + Delay_sec_sleep(1); + } + while(true); + isForceRetryClicked_QMutex.unlock(); + emit Send_SetEnable_pushButton_ForceRetry_self(); +} + +void MainWindow::DenoiseLevelSpinboxSetting_Anime4k() +{ + if(ui->checkBox_ACNet_Anime4K->isChecked()&&ui->checkBox_HDNMode_Anime4k->isChecked()) + { + if(ui->comboBox_Engine_Image->currentIndex()==3) + { + ui->spinBox_DenoiseLevel_image->setRange(1,3); + ui->spinBox_DenoiseLevel_image->setValue(1); + ui->spinBox_DenoiseLevel_image->setEnabled(1); + ui->spinBox_DenoiseLevel_image->setToolTip(tr("Range:1~3")); + ui->label_ImageDenoiseLevel->setToolTip(tr("Range:1~3")); + } + if(ui->comboBox_Engine_GIF->currentIndex()==3) + { + ui->spinBox_DenoiseLevel_gif->setRange(1,3); + ui->spinBox_DenoiseLevel_gif->setValue(1); + ui->spinBox_DenoiseLevel_gif->setEnabled(1); + ui->spinBox_DenoiseLevel_gif->setToolTip(tr("Range:1~3")); + ui->label_GIFDenoiseLevel->setToolTip(tr("Range:1~3")); + } + if(ui->comboBox_Engine_Video->currentIndex()==2) + { + ui->spinBox_DenoiseLevel_video->setRange(1,3); + ui->spinBox_DenoiseLevel_video->setValue(1); + ui->spinBox_DenoiseLevel_video->setEnabled(1); + ui->spinBox_DenoiseLevel_video->setToolTip(tr("Range:1~3")); + ui->label_VideoDenoiseLevel->setToolTip(tr("Range:1~3")); + } + } + else + { + if(ui->comboBox_Engine_Image->currentIndex()==3) + { + ui->spinBox_DenoiseLevel_image->setRange(-1,0); + ui->spinBox_DenoiseLevel_image->setValue(-1); + ui->spinBox_DenoiseLevel_image->setEnabled(0); + ui->spinBox_DenoiseLevel_image->setToolTip(tr("Due to current settings, you can\'t adjust denoise level.")); + ui->label_ImageDenoiseLevel->setToolTip(tr("Due to current settings, you can\'t adjust denoise level.")); + } + if(ui->comboBox_Engine_GIF->currentIndex()==3) + { + ui->spinBox_DenoiseLevel_gif->setRange(-1,0); + ui->spinBox_DenoiseLevel_gif->setValue(-1); + ui->spinBox_DenoiseLevel_gif->setEnabled(0); + ui->spinBox_DenoiseLevel_gif->setToolTip(tr("Due to current settings, you can\'t adjust denoise level.")); + ui->label_GIFDenoiseLevel->setToolTip(tr("Due to current settings, you can\'t adjust denoise level.")); + } + if(ui->comboBox_Engine_Video->currentIndex()==2) + { + ui->spinBox_DenoiseLevel_video->setRange(-1,0); + ui->spinBox_DenoiseLevel_video->setValue(-1); + ui->spinBox_DenoiseLevel_video->setEnabled(0); + ui->spinBox_DenoiseLevel_video->setToolTip(tr("Due to current settings, you can\'t adjust denoise level.")); + ui->label_VideoDenoiseLevel->setToolTip(tr("Due to current settings, you can\'t adjust denoise level.")); + } + } +} +/* +获取可用显卡数量 +*/ +int MainWindow::Get_NumOfGPU_Anime4k() +{ + QStringList GPU_List = ui->lineEdit_GPUs_Anime4k->text().trimmed().remove(" ").remove(" ").split(":"); + GPU_List.removeDuplicates(); + GPU_List.removeAll(""); + int GPUNum = 0; + QStringList PID_DID; + for (int i=0; i FileProgressWatch_QFuture = QtConcurrent::run(this, &MainWindow::CurrentFileProgress_WatchFolderFileNum, scaledFramesFolder);//启动waifu2x 主线程 + if(ui->checkBox_ShowInterPro->isChecked()==false) + { + FileProgressWatch_isEnabled=false; + FileProgressWatch_QFuture.cancel(); + emit Send_CurrentFileProgress_Stop(); + } + //=======获取显卡信息======== + int NumOfGPU = 1; + if(ui->checkBox_SpecifyGPU_Anime4k->isChecked()==true) + { + NumOfGPU = Get_NumOfGPU_Anime4k(); + } + //============创建显卡文件夹=========== + QStringList GPU_splitFramesFolder_List; + for(int i = 0; i < NumOfGPU; i++) + { + QString GPU_splitFramesFolder = splitFramesFolder+"/"+"GPU_"+QString::number(i); + if(file_isDirExist(GPU_splitFramesFolder)) + { + file_DelDir(GPU_splitFramesFolder); + file_mkDir(GPU_splitFramesFolder); + } + else + { + file_mkDir(GPU_splitFramesFolder); + } + GPU_splitFramesFolder_List.append(GPU_splitFramesFolder); + } + int TotalFramesNum = framesFileName_qStrList.size(); + int FramesNumForEachGPU = TotalFramesNum/NumOfGPU; + if(FramesNumForEachGPU<1)FramesNumForEachGPU=1; + int start_num=0; + for(int x = 0; x < GPU_splitFramesFolder_List.size(); x++) + { + if(x==GPU_splitFramesFolder_List.size()-1)FramesNumForEachGPU=TotalFramesNum; + QStringList file_waitformove = framesFileName_qStrList.mid(start_num,FramesNumForEachGPU); + for(int i = 0; i < file_waitformove.size(); i++) + { + QString FileName = file_waitformove.at(i); + QFile::rename(splitFramesFolder+"/"+FileName,GPU_splitFramesFolder_List.at(x)+"/"+FileName); + } + start_num+=FramesNumForEachGPU; + } + //=== + QMap Sub_Thread_info; + Sub_Thread_info["scaledFramesFolder"]=scaledFramesFolder; + if(CustRes_isContained(sourceFileFullPath)) + { + QMap Res_map = CustRes_getResMap(sourceFileFullPath);//res_map["fullpath"],["height"],["width"] + Sub_Thread_info["ScaleRatio"] = QString("%1").arg(CustRes_CalNewScaleRatio(sourceFileFullPath,Res_map["height"].toInt(),Res_map["width"].toInt())); + } + else + { + Sub_Thread_info["ScaleRatio"] = QString("%1").arg(qRound(ui->doubleSpinBox_ScaleRatio_gif->value())); + } + //========================= + bool Frame_failed = false;//放大失败标志 + int Sub_gif_ThreadNumRunning=0;//正在运行的线程数量 + //========================= + for(int i = 0; i < GPU_splitFramesFolder_List.size(); i++) + { + Sub_Thread_info["splitFramesFolder"]=GPU_splitFramesFolder_List.at(i); + mutex_SubThreadNumRunning.lock(); + Sub_gif_ThreadNumRunning++; + mutex_SubThreadNumRunning.unlock(); + QtConcurrent::run(this,&MainWindow::Anime4k_APNG_scale,Sub_Thread_info,&Sub_gif_ThreadNumRunning,&Frame_failed); + while (Sub_gif_ThreadNumRunning >= NumOfGPU) + { + Delay_msec_sleep(500); + } + if(waifu2x_STOP) + { + while (Sub_gif_ThreadNumRunning > 0) + { + Delay_msec_sleep(500); + } + FileProgressWatch_isEnabled=false; + FileProgressWatch_QFuture.cancel(); + return false; + } + if(Frame_failed) + { + FileProgressWatch_isEnabled=false; + FileProgressWatch_QFuture.cancel(); + emit Send_TextBrowser_NewMessage(tr("Error occured when processing [")+sourceFileFullPath+tr("]. Error: [Failed to scale frames.]")); + return false; + } + } + while (Sub_gif_ThreadNumRunning!=0) + { + Delay_msec_sleep(500); + } + FileProgressWatch_isEnabled=false; + FileProgressWatch_QFuture.cancel(); + emit Send_CurrentFileProgress_Stop(); + //======================= 检查是否成功放大所有帧 =========================== + QStringList framesFileName_qStrList_scaled = file_getFileNames_in_Folder_nofilter(scaledFramesFolder); + if(framesFileName_qStrList.size()!=framesFileName_qStrList_scaled.size()) + { + emit Send_TextBrowser_NewMessage(tr("Error occured when processing [")+sourceFileFullPath+tr("]. Error: [Failed to scale frames.]")); + return false; + } + //============================================================ + //组装apng + APNG_Frames2APNG(sourceFileFullPath, scaledFramesFolder, resultFileFullPath, false); + return true; +} +/* +Anime4k APNG 放大子线程 +*/ +int MainWindow::Anime4k_APNG_scale(QMap Sub_Thread_info,int *Sub_gif_ThreadNumRunning,bool *Frame_failed) +{ + bool AllFinished=true; + QString splitFramesFolder = Sub_Thread_info["splitFramesFolder"]; + QString scaledFramesFolder = Sub_Thread_info["scaledFramesFolder"]; + //================== + // 生成输出文件列表 + //================== + QStringList OutPutFilesFullPathList; + do + { + QStringList InputFilesNameList = file_getFileNames_in_Folder_nofilter(splitFramesFolder); + for(int i=0; ispinBox_retry->value()+ForceRetryCount); retry++) + { + Anime4k->start(CMD); + while(!Anime4k->waitForStarted(100)&&!QProcess_stop) {} + while(!Anime4k->waitForFinished(500)&&!QProcess_stop) + { + if(waifu2x_STOP) + { + Anime4k->close(); + mutex_SubThreadNumRunning.lock(); + *Sub_gif_ThreadNumRunning=*Sub_gif_ThreadNumRunning-1; + mutex_SubThreadNumRunning.unlock(); + return 0; + } + } + AllFinished = true; + for(int i=0; ispinBox_retry->value()+(ForceRetryCount-1))break; + Delay_sec_sleep(5); + emit Send_TextBrowser_NewMessage(tr("Automatic retry, please wait.")); + AllFinished=false; + break; + } + } + if(AllFinished == true)break; + } + //========= + AllFinished = true; + for(int i=0; i. - - My Github homepage: https://github.com/AaronFeng753 -*/ - -#include "mainwindow.h" -#include "ui_mainwindow.h" - -/* -开始处理当前文件 -*/ -void MainWindow::CurrentFileProgress_Start(QString FileName,int FrameNum) -{ - ui->groupBox_CurrentFile->setTitle(tr("Current File:")+" "+FileName); - //================================= - ui->progressBar_CurrentFile->setRange(0,FrameNum); - ui->progressBar_CurrentFile->setValue(0); - //================================= - ui->label_FrameProgress_CurrentFile->setText("0/"+QString::number(FrameNum,10)); - ui->label_TimeRemain_CurrentFile->setText(tr("Time remaining:NULL")); - ui->label_TimeCost_CurrentFile->setText(tr("Time taken:NULL")); - ui->label_ETA_CurrentFile->setText(tr("ETA:NULL")); - //================================= - TimeCost_CurrentFile = 0; - TaskNumTotal_CurrentFile=FrameNum; - TaskNumFinished_CurrentFile=0; - NewTaskFinished_CurrentFile=false; - ETA_CurrentFile=0; - //================================= - ui->groupBox_CurrentFile->setVisible(1); - //================================= - isStart_CurrentFile = true; - return; -} -/* -停止处理当前文件 -*/ -void MainWindow::CurrentFileProgress_Stop() -{ - ui->groupBox_CurrentFile->setVisible(0); - isStart_CurrentFile = false; - return; -} -/* -进度条 进度+1 -*/ -void MainWindow::CurrentFileProgress_progressbar_Add() -{ - TaskNumFinished_CurrentFile++; - NewTaskFinished_CurrentFile=true; - ui->progressBar_CurrentFile->setValue(TaskNumFinished_CurrentFile); - ui->label_FrameProgress_CurrentFile->setText(QString::number(TaskNumFinished_CurrentFile,10)+"/"+QString::number(TaskNumTotal_CurrentFile,10)); -} -/* -进度条 进度+片段時長 -*/ -void MainWindow::CurrentFileProgress_progressbar_Add_SegmentDuration(int SegmentDuration) -{ - TaskNumFinished_CurrentFile+=SegmentDuration; - NewTaskFinished_CurrentFile=true; - ui->progressBar_CurrentFile->setValue(TaskNumFinished_CurrentFile); - ui->label_FrameProgress_CurrentFile->setText(QString::number(TaskNumFinished_CurrentFile,10)+"/"+QString::number(TaskNumTotal_CurrentFile,10)); -} -/* -进度条 进度+片段時長 -*/ -void MainWindow::CurrentFileProgress_progressbar_SetFinishedValue(int FinishedValue) -{ - TaskNumFinished_CurrentFile=FinishedValue; - NewTaskFinished_CurrentFile=true; - ui->progressBar_CurrentFile->setValue(TaskNumFinished_CurrentFile); - ui->label_FrameProgress_CurrentFile->setText(QString::number(TaskNumFinished_CurrentFile,10)+"/"+QString::number(TaskNumTotal_CurrentFile,10)); -} -/* -监视文件夹内文件数量 -*/ -void MainWindow::CurrentFileProgress_WatchFolderFileNum(QString FolderPath) -{ - QStringList FilesNameList; - do - { - if(FileProgressWatch_isEnabled==false)return; - Delay_msec_sleep(2300); - if(file_isDirExist(FolderPath)==false)return; - FilesNameList = file_getFileNames_in_Folder_nofilter(FolderPath); - emit Send_CurrentFileProgress_progressbar_SetFinishedValue(FilesNameList.size()); - } - while(true); -} -/* -监视文件夹内文件数量 -*/ -void MainWindow::CurrentFileProgress_WatchFolderFileNum_Textbrower(QString SourceFile_fullPath,QString FolderPath,int TotalFileNum) -{ - QStringList FilesNameList; - int OLD_num=0; - int New_num=0; - do - { - if(FileProgressWatch_isEnabled==false)return; - Delay_msec_sleep(2300); - //========== - if(file_isDirExist(FolderPath)==false)return; - //========= - New_num = file_getFileNames_in_Folder_nofilter(FolderPath).size(); - if(New_num!=OLD_num) - { - OLD_num=New_num; - emit Send_TextBrowser_NewMessage(tr("File name:[")+SourceFile_fullPath+tr("] Scale progress:[")+QString::number(New_num,10)+"/"+QString::number(TotalFileNum,10)+tr("] Frames")); - } - } - while(true); -} +/* + Copyright (C) 2021 Aaron Feng + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU Affero General Public License as published + by the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program. If not, see . + + My Github homepage: https://github.com/AaronFeng753 +*/ + +#include "mainwindow.h" +#include "ui_mainwindow.h" + +/* +开始处理当前文件 +*/ +void MainWindow::CurrentFileProgress_Start(QString FileName,int FrameNum) +{ + ui->groupBox_CurrentFile->setTitle(tr("Current File:")+" "+FileName); + //================================= + ui->progressBar_CurrentFile->setRange(0,FrameNum); + ui->progressBar_CurrentFile->setValue(0); + //================================= + ui->label_FrameProgress_CurrentFile->setText("0/"+QString::number(FrameNum,10)); + ui->label_TimeRemain_CurrentFile->setText(tr("Time remaining:NULL")); + ui->label_TimeCost_CurrentFile->setText(tr("Time taken:NULL")); + ui->label_ETA_CurrentFile->setText(tr("ETA:NULL")); + //================================= + TimeCost_CurrentFile = 0; + TaskNumTotal_CurrentFile=FrameNum; + TaskNumFinished_CurrentFile=0; + NewTaskFinished_CurrentFile=false; + ETA_CurrentFile=0; + //================================= + ui->groupBox_CurrentFile->setVisible(1); + //================================= + isStart_CurrentFile = true; + return; +} +/* +停止处理当前文件 +*/ +void MainWindow::CurrentFileProgress_Stop() +{ + ui->groupBox_CurrentFile->setVisible(0); + isStart_CurrentFile = false; + return; +} +/* +进度条 进度+1 +*/ +void MainWindow::CurrentFileProgress_progressbar_Add() +{ + TaskNumFinished_CurrentFile++; + NewTaskFinished_CurrentFile=true; + ui->progressBar_CurrentFile->setValue(TaskNumFinished_CurrentFile); + ui->label_FrameProgress_CurrentFile->setText(QString::number(TaskNumFinished_CurrentFile,10)+"/"+QString::number(TaskNumTotal_CurrentFile,10)); +} +/* +进度条 进度+片段時長 +*/ +void MainWindow::CurrentFileProgress_progressbar_Add_SegmentDuration(int SegmentDuration) +{ + TaskNumFinished_CurrentFile+=SegmentDuration; + NewTaskFinished_CurrentFile=true; + ui->progressBar_CurrentFile->setValue(TaskNumFinished_CurrentFile); + ui->label_FrameProgress_CurrentFile->setText(QString::number(TaskNumFinished_CurrentFile,10)+"/"+QString::number(TaskNumTotal_CurrentFile,10)); +} +/* +进度条 进度+片段時長 +*/ +void MainWindow::CurrentFileProgress_progressbar_SetFinishedValue(int FinishedValue) +{ + TaskNumFinished_CurrentFile=FinishedValue; + NewTaskFinished_CurrentFile=true; + ui->progressBar_CurrentFile->setValue(TaskNumFinished_CurrentFile); + ui->label_FrameProgress_CurrentFile->setText(QString::number(TaskNumFinished_CurrentFile,10)+"/"+QString::number(TaskNumTotal_CurrentFile,10)); +} +/* +监视文件夹内文件数量 +*/ +void MainWindow::CurrentFileProgress_WatchFolderFileNum(QString FolderPath) +{ + QStringList FilesNameList; + do + { + if(FileProgressWatch_isEnabled==false)return; + Delay_msec_sleep(2300); + if(file_isDirExist(FolderPath)==false)return; + FilesNameList = file_getFileNames_in_Folder_nofilter(FolderPath); + emit Send_CurrentFileProgress_progressbar_SetFinishedValue(FilesNameList.size()); + } + while(true); +} +/* +监视文件夹内文件数量 +*/ +void MainWindow::CurrentFileProgress_WatchFolderFileNum_Textbrower(QString SourceFile_fullPath,QString FolderPath,int TotalFileNum) +{ + QStringList FilesNameList; + int OLD_num=0; + int New_num=0; + do + { + if(FileProgressWatch_isEnabled==false)return; + Delay_msec_sleep(2300); + //========== + if(file_isDirExist(FolderPath)==false)return; + //========= + New_num = file_getFileNames_in_Folder_nofilter(FolderPath).size(); + if(New_num!=OLD_num) + { + OLD_num=New_num; + emit Send_TextBrowser_NewMessage(tr("File name:[")+SourceFile_fullPath+tr("] Scale progress:[")+QString::number(New_num,10)+"/"+QString::number(TotalFileNum,10)+tr("] Frames")); + } + } + while(true); +} diff --git a/SRC/Waifu2x-Extension-QT/CustomResolution.cpp b/SRC_v3.41.01-beta/Waifu2x-Extension-QT/CustomResolution.cpp similarity index 97% rename from SRC/Waifu2x-Extension-QT/CustomResolution.cpp rename to SRC_v3.41.01-beta/Waifu2x-Extension-QT/CustomResolution.cpp index b209b2d..b890178 100644 --- a/SRC/Waifu2x-Extension-QT/CustomResolution.cpp +++ b/SRC_v3.41.01-beta/Waifu2x-Extension-QT/CustomResolution.cpp @@ -1,448 +1,448 @@ -/* - Copyright (C) 2021 Aaron Feng - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU Affero General Public License as published - by the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Affero General Public License for more details. - - You should have received a copy of the GNU Affero General Public License - along with this program. If not, see . - - My Github homepage: https://github.com/AaronFeng753 -*/ - -#include "mainwindow.h" -#include "ui_mainwindow.h" -/* -Apply自定义分辨率 -*/ -int MainWindow::CustRes_SetCustRes() -{ - int CustRes_height_spinBoxIntValue = ui->spinBox_CustRes_height->value(); - int CustRes_width_spinBoxIntValue = ui->spinBox_CustRes_width->value(); - QString CustRes_height_qStr = QString::number(CustRes_height_spinBoxIntValue,10); - QString CustRes_width_qStr = QString::number(CustRes_width_spinBoxIntValue,10); - //======== - if(ui->checkBox_custres_isAll->isChecked()&&EnableApply2All_CustRes) - { - int row_count_image = Table_image_get_rowNum(); - int row_count_gif = Table_gif_get_rowNum(); - int row_count_video = Table_video_get_rowNum(); - //==== - if((row_count_image+row_count_gif+row_count_video)==0) - { - QMessageBox *CustRes_NoItem = new QMessageBox(); - CustRes_NoItem->setWindowTitle(tr("Error")); - CustRes_NoItem->setText(tr("No items are in the list.")); - CustRes_NoItem->setIcon(QMessageBox::Warning); - CustRes_NoItem->setModal(true); - CustRes_NoItem->show(); - return 0; - } - //==== - for(int i=0; i res_map; - //读取文件信息 - QString SourceFile_fullPath = Table_model_image->item(i,2)->text(); - CustRes_remove(SourceFile_fullPath);//移除原来的设定,防止重复 - res_map["fullpath"] = SourceFile_fullPath; - res_map["height"] = CustRes_height_qStr; - res_map["width"] = CustRes_width_qStr; - Custom_resolution_list.append(res_map); - Table_image_CustRes_rowNumInt_HeightQString_WidthQString(i,res_map["height"],res_map["width"]); - } - //===== - for(int i=0; i res_map; - //读取文件信息 - QString SourceFile_fullPath = Table_model_gif->item(i,2)->text(); - CustRes_remove(SourceFile_fullPath);//移除原来的设定,防止重复 - res_map["fullpath"] = SourceFile_fullPath; - res_map["height"] = CustRes_height_qStr; - res_map["width"] = CustRes_width_qStr; - Custom_resolution_list.append(res_map); - Table_gif_CustRes_rowNumInt_HeightQString_WidthQString(i,res_map["height"],res_map["width"]); - } - //======== - if(row_count_video==0)//如果列表里没视频,直接return - { - return 0; - } - //读取自定义分辨率设定 - int CustRes_width_video=CustRes_width_spinBoxIntValue; - int CustRes_height_video=CustRes_height_spinBoxIntValue; - //判断自定义分辨率是否包含奇数 - if(CustRes_height_spinBoxIntValue%2!=0||CustRes_width_spinBoxIntValue%2!=0) - { - QMessageBox *MSG = new QMessageBox(); - MSG->setWindowTitle(tr("Warning")); - MSG->setText(tr("When setting a custom resolution for a video, neither the height value nor the width value can be odd.\n\nTherefore, the custom resolution for video has been automatically corrected by this software.")); - MSG->setIcon(QMessageBox::Warning); - MSG->setModal(false); - MSG->show(); - //自动校正分辨率 - if(CustRes_height_video%2!=0)CustRes_height_video++; - if(CustRes_width_video%2!=0)CustRes_width_video++; - } - QString CustRes_height_video_qStr = QString::number(CustRes_height_video,10); - QString CustRes_width_video_qStr = QString::number(CustRes_width_video,10); - //开始apply自定义分辨率设定 - for(int i=0; i res_map; - //读取文件信息 - QString SourceFile_fullPath = Table_model_video->item(i,2)->text(); - CustRes_remove(SourceFile_fullPath);//移除原来的设定,防止重复 - res_map["fullpath"] = SourceFile_fullPath; - res_map["height"] = CustRes_height_video_qStr; - res_map["width"] = CustRes_width_video_qStr; - Custom_resolution_list.append(res_map); - Table_video_CustRes_rowNumInt_HeightQString_WidthQString(i,res_map["height"],res_map["width"]); - } - return 0; - } - //如果没有选中任何row,则直接return - if(curRow_image==-1&&curRow_video==-1&&curRow_gif==-1) - { - QMessageBox *CustRes_NoItem = new QMessageBox(); - CustRes_NoItem->setWindowTitle(tr("Error")); - CustRes_NoItem->setText(tr("No items are currently selected.")); - CustRes_NoItem->setIcon(QMessageBox::Warning); - CustRes_NoItem->setModal(true); - CustRes_NoItem->show(); - return 0; - } - if(curRow_image >= 0)//如果已选中图片 - { - QMap res_map; - //读取文件信息 - QString SourceFile_fullPath = Table_model_image->item(curRow_image,2)->text(); - CustRes_remove(SourceFile_fullPath);//移除原来的设定,防止重复 - res_map["fullpath"] = SourceFile_fullPath; - res_map["height"] = CustRes_height_qStr; - res_map["width"] = CustRes_width_qStr; - Custom_resolution_list.append(res_map); - Table_image_CustRes_rowNumInt_HeightQString_WidthQString(curRow_image,res_map["height"],res_map["width"]); - return 0; - } - if(curRow_gif >= 0) - { - QMap res_map; - //读取文件信息 - QString SourceFile_fullPath = Table_model_gif->item(curRow_gif,2)->text(); - CustRes_remove(SourceFile_fullPath);//移除原来的设定,防止重复 - res_map["fullpath"] = SourceFile_fullPath; - res_map["height"] = CustRes_height_qStr; - res_map["width"] = CustRes_width_qStr; - Custom_resolution_list.append(res_map); - Table_gif_CustRes_rowNumInt_HeightQString_WidthQString(curRow_gif,res_map["height"],res_map["width"]); - return 0; - } - if(curRow_video >= 0) - { - //读取自定义分辨率设定 - int CustRes_width_video=CustRes_width_spinBoxIntValue; - int CustRes_height_video=CustRes_height_spinBoxIntValue; - //判断自定义分辨率是否包含奇数 - if(CustRes_height_spinBoxIntValue%2!=0||CustRes_width_spinBoxIntValue%2!=0) - { - QMessageBox *MSG = new QMessageBox(); - MSG->setWindowTitle(tr("Warning")); - MSG->setText(tr("When setting a custom resolution for a video, neither the height value nor the width value can be odd.\n\nTherefore, the custom resolution for video has been automatically corrected by this software.")); - MSG->setIcon(QMessageBox::Warning); - MSG->setModal(false); - MSG->show(); - //自动校正分辨率 - if(CustRes_height_video%2!=0)CustRes_height_video++; - if(CustRes_width_video%2!=0)CustRes_width_video++; - } - //==== - QMap res_map; - //读取文件信息 - QString SourceFile_fullPath = Table_model_video->item(curRow_video,2)->text(); - CustRes_remove(SourceFile_fullPath);//移除原来的设定,防止重复 - res_map["fullpath"] = SourceFile_fullPath; - res_map["height"] = QString::number(CustRes_height_video,10); - res_map["width"] = QString::number(CustRes_width_video,10); - Custom_resolution_list.append(res_map); - Table_video_CustRes_rowNumInt_HeightQString_WidthQString(curRow_video,res_map["height"],res_map["width"]); - return 0; - } - return 0; -} -/* -取消 自定义分辨率设定 -*/ -int MainWindow::CustRes_CancelCustRes() -{ - if(ui->checkBox_custres_isAll->isChecked()&&EnableApply2All_CustRes) - { - int row_count_image = Table_image_get_rowNum(); - int row_count_gif = Table_gif_get_rowNum(); - int row_count_video = Table_video_get_rowNum(); - if((row_count_image+row_count_gif+row_count_video)==0) - { - QMessageBox *CustRes_NoItem = new QMessageBox(); - CustRes_NoItem->setWindowTitle(tr("Error")); - CustRes_NoItem->setText(tr("No items are in the list.")); - CustRes_NoItem->setIcon(QMessageBox::Warning); - CustRes_NoItem->setModal(true); - CustRes_NoItem->show(); - return 0; - } - //==== - for(int i=0; iitem(i,2)->text());//从自定义分辨率列表移除 - Table_image_CustRes_Cancel_rowNumInt(i);//清空指定row的自定义分辨率 - } - for(int i=0; iitem(i,2)->text());//从自定义分辨率列表移除 - Table_gif_CustRes_Cancel_rowNumInt(i);//清空指定row的自定义分辨率 - } - for(int i=0; iitem(i,2)->text());//从自定义分辨率列表移除 - Table_video_CustRes_Cancel_rowNumInt(i);//清空指定row的自定义分辨率 - } - return 0; - } - //如果没有任何选中的,则弹窗后return - if(curRow_image==-1&&curRow_video==-1&&curRow_gif==-1) - { - QMessageBox *MSG = new QMessageBox(); - MSG->setWindowTitle(tr("Error")); - MSG->setText(tr("No items are currently selected.")); - MSG->setIcon(QMessageBox::Warning); - MSG->setModal(true); - MSG->show(); - return 0; - } - if(curRow_image >= 0)//如果已选中图片 - { - QString SourceFile_fullPath = Table_model_image->item(curRow_image,2)->text(); - CustRes_remove(SourceFile_fullPath);//从自定义分辨率列表移除 - Table_image_CustRes_Cancel_rowNumInt(curRow_image);//清空指定row的自定义分辨率 - return 0; - } - if(curRow_gif >= 0) - { - QString SourceFile_fullPath = Table_model_gif->item(curRow_gif,2)->text(); - CustRes_remove(SourceFile_fullPath);//从自定义分辨率列表移除 - Table_gif_CustRes_Cancel_rowNumInt(curRow_gif);//清空指定row的自定义分辨率 - return 0; - } - if(curRow_video >= 0) - { - QString SourceFile_fullPath = Table_model_video->item(curRow_video,2)->text(); - CustRes_remove(SourceFile_fullPath);//从自定义分辨率列表移除 - Table_video_CustRes_Cancel_rowNumInt(curRow_video);//清空指定row的自定义分辨率 - return 0; - } - return 0; -} - -void MainWindow::CustRes_remove(QString fullpath) -{ - for(int i=0; i map_res = Custom_resolution_list.at(i); - if(map_res["fullpath"]==fullpath) - { - Custom_resolution_list.removeAll(map_res); - } - } -} - -bool MainWindow::CustRes_isContained(QString fullpath) -{ - for(int i=0; i map_res = Custom_resolution_list.at(i); - if(map_res["fullpath"]==fullpath) - { - return true; - } - } - return false; -} - -QMap MainWindow::CustRes_getResMap(QString fullpath) -{ - for(int i=0; i map_res = Custom_resolution_list.at(i); - if(map_res["fullpath"]==fullpath) - { - return map_res; - } - } - QMap empty; - empty.clear(); - return empty; -} - -int MainWindow::CustRes_CalNewScaleRatio(QString fullpath,int Height_new,int width_new) -{ - QImage qimage_original; - qimage_original.load(fullpath); - int original_height = 0; - int original_width = 0; - //===================== 判断文件类型,获取分辨率 ============================= - //判断是否为图片或gif - QFileInfo fileinfo(fullpath); - QString file_ext_lower = fileinfo.suffix(); - QString Ext_image_str = ui->Ext_image->text(); - QStringList nameFilters_image = Ext_image_str.split(":"); - if (nameFilters_image.contains(file_ext_lower) || file_ext_lower=="gif" || file_ext_lower=="apng") - { - //是图片或动态图 - QMap res_map = Image_Gif_Read_Resolution(fullpath); - original_height = res_map["height"]; - original_width = res_map["width"]; - } - else//不是图片&动态图就是视频了 - { - QMap res_map = video_get_Resolution(fullpath); - original_height = res_map["height"]; - original_width = res_map["width"]; - } - //获取失败 - if(original_height<=0||original_width<=0) - { - emit Send_TextBrowser_NewMessage(tr("Error occured when processing [")+fullpath+tr("] [Unable to get resolution.]")); - return 0; - } - //=====================分别计算高和宽的放大倍数======================= - //==== 高 ====== - int ScaleRatio_height; - double ScaleRatio_height_double = (double)Height_new/(double)original_height; - if((ScaleRatio_height_double-(int)ScaleRatio_height_double)>0) - { - ScaleRatio_height = (int)(ScaleRatio_height_double)+1; - } - else - { - ScaleRatio_height = (int)(ScaleRatio_height_double); - } - //==== 宽 ====== - int ScaleRatio_width; - double ScaleRatio_width_double = (double)width_new/(double)original_width; - if((ScaleRatio_width_double-(int)ScaleRatio_width_double)>0) - { - ScaleRatio_width = (int)(ScaleRatio_width_double)+1; - } - else - { - ScaleRatio_width = (int)(ScaleRatio_width_double); - } - //========================比较决定取哪个放大倍数值返回===================== - if((ScaleRatio_height<=1)&&(ScaleRatio_width<=1)) - { - return 1; - } - if(ScaleRatio_height>=ScaleRatio_width) - { - return ScaleRatio_height; - } - else - { - return ScaleRatio_width; - } -} - -QMap MainWindow::DoubleScaleRatio_Cal_NewScaleRatio_NewHW(QString fullpath,double ScaleRatio_double) -{ - QMap Res_map; - //=========== - QImage qimage_original; - qimage_original.load(fullpath); - int original_height = 0; - int original_width = 0; - //===================== 判断文件类型,获取分辨率 ============================= - bool isVideo=false; - //判断是否为图片或gif - QFileInfo fileinfo(fullpath); - QString file_ext_lower = fileinfo.suffix(); - QString Ext_image_str = ui->Ext_image->text(); - QStringList nameFilters_image = Ext_image_str.split(":"); - if (nameFilters_image.contains(file_ext_lower) || file_ext_lower=="gif" || file_ext_lower=="apng") - { - //是图片或动态图 - QMap res_map = Image_Gif_Read_Resolution(fullpath); - original_height = res_map["height"]; - original_width = res_map["width"]; - } - else//不是图片&动态图就是视频了 - { - isVideo=true; - QMap res_map = video_get_Resolution(fullpath); - original_height = res_map["height"]; - original_width = res_map["width"]; - } - //获取失败 - if(original_height<=0||original_width<=0) - { - emit Send_TextBrowser_NewMessage(tr("Error occured when processing [")+fullpath+tr("] [Unable to get resolution.]")); - Res_map.clear(); - return Res_map; - } - //========= 计算新的高度宽度 ================== - int Height_new = ScaleRatio_double * original_height; - int width_new = ScaleRatio_double * original_width; - if(isVideo == true) - { - if(Height_new%2!=0)Height_new++; - if(width_new%2!=0)width_new++; - } - Res_map["Height_new"] = QString::number(Height_new,10); - Res_map["width_new"] = QString::number(width_new,10); - //=====================分别计算高和宽的放大倍数======================= - //==== 高 ====== - int ScaleRatio_height; - double ScaleRatio_height_double = (double)Height_new/(double)original_height; - if((ScaleRatio_height_double-(int)ScaleRatio_height_double)>0) - { - ScaleRatio_height = (int)(ScaleRatio_height_double)+1; - } - else - { - ScaleRatio_height = (int)(ScaleRatio_height_double); - } - //==== 宽 ====== - int ScaleRatio_width; - double ScaleRatio_width_double = (double)width_new/(double)original_width; - if((ScaleRatio_width_double-(int)ScaleRatio_width_double)>0) - { - ScaleRatio_width = (int)(ScaleRatio_width_double)+1; - } - else - { - ScaleRatio_width = (int)(ScaleRatio_width_double); - } - //========================比较决定取哪个放大倍数值返回===================== - if((ScaleRatio_height<=1)&&(ScaleRatio_width<=1)) - { - Res_map["ScaleRatio"] = QString::number(1,10); - return Res_map; - } - if(ScaleRatio_height>=ScaleRatio_width) - { - Res_map["ScaleRatio"] = QString::number(ScaleRatio_height,10); - return Res_map; - } - else - { - Res_map["ScaleRatio"] = QString::number(ScaleRatio_width,10); - return Res_map; - } -} +/* + Copyright (C) 2021 Aaron Feng + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU Affero General Public License as published + by the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program. If not, see . + + My Github homepage: https://github.com/AaronFeng753 +*/ + +#include "mainwindow.h" +#include "ui_mainwindow.h" +/* +Apply自定义分辨率 +*/ +int MainWindow::CustRes_SetCustRes() +{ + int CustRes_height_spinBoxIntValue = ui->spinBox_CustRes_height->value(); + int CustRes_width_spinBoxIntValue = ui->spinBox_CustRes_width->value(); + QString CustRes_height_qStr = QString::number(CustRes_height_spinBoxIntValue,10); + QString CustRes_width_qStr = QString::number(CustRes_width_spinBoxIntValue,10); + //======== + if(ui->checkBox_custres_isAll->isChecked()&&EnableApply2All_CustRes) + { + int row_count_image = Table_image_get_rowNum(); + int row_count_gif = Table_gif_get_rowNum(); + int row_count_video = Table_video_get_rowNum(); + //==== + if((row_count_image+row_count_gif+row_count_video)==0) + { + QMessageBox *CustRes_NoItem = new QMessageBox(); + CustRes_NoItem->setWindowTitle(tr("Error")); + CustRes_NoItem->setText(tr("No items are in the list.")); + CustRes_NoItem->setIcon(QMessageBox::Warning); + CustRes_NoItem->setModal(true); + CustRes_NoItem->show(); + return 0; + } + //==== + for(int i=0; i res_map; + //读取文件信息 + QString SourceFile_fullPath = Table_model_image->item(i,2)->text(); + CustRes_remove(SourceFile_fullPath);//移除原来的设定,防止重复 + res_map["fullpath"] = SourceFile_fullPath; + res_map["height"] = CustRes_height_qStr; + res_map["width"] = CustRes_width_qStr; + Custom_resolution_list.append(res_map); + Table_image_CustRes_rowNumInt_HeightQString_WidthQString(i,res_map["height"],res_map["width"]); + } + //===== + for(int i=0; i res_map; + //读取文件信息 + QString SourceFile_fullPath = Table_model_gif->item(i,2)->text(); + CustRes_remove(SourceFile_fullPath);//移除原来的设定,防止重复 + res_map["fullpath"] = SourceFile_fullPath; + res_map["height"] = CustRes_height_qStr; + res_map["width"] = CustRes_width_qStr; + Custom_resolution_list.append(res_map); + Table_gif_CustRes_rowNumInt_HeightQString_WidthQString(i,res_map["height"],res_map["width"]); + } + //======== + if(row_count_video==0)//如果列表里没视频,直接return + { + return 0; + } + //读取自定义分辨率设定 + int CustRes_width_video=CustRes_width_spinBoxIntValue; + int CustRes_height_video=CustRes_height_spinBoxIntValue; + //判断自定义分辨率是否包含奇数 + if(CustRes_height_spinBoxIntValue%2!=0||CustRes_width_spinBoxIntValue%2!=0) + { + QMessageBox *MSG = new QMessageBox(); + MSG->setWindowTitle(tr("Warning")); + MSG->setText(tr("When setting a custom resolution for a video, neither the height value nor the width value can be odd.\n\nTherefore, the custom resolution for video has been automatically corrected by this software.")); + MSG->setIcon(QMessageBox::Warning); + MSG->setModal(false); + MSG->show(); + //自动校正分辨率 + if(CustRes_height_video%2!=0)CustRes_height_video++; + if(CustRes_width_video%2!=0)CustRes_width_video++; + } + QString CustRes_height_video_qStr = QString::number(CustRes_height_video,10); + QString CustRes_width_video_qStr = QString::number(CustRes_width_video,10); + //开始apply自定义分辨率设定 + for(int i=0; i res_map; + //读取文件信息 + QString SourceFile_fullPath = Table_model_video->item(i,2)->text(); + CustRes_remove(SourceFile_fullPath);//移除原来的设定,防止重复 + res_map["fullpath"] = SourceFile_fullPath; + res_map["height"] = CustRes_height_video_qStr; + res_map["width"] = CustRes_width_video_qStr; + Custom_resolution_list.append(res_map); + Table_video_CustRes_rowNumInt_HeightQString_WidthQString(i,res_map["height"],res_map["width"]); + } + return 0; + } + //如果没有选中任何row,则直接return + if(curRow_image==-1&&curRow_video==-1&&curRow_gif==-1) + { + QMessageBox *CustRes_NoItem = new QMessageBox(); + CustRes_NoItem->setWindowTitle(tr("Error")); + CustRes_NoItem->setText(tr("No items are currently selected.")); + CustRes_NoItem->setIcon(QMessageBox::Warning); + CustRes_NoItem->setModal(true); + CustRes_NoItem->show(); + return 0; + } + if(curRow_image >= 0)//如果已选中图片 + { + QMap res_map; + //读取文件信息 + QString SourceFile_fullPath = Table_model_image->item(curRow_image,2)->text(); + CustRes_remove(SourceFile_fullPath);//移除原来的设定,防止重复 + res_map["fullpath"] = SourceFile_fullPath; + res_map["height"] = CustRes_height_qStr; + res_map["width"] = CustRes_width_qStr; + Custom_resolution_list.append(res_map); + Table_image_CustRes_rowNumInt_HeightQString_WidthQString(curRow_image,res_map["height"],res_map["width"]); + return 0; + } + if(curRow_gif >= 0) + { + QMap res_map; + //读取文件信息 + QString SourceFile_fullPath = Table_model_gif->item(curRow_gif,2)->text(); + CustRes_remove(SourceFile_fullPath);//移除原来的设定,防止重复 + res_map["fullpath"] = SourceFile_fullPath; + res_map["height"] = CustRes_height_qStr; + res_map["width"] = CustRes_width_qStr; + Custom_resolution_list.append(res_map); + Table_gif_CustRes_rowNumInt_HeightQString_WidthQString(curRow_gif,res_map["height"],res_map["width"]); + return 0; + } + if(curRow_video >= 0) + { + //读取自定义分辨率设定 + int CustRes_width_video=CustRes_width_spinBoxIntValue; + int CustRes_height_video=CustRes_height_spinBoxIntValue; + //判断自定义分辨率是否包含奇数 + if(CustRes_height_spinBoxIntValue%2!=0||CustRes_width_spinBoxIntValue%2!=0) + { + QMessageBox *MSG = new QMessageBox(); + MSG->setWindowTitle(tr("Warning")); + MSG->setText(tr("When setting a custom resolution for a video, neither the height value nor the width value can be odd.\n\nTherefore, the custom resolution for video has been automatically corrected by this software.")); + MSG->setIcon(QMessageBox::Warning); + MSG->setModal(false); + MSG->show(); + //自动校正分辨率 + if(CustRes_height_video%2!=0)CustRes_height_video++; + if(CustRes_width_video%2!=0)CustRes_width_video++; + } + //==== + QMap res_map; + //读取文件信息 + QString SourceFile_fullPath = Table_model_video->item(curRow_video,2)->text(); + CustRes_remove(SourceFile_fullPath);//移除原来的设定,防止重复 + res_map["fullpath"] = SourceFile_fullPath; + res_map["height"] = QString::number(CustRes_height_video,10); + res_map["width"] = QString::number(CustRes_width_video,10); + Custom_resolution_list.append(res_map); + Table_video_CustRes_rowNumInt_HeightQString_WidthQString(curRow_video,res_map["height"],res_map["width"]); + return 0; + } + return 0; +} +/* +取消 自定义分辨率设定 +*/ +int MainWindow::CustRes_CancelCustRes() +{ + if(ui->checkBox_custres_isAll->isChecked()&&EnableApply2All_CustRes) + { + int row_count_image = Table_image_get_rowNum(); + int row_count_gif = Table_gif_get_rowNum(); + int row_count_video = Table_video_get_rowNum(); + if((row_count_image+row_count_gif+row_count_video)==0) + { + QMessageBox *CustRes_NoItem = new QMessageBox(); + CustRes_NoItem->setWindowTitle(tr("Error")); + CustRes_NoItem->setText(tr("No items are in the list.")); + CustRes_NoItem->setIcon(QMessageBox::Warning); + CustRes_NoItem->setModal(true); + CustRes_NoItem->show(); + return 0; + } + //==== + for(int i=0; iitem(i,2)->text());//从自定义分辨率列表移除 + Table_image_CustRes_Cancel_rowNumInt(i);//清空指定row的自定义分辨率 + } + for(int i=0; iitem(i,2)->text());//从自定义分辨率列表移除 + Table_gif_CustRes_Cancel_rowNumInt(i);//清空指定row的自定义分辨率 + } + for(int i=0; iitem(i,2)->text());//从自定义分辨率列表移除 + Table_video_CustRes_Cancel_rowNumInt(i);//清空指定row的自定义分辨率 + } + return 0; + } + //如果没有任何选中的,则弹窗后return + if(curRow_image==-1&&curRow_video==-1&&curRow_gif==-1) + { + QMessageBox *MSG = new QMessageBox(); + MSG->setWindowTitle(tr("Error")); + MSG->setText(tr("No items are currently selected.")); + MSG->setIcon(QMessageBox::Warning); + MSG->setModal(true); + MSG->show(); + return 0; + } + if(curRow_image >= 0)//如果已选中图片 + { + QString SourceFile_fullPath = Table_model_image->item(curRow_image,2)->text(); + CustRes_remove(SourceFile_fullPath);//从自定义分辨率列表移除 + Table_image_CustRes_Cancel_rowNumInt(curRow_image);//清空指定row的自定义分辨率 + return 0; + } + if(curRow_gif >= 0) + { + QString SourceFile_fullPath = Table_model_gif->item(curRow_gif,2)->text(); + CustRes_remove(SourceFile_fullPath);//从自定义分辨率列表移除 + Table_gif_CustRes_Cancel_rowNumInt(curRow_gif);//清空指定row的自定义分辨率 + return 0; + } + if(curRow_video >= 0) + { + QString SourceFile_fullPath = Table_model_video->item(curRow_video,2)->text(); + CustRes_remove(SourceFile_fullPath);//从自定义分辨率列表移除 + Table_video_CustRes_Cancel_rowNumInt(curRow_video);//清空指定row的自定义分辨率 + return 0; + } + return 0; +} + +void MainWindow::CustRes_remove(QString fullpath) +{ + for(int i=0; i map_res = Custom_resolution_list.at(i); + if(map_res["fullpath"]==fullpath) + { + Custom_resolution_list.removeAll(map_res); + } + } +} + +bool MainWindow::CustRes_isContained(QString fullpath) +{ + for(int i=0; i map_res = Custom_resolution_list.at(i); + if(map_res["fullpath"]==fullpath) + { + return true; + } + } + return false; +} + +QMap MainWindow::CustRes_getResMap(QString fullpath) +{ + for(int i=0; i map_res = Custom_resolution_list.at(i); + if(map_res["fullpath"]==fullpath) + { + return map_res; + } + } + QMap empty; + empty.clear(); + return empty; +} + +int MainWindow::CustRes_CalNewScaleRatio(QString fullpath,int Height_new,int width_new) +{ + QImage qimage_original; + qimage_original.load(fullpath); + int original_height = 0; + int original_width = 0; + //===================== 判断文件类型,获取分辨率 ============================= + //判断是否为图片或gif + QFileInfo fileinfo(fullpath); + QString file_ext_lower = fileinfo.suffix(); + QString Ext_image_str = ui->Ext_image->text(); + QStringList nameFilters_image = Ext_image_str.split(":"); + if (nameFilters_image.contains(file_ext_lower) || file_ext_lower=="gif" || file_ext_lower=="apng") + { + //是图片或动态图 + QMap res_map = Image_Gif_Read_Resolution(fullpath); + original_height = res_map["height"]; + original_width = res_map["width"]; + } + else//不是图片&动态图就是视频了 + { + QMap res_map = video_get_Resolution(fullpath); + original_height = res_map["height"]; + original_width = res_map["width"]; + } + //获取失败 + if(original_height<=0||original_width<=0) + { + emit Send_TextBrowser_NewMessage(tr("Error occured when processing [")+fullpath+tr("] [Unable to get resolution.]")); + return 0; + } + //=====================分别计算高和宽的放大倍数======================= + //==== 高 ====== + int ScaleRatio_height; + double ScaleRatio_height_double = (double)Height_new/(double)original_height; + if((ScaleRatio_height_double-(int)ScaleRatio_height_double)>0) + { + ScaleRatio_height = (int)(ScaleRatio_height_double)+1; + } + else + { + ScaleRatio_height = (int)(ScaleRatio_height_double); + } + //==== 宽 ====== + int ScaleRatio_width; + double ScaleRatio_width_double = (double)width_new/(double)original_width; + if((ScaleRatio_width_double-(int)ScaleRatio_width_double)>0) + { + ScaleRatio_width = (int)(ScaleRatio_width_double)+1; + } + else + { + ScaleRatio_width = (int)(ScaleRatio_width_double); + } + //========================比较决定取哪个放大倍数值返回===================== + if((ScaleRatio_height<=1)&&(ScaleRatio_width<=1)) + { + return 1; + } + if(ScaleRatio_height>=ScaleRatio_width) + { + return ScaleRatio_height; + } + else + { + return ScaleRatio_width; + } +} + +QMap MainWindow::DoubleScaleRatio_Cal_NewScaleRatio_NewHW(QString fullpath,double ScaleRatio_double) +{ + QMap Res_map; + //=========== + QImage qimage_original; + qimage_original.load(fullpath); + int original_height = 0; + int original_width = 0; + //===================== 判断文件类型,获取分辨率 ============================= + bool isVideo=false; + //判断是否为图片或gif + QFileInfo fileinfo(fullpath); + QString file_ext_lower = fileinfo.suffix(); + QString Ext_image_str = ui->Ext_image->text(); + QStringList nameFilters_image = Ext_image_str.split(":"); + if (nameFilters_image.contains(file_ext_lower) || file_ext_lower=="gif" || file_ext_lower=="apng") + { + //是图片或动态图 + QMap res_map = Image_Gif_Read_Resolution(fullpath); + original_height = res_map["height"]; + original_width = res_map["width"]; + } + else//不是图片&动态图就是视频了 + { + isVideo=true; + QMap res_map = video_get_Resolution(fullpath); + original_height = res_map["height"]; + original_width = res_map["width"]; + } + //获取失败 + if(original_height<=0||original_width<=0) + { + emit Send_TextBrowser_NewMessage(tr("Error occured when processing [")+fullpath+tr("] [Unable to get resolution.]")); + Res_map.clear(); + return Res_map; + } + //========= 计算新的高度宽度 ================== + int Height_new = ScaleRatio_double * original_height; + int width_new = ScaleRatio_double * original_width; + if(isVideo == true) + { + if(Height_new%2!=0)Height_new++; + if(width_new%2!=0)width_new++; + } + Res_map["Height_new"] = QString::number(Height_new,10); + Res_map["width_new"] = QString::number(width_new,10); + //=====================分别计算高和宽的放大倍数======================= + //==== 高 ====== + int ScaleRatio_height; + double ScaleRatio_height_double = (double)Height_new/(double)original_height; + if((ScaleRatio_height_double-(int)ScaleRatio_height_double)>0) + { + ScaleRatio_height = (int)(ScaleRatio_height_double)+1; + } + else + { + ScaleRatio_height = (int)(ScaleRatio_height_double); + } + //==== 宽 ====== + int ScaleRatio_width; + double ScaleRatio_width_double = (double)width_new/(double)original_width; + if((ScaleRatio_width_double-(int)ScaleRatio_width_double)>0) + { + ScaleRatio_width = (int)(ScaleRatio_width_double)+1; + } + else + { + ScaleRatio_width = (int)(ScaleRatio_width_double); + } + //========================比较决定取哪个放大倍数值返回===================== + if((ScaleRatio_height<=1)&&(ScaleRatio_width<=1)) + { + Res_map["ScaleRatio"] = QString::number(1,10); + return Res_map; + } + if(ScaleRatio_height>=ScaleRatio_width) + { + Res_map["ScaleRatio"] = QString::number(ScaleRatio_height,10); + return Res_map; + } + else + { + Res_map["ScaleRatio"] = QString::number(ScaleRatio_width,10); + return Res_map; + } +} diff --git a/SRC/Waifu2x-Extension-QT/Donate.cpp b/SRC_v3.41.01-beta/Waifu2x-Extension-QT/Donate.cpp similarity index 100% rename from SRC/Waifu2x-Extension-QT/Donate.cpp rename to SRC_v3.41.01-beta/Waifu2x-Extension-QT/Donate.cpp diff --git a/SRC/Waifu2x-Extension-QT/Finish_Action.cpp b/SRC_v3.41.01-beta/Waifu2x-Extension-QT/Finish_Action.cpp similarity index 100% rename from SRC/Waifu2x-Extension-QT/Finish_Action.cpp rename to SRC_v3.41.01-beta/Waifu2x-Extension-QT/Finish_Action.cpp diff --git a/SRC/Waifu2x-Extension-QT/Frame_Interpolation.cpp b/SRC_v3.41.01-beta/Waifu2x-Extension-QT/Frame_Interpolation.cpp similarity index 100% rename from SRC/Waifu2x-Extension-QT/Frame_Interpolation.cpp rename to SRC_v3.41.01-beta/Waifu2x-Extension-QT/Frame_Interpolation.cpp diff --git a/SRC/Waifu2x-Extension-QT/OtherPic.qrc b/SRC_v3.41.01-beta/Waifu2x-Extension-QT/OtherPic.qrc similarity index 96% rename from SRC/Waifu2x-Extension-QT/OtherPic.qrc rename to SRC_v3.41.01-beta/Waifu2x-Extension-QT/OtherPic.qrc index 45f8a05..7b2cf92 100644 --- a/SRC/Waifu2x-Extension-QT/OtherPic.qrc +++ b/SRC_v3.41.01-beta/Waifu2x-Extension-QT/OtherPic.qrc @@ -1,5 +1,5 @@ - - - OtherPic/AspectRatioStrategy.jpg - - + + + OtherPic/AspectRatioStrategy.jpg + + diff --git a/SRC/Waifu2x-Extension-QT/OtherPic/AspectRatioStrategy.jpg b/SRC_v3.41.01-beta/Waifu2x-Extension-QT/OtherPic/AspectRatioStrategy.jpg similarity index 100% rename from SRC/Waifu2x-Extension-QT/OtherPic/AspectRatioStrategy.jpg rename to SRC_v3.41.01-beta/Waifu2x-Extension-QT/OtherPic/AspectRatioStrategy.jpg diff --git a/SRC/Waifu2x-Extension-QT/Right-click_Menu.cpp b/SRC_v3.41.01-beta/Waifu2x-Extension-QT/Right-click_Menu.cpp similarity index 100% rename from SRC/Waifu2x-Extension-QT/Right-click_Menu.cpp rename to SRC_v3.41.01-beta/Waifu2x-Extension-QT/Right-click_Menu.cpp diff --git a/SRC/Waifu2x-Extension-QT/SyncToy_3d7bd0e1-f8ab-4ddc-a52a-15db18477d2f.dat b/SRC_v3.41.01-beta/Waifu2x-Extension-QT/SyncToy_3d7bd0e1-f8ab-4ddc-a52a-15db18477d2f.dat similarity index 100% rename from SRC/Waifu2x-Extension-QT/SyncToy_3d7bd0e1-f8ab-4ddc-a52a-15db18477d2f.dat rename to SRC_v3.41.01-beta/Waifu2x-Extension-QT/SyncToy_3d7bd0e1-f8ab-4ddc-a52a-15db18477d2f.dat diff --git a/SRC/Waifu2x-Extension-QT/SystemTrayIcon.cpp b/SRC_v3.41.01-beta/Waifu2x-Extension-QT/SystemTrayIcon.cpp similarity index 100% rename from SRC/Waifu2x-Extension-QT/SystemTrayIcon.cpp rename to SRC_v3.41.01-beta/Waifu2x-Extension-QT/SystemTrayIcon.cpp diff --git a/SRC/Waifu2x-Extension-QT/Waifu2x-Extension-QT.pro b/SRC_v3.41.01-beta/Waifu2x-Extension-QT/Waifu2x-Extension-QT.pro similarity index 96% rename from SRC/Waifu2x-Extension-QT/Waifu2x-Extension-QT.pro rename to SRC_v3.41.01-beta/Waifu2x-Extension-QT/Waifu2x-Extension-QT.pro index 13017bc..044193e 100644 --- a/SRC/Waifu2x-Extension-QT/Waifu2x-Extension-QT.pro +++ b/SRC_v3.41.01-beta/Waifu2x-Extension-QT/Waifu2x-Extension-QT.pro @@ -1,93 +1,93 @@ -# Copyright (C) 2021 Aaron Feng - -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU Affero General Public License as -# published by the Free Software Foundation, either version 3 of the -# License, or (at your option) any later version. - -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU Affero General Public License for more details. - -# You should have received a copy of the GNU Affero General Public License -# along with this program. If not, see . - -# My Github homepage: https://github.com/AaronFeng753 - -QT += core gui -QT += concurrent -QT += multimedia - -greaterThan(QT_MAJOR_VERSION, 4): QT += widgets - -CONFIG += c++11 - -# The following define makes your compiler emit warnings if you use -# any Qt feature that has been marked deprecated (the exact warnings -# depend on your compiler). Please consult the documentation of the -# deprecated API in order to know how to port your code away from it. -DEFINES += QT_DEPRECATED_WARNINGS - -# You can also make your code fail to compile if it uses deprecated APIs. -# In order to do so, uncomment the following line. -# You can also select to disable deprecated APIs only up to a certain version of Qt. -#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 - -SOURCES += \ - AnimatedPNG.cpp \ - Anime4K.cpp \ - CompatibilityTest.cpp \ - Current_File_Progress.cpp \ - CustomResolution.cpp \ - Donate.cpp \ - Finish_Action.cpp \ - Frame_Interpolation.cpp \ - Right-click_Menu.cpp \ - SystemTrayIcon.cpp \ - Web_Activities.cpp \ - checkupdate.cpp \ - files.cpp \ - gif.cpp \ - image.cpp \ - main.cpp \ - mainwindow.cpp \ - progressBar.cpp \ - realsr_ncnn_vulkan.cpp \ - settings.cpp \ - srmd-cuda.cpp \ - srmd_ncnn_vulkan.cpp \ - table.cpp \ - textBrowser.cpp \ - topsupporterslist.cpp \ - video.cpp \ - waifu2x.cpp \ - waifu2x_caffe.cpp \ - waifu2x_converter.cpp \ - waifu2x_ncnn_vulkan.cpp - -HEADERS += \ - mainwindow.h \ - topsupporterslist.h - -FORMS += \ - mainwindow.ui \ - topsupporterslist.ui - -TRANSLATIONS += language_English.ts \ - language_Chinese.ts \ - language_TraditionalChinese.ts - -TARGET = Waifu2x-Extension-GUI - -# Default rules for deployment. -qnx: target.path = /tmp/$${TARGET}/bin -else: unix:!android: target.path = /opt/$${TARGET}/bin -!isEmpty(target.path): INSTALLS += target - -RESOURCES += \ - OtherPic.qrc \ - donate.qrc \ - icon.qrc - -RC_ICONS =icon/icon.ico +# Copyright (C) 2021 Aaron Feng + +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. + +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . + +# My Github homepage: https://github.com/AaronFeng753 + +QT += core gui +QT += concurrent +QT += multimedia + +greaterThan(QT_MAJOR_VERSION, 4): QT += widgets + +CONFIG += c++11 + +# The following define makes your compiler emit warnings if you use +# any Qt feature that has been marked deprecated (the exact warnings +# depend on your compiler). Please consult the documentation of the +# deprecated API in order to know how to port your code away from it. +DEFINES += QT_DEPRECATED_WARNINGS + +# You can also make your code fail to compile if it uses deprecated APIs. +# In order to do so, uncomment the following line. +# You can also select to disable deprecated APIs only up to a certain version of Qt. +#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 + +SOURCES += \ + AnimatedPNG.cpp \ + Anime4K.cpp \ + CompatibilityTest.cpp \ + Current_File_Progress.cpp \ + CustomResolution.cpp \ + Donate.cpp \ + Finish_Action.cpp \ + Frame_Interpolation.cpp \ + Right-click_Menu.cpp \ + SystemTrayIcon.cpp \ + Web_Activities.cpp \ + checkupdate.cpp \ + files.cpp \ + gif.cpp \ + image.cpp \ + main.cpp \ + mainwindow.cpp \ + progressBar.cpp \ + realsr_ncnn_vulkan.cpp \ + settings.cpp \ + srmd-cuda.cpp \ + srmd_ncnn_vulkan.cpp \ + table.cpp \ + textBrowser.cpp \ + topsupporterslist.cpp \ + video.cpp \ + waifu2x.cpp \ + waifu2x_caffe.cpp \ + waifu2x_converter.cpp \ + waifu2x_ncnn_vulkan.cpp + +HEADERS += \ + mainwindow.h \ + topsupporterslist.h + +FORMS += \ + mainwindow.ui \ + topsupporterslist.ui + +TRANSLATIONS += language_English.ts \ + language_Chinese.ts \ + language_TraditionalChinese.ts + +TARGET = Waifu2x-Extension-GUI + +# Default rules for deployment. +qnx: target.path = /tmp/$${TARGET}/bin +else: unix:!android: target.path = /opt/$${TARGET}/bin +!isEmpty(target.path): INSTALLS += target + +RESOURCES += \ + OtherPic.qrc \ + donate.qrc \ + icon.qrc + +RC_ICONS =icon/icon.ico diff --git a/SRC/Waifu2x-Extension-QT/Waifu2x-Extension-QT.pro.user b/SRC_v3.41.01-beta/Waifu2x-Extension-QT/Waifu2x-Extension-QT.pro.user similarity index 98% rename from SRC/Waifu2x-Extension-QT/Waifu2x-Extension-QT.pro.user rename to SRC_v3.41.01-beta/Waifu2x-Extension-QT/Waifu2x-Extension-QT.pro.user index f9ce5bc..d353a3f 100644 --- a/SRC/Waifu2x-Extension-QT/Waifu2x-Extension-QT.pro.user +++ b/SRC_v3.41.01-beta/Waifu2x-Extension-QT/Waifu2x-Extension-QT.pro.user @@ -1,346 +1,346 @@ - - - - - - EnvironmentId - {8ba12143-2f96-4a62-9cc5-70a8911b1041} - - - ProjectExplorer.Project.ActiveTarget - 0 - - - ProjectExplorer.Project.EditorSettings - - true - false - true - - Cpp - - CppGlobal - - - - QmlJS - - QmlJSGlobal - - - 2 - UTF-8 - false - 4 - false - 80 - true - true - 1 - true - false - 0 - true - true - 0 - 8 - true - 0 - true - true - true - false - - - - ProjectExplorer.Project.PluginSettings - - - -fno-delayed-template-parsing - - false - {a5ca5d65-944d-44d0-9f07-5c2f9679e35a} - false - - true - - 0 - - - - true - - true - - - - true - - - - ProjectExplorer.Project.Target.0 - - Desktop Qt 5.15.0 MinGW 64-bit - Desktop Qt 5.15.0 MinGW 64-bit - qt.qt5.5150.win64_mingw81_kit - 1 - 0 - 0 - - true - 0 - D:\workspace\Waifu2x-Extension-QT\build-Waifu2x-Extension-QT-Desktop_Qt_5_15_0_MinGW_64_bit-Debug - D:/workspace/Waifu2x-Extension-QT/build-Waifu2x-Extension-QT-Desktop_Qt_5_15_0_MinGW_64_bit-Debug - - - true - QtProjectManager.QMakeBuildStep - - false - - - - true - Qt4ProjectManager.MakeStep - - false - - - false - - 2 - Build - Build - ProjectExplorer.BuildSteps.Build - - - - true - Qt4ProjectManager.MakeStep - - true - clean - - false - - 1 - Clean - Clean - ProjectExplorer.BuildSteps.Clean - - 2 - false - - Debug - Qt4ProjectManager.Qt4BuildConfiguration - 2 - 2 - 2 - - - true - 2 - D:\workspace\Waifu2x-Extension-QT\build-Waifu2x-Extension-QT-Desktop_Qt_5_15_0_MinGW_64_bit-Release - D:/workspace/Waifu2x-Extension-QT/build-Waifu2x-Extension-QT-Desktop_Qt_5_15_0_MinGW_64_bit-Release - - - true - QtProjectManager.QMakeBuildStep - - false - - - - true - Qt4ProjectManager.MakeStep - - false - - - false - - 2 - Build - Build - ProjectExplorer.BuildSteps.Build - - - - true - Qt4ProjectManager.MakeStep - - true - clean - - false - - 1 - Clean - Clean - ProjectExplorer.BuildSteps.Clean - - 2 - false - - Release - Qt4ProjectManager.Qt4BuildConfiguration - 0 - 0 - 2 - - - true - 0 - D:\workspace\Waifu2x-Extension-QT\build-Waifu2x-Extension-QT-Desktop_Qt_5_15_0_MinGW_64_bit-Profile - D:/workspace/Waifu2x-Extension-QT/build-Waifu2x-Extension-QT-Desktop_Qt_5_15_0_MinGW_64_bit-Profile - - - true - QtProjectManager.QMakeBuildStep - - false - - - - true - Qt4ProjectManager.MakeStep - - false - - - false - - 2 - Build - Build - ProjectExplorer.BuildSteps.Build - - - - true - Qt4ProjectManager.MakeStep - - true - clean - - false - - 1 - Clean - Clean - ProjectExplorer.BuildSteps.Clean - - 2 - false - - Profile - Qt4ProjectManager.Qt4BuildConfiguration - 0 - 0 - 0 - - 3 - - - 0 - Deploy - Deploy - ProjectExplorer.BuildSteps.Deploy - - 1 - - false - ProjectExplorer.DefaultDeployConfiguration - - 1 - - - dwarf - - cpu-cycles - - - 250 - - -e - cpu-cycles - --call-graph - dwarf,4096 - -F - 250 - - -F - true - 4096 - false - false - 1000 - - true - - false - false - false - false - true - 0.01 - 10 - true - kcachegrind - 1 - 25 - - 1 - true - false - true - valgrind - - 0 - 1 - 2 - 3 - 4 - 5 - 6 - 7 - 8 - 9 - 10 - 11 - 12 - 13 - 14 - - 0 - - Qt4ProjectManager.Qt4RunConfiguration:D:/workspace/Waifu2x-Extension-QT/Waifu2x-Extension-QT/Waifu2x-Extension-QT.pro - D:/workspace/Waifu2x-Extension-QT/Waifu2x-Extension-QT/Waifu2x-Extension-QT.pro - - false - - false - true - true - false - false - true - - D:/workspace/Waifu2x-Extension-QT/build-Waifu2x-Extension-QT-Desktop_Qt_5_15_0_MinGW_64_bit-Release - - 1 - - - - ProjectExplorer.Project.TargetCount - 1 - - - ProjectExplorer.Project.Updater.FileVersion - 22 - - - Version - 22 - - + + + + + + EnvironmentId + {8ba12143-2f96-4a62-9cc5-70a8911b1041} + + + ProjectExplorer.Project.ActiveTarget + 0 + + + ProjectExplorer.Project.EditorSettings + + true + false + true + + Cpp + + CppGlobal + + + + QmlJS + + QmlJSGlobal + + + 2 + UTF-8 + false + 4 + false + 80 + true + true + 1 + true + false + 0 + true + true + 0 + 8 + true + 0 + true + true + true + false + + + + ProjectExplorer.Project.PluginSettings + + + -fno-delayed-template-parsing + + false + {a5ca5d65-944d-44d0-9f07-5c2f9679e35a} + false + + true + + 0 + + + + true + + true + + + + true + + + + ProjectExplorer.Project.Target.0 + + Desktop Qt 5.15.0 MinGW 64-bit + Desktop Qt 5.15.0 MinGW 64-bit + qt.qt5.5150.win64_mingw81_kit + 1 + 0 + 0 + + true + 0 + D:\workspace\Waifu2x-Extension-QT\build-Waifu2x-Extension-QT-Desktop_Qt_5_15_0_MinGW_64_bit-Debug + D:/workspace/Waifu2x-Extension-QT/build-Waifu2x-Extension-QT-Desktop_Qt_5_15_0_MinGW_64_bit-Debug + + + true + QtProjectManager.QMakeBuildStep + + false + + + + true + Qt4ProjectManager.MakeStep + + false + + + false + + 2 + Build + Build + ProjectExplorer.BuildSteps.Build + + + + true + Qt4ProjectManager.MakeStep + + true + clean + + false + + 1 + Clean + Clean + ProjectExplorer.BuildSteps.Clean + + 2 + false + + Debug + Qt4ProjectManager.Qt4BuildConfiguration + 2 + 2 + 2 + + + true + 2 + D:\workspace\Waifu2x-Extension-QT\build-Waifu2x-Extension-QT-Desktop_Qt_5_15_0_MinGW_64_bit-Release + D:/workspace/Waifu2x-Extension-QT/build-Waifu2x-Extension-QT-Desktop_Qt_5_15_0_MinGW_64_bit-Release + + + true + QtProjectManager.QMakeBuildStep + + false + + + + true + Qt4ProjectManager.MakeStep + + false + + + false + + 2 + Build + Build + ProjectExplorer.BuildSteps.Build + + + + true + Qt4ProjectManager.MakeStep + + true + clean + + false + + 1 + Clean + Clean + ProjectExplorer.BuildSteps.Clean + + 2 + false + + Release + Qt4ProjectManager.Qt4BuildConfiguration + 0 + 0 + 2 + + + true + 0 + D:\workspace\Waifu2x-Extension-QT\build-Waifu2x-Extension-QT-Desktop_Qt_5_15_0_MinGW_64_bit-Profile + D:/workspace/Waifu2x-Extension-QT/build-Waifu2x-Extension-QT-Desktop_Qt_5_15_0_MinGW_64_bit-Profile + + + true + QtProjectManager.QMakeBuildStep + + false + + + + true + Qt4ProjectManager.MakeStep + + false + + + false + + 2 + Build + Build + ProjectExplorer.BuildSteps.Build + + + + true + Qt4ProjectManager.MakeStep + + true + clean + + false + + 1 + Clean + Clean + ProjectExplorer.BuildSteps.Clean + + 2 + false + + Profile + Qt4ProjectManager.Qt4BuildConfiguration + 0 + 0 + 0 + + 3 + + + 0 + Deploy + Deploy + ProjectExplorer.BuildSteps.Deploy + + 1 + + false + ProjectExplorer.DefaultDeployConfiguration + + 1 + + + dwarf + + cpu-cycles + + + 250 + + -e + cpu-cycles + --call-graph + dwarf,4096 + -F + 250 + + -F + true + 4096 + false + false + 1000 + + true + + false + false + false + false + true + 0.01 + 10 + true + kcachegrind + 1 + 25 + + 1 + true + false + true + valgrind + + 0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 + 13 + 14 + + 0 + + Qt4ProjectManager.Qt4RunConfiguration:D:/workspace/Waifu2x-Extension-QT/Waifu2x-Extension-QT/Waifu2x-Extension-QT.pro + D:/workspace/Waifu2x-Extension-QT/Waifu2x-Extension-QT/Waifu2x-Extension-QT.pro + + false + + false + true + true + false + false + true + + D:/workspace/Waifu2x-Extension-QT/build-Waifu2x-Extension-QT-Desktop_Qt_5_15_0_MinGW_64_bit-Release + + 1 + + + + ProjectExplorer.Project.TargetCount + 1 + + + ProjectExplorer.Project.Updater.FileVersion + 22 + + + Version + 22 + + diff --git a/SRC/Waifu2x-Extension-QT/Waifu2x-Extension-QT.pro.user.hLgbqF b/SRC_v3.41.01-beta/Waifu2x-Extension-QT/Waifu2x-Extension-QT.pro.user.hLgbqF similarity index 100% rename from SRC/Waifu2x-Extension-QT/Waifu2x-Extension-QT.pro.user.hLgbqF rename to SRC_v3.41.01-beta/Waifu2x-Extension-QT/Waifu2x-Extension-QT.pro.user.hLgbqF diff --git a/SRC/Waifu2x-Extension-QT/Web_Activities.cpp b/SRC_v3.41.01-beta/Waifu2x-Extension-QT/Web_Activities.cpp similarity index 100% rename from SRC/Waifu2x-Extension-QT/Web_Activities.cpp rename to SRC_v3.41.01-beta/Waifu2x-Extension-QT/Web_Activities.cpp diff --git a/SRC/Waifu2x-Extension-QT/backgroundImage.qrc b/SRC_v3.41.01-beta/Waifu2x-Extension-QT/backgroundImage.qrc similarity index 95% rename from SRC/Waifu2x-Extension-QT/backgroundImage.qrc rename to SRC_v3.41.01-beta/Waifu2x-Extension-QT/backgroundImage.qrc index 3743ddd..51cb67f 100644 --- a/SRC/Waifu2x-Extension-QT/backgroundImage.qrc +++ b/SRC_v3.41.01-beta/Waifu2x-Extension-QT/backgroundImage.qrc @@ -1,5 +1,5 @@ - - - background/luke-chesser.jpg - - + + + background/luke-chesser.jpg + + diff --git a/SRC/Waifu2x-Extension-QT/checkupdate.cpp b/SRC_v3.41.01-beta/Waifu2x-Extension-QT/checkupdate.cpp similarity index 97% rename from SRC/Waifu2x-Extension-QT/checkupdate.cpp rename to SRC_v3.41.01-beta/Waifu2x-Extension-QT/checkupdate.cpp index 768b71e..b0296dd 100644 --- a/SRC/Waifu2x-Extension-QT/checkupdate.cpp +++ b/SRC_v3.41.01-beta/Waifu2x-Extension-QT/checkupdate.cpp @@ -1,189 +1,189 @@ -/* - Copyright (C) 2021 Aaron Feng - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU Affero General Public License as published - by the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Affero General Public License for more details. - - You should have received a copy of the GNU Affero General Public License - along with this program. If not, see . - - My Github homepage: https://github.com/AaronFeng753 -*/ -#include "mainwindow.h" -#include "ui_mainwindow.h" - -/* -手动检查更新:直接打开release页面 -*/ -void MainWindow::on_pushButton_CheckUpdate_clicked() -{ - if(ui->comboBox_language->currentIndex()==1) - { - QDesktopServices::openUrl(QUrl("https://gitee.com/aaronfeng0711/Waifu2x-Extension-GUI/releases")); - } - QDesktopServices::openUrl(QUrl("https://github.com/AaronFeng753/Waifu2x-Extension-GUI/releases")); -} -/* -自动检查更新: -启动软件时以单独线程运行,检测更新,如有则弹窗 -*/ -int MainWindow::CheckUpadte_Auto() -{ - bool isGiteeBanned = ui->checkBox_BanGitee->isChecked(); - //============ - QString Latest_Ver=""; - QString Current_Ver=""; - QString Github_UpdateInfo_online = ""; - QString Gitee_UpdateInfo_online = ""; - QString UpdateType=ui->comboBox_UpdateChannel->currentText(); - switch(ui->comboBox_UpdateChannel->currentIndex()) - { - case 0: - Current_Ver=LastStableVer; - Github_UpdateInfo_online = "https://raw.githubusercontent.com/AaronFeng753/Waifu2x-Extension-GUI/master/.github/Update_Info.ini"; - Gitee_UpdateInfo_online = "https://gitee.com/aaronfeng0711/Waifu2x-Extension-GUI/raw/master/.github/Update_Info.ini"; - break; - case 1: - Current_Ver=LastBetaVer; - Github_UpdateInfo_online = "https://raw.githubusercontent.com/AaronFeng753/Waifu2x-Extension-GUI/master/.github/Update_Info_Beta.ini"; - Gitee_UpdateInfo_online = "https://gitee.com/aaronfeng0711/Waifu2x-Extension-GUI/raw/master/.github/Update_Info_Beta.ini"; - break; - default: - break; - } - //============================ - QString Github_UpdateInfo_local = Current_Path+"/Update_Info_Github.ini"; - QString Gitee_UpdateInfo_local = Current_Path+"/Update_Info_Gitee.ini"; - //============= 从Github下载更新信息 ============== - emit Send_TextBrowser_NewMessage(tr("Starting to download update information(for auto-check update) from Github.")); - DownloadTo(Github_UpdateInfo_online,Github_UpdateInfo_local); - //========= 检查github的文件是否下载成功 ================= - if(QFile::exists(Github_UpdateInfo_local)) - { - emit Send_TextBrowser_NewMessage(tr("Successfully downloaded update information from Github.")); - //== - QSettings *configIniRead = new QSettings(Github_UpdateInfo_local, QSettings::IniFormat); - configIniRead->setIniCodec(QTextCodec::codecForName("UTF-8")); - //===== - if(configIniRead->value("/Latest_Version/Ver") == QVariant() || configIniRead->value("/Change_log/log") == QVariant()) - { - emit Send_TextBrowser_NewMessage(tr("Unable to check for updates! Please check your network or check for updates manually.")); - QFile::remove(Github_UpdateInfo_local); - QFile::remove(Gitee_UpdateInfo_local); - return 0; - } - //===== - Latest_Ver = configIniRead->value("/Latest_Version/Ver").toString(); - QString Change_log = configIniRead->value("/Change_log/log").toString(); - Latest_Ver = Latest_Ver.trimmed(); - if(Latest_Ver!=Current_Ver&&Latest_Ver!="") - { - emit Send_CheckUpadte_NewUpdate(Latest_Ver,Change_log); - } - else - { - emit Send_TextBrowser_NewMessage(tr("No update found, you are using the latest ")+UpdateType+tr(" version.")); - } - QFile::remove(Github_UpdateInfo_local); - QFile::remove(Gitee_UpdateInfo_local); - return 0; - } - else - { - emit Send_TextBrowser_NewMessage(tr("Unable to download update information from Github.")); - } - //============= 从码云下载更新信息 ============== - if(isGiteeBanned==false) - { - emit Send_TextBrowser_NewMessage(tr("Starting to download update information(for auto-check update) from Gitee.")); - DownloadTo(Gitee_UpdateInfo_online,Gitee_UpdateInfo_local); - //========= 检查gitee的文件是否下载成功 ================= - if(QFile::exists(Gitee_UpdateInfo_local)) - { - emit Send_TextBrowser_NewMessage(tr("Successfully downloaded update information from Gitee.")); - //== - QSettings *configIniRead = new QSettings(Gitee_UpdateInfo_local, QSettings::IniFormat); - configIniRead->setIniCodec(QTextCodec::codecForName("UTF-8")); - //===== - if(configIniRead->value("/Latest_Version/Ver") == QVariant() || configIniRead->value("/Change_log/log") == QVariant()) - { - emit Send_TextBrowser_NewMessage(tr("Unable to check for updates! Please check your network or check for updates manually.")); - QFile::remove(Github_UpdateInfo_local); - QFile::remove(Gitee_UpdateInfo_local); - return 0; - } - //===== - Latest_Ver = configIniRead->value("/Latest_Version/Ver").toString(); - QString Change_log = configIniRead->value("/Change_log/log").toString(); - Latest_Ver = Latest_Ver.trimmed(); - if(Latest_Ver!=Current_Ver&&Latest_Ver!="") - { - emit Send_CheckUpadte_NewUpdate(Latest_Ver,Change_log); - } - else - { - emit Send_TextBrowser_NewMessage(tr("No update found, you are using the latest ")+UpdateType+tr(" version.")); - } - QFile::remove(Github_UpdateInfo_local); - QFile::remove(Gitee_UpdateInfo_local); - return 0; - } - else - { - emit Send_TextBrowser_NewMessage(tr("Unable to download update information from Gitee.")); - } - } - if(Latest_Ver=="") - { - emit Send_TextBrowser_NewMessage(tr("Unable to check for updates! Please check your network or check for updates manually.")); - } - QFile::remove(Github_UpdateInfo_local); - QFile::remove(Gitee_UpdateInfo_local); - return 0; -} -/* -自动更新弹窗 -*/ -int MainWindow::CheckUpadte_NewUpdate(QString update_str,QString Change_log) -{ - QString UpdateType=ui->comboBox_UpdateChannel->currentText(); - //====== - if(ui->checkBox_UpdatePopup->isChecked()) - { - QMessageBox Msg(QMessageBox::Question, QString(tr("New ")+UpdateType+tr(" update available!")), QString(tr("New version: %1\n\nBrief change log:\n%2\n\nDo you wanna update now???")).arg(update_str).arg(Change_log)); - Msg.setIcon(QMessageBox::Information); - if(ui->comboBox_language->currentIndex()==1) - { - QAbstractButton *pYesBtn_Github = Msg.addButton(QString("前往Github下载"), QMessageBox::YesRole); - QAbstractButton *pYesBtn_Gitee = Msg.addButton(QString("前往码云下载"), QMessageBox::YesRole); - Msg.addButton(QString(tr("NO")), QMessageBox::NoRole); - Msg.exec(); - if (Msg.clickedButton() == pYesBtn_Github)QDesktopServices::openUrl(QUrl("https://github.com/AaronFeng753/Waifu2x-Extension-GUI/releases/"+update_str.trimmed())); - if (Msg.clickedButton() == pYesBtn_Gitee)QDesktopServices::openUrl(QUrl("https://gitee.com/aaronfeng0711/Waifu2x-Extension-GUI/releases/"+update_str.trimmed())); - return 0; - } - else - { - QAbstractButton *pYesBtn = Msg.addButton(QString(tr("YES")), QMessageBox::YesRole); - Msg.addButton(QString(tr("NO")), QMessageBox::NoRole); - Msg.exec(); - if (Msg.clickedButton() == pYesBtn)QDesktopServices::openUrl(QUrl("https://github.com/AaronFeng753/Waifu2x-Extension-GUI/releases/"+update_str.trimmed())); - return 0; - } - } - else - { - QString update_msg_str = QString(tr("New ")+UpdateType+tr(" update: %1 is available! Click [Check update] button to download the latest version!")).arg(update_str); - emit Send_SystemTray_NewMessage(update_msg_str); - emit Send_TextBrowser_NewMessage(update_msg_str); - } - return 0; -} - +/* + Copyright (C) 2021 Aaron Feng + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU Affero General Public License as published + by the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program. If not, see . + + My Github homepage: https://github.com/AaronFeng753 +*/ +#include "mainwindow.h" +#include "ui_mainwindow.h" + +/* +手动检查更新:直接打开release页面 +*/ +void MainWindow::on_pushButton_CheckUpdate_clicked() +{ + if(ui->comboBox_language->currentIndex()==1) + { + QDesktopServices::openUrl(QUrl("https://gitee.com/aaronfeng0711/Waifu2x-Extension-GUI/releases")); + } + QDesktopServices::openUrl(QUrl("https://github.com/AaronFeng753/Waifu2x-Extension-GUI/releases")); +} +/* +自动检查更新: +启动软件时以单独线程运行,检测更新,如有则弹窗 +*/ +int MainWindow::CheckUpadte_Auto() +{ + bool isGiteeBanned = ui->checkBox_BanGitee->isChecked(); + //============ + QString Latest_Ver=""; + QString Current_Ver=""; + QString Github_UpdateInfo_online = ""; + QString Gitee_UpdateInfo_online = ""; + QString UpdateType=ui->comboBox_UpdateChannel->currentText(); + switch(ui->comboBox_UpdateChannel->currentIndex()) + { + case 0: + Current_Ver=LastStableVer; + Github_UpdateInfo_online = "https://raw.githubusercontent.com/AaronFeng753/Waifu2x-Extension-GUI/master/.github/Update_Info.ini"; + Gitee_UpdateInfo_online = "https://gitee.com/aaronfeng0711/Waifu2x-Extension-GUI/raw/master/.github/Update_Info.ini"; + break; + case 1: + Current_Ver=LastBetaVer; + Github_UpdateInfo_online = "https://raw.githubusercontent.com/AaronFeng753/Waifu2x-Extension-GUI/master/.github/Update_Info_Beta.ini"; + Gitee_UpdateInfo_online = "https://gitee.com/aaronfeng0711/Waifu2x-Extension-GUI/raw/master/.github/Update_Info_Beta.ini"; + break; + default: + break; + } + //============================ + QString Github_UpdateInfo_local = Current_Path+"/Update_Info_Github.ini"; + QString Gitee_UpdateInfo_local = Current_Path+"/Update_Info_Gitee.ini"; + //============= 从Github下载更新信息 ============== + emit Send_TextBrowser_NewMessage(tr("Starting to download update information(for auto-check update) from Github.")); + DownloadTo(Github_UpdateInfo_online,Github_UpdateInfo_local); + //========= 检查github的文件是否下载成功 ================= + if(QFile::exists(Github_UpdateInfo_local)) + { + emit Send_TextBrowser_NewMessage(tr("Successfully downloaded update information from Github.")); + //== + QSettings *configIniRead = new QSettings(Github_UpdateInfo_local, QSettings::IniFormat); + configIniRead->setIniCodec(QTextCodec::codecForName("UTF-8")); + //===== + if(configIniRead->value("/Latest_Version/Ver") == QVariant() || configIniRead->value("/Change_log/log") == QVariant()) + { + emit Send_TextBrowser_NewMessage(tr("Unable to check for updates! Please check your network or check for updates manually.")); + QFile::remove(Github_UpdateInfo_local); + QFile::remove(Gitee_UpdateInfo_local); + return 0; + } + //===== + Latest_Ver = configIniRead->value("/Latest_Version/Ver").toString(); + QString Change_log = configIniRead->value("/Change_log/log").toString(); + Latest_Ver = Latest_Ver.trimmed(); + if(Latest_Ver!=Current_Ver&&Latest_Ver!="") + { + emit Send_CheckUpadte_NewUpdate(Latest_Ver,Change_log); + } + else + { + emit Send_TextBrowser_NewMessage(tr("No update found, you are using the latest ")+UpdateType+tr(" version.")); + } + QFile::remove(Github_UpdateInfo_local); + QFile::remove(Gitee_UpdateInfo_local); + return 0; + } + else + { + emit Send_TextBrowser_NewMessage(tr("Unable to download update information from Github.")); + } + //============= 从码云下载更新信息 ============== + if(isGiteeBanned==false) + { + emit Send_TextBrowser_NewMessage(tr("Starting to download update information(for auto-check update) from Gitee.")); + DownloadTo(Gitee_UpdateInfo_online,Gitee_UpdateInfo_local); + //========= 检查gitee的文件是否下载成功 ================= + if(QFile::exists(Gitee_UpdateInfo_local)) + { + emit Send_TextBrowser_NewMessage(tr("Successfully downloaded update information from Gitee.")); + //== + QSettings *configIniRead = new QSettings(Gitee_UpdateInfo_local, QSettings::IniFormat); + configIniRead->setIniCodec(QTextCodec::codecForName("UTF-8")); + //===== + if(configIniRead->value("/Latest_Version/Ver") == QVariant() || configIniRead->value("/Change_log/log") == QVariant()) + { + emit Send_TextBrowser_NewMessage(tr("Unable to check for updates! Please check your network or check for updates manually.")); + QFile::remove(Github_UpdateInfo_local); + QFile::remove(Gitee_UpdateInfo_local); + return 0; + } + //===== + Latest_Ver = configIniRead->value("/Latest_Version/Ver").toString(); + QString Change_log = configIniRead->value("/Change_log/log").toString(); + Latest_Ver = Latest_Ver.trimmed(); + if(Latest_Ver!=Current_Ver&&Latest_Ver!="") + { + emit Send_CheckUpadte_NewUpdate(Latest_Ver,Change_log); + } + else + { + emit Send_TextBrowser_NewMessage(tr("No update found, you are using the latest ")+UpdateType+tr(" version.")); + } + QFile::remove(Github_UpdateInfo_local); + QFile::remove(Gitee_UpdateInfo_local); + return 0; + } + else + { + emit Send_TextBrowser_NewMessage(tr("Unable to download update information from Gitee.")); + } + } + if(Latest_Ver=="") + { + emit Send_TextBrowser_NewMessage(tr("Unable to check for updates! Please check your network or check for updates manually.")); + } + QFile::remove(Github_UpdateInfo_local); + QFile::remove(Gitee_UpdateInfo_local); + return 0; +} +/* +自动更新弹窗 +*/ +int MainWindow::CheckUpadte_NewUpdate(QString update_str,QString Change_log) +{ + QString UpdateType=ui->comboBox_UpdateChannel->currentText(); + //====== + if(ui->checkBox_UpdatePopup->isChecked()) + { + QMessageBox Msg(QMessageBox::Question, QString(tr("New ")+UpdateType+tr(" update available!")), QString(tr("New version: %1\n\nBrief change log:\n%2\n\nDo you wanna update now???")).arg(update_str).arg(Change_log)); + Msg.setIcon(QMessageBox::Information); + if(ui->comboBox_language->currentIndex()==1) + { + QAbstractButton *pYesBtn_Github = Msg.addButton(QString("前往Github下载"), QMessageBox::YesRole); + QAbstractButton *pYesBtn_Gitee = Msg.addButton(QString("前往码云下载"), QMessageBox::YesRole); + Msg.addButton(QString(tr("NO")), QMessageBox::NoRole); + Msg.exec(); + if (Msg.clickedButton() == pYesBtn_Github)QDesktopServices::openUrl(QUrl("https://github.com/AaronFeng753/Waifu2x-Extension-GUI/releases/"+update_str.trimmed())); + if (Msg.clickedButton() == pYesBtn_Gitee)QDesktopServices::openUrl(QUrl("https://gitee.com/aaronfeng0711/Waifu2x-Extension-GUI/releases/"+update_str.trimmed())); + return 0; + } + else + { + QAbstractButton *pYesBtn = Msg.addButton(QString(tr("YES")), QMessageBox::YesRole); + Msg.addButton(QString(tr("NO")), QMessageBox::NoRole); + Msg.exec(); + if (Msg.clickedButton() == pYesBtn)QDesktopServices::openUrl(QUrl("https://github.com/AaronFeng753/Waifu2x-Extension-GUI/releases/"+update_str.trimmed())); + return 0; + } + } + else + { + QString update_msg_str = QString(tr("New ")+UpdateType+tr(" update: %1 is available! Click [Check update] button to download the latest version!")).arg(update_str); + emit Send_SystemTray_NewMessage(update_msg_str); + emit Send_TextBrowser_NewMessage(update_msg_str); + } + return 0; +} + diff --git a/SRC/Waifu2x-Extension-QT/donate.qrc b/SRC_v3.41.01-beta/Waifu2x-Extension-QT/donate.qrc similarity index 95% rename from SRC/Waifu2x-Extension-QT/donate.qrc rename to SRC_v3.41.01-beta/Waifu2x-Extension-QT/donate.qrc index cff499d..b1b9173 100644 --- a/SRC/Waifu2x-Extension-QT/donate.qrc +++ b/SRC_v3.41.01-beta/Waifu2x-Extension-QT/donate.qrc @@ -1,5 +1,5 @@ - - - donate/Donate_QRCode.jpg - - + + + donate/Donate_QRCode.jpg + + diff --git a/SRC/Waifu2x-Extension-QT/donate/Donate_QRCode.jpg b/SRC_v3.41.01-beta/Waifu2x-Extension-QT/donate/Donate_QRCode.jpg similarity index 100% rename from SRC/Waifu2x-Extension-QT/donate/Donate_QRCode.jpg rename to SRC_v3.41.01-beta/Waifu2x-Extension-QT/donate/Donate_QRCode.jpg diff --git a/SRC/Waifu2x-Extension-QT/files.cpp b/SRC_v3.41.01-beta/Waifu2x-Extension-QT/files.cpp similarity index 96% rename from SRC/Waifu2x-Extension-QT/files.cpp rename to SRC_v3.41.01-beta/Waifu2x-Extension-QT/files.cpp index 46198f2..b5747cd 100644 --- a/SRC/Waifu2x-Extension-QT/files.cpp +++ b/SRC_v3.41.01-beta/Waifu2x-Extension-QT/files.cpp @@ -1,629 +1,629 @@ -/* - Copyright (C) 2021 Aaron Feng - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU Affero General Public License as published - by the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Affero General Public License for more details. - - You should have received a copy of the GNU Affero General Public License - along with this program. If not, see . - - My Github homepage: https://github.com/AaronFeng753 -*/ - -#include "mainwindow.h" -#include "ui_mainwindow.h" - -void MainWindow::dragEnterEvent(QDragEnterEvent *event) -{ - //如果为文件,则支持拖放 - if (event->mimeData()->hasFormat("text/uri-list")) - event->acceptProposedAction(); -} -/* -拖放文件event -*/ -void MainWindow::dropEvent(QDropEvent *event) -{ - //重置 是否有某种类型的新文件加入 的判断标志 - AddNew_gif=false; - AddNew_image=false; - AddNew_video=false; - //================ - QList urls = event->mimeData()->urls(); - if(urls.isEmpty()) - return; - //================== 界面管制 ======================== - ui_tableViews_setUpdatesEnabled(false); - //================ - ui->groupBox_Setting->setEnabled(0); - ui->groupBox_FileList->setEnabled(0); - ui->groupBox_InputExt->setEnabled(0); - pushButton_Start_setEnabled_self(0); - ui->checkBox_ScanSubFolders->setEnabled(0); - this->setAcceptDrops(0); - ui->label_DropFile->setText(tr("Adding files, please wait.")); - emit Send_TextBrowser_NewMessage(tr("Adding files, please wait.")); - //=================================================== - QtConcurrent::run(this, &MainWindow::Read_urls, urls); -} -/* -读取urls -*/ -void MainWindow::Read_urls(QList urls) -{ - Progressbar_MaxVal = urls.size(); - Progressbar_CurrentVal = 0; - emit Send_PrograssBar_Range_min_max(0, Progressbar_MaxVal); - if(ui->checkBox_ScanSubFolders->isChecked()) - { - foreach(QUrl url, urls) - { - Add_File_Folder_IncludeSubFolder(url.toLocalFile()); - emit Send_progressbar_Add(); - } - } - else - { - foreach(QUrl url, urls) - { - Add_File_Folder(url.toLocalFile()); - emit Send_progressbar_Add(); - } - } - emit Send_Read_urls_finfished(); - return; -} -/* -读取urls -善后 -*/ -void MainWindow::Read_urls_finfished() -{ - //================== 解除界面管制 ======================== - ui_tableViews_setUpdatesEnabled(true); - //=== - ui->groupBox_Setting->setEnabled(1); - ui->groupBox_FileList->setEnabled(1); - pushButton_Start_setEnabled_self(1); - ui->groupBox_InputExt->setEnabled(1); - ui->checkBox_ScanSubFolders->setEnabled(1); - this->setAcceptDrops(1); - ui->label_DropFile->setText(tr("Drag and drop files or folders here\n(Image, GIF and Video)")); - emit Send_TextBrowser_NewMessage(tr("Add file complete.")); - //=================================================== - Progressbar_MaxVal = 0; - Progressbar_CurrentVal = 0; - progressbar_clear(); - //====================== - //如果没有增加任何文件 - if(AddNew_gif==false&&AddNew_image==false&&AddNew_video==false) - { - QMessageBox *MSG = new QMessageBox(); - MSG->setWindowTitle(tr("Warning")); - MSG->setText(tr("The file format is not supported, please enter supported file format, or add more file extensions yourself.")); - MSG->setIcon(QMessageBox::Warning); - MSG->setModal(true); - MSG->show(); - return; - } - if(AddNew_image) - { - ui->label_DropFile->setVisible(0);//隐藏文件投放label - ui->tableView_image->setVisible(1); - } - if(AddNew_gif) - { - ui->label_DropFile->setVisible(0);//隐藏文件投放label - ui->tableView_gif->setVisible(1); - } - if(AddNew_video) - { - ui->label_DropFile->setVisible(0);//隐藏文件投放label - ui->tableView_video->setVisible(1); - } - //=================== - ui->tableView_gif->scrollToBottom(); - ui->tableView_image->scrollToBottom(); - ui->tableView_video->scrollToBottom(); - QScrollBar *image_ScrBar = ui->tableView_image->horizontalScrollBar(); - image_ScrBar->setValue(0); - QScrollBar *gif_ScrBar = ui->tableView_gif->horizontalScrollBar(); - gif_ScrBar->setValue(0); - QScrollBar *video_ScrBar = ui->tableView_video->horizontalScrollBar(); - video_ScrBar->setValue(0); - //========== - AddNew_image=false; - AddNew_gif=false; - AddNew_video=false; - //============ - Table_FileCount_reload(); -} - - -/* -添加文件&文件夹 -*/ -void MainWindow::Add_File_Folder(QString Full_Path) -{ - QFileInfo fileinfo(Full_Path); - if(fileinfo.isFile()) - { - QString file_name = fileinfo.fileName(); - FileList_Add(file_name, Full_Path); - } - else - { - QStringList FileNameList = file_getFileNames_in_Folder_nofilter(Full_Path);//读取合法的文件名 - QString Full_Path_File = ""; - if(!FileNameList.isEmpty()) - { - QString tmp=""; - for(int i = 0; i < FileNameList.size(); i++) - { - tmp = FileNameList.at(i); - Full_Path_File = Full_Path + "/" + tmp; - FileList_Add(tmp, Full_Path_File); - } - } - } -} -/* -添加文件&文件夹 -扫描子文件夹 -*/ -void MainWindow::Add_File_Folder_IncludeSubFolder(QString Full_Path) -{ - QFileInfo fileinfo(Full_Path); - if(fileinfo.isFile()) - { - QString file_name = fileinfo.fileName(); - FileList_Add(file_name, Full_Path); - } - else - { - QStringList FileNameList = getFileNames_IncludeSubFolder(Full_Path);//读取合法的文件名 - QString Full_Path_File = ""; - if(!FileNameList.isEmpty()) - { - QString tmp=""; - for(int i = 0; i < FileNameList.size(); i++) - { - tmp = FileNameList.at(i); - Full_Path_File = Full_Path + "/" + tmp; - QFileInfo fileinfo_tmp(Full_Path_File); - if(fileinfo_tmp.isFile()) - { - if(QFile::exists(Full_Path_File))FileList_Add(tmp, Full_Path_File); - } - else - { - //if(QFile::exists(Full_Path_File)) - if(file_isDirExist(Full_Path_File))Add_File_Folder_IncludeSubFolder(Full_Path_File); - } - } - } - } -} -/* -读取文件夹下的文件名(包括子文件夹 -*/ -QStringList MainWindow::getFileNames_IncludeSubFolder(QString path) -{ - QDir dir(path); - QStringList files_old; - QStringList files_new; - while(true) - { - files_new = dir.entryList(QDir::Dirs | QDir::Files | QDir::Writable, QDir::Name); - if(files_new!=files_old) - { - files_old = files_new; - Delay_msec_sleep(100); - } - else - { - break; - } - } - files_new.removeAll(".."); - files_new.removeAll("."); - return files_new; -} -/* -扫描文件夹下文件名列表(无过滤 -*/ -QStringList MainWindow::file_getFileNames_in_Folder_nofilter(QString path) -{ - QDir dir(path); - QStringList files_old; - QStringList files_new; - while(true) - { - files_new = dir.entryList(QDir::Files | QDir::Writable, QDir::Name); - if(files_new!=files_old) - { - files_old = files_new; - Delay_msec_sleep(100); - } - else - { - break; - } - } - files_new.removeAll(".."); - files_new.removeAll("."); - return files_new; -} - -/* -向文件列表和table添加文件 -*/ -int MainWindow::FileList_Add(QString fileName, QString SourceFile_fullPath) -{ - QFileInfo fileinfo(SourceFile_fullPath); - QString file_ext = fileinfo.suffix().toLower(); - //============================ 判断是否为图片 =============================== - QString Ext_image_str = ui->Ext_image->text().toLower(); - QStringList nameFilters_image = Ext_image_str.split(":"); - nameFilters_image.removeAll("gif"); - nameFilters_image.removeAll("apng"); - if (nameFilters_image.contains(file_ext)) - { - AddNew_image=true; - int rowNum = Table_image_get_rowNum(); - QMap map; - map["SourceFile_fullPath"] = SourceFile_fullPath; - map["rowNum"] = QString::number(rowNum, 10); - if(!Deduplicate_filelist(SourceFile_fullPath)) - { - mutex_Table_insert_finished.lock(); - Table_insert_finished=false; - mutex_Table_insert_finished.unlock(); - emit Send_Table_image_insert_fileName_fullPath(fileName, SourceFile_fullPath); - while(!Table_insert_finished) - { - Delay_msec_sleep(10); - } - } - return 0; - } - //============================ 判断是否为视频 =============================== - QString Ext_video_str = ui->Ext_video->text().toLower(); - QStringList nameFilters_video = Ext_video_str.split(":"); - nameFilters_video.removeAll("gif"); - nameFilters_video.removeAll("apng"); - if (nameFilters_video.contains(file_ext)) - { - AddNew_video=true; - int rowNum = Table_video_get_rowNum(); - QMap map; - map["SourceFile_fullPath"] = SourceFile_fullPath; - map["rowNum"] = QString::number(rowNum, 10); - if(!Deduplicate_filelist(SourceFile_fullPath)) - { - mutex_Table_insert_finished.lock(); - Table_insert_finished=false; - mutex_Table_insert_finished.unlock(); - emit Send_Table_video_insert_fileName_fullPath(fileName, SourceFile_fullPath); - while(!Table_insert_finished) - { - Delay_msec_sleep(10); - } - } - return 0; - } - //============================ 最后只能是gif & apng =============================== - if(file_ext=="gif" || file_ext=="apng") - { - int rowNum = Table_gif_get_rowNum(); - QMap map; - map["SourceFile_fullPath"] = SourceFile_fullPath; - map["rowNum"] = QString::number(rowNum, 10); - AddNew_gif=true; - if(!Deduplicate_filelist(SourceFile_fullPath)) - { - mutex_Table_insert_finished.lock(); - Table_insert_finished=false; - mutex_Table_insert_finished.unlock(); - emit Send_Table_gif_insert_fileName_fullPath(fileName, SourceFile_fullPath); - while(!Table_insert_finished) - { - Delay_msec_sleep(10); - } - } - return 0; - } - return 0; -} -/* -判断是否已经在文件列表内 -*/ -bool MainWindow::Deduplicate_filelist(QString SourceFile_fullPath) -{ - for ( int i = 0; i < Table_model_image->rowCount(); i++ ) - { - QString fullpath_readRow = Table_model_image->item(i,2)->text(); - if(fullpath_readRow == SourceFile_fullPath) - { - return true; - } - } - for ( int i = 0; i < Table_model_gif->rowCount(); i++ ) - { - QString fullpath_readRow = Table_model_gif->item(i,2)->text(); - if(fullpath_readRow == SourceFile_fullPath) - { - return true; - } - } - for ( int i = 0; i < Table_model_video->rowCount(); i++ ) - { - QString fullpath_readRow = Table_model_video->item(i,2)->text(); - if(fullpath_readRow == SourceFile_fullPath) - { - return true; - } - } - return false; -} -/* -文件夹是否存在 -*/ -bool MainWindow::file_isDirExist(QString SourceFile_fullPath) -{ - QDir dir(SourceFile_fullPath.trimmed()); - return dir.exists(); -} -/* -创建文件夹 -*/ -void MainWindow::file_mkDir(QString SourceFile_fullPath) -{ - QDir dir(SourceFile_fullPath); - if(dir.exists() == false) - { - dir.mkdir(SourceFile_fullPath); - } -} -/* -文件夹是为空 -*/ -bool MainWindow::file_isDirEmpty(QString FolderPath) -{ - QDir dir(FolderPath); - return dir.isEmpty(); -} - -/* -删除文件夹 -*/ -bool MainWindow::file_DelDir(const QString &path) -{ - if (path.isEmpty()) - { - return false; - } - QDir dir(path); - if(!dir.exists()) - { - return true; - } - dir.setFilter(QDir::AllEntries | QDir::NoDotAndDotDot); //设置过滤 - QFileInfoList fileList = dir.entryInfoList(); // 获取所有的文件信息 - foreach (QFileInfo file, fileList) //遍历文件信息 - { - if (file.isFile()) // 是文件,删除 - { - file.dir().remove(file.fileName()); - } - else // 递归删除 - { - file_DelDir(file.absoluteFilePath()); - } - } - return dir.rmpath(dir.absolutePath()); // 删除文件夹 -} -/* -重写的获取basename函数 -*/ -QString MainWindow::file_getBaseName(QString path) -{ - QFileInfo fileinfo(path); - QString file_fullname = fileinfo.fileName(); - QStringList parts = file_fullname.split("."); - QString file_basename=""; - for(int i=0; i<(parts.size()-1); i++) - { - file_basename+=parts.at(i); - file_basename+="."; - } - if(file_basename.right(1)==".") - { - file_basename = file_basename.left(file_basename.length() - 1); - } - return file_basename; -} -/* -移动文件到回收站 -*/ -void MainWindow::file_MoveToTrash( QString file ) -{ - QFileInfo fileinfo( file ); - if( !fileinfo.exists() ) - return; - WCHAR from[ MAX_PATH ]; - memset( from, 0, sizeof( from )); - int l = fileinfo.absoluteFilePath().toWCharArray( from ); - Q_ASSERT( 0 <= l && l < MAX_PATH ); - from[ l ] = '\0'; - SHFILEOPSTRUCT fileop; - memset( &fileop, 0, sizeof( fileop ) ); - fileop.wFunc = FO_DELETE; - fileop.pFrom = from; - fileop.fFlags = FOF_ALLOWUNDO | FOF_NOCONFIRMATION | FOF_NOERRORUI | FOF_SILENT; - int rv = SHFileOperation( &fileop ); - if( 0 != rv ) - { - return; - } -} - -/* -获取文件夹路径(去除末尾的"/") -*/ -QString MainWindow::file_getFolderPath(QFileInfo fileInfo) -{ - QString folder_path = fileInfo.path(); - if(folder_path.right(1)=="/") - { - folder_path = folder_path.left(folder_path.length() - 1); - } - return folder_path; -} -/* -检测文件夹是否可写入 -*/ -bool MainWindow::file_isDirWritable(QString DirPath) -{ - if(DirPath.right(1)=="/") - { - DirPath = DirPath.left(DirPath.length() - 1); - } - QString TestTemp = DirPath+"/RWTest_W2xEX.tmp"; - QFile file_TestTemp(TestTemp); - file_TestTemp.remove(); - if (file_TestTemp.open(QIODevice::ReadWrite | QIODevice::Text)) //QIODevice::ReadWrite支持读写 - { - QTextStream stream(&file_TestTemp); - stream << "W2xEX"; - } - if(QFile::exists(TestTemp)) - { - file_TestTemp.remove(); - return true; - } - else - { - file_TestTemp.remove(); - return false; - } -} -/* -判断当前处理的文件所在的文件夹是否可以写入 -*/ -bool MainWindow::file_isFilesFolderWritable_row_image(int rowNum) -{ - QString SourceFile_fullPath = Table_model_image->item(rowNum,2)->text(); - QFileInfo fileinfo(SourceFile_fullPath); - QString file_FolderPath = file_getFolderPath(fileinfo); - if(file_isDirWritable(file_FolderPath)) - { - return true; - } - else - { - emit Send_TextBrowser_NewMessage(tr("Error occured when processing [")+SourceFile_fullPath+tr("]. Error: [Insufficient permissions, administrator permissions is needed.]")); - QString status = "Failed"; - emit Send_Table_image_ChangeStatus_rowNumInt_statusQString(rowNum, status); - return false; - } -} - -bool MainWindow::file_isFilesFolderWritable_row_gif(int rowNum) -{ - QString SourceFile_fullPath = Table_model_gif->item(rowNum,2)->text(); - QFileInfo fileinfo(SourceFile_fullPath); - QString file_FolderPath = file_getFolderPath(fileinfo); - if(file_isDirWritable(file_FolderPath)) - { - return true; - } - else - { - emit Send_TextBrowser_NewMessage(tr("Error occured when processing [")+SourceFile_fullPath+tr("]. Error: [Insufficient permissions, administrator permissions is needed.]")); - QString status = "Failed"; - emit Send_Table_gif_ChangeStatus_rowNumInt_statusQString(rowNum, status); - return false; - } -} - -bool MainWindow::file_isFilesFolderWritable_row_video(int rowNum) -{ - QString SourceFile_fullPath = Table_model_video->item(rowNum,2)->text(); - QFileInfo fileinfo(SourceFile_fullPath); - QString file_FolderPath = file_getFolderPath(fileinfo); - if(file_isDirWritable(file_FolderPath)) - { - return true; - } - else - { - emit Send_TextBrowser_NewMessage(tr("Error occured when processing [")+SourceFile_fullPath+tr("]. Error: [Insufficient permissions, administrator permissions is needed.]")); - emit Send_Table_video_ChangeStatus_rowNumInt_statusQString(rowNum, "Failed"); - return false; - } -} - -bool MainWindow::file_OpenFolder(QString FolderPath) -{ - if(file_isDirExist(FolderPath)) - { - FolderPath= FolderPath.replace("/","\\"); - QProcess::execute("explorer \""+FolderPath+"\""); - return true; - } - else - { - return false; - } -} - -bool MainWindow::file_OpenFilesFolder(QString FilePath) -{ - QFileInfo finfo = QFileInfo(FilePath); - return file_OpenFolder(file_getFolderPath(finfo)); -} - -bool MainWindow::file_OpenFile(QString FilePath) -{ - if(QFile::exists(FilePath)) - { - if(QDesktopServices::openUrl(QUrl("file:"+QUrl::toPercentEncoding(FilePath),QUrl::TolerantMode))==false) - { - ExecuteCMD_batFile("start \"\" \""+FilePath.replace("%","%%")+"\"",false); - } - return true; - } - else - { - return false; - } -} - -bool MainWindow::file_generateMarkFile(QString FileFullPath,QString Msg) -{ - QFile file(FileFullPath); - file.remove(); - if (file.open(QIODevice::ReadWrite | QIODevice::Text)) //QIODevice::ReadWrite支持读写 - { - QTextStream stream(&file); - if(Msg.trimmed() == "") - { - stream << "Waifu2x-Extension-GUI\nDo NOT delete this file!!"; - } - else - { - stream << Msg; - } - } - return file.exists(); -} - - +/* + Copyright (C) 2021 Aaron Feng + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU Affero General Public License as published + by the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program. If not, see . + + My Github homepage: https://github.com/AaronFeng753 +*/ + +#include "mainwindow.h" +#include "ui_mainwindow.h" + +void MainWindow::dragEnterEvent(QDragEnterEvent *event) +{ + //如果为文件,则支持拖放 + if (event->mimeData()->hasFormat("text/uri-list")) + event->acceptProposedAction(); +} +/* +拖放文件event +*/ +void MainWindow::dropEvent(QDropEvent *event) +{ + //重置 是否有某种类型的新文件加入 的判断标志 + AddNew_gif=false; + AddNew_image=false; + AddNew_video=false; + //================ + QList urls = event->mimeData()->urls(); + if(urls.isEmpty()) + return; + //================== 界面管制 ======================== + ui_tableViews_setUpdatesEnabled(false); + //================ + ui->groupBox_Setting->setEnabled(0); + ui->groupBox_FileList->setEnabled(0); + ui->groupBox_InputExt->setEnabled(0); + pushButton_Start_setEnabled_self(0); + ui->checkBox_ScanSubFolders->setEnabled(0); + this->setAcceptDrops(0); + ui->label_DropFile->setText(tr("Adding files, please wait.")); + emit Send_TextBrowser_NewMessage(tr("Adding files, please wait.")); + //=================================================== + QtConcurrent::run(this, &MainWindow::Read_urls, urls); +} +/* +读取urls +*/ +void MainWindow::Read_urls(QList urls) +{ + Progressbar_MaxVal = urls.size(); + Progressbar_CurrentVal = 0; + emit Send_PrograssBar_Range_min_max(0, Progressbar_MaxVal); + if(ui->checkBox_ScanSubFolders->isChecked()) + { + foreach(QUrl url, urls) + { + Add_File_Folder_IncludeSubFolder(url.toLocalFile()); + emit Send_progressbar_Add(); + } + } + else + { + foreach(QUrl url, urls) + { + Add_File_Folder(url.toLocalFile()); + emit Send_progressbar_Add(); + } + } + emit Send_Read_urls_finfished(); + return; +} +/* +读取urls +善后 +*/ +void MainWindow::Read_urls_finfished() +{ + //================== 解除界面管制 ======================== + ui_tableViews_setUpdatesEnabled(true); + //=== + ui->groupBox_Setting->setEnabled(1); + ui->groupBox_FileList->setEnabled(1); + pushButton_Start_setEnabled_self(1); + ui->groupBox_InputExt->setEnabled(1); + ui->checkBox_ScanSubFolders->setEnabled(1); + this->setAcceptDrops(1); + ui->label_DropFile->setText(tr("Drag and drop files or folders here\n(Image, GIF and Video)")); + emit Send_TextBrowser_NewMessage(tr("Add file complete.")); + //=================================================== + Progressbar_MaxVal = 0; + Progressbar_CurrentVal = 0; + progressbar_clear(); + //====================== + //如果没有增加任何文件 + if(AddNew_gif==false&&AddNew_image==false&&AddNew_video==false) + { + QMessageBox *MSG = new QMessageBox(); + MSG->setWindowTitle(tr("Warning")); + MSG->setText(tr("The file format is not supported, please enter supported file format, or add more file extensions yourself.")); + MSG->setIcon(QMessageBox::Warning); + MSG->setModal(true); + MSG->show(); + return; + } + if(AddNew_image) + { + ui->label_DropFile->setVisible(0);//隐藏文件投放label + ui->tableView_image->setVisible(1); + } + if(AddNew_gif) + { + ui->label_DropFile->setVisible(0);//隐藏文件投放label + ui->tableView_gif->setVisible(1); + } + if(AddNew_video) + { + ui->label_DropFile->setVisible(0);//隐藏文件投放label + ui->tableView_video->setVisible(1); + } + //=================== + ui->tableView_gif->scrollToBottom(); + ui->tableView_image->scrollToBottom(); + ui->tableView_video->scrollToBottom(); + QScrollBar *image_ScrBar = ui->tableView_image->horizontalScrollBar(); + image_ScrBar->setValue(0); + QScrollBar *gif_ScrBar = ui->tableView_gif->horizontalScrollBar(); + gif_ScrBar->setValue(0); + QScrollBar *video_ScrBar = ui->tableView_video->horizontalScrollBar(); + video_ScrBar->setValue(0); + //========== + AddNew_image=false; + AddNew_gif=false; + AddNew_video=false; + //============ + Table_FileCount_reload(); +} + + +/* +添加文件&文件夹 +*/ +void MainWindow::Add_File_Folder(QString Full_Path) +{ + QFileInfo fileinfo(Full_Path); + if(fileinfo.isFile()) + { + QString file_name = fileinfo.fileName(); + FileList_Add(file_name, Full_Path); + } + else + { + QStringList FileNameList = file_getFileNames_in_Folder_nofilter(Full_Path);//读取合法的文件名 + QString Full_Path_File = ""; + if(!FileNameList.isEmpty()) + { + QString tmp=""; + for(int i = 0; i < FileNameList.size(); i++) + { + tmp = FileNameList.at(i); + Full_Path_File = Full_Path + "/" + tmp; + FileList_Add(tmp, Full_Path_File); + } + } + } +} +/* +添加文件&文件夹 +扫描子文件夹 +*/ +void MainWindow::Add_File_Folder_IncludeSubFolder(QString Full_Path) +{ + QFileInfo fileinfo(Full_Path); + if(fileinfo.isFile()) + { + QString file_name = fileinfo.fileName(); + FileList_Add(file_name, Full_Path); + } + else + { + QStringList FileNameList = getFileNames_IncludeSubFolder(Full_Path);//读取合法的文件名 + QString Full_Path_File = ""; + if(!FileNameList.isEmpty()) + { + QString tmp=""; + for(int i = 0; i < FileNameList.size(); i++) + { + tmp = FileNameList.at(i); + Full_Path_File = Full_Path + "/" + tmp; + QFileInfo fileinfo_tmp(Full_Path_File); + if(fileinfo_tmp.isFile()) + { + if(QFile::exists(Full_Path_File))FileList_Add(tmp, Full_Path_File); + } + else + { + //if(QFile::exists(Full_Path_File)) + if(file_isDirExist(Full_Path_File))Add_File_Folder_IncludeSubFolder(Full_Path_File); + } + } + } + } +} +/* +读取文件夹下的文件名(包括子文件夹 +*/ +QStringList MainWindow::getFileNames_IncludeSubFolder(QString path) +{ + QDir dir(path); + QStringList files_old; + QStringList files_new; + while(true) + { + files_new = dir.entryList(QDir::Dirs | QDir::Files | QDir::Writable, QDir::Name); + if(files_new!=files_old) + { + files_old = files_new; + Delay_msec_sleep(100); + } + else + { + break; + } + } + files_new.removeAll(".."); + files_new.removeAll("."); + return files_new; +} +/* +扫描文件夹下文件名列表(无过滤 +*/ +QStringList MainWindow::file_getFileNames_in_Folder_nofilter(QString path) +{ + QDir dir(path); + QStringList files_old; + QStringList files_new; + while(true) + { + files_new = dir.entryList(QDir::Files | QDir::Writable, QDir::Name); + if(files_new!=files_old) + { + files_old = files_new; + Delay_msec_sleep(100); + } + else + { + break; + } + } + files_new.removeAll(".."); + files_new.removeAll("."); + return files_new; +} + +/* +向文件列表和table添加文件 +*/ +int MainWindow::FileList_Add(QString fileName, QString SourceFile_fullPath) +{ + QFileInfo fileinfo(SourceFile_fullPath); + QString file_ext = fileinfo.suffix().toLower(); + //============================ 判断是否为图片 =============================== + QString Ext_image_str = ui->Ext_image->text().toLower(); + QStringList nameFilters_image = Ext_image_str.split(":"); + nameFilters_image.removeAll("gif"); + nameFilters_image.removeAll("apng"); + if (nameFilters_image.contains(file_ext)) + { + AddNew_image=true; + int rowNum = Table_image_get_rowNum(); + QMap map; + map["SourceFile_fullPath"] = SourceFile_fullPath; + map["rowNum"] = QString::number(rowNum, 10); + if(!Deduplicate_filelist(SourceFile_fullPath)) + { + mutex_Table_insert_finished.lock(); + Table_insert_finished=false; + mutex_Table_insert_finished.unlock(); + emit Send_Table_image_insert_fileName_fullPath(fileName, SourceFile_fullPath); + while(!Table_insert_finished) + { + Delay_msec_sleep(10); + } + } + return 0; + } + //============================ 判断是否为视频 =============================== + QString Ext_video_str = ui->Ext_video->text().toLower(); + QStringList nameFilters_video = Ext_video_str.split(":"); + nameFilters_video.removeAll("gif"); + nameFilters_video.removeAll("apng"); + if (nameFilters_video.contains(file_ext)) + { + AddNew_video=true; + int rowNum = Table_video_get_rowNum(); + QMap map; + map["SourceFile_fullPath"] = SourceFile_fullPath; + map["rowNum"] = QString::number(rowNum, 10); + if(!Deduplicate_filelist(SourceFile_fullPath)) + { + mutex_Table_insert_finished.lock(); + Table_insert_finished=false; + mutex_Table_insert_finished.unlock(); + emit Send_Table_video_insert_fileName_fullPath(fileName, SourceFile_fullPath); + while(!Table_insert_finished) + { + Delay_msec_sleep(10); + } + } + return 0; + } + //============================ 最后只能是gif & apng =============================== + if(file_ext=="gif" || file_ext=="apng") + { + int rowNum = Table_gif_get_rowNum(); + QMap map; + map["SourceFile_fullPath"] = SourceFile_fullPath; + map["rowNum"] = QString::number(rowNum, 10); + AddNew_gif=true; + if(!Deduplicate_filelist(SourceFile_fullPath)) + { + mutex_Table_insert_finished.lock(); + Table_insert_finished=false; + mutex_Table_insert_finished.unlock(); + emit Send_Table_gif_insert_fileName_fullPath(fileName, SourceFile_fullPath); + while(!Table_insert_finished) + { + Delay_msec_sleep(10); + } + } + return 0; + } + return 0; +} +/* +判断是否已经在文件列表内 +*/ +bool MainWindow::Deduplicate_filelist(QString SourceFile_fullPath) +{ + for ( int i = 0; i < Table_model_image->rowCount(); i++ ) + { + QString fullpath_readRow = Table_model_image->item(i,2)->text(); + if(fullpath_readRow == SourceFile_fullPath) + { + return true; + } + } + for ( int i = 0; i < Table_model_gif->rowCount(); i++ ) + { + QString fullpath_readRow = Table_model_gif->item(i,2)->text(); + if(fullpath_readRow == SourceFile_fullPath) + { + return true; + } + } + for ( int i = 0; i < Table_model_video->rowCount(); i++ ) + { + QString fullpath_readRow = Table_model_video->item(i,2)->text(); + if(fullpath_readRow == SourceFile_fullPath) + { + return true; + } + } + return false; +} +/* +文件夹是否存在 +*/ +bool MainWindow::file_isDirExist(QString SourceFile_fullPath) +{ + QDir dir(SourceFile_fullPath.trimmed()); + return dir.exists(); +} +/* +创建文件夹 +*/ +void MainWindow::file_mkDir(QString SourceFile_fullPath) +{ + QDir dir(SourceFile_fullPath); + if(dir.exists() == false) + { + dir.mkdir(SourceFile_fullPath); + } +} +/* +文件夹是为空 +*/ +bool MainWindow::file_isDirEmpty(QString FolderPath) +{ + QDir dir(FolderPath); + return dir.isEmpty(); +} + +/* +删除文件夹 +*/ +bool MainWindow::file_DelDir(const QString &path) +{ + if (path.isEmpty()) + { + return false; + } + QDir dir(path); + if(!dir.exists()) + { + return true; + } + dir.setFilter(QDir::AllEntries | QDir::NoDotAndDotDot); //设置过滤 + QFileInfoList fileList = dir.entryInfoList(); // 获取所有的文件信息 + foreach (QFileInfo file, fileList) //遍历文件信息 + { + if (file.isFile()) // 是文件,删除 + { + file.dir().remove(file.fileName()); + } + else // 递归删除 + { + file_DelDir(file.absoluteFilePath()); + } + } + return dir.rmpath(dir.absolutePath()); // 删除文件夹 +} +/* +重写的获取basename函数 +*/ +QString MainWindow::file_getBaseName(QString path) +{ + QFileInfo fileinfo(path); + QString file_fullname = fileinfo.fileName(); + QStringList parts = file_fullname.split("."); + QString file_basename=""; + for(int i=0; i<(parts.size()-1); i++) + { + file_basename+=parts.at(i); + file_basename+="."; + } + if(file_basename.right(1)==".") + { + file_basename = file_basename.left(file_basename.length() - 1); + } + return file_basename; +} +/* +移动文件到回收站 +*/ +void MainWindow::file_MoveToTrash( QString file ) +{ + QFileInfo fileinfo( file ); + if( !fileinfo.exists() ) + return; + WCHAR from[ MAX_PATH ]; + memset( from, 0, sizeof( from )); + int l = fileinfo.absoluteFilePath().toWCharArray( from ); + Q_ASSERT( 0 <= l && l < MAX_PATH ); + from[ l ] = '\0'; + SHFILEOPSTRUCT fileop; + memset( &fileop, 0, sizeof( fileop ) ); + fileop.wFunc = FO_DELETE; + fileop.pFrom = from; + fileop.fFlags = FOF_ALLOWUNDO | FOF_NOCONFIRMATION | FOF_NOERRORUI | FOF_SILENT; + int rv = SHFileOperation( &fileop ); + if( 0 != rv ) + { + return; + } +} + +/* +获取文件夹路径(去除末尾的"/") +*/ +QString MainWindow::file_getFolderPath(QFileInfo fileInfo) +{ + QString folder_path = fileInfo.path(); + if(folder_path.right(1)=="/") + { + folder_path = folder_path.left(folder_path.length() - 1); + } + return folder_path; +} +/* +检测文件夹是否可写入 +*/ +bool MainWindow::file_isDirWritable(QString DirPath) +{ + if(DirPath.right(1)=="/") + { + DirPath = DirPath.left(DirPath.length() - 1); + } + QString TestTemp = DirPath+"/RWTest_W2xEX.tmp"; + QFile file_TestTemp(TestTemp); + file_TestTemp.remove(); + if (file_TestTemp.open(QIODevice::ReadWrite | QIODevice::Text)) //QIODevice::ReadWrite支持读写 + { + QTextStream stream(&file_TestTemp); + stream << "W2xEX"; + } + if(QFile::exists(TestTemp)) + { + file_TestTemp.remove(); + return true; + } + else + { + file_TestTemp.remove(); + return false; + } +} +/* +判断当前处理的文件所在的文件夹是否可以写入 +*/ +bool MainWindow::file_isFilesFolderWritable_row_image(int rowNum) +{ + QString SourceFile_fullPath = Table_model_image->item(rowNum,2)->text(); + QFileInfo fileinfo(SourceFile_fullPath); + QString file_FolderPath = file_getFolderPath(fileinfo); + if(file_isDirWritable(file_FolderPath)) + { + return true; + } + else + { + emit Send_TextBrowser_NewMessage(tr("Error occured when processing [")+SourceFile_fullPath+tr("]. Error: [Insufficient permissions, administrator permissions is needed.]")); + QString status = "Failed"; + emit Send_Table_image_ChangeStatus_rowNumInt_statusQString(rowNum, status); + return false; + } +} + +bool MainWindow::file_isFilesFolderWritable_row_gif(int rowNum) +{ + QString SourceFile_fullPath = Table_model_gif->item(rowNum,2)->text(); + QFileInfo fileinfo(SourceFile_fullPath); + QString file_FolderPath = file_getFolderPath(fileinfo); + if(file_isDirWritable(file_FolderPath)) + { + return true; + } + else + { + emit Send_TextBrowser_NewMessage(tr("Error occured when processing [")+SourceFile_fullPath+tr("]. Error: [Insufficient permissions, administrator permissions is needed.]")); + QString status = "Failed"; + emit Send_Table_gif_ChangeStatus_rowNumInt_statusQString(rowNum, status); + return false; + } +} + +bool MainWindow::file_isFilesFolderWritable_row_video(int rowNum) +{ + QString SourceFile_fullPath = Table_model_video->item(rowNum,2)->text(); + QFileInfo fileinfo(SourceFile_fullPath); + QString file_FolderPath = file_getFolderPath(fileinfo); + if(file_isDirWritable(file_FolderPath)) + { + return true; + } + else + { + emit Send_TextBrowser_NewMessage(tr("Error occured when processing [")+SourceFile_fullPath+tr("]. Error: [Insufficient permissions, administrator permissions is needed.]")); + emit Send_Table_video_ChangeStatus_rowNumInt_statusQString(rowNum, "Failed"); + return false; + } +} + +bool MainWindow::file_OpenFolder(QString FolderPath) +{ + if(file_isDirExist(FolderPath)) + { + FolderPath= FolderPath.replace("/","\\"); + QProcess::execute("explorer \""+FolderPath+"\""); + return true; + } + else + { + return false; + } +} + +bool MainWindow::file_OpenFilesFolder(QString FilePath) +{ + QFileInfo finfo = QFileInfo(FilePath); + return file_OpenFolder(file_getFolderPath(finfo)); +} + +bool MainWindow::file_OpenFile(QString FilePath) +{ + if(QFile::exists(FilePath)) + { + if(QDesktopServices::openUrl(QUrl("file:"+QUrl::toPercentEncoding(FilePath),QUrl::TolerantMode))==false) + { + ExecuteCMD_batFile("start \"\" \""+FilePath.replace("%","%%")+"\"",false); + } + return true; + } + else + { + return false; + } +} + +bool MainWindow::file_generateMarkFile(QString FileFullPath,QString Msg) +{ + QFile file(FileFullPath); + file.remove(); + if (file.open(QIODevice::ReadWrite | QIODevice::Text)) //QIODevice::ReadWrite支持读写 + { + QTextStream stream(&file); + if(Msg.trimmed() == "") + { + stream << "Waifu2x-Extension-GUI\nDo NOT delete this file!!"; + } + else + { + stream << Msg; + } + } + return file.exists(); +} + + diff --git a/SRC/Waifu2x-Extension-QT/gif.cpp b/SRC_v3.41.01-beta/Waifu2x-Extension-QT/gif.cpp similarity index 97% rename from SRC/Waifu2x-Extension-QT/gif.cpp rename to SRC_v3.41.01-beta/Waifu2x-Extension-QT/gif.cpp index a6b5c54..f3cc985 100644 --- a/SRC/Waifu2x-Extension-QT/gif.cpp +++ b/SRC_v3.41.01-beta/Waifu2x-Extension-QT/gif.cpp @@ -1,310 +1,310 @@ -/* - Copyright (C) 2021 Aaron Feng - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU Affero General Public License as published - by the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Affero General Public License for more details. - - You should have received a copy of the GNU Affero General Public License - along with this program. If not, see . - - My Github homepage: https://github.com/AaronFeng753 -*/ - -#include "mainwindow.h" -#include "ui_mainwindow.h" -/* -根据行数从自定义分辨率列表移除gif文件 -*/ -void MainWindow::Gif_RemoveFromCustResList(int RowNumber) -{ - QString SourceFile_fullPath = Table_model_gif->item(RowNumber,2)->text(); - CustRes_remove(SourceFile_fullPath); -} - -/* -当gif没有自定义分辨率且此时放大倍率为double,则计算一个添加到自定义列表里 -*/ -bool MainWindow::Gif_DoubleScaleRatioPrep(int RowNumber) -{ - QString SourceFile_fullPath = Table_model_gif->item(RowNumber,2)->text(); - if(CustRes_isContained(SourceFile_fullPath) == true) - { - return false; - } - else - { - //===================== 获取分辨率 ============================= - QMap Map_OrgRes = Image_Gif_Read_Resolution(SourceFile_fullPath); - //========= 计算新的高度宽度 ================== - double ScaleRatio_double = ui->doubleSpinBox_ScaleRatio_gif->value(); - int Height_new = qRound(ScaleRatio_double * Map_OrgRes["height"]); - int width_new = qRound(ScaleRatio_double * Map_OrgRes["width"]); - if(Height_new<1 || width_new<1) - { - emit Send_TextBrowser_NewMessage("Warning! Unable to read the resolution of ["+SourceFile_fullPath+"]. This file will only be scaled to "+QString::number((int)ScaleRatio_double,10)+"X."); - return false; - } - //======== 存入自定义分辨率列表中 ============ - QMap res_map; - res_map["fullpath"] = SourceFile_fullPath; - res_map["height"] = QString::number(Height_new,10); - res_map["width"] = QString::number(width_new,10); - Custom_resolution_list.append(res_map); - //========= - return true; - } -} -/* -获取gif帧间隔时间 -*/ -int MainWindow::Gif_getDuration(QString gifPath) -{ - //========================= 调用ffprobe读取GIF信息 ====================== - QProcess *Get_GifAvgFPS_process = new QProcess(); - QString cmd = "\""+Current_Path+"/ffprobe_waifu2xEX.exe\" -i \""+gifPath+"\" -select_streams v -show_streams -v quiet -print_format ini -show_format"; - Get_GifAvgFPS_process->start(cmd); - while(!Get_GifAvgFPS_process->waitForStarted(100)&&!QProcess_stop) {} - while(!Get_GifAvgFPS_process->waitForFinished(100)&&!QProcess_stop) {} - //============= 保存ffprobe输出的ini格式文本 ============= - QString ffprobe_output_str = Get_GifAvgFPS_process->readAllStandardOutput(); - //================ 将ini写入文件保存 ================ - QFileInfo videoFileInfo(gifPath); - QString Path_gif_info_ini = ""; - QString video_dir = file_getFolderPath(gifPath); - int FileNo = 0; - do - { - FileNo++; - Path_gif_info_ini = video_dir+"/"+file_getBaseName(gifPath)+"_GifInfo_"+QString::number(FileNo,10)+"_W2xEX.ini"; - } - while(QFile::exists(Path_gif_info_ini)); - //========= - QFile gif_info_ini(Path_gif_info_ini); - gif_info_ini.remove(); - if (gif_info_ini.open(QIODevice::ReadWrite | QIODevice::Text)) //QIODevice::ReadWrite支持读写 - { - QTextStream stream(&gif_info_ini); - stream << ffprobe_output_str; - } - gif_info_ini.close(); - //================== 读取ini获得参数 ===================== - QString FPS_Division = ""; - QSettings *configIniRead_videoInfo = new QSettings(Path_gif_info_ini, QSettings::IniFormat); - if(configIniRead_videoInfo->value("/streams.stream.0/avg_frame_rate") != QVariant()) - { - FPS_Division = configIniRead_videoInfo->value("/streams.stream.0/avg_frame_rate").toString().trimmed(); - } - gif_info_ini.remove(); - //======================= - int Duration = 0; - if(FPS_Division!="") - { - QStringList FPS_Nums = FPS_Division.split("/"); - if(FPS_Nums.size()==2) - { - double FPS_Num_0 = FPS_Nums.at(0).toDouble(); - double FPS_Num_1 = FPS_Nums.at(1).toDouble(); - if(FPS_Num_0>0&&FPS_Num_1>0) - { - double Duration_double = 100/(FPS_Num_0/FPS_Num_1); - Duration = qRound(Duration_double); - } - } - } - if(Duration<=0) - { - QMovie movie(gifPath); - movie.setSpeed(1); - movie.start(); - movie.stop(); - Duration = ((movie.nextFrameDelay()/100)+1)/10; - } - return Duration; -} -/* -获取gif帧数量的位数 -*/ -int MainWindow::Gif_getFrameDigits(QString gifPath) -{ - QMovie movie(gifPath); - int FrameCount=1+(int)log10(movie.frameCount());//获取frame位数 - return FrameCount; -} -/* -拆分gif -*/ -void MainWindow::Gif_splitGif(QString gifPath,QString SplitFramesFolderPath) -{ - emit Send_TextBrowser_NewMessage(tr("Start splitting GIF:[")+gifPath+"]"); - int FrameDigits = Gif_getFrameDigits(gifPath); - //删除并新建帧文件夹 - file_DelDir(SplitFramesFolderPath); - file_mkDir(SplitFramesFolderPath); - //开始用convert处理 - QString program = Current_Path+"/convert_waifu2xEX.exe"; - QString cmd = "\"" + program + "\"" + " -coalesce " + "\"" + gifPath + "\"" + " " + "\"" + SplitFramesFolderPath + "/%0"+QString::number(FrameDigits,10)+"d.png\""; - QProcess *SplitGIF=new QProcess(); - SplitGIF->start(cmd); - while(!SplitGIF->waitForStarted(100)&&!QProcess_stop) {} - while(!SplitGIF->waitForFinished(100)&&!QProcess_stop) {} - if(file_isDirEmpty(SplitFramesFolderPath))//如果拆分失败,尝试win7兼容指令 - { - QString cmd = "\"" + program + "\"" + " -coalesce " + "\"" + gifPath + "\"" + " " + "\"" + SplitFramesFolderPath + "/%%0"+QString::number(FrameDigits,10)+"d.png\""; - QProcess *SplitGIF=new QProcess(); - SplitGIF->start(cmd); - while(!SplitGIF->waitForStarted(100)&&!QProcess_stop) {} - while(!SplitGIF->waitForFinished(100)&&!QProcess_stop) {} - } - emit Send_TextBrowser_NewMessage(tr("Finish splitting GIF:[")+gifPath+"]"); -} -/* -组装gif -*/ -void MainWindow::Gif_assembleGif(QString ResGifPath,QString ScaledFramesPath,int Duration,bool CustRes_isEnabled,int CustRes_height,int CustRes_width,bool isOverScaled,QString SourceGifFullPath) -{ - emit Send_TextBrowser_NewMessage(tr("Start to assemble GIF:[")+ResGifPath+"]"); - //=============================== - QString resize_cmd =""; - QString program = Current_Path+"/convert_waifu2xEX.exe"; - if(ui->checkBox_DisableResize_gif->isChecked()==false) - { - if(CustRes_isEnabled || isOverScaled) - { - if(isOverScaled==true && CustRes_isEnabled==false) - { - QMap res_map = Image_Gif_Read_Resolution(SourceGifFullPath); - int OriginalScaleRatio = ui->doubleSpinBox_ScaleRatio_gif->value(); - resize_cmd =" -resize "+QString::number(res_map["width"]*OriginalScaleRatio,10)+"x"+QString::number(res_map["height"]*OriginalScaleRatio,10)+"! "; - } - if(CustRes_AspectRatioMode==Qt::IgnoreAspectRatio && CustRes_isEnabled==true) - { - resize_cmd =" -resize "+QString::number(CustRes_width,10)+"x"+QString::number(CustRes_height,10)+"! "; - } - if(CustRes_AspectRatioMode==Qt::KeepAspectRatio && CustRes_isEnabled==true) - { - resize_cmd =" -resize "+QString::number(CustRes_width,10)+"x"+QString::number(CustRes_height,10)+" "; - } - if(CustRes_AspectRatioMode==Qt::KeepAspectRatioByExpanding && CustRes_isEnabled==true) - { - if(CustRes_width>CustRes_height) - { - resize_cmd =" -resize "+QString::number(CustRes_width,10)+" "; - } - else - { - resize_cmd =" -resize x"+QString::number(CustRes_height,10)+" "; - } - } - } - QString cmd = "\"" + program + "\" "+resize_cmd+" -delay " + QString::number(Duration, 10) + " -loop 0 \"" + ScaledFramesPath + "/*png\" \""+ResGifPath+"\""; - QProcess *AssembleGIF=new QProcess(); - AssembleGIF->start(cmd); - while(!AssembleGIF->waitForStarted(100)&&!QProcess_stop) {} - while(!AssembleGIF->waitForFinished(100)&&!QProcess_stop) {} - //======= 纠正文件名称错误(当 结果gif文件路径内有 % 符号时) ====== - if(QFile::exists(ResGifPath)==false) - { - QFileInfo fileinfo(ResGifPath); - QString file_name = file_getBaseName(ResGifPath); - QString file_ext = fileinfo.suffix(); - QString file_path = file_getFolderPath(fileinfo); - QString ActualResGifPath = file_path + "/" + file_name + "-0." + file_ext; - if(QFile::exists(ActualResGifPath)==true) - { - QFile::rename(ActualResGifPath,ResGifPath); - } - } - if(QFile::exists(ResGifPath)) - { - emit Send_TextBrowser_NewMessage(tr("Finish assembling GIF:[")+ResGifPath+"]"); - return; - } - AssembleGIF->kill(); - } - //自行调整图片大小再组装 - if(CustRes_isEnabled || isOverScaled) - { - int New_width=0; - int New_height=0; - if(isOverScaled==true && CustRes_isEnabled==false) - { - QMap res_map = Image_Gif_Read_Resolution(SourceGifFullPath); - int OriginalScaleRatio = ui->doubleSpinBox_ScaleRatio_gif->value(); - New_width = res_map["width"]*OriginalScaleRatio; - New_height = res_map["height"]*OriginalScaleRatio; - } - if(CustRes_isEnabled==true) - { - New_width = CustRes_width; - New_height = CustRes_height; - } - ImagesResize_Folder_MultiThread(New_width,New_height,ScaledFramesPath); - } - QString cmd = "\"" + program + "\" \"" + ScaledFramesPath + "/*png\" -delay " + QString::number(Duration, 10) + " -loop 0 \""+ResGifPath+"\""; - QProcess *AssembleGIF_1=new QProcess(); - AssembleGIF_1->start(cmd); - while(!AssembleGIF_1->waitForStarted(100)&&!QProcess_stop) {} - while(!AssembleGIF_1->waitForFinished(100)&&!QProcess_stop) {} - //======= 纠正文件名称错误(当 结果gif文件路径内有 % 符号时) ====== - if(QFile::exists(ResGifPath)==false) - { - QFileInfo fileinfo(ResGifPath); - QString file_name = file_getBaseName(ResGifPath); - QString file_ext = fileinfo.suffix(); - QString file_path = file_getFolderPath(fileinfo); - QString ActualResGifPath = file_path + "/" + file_name + "-0." + file_ext; - if(QFile::exists(ActualResGifPath)==true) - { - QFile::rename(ActualResGifPath,ResGifPath); - } - } - //===================== - if(QFile::exists(ResGifPath)) - { - emit Send_TextBrowser_NewMessage(tr("Finish assembling GIF:[")+ResGifPath+"]"); - if(ui->checkBox_DisableResize_gif->isChecked()==false)emit Send_Set_checkBox_DisableResize_gif_Checked(); - } - return; -} -/* -压缩gif -*/ -QString MainWindow::Gif_compressGif(QString gifPath,QString gifPath_compressd) -{ - emit Send_TextBrowser_NewMessage(tr("Starting to optimize GIF:[")+gifPath+"]"); - //===== - QString program = Current_Path+"/gifsicle_waifu2xEX.exe"; - QString cmd = "\"" + program + "\"" + " -O3 -i \""+gifPath+"\" -o \""+gifPath_compressd+"\""; - QProcess *CompressGIF=new QProcess(); - CompressGIF->start(cmd); - while(!CompressGIF->waitForStarted(100)&&!QProcess_stop) {} - while(!CompressGIF->waitForFinished(100)&&!QProcess_stop) {} - //====== - //判断是否生成压缩后的gif - if(QFile::exists(gifPath_compressd) == false) - { - emit Send_TextBrowser_NewMessage(tr("Error occured when processing [")+gifPath+tr("]. Error: [Can't optimize gif.]")); - return gifPath;//返回源文件路径 - } - //====== - //比较文件大小,判断压缩是否有效 - QFileInfo *gifPath_QFileInfo = new QFileInfo(gifPath); - QFileInfo *gifPath_compressd_QFileInfo = new QFileInfo(gifPath_compressd); - if(gifPath_compressd_QFileInfo->size() >= gifPath_QFileInfo->size()) - { - emit Send_TextBrowser_NewMessage(tr("Failed to optimize gif [")+gifPath+tr("] to reduce storage usage, the optimized gif file will be deleted.")); - QFile::remove(gifPath_compressd); - return gifPath;//返回源文件路径 - } - //====== - QFile::remove(gifPath); - emit Send_TextBrowser_NewMessage(tr("Finish optimizing GIF:[")+gifPath+"]"); - return gifPath_compressd;//返回处理完成的文件路径 -} +/* + Copyright (C) 2021 Aaron Feng + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU Affero General Public License as published + by the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program. If not, see . + + My Github homepage: https://github.com/AaronFeng753 +*/ + +#include "mainwindow.h" +#include "ui_mainwindow.h" +/* +根据行数从自定义分辨率列表移除gif文件 +*/ +void MainWindow::Gif_RemoveFromCustResList(int RowNumber) +{ + QString SourceFile_fullPath = Table_model_gif->item(RowNumber,2)->text(); + CustRes_remove(SourceFile_fullPath); +} + +/* +当gif没有自定义分辨率且此时放大倍率为double,则计算一个添加到自定义列表里 +*/ +bool MainWindow::Gif_DoubleScaleRatioPrep(int RowNumber) +{ + QString SourceFile_fullPath = Table_model_gif->item(RowNumber,2)->text(); + if(CustRes_isContained(SourceFile_fullPath) == true) + { + return false; + } + else + { + //===================== 获取分辨率 ============================= + QMap Map_OrgRes = Image_Gif_Read_Resolution(SourceFile_fullPath); + //========= 计算新的高度宽度 ================== + double ScaleRatio_double = ui->doubleSpinBox_ScaleRatio_gif->value(); + int Height_new = qRound(ScaleRatio_double * Map_OrgRes["height"]); + int width_new = qRound(ScaleRatio_double * Map_OrgRes["width"]); + if(Height_new<1 || width_new<1) + { + emit Send_TextBrowser_NewMessage("Warning! Unable to read the resolution of ["+SourceFile_fullPath+"]. This file will only be scaled to "+QString::number((int)ScaleRatio_double,10)+"X."); + return false; + } + //======== 存入自定义分辨率列表中 ============ + QMap res_map; + res_map["fullpath"] = SourceFile_fullPath; + res_map["height"] = QString::number(Height_new,10); + res_map["width"] = QString::number(width_new,10); + Custom_resolution_list.append(res_map); + //========= + return true; + } +} +/* +获取gif帧间隔时间 +*/ +int MainWindow::Gif_getDuration(QString gifPath) +{ + //========================= 调用ffprobe读取GIF信息 ====================== + QProcess *Get_GifAvgFPS_process = new QProcess(); + QString cmd = "\""+Current_Path+"/ffprobe_waifu2xEX.exe\" -i \""+gifPath+"\" -select_streams v -show_streams -v quiet -print_format ini -show_format"; + Get_GifAvgFPS_process->start(cmd); + while(!Get_GifAvgFPS_process->waitForStarted(100)&&!QProcess_stop) {} + while(!Get_GifAvgFPS_process->waitForFinished(100)&&!QProcess_stop) {} + //============= 保存ffprobe输出的ini格式文本 ============= + QString ffprobe_output_str = Get_GifAvgFPS_process->readAllStandardOutput(); + //================ 将ini写入文件保存 ================ + QFileInfo videoFileInfo(gifPath); + QString Path_gif_info_ini = ""; + QString video_dir = file_getFolderPath(gifPath); + int FileNo = 0; + do + { + FileNo++; + Path_gif_info_ini = video_dir+"/"+file_getBaseName(gifPath)+"_GifInfo_"+QString::number(FileNo,10)+"_W2xEX.ini"; + } + while(QFile::exists(Path_gif_info_ini)); + //========= + QFile gif_info_ini(Path_gif_info_ini); + gif_info_ini.remove(); + if (gif_info_ini.open(QIODevice::ReadWrite | QIODevice::Text)) //QIODevice::ReadWrite支持读写 + { + QTextStream stream(&gif_info_ini); + stream << ffprobe_output_str; + } + gif_info_ini.close(); + //================== 读取ini获得参数 ===================== + QString FPS_Division = ""; + QSettings *configIniRead_videoInfo = new QSettings(Path_gif_info_ini, QSettings::IniFormat); + if(configIniRead_videoInfo->value("/streams.stream.0/avg_frame_rate") != QVariant()) + { + FPS_Division = configIniRead_videoInfo->value("/streams.stream.0/avg_frame_rate").toString().trimmed(); + } + gif_info_ini.remove(); + //======================= + int Duration = 0; + if(FPS_Division!="") + { + QStringList FPS_Nums = FPS_Division.split("/"); + if(FPS_Nums.size()==2) + { + double FPS_Num_0 = FPS_Nums.at(0).toDouble(); + double FPS_Num_1 = FPS_Nums.at(1).toDouble(); + if(FPS_Num_0>0&&FPS_Num_1>0) + { + double Duration_double = 100/(FPS_Num_0/FPS_Num_1); + Duration = qRound(Duration_double); + } + } + } + if(Duration<=0) + { + QMovie movie(gifPath); + movie.setSpeed(1); + movie.start(); + movie.stop(); + Duration = ((movie.nextFrameDelay()/100)+1)/10; + } + return Duration; +} +/* +获取gif帧数量的位数 +*/ +int MainWindow::Gif_getFrameDigits(QString gifPath) +{ + QMovie movie(gifPath); + int FrameCount=1+(int)log10(movie.frameCount());//获取frame位数 + return FrameCount; +} +/* +拆分gif +*/ +void MainWindow::Gif_splitGif(QString gifPath,QString SplitFramesFolderPath) +{ + emit Send_TextBrowser_NewMessage(tr("Start splitting GIF:[")+gifPath+"]"); + int FrameDigits = Gif_getFrameDigits(gifPath); + //删除并新建帧文件夹 + file_DelDir(SplitFramesFolderPath); + file_mkDir(SplitFramesFolderPath); + //开始用convert处理 + QString program = Current_Path+"/convert_waifu2xEX.exe"; + QString cmd = "\"" + program + "\"" + " -coalesce " + "\"" + gifPath + "\"" + " " + "\"" + SplitFramesFolderPath + "/%0"+QString::number(FrameDigits,10)+"d.png\""; + QProcess *SplitGIF=new QProcess(); + SplitGIF->start(cmd); + while(!SplitGIF->waitForStarted(100)&&!QProcess_stop) {} + while(!SplitGIF->waitForFinished(100)&&!QProcess_stop) {} + if(file_isDirEmpty(SplitFramesFolderPath))//如果拆分失败,尝试win7兼容指令 + { + QString cmd = "\"" + program + "\"" + " -coalesce " + "\"" + gifPath + "\"" + " " + "\"" + SplitFramesFolderPath + "/%%0"+QString::number(FrameDigits,10)+"d.png\""; + QProcess *SplitGIF=new QProcess(); + SplitGIF->start(cmd); + while(!SplitGIF->waitForStarted(100)&&!QProcess_stop) {} + while(!SplitGIF->waitForFinished(100)&&!QProcess_stop) {} + } + emit Send_TextBrowser_NewMessage(tr("Finish splitting GIF:[")+gifPath+"]"); +} +/* +组装gif +*/ +void MainWindow::Gif_assembleGif(QString ResGifPath,QString ScaledFramesPath,int Duration,bool CustRes_isEnabled,int CustRes_height,int CustRes_width,bool isOverScaled,QString SourceGifFullPath) +{ + emit Send_TextBrowser_NewMessage(tr("Start to assemble GIF:[")+ResGifPath+"]"); + //=============================== + QString resize_cmd =""; + QString program = Current_Path+"/convert_waifu2xEX.exe"; + if(ui->checkBox_DisableResize_gif->isChecked()==false) + { + if(CustRes_isEnabled || isOverScaled) + { + if(isOverScaled==true && CustRes_isEnabled==false) + { + QMap res_map = Image_Gif_Read_Resolution(SourceGifFullPath); + int OriginalScaleRatio = ui->doubleSpinBox_ScaleRatio_gif->value(); + resize_cmd =" -resize "+QString::number(res_map["width"]*OriginalScaleRatio,10)+"x"+QString::number(res_map["height"]*OriginalScaleRatio,10)+"! "; + } + if(CustRes_AspectRatioMode==Qt::IgnoreAspectRatio && CustRes_isEnabled==true) + { + resize_cmd =" -resize "+QString::number(CustRes_width,10)+"x"+QString::number(CustRes_height,10)+"! "; + } + if(CustRes_AspectRatioMode==Qt::KeepAspectRatio && CustRes_isEnabled==true) + { + resize_cmd =" -resize "+QString::number(CustRes_width,10)+"x"+QString::number(CustRes_height,10)+" "; + } + if(CustRes_AspectRatioMode==Qt::KeepAspectRatioByExpanding && CustRes_isEnabled==true) + { + if(CustRes_width>CustRes_height) + { + resize_cmd =" -resize "+QString::number(CustRes_width,10)+" "; + } + else + { + resize_cmd =" -resize x"+QString::number(CustRes_height,10)+" "; + } + } + } + QString cmd = "\"" + program + "\" "+resize_cmd+" -delay " + QString::number(Duration, 10) + " -loop 0 \"" + ScaledFramesPath + "/*png\" \""+ResGifPath+"\""; + QProcess *AssembleGIF=new QProcess(); + AssembleGIF->start(cmd); + while(!AssembleGIF->waitForStarted(100)&&!QProcess_stop) {} + while(!AssembleGIF->waitForFinished(100)&&!QProcess_stop) {} + //======= 纠正文件名称错误(当 结果gif文件路径内有 % 符号时) ====== + if(QFile::exists(ResGifPath)==false) + { + QFileInfo fileinfo(ResGifPath); + QString file_name = file_getBaseName(ResGifPath); + QString file_ext = fileinfo.suffix(); + QString file_path = file_getFolderPath(fileinfo); + QString ActualResGifPath = file_path + "/" + file_name + "-0." + file_ext; + if(QFile::exists(ActualResGifPath)==true) + { + QFile::rename(ActualResGifPath,ResGifPath); + } + } + if(QFile::exists(ResGifPath)) + { + emit Send_TextBrowser_NewMessage(tr("Finish assembling GIF:[")+ResGifPath+"]"); + return; + } + AssembleGIF->kill(); + } + //自行调整图片大小再组装 + if(CustRes_isEnabled || isOverScaled) + { + int New_width=0; + int New_height=0; + if(isOverScaled==true && CustRes_isEnabled==false) + { + QMap res_map = Image_Gif_Read_Resolution(SourceGifFullPath); + int OriginalScaleRatio = ui->doubleSpinBox_ScaleRatio_gif->value(); + New_width = res_map["width"]*OriginalScaleRatio; + New_height = res_map["height"]*OriginalScaleRatio; + } + if(CustRes_isEnabled==true) + { + New_width = CustRes_width; + New_height = CustRes_height; + } + ImagesResize_Folder_MultiThread(New_width,New_height,ScaledFramesPath); + } + QString cmd = "\"" + program + "\" \"" + ScaledFramesPath + "/*png\" -delay " + QString::number(Duration, 10) + " -loop 0 \""+ResGifPath+"\""; + QProcess *AssembleGIF_1=new QProcess(); + AssembleGIF_1->start(cmd); + while(!AssembleGIF_1->waitForStarted(100)&&!QProcess_stop) {} + while(!AssembleGIF_1->waitForFinished(100)&&!QProcess_stop) {} + //======= 纠正文件名称错误(当 结果gif文件路径内有 % 符号时) ====== + if(QFile::exists(ResGifPath)==false) + { + QFileInfo fileinfo(ResGifPath); + QString file_name = file_getBaseName(ResGifPath); + QString file_ext = fileinfo.suffix(); + QString file_path = file_getFolderPath(fileinfo); + QString ActualResGifPath = file_path + "/" + file_name + "-0." + file_ext; + if(QFile::exists(ActualResGifPath)==true) + { + QFile::rename(ActualResGifPath,ResGifPath); + } + } + //===================== + if(QFile::exists(ResGifPath)) + { + emit Send_TextBrowser_NewMessage(tr("Finish assembling GIF:[")+ResGifPath+"]"); + if(ui->checkBox_DisableResize_gif->isChecked()==false)emit Send_Set_checkBox_DisableResize_gif_Checked(); + } + return; +} +/* +压缩gif +*/ +QString MainWindow::Gif_compressGif(QString gifPath,QString gifPath_compressd) +{ + emit Send_TextBrowser_NewMessage(tr("Starting to optimize GIF:[")+gifPath+"]"); + //===== + QString program = Current_Path+"/gifsicle_waifu2xEX.exe"; + QString cmd = "\"" + program + "\"" + " -O3 -i \""+gifPath+"\" -o \""+gifPath_compressd+"\""; + QProcess *CompressGIF=new QProcess(); + CompressGIF->start(cmd); + while(!CompressGIF->waitForStarted(100)&&!QProcess_stop) {} + while(!CompressGIF->waitForFinished(100)&&!QProcess_stop) {} + //====== + //判断是否生成压缩后的gif + if(QFile::exists(gifPath_compressd) == false) + { + emit Send_TextBrowser_NewMessage(tr("Error occured when processing [")+gifPath+tr("]. Error: [Can't optimize gif.]")); + return gifPath;//返回源文件路径 + } + //====== + //比较文件大小,判断压缩是否有效 + QFileInfo *gifPath_QFileInfo = new QFileInfo(gifPath); + QFileInfo *gifPath_compressd_QFileInfo = new QFileInfo(gifPath_compressd); + if(gifPath_compressd_QFileInfo->size() >= gifPath_QFileInfo->size()) + { + emit Send_TextBrowser_NewMessage(tr("Failed to optimize gif [")+gifPath+tr("] to reduce storage usage, the optimized gif file will be deleted.")); + QFile::remove(gifPath_compressd); + return gifPath;//返回源文件路径 + } + //====== + QFile::remove(gifPath); + emit Send_TextBrowser_NewMessage(tr("Finish optimizing GIF:[")+gifPath+"]"); + return gifPath_compressd;//返回处理完成的文件路径 +} diff --git a/SRC/Waifu2x-Extension-QT/icon.qrc b/SRC_v3.41.01-beta/Waifu2x-Extension-QT/icon.qrc similarity index 97% rename from SRC/Waifu2x-Extension-QT/icon.qrc rename to SRC_v3.41.01-beta/Waifu2x-Extension-QT/icon.qrc index 967bbb5..555bf27 100644 --- a/SRC/Waifu2x-Extension-QT/icon.qrc +++ b/SRC_v3.41.01-beta/Waifu2x-Extension-QT/icon.qrc @@ -1,54 +1,54 @@ - - - icon/icon_main.png - icon/Home.png - icon/AddSetting.png - icon/EngineSettings.png - icon/VideoSettings.png - icon/CompatibilityTest.png - icon/pause-button.png - icon/refresh.png - icon/donateTabIcon_1.png - icon/paypal.png - icon/gif_Rmenu.png - icon/picture_Rmenu.png - icon/video_Rmenu.png - icon/view_file.png - icon/cancel.png - icon/Apply.png - icon/RemoveFile.png - icon/opne_folder.png - icon/Read_FileList.png - icon/Save_FileList.png - icon/Read_FileList_hover.png - icon/Save_FileList_hover.png - icon/RemoveItem.png - icon/RemoveItem_hover.png - icon/ClearList.png - icon/ClearList_hover.png - icon/AddNewFile.png - icon/AddNewFile_hover.png - icon/AddNewFile_disabled.png - icon/RemoveItem_disabled.png - icon/ClearList_disabled.png - icon/Read_FileList_disabled.png - icon/Save_FileList_disabled.png - icon/ResizeFilesListSplitter.png - icon/ResizeFilesListSplitter_disabled.png - icon/ResizeFilesListSplitter_hover.png - icon/TurnOffScreen.png - icon/TurnOffScreen_disabled.png - icon/TurnOffScreen_hover.png - icon/Exit.png - icon/SendFeedback.png - icon/ShowWindow.png - icon/Minimize.png - icon/BackgroudMode.png - icon/About.png - icon/Pause_SysTray.png - icon/Start_SysTray.png - icon/patreon.png - icon/patreon_sysTray.png - icon/donateTabIcon.png - - + + + icon/icon_main.png + icon/Home.png + icon/AddSetting.png + icon/EngineSettings.png + icon/VideoSettings.png + icon/CompatibilityTest.png + icon/pause-button.png + icon/refresh.png + icon/donateTabIcon_1.png + icon/paypal.png + icon/gif_Rmenu.png + icon/picture_Rmenu.png + icon/video_Rmenu.png + icon/view_file.png + icon/cancel.png + icon/Apply.png + icon/RemoveFile.png + icon/opne_folder.png + icon/Read_FileList.png + icon/Save_FileList.png + icon/Read_FileList_hover.png + icon/Save_FileList_hover.png + icon/RemoveItem.png + icon/RemoveItem_hover.png + icon/ClearList.png + icon/ClearList_hover.png + icon/AddNewFile.png + icon/AddNewFile_hover.png + icon/AddNewFile_disabled.png + icon/RemoveItem_disabled.png + icon/ClearList_disabled.png + icon/Read_FileList_disabled.png + icon/Save_FileList_disabled.png + icon/ResizeFilesListSplitter.png + icon/ResizeFilesListSplitter_disabled.png + icon/ResizeFilesListSplitter_hover.png + icon/TurnOffScreen.png + icon/TurnOffScreen_disabled.png + icon/TurnOffScreen_hover.png + icon/Exit.png + icon/SendFeedback.png + icon/ShowWindow.png + icon/Minimize.png + icon/BackgroudMode.png + icon/About.png + icon/Pause_SysTray.png + icon/Start_SysTray.png + icon/patreon.png + icon/patreon_sysTray.png + icon/donateTabIcon.png + + diff --git a/SRC/Waifu2x-Extension-QT/icon/About.png b/SRC_v3.41.01-beta/Waifu2x-Extension-QT/icon/About.png similarity index 100% rename from SRC/Waifu2x-Extension-QT/icon/About.png rename to SRC_v3.41.01-beta/Waifu2x-Extension-QT/icon/About.png diff --git a/SRC/Waifu2x-Extension-QT/icon/AddNewFile.png b/SRC_v3.41.01-beta/Waifu2x-Extension-QT/icon/AddNewFile.png similarity index 100% rename from SRC/Waifu2x-Extension-QT/icon/AddNewFile.png rename to SRC_v3.41.01-beta/Waifu2x-Extension-QT/icon/AddNewFile.png diff --git a/SRC/Waifu2x-Extension-QT/icon/AddNewFile_disabled.png b/SRC_v3.41.01-beta/Waifu2x-Extension-QT/icon/AddNewFile_disabled.png similarity index 100% rename from SRC/Waifu2x-Extension-QT/icon/AddNewFile_disabled.png rename to SRC_v3.41.01-beta/Waifu2x-Extension-QT/icon/AddNewFile_disabled.png diff --git a/SRC/Waifu2x-Extension-QT/icon/AddNewFile_hover.png b/SRC_v3.41.01-beta/Waifu2x-Extension-QT/icon/AddNewFile_hover.png similarity index 100% rename from SRC/Waifu2x-Extension-QT/icon/AddNewFile_hover.png rename to SRC_v3.41.01-beta/Waifu2x-Extension-QT/icon/AddNewFile_hover.png diff --git a/SRC/Waifu2x-Extension-QT/icon/AddSetting.png b/SRC_v3.41.01-beta/Waifu2x-Extension-QT/icon/AddSetting.png similarity index 100% rename from SRC/Waifu2x-Extension-QT/icon/AddSetting.png rename to SRC_v3.41.01-beta/Waifu2x-Extension-QT/icon/AddSetting.png diff --git a/SRC/Waifu2x-Extension-QT/icon/Apply.png b/SRC_v3.41.01-beta/Waifu2x-Extension-QT/icon/Apply.png similarity index 100% rename from SRC/Waifu2x-Extension-QT/icon/Apply.png rename to SRC_v3.41.01-beta/Waifu2x-Extension-QT/icon/Apply.png diff --git a/SRC/Waifu2x-Extension-QT/icon/BackgroudMode.png b/SRC_v3.41.01-beta/Waifu2x-Extension-QT/icon/BackgroudMode.png similarity index 100% rename from SRC/Waifu2x-Extension-QT/icon/BackgroudMode.png rename to SRC_v3.41.01-beta/Waifu2x-Extension-QT/icon/BackgroudMode.png diff --git a/SRC/Waifu2x-Extension-QT/icon/ClearList.png b/SRC_v3.41.01-beta/Waifu2x-Extension-QT/icon/ClearList.png similarity index 100% rename from SRC/Waifu2x-Extension-QT/icon/ClearList.png rename to SRC_v3.41.01-beta/Waifu2x-Extension-QT/icon/ClearList.png diff --git a/SRC/Waifu2x-Extension-QT/icon/ClearList_disabled.png b/SRC_v3.41.01-beta/Waifu2x-Extension-QT/icon/ClearList_disabled.png similarity index 100% rename from SRC/Waifu2x-Extension-QT/icon/ClearList_disabled.png rename to SRC_v3.41.01-beta/Waifu2x-Extension-QT/icon/ClearList_disabled.png diff --git a/SRC/Waifu2x-Extension-QT/icon/ClearList_hover.png b/SRC_v3.41.01-beta/Waifu2x-Extension-QT/icon/ClearList_hover.png similarity index 100% rename from SRC/Waifu2x-Extension-QT/icon/ClearList_hover.png rename to SRC_v3.41.01-beta/Waifu2x-Extension-QT/icon/ClearList_hover.png diff --git a/SRC/Waifu2x-Extension-QT/icon/CompatibilityTest.png b/SRC_v3.41.01-beta/Waifu2x-Extension-QT/icon/CompatibilityTest.png similarity index 100% rename from SRC/Waifu2x-Extension-QT/icon/CompatibilityTest.png rename to SRC_v3.41.01-beta/Waifu2x-Extension-QT/icon/CompatibilityTest.png diff --git a/SRC/Waifu2x-Extension-QT/icon/EngineSettings.png b/SRC_v3.41.01-beta/Waifu2x-Extension-QT/icon/EngineSettings.png similarity index 100% rename from SRC/Waifu2x-Extension-QT/icon/EngineSettings.png rename to SRC_v3.41.01-beta/Waifu2x-Extension-QT/icon/EngineSettings.png diff --git a/SRC/Waifu2x-Extension-QT/icon/Exit.png b/SRC_v3.41.01-beta/Waifu2x-Extension-QT/icon/Exit.png similarity index 100% rename from SRC/Waifu2x-Extension-QT/icon/Exit.png rename to SRC_v3.41.01-beta/Waifu2x-Extension-QT/icon/Exit.png diff --git a/SRC/Waifu2x-Extension-QT/icon/Home.png b/SRC_v3.41.01-beta/Waifu2x-Extension-QT/icon/Home.png similarity index 100% rename from SRC/Waifu2x-Extension-QT/icon/Home.png rename to SRC_v3.41.01-beta/Waifu2x-Extension-QT/icon/Home.png diff --git a/SRC/Waifu2x-Extension-QT/icon/Minimize.png b/SRC_v3.41.01-beta/Waifu2x-Extension-QT/icon/Minimize.png similarity index 100% rename from SRC/Waifu2x-Extension-QT/icon/Minimize.png rename to SRC_v3.41.01-beta/Waifu2x-Extension-QT/icon/Minimize.png diff --git a/SRC/Waifu2x-Extension-QT/icon/Pause_SysTray.png b/SRC_v3.41.01-beta/Waifu2x-Extension-QT/icon/Pause_SysTray.png similarity index 100% rename from SRC/Waifu2x-Extension-QT/icon/Pause_SysTray.png rename to SRC_v3.41.01-beta/Waifu2x-Extension-QT/icon/Pause_SysTray.png diff --git a/SRC/Waifu2x-Extension-QT/icon/Read_FileList.png b/SRC_v3.41.01-beta/Waifu2x-Extension-QT/icon/Read_FileList.png similarity index 100% rename from SRC/Waifu2x-Extension-QT/icon/Read_FileList.png rename to SRC_v3.41.01-beta/Waifu2x-Extension-QT/icon/Read_FileList.png diff --git a/SRC/Waifu2x-Extension-QT/icon/Read_FileList_disabled.png b/SRC_v3.41.01-beta/Waifu2x-Extension-QT/icon/Read_FileList_disabled.png similarity index 100% rename from SRC/Waifu2x-Extension-QT/icon/Read_FileList_disabled.png rename to SRC_v3.41.01-beta/Waifu2x-Extension-QT/icon/Read_FileList_disabled.png diff --git a/SRC/Waifu2x-Extension-QT/icon/Read_FileList_hover.png b/SRC_v3.41.01-beta/Waifu2x-Extension-QT/icon/Read_FileList_hover.png similarity index 100% rename from SRC/Waifu2x-Extension-QT/icon/Read_FileList_hover.png rename to SRC_v3.41.01-beta/Waifu2x-Extension-QT/icon/Read_FileList_hover.png diff --git a/SRC/Waifu2x-Extension-QT/icon/RemoveFile.png b/SRC_v3.41.01-beta/Waifu2x-Extension-QT/icon/RemoveFile.png similarity index 100% rename from SRC/Waifu2x-Extension-QT/icon/RemoveFile.png rename to SRC_v3.41.01-beta/Waifu2x-Extension-QT/icon/RemoveFile.png diff --git a/SRC/Waifu2x-Extension-QT/icon/RemoveItem.png b/SRC_v3.41.01-beta/Waifu2x-Extension-QT/icon/RemoveItem.png similarity index 100% rename from SRC/Waifu2x-Extension-QT/icon/RemoveItem.png rename to SRC_v3.41.01-beta/Waifu2x-Extension-QT/icon/RemoveItem.png diff --git a/SRC/Waifu2x-Extension-QT/icon/RemoveItem_disabled.png b/SRC_v3.41.01-beta/Waifu2x-Extension-QT/icon/RemoveItem_disabled.png similarity index 100% rename from SRC/Waifu2x-Extension-QT/icon/RemoveItem_disabled.png rename to SRC_v3.41.01-beta/Waifu2x-Extension-QT/icon/RemoveItem_disabled.png diff --git a/SRC/Waifu2x-Extension-QT/icon/RemoveItem_hover.png b/SRC_v3.41.01-beta/Waifu2x-Extension-QT/icon/RemoveItem_hover.png similarity index 100% rename from SRC/Waifu2x-Extension-QT/icon/RemoveItem_hover.png rename to SRC_v3.41.01-beta/Waifu2x-Extension-QT/icon/RemoveItem_hover.png diff --git a/SRC/Waifu2x-Extension-QT/icon/ResizeFilesListSplitter.png b/SRC_v3.41.01-beta/Waifu2x-Extension-QT/icon/ResizeFilesListSplitter.png similarity index 100% rename from SRC/Waifu2x-Extension-QT/icon/ResizeFilesListSplitter.png rename to SRC_v3.41.01-beta/Waifu2x-Extension-QT/icon/ResizeFilesListSplitter.png diff --git a/SRC/Waifu2x-Extension-QT/icon/ResizeFilesListSplitter_disabled.png b/SRC_v3.41.01-beta/Waifu2x-Extension-QT/icon/ResizeFilesListSplitter_disabled.png similarity index 100% rename from SRC/Waifu2x-Extension-QT/icon/ResizeFilesListSplitter_disabled.png rename to SRC_v3.41.01-beta/Waifu2x-Extension-QT/icon/ResizeFilesListSplitter_disabled.png diff --git a/SRC/Waifu2x-Extension-QT/icon/ResizeFilesListSplitter_hover.png b/SRC_v3.41.01-beta/Waifu2x-Extension-QT/icon/ResizeFilesListSplitter_hover.png similarity index 100% rename from SRC/Waifu2x-Extension-QT/icon/ResizeFilesListSplitter_hover.png rename to SRC_v3.41.01-beta/Waifu2x-Extension-QT/icon/ResizeFilesListSplitter_hover.png diff --git a/SRC/Waifu2x-Extension-QT/icon/Save_FileList.png b/SRC_v3.41.01-beta/Waifu2x-Extension-QT/icon/Save_FileList.png similarity index 100% rename from SRC/Waifu2x-Extension-QT/icon/Save_FileList.png rename to SRC_v3.41.01-beta/Waifu2x-Extension-QT/icon/Save_FileList.png diff --git a/SRC/Waifu2x-Extension-QT/icon/Save_FileList_disabled.png b/SRC_v3.41.01-beta/Waifu2x-Extension-QT/icon/Save_FileList_disabled.png similarity index 100% rename from SRC/Waifu2x-Extension-QT/icon/Save_FileList_disabled.png rename to SRC_v3.41.01-beta/Waifu2x-Extension-QT/icon/Save_FileList_disabled.png diff --git a/SRC/Waifu2x-Extension-QT/icon/Save_FileList_hover.png b/SRC_v3.41.01-beta/Waifu2x-Extension-QT/icon/Save_FileList_hover.png similarity index 100% rename from SRC/Waifu2x-Extension-QT/icon/Save_FileList_hover.png rename to SRC_v3.41.01-beta/Waifu2x-Extension-QT/icon/Save_FileList_hover.png diff --git a/SRC/Waifu2x-Extension-QT/icon/SendFeedback.png b/SRC_v3.41.01-beta/Waifu2x-Extension-QT/icon/SendFeedback.png similarity index 100% rename from SRC/Waifu2x-Extension-QT/icon/SendFeedback.png rename to SRC_v3.41.01-beta/Waifu2x-Extension-QT/icon/SendFeedback.png diff --git a/SRC/Waifu2x-Extension-QT/icon/ShowWindow.png b/SRC_v3.41.01-beta/Waifu2x-Extension-QT/icon/ShowWindow.png similarity index 100% rename from SRC/Waifu2x-Extension-QT/icon/ShowWindow.png rename to SRC_v3.41.01-beta/Waifu2x-Extension-QT/icon/ShowWindow.png diff --git a/SRC/Waifu2x-Extension-QT/icon/Start_SysTray.png b/SRC_v3.41.01-beta/Waifu2x-Extension-QT/icon/Start_SysTray.png similarity index 100% rename from SRC/Waifu2x-Extension-QT/icon/Start_SysTray.png rename to SRC_v3.41.01-beta/Waifu2x-Extension-QT/icon/Start_SysTray.png diff --git a/SRC/Waifu2x-Extension-QT/icon/TurnOffScreen.png b/SRC_v3.41.01-beta/Waifu2x-Extension-QT/icon/TurnOffScreen.png similarity index 100% rename from SRC/Waifu2x-Extension-QT/icon/TurnOffScreen.png rename to SRC_v3.41.01-beta/Waifu2x-Extension-QT/icon/TurnOffScreen.png diff --git a/SRC/Waifu2x-Extension-QT/icon/TurnOffScreen_disabled.png b/SRC_v3.41.01-beta/Waifu2x-Extension-QT/icon/TurnOffScreen_disabled.png similarity index 100% rename from SRC/Waifu2x-Extension-QT/icon/TurnOffScreen_disabled.png rename to SRC_v3.41.01-beta/Waifu2x-Extension-QT/icon/TurnOffScreen_disabled.png diff --git a/SRC/Waifu2x-Extension-QT/icon/TurnOffScreen_hover.png b/SRC_v3.41.01-beta/Waifu2x-Extension-QT/icon/TurnOffScreen_hover.png similarity index 100% rename from SRC/Waifu2x-Extension-QT/icon/TurnOffScreen_hover.png rename to SRC_v3.41.01-beta/Waifu2x-Extension-QT/icon/TurnOffScreen_hover.png diff --git a/SRC/Waifu2x-Extension-QT/icon/VideoSettings.png b/SRC_v3.41.01-beta/Waifu2x-Extension-QT/icon/VideoSettings.png similarity index 100% rename from SRC/Waifu2x-Extension-QT/icon/VideoSettings.png rename to SRC_v3.41.01-beta/Waifu2x-Extension-QT/icon/VideoSettings.png diff --git a/SRC/Waifu2x-Extension-QT/icon/cancel.png b/SRC_v3.41.01-beta/Waifu2x-Extension-QT/icon/cancel.png similarity index 100% rename from SRC/Waifu2x-Extension-QT/icon/cancel.png rename to SRC_v3.41.01-beta/Waifu2x-Extension-QT/icon/cancel.png diff --git a/SRC/Waifu2x-Extension-QT/icon/donateTabIcon.png b/SRC_v3.41.01-beta/Waifu2x-Extension-QT/icon/donateTabIcon.png similarity index 100% rename from SRC/Waifu2x-Extension-QT/icon/donateTabIcon.png rename to SRC_v3.41.01-beta/Waifu2x-Extension-QT/icon/donateTabIcon.png diff --git a/SRC/Waifu2x-Extension-QT/icon/donateTabIcon_1.png b/SRC_v3.41.01-beta/Waifu2x-Extension-QT/icon/donateTabIcon_1.png similarity index 100% rename from SRC/Waifu2x-Extension-QT/icon/donateTabIcon_1.png rename to SRC_v3.41.01-beta/Waifu2x-Extension-QT/icon/donateTabIcon_1.png diff --git a/SRC/Waifu2x-Extension-QT/icon/gif_Rmenu.png b/SRC_v3.41.01-beta/Waifu2x-Extension-QT/icon/gif_Rmenu.png similarity index 100% rename from SRC/Waifu2x-Extension-QT/icon/gif_Rmenu.png rename to SRC_v3.41.01-beta/Waifu2x-Extension-QT/icon/gif_Rmenu.png diff --git a/SRC/Waifu2x-Extension-QT/icon/icon.ico b/SRC_v3.41.01-beta/Waifu2x-Extension-QT/icon/icon.ico similarity index 100% rename from SRC/Waifu2x-Extension-QT/icon/icon.ico rename to SRC_v3.41.01-beta/Waifu2x-Extension-QT/icon/icon.ico diff --git a/SRC/Waifu2x-Extension-QT/icon/icon_main.png b/SRC_v3.41.01-beta/Waifu2x-Extension-QT/icon/icon_main.png similarity index 100% rename from SRC/Waifu2x-Extension-QT/icon/icon_main.png rename to SRC_v3.41.01-beta/Waifu2x-Extension-QT/icon/icon_main.png diff --git a/SRC/Waifu2x-Extension-QT/icon/opne_folder.png b/SRC_v3.41.01-beta/Waifu2x-Extension-QT/icon/opne_folder.png similarity index 100% rename from SRC/Waifu2x-Extension-QT/icon/opne_folder.png rename to SRC_v3.41.01-beta/Waifu2x-Extension-QT/icon/opne_folder.png diff --git a/SRC/Waifu2x-Extension-QT/icon/patreon.png b/SRC_v3.41.01-beta/Waifu2x-Extension-QT/icon/patreon.png similarity index 100% rename from SRC/Waifu2x-Extension-QT/icon/patreon.png rename to SRC_v3.41.01-beta/Waifu2x-Extension-QT/icon/patreon.png diff --git a/SRC/Waifu2x-Extension-QT/icon/patreon_sysTray.png b/SRC_v3.41.01-beta/Waifu2x-Extension-QT/icon/patreon_sysTray.png similarity index 100% rename from SRC/Waifu2x-Extension-QT/icon/patreon_sysTray.png rename to SRC_v3.41.01-beta/Waifu2x-Extension-QT/icon/patreon_sysTray.png diff --git a/SRC/Waifu2x-Extension-QT/icon/pause-button.png b/SRC_v3.41.01-beta/Waifu2x-Extension-QT/icon/pause-button.png similarity index 100% rename from SRC/Waifu2x-Extension-QT/icon/pause-button.png rename to SRC_v3.41.01-beta/Waifu2x-Extension-QT/icon/pause-button.png diff --git a/SRC/Waifu2x-Extension-QT/icon/paypal.png b/SRC_v3.41.01-beta/Waifu2x-Extension-QT/icon/paypal.png similarity index 100% rename from SRC/Waifu2x-Extension-QT/icon/paypal.png rename to SRC_v3.41.01-beta/Waifu2x-Extension-QT/icon/paypal.png diff --git a/SRC/Waifu2x-Extension-QT/icon/picture_Rmenu.png b/SRC_v3.41.01-beta/Waifu2x-Extension-QT/icon/picture_Rmenu.png similarity index 100% rename from SRC/Waifu2x-Extension-QT/icon/picture_Rmenu.png rename to SRC_v3.41.01-beta/Waifu2x-Extension-QT/icon/picture_Rmenu.png diff --git a/SRC/Waifu2x-Extension-QT/icon/refresh.png b/SRC_v3.41.01-beta/Waifu2x-Extension-QT/icon/refresh.png similarity index 100% rename from SRC/Waifu2x-Extension-QT/icon/refresh.png rename to SRC_v3.41.01-beta/Waifu2x-Extension-QT/icon/refresh.png diff --git a/SRC/Waifu2x-Extension-QT/icon/video_Rmenu.png b/SRC_v3.41.01-beta/Waifu2x-Extension-QT/icon/video_Rmenu.png similarity index 100% rename from SRC/Waifu2x-Extension-QT/icon/video_Rmenu.png rename to SRC_v3.41.01-beta/Waifu2x-Extension-QT/icon/video_Rmenu.png diff --git a/SRC/Waifu2x-Extension-QT/icon/view_file.png b/SRC_v3.41.01-beta/Waifu2x-Extension-QT/icon/view_file.png similarity index 100% rename from SRC/Waifu2x-Extension-QT/icon/view_file.png rename to SRC_v3.41.01-beta/Waifu2x-Extension-QT/icon/view_file.png diff --git a/SRC/Waifu2x-Extension-QT/image.cpp b/SRC_v3.41.01-beta/Waifu2x-Extension-QT/image.cpp similarity index 100% rename from SRC/Waifu2x-Extension-QT/image.cpp rename to SRC_v3.41.01-beta/Waifu2x-Extension-QT/image.cpp diff --git a/SRC/Waifu2x-Extension-QT/language_Chinese.qm b/SRC_v3.41.01-beta/Waifu2x-Extension-QT/language_Chinese.qm similarity index 100% rename from SRC/Waifu2x-Extension-QT/language_Chinese.qm rename to SRC_v3.41.01-beta/Waifu2x-Extension-QT/language_Chinese.qm diff --git a/SRC/Waifu2x-Extension-QT/language_Chinese.ts b/SRC_v3.41.01-beta/Waifu2x-Extension-QT/language_Chinese.ts similarity index 100% rename from SRC/Waifu2x-Extension-QT/language_Chinese.ts rename to SRC_v3.41.01-beta/Waifu2x-Extension-QT/language_Chinese.ts diff --git a/SRC/Waifu2x-Extension-QT/language_English.qm b/SRC_v3.41.01-beta/Waifu2x-Extension-QT/language_English.qm similarity index 100% rename from SRC/Waifu2x-Extension-QT/language_English.qm rename to SRC_v3.41.01-beta/Waifu2x-Extension-QT/language_English.qm diff --git a/SRC/Waifu2x-Extension-QT/language_English.ts b/SRC_v3.41.01-beta/Waifu2x-Extension-QT/language_English.ts similarity index 100% rename from SRC/Waifu2x-Extension-QT/language_English.ts rename to SRC_v3.41.01-beta/Waifu2x-Extension-QT/language_English.ts diff --git a/SRC/Waifu2x-Extension-QT/language_TraditionalChinese.qm b/SRC_v3.41.01-beta/Waifu2x-Extension-QT/language_TraditionalChinese.qm similarity index 100% rename from SRC/Waifu2x-Extension-QT/language_TraditionalChinese.qm rename to SRC_v3.41.01-beta/Waifu2x-Extension-QT/language_TraditionalChinese.qm diff --git a/SRC/Waifu2x-Extension-QT/language_TraditionalChinese.ts b/SRC_v3.41.01-beta/Waifu2x-Extension-QT/language_TraditionalChinese.ts similarity index 100% rename from SRC/Waifu2x-Extension-QT/language_TraditionalChinese.ts rename to SRC_v3.41.01-beta/Waifu2x-Extension-QT/language_TraditionalChinese.ts diff --git a/SRC/Waifu2x-Extension-QT/main.cpp b/SRC_v3.41.01-beta/Waifu2x-Extension-QT/main.cpp similarity index 97% rename from SRC/Waifu2x-Extension-QT/main.cpp rename to SRC_v3.41.01-beta/Waifu2x-Extension-QT/main.cpp index ed4f1eb..ffd8e1c 100644 --- a/SRC/Waifu2x-Extension-QT/main.cpp +++ b/SRC_v3.41.01-beta/Waifu2x-Extension-QT/main.cpp @@ -1,85 +1,85 @@ -/* - Copyright (C) 2021 Aaron Feng - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU Affero General Public License as published - by the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Affero General Public License for more details. - - You should have received a copy of the GNU Affero General Public License - along with this program. If not, see . - - My Github homepage: https://github.com/AaronFeng753 -*/ - -#include "mainwindow.h" - -#include - -int main(int argc, char *argv[]) -{ - QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);//高分辨率屏幕支持 - QApplication a(argc,argv); - a.setQuitOnLastWindowClosed(false);//隐藏无窗口时保持运行 - MainWindow *w = new MainWindow; - w->show(); - return a.exec(); -} - -/* -Change log: - -****************** 补全中文翻译 *********************** - -v3.41.02-beta: -- Fix bug: Unable to assemble APNG when there are "%" in the path. - -v3.41.01-beta: -- New Feature: APNG(Animated PNG) support. -- Improve GUI. -- Some other improvements. - -v3.31.21-beta: -- Performance optimization. -- Update FFmpeg, ImageMagick. -- Some other improvements. - --------------------------------------------------------------------------- -To do: -- APNG插件兼容性测试 -- 找一个性能更好的apng组装插件(试试ffmpeg) -- 添加对"图片文件夹"的支持,一次处理一个文件夹. -- 改进自动调整引擎设定 -- 插帧时避免黑帧混乱,避免转场混乱 (插帧后的帧编号 = N*2-1) -- 自动将GIF转换为mp4 -- 在SRMD和REALSR正式加入cpu支持后, 在GPU ID tooltip上添加[★ "-1" is CPU,others are GPUs ★] -- CRF参数调整支持 -- 自动监控文件夹 ---------------------------------------------------------------------------- -Integrated component: -- gifsicle version 1.92 -- SoX 14.4.2-win32 -- waifu2x-caffe 1.2.0.4 -- Waifu2x-converter 9e0284ae23d43c990efb6320253ff0f1e3776854 -- Waifu2x-NCNN-Vulkan 20210210 -- SRMD-NCNN-Vulkan 20210210 -- RealSR-NCNN-Vulkan 20210210 -- ImageMagick 7.0.11-8-portable-Q16-x64 -- Anime4KCPP v2.5.0 -- FFmpeg 2021-04-20-git-718e03e5f2-full_build -- NirCmd v2.86 -- Ghostscript 9.53.3 -- GNU Wget 1.20.3 -- rife-ncnn-vulkan 20210227 -- cain-ncnn-vulkan 20210210 ---------------------------------------------------------------------------- -Icons made by : -Freepik (https://www.flaticon.com/authors/freepik) From Flaticon : https://www.flaticon.com/ -Roundicons (https://www.flaticon.com/authors/roundicons) From Flaticon : https://www.flaticon.com/ -Icongeek26 (https://www.flaticon.com/authors/Icongeek26) From Flaticon : https://www.flaticon.com/ -*/ +/* + Copyright (C) 2021 Aaron Feng + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU Affero General Public License as published + by the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program. If not, see . + + My Github homepage: https://github.com/AaronFeng753 +*/ + +#include "mainwindow.h" + +#include + +int main(int argc, char *argv[]) +{ + QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);//高分辨率屏幕支持 + QApplication a(argc,argv); + a.setQuitOnLastWindowClosed(false);//隐藏无窗口时保持运行 + MainWindow *w = new MainWindow; + w->show(); + return a.exec(); +} + +/* +Change log: + +****************** 补全中文翻译 *********************** + +v3.41.02-beta: +- Fix bug: Unable to assemble APNG when there are "%" in the path. + +v3.41.01-beta: +- New Feature: APNG(Animated PNG) support. +- Improve GUI. +- Some other improvements. + +v3.31.21-beta: +- Performance optimization. +- Update FFmpeg, ImageMagick. +- Some other improvements. + +-------------------------------------------------------------------------- +To do: +- APNG插件兼容性测试 +- 找一个性能更好的apng组装插件(试试ffmpeg) +- 添加对"图片文件夹"的支持,一次处理一个文件夹. +- 改进自动调整引擎设定 +- 插帧时避免黑帧混乱,避免转场混乱 (插帧后的帧编号 = N*2-1) +- 自动将GIF转换为mp4 +- 在SRMD和REALSR正式加入cpu支持后, 在GPU ID tooltip上添加[★ "-1" is CPU,others are GPUs ★] +- CRF参数调整支持 +- 自动监控文件夹 +--------------------------------------------------------------------------- +Integrated component: +- gifsicle version 1.92 +- SoX 14.4.2-win32 +- waifu2x-caffe 1.2.0.4 +- Waifu2x-converter 9e0284ae23d43c990efb6320253ff0f1e3776854 +- Waifu2x-NCNN-Vulkan 20210210 +- SRMD-NCNN-Vulkan 20210210 +- RealSR-NCNN-Vulkan 20210210 +- ImageMagick 7.0.11-8-portable-Q16-x64 +- Anime4KCPP v2.5.0 +- FFmpeg 2021-04-20-git-718e03e5f2-full_build +- NirCmd v2.86 +- Ghostscript 9.53.3 +- GNU Wget 1.20.3 +- rife-ncnn-vulkan 20210227 +- cain-ncnn-vulkan 20210210 +--------------------------------------------------------------------------- +Icons made by : +Freepik (https://www.flaticon.com/authors/freepik) From Flaticon : https://www.flaticon.com/ +Roundicons (https://www.flaticon.com/authors/roundicons) From Flaticon : https://www.flaticon.com/ +Icongeek26 (https://www.flaticon.com/authors/Icongeek26) From Flaticon : https://www.flaticon.com/ +*/ diff --git a/SRC/Waifu2x-Extension-QT/mainwindow.cpp b/SRC_v3.41.01-beta/Waifu2x-Extension-QT/mainwindow.cpp similarity index 97% rename from SRC/Waifu2x-Extension-QT/mainwindow.cpp rename to SRC_v3.41.01-beta/Waifu2x-Extension-QT/mainwindow.cpp index acf87d8..4057788 100644 --- a/SRC/Waifu2x-Extension-QT/mainwindow.cpp +++ b/SRC_v3.41.01-beta/Waifu2x-Extension-QT/mainwindow.cpp @@ -1,2112 +1,2112 @@ -/* - Copyright (C) 2021 Aaron Feng - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU Affero General Public License as published - by the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Affero General Public License for more details. - - You should have received a copy of the GNU Affero General Public License - along with this program. If not, see . - - My Github homepage: https://github.com/AaronFeng753 -*/ - -#include "mainwindow.h" -#include "ui_mainwindow.h" - -MainWindow::MainWindow(QWidget *parent) - : QMainWindow(parent) - , ui(new Ui::MainWindow) -{ - ui->setupUi(this); - qRegisterMetaTypeStreamOperators("QList_QMap_QStrQStr"); - QThreadPool::globalInstance()->setMaxThreadCount(60);//解除全局线程池的最大线程数量限制 - //============== - this->setWindowTitle("Waifu2x-Extension-GUI "+VERSION+" by Aaron Feng"); - //============== - translator = new QTranslator(this); - //============== - ui->tabWidget->setCurrentIndex(1);//显示home tab - ui->tabWidget->tabBar()->setTabTextColor(0,Qt::red); - on_tabWidget_currentChanged(1); - ui->tabWidget_Engines->setCurrentIndex(0); - this->setAcceptDrops(true);//mainwindow接收drop - Init_Table();//初始化table - ui->groupBox_CurrentFile->setVisible(0);//隐藏当前文件进度 - pushButton_Stop_setEnabled_self(0);//禁用隐藏暂停按钮 - ui->pushButton_ForceRetry->setVisible(0); - ui->progressBar_CompatibilityTest->setVisible(0); - //=================== 初始隐藏所有table和禁用按钮 ====================== - ui->tableView_image->setVisible(0); - ui->tableView_gif->setVisible(0); - ui->tableView_video->setVisible(0); - Table_FileCount_reload();//重载文件列表下的文件数量统计 - //============== - Init_ActionsMenu_checkBox_ReplaceOriginalFile();//第一次初始化[替换原文件]的右键菜单(需要在载入设定前设置为checkable - Init_ActionsMenu_checkBox_DelOriginal(); - //=========安装事件过滤器========== - ui->tableView_image->installEventFilter(this); - ui->tableView_gif->installEventFilter(this); - ui->tableView_video->installEventFilter(this); - //=========================================== - connect(this, SIGNAL(Send_Set_checkBox_DisableResize_gif_Checked()), this, SLOT(Set_checkBox_DisableResize_gif_Checked())); - connect(this, SIGNAL(Send_Table_EnableSorting(bool)), this, SLOT(Table_EnableSorting(bool))); - connect(this, SIGNAL(Send_Add_progressBar_CompatibilityTest()), this, SLOT(Add_progressBar_CompatibilityTest())); - connect(this, SIGNAL(Send_Unable2Connect_RawGithubusercontentCom()), this, SLOT(Unable2Connect_RawGithubusercontentCom())); - connect(this, SIGNAL(Send_SetEnable_pushButton_ForceRetry_self()), this, SLOT(SetEnable_pushButton_ForceRetry_self())); - connect(this, SIGNAL(Send_SystemTray_NewMessage(QString)), this, SLOT(SystemTray_NewMessage(QString))); - connect(this, SIGNAL(Send_PrograssBar_Range_min_max(int, int)), this, SLOT(progressbar_setRange_min_max(int, int))); - connect(this, SIGNAL(Send_progressbar_Add()), this, SLOT(progressbar_Add())); - connect(this, SIGNAL(Send_Table_image_ChangeStatus_rowNumInt_statusQString(int, QString)), this, SLOT(Table_image_ChangeStatus_rowNumInt_statusQString(int, QString))); - connect(this, SIGNAL(Send_Table_gif_ChangeStatus_rowNumInt_statusQString(int, QString)), this, SLOT(Table_gif_ChangeStatus_rowNumInt_statusQString(int, QString))); - connect(this, SIGNAL(Send_Table_video_ChangeStatus_rowNumInt_statusQString(int, QString)), this, SLOT(Table_video_ChangeStatus_rowNumInt_statusQString(int, QString))); - connect(this, SIGNAL(Send_Table_FileCount_reload()), this, SLOT(Table_FileCount_reload())); - connect(this, SIGNAL(Send_Table_image_insert_fileName_fullPath(QString,QString)), this, SLOT(Table_image_insert_fileName_fullPath(QString,QString))); - connect(this, SIGNAL(Send_Table_gif_insert_fileName_fullPath(QString,QString)), this, SLOT(Table_gif_insert_fileName_fullPath(QString,QString))); - connect(this, SIGNAL(Send_Table_video_insert_fileName_fullPath(QString,QString)), this, SLOT(Table_video_insert_fileName_fullPath(QString,QString))); - connect(this, SIGNAL(Send_Table_image_CustRes_rowNumInt_HeightQString_WidthQString(int,QString,QString)), this, SLOT(Table_image_CustRes_rowNumInt_HeightQString_WidthQString(int,QString,QString))); - connect(this, SIGNAL(Send_Table_gif_CustRes_rowNumInt_HeightQString_WidthQString(int,QString,QString)), this, SLOT(Table_gif_CustRes_rowNumInt_HeightQString_WidthQString(int,QString,QString))); - connect(this, SIGNAL(Send_Table_video_CustRes_rowNumInt_HeightQString_WidthQString(int,QString,QString)), this, SLOT(Table_video_CustRes_rowNumInt_HeightQString_WidthQString(int,QString,QString))); - connect(this, SIGNAL(Send_Table_Read_Saved_Table_Filelist_Finished(QString)), this, SLOT(Table_Read_Saved_Table_Filelist_Finished(QString))); - connect(this, SIGNAL(Send_Table_Save_Current_Table_Filelist_Finished()), this, SLOT(Table_Save_Current_Table_Filelist_Finished())); - connect(this, SIGNAL(Send_Waifu2x_Finished()), this, SLOT(Waifu2x_Finished())); - connect(this, SIGNAL(Send_Waifu2x_Finished_manual()), this, SLOT(Waifu2x_Finished_manual())); - connect(this, SIGNAL(Send_TextBrowser_NewMessage(QString)), this, SLOT(TextBrowser_NewMessage(QString))); - connect(this, SIGNAL(Send_Waifu2x_Compatibility_Test_finished()), this, SLOT(Waifu2x_Compatibility_Test_finished())); - connect(this, SIGNAL(Send_Waifu2x_DetectGPU_finished()), this, SLOT(Waifu2x_DetectGPU_finished())); - connect(this, SIGNAL(Send_Realsr_ncnn_vulkan_DetectGPU_finished()), this, SLOT(Realsr_ncnn_vulkan_DetectGPU_finished())); - connect(this, SIGNAL(Send_CheckUpadte_NewUpdate(QString,QString)), this, SLOT(CheckUpadte_NewUpdate(QString,QString))); - connect(this, SIGNAL(Send_SystemShutDown()), this, SLOT(SystemShutDown())); - connect(this, SIGNAL(Send_Waifu2x_DumpProcessorList_converter_finished()), this, SLOT(Waifu2x_DumpProcessorList_converter_finished())); - connect(this, SIGNAL(Send_Read_urls_finfished()), this, SLOT(Read_urls_finfished())); - connect(this, SIGNAL(Send_FinishedProcessing_DN()), this, SLOT(FinishedProcessing_DN())); - connect(this, SIGNAL(Send_SRMD_DetectGPU_finished()), this, SLOT(SRMD_DetectGPU_finished())); - connect(this, SIGNAL(Send_FrameInterpolation_DetectGPU_finished()), this, SLOT(FrameInterpolation_DetectGPU_finished())); - connect(this, SIGNAL(Send_video_write_VideoConfiguration(QString,int,int,bool,int,int,QString,bool,QString,QString,bool,int)), this, SLOT(video_write_VideoConfiguration(QString,int,int,bool,int,int,QString,bool,QString,QString,bool,int))); - connect(this, SIGNAL(Send_Settings_Save()), this, SLOT(Settings_Save())); - connect(this, SIGNAL(Send_video_write_Progress_ProcessBySegment(QString,int,bool,bool,int,int)), this, SLOT(video_write_Progress_ProcessBySegment(QString,int,bool,bool,int,int))); - connect(this, SIGNAL(Send_Donate_ReplaceQRCode(QString)), this, SLOT(Donate_ReplaceQRCode(QString))); - connect(this, SIGNAL(Send_CurrentFileProgress_Start(QString,int)), this, SLOT(CurrentFileProgress_Start(QString,int))); - connect(this, SIGNAL(Send_CurrentFileProgress_Stop()), this, SLOT(CurrentFileProgress_Stop())); - connect(this, SIGNAL(Send_CurrentFileProgress_progressbar_Add()), this, SLOT(CurrentFileProgress_progressbar_Add())); - connect(this, SIGNAL(Send_CurrentFileProgress_progressbar_Add_SegmentDuration(int)), this, SLOT(CurrentFileProgress_progressbar_Add_SegmentDuration(int))); - connect(this, SIGNAL(Send_CurrentFileProgress_progressbar_SetFinishedValue(int)), this, SLOT(CurrentFileProgress_progressbar_SetFinishedValue(int))); - //====== - TimeCostTimer = new QTimer(); - connect(TimeCostTimer, SIGNAL(timeout()), this, SLOT(TimeSlot())); - //================================================== - Settings_Read_Apply();//读取与应用设置 - //===================================== - Set_Font_fixed();//固定字体 - //===================================== - QtConcurrent::run(this, &MainWindow::DeleteErrorLog_Waifu2xCaffe);//删除Waifu2xCaffe生成的错误日志 - QtConcurrent::run(this, &MainWindow::Del_TempBatFile);//删除bat文件缓存 - AutoUpdate = QtConcurrent::run(this, &MainWindow::CheckUpadte_Auto);//自动检查更新线程 - DownloadOnlineQRCode = QtConcurrent::run(this, &MainWindow::Donate_DownloadOnlineQRCode);//在线更新捐赠二维码 - SystemShutDown_isAutoShutDown();//上次是否自动关机 - //==================================== - TextBrowser_StartMes();//显示启动msg - //=================================== - Tip_FirstTimeStart();//首次启动 - file_mkDir(Current_Path+"/FilesList_W2xEX");//生成保存文件列表的文件夹 - //============== - /* - 校验软件是否对所在目录有写权限 - */ - if(file_isDirWritable(Current_Path)==false) - { - QMessageBox Msg(QMessageBox::Question, QString(tr("Error")), QString(tr("It is detected that this software lacks the necessary permissions to run." - "\n\nPlease close this software and start this software again after giving this software administrator permission. " - "Or reinstall the software into a directory that can run normally without administrator rights.\n\nOtherwise, this software may not work properly."))); - Msg.setIcon(QMessageBox::Warning); - Msg.addButton(QString("OK"), QMessageBox::NoRole); - Msg.exec(); - } - //============== - Init_SystemTrayIcon();//初始化托盘图标 - Init_ActionsMenu_lineEdit_outputPath();//初始化 输出路径 lineEDIT的右键菜单 - Init_ActionsMenu_FilesList(); - Init_ActionsMenu_pushButton_RemoveItem(); - Init_ActionsMenu_checkBox_ReplaceOriginalFile();//第二次初始化[替换原文件]的右键菜单(载入语言设置 - Init_ActionsMenu_checkBox_DelOriginal(); - //============== - this->showNormal(); - this->activateWindow(); - this->setWindowState((this->windowState() & ~Qt::WindowMinimized) | Qt::WindowActive); - this->adjustSize(); -} - -MainWindow::~MainWindow() -{ - delete ui; -} - -void MainWindow::closeEvent(QCloseEvent *event) -{ - if(isAlreadyClosed)//解决QT退出时重复调用closeEvent的问题 - { - event->accept(); - return; - } - //=============== 询问是否退出 ======================= - if(ui->checkBox_PromptWhenExit->isChecked()) - { - QMessageBox Msg(QMessageBox::Question, QString(tr("Notification")), QString(tr("Do you really wanna exit Waifu2x-Extension-GUI ?"))); - Msg.setIcon(QMessageBox::Question); - QAbstractButton *pYesBtn = Msg.addButton(QString(tr("YES")), QMessageBox::YesRole); - QAbstractButton *pNoBtn = Msg.addButton(QString(tr("NO")), QMessageBox::NoRole); - Msg.exec(); - if (Msg.clickedButton() == pNoBtn) - { - event->ignore(); - return; - } - if (Msg.clickedButton() == pYesBtn)isAlreadyClosed=true; - } - //============================= - systemTray->hide(); - this->hide(); - QApplication::setQuitOnLastWindowClosed(true);//無窗口時不再保持運行 - QApplication::closeAllWindows(); - //==== - if(Waifu2xMain.isRunning() == true) - { - TimeCostTimer->stop(); - pushButton_Stop_setEnabled_self(0);//隐藏stop button - waifu2x_STOP = true; - emit TextBrowser_NewMessage(tr("Trying to stop, please wait...")); - //====== - QMessageBox *MSG_2 = new QMessageBox(); - MSG_2->setWindowTitle(tr("Notification")+" @Waifu2x-Extension-GUI"); - MSG_2->setText(tr("Waiting for the files processing thread to pause")); - MSG_2->setIcon(QMessageBox::Information); - MSG_2->setModal(true); - MSG_2->setStandardButtons(NULL); - MSG_2->setWindowFlags(Qt::CustomizeWindowHint | Qt::WindowTitleHint); - MSG_2->show(); - } - else - { - QMessageBox *MSG_2 = new QMessageBox(); - MSG_2->setWindowTitle(tr("Notification")+" @Waifu2x-Extension-GUI"); - MSG_2->setText(tr("Closing...\n\nPlease wait")); - MSG_2->setIcon(QMessageBox::Information); - MSG_2->setModal(true); - MSG_2->setStandardButtons(NULL); - MSG_2->setWindowFlags(Qt::CustomizeWindowHint | Qt::WindowTitleHint); - MSG_2->show(); - } - AutoUpdate.cancel(); - DownloadOnlineQRCode.cancel(); - //===== - bool AutoSaveSettings = ui->checkBox_AutoSaveSettings->isChecked(); - if(AutoSaveSettings&&(!Settings_isReseted)) - { - Settings_Save(); - QtConcurrent::run(this, &MainWindow::Auto_Save_Settings_Watchdog,true); - } - else - { - QtConcurrent::run(this, &MainWindow::Auto_Save_Settings_Watchdog,false); - } -} - -int MainWindow::Auto_Save_Settings_Watchdog(bool isWaitForSave) -{ - Waifu2xMain.waitForFinished(); - //====== - if(isWaitForSave == true) - { - Delay_msec_sleep(1000); - QString settings_ini = Current_Path+"/settings.ini"; - while(!QFile::exists(settings_ini)) - { - Delay_msec_sleep(250); - } - Delay_msec_sleep(3000); - } - //===== - Force_close(); - //==== - return 0; -} - -int MainWindow::Force_close() -{ - //============= - QStringList TaskNameList; - TaskNameList << "convert_waifu2xEX.exe"<<"ffmpeg_waifu2xEX.exe"<<"ffprobe_waifu2xEX.exe"<<"identify_waifu2xEX.exe"<<"gifsicle_waifu2xEX.exe"<<"waifu2x-ncnn-vulkan_waifu2xEX.exe" - <<"waifu2x-ncnn-vulkan-fp16p_waifu2xEX.exe"<<"Anime4K_waifu2xEX.exe"<<"waifu2x-caffe_waifu2xEX.exe"<<"srmd-ncnn-vulkan_waifu2xEX.exe"<<"realsr-ncnn-vulkan_waifu2xEX.exe" - <<"waifu2x-converter-cpp_waifu2xEX.exe"<<"sox_waifu2xEX.exe"<<"wget_waifu2xEX.exe"<<"rife-ncnn-vulkan_waifu2xEX.exe"<<"cain-ncnn-vulkan_waifu2xEX.exe"<<"dain-ncnn-vulkan_waifu2xEX.exe" - <<"srmd-cuda_waifu2xEX.exe"<<"apngdis_waifu2xEX.exe"<<"apngasm_waifu2xEX.exe"; - KILL_TASK_QStringList(TaskNameList,true); - //=========== - QProcess Close; - Close.start("taskkill /f /t /fi \"imagename eq Waifu2x-Extension-GUI.exe\""); - Close.waitForStarted(10000); - Close.waitForFinished(10000); - return 0; -} -/* -最小化 -*/ -void MainWindow::changeEvent(QEvent *e) -{ - if((e->type()==QEvent::WindowStateChange)&&this->isMinimized()) - { - if(ui->checkBox_MinimizeToTaskbar->isChecked()) - { - this->hide(); - } - } -} -/* -计时器到时执行的代码 -*/ -void MainWindow::TimeSlot() -{ - TimeCost++; - //====================总进度================== - QString TimeCostStr = tr("Time taken:[")+Seconds2hms(TimeCost)+"]"; - ui->label_TimeCost->setText(TimeCostStr); - if(ui->label_TimeRemain->isVisible()) - { - long unsigned int TaskNumFinished_tmp = TaskNumFinished; - long unsigned int TimeCost_tmp = TimeCost; - long unsigned int TaskNumTotal_tmp = TaskNumTotal; - if(TaskNumFinished_tmp>0&&TimeCost_tmp>0&&TaskNumTotal_tmp>0) - { - if(NewTaskFinished) - { - NewTaskFinished=false; - double avgTimeCost = (double)TimeCost_tmp/(double)TaskNumFinished_tmp; - ETA = avgTimeCost*((double)TaskNumTotal_tmp-(double)TaskNumFinished_tmp); - } - else - { - if(ETA>1) - { - ETA--; - } - } - QString TimeRemainingStr = tr("Time remaining:[")+Seconds2hms(ETA)+"]"; - ui->label_TimeRemain->setText(TimeRemainingStr); - QDateTime time = QDateTime::currentDateTime(); - long unsigned int Time_t = time.toTime_t(); - Time_t+=ETA; - time = QDateTime::fromTime_t(Time_t); - QString Current_Time = time.toString("hh:mm:ss"); - QString ETA_str = "ETA:["+Current_Time+"]"; - ui->label_ETA->setText(ETA_str); - } - } - //====================当前文件================= - if(isStart_CurrentFile) - { - TimeCost_CurrentFile++; - QString TimeCostStr_CurrentFile = tr("Time taken:[")+Seconds2hms(TimeCost_CurrentFile)+"]"; - ui->label_TimeCost_CurrentFile->setText(TimeCostStr_CurrentFile); - long unsigned int TaskNumFinished_tmp_CurrentFile = TaskNumFinished_CurrentFile; - long unsigned int TimeCost_tmp_CurrentFile = TimeCost_CurrentFile; - long unsigned int TaskNumTotal_tmp_CurrentFile = TaskNumTotal_CurrentFile; - if(TaskNumFinished_tmp_CurrentFile>0&&TimeCost_tmp_CurrentFile>0&&TaskNumTotal_tmp_CurrentFile>0) - { - if(NewTaskFinished_CurrentFile) - { - NewTaskFinished_CurrentFile=false; - double avgTimeCost_CurrentFile = (double)TimeCost_tmp_CurrentFile/(double)TaskNumFinished_tmp_CurrentFile; - ETA_CurrentFile = avgTimeCost_CurrentFile*((double)TaskNumTotal_tmp_CurrentFile-(double)TaskNumFinished_tmp_CurrentFile); - } - else - { - if(ETA_CurrentFile>1) - { - ETA_CurrentFile--; - } - } - QString TimeRemainingStr_CurrentFile = tr("Time remaining:[")+Seconds2hms(ETA_CurrentFile)+"]"; - ui->label_TimeRemain_CurrentFile->setText(TimeRemainingStr_CurrentFile); - QDateTime time_CurrentFile = QDateTime::currentDateTime(); - long unsigned int Time_t_CurrentFile = time_CurrentFile.toTime_t(); - Time_t_CurrentFile+=ETA_CurrentFile; - time_CurrentFile = QDateTime::fromTime_t(Time_t_CurrentFile); - QString Current_Time_CurrentFile = time_CurrentFile.toString("hh:mm:ss"); - QString ETA_str_CurrentFile = "ETA:["+Current_Time_CurrentFile+"]"; - ui->label_ETA_CurrentFile->setText(ETA_str_CurrentFile); - } - } -} -QString MainWindow::Seconds2hms(long unsigned int seconds) -{ - if(seconds<=0)return "0:0:0"; - long unsigned int hour = seconds / 3600; - long unsigned int min = (seconds-(hour*3600))/60; - long unsigned int sec = seconds - hour*3600 - min*60; - return QString::number(hour,10)+":"+QString::number(min,10)+":"+QString::number(sec,10); -} - -void MainWindow::Set_Font_fixed() -{ - QFont font; - if(ui->checkBox_isCustFontEnable->isChecked()) - { - font = ui->fontComboBox_CustFont->currentFont(); - font.setPixelSize(ui->spinBox_GlobalFontSize->value()); - } - else - { - font = qApp->font(); - font.setPixelSize(15); - } - qApp->setFont(font); -} - -void MainWindow::on_pushButton_ClearList_clicked() -{ - curRow_image = -1; - curRow_gif = -1; - curRow_video = -1; - Table_Clear(); - Custom_resolution_list.clear(); - ui->label_DropFile->setVisible(1); - ui->tableView_gif->setVisible(0); - ui->tableView_image->setVisible(0); - ui->tableView_video->setVisible(0); - Table_FileCount_reload(); - progressbar_clear(); -} - -/* -停止处理键 -*/ -void MainWindow::on_pushButton_Stop_clicked() -{ - if(Waifu2xMain.isRunning()==false)return; - TimeCostTimer->stop(); - pushButton_Stop_setEnabled_self(0);//隐藏stop button - waifu2x_STOP = true; - emit TextBrowser_NewMessage(tr("Trying to stop, please wait...")); - QtConcurrent::run(this, &MainWindow::Wait_waifu2x_stop); -} -/* -等待处理线程完全停止 -*/ -void MainWindow::Wait_waifu2x_stop() -{ - while(true) - { - if(waifu2x_STOP_confirm||ThreadNumRunning==0) - { - waifu2x_STOP_confirm = false; - Waifu2xMain.waitForFinished(); - while(true) - { - if(Waifu2xMain.isRunning()==false)break; - Delay_msec_sleep(300); - } - emit TextBrowser_NewMessage(tr("Processing of files has stopped.")); - QtConcurrent::run(this, &MainWindow::Play_NFSound);//成功暂停,播放提示音 - break; - } - Delay_msec_sleep(300); - } - emit Send_Waifu2x_Finished_manual(); -} -/* -从tableview移除item -*/ -int MainWindow::on_pushButton_RemoveItem_clicked() -{ - if(curRow_image==-1&&curRow_video==-1&&curRow_gif==-1) - { - ui->tableView_image->clearSelection(); - ui->tableView_gif->clearSelection(); - ui->tableView_video->clearSelection(); - //===== - QMessageBox *MSG = new QMessageBox(); - MSG->setWindowTitle(tr("Warning")); - MSG->setText(tr("No items are currently selected.")); - MSG->setIcon(QMessageBox::Warning); - MSG->setModal(true); - MSG->show(); - //===== - return 0; - } - //========================== - if(curRow_image >= 0) - { - CustRes_remove(Table_model_image->item(curRow_image,2)->text()); - ui->tableView_image->setUpdatesEnabled(false); - Table_model_image->removeRow(curRow_image); - ui->tableView_image->setUpdatesEnabled(true); - curRow_image = -1; - ui->tableView_image->clearSelection(); - } - //============================================================ - if(curRow_video >= 0) - { - CustRes_remove(Table_model_video->item(curRow_video,2)->text()); - ui->tableView_video->setUpdatesEnabled(false); - Table_model_video->removeRow(curRow_video); - ui->tableView_video->setUpdatesEnabled(true); - curRow_video = -1; - ui->tableView_video->clearSelection(); - } - //============================================================ - if(curRow_gif >= 0) - { - CustRes_remove(Table_model_gif->item(curRow_gif,2)->text()); - ui->tableView_gif->setUpdatesEnabled(false); - Table_model_gif->removeRow(curRow_gif); - ui->tableView_gif->setUpdatesEnabled(true); - curRow_gif = -1; - ui->tableView_gif->clearSelection(); - } - //================================================== - if(Table_model_gif->rowCount()==0) - { - ui->tableView_gif->setVisible(0); - } - if(Table_model_image->rowCount()==0) - { - ui->tableView_image->setVisible(0); - } - if(Table_model_video->rowCount()==0) - { - ui->tableView_video->setVisible(0); - } - //=================================================== - if(Table_model_gif->rowCount()==0&&Table_model_image->rowCount()==0&&Table_model_video->rowCount()==0) - { - on_pushButton_ClearList_clicked(); - } - Table_FileCount_reload(); - //============ - return 0; -} - -//========================================================== -/* -============= 安全的阻塞延时 ===================== -*/ -void MainWindow::Delay_sec_sleep(int time) -{ - QThread::sleep(time); -} - -void MainWindow::Delay_msec_sleep(int time) -{ - QThread::msleep(time); -} -//========================================================== - -/* -播放提示音 -*/ -void MainWindow::Play_NFSound() -{ - if(ui->checkBox_NfSound->isChecked()==false)return; - //==== - QString NFSound = Current_Path+"/NFSound_Waifu2xEX.mp3"; - if(QFile::exists(NFSound)==false) - { - emit Send_TextBrowser_NewMessage(tr("Error! Notification sound file is missing!")); - return; - } - //==== - QMediaPlayer *player = new QMediaPlayer; - player->setMedia(QUrl::fromLocalFile(NFSound)); - player->play(); -} - -void MainWindow::on_pushButton_Report_clicked() -{ - QDesktopServices::openUrl(QUrl("https://github.com/AaronFeng753/Waifu2x-Extension-GUI/issues/new")); -} - -void MainWindow::on_pushButton_ReadMe_clicked() -{ - if(ui->comboBox_language->currentIndex()==1) - { - QDesktopServices::openUrl(QUrl("https://github.com/AaronFeng753/Waifu2x-Extension-GUI/")); - QDesktopServices::openUrl(QUrl("https://gitee.com/aaronfeng0711/Waifu2x-Extension-GUI/")); - } - else - { - QDesktopServices::openUrl(QUrl("https://github.com/AaronFeng753/Waifu2x-Extension-GUI/")); - } -} - - - -void MainWindow::on_comboBox_Engine_Image_currentIndexChanged(int index) -{ - switch(ui->comboBox_Engine_Image->currentIndex()) - { - case 0: - { - ui->spinBox_DenoiseLevel_image->setRange(-1,3); - ui->spinBox_DenoiseLevel_image->setValue(2); - ui->spinBox_DenoiseLevel_image->setEnabled(1); - ui->spinBox_DenoiseLevel_image->setToolTip(tr("Range:-1(No noise reduction)~3")); - ui->label_ImageDenoiseLevel->setToolTip(tr("Range:-1(No noise reduction)~3")); - break; - } - case 1: - { - ui->spinBox_DenoiseLevel_image->setRange(0,3); - ui->spinBox_DenoiseLevel_image->setValue(2); - ui->spinBox_DenoiseLevel_image->setEnabled(1); - ui->spinBox_DenoiseLevel_image->setToolTip(tr("Range:0(No noise reduction)~3")); - ui->label_ImageDenoiseLevel->setToolTip(tr("Range:0(No noise reduction)~3")); - break; - } - case 2: - case 6: - { - ui->spinBox_DenoiseLevel_image->setRange(-1,10); - ui->spinBox_DenoiseLevel_image->setValue(4); - ui->spinBox_DenoiseLevel_image->setEnabled(1); - ui->spinBox_DenoiseLevel_image->setToolTip(tr("Range:-1(No noise reduction)~10")); - ui->label_ImageDenoiseLevel->setToolTip(tr("Range:-1(No noise reduction)~10")); - break; - } - case 3: - { - DenoiseLevelSpinboxSetting_Anime4k(); - break; - } - case 4: - { - ui->spinBox_DenoiseLevel_image->setRange(-1,3); - ui->spinBox_DenoiseLevel_image->setValue(2); - ui->spinBox_DenoiseLevel_image->setEnabled(1); - ui->spinBox_DenoiseLevel_image->setToolTip(tr("Range:-1(No noise reduction)~3")); - ui->label_ImageDenoiseLevel->setToolTip(tr("Range:-1(No noise reduction)~3")); - break; - } - case 5: - { - ui->spinBox_DenoiseLevel_image->setRange(0,1); - ui->spinBox_DenoiseLevel_image->setValue(1); - ui->spinBox_DenoiseLevel_image->setEnabled(0); - ui->spinBox_DenoiseLevel_image->setToolTip(tr("Realsr-ncnn-vulkan engine will denoise automatically.")); - ui->label_ImageDenoiseLevel->setToolTip(tr("Realsr-ncnn-vulkan engine will denoise automatically.")); - break; - } - } - isShowAnime4kWarning=true; - on_comboBox_model_vulkan_currentIndexChanged(0); - isWaifu2xCaffeEnabled();//判断是否启用caffe图片风格设定 -} - -void MainWindow::on_comboBox_Engine_GIF_currentIndexChanged(int index) -{ - switch(ui->comboBox_Engine_GIF->currentIndex()) - { - case 0: - { - ui->spinBox_DenoiseLevel_gif->setRange(-1,3); - ui->spinBox_DenoiseLevel_gif->setValue(2); - ui->spinBox_DenoiseLevel_gif->setEnabled(1); - ui->spinBox_DenoiseLevel_gif->setToolTip(tr("Range:-1(No noise reduction)~3")); - ui->label_GIFDenoiseLevel->setToolTip(tr("Range:-1(No noise reduction)~3")); - break; - } - case 1: - { - ui->spinBox_DenoiseLevel_gif->setRange(0,3); - ui->spinBox_DenoiseLevel_gif->setValue(2); - ui->spinBox_DenoiseLevel_gif->setEnabled(1); - ui->spinBox_DenoiseLevel_gif->setToolTip(tr("Range:0(No noise reduction)~3")); - ui->label_GIFDenoiseLevel->setToolTip(tr("Range:0(No noise reduction)~3")); - break; - } - case 2: - case 6: - { - ui->spinBox_DenoiseLevel_gif->setRange(-1,10); - ui->spinBox_DenoiseLevel_gif->setValue(4); - ui->spinBox_DenoiseLevel_gif->setEnabled(1); - ui->spinBox_DenoiseLevel_gif->setToolTip(tr("Range:-1(No noise reduction)~10")); - ui->label_GIFDenoiseLevel->setToolTip(tr("Range:-1(No noise reduction)~10")); - break; - } - case 3: - { - DenoiseLevelSpinboxSetting_Anime4k(); - break; - } - case 4: - { - ui->spinBox_DenoiseLevel_gif->setRange(-1,3); - ui->spinBox_DenoiseLevel_gif->setValue(2); - ui->spinBox_DenoiseLevel_gif->setEnabled(1); - ui->spinBox_DenoiseLevel_gif->setToolTip(tr("Range:-1(No noise reduction)~3")); - ui->label_GIFDenoiseLevel->setToolTip(tr("Range:-1(No noise reduction)~3")); - break; - } - case 5: - { - ui->spinBox_DenoiseLevel_gif->setRange(0,1); - ui->spinBox_DenoiseLevel_gif->setValue(1); - ui->spinBox_DenoiseLevel_gif->setEnabled(0); - ui->spinBox_DenoiseLevel_gif->setToolTip(tr("Realsr-ncnn-vulkan engine will denoise automatically.")); - ui->label_GIFDenoiseLevel->setToolTip(tr("Realsr-ncnn-vulkan engine will denoise automatically.")); - break; - } - } - on_comboBox_model_vulkan_currentIndexChanged(0); - isWaifu2xCaffeEnabled();//判断是否启用caffe图片风格设定 -} - -void MainWindow::on_comboBox_Engine_Video_currentIndexChanged(int index) -{ - switch(ui->comboBox_Engine_Video->currentIndex()) - { - case 0: - { - ui->spinBox_DenoiseLevel_video->setRange(-1,3); - ui->spinBox_DenoiseLevel_video->setValue(2); - ui->spinBox_DenoiseLevel_video->setEnabled(1); - ui->spinBox_DenoiseLevel_video->setToolTip(tr("Range:-1(No noise reduction)~3")); - ui->label_VideoDenoiseLevel->setToolTip(tr("Range:-1(No noise reduction)~3")); - break; - } - case 1: - { - ui->spinBox_DenoiseLevel_video->setRange(0,3); - ui->spinBox_DenoiseLevel_video->setValue(2); - ui->spinBox_DenoiseLevel_video->setEnabled(1); - ui->spinBox_DenoiseLevel_video->setToolTip(tr("Range:0(No noise reduction)~3")); - ui->label_VideoDenoiseLevel->setToolTip(tr("Range:0(No noise reduction)~3")); - break; - } - case 2: - { - DenoiseLevelSpinboxSetting_Anime4k(); - break; - } - case 3: - case 6: - { - ui->spinBox_DenoiseLevel_video->setRange(-1,10); - ui->spinBox_DenoiseLevel_video->setValue(4); - ui->spinBox_DenoiseLevel_video->setEnabled(1); - ui->spinBox_DenoiseLevel_video->setToolTip(tr("Range:-1(No noise reduction)~10")); - ui->label_VideoDenoiseLevel->setToolTip(tr("Range:-1(No noise reduction)~10")); - break; - } - case 4: - { - ui->spinBox_DenoiseLevel_video->setRange(-1,3); - ui->spinBox_DenoiseLevel_video->setValue(2); - ui->spinBox_DenoiseLevel_video->setEnabled(1); - ui->spinBox_DenoiseLevel_video->setToolTip(tr("Range:-1(No noise reduction)~3")); - ui->label_VideoDenoiseLevel->setToolTip(tr("Range:-1(No noise reduction)~3")); - break; - } - case 5: - { - ui->spinBox_DenoiseLevel_video->setRange(0,1); - ui->spinBox_DenoiseLevel_video->setValue(1); - ui->spinBox_DenoiseLevel_video->setEnabled(0); - ui->spinBox_DenoiseLevel_video->setToolTip(tr("Realsr-ncnn-vulkan engine will denoise automatically.")); - ui->label_VideoDenoiseLevel->setToolTip(tr("Realsr-ncnn-vulkan engine will denoise automatically.")); - break; - } - } - on_comboBox_model_vulkan_currentIndexChanged(0); - isWaifu2xCaffeEnabled();//判断是否启用caffe图片风格设定 -} - -void MainWindow::on_pushButton_clear_textbrowser_clicked() -{ - ui->textBrowser->clear(); - TextBrowser_StartMes(); -} - -void MainWindow::on_spinBox_textbrowser_fontsize_valueChanged(int arg1) -{ - int size = ui->spinBox_textbrowser_fontsize->value(); - ui->textBrowser->setStyleSheet("font: "+QString::number(size,10)+"pt \"Arial\";"); - ui->textBrowser->moveCursor(QTextCursor::End); -} - -void MainWindow::on_pushButton_CustRes_apply_clicked() -{ - CustRes_SetCustRes(); -} - -void MainWindow::on_pushButton_CustRes_cancel_clicked() -{ - CustRes_CancelCustRes(); -} - -void MainWindow::on_pushButton_HideSettings_clicked() -{ - if(ui->groupBox_Setting->isVisible()) - { - ui->groupBox_Setting->setVisible(0); - isSettingsHide=true; - ui->pushButton_HideSettings->setText(tr("Show settings")); - } - else - { - ui->groupBox_Setting->setVisible(1); - isSettingsHide=false; - ui->pushButton_HideSettings->setText(tr("Hide settings")); - } -} - -/* -改变语言设置 -*/ -void MainWindow::on_comboBox_language_currentIndexChanged(int index) -{ - //检测是否存在日本语翻译文件,若存在则删除并修正翻译设定 - QString JapaneseQM = Current_Path + "/language_Japanese.qm"; - if(QFile::exists(JapaneseQM)) - { - QFile::remove(JapaneseQM); - if(ui->comboBox_language->currentIndex()==2)//若原语言为日语则重置为英语 - { - ui->comboBox_language->setCurrentIndex(0); - } - if(ui->comboBox_language->currentIndex()==3 || ui->comboBox_language->currentIndex()==-1)//若原语言为繁中则修正设定 - { - ui->comboBox_language->setCurrentIndex(2); - } - } - //============== - QString qmFilename=""; - switch(ui->comboBox_language->currentIndex()) - { - case 0: - { - qmFilename = Current_Path + "/language_English.qm"; - break; - } - case 1: - { - qmFilename = Current_Path + "/language_Chinese.qm"; - break; - } - case 2: - { - qmFilename = Current_Path + "/language_TraditionalChinese.qm"; - break; - } - } - //判断文件是否存在 - if(QFile::exists(qmFilename)==false) - { - QMessageBox *MSG_languageFile404 = new QMessageBox(); - MSG_languageFile404->setWindowTitle(tr("Error")); - MSG_languageFile404->setText(tr("Language file is missing, please reinstall this program.")); - MSG_languageFile404->setIcon(QMessageBox::Warning); - MSG_languageFile404->setModal(true); - MSG_languageFile404->show(); - return; - } - //加载语言文件 - if (translator->load(qmFilename)) - { - qApp->installTranslator(translator); - ui->retranslateUi(this); - Table_FileCount_reload(); - Init_Table(); - Init_SystemTrayIcon(); - Set_Font_fixed(); - //========= - if(ui->checkBox_AlwaysHideSettings->isChecked()) - { - ui->groupBox_Setting->setVisible(0); - isSettingsHide=true; - ui->pushButton_HideSettings->setText(tr("Show settings")); - } - else - { - ui->groupBox_Setting->setVisible(1); - isSettingsHide=false; - ui->pushButton_HideSettings->setText(tr("Hide settings")); - } - //========= - if(ui->checkBox_AlwaysHideTextBrowser->isChecked()) - { - ui->splitter_TextBrowser->setVisible(0); - ui->pushButton_HideTextBro->setText(tr("Show Text Browser")); - } - else - { - ui->splitter_TextBrowser->setVisible(1); - ui->pushButton_HideTextBro->setText(tr("Hide Text Browser")); - } - //========= - if(this->windowState()!=Qt::WindowMaximized) - { - this->adjustSize(); - } - } - else - { - QMessageBox *MSG_Unable2LoadLanguageFiles = new QMessageBox(); - MSG_Unable2LoadLanguageFiles->setWindowTitle(tr("Error")); - MSG_Unable2LoadLanguageFiles->setText(tr("Language file cannot be loaded properly.")); - MSG_Unable2LoadLanguageFiles->setIcon(QMessageBox::Warning); - MSG_Unable2LoadLanguageFiles->setModal(true); - MSG_Unable2LoadLanguageFiles->show(); - } -} - -void MainWindow::on_pushButton_ReadFileList_clicked() -{ - file_mkDir(Current_Path+"/FilesList_W2xEX");//生成保存文件列表的文件夹 - QString Table_FileList_ini = QFileDialog::getOpenFileName(this, tr("Select saved files list @Waifu2x-Extension-GUI"), Current_Path+"/FilesList_W2xEX", "*.ini"); - if(Table_FileList_ini=="")return; - //======== - if(QFile::exists(Table_FileList_ini)) - { - ui_tableViews_setUpdatesEnabled(false); - this->setAcceptDrops(0);//禁止drop file - pushButton_Start_setEnabled_self(0);//禁用start button - ui->pushButton_CustRes_cancel->setEnabled(0); - ui->pushButton_CustRes_apply->setEnabled(0); - ui->pushButton_ReadFileList->setEnabled(0); - ui->pushButton_SaveFileList->setEnabled(0); - ui->pushButton_BrowserFile->setEnabled(0); - on_pushButton_ClearList_clicked(); - Send_TextBrowser_NewMessage(tr("Please wait while reading the file.")); - ui->label_DropFile->setText(tr("Loading list, please wait.")); - QtConcurrent::run(this, &MainWindow::Table_Read_Saved_Table_Filelist,Table_FileList_ini); - } - else - { - QMessageBox *MSG_FileList404 = new QMessageBox(); - MSG_FileList404->setWindowTitle(tr("Error")); - MSG_FileList404->setText(tr("Target files list doesn't exist!")); - MSG_FileList404->setIcon(QMessageBox::Warning); - MSG_FileList404->setModal(true); - MSG_FileList404->show(); - } -} - -void MainWindow::on_Ext_image_editingFinished() -{ - QString ext_image_str = ui->Ext_image->text(); - ext_image_str = ext_image_str.trimmed().replace(":",":").remove(" ").remove(" ").replace(":gif:",":"); - ui->Ext_image->setText(ext_image_str); -} - -void MainWindow::on_Ext_video_editingFinished() -{ - QString ext_video_str = ui->Ext_video->text(); - ext_video_str = ext_video_str.trimmed().replace(":",":").remove(" ").remove(" ").replace(":gif:",":"); - ui->Ext_video->setText(ext_video_str); -} - -void MainWindow::on_checkBox_AutoSaveSettings_clicked() -{ - QString settings_ini = Current_Path+"/settings.ini"; - if(QFile::exists(settings_ini)) - { - QSettings *configIniWrite = new QSettings(settings_ini, QSettings::IniFormat); - configIniWrite->setValue("/settings/AutoSaveSettings", ui->checkBox_AutoSaveSettings->isChecked()); - } -} - -void MainWindow::on_pushButton_about_clicked() -{ - QMessageBox *MSG = new QMessageBox(); - MSG->setWindowTitle(tr("About")); - QString line1 = "Waifu2x-Extension-GUI\n\n"; - QString line2 = VERSION+"\n\n"; - QString line3 = "Github: https://github.com/AaronFeng753/Waifu2x-Extension-GUI\n\n"; - QString line4 = "Waifu2x-Extension-GUI is licensed under the\n"; - QString line5 = "GNU Affero General Public License v3.0\n\n"; - QString line6 = "Copyright (C) 2021 Aaron Feng. All rights reserved.\n\n"; - QString line7 = "The program is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.\n\n"; - QString line8 = "Icons made by : Freepik & Icongeek26 & Roundicons From Flaticon(https://www.flaticon.com/)"; - MSG->setText(line1+line2+line3+line4+line5+line6+line7+line8); - QImage img(":/new/prefix1/icon/icon_main.png"); - QImage img_scaled = img.scaled(50,50,Qt::KeepAspectRatio,Qt::SmoothTransformation); - QPixmap pix(QPixmap::fromImage(img_scaled)); - MSG->setIconPixmap(pix); - MSG->setModal(false); - MSG->show(); -} - -void MainWindow::on_comboBox_AspectRatio_custRes_currentIndexChanged(int index) -{ - int CurrentIndex = ui->comboBox_AspectRatio_custRes->currentIndex(); - switch(CurrentIndex) - { - case 0: - { - CustRes_AspectRatioMode = Qt::IgnoreAspectRatio; - break; - } - case 1: - { - CustRes_AspectRatioMode = Qt::KeepAspectRatio; - break; - } - case 2: - { - CustRes_AspectRatioMode = Qt::KeepAspectRatioByExpanding; - break; - } - } -} - -void MainWindow::on_checkBox_AlwaysHideSettings_stateChanged(int arg1) -{ - if(ui->checkBox_AlwaysHideSettings->isChecked()) - { - ui->groupBox_Setting->setVisible(0); - ui->pushButton_HideSettings->setText(tr("Show settings")); - isSettingsHide=true; - } -} - -void MainWindow::on_pushButton_Save_GlobalFontSize_clicked() -{ - QString settings_ini = Current_Path+"/settings.ini"; - QSettings *configIniWrite = new QSettings(settings_ini, QSettings::IniFormat); - configIniWrite->setValue("/settings/GlobalFontSize", ui->spinBox_GlobalFontSize->value()); - //========= - QMessageBox *MSG = new QMessageBox(); - MSG->setWindowTitle(tr("Notification")); - MSG->setText(tr("Custom Font Settings saved successfully.\n\nRestart the software to take effect.")); - MSG->setIcon(QMessageBox::Information); - MSG->setModal(true); - MSG->show(); -} -/* -================================================================================================== - 浏览与添加文本 -================================================================================================== -*/ -void MainWindow::on_pushButton_BrowserFile_clicked() -{ - QString Last_browsed_path = Current_Path+"/LastBrowsedPath_W2xEX.ini"; - //======== 生成 扩展名过滤 字符串 ========= - QStringList nameFilters; - nameFilters.append("*.gif"); - nameFilters.append("*.apng"); - QString Ext_image_str = ui->Ext_image->text(); - QStringList nameFilters_image = Ext_image_str.split(":"); - nameFilters_image.removeAll("gif"); - nameFilters_image.removeAll("apng"); - for(int i = 0; i < nameFilters_image.size(); ++i) - { - QString tmp = nameFilters_image.at(i).trimmed(); - if(tmp=="")continue; - tmp = "*." + tmp; - nameFilters.append(tmp); - } - QString Ext_video_str = ui->Ext_video->text(); - QStringList nameFilters_video = Ext_video_str.split(":"); - nameFilters_video.removeAll("gif"); - nameFilters_video.removeAll("apng"); - for(int i = 0; i < nameFilters_video.size(); ++i) - { - QString tmp = nameFilters_video.at(i).trimmed(); - if(tmp=="")continue; - tmp = "*." + tmp; - nameFilters.append(tmp); - } - QString nameFilters_QString = ""; - for(int i = 0; i < nameFilters.size(); ++i) - { - QString tmp = nameFilters.at(i).trimmed(); - nameFilters_QString = nameFilters_QString +" "+ tmp; - } - //===================================================== - QString BrowserStartPath = "";//浏览文件时的起始文件夹 - //=========== 读取上一次浏览的文件夹 =========================== - if(QFile::exists(Last_browsed_path)) - { - QSettings *configIniRead = new QSettings(Last_browsed_path, QSettings::IniFormat); - configIniRead->setIniCodec(QTextCodec::codecForName("UTF-8")); - BrowserStartPath = configIniRead->value("/Path").toString(); - if(!QFile::exists(BrowserStartPath))BrowserStartPath = ""; - } - //=========================================================== - QStringList Input_path_List = QFileDialog::getOpenFileNames(this, tr("Select files @Waifu2x-Extension-GUI"), BrowserStartPath, tr("All file(")+nameFilters_QString+")"); - if(Input_path_List.isEmpty()) - { - return; - } - //================== 记住上一次浏览的文件夹 ======================= - QFile::remove(Last_browsed_path); - QSettings *configIniWrite = new QSettings(Last_browsed_path, QSettings::IniFormat); - configIniWrite->setIniCodec(QTextCodec::codecForName("UTF-8")); - configIniWrite->setValue("/Warning/EN", "Do not modify this file! It may cause the program to crash! If problems occur after the modification, delete this file and restart the program."); - QFileInfo lastPath(Input_path_List.at(0)); - QString folder_lastPath = file_getFolderPath(lastPath); - configIniWrite->setValue("/Path", folder_lastPath); - //=============================================================== - AddNew_gif=false; - AddNew_image=false; - AddNew_video=false; - //================== 界面管制 ======================== - ui_tableViews_setUpdatesEnabled(false); - ui->groupBox_Setting->setEnabled(0); - ui->groupBox_FileList->setEnabled(0); - ui->groupBox_InputExt->setEnabled(0); - pushButton_Start_setEnabled_self(0); - ui->checkBox_ScanSubFolders->setEnabled(0); - this->setAcceptDrops(0); - ui->label_DropFile->setText(tr("Adding files, please wait.")); - emit Send_TextBrowser_NewMessage(tr("Adding files, please wait.")); - //=================================================== - QtConcurrent::run(this, &MainWindow::Read_Input_paths_BrowserFile, Input_path_List); -} -/* -读取 路径与添加文件 -*/ -void MainWindow::Read_Input_paths_BrowserFile(QStringList Input_path_List) -{ - Progressbar_MaxVal = Input_path_List.size(); - Progressbar_CurrentVal = 0; - emit Send_PrograssBar_Range_min_max(0, Progressbar_MaxVal); - foreach(QString Input_path, Input_path_List) - { - Input_path=Input_path.trimmed(); - if(QFile::exists(Input_path)==false)continue; - Add_File_Folder(Input_path); - emit Send_progressbar_Add(); - } - emit Send_Read_urls_finfished(); -} -/* -打开wiki -*/ -void MainWindow::on_pushButton_wiki_clicked() -{ - if(ui->comboBox_language->currentIndex()==1) - { - QDesktopServices::openUrl(QUrl("https://gitee.com/aaronfeng0711/Waifu2x-Extension-GUI/wikis")); - } - QDesktopServices::openUrl(QUrl("https://github.com/AaronFeng753/Waifu2x-Extension-GUI/wiki")); -} - -void MainWindow::on_pushButton_HideTextBro_clicked() -{ - if(ui->textBrowser->isVisible()) - { - ui->splitter_TextBrowser->setVisible(0); - ui->pushButton_HideTextBro->setText(tr("Show Text Browser")); - } - else - { - ui->splitter_TextBrowser->setVisible(1); - ui->pushButton_HideTextBro->setText(tr("Hide Text Browser")); - } -} - -void MainWindow::on_checkBox_AlwaysHideTextBrowser_stateChanged(int arg1) -{ - if(ui->checkBox_AlwaysHideTextBrowser->isChecked()) - { - ui->splitter_TextBrowser->setVisible(0); - ui->pushButton_HideTextBro->setText(tr("Show Text Browser")); - } -} - - - -void MainWindow::on_Ext_image_textChanged(const QString &arg1) -{ - QString lower = ui->Ext_image->text().toLower(); - ui->Ext_image->setText(lower); -} - -void MainWindow::on_Ext_video_textChanged(const QString &arg1) -{ - QString lower = ui->Ext_video->text().toLower(); - ui->Ext_video->setText(lower); -} - -void MainWindow::on_comboBox_model_vulkan_currentIndexChanged(int index) -{ - if(ui->comboBox_model_vulkan->currentIndex()==0) - { - ui->comboBox_ImageStyle->setEnabled(1); - ui->label_ImageStyle_W2xNCNNVulkan->setVisible(1); - ui->comboBox_ImageStyle->setVisible(1); - if(ui->comboBox_Engine_Image->currentIndex()!=0&&ui->comboBox_Engine_GIF->currentIndex()!=0&&ui->comboBox_Engine_Video->currentIndex()!=0) - { - ui->comboBox_ImageStyle->setEnabled(0); - ui->label_ImageStyle_W2xNCNNVulkan->setVisible(0); - ui->comboBox_ImageStyle->setVisible(0); - } - } - if(ui->comboBox_model_vulkan->currentIndex()==1) - { - ui->comboBox_ImageStyle->setEnabled(0); - ui->label_ImageStyle_W2xNCNNVulkan->setVisible(0); - ui->comboBox_ImageStyle->setVisible(0); - } -} - -void MainWindow::on_comboBox_ImageStyle_currentIndexChanged(int index) -{ - if(ui->comboBox_ImageStyle->currentIndex()==0) - { - ui->comboBox_model_vulkan->setEnabled(1); - } - if(ui->comboBox_ImageStyle->currentIndex()==1) - { - ui->comboBox_model_vulkan->setEnabled(0); - } -} - -void MainWindow::on_pushButton_ResetVideoSettings_clicked() -{ - ui->lineEdit_pixformat->setText("yuv420p"); - ui->lineEdit_encoder_vid->setText("libx264"); - ui->lineEdit_encoder_audio->setText("aac"); - ui->spinBox_bitrate_vid->setValue(6000); - ui->spinBox_bitrate_audio->setValue(320); - //==== - ui->spinBox_bitrate_vid_2mp4->setValue(2500); - ui->spinBox_bitrate_audio_2mp4->setValue(320); - ui->checkBox_acodec_copy_2mp4->setChecked(0); - ui->checkBox_vcodec_copy_2mp4->setChecked(0); - ui->spinBox_bitrate_vid_2mp4->setEnabled(1); - ui->spinBox_bitrate_audio_2mp4->setEnabled(1); - //==== - ui->lineEdit_ExCommand_2mp4->setText(""); - ui->lineEdit_ExCommand_output->setText(""); -} - -void MainWindow::on_lineEdit_encoder_vid_textChanged(const QString &arg1) -{ - QString tmp = ui->lineEdit_encoder_vid->text().trimmed(); - ui->lineEdit_encoder_vid->setText(tmp); -} - -void MainWindow::on_lineEdit_encoder_audio_textChanged(const QString &arg1) -{ - QString tmp = ui->lineEdit_encoder_audio->text().trimmed(); - ui->lineEdit_encoder_audio->setText(tmp); -} - -void MainWindow::on_lineEdit_pixformat_textChanged(const QString &arg1) -{ - QString tmp = ui->lineEdit_pixformat->text().trimmed(); - ui->lineEdit_pixformat->setText(tmp); -} - -void MainWindow::on_checkBox_vcodec_copy_2mp4_stateChanged(int arg1) -{ - if(ui->checkBox_vcodec_copy_2mp4->isChecked()) - { - ui->spinBox_bitrate_vid_2mp4->setEnabled(0); - } - else - { - ui->spinBox_bitrate_vid_2mp4->setEnabled(1); - } -} - -void MainWindow::on_checkBox_acodec_copy_2mp4_stateChanged(int arg1) -{ - if(ui->checkBox_acodec_copy_2mp4->isChecked()) - { - ui->spinBox_bitrate_audio_2mp4->setEnabled(0); - } - else - { - ui->spinBox_bitrate_audio_2mp4->setEnabled(1); - } -} - - -void MainWindow::on_pushButton_encodersList_clicked() -{ - file_OpenFile(Current_Path+"/FFmpeg_Encoders_List_waifu2xEX.bat"); -} - -void MainWindow::Tip_FirstTimeStart() -{ - QString FirstTimeStart = Current_Path+"/FirstTimeStart"; - if(QFile::exists(FirstTimeStart)) - { - isFirstTimeStart=false; - return; - } - else - { - isFirstTimeStart=true; - /* - 弹出语言选择对话框 - */ - QMessageBox Msg(QMessageBox::Question, QString("Choose your language"), QString("Choose your language.\n\n选择您的语言。\n\n言語を選んでください。")); - Msg.setIcon(QMessageBox::Information); - QAbstractButton *pYesBtn_English = Msg.addButton(QString("English"), QMessageBox::YesRole); - QAbstractButton *pYesBtn_Chinese = Msg.addButton(QString("简体中文"), QMessageBox::YesRole); - QAbstractButton *pYesBtn_TraditionalChinese = Msg.addButton(QString("繁體中文(由uimee翻譯)"), QMessageBox::YesRole); - Msg.exec(); - if (Msg.clickedButton() == pYesBtn_English)ui->comboBox_language->setCurrentIndex(0); - if (Msg.clickedButton() == pYesBtn_Chinese)ui->comboBox_language->setCurrentIndex(1); - if (Msg.clickedButton() == pYesBtn_TraditionalChinese)ui->comboBox_language->setCurrentIndex(2); - on_comboBox_language_currentIndexChanged(0); - //====== - QMessageBox *MSG_2 = new QMessageBox(); - MSG_2->setWindowTitle(tr("Notification")); - MSG_2->setText(tr("It is detected that this is the first time you have started the software, so the compatibility test will be performed automatically. Please wait for a while, then check the test result.")); - MSG_2->setIcon(QMessageBox::Information); - MSG_2->setModal(true); - MSG_2->show(); - //======= - file_generateMarkFile(FirstTimeStart,""); - //======= - on_pushButton_clear_textbrowser_clicked(); - on_pushButton_compatibilityTest_clicked(); - } -} - -void MainWindow::on_checkBox_DelOriginal_stateChanged(int arg1) -{ - if(ui->checkBox_DelOriginal->isChecked()) - { - QAction_checkBox_MoveToRecycleBin_checkBox_DelOriginal->setEnabled(1); - ui->checkBox_ReplaceOriginalFile->setEnabled(0); - ui->checkBox_ReplaceOriginalFile->setChecked(0); - } - else - { - QAction_checkBox_MoveToRecycleBin_checkBox_DelOriginal->setEnabled(0); - checkBox_ReplaceOriginalFile_setEnabled_True_Self(); - } -} - -void MainWindow::on_checkBox_FileList_Interactive_stateChanged(int arg1) -{ - if(ui->checkBox_FileList_Interactive->isChecked()) - { - ui->tableView_image->horizontalHeader()->setSectionResizeMode(QHeaderView::Interactive); - ui->tableView_gif->horizontalHeader()->setSectionResizeMode(QHeaderView::Interactive); - ui->tableView_video->horizontalHeader()->setSectionResizeMode(QHeaderView::Interactive); - } - else - { - ui->tableView_image->horizontalHeader()->setSectionResizeMode(QHeaderView::ResizeToContents); - ui->tableView_gif->horizontalHeader()->setSectionResizeMode(QHeaderView::ResizeToContents); - ui->tableView_video->horizontalHeader()->setSectionResizeMode(QHeaderView::ResizeToContents); - } -} - -void MainWindow::on_checkBox_OutPath_isEnabled_stateChanged(int arg1) -{ - if(ui->checkBox_OutPath_isEnabled->isChecked()) - { - ui->lineEdit_outputPath->setEnabled(1); - ui->checkBox_OutPath_KeepOriginalFileName->setEnabled(1); - ui->checkBox_KeepParentFolder->setEnabled(1); - ui->checkBox_OutPath_Overwrite->setEnabled(1); - ui->checkBox_ReplaceOriginalFile->setEnabled(0); - ui->checkBox_ReplaceOriginalFile->setChecked(0); - ui->checkBox_AutoOpenOutputPath->setEnabled(1); - } - else - { - ui->lineEdit_outputPath->setEnabled(0); - ui->checkBox_OutPath_KeepOriginalFileName->setEnabled(0); - ui->checkBox_KeepParentFolder->setEnabled(0); - ui->checkBox_OutPath_Overwrite->setEnabled(0); - ui->checkBox_AutoOpenOutputPath->setEnabled(0); - checkBox_ReplaceOriginalFile_setEnabled_True_Self(); - } -} - -//强制重试 -void MainWindow::on_pushButton_ForceRetry_clicked() -{ - if(isForceRetryEnabled==false)//处理视频和gif时禁用强制重试 - { - emit Send_TextBrowser_NewMessage(tr("Force retry is disabled when processing Video or GIF.")); - return; - } - //========== - ui->pushButton_ForceRetry->setEnabled(0); - //======== - QtConcurrent::run(this, &MainWindow::isForceRetryClicked_SetTrue_Block_Anime4k);//block a4k引擎线程 防止无效图片污染缓存 - //======== - ForceRetryCount++; - //======== - QProcess Close; - Close.start("taskkill /f /t /fi \"imagename eq Anime4K_waifu2xEX.exe\""); - Close.waitForStarted(10000); - Close.waitForFinished(10000); - Close.start("taskkill /f /t /fi \"imagename eq waifu2x-ncnn-vulkan_waifu2xEX.exe\""); - Close.waitForStarted(10000); - Close.waitForFinished(10000); - Close.start("taskkill /f /t /fi \"imagename eq waifu2x-ncnn-vulkan-fp16p_waifu2xEX.exe\""); - Close.waitForStarted(10000); - Close.waitForFinished(10000); - Close.start("taskkill /f /t /fi \"imagename eq waifu2x-converter-cpp_waifu2xEX.exe\""); - Close.waitForStarted(10000); - Close.waitForFinished(10000); - Close.start("taskkill /f /t /fi \"imagename eq srmd-ncnn-vulkan_waifu2xEX.exe\""); - Close.waitForStarted(10000); - Close.waitForFinished(10000); - Close.start("taskkill /f /t /fi \"imagename eq waifu2x-caffe_waifu2xEX.exe\""); - Close.waitForStarted(10000); - Close.waitForFinished(10000); - Close.start("taskkill /f /t /fi \"imagename eq realsr-ncnn-vulkan_waifu2xEX.exe\""); - Close.waitForStarted(10000); - Close.waitForFinished(10000); - //======== - emit Send_TextBrowser_NewMessage(tr("Force retry.")); - return; -} -//激活强制重试按钮 -void MainWindow::SetEnable_pushButton_ForceRetry_self() -{ - ui->pushButton_ForceRetry->setEnabled(1); - return; -} -void MainWindow::on_pushButton_PayPal_clicked() -{ - QDesktopServices::openUrl(QUrl("https://www.paypal.me/aaronfeng753")); -} -void MainWindow::on_checkBox_AudioDenoise_stateChanged(int arg1) -{ - if(ui->checkBox_AudioDenoise->isChecked()) - { - ui->doubleSpinBox_AudioDenoiseLevel->setEnabled(1); - } - else - { - ui->doubleSpinBox_AudioDenoiseLevel->setEnabled(0); - } -} -void MainWindow::on_tabWidget_currentChanged(int index) -{ - switch(ui->tabWidget->currentIndex()) - { - case 0: - { - //tab 0 - ui->label_DonateQRCode->setVisible(1); - ui->pushButton_PayPal->setVisible(1); - ui->pushButton_Patreon->setVisible(1); - ui->label_DonateText->setVisible(1); - //tab 1 - ui->groupBox_Progress->setVisible(0); - ui->splitter_2->setVisible(0); - //tab 2 - ui->groupBox_Engine->setVisible(0); - ui->groupBox_NumOfThreads->setVisible(0); - //tab 3 - ui->groupBox_AudioDenoise->setVisible(0); - ui->groupBox_video_settings->setVisible(0); - ui->groupBox_FrameInterpolation->setVisible(0); - //tab 4 - ui->groupBox_3->setVisible(0); - ui->groupBox_8->setVisible(0); - ui->groupBox_InputExt->setVisible(0); - ui->groupBox_other_1->setVisible(0); - //tab 5 - ui->groupBox_CompatibilityTestRes->setVisible(0); - ui->pushButton_compatibilityTest->setVisible(0); - break; - } - case 1: - { - //tab 0 - ui->label_DonateQRCode->setVisible(0); - ui->pushButton_PayPal->setVisible(0); - ui->pushButton_Patreon->setVisible(0); - ui->label_DonateText->setVisible(0); - //tab 1 - ui->groupBox_Progress->setVisible(1); - ui->splitter_2->setVisible(1); - if(isSettingsHide==false) - { - ui->groupBox_Setting->setVisible(1); - } - //tab 2 - ui->groupBox_Engine->setVisible(0); - ui->groupBox_NumOfThreads->setVisible(0); - //tab 3 - ui->groupBox_AudioDenoise->setVisible(0); - ui->groupBox_video_settings->setVisible(0); - ui->groupBox_FrameInterpolation->setVisible(0); - //tab 4 - ui->groupBox_3->setVisible(0); - ui->groupBox_8->setVisible(0); - ui->groupBox_InputExt->setVisible(0); - ui->groupBox_other_1->setVisible(0); - //tab 5 - ui->groupBox_CompatibilityTestRes->setVisible(0); - ui->pushButton_compatibilityTest->setVisible(0); - break; - } - case 2: - { - //tab 0 - ui->label_DonateQRCode->setVisible(0); - ui->pushButton_PayPal->setVisible(0); - ui->pushButton_Patreon->setVisible(0); - ui->label_DonateText->setVisible(0); - //tab 1 - ui->groupBox_Progress->setVisible(0); - ui->splitter_2->setVisible(0); - //tab 2 - ui->groupBox_Engine->setVisible(1); - ui->groupBox_NumOfThreads->setVisible(1); - //tab 3 - ui->groupBox_AudioDenoise->setVisible(0); - ui->groupBox_video_settings->setVisible(0); - ui->groupBox_FrameInterpolation->setVisible(0); - //tab 4 - ui->groupBox_3->setVisible(0); - ui->groupBox_8->setVisible(0); - ui->groupBox_InputExt->setVisible(0); - ui->groupBox_other_1->setVisible(0); - //tab 5 - ui->groupBox_CompatibilityTestRes->setVisible(0); - ui->pushButton_compatibilityTest->setVisible(0); - break; - } - case 3: - { - //tab 0 - ui->label_DonateQRCode->setVisible(0); - ui->pushButton_PayPal->setVisible(0); - ui->pushButton_Patreon->setVisible(0); - ui->label_DonateText->setVisible(0); - //tab 1 - ui->groupBox_Progress->setVisible(0); - ui->splitter_2->setVisible(0); - //tab 2 - ui->groupBox_Engine->setVisible(0); - ui->groupBox_NumOfThreads->setVisible(0); - //tab 3 - ui->groupBox_AudioDenoise->setVisible(1); - ui->groupBox_video_settings->setVisible(1); - ui->groupBox_FrameInterpolation->setVisible(1); - //tab 4 - ui->groupBox_3->setVisible(0); - ui->groupBox_8->setVisible(0); - ui->groupBox_InputExt->setVisible(0); - ui->groupBox_other_1->setVisible(0); - //tab 5 - ui->groupBox_CompatibilityTestRes->setVisible(0); - ui->pushButton_compatibilityTest->setVisible(0); - break; - } - case 4: - { - //tab 0 - ui->label_DonateQRCode->setVisible(0); - ui->pushButton_PayPal->setVisible(0); - ui->pushButton_Patreon->setVisible(0); - ui->label_DonateText->setVisible(0); - //tab 1 - ui->groupBox_Progress->setVisible(0); - ui->splitter_2->setVisible(0); - //tab 2 - ui->groupBox_Engine->setVisible(0); - ui->groupBox_NumOfThreads->setVisible(0); - //tab 3 - ui->groupBox_AudioDenoise->setVisible(0); - ui->groupBox_video_settings->setVisible(0); - ui->groupBox_FrameInterpolation->setVisible(0); - //tab 4 - ui->groupBox_3->setVisible(1); - ui->groupBox_8->setVisible(1); - ui->groupBox_InputExt->setVisible(1); - ui->groupBox_other_1->setVisible(1); - //tab 5 - ui->groupBox_CompatibilityTestRes->setVisible(0); - ui->pushButton_compatibilityTest->setVisible(0); - break; - } - case 5: - { - //tab 0 - ui->label_DonateQRCode->setVisible(0); - ui->pushButton_PayPal->setVisible(0); - ui->pushButton_Patreon->setVisible(0); - ui->label_DonateText->setVisible(0); - //tab 1 - ui->groupBox_Progress->setVisible(0); - ui->splitter_2->setVisible(0); - //tab 2 - ui->groupBox_Engine->setVisible(0); - ui->groupBox_NumOfThreads->setVisible(0); - //tab 3 - ui->groupBox_AudioDenoise->setVisible(0); - ui->groupBox_video_settings->setVisible(0); - ui->groupBox_FrameInterpolation->setVisible(0); - //tab 4 - ui->groupBox_3->setVisible(0); - ui->groupBox_8->setVisible(0); - ui->groupBox_InputExt->setVisible(0); - ui->groupBox_other_1->setVisible(0); - //tab 5 - ui->groupBox_CompatibilityTestRes->setVisible(1); - ui->pushButton_compatibilityTest->setVisible(1); - break; - } - } -} -void MainWindow::on_checkBox_ProcessVideoBySegment_stateChanged(int arg1) -{ - if(ui->checkBox_ProcessVideoBySegment->isChecked()) - { - ui->label_SegmentDuration->setEnabled(1); - ui->spinBox_SegmentDuration->setEnabled(1); - } - else - { - ui->label_SegmentDuration->setEnabled(0); - ui->spinBox_SegmentDuration->setEnabled(0); - } -} -void MainWindow::on_comboBox_version_Waifu2xNCNNVulkan_currentIndexChanged(int index) -{ - switch (ui->comboBox_version_Waifu2xNCNNVulkan->currentIndex()) - { - case 0: - { - Waifu2x_ncnn_vulkan_FolderPath = Current_Path + "/waifu2x-ncnn-vulkan"; - Waifu2x_ncnn_vulkan_ProgramPath = Waifu2x_ncnn_vulkan_FolderPath + "/waifu2x-ncnn-vulkan_waifu2xEX.exe"; - ui->checkBox_TTA_vulkan->setEnabled(1); - return; - } - case 1: - { - Waifu2x_ncnn_vulkan_FolderPath = Current_Path + "/waifu2x-ncnn-vulkan"; - Waifu2x_ncnn_vulkan_ProgramPath = Waifu2x_ncnn_vulkan_FolderPath + "/waifu2x-ncnn-vulkan-fp16p_waifu2xEX.exe"; - ui->checkBox_TTA_vulkan->setEnabled(1); - return; - } - case 2: - { - Waifu2x_ncnn_vulkan_FolderPath = Current_Path + "/waifu2x-ncnn-vulkan-old"; - Waifu2x_ncnn_vulkan_ProgramPath = Waifu2x_ncnn_vulkan_FolderPath + "/waifu2x-ncnn-vulkan_waifu2xEX.exe"; - ui->checkBox_TTA_vulkan->setEnabled(0); - ui->checkBox_TTA_vulkan->setChecked(0); - return; - } - } -} -void MainWindow::on_checkBox_EnablePreProcessing_Anime4k_stateChanged(int arg1) -{ - if(ui->checkBox_EnablePreProcessing_Anime4k->isChecked()) - { - ui->checkBox_MedianBlur_Pre_Anime4k->setEnabled(1); - ui->checkBox_MeanBlur_Pre_Anime4k->setEnabled(1); - ui->checkBox_CASSharping_Pre_Anime4k->setEnabled(1); - ui->checkBox_GaussianBlurWeak_Pre_Anime4k->setEnabled(1); - ui->checkBox_GaussianBlur_Pre_Anime4k->setEnabled(1); - ui->checkBox_BilateralFilter_Pre_Anime4k->setEnabled(1); - ui->checkBox_BilateralFilterFaster_Pre_Anime4k->setEnabled(1); - } - else - { - ui->checkBox_MedianBlur_Pre_Anime4k->setEnabled(0); - ui->checkBox_MeanBlur_Pre_Anime4k->setEnabled(0); - ui->checkBox_CASSharping_Pre_Anime4k->setEnabled(0); - ui->checkBox_GaussianBlurWeak_Pre_Anime4k->setEnabled(0); - ui->checkBox_GaussianBlur_Pre_Anime4k->setEnabled(0); - ui->checkBox_BilateralFilter_Pre_Anime4k->setEnabled(0); - ui->checkBox_BilateralFilterFaster_Pre_Anime4k->setEnabled(0); - } -} -void MainWindow::on_checkBox_EnablePostProcessing_Anime4k_stateChanged(int arg1) -{ - if(ui->checkBox_EnablePostProcessing_Anime4k->isChecked()) - { - ui->checkBox_MedianBlur_Post_Anime4k->setEnabled(1); - ui->checkBox_MeanBlur_Post_Anime4k->setEnabled(1); - ui->checkBox_CASSharping_Post_Anime4k->setEnabled(1); - ui->checkBox_GaussianBlurWeak_Post_Anime4k->setEnabled(1); - ui->checkBox_GaussianBlur_Post_Anime4k->setEnabled(1); - ui->checkBox_BilateralFilter_Post_Anime4k->setEnabled(1); - ui->checkBox_BilateralFilterFaster_Post_Anime4k->setEnabled(1); - } - else - { - ui->checkBox_MedianBlur_Post_Anime4k->setEnabled(0); - ui->checkBox_MeanBlur_Post_Anime4k->setEnabled(0); - ui->checkBox_CASSharping_Post_Anime4k->setEnabled(0); - ui->checkBox_GaussianBlurWeak_Post_Anime4k->setEnabled(0); - ui->checkBox_GaussianBlur_Post_Anime4k->setEnabled(0); - ui->checkBox_BilateralFilter_Post_Anime4k->setEnabled(0); - ui->checkBox_BilateralFilterFaster_Post_Anime4k->setEnabled(0); - } -} -void MainWindow::on_checkBox_SpecifyGPU_Anime4k_stateChanged(int arg1) -{ - if(ui->checkBox_SpecifyGPU_Anime4k->isChecked()) - { - ui->lineEdit_GPUs_Anime4k->setEnabled(1); - ui->pushButton_ListGPUs_Anime4k->setEnabled(1); - ui->pushButton_VerifyGPUsConfig_Anime4k->setEnabled(1); - } - else - { - ui->lineEdit_GPUs_Anime4k->setEnabled(0); - ui->pushButton_ListGPUs_Anime4k->setEnabled(0); - ui->pushButton_VerifyGPUsConfig_Anime4k->setEnabled(0); - } -} -void MainWindow::on_checkBox_isCompatible_Waifu2x_NCNN_Vulkan_NEW_clicked() -{ - ui->checkBox_isCompatible_Waifu2x_NCNN_Vulkan_NEW->setChecked(isCompatible_Waifu2x_NCNN_Vulkan_NEW); -} -void MainWindow::on_checkBox_isCompatible_Waifu2x_NCNN_Vulkan_NEW_FP16P_clicked() -{ - ui->checkBox_isCompatible_Waifu2x_NCNN_Vulkan_NEW_FP16P->setChecked(isCompatible_Waifu2x_NCNN_Vulkan_NEW_FP16P); -} -void MainWindow::on_checkBox_isCompatible_Waifu2x_NCNN_Vulkan_OLD_clicked() -{ - ui->checkBox_isCompatible_Waifu2x_NCNN_Vulkan_OLD->setChecked(isCompatible_Waifu2x_NCNN_Vulkan_OLD); -} -void MainWindow::on_checkBox_isCompatible_SRMD_NCNN_Vulkan_clicked() -{ - ui->checkBox_isCompatible_SRMD_NCNN_Vulkan->setChecked(isCompatible_SRMD_NCNN_Vulkan); -} -void MainWindow::on_checkBox_isCompatible_SRMD_CUDA_clicked() -{ - ui->checkBox_isCompatible_SRMD_CUDA->setChecked(isCompatible_SRMD_CUDA); -} -void MainWindow::on_checkBox_isCompatible_Waifu2x_Converter_clicked() -{ - ui->checkBox_isCompatible_Waifu2x_Converter->setChecked(isCompatible_Waifu2x_Converter); -} -void MainWindow::on_checkBox_isCompatible_Anime4k_CPU_clicked() -{ - ui->checkBox_isCompatible_Anime4k_CPU->setChecked(isCompatible_Anime4k_CPU); -} -void MainWindow::on_checkBox_isCompatible_Anime4k_GPU_clicked() -{ - ui->checkBox_isCompatible_Anime4k_GPU->setChecked(isCompatible_Anime4k_GPU); -} -void MainWindow::on_checkBox_isCompatible_FFmpeg_clicked() -{ - ui->checkBox_isCompatible_FFmpeg->setChecked(isCompatible_FFmpeg); -} -void MainWindow::on_checkBox_isCompatible_FFprobe_clicked() -{ - ui->checkBox_isCompatible_FFprobe->setChecked(isCompatible_FFprobe); -} -void MainWindow::on_checkBox_isCompatible_ImageMagick_clicked() -{ - ui->checkBox_isCompatible_ImageMagick->setChecked(isCompatible_ImageMagick); -} -void MainWindow::on_checkBox_isCompatible_Gifsicle_clicked() -{ - ui->checkBox_isCompatible_Gifsicle->setChecked(isCompatible_Gifsicle); -} -void MainWindow::on_checkBox_isCompatible_SoX_clicked() -{ - ui->checkBox_isCompatible_SoX->setChecked(isCompatible_SoX); -} -void MainWindow::on_checkBox_GPUMode_Anime4K_stateChanged(int arg1) -{ - if(ui->checkBox_GPUMode_Anime4K->isChecked()) - { - ui->checkBox_SpecifyGPU_Anime4k->setEnabled(1); - ui->comboBox_GPGPUModel_A4k->setEnabled(1); - on_comboBox_GPGPUModel_A4k_currentIndexChanged(1); - } - else - { - ui->checkBox_SpecifyGPU_Anime4k->setEnabled(0); - ui->checkBox_SpecifyGPU_Anime4k->setChecked(0); - ui->comboBox_GPGPUModel_A4k->setEnabled(0); - on_comboBox_GPGPUModel_A4k_currentIndexChanged(1); - } -} -void MainWindow::on_checkBox_ShowInterPro_stateChanged(int arg1) -{ - if(ui->checkBox_ShowInterPro->isChecked()==false) - { - emit Send_CurrentFileProgress_Stop(); - } -} -void MainWindow::on_checkBox_isCompatible_Waifu2x_Caffe_CPU_clicked() -{ - ui->checkBox_isCompatible_Waifu2x_Caffe_CPU->setChecked(isCompatible_Waifu2x_Caffe_CPU); -} -void MainWindow::on_checkBox_isCompatible_Waifu2x_Caffe_GPU_clicked() -{ - ui->checkBox_isCompatible_Waifu2x_Caffe_GPU->setChecked(isCompatible_Waifu2x_Caffe_GPU); -} -void MainWindow::on_checkBox_isCompatible_Waifu2x_Caffe_cuDNN_clicked() -{ - ui->checkBox_isCompatible_Waifu2x_Caffe_cuDNN->setChecked(isCompatible_Waifu2x_Caffe_cuDNN); -} -void MainWindow::on_pushButton_SplitSize_Add_Waifu2xCaffe_clicked() -{ - int VAL = ui->spinBox_SplitSize_Waifu2xCaffe->value()*2; - if(VAL<=999999999) - { - ui->spinBox_SplitSize_Waifu2xCaffe->setValue(VAL); - } -} -void MainWindow::on_pushButton_SplitSize_Minus_Waifu2xCaffe_clicked() -{ - int VAL = ui->spinBox_SplitSize_Waifu2xCaffe->value()/2; - if(VAL>=2) - { - ui->spinBox_SplitSize_Waifu2xCaffe->setValue(VAL); - } -} -void MainWindow::on_checkBox_isCompatible_Realsr_NCNN_Vulkan_clicked() -{ - ui->checkBox_isCompatible_Realsr_NCNN_Vulkan->setChecked(isCompatible_Realsr_NCNN_Vulkan); -} -void MainWindow::on_checkBox_ACNet_Anime4K_stateChanged(int arg1) -{ - if(ui->checkBox_ACNet_Anime4K->isChecked()) - { - ui->checkBox_HDNMode_Anime4k->setEnabled(1); - ui->groupBox_PostProcessing_Anime4k->setEnabled(0); - ui->groupBox_PreProcessing_Anime4k->setEnabled(0); - ui->doubleSpinBox_PushColorStrength_Anime4K->setEnabled(0); - ui->doubleSpinBox_PushGradientStrength_Anime4K->setEnabled(0); - ui->spinBox_Passes_Anime4K->setEnabled(0); - ui->spinBox_PushColorCount_Anime4K->setEnabled(0); - } - else - { - ui->checkBox_HDNMode_Anime4k->setEnabled(0); - on_checkBox_GPUMode_Anime4K_stateChanged(0); - on_checkBox_SpecifyGPU_Anime4k_stateChanged(0); - ui->groupBox_PostProcessing_Anime4k->setEnabled(1); - ui->groupBox_PreProcessing_Anime4k->setEnabled(1); - ui->doubleSpinBox_PushColorStrength_Anime4K->setEnabled(1); - ui->doubleSpinBox_PushGradientStrength_Anime4K->setEnabled(1); - ui->spinBox_Passes_Anime4K->setEnabled(1); - ui->spinBox_PushColorCount_Anime4K->setEnabled(1); - } - DenoiseLevelSpinboxSetting_Anime4k(); -} -void MainWindow::on_checkBox_HDNMode_Anime4k_stateChanged(int arg1) -{ - DenoiseLevelSpinboxSetting_Anime4k(); -} -/* -生成独立cmd文件来执行cmd命令 -*/ -void MainWindow::ExecuteCMD_batFile(QString cmd_str,bool requestAdmin) -{ - ExecuteCMD_batFile_QMutex.lock(); - QString cmd_commands = "@echo off\n "+cmd_str+"\n exit"; - Delay_msec_sleep(10);//延时防止文件名称碰撞 - file_mkDir(Current_Path+"/batFiles_tmp"); - QString Bat_path = Current_Path+"/batFiles_tmp/W2xEX_"+QDateTime::currentDateTime().toString("dhhmmsszzz")+".bat"; - //======== - QFile OpenFile_cmdFile(Bat_path); - OpenFile_cmdFile.remove(); - if (OpenFile_cmdFile.open(QIODevice::ReadWrite | QIODevice::Text)) //QIODevice::ReadWrite支持读写 - { - QTextStream stream(&OpenFile_cmdFile); - stream << cmd_commands; - } - OpenFile_cmdFile.close(); - if(requestAdmin) - { - ShellExecuteW(NULL, QString("runas").toStdWString().c_str(), QString(Bat_path).toStdWString().c_str(), QString(Bat_path).toStdWString().c_str(), NULL, 1); - } - else - { - QDesktopServices::openUrl(QUrl("file:"+QUrl::toPercentEncoding(Bat_path))); - } - //======== - ExecuteCMD_batFile_QMutex.unlock(); -} -void MainWindow::Del_TempBatFile() -{ - file_DelDir(Current_Path+"/batFiles_tmp"); -} -void MainWindow::comboBox_UpdateChannel_setCurrentIndex_self(int index) -{ - comboBox_UpdateChannel_setCurrentIndex_self_QMutex.lock(); - isClicked_comboBox_UpdateChannel=false; - ui->comboBox_UpdateChannel->setCurrentIndex(index); - isClicked_comboBox_UpdateChannel=true; - comboBox_UpdateChannel_setCurrentIndex_self_QMutex.unlock(); -} -void MainWindow::on_comboBox_UpdateChannel_currentIndexChanged(int index) -{ - if(isClicked_comboBox_UpdateChannel && AutoUpdate.isRunning()==false) - { - AutoUpdate = QtConcurrent::run(this, &MainWindow::CheckUpadte_Auto);//自动检查更新线程 - } -} -void MainWindow::on_checkBox_ReplaceOriginalFile_stateChanged(int arg1) -{ - if(ui->checkBox_ReplaceOriginalFile->isChecked()) - { - ui->groupBox_OutPut->setEnabled(0); - ui->checkBox_OutPath_isEnabled->setChecked(0); - ui->checkBox_DelOriginal->setEnabled(0); - } - else - { - ui->groupBox_OutPut->setEnabled(1); - ui->checkBox_DelOriginal->setEnabled(1); - } -} -void MainWindow::checkBox_ReplaceOriginalFile_setEnabled_True_Self() -{ - if(ui->checkBox_DelOriginal->isChecked()==false && ui->checkBox_OutPath_isEnabled->isChecked()==false) - { - ui->checkBox_ReplaceOriginalFile->setEnabled(1); - } -} -bool MainWindow::ReplaceOriginalFile(QString original_fullpath,QString output_fullpath) -{ - //检查是否启用替换源文件,以及输出文件是否存在 - if(ui->checkBox_ReplaceOriginalFile->isChecked()==false || QFile::exists(output_fullpath)==false)return false; - //================= - QFileInfo fileinfo_original_fullpath(original_fullpath); - QFileInfo fileinfo_output_fullpath(output_fullpath); - QString file_name = file_getBaseName(original_fullpath);//获取源文件的文件名 - QString file_ext = fileinfo_output_fullpath.suffix();//获取输出文件的后辍 - QString file_path = file_getFolderPath(fileinfo_original_fullpath);//获取源文件的文件路径 - //================= - QString Target_fullpath=file_path+"/"+file_name+"."+file_ext; - //================= - if(QAction_checkBox_MoveToRecycleBin_checkBox_ReplaceOriginalFile->isChecked()) - { - file_MoveToTrash(original_fullpath); - file_MoveToTrash(Target_fullpath); - } - else - { - QFile::remove(original_fullpath); - QFile::remove(Target_fullpath); - } - //================= - if(QFile::rename(output_fullpath,Target_fullpath)==false) - { - emit Send_TextBrowser_NewMessage(tr("Error! Failed to move [")+output_fullpath+tr("] to [")+Target_fullpath+"]"); - } - return true; -} -void MainWindow::on_checkBox_isCustFontEnable_stateChanged(int arg1) -{ - if(ui->checkBox_isCustFontEnable->isChecked()) - { - ui->pushButton_Save_GlobalFontSize->setEnabled(1); - ui->spinBox_GlobalFontSize->setEnabled(1); - ui->fontComboBox_CustFont->setEnabled(1); - } - else - { - ui->pushButton_Save_GlobalFontSize->setEnabled(0); - ui->spinBox_GlobalFontSize->setEnabled(0); - ui->fontComboBox_CustFont->setEnabled(0); - } -} -void MainWindow::OutputSettingsArea_setEnabled(bool isEnabled) -{ - ui->scrollArea_outputPathSettings->setEnabled(isEnabled); - ui->lineEdit_outputPath->setClearButtonEnabled(isEnabled); - if(isEnabled==true) - { - ui->lineEdit_outputPath->setFocusPolicy(Qt::StrongFocus); - } - else - { - ui->lineEdit_outputPath->setFocusPolicy(Qt::NoFocus); - } -} -//事件过滤器 -bool MainWindow::eventFilter(QObject *target, QEvent *event) -{ - //============================= - //按下 Delete 移除文件列表里的文件 - //============================= - if (target == ui->tableView_image || target == ui->tableView_gif || target == ui->tableView_video) - { - if (event->type() == QEvent::KeyPress) - { - QKeyEvent *keyEvent = static_cast(event); - if (keyEvent->key() == Qt::Key_Delete) - { - if(RemoveFile_FilesList_QAction_FileList->isEnabled()) - { - on_pushButton_RemoveItem_clicked(); - } - return true; - } - if ((keyEvent->modifiers() == Qt::ControlModifier) && (keyEvent->key() == Qt::Key_A)) - { - if(Apply_CustRes_QAction_FileList->isEnabled()) - { - EnableApply2All_CustRes=false; - on_pushButton_CustRes_apply_clicked(); - EnableApply2All_CustRes=true; - } - return true; - } - if ((keyEvent->modifiers() == Qt::ControlModifier) && (keyEvent->key() == Qt::Key_C)) - { - if(Cancel_CustRes_QAction_FileList->isEnabled()) - { - EnableApply2All_CustRes=false; - on_pushButton_CustRes_cancel_clicked(); - EnableApply2All_CustRes=true; - } - return true; - } - } - } - //============== - return false; -} -void MainWindow::on_pushButton_ResizeFilesListSplitter_clicked() -{ - ui->splitter_FilesList->setSizes(QList() << 1 << 1 << 1); -} -void MainWindow::on_comboBox_GPGPUModel_A4k_currentIndexChanged(int index) -{ - if(ui->comboBox_GPGPUModel_A4k->currentText().toLower().trimmed()=="opencl" && ui->checkBox_GPUMode_Anime4K->isChecked()) - { - ui->spinBox_OpenCLCommandQueues_A4k->setEnabled(1); - ui->checkBox_OpenCLParallelIO_A4k->setEnabled(1); - } - else - { - ui->spinBox_OpenCLCommandQueues_A4k->setEnabled(0); - ui->checkBox_OpenCLParallelIO_A4k->setEnabled(0); - } -} -void MainWindow::on_checkBox_DisableGPU_converter_stateChanged(int arg1) -{ - if(ui->checkBox_DisableGPU_converter->isChecked()) - { - ui->checkBox_MultiGPU_Waifu2xConverter->setChecked(0); - ui->comboBox_TargetProcessor_converter->setEnabled(0); - ui->comboBox_TargetProcessor_converter->setCurrentIndex(0); - ui->checkBox_MultiGPU_Waifu2xConverter->setEnabled(0); - } - else - { - ui->comboBox_TargetProcessor_converter->setEnabled(1); - ui->checkBox_MultiGPU_Waifu2xConverter->setEnabled(1); - } -} -void MainWindow::on_groupBox_video_settings_clicked() -{ - if(ui->groupBox_video_settings->isChecked()) - { - //====== - if(isCustomVideoSettingsClicked==true) - { - QMessageBox *MSG = new QMessageBox(); - MSG->setWindowTitle(tr("Warning")); - MSG->setText(tr("Change Custom video settings might cause ERROR.\n\nMake sure you know what you are doing before change any settings.")); - MSG->setIcon(QMessageBox::Warning); - MSG->setModal(true); - MSG->show(); - } - //====== - ui->groupBox_OutputVideoSettings->setEnabled(1); - ui->groupBox_ToMp4VideoSettings->setEnabled(1); - ui->pushButton_encodersList->setEnabled(1); - ui->pushButton_ResetVideoSettings->setEnabled(1); - } - else - { - ui->groupBox_OutputVideoSettings->setEnabled(0); - ui->groupBox_ToMp4VideoSettings->setEnabled(0); - ui->pushButton_encodersList->setEnabled(0); - ui->pushButton_ResetVideoSettings->setEnabled(0); - } -} -void MainWindow::Set_checkBox_DisableResize_gif_Checked() -{ - emit Send_TextBrowser_NewMessage(tr("[Disable \"-resize\"] is automatically enabled to fix compatibility issue and improve performance.")); - ui->checkBox_DisableResize_gif->setChecked(true); -} - -void MainWindow::on_pushButton_TurnOffScreen_clicked() -{ - if(TurnOffScreen_QF.isRunning() == true)return; - TurnOffScreen_QF = QtConcurrent::run(this, &MainWindow::TurnOffScreen);//关闭显示器 -} -/* -调用nircmd关闭显示器 -*/ -void MainWindow::TurnOffScreen() -{ - QProcess *OffScreen = new QProcess(); - OffScreen->start("\""+Current_Path+"/nircmd-x64/nircmd.exe\" monitor off"); - OffScreen->waitForStarted(5000); - OffScreen->waitForFinished(5000); - OffScreen->kill(); - return; -} -/* -禁用&启用 开始按钮 -*/ -void MainWindow::pushButton_Start_setEnabled_self(bool isEnabled) -{ - ui->pushButton_Start->setEnabled(isEnabled); - Start_SystemTrayIcon->setEnabled(isEnabled); - ui->pushButton_Start->setVisible(isEnabled); -} -/* -禁用&启用 暂停按钮 -*/ -void MainWindow::pushButton_Stop_setEnabled_self(bool isEnabled) -{ - ui->pushButton_Stop->setEnabled(isEnabled); - Pause_SystemTrayIcon->setEnabled(isEnabled); - ui->pushButton_Stop->setVisible(isEnabled); -} - - -void MainWindow::on_pushButton_MultipleOfFPS_VFI_MIN_clicked() -{ - int VAL = 2; - if(ui->comboBox_Engine_VFI->currentIndex()==2) - { - VAL = ui->spinBox_MultipleOfFPS_VFI->value()-1; - } - else - { - VAL = ui->spinBox_MultipleOfFPS_VFI->value()/2; - } - if(VAL>=2) - { - ui->spinBox_MultipleOfFPS_VFI->setValue(VAL); - } -} - -void MainWindow::on_pushButton_MultipleOfFPS_VFI_ADD_clicked() -{ - int VAL = 2; - if(ui->comboBox_Engine_VFI->currentIndex()==2) - { - VAL = ui->spinBox_MultipleOfFPS_VFI->value()+1; - } - else - { - VAL = ui->spinBox_MultipleOfFPS_VFI->value()*2; - } - if(VAL<=999999999) - { - ui->spinBox_MultipleOfFPS_VFI->setValue(VAL); - } -} +/* + Copyright (C) 2021 Aaron Feng + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU Affero General Public License as published + by the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program. If not, see . + + My Github homepage: https://github.com/AaronFeng753 +*/ + +#include "mainwindow.h" +#include "ui_mainwindow.h" + +MainWindow::MainWindow(QWidget *parent) + : QMainWindow(parent) + , ui(new Ui::MainWindow) +{ + ui->setupUi(this); + qRegisterMetaTypeStreamOperators("QList_QMap_QStrQStr"); + QThreadPool::globalInstance()->setMaxThreadCount(60);//解除全局线程池的最大线程数量限制 + //============== + this->setWindowTitle("Waifu2x-Extension-GUI "+VERSION+" by Aaron Feng"); + //============== + translator = new QTranslator(this); + //============== + ui->tabWidget->setCurrentIndex(1);//显示home tab + ui->tabWidget->tabBar()->setTabTextColor(0,Qt::red); + on_tabWidget_currentChanged(1); + ui->tabWidget_Engines->setCurrentIndex(0); + this->setAcceptDrops(true);//mainwindow接收drop + Init_Table();//初始化table + ui->groupBox_CurrentFile->setVisible(0);//隐藏当前文件进度 + pushButton_Stop_setEnabled_self(0);//禁用隐藏暂停按钮 + ui->pushButton_ForceRetry->setVisible(0); + ui->progressBar_CompatibilityTest->setVisible(0); + //=================== 初始隐藏所有table和禁用按钮 ====================== + ui->tableView_image->setVisible(0); + ui->tableView_gif->setVisible(0); + ui->tableView_video->setVisible(0); + Table_FileCount_reload();//重载文件列表下的文件数量统计 + //============== + Init_ActionsMenu_checkBox_ReplaceOriginalFile();//第一次初始化[替换原文件]的右键菜单(需要在载入设定前设置为checkable + Init_ActionsMenu_checkBox_DelOriginal(); + //=========安装事件过滤器========== + ui->tableView_image->installEventFilter(this); + ui->tableView_gif->installEventFilter(this); + ui->tableView_video->installEventFilter(this); + //=========================================== + connect(this, SIGNAL(Send_Set_checkBox_DisableResize_gif_Checked()), this, SLOT(Set_checkBox_DisableResize_gif_Checked())); + connect(this, SIGNAL(Send_Table_EnableSorting(bool)), this, SLOT(Table_EnableSorting(bool))); + connect(this, SIGNAL(Send_Add_progressBar_CompatibilityTest()), this, SLOT(Add_progressBar_CompatibilityTest())); + connect(this, SIGNAL(Send_Unable2Connect_RawGithubusercontentCom()), this, SLOT(Unable2Connect_RawGithubusercontentCom())); + connect(this, SIGNAL(Send_SetEnable_pushButton_ForceRetry_self()), this, SLOT(SetEnable_pushButton_ForceRetry_self())); + connect(this, SIGNAL(Send_SystemTray_NewMessage(QString)), this, SLOT(SystemTray_NewMessage(QString))); + connect(this, SIGNAL(Send_PrograssBar_Range_min_max(int, int)), this, SLOT(progressbar_setRange_min_max(int, int))); + connect(this, SIGNAL(Send_progressbar_Add()), this, SLOT(progressbar_Add())); + connect(this, SIGNAL(Send_Table_image_ChangeStatus_rowNumInt_statusQString(int, QString)), this, SLOT(Table_image_ChangeStatus_rowNumInt_statusQString(int, QString))); + connect(this, SIGNAL(Send_Table_gif_ChangeStatus_rowNumInt_statusQString(int, QString)), this, SLOT(Table_gif_ChangeStatus_rowNumInt_statusQString(int, QString))); + connect(this, SIGNAL(Send_Table_video_ChangeStatus_rowNumInt_statusQString(int, QString)), this, SLOT(Table_video_ChangeStatus_rowNumInt_statusQString(int, QString))); + connect(this, SIGNAL(Send_Table_FileCount_reload()), this, SLOT(Table_FileCount_reload())); + connect(this, SIGNAL(Send_Table_image_insert_fileName_fullPath(QString,QString)), this, SLOT(Table_image_insert_fileName_fullPath(QString,QString))); + connect(this, SIGNAL(Send_Table_gif_insert_fileName_fullPath(QString,QString)), this, SLOT(Table_gif_insert_fileName_fullPath(QString,QString))); + connect(this, SIGNAL(Send_Table_video_insert_fileName_fullPath(QString,QString)), this, SLOT(Table_video_insert_fileName_fullPath(QString,QString))); + connect(this, SIGNAL(Send_Table_image_CustRes_rowNumInt_HeightQString_WidthQString(int,QString,QString)), this, SLOT(Table_image_CustRes_rowNumInt_HeightQString_WidthQString(int,QString,QString))); + connect(this, SIGNAL(Send_Table_gif_CustRes_rowNumInt_HeightQString_WidthQString(int,QString,QString)), this, SLOT(Table_gif_CustRes_rowNumInt_HeightQString_WidthQString(int,QString,QString))); + connect(this, SIGNAL(Send_Table_video_CustRes_rowNumInt_HeightQString_WidthQString(int,QString,QString)), this, SLOT(Table_video_CustRes_rowNumInt_HeightQString_WidthQString(int,QString,QString))); + connect(this, SIGNAL(Send_Table_Read_Saved_Table_Filelist_Finished(QString)), this, SLOT(Table_Read_Saved_Table_Filelist_Finished(QString))); + connect(this, SIGNAL(Send_Table_Save_Current_Table_Filelist_Finished()), this, SLOT(Table_Save_Current_Table_Filelist_Finished())); + connect(this, SIGNAL(Send_Waifu2x_Finished()), this, SLOT(Waifu2x_Finished())); + connect(this, SIGNAL(Send_Waifu2x_Finished_manual()), this, SLOT(Waifu2x_Finished_manual())); + connect(this, SIGNAL(Send_TextBrowser_NewMessage(QString)), this, SLOT(TextBrowser_NewMessage(QString))); + connect(this, SIGNAL(Send_Waifu2x_Compatibility_Test_finished()), this, SLOT(Waifu2x_Compatibility_Test_finished())); + connect(this, SIGNAL(Send_Waifu2x_DetectGPU_finished()), this, SLOT(Waifu2x_DetectGPU_finished())); + connect(this, SIGNAL(Send_Realsr_ncnn_vulkan_DetectGPU_finished()), this, SLOT(Realsr_ncnn_vulkan_DetectGPU_finished())); + connect(this, SIGNAL(Send_CheckUpadte_NewUpdate(QString,QString)), this, SLOT(CheckUpadte_NewUpdate(QString,QString))); + connect(this, SIGNAL(Send_SystemShutDown()), this, SLOT(SystemShutDown())); + connect(this, SIGNAL(Send_Waifu2x_DumpProcessorList_converter_finished()), this, SLOT(Waifu2x_DumpProcessorList_converter_finished())); + connect(this, SIGNAL(Send_Read_urls_finfished()), this, SLOT(Read_urls_finfished())); + connect(this, SIGNAL(Send_FinishedProcessing_DN()), this, SLOT(FinishedProcessing_DN())); + connect(this, SIGNAL(Send_SRMD_DetectGPU_finished()), this, SLOT(SRMD_DetectGPU_finished())); + connect(this, SIGNAL(Send_FrameInterpolation_DetectGPU_finished()), this, SLOT(FrameInterpolation_DetectGPU_finished())); + connect(this, SIGNAL(Send_video_write_VideoConfiguration(QString,int,int,bool,int,int,QString,bool,QString,QString,bool,int)), this, SLOT(video_write_VideoConfiguration(QString,int,int,bool,int,int,QString,bool,QString,QString,bool,int))); + connect(this, SIGNAL(Send_Settings_Save()), this, SLOT(Settings_Save())); + connect(this, SIGNAL(Send_video_write_Progress_ProcessBySegment(QString,int,bool,bool,int,int)), this, SLOT(video_write_Progress_ProcessBySegment(QString,int,bool,bool,int,int))); + connect(this, SIGNAL(Send_Donate_ReplaceQRCode(QString)), this, SLOT(Donate_ReplaceQRCode(QString))); + connect(this, SIGNAL(Send_CurrentFileProgress_Start(QString,int)), this, SLOT(CurrentFileProgress_Start(QString,int))); + connect(this, SIGNAL(Send_CurrentFileProgress_Stop()), this, SLOT(CurrentFileProgress_Stop())); + connect(this, SIGNAL(Send_CurrentFileProgress_progressbar_Add()), this, SLOT(CurrentFileProgress_progressbar_Add())); + connect(this, SIGNAL(Send_CurrentFileProgress_progressbar_Add_SegmentDuration(int)), this, SLOT(CurrentFileProgress_progressbar_Add_SegmentDuration(int))); + connect(this, SIGNAL(Send_CurrentFileProgress_progressbar_SetFinishedValue(int)), this, SLOT(CurrentFileProgress_progressbar_SetFinishedValue(int))); + //====== + TimeCostTimer = new QTimer(); + connect(TimeCostTimer, SIGNAL(timeout()), this, SLOT(TimeSlot())); + //================================================== + Settings_Read_Apply();//读取与应用设置 + //===================================== + Set_Font_fixed();//固定字体 + //===================================== + QtConcurrent::run(this, &MainWindow::DeleteErrorLog_Waifu2xCaffe);//删除Waifu2xCaffe生成的错误日志 + QtConcurrent::run(this, &MainWindow::Del_TempBatFile);//删除bat文件缓存 + AutoUpdate = QtConcurrent::run(this, &MainWindow::CheckUpadte_Auto);//自动检查更新线程 + DownloadOnlineQRCode = QtConcurrent::run(this, &MainWindow::Donate_DownloadOnlineQRCode);//在线更新捐赠二维码 + SystemShutDown_isAutoShutDown();//上次是否自动关机 + //==================================== + TextBrowser_StartMes();//显示启动msg + //=================================== + Tip_FirstTimeStart();//首次启动 + file_mkDir(Current_Path+"/FilesList_W2xEX");//生成保存文件列表的文件夹 + //============== + /* + 校验软件是否对所在目录有写权限 + */ + if(file_isDirWritable(Current_Path)==false) + { + QMessageBox Msg(QMessageBox::Question, QString(tr("Error")), QString(tr("It is detected that this software lacks the necessary permissions to run." + "\n\nPlease close this software and start this software again after giving this software administrator permission. " + "Or reinstall the software into a directory that can run normally without administrator rights.\n\nOtherwise, this software may not work properly."))); + Msg.setIcon(QMessageBox::Warning); + Msg.addButton(QString("OK"), QMessageBox::NoRole); + Msg.exec(); + } + //============== + Init_SystemTrayIcon();//初始化托盘图标 + Init_ActionsMenu_lineEdit_outputPath();//初始化 输出路径 lineEDIT的右键菜单 + Init_ActionsMenu_FilesList(); + Init_ActionsMenu_pushButton_RemoveItem(); + Init_ActionsMenu_checkBox_ReplaceOriginalFile();//第二次初始化[替换原文件]的右键菜单(载入语言设置 + Init_ActionsMenu_checkBox_DelOriginal(); + //============== + this->showNormal(); + this->activateWindow(); + this->setWindowState((this->windowState() & ~Qt::WindowMinimized) | Qt::WindowActive); + this->adjustSize(); +} + +MainWindow::~MainWindow() +{ + delete ui; +} + +void MainWindow::closeEvent(QCloseEvent *event) +{ + if(isAlreadyClosed)//解决QT退出时重复调用closeEvent的问题 + { + event->accept(); + return; + } + //=============== 询问是否退出 ======================= + if(ui->checkBox_PromptWhenExit->isChecked()) + { + QMessageBox Msg(QMessageBox::Question, QString(tr("Notification")), QString(tr("Do you really wanna exit Waifu2x-Extension-GUI ?"))); + Msg.setIcon(QMessageBox::Question); + QAbstractButton *pYesBtn = Msg.addButton(QString(tr("YES")), QMessageBox::YesRole); + QAbstractButton *pNoBtn = Msg.addButton(QString(tr("NO")), QMessageBox::NoRole); + Msg.exec(); + if (Msg.clickedButton() == pNoBtn) + { + event->ignore(); + return; + } + if (Msg.clickedButton() == pYesBtn)isAlreadyClosed=true; + } + //============================= + systemTray->hide(); + this->hide(); + QApplication::setQuitOnLastWindowClosed(true);//無窗口時不再保持運行 + QApplication::closeAllWindows(); + //==== + if(Waifu2xMain.isRunning() == true) + { + TimeCostTimer->stop(); + pushButton_Stop_setEnabled_self(0);//隐藏stop button + waifu2x_STOP = true; + emit TextBrowser_NewMessage(tr("Trying to stop, please wait...")); + //====== + QMessageBox *MSG_2 = new QMessageBox(); + MSG_2->setWindowTitle(tr("Notification")+" @Waifu2x-Extension-GUI"); + MSG_2->setText(tr("Waiting for the files processing thread to pause")); + MSG_2->setIcon(QMessageBox::Information); + MSG_2->setModal(true); + MSG_2->setStandardButtons(NULL); + MSG_2->setWindowFlags(Qt::CustomizeWindowHint | Qt::WindowTitleHint); + MSG_2->show(); + } + else + { + QMessageBox *MSG_2 = new QMessageBox(); + MSG_2->setWindowTitle(tr("Notification")+" @Waifu2x-Extension-GUI"); + MSG_2->setText(tr("Closing...\n\nPlease wait")); + MSG_2->setIcon(QMessageBox::Information); + MSG_2->setModal(true); + MSG_2->setStandardButtons(NULL); + MSG_2->setWindowFlags(Qt::CustomizeWindowHint | Qt::WindowTitleHint); + MSG_2->show(); + } + AutoUpdate.cancel(); + DownloadOnlineQRCode.cancel(); + //===== + bool AutoSaveSettings = ui->checkBox_AutoSaveSettings->isChecked(); + if(AutoSaveSettings&&(!Settings_isReseted)) + { + Settings_Save(); + QtConcurrent::run(this, &MainWindow::Auto_Save_Settings_Watchdog,true); + } + else + { + QtConcurrent::run(this, &MainWindow::Auto_Save_Settings_Watchdog,false); + } +} + +int MainWindow::Auto_Save_Settings_Watchdog(bool isWaitForSave) +{ + Waifu2xMain.waitForFinished(); + //====== + if(isWaitForSave == true) + { + Delay_msec_sleep(1000); + QString settings_ini = Current_Path+"/settings.ini"; + while(!QFile::exists(settings_ini)) + { + Delay_msec_sleep(250); + } + Delay_msec_sleep(3000); + } + //===== + Force_close(); + //==== + return 0; +} + +int MainWindow::Force_close() +{ + //============= + QStringList TaskNameList; + TaskNameList << "convert_waifu2xEX.exe"<<"ffmpeg_waifu2xEX.exe"<<"ffprobe_waifu2xEX.exe"<<"identify_waifu2xEX.exe"<<"gifsicle_waifu2xEX.exe"<<"waifu2x-ncnn-vulkan_waifu2xEX.exe" + <<"waifu2x-ncnn-vulkan-fp16p_waifu2xEX.exe"<<"Anime4K_waifu2xEX.exe"<<"waifu2x-caffe_waifu2xEX.exe"<<"srmd-ncnn-vulkan_waifu2xEX.exe"<<"realsr-ncnn-vulkan_waifu2xEX.exe" + <<"waifu2x-converter-cpp_waifu2xEX.exe"<<"sox_waifu2xEX.exe"<<"wget_waifu2xEX.exe"<<"rife-ncnn-vulkan_waifu2xEX.exe"<<"cain-ncnn-vulkan_waifu2xEX.exe"<<"dain-ncnn-vulkan_waifu2xEX.exe" + <<"srmd-cuda_waifu2xEX.exe"<<"apngdis_waifu2xEX.exe"<<"apngasm_waifu2xEX.exe"; + KILL_TASK_QStringList(TaskNameList,true); + //=========== + QProcess Close; + Close.start("taskkill /f /t /fi \"imagename eq Waifu2x-Extension-GUI.exe\""); + Close.waitForStarted(10000); + Close.waitForFinished(10000); + return 0; +} +/* +最小化 +*/ +void MainWindow::changeEvent(QEvent *e) +{ + if((e->type()==QEvent::WindowStateChange)&&this->isMinimized()) + { + if(ui->checkBox_MinimizeToTaskbar->isChecked()) + { + this->hide(); + } + } +} +/* +计时器到时执行的代码 +*/ +void MainWindow::TimeSlot() +{ + TimeCost++; + //====================总进度================== + QString TimeCostStr = tr("Time taken:[")+Seconds2hms(TimeCost)+"]"; + ui->label_TimeCost->setText(TimeCostStr); + if(ui->label_TimeRemain->isVisible()) + { + long unsigned int TaskNumFinished_tmp = TaskNumFinished; + long unsigned int TimeCost_tmp = TimeCost; + long unsigned int TaskNumTotal_tmp = TaskNumTotal; + if(TaskNumFinished_tmp>0&&TimeCost_tmp>0&&TaskNumTotal_tmp>0) + { + if(NewTaskFinished) + { + NewTaskFinished=false; + double avgTimeCost = (double)TimeCost_tmp/(double)TaskNumFinished_tmp; + ETA = avgTimeCost*((double)TaskNumTotal_tmp-(double)TaskNumFinished_tmp); + } + else + { + if(ETA>1) + { + ETA--; + } + } + QString TimeRemainingStr = tr("Time remaining:[")+Seconds2hms(ETA)+"]"; + ui->label_TimeRemain->setText(TimeRemainingStr); + QDateTime time = QDateTime::currentDateTime(); + long unsigned int Time_t = time.toTime_t(); + Time_t+=ETA; + time = QDateTime::fromTime_t(Time_t); + QString Current_Time = time.toString("hh:mm:ss"); + QString ETA_str = "ETA:["+Current_Time+"]"; + ui->label_ETA->setText(ETA_str); + } + } + //====================当前文件================= + if(isStart_CurrentFile) + { + TimeCost_CurrentFile++; + QString TimeCostStr_CurrentFile = tr("Time taken:[")+Seconds2hms(TimeCost_CurrentFile)+"]"; + ui->label_TimeCost_CurrentFile->setText(TimeCostStr_CurrentFile); + long unsigned int TaskNumFinished_tmp_CurrentFile = TaskNumFinished_CurrentFile; + long unsigned int TimeCost_tmp_CurrentFile = TimeCost_CurrentFile; + long unsigned int TaskNumTotal_tmp_CurrentFile = TaskNumTotal_CurrentFile; + if(TaskNumFinished_tmp_CurrentFile>0&&TimeCost_tmp_CurrentFile>0&&TaskNumTotal_tmp_CurrentFile>0) + { + if(NewTaskFinished_CurrentFile) + { + NewTaskFinished_CurrentFile=false; + double avgTimeCost_CurrentFile = (double)TimeCost_tmp_CurrentFile/(double)TaskNumFinished_tmp_CurrentFile; + ETA_CurrentFile = avgTimeCost_CurrentFile*((double)TaskNumTotal_tmp_CurrentFile-(double)TaskNumFinished_tmp_CurrentFile); + } + else + { + if(ETA_CurrentFile>1) + { + ETA_CurrentFile--; + } + } + QString TimeRemainingStr_CurrentFile = tr("Time remaining:[")+Seconds2hms(ETA_CurrentFile)+"]"; + ui->label_TimeRemain_CurrentFile->setText(TimeRemainingStr_CurrentFile); + QDateTime time_CurrentFile = QDateTime::currentDateTime(); + long unsigned int Time_t_CurrentFile = time_CurrentFile.toTime_t(); + Time_t_CurrentFile+=ETA_CurrentFile; + time_CurrentFile = QDateTime::fromTime_t(Time_t_CurrentFile); + QString Current_Time_CurrentFile = time_CurrentFile.toString("hh:mm:ss"); + QString ETA_str_CurrentFile = "ETA:["+Current_Time_CurrentFile+"]"; + ui->label_ETA_CurrentFile->setText(ETA_str_CurrentFile); + } + } +} +QString MainWindow::Seconds2hms(long unsigned int seconds) +{ + if(seconds<=0)return "0:0:0"; + long unsigned int hour = seconds / 3600; + long unsigned int min = (seconds-(hour*3600))/60; + long unsigned int sec = seconds - hour*3600 - min*60; + return QString::number(hour,10)+":"+QString::number(min,10)+":"+QString::number(sec,10); +} + +void MainWindow::Set_Font_fixed() +{ + QFont font; + if(ui->checkBox_isCustFontEnable->isChecked()) + { + font = ui->fontComboBox_CustFont->currentFont(); + font.setPixelSize(ui->spinBox_GlobalFontSize->value()); + } + else + { + font = qApp->font(); + font.setPixelSize(15); + } + qApp->setFont(font); +} + +void MainWindow::on_pushButton_ClearList_clicked() +{ + curRow_image = -1; + curRow_gif = -1; + curRow_video = -1; + Table_Clear(); + Custom_resolution_list.clear(); + ui->label_DropFile->setVisible(1); + ui->tableView_gif->setVisible(0); + ui->tableView_image->setVisible(0); + ui->tableView_video->setVisible(0); + Table_FileCount_reload(); + progressbar_clear(); +} + +/* +停止处理键 +*/ +void MainWindow::on_pushButton_Stop_clicked() +{ + if(Waifu2xMain.isRunning()==false)return; + TimeCostTimer->stop(); + pushButton_Stop_setEnabled_self(0);//隐藏stop button + waifu2x_STOP = true; + emit TextBrowser_NewMessage(tr("Trying to stop, please wait...")); + QtConcurrent::run(this, &MainWindow::Wait_waifu2x_stop); +} +/* +等待处理线程完全停止 +*/ +void MainWindow::Wait_waifu2x_stop() +{ + while(true) + { + if(waifu2x_STOP_confirm||ThreadNumRunning==0) + { + waifu2x_STOP_confirm = false; + Waifu2xMain.waitForFinished(); + while(true) + { + if(Waifu2xMain.isRunning()==false)break; + Delay_msec_sleep(300); + } + emit TextBrowser_NewMessage(tr("Processing of files has stopped.")); + QtConcurrent::run(this, &MainWindow::Play_NFSound);//成功暂停,播放提示音 + break; + } + Delay_msec_sleep(300); + } + emit Send_Waifu2x_Finished_manual(); +} +/* +从tableview移除item +*/ +int MainWindow::on_pushButton_RemoveItem_clicked() +{ + if(curRow_image==-1&&curRow_video==-1&&curRow_gif==-1) + { + ui->tableView_image->clearSelection(); + ui->tableView_gif->clearSelection(); + ui->tableView_video->clearSelection(); + //===== + QMessageBox *MSG = new QMessageBox(); + MSG->setWindowTitle(tr("Warning")); + MSG->setText(tr("No items are currently selected.")); + MSG->setIcon(QMessageBox::Warning); + MSG->setModal(true); + MSG->show(); + //===== + return 0; + } + //========================== + if(curRow_image >= 0) + { + CustRes_remove(Table_model_image->item(curRow_image,2)->text()); + ui->tableView_image->setUpdatesEnabled(false); + Table_model_image->removeRow(curRow_image); + ui->tableView_image->setUpdatesEnabled(true); + curRow_image = -1; + ui->tableView_image->clearSelection(); + } + //============================================================ + if(curRow_video >= 0) + { + CustRes_remove(Table_model_video->item(curRow_video,2)->text()); + ui->tableView_video->setUpdatesEnabled(false); + Table_model_video->removeRow(curRow_video); + ui->tableView_video->setUpdatesEnabled(true); + curRow_video = -1; + ui->tableView_video->clearSelection(); + } + //============================================================ + if(curRow_gif >= 0) + { + CustRes_remove(Table_model_gif->item(curRow_gif,2)->text()); + ui->tableView_gif->setUpdatesEnabled(false); + Table_model_gif->removeRow(curRow_gif); + ui->tableView_gif->setUpdatesEnabled(true); + curRow_gif = -1; + ui->tableView_gif->clearSelection(); + } + //================================================== + if(Table_model_gif->rowCount()==0) + { + ui->tableView_gif->setVisible(0); + } + if(Table_model_image->rowCount()==0) + { + ui->tableView_image->setVisible(0); + } + if(Table_model_video->rowCount()==0) + { + ui->tableView_video->setVisible(0); + } + //=================================================== + if(Table_model_gif->rowCount()==0&&Table_model_image->rowCount()==0&&Table_model_video->rowCount()==0) + { + on_pushButton_ClearList_clicked(); + } + Table_FileCount_reload(); + //============ + return 0; +} + +//========================================================== +/* +============= 安全的阻塞延时 ===================== +*/ +void MainWindow::Delay_sec_sleep(int time) +{ + QThread::sleep(time); +} + +void MainWindow::Delay_msec_sleep(int time) +{ + QThread::msleep(time); +} +//========================================================== + +/* +播放提示音 +*/ +void MainWindow::Play_NFSound() +{ + if(ui->checkBox_NfSound->isChecked()==false)return; + //==== + QString NFSound = Current_Path+"/NFSound_Waifu2xEX.mp3"; + if(QFile::exists(NFSound)==false) + { + emit Send_TextBrowser_NewMessage(tr("Error! Notification sound file is missing!")); + return; + } + //==== + QMediaPlayer *player = new QMediaPlayer; + player->setMedia(QUrl::fromLocalFile(NFSound)); + player->play(); +} + +void MainWindow::on_pushButton_Report_clicked() +{ + QDesktopServices::openUrl(QUrl("https://github.com/AaronFeng753/Waifu2x-Extension-GUI/issues/new")); +} + +void MainWindow::on_pushButton_ReadMe_clicked() +{ + if(ui->comboBox_language->currentIndex()==1) + { + QDesktopServices::openUrl(QUrl("https://github.com/AaronFeng753/Waifu2x-Extension-GUI/")); + QDesktopServices::openUrl(QUrl("https://gitee.com/aaronfeng0711/Waifu2x-Extension-GUI/")); + } + else + { + QDesktopServices::openUrl(QUrl("https://github.com/AaronFeng753/Waifu2x-Extension-GUI/")); + } +} + + + +void MainWindow::on_comboBox_Engine_Image_currentIndexChanged(int index) +{ + switch(ui->comboBox_Engine_Image->currentIndex()) + { + case 0: + { + ui->spinBox_DenoiseLevel_image->setRange(-1,3); + ui->spinBox_DenoiseLevel_image->setValue(2); + ui->spinBox_DenoiseLevel_image->setEnabled(1); + ui->spinBox_DenoiseLevel_image->setToolTip(tr("Range:-1(No noise reduction)~3")); + ui->label_ImageDenoiseLevel->setToolTip(tr("Range:-1(No noise reduction)~3")); + break; + } + case 1: + { + ui->spinBox_DenoiseLevel_image->setRange(0,3); + ui->spinBox_DenoiseLevel_image->setValue(2); + ui->spinBox_DenoiseLevel_image->setEnabled(1); + ui->spinBox_DenoiseLevel_image->setToolTip(tr("Range:0(No noise reduction)~3")); + ui->label_ImageDenoiseLevel->setToolTip(tr("Range:0(No noise reduction)~3")); + break; + } + case 2: + case 6: + { + ui->spinBox_DenoiseLevel_image->setRange(-1,10); + ui->spinBox_DenoiseLevel_image->setValue(4); + ui->spinBox_DenoiseLevel_image->setEnabled(1); + ui->spinBox_DenoiseLevel_image->setToolTip(tr("Range:-1(No noise reduction)~10")); + ui->label_ImageDenoiseLevel->setToolTip(tr("Range:-1(No noise reduction)~10")); + break; + } + case 3: + { + DenoiseLevelSpinboxSetting_Anime4k(); + break; + } + case 4: + { + ui->spinBox_DenoiseLevel_image->setRange(-1,3); + ui->spinBox_DenoiseLevel_image->setValue(2); + ui->spinBox_DenoiseLevel_image->setEnabled(1); + ui->spinBox_DenoiseLevel_image->setToolTip(tr("Range:-1(No noise reduction)~3")); + ui->label_ImageDenoiseLevel->setToolTip(tr("Range:-1(No noise reduction)~3")); + break; + } + case 5: + { + ui->spinBox_DenoiseLevel_image->setRange(0,1); + ui->spinBox_DenoiseLevel_image->setValue(1); + ui->spinBox_DenoiseLevel_image->setEnabled(0); + ui->spinBox_DenoiseLevel_image->setToolTip(tr("Realsr-ncnn-vulkan engine will denoise automatically.")); + ui->label_ImageDenoiseLevel->setToolTip(tr("Realsr-ncnn-vulkan engine will denoise automatically.")); + break; + } + } + isShowAnime4kWarning=true; + on_comboBox_model_vulkan_currentIndexChanged(0); + isWaifu2xCaffeEnabled();//判断是否启用caffe图片风格设定 +} + +void MainWindow::on_comboBox_Engine_GIF_currentIndexChanged(int index) +{ + switch(ui->comboBox_Engine_GIF->currentIndex()) + { + case 0: + { + ui->spinBox_DenoiseLevel_gif->setRange(-1,3); + ui->spinBox_DenoiseLevel_gif->setValue(2); + ui->spinBox_DenoiseLevel_gif->setEnabled(1); + ui->spinBox_DenoiseLevel_gif->setToolTip(tr("Range:-1(No noise reduction)~3")); + ui->label_GIFDenoiseLevel->setToolTip(tr("Range:-1(No noise reduction)~3")); + break; + } + case 1: + { + ui->spinBox_DenoiseLevel_gif->setRange(0,3); + ui->spinBox_DenoiseLevel_gif->setValue(2); + ui->spinBox_DenoiseLevel_gif->setEnabled(1); + ui->spinBox_DenoiseLevel_gif->setToolTip(tr("Range:0(No noise reduction)~3")); + ui->label_GIFDenoiseLevel->setToolTip(tr("Range:0(No noise reduction)~3")); + break; + } + case 2: + case 6: + { + ui->spinBox_DenoiseLevel_gif->setRange(-1,10); + ui->spinBox_DenoiseLevel_gif->setValue(4); + ui->spinBox_DenoiseLevel_gif->setEnabled(1); + ui->spinBox_DenoiseLevel_gif->setToolTip(tr("Range:-1(No noise reduction)~10")); + ui->label_GIFDenoiseLevel->setToolTip(tr("Range:-1(No noise reduction)~10")); + break; + } + case 3: + { + DenoiseLevelSpinboxSetting_Anime4k(); + break; + } + case 4: + { + ui->spinBox_DenoiseLevel_gif->setRange(-1,3); + ui->spinBox_DenoiseLevel_gif->setValue(2); + ui->spinBox_DenoiseLevel_gif->setEnabled(1); + ui->spinBox_DenoiseLevel_gif->setToolTip(tr("Range:-1(No noise reduction)~3")); + ui->label_GIFDenoiseLevel->setToolTip(tr("Range:-1(No noise reduction)~3")); + break; + } + case 5: + { + ui->spinBox_DenoiseLevel_gif->setRange(0,1); + ui->spinBox_DenoiseLevel_gif->setValue(1); + ui->spinBox_DenoiseLevel_gif->setEnabled(0); + ui->spinBox_DenoiseLevel_gif->setToolTip(tr("Realsr-ncnn-vulkan engine will denoise automatically.")); + ui->label_GIFDenoiseLevel->setToolTip(tr("Realsr-ncnn-vulkan engine will denoise automatically.")); + break; + } + } + on_comboBox_model_vulkan_currentIndexChanged(0); + isWaifu2xCaffeEnabled();//判断是否启用caffe图片风格设定 +} + +void MainWindow::on_comboBox_Engine_Video_currentIndexChanged(int index) +{ + switch(ui->comboBox_Engine_Video->currentIndex()) + { + case 0: + { + ui->spinBox_DenoiseLevel_video->setRange(-1,3); + ui->spinBox_DenoiseLevel_video->setValue(2); + ui->spinBox_DenoiseLevel_video->setEnabled(1); + ui->spinBox_DenoiseLevel_video->setToolTip(tr("Range:-1(No noise reduction)~3")); + ui->label_VideoDenoiseLevel->setToolTip(tr("Range:-1(No noise reduction)~3")); + break; + } + case 1: + { + ui->spinBox_DenoiseLevel_video->setRange(0,3); + ui->spinBox_DenoiseLevel_video->setValue(2); + ui->spinBox_DenoiseLevel_video->setEnabled(1); + ui->spinBox_DenoiseLevel_video->setToolTip(tr("Range:0(No noise reduction)~3")); + ui->label_VideoDenoiseLevel->setToolTip(tr("Range:0(No noise reduction)~3")); + break; + } + case 2: + { + DenoiseLevelSpinboxSetting_Anime4k(); + break; + } + case 3: + case 6: + { + ui->spinBox_DenoiseLevel_video->setRange(-1,10); + ui->spinBox_DenoiseLevel_video->setValue(4); + ui->spinBox_DenoiseLevel_video->setEnabled(1); + ui->spinBox_DenoiseLevel_video->setToolTip(tr("Range:-1(No noise reduction)~10")); + ui->label_VideoDenoiseLevel->setToolTip(tr("Range:-1(No noise reduction)~10")); + break; + } + case 4: + { + ui->spinBox_DenoiseLevel_video->setRange(-1,3); + ui->spinBox_DenoiseLevel_video->setValue(2); + ui->spinBox_DenoiseLevel_video->setEnabled(1); + ui->spinBox_DenoiseLevel_video->setToolTip(tr("Range:-1(No noise reduction)~3")); + ui->label_VideoDenoiseLevel->setToolTip(tr("Range:-1(No noise reduction)~3")); + break; + } + case 5: + { + ui->spinBox_DenoiseLevel_video->setRange(0,1); + ui->spinBox_DenoiseLevel_video->setValue(1); + ui->spinBox_DenoiseLevel_video->setEnabled(0); + ui->spinBox_DenoiseLevel_video->setToolTip(tr("Realsr-ncnn-vulkan engine will denoise automatically.")); + ui->label_VideoDenoiseLevel->setToolTip(tr("Realsr-ncnn-vulkan engine will denoise automatically.")); + break; + } + } + on_comboBox_model_vulkan_currentIndexChanged(0); + isWaifu2xCaffeEnabled();//判断是否启用caffe图片风格设定 +} + +void MainWindow::on_pushButton_clear_textbrowser_clicked() +{ + ui->textBrowser->clear(); + TextBrowser_StartMes(); +} + +void MainWindow::on_spinBox_textbrowser_fontsize_valueChanged(int arg1) +{ + int size = ui->spinBox_textbrowser_fontsize->value(); + ui->textBrowser->setStyleSheet("font: "+QString::number(size,10)+"pt \"Arial\";"); + ui->textBrowser->moveCursor(QTextCursor::End); +} + +void MainWindow::on_pushButton_CustRes_apply_clicked() +{ + CustRes_SetCustRes(); +} + +void MainWindow::on_pushButton_CustRes_cancel_clicked() +{ + CustRes_CancelCustRes(); +} + +void MainWindow::on_pushButton_HideSettings_clicked() +{ + if(ui->groupBox_Setting->isVisible()) + { + ui->groupBox_Setting->setVisible(0); + isSettingsHide=true; + ui->pushButton_HideSettings->setText(tr("Show settings")); + } + else + { + ui->groupBox_Setting->setVisible(1); + isSettingsHide=false; + ui->pushButton_HideSettings->setText(tr("Hide settings")); + } +} + +/* +改变语言设置 +*/ +void MainWindow::on_comboBox_language_currentIndexChanged(int index) +{ + //检测是否存在日本语翻译文件,若存在则删除并修正翻译设定 + QString JapaneseQM = Current_Path + "/language_Japanese.qm"; + if(QFile::exists(JapaneseQM)) + { + QFile::remove(JapaneseQM); + if(ui->comboBox_language->currentIndex()==2)//若原语言为日语则重置为英语 + { + ui->comboBox_language->setCurrentIndex(0); + } + if(ui->comboBox_language->currentIndex()==3 || ui->comboBox_language->currentIndex()==-1)//若原语言为繁中则修正设定 + { + ui->comboBox_language->setCurrentIndex(2); + } + } + //============== + QString qmFilename=""; + switch(ui->comboBox_language->currentIndex()) + { + case 0: + { + qmFilename = Current_Path + "/language_English.qm"; + break; + } + case 1: + { + qmFilename = Current_Path + "/language_Chinese.qm"; + break; + } + case 2: + { + qmFilename = Current_Path + "/language_TraditionalChinese.qm"; + break; + } + } + //判断文件是否存在 + if(QFile::exists(qmFilename)==false) + { + QMessageBox *MSG_languageFile404 = new QMessageBox(); + MSG_languageFile404->setWindowTitle(tr("Error")); + MSG_languageFile404->setText(tr("Language file is missing, please reinstall this program.")); + MSG_languageFile404->setIcon(QMessageBox::Warning); + MSG_languageFile404->setModal(true); + MSG_languageFile404->show(); + return; + } + //加载语言文件 + if (translator->load(qmFilename)) + { + qApp->installTranslator(translator); + ui->retranslateUi(this); + Table_FileCount_reload(); + Init_Table(); + Init_SystemTrayIcon(); + Set_Font_fixed(); + //========= + if(ui->checkBox_AlwaysHideSettings->isChecked()) + { + ui->groupBox_Setting->setVisible(0); + isSettingsHide=true; + ui->pushButton_HideSettings->setText(tr("Show settings")); + } + else + { + ui->groupBox_Setting->setVisible(1); + isSettingsHide=false; + ui->pushButton_HideSettings->setText(tr("Hide settings")); + } + //========= + if(ui->checkBox_AlwaysHideTextBrowser->isChecked()) + { + ui->splitter_TextBrowser->setVisible(0); + ui->pushButton_HideTextBro->setText(tr("Show Text Browser")); + } + else + { + ui->splitter_TextBrowser->setVisible(1); + ui->pushButton_HideTextBro->setText(tr("Hide Text Browser")); + } + //========= + if(this->windowState()!=Qt::WindowMaximized) + { + this->adjustSize(); + } + } + else + { + QMessageBox *MSG_Unable2LoadLanguageFiles = new QMessageBox(); + MSG_Unable2LoadLanguageFiles->setWindowTitle(tr("Error")); + MSG_Unable2LoadLanguageFiles->setText(tr("Language file cannot be loaded properly.")); + MSG_Unable2LoadLanguageFiles->setIcon(QMessageBox::Warning); + MSG_Unable2LoadLanguageFiles->setModal(true); + MSG_Unable2LoadLanguageFiles->show(); + } +} + +void MainWindow::on_pushButton_ReadFileList_clicked() +{ + file_mkDir(Current_Path+"/FilesList_W2xEX");//生成保存文件列表的文件夹 + QString Table_FileList_ini = QFileDialog::getOpenFileName(this, tr("Select saved files list @Waifu2x-Extension-GUI"), Current_Path+"/FilesList_W2xEX", "*.ini"); + if(Table_FileList_ini=="")return; + //======== + if(QFile::exists(Table_FileList_ini)) + { + ui_tableViews_setUpdatesEnabled(false); + this->setAcceptDrops(0);//禁止drop file + pushButton_Start_setEnabled_self(0);//禁用start button + ui->pushButton_CustRes_cancel->setEnabled(0); + ui->pushButton_CustRes_apply->setEnabled(0); + ui->pushButton_ReadFileList->setEnabled(0); + ui->pushButton_SaveFileList->setEnabled(0); + ui->pushButton_BrowserFile->setEnabled(0); + on_pushButton_ClearList_clicked(); + Send_TextBrowser_NewMessage(tr("Please wait while reading the file.")); + ui->label_DropFile->setText(tr("Loading list, please wait.")); + QtConcurrent::run(this, &MainWindow::Table_Read_Saved_Table_Filelist,Table_FileList_ini); + } + else + { + QMessageBox *MSG_FileList404 = new QMessageBox(); + MSG_FileList404->setWindowTitle(tr("Error")); + MSG_FileList404->setText(tr("Target files list doesn't exist!")); + MSG_FileList404->setIcon(QMessageBox::Warning); + MSG_FileList404->setModal(true); + MSG_FileList404->show(); + } +} + +void MainWindow::on_Ext_image_editingFinished() +{ + QString ext_image_str = ui->Ext_image->text(); + ext_image_str = ext_image_str.trimmed().replace(":",":").remove(" ").remove(" ").replace(":gif:",":"); + ui->Ext_image->setText(ext_image_str); +} + +void MainWindow::on_Ext_video_editingFinished() +{ + QString ext_video_str = ui->Ext_video->text(); + ext_video_str = ext_video_str.trimmed().replace(":",":").remove(" ").remove(" ").replace(":gif:",":"); + ui->Ext_video->setText(ext_video_str); +} + +void MainWindow::on_checkBox_AutoSaveSettings_clicked() +{ + QString settings_ini = Current_Path+"/settings.ini"; + if(QFile::exists(settings_ini)) + { + QSettings *configIniWrite = new QSettings(settings_ini, QSettings::IniFormat); + configIniWrite->setValue("/settings/AutoSaveSettings", ui->checkBox_AutoSaveSettings->isChecked()); + } +} + +void MainWindow::on_pushButton_about_clicked() +{ + QMessageBox *MSG = new QMessageBox(); + MSG->setWindowTitle(tr("About")); + QString line1 = "Waifu2x-Extension-GUI\n\n"; + QString line2 = VERSION+"\n\n"; + QString line3 = "Github: https://github.com/AaronFeng753/Waifu2x-Extension-GUI\n\n"; + QString line4 = "Waifu2x-Extension-GUI is licensed under the\n"; + QString line5 = "GNU Affero General Public License v3.0\n\n"; + QString line6 = "Copyright (C) 2021 Aaron Feng. All rights reserved.\n\n"; + QString line7 = "The program is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.\n\n"; + QString line8 = "Icons made by : Freepik & Icongeek26 & Roundicons From Flaticon(https://www.flaticon.com/)"; + MSG->setText(line1+line2+line3+line4+line5+line6+line7+line8); + QImage img(":/new/prefix1/icon/icon_main.png"); + QImage img_scaled = img.scaled(50,50,Qt::KeepAspectRatio,Qt::SmoothTransformation); + QPixmap pix(QPixmap::fromImage(img_scaled)); + MSG->setIconPixmap(pix); + MSG->setModal(false); + MSG->show(); +} + +void MainWindow::on_comboBox_AspectRatio_custRes_currentIndexChanged(int index) +{ + int CurrentIndex = ui->comboBox_AspectRatio_custRes->currentIndex(); + switch(CurrentIndex) + { + case 0: + { + CustRes_AspectRatioMode = Qt::IgnoreAspectRatio; + break; + } + case 1: + { + CustRes_AspectRatioMode = Qt::KeepAspectRatio; + break; + } + case 2: + { + CustRes_AspectRatioMode = Qt::KeepAspectRatioByExpanding; + break; + } + } +} + +void MainWindow::on_checkBox_AlwaysHideSettings_stateChanged(int arg1) +{ + if(ui->checkBox_AlwaysHideSettings->isChecked()) + { + ui->groupBox_Setting->setVisible(0); + ui->pushButton_HideSettings->setText(tr("Show settings")); + isSettingsHide=true; + } +} + +void MainWindow::on_pushButton_Save_GlobalFontSize_clicked() +{ + QString settings_ini = Current_Path+"/settings.ini"; + QSettings *configIniWrite = new QSettings(settings_ini, QSettings::IniFormat); + configIniWrite->setValue("/settings/GlobalFontSize", ui->spinBox_GlobalFontSize->value()); + //========= + QMessageBox *MSG = new QMessageBox(); + MSG->setWindowTitle(tr("Notification")); + MSG->setText(tr("Custom Font Settings saved successfully.\n\nRestart the software to take effect.")); + MSG->setIcon(QMessageBox::Information); + MSG->setModal(true); + MSG->show(); +} +/* +================================================================================================== + 浏览与添加文本 +================================================================================================== +*/ +void MainWindow::on_pushButton_BrowserFile_clicked() +{ + QString Last_browsed_path = Current_Path+"/LastBrowsedPath_W2xEX.ini"; + //======== 生成 扩展名过滤 字符串 ========= + QStringList nameFilters; + nameFilters.append("*.gif"); + nameFilters.append("*.apng"); + QString Ext_image_str = ui->Ext_image->text(); + QStringList nameFilters_image = Ext_image_str.split(":"); + nameFilters_image.removeAll("gif"); + nameFilters_image.removeAll("apng"); + for(int i = 0; i < nameFilters_image.size(); ++i) + { + QString tmp = nameFilters_image.at(i).trimmed(); + if(tmp=="")continue; + tmp = "*." + tmp; + nameFilters.append(tmp); + } + QString Ext_video_str = ui->Ext_video->text(); + QStringList nameFilters_video = Ext_video_str.split(":"); + nameFilters_video.removeAll("gif"); + nameFilters_video.removeAll("apng"); + for(int i = 0; i < nameFilters_video.size(); ++i) + { + QString tmp = nameFilters_video.at(i).trimmed(); + if(tmp=="")continue; + tmp = "*." + tmp; + nameFilters.append(tmp); + } + QString nameFilters_QString = ""; + for(int i = 0; i < nameFilters.size(); ++i) + { + QString tmp = nameFilters.at(i).trimmed(); + nameFilters_QString = nameFilters_QString +" "+ tmp; + } + //===================================================== + QString BrowserStartPath = "";//浏览文件时的起始文件夹 + //=========== 读取上一次浏览的文件夹 =========================== + if(QFile::exists(Last_browsed_path)) + { + QSettings *configIniRead = new QSettings(Last_browsed_path, QSettings::IniFormat); + configIniRead->setIniCodec(QTextCodec::codecForName("UTF-8")); + BrowserStartPath = configIniRead->value("/Path").toString(); + if(!QFile::exists(BrowserStartPath))BrowserStartPath = ""; + } + //=========================================================== + QStringList Input_path_List = QFileDialog::getOpenFileNames(this, tr("Select files @Waifu2x-Extension-GUI"), BrowserStartPath, tr("All file(")+nameFilters_QString+")"); + if(Input_path_List.isEmpty()) + { + return; + } + //================== 记住上一次浏览的文件夹 ======================= + QFile::remove(Last_browsed_path); + QSettings *configIniWrite = new QSettings(Last_browsed_path, QSettings::IniFormat); + configIniWrite->setIniCodec(QTextCodec::codecForName("UTF-8")); + configIniWrite->setValue("/Warning/EN", "Do not modify this file! It may cause the program to crash! If problems occur after the modification, delete this file and restart the program."); + QFileInfo lastPath(Input_path_List.at(0)); + QString folder_lastPath = file_getFolderPath(lastPath); + configIniWrite->setValue("/Path", folder_lastPath); + //=============================================================== + AddNew_gif=false; + AddNew_image=false; + AddNew_video=false; + //================== 界面管制 ======================== + ui_tableViews_setUpdatesEnabled(false); + ui->groupBox_Setting->setEnabled(0); + ui->groupBox_FileList->setEnabled(0); + ui->groupBox_InputExt->setEnabled(0); + pushButton_Start_setEnabled_self(0); + ui->checkBox_ScanSubFolders->setEnabled(0); + this->setAcceptDrops(0); + ui->label_DropFile->setText(tr("Adding files, please wait.")); + emit Send_TextBrowser_NewMessage(tr("Adding files, please wait.")); + //=================================================== + QtConcurrent::run(this, &MainWindow::Read_Input_paths_BrowserFile, Input_path_List); +} +/* +读取 路径与添加文件 +*/ +void MainWindow::Read_Input_paths_BrowserFile(QStringList Input_path_List) +{ + Progressbar_MaxVal = Input_path_List.size(); + Progressbar_CurrentVal = 0; + emit Send_PrograssBar_Range_min_max(0, Progressbar_MaxVal); + foreach(QString Input_path, Input_path_List) + { + Input_path=Input_path.trimmed(); + if(QFile::exists(Input_path)==false)continue; + Add_File_Folder(Input_path); + emit Send_progressbar_Add(); + } + emit Send_Read_urls_finfished(); +} +/* +打开wiki +*/ +void MainWindow::on_pushButton_wiki_clicked() +{ + if(ui->comboBox_language->currentIndex()==1) + { + QDesktopServices::openUrl(QUrl("https://gitee.com/aaronfeng0711/Waifu2x-Extension-GUI/wikis")); + } + QDesktopServices::openUrl(QUrl("https://github.com/AaronFeng753/Waifu2x-Extension-GUI/wiki")); +} + +void MainWindow::on_pushButton_HideTextBro_clicked() +{ + if(ui->textBrowser->isVisible()) + { + ui->splitter_TextBrowser->setVisible(0); + ui->pushButton_HideTextBro->setText(tr("Show Text Browser")); + } + else + { + ui->splitter_TextBrowser->setVisible(1); + ui->pushButton_HideTextBro->setText(tr("Hide Text Browser")); + } +} + +void MainWindow::on_checkBox_AlwaysHideTextBrowser_stateChanged(int arg1) +{ + if(ui->checkBox_AlwaysHideTextBrowser->isChecked()) + { + ui->splitter_TextBrowser->setVisible(0); + ui->pushButton_HideTextBro->setText(tr("Show Text Browser")); + } +} + + + +void MainWindow::on_Ext_image_textChanged(const QString &arg1) +{ + QString lower = ui->Ext_image->text().toLower(); + ui->Ext_image->setText(lower); +} + +void MainWindow::on_Ext_video_textChanged(const QString &arg1) +{ + QString lower = ui->Ext_video->text().toLower(); + ui->Ext_video->setText(lower); +} + +void MainWindow::on_comboBox_model_vulkan_currentIndexChanged(int index) +{ + if(ui->comboBox_model_vulkan->currentIndex()==0) + { + ui->comboBox_ImageStyle->setEnabled(1); + ui->label_ImageStyle_W2xNCNNVulkan->setVisible(1); + ui->comboBox_ImageStyle->setVisible(1); + if(ui->comboBox_Engine_Image->currentIndex()!=0&&ui->comboBox_Engine_GIF->currentIndex()!=0&&ui->comboBox_Engine_Video->currentIndex()!=0) + { + ui->comboBox_ImageStyle->setEnabled(0); + ui->label_ImageStyle_W2xNCNNVulkan->setVisible(0); + ui->comboBox_ImageStyle->setVisible(0); + } + } + if(ui->comboBox_model_vulkan->currentIndex()==1) + { + ui->comboBox_ImageStyle->setEnabled(0); + ui->label_ImageStyle_W2xNCNNVulkan->setVisible(0); + ui->comboBox_ImageStyle->setVisible(0); + } +} + +void MainWindow::on_comboBox_ImageStyle_currentIndexChanged(int index) +{ + if(ui->comboBox_ImageStyle->currentIndex()==0) + { + ui->comboBox_model_vulkan->setEnabled(1); + } + if(ui->comboBox_ImageStyle->currentIndex()==1) + { + ui->comboBox_model_vulkan->setEnabled(0); + } +} + +void MainWindow::on_pushButton_ResetVideoSettings_clicked() +{ + ui->lineEdit_pixformat->setText("yuv420p"); + ui->lineEdit_encoder_vid->setText("libx264"); + ui->lineEdit_encoder_audio->setText("aac"); + ui->spinBox_bitrate_vid->setValue(6000); + ui->spinBox_bitrate_audio->setValue(320); + //==== + ui->spinBox_bitrate_vid_2mp4->setValue(2500); + ui->spinBox_bitrate_audio_2mp4->setValue(320); + ui->checkBox_acodec_copy_2mp4->setChecked(0); + ui->checkBox_vcodec_copy_2mp4->setChecked(0); + ui->spinBox_bitrate_vid_2mp4->setEnabled(1); + ui->spinBox_bitrate_audio_2mp4->setEnabled(1); + //==== + ui->lineEdit_ExCommand_2mp4->setText(""); + ui->lineEdit_ExCommand_output->setText(""); +} + +void MainWindow::on_lineEdit_encoder_vid_textChanged(const QString &arg1) +{ + QString tmp = ui->lineEdit_encoder_vid->text().trimmed(); + ui->lineEdit_encoder_vid->setText(tmp); +} + +void MainWindow::on_lineEdit_encoder_audio_textChanged(const QString &arg1) +{ + QString tmp = ui->lineEdit_encoder_audio->text().trimmed(); + ui->lineEdit_encoder_audio->setText(tmp); +} + +void MainWindow::on_lineEdit_pixformat_textChanged(const QString &arg1) +{ + QString tmp = ui->lineEdit_pixformat->text().trimmed(); + ui->lineEdit_pixformat->setText(tmp); +} + +void MainWindow::on_checkBox_vcodec_copy_2mp4_stateChanged(int arg1) +{ + if(ui->checkBox_vcodec_copy_2mp4->isChecked()) + { + ui->spinBox_bitrate_vid_2mp4->setEnabled(0); + } + else + { + ui->spinBox_bitrate_vid_2mp4->setEnabled(1); + } +} + +void MainWindow::on_checkBox_acodec_copy_2mp4_stateChanged(int arg1) +{ + if(ui->checkBox_acodec_copy_2mp4->isChecked()) + { + ui->spinBox_bitrate_audio_2mp4->setEnabled(0); + } + else + { + ui->spinBox_bitrate_audio_2mp4->setEnabled(1); + } +} + + +void MainWindow::on_pushButton_encodersList_clicked() +{ + file_OpenFile(Current_Path+"/FFmpeg_Encoders_List_waifu2xEX.bat"); +} + +void MainWindow::Tip_FirstTimeStart() +{ + QString FirstTimeStart = Current_Path+"/FirstTimeStart"; + if(QFile::exists(FirstTimeStart)) + { + isFirstTimeStart=false; + return; + } + else + { + isFirstTimeStart=true; + /* + 弹出语言选择对话框 + */ + QMessageBox Msg(QMessageBox::Question, QString("Choose your language"), QString("Choose your language.\n\n选择您的语言。\n\n言語を選んでください。")); + Msg.setIcon(QMessageBox::Information); + QAbstractButton *pYesBtn_English = Msg.addButton(QString("English"), QMessageBox::YesRole); + QAbstractButton *pYesBtn_Chinese = Msg.addButton(QString("简体中文"), QMessageBox::YesRole); + QAbstractButton *pYesBtn_TraditionalChinese = Msg.addButton(QString("繁體中文(由uimee翻譯)"), QMessageBox::YesRole); + Msg.exec(); + if (Msg.clickedButton() == pYesBtn_English)ui->comboBox_language->setCurrentIndex(0); + if (Msg.clickedButton() == pYesBtn_Chinese)ui->comboBox_language->setCurrentIndex(1); + if (Msg.clickedButton() == pYesBtn_TraditionalChinese)ui->comboBox_language->setCurrentIndex(2); + on_comboBox_language_currentIndexChanged(0); + //====== + QMessageBox *MSG_2 = new QMessageBox(); + MSG_2->setWindowTitle(tr("Notification")); + MSG_2->setText(tr("It is detected that this is the first time you have started the software, so the compatibility test will be performed automatically. Please wait for a while, then check the test result.")); + MSG_2->setIcon(QMessageBox::Information); + MSG_2->setModal(true); + MSG_2->show(); + //======= + file_generateMarkFile(FirstTimeStart,""); + //======= + on_pushButton_clear_textbrowser_clicked(); + on_pushButton_compatibilityTest_clicked(); + } +} + +void MainWindow::on_checkBox_DelOriginal_stateChanged(int arg1) +{ + if(ui->checkBox_DelOriginal->isChecked()) + { + QAction_checkBox_MoveToRecycleBin_checkBox_DelOriginal->setEnabled(1); + ui->checkBox_ReplaceOriginalFile->setEnabled(0); + ui->checkBox_ReplaceOriginalFile->setChecked(0); + } + else + { + QAction_checkBox_MoveToRecycleBin_checkBox_DelOriginal->setEnabled(0); + checkBox_ReplaceOriginalFile_setEnabled_True_Self(); + } +} + +void MainWindow::on_checkBox_FileList_Interactive_stateChanged(int arg1) +{ + if(ui->checkBox_FileList_Interactive->isChecked()) + { + ui->tableView_image->horizontalHeader()->setSectionResizeMode(QHeaderView::Interactive); + ui->tableView_gif->horizontalHeader()->setSectionResizeMode(QHeaderView::Interactive); + ui->tableView_video->horizontalHeader()->setSectionResizeMode(QHeaderView::Interactive); + } + else + { + ui->tableView_image->horizontalHeader()->setSectionResizeMode(QHeaderView::ResizeToContents); + ui->tableView_gif->horizontalHeader()->setSectionResizeMode(QHeaderView::ResizeToContents); + ui->tableView_video->horizontalHeader()->setSectionResizeMode(QHeaderView::ResizeToContents); + } +} + +void MainWindow::on_checkBox_OutPath_isEnabled_stateChanged(int arg1) +{ + if(ui->checkBox_OutPath_isEnabled->isChecked()) + { + ui->lineEdit_outputPath->setEnabled(1); + ui->checkBox_OutPath_KeepOriginalFileName->setEnabled(1); + ui->checkBox_KeepParentFolder->setEnabled(1); + ui->checkBox_OutPath_Overwrite->setEnabled(1); + ui->checkBox_ReplaceOriginalFile->setEnabled(0); + ui->checkBox_ReplaceOriginalFile->setChecked(0); + ui->checkBox_AutoOpenOutputPath->setEnabled(1); + } + else + { + ui->lineEdit_outputPath->setEnabled(0); + ui->checkBox_OutPath_KeepOriginalFileName->setEnabled(0); + ui->checkBox_KeepParentFolder->setEnabled(0); + ui->checkBox_OutPath_Overwrite->setEnabled(0); + ui->checkBox_AutoOpenOutputPath->setEnabled(0); + checkBox_ReplaceOriginalFile_setEnabled_True_Self(); + } +} + +//强制重试 +void MainWindow::on_pushButton_ForceRetry_clicked() +{ + if(isForceRetryEnabled==false)//处理视频和gif时禁用强制重试 + { + emit Send_TextBrowser_NewMessage(tr("Force retry is disabled when processing Video or GIF.")); + return; + } + //========== + ui->pushButton_ForceRetry->setEnabled(0); + //======== + QtConcurrent::run(this, &MainWindow::isForceRetryClicked_SetTrue_Block_Anime4k);//block a4k引擎线程 防止无效图片污染缓存 + //======== + ForceRetryCount++; + //======== + QProcess Close; + Close.start("taskkill /f /t /fi \"imagename eq Anime4K_waifu2xEX.exe\""); + Close.waitForStarted(10000); + Close.waitForFinished(10000); + Close.start("taskkill /f /t /fi \"imagename eq waifu2x-ncnn-vulkan_waifu2xEX.exe\""); + Close.waitForStarted(10000); + Close.waitForFinished(10000); + Close.start("taskkill /f /t /fi \"imagename eq waifu2x-ncnn-vulkan-fp16p_waifu2xEX.exe\""); + Close.waitForStarted(10000); + Close.waitForFinished(10000); + Close.start("taskkill /f /t /fi \"imagename eq waifu2x-converter-cpp_waifu2xEX.exe\""); + Close.waitForStarted(10000); + Close.waitForFinished(10000); + Close.start("taskkill /f /t /fi \"imagename eq srmd-ncnn-vulkan_waifu2xEX.exe\""); + Close.waitForStarted(10000); + Close.waitForFinished(10000); + Close.start("taskkill /f /t /fi \"imagename eq waifu2x-caffe_waifu2xEX.exe\""); + Close.waitForStarted(10000); + Close.waitForFinished(10000); + Close.start("taskkill /f /t /fi \"imagename eq realsr-ncnn-vulkan_waifu2xEX.exe\""); + Close.waitForStarted(10000); + Close.waitForFinished(10000); + //======== + emit Send_TextBrowser_NewMessage(tr("Force retry.")); + return; +} +//激活强制重试按钮 +void MainWindow::SetEnable_pushButton_ForceRetry_self() +{ + ui->pushButton_ForceRetry->setEnabled(1); + return; +} +void MainWindow::on_pushButton_PayPal_clicked() +{ + QDesktopServices::openUrl(QUrl("https://www.paypal.me/aaronfeng753")); +} +void MainWindow::on_checkBox_AudioDenoise_stateChanged(int arg1) +{ + if(ui->checkBox_AudioDenoise->isChecked()) + { + ui->doubleSpinBox_AudioDenoiseLevel->setEnabled(1); + } + else + { + ui->doubleSpinBox_AudioDenoiseLevel->setEnabled(0); + } +} +void MainWindow::on_tabWidget_currentChanged(int index) +{ + switch(ui->tabWidget->currentIndex()) + { + case 0: + { + //tab 0 + ui->label_DonateQRCode->setVisible(1); + ui->pushButton_PayPal->setVisible(1); + ui->pushButton_Patreon->setVisible(1); + ui->label_DonateText->setVisible(1); + //tab 1 + ui->groupBox_Progress->setVisible(0); + ui->splitter_2->setVisible(0); + //tab 2 + ui->groupBox_Engine->setVisible(0); + ui->groupBox_NumOfThreads->setVisible(0); + //tab 3 + ui->groupBox_AudioDenoise->setVisible(0); + ui->groupBox_video_settings->setVisible(0); + ui->groupBox_FrameInterpolation->setVisible(0); + //tab 4 + ui->groupBox_3->setVisible(0); + ui->groupBox_8->setVisible(0); + ui->groupBox_InputExt->setVisible(0); + ui->groupBox_other_1->setVisible(0); + //tab 5 + ui->groupBox_CompatibilityTestRes->setVisible(0); + ui->pushButton_compatibilityTest->setVisible(0); + break; + } + case 1: + { + //tab 0 + ui->label_DonateQRCode->setVisible(0); + ui->pushButton_PayPal->setVisible(0); + ui->pushButton_Patreon->setVisible(0); + ui->label_DonateText->setVisible(0); + //tab 1 + ui->groupBox_Progress->setVisible(1); + ui->splitter_2->setVisible(1); + if(isSettingsHide==false) + { + ui->groupBox_Setting->setVisible(1); + } + //tab 2 + ui->groupBox_Engine->setVisible(0); + ui->groupBox_NumOfThreads->setVisible(0); + //tab 3 + ui->groupBox_AudioDenoise->setVisible(0); + ui->groupBox_video_settings->setVisible(0); + ui->groupBox_FrameInterpolation->setVisible(0); + //tab 4 + ui->groupBox_3->setVisible(0); + ui->groupBox_8->setVisible(0); + ui->groupBox_InputExt->setVisible(0); + ui->groupBox_other_1->setVisible(0); + //tab 5 + ui->groupBox_CompatibilityTestRes->setVisible(0); + ui->pushButton_compatibilityTest->setVisible(0); + break; + } + case 2: + { + //tab 0 + ui->label_DonateQRCode->setVisible(0); + ui->pushButton_PayPal->setVisible(0); + ui->pushButton_Patreon->setVisible(0); + ui->label_DonateText->setVisible(0); + //tab 1 + ui->groupBox_Progress->setVisible(0); + ui->splitter_2->setVisible(0); + //tab 2 + ui->groupBox_Engine->setVisible(1); + ui->groupBox_NumOfThreads->setVisible(1); + //tab 3 + ui->groupBox_AudioDenoise->setVisible(0); + ui->groupBox_video_settings->setVisible(0); + ui->groupBox_FrameInterpolation->setVisible(0); + //tab 4 + ui->groupBox_3->setVisible(0); + ui->groupBox_8->setVisible(0); + ui->groupBox_InputExt->setVisible(0); + ui->groupBox_other_1->setVisible(0); + //tab 5 + ui->groupBox_CompatibilityTestRes->setVisible(0); + ui->pushButton_compatibilityTest->setVisible(0); + break; + } + case 3: + { + //tab 0 + ui->label_DonateQRCode->setVisible(0); + ui->pushButton_PayPal->setVisible(0); + ui->pushButton_Patreon->setVisible(0); + ui->label_DonateText->setVisible(0); + //tab 1 + ui->groupBox_Progress->setVisible(0); + ui->splitter_2->setVisible(0); + //tab 2 + ui->groupBox_Engine->setVisible(0); + ui->groupBox_NumOfThreads->setVisible(0); + //tab 3 + ui->groupBox_AudioDenoise->setVisible(1); + ui->groupBox_video_settings->setVisible(1); + ui->groupBox_FrameInterpolation->setVisible(1); + //tab 4 + ui->groupBox_3->setVisible(0); + ui->groupBox_8->setVisible(0); + ui->groupBox_InputExt->setVisible(0); + ui->groupBox_other_1->setVisible(0); + //tab 5 + ui->groupBox_CompatibilityTestRes->setVisible(0); + ui->pushButton_compatibilityTest->setVisible(0); + break; + } + case 4: + { + //tab 0 + ui->label_DonateQRCode->setVisible(0); + ui->pushButton_PayPal->setVisible(0); + ui->pushButton_Patreon->setVisible(0); + ui->label_DonateText->setVisible(0); + //tab 1 + ui->groupBox_Progress->setVisible(0); + ui->splitter_2->setVisible(0); + //tab 2 + ui->groupBox_Engine->setVisible(0); + ui->groupBox_NumOfThreads->setVisible(0); + //tab 3 + ui->groupBox_AudioDenoise->setVisible(0); + ui->groupBox_video_settings->setVisible(0); + ui->groupBox_FrameInterpolation->setVisible(0); + //tab 4 + ui->groupBox_3->setVisible(1); + ui->groupBox_8->setVisible(1); + ui->groupBox_InputExt->setVisible(1); + ui->groupBox_other_1->setVisible(1); + //tab 5 + ui->groupBox_CompatibilityTestRes->setVisible(0); + ui->pushButton_compatibilityTest->setVisible(0); + break; + } + case 5: + { + //tab 0 + ui->label_DonateQRCode->setVisible(0); + ui->pushButton_PayPal->setVisible(0); + ui->pushButton_Patreon->setVisible(0); + ui->label_DonateText->setVisible(0); + //tab 1 + ui->groupBox_Progress->setVisible(0); + ui->splitter_2->setVisible(0); + //tab 2 + ui->groupBox_Engine->setVisible(0); + ui->groupBox_NumOfThreads->setVisible(0); + //tab 3 + ui->groupBox_AudioDenoise->setVisible(0); + ui->groupBox_video_settings->setVisible(0); + ui->groupBox_FrameInterpolation->setVisible(0); + //tab 4 + ui->groupBox_3->setVisible(0); + ui->groupBox_8->setVisible(0); + ui->groupBox_InputExt->setVisible(0); + ui->groupBox_other_1->setVisible(0); + //tab 5 + ui->groupBox_CompatibilityTestRes->setVisible(1); + ui->pushButton_compatibilityTest->setVisible(1); + break; + } + } +} +void MainWindow::on_checkBox_ProcessVideoBySegment_stateChanged(int arg1) +{ + if(ui->checkBox_ProcessVideoBySegment->isChecked()) + { + ui->label_SegmentDuration->setEnabled(1); + ui->spinBox_SegmentDuration->setEnabled(1); + } + else + { + ui->label_SegmentDuration->setEnabled(0); + ui->spinBox_SegmentDuration->setEnabled(0); + } +} +void MainWindow::on_comboBox_version_Waifu2xNCNNVulkan_currentIndexChanged(int index) +{ + switch (ui->comboBox_version_Waifu2xNCNNVulkan->currentIndex()) + { + case 0: + { + Waifu2x_ncnn_vulkan_FolderPath = Current_Path + "/waifu2x-ncnn-vulkan"; + Waifu2x_ncnn_vulkan_ProgramPath = Waifu2x_ncnn_vulkan_FolderPath + "/waifu2x-ncnn-vulkan_waifu2xEX.exe"; + ui->checkBox_TTA_vulkan->setEnabled(1); + return; + } + case 1: + { + Waifu2x_ncnn_vulkan_FolderPath = Current_Path + "/waifu2x-ncnn-vulkan"; + Waifu2x_ncnn_vulkan_ProgramPath = Waifu2x_ncnn_vulkan_FolderPath + "/waifu2x-ncnn-vulkan-fp16p_waifu2xEX.exe"; + ui->checkBox_TTA_vulkan->setEnabled(1); + return; + } + case 2: + { + Waifu2x_ncnn_vulkan_FolderPath = Current_Path + "/waifu2x-ncnn-vulkan-old"; + Waifu2x_ncnn_vulkan_ProgramPath = Waifu2x_ncnn_vulkan_FolderPath + "/waifu2x-ncnn-vulkan_waifu2xEX.exe"; + ui->checkBox_TTA_vulkan->setEnabled(0); + ui->checkBox_TTA_vulkan->setChecked(0); + return; + } + } +} +void MainWindow::on_checkBox_EnablePreProcessing_Anime4k_stateChanged(int arg1) +{ + if(ui->checkBox_EnablePreProcessing_Anime4k->isChecked()) + { + ui->checkBox_MedianBlur_Pre_Anime4k->setEnabled(1); + ui->checkBox_MeanBlur_Pre_Anime4k->setEnabled(1); + ui->checkBox_CASSharping_Pre_Anime4k->setEnabled(1); + ui->checkBox_GaussianBlurWeak_Pre_Anime4k->setEnabled(1); + ui->checkBox_GaussianBlur_Pre_Anime4k->setEnabled(1); + ui->checkBox_BilateralFilter_Pre_Anime4k->setEnabled(1); + ui->checkBox_BilateralFilterFaster_Pre_Anime4k->setEnabled(1); + } + else + { + ui->checkBox_MedianBlur_Pre_Anime4k->setEnabled(0); + ui->checkBox_MeanBlur_Pre_Anime4k->setEnabled(0); + ui->checkBox_CASSharping_Pre_Anime4k->setEnabled(0); + ui->checkBox_GaussianBlurWeak_Pre_Anime4k->setEnabled(0); + ui->checkBox_GaussianBlur_Pre_Anime4k->setEnabled(0); + ui->checkBox_BilateralFilter_Pre_Anime4k->setEnabled(0); + ui->checkBox_BilateralFilterFaster_Pre_Anime4k->setEnabled(0); + } +} +void MainWindow::on_checkBox_EnablePostProcessing_Anime4k_stateChanged(int arg1) +{ + if(ui->checkBox_EnablePostProcessing_Anime4k->isChecked()) + { + ui->checkBox_MedianBlur_Post_Anime4k->setEnabled(1); + ui->checkBox_MeanBlur_Post_Anime4k->setEnabled(1); + ui->checkBox_CASSharping_Post_Anime4k->setEnabled(1); + ui->checkBox_GaussianBlurWeak_Post_Anime4k->setEnabled(1); + ui->checkBox_GaussianBlur_Post_Anime4k->setEnabled(1); + ui->checkBox_BilateralFilter_Post_Anime4k->setEnabled(1); + ui->checkBox_BilateralFilterFaster_Post_Anime4k->setEnabled(1); + } + else + { + ui->checkBox_MedianBlur_Post_Anime4k->setEnabled(0); + ui->checkBox_MeanBlur_Post_Anime4k->setEnabled(0); + ui->checkBox_CASSharping_Post_Anime4k->setEnabled(0); + ui->checkBox_GaussianBlurWeak_Post_Anime4k->setEnabled(0); + ui->checkBox_GaussianBlur_Post_Anime4k->setEnabled(0); + ui->checkBox_BilateralFilter_Post_Anime4k->setEnabled(0); + ui->checkBox_BilateralFilterFaster_Post_Anime4k->setEnabled(0); + } +} +void MainWindow::on_checkBox_SpecifyGPU_Anime4k_stateChanged(int arg1) +{ + if(ui->checkBox_SpecifyGPU_Anime4k->isChecked()) + { + ui->lineEdit_GPUs_Anime4k->setEnabled(1); + ui->pushButton_ListGPUs_Anime4k->setEnabled(1); + ui->pushButton_VerifyGPUsConfig_Anime4k->setEnabled(1); + } + else + { + ui->lineEdit_GPUs_Anime4k->setEnabled(0); + ui->pushButton_ListGPUs_Anime4k->setEnabled(0); + ui->pushButton_VerifyGPUsConfig_Anime4k->setEnabled(0); + } +} +void MainWindow::on_checkBox_isCompatible_Waifu2x_NCNN_Vulkan_NEW_clicked() +{ + ui->checkBox_isCompatible_Waifu2x_NCNN_Vulkan_NEW->setChecked(isCompatible_Waifu2x_NCNN_Vulkan_NEW); +} +void MainWindow::on_checkBox_isCompatible_Waifu2x_NCNN_Vulkan_NEW_FP16P_clicked() +{ + ui->checkBox_isCompatible_Waifu2x_NCNN_Vulkan_NEW_FP16P->setChecked(isCompatible_Waifu2x_NCNN_Vulkan_NEW_FP16P); +} +void MainWindow::on_checkBox_isCompatible_Waifu2x_NCNN_Vulkan_OLD_clicked() +{ + ui->checkBox_isCompatible_Waifu2x_NCNN_Vulkan_OLD->setChecked(isCompatible_Waifu2x_NCNN_Vulkan_OLD); +} +void MainWindow::on_checkBox_isCompatible_SRMD_NCNN_Vulkan_clicked() +{ + ui->checkBox_isCompatible_SRMD_NCNN_Vulkan->setChecked(isCompatible_SRMD_NCNN_Vulkan); +} +void MainWindow::on_checkBox_isCompatible_SRMD_CUDA_clicked() +{ + ui->checkBox_isCompatible_SRMD_CUDA->setChecked(isCompatible_SRMD_CUDA); +} +void MainWindow::on_checkBox_isCompatible_Waifu2x_Converter_clicked() +{ + ui->checkBox_isCompatible_Waifu2x_Converter->setChecked(isCompatible_Waifu2x_Converter); +} +void MainWindow::on_checkBox_isCompatible_Anime4k_CPU_clicked() +{ + ui->checkBox_isCompatible_Anime4k_CPU->setChecked(isCompatible_Anime4k_CPU); +} +void MainWindow::on_checkBox_isCompatible_Anime4k_GPU_clicked() +{ + ui->checkBox_isCompatible_Anime4k_GPU->setChecked(isCompatible_Anime4k_GPU); +} +void MainWindow::on_checkBox_isCompatible_FFmpeg_clicked() +{ + ui->checkBox_isCompatible_FFmpeg->setChecked(isCompatible_FFmpeg); +} +void MainWindow::on_checkBox_isCompatible_FFprobe_clicked() +{ + ui->checkBox_isCompatible_FFprobe->setChecked(isCompatible_FFprobe); +} +void MainWindow::on_checkBox_isCompatible_ImageMagick_clicked() +{ + ui->checkBox_isCompatible_ImageMagick->setChecked(isCompatible_ImageMagick); +} +void MainWindow::on_checkBox_isCompatible_Gifsicle_clicked() +{ + ui->checkBox_isCompatible_Gifsicle->setChecked(isCompatible_Gifsicle); +} +void MainWindow::on_checkBox_isCompatible_SoX_clicked() +{ + ui->checkBox_isCompatible_SoX->setChecked(isCompatible_SoX); +} +void MainWindow::on_checkBox_GPUMode_Anime4K_stateChanged(int arg1) +{ + if(ui->checkBox_GPUMode_Anime4K->isChecked()) + { + ui->checkBox_SpecifyGPU_Anime4k->setEnabled(1); + ui->comboBox_GPGPUModel_A4k->setEnabled(1); + on_comboBox_GPGPUModel_A4k_currentIndexChanged(1); + } + else + { + ui->checkBox_SpecifyGPU_Anime4k->setEnabled(0); + ui->checkBox_SpecifyGPU_Anime4k->setChecked(0); + ui->comboBox_GPGPUModel_A4k->setEnabled(0); + on_comboBox_GPGPUModel_A4k_currentIndexChanged(1); + } +} +void MainWindow::on_checkBox_ShowInterPro_stateChanged(int arg1) +{ + if(ui->checkBox_ShowInterPro->isChecked()==false) + { + emit Send_CurrentFileProgress_Stop(); + } +} +void MainWindow::on_checkBox_isCompatible_Waifu2x_Caffe_CPU_clicked() +{ + ui->checkBox_isCompatible_Waifu2x_Caffe_CPU->setChecked(isCompatible_Waifu2x_Caffe_CPU); +} +void MainWindow::on_checkBox_isCompatible_Waifu2x_Caffe_GPU_clicked() +{ + ui->checkBox_isCompatible_Waifu2x_Caffe_GPU->setChecked(isCompatible_Waifu2x_Caffe_GPU); +} +void MainWindow::on_checkBox_isCompatible_Waifu2x_Caffe_cuDNN_clicked() +{ + ui->checkBox_isCompatible_Waifu2x_Caffe_cuDNN->setChecked(isCompatible_Waifu2x_Caffe_cuDNN); +} +void MainWindow::on_pushButton_SplitSize_Add_Waifu2xCaffe_clicked() +{ + int VAL = ui->spinBox_SplitSize_Waifu2xCaffe->value()*2; + if(VAL<=999999999) + { + ui->spinBox_SplitSize_Waifu2xCaffe->setValue(VAL); + } +} +void MainWindow::on_pushButton_SplitSize_Minus_Waifu2xCaffe_clicked() +{ + int VAL = ui->spinBox_SplitSize_Waifu2xCaffe->value()/2; + if(VAL>=2) + { + ui->spinBox_SplitSize_Waifu2xCaffe->setValue(VAL); + } +} +void MainWindow::on_checkBox_isCompatible_Realsr_NCNN_Vulkan_clicked() +{ + ui->checkBox_isCompatible_Realsr_NCNN_Vulkan->setChecked(isCompatible_Realsr_NCNN_Vulkan); +} +void MainWindow::on_checkBox_ACNet_Anime4K_stateChanged(int arg1) +{ + if(ui->checkBox_ACNet_Anime4K->isChecked()) + { + ui->checkBox_HDNMode_Anime4k->setEnabled(1); + ui->groupBox_PostProcessing_Anime4k->setEnabled(0); + ui->groupBox_PreProcessing_Anime4k->setEnabled(0); + ui->doubleSpinBox_PushColorStrength_Anime4K->setEnabled(0); + ui->doubleSpinBox_PushGradientStrength_Anime4K->setEnabled(0); + ui->spinBox_Passes_Anime4K->setEnabled(0); + ui->spinBox_PushColorCount_Anime4K->setEnabled(0); + } + else + { + ui->checkBox_HDNMode_Anime4k->setEnabled(0); + on_checkBox_GPUMode_Anime4K_stateChanged(0); + on_checkBox_SpecifyGPU_Anime4k_stateChanged(0); + ui->groupBox_PostProcessing_Anime4k->setEnabled(1); + ui->groupBox_PreProcessing_Anime4k->setEnabled(1); + ui->doubleSpinBox_PushColorStrength_Anime4K->setEnabled(1); + ui->doubleSpinBox_PushGradientStrength_Anime4K->setEnabled(1); + ui->spinBox_Passes_Anime4K->setEnabled(1); + ui->spinBox_PushColorCount_Anime4K->setEnabled(1); + } + DenoiseLevelSpinboxSetting_Anime4k(); +} +void MainWindow::on_checkBox_HDNMode_Anime4k_stateChanged(int arg1) +{ + DenoiseLevelSpinboxSetting_Anime4k(); +} +/* +生成独立cmd文件来执行cmd命令 +*/ +void MainWindow::ExecuteCMD_batFile(QString cmd_str,bool requestAdmin) +{ + ExecuteCMD_batFile_QMutex.lock(); + QString cmd_commands = "@echo off\n "+cmd_str+"\n exit"; + Delay_msec_sleep(10);//延时防止文件名称碰撞 + file_mkDir(Current_Path+"/batFiles_tmp"); + QString Bat_path = Current_Path+"/batFiles_tmp/W2xEX_"+QDateTime::currentDateTime().toString("dhhmmsszzz")+".bat"; + //======== + QFile OpenFile_cmdFile(Bat_path); + OpenFile_cmdFile.remove(); + if (OpenFile_cmdFile.open(QIODevice::ReadWrite | QIODevice::Text)) //QIODevice::ReadWrite支持读写 + { + QTextStream stream(&OpenFile_cmdFile); + stream << cmd_commands; + } + OpenFile_cmdFile.close(); + if(requestAdmin) + { + ShellExecuteW(NULL, QString("runas").toStdWString().c_str(), QString(Bat_path).toStdWString().c_str(), QString(Bat_path).toStdWString().c_str(), NULL, 1); + } + else + { + QDesktopServices::openUrl(QUrl("file:"+QUrl::toPercentEncoding(Bat_path))); + } + //======== + ExecuteCMD_batFile_QMutex.unlock(); +} +void MainWindow::Del_TempBatFile() +{ + file_DelDir(Current_Path+"/batFiles_tmp"); +} +void MainWindow::comboBox_UpdateChannel_setCurrentIndex_self(int index) +{ + comboBox_UpdateChannel_setCurrentIndex_self_QMutex.lock(); + isClicked_comboBox_UpdateChannel=false; + ui->comboBox_UpdateChannel->setCurrentIndex(index); + isClicked_comboBox_UpdateChannel=true; + comboBox_UpdateChannel_setCurrentIndex_self_QMutex.unlock(); +} +void MainWindow::on_comboBox_UpdateChannel_currentIndexChanged(int index) +{ + if(isClicked_comboBox_UpdateChannel && AutoUpdate.isRunning()==false) + { + AutoUpdate = QtConcurrent::run(this, &MainWindow::CheckUpadte_Auto);//自动检查更新线程 + } +} +void MainWindow::on_checkBox_ReplaceOriginalFile_stateChanged(int arg1) +{ + if(ui->checkBox_ReplaceOriginalFile->isChecked()) + { + ui->groupBox_OutPut->setEnabled(0); + ui->checkBox_OutPath_isEnabled->setChecked(0); + ui->checkBox_DelOriginal->setEnabled(0); + } + else + { + ui->groupBox_OutPut->setEnabled(1); + ui->checkBox_DelOriginal->setEnabled(1); + } +} +void MainWindow::checkBox_ReplaceOriginalFile_setEnabled_True_Self() +{ + if(ui->checkBox_DelOriginal->isChecked()==false && ui->checkBox_OutPath_isEnabled->isChecked()==false) + { + ui->checkBox_ReplaceOriginalFile->setEnabled(1); + } +} +bool MainWindow::ReplaceOriginalFile(QString original_fullpath,QString output_fullpath) +{ + //检查是否启用替换源文件,以及输出文件是否存在 + if(ui->checkBox_ReplaceOriginalFile->isChecked()==false || QFile::exists(output_fullpath)==false)return false; + //================= + QFileInfo fileinfo_original_fullpath(original_fullpath); + QFileInfo fileinfo_output_fullpath(output_fullpath); + QString file_name = file_getBaseName(original_fullpath);//获取源文件的文件名 + QString file_ext = fileinfo_output_fullpath.suffix();//获取输出文件的后辍 + QString file_path = file_getFolderPath(fileinfo_original_fullpath);//获取源文件的文件路径 + //================= + QString Target_fullpath=file_path+"/"+file_name+"."+file_ext; + //================= + if(QAction_checkBox_MoveToRecycleBin_checkBox_ReplaceOriginalFile->isChecked()) + { + file_MoveToTrash(original_fullpath); + file_MoveToTrash(Target_fullpath); + } + else + { + QFile::remove(original_fullpath); + QFile::remove(Target_fullpath); + } + //================= + if(QFile::rename(output_fullpath,Target_fullpath)==false) + { + emit Send_TextBrowser_NewMessage(tr("Error! Failed to move [")+output_fullpath+tr("] to [")+Target_fullpath+"]"); + } + return true; +} +void MainWindow::on_checkBox_isCustFontEnable_stateChanged(int arg1) +{ + if(ui->checkBox_isCustFontEnable->isChecked()) + { + ui->pushButton_Save_GlobalFontSize->setEnabled(1); + ui->spinBox_GlobalFontSize->setEnabled(1); + ui->fontComboBox_CustFont->setEnabled(1); + } + else + { + ui->pushButton_Save_GlobalFontSize->setEnabled(0); + ui->spinBox_GlobalFontSize->setEnabled(0); + ui->fontComboBox_CustFont->setEnabled(0); + } +} +void MainWindow::OutputSettingsArea_setEnabled(bool isEnabled) +{ + ui->scrollArea_outputPathSettings->setEnabled(isEnabled); + ui->lineEdit_outputPath->setClearButtonEnabled(isEnabled); + if(isEnabled==true) + { + ui->lineEdit_outputPath->setFocusPolicy(Qt::StrongFocus); + } + else + { + ui->lineEdit_outputPath->setFocusPolicy(Qt::NoFocus); + } +} +//事件过滤器 +bool MainWindow::eventFilter(QObject *target, QEvent *event) +{ + //============================= + //按下 Delete 移除文件列表里的文件 + //============================= + if (target == ui->tableView_image || target == ui->tableView_gif || target == ui->tableView_video) + { + if (event->type() == QEvent::KeyPress) + { + QKeyEvent *keyEvent = static_cast(event); + if (keyEvent->key() == Qt::Key_Delete) + { + if(RemoveFile_FilesList_QAction_FileList->isEnabled()) + { + on_pushButton_RemoveItem_clicked(); + } + return true; + } + if ((keyEvent->modifiers() == Qt::ControlModifier) && (keyEvent->key() == Qt::Key_A)) + { + if(Apply_CustRes_QAction_FileList->isEnabled()) + { + EnableApply2All_CustRes=false; + on_pushButton_CustRes_apply_clicked(); + EnableApply2All_CustRes=true; + } + return true; + } + if ((keyEvent->modifiers() == Qt::ControlModifier) && (keyEvent->key() == Qt::Key_C)) + { + if(Cancel_CustRes_QAction_FileList->isEnabled()) + { + EnableApply2All_CustRes=false; + on_pushButton_CustRes_cancel_clicked(); + EnableApply2All_CustRes=true; + } + return true; + } + } + } + //============== + return false; +} +void MainWindow::on_pushButton_ResizeFilesListSplitter_clicked() +{ + ui->splitter_FilesList->setSizes(QList() << 1 << 1 << 1); +} +void MainWindow::on_comboBox_GPGPUModel_A4k_currentIndexChanged(int index) +{ + if(ui->comboBox_GPGPUModel_A4k->currentText().toLower().trimmed()=="opencl" && ui->checkBox_GPUMode_Anime4K->isChecked()) + { + ui->spinBox_OpenCLCommandQueues_A4k->setEnabled(1); + ui->checkBox_OpenCLParallelIO_A4k->setEnabled(1); + } + else + { + ui->spinBox_OpenCLCommandQueues_A4k->setEnabled(0); + ui->checkBox_OpenCLParallelIO_A4k->setEnabled(0); + } +} +void MainWindow::on_checkBox_DisableGPU_converter_stateChanged(int arg1) +{ + if(ui->checkBox_DisableGPU_converter->isChecked()) + { + ui->checkBox_MultiGPU_Waifu2xConverter->setChecked(0); + ui->comboBox_TargetProcessor_converter->setEnabled(0); + ui->comboBox_TargetProcessor_converter->setCurrentIndex(0); + ui->checkBox_MultiGPU_Waifu2xConverter->setEnabled(0); + } + else + { + ui->comboBox_TargetProcessor_converter->setEnabled(1); + ui->checkBox_MultiGPU_Waifu2xConverter->setEnabled(1); + } +} +void MainWindow::on_groupBox_video_settings_clicked() +{ + if(ui->groupBox_video_settings->isChecked()) + { + //====== + if(isCustomVideoSettingsClicked==true) + { + QMessageBox *MSG = new QMessageBox(); + MSG->setWindowTitle(tr("Warning")); + MSG->setText(tr("Change Custom video settings might cause ERROR.\n\nMake sure you know what you are doing before change any settings.")); + MSG->setIcon(QMessageBox::Warning); + MSG->setModal(true); + MSG->show(); + } + //====== + ui->groupBox_OutputVideoSettings->setEnabled(1); + ui->groupBox_ToMp4VideoSettings->setEnabled(1); + ui->pushButton_encodersList->setEnabled(1); + ui->pushButton_ResetVideoSettings->setEnabled(1); + } + else + { + ui->groupBox_OutputVideoSettings->setEnabled(0); + ui->groupBox_ToMp4VideoSettings->setEnabled(0); + ui->pushButton_encodersList->setEnabled(0); + ui->pushButton_ResetVideoSettings->setEnabled(0); + } +} +void MainWindow::Set_checkBox_DisableResize_gif_Checked() +{ + emit Send_TextBrowser_NewMessage(tr("[Disable \"-resize\"] is automatically enabled to fix compatibility issue and improve performance.")); + ui->checkBox_DisableResize_gif->setChecked(true); +} + +void MainWindow::on_pushButton_TurnOffScreen_clicked() +{ + if(TurnOffScreen_QF.isRunning() == true)return; + TurnOffScreen_QF = QtConcurrent::run(this, &MainWindow::TurnOffScreen);//关闭显示器 +} +/* +调用nircmd关闭显示器 +*/ +void MainWindow::TurnOffScreen() +{ + QProcess *OffScreen = new QProcess(); + OffScreen->start("\""+Current_Path+"/nircmd-x64/nircmd.exe\" monitor off"); + OffScreen->waitForStarted(5000); + OffScreen->waitForFinished(5000); + OffScreen->kill(); + return; +} +/* +禁用&启用 开始按钮 +*/ +void MainWindow::pushButton_Start_setEnabled_self(bool isEnabled) +{ + ui->pushButton_Start->setEnabled(isEnabled); + Start_SystemTrayIcon->setEnabled(isEnabled); + ui->pushButton_Start->setVisible(isEnabled); +} +/* +禁用&启用 暂停按钮 +*/ +void MainWindow::pushButton_Stop_setEnabled_self(bool isEnabled) +{ + ui->pushButton_Stop->setEnabled(isEnabled); + Pause_SystemTrayIcon->setEnabled(isEnabled); + ui->pushButton_Stop->setVisible(isEnabled); +} + + +void MainWindow::on_pushButton_MultipleOfFPS_VFI_MIN_clicked() +{ + int VAL = 2; + if(ui->comboBox_Engine_VFI->currentIndex()==2) + { + VAL = ui->spinBox_MultipleOfFPS_VFI->value()-1; + } + else + { + VAL = ui->spinBox_MultipleOfFPS_VFI->value()/2; + } + if(VAL>=2) + { + ui->spinBox_MultipleOfFPS_VFI->setValue(VAL); + } +} + +void MainWindow::on_pushButton_MultipleOfFPS_VFI_ADD_clicked() +{ + int VAL = 2; + if(ui->comboBox_Engine_VFI->currentIndex()==2) + { + VAL = ui->spinBox_MultipleOfFPS_VFI->value()+1; + } + else + { + VAL = ui->spinBox_MultipleOfFPS_VFI->value()*2; + } + if(VAL<=999999999) + { + ui->spinBox_MultipleOfFPS_VFI->setValue(VAL); + } +} diff --git a/SRC/Waifu2x-Extension-QT/mainwindow.h b/SRC_v3.41.01-beta/Waifu2x-Extension-QT/mainwindow.h similarity index 97% rename from SRC/Waifu2x-Extension-QT/mainwindow.h rename to SRC_v3.41.01-beta/Waifu2x-Extension-QT/mainwindow.h index dabd396..19e152d 100644 --- a/SRC/Waifu2x-Extension-QT/mainwindow.h +++ b/SRC_v3.41.01-beta/Waifu2x-Extension-QT/mainwindow.h @@ -1,1093 +1,1093 @@ -/* - Copyright (C) 2021 Aaron Feng - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU Affero General Public License as published - by the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Affero General Public License for more details. - - You should have received a copy of the GNU Affero General Public License - along with this program. If not, see . - - My Github homepage: https://github.com/AaronFeng753 -*/ - -#ifndef MAINWINDOW_H -#define MAINWINDOW_H - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "topsupporterslist.h" - -typedef QList> QList_QMap_QStrQStr; -Q_DECLARE_METATYPE(QList_QMap_QStrQStr) - -QT_BEGIN_NAMESPACE -namespace Ui -{ - class MainWindow; -} -QT_END_NAMESPACE - -class MainWindow : public QMainWindow -{ - Q_OBJECT - -public: - MainWindow(QWidget *parent = nullptr); - void changeEvent(QEvent *e); - //======================= - QString VERSION = "v3.41.02-beta";//软件版本号 - bool isBetaVer = true; - QString LastStableVer = "v3.31.13"; - QString LastBetaVer = "v3.41.02-beta"; - //======================= - QTranslator * translator;//界面翻译 - QIcon *MainIcon_QIcon = new QIcon(":/new/prefix1/icon/icon_main.png"); - TopSupportersList *TopSupportersList_widget; - //======= - QString Current_Path = qApp->applicationDirPath();//当前路径 - //======= - void Set_Font_fixed(); - //================================= File 文件 ================================= - void dragEnterEvent(QDragEnterEvent *event);//拖放文件event - void dropEvent(QDropEvent *event); - void Read_urls(QList urls); - void Read_Input_paths_BrowserFile(QStringList Input_path_List); - bool AddNew_gif=false;//判断是否有新增文件-gif - bool AddNew_image=false;//判断是否有新增文件-图片 - bool AddNew_video=false;//判断是否有新增文件-视频 - void Add_File_Folder(QString Full_Path);//添加文件or文件夹(判断一个路径是文件还是文件夹,然后处理判断类型添加到table和file list) - void Add_File_Folder_IncludeSubFolder(QString Full_Path);//添加文件文件夹(扫描子文件夹 - QStringList getFileNames_IncludeSubFolder(QString path);//读取文件列表, 包括文件夹 - int FileList_Add(QString fileName, QString SourceFile_fullPath);//直接向file list和tableview添加文件 - //判断一个文件是否已存在于一个文件列表中(输入list和完整路径,然后判断返回bool) - bool Deduplicate_filelist(QString SourceFile_fullPath); - bool file_isDirExist(QString SourceFile_fullPath);//判断文件夹是否存在 - void file_mkDir(QString SourceFile_fullPath);//创建文件夹 - bool file_isDirEmpty(QString FolderPath); - QStringList file_getFileNames_in_Folder_nofilter(QString path);//读取文件夹内文件列表并返回(无过滤器) - bool file_DelDir(const QString &path);//删除文件夹(无论是否为空,强制删除) - QString file_getBaseName(QString path);//获取basename - void file_MoveToTrash( QString file );//移动到回收站 - void MoveFileToOutputPath(QString Orginal,QString SourceFilePath);//移动文件 - QMutex MoveFile_QMutex; - QString file_getFolderPath(QFileInfo fileInfo);//获取文件夹路径(去除末尾的"/") - bool file_isDirWritable(QString DirPath);//检查文件夹是否可写入 - //检查当前行的文件所在的文件夹是否可写入 - bool file_isFilesFolderWritable_row_image(int rowNum); - bool file_isFilesFolderWritable_row_video(int rowNum); - bool file_isFilesFolderWritable_row_gif(int rowNum); - bool file_OpenFolder(QString FolderPath);//调用系统资源管理器打开文件夹. - bool file_OpenFilesFolder(QString FilePath);//打开文件所在的文件夹 - bool file_OpenFile(QString FilePath); - void file_MoveFiles_Folder_NcnnVulkanFolderProcess(QString Old_folder, QString New_folder, bool Delete_); - bool file_generateMarkFile(QString FileFullPath,QString Msg); - //================================= Table ================================= - void ui_tableViews_setUpdatesEnabled(bool isEnabled);// 启用/禁用 文件列表table的UI更新 - void Init_Table();//初始化三个tableview - QStandardItemModel *Table_model_image = new QStandardItemModel(); - QStandardItemModel *Table_model_video = new QStandardItemModel(); - QStandardItemModel *Table_model_gif = new QStandardItemModel(); - //取消指定row的自定义分辨率 - void Table_image_CustRes_Cancel_rowNumInt(int rowNum); - void Table_gif_CustRes_Cancel_rowNumInt(int rowNum); - void Table_video_CustRes_Cancel_rowNumInt(int rowNum); - void Table_ChangeAllStatusToWaiting();//将所有row的状态改为waiting - QMutex QMutex_Table_ChangeAllStatusToWaiting; - void Table_Clear();//清空tableview - //获取下一个row值(用于插入新数据 - int Table_image_get_rowNum(); - int Table_gif_get_rowNum(); - int Table_video_get_rowNum(); - //根据输入的table,返回成对的[完整路径]和[状态]:[fullpath]=status; - QMap Table_Read_status_fullpath(QStandardItemModel *Table_model); - //当前选中的rowNum - int curRow_image = -1; - int curRow_gif = -1; - int curRow_video = -1; - - int Table_Save_Current_Table_Filelist(QString Table_FileList_ini);//保存当前文件列表(包括table - - int Table_Read_Saved_Table_Filelist(QString Table_FileList_ini);//读取保存的文件列表 - - int Table_Save_Current_Table_Filelist_Watchdog(QString Table_FileList_ini);//保存文件列表的看门狗线程,确保文件成功保存 - - bool Table_insert_finished=false; - QMutex mutex_Table_insert_finished;//监管是否完成表格插入的bool值的mutex - - QMutex mutex_Table_insert;//监管表格插入的mutex - //================================= Waifu2x ==================================== - void ShowFileProcessSummary();//展示文件处理总结报告 - QString OutPutFolder_main="";//总输出文件夹 - int Waifu2xMainThread();//waifu2x总线程,负责读取文件列表,调度waifu2x放大线程 - QStringList WaitForEngineIO(QStringList OutPutFilesFullPathList); - QStringList WaitForEngineIO_NcnnVulkan(QString OutputFolderFullPath); - void Restore_SplitFramesFolderPath(QString SplitFramesFolderPath, QStringList GPU_SplitFramesFolderPath_List); - bool isForceRetryEnabled=true; - //bool KILL_TASK_(QString TaskName,bool RequestAdmin); - bool KILL_TASK_QStringList(QStringList TaskNameList,bool RequestAdmin); - //========================== - QString Waifu2x_ncnn_vulkan_FolderPath = ""; - QString Waifu2x_ncnn_vulkan_ProgramPath = ""; - //=== - int Waifu2x_NCNN_Vulkan_Image(int rowNum,bool ReProcess_MissingAlphaChannel);//vulkan放大图片线程 - //vulakn放大GIF线程:1.主线程,拆分,调度放大子线程,组装&压缩;2.放大子线程,负责放大所有帧以及调整大小 - int Waifu2x_NCNN_Vulkan_GIF(int rowNum); - //vulkan放大视频线程:1.主线程,拆分,调度放大子线程,组装;2.放大子线程,负责放大所有帧以及调整大小 - int Waifu2x_NCNN_Vulkan_Video(int rowNum); - int Waifu2x_NCNN_Vulkan_Video_BySegment(int rowNum); - QString Waifu2x_NCNN_Vulkan_ReadSettings(); - QString Waifu2x_NCNN_Vulkan_ReadSettings_Video_GIF(int ThreadNum); - //=== - int Realsr_NCNN_Vulkan_Image(int rowNum,bool ReProcess_MissingAlphaChannel);//Realsr放大图片线程 - //Realsr放大GIF线程:1.主线程,拆分,调度放大子线程,组装&压缩;2.放大子线程,负责放大所有帧以及调整大小 - int Realsr_NCNN_Vulkan_GIF(int rowNum); - //Realsr放大视频线程:1.主线程,拆分,调度放大子线程,组装;2.放大子线程,负责放大所有帧以及调整大小 - int Realsr_NCNN_Vulkan_Video(int rowNum); - int Realsr_NCNN_Vulkan_Video_BySegment(int rowNum); - QString Realsr_NCNN_Vulkan_ReadSettings(); - int Calculate_Temporary_ScaleRatio_RealsrNCNNVulkan(int ScaleRatio); - QString Realsr_NCNN_Vulkan_ReadSettings_Video_GIF(int ThreadNum); - //========================= - int Anime4k_Image(int rowNum,bool ReProcess_MissingAlphaChannel); - int Anime4k_GIF(int rowNum); - int Anime4k_GIF_scale(QMap Sub_Thread_info,int *Sub_gif_ThreadNumRunning,bool *Frame_failed); - //Anime4k放大视频线程:1.主线程,拆分,调度放大子线程,组装;2.放大子线程,负责放大所有帧以及调整大小 - int Anime4k_Video(int rowNum); - int Anime4k_Video_BySegment(int rowNum); - int Anime4k_Video_scale(QMap Sub_Thread_info,int *Sub_video_ThreadNumRunning,bool *Frame_failed); - QString Anime4k_ReadSettings(bool PreserveAlphaChannel); - void DenoiseLevelSpinboxSetting_Anime4k(); - QString Anime4k_ProgramPath = Current_Path + "/Anime4K/Anime4K_waifu2xEX.exe"; - int Get_NumOfGPU_Anime4k(); - //================================= - int Waifu2x_Converter_Image(int rowNum,bool ReProcess_MissingAlphaChannel);//Converter放大图片线程 - //Converter放大GIF线程:1.主线程,拆分,调度放大子线程,组装&压缩;2.放大子线程,负责放大所有帧以及调整大小 - int Waifu2x_Converter_GIF(int rowNum); - int Waifu2x_Converter_GIF_scale(QMap Sub_Thread_info,int *Sub_gif_ThreadNumRunning,bool *Frame_failed); - //Converter放大视频线程:1.主线程,拆分,调度放大子线程,组装;2.放大子线程,负责放大所有帧以及调整大小 - int Waifu2x_Converter_Video(int rowNum); - int Waifu2x_Converter_Video_BySegment(int rowNum); - int Waifu2x_Converter_Video_scale(QMap Sub_Thread_info,int *Sub_video_ThreadNumRunning,bool *Frame_failed); - QString Waifu2xConverter_ReadSettings(); - //=================================== - int SRMD_NCNN_Vulkan_Image(int rowNum,bool ReProcess_MissingAlphaChannel);//SRMD放大图片线程 - //SRMD放大GIF线程:1.主线程,拆分,调度放大子线程,组装&压缩;2.放大子线程,负责放大所有帧以及调整大小 - int SRMD_NCNN_Vulkan_GIF(int rowNum); - //SRMD放大视频线程:1.主线程,拆分,调度放大子线程,组装;2.放大子线程,负责放大所有帧以及调整大小 - int SRMD_NCNN_Vulkan_Video(int rowNum); - int SRMD_NCNN_Vulkan_Video_BySegment(int rowNum); - QString SrmdNcnnVulkan_ReadSettings(); - QMap Calculate_ScaleRatio_SrmdNcnnVulkan(int ScaleRatio); - QString SrmdNcnnVulkan_ReadSettings_Video_GIF(int ThreadNum); - //================================= - int Waifu2x_Caffe_Image(int rowNum,bool ReProcess_MissingAlphaChannel);//Caffe放大图片线程 - //Caffe放大GIF线程:1.主线程,拆分,调度放大子线程,组装&压缩;2.放大子线程,负责放大所有帧以及调整大小 - int Waifu2x_Caffe_GIF(int rowNum); - int Waifu2x_Caffe_GIF_scale(QMap Sub_Thread_info,int *Sub_gif_ThreadNumRunning,bool *Frame_failed); - //Caffe放大视频线程:1.主线程,拆分,调度放大子线程,组装;2.放大子线程,负责放大所有帧以及调整大小 - int Waifu2x_Caffe_Video(int rowNum); - int Waifu2x_Caffe_Video_BySegment(int rowNum); - int Waifu2x_Caffe_Video_scale(QMap Sub_Thread_info,int *Sub_video_ThreadNumRunning,bool *Frame_failed); - QString Waifu2x_Caffe_ReadSettings(); - bool isWaifu2xCaffeEnabled(); - void DeleteErrorLog_Waifu2xCaffe(); - //==================================== - int SRMD_CUDA_Image(int rowNum,bool ReProcess_MissingAlphaChannel);//SRMD放大图片线程 - //SRMD放大GIF线程:1.主线程,拆分,调度放大子线程,组装&压缩;2.放大子线程,负责放大所有帧以及调整大小 - int SRMD_CUDA_GIF(int rowNum); - //SRMD放大视频线程:1.主线程,拆分,调度放大子线程,组装;2.放大子线程,负责放大所有帧以及调整大小 - int SRMD_CUDA_Video(int rowNum); - int SRMD_CUDA_Video_BySegment(int rowNum); - //==================================== - - void Wait_waifu2x_stop();//等待waifu2x主线程完全停止所有子线程的看门狗线程 - bool waifu2x_STOP = false;//负责通知waifu2x主线程及其子线程的停止信号 - bool waifu2x_STOP_confirm = false;//返回给waifu2x停止看门狗的信号 - - int ThreadNumMax = 0;//waifu2x放大线程最大值 - int ThreadNumRunning = 0;//正在运行的waifu2x线程数量 - - QMutex mutex_ThreadNumRunning;//监管总线程数量的mutex - QMutex mutex_SubThreadNumRunning;//监管内部线程数量的mutex - - int Waifu2x_DetectGPU();//检测可用gpu(for vulkan) - QStringList Available_GPUID;//可用GPU ID列表 - - int Waifu2x_DumpProcessorList_converter(); - int Core_num = 0; - QStringList Available_ProcessorList_converter; - QString Processor_converter_STR=""; - - int SRMD_DetectGPU();//检测可用gpu(for srmd) - QStringList Available_GPUID_srmd;//可用GPU ID列表 - QString GPU_ID_STR_SRMD="";//向srmd命令行cmd插入的gpuid命令,如果auto则为空 - - int Realsr_ncnn_vulkan_DetectGPU();//检测可用gpu(for realsr) - QStringList Available_GPUID_Realsr_ncnn_vulkan;//可用GPU ID列表 - - void ListGPUs_Anime4k();//列出可用显卡 Anime4k - - int FrameInterpolation_DetectGPU();//检测可用gpu(for vulkan) - QStringList Available_GPUID_FrameInterpolation;//可用GPU ID列表 - //======================== 图片处理 ================================ - bool Image_Gif_AutoSkip_CustRes(int rowNum,bool isGif); - QMap Image_Gif_Read_Resolution(QString SourceFileFullPath);//获取图片&GIF分辨率 - bool Imgae_hasAlphaChannel(int rowNum); - QString Imgae_PreProcess(QString ImagePath,bool ReProcess_AlphaChannel); - QString SaveImageAs_FormatAndQuality(QString OriginalSourceImage_fullPath,QString ScaledImage_fullPath,bool isDenoiseLevelEnabled,int DenoiseLevel); - //================================================================ - int Waifu2x_Compatibility_Test();//引擎兼容性检测 - //初始化 -兼容性测试进度条 - void Init_progressBar_CompatibilityTest(); - //兼容性测试完成后的操作 -兼容性测试进度条 - void Finish_progressBar_CompatibilityTest(); - //兼容性检测 - bool isCompatible_Waifu2x_NCNN_Vulkan_OLD=false; - bool isCompatible_Waifu2x_NCNN_Vulkan_NEW=false; - bool isCompatible_Waifu2x_NCNN_Vulkan_NEW_FP16P=false; - bool isCompatible_SRMD_NCNN_Vulkan=false; - bool isCompatible_SRMD_CUDA=false; - bool isCompatible_Waifu2x_Converter=false; - bool isCompatible_Anime4k_CPU=false; - bool isCompatible_Anime4k_GPU=false; - bool isCompatible_FFmpeg=false; - bool isCompatible_FFprobe=false; - bool isCompatible_ImageMagick=false; - bool isCompatible_Gifsicle=false; - bool isCompatible_SoX=false; - bool isCompatible_Waifu2x_Caffe_CPU=false; - bool isCompatible_Waifu2x_Caffe_GPU=false; - bool isCompatible_Waifu2x_Caffe_cuDNN=false; - bool isCompatible_Realsr_NCNN_Vulkan=false; - bool isCompatible_RifeNcnnVulkan=false; - bool isCompatible_CainNcnnVulkan=false; - bool isCompatible_DainNcnnVulkan=false; - //============================== 多显卡 ========================================== - //waifu2x-ncnn-vulkan - int GPU_ID_Waifu2x_NCNN_Vulkan_MultiGPU = 0; - QMap Waifu2x_NCNN_Vulkan_MultiGPU(); - QMutex MultiGPU_QMutex_Waifu2xNCNNVulkan; - QList> GPUIDs_List_MultiGPU_Waifu2xNCNNVulkan; - void AddGPU_MultiGPU_Waifu2xNCNNVulkan(QString GPUID); - - //SRMD-ncnn-vulkan - int GPU_ID_SrmdNcnnVulkan_MultiGPU = 0; - QMap SrmdNcnnVulkan_MultiGPU(); - QMutex MultiGPU_QMutex_SrmdNcnnVulkan; - QList> GPUIDs_List_MultiGPU_SrmdNcnnVulkan; - void AddGPU_MultiGPU_SrmdNcnnVulkan(QString GPUID); - - //RealsrNcnnVulkan - int GPU_ID_RealsrNcnnVulkan_MultiGPU = 0; - QMap RealsrNcnnVulkan_MultiGPU(); - QMutex MultiGPU_QMutex_RealsrNcnnVulkan; - QList> GPUIDs_List_MultiGPU_RealsrNcnnVulkan; - void AddGPU_MultiGPU_RealsrNcnnVulkan(QString GPUID); - - //Waifu2xConverter - int GPU_ID_Waifu2xConverter_MultiGPU = 0; - QMap Waifu2xConverter_MultiGPU(); - QMutex MultiGPU_QMutex_Waifu2xConverter; - QList> GPUIDs_List_MultiGPU_Waifu2xConverter; - void AddGPU_MultiGPU_Waifu2xConverter(QString GPUID); - - //Anime4k - int GPU_ID_Anime4k_GetGPUInfo = 0; - QString Anime4k_GetGPUInfo(); - QMutex GetGPUInfo_QMutex_Anime4k; - - //Waifu2x-caffe - int GPU_ID_Waifu2xCaffe_GetGPUInfo = 0; - QString Waifu2xCaffe_GetGPUInfo(); - QMutex GetGPUInfo_QMutex_Waifu2xCaffe; - int Get_NumOfGPU_W2xCaffe(); - //================================ progressbar =================================== - int Progressbar_MaxVal = 0;//进度条最大值 - int Progressbar_CurrentVal = 0;//进度条当前值 - void progressbar_clear();//清空进度条 - void progressbar_SetToMax(int maxval);//将进度条设定到最大值 - //=============================== textbrowser=============================== - void TextBrowser_StartMes();//输出启动信息 - //================================ gif ==================================== - void Gif_RemoveFromCustResList(int RowNumber); - bool Gif_DoubleScaleRatioPrep(int RowNumber); - int Gif_getDuration(QString gifPath);//获取帧间隔时长 - int Gif_getFrameDigits(QString gifPath);//获取帧数量的位数 - void Gif_splitGif(QString gifPath,QString SplitFramesFolderPath);//拆分gif - void Gif_assembleGif(QString ResGifPath,QString ScaledFramesPath,int Duration,bool CustRes_isEnabled,int CustRes_height,int CustRes_width,bool isOverScaled,QString SourceGifFullPath);//组装gif - QString Gif_compressGif(QString gifPath,QString gifPath_compressd);//压缩gif - //================================= video =============================== - void video_RemoveFromCustResList(int RowNumber); - bool video_DoubleScaleRatioPrep(int RowNumber); - QString isPreVFIDone_MarkFilePath(QString VideoPath); - int CalNumDigits(int input_num); - bool isSuccessiveFailuresDetected_VFI=false; - int FrameInterpolation_Video_BySegment(int rowNum); - int FrameInterpolation_Video(int rowNum); - int Old_FrameInterpolation_Engine_Index=0; - QString FrameInterpolation_ReadConfig(bool isUhdInput,int NumOfFrames); - bool FrameInterpolation(QString SourcePath,QString OutputPath); - bool Video_AutoSkip_CustRes(int rowNum); - QMap video_get_Resolution(QString VideoFileFullPath);//获取视频的帧率 - QString video_get_fps(QString videoPath);//获取视频fps - int video_get_frameNumDigits(QString videoPath);//获取帧数量的位数 - int video_get_frameNum(QString videoPath);//获取帧数量 - - //判断视频是否可变帧率 - bool video_isVFR(QString videoPath); - //拆分视频 - void video_video2images(QString VideoPath,QString FrameFolderPath,QString AudioPath); - //组装视频 - int video_images2video(QString VideoPath,QString video_mp4_scaled_fullpath,QString ScaledFrameFolderPath,QString AudioPath,bool CustRes_isEnabled,int CustRes_height,int CustRes_width,bool isOverScaled); - //读取输出视频的设定参数 - QString video_ReadSettings_OutputVid(QString AudioPath); - //获取视频比特率 - QString video_get_bitrate(QString videoPath,bool isReturnFullCMD,bool isVidOnly); - //获取视频比特率(根据分辨率计算) - QString video_get_bitrate_AccordingToRes_FrameFolder(QString ScaledFrameFolderPath,QString VideoPath); - int video_UseRes2CalculateBitrate(QString VideoFileFullPath);//根据视频的分辨率计算他应该被分配的比特率 - //音频降噪 - QString video_AudioDenoise(QString OriginalAudioPath); - //获取时长(秒) - int video_get_duration(QString videoPath); - //转换为mp4 - QString video_To_CFRMp4(QString VideoPath); - //提取音频 - void video_get_audio(QString VideoPath,QString AudioPath); - //拆分视频(分段) - void video_video2images_ProcessBySegment(QString VideoPath,QString FrameFolderPath,int StartTime,int SegmentDuration); - //组装视频(mp4片段到成片) - void video_AssembleVideoClips(QString VideoClipsFolderPath,QString VideoClipsFolderName,QString video_mp4_scaled_fullpath,QString AudioPath); - //生成视频片段文件夹编号 - QString video_getClipsFolderNo(); - QMutex MultiLine_ErrorOutput_QMutex; - - bool video_isNeedProcessBySegment(int rowNum);//根据视频时长,判断是否需要分段处理 - void DelVfiDir(QString VideoPath); - //============================ custom res ==================================== - //自定义分辨率列表 - QList> Custom_resolution_list;//res_map["fullpath"],["height"],["width"] - void CustRes_remove(QString fullpath);//根据完整路径,移除自定义分辨率内条目 - bool CustRes_isContained(QString fullpath);//检查是否包括某文件 - QMap CustRes_getResMap(QString fullpath);//读取指定文件的自定义分辨率值 - int CustRes_CalNewScaleRatio(QString fullpath,int Height_new,int width_new);//计算新的放大倍数 - int CustRes_SetCustRes();//设定自定义分辨率 - int CustRes_CancelCustRes();//取消自定义分辨率 - QMap DoubleScaleRatio_Cal_NewScaleRatio_NewHW(QString fullpath,double ScaleRatio_double); - - Qt::AspectRatioMode CustRes_AspectRatioMode = Qt::IgnoreAspectRatio;//自定义分辨率的纵横比策略 - //======================== 设置 =========================================== - int Settings_Read_Apply();//读取与apply设置 - bool Settings_isReseted = false;//是否重置设置标记 - QVariant Settings_Read_value(QString Key); - bool isReadOldSettings = false; - //================================ Other ======================================= - bool isCustomVideoSettingsClicked=true; - - void pushButton_Start_setEnabled_self(bool isEnabled); - void pushButton_Stop_setEnabled_self(bool isEnabled); - - void TurnOffScreen(); - QFuture TurnOffScreen_QF;//监视是否连续多次点击关闭屏幕,避免连续启动nircmd - - bool FileProgressWatch_isEnabled = true;//是否启用输出文件夹进度监控线程 - - int ForceRetryCount = 1; - - void OutputSettingsArea_setEnabled(bool isEnabled); - - bool isFirstTimeStart=false; - - bool isForceRetryClicked=false; - QMutex isForceRetryClicked_QMutex; - void DelTrash_ForceRetry_Anime4k(QString OutPut_Path); - void isForceRetryClicked_SetTrue_Block_Anime4k(); - - void AutoFinishAction_Message(); - int SystemShutDown_Countdown();//自动关机倒计时 - int SystemShutDown_isAutoShutDown();//判断之前是否执行过自动关机 - //阻塞延时(安全 - void Delay_sec_sleep(int time); - void Delay_msec_sleep(int time); - - void Play_NFSound();//播放提示音 - - QTimer *TimeCostTimer;//计算耗时的timer - long unsigned int TimeCost = 0;//已消耗时间 - QString Seconds2hms(long unsigned int seconds);//秒 转 时:分:秒 - long unsigned int TaskNumTotal=0;//总任务数量(需要处理的文件) - long unsigned int TaskNumFinished=0;//处理完的文件数量 - bool NewTaskFinished=false;//新任务被完成之标记 - long unsigned int ETA=0;//ETA时间(s) - - int CheckUpadte_Auto();//自动检查更新 - - int Donate_DownloadOnlineQRCode(); - - bool isSettingsHide=false;//是否隐藏主页的设置groupbox - - bool isShowAnime4kWarning=true; - - void ConnectivityTest_RawGithubusercontentCom();//检查是否可以连接github - bool isConnectivityTest_RawGithubusercontentCom_Running=false; - QMutex QMutex_ConnectivityTest_RawGithubusercontentCom; - - bool DownloadTo(QString OnlineLink,QString LocalPath); - //=========== 关闭窗口时执行的代码 =============== - void closeEvent(QCloseEvent* event);//关闭事件 - //void Close_self();//包含所有关闭时执行的代码 - bool QProcess_stop=false;//所有QProcess停止标记 - int Auto_Save_Settings_Watchdog(bool isWaitForSave);//自动保存设置的看门狗 - QFuture AutoUpdate;//监视自动检查更新线程 - QFuture DownloadOnlineQRCode;//监视在线下载二维码线程 - QFuture Waifu2xMain;//监视waifu2x主线程 - int Force_close();//调用cmd强制关闭自己 - bool isAlreadyClosed=false; - //================== 处理当前文件的进度 ========================= - long unsigned int TimeCost_CurrentFile =0; - long unsigned int TaskNumTotal_CurrentFile=0; - long unsigned int TaskNumFinished_CurrentFile=0; - bool NewTaskFinished_CurrentFile=false; - long unsigned int ETA_CurrentFile=0; - bool isStart_CurrentFile=false; - //============================================= - void Tip_FirstTimeStart(); - //================== 托盘图标 ================= - void Init_SystemTrayIcon(); - QSystemTrayIcon *systemTray = new QSystemTrayIcon(this); - QMenu *pContextMenu = new QMenu(this); - QAction *minimumAct_SystemTrayIcon = new QAction(this); - QAction *restoreAct_SystemTrayIcon = new QAction(this); - QAction *quitAct_SystemTrayIcon = new QAction(this); - QAction *BackgroundModeAct_SystemTrayIcon = new QAction(this); - QAction *SendFeedback_SystemTrayIcon = new QAction(this); - QAction *About_SystemTrayIcon = new QAction(this); - QAction *Donate_SystemTrayIcon = new QAction(this); - QAction *Pause_SystemTrayIcon = new QAction(this); - QAction *Start_SystemTrayIcon = new QAction(this); - QAction *BecomePatron_SystemTrayIcon = new QAction(this); - QAction *TopSupportersList_SystemTrayIcon = new QAction(this); - //================= 输出路径 lineEdit 的右键菜单 ============== - void Init_ActionsMenu_lineEdit_outputPath(); - QAction *OpenFolder_lineEdit_outputPath = new QAction(this); - //================= 文件列表的右键菜单 ==================== - void Init_ActionsMenu_FilesList(); - QAction *OpenFile_QAction_FileList = new QAction(this); - QAction *OpenFilesFolder_QAction_FileList = new QAction(this); - QAction *RemoveFile_FilesList_QAction_FileList = new QAction(this); - bool EnableApply2All_CustRes=true; - QAction *Apply_CustRes_QAction_FileList = new QAction(this); - QAction *Cancel_CustRes_QAction_FileList = new QAction(this); - void OpenSelectedFile_FailedWarning_FilesList(); - //================ 移除条目 按钮的右键菜单======================= - void Init_ActionsMenu_pushButton_RemoveItem(); - QAction *RemoveALL_image = new QAction(this); - QAction *RemoveALL_gif = new QAction(this); - QAction *RemoveALL_video = new QAction(this); - //=================== 生成bat文件来执行cmd命令 =========== - void ExecuteCMD_batFile(QString cmd_str,bool requestAdmin); - QMutex ExecuteCMD_batFile_QMutex; - void Del_TempBatFile(); - //===================================================== - void comboBox_UpdateChannel_setCurrentIndex_self(int index); - QMutex comboBox_UpdateChannel_setCurrentIndex_self_QMutex; - bool isClicked_comboBox_UpdateChannel=true; - //===================== 直接替换源文件 ===================== - void checkBox_ReplaceOriginalFile_setEnabled_True_Self(); - bool ReplaceOriginalFile(QString original_fullpath,QString output_fullpath); - void Init_ActionsMenu_checkBox_ReplaceOriginalFile();//替换源文件 的右键菜单 - QAction *QAction_checkBox_MoveToRecycleBin_checkBox_ReplaceOriginalFile = new QAction(this); - //===================== 删除原文件的右键菜单 =========================== - void Init_ActionsMenu_checkBox_DelOriginal();//替换源文件 的右键菜单 - QAction *QAction_checkBox_MoveToRecycleBin_checkBox_DelOriginal = new QAction(this); - //===================== 事件过滤器 ===================== - bool eventFilter(QObject *target, QEvent *event); - //===================== 块大小调整 ====================== - int AddTileSize_NCNNVulkan_Converter(int OrginalTileSize); - int MinusTileSize_NCNNVulkan_Converter(int OrginalTileSize); - //==================== 预读取引擎设定 ================== - void PreLoad_Engines_Settings(); - //=== - QString Waifu2x_NCNN_Vulkan_PreLoad_Settings(); - QString Waifu2x_NCNN_Vulkan_PreLoad_Settings_Str = ""; - //=== - QString SrmdNcnnVulkan_PreLoad_Settings(); - QString SrmdNcnnVulkan_PreLoad_Settings_Str = ""; - //=== - QString Realsr_NCNN_Vulkan_PreLoad_Settings(); - QString Realsr_NCNN_Vulkan_PreLoad_Settings_Str = ""; - //=== - QString Waifu2xCaffe_PreLoad_Settings(); - QString Waifu2xCaffe_PreLoad_Settings_Str = ""; - //=== - QString Waifu2xConverter_PreLoad_Settings(); - QString Waifu2xConverter_PreLoad_Settings_Str = ""; - //=== - QString Anime4k_PreLoad_Settings(); - QString Anime4k_PreLoad_Settings_Str = ""; - QString HDNDenoiseLevel_image = ""; - QString HDNDenoiseLevel_gif = ""; - QString HDNDenoiseLevel_video = ""; - //================== 计算临时放大倍率 ==================== - int Calculate_Temporary_ScaleRatio_W2xNCNNVulkan(int ScaleRatio); - //================== 多线程调整图片大小 ========================= - void ImagesResize_Folder_MultiThread(int New_width,int New_height,QString ImagesFolderPath); - int TotalNumOfThreads_ImagesResize_Folder_MultiThread; - int RunningNumOfThreads_ImagesResize_Folder_MultiThread; - QMutex QMutex_ResizeImage_MultiThread; - void ResizeImage_MultiThread(int New_width,int New_height,QString ImagesPath); - //================== 处理APNG ================= - void APNG_Main(int rowNum,bool isFromImageList); - void APNG_Split2Frames(QString sourceFileFullPath,QString splitFramesFolder); - void APNG_Frames2APNG(QString sourceFileFullPath,QString scaledFramesFolder,QString resultFileFullPath,bool isOverScaled); - bool APNG_isAnimatedPNG(int rowNum); - //Waifu2x-NCNN-Vulkan - bool APNG_Waifu2xNCNNVulkan(QString splitFramesFolder,QString scaledFramesFolder,QString sourceFileFullPath,QStringList framesFileName_qStrList,QString resultFileFullPath); - //Waifu2x-Converter - bool APNG_Waifu2xConverter(QString splitFramesFolder,QString scaledFramesFolder,QString sourceFileFullPath,QStringList framesFileName_qStrList,QString resultFileFullPath); - int Waifu2x_Converter_APNG_scale(QMap Sub_Thread_info,int *Sub_gif_ThreadNumRunning,bool *Frame_failed); - //Srmd-NCNN-Vulkan - bool APNG_SrmdNCNNVulkan(QString splitFramesFolder,QString scaledFramesFolder,QString sourceFileFullPath,QStringList framesFileName_qStrList,QString resultFileFullPath); - //Anime4k - bool APNG_Anime4k(QString splitFramesFolder,QString scaledFramesFolder,QString sourceFileFullPath,QStringList framesFileName_qStrList,QString resultFileFullPath); - int Anime4k_APNG_scale(QMap Sub_Thread_info,int *Sub_gif_ThreadNumRunning,bool *Frame_failed); - //Srmd-CUDA - bool APNG_SrmdCUDA(QString splitFramesFolder,QString scaledFramesFolder,QString sourceFileFullPath,QStringList framesFileName_qStrList,QString resultFileFullPath); - //waifu2x-caffe - bool APNG_Waifu2xCaffe(QString splitFramesFolder,QString scaledFramesFolder,QString sourceFileFullPath,QStringList framesFileName_qStrList,QString resultFileFullPath); - int Waifu2x_Caffe_APNG_scale(QMap Sub_Thread_info,int *Sub_gif_ThreadNumRunning,bool *Frame_failed); - //Realsr-NCNN-Vulkan - bool APNG_RealsrNCNNVulkan(QString splitFramesFolder,QString scaledFramesFolder,QString sourceFileFullPath,QStringList framesFileName_qStrList,QString resultFileFullPath); - //============= - ~MainWindow(); - -public slots: - void Table_EnableSorting(bool EnableSorting); - - void Apply_CustRes_QAction_FileList_slot(); - void Cancel_CustRes_QAction_FileList_slot(); - - void RemoveALL_image_slot(); - void RemoveALL_gif_slot(); - void RemoveALL_video_slot(); - - void Add_progressBar_CompatibilityTest();//进度+1 -兼容性测试进度条 - - void OpenSelectedFilesFolder_FilesList(); - void OpenSelectedFile_FilesList(); - - void OpenOutputFolder(); - - void Unable2Connect_RawGithubusercontentCom(); - - void SetEnable_pushButton_ForceRetry_self(); - - void SystemTray_hide_self(); - void SystemTray_showNormal_self(); - void SystemTray_showDonate(); - - void SystemTray_NewMessage(QString message); - void EnableBackgroundMode_SystemTray(); - void on_activatedSysTrayIcon(QSystemTrayIcon::ActivationReason reason); - - void progressbar_setRange_min_max(int min, int max);//进度条设定min和max - void progressbar_Add();//进度条进度+1 - - //根据row修改指定row的状态 - void Table_image_ChangeStatus_rowNumInt_statusQString(int rowNum, QString status); - void Table_gif_ChangeStatus_rowNumInt_statusQString(int rowNum, QString status); - void Table_video_ChangeStatus_rowNumInt_statusQString(int rowNum, QString status); - - void Waifu2x_Finished();//自动结束时调用的代码(会自动接着调用manual - void Waifu2x_Finished_manual();//手动停止后调用的结束代码 - - void TextBrowser_NewMessage(QString message);//Textbrowser发送新消息"[时间] 消息" - - void TimeSlot();//计时槽函数 - - int Waifu2x_Compatibility_Test_finished();//兼容性检测结束后执行的槽函数 - - int Waifu2x_DetectGPU_finished();//检测可用gpu结束后的执行的槽函数 - - int Realsr_ncnn_vulkan_DetectGPU_finished();//检测可用gpu结束后的执行的槽函数 - - int FrameInterpolation_DetectGPU_finished(); - - int CheckUpadte_NewUpdate(QString update_str,QString Change_log);//检测到更新的弹窗代码 - - void FinishedProcessing_DN(); - - int Table_FileCount_reload();//重载table下的文件数量计数 - - //向table插入文件名和fullpath - void Table_image_insert_fileName_fullPath(QString fileName, QString SourceFile_fullPath); - void Table_gif_insert_fileName_fullPath(QString fileName, QString SourceFile_fullPath); - void Table_video_insert_fileName_fullPath(QString fileName, QString SourceFile_fullPath); - - //向table插入自定义分辨率值 - void Table_image_CustRes_rowNumInt_HeightQString_WidthQString(int rowNum, QString height, QString width); - void Table_gif_CustRes_rowNumInt_HeightQString_WidthQString(int rowNum, QString height, QString width); - void Table_video_CustRes_rowNumInt_HeightQString_WidthQString(int rowNum, QString height, QString width); - - //读取&保存文件列表与table后执行的代码 - int Table_Read_Saved_Table_Filelist_Finished(QString Table_FileList_ini); - int Table_Save_Current_Table_Filelist_Finished(); - - void on_pushButton_ClearList_clicked();//清空列表 - - bool SystemShutDown();//关机 - - int Waifu2x_DumpProcessorList_converter_finished(); - - void Read_urls_finfished(); - - void SRMD_DetectGPU_finished(); - - void video_write_VideoConfiguration(QString VideoConfiguration_fullPath,int ScaleRatio,int DenoiseLevel,bool CustRes_isEnabled,int CustRes_height,int CustRes_width,QString EngineName,bool isProcessBySegment,QString VideoClipsFolderPath,QString VideoClipsFolderName,bool isVideoFrameInterpolationEnabled,int MultipleOfFPS); - - int Settings_Save();//保存设置 - - //存储进度 - void video_write_Progress_ProcessBySegment(QString VideoConfiguration_fullPath,int StartTime,bool isSplitComplete,bool isScaleComplete,int OLDSegmentDuration,int LastVideoClipNo); - - //================== 处理当前文件的进度 ========================= - void CurrentFileProgress_Start(QString FileName,int FrameNum); - void CurrentFileProgress_Stop(); - void CurrentFileProgress_progressbar_Add(); - void CurrentFileProgress_progressbar_Add_SegmentDuration(int SegmentDuration); - void CurrentFileProgress_progressbar_SetFinishedValue(int FinishedValue); - void CurrentFileProgress_WatchFolderFileNum(QString FolderPath); - void CurrentFileProgress_WatchFolderFileNum_Textbrower(QString SourceFile_fullPath,QString FolderPath,int TotalFileNum); - - void Donate_ReplaceQRCode(QString QRCodePath); - - void Set_checkBox_DisableResize_gif_Checked(); - -private slots: - void on_pushButton_Start_clicked(); - - void on_pushButton_Stop_clicked(); - - int on_pushButton_RemoveItem_clicked(); - - void on_pushButton_CheckUpdate_clicked(); - - void on_pushButton_Report_clicked(); - - void on_pushButton_ReadMe_clicked(); - - void on_comboBox_Engine_Image_currentIndexChanged(int index); - - void on_comboBox_Engine_GIF_currentIndexChanged(int index); - - void on_comboBox_Engine_Video_currentIndexChanged(int index); - - void on_pushButton_clear_textbrowser_clicked(); - - void on_spinBox_textbrowser_fontsize_valueChanged(int arg1); - - void on_pushButton_compatibilityTest_clicked(); - - void on_pushButton_CustRes_apply_clicked(); - - void on_pushButton_CustRes_cancel_clicked(); - - void on_pushButton_HideSettings_clicked(); - - void on_pushButton_DetectGPU_clicked(); - - void on_pushButton_SaveSettings_clicked(); - - void on_pushButton_ResetSettings_clicked(); - - void on_comboBox_language_currentIndexChanged(int index); - - void on_pushButton_SaveFileList_clicked(); - - void on_pushButton_ReadFileList_clicked(); - - void on_Ext_image_editingFinished(); - - void on_Ext_video_editingFinished(); - - void on_checkBox_AutoSaveSettings_clicked(); - - void on_pushButton_about_clicked(); - - void on_comboBox_AspectRatio_custRes_currentIndexChanged(int index); - - void on_checkBox_AlwaysHideSettings_stateChanged(int arg1); - - void on_pushButton_Save_GlobalFontSize_clicked(); - - void on_pushButton_BrowserFile_clicked(); - - void on_pushButton_wiki_clicked(); - - void on_pushButton_HideTextBro_clicked(); - - void on_checkBox_AlwaysHideTextBrowser_stateChanged(int arg1); - - void on_pushButton_DumpProcessorList_converter_clicked(); - - void on_comboBox_TargetProcessor_converter_currentIndexChanged(int index); - - void on_Ext_image_textChanged(const QString &arg1); - - void on_Ext_video_textChanged(const QString &arg1); - - void on_comboBox_model_vulkan_currentIndexChanged(int index); - - void on_comboBox_ImageStyle_currentIndexChanged(int index); - - void on_pushButton_ResetVideoSettings_clicked(); - - void on_lineEdit_encoder_vid_textChanged(const QString &arg1); - - void on_lineEdit_encoder_audio_textChanged(const QString &arg1); - - void on_lineEdit_pixformat_textChanged(const QString &arg1); - - void on_checkBox_vcodec_copy_2mp4_stateChanged(int arg1); - - void on_checkBox_acodec_copy_2mp4_stateChanged(int arg1); - - void on_pushButton_encodersList_clicked(); - - void on_checkBox_DelOriginal_stateChanged(int arg1); - - void on_checkBox_FileList_Interactive_stateChanged(int arg1); - - void on_checkBox_OutPath_isEnabled_stateChanged(int arg1); - - void on_pushButton_ForceRetry_clicked(); - - void on_pushButton_PayPal_clicked(); - - void on_pushButton_DetectGPUID_srmd_clicked(); - - void on_checkBox_AudioDenoise_stateChanged(int arg1); - - void on_tabWidget_currentChanged(int index); - - void on_checkBox_ProcessVideoBySegment_stateChanged(int arg1); - - void on_comboBox_version_Waifu2xNCNNVulkan_currentIndexChanged(int index); - - void on_checkBox_EnablePreProcessing_Anime4k_stateChanged(int arg1); - - void on_checkBox_EnablePostProcessing_Anime4k_stateChanged(int arg1); - - void on_checkBox_isCompatible_Waifu2x_NCNN_Vulkan_NEW_clicked(); - - void on_checkBox_isCompatible_Waifu2x_NCNN_Vulkan_NEW_FP16P_clicked(); - - void on_checkBox_isCompatible_Waifu2x_NCNN_Vulkan_OLD_clicked(); - - void on_checkBox_isCompatible_SRMD_NCNN_Vulkan_clicked(); - - void on_checkBox_isCompatible_Waifu2x_Converter_clicked(); - - void on_checkBox_isCompatible_Anime4k_CPU_clicked(); - - void on_checkBox_isCompatible_Anime4k_GPU_clicked(); - - void on_checkBox_SpecifyGPU_Anime4k_stateChanged(int arg1); - - void on_pushButton_ListGPUs_Anime4k_clicked(); - - void on_checkBox_isCompatible_FFmpeg_clicked(); - - void on_checkBox_isCompatible_FFprobe_clicked(); - - void on_checkBox_isCompatible_ImageMagick_clicked(); - - void on_checkBox_isCompatible_Gifsicle_clicked(); - - void on_checkBox_isCompatible_SoX_clicked(); - - void on_checkBox_GPUMode_Anime4K_stateChanged(int arg1); - - void on_checkBox_ShowInterPro_stateChanged(int arg1); - - void on_checkBox_isCompatible_Waifu2x_Caffe_CPU_clicked(); - - void on_checkBox_isCompatible_Waifu2x_Caffe_GPU_clicked(); - - void on_checkBox_isCompatible_Waifu2x_Caffe_cuDNN_clicked(); - - void on_pushButton_SplitSize_Add_Waifu2xCaffe_clicked(); - - void on_pushButton_SplitSize_Minus_Waifu2xCaffe_clicked(); - - void on_checkBox_isCompatible_Realsr_NCNN_Vulkan_clicked(); - - void on_pushButton_DetectGPU_RealsrNCNNVulkan_clicked(); - - void on_checkBox_ACNet_Anime4K_stateChanged(int arg1); - - void on_checkBox_MultiGPU_Waifu2xNCNNVulkan_clicked(); - - void on_comboBox_GPUIDs_MultiGPU_Waifu2xNCNNVulkan_currentIndexChanged(int index); - - void on_spinBox_TileSize_CurrentGPU_MultiGPU_Waifu2xNCNNVulkan_valueChanged(int arg1); - - void on_checkBox_isEnable_CurrentGPU_MultiGPU_Waifu2xNCNNVulkan_clicked(); - - void on_checkBox_MultiGPU_Waifu2xNCNNVulkan_stateChanged(int arg1); - - void on_checkBox_MultiGPU_SrmdNCNNVulkan_stateChanged(int arg1); - - void on_checkBox_MultiGPU_SrmdNCNNVulkan_clicked(); - - void on_comboBox_GPUIDs_MultiGPU_SrmdNCNNVulkan_currentIndexChanged(int index); - - void on_checkBox_isEnable_CurrentGPU_MultiGPU_SrmdNCNNVulkan_clicked(); - - void on_spinBox_TileSize_CurrentGPU_MultiGPU_SrmdNCNNVulkan_valueChanged(int arg1); - - void on_checkBox_MultiGPU_RealsrNcnnVulkan_stateChanged(int arg1); - - void on_checkBox_MultiGPU_RealsrNcnnVulkan_clicked(); - - void on_comboBox_GPUIDs_MultiGPU_RealsrNcnnVulkan_currentIndexChanged(int index); - - void on_checkBox_isEnable_CurrentGPU_MultiGPU_RealsrNcnnVulkan_clicked(); - - void on_spinBox_TileSize_CurrentGPU_MultiGPU_RealsrNcnnVulkan_valueChanged(int arg1); - - void on_checkBox_MultiGPU_Waifu2xConverter_clicked(); - - void on_checkBox_MultiGPU_Waifu2xConverter_stateChanged(int arg1); - - void on_comboBox_GPUIDs_MultiGPU_Waifu2xConverter_currentIndexChanged(int index); - - void on_checkBox_isEnable_CurrentGPU_MultiGPU_Waifu2xConverter_clicked(); - - void on_spinBox_TileSize_CurrentGPU_MultiGPU_Waifu2xConverter_valueChanged(int arg1); - - void on_checkBox_EnableMultiGPU_Waifu2xCaffe_stateChanged(int arg1); - - void on_comboBox_ProcessMode_Waifu2xCaffe_currentIndexChanged(int index); - - void on_lineEdit_GPUs_Anime4k_editingFinished(); - - void on_lineEdit_MultiGPUInfo_Waifu2xCaffe_editingFinished(); - - void on_pushButton_VerifyGPUsConfig_Anime4k_clicked(); - - void on_pushButton_VerifyGPUsConfig_Waifu2xCaffe_clicked(); - - void on_tableView_image_doubleClicked(const QModelIndex &index); - - void on_tableView_gif_doubleClicked(const QModelIndex &index); - - void on_tableView_video_doubleClicked(const QModelIndex &index); - - void on_checkBox_BanGitee_clicked(); - - void on_pushButton_ShowMultiGPUSettings_Waifu2xNCNNVulkan_clicked(); - - void on_pushButton_ShowMultiGPUSettings_Waifu2xConverter_clicked(); - - void on_pushButton_ShowMultiGPUSettings_SrmdNCNNVulkan_clicked(); - - void on_pushButton_ShowMultiGPUSettings_RealsrNcnnVulkan_clicked(); - - void on_checkBox_HDNMode_Anime4k_stateChanged(int arg1); - - void on_tableView_image_pressed(const QModelIndex &index); - - void on_tableView_gif_pressed(const QModelIndex &index); - - void on_tableView_video_pressed(const QModelIndex &index); - - void on_comboBox_UpdateChannel_currentIndexChanged(int index); - - void on_checkBox_ReplaceOriginalFile_stateChanged(int arg1); - - void on_checkBox_isCustFontEnable_stateChanged(int arg1); - - void on_comboBox_ImageSaveFormat_currentIndexChanged(int index); - - void on_pushButton_ResizeFilesListSplitter_clicked(); - - void on_pushButton_TileSize_Add_W2xNCNNVulkan_clicked(); - - void on_pushButton_TileSize_Minus_W2xNCNNVulkan_clicked(); - - void on_pushButton_BlockSize_Add_W2xConverter_clicked(); - - void on_pushButton_BlockSize_Minus_W2xConverter_clicked(); - - void on_pushButton_Add_TileSize_SrmdNCNNVulkan_clicked(); - - void on_pushButton_Minus_TileSize_SrmdNCNNVulkan_clicked(); - - void on_pushButton_Add_TileSize_RealsrNCNNVulkan_clicked(); - - void on_pushButton_Minus_TileSize_RealsrNCNNVulkan_clicked(); - - void on_comboBox_GPGPUModel_A4k_currentIndexChanged(int index); - - void on_checkBox_DisableGPU_converter_stateChanged(int arg1); - - void on_groupBox_video_settings_clicked(); - - void on_pushButton_DetectGPU_VFI_clicked(); - - void on_lineEdit_MultiGPU_IDs_VFI_editingFinished(); - - void on_checkBox_MultiGPU_VFI_stateChanged(int arg1); - - void on_groupBox_FrameInterpolation_clicked(); - - void on_checkBox_isCompatible_RifeNcnnVulkan_clicked(); - - void on_comboBox_Engine_VFI_currentIndexChanged(int index); - - void on_checkBox_isCompatible_CainNcnnVulkan_clicked(); - - void on_pushButton_Verify_MultiGPU_VFI_clicked(); - - void on_checkBox_EnableVFI_Home_clicked(); - - void on_checkBox_MultiThread_VFI_stateChanged(int arg1); - - void on_checkBox_MultiThread_VFI_clicked(); - - void on_pushButton_TurnOffScreen_clicked(); - - void on_checkBox_isCompatible_DainNcnnVulkan_clicked(); - - void on_pushButton_MultipleOfFPS_VFI_MIN_clicked(); - - void on_pushButton_MultipleOfFPS_VFI_ADD_clicked(); - - void on_pushButton_Patreon_clicked(); - - void on_pushButton_SupportersList_clicked(); - - void on_checkBox_isCompatible_SRMD_CUDA_clicked(); - -signals: - void Send_Table_EnableSorting(bool EnableSorting); - - void Send_Add_progressBar_CompatibilityTest();//进度+1 -兼容性测试进度条 - - void Send_Unable2Connect_RawGithubusercontentCom(); - - void Send_SetEnable_pushButton_ForceRetry_self(); - - void Send_SystemTray_NewMessage(QString message); - - void Send_PrograssBar_Range_min_max(int, int); - void Send_progressbar_Add(); - - void Send_Table_image_ChangeStatus_rowNumInt_statusQString(int, QString); - void Send_Table_gif_ChangeStatus_rowNumInt_statusQString(int, QString); - void Send_Table_video_ChangeStatus_rowNumInt_statusQString(int, QString); - - void Send_Waifu2x_Finished(); - void Send_Waifu2x_Finished_manual(); - - void Send_TextBrowser_NewMessage(QString); - - void Send_Waifu2x_Compatibility_Test_finished(); - - void Send_Waifu2x_DetectGPU_finished(); - - void Send_FinishedProcessing_DN(); - - void Send_Realsr_ncnn_vulkan_DetectGPU_finished(); - void Send_FrameInterpolation_DetectGPU_finished(); - - void Send_CheckUpadte_NewUpdate(QString, QString); - - void Send_Table_FileCount_reload(); - - void Send_Table_image_insert_fileName_fullPath(QString fileName, QString SourceFile_fullPath); - void Send_Table_gif_insert_fileName_fullPath(QString fileName, QString SourceFile_fullPath); - void Send_Table_video_insert_fileName_fullPath(QString fileName, QString SourceFile_fullPath); - - void Send_Table_image_CustRes_rowNumInt_HeightQString_WidthQString(int rowNum, QString height, QString width); - void Send_Table_gif_CustRes_rowNumInt_HeightQString_WidthQString(int rowNum, QString height, QString width); - void Send_Table_video_CustRes_rowNumInt_HeightQString_WidthQString(int rowNum, QString height, QString width); - - void Send_Table_Read_Saved_Table_Filelist_Finished(QString Table_FileList_ini); - void Send_Table_Save_Current_Table_Filelist_Finished(); - - void Send_SystemShutDown(); - - void Send_Waifu2x_DumpProcessorList_converter_finished(); - - void Send_Read_urls_finfished(); - - void Send_SRMD_DetectGPU_finished(); - - void Send_video_write_VideoConfiguration(QString VideoConfiguration_fullPath,int ScaleRatio,int DenoiseLevel,bool CustRes_isEnabled,int CustRes_height,int CustRes_width,QString EngineName,bool isProcessBySegment,QString VideoClipsFolderPath,QString VideoClipsFolderName,bool isVideoFrameInterpolationEnabled,int MultipleOfFPS); - - void Send_Settings_Save(); - - void Send_video_write_Progress_ProcessBySegment(QString VideoConfiguration_fullPath,int StartTime,bool isSplitComplete,bool isScaleComplete,int OLDSegmentDuration,int LastVideoClipNo); - - //================== 处理当前文件的进度 ========================= - void Send_CurrentFileProgress_Start(QString FileName,int FrameNum); - void Send_CurrentFileProgress_Stop(); - void Send_CurrentFileProgress_progressbar_Add(); - void Send_CurrentFileProgress_progressbar_Add_SegmentDuration(int SegmentDuration); - void Send_CurrentFileProgress_progressbar_SetFinishedValue(int FinishedValue); - - void Send_Donate_ReplaceQRCode(QString QRCodePath); - - void Send_Set_checkBox_DisableResize_gif_Checked(); - -private: - Ui::MainWindow *ui; -}; -#endif // MAINWINDOW_H - +/* + Copyright (C) 2021 Aaron Feng + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU Affero General Public License as published + by the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program. If not, see . + + My Github homepage: https://github.com/AaronFeng753 +*/ + +#ifndef MAINWINDOW_H +#define MAINWINDOW_H + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "topsupporterslist.h" + +typedef QList> QList_QMap_QStrQStr; +Q_DECLARE_METATYPE(QList_QMap_QStrQStr) + +QT_BEGIN_NAMESPACE +namespace Ui +{ + class MainWindow; +} +QT_END_NAMESPACE + +class MainWindow : public QMainWindow +{ + Q_OBJECT + +public: + MainWindow(QWidget *parent = nullptr); + void changeEvent(QEvent *e); + //======================= + QString VERSION = "v3.41.02-beta";//软件版本号 + bool isBetaVer = true; + QString LastStableVer = "v3.31.13"; + QString LastBetaVer = "v3.41.02-beta"; + //======================= + QTranslator * translator;//界面翻译 + QIcon *MainIcon_QIcon = new QIcon(":/new/prefix1/icon/icon_main.png"); + TopSupportersList *TopSupportersList_widget; + //======= + QString Current_Path = qApp->applicationDirPath();//当前路径 + //======= + void Set_Font_fixed(); + //================================= File 文件 ================================= + void dragEnterEvent(QDragEnterEvent *event);//拖放文件event + void dropEvent(QDropEvent *event); + void Read_urls(QList urls); + void Read_Input_paths_BrowserFile(QStringList Input_path_List); + bool AddNew_gif=false;//判断是否有新增文件-gif + bool AddNew_image=false;//判断是否有新增文件-图片 + bool AddNew_video=false;//判断是否有新增文件-视频 + void Add_File_Folder(QString Full_Path);//添加文件or文件夹(判断一个路径是文件还是文件夹,然后处理判断类型添加到table和file list) + void Add_File_Folder_IncludeSubFolder(QString Full_Path);//添加文件文件夹(扫描子文件夹 + QStringList getFileNames_IncludeSubFolder(QString path);//读取文件列表, 包括文件夹 + int FileList_Add(QString fileName, QString SourceFile_fullPath);//直接向file list和tableview添加文件 + //判断一个文件是否已存在于一个文件列表中(输入list和完整路径,然后判断返回bool) + bool Deduplicate_filelist(QString SourceFile_fullPath); + bool file_isDirExist(QString SourceFile_fullPath);//判断文件夹是否存在 + void file_mkDir(QString SourceFile_fullPath);//创建文件夹 + bool file_isDirEmpty(QString FolderPath); + QStringList file_getFileNames_in_Folder_nofilter(QString path);//读取文件夹内文件列表并返回(无过滤器) + bool file_DelDir(const QString &path);//删除文件夹(无论是否为空,强制删除) + QString file_getBaseName(QString path);//获取basename + void file_MoveToTrash( QString file );//移动到回收站 + void MoveFileToOutputPath(QString Orginal,QString SourceFilePath);//移动文件 + QMutex MoveFile_QMutex; + QString file_getFolderPath(QFileInfo fileInfo);//获取文件夹路径(去除末尾的"/") + bool file_isDirWritable(QString DirPath);//检查文件夹是否可写入 + //检查当前行的文件所在的文件夹是否可写入 + bool file_isFilesFolderWritable_row_image(int rowNum); + bool file_isFilesFolderWritable_row_video(int rowNum); + bool file_isFilesFolderWritable_row_gif(int rowNum); + bool file_OpenFolder(QString FolderPath);//调用系统资源管理器打开文件夹. + bool file_OpenFilesFolder(QString FilePath);//打开文件所在的文件夹 + bool file_OpenFile(QString FilePath); + void file_MoveFiles_Folder_NcnnVulkanFolderProcess(QString Old_folder, QString New_folder, bool Delete_); + bool file_generateMarkFile(QString FileFullPath,QString Msg); + //================================= Table ================================= + void ui_tableViews_setUpdatesEnabled(bool isEnabled);// 启用/禁用 文件列表table的UI更新 + void Init_Table();//初始化三个tableview + QStandardItemModel *Table_model_image = new QStandardItemModel(); + QStandardItemModel *Table_model_video = new QStandardItemModel(); + QStandardItemModel *Table_model_gif = new QStandardItemModel(); + //取消指定row的自定义分辨率 + void Table_image_CustRes_Cancel_rowNumInt(int rowNum); + void Table_gif_CustRes_Cancel_rowNumInt(int rowNum); + void Table_video_CustRes_Cancel_rowNumInt(int rowNum); + void Table_ChangeAllStatusToWaiting();//将所有row的状态改为waiting + QMutex QMutex_Table_ChangeAllStatusToWaiting; + void Table_Clear();//清空tableview + //获取下一个row值(用于插入新数据 + int Table_image_get_rowNum(); + int Table_gif_get_rowNum(); + int Table_video_get_rowNum(); + //根据输入的table,返回成对的[完整路径]和[状态]:[fullpath]=status; + QMap Table_Read_status_fullpath(QStandardItemModel *Table_model); + //当前选中的rowNum + int curRow_image = -1; + int curRow_gif = -1; + int curRow_video = -1; + + int Table_Save_Current_Table_Filelist(QString Table_FileList_ini);//保存当前文件列表(包括table + + int Table_Read_Saved_Table_Filelist(QString Table_FileList_ini);//读取保存的文件列表 + + int Table_Save_Current_Table_Filelist_Watchdog(QString Table_FileList_ini);//保存文件列表的看门狗线程,确保文件成功保存 + + bool Table_insert_finished=false; + QMutex mutex_Table_insert_finished;//监管是否完成表格插入的bool值的mutex + + QMutex mutex_Table_insert;//监管表格插入的mutex + //================================= Waifu2x ==================================== + void ShowFileProcessSummary();//展示文件处理总结报告 + QString OutPutFolder_main="";//总输出文件夹 + int Waifu2xMainThread();//waifu2x总线程,负责读取文件列表,调度waifu2x放大线程 + QStringList WaitForEngineIO(QStringList OutPutFilesFullPathList); + QStringList WaitForEngineIO_NcnnVulkan(QString OutputFolderFullPath); + void Restore_SplitFramesFolderPath(QString SplitFramesFolderPath, QStringList GPU_SplitFramesFolderPath_List); + bool isForceRetryEnabled=true; + //bool KILL_TASK_(QString TaskName,bool RequestAdmin); + bool KILL_TASK_QStringList(QStringList TaskNameList,bool RequestAdmin); + //========================== + QString Waifu2x_ncnn_vulkan_FolderPath = ""; + QString Waifu2x_ncnn_vulkan_ProgramPath = ""; + //=== + int Waifu2x_NCNN_Vulkan_Image(int rowNum,bool ReProcess_MissingAlphaChannel);//vulkan放大图片线程 + //vulakn放大GIF线程:1.主线程,拆分,调度放大子线程,组装&压缩;2.放大子线程,负责放大所有帧以及调整大小 + int Waifu2x_NCNN_Vulkan_GIF(int rowNum); + //vulkan放大视频线程:1.主线程,拆分,调度放大子线程,组装;2.放大子线程,负责放大所有帧以及调整大小 + int Waifu2x_NCNN_Vulkan_Video(int rowNum); + int Waifu2x_NCNN_Vulkan_Video_BySegment(int rowNum); + QString Waifu2x_NCNN_Vulkan_ReadSettings(); + QString Waifu2x_NCNN_Vulkan_ReadSettings_Video_GIF(int ThreadNum); + //=== + int Realsr_NCNN_Vulkan_Image(int rowNum,bool ReProcess_MissingAlphaChannel);//Realsr放大图片线程 + //Realsr放大GIF线程:1.主线程,拆分,调度放大子线程,组装&压缩;2.放大子线程,负责放大所有帧以及调整大小 + int Realsr_NCNN_Vulkan_GIF(int rowNum); + //Realsr放大视频线程:1.主线程,拆分,调度放大子线程,组装;2.放大子线程,负责放大所有帧以及调整大小 + int Realsr_NCNN_Vulkan_Video(int rowNum); + int Realsr_NCNN_Vulkan_Video_BySegment(int rowNum); + QString Realsr_NCNN_Vulkan_ReadSettings(); + int Calculate_Temporary_ScaleRatio_RealsrNCNNVulkan(int ScaleRatio); + QString Realsr_NCNN_Vulkan_ReadSettings_Video_GIF(int ThreadNum); + //========================= + int Anime4k_Image(int rowNum,bool ReProcess_MissingAlphaChannel); + int Anime4k_GIF(int rowNum); + int Anime4k_GIF_scale(QMap Sub_Thread_info,int *Sub_gif_ThreadNumRunning,bool *Frame_failed); + //Anime4k放大视频线程:1.主线程,拆分,调度放大子线程,组装;2.放大子线程,负责放大所有帧以及调整大小 + int Anime4k_Video(int rowNum); + int Anime4k_Video_BySegment(int rowNum); + int Anime4k_Video_scale(QMap Sub_Thread_info,int *Sub_video_ThreadNumRunning,bool *Frame_failed); + QString Anime4k_ReadSettings(bool PreserveAlphaChannel); + void DenoiseLevelSpinboxSetting_Anime4k(); + QString Anime4k_ProgramPath = Current_Path + "/Anime4K/Anime4K_waifu2xEX.exe"; + int Get_NumOfGPU_Anime4k(); + //================================= + int Waifu2x_Converter_Image(int rowNum,bool ReProcess_MissingAlphaChannel);//Converter放大图片线程 + //Converter放大GIF线程:1.主线程,拆分,调度放大子线程,组装&压缩;2.放大子线程,负责放大所有帧以及调整大小 + int Waifu2x_Converter_GIF(int rowNum); + int Waifu2x_Converter_GIF_scale(QMap Sub_Thread_info,int *Sub_gif_ThreadNumRunning,bool *Frame_failed); + //Converter放大视频线程:1.主线程,拆分,调度放大子线程,组装;2.放大子线程,负责放大所有帧以及调整大小 + int Waifu2x_Converter_Video(int rowNum); + int Waifu2x_Converter_Video_BySegment(int rowNum); + int Waifu2x_Converter_Video_scale(QMap Sub_Thread_info,int *Sub_video_ThreadNumRunning,bool *Frame_failed); + QString Waifu2xConverter_ReadSettings(); + //=================================== + int SRMD_NCNN_Vulkan_Image(int rowNum,bool ReProcess_MissingAlphaChannel);//SRMD放大图片线程 + //SRMD放大GIF线程:1.主线程,拆分,调度放大子线程,组装&压缩;2.放大子线程,负责放大所有帧以及调整大小 + int SRMD_NCNN_Vulkan_GIF(int rowNum); + //SRMD放大视频线程:1.主线程,拆分,调度放大子线程,组装;2.放大子线程,负责放大所有帧以及调整大小 + int SRMD_NCNN_Vulkan_Video(int rowNum); + int SRMD_NCNN_Vulkan_Video_BySegment(int rowNum); + QString SrmdNcnnVulkan_ReadSettings(); + QMap Calculate_ScaleRatio_SrmdNcnnVulkan(int ScaleRatio); + QString SrmdNcnnVulkan_ReadSettings_Video_GIF(int ThreadNum); + //================================= + int Waifu2x_Caffe_Image(int rowNum,bool ReProcess_MissingAlphaChannel);//Caffe放大图片线程 + //Caffe放大GIF线程:1.主线程,拆分,调度放大子线程,组装&压缩;2.放大子线程,负责放大所有帧以及调整大小 + int Waifu2x_Caffe_GIF(int rowNum); + int Waifu2x_Caffe_GIF_scale(QMap Sub_Thread_info,int *Sub_gif_ThreadNumRunning,bool *Frame_failed); + //Caffe放大视频线程:1.主线程,拆分,调度放大子线程,组装;2.放大子线程,负责放大所有帧以及调整大小 + int Waifu2x_Caffe_Video(int rowNum); + int Waifu2x_Caffe_Video_BySegment(int rowNum); + int Waifu2x_Caffe_Video_scale(QMap Sub_Thread_info,int *Sub_video_ThreadNumRunning,bool *Frame_failed); + QString Waifu2x_Caffe_ReadSettings(); + bool isWaifu2xCaffeEnabled(); + void DeleteErrorLog_Waifu2xCaffe(); + //==================================== + int SRMD_CUDA_Image(int rowNum,bool ReProcess_MissingAlphaChannel);//SRMD放大图片线程 + //SRMD放大GIF线程:1.主线程,拆分,调度放大子线程,组装&压缩;2.放大子线程,负责放大所有帧以及调整大小 + int SRMD_CUDA_GIF(int rowNum); + //SRMD放大视频线程:1.主线程,拆分,调度放大子线程,组装;2.放大子线程,负责放大所有帧以及调整大小 + int SRMD_CUDA_Video(int rowNum); + int SRMD_CUDA_Video_BySegment(int rowNum); + //==================================== + + void Wait_waifu2x_stop();//等待waifu2x主线程完全停止所有子线程的看门狗线程 + bool waifu2x_STOP = false;//负责通知waifu2x主线程及其子线程的停止信号 + bool waifu2x_STOP_confirm = false;//返回给waifu2x停止看门狗的信号 + + int ThreadNumMax = 0;//waifu2x放大线程最大值 + int ThreadNumRunning = 0;//正在运行的waifu2x线程数量 + + QMutex mutex_ThreadNumRunning;//监管总线程数量的mutex + QMutex mutex_SubThreadNumRunning;//监管内部线程数量的mutex + + int Waifu2x_DetectGPU();//检测可用gpu(for vulkan) + QStringList Available_GPUID;//可用GPU ID列表 + + int Waifu2x_DumpProcessorList_converter(); + int Core_num = 0; + QStringList Available_ProcessorList_converter; + QString Processor_converter_STR=""; + + int SRMD_DetectGPU();//检测可用gpu(for srmd) + QStringList Available_GPUID_srmd;//可用GPU ID列表 + QString GPU_ID_STR_SRMD="";//向srmd命令行cmd插入的gpuid命令,如果auto则为空 + + int Realsr_ncnn_vulkan_DetectGPU();//检测可用gpu(for realsr) + QStringList Available_GPUID_Realsr_ncnn_vulkan;//可用GPU ID列表 + + void ListGPUs_Anime4k();//列出可用显卡 Anime4k + + int FrameInterpolation_DetectGPU();//检测可用gpu(for vulkan) + QStringList Available_GPUID_FrameInterpolation;//可用GPU ID列表 + //======================== 图片处理 ================================ + bool Image_Gif_AutoSkip_CustRes(int rowNum,bool isGif); + QMap Image_Gif_Read_Resolution(QString SourceFileFullPath);//获取图片&GIF分辨率 + bool Imgae_hasAlphaChannel(int rowNum); + QString Imgae_PreProcess(QString ImagePath,bool ReProcess_AlphaChannel); + QString SaveImageAs_FormatAndQuality(QString OriginalSourceImage_fullPath,QString ScaledImage_fullPath,bool isDenoiseLevelEnabled,int DenoiseLevel); + //================================================================ + int Waifu2x_Compatibility_Test();//引擎兼容性检测 + //初始化 -兼容性测试进度条 + void Init_progressBar_CompatibilityTest(); + //兼容性测试完成后的操作 -兼容性测试进度条 + void Finish_progressBar_CompatibilityTest(); + //兼容性检测 + bool isCompatible_Waifu2x_NCNN_Vulkan_OLD=false; + bool isCompatible_Waifu2x_NCNN_Vulkan_NEW=false; + bool isCompatible_Waifu2x_NCNN_Vulkan_NEW_FP16P=false; + bool isCompatible_SRMD_NCNN_Vulkan=false; + bool isCompatible_SRMD_CUDA=false; + bool isCompatible_Waifu2x_Converter=false; + bool isCompatible_Anime4k_CPU=false; + bool isCompatible_Anime4k_GPU=false; + bool isCompatible_FFmpeg=false; + bool isCompatible_FFprobe=false; + bool isCompatible_ImageMagick=false; + bool isCompatible_Gifsicle=false; + bool isCompatible_SoX=false; + bool isCompatible_Waifu2x_Caffe_CPU=false; + bool isCompatible_Waifu2x_Caffe_GPU=false; + bool isCompatible_Waifu2x_Caffe_cuDNN=false; + bool isCompatible_Realsr_NCNN_Vulkan=false; + bool isCompatible_RifeNcnnVulkan=false; + bool isCompatible_CainNcnnVulkan=false; + bool isCompatible_DainNcnnVulkan=false; + //============================== 多显卡 ========================================== + //waifu2x-ncnn-vulkan + int GPU_ID_Waifu2x_NCNN_Vulkan_MultiGPU = 0; + QMap Waifu2x_NCNN_Vulkan_MultiGPU(); + QMutex MultiGPU_QMutex_Waifu2xNCNNVulkan; + QList> GPUIDs_List_MultiGPU_Waifu2xNCNNVulkan; + void AddGPU_MultiGPU_Waifu2xNCNNVulkan(QString GPUID); + + //SRMD-ncnn-vulkan + int GPU_ID_SrmdNcnnVulkan_MultiGPU = 0; + QMap SrmdNcnnVulkan_MultiGPU(); + QMutex MultiGPU_QMutex_SrmdNcnnVulkan; + QList> GPUIDs_List_MultiGPU_SrmdNcnnVulkan; + void AddGPU_MultiGPU_SrmdNcnnVulkan(QString GPUID); + + //RealsrNcnnVulkan + int GPU_ID_RealsrNcnnVulkan_MultiGPU = 0; + QMap RealsrNcnnVulkan_MultiGPU(); + QMutex MultiGPU_QMutex_RealsrNcnnVulkan; + QList> GPUIDs_List_MultiGPU_RealsrNcnnVulkan; + void AddGPU_MultiGPU_RealsrNcnnVulkan(QString GPUID); + + //Waifu2xConverter + int GPU_ID_Waifu2xConverter_MultiGPU = 0; + QMap Waifu2xConverter_MultiGPU(); + QMutex MultiGPU_QMutex_Waifu2xConverter; + QList> GPUIDs_List_MultiGPU_Waifu2xConverter; + void AddGPU_MultiGPU_Waifu2xConverter(QString GPUID); + + //Anime4k + int GPU_ID_Anime4k_GetGPUInfo = 0; + QString Anime4k_GetGPUInfo(); + QMutex GetGPUInfo_QMutex_Anime4k; + + //Waifu2x-caffe + int GPU_ID_Waifu2xCaffe_GetGPUInfo = 0; + QString Waifu2xCaffe_GetGPUInfo(); + QMutex GetGPUInfo_QMutex_Waifu2xCaffe; + int Get_NumOfGPU_W2xCaffe(); + //================================ progressbar =================================== + int Progressbar_MaxVal = 0;//进度条最大值 + int Progressbar_CurrentVal = 0;//进度条当前值 + void progressbar_clear();//清空进度条 + void progressbar_SetToMax(int maxval);//将进度条设定到最大值 + //=============================== textbrowser=============================== + void TextBrowser_StartMes();//输出启动信息 + //================================ gif ==================================== + void Gif_RemoveFromCustResList(int RowNumber); + bool Gif_DoubleScaleRatioPrep(int RowNumber); + int Gif_getDuration(QString gifPath);//获取帧间隔时长 + int Gif_getFrameDigits(QString gifPath);//获取帧数量的位数 + void Gif_splitGif(QString gifPath,QString SplitFramesFolderPath);//拆分gif + void Gif_assembleGif(QString ResGifPath,QString ScaledFramesPath,int Duration,bool CustRes_isEnabled,int CustRes_height,int CustRes_width,bool isOverScaled,QString SourceGifFullPath);//组装gif + QString Gif_compressGif(QString gifPath,QString gifPath_compressd);//压缩gif + //================================= video =============================== + void video_RemoveFromCustResList(int RowNumber); + bool video_DoubleScaleRatioPrep(int RowNumber); + QString isPreVFIDone_MarkFilePath(QString VideoPath); + int CalNumDigits(int input_num); + bool isSuccessiveFailuresDetected_VFI=false; + int FrameInterpolation_Video_BySegment(int rowNum); + int FrameInterpolation_Video(int rowNum); + int Old_FrameInterpolation_Engine_Index=0; + QString FrameInterpolation_ReadConfig(bool isUhdInput,int NumOfFrames); + bool FrameInterpolation(QString SourcePath,QString OutputPath); + bool Video_AutoSkip_CustRes(int rowNum); + QMap video_get_Resolution(QString VideoFileFullPath);//获取视频的帧率 + QString video_get_fps(QString videoPath);//获取视频fps + int video_get_frameNumDigits(QString videoPath);//获取帧数量的位数 + int video_get_frameNum(QString videoPath);//获取帧数量 + + //判断视频是否可变帧率 + bool video_isVFR(QString videoPath); + //拆分视频 + void video_video2images(QString VideoPath,QString FrameFolderPath,QString AudioPath); + //组装视频 + int video_images2video(QString VideoPath,QString video_mp4_scaled_fullpath,QString ScaledFrameFolderPath,QString AudioPath,bool CustRes_isEnabled,int CustRes_height,int CustRes_width,bool isOverScaled); + //读取输出视频的设定参数 + QString video_ReadSettings_OutputVid(QString AudioPath); + //获取视频比特率 + QString video_get_bitrate(QString videoPath,bool isReturnFullCMD,bool isVidOnly); + //获取视频比特率(根据分辨率计算) + QString video_get_bitrate_AccordingToRes_FrameFolder(QString ScaledFrameFolderPath,QString VideoPath); + int video_UseRes2CalculateBitrate(QString VideoFileFullPath);//根据视频的分辨率计算他应该被分配的比特率 + //音频降噪 + QString video_AudioDenoise(QString OriginalAudioPath); + //获取时长(秒) + int video_get_duration(QString videoPath); + //转换为mp4 + QString video_To_CFRMp4(QString VideoPath); + //提取音频 + void video_get_audio(QString VideoPath,QString AudioPath); + //拆分视频(分段) + void video_video2images_ProcessBySegment(QString VideoPath,QString FrameFolderPath,int StartTime,int SegmentDuration); + //组装视频(mp4片段到成片) + void video_AssembleVideoClips(QString VideoClipsFolderPath,QString VideoClipsFolderName,QString video_mp4_scaled_fullpath,QString AudioPath); + //生成视频片段文件夹编号 + QString video_getClipsFolderNo(); + QMutex MultiLine_ErrorOutput_QMutex; + + bool video_isNeedProcessBySegment(int rowNum);//根据视频时长,判断是否需要分段处理 + void DelVfiDir(QString VideoPath); + //============================ custom res ==================================== + //自定义分辨率列表 + QList> Custom_resolution_list;//res_map["fullpath"],["height"],["width"] + void CustRes_remove(QString fullpath);//根据完整路径,移除自定义分辨率内条目 + bool CustRes_isContained(QString fullpath);//检查是否包括某文件 + QMap CustRes_getResMap(QString fullpath);//读取指定文件的自定义分辨率值 + int CustRes_CalNewScaleRatio(QString fullpath,int Height_new,int width_new);//计算新的放大倍数 + int CustRes_SetCustRes();//设定自定义分辨率 + int CustRes_CancelCustRes();//取消自定义分辨率 + QMap DoubleScaleRatio_Cal_NewScaleRatio_NewHW(QString fullpath,double ScaleRatio_double); + + Qt::AspectRatioMode CustRes_AspectRatioMode = Qt::IgnoreAspectRatio;//自定义分辨率的纵横比策略 + //======================== 设置 =========================================== + int Settings_Read_Apply();//读取与apply设置 + bool Settings_isReseted = false;//是否重置设置标记 + QVariant Settings_Read_value(QString Key); + bool isReadOldSettings = false; + //================================ Other ======================================= + bool isCustomVideoSettingsClicked=true; + + void pushButton_Start_setEnabled_self(bool isEnabled); + void pushButton_Stop_setEnabled_self(bool isEnabled); + + void TurnOffScreen(); + QFuture TurnOffScreen_QF;//监视是否连续多次点击关闭屏幕,避免连续启动nircmd + + bool FileProgressWatch_isEnabled = true;//是否启用输出文件夹进度监控线程 + + int ForceRetryCount = 1; + + void OutputSettingsArea_setEnabled(bool isEnabled); + + bool isFirstTimeStart=false; + + bool isForceRetryClicked=false; + QMutex isForceRetryClicked_QMutex; + void DelTrash_ForceRetry_Anime4k(QString OutPut_Path); + void isForceRetryClicked_SetTrue_Block_Anime4k(); + + void AutoFinishAction_Message(); + int SystemShutDown_Countdown();//自动关机倒计时 + int SystemShutDown_isAutoShutDown();//判断之前是否执行过自动关机 + //阻塞延时(安全 + void Delay_sec_sleep(int time); + void Delay_msec_sleep(int time); + + void Play_NFSound();//播放提示音 + + QTimer *TimeCostTimer;//计算耗时的timer + long unsigned int TimeCost = 0;//已消耗时间 + QString Seconds2hms(long unsigned int seconds);//秒 转 时:分:秒 + long unsigned int TaskNumTotal=0;//总任务数量(需要处理的文件) + long unsigned int TaskNumFinished=0;//处理完的文件数量 + bool NewTaskFinished=false;//新任务被完成之标记 + long unsigned int ETA=0;//ETA时间(s) + + int CheckUpadte_Auto();//自动检查更新 + + int Donate_DownloadOnlineQRCode(); + + bool isSettingsHide=false;//是否隐藏主页的设置groupbox + + bool isShowAnime4kWarning=true; + + void ConnectivityTest_RawGithubusercontentCom();//检查是否可以连接github + bool isConnectivityTest_RawGithubusercontentCom_Running=false; + QMutex QMutex_ConnectivityTest_RawGithubusercontentCom; + + bool DownloadTo(QString OnlineLink,QString LocalPath); + //=========== 关闭窗口时执行的代码 =============== + void closeEvent(QCloseEvent* event);//关闭事件 + //void Close_self();//包含所有关闭时执行的代码 + bool QProcess_stop=false;//所有QProcess停止标记 + int Auto_Save_Settings_Watchdog(bool isWaitForSave);//自动保存设置的看门狗 + QFuture AutoUpdate;//监视自动检查更新线程 + QFuture DownloadOnlineQRCode;//监视在线下载二维码线程 + QFuture Waifu2xMain;//监视waifu2x主线程 + int Force_close();//调用cmd强制关闭自己 + bool isAlreadyClosed=false; + //================== 处理当前文件的进度 ========================= + long unsigned int TimeCost_CurrentFile =0; + long unsigned int TaskNumTotal_CurrentFile=0; + long unsigned int TaskNumFinished_CurrentFile=0; + bool NewTaskFinished_CurrentFile=false; + long unsigned int ETA_CurrentFile=0; + bool isStart_CurrentFile=false; + //============================================= + void Tip_FirstTimeStart(); + //================== 托盘图标 ================= + void Init_SystemTrayIcon(); + QSystemTrayIcon *systemTray = new QSystemTrayIcon(this); + QMenu *pContextMenu = new QMenu(this); + QAction *minimumAct_SystemTrayIcon = new QAction(this); + QAction *restoreAct_SystemTrayIcon = new QAction(this); + QAction *quitAct_SystemTrayIcon = new QAction(this); + QAction *BackgroundModeAct_SystemTrayIcon = new QAction(this); + QAction *SendFeedback_SystemTrayIcon = new QAction(this); + QAction *About_SystemTrayIcon = new QAction(this); + QAction *Donate_SystemTrayIcon = new QAction(this); + QAction *Pause_SystemTrayIcon = new QAction(this); + QAction *Start_SystemTrayIcon = new QAction(this); + QAction *BecomePatron_SystemTrayIcon = new QAction(this); + QAction *TopSupportersList_SystemTrayIcon = new QAction(this); + //================= 输出路径 lineEdit 的右键菜单 ============== + void Init_ActionsMenu_lineEdit_outputPath(); + QAction *OpenFolder_lineEdit_outputPath = new QAction(this); + //================= 文件列表的右键菜单 ==================== + void Init_ActionsMenu_FilesList(); + QAction *OpenFile_QAction_FileList = new QAction(this); + QAction *OpenFilesFolder_QAction_FileList = new QAction(this); + QAction *RemoveFile_FilesList_QAction_FileList = new QAction(this); + bool EnableApply2All_CustRes=true; + QAction *Apply_CustRes_QAction_FileList = new QAction(this); + QAction *Cancel_CustRes_QAction_FileList = new QAction(this); + void OpenSelectedFile_FailedWarning_FilesList(); + //================ 移除条目 按钮的右键菜单======================= + void Init_ActionsMenu_pushButton_RemoveItem(); + QAction *RemoveALL_image = new QAction(this); + QAction *RemoveALL_gif = new QAction(this); + QAction *RemoveALL_video = new QAction(this); + //=================== 生成bat文件来执行cmd命令 =========== + void ExecuteCMD_batFile(QString cmd_str,bool requestAdmin); + QMutex ExecuteCMD_batFile_QMutex; + void Del_TempBatFile(); + //===================================================== + void comboBox_UpdateChannel_setCurrentIndex_self(int index); + QMutex comboBox_UpdateChannel_setCurrentIndex_self_QMutex; + bool isClicked_comboBox_UpdateChannel=true; + //===================== 直接替换源文件 ===================== + void checkBox_ReplaceOriginalFile_setEnabled_True_Self(); + bool ReplaceOriginalFile(QString original_fullpath,QString output_fullpath); + void Init_ActionsMenu_checkBox_ReplaceOriginalFile();//替换源文件 的右键菜单 + QAction *QAction_checkBox_MoveToRecycleBin_checkBox_ReplaceOriginalFile = new QAction(this); + //===================== 删除原文件的右键菜单 =========================== + void Init_ActionsMenu_checkBox_DelOriginal();//替换源文件 的右键菜单 + QAction *QAction_checkBox_MoveToRecycleBin_checkBox_DelOriginal = new QAction(this); + //===================== 事件过滤器 ===================== + bool eventFilter(QObject *target, QEvent *event); + //===================== 块大小调整 ====================== + int AddTileSize_NCNNVulkan_Converter(int OrginalTileSize); + int MinusTileSize_NCNNVulkan_Converter(int OrginalTileSize); + //==================== 预读取引擎设定 ================== + void PreLoad_Engines_Settings(); + //=== + QString Waifu2x_NCNN_Vulkan_PreLoad_Settings(); + QString Waifu2x_NCNN_Vulkan_PreLoad_Settings_Str = ""; + //=== + QString SrmdNcnnVulkan_PreLoad_Settings(); + QString SrmdNcnnVulkan_PreLoad_Settings_Str = ""; + //=== + QString Realsr_NCNN_Vulkan_PreLoad_Settings(); + QString Realsr_NCNN_Vulkan_PreLoad_Settings_Str = ""; + //=== + QString Waifu2xCaffe_PreLoad_Settings(); + QString Waifu2xCaffe_PreLoad_Settings_Str = ""; + //=== + QString Waifu2xConverter_PreLoad_Settings(); + QString Waifu2xConverter_PreLoad_Settings_Str = ""; + //=== + QString Anime4k_PreLoad_Settings(); + QString Anime4k_PreLoad_Settings_Str = ""; + QString HDNDenoiseLevel_image = ""; + QString HDNDenoiseLevel_gif = ""; + QString HDNDenoiseLevel_video = ""; + //================== 计算临时放大倍率 ==================== + int Calculate_Temporary_ScaleRatio_W2xNCNNVulkan(int ScaleRatio); + //================== 多线程调整图片大小 ========================= + void ImagesResize_Folder_MultiThread(int New_width,int New_height,QString ImagesFolderPath); + int TotalNumOfThreads_ImagesResize_Folder_MultiThread; + int RunningNumOfThreads_ImagesResize_Folder_MultiThread; + QMutex QMutex_ResizeImage_MultiThread; + void ResizeImage_MultiThread(int New_width,int New_height,QString ImagesPath); + //================== 处理APNG ================= + void APNG_Main(int rowNum,bool isFromImageList); + void APNG_Split2Frames(QString sourceFileFullPath,QString splitFramesFolder); + void APNG_Frames2APNG(QString sourceFileFullPath,QString scaledFramesFolder,QString resultFileFullPath,bool isOverScaled); + bool APNG_isAnimatedPNG(int rowNum); + //Waifu2x-NCNN-Vulkan + bool APNG_Waifu2xNCNNVulkan(QString splitFramesFolder,QString scaledFramesFolder,QString sourceFileFullPath,QStringList framesFileName_qStrList,QString resultFileFullPath); + //Waifu2x-Converter + bool APNG_Waifu2xConverter(QString splitFramesFolder,QString scaledFramesFolder,QString sourceFileFullPath,QStringList framesFileName_qStrList,QString resultFileFullPath); + int Waifu2x_Converter_APNG_scale(QMap Sub_Thread_info,int *Sub_gif_ThreadNumRunning,bool *Frame_failed); + //Srmd-NCNN-Vulkan + bool APNG_SrmdNCNNVulkan(QString splitFramesFolder,QString scaledFramesFolder,QString sourceFileFullPath,QStringList framesFileName_qStrList,QString resultFileFullPath); + //Anime4k + bool APNG_Anime4k(QString splitFramesFolder,QString scaledFramesFolder,QString sourceFileFullPath,QStringList framesFileName_qStrList,QString resultFileFullPath); + int Anime4k_APNG_scale(QMap Sub_Thread_info,int *Sub_gif_ThreadNumRunning,bool *Frame_failed); + //Srmd-CUDA + bool APNG_SrmdCUDA(QString splitFramesFolder,QString scaledFramesFolder,QString sourceFileFullPath,QStringList framesFileName_qStrList,QString resultFileFullPath); + //waifu2x-caffe + bool APNG_Waifu2xCaffe(QString splitFramesFolder,QString scaledFramesFolder,QString sourceFileFullPath,QStringList framesFileName_qStrList,QString resultFileFullPath); + int Waifu2x_Caffe_APNG_scale(QMap Sub_Thread_info,int *Sub_gif_ThreadNumRunning,bool *Frame_failed); + //Realsr-NCNN-Vulkan + bool APNG_RealsrNCNNVulkan(QString splitFramesFolder,QString scaledFramesFolder,QString sourceFileFullPath,QStringList framesFileName_qStrList,QString resultFileFullPath); + //============= + ~MainWindow(); + +public slots: + void Table_EnableSorting(bool EnableSorting); + + void Apply_CustRes_QAction_FileList_slot(); + void Cancel_CustRes_QAction_FileList_slot(); + + void RemoveALL_image_slot(); + void RemoveALL_gif_slot(); + void RemoveALL_video_slot(); + + void Add_progressBar_CompatibilityTest();//进度+1 -兼容性测试进度条 + + void OpenSelectedFilesFolder_FilesList(); + void OpenSelectedFile_FilesList(); + + void OpenOutputFolder(); + + void Unable2Connect_RawGithubusercontentCom(); + + void SetEnable_pushButton_ForceRetry_self(); + + void SystemTray_hide_self(); + void SystemTray_showNormal_self(); + void SystemTray_showDonate(); + + void SystemTray_NewMessage(QString message); + void EnableBackgroundMode_SystemTray(); + void on_activatedSysTrayIcon(QSystemTrayIcon::ActivationReason reason); + + void progressbar_setRange_min_max(int min, int max);//进度条设定min和max + void progressbar_Add();//进度条进度+1 + + //根据row修改指定row的状态 + void Table_image_ChangeStatus_rowNumInt_statusQString(int rowNum, QString status); + void Table_gif_ChangeStatus_rowNumInt_statusQString(int rowNum, QString status); + void Table_video_ChangeStatus_rowNumInt_statusQString(int rowNum, QString status); + + void Waifu2x_Finished();//自动结束时调用的代码(会自动接着调用manual + void Waifu2x_Finished_manual();//手动停止后调用的结束代码 + + void TextBrowser_NewMessage(QString message);//Textbrowser发送新消息"[时间] 消息" + + void TimeSlot();//计时槽函数 + + int Waifu2x_Compatibility_Test_finished();//兼容性检测结束后执行的槽函数 + + int Waifu2x_DetectGPU_finished();//检测可用gpu结束后的执行的槽函数 + + int Realsr_ncnn_vulkan_DetectGPU_finished();//检测可用gpu结束后的执行的槽函数 + + int FrameInterpolation_DetectGPU_finished(); + + int CheckUpadte_NewUpdate(QString update_str,QString Change_log);//检测到更新的弹窗代码 + + void FinishedProcessing_DN(); + + int Table_FileCount_reload();//重载table下的文件数量计数 + + //向table插入文件名和fullpath + void Table_image_insert_fileName_fullPath(QString fileName, QString SourceFile_fullPath); + void Table_gif_insert_fileName_fullPath(QString fileName, QString SourceFile_fullPath); + void Table_video_insert_fileName_fullPath(QString fileName, QString SourceFile_fullPath); + + //向table插入自定义分辨率值 + void Table_image_CustRes_rowNumInt_HeightQString_WidthQString(int rowNum, QString height, QString width); + void Table_gif_CustRes_rowNumInt_HeightQString_WidthQString(int rowNum, QString height, QString width); + void Table_video_CustRes_rowNumInt_HeightQString_WidthQString(int rowNum, QString height, QString width); + + //读取&保存文件列表与table后执行的代码 + int Table_Read_Saved_Table_Filelist_Finished(QString Table_FileList_ini); + int Table_Save_Current_Table_Filelist_Finished(); + + void on_pushButton_ClearList_clicked();//清空列表 + + bool SystemShutDown();//关机 + + int Waifu2x_DumpProcessorList_converter_finished(); + + void Read_urls_finfished(); + + void SRMD_DetectGPU_finished(); + + void video_write_VideoConfiguration(QString VideoConfiguration_fullPath,int ScaleRatio,int DenoiseLevel,bool CustRes_isEnabled,int CustRes_height,int CustRes_width,QString EngineName,bool isProcessBySegment,QString VideoClipsFolderPath,QString VideoClipsFolderName,bool isVideoFrameInterpolationEnabled,int MultipleOfFPS); + + int Settings_Save();//保存设置 + + //存储进度 + void video_write_Progress_ProcessBySegment(QString VideoConfiguration_fullPath,int StartTime,bool isSplitComplete,bool isScaleComplete,int OLDSegmentDuration,int LastVideoClipNo); + + //================== 处理当前文件的进度 ========================= + void CurrentFileProgress_Start(QString FileName,int FrameNum); + void CurrentFileProgress_Stop(); + void CurrentFileProgress_progressbar_Add(); + void CurrentFileProgress_progressbar_Add_SegmentDuration(int SegmentDuration); + void CurrentFileProgress_progressbar_SetFinishedValue(int FinishedValue); + void CurrentFileProgress_WatchFolderFileNum(QString FolderPath); + void CurrentFileProgress_WatchFolderFileNum_Textbrower(QString SourceFile_fullPath,QString FolderPath,int TotalFileNum); + + void Donate_ReplaceQRCode(QString QRCodePath); + + void Set_checkBox_DisableResize_gif_Checked(); + +private slots: + void on_pushButton_Start_clicked(); + + void on_pushButton_Stop_clicked(); + + int on_pushButton_RemoveItem_clicked(); + + void on_pushButton_CheckUpdate_clicked(); + + void on_pushButton_Report_clicked(); + + void on_pushButton_ReadMe_clicked(); + + void on_comboBox_Engine_Image_currentIndexChanged(int index); + + void on_comboBox_Engine_GIF_currentIndexChanged(int index); + + void on_comboBox_Engine_Video_currentIndexChanged(int index); + + void on_pushButton_clear_textbrowser_clicked(); + + void on_spinBox_textbrowser_fontsize_valueChanged(int arg1); + + void on_pushButton_compatibilityTest_clicked(); + + void on_pushButton_CustRes_apply_clicked(); + + void on_pushButton_CustRes_cancel_clicked(); + + void on_pushButton_HideSettings_clicked(); + + void on_pushButton_DetectGPU_clicked(); + + void on_pushButton_SaveSettings_clicked(); + + void on_pushButton_ResetSettings_clicked(); + + void on_comboBox_language_currentIndexChanged(int index); + + void on_pushButton_SaveFileList_clicked(); + + void on_pushButton_ReadFileList_clicked(); + + void on_Ext_image_editingFinished(); + + void on_Ext_video_editingFinished(); + + void on_checkBox_AutoSaveSettings_clicked(); + + void on_pushButton_about_clicked(); + + void on_comboBox_AspectRatio_custRes_currentIndexChanged(int index); + + void on_checkBox_AlwaysHideSettings_stateChanged(int arg1); + + void on_pushButton_Save_GlobalFontSize_clicked(); + + void on_pushButton_BrowserFile_clicked(); + + void on_pushButton_wiki_clicked(); + + void on_pushButton_HideTextBro_clicked(); + + void on_checkBox_AlwaysHideTextBrowser_stateChanged(int arg1); + + void on_pushButton_DumpProcessorList_converter_clicked(); + + void on_comboBox_TargetProcessor_converter_currentIndexChanged(int index); + + void on_Ext_image_textChanged(const QString &arg1); + + void on_Ext_video_textChanged(const QString &arg1); + + void on_comboBox_model_vulkan_currentIndexChanged(int index); + + void on_comboBox_ImageStyle_currentIndexChanged(int index); + + void on_pushButton_ResetVideoSettings_clicked(); + + void on_lineEdit_encoder_vid_textChanged(const QString &arg1); + + void on_lineEdit_encoder_audio_textChanged(const QString &arg1); + + void on_lineEdit_pixformat_textChanged(const QString &arg1); + + void on_checkBox_vcodec_copy_2mp4_stateChanged(int arg1); + + void on_checkBox_acodec_copy_2mp4_stateChanged(int arg1); + + void on_pushButton_encodersList_clicked(); + + void on_checkBox_DelOriginal_stateChanged(int arg1); + + void on_checkBox_FileList_Interactive_stateChanged(int arg1); + + void on_checkBox_OutPath_isEnabled_stateChanged(int arg1); + + void on_pushButton_ForceRetry_clicked(); + + void on_pushButton_PayPal_clicked(); + + void on_pushButton_DetectGPUID_srmd_clicked(); + + void on_checkBox_AudioDenoise_stateChanged(int arg1); + + void on_tabWidget_currentChanged(int index); + + void on_checkBox_ProcessVideoBySegment_stateChanged(int arg1); + + void on_comboBox_version_Waifu2xNCNNVulkan_currentIndexChanged(int index); + + void on_checkBox_EnablePreProcessing_Anime4k_stateChanged(int arg1); + + void on_checkBox_EnablePostProcessing_Anime4k_stateChanged(int arg1); + + void on_checkBox_isCompatible_Waifu2x_NCNN_Vulkan_NEW_clicked(); + + void on_checkBox_isCompatible_Waifu2x_NCNN_Vulkan_NEW_FP16P_clicked(); + + void on_checkBox_isCompatible_Waifu2x_NCNN_Vulkan_OLD_clicked(); + + void on_checkBox_isCompatible_SRMD_NCNN_Vulkan_clicked(); + + void on_checkBox_isCompatible_Waifu2x_Converter_clicked(); + + void on_checkBox_isCompatible_Anime4k_CPU_clicked(); + + void on_checkBox_isCompatible_Anime4k_GPU_clicked(); + + void on_checkBox_SpecifyGPU_Anime4k_stateChanged(int arg1); + + void on_pushButton_ListGPUs_Anime4k_clicked(); + + void on_checkBox_isCompatible_FFmpeg_clicked(); + + void on_checkBox_isCompatible_FFprobe_clicked(); + + void on_checkBox_isCompatible_ImageMagick_clicked(); + + void on_checkBox_isCompatible_Gifsicle_clicked(); + + void on_checkBox_isCompatible_SoX_clicked(); + + void on_checkBox_GPUMode_Anime4K_stateChanged(int arg1); + + void on_checkBox_ShowInterPro_stateChanged(int arg1); + + void on_checkBox_isCompatible_Waifu2x_Caffe_CPU_clicked(); + + void on_checkBox_isCompatible_Waifu2x_Caffe_GPU_clicked(); + + void on_checkBox_isCompatible_Waifu2x_Caffe_cuDNN_clicked(); + + void on_pushButton_SplitSize_Add_Waifu2xCaffe_clicked(); + + void on_pushButton_SplitSize_Minus_Waifu2xCaffe_clicked(); + + void on_checkBox_isCompatible_Realsr_NCNN_Vulkan_clicked(); + + void on_pushButton_DetectGPU_RealsrNCNNVulkan_clicked(); + + void on_checkBox_ACNet_Anime4K_stateChanged(int arg1); + + void on_checkBox_MultiGPU_Waifu2xNCNNVulkan_clicked(); + + void on_comboBox_GPUIDs_MultiGPU_Waifu2xNCNNVulkan_currentIndexChanged(int index); + + void on_spinBox_TileSize_CurrentGPU_MultiGPU_Waifu2xNCNNVulkan_valueChanged(int arg1); + + void on_checkBox_isEnable_CurrentGPU_MultiGPU_Waifu2xNCNNVulkan_clicked(); + + void on_checkBox_MultiGPU_Waifu2xNCNNVulkan_stateChanged(int arg1); + + void on_checkBox_MultiGPU_SrmdNCNNVulkan_stateChanged(int arg1); + + void on_checkBox_MultiGPU_SrmdNCNNVulkan_clicked(); + + void on_comboBox_GPUIDs_MultiGPU_SrmdNCNNVulkan_currentIndexChanged(int index); + + void on_checkBox_isEnable_CurrentGPU_MultiGPU_SrmdNCNNVulkan_clicked(); + + void on_spinBox_TileSize_CurrentGPU_MultiGPU_SrmdNCNNVulkan_valueChanged(int arg1); + + void on_checkBox_MultiGPU_RealsrNcnnVulkan_stateChanged(int arg1); + + void on_checkBox_MultiGPU_RealsrNcnnVulkan_clicked(); + + void on_comboBox_GPUIDs_MultiGPU_RealsrNcnnVulkan_currentIndexChanged(int index); + + void on_checkBox_isEnable_CurrentGPU_MultiGPU_RealsrNcnnVulkan_clicked(); + + void on_spinBox_TileSize_CurrentGPU_MultiGPU_RealsrNcnnVulkan_valueChanged(int arg1); + + void on_checkBox_MultiGPU_Waifu2xConverter_clicked(); + + void on_checkBox_MultiGPU_Waifu2xConverter_stateChanged(int arg1); + + void on_comboBox_GPUIDs_MultiGPU_Waifu2xConverter_currentIndexChanged(int index); + + void on_checkBox_isEnable_CurrentGPU_MultiGPU_Waifu2xConverter_clicked(); + + void on_spinBox_TileSize_CurrentGPU_MultiGPU_Waifu2xConverter_valueChanged(int arg1); + + void on_checkBox_EnableMultiGPU_Waifu2xCaffe_stateChanged(int arg1); + + void on_comboBox_ProcessMode_Waifu2xCaffe_currentIndexChanged(int index); + + void on_lineEdit_GPUs_Anime4k_editingFinished(); + + void on_lineEdit_MultiGPUInfo_Waifu2xCaffe_editingFinished(); + + void on_pushButton_VerifyGPUsConfig_Anime4k_clicked(); + + void on_pushButton_VerifyGPUsConfig_Waifu2xCaffe_clicked(); + + void on_tableView_image_doubleClicked(const QModelIndex &index); + + void on_tableView_gif_doubleClicked(const QModelIndex &index); + + void on_tableView_video_doubleClicked(const QModelIndex &index); + + void on_checkBox_BanGitee_clicked(); + + void on_pushButton_ShowMultiGPUSettings_Waifu2xNCNNVulkan_clicked(); + + void on_pushButton_ShowMultiGPUSettings_Waifu2xConverter_clicked(); + + void on_pushButton_ShowMultiGPUSettings_SrmdNCNNVulkan_clicked(); + + void on_pushButton_ShowMultiGPUSettings_RealsrNcnnVulkan_clicked(); + + void on_checkBox_HDNMode_Anime4k_stateChanged(int arg1); + + void on_tableView_image_pressed(const QModelIndex &index); + + void on_tableView_gif_pressed(const QModelIndex &index); + + void on_tableView_video_pressed(const QModelIndex &index); + + void on_comboBox_UpdateChannel_currentIndexChanged(int index); + + void on_checkBox_ReplaceOriginalFile_stateChanged(int arg1); + + void on_checkBox_isCustFontEnable_stateChanged(int arg1); + + void on_comboBox_ImageSaveFormat_currentIndexChanged(int index); + + void on_pushButton_ResizeFilesListSplitter_clicked(); + + void on_pushButton_TileSize_Add_W2xNCNNVulkan_clicked(); + + void on_pushButton_TileSize_Minus_W2xNCNNVulkan_clicked(); + + void on_pushButton_BlockSize_Add_W2xConverter_clicked(); + + void on_pushButton_BlockSize_Minus_W2xConverter_clicked(); + + void on_pushButton_Add_TileSize_SrmdNCNNVulkan_clicked(); + + void on_pushButton_Minus_TileSize_SrmdNCNNVulkan_clicked(); + + void on_pushButton_Add_TileSize_RealsrNCNNVulkan_clicked(); + + void on_pushButton_Minus_TileSize_RealsrNCNNVulkan_clicked(); + + void on_comboBox_GPGPUModel_A4k_currentIndexChanged(int index); + + void on_checkBox_DisableGPU_converter_stateChanged(int arg1); + + void on_groupBox_video_settings_clicked(); + + void on_pushButton_DetectGPU_VFI_clicked(); + + void on_lineEdit_MultiGPU_IDs_VFI_editingFinished(); + + void on_checkBox_MultiGPU_VFI_stateChanged(int arg1); + + void on_groupBox_FrameInterpolation_clicked(); + + void on_checkBox_isCompatible_RifeNcnnVulkan_clicked(); + + void on_comboBox_Engine_VFI_currentIndexChanged(int index); + + void on_checkBox_isCompatible_CainNcnnVulkan_clicked(); + + void on_pushButton_Verify_MultiGPU_VFI_clicked(); + + void on_checkBox_EnableVFI_Home_clicked(); + + void on_checkBox_MultiThread_VFI_stateChanged(int arg1); + + void on_checkBox_MultiThread_VFI_clicked(); + + void on_pushButton_TurnOffScreen_clicked(); + + void on_checkBox_isCompatible_DainNcnnVulkan_clicked(); + + void on_pushButton_MultipleOfFPS_VFI_MIN_clicked(); + + void on_pushButton_MultipleOfFPS_VFI_ADD_clicked(); + + void on_pushButton_Patreon_clicked(); + + void on_pushButton_SupportersList_clicked(); + + void on_checkBox_isCompatible_SRMD_CUDA_clicked(); + +signals: + void Send_Table_EnableSorting(bool EnableSorting); + + void Send_Add_progressBar_CompatibilityTest();//进度+1 -兼容性测试进度条 + + void Send_Unable2Connect_RawGithubusercontentCom(); + + void Send_SetEnable_pushButton_ForceRetry_self(); + + void Send_SystemTray_NewMessage(QString message); + + void Send_PrograssBar_Range_min_max(int, int); + void Send_progressbar_Add(); + + void Send_Table_image_ChangeStatus_rowNumInt_statusQString(int, QString); + void Send_Table_gif_ChangeStatus_rowNumInt_statusQString(int, QString); + void Send_Table_video_ChangeStatus_rowNumInt_statusQString(int, QString); + + void Send_Waifu2x_Finished(); + void Send_Waifu2x_Finished_manual(); + + void Send_TextBrowser_NewMessage(QString); + + void Send_Waifu2x_Compatibility_Test_finished(); + + void Send_Waifu2x_DetectGPU_finished(); + + void Send_FinishedProcessing_DN(); + + void Send_Realsr_ncnn_vulkan_DetectGPU_finished(); + void Send_FrameInterpolation_DetectGPU_finished(); + + void Send_CheckUpadte_NewUpdate(QString, QString); + + void Send_Table_FileCount_reload(); + + void Send_Table_image_insert_fileName_fullPath(QString fileName, QString SourceFile_fullPath); + void Send_Table_gif_insert_fileName_fullPath(QString fileName, QString SourceFile_fullPath); + void Send_Table_video_insert_fileName_fullPath(QString fileName, QString SourceFile_fullPath); + + void Send_Table_image_CustRes_rowNumInt_HeightQString_WidthQString(int rowNum, QString height, QString width); + void Send_Table_gif_CustRes_rowNumInt_HeightQString_WidthQString(int rowNum, QString height, QString width); + void Send_Table_video_CustRes_rowNumInt_HeightQString_WidthQString(int rowNum, QString height, QString width); + + void Send_Table_Read_Saved_Table_Filelist_Finished(QString Table_FileList_ini); + void Send_Table_Save_Current_Table_Filelist_Finished(); + + void Send_SystemShutDown(); + + void Send_Waifu2x_DumpProcessorList_converter_finished(); + + void Send_Read_urls_finfished(); + + void Send_SRMD_DetectGPU_finished(); + + void Send_video_write_VideoConfiguration(QString VideoConfiguration_fullPath,int ScaleRatio,int DenoiseLevel,bool CustRes_isEnabled,int CustRes_height,int CustRes_width,QString EngineName,bool isProcessBySegment,QString VideoClipsFolderPath,QString VideoClipsFolderName,bool isVideoFrameInterpolationEnabled,int MultipleOfFPS); + + void Send_Settings_Save(); + + void Send_video_write_Progress_ProcessBySegment(QString VideoConfiguration_fullPath,int StartTime,bool isSplitComplete,bool isScaleComplete,int OLDSegmentDuration,int LastVideoClipNo); + + //================== 处理当前文件的进度 ========================= + void Send_CurrentFileProgress_Start(QString FileName,int FrameNum); + void Send_CurrentFileProgress_Stop(); + void Send_CurrentFileProgress_progressbar_Add(); + void Send_CurrentFileProgress_progressbar_Add_SegmentDuration(int SegmentDuration); + void Send_CurrentFileProgress_progressbar_SetFinishedValue(int FinishedValue); + + void Send_Donate_ReplaceQRCode(QString QRCodePath); + + void Send_Set_checkBox_DisableResize_gif_Checked(); + +private: + Ui::MainWindow *ui; +}; +#endif // MAINWINDOW_H + diff --git a/SRC/Waifu2x-Extension-QT/mainwindow.ui b/SRC_v3.41.01-beta/Waifu2x-Extension-QT/mainwindow.ui similarity index 97% rename from SRC/Waifu2x-Extension-QT/mainwindow.ui rename to SRC_v3.41.01-beta/Waifu2x-Extension-QT/mainwindow.ui index 9ec9632..b12e940 100644 --- a/SRC/Waifu2x-Extension-QT/mainwindow.ui +++ b/SRC_v3.41.01-beta/Waifu2x-Extension-QT/mainwindow.ui @@ -1,11227 +1,11227 @@ - - - MainWindow - - - - 0 - 0 - 1096 - 794 - - - - - 0 - 0 - - - - - 0 - 0 - - - - - 16777215 - 16777215 - - - - Qt::StrongFocus - - - Waifu2x-Extension-GUI by Aaron Feng - - - - :/new/prefix1/icon/icon_main.png:/new/prefix1/icon/icon_main.png - - - - - - - - 0 - 0 - - - - - - - - 6 - - - 6 - - - 6 - - - 6 - - - - - - - - Qt::Vertical - - - 5 - - - - - 0 - 0 - - - - - 0 - 0 - - - - QTabBar::tab{ -height:35 -} - - - QTabWidget::Rounded - - - 1 - - - - 23 - 23 - - - - Qt::ElideNone - - - false - - - false - - - false - - - false - - - false - - - - true - - - - - - - :/new/prefix1/icon/donateTabIcon_1.png:/new/prefix1/icon/donateTabIcon_1.png - - - Donate - - - - - - - 16777215 - 50 - - - - - 10 - 50 - false - false - false - - - - <html><head/><body><p align="center">Please donate to support the developers, so we can bring further updates for this software, thank you! (。・∀・)ノ゙ </p><p align="center">If you don't wanna see the Donate page anymore, you can <span style=" color:#ff0004;">get the </span><span style=" font-weight:600; color:#ff0004;">Premium</span><span style=" color:#ff0004;"> version by support me on Patreon.</span></p></body></html> - - - Qt::AlignCenter - - - - - - - - - - 0 - 0 - - - - - 240 - 60 - - - - - 20 - 75 - false - true - false - false - - - - Donate to the developer through PayPal. - - - QPushButton{ -background-color: rgb(52, 152, 219); -color: rgb(255, 255, 255); -border-style:outset; -border-radius:8px; -padding:10px; -} -QPushButton:hover{ -background-color: rgb(60, 177, 255); -color: rgb(255, 255, 255); -border-style:outset; -border-radius:8px; -padding:10px; -} -QPushButton:pressed{ -background-color: rgb(45, 134, 193); -color: rgb(255, 255, 255); -border-style:outset; -border-radius:8px; -padding:10px; -} -QPushButton:disabled{ -background-color: rgb(166, 166, 166); -color: rgb(255, 255, 255); -border-style:outset; -border-radius:8px; -padding:10px; -} - - - PayPal - - - - :/new/prefix1/icon/paypal.png:/new/prefix1/icon/paypal.png - - - - 38 - 38 - - - - - - - - - 0 - 60 - - - - - 20 - 75 - true - - - - Support this project on Patreon and get Premium version. - - - QPushButton{ -background-color: rgb(255, 66, 77); -color: rgb(255, 255, 255); -border-style:outset; -border-radius:8px; -padding:10px; -} -QPushButton:hover{ -background-color: rgb(255, 105, 112); -color: rgb(255, 255, 255); -border-style:outset; -border-radius:8px; -padding:10px; -} -QPushButton:pressed{ -background-color: rgb(223, 50, 61); -color: rgb(255, 255, 255); -border-style:outset; -border-radius:8px; -padding:10px; -} -QPushButton:disabled{ -background-color: rgb(166, 166, 166); -color: rgb(255, 255, 255); -border-style:outset; -border-radius:8px; -padding:10px; -} - - - Get Premium version on Patreon - - - - :/new/prefix1/icon/patreon.png:/new/prefix1/icon/patreon.png - - - - 38 - 38 - - - - - - - - - - - 0 - 0 - - - - - 750 - 360 - - - - - 2 - 1 - - - - - Arial - 13 - 75 - true - - - - image: url(:/new/prefix1/donate/Donate_QRCode.jpg); - - - QFrame::NoFrame - - - - - - false - - - Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop - - - - - - - - - 9 - - - - - :/new/prefix1/icon/Home.png:/new/prefix1/icon/Home.png - - - Home - - - - 6 - - - 6 - - - 6 - - - 6 - - - - - - 0 - 0 - - - - - 0 - 0 - - - - - 16777215 - 51 - - - - - - - - 6 - - - 6 - - - 6 - - - 6 - - - - - - 0 - 0 - - - - - 0 - 0 - - - - - 16777215 - 16777215 - - - - - - - QPushButton{ -background-color: rgb(26, 188, 156); -color: rgb(255, 255, 255); -border-style:outset; -border-radius:8px; -padding:10px; -} -QPushButton:hover{ -background-color: rgb(29, 214, 177); -color: rgb(255, 255, 255); -border-style:outset; -border-radius:8px; -padding:10px; -} -QPushButton:pressed{ -background-color: rgb(23, 173, 143); -color: rgb(255, 255, 255); -border-style:outset; -border-radius:8px; -padding:10px; -} -QPushButton:disabled{ -background-color: rgb(166, 166, 166); -color: rgb(255, 255, 255); -border-style:outset; -border-radius:8px; -padding:10px; -} - - - Start - - - - :/new/prefix1/icon/icon_main.png:/new/prefix1/icon/icon_main.png - - - - 25 - 25 - - - - - - - - 0 - - - %p% - - - - - - - - 0 - 0 - - - - QFrame::Box - - - 1 - - - ETA:NULL - - - - - - - - 0 - 0 - - - - Finished/Total - - - QFrame::Box - - - QFrame::Plain - - - 1 - - - 0/0 - - - - - - - - 0 - 0 - - - - QFrame::Box - - - 1 - - - Time taken:NULL - - - - - - - true - - - - 0 - 0 - - - - In some cases, the Engine process can get stuck. - -When you find that the [Scale and denoise] progress has -not changed for a long time, it is recommended that you -perform a forced retry to remove the stuck. - -You can try using [Force Retry] to end the Engine process -and restart it, and the entire [Scale and denoise] process -will not be interrupted and will continue. - - - QPushButton{ -background-color: rgb(178, 58, 238); -color: rgb(255, 255, 255); -border-style:outset; -border-radius:8px; -padding:10px; -} -QPushButton:hover{ -background-color: rgb(191, 62, 255); -color: rgb(255, 255, 255); -border-style:outset; -border-radius:8px; -padding:10px; -} -QPushButton:pressed{ -background-color: rgb(154, 50, 205); -color: rgb(255, 255, 255); -border-style:outset; -border-radius:8px; -padding:10px; -} -QPushButton:disabled{ -background-color: rgb(166, 166, 166); -color: rgb(255, 255, 255); -border-style:outset; -border-radius:8px; -padding:10px; -} - - - Force retry - - - - :/new/prefix1/icon/refresh.png:/new/prefix1/icon/refresh.png - - - - 25 - 25 - - - - - - - - - 0 - 0 - - - - - 16777215 - 16777215 - - - - QPushButton{ -background-color: rgb(231, 76, 60); -color: rgb(255, 255, 255); -border-style:outset; -border-radius:8px; -padding:10px; -} -QPushButton:hover{ -background-color: rgb(255, 102, 64); -color: rgb(255, 255, 255); -border-style:outset; -border-radius:8px; -padding:10px; -} -QPushButton:pressed{ -background-color: rgb(204, 65, 53); -color: rgb(255, 255, 255); -border-style:outset; -border-radius:8px; -padding:10px; -} -QPushButton:disabled{ -background-color: rgb(166, 166, 166); -color: rgb(255, 255, 255); -border-style:outset; -border-radius:8px; -padding:10px; -} - - - Pause - - - - :/new/prefix1/icon/pause-button.png:/new/prefix1/icon/pause-button.png - - - - 25 - 25 - - - - - - - - - 0 - 0 - - - - QFrame::Box - - - 1 - - - Time remaining:NULL - - - - - - - - - - - 0 - 0 - - - - - 0 - 0 - - - - Current File: - - - - 6 - - - 6 - - - 6 - - - 6 - - - 6 - - - - - - 0 - 0 - - - - Finished/Total - - - QFrame::Box - - - QFrame::Plain - - - 0/0 - - - - - - - - 0 - 0 - - - - QFrame::Box - - - ETA:NULL - - - - - - - 0 - - - - - - - - 0 - 0 - - - - QFrame::Box - - - Time remaining:NULL - - - - - - - - 0 - 0 - - - - QFrame::Box - - - Time taken:NULL - - - - - - - - - - QSplitter:handle{ - - background-color: rgb(255, 255, 255); -} - - - 0 - - - Qt::Vertical - - - 3 - - - - - 0 - 0 - - - - - 0 - 0 - - - - Files List - - - - 6 - - - 6 - - - 6 - - - 6 - - - - - - 0 - 0 - - - - QSplitter:handle{ - - background-color: rgb(255, 255, 255); -} - - - Qt::Horizontal - - - 5 - - - false - - - - - 0 - 0 - - - - Qt::ActionsContextMenu - - - Press [Delete] key to remove file from the list. -Press [Ctrl + A] key to apply custom resolution. -Press [Ctrl + C] key to cancel custom resolution. - -Right click to show more options. - - - QTableView{ -selection-background-color: rgb(52, 152, 219); - -} - - - false - - - 0 - - - QAbstractItemView::NoEditTriggers - - - QAbstractItemView::SingleSelection - - - QAbstractItemView::SelectRows - - - QAbstractItemView::ScrollPerPixel - - - QAbstractItemView::ScrollPerPixel - - - false - - - false - - - false - - - 20 - - - 200 - - - false - - - false - - - false - - - false - - - - - true - - - - 0 - 0 - - - - Qt::ActionsContextMenu - - - Press [Delete] key to remove file from the list. -Press [Ctrl + A] key to apply custom resolution. -Press [Ctrl + C] key to cancel custom resolution. - -Right click to show more options. - - - QTableView{ -selection-background-color: rgb(26, 188, 156); -} - - - false - - - 0 - - - QAbstractItemView::NoEditTriggers - - - QAbstractItemView::SingleSelection - - - QAbstractItemView::SelectRows - - - QAbstractItemView::ScrollPerPixel - - - QAbstractItemView::ScrollPerPixel - - - false - - - false - - - false - - - 20 - - - 200 - - - false - - - false - - - - - - 0 - 0 - - - - Qt::ActionsContextMenu - - - Press [Delete] key to remove file from the list. -Press [Ctrl + A] key to apply custom resolution. -Press [Ctrl + C] key to cancel custom resolution. - -Right click to show more options. - - - QTableView{ -selection-background-color: rgb(178, 58, 238); -} - - - false - - - 0 - - - QAbstractItemView::NoEditTriggers - - - QAbstractItemView::SingleSelection - - - QAbstractItemView::SelectRows - - - QAbstractItemView::ScrollPerPixel - - - QAbstractItemView::ScrollPerPixel - - - false - - - false - - - false - - - 20 - - - 200 - - - false - - - - - - 0 - 90 - - - - - Arial - 13 - 50 - false - false - - - - When the software is running with administrator rights, -you will not be able to drag and drop files into the window. - -If this happens, please unauthorize the software or reinstall the -software into a directory that can run normally without administrator rights. - - - - - - QFrame::Box - - - QFrame::Plain - - - 1 - - - <html><head/><body><p>Drag and drop files or folders here</p><p>(Image, Animated Image<span style=" vertical-align:super;">GIF, APNG</span> and Video)</p></body></html> - - - Qt::AlignCenter - - - - - - - - - 0 - 0 - - - - - - - - - - QFrame::Box - - - QFrame::Plain - - - 0 - - - File count: 0 - - - Qt::AlignCenter - - - 5 - - - false - - - - - - - - 0 - 0 - - - - - 16777215 - 16777215 - - - - QFrame::NoFrame - - - QFrame::Raised - - - - 0 - - - 0 - - - 0 - - - 0 - - - - - - 0 - 0 - - - - - 35 - 35 - - - - - 16777215 - 16777215 - - - - Read Files List - - - QPushButton{ -image: url(:/new/prefix1/icon/Read_FileList.png); -border-style:transparent; -border-radius:0px; -padding:0px; -} -QPushButton:hover{ -image: url(:/new/prefix1/icon/Read_FileList_hover.png); -border-style:transparent; -border-radius:0px; -padding:0px; -} -QPushButton:pressed{ -image: url(:/new/prefix1/icon/Read_FileList.png); -border-style:transparent; -border-radius:0px; -padding:0px; -} -QPushButton:disabled{ -image: url(:/new/prefix1/icon/Read_FileList_disabled.png); -border-style:transparent; -border-radius:0px; -padding:0px; -} - - - - - - - 35 - 35 - - - - - - - - QFrame::Sunken - - - 1 - - - Qt::Vertical - - - - - - - Qt::Vertical - - - - - - - - 0 - 0 - - - - - 35 - 35 - - - - Reset Files List scale. - - - QPushButton{ -image: url(:/new/prefix1/icon/ResizeFilesListSplitter.png); -border-style:transparent; -border-radius:0px; -padding:0px; -} -QPushButton:hover{ -image: url(:/new/prefix1/icon/ResizeFilesListSplitter_hover.png); -border-style:transparent; -border-radius:0px; -padding:0px; -} -QPushButton:pressed{ -image: url(:/new/prefix1/icon/ResizeFilesListSplitter.png); -border-style:transparent; -border-radius:0px; -padding:0px; -} -QPushButton:disabled{ -image: url(:/new/prefix1/icon/ResizeFilesListSplitter_disabled.png); -border-style:transparent; -border-radius:0px; -padding:0px; -} - - - - - - - - - - - 0 - 0 - - - - - 35 - 35 - - - - - 16777215 - 16777215 - - - - Qt::ActionsContextMenu - - - Remove the selected file from File List. - -[Right click here to show more options] - - - QPushButton{ -image: url(:/new/prefix1/icon/RemoveItem.png); -border-style:transparent; -border-radius:0px; -padding:0px; -} -QPushButton:hover{ -image: url(:/new/prefix1/icon/RemoveItem_hover.png); -border-style:transparent; -border-radius:0px; -padding:0px; -} -QPushButton:pressed{ -image: url(:/new/prefix1/icon/RemoveItem.png); -border-style:transparent; -border-radius:0px; -padding:0px; -} -QPushButton:disabled{ -image: url(:/new/prefix1/icon/RemoveItem_disabled.png); -border-style:transparent; -border-radius:0px; -padding:0px; -} - - - - - - - - - - - 0 - 0 - - - - - 35 - 35 - - - - Browse and add files. - - - QPushButton{ -image: url(:/new/prefix1/icon/AddNewFile.png); -border-style:transparent; -border-radius:0px; -padding:0px; -} -QPushButton:hover{ -image: url(:/new/prefix1/icon/AddNewFile_hover.png); -border-style:transparent; -border-radius:0px; -padding:0px; -} -QPushButton:pressed{ -image: url(:/new/prefix1/icon/AddNewFile.png); -border-style:transparent; -border-radius:0px; -padding:0px; -} -QPushButton:disabled{ -image: url(:/new/prefix1/icon/AddNewFile_disabled.png); -border-style:transparent; -border-radius:0px; -padding:0px; -} - - - - - - - - - - Qt::Vertical - - - - - - - - 0 - 0 - - - - - 35 - 35 - - - - - 16777215 - 16777215 - - - - Remove all the files in the File list. - - - QPushButton{ -image: url(:/new/prefix1/icon/ClearList.png); -border-style:transparent; -border-radius:0px; -padding:0px; -} -QPushButton:hover{ -image: url(:/new/prefix1/icon/ClearList_hover.png); -border-style:transparent; -border-radius:0px; -padding:0px; -} -QPushButton:pressed{ -image: url(:/new/prefix1/icon/ClearList.png); -border-style:transparent; -border-radius:0px; -padding:0px; -} -QPushButton:disabled{ -image: url(:/new/prefix1/icon/ClearList_disabled.png); -border-style:transparent; -border-radius:0px; -padding:0px; -} - - - - - - - - - - - 0 - 0 - - - - - 35 - 35 - - - - Save Files List - - - QPushButton{ -image: url(:/new/prefix1/icon/Save_FileList.png); -border-style:transparent; -border-radius:0px; -padding:0px; -} -QPushButton:hover{ -image: url(:/new/prefix1/icon/Save_FileList_hover.png); -border-style:transparent; -border-radius:0px; -padding:0px; -} -QPushButton:pressed{ -image: url(:/new/prefix1/icon/Save_FileList.png); -border-style:transparent; -border-radius:0px; -padding:0px; -} -QPushButton:disabled{ -image: url(:/new/prefix1/icon/Save_FileList_disabled.png); -border-style:transparent; -border-radius:0px; -padding:0px; -} - - - - - - - 35 - 35 - - - - - - - - - 0 - 0 - - - - - 35 - 35 - - - - Turn off screen. - -We recommand you to use this button to turn off screen -while program is running. Using other methods to turn off -the screen may cause the software to freeze during the screen -shutdown. And we recommend that you turn off the automatic -shutdown screen and automatic sleep of the Windows system while -the software is running. - - - 60000 - - - QPushButton{ -image: url(:/new/prefix1/icon/TurnOffScreen.png); -border-style:transparent; -border-radius:0px; -padding:0px; -} -QPushButton:hover{ -image: url(:/new/prefix1/icon/TurnOffScreen_hover.png); -border-style:transparent; -border-radius:0px; -padding:0px; -} -QPushButton:pressed{ -image: url(:/new/prefix1/icon/TurnOffScreen.png); -border-style:transparent; -border-radius:0px; -padding:0px; -} -QPushButton:disabled{ -image: url(:/new/prefix1/icon/TurnOffScreen_disabled.png); -border-style:transparent; -border-radius:0px; -padding:0px; -} - - - - - - - - - - Qt::Vertical - - - - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - - 0 - 0 - - - - - - - QPushButton{ -background-color: rgb(52, 152, 219); -color: rgb(255, 255, 255); -border-style:outset; -border-radius:8px; -padding:10px; -} -QPushButton:hover{ -background-color: rgb(60, 177, 255); -color: rgb(255, 255, 255); -border-style:outset; -border-radius:8px; -padding:10px; -} -QPushButton:pressed{ -background-color: rgb(45, 134, 193); -color: rgb(255, 255, 255); -border-style:outset; -border-radius:8px; -padding:10px; -} -QPushButton:disabled{ -background-color: rgb(166, 166, 166); -color: rgb(255, 255, 255); -border-style:outset; -border-radius:8px; -padding:10px; -} - - - Hide settings - - - - - - - - 0 - 0 - - - - QPushButton{ -background-color: rgb(178, 58, 238); -color: rgb(255, 255, 255); -border-style:outset; -border-radius:8px; -padding:10px; -} -QPushButton:hover{ -background-color: rgb(191, 62, 255); -color: rgb(255, 255, 255); -border-style:outset; -border-radius:8px; -padding:10px; -} -QPushButton:pressed{ -background-color: rgb(154, 50, 205); -color: rgb(255, 255, 255); -border-style:outset; -border-radius:8px; -padding:10px; -} -QPushButton:disabled{ -background-color: rgb(166, 166, 166); -color: rgb(255, 255, 255); -border-style:outset; -border-radius:8px; -padding:10px; -} - - - Hide Text Browser - - - - - - - - - 0 - 0 - - - - - 0 - 0 - - - - - 16777215 - 305 - - - - - - - - 6 - - - 6 - - - 6 - - - 6 - - - - - 5 - - - - - - 0 - 0 - - - - - 16777215 - 16777215 - - - - - - - Custom resolution - - - Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter - - - - 6 - - - 6 - - - 6 - - - 6 - - - 5 - - - - - - 0 - 0 - - - - Width: - - - - - - - 2 - - - QLayout::SetDefaultConstraint - - - - - - 0 - 0 - - - - - 16777215 - 16777215 - - - - <html><head/><body><p><img src=":/new/prefix1/OtherPic/AspectRatioStrategy.jpg"/></p></body></html> - - - Aspect Ratio: - - - Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter - - - - - - - - 280 - 0 - - - - <html><head/><body><p><img src=":/new/prefix1/OtherPic/AspectRatioStrategy.jpg"/></p></body></html> - - - 1 - - - - Ignore Aspect Ratio - - - - - Keep Aspect Ratio - - - - - Keep Aspect Ratio By Expanding - - - - - - - - - - - 0 - 0 - - - - Height: - - - - - - - pixels - - - 1 - - - 999999999 - - - 1080 - - - - - - - pixels - - - 1 - - - 999999999 - - - 1920 - - - - - - - - - 1.Set the height and width of the resolution. -2.Select a file in the file list. -3.Click the Apply button to set the resolution. - -★Scale ratio will not be applied to files which -already have custom resolution applied.★ - - - QPushButton{ -background-color: rgb(26, 188, 156); -color: rgb(255, 255, 255); -border-style:outset; -border-radius:8px; -padding:10px; -} -QPushButton:hover{ -background-color: rgb(29, 214, 177); -color: rgb(255, 255, 255); -border-style:outset; -border-radius:8px; -padding:10px; -} -QPushButton:pressed{ -background-color: rgb(23, 173, 143); -color: rgb(255, 255, 255); -border-style:outset; -border-radius:8px; -padding:10px; -} -QPushButton:disabled{ -background-color: rgb(166, 166, 166); -color: rgb(255, 255, 255); -border-style:outset; -border-radius:8px; -padding:10px; -} - - - Apply - - - - - - - 1.Select a file in the file list. -2.Click the Cancel button to cancel the custom resolution. - - - QPushButton{ -background-color: rgb(231, 76, 60); -color: rgb(255, 255, 255); -border-style:outset; -border-radius:8px; -padding:10px; -} -QPushButton:hover{ -background-color: rgb(255, 102, 64); -color: rgb(255, 255, 255); -border-style:outset; -border-radius:8px; -padding:10px; -} -QPushButton:pressed{ -background-color: rgb(204, 65, 53); -color: rgb(255, 255, 255); -border-style:outset; -border-radius:8px; -padding:10px; -} -QPushButton{ -background-color: rgb(231, 76, 60); -color: rgb(255, 255, 255); -border-style:outset; -border-radius:8px; -padding:10px; -} -QPushButton:hover{ -background-color: rgb(255, 102, 64); -color: rgb(255, 255, 255); -border-style:outset; -border-radius:8px; -padding:10px; -} -QPushButton:disabled{ - background-color: rgb(166, 166, 166); -color: rgb(255, 255, 255); -border-style:outset; -border-radius:8px; -padding:10px; -} - - - Cancel - - - - - - - - - - 0 - 0 - - - - Automatically skip file when its resolution -is larger than the specified resolution. - - - Auto Skip - - - - - - - - 0 - 0 - - - - Valid for all files. - - - Apply to all - - - - - - - - - - - 0 - 0 - - - - - 16777215 - 16777215 - - - - - - - - 6 - - - 6 - - - 6 - - - 6 - - - - - true - - - - 0 - 0 - - - - - 0 - 45 - - - - - 16777215 - 16777215 - - - - QFrame::StyledPanel - - - QFrame::Raised - - - - QLayout::SetDefaultConstraint - - - 0 - - - 0 - - - 0 - - - 0 - - - 7 - - - - - - 0 - 0 - - - - Image quality: - - - - - - - Only takes effect when processing Static Image. - -Will NOT take effect when processing Video and GIF. - - - 1 - - - 100 - - - 100 - - - - - - - - - - - 16777215 - 16777215 - - - - Select the image style of the source files. -So the engine can load the correct model when processing files. - - - Image Style(waifu2x-ncnn-vulkan): - - - Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter - - - - - - - Select the image style of the source files. -So the engine can load the correct model when processing files. - - - Image Style(waifu2x-caffe): - - - - - - - true - - - - 0 - 0 - - - - - 0 - 45 - - - - - 16777215 - 16777215 - - - - QFrame::NoFrame - - - QFrame::Plain - - - 0 - - - - 0 - - - 0 - - - 0 - - - 0 - - - 7 - - - - - Only takes effect when processing Static Image. - -Will NOT take effect when processing Video and GIF. - - - 0 - - - 15 - - - - png - - - - - jpg - - - - - webp - - - - - bmp - - - - - tiff - - - - - pdf - - - - - gif - - - - - eps - - - - - tga - - - - - jp2 - - - - - svg - - - - - - - - Save image as: - - - - - - - - - - - 120 - 0 - - - - Select the image style of the source files. -So the engine can load the correct model when processing files. - - - 2D Anime - - - - 2D Anime - - - - - 3D Real-life - - - - - - - - Select the image style of the source files. -So the engine can load the correct model when processing files. - - - - 2D Anime - - - - - 3D Real-life - - - - - - - - - 0 - 0 - - - - - 0 - 0 - - - - QFrame::StyledPanel - - - QFrame::Raised - - - - 0 - - - 0 - - - 0 - - - 0 - - - 3 - - - 0 - - - - - - 0 - 0 - - - - Qt::ActionsContextMenu - - - Delete the original file after processing is complete. - -*This option will be deactivated when [Replace original -file] is enabled* - -[Right click here to show more options] - - - Delete original files - - - - - - - - 0 - 0 - - - - Qt::ActionsContextMenu - - - After processing the file, directly replace -the original file with the result file. -(And keep the original file name.) - -WARNING: The original file will be DELETED. - -*This option will be deactivated when [Output -path] or [Delete original files] is enabled* - -[Right click here to show more options] - - - Replace original file - - - - - - - - 0 - 0 - - - - Optimizing the scaled gif will slightly reduce the -image quality, but it can reduce the GIF file size. - -It is recommended to enable this option. - - - Optimize GIF - - - - - - - - - - Select the action to be executed automatically -after processing all files in the file list. - - - - Do nothing(when finished) - - - - - Shut down - - - - - Sleep - - - - - Hibernate - - - - - Restart - - - - - - - - When there are finished files in the list, the finished files will -be processed again when the processing process is started again. - - - Re-process finished files - - - - - - - false - - - - 50 - false - - - - Skip the super-resolution, only interpolate video frames. - -You can modify the settings of Frame Interpolation in the -[Video settings] tab. - -*Only taken effect when processing video* - - - - - - Frame Interpolation only(Video) - - - - - - - Interpolate frames after super-resolution of the video. -(Increase the frame rate to the result video.) - -You can modify the settings of Frame Interpolation -in the [Video settings] tab. - -You can enable [Frame Interpolation only(Video)] to skip -the super-resolution, only interpolate video frames. - -*Only taken effect when processing video* - - - color: rgb(33, 85, 255); - - - Video Frame Interpolation - - - - - - - - - - - 0 - 0 - - - - - 16777215 - 16777215 - - - - Output path(Folder): - - - false - - - - 6 - - - 6 - - - 6 - - - 6 - - - - - false - - - Qt::StrongFocus - - - Qt::ActionsContextMenu - - - Output path must be a Folder. - -[Right click here to show more options] - - - - - - true - - - - - - - - 0 - 0 - - - - background-color: rgb(255, 255, 255); - - - QFrame::Sunken - - - QAbstractScrollArea::AdjustIgnored - - - true - - - - - 0 - 0 - 241 - 122 - - - - - - - false - - - - 0 - 0 - - - - Keep original file name - - - - - - - - - - 0 - 0 - - - - When this option is enabled, the output file -will be moved to the path you specified. -Otherwise, it will be saved in the same -folder as the source file. - -*This option will be deactivated when [Replace -original file] is enabled* - - - Enabled - - - - - - - false - - - - 0 - 0 - - - - When this option is enabled, the output file will -replace the file with the same name as the output -file that exists in the output path. - - - Overwrite - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - - - false - - - - 0 - 0 - - - - Keep parent folder - - - - - - - false - - - Automatically open the output folder -after processing all files. - - - Auto-open after finished - - - - - - - - - - - - - - - - - 0 - 0 - - - - - 0 - 0 - - - - - 16777215 - 85 - - - - - - - Qt::AlignCenter - - - true - - - false - - - - - - QFrame::Plain - - - Qt::Vertical - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - - - - - - 0 - 0 - - - - color: rgb(255, 70, 14); - - - Scale ratio: - - - - - - - - 0 - 0 - - - - Range: 1 ~ 999999999 - - - Image - - - - - - - 4 - - - 1.000000000000000 - - - 99999.000000000000000 - - - 2.000000000000000 - - - - - - - Qt::Vertical - - - - - - - - 0 - 0 - - - - Range: 1 ~ 999999999 - - - Animated Image - - - - - - - 4 - - - 1.000000000000000 - - - 99999.000000000000000 - - - 2.000000000000000 - - - - - - - Qt::Vertical - - - - - - - - 0 - 0 - - - - Range: 1 ~ 999999999 - - - Video - - - - - - - 4 - - - 1.000000000000000 - - - 99999.000000000000000 - - - 2.000000000000000 - - - - - - - - - QFrame::Plain - - - Qt::Horizontal - - - - - - - - - - 0 - 0 - - - - color: rgb(33, 85, 254); - - - Deoise level: - - - - - - - - 0 - 0 - - - - Image - - - - - - - true - - - Qt::WheelFocus - - - -1 - - - 3 - - - 1 - - - QAbstractSpinBox::DefaultStepType - - - 2 - - - 10 - - - - - - - Qt::Vertical - - - - - - - - 0 - 0 - - - - Animated Image - - - - - - - true - - - Qt::WheelFocus - - - -1 - - - 3 - - - 1 - - - QAbstractSpinBox::DefaultStepType - - - 2 - - - 10 - - - - - - - Qt::Vertical - - - - - - - - 0 - 0 - - - - Video - - - - - - - true - - - Qt::WheelFocus - - - -1 - - - 3 - - - 1 - - - QAbstractSpinBox::DefaultStepType - - - 2 - - - 10 - - - - - - - - - - - - - - 0 - 0 - - - - You need to enable [Video Frame Interpolation] to use this option. - -If the fps of orignal video is 30 fps, multiple of fps is "4", -then the result video will be 120 fps. - - - Multiple of FPS: - - - - - - - - - - 30 - 16777215 - - - - - - - - - - - - Qt::NoFocus - - - You need to enable [Video Frame Interpolation] to use this option. - -If the fps of orignal video is 30 fps, multiple of fps is "4", -then the result video will be 120 fps. - - - false - - - true - - - QAbstractSpinBox::NoButtons - - - false - - - 2 - - - 999999999 - - - 0 - - - - - - - - 0 - 0 - - - - - 30 - 16777215 - - - - + - - - - - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - - - - - - - - - - :/new/prefix1/icon/EngineSettings.png:/new/prefix1/icon/EngineSettings.png - - - Engine settings - - - - 6 - - - 6 - - - 6 - - - 6 - - - 0 - - - - - true - - - - 0 - 0 - - - - - 16777215 - 16777215 - - - - - - - Number of threads - - - Qt::AlignCenter - - - false - - - - 6 - - - 6 - - - 6 - - - 6 - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - - 0 - 0 - - - - QFrame::NoFrame - - - QFrame::Raised - - - - 0 - - - 0 - - - 0 - - - 0 - - - - - - 0 - 0 - - - - - 16777215 - 16777215 - - - - - - - - - - - - - Image: - - - - - - - Qt::Vertical - - - - - - - - 0 - 0 - - - - - 16777215 - 16777215 - - - - - - - Video: - - - - - - - Qt::Vertical - - - - - - - - 0 - 0 - - - - The number of threads that the software processes GIF, -which will determine how many frames the software will -process at the same time. - -The actual maximum number of threads is limited by the -number of enabled GPUs when using Anime4k, Waifu2x-Caffe -and Waifu2x-converter.(Only when processing GIF and Video) - - - 1 - - - 999999999 - - - 1 - - - 1 - - - - - - - - 0 - 0 - - - - The number of threads that the software processes Video, -which will determine how many frames the software will -process at the same time. - -The actual maximum number of threads is limited by the -number of enabled GPUs when using Anime4k, Waifu2x-Caffe -and Waifu2x-converter.(Only when processing GIF and Video) - - - 1 - - - 999999999 - - - 1 - - - 1 - - - - - - - - 0 - 0 - - - - - 16777215 - 16777215 - - - - - - - Animated Image: - - - - - - - - 0 - 0 - - - - The number of threads that the software processes Image, -which will determine how many images the software will -process at the same time. - - - 1 - - - 999999999 - - - 1 - - - 1 - - - - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - - - - - 0 - 0 - - - - Engine - - - Qt::AlignCenter - - - false - - - false - - - - 6 - - - 6 - - - 6 - - - 6 - - - - - Qt::Horizontal - - - - - - - - 0 - 0 - - - - QFrame::NoFrame - - - QFrame::Raised - - - - 0 - - - 0 - - - 0 - - - 0 - - - - - - 0 - 0 - - - - QFrame::NoFrame - - - QFrame::Raised - - - - 0 - - - 0 - - - 0 - - - 0 - - - - - - 0 - 0 - - - - - 16777215 - 16777215 - - - - Animated Image: - - - Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter - - - - - - - Qt::Vertical - - - - - - - true - - - - 190 - 0 - - - - Waifu2x-NCNN-Vulkan [Speed:★★ Image quality:★★★] [2D Anime]&[3D Real-life] -Waifu2x-Converter [Speed:★☆ Image quality:★★☆] [2D Anime] -Anime4K [Speed:★★★ Image quality:★☆ ] [2D Anime] -SRMD-NCNN-Vulkan [Speed:★☆ Image quality:★★★] [2D Anime]&[3D Real-life] -Waifu2x-Caffe [Speed:★☆ Image quality:★★★] [2D Anime]&[3D Real-life] -RealSR-NCNN-Vulkan [Speed:☆ Image quality:★★★] [3D Real-life] -SRMD-CUDA [Speed:★★☆ Image quality:★★★] [2D Anime]&[3D Real-life] - - - waifu2x-ncnn-vulkan - - - QComboBox::AdjustToContents - - - - waifu2x-ncnn-vulkan - - - - - waifu2x-converter - - - - - srmd-ncnn-vulkan - - - - - Anime4K - - - - - waifu2x-caffe - - - - - realsr-ncnn-vulkan - - - - - [BETA] srmd-cuda - - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - - 0 - 0 - - - - - 16777215 - 16777215 - - - - Image: - - - Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter - - - - - - - - 0 - 0 - - - - - 16777215 - 16777215 - - - - Video: - - - Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter - - - - - - - Qt::Vertical - - - - - - - true - - - - 190 - 0 - - - - Waifu2x-NCNN-Vulkan [Speed:★★ Image quality:★★★] [2D Anime]&[3D Real-life] -Waifu2x-Converter [Speed:★☆ Image quality:★★☆] [2D Anime] -Anime4K [Speed:★★★ Image quality:★☆ ] [2D Anime] -SRMD-NCNN-Vulkan [Speed:★☆ Image quality:★★★] [2D Anime]&[3D Real-life] -Waifu2x-Caffe [Speed:★☆ Image quality:★★★] [2D Anime]&[3D Real-life] -RealSR-NCNN-Vulkan [Speed:☆ Image quality:★★★] [3D Real-life] -SRMD-CUDA [Speed:★★☆ Image quality:★★★] [2D Anime]&[3D Real-life] - - - waifu2x-ncnn-vulkan - - - QComboBox::AdjustToContents - - - - waifu2x-ncnn-vulkan - - - - - waifu2x-converter - - - - - Anime4k - - - - - srmd-ncnn-vulkan - - - - - waifu2x-caffe - - - - - realsr-ncnn-vulkan - - - - - [BETA] srmd-cuda - - - - - - - - true - - - - 190 - 0 - - - - - 16777215 - 16777215 - - - - Waifu2x-NCNN-Vulkan [Speed:★★ Image quality:★★★] [2D Anime]&[3D Real-life] -Waifu2x-Converter [Speed:★☆ Image quality:★★☆] [2D Anime] -Anime4K [Speed:★★★ Image quality:★☆ ] [2D Anime] -SRMD-NCNN-Vulkan [Speed:★☆ Image quality:★★★] [2D Anime]&[3D Real-life] -Waifu2x-Caffe [Speed:★☆ Image quality:★★★] [2D Anime]&[3D Real-life] -RealSR-NCNN-Vulkan [Speed:☆ Image quality:★★★] [3D Real-life] -SRMD-CUDA [Speed:★★☆ Image quality:★★★] [2D Anime]&[3D Real-life] - - - waifu2x-ncnn-vulkan - - - QComboBox::AdjustToContents - - - - waifu2x-ncnn-vulkan - - - - - waifu2x-converter - - - - - srmd-ncnn-vulkan - - - - - Anime4K - - - - - waifu2x-caffe - - - - - realsr-ncnn-vulkan - - - - - [BETA] srmd-cuda - - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - - - - - - - - - - QTabWidget::North - - - 0 - - - false - - - - Waifu2x-ncnn-vulkan - - - Waifu2x-NCNN-Vulkan: - -- Supports [2D Anime] and [3D Real-life] image style. But not at the -same time, you need to change [Image style] settings at [Home] tab. - -- More suitable for processing [2D Anime] image. - -- [ Speed:★★ Image Quality:★★★ ] - - - - 6 - - - 6 - - - 6 - - - 6 - - - 7 - - - - - - - - 0 - 0 - - - - Select the GPU to use when enabling the "waifu2x-ncnn-vulkan" engine. - - - GPU ID: - - - - - - - true - - - - 0 - 0 - - - - - 180 - 0 - - - - Select the GPU to use when enabling the "waifu2x-ncnn-vulkan" engine. -★ "-1" is CPU,others are GPUs ★ - - - auto - - - - auto - - - - - - - - true - - - - 0 - 0 - - - - QPushButton{ -background-color: rgb(178, 58, 238); -color: rgb(255, 255, 255); -border-style:outset; -border-radius:8px; -padding:10px; -} -QPushButton:hover{ -background-color: rgb(191, 62, 255); -color: rgb(255, 255, 255); -border-style:outset; -border-radius:8px; -padding:10px; -} -QPushButton:pressed{ -background-color: rgb(154, 50, 205); -color: rgb(255, 255, 255); -border-style:outset; -border-radius:8px; -padding:10px; -} -QPushButton:disabled{ -background-color: rgb(166, 166, 166); -color: rgb(255, 255, 255); -border-style:outset; -border-radius:8px; -padding:10px; -} - - - Detect available GPU ID - - - - - - - - 0 - 0 - - - - 1.You need at least 2 available GPUs. - -2.If you wanna get all GPUs running together, -the number of threads must >= the number of GPUs. - -3.You need to [Detect available GPU ID] first. - -*Only latest version fully supports Multi-GPU* - - - Enable Multi-GPU - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - - - - - - 0 - 0 - - - - - 16777215 - 16777215 - - - - Tile size: This value will affects GPU memory usage. -Larger tile size means waifu2x will use more GPU memory and run faster. -Smaller tile size means waifu2x will use less GPU memory and run slower. -(Only works when using "waifu2x-ncnn-vulkan" engine.) - - - Tile size: - - - - - - - - 0 - 0 - - - - QFrame::NoFrame - - - QFrame::Raised - - - - QLayout::SetDefaultConstraint - - - 0 - - - 0 - - - 0 - - - 0 - - - - - - 0 - 0 - - - - - 30 - 30 - - - - - - - - - - - - - 0 - 0 - - - - Tile size: This value will affects GPU memory usage. -Larger Tile size means waifu2x will use more GPU memory and run faster. -Smaller Tile size means waifu2x will use less GPU memory and run slower. - - - 32 - - - 999999999 - - - 10 - - - 128 - - - - - - - - 0 - 0 - - - - - 30 - 30 - - - - + - - - - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - - - 0 - - - - - false - - - - 0 - 0 - - - - - 16777215 - 16777215 - - - - GPU Settings(Multi-GPU) - - - Qt::AlignCenter - - - true - - - - 0 - - - 6 - - - 0 - - - 6 - - - 7 - - - - - - - - - - - - 32 - - - 999999999 - - - 10 - - - 128 - - - - - - - - 0 - 0 - - - - Enable - - - true - - - - - - - Show current Multi-GPU settings. - - - QPushButton{ -background-color: rgb(231, 76, 60); -color: rgb(255, 255, 255); -border-style:outset; -border-radius:8px; -padding:10px; -} -QPushButton:hover{ -background-color: rgb(255, 102, 64); -color: rgb(255, 255, 255); -border-style:outset; -border-radius:8px; -padding:10px; -} -QPushButton:pressed{ -background-color: rgb(204, 65, 53); -color: rgb(255, 255, 255); -border-style:outset; -border-radius:8px; -padding:10px; -} -QPushButton:disabled{ -background-color: rgb(166, 166, 166); -color: rgb(255, 255, 255); -border-style:outset; -border-radius:8px; -padding:10px; -} - - - Show GPUs Settings - - - - - - - - 0 - 0 - - - - Tile size: - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - - - - - - 0 - 0 - - - - GPU ID: - - - Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter - - - - - - - Qt::Vertical - - - - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - - - Qt::Horizontal - - - - - - - Qt::Horizontal - - - - - - - - - - 0 - 0 - - - - Version: - - - - - - - 0 - - - - Latest(Alpha channel,TTA,Multi-GPU) - - - - - 20200414-fp16p(TTA,Multi-GPU(Image only)) - - - - - Old(Multi-GPU(Image only)) - - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - - - - - - 0 - 0 - - - - Model: - - - - - - - We recommend you use the default "upconv_7" model. -Only "upconv_7" model supports image style switching. -"cunet" model only supports 2D anime image style, -and it's much more slower than "upconv_7" model. - - - - upconv_7 - - - - - cunet(Only support 2D Anime) - - - - - - - - - 0 - 0 - - - - TTA(Test-Time Augmentation): -The processing time is eight times longer than when unchecked, -and the peak signal-to-noise ratio (PSNR) is increased by 0.15, -but the effect may not be obvious. It is not recommended to enable it. -[TTA] is not available for [OLD Version] of waifu2x-ncnn-vulkan. - - - TTA - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - - - Qt::Horizontal - - - - - - - - Waifu2x-converter - - - Waifu2x-Converter: - -- Only supports [2D Anime] image style. - -- [ Speed:★☆ Image Quality:★★☆ ] - - - - 6 - - - 6 - - - 6 - - - 6 - - - 7 - - - - - Qt::Horizontal - - - - - - - - - - 0 - 0 - - - - Force to use OpenCL on Intel Platform. - - - Force OpenCL - - - - - - - - 0 - 0 - - - - Disable GPU - - - - - - - - 0 - 0 - - - - TTA(Test-Time Augmentation): -The processing time is eight times longer than when unchecked, -and the peak signal-to-noise ratio (PSNR) is increased by 0.15, -but the effect may not be obvious. It is not recommended to enable it. - - - TTA - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - - - Qt::Horizontal - - - - - - - - - - 0 - 0 - - - - Target processor: - - - - - - - true - - - - 180 - 0 - - - - auto - - - - auto - - - - - - - - true - - - - 0 - 0 - - - - QPushButton{ - background-color: rgb(238, 119, 133); -color: rgb(255, 255, 255); -border-style:outset; -border-radius:8px; -padding:10px; -} -QPushButton:hover{ - background-color: rgb(255, 127, 144); -color: rgb(255, 255, 255); -border-style:outset; -border-radius:8px; -padding:10px; -} -QPushButton:pressed{ - background-color: rgb(226, 112, 128); -color: rgb(255, 255, 255); -border-style:outset; -border-radius:8px; -padding:10px; -} -QPushButton:disabled{ -background-color: rgb(166, 166, 166); -color: rgb(255, 255, 255); -border-style:outset; -border-radius:8px; -padding:10px; -} - - - Dump processor list - - - - - - - - 0 - 0 - - - - 1.You need at least 2 available processors. - -2.If you wanna get all processors running together, -the number of threads must >= the number of processors. - -3.You need to [Dump processor list] first. - - - Enable Multi-Processor - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - - - - - - 0 - 0 - - - - Block size: This value will affects GPU memory usage. -Larger Block size means waifu2x will use more GPU memory and run faster. -Smaller Block size means waifu2x will use less GPU memory and run slower. - - - Block size: - - - - - - - - 0 - 0 - - - - QFrame::NoFrame - - - QFrame::Raised - - - - 0 - - - 0 - - - 0 - - - 0 - - - - - - 30 - 30 - - - - - - - - - - - - Block size: This value will affects GPU memory usage. -Larger Block size means waifu2x will use more GPU memory and run faster. -Smaller Block size means waifu2x will use less GPU memory and run slower. - - - 32 - - - 999999999 - - - 10 - - - 256 - - - - - - - - 30 - 30 - - - - + - - - - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - - - - - false - - - - 0 - 0 - - - - - 16777215 - 16777215 - - - - Processor Settings(Multi-Processor) - - - Qt::AlignCenter - - - true - - - - 6 - - - 6 - - - 6 - - - 6 - - - - - Show current Multi-Processor settings. - - - QPushButton{ -background-color: rgb(231, 76, 60); -color: rgb(255, 255, 255); -border-style:outset; -border-radius:8px; -padding:10px; -} -QPushButton:hover{ -background-color: rgb(255, 102, 64); -color: rgb(255, 255, 255); -border-style:outset; -border-radius:8px; -padding:10px; -} -QPushButton:pressed{ -background-color: rgb(204, 65, 53); -color: rgb(255, 255, 255); -border-style:outset; -border-radius:8px; -padding:10px; -} -QPushButton:disabled{ -background-color: rgb(166, 166, 166); -color: rgb(255, 255, 255); -border-style:outset; -border-radius:8px; -padding:10px; -} - - - Show Processor Settings - - - - - - - - 0 - 0 - - - - Processor ID: - - - Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter - - - - - - - - 0 - 0 - - - - Block size: - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - - - - - - - - - - - - - 0 - 0 - - - - Enable - - - true - - - - - - - 32 - - - 999999999 - - - 10 - - - 256 - - - - - - - Qt::Vertical - - - - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - - - - - 0 - 0 - - - - Anime4K - - - Anime4K: - -- Only supports [2D Anime] image style. - -- More suitable for image with not too bad quality. - -- You can enable [ACNet] algorithm to improve image quality. - -- Although [GPU Mode] is not enabled by default, in most cases, -enabling [GPU Mode] can greatly increase the processing speed. -(Please make sure your PC is compatible with [GPU Mode] first) - -- [ Speed:★★★ Image Quality:★ ] - - - - 6 - - - 6 - - - 6 - - - 6 - - - - - - 0 - 0 - - - - QFrame::StyledPanel - - - QFrame::Raised - - - - 0 - - - 0 - - - 0 - - - 0 - - - - - false - - - - 0 - 0 - - - - OpenCL parallel IO command queue -*Enable this might cause compatibility problem* - - - OpenCL parallel IO - - - - - - - true - - - - 0 - 0 - - - - Enable ACNet. -Will improve image quality. - - - ACNet - - - - - - - false - - - - 0 - 0 - - - - Enable HDN mode for ACNet. -Will improve image quality. - -*This option will be deactivated -when [ACNet] is disabled* - - - HDN mode - - - true - - - - - - - - 0 - 0 - - - - Faster but maybe low quality. - - - Fast mode - - - - - - - OpenCL command queues: - - - - - - - false - - - - 0 - 0 - - - - Number of OpenCL command queues - - - 1 - - - 999999999 - - - - - - - Qt::Vertical - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - - - - Qt::Horizontal - - - - - - - - 0 - 0 - - - - QFrame::NoFrame - - - QFrame::Sunken - - - - 0 - - - 0 - - - 0 - - - 0 - - - - - false - - - - 0 - 0 - - - - - 230 - 0 - - - - Format: Platform ID,Device ID: - -Example: 0,0:0,1:1,0: - -You must follow the format,otherwise the software may crash. - -If you wanna get all GPUs running together, -the number of threads must >= the number of GPUs. - - - 0,0: - - - true - - - - - - - false - - - - 0 - 0 - - - - - 16777215 - 35 - - - - QPushButton{ -background-color: rgb(26, 188, 156); -color: rgb(255, 255, 255); -border-style:outset; -border-radius:8px; -padding:10px; -} -QPushButton:hover{ -background-color: rgb(29, 214, 177); -color: rgb(255, 255, 255); -border-style:outset; -border-radius:8px; -padding:10px; -} -QPushButton:pressed{ -background-color: rgb(23, 173, 143); -color: rgb(255, 255, 255); -border-style:outset; -border-radius:8px; -padding:10px; -} -QPushButton:disabled{ -background-color: rgb(166, 166, 166); -color: rgb(255, 255, 255); -border-style:outset; -border-radius:8px; -padding:10px; -} - - - List GPUs - - - - - - - false - - - - 0 - 0 - - - - - 130 - 0 - - - - GPGPU model. - -Only NVIDIA products support CUDA. - - - - OpenCL - - - - - CUDA - - - - - - - - Qt::Vertical - - - - - - - - 0 - 0 - - - - Enable GPU acceleration. - - - GPU Mode - - - - - - - false - - - - 0 - 0 - - - - Verify your GPUs configuration. - - - QPushButton{ -background-color: rgb(178, 58, 238); -color: rgb(255, 255, 255); -border-style:outset; -border-radius:8px; -padding:10px; -} -QPushButton:hover{ -background-color: rgb(191, 62, 255); -color: rgb(255, 255, 255); -border-style:outset; -border-radius:8px; -padding:10px; -} -QPushButton:pressed{ -background-color: rgb(154, 50, 205); -color: rgb(255, 255, 255); -border-style:outset; -border-radius:8px; -padding:10px; -} -QPushButton:disabled{ -background-color: rgb(166, 166, 166); -color: rgb(255, 255, 255); -border-style:outset; -border-radius:8px; -padding:10px; -} - - - Verify - - - - - - - false - - - - 0 - 0 - - - - You can specify multiple GPUs to fully -utilize the capabilities of your PC. -(If there are multiple GPUs available.) - - - Specify GPUs: - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - - - - Qt::Horizontal - - - - - - - - 0 - 0 - - - - - 16777215 - 42 - - - - - 0 - - - 0 - - - 0 - - - 0 - - - - - - 0 - 0 - - - - Strength for pushing color,range 0 to 1,higher for thinner. - - - Push color strength: - - - - - - - - 0 - 0 - - - - - 100 - 0 - - - - 1.000000000000000 - - - 0.100000000000000 - - - 1.000000000000000 - - - - - - - - 0 - 0 - - - - 1 - - - 999999999 - - - 2 - - - - - - - - 0 - 0 - - - - - 100 - 0 - - - - 1.000000000000000 - - - 0.100000000000000 - - - 0.300000000000000 - - - - - - - - 0 - 0 - - - - Passes for processing. - - - Passes: - - - - - - - - 0 - 0 - - - - 1 - - - 999999999 - - - 2 - - - - - - - - 0 - 0 - - - - Strength for pushing gradient,range 0 to 1,higher for sharper. - - - Push gradient strength: - - - - - - - - 0 - 0 - - - - Limit the number of color pushes. - - - Push color count: - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - - - - - - - 16777215 - 16777215 - - - - - - - Pre-processing - - - - 6 - - - 6 - - - 6 - - - 6 - - - - - Qt::Horizontal - - - - - - - Mean blur - - - - - - - Median blur - - - - - - - Gaussian blur weak - - - - - - - CAS Sharpening - - - true - - - - - - - Gaussian blur - - - - - - - Bilateral filter - - - - - - - Bilateral filter faster - - - - - - - Apply filters to image before process it. - - - Enable Pre-processing - - - true - - - - - - - - - - - - - Post-processing - - - - 6 - - - 6 - - - 6 - - - 6 - - - - - Add filters to the image after processing it. - - - Enable Post-processing - - - true - - - - - - - Qt::Horizontal - - - - - - - Median blur - - - - - - - Mean blur - - - - - - - CAS Sharpening - - - false - - - - - - - Gaussian blur - - - - - - - Bilateral filter - - - true - - - - - - - Gaussian blur weak - - - true - - - - - - - Bilateral filter faster - - - - - - - - - - - - - SRMD-ncnn-vulkan - - - SRMD-NCNN-Vulkan: - -- Supports [2D Anime] and [3D Real-life] image style at the same time. - -- More suitable for processing [3D Real-life] images. - -- [ Speed:★☆ Image Quality:★★★ ] - - - - 6 - - - 6 - - - 6 - - - 6 - - - 7 - - - - - - - false - - - - 0 - 0 - - - - - 16777215 - 16777215 - - - - GPU Settings(Multi-GPU) - - - Qt::AlignCenter - - - true - - - - 6 - - - 6 - - - 6 - - - 6 - - - - - - 0 - 0 - - - - Enable - - - true - - - - - - - - 0 - 0 - - - - Tile size: - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - - - - - - - - - - - - Show current Multi-GPU settings. - - - QPushButton{ -background-color: rgb(231, 76, 60); -color: rgb(255, 255, 255); -border-style:outset; -border-radius:8px; -padding:10px; -} -QPushButton:hover{ -background-color: rgb(255, 102, 64); -color: rgb(255, 255, 255); -border-style:outset; -border-radius:8px; -padding:10px; -} -QPushButton:pressed{ -background-color: rgb(204, 65, 53); -color: rgb(255, 255, 255); -border-style:outset; -border-radius:8px; -padding:10px; -} -QPushButton:disabled{ -background-color: rgb(166, 166, 166); -color: rgb(255, 255, 255); -border-style:outset; -border-radius:8px; -padding:10px; -} - - - Show GPUs Settings - - - - - - - 32 - - - 999999999 - - - 10 - - - 128 - - - - - - - - 0 - 0 - - - - GPU ID: - - - Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter - - - - - - - Qt::Vertical - - - - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - - - - - - 0 - 0 - - - - GPU ID: - - - - - - - - 180 - 0 - - - - Select the GPU to use when enabling the "srmd-ncnn-vulkan" engine. - - - auto - - - - auto - - - - - - - - - 0 - 0 - - - - QPushButton{ -background-color: rgb(52, 152, 219); -color: rgb(255, 255, 255); -border-style:outset; -border-radius:8px; -padding:10px; -} -QPushButton:hover{ -background-color: rgb(60, 177, 255); -color: rgb(255, 255, 255); -border-style:outset; -border-radius:8px; -padding:10px; -} -QPushButton:pressed{ -background-color: rgb(45, 134, 193); -color: rgb(255, 255, 255); -border-style:outset; -border-radius:8px; -padding:10px; -} -QPushButton:disabled{ -background-color: rgb(166, 166, 166); -color: rgb(255, 255, 255); -border-style:outset; -border-radius:8px; -padding:10px; -} - - - Detect available GPU ID - - - - - - - - 0 - 0 - - - - 1.You need at least 2 available GPUs. - -2.If you wanna get all GPUs running together, -the number of threads must >= the number of GPUs. - -3.You need to [Detect available GPU ID] first. - - - Enable Multi-GPU - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - - - - - - 0 - 0 - - - - Tile size: This value will affects GPU memory usage. -Larger tile size means SRMD will use more GPU memory and run faster. -Smaller tile size means SRMD will use less GPU memory and run slower. - - - Tile size: - - - - - - - - 0 - 0 - - - - QFrame::NoFrame - - - QFrame::Raised - - - - 0 - - - 0 - - - 0 - - - 0 - - - - - - 30 - 30 - - - - + - - - - - - - - 30 - 30 - - - - - - - - - - - - - 0 - 0 - - - - Tile size: This value will affects GPU memory usage. -Larger tile size means SRMD will use more GPU memory and run faster. -Smaller tile size means SRMD will use less GPU memory and run slower. - - - 32 - - - 999999999 - - - 10 - - - 128 - - - - - - - - - - - 0 - 0 - - - - TTA(Test-Time Augmentation): -The processing time is eight times longer than when unchecked, -and the peak signal-to-noise ratio (PSNR) is increased by 0.15, -but the effect may not be obvious. It is not recommended to enable it. - - - TTA - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - - - - 0 - 0 - - - - Qt::Horizontal - - - - - - - - Waifu2x-Caffe - - - Waifu2x-Caffe: - -- Supports [2D Anime] and [3D Real-life] image style. But not at the -same time, you need to change [Image style] settings at [Home] tab. - -- More suitable for processing [2D Anime] images. - -- When using [CPU Process mode], it's very slow, so only using this -engine when your PC is compatible with [GPU(or cuDNN) Process mode] -is recommended. - -- [ Speed:★☆ Image Quality:★★★ ] - - - - - - - - - 0 - 0 - - - - 3D Real-life Model: - - - - - - - - 220 - 0 - - - - Model for processing 3D Real-life style image. - - - upconv_7_photo - - - - upconv_7_photo - - - - - photo - - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - - - - - - 0 - 0 - - - - The batch size defines the number of samples that -will be propagated through the network. - - - Batch size: - - - - - - - - 120 - 0 - - - - The batch size defines the number of samples that -will be propagated through the network. - - - 1 - - - 999999999 - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - - - Qt::Horizontal - - - - - - - - - - 0 - 0 - - - - Process mode: - - - - - - - - 130 - 0 - - - - CPU - - - 0 - - - - CPU - - - - - GPU - - - - - cuDNN - - - - - - - - TTA(Test-Time Augmentation): -The processing time is eight times longer than when unchecked, -and the peak signal-to-noise ratio (PSNR) is increased by 0.15, -but the effect may not be obvious. It is not recommended to enable it. - - - TTA - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - - - - - false - - - - 0 - 0 - - - - You need to switch [Process mode] to -[GPU] or [cuDNN] to enable Multi-GPU. - - - Multi-GPU: - - - - - - - false - - - - 0 - 0 - - - - - 300 - 0 - - - - Format: GPU ID,Batch size,Split size: - -Example: 0,1,128:1,2,64:2,1,128: - -You must follow the format,otherwise the software may crash. - -If you wanna get all GPUs running together, -the number of threads must >= the number of GPUs. - - - 0,1,128: - - - true - - - - - - - false - - - - 0 - 0 - - - - Verify your GPUs configuration. - - - QPushButton{ -background-color: rgb(178, 58, 238); -color: rgb(255, 255, 255); -border-style:outset; -border-radius:8px; -padding:10px; -} -QPushButton:hover{ -background-color: rgb(191, 62, 255); -color: rgb(255, 255, 255); -border-style:outset; -border-radius:8px; -padding:10px; -} -QPushButton:pressed{ -background-color: rgb(154, 50, 205); -color: rgb(255, 255, 255); -border-style:outset; -border-radius:8px; -padding:10px; -} -QPushButton:disabled{ -background-color: rgb(166, 166, 166); -color: rgb(255, 255, 255); -border-style:outset; -border-radius:8px; -padding:10px; -} - - - Verify - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - - - Qt::Horizontal - - - - - - - Qt::Horizontal - - - - - - - Qt::Horizontal - - - - - - - - - - 0 - 0 - - - - 2D Anime Model: - - - - - - - Model for processing 2D Anime style image. - - - anime_style_art_rgb - - - 1 - - - - anime_style_art - - - - - anime_style_art_rgb - - - - - cunet - - - - - photo - - - - - upconv_7_anime_style_art_rgb - - - - - upconv_7_photo - - - - - upresnet10 - - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - - - - - - 0 - 0 - - - - GPU ID: - - - - - - - - 150 - 0 - - - - Select the GPU to use when enabling the "waifu2x-caffe" engine. - - - 999999999 - - - 1 - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - - - Qt::Horizontal - - - - - - - - - - 0 - 0 - - - - Split size: This value will affects GPU memory usage. -Larger Split size means waifu2x will use more GPU memory and run faster. -Smaller Split size means waifu2x will use less GPU memory and run slower. - - - Split size: - - - - - - - - 30 - 16777215 - - - - Decrease split size. - - - - - - - - - - - - 0 - 0 - - - - Split size: This value will affects GPU memory usage. -Larger Split size means waifu2x will use more GPU memory and run faster. -Smaller Split size means waifu2x will use less GPU memory and run slower. - - - true - - - QAbstractSpinBox::NoButtons - - - QAbstractSpinBox::CorrectToNearestValue - - - 1 - - - 999999999 - - - 128 - - - - - - - - 30 - 16777215 - - - - Increase split size. - - - + - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - - - Qt::Horizontal - - - - - - - - RealSR-ncnn-vulkan - - - RealSR-NCNN-Vulkan: - -- Only support [3D Real-life] image style. - -- Best engine for processing [3D Real-life] images. - -- Much more slower than other engines. - -- [ Speed:☆ Image Quality:★★★ ] - - - - 6 - - - 6 - - - 6 - - - 6 - - - 7 - - - - - Qt::Horizontal - - - - - - - Qt::Horizontal - - - - - - - - - - 0 - 0 - - - - Model: - - - - - - - - models-DF2K_JPEG(Supports denoise) - - - - - models-DF2K(Does NOT supports denoise) - - - - - - - - TTA(Test-Time Augmentation): -The processing time is eight times longer than when unchecked, -and the peak signal-to-noise ratio (PSNR) is increased by 0.15, -but the effect may not be obvious. It is not recommended to enable it. - - - TTA - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - - - - - - 0 - 0 - - - - GPU ID: - - - - - - - true - - - - 180 - 0 - - - - Select the GPU to use when enabling the "Realsr-ncnn-vulkan" engine. - - - auto - - - - auto - - - - - - - - true - - - - 0 - 0 - - - - QPushButton{ -background-color: rgb(52, 152, 219); -color: rgb(255, 255, 255); -border-style:outset; -border-radius:8px; -padding:10px; -} -QPushButton:hover{ -background-color: rgb(60, 177, 255); -color: rgb(255, 255, 255); -border-style:outset; -border-radius:8px; -padding:10px; -} -QPushButton:pressed{ -background-color: rgb(45, 134, 193); -color: rgb(255, 255, 255); -border-style:outset; -border-radius:8px; -padding:10px; -} -QPushButton:disabled{ -background-color: rgb(166, 166, 166); -color: rgb(255, 255, 255); -border-style:outset; -border-radius:8px; -padding:10px; -} - - - Detect available GPU ID - - - - - - - - 0 - 0 - - - - 1.You need at least 2 available GPUs. - -2.If you wanna get all GPUs running together, -the number of threads must >= the number of GPUs. - -3.You need to [Detect available GPU ID] first. - - - Enable Multi-GPU - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - - - - - - 0 - 0 - - - - Tile size: - - - - - - - true - - - - 0 - 0 - - - - - 0 - 0 - - - - QFrame::NoFrame - - - QFrame::Raised - - - - 0 - - - 0 - - - 0 - - - 0 - - - - - - 30 - 30 - - - - - - - - - - - - Tile size: This value will affects GPU memory usage. -Larger tile size means Realsr will use more GPU memory and run faster. -Smaller tile size means Realsr will use less GPU memory and run slower. - - - 32 - - - 999999999 - - - 10 - - - 128 - - - - - - - - 30 - 30 - - - - + - - - - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - - - - - false - - - - 0 - 0 - - - - - 16777215 - 16777215 - - - - GPU Settings(Multi-GPU) - - - Qt::AlignCenter - - - true - - - - 6 - - - 6 - - - 6 - - - 6 - - - - - - 0 - 0 - - - - Enable - - - true - - - - - - - - 0 - 0 - - - - GPU ID: - - - Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter - - - - - - - - 0 - 0 - - - - Tile size: - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - - - - - Show current Multi-GPU settings. - - - QPushButton{ -background-color: rgb(231, 76, 60); -color: rgb(255, 255, 255); -border-style:outset; -border-radius:8px; -padding:10px; -} -QPushButton:hover{ -background-color: rgb(255, 102, 64); -color: rgb(255, 255, 255); -border-style:outset; -border-radius:8px; -padding:10px; -} -QPushButton:pressed{ -background-color: rgb(204, 65, 53); -color: rgb(255, 255, 255); -border-style:outset; -border-radius:8px; -padding:10px; -} -QPushButton:disabled{ -background-color: rgb(166, 166, 166); -color: rgb(255, 255, 255); -border-style:outset; -border-radius:8px; -padding:10px; -} - - - Show GPUs Settings - - - - - - - - - - - - - - 32 - - - 999999999 - - - 10 - - - 128 - - - - - - - Qt::Vertical - - - - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - - - - - - - - - - - - :/new/prefix1/icon/VideoSettings.png:/new/prefix1/icon/VideoSettings.png - - - Video settings - - - - 5 - - - 5 - - - 5 - - - 5 - - - 5 - - - - - Qt::Horizontal - - - - 226 - 20 - - - - - - - - - 0 - 0 - - - - Frame Interpolation - - - true - - - false - - - - 6 - - - 6 - - - 6 - - - 6 - - - 0 - - - - - false - - - - 0 - 0 - - - - QFrame::NoFrame - - - QFrame::Raised - - - 0 - - - - 0 - - - 0 - - - 0 - - - 0 - - - - - - 0 - 0 - - - - QFrame::NoFrame - - - QFrame::Raised - - - - 0 - - - 0 - - - 0 - - - 0 - - - - - - 0 - 0 - - - - You should enable this option when processing Ultra High Definition videos. - -The software will automatically enable UHD Mode when it detects input with -resolution higher than 3840×2160. - -Only works when using [rife-ncnn-vulkan] engine. - - - UHD Mode - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - Qt::Vertical - - - - - - - - 0 - 0 - - - - QFrame::NoFrame - - - QFrame::Raised - - - - 0 - - - 0 - - - 0 - - - 0 - - - - - - 0 - 0 - - - - Frame Interpolation Engine: - - - - - - - - 0 - 0 - - - - RIFE-NCNN-Vulkan [Speed:★★★ Image quality:★★☆] [2D Anime]&[3D Real-life] -CAIN-NCNN-Vulkan [Speed:★★★ Image quality:★★☆] [2D Anime]&[3D Real-life] -DAIN-NCNN-Vulkan [Speed:☆ Image quality:★★★] [2D Anime]&[3D Real-life] - - - - rife-ncnn-vulkan - - - - - cain-ncnn-vulkan - - - - - dain-ncnn-vulkan - - - - - - - - - - - - 0 - 0 - - - - TTA(Test-Time Augmentation): -The processing time is eight times longer than when unchecked, -and the peak signal-to-noise ratio (PSNR) is increased by 0.15, -but the effect may not be obvious. It is not recommended to enable it. - -Only works when using [rife-ncnn-vulkan] engine. - - - TTA Mode - - - - - - - Interpolate frames after upscaled. - -By default the frames will be interpolated before upscaled, -because PC with low vram will encounter difficulties when -interpolate high res frames. - - - After Upscale - - - - - - - - - - Qt::Horizontal - - - - - - - Qt::Vertical - - - - - - - - - - 0 - 0 - - - - GPU ID: - - - - - - - "-1" is CPU, others are GPUs - - - - auto - - - - - - - - - 0 - 0 - - - - QPushButton{ -background-color: rgb(52, 152, 219); -color: rgb(255, 255, 255); -border-style:outset; -border-radius:8px; -padding:10px; -} -QPushButton:hover{ -background-color: rgb(60, 177, 255); -color: rgb(255, 255, 255); -border-style:outset; -border-radius:8px; -padding:10px; -} -QPushButton:pressed{ -background-color: rgb(45, 134, 193); -color: rgb(255, 255, 255); -border-style:outset; -border-radius:8px; -padding:10px; -} -QPushButton:disabled{ -background-color: rgb(166, 166, 166); -color: rgb(255, 255, 255); -border-style:outset; -border-radius:8px; -padding:10px; -} - - - Detect available GPU ID - - - - - - - - - - - - 0 - 0 - - - - Multi GPU - - - - - - - - 0 - 0 - - - - Format: GPU ID,GPU ID - -Example: 0,1 - -You must follow the format,otherwise the software may crash. - - - - - - - - 0 - 0 - - - - Verify your Multi GPU configuration. - - - QPushButton{ -background-color: rgb(178, 58, 238); -color: rgb(255, 255, 255); -border-style:outset; -border-radius:8px; -padding:10px; -} -QPushButton:hover{ -background-color: rgb(191, 62, 255); -color: rgb(255, 255, 255); -border-style:outset; -border-radius:8px; -padding:10px; -} -QPushButton:pressed{ -background-color: rgb(154, 50, 205); -color: rgb(255, 255, 255); -border-style:outset; -border-radius:8px; -padding:10px; -} -QPushButton:disabled{ -background-color: rgb(166, 166, 166); -color: rgb(255, 255, 255); -border-style:outset; -border-radius:8px; -padding:10px; -} - - - Verify - - - - - - - - - - - - 0 - 0 - - - - This value will affects GPU memory usage. -Only works when using [dain-ncnn-vulkan] engine. - - - Tile size: - - - - - - - Qt::NoFocus - - - This value will affects GPU memory usage. -Only works when using [dain-ncnn-vulkan] engine. - - - 128 - - - 999999999 - - - 32 - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - - - - - - - - 0 - 0 - - - - Model: - - - - - - - Choose the model for rife-ncnn-vulkan engine. - -We recommend you to use the default model "rife-v2.4". - -Only works when using [rife-ncnn-vulkan] engine. - - - 5 - - - - rife - - - - - rife-anime - - - - - rife-HD - - - - - rife-UHD - - - - - rife-v2 - - - - - rife-v2.4 - - - - - - - - - - - - - 0 - 0 - - - - The multi-threading of the frame interpolation engines is NOT -very stable, we don't recommend you to enable this option. - - - Multithreading: - - - - - - - - 0 - 0 - - - - Number of threads. - - - 1 - - - 999999999 - - - - - - - - 0 - 0 - - - - When successive failures are detected, the number -of threads will be adjusted automatically. - - - Auto adjust - - - false - - - - - - - - - - - - - - - - - - 0 - 0 - - - - - 16777215 - 55 - - - - Audio denoise(for video) - - - - 6 - - - 6 - - - 6 - - - 6 - - - - - false - - - - 0 - 0 - - - - - 80 - 0 - - - - How much noise should be removed is specified by amount-a -number between 0.01 and 1 with a default of 0.20. Higher -numbers will remove more noise but present a greater -likelihood of removing wanted components of the audio signal. - - - 2 - - - 0.010000000000000 - - - 1.000000000000000 - - - 0.010000000000000 - - - 0.200000000000000 - - - - - - - - 0 - 0 - - - - - 0 - 0 - - - - Denoise level: - - - - - - - - 0 - 0 - - - - Enabled - - - - - - - Qt::Vertical - - - - - - - - - - Qt::Horizontal - - - - 673 - 45 - - - - - - - - - 0 - 0 - - - - - 16777215 - 16777215 - - - - Custom video settings - - - true - - - false - - - - 6 - - - 6 - - - 6 - - - 6 - - - - - - - false - - - When output the result video - - - - 5 - - - 5 - - - 5 - - - 5 - - - 5 - - - - - - - - 0 - 0 - - - - Encoder(video): - - - - - - - If you leave it empty, software will use auto settings. - - - libx264 - - - - - - - - - - - - 0 - 0 - - - - Bitrate(video): - - - - - - - If you set it to 0, software will use auto settings. - - - K - - - 0 - - - 999999999 - - - 100 - - - 6000 - - - - - - - - - - - - 0 - 0 - - - - Encoder(audio): - - - - - - - If you leave it empty, software will use auto settings. - - - aac - - - - - - - - - - - - 0 - 0 - - - - Bitrate(audio): - - - - - - - If you set it to 0, software will use auto settings. - - - K - - - 0 - - - 999999999 - - - 10 - - - 320 - - - - - - - - - - - - 0 - 0 - - - - Pixel format: - - - - - - - If you leave it empty, software will use auto settings. - - - yuv420p - - - - - - - - - Qt::Horizontal - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - - 0 - 0 - - - - QFrame::NoFrame - - - QFrame::Raised - - - - 0 - - - 0 - - - 0 - - - 0 - - - 5 - - - - - - 0 - 0 - - - - Extra command: - - - - - - - You can enter ffmpeg instructions here. - - - - - - true - - - - - - - - - - - - - false - - - When convert source video to CFR mp4 - - - - 5 - - - 5 - - - 5 - - - 5 - - - 5 - - - - - Qt::Horizontal - - - - 130 - 208 - - - - - - - - - - - 0 - 0 - - - - Bitrate(audio): - - - - - - - If you set it to 0, software will use auto settings. - - - K - - - 0 - - - 999999999 - - - 10 - - - 320 - - - - - - - - - Qt::Horizontal - - - - - - - - - - 0 - 0 - - - - When this is enabled, ffmpeg will copy the audio part of -the original video directly to the mp4, may cause error. - -Command: -acodec copy - -This option will not take effect when source video's frame -rate mode is variable. - - - Copy audio stream - - - - - - - - 0 - 0 - - - - When this is enabled, ffmpeg will copy the video part of -the original video directly to the mp4, may cause error. - -Command: -vcodec copy - -This option will not take effect when source video's frame -rate mode is variable. - - - Copy video stream - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - - - - 0 - 0 - - - - QFrame::NoFrame - - - QFrame::Raised - - - - 0 - - - 0 - - - 0 - - - 0 - - - 5 - - - - - - 0 - 0 - - - - Extra command: - - - - - - - You can enter ffmpeg instructions here. - - - - - - true - - - - - - - - - - - - - 0 - 0 - - - - Bitrate(video): - - - - - - - If you set it to 0, software will use auto settings. - - - K - - - 0 - - - 999999999 - - - 100 - - - 2500 - - - - - - - - - Ignore the frame rate mode of the source video. -Might cause ERROR. - - - Ignore frame rate mode - - - - - - - - - - - - - 0 - 0 - - - - QFrame::StyledPanel - - - QFrame::Raised - - - - 0 - - - 0 - - - 0 - - - 0 - - - - - - 0 - 0 - - - - Reset video settings - - - QPushButton{ -background-color: rgb(231, 76, 60); -color: rgb(255, 255, 255); -border-style:outset; -border-radius:8px; -padding:10px; -} -QPushButton:hover{ -background-color: rgb(255, 102, 64); -color: rgb(255, 255, 255); -border-style:outset; -border-radius:8px; -padding:10px; -} -QPushButton:pressed{ -background-color: rgb(204, 65, 53); -color: rgb(255, 255, 255); -border-style:outset; -border-radius:8px; -padding:10px; -} -QPushButton:disabled{ -background-color: rgb(166, 166, 166); -color: rgb(255, 255, 255); -border-style:outset; -border-radius:8px; -padding:10px; -} - - - Reset video settings - - - - - - - - 0 - 0 - - - - QPushButton{ -background-color: rgb(52, 152, 219); -color: rgb(255, 255, 255); -border-style:outset; -border-radius:8px; -padding:10px; -} -QPushButton:hover{ -background-color: rgb(60, 177, 255); -color: rgb(255, 255, 255); -border-style:outset; -border-radius:8px; -padding:10px; -} -QPushButton:pressed{ -background-color: rgb(45, 134, 193); -color: rgb(255, 255, 255); -border-style:outset; -border-radius:8px; -padding:10px; -} -QPushButton:disabled{ -background-color: rgb(166, 166, 166); -color: rgb(255, 255, 255); -border-style:outset; -border-radius:8px; -padding:10px; -} - - - List Available Encoders - - - - - - - Qt::Horizontal - - - - 549 - 20 - - - - - - - - - - - - - - Process video by segment - - - - - - - 0 - 0 - - - - When processing video in segments, the length of each video clip. -This will determine how much hard disk space the program will occupy -when processing video in segments. - - - Segment duration: - - - - - - - - 0 - 0 - - - - When processing video in segments, the length of each video clip. -This will determine how much hard disk space the program will occupy -when processing video in segments. - - - secs - - - - - - 1 - - - 999999999 - - - 30 - - - - - - - Processing video in segments can greatly reduce the -hard disk space occupied by processing video. But it -will increase the time required to process video. - - - Enabled - - - true - - - - - - - Qt::Vertical - - - - - - - - - - - - :/new/prefix1/icon/AddSetting.png:/new/prefix1/icon/AddSetting.png - - - Additional settings - - - - 6 - - - 6 - - - 6 - - - 6 - - - 5 - - - - - - - - - - 16777215 - 16777215 - - - - Input file extensions - - - - - - - - - 0 - 0 - - - - - 50 - 16777215 - - - - When you find that the file format you want to process cannot -be added to the file list, you can add the file extension yourself -in the additional settings. - -Each extension needs to be separated by ":" - -(There is no guarantee that the file format you add will -be processed successfully) - - - Image: - - - - - - - - 300 - 0 - - - - false - - - When you find that the file format you want to process cannot -be added to the file list, you can add the file extension yourself -in the additional settings. - -Each extension needs to be separated by ":" - -(There is no guarantee that the file format you add will -be processed successfully) - - - png:jpg:jpeg:tif:tiff:bmp - - - - - - - - - - - - 0 - 0 - - - - - 50 - 16777215 - - - - When you find that the file format you want to process cannot -be added to the file list, you can add the file extension yourself -in the additional settings. - -Each extension needs to be separated by ":" - -(There is no guarantee that the file format you add will -be processed successfully) - - - Video: - - - - - - - - 300 - 0 - - - - false - - - When you find that the file format you want to process cannot -be added to the file list, you can add the file extension yourself -in the additional settings. - -Each extension needs to be separated by ":" - -(There is no guarantee that the file format you add will -be processed successfully) - - - mp4:3gp:avi:flv:mkv:mov:mpg:ogg:vob:webm:wmv - - - - - - - - - - - Convert every image to PNG before processing it. -Enabling this option will improve compatibility. However, it will -increase the time and storage space required to process image. - - - Pre-process all images - - - - - - - true - - - When the alpha channel is detected in the picture, software will -automatically force the picture to be saved as PNG. - - - Auto detect Alpha channel - - - true - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - - - - 0 - 0 - - - - This software already can intelligently detect whether the Alpha channel is lost, -and automatically reprocess the picture. And image will be pre-processed during the -reporcess so the alpha channel won't lost again. - -However, this will cause additional time consumption. If re-processing -frequently occurs when processing images, you can enable this option to save time. - - - Always pre-process images with Alpha Channel - - - false - - - - - - - - - - - 16777215 - 16777215 - - - - Custom Font Settings (Restart the software to take effect) - - - - - - - - - 0 - 0 - - - - Custom font: - - - Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter - - - - - - - false - - - 宋体 - - - - 宋体 - - - - - - - - - - - - false - - - - 0 - 0 - - - - - 16777215 - 16777215 - - - - QPushButton{ -background-color: rgb(26, 188, 156); -color: rgb(255, 255, 255); -border-style:outset; -border-radius:8px; -padding:10px; -} -QPushButton:hover{ -background-color: rgb(29, 214, 177); -color: rgb(255, 255, 255); -border-style:outset; -border-radius:8px; -padding:10px; -} -QPushButton:pressed{ -background-color: rgb(23, 173, 143); -color: rgb(255, 255, 255); -border-style:outset; -border-radius:8px; -padding:10px; -} -QPushButton:disabled{ -background-color: rgb(166, 166, 166); -color: rgb(255, 255, 255); -border-style:outset; -border-radius:8px; -padding:10px; -} - - - Save Custom Font Settings - - - - - - - - 0 - 0 - - - - Enable Custom Font Settings. - - - Enable - - - - - - - - - - - - 0 - 0 - - - - Custom font size: - - - Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter - - - - - - - false - - - - 0 - 0 - - - - - 80 - 0 - - - - - 16777215 - 16777215 - - - - 1 - - - 999 - - - 15 - - - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - - - - - 0 - 0 - - - - - 16777215 - 16777215 - - - - - - - - - - - - true - - - QPushButton{ -background-color: rgb(178, 58, 238); -color: rgb(255, 255, 255); -border-style:outset; -border-radius:8px; -padding:10px; -} -QPushButton:hover{ -background-color: rgb(191, 62, 255); -color: rgb(255, 255, 255); -border-style:outset; -border-radius:8px; -padding:10px; -} -QPushButton:pressed{ -background-color: rgb(154, 50, 205); -color: rgb(255, 255, 255); -border-style:outset; -border-radius:8px; -padding:10px; -} -QPushButton:disabled{ -background-color: rgb(166, 166, 166); -color: rgb(255, 255, 255); -border-style:outset; -border-radius:8px; -padding:10px; -} - - - Save settings - - - - - - - QPushButton{ -background-color: rgb(238, 99, 99); -color: rgb(255, 255, 255); -border-style:outset; -border-radius:8px; -padding:10px; -} -QPushButton:hover{ -background-color: rgb(255, 106, 106); -color: rgb(255, 255, 255); -border-style:outset; -border-radius:8px; -padding:10px; -} -QPushButton:pressed{ -background-color: rgb(205, 85, 85); -color: rgb(255, 255, 255); -border-style:outset; -border-radius:8px; -padding:10px; -} -QPushButton:disabled{ -background-color: rgb(166, 166, 166); -color: rgb(255, 255, 255); -border-style:outset; -border-radius:8px; -padding:10px; -} - - - Reset settings - - - - - - - - 9 - false - - - - QPushButton{ -background-color: rgb(26, 188, 156); -color: rgb(255, 255, 255); -border-style:outset; -border-radius:8px; -padding:10px; -} -QPushButton:hover{ -background-color: rgb(29, 214, 177); -color: rgb(255, 255, 255); -border-style:outset; -border-radius:8px; -padding:10px; -} -QPushButton:pressed{ -background-color: rgb(23, 173, 143); -color: rgb(255, 255, 255); -border-style:outset; -border-radius:8px; -padding:10px; -} -QPushButton:disabled{ -background-color: rgb(166, 166, 166); -color: rgb(255, 255, 255); -border-style:outset; -border-radius:8px; -padding:10px; -} - - - Check update - - - - - - - - - - - - false - - - - QPushButton{ -background-color: rgb(231, 76, 60); -color: rgb(255, 255, 255); -border-style:outset; -border-radius:8px; -padding:10px; -} -QPushButton:hover{ -background-color: rgb(255, 102, 64); -color: rgb(255, 255, 255); -border-style:outset; -border-radius:8px; -padding:10px; -} -QPushButton:pressed{ -background-color: rgb(204, 65, 53); -color: rgb(255, 255, 255); -border-style:outset; -border-radius:8px; -padding:10px; -} -QPushButton:disabled{ -background-color: rgb(166, 166, 166); -color: rgb(255, 255, 255); -border-style:outset; -border-radius:8px; -padding:10px; -} - - - Report issue - - - - - - - - false - - - - QPushButton{ -background-color: rgb(255, 181, 6); -color: rgb(255, 255, 255); -border-style:outset; -border-radius:8px; -padding:10px; -} -QPushButton:hover{ -background-color: rgb(255, 200, 50); -color: rgb(255, 255, 255); -border-style:outset; -border-radius:8px; -padding:10px; -} -QPushButton:pressed{ -background-color: rgb(255, 170, 0); -color: rgb(255, 255, 255); -border-style:outset; -border-radius:8px; -padding:10px; -} -QPushButton:disabled{ -background-color: rgb(166, 166, 166); -color: rgb(255, 255, 255); -border-style:outset; -border-radius:8px; -padding:10px; -} - - - Official website - - - - - - - Open Waifu2x-Extension-GUI online wiki. - - - QPushButton{ -background-color: rgb(178, 58, 238); -color: rgb(255, 255, 255); -border-style:outset; -border-radius:8px; -padding:10px; -} -QPushButton:hover{ -background-color: rgb(191, 62, 255); -color: rgb(255, 255, 255); -border-style:outset; -border-radius:8px; -padding:10px; -} -QPushButton:pressed{ -background-color: rgb(154, 50, 205); -color: rgb(255, 255, 255); -border-style:outset; -border-radius:8px; -padding:10px; -} -QPushButton:disabled{ -background-color: rgb(166, 166, 166); -color: rgb(255, 255, 255); -border-style:outset; -border-radius:8px; -padding:10px; -} - - - Wiki - - - - - - - - - - - - 16777215 - 16777215 - - - - QPushButton{ -background-color: rgb(52, 152, 219); -color: rgb(255, 255, 255); -border-style:outset; -border-radius:8px; -padding:10px; -} -QPushButton:hover{ -background-color: rgb(60, 177, 255); -color: rgb(255, 255, 255); -border-style:outset; -border-radius:8px; -padding:10px; -} -QPushButton:pressed{ -background-color: rgb(45, 134, 193); -color: rgb(255, 255, 255); -border-style:outset; -border-radius:8px; -padding:10px; -} -QPushButton:disabled{ -background-color: rgb(166, 166, 166); -color: rgb(255, 255, 255); -border-style:outset; -border-radius:8px; -padding:10px; -} - - - About - - - - - - - QPushButton{ -background-color: rgb(255, 66, 77); -color: rgb(255, 255, 255); -border-style:outset; -border-radius:8px; -padding:10px; -} -QPushButton:hover{ -background-color: rgb(255, 105, 112); -color: rgb(255, 255, 255); -border-style:outset; -border-radius:8px; -padding:10px; -} -QPushButton:pressed{ -background-color: rgb(223, 50, 61); -color: rgb(255, 255, 255); -border-style:outset; -border-radius:8px; -padding:10px; -} -QPushButton:disabled{ -background-color: rgb(166, 166, 166); -color: rgb(255, 255, 255); -border-style:outset; -border-radius:8px; -padding:10px; -} - - - Top Supporters - - - - - - - - - - - - - - - - - - 6 - - - 6 - - - 6 - - - 6 - - - 7 - - - - - QFrame::NoFrame - - - QFrame::Raised - - - - 0 - - - 0 - - - 0 - - - 0 - - - 5 - - - - - - 0 - 0 - - - - A pop-up window will prompts when an update is detected. - - - Update popup - - - true - - - - - - - Settings will be saved automatically when you close the software. - - - Auto save settings - - - true - - - - - - - This option will be automatically enabled to improve -performance and fix issues when the software detects -that your PC has compatibility issues with ImageMagick. - - - Disable "-resize" - - - - - - - Prompt when exit - - - true - - - - - - - Minimize to taskbar - - - - - - - [Text browser] will be automatically hidden when the software starts. - - - Always hide Text Browser - - - - - - - When adding a folder to the file list, scan the files in -the subfolder and add them to the file list. - - - Scan sub-folders - - - true - - - - - - - - 0 - 0 - - - - QFrame::NoFrame - - - QFrame::Raised - - - 0 - - - - 0 - - - 0 - - - 0 - - - 0 - - - 2 - - - - - - 0 - 0 - - - - The number of retries when an image (or frame) processing fails. - - - Retry: - - - - - - - - 0 - 0 - - - - The number of retries when an image (or frame) processing fails. - - - 1 - - - 999999999 - - - 6 - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - - - - Stop downloading any data from Gitee. - -When you cannot access github, enabling -this option will affect the automatic -detection of new updates. - - - Ban Gitee - - - - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - QFrame::Raised - - - Qt::Vertical - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - QFrame::NoFrame - - - QFrame::Raised - - - - 0 - - - 0 - - - 0 - - - 0 - - - 5 - - - - - - 0 - 0 - - - - QFrame::NoFrame - - - QFrame::Raised - - - 0 - - - - 0 - - - 0 - - - 0 - - - 0 - - - 2 - - - - - - 150 - 0 - - - - We recommend that you restart the software after changing -the language for the language settings to fully take effect. - - - English - - - - English - - - - - 简体中文 - - - - - 繁體中文(由uimee翻譯) - - - - - - - - - 0 - 0 - - - - - 16777215 - 16777215 - - - - We recommend that you restart the software after changing -the language for the language settings to fully take effect. - - - Language: - - - Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter - - - - - - - - - - Play Notification sound. - - - Notification sound - - - true - - - - - - - When the file processing status changes, the file list scrolls automatically. - - - Automatic file list scrolling - - - true - - - - - - - - 0 - 0 - - - - QFrame::NoFrame - - - QFrame::Raised - - - 0 - - - - 0 - - - 0 - - - 0 - - - 0 - - - 2 - - - - - - 0 - 0 - - - - Update channel: - - - - - - - - 0 - 0 - - - - - - - - Stable - - - - - Beta - - - - - - - - - - - Keep video cache after processing the video. - - - Keep video cache - - - false - - - - - - - Interactive file list - - - false - - - - - - - [Settings] will be automatically hidden when the software starts. - - - Always hide Settings - - - - - - - Output internal Scale and Denoise progress of GIF and video process inside textbrowser. - - - Show internal progress - - - true - - - - - - - Show the summary pop-up window after processing all files. - - - Summary popup - - - true - - - - - - - - - - - - - - - - - :/new/prefix1/icon/CompatibilityTest.png:/new/prefix1/icon/CompatibilityTest.png - - - Compatibility test - - - - 6 - - - 6 - - - 6 - - - 6 - - - 0 - - - - - - 0 - 0 - - - - Run a compatibility test to see which engines your computer is compatible with. - - - QPushButton{ - background-color: rgb(92, 172, 238); -color: rgb(255, 255, 255); -border-style:outset; -border-radius:8px; -padding:10px; -} -QPushButton:hover{ - background-color: rgb(99, 184, 255); -color: rgb(255, 255, 255); -border-style:outset; -border-radius:8px; -padding:10px; -} -QPushButton:pressed{ -background-color: rgb(79, 148,205); -color: rgb(255, 255, 255); -border-style:outset; -border-radius:8px; -padding:10px; -} -QPushButton:disabled{ -background-color: rgb(166, 166, 166); -color: rgb(255, 255, 255); -border-style:outset; -border-radius:8px; -padding:10px; -} - - - Start compatibility test - - - - - - - - 0 - 0 - - - - 19 - - - 0 - - - false - - - QProgressBar::TopToBottom - - - - - - - true - - - Compatibility test results - - - - 6 - - - 6 - - - 6 - - - 6 - - - - - true - - - Qt::NoFocus - - - By @nihui(https://github.com/nihui) - -https://github.com/nihui/waifu2x-ncnn-vulkan - - - QCheckBox:disabled{ - color: rgb(0, 0, 0); -} - - - Waifu2x-ncnn-vulkan(OLD) - - - - - - - true - - - Qt::NoFocus - - - By @nihui(https://github.com/nihui) - -https://github.com/nihui/waifu2x-ncnn-vulkan - - - QCheckBox:disabled{ - color: rgb(0, 0, 0); -} - - - Waifu2x-ncnn-vulkan(Latest) - - - true - - - false - - - - - - - By @nihui(https://github.com/nihui) - -https://github.com/nihui/realsr-ncnn-vulkan - - - Realsr-ncnn-vulkan - - - - - - - https://www.ffmpeg.org/ - - - FFprobe - - - - - - - true - - - false - - - Qt::NoFocus - - - Qt::NoContextMenu - - - By @DeadSix27(https://github.com/DeadSix27) - -https://github.com/DeadSix27/waifu2x-converter-cpp - - - QCheckBox:disabled{ - color: rgb(0, 0, 0); -} - - - Waifu2x-converter - - - true - - - - - - - true - - - Qt::NoFocus - - - By @nihui(https://github.com/nihui) - -https://github.com/nihui/waifu2x-ncnn-vulkan - - - QCheckBox:disabled{ - color: rgb(0, 0, 0); -} - - - Waifu2x-ncnn-vulkan(20200414(fp16p)) - - - - - - - https://www.lcdf.org/gifsicle/ - - - Gifsicle - - - - - - - true - - - Qt::NoFocus - - - By @nihui(https://github.com/nihui) - -https://github.com/nihui/srmd-ncnn-vulkan - - - QCheckBox:disabled{ - color: rgb(0, 0, 0); -} - - - SRMD-ncnn-vulkan - - - - - - - Qt::Horizontal - - - - - - - https://imagemagick.org/ - - - ImageMagick - - - - - - - http://sox.sourceforge.net/ - - - SoX - - - - - - - true - - - Qt::NoFocus - - - By @TianZerL(https://github.com/TianZerL) - -https://github.com/TianZerL/Anime4KCPP - - - QCheckBox:disabled{ - color: rgb(0, 0, 0); -} - - - Anime4K(GPU) - - - - - - - By @lltcggie(https://github.com/lltcggie) - -https://github.com/lltcggie/waifu2x-caffe - - - Waifu2x-caffe(CPU) - - - - - - - - 0 - 0 - - - - - 16777215 - 30 - - - - Plugins: - - - - - - - By @lltcggie(https://github.com/lltcggie) - -https://github.com/lltcggie/waifu2x-caffe - - - Waifu2x-caffe(GPU) - - - - - - - - 0 - 0 - - - - - 16777215 - 30 - - - - Super-Resolution Engines: - - - - - - - https://www.ffmpeg.org/ - - - FFmpeg - - - - - - - true - - - Qt::NoFocus - - - By @TianZerL(https://github.com/TianZerL) - -https://github.com/TianZerL/Anime4KCPP - - - QCheckBox:disabled{ - color: rgb(0, 0, 0); -} - - - Anime4K(CPU) - - - - - - - By @lltcggie(https://github.com/lltcggie) - -https://github.com/lltcggie/waifu2x-caffe - - - Waifu2x-caffe(cuDNN) - - - - - - - Qt::Horizontal - - - - - - - - 0 - 0 - - - - Frame Interpolation Engines: - - - - - - - By @nihui(https://github.com/nihui) - -https://github.com/nihui/rife-ncnn-vulkan - - - RIFE-NCNN-Vulkan - - - - - - - By @nihui(https://github.com/nihui) - -https://github.com/nihui/cain-ncnn-vulkan - - - CAIN-NCNN-Vulkan - - - - - - - By @nihui(https://github.com/nihui) - -https://github.com/nihui/dain-ncnn-vulkan - - - DAIN-NCNN-Vulkan - - - - - - - - 660 - 260 - - - - - 16777215 - 260 - - - - QFrame::Box - - - QFrame::Sunken - - - [FFmpeg, FFprobe, ImageMagick, Gifsicle, SoX], one of the Super-Resolution engines and one of the Frame Interpolation engines must be compatible with your computer, to make sure you can use all functions in this software. - -Waifu2x-NCNN-Vulkan [Speed:★★ Image quality:★★★] [2D Anime]&[3D Real-life] -Waifu2x-Converter [Speed:★☆ Image quality:★★☆] [2D Anime] -Anime4K [Speed:★★★ Image quality:★☆ ] [2D Anime] -SRMD-NCNN-Vulkan [Speed:★☆ Image quality:★★★] [2D Anime]&[3D Real-life] -Waifu2x-Caffe [Speed:★☆ Image quality:★★★] [2D Anime]&[3D Real-life] -RealSR-NCNN-Vulkan [Speed:☆ Image quality:★★★] [3D Real-life] -SRMD-CUDA [Speed:★★☆ Image quality:★★★] [2D Anime]&[3D Real-life] - -RIFE-NCNN-Vulkan [Speed:★★★ Image quality:★★☆] [2D Anime]&[3D Real-life] -CAIN-NCNN-Vulkan [Speed:★★★ Image quality:★★☆] [2D Anime]&[3D Real-life] -DAIN-NCNN-Vulkan [Speed:☆ Image quality:★★★] [2D Anime]&[3D Real-life] - - - Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter - - - true - - - - - - - By @MrZihan(https://github.com/MrZihan) - -https://github.com/MrZihan/Super-resolution-SR-CUDA - - - SRMD-CUDA [BETA] - - - - - - - - - - - - - 0 - 0 - - - - - 0 - 95 - - - - - 16777215 - 16777215 - - - - Qt::DefaultContextMenu - - - 0 - - - Qt::Horizontal - - - 5 - - - - - 0 - 0 - - - - - 0 - 0 - - - - - 16777215 - 16777215 - - - - - Arial - - - - false - - - - - - 0 - 0 - - - - - 0 - 0 - - - - - 16777215 - 16777215 - - - - - - - - - - false - - - - QLayout::SetFixedSize - - - 6 - - - 6 - - - 6 - - - 6 - - - 5 - - - - - - 0 - 0 - - - - Clear text browser. - - - QPushButton{ - background-color: rgb(0, 140, 158); -color: rgb(255, 255, 255); -border-style:outset; -border-radius:8px; -padding:10px; -} -QPushButton:hover{ - background-color: rgb(0, 190, 211); -color: rgb(255, 255, 255); -border-style:outset; -border-radius:8px; -padding:10px; -} -QPushButton:pressed{ - background-color: rgb(0, 108, 120); -color: rgb(255, 255, 255); -border-style:outset; -border-radius:8px; -padding:10px; -} -QPushButton:disabled{ -background-color: rgb(166, 166, 166); -color: rgb(255, 255, 255); -border-style:outset; -border-radius:8px; -padding:10px; -} - - - Clear - - - - 25 - 25 - - - - - - - - 5 - - - QLayout::SetFixedSize - - - - - - 0 - 0 - - - - Change the font size of the text browser. - - - Font size: - - - - - - - - 0 - 0 - - - - Change the font size of the text browser. - - - 1 - - - 9 - - - - - - - - - - - - - - - - - - + + + MainWindow + + + + 0 + 0 + 1096 + 794 + + + + + 0 + 0 + + + + + 0 + 0 + + + + + 16777215 + 16777215 + + + + Qt::StrongFocus + + + Waifu2x-Extension-GUI by Aaron Feng + + + + :/new/prefix1/icon/icon_main.png:/new/prefix1/icon/icon_main.png + + + + + + + + 0 + 0 + + + + + + + + 6 + + + 6 + + + 6 + + + 6 + + + + + + + + Qt::Vertical + + + 5 + + + + + 0 + 0 + + + + + 0 + 0 + + + + QTabBar::tab{ +height:35 +} + + + QTabWidget::Rounded + + + 1 + + + + 23 + 23 + + + + Qt::ElideNone + + + false + + + false + + + false + + + false + + + false + + + + true + + + + + + + :/new/prefix1/icon/donateTabIcon_1.png:/new/prefix1/icon/donateTabIcon_1.png + + + Donate + + + + + + + 16777215 + 50 + + + + + 10 + 50 + false + false + false + + + + <html><head/><body><p align="center">Please donate to support the developers, so we can bring further updates for this software, thank you! (。・∀・)ノ゙ </p><p align="center">If you don't wanna see the Donate page anymore, you can <span style=" color:#ff0004;">get the </span><span style=" font-weight:600; color:#ff0004;">Premium</span><span style=" color:#ff0004;"> version by support me on Patreon.</span></p></body></html> + + + Qt::AlignCenter + + + + + + + + + + 0 + 0 + + + + + 240 + 60 + + + + + 20 + 75 + false + true + false + false + + + + Donate to the developer through PayPal. + + + QPushButton{ +background-color: rgb(52, 152, 219); +color: rgb(255, 255, 255); +border-style:outset; +border-radius:8px; +padding:10px; +} +QPushButton:hover{ +background-color: rgb(60, 177, 255); +color: rgb(255, 255, 255); +border-style:outset; +border-radius:8px; +padding:10px; +} +QPushButton:pressed{ +background-color: rgb(45, 134, 193); +color: rgb(255, 255, 255); +border-style:outset; +border-radius:8px; +padding:10px; +} +QPushButton:disabled{ +background-color: rgb(166, 166, 166); +color: rgb(255, 255, 255); +border-style:outset; +border-radius:8px; +padding:10px; +} + + + PayPal + + + + :/new/prefix1/icon/paypal.png:/new/prefix1/icon/paypal.png + + + + 38 + 38 + + + + + + + + + 0 + 60 + + + + + 20 + 75 + true + + + + Support this project on Patreon and get Premium version. + + + QPushButton{ +background-color: rgb(255, 66, 77); +color: rgb(255, 255, 255); +border-style:outset; +border-radius:8px; +padding:10px; +} +QPushButton:hover{ +background-color: rgb(255, 105, 112); +color: rgb(255, 255, 255); +border-style:outset; +border-radius:8px; +padding:10px; +} +QPushButton:pressed{ +background-color: rgb(223, 50, 61); +color: rgb(255, 255, 255); +border-style:outset; +border-radius:8px; +padding:10px; +} +QPushButton:disabled{ +background-color: rgb(166, 166, 166); +color: rgb(255, 255, 255); +border-style:outset; +border-radius:8px; +padding:10px; +} + + + Get Premium version on Patreon + + + + :/new/prefix1/icon/patreon.png:/new/prefix1/icon/patreon.png + + + + 38 + 38 + + + + + + + + + + + 0 + 0 + + + + + 750 + 360 + + + + + 2 + 1 + + + + + Arial + 13 + 75 + true + + + + image: url(:/new/prefix1/donate/Donate_QRCode.jpg); + + + QFrame::NoFrame + + + + + + false + + + Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop + + + + + + + + + 9 + + + + + :/new/prefix1/icon/Home.png:/new/prefix1/icon/Home.png + + + Home + + + + 6 + + + 6 + + + 6 + + + 6 + + + + + + 0 + 0 + + + + + 0 + 0 + + + + + 16777215 + 51 + + + + + + + + 6 + + + 6 + + + 6 + + + 6 + + + + + + 0 + 0 + + + + + 0 + 0 + + + + + 16777215 + 16777215 + + + + + + + QPushButton{ +background-color: rgb(26, 188, 156); +color: rgb(255, 255, 255); +border-style:outset; +border-radius:8px; +padding:10px; +} +QPushButton:hover{ +background-color: rgb(29, 214, 177); +color: rgb(255, 255, 255); +border-style:outset; +border-radius:8px; +padding:10px; +} +QPushButton:pressed{ +background-color: rgb(23, 173, 143); +color: rgb(255, 255, 255); +border-style:outset; +border-radius:8px; +padding:10px; +} +QPushButton:disabled{ +background-color: rgb(166, 166, 166); +color: rgb(255, 255, 255); +border-style:outset; +border-radius:8px; +padding:10px; +} + + + Start + + + + :/new/prefix1/icon/icon_main.png:/new/prefix1/icon/icon_main.png + + + + 25 + 25 + + + + + + + + 0 + + + %p% + + + + + + + + 0 + 0 + + + + QFrame::Box + + + 1 + + + ETA:NULL + + + + + + + + 0 + 0 + + + + Finished/Total + + + QFrame::Box + + + QFrame::Plain + + + 1 + + + 0/0 + + + + + + + + 0 + 0 + + + + QFrame::Box + + + 1 + + + Time taken:NULL + + + + + + + true + + + + 0 + 0 + + + + In some cases, the Engine process can get stuck. + +When you find that the [Scale and denoise] progress has +not changed for a long time, it is recommended that you +perform a forced retry to remove the stuck. + +You can try using [Force Retry] to end the Engine process +and restart it, and the entire [Scale and denoise] process +will not be interrupted and will continue. + + + QPushButton{ +background-color: rgb(178, 58, 238); +color: rgb(255, 255, 255); +border-style:outset; +border-radius:8px; +padding:10px; +} +QPushButton:hover{ +background-color: rgb(191, 62, 255); +color: rgb(255, 255, 255); +border-style:outset; +border-radius:8px; +padding:10px; +} +QPushButton:pressed{ +background-color: rgb(154, 50, 205); +color: rgb(255, 255, 255); +border-style:outset; +border-radius:8px; +padding:10px; +} +QPushButton:disabled{ +background-color: rgb(166, 166, 166); +color: rgb(255, 255, 255); +border-style:outset; +border-radius:8px; +padding:10px; +} + + + Force retry + + + + :/new/prefix1/icon/refresh.png:/new/prefix1/icon/refresh.png + + + + 25 + 25 + + + + + + + + + 0 + 0 + + + + + 16777215 + 16777215 + + + + QPushButton{ +background-color: rgb(231, 76, 60); +color: rgb(255, 255, 255); +border-style:outset; +border-radius:8px; +padding:10px; +} +QPushButton:hover{ +background-color: rgb(255, 102, 64); +color: rgb(255, 255, 255); +border-style:outset; +border-radius:8px; +padding:10px; +} +QPushButton:pressed{ +background-color: rgb(204, 65, 53); +color: rgb(255, 255, 255); +border-style:outset; +border-radius:8px; +padding:10px; +} +QPushButton:disabled{ +background-color: rgb(166, 166, 166); +color: rgb(255, 255, 255); +border-style:outset; +border-radius:8px; +padding:10px; +} + + + Pause + + + + :/new/prefix1/icon/pause-button.png:/new/prefix1/icon/pause-button.png + + + + 25 + 25 + + + + + + + + + 0 + 0 + + + + QFrame::Box + + + 1 + + + Time remaining:NULL + + + + + + + + + + + 0 + 0 + + + + + 0 + 0 + + + + Current File: + + + + 6 + + + 6 + + + 6 + + + 6 + + + 6 + + + + + + 0 + 0 + + + + Finished/Total + + + QFrame::Box + + + QFrame::Plain + + + 0/0 + + + + + + + + 0 + 0 + + + + QFrame::Box + + + ETA:NULL + + + + + + + 0 + + + + + + + + 0 + 0 + + + + QFrame::Box + + + Time remaining:NULL + + + + + + + + 0 + 0 + + + + QFrame::Box + + + Time taken:NULL + + + + + + + + + + QSplitter:handle{ + + background-color: rgb(255, 255, 255); +} + + + 0 + + + Qt::Vertical + + + 3 + + + + + 0 + 0 + + + + + 0 + 0 + + + + Files List + + + + 6 + + + 6 + + + 6 + + + 6 + + + + + + 0 + 0 + + + + QSplitter:handle{ + + background-color: rgb(255, 255, 255); +} + + + Qt::Horizontal + + + 5 + + + false + + + + + 0 + 0 + + + + Qt::ActionsContextMenu + + + Press [Delete] key to remove file from the list. +Press [Ctrl + A] key to apply custom resolution. +Press [Ctrl + C] key to cancel custom resolution. + +Right click to show more options. + + + QTableView{ +selection-background-color: rgb(52, 152, 219); + +} + + + false + + + 0 + + + QAbstractItemView::NoEditTriggers + + + QAbstractItemView::SingleSelection + + + QAbstractItemView::SelectRows + + + QAbstractItemView::ScrollPerPixel + + + QAbstractItemView::ScrollPerPixel + + + false + + + false + + + false + + + 20 + + + 200 + + + false + + + false + + + false + + + false + + + + + true + + + + 0 + 0 + + + + Qt::ActionsContextMenu + + + Press [Delete] key to remove file from the list. +Press [Ctrl + A] key to apply custom resolution. +Press [Ctrl + C] key to cancel custom resolution. + +Right click to show more options. + + + QTableView{ +selection-background-color: rgb(26, 188, 156); +} + + + false + + + 0 + + + QAbstractItemView::NoEditTriggers + + + QAbstractItemView::SingleSelection + + + QAbstractItemView::SelectRows + + + QAbstractItemView::ScrollPerPixel + + + QAbstractItemView::ScrollPerPixel + + + false + + + false + + + false + + + 20 + + + 200 + + + false + + + false + + + + + + 0 + 0 + + + + Qt::ActionsContextMenu + + + Press [Delete] key to remove file from the list. +Press [Ctrl + A] key to apply custom resolution. +Press [Ctrl + C] key to cancel custom resolution. + +Right click to show more options. + + + QTableView{ +selection-background-color: rgb(178, 58, 238); +} + + + false + + + 0 + + + QAbstractItemView::NoEditTriggers + + + QAbstractItemView::SingleSelection + + + QAbstractItemView::SelectRows + + + QAbstractItemView::ScrollPerPixel + + + QAbstractItemView::ScrollPerPixel + + + false + + + false + + + false + + + 20 + + + 200 + + + false + + + + + + 0 + 90 + + + + + Arial + 13 + 50 + false + false + + + + When the software is running with administrator rights, +you will not be able to drag and drop files into the window. + +If this happens, please unauthorize the software or reinstall the +software into a directory that can run normally without administrator rights. + + + + + + QFrame::Box + + + QFrame::Plain + + + 1 + + + <html><head/><body><p>Drag and drop files or folders here</p><p>(Image, Animated Image<span style=" vertical-align:super;">GIF, APNG</span> and Video)</p></body></html> + + + Qt::AlignCenter + + + + + + + + + 0 + 0 + + + + + + + + + + QFrame::Box + + + QFrame::Plain + + + 0 + + + File count: 0 + + + Qt::AlignCenter + + + 5 + + + false + + + + + + + + 0 + 0 + + + + + 16777215 + 16777215 + + + + QFrame::NoFrame + + + QFrame::Raised + + + + 0 + + + 0 + + + 0 + + + 0 + + + + + + 0 + 0 + + + + + 35 + 35 + + + + + 16777215 + 16777215 + + + + Read Files List + + + QPushButton{ +image: url(:/new/prefix1/icon/Read_FileList.png); +border-style:transparent; +border-radius:0px; +padding:0px; +} +QPushButton:hover{ +image: url(:/new/prefix1/icon/Read_FileList_hover.png); +border-style:transparent; +border-radius:0px; +padding:0px; +} +QPushButton:pressed{ +image: url(:/new/prefix1/icon/Read_FileList.png); +border-style:transparent; +border-radius:0px; +padding:0px; +} +QPushButton:disabled{ +image: url(:/new/prefix1/icon/Read_FileList_disabled.png); +border-style:transparent; +border-radius:0px; +padding:0px; +} + + + + + + + 35 + 35 + + + + + + + + QFrame::Sunken + + + 1 + + + Qt::Vertical + + + + + + + Qt::Vertical + + + + + + + + 0 + 0 + + + + + 35 + 35 + + + + Reset Files List scale. + + + QPushButton{ +image: url(:/new/prefix1/icon/ResizeFilesListSplitter.png); +border-style:transparent; +border-radius:0px; +padding:0px; +} +QPushButton:hover{ +image: url(:/new/prefix1/icon/ResizeFilesListSplitter_hover.png); +border-style:transparent; +border-radius:0px; +padding:0px; +} +QPushButton:pressed{ +image: url(:/new/prefix1/icon/ResizeFilesListSplitter.png); +border-style:transparent; +border-radius:0px; +padding:0px; +} +QPushButton:disabled{ +image: url(:/new/prefix1/icon/ResizeFilesListSplitter_disabled.png); +border-style:transparent; +border-radius:0px; +padding:0px; +} + + + + + + + + + + + 0 + 0 + + + + + 35 + 35 + + + + + 16777215 + 16777215 + + + + Qt::ActionsContextMenu + + + Remove the selected file from File List. + +[Right click here to show more options] + + + QPushButton{ +image: url(:/new/prefix1/icon/RemoveItem.png); +border-style:transparent; +border-radius:0px; +padding:0px; +} +QPushButton:hover{ +image: url(:/new/prefix1/icon/RemoveItem_hover.png); +border-style:transparent; +border-radius:0px; +padding:0px; +} +QPushButton:pressed{ +image: url(:/new/prefix1/icon/RemoveItem.png); +border-style:transparent; +border-radius:0px; +padding:0px; +} +QPushButton:disabled{ +image: url(:/new/prefix1/icon/RemoveItem_disabled.png); +border-style:transparent; +border-radius:0px; +padding:0px; +} + + + + + + + + + + + 0 + 0 + + + + + 35 + 35 + + + + Browse and add files. + + + QPushButton{ +image: url(:/new/prefix1/icon/AddNewFile.png); +border-style:transparent; +border-radius:0px; +padding:0px; +} +QPushButton:hover{ +image: url(:/new/prefix1/icon/AddNewFile_hover.png); +border-style:transparent; +border-radius:0px; +padding:0px; +} +QPushButton:pressed{ +image: url(:/new/prefix1/icon/AddNewFile.png); +border-style:transparent; +border-radius:0px; +padding:0px; +} +QPushButton:disabled{ +image: url(:/new/prefix1/icon/AddNewFile_disabled.png); +border-style:transparent; +border-radius:0px; +padding:0px; +} + + + + + + + + + + Qt::Vertical + + + + + + + + 0 + 0 + + + + + 35 + 35 + + + + + 16777215 + 16777215 + + + + Remove all the files in the File list. + + + QPushButton{ +image: url(:/new/prefix1/icon/ClearList.png); +border-style:transparent; +border-radius:0px; +padding:0px; +} +QPushButton:hover{ +image: url(:/new/prefix1/icon/ClearList_hover.png); +border-style:transparent; +border-radius:0px; +padding:0px; +} +QPushButton:pressed{ +image: url(:/new/prefix1/icon/ClearList.png); +border-style:transparent; +border-radius:0px; +padding:0px; +} +QPushButton:disabled{ +image: url(:/new/prefix1/icon/ClearList_disabled.png); +border-style:transparent; +border-radius:0px; +padding:0px; +} + + + + + + + + + + + 0 + 0 + + + + + 35 + 35 + + + + Save Files List + + + QPushButton{ +image: url(:/new/prefix1/icon/Save_FileList.png); +border-style:transparent; +border-radius:0px; +padding:0px; +} +QPushButton:hover{ +image: url(:/new/prefix1/icon/Save_FileList_hover.png); +border-style:transparent; +border-radius:0px; +padding:0px; +} +QPushButton:pressed{ +image: url(:/new/prefix1/icon/Save_FileList.png); +border-style:transparent; +border-radius:0px; +padding:0px; +} +QPushButton:disabled{ +image: url(:/new/prefix1/icon/Save_FileList_disabled.png); +border-style:transparent; +border-radius:0px; +padding:0px; +} + + + + + + + 35 + 35 + + + + + + + + + 0 + 0 + + + + + 35 + 35 + + + + Turn off screen. + +We recommand you to use this button to turn off screen +while program is running. Using other methods to turn off +the screen may cause the software to freeze during the screen +shutdown. And we recommend that you turn off the automatic +shutdown screen and automatic sleep of the Windows system while +the software is running. + + + 60000 + + + QPushButton{ +image: url(:/new/prefix1/icon/TurnOffScreen.png); +border-style:transparent; +border-radius:0px; +padding:0px; +} +QPushButton:hover{ +image: url(:/new/prefix1/icon/TurnOffScreen_hover.png); +border-style:transparent; +border-radius:0px; +padding:0px; +} +QPushButton:pressed{ +image: url(:/new/prefix1/icon/TurnOffScreen.png); +border-style:transparent; +border-radius:0px; +padding:0px; +} +QPushButton:disabled{ +image: url(:/new/prefix1/icon/TurnOffScreen_disabled.png); +border-style:transparent; +border-radius:0px; +padding:0px; +} + + + + + + + + + + Qt::Vertical + + + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + 0 + 0 + + + + + + + QPushButton{ +background-color: rgb(52, 152, 219); +color: rgb(255, 255, 255); +border-style:outset; +border-radius:8px; +padding:10px; +} +QPushButton:hover{ +background-color: rgb(60, 177, 255); +color: rgb(255, 255, 255); +border-style:outset; +border-radius:8px; +padding:10px; +} +QPushButton:pressed{ +background-color: rgb(45, 134, 193); +color: rgb(255, 255, 255); +border-style:outset; +border-radius:8px; +padding:10px; +} +QPushButton:disabled{ +background-color: rgb(166, 166, 166); +color: rgb(255, 255, 255); +border-style:outset; +border-radius:8px; +padding:10px; +} + + + Hide settings + + + + + + + + 0 + 0 + + + + QPushButton{ +background-color: rgb(178, 58, 238); +color: rgb(255, 255, 255); +border-style:outset; +border-radius:8px; +padding:10px; +} +QPushButton:hover{ +background-color: rgb(191, 62, 255); +color: rgb(255, 255, 255); +border-style:outset; +border-radius:8px; +padding:10px; +} +QPushButton:pressed{ +background-color: rgb(154, 50, 205); +color: rgb(255, 255, 255); +border-style:outset; +border-radius:8px; +padding:10px; +} +QPushButton:disabled{ +background-color: rgb(166, 166, 166); +color: rgb(255, 255, 255); +border-style:outset; +border-radius:8px; +padding:10px; +} + + + Hide Text Browser + + + + + + + + + 0 + 0 + + + + + 0 + 0 + + + + + 16777215 + 305 + + + + + + + + 6 + + + 6 + + + 6 + + + 6 + + + + + 5 + + + + + + 0 + 0 + + + + + 16777215 + 16777215 + + + + + + + Custom resolution + + + Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter + + + + 6 + + + 6 + + + 6 + + + 6 + + + 5 + + + + + + 0 + 0 + + + + Width: + + + + + + + 2 + + + QLayout::SetDefaultConstraint + + + + + + 0 + 0 + + + + + 16777215 + 16777215 + + + + <html><head/><body><p><img src=":/new/prefix1/OtherPic/AspectRatioStrategy.jpg"/></p></body></html> + + + Aspect Ratio: + + + Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter + + + + + + + + 280 + 0 + + + + <html><head/><body><p><img src=":/new/prefix1/OtherPic/AspectRatioStrategy.jpg"/></p></body></html> + + + 1 + + + + Ignore Aspect Ratio + + + + + Keep Aspect Ratio + + + + + Keep Aspect Ratio By Expanding + + + + + + + + + + + 0 + 0 + + + + Height: + + + + + + + pixels + + + 1 + + + 999999999 + + + 1080 + + + + + + + pixels + + + 1 + + + 999999999 + + + 1920 + + + + + + + + + 1.Set the height and width of the resolution. +2.Select a file in the file list. +3.Click the Apply button to set the resolution. + +★Scale ratio will not be applied to files which +already have custom resolution applied.★ + + + QPushButton{ +background-color: rgb(26, 188, 156); +color: rgb(255, 255, 255); +border-style:outset; +border-radius:8px; +padding:10px; +} +QPushButton:hover{ +background-color: rgb(29, 214, 177); +color: rgb(255, 255, 255); +border-style:outset; +border-radius:8px; +padding:10px; +} +QPushButton:pressed{ +background-color: rgb(23, 173, 143); +color: rgb(255, 255, 255); +border-style:outset; +border-radius:8px; +padding:10px; +} +QPushButton:disabled{ +background-color: rgb(166, 166, 166); +color: rgb(255, 255, 255); +border-style:outset; +border-radius:8px; +padding:10px; +} + + + Apply + + + + + + + 1.Select a file in the file list. +2.Click the Cancel button to cancel the custom resolution. + + + QPushButton{ +background-color: rgb(231, 76, 60); +color: rgb(255, 255, 255); +border-style:outset; +border-radius:8px; +padding:10px; +} +QPushButton:hover{ +background-color: rgb(255, 102, 64); +color: rgb(255, 255, 255); +border-style:outset; +border-radius:8px; +padding:10px; +} +QPushButton:pressed{ +background-color: rgb(204, 65, 53); +color: rgb(255, 255, 255); +border-style:outset; +border-radius:8px; +padding:10px; +} +QPushButton{ +background-color: rgb(231, 76, 60); +color: rgb(255, 255, 255); +border-style:outset; +border-radius:8px; +padding:10px; +} +QPushButton:hover{ +background-color: rgb(255, 102, 64); +color: rgb(255, 255, 255); +border-style:outset; +border-radius:8px; +padding:10px; +} +QPushButton:disabled{ + background-color: rgb(166, 166, 166); +color: rgb(255, 255, 255); +border-style:outset; +border-radius:8px; +padding:10px; +} + + + Cancel + + + + + + + + + + 0 + 0 + + + + Automatically skip file when its resolution +is larger than the specified resolution. + + + Auto Skip + + + + + + + + 0 + 0 + + + + Valid for all files. + + + Apply to all + + + + + + + + + + + 0 + 0 + + + + + 16777215 + 16777215 + + + + + + + + 6 + + + 6 + + + 6 + + + 6 + + + + + true + + + + 0 + 0 + + + + + 0 + 45 + + + + + 16777215 + 16777215 + + + + QFrame::StyledPanel + + + QFrame::Raised + + + + QLayout::SetDefaultConstraint + + + 0 + + + 0 + + + 0 + + + 0 + + + 7 + + + + + + 0 + 0 + + + + Image quality: + + + + + + + Only takes effect when processing Static Image. + +Will NOT take effect when processing Video and GIF. + + + 1 + + + 100 + + + 100 + + + + + + + + + + + 16777215 + 16777215 + + + + Select the image style of the source files. +So the engine can load the correct model when processing files. + + + Image Style(waifu2x-ncnn-vulkan): + + + Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter + + + + + + + Select the image style of the source files. +So the engine can load the correct model when processing files. + + + Image Style(waifu2x-caffe): + + + + + + + true + + + + 0 + 0 + + + + + 0 + 45 + + + + + 16777215 + 16777215 + + + + QFrame::NoFrame + + + QFrame::Plain + + + 0 + + + + 0 + + + 0 + + + 0 + + + 0 + + + 7 + + + + + Only takes effect when processing Static Image. + +Will NOT take effect when processing Video and GIF. + + + 0 + + + 15 + + + + png + + + + + jpg + + + + + webp + + + + + bmp + + + + + tiff + + + + + pdf + + + + + gif + + + + + eps + + + + + tga + + + + + jp2 + + + + + svg + + + + + + + + Save image as: + + + + + + + + + + + 120 + 0 + + + + Select the image style of the source files. +So the engine can load the correct model when processing files. + + + 2D Anime + + + + 2D Anime + + + + + 3D Real-life + + + + + + + + Select the image style of the source files. +So the engine can load the correct model when processing files. + + + + 2D Anime + + + + + 3D Real-life + + + + + + + + + 0 + 0 + + + + + 0 + 0 + + + + QFrame::StyledPanel + + + QFrame::Raised + + + + 0 + + + 0 + + + 0 + + + 0 + + + 3 + + + 0 + + + + + + 0 + 0 + + + + Qt::ActionsContextMenu + + + Delete the original file after processing is complete. + +*This option will be deactivated when [Replace original +file] is enabled* + +[Right click here to show more options] + + + Delete original files + + + + + + + + 0 + 0 + + + + Qt::ActionsContextMenu + + + After processing the file, directly replace +the original file with the result file. +(And keep the original file name.) + +WARNING: The original file will be DELETED. + +*This option will be deactivated when [Output +path] or [Delete original files] is enabled* + +[Right click here to show more options] + + + Replace original file + + + + + + + + 0 + 0 + + + + Optimizing the scaled gif will slightly reduce the +image quality, but it can reduce the GIF file size. + +It is recommended to enable this option. + + + Optimize GIF + + + + + + + + + + Select the action to be executed automatically +after processing all files in the file list. + + + + Do nothing(when finished) + + + + + Shut down + + + + + Sleep + + + + + Hibernate + + + + + Restart + + + + + + + + When there are finished files in the list, the finished files will +be processed again when the processing process is started again. + + + Re-process finished files + + + + + + + false + + + + 50 + false + + + + Skip the super-resolution, only interpolate video frames. + +You can modify the settings of Frame Interpolation in the +[Video settings] tab. + +*Only taken effect when processing video* + + + + + + Frame Interpolation only(Video) + + + + + + + Interpolate frames after super-resolution of the video. +(Increase the frame rate to the result video.) + +You can modify the settings of Frame Interpolation +in the [Video settings] tab. + +You can enable [Frame Interpolation only(Video)] to skip +the super-resolution, only interpolate video frames. + +*Only taken effect when processing video* + + + color: rgb(33, 85, 255); + + + Video Frame Interpolation + + + + + + + + + + + 0 + 0 + + + + + 16777215 + 16777215 + + + + Output path(Folder): + + + false + + + + 6 + + + 6 + + + 6 + + + 6 + + + + + false + + + Qt::StrongFocus + + + Qt::ActionsContextMenu + + + Output path must be a Folder. + +[Right click here to show more options] + + + + + + true + + + + + + + + 0 + 0 + + + + background-color: rgb(255, 255, 255); + + + QFrame::Sunken + + + QAbstractScrollArea::AdjustIgnored + + + true + + + + + 0 + 0 + 241 + 122 + + + + + + + false + + + + 0 + 0 + + + + Keep original file name + + + + + + + + + + 0 + 0 + + + + When this option is enabled, the output file +will be moved to the path you specified. +Otherwise, it will be saved in the same +folder as the source file. + +*This option will be deactivated when [Replace +original file] is enabled* + + + Enabled + + + + + + + false + + + + 0 + 0 + + + + When this option is enabled, the output file will +replace the file with the same name as the output +file that exists in the output path. + + + Overwrite + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + false + + + + 0 + 0 + + + + Keep parent folder + + + + + + + false + + + Automatically open the output folder +after processing all files. + + + Auto-open after finished + + + + + + + + + + + + + + + + + 0 + 0 + + + + + 0 + 0 + + + + + 16777215 + 85 + + + + + + + Qt::AlignCenter + + + true + + + false + + + + + + QFrame::Plain + + + Qt::Vertical + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + + + + 0 + 0 + + + + color: rgb(255, 70, 14); + + + Scale ratio: + + + + + + + + 0 + 0 + + + + Range: 1 ~ 999999999 + + + Image + + + + + + + 4 + + + 1.000000000000000 + + + 99999.000000000000000 + + + 2.000000000000000 + + + + + + + Qt::Vertical + + + + + + + + 0 + 0 + + + + Range: 1 ~ 999999999 + + + Animated Image + + + + + + + 4 + + + 1.000000000000000 + + + 99999.000000000000000 + + + 2.000000000000000 + + + + + + + Qt::Vertical + + + + + + + + 0 + 0 + + + + Range: 1 ~ 999999999 + + + Video + + + + + + + 4 + + + 1.000000000000000 + + + 99999.000000000000000 + + + 2.000000000000000 + + + + + + + + + QFrame::Plain + + + Qt::Horizontal + + + + + + + + + + 0 + 0 + + + + color: rgb(33, 85, 254); + + + Deoise level: + + + + + + + + 0 + 0 + + + + Image + + + + + + + true + + + Qt::WheelFocus + + + -1 + + + 3 + + + 1 + + + QAbstractSpinBox::DefaultStepType + + + 2 + + + 10 + + + + + + + Qt::Vertical + + + + + + + + 0 + 0 + + + + Animated Image + + + + + + + true + + + Qt::WheelFocus + + + -1 + + + 3 + + + 1 + + + QAbstractSpinBox::DefaultStepType + + + 2 + + + 10 + + + + + + + Qt::Vertical + + + + + + + + 0 + 0 + + + + Video + + + + + + + true + + + Qt::WheelFocus + + + -1 + + + 3 + + + 1 + + + QAbstractSpinBox::DefaultStepType + + + 2 + + + 10 + + + + + + + + + + + + + + 0 + 0 + + + + You need to enable [Video Frame Interpolation] to use this option. + +If the fps of orignal video is 30 fps, multiple of fps is "4", +then the result video will be 120 fps. + + + Multiple of FPS: + + + + + + + + + + 30 + 16777215 + + + + - + + + + + + + Qt::NoFocus + + + You need to enable [Video Frame Interpolation] to use this option. + +If the fps of orignal video is 30 fps, multiple of fps is "4", +then the result video will be 120 fps. + + + false + + + true + + + QAbstractSpinBox::NoButtons + + + false + + + 2 + + + 999999999 + + + 0 + + + + + + + + 0 + 0 + + + + + 30 + 16777215 + + + + + + + + + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + + + + + + + + :/new/prefix1/icon/EngineSettings.png:/new/prefix1/icon/EngineSettings.png + + + Engine settings + + + + 6 + + + 6 + + + 6 + + + 6 + + + 0 + + + + + true + + + + 0 + 0 + + + + + 16777215 + 16777215 + + + + + + + Number of threads + + + Qt::AlignCenter + + + false + + + + 6 + + + 6 + + + 6 + + + 6 + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + 0 + 0 + + + + QFrame::NoFrame + + + QFrame::Raised + + + + 0 + + + 0 + + + 0 + + + 0 + + + + + + 0 + 0 + + + + + 16777215 + 16777215 + + + + + + + + + + + + + Image: + + + + + + + Qt::Vertical + + + + + + + + 0 + 0 + + + + + 16777215 + 16777215 + + + + + + + Video: + + + + + + + Qt::Vertical + + + + + + + + 0 + 0 + + + + The number of threads that the software processes GIF, +which will determine how many frames the software will +process at the same time. + +The actual maximum number of threads is limited by the +number of enabled GPUs when using Anime4k, Waifu2x-Caffe +and Waifu2x-converter.(Only when processing GIF and Video) + + + 1 + + + 999999999 + + + 1 + + + 1 + + + + + + + + 0 + 0 + + + + The number of threads that the software processes Video, +which will determine how many frames the software will +process at the same time. + +The actual maximum number of threads is limited by the +number of enabled GPUs when using Anime4k, Waifu2x-Caffe +and Waifu2x-converter.(Only when processing GIF and Video) + + + 1 + + + 999999999 + + + 1 + + + 1 + + + + + + + + 0 + 0 + + + + + 16777215 + 16777215 + + + + + + + Animated Image: + + + + + + + + 0 + 0 + + + + The number of threads that the software processes Image, +which will determine how many images the software will +process at the same time. + + + 1 + + + 999999999 + + + 1 + + + 1 + + + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + + + 0 + 0 + + + + Engine + + + Qt::AlignCenter + + + false + + + false + + + + 6 + + + 6 + + + 6 + + + 6 + + + + + Qt::Horizontal + + + + + + + + 0 + 0 + + + + QFrame::NoFrame + + + QFrame::Raised + + + + 0 + + + 0 + + + 0 + + + 0 + + + + + + 0 + 0 + + + + QFrame::NoFrame + + + QFrame::Raised + + + + 0 + + + 0 + + + 0 + + + 0 + + + + + + 0 + 0 + + + + + 16777215 + 16777215 + + + + Animated Image: + + + Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter + + + + + + + Qt::Vertical + + + + + + + true + + + + 190 + 0 + + + + Waifu2x-NCNN-Vulkan [Speed:★★ Image quality:★★★] [2D Anime]&[3D Real-life] +Waifu2x-Converter [Speed:★☆ Image quality:★★☆] [2D Anime] +Anime4K [Speed:★★★ Image quality:★☆ ] [2D Anime] +SRMD-NCNN-Vulkan [Speed:★☆ Image quality:★★★] [2D Anime]&[3D Real-life] +Waifu2x-Caffe [Speed:★☆ Image quality:★★★] [2D Anime]&[3D Real-life] +RealSR-NCNN-Vulkan [Speed:☆ Image quality:★★★] [3D Real-life] +SRMD-CUDA [Speed:★★☆ Image quality:★★★] [2D Anime]&[3D Real-life] + + + waifu2x-ncnn-vulkan + + + QComboBox::AdjustToContents + + + + waifu2x-ncnn-vulkan + + + + + waifu2x-converter + + + + + srmd-ncnn-vulkan + + + + + Anime4K + + + + + waifu2x-caffe + + + + + realsr-ncnn-vulkan + + + + + [BETA] srmd-cuda + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + 0 + 0 + + + + + 16777215 + 16777215 + + + + Image: + + + Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter + + + + + + + + 0 + 0 + + + + + 16777215 + 16777215 + + + + Video: + + + Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter + + + + + + + Qt::Vertical + + + + + + + true + + + + 190 + 0 + + + + Waifu2x-NCNN-Vulkan [Speed:★★ Image quality:★★★] [2D Anime]&[3D Real-life] +Waifu2x-Converter [Speed:★☆ Image quality:★★☆] [2D Anime] +Anime4K [Speed:★★★ Image quality:★☆ ] [2D Anime] +SRMD-NCNN-Vulkan [Speed:★☆ Image quality:★★★] [2D Anime]&[3D Real-life] +Waifu2x-Caffe [Speed:★☆ Image quality:★★★] [2D Anime]&[3D Real-life] +RealSR-NCNN-Vulkan [Speed:☆ Image quality:★★★] [3D Real-life] +SRMD-CUDA [Speed:★★☆ Image quality:★★★] [2D Anime]&[3D Real-life] + + + waifu2x-ncnn-vulkan + + + QComboBox::AdjustToContents + + + + waifu2x-ncnn-vulkan + + + + + waifu2x-converter + + + + + Anime4k + + + + + srmd-ncnn-vulkan + + + + + waifu2x-caffe + + + + + realsr-ncnn-vulkan + + + + + [BETA] srmd-cuda + + + + + + + + true + + + + 190 + 0 + + + + + 16777215 + 16777215 + + + + Waifu2x-NCNN-Vulkan [Speed:★★ Image quality:★★★] [2D Anime]&[3D Real-life] +Waifu2x-Converter [Speed:★☆ Image quality:★★☆] [2D Anime] +Anime4K [Speed:★★★ Image quality:★☆ ] [2D Anime] +SRMD-NCNN-Vulkan [Speed:★☆ Image quality:★★★] [2D Anime]&[3D Real-life] +Waifu2x-Caffe [Speed:★☆ Image quality:★★★] [2D Anime]&[3D Real-life] +RealSR-NCNN-Vulkan [Speed:☆ Image quality:★★★] [3D Real-life] +SRMD-CUDA [Speed:★★☆ Image quality:★★★] [2D Anime]&[3D Real-life] + + + waifu2x-ncnn-vulkan + + + QComboBox::AdjustToContents + + + + waifu2x-ncnn-vulkan + + + + + waifu2x-converter + + + + + srmd-ncnn-vulkan + + + + + Anime4K + + + + + waifu2x-caffe + + + + + realsr-ncnn-vulkan + + + + + [BETA] srmd-cuda + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + + + + + + + + QTabWidget::North + + + 0 + + + false + + + + Waifu2x-ncnn-vulkan + + + Waifu2x-NCNN-Vulkan: + +- Supports [2D Anime] and [3D Real-life] image style. But not at the +same time, you need to change [Image style] settings at [Home] tab. + +- More suitable for processing [2D Anime] image. + +- [ Speed:★★ Image Quality:★★★ ] + + + + 6 + + + 6 + + + 6 + + + 6 + + + 7 + + + + + + + + 0 + 0 + + + + Select the GPU to use when enabling the "waifu2x-ncnn-vulkan" engine. + + + GPU ID: + + + + + + + true + + + + 0 + 0 + + + + + 180 + 0 + + + + Select the GPU to use when enabling the "waifu2x-ncnn-vulkan" engine. +★ "-1" is CPU,others are GPUs ★ + + + auto + + + + auto + + + + + + + + true + + + + 0 + 0 + + + + QPushButton{ +background-color: rgb(178, 58, 238); +color: rgb(255, 255, 255); +border-style:outset; +border-radius:8px; +padding:10px; +} +QPushButton:hover{ +background-color: rgb(191, 62, 255); +color: rgb(255, 255, 255); +border-style:outset; +border-radius:8px; +padding:10px; +} +QPushButton:pressed{ +background-color: rgb(154, 50, 205); +color: rgb(255, 255, 255); +border-style:outset; +border-radius:8px; +padding:10px; +} +QPushButton:disabled{ +background-color: rgb(166, 166, 166); +color: rgb(255, 255, 255); +border-style:outset; +border-radius:8px; +padding:10px; +} + + + Detect available GPU ID + + + + + + + + 0 + 0 + + + + 1.You need at least 2 available GPUs. + +2.If you wanna get all GPUs running together, +the number of threads must >= the number of GPUs. + +3.You need to [Detect available GPU ID] first. + +*Only latest version fully supports Multi-GPU* + + + Enable Multi-GPU + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + + + + 0 + 0 + + + + + 16777215 + 16777215 + + + + Tile size: This value will affects GPU memory usage. +Larger tile size means waifu2x will use more GPU memory and run faster. +Smaller tile size means waifu2x will use less GPU memory and run slower. +(Only works when using "waifu2x-ncnn-vulkan" engine.) + + + Tile size: + + + + + + + + 0 + 0 + + + + QFrame::NoFrame + + + QFrame::Raised + + + + QLayout::SetDefaultConstraint + + + 0 + + + 0 + + + 0 + + + 0 + + + + + + 0 + 0 + + + + + 30 + 30 + + + + - + + + + + + + + 0 + 0 + + + + Tile size: This value will affects GPU memory usage. +Larger Tile size means waifu2x will use more GPU memory and run faster. +Smaller Tile size means waifu2x will use less GPU memory and run slower. + + + 32 + + + 999999999 + + + 10 + + + 128 + + + + + + + + 0 + 0 + + + + + 30 + 30 + + + + + + + + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + 0 + + + + + false + + + + 0 + 0 + + + + + 16777215 + 16777215 + + + + GPU Settings(Multi-GPU) + + + Qt::AlignCenter + + + true + + + + 0 + + + 6 + + + 0 + + + 6 + + + 7 + + + + + + + + + + + + 32 + + + 999999999 + + + 10 + + + 128 + + + + + + + + 0 + 0 + + + + Enable + + + true + + + + + + + Show current Multi-GPU settings. + + + QPushButton{ +background-color: rgb(231, 76, 60); +color: rgb(255, 255, 255); +border-style:outset; +border-radius:8px; +padding:10px; +} +QPushButton:hover{ +background-color: rgb(255, 102, 64); +color: rgb(255, 255, 255); +border-style:outset; +border-radius:8px; +padding:10px; +} +QPushButton:pressed{ +background-color: rgb(204, 65, 53); +color: rgb(255, 255, 255); +border-style:outset; +border-radius:8px; +padding:10px; +} +QPushButton:disabled{ +background-color: rgb(166, 166, 166); +color: rgb(255, 255, 255); +border-style:outset; +border-radius:8px; +padding:10px; +} + + + Show GPUs Settings + + + + + + + + 0 + 0 + + + + Tile size: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + 0 + 0 + + + + GPU ID: + + + Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter + + + + + + + Qt::Vertical + + + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + Qt::Horizontal + + + + + + + Qt::Horizontal + + + + + + + + + + 0 + 0 + + + + Version: + + + + + + + 0 + + + + Latest(Alpha channel,TTA,Multi-GPU) + + + + + 20200414-fp16p(TTA,Multi-GPU(Image only)) + + + + + Old(Multi-GPU(Image only)) + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + + + + 0 + 0 + + + + Model: + + + + + + + We recommend you use the default "upconv_7" model. +Only "upconv_7" model supports image style switching. +"cunet" model only supports 2D anime image style, +and it's much more slower than "upconv_7" model. + + + + upconv_7 + + + + + cunet(Only support 2D Anime) + + + + + + + + + 0 + 0 + + + + TTA(Test-Time Augmentation): +The processing time is eight times longer than when unchecked, +and the peak signal-to-noise ratio (PSNR) is increased by 0.15, +but the effect may not be obvious. It is not recommended to enable it. +[TTA] is not available for [OLD Version] of waifu2x-ncnn-vulkan. + + + TTA + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + Qt::Horizontal + + + + + + + + Waifu2x-converter + + + Waifu2x-Converter: + +- Only supports [2D Anime] image style. + +- [ Speed:★☆ Image Quality:★★☆ ] + + + + 6 + + + 6 + + + 6 + + + 6 + + + 7 + + + + + Qt::Horizontal + + + + + + + + + + 0 + 0 + + + + Force to use OpenCL on Intel Platform. + + + Force OpenCL + + + + + + + + 0 + 0 + + + + Disable GPU + + + + + + + + 0 + 0 + + + + TTA(Test-Time Augmentation): +The processing time is eight times longer than when unchecked, +and the peak signal-to-noise ratio (PSNR) is increased by 0.15, +but the effect may not be obvious. It is not recommended to enable it. + + + TTA + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + Qt::Horizontal + + + + + + + + + + 0 + 0 + + + + Target processor: + + + + + + + true + + + + 180 + 0 + + + + auto + + + + auto + + + + + + + + true + + + + 0 + 0 + + + + QPushButton{ + background-color: rgb(238, 119, 133); +color: rgb(255, 255, 255); +border-style:outset; +border-radius:8px; +padding:10px; +} +QPushButton:hover{ + background-color: rgb(255, 127, 144); +color: rgb(255, 255, 255); +border-style:outset; +border-radius:8px; +padding:10px; +} +QPushButton:pressed{ + background-color: rgb(226, 112, 128); +color: rgb(255, 255, 255); +border-style:outset; +border-radius:8px; +padding:10px; +} +QPushButton:disabled{ +background-color: rgb(166, 166, 166); +color: rgb(255, 255, 255); +border-style:outset; +border-radius:8px; +padding:10px; +} + + + Dump processor list + + + + + + + + 0 + 0 + + + + 1.You need at least 2 available processors. + +2.If you wanna get all processors running together, +the number of threads must >= the number of processors. + +3.You need to [Dump processor list] first. + + + Enable Multi-Processor + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + + + + 0 + 0 + + + + Block size: This value will affects GPU memory usage. +Larger Block size means waifu2x will use more GPU memory and run faster. +Smaller Block size means waifu2x will use less GPU memory and run slower. + + + Block size: + + + + + + + + 0 + 0 + + + + QFrame::NoFrame + + + QFrame::Raised + + + + 0 + + + 0 + + + 0 + + + 0 + + + + + + 30 + 30 + + + + - + + + + + + + Block size: This value will affects GPU memory usage. +Larger Block size means waifu2x will use more GPU memory and run faster. +Smaller Block size means waifu2x will use less GPU memory and run slower. + + + 32 + + + 999999999 + + + 10 + + + 256 + + + + + + + + 30 + 30 + + + + + + + + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + + + false + + + + 0 + 0 + + + + + 16777215 + 16777215 + + + + Processor Settings(Multi-Processor) + + + Qt::AlignCenter + + + true + + + + 6 + + + 6 + + + 6 + + + 6 + + + + + Show current Multi-Processor settings. + + + QPushButton{ +background-color: rgb(231, 76, 60); +color: rgb(255, 255, 255); +border-style:outset; +border-radius:8px; +padding:10px; +} +QPushButton:hover{ +background-color: rgb(255, 102, 64); +color: rgb(255, 255, 255); +border-style:outset; +border-radius:8px; +padding:10px; +} +QPushButton:pressed{ +background-color: rgb(204, 65, 53); +color: rgb(255, 255, 255); +border-style:outset; +border-radius:8px; +padding:10px; +} +QPushButton:disabled{ +background-color: rgb(166, 166, 166); +color: rgb(255, 255, 255); +border-style:outset; +border-radius:8px; +padding:10px; +} + + + Show Processor Settings + + + + + + + + 0 + 0 + + + + Processor ID: + + + Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter + + + + + + + + 0 + 0 + + + + Block size: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + + + + + + + + 0 + 0 + + + + Enable + + + true + + + + + + + 32 + + + 999999999 + + + 10 + + + 256 + + + + + + + Qt::Vertical + + + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + + + 0 + 0 + + + + Anime4K + + + Anime4K: + +- Only supports [2D Anime] image style. + +- More suitable for image with not too bad quality. + +- You can enable [ACNet] algorithm to improve image quality. + +- Although [GPU Mode] is not enabled by default, in most cases, +enabling [GPU Mode] can greatly increase the processing speed. +(Please make sure your PC is compatible with [GPU Mode] first) + +- [ Speed:★★★ Image Quality:★ ] + + + + 6 + + + 6 + + + 6 + + + 6 + + + + + + 0 + 0 + + + + QFrame::StyledPanel + + + QFrame::Raised + + + + 0 + + + 0 + + + 0 + + + 0 + + + + + false + + + + 0 + 0 + + + + OpenCL parallel IO command queue +*Enable this might cause compatibility problem* + + + OpenCL parallel IO + + + + + + + true + + + + 0 + 0 + + + + Enable ACNet. +Will improve image quality. + + + ACNet + + + + + + + false + + + + 0 + 0 + + + + Enable HDN mode for ACNet. +Will improve image quality. + +*This option will be deactivated +when [ACNet] is disabled* + + + HDN mode + + + true + + + + + + + + 0 + 0 + + + + Faster but maybe low quality. + + + Fast mode + + + + + + + OpenCL command queues: + + + + + + + false + + + + 0 + 0 + + + + Number of OpenCL command queues + + + 1 + + + 999999999 + + + + + + + Qt::Vertical + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + + Qt::Horizontal + + + + + + + + 0 + 0 + + + + QFrame::NoFrame + + + QFrame::Sunken + + + + 0 + + + 0 + + + 0 + + + 0 + + + + + false + + + + 0 + 0 + + + + + 230 + 0 + + + + Format: Platform ID,Device ID: + +Example: 0,0:0,1:1,0: + +You must follow the format,otherwise the software may crash. + +If you wanna get all GPUs running together, +the number of threads must >= the number of GPUs. + + + 0,0: + + + true + + + + + + + false + + + + 0 + 0 + + + + + 16777215 + 35 + + + + QPushButton{ +background-color: rgb(26, 188, 156); +color: rgb(255, 255, 255); +border-style:outset; +border-radius:8px; +padding:10px; +} +QPushButton:hover{ +background-color: rgb(29, 214, 177); +color: rgb(255, 255, 255); +border-style:outset; +border-radius:8px; +padding:10px; +} +QPushButton:pressed{ +background-color: rgb(23, 173, 143); +color: rgb(255, 255, 255); +border-style:outset; +border-radius:8px; +padding:10px; +} +QPushButton:disabled{ +background-color: rgb(166, 166, 166); +color: rgb(255, 255, 255); +border-style:outset; +border-radius:8px; +padding:10px; +} + + + List GPUs + + + + + + + false + + + + 0 + 0 + + + + + 130 + 0 + + + + GPGPU model. + +Only NVIDIA products support CUDA. + + + + OpenCL + + + + + CUDA + + + + + + + + Qt::Vertical + + + + + + + + 0 + 0 + + + + Enable GPU acceleration. + + + GPU Mode + + + + + + + false + + + + 0 + 0 + + + + Verify your GPUs configuration. + + + QPushButton{ +background-color: rgb(178, 58, 238); +color: rgb(255, 255, 255); +border-style:outset; +border-radius:8px; +padding:10px; +} +QPushButton:hover{ +background-color: rgb(191, 62, 255); +color: rgb(255, 255, 255); +border-style:outset; +border-radius:8px; +padding:10px; +} +QPushButton:pressed{ +background-color: rgb(154, 50, 205); +color: rgb(255, 255, 255); +border-style:outset; +border-radius:8px; +padding:10px; +} +QPushButton:disabled{ +background-color: rgb(166, 166, 166); +color: rgb(255, 255, 255); +border-style:outset; +border-radius:8px; +padding:10px; +} + + + Verify + + + + + + + false + + + + 0 + 0 + + + + You can specify multiple GPUs to fully +utilize the capabilities of your PC. +(If there are multiple GPUs available.) + + + Specify GPUs: + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + + Qt::Horizontal + + + + + + + + 0 + 0 + + + + + 16777215 + 42 + + + + + 0 + + + 0 + + + 0 + + + 0 + + + + + + 0 + 0 + + + + Strength for pushing color,range 0 to 1,higher for thinner. + + + Push color strength: + + + + + + + + 0 + 0 + + + + + 100 + 0 + + + + 1.000000000000000 + + + 0.100000000000000 + + + 1.000000000000000 + + + + + + + + 0 + 0 + + + + 1 + + + 999999999 + + + 2 + + + + + + + + 0 + 0 + + + + + 100 + 0 + + + + 1.000000000000000 + + + 0.100000000000000 + + + 0.300000000000000 + + + + + + + + 0 + 0 + + + + Passes for processing. + + + Passes: + + + + + + + + 0 + 0 + + + + 1 + + + 999999999 + + + 2 + + + + + + + + 0 + 0 + + + + Strength for pushing gradient,range 0 to 1,higher for sharper. + + + Push gradient strength: + + + + + + + + 0 + 0 + + + + Limit the number of color pushes. + + + Push color count: + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + + + + + 16777215 + 16777215 + + + + + + + Pre-processing + + + + 6 + + + 6 + + + 6 + + + 6 + + + + + Qt::Horizontal + + + + + + + Mean blur + + + + + + + Median blur + + + + + + + Gaussian blur weak + + + + + + + CAS Sharpening + + + true + + + + + + + Gaussian blur + + + + + + + Bilateral filter + + + + + + + Bilateral filter faster + + + + + + + Apply filters to image before process it. + + + Enable Pre-processing + + + true + + + + + + + + + + + + + Post-processing + + + + 6 + + + 6 + + + 6 + + + 6 + + + + + Add filters to the image after processing it. + + + Enable Post-processing + + + true + + + + + + + Qt::Horizontal + + + + + + + Median blur + + + + + + + Mean blur + + + + + + + CAS Sharpening + + + false + + + + + + + Gaussian blur + + + + + + + Bilateral filter + + + true + + + + + + + Gaussian blur weak + + + true + + + + + + + Bilateral filter faster + + + + + + + + + + + + + SRMD-ncnn-vulkan + + + SRMD-NCNN-Vulkan: + +- Supports [2D Anime] and [3D Real-life] image style at the same time. + +- More suitable for processing [3D Real-life] images. + +- [ Speed:★☆ Image Quality:★★★ ] + + + + 6 + + + 6 + + + 6 + + + 6 + + + 7 + + + + + + + false + + + + 0 + 0 + + + + + 16777215 + 16777215 + + + + GPU Settings(Multi-GPU) + + + Qt::AlignCenter + + + true + + + + 6 + + + 6 + + + 6 + + + 6 + + + + + + 0 + 0 + + + + Enable + + + true + + + + + + + + 0 + 0 + + + + Tile size: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + + + + + + + Show current Multi-GPU settings. + + + QPushButton{ +background-color: rgb(231, 76, 60); +color: rgb(255, 255, 255); +border-style:outset; +border-radius:8px; +padding:10px; +} +QPushButton:hover{ +background-color: rgb(255, 102, 64); +color: rgb(255, 255, 255); +border-style:outset; +border-radius:8px; +padding:10px; +} +QPushButton:pressed{ +background-color: rgb(204, 65, 53); +color: rgb(255, 255, 255); +border-style:outset; +border-radius:8px; +padding:10px; +} +QPushButton:disabled{ +background-color: rgb(166, 166, 166); +color: rgb(255, 255, 255); +border-style:outset; +border-radius:8px; +padding:10px; +} + + + Show GPUs Settings + + + + + + + 32 + + + 999999999 + + + 10 + + + 128 + + + + + + + + 0 + 0 + + + + GPU ID: + + + Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter + + + + + + + Qt::Vertical + + + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + + + + 0 + 0 + + + + GPU ID: + + + + + + + + 180 + 0 + + + + Select the GPU to use when enabling the "srmd-ncnn-vulkan" engine. + + + auto + + + + auto + + + + + + + + + 0 + 0 + + + + QPushButton{ +background-color: rgb(52, 152, 219); +color: rgb(255, 255, 255); +border-style:outset; +border-radius:8px; +padding:10px; +} +QPushButton:hover{ +background-color: rgb(60, 177, 255); +color: rgb(255, 255, 255); +border-style:outset; +border-radius:8px; +padding:10px; +} +QPushButton:pressed{ +background-color: rgb(45, 134, 193); +color: rgb(255, 255, 255); +border-style:outset; +border-radius:8px; +padding:10px; +} +QPushButton:disabled{ +background-color: rgb(166, 166, 166); +color: rgb(255, 255, 255); +border-style:outset; +border-radius:8px; +padding:10px; +} + + + Detect available GPU ID + + + + + + + + 0 + 0 + + + + 1.You need at least 2 available GPUs. + +2.If you wanna get all GPUs running together, +the number of threads must >= the number of GPUs. + +3.You need to [Detect available GPU ID] first. + + + Enable Multi-GPU + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + + + + 0 + 0 + + + + Tile size: This value will affects GPU memory usage. +Larger tile size means SRMD will use more GPU memory and run faster. +Smaller tile size means SRMD will use less GPU memory and run slower. + + + Tile size: + + + + + + + + 0 + 0 + + + + QFrame::NoFrame + + + QFrame::Raised + + + + 0 + + + 0 + + + 0 + + + 0 + + + + + + 30 + 30 + + + + + + + + + + + + + 30 + 30 + + + + - + + + + + + + + 0 + 0 + + + + Tile size: This value will affects GPU memory usage. +Larger tile size means SRMD will use more GPU memory and run faster. +Smaller tile size means SRMD will use less GPU memory and run slower. + + + 32 + + + 999999999 + + + 10 + + + 128 + + + + + + + + + + + 0 + 0 + + + + TTA(Test-Time Augmentation): +The processing time is eight times longer than when unchecked, +and the peak signal-to-noise ratio (PSNR) is increased by 0.15, +but the effect may not be obvious. It is not recommended to enable it. + + + TTA + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + + 0 + 0 + + + + Qt::Horizontal + + + + + + + + Waifu2x-Caffe + + + Waifu2x-Caffe: + +- Supports [2D Anime] and [3D Real-life] image style. But not at the +same time, you need to change [Image style] settings at [Home] tab. + +- More suitable for processing [2D Anime] images. + +- When using [CPU Process mode], it's very slow, so only using this +engine when your PC is compatible with [GPU(or cuDNN) Process mode] +is recommended. + +- [ Speed:★☆ Image Quality:★★★ ] + + + + + + + + + 0 + 0 + + + + 3D Real-life Model: + + + + + + + + 220 + 0 + + + + Model for processing 3D Real-life style image. + + + upconv_7_photo + + + + upconv_7_photo + + + + + photo + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + + + + 0 + 0 + + + + The batch size defines the number of samples that +will be propagated through the network. + + + Batch size: + + + + + + + + 120 + 0 + + + + The batch size defines the number of samples that +will be propagated through the network. + + + 1 + + + 999999999 + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + Qt::Horizontal + + + + + + + + + + 0 + 0 + + + + Process mode: + + + + + + + + 130 + 0 + + + + CPU + + + 0 + + + + CPU + + + + + GPU + + + + + cuDNN + + + + + + + + TTA(Test-Time Augmentation): +The processing time is eight times longer than when unchecked, +and the peak signal-to-noise ratio (PSNR) is increased by 0.15, +but the effect may not be obvious. It is not recommended to enable it. + + + TTA + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + + + false + + + + 0 + 0 + + + + You need to switch [Process mode] to +[GPU] or [cuDNN] to enable Multi-GPU. + + + Multi-GPU: + + + + + + + false + + + + 0 + 0 + + + + + 300 + 0 + + + + Format: GPU ID,Batch size,Split size: + +Example: 0,1,128:1,2,64:2,1,128: + +You must follow the format,otherwise the software may crash. + +If you wanna get all GPUs running together, +the number of threads must >= the number of GPUs. + + + 0,1,128: + + + true + + + + + + + false + + + + 0 + 0 + + + + Verify your GPUs configuration. + + + QPushButton{ +background-color: rgb(178, 58, 238); +color: rgb(255, 255, 255); +border-style:outset; +border-radius:8px; +padding:10px; +} +QPushButton:hover{ +background-color: rgb(191, 62, 255); +color: rgb(255, 255, 255); +border-style:outset; +border-radius:8px; +padding:10px; +} +QPushButton:pressed{ +background-color: rgb(154, 50, 205); +color: rgb(255, 255, 255); +border-style:outset; +border-radius:8px; +padding:10px; +} +QPushButton:disabled{ +background-color: rgb(166, 166, 166); +color: rgb(255, 255, 255); +border-style:outset; +border-radius:8px; +padding:10px; +} + + + Verify + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + Qt::Horizontal + + + + + + + Qt::Horizontal + + + + + + + Qt::Horizontal + + + + + + + + + + 0 + 0 + + + + 2D Anime Model: + + + + + + + Model for processing 2D Anime style image. + + + anime_style_art_rgb + + + 1 + + + + anime_style_art + + + + + anime_style_art_rgb + + + + + cunet + + + + + photo + + + + + upconv_7_anime_style_art_rgb + + + + + upconv_7_photo + + + + + upresnet10 + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + + + + 0 + 0 + + + + GPU ID: + + + + + + + + 150 + 0 + + + + Select the GPU to use when enabling the "waifu2x-caffe" engine. + + + 999999999 + + + 1 + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + Qt::Horizontal + + + + + + + + + + 0 + 0 + + + + Split size: This value will affects GPU memory usage. +Larger Split size means waifu2x will use more GPU memory and run faster. +Smaller Split size means waifu2x will use less GPU memory and run slower. + + + Split size: + + + + + + + + 30 + 16777215 + + + + Decrease split size. + + + - + + + + + + + + 0 + 0 + + + + Split size: This value will affects GPU memory usage. +Larger Split size means waifu2x will use more GPU memory and run faster. +Smaller Split size means waifu2x will use less GPU memory and run slower. + + + true + + + QAbstractSpinBox::NoButtons + + + QAbstractSpinBox::CorrectToNearestValue + + + 1 + + + 999999999 + + + 128 + + + + + + + + 30 + 16777215 + + + + Increase split size. + + + + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + Qt::Horizontal + + + + + + + + RealSR-ncnn-vulkan + + + RealSR-NCNN-Vulkan: + +- Only support [3D Real-life] image style. + +- Best engine for processing [3D Real-life] images. + +- Much more slower than other engines. + +- [ Speed:☆ Image Quality:★★★ ] + + + + 6 + + + 6 + + + 6 + + + 6 + + + 7 + + + + + Qt::Horizontal + + + + + + + Qt::Horizontal + + + + + + + + + + 0 + 0 + + + + Model: + + + + + + + + models-DF2K_JPEG(Supports denoise) + + + + + models-DF2K(Does NOT supports denoise) + + + + + + + + TTA(Test-Time Augmentation): +The processing time is eight times longer than when unchecked, +and the peak signal-to-noise ratio (PSNR) is increased by 0.15, +but the effect may not be obvious. It is not recommended to enable it. + + + TTA + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + + + + 0 + 0 + + + + GPU ID: + + + + + + + true + + + + 180 + 0 + + + + Select the GPU to use when enabling the "Realsr-ncnn-vulkan" engine. + + + auto + + + + auto + + + + + + + + true + + + + 0 + 0 + + + + QPushButton{ +background-color: rgb(52, 152, 219); +color: rgb(255, 255, 255); +border-style:outset; +border-radius:8px; +padding:10px; +} +QPushButton:hover{ +background-color: rgb(60, 177, 255); +color: rgb(255, 255, 255); +border-style:outset; +border-radius:8px; +padding:10px; +} +QPushButton:pressed{ +background-color: rgb(45, 134, 193); +color: rgb(255, 255, 255); +border-style:outset; +border-radius:8px; +padding:10px; +} +QPushButton:disabled{ +background-color: rgb(166, 166, 166); +color: rgb(255, 255, 255); +border-style:outset; +border-radius:8px; +padding:10px; +} + + + Detect available GPU ID + + + + + + + + 0 + 0 + + + + 1.You need at least 2 available GPUs. + +2.If you wanna get all GPUs running together, +the number of threads must >= the number of GPUs. + +3.You need to [Detect available GPU ID] first. + + + Enable Multi-GPU + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + + + + 0 + 0 + + + + Tile size: + + + + + + + true + + + + 0 + 0 + + + + + 0 + 0 + + + + QFrame::NoFrame + + + QFrame::Raised + + + + 0 + + + 0 + + + 0 + + + 0 + + + + + + 30 + 30 + + + + - + + + + + + + Tile size: This value will affects GPU memory usage. +Larger tile size means Realsr will use more GPU memory and run faster. +Smaller tile size means Realsr will use less GPU memory and run slower. + + + 32 + + + 999999999 + + + 10 + + + 128 + + + + + + + + 30 + 30 + + + + + + + + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + + + false + + + + 0 + 0 + + + + + 16777215 + 16777215 + + + + GPU Settings(Multi-GPU) + + + Qt::AlignCenter + + + true + + + + 6 + + + 6 + + + 6 + + + 6 + + + + + + 0 + 0 + + + + Enable + + + true + + + + + + + + 0 + 0 + + + + GPU ID: + + + Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter + + + + + + + + 0 + 0 + + + + Tile size: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + Show current Multi-GPU settings. + + + QPushButton{ +background-color: rgb(231, 76, 60); +color: rgb(255, 255, 255); +border-style:outset; +border-radius:8px; +padding:10px; +} +QPushButton:hover{ +background-color: rgb(255, 102, 64); +color: rgb(255, 255, 255); +border-style:outset; +border-radius:8px; +padding:10px; +} +QPushButton:pressed{ +background-color: rgb(204, 65, 53); +color: rgb(255, 255, 255); +border-style:outset; +border-radius:8px; +padding:10px; +} +QPushButton:disabled{ +background-color: rgb(166, 166, 166); +color: rgb(255, 255, 255); +border-style:outset; +border-radius:8px; +padding:10px; +} + + + Show GPUs Settings + + + + + + + + + + + + + + 32 + + + 999999999 + + + 10 + + + 128 + + + + + + + Qt::Vertical + + + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + + + + + + + + + + :/new/prefix1/icon/VideoSettings.png:/new/prefix1/icon/VideoSettings.png + + + Video settings + + + + 5 + + + 5 + + + 5 + + + 5 + + + 5 + + + + + Qt::Horizontal + + + + 226 + 20 + + + + + + + + + 0 + 0 + + + + Frame Interpolation + + + true + + + false + + + + 6 + + + 6 + + + 6 + + + 6 + + + 0 + + + + + false + + + + 0 + 0 + + + + QFrame::NoFrame + + + QFrame::Raised + + + 0 + + + + 0 + + + 0 + + + 0 + + + 0 + + + + + + 0 + 0 + + + + QFrame::NoFrame + + + QFrame::Raised + + + + 0 + + + 0 + + + 0 + + + 0 + + + + + + 0 + 0 + + + + You should enable this option when processing Ultra High Definition videos. + +The software will automatically enable UHD Mode when it detects input with +resolution higher than 3840×2160. + +Only works when using [rife-ncnn-vulkan] engine. + + + UHD Mode + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + Qt::Vertical + + + + + + + + 0 + 0 + + + + QFrame::NoFrame + + + QFrame::Raised + + + + 0 + + + 0 + + + 0 + + + 0 + + + + + + 0 + 0 + + + + Frame Interpolation Engine: + + + + + + + + 0 + 0 + + + + RIFE-NCNN-Vulkan [Speed:★★★ Image quality:★★☆] [2D Anime]&[3D Real-life] +CAIN-NCNN-Vulkan [Speed:★★★ Image quality:★★☆] [2D Anime]&[3D Real-life] +DAIN-NCNN-Vulkan [Speed:☆ Image quality:★★★] [2D Anime]&[3D Real-life] + + + + rife-ncnn-vulkan + + + + + cain-ncnn-vulkan + + + + + dain-ncnn-vulkan + + + + + + + + + + + + 0 + 0 + + + + TTA(Test-Time Augmentation): +The processing time is eight times longer than when unchecked, +and the peak signal-to-noise ratio (PSNR) is increased by 0.15, +but the effect may not be obvious. It is not recommended to enable it. + +Only works when using [rife-ncnn-vulkan] engine. + + + TTA Mode + + + + + + + Interpolate frames after upscaled. + +By default the frames will be interpolated before upscaled, +because PC with low vram will encounter difficulties when +interpolate high res frames. + + + After Upscale + + + + + + + + + + Qt::Horizontal + + + + + + + Qt::Vertical + + + + + + + + + + 0 + 0 + + + + GPU ID: + + + + + + + "-1" is CPU, others are GPUs + + + + auto + + + + + + + + + 0 + 0 + + + + QPushButton{ +background-color: rgb(52, 152, 219); +color: rgb(255, 255, 255); +border-style:outset; +border-radius:8px; +padding:10px; +} +QPushButton:hover{ +background-color: rgb(60, 177, 255); +color: rgb(255, 255, 255); +border-style:outset; +border-radius:8px; +padding:10px; +} +QPushButton:pressed{ +background-color: rgb(45, 134, 193); +color: rgb(255, 255, 255); +border-style:outset; +border-radius:8px; +padding:10px; +} +QPushButton:disabled{ +background-color: rgb(166, 166, 166); +color: rgb(255, 255, 255); +border-style:outset; +border-radius:8px; +padding:10px; +} + + + Detect available GPU ID + + + + + + + + + + + + 0 + 0 + + + + Multi GPU + + + + + + + + 0 + 0 + + + + Format: GPU ID,GPU ID + +Example: 0,1 + +You must follow the format,otherwise the software may crash. + + + + + + + + 0 + 0 + + + + Verify your Multi GPU configuration. + + + QPushButton{ +background-color: rgb(178, 58, 238); +color: rgb(255, 255, 255); +border-style:outset; +border-radius:8px; +padding:10px; +} +QPushButton:hover{ +background-color: rgb(191, 62, 255); +color: rgb(255, 255, 255); +border-style:outset; +border-radius:8px; +padding:10px; +} +QPushButton:pressed{ +background-color: rgb(154, 50, 205); +color: rgb(255, 255, 255); +border-style:outset; +border-radius:8px; +padding:10px; +} +QPushButton:disabled{ +background-color: rgb(166, 166, 166); +color: rgb(255, 255, 255); +border-style:outset; +border-radius:8px; +padding:10px; +} + + + Verify + + + + + + + + + + + + 0 + 0 + + + + This value will affects GPU memory usage. +Only works when using [dain-ncnn-vulkan] engine. + + + Tile size: + + + + + + + Qt::NoFocus + + + This value will affects GPU memory usage. +Only works when using [dain-ncnn-vulkan] engine. + + + 128 + + + 999999999 + + + 32 + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + + + + + + 0 + 0 + + + + Model: + + + + + + + Choose the model for rife-ncnn-vulkan engine. + +We recommend you to use the default model "rife-v2.4". + +Only works when using [rife-ncnn-vulkan] engine. + + + 5 + + + + rife + + + + + rife-anime + + + + + rife-HD + + + + + rife-UHD + + + + + rife-v2 + + + + + rife-v2.4 + + + + + + + + + + + + + 0 + 0 + + + + The multi-threading of the frame interpolation engines is NOT +very stable, we don't recommend you to enable this option. + + + Multithreading: + + + + + + + + 0 + 0 + + + + Number of threads. + + + 1 + + + 999999999 + + + + + + + + 0 + 0 + + + + When successive failures are detected, the number +of threads will be adjusted automatically. + + + Auto adjust + + + false + + + + + + + + + + + + + + + + + + 0 + 0 + + + + + 16777215 + 55 + + + + Audio denoise(for video) + + + + 6 + + + 6 + + + 6 + + + 6 + + + + + false + + + + 0 + 0 + + + + + 80 + 0 + + + + How much noise should be removed is specified by amount-a +number between 0.01 and 1 with a default of 0.20. Higher +numbers will remove more noise but present a greater +likelihood of removing wanted components of the audio signal. + + + 2 + + + 0.010000000000000 + + + 1.000000000000000 + + + 0.010000000000000 + + + 0.200000000000000 + + + + + + + + 0 + 0 + + + + + 0 + 0 + + + + Denoise level: + + + + + + + + 0 + 0 + + + + Enabled + + + + + + + Qt::Vertical + + + + + + + + + + Qt::Horizontal + + + + 673 + 45 + + + + + + + + + 0 + 0 + + + + + 16777215 + 16777215 + + + + Custom video settings + + + true + + + false + + + + 6 + + + 6 + + + 6 + + + 6 + + + + + + + false + + + When output the result video + + + + 5 + + + 5 + + + 5 + + + 5 + + + 5 + + + + + + + + 0 + 0 + + + + Encoder(video): + + + + + + + If you leave it empty, software will use auto settings. + + + libx264 + + + + + + + + + + + + 0 + 0 + + + + Bitrate(video): + + + + + + + If you set it to 0, software will use auto settings. + + + K + + + 0 + + + 999999999 + + + 100 + + + 6000 + + + + + + + + + + + + 0 + 0 + + + + Encoder(audio): + + + + + + + If you leave it empty, software will use auto settings. + + + aac + + + + + + + + + + + + 0 + 0 + + + + Bitrate(audio): + + + + + + + If you set it to 0, software will use auto settings. + + + K + + + 0 + + + 999999999 + + + 10 + + + 320 + + + + + + + + + + + + 0 + 0 + + + + Pixel format: + + + + + + + If you leave it empty, software will use auto settings. + + + yuv420p + + + + + + + + + Qt::Horizontal + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + 0 + 0 + + + + QFrame::NoFrame + + + QFrame::Raised + + + + 0 + + + 0 + + + 0 + + + 0 + + + 5 + + + + + + 0 + 0 + + + + Extra command: + + + + + + + You can enter ffmpeg instructions here. + + + + + + true + + + + + + + + + + + + + false + + + When convert source video to CFR mp4 + + + + 5 + + + 5 + + + 5 + + + 5 + + + 5 + + + + + Qt::Horizontal + + + + 130 + 208 + + + + + + + + + + + 0 + 0 + + + + Bitrate(audio): + + + + + + + If you set it to 0, software will use auto settings. + + + K + + + 0 + + + 999999999 + + + 10 + + + 320 + + + + + + + + + Qt::Horizontal + + + + + + + + + + 0 + 0 + + + + When this is enabled, ffmpeg will copy the audio part of +the original video directly to the mp4, may cause error. + +Command: -acodec copy + +This option will not take effect when source video's frame +rate mode is variable. + + + Copy audio stream + + + + + + + + 0 + 0 + + + + When this is enabled, ffmpeg will copy the video part of +the original video directly to the mp4, may cause error. + +Command: -vcodec copy + +This option will not take effect when source video's frame +rate mode is variable. + + + Copy video stream + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + + 0 + 0 + + + + QFrame::NoFrame + + + QFrame::Raised + + + + 0 + + + 0 + + + 0 + + + 0 + + + 5 + + + + + + 0 + 0 + + + + Extra command: + + + + + + + You can enter ffmpeg instructions here. + + + + + + true + + + + + + + + + + + + + 0 + 0 + + + + Bitrate(video): + + + + + + + If you set it to 0, software will use auto settings. + + + K + + + 0 + + + 999999999 + + + 100 + + + 2500 + + + + + + + + + Ignore the frame rate mode of the source video. +Might cause ERROR. + + + Ignore frame rate mode + + + + + + + + + + + + + 0 + 0 + + + + QFrame::StyledPanel + + + QFrame::Raised + + + + 0 + + + 0 + + + 0 + + + 0 + + + + + + 0 + 0 + + + + Reset video settings + + + QPushButton{ +background-color: rgb(231, 76, 60); +color: rgb(255, 255, 255); +border-style:outset; +border-radius:8px; +padding:10px; +} +QPushButton:hover{ +background-color: rgb(255, 102, 64); +color: rgb(255, 255, 255); +border-style:outset; +border-radius:8px; +padding:10px; +} +QPushButton:pressed{ +background-color: rgb(204, 65, 53); +color: rgb(255, 255, 255); +border-style:outset; +border-radius:8px; +padding:10px; +} +QPushButton:disabled{ +background-color: rgb(166, 166, 166); +color: rgb(255, 255, 255); +border-style:outset; +border-radius:8px; +padding:10px; +} + + + Reset video settings + + + + + + + + 0 + 0 + + + + QPushButton{ +background-color: rgb(52, 152, 219); +color: rgb(255, 255, 255); +border-style:outset; +border-radius:8px; +padding:10px; +} +QPushButton:hover{ +background-color: rgb(60, 177, 255); +color: rgb(255, 255, 255); +border-style:outset; +border-radius:8px; +padding:10px; +} +QPushButton:pressed{ +background-color: rgb(45, 134, 193); +color: rgb(255, 255, 255); +border-style:outset; +border-radius:8px; +padding:10px; +} +QPushButton:disabled{ +background-color: rgb(166, 166, 166); +color: rgb(255, 255, 255); +border-style:outset; +border-radius:8px; +padding:10px; +} + + + List Available Encoders + + + + + + + Qt::Horizontal + + + + 549 + 20 + + + + + + + + + + + + + + Process video by segment + + + + + + + 0 + 0 + + + + When processing video in segments, the length of each video clip. +This will determine how much hard disk space the program will occupy +when processing video in segments. + + + Segment duration: + + + + + + + + 0 + 0 + + + + When processing video in segments, the length of each video clip. +This will determine how much hard disk space the program will occupy +when processing video in segments. + + + secs + + + + + + 1 + + + 999999999 + + + 30 + + + + + + + Processing video in segments can greatly reduce the +hard disk space occupied by processing video. But it +will increase the time required to process video. + + + Enabled + + + true + + + + + + + Qt::Vertical + + + + + + + + + + + + :/new/prefix1/icon/AddSetting.png:/new/prefix1/icon/AddSetting.png + + + Additional settings + + + + 6 + + + 6 + + + 6 + + + 6 + + + 5 + + + + + + + + + + 16777215 + 16777215 + + + + Input file extensions + + + + + + + + + 0 + 0 + + + + + 50 + 16777215 + + + + When you find that the file format you want to process cannot +be added to the file list, you can add the file extension yourself +in the additional settings. + +Each extension needs to be separated by ":" + +(There is no guarantee that the file format you add will +be processed successfully) + + + Image: + + + + + + + + 300 + 0 + + + + false + + + When you find that the file format you want to process cannot +be added to the file list, you can add the file extension yourself +in the additional settings. + +Each extension needs to be separated by ":" + +(There is no guarantee that the file format you add will +be processed successfully) + + + png:jpg:jpeg:tif:tiff:bmp + + + + + + + + + + + + 0 + 0 + + + + + 50 + 16777215 + + + + When you find that the file format you want to process cannot +be added to the file list, you can add the file extension yourself +in the additional settings. + +Each extension needs to be separated by ":" + +(There is no guarantee that the file format you add will +be processed successfully) + + + Video: + + + + + + + + 300 + 0 + + + + false + + + When you find that the file format you want to process cannot +be added to the file list, you can add the file extension yourself +in the additional settings. + +Each extension needs to be separated by ":" + +(There is no guarantee that the file format you add will +be processed successfully) + + + mp4:3gp:avi:flv:mkv:mov:mpg:ogg:vob:webm:wmv + + + + + + + + + + + Convert every image to PNG before processing it. +Enabling this option will improve compatibility. However, it will +increase the time and storage space required to process image. + + + Pre-process all images + + + + + + + true + + + When the alpha channel is detected in the picture, software will +automatically force the picture to be saved as PNG. + + + Auto detect Alpha channel + + + true + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + + 0 + 0 + + + + This software already can intelligently detect whether the Alpha channel is lost, +and automatically reprocess the picture. And image will be pre-processed during the +reporcess so the alpha channel won't lost again. + +However, this will cause additional time consumption. If re-processing +frequently occurs when processing images, you can enable this option to save time. + + + Always pre-process images with Alpha Channel + + + false + + + + + + + + + + + 16777215 + 16777215 + + + + Custom Font Settings (Restart the software to take effect) + + + + + + + + + 0 + 0 + + + + Custom font: + + + Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter + + + + + + + false + + + 宋体 + + + + 宋体 + + + + + + + + + + + + false + + + + 0 + 0 + + + + + 16777215 + 16777215 + + + + QPushButton{ +background-color: rgb(26, 188, 156); +color: rgb(255, 255, 255); +border-style:outset; +border-radius:8px; +padding:10px; +} +QPushButton:hover{ +background-color: rgb(29, 214, 177); +color: rgb(255, 255, 255); +border-style:outset; +border-radius:8px; +padding:10px; +} +QPushButton:pressed{ +background-color: rgb(23, 173, 143); +color: rgb(255, 255, 255); +border-style:outset; +border-radius:8px; +padding:10px; +} +QPushButton:disabled{ +background-color: rgb(166, 166, 166); +color: rgb(255, 255, 255); +border-style:outset; +border-radius:8px; +padding:10px; +} + + + Save Custom Font Settings + + + + + + + + 0 + 0 + + + + Enable Custom Font Settings. + + + Enable + + + + + + + + + + + + 0 + 0 + + + + Custom font size: + + + Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter + + + + + + + false + + + + 0 + 0 + + + + + 80 + 0 + + + + + 16777215 + 16777215 + + + + 1 + + + 999 + + + 15 + + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + + + 0 + 0 + + + + + 16777215 + 16777215 + + + + + + + + + + + + true + + + QPushButton{ +background-color: rgb(178, 58, 238); +color: rgb(255, 255, 255); +border-style:outset; +border-radius:8px; +padding:10px; +} +QPushButton:hover{ +background-color: rgb(191, 62, 255); +color: rgb(255, 255, 255); +border-style:outset; +border-radius:8px; +padding:10px; +} +QPushButton:pressed{ +background-color: rgb(154, 50, 205); +color: rgb(255, 255, 255); +border-style:outset; +border-radius:8px; +padding:10px; +} +QPushButton:disabled{ +background-color: rgb(166, 166, 166); +color: rgb(255, 255, 255); +border-style:outset; +border-radius:8px; +padding:10px; +} + + + Save settings + + + + + + + QPushButton{ +background-color: rgb(238, 99, 99); +color: rgb(255, 255, 255); +border-style:outset; +border-radius:8px; +padding:10px; +} +QPushButton:hover{ +background-color: rgb(255, 106, 106); +color: rgb(255, 255, 255); +border-style:outset; +border-radius:8px; +padding:10px; +} +QPushButton:pressed{ +background-color: rgb(205, 85, 85); +color: rgb(255, 255, 255); +border-style:outset; +border-radius:8px; +padding:10px; +} +QPushButton:disabled{ +background-color: rgb(166, 166, 166); +color: rgb(255, 255, 255); +border-style:outset; +border-radius:8px; +padding:10px; +} + + + Reset settings + + + + + + + + 9 + false + + + + QPushButton{ +background-color: rgb(26, 188, 156); +color: rgb(255, 255, 255); +border-style:outset; +border-radius:8px; +padding:10px; +} +QPushButton:hover{ +background-color: rgb(29, 214, 177); +color: rgb(255, 255, 255); +border-style:outset; +border-radius:8px; +padding:10px; +} +QPushButton:pressed{ +background-color: rgb(23, 173, 143); +color: rgb(255, 255, 255); +border-style:outset; +border-radius:8px; +padding:10px; +} +QPushButton:disabled{ +background-color: rgb(166, 166, 166); +color: rgb(255, 255, 255); +border-style:outset; +border-radius:8px; +padding:10px; +} + + + Check update + + + + + + + + + + + + false + + + + QPushButton{ +background-color: rgb(231, 76, 60); +color: rgb(255, 255, 255); +border-style:outset; +border-radius:8px; +padding:10px; +} +QPushButton:hover{ +background-color: rgb(255, 102, 64); +color: rgb(255, 255, 255); +border-style:outset; +border-radius:8px; +padding:10px; +} +QPushButton:pressed{ +background-color: rgb(204, 65, 53); +color: rgb(255, 255, 255); +border-style:outset; +border-radius:8px; +padding:10px; +} +QPushButton:disabled{ +background-color: rgb(166, 166, 166); +color: rgb(255, 255, 255); +border-style:outset; +border-radius:8px; +padding:10px; +} + + + Report issue + + + + + + + + false + + + + QPushButton{ +background-color: rgb(255, 181, 6); +color: rgb(255, 255, 255); +border-style:outset; +border-radius:8px; +padding:10px; +} +QPushButton:hover{ +background-color: rgb(255, 200, 50); +color: rgb(255, 255, 255); +border-style:outset; +border-radius:8px; +padding:10px; +} +QPushButton:pressed{ +background-color: rgb(255, 170, 0); +color: rgb(255, 255, 255); +border-style:outset; +border-radius:8px; +padding:10px; +} +QPushButton:disabled{ +background-color: rgb(166, 166, 166); +color: rgb(255, 255, 255); +border-style:outset; +border-radius:8px; +padding:10px; +} + + + Official website + + + + + + + Open Waifu2x-Extension-GUI online wiki. + + + QPushButton{ +background-color: rgb(178, 58, 238); +color: rgb(255, 255, 255); +border-style:outset; +border-radius:8px; +padding:10px; +} +QPushButton:hover{ +background-color: rgb(191, 62, 255); +color: rgb(255, 255, 255); +border-style:outset; +border-radius:8px; +padding:10px; +} +QPushButton:pressed{ +background-color: rgb(154, 50, 205); +color: rgb(255, 255, 255); +border-style:outset; +border-radius:8px; +padding:10px; +} +QPushButton:disabled{ +background-color: rgb(166, 166, 166); +color: rgb(255, 255, 255); +border-style:outset; +border-radius:8px; +padding:10px; +} + + + Wiki + + + + + + + + + + + + 16777215 + 16777215 + + + + QPushButton{ +background-color: rgb(52, 152, 219); +color: rgb(255, 255, 255); +border-style:outset; +border-radius:8px; +padding:10px; +} +QPushButton:hover{ +background-color: rgb(60, 177, 255); +color: rgb(255, 255, 255); +border-style:outset; +border-radius:8px; +padding:10px; +} +QPushButton:pressed{ +background-color: rgb(45, 134, 193); +color: rgb(255, 255, 255); +border-style:outset; +border-radius:8px; +padding:10px; +} +QPushButton:disabled{ +background-color: rgb(166, 166, 166); +color: rgb(255, 255, 255); +border-style:outset; +border-radius:8px; +padding:10px; +} + + + About + + + + + + + QPushButton{ +background-color: rgb(255, 66, 77); +color: rgb(255, 255, 255); +border-style:outset; +border-radius:8px; +padding:10px; +} +QPushButton:hover{ +background-color: rgb(255, 105, 112); +color: rgb(255, 255, 255); +border-style:outset; +border-radius:8px; +padding:10px; +} +QPushButton:pressed{ +background-color: rgb(223, 50, 61); +color: rgb(255, 255, 255); +border-style:outset; +border-radius:8px; +padding:10px; +} +QPushButton:disabled{ +background-color: rgb(166, 166, 166); +color: rgb(255, 255, 255); +border-style:outset; +border-radius:8px; +padding:10px; +} + + + Top Supporters + + + + + + + + + + + + + + + + + + 6 + + + 6 + + + 6 + + + 6 + + + 7 + + + + + QFrame::NoFrame + + + QFrame::Raised + + + + 0 + + + 0 + + + 0 + + + 0 + + + 5 + + + + + + 0 + 0 + + + + A pop-up window will prompts when an update is detected. + + + Update popup + + + true + + + + + + + Settings will be saved automatically when you close the software. + + + Auto save settings + + + true + + + + + + + This option will be automatically enabled to improve +performance and fix issues when the software detects +that your PC has compatibility issues with ImageMagick. + + + Disable "-resize" + + + + + + + Prompt when exit + + + true + + + + + + + Minimize to taskbar + + + + + + + [Text browser] will be automatically hidden when the software starts. + + + Always hide Text Browser + + + + + + + When adding a folder to the file list, scan the files in +the subfolder and add them to the file list. + + + Scan sub-folders + + + true + + + + + + + + 0 + 0 + + + + QFrame::NoFrame + + + QFrame::Raised + + + 0 + + + + 0 + + + 0 + + + 0 + + + 0 + + + 2 + + + + + + 0 + 0 + + + + The number of retries when an image (or frame) processing fails. + + + Retry: + + + + + + + + 0 + 0 + + + + The number of retries when an image (or frame) processing fails. + + + 1 + + + 999999999 + + + 6 + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + + Stop downloading any data from Gitee. + +When you cannot access github, enabling +this option will affect the automatic +detection of new updates. + + + Ban Gitee + + + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + QFrame::Raised + + + Qt::Vertical + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + QFrame::NoFrame + + + QFrame::Raised + + + + 0 + + + 0 + + + 0 + + + 0 + + + 5 + + + + + + 0 + 0 + + + + QFrame::NoFrame + + + QFrame::Raised + + + 0 + + + + 0 + + + 0 + + + 0 + + + 0 + + + 2 + + + + + + 150 + 0 + + + + We recommend that you restart the software after changing +the language for the language settings to fully take effect. + + + English + + + + English + + + + + 简体中文 + + + + + 繁體中文(由uimee翻譯) + + + + + + + + + 0 + 0 + + + + + 16777215 + 16777215 + + + + We recommend that you restart the software after changing +the language for the language settings to fully take effect. + + + Language: + + + Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter + + + + + + + + + + Play Notification sound. + + + Notification sound + + + true + + + + + + + When the file processing status changes, the file list scrolls automatically. + + + Automatic file list scrolling + + + true + + + + + + + + 0 + 0 + + + + QFrame::NoFrame + + + QFrame::Raised + + + 0 + + + + 0 + + + 0 + + + 0 + + + 0 + + + 2 + + + + + + 0 + 0 + + + + Update channel: + + + + + + + + 0 + 0 + + + + + + + + Stable + + + + + Beta + + + + + + + + + + + Keep video cache after processing the video. + + + Keep video cache + + + false + + + + + + + Interactive file list + + + false + + + + + + + [Settings] will be automatically hidden when the software starts. + + + Always hide Settings + + + + + + + Output internal Scale and Denoise progress of GIF and video process inside textbrowser. + + + Show internal progress + + + true + + + + + + + Show the summary pop-up window after processing all files. + + + Summary popup + + + true + + + + + + + + + + + + + + + + + :/new/prefix1/icon/CompatibilityTest.png:/new/prefix1/icon/CompatibilityTest.png + + + Compatibility test + + + + 6 + + + 6 + + + 6 + + + 6 + + + 0 + + + + + + 0 + 0 + + + + Run a compatibility test to see which engines your computer is compatible with. + + + QPushButton{ + background-color: rgb(92, 172, 238); +color: rgb(255, 255, 255); +border-style:outset; +border-radius:8px; +padding:10px; +} +QPushButton:hover{ + background-color: rgb(99, 184, 255); +color: rgb(255, 255, 255); +border-style:outset; +border-radius:8px; +padding:10px; +} +QPushButton:pressed{ +background-color: rgb(79, 148,205); +color: rgb(255, 255, 255); +border-style:outset; +border-radius:8px; +padding:10px; +} +QPushButton:disabled{ +background-color: rgb(166, 166, 166); +color: rgb(255, 255, 255); +border-style:outset; +border-radius:8px; +padding:10px; +} + + + Start compatibility test + + + + + + + + 0 + 0 + + + + 19 + + + 0 + + + false + + + QProgressBar::TopToBottom + + + + + + + true + + + Compatibility test results + + + + 6 + + + 6 + + + 6 + + + 6 + + + + + true + + + Qt::NoFocus + + + By @nihui(https://github.com/nihui) + +https://github.com/nihui/waifu2x-ncnn-vulkan + + + QCheckBox:disabled{ + color: rgb(0, 0, 0); +} + + + Waifu2x-ncnn-vulkan(OLD) + + + + + + + true + + + Qt::NoFocus + + + By @nihui(https://github.com/nihui) + +https://github.com/nihui/waifu2x-ncnn-vulkan + + + QCheckBox:disabled{ + color: rgb(0, 0, 0); +} + + + Waifu2x-ncnn-vulkan(Latest) + + + true + + + false + + + + + + + By @nihui(https://github.com/nihui) + +https://github.com/nihui/realsr-ncnn-vulkan + + + Realsr-ncnn-vulkan + + + + + + + https://www.ffmpeg.org/ + + + FFprobe + + + + + + + true + + + false + + + Qt::NoFocus + + + Qt::NoContextMenu + + + By @DeadSix27(https://github.com/DeadSix27) + +https://github.com/DeadSix27/waifu2x-converter-cpp + + + QCheckBox:disabled{ + color: rgb(0, 0, 0); +} + + + Waifu2x-converter + + + true + + + + + + + true + + + Qt::NoFocus + + + By @nihui(https://github.com/nihui) + +https://github.com/nihui/waifu2x-ncnn-vulkan + + + QCheckBox:disabled{ + color: rgb(0, 0, 0); +} + + + Waifu2x-ncnn-vulkan(20200414(fp16p)) + + + + + + + https://www.lcdf.org/gifsicle/ + + + Gifsicle + + + + + + + true + + + Qt::NoFocus + + + By @nihui(https://github.com/nihui) + +https://github.com/nihui/srmd-ncnn-vulkan + + + QCheckBox:disabled{ + color: rgb(0, 0, 0); +} + + + SRMD-ncnn-vulkan + + + + + + + Qt::Horizontal + + + + + + + https://imagemagick.org/ + + + ImageMagick + + + + + + + http://sox.sourceforge.net/ + + + SoX + + + + + + + true + + + Qt::NoFocus + + + By @TianZerL(https://github.com/TianZerL) + +https://github.com/TianZerL/Anime4KCPP + + + QCheckBox:disabled{ + color: rgb(0, 0, 0); +} + + + Anime4K(GPU) + + + + + + + By @lltcggie(https://github.com/lltcggie) + +https://github.com/lltcggie/waifu2x-caffe + + + Waifu2x-caffe(CPU) + + + + + + + + 0 + 0 + + + + + 16777215 + 30 + + + + Plugins: + + + + + + + By @lltcggie(https://github.com/lltcggie) + +https://github.com/lltcggie/waifu2x-caffe + + + Waifu2x-caffe(GPU) + + + + + + + + 0 + 0 + + + + + 16777215 + 30 + + + + Super-Resolution Engines: + + + + + + + https://www.ffmpeg.org/ + + + FFmpeg + + + + + + + true + + + Qt::NoFocus + + + By @TianZerL(https://github.com/TianZerL) + +https://github.com/TianZerL/Anime4KCPP + + + QCheckBox:disabled{ + color: rgb(0, 0, 0); +} + + + Anime4K(CPU) + + + + + + + By @lltcggie(https://github.com/lltcggie) + +https://github.com/lltcggie/waifu2x-caffe + + + Waifu2x-caffe(cuDNN) + + + + + + + Qt::Horizontal + + + + + + + + 0 + 0 + + + + Frame Interpolation Engines: + + + + + + + By @nihui(https://github.com/nihui) + +https://github.com/nihui/rife-ncnn-vulkan + + + RIFE-NCNN-Vulkan + + + + + + + By @nihui(https://github.com/nihui) + +https://github.com/nihui/cain-ncnn-vulkan + + + CAIN-NCNN-Vulkan + + + + + + + By @nihui(https://github.com/nihui) + +https://github.com/nihui/dain-ncnn-vulkan + + + DAIN-NCNN-Vulkan + + + + + + + + 660 + 260 + + + + + 16777215 + 260 + + + + QFrame::Box + + + QFrame::Sunken + + + [FFmpeg, FFprobe, ImageMagick, Gifsicle, SoX], one of the Super-Resolution engines and one of the Frame Interpolation engines must be compatible with your computer, to make sure you can use all functions in this software. + +Waifu2x-NCNN-Vulkan [Speed:★★ Image quality:★★★] [2D Anime]&[3D Real-life] +Waifu2x-Converter [Speed:★☆ Image quality:★★☆] [2D Anime] +Anime4K [Speed:★★★ Image quality:★☆ ] [2D Anime] +SRMD-NCNN-Vulkan [Speed:★☆ Image quality:★★★] [2D Anime]&[3D Real-life] +Waifu2x-Caffe [Speed:★☆ Image quality:★★★] [2D Anime]&[3D Real-life] +RealSR-NCNN-Vulkan [Speed:☆ Image quality:★★★] [3D Real-life] +SRMD-CUDA [Speed:★★☆ Image quality:★★★] [2D Anime]&[3D Real-life] + +RIFE-NCNN-Vulkan [Speed:★★★ Image quality:★★☆] [2D Anime]&[3D Real-life] +CAIN-NCNN-Vulkan [Speed:★★★ Image quality:★★☆] [2D Anime]&[3D Real-life] +DAIN-NCNN-Vulkan [Speed:☆ Image quality:★★★] [2D Anime]&[3D Real-life] + + + Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter + + + true + + + + + + + By @MrZihan(https://github.com/MrZihan) + +https://github.com/MrZihan/Super-resolution-SR-CUDA + + + SRMD-CUDA [BETA] + + + + + + + + + + + + + 0 + 0 + + + + + 0 + 95 + + + + + 16777215 + 16777215 + + + + Qt::DefaultContextMenu + + + 0 + + + Qt::Horizontal + + + 5 + + + + + 0 + 0 + + + + + 0 + 0 + + + + + 16777215 + 16777215 + + + + + Arial + + + + false + + + + + + 0 + 0 + + + + + 0 + 0 + + + + + 16777215 + 16777215 + + + + + + + + + + false + + + + QLayout::SetFixedSize + + + 6 + + + 6 + + + 6 + + + 6 + + + 5 + + + + + + 0 + 0 + + + + Clear text browser. + + + QPushButton{ + background-color: rgb(0, 140, 158); +color: rgb(255, 255, 255); +border-style:outset; +border-radius:8px; +padding:10px; +} +QPushButton:hover{ + background-color: rgb(0, 190, 211); +color: rgb(255, 255, 255); +border-style:outset; +border-radius:8px; +padding:10px; +} +QPushButton:pressed{ + background-color: rgb(0, 108, 120); +color: rgb(255, 255, 255); +border-style:outset; +border-radius:8px; +padding:10px; +} +QPushButton:disabled{ +background-color: rgb(166, 166, 166); +color: rgb(255, 255, 255); +border-style:outset; +border-radius:8px; +padding:10px; +} + + + Clear + + + + 25 + 25 + + + + + + + + 5 + + + QLayout::SetFixedSize + + + + + + 0 + 0 + + + + Change the font size of the text browser. + + + Font size: + + + + + + + + 0 + 0 + + + + Change the font size of the text browser. + + + 1 + + + 9 + + + + + + + + + + + + + + + + + + diff --git a/SRC/Waifu2x-Extension-QT/progressBar.cpp b/SRC_v3.41.01-beta/Waifu2x-Extension-QT/progressBar.cpp similarity index 96% rename from SRC/Waifu2x-Extension-QT/progressBar.cpp rename to SRC_v3.41.01-beta/Waifu2x-Extension-QT/progressBar.cpp index 0978e65..1260cca 100644 --- a/SRC/Waifu2x-Extension-QT/progressBar.cpp +++ b/SRC_v3.41.01-beta/Waifu2x-Extension-QT/progressBar.cpp @@ -1,59 +1,59 @@ -/* - Copyright (C) 2021 Aaron Feng - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU Affero General Public License as published - by the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Affero General Public License for more details. - - You should have received a copy of the GNU Affero General Public License - along with this program. If not, see . - - My Github homepage: https://github.com/AaronFeng753 -*/ - -#include "mainwindow.h" -#include "ui_mainwindow.h" -/* -设定进度条最小值与最大值 -*/ -void MainWindow::progressbar_setRange_min_max(int min, int max) -{ - ui->progressBar->setRange(min, max); - TaskNumTotal=max; - ui->label_progressBar_filenum->setText("0/"+QString::number(max,10)); -} -/* -将进度条直接充满 -*/ -void MainWindow::progressbar_SetToMax(int maxval) -{ - ui->progressBar->setValue(maxval); - ui->label_progressBar_filenum->setText(QString::number(maxval,10)+"/"+QString::number(maxval,10)); -} -/* -进度条 进度+1 -*/ -void MainWindow::progressbar_Add() -{ - Progressbar_CurrentVal++; - TaskNumFinished++; - NewTaskFinished=true; - ui->progressBar->setValue(Progressbar_CurrentVal); - ui->label_progressBar_filenum->setText(QString::number(Progressbar_CurrentVal,10)+"/"+QString::number(Progressbar_MaxVal,10)); -} -/* -清空进度条 -*/ -void MainWindow::progressbar_clear() -{ - ui->progressBar->setRange(0, 1); - ui->progressBar->setValue(0); - ui->label_progressBar_filenum->setText("0/0"); -} - +/* + Copyright (C) 2021 Aaron Feng + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU Affero General Public License as published + by the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program. If not, see . + + My Github homepage: https://github.com/AaronFeng753 +*/ + +#include "mainwindow.h" +#include "ui_mainwindow.h" +/* +设定进度条最小值与最大值 +*/ +void MainWindow::progressbar_setRange_min_max(int min, int max) +{ + ui->progressBar->setRange(min, max); + TaskNumTotal=max; + ui->label_progressBar_filenum->setText("0/"+QString::number(max,10)); +} +/* +将进度条直接充满 +*/ +void MainWindow::progressbar_SetToMax(int maxval) +{ + ui->progressBar->setValue(maxval); + ui->label_progressBar_filenum->setText(QString::number(maxval,10)+"/"+QString::number(maxval,10)); +} +/* +进度条 进度+1 +*/ +void MainWindow::progressbar_Add() +{ + Progressbar_CurrentVal++; + TaskNumFinished++; + NewTaskFinished=true; + ui->progressBar->setValue(Progressbar_CurrentVal); + ui->label_progressBar_filenum->setText(QString::number(Progressbar_CurrentVal,10)+"/"+QString::number(Progressbar_MaxVal,10)); +} +/* +清空进度条 +*/ +void MainWindow::progressbar_clear() +{ + ui->progressBar->setRange(0, 1); + ui->progressBar->setValue(0); + ui->label_progressBar_filenum->setText("0/0"); +} + diff --git a/SRC/Waifu2x-Extension-QT/realsr_ncnn_vulkan.cpp b/SRC_v3.41.01-beta/Waifu2x-Extension-QT/realsr_ncnn_vulkan.cpp similarity index 97% rename from SRC/Waifu2x-Extension-QT/realsr_ncnn_vulkan.cpp rename to SRC_v3.41.01-beta/Waifu2x-Extension-QT/realsr_ncnn_vulkan.cpp index 8296719..dc660df 100644 --- a/SRC/Waifu2x-Extension-QT/realsr_ncnn_vulkan.cpp +++ b/SRC_v3.41.01-beta/Waifu2x-Extension-QT/realsr_ncnn_vulkan.cpp @@ -1,2181 +1,2181 @@ -/* - Copyright (C) 2021 Aaron Feng - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU Affero General Public License as published - by the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Affero General Public License for more details. - - You should have received a copy of the GNU Affero General Public License - along with this program. If not, see . - - My Github homepage: https://github.com/AaronFeng753 -*/ - -#include "mainwindow.h" -#include "ui_mainwindow.h" - -int MainWindow::Realsr_NCNN_Vulkan_Image(int rowNum,bool ReProcess_MissingAlphaChannel) -{ - //============================= 读取设置 ================================ - bool DelOriginal = (ui->checkBox_DelOriginal->isChecked()||ui->checkBox_ReplaceOriginalFile->isChecked()); - QString OutPutPath_Final =""; - //========================= 拆解map得到参数 ============================= - //将状态设定到处理中 - emit Send_Table_image_ChangeStatus_rowNumInt_statusQString(rowNum, "Processing"); - //得到原文件路径 - QString SourceFile_fullPath = Table_model_image->item(rowNum,2)->text(); - if(!QFile::exists(SourceFile_fullPath))//判断源文件是否存在 - { - emit Send_TextBrowser_NewMessage(tr("Error occured when processing [")+SourceFile_fullPath+tr("]. Error: [File does not exist.]")); - emit Send_Table_image_ChangeStatus_rowNumInt_statusQString(rowNum, "Failed"); - emit Send_progressbar_Add(); - mutex_ThreadNumRunning.lock(); - ThreadNumRunning--; - mutex_ThreadNumRunning.unlock();//线程数量统计-1 - return 0; - } - //========= 转换到 PNG ========= - QString SourceFile_fullPath_Original = SourceFile_fullPath; - SourceFile_fullPath = Imgae_PreProcess(SourceFile_fullPath_Original,ReProcess_MissingAlphaChannel); - //=============== - int ScaleRatio=2; - bool CustRes_isEnabled = false; - int CustRes_height=0; - int CustRes_width=0; - //检查是是否有自定义分辨率 - if(CustRes_isContained(SourceFile_fullPath_Original)) - { - CustRes_isEnabled=true; - QMap Res_map = CustRes_getResMap(SourceFile_fullPath_Original);//res_map["fullpath"],["height"],["width"] - ScaleRatio = CustRes_CalNewScaleRatio(SourceFile_fullPath,Res_map["height"].toInt(),Res_map["width"].toInt()); - if(ScaleRatio==0) - { - emit Send_TextBrowser_NewMessage(tr("Error occured when processing [")+SourceFile_fullPath_Original+tr("]. Error: [The resolution of the source file cannot be read, so the image cannot be scaled to a custom resolution.]")); - emit Send_Table_image_ChangeStatus_rowNumInt_statusQString(rowNum, "Failed"); - emit Send_progressbar_Add(); - mutex_ThreadNumRunning.lock(); - ThreadNumRunning--; - mutex_ThreadNumRunning.unlock();//线程数量统计-1 - return 0; - } - CustRes_height=Res_map["height"].toInt(); - CustRes_width=Res_map["width"].toInt(); - } - else - { - double ScaleRatio_double_tmp = ui->doubleSpinBox_ScaleRatio_image->value(); - if(ScaleRatio_double_tmp == (int)ScaleRatio_double_tmp) - { - ScaleRatio = qRound(ScaleRatio_double_tmp); - } - else - { - CustRes_isEnabled=true; - QMap Res_map = DoubleScaleRatio_Cal_NewScaleRatio_NewHW(SourceFile_fullPath,ScaleRatio_double_tmp); - //==== - if(Res_map.isEmpty()) - { - emit Send_TextBrowser_NewMessage(tr("Error occured when processing [")+SourceFile_fullPath+tr("]. Error: [Unable to read the resolution of the source file.]")); - emit Send_Table_image_ChangeStatus_rowNumInt_statusQString(rowNum, "Failed"); - emit Send_progressbar_Add(); - mutex_ThreadNumRunning.lock(); - ThreadNumRunning--; - mutex_ThreadNumRunning.unlock();//线程数量统计-1 - return 0; - } - //==== - ScaleRatio = Res_map["ScaleRatio"].toInt(); - CustRes_height = Res_map["Height_new"].toInt(); - CustRes_width = Res_map["width_new"].toInt(); - } - } - //=============== - QFileInfo fileinfo(SourceFile_fullPath); - QString file_name = file_getBaseName(SourceFile_fullPath); - QString file_ext = fileinfo.suffix(); - QString file_path = file_getFolderPath(fileinfo); - QString OutPut_Path = file_path + "/" + file_name + "_waifu2x_"+QString::number(ScaleRatio, 10)+"x_"+file_ext+".png"; - //============================== 放大 ======================================= - QProcess *Waifu2x = new QProcess(); - QString program = Current_Path+"/realsr-ncnn-vulkan/realsr-ncnn-vulkan_waifu2xEX.exe"; - //========== - int ScaleRatio_tmp=Calculate_Temporary_ScaleRatio_RealsrNCNNVulkan(ScaleRatio); - QString InputPath_tmp = SourceFile_fullPath; - QString OutputPath_tmp =""; - for(int retry=0; retry<(ui->spinBox_retry->value()+ForceRetryCount); retry++) - { - bool waifu2x_qprocess_failed = false; - InputPath_tmp = SourceFile_fullPath; - OutputPath_tmp =""; - for(int i=4; i<=ScaleRatio_tmp; i*=4) - { - QString ErrorMSG=""; - QString StanderMSG=""; - //========================== - OutputPath_tmp = file_path + "/" + file_name + "_waifu2x_"+QString::number(i, 10)+"x_"+file_ext+".png"; - QString cmd = "\"" + program + "\"" + " -i " + "\"" + InputPath_tmp + "\"" + " -o " + "\"" + OutputPath_tmp + "\"" + " -s " + "4" + Realsr_NCNN_Vulkan_ReadSettings(); - Waifu2x->start(cmd); - while(!Waifu2x->waitForStarted(100)&&!QProcess_stop) {} - while(!Waifu2x->waitForFinished(500)&&!QProcess_stop) - { - //判断用户是否暂停处理 - if(waifu2x_STOP) - { - Waifu2x->close(); - if(i>4) - { - QFile::remove(InputPath_tmp); - } - QFile::remove(OutputPath_tmp); - emit Send_Table_image_ChangeStatus_rowNumInt_statusQString(rowNum, "Interrupted"); - mutex_ThreadNumRunning.lock(); - ThreadNumRunning--; - mutex_ThreadNumRunning.unlock(); - return 0; - } - //读取输出判断是否出错 - ErrorMSG.append(Waifu2x->readAllStandardError().toLower()); - StanderMSG.append(Waifu2x->readAllStandardOutput().toLower()); - if(ErrorMSG.contains("failed")||StanderMSG.contains("failed")) - { - waifu2x_qprocess_failed = true; - Waifu2x->close(); - if(i>4) - { - QFile::remove(InputPath_tmp); - } - QFile::remove(OutputPath_tmp); - break; - } - } - //=============== - if(waifu2x_qprocess_failed)break; - //=============== - ErrorMSG.append(Waifu2x->readAllStandardError().toLower()); - StanderMSG.append(Waifu2x->readAllStandardOutput().toLower()); - if(ErrorMSG.contains("failed")||StanderMSG.contains("failed")) - { - waifu2x_qprocess_failed = true; - if(i>4) - { - QFile::remove(InputPath_tmp); - } - QFile::remove(OutputPath_tmp); - break; - } - //=============== - if(i>4) - { - QFile::remove(InputPath_tmp); - } - InputPath_tmp = OutputPath_tmp; - } - //========= 检测是否成功,是否需要重试 ============ - if(QFile::exists(OutputPath_tmp)&&!waifu2x_qprocess_failed) - { - break; - } - else - { - QFile::remove(OutputPath_tmp); - if(retry==ui->spinBox_retry->value()+(ForceRetryCount-1))break; - emit Send_TextBrowser_NewMessage(tr("Automatic retry, please wait.")); - Delay_sec_sleep(5); - } - } - if(!QFile::exists(OutputPath_tmp)) - { - if(SourceFile_fullPath_Original!=SourceFile_fullPath) - { - QFile::remove(SourceFile_fullPath); - } - emit Send_TextBrowser_NewMessage(tr("Error occured when processing [")+SourceFile_fullPath_Original+tr("]. Error: [Unable to scale the picture.]")); - emit Send_Table_image_ChangeStatus_rowNumInt_statusQString(rowNum, "Failed"); - emit Send_progressbar_Add(); - mutex_ThreadNumRunning.lock(); - ThreadNumRunning--; - mutex_ThreadNumRunning.unlock(); - return 0; - } - OutPutPath_Final = OutputPath_tmp; - //============================ 调整大小 ==================================================== - if(ScaleRatio_tmp != ScaleRatio||CustRes_isEnabled) - { - int New_height=0; - int New_width=0; - if(CustRes_isEnabled) - { - New_height= CustRes_height; - New_width= CustRes_width; - } - else - { - QMap res_map_OriginalFile = Image_Gif_Read_Resolution(SourceFile_fullPath); - New_height = res_map_OriginalFile["height"]*ScaleRatio; - New_width = res_map_OriginalFile["width"]*ScaleRatio; - } - QImage qimage_adj(OutputPath_tmp); - //读取放大后的图片并调整大小 - QImage qimage_adj_scaled = qimage_adj.scaled(New_width,New_height,CustRes_AspectRatioMode,Qt::SmoothTransformation); - QImageWriter qimageW_adj; - qimageW_adj.setFormat("png"); - qimageW_adj.setFileName(OutPut_Path); - if(qimageW_adj.canWrite()) - { - qimageW_adj.write(qimage_adj_scaled); - } - QFile::remove(OutputPath_tmp); - if(!QFile::exists(OutPut_Path)) - { - emit Send_TextBrowser_NewMessage(tr("Error occured when processing [")+SourceFile_fullPath+tr("]. Error: [Unable to resize the scaled picture to the target size]")); - emit Send_Table_image_ChangeStatus_rowNumInt_statusQString(rowNum, "Failed"); - emit Send_progressbar_Add(); - mutex_ThreadNumRunning.lock(); - ThreadNumRunning--; - mutex_ThreadNumRunning.unlock();//线程数量统计-1 - return 0; - } - OutPutPath_Final = OutPut_Path; - } - if(CustRes_isEnabled) - { - QString OutPut_Path_CustRes = file_path + "/" + file_name + "_waifu2x_"+QString::number(CustRes_width, 10)+"x"+QString::number(CustRes_height, 10)+"_"+file_ext+".png"; - QFile::remove(OutPut_Path_CustRes); - QFile::rename(OutPut_Path,OutPut_Path_CustRes); - OutPutPath_Final = OutPut_Path_CustRes; - } - //=========================== 另存为JPG&压缩JPG =========================================== - OutPutPath_Final = SaveImageAs_FormatAndQuality(SourceFile_fullPath_Original,OutPutPath_Final,false,0); - //================== 检查是否丢失了透明通道 ===================== - if(ReProcess_MissingAlphaChannel==false) - { - QImage QImage_source(SourceFile_fullPath_Original); - QImage QImage_Final(OutPutPath_Final); - if(QImage_source.hasAlphaChannel()==true && QImage_Final.hasAlphaChannel()==false && ui->checkBox_AutoDetectAlphaChannel->isChecked()) - { - QFile::remove(OutPutPath_Final); - emit Send_TextBrowser_NewMessage(tr("Since the Alpha channel in the resulting image is lost, this image will be reprocessed to fix it:[")+SourceFile_fullPath_Original+tr("].\nIf the reprocessing happens a lot, you should consider enable [Always pre-process images with Alpha Channel] in [Additional settings].")); - return Realsr_NCNN_Vulkan_Image(rowNum,true); - } - } - //============================= 删除原文件 & & 更新table status ============================ - if(SourceFile_fullPath_Original!=SourceFile_fullPath) - { - QFile::remove(SourceFile_fullPath); - SourceFile_fullPath = SourceFile_fullPath_Original; - } - if(DelOriginal) - { - if(ReplaceOriginalFile(SourceFile_fullPath,OutPutPath_Final)==false) - { - if(QAction_checkBox_MoveToRecycleBin_checkBox_DelOriginal->isChecked()) - { - file_MoveToTrash(SourceFile_fullPath); - } - else - { - QFile::remove(SourceFile_fullPath); - } - } - emit Send_Table_image_ChangeStatus_rowNumInt_statusQString(rowNum, "Finished, original file deleted"); - } - else - { - emit Send_Table_image_ChangeStatus_rowNumInt_statusQString(rowNum, "Finished"); - } - //========== 移动到输出路径 ========= - if(ui->checkBox_OutPath_isEnabled->isChecked()) - { - MoveFileToOutputPath(OutPutPath_Final,SourceFile_fullPath); - } - //============================ 更新进度条 ================================= - emit Send_progressbar_Add(); - //=========================== 更新线程数量统计============================== - mutex_ThreadNumRunning.lock(); - ThreadNumRunning--; - mutex_ThreadNumRunning.unlock();//线程数量统计-1 - return 0; -} - -/* - - ============================================================================================= - ============================================================================================= - ============================= Waifu2x_NCNN_Vulkan_GIF ======================================= - ============================================================================================= - ============================================================================================= - -*/ - -int MainWindow::Realsr_NCNN_Vulkan_GIF(int rowNum) -{ - //============================= 读取设置 ================================ - int ScaleRatio = ui->doubleSpinBox_ScaleRatio_gif->value(); - bool DelOriginal = (ui->checkBox_DelOriginal->isChecked()||ui->checkBox_ReplaceOriginalFile->isChecked()); - bool OptGIF = ui->checkBox_OptGIF->isChecked(); - QString OutPutPath_Final =""; - //========================= 拆解map得到参数 ============================= - emit Send_Table_gif_ChangeStatus_rowNumInt_statusQString(rowNum, "Processing"); - QString SourceFile_fullPath = Table_model_gif->item(rowNum,2)->text(); - if(!QFile::exists(SourceFile_fullPath)) - { - emit Send_TextBrowser_NewMessage(tr("Error occured when processing [")+SourceFile_fullPath+tr("]. Error: [File does not exist.]")); - emit Send_Table_gif_ChangeStatus_rowNumInt_statusQString(rowNum, "Failed"); - emit Send_progressbar_Add(); - return 0; - } - //========================== - bool CustRes_isEnabled = false; - int CustRes_height=0; - int CustRes_width=0; - if(CustRes_isContained(SourceFile_fullPath)) - { - CustRes_isEnabled=true; - QMap Res_map = CustRes_getResMap(SourceFile_fullPath);//res_map["fullpath"],["height"],["width"] - CustRes_height=Res_map["height"].toInt(); - CustRes_width=Res_map["width"].toInt(); - } - //========================== - QFileInfo fileinfo(SourceFile_fullPath); - QString file_name = file_getBaseName(SourceFile_fullPath); - QString file_ext = fileinfo.suffix(); - QString file_path = file_getFolderPath(fileinfo); - QString ResGIFPath = file_path + "/" + file_name + "_waifu2x_"+QString::number(ScaleRatio, 10)+"x.gif"; - //=========================== 获取帧时间 ==================================== - int GIF_Duration = Gif_getDuration(SourceFile_fullPath); - if(GIF_Duration==0)//检查是否成功获取duration - { - emit Send_TextBrowser_NewMessage(tr("Error occured when processing [")+SourceFile_fullPath+tr("]. Error: [Can't get Duration value of GIF file.]")); - emit Send_Table_gif_ChangeStatus_rowNumInt_statusQString(rowNum, "Failed"); - //file_DelDir(SplitFramesFolderPath); - emit Send_progressbar_Add(); - return 0;//如果启用stop位,则直接return - } - //============================== 拆分 ========================================== - QString SplitFramesFolderPath = file_path+"/"+file_name+"_SplitFrames_W2xEX";//拆分后存储frame的文件夹 - Gif_splitGif(SourceFile_fullPath,SplitFramesFolderPath); - //============================== 扫描获取文件名 =============================== - QStringList Frame_fileName_list = file_getFileNames_in_Folder_nofilter(SplitFramesFolderPath); - if(Frame_fileName_list.isEmpty())//检查是否成功拆分gif - { - emit Send_TextBrowser_NewMessage(tr("Error occured when processing [")+SourceFile_fullPath+tr("]. Error: [Can't split GIF into frames.]")); - emit Send_Table_gif_ChangeStatus_rowNumInt_statusQString(rowNum, "Failed"); - file_DelDir(SplitFramesFolderPath); - emit Send_progressbar_Add(); - return 0;//如果启用stop位,则直接return - } - //===========建立存储放大后frame的文件夹=========== - QString ScaledFramesFolderPath = SplitFramesFolderPath+"/ScaledFrames_W2xEX"; - if(file_isDirExist(ScaledFramesFolderPath)) - { - file_DelDir(ScaledFramesFolderPath); - file_mkDir(ScaledFramesFolderPath); - } - else - { - file_mkDir(ScaledFramesFolderPath); - } - //==========开始放大========================== - //读取放大倍数 - int ScaleRatio_Original = 2; - if(CustRes_isEnabled == true) - { - ScaleRatio_Original = CustRes_CalNewScaleRatio(SourceFile_fullPath,CustRes_height,CustRes_width); - } - else - { - ScaleRatio_Original = ui->doubleSpinBox_ScaleRatio_gif->value(); - } - int ScaleRatio_Max=Calculate_Temporary_ScaleRatio_RealsrNCNNVulkan(ScaleRatio_Original); - bool isOverScaled = (ScaleRatio_Max!=ScaleRatio_Original); - //初始化进度讯息 - int NumOfSplitFrames = Frame_fileName_list.size(); - if(ui->checkBox_ShowInterPro->isChecked()) - { - int NumOfRounds=0; - for(int ScaleRatio_Current_tmp=4; ScaleRatio_Current_tmp<=ScaleRatio_Max; ScaleRatio_Current_tmp*=4) - { - NumOfRounds++; - } - emit Send_CurrentFileProgress_Start(file_name+"."+file_ext,NumOfSplitFrames*NumOfRounds); - } - //读取配置讯息 - QString Realsr_NCNN_Vulkan_Settings_str = Realsr_NCNN_Vulkan_ReadSettings_Video_GIF(ui->spinBox_ThreadNum_gif_internal->value()); - QProcess *Waifu2x = new QProcess(); - QString program = Current_Path+"/realsr-ncnn-vulkan/realsr-ncnn-vulkan_waifu2xEX.exe"; - bool waifu2x_qprocess_failed = false; - int CountFinishedRounds=0; - //==== - for(int ScaleRatio_Current_tmp=4; ScaleRatio_Current_tmp<=ScaleRatio_Max && Frame_fileName_list.isEmpty()==false; ScaleRatio_Current_tmp*=4) - { - for(int retry=0; retry<(ui->spinBox_retry->value()+ForceRetryCount); retry++) - { - QString ErrorMSG=""; - QString StanderMSG=""; - //========== - waifu2x_qprocess_failed = false; - QString cmd = "\"" + program + "\"" + " -i " + "\"" + SplitFramesFolderPath + "\"" + " -o " + "\"" + ScaledFramesFolderPath + "\"" + " -s 4 " + Realsr_NCNN_Vulkan_Settings_str; - Waifu2x->start(cmd); - while(!Waifu2x->waitForStarted(100)&&!QProcess_stop) {} - while(!Waifu2x->waitForFinished(650)&&!QProcess_stop) - { - if(waifu2x_STOP) - { - Waifu2x->close(); - file_DelDir(SplitFramesFolderPath); - emit Send_Table_gif_ChangeStatus_rowNumInt_statusQString(rowNum, "Interrupted"); - mutex_ThreadNumRunning.lock(); - ThreadNumRunning--; - mutex_ThreadNumRunning.unlock(); - return 0; - } - ErrorMSG.append(Waifu2x->readAllStandardError().toLower()); - StanderMSG.append(Waifu2x->readAllStandardOutput().toLower()); - if(ErrorMSG.contains("failed")||StanderMSG.contains("failed")) - { - waifu2x_qprocess_failed = true; - Waifu2x->close(); - break; - } - if(ui->checkBox_ShowInterPro->isChecked()) - { - emit Send_CurrentFileProgress_progressbar_SetFinishedValue((NumOfSplitFrames*CountFinishedRounds)+file_getFileNames_in_Folder_nofilter(ScaledFramesFolderPath).size()); - } - } - //=============== - if(waifu2x_qprocess_failed==false) - { - ErrorMSG.append(Waifu2x->readAllStandardError().toLower()); - StanderMSG.append(Waifu2x->readAllStandardOutput().toLower()); - if(ErrorMSG.contains("failed")||StanderMSG.contains("failed")) - { - waifu2x_qprocess_failed = true; - } - } - //========= 检测是否成功,是否需要重试 ============ - if((NumOfSplitFrames == file_getFileNames_in_Folder_nofilter(ScaledFramesFolderPath).size())&&!waifu2x_qprocess_failed) - { - break; - } - else - { - //失败 - file_DelDir(ScaledFramesFolderPath); - file_mkDir(ScaledFramesFolderPath); - if(retry==ui->spinBox_retry->value()+(ForceRetryCount-1))break; - emit Send_TextBrowser_NewMessage(tr("Automatic retry, please wait.")); - Delay_sec_sleep(5); - } - } - //=========== - //根据轮数修改参数 - if(ScaleRatio_Current_tmpisChecked()) - { - file_MoveToTrash(SourceFile_fullPath); - } - else - { - QFile::remove(SourceFile_fullPath); - } - } - emit Send_Table_gif_ChangeStatus_rowNumInt_statusQString(rowNum, "Finished, original file deleted"); - } - else - { - emit Send_Table_gif_ChangeStatus_rowNumInt_statusQString(rowNum, "Finished"); - } - //========== 移动到输出路径 ========= - if(ui->checkBox_OutPath_isEnabled->isChecked()) - { - MoveFileToOutputPath(OutPutPath_Final,SourceFile_fullPath); - } - //============================ 更新进度条 ================================= - emit Send_progressbar_Add(); - //=========================== ============================== - return 0; -} - - - -/* - - ============================================================================================= - ============================================================================================= - ============================= Waifu2x_NCNN_Vulkan_Video ======================================= - ============================================================================================= - ============================================================================================= - - -*/ - -int MainWindow::Realsr_NCNN_Vulkan_Video(int rowNum) -{ - //============================= 读取设置 ================================ - int ScaleRatio = ui->doubleSpinBox_ScaleRatio_video->value(); - bool DelOriginal = (ui->checkBox_DelOriginal->isChecked()||ui->checkBox_ReplaceOriginalFile->isChecked()); - bool isCacheExists = false; - bool isVideoConfigChanged = true; - //========================= 拆解map得到参数 ============================= - emit Send_Table_video_ChangeStatus_rowNumInt_statusQString(rowNum, "Processing"); - QString SourceFile_fullPath = Table_model_video->item(rowNum,2)->text(); - if(!QFile::exists(SourceFile_fullPath)) - { - emit Send_TextBrowser_NewMessage(tr("Error occured when processing [")+SourceFile_fullPath+tr("]. Error: [File does not exist.]")); - emit Send_Table_video_ChangeStatus_rowNumInt_statusQString(rowNum, "Failed"); - emit Send_progressbar_Add(); - return 0; - } - //========================== - QFileInfo fileinfo(SourceFile_fullPath); - QString file_name = file_getBaseName(SourceFile_fullPath); - QString file_ext = fileinfo.suffix(); - QString file_path = file_getFolderPath(fileinfo); - //=================================================================== - //生成mp4 - QString video_mp4_fullpath=video_To_CFRMp4(SourceFile_fullPath); - if(!QFile::exists(video_mp4_fullpath))//检查是否成功生成mp4 - { - emit Send_TextBrowser_NewMessage(tr("Error occured when processing [")+SourceFile_fullPath+tr("]. Error: [Cannot convert video format to mp4.]")); - emit Send_Table_video_ChangeStatus_rowNumInt_statusQString(rowNum, "Failed"); - emit Send_progressbar_Add(); - return 0;//如果启用stop位,则直接return - } - //============ 读取自定义分辨率设定 ============== - bool CustRes_isEnabled = false; - int CustRes_height=0; - int CustRes_width=0; - if(CustRes_isContained(SourceFile_fullPath)) - { - CustRes_isEnabled=true; - QMap Res_map = CustRes_getResMap(SourceFile_fullPath);//res_map["fullpath"],["height"],["width"] - CustRes_height=Res_map["height"].toInt(); - CustRes_width=Res_map["width"].toInt(); - } - //================= - QString AudioPath = file_path+"/Audio_"+file_name+"_"+file_ext+"_W2xEX.wav";//音频 - QString SplitFramesFolderPath = file_path+"/"+file_name+"_"+file_ext+"_SplitFrames_W2xEX";//拆分后存储frame的文件夹 - QString ScaledFramesFolderPath = SplitFramesFolderPath+"/ScaledFrames_W2xEX";//存储放大后的帧 - //========================== - // 检测之前的视频配置文件 - //========================== - QString VideoConfiguration_fullPath = file_path+"/VideoConfiguration_"+file_name+"_"+file_ext+"_Waifu2xEX.ini"; - if(QFile::exists(VideoConfiguration_fullPath)) - { - QSettings *configIniRead = new QSettings(VideoConfiguration_fullPath, QSettings::IniFormat); - configIniRead->setIniCodec(QTextCodec::codecForName("UTF-8")); - //=================== 加载之前存储的视频信息 ========================= - int ScaleRatio_old = configIniRead->value("/VideoConfiguration/ScaleRatio").toInt(); - bool CustRes_isEnabled_old = configIniRead->value("/VideoConfiguration/CustRes_isEnabled").toBool(); - int CustRes_height_old = configIniRead->value("/VideoConfiguration/CustRes_height").toInt(); - int CustRes_width_old = configIniRead->value("/VideoConfiguration/CustRes_width").toInt(); - QString EngineName_old = configIniRead->value("/VideoConfiguration/EngineName").toString(); - bool isProcessBySegment_old = configIniRead->value("/VideoConfiguration/isProcessBySegment").toBool(); - //=================== 比对信息 ================================ - if(EngineName_old=="realsr-ncnn-vulkan") - { - if(CustRes_isEnabled_old==false&&CustRes_isEnabled==false) - { - if(ScaleRatio_old!=ScaleRatio) - { - isVideoConfigChanged=true; - } - else - { - isVideoConfigChanged=false; - } - } - else - { - if(CustRes_isEnabled_old==true&&CustRes_isEnabled==true) - { - if(CustRes_height_old!=CustRes_height||CustRes_width_old!=CustRes_width) - { - isVideoConfigChanged=true; - } - else - { - isVideoConfigChanged=false; - } - } - else - { - isVideoConfigChanged=true; - } - } - if(isProcessBySegment_old==true) - { - isVideoConfigChanged=true; - } - } - else - { - isVideoConfigChanged=true; - } - } - else - { - emit Send_video_write_VideoConfiguration(VideoConfiguration_fullPath,ScaleRatio,0,CustRes_isEnabled,CustRes_height,CustRes_width,"realsr-ncnn-vulkan",false,"","",ui->groupBox_FrameInterpolation->isChecked(),0); - } - //======================= - // 检测缓存是否存在 - //======================= - if(QFile::exists(video_mp4_fullpath)&&file_isDirExist(SplitFramesFolderPath)&&file_isDirExist(ScaledFramesFolderPath)&&QFile::exists(VideoConfiguration_fullPath)) - { - if(!isVideoConfigChanged) - { - isCacheExists=true; - emit Send_TextBrowser_NewMessage(tr("The previous video cache file is detected and processing of the previous video cache will continue. If you want to restart processing of the current video:[")+SourceFile_fullPath+tr("], delete the cache manually.")); - } - else - { - isCacheExists=false; - //======== - QFile::remove(VideoConfiguration_fullPath); - file_DelDir(SplitFramesFolderPath); - QFile::remove(AudioPath); - DelVfiDir(video_mp4_fullpath); - emit Send_video_write_VideoConfiguration(VideoConfiguration_fullPath,ScaleRatio,0,CustRes_isEnabled,CustRes_height,CustRes_width,"realsr-ncnn-vulkan",false,"","",ui->groupBox_FrameInterpolation->isChecked(),0); - //======= - emit Send_TextBrowser_NewMessage(tr("The previous video cache file was detected, but because you changed the settings about the video resolution, the previous cache will be deleted and processing of the video:[")+SourceFile_fullPath+tr("] will restart.")); - } - } - else - { - isCacheExists=false; - //======== - QFile::remove(VideoConfiguration_fullPath); - file_DelDir(SplitFramesFolderPath); - QFile::remove(AudioPath); - DelVfiDir(video_mp4_fullpath); - emit Send_video_write_VideoConfiguration(VideoConfiguration_fullPath,ScaleRatio,0,CustRes_isEnabled,CustRes_height,CustRes_width,"realsr-ncnn-vulkan",false,"","",ui->groupBox_FrameInterpolation->isChecked(),0); - //======== - } - if(!isCacheExists) - { - //============================== 拆分 ========================================== - if(file_isDirExist(SplitFramesFolderPath)) - { - file_DelDir(SplitFramesFolderPath); - file_mkDir(SplitFramesFolderPath); - } - else - { - file_mkDir(SplitFramesFolderPath); - } - QFile::remove(AudioPath); - video_video2images(video_mp4_fullpath,SplitFramesFolderPath,AudioPath); - if(waifu2x_STOP) - { - emit Send_Table_video_ChangeStatus_rowNumInt_statusQString(rowNum, "Interrupted"); - return 0;//如果启用stop位,则直接return - } - } - //============================== 扫描获取文件名 =============================== - QStringList Frame_fileName_list = file_getFileNames_in_Folder_nofilter(SplitFramesFolderPath); - if(!isCacheExists) - { - if(Frame_fileName_list.isEmpty())//检查是否成功拆分为帧 - { - emit Send_TextBrowser_NewMessage(tr("Error occured when processing [")+SourceFile_fullPath+tr("]. Error: [Unable to split video into pictures.]")); - emit Send_Table_video_ChangeStatus_rowNumInt_statusQString(rowNum, "Failed"); - emit Send_progressbar_Add(); - return 0;//如果启用stop位,则直接return - } - } - //============================== 放大 ======================================= - //===========建立存储放大后frame的文件夹=========== - if(!isCacheExists) - { - if(file_isDirExist(ScaledFramesFolderPath)) - { - file_DelDir(ScaledFramesFolderPath); - file_mkDir(ScaledFramesFolderPath); - } - else - { - file_mkDir(ScaledFramesFolderPath); - } - } - //==========开始放大========================== - //读取放大倍数 - int ScaleRatio_Original = 2; - if(CustRes_isEnabled == true) - { - ScaleRatio_Original = CustRes_CalNewScaleRatio(video_mp4_fullpath,CustRes_height,CustRes_width); - } - else - { - ScaleRatio_Original = ui->doubleSpinBox_ScaleRatio_video->value(); - } - int ScaleRatio_Max=Calculate_Temporary_ScaleRatio_RealsrNCNNVulkan(ScaleRatio_Original); - bool isOverScaled = (ScaleRatio_Max!=ScaleRatio_Original); - //读取初始放大倍率 - int Initial_ScaleRatio = 4; - if(!Frame_fileName_list.isEmpty()) - { - QString Full_Path_File = ""; - for(int i = 0; i < Frame_fileName_list.size(); i++) - { - QString tmp = Frame_fileName_list.at(i); - Full_Path_File = SplitFramesFolderPath + "/" + tmp; - QFileInfo finfo(Full_Path_File); - if(finfo.suffix()=="png")break; - } - QImage qimage_original; - qimage_original.load(Full_Path_File); - int Frame_height = qimage_original.height(); - QMap res_map = video_get_Resolution(SourceFile_fullPath); - int Video_height = res_map["height"]; - if(Frame_height>0 && Video_height>0 && Frame_height>=Video_height)//判断是否读取失败 - { - Initial_ScaleRatio = 4*(Frame_height/Video_height); - } - } - //初始化进度讯息 - int NumOfSplitFrames = Frame_fileName_list.size()+file_getFileNames_in_Folder_nofilter(ScaledFramesFolderPath).size(); - if(ui->checkBox_ShowInterPro->isChecked()) - { - int NumOfRounds=0; - for(int ScaleRatio_Current_tmp=Initial_ScaleRatio; ScaleRatio_Current_tmp<=ScaleRatio_Max; ScaleRatio_Current_tmp*=4) - { - NumOfRounds++; - } - emit Send_CurrentFileProgress_Start(file_name+"."+file_ext,NumOfSplitFrames*NumOfRounds); - } - //读取配置讯息 - QString Realsr_NCNN_Vulkan_Settings_str = Realsr_NCNN_Vulkan_ReadSettings_Video_GIF(ui->spinBox_ThreadNum_video_internal->value()); - QProcess *Waifu2x = new QProcess(); - QString program = Current_Path+"/realsr-ncnn-vulkan/realsr-ncnn-vulkan_waifu2xEX.exe"; - bool waifu2x_qprocess_failed = false; - int CountFinishedRounds=0; - //==== - for(int ScaleRatio_Current_tmp=Initial_ScaleRatio; ScaleRatio_Current_tmp<=ScaleRatio_Max && Frame_fileName_list.isEmpty()==false; ScaleRatio_Current_tmp*=4) - { - for(int retry=0; retry<(ui->spinBox_retry->value()+ForceRetryCount); retry++) - { - QString ErrorMSG=""; - QString StanderMSG=""; - //========== - waifu2x_qprocess_failed = false; - QString cmd = "\"" + program + "\"" + " -i " + "\"" + SplitFramesFolderPath + "\"" + " -o " + "\"" + ScaledFramesFolderPath + "\"" + " -s 4 " + Realsr_NCNN_Vulkan_Settings_str; - Waifu2x->start(cmd); - while(!Waifu2x->waitForStarted(100)&&!QProcess_stop) {} - while(!Waifu2x->waitForFinished(650)&&!QProcess_stop) - { - if(waifu2x_STOP) - { - QStringList FinfishedFileList_FileNames = WaitForEngineIO_NcnnVulkan(ScaledFramesFolderPath); - Waifu2x->close(); - //============ - QString file_name_tmp; - QStringList FileNames_ScaledFramesFolderPath = file_getFileNames_in_Folder_nofilter(ScaledFramesFolderPath); - for(int i=0; ireadAllStandardError().toLower()); - StanderMSG.append(Waifu2x->readAllStandardOutput().toLower()); - if(ErrorMSG.contains("failed")||StanderMSG.contains("failed")) - { - waifu2x_qprocess_failed = true; - Waifu2x->close(); - break; - } - if(ui->checkBox_ShowInterPro->isChecked()) - { - emit Send_CurrentFileProgress_progressbar_SetFinishedValue((NumOfSplitFrames*CountFinishedRounds)+file_getFileNames_in_Folder_nofilter(ScaledFramesFolderPath).size()); - } - } - //=============== - if(waifu2x_qprocess_failed==false) - { - ErrorMSG.append(Waifu2x->readAllStandardError().toLower()); - StanderMSG.append(Waifu2x->readAllStandardOutput().toLower()); - if(ErrorMSG.contains("failed")||StanderMSG.contains("failed")) - { - waifu2x_qprocess_failed = true; - } - } - //========= 检测是否成功,是否需要重试 ============ - if((NumOfSplitFrames == file_getFileNames_in_Folder_nofilter(ScaledFramesFolderPath).size())&&!waifu2x_qprocess_failed) - { - break; - } - else - { - //失败 - file_DelDir(ScaledFramesFolderPath); - file_mkDir(ScaledFramesFolderPath); - if(retry==ui->spinBox_retry->value()+(ForceRetryCount-1))break; - emit Send_TextBrowser_NewMessage(tr("Automatic retry, please wait.")); - Delay_sec_sleep(5); - } - } - //=========== - //根据轮数修改参数 - if(ScaleRatio_Current_tmpcheckBox_KeepVideoCache->isChecked()==false) - { - QFile::remove(VideoConfiguration_fullPath); - file_DelDir(SplitFramesFolderPath); - QFile::remove(AudioPath); - if(SourceFile_fullPath!=video_mp4_fullpath)QFile::remove(video_mp4_fullpath); - } - else - { - DelOriginal=false; - } - //============================= 删除原文件 & & 更新table status ============================ - if(DelOriginal) - { - if(ReplaceOriginalFile(SourceFile_fullPath,video_mp4_scaled_fullpath)==false) - { - if(QAction_checkBox_MoveToRecycleBin_checkBox_DelOriginal->isChecked()) - { - file_MoveToTrash(SourceFile_fullPath); - } - else - { - QFile::remove(SourceFile_fullPath); - } - } - emit Send_Table_video_ChangeStatus_rowNumInt_statusQString(rowNum, "Finished, original file deleted"); - } - else - { - emit Send_Table_video_ChangeStatus_rowNumInt_statusQString(rowNum, "Finished"); - } - //========== 移动到输出路径 ========= - if(ui->checkBox_OutPath_isEnabled->isChecked()) - { - MoveFileToOutputPath(video_mp4_scaled_fullpath,SourceFile_fullPath); - } - //============================ 更新进度条 ================================= - emit Send_progressbar_Add(); - //=========================== ============================== - return 0; -} -/* -#### 分段处理 #### -调用realser-ncnn-vulkan处理视频 -读取设置,拆分,创建放大子线程,组装视频 -*/ -int MainWindow::Realsr_NCNN_Vulkan_Video_BySegment(int rowNum) -{ - //============================= 读取设置 ================================ - int ScaleRatio = ui->doubleSpinBox_ScaleRatio_video->value(); - bool DelOriginal = (ui->checkBox_DelOriginal->isChecked()||ui->checkBox_ReplaceOriginalFile->isChecked()); - bool isCacheExists = false; - bool isVideoConfigChanged = true; - int SegmentDuration = ui->spinBox_SegmentDuration->value(); - //========================= 拆解map得到参数 ============================= - emit Send_Table_video_ChangeStatus_rowNumInt_statusQString(rowNum, "Processing"); - QString SourceFile_fullPath = Table_model_video->item(rowNum,2)->text(); - if(!QFile::exists(SourceFile_fullPath)) - { - emit Send_TextBrowser_NewMessage(tr("Error occured when processing [")+SourceFile_fullPath+tr("]. Error: [File does not exist.]")); - emit Send_Table_video_ChangeStatus_rowNumInt_statusQString(rowNum, "Failed"); - emit Send_progressbar_Add(); - return 0; - } - //========================== - QFileInfo fileinfo(SourceFile_fullPath); - QString file_name = file_getBaseName(SourceFile_fullPath); - QString file_ext = fileinfo.suffix(); - QString file_path = file_getFolderPath(fileinfo); - //=================================================================== - //生成mp4 - QString video_mp4_fullpath=video_To_CFRMp4(SourceFile_fullPath); - if(!QFile::exists(video_mp4_fullpath))//检查是否成功生成mp4 - { - emit Send_TextBrowser_NewMessage(tr("Error occured when processing [")+SourceFile_fullPath+tr("]. Error: [Cannot convert video format to mp4.]")); - emit Send_Table_video_ChangeStatus_rowNumInt_statusQString(rowNum, "Failed"); - emit Send_progressbar_Add(); - return 0;//如果启用stop位,则直接return - } - //============ 读取自定义分辨率设定 ============== - bool CustRes_isEnabled = false; - int CustRes_height=0; - int CustRes_width=0; - if(CustRes_isContained(SourceFile_fullPath)) - { - CustRes_isEnabled=true; - QMap Res_map = CustRes_getResMap(SourceFile_fullPath);//res_map["fullpath"],["height"],["width"] - CustRes_height=Res_map["height"].toInt(); - CustRes_width=Res_map["width"].toInt(); - } - //================= - QString AudioPath = file_path+"/Audio_"+file_name+"_"+file_ext+"_W2xEX.wav";//音频 - QString SplitFramesFolderPath = file_path+"/"+file_name+"_"+file_ext+"_SplitFrames_W2xEX";//拆分后存储frame的文件夹 - QString ScaledFramesFolderPath = SplitFramesFolderPath+"/ScaledFrames_W2xEX";//存储放大后的帧 - //=== - QString VideoClipsFolderPath = "";//存储视频片段的文件夹(完整路径) - QString DateStr = ""; - do - { - DateStr = video_getClipsFolderNo(); - VideoClipsFolderPath = file_path+"/"+DateStr+"_VideoClipsWaifu2xEX";//存储视频片段的文件夹(完整路径) - } - while(file_isDirExist(VideoClipsFolderPath)); - QString VideoClipsFolderName = DateStr+"_VideoClipsWaifu2xEX";//存储视频片段的文件夹(名称) - //========================== - // 检测之前的视频配置文件 - //========================== - QString VideoConfiguration_fullPath = file_path+"/VideoConfiguration_"+file_name+"_"+file_ext+"_Waifu2xEX.ini"; - if(QFile::exists(VideoConfiguration_fullPath)) - { - QSettings *configIniRead = new QSettings(VideoConfiguration_fullPath, QSettings::IniFormat); - configIniRead->setIniCodec(QTextCodec::codecForName("UTF-8")); - //=================== 加载之前存储的视频信息 ========================= - int ScaleRatio_old = configIniRead->value("/VideoConfiguration/ScaleRatio").toInt(); - bool CustRes_isEnabled_old = configIniRead->value("/VideoConfiguration/CustRes_isEnabled").toBool(); - int CustRes_height_old = configIniRead->value("/VideoConfiguration/CustRes_height").toInt(); - int CustRes_width_old = configIniRead->value("/VideoConfiguration/CustRes_width").toInt(); - QString EngineName_old = configIniRead->value("/VideoConfiguration/EngineName").toString(); - bool isProcessBySegment_old = configIniRead->value("/VideoConfiguration/isProcessBySegment").toBool(); - bool isVideoFrameInterpolationEnabled_old = configIniRead->value("/VideoConfiguration/isVideoFrameInterpolationEnabled").toBool(); - int MultipleOfFPS_old = configIniRead->value("/VideoConfiguration/MultipleOfFPS").toInt(); - //=================== 比对信息 ================================ - if(EngineName_old=="realsr-ncnn-vulkan") - { - if(CustRes_isEnabled_old==false&&CustRes_isEnabled==false) - { - if(ScaleRatio_old!=ScaleRatio) - { - isVideoConfigChanged=true; - } - else - { - isVideoConfigChanged=false; - } - } - else - { - if(CustRes_isEnabled_old==true&&CustRes_isEnabled==true) - { - if(CustRes_height_old!=CustRes_height||CustRes_width_old!=CustRes_width) - { - isVideoConfigChanged=true; - } - else - { - isVideoConfigChanged=false; - } - } - else - { - isVideoConfigChanged=true; - } - } - if(isProcessBySegment_old == false) - { - isVideoConfigChanged=true; - } - if(isVideoFrameInterpolationEnabled_old != ui->groupBox_FrameInterpolation->isChecked()) - { - isVideoConfigChanged=true; - } - if(MultipleOfFPS_old != ui->spinBox_MultipleOfFPS_VFI->value() && ui->groupBox_FrameInterpolation->isChecked()) - { - isVideoConfigChanged=true; - } - } - else - { - isVideoConfigChanged=true; - } - //============ 修正文件夹名称 ============= - QString VideoClipsFolderPath_old = configIniRead->value("/VideoConfiguration/VideoClipsFolderPath").toString(); - QString VideoClipsFolderName_old = configIniRead->value("/VideoConfiguration/VideoClipsFolderName").toString(); - file_mkDir(VideoClipsFolderPath_old); - if(file_isDirExist(VideoClipsFolderPath_old)==true) - { - VideoClipsFolderPath = VideoClipsFolderPath_old; - VideoClipsFolderName = VideoClipsFolderName_old; - } - } - else - { - emit Send_video_write_VideoConfiguration(VideoConfiguration_fullPath,ScaleRatio,0,CustRes_isEnabled,CustRes_height,CustRes_width,"realsr-ncnn-vulkan",true,VideoClipsFolderPath,VideoClipsFolderName,ui->groupBox_FrameInterpolation->isChecked(),ui->spinBox_MultipleOfFPS_VFI->value()); - } - //======================= - // 检测缓存是否存在 - //======================= - if(file_isDirExist(SplitFramesFolderPath)) - { - if(!isVideoConfigChanged) - { - isCacheExists=true; - emit Send_TextBrowser_NewMessage(tr("The previous video cache file is detected and processing of the previous video cache will continue. If you want to restart processing of the current video:[")+SourceFile_fullPath+tr("], delete the cache manually.")); - } - else - { - isCacheExists=false; - //======== - QFile::remove(VideoConfiguration_fullPath); - file_DelDir(SplitFramesFolderPath); - file_DelDir(VideoClipsFolderPath); - QFile::remove(AudioPath); - DelVfiDir(video_mp4_fullpath); - emit Send_video_write_VideoConfiguration(VideoConfiguration_fullPath,ScaleRatio,0,CustRes_isEnabled,CustRes_height,CustRes_width,"realsr-ncnn-vulkan",true,VideoClipsFolderPath,VideoClipsFolderName,ui->groupBox_FrameInterpolation->isChecked(),ui->spinBox_MultipleOfFPS_VFI->value()); - //======= - emit Send_TextBrowser_NewMessage(tr("The previous video cache file was detected, but because you changed the settings about the video resolution, the previous cache will be deleted and processing of the video:[")+SourceFile_fullPath+tr("] will restart.")); - } - } - else - { - isCacheExists=false; - //======== - QFile::remove(VideoConfiguration_fullPath); - file_DelDir(SplitFramesFolderPath); - file_DelDir(VideoClipsFolderPath); - QFile::remove(AudioPath); - DelVfiDir(video_mp4_fullpath); - emit Send_video_write_VideoConfiguration(VideoConfiguration_fullPath,ScaleRatio,0,CustRes_isEnabled,CustRes_height,CustRes_width,"realsr-ncnn-vulkan",true,VideoClipsFolderPath,VideoClipsFolderName,ui->groupBox_FrameInterpolation->isChecked(),ui->spinBox_MultipleOfFPS_VFI->value()); - //======== - } - /*==================================== - 提取音频 - ======================================*/ - if(!QFile::exists(AudioPath)) - { - video_get_audio(video_mp4_fullpath,AudioPath); - } - //================================== 开始分段处理视频 ================================================= - int StartTime = 0;//起始时间(秒) - int VideoDuration = video_get_duration(video_mp4_fullpath); - bool isSplitComplete = false; - bool isScaleComplete = false; - /* - ============================================ - 开始之前先读取进度 - ============================================ - */ - int OLD_SegmentDuration=-1; - bool read_OLD_SegmentDuration =false; - int LastVideoClipNo = -1; - if(QFile::exists(VideoConfiguration_fullPath)) - { - QSettings *configIniRead = new QSettings(VideoConfiguration_fullPath, QSettings::IniFormat); - configIniRead->setIniCodec(QTextCodec::codecForName("UTF-8")); - //=================== 加载进度 ========================= - StartTime = configIniRead->value("/Progress/StartTime").toInt(); - isSplitComplete = configIniRead->value("/Progress/isSplitComplete").toBool(); - isScaleComplete = configIniRead->value("/Progress/isScaleComplete").toBool(); - OLD_SegmentDuration = configIniRead->value("/Progress/OLDSegmentDuration").toInt(); - LastVideoClipNo = configIniRead->value("/Progress/LastVideoClipNo").toInt(); - } - if(OLD_SegmentDuration>0) - { - read_OLD_SegmentDuration = true; - } - /* - 加载进度条 - */ - int SegmentDuration_tmp_progressbar = 0; - if(read_OLD_SegmentDuration) - { - SegmentDuration_tmp_progressbar = OLD_SegmentDuration; - } - else - { - SegmentDuration_tmp_progressbar = SegmentDuration; - } - if(ui->checkBox_ShowInterPro->isChecked()&&VideoDuration>SegmentDuration_tmp_progressbar) - { - emit Send_CurrentFileProgress_Start(file_name+"."+file_ext,VideoDuration); - if(StartTime>0) - { - emit Send_CurrentFileProgress_progressbar_Add_SegmentDuration(StartTime); - } - } - /* - ============================================ - 正式开始处理 - ============================================ - */ - int SegmentDuration_tmp=0; - int TimeLeft_tmp=0; - while(VideoDuration>StartTime) - { - /*========================== - 计算视频片段时间 - ==========================*/ - TimeLeft_tmp = VideoDuration-StartTime; - if((TimeLeft_tmp)>=SegmentDuration) - { - SegmentDuration_tmp = SegmentDuration; - } - else - { - SegmentDuration_tmp = TimeLeft_tmp; - } - if(read_OLD_SegmentDuration) - { - SegmentDuration_tmp = OLD_SegmentDuration; - read_OLD_SegmentDuration=false; - } - /*========================== - 拆分视频片段 - ==========================*/ - if(isSplitComplete==false) - { - if(file_isDirExist(SplitFramesFolderPath)) - { - file_DelDir(SplitFramesFolderPath); - file_mkDir(SplitFramesFolderPath); - } - else - { - file_mkDir(SplitFramesFolderPath); - } - video_video2images_ProcessBySegment(video_mp4_fullpath,SplitFramesFolderPath,StartTime,SegmentDuration_tmp); - if(waifu2x_STOP) - { - emit Send_Table_video_ChangeStatus_rowNumInt_statusQString(rowNum, "Interrupted"); - return 0;//如果启用stop位,则直接return - } - } - /*========================== - 处理视频片段的帧 - ==========================*/ - bool isOverScaled=false; - if(isScaleComplete==false) - { - //============================== 扫描获取文件名 =============================== - QStringList Frame_fileName_list = file_getFileNames_in_Folder_nofilter(SplitFramesFolderPath); - if(isSplitComplete==false) - { - if(Frame_fileName_list.isEmpty())//检查是否成功拆分为帧 - { - emit Send_TextBrowser_NewMessage(tr("Error occured when processing [")+SourceFile_fullPath+tr("]. Error: [Unable to split video into pictures.]")); - emit Send_Table_video_ChangeStatus_rowNumInt_statusQString(rowNum, "Failed"); - emit Send_progressbar_Add(); - return 0;//如果启用stop位,则直接return - } - } - /* - 记录进度 - 帧拆分成功 - */ - emit Send_video_write_Progress_ProcessBySegment(VideoConfiguration_fullPath,StartTime,true,false,SegmentDuration_tmp,LastVideoClipNo); - //============================== 放大 ======================================= - //===========建立存储放大后frame的文件夹=========== - if(isSplitComplete==false) - { - if(file_isDirExist(ScaledFramesFolderPath)) - { - file_DelDir(ScaledFramesFolderPath); - file_mkDir(ScaledFramesFolderPath); - } - else - { - file_mkDir(ScaledFramesFolderPath); - } - } - //==========开始放大========================== - //读取放大倍数 - int ScaleRatio_Original = 2; - if(CustRes_isEnabled == true) - { - ScaleRatio_Original = CustRes_CalNewScaleRatio(video_mp4_fullpath,CustRes_height,CustRes_width); - } - else - { - ScaleRatio_Original = ui->doubleSpinBox_ScaleRatio_video->value(); - } - int ScaleRatio_Max=Calculate_Temporary_ScaleRatio_RealsrNCNNVulkan(ScaleRatio_Original); - isOverScaled = (ScaleRatio_Max!=ScaleRatio_Original); - //读取初始放大倍率 - int Initial_ScaleRatio = 4; - if(!Frame_fileName_list.isEmpty()) - { - QString Full_Path_File = ""; - for(int i = 0; i < Frame_fileName_list.size(); i++) - { - QString tmp = Frame_fileName_list.at(i); - Full_Path_File = SplitFramesFolderPath + "/" + tmp; - QFileInfo finfo(Full_Path_File); - if(finfo.suffix()=="png")break; - } - QImage qimage_original; - qimage_original.load(Full_Path_File); - int Frame_height = qimage_original.height(); - QMap res_map = video_get_Resolution(SourceFile_fullPath); - int Video_height = res_map["height"]; - if(Frame_height>0 && Video_height>0 && Frame_height>=Video_height)//判断是否读取失败 - { - Initial_ScaleRatio = 4*(Frame_height/Video_height); - } - } - //初始化进度讯息 - int NumOfSplitFrames = Frame_fileName_list.size()+file_getFileNames_in_Folder_nofilter(ScaledFramesFolderPath).size(); - int CurrentFileProgress_MAX = 0; - int CurrentFileProgress_OLD = 0; - int CurrentFileProgress_New = 0; - if(ui->checkBox_ShowInterPro->isChecked()) - { - int NumOfRounds=0; - for(int ScaleRatio_Current_tmp=Initial_ScaleRatio; ScaleRatio_Current_tmp<=ScaleRatio_Max; ScaleRatio_Current_tmp*=4) - { - NumOfRounds++; - } - CurrentFileProgress_MAX =NumOfSplitFrames*NumOfRounds; - } - //读取配置讯息 - QString Realsr_NCNN_Vulkan_Settings_str = Realsr_NCNN_Vulkan_ReadSettings_Video_GIF(ui->spinBox_ThreadNum_video_internal->value()); - QProcess *Waifu2x = new QProcess(); - QString program = Current_Path+"/realsr-ncnn-vulkan/realsr-ncnn-vulkan_waifu2xEX.exe"; - bool waifu2x_qprocess_failed = false; - int CountFinishedRounds=0; - //==== - for(int ScaleRatio_Current_tmp=Initial_ScaleRatio; ScaleRatio_Current_tmp<=ScaleRatio_Max && Frame_fileName_list.isEmpty()==false; ScaleRatio_Current_tmp*=4) - { - for(int retry=0; retry<(ui->spinBox_retry->value()+ForceRetryCount); retry++) - { - QString ErrorMSG=""; - QString StanderMSG=""; - //========== - waifu2x_qprocess_failed = false; - QString cmd = "\"" + program + "\"" + " -i " + "\"" + SplitFramesFolderPath + "\"" + " -o " + "\"" + ScaledFramesFolderPath + "\"" + " -s 4 " + Realsr_NCNN_Vulkan_Settings_str; - Waifu2x->start(cmd); - while(!Waifu2x->waitForStarted(100)&&!QProcess_stop) {} - while(!Waifu2x->waitForFinished(650)&&!QProcess_stop) - { - if(waifu2x_STOP) - { - QStringList FinfishedFileList_FileNames = WaitForEngineIO_NcnnVulkan(ScaledFramesFolderPath); - Waifu2x->close(); - //============ - QString file_name_tmp; - QStringList FileNames_ScaledFramesFolderPath = file_getFileNames_in_Folder_nofilter(ScaledFramesFolderPath); - for(int i=0; ireadAllStandardError().toLower()); - StanderMSG.append(Waifu2x->readAllStandardOutput().toLower()); - if(ErrorMSG.contains("failed")||StanderMSG.contains("failed")) - { - waifu2x_qprocess_failed = true; - Waifu2x->close(); - break; - } - if(ui->checkBox_ShowInterPro->isChecked()) - { - CurrentFileProgress_New = (NumOfSplitFrames*CountFinishedRounds)+file_getFileNames_in_Folder_nofilter(ScaledFramesFolderPath).size(); - if(CurrentFileProgress_New!=CurrentFileProgress_OLD) - { - emit Send_TextBrowser_NewMessage(tr("File name:[")+SourceFile_fullPath+tr("] Scale progress:[")+QString::number(CurrentFileProgress_New,10)+"/"+QString::number(CurrentFileProgress_MAX,10)+tr("] Duration progress:[")+QString::number(StartTime,10)+"s/"+QString::number(VideoDuration,10)+"s]"); - CurrentFileProgress_OLD=CurrentFileProgress_New; - } - } - } - //=============== - if(waifu2x_qprocess_failed==false) - { - ErrorMSG.append(Waifu2x->readAllStandardError().toLower()); - StanderMSG.append(Waifu2x->readAllStandardOutput().toLower()); - if(ErrorMSG.contains("failed")||StanderMSG.contains("failed")) - { - waifu2x_qprocess_failed = true; - } - } - //========= 检测是否成功,是否需要重试 ============ - if((NumOfSplitFrames == file_getFileNames_in_Folder_nofilter(ScaledFramesFolderPath).size())&&!waifu2x_qprocess_failed) - { - break; - } - else - { - //失败 - file_DelDir(ScaledFramesFolderPath); - file_mkDir(ScaledFramesFolderPath); - if(retry==ui->spinBox_retry->value()+(ForceRetryCount-1))break; - emit Send_TextBrowser_NewMessage(tr("Automatic retry, please wait.")); - Delay_sec_sleep(5); - } - } - //=========== - //根据轮数修改参数 - if(ScaleRatio_Current_tmpcheckBox_ShowInterPro->isChecked()) - { - emit Send_CurrentFileProgress_progressbar_Add_SegmentDuration(SegmentDuration_tmp); - } - StartTime+=SegmentDuration_tmp; - isSplitComplete = false; - isScaleComplete = false; - LastVideoClipNo=VideoClipNo; - emit Send_video_write_Progress_ProcessBySegment(VideoConfiguration_fullPath,StartTime,false,false,-1,VideoClipNo); - } - emit Send_CurrentFileProgress_Stop(); - //====================================================== - // 组装(片段到成片) - //====================================================== - QString video_mp4_scaled_fullpath = ""; - if(CustRes_isEnabled) - { - video_mp4_scaled_fullpath = file_path+"/"+file_name+"_waifu2x_"+QString::number(CustRes_width,10)+"x"+QString::number(CustRes_height,10)+"_"+file_ext+".mp4"; - } - else - { - video_mp4_scaled_fullpath = file_path+"/"+file_name+"_waifu2x_"+QString::number(ScaleRatio,10)+"x_"+file_ext+".mp4"; - } - QFile::remove(video_mp4_scaled_fullpath); - video_AssembleVideoClips(VideoClipsFolderPath,VideoClipsFolderName,video_mp4_scaled_fullpath,AudioPath); - if(QFile::exists(video_mp4_scaled_fullpath)==false)//检查是否成功生成视频 - { - if(waifu2x_STOP) - { - emit Send_Table_video_ChangeStatus_rowNumInt_statusQString(rowNum, "Interrupted"); - return 0;//如果启用stop位,则直接return - } - emit Send_TextBrowser_NewMessage(tr("Error occured when processing [")+SourceFile_fullPath+tr("]. Error: [Unable to assemble video clips.]")); - emit Send_Table_video_ChangeStatus_rowNumInt_statusQString(rowNum, "Failed"); - emit Send_progressbar_Add(); - return 0;//如果启用stop位,则直接return - } - //============================== 删除缓存文件 ==================================================== - if(ui->checkBox_KeepVideoCache->isChecked()==false) - { - QFile::remove(VideoConfiguration_fullPath); - file_DelDir(SplitFramesFolderPath); - file_DelDir(VideoClipsFolderPath); - QFile::remove(AudioPath); - if(SourceFile_fullPath!=video_mp4_fullpath)QFile::remove(video_mp4_fullpath); - } - else - { - DelOriginal=false; - } - //============================= 删除原文件 & & 更新table status ============================ - if(DelOriginal) - { - if(ReplaceOriginalFile(SourceFile_fullPath,video_mp4_scaled_fullpath)==false) - { - if(QAction_checkBox_MoveToRecycleBin_checkBox_DelOriginal->isChecked()) - { - file_MoveToTrash(SourceFile_fullPath); - } - else - { - QFile::remove(SourceFile_fullPath); - } - } - emit Send_Table_video_ChangeStatus_rowNumInt_statusQString(rowNum, "Finished, original file deleted"); - } - else - { - emit Send_Table_video_ChangeStatus_rowNumInt_statusQString(rowNum, "Finished"); - } - //========== 移动到输出路径 ========= - if(ui->checkBox_OutPath_isEnabled->isChecked()) - { - MoveFileToOutputPath(video_mp4_scaled_fullpath,SourceFile_fullPath); - } - //============================ 更新进度条 ================================= - emit Send_progressbar_Add(); - //=========================== ============================== - return 0; -} - - -/* -Realsr_NCNN_Vulkan -预读取引擎配置 -*/ -QString MainWindow::Realsr_NCNN_Vulkan_PreLoad_Settings() -{ - QString Realsr_NCNN_Vulkan_Settings_str = " "; - if(ui->checkBox_MultiGPU_RealsrNcnnVulkan->isChecked()==false) - { - //==========单显卡========== - //GPU ID - if(ui->comboBox_GPUID_RealsrNCNNVulkan->currentText()!="auto") - { - Realsr_NCNN_Vulkan_Settings_str.append("-g "+ui->comboBox_GPUID_RealsrNCNNVulkan->currentText()+" "); - } - //Tile Size - Realsr_NCNN_Vulkan_Settings_str.append("-t "+QString::number(ui->spinBox_TileSize_RealsrNCNNVulkan->value(),10)+" "); - } - //TTA - if(ui->checkBox_TTA_RealsrNCNNVulkan->isChecked()) - { - Realsr_NCNN_Vulkan_Settings_str.append("-x "); - } - //Model - QString Waifu2x_folder_path = Current_Path+"/realsr-ncnn-vulkan"; - switch(ui->comboBox_Model_RealsrNCNNVulkan->currentIndex()) - { - case 0: - { - Realsr_NCNN_Vulkan_Settings_str.append("-m \""+Waifu2x_folder_path+"/models-DF2K_JPEG\" "); - break; - } - case 1: - { - Realsr_NCNN_Vulkan_Settings_str.append("-m \""+Waifu2x_folder_path+"/models-DF2K\" "); - break; - } - } - Realsr_NCNN_Vulkan_Settings_str.append("-j 1:1:1 "); - //======================================= - return Realsr_NCNN_Vulkan_Settings_str; -} -/* -Realsr_NCNN_Vulkan -读取配置生成配置QString -*/ -QString MainWindow::Realsr_NCNN_Vulkan_ReadSettings() -{ - QString Realsr_NCNN_Vulkan_Settings_str = ""; - Realsr_NCNN_Vulkan_Settings_str.append(Realsr_NCNN_Vulkan_PreLoad_Settings_Str); - if(ui->checkBox_MultiGPU_RealsrNcnnVulkan->isChecked()) - { - //==========多显卡========== - QMap GPUInfo = RealsrNcnnVulkan_MultiGPU(); - //GPU ID - Realsr_NCNN_Vulkan_Settings_str.append("-g "+GPUInfo["ID"]+" "); - //Tile Size - Realsr_NCNN_Vulkan_Settings_str.append("-t "+GPUInfo["TileSize"]+" "); - } - //======================================= - return Realsr_NCNN_Vulkan_Settings_str; -} - -/* -================================================================================ - Realsr NCNN Vulkan 检测可用GPU -================================================================================= -*/ -/* -点击检测gpu按键时: -*/ -void MainWindow::on_pushButton_DetectGPU_RealsrNCNNVulkan_clicked() -{ - //==== - ui->pushButton_DetectGPU_RealsrNCNNVulkan->setText(tr("Detecting, please wait...")); - //==== - pushButton_Start_setEnabled_self(0); - ui->pushButton_DetectGPU->setEnabled(0); - ui->pushButton_DetectGPUID_srmd->setEnabled(0); - ui->pushButton_DumpProcessorList_converter->setEnabled(0); - ui->pushButton_ListGPUs_Anime4k->setEnabled(0); - ui->pushButton_compatibilityTest->setEnabled(0); - ui->pushButton_DetectGPU_RealsrNCNNVulkan->setEnabled(0); - Available_GPUID_Realsr_ncnn_vulkan.clear(); - QtConcurrent::run(this, &MainWindow::Realsr_ncnn_vulkan_DetectGPU); -} -/* -检测可用GPU ID中: -*/ -int MainWindow::Realsr_ncnn_vulkan_DetectGPU() -{ - emit Send_TextBrowser_NewMessage(tr("Detecting available GPU, please wait.")); - //=============== - QString InputPath = Current_Path + "/Compatibility_Test/Compatibility_Test.jpg"; - QString OutputPath = Current_Path + "/Compatibility_Test/res.png"; - QFile::remove(OutputPath); - //============== - QString Waifu2x_folder_path = Current_Path + "/realsr-ncnn-vulkan"; - QString program = Waifu2x_folder_path + "/realsr-ncnn-vulkan_waifu2xEX.exe"; - QString model_path = Waifu2x_folder_path+"/models-DF2K_JPEG"; - //=========== - int GPU_ID=-1; - //========= - while(true) - { - QFile::remove(OutputPath); - QProcess *Waifu2x = new QProcess(); - QString gpu_str = " -g "+QString::number(GPU_ID,10)+" "; - QString cmd = "\"" + program + "\"" + " -i " + "\"" + InputPath + "\"" + " -o " + "\"" + OutputPath + "\"" + " -s 4 -t 32 -m " + "\"" + model_path + "\" -g "+QString::number(GPU_ID,10); - Waifu2x->start(cmd); - while(!Waifu2x->waitForStarted(100)&&!QProcess_stop) {} - while(!Waifu2x->waitForFinished(100)&&!QProcess_stop) {} - if(QFile::exists(OutputPath) && (Waifu2x->readAllStandardError().toLower().contains("failed")||Waifu2x->readAllStandardOutput().toLower().contains("failed"))==false) - { - Available_GPUID_Realsr_ncnn_vulkan.append(QString::number(GPU_ID,10)); - GPU_ID++; - QFile::remove(OutputPath); - } - else - { - if(GPU_ID > -1) - { - break; - } - else - { - GPU_ID++; - } - } - } - QFile::remove(OutputPath); - //=============== - emit Send_TextBrowser_NewMessage(tr("Detection is complete!")); - if(Available_GPUID_Realsr_ncnn_vulkan.isEmpty()) - { - Send_TextBrowser_NewMessage(tr("No available GPU ID detected!")); - } - emit Send_Realsr_ncnn_vulkan_DetectGPU_finished(); - return 0; -} -/* -检测完成,向可用gpu列表和多显卡列表内填充数据: -*/ -int MainWindow::Realsr_ncnn_vulkan_DetectGPU_finished() -{ - pushButton_Start_setEnabled_self(1); - ui->pushButton_DetectGPU->setEnabled(1); - ui->pushButton_compatibilityTest->setEnabled(1); - ui->pushButton_DetectGPUID_srmd->setEnabled(1); - ui->pushButton_DumpProcessorList_converter->setEnabled(1); - on_checkBox_SpecifyGPU_Anime4k_stateChanged(1); - ui->pushButton_DetectGPU_RealsrNCNNVulkan->setEnabled(1); - //==== - GPUIDs_List_MultiGPU_RealsrNcnnVulkan.clear(); - ui->comboBox_GPUIDs_MultiGPU_RealsrNcnnVulkan->clear(); - //=== - ui->comboBox_GPUID_RealsrNCNNVulkan->clear(); - ui->comboBox_GPUID_RealsrNCNNVulkan->addItem("auto"); - if(!Available_GPUID_Realsr_ncnn_vulkan.isEmpty()) - { - for(int i=0; icomboBox_GPUID_RealsrNCNNVulkan->addItem(Available_GPUID_Realsr_ncnn_vulkan.at(i)); - AddGPU_MultiGPU_RealsrNcnnVulkan(Available_GPUID_Realsr_ncnn_vulkan.at(i)); - } - } - //==== - ui->pushButton_DetectGPU_RealsrNCNNVulkan->setText(tr("Detect available GPU ID")); - //==== - return 0; -} -/* -RealsrNcnnVulkan_MultiGPU -向Realsr_NCNN_Vulkan_ReadSettings()提交显卡信息. -通过 轮流提交显卡信息+多线程 一起实现多显卡 -*/ -QMap MainWindow::RealsrNcnnVulkan_MultiGPU() -{ - MultiGPU_QMutex_RealsrNcnnVulkan.lock(); - //==== - int MAX_GPU_ID_RealsrNcnnVulkan = GPUIDs_List_MultiGPU_RealsrNcnnVulkan.size()-1; - if(GPU_ID_RealsrNcnnVulkan_MultiGPU>MAX_GPU_ID_RealsrNcnnVulkan) - { - GPU_ID_RealsrNcnnVulkan_MultiGPU=0; - } - //====== - QMap GPUInfo; - do - { - GPUInfo = GPUIDs_List_MultiGPU_RealsrNcnnVulkan.at(GPU_ID_RealsrNcnnVulkan_MultiGPU); - if(GPUInfo["isEnabled"] != "true") - { - GPU_ID_RealsrNcnnVulkan_MultiGPU++; - if(GPU_ID_RealsrNcnnVulkan_MultiGPU>MAX_GPU_ID_RealsrNcnnVulkan) - { - GPU_ID_RealsrNcnnVulkan_MultiGPU=0; - } - } - else - { - break; - } - } - while(true); - //====== - GPU_ID_RealsrNcnnVulkan_MultiGPU++; - if(GPU_ID_RealsrNcnnVulkan_MultiGPU>MAX_GPU_ID_RealsrNcnnVulkan) - { - GPU_ID_RealsrNcnnVulkan_MultiGPU=0; - } - //====== - MultiGPU_QMutex_RealsrNcnnVulkan.unlock(); - return GPUInfo; -} -/* -向多显卡的显卡信息列表中添加显卡信息 -*/ -void MainWindow::AddGPU_MultiGPU_RealsrNcnnVulkan(QString GPUID) -{ - QMap GPUInfo; - GPUInfo["ID"] = GPUID; - GPUInfo["isEnabled"] = "true"; - GPUInfo["TileSize"] = "100"; - GPUIDs_List_MultiGPU_RealsrNcnnVulkan.append(GPUInfo); - ui->comboBox_GPUIDs_MultiGPU_RealsrNcnnVulkan->addItem(GPUID); - ui->comboBox_GPUIDs_MultiGPU_RealsrNcnnVulkan->setCurrentIndex(0); -} - -void MainWindow::on_checkBox_MultiGPU_RealsrNcnnVulkan_stateChanged(int arg1) -{ - if(ui->checkBox_MultiGPU_RealsrNcnnVulkan->isChecked()) - { - ui->comboBox_GPUID_RealsrNCNNVulkan->setEnabled(0); - ui->frame_TileSize_RealsrNcnnVulkan->setEnabled(0); - ui->groupBox_GPUSettings_MultiGPU_RealsrNcnnVulkan->setEnabled(1); - } - else - { - ui->comboBox_GPUID_RealsrNCNNVulkan->setEnabled(1); - ui->frame_TileSize_RealsrNcnnVulkan->setEnabled(1); - ui->groupBox_GPUSettings_MultiGPU_RealsrNcnnVulkan->setEnabled(0); - } -} - -void MainWindow::on_checkBox_MultiGPU_RealsrNcnnVulkan_clicked() -{ - if(ui->checkBox_MultiGPU_RealsrNcnnVulkan->isChecked()) - { - if(GPUIDs_List_MultiGPU_RealsrNcnnVulkan.size()==0) - { - QMessageBox *MSG = new QMessageBox(); - MSG->setWindowTitle(tr("Notification")); - MSG->setText(tr("Please detect available GPU ID before enable Multi-GPU.")); - MSG->setIcon(QMessageBox::Information); - MSG->setModal(true); - MSG->show(); - ui->checkBox_MultiGPU_RealsrNcnnVulkan->setChecked(0); - return; - } - if(GPUIDs_List_MultiGPU_RealsrNcnnVulkan.size()<2) - { - QMessageBox *MSG = new QMessageBox(); - MSG->setWindowTitle(tr("Error")); - MSG->setText(tr("Insufficient number of available GPUs.")); - MSG->setIcon(QMessageBox::Warning); - MSG->setModal(true); - MSG->show(); - ui->checkBox_MultiGPU_RealsrNcnnVulkan->setChecked(0); - return; - } - } -} - -void MainWindow::on_comboBox_GPUIDs_MultiGPU_RealsrNcnnVulkan_currentIndexChanged(int index) -{ - if(ui->comboBox_GPUIDs_MultiGPU_RealsrNcnnVulkan->count()==0) - { - return; - } - QMap GPUInfo=GPUIDs_List_MultiGPU_RealsrNcnnVulkan.at(ui->comboBox_GPUIDs_MultiGPU_RealsrNcnnVulkan->currentIndex()); - ui->checkBox_isEnable_CurrentGPU_MultiGPU_RealsrNcnnVulkan->setChecked(GPUInfo["isEnabled"] == "true"); - ui->spinBox_TileSize_CurrentGPU_MultiGPU_RealsrNcnnVulkan->setValue(GPUInfo["TileSize"].toInt()); -} - -void MainWindow::on_checkBox_isEnable_CurrentGPU_MultiGPU_RealsrNcnnVulkan_clicked() -{ - QMap GPUInfo=GPUIDs_List_MultiGPU_RealsrNcnnVulkan.at(ui->comboBox_GPUIDs_MultiGPU_RealsrNcnnVulkan->currentIndex()); - if(ui->checkBox_isEnable_CurrentGPU_MultiGPU_RealsrNcnnVulkan->isChecked()) - { - GPUInfo["isEnabled"] = "true"; - } - else - { - GPUInfo["isEnabled"] = "false"; - } - GPUIDs_List_MultiGPU_RealsrNcnnVulkan.replace(ui->comboBox_GPUIDs_MultiGPU_RealsrNcnnVulkan->currentIndex(),GPUInfo); - int enabledGPUs = 0; - for (int i=0; i GPUInfo_tmp = GPUIDs_List_MultiGPU_RealsrNcnnVulkan.at(i); - if(GPUInfo_tmp["isEnabled"] == "true") - { - enabledGPUs++; - } - } - if(enabledGPUs<2) - { - QMap GPUInfo=GPUIDs_List_MultiGPU_RealsrNcnnVulkan.at(ui->comboBox_GPUIDs_MultiGPU_RealsrNcnnVulkan->currentIndex()); - GPUInfo["isEnabled"] = "true"; - GPUIDs_List_MultiGPU_RealsrNcnnVulkan.replace(ui->comboBox_GPUIDs_MultiGPU_RealsrNcnnVulkan->currentIndex(),GPUInfo); - ui->checkBox_isEnable_CurrentGPU_MultiGPU_RealsrNcnnVulkan->setChecked(1); - QMessageBox *MSG = new QMessageBox(); - MSG->setWindowTitle(tr("Warning")); - MSG->setText(tr("At least 2 GPUs need to be enabled !!")); - MSG->setIcon(QMessageBox::Warning); - MSG->setModal(true); - MSG->show(); - } -} - -void MainWindow::on_spinBox_TileSize_CurrentGPU_MultiGPU_RealsrNcnnVulkan_valueChanged(int arg1) -{ - QMap GPUInfo=GPUIDs_List_MultiGPU_RealsrNcnnVulkan.at(ui->comboBox_GPUIDs_MultiGPU_RealsrNcnnVulkan->currentIndex()); - GPUInfo["TileSize"] = QString::number(ui->spinBox_TileSize_CurrentGPU_MultiGPU_RealsrNcnnVulkan->value(),10); - GPUIDs_List_MultiGPU_RealsrNcnnVulkan.replace(ui->comboBox_GPUIDs_MultiGPU_RealsrNcnnVulkan->currentIndex(),GPUInfo); -} - -void MainWindow::on_pushButton_ShowMultiGPUSettings_RealsrNcnnVulkan_clicked() -{ - int Max_GPU_ID = GPUIDs_List_MultiGPU_RealsrNcnnVulkan.size(); - QString MultiGPUSettings_str=""; - for(int GPU_ID=0; GPU_ID GPUInfo = GPUIDs_List_MultiGPU_RealsrNcnnVulkan.at(GPU_ID); - if(GPUInfo["isEnabled"] != "true") - { - continue; - } - else - { - MultiGPUSettings_str.append("GPU ID:["+GPUInfo["ID"]+"] | "+tr("Tile size:")+"["+GPUInfo["TileSize"]+"]\n\n"); - } - } - //========= - QMessageBox *MSG = new QMessageBox(); - MSG->setWindowTitle(tr("Current Multi-GPU settings")); - MSG->setText(MultiGPUSettings_str); - MSG->setIcon(QMessageBox::Information); - MSG->setModal(true); - MSG->show(); -} -/* -RealSR 块大小调整按钮 -*/ -void MainWindow::on_pushButton_Add_TileSize_RealsrNCNNVulkan_clicked() -{ - ui->spinBox_TileSize_RealsrNCNNVulkan->setValue(AddTileSize_NCNNVulkan_Converter(ui->spinBox_TileSize_RealsrNCNNVulkan->value())); -} - -void MainWindow::on_pushButton_Minus_TileSize_RealsrNCNNVulkan_clicked() -{ - ui->spinBox_TileSize_RealsrNCNNVulkan->setValue(MinusTileSize_NCNNVulkan_Converter(ui->spinBox_TileSize_RealsrNCNNVulkan->value())); -} - -/* -计算 临时放大倍率 -*/ -int MainWindow::Calculate_Temporary_ScaleRatio_RealsrNCNNVulkan(int ScaleRatio) -{ - int ScaleRatio_tmp=0; - //如果设定的scaleRatio不是偶数,则+1,并输出到tmp - if((ScaleRatio%2)==0) - { - ScaleRatio_tmp = ScaleRatio; - } - else - { - ScaleRatio_tmp = ScaleRatio+1; - } - //判断是否为4的幂数 - if((((ScaleRatio_tmp&(ScaleRatio_tmp-1))==0)&&(ScaleRatio_tmp&0x555555555))!=true) - { - for(int i=1; true; i++) - { - int pow_ =pow(4,i); - if(pow_>=ScaleRatio_tmp) - { - ScaleRatio_tmp=pow_; - break; - } - } - } - return ScaleRatio_tmp; -} - -/* -Realsr_NCNN_Vulkan -读取引擎配置 -*/ -QString MainWindow::Realsr_NCNN_Vulkan_ReadSettings_Video_GIF(int ThreadNum) -{ - QString Realsr_NCNN_Vulkan_Settings_str = " "; - if(ui->checkBox_MultiGPU_RealsrNcnnVulkan->isChecked()==false) - { - //==========单显卡========== - //GPU ID - if(ui->comboBox_GPUID_RealsrNCNNVulkan->currentText()!="auto") - { - Realsr_NCNN_Vulkan_Settings_str.append("-g "+ui->comboBox_GPUID_RealsrNCNNVulkan->currentText()+" "); - } - //Tile Size - Realsr_NCNN_Vulkan_Settings_str.append("-t "+QString::number(ui->spinBox_TileSize_RealsrNCNNVulkan->value(),10)+" "); - //线程数量 - QString jobs_num_str = QString("%1").arg(ThreadNum); - Realsr_NCNN_Vulkan_Settings_str.append("-j "+jobs_num_str+":"+jobs_num_str+":"+jobs_num_str+" "); - } - else - { - //==============多显卡================ - int NumOfGPUs_Available = GPUIDs_List_MultiGPU_RealsrNcnnVulkan.size();//获取显卡总数 - int NumOfGPUs_Enabled = 0; - QString GPU_ID_cmd = "-g "; - QString TileSize_cmd = "-t "; - for(int i=0; i GPUInfo = GPUIDs_List_MultiGPU_RealsrNcnnVulkan.at(i); - if(GPUInfo["isEnabled"] != "true")continue; - NumOfGPUs_Enabled++; - if(i==0) - { - GPU_ID_cmd.append(GPUInfo["ID"]); - TileSize_cmd.append(GPUInfo["TileSize"]); - } - else - { - GPU_ID_cmd.append(","+GPUInfo["ID"]); - TileSize_cmd.append(","+GPUInfo["TileSize"]); - } - } - Realsr_NCNN_Vulkan_Settings_str.append(GPU_ID_cmd+" "); - Realsr_NCNN_Vulkan_Settings_str.append(TileSize_cmd+" "); - //线程数量 - int NumOfThreads_PerGPU = ThreadNum/NumOfGPUs_Enabled; - if(NumOfThreads_PerGPU<1)NumOfThreads_PerGPU=1; - int LoadAndWrite_tnum = NumOfGPUs_Enabled*NumOfThreads_PerGPU; - QString Jobs_cmd = ""; - for(int i=0; icheckBox_TTA_RealsrNCNNVulkan->isChecked()) - { - Realsr_NCNN_Vulkan_Settings_str.append("-x "); - } - //Model - QString Waifu2x_folder_path = Current_Path+"/realsr-ncnn-vulkan"; - switch(ui->comboBox_Model_RealsrNCNNVulkan->currentIndex()) - { - case 0: - { - Realsr_NCNN_Vulkan_Settings_str.append("-m \""+Waifu2x_folder_path+"/models-DF2K_JPEG\" "); - break; - } - case 1: - { - Realsr_NCNN_Vulkan_Settings_str.append("-m \""+Waifu2x_folder_path+"/models-DF2K\" "); - break; - } - } - //======================================= - return Realsr_NCNN_Vulkan_Settings_str; -} -/* -放大 APNG -*/ -bool MainWindow::APNG_RealsrNCNNVulkan(QString splitFramesFolder,QString scaledFramesFolder,QString sourceFileFullPath,QStringList framesFileName_qStrList,QString resultFileFullPath) -{ - //生成文件夹 - file_DelDir(scaledFramesFolder); - file_mkDir(scaledFramesFolder); - //============================================================ - //开始放大 - //读取放大倍数 - int ScaleRatio_Original = 2; - if(CustRes_isContained(sourceFileFullPath)) - { - QMap Res_map = CustRes_getResMap(sourceFileFullPath);//res_map["fullpath"],["height"],["width"] - ScaleRatio_Original = CustRes_CalNewScaleRatio(sourceFileFullPath,Res_map["height"].toInt(),Res_map["width"].toInt()); - } - else - { - ScaleRatio_Original = ui->doubleSpinBox_ScaleRatio_gif->value(); - } - int ScaleRatio_Max=Calculate_Temporary_ScaleRatio_RealsrNCNNVulkan(ScaleRatio_Original); - bool isOverScaled = (ScaleRatio_Max!=ScaleRatio_Original); - //初始化进度讯息 - int NumOfSplitFrames = framesFileName_qStrList.size(); - if(ui->checkBox_ShowInterPro->isChecked()) - { - int NumOfRounds=0; - for(int ScaleRatio_Current_tmp=4; ScaleRatio_Current_tmp<=ScaleRatio_Max; ScaleRatio_Current_tmp*=4) - { - NumOfRounds++; - } - emit Send_CurrentFileProgress_Start(file_getBaseName(sourceFileFullPath)+"."+sourceFileFullPath.split(".").last(),NumOfSplitFrames*NumOfRounds); - } - //读取配置讯息 - QString Realsr_NCNN_Vulkan_Settings_str = Realsr_NCNN_Vulkan_ReadSettings_Video_GIF(ui->spinBox_ThreadNum_gif_internal->value()); - QProcess *Waifu2x = new QProcess(); - QString program = Current_Path+"/realsr-ncnn-vulkan/realsr-ncnn-vulkan_waifu2xEX.exe"; - bool waifu2x_qprocess_failed = false; - int CountFinishedRounds=0; - //==== - for(int ScaleRatio_Current_tmp=4; ScaleRatio_Current_tmp<=ScaleRatio_Max && framesFileName_qStrList.isEmpty()==false; ScaleRatio_Current_tmp*=4) - { - for(int retry=0; retry<(ui->spinBox_retry->value()+ForceRetryCount); retry++) - { - QString ErrorMSG=""; - QString StanderMSG=""; - //========== - waifu2x_qprocess_failed = false; - QString cmd = "\"" + program + "\"" + " -i " + "\"" + splitFramesFolder + "\"" + " -o " + "\"" + scaledFramesFolder + "\"" + " -s 4 " + Realsr_NCNN_Vulkan_Settings_str; - Waifu2x->start(cmd); - while(!Waifu2x->waitForStarted(100)&&!QProcess_stop) {} - while(!Waifu2x->waitForFinished(650)&&!QProcess_stop) - { - if(waifu2x_STOP) - { - Waifu2x->close(); - mutex_ThreadNumRunning.lock(); - ThreadNumRunning--; - mutex_ThreadNumRunning.unlock(); - return false; - } - ErrorMSG.append(Waifu2x->readAllStandardError().toLower()); - StanderMSG.append(Waifu2x->readAllStandardOutput().toLower()); - if(ErrorMSG.contains("failed")||StanderMSG.contains("failed")) - { - waifu2x_qprocess_failed = true; - Waifu2x->close(); - break; - } - if(ui->checkBox_ShowInterPro->isChecked()) - { - emit Send_CurrentFileProgress_progressbar_SetFinishedValue((NumOfSplitFrames*CountFinishedRounds)+file_getFileNames_in_Folder_nofilter(scaledFramesFolder).size()); - } - } - //=============== - if(waifu2x_qprocess_failed==false) - { - ErrorMSG.append(Waifu2x->readAllStandardError().toLower()); - StanderMSG.append(Waifu2x->readAllStandardOutput().toLower()); - if(ErrorMSG.contains("failed")||StanderMSG.contains("failed")) - { - waifu2x_qprocess_failed = true; - } - } - //========= 检测是否成功,是否需要重试 ============ - if((NumOfSplitFrames == file_getFileNames_in_Folder_nofilter(scaledFramesFolder).size())&&!waifu2x_qprocess_failed) - { - break; - } - else - { - //失败 - file_DelDir(scaledFramesFolder); - file_mkDir(scaledFramesFolder); - if(retry==ui->spinBox_retry->value()+(ForceRetryCount-1))break; - emit Send_TextBrowser_NewMessage(tr("Automatic retry, please wait.")); - Delay_sec_sleep(5); - } - } - //=========== - //根据轮数修改参数 - if(ScaleRatio_Current_tmp. + + My Github homepage: https://github.com/AaronFeng753 +*/ + +#include "mainwindow.h" +#include "ui_mainwindow.h" + +int MainWindow::Realsr_NCNN_Vulkan_Image(int rowNum,bool ReProcess_MissingAlphaChannel) +{ + //============================= 读取设置 ================================ + bool DelOriginal = (ui->checkBox_DelOriginal->isChecked()||ui->checkBox_ReplaceOriginalFile->isChecked()); + QString OutPutPath_Final =""; + //========================= 拆解map得到参数 ============================= + //将状态设定到处理中 + emit Send_Table_image_ChangeStatus_rowNumInt_statusQString(rowNum, "Processing"); + //得到原文件路径 + QString SourceFile_fullPath = Table_model_image->item(rowNum,2)->text(); + if(!QFile::exists(SourceFile_fullPath))//判断源文件是否存在 + { + emit Send_TextBrowser_NewMessage(tr("Error occured when processing [")+SourceFile_fullPath+tr("]. Error: [File does not exist.]")); + emit Send_Table_image_ChangeStatus_rowNumInt_statusQString(rowNum, "Failed"); + emit Send_progressbar_Add(); + mutex_ThreadNumRunning.lock(); + ThreadNumRunning--; + mutex_ThreadNumRunning.unlock();//线程数量统计-1 + return 0; + } + //========= 转换到 PNG ========= + QString SourceFile_fullPath_Original = SourceFile_fullPath; + SourceFile_fullPath = Imgae_PreProcess(SourceFile_fullPath_Original,ReProcess_MissingAlphaChannel); + //=============== + int ScaleRatio=2; + bool CustRes_isEnabled = false; + int CustRes_height=0; + int CustRes_width=0; + //检查是是否有自定义分辨率 + if(CustRes_isContained(SourceFile_fullPath_Original)) + { + CustRes_isEnabled=true; + QMap Res_map = CustRes_getResMap(SourceFile_fullPath_Original);//res_map["fullpath"],["height"],["width"] + ScaleRatio = CustRes_CalNewScaleRatio(SourceFile_fullPath,Res_map["height"].toInt(),Res_map["width"].toInt()); + if(ScaleRatio==0) + { + emit Send_TextBrowser_NewMessage(tr("Error occured when processing [")+SourceFile_fullPath_Original+tr("]. Error: [The resolution of the source file cannot be read, so the image cannot be scaled to a custom resolution.]")); + emit Send_Table_image_ChangeStatus_rowNumInt_statusQString(rowNum, "Failed"); + emit Send_progressbar_Add(); + mutex_ThreadNumRunning.lock(); + ThreadNumRunning--; + mutex_ThreadNumRunning.unlock();//线程数量统计-1 + return 0; + } + CustRes_height=Res_map["height"].toInt(); + CustRes_width=Res_map["width"].toInt(); + } + else + { + double ScaleRatio_double_tmp = ui->doubleSpinBox_ScaleRatio_image->value(); + if(ScaleRatio_double_tmp == (int)ScaleRatio_double_tmp) + { + ScaleRatio = qRound(ScaleRatio_double_tmp); + } + else + { + CustRes_isEnabled=true; + QMap Res_map = DoubleScaleRatio_Cal_NewScaleRatio_NewHW(SourceFile_fullPath,ScaleRatio_double_tmp); + //==== + if(Res_map.isEmpty()) + { + emit Send_TextBrowser_NewMessage(tr("Error occured when processing [")+SourceFile_fullPath+tr("]. Error: [Unable to read the resolution of the source file.]")); + emit Send_Table_image_ChangeStatus_rowNumInt_statusQString(rowNum, "Failed"); + emit Send_progressbar_Add(); + mutex_ThreadNumRunning.lock(); + ThreadNumRunning--; + mutex_ThreadNumRunning.unlock();//线程数量统计-1 + return 0; + } + //==== + ScaleRatio = Res_map["ScaleRatio"].toInt(); + CustRes_height = Res_map["Height_new"].toInt(); + CustRes_width = Res_map["width_new"].toInt(); + } + } + //=============== + QFileInfo fileinfo(SourceFile_fullPath); + QString file_name = file_getBaseName(SourceFile_fullPath); + QString file_ext = fileinfo.suffix(); + QString file_path = file_getFolderPath(fileinfo); + QString OutPut_Path = file_path + "/" + file_name + "_waifu2x_"+QString::number(ScaleRatio, 10)+"x_"+file_ext+".png"; + //============================== 放大 ======================================= + QProcess *Waifu2x = new QProcess(); + QString program = Current_Path+"/realsr-ncnn-vulkan/realsr-ncnn-vulkan_waifu2xEX.exe"; + //========== + int ScaleRatio_tmp=Calculate_Temporary_ScaleRatio_RealsrNCNNVulkan(ScaleRatio); + QString InputPath_tmp = SourceFile_fullPath; + QString OutputPath_tmp =""; + for(int retry=0; retry<(ui->spinBox_retry->value()+ForceRetryCount); retry++) + { + bool waifu2x_qprocess_failed = false; + InputPath_tmp = SourceFile_fullPath; + OutputPath_tmp =""; + for(int i=4; i<=ScaleRatio_tmp; i*=4) + { + QString ErrorMSG=""; + QString StanderMSG=""; + //========================== + OutputPath_tmp = file_path + "/" + file_name + "_waifu2x_"+QString::number(i, 10)+"x_"+file_ext+".png"; + QString cmd = "\"" + program + "\"" + " -i " + "\"" + InputPath_tmp + "\"" + " -o " + "\"" + OutputPath_tmp + "\"" + " -s " + "4" + Realsr_NCNN_Vulkan_ReadSettings(); + Waifu2x->start(cmd); + while(!Waifu2x->waitForStarted(100)&&!QProcess_stop) {} + while(!Waifu2x->waitForFinished(500)&&!QProcess_stop) + { + //判断用户是否暂停处理 + if(waifu2x_STOP) + { + Waifu2x->close(); + if(i>4) + { + QFile::remove(InputPath_tmp); + } + QFile::remove(OutputPath_tmp); + emit Send_Table_image_ChangeStatus_rowNumInt_statusQString(rowNum, "Interrupted"); + mutex_ThreadNumRunning.lock(); + ThreadNumRunning--; + mutex_ThreadNumRunning.unlock(); + return 0; + } + //读取输出判断是否出错 + ErrorMSG.append(Waifu2x->readAllStandardError().toLower()); + StanderMSG.append(Waifu2x->readAllStandardOutput().toLower()); + if(ErrorMSG.contains("failed")||StanderMSG.contains("failed")) + { + waifu2x_qprocess_failed = true; + Waifu2x->close(); + if(i>4) + { + QFile::remove(InputPath_tmp); + } + QFile::remove(OutputPath_tmp); + break; + } + } + //=============== + if(waifu2x_qprocess_failed)break; + //=============== + ErrorMSG.append(Waifu2x->readAllStandardError().toLower()); + StanderMSG.append(Waifu2x->readAllStandardOutput().toLower()); + if(ErrorMSG.contains("failed")||StanderMSG.contains("failed")) + { + waifu2x_qprocess_failed = true; + if(i>4) + { + QFile::remove(InputPath_tmp); + } + QFile::remove(OutputPath_tmp); + break; + } + //=============== + if(i>4) + { + QFile::remove(InputPath_tmp); + } + InputPath_tmp = OutputPath_tmp; + } + //========= 检测是否成功,是否需要重试 ============ + if(QFile::exists(OutputPath_tmp)&&!waifu2x_qprocess_failed) + { + break; + } + else + { + QFile::remove(OutputPath_tmp); + if(retry==ui->spinBox_retry->value()+(ForceRetryCount-1))break; + emit Send_TextBrowser_NewMessage(tr("Automatic retry, please wait.")); + Delay_sec_sleep(5); + } + } + if(!QFile::exists(OutputPath_tmp)) + { + if(SourceFile_fullPath_Original!=SourceFile_fullPath) + { + QFile::remove(SourceFile_fullPath); + } + emit Send_TextBrowser_NewMessage(tr("Error occured when processing [")+SourceFile_fullPath_Original+tr("]. Error: [Unable to scale the picture.]")); + emit Send_Table_image_ChangeStatus_rowNumInt_statusQString(rowNum, "Failed"); + emit Send_progressbar_Add(); + mutex_ThreadNumRunning.lock(); + ThreadNumRunning--; + mutex_ThreadNumRunning.unlock(); + return 0; + } + OutPutPath_Final = OutputPath_tmp; + //============================ 调整大小 ==================================================== + if(ScaleRatio_tmp != ScaleRatio||CustRes_isEnabled) + { + int New_height=0; + int New_width=0; + if(CustRes_isEnabled) + { + New_height= CustRes_height; + New_width= CustRes_width; + } + else + { + QMap res_map_OriginalFile = Image_Gif_Read_Resolution(SourceFile_fullPath); + New_height = res_map_OriginalFile["height"]*ScaleRatio; + New_width = res_map_OriginalFile["width"]*ScaleRatio; + } + QImage qimage_adj(OutputPath_tmp); + //读取放大后的图片并调整大小 + QImage qimage_adj_scaled = qimage_adj.scaled(New_width,New_height,CustRes_AspectRatioMode,Qt::SmoothTransformation); + QImageWriter qimageW_adj; + qimageW_adj.setFormat("png"); + qimageW_adj.setFileName(OutPut_Path); + if(qimageW_adj.canWrite()) + { + qimageW_adj.write(qimage_adj_scaled); + } + QFile::remove(OutputPath_tmp); + if(!QFile::exists(OutPut_Path)) + { + emit Send_TextBrowser_NewMessage(tr("Error occured when processing [")+SourceFile_fullPath+tr("]. Error: [Unable to resize the scaled picture to the target size]")); + emit Send_Table_image_ChangeStatus_rowNumInt_statusQString(rowNum, "Failed"); + emit Send_progressbar_Add(); + mutex_ThreadNumRunning.lock(); + ThreadNumRunning--; + mutex_ThreadNumRunning.unlock();//线程数量统计-1 + return 0; + } + OutPutPath_Final = OutPut_Path; + } + if(CustRes_isEnabled) + { + QString OutPut_Path_CustRes = file_path + "/" + file_name + "_waifu2x_"+QString::number(CustRes_width, 10)+"x"+QString::number(CustRes_height, 10)+"_"+file_ext+".png"; + QFile::remove(OutPut_Path_CustRes); + QFile::rename(OutPut_Path,OutPut_Path_CustRes); + OutPutPath_Final = OutPut_Path_CustRes; + } + //=========================== 另存为JPG&压缩JPG =========================================== + OutPutPath_Final = SaveImageAs_FormatAndQuality(SourceFile_fullPath_Original,OutPutPath_Final,false,0); + //================== 检查是否丢失了透明通道 ===================== + if(ReProcess_MissingAlphaChannel==false) + { + QImage QImage_source(SourceFile_fullPath_Original); + QImage QImage_Final(OutPutPath_Final); + if(QImage_source.hasAlphaChannel()==true && QImage_Final.hasAlphaChannel()==false && ui->checkBox_AutoDetectAlphaChannel->isChecked()) + { + QFile::remove(OutPutPath_Final); + emit Send_TextBrowser_NewMessage(tr("Since the Alpha channel in the resulting image is lost, this image will be reprocessed to fix it:[")+SourceFile_fullPath_Original+tr("].\nIf the reprocessing happens a lot, you should consider enable [Always pre-process images with Alpha Channel] in [Additional settings].")); + return Realsr_NCNN_Vulkan_Image(rowNum,true); + } + } + //============================= 删除原文件 & & 更新table status ============================ + if(SourceFile_fullPath_Original!=SourceFile_fullPath) + { + QFile::remove(SourceFile_fullPath); + SourceFile_fullPath = SourceFile_fullPath_Original; + } + if(DelOriginal) + { + if(ReplaceOriginalFile(SourceFile_fullPath,OutPutPath_Final)==false) + { + if(QAction_checkBox_MoveToRecycleBin_checkBox_DelOriginal->isChecked()) + { + file_MoveToTrash(SourceFile_fullPath); + } + else + { + QFile::remove(SourceFile_fullPath); + } + } + emit Send_Table_image_ChangeStatus_rowNumInt_statusQString(rowNum, "Finished, original file deleted"); + } + else + { + emit Send_Table_image_ChangeStatus_rowNumInt_statusQString(rowNum, "Finished"); + } + //========== 移动到输出路径 ========= + if(ui->checkBox_OutPath_isEnabled->isChecked()) + { + MoveFileToOutputPath(OutPutPath_Final,SourceFile_fullPath); + } + //============================ 更新进度条 ================================= + emit Send_progressbar_Add(); + //=========================== 更新线程数量统计============================== + mutex_ThreadNumRunning.lock(); + ThreadNumRunning--; + mutex_ThreadNumRunning.unlock();//线程数量统计-1 + return 0; +} + +/* + + ============================================================================================= + ============================================================================================= + ============================= Waifu2x_NCNN_Vulkan_GIF ======================================= + ============================================================================================= + ============================================================================================= + +*/ + +int MainWindow::Realsr_NCNN_Vulkan_GIF(int rowNum) +{ + //============================= 读取设置 ================================ + int ScaleRatio = ui->doubleSpinBox_ScaleRatio_gif->value(); + bool DelOriginal = (ui->checkBox_DelOriginal->isChecked()||ui->checkBox_ReplaceOriginalFile->isChecked()); + bool OptGIF = ui->checkBox_OptGIF->isChecked(); + QString OutPutPath_Final =""; + //========================= 拆解map得到参数 ============================= + emit Send_Table_gif_ChangeStatus_rowNumInt_statusQString(rowNum, "Processing"); + QString SourceFile_fullPath = Table_model_gif->item(rowNum,2)->text(); + if(!QFile::exists(SourceFile_fullPath)) + { + emit Send_TextBrowser_NewMessage(tr("Error occured when processing [")+SourceFile_fullPath+tr("]. Error: [File does not exist.]")); + emit Send_Table_gif_ChangeStatus_rowNumInt_statusQString(rowNum, "Failed"); + emit Send_progressbar_Add(); + return 0; + } + //========================== + bool CustRes_isEnabled = false; + int CustRes_height=0; + int CustRes_width=0; + if(CustRes_isContained(SourceFile_fullPath)) + { + CustRes_isEnabled=true; + QMap Res_map = CustRes_getResMap(SourceFile_fullPath);//res_map["fullpath"],["height"],["width"] + CustRes_height=Res_map["height"].toInt(); + CustRes_width=Res_map["width"].toInt(); + } + //========================== + QFileInfo fileinfo(SourceFile_fullPath); + QString file_name = file_getBaseName(SourceFile_fullPath); + QString file_ext = fileinfo.suffix(); + QString file_path = file_getFolderPath(fileinfo); + QString ResGIFPath = file_path + "/" + file_name + "_waifu2x_"+QString::number(ScaleRatio, 10)+"x.gif"; + //=========================== 获取帧时间 ==================================== + int GIF_Duration = Gif_getDuration(SourceFile_fullPath); + if(GIF_Duration==0)//检查是否成功获取duration + { + emit Send_TextBrowser_NewMessage(tr("Error occured when processing [")+SourceFile_fullPath+tr("]. Error: [Can't get Duration value of GIF file.]")); + emit Send_Table_gif_ChangeStatus_rowNumInt_statusQString(rowNum, "Failed"); + //file_DelDir(SplitFramesFolderPath); + emit Send_progressbar_Add(); + return 0;//如果启用stop位,则直接return + } + //============================== 拆分 ========================================== + QString SplitFramesFolderPath = file_path+"/"+file_name+"_SplitFrames_W2xEX";//拆分后存储frame的文件夹 + Gif_splitGif(SourceFile_fullPath,SplitFramesFolderPath); + //============================== 扫描获取文件名 =============================== + QStringList Frame_fileName_list = file_getFileNames_in_Folder_nofilter(SplitFramesFolderPath); + if(Frame_fileName_list.isEmpty())//检查是否成功拆分gif + { + emit Send_TextBrowser_NewMessage(tr("Error occured when processing [")+SourceFile_fullPath+tr("]. Error: [Can't split GIF into frames.]")); + emit Send_Table_gif_ChangeStatus_rowNumInt_statusQString(rowNum, "Failed"); + file_DelDir(SplitFramesFolderPath); + emit Send_progressbar_Add(); + return 0;//如果启用stop位,则直接return + } + //===========建立存储放大后frame的文件夹=========== + QString ScaledFramesFolderPath = SplitFramesFolderPath+"/ScaledFrames_W2xEX"; + if(file_isDirExist(ScaledFramesFolderPath)) + { + file_DelDir(ScaledFramesFolderPath); + file_mkDir(ScaledFramesFolderPath); + } + else + { + file_mkDir(ScaledFramesFolderPath); + } + //==========开始放大========================== + //读取放大倍数 + int ScaleRatio_Original = 2; + if(CustRes_isEnabled == true) + { + ScaleRatio_Original = CustRes_CalNewScaleRatio(SourceFile_fullPath,CustRes_height,CustRes_width); + } + else + { + ScaleRatio_Original = ui->doubleSpinBox_ScaleRatio_gif->value(); + } + int ScaleRatio_Max=Calculate_Temporary_ScaleRatio_RealsrNCNNVulkan(ScaleRatio_Original); + bool isOverScaled = (ScaleRatio_Max!=ScaleRatio_Original); + //初始化进度讯息 + int NumOfSplitFrames = Frame_fileName_list.size(); + if(ui->checkBox_ShowInterPro->isChecked()) + { + int NumOfRounds=0; + for(int ScaleRatio_Current_tmp=4; ScaleRatio_Current_tmp<=ScaleRatio_Max; ScaleRatio_Current_tmp*=4) + { + NumOfRounds++; + } + emit Send_CurrentFileProgress_Start(file_name+"."+file_ext,NumOfSplitFrames*NumOfRounds); + } + //读取配置讯息 + QString Realsr_NCNN_Vulkan_Settings_str = Realsr_NCNN_Vulkan_ReadSettings_Video_GIF(ui->spinBox_ThreadNum_gif_internal->value()); + QProcess *Waifu2x = new QProcess(); + QString program = Current_Path+"/realsr-ncnn-vulkan/realsr-ncnn-vulkan_waifu2xEX.exe"; + bool waifu2x_qprocess_failed = false; + int CountFinishedRounds=0; + //==== + for(int ScaleRatio_Current_tmp=4; ScaleRatio_Current_tmp<=ScaleRatio_Max && Frame_fileName_list.isEmpty()==false; ScaleRatio_Current_tmp*=4) + { + for(int retry=0; retry<(ui->spinBox_retry->value()+ForceRetryCount); retry++) + { + QString ErrorMSG=""; + QString StanderMSG=""; + //========== + waifu2x_qprocess_failed = false; + QString cmd = "\"" + program + "\"" + " -i " + "\"" + SplitFramesFolderPath + "\"" + " -o " + "\"" + ScaledFramesFolderPath + "\"" + " -s 4 " + Realsr_NCNN_Vulkan_Settings_str; + Waifu2x->start(cmd); + while(!Waifu2x->waitForStarted(100)&&!QProcess_stop) {} + while(!Waifu2x->waitForFinished(650)&&!QProcess_stop) + { + if(waifu2x_STOP) + { + Waifu2x->close(); + file_DelDir(SplitFramesFolderPath); + emit Send_Table_gif_ChangeStatus_rowNumInt_statusQString(rowNum, "Interrupted"); + mutex_ThreadNumRunning.lock(); + ThreadNumRunning--; + mutex_ThreadNumRunning.unlock(); + return 0; + } + ErrorMSG.append(Waifu2x->readAllStandardError().toLower()); + StanderMSG.append(Waifu2x->readAllStandardOutput().toLower()); + if(ErrorMSG.contains("failed")||StanderMSG.contains("failed")) + { + waifu2x_qprocess_failed = true; + Waifu2x->close(); + break; + } + if(ui->checkBox_ShowInterPro->isChecked()) + { + emit Send_CurrentFileProgress_progressbar_SetFinishedValue((NumOfSplitFrames*CountFinishedRounds)+file_getFileNames_in_Folder_nofilter(ScaledFramesFolderPath).size()); + } + } + //=============== + if(waifu2x_qprocess_failed==false) + { + ErrorMSG.append(Waifu2x->readAllStandardError().toLower()); + StanderMSG.append(Waifu2x->readAllStandardOutput().toLower()); + if(ErrorMSG.contains("failed")||StanderMSG.contains("failed")) + { + waifu2x_qprocess_failed = true; + } + } + //========= 检测是否成功,是否需要重试 ============ + if((NumOfSplitFrames == file_getFileNames_in_Folder_nofilter(ScaledFramesFolderPath).size())&&!waifu2x_qprocess_failed) + { + break; + } + else + { + //失败 + file_DelDir(ScaledFramesFolderPath); + file_mkDir(ScaledFramesFolderPath); + if(retry==ui->spinBox_retry->value()+(ForceRetryCount-1))break; + emit Send_TextBrowser_NewMessage(tr("Automatic retry, please wait.")); + Delay_sec_sleep(5); + } + } + //=========== + //根据轮数修改参数 + if(ScaleRatio_Current_tmpisChecked()) + { + file_MoveToTrash(SourceFile_fullPath); + } + else + { + QFile::remove(SourceFile_fullPath); + } + } + emit Send_Table_gif_ChangeStatus_rowNumInt_statusQString(rowNum, "Finished, original file deleted"); + } + else + { + emit Send_Table_gif_ChangeStatus_rowNumInt_statusQString(rowNum, "Finished"); + } + //========== 移动到输出路径 ========= + if(ui->checkBox_OutPath_isEnabled->isChecked()) + { + MoveFileToOutputPath(OutPutPath_Final,SourceFile_fullPath); + } + //============================ 更新进度条 ================================= + emit Send_progressbar_Add(); + //=========================== ============================== + return 0; +} + + + +/* + + ============================================================================================= + ============================================================================================= + ============================= Waifu2x_NCNN_Vulkan_Video ======================================= + ============================================================================================= + ============================================================================================= + + +*/ + +int MainWindow::Realsr_NCNN_Vulkan_Video(int rowNum) +{ + //============================= 读取设置 ================================ + int ScaleRatio = ui->doubleSpinBox_ScaleRatio_video->value(); + bool DelOriginal = (ui->checkBox_DelOriginal->isChecked()||ui->checkBox_ReplaceOriginalFile->isChecked()); + bool isCacheExists = false; + bool isVideoConfigChanged = true; + //========================= 拆解map得到参数 ============================= + emit Send_Table_video_ChangeStatus_rowNumInt_statusQString(rowNum, "Processing"); + QString SourceFile_fullPath = Table_model_video->item(rowNum,2)->text(); + if(!QFile::exists(SourceFile_fullPath)) + { + emit Send_TextBrowser_NewMessage(tr("Error occured when processing [")+SourceFile_fullPath+tr("]. Error: [File does not exist.]")); + emit Send_Table_video_ChangeStatus_rowNumInt_statusQString(rowNum, "Failed"); + emit Send_progressbar_Add(); + return 0; + } + //========================== + QFileInfo fileinfo(SourceFile_fullPath); + QString file_name = file_getBaseName(SourceFile_fullPath); + QString file_ext = fileinfo.suffix(); + QString file_path = file_getFolderPath(fileinfo); + //=================================================================== + //生成mp4 + QString video_mp4_fullpath=video_To_CFRMp4(SourceFile_fullPath); + if(!QFile::exists(video_mp4_fullpath))//检查是否成功生成mp4 + { + emit Send_TextBrowser_NewMessage(tr("Error occured when processing [")+SourceFile_fullPath+tr("]. Error: [Cannot convert video format to mp4.]")); + emit Send_Table_video_ChangeStatus_rowNumInt_statusQString(rowNum, "Failed"); + emit Send_progressbar_Add(); + return 0;//如果启用stop位,则直接return + } + //============ 读取自定义分辨率设定 ============== + bool CustRes_isEnabled = false; + int CustRes_height=0; + int CustRes_width=0; + if(CustRes_isContained(SourceFile_fullPath)) + { + CustRes_isEnabled=true; + QMap Res_map = CustRes_getResMap(SourceFile_fullPath);//res_map["fullpath"],["height"],["width"] + CustRes_height=Res_map["height"].toInt(); + CustRes_width=Res_map["width"].toInt(); + } + //================= + QString AudioPath = file_path+"/Audio_"+file_name+"_"+file_ext+"_W2xEX.wav";//音频 + QString SplitFramesFolderPath = file_path+"/"+file_name+"_"+file_ext+"_SplitFrames_W2xEX";//拆分后存储frame的文件夹 + QString ScaledFramesFolderPath = SplitFramesFolderPath+"/ScaledFrames_W2xEX";//存储放大后的帧 + //========================== + // 检测之前的视频配置文件 + //========================== + QString VideoConfiguration_fullPath = file_path+"/VideoConfiguration_"+file_name+"_"+file_ext+"_Waifu2xEX.ini"; + if(QFile::exists(VideoConfiguration_fullPath)) + { + QSettings *configIniRead = new QSettings(VideoConfiguration_fullPath, QSettings::IniFormat); + configIniRead->setIniCodec(QTextCodec::codecForName("UTF-8")); + //=================== 加载之前存储的视频信息 ========================= + int ScaleRatio_old = configIniRead->value("/VideoConfiguration/ScaleRatio").toInt(); + bool CustRes_isEnabled_old = configIniRead->value("/VideoConfiguration/CustRes_isEnabled").toBool(); + int CustRes_height_old = configIniRead->value("/VideoConfiguration/CustRes_height").toInt(); + int CustRes_width_old = configIniRead->value("/VideoConfiguration/CustRes_width").toInt(); + QString EngineName_old = configIniRead->value("/VideoConfiguration/EngineName").toString(); + bool isProcessBySegment_old = configIniRead->value("/VideoConfiguration/isProcessBySegment").toBool(); + //=================== 比对信息 ================================ + if(EngineName_old=="realsr-ncnn-vulkan") + { + if(CustRes_isEnabled_old==false&&CustRes_isEnabled==false) + { + if(ScaleRatio_old!=ScaleRatio) + { + isVideoConfigChanged=true; + } + else + { + isVideoConfigChanged=false; + } + } + else + { + if(CustRes_isEnabled_old==true&&CustRes_isEnabled==true) + { + if(CustRes_height_old!=CustRes_height||CustRes_width_old!=CustRes_width) + { + isVideoConfigChanged=true; + } + else + { + isVideoConfigChanged=false; + } + } + else + { + isVideoConfigChanged=true; + } + } + if(isProcessBySegment_old==true) + { + isVideoConfigChanged=true; + } + } + else + { + isVideoConfigChanged=true; + } + } + else + { + emit Send_video_write_VideoConfiguration(VideoConfiguration_fullPath,ScaleRatio,0,CustRes_isEnabled,CustRes_height,CustRes_width,"realsr-ncnn-vulkan",false,"","",ui->groupBox_FrameInterpolation->isChecked(),0); + } + //======================= + // 检测缓存是否存在 + //======================= + if(QFile::exists(video_mp4_fullpath)&&file_isDirExist(SplitFramesFolderPath)&&file_isDirExist(ScaledFramesFolderPath)&&QFile::exists(VideoConfiguration_fullPath)) + { + if(!isVideoConfigChanged) + { + isCacheExists=true; + emit Send_TextBrowser_NewMessage(tr("The previous video cache file is detected and processing of the previous video cache will continue. If you want to restart processing of the current video:[")+SourceFile_fullPath+tr("], delete the cache manually.")); + } + else + { + isCacheExists=false; + //======== + QFile::remove(VideoConfiguration_fullPath); + file_DelDir(SplitFramesFolderPath); + QFile::remove(AudioPath); + DelVfiDir(video_mp4_fullpath); + emit Send_video_write_VideoConfiguration(VideoConfiguration_fullPath,ScaleRatio,0,CustRes_isEnabled,CustRes_height,CustRes_width,"realsr-ncnn-vulkan",false,"","",ui->groupBox_FrameInterpolation->isChecked(),0); + //======= + emit Send_TextBrowser_NewMessage(tr("The previous video cache file was detected, but because you changed the settings about the video resolution, the previous cache will be deleted and processing of the video:[")+SourceFile_fullPath+tr("] will restart.")); + } + } + else + { + isCacheExists=false; + //======== + QFile::remove(VideoConfiguration_fullPath); + file_DelDir(SplitFramesFolderPath); + QFile::remove(AudioPath); + DelVfiDir(video_mp4_fullpath); + emit Send_video_write_VideoConfiguration(VideoConfiguration_fullPath,ScaleRatio,0,CustRes_isEnabled,CustRes_height,CustRes_width,"realsr-ncnn-vulkan",false,"","",ui->groupBox_FrameInterpolation->isChecked(),0); + //======== + } + if(!isCacheExists) + { + //============================== 拆分 ========================================== + if(file_isDirExist(SplitFramesFolderPath)) + { + file_DelDir(SplitFramesFolderPath); + file_mkDir(SplitFramesFolderPath); + } + else + { + file_mkDir(SplitFramesFolderPath); + } + QFile::remove(AudioPath); + video_video2images(video_mp4_fullpath,SplitFramesFolderPath,AudioPath); + if(waifu2x_STOP) + { + emit Send_Table_video_ChangeStatus_rowNumInt_statusQString(rowNum, "Interrupted"); + return 0;//如果启用stop位,则直接return + } + } + //============================== 扫描获取文件名 =============================== + QStringList Frame_fileName_list = file_getFileNames_in_Folder_nofilter(SplitFramesFolderPath); + if(!isCacheExists) + { + if(Frame_fileName_list.isEmpty())//检查是否成功拆分为帧 + { + emit Send_TextBrowser_NewMessage(tr("Error occured when processing [")+SourceFile_fullPath+tr("]. Error: [Unable to split video into pictures.]")); + emit Send_Table_video_ChangeStatus_rowNumInt_statusQString(rowNum, "Failed"); + emit Send_progressbar_Add(); + return 0;//如果启用stop位,则直接return + } + } + //============================== 放大 ======================================= + //===========建立存储放大后frame的文件夹=========== + if(!isCacheExists) + { + if(file_isDirExist(ScaledFramesFolderPath)) + { + file_DelDir(ScaledFramesFolderPath); + file_mkDir(ScaledFramesFolderPath); + } + else + { + file_mkDir(ScaledFramesFolderPath); + } + } + //==========开始放大========================== + //读取放大倍数 + int ScaleRatio_Original = 2; + if(CustRes_isEnabled == true) + { + ScaleRatio_Original = CustRes_CalNewScaleRatio(video_mp4_fullpath,CustRes_height,CustRes_width); + } + else + { + ScaleRatio_Original = ui->doubleSpinBox_ScaleRatio_video->value(); + } + int ScaleRatio_Max=Calculate_Temporary_ScaleRatio_RealsrNCNNVulkan(ScaleRatio_Original); + bool isOverScaled = (ScaleRatio_Max!=ScaleRatio_Original); + //读取初始放大倍率 + int Initial_ScaleRatio = 4; + if(!Frame_fileName_list.isEmpty()) + { + QString Full_Path_File = ""; + for(int i = 0; i < Frame_fileName_list.size(); i++) + { + QString tmp = Frame_fileName_list.at(i); + Full_Path_File = SplitFramesFolderPath + "/" + tmp; + QFileInfo finfo(Full_Path_File); + if(finfo.suffix()=="png")break; + } + QImage qimage_original; + qimage_original.load(Full_Path_File); + int Frame_height = qimage_original.height(); + QMap res_map = video_get_Resolution(SourceFile_fullPath); + int Video_height = res_map["height"]; + if(Frame_height>0 && Video_height>0 && Frame_height>=Video_height)//判断是否读取失败 + { + Initial_ScaleRatio = 4*(Frame_height/Video_height); + } + } + //初始化进度讯息 + int NumOfSplitFrames = Frame_fileName_list.size()+file_getFileNames_in_Folder_nofilter(ScaledFramesFolderPath).size(); + if(ui->checkBox_ShowInterPro->isChecked()) + { + int NumOfRounds=0; + for(int ScaleRatio_Current_tmp=Initial_ScaleRatio; ScaleRatio_Current_tmp<=ScaleRatio_Max; ScaleRatio_Current_tmp*=4) + { + NumOfRounds++; + } + emit Send_CurrentFileProgress_Start(file_name+"."+file_ext,NumOfSplitFrames*NumOfRounds); + } + //读取配置讯息 + QString Realsr_NCNN_Vulkan_Settings_str = Realsr_NCNN_Vulkan_ReadSettings_Video_GIF(ui->spinBox_ThreadNum_video_internal->value()); + QProcess *Waifu2x = new QProcess(); + QString program = Current_Path+"/realsr-ncnn-vulkan/realsr-ncnn-vulkan_waifu2xEX.exe"; + bool waifu2x_qprocess_failed = false; + int CountFinishedRounds=0; + //==== + for(int ScaleRatio_Current_tmp=Initial_ScaleRatio; ScaleRatio_Current_tmp<=ScaleRatio_Max && Frame_fileName_list.isEmpty()==false; ScaleRatio_Current_tmp*=4) + { + for(int retry=0; retry<(ui->spinBox_retry->value()+ForceRetryCount); retry++) + { + QString ErrorMSG=""; + QString StanderMSG=""; + //========== + waifu2x_qprocess_failed = false; + QString cmd = "\"" + program + "\"" + " -i " + "\"" + SplitFramesFolderPath + "\"" + " -o " + "\"" + ScaledFramesFolderPath + "\"" + " -s 4 " + Realsr_NCNN_Vulkan_Settings_str; + Waifu2x->start(cmd); + while(!Waifu2x->waitForStarted(100)&&!QProcess_stop) {} + while(!Waifu2x->waitForFinished(650)&&!QProcess_stop) + { + if(waifu2x_STOP) + { + QStringList FinfishedFileList_FileNames = WaitForEngineIO_NcnnVulkan(ScaledFramesFolderPath); + Waifu2x->close(); + //============ + QString file_name_tmp; + QStringList FileNames_ScaledFramesFolderPath = file_getFileNames_in_Folder_nofilter(ScaledFramesFolderPath); + for(int i=0; ireadAllStandardError().toLower()); + StanderMSG.append(Waifu2x->readAllStandardOutput().toLower()); + if(ErrorMSG.contains("failed")||StanderMSG.contains("failed")) + { + waifu2x_qprocess_failed = true; + Waifu2x->close(); + break; + } + if(ui->checkBox_ShowInterPro->isChecked()) + { + emit Send_CurrentFileProgress_progressbar_SetFinishedValue((NumOfSplitFrames*CountFinishedRounds)+file_getFileNames_in_Folder_nofilter(ScaledFramesFolderPath).size()); + } + } + //=============== + if(waifu2x_qprocess_failed==false) + { + ErrorMSG.append(Waifu2x->readAllStandardError().toLower()); + StanderMSG.append(Waifu2x->readAllStandardOutput().toLower()); + if(ErrorMSG.contains("failed")||StanderMSG.contains("failed")) + { + waifu2x_qprocess_failed = true; + } + } + //========= 检测是否成功,是否需要重试 ============ + if((NumOfSplitFrames == file_getFileNames_in_Folder_nofilter(ScaledFramesFolderPath).size())&&!waifu2x_qprocess_failed) + { + break; + } + else + { + //失败 + file_DelDir(ScaledFramesFolderPath); + file_mkDir(ScaledFramesFolderPath); + if(retry==ui->spinBox_retry->value()+(ForceRetryCount-1))break; + emit Send_TextBrowser_NewMessage(tr("Automatic retry, please wait.")); + Delay_sec_sleep(5); + } + } + //=========== + //根据轮数修改参数 + if(ScaleRatio_Current_tmpcheckBox_KeepVideoCache->isChecked()==false) + { + QFile::remove(VideoConfiguration_fullPath); + file_DelDir(SplitFramesFolderPath); + QFile::remove(AudioPath); + if(SourceFile_fullPath!=video_mp4_fullpath)QFile::remove(video_mp4_fullpath); + } + else + { + DelOriginal=false; + } + //============================= 删除原文件 & & 更新table status ============================ + if(DelOriginal) + { + if(ReplaceOriginalFile(SourceFile_fullPath,video_mp4_scaled_fullpath)==false) + { + if(QAction_checkBox_MoveToRecycleBin_checkBox_DelOriginal->isChecked()) + { + file_MoveToTrash(SourceFile_fullPath); + } + else + { + QFile::remove(SourceFile_fullPath); + } + } + emit Send_Table_video_ChangeStatus_rowNumInt_statusQString(rowNum, "Finished, original file deleted"); + } + else + { + emit Send_Table_video_ChangeStatus_rowNumInt_statusQString(rowNum, "Finished"); + } + //========== 移动到输出路径 ========= + if(ui->checkBox_OutPath_isEnabled->isChecked()) + { + MoveFileToOutputPath(video_mp4_scaled_fullpath,SourceFile_fullPath); + } + //============================ 更新进度条 ================================= + emit Send_progressbar_Add(); + //=========================== ============================== + return 0; +} +/* +#### 分段处理 #### +调用realser-ncnn-vulkan处理视频 +读取设置,拆分,创建放大子线程,组装视频 +*/ +int MainWindow::Realsr_NCNN_Vulkan_Video_BySegment(int rowNum) +{ + //============================= 读取设置 ================================ + int ScaleRatio = ui->doubleSpinBox_ScaleRatio_video->value(); + bool DelOriginal = (ui->checkBox_DelOriginal->isChecked()||ui->checkBox_ReplaceOriginalFile->isChecked()); + bool isCacheExists = false; + bool isVideoConfigChanged = true; + int SegmentDuration = ui->spinBox_SegmentDuration->value(); + //========================= 拆解map得到参数 ============================= + emit Send_Table_video_ChangeStatus_rowNumInt_statusQString(rowNum, "Processing"); + QString SourceFile_fullPath = Table_model_video->item(rowNum,2)->text(); + if(!QFile::exists(SourceFile_fullPath)) + { + emit Send_TextBrowser_NewMessage(tr("Error occured when processing [")+SourceFile_fullPath+tr("]. Error: [File does not exist.]")); + emit Send_Table_video_ChangeStatus_rowNumInt_statusQString(rowNum, "Failed"); + emit Send_progressbar_Add(); + return 0; + } + //========================== + QFileInfo fileinfo(SourceFile_fullPath); + QString file_name = file_getBaseName(SourceFile_fullPath); + QString file_ext = fileinfo.suffix(); + QString file_path = file_getFolderPath(fileinfo); + //=================================================================== + //生成mp4 + QString video_mp4_fullpath=video_To_CFRMp4(SourceFile_fullPath); + if(!QFile::exists(video_mp4_fullpath))//检查是否成功生成mp4 + { + emit Send_TextBrowser_NewMessage(tr("Error occured when processing [")+SourceFile_fullPath+tr("]. Error: [Cannot convert video format to mp4.]")); + emit Send_Table_video_ChangeStatus_rowNumInt_statusQString(rowNum, "Failed"); + emit Send_progressbar_Add(); + return 0;//如果启用stop位,则直接return + } + //============ 读取自定义分辨率设定 ============== + bool CustRes_isEnabled = false; + int CustRes_height=0; + int CustRes_width=0; + if(CustRes_isContained(SourceFile_fullPath)) + { + CustRes_isEnabled=true; + QMap Res_map = CustRes_getResMap(SourceFile_fullPath);//res_map["fullpath"],["height"],["width"] + CustRes_height=Res_map["height"].toInt(); + CustRes_width=Res_map["width"].toInt(); + } + //================= + QString AudioPath = file_path+"/Audio_"+file_name+"_"+file_ext+"_W2xEX.wav";//音频 + QString SplitFramesFolderPath = file_path+"/"+file_name+"_"+file_ext+"_SplitFrames_W2xEX";//拆分后存储frame的文件夹 + QString ScaledFramesFolderPath = SplitFramesFolderPath+"/ScaledFrames_W2xEX";//存储放大后的帧 + //=== + QString VideoClipsFolderPath = "";//存储视频片段的文件夹(完整路径) + QString DateStr = ""; + do + { + DateStr = video_getClipsFolderNo(); + VideoClipsFolderPath = file_path+"/"+DateStr+"_VideoClipsWaifu2xEX";//存储视频片段的文件夹(完整路径) + } + while(file_isDirExist(VideoClipsFolderPath)); + QString VideoClipsFolderName = DateStr+"_VideoClipsWaifu2xEX";//存储视频片段的文件夹(名称) + //========================== + // 检测之前的视频配置文件 + //========================== + QString VideoConfiguration_fullPath = file_path+"/VideoConfiguration_"+file_name+"_"+file_ext+"_Waifu2xEX.ini"; + if(QFile::exists(VideoConfiguration_fullPath)) + { + QSettings *configIniRead = new QSettings(VideoConfiguration_fullPath, QSettings::IniFormat); + configIniRead->setIniCodec(QTextCodec::codecForName("UTF-8")); + //=================== 加载之前存储的视频信息 ========================= + int ScaleRatio_old = configIniRead->value("/VideoConfiguration/ScaleRatio").toInt(); + bool CustRes_isEnabled_old = configIniRead->value("/VideoConfiguration/CustRes_isEnabled").toBool(); + int CustRes_height_old = configIniRead->value("/VideoConfiguration/CustRes_height").toInt(); + int CustRes_width_old = configIniRead->value("/VideoConfiguration/CustRes_width").toInt(); + QString EngineName_old = configIniRead->value("/VideoConfiguration/EngineName").toString(); + bool isProcessBySegment_old = configIniRead->value("/VideoConfiguration/isProcessBySegment").toBool(); + bool isVideoFrameInterpolationEnabled_old = configIniRead->value("/VideoConfiguration/isVideoFrameInterpolationEnabled").toBool(); + int MultipleOfFPS_old = configIniRead->value("/VideoConfiguration/MultipleOfFPS").toInt(); + //=================== 比对信息 ================================ + if(EngineName_old=="realsr-ncnn-vulkan") + { + if(CustRes_isEnabled_old==false&&CustRes_isEnabled==false) + { + if(ScaleRatio_old!=ScaleRatio) + { + isVideoConfigChanged=true; + } + else + { + isVideoConfigChanged=false; + } + } + else + { + if(CustRes_isEnabled_old==true&&CustRes_isEnabled==true) + { + if(CustRes_height_old!=CustRes_height||CustRes_width_old!=CustRes_width) + { + isVideoConfigChanged=true; + } + else + { + isVideoConfigChanged=false; + } + } + else + { + isVideoConfigChanged=true; + } + } + if(isProcessBySegment_old == false) + { + isVideoConfigChanged=true; + } + if(isVideoFrameInterpolationEnabled_old != ui->groupBox_FrameInterpolation->isChecked()) + { + isVideoConfigChanged=true; + } + if(MultipleOfFPS_old != ui->spinBox_MultipleOfFPS_VFI->value() && ui->groupBox_FrameInterpolation->isChecked()) + { + isVideoConfigChanged=true; + } + } + else + { + isVideoConfigChanged=true; + } + //============ 修正文件夹名称 ============= + QString VideoClipsFolderPath_old = configIniRead->value("/VideoConfiguration/VideoClipsFolderPath").toString(); + QString VideoClipsFolderName_old = configIniRead->value("/VideoConfiguration/VideoClipsFolderName").toString(); + file_mkDir(VideoClipsFolderPath_old); + if(file_isDirExist(VideoClipsFolderPath_old)==true) + { + VideoClipsFolderPath = VideoClipsFolderPath_old; + VideoClipsFolderName = VideoClipsFolderName_old; + } + } + else + { + emit Send_video_write_VideoConfiguration(VideoConfiguration_fullPath,ScaleRatio,0,CustRes_isEnabled,CustRes_height,CustRes_width,"realsr-ncnn-vulkan",true,VideoClipsFolderPath,VideoClipsFolderName,ui->groupBox_FrameInterpolation->isChecked(),ui->spinBox_MultipleOfFPS_VFI->value()); + } + //======================= + // 检测缓存是否存在 + //======================= + if(file_isDirExist(SplitFramesFolderPath)) + { + if(!isVideoConfigChanged) + { + isCacheExists=true; + emit Send_TextBrowser_NewMessage(tr("The previous video cache file is detected and processing of the previous video cache will continue. If you want to restart processing of the current video:[")+SourceFile_fullPath+tr("], delete the cache manually.")); + } + else + { + isCacheExists=false; + //======== + QFile::remove(VideoConfiguration_fullPath); + file_DelDir(SplitFramesFolderPath); + file_DelDir(VideoClipsFolderPath); + QFile::remove(AudioPath); + DelVfiDir(video_mp4_fullpath); + emit Send_video_write_VideoConfiguration(VideoConfiguration_fullPath,ScaleRatio,0,CustRes_isEnabled,CustRes_height,CustRes_width,"realsr-ncnn-vulkan",true,VideoClipsFolderPath,VideoClipsFolderName,ui->groupBox_FrameInterpolation->isChecked(),ui->spinBox_MultipleOfFPS_VFI->value()); + //======= + emit Send_TextBrowser_NewMessage(tr("The previous video cache file was detected, but because you changed the settings about the video resolution, the previous cache will be deleted and processing of the video:[")+SourceFile_fullPath+tr("] will restart.")); + } + } + else + { + isCacheExists=false; + //======== + QFile::remove(VideoConfiguration_fullPath); + file_DelDir(SplitFramesFolderPath); + file_DelDir(VideoClipsFolderPath); + QFile::remove(AudioPath); + DelVfiDir(video_mp4_fullpath); + emit Send_video_write_VideoConfiguration(VideoConfiguration_fullPath,ScaleRatio,0,CustRes_isEnabled,CustRes_height,CustRes_width,"realsr-ncnn-vulkan",true,VideoClipsFolderPath,VideoClipsFolderName,ui->groupBox_FrameInterpolation->isChecked(),ui->spinBox_MultipleOfFPS_VFI->value()); + //======== + } + /*==================================== + 提取音频 + ======================================*/ + if(!QFile::exists(AudioPath)) + { + video_get_audio(video_mp4_fullpath,AudioPath); + } + //================================== 开始分段处理视频 ================================================= + int StartTime = 0;//起始时间(秒) + int VideoDuration = video_get_duration(video_mp4_fullpath); + bool isSplitComplete = false; + bool isScaleComplete = false; + /* + ============================================ + 开始之前先读取进度 + ============================================ + */ + int OLD_SegmentDuration=-1; + bool read_OLD_SegmentDuration =false; + int LastVideoClipNo = -1; + if(QFile::exists(VideoConfiguration_fullPath)) + { + QSettings *configIniRead = new QSettings(VideoConfiguration_fullPath, QSettings::IniFormat); + configIniRead->setIniCodec(QTextCodec::codecForName("UTF-8")); + //=================== 加载进度 ========================= + StartTime = configIniRead->value("/Progress/StartTime").toInt(); + isSplitComplete = configIniRead->value("/Progress/isSplitComplete").toBool(); + isScaleComplete = configIniRead->value("/Progress/isScaleComplete").toBool(); + OLD_SegmentDuration = configIniRead->value("/Progress/OLDSegmentDuration").toInt(); + LastVideoClipNo = configIniRead->value("/Progress/LastVideoClipNo").toInt(); + } + if(OLD_SegmentDuration>0) + { + read_OLD_SegmentDuration = true; + } + /* + 加载进度条 + */ + int SegmentDuration_tmp_progressbar = 0; + if(read_OLD_SegmentDuration) + { + SegmentDuration_tmp_progressbar = OLD_SegmentDuration; + } + else + { + SegmentDuration_tmp_progressbar = SegmentDuration; + } + if(ui->checkBox_ShowInterPro->isChecked()&&VideoDuration>SegmentDuration_tmp_progressbar) + { + emit Send_CurrentFileProgress_Start(file_name+"."+file_ext,VideoDuration); + if(StartTime>0) + { + emit Send_CurrentFileProgress_progressbar_Add_SegmentDuration(StartTime); + } + } + /* + ============================================ + 正式开始处理 + ============================================ + */ + int SegmentDuration_tmp=0; + int TimeLeft_tmp=0; + while(VideoDuration>StartTime) + { + /*========================== + 计算视频片段时间 + ==========================*/ + TimeLeft_tmp = VideoDuration-StartTime; + if((TimeLeft_tmp)>=SegmentDuration) + { + SegmentDuration_tmp = SegmentDuration; + } + else + { + SegmentDuration_tmp = TimeLeft_tmp; + } + if(read_OLD_SegmentDuration) + { + SegmentDuration_tmp = OLD_SegmentDuration; + read_OLD_SegmentDuration=false; + } + /*========================== + 拆分视频片段 + ==========================*/ + if(isSplitComplete==false) + { + if(file_isDirExist(SplitFramesFolderPath)) + { + file_DelDir(SplitFramesFolderPath); + file_mkDir(SplitFramesFolderPath); + } + else + { + file_mkDir(SplitFramesFolderPath); + } + video_video2images_ProcessBySegment(video_mp4_fullpath,SplitFramesFolderPath,StartTime,SegmentDuration_tmp); + if(waifu2x_STOP) + { + emit Send_Table_video_ChangeStatus_rowNumInt_statusQString(rowNum, "Interrupted"); + return 0;//如果启用stop位,则直接return + } + } + /*========================== + 处理视频片段的帧 + ==========================*/ + bool isOverScaled=false; + if(isScaleComplete==false) + { + //============================== 扫描获取文件名 =============================== + QStringList Frame_fileName_list = file_getFileNames_in_Folder_nofilter(SplitFramesFolderPath); + if(isSplitComplete==false) + { + if(Frame_fileName_list.isEmpty())//检查是否成功拆分为帧 + { + emit Send_TextBrowser_NewMessage(tr("Error occured when processing [")+SourceFile_fullPath+tr("]. Error: [Unable to split video into pictures.]")); + emit Send_Table_video_ChangeStatus_rowNumInt_statusQString(rowNum, "Failed"); + emit Send_progressbar_Add(); + return 0;//如果启用stop位,则直接return + } + } + /* + 记录进度 + 帧拆分成功 + */ + emit Send_video_write_Progress_ProcessBySegment(VideoConfiguration_fullPath,StartTime,true,false,SegmentDuration_tmp,LastVideoClipNo); + //============================== 放大 ======================================= + //===========建立存储放大后frame的文件夹=========== + if(isSplitComplete==false) + { + if(file_isDirExist(ScaledFramesFolderPath)) + { + file_DelDir(ScaledFramesFolderPath); + file_mkDir(ScaledFramesFolderPath); + } + else + { + file_mkDir(ScaledFramesFolderPath); + } + } + //==========开始放大========================== + //读取放大倍数 + int ScaleRatio_Original = 2; + if(CustRes_isEnabled == true) + { + ScaleRatio_Original = CustRes_CalNewScaleRatio(video_mp4_fullpath,CustRes_height,CustRes_width); + } + else + { + ScaleRatio_Original = ui->doubleSpinBox_ScaleRatio_video->value(); + } + int ScaleRatio_Max=Calculate_Temporary_ScaleRatio_RealsrNCNNVulkan(ScaleRatio_Original); + isOverScaled = (ScaleRatio_Max!=ScaleRatio_Original); + //读取初始放大倍率 + int Initial_ScaleRatio = 4; + if(!Frame_fileName_list.isEmpty()) + { + QString Full_Path_File = ""; + for(int i = 0; i < Frame_fileName_list.size(); i++) + { + QString tmp = Frame_fileName_list.at(i); + Full_Path_File = SplitFramesFolderPath + "/" + tmp; + QFileInfo finfo(Full_Path_File); + if(finfo.suffix()=="png")break; + } + QImage qimage_original; + qimage_original.load(Full_Path_File); + int Frame_height = qimage_original.height(); + QMap res_map = video_get_Resolution(SourceFile_fullPath); + int Video_height = res_map["height"]; + if(Frame_height>0 && Video_height>0 && Frame_height>=Video_height)//判断是否读取失败 + { + Initial_ScaleRatio = 4*(Frame_height/Video_height); + } + } + //初始化进度讯息 + int NumOfSplitFrames = Frame_fileName_list.size()+file_getFileNames_in_Folder_nofilter(ScaledFramesFolderPath).size(); + int CurrentFileProgress_MAX = 0; + int CurrentFileProgress_OLD = 0; + int CurrentFileProgress_New = 0; + if(ui->checkBox_ShowInterPro->isChecked()) + { + int NumOfRounds=0; + for(int ScaleRatio_Current_tmp=Initial_ScaleRatio; ScaleRatio_Current_tmp<=ScaleRatio_Max; ScaleRatio_Current_tmp*=4) + { + NumOfRounds++; + } + CurrentFileProgress_MAX =NumOfSplitFrames*NumOfRounds; + } + //读取配置讯息 + QString Realsr_NCNN_Vulkan_Settings_str = Realsr_NCNN_Vulkan_ReadSettings_Video_GIF(ui->spinBox_ThreadNum_video_internal->value()); + QProcess *Waifu2x = new QProcess(); + QString program = Current_Path+"/realsr-ncnn-vulkan/realsr-ncnn-vulkan_waifu2xEX.exe"; + bool waifu2x_qprocess_failed = false; + int CountFinishedRounds=0; + //==== + for(int ScaleRatio_Current_tmp=Initial_ScaleRatio; ScaleRatio_Current_tmp<=ScaleRatio_Max && Frame_fileName_list.isEmpty()==false; ScaleRatio_Current_tmp*=4) + { + for(int retry=0; retry<(ui->spinBox_retry->value()+ForceRetryCount); retry++) + { + QString ErrorMSG=""; + QString StanderMSG=""; + //========== + waifu2x_qprocess_failed = false; + QString cmd = "\"" + program + "\"" + " -i " + "\"" + SplitFramesFolderPath + "\"" + " -o " + "\"" + ScaledFramesFolderPath + "\"" + " -s 4 " + Realsr_NCNN_Vulkan_Settings_str; + Waifu2x->start(cmd); + while(!Waifu2x->waitForStarted(100)&&!QProcess_stop) {} + while(!Waifu2x->waitForFinished(650)&&!QProcess_stop) + { + if(waifu2x_STOP) + { + QStringList FinfishedFileList_FileNames = WaitForEngineIO_NcnnVulkan(ScaledFramesFolderPath); + Waifu2x->close(); + //============ + QString file_name_tmp; + QStringList FileNames_ScaledFramesFolderPath = file_getFileNames_in_Folder_nofilter(ScaledFramesFolderPath); + for(int i=0; ireadAllStandardError().toLower()); + StanderMSG.append(Waifu2x->readAllStandardOutput().toLower()); + if(ErrorMSG.contains("failed")||StanderMSG.contains("failed")) + { + waifu2x_qprocess_failed = true; + Waifu2x->close(); + break; + } + if(ui->checkBox_ShowInterPro->isChecked()) + { + CurrentFileProgress_New = (NumOfSplitFrames*CountFinishedRounds)+file_getFileNames_in_Folder_nofilter(ScaledFramesFolderPath).size(); + if(CurrentFileProgress_New!=CurrentFileProgress_OLD) + { + emit Send_TextBrowser_NewMessage(tr("File name:[")+SourceFile_fullPath+tr("] Scale progress:[")+QString::number(CurrentFileProgress_New,10)+"/"+QString::number(CurrentFileProgress_MAX,10)+tr("] Duration progress:[")+QString::number(StartTime,10)+"s/"+QString::number(VideoDuration,10)+"s]"); + CurrentFileProgress_OLD=CurrentFileProgress_New; + } + } + } + //=============== + if(waifu2x_qprocess_failed==false) + { + ErrorMSG.append(Waifu2x->readAllStandardError().toLower()); + StanderMSG.append(Waifu2x->readAllStandardOutput().toLower()); + if(ErrorMSG.contains("failed")||StanderMSG.contains("failed")) + { + waifu2x_qprocess_failed = true; + } + } + //========= 检测是否成功,是否需要重试 ============ + if((NumOfSplitFrames == file_getFileNames_in_Folder_nofilter(ScaledFramesFolderPath).size())&&!waifu2x_qprocess_failed) + { + break; + } + else + { + //失败 + file_DelDir(ScaledFramesFolderPath); + file_mkDir(ScaledFramesFolderPath); + if(retry==ui->spinBox_retry->value()+(ForceRetryCount-1))break; + emit Send_TextBrowser_NewMessage(tr("Automatic retry, please wait.")); + Delay_sec_sleep(5); + } + } + //=========== + //根据轮数修改参数 + if(ScaleRatio_Current_tmpcheckBox_ShowInterPro->isChecked()) + { + emit Send_CurrentFileProgress_progressbar_Add_SegmentDuration(SegmentDuration_tmp); + } + StartTime+=SegmentDuration_tmp; + isSplitComplete = false; + isScaleComplete = false; + LastVideoClipNo=VideoClipNo; + emit Send_video_write_Progress_ProcessBySegment(VideoConfiguration_fullPath,StartTime,false,false,-1,VideoClipNo); + } + emit Send_CurrentFileProgress_Stop(); + //====================================================== + // 组装(片段到成片) + //====================================================== + QString video_mp4_scaled_fullpath = ""; + if(CustRes_isEnabled) + { + video_mp4_scaled_fullpath = file_path+"/"+file_name+"_waifu2x_"+QString::number(CustRes_width,10)+"x"+QString::number(CustRes_height,10)+"_"+file_ext+".mp4"; + } + else + { + video_mp4_scaled_fullpath = file_path+"/"+file_name+"_waifu2x_"+QString::number(ScaleRatio,10)+"x_"+file_ext+".mp4"; + } + QFile::remove(video_mp4_scaled_fullpath); + video_AssembleVideoClips(VideoClipsFolderPath,VideoClipsFolderName,video_mp4_scaled_fullpath,AudioPath); + if(QFile::exists(video_mp4_scaled_fullpath)==false)//检查是否成功生成视频 + { + if(waifu2x_STOP) + { + emit Send_Table_video_ChangeStatus_rowNumInt_statusQString(rowNum, "Interrupted"); + return 0;//如果启用stop位,则直接return + } + emit Send_TextBrowser_NewMessage(tr("Error occured when processing [")+SourceFile_fullPath+tr("]. Error: [Unable to assemble video clips.]")); + emit Send_Table_video_ChangeStatus_rowNumInt_statusQString(rowNum, "Failed"); + emit Send_progressbar_Add(); + return 0;//如果启用stop位,则直接return + } + //============================== 删除缓存文件 ==================================================== + if(ui->checkBox_KeepVideoCache->isChecked()==false) + { + QFile::remove(VideoConfiguration_fullPath); + file_DelDir(SplitFramesFolderPath); + file_DelDir(VideoClipsFolderPath); + QFile::remove(AudioPath); + if(SourceFile_fullPath!=video_mp4_fullpath)QFile::remove(video_mp4_fullpath); + } + else + { + DelOriginal=false; + } + //============================= 删除原文件 & & 更新table status ============================ + if(DelOriginal) + { + if(ReplaceOriginalFile(SourceFile_fullPath,video_mp4_scaled_fullpath)==false) + { + if(QAction_checkBox_MoveToRecycleBin_checkBox_DelOriginal->isChecked()) + { + file_MoveToTrash(SourceFile_fullPath); + } + else + { + QFile::remove(SourceFile_fullPath); + } + } + emit Send_Table_video_ChangeStatus_rowNumInt_statusQString(rowNum, "Finished, original file deleted"); + } + else + { + emit Send_Table_video_ChangeStatus_rowNumInt_statusQString(rowNum, "Finished"); + } + //========== 移动到输出路径 ========= + if(ui->checkBox_OutPath_isEnabled->isChecked()) + { + MoveFileToOutputPath(video_mp4_scaled_fullpath,SourceFile_fullPath); + } + //============================ 更新进度条 ================================= + emit Send_progressbar_Add(); + //=========================== ============================== + return 0; +} + + +/* +Realsr_NCNN_Vulkan +预读取引擎配置 +*/ +QString MainWindow::Realsr_NCNN_Vulkan_PreLoad_Settings() +{ + QString Realsr_NCNN_Vulkan_Settings_str = " "; + if(ui->checkBox_MultiGPU_RealsrNcnnVulkan->isChecked()==false) + { + //==========单显卡========== + //GPU ID + if(ui->comboBox_GPUID_RealsrNCNNVulkan->currentText()!="auto") + { + Realsr_NCNN_Vulkan_Settings_str.append("-g "+ui->comboBox_GPUID_RealsrNCNNVulkan->currentText()+" "); + } + //Tile Size + Realsr_NCNN_Vulkan_Settings_str.append("-t "+QString::number(ui->spinBox_TileSize_RealsrNCNNVulkan->value(),10)+" "); + } + //TTA + if(ui->checkBox_TTA_RealsrNCNNVulkan->isChecked()) + { + Realsr_NCNN_Vulkan_Settings_str.append("-x "); + } + //Model + QString Waifu2x_folder_path = Current_Path+"/realsr-ncnn-vulkan"; + switch(ui->comboBox_Model_RealsrNCNNVulkan->currentIndex()) + { + case 0: + { + Realsr_NCNN_Vulkan_Settings_str.append("-m \""+Waifu2x_folder_path+"/models-DF2K_JPEG\" "); + break; + } + case 1: + { + Realsr_NCNN_Vulkan_Settings_str.append("-m \""+Waifu2x_folder_path+"/models-DF2K\" "); + break; + } + } + Realsr_NCNN_Vulkan_Settings_str.append("-j 1:1:1 "); + //======================================= + return Realsr_NCNN_Vulkan_Settings_str; +} +/* +Realsr_NCNN_Vulkan +读取配置生成配置QString +*/ +QString MainWindow::Realsr_NCNN_Vulkan_ReadSettings() +{ + QString Realsr_NCNN_Vulkan_Settings_str = ""; + Realsr_NCNN_Vulkan_Settings_str.append(Realsr_NCNN_Vulkan_PreLoad_Settings_Str); + if(ui->checkBox_MultiGPU_RealsrNcnnVulkan->isChecked()) + { + //==========多显卡========== + QMap GPUInfo = RealsrNcnnVulkan_MultiGPU(); + //GPU ID + Realsr_NCNN_Vulkan_Settings_str.append("-g "+GPUInfo["ID"]+" "); + //Tile Size + Realsr_NCNN_Vulkan_Settings_str.append("-t "+GPUInfo["TileSize"]+" "); + } + //======================================= + return Realsr_NCNN_Vulkan_Settings_str; +} + +/* +================================================================================ + Realsr NCNN Vulkan 检测可用GPU +================================================================================= +*/ +/* +点击检测gpu按键时: +*/ +void MainWindow::on_pushButton_DetectGPU_RealsrNCNNVulkan_clicked() +{ + //==== + ui->pushButton_DetectGPU_RealsrNCNNVulkan->setText(tr("Detecting, please wait...")); + //==== + pushButton_Start_setEnabled_self(0); + ui->pushButton_DetectGPU->setEnabled(0); + ui->pushButton_DetectGPUID_srmd->setEnabled(0); + ui->pushButton_DumpProcessorList_converter->setEnabled(0); + ui->pushButton_ListGPUs_Anime4k->setEnabled(0); + ui->pushButton_compatibilityTest->setEnabled(0); + ui->pushButton_DetectGPU_RealsrNCNNVulkan->setEnabled(0); + Available_GPUID_Realsr_ncnn_vulkan.clear(); + QtConcurrent::run(this, &MainWindow::Realsr_ncnn_vulkan_DetectGPU); +} +/* +检测可用GPU ID中: +*/ +int MainWindow::Realsr_ncnn_vulkan_DetectGPU() +{ + emit Send_TextBrowser_NewMessage(tr("Detecting available GPU, please wait.")); + //=============== + QString InputPath = Current_Path + "/Compatibility_Test/Compatibility_Test.jpg"; + QString OutputPath = Current_Path + "/Compatibility_Test/res.png"; + QFile::remove(OutputPath); + //============== + QString Waifu2x_folder_path = Current_Path + "/realsr-ncnn-vulkan"; + QString program = Waifu2x_folder_path + "/realsr-ncnn-vulkan_waifu2xEX.exe"; + QString model_path = Waifu2x_folder_path+"/models-DF2K_JPEG"; + //=========== + int GPU_ID=-1; + //========= + while(true) + { + QFile::remove(OutputPath); + QProcess *Waifu2x = new QProcess(); + QString gpu_str = " -g "+QString::number(GPU_ID,10)+" "; + QString cmd = "\"" + program + "\"" + " -i " + "\"" + InputPath + "\"" + " -o " + "\"" + OutputPath + "\"" + " -s 4 -t 32 -m " + "\"" + model_path + "\" -g "+QString::number(GPU_ID,10); + Waifu2x->start(cmd); + while(!Waifu2x->waitForStarted(100)&&!QProcess_stop) {} + while(!Waifu2x->waitForFinished(100)&&!QProcess_stop) {} + if(QFile::exists(OutputPath) && (Waifu2x->readAllStandardError().toLower().contains("failed")||Waifu2x->readAllStandardOutput().toLower().contains("failed"))==false) + { + Available_GPUID_Realsr_ncnn_vulkan.append(QString::number(GPU_ID,10)); + GPU_ID++; + QFile::remove(OutputPath); + } + else + { + if(GPU_ID > -1) + { + break; + } + else + { + GPU_ID++; + } + } + } + QFile::remove(OutputPath); + //=============== + emit Send_TextBrowser_NewMessage(tr("Detection is complete!")); + if(Available_GPUID_Realsr_ncnn_vulkan.isEmpty()) + { + Send_TextBrowser_NewMessage(tr("No available GPU ID detected!")); + } + emit Send_Realsr_ncnn_vulkan_DetectGPU_finished(); + return 0; +} +/* +检测完成,向可用gpu列表和多显卡列表内填充数据: +*/ +int MainWindow::Realsr_ncnn_vulkan_DetectGPU_finished() +{ + pushButton_Start_setEnabled_self(1); + ui->pushButton_DetectGPU->setEnabled(1); + ui->pushButton_compatibilityTest->setEnabled(1); + ui->pushButton_DetectGPUID_srmd->setEnabled(1); + ui->pushButton_DumpProcessorList_converter->setEnabled(1); + on_checkBox_SpecifyGPU_Anime4k_stateChanged(1); + ui->pushButton_DetectGPU_RealsrNCNNVulkan->setEnabled(1); + //==== + GPUIDs_List_MultiGPU_RealsrNcnnVulkan.clear(); + ui->comboBox_GPUIDs_MultiGPU_RealsrNcnnVulkan->clear(); + //=== + ui->comboBox_GPUID_RealsrNCNNVulkan->clear(); + ui->comboBox_GPUID_RealsrNCNNVulkan->addItem("auto"); + if(!Available_GPUID_Realsr_ncnn_vulkan.isEmpty()) + { + for(int i=0; icomboBox_GPUID_RealsrNCNNVulkan->addItem(Available_GPUID_Realsr_ncnn_vulkan.at(i)); + AddGPU_MultiGPU_RealsrNcnnVulkan(Available_GPUID_Realsr_ncnn_vulkan.at(i)); + } + } + //==== + ui->pushButton_DetectGPU_RealsrNCNNVulkan->setText(tr("Detect available GPU ID")); + //==== + return 0; +} +/* +RealsrNcnnVulkan_MultiGPU +向Realsr_NCNN_Vulkan_ReadSettings()提交显卡信息. +通过 轮流提交显卡信息+多线程 一起实现多显卡 +*/ +QMap MainWindow::RealsrNcnnVulkan_MultiGPU() +{ + MultiGPU_QMutex_RealsrNcnnVulkan.lock(); + //==== + int MAX_GPU_ID_RealsrNcnnVulkan = GPUIDs_List_MultiGPU_RealsrNcnnVulkan.size()-1; + if(GPU_ID_RealsrNcnnVulkan_MultiGPU>MAX_GPU_ID_RealsrNcnnVulkan) + { + GPU_ID_RealsrNcnnVulkan_MultiGPU=0; + } + //====== + QMap GPUInfo; + do + { + GPUInfo = GPUIDs_List_MultiGPU_RealsrNcnnVulkan.at(GPU_ID_RealsrNcnnVulkan_MultiGPU); + if(GPUInfo["isEnabled"] != "true") + { + GPU_ID_RealsrNcnnVulkan_MultiGPU++; + if(GPU_ID_RealsrNcnnVulkan_MultiGPU>MAX_GPU_ID_RealsrNcnnVulkan) + { + GPU_ID_RealsrNcnnVulkan_MultiGPU=0; + } + } + else + { + break; + } + } + while(true); + //====== + GPU_ID_RealsrNcnnVulkan_MultiGPU++; + if(GPU_ID_RealsrNcnnVulkan_MultiGPU>MAX_GPU_ID_RealsrNcnnVulkan) + { + GPU_ID_RealsrNcnnVulkan_MultiGPU=0; + } + //====== + MultiGPU_QMutex_RealsrNcnnVulkan.unlock(); + return GPUInfo; +} +/* +向多显卡的显卡信息列表中添加显卡信息 +*/ +void MainWindow::AddGPU_MultiGPU_RealsrNcnnVulkan(QString GPUID) +{ + QMap GPUInfo; + GPUInfo["ID"] = GPUID; + GPUInfo["isEnabled"] = "true"; + GPUInfo["TileSize"] = "100"; + GPUIDs_List_MultiGPU_RealsrNcnnVulkan.append(GPUInfo); + ui->comboBox_GPUIDs_MultiGPU_RealsrNcnnVulkan->addItem(GPUID); + ui->comboBox_GPUIDs_MultiGPU_RealsrNcnnVulkan->setCurrentIndex(0); +} + +void MainWindow::on_checkBox_MultiGPU_RealsrNcnnVulkan_stateChanged(int arg1) +{ + if(ui->checkBox_MultiGPU_RealsrNcnnVulkan->isChecked()) + { + ui->comboBox_GPUID_RealsrNCNNVulkan->setEnabled(0); + ui->frame_TileSize_RealsrNcnnVulkan->setEnabled(0); + ui->groupBox_GPUSettings_MultiGPU_RealsrNcnnVulkan->setEnabled(1); + } + else + { + ui->comboBox_GPUID_RealsrNCNNVulkan->setEnabled(1); + ui->frame_TileSize_RealsrNcnnVulkan->setEnabled(1); + ui->groupBox_GPUSettings_MultiGPU_RealsrNcnnVulkan->setEnabled(0); + } +} + +void MainWindow::on_checkBox_MultiGPU_RealsrNcnnVulkan_clicked() +{ + if(ui->checkBox_MultiGPU_RealsrNcnnVulkan->isChecked()) + { + if(GPUIDs_List_MultiGPU_RealsrNcnnVulkan.size()==0) + { + QMessageBox *MSG = new QMessageBox(); + MSG->setWindowTitle(tr("Notification")); + MSG->setText(tr("Please detect available GPU ID before enable Multi-GPU.")); + MSG->setIcon(QMessageBox::Information); + MSG->setModal(true); + MSG->show(); + ui->checkBox_MultiGPU_RealsrNcnnVulkan->setChecked(0); + return; + } + if(GPUIDs_List_MultiGPU_RealsrNcnnVulkan.size()<2) + { + QMessageBox *MSG = new QMessageBox(); + MSG->setWindowTitle(tr("Error")); + MSG->setText(tr("Insufficient number of available GPUs.")); + MSG->setIcon(QMessageBox::Warning); + MSG->setModal(true); + MSG->show(); + ui->checkBox_MultiGPU_RealsrNcnnVulkan->setChecked(0); + return; + } + } +} + +void MainWindow::on_comboBox_GPUIDs_MultiGPU_RealsrNcnnVulkan_currentIndexChanged(int index) +{ + if(ui->comboBox_GPUIDs_MultiGPU_RealsrNcnnVulkan->count()==0) + { + return; + } + QMap GPUInfo=GPUIDs_List_MultiGPU_RealsrNcnnVulkan.at(ui->comboBox_GPUIDs_MultiGPU_RealsrNcnnVulkan->currentIndex()); + ui->checkBox_isEnable_CurrentGPU_MultiGPU_RealsrNcnnVulkan->setChecked(GPUInfo["isEnabled"] == "true"); + ui->spinBox_TileSize_CurrentGPU_MultiGPU_RealsrNcnnVulkan->setValue(GPUInfo["TileSize"].toInt()); +} + +void MainWindow::on_checkBox_isEnable_CurrentGPU_MultiGPU_RealsrNcnnVulkan_clicked() +{ + QMap GPUInfo=GPUIDs_List_MultiGPU_RealsrNcnnVulkan.at(ui->comboBox_GPUIDs_MultiGPU_RealsrNcnnVulkan->currentIndex()); + if(ui->checkBox_isEnable_CurrentGPU_MultiGPU_RealsrNcnnVulkan->isChecked()) + { + GPUInfo["isEnabled"] = "true"; + } + else + { + GPUInfo["isEnabled"] = "false"; + } + GPUIDs_List_MultiGPU_RealsrNcnnVulkan.replace(ui->comboBox_GPUIDs_MultiGPU_RealsrNcnnVulkan->currentIndex(),GPUInfo); + int enabledGPUs = 0; + for (int i=0; i GPUInfo_tmp = GPUIDs_List_MultiGPU_RealsrNcnnVulkan.at(i); + if(GPUInfo_tmp["isEnabled"] == "true") + { + enabledGPUs++; + } + } + if(enabledGPUs<2) + { + QMap GPUInfo=GPUIDs_List_MultiGPU_RealsrNcnnVulkan.at(ui->comboBox_GPUIDs_MultiGPU_RealsrNcnnVulkan->currentIndex()); + GPUInfo["isEnabled"] = "true"; + GPUIDs_List_MultiGPU_RealsrNcnnVulkan.replace(ui->comboBox_GPUIDs_MultiGPU_RealsrNcnnVulkan->currentIndex(),GPUInfo); + ui->checkBox_isEnable_CurrentGPU_MultiGPU_RealsrNcnnVulkan->setChecked(1); + QMessageBox *MSG = new QMessageBox(); + MSG->setWindowTitle(tr("Warning")); + MSG->setText(tr("At least 2 GPUs need to be enabled !!")); + MSG->setIcon(QMessageBox::Warning); + MSG->setModal(true); + MSG->show(); + } +} + +void MainWindow::on_spinBox_TileSize_CurrentGPU_MultiGPU_RealsrNcnnVulkan_valueChanged(int arg1) +{ + QMap GPUInfo=GPUIDs_List_MultiGPU_RealsrNcnnVulkan.at(ui->comboBox_GPUIDs_MultiGPU_RealsrNcnnVulkan->currentIndex()); + GPUInfo["TileSize"] = QString::number(ui->spinBox_TileSize_CurrentGPU_MultiGPU_RealsrNcnnVulkan->value(),10); + GPUIDs_List_MultiGPU_RealsrNcnnVulkan.replace(ui->comboBox_GPUIDs_MultiGPU_RealsrNcnnVulkan->currentIndex(),GPUInfo); +} + +void MainWindow::on_pushButton_ShowMultiGPUSettings_RealsrNcnnVulkan_clicked() +{ + int Max_GPU_ID = GPUIDs_List_MultiGPU_RealsrNcnnVulkan.size(); + QString MultiGPUSettings_str=""; + for(int GPU_ID=0; GPU_ID GPUInfo = GPUIDs_List_MultiGPU_RealsrNcnnVulkan.at(GPU_ID); + if(GPUInfo["isEnabled"] != "true") + { + continue; + } + else + { + MultiGPUSettings_str.append("GPU ID:["+GPUInfo["ID"]+"] | "+tr("Tile size:")+"["+GPUInfo["TileSize"]+"]\n\n"); + } + } + //========= + QMessageBox *MSG = new QMessageBox(); + MSG->setWindowTitle(tr("Current Multi-GPU settings")); + MSG->setText(MultiGPUSettings_str); + MSG->setIcon(QMessageBox::Information); + MSG->setModal(true); + MSG->show(); +} +/* +RealSR 块大小调整按钮 +*/ +void MainWindow::on_pushButton_Add_TileSize_RealsrNCNNVulkan_clicked() +{ + ui->spinBox_TileSize_RealsrNCNNVulkan->setValue(AddTileSize_NCNNVulkan_Converter(ui->spinBox_TileSize_RealsrNCNNVulkan->value())); +} + +void MainWindow::on_pushButton_Minus_TileSize_RealsrNCNNVulkan_clicked() +{ + ui->spinBox_TileSize_RealsrNCNNVulkan->setValue(MinusTileSize_NCNNVulkan_Converter(ui->spinBox_TileSize_RealsrNCNNVulkan->value())); +} + +/* +计算 临时放大倍率 +*/ +int MainWindow::Calculate_Temporary_ScaleRatio_RealsrNCNNVulkan(int ScaleRatio) +{ + int ScaleRatio_tmp=0; + //如果设定的scaleRatio不是偶数,则+1,并输出到tmp + if((ScaleRatio%2)==0) + { + ScaleRatio_tmp = ScaleRatio; + } + else + { + ScaleRatio_tmp = ScaleRatio+1; + } + //判断是否为4的幂数 + if((((ScaleRatio_tmp&(ScaleRatio_tmp-1))==0)&&(ScaleRatio_tmp&0x555555555))!=true) + { + for(int i=1; true; i++) + { + int pow_ =pow(4,i); + if(pow_>=ScaleRatio_tmp) + { + ScaleRatio_tmp=pow_; + break; + } + } + } + return ScaleRatio_tmp; +} + +/* +Realsr_NCNN_Vulkan +读取引擎配置 +*/ +QString MainWindow::Realsr_NCNN_Vulkan_ReadSettings_Video_GIF(int ThreadNum) +{ + QString Realsr_NCNN_Vulkan_Settings_str = " "; + if(ui->checkBox_MultiGPU_RealsrNcnnVulkan->isChecked()==false) + { + //==========单显卡========== + //GPU ID + if(ui->comboBox_GPUID_RealsrNCNNVulkan->currentText()!="auto") + { + Realsr_NCNN_Vulkan_Settings_str.append("-g "+ui->comboBox_GPUID_RealsrNCNNVulkan->currentText()+" "); + } + //Tile Size + Realsr_NCNN_Vulkan_Settings_str.append("-t "+QString::number(ui->spinBox_TileSize_RealsrNCNNVulkan->value(),10)+" "); + //线程数量 + QString jobs_num_str = QString("%1").arg(ThreadNum); + Realsr_NCNN_Vulkan_Settings_str.append("-j "+jobs_num_str+":"+jobs_num_str+":"+jobs_num_str+" "); + } + else + { + //==============多显卡================ + int NumOfGPUs_Available = GPUIDs_List_MultiGPU_RealsrNcnnVulkan.size();//获取显卡总数 + int NumOfGPUs_Enabled = 0; + QString GPU_ID_cmd = "-g "; + QString TileSize_cmd = "-t "; + for(int i=0; i GPUInfo = GPUIDs_List_MultiGPU_RealsrNcnnVulkan.at(i); + if(GPUInfo["isEnabled"] != "true")continue; + NumOfGPUs_Enabled++; + if(i==0) + { + GPU_ID_cmd.append(GPUInfo["ID"]); + TileSize_cmd.append(GPUInfo["TileSize"]); + } + else + { + GPU_ID_cmd.append(","+GPUInfo["ID"]); + TileSize_cmd.append(","+GPUInfo["TileSize"]); + } + } + Realsr_NCNN_Vulkan_Settings_str.append(GPU_ID_cmd+" "); + Realsr_NCNN_Vulkan_Settings_str.append(TileSize_cmd+" "); + //线程数量 + int NumOfThreads_PerGPU = ThreadNum/NumOfGPUs_Enabled; + if(NumOfThreads_PerGPU<1)NumOfThreads_PerGPU=1; + int LoadAndWrite_tnum = NumOfGPUs_Enabled*NumOfThreads_PerGPU; + QString Jobs_cmd = ""; + for(int i=0; icheckBox_TTA_RealsrNCNNVulkan->isChecked()) + { + Realsr_NCNN_Vulkan_Settings_str.append("-x "); + } + //Model + QString Waifu2x_folder_path = Current_Path+"/realsr-ncnn-vulkan"; + switch(ui->comboBox_Model_RealsrNCNNVulkan->currentIndex()) + { + case 0: + { + Realsr_NCNN_Vulkan_Settings_str.append("-m \""+Waifu2x_folder_path+"/models-DF2K_JPEG\" "); + break; + } + case 1: + { + Realsr_NCNN_Vulkan_Settings_str.append("-m \""+Waifu2x_folder_path+"/models-DF2K\" "); + break; + } + } + //======================================= + return Realsr_NCNN_Vulkan_Settings_str; +} +/* +放大 APNG +*/ +bool MainWindow::APNG_RealsrNCNNVulkan(QString splitFramesFolder,QString scaledFramesFolder,QString sourceFileFullPath,QStringList framesFileName_qStrList,QString resultFileFullPath) +{ + //生成文件夹 + file_DelDir(scaledFramesFolder); + file_mkDir(scaledFramesFolder); + //============================================================ + //开始放大 + //读取放大倍数 + int ScaleRatio_Original = 2; + if(CustRes_isContained(sourceFileFullPath)) + { + QMap Res_map = CustRes_getResMap(sourceFileFullPath);//res_map["fullpath"],["height"],["width"] + ScaleRatio_Original = CustRes_CalNewScaleRatio(sourceFileFullPath,Res_map["height"].toInt(),Res_map["width"].toInt()); + } + else + { + ScaleRatio_Original = ui->doubleSpinBox_ScaleRatio_gif->value(); + } + int ScaleRatio_Max=Calculate_Temporary_ScaleRatio_RealsrNCNNVulkan(ScaleRatio_Original); + bool isOverScaled = (ScaleRatio_Max!=ScaleRatio_Original); + //初始化进度讯息 + int NumOfSplitFrames = framesFileName_qStrList.size(); + if(ui->checkBox_ShowInterPro->isChecked()) + { + int NumOfRounds=0; + for(int ScaleRatio_Current_tmp=4; ScaleRatio_Current_tmp<=ScaleRatio_Max; ScaleRatio_Current_tmp*=4) + { + NumOfRounds++; + } + emit Send_CurrentFileProgress_Start(file_getBaseName(sourceFileFullPath)+"."+sourceFileFullPath.split(".").last(),NumOfSplitFrames*NumOfRounds); + } + //读取配置讯息 + QString Realsr_NCNN_Vulkan_Settings_str = Realsr_NCNN_Vulkan_ReadSettings_Video_GIF(ui->spinBox_ThreadNum_gif_internal->value()); + QProcess *Waifu2x = new QProcess(); + QString program = Current_Path+"/realsr-ncnn-vulkan/realsr-ncnn-vulkan_waifu2xEX.exe"; + bool waifu2x_qprocess_failed = false; + int CountFinishedRounds=0; + //==== + for(int ScaleRatio_Current_tmp=4; ScaleRatio_Current_tmp<=ScaleRatio_Max && framesFileName_qStrList.isEmpty()==false; ScaleRatio_Current_tmp*=4) + { + for(int retry=0; retry<(ui->spinBox_retry->value()+ForceRetryCount); retry++) + { + QString ErrorMSG=""; + QString StanderMSG=""; + //========== + waifu2x_qprocess_failed = false; + QString cmd = "\"" + program + "\"" + " -i " + "\"" + splitFramesFolder + "\"" + " -o " + "\"" + scaledFramesFolder + "\"" + " -s 4 " + Realsr_NCNN_Vulkan_Settings_str; + Waifu2x->start(cmd); + while(!Waifu2x->waitForStarted(100)&&!QProcess_stop) {} + while(!Waifu2x->waitForFinished(650)&&!QProcess_stop) + { + if(waifu2x_STOP) + { + Waifu2x->close(); + mutex_ThreadNumRunning.lock(); + ThreadNumRunning--; + mutex_ThreadNumRunning.unlock(); + return false; + } + ErrorMSG.append(Waifu2x->readAllStandardError().toLower()); + StanderMSG.append(Waifu2x->readAllStandardOutput().toLower()); + if(ErrorMSG.contains("failed")||StanderMSG.contains("failed")) + { + waifu2x_qprocess_failed = true; + Waifu2x->close(); + break; + } + if(ui->checkBox_ShowInterPro->isChecked()) + { + emit Send_CurrentFileProgress_progressbar_SetFinishedValue((NumOfSplitFrames*CountFinishedRounds)+file_getFileNames_in_Folder_nofilter(scaledFramesFolder).size()); + } + } + //=============== + if(waifu2x_qprocess_failed==false) + { + ErrorMSG.append(Waifu2x->readAllStandardError().toLower()); + StanderMSG.append(Waifu2x->readAllStandardOutput().toLower()); + if(ErrorMSG.contains("failed")||StanderMSG.contains("failed")) + { + waifu2x_qprocess_failed = true; + } + } + //========= 检测是否成功,是否需要重试 ============ + if((NumOfSplitFrames == file_getFileNames_in_Folder_nofilter(scaledFramesFolder).size())&&!waifu2x_qprocess_failed) + { + break; + } + else + { + //失败 + file_DelDir(scaledFramesFolder); + file_mkDir(scaledFramesFolder); + if(retry==ui->spinBox_retry->value()+(ForceRetryCount-1))break; + emit Send_TextBrowser_NewMessage(tr("Automatic retry, please wait.")); + Delay_sec_sleep(5); + } + } + //=========== + //根据轮数修改参数 + if(ScaleRatio_Current_tmp. - - My Github homepage: https://github.com/AaronFeng753 -*/ - -#include "mainwindow.h" -#include "ui_mainwindow.h" - -/* -保存设置 -删除原设置文件,保存设置 -*/ -int MainWindow::Settings_Save() -{ - QString settings_ini = Current_Path+"/settings.ini"; - QFile::remove(settings_ini); - //================= - QSettings *configIniWrite = new QSettings(settings_ini, QSettings::IniFormat); - configIniWrite->setIniCodec(QTextCodec::codecForName("UTF-8")); - //================= 添加警告 ========================= - configIniWrite->setValue("/Warning/.", "Do not modify this file! It may cause the program to crash! If problems occur after the modification, delete this file and restart the program."); - //==================== 存储版本识别 ================================== - configIniWrite->setValue("/settings/VERSION", VERSION); - //======= 存储放大值和降噪值 ================================= - configIniWrite->setValue("/settings/ImageScaleRatio", ui->doubleSpinBox_ScaleRatio_image->value()); - configIniWrite->setValue("/settings/GIFScaleRatio", ui->doubleSpinBox_ScaleRatio_gif->value()); - configIniWrite->setValue("/settings/VideoScaleRatio", ui->doubleSpinBox_ScaleRatio_video->value()); - configIniWrite->setValue("/settings/ImageDenoiseLevel", ui->spinBox_DenoiseLevel_image->value()); - configIniWrite->setValue("/settings/GIFDenoiseLevel", ui->spinBox_DenoiseLevel_gif->value()); - configIniWrite->setValue("/settings/VideoDenoiseLevel", ui->spinBox_DenoiseLevel_video->value()); - //============ 存储自定义宽度和高度及设置 ============================ - configIniWrite->setValue("/settings/CustResWidth", ui->spinBox_CustRes_width->value()); - configIniWrite->setValue("/settings/CustResHeight", ui->spinBox_CustRes_height->value()); - configIniWrite->setValue("/settings/CustResAspectRatioMode", ui->comboBox_AspectRatio_custRes->currentIndex()); - //============ 存储线程数量 ==================================== - configIniWrite->setValue("/settings/ImageThreadNum", ui->spinBox_ThreadNum_image->value()); - configIniWrite->setValue("/settings/GIFThreadNumInternal", ui->spinBox_ThreadNum_gif_internal->value()); - configIniWrite->setValue("/settings/VideoThreadNumInternal", ui->spinBox_ThreadNum_video_internal->value()); - //================== 存储引擎设置 ========================= - configIniWrite->setValue("/settings/ImageEngine", ui->comboBox_Engine_Image->currentIndex()); - configIniWrite->setValue("/settings/GIFEngine", ui->comboBox_Engine_GIF->currentIndex()); - configIniWrite->setValue("/settings/VideoEngine", ui->comboBox_Engine_Video->currentIndex()); - configIniWrite->setValue("/settings/ImageStyle", ui->comboBox_ImageStyle->currentIndex()); - configIniWrite->setValue("/settings/ModelVulkan", ui->comboBox_model_vulkan->currentIndex()); - configIniWrite->setValue("/settings/TileSize", ui->spinBox_TileSize->value()); - configIniWrite->setValue("/settings/BlockSizeConverter", ui->spinBox_BlockSize_converter->value()); - configIniWrite->setValue("/settings/DisableGPUConverter", ui->checkBox_DisableGPU_converter->isChecked()); - configIniWrite->setValue("/settings/ForceOpenCLConverter", ui->checkBox_ForceOpenCL_converter->isChecked()); - configIniWrite->setValue("/settings/TTAVulkan", ui->checkBox_TTA_vulkan->isChecked()); - configIniWrite->setValue("/settings/TTAConverter", ui->checkBox_TTA_converter->isChecked()); - configIniWrite->setValue("/settings/TTA_SRMD", ui->checkBox_TTA_srmd->isChecked()); - configIniWrite->setValue("/settings/TileSize_SRMD", ui->spinBox_TileSize_srmd->value()); - configIniWrite->setValue("/settings/Version_Waifu2xNCNNVulkan", ui->comboBox_version_Waifu2xNCNNVulkan->currentIndex()); - //=== - configIniWrite->setValue("/settings/TTA_Waifu2xCaffe", ui->checkBox_TTA_Waifu2xCaffe->isChecked()); - configIniWrite->setValue("/settings/Model_2D_Waifu2xCaffe", ui->comboBox_Model_2D_Waifu2xCaffe->currentIndex()); - configIniWrite->setValue("/settings/Model_3D_Waifu2xCaffe", ui->comboBox_Model_3D_Waifu2xCaffe->currentIndex()); - configIniWrite->setValue("/settings/ProcessMode_Waifu2xCaffe", ui->comboBox_ProcessMode_Waifu2xCaffe->currentIndex()); - configIniWrite->setValue("/settings/BatchSize_Waifu2xCaffe", ui->spinBox_BatchSize_Waifu2xCaffe->value()); - configIniWrite->setValue("/settings/GPUID_Waifu2xCaffe", ui->spinBox_GPUID_Waifu2xCaffe->value()); - configIniWrite->setValue("/settings/SplitSize_Waifu2xCaffe", ui->spinBox_SplitSize_Waifu2xCaffe->value()); - configIniWrite->setValue("/settings/checkBox_EnableMultiGPU_Waifu2xCaffe", ui->checkBox_EnableMultiGPU_Waifu2xCaffe->isChecked()); - configIniWrite->setValue("/settings/lineEdit_MultiGPUInfo_Waifu2xCaffe", ui->lineEdit_MultiGPUInfo_Waifu2xCaffe->text()); - //=== - configIniWrite->setValue("/settings/checkBox_TTA_RealsrNCNNVulkan", ui->checkBox_TTA_RealsrNCNNVulkan->isChecked()); - configIniWrite->setValue("/settings/comboBox_Model_RealsrNCNNVulkan", ui->comboBox_Model_RealsrNCNNVulkan->currentIndex()); - configIniWrite->setValue("/settings/spinBox_TileSize_RealsrNCNNVulkan", ui->spinBox_TileSize_RealsrNCNNVulkan->value()); - //GPU ID List - configIniWrite->setValue("/settings/CurrentGPUID_Waifu2xNCNNVulkan", ui->comboBox_GPUID->currentIndex()); - configIniWrite->setValue("/settings/Available_GPUID_Waifu2xNCNNVulkan", Available_GPUID); - configIniWrite->setValue("/settings/GPUIDs_List_MultiGPU_Waifu2xNCNNVulkan", QVariant::fromValue(GPUIDs_List_MultiGPU_Waifu2xNCNNVulkan)); - configIniWrite->setValue("/settings/checkBox_MultiGPU_Waifu2xNCNNVulkan", ui->checkBox_MultiGPU_Waifu2xNCNNVulkan->isChecked()); - //== - configIniWrite->setValue("/settings/comboBox_GPUID_RealsrNCNNVulkan", ui->comboBox_GPUID_RealsrNCNNVulkan->currentIndex()); - configIniWrite->setValue("/settings/Available_GPUID_Realsr_ncnn_vulkan", Available_GPUID_Realsr_ncnn_vulkan); - configIniWrite->setValue("/settings/GPUIDs_List_MultiGPU_RealsrNcnnVulkan", QVariant::fromValue(GPUIDs_List_MultiGPU_RealsrNcnnVulkan)); - configIniWrite->setValue("/settings/checkBox_MultiGPU_RealsrNcnnVulkan", ui->checkBox_MultiGPU_RealsrNcnnVulkan->isChecked()); - //== - configIniWrite->setValue("/settings/comboBox_TargetProcessor_converter", ui->comboBox_TargetProcessor_converter->currentIndex()); - configIniWrite->setValue("/settings/Available_ProcessorList_converter", Available_ProcessorList_converter); - configIniWrite->setValue("/settings/GPUIDs_List_MultiGPU_Waifu2xConverter", QVariant::fromValue(GPUIDs_List_MultiGPU_Waifu2xConverter)); - configIniWrite->setValue("/settings/checkBox_MultiGPU_Waifu2xConverter", ui->checkBox_MultiGPU_Waifu2xConverter->isChecked()); - //== - configIniWrite->setValue("/settings/comboBox_GPUID_srmd", ui->comboBox_GPUID_srmd->currentIndex()); - configIniWrite->setValue("/settings/Available_GPUID_srmd", Available_GPUID_srmd); - configIniWrite->setValue("/settings/GPUIDs_List_MultiGPU_SrmdNcnnVulkan", QVariant::fromValue(GPUIDs_List_MultiGPU_SrmdNcnnVulkan)); - configIniWrite->setValue("/settings/checkBox_MultiGPU_SrmdNCNNVulkan", ui->checkBox_MultiGPU_SrmdNCNNVulkan->isChecked()); - //================== 存储 扩展名 ================================= - configIniWrite->setValue("/settings/ImageEXT", ui->Ext_image->text()); - configIniWrite->setValue("/settings/VideoEXT", ui->Ext_video->text()); - //=================== 存储 杂项设置 ================================= - configIniWrite->setValue("/settings/checkBox_SummaryPopup", ui->checkBox_SummaryPopup->isChecked()); - configIniWrite->setValue("/settings/checkBox_DisableResize_gif", ui->checkBox_DisableResize_gif->isChecked()); - configIniWrite->setValue("/settings/checkBox_AutoSkip_CustomRes", ui->checkBox_AutoSkip_CustomRes->isChecked()); - configIniWrite->setValue("/settings/checkBox_AlwaysPreProcessAlphaPNG", ui->checkBox_AlwaysPreProcessAlphaPNG->isChecked()); - configIniWrite->setValue("/settings/spinBox_ImageQualityLevel", ui->spinBox_ImageQualityLevel->value()); - configIniWrite->setValue("/settings/comboBox_ImageSaveFormat", ui->comboBox_ImageSaveFormat->currentIndex()); - configIniWrite->setValue("/settings/checkBox_KeepParentFolder", ui->checkBox_KeepParentFolder->isChecked()); - configIniWrite->setValue("/settings/checkBox_BanGitee", ui->checkBox_BanGitee->isChecked()); - configIniWrite->setValue("/settings/comboBox_UpdateChannel", ui->comboBox_UpdateChannel->currentIndex()); - configIniWrite->setValue("/settings/checkBox_MinimizeToTaskbar", ui->checkBox_MinimizeToTaskbar->isChecked()); - configIniWrite->setValue("/settings/checkBox_custres_isAll", ui->checkBox_custres_isAll->isChecked()); - configIniWrite->setValue("/settings/DelOriginal", ui->checkBox_DelOriginal->isChecked()); - configIniWrite->setValue("/settings/OptGIF", ui->checkBox_OptGIF->isChecked()); - configIniWrite->setValue("/settings/NFSound", ui->checkBox_NfSound->isChecked()); - configIniWrite->setValue("/settings/ReProFinFiles", ui->checkBox_ReProcFinFiles->isChecked()); - configIniWrite->setValue("/settings/ShowInterPro", ui->checkBox_ShowInterPro->isChecked()); - configIniWrite->setValue("/settings/UpdatePopup", ui->checkBox_UpdatePopup->isChecked()); - configIniWrite->setValue("/settings/FileListAutoScroll", ui->checkBox_FileListAutoSlide->isChecked()); - configIniWrite->setValue("/settings/AutoSaveSettings", ui->checkBox_AutoSaveSettings->isChecked()); - configIniWrite->setValue("/settings/AlwaysHideSettings", ui->checkBox_AlwaysHideSettings->isChecked()); - configIniWrite->setValue("/settings/AlwaysHideTextBrowser", ui->checkBox_AlwaysHideTextBrowser->isChecked()); - configIniWrite->setValue("/settings/ScanSubFolders", ui->checkBox_ScanSubFolders->isChecked()); - configIniWrite->setValue("/settings/InteractiveFileList", ui->checkBox_FileList_Interactive->isChecked()); - configIniWrite->setValue("/settings/RetryTimes", ui->spinBox_retry->value()); - configIniWrite->setValue("/settings/AutoDetectAlphaChannel", ui->checkBox_AutoDetectAlphaChannel->isChecked()); - configIniWrite->setValue("/settings/PromptWhenExit", ui->checkBox_PromptWhenExit->isChecked()); - configIniWrite->setValue("/settings/KeepVideoCache", ui->checkBox_KeepVideoCache->isChecked()); - configIniWrite->setValue("/settings/checkBox_ReplaceOriginalFile", ui->checkBox_ReplaceOriginalFile->isChecked()); - //=== - configIniWrite->setValue("/settings/QAction_checkBox_MoveToRecycleBin_checkBox_ReplaceOriginalFile", QAction_checkBox_MoveToRecycleBin_checkBox_ReplaceOriginalFile->isChecked()); - //=== - configIniWrite->setValue("/settings/QAction_checkBox_MoveToRecycleBin_checkBox_DelOriginal", QAction_checkBox_MoveToRecycleBin_checkBox_DelOriginal->isChecked()); - //=== - configIniWrite->setValue("/settings/ProcessVideoBySegment", ui->checkBox_ProcessVideoBySegment->isChecked()); - configIniWrite->setValue("/settings/SegmentDuration", ui->spinBox_SegmentDuration->value()); - //===== - configIniWrite->setValue("/settings/AudioDenoise", ui->checkBox_AudioDenoise->isChecked()); - configIniWrite->setValue("/settings/AudioDenoiseLevel", ui->doubleSpinBox_AudioDenoiseLevel->value()); - //===== - configIniWrite->setValue("/settings/checkBox_PreProcessImage", ui->checkBox_PreProcessImage->isChecked()); - //===================== 存储 textbrowser 设置 ===================== - configIniWrite->setValue("/settings/TextBrowserFontSize", ui->spinBox_textbrowser_fontsize->value()); - //===================== 存储语言设置 ================================ - configIniWrite->setValue("/settings/Language", ui->comboBox_language->currentIndex()); - //================== 存储全局字体 ========================= - configIniWrite->setValue("/settings/GlobalFontSize", ui->spinBox_GlobalFontSize->value()); - configIniWrite->setValue("/settings/CustFont", ui->fontComboBox_CustFont->currentFont()); - configIniWrite->setValue("/settings/CustFont_isEnabled", ui->checkBox_isCustFontEnable->isChecked()); - //=================== 存储视频设置 =========================== - configIniWrite->setValue("/settings/VideoSettingsIsEnabled", ui->groupBox_video_settings->isChecked()); - configIniWrite->setValue("/settings/EncoderVideo", ui->lineEdit_encoder_vid->text()); - configIniWrite->setValue("/settings/EncoderAudio", ui->lineEdit_encoder_audio->text()); - configIniWrite->setValue("/settings/PixelFormat", ui->lineEdit_pixformat->text()); - configIniWrite->setValue("/settings/BitrateVideo", ui->spinBox_bitrate_vid->value()); - configIniWrite->setValue("/settings/BitrateAudio", ui->spinBox_bitrate_audio->value()); - configIniWrite->setValue("/settings/ExtraCommandOutput", ui->lineEdit_ExCommand_output->text()); - //=== - configIniWrite->setValue("/settings/BitrateVideo2mp4", ui->spinBox_bitrate_vid_2mp4->value()); - configIniWrite->setValue("/settings/BitrateAudio2mp4", ui->spinBox_bitrate_audio_2mp4->value()); - configIniWrite->setValue("/settings/vcodecCopy", ui->checkBox_vcodec_copy_2mp4->isChecked()); - configIniWrite->setValue("/settings/acodecCopy", ui->checkBox_acodec_copy_2mp4->isChecked()); - configIniWrite->setValue("/settings/checkBox_IgnoreFrameRateMode", ui->checkBox_IgnoreFrameRateMode->isChecked()); - configIniWrite->setValue("/settings/ExtraCommand2mp4", ui->lineEdit_ExCommand_2mp4->text()); - //==================== 存储输出路径设置 ======================== - configIniWrite->setValue("/settings/OutPutPath", ui->lineEdit_outputPath->text()); - configIniWrite->setValue("/settings/OutPutPathIsEnabled", ui->checkBox_OutPath_isEnabled->isChecked()); - configIniWrite->setValue("/settings/checkBox_OutPath_KeepOriginalFileName", ui->checkBox_OutPath_KeepOriginalFileName->isChecked()); - configIniWrite->setValue("/settings/checkBox_OutPath_Overwrite", ui->checkBox_OutPath_Overwrite->isChecked()); - configIniWrite->setValue("/settings/checkBox_AutoOpenOutputPath", ui->checkBox_AutoOpenOutputPath->isChecked()); - //=================== 存储Anime4k设置 ============================= - configIniWrite->setValue("/settings/spinBox_OpenCLCommandQueues_A4k", ui->spinBox_OpenCLCommandQueues_A4k->value()); - configIniWrite->setValue("/settings/checkBox_OpenCLParallelIO_A4k", ui->checkBox_OpenCLParallelIO_A4k->isChecked()); - configIniWrite->setValue("/settings/comboBox_GPGPUModel_A4k", ui->comboBox_GPGPUModel_A4k->currentIndex()); - configIniWrite->setValue("/settings/checkBox_HDNMode_Anime4k", ui->checkBox_HDNMode_Anime4k->isChecked()); - configIniWrite->setValue("/settings/checkBox_FastMode_Anime4K", ui->checkBox_FastMode_Anime4K->isChecked()); - configIniWrite->setValue("/settings/checkBox_ACNet_Anime4K", ui->checkBox_ACNet_Anime4K->isChecked()); - configIniWrite->setValue("/settings/checkBox_GPUMode_Anime4K", ui->checkBox_GPUMode_Anime4K->isChecked()); - configIniWrite->setValue("/settings/spinBox_Passes_Anime4K", ui->spinBox_Passes_Anime4K->value()); - configIniWrite->setValue("/settings/spinBox_PushColorCount_Anime4K", ui->spinBox_PushColorCount_Anime4K->value()); - configIniWrite->setValue("/settings/doubleSpinBox_PushColorStrength_Anime4K", ui->doubleSpinBox_PushColorStrength_Anime4K->value()); - configIniWrite->setValue("/settings/doubleSpinBox_PushGradientStrength_Anime4K", ui->doubleSpinBox_PushGradientStrength_Anime4K->value()); - configIniWrite->setValue("/settings/checkBox_SpecifyGPU_Anime4k", ui->checkBox_SpecifyGPU_Anime4k->isChecked()); - configIniWrite->setValue("/settings/lineEdit_GPUs_Anime4k", ui->lineEdit_GPUs_Anime4k->text()); - //Pre-Processing - configIniWrite->setValue("/settings/checkBox_EnablePreProcessing_Anime4k", ui->checkBox_EnablePreProcessing_Anime4k->isChecked()); - configIniWrite->setValue("/settings/checkBox_MedianBlur_Pre_Anime4k", ui->checkBox_MedianBlur_Pre_Anime4k->isChecked()); - configIniWrite->setValue("/settings/checkBox_MeanBlur_Pre_Anime4k", ui->checkBox_MeanBlur_Pre_Anime4k->isChecked()); - configIniWrite->setValue("/settings/checkBox_CASSharping_Pre_Anime4k", ui->checkBox_CASSharping_Pre_Anime4k->isChecked()); - configIniWrite->setValue("/settings/checkBox_GaussianBlurWeak_Pre_Anime4k", ui->checkBox_GaussianBlurWeak_Pre_Anime4k->isChecked()); - configIniWrite->setValue("/settings/checkBox_GaussianBlur_Pre_Anime4k", ui->checkBox_GaussianBlur_Pre_Anime4k->isChecked()); - configIniWrite->setValue("/settings/checkBox_BilateralFilter_Pre_Anime4k", ui->checkBox_BilateralFilter_Pre_Anime4k->isChecked()); - configIniWrite->setValue("/settings/checkBox_BilateralFilterFaster_Pre_Anime4k", ui->checkBox_BilateralFilterFaster_Pre_Anime4k->isChecked()); - //Post-Processing - configIniWrite->setValue("/settings/checkBox_EnablePostProcessing_Anime4k", ui->checkBox_EnablePostProcessing_Anime4k->isChecked()); - configIniWrite->setValue("/settings/checkBox_MedianBlur_Post_Anime4k", ui->checkBox_MedianBlur_Post_Anime4k->isChecked()); - configIniWrite->setValue("/settings/checkBox_MeanBlur_Post_Anime4k", ui->checkBox_MeanBlur_Post_Anime4k->isChecked()); - configIniWrite->setValue("/settings/checkBox_CASSharping_Post_Anime4k", ui->checkBox_CASSharping_Post_Anime4k->isChecked()); - configIniWrite->setValue("/settings/checkBox_GaussianBlurWeak_Post_Anime4k", ui->checkBox_GaussianBlurWeak_Post_Anime4k->isChecked()); - configIniWrite->setValue("/settings/checkBox_GaussianBlur_Post_Anime4k", ui->checkBox_GaussianBlur_Post_Anime4k->isChecked()); - configIniWrite->setValue("/settings/checkBox_BilateralFilter_Post_Anime4k", ui->checkBox_BilateralFilter_Post_Anime4k->isChecked()); - configIniWrite->setValue("/settings/checkBox_BilateralFilterFaster_Post_Anime4k", ui->checkBox_BilateralFilterFaster_Post_Anime4k->isChecked()); - //========================= 存储兼容性测试结果 ================ - configIniWrite->setValue("/settings/checkBox_isCompatible_Waifu2x_NCNN_Vulkan_NEW", ui->checkBox_isCompatible_Waifu2x_NCNN_Vulkan_NEW->isChecked()); - configIniWrite->setValue("/settings/checkBox_isCompatible_Waifu2x_NCNN_Vulkan_NEW_FP16P", ui->checkBox_isCompatible_Waifu2x_NCNN_Vulkan_NEW_FP16P->isChecked()); - configIniWrite->setValue("/settings/checkBox_isCompatible_Waifu2x_NCNN_Vulkan_OLD", ui->checkBox_isCompatible_Waifu2x_NCNN_Vulkan_OLD->isChecked()); - configIniWrite->setValue("/settings/checkBox_isCompatible_Waifu2x_Converter", ui->checkBox_isCompatible_Waifu2x_Converter->isChecked()); - configIniWrite->setValue("/settings/checkBox_isCompatible_SRMD_NCNN_Vulkan", ui->checkBox_isCompatible_SRMD_NCNN_Vulkan->isChecked()); - configIniWrite->setValue("/settings/checkBox_isCompatible_SRMD_CUDA", ui->checkBox_isCompatible_SRMD_CUDA->isChecked()); - configIniWrite->setValue("/settings/checkBox_isCompatible_Anime4k_CPU", ui->checkBox_isCompatible_Anime4k_CPU->isChecked()); - configIniWrite->setValue("/settings/checkBox_isCompatible_Anime4k_GPU", ui->checkBox_isCompatible_Anime4k_GPU->isChecked()); - configIniWrite->setValue("/settings/checkBox_isCompatible_FFmpeg", ui->checkBox_isCompatible_FFmpeg->isChecked()); - configIniWrite->setValue("/settings/checkBox_isCompatible_FFprobe", ui->checkBox_isCompatible_FFprobe->isChecked()); - configIniWrite->setValue("/settings/checkBox_isCompatible_ImageMagick", ui->checkBox_isCompatible_ImageMagick->isChecked()); - configIniWrite->setValue("/settings/checkBox_isCompatible_Gifsicle", ui->checkBox_isCompatible_Gifsicle->isChecked()); - configIniWrite->setValue("/settings/checkBox_isCompatible_SoX", ui->checkBox_isCompatible_SoX->isChecked()); - configIniWrite->setValue("/settings/checkBox_isCompatible_Waifu2x_Caffe_CPU", ui->checkBox_isCompatible_Waifu2x_Caffe_CPU->isChecked()); - configIniWrite->setValue("/settings/checkBox_isCompatible_Waifu2x_Caffe_GPU", ui->checkBox_isCompatible_Waifu2x_Caffe_GPU->isChecked()); - configIniWrite->setValue("/settings/checkBox_isCompatible_Waifu2x_Caffe_cuDNN", ui->checkBox_isCompatible_Waifu2x_Caffe_cuDNN->isChecked()); - configIniWrite->setValue("/settings/checkBox_isCompatible_Realsr_NCNN_Vulkan", ui->checkBox_isCompatible_Realsr_NCNN_Vulkan->isChecked()); - configIniWrite->setValue("/settings/checkBox_isCompatible_RifeNcnnVulkan", ui->checkBox_isCompatible_RifeNcnnVulkan->isChecked()); - configIniWrite->setValue("/settings/checkBox_isCompatible_CainNcnnVulkan", ui->checkBox_isCompatible_CainNcnnVulkan->isChecked()); - configIniWrite->setValue("/settings/checkBox_isCompatible_DainNcnnVulkan", ui->checkBox_isCompatible_DainNcnnVulkan->isChecked()); - //======================== 存储VFI 设定 ======================== - configIniWrite->setValue("/settings/checkBox_VfiAfterScale_VFI", ui->checkBox_VfiAfterScale_VFI->isChecked()); - configIniWrite->setValue("/settings/checkBox_MultiThread_VFI", ui->checkBox_MultiThread_VFI->isChecked()); - configIniWrite->setValue("/settings/checkBox_AutoAdjustNumOfThreads_VFI", ui->checkBox_AutoAdjustNumOfThreads_VFI->isChecked()); - configIniWrite->setValue("/settings/checkBox_FrameInterpolationOnly_Video", ui->checkBox_FrameInterpolationOnly_Video->isChecked()); - configIniWrite->setValue("/settings/groupBox_FrameInterpolation", ui->groupBox_FrameInterpolation->isChecked()); - configIniWrite->setValue("/settings/checkBox_MultiGPU_VFI", ui->checkBox_MultiGPU_VFI->isChecked()); - configIniWrite->setValue("/settings/checkBox_TTA_VFI", ui->checkBox_TTA_VFI->isChecked()); - configIniWrite->setValue("/settings/checkBox_UHD_VFI", ui->checkBox_UHD_VFI->isChecked()); - configIniWrite->setValue("/settings/comboBox_Model_VFI", ui->comboBox_Model_VFI->currentIndex()); - configIniWrite->setValue("/settings/comboBox_GPUID_VFI", ui->comboBox_GPUID_VFI->currentIndex()); - configIniWrite->setValue("/settings/Available_GPUID_FrameInterpolation", Available_GPUID_FrameInterpolation); - configIniWrite->setValue("/settings/lineEdit_MultiGPU_IDs_VFI", ui->lineEdit_MultiGPU_IDs_VFI->text()); - configIniWrite->setValue("/settings/spinBox_NumOfThreads_VFI", ui->spinBox_NumOfThreads_VFI->value()); - configIniWrite->setValue("/settings/comboBox_Engine_VFI", ui->comboBox_Engine_VFI->currentIndex()); - configIniWrite->setValue("/settings/spinBox_MultipleOfFPS_VFI", ui->spinBox_MultipleOfFPS_VFI->value()); - configIniWrite->setValue("/settings/spinBox_TileSize_VFI", ui->spinBox_TileSize_VFI->value()); - //======== - return 0; -} -/* -读取&应用设置 -如果设置文件不存在则生成默认设置文件,读取设置,应用设置 -*/ -int MainWindow::Settings_Read_Apply() -{ - QString settings_ini = Current_Path+"/settings.ini"; - if(!QFile::exists(settings_ini)) - { - QAction_checkBox_MoveToRecycleBin_checkBox_ReplaceOriginalFile->setChecked(1); - QAction_checkBox_MoveToRecycleBin_checkBox_DelOriginal->setChecked(1); - if(isBetaVer)comboBox_UpdateChannel_setCurrentIndex_self(1); - Settings_Save(); - Settings_Read_Apply(); - return 0; - } - else - { - QSettings *configIniRead_ver = new QSettings(settings_ini, QSettings::IniFormat); - configIniRead_ver->setIniCodec(QTextCodec::codecForName("UTF-8")); - QString Settings_VERSION = configIniRead_ver->value("/settings/VERSION").toString(); - if(Settings_VERSION!=VERSION) - { - isReadOldSettings=true; - QFile::rename(settings_ini,Current_Path+"/settings_old.ini"); - if(isBetaVer)comboBox_UpdateChannel_setCurrentIndex_self(1); - Settings_Save(); - Settings_Read_Apply(); - return 0; - } - } - //================= - QSettings *configIniRead = new QSettings(settings_ini, QSettings::IniFormat); - configIniRead->setIniCodec(QTextCodec::codecForName("UTF-8")); - //=================== 加载全局字体设置 ========================= - ui->spinBox_GlobalFontSize->setValue(Settings_Read_value("/settings/GlobalFontSize").toInt()); - ui->fontComboBox_CustFont->setCurrentFont(Settings_Read_value("/settings/CustFont").value()); - ui->checkBox_isCustFontEnable->setChecked(Settings_Read_value("/settings/CustFont_isEnabled").toBool()); - Set_Font_fixed(); - //======= 加载放大值和降噪值 ====== - ui->doubleSpinBox_ScaleRatio_image->setValue(Settings_Read_value("/settings/ImageScaleRatio").toDouble()); - ui->doubleSpinBox_ScaleRatio_gif->setValue(Settings_Read_value("/settings/GIFScaleRatio").toDouble()); - ui->doubleSpinBox_ScaleRatio_video->setValue(Settings_Read_value("/settings/VideoScaleRatio").toDouble()); - //============= 加载自定义宽度和高度 ============================ - ui->spinBox_CustRes_width->setValue(Settings_Read_value("/settings/CustResWidth").toInt()); - ui->spinBox_CustRes_height->setValue(Settings_Read_value("/settings/CustResHeight").toInt()); - ui->comboBox_AspectRatio_custRes->setCurrentIndex(Settings_Read_value("/settings/CustResAspectRatioMode").toInt()); - //============ 加载 线程数量 ================================== - ui->spinBox_ThreadNum_image->setValue(Settings_Read_value("/settings/ImageThreadNum").toInt()); - ui->spinBox_ThreadNum_gif_internal->setValue(Settings_Read_value("/settings/GIFThreadNumInternal").toInt()); - ui->spinBox_ThreadNum_video_internal->setValue(Settings_Read_value("/settings/VideoThreadNumInternal").toInt()); - //================ 加载 引擎设置 ================================ - isShowAnime4kWarning=false; - ui->comboBox_Engine_Image->setCurrentIndex(Settings_Read_value("/settings/ImageEngine").toInt()); - ui->comboBox_Engine_GIF->setCurrentIndex(Settings_Read_value("/settings/GIFEngine").toInt()); - ui->comboBox_Engine_Video->setCurrentIndex(Settings_Read_value("/settings/VideoEngine").toInt()); - ui->comboBox_ImageStyle->setCurrentIndex(Settings_Read_value("/settings/ImageStyle").toInt()); - ui->comboBox_model_vulkan->setCurrentIndex(Settings_Read_value("/settings/ModelVulkan").toInt()); - ui->spinBox_TileSize->setValue(Settings_Read_value("/settings/TileSize").toInt()); - ui->spinBox_BlockSize_converter->setValue(Settings_Read_value("/settings/BlockSizeConverter").toInt()); - ui->checkBox_DisableGPU_converter->setChecked(Settings_Read_value("/settings/DisableGPUConverter").toBool()); - ui->checkBox_ForceOpenCL_converter->setChecked(Settings_Read_value("/settings/ForceOpenCLConverter").toBool()); - ui->checkBox_TTA_vulkan->setChecked(Settings_Read_value("/settings/TTAVulkan").toBool()); - ui->checkBox_TTA_converter->setChecked(Settings_Read_value("/settings/TTAConverter").toBool()); - ui->checkBox_TTA_srmd->setChecked(Settings_Read_value("/settings/TTA_SRMD").toBool()); - ui->spinBox_TileSize_srmd->setValue(Settings_Read_value("/settings/TileSize_SRMD").toInt()); - ui->comboBox_version_Waifu2xNCNNVulkan->setCurrentIndex(Settings_Read_value("/settings/Version_Waifu2xNCNNVulkan").toInt()); - //=== - ui->checkBox_TTA_RealsrNCNNVulkan->setChecked(Settings_Read_value("/settings/checkBox_TTA_RealsrNCNNVulkan").toBool()); - ui->comboBox_Model_RealsrNCNNVulkan->setCurrentIndex(Settings_Read_value("/settings/comboBox_Model_RealsrNCNNVulkan").toInt()); - ui->spinBox_TileSize_RealsrNCNNVulkan->setValue(Settings_Read_value("/settings/spinBox_TileSize_RealsrNCNNVulkan").toInt()); - //=== - ui->checkBox_TTA_Waifu2xCaffe->setChecked(Settings_Read_value("/settings/TTA_Waifu2xCaffe").toBool()); - ui->comboBox_Model_2D_Waifu2xCaffe->setCurrentIndex(Settings_Read_value("/settings/Model_2D_Waifu2xCaffe").toInt()); - ui->comboBox_Model_3D_Waifu2xCaffe->setCurrentIndex(Settings_Read_value("/settings/Model_3D_Waifu2xCaffe").toInt()); - ui->comboBox_ProcessMode_Waifu2xCaffe->setCurrentIndex(Settings_Read_value("/settings/ProcessMode_Waifu2xCaffe").toInt()); - ui->spinBox_BatchSize_Waifu2xCaffe->setValue(Settings_Read_value("/settings/BatchSize_Waifu2xCaffe").toInt()); - ui->spinBox_GPUID_Waifu2xCaffe->setValue(Settings_Read_value("/settings/GPUID_Waifu2xCaffe").toInt()); - ui->spinBox_SplitSize_Waifu2xCaffe->setValue(Settings_Read_value("/settings/SplitSize_Waifu2xCaffe").toInt()); - ui->checkBox_EnableMultiGPU_Waifu2xCaffe->setChecked(Settings_Read_value("/settings/checkBox_EnableMultiGPU_Waifu2xCaffe").toBool()); - ui->lineEdit_MultiGPUInfo_Waifu2xCaffe->setText(Settings_Read_value("/settings/lineEdit_MultiGPUInfo_Waifu2xCaffe").toString()); - //GPU ID List - //Waifu2x-NCNN-Vulkan - Available_GPUID = Settings_Read_value("/settings/Available_GPUID_Waifu2xNCNNVulkan").toStringList(); - Waifu2x_DetectGPU_finished(); - ui->comboBox_GPUID->setCurrentIndex(Settings_Read_value("/settings/CurrentGPUID_Waifu2xNCNNVulkan").toInt()); - //读取多显卡设定 - GPUIDs_List_MultiGPU_Waifu2xNCNNVulkan = Settings_Read_value("/settings/GPUIDs_List_MultiGPU_Waifu2xNCNNVulkan").value> >(); - if(GPUIDs_List_MultiGPU_Waifu2xNCNNVulkan.isEmpty()==false) - { - QMap GPUInfo_waifu2xNcnnVulkan = GPUIDs_List_MultiGPU_Waifu2xNCNNVulkan.at(ui->comboBox_GPUIDs_MultiGPU_Waifu2xNCNNVulkan->currentIndex()); - ui->checkBox_isEnable_CurrentGPU_MultiGPU_Waifu2xNCNNVulkan->setChecked(GPUInfo_waifu2xNcnnVulkan["isEnabled"] == "true"); - ui->spinBox_TileSize_CurrentGPU_MultiGPU_Waifu2xNCNNVulkan->setValue(GPUInfo_waifu2xNcnnVulkan["TileSize"].toInt()); - } - ui->checkBox_MultiGPU_Waifu2xNCNNVulkan->setChecked(Settings_Read_value("/settings/checkBox_MultiGPU_Waifu2xNCNNVulkan").toBool()); - //Realsr_ncnn_vulkan - Available_GPUID_Realsr_ncnn_vulkan = Settings_Read_value("/settings/Available_GPUID_Realsr_ncnn_vulkan").toStringList(); - Realsr_ncnn_vulkan_DetectGPU_finished(); - ui->comboBox_GPUID_RealsrNCNNVulkan->setCurrentIndex(Settings_Read_value("/settings/comboBox_GPUID_RealsrNCNNVulkan").toInt()); - //读取多显卡设定 - GPUIDs_List_MultiGPU_RealsrNcnnVulkan = Settings_Read_value("/settings/GPUIDs_List_MultiGPU_RealsrNcnnVulkan").value> >(); - if(GPUIDs_List_MultiGPU_RealsrNcnnVulkan.isEmpty()==false) - { - QMap GPUInfo_RealsrNcnnVulkan = GPUIDs_List_MultiGPU_RealsrNcnnVulkan.at(ui->comboBox_GPUIDs_MultiGPU_RealsrNcnnVulkan->currentIndex()); - ui->checkBox_isEnable_CurrentGPU_MultiGPU_RealsrNcnnVulkan->setChecked(GPUInfo_RealsrNcnnVulkan["isEnabled"] == "true"); - ui->spinBox_TileSize_CurrentGPU_MultiGPU_RealsrNcnnVulkan->setValue(GPUInfo_RealsrNcnnVulkan["TileSize"].toInt()); - } - ui->checkBox_MultiGPU_RealsrNcnnVulkan->setChecked(Settings_Read_value("/settings/checkBox_MultiGPU_RealsrNcnnVulkan").toBool()); - //Waifu2x-Converter - Available_ProcessorList_converter = Settings_Read_value("/settings/Available_ProcessorList_converter").toStringList(); - Waifu2x_DumpProcessorList_converter_finished(); - ui->comboBox_TargetProcessor_converter->setCurrentIndex(Settings_Read_value("/settings/comboBox_TargetProcessor_converter").toInt()); - on_comboBox_TargetProcessor_converter_currentIndexChanged(0); - //读取多显卡设定 - GPUIDs_List_MultiGPU_Waifu2xConverter = Settings_Read_value("/settings/GPUIDs_List_MultiGPU_Waifu2xConverter").value> >(); - if(GPUIDs_List_MultiGPU_Waifu2xConverter.isEmpty()==false) - { - QMap GPUInfo_Waifu2xConverter = GPUIDs_List_MultiGPU_Waifu2xConverter.at(ui->comboBox_GPUIDs_MultiGPU_Waifu2xConverter->currentIndex()); - ui->checkBox_isEnable_CurrentGPU_MultiGPU_Waifu2xConverter->setChecked(GPUInfo_Waifu2xConverter["isEnabled"] == "true"); - ui->spinBox_TileSize_CurrentGPU_MultiGPU_Waifu2xConverter->setValue(GPUInfo_Waifu2xConverter["TileSize"].toInt()); - } - ui->checkBox_MultiGPU_Waifu2xConverter->setChecked(Settings_Read_value("/settings/checkBox_MultiGPU_Waifu2xConverter").toBool()); - //SRMD-NCNN-Vulkan - Available_GPUID_srmd = Settings_Read_value("/settings/Available_GPUID_srmd").toStringList(); - SRMD_DetectGPU_finished(); - ui->comboBox_GPUID_srmd->setCurrentIndex(Settings_Read_value("/settings/comboBox_GPUID_srmd").toInt()); - //读取多显卡设定 - GPUIDs_List_MultiGPU_SrmdNcnnVulkan = Settings_Read_value("/settings/GPUIDs_List_MultiGPU_SrmdNcnnVulkan").value> >(); - if(GPUIDs_List_MultiGPU_SrmdNcnnVulkan.isEmpty()==false) - { - QMap GPUInfo_SrmdNcnnVulkan = GPUIDs_List_MultiGPU_SrmdNcnnVulkan.at(ui->comboBox_GPUIDs_MultiGPU_SrmdNCNNVulkan->currentIndex()); - ui->checkBox_isEnable_CurrentGPU_MultiGPU_SrmdNCNNVulkan->setChecked(GPUInfo_SrmdNcnnVulkan["isEnabled"] == "true"); - ui->spinBox_TileSize_CurrentGPU_MultiGPU_SrmdNCNNVulkan->setValue(GPUInfo_SrmdNcnnVulkan["TileSize"].toInt()); - } - ui->checkBox_MultiGPU_SrmdNCNNVulkan->setChecked(Settings_Read_value("/settings/checkBox_MultiGPU_SrmdNCNNVulkan").toBool()); - //================= 加载 扩展名 =========================== - ui->Ext_image->setText(Settings_Read_value("/settings/ImageEXT").toString()); - ui->Ext_video->setText(Settings_Read_value("/settings/VideoEXT").toString()); - //================== 加载 杂项设置 ================================== - ui->checkBox_SummaryPopup->setChecked(Settings_Read_value("/settings/checkBox_SummaryPopup").toBool()); - ui->checkBox_DisableResize_gif->setChecked(Settings_Read_value("/settings/checkBox_DisableResize_gif").toBool()); - ui->checkBox_AutoSkip_CustomRes->setChecked(Settings_Read_value("/settings/checkBox_AutoSkip_CustomRes").toBool()); - ui->checkBox_AlwaysPreProcessAlphaPNG->setChecked(Settings_Read_value("/settings/checkBox_AlwaysPreProcessAlphaPNG").toBool()); - ui->spinBox_ImageQualityLevel->setValue(Settings_Read_value("/settings/spinBox_ImageQualityLevel").toInt()); - ui->comboBox_ImageSaveFormat->setCurrentIndex(Settings_Read_value("/settings/comboBox_ImageSaveFormat").toInt()); - ui->checkBox_KeepParentFolder->setChecked(Settings_Read_value("/settings/checkBox_KeepParentFolder").toBool()); - ui->checkBox_BanGitee->setChecked(Settings_Read_value("/settings/checkBox_BanGitee").toBool()); - comboBox_UpdateChannel_setCurrentIndex_self(Settings_Read_value("/settings/comboBox_UpdateChannel").toInt()); - ui->checkBox_MinimizeToTaskbar->setChecked(Settings_Read_value("/settings/checkBox_MinimizeToTaskbar").toBool()); - ui->checkBox_custres_isAll->setChecked(Settings_Read_value("/settings/checkBox_custres_isAll").toBool()); - ui->checkBox_DelOriginal->setChecked(Settings_Read_value("/settings/DelOriginal").toBool()); - ui->checkBox_OptGIF->setChecked(Settings_Read_value("/settings/OptGIF").toBool()); - ui->checkBox_NfSound->setChecked(Settings_Read_value("/settings/NFSound").toBool()); - ui->checkBox_ReProcFinFiles->setChecked(Settings_Read_value("/settings/ReProFinFiles").toBool()); - ui->checkBox_ShowInterPro->setChecked(Settings_Read_value("/settings/ShowInterPro").toBool()); - ui->checkBox_UpdatePopup->setChecked(Settings_Read_value("/settings/UpdatePopup").toBool()); - ui->checkBox_FileListAutoSlide->setChecked(Settings_Read_value("/settings/FileListAutoScroll").toBool()); - ui->checkBox_AutoSaveSettings->setChecked(Settings_Read_value("/settings/AutoSaveSettings").toBool()); - ui->checkBox_AlwaysHideSettings->setChecked(Settings_Read_value("/settings/AlwaysHideSettings").toBool()); - ui->checkBox_AlwaysHideTextBrowser->setChecked(Settings_Read_value("/settings/AlwaysHideTextBrowser").toBool()); - ui->checkBox_ScanSubFolders->setChecked(Settings_Read_value("/settings/ScanSubFolders").toBool()); - ui->checkBox_FileList_Interactive->setChecked(Settings_Read_value("/settings/InteractiveFileList").toBool()); - ui->spinBox_retry->setValue(Settings_Read_value("/settings/RetryTimes").toInt()); - ui->checkBox_AutoDetectAlphaChannel->setChecked(Settings_Read_value("/settings/AutoDetectAlphaChannel").toBool()); - ui->checkBox_PromptWhenExit->setChecked(Settings_Read_value("/settings/PromptWhenExit").toBool()); - ui->checkBox_KeepVideoCache->setChecked(Settings_Read_value("/settings/KeepVideoCache").toBool()); - ui->checkBox_ReplaceOriginalFile->setChecked(Settings_Read_value("/settings/checkBox_ReplaceOriginalFile").toBool()); - QAction_checkBox_MoveToRecycleBin_checkBox_ReplaceOriginalFile->setChecked(Settings_Read_value("/settings/QAction_checkBox_MoveToRecycleBin_checkBox_ReplaceOriginalFile").toBool()); - QAction_checkBox_MoveToRecycleBin_checkBox_DelOriginal->setChecked(Settings_Read_value("/settings/QAction_checkBox_MoveToRecycleBin_checkBox_DelOriginal").toBool()); - //=== - ui->checkBox_ProcessVideoBySegment->setChecked(Settings_Read_value("/settings/ProcessVideoBySegment").toBool()); - ui->spinBox_SegmentDuration->setValue(Settings_Read_value("/settings/SegmentDuration").toInt()); - //========= - ui->checkBox_AudioDenoise->setChecked(Settings_Read_value("/settings/AudioDenoise").toBool()); - ui->doubleSpinBox_AudioDenoiseLevel->setValue(Settings_Read_value("/settings/AudioDenoiseLevel").toDouble()); - //========= - ui->checkBox_PreProcessImage->setChecked(Settings_Read_value("/settings/checkBox_PreProcessImage").toBool()); - //=================== 加载 textbrowser 设置 ========================== - ui->spinBox_textbrowser_fontsize->setValue(Settings_Read_value("/settings/TextBrowserFontSize").toInt()); - //=================== 加载视频设置 =========================== - ui->groupBox_video_settings->setChecked(Settings_Read_value("/settings/VideoSettingsIsEnabled").toBool()); - //=== - ui->lineEdit_encoder_vid->setText(Settings_Read_value("/settings/EncoderVideo").toString()); - ui->lineEdit_encoder_audio->setText(Settings_Read_value("/settings/EncoderAudio").toString()); - ui->lineEdit_pixformat->setText(Settings_Read_value("/settings/PixelFormat").toString()); - ui->spinBox_bitrate_vid->setValue(Settings_Read_value("/settings/BitrateVideo").toInt()); - ui->spinBox_bitrate_audio->setValue(Settings_Read_value("/settings/BitrateAudio").toInt()); - ui->lineEdit_ExCommand_output->setText(Settings_Read_value("/settings/ExtraCommandOutput").toString()); - //=== - ui->spinBox_bitrate_vid_2mp4->setValue(Settings_Read_value("/settings/BitrateVideo2mp4").toInt()); - ui->spinBox_bitrate_audio_2mp4->setValue(Settings_Read_value("/settings/BitrateAudio2mp4").toInt()); - ui->checkBox_vcodec_copy_2mp4->setChecked(Settings_Read_value("/settings/vcodecCopy").toBool()); - ui->checkBox_acodec_copy_2mp4->setChecked(Settings_Read_value("/settings/acodecCopy").toBool()); - ui->checkBox_IgnoreFrameRateMode->setChecked(Settings_Read_value("/settings/checkBox_IgnoreFrameRateMode").toBool()); - ui->lineEdit_ExCommand_2mp4->setText(Settings_Read_value("/settings/ExtraCommand2mp4").toString()); - //=============== 加载输出路径设置 =========================== - ui->lineEdit_outputPath->setText(Settings_Read_value("/settings/OutPutPath").toString()); - ui->checkBox_OutPath_isEnabled->setChecked(Settings_Read_value("/settings/OutPutPathIsEnabled").toBool()); - ui->checkBox_OutPath_KeepOriginalFileName->setChecked(Settings_Read_value("/settings/checkBox_OutPath_KeepOriginalFileName").toBool()); - ui->checkBox_OutPath_Overwrite->setChecked(Settings_Read_value("/settings/checkBox_OutPath_Overwrite").toBool()); - ui->checkBox_AutoOpenOutputPath->setChecked(Settings_Read_value("/settings/checkBox_AutoOpenOutputPath").toBool()); - //================== 加载Anime4k设置 =================================== - ui->spinBox_OpenCLCommandQueues_A4k->setValue(Settings_Read_value("/settings/spinBox_OpenCLCommandQueues_A4k").toInt()); - ui->checkBox_OpenCLParallelIO_A4k->setChecked(Settings_Read_value("/settings/checkBox_OpenCLParallelIO_A4k").toBool()); - ui->comboBox_GPGPUModel_A4k->setCurrentIndex(Settings_Read_value("/settings/comboBox_GPGPUModel_A4k").toInt()); - ui->checkBox_HDNMode_Anime4k->setChecked(Settings_Read_value("/settings/checkBox_HDNMode_Anime4k").toBool()); - ui->checkBox_FastMode_Anime4K->setChecked(Settings_Read_value("/settings/checkBox_FastMode_Anime4K").toBool()); - ui->checkBox_ACNet_Anime4K->setChecked(Settings_Read_value("/settings/checkBox_ACNet_Anime4K").toBool()); - ui->checkBox_GPUMode_Anime4K->setChecked(Settings_Read_value("/settings/checkBox_GPUMode_Anime4K").toBool()); - ui->spinBox_Passes_Anime4K->setValue(Settings_Read_value("/settings/spinBox_Passes_Anime4K").toInt()); - ui->spinBox_PushColorCount_Anime4K->setValue(Settings_Read_value("/settings/spinBox_PushColorCount_Anime4K").toInt()); - ui->doubleSpinBox_PushColorStrength_Anime4K->setValue(Settings_Read_value("/settings/doubleSpinBox_PushColorStrength_Anime4K").toDouble()); - ui->doubleSpinBox_PushGradientStrength_Anime4K->setValue(Settings_Read_value("/settings/doubleSpinBox_PushGradientStrength_Anime4K").toDouble()); - ui->checkBox_SpecifyGPU_Anime4k->setChecked(Settings_Read_value("/settings/checkBox_SpecifyGPU_Anime4k").toBool()); - ui->lineEdit_GPUs_Anime4k->setText(Settings_Read_value("/settings/lineEdit_GPUs_Anime4k").toString()); - //Pre-Processing - ui->checkBox_EnablePreProcessing_Anime4k->setChecked(Settings_Read_value("/settings/checkBox_EnablePreProcessing_Anime4k").toBool()); - ui->checkBox_MedianBlur_Pre_Anime4k->setChecked(Settings_Read_value("/settings/checkBox_MedianBlur_Pre_Anime4k").toBool()); - ui->checkBox_MeanBlur_Pre_Anime4k->setChecked(Settings_Read_value("/settings/checkBox_MeanBlur_Pre_Anime4k").toBool()); - ui->checkBox_CASSharping_Pre_Anime4k->setChecked(Settings_Read_value("/settings/checkBox_CASSharping_Pre_Anime4k").toBool()); - ui->checkBox_GaussianBlurWeak_Pre_Anime4k->setChecked(Settings_Read_value("/settings/checkBox_GaussianBlurWeak_Pre_Anime4k").toBool()); - ui->checkBox_GaussianBlur_Pre_Anime4k->setChecked(Settings_Read_value("/settings/checkBox_GaussianBlur_Pre_Anime4k").toBool()); - ui->checkBox_BilateralFilter_Pre_Anime4k->setChecked(Settings_Read_value("/settings/checkBox_BilateralFilter_Pre_Anime4k").toBool()); - ui->checkBox_BilateralFilterFaster_Pre_Anime4k->setChecked(Settings_Read_value("/settings/checkBox_BilateralFilterFaster_Pre_Anime4k").toBool()); - //Post-Processing - ui->checkBox_EnablePostProcessing_Anime4k->setChecked(Settings_Read_value("/settings/checkBox_EnablePostProcessing_Anime4k").toBool()); - ui->checkBox_MedianBlur_Post_Anime4k->setChecked(Settings_Read_value("/settings/checkBox_MedianBlur_Post_Anime4k").toBool()); - ui->checkBox_MeanBlur_Post_Anime4k->setChecked(Settings_Read_value("/settings/checkBox_MeanBlur_Post_Anime4k").toBool()); - ui->checkBox_CASSharping_Post_Anime4k->setChecked(Settings_Read_value("/settings/checkBox_CASSharping_Post_Anime4k").toBool()); - ui->checkBox_GaussianBlurWeak_Post_Anime4k->setChecked(Settings_Read_value("/settings/checkBox_GaussianBlurWeak_Post_Anime4k").toBool()); - ui->checkBox_GaussianBlur_Post_Anime4k->setChecked(Settings_Read_value("/settings/checkBox_GaussianBlur_Post_Anime4k").toBool()); - ui->checkBox_BilateralFilter_Post_Anime4k->setChecked(Settings_Read_value("/settings/checkBox_BilateralFilter_Post_Anime4k").toBool()); - ui->checkBox_BilateralFilterFaster_Post_Anime4k->setChecked(Settings_Read_value("/settings/checkBox_BilateralFilterFaster_Post_Anime4k").toBool()); - //===================== 加载兼容性测试结果 ============================ - isCompatible_Waifu2x_NCNN_Vulkan_NEW = Settings_Read_value("/settings/checkBox_isCompatible_Waifu2x_NCNN_Vulkan_NEW").toBool(); - isCompatible_Waifu2x_NCNN_Vulkan_NEW_FP16P = Settings_Read_value("/settings/checkBox_isCompatible_Waifu2x_NCNN_Vulkan_NEW_FP16P").toBool(); - isCompatible_Waifu2x_NCNN_Vulkan_OLD = Settings_Read_value("/settings/checkBox_isCompatible_Waifu2x_NCNN_Vulkan_OLD").toBool(); - isCompatible_Waifu2x_Converter = Settings_Read_value("/settings/checkBox_isCompatible_Waifu2x_Converter").toBool(); - isCompatible_SRMD_NCNN_Vulkan = Settings_Read_value("/settings/checkBox_isCompatible_SRMD_NCNN_Vulkan").toBool(); - isCompatible_SRMD_CUDA = Settings_Read_value("/settings/checkBox_isCompatible_SRMD_CUDA").toBool(); - isCompatible_Anime4k_CPU = Settings_Read_value("/settings/checkBox_isCompatible_Anime4k_CPU").toBool(); - isCompatible_Anime4k_GPU = Settings_Read_value("/settings/checkBox_isCompatible_Anime4k_GPU").toBool(); - isCompatible_FFmpeg = Settings_Read_value("/settings/checkBox_isCompatible_FFmpeg").toBool(); - isCompatible_FFprobe = Settings_Read_value("/settings/checkBox_isCompatible_FFprobe").toBool(); - isCompatible_ImageMagick = Settings_Read_value("/settings/checkBox_isCompatible_ImageMagick").toBool(); - isCompatible_Gifsicle = Settings_Read_value("/settings/checkBox_isCompatible_Gifsicle").toBool(); - isCompatible_SoX = Settings_Read_value("/settings/checkBox_isCompatible_SoX").toBool(); - isCompatible_Waifu2x_Caffe_CPU = Settings_Read_value("/settings/checkBox_isCompatible_Waifu2x_Caffe_CPU").toBool(); - isCompatible_Waifu2x_Caffe_GPU = Settings_Read_value("/settings/checkBox_isCompatible_Waifu2x_Caffe_GPU").toBool(); - isCompatible_Waifu2x_Caffe_cuDNN = Settings_Read_value("/settings/checkBox_isCompatible_Waifu2x_Caffe_cuDNN").toBool(); - isCompatible_Realsr_NCNN_Vulkan = Settings_Read_value("/settings/checkBox_isCompatible_Realsr_NCNN_Vulkan").toBool(); - isCompatible_RifeNcnnVulkan = Settings_Read_value("/settings/checkBox_isCompatible_RifeNcnnVulkan").toBool(); - isCompatible_CainNcnnVulkan = Settings_Read_value("/settings/checkBox_isCompatible_CainNcnnVulkan").toBool(); - isCompatible_DainNcnnVulkan = Settings_Read_value("/settings/checkBox_isCompatible_DainNcnnVulkan").toBool(); - //=== - ui->checkBox_isCompatible_Waifu2x_NCNN_Vulkan_NEW->setChecked(isCompatible_Waifu2x_NCNN_Vulkan_NEW); - ui->checkBox_isCompatible_Waifu2x_NCNN_Vulkan_NEW_FP16P->setChecked(isCompatible_Waifu2x_NCNN_Vulkan_NEW_FP16P); - ui->checkBox_isCompatible_Waifu2x_NCNN_Vulkan_OLD->setChecked(isCompatible_Waifu2x_NCNN_Vulkan_OLD); - ui->checkBox_isCompatible_Waifu2x_Converter->setChecked(isCompatible_Waifu2x_Converter); - ui->checkBox_isCompatible_SRMD_NCNN_Vulkan->setChecked(isCompatible_SRMD_NCNN_Vulkan); - ui->checkBox_isCompatible_SRMD_CUDA->setChecked(isCompatible_SRMD_CUDA); - ui->checkBox_isCompatible_Anime4k_CPU->setChecked(isCompatible_Anime4k_CPU); - ui->checkBox_isCompatible_Anime4k_GPU->setChecked(isCompatible_Anime4k_GPU); - ui->checkBox_isCompatible_FFmpeg->setChecked(isCompatible_FFmpeg); - ui->checkBox_isCompatible_FFprobe->setChecked(isCompatible_FFprobe); - ui->checkBox_isCompatible_ImageMagick->setChecked(isCompatible_ImageMagick); - ui->checkBox_isCompatible_Gifsicle->setChecked(isCompatible_Gifsicle); - ui->checkBox_isCompatible_SoX->setChecked(isCompatible_SoX); - ui->checkBox_isCompatible_Waifu2x_Caffe_CPU->setChecked(isCompatible_Waifu2x_Caffe_CPU); - ui->checkBox_isCompatible_Waifu2x_Caffe_GPU->setChecked(isCompatible_Waifu2x_Caffe_GPU); - ui->checkBox_isCompatible_Waifu2x_Caffe_cuDNN->setChecked(isCompatible_Waifu2x_Caffe_cuDNN); - ui->checkBox_isCompatible_Realsr_NCNN_Vulkan->setChecked(isCompatible_Realsr_NCNN_Vulkan); - ui->checkBox_isCompatible_RifeNcnnVulkan->setChecked(isCompatible_RifeNcnnVulkan); - ui->checkBox_isCompatible_CainNcnnVulkan->setChecked(isCompatible_CainNcnnVulkan); - ui->checkBox_isCompatible_DainNcnnVulkan->setChecked(isCompatible_DainNcnnVulkan); - //======================== 加载 VFI 设定 ======================== - ui->checkBox_VfiAfterScale_VFI->setChecked(Settings_Read_value("/settings/checkBox_VfiAfterScale_VFI").toBool()); - ui->checkBox_MultiThread_VFI->setChecked(Settings_Read_value("/settings/checkBox_MultiThread_VFI").toBool()); - ui->checkBox_AutoAdjustNumOfThreads_VFI->setChecked(Settings_Read_value("/settings/checkBox_AutoAdjustNumOfThreads_VFI").toBool()); - ui->checkBox_FrameInterpolationOnly_Video->setChecked(Settings_Read_value("/settings/checkBox_FrameInterpolationOnly_Video").toBool()); - ui->groupBox_FrameInterpolation->setChecked(Settings_Read_value("/settings/groupBox_FrameInterpolation").toBool()); - ui->checkBox_MultiGPU_VFI->setChecked(Settings_Read_value("/settings/checkBox_MultiGPU_VFI").toBool()); - ui->checkBox_TTA_VFI->setChecked(Settings_Read_value("/settings/checkBox_TTA_VFI").toBool()); - ui->checkBox_UHD_VFI->setChecked(Settings_Read_value("/settings/checkBox_UHD_VFI").toBool()); - ui->comboBox_Model_VFI->setCurrentIndex(Settings_Read_value("/settings/comboBox_Model_VFI").toInt()); - Available_GPUID_FrameInterpolation = Settings_Read_value("/settings/Available_GPUID_FrameInterpolation").toStringList(); - FrameInterpolation_DetectGPU_finished(); - ui->comboBox_GPUID_VFI->setCurrentIndex(Settings_Read_value("/settings/comboBox_GPUID_VFI").toInt()); - ui->lineEdit_MultiGPU_IDs_VFI->setText(Settings_Read_value("/settings/lineEdit_MultiGPU_IDs_VFI").toString()); - ui->spinBox_NumOfThreads_VFI->setValue(Settings_Read_value("/settings/spinBox_NumOfThreads_VFI").toInt()); - Old_FrameInterpolation_Engine_Index = Settings_Read_value("/settings/comboBox_Engine_VFI").toInt(); - ui->comboBox_Engine_VFI->setCurrentIndex(Old_FrameInterpolation_Engine_Index); - ui->spinBox_MultipleOfFPS_VFI->setValue(Settings_Read_value("/settings/spinBox_MultipleOfFPS_VFI").toInt()); - ui->spinBox_TileSize_VFI->setValue(Settings_Read_value("/settings/spinBox_TileSize_VFI").toInt()); - //==================== 加载语言设置 ===================== - ui->comboBox_language->setCurrentIndex(Settings_Read_value("/settings/Language").toInt()); - on_comboBox_language_currentIndexChanged(0); - //==================================================== - on_groupBox_FrameInterpolation_clicked(); - isCustomVideoSettingsClicked=false; - on_groupBox_video_settings_clicked(); - isCustomVideoSettingsClicked=true; - on_checkBox_AlwaysHideSettings_stateChanged(0); - on_checkBox_AlwaysHideTextBrowser_stateChanged(0); - on_checkBox_DelOriginal_stateChanged(0); - on_checkBox_FileList_Interactive_stateChanged(0); - on_checkBox_OutPath_isEnabled_stateChanged(0); - on_checkBox_AudioDenoise_stateChanged(0); - on_checkBox_ProcessVideoBySegment_stateChanged(0); - on_checkBox_EnablePreProcessing_Anime4k_stateChanged(0); - on_checkBox_EnablePostProcessing_Anime4k_stateChanged(0); - on_checkBox_SpecifyGPU_Anime4k_stateChanged(0); - on_checkBox_GPUMode_Anime4K_stateChanged(0); - on_checkBox_ShowInterPro_stateChanged(0); - //==== - on_comboBox_version_Waifu2xNCNNVulkan_currentIndexChanged(0); - on_comboBox_Engine_GIF_currentIndexChanged(0); - isShowAnime4kWarning=false; - on_comboBox_Engine_Image_currentIndexChanged(0); - on_comboBox_Engine_Video_currentIndexChanged(0); - on_comboBox_ImageStyle_currentIndexChanged(0); - on_comboBox_model_vulkan_currentIndexChanged(0); - ui->spinBox_DenoiseLevel_image->setValue(Settings_Read_value("/settings/ImageDenoiseLevel").toInt()); - ui->spinBox_DenoiseLevel_gif->setValue(Settings_Read_value("/settings/GIFDenoiseLevel").toInt()); - ui->spinBox_DenoiseLevel_video->setValue(Settings_Read_value("/settings/VideoDenoiseLevel").toInt()); - //===== - on_spinBox_textbrowser_fontsize_valueChanged(0); - //=== - on_comboBox_AspectRatio_custRes_currentIndexChanged(0); - //===== - Init_Table(); - //==== - on_checkBox_acodec_copy_2mp4_stateChanged(1); - on_checkBox_vcodec_copy_2mp4_stateChanged(1); - on_checkBox_MultiThread_VFI_stateChanged(1); - //================================== - isReadOldSettings=false; - QFile::remove(Current_Path+"/settings_old.ini"); - Settings_Save(); - //================================== - return 0; -} - -QVariant MainWindow::Settings_Read_value(QString Key) -{ - QString settings_ini_old = Current_Path+"/settings_old.ini"; - QString settings_ini_new = Current_Path+"/settings.ini"; - QSettings *configIniRead_new = new QSettings(settings_ini_new, QSettings::IniFormat); - configIniRead_new->setIniCodec(QTextCodec::codecForName("UTF-8")); - //==== - if(isReadOldSettings&&QFile::exists(settings_ini_old)) - { - QSettings *configIniRead_old = new QSettings(settings_ini_old, QSettings::IniFormat); - configIniRead_old->setIniCodec(QTextCodec::codecForName("UTF-8")); - //==== - if(configIniRead_old->value(Key)!=QVariant()) - { - return configIniRead_old->value(Key); - } - else - { - return configIniRead_new->value(Key); - } - } - //==== - return configIniRead_new->value(Key); -} - -/* -保存设置pushbutton -保存设置,弹窗 -*/ -void MainWindow::on_pushButton_SaveSettings_clicked() -{ - Settings_Save(); - QMessageBox *MSG = new QMessageBox(); - MSG->setWindowTitle(tr("Notification")); - MSG->setText(tr("Settings saved successfully!")); - MSG->setIcon(QMessageBox::Information); - MSG->setModal(false); - MSG->show(); -} -/* -重置设置 -删除设置文件,重置标记=true,弹窗 -*/ -void MainWindow::on_pushButton_ResetSettings_clicked() -{ - QMessageBox Msg(QMessageBox::Question, QString(tr("Warning")), QString(tr("Do you really wanna RESET all the settings?"))); - Msg.setIcon(QMessageBox::Warning); - Msg.addButton(QString(tr("YES")), QMessageBox::YesRole); - QAbstractButton *pNoBtn = Msg.addButton(QString(tr("NO")), QMessageBox::NoRole); - Msg.exec(); - if (Msg.clickedButton() == pNoBtn)return; - //============ - QString settings_ini = Current_Path+"/settings.ini"; - QFile::remove(settings_ini); - Settings_isReseted = true; - //============ - QMessageBox *MSG = new QMessageBox(); - MSG->setWindowTitle(tr("Notification")); - MSG->setText(tr("The settings file has been reset, please restart the software manually for the default settings to take effect.")); - MSG->setIcon(QMessageBox::Information); - MSG->setModal(false); - MSG->show(); -} +/* + Copyright (C) 2021 Aaron Feng + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU Affero General Public License as published + by the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program. If not, see . + + My Github homepage: https://github.com/AaronFeng753 +*/ + +#include "mainwindow.h" +#include "ui_mainwindow.h" + +/* +保存设置 +删除原设置文件,保存设置 +*/ +int MainWindow::Settings_Save() +{ + QString settings_ini = Current_Path+"/settings.ini"; + QFile::remove(settings_ini); + //================= + QSettings *configIniWrite = new QSettings(settings_ini, QSettings::IniFormat); + configIniWrite->setIniCodec(QTextCodec::codecForName("UTF-8")); + //================= 添加警告 ========================= + configIniWrite->setValue("/Warning/.", "Do not modify this file! It may cause the program to crash! If problems occur after the modification, delete this file and restart the program."); + //==================== 存储版本识别 ================================== + configIniWrite->setValue("/settings/VERSION", VERSION); + //======= 存储放大值和降噪值 ================================= + configIniWrite->setValue("/settings/ImageScaleRatio", ui->doubleSpinBox_ScaleRatio_image->value()); + configIniWrite->setValue("/settings/GIFScaleRatio", ui->doubleSpinBox_ScaleRatio_gif->value()); + configIniWrite->setValue("/settings/VideoScaleRatio", ui->doubleSpinBox_ScaleRatio_video->value()); + configIniWrite->setValue("/settings/ImageDenoiseLevel", ui->spinBox_DenoiseLevel_image->value()); + configIniWrite->setValue("/settings/GIFDenoiseLevel", ui->spinBox_DenoiseLevel_gif->value()); + configIniWrite->setValue("/settings/VideoDenoiseLevel", ui->spinBox_DenoiseLevel_video->value()); + //============ 存储自定义宽度和高度及设置 ============================ + configIniWrite->setValue("/settings/CustResWidth", ui->spinBox_CustRes_width->value()); + configIniWrite->setValue("/settings/CustResHeight", ui->spinBox_CustRes_height->value()); + configIniWrite->setValue("/settings/CustResAspectRatioMode", ui->comboBox_AspectRatio_custRes->currentIndex()); + //============ 存储线程数量 ==================================== + configIniWrite->setValue("/settings/ImageThreadNum", ui->spinBox_ThreadNum_image->value()); + configIniWrite->setValue("/settings/GIFThreadNumInternal", ui->spinBox_ThreadNum_gif_internal->value()); + configIniWrite->setValue("/settings/VideoThreadNumInternal", ui->spinBox_ThreadNum_video_internal->value()); + //================== 存储引擎设置 ========================= + configIniWrite->setValue("/settings/ImageEngine", ui->comboBox_Engine_Image->currentIndex()); + configIniWrite->setValue("/settings/GIFEngine", ui->comboBox_Engine_GIF->currentIndex()); + configIniWrite->setValue("/settings/VideoEngine", ui->comboBox_Engine_Video->currentIndex()); + configIniWrite->setValue("/settings/ImageStyle", ui->comboBox_ImageStyle->currentIndex()); + configIniWrite->setValue("/settings/ModelVulkan", ui->comboBox_model_vulkan->currentIndex()); + configIniWrite->setValue("/settings/TileSize", ui->spinBox_TileSize->value()); + configIniWrite->setValue("/settings/BlockSizeConverter", ui->spinBox_BlockSize_converter->value()); + configIniWrite->setValue("/settings/DisableGPUConverter", ui->checkBox_DisableGPU_converter->isChecked()); + configIniWrite->setValue("/settings/ForceOpenCLConverter", ui->checkBox_ForceOpenCL_converter->isChecked()); + configIniWrite->setValue("/settings/TTAVulkan", ui->checkBox_TTA_vulkan->isChecked()); + configIniWrite->setValue("/settings/TTAConverter", ui->checkBox_TTA_converter->isChecked()); + configIniWrite->setValue("/settings/TTA_SRMD", ui->checkBox_TTA_srmd->isChecked()); + configIniWrite->setValue("/settings/TileSize_SRMD", ui->spinBox_TileSize_srmd->value()); + configIniWrite->setValue("/settings/Version_Waifu2xNCNNVulkan", ui->comboBox_version_Waifu2xNCNNVulkan->currentIndex()); + //=== + configIniWrite->setValue("/settings/TTA_Waifu2xCaffe", ui->checkBox_TTA_Waifu2xCaffe->isChecked()); + configIniWrite->setValue("/settings/Model_2D_Waifu2xCaffe", ui->comboBox_Model_2D_Waifu2xCaffe->currentIndex()); + configIniWrite->setValue("/settings/Model_3D_Waifu2xCaffe", ui->comboBox_Model_3D_Waifu2xCaffe->currentIndex()); + configIniWrite->setValue("/settings/ProcessMode_Waifu2xCaffe", ui->comboBox_ProcessMode_Waifu2xCaffe->currentIndex()); + configIniWrite->setValue("/settings/BatchSize_Waifu2xCaffe", ui->spinBox_BatchSize_Waifu2xCaffe->value()); + configIniWrite->setValue("/settings/GPUID_Waifu2xCaffe", ui->spinBox_GPUID_Waifu2xCaffe->value()); + configIniWrite->setValue("/settings/SplitSize_Waifu2xCaffe", ui->spinBox_SplitSize_Waifu2xCaffe->value()); + configIniWrite->setValue("/settings/checkBox_EnableMultiGPU_Waifu2xCaffe", ui->checkBox_EnableMultiGPU_Waifu2xCaffe->isChecked()); + configIniWrite->setValue("/settings/lineEdit_MultiGPUInfo_Waifu2xCaffe", ui->lineEdit_MultiGPUInfo_Waifu2xCaffe->text()); + //=== + configIniWrite->setValue("/settings/checkBox_TTA_RealsrNCNNVulkan", ui->checkBox_TTA_RealsrNCNNVulkan->isChecked()); + configIniWrite->setValue("/settings/comboBox_Model_RealsrNCNNVulkan", ui->comboBox_Model_RealsrNCNNVulkan->currentIndex()); + configIniWrite->setValue("/settings/spinBox_TileSize_RealsrNCNNVulkan", ui->spinBox_TileSize_RealsrNCNNVulkan->value()); + //GPU ID List + configIniWrite->setValue("/settings/CurrentGPUID_Waifu2xNCNNVulkan", ui->comboBox_GPUID->currentIndex()); + configIniWrite->setValue("/settings/Available_GPUID_Waifu2xNCNNVulkan", Available_GPUID); + configIniWrite->setValue("/settings/GPUIDs_List_MultiGPU_Waifu2xNCNNVulkan", QVariant::fromValue(GPUIDs_List_MultiGPU_Waifu2xNCNNVulkan)); + configIniWrite->setValue("/settings/checkBox_MultiGPU_Waifu2xNCNNVulkan", ui->checkBox_MultiGPU_Waifu2xNCNNVulkan->isChecked()); + //== + configIniWrite->setValue("/settings/comboBox_GPUID_RealsrNCNNVulkan", ui->comboBox_GPUID_RealsrNCNNVulkan->currentIndex()); + configIniWrite->setValue("/settings/Available_GPUID_Realsr_ncnn_vulkan", Available_GPUID_Realsr_ncnn_vulkan); + configIniWrite->setValue("/settings/GPUIDs_List_MultiGPU_RealsrNcnnVulkan", QVariant::fromValue(GPUIDs_List_MultiGPU_RealsrNcnnVulkan)); + configIniWrite->setValue("/settings/checkBox_MultiGPU_RealsrNcnnVulkan", ui->checkBox_MultiGPU_RealsrNcnnVulkan->isChecked()); + //== + configIniWrite->setValue("/settings/comboBox_TargetProcessor_converter", ui->comboBox_TargetProcessor_converter->currentIndex()); + configIniWrite->setValue("/settings/Available_ProcessorList_converter", Available_ProcessorList_converter); + configIniWrite->setValue("/settings/GPUIDs_List_MultiGPU_Waifu2xConverter", QVariant::fromValue(GPUIDs_List_MultiGPU_Waifu2xConverter)); + configIniWrite->setValue("/settings/checkBox_MultiGPU_Waifu2xConverter", ui->checkBox_MultiGPU_Waifu2xConverter->isChecked()); + //== + configIniWrite->setValue("/settings/comboBox_GPUID_srmd", ui->comboBox_GPUID_srmd->currentIndex()); + configIniWrite->setValue("/settings/Available_GPUID_srmd", Available_GPUID_srmd); + configIniWrite->setValue("/settings/GPUIDs_List_MultiGPU_SrmdNcnnVulkan", QVariant::fromValue(GPUIDs_List_MultiGPU_SrmdNcnnVulkan)); + configIniWrite->setValue("/settings/checkBox_MultiGPU_SrmdNCNNVulkan", ui->checkBox_MultiGPU_SrmdNCNNVulkan->isChecked()); + //================== 存储 扩展名 ================================= + configIniWrite->setValue("/settings/ImageEXT", ui->Ext_image->text()); + configIniWrite->setValue("/settings/VideoEXT", ui->Ext_video->text()); + //=================== 存储 杂项设置 ================================= + configIniWrite->setValue("/settings/checkBox_SummaryPopup", ui->checkBox_SummaryPopup->isChecked()); + configIniWrite->setValue("/settings/checkBox_DisableResize_gif", ui->checkBox_DisableResize_gif->isChecked()); + configIniWrite->setValue("/settings/checkBox_AutoSkip_CustomRes", ui->checkBox_AutoSkip_CustomRes->isChecked()); + configIniWrite->setValue("/settings/checkBox_AlwaysPreProcessAlphaPNG", ui->checkBox_AlwaysPreProcessAlphaPNG->isChecked()); + configIniWrite->setValue("/settings/spinBox_ImageQualityLevel", ui->spinBox_ImageQualityLevel->value()); + configIniWrite->setValue("/settings/comboBox_ImageSaveFormat", ui->comboBox_ImageSaveFormat->currentIndex()); + configIniWrite->setValue("/settings/checkBox_KeepParentFolder", ui->checkBox_KeepParentFolder->isChecked()); + configIniWrite->setValue("/settings/checkBox_BanGitee", ui->checkBox_BanGitee->isChecked()); + configIniWrite->setValue("/settings/comboBox_UpdateChannel", ui->comboBox_UpdateChannel->currentIndex()); + configIniWrite->setValue("/settings/checkBox_MinimizeToTaskbar", ui->checkBox_MinimizeToTaskbar->isChecked()); + configIniWrite->setValue("/settings/checkBox_custres_isAll", ui->checkBox_custres_isAll->isChecked()); + configIniWrite->setValue("/settings/DelOriginal", ui->checkBox_DelOriginal->isChecked()); + configIniWrite->setValue("/settings/OptGIF", ui->checkBox_OptGIF->isChecked()); + configIniWrite->setValue("/settings/NFSound", ui->checkBox_NfSound->isChecked()); + configIniWrite->setValue("/settings/ReProFinFiles", ui->checkBox_ReProcFinFiles->isChecked()); + configIniWrite->setValue("/settings/ShowInterPro", ui->checkBox_ShowInterPro->isChecked()); + configIniWrite->setValue("/settings/UpdatePopup", ui->checkBox_UpdatePopup->isChecked()); + configIniWrite->setValue("/settings/FileListAutoScroll", ui->checkBox_FileListAutoSlide->isChecked()); + configIniWrite->setValue("/settings/AutoSaveSettings", ui->checkBox_AutoSaveSettings->isChecked()); + configIniWrite->setValue("/settings/AlwaysHideSettings", ui->checkBox_AlwaysHideSettings->isChecked()); + configIniWrite->setValue("/settings/AlwaysHideTextBrowser", ui->checkBox_AlwaysHideTextBrowser->isChecked()); + configIniWrite->setValue("/settings/ScanSubFolders", ui->checkBox_ScanSubFolders->isChecked()); + configIniWrite->setValue("/settings/InteractiveFileList", ui->checkBox_FileList_Interactive->isChecked()); + configIniWrite->setValue("/settings/RetryTimes", ui->spinBox_retry->value()); + configIniWrite->setValue("/settings/AutoDetectAlphaChannel", ui->checkBox_AutoDetectAlphaChannel->isChecked()); + configIniWrite->setValue("/settings/PromptWhenExit", ui->checkBox_PromptWhenExit->isChecked()); + configIniWrite->setValue("/settings/KeepVideoCache", ui->checkBox_KeepVideoCache->isChecked()); + configIniWrite->setValue("/settings/checkBox_ReplaceOriginalFile", ui->checkBox_ReplaceOriginalFile->isChecked()); + //=== + configIniWrite->setValue("/settings/QAction_checkBox_MoveToRecycleBin_checkBox_ReplaceOriginalFile", QAction_checkBox_MoveToRecycleBin_checkBox_ReplaceOriginalFile->isChecked()); + //=== + configIniWrite->setValue("/settings/QAction_checkBox_MoveToRecycleBin_checkBox_DelOriginal", QAction_checkBox_MoveToRecycleBin_checkBox_DelOriginal->isChecked()); + //=== + configIniWrite->setValue("/settings/ProcessVideoBySegment", ui->checkBox_ProcessVideoBySegment->isChecked()); + configIniWrite->setValue("/settings/SegmentDuration", ui->spinBox_SegmentDuration->value()); + //===== + configIniWrite->setValue("/settings/AudioDenoise", ui->checkBox_AudioDenoise->isChecked()); + configIniWrite->setValue("/settings/AudioDenoiseLevel", ui->doubleSpinBox_AudioDenoiseLevel->value()); + //===== + configIniWrite->setValue("/settings/checkBox_PreProcessImage", ui->checkBox_PreProcessImage->isChecked()); + //===================== 存储 textbrowser 设置 ===================== + configIniWrite->setValue("/settings/TextBrowserFontSize", ui->spinBox_textbrowser_fontsize->value()); + //===================== 存储语言设置 ================================ + configIniWrite->setValue("/settings/Language", ui->comboBox_language->currentIndex()); + //================== 存储全局字体 ========================= + configIniWrite->setValue("/settings/GlobalFontSize", ui->spinBox_GlobalFontSize->value()); + configIniWrite->setValue("/settings/CustFont", ui->fontComboBox_CustFont->currentFont()); + configIniWrite->setValue("/settings/CustFont_isEnabled", ui->checkBox_isCustFontEnable->isChecked()); + //=================== 存储视频设置 =========================== + configIniWrite->setValue("/settings/VideoSettingsIsEnabled", ui->groupBox_video_settings->isChecked()); + configIniWrite->setValue("/settings/EncoderVideo", ui->lineEdit_encoder_vid->text()); + configIniWrite->setValue("/settings/EncoderAudio", ui->lineEdit_encoder_audio->text()); + configIniWrite->setValue("/settings/PixelFormat", ui->lineEdit_pixformat->text()); + configIniWrite->setValue("/settings/BitrateVideo", ui->spinBox_bitrate_vid->value()); + configIniWrite->setValue("/settings/BitrateAudio", ui->spinBox_bitrate_audio->value()); + configIniWrite->setValue("/settings/ExtraCommandOutput", ui->lineEdit_ExCommand_output->text()); + //=== + configIniWrite->setValue("/settings/BitrateVideo2mp4", ui->spinBox_bitrate_vid_2mp4->value()); + configIniWrite->setValue("/settings/BitrateAudio2mp4", ui->spinBox_bitrate_audio_2mp4->value()); + configIniWrite->setValue("/settings/vcodecCopy", ui->checkBox_vcodec_copy_2mp4->isChecked()); + configIniWrite->setValue("/settings/acodecCopy", ui->checkBox_acodec_copy_2mp4->isChecked()); + configIniWrite->setValue("/settings/checkBox_IgnoreFrameRateMode", ui->checkBox_IgnoreFrameRateMode->isChecked()); + configIniWrite->setValue("/settings/ExtraCommand2mp4", ui->lineEdit_ExCommand_2mp4->text()); + //==================== 存储输出路径设置 ======================== + configIniWrite->setValue("/settings/OutPutPath", ui->lineEdit_outputPath->text()); + configIniWrite->setValue("/settings/OutPutPathIsEnabled", ui->checkBox_OutPath_isEnabled->isChecked()); + configIniWrite->setValue("/settings/checkBox_OutPath_KeepOriginalFileName", ui->checkBox_OutPath_KeepOriginalFileName->isChecked()); + configIniWrite->setValue("/settings/checkBox_OutPath_Overwrite", ui->checkBox_OutPath_Overwrite->isChecked()); + configIniWrite->setValue("/settings/checkBox_AutoOpenOutputPath", ui->checkBox_AutoOpenOutputPath->isChecked()); + //=================== 存储Anime4k设置 ============================= + configIniWrite->setValue("/settings/spinBox_OpenCLCommandQueues_A4k", ui->spinBox_OpenCLCommandQueues_A4k->value()); + configIniWrite->setValue("/settings/checkBox_OpenCLParallelIO_A4k", ui->checkBox_OpenCLParallelIO_A4k->isChecked()); + configIniWrite->setValue("/settings/comboBox_GPGPUModel_A4k", ui->comboBox_GPGPUModel_A4k->currentIndex()); + configIniWrite->setValue("/settings/checkBox_HDNMode_Anime4k", ui->checkBox_HDNMode_Anime4k->isChecked()); + configIniWrite->setValue("/settings/checkBox_FastMode_Anime4K", ui->checkBox_FastMode_Anime4K->isChecked()); + configIniWrite->setValue("/settings/checkBox_ACNet_Anime4K", ui->checkBox_ACNet_Anime4K->isChecked()); + configIniWrite->setValue("/settings/checkBox_GPUMode_Anime4K", ui->checkBox_GPUMode_Anime4K->isChecked()); + configIniWrite->setValue("/settings/spinBox_Passes_Anime4K", ui->spinBox_Passes_Anime4K->value()); + configIniWrite->setValue("/settings/spinBox_PushColorCount_Anime4K", ui->spinBox_PushColorCount_Anime4K->value()); + configIniWrite->setValue("/settings/doubleSpinBox_PushColorStrength_Anime4K", ui->doubleSpinBox_PushColorStrength_Anime4K->value()); + configIniWrite->setValue("/settings/doubleSpinBox_PushGradientStrength_Anime4K", ui->doubleSpinBox_PushGradientStrength_Anime4K->value()); + configIniWrite->setValue("/settings/checkBox_SpecifyGPU_Anime4k", ui->checkBox_SpecifyGPU_Anime4k->isChecked()); + configIniWrite->setValue("/settings/lineEdit_GPUs_Anime4k", ui->lineEdit_GPUs_Anime4k->text()); + //Pre-Processing + configIniWrite->setValue("/settings/checkBox_EnablePreProcessing_Anime4k", ui->checkBox_EnablePreProcessing_Anime4k->isChecked()); + configIniWrite->setValue("/settings/checkBox_MedianBlur_Pre_Anime4k", ui->checkBox_MedianBlur_Pre_Anime4k->isChecked()); + configIniWrite->setValue("/settings/checkBox_MeanBlur_Pre_Anime4k", ui->checkBox_MeanBlur_Pre_Anime4k->isChecked()); + configIniWrite->setValue("/settings/checkBox_CASSharping_Pre_Anime4k", ui->checkBox_CASSharping_Pre_Anime4k->isChecked()); + configIniWrite->setValue("/settings/checkBox_GaussianBlurWeak_Pre_Anime4k", ui->checkBox_GaussianBlurWeak_Pre_Anime4k->isChecked()); + configIniWrite->setValue("/settings/checkBox_GaussianBlur_Pre_Anime4k", ui->checkBox_GaussianBlur_Pre_Anime4k->isChecked()); + configIniWrite->setValue("/settings/checkBox_BilateralFilter_Pre_Anime4k", ui->checkBox_BilateralFilter_Pre_Anime4k->isChecked()); + configIniWrite->setValue("/settings/checkBox_BilateralFilterFaster_Pre_Anime4k", ui->checkBox_BilateralFilterFaster_Pre_Anime4k->isChecked()); + //Post-Processing + configIniWrite->setValue("/settings/checkBox_EnablePostProcessing_Anime4k", ui->checkBox_EnablePostProcessing_Anime4k->isChecked()); + configIniWrite->setValue("/settings/checkBox_MedianBlur_Post_Anime4k", ui->checkBox_MedianBlur_Post_Anime4k->isChecked()); + configIniWrite->setValue("/settings/checkBox_MeanBlur_Post_Anime4k", ui->checkBox_MeanBlur_Post_Anime4k->isChecked()); + configIniWrite->setValue("/settings/checkBox_CASSharping_Post_Anime4k", ui->checkBox_CASSharping_Post_Anime4k->isChecked()); + configIniWrite->setValue("/settings/checkBox_GaussianBlurWeak_Post_Anime4k", ui->checkBox_GaussianBlurWeak_Post_Anime4k->isChecked()); + configIniWrite->setValue("/settings/checkBox_GaussianBlur_Post_Anime4k", ui->checkBox_GaussianBlur_Post_Anime4k->isChecked()); + configIniWrite->setValue("/settings/checkBox_BilateralFilter_Post_Anime4k", ui->checkBox_BilateralFilter_Post_Anime4k->isChecked()); + configIniWrite->setValue("/settings/checkBox_BilateralFilterFaster_Post_Anime4k", ui->checkBox_BilateralFilterFaster_Post_Anime4k->isChecked()); + //========================= 存储兼容性测试结果 ================ + configIniWrite->setValue("/settings/checkBox_isCompatible_Waifu2x_NCNN_Vulkan_NEW", ui->checkBox_isCompatible_Waifu2x_NCNN_Vulkan_NEW->isChecked()); + configIniWrite->setValue("/settings/checkBox_isCompatible_Waifu2x_NCNN_Vulkan_NEW_FP16P", ui->checkBox_isCompatible_Waifu2x_NCNN_Vulkan_NEW_FP16P->isChecked()); + configIniWrite->setValue("/settings/checkBox_isCompatible_Waifu2x_NCNN_Vulkan_OLD", ui->checkBox_isCompatible_Waifu2x_NCNN_Vulkan_OLD->isChecked()); + configIniWrite->setValue("/settings/checkBox_isCompatible_Waifu2x_Converter", ui->checkBox_isCompatible_Waifu2x_Converter->isChecked()); + configIniWrite->setValue("/settings/checkBox_isCompatible_SRMD_NCNN_Vulkan", ui->checkBox_isCompatible_SRMD_NCNN_Vulkan->isChecked()); + configIniWrite->setValue("/settings/checkBox_isCompatible_SRMD_CUDA", ui->checkBox_isCompatible_SRMD_CUDA->isChecked()); + configIniWrite->setValue("/settings/checkBox_isCompatible_Anime4k_CPU", ui->checkBox_isCompatible_Anime4k_CPU->isChecked()); + configIniWrite->setValue("/settings/checkBox_isCompatible_Anime4k_GPU", ui->checkBox_isCompatible_Anime4k_GPU->isChecked()); + configIniWrite->setValue("/settings/checkBox_isCompatible_FFmpeg", ui->checkBox_isCompatible_FFmpeg->isChecked()); + configIniWrite->setValue("/settings/checkBox_isCompatible_FFprobe", ui->checkBox_isCompatible_FFprobe->isChecked()); + configIniWrite->setValue("/settings/checkBox_isCompatible_ImageMagick", ui->checkBox_isCompatible_ImageMagick->isChecked()); + configIniWrite->setValue("/settings/checkBox_isCompatible_Gifsicle", ui->checkBox_isCompatible_Gifsicle->isChecked()); + configIniWrite->setValue("/settings/checkBox_isCompatible_SoX", ui->checkBox_isCompatible_SoX->isChecked()); + configIniWrite->setValue("/settings/checkBox_isCompatible_Waifu2x_Caffe_CPU", ui->checkBox_isCompatible_Waifu2x_Caffe_CPU->isChecked()); + configIniWrite->setValue("/settings/checkBox_isCompatible_Waifu2x_Caffe_GPU", ui->checkBox_isCompatible_Waifu2x_Caffe_GPU->isChecked()); + configIniWrite->setValue("/settings/checkBox_isCompatible_Waifu2x_Caffe_cuDNN", ui->checkBox_isCompatible_Waifu2x_Caffe_cuDNN->isChecked()); + configIniWrite->setValue("/settings/checkBox_isCompatible_Realsr_NCNN_Vulkan", ui->checkBox_isCompatible_Realsr_NCNN_Vulkan->isChecked()); + configIniWrite->setValue("/settings/checkBox_isCompatible_RifeNcnnVulkan", ui->checkBox_isCompatible_RifeNcnnVulkan->isChecked()); + configIniWrite->setValue("/settings/checkBox_isCompatible_CainNcnnVulkan", ui->checkBox_isCompatible_CainNcnnVulkan->isChecked()); + configIniWrite->setValue("/settings/checkBox_isCompatible_DainNcnnVulkan", ui->checkBox_isCompatible_DainNcnnVulkan->isChecked()); + //======================== 存储VFI 设定 ======================== + configIniWrite->setValue("/settings/checkBox_VfiAfterScale_VFI", ui->checkBox_VfiAfterScale_VFI->isChecked()); + configIniWrite->setValue("/settings/checkBox_MultiThread_VFI", ui->checkBox_MultiThread_VFI->isChecked()); + configIniWrite->setValue("/settings/checkBox_AutoAdjustNumOfThreads_VFI", ui->checkBox_AutoAdjustNumOfThreads_VFI->isChecked()); + configIniWrite->setValue("/settings/checkBox_FrameInterpolationOnly_Video", ui->checkBox_FrameInterpolationOnly_Video->isChecked()); + configIniWrite->setValue("/settings/groupBox_FrameInterpolation", ui->groupBox_FrameInterpolation->isChecked()); + configIniWrite->setValue("/settings/checkBox_MultiGPU_VFI", ui->checkBox_MultiGPU_VFI->isChecked()); + configIniWrite->setValue("/settings/checkBox_TTA_VFI", ui->checkBox_TTA_VFI->isChecked()); + configIniWrite->setValue("/settings/checkBox_UHD_VFI", ui->checkBox_UHD_VFI->isChecked()); + configIniWrite->setValue("/settings/comboBox_Model_VFI", ui->comboBox_Model_VFI->currentIndex()); + configIniWrite->setValue("/settings/comboBox_GPUID_VFI", ui->comboBox_GPUID_VFI->currentIndex()); + configIniWrite->setValue("/settings/Available_GPUID_FrameInterpolation", Available_GPUID_FrameInterpolation); + configIniWrite->setValue("/settings/lineEdit_MultiGPU_IDs_VFI", ui->lineEdit_MultiGPU_IDs_VFI->text()); + configIniWrite->setValue("/settings/spinBox_NumOfThreads_VFI", ui->spinBox_NumOfThreads_VFI->value()); + configIniWrite->setValue("/settings/comboBox_Engine_VFI", ui->comboBox_Engine_VFI->currentIndex()); + configIniWrite->setValue("/settings/spinBox_MultipleOfFPS_VFI", ui->spinBox_MultipleOfFPS_VFI->value()); + configIniWrite->setValue("/settings/spinBox_TileSize_VFI", ui->spinBox_TileSize_VFI->value()); + //======== + return 0; +} +/* +读取&应用设置 +如果设置文件不存在则生成默认设置文件,读取设置,应用设置 +*/ +int MainWindow::Settings_Read_Apply() +{ + QString settings_ini = Current_Path+"/settings.ini"; + if(!QFile::exists(settings_ini)) + { + QAction_checkBox_MoveToRecycleBin_checkBox_ReplaceOriginalFile->setChecked(1); + QAction_checkBox_MoveToRecycleBin_checkBox_DelOriginal->setChecked(1); + if(isBetaVer)comboBox_UpdateChannel_setCurrentIndex_self(1); + Settings_Save(); + Settings_Read_Apply(); + return 0; + } + else + { + QSettings *configIniRead_ver = new QSettings(settings_ini, QSettings::IniFormat); + configIniRead_ver->setIniCodec(QTextCodec::codecForName("UTF-8")); + QString Settings_VERSION = configIniRead_ver->value("/settings/VERSION").toString(); + if(Settings_VERSION!=VERSION) + { + isReadOldSettings=true; + QFile::rename(settings_ini,Current_Path+"/settings_old.ini"); + if(isBetaVer)comboBox_UpdateChannel_setCurrentIndex_self(1); + Settings_Save(); + Settings_Read_Apply(); + return 0; + } + } + //================= + QSettings *configIniRead = new QSettings(settings_ini, QSettings::IniFormat); + configIniRead->setIniCodec(QTextCodec::codecForName("UTF-8")); + //=================== 加载全局字体设置 ========================= + ui->spinBox_GlobalFontSize->setValue(Settings_Read_value("/settings/GlobalFontSize").toInt()); + ui->fontComboBox_CustFont->setCurrentFont(Settings_Read_value("/settings/CustFont").value()); + ui->checkBox_isCustFontEnable->setChecked(Settings_Read_value("/settings/CustFont_isEnabled").toBool()); + Set_Font_fixed(); + //======= 加载放大值和降噪值 ====== + ui->doubleSpinBox_ScaleRatio_image->setValue(Settings_Read_value("/settings/ImageScaleRatio").toDouble()); + ui->doubleSpinBox_ScaleRatio_gif->setValue(Settings_Read_value("/settings/GIFScaleRatio").toDouble()); + ui->doubleSpinBox_ScaleRatio_video->setValue(Settings_Read_value("/settings/VideoScaleRatio").toDouble()); + //============= 加载自定义宽度和高度 ============================ + ui->spinBox_CustRes_width->setValue(Settings_Read_value("/settings/CustResWidth").toInt()); + ui->spinBox_CustRes_height->setValue(Settings_Read_value("/settings/CustResHeight").toInt()); + ui->comboBox_AspectRatio_custRes->setCurrentIndex(Settings_Read_value("/settings/CustResAspectRatioMode").toInt()); + //============ 加载 线程数量 ================================== + ui->spinBox_ThreadNum_image->setValue(Settings_Read_value("/settings/ImageThreadNum").toInt()); + ui->spinBox_ThreadNum_gif_internal->setValue(Settings_Read_value("/settings/GIFThreadNumInternal").toInt()); + ui->spinBox_ThreadNum_video_internal->setValue(Settings_Read_value("/settings/VideoThreadNumInternal").toInt()); + //================ 加载 引擎设置 ================================ + isShowAnime4kWarning=false; + ui->comboBox_Engine_Image->setCurrentIndex(Settings_Read_value("/settings/ImageEngine").toInt()); + ui->comboBox_Engine_GIF->setCurrentIndex(Settings_Read_value("/settings/GIFEngine").toInt()); + ui->comboBox_Engine_Video->setCurrentIndex(Settings_Read_value("/settings/VideoEngine").toInt()); + ui->comboBox_ImageStyle->setCurrentIndex(Settings_Read_value("/settings/ImageStyle").toInt()); + ui->comboBox_model_vulkan->setCurrentIndex(Settings_Read_value("/settings/ModelVulkan").toInt()); + ui->spinBox_TileSize->setValue(Settings_Read_value("/settings/TileSize").toInt()); + ui->spinBox_BlockSize_converter->setValue(Settings_Read_value("/settings/BlockSizeConverter").toInt()); + ui->checkBox_DisableGPU_converter->setChecked(Settings_Read_value("/settings/DisableGPUConverter").toBool()); + ui->checkBox_ForceOpenCL_converter->setChecked(Settings_Read_value("/settings/ForceOpenCLConverter").toBool()); + ui->checkBox_TTA_vulkan->setChecked(Settings_Read_value("/settings/TTAVulkan").toBool()); + ui->checkBox_TTA_converter->setChecked(Settings_Read_value("/settings/TTAConverter").toBool()); + ui->checkBox_TTA_srmd->setChecked(Settings_Read_value("/settings/TTA_SRMD").toBool()); + ui->spinBox_TileSize_srmd->setValue(Settings_Read_value("/settings/TileSize_SRMD").toInt()); + ui->comboBox_version_Waifu2xNCNNVulkan->setCurrentIndex(Settings_Read_value("/settings/Version_Waifu2xNCNNVulkan").toInt()); + //=== + ui->checkBox_TTA_RealsrNCNNVulkan->setChecked(Settings_Read_value("/settings/checkBox_TTA_RealsrNCNNVulkan").toBool()); + ui->comboBox_Model_RealsrNCNNVulkan->setCurrentIndex(Settings_Read_value("/settings/comboBox_Model_RealsrNCNNVulkan").toInt()); + ui->spinBox_TileSize_RealsrNCNNVulkan->setValue(Settings_Read_value("/settings/spinBox_TileSize_RealsrNCNNVulkan").toInt()); + //=== + ui->checkBox_TTA_Waifu2xCaffe->setChecked(Settings_Read_value("/settings/TTA_Waifu2xCaffe").toBool()); + ui->comboBox_Model_2D_Waifu2xCaffe->setCurrentIndex(Settings_Read_value("/settings/Model_2D_Waifu2xCaffe").toInt()); + ui->comboBox_Model_3D_Waifu2xCaffe->setCurrentIndex(Settings_Read_value("/settings/Model_3D_Waifu2xCaffe").toInt()); + ui->comboBox_ProcessMode_Waifu2xCaffe->setCurrentIndex(Settings_Read_value("/settings/ProcessMode_Waifu2xCaffe").toInt()); + ui->spinBox_BatchSize_Waifu2xCaffe->setValue(Settings_Read_value("/settings/BatchSize_Waifu2xCaffe").toInt()); + ui->spinBox_GPUID_Waifu2xCaffe->setValue(Settings_Read_value("/settings/GPUID_Waifu2xCaffe").toInt()); + ui->spinBox_SplitSize_Waifu2xCaffe->setValue(Settings_Read_value("/settings/SplitSize_Waifu2xCaffe").toInt()); + ui->checkBox_EnableMultiGPU_Waifu2xCaffe->setChecked(Settings_Read_value("/settings/checkBox_EnableMultiGPU_Waifu2xCaffe").toBool()); + ui->lineEdit_MultiGPUInfo_Waifu2xCaffe->setText(Settings_Read_value("/settings/lineEdit_MultiGPUInfo_Waifu2xCaffe").toString()); + //GPU ID List + //Waifu2x-NCNN-Vulkan + Available_GPUID = Settings_Read_value("/settings/Available_GPUID_Waifu2xNCNNVulkan").toStringList(); + Waifu2x_DetectGPU_finished(); + ui->comboBox_GPUID->setCurrentIndex(Settings_Read_value("/settings/CurrentGPUID_Waifu2xNCNNVulkan").toInt()); + //读取多显卡设定 + GPUIDs_List_MultiGPU_Waifu2xNCNNVulkan = Settings_Read_value("/settings/GPUIDs_List_MultiGPU_Waifu2xNCNNVulkan").value> >(); + if(GPUIDs_List_MultiGPU_Waifu2xNCNNVulkan.isEmpty()==false) + { + QMap GPUInfo_waifu2xNcnnVulkan = GPUIDs_List_MultiGPU_Waifu2xNCNNVulkan.at(ui->comboBox_GPUIDs_MultiGPU_Waifu2xNCNNVulkan->currentIndex()); + ui->checkBox_isEnable_CurrentGPU_MultiGPU_Waifu2xNCNNVulkan->setChecked(GPUInfo_waifu2xNcnnVulkan["isEnabled"] == "true"); + ui->spinBox_TileSize_CurrentGPU_MultiGPU_Waifu2xNCNNVulkan->setValue(GPUInfo_waifu2xNcnnVulkan["TileSize"].toInt()); + } + ui->checkBox_MultiGPU_Waifu2xNCNNVulkan->setChecked(Settings_Read_value("/settings/checkBox_MultiGPU_Waifu2xNCNNVulkan").toBool()); + //Realsr_ncnn_vulkan + Available_GPUID_Realsr_ncnn_vulkan = Settings_Read_value("/settings/Available_GPUID_Realsr_ncnn_vulkan").toStringList(); + Realsr_ncnn_vulkan_DetectGPU_finished(); + ui->comboBox_GPUID_RealsrNCNNVulkan->setCurrentIndex(Settings_Read_value("/settings/comboBox_GPUID_RealsrNCNNVulkan").toInt()); + //读取多显卡设定 + GPUIDs_List_MultiGPU_RealsrNcnnVulkan = Settings_Read_value("/settings/GPUIDs_List_MultiGPU_RealsrNcnnVulkan").value> >(); + if(GPUIDs_List_MultiGPU_RealsrNcnnVulkan.isEmpty()==false) + { + QMap GPUInfo_RealsrNcnnVulkan = GPUIDs_List_MultiGPU_RealsrNcnnVulkan.at(ui->comboBox_GPUIDs_MultiGPU_RealsrNcnnVulkan->currentIndex()); + ui->checkBox_isEnable_CurrentGPU_MultiGPU_RealsrNcnnVulkan->setChecked(GPUInfo_RealsrNcnnVulkan["isEnabled"] == "true"); + ui->spinBox_TileSize_CurrentGPU_MultiGPU_RealsrNcnnVulkan->setValue(GPUInfo_RealsrNcnnVulkan["TileSize"].toInt()); + } + ui->checkBox_MultiGPU_RealsrNcnnVulkan->setChecked(Settings_Read_value("/settings/checkBox_MultiGPU_RealsrNcnnVulkan").toBool()); + //Waifu2x-Converter + Available_ProcessorList_converter = Settings_Read_value("/settings/Available_ProcessorList_converter").toStringList(); + Waifu2x_DumpProcessorList_converter_finished(); + ui->comboBox_TargetProcessor_converter->setCurrentIndex(Settings_Read_value("/settings/comboBox_TargetProcessor_converter").toInt()); + on_comboBox_TargetProcessor_converter_currentIndexChanged(0); + //读取多显卡设定 + GPUIDs_List_MultiGPU_Waifu2xConverter = Settings_Read_value("/settings/GPUIDs_List_MultiGPU_Waifu2xConverter").value> >(); + if(GPUIDs_List_MultiGPU_Waifu2xConverter.isEmpty()==false) + { + QMap GPUInfo_Waifu2xConverter = GPUIDs_List_MultiGPU_Waifu2xConverter.at(ui->comboBox_GPUIDs_MultiGPU_Waifu2xConverter->currentIndex()); + ui->checkBox_isEnable_CurrentGPU_MultiGPU_Waifu2xConverter->setChecked(GPUInfo_Waifu2xConverter["isEnabled"] == "true"); + ui->spinBox_TileSize_CurrentGPU_MultiGPU_Waifu2xConverter->setValue(GPUInfo_Waifu2xConverter["TileSize"].toInt()); + } + ui->checkBox_MultiGPU_Waifu2xConverter->setChecked(Settings_Read_value("/settings/checkBox_MultiGPU_Waifu2xConverter").toBool()); + //SRMD-NCNN-Vulkan + Available_GPUID_srmd = Settings_Read_value("/settings/Available_GPUID_srmd").toStringList(); + SRMD_DetectGPU_finished(); + ui->comboBox_GPUID_srmd->setCurrentIndex(Settings_Read_value("/settings/comboBox_GPUID_srmd").toInt()); + //读取多显卡设定 + GPUIDs_List_MultiGPU_SrmdNcnnVulkan = Settings_Read_value("/settings/GPUIDs_List_MultiGPU_SrmdNcnnVulkan").value> >(); + if(GPUIDs_List_MultiGPU_SrmdNcnnVulkan.isEmpty()==false) + { + QMap GPUInfo_SrmdNcnnVulkan = GPUIDs_List_MultiGPU_SrmdNcnnVulkan.at(ui->comboBox_GPUIDs_MultiGPU_SrmdNCNNVulkan->currentIndex()); + ui->checkBox_isEnable_CurrentGPU_MultiGPU_SrmdNCNNVulkan->setChecked(GPUInfo_SrmdNcnnVulkan["isEnabled"] == "true"); + ui->spinBox_TileSize_CurrentGPU_MultiGPU_SrmdNCNNVulkan->setValue(GPUInfo_SrmdNcnnVulkan["TileSize"].toInt()); + } + ui->checkBox_MultiGPU_SrmdNCNNVulkan->setChecked(Settings_Read_value("/settings/checkBox_MultiGPU_SrmdNCNNVulkan").toBool()); + //================= 加载 扩展名 =========================== + ui->Ext_image->setText(Settings_Read_value("/settings/ImageEXT").toString()); + ui->Ext_video->setText(Settings_Read_value("/settings/VideoEXT").toString()); + //================== 加载 杂项设置 ================================== + ui->checkBox_SummaryPopup->setChecked(Settings_Read_value("/settings/checkBox_SummaryPopup").toBool()); + ui->checkBox_DisableResize_gif->setChecked(Settings_Read_value("/settings/checkBox_DisableResize_gif").toBool()); + ui->checkBox_AutoSkip_CustomRes->setChecked(Settings_Read_value("/settings/checkBox_AutoSkip_CustomRes").toBool()); + ui->checkBox_AlwaysPreProcessAlphaPNG->setChecked(Settings_Read_value("/settings/checkBox_AlwaysPreProcessAlphaPNG").toBool()); + ui->spinBox_ImageQualityLevel->setValue(Settings_Read_value("/settings/spinBox_ImageQualityLevel").toInt()); + ui->comboBox_ImageSaveFormat->setCurrentIndex(Settings_Read_value("/settings/comboBox_ImageSaveFormat").toInt()); + ui->checkBox_KeepParentFolder->setChecked(Settings_Read_value("/settings/checkBox_KeepParentFolder").toBool()); + ui->checkBox_BanGitee->setChecked(Settings_Read_value("/settings/checkBox_BanGitee").toBool()); + comboBox_UpdateChannel_setCurrentIndex_self(Settings_Read_value("/settings/comboBox_UpdateChannel").toInt()); + ui->checkBox_MinimizeToTaskbar->setChecked(Settings_Read_value("/settings/checkBox_MinimizeToTaskbar").toBool()); + ui->checkBox_custres_isAll->setChecked(Settings_Read_value("/settings/checkBox_custres_isAll").toBool()); + ui->checkBox_DelOriginal->setChecked(Settings_Read_value("/settings/DelOriginal").toBool()); + ui->checkBox_OptGIF->setChecked(Settings_Read_value("/settings/OptGIF").toBool()); + ui->checkBox_NfSound->setChecked(Settings_Read_value("/settings/NFSound").toBool()); + ui->checkBox_ReProcFinFiles->setChecked(Settings_Read_value("/settings/ReProFinFiles").toBool()); + ui->checkBox_ShowInterPro->setChecked(Settings_Read_value("/settings/ShowInterPro").toBool()); + ui->checkBox_UpdatePopup->setChecked(Settings_Read_value("/settings/UpdatePopup").toBool()); + ui->checkBox_FileListAutoSlide->setChecked(Settings_Read_value("/settings/FileListAutoScroll").toBool()); + ui->checkBox_AutoSaveSettings->setChecked(Settings_Read_value("/settings/AutoSaveSettings").toBool()); + ui->checkBox_AlwaysHideSettings->setChecked(Settings_Read_value("/settings/AlwaysHideSettings").toBool()); + ui->checkBox_AlwaysHideTextBrowser->setChecked(Settings_Read_value("/settings/AlwaysHideTextBrowser").toBool()); + ui->checkBox_ScanSubFolders->setChecked(Settings_Read_value("/settings/ScanSubFolders").toBool()); + ui->checkBox_FileList_Interactive->setChecked(Settings_Read_value("/settings/InteractiveFileList").toBool()); + ui->spinBox_retry->setValue(Settings_Read_value("/settings/RetryTimes").toInt()); + ui->checkBox_AutoDetectAlphaChannel->setChecked(Settings_Read_value("/settings/AutoDetectAlphaChannel").toBool()); + ui->checkBox_PromptWhenExit->setChecked(Settings_Read_value("/settings/PromptWhenExit").toBool()); + ui->checkBox_KeepVideoCache->setChecked(Settings_Read_value("/settings/KeepVideoCache").toBool()); + ui->checkBox_ReplaceOriginalFile->setChecked(Settings_Read_value("/settings/checkBox_ReplaceOriginalFile").toBool()); + QAction_checkBox_MoveToRecycleBin_checkBox_ReplaceOriginalFile->setChecked(Settings_Read_value("/settings/QAction_checkBox_MoveToRecycleBin_checkBox_ReplaceOriginalFile").toBool()); + QAction_checkBox_MoveToRecycleBin_checkBox_DelOriginal->setChecked(Settings_Read_value("/settings/QAction_checkBox_MoveToRecycleBin_checkBox_DelOriginal").toBool()); + //=== + ui->checkBox_ProcessVideoBySegment->setChecked(Settings_Read_value("/settings/ProcessVideoBySegment").toBool()); + ui->spinBox_SegmentDuration->setValue(Settings_Read_value("/settings/SegmentDuration").toInt()); + //========= + ui->checkBox_AudioDenoise->setChecked(Settings_Read_value("/settings/AudioDenoise").toBool()); + ui->doubleSpinBox_AudioDenoiseLevel->setValue(Settings_Read_value("/settings/AudioDenoiseLevel").toDouble()); + //========= + ui->checkBox_PreProcessImage->setChecked(Settings_Read_value("/settings/checkBox_PreProcessImage").toBool()); + //=================== 加载 textbrowser 设置 ========================== + ui->spinBox_textbrowser_fontsize->setValue(Settings_Read_value("/settings/TextBrowserFontSize").toInt()); + //=================== 加载视频设置 =========================== + ui->groupBox_video_settings->setChecked(Settings_Read_value("/settings/VideoSettingsIsEnabled").toBool()); + //=== + ui->lineEdit_encoder_vid->setText(Settings_Read_value("/settings/EncoderVideo").toString()); + ui->lineEdit_encoder_audio->setText(Settings_Read_value("/settings/EncoderAudio").toString()); + ui->lineEdit_pixformat->setText(Settings_Read_value("/settings/PixelFormat").toString()); + ui->spinBox_bitrate_vid->setValue(Settings_Read_value("/settings/BitrateVideo").toInt()); + ui->spinBox_bitrate_audio->setValue(Settings_Read_value("/settings/BitrateAudio").toInt()); + ui->lineEdit_ExCommand_output->setText(Settings_Read_value("/settings/ExtraCommandOutput").toString()); + //=== + ui->spinBox_bitrate_vid_2mp4->setValue(Settings_Read_value("/settings/BitrateVideo2mp4").toInt()); + ui->spinBox_bitrate_audio_2mp4->setValue(Settings_Read_value("/settings/BitrateAudio2mp4").toInt()); + ui->checkBox_vcodec_copy_2mp4->setChecked(Settings_Read_value("/settings/vcodecCopy").toBool()); + ui->checkBox_acodec_copy_2mp4->setChecked(Settings_Read_value("/settings/acodecCopy").toBool()); + ui->checkBox_IgnoreFrameRateMode->setChecked(Settings_Read_value("/settings/checkBox_IgnoreFrameRateMode").toBool()); + ui->lineEdit_ExCommand_2mp4->setText(Settings_Read_value("/settings/ExtraCommand2mp4").toString()); + //=============== 加载输出路径设置 =========================== + ui->lineEdit_outputPath->setText(Settings_Read_value("/settings/OutPutPath").toString()); + ui->checkBox_OutPath_isEnabled->setChecked(Settings_Read_value("/settings/OutPutPathIsEnabled").toBool()); + ui->checkBox_OutPath_KeepOriginalFileName->setChecked(Settings_Read_value("/settings/checkBox_OutPath_KeepOriginalFileName").toBool()); + ui->checkBox_OutPath_Overwrite->setChecked(Settings_Read_value("/settings/checkBox_OutPath_Overwrite").toBool()); + ui->checkBox_AutoOpenOutputPath->setChecked(Settings_Read_value("/settings/checkBox_AutoOpenOutputPath").toBool()); + //================== 加载Anime4k设置 =================================== + ui->spinBox_OpenCLCommandQueues_A4k->setValue(Settings_Read_value("/settings/spinBox_OpenCLCommandQueues_A4k").toInt()); + ui->checkBox_OpenCLParallelIO_A4k->setChecked(Settings_Read_value("/settings/checkBox_OpenCLParallelIO_A4k").toBool()); + ui->comboBox_GPGPUModel_A4k->setCurrentIndex(Settings_Read_value("/settings/comboBox_GPGPUModel_A4k").toInt()); + ui->checkBox_HDNMode_Anime4k->setChecked(Settings_Read_value("/settings/checkBox_HDNMode_Anime4k").toBool()); + ui->checkBox_FastMode_Anime4K->setChecked(Settings_Read_value("/settings/checkBox_FastMode_Anime4K").toBool()); + ui->checkBox_ACNet_Anime4K->setChecked(Settings_Read_value("/settings/checkBox_ACNet_Anime4K").toBool()); + ui->checkBox_GPUMode_Anime4K->setChecked(Settings_Read_value("/settings/checkBox_GPUMode_Anime4K").toBool()); + ui->spinBox_Passes_Anime4K->setValue(Settings_Read_value("/settings/spinBox_Passes_Anime4K").toInt()); + ui->spinBox_PushColorCount_Anime4K->setValue(Settings_Read_value("/settings/spinBox_PushColorCount_Anime4K").toInt()); + ui->doubleSpinBox_PushColorStrength_Anime4K->setValue(Settings_Read_value("/settings/doubleSpinBox_PushColorStrength_Anime4K").toDouble()); + ui->doubleSpinBox_PushGradientStrength_Anime4K->setValue(Settings_Read_value("/settings/doubleSpinBox_PushGradientStrength_Anime4K").toDouble()); + ui->checkBox_SpecifyGPU_Anime4k->setChecked(Settings_Read_value("/settings/checkBox_SpecifyGPU_Anime4k").toBool()); + ui->lineEdit_GPUs_Anime4k->setText(Settings_Read_value("/settings/lineEdit_GPUs_Anime4k").toString()); + //Pre-Processing + ui->checkBox_EnablePreProcessing_Anime4k->setChecked(Settings_Read_value("/settings/checkBox_EnablePreProcessing_Anime4k").toBool()); + ui->checkBox_MedianBlur_Pre_Anime4k->setChecked(Settings_Read_value("/settings/checkBox_MedianBlur_Pre_Anime4k").toBool()); + ui->checkBox_MeanBlur_Pre_Anime4k->setChecked(Settings_Read_value("/settings/checkBox_MeanBlur_Pre_Anime4k").toBool()); + ui->checkBox_CASSharping_Pre_Anime4k->setChecked(Settings_Read_value("/settings/checkBox_CASSharping_Pre_Anime4k").toBool()); + ui->checkBox_GaussianBlurWeak_Pre_Anime4k->setChecked(Settings_Read_value("/settings/checkBox_GaussianBlurWeak_Pre_Anime4k").toBool()); + ui->checkBox_GaussianBlur_Pre_Anime4k->setChecked(Settings_Read_value("/settings/checkBox_GaussianBlur_Pre_Anime4k").toBool()); + ui->checkBox_BilateralFilter_Pre_Anime4k->setChecked(Settings_Read_value("/settings/checkBox_BilateralFilter_Pre_Anime4k").toBool()); + ui->checkBox_BilateralFilterFaster_Pre_Anime4k->setChecked(Settings_Read_value("/settings/checkBox_BilateralFilterFaster_Pre_Anime4k").toBool()); + //Post-Processing + ui->checkBox_EnablePostProcessing_Anime4k->setChecked(Settings_Read_value("/settings/checkBox_EnablePostProcessing_Anime4k").toBool()); + ui->checkBox_MedianBlur_Post_Anime4k->setChecked(Settings_Read_value("/settings/checkBox_MedianBlur_Post_Anime4k").toBool()); + ui->checkBox_MeanBlur_Post_Anime4k->setChecked(Settings_Read_value("/settings/checkBox_MeanBlur_Post_Anime4k").toBool()); + ui->checkBox_CASSharping_Post_Anime4k->setChecked(Settings_Read_value("/settings/checkBox_CASSharping_Post_Anime4k").toBool()); + ui->checkBox_GaussianBlurWeak_Post_Anime4k->setChecked(Settings_Read_value("/settings/checkBox_GaussianBlurWeak_Post_Anime4k").toBool()); + ui->checkBox_GaussianBlur_Post_Anime4k->setChecked(Settings_Read_value("/settings/checkBox_GaussianBlur_Post_Anime4k").toBool()); + ui->checkBox_BilateralFilter_Post_Anime4k->setChecked(Settings_Read_value("/settings/checkBox_BilateralFilter_Post_Anime4k").toBool()); + ui->checkBox_BilateralFilterFaster_Post_Anime4k->setChecked(Settings_Read_value("/settings/checkBox_BilateralFilterFaster_Post_Anime4k").toBool()); + //===================== 加载兼容性测试结果 ============================ + isCompatible_Waifu2x_NCNN_Vulkan_NEW = Settings_Read_value("/settings/checkBox_isCompatible_Waifu2x_NCNN_Vulkan_NEW").toBool(); + isCompatible_Waifu2x_NCNN_Vulkan_NEW_FP16P = Settings_Read_value("/settings/checkBox_isCompatible_Waifu2x_NCNN_Vulkan_NEW_FP16P").toBool(); + isCompatible_Waifu2x_NCNN_Vulkan_OLD = Settings_Read_value("/settings/checkBox_isCompatible_Waifu2x_NCNN_Vulkan_OLD").toBool(); + isCompatible_Waifu2x_Converter = Settings_Read_value("/settings/checkBox_isCompatible_Waifu2x_Converter").toBool(); + isCompatible_SRMD_NCNN_Vulkan = Settings_Read_value("/settings/checkBox_isCompatible_SRMD_NCNN_Vulkan").toBool(); + isCompatible_SRMD_CUDA = Settings_Read_value("/settings/checkBox_isCompatible_SRMD_CUDA").toBool(); + isCompatible_Anime4k_CPU = Settings_Read_value("/settings/checkBox_isCompatible_Anime4k_CPU").toBool(); + isCompatible_Anime4k_GPU = Settings_Read_value("/settings/checkBox_isCompatible_Anime4k_GPU").toBool(); + isCompatible_FFmpeg = Settings_Read_value("/settings/checkBox_isCompatible_FFmpeg").toBool(); + isCompatible_FFprobe = Settings_Read_value("/settings/checkBox_isCompatible_FFprobe").toBool(); + isCompatible_ImageMagick = Settings_Read_value("/settings/checkBox_isCompatible_ImageMagick").toBool(); + isCompatible_Gifsicle = Settings_Read_value("/settings/checkBox_isCompatible_Gifsicle").toBool(); + isCompatible_SoX = Settings_Read_value("/settings/checkBox_isCompatible_SoX").toBool(); + isCompatible_Waifu2x_Caffe_CPU = Settings_Read_value("/settings/checkBox_isCompatible_Waifu2x_Caffe_CPU").toBool(); + isCompatible_Waifu2x_Caffe_GPU = Settings_Read_value("/settings/checkBox_isCompatible_Waifu2x_Caffe_GPU").toBool(); + isCompatible_Waifu2x_Caffe_cuDNN = Settings_Read_value("/settings/checkBox_isCompatible_Waifu2x_Caffe_cuDNN").toBool(); + isCompatible_Realsr_NCNN_Vulkan = Settings_Read_value("/settings/checkBox_isCompatible_Realsr_NCNN_Vulkan").toBool(); + isCompatible_RifeNcnnVulkan = Settings_Read_value("/settings/checkBox_isCompatible_RifeNcnnVulkan").toBool(); + isCompatible_CainNcnnVulkan = Settings_Read_value("/settings/checkBox_isCompatible_CainNcnnVulkan").toBool(); + isCompatible_DainNcnnVulkan = Settings_Read_value("/settings/checkBox_isCompatible_DainNcnnVulkan").toBool(); + //=== + ui->checkBox_isCompatible_Waifu2x_NCNN_Vulkan_NEW->setChecked(isCompatible_Waifu2x_NCNN_Vulkan_NEW); + ui->checkBox_isCompatible_Waifu2x_NCNN_Vulkan_NEW_FP16P->setChecked(isCompatible_Waifu2x_NCNN_Vulkan_NEW_FP16P); + ui->checkBox_isCompatible_Waifu2x_NCNN_Vulkan_OLD->setChecked(isCompatible_Waifu2x_NCNN_Vulkan_OLD); + ui->checkBox_isCompatible_Waifu2x_Converter->setChecked(isCompatible_Waifu2x_Converter); + ui->checkBox_isCompatible_SRMD_NCNN_Vulkan->setChecked(isCompatible_SRMD_NCNN_Vulkan); + ui->checkBox_isCompatible_SRMD_CUDA->setChecked(isCompatible_SRMD_CUDA); + ui->checkBox_isCompatible_Anime4k_CPU->setChecked(isCompatible_Anime4k_CPU); + ui->checkBox_isCompatible_Anime4k_GPU->setChecked(isCompatible_Anime4k_GPU); + ui->checkBox_isCompatible_FFmpeg->setChecked(isCompatible_FFmpeg); + ui->checkBox_isCompatible_FFprobe->setChecked(isCompatible_FFprobe); + ui->checkBox_isCompatible_ImageMagick->setChecked(isCompatible_ImageMagick); + ui->checkBox_isCompatible_Gifsicle->setChecked(isCompatible_Gifsicle); + ui->checkBox_isCompatible_SoX->setChecked(isCompatible_SoX); + ui->checkBox_isCompatible_Waifu2x_Caffe_CPU->setChecked(isCompatible_Waifu2x_Caffe_CPU); + ui->checkBox_isCompatible_Waifu2x_Caffe_GPU->setChecked(isCompatible_Waifu2x_Caffe_GPU); + ui->checkBox_isCompatible_Waifu2x_Caffe_cuDNN->setChecked(isCompatible_Waifu2x_Caffe_cuDNN); + ui->checkBox_isCompatible_Realsr_NCNN_Vulkan->setChecked(isCompatible_Realsr_NCNN_Vulkan); + ui->checkBox_isCompatible_RifeNcnnVulkan->setChecked(isCompatible_RifeNcnnVulkan); + ui->checkBox_isCompatible_CainNcnnVulkan->setChecked(isCompatible_CainNcnnVulkan); + ui->checkBox_isCompatible_DainNcnnVulkan->setChecked(isCompatible_DainNcnnVulkan); + //======================== 加载 VFI 设定 ======================== + ui->checkBox_VfiAfterScale_VFI->setChecked(Settings_Read_value("/settings/checkBox_VfiAfterScale_VFI").toBool()); + ui->checkBox_MultiThread_VFI->setChecked(Settings_Read_value("/settings/checkBox_MultiThread_VFI").toBool()); + ui->checkBox_AutoAdjustNumOfThreads_VFI->setChecked(Settings_Read_value("/settings/checkBox_AutoAdjustNumOfThreads_VFI").toBool()); + ui->checkBox_FrameInterpolationOnly_Video->setChecked(Settings_Read_value("/settings/checkBox_FrameInterpolationOnly_Video").toBool()); + ui->groupBox_FrameInterpolation->setChecked(Settings_Read_value("/settings/groupBox_FrameInterpolation").toBool()); + ui->checkBox_MultiGPU_VFI->setChecked(Settings_Read_value("/settings/checkBox_MultiGPU_VFI").toBool()); + ui->checkBox_TTA_VFI->setChecked(Settings_Read_value("/settings/checkBox_TTA_VFI").toBool()); + ui->checkBox_UHD_VFI->setChecked(Settings_Read_value("/settings/checkBox_UHD_VFI").toBool()); + ui->comboBox_Model_VFI->setCurrentIndex(Settings_Read_value("/settings/comboBox_Model_VFI").toInt()); + Available_GPUID_FrameInterpolation = Settings_Read_value("/settings/Available_GPUID_FrameInterpolation").toStringList(); + FrameInterpolation_DetectGPU_finished(); + ui->comboBox_GPUID_VFI->setCurrentIndex(Settings_Read_value("/settings/comboBox_GPUID_VFI").toInt()); + ui->lineEdit_MultiGPU_IDs_VFI->setText(Settings_Read_value("/settings/lineEdit_MultiGPU_IDs_VFI").toString()); + ui->spinBox_NumOfThreads_VFI->setValue(Settings_Read_value("/settings/spinBox_NumOfThreads_VFI").toInt()); + Old_FrameInterpolation_Engine_Index = Settings_Read_value("/settings/comboBox_Engine_VFI").toInt(); + ui->comboBox_Engine_VFI->setCurrentIndex(Old_FrameInterpolation_Engine_Index); + ui->spinBox_MultipleOfFPS_VFI->setValue(Settings_Read_value("/settings/spinBox_MultipleOfFPS_VFI").toInt()); + ui->spinBox_TileSize_VFI->setValue(Settings_Read_value("/settings/spinBox_TileSize_VFI").toInt()); + //==================== 加载语言设置 ===================== + ui->comboBox_language->setCurrentIndex(Settings_Read_value("/settings/Language").toInt()); + on_comboBox_language_currentIndexChanged(0); + //==================================================== + on_groupBox_FrameInterpolation_clicked(); + isCustomVideoSettingsClicked=false; + on_groupBox_video_settings_clicked(); + isCustomVideoSettingsClicked=true; + on_checkBox_AlwaysHideSettings_stateChanged(0); + on_checkBox_AlwaysHideTextBrowser_stateChanged(0); + on_checkBox_DelOriginal_stateChanged(0); + on_checkBox_FileList_Interactive_stateChanged(0); + on_checkBox_OutPath_isEnabled_stateChanged(0); + on_checkBox_AudioDenoise_stateChanged(0); + on_checkBox_ProcessVideoBySegment_stateChanged(0); + on_checkBox_EnablePreProcessing_Anime4k_stateChanged(0); + on_checkBox_EnablePostProcessing_Anime4k_stateChanged(0); + on_checkBox_SpecifyGPU_Anime4k_stateChanged(0); + on_checkBox_GPUMode_Anime4K_stateChanged(0); + on_checkBox_ShowInterPro_stateChanged(0); + //==== + on_comboBox_version_Waifu2xNCNNVulkan_currentIndexChanged(0); + on_comboBox_Engine_GIF_currentIndexChanged(0); + isShowAnime4kWarning=false; + on_comboBox_Engine_Image_currentIndexChanged(0); + on_comboBox_Engine_Video_currentIndexChanged(0); + on_comboBox_ImageStyle_currentIndexChanged(0); + on_comboBox_model_vulkan_currentIndexChanged(0); + ui->spinBox_DenoiseLevel_image->setValue(Settings_Read_value("/settings/ImageDenoiseLevel").toInt()); + ui->spinBox_DenoiseLevel_gif->setValue(Settings_Read_value("/settings/GIFDenoiseLevel").toInt()); + ui->spinBox_DenoiseLevel_video->setValue(Settings_Read_value("/settings/VideoDenoiseLevel").toInt()); + //===== + on_spinBox_textbrowser_fontsize_valueChanged(0); + //=== + on_comboBox_AspectRatio_custRes_currentIndexChanged(0); + //===== + Init_Table(); + //==== + on_checkBox_acodec_copy_2mp4_stateChanged(1); + on_checkBox_vcodec_copy_2mp4_stateChanged(1); + on_checkBox_MultiThread_VFI_stateChanged(1); + //================================== + isReadOldSettings=false; + QFile::remove(Current_Path+"/settings_old.ini"); + Settings_Save(); + //================================== + return 0; +} + +QVariant MainWindow::Settings_Read_value(QString Key) +{ + QString settings_ini_old = Current_Path+"/settings_old.ini"; + QString settings_ini_new = Current_Path+"/settings.ini"; + QSettings *configIniRead_new = new QSettings(settings_ini_new, QSettings::IniFormat); + configIniRead_new->setIniCodec(QTextCodec::codecForName("UTF-8")); + //==== + if(isReadOldSettings&&QFile::exists(settings_ini_old)) + { + QSettings *configIniRead_old = new QSettings(settings_ini_old, QSettings::IniFormat); + configIniRead_old->setIniCodec(QTextCodec::codecForName("UTF-8")); + //==== + if(configIniRead_old->value(Key)!=QVariant()) + { + return configIniRead_old->value(Key); + } + else + { + return configIniRead_new->value(Key); + } + } + //==== + return configIniRead_new->value(Key); +} + +/* +保存设置pushbutton +保存设置,弹窗 +*/ +void MainWindow::on_pushButton_SaveSettings_clicked() +{ + Settings_Save(); + QMessageBox *MSG = new QMessageBox(); + MSG->setWindowTitle(tr("Notification")); + MSG->setText(tr("Settings saved successfully!")); + MSG->setIcon(QMessageBox::Information); + MSG->setModal(false); + MSG->show(); +} +/* +重置设置 +删除设置文件,重置标记=true,弹窗 +*/ +void MainWindow::on_pushButton_ResetSettings_clicked() +{ + QMessageBox Msg(QMessageBox::Question, QString(tr("Warning")), QString(tr("Do you really wanna RESET all the settings?"))); + Msg.setIcon(QMessageBox::Warning); + Msg.addButton(QString(tr("YES")), QMessageBox::YesRole); + QAbstractButton *pNoBtn = Msg.addButton(QString(tr("NO")), QMessageBox::NoRole); + Msg.exec(); + if (Msg.clickedButton() == pNoBtn)return; + //============ + QString settings_ini = Current_Path+"/settings.ini"; + QFile::remove(settings_ini); + Settings_isReseted = true; + //============ + QMessageBox *MSG = new QMessageBox(); + MSG->setWindowTitle(tr("Notification")); + MSG->setText(tr("The settings file has been reset, please restart the software manually for the default settings to take effect.")); + MSG->setIcon(QMessageBox::Information); + MSG->setModal(false); + MSG->show(); +} diff --git a/SRC/Waifu2x-Extension-QT/srmd-cuda.cpp b/SRC_v3.41.01-beta/Waifu2x-Extension-QT/srmd-cuda.cpp similarity index 100% rename from SRC/Waifu2x-Extension-QT/srmd-cuda.cpp rename to SRC_v3.41.01-beta/Waifu2x-Extension-QT/srmd-cuda.cpp diff --git a/SRC/Waifu2x-Extension-QT/srmd_ncnn_vulkan.cpp b/SRC_v3.41.01-beta/Waifu2x-Extension-QT/srmd_ncnn_vulkan.cpp similarity index 97% rename from SRC/Waifu2x-Extension-QT/srmd_ncnn_vulkan.cpp rename to SRC_v3.41.01-beta/Waifu2x-Extension-QT/srmd_ncnn_vulkan.cpp index 4316fe3..d66bcc2 100644 --- a/SRC/Waifu2x-Extension-QT/srmd_ncnn_vulkan.cpp +++ b/SRC_v3.41.01-beta/Waifu2x-Extension-QT/srmd_ncnn_vulkan.cpp @@ -1,2272 +1,2272 @@ -/* - Copyright (C) 2021 Aaron Feng - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU Affero General Public License as published - by the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Affero General Public License for more details. - - You should have received a copy of the GNU Affero General Public License - along with this program. If not, see . - - My Github homepage: https://github.com/AaronFeng753 -*/ - -#include "mainwindow.h" -#include "ui_mainwindow.h" - -int MainWindow::SRMD_NCNN_Vulkan_Image(int rowNum,bool ReProcess_MissingAlphaChannel) -{ - //============================= 读取设置 ================================ - int DenoiseLevel = ui->spinBox_DenoiseLevel_image->value(); - bool DelOriginal = (ui->checkBox_DelOriginal->isChecked()||ui->checkBox_ReplaceOriginalFile->isChecked()); - QString OutPutPath_Final =""; - //========================= 拆解map得到参数 ============================= - //将状态设定到处理中 - emit Send_Table_image_ChangeStatus_rowNumInt_statusQString(rowNum, "Processing"); - //得到原文件路径 - QString SourceFile_fullPath = Table_model_image->item(rowNum,2)->text(); - if(!QFile::exists(SourceFile_fullPath))//判断源文件是否存在 - { - emit Send_TextBrowser_NewMessage(tr("Error occured when processing [")+SourceFile_fullPath+tr("]. Error: [File does not exist.]")); - emit Send_Table_image_ChangeStatus_rowNumInt_statusQString(rowNum, "Failed"); - emit Send_progressbar_Add(); - mutex_ThreadNumRunning.lock(); - ThreadNumRunning--; - mutex_ThreadNumRunning.unlock();//线程数量统计-1 - return 0; - } - //========= 转换到 PNG ========= - QString SourceFile_fullPath_Original = SourceFile_fullPath; - SourceFile_fullPath = Imgae_PreProcess(SourceFile_fullPath_Original,ReProcess_MissingAlphaChannel); - //=============== - int ScaleRatio=2; - bool CustRes_isEnabled = false; - int CustRes_height=0; - int CustRes_width=0; - //检查是是否有自定义分辨率 - if(CustRes_isContained(SourceFile_fullPath_Original)) - { - CustRes_isEnabled=true; - QMap Res_map = CustRes_getResMap(SourceFile_fullPath_Original);//res_map["fullpath"],["height"],["width"] - ScaleRatio = CustRes_CalNewScaleRatio(SourceFile_fullPath,Res_map["height"].toInt(),Res_map["width"].toInt()); - if(ScaleRatio==0) - { - emit Send_TextBrowser_NewMessage(tr("Error occured when processing [")+SourceFile_fullPath_Original+tr("]. Error: [The resolution of the source file cannot be read, so the image cannot be scaled to a custom resolution.]")); - emit Send_Table_image_ChangeStatus_rowNumInt_statusQString(rowNum, "Failed"); - emit Send_progressbar_Add(); - mutex_ThreadNumRunning.lock(); - ThreadNumRunning--; - mutex_ThreadNumRunning.unlock();//线程数量统计-1 - return 0; - } - CustRes_height=Res_map["height"].toInt(); - CustRes_width=Res_map["width"].toInt(); - } - else - { - double ScaleRatio_double_tmp = ui->doubleSpinBox_ScaleRatio_image->value(); - if(ScaleRatio_double_tmp == (int)ScaleRatio_double_tmp) - { - ScaleRatio = qRound(ScaleRatio_double_tmp); - } - else - { - CustRes_isEnabled=true; - QMap Res_map = DoubleScaleRatio_Cal_NewScaleRatio_NewHW(SourceFile_fullPath,ScaleRatio_double_tmp); - //==== - if(Res_map.isEmpty()) - { - emit Send_TextBrowser_NewMessage(tr("Error occured when processing [")+SourceFile_fullPath+tr("]. Error: [Unable to read the resolution of the source file.]")); - emit Send_Table_image_ChangeStatus_rowNumInt_statusQString(rowNum, "Failed"); - emit Send_progressbar_Add(); - mutex_ThreadNumRunning.lock(); - ThreadNumRunning--; - mutex_ThreadNumRunning.unlock();//线程数量统计-1 - return 0; - } - //==== - ScaleRatio = Res_map["ScaleRatio"].toInt(); - CustRes_height = Res_map["Height_new"].toInt(); - CustRes_width = Res_map["width_new"].toInt(); - } - } - //=============== - QFileInfo fileinfo(SourceFile_fullPath); - QString file_name = file_getBaseName(SourceFile_fullPath); - QString file_ext = fileinfo.suffix(); - QString file_path = file_getFolderPath(fileinfo); - QString OutPut_Path = file_path + "/" + file_name + "_waifu2x_"+QString::number(ScaleRatio, 10)+"x_"+QString::number(DenoiseLevel, 10)+"n_"+file_ext+".png"; - //============================== 放大 ======================================= - QProcess *Waifu2x = new QProcess(); - QString Waifu2x_folder_path = Current_Path + "/srmd-ncnn-vulkan"; - QString program = Waifu2x_folder_path + "/srmd-ncnn-vulkan_waifu2xEX.exe"; - //========== - QMap result_map = Calculate_ScaleRatio_SrmdNcnnVulkan(ScaleRatio); - int ScaleRatio_tmp=result_map["ScaleRatio_tmp"]; - int Initial_ScaleRatio=result_map["Initial_ScaleRatio"]; - //====== - QString InputPath_tmp = SourceFile_fullPath; - QString OutputPath_tmp =""; - for(int retry=0; retry<(ui->spinBox_retry->value()+ForceRetryCount); retry++) - { - bool waifu2x_qprocess_failed = false; - InputPath_tmp = SourceFile_fullPath; - OutputPath_tmp =""; - int DenoiseLevel_tmp = DenoiseLevel; - for(int i=Initial_ScaleRatio; i<=ScaleRatio_tmp; i*=Initial_ScaleRatio) - { - QString ErrorMSG=""; - QString StanderMSG=""; - //========== - OutputPath_tmp = file_path + "/" + file_name + "_waifu2x_"+QString::number(i, 10)+"x_"+QString::number(DenoiseLevel, 10)+"n_"+file_ext+".png"; - QString cmd = "\"" + program + "\"" + " -i " + "\"" + InputPath_tmp + "\"" + " -o " + "\"" + OutputPath_tmp + "\"" + " -s " + QString::number(Initial_ScaleRatio, 10) + " -n " + QString::number(DenoiseLevel_tmp, 10) + SrmdNcnnVulkan_ReadSettings(); - Waifu2x->start(cmd); - while(!Waifu2x->waitForStarted(100)&&!QProcess_stop) {} - while(!Waifu2x->waitForFinished(500)&&!QProcess_stop) - { - if(waifu2x_STOP) - { - Waifu2x->close(); - if(i>Initial_ScaleRatio) - { - QFile::remove(InputPath_tmp); - } - QFile::remove(OutputPath_tmp); - emit Send_Table_image_ChangeStatus_rowNumInt_statusQString(rowNum, "Interrupted"); - mutex_ThreadNumRunning.lock(); - ThreadNumRunning--; - mutex_ThreadNumRunning.unlock(); - return 0; - } - ErrorMSG.append(Waifu2x->readAllStandardError().toLower()); - StanderMSG.append(Waifu2x->readAllStandardOutput().toLower()); - if(ErrorMSG.contains("failed")||StanderMSG.contains("failed")) - { - waifu2x_qprocess_failed = true; - Waifu2x->close(); - if(i>Initial_ScaleRatio) - { - QFile::remove(InputPath_tmp); - } - QFile::remove(OutputPath_tmp); - break; - } - } - //=============== - if(waifu2x_qprocess_failed)break; - //=============== - ErrorMSG.append(Waifu2x->readAllStandardError().toLower()); - StanderMSG.append(Waifu2x->readAllStandardOutput().toLower()); - if(ErrorMSG.contains("failed")||StanderMSG.contains("failed")) - { - waifu2x_qprocess_failed = true; - if(i>Initial_ScaleRatio) - { - QFile::remove(InputPath_tmp); - } - QFile::remove(OutputPath_tmp); - break; - } - //=============== - if(i>Initial_ScaleRatio) - { - QFile::remove(InputPath_tmp); - } - DenoiseLevel_tmp = -1; - InputPath_tmp = OutputPath_tmp; - } - //========= 检测是否成功,是否需要重试 ============ - if(QFile::exists(OutputPath_tmp)&&!waifu2x_qprocess_failed) - { - break; - } - else - { - QFile::remove(OutputPath_tmp); - if(retry==ui->spinBox_retry->value()+(ForceRetryCount-1))break; - emit Send_TextBrowser_NewMessage(tr("Automatic retry, please wait.")); - Delay_sec_sleep(5); - } - } - if(!QFile::exists(OutputPath_tmp)) - { - if(SourceFile_fullPath_Original!=SourceFile_fullPath) - { - QFile::remove(SourceFile_fullPath); - } - emit Send_TextBrowser_NewMessage(tr("Error occured when processing [")+SourceFile_fullPath_Original+tr("]. Error: [Unable to scale the picture.]")); - emit Send_Table_image_ChangeStatus_rowNumInt_statusQString(rowNum, "Failed"); - emit Send_progressbar_Add(); - mutex_ThreadNumRunning.lock(); - ThreadNumRunning--; - mutex_ThreadNumRunning.unlock(); - return 0; - } - OutPutPath_Final = OutputPath_tmp; - //============================ 调整大小 ==================================================== - if(ScaleRatio_tmp != ScaleRatio||CustRes_isEnabled) - { - int New_height=0; - int New_width=0; - if(CustRes_isEnabled) - { - New_height= CustRes_height; - New_width= CustRes_width; - } - else - { - QMap res_map_OriginalFile = Image_Gif_Read_Resolution(SourceFile_fullPath); - New_height = res_map_OriginalFile["height"]*ScaleRatio; - New_width = res_map_OriginalFile["width"]*ScaleRatio; - } - QImage qimage_adj(OutputPath_tmp); - //读取放大后的图片并调整大小 - QImage qimage_adj_scaled = qimage_adj.scaled(New_width,New_height,CustRes_AspectRatioMode,Qt::SmoothTransformation); - QImageWriter qimageW_adj; - qimageW_adj.setFormat("png"); - qimageW_adj.setFileName(OutPut_Path); - if(qimageW_adj.canWrite()) - { - qimageW_adj.write(qimage_adj_scaled); - } - QFile::remove(OutputPath_tmp); - if(!QFile::exists(OutPut_Path)) - { - emit Send_TextBrowser_NewMessage(tr("Error occured when processing [")+SourceFile_fullPath+tr("]. Error: [Unable to resize the scaled picture to the target size]")); - emit Send_Table_image_ChangeStatus_rowNumInt_statusQString(rowNum, "Failed"); - emit Send_progressbar_Add(); - mutex_ThreadNumRunning.lock(); - ThreadNumRunning--; - mutex_ThreadNumRunning.unlock();//线程数量统计-1 - return 0; - } - OutPutPath_Final = OutPut_Path; - } - if(CustRes_isEnabled) - { - QString OutPut_Path_CustRes = file_path + "/" + file_name + "_waifu2x_"+QString::number(CustRes_width, 10)+"x"+QString::number(CustRes_height, 10)+"_"+QString::number(DenoiseLevel, 10)+"n_"+file_ext+".png"; - QFile::remove(OutPut_Path_CustRes); - QFile::rename(OutPut_Path,OutPut_Path_CustRes); - OutPutPath_Final = OutPut_Path_CustRes; - } - //=========================== 另存为JPG&压缩JPG =========================================== - OutPutPath_Final = SaveImageAs_FormatAndQuality(SourceFile_fullPath_Original,OutPutPath_Final,true,DenoiseLevel); - //================== 检查是否丢失了透明通道 ===================== - if(ReProcess_MissingAlphaChannel==false) - { - QImage QImage_source(SourceFile_fullPath_Original); - QImage QImage_Final(OutPutPath_Final); - if(QImage_source.hasAlphaChannel()==true && QImage_Final.hasAlphaChannel()==false && ui->checkBox_AutoDetectAlphaChannel->isChecked()) - { - QFile::remove(OutPutPath_Final); - emit Send_TextBrowser_NewMessage(tr("Since the Alpha channel in the resulting image is lost, this image will be reprocessed to fix it:[")+SourceFile_fullPath_Original+tr("].\nIf the reprocessing happens a lot, you should consider enable [Always pre-process images with Alpha Channel] in [Additional settings].")); - return SRMD_NCNN_Vulkan_Image(rowNum,true); - } - } - //============================= 删除原文件 & & 更新table status ============================ - if(SourceFile_fullPath_Original!=SourceFile_fullPath) - { - QFile::remove(SourceFile_fullPath); - SourceFile_fullPath = SourceFile_fullPath_Original; - } - if(DelOriginal) - { - if(ReplaceOriginalFile(SourceFile_fullPath,OutPutPath_Final)==false) - { - if(QAction_checkBox_MoveToRecycleBin_checkBox_DelOriginal->isChecked()) - { - file_MoveToTrash(SourceFile_fullPath); - } - else - { - QFile::remove(SourceFile_fullPath); - } - } - emit Send_Table_image_ChangeStatus_rowNumInt_statusQString(rowNum, "Finished, original file deleted"); - } - else - { - emit Send_Table_image_ChangeStatus_rowNumInt_statusQString(rowNum, "Finished"); - } - //========== 移动到输出路径 ========= - if(ui->checkBox_OutPath_isEnabled->isChecked()) - { - MoveFileToOutputPath(OutPutPath_Final,SourceFile_fullPath); - } - //============================ 更新进度条 ================================= - emit Send_progressbar_Add(); - //=========================== 更新线程数量统计============================== - mutex_ThreadNumRunning.lock(); - ThreadNumRunning--; - mutex_ThreadNumRunning.unlock();//线程数量统计-1 - return 0; -} - -/* - - ============================================================================================= - ============================================================================================= - ============================= SRMD_NCNN_Vulkan_GIF ======================================= - ============================================================================================= - ============================================================================================= - -*/ - -int MainWindow::SRMD_NCNN_Vulkan_GIF(int rowNum) -{ - //============================= 读取设置 ================================ - int ScaleRatio = ui->doubleSpinBox_ScaleRatio_gif->value(); - int DenoiseLevel = ui->spinBox_DenoiseLevel_gif->value(); - bool DelOriginal = (ui->checkBox_DelOriginal->isChecked()||ui->checkBox_ReplaceOriginalFile->isChecked()); - bool OptGIF = ui->checkBox_OptGIF->isChecked(); - QString OutPutPath_Final =""; - //========================= 拆解map得到参数 ============================= - emit Send_Table_gif_ChangeStatus_rowNumInt_statusQString(rowNum, "Processing"); - QString SourceFile_fullPath = Table_model_gif->item(rowNum,2)->text(); - if(!QFile::exists(SourceFile_fullPath)) - { - emit Send_TextBrowser_NewMessage(tr("Error occured when processing [")+SourceFile_fullPath+tr("]. Error: [File does not exist.]")); - emit Send_Table_gif_ChangeStatus_rowNumInt_statusQString(rowNum, "Failed"); - emit Send_progressbar_Add(); - return 0; - } - //========================== - bool CustRes_isEnabled = false; - int CustRes_height=0; - int CustRes_width=0; - if(CustRes_isContained(SourceFile_fullPath)) - { - CustRes_isEnabled=true; - QMap Res_map = CustRes_getResMap(SourceFile_fullPath);//res_map["fullpath"],["height"],["width"] - CustRes_height=Res_map["height"].toInt(); - CustRes_width=Res_map["width"].toInt(); - } - //========================== - QFileInfo fileinfo(SourceFile_fullPath); - QString file_name = file_getBaseName(SourceFile_fullPath); - QString file_ext = fileinfo.suffix(); - QString file_path = file_getFolderPath(fileinfo); - QString ResGIFPath = file_path + "/" + file_name + "_waifu2x_"+QString::number(ScaleRatio, 10)+"x_"+QString::number(DenoiseLevel, 10)+"n.gif"; - //=========================== 获取帧时间 ==================================== - int GIF_Duration = Gif_getDuration(SourceFile_fullPath); - if(GIF_Duration==0)//检查是否成功获取duration - { - emit Send_TextBrowser_NewMessage(tr("Error occured when processing [")+SourceFile_fullPath+tr("]. Error: [Can't get Duration value of GIF file.]")); - emit Send_Table_gif_ChangeStatus_rowNumInt_statusQString(rowNum, "Failed"); - //file_DelDir(SplitFramesFolderPath); - emit Send_progressbar_Add(); - return 0;//如果启用stop位,则直接return - } - //============================== 拆分 ========================================== - QString SplitFramesFolderPath = file_path+"/"+file_name+"_SplitFrames_W2xEX";//拆分后存储frame的文件夹 - Gif_splitGif(SourceFile_fullPath,SplitFramesFolderPath); - //============================== 扫描获取文件名 =============================== - QStringList Frame_fileName_list = file_getFileNames_in_Folder_nofilter(SplitFramesFolderPath); - if(Frame_fileName_list.isEmpty())//检查是否成功拆分gif - { - emit Send_TextBrowser_NewMessage(tr("Error occured when processing [")+SourceFile_fullPath+tr("]. Error: [Can't split GIF into frames.]")); - emit Send_Table_gif_ChangeStatus_rowNumInt_statusQString(rowNum, "Failed"); - file_DelDir(SplitFramesFolderPath); - emit Send_progressbar_Add(); - return 0;//如果启用stop位,则直接return - } - //===========建立存储放大后frame的文件夹=========== - QString ScaledFramesFolderPath = SplitFramesFolderPath+"/ScaledFrames_W2xEX"; - if(file_isDirExist(ScaledFramesFolderPath)) - { - file_DelDir(ScaledFramesFolderPath); - file_mkDir(ScaledFramesFolderPath); - } - else - { - file_mkDir(ScaledFramesFolderPath); - } - //==========开始放大========================== - //读取放大倍数 - int ScaleRatio_Original = 2; - if(CustRes_isEnabled == true) - { - ScaleRatio_Original = CustRes_CalNewScaleRatio(SourceFile_fullPath,CustRes_height,CustRes_width); - } - else - { - ScaleRatio_Original = ui->doubleSpinBox_ScaleRatio_gif->value(); - } - QMap result_map = Calculate_ScaleRatio_SrmdNcnnVulkan(ScaleRatio_Original); - int ScaleRatio_Max=result_map["ScaleRatio_tmp"]; - int Initial_ScaleRatio=result_map["Initial_ScaleRatio"]; - bool isOverScaled = (ScaleRatio_Max!=ScaleRatio_Original); - //初始化进度讯息 - int NumOfSplitFrames = Frame_fileName_list.size(); - if(ui->checkBox_ShowInterPro->isChecked()) - { - int NumOfRounds=0; - for(int ScaleRatio_Current_tmp=Initial_ScaleRatio; ScaleRatio_Current_tmp<=ScaleRatio_Max; ScaleRatio_Current_tmp*=Initial_ScaleRatio) - { - NumOfRounds++; - } - emit Send_CurrentFileProgress_Start(file_name+"."+file_ext,NumOfSplitFrames*NumOfRounds); - } - //读取配置讯息 - QString SRMD_NCNN_Vulkan_Settings_str = SrmdNcnnVulkan_ReadSettings_Video_GIF(ui->spinBox_ThreadNum_gif_internal->value()); - QProcess *Waifu2x = new QProcess(); - QString program = Current_Path + "/srmd-ncnn-vulkan/srmd-ncnn-vulkan_waifu2xEX.exe"; - bool waifu2x_qprocess_failed = false; - int DenoiseLevel_tmp = DenoiseLevel; - int CountFinishedRounds=0; - //==== - for(int ScaleRatio_Current_tmp=Initial_ScaleRatio; ScaleRatio_Current_tmp<=ScaleRatio_Max && Frame_fileName_list.isEmpty()==false; ScaleRatio_Current_tmp*=Initial_ScaleRatio) - { - for(int retry=0; retry<(ui->spinBox_retry->value()+ForceRetryCount); retry++) - { - QString ErrorMSG=""; - QString StanderMSG=""; - //========== - waifu2x_qprocess_failed = false; - QString cmd = "\"" + program + "\"" + " -i " + "\"" + SplitFramesFolderPath + "\"" + " -o " + "\"" + ScaledFramesFolderPath + "\"" + " -s " + QString("%1").arg(Initial_ScaleRatio) + " -n " + QString::number(DenoiseLevel_tmp, 10) + SRMD_NCNN_Vulkan_Settings_str; - Waifu2x->start(cmd); - while(!Waifu2x->waitForStarted(100)&&!QProcess_stop) {} - while(!Waifu2x->waitForFinished(650)&&!QProcess_stop) - { - if(waifu2x_STOP) - { - Waifu2x->close(); - file_DelDir(SplitFramesFolderPath); - emit Send_Table_gif_ChangeStatus_rowNumInt_statusQString(rowNum, "Interrupted"); - mutex_ThreadNumRunning.lock(); - ThreadNumRunning--; - mutex_ThreadNumRunning.unlock(); - return 0; - } - ErrorMSG.append(Waifu2x->readAllStandardError().toLower()); - StanderMSG.append(Waifu2x->readAllStandardOutput().toLower()); - if(ErrorMSG.contains("failed")||StanderMSG.contains("failed")) - { - waifu2x_qprocess_failed = true; - Waifu2x->close(); - break; - } - if(ui->checkBox_ShowInterPro->isChecked()) - { - emit Send_CurrentFileProgress_progressbar_SetFinishedValue((NumOfSplitFrames*CountFinishedRounds)+file_getFileNames_in_Folder_nofilter(ScaledFramesFolderPath).size()); - } - } - //=============== - if(waifu2x_qprocess_failed==false) - { - ErrorMSG.append(Waifu2x->readAllStandardError().toLower()); - StanderMSG.append(Waifu2x->readAllStandardOutput().toLower()); - if(ErrorMSG.contains("failed")||StanderMSG.contains("failed")) - { - waifu2x_qprocess_failed = true; - } - } - //========= 检测是否成功,是否需要重试 ============ - if((NumOfSplitFrames == file_getFileNames_in_Folder_nofilter(ScaledFramesFolderPath).size())&&!waifu2x_qprocess_failed) - { - break; - } - else - { - //失败 - file_DelDir(ScaledFramesFolderPath); - file_mkDir(ScaledFramesFolderPath); - if(retry==ui->spinBox_retry->value()+(ForceRetryCount-1))break; - emit Send_TextBrowser_NewMessage(tr("Automatic retry, please wait.")); - Delay_sec_sleep(5); - } - } - //=========== - //根据轮数修改参数 - DenoiseLevel_tmp = -1; - if(ScaleRatio_Current_tmpisChecked()) - { - file_MoveToTrash(SourceFile_fullPath); - } - else - { - QFile::remove(SourceFile_fullPath); - } - } - emit Send_Table_gif_ChangeStatus_rowNumInt_statusQString(rowNum, "Finished, original file deleted"); - } - else - { - emit Send_Table_gif_ChangeStatus_rowNumInt_statusQString(rowNum, "Finished"); - } - //========== 移动到输出路径 ========= - if(ui->checkBox_OutPath_isEnabled->isChecked()) - { - MoveFileToOutputPath(OutPutPath_Final,SourceFile_fullPath); - } - //============================ 更新进度条 ================================= - emit Send_progressbar_Add(); - //=========================== 更新运行中线程数量 ============================== - return 0; -} - -/* - ============================================================================================= - ============================================================================================= - ============================= SRMD_NCNN_Vulkan_Video ======================================= - ============================================================================================= - ============================================================================================= -*/ - -int MainWindow::SRMD_NCNN_Vulkan_Video(int rowNum) -{ - //============================= 读取设置 ================================ - int ScaleRatio = ui->doubleSpinBox_ScaleRatio_video->value(); - int DenoiseLevel = ui->spinBox_DenoiseLevel_video->value(); - bool DelOriginal = (ui->checkBox_DelOriginal->isChecked()||ui->checkBox_ReplaceOriginalFile->isChecked()); - bool isCacheExists = false; - bool isVideoConfigChanged = true; - //========================= 拆解map得到参数 ============================= - emit Send_Table_video_ChangeStatus_rowNumInt_statusQString(rowNum, "Processing"); - QString SourceFile_fullPath = Table_model_video->item(rowNum,2)->text(); - if(!QFile::exists(SourceFile_fullPath)) - { - emit Send_TextBrowser_NewMessage(tr("Error occured when processing [")+SourceFile_fullPath+tr("]. Error: [File does not exist.]")); - emit Send_Table_video_ChangeStatus_rowNumInt_statusQString(rowNum, "Failed"); - emit Send_progressbar_Add(); - return 0; - } - //========================== - QFileInfo fileinfo(SourceFile_fullPath); - QString file_name = file_getBaseName(SourceFile_fullPath); - QString file_ext = fileinfo.suffix(); - QString file_path = file_getFolderPath(fileinfo); - //=================================================================== - //生成mp4 - QString video_mp4_fullpath=video_To_CFRMp4(SourceFile_fullPath); - if(!QFile::exists(video_mp4_fullpath))//检查是否成功生成mp4 - { - emit Send_TextBrowser_NewMessage(tr("Error occured when processing [")+SourceFile_fullPath+tr("]. Error: [Cannot convert video format to mp4.]")); - emit Send_Table_video_ChangeStatus_rowNumInt_statusQString(rowNum, "Failed"); - emit Send_progressbar_Add(); - return 0;//如果启用stop位,则直接return - } - //============ 读取自定义分辨率设定 ============== - bool CustRes_isEnabled = false; - int CustRes_height=0; - int CustRes_width=0; - if(CustRes_isContained(SourceFile_fullPath)) - { - CustRes_isEnabled=true; - QMap Res_map = CustRes_getResMap(SourceFile_fullPath);//res_map["fullpath"],["height"],["width"] - CustRes_height=Res_map["height"].toInt(); - CustRes_width=Res_map["width"].toInt(); - } - //================= - QString AudioPath = file_path+"/Audio_"+file_name+"_"+file_ext+"_W2xEX.wav";//音频 - QString SplitFramesFolderPath = file_path+"/"+file_name+"_"+file_ext+"_SplitFrames_W2xEX";//拆分后存储frame的文件夹 - QString ScaledFramesFolderPath = SplitFramesFolderPath+"/ScaledFrames_W2xEX";//存储放大后的帧 - //========================== - // 检测之前的视频配置文件 - //========================== - QString VideoConfiguration_fullPath = file_path+"/VideoConfiguration_"+file_name+"_"+file_ext+"_Waifu2xEX.ini"; - if(QFile::exists(VideoConfiguration_fullPath)) - { - QSettings *configIniRead = new QSettings(VideoConfiguration_fullPath, QSettings::IniFormat); - configIniRead->setIniCodec(QTextCodec::codecForName("UTF-8")); - //=================== 加载之前存储的视频信息 ========================= - int ScaleRatio_old = configIniRead->value("/VideoConfiguration/ScaleRatio").toInt(); - int DenoiseLevel_old = configIniRead->value("/VideoConfiguration/DenoiseLevel").toInt(); - bool CustRes_isEnabled_old = configIniRead->value("/VideoConfiguration/CustRes_isEnabled").toBool(); - int CustRes_height_old = configIniRead->value("/VideoConfiguration/CustRes_height").toInt(); - int CustRes_width_old = configIniRead->value("/VideoConfiguration/CustRes_width").toInt(); - QString EngineName_old = configIniRead->value("/VideoConfiguration/EngineName").toString(); - bool isProcessBySegment_old = configIniRead->value("/VideoConfiguration/isProcessBySegment").toBool(); - //=================== 比对信息 ================================ - if(EngineName_old=="srmd-ncnn-vulkan") - { - if(CustRes_isEnabled_old==false&&CustRes_isEnabled==false) - { - if(ScaleRatio_old!=ScaleRatio||DenoiseLevel_old!=DenoiseLevel) - { - isVideoConfigChanged=true; - } - else - { - isVideoConfigChanged=false; - } - } - else - { - if(CustRes_isEnabled_old==true&&CustRes_isEnabled==true) - { - if(CustRes_height_old!=CustRes_height||CustRes_width_old!=CustRes_width) - { - isVideoConfigChanged=true; - } - else - { - isVideoConfigChanged=false; - } - } - else - { - isVideoConfigChanged=true; - } - } - if(isProcessBySegment_old==true) - { - isVideoConfigChanged=true; - } - } - else - { - isVideoConfigChanged=true; - } - } - else - { - emit Send_video_write_VideoConfiguration(VideoConfiguration_fullPath,ScaleRatio,DenoiseLevel,CustRes_isEnabled,CustRes_height,CustRes_width,"srmd-ncnn-vulkan",false,"","",ui->groupBox_FrameInterpolation->isChecked(),0); - } - //======================= - // 检测缓存是否存在 - //======================= - if(QFile::exists(video_mp4_fullpath)&&file_isDirExist(SplitFramesFolderPath)&&file_isDirExist(ScaledFramesFolderPath)&&QFile::exists(VideoConfiguration_fullPath)) - { - if(!isVideoConfigChanged) - { - isCacheExists=true; - emit Send_TextBrowser_NewMessage(tr("The previous video cache file is detected and processing of the previous video cache will continue. If you want to restart processing of the current video:[")+SourceFile_fullPath+tr("], delete the cache manually.")); - } - else - { - isCacheExists=false; - //======== - QFile::remove(VideoConfiguration_fullPath); - file_DelDir(SplitFramesFolderPath); - QFile::remove(AudioPath); - DelVfiDir(video_mp4_fullpath); - emit Send_video_write_VideoConfiguration(VideoConfiguration_fullPath,ScaleRatio,DenoiseLevel,CustRes_isEnabled,CustRes_height,CustRes_width,"srmd-ncnn-vulkan",false,"","",ui->groupBox_FrameInterpolation->isChecked(),0); - //======= - emit Send_TextBrowser_NewMessage(tr("The previous video cache file was detected, but because you changed the settings about the video resolution or denoise level, the previous cache will be deleted and processing of the video:[")+SourceFile_fullPath+tr("] will restart.")); - } - } - else - { - isCacheExists=false; - //======== - QFile::remove(VideoConfiguration_fullPath); - file_DelDir(SplitFramesFolderPath); - QFile::remove(AudioPath); - DelVfiDir(video_mp4_fullpath); - emit Send_video_write_VideoConfiguration(VideoConfiguration_fullPath,ScaleRatio,DenoiseLevel,CustRes_isEnabled,CustRes_height,CustRes_width,"srmd-ncnn-vulkan",false,"","",ui->groupBox_FrameInterpolation->isChecked(),0); - //======== - } - if(!isCacheExists) - { - //============================== 拆分 ========================================== - if(file_isDirExist(SplitFramesFolderPath)) - { - file_DelDir(SplitFramesFolderPath); - file_mkDir(SplitFramesFolderPath); - } - else - { - file_mkDir(SplitFramesFolderPath); - } - QFile::remove(AudioPath); - video_video2images(video_mp4_fullpath,SplitFramesFolderPath,AudioPath); - if(waifu2x_STOP) - { - emit Send_Table_video_ChangeStatus_rowNumInt_statusQString(rowNum, "Interrupted"); - return 0;//如果启用stop位,则直接return - } - } - //============================== 扫描获取文件名 =============================== - QStringList Frame_fileName_list = file_getFileNames_in_Folder_nofilter(SplitFramesFolderPath); - if(!isCacheExists) - { - if(Frame_fileName_list.isEmpty())//检查是否成功拆分为帧 - { - emit Send_TextBrowser_NewMessage(tr("Error occured when processing [")+SourceFile_fullPath+tr("]. Error: [Unable to split video into pictures.]")); - emit Send_Table_video_ChangeStatus_rowNumInt_statusQString(rowNum, "Failed"); - emit Send_progressbar_Add(); - return 0;//如果启用stop位,则直接return - } - } - //============================== 放大 ======================================= - //===========建立存储放大后frame的文件夹=========== - if(!isCacheExists) - { - if(file_isDirExist(ScaledFramesFolderPath)) - { - file_DelDir(ScaledFramesFolderPath); - file_mkDir(ScaledFramesFolderPath); - } - else - { - file_mkDir(ScaledFramesFolderPath); - } - } - //==========开始放大========================== - //读取放大倍数 - int ScaleRatio_Original = 2; - if(CustRes_isEnabled == true) - { - ScaleRatio_Original = CustRes_CalNewScaleRatio(video_mp4_fullpath,CustRes_height,CustRes_width); - } - else - { - ScaleRatio_Original = ui->doubleSpinBox_ScaleRatio_video->value(); - } - QMap result_map = Calculate_ScaleRatio_SrmdNcnnVulkan(ScaleRatio_Original); - int ScaleRatio_Max=result_map["ScaleRatio_tmp"]; - int Initial_ScaleRatio=result_map["Initial_ScaleRatio"]; - bool isOverScaled = (ScaleRatio_Max!=ScaleRatio_Original); - //读取初始放大倍率 - int Start_ScaleRatio_Video = Initial_ScaleRatio; - if(!Frame_fileName_list.isEmpty()) - { - QString Full_Path_File = ""; - for(int i = 0; i < Frame_fileName_list.size(); i++) - { - QString tmp = Frame_fileName_list.at(i); - Full_Path_File = SplitFramesFolderPath + "/" + tmp; - QFileInfo finfo(Full_Path_File); - if(finfo.suffix()=="png")break; - } - QImage qimage_original; - qimage_original.load(Full_Path_File); - int Frame_height = qimage_original.height(); - QMap res_map = video_get_Resolution(SourceFile_fullPath); - int Video_height = res_map["height"]; - if(Frame_height>0 && Video_height>0 && Frame_height>=Video_height)//判断是否读取失败 - { - Start_ScaleRatio_Video = Initial_ScaleRatio*(Frame_height/Video_height); - } - } - //初始化进度讯息 - int NumOfSplitFrames = Frame_fileName_list.size()+file_getFileNames_in_Folder_nofilter(ScaledFramesFolderPath).size(); - if(ui->checkBox_ShowInterPro->isChecked()) - { - int NumOfRounds=0; - for(int ScaleRatio_Current_tmp=Start_ScaleRatio_Video; ScaleRatio_Current_tmp<=ScaleRatio_Max; ScaleRatio_Current_tmp*=Initial_ScaleRatio) - { - NumOfRounds++; - } - emit Send_CurrentFileProgress_Start(file_name+"."+file_ext,NumOfSplitFrames*NumOfRounds); - } - //读取配置讯息 - QString SRMD_NCNN_Vulkan_Settings_str = SrmdNcnnVulkan_ReadSettings_Video_GIF(ui->spinBox_ThreadNum_video_internal->value()); - QProcess *Waifu2x = new QProcess(); - QString program = Current_Path + "/srmd-ncnn-vulkan/srmd-ncnn-vulkan_waifu2xEX.exe"; - bool waifu2x_qprocess_failed = false; - int DenoiseLevel_tmp = DenoiseLevel; - int CountFinishedRounds=0; - //==== - for(int ScaleRatio_Current_tmp=Start_ScaleRatio_Video; ScaleRatio_Current_tmp<=ScaleRatio_Max && Frame_fileName_list.isEmpty()==false; ScaleRatio_Current_tmp*=Initial_ScaleRatio) - { - for(int retry=0; retry<(ui->spinBox_retry->value()+ForceRetryCount); retry++) - { - QString ErrorMSG=""; - QString StanderMSG=""; - //========== - waifu2x_qprocess_failed = false; - QString cmd = "\"" + program + "\"" + " -i " + "\"" + SplitFramesFolderPath + "\"" + " -o " + "\"" + ScaledFramesFolderPath + "\"" + " -s " + QString("%1").arg(Initial_ScaleRatio) + " -n " + QString::number(DenoiseLevel_tmp, 10) + SRMD_NCNN_Vulkan_Settings_str; - Waifu2x->start(cmd); - while(!Waifu2x->waitForStarted(100)&&!QProcess_stop) {} - while(!Waifu2x->waitForFinished(650)&&!QProcess_stop) - { - if(waifu2x_STOP) - { - QStringList FinfishedFileList_FileNames = WaitForEngineIO_NcnnVulkan(ScaledFramesFolderPath); - Waifu2x->close(); - //============ - QString file_name_tmp; - QStringList FileNames_ScaledFramesFolderPath = file_getFileNames_in_Folder_nofilter(ScaledFramesFolderPath); - for(int i=0; ireadAllStandardError().toLower()); - StanderMSG.append(Waifu2x->readAllStandardOutput().toLower()); - if(ErrorMSG.contains("failed")||StanderMSG.contains("failed")) - { - waifu2x_qprocess_failed = true; - Waifu2x->close(); - break; - } - if(ui->checkBox_ShowInterPro->isChecked()) - { - emit Send_CurrentFileProgress_progressbar_SetFinishedValue((NumOfSplitFrames*CountFinishedRounds)+file_getFileNames_in_Folder_nofilter(ScaledFramesFolderPath).size()); - } - } - //=============== - if(waifu2x_qprocess_failed==false) - { - ErrorMSG.append(Waifu2x->readAllStandardError().toLower()); - StanderMSG.append(Waifu2x->readAllStandardOutput().toLower()); - if(ErrorMSG.contains("failed")||StanderMSG.contains("failed")) - { - waifu2x_qprocess_failed = true; - } - } - //========= 检测是否成功,是否需要重试 ============ - if((NumOfSplitFrames == file_getFileNames_in_Folder_nofilter(ScaledFramesFolderPath).size())&&!waifu2x_qprocess_failed) - { - break; - } - else - { - //失败 - file_DelDir(ScaledFramesFolderPath); - file_mkDir(ScaledFramesFolderPath); - if(retry==ui->spinBox_retry->value()+(ForceRetryCount-1))break; - emit Send_TextBrowser_NewMessage(tr("Automatic retry, please wait.")); - Delay_sec_sleep(5); - } - } - //=========== - //根据轮数修改参数 - DenoiseLevel_tmp = -1; - if(ScaleRatio_Current_tmpcheckBox_KeepVideoCache->isChecked()==false) - { - QFile::remove(VideoConfiguration_fullPath); - file_DelDir(SplitFramesFolderPath); - QFile::remove(AudioPath); - if(SourceFile_fullPath!=video_mp4_fullpath)QFile::remove(video_mp4_fullpath); - } - else - { - DelOriginal=false; - } - //============================= 删除原文件 & & 更新table status ============================ - if(DelOriginal) - { - if(ReplaceOriginalFile(SourceFile_fullPath,video_mp4_scaled_fullpath)==false) - { - if(QAction_checkBox_MoveToRecycleBin_checkBox_DelOriginal->isChecked()) - { - file_MoveToTrash(SourceFile_fullPath); - } - else - { - QFile::remove(SourceFile_fullPath); - } - } - emit Send_Table_video_ChangeStatus_rowNumInt_statusQString(rowNum, "Finished, original file deleted"); - } - else - { - emit Send_Table_video_ChangeStatus_rowNumInt_statusQString(rowNum, "Finished"); - } - //========== 移动到输出路径 ========= - if(ui->checkBox_OutPath_isEnabled->isChecked()) - { - MoveFileToOutputPath(video_mp4_scaled_fullpath,SourceFile_fullPath); - } - //============================ 更新进度条 ================================= - emit Send_progressbar_Add(); - //=========================== ============================== - return 0; -} - -/* -#### 分段处理 #### -调用SRMD-NCNN-Vulkan处理视频 -读取设置,拆分,创建放大子线程,组装视频 -*/ -int MainWindow::SRMD_NCNN_Vulkan_Video_BySegment(int rowNum) -{ - //============================= 读取设置 ================================ - int ScaleRatio = ui->doubleSpinBox_ScaleRatio_video->value(); - int DenoiseLevel = ui->spinBox_DenoiseLevel_video->value(); - bool DelOriginal = (ui->checkBox_DelOriginal->isChecked()||ui->checkBox_ReplaceOriginalFile->isChecked()); - bool isCacheExists = false; - bool isVideoConfigChanged = true; - int SegmentDuration = ui->spinBox_SegmentDuration->value(); - //========================= 拆解map得到参数 ============================= - emit Send_Table_video_ChangeStatus_rowNumInt_statusQString(rowNum, "Processing"); - QString SourceFile_fullPath = Table_model_video->item(rowNum,2)->text(); - if(!QFile::exists(SourceFile_fullPath)) - { - emit Send_TextBrowser_NewMessage(tr("Error occured when processing [")+SourceFile_fullPath+tr("]. Error: [File does not exist.]")); - emit Send_Table_video_ChangeStatus_rowNumInt_statusQString(rowNum, "Failed"); - emit Send_progressbar_Add(); - return 0; - } - //========================== - QFileInfo fileinfo(SourceFile_fullPath); - QString file_name = file_getBaseName(SourceFile_fullPath); - QString file_ext = fileinfo.suffix(); - QString file_path = file_getFolderPath(fileinfo); - //=================================================================== - //生成mp4 - QString video_mp4_fullpath=video_To_CFRMp4(SourceFile_fullPath); - if(!QFile::exists(video_mp4_fullpath))//检查是否成功生成mp4 - { - emit Send_TextBrowser_NewMessage(tr("Error occured when processing [")+SourceFile_fullPath+tr("]. Error: [Cannot convert video format to mp4.]")); - emit Send_Table_video_ChangeStatus_rowNumInt_statusQString(rowNum, "Failed"); - emit Send_progressbar_Add(); - return 0;//如果启用stop位,则直接return - } - //============== 读取自定义分辨率设定 ============ - bool CustRes_isEnabled = false; - int CustRes_height=0; - int CustRes_width=0; - if(CustRes_isContained(SourceFile_fullPath)) - { - CustRes_isEnabled=true; - QMap Res_map = CustRes_getResMap(SourceFile_fullPath);//res_map["fullpath"],["height"],["width"] - CustRes_height=Res_map["height"].toInt(); - CustRes_width=Res_map["width"].toInt(); - } - //================= - QString AudioPath = file_path+"/Audio_"+file_name+"_"+file_ext+"_W2xEX.wav";//音频 - QString SplitFramesFolderPath = file_path+"/"+file_name+"_"+file_ext+"_SplitFrames_W2xEX";//拆分后存储frame的文件夹 - QString ScaledFramesFolderPath = SplitFramesFolderPath+"/ScaledFrames_W2xEX";//存储放大后的帧 - //=== - QString VideoClipsFolderPath = "";//存储视频片段的文件夹(完整路径) - QString DateStr = ""; - do - { - DateStr = video_getClipsFolderNo(); - VideoClipsFolderPath = file_path+"/"+DateStr+"_VideoClipsWaifu2xEX";//存储视频片段的文件夹(完整路径) - } - while(file_isDirExist(VideoClipsFolderPath)); - QString VideoClipsFolderName = DateStr+"_VideoClipsWaifu2xEX";//存储视频片段的文件夹(名称) - //========================== - // 检测之前的视频配置文件 - //========================== - QString VideoConfiguration_fullPath = file_path+"/VideoConfiguration_"+file_name+"_"+file_ext+"_Waifu2xEX.ini"; - if(QFile::exists(VideoConfiguration_fullPath)) - { - QSettings *configIniRead = new QSettings(VideoConfiguration_fullPath, QSettings::IniFormat); - configIniRead->setIniCodec(QTextCodec::codecForName("UTF-8")); - //=================== 加载之前存储的视频信息 ========================= - int ScaleRatio_old = configIniRead->value("/VideoConfiguration/ScaleRatio").toInt(); - int DenoiseLevel_old = configIniRead->value("/VideoConfiguration/DenoiseLevel").toInt(); - bool CustRes_isEnabled_old = configIniRead->value("/VideoConfiguration/CustRes_isEnabled").toBool(); - int CustRes_height_old = configIniRead->value("/VideoConfiguration/CustRes_height").toInt(); - int CustRes_width_old = configIniRead->value("/VideoConfiguration/CustRes_width").toInt(); - QString EngineName_old = configIniRead->value("/VideoConfiguration/EngineName").toString(); - bool isProcessBySegment_old = configIniRead->value("/VideoConfiguration/isProcessBySegment").toBool(); - bool isVideoFrameInterpolationEnabled_old = configIniRead->value("/VideoConfiguration/isVideoFrameInterpolationEnabled").toBool(); - int MultipleOfFPS_old = configIniRead->value("/VideoConfiguration/MultipleOfFPS").toInt(); - //=================== 比对信息 ================================ - if(EngineName_old=="srmd-ncnn-vulkan") - { - if(CustRes_isEnabled_old==false&&CustRes_isEnabled==false) - { - if(ScaleRatio_old!=ScaleRatio||DenoiseLevel_old!=DenoiseLevel) - { - isVideoConfigChanged=true; - } - else - { - isVideoConfigChanged=false; - } - } - else - { - if(CustRes_isEnabled_old==true&&CustRes_isEnabled==true) - { - if(CustRes_height_old!=CustRes_height||CustRes_width_old!=CustRes_width) - { - isVideoConfigChanged=true; - } - else - { - isVideoConfigChanged=false; - } - } - else - { - isVideoConfigChanged=true; - } - } - if(isProcessBySegment_old == false) - { - isVideoConfigChanged=true; - } - if(isVideoFrameInterpolationEnabled_old != ui->groupBox_FrameInterpolation->isChecked()) - { - isVideoConfigChanged=true; - } - if(MultipleOfFPS_old != ui->spinBox_MultipleOfFPS_VFI->value() && ui->groupBox_FrameInterpolation->isChecked()) - { - isVideoConfigChanged=true; - } - } - else - { - isVideoConfigChanged=true; - } - //============ 修正文件夹名称 ============= - QString VideoClipsFolderPath_old = configIniRead->value("/VideoConfiguration/VideoClipsFolderPath").toString(); - QString VideoClipsFolderName_old = configIniRead->value("/VideoConfiguration/VideoClipsFolderName").toString(); - file_mkDir(VideoClipsFolderPath_old); - if(file_isDirExist(VideoClipsFolderPath_old)==true) - { - VideoClipsFolderPath = VideoClipsFolderPath_old; - VideoClipsFolderName = VideoClipsFolderName_old; - } - } - else - { - emit Send_video_write_VideoConfiguration(VideoConfiguration_fullPath,ScaleRatio,DenoiseLevel,CustRes_isEnabled,CustRes_height,CustRes_width,"srmd-ncnn-vulkan",true,VideoClipsFolderPath,VideoClipsFolderName,ui->groupBox_FrameInterpolation->isChecked(),ui->spinBox_MultipleOfFPS_VFI->value()); - } - //======================= - // 检测缓存是否存在 - //======================= - if(file_isDirExist(SplitFramesFolderPath)) - { - if(!isVideoConfigChanged) - { - isCacheExists=true; - emit Send_TextBrowser_NewMessage(tr("The previous video cache file is detected and processing of the previous video cache will continue. If you want to restart processing of the current video:[")+SourceFile_fullPath+tr("], delete the cache manually.")); - } - else - { - isCacheExists=false; - //======== - QFile::remove(VideoConfiguration_fullPath); - file_DelDir(SplitFramesFolderPath); - file_DelDir(VideoClipsFolderPath); - QFile::remove(AudioPath); - DelVfiDir(video_mp4_fullpath); - emit Send_video_write_VideoConfiguration(VideoConfiguration_fullPath,ScaleRatio,DenoiseLevel,CustRes_isEnabled,CustRes_height,CustRes_width,"srmd-ncnn-vulkan",true,VideoClipsFolderPath,VideoClipsFolderName,ui->groupBox_FrameInterpolation->isChecked(),ui->spinBox_MultipleOfFPS_VFI->value()); - //======= - emit Send_TextBrowser_NewMessage(tr("The previous video cache file was detected, but because you changed the settings about the video resolution or denoise level, the previous cache will be deleted and processing of the video:[")+SourceFile_fullPath+tr("] will restart.")); - } - } - else - { - isCacheExists=false; - //======== - QFile::remove(VideoConfiguration_fullPath); - file_DelDir(SplitFramesFolderPath); - file_DelDir(VideoClipsFolderPath); - QFile::remove(AudioPath); - DelVfiDir(video_mp4_fullpath); - emit Send_video_write_VideoConfiguration(VideoConfiguration_fullPath,ScaleRatio,DenoiseLevel,CustRes_isEnabled,CustRes_height,CustRes_width,"srmd-ncnn-vulkan",true,VideoClipsFolderPath,VideoClipsFolderName,ui->groupBox_FrameInterpolation->isChecked(),ui->spinBox_MultipleOfFPS_VFI->value()); - //======== - } - /*==================================== - 提取音频 - ======================================*/ - if(!QFile::exists(AudioPath)) - { - video_get_audio(video_mp4_fullpath,AudioPath); - } - //================================== 开始分段处理视频 ================================================= - int StartTime = 0;//起始时间(秒) - int VideoDuration = video_get_duration(video_mp4_fullpath); - bool isSplitComplete = false; - bool isScaleComplete = false; - /* - ============================================ - 开始之前先读取进度 - ============================================ - */ - int OLD_SegmentDuration=-1; - bool read_OLD_SegmentDuration =false; - int LastVideoClipNo = -1; - if(QFile::exists(VideoConfiguration_fullPath)) - { - QSettings *configIniRead = new QSettings(VideoConfiguration_fullPath, QSettings::IniFormat); - configIniRead->setIniCodec(QTextCodec::codecForName("UTF-8")); - //=================== 加载进度 ========================= - StartTime = configIniRead->value("/Progress/StartTime").toInt(); - isSplitComplete = configIniRead->value("/Progress/isSplitComplete").toBool(); - isScaleComplete = configIniRead->value("/Progress/isScaleComplete").toBool(); - OLD_SegmentDuration = configIniRead->value("/Progress/OLDSegmentDuration").toInt(); - LastVideoClipNo = configIniRead->value("/Progress/LastVideoClipNo").toInt(); - } - if(OLD_SegmentDuration>0) - { - read_OLD_SegmentDuration = true; - } - /* - 加载进度条 - */ - int SegmentDuration_tmp_progressbar = 0; - if(read_OLD_SegmentDuration) - { - SegmentDuration_tmp_progressbar = OLD_SegmentDuration; - } - else - { - SegmentDuration_tmp_progressbar = SegmentDuration; - } - if(ui->checkBox_ShowInterPro->isChecked()&&VideoDuration>SegmentDuration_tmp_progressbar) - { - emit Send_CurrentFileProgress_Start(file_name+"."+file_ext,VideoDuration); - if(StartTime>0) - { - emit Send_CurrentFileProgress_progressbar_Add_SegmentDuration(StartTime); - } - } - /* - ============================================ - 正式开始处理 - ============================================ - */ - int SegmentDuration_tmp=0; - int TimeLeft_tmp=0; - while(VideoDuration>StartTime) - { - /*========================== - 计算视频片段时间 - ==========================*/ - TimeLeft_tmp = VideoDuration-StartTime; - if((TimeLeft_tmp)>=SegmentDuration) - { - SegmentDuration_tmp = SegmentDuration; - } - else - { - SegmentDuration_tmp = TimeLeft_tmp; - } - if(read_OLD_SegmentDuration) - { - SegmentDuration_tmp = OLD_SegmentDuration; - read_OLD_SegmentDuration=false; - } - /*========================== - 拆分视频片段 - ==========================*/ - if(isSplitComplete==false) - { - if(file_isDirExist(SplitFramesFolderPath)) - { - file_DelDir(SplitFramesFolderPath); - file_mkDir(SplitFramesFolderPath); - } - else - { - file_mkDir(SplitFramesFolderPath); - } - video_video2images_ProcessBySegment(video_mp4_fullpath,SplitFramesFolderPath,StartTime,SegmentDuration_tmp); - if(waifu2x_STOP) - { - emit Send_Table_video_ChangeStatus_rowNumInt_statusQString(rowNum, "Interrupted"); - return 0;//如果启用stop位,则直接return - } - } - /*========================== - 处理视频片段的帧 - ==========================*/ - bool isOverScaled=false; - if(isScaleComplete==false) - { - //============================== 扫描获取文件名 =============================== - QStringList Frame_fileName_list = file_getFileNames_in_Folder_nofilter(SplitFramesFolderPath); - if(isSplitComplete==false) - { - if(Frame_fileName_list.isEmpty())//检查是否成功拆分为帧 - { - emit Send_TextBrowser_NewMessage(tr("Error occured when processing [")+SourceFile_fullPath+tr("]. Error: [Unable to split video into pictures.]")); - emit Send_Table_video_ChangeStatus_rowNumInt_statusQString(rowNum, "Failed"); - emit Send_progressbar_Add(); - return 0;//如果启用stop位,则直接return - } - } - /* - 记录进度 - 帧拆分成功 - */ - emit Send_video_write_Progress_ProcessBySegment(VideoConfiguration_fullPath,StartTime,true,false,SegmentDuration_tmp,LastVideoClipNo); - //============================== 放大 ======================================= - //===========建立存储放大后frame的文件夹=========== - if(isSplitComplete==false) - { - if(file_isDirExist(ScaledFramesFolderPath)) - { - file_DelDir(ScaledFramesFolderPath); - file_mkDir(ScaledFramesFolderPath); - } - else - { - file_mkDir(ScaledFramesFolderPath); - } - } - //==========开始放大========================== - //读取放大倍数 - int ScaleRatio_Original = 2; - if(CustRes_isEnabled == true) - { - ScaleRatio_Original = CustRes_CalNewScaleRatio(video_mp4_fullpath,CustRes_height,CustRes_width); - } - else - { - ScaleRatio_Original = ui->doubleSpinBox_ScaleRatio_video->value(); - } - QMap result_map = Calculate_ScaleRatio_SrmdNcnnVulkan(ScaleRatio_Original); - int ScaleRatio_Max=result_map["ScaleRatio_tmp"]; - int Initial_ScaleRatio=result_map["Initial_ScaleRatio"]; - isOverScaled = (ScaleRatio_Max!=ScaleRatio_Original); - //读取初始放大倍率 - int Start_ScaleRatio_Video = Initial_ScaleRatio; - if(!Frame_fileName_list.isEmpty()) - { - QString Full_Path_File = ""; - for(int i = 0; i < Frame_fileName_list.size(); i++) - { - QString tmp = Frame_fileName_list.at(i); - Full_Path_File = SplitFramesFolderPath + "/" + tmp; - QFileInfo finfo(Full_Path_File); - if(finfo.suffix()=="png")break; - } - QImage qimage_original; - qimage_original.load(Full_Path_File); - int Frame_height = qimage_original.height(); - QMap res_map = video_get_Resolution(SourceFile_fullPath); - int Video_height = res_map["height"]; - if(Frame_height>0 && Video_height>0 && Frame_height>=Video_height)//判断是否读取失败 - { - Start_ScaleRatio_Video = Initial_ScaleRatio*(Frame_height/Video_height); - } - } - //初始化进度讯息 - int NumOfSplitFrames = Frame_fileName_list.size()+file_getFileNames_in_Folder_nofilter(ScaledFramesFolderPath).size(); - int CurrentFileProgress_MAX = 0; - int CurrentFileProgress_OLD = 0; - int CurrentFileProgress_New = 0; - if(ui->checkBox_ShowInterPro->isChecked()) - { - int NumOfRounds=0; - for(int ScaleRatio_Current_tmp=Start_ScaleRatio_Video; ScaleRatio_Current_tmp<=ScaleRatio_Max; ScaleRatio_Current_tmp*=Initial_ScaleRatio) - { - NumOfRounds++; - } - CurrentFileProgress_MAX =NumOfSplitFrames*NumOfRounds; - } - //读取配置讯息 - QString SRMD_NCNN_Vulkan_Settings_str = SrmdNcnnVulkan_ReadSettings_Video_GIF(ui->spinBox_ThreadNum_video_internal->value()); - QProcess *Waifu2x = new QProcess(); - QString program = Current_Path + "/srmd-ncnn-vulkan/srmd-ncnn-vulkan_waifu2xEX.exe"; - bool waifu2x_qprocess_failed = false; - int DenoiseLevel_tmp = DenoiseLevel; - int CountFinishedRounds=0; - //==== - for(int ScaleRatio_Current_tmp=Start_ScaleRatio_Video; ScaleRatio_Current_tmp<=ScaleRatio_Max && Frame_fileName_list.isEmpty()==false; ScaleRatio_Current_tmp*=Initial_ScaleRatio) - { - for(int retry=0; retry<(ui->spinBox_retry->value()+ForceRetryCount); retry++) - { - QString ErrorMSG=""; - QString StanderMSG=""; - //========== - waifu2x_qprocess_failed = false; - QString cmd = "\"" + program + "\"" + " -i " + "\"" + SplitFramesFolderPath + "\"" + " -o " + "\"" + ScaledFramesFolderPath + "\"" + " -s " + QString("%1").arg(Initial_ScaleRatio) + " -n " + QString::number(DenoiseLevel_tmp, 10) + SRMD_NCNN_Vulkan_Settings_str; - Waifu2x->start(cmd); - while(!Waifu2x->waitForStarted(100)&&!QProcess_stop) {} - while(!Waifu2x->waitForFinished(650)&&!QProcess_stop) - { - if(waifu2x_STOP) - { - QStringList FinfishedFileList_FileNames = WaitForEngineIO_NcnnVulkan(ScaledFramesFolderPath); - Waifu2x->close(); - //============ - QString file_name_tmp; - QStringList FileNames_ScaledFramesFolderPath = file_getFileNames_in_Folder_nofilter(ScaledFramesFolderPath); - for(int i=0; ireadAllStandardError().toLower()); - StanderMSG.append(Waifu2x->readAllStandardOutput().toLower()); - if(ErrorMSG.contains("failed")||StanderMSG.contains("failed")) - { - waifu2x_qprocess_failed = true; - Waifu2x->close(); - break; - } - if(ui->checkBox_ShowInterPro->isChecked()) - { - CurrentFileProgress_New = (NumOfSplitFrames*CountFinishedRounds)+file_getFileNames_in_Folder_nofilter(ScaledFramesFolderPath).size(); - if(CurrentFileProgress_New!=CurrentFileProgress_OLD) - { - emit Send_TextBrowser_NewMessage(tr("File name:[")+SourceFile_fullPath+tr("] Scale progress:[")+QString::number(CurrentFileProgress_New,10)+"/"+QString::number(CurrentFileProgress_MAX,10)+tr("] Duration progress:[")+QString::number(StartTime,10)+"s/"+QString::number(VideoDuration,10)+"s]"); - CurrentFileProgress_OLD=CurrentFileProgress_New; - } - } - } - //=============== - if(waifu2x_qprocess_failed==false) - { - ErrorMSG.append(Waifu2x->readAllStandardError().toLower()); - StanderMSG.append(Waifu2x->readAllStandardOutput().toLower()); - if(ErrorMSG.contains("failed")||StanderMSG.contains("failed")) - { - waifu2x_qprocess_failed = true; - } - } - //========= 检测是否成功,是否需要重试 ============ - if((NumOfSplitFrames == file_getFileNames_in_Folder_nofilter(ScaledFramesFolderPath).size())&&!waifu2x_qprocess_failed) - { - break; - } - else - { - //失败 - file_DelDir(ScaledFramesFolderPath); - file_mkDir(ScaledFramesFolderPath); - if(retry==ui->spinBox_retry->value()+(ForceRetryCount-1))break; - emit Send_TextBrowser_NewMessage(tr("Automatic retry, please wait.")); - Delay_sec_sleep(5); - } - } - //=========== - //根据轮数修改参数 - DenoiseLevel_tmp = -1; - if(ScaleRatio_Current_tmpcheckBox_ShowInterPro->isChecked()) - { - emit Send_CurrentFileProgress_progressbar_Add_SegmentDuration(SegmentDuration_tmp); - } - StartTime+=SegmentDuration_tmp; - isSplitComplete = false; - isScaleComplete = false; - LastVideoClipNo=VideoClipNo; - emit Send_video_write_Progress_ProcessBySegment(VideoConfiguration_fullPath,StartTime,false,false,-1,VideoClipNo); - } - emit Send_CurrentFileProgress_Stop(); - //====================================================== - // 组装(片段到成片) - //====================================================== - QString video_mp4_scaled_fullpath = ""; - if(CustRes_isEnabled) - { - video_mp4_scaled_fullpath = file_path+"/"+file_name+"_waifu2x_"+QString::number(CustRes_width,10)+"x"+QString::number(CustRes_height,10)+"_"+QString::number(DenoiseLevel,10)+"n"+"_"+file_ext+".mp4"; - } - else - { - video_mp4_scaled_fullpath = file_path+"/"+file_name+"_waifu2x_"+QString::number(ScaleRatio,10)+"x_"+QString::number(DenoiseLevel,10)+"n"+"_"+file_ext+".mp4"; - } - QFile::remove(video_mp4_scaled_fullpath); - video_AssembleVideoClips(VideoClipsFolderPath,VideoClipsFolderName,video_mp4_scaled_fullpath,AudioPath); - if(QFile::exists(video_mp4_scaled_fullpath)==false)//检查是否成功生成视频 - { - if(waifu2x_STOP) - { - emit Send_Table_video_ChangeStatus_rowNumInt_statusQString(rowNum, "Interrupted"); - return 0;//如果启用stop位,则直接return - } - emit Send_TextBrowser_NewMessage(tr("Error occured when processing [")+SourceFile_fullPath+tr("]. Error: [Unable to assemble video clips.]")); - emit Send_Table_video_ChangeStatus_rowNumInt_statusQString(rowNum, "Failed"); - emit Send_progressbar_Add(); - return 0;//如果启用stop位,则直接return - } - //============================== 删除缓存文件 ==================================================== - if(ui->checkBox_KeepVideoCache->isChecked()==false) - { - QFile::remove(VideoConfiguration_fullPath); - file_DelDir(SplitFramesFolderPath); - file_DelDir(VideoClipsFolderPath); - QFile::remove(AudioPath); - if(SourceFile_fullPath!=video_mp4_fullpath)QFile::remove(video_mp4_fullpath); - } - else - { - DelOriginal=false; - } - //============================= 删除原文件 & & 更新table status ============================ - if(DelOriginal) - { - if(ReplaceOriginalFile(SourceFile_fullPath,video_mp4_scaled_fullpath)==false) - { - if(QAction_checkBox_MoveToRecycleBin_checkBox_DelOriginal->isChecked()) - { - file_MoveToTrash(SourceFile_fullPath); - } - else - { - QFile::remove(SourceFile_fullPath); - } - } - emit Send_Table_video_ChangeStatus_rowNumInt_statusQString(rowNum, "Finished, original file deleted"); - } - else - { - emit Send_Table_video_ChangeStatus_rowNumInt_statusQString(rowNum, "Finished"); - } - //========== 移动到输出路径 ========= - if(ui->checkBox_OutPath_isEnabled->isChecked()) - { - MoveFileToOutputPath(video_mp4_scaled_fullpath,SourceFile_fullPath); - } - //============================ 更新进度条 ================================= - emit Send_progressbar_Add(); - //=========================== ============================== - return 0; -} -/* -SRMD 检测可用GPU -*/ -void MainWindow::on_pushButton_DetectGPUID_srmd_clicked() -{ - //=== - ui->pushButton_DetectGPUID_srmd->setText(tr("Detecting, please wait...")); - //=== - pushButton_Start_setEnabled_self(0); - ui->pushButton_DetectGPU->setEnabled(0); - ui->pushButton_DetectGPUID_srmd->setEnabled(0); - ui->pushButton_DumpProcessorList_converter->setEnabled(0); - ui->pushButton_ListGPUs_Anime4k->setEnabled(0); - ui->pushButton_compatibilityTest->setEnabled(0); - ui->pushButton_DetectGPU_RealsrNCNNVulkan->setEnabled(0); - Available_GPUID_srmd.clear(); - QtConcurrent::run(this, &MainWindow::SRMD_DetectGPU); -} - -int MainWindow::SRMD_DetectGPU() -{ - emit Send_TextBrowser_NewMessage(tr("Detecting available GPU, please wait.")); - //=============== - QString InputPath = Current_Path + "/Compatibility_Test/Compatibility_Test.jpg"; - QString OutputPath = Current_Path + "/Compatibility_Test/res.png"; - QFile::remove(OutputPath); - //============== - QString Waifu2x_folder_path = Current_Path + "/srmd-ncnn-vulkan"; - QString program = Waifu2x_folder_path + "/srmd-ncnn-vulkan_waifu2xEX.exe"; - QString model_path = Waifu2x_folder_path+"/models-srmd"; - //========= - int GPU_ID=-1; - //========= - while(true) - { - QFile::remove(OutputPath); - QProcess *Waifu2x = new QProcess(); - QString gpu_str = " -g "+QString::number(GPU_ID,10)+" "; - QString cmd = "\"" + program + "\"" + " -i " + "\"" + InputPath + "\"" + " -o " + "\"" + OutputPath + "\"" + " -s 2 -n 0 -t 32 -m " + "\"" + model_path + "\"" + " -j 1:1:1"+gpu_str; - Waifu2x->start(cmd); - while(!Waifu2x->waitForStarted(100)&&!QProcess_stop) {} - while(!Waifu2x->waitForFinished(100)&&!QProcess_stop) {} - if(QFile::exists(OutputPath) && (Waifu2x->readAllStandardError().toLower().contains("failed")||Waifu2x->readAllStandardOutput().toLower().contains("failed"))==false) - { - Available_GPUID_srmd.append(QString::number(GPU_ID,10)); - GPU_ID++; - QFile::remove(OutputPath); - } - else - { - if(GPU_ID > -1) - { - break; - } - else - { - GPU_ID++; - } - } - } - QFile::remove(OutputPath); - //=============== - emit Send_TextBrowser_NewMessage(tr("Detection is complete!")); - if(Available_GPUID_srmd.isEmpty()) - { - Send_TextBrowser_NewMessage(tr("No available GPU ID detected!")); - } - emit Send_SRMD_DetectGPU_finished(); - return 0; -} - -void MainWindow::SRMD_DetectGPU_finished() -{ - pushButton_Start_setEnabled_self(1); - ui->pushButton_DetectGPU->setEnabled(1); - ui->pushButton_compatibilityTest->setEnabled(1); - ui->pushButton_DetectGPUID_srmd->setEnabled(1); - ui->pushButton_DumpProcessorList_converter->setEnabled(1); - on_checkBox_SpecifyGPU_Anime4k_stateChanged(1); - ui->pushButton_DetectGPU_RealsrNCNNVulkan->setEnabled(1); - //==== - GPUIDs_List_MultiGPU_SrmdNcnnVulkan.clear(); - ui->comboBox_GPUIDs_MultiGPU_SrmdNCNNVulkan->clear(); - ui->comboBox_GPUID_srmd->clear(); - ui->comboBox_GPUID_srmd->addItem("auto"); - if(!Available_GPUID_srmd.isEmpty()) - { - for(int i=0; icomboBox_GPUID_srmd->addItem(Available_GPUID_srmd.at(i)); - AddGPU_MultiGPU_SrmdNcnnVulkan(Available_GPUID_srmd.at(i)); - } - } - //=== - ui->pushButton_DetectGPUID_srmd->setText(tr("Detect available GPU ID")); - //=== -} -/* -预读取SRMD引擎设定 -*/ -QString MainWindow::SrmdNcnnVulkan_PreLoad_Settings() -{ - QString SrmdNcnnVulkan_Settings_str = " "; - //TTA - if(ui->checkBox_TTA_srmd->isChecked()) - { - SrmdNcnnVulkan_Settings_str.append("-x "); - } - if(ui->checkBox_MultiGPU_SrmdNCNNVulkan->isChecked()==false) - { - //==========单显卡========== - //GPU ID - if(ui->comboBox_GPUID_srmd->currentText()!="auto") - { - SrmdNcnnVulkan_Settings_str.append("-g "+ui->comboBox_GPUID_srmd->currentText()+" "); - } - //Tile Size - SrmdNcnnVulkan_Settings_str.append("-t "+QString::number(ui->spinBox_TileSize_srmd->value(),10)+" "); - } - //Model - QString SrmdNcnnVulkan_folder_path = Current_Path + "/srmd-ncnn-vulkan"; - QString model_path = SrmdNcnnVulkan_folder_path+"/models-srmd"; - SrmdNcnnVulkan_Settings_str.append("-m \""+model_path+"\" "); - SrmdNcnnVulkan_Settings_str.append("-j 1:1:1 "); - //======================================= - return SrmdNcnnVulkan_Settings_str; -} - -/* -读取SRMD引擎设置 -*/ -QString MainWindow::SrmdNcnnVulkan_ReadSettings() -{ - QString SrmdNcnnVulkan_Settings_str = ""; - SrmdNcnnVulkan_Settings_str.append(SrmdNcnnVulkan_PreLoad_Settings_Str); - if(ui->checkBox_MultiGPU_SrmdNCNNVulkan->isChecked()) - { - //==========多显卡========== - QMap GPUInfo = SrmdNcnnVulkan_MultiGPU(); - //GPU ID - SrmdNcnnVulkan_Settings_str.append("-g "+GPUInfo["ID"]+" "); - //Tile Size - SrmdNcnnVulkan_Settings_str.append("-t "+GPUInfo["TileSize"]+" "); - } - //======================================= - return SrmdNcnnVulkan_Settings_str; -} - - -/* -SrmdNCNNVulkan_MultiGPU -显卡切换 -*/ -QMap MainWindow::SrmdNcnnVulkan_MultiGPU() -{ - MultiGPU_QMutex_SrmdNcnnVulkan.lock(); - //==== - int MAX_GPU_ID_SrmdNcnnVulkan = GPUIDs_List_MultiGPU_SrmdNcnnVulkan.size()-1; - if(GPU_ID_SrmdNcnnVulkan_MultiGPU>MAX_GPU_ID_SrmdNcnnVulkan) - { - GPU_ID_SrmdNcnnVulkan_MultiGPU=0; - } - //====== - QMap GPUInfo; - do - { - GPUInfo = GPUIDs_List_MultiGPU_SrmdNcnnVulkan.at(GPU_ID_SrmdNcnnVulkan_MultiGPU); - if(GPUInfo["isEnabled"] != "true") - { - GPU_ID_SrmdNcnnVulkan_MultiGPU++; - if(GPU_ID_SrmdNcnnVulkan_MultiGPU>MAX_GPU_ID_SrmdNcnnVulkan) - { - GPU_ID_SrmdNcnnVulkan_MultiGPU=0; - } - } - else - { - break; - } - } - while(true); - //====== - GPU_ID_SrmdNcnnVulkan_MultiGPU++; - if(GPU_ID_SrmdNcnnVulkan_MultiGPU>MAX_GPU_ID_SrmdNcnnVulkan) - { - GPU_ID_SrmdNcnnVulkan_MultiGPU=0; - } - //====== - MultiGPU_QMutex_SrmdNcnnVulkan.unlock(); - return GPUInfo; -} - -void MainWindow::AddGPU_MultiGPU_SrmdNcnnVulkan(QString GPUID) -{ - QMap GPUInfo; - GPUInfo["ID"] = GPUID; - GPUInfo["isEnabled"] = "true"; - GPUInfo["TileSize"] = "100"; - GPUIDs_List_MultiGPU_SrmdNcnnVulkan.append(GPUInfo); - ui->comboBox_GPUIDs_MultiGPU_SrmdNCNNVulkan->addItem(GPUID); - ui->comboBox_GPUIDs_MultiGPU_SrmdNCNNVulkan->setCurrentIndex(0); -} - -void MainWindow::on_checkBox_MultiGPU_SrmdNCNNVulkan_stateChanged(int arg1) -{ - if(ui->checkBox_MultiGPU_SrmdNCNNVulkan->isChecked()) - { - ui->comboBox_GPUID_srmd->setEnabled(0); - ui->frame_TileSize_SrmdNcnnVulkan->setEnabled(0); - ui->groupBox_GPUSettings_MultiGPU_SrmdNCNNVulkan->setEnabled(1); - } - else - { - ui->comboBox_GPUID_srmd->setEnabled(1); - ui->frame_TileSize_SrmdNcnnVulkan->setEnabled(1); - ui->groupBox_GPUSettings_MultiGPU_SrmdNCNNVulkan->setEnabled(0); - } -} - -void MainWindow::on_checkBox_MultiGPU_SrmdNCNNVulkan_clicked() -{ - if(ui->checkBox_MultiGPU_SrmdNCNNVulkan->isChecked()) - { - if(GPUIDs_List_MultiGPU_SrmdNcnnVulkan.size()==0) - { - QMessageBox *MSG = new QMessageBox(); - MSG->setWindowTitle(tr("Notification")); - MSG->setText(tr("Please detect available GPU ID before enable Multi-GPU.")); - MSG->setIcon(QMessageBox::Information); - MSG->setModal(true); - MSG->show(); - ui->checkBox_MultiGPU_SrmdNCNNVulkan->setChecked(0); - return; - } - if(GPUIDs_List_MultiGPU_SrmdNcnnVulkan.size()<2) - { - QMessageBox *MSG = new QMessageBox(); - MSG->setWindowTitle(tr("Error")); - MSG->setText(tr("Insufficient number of available GPUs.")); - MSG->setIcon(QMessageBox::Warning); - MSG->setModal(true); - MSG->show(); - ui->checkBox_MultiGPU_SrmdNCNNVulkan->setChecked(0); - return; - } - } -} - -void MainWindow::on_checkBox_isEnable_CurrentGPU_MultiGPU_SrmdNCNNVulkan_clicked() -{ - QMap GPUInfo=GPUIDs_List_MultiGPU_SrmdNcnnVulkan.at(ui->comboBox_GPUIDs_MultiGPU_SrmdNCNNVulkan->currentIndex()); - if(ui->checkBox_isEnable_CurrentGPU_MultiGPU_SrmdNCNNVulkan->isChecked()) - { - GPUInfo["isEnabled"] = "true"; - } - else - { - GPUInfo["isEnabled"] = "false"; - } - GPUIDs_List_MultiGPU_SrmdNcnnVulkan.replace(ui->comboBox_GPUIDs_MultiGPU_SrmdNCNNVulkan->currentIndex(),GPUInfo); - int enabledGPUs = 0; - for (int i=0; i GPUInfo_tmp = GPUIDs_List_MultiGPU_SrmdNcnnVulkan.at(i); - if(GPUInfo_tmp["isEnabled"] == "true") - { - enabledGPUs++; - } - } - if(enabledGPUs<2) - { - QMap GPUInfo=GPUIDs_List_MultiGPU_SrmdNcnnVulkan.at(ui->comboBox_GPUIDs_MultiGPU_SrmdNCNNVulkan->currentIndex()); - GPUInfo["isEnabled"] = "true"; - GPUIDs_List_MultiGPU_SrmdNcnnVulkan.replace(ui->comboBox_GPUIDs_MultiGPU_SrmdNCNNVulkan->currentIndex(),GPUInfo); - ui->checkBox_isEnable_CurrentGPU_MultiGPU_SrmdNCNNVulkan->setChecked(1); - QMessageBox *MSG = new QMessageBox(); - MSG->setWindowTitle(tr("Warning")); - MSG->setText(tr("At least 2 GPUs need to be enabled !!")); - MSG->setIcon(QMessageBox::Warning); - MSG->setModal(true); - MSG->show(); - } -} - -void MainWindow::on_comboBox_GPUIDs_MultiGPU_SrmdNCNNVulkan_currentIndexChanged(int index) -{ - if(ui->comboBox_GPUIDs_MultiGPU_SrmdNCNNVulkan->count()==0) - { - return; - } - QMap GPUInfo=GPUIDs_List_MultiGPU_SrmdNcnnVulkan.at(ui->comboBox_GPUIDs_MultiGPU_SrmdNCNNVulkan->currentIndex()); - ui->checkBox_isEnable_CurrentGPU_MultiGPU_SrmdNCNNVulkan->setChecked(GPUInfo["isEnabled"] == "true"); - ui->spinBox_TileSize_CurrentGPU_MultiGPU_SrmdNCNNVulkan->setValue(GPUInfo["TileSize"].toInt()); -} - -void MainWindow::on_spinBox_TileSize_CurrentGPU_MultiGPU_SrmdNCNNVulkan_valueChanged(int arg1) -{ - QMap GPUInfo=GPUIDs_List_MultiGPU_SrmdNcnnVulkan.at(ui->comboBox_GPUIDs_MultiGPU_SrmdNCNNVulkan->currentIndex()); - GPUInfo["TileSize"] = QString::number(ui->spinBox_TileSize_CurrentGPU_MultiGPU_SrmdNCNNVulkan->value(),10); - GPUIDs_List_MultiGPU_SrmdNcnnVulkan.replace(ui->comboBox_GPUIDs_MultiGPU_SrmdNCNNVulkan->currentIndex(),GPUInfo); -} - -void MainWindow::on_pushButton_ShowMultiGPUSettings_SrmdNCNNVulkan_clicked() -{ - int Max_GPU_ID = GPUIDs_List_MultiGPU_SrmdNcnnVulkan.size(); - QString MultiGPUSettings_str=""; - for(int GPU_ID=0; GPU_ID GPUInfo = GPUIDs_List_MultiGPU_SrmdNcnnVulkan.at(GPU_ID); - if(GPUInfo["isEnabled"] != "true") - { - continue; - } - else - { - MultiGPUSettings_str.append("GPU ID:["+GPUInfo["ID"]+"] | "+tr("Tile size:")+"["+GPUInfo["TileSize"]+"]\n\n"); - } - } - //========= - QMessageBox *MSG = new QMessageBox(); - MSG->setWindowTitle(tr("Current Multi-GPU settings")); - MSG->setText(MultiGPUSettings_str); - MSG->setIcon(QMessageBox::Information); - MSG->setModal(true); - MSG->show(); -} -/* -SRMD 块大小调整按钮 -*/ -void MainWindow::on_pushButton_Add_TileSize_SrmdNCNNVulkan_clicked() -{ - ui->spinBox_TileSize_srmd->setValue(AddTileSize_NCNNVulkan_Converter(ui->spinBox_TileSize_srmd->value())); -} - -void MainWindow::on_pushButton_Minus_TileSize_SrmdNCNNVulkan_clicked() -{ - ui->spinBox_TileSize_srmd->setValue(MinusTileSize_NCNNVulkan_Converter(ui->spinBox_TileSize_srmd->value())); -} -/* -SRMD 计算放大倍数 -result_map["ScaleRatio_tmp"] = ScaleRatio_tmp; -result_map["Initial_ScaleRatio"] = Initial_ScaleRatio; -*/ -QMap MainWindow::Calculate_ScaleRatio_SrmdNcnnVulkan(int ScaleRatio) -{ - int ScaleRatio_tmp=0; - int Initial_ScaleRatio=0; - do - { - //判断是否为1 - if(ScaleRatio<=1) - { - ScaleRatio_tmp = 2; - Initial_ScaleRatio = 2; - break; - } - //判断是否为原生支持的倍率 - if(ScaleRatio>=2&&ScaleRatio<=4) - { - ScaleRatio_tmp=ScaleRatio; - Initial_ScaleRatio=ScaleRatio; - break; - } - //若不是原生支持,则判断是否为2,3,4中某个数的幂 - //开始判断是否是3的幂 - if(387420489%ScaleRatio==0) - { - ScaleRatio_tmp = ScaleRatio; - Initial_ScaleRatio = 3; - break; - } - //开始判断是否是2和4的幂,先转换为偶数 - if((ScaleRatio%2)==0) - { - ScaleRatio_tmp = ScaleRatio; - } - else - { - ScaleRatio_tmp = ScaleRatio+1; - } - //判断是否是4的幂 - if((((ScaleRatio_tmp&(ScaleRatio_tmp-1))==0)&&(ScaleRatio_tmp&0x555555555))==true) - { - Initial_ScaleRatio = 4; - break; - } - //判断是否是2的幂 - if((ScaleRatio_tmp&(ScaleRatio_tmp-1))==0) - { - Initial_ScaleRatio = 2; - break; - } - //谁的幂都不是,就比谁更近 - int res_2=0; - int res_3=0; - int res_4=0; - int pow_ = 0; - for(int i=1; true; i++) - { - pow_ =pow(2,i); - if(pow_>=ScaleRatio) - { - res_2=pow_; - break; - } - } - for(int i=1; true; i++) - { - pow_ =pow(3,i); - if(pow_>=ScaleRatio) - { - res_3=pow_; - break; - } - } - for(int i=1; true; i++) - { - pow_ =pow(4,i); - if(pow_>=ScaleRatio) - { - res_4=pow_; - break; - } - } - QList sort_list; - sort_list<=ScaleRatio_tmp) - { - ScaleRatio_tmp=pow_; - break; - } - } - } - break; - } - while(false); - QMap result_map; - result_map["ScaleRatio_tmp"] = ScaleRatio_tmp; - result_map["Initial_ScaleRatio"] = Initial_ScaleRatio; - return result_map; -} -/* -读取SRMD引擎设置 - -GIF 和 Video -*/ -QString MainWindow::SrmdNcnnVulkan_ReadSettings_Video_GIF(int ThreadNum) -{ - QString SrmdNcnnVulkan_Settings_str = " "; - //TTA - if(ui->checkBox_TTA_srmd->isChecked()) - { - SrmdNcnnVulkan_Settings_str.append("-x "); - } - if(ui->checkBox_MultiGPU_SrmdNCNNVulkan->isChecked()==false) - { - //==========单显卡========== - //GPU ID - if(ui->comboBox_GPUID_srmd->currentText()!="auto") - { - SrmdNcnnVulkan_Settings_str.append("-g "+ui->comboBox_GPUID_srmd->currentText()+" "); - } - //Tile Size - SrmdNcnnVulkan_Settings_str.append("-t "+QString::number(ui->spinBox_TileSize_srmd->value(),10)+" "); - //线程数量 - QString jobs_num_str = QString("%1").arg(ThreadNum); - SrmdNcnnVulkan_Settings_str.append("-j "+jobs_num_str+":"+jobs_num_str+":"+jobs_num_str+" "); - } - else - { - //==============多显卡================ - int NumOfGPUs_Available = GPUIDs_List_MultiGPU_SrmdNcnnVulkan.size();//获取显卡总数 - int NumOfGPUs_Enabled = 0; - QString GPU_ID_cmd = "-g "; - QString TileSize_cmd = "-t "; - for(int i=0; i GPUInfo = GPUIDs_List_MultiGPU_SrmdNcnnVulkan.at(i); - if(GPUInfo["isEnabled"] != "true")continue; - NumOfGPUs_Enabled++; - if(i==0) - { - GPU_ID_cmd.append(GPUInfo["ID"]); - TileSize_cmd.append(GPUInfo["TileSize"]); - } - else - { - GPU_ID_cmd.append(","+GPUInfo["ID"]); - TileSize_cmd.append(","+GPUInfo["TileSize"]); - } - } - SrmdNcnnVulkan_Settings_str.append(GPU_ID_cmd+" "); - SrmdNcnnVulkan_Settings_str.append(TileSize_cmd+" "); - //线程数量 - int NumOfThreads_PerGPU = ThreadNum/NumOfGPUs_Enabled; - if(NumOfThreads_PerGPU<1)NumOfThreads_PerGPU=1; - int LoadAndWrite_tnum = NumOfGPUs_Enabled*NumOfThreads_PerGPU; - QString Jobs_cmd = ""; - for(int i=0; i Res_map = CustRes_getResMap(sourceFileFullPath);//res_map["fullpath"],["height"],["width"] - ScaleRatio_Original = CustRes_CalNewScaleRatio(sourceFileFullPath,Res_map["height"].toInt(),Res_map["width"].toInt()); - } - else - { - ScaleRatio_Original = ui->doubleSpinBox_ScaleRatio_gif->value(); - } - QMap result_map = Calculate_ScaleRatio_SrmdNcnnVulkan(ScaleRatio_Original); - int ScaleRatio_Max=result_map["ScaleRatio_tmp"]; - int Initial_ScaleRatio=result_map["Initial_ScaleRatio"]; - bool isOverScaled = (ScaleRatio_Max!=ScaleRatio_Original); - //初始化进度讯息 - int NumOfSplitFrames = framesFileName_qStrList.size(); - if(ui->checkBox_ShowInterPro->isChecked()) - { - int NumOfRounds=0; - for(int ScaleRatio_Current_tmp=Initial_ScaleRatio; ScaleRatio_Current_tmp<=ScaleRatio_Max; ScaleRatio_Current_tmp*=Initial_ScaleRatio) - { - NumOfRounds++; - } - emit Send_CurrentFileProgress_Start(file_getBaseName(sourceFileFullPath)+"."+sourceFileFullPath.split(".").last(),NumOfSplitFrames*NumOfRounds); - } - //读取配置讯息 - QString SRMD_NCNN_Vulkan_Settings_str = SrmdNcnnVulkan_ReadSettings_Video_GIF(ui->spinBox_ThreadNum_gif_internal->value()); - QProcess *Waifu2x = new QProcess(); - QString program = Current_Path + "/srmd-ncnn-vulkan/srmd-ncnn-vulkan_waifu2xEX.exe"; - bool waifu2x_qprocess_failed = false; - int DenoiseLevel_tmp = ui->spinBox_DenoiseLevel_gif->value(); - int CountFinishedRounds=0; - //==== - for(int ScaleRatio_Current_tmp=Initial_ScaleRatio; ScaleRatio_Current_tmp<=ScaleRatio_Max && framesFileName_qStrList.isEmpty()==false; ScaleRatio_Current_tmp*=Initial_ScaleRatio) - { - for(int retry=0; retry<(ui->spinBox_retry->value()+ForceRetryCount); retry++) - { - QString ErrorMSG=""; - QString StanderMSG=""; - //========== - waifu2x_qprocess_failed = false; - QString cmd = "\"" + program + "\"" + " -i " + "\"" + splitFramesFolder + "\"" + " -o " + "\"" + scaledFramesFolder + "\"" + " -s " + QString("%1").arg(Initial_ScaleRatio) + " -n " + QString::number(DenoiseLevel_tmp, 10) + SRMD_NCNN_Vulkan_Settings_str; - Waifu2x->start(cmd); - while(!Waifu2x->waitForStarted(100)&&!QProcess_stop) {} - while(!Waifu2x->waitForFinished(650)&&!QProcess_stop) - { - if(waifu2x_STOP) - { - Waifu2x->close(); - mutex_ThreadNumRunning.lock(); - ThreadNumRunning--; - mutex_ThreadNumRunning.unlock(); - return false; - } - ErrorMSG.append(Waifu2x->readAllStandardError().toLower()); - StanderMSG.append(Waifu2x->readAllStandardOutput().toLower()); - if(ErrorMSG.contains("failed")||StanderMSG.contains("failed")) - { - waifu2x_qprocess_failed = true; - Waifu2x->close(); - break; - } - if(ui->checkBox_ShowInterPro->isChecked()) - { - emit Send_CurrentFileProgress_progressbar_SetFinishedValue((NumOfSplitFrames*CountFinishedRounds)+file_getFileNames_in_Folder_nofilter(scaledFramesFolder).size()); - } - } - //=============== - if(waifu2x_qprocess_failed==false) - { - ErrorMSG.append(Waifu2x->readAllStandardError().toLower()); - StanderMSG.append(Waifu2x->readAllStandardOutput().toLower()); - if(ErrorMSG.contains("failed")||StanderMSG.contains("failed")) - { - waifu2x_qprocess_failed = true; - } - } - //========= 检测是否成功,是否需要重试 ============ - if((NumOfSplitFrames == file_getFileNames_in_Folder_nofilter(scaledFramesFolder).size())&&!waifu2x_qprocess_failed) - { - break; - } - else - { - //失败 - file_DelDir(scaledFramesFolder); - file_mkDir(scaledFramesFolder); - if(retry==ui->spinBox_retry->value()+(ForceRetryCount-1))break; - emit Send_TextBrowser_NewMessage(tr("Automatic retry, please wait.")); - Delay_sec_sleep(5); - } - } - //=========== - //根据轮数修改参数 - DenoiseLevel_tmp = -1; - if(ScaleRatio_Current_tmp. + + My Github homepage: https://github.com/AaronFeng753 +*/ + +#include "mainwindow.h" +#include "ui_mainwindow.h" + +int MainWindow::SRMD_NCNN_Vulkan_Image(int rowNum,bool ReProcess_MissingAlphaChannel) +{ + //============================= 读取设置 ================================ + int DenoiseLevel = ui->spinBox_DenoiseLevel_image->value(); + bool DelOriginal = (ui->checkBox_DelOriginal->isChecked()||ui->checkBox_ReplaceOriginalFile->isChecked()); + QString OutPutPath_Final =""; + //========================= 拆解map得到参数 ============================= + //将状态设定到处理中 + emit Send_Table_image_ChangeStatus_rowNumInt_statusQString(rowNum, "Processing"); + //得到原文件路径 + QString SourceFile_fullPath = Table_model_image->item(rowNum,2)->text(); + if(!QFile::exists(SourceFile_fullPath))//判断源文件是否存在 + { + emit Send_TextBrowser_NewMessage(tr("Error occured when processing [")+SourceFile_fullPath+tr("]. Error: [File does not exist.]")); + emit Send_Table_image_ChangeStatus_rowNumInt_statusQString(rowNum, "Failed"); + emit Send_progressbar_Add(); + mutex_ThreadNumRunning.lock(); + ThreadNumRunning--; + mutex_ThreadNumRunning.unlock();//线程数量统计-1 + return 0; + } + //========= 转换到 PNG ========= + QString SourceFile_fullPath_Original = SourceFile_fullPath; + SourceFile_fullPath = Imgae_PreProcess(SourceFile_fullPath_Original,ReProcess_MissingAlphaChannel); + //=============== + int ScaleRatio=2; + bool CustRes_isEnabled = false; + int CustRes_height=0; + int CustRes_width=0; + //检查是是否有自定义分辨率 + if(CustRes_isContained(SourceFile_fullPath_Original)) + { + CustRes_isEnabled=true; + QMap Res_map = CustRes_getResMap(SourceFile_fullPath_Original);//res_map["fullpath"],["height"],["width"] + ScaleRatio = CustRes_CalNewScaleRatio(SourceFile_fullPath,Res_map["height"].toInt(),Res_map["width"].toInt()); + if(ScaleRatio==0) + { + emit Send_TextBrowser_NewMessage(tr("Error occured when processing [")+SourceFile_fullPath_Original+tr("]. Error: [The resolution of the source file cannot be read, so the image cannot be scaled to a custom resolution.]")); + emit Send_Table_image_ChangeStatus_rowNumInt_statusQString(rowNum, "Failed"); + emit Send_progressbar_Add(); + mutex_ThreadNumRunning.lock(); + ThreadNumRunning--; + mutex_ThreadNumRunning.unlock();//线程数量统计-1 + return 0; + } + CustRes_height=Res_map["height"].toInt(); + CustRes_width=Res_map["width"].toInt(); + } + else + { + double ScaleRatio_double_tmp = ui->doubleSpinBox_ScaleRatio_image->value(); + if(ScaleRatio_double_tmp == (int)ScaleRatio_double_tmp) + { + ScaleRatio = qRound(ScaleRatio_double_tmp); + } + else + { + CustRes_isEnabled=true; + QMap Res_map = DoubleScaleRatio_Cal_NewScaleRatio_NewHW(SourceFile_fullPath,ScaleRatio_double_tmp); + //==== + if(Res_map.isEmpty()) + { + emit Send_TextBrowser_NewMessage(tr("Error occured when processing [")+SourceFile_fullPath+tr("]. Error: [Unable to read the resolution of the source file.]")); + emit Send_Table_image_ChangeStatus_rowNumInt_statusQString(rowNum, "Failed"); + emit Send_progressbar_Add(); + mutex_ThreadNumRunning.lock(); + ThreadNumRunning--; + mutex_ThreadNumRunning.unlock();//线程数量统计-1 + return 0; + } + //==== + ScaleRatio = Res_map["ScaleRatio"].toInt(); + CustRes_height = Res_map["Height_new"].toInt(); + CustRes_width = Res_map["width_new"].toInt(); + } + } + //=============== + QFileInfo fileinfo(SourceFile_fullPath); + QString file_name = file_getBaseName(SourceFile_fullPath); + QString file_ext = fileinfo.suffix(); + QString file_path = file_getFolderPath(fileinfo); + QString OutPut_Path = file_path + "/" + file_name + "_waifu2x_"+QString::number(ScaleRatio, 10)+"x_"+QString::number(DenoiseLevel, 10)+"n_"+file_ext+".png"; + //============================== 放大 ======================================= + QProcess *Waifu2x = new QProcess(); + QString Waifu2x_folder_path = Current_Path + "/srmd-ncnn-vulkan"; + QString program = Waifu2x_folder_path + "/srmd-ncnn-vulkan_waifu2xEX.exe"; + //========== + QMap result_map = Calculate_ScaleRatio_SrmdNcnnVulkan(ScaleRatio); + int ScaleRatio_tmp=result_map["ScaleRatio_tmp"]; + int Initial_ScaleRatio=result_map["Initial_ScaleRatio"]; + //====== + QString InputPath_tmp = SourceFile_fullPath; + QString OutputPath_tmp =""; + for(int retry=0; retry<(ui->spinBox_retry->value()+ForceRetryCount); retry++) + { + bool waifu2x_qprocess_failed = false; + InputPath_tmp = SourceFile_fullPath; + OutputPath_tmp =""; + int DenoiseLevel_tmp = DenoiseLevel; + for(int i=Initial_ScaleRatio; i<=ScaleRatio_tmp; i*=Initial_ScaleRatio) + { + QString ErrorMSG=""; + QString StanderMSG=""; + //========== + OutputPath_tmp = file_path + "/" + file_name + "_waifu2x_"+QString::number(i, 10)+"x_"+QString::number(DenoiseLevel, 10)+"n_"+file_ext+".png"; + QString cmd = "\"" + program + "\"" + " -i " + "\"" + InputPath_tmp + "\"" + " -o " + "\"" + OutputPath_tmp + "\"" + " -s " + QString::number(Initial_ScaleRatio, 10) + " -n " + QString::number(DenoiseLevel_tmp, 10) + SrmdNcnnVulkan_ReadSettings(); + Waifu2x->start(cmd); + while(!Waifu2x->waitForStarted(100)&&!QProcess_stop) {} + while(!Waifu2x->waitForFinished(500)&&!QProcess_stop) + { + if(waifu2x_STOP) + { + Waifu2x->close(); + if(i>Initial_ScaleRatio) + { + QFile::remove(InputPath_tmp); + } + QFile::remove(OutputPath_tmp); + emit Send_Table_image_ChangeStatus_rowNumInt_statusQString(rowNum, "Interrupted"); + mutex_ThreadNumRunning.lock(); + ThreadNumRunning--; + mutex_ThreadNumRunning.unlock(); + return 0; + } + ErrorMSG.append(Waifu2x->readAllStandardError().toLower()); + StanderMSG.append(Waifu2x->readAllStandardOutput().toLower()); + if(ErrorMSG.contains("failed")||StanderMSG.contains("failed")) + { + waifu2x_qprocess_failed = true; + Waifu2x->close(); + if(i>Initial_ScaleRatio) + { + QFile::remove(InputPath_tmp); + } + QFile::remove(OutputPath_tmp); + break; + } + } + //=============== + if(waifu2x_qprocess_failed)break; + //=============== + ErrorMSG.append(Waifu2x->readAllStandardError().toLower()); + StanderMSG.append(Waifu2x->readAllStandardOutput().toLower()); + if(ErrorMSG.contains("failed")||StanderMSG.contains("failed")) + { + waifu2x_qprocess_failed = true; + if(i>Initial_ScaleRatio) + { + QFile::remove(InputPath_tmp); + } + QFile::remove(OutputPath_tmp); + break; + } + //=============== + if(i>Initial_ScaleRatio) + { + QFile::remove(InputPath_tmp); + } + DenoiseLevel_tmp = -1; + InputPath_tmp = OutputPath_tmp; + } + //========= 检测是否成功,是否需要重试 ============ + if(QFile::exists(OutputPath_tmp)&&!waifu2x_qprocess_failed) + { + break; + } + else + { + QFile::remove(OutputPath_tmp); + if(retry==ui->spinBox_retry->value()+(ForceRetryCount-1))break; + emit Send_TextBrowser_NewMessage(tr("Automatic retry, please wait.")); + Delay_sec_sleep(5); + } + } + if(!QFile::exists(OutputPath_tmp)) + { + if(SourceFile_fullPath_Original!=SourceFile_fullPath) + { + QFile::remove(SourceFile_fullPath); + } + emit Send_TextBrowser_NewMessage(tr("Error occured when processing [")+SourceFile_fullPath_Original+tr("]. Error: [Unable to scale the picture.]")); + emit Send_Table_image_ChangeStatus_rowNumInt_statusQString(rowNum, "Failed"); + emit Send_progressbar_Add(); + mutex_ThreadNumRunning.lock(); + ThreadNumRunning--; + mutex_ThreadNumRunning.unlock(); + return 0; + } + OutPutPath_Final = OutputPath_tmp; + //============================ 调整大小 ==================================================== + if(ScaleRatio_tmp != ScaleRatio||CustRes_isEnabled) + { + int New_height=0; + int New_width=0; + if(CustRes_isEnabled) + { + New_height= CustRes_height; + New_width= CustRes_width; + } + else + { + QMap res_map_OriginalFile = Image_Gif_Read_Resolution(SourceFile_fullPath); + New_height = res_map_OriginalFile["height"]*ScaleRatio; + New_width = res_map_OriginalFile["width"]*ScaleRatio; + } + QImage qimage_adj(OutputPath_tmp); + //读取放大后的图片并调整大小 + QImage qimage_adj_scaled = qimage_adj.scaled(New_width,New_height,CustRes_AspectRatioMode,Qt::SmoothTransformation); + QImageWriter qimageW_adj; + qimageW_adj.setFormat("png"); + qimageW_adj.setFileName(OutPut_Path); + if(qimageW_adj.canWrite()) + { + qimageW_adj.write(qimage_adj_scaled); + } + QFile::remove(OutputPath_tmp); + if(!QFile::exists(OutPut_Path)) + { + emit Send_TextBrowser_NewMessage(tr("Error occured when processing [")+SourceFile_fullPath+tr("]. Error: [Unable to resize the scaled picture to the target size]")); + emit Send_Table_image_ChangeStatus_rowNumInt_statusQString(rowNum, "Failed"); + emit Send_progressbar_Add(); + mutex_ThreadNumRunning.lock(); + ThreadNumRunning--; + mutex_ThreadNumRunning.unlock();//线程数量统计-1 + return 0; + } + OutPutPath_Final = OutPut_Path; + } + if(CustRes_isEnabled) + { + QString OutPut_Path_CustRes = file_path + "/" + file_name + "_waifu2x_"+QString::number(CustRes_width, 10)+"x"+QString::number(CustRes_height, 10)+"_"+QString::number(DenoiseLevel, 10)+"n_"+file_ext+".png"; + QFile::remove(OutPut_Path_CustRes); + QFile::rename(OutPut_Path,OutPut_Path_CustRes); + OutPutPath_Final = OutPut_Path_CustRes; + } + //=========================== 另存为JPG&压缩JPG =========================================== + OutPutPath_Final = SaveImageAs_FormatAndQuality(SourceFile_fullPath_Original,OutPutPath_Final,true,DenoiseLevel); + //================== 检查是否丢失了透明通道 ===================== + if(ReProcess_MissingAlphaChannel==false) + { + QImage QImage_source(SourceFile_fullPath_Original); + QImage QImage_Final(OutPutPath_Final); + if(QImage_source.hasAlphaChannel()==true && QImage_Final.hasAlphaChannel()==false && ui->checkBox_AutoDetectAlphaChannel->isChecked()) + { + QFile::remove(OutPutPath_Final); + emit Send_TextBrowser_NewMessage(tr("Since the Alpha channel in the resulting image is lost, this image will be reprocessed to fix it:[")+SourceFile_fullPath_Original+tr("].\nIf the reprocessing happens a lot, you should consider enable [Always pre-process images with Alpha Channel] in [Additional settings].")); + return SRMD_NCNN_Vulkan_Image(rowNum,true); + } + } + //============================= 删除原文件 & & 更新table status ============================ + if(SourceFile_fullPath_Original!=SourceFile_fullPath) + { + QFile::remove(SourceFile_fullPath); + SourceFile_fullPath = SourceFile_fullPath_Original; + } + if(DelOriginal) + { + if(ReplaceOriginalFile(SourceFile_fullPath,OutPutPath_Final)==false) + { + if(QAction_checkBox_MoveToRecycleBin_checkBox_DelOriginal->isChecked()) + { + file_MoveToTrash(SourceFile_fullPath); + } + else + { + QFile::remove(SourceFile_fullPath); + } + } + emit Send_Table_image_ChangeStatus_rowNumInt_statusQString(rowNum, "Finished, original file deleted"); + } + else + { + emit Send_Table_image_ChangeStatus_rowNumInt_statusQString(rowNum, "Finished"); + } + //========== 移动到输出路径 ========= + if(ui->checkBox_OutPath_isEnabled->isChecked()) + { + MoveFileToOutputPath(OutPutPath_Final,SourceFile_fullPath); + } + //============================ 更新进度条 ================================= + emit Send_progressbar_Add(); + //=========================== 更新线程数量统计============================== + mutex_ThreadNumRunning.lock(); + ThreadNumRunning--; + mutex_ThreadNumRunning.unlock();//线程数量统计-1 + return 0; +} + +/* + + ============================================================================================= + ============================================================================================= + ============================= SRMD_NCNN_Vulkan_GIF ======================================= + ============================================================================================= + ============================================================================================= + +*/ + +int MainWindow::SRMD_NCNN_Vulkan_GIF(int rowNum) +{ + //============================= 读取设置 ================================ + int ScaleRatio = ui->doubleSpinBox_ScaleRatio_gif->value(); + int DenoiseLevel = ui->spinBox_DenoiseLevel_gif->value(); + bool DelOriginal = (ui->checkBox_DelOriginal->isChecked()||ui->checkBox_ReplaceOriginalFile->isChecked()); + bool OptGIF = ui->checkBox_OptGIF->isChecked(); + QString OutPutPath_Final =""; + //========================= 拆解map得到参数 ============================= + emit Send_Table_gif_ChangeStatus_rowNumInt_statusQString(rowNum, "Processing"); + QString SourceFile_fullPath = Table_model_gif->item(rowNum,2)->text(); + if(!QFile::exists(SourceFile_fullPath)) + { + emit Send_TextBrowser_NewMessage(tr("Error occured when processing [")+SourceFile_fullPath+tr("]. Error: [File does not exist.]")); + emit Send_Table_gif_ChangeStatus_rowNumInt_statusQString(rowNum, "Failed"); + emit Send_progressbar_Add(); + return 0; + } + //========================== + bool CustRes_isEnabled = false; + int CustRes_height=0; + int CustRes_width=0; + if(CustRes_isContained(SourceFile_fullPath)) + { + CustRes_isEnabled=true; + QMap Res_map = CustRes_getResMap(SourceFile_fullPath);//res_map["fullpath"],["height"],["width"] + CustRes_height=Res_map["height"].toInt(); + CustRes_width=Res_map["width"].toInt(); + } + //========================== + QFileInfo fileinfo(SourceFile_fullPath); + QString file_name = file_getBaseName(SourceFile_fullPath); + QString file_ext = fileinfo.suffix(); + QString file_path = file_getFolderPath(fileinfo); + QString ResGIFPath = file_path + "/" + file_name + "_waifu2x_"+QString::number(ScaleRatio, 10)+"x_"+QString::number(DenoiseLevel, 10)+"n.gif"; + //=========================== 获取帧时间 ==================================== + int GIF_Duration = Gif_getDuration(SourceFile_fullPath); + if(GIF_Duration==0)//检查是否成功获取duration + { + emit Send_TextBrowser_NewMessage(tr("Error occured when processing [")+SourceFile_fullPath+tr("]. Error: [Can't get Duration value of GIF file.]")); + emit Send_Table_gif_ChangeStatus_rowNumInt_statusQString(rowNum, "Failed"); + //file_DelDir(SplitFramesFolderPath); + emit Send_progressbar_Add(); + return 0;//如果启用stop位,则直接return + } + //============================== 拆分 ========================================== + QString SplitFramesFolderPath = file_path+"/"+file_name+"_SplitFrames_W2xEX";//拆分后存储frame的文件夹 + Gif_splitGif(SourceFile_fullPath,SplitFramesFolderPath); + //============================== 扫描获取文件名 =============================== + QStringList Frame_fileName_list = file_getFileNames_in_Folder_nofilter(SplitFramesFolderPath); + if(Frame_fileName_list.isEmpty())//检查是否成功拆分gif + { + emit Send_TextBrowser_NewMessage(tr("Error occured when processing [")+SourceFile_fullPath+tr("]. Error: [Can't split GIF into frames.]")); + emit Send_Table_gif_ChangeStatus_rowNumInt_statusQString(rowNum, "Failed"); + file_DelDir(SplitFramesFolderPath); + emit Send_progressbar_Add(); + return 0;//如果启用stop位,则直接return + } + //===========建立存储放大后frame的文件夹=========== + QString ScaledFramesFolderPath = SplitFramesFolderPath+"/ScaledFrames_W2xEX"; + if(file_isDirExist(ScaledFramesFolderPath)) + { + file_DelDir(ScaledFramesFolderPath); + file_mkDir(ScaledFramesFolderPath); + } + else + { + file_mkDir(ScaledFramesFolderPath); + } + //==========开始放大========================== + //读取放大倍数 + int ScaleRatio_Original = 2; + if(CustRes_isEnabled == true) + { + ScaleRatio_Original = CustRes_CalNewScaleRatio(SourceFile_fullPath,CustRes_height,CustRes_width); + } + else + { + ScaleRatio_Original = ui->doubleSpinBox_ScaleRatio_gif->value(); + } + QMap result_map = Calculate_ScaleRatio_SrmdNcnnVulkan(ScaleRatio_Original); + int ScaleRatio_Max=result_map["ScaleRatio_tmp"]; + int Initial_ScaleRatio=result_map["Initial_ScaleRatio"]; + bool isOverScaled = (ScaleRatio_Max!=ScaleRatio_Original); + //初始化进度讯息 + int NumOfSplitFrames = Frame_fileName_list.size(); + if(ui->checkBox_ShowInterPro->isChecked()) + { + int NumOfRounds=0; + for(int ScaleRatio_Current_tmp=Initial_ScaleRatio; ScaleRatio_Current_tmp<=ScaleRatio_Max; ScaleRatio_Current_tmp*=Initial_ScaleRatio) + { + NumOfRounds++; + } + emit Send_CurrentFileProgress_Start(file_name+"."+file_ext,NumOfSplitFrames*NumOfRounds); + } + //读取配置讯息 + QString SRMD_NCNN_Vulkan_Settings_str = SrmdNcnnVulkan_ReadSettings_Video_GIF(ui->spinBox_ThreadNum_gif_internal->value()); + QProcess *Waifu2x = new QProcess(); + QString program = Current_Path + "/srmd-ncnn-vulkan/srmd-ncnn-vulkan_waifu2xEX.exe"; + bool waifu2x_qprocess_failed = false; + int DenoiseLevel_tmp = DenoiseLevel; + int CountFinishedRounds=0; + //==== + for(int ScaleRatio_Current_tmp=Initial_ScaleRatio; ScaleRatio_Current_tmp<=ScaleRatio_Max && Frame_fileName_list.isEmpty()==false; ScaleRatio_Current_tmp*=Initial_ScaleRatio) + { + for(int retry=0; retry<(ui->spinBox_retry->value()+ForceRetryCount); retry++) + { + QString ErrorMSG=""; + QString StanderMSG=""; + //========== + waifu2x_qprocess_failed = false; + QString cmd = "\"" + program + "\"" + " -i " + "\"" + SplitFramesFolderPath + "\"" + " -o " + "\"" + ScaledFramesFolderPath + "\"" + " -s " + QString("%1").arg(Initial_ScaleRatio) + " -n " + QString::number(DenoiseLevel_tmp, 10) + SRMD_NCNN_Vulkan_Settings_str; + Waifu2x->start(cmd); + while(!Waifu2x->waitForStarted(100)&&!QProcess_stop) {} + while(!Waifu2x->waitForFinished(650)&&!QProcess_stop) + { + if(waifu2x_STOP) + { + Waifu2x->close(); + file_DelDir(SplitFramesFolderPath); + emit Send_Table_gif_ChangeStatus_rowNumInt_statusQString(rowNum, "Interrupted"); + mutex_ThreadNumRunning.lock(); + ThreadNumRunning--; + mutex_ThreadNumRunning.unlock(); + return 0; + } + ErrorMSG.append(Waifu2x->readAllStandardError().toLower()); + StanderMSG.append(Waifu2x->readAllStandardOutput().toLower()); + if(ErrorMSG.contains("failed")||StanderMSG.contains("failed")) + { + waifu2x_qprocess_failed = true; + Waifu2x->close(); + break; + } + if(ui->checkBox_ShowInterPro->isChecked()) + { + emit Send_CurrentFileProgress_progressbar_SetFinishedValue((NumOfSplitFrames*CountFinishedRounds)+file_getFileNames_in_Folder_nofilter(ScaledFramesFolderPath).size()); + } + } + //=============== + if(waifu2x_qprocess_failed==false) + { + ErrorMSG.append(Waifu2x->readAllStandardError().toLower()); + StanderMSG.append(Waifu2x->readAllStandardOutput().toLower()); + if(ErrorMSG.contains("failed")||StanderMSG.contains("failed")) + { + waifu2x_qprocess_failed = true; + } + } + //========= 检测是否成功,是否需要重试 ============ + if((NumOfSplitFrames == file_getFileNames_in_Folder_nofilter(ScaledFramesFolderPath).size())&&!waifu2x_qprocess_failed) + { + break; + } + else + { + //失败 + file_DelDir(ScaledFramesFolderPath); + file_mkDir(ScaledFramesFolderPath); + if(retry==ui->spinBox_retry->value()+(ForceRetryCount-1))break; + emit Send_TextBrowser_NewMessage(tr("Automatic retry, please wait.")); + Delay_sec_sleep(5); + } + } + //=========== + //根据轮数修改参数 + DenoiseLevel_tmp = -1; + if(ScaleRatio_Current_tmpisChecked()) + { + file_MoveToTrash(SourceFile_fullPath); + } + else + { + QFile::remove(SourceFile_fullPath); + } + } + emit Send_Table_gif_ChangeStatus_rowNumInt_statusQString(rowNum, "Finished, original file deleted"); + } + else + { + emit Send_Table_gif_ChangeStatus_rowNumInt_statusQString(rowNum, "Finished"); + } + //========== 移动到输出路径 ========= + if(ui->checkBox_OutPath_isEnabled->isChecked()) + { + MoveFileToOutputPath(OutPutPath_Final,SourceFile_fullPath); + } + //============================ 更新进度条 ================================= + emit Send_progressbar_Add(); + //=========================== 更新运行中线程数量 ============================== + return 0; +} + +/* + ============================================================================================= + ============================================================================================= + ============================= SRMD_NCNN_Vulkan_Video ======================================= + ============================================================================================= + ============================================================================================= +*/ + +int MainWindow::SRMD_NCNN_Vulkan_Video(int rowNum) +{ + //============================= 读取设置 ================================ + int ScaleRatio = ui->doubleSpinBox_ScaleRatio_video->value(); + int DenoiseLevel = ui->spinBox_DenoiseLevel_video->value(); + bool DelOriginal = (ui->checkBox_DelOriginal->isChecked()||ui->checkBox_ReplaceOriginalFile->isChecked()); + bool isCacheExists = false; + bool isVideoConfigChanged = true; + //========================= 拆解map得到参数 ============================= + emit Send_Table_video_ChangeStatus_rowNumInt_statusQString(rowNum, "Processing"); + QString SourceFile_fullPath = Table_model_video->item(rowNum,2)->text(); + if(!QFile::exists(SourceFile_fullPath)) + { + emit Send_TextBrowser_NewMessage(tr("Error occured when processing [")+SourceFile_fullPath+tr("]. Error: [File does not exist.]")); + emit Send_Table_video_ChangeStatus_rowNumInt_statusQString(rowNum, "Failed"); + emit Send_progressbar_Add(); + return 0; + } + //========================== + QFileInfo fileinfo(SourceFile_fullPath); + QString file_name = file_getBaseName(SourceFile_fullPath); + QString file_ext = fileinfo.suffix(); + QString file_path = file_getFolderPath(fileinfo); + //=================================================================== + //生成mp4 + QString video_mp4_fullpath=video_To_CFRMp4(SourceFile_fullPath); + if(!QFile::exists(video_mp4_fullpath))//检查是否成功生成mp4 + { + emit Send_TextBrowser_NewMessage(tr("Error occured when processing [")+SourceFile_fullPath+tr("]. Error: [Cannot convert video format to mp4.]")); + emit Send_Table_video_ChangeStatus_rowNumInt_statusQString(rowNum, "Failed"); + emit Send_progressbar_Add(); + return 0;//如果启用stop位,则直接return + } + //============ 读取自定义分辨率设定 ============== + bool CustRes_isEnabled = false; + int CustRes_height=0; + int CustRes_width=0; + if(CustRes_isContained(SourceFile_fullPath)) + { + CustRes_isEnabled=true; + QMap Res_map = CustRes_getResMap(SourceFile_fullPath);//res_map["fullpath"],["height"],["width"] + CustRes_height=Res_map["height"].toInt(); + CustRes_width=Res_map["width"].toInt(); + } + //================= + QString AudioPath = file_path+"/Audio_"+file_name+"_"+file_ext+"_W2xEX.wav";//音频 + QString SplitFramesFolderPath = file_path+"/"+file_name+"_"+file_ext+"_SplitFrames_W2xEX";//拆分后存储frame的文件夹 + QString ScaledFramesFolderPath = SplitFramesFolderPath+"/ScaledFrames_W2xEX";//存储放大后的帧 + //========================== + // 检测之前的视频配置文件 + //========================== + QString VideoConfiguration_fullPath = file_path+"/VideoConfiguration_"+file_name+"_"+file_ext+"_Waifu2xEX.ini"; + if(QFile::exists(VideoConfiguration_fullPath)) + { + QSettings *configIniRead = new QSettings(VideoConfiguration_fullPath, QSettings::IniFormat); + configIniRead->setIniCodec(QTextCodec::codecForName("UTF-8")); + //=================== 加载之前存储的视频信息 ========================= + int ScaleRatio_old = configIniRead->value("/VideoConfiguration/ScaleRatio").toInt(); + int DenoiseLevel_old = configIniRead->value("/VideoConfiguration/DenoiseLevel").toInt(); + bool CustRes_isEnabled_old = configIniRead->value("/VideoConfiguration/CustRes_isEnabled").toBool(); + int CustRes_height_old = configIniRead->value("/VideoConfiguration/CustRes_height").toInt(); + int CustRes_width_old = configIniRead->value("/VideoConfiguration/CustRes_width").toInt(); + QString EngineName_old = configIniRead->value("/VideoConfiguration/EngineName").toString(); + bool isProcessBySegment_old = configIniRead->value("/VideoConfiguration/isProcessBySegment").toBool(); + //=================== 比对信息 ================================ + if(EngineName_old=="srmd-ncnn-vulkan") + { + if(CustRes_isEnabled_old==false&&CustRes_isEnabled==false) + { + if(ScaleRatio_old!=ScaleRatio||DenoiseLevel_old!=DenoiseLevel) + { + isVideoConfigChanged=true; + } + else + { + isVideoConfigChanged=false; + } + } + else + { + if(CustRes_isEnabled_old==true&&CustRes_isEnabled==true) + { + if(CustRes_height_old!=CustRes_height||CustRes_width_old!=CustRes_width) + { + isVideoConfigChanged=true; + } + else + { + isVideoConfigChanged=false; + } + } + else + { + isVideoConfigChanged=true; + } + } + if(isProcessBySegment_old==true) + { + isVideoConfigChanged=true; + } + } + else + { + isVideoConfigChanged=true; + } + } + else + { + emit Send_video_write_VideoConfiguration(VideoConfiguration_fullPath,ScaleRatio,DenoiseLevel,CustRes_isEnabled,CustRes_height,CustRes_width,"srmd-ncnn-vulkan",false,"","",ui->groupBox_FrameInterpolation->isChecked(),0); + } + //======================= + // 检测缓存是否存在 + //======================= + if(QFile::exists(video_mp4_fullpath)&&file_isDirExist(SplitFramesFolderPath)&&file_isDirExist(ScaledFramesFolderPath)&&QFile::exists(VideoConfiguration_fullPath)) + { + if(!isVideoConfigChanged) + { + isCacheExists=true; + emit Send_TextBrowser_NewMessage(tr("The previous video cache file is detected and processing of the previous video cache will continue. If you want to restart processing of the current video:[")+SourceFile_fullPath+tr("], delete the cache manually.")); + } + else + { + isCacheExists=false; + //======== + QFile::remove(VideoConfiguration_fullPath); + file_DelDir(SplitFramesFolderPath); + QFile::remove(AudioPath); + DelVfiDir(video_mp4_fullpath); + emit Send_video_write_VideoConfiguration(VideoConfiguration_fullPath,ScaleRatio,DenoiseLevel,CustRes_isEnabled,CustRes_height,CustRes_width,"srmd-ncnn-vulkan",false,"","",ui->groupBox_FrameInterpolation->isChecked(),0); + //======= + emit Send_TextBrowser_NewMessage(tr("The previous video cache file was detected, but because you changed the settings about the video resolution or denoise level, the previous cache will be deleted and processing of the video:[")+SourceFile_fullPath+tr("] will restart.")); + } + } + else + { + isCacheExists=false; + //======== + QFile::remove(VideoConfiguration_fullPath); + file_DelDir(SplitFramesFolderPath); + QFile::remove(AudioPath); + DelVfiDir(video_mp4_fullpath); + emit Send_video_write_VideoConfiguration(VideoConfiguration_fullPath,ScaleRatio,DenoiseLevel,CustRes_isEnabled,CustRes_height,CustRes_width,"srmd-ncnn-vulkan",false,"","",ui->groupBox_FrameInterpolation->isChecked(),0); + //======== + } + if(!isCacheExists) + { + //============================== 拆分 ========================================== + if(file_isDirExist(SplitFramesFolderPath)) + { + file_DelDir(SplitFramesFolderPath); + file_mkDir(SplitFramesFolderPath); + } + else + { + file_mkDir(SplitFramesFolderPath); + } + QFile::remove(AudioPath); + video_video2images(video_mp4_fullpath,SplitFramesFolderPath,AudioPath); + if(waifu2x_STOP) + { + emit Send_Table_video_ChangeStatus_rowNumInt_statusQString(rowNum, "Interrupted"); + return 0;//如果启用stop位,则直接return + } + } + //============================== 扫描获取文件名 =============================== + QStringList Frame_fileName_list = file_getFileNames_in_Folder_nofilter(SplitFramesFolderPath); + if(!isCacheExists) + { + if(Frame_fileName_list.isEmpty())//检查是否成功拆分为帧 + { + emit Send_TextBrowser_NewMessage(tr("Error occured when processing [")+SourceFile_fullPath+tr("]. Error: [Unable to split video into pictures.]")); + emit Send_Table_video_ChangeStatus_rowNumInt_statusQString(rowNum, "Failed"); + emit Send_progressbar_Add(); + return 0;//如果启用stop位,则直接return + } + } + //============================== 放大 ======================================= + //===========建立存储放大后frame的文件夹=========== + if(!isCacheExists) + { + if(file_isDirExist(ScaledFramesFolderPath)) + { + file_DelDir(ScaledFramesFolderPath); + file_mkDir(ScaledFramesFolderPath); + } + else + { + file_mkDir(ScaledFramesFolderPath); + } + } + //==========开始放大========================== + //读取放大倍数 + int ScaleRatio_Original = 2; + if(CustRes_isEnabled == true) + { + ScaleRatio_Original = CustRes_CalNewScaleRatio(video_mp4_fullpath,CustRes_height,CustRes_width); + } + else + { + ScaleRatio_Original = ui->doubleSpinBox_ScaleRatio_video->value(); + } + QMap result_map = Calculate_ScaleRatio_SrmdNcnnVulkan(ScaleRatio_Original); + int ScaleRatio_Max=result_map["ScaleRatio_tmp"]; + int Initial_ScaleRatio=result_map["Initial_ScaleRatio"]; + bool isOverScaled = (ScaleRatio_Max!=ScaleRatio_Original); + //读取初始放大倍率 + int Start_ScaleRatio_Video = Initial_ScaleRatio; + if(!Frame_fileName_list.isEmpty()) + { + QString Full_Path_File = ""; + for(int i = 0; i < Frame_fileName_list.size(); i++) + { + QString tmp = Frame_fileName_list.at(i); + Full_Path_File = SplitFramesFolderPath + "/" + tmp; + QFileInfo finfo(Full_Path_File); + if(finfo.suffix()=="png")break; + } + QImage qimage_original; + qimage_original.load(Full_Path_File); + int Frame_height = qimage_original.height(); + QMap res_map = video_get_Resolution(SourceFile_fullPath); + int Video_height = res_map["height"]; + if(Frame_height>0 && Video_height>0 && Frame_height>=Video_height)//判断是否读取失败 + { + Start_ScaleRatio_Video = Initial_ScaleRatio*(Frame_height/Video_height); + } + } + //初始化进度讯息 + int NumOfSplitFrames = Frame_fileName_list.size()+file_getFileNames_in_Folder_nofilter(ScaledFramesFolderPath).size(); + if(ui->checkBox_ShowInterPro->isChecked()) + { + int NumOfRounds=0; + for(int ScaleRatio_Current_tmp=Start_ScaleRatio_Video; ScaleRatio_Current_tmp<=ScaleRatio_Max; ScaleRatio_Current_tmp*=Initial_ScaleRatio) + { + NumOfRounds++; + } + emit Send_CurrentFileProgress_Start(file_name+"."+file_ext,NumOfSplitFrames*NumOfRounds); + } + //读取配置讯息 + QString SRMD_NCNN_Vulkan_Settings_str = SrmdNcnnVulkan_ReadSettings_Video_GIF(ui->spinBox_ThreadNum_video_internal->value()); + QProcess *Waifu2x = new QProcess(); + QString program = Current_Path + "/srmd-ncnn-vulkan/srmd-ncnn-vulkan_waifu2xEX.exe"; + bool waifu2x_qprocess_failed = false; + int DenoiseLevel_tmp = DenoiseLevel; + int CountFinishedRounds=0; + //==== + for(int ScaleRatio_Current_tmp=Start_ScaleRatio_Video; ScaleRatio_Current_tmp<=ScaleRatio_Max && Frame_fileName_list.isEmpty()==false; ScaleRatio_Current_tmp*=Initial_ScaleRatio) + { + for(int retry=0; retry<(ui->spinBox_retry->value()+ForceRetryCount); retry++) + { + QString ErrorMSG=""; + QString StanderMSG=""; + //========== + waifu2x_qprocess_failed = false; + QString cmd = "\"" + program + "\"" + " -i " + "\"" + SplitFramesFolderPath + "\"" + " -o " + "\"" + ScaledFramesFolderPath + "\"" + " -s " + QString("%1").arg(Initial_ScaleRatio) + " -n " + QString::number(DenoiseLevel_tmp, 10) + SRMD_NCNN_Vulkan_Settings_str; + Waifu2x->start(cmd); + while(!Waifu2x->waitForStarted(100)&&!QProcess_stop) {} + while(!Waifu2x->waitForFinished(650)&&!QProcess_stop) + { + if(waifu2x_STOP) + { + QStringList FinfishedFileList_FileNames = WaitForEngineIO_NcnnVulkan(ScaledFramesFolderPath); + Waifu2x->close(); + //============ + QString file_name_tmp; + QStringList FileNames_ScaledFramesFolderPath = file_getFileNames_in_Folder_nofilter(ScaledFramesFolderPath); + for(int i=0; ireadAllStandardError().toLower()); + StanderMSG.append(Waifu2x->readAllStandardOutput().toLower()); + if(ErrorMSG.contains("failed")||StanderMSG.contains("failed")) + { + waifu2x_qprocess_failed = true; + Waifu2x->close(); + break; + } + if(ui->checkBox_ShowInterPro->isChecked()) + { + emit Send_CurrentFileProgress_progressbar_SetFinishedValue((NumOfSplitFrames*CountFinishedRounds)+file_getFileNames_in_Folder_nofilter(ScaledFramesFolderPath).size()); + } + } + //=============== + if(waifu2x_qprocess_failed==false) + { + ErrorMSG.append(Waifu2x->readAllStandardError().toLower()); + StanderMSG.append(Waifu2x->readAllStandardOutput().toLower()); + if(ErrorMSG.contains("failed")||StanderMSG.contains("failed")) + { + waifu2x_qprocess_failed = true; + } + } + //========= 检测是否成功,是否需要重试 ============ + if((NumOfSplitFrames == file_getFileNames_in_Folder_nofilter(ScaledFramesFolderPath).size())&&!waifu2x_qprocess_failed) + { + break; + } + else + { + //失败 + file_DelDir(ScaledFramesFolderPath); + file_mkDir(ScaledFramesFolderPath); + if(retry==ui->spinBox_retry->value()+(ForceRetryCount-1))break; + emit Send_TextBrowser_NewMessage(tr("Automatic retry, please wait.")); + Delay_sec_sleep(5); + } + } + //=========== + //根据轮数修改参数 + DenoiseLevel_tmp = -1; + if(ScaleRatio_Current_tmpcheckBox_KeepVideoCache->isChecked()==false) + { + QFile::remove(VideoConfiguration_fullPath); + file_DelDir(SplitFramesFolderPath); + QFile::remove(AudioPath); + if(SourceFile_fullPath!=video_mp4_fullpath)QFile::remove(video_mp4_fullpath); + } + else + { + DelOriginal=false; + } + //============================= 删除原文件 & & 更新table status ============================ + if(DelOriginal) + { + if(ReplaceOriginalFile(SourceFile_fullPath,video_mp4_scaled_fullpath)==false) + { + if(QAction_checkBox_MoveToRecycleBin_checkBox_DelOriginal->isChecked()) + { + file_MoveToTrash(SourceFile_fullPath); + } + else + { + QFile::remove(SourceFile_fullPath); + } + } + emit Send_Table_video_ChangeStatus_rowNumInt_statusQString(rowNum, "Finished, original file deleted"); + } + else + { + emit Send_Table_video_ChangeStatus_rowNumInt_statusQString(rowNum, "Finished"); + } + //========== 移动到输出路径 ========= + if(ui->checkBox_OutPath_isEnabled->isChecked()) + { + MoveFileToOutputPath(video_mp4_scaled_fullpath,SourceFile_fullPath); + } + //============================ 更新进度条 ================================= + emit Send_progressbar_Add(); + //=========================== ============================== + return 0; +} + +/* +#### 分段处理 #### +调用SRMD-NCNN-Vulkan处理视频 +读取设置,拆分,创建放大子线程,组装视频 +*/ +int MainWindow::SRMD_NCNN_Vulkan_Video_BySegment(int rowNum) +{ + //============================= 读取设置 ================================ + int ScaleRatio = ui->doubleSpinBox_ScaleRatio_video->value(); + int DenoiseLevel = ui->spinBox_DenoiseLevel_video->value(); + bool DelOriginal = (ui->checkBox_DelOriginal->isChecked()||ui->checkBox_ReplaceOriginalFile->isChecked()); + bool isCacheExists = false; + bool isVideoConfigChanged = true; + int SegmentDuration = ui->spinBox_SegmentDuration->value(); + //========================= 拆解map得到参数 ============================= + emit Send_Table_video_ChangeStatus_rowNumInt_statusQString(rowNum, "Processing"); + QString SourceFile_fullPath = Table_model_video->item(rowNum,2)->text(); + if(!QFile::exists(SourceFile_fullPath)) + { + emit Send_TextBrowser_NewMessage(tr("Error occured when processing [")+SourceFile_fullPath+tr("]. Error: [File does not exist.]")); + emit Send_Table_video_ChangeStatus_rowNumInt_statusQString(rowNum, "Failed"); + emit Send_progressbar_Add(); + return 0; + } + //========================== + QFileInfo fileinfo(SourceFile_fullPath); + QString file_name = file_getBaseName(SourceFile_fullPath); + QString file_ext = fileinfo.suffix(); + QString file_path = file_getFolderPath(fileinfo); + //=================================================================== + //生成mp4 + QString video_mp4_fullpath=video_To_CFRMp4(SourceFile_fullPath); + if(!QFile::exists(video_mp4_fullpath))//检查是否成功生成mp4 + { + emit Send_TextBrowser_NewMessage(tr("Error occured when processing [")+SourceFile_fullPath+tr("]. Error: [Cannot convert video format to mp4.]")); + emit Send_Table_video_ChangeStatus_rowNumInt_statusQString(rowNum, "Failed"); + emit Send_progressbar_Add(); + return 0;//如果启用stop位,则直接return + } + //============== 读取自定义分辨率设定 ============ + bool CustRes_isEnabled = false; + int CustRes_height=0; + int CustRes_width=0; + if(CustRes_isContained(SourceFile_fullPath)) + { + CustRes_isEnabled=true; + QMap Res_map = CustRes_getResMap(SourceFile_fullPath);//res_map["fullpath"],["height"],["width"] + CustRes_height=Res_map["height"].toInt(); + CustRes_width=Res_map["width"].toInt(); + } + //================= + QString AudioPath = file_path+"/Audio_"+file_name+"_"+file_ext+"_W2xEX.wav";//音频 + QString SplitFramesFolderPath = file_path+"/"+file_name+"_"+file_ext+"_SplitFrames_W2xEX";//拆分后存储frame的文件夹 + QString ScaledFramesFolderPath = SplitFramesFolderPath+"/ScaledFrames_W2xEX";//存储放大后的帧 + //=== + QString VideoClipsFolderPath = "";//存储视频片段的文件夹(完整路径) + QString DateStr = ""; + do + { + DateStr = video_getClipsFolderNo(); + VideoClipsFolderPath = file_path+"/"+DateStr+"_VideoClipsWaifu2xEX";//存储视频片段的文件夹(完整路径) + } + while(file_isDirExist(VideoClipsFolderPath)); + QString VideoClipsFolderName = DateStr+"_VideoClipsWaifu2xEX";//存储视频片段的文件夹(名称) + //========================== + // 检测之前的视频配置文件 + //========================== + QString VideoConfiguration_fullPath = file_path+"/VideoConfiguration_"+file_name+"_"+file_ext+"_Waifu2xEX.ini"; + if(QFile::exists(VideoConfiguration_fullPath)) + { + QSettings *configIniRead = new QSettings(VideoConfiguration_fullPath, QSettings::IniFormat); + configIniRead->setIniCodec(QTextCodec::codecForName("UTF-8")); + //=================== 加载之前存储的视频信息 ========================= + int ScaleRatio_old = configIniRead->value("/VideoConfiguration/ScaleRatio").toInt(); + int DenoiseLevel_old = configIniRead->value("/VideoConfiguration/DenoiseLevel").toInt(); + bool CustRes_isEnabled_old = configIniRead->value("/VideoConfiguration/CustRes_isEnabled").toBool(); + int CustRes_height_old = configIniRead->value("/VideoConfiguration/CustRes_height").toInt(); + int CustRes_width_old = configIniRead->value("/VideoConfiguration/CustRes_width").toInt(); + QString EngineName_old = configIniRead->value("/VideoConfiguration/EngineName").toString(); + bool isProcessBySegment_old = configIniRead->value("/VideoConfiguration/isProcessBySegment").toBool(); + bool isVideoFrameInterpolationEnabled_old = configIniRead->value("/VideoConfiguration/isVideoFrameInterpolationEnabled").toBool(); + int MultipleOfFPS_old = configIniRead->value("/VideoConfiguration/MultipleOfFPS").toInt(); + //=================== 比对信息 ================================ + if(EngineName_old=="srmd-ncnn-vulkan") + { + if(CustRes_isEnabled_old==false&&CustRes_isEnabled==false) + { + if(ScaleRatio_old!=ScaleRatio||DenoiseLevel_old!=DenoiseLevel) + { + isVideoConfigChanged=true; + } + else + { + isVideoConfigChanged=false; + } + } + else + { + if(CustRes_isEnabled_old==true&&CustRes_isEnabled==true) + { + if(CustRes_height_old!=CustRes_height||CustRes_width_old!=CustRes_width) + { + isVideoConfigChanged=true; + } + else + { + isVideoConfigChanged=false; + } + } + else + { + isVideoConfigChanged=true; + } + } + if(isProcessBySegment_old == false) + { + isVideoConfigChanged=true; + } + if(isVideoFrameInterpolationEnabled_old != ui->groupBox_FrameInterpolation->isChecked()) + { + isVideoConfigChanged=true; + } + if(MultipleOfFPS_old != ui->spinBox_MultipleOfFPS_VFI->value() && ui->groupBox_FrameInterpolation->isChecked()) + { + isVideoConfigChanged=true; + } + } + else + { + isVideoConfigChanged=true; + } + //============ 修正文件夹名称 ============= + QString VideoClipsFolderPath_old = configIniRead->value("/VideoConfiguration/VideoClipsFolderPath").toString(); + QString VideoClipsFolderName_old = configIniRead->value("/VideoConfiguration/VideoClipsFolderName").toString(); + file_mkDir(VideoClipsFolderPath_old); + if(file_isDirExist(VideoClipsFolderPath_old)==true) + { + VideoClipsFolderPath = VideoClipsFolderPath_old; + VideoClipsFolderName = VideoClipsFolderName_old; + } + } + else + { + emit Send_video_write_VideoConfiguration(VideoConfiguration_fullPath,ScaleRatio,DenoiseLevel,CustRes_isEnabled,CustRes_height,CustRes_width,"srmd-ncnn-vulkan",true,VideoClipsFolderPath,VideoClipsFolderName,ui->groupBox_FrameInterpolation->isChecked(),ui->spinBox_MultipleOfFPS_VFI->value()); + } + //======================= + // 检测缓存是否存在 + //======================= + if(file_isDirExist(SplitFramesFolderPath)) + { + if(!isVideoConfigChanged) + { + isCacheExists=true; + emit Send_TextBrowser_NewMessage(tr("The previous video cache file is detected and processing of the previous video cache will continue. If you want to restart processing of the current video:[")+SourceFile_fullPath+tr("], delete the cache manually.")); + } + else + { + isCacheExists=false; + //======== + QFile::remove(VideoConfiguration_fullPath); + file_DelDir(SplitFramesFolderPath); + file_DelDir(VideoClipsFolderPath); + QFile::remove(AudioPath); + DelVfiDir(video_mp4_fullpath); + emit Send_video_write_VideoConfiguration(VideoConfiguration_fullPath,ScaleRatio,DenoiseLevel,CustRes_isEnabled,CustRes_height,CustRes_width,"srmd-ncnn-vulkan",true,VideoClipsFolderPath,VideoClipsFolderName,ui->groupBox_FrameInterpolation->isChecked(),ui->spinBox_MultipleOfFPS_VFI->value()); + //======= + emit Send_TextBrowser_NewMessage(tr("The previous video cache file was detected, but because you changed the settings about the video resolution or denoise level, the previous cache will be deleted and processing of the video:[")+SourceFile_fullPath+tr("] will restart.")); + } + } + else + { + isCacheExists=false; + //======== + QFile::remove(VideoConfiguration_fullPath); + file_DelDir(SplitFramesFolderPath); + file_DelDir(VideoClipsFolderPath); + QFile::remove(AudioPath); + DelVfiDir(video_mp4_fullpath); + emit Send_video_write_VideoConfiguration(VideoConfiguration_fullPath,ScaleRatio,DenoiseLevel,CustRes_isEnabled,CustRes_height,CustRes_width,"srmd-ncnn-vulkan",true,VideoClipsFolderPath,VideoClipsFolderName,ui->groupBox_FrameInterpolation->isChecked(),ui->spinBox_MultipleOfFPS_VFI->value()); + //======== + } + /*==================================== + 提取音频 + ======================================*/ + if(!QFile::exists(AudioPath)) + { + video_get_audio(video_mp4_fullpath,AudioPath); + } + //================================== 开始分段处理视频 ================================================= + int StartTime = 0;//起始时间(秒) + int VideoDuration = video_get_duration(video_mp4_fullpath); + bool isSplitComplete = false; + bool isScaleComplete = false; + /* + ============================================ + 开始之前先读取进度 + ============================================ + */ + int OLD_SegmentDuration=-1; + bool read_OLD_SegmentDuration =false; + int LastVideoClipNo = -1; + if(QFile::exists(VideoConfiguration_fullPath)) + { + QSettings *configIniRead = new QSettings(VideoConfiguration_fullPath, QSettings::IniFormat); + configIniRead->setIniCodec(QTextCodec::codecForName("UTF-8")); + //=================== 加载进度 ========================= + StartTime = configIniRead->value("/Progress/StartTime").toInt(); + isSplitComplete = configIniRead->value("/Progress/isSplitComplete").toBool(); + isScaleComplete = configIniRead->value("/Progress/isScaleComplete").toBool(); + OLD_SegmentDuration = configIniRead->value("/Progress/OLDSegmentDuration").toInt(); + LastVideoClipNo = configIniRead->value("/Progress/LastVideoClipNo").toInt(); + } + if(OLD_SegmentDuration>0) + { + read_OLD_SegmentDuration = true; + } + /* + 加载进度条 + */ + int SegmentDuration_tmp_progressbar = 0; + if(read_OLD_SegmentDuration) + { + SegmentDuration_tmp_progressbar = OLD_SegmentDuration; + } + else + { + SegmentDuration_tmp_progressbar = SegmentDuration; + } + if(ui->checkBox_ShowInterPro->isChecked()&&VideoDuration>SegmentDuration_tmp_progressbar) + { + emit Send_CurrentFileProgress_Start(file_name+"."+file_ext,VideoDuration); + if(StartTime>0) + { + emit Send_CurrentFileProgress_progressbar_Add_SegmentDuration(StartTime); + } + } + /* + ============================================ + 正式开始处理 + ============================================ + */ + int SegmentDuration_tmp=0; + int TimeLeft_tmp=0; + while(VideoDuration>StartTime) + { + /*========================== + 计算视频片段时间 + ==========================*/ + TimeLeft_tmp = VideoDuration-StartTime; + if((TimeLeft_tmp)>=SegmentDuration) + { + SegmentDuration_tmp = SegmentDuration; + } + else + { + SegmentDuration_tmp = TimeLeft_tmp; + } + if(read_OLD_SegmentDuration) + { + SegmentDuration_tmp = OLD_SegmentDuration; + read_OLD_SegmentDuration=false; + } + /*========================== + 拆分视频片段 + ==========================*/ + if(isSplitComplete==false) + { + if(file_isDirExist(SplitFramesFolderPath)) + { + file_DelDir(SplitFramesFolderPath); + file_mkDir(SplitFramesFolderPath); + } + else + { + file_mkDir(SplitFramesFolderPath); + } + video_video2images_ProcessBySegment(video_mp4_fullpath,SplitFramesFolderPath,StartTime,SegmentDuration_tmp); + if(waifu2x_STOP) + { + emit Send_Table_video_ChangeStatus_rowNumInt_statusQString(rowNum, "Interrupted"); + return 0;//如果启用stop位,则直接return + } + } + /*========================== + 处理视频片段的帧 + ==========================*/ + bool isOverScaled=false; + if(isScaleComplete==false) + { + //============================== 扫描获取文件名 =============================== + QStringList Frame_fileName_list = file_getFileNames_in_Folder_nofilter(SplitFramesFolderPath); + if(isSplitComplete==false) + { + if(Frame_fileName_list.isEmpty())//检查是否成功拆分为帧 + { + emit Send_TextBrowser_NewMessage(tr("Error occured when processing [")+SourceFile_fullPath+tr("]. Error: [Unable to split video into pictures.]")); + emit Send_Table_video_ChangeStatus_rowNumInt_statusQString(rowNum, "Failed"); + emit Send_progressbar_Add(); + return 0;//如果启用stop位,则直接return + } + } + /* + 记录进度 + 帧拆分成功 + */ + emit Send_video_write_Progress_ProcessBySegment(VideoConfiguration_fullPath,StartTime,true,false,SegmentDuration_tmp,LastVideoClipNo); + //============================== 放大 ======================================= + //===========建立存储放大后frame的文件夹=========== + if(isSplitComplete==false) + { + if(file_isDirExist(ScaledFramesFolderPath)) + { + file_DelDir(ScaledFramesFolderPath); + file_mkDir(ScaledFramesFolderPath); + } + else + { + file_mkDir(ScaledFramesFolderPath); + } + } + //==========开始放大========================== + //读取放大倍数 + int ScaleRatio_Original = 2; + if(CustRes_isEnabled == true) + { + ScaleRatio_Original = CustRes_CalNewScaleRatio(video_mp4_fullpath,CustRes_height,CustRes_width); + } + else + { + ScaleRatio_Original = ui->doubleSpinBox_ScaleRatio_video->value(); + } + QMap result_map = Calculate_ScaleRatio_SrmdNcnnVulkan(ScaleRatio_Original); + int ScaleRatio_Max=result_map["ScaleRatio_tmp"]; + int Initial_ScaleRatio=result_map["Initial_ScaleRatio"]; + isOverScaled = (ScaleRatio_Max!=ScaleRatio_Original); + //读取初始放大倍率 + int Start_ScaleRatio_Video = Initial_ScaleRatio; + if(!Frame_fileName_list.isEmpty()) + { + QString Full_Path_File = ""; + for(int i = 0; i < Frame_fileName_list.size(); i++) + { + QString tmp = Frame_fileName_list.at(i); + Full_Path_File = SplitFramesFolderPath + "/" + tmp; + QFileInfo finfo(Full_Path_File); + if(finfo.suffix()=="png")break; + } + QImage qimage_original; + qimage_original.load(Full_Path_File); + int Frame_height = qimage_original.height(); + QMap res_map = video_get_Resolution(SourceFile_fullPath); + int Video_height = res_map["height"]; + if(Frame_height>0 && Video_height>0 && Frame_height>=Video_height)//判断是否读取失败 + { + Start_ScaleRatio_Video = Initial_ScaleRatio*(Frame_height/Video_height); + } + } + //初始化进度讯息 + int NumOfSplitFrames = Frame_fileName_list.size()+file_getFileNames_in_Folder_nofilter(ScaledFramesFolderPath).size(); + int CurrentFileProgress_MAX = 0; + int CurrentFileProgress_OLD = 0; + int CurrentFileProgress_New = 0; + if(ui->checkBox_ShowInterPro->isChecked()) + { + int NumOfRounds=0; + for(int ScaleRatio_Current_tmp=Start_ScaleRatio_Video; ScaleRatio_Current_tmp<=ScaleRatio_Max; ScaleRatio_Current_tmp*=Initial_ScaleRatio) + { + NumOfRounds++; + } + CurrentFileProgress_MAX =NumOfSplitFrames*NumOfRounds; + } + //读取配置讯息 + QString SRMD_NCNN_Vulkan_Settings_str = SrmdNcnnVulkan_ReadSettings_Video_GIF(ui->spinBox_ThreadNum_video_internal->value()); + QProcess *Waifu2x = new QProcess(); + QString program = Current_Path + "/srmd-ncnn-vulkan/srmd-ncnn-vulkan_waifu2xEX.exe"; + bool waifu2x_qprocess_failed = false; + int DenoiseLevel_tmp = DenoiseLevel; + int CountFinishedRounds=0; + //==== + for(int ScaleRatio_Current_tmp=Start_ScaleRatio_Video; ScaleRatio_Current_tmp<=ScaleRatio_Max && Frame_fileName_list.isEmpty()==false; ScaleRatio_Current_tmp*=Initial_ScaleRatio) + { + for(int retry=0; retry<(ui->spinBox_retry->value()+ForceRetryCount); retry++) + { + QString ErrorMSG=""; + QString StanderMSG=""; + //========== + waifu2x_qprocess_failed = false; + QString cmd = "\"" + program + "\"" + " -i " + "\"" + SplitFramesFolderPath + "\"" + " -o " + "\"" + ScaledFramesFolderPath + "\"" + " -s " + QString("%1").arg(Initial_ScaleRatio) + " -n " + QString::number(DenoiseLevel_tmp, 10) + SRMD_NCNN_Vulkan_Settings_str; + Waifu2x->start(cmd); + while(!Waifu2x->waitForStarted(100)&&!QProcess_stop) {} + while(!Waifu2x->waitForFinished(650)&&!QProcess_stop) + { + if(waifu2x_STOP) + { + QStringList FinfishedFileList_FileNames = WaitForEngineIO_NcnnVulkan(ScaledFramesFolderPath); + Waifu2x->close(); + //============ + QString file_name_tmp; + QStringList FileNames_ScaledFramesFolderPath = file_getFileNames_in_Folder_nofilter(ScaledFramesFolderPath); + for(int i=0; ireadAllStandardError().toLower()); + StanderMSG.append(Waifu2x->readAllStandardOutput().toLower()); + if(ErrorMSG.contains("failed")||StanderMSG.contains("failed")) + { + waifu2x_qprocess_failed = true; + Waifu2x->close(); + break; + } + if(ui->checkBox_ShowInterPro->isChecked()) + { + CurrentFileProgress_New = (NumOfSplitFrames*CountFinishedRounds)+file_getFileNames_in_Folder_nofilter(ScaledFramesFolderPath).size(); + if(CurrentFileProgress_New!=CurrentFileProgress_OLD) + { + emit Send_TextBrowser_NewMessage(tr("File name:[")+SourceFile_fullPath+tr("] Scale progress:[")+QString::number(CurrentFileProgress_New,10)+"/"+QString::number(CurrentFileProgress_MAX,10)+tr("] Duration progress:[")+QString::number(StartTime,10)+"s/"+QString::number(VideoDuration,10)+"s]"); + CurrentFileProgress_OLD=CurrentFileProgress_New; + } + } + } + //=============== + if(waifu2x_qprocess_failed==false) + { + ErrorMSG.append(Waifu2x->readAllStandardError().toLower()); + StanderMSG.append(Waifu2x->readAllStandardOutput().toLower()); + if(ErrorMSG.contains("failed")||StanderMSG.contains("failed")) + { + waifu2x_qprocess_failed = true; + } + } + //========= 检测是否成功,是否需要重试 ============ + if((NumOfSplitFrames == file_getFileNames_in_Folder_nofilter(ScaledFramesFolderPath).size())&&!waifu2x_qprocess_failed) + { + break; + } + else + { + //失败 + file_DelDir(ScaledFramesFolderPath); + file_mkDir(ScaledFramesFolderPath); + if(retry==ui->spinBox_retry->value()+(ForceRetryCount-1))break; + emit Send_TextBrowser_NewMessage(tr("Automatic retry, please wait.")); + Delay_sec_sleep(5); + } + } + //=========== + //根据轮数修改参数 + DenoiseLevel_tmp = -1; + if(ScaleRatio_Current_tmpcheckBox_ShowInterPro->isChecked()) + { + emit Send_CurrentFileProgress_progressbar_Add_SegmentDuration(SegmentDuration_tmp); + } + StartTime+=SegmentDuration_tmp; + isSplitComplete = false; + isScaleComplete = false; + LastVideoClipNo=VideoClipNo; + emit Send_video_write_Progress_ProcessBySegment(VideoConfiguration_fullPath,StartTime,false,false,-1,VideoClipNo); + } + emit Send_CurrentFileProgress_Stop(); + //====================================================== + // 组装(片段到成片) + //====================================================== + QString video_mp4_scaled_fullpath = ""; + if(CustRes_isEnabled) + { + video_mp4_scaled_fullpath = file_path+"/"+file_name+"_waifu2x_"+QString::number(CustRes_width,10)+"x"+QString::number(CustRes_height,10)+"_"+QString::number(DenoiseLevel,10)+"n"+"_"+file_ext+".mp4"; + } + else + { + video_mp4_scaled_fullpath = file_path+"/"+file_name+"_waifu2x_"+QString::number(ScaleRatio,10)+"x_"+QString::number(DenoiseLevel,10)+"n"+"_"+file_ext+".mp4"; + } + QFile::remove(video_mp4_scaled_fullpath); + video_AssembleVideoClips(VideoClipsFolderPath,VideoClipsFolderName,video_mp4_scaled_fullpath,AudioPath); + if(QFile::exists(video_mp4_scaled_fullpath)==false)//检查是否成功生成视频 + { + if(waifu2x_STOP) + { + emit Send_Table_video_ChangeStatus_rowNumInt_statusQString(rowNum, "Interrupted"); + return 0;//如果启用stop位,则直接return + } + emit Send_TextBrowser_NewMessage(tr("Error occured when processing [")+SourceFile_fullPath+tr("]. Error: [Unable to assemble video clips.]")); + emit Send_Table_video_ChangeStatus_rowNumInt_statusQString(rowNum, "Failed"); + emit Send_progressbar_Add(); + return 0;//如果启用stop位,则直接return + } + //============================== 删除缓存文件 ==================================================== + if(ui->checkBox_KeepVideoCache->isChecked()==false) + { + QFile::remove(VideoConfiguration_fullPath); + file_DelDir(SplitFramesFolderPath); + file_DelDir(VideoClipsFolderPath); + QFile::remove(AudioPath); + if(SourceFile_fullPath!=video_mp4_fullpath)QFile::remove(video_mp4_fullpath); + } + else + { + DelOriginal=false; + } + //============================= 删除原文件 & & 更新table status ============================ + if(DelOriginal) + { + if(ReplaceOriginalFile(SourceFile_fullPath,video_mp4_scaled_fullpath)==false) + { + if(QAction_checkBox_MoveToRecycleBin_checkBox_DelOriginal->isChecked()) + { + file_MoveToTrash(SourceFile_fullPath); + } + else + { + QFile::remove(SourceFile_fullPath); + } + } + emit Send_Table_video_ChangeStatus_rowNumInt_statusQString(rowNum, "Finished, original file deleted"); + } + else + { + emit Send_Table_video_ChangeStatus_rowNumInt_statusQString(rowNum, "Finished"); + } + //========== 移动到输出路径 ========= + if(ui->checkBox_OutPath_isEnabled->isChecked()) + { + MoveFileToOutputPath(video_mp4_scaled_fullpath,SourceFile_fullPath); + } + //============================ 更新进度条 ================================= + emit Send_progressbar_Add(); + //=========================== ============================== + return 0; +} +/* +SRMD 检测可用GPU +*/ +void MainWindow::on_pushButton_DetectGPUID_srmd_clicked() +{ + //=== + ui->pushButton_DetectGPUID_srmd->setText(tr("Detecting, please wait...")); + //=== + pushButton_Start_setEnabled_self(0); + ui->pushButton_DetectGPU->setEnabled(0); + ui->pushButton_DetectGPUID_srmd->setEnabled(0); + ui->pushButton_DumpProcessorList_converter->setEnabled(0); + ui->pushButton_ListGPUs_Anime4k->setEnabled(0); + ui->pushButton_compatibilityTest->setEnabled(0); + ui->pushButton_DetectGPU_RealsrNCNNVulkan->setEnabled(0); + Available_GPUID_srmd.clear(); + QtConcurrent::run(this, &MainWindow::SRMD_DetectGPU); +} + +int MainWindow::SRMD_DetectGPU() +{ + emit Send_TextBrowser_NewMessage(tr("Detecting available GPU, please wait.")); + //=============== + QString InputPath = Current_Path + "/Compatibility_Test/Compatibility_Test.jpg"; + QString OutputPath = Current_Path + "/Compatibility_Test/res.png"; + QFile::remove(OutputPath); + //============== + QString Waifu2x_folder_path = Current_Path + "/srmd-ncnn-vulkan"; + QString program = Waifu2x_folder_path + "/srmd-ncnn-vulkan_waifu2xEX.exe"; + QString model_path = Waifu2x_folder_path+"/models-srmd"; + //========= + int GPU_ID=-1; + //========= + while(true) + { + QFile::remove(OutputPath); + QProcess *Waifu2x = new QProcess(); + QString gpu_str = " -g "+QString::number(GPU_ID,10)+" "; + QString cmd = "\"" + program + "\"" + " -i " + "\"" + InputPath + "\"" + " -o " + "\"" + OutputPath + "\"" + " -s 2 -n 0 -t 32 -m " + "\"" + model_path + "\"" + " -j 1:1:1"+gpu_str; + Waifu2x->start(cmd); + while(!Waifu2x->waitForStarted(100)&&!QProcess_stop) {} + while(!Waifu2x->waitForFinished(100)&&!QProcess_stop) {} + if(QFile::exists(OutputPath) && (Waifu2x->readAllStandardError().toLower().contains("failed")||Waifu2x->readAllStandardOutput().toLower().contains("failed"))==false) + { + Available_GPUID_srmd.append(QString::number(GPU_ID,10)); + GPU_ID++; + QFile::remove(OutputPath); + } + else + { + if(GPU_ID > -1) + { + break; + } + else + { + GPU_ID++; + } + } + } + QFile::remove(OutputPath); + //=============== + emit Send_TextBrowser_NewMessage(tr("Detection is complete!")); + if(Available_GPUID_srmd.isEmpty()) + { + Send_TextBrowser_NewMessage(tr("No available GPU ID detected!")); + } + emit Send_SRMD_DetectGPU_finished(); + return 0; +} + +void MainWindow::SRMD_DetectGPU_finished() +{ + pushButton_Start_setEnabled_self(1); + ui->pushButton_DetectGPU->setEnabled(1); + ui->pushButton_compatibilityTest->setEnabled(1); + ui->pushButton_DetectGPUID_srmd->setEnabled(1); + ui->pushButton_DumpProcessorList_converter->setEnabled(1); + on_checkBox_SpecifyGPU_Anime4k_stateChanged(1); + ui->pushButton_DetectGPU_RealsrNCNNVulkan->setEnabled(1); + //==== + GPUIDs_List_MultiGPU_SrmdNcnnVulkan.clear(); + ui->comboBox_GPUIDs_MultiGPU_SrmdNCNNVulkan->clear(); + ui->comboBox_GPUID_srmd->clear(); + ui->comboBox_GPUID_srmd->addItem("auto"); + if(!Available_GPUID_srmd.isEmpty()) + { + for(int i=0; icomboBox_GPUID_srmd->addItem(Available_GPUID_srmd.at(i)); + AddGPU_MultiGPU_SrmdNcnnVulkan(Available_GPUID_srmd.at(i)); + } + } + //=== + ui->pushButton_DetectGPUID_srmd->setText(tr("Detect available GPU ID")); + //=== +} +/* +预读取SRMD引擎设定 +*/ +QString MainWindow::SrmdNcnnVulkan_PreLoad_Settings() +{ + QString SrmdNcnnVulkan_Settings_str = " "; + //TTA + if(ui->checkBox_TTA_srmd->isChecked()) + { + SrmdNcnnVulkan_Settings_str.append("-x "); + } + if(ui->checkBox_MultiGPU_SrmdNCNNVulkan->isChecked()==false) + { + //==========单显卡========== + //GPU ID + if(ui->comboBox_GPUID_srmd->currentText()!="auto") + { + SrmdNcnnVulkan_Settings_str.append("-g "+ui->comboBox_GPUID_srmd->currentText()+" "); + } + //Tile Size + SrmdNcnnVulkan_Settings_str.append("-t "+QString::number(ui->spinBox_TileSize_srmd->value(),10)+" "); + } + //Model + QString SrmdNcnnVulkan_folder_path = Current_Path + "/srmd-ncnn-vulkan"; + QString model_path = SrmdNcnnVulkan_folder_path+"/models-srmd"; + SrmdNcnnVulkan_Settings_str.append("-m \""+model_path+"\" "); + SrmdNcnnVulkan_Settings_str.append("-j 1:1:1 "); + //======================================= + return SrmdNcnnVulkan_Settings_str; +} + +/* +读取SRMD引擎设置 +*/ +QString MainWindow::SrmdNcnnVulkan_ReadSettings() +{ + QString SrmdNcnnVulkan_Settings_str = ""; + SrmdNcnnVulkan_Settings_str.append(SrmdNcnnVulkan_PreLoad_Settings_Str); + if(ui->checkBox_MultiGPU_SrmdNCNNVulkan->isChecked()) + { + //==========多显卡========== + QMap GPUInfo = SrmdNcnnVulkan_MultiGPU(); + //GPU ID + SrmdNcnnVulkan_Settings_str.append("-g "+GPUInfo["ID"]+" "); + //Tile Size + SrmdNcnnVulkan_Settings_str.append("-t "+GPUInfo["TileSize"]+" "); + } + //======================================= + return SrmdNcnnVulkan_Settings_str; +} + + +/* +SrmdNCNNVulkan_MultiGPU +显卡切换 +*/ +QMap MainWindow::SrmdNcnnVulkan_MultiGPU() +{ + MultiGPU_QMutex_SrmdNcnnVulkan.lock(); + //==== + int MAX_GPU_ID_SrmdNcnnVulkan = GPUIDs_List_MultiGPU_SrmdNcnnVulkan.size()-1; + if(GPU_ID_SrmdNcnnVulkan_MultiGPU>MAX_GPU_ID_SrmdNcnnVulkan) + { + GPU_ID_SrmdNcnnVulkan_MultiGPU=0; + } + //====== + QMap GPUInfo; + do + { + GPUInfo = GPUIDs_List_MultiGPU_SrmdNcnnVulkan.at(GPU_ID_SrmdNcnnVulkan_MultiGPU); + if(GPUInfo["isEnabled"] != "true") + { + GPU_ID_SrmdNcnnVulkan_MultiGPU++; + if(GPU_ID_SrmdNcnnVulkan_MultiGPU>MAX_GPU_ID_SrmdNcnnVulkan) + { + GPU_ID_SrmdNcnnVulkan_MultiGPU=0; + } + } + else + { + break; + } + } + while(true); + //====== + GPU_ID_SrmdNcnnVulkan_MultiGPU++; + if(GPU_ID_SrmdNcnnVulkan_MultiGPU>MAX_GPU_ID_SrmdNcnnVulkan) + { + GPU_ID_SrmdNcnnVulkan_MultiGPU=0; + } + //====== + MultiGPU_QMutex_SrmdNcnnVulkan.unlock(); + return GPUInfo; +} + +void MainWindow::AddGPU_MultiGPU_SrmdNcnnVulkan(QString GPUID) +{ + QMap GPUInfo; + GPUInfo["ID"] = GPUID; + GPUInfo["isEnabled"] = "true"; + GPUInfo["TileSize"] = "100"; + GPUIDs_List_MultiGPU_SrmdNcnnVulkan.append(GPUInfo); + ui->comboBox_GPUIDs_MultiGPU_SrmdNCNNVulkan->addItem(GPUID); + ui->comboBox_GPUIDs_MultiGPU_SrmdNCNNVulkan->setCurrentIndex(0); +} + +void MainWindow::on_checkBox_MultiGPU_SrmdNCNNVulkan_stateChanged(int arg1) +{ + if(ui->checkBox_MultiGPU_SrmdNCNNVulkan->isChecked()) + { + ui->comboBox_GPUID_srmd->setEnabled(0); + ui->frame_TileSize_SrmdNcnnVulkan->setEnabled(0); + ui->groupBox_GPUSettings_MultiGPU_SrmdNCNNVulkan->setEnabled(1); + } + else + { + ui->comboBox_GPUID_srmd->setEnabled(1); + ui->frame_TileSize_SrmdNcnnVulkan->setEnabled(1); + ui->groupBox_GPUSettings_MultiGPU_SrmdNCNNVulkan->setEnabled(0); + } +} + +void MainWindow::on_checkBox_MultiGPU_SrmdNCNNVulkan_clicked() +{ + if(ui->checkBox_MultiGPU_SrmdNCNNVulkan->isChecked()) + { + if(GPUIDs_List_MultiGPU_SrmdNcnnVulkan.size()==0) + { + QMessageBox *MSG = new QMessageBox(); + MSG->setWindowTitle(tr("Notification")); + MSG->setText(tr("Please detect available GPU ID before enable Multi-GPU.")); + MSG->setIcon(QMessageBox::Information); + MSG->setModal(true); + MSG->show(); + ui->checkBox_MultiGPU_SrmdNCNNVulkan->setChecked(0); + return; + } + if(GPUIDs_List_MultiGPU_SrmdNcnnVulkan.size()<2) + { + QMessageBox *MSG = new QMessageBox(); + MSG->setWindowTitle(tr("Error")); + MSG->setText(tr("Insufficient number of available GPUs.")); + MSG->setIcon(QMessageBox::Warning); + MSG->setModal(true); + MSG->show(); + ui->checkBox_MultiGPU_SrmdNCNNVulkan->setChecked(0); + return; + } + } +} + +void MainWindow::on_checkBox_isEnable_CurrentGPU_MultiGPU_SrmdNCNNVulkan_clicked() +{ + QMap GPUInfo=GPUIDs_List_MultiGPU_SrmdNcnnVulkan.at(ui->comboBox_GPUIDs_MultiGPU_SrmdNCNNVulkan->currentIndex()); + if(ui->checkBox_isEnable_CurrentGPU_MultiGPU_SrmdNCNNVulkan->isChecked()) + { + GPUInfo["isEnabled"] = "true"; + } + else + { + GPUInfo["isEnabled"] = "false"; + } + GPUIDs_List_MultiGPU_SrmdNcnnVulkan.replace(ui->comboBox_GPUIDs_MultiGPU_SrmdNCNNVulkan->currentIndex(),GPUInfo); + int enabledGPUs = 0; + for (int i=0; i GPUInfo_tmp = GPUIDs_List_MultiGPU_SrmdNcnnVulkan.at(i); + if(GPUInfo_tmp["isEnabled"] == "true") + { + enabledGPUs++; + } + } + if(enabledGPUs<2) + { + QMap GPUInfo=GPUIDs_List_MultiGPU_SrmdNcnnVulkan.at(ui->comboBox_GPUIDs_MultiGPU_SrmdNCNNVulkan->currentIndex()); + GPUInfo["isEnabled"] = "true"; + GPUIDs_List_MultiGPU_SrmdNcnnVulkan.replace(ui->comboBox_GPUIDs_MultiGPU_SrmdNCNNVulkan->currentIndex(),GPUInfo); + ui->checkBox_isEnable_CurrentGPU_MultiGPU_SrmdNCNNVulkan->setChecked(1); + QMessageBox *MSG = new QMessageBox(); + MSG->setWindowTitle(tr("Warning")); + MSG->setText(tr("At least 2 GPUs need to be enabled !!")); + MSG->setIcon(QMessageBox::Warning); + MSG->setModal(true); + MSG->show(); + } +} + +void MainWindow::on_comboBox_GPUIDs_MultiGPU_SrmdNCNNVulkan_currentIndexChanged(int index) +{ + if(ui->comboBox_GPUIDs_MultiGPU_SrmdNCNNVulkan->count()==0) + { + return; + } + QMap GPUInfo=GPUIDs_List_MultiGPU_SrmdNcnnVulkan.at(ui->comboBox_GPUIDs_MultiGPU_SrmdNCNNVulkan->currentIndex()); + ui->checkBox_isEnable_CurrentGPU_MultiGPU_SrmdNCNNVulkan->setChecked(GPUInfo["isEnabled"] == "true"); + ui->spinBox_TileSize_CurrentGPU_MultiGPU_SrmdNCNNVulkan->setValue(GPUInfo["TileSize"].toInt()); +} + +void MainWindow::on_spinBox_TileSize_CurrentGPU_MultiGPU_SrmdNCNNVulkan_valueChanged(int arg1) +{ + QMap GPUInfo=GPUIDs_List_MultiGPU_SrmdNcnnVulkan.at(ui->comboBox_GPUIDs_MultiGPU_SrmdNCNNVulkan->currentIndex()); + GPUInfo["TileSize"] = QString::number(ui->spinBox_TileSize_CurrentGPU_MultiGPU_SrmdNCNNVulkan->value(),10); + GPUIDs_List_MultiGPU_SrmdNcnnVulkan.replace(ui->comboBox_GPUIDs_MultiGPU_SrmdNCNNVulkan->currentIndex(),GPUInfo); +} + +void MainWindow::on_pushButton_ShowMultiGPUSettings_SrmdNCNNVulkan_clicked() +{ + int Max_GPU_ID = GPUIDs_List_MultiGPU_SrmdNcnnVulkan.size(); + QString MultiGPUSettings_str=""; + for(int GPU_ID=0; GPU_ID GPUInfo = GPUIDs_List_MultiGPU_SrmdNcnnVulkan.at(GPU_ID); + if(GPUInfo["isEnabled"] != "true") + { + continue; + } + else + { + MultiGPUSettings_str.append("GPU ID:["+GPUInfo["ID"]+"] | "+tr("Tile size:")+"["+GPUInfo["TileSize"]+"]\n\n"); + } + } + //========= + QMessageBox *MSG = new QMessageBox(); + MSG->setWindowTitle(tr("Current Multi-GPU settings")); + MSG->setText(MultiGPUSettings_str); + MSG->setIcon(QMessageBox::Information); + MSG->setModal(true); + MSG->show(); +} +/* +SRMD 块大小调整按钮 +*/ +void MainWindow::on_pushButton_Add_TileSize_SrmdNCNNVulkan_clicked() +{ + ui->spinBox_TileSize_srmd->setValue(AddTileSize_NCNNVulkan_Converter(ui->spinBox_TileSize_srmd->value())); +} + +void MainWindow::on_pushButton_Minus_TileSize_SrmdNCNNVulkan_clicked() +{ + ui->spinBox_TileSize_srmd->setValue(MinusTileSize_NCNNVulkan_Converter(ui->spinBox_TileSize_srmd->value())); +} +/* +SRMD 计算放大倍数 +result_map["ScaleRatio_tmp"] = ScaleRatio_tmp; +result_map["Initial_ScaleRatio"] = Initial_ScaleRatio; +*/ +QMap MainWindow::Calculate_ScaleRatio_SrmdNcnnVulkan(int ScaleRatio) +{ + int ScaleRatio_tmp=0; + int Initial_ScaleRatio=0; + do + { + //判断是否为1 + if(ScaleRatio<=1) + { + ScaleRatio_tmp = 2; + Initial_ScaleRatio = 2; + break; + } + //判断是否为原生支持的倍率 + if(ScaleRatio>=2&&ScaleRatio<=4) + { + ScaleRatio_tmp=ScaleRatio; + Initial_ScaleRatio=ScaleRatio; + break; + } + //若不是原生支持,则判断是否为2,3,4中某个数的幂 + //开始判断是否是3的幂 + if(387420489%ScaleRatio==0) + { + ScaleRatio_tmp = ScaleRatio; + Initial_ScaleRatio = 3; + break; + } + //开始判断是否是2和4的幂,先转换为偶数 + if((ScaleRatio%2)==0) + { + ScaleRatio_tmp = ScaleRatio; + } + else + { + ScaleRatio_tmp = ScaleRatio+1; + } + //判断是否是4的幂 + if((((ScaleRatio_tmp&(ScaleRatio_tmp-1))==0)&&(ScaleRatio_tmp&0x555555555))==true) + { + Initial_ScaleRatio = 4; + break; + } + //判断是否是2的幂 + if((ScaleRatio_tmp&(ScaleRatio_tmp-1))==0) + { + Initial_ScaleRatio = 2; + break; + } + //谁的幂都不是,就比谁更近 + int res_2=0; + int res_3=0; + int res_4=0; + int pow_ = 0; + for(int i=1; true; i++) + { + pow_ =pow(2,i); + if(pow_>=ScaleRatio) + { + res_2=pow_; + break; + } + } + for(int i=1; true; i++) + { + pow_ =pow(3,i); + if(pow_>=ScaleRatio) + { + res_3=pow_; + break; + } + } + for(int i=1; true; i++) + { + pow_ =pow(4,i); + if(pow_>=ScaleRatio) + { + res_4=pow_; + break; + } + } + QList sort_list; + sort_list<=ScaleRatio_tmp) + { + ScaleRatio_tmp=pow_; + break; + } + } + } + break; + } + while(false); + QMap result_map; + result_map["ScaleRatio_tmp"] = ScaleRatio_tmp; + result_map["Initial_ScaleRatio"] = Initial_ScaleRatio; + return result_map; +} +/* +读取SRMD引擎设置 + +GIF 和 Video +*/ +QString MainWindow::SrmdNcnnVulkan_ReadSettings_Video_GIF(int ThreadNum) +{ + QString SrmdNcnnVulkan_Settings_str = " "; + //TTA + if(ui->checkBox_TTA_srmd->isChecked()) + { + SrmdNcnnVulkan_Settings_str.append("-x "); + } + if(ui->checkBox_MultiGPU_SrmdNCNNVulkan->isChecked()==false) + { + //==========单显卡========== + //GPU ID + if(ui->comboBox_GPUID_srmd->currentText()!="auto") + { + SrmdNcnnVulkan_Settings_str.append("-g "+ui->comboBox_GPUID_srmd->currentText()+" "); + } + //Tile Size + SrmdNcnnVulkan_Settings_str.append("-t "+QString::number(ui->spinBox_TileSize_srmd->value(),10)+" "); + //线程数量 + QString jobs_num_str = QString("%1").arg(ThreadNum); + SrmdNcnnVulkan_Settings_str.append("-j "+jobs_num_str+":"+jobs_num_str+":"+jobs_num_str+" "); + } + else + { + //==============多显卡================ + int NumOfGPUs_Available = GPUIDs_List_MultiGPU_SrmdNcnnVulkan.size();//获取显卡总数 + int NumOfGPUs_Enabled = 0; + QString GPU_ID_cmd = "-g "; + QString TileSize_cmd = "-t "; + for(int i=0; i GPUInfo = GPUIDs_List_MultiGPU_SrmdNcnnVulkan.at(i); + if(GPUInfo["isEnabled"] != "true")continue; + NumOfGPUs_Enabled++; + if(i==0) + { + GPU_ID_cmd.append(GPUInfo["ID"]); + TileSize_cmd.append(GPUInfo["TileSize"]); + } + else + { + GPU_ID_cmd.append(","+GPUInfo["ID"]); + TileSize_cmd.append(","+GPUInfo["TileSize"]); + } + } + SrmdNcnnVulkan_Settings_str.append(GPU_ID_cmd+" "); + SrmdNcnnVulkan_Settings_str.append(TileSize_cmd+" "); + //线程数量 + int NumOfThreads_PerGPU = ThreadNum/NumOfGPUs_Enabled; + if(NumOfThreads_PerGPU<1)NumOfThreads_PerGPU=1; + int LoadAndWrite_tnum = NumOfGPUs_Enabled*NumOfThreads_PerGPU; + QString Jobs_cmd = ""; + for(int i=0; i Res_map = CustRes_getResMap(sourceFileFullPath);//res_map["fullpath"],["height"],["width"] + ScaleRatio_Original = CustRes_CalNewScaleRatio(sourceFileFullPath,Res_map["height"].toInt(),Res_map["width"].toInt()); + } + else + { + ScaleRatio_Original = ui->doubleSpinBox_ScaleRatio_gif->value(); + } + QMap result_map = Calculate_ScaleRatio_SrmdNcnnVulkan(ScaleRatio_Original); + int ScaleRatio_Max=result_map["ScaleRatio_tmp"]; + int Initial_ScaleRatio=result_map["Initial_ScaleRatio"]; + bool isOverScaled = (ScaleRatio_Max!=ScaleRatio_Original); + //初始化进度讯息 + int NumOfSplitFrames = framesFileName_qStrList.size(); + if(ui->checkBox_ShowInterPro->isChecked()) + { + int NumOfRounds=0; + for(int ScaleRatio_Current_tmp=Initial_ScaleRatio; ScaleRatio_Current_tmp<=ScaleRatio_Max; ScaleRatio_Current_tmp*=Initial_ScaleRatio) + { + NumOfRounds++; + } + emit Send_CurrentFileProgress_Start(file_getBaseName(sourceFileFullPath)+"."+sourceFileFullPath.split(".").last(),NumOfSplitFrames*NumOfRounds); + } + //读取配置讯息 + QString SRMD_NCNN_Vulkan_Settings_str = SrmdNcnnVulkan_ReadSettings_Video_GIF(ui->spinBox_ThreadNum_gif_internal->value()); + QProcess *Waifu2x = new QProcess(); + QString program = Current_Path + "/srmd-ncnn-vulkan/srmd-ncnn-vulkan_waifu2xEX.exe"; + bool waifu2x_qprocess_failed = false; + int DenoiseLevel_tmp = ui->spinBox_DenoiseLevel_gif->value(); + int CountFinishedRounds=0; + //==== + for(int ScaleRatio_Current_tmp=Initial_ScaleRatio; ScaleRatio_Current_tmp<=ScaleRatio_Max && framesFileName_qStrList.isEmpty()==false; ScaleRatio_Current_tmp*=Initial_ScaleRatio) + { + for(int retry=0; retry<(ui->spinBox_retry->value()+ForceRetryCount); retry++) + { + QString ErrorMSG=""; + QString StanderMSG=""; + //========== + waifu2x_qprocess_failed = false; + QString cmd = "\"" + program + "\"" + " -i " + "\"" + splitFramesFolder + "\"" + " -o " + "\"" + scaledFramesFolder + "\"" + " -s " + QString("%1").arg(Initial_ScaleRatio) + " -n " + QString::number(DenoiseLevel_tmp, 10) + SRMD_NCNN_Vulkan_Settings_str; + Waifu2x->start(cmd); + while(!Waifu2x->waitForStarted(100)&&!QProcess_stop) {} + while(!Waifu2x->waitForFinished(650)&&!QProcess_stop) + { + if(waifu2x_STOP) + { + Waifu2x->close(); + mutex_ThreadNumRunning.lock(); + ThreadNumRunning--; + mutex_ThreadNumRunning.unlock(); + return false; + } + ErrorMSG.append(Waifu2x->readAllStandardError().toLower()); + StanderMSG.append(Waifu2x->readAllStandardOutput().toLower()); + if(ErrorMSG.contains("failed")||StanderMSG.contains("failed")) + { + waifu2x_qprocess_failed = true; + Waifu2x->close(); + break; + } + if(ui->checkBox_ShowInterPro->isChecked()) + { + emit Send_CurrentFileProgress_progressbar_SetFinishedValue((NumOfSplitFrames*CountFinishedRounds)+file_getFileNames_in_Folder_nofilter(scaledFramesFolder).size()); + } + } + //=============== + if(waifu2x_qprocess_failed==false) + { + ErrorMSG.append(Waifu2x->readAllStandardError().toLower()); + StanderMSG.append(Waifu2x->readAllStandardOutput().toLower()); + if(ErrorMSG.contains("failed")||StanderMSG.contains("failed")) + { + waifu2x_qprocess_failed = true; + } + } + //========= 检测是否成功,是否需要重试 ============ + if((NumOfSplitFrames == file_getFileNames_in_Folder_nofilter(scaledFramesFolder).size())&&!waifu2x_qprocess_failed) + { + break; + } + else + { + //失败 + file_DelDir(scaledFramesFolder); + file_mkDir(scaledFramesFolder); + if(retry==ui->spinBox_retry->value()+(ForceRetryCount-1))break; + emit Send_TextBrowser_NewMessage(tr("Automatic retry, please wait.")); + Delay_sec_sleep(5); + } + } + //=========== + //根据轮数修改参数 + DenoiseLevel_tmp = -1; + if(ScaleRatio_Current_tmp. - - My Github homepage: https://github.com/AaronFeng753 -*/ - -#include "mainwindow.h" -#include "ui_mainwindow.h" -/* -初始化tableview -*/ -void MainWindow::Init_Table() -{ - Table_model_image->setColumnCount(4); - Table_model_image->setHeaderData(0, Qt::Horizontal, tr("Image File Name")); - Table_model_image->setHeaderData(1, Qt::Horizontal, tr("Status")); - Table_model_image->setHeaderData(2, Qt::Horizontal, tr("Full Path")); - Table_model_image->setHeaderData(3, Qt::Horizontal, tr("Custom resolution(Width x Height)")); - ui->tableView_image->horizontalHeader()->setDefaultAlignment(Qt::AlignLeft); - ui->tableView_image->setModel(Table_model_image); - //================================= - Table_model_gif->setColumnCount(4); - Table_model_gif->setHeaderData(0, Qt::Horizontal, tr("Animated Image File Name")); - Table_model_gif->setHeaderData(1, Qt::Horizontal, tr("Status")); - Table_model_gif->setHeaderData(2, Qt::Horizontal, tr("Full Path")); - Table_model_gif->setHeaderData(3, Qt::Horizontal, tr("Custom resolution(Width x Height)")); - ui->tableView_gif->horizontalHeader()->setDefaultAlignment(Qt::AlignLeft); - ui->tableView_gif->setModel(Table_model_gif); - //================================= - Table_model_video->setColumnCount(4); - Table_model_video->setHeaderData(0, Qt::Horizontal, tr("Video File Name")); - Table_model_video->setHeaderData(1, Qt::Horizontal, tr("Status")); - Table_model_video->setHeaderData(2, Qt::Horizontal, tr("Full Path")); - Table_model_video->setHeaderData(3, Qt::Horizontal, tr("Custom resolution(Width x Height)")); - ui->tableView_video->horizontalHeader()->setDefaultAlignment(Qt::AlignLeft); - ui->tableView_video->setModel(Table_model_video); - //将横向表头设置为可见 - ui->tableView_video->horizontalHeader()->setVisible(1); - ui->tableView_gif->horizontalHeader()->setVisible(1); - ui->tableView_image->horizontalHeader()->setVisible(1); - //============================================= - emit Send_Table_EnableSorting(1);//启用文件列表的排序功能 -} -/* -重载Tableview下的文件数量统计 -*/ -int MainWindow::Table_FileCount_reload() -{ - long int filecount_image=Table_model_image->rowCount(); - long int filecount_gif=Table_model_gif->rowCount(); - long int filecount_video=Table_model_video->rowCount(); - long int filecount_total=filecount_image+filecount_gif+filecount_video; - //==================== - // 列表内有文件 - //==================== - if(filecount_total>0) - { - //=========== - //显示文件数量 - //=========== - ui->label_FileCount->setVisible(1); - ui->label_FileCount->setText(QString(tr("File count: %1")).arg(filecount_total)); - ui->label_FileCount->setToolTip(QString(tr("Image: %1\nAnimated Image: %2\nVideo: %3")).arg(filecount_image).arg(filecount_gif).arg(filecount_video)); - //================= - //启用控制按钮 - //================= - ui->pushButton_ClearList->setEnabled(1); - ui->pushButton_RemoveItem->setEnabled(1); - //=============================================== - //根据每个列表内文件数量逐个判断是否显示这个列表 - //=============================================== - int TableView_VisibleCount = 0; - ui->label_DropFile->setVisible(0);//隐藏文件投放label - if(filecount_image>0) - { - ui->tableView_image->setVisible(1); - TableView_VisibleCount++; - } - else - { - curRow_image = -1; - ui->tableView_image->clearSelection(); - ui->tableView_image->setVisible(0); - } - //=== - if(filecount_gif>0) - { - ui->tableView_gif->setVisible(1); - TableView_VisibleCount++; - } - else - { - curRow_gif = -1; - ui->tableView_gif->clearSelection(); - ui->tableView_gif->setVisible(0); - } - //=== - if(filecount_video>0) - { - ui->tableView_video->setVisible(1); - TableView_VisibleCount++; - } - else - { - curRow_video = -1; - ui->tableView_video->clearSelection(); - ui->tableView_video->setVisible(0); - } - //======================== - ui->pushButton_ResizeFilesListSplitter->setEnabled(TableView_VisibleCount>1);//当可见的文件列表数量大于1时启用重置文件列表比例按钮 - //======================== - ui->pushButton_SaveFileList->setEnabled(1);//列表内有文件时自动启用保存文件列表的按钮 - } - //==================== - // 列表内无文件 - //==================== - else - { - ui->label_FileCount->setVisible(0);//隐藏文件数量label - //=================== - // 禁用文件列表控制按钮 - //=================== - ui->pushButton_ClearList->setEnabled(0); - ui->pushButton_RemoveItem->setEnabled(0); - ui->pushButton_ResizeFilesListSplitter->setEnabled(0); - //==================== - //隐藏文件列表,取消选中 - //==================== - ui->label_DropFile->setVisible(1); - curRow_image = -1; - ui->tableView_image->clearSelection(); - ui->tableView_image->setVisible(0); - curRow_gif = -1; - ui->tableView_gif->clearSelection(); - ui->tableView_gif->setVisible(0); - curRow_video = -1; - ui->tableView_video->clearSelection(); - ui->tableView_video->setVisible(0); - //======================== - ui->pushButton_SaveFileList->setEnabled(0);//列表内没有文件时自动禁用保存文件列表的按钮 - } - return 0; -} -//============================ -// 插入文件 -//============================ -void MainWindow::Table_image_insert_fileName_fullPath(QString fileName, QString SourceFile_fullPath) -{ - mutex_Table_insert.lock(); - //========= - int rowNum = Table_model_image->rowCount(); - Table_model_image->setItem(rowNum, 0, new QStandardItem(fileName)); - Table_model_image->setItem(rowNum, 1, new QStandardItem("")); - Table_model_image->setItem(rowNum, 2, new QStandardItem(SourceFile_fullPath)); - Table_model_image->setItem(rowNum, 3, new QStandardItem("")); - mutex_Table_insert_finished.lock(); - Table_insert_finished=true; - mutex_Table_insert_finished.unlock(); - //======== - mutex_Table_insert.unlock(); -} - -void MainWindow::Table_gif_insert_fileName_fullPath(QString fileName, QString SourceFile_fullPath) -{ - mutex_Table_insert.lock(); - //========= - int rowNum = Table_model_gif->rowCount(); - Table_model_gif->setItem(rowNum, 0, new QStandardItem(fileName)); - Table_model_gif->setItem(rowNum, 1, new QStandardItem("")); - Table_model_gif->setItem(rowNum, 2, new QStandardItem(SourceFile_fullPath)); - Table_model_gif->setItem(rowNum, 3, new QStandardItem("")); - mutex_Table_insert_finished.lock(); - Table_insert_finished=true; - mutex_Table_insert_finished.unlock(); - //======== - mutex_Table_insert.unlock(); -} - -void MainWindow::Table_video_insert_fileName_fullPath(QString fileName, QString SourceFile_fullPath) -{ - mutex_Table_insert.lock(); - //========= - int rowNum = Table_model_video->rowCount(); - Table_model_video->setItem(rowNum, 0, new QStandardItem(fileName)); - Table_model_video->setItem(rowNum, 1, new QStandardItem("")); - Table_model_video->setItem(rowNum, 2, new QStandardItem(SourceFile_fullPath)); - Table_model_video->setItem(rowNum, 3, new QStandardItem("")); - mutex_Table_insert_finished.lock(); - Table_insert_finished=true; - mutex_Table_insert_finished.unlock(); - //======== - mutex_Table_insert.unlock(); -} - -void MainWindow::Table_image_ChangeStatus_rowNumInt_statusQString(int rowNum, QString status) -{ - ui->tableView_image->setUpdatesEnabled(false); - Table_model_image->setItem(rowNum, 1, new QStandardItem(status)); - if(ui->checkBox_FileListAutoSlide->isChecked()) - { - QAbstractItemModel *modessl = Table_model_image; - QModelIndex indextemp = modessl->index(rowNum, 1); - ui->tableView_image->scrollTo(indextemp,QAbstractItemView::PositionAtCenter); - } - ui->tableView_image->setUpdatesEnabled(true); -} - -void MainWindow::Table_gif_ChangeStatus_rowNumInt_statusQString(int rowNum, QString status) -{ - ui->tableView_gif->setUpdatesEnabled(false); - Table_model_gif->setItem(rowNum, 1, new QStandardItem(status)); - if(ui->checkBox_FileListAutoSlide->isChecked()) - { - QAbstractItemModel *modessl = Table_model_gif; - QModelIndex indextemp = modessl->index(rowNum, 1); - ui->tableView_gif->scrollTo(indextemp,QAbstractItemView::PositionAtCenter); - } - ui->tableView_gif->setUpdatesEnabled(true); -} - -void MainWindow::Table_video_ChangeStatus_rowNumInt_statusQString(int rowNum, QString status) -{ - ui->tableView_video->setUpdatesEnabled(false); - Table_model_video->setItem(rowNum, 1, new QStandardItem(status)); - if(ui->checkBox_FileListAutoSlide->isChecked()) - { - QAbstractItemModel *modessl = Table_model_video; - QModelIndex indextemp = modessl->index(rowNum, 1); - ui->tableView_video->scrollTo(indextemp,QAbstractItemView::PositionAtCenter); - } - ui->tableView_video->setUpdatesEnabled(true); -} - -void MainWindow::Table_image_CustRes_rowNumInt_HeightQString_WidthQString(int rowNum, QString height, QString width) -{ - QString ResStr = width+"x"+height; - ui->tableView_image->setUpdatesEnabled(false); - Table_model_image->setItem(rowNum, 3, new QStandardItem(ResStr)); - ui->tableView_image->setUpdatesEnabled(true); -} - -void MainWindow::Table_gif_CustRes_rowNumInt_HeightQString_WidthQString(int rowNum, QString height, QString width) -{ - QString ResStr = width+"x"+height; - ui->tableView_gif->setUpdatesEnabled(false); - Table_model_gif->setItem(rowNum, 3, new QStandardItem(ResStr)); - ui->tableView_gif->setUpdatesEnabled(true); -} - -void MainWindow::Table_video_CustRes_rowNumInt_HeightQString_WidthQString(int rowNum, QString height, QString width) -{ - QString ResStr = width+"x"+height; - ui->tableView_video->setUpdatesEnabled(false); - Table_model_video->setItem(rowNum, 3, new QStandardItem(ResStr)); - ui->tableView_video->setUpdatesEnabled(true); -} - -void MainWindow::Table_image_CustRes_Cancel_rowNumInt(int rowNum) -{ - ui->tableView_image->setUpdatesEnabled(false); - Table_model_image->setItem(rowNum, 3, new QStandardItem("")); - ui->tableView_image->setUpdatesEnabled(true); -} - -void MainWindow::Table_gif_CustRes_Cancel_rowNumInt(int rowNum) -{ - ui->tableView_gif->setUpdatesEnabled(false); - Table_model_gif->setItem(rowNum, 3, new QStandardItem("")); - ui->tableView_gif->setUpdatesEnabled(true); -} - -void MainWindow::Table_video_CustRes_Cancel_rowNumInt(int rowNum) -{ - ui->tableView_video->setUpdatesEnabled(false); - Table_model_video->setItem(rowNum, 3, new QStandardItem("")); - ui->tableView_video->setUpdatesEnabled(true); -} - - -void MainWindow::Table_ChangeAllStatusToWaiting() -{ - QMutex_Table_ChangeAllStatusToWaiting.lock(); - ui_tableViews_setUpdatesEnabled(false); - bool ReProcFinFiles = ui->checkBox_ReProcFinFiles->isChecked(); - int rowNum = Table_model_image->rowCount(); - for (int i = 0; i < rowNum; i++) - { - QAbstractItemModel *modessl = Table_model_image; - QModelIndex indextemp = modessl->index(i, 1); - QVariant datatemp = modessl->data(indextemp); - QString status = datatemp.toString(); - if(ReProcFinFiles) - { - if(status != "Finished, original file deleted") - { - Table_model_image->setItem(i, 1, new QStandardItem("Waiting")); - } - } - else - { - if(status != "Finished, original file deleted" && status != "Finished") - { - Table_model_image->setItem(i, 1, new QStandardItem("Waiting")); - } - } - } - rowNum = Table_model_gif->rowCount(); - for (int i = 0; i < rowNum; i++) - { - QAbstractItemModel *modessl = Table_model_gif; - QModelIndex indextemp = modessl->index(i, 1); - QVariant datatemp = modessl->data(indextemp); - QString status = datatemp.toString(); - if(ReProcFinFiles) - { - if(status != "Finished, original file deleted") - { - Table_model_gif->setItem(i, 1, new QStandardItem("Waiting")); - } - } - else - { - if(status != "Finished, original file deleted" && status != "Finished") - { - Table_model_gif->setItem(i, 1, new QStandardItem("Waiting")); - } - } - } - rowNum = Table_model_video->rowCount(); - for (int i = 0; i < rowNum; i++) - { - QAbstractItemModel *modessl = Table_model_video; - QModelIndex indextemp = modessl->index(i, 1); - QVariant datatemp = modessl->data(indextemp); - QString status = datatemp.toString(); - if(ReProcFinFiles) - { - if(status != "Finished, original file deleted") - { - Table_model_video->setItem(i, 1, new QStandardItem("Waiting")); - } - } - else - { - if(status != "Finished, original file deleted" && status != "Finished") - { - Table_model_video->setItem(i, 1, new QStandardItem("Waiting")); - } - } - } - ui_tableViews_setUpdatesEnabled(true); - QMutex_Table_ChangeAllStatusToWaiting.unlock(); -} - -void MainWindow::Table_Clear() -{ - ui_tableViews_setUpdatesEnabled(false); - //===== - Table_model_image->clear(); - Table_model_gif->clear(); - Table_model_video->clear(); - Init_Table(); - curRow_image = -1; - curRow_gif = -1; - curRow_video = -1; - //===== - ui_tableViews_setUpdatesEnabled(true); -} - -int MainWindow::Table_image_get_rowNum() -{ - int rowNum = Table_model_image->rowCount(); - return rowNum; -} - -int MainWindow::Table_gif_get_rowNum() -{ - int rowNum = Table_model_gif->rowCount(); - return rowNum; -} - -int MainWindow::Table_video_get_rowNum() -{ - int rowNum = Table_model_video->rowCount(); - return rowNum; -} -/* -从table读取状态和完整路径 -[fullpath]=status; -*/ -QMap MainWindow::Table_Read_status_fullpath(QStandardItemModel *Table_model) -{ - int rowNum = Table_model->rowCount(); - QMap Map_fullPath_status; - for (int i = 0; i < rowNum; i++) - { - QAbstractItemModel *modessl = Table_model; - QModelIndex indextemp_status = modessl->index(i, 1); - QVariant datatemp_status = modessl->data(indextemp_status); - QString status = datatemp_status.toString(); - QModelIndex indextemp_fullpath = modessl->index(i, 2); - QVariant datatemp_fullpath = modessl->data(indextemp_fullpath); - QString fullpath = datatemp_fullpath.toString(); - Map_fullPath_status[fullpath]=status; - } - return Map_fullPath_status; -} - -//保存当前文件列表 -int MainWindow::Table_Save_Current_Table_Filelist(QString Table_FileList_ini) -{ - QFile::remove(Table_FileList_ini); - //================= - QSettings *configIniWrite = new QSettings(Table_FileList_ini, QSettings::IniFormat); - //================= 添加警告 ========================= - configIniWrite->setValue("/Warning/EN", "Do not modify this file! It may cause the program to crash! If problems occur after the modification, delete this file and restart the program."); - //================= 存储table_image ========================= - configIniWrite->setValue("/table_image/rowCount", Table_model_image->rowCount()); - for(int i=0; irowCount(); i++) - { - QAbstractItemModel *modessl = Table_model_image; - //=== - QModelIndex indextemp = modessl->index(i, 0); - QVariant datatemp = modessl->data(indextemp); - QString FileName = datatemp.toString(); - configIniWrite->setValue("/table_image/"+QString::number(i,10)+"_FileName", FileName); - //=== - indextemp = modessl->index(i, 1); - datatemp = modessl->data(indextemp); - QString status = datatemp.toString(); - configIniWrite->setValue("/table_image/"+QString::number(i,10)+"_status", status); - //=== - indextemp = modessl->index(i, 2); - datatemp = modessl->data(indextemp); - QString fullPath = datatemp.toString(); - configIniWrite->setValue("/table_image/"+QString::number(i,10)+"_fullPath", fullPath); - //=== - indextemp = modessl->index(i, 3); - datatemp = modessl->data(indextemp); - QString CustRes_str = datatemp.toString(); - configIniWrite->setValue("/table_image/"+QString::number(i,10)+"_CustRes_str", CustRes_str); - if(CustRes_str!="") - { - QMap ResMap = CustRes_getResMap(fullPath); - if(!ResMap.isEmpty()) - { - configIniWrite->setValue("/table_image/"+QString::number(i,10)+"_CustRes_height", ResMap["height"]); - configIniWrite->setValue("/table_image/"+QString::number(i,10)+"_CustRes_width", ResMap["width"]); - } - } - } - //================= 存储table_gif ========================= - configIniWrite->setValue("/table_gif/rowCount", Table_model_gif->rowCount()); - for(int i=0; irowCount(); i++) - { - QAbstractItemModel *modessl = Table_model_gif; - //=== - QModelIndex indextemp = modessl->index(i, 0); - QVariant datatemp = modessl->data(indextemp); - QString FileName = datatemp.toString(); - configIniWrite->setValue("/table_gif/"+QString::number(i,10)+"_FileName", FileName); - //=== - indextemp = modessl->index(i, 1); - datatemp = modessl->data(indextemp); - QString status = datatemp.toString(); - configIniWrite->setValue("/table_gif/"+QString::number(i,10)+"_status", status); - //=== - indextemp = modessl->index(i, 2); - datatemp = modessl->data(indextemp); - QString fullPath = datatemp.toString(); - configIniWrite->setValue("/table_gif/"+QString::number(i,10)+"_fullPath", fullPath); - //=== - indextemp = modessl->index(i, 3); - datatemp = modessl->data(indextemp); - QString CustRes_str = datatemp.toString(); - configIniWrite->setValue("/table_gif/"+QString::number(i,10)+"_CustRes_str", CustRes_str); - if(CustRes_str!="") - { - QMap ResMap = CustRes_getResMap(fullPath); - if(!ResMap.isEmpty()) - { - configIniWrite->setValue("/table_gif/"+QString::number(i,10)+"_CustRes_height", ResMap["height"]); - configIniWrite->setValue("/table_gif/"+QString::number(i,10)+"_CustRes_width", ResMap["width"]); - } - } - } - //================= 存储table_video ========================= - configIniWrite->setValue("/table_video/rowCount", Table_model_video->rowCount()); - for(int i=0; irowCount(); i++) - { - QAbstractItemModel *modessl = Table_model_video; - //=== - QModelIndex indextemp = modessl->index(i, 0); - QVariant datatemp = modessl->data(indextemp); - QString FileName = datatemp.toString(); - configIniWrite->setValue("/table_video/"+QString::number(i,10)+"_FileName", FileName); - //=== - indextemp = modessl->index(i, 1); - datatemp = modessl->data(indextemp); - QString status = datatemp.toString(); - configIniWrite->setValue("/table_video/"+QString::number(i,10)+"_status", status); - //=== - indextemp = modessl->index(i, 2); - datatemp = modessl->data(indextemp); - QString fullPath = datatemp.toString(); - configIniWrite->setValue("/table_video/"+QString::number(i,10)+"_fullPath", fullPath); - //=== - indextemp = modessl->index(i, 3); - datatemp = modessl->data(indextemp); - QString CustRes_str = datatemp.toString(); - configIniWrite->setValue("/table_video/"+QString::number(i,10)+"_CustRes_str", CustRes_str); - if(CustRes_str!="") - { - QMap ResMap = CustRes_getResMap(fullPath); - if(!ResMap.isEmpty()) - { - configIniWrite->setValue("/table_video/"+QString::number(i,10)+"_CustRes_height", ResMap["height"]); - configIniWrite->setValue("/table_video/"+QString::number(i,10)+"_CustRes_width", ResMap["width"]); - } - } - } - return 0; -} -void MainWindow::on_pushButton_SaveFileList_clicked() -{ - if(Table_model_video->rowCount()<=0&&Table_model_image->rowCount()<=0&&Table_model_gif->rowCount()<=0) - { - QMessageBox *MSG = new QMessageBox(); - MSG->setWindowTitle(tr("Error")); - MSG->setText(tr("File list is empty!")); - MSG->setIcon(QMessageBox::Warning); - MSG->setModal(false); - MSG->show(); - return; - } - //====================== 选择保存位置 ========================== - //生成默认保存文件的文件夹 - file_mkDir(Current_Path+"/FilesList_W2xEX"); - //保存文件弹窗 - QString FilesListFullPath = QFileDialog::getSaveFileName(this, tr("Save files list @Waifu2x-Extension-GUI"), - Current_Path+"/FilesList_W2xEX/FilesList_W2xEX_"+QDateTime::currentDateTime().toString("yyyy-MM-dd_hh-mm-ss")+".ini", - "*.ini"); - if(FilesListFullPath.trimmed()=="")return; - //判断文件夹是否存在以及是否可写入 - QFileInfo FilesListFullPath_fileinfo(FilesListFullPath); - QString FilesListFullPath_FolderPath = file_getFolderPath(FilesListFullPath_fileinfo); - if(file_isDirExist(FilesListFullPath_FolderPath)==false || file_isDirWritable(FilesListFullPath_FolderPath)==false) - { - QMessageBox *MSG = new QMessageBox(); - MSG->setWindowTitle(tr("Error")); - MSG->setText(tr("Target folder doesn't exist or unable to write to the target folder.")); - MSG->setIcon(QMessageBox::Warning); - MSG->setModal(false); - MSG->show(); - return; - } - //======================= 开始保存 ======================== - this->setAcceptDrops(0);//禁止drop file - pushButton_Start_setEnabled_self(0);//禁用start button - ui->pushButton_ClearList->setEnabled(0); - ui->pushButton_RemoveItem->setEnabled(0); - ui->pushButton_CustRes_cancel->setEnabled(0); - ui->pushButton_CustRes_apply->setEnabled(0); - ui->pushButton_ReadFileList->setEnabled(0); - ui->pushButton_SaveFileList->setEnabled(0); - ui->pushButton_BrowserFile->setEnabled(0); - emit Send_TextBrowser_NewMessage(tr("Write to the file, please wait.")); - Table_Save_Current_Table_Filelist(FilesListFullPath); - QtConcurrent::run(this, &MainWindow::Table_Save_Current_Table_Filelist_Watchdog,FilesListFullPath); -} -int MainWindow::Table_Save_Current_Table_Filelist_Watchdog(QString Table_FileList_ini) -{ - while(!QFile::exists(Table_FileList_ini)) - { - Delay_msec_sleep(100); - } - emit Send_Table_Save_Current_Table_Filelist_Finished(); - return 0; -} -int MainWindow::Table_Save_Current_Table_Filelist_Finished() -{ - if(Waifu2xMain.isRunning()==false) - { - this->setAcceptDrops(1);//启用drop file - ui->pushButton_ClearList->setEnabled(1); - ui->pushButton_RemoveItem->setEnabled(1); - ui->pushButton_ReadFileList->setEnabled(1); - ui->pushButton_BrowserFile->setEnabled(1); - } - ui->pushButton_CustRes_cancel->setEnabled(1); - ui->pushButton_CustRes_apply->setEnabled(1); - pushButton_Start_setEnabled_self(1);//启用start button - ui->pushButton_SaveFileList->setEnabled(1); - emit Send_TextBrowser_NewMessage(tr("File list saved successfully!")); - //=== - QMessageBox *MSG = new QMessageBox(); - MSG->setWindowTitle(tr("Notification")); - MSG->setText(tr("File list saved successfully!")); - MSG->setIcon(QMessageBox::Information); - MSG->setModal(true); - MSG->show(); - //=== - return 0; -} -int MainWindow::Table_Read_Saved_Table_Filelist(QString Table_FileList_ini) -{ - if(!QFile::exists(Table_FileList_ini)) - { - emit Send_TextBrowser_NewMessage(tr("Cannot find the saved Files List!")); - emit Send_Table_Read_Saved_Table_Filelist_Finished(Table_FileList_ini); - return 0; - } - //================= - QSettings *configIniRead = new QSettings(Table_FileList_ini, QSettings::IniFormat); - //==================== - int rowCount_image = configIniRead->value("/table_image/rowCount").toInt(); - int rowCount_gif = configIniRead->value("/table_gif/rowCount").toInt(); - int rowCount_video = configIniRead->value("/table_video/rowCount").toInt(); - //========== - Progressbar_MaxVal = rowCount_image + rowCount_gif + rowCount_video; - Progressbar_CurrentVal = 0; - emit Send_PrograssBar_Range_min_max(0, Progressbar_MaxVal); - //========= 加载image ======== - for(int i=0; ivalue("/table_image/"+QString::number(i,10)+"_FileName").toString(); - QString status =configIniRead->value("/table_image/"+QString::number(i,10)+"_status").toString(); - QString fullPath =configIniRead->value("/table_image/"+QString::number(i,10)+"_fullPath").toString(); - QString CustRes_str =configIniRead->value("/table_image/"+QString::number(i,10)+"_CustRes_str").toString(); - //================ - mutex_Table_insert_finished.lock(); - Table_insert_finished=false; - mutex_Table_insert_finished.unlock(); - emit Send_Table_image_insert_fileName_fullPath(FileName,fullPath); - while(!Table_insert_finished) - { - Delay_msec_sleep(10); - } - emit Send_Table_image_ChangeStatus_rowNumInt_statusQString(i,status); - if(status=="Failed") - { - emit Send_TextBrowser_NewMessage(tr("[Failed]--[")+fullPath+"]"); - } - //=============== - if(CustRes_str!="") - { - QString CustRes_height =configIniRead->value("/table_image/"+QString::number(i,10)+"_CustRes_height").toString(); - QString CustRes_width =configIniRead->value("/table_image/"+QString::number(i,10)+"_CustRes_width").toString(); - emit Send_Table_image_CustRes_rowNumInt_HeightQString_WidthQString(i,CustRes_height,CustRes_width); - QMap res_map; - res_map["fullpath"] = fullPath; - res_map["height"] = CustRes_height; - res_map["width"] = CustRes_width; - Custom_resolution_list.append(res_map); - } - emit Send_progressbar_Add(); - //Delay_msec_sleep(100); - } - //========= 加载gif ======== - for(int i=0; ivalue("/table_gif/"+QString::number(i,10)+"_FileName").toString(); - QString status =configIniRead->value("/table_gif/"+QString::number(i,10)+"_status").toString(); - QString fullPath =configIniRead->value("/table_gif/"+QString::number(i,10)+"_fullPath").toString(); - QString CustRes_str =configIniRead->value("/table_gif/"+QString::number(i,10)+"_CustRes_str").toString(); - //================ - mutex_Table_insert_finished.lock(); - Table_insert_finished=false; - mutex_Table_insert_finished.unlock(); - emit Send_Table_gif_insert_fileName_fullPath(FileName,fullPath); - while(!Table_insert_finished) - { - Delay_msec_sleep(10); - } - emit Send_Table_gif_ChangeStatus_rowNumInt_statusQString(i,status); - if(status=="Failed") - { - emit Send_TextBrowser_NewMessage(tr("[Failed]--[")+fullPath+"]"); - } - //=============== - if(CustRes_str!="") - { - QString CustRes_height =configIniRead->value("/table_gif/"+QString::number(i,10)+"_CustRes_height").toString(); - QString CustRes_width =configIniRead->value("/table_gif/"+QString::number(i,10)+"_CustRes_width").toString(); - emit Send_Table_gif_CustRes_rowNumInt_HeightQString_WidthQString(i,CustRes_height,CustRes_width); - QMap res_map; - res_map["fullpath"] = fullPath; - res_map["height"] = CustRes_height; - res_map["width"] = CustRes_width; - Custom_resolution_list.append(res_map); - } - emit Send_progressbar_Add(); - //Delay_msec_sleep(100); - } - //========= 加载video ======== - for(int i=0; ivalue("/table_video/"+QString::number(i,10)+"_FileName").toString(); - QString status =configIniRead->value("/table_video/"+QString::number(i,10)+"_status").toString(); - QString fullPath =configIniRead->value("/table_video/"+QString::number(i,10)+"_fullPath").toString(); - QString CustRes_str =configIniRead->value("/table_video/"+QString::number(i,10)+"_CustRes_str").toString(); - //================ - mutex_Table_insert_finished.lock(); - Table_insert_finished=false; - mutex_Table_insert_finished.unlock(); - emit Send_Table_video_insert_fileName_fullPath(FileName,fullPath); - while(!Table_insert_finished) - { - Delay_msec_sleep(10); - } - emit Send_Table_video_ChangeStatus_rowNumInt_statusQString(i,status); - if(status=="Failed") - { - emit Send_TextBrowser_NewMessage(tr("[Failed]--[")+fullPath+"]"); - } - //=============== - if(CustRes_str!="") - { - QString CustRes_height =configIniRead->value("/table_video/"+QString::number(i,10)+"_CustRes_height").toString(); - QString CustRes_width =configIniRead->value("/table_video/"+QString::number(i,10)+"_CustRes_width").toString(); - emit Send_Table_video_CustRes_rowNumInt_HeightQString_WidthQString(i,CustRes_height,CustRes_width); - QMap res_map; - res_map["fullpath"] = fullPath; - res_map["height"] = CustRes_height; - res_map["width"] = CustRes_width; - Custom_resolution_list.append(res_map); - } - emit Send_progressbar_Add(); - //Delay_msec_sleep(100); - } - //==================== - emit Send_Table_Read_Saved_Table_Filelist_Finished(Table_FileList_ini); - return 0; -} -int MainWindow::Table_Read_Saved_Table_Filelist_Finished(QString Table_FileList_ini) -{ - Progressbar_MaxVal = 0; - Progressbar_CurrentVal = 0; - progressbar_clear(); - //==== - ui_tableViews_setUpdatesEnabled(true); - this->setAcceptDrops(1); - pushButton_Start_setEnabled_self(1); - ui->pushButton_CustRes_cancel->setEnabled(1); - ui->pushButton_CustRes_apply->setEnabled(1); - ui->pushButton_ReadFileList->setEnabled(1); - ui->pushButton_SaveFileList->setEnabled(1); - ui->pushButton_BrowserFile->setEnabled(1); - if(!QFile::exists(Table_FileList_ini)) - { - return 0; - } - //================= - QSettings *configIniRead = new QSettings(Table_FileList_ini, QSettings::IniFormat); - //==================== - //========= image ======== - int rowCount_image = configIniRead->value("/table_image/rowCount").toInt(); - if(rowCount_image>0) - { - ui->label_DropFile->setVisible(0);//隐藏文件投放label - ui->tableView_image->setVisible(1); - } - //========= gif ======== - int rowCount_gif = configIniRead->value("/table_gif/rowCount").toInt(); - if(rowCount_gif>0) - { - ui->label_DropFile->setVisible(0);//隐藏文件投放label - ui->tableView_gif->setVisible(1); - } - //========= video ======== - int rowCount_video = configIniRead->value("/table_video/rowCount").toInt(); - if(rowCount_video>0) - { - ui->label_DropFile->setVisible(0);//隐藏文件投放label - ui->tableView_video->setVisible(1); - } - //==================== - ui->tableView_gif->scrollToBottom(); - ui->tableView_image->scrollToBottom(); - ui->tableView_video->scrollToBottom(); - QScrollBar *image_ScrBar = ui->tableView_image->horizontalScrollBar(); - image_ScrBar->setValue(0); - QScrollBar *gif_ScrBar = ui->tableView_gif->horizontalScrollBar(); - gif_ScrBar->setValue(0); - QScrollBar *video_ScrBar = ui->tableView_video->horizontalScrollBar(); - video_ScrBar->setValue(0); - //============ - Send_TextBrowser_NewMessage(tr("File list update is complete!")); - //==== - progressbar_SetToMax(Progressbar_MaxVal); - Progressbar_MaxVal = 0; - Progressbar_CurrentVal = 0; - //==== - if(rowCount_image<=0&&rowCount_video<=0&&rowCount_gif<=0) - { - Send_TextBrowser_NewMessage(tr("The file list saved last time is empty.")); - progressbar_clear(); - } - //== - Table_FileCount_reload(); - //=== - return 0; -} -void MainWindow::on_tableView_image_doubleClicked(const QModelIndex &index) -{ - if(curRow_image==-1)return; - QModelIndex a; - on_tableView_image_pressed(a); -} -void MainWindow::on_tableView_gif_doubleClicked(const QModelIndex &index) -{ - if(curRow_gif==-1)return; - QModelIndex a; - on_tableView_gif_pressed(a); -} -void MainWindow::on_tableView_video_doubleClicked(const QModelIndex &index) -{ - if(curRow_video==-1)return; - QModelIndex a; - on_tableView_video_pressed(a); -} -void MainWindow::on_tableView_image_pressed(const QModelIndex &index) -{ - curRow_image = ui->tableView_image->currentIndex().row(); - curRow_gif = -1; - curRow_video = -1; - ui->tableView_gif->clearSelection(); - ui->tableView_video->clearSelection(); -} -void MainWindow::on_tableView_gif_pressed(const QModelIndex &index) -{ - curRow_gif = ui->tableView_gif->currentIndex().row(); - curRow_image = -1; - curRow_video = -1; - ui->tableView_image->clearSelection(); - ui->tableView_video->clearSelection(); -} -void MainWindow::on_tableView_video_pressed(const QModelIndex &index) -{ - curRow_video = ui->tableView_video->currentIndex().row(); - curRow_image = -1; - curRow_gif = -1; - ui->tableView_image->clearSelection(); - ui->tableView_gif->clearSelection(); -} -/* -启用 or 禁用 三个文件列表的排序功能 -*/ -void MainWindow::Table_EnableSorting(bool EnableSorting) -{ - ui->tableView_video->horizontalHeader()->setSortIndicatorShown(EnableSorting); - ui->tableView_gif->horizontalHeader()->setSortIndicatorShown(EnableSorting); - ui->tableView_image->horizontalHeader()->setSortIndicatorShown(EnableSorting); - //===== - ui->tableView_image->setSortingEnabled(EnableSorting); - ui->tableView_gif->setSortingEnabled(EnableSorting); - ui->tableView_video->setSortingEnabled(EnableSorting); -} -/* -启用/禁用 文件列表table的UI更新 -*/ -void MainWindow::ui_tableViews_setUpdatesEnabled(bool isEnabled) -{ - ui->tableView_video->setUpdatesEnabled(isEnabled); - ui->tableView_gif->setUpdatesEnabled(isEnabled); - ui->tableView_image->setUpdatesEnabled(isEnabled); -} +/* + Copyright (C) 2021 Aaron Feng + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU Affero General Public License as published + by the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program. If not, see . + + My Github homepage: https://github.com/AaronFeng753 +*/ + +#include "mainwindow.h" +#include "ui_mainwindow.h" +/* +初始化tableview +*/ +void MainWindow::Init_Table() +{ + Table_model_image->setColumnCount(4); + Table_model_image->setHeaderData(0, Qt::Horizontal, tr("Image File Name")); + Table_model_image->setHeaderData(1, Qt::Horizontal, tr("Status")); + Table_model_image->setHeaderData(2, Qt::Horizontal, tr("Full Path")); + Table_model_image->setHeaderData(3, Qt::Horizontal, tr("Custom resolution(Width x Height)")); + ui->tableView_image->horizontalHeader()->setDefaultAlignment(Qt::AlignLeft); + ui->tableView_image->setModel(Table_model_image); + //================================= + Table_model_gif->setColumnCount(4); + Table_model_gif->setHeaderData(0, Qt::Horizontal, tr("Animated Image File Name")); + Table_model_gif->setHeaderData(1, Qt::Horizontal, tr("Status")); + Table_model_gif->setHeaderData(2, Qt::Horizontal, tr("Full Path")); + Table_model_gif->setHeaderData(3, Qt::Horizontal, tr("Custom resolution(Width x Height)")); + ui->tableView_gif->horizontalHeader()->setDefaultAlignment(Qt::AlignLeft); + ui->tableView_gif->setModel(Table_model_gif); + //================================= + Table_model_video->setColumnCount(4); + Table_model_video->setHeaderData(0, Qt::Horizontal, tr("Video File Name")); + Table_model_video->setHeaderData(1, Qt::Horizontal, tr("Status")); + Table_model_video->setHeaderData(2, Qt::Horizontal, tr("Full Path")); + Table_model_video->setHeaderData(3, Qt::Horizontal, tr("Custom resolution(Width x Height)")); + ui->tableView_video->horizontalHeader()->setDefaultAlignment(Qt::AlignLeft); + ui->tableView_video->setModel(Table_model_video); + //将横向表头设置为可见 + ui->tableView_video->horizontalHeader()->setVisible(1); + ui->tableView_gif->horizontalHeader()->setVisible(1); + ui->tableView_image->horizontalHeader()->setVisible(1); + //============================================= + emit Send_Table_EnableSorting(1);//启用文件列表的排序功能 +} +/* +重载Tableview下的文件数量统计 +*/ +int MainWindow::Table_FileCount_reload() +{ + long int filecount_image=Table_model_image->rowCount(); + long int filecount_gif=Table_model_gif->rowCount(); + long int filecount_video=Table_model_video->rowCount(); + long int filecount_total=filecount_image+filecount_gif+filecount_video; + //==================== + // 列表内有文件 + //==================== + if(filecount_total>0) + { + //=========== + //显示文件数量 + //=========== + ui->label_FileCount->setVisible(1); + ui->label_FileCount->setText(QString(tr("File count: %1")).arg(filecount_total)); + ui->label_FileCount->setToolTip(QString(tr("Image: %1\nAnimated Image: %2\nVideo: %3")).arg(filecount_image).arg(filecount_gif).arg(filecount_video)); + //================= + //启用控制按钮 + //================= + ui->pushButton_ClearList->setEnabled(1); + ui->pushButton_RemoveItem->setEnabled(1); + //=============================================== + //根据每个列表内文件数量逐个判断是否显示这个列表 + //=============================================== + int TableView_VisibleCount = 0; + ui->label_DropFile->setVisible(0);//隐藏文件投放label + if(filecount_image>0) + { + ui->tableView_image->setVisible(1); + TableView_VisibleCount++; + } + else + { + curRow_image = -1; + ui->tableView_image->clearSelection(); + ui->tableView_image->setVisible(0); + } + //=== + if(filecount_gif>0) + { + ui->tableView_gif->setVisible(1); + TableView_VisibleCount++; + } + else + { + curRow_gif = -1; + ui->tableView_gif->clearSelection(); + ui->tableView_gif->setVisible(0); + } + //=== + if(filecount_video>0) + { + ui->tableView_video->setVisible(1); + TableView_VisibleCount++; + } + else + { + curRow_video = -1; + ui->tableView_video->clearSelection(); + ui->tableView_video->setVisible(0); + } + //======================== + ui->pushButton_ResizeFilesListSplitter->setEnabled(TableView_VisibleCount>1);//当可见的文件列表数量大于1时启用重置文件列表比例按钮 + //======================== + ui->pushButton_SaveFileList->setEnabled(1);//列表内有文件时自动启用保存文件列表的按钮 + } + //==================== + // 列表内无文件 + //==================== + else + { + ui->label_FileCount->setVisible(0);//隐藏文件数量label + //=================== + // 禁用文件列表控制按钮 + //=================== + ui->pushButton_ClearList->setEnabled(0); + ui->pushButton_RemoveItem->setEnabled(0); + ui->pushButton_ResizeFilesListSplitter->setEnabled(0); + //==================== + //隐藏文件列表,取消选中 + //==================== + ui->label_DropFile->setVisible(1); + curRow_image = -1; + ui->tableView_image->clearSelection(); + ui->tableView_image->setVisible(0); + curRow_gif = -1; + ui->tableView_gif->clearSelection(); + ui->tableView_gif->setVisible(0); + curRow_video = -1; + ui->tableView_video->clearSelection(); + ui->tableView_video->setVisible(0); + //======================== + ui->pushButton_SaveFileList->setEnabled(0);//列表内没有文件时自动禁用保存文件列表的按钮 + } + return 0; +} +//============================ +// 插入文件 +//============================ +void MainWindow::Table_image_insert_fileName_fullPath(QString fileName, QString SourceFile_fullPath) +{ + mutex_Table_insert.lock(); + //========= + int rowNum = Table_model_image->rowCount(); + Table_model_image->setItem(rowNum, 0, new QStandardItem(fileName)); + Table_model_image->setItem(rowNum, 1, new QStandardItem("")); + Table_model_image->setItem(rowNum, 2, new QStandardItem(SourceFile_fullPath)); + Table_model_image->setItem(rowNum, 3, new QStandardItem("")); + mutex_Table_insert_finished.lock(); + Table_insert_finished=true; + mutex_Table_insert_finished.unlock(); + //======== + mutex_Table_insert.unlock(); +} + +void MainWindow::Table_gif_insert_fileName_fullPath(QString fileName, QString SourceFile_fullPath) +{ + mutex_Table_insert.lock(); + //========= + int rowNum = Table_model_gif->rowCount(); + Table_model_gif->setItem(rowNum, 0, new QStandardItem(fileName)); + Table_model_gif->setItem(rowNum, 1, new QStandardItem("")); + Table_model_gif->setItem(rowNum, 2, new QStandardItem(SourceFile_fullPath)); + Table_model_gif->setItem(rowNum, 3, new QStandardItem("")); + mutex_Table_insert_finished.lock(); + Table_insert_finished=true; + mutex_Table_insert_finished.unlock(); + //======== + mutex_Table_insert.unlock(); +} + +void MainWindow::Table_video_insert_fileName_fullPath(QString fileName, QString SourceFile_fullPath) +{ + mutex_Table_insert.lock(); + //========= + int rowNum = Table_model_video->rowCount(); + Table_model_video->setItem(rowNum, 0, new QStandardItem(fileName)); + Table_model_video->setItem(rowNum, 1, new QStandardItem("")); + Table_model_video->setItem(rowNum, 2, new QStandardItem(SourceFile_fullPath)); + Table_model_video->setItem(rowNum, 3, new QStandardItem("")); + mutex_Table_insert_finished.lock(); + Table_insert_finished=true; + mutex_Table_insert_finished.unlock(); + //======== + mutex_Table_insert.unlock(); +} + +void MainWindow::Table_image_ChangeStatus_rowNumInt_statusQString(int rowNum, QString status) +{ + ui->tableView_image->setUpdatesEnabled(false); + Table_model_image->setItem(rowNum, 1, new QStandardItem(status)); + if(ui->checkBox_FileListAutoSlide->isChecked()) + { + QAbstractItemModel *modessl = Table_model_image; + QModelIndex indextemp = modessl->index(rowNum, 1); + ui->tableView_image->scrollTo(indextemp,QAbstractItemView::PositionAtCenter); + } + ui->tableView_image->setUpdatesEnabled(true); +} + +void MainWindow::Table_gif_ChangeStatus_rowNumInt_statusQString(int rowNum, QString status) +{ + ui->tableView_gif->setUpdatesEnabled(false); + Table_model_gif->setItem(rowNum, 1, new QStandardItem(status)); + if(ui->checkBox_FileListAutoSlide->isChecked()) + { + QAbstractItemModel *modessl = Table_model_gif; + QModelIndex indextemp = modessl->index(rowNum, 1); + ui->tableView_gif->scrollTo(indextemp,QAbstractItemView::PositionAtCenter); + } + ui->tableView_gif->setUpdatesEnabled(true); +} + +void MainWindow::Table_video_ChangeStatus_rowNumInt_statusQString(int rowNum, QString status) +{ + ui->tableView_video->setUpdatesEnabled(false); + Table_model_video->setItem(rowNum, 1, new QStandardItem(status)); + if(ui->checkBox_FileListAutoSlide->isChecked()) + { + QAbstractItemModel *modessl = Table_model_video; + QModelIndex indextemp = modessl->index(rowNum, 1); + ui->tableView_video->scrollTo(indextemp,QAbstractItemView::PositionAtCenter); + } + ui->tableView_video->setUpdatesEnabled(true); +} + +void MainWindow::Table_image_CustRes_rowNumInt_HeightQString_WidthQString(int rowNum, QString height, QString width) +{ + QString ResStr = width+"x"+height; + ui->tableView_image->setUpdatesEnabled(false); + Table_model_image->setItem(rowNum, 3, new QStandardItem(ResStr)); + ui->tableView_image->setUpdatesEnabled(true); +} + +void MainWindow::Table_gif_CustRes_rowNumInt_HeightQString_WidthQString(int rowNum, QString height, QString width) +{ + QString ResStr = width+"x"+height; + ui->tableView_gif->setUpdatesEnabled(false); + Table_model_gif->setItem(rowNum, 3, new QStandardItem(ResStr)); + ui->tableView_gif->setUpdatesEnabled(true); +} + +void MainWindow::Table_video_CustRes_rowNumInt_HeightQString_WidthQString(int rowNum, QString height, QString width) +{ + QString ResStr = width+"x"+height; + ui->tableView_video->setUpdatesEnabled(false); + Table_model_video->setItem(rowNum, 3, new QStandardItem(ResStr)); + ui->tableView_video->setUpdatesEnabled(true); +} + +void MainWindow::Table_image_CustRes_Cancel_rowNumInt(int rowNum) +{ + ui->tableView_image->setUpdatesEnabled(false); + Table_model_image->setItem(rowNum, 3, new QStandardItem("")); + ui->tableView_image->setUpdatesEnabled(true); +} + +void MainWindow::Table_gif_CustRes_Cancel_rowNumInt(int rowNum) +{ + ui->tableView_gif->setUpdatesEnabled(false); + Table_model_gif->setItem(rowNum, 3, new QStandardItem("")); + ui->tableView_gif->setUpdatesEnabled(true); +} + +void MainWindow::Table_video_CustRes_Cancel_rowNumInt(int rowNum) +{ + ui->tableView_video->setUpdatesEnabled(false); + Table_model_video->setItem(rowNum, 3, new QStandardItem("")); + ui->tableView_video->setUpdatesEnabled(true); +} + + +void MainWindow::Table_ChangeAllStatusToWaiting() +{ + QMutex_Table_ChangeAllStatusToWaiting.lock(); + ui_tableViews_setUpdatesEnabled(false); + bool ReProcFinFiles = ui->checkBox_ReProcFinFiles->isChecked(); + int rowNum = Table_model_image->rowCount(); + for (int i = 0; i < rowNum; i++) + { + QAbstractItemModel *modessl = Table_model_image; + QModelIndex indextemp = modessl->index(i, 1); + QVariant datatemp = modessl->data(indextemp); + QString status = datatemp.toString(); + if(ReProcFinFiles) + { + if(status != "Finished, original file deleted") + { + Table_model_image->setItem(i, 1, new QStandardItem("Waiting")); + } + } + else + { + if(status != "Finished, original file deleted" && status != "Finished") + { + Table_model_image->setItem(i, 1, new QStandardItem("Waiting")); + } + } + } + rowNum = Table_model_gif->rowCount(); + for (int i = 0; i < rowNum; i++) + { + QAbstractItemModel *modessl = Table_model_gif; + QModelIndex indextemp = modessl->index(i, 1); + QVariant datatemp = modessl->data(indextemp); + QString status = datatemp.toString(); + if(ReProcFinFiles) + { + if(status != "Finished, original file deleted") + { + Table_model_gif->setItem(i, 1, new QStandardItem("Waiting")); + } + } + else + { + if(status != "Finished, original file deleted" && status != "Finished") + { + Table_model_gif->setItem(i, 1, new QStandardItem("Waiting")); + } + } + } + rowNum = Table_model_video->rowCount(); + for (int i = 0; i < rowNum; i++) + { + QAbstractItemModel *modessl = Table_model_video; + QModelIndex indextemp = modessl->index(i, 1); + QVariant datatemp = modessl->data(indextemp); + QString status = datatemp.toString(); + if(ReProcFinFiles) + { + if(status != "Finished, original file deleted") + { + Table_model_video->setItem(i, 1, new QStandardItem("Waiting")); + } + } + else + { + if(status != "Finished, original file deleted" && status != "Finished") + { + Table_model_video->setItem(i, 1, new QStandardItem("Waiting")); + } + } + } + ui_tableViews_setUpdatesEnabled(true); + QMutex_Table_ChangeAllStatusToWaiting.unlock(); +} + +void MainWindow::Table_Clear() +{ + ui_tableViews_setUpdatesEnabled(false); + //===== + Table_model_image->clear(); + Table_model_gif->clear(); + Table_model_video->clear(); + Init_Table(); + curRow_image = -1; + curRow_gif = -1; + curRow_video = -1; + //===== + ui_tableViews_setUpdatesEnabled(true); +} + +int MainWindow::Table_image_get_rowNum() +{ + int rowNum = Table_model_image->rowCount(); + return rowNum; +} + +int MainWindow::Table_gif_get_rowNum() +{ + int rowNum = Table_model_gif->rowCount(); + return rowNum; +} + +int MainWindow::Table_video_get_rowNum() +{ + int rowNum = Table_model_video->rowCount(); + return rowNum; +} +/* +从table读取状态和完整路径 +[fullpath]=status; +*/ +QMap MainWindow::Table_Read_status_fullpath(QStandardItemModel *Table_model) +{ + int rowNum = Table_model->rowCount(); + QMap Map_fullPath_status; + for (int i = 0; i < rowNum; i++) + { + QAbstractItemModel *modessl = Table_model; + QModelIndex indextemp_status = modessl->index(i, 1); + QVariant datatemp_status = modessl->data(indextemp_status); + QString status = datatemp_status.toString(); + QModelIndex indextemp_fullpath = modessl->index(i, 2); + QVariant datatemp_fullpath = modessl->data(indextemp_fullpath); + QString fullpath = datatemp_fullpath.toString(); + Map_fullPath_status[fullpath]=status; + } + return Map_fullPath_status; +} + +//保存当前文件列表 +int MainWindow::Table_Save_Current_Table_Filelist(QString Table_FileList_ini) +{ + QFile::remove(Table_FileList_ini); + //================= + QSettings *configIniWrite = new QSettings(Table_FileList_ini, QSettings::IniFormat); + //================= 添加警告 ========================= + configIniWrite->setValue("/Warning/EN", "Do not modify this file! It may cause the program to crash! If problems occur after the modification, delete this file and restart the program."); + //================= 存储table_image ========================= + configIniWrite->setValue("/table_image/rowCount", Table_model_image->rowCount()); + for(int i=0; irowCount(); i++) + { + QAbstractItemModel *modessl = Table_model_image; + //=== + QModelIndex indextemp = modessl->index(i, 0); + QVariant datatemp = modessl->data(indextemp); + QString FileName = datatemp.toString(); + configIniWrite->setValue("/table_image/"+QString::number(i,10)+"_FileName", FileName); + //=== + indextemp = modessl->index(i, 1); + datatemp = modessl->data(indextemp); + QString status = datatemp.toString(); + configIniWrite->setValue("/table_image/"+QString::number(i,10)+"_status", status); + //=== + indextemp = modessl->index(i, 2); + datatemp = modessl->data(indextemp); + QString fullPath = datatemp.toString(); + configIniWrite->setValue("/table_image/"+QString::number(i,10)+"_fullPath", fullPath); + //=== + indextemp = modessl->index(i, 3); + datatemp = modessl->data(indextemp); + QString CustRes_str = datatemp.toString(); + configIniWrite->setValue("/table_image/"+QString::number(i,10)+"_CustRes_str", CustRes_str); + if(CustRes_str!="") + { + QMap ResMap = CustRes_getResMap(fullPath); + if(!ResMap.isEmpty()) + { + configIniWrite->setValue("/table_image/"+QString::number(i,10)+"_CustRes_height", ResMap["height"]); + configIniWrite->setValue("/table_image/"+QString::number(i,10)+"_CustRes_width", ResMap["width"]); + } + } + } + //================= 存储table_gif ========================= + configIniWrite->setValue("/table_gif/rowCount", Table_model_gif->rowCount()); + for(int i=0; irowCount(); i++) + { + QAbstractItemModel *modessl = Table_model_gif; + //=== + QModelIndex indextemp = modessl->index(i, 0); + QVariant datatemp = modessl->data(indextemp); + QString FileName = datatemp.toString(); + configIniWrite->setValue("/table_gif/"+QString::number(i,10)+"_FileName", FileName); + //=== + indextemp = modessl->index(i, 1); + datatemp = modessl->data(indextemp); + QString status = datatemp.toString(); + configIniWrite->setValue("/table_gif/"+QString::number(i,10)+"_status", status); + //=== + indextemp = modessl->index(i, 2); + datatemp = modessl->data(indextemp); + QString fullPath = datatemp.toString(); + configIniWrite->setValue("/table_gif/"+QString::number(i,10)+"_fullPath", fullPath); + //=== + indextemp = modessl->index(i, 3); + datatemp = modessl->data(indextemp); + QString CustRes_str = datatemp.toString(); + configIniWrite->setValue("/table_gif/"+QString::number(i,10)+"_CustRes_str", CustRes_str); + if(CustRes_str!="") + { + QMap ResMap = CustRes_getResMap(fullPath); + if(!ResMap.isEmpty()) + { + configIniWrite->setValue("/table_gif/"+QString::number(i,10)+"_CustRes_height", ResMap["height"]); + configIniWrite->setValue("/table_gif/"+QString::number(i,10)+"_CustRes_width", ResMap["width"]); + } + } + } + //================= 存储table_video ========================= + configIniWrite->setValue("/table_video/rowCount", Table_model_video->rowCount()); + for(int i=0; irowCount(); i++) + { + QAbstractItemModel *modessl = Table_model_video; + //=== + QModelIndex indextemp = modessl->index(i, 0); + QVariant datatemp = modessl->data(indextemp); + QString FileName = datatemp.toString(); + configIniWrite->setValue("/table_video/"+QString::number(i,10)+"_FileName", FileName); + //=== + indextemp = modessl->index(i, 1); + datatemp = modessl->data(indextemp); + QString status = datatemp.toString(); + configIniWrite->setValue("/table_video/"+QString::number(i,10)+"_status", status); + //=== + indextemp = modessl->index(i, 2); + datatemp = modessl->data(indextemp); + QString fullPath = datatemp.toString(); + configIniWrite->setValue("/table_video/"+QString::number(i,10)+"_fullPath", fullPath); + //=== + indextemp = modessl->index(i, 3); + datatemp = modessl->data(indextemp); + QString CustRes_str = datatemp.toString(); + configIniWrite->setValue("/table_video/"+QString::number(i,10)+"_CustRes_str", CustRes_str); + if(CustRes_str!="") + { + QMap ResMap = CustRes_getResMap(fullPath); + if(!ResMap.isEmpty()) + { + configIniWrite->setValue("/table_video/"+QString::number(i,10)+"_CustRes_height", ResMap["height"]); + configIniWrite->setValue("/table_video/"+QString::number(i,10)+"_CustRes_width", ResMap["width"]); + } + } + } + return 0; +} +void MainWindow::on_pushButton_SaveFileList_clicked() +{ + if(Table_model_video->rowCount()<=0&&Table_model_image->rowCount()<=0&&Table_model_gif->rowCount()<=0) + { + QMessageBox *MSG = new QMessageBox(); + MSG->setWindowTitle(tr("Error")); + MSG->setText(tr("File list is empty!")); + MSG->setIcon(QMessageBox::Warning); + MSG->setModal(false); + MSG->show(); + return; + } + //====================== 选择保存位置 ========================== + //生成默认保存文件的文件夹 + file_mkDir(Current_Path+"/FilesList_W2xEX"); + //保存文件弹窗 + QString FilesListFullPath = QFileDialog::getSaveFileName(this, tr("Save files list @Waifu2x-Extension-GUI"), + Current_Path+"/FilesList_W2xEX/FilesList_W2xEX_"+QDateTime::currentDateTime().toString("yyyy-MM-dd_hh-mm-ss")+".ini", + "*.ini"); + if(FilesListFullPath.trimmed()=="")return; + //判断文件夹是否存在以及是否可写入 + QFileInfo FilesListFullPath_fileinfo(FilesListFullPath); + QString FilesListFullPath_FolderPath = file_getFolderPath(FilesListFullPath_fileinfo); + if(file_isDirExist(FilesListFullPath_FolderPath)==false || file_isDirWritable(FilesListFullPath_FolderPath)==false) + { + QMessageBox *MSG = new QMessageBox(); + MSG->setWindowTitle(tr("Error")); + MSG->setText(tr("Target folder doesn't exist or unable to write to the target folder.")); + MSG->setIcon(QMessageBox::Warning); + MSG->setModal(false); + MSG->show(); + return; + } + //======================= 开始保存 ======================== + this->setAcceptDrops(0);//禁止drop file + pushButton_Start_setEnabled_self(0);//禁用start button + ui->pushButton_ClearList->setEnabled(0); + ui->pushButton_RemoveItem->setEnabled(0); + ui->pushButton_CustRes_cancel->setEnabled(0); + ui->pushButton_CustRes_apply->setEnabled(0); + ui->pushButton_ReadFileList->setEnabled(0); + ui->pushButton_SaveFileList->setEnabled(0); + ui->pushButton_BrowserFile->setEnabled(0); + emit Send_TextBrowser_NewMessage(tr("Write to the file, please wait.")); + Table_Save_Current_Table_Filelist(FilesListFullPath); + QtConcurrent::run(this, &MainWindow::Table_Save_Current_Table_Filelist_Watchdog,FilesListFullPath); +} +int MainWindow::Table_Save_Current_Table_Filelist_Watchdog(QString Table_FileList_ini) +{ + while(!QFile::exists(Table_FileList_ini)) + { + Delay_msec_sleep(100); + } + emit Send_Table_Save_Current_Table_Filelist_Finished(); + return 0; +} +int MainWindow::Table_Save_Current_Table_Filelist_Finished() +{ + if(Waifu2xMain.isRunning()==false) + { + this->setAcceptDrops(1);//启用drop file + ui->pushButton_ClearList->setEnabled(1); + ui->pushButton_RemoveItem->setEnabled(1); + ui->pushButton_ReadFileList->setEnabled(1); + ui->pushButton_BrowserFile->setEnabled(1); + } + ui->pushButton_CustRes_cancel->setEnabled(1); + ui->pushButton_CustRes_apply->setEnabled(1); + pushButton_Start_setEnabled_self(1);//启用start button + ui->pushButton_SaveFileList->setEnabled(1); + emit Send_TextBrowser_NewMessage(tr("File list saved successfully!")); + //=== + QMessageBox *MSG = new QMessageBox(); + MSG->setWindowTitle(tr("Notification")); + MSG->setText(tr("File list saved successfully!")); + MSG->setIcon(QMessageBox::Information); + MSG->setModal(true); + MSG->show(); + //=== + return 0; +} +int MainWindow::Table_Read_Saved_Table_Filelist(QString Table_FileList_ini) +{ + if(!QFile::exists(Table_FileList_ini)) + { + emit Send_TextBrowser_NewMessage(tr("Cannot find the saved Files List!")); + emit Send_Table_Read_Saved_Table_Filelist_Finished(Table_FileList_ini); + return 0; + } + //================= + QSettings *configIniRead = new QSettings(Table_FileList_ini, QSettings::IniFormat); + //==================== + int rowCount_image = configIniRead->value("/table_image/rowCount").toInt(); + int rowCount_gif = configIniRead->value("/table_gif/rowCount").toInt(); + int rowCount_video = configIniRead->value("/table_video/rowCount").toInt(); + //========== + Progressbar_MaxVal = rowCount_image + rowCount_gif + rowCount_video; + Progressbar_CurrentVal = 0; + emit Send_PrograssBar_Range_min_max(0, Progressbar_MaxVal); + //========= 加载image ======== + for(int i=0; ivalue("/table_image/"+QString::number(i,10)+"_FileName").toString(); + QString status =configIniRead->value("/table_image/"+QString::number(i,10)+"_status").toString(); + QString fullPath =configIniRead->value("/table_image/"+QString::number(i,10)+"_fullPath").toString(); + QString CustRes_str =configIniRead->value("/table_image/"+QString::number(i,10)+"_CustRes_str").toString(); + //================ + mutex_Table_insert_finished.lock(); + Table_insert_finished=false; + mutex_Table_insert_finished.unlock(); + emit Send_Table_image_insert_fileName_fullPath(FileName,fullPath); + while(!Table_insert_finished) + { + Delay_msec_sleep(10); + } + emit Send_Table_image_ChangeStatus_rowNumInt_statusQString(i,status); + if(status=="Failed") + { + emit Send_TextBrowser_NewMessage(tr("[Failed]--[")+fullPath+"]"); + } + //=============== + if(CustRes_str!="") + { + QString CustRes_height =configIniRead->value("/table_image/"+QString::number(i,10)+"_CustRes_height").toString(); + QString CustRes_width =configIniRead->value("/table_image/"+QString::number(i,10)+"_CustRes_width").toString(); + emit Send_Table_image_CustRes_rowNumInt_HeightQString_WidthQString(i,CustRes_height,CustRes_width); + QMap res_map; + res_map["fullpath"] = fullPath; + res_map["height"] = CustRes_height; + res_map["width"] = CustRes_width; + Custom_resolution_list.append(res_map); + } + emit Send_progressbar_Add(); + //Delay_msec_sleep(100); + } + //========= 加载gif ======== + for(int i=0; ivalue("/table_gif/"+QString::number(i,10)+"_FileName").toString(); + QString status =configIniRead->value("/table_gif/"+QString::number(i,10)+"_status").toString(); + QString fullPath =configIniRead->value("/table_gif/"+QString::number(i,10)+"_fullPath").toString(); + QString CustRes_str =configIniRead->value("/table_gif/"+QString::number(i,10)+"_CustRes_str").toString(); + //================ + mutex_Table_insert_finished.lock(); + Table_insert_finished=false; + mutex_Table_insert_finished.unlock(); + emit Send_Table_gif_insert_fileName_fullPath(FileName,fullPath); + while(!Table_insert_finished) + { + Delay_msec_sleep(10); + } + emit Send_Table_gif_ChangeStatus_rowNumInt_statusQString(i,status); + if(status=="Failed") + { + emit Send_TextBrowser_NewMessage(tr("[Failed]--[")+fullPath+"]"); + } + //=============== + if(CustRes_str!="") + { + QString CustRes_height =configIniRead->value("/table_gif/"+QString::number(i,10)+"_CustRes_height").toString(); + QString CustRes_width =configIniRead->value("/table_gif/"+QString::number(i,10)+"_CustRes_width").toString(); + emit Send_Table_gif_CustRes_rowNumInt_HeightQString_WidthQString(i,CustRes_height,CustRes_width); + QMap res_map; + res_map["fullpath"] = fullPath; + res_map["height"] = CustRes_height; + res_map["width"] = CustRes_width; + Custom_resolution_list.append(res_map); + } + emit Send_progressbar_Add(); + //Delay_msec_sleep(100); + } + //========= 加载video ======== + for(int i=0; ivalue("/table_video/"+QString::number(i,10)+"_FileName").toString(); + QString status =configIniRead->value("/table_video/"+QString::number(i,10)+"_status").toString(); + QString fullPath =configIniRead->value("/table_video/"+QString::number(i,10)+"_fullPath").toString(); + QString CustRes_str =configIniRead->value("/table_video/"+QString::number(i,10)+"_CustRes_str").toString(); + //================ + mutex_Table_insert_finished.lock(); + Table_insert_finished=false; + mutex_Table_insert_finished.unlock(); + emit Send_Table_video_insert_fileName_fullPath(FileName,fullPath); + while(!Table_insert_finished) + { + Delay_msec_sleep(10); + } + emit Send_Table_video_ChangeStatus_rowNumInt_statusQString(i,status); + if(status=="Failed") + { + emit Send_TextBrowser_NewMessage(tr("[Failed]--[")+fullPath+"]"); + } + //=============== + if(CustRes_str!="") + { + QString CustRes_height =configIniRead->value("/table_video/"+QString::number(i,10)+"_CustRes_height").toString(); + QString CustRes_width =configIniRead->value("/table_video/"+QString::number(i,10)+"_CustRes_width").toString(); + emit Send_Table_video_CustRes_rowNumInt_HeightQString_WidthQString(i,CustRes_height,CustRes_width); + QMap res_map; + res_map["fullpath"] = fullPath; + res_map["height"] = CustRes_height; + res_map["width"] = CustRes_width; + Custom_resolution_list.append(res_map); + } + emit Send_progressbar_Add(); + //Delay_msec_sleep(100); + } + //==================== + emit Send_Table_Read_Saved_Table_Filelist_Finished(Table_FileList_ini); + return 0; +} +int MainWindow::Table_Read_Saved_Table_Filelist_Finished(QString Table_FileList_ini) +{ + Progressbar_MaxVal = 0; + Progressbar_CurrentVal = 0; + progressbar_clear(); + //==== + ui_tableViews_setUpdatesEnabled(true); + this->setAcceptDrops(1); + pushButton_Start_setEnabled_self(1); + ui->pushButton_CustRes_cancel->setEnabled(1); + ui->pushButton_CustRes_apply->setEnabled(1); + ui->pushButton_ReadFileList->setEnabled(1); + ui->pushButton_SaveFileList->setEnabled(1); + ui->pushButton_BrowserFile->setEnabled(1); + if(!QFile::exists(Table_FileList_ini)) + { + return 0; + } + //================= + QSettings *configIniRead = new QSettings(Table_FileList_ini, QSettings::IniFormat); + //==================== + //========= image ======== + int rowCount_image = configIniRead->value("/table_image/rowCount").toInt(); + if(rowCount_image>0) + { + ui->label_DropFile->setVisible(0);//隐藏文件投放label + ui->tableView_image->setVisible(1); + } + //========= gif ======== + int rowCount_gif = configIniRead->value("/table_gif/rowCount").toInt(); + if(rowCount_gif>0) + { + ui->label_DropFile->setVisible(0);//隐藏文件投放label + ui->tableView_gif->setVisible(1); + } + //========= video ======== + int rowCount_video = configIniRead->value("/table_video/rowCount").toInt(); + if(rowCount_video>0) + { + ui->label_DropFile->setVisible(0);//隐藏文件投放label + ui->tableView_video->setVisible(1); + } + //==================== + ui->tableView_gif->scrollToBottom(); + ui->tableView_image->scrollToBottom(); + ui->tableView_video->scrollToBottom(); + QScrollBar *image_ScrBar = ui->tableView_image->horizontalScrollBar(); + image_ScrBar->setValue(0); + QScrollBar *gif_ScrBar = ui->tableView_gif->horizontalScrollBar(); + gif_ScrBar->setValue(0); + QScrollBar *video_ScrBar = ui->tableView_video->horizontalScrollBar(); + video_ScrBar->setValue(0); + //============ + Send_TextBrowser_NewMessage(tr("File list update is complete!")); + //==== + progressbar_SetToMax(Progressbar_MaxVal); + Progressbar_MaxVal = 0; + Progressbar_CurrentVal = 0; + //==== + if(rowCount_image<=0&&rowCount_video<=0&&rowCount_gif<=0) + { + Send_TextBrowser_NewMessage(tr("The file list saved last time is empty.")); + progressbar_clear(); + } + //== + Table_FileCount_reload(); + //=== + return 0; +} +void MainWindow::on_tableView_image_doubleClicked(const QModelIndex &index) +{ + if(curRow_image==-1)return; + QModelIndex a; + on_tableView_image_pressed(a); +} +void MainWindow::on_tableView_gif_doubleClicked(const QModelIndex &index) +{ + if(curRow_gif==-1)return; + QModelIndex a; + on_tableView_gif_pressed(a); +} +void MainWindow::on_tableView_video_doubleClicked(const QModelIndex &index) +{ + if(curRow_video==-1)return; + QModelIndex a; + on_tableView_video_pressed(a); +} +void MainWindow::on_tableView_image_pressed(const QModelIndex &index) +{ + curRow_image = ui->tableView_image->currentIndex().row(); + curRow_gif = -1; + curRow_video = -1; + ui->tableView_gif->clearSelection(); + ui->tableView_video->clearSelection(); +} +void MainWindow::on_tableView_gif_pressed(const QModelIndex &index) +{ + curRow_gif = ui->tableView_gif->currentIndex().row(); + curRow_image = -1; + curRow_video = -1; + ui->tableView_image->clearSelection(); + ui->tableView_video->clearSelection(); +} +void MainWindow::on_tableView_video_pressed(const QModelIndex &index) +{ + curRow_video = ui->tableView_video->currentIndex().row(); + curRow_image = -1; + curRow_gif = -1; + ui->tableView_image->clearSelection(); + ui->tableView_gif->clearSelection(); +} +/* +启用 or 禁用 三个文件列表的排序功能 +*/ +void MainWindow::Table_EnableSorting(bool EnableSorting) +{ + ui->tableView_video->horizontalHeader()->setSortIndicatorShown(EnableSorting); + ui->tableView_gif->horizontalHeader()->setSortIndicatorShown(EnableSorting); + ui->tableView_image->horizontalHeader()->setSortIndicatorShown(EnableSorting); + //===== + ui->tableView_image->setSortingEnabled(EnableSorting); + ui->tableView_gif->setSortingEnabled(EnableSorting); + ui->tableView_video->setSortingEnabled(EnableSorting); +} +/* +启用/禁用 文件列表table的UI更新 +*/ +void MainWindow::ui_tableViews_setUpdatesEnabled(bool isEnabled) +{ + ui->tableView_video->setUpdatesEnabled(isEnabled); + ui->tableView_gif->setUpdatesEnabled(isEnabled); + ui->tableView_image->setUpdatesEnabled(isEnabled); +} diff --git a/SRC/Waifu2x-Extension-QT/textBrowser.cpp b/SRC_v3.41.01-beta/Waifu2x-Extension-QT/textBrowser.cpp similarity index 97% rename from SRC/Waifu2x-Extension-QT/textBrowser.cpp rename to SRC_v3.41.01-beta/Waifu2x-Extension-QT/textBrowser.cpp index 26c58ab..f11f948 100644 --- a/SRC/Waifu2x-Extension-QT/textBrowser.cpp +++ b/SRC_v3.41.01-beta/Waifu2x-Extension-QT/textBrowser.cpp @@ -1,54 +1,54 @@ -/* - Copyright (C) 2021 Aaron Feng - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU Affero General Public License as published - by the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Affero General Public License for more details. - - You should have received a copy of the GNU Affero General Public License - along with this program. If not, see . - - My Github homepage: https://github.com/AaronFeng753 -*/ - -#include "mainwindow.h" -#include "ui_mainwindow.h" -/* -在文本框内输出一条新消息 -*/ -void MainWindow::TextBrowser_NewMessage(QString message) -{ - QString Current_Time = QDateTime::currentDateTime().toString("[yyyy-MM-dd hh:mm:ss]"); - QString OutPutStr = Current_Time+" "+message; - ui->textBrowser->append(OutPutStr); - ui->textBrowser->moveCursor(QTextCursor::End); -} -/* -输出文本框的欢迎消息 -启动时显示 -*/ -void MainWindow::TextBrowser_StartMes() -{ - QString CurrentVerState=""; - if(isBetaVer) - { - CurrentVerState=tr("[Beta]"); - } - else - { - CurrentVerState=tr("[Stable]"); - } - //==== - ui->textBrowser->append("Waifu2x-Extension-GUI by Aaron Feng"); - ui->textBrowser->append(tr("Version:")+" "+VERSION+" "+CurrentVerState); - ui->textBrowser->append("Github: https://github.com/AaronFeng753/Waifu2x-Extension-GUI"); - if(ui->comboBox_language->currentIndex()==1)ui->textBrowser->append("码云: https://gitee.com/aaronfeng0711/Waifu2x-Extension-GUI"); - ui->textBrowser->append(tr("Please donate to support the developers, so we can bring further updates for this software, thank you! (。・∀・)ノ゙")); - ui->textBrowser->moveCursor(QTextCursor::End); -} +/* + Copyright (C) 2021 Aaron Feng + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU Affero General Public License as published + by the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program. If not, see . + + My Github homepage: https://github.com/AaronFeng753 +*/ + +#include "mainwindow.h" +#include "ui_mainwindow.h" +/* +在文本框内输出一条新消息 +*/ +void MainWindow::TextBrowser_NewMessage(QString message) +{ + QString Current_Time = QDateTime::currentDateTime().toString("[yyyy-MM-dd hh:mm:ss]"); + QString OutPutStr = Current_Time+" "+message; + ui->textBrowser->append(OutPutStr); + ui->textBrowser->moveCursor(QTextCursor::End); +} +/* +输出文本框的欢迎消息 +启动时显示 +*/ +void MainWindow::TextBrowser_StartMes() +{ + QString CurrentVerState=""; + if(isBetaVer) + { + CurrentVerState=tr("[Beta]"); + } + else + { + CurrentVerState=tr("[Stable]"); + } + //==== + ui->textBrowser->append("Waifu2x-Extension-GUI by Aaron Feng"); + ui->textBrowser->append(tr("Version:")+" "+VERSION+" "+CurrentVerState); + ui->textBrowser->append("Github: https://github.com/AaronFeng753/Waifu2x-Extension-GUI"); + if(ui->comboBox_language->currentIndex()==1)ui->textBrowser->append("码云: https://gitee.com/aaronfeng0711/Waifu2x-Extension-GUI"); + ui->textBrowser->append(tr("Please donate to support the developers, so we can bring further updates for this software, thank you! (。・∀・)ノ゙")); + ui->textBrowser->moveCursor(QTextCursor::End); +} diff --git a/SRC/Waifu2x-Extension-QT/topsupporterslist.cpp b/SRC_v3.41.01-beta/Waifu2x-Extension-QT/topsupporterslist.cpp similarity index 100% rename from SRC/Waifu2x-Extension-QT/topsupporterslist.cpp rename to SRC_v3.41.01-beta/Waifu2x-Extension-QT/topsupporterslist.cpp diff --git a/SRC/Waifu2x-Extension-QT/topsupporterslist.h b/SRC_v3.41.01-beta/Waifu2x-Extension-QT/topsupporterslist.h similarity index 100% rename from SRC/Waifu2x-Extension-QT/topsupporterslist.h rename to SRC_v3.41.01-beta/Waifu2x-Extension-QT/topsupporterslist.h diff --git a/SRC/Waifu2x-Extension-QT/topsupporterslist.ui b/SRC_v3.41.01-beta/Waifu2x-Extension-QT/topsupporterslist.ui similarity index 100% rename from SRC/Waifu2x-Extension-QT/topsupporterslist.ui rename to SRC_v3.41.01-beta/Waifu2x-Extension-QT/topsupporterslist.ui diff --git a/SRC/Waifu2x-Extension-QT/video.cpp b/SRC_v3.41.01-beta/Waifu2x-Extension-QT/video.cpp similarity index 97% rename from SRC/Waifu2x-Extension-QT/video.cpp rename to SRC_v3.41.01-beta/Waifu2x-Extension-QT/video.cpp index f35bf57..886e697 100644 --- a/SRC/Waifu2x-Extension-QT/video.cpp +++ b/SRC_v3.41.01-beta/Waifu2x-Extension-QT/video.cpp @@ -1,1365 +1,1365 @@ -/* - Copyright (C) 2021 Aaron Feng - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU Affero General Public License as published - by the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Affero General Public License for more details. - - You should have received a copy of the GNU Affero General Public License - along with this program. If not, see . - - My Github homepage: https://github.com/AaronFeng753 -*/ -#include "mainwindow.h" -#include "ui_mainwindow.h" -/* -根据行数从自定义分辨率列表移除视频文件 -*/ -void MainWindow::video_RemoveFromCustResList(int RowNumber) -{ - QString SourceFile_fullPath = Table_model_video->item(RowNumber,2)->text(); - CustRes_remove(SourceFile_fullPath); -} - -/* -当视频没有自定义分辨率且此时放大倍率为double,则计算一个添加到自定义列表里 -*/ -bool MainWindow::video_DoubleScaleRatioPrep(int RowNumber) -{ - QString SourceFile_fullPath = Table_model_video->item(RowNumber,2)->text(); - if(CustRes_isContained(SourceFile_fullPath) == true || ui->checkBox_FrameInterpolationOnly_Video->isChecked()) - { - //如果已经被定义自定义分辨率,或者仅进行插帧 - return false; - } - //===================== 获取分辨率 ============================= - QMap Map_OrgRes = video_get_Resolution(SourceFile_fullPath); - //========= 计算新的高度宽度 ================== - double ScaleRatio_double = ui->doubleSpinBox_ScaleRatio_video->value(); - int Height_new = qRound(ScaleRatio_double * Map_OrgRes["height"]); - int width_new = qRound(ScaleRatio_double * Map_OrgRes["width"]); - if(Height_new<1 || width_new<1) - { - emit Send_TextBrowser_NewMessage("Warning! Unable to read the resolution of ["+SourceFile_fullPath+"]. This file will only be scaled to "+QString::number((int)ScaleRatio_double,10)+"X."); - return false; - } - if(Height_new%2!=0)Height_new++; - if(width_new%2!=0)width_new++; - //======== 存入自定义分辨率列表中 ============ - QMap res_map; - res_map["fullpath"] = SourceFile_fullPath; - res_map["height"] = QString::number(Height_new,10); - res_map["width"] = QString::number(width_new,10); - Custom_resolution_list.append(res_map); - //========= - return true; -} -/* -计算数字的位数 -*/ -int MainWindow::CalNumDigits(int input_num) -{ - int frameNumDigits=1+(int)log10(input_num); - return frameNumDigits; -} - -/* -判断视频是否是可变帧率的 -*/ -bool MainWindow::video_isVFR(QString videoPath) -{ - //========================= 调用ffprobe读取视频信息 ====================== - QProcess *Get_VideoFPS_process = new QProcess(); - QString cmd = "\""+Current_Path+"/ffprobe_waifu2xEX.exe\" -i \""+videoPath+"\" -select_streams v -show_streams -v quiet -print_format ini -show_format"; - Get_VideoFPS_process->start(cmd); - while(!Get_VideoFPS_process->waitForStarted(100)&&!QProcess_stop) {} - while(!Get_VideoFPS_process->waitForFinished(100)&&!QProcess_stop) {} - //============= 保存ffprobe输出的ini格式文本 ============= - QString ffprobe_output_str = Get_VideoFPS_process->readAllStandardOutput(); - //================ 将ini写入文件保存 ================ - QFileInfo videoFileInfo(videoPath); - QString Path_video_info_ini = ""; - QString video_dir = file_getFolderPath(videoPath); - int FileNo = 0; - do - { - FileNo++; - Path_video_info_ini = video_dir+"/"+file_getBaseName(videoPath)+"_videoInfo_"+QString::number(FileNo,10)+"_Waifu2xEX.ini"; - } - while(QFile::exists(Path_video_info_ini)); - //========= - QFile video_info_ini(Path_video_info_ini); - video_info_ini.remove(); - if (video_info_ini.open(QIODevice::ReadWrite | QIODevice::Text)) //QIODevice::ReadWrite支持读写 - { - QTextStream stream(&video_info_ini); - stream << ffprobe_output_str; - } - video_info_ini.close(); - //================== 读取ini获得参数 ===================== - QString avg_frame_rate = ""; - QString r_frame_rate = ""; - QSettings *configIniRead_videoInfo = new QSettings(Path_video_info_ini, QSettings::IniFormat); - if(configIniRead_videoInfo->value("/streams.stream.0/avg_frame_rate") != QVariant() && configIniRead_videoInfo->value("/streams.stream.0/r_frame_rate") != QVariant()) - { - avg_frame_rate = configIniRead_videoInfo->value("/streams.stream.0/avg_frame_rate").toString().trimmed(); - r_frame_rate = configIniRead_videoInfo->value("/streams.stream.0/r_frame_rate").toString().trimmed(); - } - video_info_ini.remove(); - //===== - if(avg_frame_rate!=""&&r_frame_rate!="") - { - return (avg_frame_rate!=r_frame_rate); - } - else - { - return true; - } -} -/* -根据分辨率判断是否跳过 -true = 跳过 -*/ -bool MainWindow::Video_AutoSkip_CustRes(int rowNum) -{ - if(ui->checkBox_AutoSkip_CustomRes->isChecked()==false || ui->checkBox_FrameInterpolationOnly_Video->isChecked()==true)return false; - QString SourceFile_fullPath = Table_model_video->item(rowNum,2)->text(); - if(CustRes_isContained(SourceFile_fullPath)) - { - QMap Res_map = CustRes_getResMap(SourceFile_fullPath);//res_map["fullpath"],["height"],["width"] - int CustRes_height=Res_map["height"].toInt(); - int CustRes_width=Res_map["width"].toInt(); - //========================= - QMap res_map = video_get_Resolution(SourceFile_fullPath); - int original_height = res_map["height"]; - int original_width = res_map["width"]; - if(original_height<=0||original_width<=0)//判断是否读取失败 - { - return false; - } - //========================== - if((CustRes_height*CustRes_width) <= (original_height*original_width)) - { - return true; - } - else - { - return false; - } - } - else - { - return false; - } -} - -/* -直接获取视频的分辨率 -*/ -QMap MainWindow::video_get_Resolution(QString VideoFileFullPath) -{ - emit Send_TextBrowser_NewMessage(tr("Get resolution of the video:[")+VideoFileFullPath+"]"); - //========================= 调用ffprobe读取视频信息 ====================== - QProcess *Get_resolution_process = new QProcess(); - QString cmd = "\""+Current_Path+"/ffprobe_waifu2xEX.exe\" -i \""+VideoFileFullPath+"\" -select_streams v -show_streams -v quiet -print_format ini -show_format"; - Get_resolution_process->start(cmd); - while(!Get_resolution_process->waitForStarted(100)&&!QProcess_stop) {} - while(!Get_resolution_process->waitForFinished(100)&&!QProcess_stop) {} - //============= 保存ffprobe输出的ini格式文本 ============= - QString ffprobe_output_str = Get_resolution_process->readAllStandardOutput(); - //================ 将ini写入文件保存 ================ - QFileInfo videoFileInfo(VideoFileFullPath); - QString Path_video_info_ini = ""; - QString video_dir = file_getFolderPath(VideoFileFullPath); - int FileNo = 0; - do - { - FileNo++; - Path_video_info_ini = video_dir+"/"+file_getBaseName(VideoFileFullPath)+"_videoInfo_"+QString::number(FileNo,10)+"_Waifu2xEX.ini"; - } - while(QFile::exists(Path_video_info_ini)); - //========= - QFile video_info_ini(Path_video_info_ini); - video_info_ini.remove(); - if (video_info_ini.open(QIODevice::ReadWrite | QIODevice::Text)) //QIODevice::ReadWrite支持读写 - { - QTextStream stream(&video_info_ini); - stream << ffprobe_output_str; - } - video_info_ini.close(); - //================== 读取ini获得参数 ===================== - QSettings *configIniRead_videoInfo = new QSettings(Path_video_info_ini, QSettings::IniFormat); - QString width_str = ""; - QString height_str = ""; - if(configIniRead_videoInfo->value("/streams.stream.0/width") != QVariant() && configIniRead_videoInfo->value("/streams.stream.0/height") != QVariant()) - { - width_str = configIniRead_videoInfo->value("/streams.stream.0/width").toString().trimmed(); - height_str = configIniRead_videoInfo->value("/streams.stream.0/height").toString().trimmed(); - } - video_info_ini.remove(); - //======================= - if(width_str!="" && height_str!="") - { - int width_int = width_str.toInt(); - int height_int = height_str.toInt(); - if(width_int>0 && height_int>0) - { - QMap res_map; - res_map["height"] = height_int; - res_map["width"] = width_int; - return res_map; - } - } - emit Send_TextBrowser_NewMessage(tr("ERROR! Unable to read the resolution of the video. [")+VideoFileFullPath+"]"); - QMap empty; - empty["height"] = 0; - empty["width"] = 0; - return empty; -} - -/* -根据视频时长,判断是否需要分段处理 -*/ -bool MainWindow::video_isNeedProcessBySegment(int rowNum) -{ - if(ui->checkBox_ProcessVideoBySegment->isChecked()==false)return false;//如果没启用分段处理,直接返回false - QString VideoFile = Table_model_video->item(rowNum,2)->text(); - if(video_get_duration(VideoFile)>ui->spinBox_SegmentDuration->value()) - { - return true; - } - else - { - emit Send_TextBrowser_NewMessage(tr("This video is too short, so segment processing is automatically disabled.[")+VideoFile+"]"); - return false; - } -} - -/* -生成视频片段文件夹编号 -*/ -QString MainWindow::video_getClipsFolderNo() -{ - QString current_date =QDateTime::currentDateTime().toString("yyMMddhhmmss"); - return current_date; -} -/* -组装视频(从mp4片段组装) -*/ -void MainWindow::video_AssembleVideoClips(QString VideoClipsFolderPath,QString VideoClipsFolderName,QString video_mp4_scaled_fullpath,QString AudioPath) -{ - emit Send_TextBrowser_NewMessage(tr("Start assembling video with clips:[")+video_mp4_scaled_fullpath+"]"); - //================= - QStringList VideoClips_Scan_list = file_getFileNames_in_Folder_nofilter(VideoClipsFolderPath); - QStringList VideoClips_fileName_list; - VideoClips_fileName_list.clear(); - QFileInfo vfinfo(video_mp4_scaled_fullpath); - QString video_dir = file_getFolderPath(video_mp4_scaled_fullpath); - /* - 生成视频片段文件完整路径QStringList - */ - for (int VideoNameNo = 0; VideoNameNocheckBox_AudioDenoise->isChecked())&&QFile::exists(AudioPath)) - { - QString AudioPath_tmp = video_AudioDenoise(AudioPath); - if(AudioPath_tmp!=AudioPath) - { - AudioPath = AudioPath_tmp; - Del_DenoisedAudio = true; - } - } - //================= 获取比特率 ================= - QString bitrate_video_cmd=""; - if(ui->spinBox_bitrate_vid->value()>0 && ui->groupBox_video_settings->isChecked()) - { - bitrate_video_cmd = " -b:v "+QString::number(ui->spinBox_bitrate_vid->value(),10)+"k "; - } - else - { - QString BitRate_str = video_get_bitrate(Mp4Clip_forReadInfo,false,true); - if(BitRate_str!="") - { - bitrate_video_cmd = " -b:v "+BitRate_str+" "; - } - else - { - int BitRate = video_UseRes2CalculateBitrate(Mp4Clip_forReadInfo); - if(BitRate!=0)bitrate_video_cmd = " -b:v "+QString::number(BitRate,10)+"k "; - } - } - //================= 读取视频编码器设定 ============== - QString encoder_video_cmd=""; - if(ui->groupBox_video_settings->isChecked() && ui->lineEdit_encoder_vid->text().trimmed()!="") - { - encoder_video_cmd = " -c:v "+ui->lineEdit_encoder_vid->text().trimmed()+" ";//图像编码器 - } - //=============== 读取音频编码设定 ==================== - QString encoder_audio_cmd=""; - QString bitrate_audio_cmd=""; - if(ui->groupBox_video_settings->isChecked()) - { - if(ui->lineEdit_encoder_audio->text().trimmed()!="") - encoder_audio_cmd=" -c:a "+ui->lineEdit_encoder_audio->text().trimmed()+" "; - if(ui->spinBox_bitrate_audio->value()>0) - bitrate_audio_cmd=" -b:a "+QString::number(ui->spinBox_bitrate_audio->value(),10)+"k "; - } - //================== - QString Extra_command = ""; - if(ui->groupBox_video_settings->isChecked() && ui->lineEdit_ExCommand_output->text().trimmed()!="") - { - Extra_command = " "+ui->lineEdit_ExCommand_output->text().trimmed()+" ";//附加指令 - } - //================ 获取fps ===================== - QString fps_video_cmd=" "; - QString fps = video_get_fps(Mp4Clip_forReadInfo).trimmed(); - if(fps != "0.0") - { - fps_video_cmd = " -r "+fps+" "; - } - //================= 开始处理 ============================= - QString CMD = ""; - if(QFile::exists(AudioPath)) - { - CMD = "\""+ffmpeg_path+"\" -y -f concat -safe 0 "+fps_video_cmd+" -i \""+Path_FFMpegFileList+"\" "+fps_video_cmd+" -i \""+AudioPath+"\" "+fps_video_cmd+" "+bitrate_video_cmd+encoder_video_cmd+fps_video_cmd+encoder_audio_cmd+bitrate_audio_cmd+Extra_command+"\""+video_mp4_scaled_fullpath+"\""; - } - else - { - CMD = "\""+ffmpeg_path+"\" -y -f concat -safe 0 "+fps_video_cmd+" -i \""+Path_FFMpegFileList+"\""+bitrate_video_cmd+encoder_video_cmd+fps_video_cmd+Extra_command+"\""+video_mp4_scaled_fullpath+"\""; - } - QProcess AssembleVideo; - AssembleVideo.start(CMD); - while(!AssembleVideo.waitForStarted(100)&&!QProcess_stop) {} - while(!AssembleVideo.waitForFinished(100)&&!QProcess_stop) - { - if(waifu2x_STOP) - { - AssembleVideo.close(); - QFile::remove(video_mp4_scaled_fullpath); - QFile::remove(Path_FFMpegFileList); - return; - } - } - //检查是否发生错误 - if(QFile::exists(video_mp4_scaled_fullpath)==false)//检查是否成功生成视频 - { - MultiLine_ErrorOutput_QMutex.lock(); - emit Send_TextBrowser_NewMessage(tr("Error output for FFmpeg when processing:[")+video_mp4_scaled_fullpath+"]"); - emit Send_TextBrowser_NewMessage("\n--------------------------------------"); - //标准输出 - emit Send_TextBrowser_NewMessage(AssembleVideo.readAllStandardOutput()); - //错误输出 - emit Send_TextBrowser_NewMessage(AssembleVideo.readAllStandardError()); - emit Send_TextBrowser_NewMessage("\n--------------------------------------"); - MultiLine_ErrorOutput_QMutex.unlock(); - } - QFile::remove(Path_FFMpegFileList);//删除文件列表 - //=================== - if(Del_DenoisedAudio)QFile::remove(AudioPath); - //============================== - emit Send_TextBrowser_NewMessage(tr("Finish assembling video with clips:[")+video_mp4_scaled_fullpath+"]"); -} -/* -将视频拆分到帧(分段的) -*/ -void MainWindow::video_video2images_ProcessBySegment(QString VideoPath,QString FrameFolderPath,int StartTime,int SegmentDuration) -{ - emit Send_TextBrowser_NewMessage(tr("Start splitting video: [")+VideoPath+"]"); - //================= - QString ffmpeg_path = Current_Path+"/ffmpeg_waifu2xEX.exe"; - QString video_mp4_fullpath = VideoPath; - //================ 获取fps ===================== - QString fps_video_cmd=" "; - QString fps = video_get_fps(video_mp4_fullpath).trimmed(); - if(fps != "0.0") - { - fps_video_cmd = " -r "+fps+" "; - } - //===================== - int FrameNumDigits = video_get_frameNumDigits(video_mp4_fullpath); - if(FrameNumDigits==0)return; - QFile::remove(isPreVFIDone_MarkFilePath(VideoPath)); - //===================== - QProcess video_splitFrame; - video_splitFrame.start("\""+ffmpeg_path+"\" -y"+fps_video_cmd+"-i \""+video_mp4_fullpath+"\" -ss "+QString::number(StartTime,10)+" -t "+QString::number(SegmentDuration,10)+fps_video_cmd+" \""+FrameFolderPath.replace("%","%%")+"/%0"+QString::number(FrameNumDigits,10)+"d.png\""); - while(!video_splitFrame.waitForStarted(100)&&!QProcess_stop) {} - while(!video_splitFrame.waitForFinished(100)&&!QProcess_stop) {} - //============== 尝试在Win7下可能兼容的指令 ================================ - if(file_isDirEmpty(FrameFolderPath)) - { - video_splitFrame.start("\""+ffmpeg_path+"\" -y"+fps_video_cmd+"-i \""+video_mp4_fullpath+"\" -ss "+QString::number(StartTime,10)+" -t "+QString::number(SegmentDuration,10)+fps_video_cmd+" \""+FrameFolderPath.replace("%","%%")+"/%%0"+QString::number(FrameNumDigits,10)+"d.png\""); - while(!video_splitFrame.waitForStarted(100)&&!QProcess_stop) {} - while(!video_splitFrame.waitForFinished(100)&&!QProcess_stop) {} - } - //======== 插帧 ========= - QFileInfo vfinfo(VideoPath); - QString video_dir = file_getFolderPath(vfinfo); - QString video_filename = file_getBaseName(VideoPath); - QString VFI_FolderPath_tmp = video_dir+"/"+video_filename+"_PreVFI_W2xEX"; - if(ui->checkBox_VfiAfterScale_VFI->isChecked()==false && ui->groupBox_FrameInterpolation->isChecked()==true && ui->checkBox_FrameInterpolationOnly_Video->isChecked()==false) //如果启用了插帧 - { - //如果检测到完整的已经插帧的帧缓存 - if(file_isDirExist(VFI_FolderPath_tmp) && (file_getFileNames_in_Folder_nofilter(FrameFolderPath).size() * ui->spinBox_MultipleOfFPS_VFI->value() == file_getFileNames_in_Folder_nofilter(VFI_FolderPath_tmp).size())) - { - file_DelDir(FrameFolderPath); - QDir VFI_FolderPath_tmp_qdir(VFI_FolderPath_tmp); - VFI_FolderPath_tmp_qdir.rename(VFI_FolderPath_tmp,FrameFolderPath); - return; - } - else - { - if(FrameInterpolation(FrameFolderPath,VFI_FolderPath_tmp)==true) - { - //如果插帧成功 - file_DelDir(FrameFolderPath); - QDir VFI_FolderPath_tmp_qdir(VFI_FolderPath_tmp); - VFI_FolderPath_tmp_qdir.rename(VFI_FolderPath_tmp,FrameFolderPath); - file_generateMarkFile(isPreVFIDone_MarkFilePath(VideoPath),QString("%1").arg(ui->spinBox_MultipleOfFPS_VFI->value())); - return; - } - else - { - file_DelDir(FrameFolderPath); - file_mkDir(FrameFolderPath); - file_DelDir(VFI_FolderPath_tmp); - if(waifu2x_STOP==false)emit Send_TextBrowser_NewMessage(tr("Failed to interpolate frames of video:[")+VideoPath+"]"); - return; - } - } - } - //==================================== - emit Send_TextBrowser_NewMessage(tr("Finish splitting video: [")+VideoPath+"]"); -} - -/* -提取视频的音频 -*/ -void MainWindow::video_get_audio(QString VideoPath,QString AudioPath) -{ - emit Send_TextBrowser_NewMessage(tr("Extract audio from video: [")+VideoPath+"]"); - //============================================== - QString ffmpeg_path = Current_Path+"/ffmpeg_waifu2xEX.exe"; - QFile::remove(AudioPath); - QProcess video_splitSound; - video_splitSound.start("\""+ffmpeg_path+"\" -y -i \""+VideoPath+"\" \""+AudioPath+"\""); - while(!video_splitSound.waitForStarted(100)&&!QProcess_stop) {} - while(!video_splitSound.waitForFinished(100)&&!QProcess_stop) {} - if(QFile::exists(AudioPath)) - { - emit Send_TextBrowser_NewMessage(tr("Successfully extracted audio from video: [")+VideoPath+"]"); - } - else - { - emit Send_TextBrowser_NewMessage(tr("Failed to extract audio from video: [")+VideoPath+tr("] This video might be a silent video, so will continue to process this video.")); - } -} -/* -将视频转换为mp4 -*/ -QString MainWindow::video_To_CFRMp4(QString VideoPath) -{ - QFileInfo vfinfo(VideoPath); - QString video_ext = vfinfo.suffix(); - bool isVFR = false; - //============== - if(video_ext.toLower()=="mp4") - { - if(video_isVFR(VideoPath)==false) - { - return VideoPath; - } - else - { - isVFR = true; - } - } - QString video_dir = file_getFolderPath(vfinfo); - QString video_filename = file_getBaseName(VideoPath); - QString video_mp4_fullpath = video_dir+"/"+video_filename+"_"+video_ext+"_CfrMp4.mp4"; - if(QFile::exists(video_mp4_fullpath))return video_mp4_fullpath; - QFile::remove(video_mp4_fullpath); - //================= - emit Send_TextBrowser_NewMessage(tr("Start converting video: [")+VideoPath+tr("] to CFR MP4.")); - QString ffmpeg_path = Current_Path+"/ffmpeg_waifu2xEX.exe"; - QString vcodec_copy_cmd = ""; - QString acodec_copy_cmd = ""; - QString bitrate_vid_cmd = ""; - QString bitrate_audio_cmd = ""; - QString Extra_command = ""; - QString bitrate_FromOG = ""; - QString vsync_1 = " -vsync 1 "; - if(ui->groupBox_video_settings->isChecked()) - { - if(ui->checkBox_IgnoreFrameRateMode->isChecked()==true) - { - vsync_1 = ""; - isVFR = false; - } - Extra_command = ui->lineEdit_ExCommand_2mp4->text().trimmed(); - if(ui->checkBox_vcodec_copy_2mp4->isChecked()&&isVFR==false) - { - vcodec_copy_cmd = " -vcodec copy "; - } - else - { - if(ui->spinBox_bitrate_vid_2mp4->value()>0&&ui->spinBox_bitrate_audio_2mp4->value()>0)bitrate_vid_cmd = " -b:v "+QString::number(ui->spinBox_bitrate_vid_2mp4->value(),10)+"k "; - } - if(ui->checkBox_acodec_copy_2mp4->isChecked()&&isVFR==false) - { - acodec_copy_cmd = " -acodec copy "; - } - else - { - if(ui->spinBox_bitrate_vid_2mp4->value()>0&&ui->spinBox_bitrate_audio_2mp4->value()>0)bitrate_audio_cmd = " -b:a "+QString::number(ui->spinBox_bitrate_audio_2mp4->value(),10)+"k "; - } - } - if((ui->groupBox_video_settings->isChecked()==false)||(ui->spinBox_bitrate_vid_2mp4->value()<=0||ui->spinBox_bitrate_audio_2mp4->value()<=0)) - { - QString BitRate = video_get_bitrate(VideoPath,true,false); - if(BitRate!="") - { - bitrate_FromOG = BitRate; - } - else - { - emit Send_TextBrowser_NewMessage(tr("Warning! Unable to get the bitrate of the [")+VideoPath+tr("]. The bit rate automatically allocated by ffmpeg will be used.")); - } - } - //===== - QProcess video_tomp4; - video_tomp4.start("\""+ffmpeg_path+"\" -y -i \""+VideoPath+"\""+vsync_1+vcodec_copy_cmd+acodec_copy_cmd+bitrate_vid_cmd+bitrate_audio_cmd+bitrate_FromOG+" "+Extra_command+" \""+video_mp4_fullpath+"\""); - while(!video_tomp4.waitForStarted(100)&&!QProcess_stop) {} - while(!video_tomp4.waitForFinished(100)&&!QProcess_stop) {} - //====== - if(QFile::exists(video_mp4_fullpath)) - { - emit Send_TextBrowser_NewMessage(tr("Successfully converted video: [")+VideoPath+tr("] to CFR MP4.")); - return video_mp4_fullpath; - } - return "null"; -} -//=============== -//获取时长(秒) -//=============== -int MainWindow::video_get_duration(QString videoPath) -{ - emit Send_TextBrowser_NewMessage(tr("Get duration of the video:[")+videoPath+"]"); - //========================= 调用ffprobe读取视频信息 ====================== - QProcess *Get_Duration_process = new QProcess(); - QString cmd = "\""+Current_Path+"/ffprobe_waifu2xEX.exe\" -i \""+videoPath+"\" -select_streams v -show_streams -v quiet -print_format ini -show_format"; - Get_Duration_process->start(cmd); - while(!Get_Duration_process->waitForStarted(100)&&!QProcess_stop) {} - while(!Get_Duration_process->waitForFinished(100)&&!QProcess_stop) {} - //============= 保存ffprobe输出的ini格式文本 ============= - QString ffprobe_output_str = Get_Duration_process->readAllStandardOutput(); - //================ 将ini写入文件保存 ================ - QFileInfo videoFileInfo(videoPath); - QString Path_video_info_ini = ""; - QString video_dir = file_getFolderPath(videoPath); - int FileNo = 0; - do - { - FileNo++; - Path_video_info_ini = video_dir+"/"+file_getBaseName(videoPath)+"_videoInfo_"+QString::number(FileNo,10)+"_Waifu2xEX.ini"; - } - while(QFile::exists(Path_video_info_ini)); - //========= - QFile video_info_ini(Path_video_info_ini); - video_info_ini.remove(); - if (video_info_ini.open(QIODevice::ReadWrite | QIODevice::Text)) //QIODevice::ReadWrite支持读写 - { - QTextStream stream(&video_info_ini); - stream << ffprobe_output_str; - } - video_info_ini.close(); - //================== 读取ini获得参数 ===================== - QString Duration = ""; - QSettings *configIniRead_videoInfo = new QSettings(Path_video_info_ini, QSettings::IniFormat); - if(configIniRead_videoInfo->value("/format/duration") != QVariant()) - { - Duration = configIniRead_videoInfo->value("/format/duration").toString().trimmed(); - } - video_info_ini.remove(); - //======================= - if(Duration=="") - { - emit Send_TextBrowser_NewMessage(tr("ERROR! Unable to get the duration of the [")+videoPath+tr("].")); - return 0; - } - //======================= - double Duration_double = Duration.toDouble(); - int Duration_int = (int)Duration_double; - //===================== - return Duration_int; -} -/* -音频降噪 -*/ -QString MainWindow::video_AudioDenoise(QString OriginalAudioPath) -{ - emit Send_TextBrowser_NewMessage(tr("Starting to denoise audio.[")+OriginalAudioPath+"]"); - //=========== - QFileInfo fileinfo(OriginalAudioPath); - QString file_name = file_getBaseName(OriginalAudioPath); - QString file_ext = fileinfo.suffix(); - QString file_path = file_getFolderPath(fileinfo); - //================ - QString program = Current_Path+"/SoX/sox_waifu2xEX.exe"; - QString DenoiseProfile = file_path+"/"+file_name+"_DenoiseProfile.dp"; - QString DenoisedAudio = file_path+"/"+file_name+"_Denoised."+file_ext; - double DenoiseLevel = ui->doubleSpinBox_AudioDenoiseLevel->value(); - //================ - QProcess vid; - vid.start("\""+program+"\" \""+OriginalAudioPath+"\" -n noiseprof \""+DenoiseProfile+"\""); - while(!vid.waitForStarted(100)&&!QProcess_stop) {} - while(!vid.waitForFinished(100)&&!QProcess_stop) {} - //================ - vid.start("\""+program+"\" \""+OriginalAudioPath+"\" \""+DenoisedAudio+"\" noisered \""+DenoiseProfile+"\" "+QString("%1").arg(DenoiseLevel)); - while(!vid.waitForStarted(100)&&!QProcess_stop) {} - while(!vid.waitForFinished(100)&&!QProcess_stop) {} - //================ - if(QFile::exists(DenoisedAudio)) - { - emit Send_TextBrowser_NewMessage(tr("Successfully denoise audio.[")+OriginalAudioPath+"]"); - QFile::remove(DenoiseProfile); - return DenoisedAudio; - } - else - { - emit Send_TextBrowser_NewMessage(tr("Error! Unable to denoise audio.[")+OriginalAudioPath+"]"); - return OriginalAudioPath; - } -} -/* -保存进度 -*/ -void MainWindow::video_write_Progress_ProcessBySegment(QString VideoConfiguration_fullPath,int StartTime,bool isSplitComplete,bool isScaleComplete,int OLDSegmentDuration,int LastVideoClipNo) -{ - QSettings *configIniWrite = new QSettings(VideoConfiguration_fullPath, QSettings::IniFormat); - configIniWrite->setIniCodec(QTextCodec::codecForName("UTF-8")); - //==================== 存储进度 ================================== - configIniWrite->setValue("/Progress/StartTime", StartTime); - configIniWrite->setValue("/Progress/isSplitComplete", isSplitComplete); - configIniWrite->setValue("/Progress/isScaleComplete", isScaleComplete); - configIniWrite->setValue("/Progress/OLDSegmentDuration", OLDSegmentDuration); - configIniWrite->setValue("/Progress/LastVideoClipNo", LastVideoClipNo); -} -/* -保存视频配置 -*/ -void MainWindow::video_write_VideoConfiguration(QString VideoConfiguration_fullPath,int ScaleRatio,int DenoiseLevel,bool CustRes_isEnabled,int CustRes_height,int CustRes_width,QString EngineName,bool isProcessBySegment,QString VideoClipsFolderPath,QString VideoClipsFolderName,bool isVideoFrameInterpolationEnabled,int MultipleOfFPS) -{ - QSettings *configIniWrite = new QSettings(VideoConfiguration_fullPath, QSettings::IniFormat); - configIniWrite->setIniCodec(QTextCodec::codecForName("UTF-8")); - //================= 添加警告 ========================= - configIniWrite->setValue("/Warning/EN", "Do not modify this file! It may cause the program to crash! If problems occur after the modification, delete this file and restart the program."); - //==================== 存储视频信息 ================================== - configIniWrite->setValue("/VideoConfiguration/ScaleRatio", ScaleRatio); - configIniWrite->setValue("/VideoConfiguration/DenoiseLevel", DenoiseLevel); - configIniWrite->setValue("/VideoConfiguration/CustRes_isEnabled", CustRes_isEnabled); - configIniWrite->setValue("/VideoConfiguration/CustRes_height", CustRes_height); - configIniWrite->setValue("/VideoConfiguration/CustRes_width", CustRes_width); - configIniWrite->setValue("/VideoConfiguration/EngineName", EngineName); - configIniWrite->setValue("/VideoConfiguration/isProcessBySegment", isProcessBySegment); - configIniWrite->setValue("/VideoConfiguration/VideoClipsFolderPath", VideoClipsFolderPath); - configIniWrite->setValue("/VideoConfiguration/VideoClipsFolderName", VideoClipsFolderName); - configIniWrite->setValue("/VideoConfiguration/isVideoFrameInterpolationEnabled", isVideoFrameInterpolationEnabled); - configIniWrite->setValue("/VideoConfiguration/MultipleOfFPS", MultipleOfFPS); - //==================== 存储进度 ================================== - configIniWrite->setValue("/Progress/StartTime", 0); - configIniWrite->setValue("/Progress/isSplitComplete", false); - configIniWrite->setValue("/Progress/isScaleComplete", false); - configIniWrite->setValue("/Progress/OLDSegmentDuration", -1); - configIniWrite->setValue("/Progress/LastVideoClipNo", -1); -} - -/* -直接读取视频 分辨率 然后用 自有算法 计算其应该有的比特率 -单位为k -*/ -int MainWindow::video_UseRes2CalculateBitrate(QString VideoFileFullPath) -{ - QMap res_map = video_get_Resolution(VideoFileFullPath); - int original_height = res_map["height"]; - int original_width = res_map["width"]; - if(original_height<=0||original_width<=0) - { - return 0; - } - //========= - double MultipleOfBitrate_OGFR = 1; - QString fps = video_get_fps(VideoFileFullPath).trimmed(); - if(fps != "0.0") - { - QStringList FPS_Nums = fps.split("/"); - double FPS_Nums_0 = FPS_Nums.at(0).toDouble(); - double FPS_Nums_1 = FPS_Nums.at(1).toDouble(); - if(FPS_Nums_0 >= FPS_Nums_1) - { - MultipleOfBitrate_OGFR = ((FPS_Nums_0/FPS_Nums_1)/24)*0.75; - if(MultipleOfBitrate_OGFR<1) - { - MultipleOfBitrate_OGFR = 1; - } - } - } - //========= - if(original_height<=original_width) - { - return qRound(original_height*6*MultipleOfBitrate_OGFR); - } - else - { - return qRound(original_width*6*MultipleOfBitrate_OGFR); - } -} - -QString MainWindow::video_get_bitrate_AccordingToRes_FrameFolder(QString ScaledFrameFolderPath,QString VideoPath) -{ - QStringList flist = file_getFileNames_in_Folder_nofilter(ScaledFrameFolderPath); - QString Full_Path_File = ""; - if(!flist.isEmpty()) - { - for(int i = 0; i < flist.size(); i++) - { - QString tmp = flist.at(i); - Full_Path_File = ScaledFrameFolderPath + "/" + tmp; - QFileInfo finfo(Full_Path_File); - if(finfo.suffix()=="png")break; - } - } - QImage qimage_original; - qimage_original.load(Full_Path_File); - int original_height = qimage_original.height(); - int original_width = qimage_original.width(); - if(original_height<=0||original_width<=0) - { - return ""; - } - //========= - double MultipleOfBitrate_OGFR = 1; - QString fps = video_get_fps(VideoPath).trimmed(); - if(fps != "0.0") - { - QStringList FPS_Nums = fps.split("/"); - double FPS_Nums_0 = FPS_Nums.at(0).toDouble(); - double FPS_Nums_1 = FPS_Nums.at(1).toDouble(); - if(FPS_Nums_0 >= FPS_Nums_1) - { - MultipleOfBitrate_OGFR = ((FPS_Nums_0/FPS_Nums_1)/24)*0.75; - if(MultipleOfBitrate_OGFR<1) - { - MultipleOfBitrate_OGFR = 1; - } - } - } - //========= - double MultipleOfBitrate_MOF = 1; - if(ui->groupBox_FrameInterpolation->isChecked()==true) - { - MultipleOfBitrate_MOF = ui->spinBox_MultipleOfFPS_VFI->value()*0.75; - } - //========= - if(original_height<=original_width) - { - return QString::number(qRound(original_height*6*MultipleOfBitrate_MOF*MultipleOfBitrate_OGFR),10); - } - else - { - return QString::number(qRound(original_width*6*MultipleOfBitrate_MOF*MultipleOfBitrate_OGFR),10); - } -} -/* -获取视频比特率 -*/ -QString MainWindow::video_get_bitrate(QString videoPath,bool isReturnFullCMD,bool isVidOnly) -{ - emit Send_TextBrowser_NewMessage(tr("Get bitrate of the video:[")+videoPath+"]"); - //========================= 调用ffprobe读取视频信息 ====================== - QProcess *Get_Bitrate_process = new QProcess(); - QString cmd = "\""+Current_Path+"/ffprobe_waifu2xEX.exe\" -i \""+videoPath+"\" -select_streams v -show_streams -v quiet -print_format ini -show_format"; - Get_Bitrate_process->start(cmd); - while(!Get_Bitrate_process->waitForStarted(100)&&!QProcess_stop) {} - while(!Get_Bitrate_process->waitForFinished(100)&&!QProcess_stop) {} - //============= 保存ffprobe输出的ini格式文本 ============= - QString ffprobe_output_str = Get_Bitrate_process->readAllStandardOutput(); - //================ 将ini写入文件保存 ================ - //创建文件夹 - QString video_info_dir = Current_Path+"/videoInfo"; - if(!file_isDirExist(video_info_dir)) - { - file_mkDir(video_info_dir); - } - //======================== - QFileInfo videoFileInfo(videoPath); - QString Path_video_info_ini = ""; - QString video_dir = file_getFolderPath(videoPath); - int FileNo = 0; - do - { - FileNo++; - Path_video_info_ini = video_dir+"/"+file_getBaseName(videoPath)+"_videoInfo_"+QString::number(FileNo,10)+"_Waifu2xEX.ini"; - } - while(QFile::exists(Path_video_info_ini)); - //========= - QFile video_info_ini(Path_video_info_ini); - video_info_ini.remove(); - if (video_info_ini.open(QIODevice::ReadWrite | QIODevice::Text)) //QIODevice::ReadWrite支持读写 - { - QTextStream stream(&video_info_ini); - stream << ffprobe_output_str; - } - video_info_ini.close(); - //================== 读取ini获得参数 ===================== - QSettings *configIniRead_videoInfo = new QSettings(Path_video_info_ini, QSettings::IniFormat); - QString BitRate = ""; - QString BitRateCMD = ""; - if(configIniRead_videoInfo->value("/streams.stream.0/bit_rate")!=QVariant()) - { - BitRate = configIniRead_videoInfo->value("/streams.stream.0/bit_rate").toString().trimmed(); - if(isReturnFullCMD==true)BitRateCMD = " -b:v "+BitRate+" "; - } - if(BitRate.toUInt() == 0 && isVidOnly == false) - { - if(configIniRead_videoInfo->value("/format/bit_rate")!=QVariant()) - { - BitRate = configIniRead_videoInfo->value("/format/bit_rate").toString().trimmed(); - if(isReturnFullCMD==true)BitRateCMD = " -b "+BitRate+" "; - } - } - //======================= - if(BitRate.toUInt() == 0) - { - BitRate=""; - } - //======================= - if(isReturnFullCMD==true && BitRate!="" && BitRateCMD!="") - { - video_info_ini.remove(); - return BitRateCMD; - } - else - { - video_info_ini.remove(); - return BitRate; - } -} -/* -获取视频FPS -*/ -QString MainWindow::video_get_fps(QString videoPath) -{ - //========================= 调用ffprobe读取视频信息 ====================== - QProcess *Get_VideoFPS_process = new QProcess(); - QString cmd = "\""+Current_Path+"/ffprobe_waifu2xEX.exe\" -i \""+videoPath+"\" -select_streams v -show_streams -v quiet -print_format ini -show_format"; - Get_VideoFPS_process->start(cmd); - while(!Get_VideoFPS_process->waitForStarted(100)&&!QProcess_stop) {} - while(!Get_VideoFPS_process->waitForFinished(100)&&!QProcess_stop) {} - //============= 保存ffprobe输出的ini格式文本 ============= - QString ffprobe_output_str = Get_VideoFPS_process->readAllStandardOutput(); - //================ 将ini写入文件保存 ================ - QFileInfo videoFileInfo(videoPath); - QString Path_video_info_ini = ""; - QString video_dir = file_getFolderPath(videoPath); - int FileNo = 0; - do - { - FileNo++; - Path_video_info_ini = video_dir+"/"+file_getBaseName(videoPath)+"_videoInfo_"+QString::number(FileNo,10)+"_Waifu2xEX.ini"; - } - while(QFile::exists(Path_video_info_ini)); - //========= - QFile video_info_ini(Path_video_info_ini); - video_info_ini.remove(); - if (video_info_ini.open(QIODevice::ReadWrite | QIODevice::Text)) //QIODevice::ReadWrite支持读写 - { - QTextStream stream(&video_info_ini); - stream << ffprobe_output_str; - } - video_info_ini.close(); - //================== 读取ini获得参数 ===================== - QString FPS_Division = ""; - QSettings *configIniRead_videoInfo = new QSettings(Path_video_info_ini, QSettings::IniFormat); - if(configIniRead_videoInfo->value("/streams.stream.0/avg_frame_rate") != QVariant()) - { - FPS_Division = configIniRead_videoInfo->value("/streams.stream.0/avg_frame_rate").toString().trimmed(); - } - video_info_ini.remove(); - //======================= - if(FPS_Division=="") - { - return "0.0"; - } - //======================= - QStringList FPS_Nums = FPS_Division.split("/"); - if(FPS_Nums.size()!=2) - { - return "0.0"; - } - double FPS_Num_0 = FPS_Nums.at(0).toDouble(); - double FPS_Num_1 = FPS_Nums.at(1).toDouble(); - if(FPS_Num_0<=0||FPS_Num_1<=0) - { - return "0.0"; - } - return FPS_Division; -} - -int MainWindow::video_get_frameNum(QString videoPath) -{ - //========================= 调用ffprobe读取视频信息 ====================== - QProcess *Get_VideoFrameNumDigits_process = new QProcess(); - QString cmd = "\""+Current_Path+"/ffprobe_waifu2xEX.exe\" -i \""+videoPath+"\" -select_streams v -show_streams -v quiet -print_format ini -show_format"; - Get_VideoFrameNumDigits_process->start(cmd); - while(!Get_VideoFrameNumDigits_process->waitForStarted(100)&&!QProcess_stop) {} - while(!Get_VideoFrameNumDigits_process->waitForFinished(100)&&!QProcess_stop) {} - //============= 保存ffprobe输出的ini格式文本 ============= - QString ffprobe_output_str = Get_VideoFrameNumDigits_process->readAllStandardOutput(); - //================ 将ini写入文件保存 ================ - QFileInfo videoFileInfo(videoPath); - QString Path_video_info_ini = ""; - QString video_dir = file_getFolderPath(videoPath); - int FileNo = 0; - do - { - FileNo++; - Path_video_info_ini = video_dir+"/"+file_getBaseName(videoPath)+"_videoInfo_"+QString::number(FileNo,10)+"_Waifu2xEX.ini"; - } - while(QFile::exists(Path_video_info_ini)); - //========= - QFile video_info_ini(Path_video_info_ini); - video_info_ini.remove(); - if (video_info_ini.open(QIODevice::ReadWrite | QIODevice::Text)) //QIODevice::ReadWrite支持读写 - { - QTextStream stream(&video_info_ini); - stream << ffprobe_output_str; - } - video_info_ini.close(); - //================== 读取ini获得参数 ===================== - int FrameNum = 0; - QSettings *configIniRead_videoInfo = new QSettings(Path_video_info_ini, QSettings::IniFormat); - if(configIniRead_videoInfo->value("/streams.stream.0/nb_frames") != QVariant()) - { - FrameNum = configIniRead_videoInfo->value("/streams.stream.0/nb_frames").toInt(); - } - video_info_ini.remove(); - if(FrameNum<1) - { - emit Send_TextBrowser_NewMessage(tr("ERROR! Unable to read the number of frames of the video: [")+videoPath+"]"); - return 0; - } - return FrameNum; -} - -int MainWindow::video_get_frameNumDigits(QString videoPath) -{ - int frameNumDigits=1+(int)log10(video_get_frameNum(videoPath)); - return frameNumDigits; -} - -void MainWindow::video_video2images(QString VideoPath,QString FrameFolderPath,QString AudioPath) -{ - emit Send_TextBrowser_NewMessage(tr("Start splitting video: [")+VideoPath+"]"); - //================= - QString ffmpeg_path = Current_Path+"/ffmpeg_waifu2xEX.exe"; - //================ 获取fps ===================== - QString fps_video_cmd=" "; - QString fps = video_get_fps(VideoPath).trimmed(); - if(fps != "0.0") - { - fps_video_cmd = " -r "+fps+" "; - } - //===================== - int FrameNumDigits = video_get_frameNumDigits(VideoPath); - if(FrameNumDigits==0)return; - QFile::remove(isPreVFIDone_MarkFilePath(VideoPath)); - //===================== - QProcess video_splitFrame; - video_splitFrame.start("\""+ffmpeg_path+"\" -y"+fps_video_cmd+"-i \""+VideoPath+"\" "+fps_video_cmd+" \""+FrameFolderPath.replace("%","%%")+"/%0"+QString::number(FrameNumDigits,10)+"d.png\""); - while(!video_splitFrame.waitForStarted(100)&&!QProcess_stop) {} - while(!video_splitFrame.waitForFinished(100)&&!QProcess_stop) {} - //============== 尝试在Win7下可能兼容的指令 ================================ - if(file_isDirEmpty(FrameFolderPath)) - { - video_splitFrame.start("\""+ffmpeg_path+"\" -y"+fps_video_cmd+"-i \""+VideoPath+"\" "+fps_video_cmd+" \""+FrameFolderPath.replace("%","%%")+"/%%0"+QString::number(FrameNumDigits,10)+"d.png\""); - while(!video_splitFrame.waitForStarted(100)&&!QProcess_stop) {} - while(!video_splitFrame.waitForFinished(100)&&!QProcess_stop) {} - } - video_get_audio(VideoPath,AudioPath);//拆分音频 - //======== 插帧 ========= - QFileInfo vfinfo(VideoPath); - QString video_dir = file_getFolderPath(vfinfo); - QString video_filename = file_getBaseName(VideoPath); - QString VFI_FolderPath_tmp = video_dir+"/"+video_filename+"_PreVFI_W2xEX"; - if(ui->checkBox_VfiAfterScale_VFI->isChecked()==false && ui->groupBox_FrameInterpolation->isChecked()==true && ui->checkBox_FrameInterpolationOnly_Video->isChecked()==false) //如果启用了插帧 - { - //如果检测到完整的已经插帧的帧缓存 - if(file_isDirExist(VFI_FolderPath_tmp) && (file_getFileNames_in_Folder_nofilter(FrameFolderPath).size() * ui->spinBox_MultipleOfFPS_VFI->value() == file_getFileNames_in_Folder_nofilter(VFI_FolderPath_tmp).size())) - { - file_DelDir(FrameFolderPath); - QDir VFI_FolderPath_tmp_qdir(VFI_FolderPath_tmp); - VFI_FolderPath_tmp_qdir.rename(VFI_FolderPath_tmp,FrameFolderPath); - return; - } - else - { - if(FrameInterpolation(FrameFolderPath,VFI_FolderPath_tmp)==true) - { - //如果插帧成功 - file_DelDir(FrameFolderPath); - QDir VFI_FolderPath_tmp_qdir(VFI_FolderPath_tmp); - VFI_FolderPath_tmp_qdir.rename(VFI_FolderPath_tmp,FrameFolderPath); - file_generateMarkFile(isPreVFIDone_MarkFilePath(VideoPath),QString("%1").arg(ui->spinBox_MultipleOfFPS_VFI->value())); - return; - } - else - { - //如果插帧失败且启用了仅插帧模式 - if(ui->checkBox_FrameInterpolationOnly_Video->isChecked()==true) - { - file_DelDir(FrameFolderPath); - file_mkDir(FrameFolderPath); - file_DelDir(VFI_FolderPath_tmp); - if(waifu2x_STOP==false)emit Send_TextBrowser_NewMessage(tr("Failed to interpolate frames of video:[")+VideoPath+"]"); - return; - } - //如果插帧失败但是已经超分辨率 - else - { - file_DelDir(VFI_FolderPath_tmp); - if(waifu2x_STOP==false)emit Send_TextBrowser_NewMessage(tr("Failed to interpolate frames of video:[")+VideoPath+tr("]. Gonna generate a video without frame Interpolation.")); - } - } - } - } - //==================================== - emit Send_TextBrowser_NewMessage(tr("Finish splitting video: [")+VideoPath+"]"); -} - -int MainWindow::video_images2video(QString VideoPath,QString video_mp4_scaled_fullpath,QString ScaledFrameFolderPath,QString AudioPath,bool CustRes_isEnabled,int CustRes_height,int CustRes_width,bool isOverScaled) -{ - bool Del_DenoisedAudio = false; - //================= - QString bitrate_video_cmd=""; - //======= - if(ui->groupBox_video_settings->isChecked()&&(ui->spinBox_bitrate_vid->value()>0)) - { - bitrate_video_cmd=" -b:v "+QString::number(ui->spinBox_bitrate_vid->value(),10)+"k "; - } - else - { - QString BitRate = video_get_bitrate_AccordingToRes_FrameFolder(ScaledFrameFolderPath,VideoPath); - if(BitRate!="")bitrate_video_cmd=" -b:v "+BitRate+"k "; - } - //================ 自定义分辨率 ====================== - QString resize_cmd =""; - if(CustRes_isEnabled || isOverScaled) - { - if(isOverScaled==true && CustRes_isEnabled==false) - { - QMap res_map = video_get_Resolution(VideoPath); - int scaleratio_orginal = ui->doubleSpinBox_ScaleRatio_video->value(); - resize_cmd =" -vf scale="+QString::number(res_map["width"]*scaleratio_orginal,10)+":"+QString::number(res_map["height"]*scaleratio_orginal,10)+" "; - } - //============= 如果没有自定义视频参数, 则根据自定义分辨率再计算一次比特率 ========== - if(ui->groupBox_video_settings->isChecked()==false || (ui->spinBox_bitrate_vid->value()<1)) - { - int small_res =0; - if(CustRes_width<=CustRes_height) - { - small_res = CustRes_width; - } - else - { - small_res = CustRes_height; - } - bitrate_video_cmd=" -b:v "+QString::number(small_res*6,10)+"k "; - } - //================================================================= - if(CustRes_AspectRatioMode==Qt::IgnoreAspectRatio && CustRes_isEnabled==true) - { - resize_cmd =" -vf scale="+QString::number(CustRes_width,10)+":"+QString::number(CustRes_height,10)+" "; - } - if(CustRes_AspectRatioMode==Qt::KeepAspectRatio && CustRes_isEnabled==true) - { - if(CustRes_width>=CustRes_height) - { - resize_cmd =" -vf scale=-2:"+QString::number(CustRes_height,10)+" "; - } - else - { - resize_cmd =" -vf scale="+QString::number(CustRes_width,10)+":-2 "; - } - } - if(CustRes_AspectRatioMode==Qt::KeepAspectRatioByExpanding && CustRes_isEnabled==true) - { - if(CustRes_width>=CustRes_height) - { - resize_cmd =" -vf scale="+QString::number(CustRes_width,10)+":-2 "; - } - else - { - resize_cmd =" -vf scale=-2:"+QString::number(CustRes_height,10)+" "; - } - } - } - QString ffmpeg_path = Current_Path+"/ffmpeg_waifu2xEX.exe"; - int FrameNumDigits = video_get_frameNumDigits(VideoPath); - if(FrameNumDigits==0)return 0; - QFileInfo vfinfo(VideoPath); - QString video_dir = file_getFolderPath(vfinfo); - QString video_filename = file_getBaseName(VideoPath); - QString video_ext = vfinfo.suffix(); - //=========== 获取fps =========== - QString fps = video_get_fps(VideoPath).trimmed(); - if(fps == "0.0") - { - emit Send_TextBrowser_NewMessage(tr("Error occured when processing [")+VideoPath+tr("]. Error: [Unable to get video frame rate.]")); - return 0; - } - //=============== 补帧 =============== - QString VFI_FolderPath_tmp = video_dir+"/"+video_filename+"_PostVFI_W2xEX"; - //如果启用了插帧 - if(ui->groupBox_FrameInterpolation->isChecked()==true) - { - bool isPreVFIDone = QFile::exists(isPreVFIDone_MarkFilePath(VideoPath)); - if((ui->checkBox_VfiAfterScale_VFI->isChecked()==false && ui->checkBox_FrameInterpolationOnly_Video->isChecked()==false) || isPreVFIDone==true) - { - if(isPreVFIDone==true) - { - FrameNumDigits = CalNumDigits((file_getFileNames_in_Folder_nofilter(ScaledFrameFolderPath).size())); - //========== - int Old_MultipleOfFPS = ui->spinBox_MultipleOfFPS_VFI->value(); - QFile f(isPreVFIDone_MarkFilePath(VideoPath)); - if(f.open(QIODevice::ReadOnly | QIODevice::Text)) - { - QTextStream txtInput(&f); - QString lineStr; - lineStr = txtInput.readAll(); - int tmp_mof = lineStr.trimmed().toInt(); - if(tmp_mof>1) - { - Old_MultipleOfFPS = tmp_mof; - } - } - //========== - QStringList FPS_Nums = fps.split("/"); - fps = QString("%1/%2").arg(FPS_Nums.at(0).toDouble() * Old_MultipleOfFPS).arg(FPS_Nums.at(1).toDouble()); - } - } - else - { - //如果检测到完整的已经插帧的帧缓存 - if(file_isDirExist(VFI_FolderPath_tmp) && (file_getFileNames_in_Folder_nofilter(ScaledFrameFolderPath).size() * ui->spinBox_MultipleOfFPS_VFI->value() == file_getFileNames_in_Folder_nofilter(VFI_FolderPath_tmp).size())) - { - FrameNumDigits = CalNumDigits((file_getFileNames_in_Folder_nofilter(VFI_FolderPath_tmp).size())); - ScaledFrameFolderPath = VFI_FolderPath_tmp; - QStringList FPS_Nums = fps.split("/"); - fps = QString("%1/%2").arg(FPS_Nums.at(0).toDouble() * ui->spinBox_MultipleOfFPS_VFI->value()).arg(FPS_Nums.at(1).toDouble()); - } - else - { - //如果插帧成功 - if(FrameInterpolation(ScaledFrameFolderPath,VFI_FolderPath_tmp)==true) - { - FrameNumDigits = CalNumDigits((file_getFileNames_in_Folder_nofilter(VFI_FolderPath_tmp).size())); - ScaledFrameFolderPath = VFI_FolderPath_tmp; - QStringList FPS_Nums = fps.split("/"); - fps = QString("%1/%2").arg(FPS_Nums.at(0).toDouble() * ui->spinBox_MultipleOfFPS_VFI->value()).arg(FPS_Nums.at(1).toDouble()); - } - else - { - //如果插帧失败且启用了分段处理或仅插帧模式 - if(ui->checkBox_ProcessVideoBySegment->isChecked()==true || ui->checkBox_FrameInterpolationOnly_Video->isChecked()==true) - { - file_DelDir(VFI_FolderPath_tmp); - if(waifu2x_STOP==false)emit Send_TextBrowser_NewMessage(tr("Failed to interpolate frames of video:[")+VideoPath+"]"); - return 0; - } - //如果插帧失败但是已经超分辨率且没分段 - else - { - file_DelDir(VFI_FolderPath_tmp); - if(waifu2x_STOP==false)emit Send_TextBrowser_NewMessage(tr("Failed to interpolate frames of video:[")+VideoPath+tr("]. Gonna generate a video without frame Interpolation.")); - } - } - } - } - } - //=============== 音频降噪 ======================== - if((ui->checkBox_AudioDenoise->isChecked())&&QFile::exists(AudioPath)) - { - QString AudioPath_tmp = video_AudioDenoise(AudioPath); - if(AudioPath_tmp!=AudioPath) - { - AudioPath = AudioPath_tmp; - Del_DenoisedAudio = true; - } - } - //================= 开始处理 ============================= - emit Send_TextBrowser_NewMessage(tr("Start assembling video:[")+VideoPath+"]"); - //====== - QString CMD = ""; - if(QFile::exists(AudioPath)) - { - CMD = "\""+ffmpeg_path+"\" -y -f image2 -framerate "+fps+" -r "+fps+" -i \""+ScaledFrameFolderPath.replace("%","%%")+"/%0"+QString::number(FrameNumDigits,10)+"d.png\" -i \""+AudioPath+"\" -r "+fps+bitrate_video_cmd+resize_cmd+video_ReadSettings_OutputVid(AudioPath)+" -r "+fps+" \""+video_mp4_scaled_fullpath+"\""; - } - else - { - CMD = "\""+ffmpeg_path+"\" -y -f image2 -framerate "+fps+" -r "+fps+" -i \""+ScaledFrameFolderPath.replace("%","%%")+"/%0"+QString::number(FrameNumDigits,10)+"d.png\" -r "+fps+bitrate_video_cmd+resize_cmd+video_ReadSettings_OutputVid(AudioPath)+" -r "+fps+" \""+video_mp4_scaled_fullpath+"\""; - } - QProcess images2video; - QFile::remove(video_mp4_scaled_fullpath);//删除旧文件 - images2video.start(CMD); - while(!images2video.waitForStarted(100)&&!QProcess_stop) {} - while(!images2video.waitForFinished(100)&&!QProcess_stop) - { - if(waifu2x_STOP) - { - images2video.close(); - QFile::remove(video_mp4_scaled_fullpath); - file_DelDir(VFI_FolderPath_tmp); - if(Del_DenoisedAudio)QFile::remove(AudioPath); - return 0; - } - } - //============== 尝试在Win7下可能兼容的指令 ================================ - if(QFile::exists(video_mp4_scaled_fullpath)==false) - { - if(QFile::exists(AudioPath)) - { - CMD = "\""+ffmpeg_path+"\" -y -f image2 -framerate "+fps+" -r "+fps+" -i \""+ScaledFrameFolderPath.replace("%","%%")+"/%%0"+QString::number(FrameNumDigits,10)+"d.png\" -i \""+AudioPath+"\" -r "+fps+bitrate_video_cmd+resize_cmd+video_ReadSettings_OutputVid(AudioPath)+" -r "+fps+" \""+video_mp4_scaled_fullpath+"\""; - } - else - { - CMD = "\""+ffmpeg_path+"\" -y -f image2 -framerate "+fps+" -r "+fps+" -i \""+ScaledFrameFolderPath.replace("%","%%")+"/%%0"+QString::number(FrameNumDigits,10)+"d.png\" -r "+fps+bitrate_video_cmd+resize_cmd+video_ReadSettings_OutputVid(AudioPath)+" -r "+fps+" \""+video_mp4_scaled_fullpath+"\""; - } - QProcess images2video; - images2video.start(CMD); - while(!images2video.waitForStarted(100)&&!QProcess_stop) {} - while(!images2video.waitForFinished(100)&&!QProcess_stop) - { - if(waifu2x_STOP) - { - images2video.close(); - QFile::remove(video_mp4_scaled_fullpath); - file_DelDir(VFI_FolderPath_tmp); - if(Del_DenoisedAudio)QFile::remove(AudioPath); - return 0; - } - } - } - //=================== - if(Del_DenoisedAudio)QFile::remove(AudioPath); - if(ui->checkBox_KeepVideoCache->isChecked() == false || ui->checkBox_ProcessVideoBySegment->isChecked())file_DelDir(VFI_FolderPath_tmp); - if(ui->checkBox_KeepVideoCache->isChecked() == false)QFile::remove(isPreVFIDone_MarkFilePath(VideoPath)); - //============================== - emit Send_TextBrowser_NewMessage(tr("Finish assembling video:[")+VideoPath+"]"); - return 0; -} - -QString MainWindow::video_ReadSettings_OutputVid(QString AudioPath) -{ - QString OutputVideoSettings= " "; - //==== - if(ui->groupBox_video_settings->isChecked()) - { - if(ui->lineEdit_encoder_vid->text().trimmed()!="") - { - OutputVideoSettings.append("-c:v "+ui->lineEdit_encoder_vid->text().trimmed()+" ");//图像编码器 - } - //======== - if(QFile::exists(AudioPath)) - { - if(ui->lineEdit_encoder_audio->text().trimmed()!="") - { - OutputVideoSettings.append("-c:a "+ui->lineEdit_encoder_audio->text().trimmed()+" ");//音频编码器 - } - //========= - if(ui->spinBox_bitrate_audio->value()>0) - { - OutputVideoSettings.append("-b:a "+QString::number(ui->spinBox_bitrate_audio->value(),10)+"k ");//音频比特率 - } - } - //========= - if(ui->lineEdit_pixformat->text().trimmed()!="") - { - OutputVideoSettings.append("-pix_fmt "+ui->lineEdit_pixformat->text().trimmed()+" ");//pixel format - } - else - { - OutputVideoSettings.append("-pix_fmt yuv420p ");//pixel format - } - //=========== - if(ui->lineEdit_ExCommand_output->text().trimmed()!="") - { - OutputVideoSettings.append(ui->lineEdit_ExCommand_output->text().trimmed()+" ");//附加指令 - } - } - //========= - else - { - OutputVideoSettings.append("-pix_fmt yuv420p ");//pixel format - } - //======= - return OutputVideoSettings; -} - -void MainWindow::DelVfiDir(QString VideoPath) -{ - QFileInfo vfinfo(VideoPath); - QString video_dir = file_getFolderPath(vfinfo); - QString video_filename = file_getBaseName(VideoPath); - file_DelDir(video_dir+"/"+video_filename+"_PreVFI_W2xEX"); - file_DelDir(video_dir+"/"+video_filename+"_PostVFI_W2xEX"); -} +/* + Copyright (C) 2021 Aaron Feng + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU Affero General Public License as published + by the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program. If not, see . + + My Github homepage: https://github.com/AaronFeng753 +*/ +#include "mainwindow.h" +#include "ui_mainwindow.h" +/* +根据行数从自定义分辨率列表移除视频文件 +*/ +void MainWindow::video_RemoveFromCustResList(int RowNumber) +{ + QString SourceFile_fullPath = Table_model_video->item(RowNumber,2)->text(); + CustRes_remove(SourceFile_fullPath); +} + +/* +当视频没有自定义分辨率且此时放大倍率为double,则计算一个添加到自定义列表里 +*/ +bool MainWindow::video_DoubleScaleRatioPrep(int RowNumber) +{ + QString SourceFile_fullPath = Table_model_video->item(RowNumber,2)->text(); + if(CustRes_isContained(SourceFile_fullPath) == true || ui->checkBox_FrameInterpolationOnly_Video->isChecked()) + { + //如果已经被定义自定义分辨率,或者仅进行插帧 + return false; + } + //===================== 获取分辨率 ============================= + QMap Map_OrgRes = video_get_Resolution(SourceFile_fullPath); + //========= 计算新的高度宽度 ================== + double ScaleRatio_double = ui->doubleSpinBox_ScaleRatio_video->value(); + int Height_new = qRound(ScaleRatio_double * Map_OrgRes["height"]); + int width_new = qRound(ScaleRatio_double * Map_OrgRes["width"]); + if(Height_new<1 || width_new<1) + { + emit Send_TextBrowser_NewMessage("Warning! Unable to read the resolution of ["+SourceFile_fullPath+"]. This file will only be scaled to "+QString::number((int)ScaleRatio_double,10)+"X."); + return false; + } + if(Height_new%2!=0)Height_new++; + if(width_new%2!=0)width_new++; + //======== 存入自定义分辨率列表中 ============ + QMap res_map; + res_map["fullpath"] = SourceFile_fullPath; + res_map["height"] = QString::number(Height_new,10); + res_map["width"] = QString::number(width_new,10); + Custom_resolution_list.append(res_map); + //========= + return true; +} +/* +计算数字的位数 +*/ +int MainWindow::CalNumDigits(int input_num) +{ + int frameNumDigits=1+(int)log10(input_num); + return frameNumDigits; +} + +/* +判断视频是否是可变帧率的 +*/ +bool MainWindow::video_isVFR(QString videoPath) +{ + //========================= 调用ffprobe读取视频信息 ====================== + QProcess *Get_VideoFPS_process = new QProcess(); + QString cmd = "\""+Current_Path+"/ffprobe_waifu2xEX.exe\" -i \""+videoPath+"\" -select_streams v -show_streams -v quiet -print_format ini -show_format"; + Get_VideoFPS_process->start(cmd); + while(!Get_VideoFPS_process->waitForStarted(100)&&!QProcess_stop) {} + while(!Get_VideoFPS_process->waitForFinished(100)&&!QProcess_stop) {} + //============= 保存ffprobe输出的ini格式文本 ============= + QString ffprobe_output_str = Get_VideoFPS_process->readAllStandardOutput(); + //================ 将ini写入文件保存 ================ + QFileInfo videoFileInfo(videoPath); + QString Path_video_info_ini = ""; + QString video_dir = file_getFolderPath(videoPath); + int FileNo = 0; + do + { + FileNo++; + Path_video_info_ini = video_dir+"/"+file_getBaseName(videoPath)+"_videoInfo_"+QString::number(FileNo,10)+"_Waifu2xEX.ini"; + } + while(QFile::exists(Path_video_info_ini)); + //========= + QFile video_info_ini(Path_video_info_ini); + video_info_ini.remove(); + if (video_info_ini.open(QIODevice::ReadWrite | QIODevice::Text)) //QIODevice::ReadWrite支持读写 + { + QTextStream stream(&video_info_ini); + stream << ffprobe_output_str; + } + video_info_ini.close(); + //================== 读取ini获得参数 ===================== + QString avg_frame_rate = ""; + QString r_frame_rate = ""; + QSettings *configIniRead_videoInfo = new QSettings(Path_video_info_ini, QSettings::IniFormat); + if(configIniRead_videoInfo->value("/streams.stream.0/avg_frame_rate") != QVariant() && configIniRead_videoInfo->value("/streams.stream.0/r_frame_rate") != QVariant()) + { + avg_frame_rate = configIniRead_videoInfo->value("/streams.stream.0/avg_frame_rate").toString().trimmed(); + r_frame_rate = configIniRead_videoInfo->value("/streams.stream.0/r_frame_rate").toString().trimmed(); + } + video_info_ini.remove(); + //===== + if(avg_frame_rate!=""&&r_frame_rate!="") + { + return (avg_frame_rate!=r_frame_rate); + } + else + { + return true; + } +} +/* +根据分辨率判断是否跳过 +true = 跳过 +*/ +bool MainWindow::Video_AutoSkip_CustRes(int rowNum) +{ + if(ui->checkBox_AutoSkip_CustomRes->isChecked()==false || ui->checkBox_FrameInterpolationOnly_Video->isChecked()==true)return false; + QString SourceFile_fullPath = Table_model_video->item(rowNum,2)->text(); + if(CustRes_isContained(SourceFile_fullPath)) + { + QMap Res_map = CustRes_getResMap(SourceFile_fullPath);//res_map["fullpath"],["height"],["width"] + int CustRes_height=Res_map["height"].toInt(); + int CustRes_width=Res_map["width"].toInt(); + //========================= + QMap res_map = video_get_Resolution(SourceFile_fullPath); + int original_height = res_map["height"]; + int original_width = res_map["width"]; + if(original_height<=0||original_width<=0)//判断是否读取失败 + { + return false; + } + //========================== + if((CustRes_height*CustRes_width) <= (original_height*original_width)) + { + return true; + } + else + { + return false; + } + } + else + { + return false; + } +} + +/* +直接获取视频的分辨率 +*/ +QMap MainWindow::video_get_Resolution(QString VideoFileFullPath) +{ + emit Send_TextBrowser_NewMessage(tr("Get resolution of the video:[")+VideoFileFullPath+"]"); + //========================= 调用ffprobe读取视频信息 ====================== + QProcess *Get_resolution_process = new QProcess(); + QString cmd = "\""+Current_Path+"/ffprobe_waifu2xEX.exe\" -i \""+VideoFileFullPath+"\" -select_streams v -show_streams -v quiet -print_format ini -show_format"; + Get_resolution_process->start(cmd); + while(!Get_resolution_process->waitForStarted(100)&&!QProcess_stop) {} + while(!Get_resolution_process->waitForFinished(100)&&!QProcess_stop) {} + //============= 保存ffprobe输出的ini格式文本 ============= + QString ffprobe_output_str = Get_resolution_process->readAllStandardOutput(); + //================ 将ini写入文件保存 ================ + QFileInfo videoFileInfo(VideoFileFullPath); + QString Path_video_info_ini = ""; + QString video_dir = file_getFolderPath(VideoFileFullPath); + int FileNo = 0; + do + { + FileNo++; + Path_video_info_ini = video_dir+"/"+file_getBaseName(VideoFileFullPath)+"_videoInfo_"+QString::number(FileNo,10)+"_Waifu2xEX.ini"; + } + while(QFile::exists(Path_video_info_ini)); + //========= + QFile video_info_ini(Path_video_info_ini); + video_info_ini.remove(); + if (video_info_ini.open(QIODevice::ReadWrite | QIODevice::Text)) //QIODevice::ReadWrite支持读写 + { + QTextStream stream(&video_info_ini); + stream << ffprobe_output_str; + } + video_info_ini.close(); + //================== 读取ini获得参数 ===================== + QSettings *configIniRead_videoInfo = new QSettings(Path_video_info_ini, QSettings::IniFormat); + QString width_str = ""; + QString height_str = ""; + if(configIniRead_videoInfo->value("/streams.stream.0/width") != QVariant() && configIniRead_videoInfo->value("/streams.stream.0/height") != QVariant()) + { + width_str = configIniRead_videoInfo->value("/streams.stream.0/width").toString().trimmed(); + height_str = configIniRead_videoInfo->value("/streams.stream.0/height").toString().trimmed(); + } + video_info_ini.remove(); + //======================= + if(width_str!="" && height_str!="") + { + int width_int = width_str.toInt(); + int height_int = height_str.toInt(); + if(width_int>0 && height_int>0) + { + QMap res_map; + res_map["height"] = height_int; + res_map["width"] = width_int; + return res_map; + } + } + emit Send_TextBrowser_NewMessage(tr("ERROR! Unable to read the resolution of the video. [")+VideoFileFullPath+"]"); + QMap empty; + empty["height"] = 0; + empty["width"] = 0; + return empty; +} + +/* +根据视频时长,判断是否需要分段处理 +*/ +bool MainWindow::video_isNeedProcessBySegment(int rowNum) +{ + if(ui->checkBox_ProcessVideoBySegment->isChecked()==false)return false;//如果没启用分段处理,直接返回false + QString VideoFile = Table_model_video->item(rowNum,2)->text(); + if(video_get_duration(VideoFile)>ui->spinBox_SegmentDuration->value()) + { + return true; + } + else + { + emit Send_TextBrowser_NewMessage(tr("This video is too short, so segment processing is automatically disabled.[")+VideoFile+"]"); + return false; + } +} + +/* +生成视频片段文件夹编号 +*/ +QString MainWindow::video_getClipsFolderNo() +{ + QString current_date =QDateTime::currentDateTime().toString("yyMMddhhmmss"); + return current_date; +} +/* +组装视频(从mp4片段组装) +*/ +void MainWindow::video_AssembleVideoClips(QString VideoClipsFolderPath,QString VideoClipsFolderName,QString video_mp4_scaled_fullpath,QString AudioPath) +{ + emit Send_TextBrowser_NewMessage(tr("Start assembling video with clips:[")+video_mp4_scaled_fullpath+"]"); + //================= + QStringList VideoClips_Scan_list = file_getFileNames_in_Folder_nofilter(VideoClipsFolderPath); + QStringList VideoClips_fileName_list; + VideoClips_fileName_list.clear(); + QFileInfo vfinfo(video_mp4_scaled_fullpath); + QString video_dir = file_getFolderPath(video_mp4_scaled_fullpath); + /* + 生成视频片段文件完整路径QStringList + */ + for (int VideoNameNo = 0; VideoNameNocheckBox_AudioDenoise->isChecked())&&QFile::exists(AudioPath)) + { + QString AudioPath_tmp = video_AudioDenoise(AudioPath); + if(AudioPath_tmp!=AudioPath) + { + AudioPath = AudioPath_tmp; + Del_DenoisedAudio = true; + } + } + //================= 获取比特率 ================= + QString bitrate_video_cmd=""; + if(ui->spinBox_bitrate_vid->value()>0 && ui->groupBox_video_settings->isChecked()) + { + bitrate_video_cmd = " -b:v "+QString::number(ui->spinBox_bitrate_vid->value(),10)+"k "; + } + else + { + QString BitRate_str = video_get_bitrate(Mp4Clip_forReadInfo,false,true); + if(BitRate_str!="") + { + bitrate_video_cmd = " -b:v "+BitRate_str+" "; + } + else + { + int BitRate = video_UseRes2CalculateBitrate(Mp4Clip_forReadInfo); + if(BitRate!=0)bitrate_video_cmd = " -b:v "+QString::number(BitRate,10)+"k "; + } + } + //================= 读取视频编码器设定 ============== + QString encoder_video_cmd=""; + if(ui->groupBox_video_settings->isChecked() && ui->lineEdit_encoder_vid->text().trimmed()!="") + { + encoder_video_cmd = " -c:v "+ui->lineEdit_encoder_vid->text().trimmed()+" ";//图像编码器 + } + //=============== 读取音频编码设定 ==================== + QString encoder_audio_cmd=""; + QString bitrate_audio_cmd=""; + if(ui->groupBox_video_settings->isChecked()) + { + if(ui->lineEdit_encoder_audio->text().trimmed()!="") + encoder_audio_cmd=" -c:a "+ui->lineEdit_encoder_audio->text().trimmed()+" "; + if(ui->spinBox_bitrate_audio->value()>0) + bitrate_audio_cmd=" -b:a "+QString::number(ui->spinBox_bitrate_audio->value(),10)+"k "; + } + //================== + QString Extra_command = ""; + if(ui->groupBox_video_settings->isChecked() && ui->lineEdit_ExCommand_output->text().trimmed()!="") + { + Extra_command = " "+ui->lineEdit_ExCommand_output->text().trimmed()+" ";//附加指令 + } + //================ 获取fps ===================== + QString fps_video_cmd=" "; + QString fps = video_get_fps(Mp4Clip_forReadInfo).trimmed(); + if(fps != "0.0") + { + fps_video_cmd = " -r "+fps+" "; + } + //================= 开始处理 ============================= + QString CMD = ""; + if(QFile::exists(AudioPath)) + { + CMD = "\""+ffmpeg_path+"\" -y -f concat -safe 0 "+fps_video_cmd+" -i \""+Path_FFMpegFileList+"\" "+fps_video_cmd+" -i \""+AudioPath+"\" "+fps_video_cmd+" "+bitrate_video_cmd+encoder_video_cmd+fps_video_cmd+encoder_audio_cmd+bitrate_audio_cmd+Extra_command+"\""+video_mp4_scaled_fullpath+"\""; + } + else + { + CMD = "\""+ffmpeg_path+"\" -y -f concat -safe 0 "+fps_video_cmd+" -i \""+Path_FFMpegFileList+"\""+bitrate_video_cmd+encoder_video_cmd+fps_video_cmd+Extra_command+"\""+video_mp4_scaled_fullpath+"\""; + } + QProcess AssembleVideo; + AssembleVideo.start(CMD); + while(!AssembleVideo.waitForStarted(100)&&!QProcess_stop) {} + while(!AssembleVideo.waitForFinished(100)&&!QProcess_stop) + { + if(waifu2x_STOP) + { + AssembleVideo.close(); + QFile::remove(video_mp4_scaled_fullpath); + QFile::remove(Path_FFMpegFileList); + return; + } + } + //检查是否发生错误 + if(QFile::exists(video_mp4_scaled_fullpath)==false)//检查是否成功生成视频 + { + MultiLine_ErrorOutput_QMutex.lock(); + emit Send_TextBrowser_NewMessage(tr("Error output for FFmpeg when processing:[")+video_mp4_scaled_fullpath+"]"); + emit Send_TextBrowser_NewMessage("\n--------------------------------------"); + //标准输出 + emit Send_TextBrowser_NewMessage(AssembleVideo.readAllStandardOutput()); + //错误输出 + emit Send_TextBrowser_NewMessage(AssembleVideo.readAllStandardError()); + emit Send_TextBrowser_NewMessage("\n--------------------------------------"); + MultiLine_ErrorOutput_QMutex.unlock(); + } + QFile::remove(Path_FFMpegFileList);//删除文件列表 + //=================== + if(Del_DenoisedAudio)QFile::remove(AudioPath); + //============================== + emit Send_TextBrowser_NewMessage(tr("Finish assembling video with clips:[")+video_mp4_scaled_fullpath+"]"); +} +/* +将视频拆分到帧(分段的) +*/ +void MainWindow::video_video2images_ProcessBySegment(QString VideoPath,QString FrameFolderPath,int StartTime,int SegmentDuration) +{ + emit Send_TextBrowser_NewMessage(tr("Start splitting video: [")+VideoPath+"]"); + //================= + QString ffmpeg_path = Current_Path+"/ffmpeg_waifu2xEX.exe"; + QString video_mp4_fullpath = VideoPath; + //================ 获取fps ===================== + QString fps_video_cmd=" "; + QString fps = video_get_fps(video_mp4_fullpath).trimmed(); + if(fps != "0.0") + { + fps_video_cmd = " -r "+fps+" "; + } + //===================== + int FrameNumDigits = video_get_frameNumDigits(video_mp4_fullpath); + if(FrameNumDigits==0)return; + QFile::remove(isPreVFIDone_MarkFilePath(VideoPath)); + //===================== + QProcess video_splitFrame; + video_splitFrame.start("\""+ffmpeg_path+"\" -y"+fps_video_cmd+"-i \""+video_mp4_fullpath+"\" -ss "+QString::number(StartTime,10)+" -t "+QString::number(SegmentDuration,10)+fps_video_cmd+" \""+FrameFolderPath.replace("%","%%")+"/%0"+QString::number(FrameNumDigits,10)+"d.png\""); + while(!video_splitFrame.waitForStarted(100)&&!QProcess_stop) {} + while(!video_splitFrame.waitForFinished(100)&&!QProcess_stop) {} + //============== 尝试在Win7下可能兼容的指令 ================================ + if(file_isDirEmpty(FrameFolderPath)) + { + video_splitFrame.start("\""+ffmpeg_path+"\" -y"+fps_video_cmd+"-i \""+video_mp4_fullpath+"\" -ss "+QString::number(StartTime,10)+" -t "+QString::number(SegmentDuration,10)+fps_video_cmd+" \""+FrameFolderPath.replace("%","%%")+"/%%0"+QString::number(FrameNumDigits,10)+"d.png\""); + while(!video_splitFrame.waitForStarted(100)&&!QProcess_stop) {} + while(!video_splitFrame.waitForFinished(100)&&!QProcess_stop) {} + } + //======== 插帧 ========= + QFileInfo vfinfo(VideoPath); + QString video_dir = file_getFolderPath(vfinfo); + QString video_filename = file_getBaseName(VideoPath); + QString VFI_FolderPath_tmp = video_dir+"/"+video_filename+"_PreVFI_W2xEX"; + if(ui->checkBox_VfiAfterScale_VFI->isChecked()==false && ui->groupBox_FrameInterpolation->isChecked()==true && ui->checkBox_FrameInterpolationOnly_Video->isChecked()==false) //如果启用了插帧 + { + //如果检测到完整的已经插帧的帧缓存 + if(file_isDirExist(VFI_FolderPath_tmp) && (file_getFileNames_in_Folder_nofilter(FrameFolderPath).size() * ui->spinBox_MultipleOfFPS_VFI->value() == file_getFileNames_in_Folder_nofilter(VFI_FolderPath_tmp).size())) + { + file_DelDir(FrameFolderPath); + QDir VFI_FolderPath_tmp_qdir(VFI_FolderPath_tmp); + VFI_FolderPath_tmp_qdir.rename(VFI_FolderPath_tmp,FrameFolderPath); + return; + } + else + { + if(FrameInterpolation(FrameFolderPath,VFI_FolderPath_tmp)==true) + { + //如果插帧成功 + file_DelDir(FrameFolderPath); + QDir VFI_FolderPath_tmp_qdir(VFI_FolderPath_tmp); + VFI_FolderPath_tmp_qdir.rename(VFI_FolderPath_tmp,FrameFolderPath); + file_generateMarkFile(isPreVFIDone_MarkFilePath(VideoPath),QString("%1").arg(ui->spinBox_MultipleOfFPS_VFI->value())); + return; + } + else + { + file_DelDir(FrameFolderPath); + file_mkDir(FrameFolderPath); + file_DelDir(VFI_FolderPath_tmp); + if(waifu2x_STOP==false)emit Send_TextBrowser_NewMessage(tr("Failed to interpolate frames of video:[")+VideoPath+"]"); + return; + } + } + } + //==================================== + emit Send_TextBrowser_NewMessage(tr("Finish splitting video: [")+VideoPath+"]"); +} + +/* +提取视频的音频 +*/ +void MainWindow::video_get_audio(QString VideoPath,QString AudioPath) +{ + emit Send_TextBrowser_NewMessage(tr("Extract audio from video: [")+VideoPath+"]"); + //============================================== + QString ffmpeg_path = Current_Path+"/ffmpeg_waifu2xEX.exe"; + QFile::remove(AudioPath); + QProcess video_splitSound; + video_splitSound.start("\""+ffmpeg_path+"\" -y -i \""+VideoPath+"\" \""+AudioPath+"\""); + while(!video_splitSound.waitForStarted(100)&&!QProcess_stop) {} + while(!video_splitSound.waitForFinished(100)&&!QProcess_stop) {} + if(QFile::exists(AudioPath)) + { + emit Send_TextBrowser_NewMessage(tr("Successfully extracted audio from video: [")+VideoPath+"]"); + } + else + { + emit Send_TextBrowser_NewMessage(tr("Failed to extract audio from video: [")+VideoPath+tr("] This video might be a silent video, so will continue to process this video.")); + } +} +/* +将视频转换为mp4 +*/ +QString MainWindow::video_To_CFRMp4(QString VideoPath) +{ + QFileInfo vfinfo(VideoPath); + QString video_ext = vfinfo.suffix(); + bool isVFR = false; + //============== + if(video_ext.toLower()=="mp4") + { + if(video_isVFR(VideoPath)==false) + { + return VideoPath; + } + else + { + isVFR = true; + } + } + QString video_dir = file_getFolderPath(vfinfo); + QString video_filename = file_getBaseName(VideoPath); + QString video_mp4_fullpath = video_dir+"/"+video_filename+"_"+video_ext+"_CfrMp4.mp4"; + if(QFile::exists(video_mp4_fullpath))return video_mp4_fullpath; + QFile::remove(video_mp4_fullpath); + //================= + emit Send_TextBrowser_NewMessage(tr("Start converting video: [")+VideoPath+tr("] to CFR MP4.")); + QString ffmpeg_path = Current_Path+"/ffmpeg_waifu2xEX.exe"; + QString vcodec_copy_cmd = ""; + QString acodec_copy_cmd = ""; + QString bitrate_vid_cmd = ""; + QString bitrate_audio_cmd = ""; + QString Extra_command = ""; + QString bitrate_FromOG = ""; + QString vsync_1 = " -vsync 1 "; + if(ui->groupBox_video_settings->isChecked()) + { + if(ui->checkBox_IgnoreFrameRateMode->isChecked()==true) + { + vsync_1 = ""; + isVFR = false; + } + Extra_command = ui->lineEdit_ExCommand_2mp4->text().trimmed(); + if(ui->checkBox_vcodec_copy_2mp4->isChecked()&&isVFR==false) + { + vcodec_copy_cmd = " -vcodec copy "; + } + else + { + if(ui->spinBox_bitrate_vid_2mp4->value()>0&&ui->spinBox_bitrate_audio_2mp4->value()>0)bitrate_vid_cmd = " -b:v "+QString::number(ui->spinBox_bitrate_vid_2mp4->value(),10)+"k "; + } + if(ui->checkBox_acodec_copy_2mp4->isChecked()&&isVFR==false) + { + acodec_copy_cmd = " -acodec copy "; + } + else + { + if(ui->spinBox_bitrate_vid_2mp4->value()>0&&ui->spinBox_bitrate_audio_2mp4->value()>0)bitrate_audio_cmd = " -b:a "+QString::number(ui->spinBox_bitrate_audio_2mp4->value(),10)+"k "; + } + } + if((ui->groupBox_video_settings->isChecked()==false)||(ui->spinBox_bitrate_vid_2mp4->value()<=0||ui->spinBox_bitrate_audio_2mp4->value()<=0)) + { + QString BitRate = video_get_bitrate(VideoPath,true,false); + if(BitRate!="") + { + bitrate_FromOG = BitRate; + } + else + { + emit Send_TextBrowser_NewMessage(tr("Warning! Unable to get the bitrate of the [")+VideoPath+tr("]. The bit rate automatically allocated by ffmpeg will be used.")); + } + } + //===== + QProcess video_tomp4; + video_tomp4.start("\""+ffmpeg_path+"\" -y -i \""+VideoPath+"\""+vsync_1+vcodec_copy_cmd+acodec_copy_cmd+bitrate_vid_cmd+bitrate_audio_cmd+bitrate_FromOG+" "+Extra_command+" \""+video_mp4_fullpath+"\""); + while(!video_tomp4.waitForStarted(100)&&!QProcess_stop) {} + while(!video_tomp4.waitForFinished(100)&&!QProcess_stop) {} + //====== + if(QFile::exists(video_mp4_fullpath)) + { + emit Send_TextBrowser_NewMessage(tr("Successfully converted video: [")+VideoPath+tr("] to CFR MP4.")); + return video_mp4_fullpath; + } + return "null"; +} +//=============== +//获取时长(秒) +//=============== +int MainWindow::video_get_duration(QString videoPath) +{ + emit Send_TextBrowser_NewMessage(tr("Get duration of the video:[")+videoPath+"]"); + //========================= 调用ffprobe读取视频信息 ====================== + QProcess *Get_Duration_process = new QProcess(); + QString cmd = "\""+Current_Path+"/ffprobe_waifu2xEX.exe\" -i \""+videoPath+"\" -select_streams v -show_streams -v quiet -print_format ini -show_format"; + Get_Duration_process->start(cmd); + while(!Get_Duration_process->waitForStarted(100)&&!QProcess_stop) {} + while(!Get_Duration_process->waitForFinished(100)&&!QProcess_stop) {} + //============= 保存ffprobe输出的ini格式文本 ============= + QString ffprobe_output_str = Get_Duration_process->readAllStandardOutput(); + //================ 将ini写入文件保存 ================ + QFileInfo videoFileInfo(videoPath); + QString Path_video_info_ini = ""; + QString video_dir = file_getFolderPath(videoPath); + int FileNo = 0; + do + { + FileNo++; + Path_video_info_ini = video_dir+"/"+file_getBaseName(videoPath)+"_videoInfo_"+QString::number(FileNo,10)+"_Waifu2xEX.ini"; + } + while(QFile::exists(Path_video_info_ini)); + //========= + QFile video_info_ini(Path_video_info_ini); + video_info_ini.remove(); + if (video_info_ini.open(QIODevice::ReadWrite | QIODevice::Text)) //QIODevice::ReadWrite支持读写 + { + QTextStream stream(&video_info_ini); + stream << ffprobe_output_str; + } + video_info_ini.close(); + //================== 读取ini获得参数 ===================== + QString Duration = ""; + QSettings *configIniRead_videoInfo = new QSettings(Path_video_info_ini, QSettings::IniFormat); + if(configIniRead_videoInfo->value("/format/duration") != QVariant()) + { + Duration = configIniRead_videoInfo->value("/format/duration").toString().trimmed(); + } + video_info_ini.remove(); + //======================= + if(Duration=="") + { + emit Send_TextBrowser_NewMessage(tr("ERROR! Unable to get the duration of the [")+videoPath+tr("].")); + return 0; + } + //======================= + double Duration_double = Duration.toDouble(); + int Duration_int = (int)Duration_double; + //===================== + return Duration_int; +} +/* +音频降噪 +*/ +QString MainWindow::video_AudioDenoise(QString OriginalAudioPath) +{ + emit Send_TextBrowser_NewMessage(tr("Starting to denoise audio.[")+OriginalAudioPath+"]"); + //=========== + QFileInfo fileinfo(OriginalAudioPath); + QString file_name = file_getBaseName(OriginalAudioPath); + QString file_ext = fileinfo.suffix(); + QString file_path = file_getFolderPath(fileinfo); + //================ + QString program = Current_Path+"/SoX/sox_waifu2xEX.exe"; + QString DenoiseProfile = file_path+"/"+file_name+"_DenoiseProfile.dp"; + QString DenoisedAudio = file_path+"/"+file_name+"_Denoised."+file_ext; + double DenoiseLevel = ui->doubleSpinBox_AudioDenoiseLevel->value(); + //================ + QProcess vid; + vid.start("\""+program+"\" \""+OriginalAudioPath+"\" -n noiseprof \""+DenoiseProfile+"\""); + while(!vid.waitForStarted(100)&&!QProcess_stop) {} + while(!vid.waitForFinished(100)&&!QProcess_stop) {} + //================ + vid.start("\""+program+"\" \""+OriginalAudioPath+"\" \""+DenoisedAudio+"\" noisered \""+DenoiseProfile+"\" "+QString("%1").arg(DenoiseLevel)); + while(!vid.waitForStarted(100)&&!QProcess_stop) {} + while(!vid.waitForFinished(100)&&!QProcess_stop) {} + //================ + if(QFile::exists(DenoisedAudio)) + { + emit Send_TextBrowser_NewMessage(tr("Successfully denoise audio.[")+OriginalAudioPath+"]"); + QFile::remove(DenoiseProfile); + return DenoisedAudio; + } + else + { + emit Send_TextBrowser_NewMessage(tr("Error! Unable to denoise audio.[")+OriginalAudioPath+"]"); + return OriginalAudioPath; + } +} +/* +保存进度 +*/ +void MainWindow::video_write_Progress_ProcessBySegment(QString VideoConfiguration_fullPath,int StartTime,bool isSplitComplete,bool isScaleComplete,int OLDSegmentDuration,int LastVideoClipNo) +{ + QSettings *configIniWrite = new QSettings(VideoConfiguration_fullPath, QSettings::IniFormat); + configIniWrite->setIniCodec(QTextCodec::codecForName("UTF-8")); + //==================== 存储进度 ================================== + configIniWrite->setValue("/Progress/StartTime", StartTime); + configIniWrite->setValue("/Progress/isSplitComplete", isSplitComplete); + configIniWrite->setValue("/Progress/isScaleComplete", isScaleComplete); + configIniWrite->setValue("/Progress/OLDSegmentDuration", OLDSegmentDuration); + configIniWrite->setValue("/Progress/LastVideoClipNo", LastVideoClipNo); +} +/* +保存视频配置 +*/ +void MainWindow::video_write_VideoConfiguration(QString VideoConfiguration_fullPath,int ScaleRatio,int DenoiseLevel,bool CustRes_isEnabled,int CustRes_height,int CustRes_width,QString EngineName,bool isProcessBySegment,QString VideoClipsFolderPath,QString VideoClipsFolderName,bool isVideoFrameInterpolationEnabled,int MultipleOfFPS) +{ + QSettings *configIniWrite = new QSettings(VideoConfiguration_fullPath, QSettings::IniFormat); + configIniWrite->setIniCodec(QTextCodec::codecForName("UTF-8")); + //================= 添加警告 ========================= + configIniWrite->setValue("/Warning/EN", "Do not modify this file! It may cause the program to crash! If problems occur after the modification, delete this file and restart the program."); + //==================== 存储视频信息 ================================== + configIniWrite->setValue("/VideoConfiguration/ScaleRatio", ScaleRatio); + configIniWrite->setValue("/VideoConfiguration/DenoiseLevel", DenoiseLevel); + configIniWrite->setValue("/VideoConfiguration/CustRes_isEnabled", CustRes_isEnabled); + configIniWrite->setValue("/VideoConfiguration/CustRes_height", CustRes_height); + configIniWrite->setValue("/VideoConfiguration/CustRes_width", CustRes_width); + configIniWrite->setValue("/VideoConfiguration/EngineName", EngineName); + configIniWrite->setValue("/VideoConfiguration/isProcessBySegment", isProcessBySegment); + configIniWrite->setValue("/VideoConfiguration/VideoClipsFolderPath", VideoClipsFolderPath); + configIniWrite->setValue("/VideoConfiguration/VideoClipsFolderName", VideoClipsFolderName); + configIniWrite->setValue("/VideoConfiguration/isVideoFrameInterpolationEnabled", isVideoFrameInterpolationEnabled); + configIniWrite->setValue("/VideoConfiguration/MultipleOfFPS", MultipleOfFPS); + //==================== 存储进度 ================================== + configIniWrite->setValue("/Progress/StartTime", 0); + configIniWrite->setValue("/Progress/isSplitComplete", false); + configIniWrite->setValue("/Progress/isScaleComplete", false); + configIniWrite->setValue("/Progress/OLDSegmentDuration", -1); + configIniWrite->setValue("/Progress/LastVideoClipNo", -1); +} + +/* +直接读取视频 分辨率 然后用 自有算法 计算其应该有的比特率 +单位为k +*/ +int MainWindow::video_UseRes2CalculateBitrate(QString VideoFileFullPath) +{ + QMap res_map = video_get_Resolution(VideoFileFullPath); + int original_height = res_map["height"]; + int original_width = res_map["width"]; + if(original_height<=0||original_width<=0) + { + return 0; + } + //========= + double MultipleOfBitrate_OGFR = 1; + QString fps = video_get_fps(VideoFileFullPath).trimmed(); + if(fps != "0.0") + { + QStringList FPS_Nums = fps.split("/"); + double FPS_Nums_0 = FPS_Nums.at(0).toDouble(); + double FPS_Nums_1 = FPS_Nums.at(1).toDouble(); + if(FPS_Nums_0 >= FPS_Nums_1) + { + MultipleOfBitrate_OGFR = ((FPS_Nums_0/FPS_Nums_1)/24)*0.75; + if(MultipleOfBitrate_OGFR<1) + { + MultipleOfBitrate_OGFR = 1; + } + } + } + //========= + if(original_height<=original_width) + { + return qRound(original_height*6*MultipleOfBitrate_OGFR); + } + else + { + return qRound(original_width*6*MultipleOfBitrate_OGFR); + } +} + +QString MainWindow::video_get_bitrate_AccordingToRes_FrameFolder(QString ScaledFrameFolderPath,QString VideoPath) +{ + QStringList flist = file_getFileNames_in_Folder_nofilter(ScaledFrameFolderPath); + QString Full_Path_File = ""; + if(!flist.isEmpty()) + { + for(int i = 0; i < flist.size(); i++) + { + QString tmp = flist.at(i); + Full_Path_File = ScaledFrameFolderPath + "/" + tmp; + QFileInfo finfo(Full_Path_File); + if(finfo.suffix()=="png")break; + } + } + QImage qimage_original; + qimage_original.load(Full_Path_File); + int original_height = qimage_original.height(); + int original_width = qimage_original.width(); + if(original_height<=0||original_width<=0) + { + return ""; + } + //========= + double MultipleOfBitrate_OGFR = 1; + QString fps = video_get_fps(VideoPath).trimmed(); + if(fps != "0.0") + { + QStringList FPS_Nums = fps.split("/"); + double FPS_Nums_0 = FPS_Nums.at(0).toDouble(); + double FPS_Nums_1 = FPS_Nums.at(1).toDouble(); + if(FPS_Nums_0 >= FPS_Nums_1) + { + MultipleOfBitrate_OGFR = ((FPS_Nums_0/FPS_Nums_1)/24)*0.75; + if(MultipleOfBitrate_OGFR<1) + { + MultipleOfBitrate_OGFR = 1; + } + } + } + //========= + double MultipleOfBitrate_MOF = 1; + if(ui->groupBox_FrameInterpolation->isChecked()==true) + { + MultipleOfBitrate_MOF = ui->spinBox_MultipleOfFPS_VFI->value()*0.75; + } + //========= + if(original_height<=original_width) + { + return QString::number(qRound(original_height*6*MultipleOfBitrate_MOF*MultipleOfBitrate_OGFR),10); + } + else + { + return QString::number(qRound(original_width*6*MultipleOfBitrate_MOF*MultipleOfBitrate_OGFR),10); + } +} +/* +获取视频比特率 +*/ +QString MainWindow::video_get_bitrate(QString videoPath,bool isReturnFullCMD,bool isVidOnly) +{ + emit Send_TextBrowser_NewMessage(tr("Get bitrate of the video:[")+videoPath+"]"); + //========================= 调用ffprobe读取视频信息 ====================== + QProcess *Get_Bitrate_process = new QProcess(); + QString cmd = "\""+Current_Path+"/ffprobe_waifu2xEX.exe\" -i \""+videoPath+"\" -select_streams v -show_streams -v quiet -print_format ini -show_format"; + Get_Bitrate_process->start(cmd); + while(!Get_Bitrate_process->waitForStarted(100)&&!QProcess_stop) {} + while(!Get_Bitrate_process->waitForFinished(100)&&!QProcess_stop) {} + //============= 保存ffprobe输出的ini格式文本 ============= + QString ffprobe_output_str = Get_Bitrate_process->readAllStandardOutput(); + //================ 将ini写入文件保存 ================ + //创建文件夹 + QString video_info_dir = Current_Path+"/videoInfo"; + if(!file_isDirExist(video_info_dir)) + { + file_mkDir(video_info_dir); + } + //======================== + QFileInfo videoFileInfo(videoPath); + QString Path_video_info_ini = ""; + QString video_dir = file_getFolderPath(videoPath); + int FileNo = 0; + do + { + FileNo++; + Path_video_info_ini = video_dir+"/"+file_getBaseName(videoPath)+"_videoInfo_"+QString::number(FileNo,10)+"_Waifu2xEX.ini"; + } + while(QFile::exists(Path_video_info_ini)); + //========= + QFile video_info_ini(Path_video_info_ini); + video_info_ini.remove(); + if (video_info_ini.open(QIODevice::ReadWrite | QIODevice::Text)) //QIODevice::ReadWrite支持读写 + { + QTextStream stream(&video_info_ini); + stream << ffprobe_output_str; + } + video_info_ini.close(); + //================== 读取ini获得参数 ===================== + QSettings *configIniRead_videoInfo = new QSettings(Path_video_info_ini, QSettings::IniFormat); + QString BitRate = ""; + QString BitRateCMD = ""; + if(configIniRead_videoInfo->value("/streams.stream.0/bit_rate")!=QVariant()) + { + BitRate = configIniRead_videoInfo->value("/streams.stream.0/bit_rate").toString().trimmed(); + if(isReturnFullCMD==true)BitRateCMD = " -b:v "+BitRate+" "; + } + if(BitRate.toUInt() == 0 && isVidOnly == false) + { + if(configIniRead_videoInfo->value("/format/bit_rate")!=QVariant()) + { + BitRate = configIniRead_videoInfo->value("/format/bit_rate").toString().trimmed(); + if(isReturnFullCMD==true)BitRateCMD = " -b "+BitRate+" "; + } + } + //======================= + if(BitRate.toUInt() == 0) + { + BitRate=""; + } + //======================= + if(isReturnFullCMD==true && BitRate!="" && BitRateCMD!="") + { + video_info_ini.remove(); + return BitRateCMD; + } + else + { + video_info_ini.remove(); + return BitRate; + } +} +/* +获取视频FPS +*/ +QString MainWindow::video_get_fps(QString videoPath) +{ + //========================= 调用ffprobe读取视频信息 ====================== + QProcess *Get_VideoFPS_process = new QProcess(); + QString cmd = "\""+Current_Path+"/ffprobe_waifu2xEX.exe\" -i \""+videoPath+"\" -select_streams v -show_streams -v quiet -print_format ini -show_format"; + Get_VideoFPS_process->start(cmd); + while(!Get_VideoFPS_process->waitForStarted(100)&&!QProcess_stop) {} + while(!Get_VideoFPS_process->waitForFinished(100)&&!QProcess_stop) {} + //============= 保存ffprobe输出的ini格式文本 ============= + QString ffprobe_output_str = Get_VideoFPS_process->readAllStandardOutput(); + //================ 将ini写入文件保存 ================ + QFileInfo videoFileInfo(videoPath); + QString Path_video_info_ini = ""; + QString video_dir = file_getFolderPath(videoPath); + int FileNo = 0; + do + { + FileNo++; + Path_video_info_ini = video_dir+"/"+file_getBaseName(videoPath)+"_videoInfo_"+QString::number(FileNo,10)+"_Waifu2xEX.ini"; + } + while(QFile::exists(Path_video_info_ini)); + //========= + QFile video_info_ini(Path_video_info_ini); + video_info_ini.remove(); + if (video_info_ini.open(QIODevice::ReadWrite | QIODevice::Text)) //QIODevice::ReadWrite支持读写 + { + QTextStream stream(&video_info_ini); + stream << ffprobe_output_str; + } + video_info_ini.close(); + //================== 读取ini获得参数 ===================== + QString FPS_Division = ""; + QSettings *configIniRead_videoInfo = new QSettings(Path_video_info_ini, QSettings::IniFormat); + if(configIniRead_videoInfo->value("/streams.stream.0/avg_frame_rate") != QVariant()) + { + FPS_Division = configIniRead_videoInfo->value("/streams.stream.0/avg_frame_rate").toString().trimmed(); + } + video_info_ini.remove(); + //======================= + if(FPS_Division=="") + { + return "0.0"; + } + //======================= + QStringList FPS_Nums = FPS_Division.split("/"); + if(FPS_Nums.size()!=2) + { + return "0.0"; + } + double FPS_Num_0 = FPS_Nums.at(0).toDouble(); + double FPS_Num_1 = FPS_Nums.at(1).toDouble(); + if(FPS_Num_0<=0||FPS_Num_1<=0) + { + return "0.0"; + } + return FPS_Division; +} + +int MainWindow::video_get_frameNum(QString videoPath) +{ + //========================= 调用ffprobe读取视频信息 ====================== + QProcess *Get_VideoFrameNumDigits_process = new QProcess(); + QString cmd = "\""+Current_Path+"/ffprobe_waifu2xEX.exe\" -i \""+videoPath+"\" -select_streams v -show_streams -v quiet -print_format ini -show_format"; + Get_VideoFrameNumDigits_process->start(cmd); + while(!Get_VideoFrameNumDigits_process->waitForStarted(100)&&!QProcess_stop) {} + while(!Get_VideoFrameNumDigits_process->waitForFinished(100)&&!QProcess_stop) {} + //============= 保存ffprobe输出的ini格式文本 ============= + QString ffprobe_output_str = Get_VideoFrameNumDigits_process->readAllStandardOutput(); + //================ 将ini写入文件保存 ================ + QFileInfo videoFileInfo(videoPath); + QString Path_video_info_ini = ""; + QString video_dir = file_getFolderPath(videoPath); + int FileNo = 0; + do + { + FileNo++; + Path_video_info_ini = video_dir+"/"+file_getBaseName(videoPath)+"_videoInfo_"+QString::number(FileNo,10)+"_Waifu2xEX.ini"; + } + while(QFile::exists(Path_video_info_ini)); + //========= + QFile video_info_ini(Path_video_info_ini); + video_info_ini.remove(); + if (video_info_ini.open(QIODevice::ReadWrite | QIODevice::Text)) //QIODevice::ReadWrite支持读写 + { + QTextStream stream(&video_info_ini); + stream << ffprobe_output_str; + } + video_info_ini.close(); + //================== 读取ini获得参数 ===================== + int FrameNum = 0; + QSettings *configIniRead_videoInfo = new QSettings(Path_video_info_ini, QSettings::IniFormat); + if(configIniRead_videoInfo->value("/streams.stream.0/nb_frames") != QVariant()) + { + FrameNum = configIniRead_videoInfo->value("/streams.stream.0/nb_frames").toInt(); + } + video_info_ini.remove(); + if(FrameNum<1) + { + emit Send_TextBrowser_NewMessage(tr("ERROR! Unable to read the number of frames of the video: [")+videoPath+"]"); + return 0; + } + return FrameNum; +} + +int MainWindow::video_get_frameNumDigits(QString videoPath) +{ + int frameNumDigits=1+(int)log10(video_get_frameNum(videoPath)); + return frameNumDigits; +} + +void MainWindow::video_video2images(QString VideoPath,QString FrameFolderPath,QString AudioPath) +{ + emit Send_TextBrowser_NewMessage(tr("Start splitting video: [")+VideoPath+"]"); + //================= + QString ffmpeg_path = Current_Path+"/ffmpeg_waifu2xEX.exe"; + //================ 获取fps ===================== + QString fps_video_cmd=" "; + QString fps = video_get_fps(VideoPath).trimmed(); + if(fps != "0.0") + { + fps_video_cmd = " -r "+fps+" "; + } + //===================== + int FrameNumDigits = video_get_frameNumDigits(VideoPath); + if(FrameNumDigits==0)return; + QFile::remove(isPreVFIDone_MarkFilePath(VideoPath)); + //===================== + QProcess video_splitFrame; + video_splitFrame.start("\""+ffmpeg_path+"\" -y"+fps_video_cmd+"-i \""+VideoPath+"\" "+fps_video_cmd+" \""+FrameFolderPath.replace("%","%%")+"/%0"+QString::number(FrameNumDigits,10)+"d.png\""); + while(!video_splitFrame.waitForStarted(100)&&!QProcess_stop) {} + while(!video_splitFrame.waitForFinished(100)&&!QProcess_stop) {} + //============== 尝试在Win7下可能兼容的指令 ================================ + if(file_isDirEmpty(FrameFolderPath)) + { + video_splitFrame.start("\""+ffmpeg_path+"\" -y"+fps_video_cmd+"-i \""+VideoPath+"\" "+fps_video_cmd+" \""+FrameFolderPath.replace("%","%%")+"/%%0"+QString::number(FrameNumDigits,10)+"d.png\""); + while(!video_splitFrame.waitForStarted(100)&&!QProcess_stop) {} + while(!video_splitFrame.waitForFinished(100)&&!QProcess_stop) {} + } + video_get_audio(VideoPath,AudioPath);//拆分音频 + //======== 插帧 ========= + QFileInfo vfinfo(VideoPath); + QString video_dir = file_getFolderPath(vfinfo); + QString video_filename = file_getBaseName(VideoPath); + QString VFI_FolderPath_tmp = video_dir+"/"+video_filename+"_PreVFI_W2xEX"; + if(ui->checkBox_VfiAfterScale_VFI->isChecked()==false && ui->groupBox_FrameInterpolation->isChecked()==true && ui->checkBox_FrameInterpolationOnly_Video->isChecked()==false) //如果启用了插帧 + { + //如果检测到完整的已经插帧的帧缓存 + if(file_isDirExist(VFI_FolderPath_tmp) && (file_getFileNames_in_Folder_nofilter(FrameFolderPath).size() * ui->spinBox_MultipleOfFPS_VFI->value() == file_getFileNames_in_Folder_nofilter(VFI_FolderPath_tmp).size())) + { + file_DelDir(FrameFolderPath); + QDir VFI_FolderPath_tmp_qdir(VFI_FolderPath_tmp); + VFI_FolderPath_tmp_qdir.rename(VFI_FolderPath_tmp,FrameFolderPath); + return; + } + else + { + if(FrameInterpolation(FrameFolderPath,VFI_FolderPath_tmp)==true) + { + //如果插帧成功 + file_DelDir(FrameFolderPath); + QDir VFI_FolderPath_tmp_qdir(VFI_FolderPath_tmp); + VFI_FolderPath_tmp_qdir.rename(VFI_FolderPath_tmp,FrameFolderPath); + file_generateMarkFile(isPreVFIDone_MarkFilePath(VideoPath),QString("%1").arg(ui->spinBox_MultipleOfFPS_VFI->value())); + return; + } + else + { + //如果插帧失败且启用了仅插帧模式 + if(ui->checkBox_FrameInterpolationOnly_Video->isChecked()==true) + { + file_DelDir(FrameFolderPath); + file_mkDir(FrameFolderPath); + file_DelDir(VFI_FolderPath_tmp); + if(waifu2x_STOP==false)emit Send_TextBrowser_NewMessage(tr("Failed to interpolate frames of video:[")+VideoPath+"]"); + return; + } + //如果插帧失败但是已经超分辨率 + else + { + file_DelDir(VFI_FolderPath_tmp); + if(waifu2x_STOP==false)emit Send_TextBrowser_NewMessage(tr("Failed to interpolate frames of video:[")+VideoPath+tr("]. Gonna generate a video without frame Interpolation.")); + } + } + } + } + //==================================== + emit Send_TextBrowser_NewMessage(tr("Finish splitting video: [")+VideoPath+"]"); +} + +int MainWindow::video_images2video(QString VideoPath,QString video_mp4_scaled_fullpath,QString ScaledFrameFolderPath,QString AudioPath,bool CustRes_isEnabled,int CustRes_height,int CustRes_width,bool isOverScaled) +{ + bool Del_DenoisedAudio = false; + //================= + QString bitrate_video_cmd=""; + //======= + if(ui->groupBox_video_settings->isChecked()&&(ui->spinBox_bitrate_vid->value()>0)) + { + bitrate_video_cmd=" -b:v "+QString::number(ui->spinBox_bitrate_vid->value(),10)+"k "; + } + else + { + QString BitRate = video_get_bitrate_AccordingToRes_FrameFolder(ScaledFrameFolderPath,VideoPath); + if(BitRate!="")bitrate_video_cmd=" -b:v "+BitRate+"k "; + } + //================ 自定义分辨率 ====================== + QString resize_cmd =""; + if(CustRes_isEnabled || isOverScaled) + { + if(isOverScaled==true && CustRes_isEnabled==false) + { + QMap res_map = video_get_Resolution(VideoPath); + int scaleratio_orginal = ui->doubleSpinBox_ScaleRatio_video->value(); + resize_cmd =" -vf scale="+QString::number(res_map["width"]*scaleratio_orginal,10)+":"+QString::number(res_map["height"]*scaleratio_orginal,10)+" "; + } + //============= 如果没有自定义视频参数, 则根据自定义分辨率再计算一次比特率 ========== + if(ui->groupBox_video_settings->isChecked()==false || (ui->spinBox_bitrate_vid->value()<1)) + { + int small_res =0; + if(CustRes_width<=CustRes_height) + { + small_res = CustRes_width; + } + else + { + small_res = CustRes_height; + } + bitrate_video_cmd=" -b:v "+QString::number(small_res*6,10)+"k "; + } + //================================================================= + if(CustRes_AspectRatioMode==Qt::IgnoreAspectRatio && CustRes_isEnabled==true) + { + resize_cmd =" -vf scale="+QString::number(CustRes_width,10)+":"+QString::number(CustRes_height,10)+" "; + } + if(CustRes_AspectRatioMode==Qt::KeepAspectRatio && CustRes_isEnabled==true) + { + if(CustRes_width>=CustRes_height) + { + resize_cmd =" -vf scale=-2:"+QString::number(CustRes_height,10)+" "; + } + else + { + resize_cmd =" -vf scale="+QString::number(CustRes_width,10)+":-2 "; + } + } + if(CustRes_AspectRatioMode==Qt::KeepAspectRatioByExpanding && CustRes_isEnabled==true) + { + if(CustRes_width>=CustRes_height) + { + resize_cmd =" -vf scale="+QString::number(CustRes_width,10)+":-2 "; + } + else + { + resize_cmd =" -vf scale=-2:"+QString::number(CustRes_height,10)+" "; + } + } + } + QString ffmpeg_path = Current_Path+"/ffmpeg_waifu2xEX.exe"; + int FrameNumDigits = video_get_frameNumDigits(VideoPath); + if(FrameNumDigits==0)return 0; + QFileInfo vfinfo(VideoPath); + QString video_dir = file_getFolderPath(vfinfo); + QString video_filename = file_getBaseName(VideoPath); + QString video_ext = vfinfo.suffix(); + //=========== 获取fps =========== + QString fps = video_get_fps(VideoPath).trimmed(); + if(fps == "0.0") + { + emit Send_TextBrowser_NewMessage(tr("Error occured when processing [")+VideoPath+tr("]. Error: [Unable to get video frame rate.]")); + return 0; + } + //=============== 补帧 =============== + QString VFI_FolderPath_tmp = video_dir+"/"+video_filename+"_PostVFI_W2xEX"; + //如果启用了插帧 + if(ui->groupBox_FrameInterpolation->isChecked()==true) + { + bool isPreVFIDone = QFile::exists(isPreVFIDone_MarkFilePath(VideoPath)); + if((ui->checkBox_VfiAfterScale_VFI->isChecked()==false && ui->checkBox_FrameInterpolationOnly_Video->isChecked()==false) || isPreVFIDone==true) + { + if(isPreVFIDone==true) + { + FrameNumDigits = CalNumDigits((file_getFileNames_in_Folder_nofilter(ScaledFrameFolderPath).size())); + //========== + int Old_MultipleOfFPS = ui->spinBox_MultipleOfFPS_VFI->value(); + QFile f(isPreVFIDone_MarkFilePath(VideoPath)); + if(f.open(QIODevice::ReadOnly | QIODevice::Text)) + { + QTextStream txtInput(&f); + QString lineStr; + lineStr = txtInput.readAll(); + int tmp_mof = lineStr.trimmed().toInt(); + if(tmp_mof>1) + { + Old_MultipleOfFPS = tmp_mof; + } + } + //========== + QStringList FPS_Nums = fps.split("/"); + fps = QString("%1/%2").arg(FPS_Nums.at(0).toDouble() * Old_MultipleOfFPS).arg(FPS_Nums.at(1).toDouble()); + } + } + else + { + //如果检测到完整的已经插帧的帧缓存 + if(file_isDirExist(VFI_FolderPath_tmp) && (file_getFileNames_in_Folder_nofilter(ScaledFrameFolderPath).size() * ui->spinBox_MultipleOfFPS_VFI->value() == file_getFileNames_in_Folder_nofilter(VFI_FolderPath_tmp).size())) + { + FrameNumDigits = CalNumDigits((file_getFileNames_in_Folder_nofilter(VFI_FolderPath_tmp).size())); + ScaledFrameFolderPath = VFI_FolderPath_tmp; + QStringList FPS_Nums = fps.split("/"); + fps = QString("%1/%2").arg(FPS_Nums.at(0).toDouble() * ui->spinBox_MultipleOfFPS_VFI->value()).arg(FPS_Nums.at(1).toDouble()); + } + else + { + //如果插帧成功 + if(FrameInterpolation(ScaledFrameFolderPath,VFI_FolderPath_tmp)==true) + { + FrameNumDigits = CalNumDigits((file_getFileNames_in_Folder_nofilter(VFI_FolderPath_tmp).size())); + ScaledFrameFolderPath = VFI_FolderPath_tmp; + QStringList FPS_Nums = fps.split("/"); + fps = QString("%1/%2").arg(FPS_Nums.at(0).toDouble() * ui->spinBox_MultipleOfFPS_VFI->value()).arg(FPS_Nums.at(1).toDouble()); + } + else + { + //如果插帧失败且启用了分段处理或仅插帧模式 + if(ui->checkBox_ProcessVideoBySegment->isChecked()==true || ui->checkBox_FrameInterpolationOnly_Video->isChecked()==true) + { + file_DelDir(VFI_FolderPath_tmp); + if(waifu2x_STOP==false)emit Send_TextBrowser_NewMessage(tr("Failed to interpolate frames of video:[")+VideoPath+"]"); + return 0; + } + //如果插帧失败但是已经超分辨率且没分段 + else + { + file_DelDir(VFI_FolderPath_tmp); + if(waifu2x_STOP==false)emit Send_TextBrowser_NewMessage(tr("Failed to interpolate frames of video:[")+VideoPath+tr("]. Gonna generate a video without frame Interpolation.")); + } + } + } + } + } + //=============== 音频降噪 ======================== + if((ui->checkBox_AudioDenoise->isChecked())&&QFile::exists(AudioPath)) + { + QString AudioPath_tmp = video_AudioDenoise(AudioPath); + if(AudioPath_tmp!=AudioPath) + { + AudioPath = AudioPath_tmp; + Del_DenoisedAudio = true; + } + } + //================= 开始处理 ============================= + emit Send_TextBrowser_NewMessage(tr("Start assembling video:[")+VideoPath+"]"); + //====== + QString CMD = ""; + if(QFile::exists(AudioPath)) + { + CMD = "\""+ffmpeg_path+"\" -y -f image2 -framerate "+fps+" -r "+fps+" -i \""+ScaledFrameFolderPath.replace("%","%%")+"/%0"+QString::number(FrameNumDigits,10)+"d.png\" -i \""+AudioPath+"\" -r "+fps+bitrate_video_cmd+resize_cmd+video_ReadSettings_OutputVid(AudioPath)+" -r "+fps+" \""+video_mp4_scaled_fullpath+"\""; + } + else + { + CMD = "\""+ffmpeg_path+"\" -y -f image2 -framerate "+fps+" -r "+fps+" -i \""+ScaledFrameFolderPath.replace("%","%%")+"/%0"+QString::number(FrameNumDigits,10)+"d.png\" -r "+fps+bitrate_video_cmd+resize_cmd+video_ReadSettings_OutputVid(AudioPath)+" -r "+fps+" \""+video_mp4_scaled_fullpath+"\""; + } + QProcess images2video; + QFile::remove(video_mp4_scaled_fullpath);//删除旧文件 + images2video.start(CMD); + while(!images2video.waitForStarted(100)&&!QProcess_stop) {} + while(!images2video.waitForFinished(100)&&!QProcess_stop) + { + if(waifu2x_STOP) + { + images2video.close(); + QFile::remove(video_mp4_scaled_fullpath); + file_DelDir(VFI_FolderPath_tmp); + if(Del_DenoisedAudio)QFile::remove(AudioPath); + return 0; + } + } + //============== 尝试在Win7下可能兼容的指令 ================================ + if(QFile::exists(video_mp4_scaled_fullpath)==false) + { + if(QFile::exists(AudioPath)) + { + CMD = "\""+ffmpeg_path+"\" -y -f image2 -framerate "+fps+" -r "+fps+" -i \""+ScaledFrameFolderPath.replace("%","%%")+"/%%0"+QString::number(FrameNumDigits,10)+"d.png\" -i \""+AudioPath+"\" -r "+fps+bitrate_video_cmd+resize_cmd+video_ReadSettings_OutputVid(AudioPath)+" -r "+fps+" \""+video_mp4_scaled_fullpath+"\""; + } + else + { + CMD = "\""+ffmpeg_path+"\" -y -f image2 -framerate "+fps+" -r "+fps+" -i \""+ScaledFrameFolderPath.replace("%","%%")+"/%%0"+QString::number(FrameNumDigits,10)+"d.png\" -r "+fps+bitrate_video_cmd+resize_cmd+video_ReadSettings_OutputVid(AudioPath)+" -r "+fps+" \""+video_mp4_scaled_fullpath+"\""; + } + QProcess images2video; + images2video.start(CMD); + while(!images2video.waitForStarted(100)&&!QProcess_stop) {} + while(!images2video.waitForFinished(100)&&!QProcess_stop) + { + if(waifu2x_STOP) + { + images2video.close(); + QFile::remove(video_mp4_scaled_fullpath); + file_DelDir(VFI_FolderPath_tmp); + if(Del_DenoisedAudio)QFile::remove(AudioPath); + return 0; + } + } + } + //=================== + if(Del_DenoisedAudio)QFile::remove(AudioPath); + if(ui->checkBox_KeepVideoCache->isChecked() == false || ui->checkBox_ProcessVideoBySegment->isChecked())file_DelDir(VFI_FolderPath_tmp); + if(ui->checkBox_KeepVideoCache->isChecked() == false)QFile::remove(isPreVFIDone_MarkFilePath(VideoPath)); + //============================== + emit Send_TextBrowser_NewMessage(tr("Finish assembling video:[")+VideoPath+"]"); + return 0; +} + +QString MainWindow::video_ReadSettings_OutputVid(QString AudioPath) +{ + QString OutputVideoSettings= " "; + //==== + if(ui->groupBox_video_settings->isChecked()) + { + if(ui->lineEdit_encoder_vid->text().trimmed()!="") + { + OutputVideoSettings.append("-c:v "+ui->lineEdit_encoder_vid->text().trimmed()+" ");//图像编码器 + } + //======== + if(QFile::exists(AudioPath)) + { + if(ui->lineEdit_encoder_audio->text().trimmed()!="") + { + OutputVideoSettings.append("-c:a "+ui->lineEdit_encoder_audio->text().trimmed()+" ");//音频编码器 + } + //========= + if(ui->spinBox_bitrate_audio->value()>0) + { + OutputVideoSettings.append("-b:a "+QString::number(ui->spinBox_bitrate_audio->value(),10)+"k ");//音频比特率 + } + } + //========= + if(ui->lineEdit_pixformat->text().trimmed()!="") + { + OutputVideoSettings.append("-pix_fmt "+ui->lineEdit_pixformat->text().trimmed()+" ");//pixel format + } + else + { + OutputVideoSettings.append("-pix_fmt yuv420p ");//pixel format + } + //=========== + if(ui->lineEdit_ExCommand_output->text().trimmed()!="") + { + OutputVideoSettings.append(ui->lineEdit_ExCommand_output->text().trimmed()+" ");//附加指令 + } + } + //========= + else + { + OutputVideoSettings.append("-pix_fmt yuv420p ");//pixel format + } + //======= + return OutputVideoSettings; +} + +void MainWindow::DelVfiDir(QString VideoPath) +{ + QFileInfo vfinfo(VideoPath); + QString video_dir = file_getFolderPath(vfinfo); + QString video_filename = file_getBaseName(VideoPath); + file_DelDir(video_dir+"/"+video_filename+"_PreVFI_W2xEX"); + file_DelDir(video_dir+"/"+video_filename+"_PostVFI_W2xEX"); +} diff --git a/SRC/Waifu2x-Extension-QT/waifu2x.cpp b/SRC_v3.41.01-beta/Waifu2x-Extension-QT/waifu2x.cpp similarity index 97% rename from SRC/Waifu2x-Extension-QT/waifu2x.cpp rename to SRC_v3.41.01-beta/Waifu2x-Extension-QT/waifu2x.cpp index a971bc8..d58ff65 100644 --- a/SRC/Waifu2x-Extension-QT/waifu2x.cpp +++ b/SRC_v3.41.01-beta/Waifu2x-Extension-QT/waifu2x.cpp @@ -1,1351 +1,1351 @@ -/* - Copyright (C) 2021 Aaron Feng - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU Affero General Public License as published - by the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Affero General Public License for more details. - - You should have received a copy of the GNU Affero General Public License - along with this program. If not, see . - - My Github homepage: https://github.com/AaronFeng753 -*/ - -#include "mainwindow.h" -#include "ui_mainwindow.h" -/* -开始处理文件的按钮 -*/ -void MainWindow::on_pushButton_Start_clicked() -{ - /* - * 判断是否启用自定义输出路径 - * 判断输出路径是否合法 - */ - if(ui->checkBox_OutPath_isEnabled->isChecked()) - { - QString tmp = ui->lineEdit_outputPath->text(); - tmp = tmp.trimmed(); - if(tmp=="") - { - //===== - QMessageBox *MSG = new QMessageBox(); - MSG->setWindowTitle(tr("Error")); - MSG->setText(tr("Output path is empty.")); - MSG->setIcon(QMessageBox::Warning); - MSG->setModal(true); - MSG->show(); - //===== - emit Send_TextBrowser_NewMessage(tr("Output path is empty.")); - return; - } - tmp = tmp.replace("\\","/"); - tmp = tmp.replace("\\\\","/"); - tmp = tmp.replace("//","/"); - if(tmp.right(1)=="/") - { - tmp = tmp.left(tmp.length() - 1); - } - QFileInfo fileinfo_tmp(tmp); - if(file_isDirExist(tmp)&&fileinfo_tmp.isDir()&&file_isDirWritable(tmp)) - { - OutPutFolder_main = tmp; - } - else - { - //===== - QMessageBox *MSG = new QMessageBox(); - MSG->setWindowTitle(tr("Error")); - MSG->setText(tr("Invalid output path.\n\nOr do not have sufficient permissions to write files to the output path, you might need to grant administrator permissions to this software.")); - MSG->setIcon(QMessageBox::Warning); - MSG->setModal(true); - MSG->show(); - //===== - emit Send_TextBrowser_NewMessage(tr("Invalid output path.")); - return; - } - } - //============================= - // 判断文件列表是否为空 - //============================= - if(Table_model_image->rowCount()==0&&Table_model_gif->rowCount()==0&&Table_model_video->rowCount()==0) - { - QMessageBox *MSG = new QMessageBox(); - MSG->setWindowTitle(tr("Error")); - MSG->setText(tr("Unable to start processing files: The file list is empty.")); - MSG->setIcon(QMessageBox::Warning); - MSG->setModal(true); - MSG->show(); - return; - } - //====================================== - // 判断文件列表是否全部处理完成 - //====================================== - int rowCount_image = Table_model_image->rowCount(); - int rowCount_image_cache = rowCount_image; - int rowCount_gif = Table_model_gif->rowCount(); - int rowCount_gif_cache = rowCount_gif; - int rowCount_video = Table_model_video->rowCount(); - int rowCount_video_cache = rowCount_video; - //检查图片文件列表 - for ( int RowNum = 0; RowNum < rowCount_image; RowNum++ ) - { - if(ui->checkBox_ReProcFinFiles->isChecked()==false) - { - if(Table_model_image->item(RowNum,1)->text().toLower().contains("finished")) - { - rowCount_image_cache--; - continue; - } - } - if(Table_model_image->item(RowNum,1)->text().toLower().contains("deleted")) - { - rowCount_image_cache--; - continue; - } - } - //检查GIF文件列表 - for ( int RowNum = 0; RowNum < rowCount_gif; RowNum++ ) - { - if(ui->checkBox_ReProcFinFiles->isChecked()==false) - { - if(Table_model_gif->item(RowNum,1)->text().toLower().contains("finished")) - { - rowCount_gif_cache--; - continue; - } - } - if(Table_model_gif->item(RowNum,1)->text().toLower().contains("deleted")) - { - rowCount_gif_cache--; - continue; - } - } - //检查视频文件列表 - for ( int RowNum = 0; RowNum < rowCount_video; RowNum++ ) - { - if(ui->checkBox_ReProcFinFiles->isChecked()==false) - { - if(Table_model_video->item(RowNum,1)->text().toLower().contains("finished")) - { - rowCount_video_cache--; - continue; - } - } - if(Table_model_video->item(RowNum,1)->text().toLower().contains("deleted")) - { - rowCount_video_cache--; - continue; - } - } - //判断是否剩余可处理的文件 - if(rowCount_image_cache+rowCount_gif_cache+rowCount_video_cache==0) - { - QMessageBox *MSG = new QMessageBox(); - MSG->setWindowTitle(tr("Error")); - MSG->setText(tr("Unable to start processing files: All files in Files list are Finished or Deleted.\n\nTip: You can enable [Re-process finished files] if you wanna re-process finished files.")); - MSG->setIcon(QMessageBox::Warning); - MSG->setModal(true); - MSG->show(); - return; - } - //正式开始处理列表内的文件 - Table_ChangeAllStatusToWaiting();//将table内没开始处理或者被打断的条目状态变为等待中 - //============== 判断是否需要隐藏ETA和剩余时间 ================ - if(Table_model_gif->rowCount()!=0||Table_model_video->rowCount()!=0) - { - ui->label_TimeRemain->setVisible(0); - ui->label_ETA->setVisible(0); - } - else - { - ui->label_TimeRemain->setVisible(1); - ui->label_ETA->setVisible(1); - } - //============== 数值初始化 ================== - waifu2x_STOP = false; - waifu2x_STOP_confirm = false; - ThreadNumMax = 0; - ThreadNumRunning = 0; - Progressbar_MaxVal = 0; - Progressbar_CurrentVal = 0; - TaskNumTotal=0; - TaskNumFinished=0; - NewTaskFinished=false; - ETA=0; - isForceRetryClicked=false; - ForceRetryCount=1; - isForceRetryEnabled=true; - isSuccessiveFailuresDetected_VFI=false; - //============== 界面初始化 ====================== - ui->checkBox_EnableVFI_Home->setEnabled(0); - ui->checkBox_FrameInterpolationOnly_Video->setEnabled(0); - ui->groupBox_FrameInterpolation->setEnabled(0); - ui->pushButton_BrowserFile->setEnabled(0); - ui->comboBox_ImageSaveFormat->setEnabled(0); - ui->spinBox_ImageQualityLevel->setEnabled(0); - emit Send_Table_EnableSorting(0);//启用文件列表的排序功能 - RemoveFile_FilesList_QAction_FileList->setEnabled(0); - Apply_CustRes_QAction_FileList->setEnabled(0); - Cancel_CustRes_QAction_FileList->setEnabled(0); - this->setAcceptDrops(0);//禁止drop file - pushButton_Stop_setEnabled_self(1);//启用stop button - pushButton_Start_setEnabled_self(0);//禁用start button - OutputSettingsArea_setEnabled(false); - ui->pushButton_ClearList->setEnabled(0); - ui->pushButton_RemoveItem->setEnabled(0); - ui->groupBox_Engine->setEnabled(0); - ui->groupBox_ScaleRaton_DenoiseLevel->setEnabled(0); - ui->checkBox_OptGIF->setEnabled(0); - ui->checkBox_DelOriginal->setEnabled(0); - ui->checkBox_ReProcFinFiles->setEnabled(0); - ui->pushButton_compatibilityTest->setEnabled(0); - ui->pushButton_ReadFileList->setEnabled(0); - progressbar_clear(); - ui->label_TimeCost->setText(tr("Time taken:NULL")); - ui->label_ETA->setText(tr("ETA:NULL")); - ui->label_TimeRemain->setText(tr("Time remaining:NULL")); - ui->groupBox_video_settings->setEnabled(0); - QAction_checkBox_MoveToRecycleBin_checkBox_DelOriginal->setEnabled(0); - ui->pushButton_ForceRetry->setVisible(1); - ui->checkBox_AutoDetectAlphaChannel->setEnabled(0); - ui->groupBox_AudioDenoise->setEnabled(0); - ui->checkBox_ProcessVideoBySegment->setEnabled(0); - ui->spinBox_SegmentDuration->setEnabled(0); - ui->comboBox_ImageStyle->setEnabled(0); - ui->checkBox_PreProcessImage->setEnabled(0); - ui->checkBox_AlwaysPreProcessAlphaPNG->setEnabled(0); - on_lineEdit_GPUs_Anime4k_editingFinished(); - on_lineEdit_MultiGPUInfo_Waifu2xCaffe_editingFinished(); - ui->checkBox_ReplaceOriginalFile->setEnabled(0); - ui->groupBox_CustRes->setEnabled(0); - ui->checkBox_DisableResize_gif->setEnabled(0); - //========== - TimeCost=0; - TimeCostTimer->start(1000); - emit Send_TextBrowser_NewMessage(tr("Start processing files.")); - //========== - PreLoad_Engines_Settings();//预读取引擎设定 - ui->comboBox_ImageStyle_Waifu2xCaffe->setEnabled(0); - //========== - Waifu2xMain = QtConcurrent::run(this, &MainWindow::Waifu2xMainThread);//启动waifu2x 主线程 -} -/* -主调度线程 -*/ -int MainWindow::Waifu2xMainThread() -{ - //在table中的状态修改完成前一直block,防止偶发的多线程错误 - QMutex_Table_ChangeAllStatusToWaiting.lock(); - NULL; - QMutex_Table_ChangeAllStatusToWaiting.unlock(); - //======================= - int rowCount_image = Table_model_image->rowCount(); - int rowCount_gif = Table_model_gif->rowCount(); - int rowCount_video = Table_model_video->rowCount(); - //======================= - Progressbar_MaxVal = rowCount_image + rowCount_gif + rowCount_video; - Progressbar_CurrentVal = 0; - TaskNumFinished=0; - emit Send_PrograssBar_Range_min_max(0, Progressbar_MaxVal); - if(rowCount_image>0) - { - int ImageEngine = ui->comboBox_Engine_Image->currentIndex(); - for ( int currentRowNumber = 0; currentRowNumber < rowCount_image; currentRowNumber++ ) - { - if(waifu2x_STOP) - { - while (ThreadNumRunning > 0) - { - Delay_msec_sleep(750); - } - waifu2x_STOP_confirm = true; - return 0;//如果启用stop位,则直接return - } - //=============== 判断状态 ================ - if(ui->checkBox_ReProcFinFiles->isChecked()==false) - { - if(Table_model_image->item(currentRowNumber,1)->text().toLower().contains("finished")) - { - emit Send_progressbar_Add(); - continue; - } - } - if(Table_model_image->item(currentRowNumber,1)->text().toLower().contains("deleted")) - { - emit Send_progressbar_Add(); - continue; - } - //============== 判断权限 ===================== - if(file_isFilesFolderWritable_row_image(currentRowNumber)==false) - { - emit Send_progressbar_Add(); - continue; - } - //============ 自动跳过高分辨率文件 =================== - if(Image_Gif_AutoSkip_CustRes(currentRowNumber,false)==true) - { - emit Send_Table_image_ChangeStatus_rowNumInt_statusQString(currentRowNumber, "Skipped"); - continue; - } - //=========== 判断是不是apng ========== - if(APNG_isAnimatedPNG(currentRowNumber)==true) - { - //等待其他线程结束 - while (ThreadNumRunning > 0) - { - Delay_msec_sleep(750); - } - APNG_Main(currentRowNumber,true); - continue; - } - //========= - ThreadNumMax = ui->spinBox_ThreadNum_image->value();//获取image线程数量最大值 - //==================================================================================== - switch(ImageEngine) - { - case 0: - { - mutex_ThreadNumRunning.lock(); - ThreadNumRunning++;//线程数量统计+1 - mutex_ThreadNumRunning.unlock(); - QtConcurrent::run(this, &MainWindow::Waifu2x_NCNN_Vulkan_Image, currentRowNumber, false); - break; - } - case 1: - { - mutex_ThreadNumRunning.lock(); - ThreadNumRunning++;//线程数量统计+1 - mutex_ThreadNumRunning.unlock(); - QtConcurrent::run(this, &MainWindow::Waifu2x_Converter_Image, currentRowNumber, false); - break; - } - case 2: - { - mutex_ThreadNumRunning.lock(); - ThreadNumRunning++;//线程数量统计+1 - mutex_ThreadNumRunning.unlock(); - QtConcurrent::run(this, &MainWindow::SRMD_NCNN_Vulkan_Image, currentRowNumber, false); - break; - } - case 3: - { - mutex_ThreadNumRunning.lock(); - ThreadNumRunning++;//线程数量统计+1 - mutex_ThreadNumRunning.unlock(); - QtConcurrent::run(this, &MainWindow::Anime4k_Image, currentRowNumber, false); - break; - } - case 4: - { - mutex_ThreadNumRunning.lock(); - ThreadNumRunning++;//线程数量统计+1 - mutex_ThreadNumRunning.unlock(); - QtConcurrent::run(this, &MainWindow::Waifu2x_Caffe_Image, currentRowNumber, false); - break; - } - case 5: - { - mutex_ThreadNumRunning.lock(); - ThreadNumRunning++;//线程数量统计+1 - mutex_ThreadNumRunning.unlock(); - QtConcurrent::run(this, &MainWindow::Realsr_NCNN_Vulkan_Image, currentRowNumber, false); - break; - } - case 6: - { - mutex_ThreadNumRunning.lock(); - ThreadNumRunning++;//线程数量统计+1 - mutex_ThreadNumRunning.unlock(); - QtConcurrent::run(this, &MainWindow::SRMD_CUDA_Image, currentRowNumber, false); - break; - } - } - //================ - while (ThreadNumRunning >= ThreadNumMax) - { - Delay_msec_sleep(750); - } - } - } - while (ThreadNumRunning>0) - { - Delay_msec_sleep(750); - } - mutex_ThreadNumRunning.lock(); - ThreadNumRunning=0;//线程数量统计+1 - mutex_ThreadNumRunning.unlock(); - //========================================================= - // GIF 线程调度 - //=========================================================== - isForceRetryEnabled=false; - if(rowCount_gif>0) - { - double ScaleRatio_Gif = ui->doubleSpinBox_ScaleRatio_gif->value(); - bool isDoubleGifScaleRatio = (ScaleRatio_Gif != (int)ScaleRatio_Gif); - //===== - int GIFEngine = ui->comboBox_Engine_GIF->currentIndex(); - for ( int currentRowNumber = 0; currentRowNumber < rowCount_gif; currentRowNumber++ ) - { - if(waifu2x_STOP) - { - waifu2x_STOP_confirm = true; - return 0;//如果启用stop位,则直接return - } - //=============== 判断状态 ================ - if(ui->checkBox_ReProcFinFiles->isChecked()==false) - { - if(Table_model_gif->item(currentRowNumber,1)->text().toLower().contains("finished")) - { - emit Send_progressbar_Add(); - continue; - } - } - if(Table_model_gif->item(currentRowNumber,1)->text().toLower().contains("deleted")) - { - emit Send_progressbar_Add(); - continue; - } - //============== 判断权限 ===================== - if(file_isFilesFolderWritable_row_gif(currentRowNumber)==false) - { - emit Send_progressbar_Add(); - continue; - } - //============ 自动跳过高分辨率文件 =================== - if(Image_Gif_AutoSkip_CustRes(currentRowNumber,true)) - { - emit Send_Table_gif_ChangeStatus_rowNumInt_statusQString(currentRowNumber, "Skipped"); - continue; - } - //======================= 判断是不是apng ===================== - QString sourceFileFullPath = Table_model_gif->item(currentRowNumber,2)->text(); - QFileInfo fileinfo_sourceFileFullPath(sourceFileFullPath); - if(fileinfo_sourceFileFullPath.suffix().toLower() == "apng") - { - mutex_ThreadNumRunning.lock(); - ThreadNumRunning=1;//线程数量统计+1 - mutex_ThreadNumRunning.unlock(); - //======== - APNG_Main(currentRowNumber,false); - //======== - mutex_ThreadNumRunning.lock(); - ThreadNumRunning=0;//线程数量统计+1 - mutex_ThreadNumRunning.unlock(); - //======= - continue; - } - //=============== 判断是否需要加入自定义分辨率列表中 ============ - bool isNeedRemoveFromCustResList = false; - if(isDoubleGifScaleRatio) - { - isNeedRemoveFromCustResList = Gif_DoubleScaleRatioPrep(currentRowNumber); - } - //========= - mutex_ThreadNumRunning.lock(); - ThreadNumRunning=1;//线程数量统计+1 - mutex_ThreadNumRunning.unlock(); - //========= - //是GIF - switch(GIFEngine) - { - case 0: - { - Waifu2x_NCNN_Vulkan_GIF(currentRowNumber); - break; - } - case 1: - { - Waifu2x_Converter_GIF(currentRowNumber); - break; - } - case 2: - { - SRMD_NCNN_Vulkan_GIF(currentRowNumber); - break; - } - case 3: - { - Anime4k_GIF(currentRowNumber); - break; - } - case 4: - { - Waifu2x_Caffe_GIF(currentRowNumber); - break; - } - case 5: - { - Realsr_NCNN_Vulkan_GIF(currentRowNumber); - break; - } - case 6: - { - SRMD_CUDA_GIF(currentRowNumber); - break; - } - } - //======== - if(isNeedRemoveFromCustResList == true)Gif_RemoveFromCustResList(currentRowNumber); - //======== - mutex_ThreadNumRunning.lock(); - ThreadNumRunning=0;//线程数量统计+1 - mutex_ThreadNumRunning.unlock(); - } - } - //========================================================= - // 视频 线程调度 - //=========================================================== - if(rowCount_video>0) - { - double ScaleRatio_video = ui->doubleSpinBox_ScaleRatio_video->value(); - bool isDoubleVideoScaleRatio = (ScaleRatio_video != (int)ScaleRatio_video); - //======= - int VideoEngine = 0; - if(ui->checkBox_FrameInterpolationOnly_Video->isChecked()==true) - { - //仅插帧 - VideoEngine=99; - } - else - { - VideoEngine = ui->comboBox_Engine_Video->currentIndex(); - } - //======= - for ( int currentRowNumber = 0; currentRowNumbercheckBox_ReProcFinFiles->isChecked()==false) - { - if(Table_model_video->item(currentRowNumber,1)->text().toLower().contains("finished")) - { - emit Send_progressbar_Add(); - continue; - } - } - if(Table_model_video->item(currentRowNumber,1)->text().toLower().contains("deleted")) - { - emit Send_progressbar_Add(); - continue; - } - //============== 判断权限 ===================== - if(file_isFilesFolderWritable_row_video(currentRowNumber)==false) - { - emit Send_progressbar_Add(); - continue; - } - //============ 自动跳过高分辨率文件 =================== - if(Video_AutoSkip_CustRes(currentRowNumber)) - { - emit Send_Table_video_ChangeStatus_rowNumInt_statusQString(currentRowNumber, "Skipped"); - continue; - } - //=============== 判断是否需要加入自定义分辨率列表中 ============ - bool isNeedRemoveFromCustResList = false; - if(isDoubleVideoScaleRatio) - { - isNeedRemoveFromCustResList = video_DoubleScaleRatioPrep(currentRowNumber); - } - //============= 获取时长, 判断是否需要分段处理 ================= - mutex_ThreadNumRunning.lock(); - ThreadNumRunning=1;//线程数量统计+1 - mutex_ThreadNumRunning.unlock(); - switch(VideoEngine) - { - case 0://w2x ncnn vulkan - { - if(video_isNeedProcessBySegment(currentRowNumber)) - { - Waifu2x_NCNN_Vulkan_Video_BySegment(currentRowNumber); - } - else - { - Waifu2x_NCNN_Vulkan_Video(currentRowNumber); - } - break; - } - case 1://w2x converter - { - if(video_isNeedProcessBySegment(currentRowNumber)) - { - Waifu2x_Converter_Video_BySegment(currentRowNumber); - } - else - { - Waifu2x_Converter_Video(currentRowNumber); - } - break; - } - case 2://a4k - { - if(video_isNeedProcessBySegment(currentRowNumber)) - { - Anime4k_Video_BySegment(currentRowNumber); - } - else - { - Anime4k_Video(currentRowNumber); - } - break; - } - case 3://srmd ncnn vulkan - { - if(video_isNeedProcessBySegment(currentRowNumber)) - { - SRMD_NCNN_Vulkan_Video_BySegment(currentRowNumber); - } - else - { - SRMD_NCNN_Vulkan_Video(currentRowNumber); - } - break; - } - case 4://w2x caffe - { - if(video_isNeedProcessBySegment(currentRowNumber)) - { - Waifu2x_Caffe_Video_BySegment(currentRowNumber); - } - else - { - Waifu2x_Caffe_Video(currentRowNumber); - } - break; - } - case 5://realsr ncnn vulkan - { - if(video_isNeedProcessBySegment(currentRowNumber)) - { - Realsr_NCNN_Vulkan_Video_BySegment(currentRowNumber); - } - else - { - Realsr_NCNN_Vulkan_Video(currentRowNumber); - } - break; - } - case 6://srmd cuda - { - if(video_isNeedProcessBySegment(currentRowNumber)) - { - SRMD_CUDA_Video_BySegment(currentRowNumber); - } - else - { - SRMD_CUDA_Video(currentRowNumber); - } - break; - } - case 99://frame interpolation - { - if(video_isNeedProcessBySegment(currentRowNumber)) - { - FrameInterpolation_Video_BySegment(currentRowNumber); - } - else - { - FrameInterpolation_Video(currentRowNumber); - } - break; - } - } - //======= - if(isNeedRemoveFromCustResList == true)video_RemoveFromCustResList(currentRowNumber); - //======== - mutex_ThreadNumRunning.lock(); - ThreadNumRunning=0;//线程数量统计+1 - mutex_ThreadNumRunning.unlock(); - } - } - isForceRetryEnabled=true; - if(waifu2x_STOP) - { - waifu2x_STOP_confirm = true; - return 0;//如果启用stop位,则直接return - } - emit Send_Waifu2x_Finished(); - return 0; -} -/* -正常(非手动停止)时执行的结束代码 -*/ -void MainWindow::Waifu2x_Finished() -{ - //=================== 提示音 ================================= - QtConcurrent::run(this, &MainWindow::Play_NFSound); - //===================== 关机 ============================== - if(ui->comboBox_FinishAction->currentIndex()>0) - { - AutoFinishAction_Message(); - //关机前自动保存设置 - if(ui->checkBox_AutoSaveSettings->isChecked()) - { - emit Send_Settings_Save(); - } - QtConcurrent::run(this, &MainWindow::SystemShutDown_Countdown); - } - //==================== 进度条 ================================= - progressbar_SetToMax(Progressbar_MaxVal); - //============================================================= - emit Send_TextBrowser_NewMessage(tr("Process finished.")); - emit Send_SystemTray_NewMessage(tr("Process finished.")); - //============================================================ - Waifu2x_Finished_manual(); -} -/* -手动停止处理文件时执行的代码 -*/ -void MainWindow::Waifu2x_Finished_manual() -{ - TimeCostTimer->stop(); - //================== 界面恢复 =============================== - ui->checkBox_EnableVFI_Home->setEnabled(1); - if(ui->groupBox_FrameInterpolation->isChecked())ui->checkBox_FrameInterpolationOnly_Video->setEnabled(1); - ui->groupBox_FrameInterpolation->setEnabled(1); - ui->pushButton_BrowserFile->setEnabled(1); - ui->comboBox_ImageSaveFormat->setEnabled(1); - on_comboBox_ImageSaveFormat_currentIndexChanged(1); - emit Send_Table_EnableSorting(1);//启用文件列表的排序功能 - RemoveFile_FilesList_QAction_FileList->setEnabled(1); - Apply_CustRes_QAction_FileList->setEnabled(1); - Cancel_CustRes_QAction_FileList->setEnabled(1); - this->setAcceptDrops(1); - pushButton_Stop_setEnabled_self(0); - pushButton_Start_setEnabled_self(1); - if(ui->checkBox_ReplaceOriginalFile->isChecked()==false) - { - ui->groupBox_OutPut->setEnabled(1); - OutputSettingsArea_setEnabled(true); - ui->checkBox_DelOriginal->setEnabled(1); - } - ui->pushButton_ClearList->setEnabled(1); - ui->pushButton_RemoveItem->setEnabled(1); - ui->groupBox_Engine->setEnabled(1); - ui->groupBox_ScaleRaton_DenoiseLevel->setEnabled(1); - ui->checkBox_OptGIF->setEnabled(1); - ui->checkBox_ReProcFinFiles->setEnabled(1); - ui->pushButton_compatibilityTest->setEnabled(1); - ui->pushButton_ReadFileList->setEnabled(1); - ui->groupBox_video_settings->setEnabled(1); - if(ui->checkBox_DelOriginal->isChecked())QAction_checkBox_MoveToRecycleBin_checkBox_DelOriginal->setEnabled(1); - ui->pushButton_ForceRetry->setVisible(0); - ui->groupBox_AudioDenoise->setEnabled(1); - ui->checkBox_ProcessVideoBySegment->setEnabled(1); - if(ui->checkBox_ProcessVideoBySegment->isChecked()) - { - ui->spinBox_SegmentDuration->setEnabled(1); - } - on_comboBox_model_vulkan_currentIndexChanged(0); - isWaifu2xCaffeEnabled();//判断是否启用caffe图片风格combobox - emit Send_CurrentFileProgress_Stop(); - ui->checkBox_PreProcessImage->setEnabled(1); - ui->checkBox_AlwaysPreProcessAlphaPNG->setEnabled(1); - checkBox_ReplaceOriginalFile_setEnabled_True_Self(); - ui->checkBox_AutoDetectAlphaChannel->setEnabled(1); - ui->groupBox_CustRes->setEnabled(1); - ui->checkBox_DisableResize_gif->setEnabled(1); - //=================== 数值恢复 ================================ - ThreadNumMax = 0; - ThreadNumRunning = 0; - Progressbar_MaxVal = 0; - Progressbar_CurrentVal = 0; - TaskNumTotal=0; - TaskNumFinished=0; - NewTaskFinished=false; - ETA=0; - TimeCost=0; - ForceRetryCount=1; - isForceRetryEnabled=true; - isSuccessiveFailuresDetected_VFI=false; - //================= 杀死卡死在后台的进程 ================= - QStringList TaskNameList; - TaskNameList << "convert_waifu2xEX.exe"<<"ffmpeg_waifu2xEX.exe"<<"ffprobe_waifu2xEX.exe"<<"identify_waifu2xEX.exe"<<"gifsicle_waifu2xEX.exe"<<"waifu2x-ncnn-vulkan_waifu2xEX.exe" - <<"waifu2x-ncnn-vulkan-fp16p_waifu2xEX.exe"<<"Anime4K_waifu2xEX.exe"<<"waifu2x-caffe_waifu2xEX.exe"<<"srmd-ncnn-vulkan_waifu2xEX.exe"<<"realsr-ncnn-vulkan_waifu2xEX.exe" - <<"waifu2x-converter-cpp_waifu2xEX.exe"<<"sox_waifu2xEX.exe"<<"rife-ncnn-vulkan_waifu2xEX.exe"<<"cain-ncnn-vulkan_waifu2xEX.exe"<<"dain-ncnn-vulkan_waifu2xEX.exe" - <<"srmd-cuda_waifu2xEX.exe"<<"apngdis_waifu2xEX.exe"<<"apngasm_waifu2xEX.exe"; - KILL_TASK_QStringList(TaskNameList,true); - //================= 生成处理报告 ================= - ShowFileProcessSummary(); - //================= 打开输出文件夹 ==================== - if(ui->checkBox_AutoOpenOutputPath->isChecked()==true && ui->checkBox_OutPath_isEnabled->isChecked()==true)OpenOutputFolder(); - //====================== - FinishedProcessing_DN(); -} - -/* -移动文件到输出路径 -*/ -void MainWindow::MoveFileToOutputPath(QString Orginal,QString SourceFilePath) -{ - MoveFile_QMutex.lock(); - if(QFile::exists(Orginal)==false) - { - emit Send_TextBrowser_NewMessage(tr("Error! Original file [")+Orginal+tr("] does not exists.")); - MoveFile_QMutex.unlock(); - return; - } - QString Target_fullpPath=""; - QString Target_fileName=""; - QString Target_folder=""; - //确定文件名 - if(ui->checkBox_OutPath_KeepOriginalFileName->isChecked()) - { - QFileInfo fileinfo_source(SourceFilePath); - QString file_name = file_getBaseName(SourceFilePath); - QFileInfo fileinfo_Orginal(Orginal); - QString file_ext = fileinfo_Orginal.suffix(); - Target_fileName=file_name+"."+file_ext; - } - else - { - QFileInfo fileinfo_Orginal(Orginal); - Target_fileName = fileinfo_Orginal.fileName(); - } - //确定输出文件夹 - if(ui->checkBox_KeepParentFolder->isChecked()) - { - QFileInfo fileinfo_SourceFilePath(SourceFilePath); - QString folder_path_SourceFilePath = file_getFolderPath(fileinfo_SourceFilePath); - QStringList folder_path_SourceFilePath_QStringList = folder_path_SourceFilePath.split("/"); - QString ParentFolderName = folder_path_SourceFilePath_QStringList.last(); - //判断上级文件夹是不是磁盘根目录,若是则将文件夹名改为[盘符 Drive] - if(ParentFolderName.contains(":")) - { - ParentFolderName=ParentFolderName.replace(":"," Drive"); - } - Target_folder = OutPutFolder_main+"/"+ParentFolderName; - file_mkDir(Target_folder); - } - else - { - Target_folder=OutPutFolder_main; - } - //组装生成完整路径 - Target_fullpPath = Target_folder+"/"+Target_fileName; - //判断输出路径是否有和目标文件重名的 以及 是否启用了直接覆盖 - if(QFile::exists(Target_fullpPath)&&(ui->checkBox_OutPath_Overwrite->isChecked()==false)) - { - int suffix_int = 1; - QString Target_fullpPath_tmp = ""; - while(true) - { - QFileInfo fileinfo_tmp(Target_fullpPath); - QString file_name = file_getBaseName(Target_fullpPath); - QString file_ext = fileinfo_tmp.suffix(); - QString file_path = file_getFolderPath(fileinfo_tmp); - Target_fullpPath_tmp = file_path+"/"+file_name+"_"+QString::number(suffix_int,10)+"."+file_ext; - if(!QFile::exists(Target_fullpPath_tmp))break; - suffix_int++; - } - Target_fullpPath = Target_fullpPath_tmp; - } - if(ui->checkBox_OutPath_Overwrite->isChecked()==true) - { - QFile::remove(Target_fullpPath); - } - if(QFile::rename(Orginal,Target_fullpPath)==false) - { - emit Send_TextBrowser_NewMessage(tr("Error! Failed to move [")+Orginal+tr("] to [")+Target_fullpPath+"]"); - } - MoveFile_QMutex.unlock(); -} -/* -块大小调节 NCNN-Vulkan & Converter -*/ -/* -块大小调整按钮 + -*/ -int MainWindow::AddTileSize_NCNNVulkan_Converter(int OrginalTileSize) -{ - int TileSize = OrginalTileSize; - //判断是否为2的幂数 - if((TileSize&(TileSize-1))==0) - { - TileSize++; - } - if((TileSize&(TileSize-1))!=0) - { - for(int intNum=1; true; intNum++) - { - int pow_ =pow(2,intNum); - if(pow_>999999999) - { - return OrginalTileSize; - } - if(pow_>=TileSize) - { - return pow_; - } - } - } - return OrginalTileSize+1; -} -/* -块大小调整按钮 - -*/ -int MainWindow::MinusTileSize_NCNNVulkan_Converter(int OrginalTileSize) -{ - int TileSize = OrginalTileSize; - //判断是否为2的幂数 - if((TileSize&(TileSize-1))==0) - { - TileSize--; - } - if((TileSize&(TileSize-1))!=0) - { - for(int intNum=1; true; intNum++) - { - int pow_ =pow(2,intNum); - if(pow_>999999999) - { - return OrginalTileSize; - } - if(pow_>=TileSize) - { - return pow(2,intNum-1); - } - } - } - return OrginalTileSize-1; -} -/* -预读取引擎设定 -*/ -void MainWindow::PreLoad_Engines_Settings() -{ - //====================== - //Waifu2x-NCNN-Vulkan - //====================== - if(ui->comboBox_Engine_Image->currentIndex()==0) - { - Waifu2x_NCNN_Vulkan_PreLoad_Settings_Str = Waifu2x_NCNN_Vulkan_PreLoad_Settings(); - } - //====================== - //Waifu2x-Converter - //====================== - if(ui->comboBox_Engine_Image->currentIndex()==1||ui->comboBox_Engine_GIF->currentIndex()==1||ui->comboBox_Engine_Video->currentIndex()==1) - { - Waifu2xConverter_PreLoad_Settings_Str = Waifu2xConverter_PreLoad_Settings(); - } - //====================== - //SRMD-NCNN-Vulkan - //====================== - if(ui->comboBox_Engine_Image->currentIndex()==2) - { - SrmdNcnnVulkan_PreLoad_Settings_Str = SrmdNcnnVulkan_PreLoad_Settings(); - } - //====================== - //Anime4k - //====================== - if(ui->comboBox_Engine_Image->currentIndex()==3||ui->comboBox_Engine_GIF->currentIndex()==3||ui->comboBox_Engine_Video->currentIndex()==2) - { - Anime4k_PreLoad_Settings_Str = Anime4k_PreLoad_Settings(); - //预加载HDN等级 - if(ui->checkBox_ACNet_Anime4K->isChecked()&&ui->checkBox_HDNMode_Anime4k->isChecked()) - { - int HDNDenoiseLevel_value = 0; - if(ui->comboBox_Engine_Image->currentIndex()==3)//图片 - { - HDNDenoiseLevel_value = ui->spinBox_DenoiseLevel_image->value(); - if(HDNDenoiseLevel_value>=1&&HDNDenoiseLevel_value<=3) - { - HDNDenoiseLevel_image = " -L "+QString::number(HDNDenoiseLevel_value,10)+" "; - } - else - { - HDNDenoiseLevel_image = ""; - } - } - if(ui->comboBox_Engine_GIF->currentIndex()==3)//GIF - { - HDNDenoiseLevel_value = ui->spinBox_DenoiseLevel_gif->value(); - if(HDNDenoiseLevel_value>=1&&HDNDenoiseLevel_value<=3) - { - HDNDenoiseLevel_gif = " -L "+QString::number(HDNDenoiseLevel_value,10)+" "; - } - else - { - HDNDenoiseLevel_gif = ""; - } - } - if(ui->comboBox_Engine_Video->currentIndex()==2)//视频 - { - HDNDenoiseLevel_value = ui->spinBox_DenoiseLevel_video->value(); - if(HDNDenoiseLevel_value>=1&&HDNDenoiseLevel_value<=3) - { - HDNDenoiseLevel_video = " -L "+QString::number(HDNDenoiseLevel_value,10)+" "; - } - else - { - HDNDenoiseLevel_video = ""; - } - } - } - } - //====================== - //Waifu2x-Caffe - //====================== - if(isWaifu2xCaffeEnabled()) - { - Waifu2xCaffe_PreLoad_Settings_Str = Waifu2xCaffe_PreLoad_Settings(); - } - //====================== - //Realsr-NCNN-Vulkan - //====================== - if(ui->comboBox_Engine_Image->currentIndex()==5) - { - Realsr_NCNN_Vulkan_PreLoad_Settings_Str = Realsr_NCNN_Vulkan_PreLoad_Settings(); - } -} -/* -等待引擎IO结束 -1.读取初始文件列表 -2.获取初始文件大小列表 -3.等待数秒,再次读取文件大小判断是否发生IO,若没有IO则返回文件列表. -*/ -QStringList MainWindow::WaitForEngineIO(QStringList OutPutFilesFullPathList) -{ - QStringList ExistFileList; - QString fullpath_tmp; - for(int i = 0; i < OutPutFilesFullPathList.size(); i++) - { - fullpath_tmp= OutPutFilesFullPathList.at(i); - if(QFile::exists(fullpath_tmp)) - { - ExistFileList.append(fullpath_tmp); - } - } - QList FilesSizeList; - for(int i = 0; i < ExistFileList.size(); i++) - { - QFileInfo finfo(ExistFileList.at(i)); - FilesSizeList.append(finfo.size()); - } - do - { - Delay_sec_sleep(3); - QList FilesSizeList_tmp; - for(int i = 0; i < ExistFileList.size(); i++) - { - QFileInfo finfo(ExistFileList.at(i)); - FilesSizeList_tmp.append(finfo.size()); - } - if(FilesSizeList_tmp == FilesSizeList) - { - break; - } - else - { - FilesSizeList = FilesSizeList_tmp; - } - } - while (true); - return ExistFileList; -} -QStringList MainWindow::WaitForEngineIO_NcnnVulkan(QString OutputFolderFullPath) -{ - QStringList ExistFileList = file_getFileNames_in_Folder_nofilter(OutputFolderFullPath); - QString fullpath_tmp; - QList FilesSizeList; - for(int i = 0; i < ExistFileList.size(); i++) - { - QFileInfo finfo(OutputFolderFullPath+"/"+ExistFileList.at(i)); - FilesSizeList.append(finfo.size()); - } - do - { - Delay_sec_sleep(3); - QList FilesSizeList_tmp; - for(int i = 0; i < ExistFileList.size(); i++) - { - QFileInfo finfo(OutputFolderFullPath+"/"+ExistFileList.at(i)); - FilesSizeList_tmp.append(finfo.size()); - } - if(FilesSizeList_tmp == FilesSizeList) - { - break; - } - else - { - FilesSizeList = FilesSizeList_tmp; - } - } - while (true); - return ExistFileList; -} -/* -恢复拆分帧文件夹 -*/ -void MainWindow::Restore_SplitFramesFolderPath(QString SplitFramesFolderPath, QStringList GPU_SplitFramesFolderPath_List) -{ - if(file_isDirExist(SplitFramesFolderPath)==false)return; - for(int x = 0; x < GPU_SplitFramesFolderPath_List.size(); x++) - { - QString GPUfolder = GPU_SplitFramesFolderPath_List.at(x); - if(file_isDirExist(GPUfolder)==false)continue; - QStringList file_waitformove = file_getFileNames_in_Folder_nofilter(GPUfolder); - for(int i = 0; i < file_waitformove.size(); i++) - { - QString FileName = file_waitformove.at(i); - QFile::remove(SplitFramesFolderPath+"/"+FileName); - QFile::rename(GPUfolder+"/"+FileName,SplitFramesFolderPath+"/"+FileName); - } - file_DelDir(GPUfolder); - } -} -/* -复制一个文件夹的内容到另一个文件夹 Ncnn Vulkan -*/ -void MainWindow::file_MoveFiles_Folder_NcnnVulkanFolderProcess(QString Old_folder, QString New_folder, bool Delete_) -{ - if(file_isDirExist(Old_folder)==false || file_isDirExist(New_folder)==false)return; - QStringList file_waitformove = file_getFileNames_in_Folder_nofilter(Old_folder); - QString NewName=""; - QString FileName=""; - for(int i = 0; i < file_waitformove.size(); i++) - { - FileName = file_waitformove.at(i); - if(FileName.count(".")>1) - { - NewName = file_getBaseName(Old_folder+"/"+FileName); - do - { - if(NewName.count(".")<2)break; - NewName = file_getBaseName(Old_folder+"/"+NewName); - } - while(true); - QFile::rename(Old_folder+"/"+FileName,Old_folder+"/"+NewName); - FileName = NewName; - } - QFile::remove(New_folder+"/"+FileName); - QFile::rename(Old_folder+"/"+FileName,New_folder+"/"+FileName); - } - if(Delete_)file_DelDir(Old_folder); -} -/* -//杀死进程,可选管理员 -bool MainWindow::KILL_TASK_(QString TaskName,bool RequestAdmin) -{ - TaskName=TaskName.trimmed(); - if(TaskName=="")return false; - //=============== - QProcess Get_tasklist; - Get_tasklist.start("tasklist /fo csv"); - while(!Get_tasklist.waitForStarted(500)) {} - while(!Get_tasklist.waitForFinished(500)) {} - if(Get_tasklist.readAllStandardOutput().contains(TaskName.toUtf8())==false) - { - return true; - } - //=============== - QProcess Close; - Close.start("taskkill /f /t /fi \"imagename eq "+TaskName+"\""); - while(!Close.waitForStarted(500)) {} - while(!Close.waitForFinished(500)) {} - Get_tasklist.start("tasklist /fo csv"); - while(!Get_tasklist.waitForStarted(500)) {} - while(!Get_tasklist.waitForFinished(500)) {} - if(Get_tasklist.readAllStandardOutput().contains(TaskName.toUtf8()) && RequestAdmin==true) - { - ExecuteCMD_batFile("taskkill /f /t /fi \"imagename eq "+TaskName+"\"",true); - return true; - } - return true; -}*/ -/* -杀死进程列表,可选管理员 -*/ -bool MainWindow::KILL_TASK_QStringList(QStringList TaskNameList,bool RequestAdmin) -{ - TaskNameList.removeAll(""); - if(TaskNameList.isEmpty())return false; - //=============== - QProcess Get_tasklist; - Get_tasklist.start("tasklist /fo csv"); - while(!Get_tasklist.waitForStarted(500)) {} - while(!Get_tasklist.waitForFinished(500)) {} - QString RunningTaskList = Get_tasklist.readAllStandardOutput(); - //=== - QString TaskName_tmp; - QStringList TaskNameList_tmp = TaskNameList; - //=== - for(int i=0; icheckBox_SummaryPopup->isChecked()==false) - { - int rowCount_image = Table_model_image->rowCount(); - int rowCount_gif = Table_model_gif->rowCount(); - int rowCount_video = Table_model_video->rowCount(); - //=== - int NumOfFailedFiles = 0; - QString FailedFilesList = "\n"; - //检查图片文件列表 - for ( int RowNum = 0; RowNum < rowCount_image; RowNum++ ) - { - QString CurrentRowStatus = Table_model_image->item(RowNum,1)->text().toLower(); - if(CurrentRowStatus.contains("fail")) - { - NumOfFailedFiles++; - FailedFilesList.append(tr("Failed: [")+Table_model_image->item(RowNum,2)->text()+"]\n"); - continue; - } - } - //检查GIF文件列表 - for ( int RowNum = 0; RowNum < rowCount_gif; RowNum++ ) - { - QString CurrentRowStatus = Table_model_gif->item(RowNum,1)->text().toLower(); - if(CurrentRowStatus.contains("fail")) - { - NumOfFailedFiles++; - FailedFilesList.append(tr("Failed: [")+Table_model_gif->item(RowNum,2)->text()+"]\n"); - continue; - } - } - //检查视频文件列表 - for ( int RowNum = 0; RowNum < rowCount_video; RowNum++ ) - { - QString CurrentRowStatus = Table_model_video->item(RowNum,1)->text().toLower(); - if(CurrentRowStatus.contains("fail")) - { - NumOfFailedFiles++; - FailedFilesList.append(tr("Failed: [")+Table_model_video->item(RowNum,2)->text()+"]\n"); - continue; - } - } - //输出失败文件列表 - if(NumOfFailedFiles>0) - { - emit Send_TextBrowser_NewMessage(FailedFilesList); - } - return; - } - int rowCount_image = Table_model_image->rowCount(); - int rowCount_gif = Table_model_gif->rowCount(); - int rowCount_video = Table_model_video->rowCount(); - //=== - int NumOfFinishedFiles = 0; - int NumOfSkippedFiles = 0; - int NumOfFailedFiles = 0; - QString FailedFilesList = "\n"; - //=== - //检查图片文件列表 - for ( int RowNum = 0; RowNum < rowCount_image; RowNum++ ) - { - QString CurrentRowStatus = Table_model_image->item(RowNum,1)->text().toLower(); - if(CurrentRowStatus.contains("finished")) - { - NumOfFinishedFiles++; - continue; - } - if(CurrentRowStatus.contains("fail")) - { - NumOfFailedFiles++; - FailedFilesList.append(tr("Failed: [")+Table_model_image->item(RowNum,2)->text()+"]\n"); - continue; - } - if(ui->checkBox_AutoSkip_CustomRes->isChecked() && CurrentRowStatus.contains("skipped")) - { - NumOfSkippedFiles++; - continue; - } - } - //检查GIF文件列表 - for ( int RowNum = 0; RowNum < rowCount_gif; RowNum++ ) - { - QString CurrentRowStatus = Table_model_gif->item(RowNum,1)->text().toLower(); - if(CurrentRowStatus.contains("finished")) - { - NumOfFinishedFiles++; - continue; - } - if(CurrentRowStatus.contains("fail")) - { - NumOfFailedFiles++; - FailedFilesList.append(tr("Failed: [")+Table_model_gif->item(RowNum,2)->text()+"]\n"); - continue; - } - if(ui->checkBox_AutoSkip_CustomRes->isChecked() && CurrentRowStatus.contains("skipped")) - { - NumOfSkippedFiles++; - continue; - } - } - //检查视频文件列表 - for ( int RowNum = 0; RowNum < rowCount_video; RowNum++ ) - { - QString CurrentRowStatus = Table_model_video->item(RowNum,1)->text().toLower(); - if(CurrentRowStatus.contains("finished")) - { - NumOfFinishedFiles++; - continue; - } - if(CurrentRowStatus.contains("fail")) - { - NumOfFailedFiles++; - FailedFilesList.append(tr("Failed: [")+Table_model_video->item(RowNum,2)->text()+"]\n"); - continue; - } - if(ui->checkBox_AutoSkip_CustomRes->isChecked() && CurrentRowStatus.contains("skipped")) - { - NumOfSkippedFiles++; - continue; - } - } - //输出报告 - QString Summary_qstr = tr("Total: ")+QString("%1").arg((rowCount_image+rowCount_gif+rowCount_video))+"\n\n"+tr("Finished: ")+QString("%1").arg(NumOfFinishedFiles)+"\n\n"+tr("Failed: ")+QString("%1").arg(NumOfFailedFiles); - if(ui->checkBox_AutoSkip_CustomRes->isChecked()) - { - Summary_qstr.append("\n\n"+tr("Skipped: ")+QString("%1").arg(NumOfSkippedFiles)); - } - if(NumOfFailedFiles>0) - { - emit Send_TextBrowser_NewMessage(FailedFilesList); - Summary_qstr.append("\n\n"+tr("Info of failed files will be listed in the text browser at the bottom of the GUI.")); - } - //=== - QMessageBox *MSG_Summary = new QMessageBox(); - MSG_Summary->setWindowTitle(tr("Summary")); - MSG_Summary->setText(Summary_qstr); - MSG_Summary->setIcon(QMessageBox::Information); - MSG_Summary->setModal(true); - MSG_Summary->show(); - //=== - return; -} +/* + Copyright (C) 2021 Aaron Feng + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU Affero General Public License as published + by the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program. If not, see . + + My Github homepage: https://github.com/AaronFeng753 +*/ + +#include "mainwindow.h" +#include "ui_mainwindow.h" +/* +开始处理文件的按钮 +*/ +void MainWindow::on_pushButton_Start_clicked() +{ + /* + * 判断是否启用自定义输出路径 + * 判断输出路径是否合法 + */ + if(ui->checkBox_OutPath_isEnabled->isChecked()) + { + QString tmp = ui->lineEdit_outputPath->text(); + tmp = tmp.trimmed(); + if(tmp=="") + { + //===== + QMessageBox *MSG = new QMessageBox(); + MSG->setWindowTitle(tr("Error")); + MSG->setText(tr("Output path is empty.")); + MSG->setIcon(QMessageBox::Warning); + MSG->setModal(true); + MSG->show(); + //===== + emit Send_TextBrowser_NewMessage(tr("Output path is empty.")); + return; + } + tmp = tmp.replace("\\","/"); + tmp = tmp.replace("\\\\","/"); + tmp = tmp.replace("//","/"); + if(tmp.right(1)=="/") + { + tmp = tmp.left(tmp.length() - 1); + } + QFileInfo fileinfo_tmp(tmp); + if(file_isDirExist(tmp)&&fileinfo_tmp.isDir()&&file_isDirWritable(tmp)) + { + OutPutFolder_main = tmp; + } + else + { + //===== + QMessageBox *MSG = new QMessageBox(); + MSG->setWindowTitle(tr("Error")); + MSG->setText(tr("Invalid output path.\n\nOr do not have sufficient permissions to write files to the output path, you might need to grant administrator permissions to this software.")); + MSG->setIcon(QMessageBox::Warning); + MSG->setModal(true); + MSG->show(); + //===== + emit Send_TextBrowser_NewMessage(tr("Invalid output path.")); + return; + } + } + //============================= + // 判断文件列表是否为空 + //============================= + if(Table_model_image->rowCount()==0&&Table_model_gif->rowCount()==0&&Table_model_video->rowCount()==0) + { + QMessageBox *MSG = new QMessageBox(); + MSG->setWindowTitle(tr("Error")); + MSG->setText(tr("Unable to start processing files: The file list is empty.")); + MSG->setIcon(QMessageBox::Warning); + MSG->setModal(true); + MSG->show(); + return; + } + //====================================== + // 判断文件列表是否全部处理完成 + //====================================== + int rowCount_image = Table_model_image->rowCount(); + int rowCount_image_cache = rowCount_image; + int rowCount_gif = Table_model_gif->rowCount(); + int rowCount_gif_cache = rowCount_gif; + int rowCount_video = Table_model_video->rowCount(); + int rowCount_video_cache = rowCount_video; + //检查图片文件列表 + for ( int RowNum = 0; RowNum < rowCount_image; RowNum++ ) + { + if(ui->checkBox_ReProcFinFiles->isChecked()==false) + { + if(Table_model_image->item(RowNum,1)->text().toLower().contains("finished")) + { + rowCount_image_cache--; + continue; + } + } + if(Table_model_image->item(RowNum,1)->text().toLower().contains("deleted")) + { + rowCount_image_cache--; + continue; + } + } + //检查GIF文件列表 + for ( int RowNum = 0; RowNum < rowCount_gif; RowNum++ ) + { + if(ui->checkBox_ReProcFinFiles->isChecked()==false) + { + if(Table_model_gif->item(RowNum,1)->text().toLower().contains("finished")) + { + rowCount_gif_cache--; + continue; + } + } + if(Table_model_gif->item(RowNum,1)->text().toLower().contains("deleted")) + { + rowCount_gif_cache--; + continue; + } + } + //检查视频文件列表 + for ( int RowNum = 0; RowNum < rowCount_video; RowNum++ ) + { + if(ui->checkBox_ReProcFinFiles->isChecked()==false) + { + if(Table_model_video->item(RowNum,1)->text().toLower().contains("finished")) + { + rowCount_video_cache--; + continue; + } + } + if(Table_model_video->item(RowNum,1)->text().toLower().contains("deleted")) + { + rowCount_video_cache--; + continue; + } + } + //判断是否剩余可处理的文件 + if(rowCount_image_cache+rowCount_gif_cache+rowCount_video_cache==0) + { + QMessageBox *MSG = new QMessageBox(); + MSG->setWindowTitle(tr("Error")); + MSG->setText(tr("Unable to start processing files: All files in Files list are Finished or Deleted.\n\nTip: You can enable [Re-process finished files] if you wanna re-process finished files.")); + MSG->setIcon(QMessageBox::Warning); + MSG->setModal(true); + MSG->show(); + return; + } + //正式开始处理列表内的文件 + Table_ChangeAllStatusToWaiting();//将table内没开始处理或者被打断的条目状态变为等待中 + //============== 判断是否需要隐藏ETA和剩余时间 ================ + if(Table_model_gif->rowCount()!=0||Table_model_video->rowCount()!=0) + { + ui->label_TimeRemain->setVisible(0); + ui->label_ETA->setVisible(0); + } + else + { + ui->label_TimeRemain->setVisible(1); + ui->label_ETA->setVisible(1); + } + //============== 数值初始化 ================== + waifu2x_STOP = false; + waifu2x_STOP_confirm = false; + ThreadNumMax = 0; + ThreadNumRunning = 0; + Progressbar_MaxVal = 0; + Progressbar_CurrentVal = 0; + TaskNumTotal=0; + TaskNumFinished=0; + NewTaskFinished=false; + ETA=0; + isForceRetryClicked=false; + ForceRetryCount=1; + isForceRetryEnabled=true; + isSuccessiveFailuresDetected_VFI=false; + //============== 界面初始化 ====================== + ui->checkBox_EnableVFI_Home->setEnabled(0); + ui->checkBox_FrameInterpolationOnly_Video->setEnabled(0); + ui->groupBox_FrameInterpolation->setEnabled(0); + ui->pushButton_BrowserFile->setEnabled(0); + ui->comboBox_ImageSaveFormat->setEnabled(0); + ui->spinBox_ImageQualityLevel->setEnabled(0); + emit Send_Table_EnableSorting(0);//启用文件列表的排序功能 + RemoveFile_FilesList_QAction_FileList->setEnabled(0); + Apply_CustRes_QAction_FileList->setEnabled(0); + Cancel_CustRes_QAction_FileList->setEnabled(0); + this->setAcceptDrops(0);//禁止drop file + pushButton_Stop_setEnabled_self(1);//启用stop button + pushButton_Start_setEnabled_self(0);//禁用start button + OutputSettingsArea_setEnabled(false); + ui->pushButton_ClearList->setEnabled(0); + ui->pushButton_RemoveItem->setEnabled(0); + ui->groupBox_Engine->setEnabled(0); + ui->groupBox_ScaleRaton_DenoiseLevel->setEnabled(0); + ui->checkBox_OptGIF->setEnabled(0); + ui->checkBox_DelOriginal->setEnabled(0); + ui->checkBox_ReProcFinFiles->setEnabled(0); + ui->pushButton_compatibilityTest->setEnabled(0); + ui->pushButton_ReadFileList->setEnabled(0); + progressbar_clear(); + ui->label_TimeCost->setText(tr("Time taken:NULL")); + ui->label_ETA->setText(tr("ETA:NULL")); + ui->label_TimeRemain->setText(tr("Time remaining:NULL")); + ui->groupBox_video_settings->setEnabled(0); + QAction_checkBox_MoveToRecycleBin_checkBox_DelOriginal->setEnabled(0); + ui->pushButton_ForceRetry->setVisible(1); + ui->checkBox_AutoDetectAlphaChannel->setEnabled(0); + ui->groupBox_AudioDenoise->setEnabled(0); + ui->checkBox_ProcessVideoBySegment->setEnabled(0); + ui->spinBox_SegmentDuration->setEnabled(0); + ui->comboBox_ImageStyle->setEnabled(0); + ui->checkBox_PreProcessImage->setEnabled(0); + ui->checkBox_AlwaysPreProcessAlphaPNG->setEnabled(0); + on_lineEdit_GPUs_Anime4k_editingFinished(); + on_lineEdit_MultiGPUInfo_Waifu2xCaffe_editingFinished(); + ui->checkBox_ReplaceOriginalFile->setEnabled(0); + ui->groupBox_CustRes->setEnabled(0); + ui->checkBox_DisableResize_gif->setEnabled(0); + //========== + TimeCost=0; + TimeCostTimer->start(1000); + emit Send_TextBrowser_NewMessage(tr("Start processing files.")); + //========== + PreLoad_Engines_Settings();//预读取引擎设定 + ui->comboBox_ImageStyle_Waifu2xCaffe->setEnabled(0); + //========== + Waifu2xMain = QtConcurrent::run(this, &MainWindow::Waifu2xMainThread);//启动waifu2x 主线程 +} +/* +主调度线程 +*/ +int MainWindow::Waifu2xMainThread() +{ + //在table中的状态修改完成前一直block,防止偶发的多线程错误 + QMutex_Table_ChangeAllStatusToWaiting.lock(); + NULL; + QMutex_Table_ChangeAllStatusToWaiting.unlock(); + //======================= + int rowCount_image = Table_model_image->rowCount(); + int rowCount_gif = Table_model_gif->rowCount(); + int rowCount_video = Table_model_video->rowCount(); + //======================= + Progressbar_MaxVal = rowCount_image + rowCount_gif + rowCount_video; + Progressbar_CurrentVal = 0; + TaskNumFinished=0; + emit Send_PrograssBar_Range_min_max(0, Progressbar_MaxVal); + if(rowCount_image>0) + { + int ImageEngine = ui->comboBox_Engine_Image->currentIndex(); + for ( int currentRowNumber = 0; currentRowNumber < rowCount_image; currentRowNumber++ ) + { + if(waifu2x_STOP) + { + while (ThreadNumRunning > 0) + { + Delay_msec_sleep(750); + } + waifu2x_STOP_confirm = true; + return 0;//如果启用stop位,则直接return + } + //=============== 判断状态 ================ + if(ui->checkBox_ReProcFinFiles->isChecked()==false) + { + if(Table_model_image->item(currentRowNumber,1)->text().toLower().contains("finished")) + { + emit Send_progressbar_Add(); + continue; + } + } + if(Table_model_image->item(currentRowNumber,1)->text().toLower().contains("deleted")) + { + emit Send_progressbar_Add(); + continue; + } + //============== 判断权限 ===================== + if(file_isFilesFolderWritable_row_image(currentRowNumber)==false) + { + emit Send_progressbar_Add(); + continue; + } + //============ 自动跳过高分辨率文件 =================== + if(Image_Gif_AutoSkip_CustRes(currentRowNumber,false)==true) + { + emit Send_Table_image_ChangeStatus_rowNumInt_statusQString(currentRowNumber, "Skipped"); + continue; + } + //=========== 判断是不是apng ========== + if(APNG_isAnimatedPNG(currentRowNumber)==true) + { + //等待其他线程结束 + while (ThreadNumRunning > 0) + { + Delay_msec_sleep(750); + } + APNG_Main(currentRowNumber,true); + continue; + } + //========= + ThreadNumMax = ui->spinBox_ThreadNum_image->value();//获取image线程数量最大值 + //==================================================================================== + switch(ImageEngine) + { + case 0: + { + mutex_ThreadNumRunning.lock(); + ThreadNumRunning++;//线程数量统计+1 + mutex_ThreadNumRunning.unlock(); + QtConcurrent::run(this, &MainWindow::Waifu2x_NCNN_Vulkan_Image, currentRowNumber, false); + break; + } + case 1: + { + mutex_ThreadNumRunning.lock(); + ThreadNumRunning++;//线程数量统计+1 + mutex_ThreadNumRunning.unlock(); + QtConcurrent::run(this, &MainWindow::Waifu2x_Converter_Image, currentRowNumber, false); + break; + } + case 2: + { + mutex_ThreadNumRunning.lock(); + ThreadNumRunning++;//线程数量统计+1 + mutex_ThreadNumRunning.unlock(); + QtConcurrent::run(this, &MainWindow::SRMD_NCNN_Vulkan_Image, currentRowNumber, false); + break; + } + case 3: + { + mutex_ThreadNumRunning.lock(); + ThreadNumRunning++;//线程数量统计+1 + mutex_ThreadNumRunning.unlock(); + QtConcurrent::run(this, &MainWindow::Anime4k_Image, currentRowNumber, false); + break; + } + case 4: + { + mutex_ThreadNumRunning.lock(); + ThreadNumRunning++;//线程数量统计+1 + mutex_ThreadNumRunning.unlock(); + QtConcurrent::run(this, &MainWindow::Waifu2x_Caffe_Image, currentRowNumber, false); + break; + } + case 5: + { + mutex_ThreadNumRunning.lock(); + ThreadNumRunning++;//线程数量统计+1 + mutex_ThreadNumRunning.unlock(); + QtConcurrent::run(this, &MainWindow::Realsr_NCNN_Vulkan_Image, currentRowNumber, false); + break; + } + case 6: + { + mutex_ThreadNumRunning.lock(); + ThreadNumRunning++;//线程数量统计+1 + mutex_ThreadNumRunning.unlock(); + QtConcurrent::run(this, &MainWindow::SRMD_CUDA_Image, currentRowNumber, false); + break; + } + } + //================ + while (ThreadNumRunning >= ThreadNumMax) + { + Delay_msec_sleep(750); + } + } + } + while (ThreadNumRunning>0) + { + Delay_msec_sleep(750); + } + mutex_ThreadNumRunning.lock(); + ThreadNumRunning=0;//线程数量统计+1 + mutex_ThreadNumRunning.unlock(); + //========================================================= + // GIF 线程调度 + //=========================================================== + isForceRetryEnabled=false; + if(rowCount_gif>0) + { + double ScaleRatio_Gif = ui->doubleSpinBox_ScaleRatio_gif->value(); + bool isDoubleGifScaleRatio = (ScaleRatio_Gif != (int)ScaleRatio_Gif); + //===== + int GIFEngine = ui->comboBox_Engine_GIF->currentIndex(); + for ( int currentRowNumber = 0; currentRowNumber < rowCount_gif; currentRowNumber++ ) + { + if(waifu2x_STOP) + { + waifu2x_STOP_confirm = true; + return 0;//如果启用stop位,则直接return + } + //=============== 判断状态 ================ + if(ui->checkBox_ReProcFinFiles->isChecked()==false) + { + if(Table_model_gif->item(currentRowNumber,1)->text().toLower().contains("finished")) + { + emit Send_progressbar_Add(); + continue; + } + } + if(Table_model_gif->item(currentRowNumber,1)->text().toLower().contains("deleted")) + { + emit Send_progressbar_Add(); + continue; + } + //============== 判断权限 ===================== + if(file_isFilesFolderWritable_row_gif(currentRowNumber)==false) + { + emit Send_progressbar_Add(); + continue; + } + //============ 自动跳过高分辨率文件 =================== + if(Image_Gif_AutoSkip_CustRes(currentRowNumber,true)) + { + emit Send_Table_gif_ChangeStatus_rowNumInt_statusQString(currentRowNumber, "Skipped"); + continue; + } + //======================= 判断是不是apng ===================== + QString sourceFileFullPath = Table_model_gif->item(currentRowNumber,2)->text(); + QFileInfo fileinfo_sourceFileFullPath(sourceFileFullPath); + if(fileinfo_sourceFileFullPath.suffix().toLower() == "apng") + { + mutex_ThreadNumRunning.lock(); + ThreadNumRunning=1;//线程数量统计+1 + mutex_ThreadNumRunning.unlock(); + //======== + APNG_Main(currentRowNumber,false); + //======== + mutex_ThreadNumRunning.lock(); + ThreadNumRunning=0;//线程数量统计+1 + mutex_ThreadNumRunning.unlock(); + //======= + continue; + } + //=============== 判断是否需要加入自定义分辨率列表中 ============ + bool isNeedRemoveFromCustResList = false; + if(isDoubleGifScaleRatio) + { + isNeedRemoveFromCustResList = Gif_DoubleScaleRatioPrep(currentRowNumber); + } + //========= + mutex_ThreadNumRunning.lock(); + ThreadNumRunning=1;//线程数量统计+1 + mutex_ThreadNumRunning.unlock(); + //========= + //是GIF + switch(GIFEngine) + { + case 0: + { + Waifu2x_NCNN_Vulkan_GIF(currentRowNumber); + break; + } + case 1: + { + Waifu2x_Converter_GIF(currentRowNumber); + break; + } + case 2: + { + SRMD_NCNN_Vulkan_GIF(currentRowNumber); + break; + } + case 3: + { + Anime4k_GIF(currentRowNumber); + break; + } + case 4: + { + Waifu2x_Caffe_GIF(currentRowNumber); + break; + } + case 5: + { + Realsr_NCNN_Vulkan_GIF(currentRowNumber); + break; + } + case 6: + { + SRMD_CUDA_GIF(currentRowNumber); + break; + } + } + //======== + if(isNeedRemoveFromCustResList == true)Gif_RemoveFromCustResList(currentRowNumber); + //======== + mutex_ThreadNumRunning.lock(); + ThreadNumRunning=0;//线程数量统计+1 + mutex_ThreadNumRunning.unlock(); + } + } + //========================================================= + // 视频 线程调度 + //=========================================================== + if(rowCount_video>0) + { + double ScaleRatio_video = ui->doubleSpinBox_ScaleRatio_video->value(); + bool isDoubleVideoScaleRatio = (ScaleRatio_video != (int)ScaleRatio_video); + //======= + int VideoEngine = 0; + if(ui->checkBox_FrameInterpolationOnly_Video->isChecked()==true) + { + //仅插帧 + VideoEngine=99; + } + else + { + VideoEngine = ui->comboBox_Engine_Video->currentIndex(); + } + //======= + for ( int currentRowNumber = 0; currentRowNumbercheckBox_ReProcFinFiles->isChecked()==false) + { + if(Table_model_video->item(currentRowNumber,1)->text().toLower().contains("finished")) + { + emit Send_progressbar_Add(); + continue; + } + } + if(Table_model_video->item(currentRowNumber,1)->text().toLower().contains("deleted")) + { + emit Send_progressbar_Add(); + continue; + } + //============== 判断权限 ===================== + if(file_isFilesFolderWritable_row_video(currentRowNumber)==false) + { + emit Send_progressbar_Add(); + continue; + } + //============ 自动跳过高分辨率文件 =================== + if(Video_AutoSkip_CustRes(currentRowNumber)) + { + emit Send_Table_video_ChangeStatus_rowNumInt_statusQString(currentRowNumber, "Skipped"); + continue; + } + //=============== 判断是否需要加入自定义分辨率列表中 ============ + bool isNeedRemoveFromCustResList = false; + if(isDoubleVideoScaleRatio) + { + isNeedRemoveFromCustResList = video_DoubleScaleRatioPrep(currentRowNumber); + } + //============= 获取时长, 判断是否需要分段处理 ================= + mutex_ThreadNumRunning.lock(); + ThreadNumRunning=1;//线程数量统计+1 + mutex_ThreadNumRunning.unlock(); + switch(VideoEngine) + { + case 0://w2x ncnn vulkan + { + if(video_isNeedProcessBySegment(currentRowNumber)) + { + Waifu2x_NCNN_Vulkan_Video_BySegment(currentRowNumber); + } + else + { + Waifu2x_NCNN_Vulkan_Video(currentRowNumber); + } + break; + } + case 1://w2x converter + { + if(video_isNeedProcessBySegment(currentRowNumber)) + { + Waifu2x_Converter_Video_BySegment(currentRowNumber); + } + else + { + Waifu2x_Converter_Video(currentRowNumber); + } + break; + } + case 2://a4k + { + if(video_isNeedProcessBySegment(currentRowNumber)) + { + Anime4k_Video_BySegment(currentRowNumber); + } + else + { + Anime4k_Video(currentRowNumber); + } + break; + } + case 3://srmd ncnn vulkan + { + if(video_isNeedProcessBySegment(currentRowNumber)) + { + SRMD_NCNN_Vulkan_Video_BySegment(currentRowNumber); + } + else + { + SRMD_NCNN_Vulkan_Video(currentRowNumber); + } + break; + } + case 4://w2x caffe + { + if(video_isNeedProcessBySegment(currentRowNumber)) + { + Waifu2x_Caffe_Video_BySegment(currentRowNumber); + } + else + { + Waifu2x_Caffe_Video(currentRowNumber); + } + break; + } + case 5://realsr ncnn vulkan + { + if(video_isNeedProcessBySegment(currentRowNumber)) + { + Realsr_NCNN_Vulkan_Video_BySegment(currentRowNumber); + } + else + { + Realsr_NCNN_Vulkan_Video(currentRowNumber); + } + break; + } + case 6://srmd cuda + { + if(video_isNeedProcessBySegment(currentRowNumber)) + { + SRMD_CUDA_Video_BySegment(currentRowNumber); + } + else + { + SRMD_CUDA_Video(currentRowNumber); + } + break; + } + case 99://frame interpolation + { + if(video_isNeedProcessBySegment(currentRowNumber)) + { + FrameInterpolation_Video_BySegment(currentRowNumber); + } + else + { + FrameInterpolation_Video(currentRowNumber); + } + break; + } + } + //======= + if(isNeedRemoveFromCustResList == true)video_RemoveFromCustResList(currentRowNumber); + //======== + mutex_ThreadNumRunning.lock(); + ThreadNumRunning=0;//线程数量统计+1 + mutex_ThreadNumRunning.unlock(); + } + } + isForceRetryEnabled=true; + if(waifu2x_STOP) + { + waifu2x_STOP_confirm = true; + return 0;//如果启用stop位,则直接return + } + emit Send_Waifu2x_Finished(); + return 0; +} +/* +正常(非手动停止)时执行的结束代码 +*/ +void MainWindow::Waifu2x_Finished() +{ + //=================== 提示音 ================================= + QtConcurrent::run(this, &MainWindow::Play_NFSound); + //===================== 关机 ============================== + if(ui->comboBox_FinishAction->currentIndex()>0) + { + AutoFinishAction_Message(); + //关机前自动保存设置 + if(ui->checkBox_AutoSaveSettings->isChecked()) + { + emit Send_Settings_Save(); + } + QtConcurrent::run(this, &MainWindow::SystemShutDown_Countdown); + } + //==================== 进度条 ================================= + progressbar_SetToMax(Progressbar_MaxVal); + //============================================================= + emit Send_TextBrowser_NewMessage(tr("Process finished.")); + emit Send_SystemTray_NewMessage(tr("Process finished.")); + //============================================================ + Waifu2x_Finished_manual(); +} +/* +手动停止处理文件时执行的代码 +*/ +void MainWindow::Waifu2x_Finished_manual() +{ + TimeCostTimer->stop(); + //================== 界面恢复 =============================== + ui->checkBox_EnableVFI_Home->setEnabled(1); + if(ui->groupBox_FrameInterpolation->isChecked())ui->checkBox_FrameInterpolationOnly_Video->setEnabled(1); + ui->groupBox_FrameInterpolation->setEnabled(1); + ui->pushButton_BrowserFile->setEnabled(1); + ui->comboBox_ImageSaveFormat->setEnabled(1); + on_comboBox_ImageSaveFormat_currentIndexChanged(1); + emit Send_Table_EnableSorting(1);//启用文件列表的排序功能 + RemoveFile_FilesList_QAction_FileList->setEnabled(1); + Apply_CustRes_QAction_FileList->setEnabled(1); + Cancel_CustRes_QAction_FileList->setEnabled(1); + this->setAcceptDrops(1); + pushButton_Stop_setEnabled_self(0); + pushButton_Start_setEnabled_self(1); + if(ui->checkBox_ReplaceOriginalFile->isChecked()==false) + { + ui->groupBox_OutPut->setEnabled(1); + OutputSettingsArea_setEnabled(true); + ui->checkBox_DelOriginal->setEnabled(1); + } + ui->pushButton_ClearList->setEnabled(1); + ui->pushButton_RemoveItem->setEnabled(1); + ui->groupBox_Engine->setEnabled(1); + ui->groupBox_ScaleRaton_DenoiseLevel->setEnabled(1); + ui->checkBox_OptGIF->setEnabled(1); + ui->checkBox_ReProcFinFiles->setEnabled(1); + ui->pushButton_compatibilityTest->setEnabled(1); + ui->pushButton_ReadFileList->setEnabled(1); + ui->groupBox_video_settings->setEnabled(1); + if(ui->checkBox_DelOriginal->isChecked())QAction_checkBox_MoveToRecycleBin_checkBox_DelOriginal->setEnabled(1); + ui->pushButton_ForceRetry->setVisible(0); + ui->groupBox_AudioDenoise->setEnabled(1); + ui->checkBox_ProcessVideoBySegment->setEnabled(1); + if(ui->checkBox_ProcessVideoBySegment->isChecked()) + { + ui->spinBox_SegmentDuration->setEnabled(1); + } + on_comboBox_model_vulkan_currentIndexChanged(0); + isWaifu2xCaffeEnabled();//判断是否启用caffe图片风格combobox + emit Send_CurrentFileProgress_Stop(); + ui->checkBox_PreProcessImage->setEnabled(1); + ui->checkBox_AlwaysPreProcessAlphaPNG->setEnabled(1); + checkBox_ReplaceOriginalFile_setEnabled_True_Self(); + ui->checkBox_AutoDetectAlphaChannel->setEnabled(1); + ui->groupBox_CustRes->setEnabled(1); + ui->checkBox_DisableResize_gif->setEnabled(1); + //=================== 数值恢复 ================================ + ThreadNumMax = 0; + ThreadNumRunning = 0; + Progressbar_MaxVal = 0; + Progressbar_CurrentVal = 0; + TaskNumTotal=0; + TaskNumFinished=0; + NewTaskFinished=false; + ETA=0; + TimeCost=0; + ForceRetryCount=1; + isForceRetryEnabled=true; + isSuccessiveFailuresDetected_VFI=false; + //================= 杀死卡死在后台的进程 ================= + QStringList TaskNameList; + TaskNameList << "convert_waifu2xEX.exe"<<"ffmpeg_waifu2xEX.exe"<<"ffprobe_waifu2xEX.exe"<<"identify_waifu2xEX.exe"<<"gifsicle_waifu2xEX.exe"<<"waifu2x-ncnn-vulkan_waifu2xEX.exe" + <<"waifu2x-ncnn-vulkan-fp16p_waifu2xEX.exe"<<"Anime4K_waifu2xEX.exe"<<"waifu2x-caffe_waifu2xEX.exe"<<"srmd-ncnn-vulkan_waifu2xEX.exe"<<"realsr-ncnn-vulkan_waifu2xEX.exe" + <<"waifu2x-converter-cpp_waifu2xEX.exe"<<"sox_waifu2xEX.exe"<<"rife-ncnn-vulkan_waifu2xEX.exe"<<"cain-ncnn-vulkan_waifu2xEX.exe"<<"dain-ncnn-vulkan_waifu2xEX.exe" + <<"srmd-cuda_waifu2xEX.exe"<<"apngdis_waifu2xEX.exe"<<"apngasm_waifu2xEX.exe"; + KILL_TASK_QStringList(TaskNameList,true); + //================= 生成处理报告 ================= + ShowFileProcessSummary(); + //================= 打开输出文件夹 ==================== + if(ui->checkBox_AutoOpenOutputPath->isChecked()==true && ui->checkBox_OutPath_isEnabled->isChecked()==true)OpenOutputFolder(); + //====================== + FinishedProcessing_DN(); +} + +/* +移动文件到输出路径 +*/ +void MainWindow::MoveFileToOutputPath(QString Orginal,QString SourceFilePath) +{ + MoveFile_QMutex.lock(); + if(QFile::exists(Orginal)==false) + { + emit Send_TextBrowser_NewMessage(tr("Error! Original file [")+Orginal+tr("] does not exists.")); + MoveFile_QMutex.unlock(); + return; + } + QString Target_fullpPath=""; + QString Target_fileName=""; + QString Target_folder=""; + //确定文件名 + if(ui->checkBox_OutPath_KeepOriginalFileName->isChecked()) + { + QFileInfo fileinfo_source(SourceFilePath); + QString file_name = file_getBaseName(SourceFilePath); + QFileInfo fileinfo_Orginal(Orginal); + QString file_ext = fileinfo_Orginal.suffix(); + Target_fileName=file_name+"."+file_ext; + } + else + { + QFileInfo fileinfo_Orginal(Orginal); + Target_fileName = fileinfo_Orginal.fileName(); + } + //确定输出文件夹 + if(ui->checkBox_KeepParentFolder->isChecked()) + { + QFileInfo fileinfo_SourceFilePath(SourceFilePath); + QString folder_path_SourceFilePath = file_getFolderPath(fileinfo_SourceFilePath); + QStringList folder_path_SourceFilePath_QStringList = folder_path_SourceFilePath.split("/"); + QString ParentFolderName = folder_path_SourceFilePath_QStringList.last(); + //判断上级文件夹是不是磁盘根目录,若是则将文件夹名改为[盘符 Drive] + if(ParentFolderName.contains(":")) + { + ParentFolderName=ParentFolderName.replace(":"," Drive"); + } + Target_folder = OutPutFolder_main+"/"+ParentFolderName; + file_mkDir(Target_folder); + } + else + { + Target_folder=OutPutFolder_main; + } + //组装生成完整路径 + Target_fullpPath = Target_folder+"/"+Target_fileName; + //判断输出路径是否有和目标文件重名的 以及 是否启用了直接覆盖 + if(QFile::exists(Target_fullpPath)&&(ui->checkBox_OutPath_Overwrite->isChecked()==false)) + { + int suffix_int = 1; + QString Target_fullpPath_tmp = ""; + while(true) + { + QFileInfo fileinfo_tmp(Target_fullpPath); + QString file_name = file_getBaseName(Target_fullpPath); + QString file_ext = fileinfo_tmp.suffix(); + QString file_path = file_getFolderPath(fileinfo_tmp); + Target_fullpPath_tmp = file_path+"/"+file_name+"_"+QString::number(suffix_int,10)+"."+file_ext; + if(!QFile::exists(Target_fullpPath_tmp))break; + suffix_int++; + } + Target_fullpPath = Target_fullpPath_tmp; + } + if(ui->checkBox_OutPath_Overwrite->isChecked()==true) + { + QFile::remove(Target_fullpPath); + } + if(QFile::rename(Orginal,Target_fullpPath)==false) + { + emit Send_TextBrowser_NewMessage(tr("Error! Failed to move [")+Orginal+tr("] to [")+Target_fullpPath+"]"); + } + MoveFile_QMutex.unlock(); +} +/* +块大小调节 NCNN-Vulkan & Converter +*/ +/* +块大小调整按钮 + +*/ +int MainWindow::AddTileSize_NCNNVulkan_Converter(int OrginalTileSize) +{ + int TileSize = OrginalTileSize; + //判断是否为2的幂数 + if((TileSize&(TileSize-1))==0) + { + TileSize++; + } + if((TileSize&(TileSize-1))!=0) + { + for(int intNum=1; true; intNum++) + { + int pow_ =pow(2,intNum); + if(pow_>999999999) + { + return OrginalTileSize; + } + if(pow_>=TileSize) + { + return pow_; + } + } + } + return OrginalTileSize+1; +} +/* +块大小调整按钮 - +*/ +int MainWindow::MinusTileSize_NCNNVulkan_Converter(int OrginalTileSize) +{ + int TileSize = OrginalTileSize; + //判断是否为2的幂数 + if((TileSize&(TileSize-1))==0) + { + TileSize--; + } + if((TileSize&(TileSize-1))!=0) + { + for(int intNum=1; true; intNum++) + { + int pow_ =pow(2,intNum); + if(pow_>999999999) + { + return OrginalTileSize; + } + if(pow_>=TileSize) + { + return pow(2,intNum-1); + } + } + } + return OrginalTileSize-1; +} +/* +预读取引擎设定 +*/ +void MainWindow::PreLoad_Engines_Settings() +{ + //====================== + //Waifu2x-NCNN-Vulkan + //====================== + if(ui->comboBox_Engine_Image->currentIndex()==0) + { + Waifu2x_NCNN_Vulkan_PreLoad_Settings_Str = Waifu2x_NCNN_Vulkan_PreLoad_Settings(); + } + //====================== + //Waifu2x-Converter + //====================== + if(ui->comboBox_Engine_Image->currentIndex()==1||ui->comboBox_Engine_GIF->currentIndex()==1||ui->comboBox_Engine_Video->currentIndex()==1) + { + Waifu2xConverter_PreLoad_Settings_Str = Waifu2xConverter_PreLoad_Settings(); + } + //====================== + //SRMD-NCNN-Vulkan + //====================== + if(ui->comboBox_Engine_Image->currentIndex()==2) + { + SrmdNcnnVulkan_PreLoad_Settings_Str = SrmdNcnnVulkan_PreLoad_Settings(); + } + //====================== + //Anime4k + //====================== + if(ui->comboBox_Engine_Image->currentIndex()==3||ui->comboBox_Engine_GIF->currentIndex()==3||ui->comboBox_Engine_Video->currentIndex()==2) + { + Anime4k_PreLoad_Settings_Str = Anime4k_PreLoad_Settings(); + //预加载HDN等级 + if(ui->checkBox_ACNet_Anime4K->isChecked()&&ui->checkBox_HDNMode_Anime4k->isChecked()) + { + int HDNDenoiseLevel_value = 0; + if(ui->comboBox_Engine_Image->currentIndex()==3)//图片 + { + HDNDenoiseLevel_value = ui->spinBox_DenoiseLevel_image->value(); + if(HDNDenoiseLevel_value>=1&&HDNDenoiseLevel_value<=3) + { + HDNDenoiseLevel_image = " -L "+QString::number(HDNDenoiseLevel_value,10)+" "; + } + else + { + HDNDenoiseLevel_image = ""; + } + } + if(ui->comboBox_Engine_GIF->currentIndex()==3)//GIF + { + HDNDenoiseLevel_value = ui->spinBox_DenoiseLevel_gif->value(); + if(HDNDenoiseLevel_value>=1&&HDNDenoiseLevel_value<=3) + { + HDNDenoiseLevel_gif = " -L "+QString::number(HDNDenoiseLevel_value,10)+" "; + } + else + { + HDNDenoiseLevel_gif = ""; + } + } + if(ui->comboBox_Engine_Video->currentIndex()==2)//视频 + { + HDNDenoiseLevel_value = ui->spinBox_DenoiseLevel_video->value(); + if(HDNDenoiseLevel_value>=1&&HDNDenoiseLevel_value<=3) + { + HDNDenoiseLevel_video = " -L "+QString::number(HDNDenoiseLevel_value,10)+" "; + } + else + { + HDNDenoiseLevel_video = ""; + } + } + } + } + //====================== + //Waifu2x-Caffe + //====================== + if(isWaifu2xCaffeEnabled()) + { + Waifu2xCaffe_PreLoad_Settings_Str = Waifu2xCaffe_PreLoad_Settings(); + } + //====================== + //Realsr-NCNN-Vulkan + //====================== + if(ui->comboBox_Engine_Image->currentIndex()==5) + { + Realsr_NCNN_Vulkan_PreLoad_Settings_Str = Realsr_NCNN_Vulkan_PreLoad_Settings(); + } +} +/* +等待引擎IO结束 +1.读取初始文件列表 +2.获取初始文件大小列表 +3.等待数秒,再次读取文件大小判断是否发生IO,若没有IO则返回文件列表. +*/ +QStringList MainWindow::WaitForEngineIO(QStringList OutPutFilesFullPathList) +{ + QStringList ExistFileList; + QString fullpath_tmp; + for(int i = 0; i < OutPutFilesFullPathList.size(); i++) + { + fullpath_tmp= OutPutFilesFullPathList.at(i); + if(QFile::exists(fullpath_tmp)) + { + ExistFileList.append(fullpath_tmp); + } + } + QList FilesSizeList; + for(int i = 0; i < ExistFileList.size(); i++) + { + QFileInfo finfo(ExistFileList.at(i)); + FilesSizeList.append(finfo.size()); + } + do + { + Delay_sec_sleep(3); + QList FilesSizeList_tmp; + for(int i = 0; i < ExistFileList.size(); i++) + { + QFileInfo finfo(ExistFileList.at(i)); + FilesSizeList_tmp.append(finfo.size()); + } + if(FilesSizeList_tmp == FilesSizeList) + { + break; + } + else + { + FilesSizeList = FilesSizeList_tmp; + } + } + while (true); + return ExistFileList; +} +QStringList MainWindow::WaitForEngineIO_NcnnVulkan(QString OutputFolderFullPath) +{ + QStringList ExistFileList = file_getFileNames_in_Folder_nofilter(OutputFolderFullPath); + QString fullpath_tmp; + QList FilesSizeList; + for(int i = 0; i < ExistFileList.size(); i++) + { + QFileInfo finfo(OutputFolderFullPath+"/"+ExistFileList.at(i)); + FilesSizeList.append(finfo.size()); + } + do + { + Delay_sec_sleep(3); + QList FilesSizeList_tmp; + for(int i = 0; i < ExistFileList.size(); i++) + { + QFileInfo finfo(OutputFolderFullPath+"/"+ExistFileList.at(i)); + FilesSizeList_tmp.append(finfo.size()); + } + if(FilesSizeList_tmp == FilesSizeList) + { + break; + } + else + { + FilesSizeList = FilesSizeList_tmp; + } + } + while (true); + return ExistFileList; +} +/* +恢复拆分帧文件夹 +*/ +void MainWindow::Restore_SplitFramesFolderPath(QString SplitFramesFolderPath, QStringList GPU_SplitFramesFolderPath_List) +{ + if(file_isDirExist(SplitFramesFolderPath)==false)return; + for(int x = 0; x < GPU_SplitFramesFolderPath_List.size(); x++) + { + QString GPUfolder = GPU_SplitFramesFolderPath_List.at(x); + if(file_isDirExist(GPUfolder)==false)continue; + QStringList file_waitformove = file_getFileNames_in_Folder_nofilter(GPUfolder); + for(int i = 0; i < file_waitformove.size(); i++) + { + QString FileName = file_waitformove.at(i); + QFile::remove(SplitFramesFolderPath+"/"+FileName); + QFile::rename(GPUfolder+"/"+FileName,SplitFramesFolderPath+"/"+FileName); + } + file_DelDir(GPUfolder); + } +} +/* +复制一个文件夹的内容到另一个文件夹 Ncnn Vulkan +*/ +void MainWindow::file_MoveFiles_Folder_NcnnVulkanFolderProcess(QString Old_folder, QString New_folder, bool Delete_) +{ + if(file_isDirExist(Old_folder)==false || file_isDirExist(New_folder)==false)return; + QStringList file_waitformove = file_getFileNames_in_Folder_nofilter(Old_folder); + QString NewName=""; + QString FileName=""; + for(int i = 0; i < file_waitformove.size(); i++) + { + FileName = file_waitformove.at(i); + if(FileName.count(".")>1) + { + NewName = file_getBaseName(Old_folder+"/"+FileName); + do + { + if(NewName.count(".")<2)break; + NewName = file_getBaseName(Old_folder+"/"+NewName); + } + while(true); + QFile::rename(Old_folder+"/"+FileName,Old_folder+"/"+NewName); + FileName = NewName; + } + QFile::remove(New_folder+"/"+FileName); + QFile::rename(Old_folder+"/"+FileName,New_folder+"/"+FileName); + } + if(Delete_)file_DelDir(Old_folder); +} +/* +//杀死进程,可选管理员 +bool MainWindow::KILL_TASK_(QString TaskName,bool RequestAdmin) +{ + TaskName=TaskName.trimmed(); + if(TaskName=="")return false; + //=============== + QProcess Get_tasklist; + Get_tasklist.start("tasklist /fo csv"); + while(!Get_tasklist.waitForStarted(500)) {} + while(!Get_tasklist.waitForFinished(500)) {} + if(Get_tasklist.readAllStandardOutput().contains(TaskName.toUtf8())==false) + { + return true; + } + //=============== + QProcess Close; + Close.start("taskkill /f /t /fi \"imagename eq "+TaskName+"\""); + while(!Close.waitForStarted(500)) {} + while(!Close.waitForFinished(500)) {} + Get_tasklist.start("tasklist /fo csv"); + while(!Get_tasklist.waitForStarted(500)) {} + while(!Get_tasklist.waitForFinished(500)) {} + if(Get_tasklist.readAllStandardOutput().contains(TaskName.toUtf8()) && RequestAdmin==true) + { + ExecuteCMD_batFile("taskkill /f /t /fi \"imagename eq "+TaskName+"\"",true); + return true; + } + return true; +}*/ +/* +杀死进程列表,可选管理员 +*/ +bool MainWindow::KILL_TASK_QStringList(QStringList TaskNameList,bool RequestAdmin) +{ + TaskNameList.removeAll(""); + if(TaskNameList.isEmpty())return false; + //=============== + QProcess Get_tasklist; + Get_tasklist.start("tasklist /fo csv"); + while(!Get_tasklist.waitForStarted(500)) {} + while(!Get_tasklist.waitForFinished(500)) {} + QString RunningTaskList = Get_tasklist.readAllStandardOutput(); + //=== + QString TaskName_tmp; + QStringList TaskNameList_tmp = TaskNameList; + //=== + for(int i=0; icheckBox_SummaryPopup->isChecked()==false) + { + int rowCount_image = Table_model_image->rowCount(); + int rowCount_gif = Table_model_gif->rowCount(); + int rowCount_video = Table_model_video->rowCount(); + //=== + int NumOfFailedFiles = 0; + QString FailedFilesList = "\n"; + //检查图片文件列表 + for ( int RowNum = 0; RowNum < rowCount_image; RowNum++ ) + { + QString CurrentRowStatus = Table_model_image->item(RowNum,1)->text().toLower(); + if(CurrentRowStatus.contains("fail")) + { + NumOfFailedFiles++; + FailedFilesList.append(tr("Failed: [")+Table_model_image->item(RowNum,2)->text()+"]\n"); + continue; + } + } + //检查GIF文件列表 + for ( int RowNum = 0; RowNum < rowCount_gif; RowNum++ ) + { + QString CurrentRowStatus = Table_model_gif->item(RowNum,1)->text().toLower(); + if(CurrentRowStatus.contains("fail")) + { + NumOfFailedFiles++; + FailedFilesList.append(tr("Failed: [")+Table_model_gif->item(RowNum,2)->text()+"]\n"); + continue; + } + } + //检查视频文件列表 + for ( int RowNum = 0; RowNum < rowCount_video; RowNum++ ) + { + QString CurrentRowStatus = Table_model_video->item(RowNum,1)->text().toLower(); + if(CurrentRowStatus.contains("fail")) + { + NumOfFailedFiles++; + FailedFilesList.append(tr("Failed: [")+Table_model_video->item(RowNum,2)->text()+"]\n"); + continue; + } + } + //输出失败文件列表 + if(NumOfFailedFiles>0) + { + emit Send_TextBrowser_NewMessage(FailedFilesList); + } + return; + } + int rowCount_image = Table_model_image->rowCount(); + int rowCount_gif = Table_model_gif->rowCount(); + int rowCount_video = Table_model_video->rowCount(); + //=== + int NumOfFinishedFiles = 0; + int NumOfSkippedFiles = 0; + int NumOfFailedFiles = 0; + QString FailedFilesList = "\n"; + //=== + //检查图片文件列表 + for ( int RowNum = 0; RowNum < rowCount_image; RowNum++ ) + { + QString CurrentRowStatus = Table_model_image->item(RowNum,1)->text().toLower(); + if(CurrentRowStatus.contains("finished")) + { + NumOfFinishedFiles++; + continue; + } + if(CurrentRowStatus.contains("fail")) + { + NumOfFailedFiles++; + FailedFilesList.append(tr("Failed: [")+Table_model_image->item(RowNum,2)->text()+"]\n"); + continue; + } + if(ui->checkBox_AutoSkip_CustomRes->isChecked() && CurrentRowStatus.contains("skipped")) + { + NumOfSkippedFiles++; + continue; + } + } + //检查GIF文件列表 + for ( int RowNum = 0; RowNum < rowCount_gif; RowNum++ ) + { + QString CurrentRowStatus = Table_model_gif->item(RowNum,1)->text().toLower(); + if(CurrentRowStatus.contains("finished")) + { + NumOfFinishedFiles++; + continue; + } + if(CurrentRowStatus.contains("fail")) + { + NumOfFailedFiles++; + FailedFilesList.append(tr("Failed: [")+Table_model_gif->item(RowNum,2)->text()+"]\n"); + continue; + } + if(ui->checkBox_AutoSkip_CustomRes->isChecked() && CurrentRowStatus.contains("skipped")) + { + NumOfSkippedFiles++; + continue; + } + } + //检查视频文件列表 + for ( int RowNum = 0; RowNum < rowCount_video; RowNum++ ) + { + QString CurrentRowStatus = Table_model_video->item(RowNum,1)->text().toLower(); + if(CurrentRowStatus.contains("finished")) + { + NumOfFinishedFiles++; + continue; + } + if(CurrentRowStatus.contains("fail")) + { + NumOfFailedFiles++; + FailedFilesList.append(tr("Failed: [")+Table_model_video->item(RowNum,2)->text()+"]\n"); + continue; + } + if(ui->checkBox_AutoSkip_CustomRes->isChecked() && CurrentRowStatus.contains("skipped")) + { + NumOfSkippedFiles++; + continue; + } + } + //输出报告 + QString Summary_qstr = tr("Total: ")+QString("%1").arg((rowCount_image+rowCount_gif+rowCount_video))+"\n\n"+tr("Finished: ")+QString("%1").arg(NumOfFinishedFiles)+"\n\n"+tr("Failed: ")+QString("%1").arg(NumOfFailedFiles); + if(ui->checkBox_AutoSkip_CustomRes->isChecked()) + { + Summary_qstr.append("\n\n"+tr("Skipped: ")+QString("%1").arg(NumOfSkippedFiles)); + } + if(NumOfFailedFiles>0) + { + emit Send_TextBrowser_NewMessage(FailedFilesList); + Summary_qstr.append("\n\n"+tr("Info of failed files will be listed in the text browser at the bottom of the GUI.")); + } + //=== + QMessageBox *MSG_Summary = new QMessageBox(); + MSG_Summary->setWindowTitle(tr("Summary")); + MSG_Summary->setText(Summary_qstr); + MSG_Summary->setIcon(QMessageBox::Information); + MSG_Summary->setModal(true); + MSG_Summary->show(); + //=== + return; +} diff --git a/SRC/Waifu2x-Extension-QT/waifu2x_caffe.cpp b/SRC_v3.41.01-beta/Waifu2x-Extension-QT/waifu2x_caffe.cpp similarity index 97% rename from SRC/Waifu2x-Extension-QT/waifu2x_caffe.cpp rename to SRC_v3.41.01-beta/Waifu2x-Extension-QT/waifu2x_caffe.cpp index 8c57af2..95084c8 100644 --- a/SRC/Waifu2x-Extension-QT/waifu2x_caffe.cpp +++ b/SRC_v3.41.01-beta/Waifu2x-Extension-QT/waifu2x_caffe.cpp @@ -1,2154 +1,2154 @@ -/* - Copyright (C) 2021 Aaron Feng - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU Affero General Public License as published - by the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Affero General Public License for more details. - - You should have received a copy of the GNU Affero General Public License - along with this program. If not, see . - - My Github homepage: https://github.com/AaronFeng753 -*/ - -#include "mainwindow.h" -#include "ui_mainwindow.h" - -int MainWindow::Waifu2x_Caffe_Image(int rowNum,bool ReProcess_MissingAlphaChannel) -{ - //============================= 读取设置 ================================ - int DenoiseLevel = ui->spinBox_DenoiseLevel_image->value(); - bool DelOriginal = (ui->checkBox_DelOriginal->isChecked()||ui->checkBox_ReplaceOriginalFile->isChecked()); - QString OutPutPath_Final =""; - //========================= 拆解map得到参数 ============================= - emit Send_Table_image_ChangeStatus_rowNumInt_statusQString(rowNum, "Processing"); - QString SourceFile_fullPath = Table_model_image->item(rowNum,2)->text(); - if(!QFile::exists(SourceFile_fullPath)) - { - emit Send_TextBrowser_NewMessage(tr("Error occured when processing [")+SourceFile_fullPath+tr("]. Error: [File does not exist.]")); - emit Send_Table_image_ChangeStatus_rowNumInt_statusQString(rowNum, "Failed"); - emit Send_progressbar_Add(); - mutex_ThreadNumRunning.lock(); - ThreadNumRunning--; - mutex_ThreadNumRunning.unlock();//线程数量统计-1 - return 0; - } - //========= 转换到 PNG ========= - QString SourceFile_fullPath_Original = SourceFile_fullPath; - SourceFile_fullPath = Imgae_PreProcess(SourceFile_fullPath_Original,ReProcess_MissingAlphaChannel); - //======================================================= - int ScaleRatio = 2; - bool CustRes_isEnabled = false; - int CustRes_height=0; - int CustRes_width=0; - if(CustRes_isContained(SourceFile_fullPath_Original)) - { - CustRes_isEnabled=true; - QMap Res_map = CustRes_getResMap(SourceFile_fullPath_Original);//res_map["fullpath"],["height"],["width"] - ScaleRatio = CustRes_CalNewScaleRatio(SourceFile_fullPath,Res_map["height"].toInt(),Res_map["width"].toInt()); - if(ScaleRatio==0) - { - emit Send_TextBrowser_NewMessage(tr("Error occured when processing [")+SourceFile_fullPath_Original+tr("]. Error: [The resolution of the source file cannot be read, so the image cannot be scaled to a custom resolution.]")); - emit Send_Table_image_ChangeStatus_rowNumInt_statusQString(rowNum, "Failed"); - emit Send_progressbar_Add(); - mutex_ThreadNumRunning.lock(); - ThreadNumRunning--; - mutex_ThreadNumRunning.unlock();//线程数量统计-1 - return 0; - } - CustRes_height=Res_map["height"].toInt(); - CustRes_width=Res_map["width"].toInt(); - } - else - { - double ScaleRatio_double_tmp = ui->doubleSpinBox_ScaleRatio_image->value(); - if(ScaleRatio_double_tmp == (int)ScaleRatio_double_tmp) - { - ScaleRatio = qRound(ScaleRatio_double_tmp); - } - else - { - CustRes_isEnabled=true; - QMap Res_map = DoubleScaleRatio_Cal_NewScaleRatio_NewHW(SourceFile_fullPath,ScaleRatio_double_tmp); - //==== - if(Res_map.isEmpty()) - { - emit Send_TextBrowser_NewMessage(tr("Error occured when processing [")+SourceFile_fullPath+tr("]. Error: [Unable to read the resolution of the source file.]")); - emit Send_Table_image_ChangeStatus_rowNumInt_statusQString(rowNum, "Failed"); - emit Send_progressbar_Add(); - mutex_ThreadNumRunning.lock(); - ThreadNumRunning--; - mutex_ThreadNumRunning.unlock();//线程数量统计-1 - return 0; - } - //==== - ScaleRatio = Res_map["ScaleRatio"].toInt(); - CustRes_height = Res_map["Height_new"].toInt(); - CustRes_width = Res_map["width_new"].toInt(); - } - } - //======================================================= - QFileInfo fileinfo(SourceFile_fullPath); - QString file_name = file_getBaseName(SourceFile_fullPath); - QString file_ext = fileinfo.suffix(); - QString file_path = file_getFolderPath(fileinfo); - QString OutPut_Path = file_path + "/" + file_name + "_waifu2x_"+QString::number(ScaleRatio, 10)+"x_"+QString::number(DenoiseLevel, 10)+"n_"+file_ext+".png"; - //============================== 放大 ======================================= - QString Waifu2x_folder_path = Current_Path + "/waifu2x-caffe"; - QString program = Waifu2x_folder_path + "/waifu2x-caffe_waifu2xEX.exe"; - //==== - QString ImageProcessingModeCMD = ""; - if(DenoiseLevel==-1) - { - ImageProcessingModeCMD = " -m scale -s " + QString::number(ScaleRatio, 10)+" "; - } - else - { - int DenoiseLevel_tmp =0; - if((ui->comboBox_Model_2D_Waifu2xCaffe->currentIndex()==0)&&(DenoiseLevel==0)&&(ui->comboBox_ImageStyle_Waifu2xCaffe->currentIndex()==0)) - { - DenoiseLevel_tmp=1; - } - else - { - DenoiseLevel_tmp = DenoiseLevel; - } - ImageProcessingModeCMD = " -m noise_scale -s " + QString::number(ScaleRatio, 10)+ " -n " + QString::number(DenoiseLevel_tmp, 10)+" "; - } - //==== - QString cmd = "\"" + program + "\"" + " -i " + "\"" + SourceFile_fullPath + "\"" + " -o " + "\"" + OutPut_Path + "\"" + ImageProcessingModeCMD + Waifu2x_Caffe_ReadSettings(); - //======== - for(int retry=0; retry<(ui->spinBox_retry->value()+ForceRetryCount); retry++) - { - QProcess *Waifu2x = new QProcess(); - Waifu2x->start(cmd); - while(!Waifu2x->waitForStarted(100)&&!QProcess_stop) {} - while(!Waifu2x->waitForFinished(500)&&!QProcess_stop) - { - if(waifu2x_STOP) - { - Waifu2x->close(); - QFile::remove(OutPut_Path); - emit Send_Table_image_ChangeStatus_rowNumInt_statusQString(rowNum, "Interrupted"); - mutex_ThreadNumRunning.lock(); - ThreadNumRunning--; - mutex_ThreadNumRunning.unlock(); - return 0; - } - } - if(QFile::exists(OutPut_Path)) - { - break; - } - else - { - if(retry==ui->spinBox_retry->value()+(ForceRetryCount-1))break; - Delay_sec_sleep(5); - emit Send_TextBrowser_NewMessage(tr("Automatic retry, please wait.")); - } - } - //======== - if(!QFile::exists(OutPut_Path)) - { - if(SourceFile_fullPath_Original!=SourceFile_fullPath) - { - QFile::remove(SourceFile_fullPath); - } - emit Send_TextBrowser_NewMessage(tr("Error occured when processing [")+SourceFile_fullPath_Original+tr("]. Error: [Unable to scale the picture.]")); - emit Send_Table_image_ChangeStatus_rowNumInt_statusQString(rowNum, "Failed"); - emit Send_progressbar_Add(); - mutex_ThreadNumRunning.lock(); - ThreadNumRunning--; - mutex_ThreadNumRunning.unlock(); - return 0; - } - OutPutPath_Final = OutPut_Path; - //============================ 调整大小 ==================================================== - if(CustRes_isEnabled) - { - do - { - QImage qimage_adj(OutPut_Path); - //读取放大后的图片并调整大小 - QImage qimage_adj_scaled = qimage_adj.scaled(CustRes_width,CustRes_height,CustRes_AspectRatioMode,Qt::SmoothTransformation); - QImageWriter qimageW_adj; - qimageW_adj.setFormat("png"); - qimageW_adj.setFileName(OutPut_Path); - if(qimageW_adj.canWrite()) - { - qimageW_adj.write(qimage_adj_scaled); - } - if(!QFile::exists(OutPut_Path)) - { - emit Send_TextBrowser_NewMessage(tr("Error occured when processing [")+SourceFile_fullPath+tr("]. Error: [Unable to resize the scaled picture to the target size]")); - emit Send_Table_image_ChangeStatus_rowNumInt_statusQString(rowNum, "Failed"); - emit Send_progressbar_Add(); - mutex_ThreadNumRunning.lock(); - ThreadNumRunning--; - mutex_ThreadNumRunning.unlock();//线程数量统计-1 - return 0; - } - } - while(false); - QString OutPut_Path_CustRes = file_path + "/" + file_name + "_waifu2x_"+QString::number(CustRes_width, 10)+"x"+QString::number(CustRes_height, 10)+"_"+QString::number(DenoiseLevel, 10)+"n_"+file_ext+".png"; - QFile::remove(OutPut_Path_CustRes); - QFile::rename(OutPut_Path,OutPut_Path_CustRes); - OutPutPath_Final = OutPut_Path_CustRes; - } - //=========================== 另存为JPG&压缩JPG =========================================== - OutPutPath_Final = SaveImageAs_FormatAndQuality(SourceFile_fullPath_Original,OutPutPath_Final,true,DenoiseLevel); - //================== 检查是否丢失了透明通道 ===================== - if(ReProcess_MissingAlphaChannel==false) - { - QImage QImage_source(SourceFile_fullPath_Original); - QImage QImage_Final(OutPutPath_Final); - if(QImage_source.hasAlphaChannel()==true && QImage_Final.hasAlphaChannel()==false && ui->checkBox_AutoDetectAlphaChannel->isChecked()) - { - QFile::remove(OutPutPath_Final); - emit Send_TextBrowser_NewMessage(tr("Since the Alpha channel in the resulting image is lost, this image will be reprocessed to fix it:[")+SourceFile_fullPath_Original+tr("].\nIf the reprocessing happens a lot, you should consider enable [Always pre-process images with Alpha Channel] in [Additional settings].")); - return Waifu2x_Caffe_Image(rowNum,true); - } - } - //============================= 删除原文件 & & 更新table status ============================ - if(SourceFile_fullPath_Original!=SourceFile_fullPath) - { - QFile::remove(SourceFile_fullPath); - SourceFile_fullPath = SourceFile_fullPath_Original; - } - if(DelOriginal) - { - if(ReplaceOriginalFile(SourceFile_fullPath,OutPutPath_Final)==false) - { - if(QAction_checkBox_MoveToRecycleBin_checkBox_DelOriginal->isChecked()) - { - file_MoveToTrash(SourceFile_fullPath); - } - else - { - QFile::remove(SourceFile_fullPath); - } - } - emit Send_Table_image_ChangeStatus_rowNumInt_statusQString(rowNum, "Finished, original file deleted"); - } - else - { - emit Send_Table_image_ChangeStatus_rowNumInt_statusQString(rowNum, "Finished"); - } - //========== 移动到输出路径 ========= - if(ui->checkBox_OutPath_isEnabled->isChecked()) - { - MoveFileToOutputPath(OutPutPath_Final,SourceFile_fullPath); - } - //============================ 更新进度条 ================================= - emit Send_progressbar_Add(); - //=========================== 更新线程数量统计============================== - mutex_ThreadNumRunning.lock(); - ThreadNumRunning--; - mutex_ThreadNumRunning.unlock();//线程数量统计-1 - return 0; -} - - -int MainWindow::Waifu2x_Caffe_GIF(int rowNum) -{ - //============================= 读取设置 ================================ - int ScaleRatio = ui->doubleSpinBox_ScaleRatio_gif->value(); - int DenoiseLevel = ui->spinBox_DenoiseLevel_gif->value(); - bool DelOriginal = (ui->checkBox_DelOriginal->isChecked()||ui->checkBox_ReplaceOriginalFile->isChecked()); - bool OptGIF = ui->checkBox_OptGIF->isChecked(); - int Sub_gif_ThreadNumRunning = 0; - QString OutPutPath_Final =""; - //========================= 拆解map得到参数 ============================= - emit Send_Table_gif_ChangeStatus_rowNumInt_statusQString(rowNum, "Processing"); - QString SourceFile_fullPath = Table_model_gif->item(rowNum,2)->text(); - if(!QFile::exists(SourceFile_fullPath)) - { - emit Send_TextBrowser_NewMessage(tr("Error occured when processing [")+SourceFile_fullPath+tr("]. Error: [File does not exist.]")); - emit Send_Table_gif_ChangeStatus_rowNumInt_statusQString(rowNum, "Failed"); - emit Send_progressbar_Add(); - return 0; - } - //========================== - bool CustRes_isEnabled = false; - int CustRes_height=0; - int CustRes_width=0; - if(CustRes_isContained(SourceFile_fullPath)) - { - CustRes_isEnabled=true; - QMap Res_map = CustRes_getResMap(SourceFile_fullPath);//res_map["fullpath"],["height"],["width"] - CustRes_height=Res_map["height"].toInt(); - CustRes_width=Res_map["width"].toInt(); - } - //========================== - QFileInfo fileinfo(SourceFile_fullPath); - QString file_name = file_getBaseName(SourceFile_fullPath); - QString file_ext = fileinfo.suffix(); - QString file_path = file_getFolderPath(fileinfo); - QString ResGIFPath = file_path + "/" + file_name + "_waifu2x_"+QString::number(ScaleRatio, 10)+"x_"+QString::number(DenoiseLevel, 10)+"n.gif"; - //=========================== 获取帧时间 ==================================== - int GIF_Duration = Gif_getDuration(SourceFile_fullPath); - if(GIF_Duration==0)//检查是否成功获取duration - { - emit Send_TextBrowser_NewMessage(tr("Error occured when processing [")+SourceFile_fullPath+tr("]. Error: [Can't get Duration value of GIF file.]")); - emit Send_Table_gif_ChangeStatus_rowNumInt_statusQString(rowNum, "Failed"); - //file_DelDir(SplitFramesFolderPath); - emit Send_progressbar_Add(); - return 0;//如果启用stop位,则直接return - } - //============================== 拆分 ========================================== - QString SplitFramesFolderPath = file_path+"/"+file_name+"_SplitFrames_W2xEX";//拆分后存储frame的文件夹 - Gif_splitGif(SourceFile_fullPath,SplitFramesFolderPath); - //============================== 扫描获取文件名 =============================== - QStringList Frame_fileName_list = file_getFileNames_in_Folder_nofilter(SplitFramesFolderPath); - if(Frame_fileName_list.isEmpty())//检查是否成功拆分gif - { - emit Send_TextBrowser_NewMessage(tr("Error occured when processing [")+SourceFile_fullPath+tr("]. Error: [Can't split GIF into frames.]")); - emit Send_Table_gif_ChangeStatus_rowNumInt_statusQString(rowNum, "Failed"); - file_DelDir(SplitFramesFolderPath); - emit Send_progressbar_Add(); - return 0;//如果启用stop位,则直接return - } - //===========建立存储放大后frame的文件夹=========== - QString ScaledFramesFolderPath = SplitFramesFolderPath+"/ScaledFrames_W2xEX"; - if(file_isDirExist(ScaledFramesFolderPath)) - { - file_DelDir(ScaledFramesFolderPath); - file_mkDir(ScaledFramesFolderPath); - } - else - { - file_mkDir(ScaledFramesFolderPath); - } - //==========开始放大========================== - emit Send_CurrentFileProgress_Start(file_name+"."+file_ext,Frame_fileName_list.size()); - FileProgressWatch_isEnabled=true; - QFuture FileProgressWatch_QFuture = QtConcurrent::run(this, &MainWindow::CurrentFileProgress_WatchFolderFileNum, ScaledFramesFolderPath);//启动waifu2x 主线程 - if(ui->checkBox_ShowInterPro->isChecked()==false) - { - FileProgressWatch_isEnabled=false; - FileProgressWatch_QFuture.cancel(); - emit Send_CurrentFileProgress_Stop(); - } - //=======获取显卡信息======== - int NumOfGPU = 1; - if(ui->checkBox_EnableMultiGPU_Waifu2xCaffe->isChecked()==true) - { - NumOfGPU = Get_NumOfGPU_W2xCaffe(); - } - //============创建显卡文件夹=========== - QStringList GPU_SplitFramesFolderPath_List; - for(int i = 0; i < NumOfGPU; i++) - { - QString GPU_SplitFramesFolderPath = SplitFramesFolderPath+"/"+"GPU_"+QString::number(i); - if(file_isDirExist(GPU_SplitFramesFolderPath)) - { - file_DelDir(GPU_SplitFramesFolderPath); - file_mkDir(GPU_SplitFramesFolderPath); - } - else - { - file_mkDir(GPU_SplitFramesFolderPath); - } - GPU_SplitFramesFolderPath_List.append(GPU_SplitFramesFolderPath); - } - int TotalFramesNum = Frame_fileName_list.size(); - int FramesNumForEachGPU = TotalFramesNum/NumOfGPU; - if(FramesNumForEachGPU<1)FramesNumForEachGPU=1; - int start_num=0; - for(int x = 0; x < GPU_SplitFramesFolderPath_List.size(); x++) - { - if(x==GPU_SplitFramesFolderPath_List.size()-1)FramesNumForEachGPU=TotalFramesNum; - QStringList file_waitformove = Frame_fileName_list.mid(start_num,FramesNumForEachGPU); - for(int i = 0; i < file_waitformove.size(); i++) - { - QString FileName = file_waitformove.at(i); - QFile::rename(SplitFramesFolderPath+"/"+FileName,GPU_SplitFramesFolderPath_List.at(x)+"/"+FileName); - } - start_num+=FramesNumForEachGPU; - } - //========================= - bool Frame_failed = false;//放大失败标志 - //==== - QMap Sub_Thread_info; - Sub_Thread_info["ScaledFramesFolderPath"]= ScaledFramesFolderPath; - if(CustRes_isEnabled == true) - { - Sub_Thread_info["ScaleRatio"] = QString("%1").arg(CustRes_CalNewScaleRatio(SourceFile_fullPath,CustRes_height,CustRes_width)); - } - else - { - Sub_Thread_info["ScaleRatio"] = QString("%1").arg(qRound(ui->doubleSpinBox_ScaleRatio_gif->value())); - } - //========================= - for(int i = 0; i < GPU_SplitFramesFolderPath_List.size(); i++) - { - Sub_Thread_info["SplitFramesFolderPath"]=GPU_SplitFramesFolderPath_List.at(i); - mutex_SubThreadNumRunning.lock(); - Sub_gif_ThreadNumRunning++; - mutex_SubThreadNumRunning.unlock(); - QtConcurrent::run(this,&MainWindow::Waifu2x_Caffe_GIF_scale,Sub_Thread_info,&Sub_gif_ThreadNumRunning,&Frame_failed); - while (Sub_gif_ThreadNumRunning >= NumOfGPU) - { - Delay_msec_sleep(500); - } - if(waifu2x_STOP) - { - while (Sub_gif_ThreadNumRunning > 0) - { - Delay_msec_sleep(500); - } - FileProgressWatch_isEnabled=false; - FileProgressWatch_QFuture.cancel(); - file_DelDir(SplitFramesFolderPath); - emit Send_Table_gif_ChangeStatus_rowNumInt_statusQString(rowNum, "Interrupted"); - return 0;//如果启用stop位,则直接return - } - if(Frame_failed) - { - FileProgressWatch_isEnabled=false; - FileProgressWatch_QFuture.cancel(); - emit Send_TextBrowser_NewMessage(tr("Error occured when processing [")+SourceFile_fullPath+tr("]. Error: [Failed to scale frames.]")); - emit Send_Table_gif_ChangeStatus_rowNumInt_statusQString(rowNum, "Failed"); - file_DelDir(SplitFramesFolderPath); - emit Send_progressbar_Add(); - return 0;//如果启用stop位,则直接return - } - } - while (Sub_gif_ThreadNumRunning!=0) - { - Delay_msec_sleep(500); - } - FileProgressWatch_isEnabled=false; - FileProgressWatch_QFuture.cancel(); - emit Send_CurrentFileProgress_Stop(); - //======================= 检查是否成功放大所有帧 =========================== - QStringList Frame_fileName_list_scaled = file_getFileNames_in_Folder_nofilter(ScaledFramesFolderPath); - if(Frame_fileName_list.size()!=Frame_fileName_list_scaled.size()) - { - emit Send_TextBrowser_NewMessage(tr("Error occured when processing [")+SourceFile_fullPath+tr("]. Error: [Failed to scale frames.]")); - emit Send_Table_gif_ChangeStatus_rowNumInt_statusQString(rowNum, "Failed"); - file_DelDir(SplitFramesFolderPath); - emit Send_progressbar_Add(); - return 0;//如果启用stop位,则直接return - } - //======================================== 组装 ====================================================== - if(CustRes_isEnabled) - { - ResGIFPath = file_path + "/" + file_name + "_waifu2x_"+QString::number(CustRes_width, 10)+"x"+QString::number(CustRes_height,10)+"_"+QString::number(DenoiseLevel, 10)+"n.gif"; - } - Gif_assembleGif(ResGIFPath,ScaledFramesFolderPath,GIF_Duration,CustRes_isEnabled,CustRes_height,CustRes_width,false,""); - if(!QFile::exists(ResGIFPath)) - { - emit Send_TextBrowser_NewMessage(tr("Error occured when processing [")+SourceFile_fullPath+tr("]. Error: [Unable to assemble gif.]")); - emit Send_Table_gif_ChangeStatus_rowNumInt_statusQString(rowNum, "Failed"); - file_DelDir(SplitFramesFolderPath); - emit Send_progressbar_Add(); - return 0;//如果启用stop位,则直接return - } - OutPutPath_Final = ResGIFPath; - //======================================= 优化gif =================================================== - if(OptGIF) - { - QString ResGIFPath_compressed = ""; - if(CustRes_isEnabled) - { - ResGIFPath_compressed = file_path + "/" + file_name + "_waifu2x_"+QString::number(CustRes_width, 10)+"x"+QString::number(CustRes_height,10)+"_"+QString::number(DenoiseLevel, 10)+"n_opt.gif"; - } - else - { - ResGIFPath_compressed = file_path + "/" + file_name + "_waifu2x_"+QString::number(ScaleRatio, 10)+"x_"+QString::number(DenoiseLevel, 10)+"n_opt.gif"; - } - OutPutPath_Final = Gif_compressGif(ResGIFPath,ResGIFPath_compressed); - } - //============================== 删除缓存文件 ==================================================== - file_DelDir(SplitFramesFolderPath); - //============================= 删除原文件 & & 更新table status ============================ - if(DelOriginal) - { - if(ReplaceOriginalFile(SourceFile_fullPath,OutPutPath_Final)==false) - { - if(QAction_checkBox_MoveToRecycleBin_checkBox_DelOriginal->isChecked()) - { - file_MoveToTrash(SourceFile_fullPath); - } - else - { - QFile::remove(SourceFile_fullPath); - } - } - emit Send_Table_gif_ChangeStatus_rowNumInt_statusQString(rowNum, "Finished, original file deleted"); - } - else - { - emit Send_Table_gif_ChangeStatus_rowNumInt_statusQString(rowNum, "Finished"); - } - //========== 移动到输出路径 ========= - if(ui->checkBox_OutPath_isEnabled->isChecked()) - { - MoveFileToOutputPath(OutPutPath_Final,SourceFile_fullPath); - } - //============================ 更新进度条 ================================= - emit Send_progressbar_Add(); - //=========================== ============================== - return 0; -} - -int MainWindow::Waifu2x_Caffe_GIF_scale(QMap Sub_Thread_info,int *Sub_gif_ThreadNumRunning,bool *Frame_failed) -{ - bool AllFinished=true; - QString SplitFramesFolderPath = Sub_Thread_info["SplitFramesFolderPath"]; - QString ScaledFramesFolderPath = Sub_Thread_info["ScaledFramesFolderPath"]; - //=========== - int ScaleRatio = Sub_Thread_info["ScaleRatio"].toInt(); - int DenoiseLevel = ui->spinBox_DenoiseLevel_gif->value(); - //=========== - QString program = Current_Path + "/waifu2x-caffe/waifu2x-caffe_waifu2xEX.exe"; - //==== - QString ImageProcessingModeCMD = ""; - if(DenoiseLevel==-1) - { - ImageProcessingModeCMD = " -m scale -s " + QString::number(ScaleRatio, 10)+" "; - } - else - { - int DenoiseLevel_tmp =0; - if((ui->comboBox_Model_2D_Waifu2xCaffe->currentIndex()==0)&&(DenoiseLevel==0)&&(ui->comboBox_ImageStyle_Waifu2xCaffe->currentIndex()==0)) - { - DenoiseLevel_tmp=1; - } - else - { - DenoiseLevel_tmp = DenoiseLevel; - } - ImageProcessingModeCMD = " -m noise_scale -s " + QString::number(ScaleRatio, 10)+ " -n " + QString::number(DenoiseLevel_tmp, 10)+" "; - } - //======= - //======================================================================== - QStringList InputFilesNameList = file_getFileNames_in_Folder_nofilter(SplitFramesFolderPath); - QStringList OutPutFilesFullPathList; - for(int i=0; ispinBox_retry->value()+ForceRetryCount); retry++) - { - Waifu2x->start(cmd); - while(!Waifu2x->waitForStarted(100)&&!QProcess_stop) {} - while(!Waifu2x->waitForFinished(500)&&!QProcess_stop) - { - if(waifu2x_STOP) - { - Waifu2x->close(); - mutex_SubThreadNumRunning.lock(); - *Sub_gif_ThreadNumRunning=*Sub_gif_ThreadNumRunning-1; - mutex_SubThreadNumRunning.unlock(); - return 0; - } - } - AllFinished = true; - for(int i=0; ispinBox_retry->value()+(ForceRetryCount-1))break; - Delay_sec_sleep(5); - emit Send_TextBrowser_NewMessage(tr("Automatic retry, please wait.")); - AllFinished=false; - break; - } - } - if(AllFinished)break; - } - //========= - AllFinished = true; - for(int i=0; idoubleSpinBox_ScaleRatio_video->value(); - int DenoiseLevel = ui->spinBox_DenoiseLevel_video->value(); - bool DelOriginal = (ui->checkBox_DelOriginal->isChecked()||ui->checkBox_ReplaceOriginalFile->isChecked()); - bool isCacheExists = false; - bool isVideoConfigChanged = true; - int Sub_video_ThreadNumRunning = 0; - //========================= 拆解map得到参数 ============================= - emit Send_Table_video_ChangeStatus_rowNumInt_statusQString(rowNum, "Processing"); - QString SourceFile_fullPath = Table_model_video->item(rowNum,2)->text(); - if(!QFile::exists(SourceFile_fullPath)) - { - emit Send_TextBrowser_NewMessage(tr("Error occured when processing [")+SourceFile_fullPath+tr("]. Error: [File does not exist.]")); - emit Send_Table_video_ChangeStatus_rowNumInt_statusQString(rowNum, "Failed"); - emit Send_progressbar_Add(); - return 0; - } - //========================== - QFileInfo fileinfo(SourceFile_fullPath); - QString file_name = file_getBaseName(SourceFile_fullPath); - QString file_ext = fileinfo.suffix(); - QString file_path = file_getFolderPath(fileinfo); - //=================================================================== - //生成mp4 - QString video_mp4_fullpath=video_To_CFRMp4(SourceFile_fullPath); - if(!QFile::exists(video_mp4_fullpath))//检查是否成功生成mp4 - { - emit Send_TextBrowser_NewMessage(tr("Error occured when processing [")+SourceFile_fullPath+tr("]. Error: [Cannot convert video format to mp4.]")); - emit Send_Table_video_ChangeStatus_rowNumInt_statusQString(rowNum, "Failed"); - emit Send_progressbar_Add(); - return 0;//如果启用stop位,则直接return - } - //============ 读取自定义分辨率 ============== - bool CustRes_isEnabled = false; - int CustRes_height=0; - int CustRes_width=0; - if(CustRes_isContained(SourceFile_fullPath)) - { - CustRes_isEnabled=true; - QMap Res_map = CustRes_getResMap(SourceFile_fullPath);//res_map["fullpath"],["height"],["width"] - CustRes_height=Res_map["height"].toInt(); - CustRes_width=Res_map["width"].toInt(); - } - //================= - QString AudioPath = file_path+"/Audio_"+file_name+"_"+file_ext+"_W2xEX.wav";//音频 - QString SplitFramesFolderPath = file_path+"/"+file_name+"_"+file_ext+"_SplitFrames_W2xEX";//拆分后存储frame的文件夹 - QString ScaledFramesFolderPath = SplitFramesFolderPath+"/ScaledFrames_W2xEX";//存储放大后的帧 - //========================== - // 检测之前的视频配置文件 - //========================== - QString VideoConfiguration_fullPath = file_path+"/VideoConfiguration_"+file_name+"_"+file_ext+"_Waifu2xEX.ini"; - if(QFile::exists(VideoConfiguration_fullPath)) - { - QSettings *configIniRead = new QSettings(VideoConfiguration_fullPath, QSettings::IniFormat); - configIniRead->setIniCodec(QTextCodec::codecForName("UTF-8")); - //=================== 加载之前存储的视频信息 ========================= - int ScaleRatio_old = configIniRead->value("/VideoConfiguration/ScaleRatio").toInt(); - int DenoiseLevel_old = configIniRead->value("/VideoConfiguration/DenoiseLevel").toInt(); - bool CustRes_isEnabled_old = configIniRead->value("/VideoConfiguration/CustRes_isEnabled").toBool(); - int CustRes_height_old = configIniRead->value("/VideoConfiguration/CustRes_height").toInt(); - int CustRes_width_old = configIniRead->value("/VideoConfiguration/CustRes_width").toInt(); - QString EngineName_old = configIniRead->value("/VideoConfiguration/EngineName").toString(); - bool isProcessBySegment_old = configIniRead->value("/VideoConfiguration/isProcessBySegment").toBool(); - //=================== 比对信息 ================================ - if(EngineName_old=="waifu2x-caffe") - { - if(CustRes_isEnabled_old==false&&CustRes_isEnabled==false) - { - if(ScaleRatio_old!=ScaleRatio||DenoiseLevel_old!=DenoiseLevel) - { - isVideoConfigChanged=true; - } - else - { - isVideoConfigChanged=false; - } - } - else - { - if(CustRes_isEnabled_old==true&&CustRes_isEnabled==true) - { - if(CustRes_height_old!=CustRes_height||CustRes_width_old!=CustRes_width) - { - isVideoConfigChanged=true; - } - else - { - isVideoConfigChanged=false; - } - } - else - { - isVideoConfigChanged=true; - } - } - if(isProcessBySegment_old==true) - { - isVideoConfigChanged=true; - } - } - else - { - isVideoConfigChanged=true; - } - } - else - { - emit Send_video_write_VideoConfiguration(VideoConfiguration_fullPath,ScaleRatio,DenoiseLevel,CustRes_isEnabled,CustRes_height,CustRes_width,"waifu2x-caffe",false,"","",ui->groupBox_FrameInterpolation->isChecked(),0); - } - //======================= - // 检测缓存是否存在 - //======================= - if(QFile::exists(video_mp4_fullpath)&&file_isDirExist(SplitFramesFolderPath)&&file_isDirExist(ScaledFramesFolderPath)&&QFile::exists(VideoConfiguration_fullPath)) - { - if(!isVideoConfigChanged) - { - isCacheExists=true; - emit Send_TextBrowser_NewMessage(tr("The previous video cache file is detected and processing of the previous video cache will continue. If you want to restart processing of the current video:[")+SourceFile_fullPath+tr("], delete the cache manually.")); - } - else - { - isCacheExists=false; - //======== - QFile::remove(VideoConfiguration_fullPath); - file_DelDir(SplitFramesFolderPath); - QFile::remove(AudioPath); - DelVfiDir(video_mp4_fullpath); - emit Send_video_write_VideoConfiguration(VideoConfiguration_fullPath,ScaleRatio,DenoiseLevel,CustRes_isEnabled,CustRes_height,CustRes_width,"waifu2x-caffe",false,"","",ui->groupBox_FrameInterpolation->isChecked(),0); - //======= - emit Send_TextBrowser_NewMessage(tr("The previous video cache file was detected, but because you changed the settings about the video resolution or denoise level, the previous cache will be deleted and processing of the video:[")+SourceFile_fullPath+tr("] will restart.")); - } - } - else - { - isCacheExists=false; - //======== - QFile::remove(VideoConfiguration_fullPath); - file_DelDir(SplitFramesFolderPath); - QFile::remove(AudioPath); - DelVfiDir(video_mp4_fullpath); - emit Send_video_write_VideoConfiguration(VideoConfiguration_fullPath,ScaleRatio,DenoiseLevel,CustRes_isEnabled,CustRes_height,CustRes_width,"waifu2x-caffe",false,"","",ui->groupBox_FrameInterpolation->isChecked(),0); - //======== - } - if(!isCacheExists) - { - //============================== 拆分 ========================================== - if(file_isDirExist(SplitFramesFolderPath)) - { - file_DelDir(SplitFramesFolderPath); - file_mkDir(SplitFramesFolderPath); - } - else - { - file_mkDir(SplitFramesFolderPath); - } - QFile::remove(AudioPath); - video_video2images(video_mp4_fullpath,SplitFramesFolderPath,AudioPath); - if(waifu2x_STOP) - { - emit Send_Table_video_ChangeStatus_rowNumInt_statusQString(rowNum, "Interrupted"); - return 0;//如果启用stop位,则直接return - } - } - //============================== 扫描获取文件名 =============================== - QStringList Frame_fileName_list = file_getFileNames_in_Folder_nofilter(SplitFramesFolderPath); - if(!isCacheExists) - { - if(Frame_fileName_list.isEmpty())//检查是否成功拆分为帧 - { - emit Send_TextBrowser_NewMessage(tr("Error occured when processing [")+SourceFile_fullPath+tr("]. Error: [Unable to split video into pictures.]")); - emit Send_Table_video_ChangeStatus_rowNumInt_statusQString(rowNum, "Failed"); - emit Send_progressbar_Add(); - return 0;//如果启用stop位,则直接return - } - } - //============================== 放大 ======================================= - //===========建立存储放大后frame的文件夹=========== - if(!isCacheExists) - { - if(file_isDirExist(ScaledFramesFolderPath)) - { - file_DelDir(ScaledFramesFolderPath); - file_mkDir(ScaledFramesFolderPath); - } - else - { - file_mkDir(ScaledFramesFolderPath); - } - } - //==========开始放大========================== - emit Send_CurrentFileProgress_Start(file_name+"."+file_ext,(Frame_fileName_list.size()+file_getFileNames_in_Folder_nofilter(ScaledFramesFolderPath).size())); - FileProgressWatch_isEnabled=true; - QFuture FileProgressWatch_QFuture = QtConcurrent::run(this, &MainWindow::CurrentFileProgress_WatchFolderFileNum, ScaledFramesFolderPath);//启动waifu2x 主线程 - if(ui->checkBox_ShowInterPro->isChecked()==false) - { - FileProgressWatch_isEnabled=false; - FileProgressWatch_QFuture.cancel(); - emit Send_CurrentFileProgress_Stop(); - } - //=======获取显卡信息======== - int NumOfGPU = 1; - if(ui->checkBox_EnableMultiGPU_Waifu2xCaffe->isChecked()==true) - { - NumOfGPU = Get_NumOfGPU_W2xCaffe(); - } - //============创建显卡文件夹=========== - QStringList GPU_SplitFramesFolderPath_List; - for(int i = 0; i < NumOfGPU; i++) - { - QString GPU_SplitFramesFolderPath = SplitFramesFolderPath+"/"+"GPU_"+QString::number(i); - if(file_isDirExist(GPU_SplitFramesFolderPath)==false) - { - file_DelDir(GPU_SplitFramesFolderPath); - file_mkDir(GPU_SplitFramesFolderPath); - } - else - { - file_mkDir(GPU_SplitFramesFolderPath); - } - GPU_SplitFramesFolderPath_List.append(GPU_SplitFramesFolderPath); - } - int TotalFramesNum = Frame_fileName_list.size(); - int FramesNumForEachGPU = TotalFramesNum/NumOfGPU; - if(FramesNumForEachGPU<1)FramesNumForEachGPU=1; - int start_num=0; - for(int x = 0; x < GPU_SplitFramesFolderPath_List.size(); x++) - { - if(x==GPU_SplitFramesFolderPath_List.size()-1)FramesNumForEachGPU=TotalFramesNum; - QStringList file_waitformove = Frame_fileName_list.mid(start_num,FramesNumForEachGPU); - for(int i = 0; i < file_waitformove.size(); i++) - { - QString FileName = file_waitformove.at(i); - QFile::rename(SplitFramesFolderPath+"/"+FileName,GPU_SplitFramesFolderPath_List.at(x)+"/"+FileName); - } - start_num+=FramesNumForEachGPU; - } - //========================= - bool Frame_failed = false;//放大失败标志 - QMap Sub_Thread_info; - Sub_Thread_info["ScaledFramesFolderPath"]=ScaledFramesFolderPath; - if(CustRes_isEnabled == true) - { - Sub_Thread_info["ScaleRatio"] = QString("%1").arg(CustRes_CalNewScaleRatio(video_mp4_fullpath,CustRes_height,CustRes_width)); - } - else - { - Sub_Thread_info["ScaleRatio"] = QString("%1").arg(ScaleRatio); - } - //========================= - for(int i = 0; i < GPU_SplitFramesFolderPath_List.size(); i++) - { - Sub_Thread_info["SplitFramesFolderPath"]=GPU_SplitFramesFolderPath_List.at(i); - mutex_SubThreadNumRunning.lock(); - Sub_video_ThreadNumRunning++; - mutex_SubThreadNumRunning.unlock(); - QtConcurrent::run(this,&MainWindow::Waifu2x_Caffe_Video_scale,Sub_Thread_info,&Sub_video_ThreadNumRunning,&Frame_failed); - while (Sub_video_ThreadNumRunning >= NumOfGPU) - { - Delay_msec_sleep(500); - } - if(waifu2x_STOP) - { - while (Sub_video_ThreadNumRunning > 0) - { - Delay_msec_sleep(500); - } - FileProgressWatch_isEnabled=false; - FileProgressWatch_QFuture.cancel(); - Restore_SplitFramesFolderPath(SplitFramesFolderPath,GPU_SplitFramesFolderPath_List); - emit Send_Table_video_ChangeStatus_rowNumInt_statusQString(rowNum, "Interrupted"); - return 0;//如果启用stop位,则直接return - } - if(Frame_failed) - { - FileProgressWatch_isEnabled=false; - FileProgressWatch_QFuture.cancel(); - Restore_SplitFramesFolderPath(SplitFramesFolderPath,GPU_SplitFramesFolderPath_List); - emit Send_TextBrowser_NewMessage(tr("Error occured when processing [")+SourceFile_fullPath+tr("]. Error: [Failed to scale frames.]")); - emit Send_Table_video_ChangeStatus_rowNumInt_statusQString(rowNum, "Failed"); - emit Send_progressbar_Add(); - return 0;//如果启用stop位,则直接return - } - } - while (Sub_video_ThreadNumRunning!=0) - { - Delay_msec_sleep(500); - } - FileProgressWatch_isEnabled=false; - FileProgressWatch_QFuture.cancel(); - emit Send_CurrentFileProgress_Stop(); - //================ 扫描放大后的帧文件数量,判断是否放大成功 ======================= - QStringList Frame_fileName_list_scaled = file_getFileNames_in_Folder_nofilter(ScaledFramesFolderPath); - if(Frame_fileName_list_scaled.size()checkBox_KeepVideoCache->isChecked()==false) - { - QFile::remove(VideoConfiguration_fullPath); - file_DelDir(SplitFramesFolderPath); - QFile::remove(AudioPath); - if(SourceFile_fullPath!=video_mp4_fullpath)QFile::remove(video_mp4_fullpath); - } - else - { - DelOriginal=false; - } - //============================= 删除原文件 & & 更新table status ============================ - if(DelOriginal) - { - if(ReplaceOriginalFile(SourceFile_fullPath,video_mp4_scaled_fullpath)==false) - { - if(QAction_checkBox_MoveToRecycleBin_checkBox_DelOriginal->isChecked()) - { - file_MoveToTrash(SourceFile_fullPath); - } - else - { - QFile::remove(SourceFile_fullPath); - } - } - emit Send_Table_video_ChangeStatus_rowNumInt_statusQString(rowNum, "Finished, original file deleted"); - } - else - { - emit Send_Table_video_ChangeStatus_rowNumInt_statusQString(rowNum, "Finished"); - } - //========== 移动到输出路径 ========= - if(ui->checkBox_OutPath_isEnabled->isChecked()) - { - MoveFileToOutputPath(video_mp4_scaled_fullpath,SourceFile_fullPath); - } - //============================ 更新进度条 ================================= - emit Send_progressbar_Add(); - //=========================== ============================== - return 0; -} - -/* -#### 分段处理 #### -调用Waifu2x-caffe处理视频 -读取设置,拆分,创建放大子线程,组装视频 -*/ -int MainWindow::Waifu2x_Caffe_Video_BySegment(int rowNum) -{ - //============================= 读取设置 ================================ - int ScaleRatio = ui->doubleSpinBox_ScaleRatio_video->value(); - int DenoiseLevel = ui->spinBox_DenoiseLevel_video->value(); - bool DelOriginal = (ui->checkBox_DelOriginal->isChecked()||ui->checkBox_ReplaceOriginalFile->isChecked()); - bool isCacheExists = false; - bool isVideoConfigChanged = true; - int Sub_video_ThreadNumRunning = 0; - int SegmentDuration = ui->spinBox_SegmentDuration->value(); - //========================= 拆解map得到参数 ============================= - emit Send_Table_video_ChangeStatus_rowNumInt_statusQString(rowNum, "Processing"); - QString SourceFile_fullPath = Table_model_video->item(rowNum,2)->text(); - if(!QFile::exists(SourceFile_fullPath)) - { - emit Send_TextBrowser_NewMessage(tr("Error occured when processing [")+SourceFile_fullPath+tr("]. Error: [File does not exist.]")); - emit Send_Table_video_ChangeStatus_rowNumInt_statusQString(rowNum, "Failed"); - emit Send_progressbar_Add(); - return 0; - } - //========================== - QFileInfo fileinfo(SourceFile_fullPath); - QString file_name = file_getBaseName(SourceFile_fullPath); - QString file_ext = fileinfo.suffix(); - QString file_path = file_getFolderPath(fileinfo); - //=================================================================== - //生成mp4 - QString video_mp4_fullpath=video_To_CFRMp4(SourceFile_fullPath); - if(!QFile::exists(video_mp4_fullpath))//检查是否成功生成mp4 - { - emit Send_TextBrowser_NewMessage(tr("Error occured when processing [")+SourceFile_fullPath+tr("]. Error: [Cannot convert video format to mp4.]")); - emit Send_Table_video_ChangeStatus_rowNumInt_statusQString(rowNum, "Failed"); - emit Send_progressbar_Add(); - return 0;//如果启用stop位,则直接return - } - //============== 读取自定义分辨率 ============ - bool CustRes_isEnabled = false; - int CustRes_height=0; - int CustRes_width=0; - if(CustRes_isContained(SourceFile_fullPath)) - { - CustRes_isEnabled=true; - QMap Res_map = CustRes_getResMap(SourceFile_fullPath);//res_map["fullpath"],["height"],["width"] - CustRes_height=Res_map["height"].toInt(); - CustRes_width=Res_map["width"].toInt(); - } - //================= - QString AudioPath = file_path+"/Audio_"+file_name+"_"+file_ext+"_W2xEX.wav";//音频 - QString SplitFramesFolderPath = file_path+"/"+file_name+"_"+file_ext+"_SplitFrames_W2xEX";//拆分后存储frame的文件夹 - QString ScaledFramesFolderPath = SplitFramesFolderPath+"/ScaledFrames_W2xEX";//存储放大后的帧 - //=== - QString VideoClipsFolderPath = "";//存储视频片段的文件夹(完整路径) - QString DateStr = ""; - do - { - DateStr = video_getClipsFolderNo(); - VideoClipsFolderPath = file_path+"/"+DateStr+"_VideoClipsWaifu2xEX";//存储视频片段的文件夹(完整路径) - } - while(file_isDirExist(VideoClipsFolderPath)); - QString VideoClipsFolderName = DateStr+"_VideoClipsWaifu2xEX";//存储视频片段的文件夹(名称) - //========================== - // 检测之前的视频配置文件 - //========================== - QString VideoConfiguration_fullPath = file_path+"/VideoConfiguration_"+file_name+"_"+file_ext+"_Waifu2xEX.ini"; - if(QFile::exists(VideoConfiguration_fullPath)) - { - QSettings *configIniRead = new QSettings(VideoConfiguration_fullPath, QSettings::IniFormat); - configIniRead->setIniCodec(QTextCodec::codecForName("UTF-8")); - //=================== 加载之前存储的视频信息 ========================= - int ScaleRatio_old = configIniRead->value("/VideoConfiguration/ScaleRatio").toInt(); - int DenoiseLevel_old = configIniRead->value("/VideoConfiguration/DenoiseLevel").toInt(); - bool CustRes_isEnabled_old = configIniRead->value("/VideoConfiguration/CustRes_isEnabled").toBool(); - int CustRes_height_old = configIniRead->value("/VideoConfiguration/CustRes_height").toInt(); - int CustRes_width_old = configIniRead->value("/VideoConfiguration/CustRes_width").toInt(); - QString EngineName_old = configIniRead->value("/VideoConfiguration/EngineName").toString(); - bool isProcessBySegment_old = configIniRead->value("/VideoConfiguration/isProcessBySegment").toBool(); - bool isVideoFrameInterpolationEnabled_old = configIniRead->value("/VideoConfiguration/isVideoFrameInterpolationEnabled").toBool(); - int MultipleOfFPS_old = configIniRead->value("/VideoConfiguration/MultipleOfFPS").toInt(); - //=================== 比对信息 ================================ - if(EngineName_old=="waifu2x-caffe") - { - if(CustRes_isEnabled_old==false&&CustRes_isEnabled==false) - { - if(ScaleRatio_old!=ScaleRatio||DenoiseLevel_old!=DenoiseLevel) - { - isVideoConfigChanged=true; - } - else - { - isVideoConfigChanged=false; - } - } - else - { - if(CustRes_isEnabled_old==true&&CustRes_isEnabled==true) - { - if(CustRes_height_old!=CustRes_height||CustRes_width_old!=CustRes_width) - { - isVideoConfigChanged=true; - } - else - { - isVideoConfigChanged=false; - } - } - else - { - isVideoConfigChanged=true; - } - } - if(isProcessBySegment_old == false) - { - isVideoConfigChanged=true; - } - if(isVideoFrameInterpolationEnabled_old != ui->groupBox_FrameInterpolation->isChecked()) - { - isVideoConfigChanged=true; - } - if(MultipleOfFPS_old != ui->spinBox_MultipleOfFPS_VFI->value() && ui->groupBox_FrameInterpolation->isChecked()) - { - isVideoConfigChanged=true; - } - } - else - { - isVideoConfigChanged=true; - } - //============ 修正文件夹名称 ============= - QString VideoClipsFolderPath_old = configIniRead->value("/VideoConfiguration/VideoClipsFolderPath").toString(); - QString VideoClipsFolderName_old = configIniRead->value("/VideoConfiguration/VideoClipsFolderName").toString(); - file_mkDir(VideoClipsFolderPath_old); - if(file_isDirExist(VideoClipsFolderPath_old)==true) - { - VideoClipsFolderPath = VideoClipsFolderPath_old; - VideoClipsFolderName = VideoClipsFolderName_old; - } - } - else - { - emit Send_video_write_VideoConfiguration(VideoConfiguration_fullPath,ScaleRatio,DenoiseLevel,CustRes_isEnabled,CustRes_height,CustRes_width,"waifu2x-caffe",true,VideoClipsFolderPath,VideoClipsFolderName,ui->groupBox_FrameInterpolation->isChecked(),ui->spinBox_MultipleOfFPS_VFI->value()); - } - //======================= - // 检测缓存是否存在 - //======================= - if(file_isDirExist(SplitFramesFolderPath)) - { - if(!isVideoConfigChanged) - { - isCacheExists=true; - emit Send_TextBrowser_NewMessage(tr("The previous video cache file is detected and processing of the previous video cache will continue. If you want to restart processing of the current video:[")+SourceFile_fullPath+tr("], delete the cache manually.")); - } - else - { - isCacheExists=false; - //======== - QFile::remove(VideoConfiguration_fullPath); - file_DelDir(SplitFramesFolderPath); - file_DelDir(VideoClipsFolderPath); - QFile::remove(AudioPath); - DelVfiDir(video_mp4_fullpath); - emit Send_video_write_VideoConfiguration(VideoConfiguration_fullPath,ScaleRatio,DenoiseLevel,CustRes_isEnabled,CustRes_height,CustRes_width,"waifu2x-caffe",true,VideoClipsFolderPath,VideoClipsFolderName,ui->groupBox_FrameInterpolation->isChecked(),ui->spinBox_MultipleOfFPS_VFI->value()); - //======= - emit Send_TextBrowser_NewMessage(tr("The previous video cache file was detected, but because you changed the settings about the video resolution or denoise level, the previous cache will be deleted and processing of the video:[")+SourceFile_fullPath+tr("] will restart.")); - } - } - else - { - isCacheExists=false; - //======== - QFile::remove(VideoConfiguration_fullPath); - file_DelDir(SplitFramesFolderPath); - file_DelDir(VideoClipsFolderPath); - QFile::remove(AudioPath); - DelVfiDir(video_mp4_fullpath); - emit Send_video_write_VideoConfiguration(VideoConfiguration_fullPath,ScaleRatio,DenoiseLevel,CustRes_isEnabled,CustRes_height,CustRes_width,"waifu2x-caffe",true,VideoClipsFolderPath,VideoClipsFolderName,ui->groupBox_FrameInterpolation->isChecked(),ui->spinBox_MultipleOfFPS_VFI->value()); - //======== - } - /*==================================== - 提取音频 - ======================================*/ - if(!QFile::exists(AudioPath)) - { - video_get_audio(video_mp4_fullpath,AudioPath); - } - //================================== 开始分段处理视频 ================================================= - int StartTime = 0;//起始时间(秒) - int VideoDuration = video_get_duration(video_mp4_fullpath); - bool isSplitComplete = false; - bool isScaleComplete = false; - /* - ============================================ - 开始之前先读取进度 - ============================================ - */ - int OLD_SegmentDuration=-1; - bool read_OLD_SegmentDuration =false; - int LastVideoClipNo = -1; - if(QFile::exists(VideoConfiguration_fullPath)) - { - QSettings *configIniRead = new QSettings(VideoConfiguration_fullPath, QSettings::IniFormat); - configIniRead->setIniCodec(QTextCodec::codecForName("UTF-8")); - //=================== 加载进度 ========================= - StartTime = configIniRead->value("/Progress/StartTime").toInt(); - isSplitComplete = configIniRead->value("/Progress/isSplitComplete").toBool(); - isScaleComplete = configIniRead->value("/Progress/isScaleComplete").toBool(); - OLD_SegmentDuration = configIniRead->value("/Progress/OLDSegmentDuration").toInt(); - LastVideoClipNo = configIniRead->value("/Progress/LastVideoClipNo").toInt(); - } - if(OLD_SegmentDuration>0) - { - read_OLD_SegmentDuration = true; - } - /* - 加载进度条 - */ - int SegmentDuration_tmp_progressbar = 0; - if(read_OLD_SegmentDuration) - { - SegmentDuration_tmp_progressbar = OLD_SegmentDuration; - } - else - { - SegmentDuration_tmp_progressbar = SegmentDuration; - } - if(ui->checkBox_ShowInterPro->isChecked()&&VideoDuration>SegmentDuration_tmp_progressbar) - { - emit Send_CurrentFileProgress_Start(file_name+"."+file_ext,VideoDuration); - if(StartTime>0) - { - emit Send_CurrentFileProgress_progressbar_Add_SegmentDuration(StartTime); - } - } - /* - ============================================ - 正式开始处理 - ============================================ - */ - int SegmentDuration_tmp=0; - int TimeLeft_tmp=0; - while(VideoDuration>StartTime) - { - /*========================== - 计算视频片段时间 - ==========================*/ - TimeLeft_tmp = VideoDuration-StartTime; - if((TimeLeft_tmp)>=SegmentDuration) - { - SegmentDuration_tmp = SegmentDuration; - } - else - { - SegmentDuration_tmp = TimeLeft_tmp; - } - if(read_OLD_SegmentDuration) - { - SegmentDuration_tmp = OLD_SegmentDuration; - read_OLD_SegmentDuration=false; - } - /*========================== - 拆分视频片段 - ==========================*/ - if(isSplitComplete==false) - { - if(file_isDirExist(SplitFramesFolderPath)) - { - file_DelDir(SplitFramesFolderPath); - file_mkDir(SplitFramesFolderPath); - } - else - { - file_mkDir(SplitFramesFolderPath); - } - video_video2images_ProcessBySegment(video_mp4_fullpath,SplitFramesFolderPath,StartTime,SegmentDuration_tmp); - if(waifu2x_STOP) - { - emit Send_Table_video_ChangeStatus_rowNumInt_statusQString(rowNum, "Interrupted"); - return 0;//如果启用stop位,则直接return - } - } - /*========================== - 处理视频片段的帧 - ==========================*/ - if(isScaleComplete==false) - { - //============================== 扫描获取文件名 =============================== - QStringList Frame_fileName_list = file_getFileNames_in_Folder_nofilter(SplitFramesFolderPath); - if(isSplitComplete==false) - { - if(Frame_fileName_list.isEmpty())//检查是否成功拆分为帧 - { - emit Send_TextBrowser_NewMessage(tr("Error occured when processing [")+SourceFile_fullPath+tr("]. Error: [Unable to split video into pictures.]")); - emit Send_Table_video_ChangeStatus_rowNumInt_statusQString(rowNum, "Failed"); - emit Send_progressbar_Add(); - return 0;//如果启用stop位,则直接return - } - } - /* - 记录进度 - 帧拆分成功 - */ - emit Send_video_write_Progress_ProcessBySegment(VideoConfiguration_fullPath,StartTime,true,false,SegmentDuration_tmp,LastVideoClipNo); - //============================== 放大 ======================================= - //===========建立存储放大后frame的文件夹=========== - if(isSplitComplete==false) - { - if(file_isDirExist(ScaledFramesFolderPath)) - { - file_DelDir(ScaledFramesFolderPath); - file_mkDir(ScaledFramesFolderPath); - } - else - { - file_mkDir(ScaledFramesFolderPath); - } - } - //==========开始放大========================== - FileProgressWatch_isEnabled=true; - QFuture FileProgressWatch_QFuture = QtConcurrent::run(this, &MainWindow::CurrentFileProgress_WatchFolderFileNum_Textbrower, SourceFile_fullPath,ScaledFramesFolderPath,Frame_fileName_list.size()+file_getFileNames_in_Folder_nofilter(ScaledFramesFolderPath).size()); - if(ui->checkBox_ShowInterPro->isChecked()==false) - { - FileProgressWatch_isEnabled=false; - FileProgressWatch_QFuture.cancel(); - } - //=======获取显卡信息======== - int NumOfGPU = 1; - if(ui->checkBox_EnableMultiGPU_Waifu2xCaffe->isChecked()==true) - { - NumOfGPU = Get_NumOfGPU_W2xCaffe(); - } - //============创建显卡文件夹=========== - QStringList GPU_SplitFramesFolderPath_List; - for(int i = 0; i < NumOfGPU; i++) - { - QString GPU_SplitFramesFolderPath = SplitFramesFolderPath+"/"+"GPU_"+QString::number(i); - if(file_isDirExist(GPU_SplitFramesFolderPath)==false) - { - file_DelDir(GPU_SplitFramesFolderPath); - file_mkDir(GPU_SplitFramesFolderPath); - } - else - { - file_mkDir(GPU_SplitFramesFolderPath); - } - GPU_SplitFramesFolderPath_List.append(GPU_SplitFramesFolderPath); - } - int TotalFramesNum = Frame_fileName_list.size(); - int FramesNumForEachGPU = TotalFramesNum/NumOfGPU; - if(FramesNumForEachGPU<1)FramesNumForEachGPU=1; - int start_num=0; - for(int x = 0; x < GPU_SplitFramesFolderPath_List.size(); x++) - { - if(x==GPU_SplitFramesFolderPath_List.size()-1)FramesNumForEachGPU=TotalFramesNum; - QStringList file_waitformove = Frame_fileName_list.mid(start_num,FramesNumForEachGPU); - for(int i = 0; i < file_waitformove.size(); i++) - { - QString FileName = file_waitformove.at(i); - QFile::rename(SplitFramesFolderPath+"/"+FileName,GPU_SplitFramesFolderPath_List.at(x)+"/"+FileName); - } - start_num+=FramesNumForEachGPU; - } - //========================= - bool Frame_failed = false;//放大失败标志 - QMap Sub_Thread_info; - Sub_Thread_info["ScaledFramesFolderPath"]=ScaledFramesFolderPath; - if(CustRes_isEnabled == true) - { - Sub_Thread_info["ScaleRatio"] = QString("%1").arg(CustRes_CalNewScaleRatio(video_mp4_fullpath,CustRes_height,CustRes_width)); - } - else - { - Sub_Thread_info["ScaleRatio"] = QString("%1").arg(ScaleRatio); - } - //========================= - for(int i = 0; i < GPU_SplitFramesFolderPath_List.size(); i++) - { - Sub_Thread_info["SplitFramesFolderPath"]=GPU_SplitFramesFolderPath_List.at(i); - mutex_SubThreadNumRunning.lock(); - Sub_video_ThreadNumRunning++; - mutex_SubThreadNumRunning.unlock(); - QtConcurrent::run(this,&MainWindow::Waifu2x_Caffe_Video_scale,Sub_Thread_info,&Sub_video_ThreadNumRunning,&Frame_failed); - while (Sub_video_ThreadNumRunning >= NumOfGPU) - { - Delay_msec_sleep(500); - } - if(waifu2x_STOP) - { - while (Sub_video_ThreadNumRunning > 0) - { - Delay_msec_sleep(500); - } - FileProgressWatch_isEnabled=false; - FileProgressWatch_QFuture.cancel(); - Restore_SplitFramesFolderPath(SplitFramesFolderPath,GPU_SplitFramesFolderPath_List); - emit Send_Table_video_ChangeStatus_rowNumInt_statusQString(rowNum, "Interrupted"); - return 0;//如果启用stop位,则直接return - } - if(Frame_failed) - { - FileProgressWatch_isEnabled=false; - FileProgressWatch_QFuture.cancel(); - Restore_SplitFramesFolderPath(SplitFramesFolderPath,GPU_SplitFramesFolderPath_List); - emit Send_TextBrowser_NewMessage(tr("Error occured when processing [")+SourceFile_fullPath+tr("]. Error: [Failed to scale frames.]")); - emit Send_Table_video_ChangeStatus_rowNumInt_statusQString(rowNum, "Failed"); - emit Send_progressbar_Add(); - return 0;//如果启用stop位,则直接return - } - } - while (Sub_video_ThreadNumRunning!=0) - { - Delay_msec_sleep(500); - } - FileProgressWatch_isEnabled=false; - FileProgressWatch_QFuture.cancel(); - //================ 扫描放大后的帧文件数量,判断是否放大成功 ======================= - QStringList Frame_fileName_list_scaled = file_getFileNames_in_Folder_nofilter(ScaledFramesFolderPath); - if(Frame_fileName_list_scaled.size()checkBox_ShowInterPro->isChecked()) - { - emit Send_CurrentFileProgress_progressbar_Add_SegmentDuration(SegmentDuration_tmp); - } - StartTime+=SegmentDuration_tmp; - isSplitComplete = false; - isScaleComplete = false; - LastVideoClipNo=VideoClipNo; - emit Send_video_write_Progress_ProcessBySegment(VideoConfiguration_fullPath,StartTime,false,false,-1,VideoClipNo); - } - emit Send_CurrentFileProgress_Stop(); - //====================================================== - // 组装(片段到成片) - //====================================================== - QString video_mp4_scaled_fullpath = ""; - if(CustRes_isEnabled) - { - video_mp4_scaled_fullpath = file_path+"/"+file_name+"_waifu2x_"+QString::number(CustRes_width,10)+"x"+QString::number(CustRes_height,10)+"_"+QString::number(DenoiseLevel,10)+"n"+"_"+file_ext+".mp4"; - } - else - { - video_mp4_scaled_fullpath = file_path+"/"+file_name+"_waifu2x_"+QString::number(ScaleRatio,10)+"x_"+QString::number(DenoiseLevel,10)+"n"+"_"+file_ext+".mp4"; - } - QFile::remove(video_mp4_scaled_fullpath); - video_AssembleVideoClips(VideoClipsFolderPath,VideoClipsFolderName,video_mp4_scaled_fullpath,AudioPath); - if(QFile::exists(video_mp4_scaled_fullpath)==false)//检查是否成功生成视频 - { - if(waifu2x_STOP) - { - emit Send_Table_video_ChangeStatus_rowNumInt_statusQString(rowNum, "Interrupted"); - return 0;//如果启用stop位,则直接return - } - emit Send_TextBrowser_NewMessage(tr("Error occured when processing [")+SourceFile_fullPath+tr("]. Error: [Unable to assemble video clips.]")); - emit Send_Table_video_ChangeStatus_rowNumInt_statusQString(rowNum, "Failed"); - emit Send_progressbar_Add(); - return 0;//如果启用stop位,则直接return - } - //============================== 删除缓存文件 ==================================================== - if(ui->checkBox_KeepVideoCache->isChecked()==false) - { - QFile::remove(VideoConfiguration_fullPath); - file_DelDir(SplitFramesFolderPath); - file_DelDir(VideoClipsFolderPath); - QFile::remove(AudioPath); - if(SourceFile_fullPath!=video_mp4_fullpath)QFile::remove(video_mp4_fullpath); - } - else - { - DelOriginal=false; - } - //============================= 删除原文件 & & 更新table status ============================ - if(DelOriginal) - { - if(ReplaceOriginalFile(SourceFile_fullPath,video_mp4_scaled_fullpath)==false) - { - if(QAction_checkBox_MoveToRecycleBin_checkBox_DelOriginal->isChecked()) - { - file_MoveToTrash(SourceFile_fullPath); - } - else - { - QFile::remove(SourceFile_fullPath); - } - } - emit Send_Table_video_ChangeStatus_rowNumInt_statusQString(rowNum, "Finished, original file deleted"); - } - else - { - emit Send_Table_video_ChangeStatus_rowNumInt_statusQString(rowNum, "Finished"); - } - //========== 移动到输出路径 ========= - if(ui->checkBox_OutPath_isEnabled->isChecked()) - { - MoveFileToOutputPath(video_mp4_scaled_fullpath,SourceFile_fullPath); - } - //============================ 更新进度条 ================================= - emit Send_progressbar_Add(); - //=========================== ============================== - return 0; -} -/* -视频帧放大函数 -*/ -int MainWindow::Waifu2x_Caffe_Video_scale(QMap Sub_Thread_info,int *Sub_video_ThreadNumRunning,bool *Frame_failed) -{ - bool AllFinished=true; - QString SplitFramesFolderPath = Sub_Thread_info["SplitFramesFolderPath"]; - QString ScaledFramesFolderPath = Sub_Thread_info["ScaledFramesFolderPath"]; - //=========== - int ScaleRatio = Sub_Thread_info["ScaleRatio"].toInt(); - int DenoiseLevel = ui->spinBox_DenoiseLevel_video->value(); - //=========== - QString program = Current_Path + "/waifu2x-caffe/waifu2x-caffe_waifu2xEX.exe"; - //==== - QString ImageProcessingModeCMD = ""; - if(DenoiseLevel==-1) - { - ImageProcessingModeCMD = " -m scale -s " + QString::number(ScaleRatio, 10)+" "; - } - else - { - int DenoiseLevel_tmp =0; - if((ui->comboBox_Model_2D_Waifu2xCaffe->currentIndex()==0)&&(DenoiseLevel==0)&&(ui->comboBox_ImageStyle_Waifu2xCaffe->currentIndex()==0)) - { - DenoiseLevel_tmp=1; - } - else - { - DenoiseLevel_tmp = DenoiseLevel; - } - ImageProcessingModeCMD = " -m noise_scale -s " + QString::number(ScaleRatio, 10)+ " -n " + QString::number(DenoiseLevel_tmp, 10)+" "; - } - //======= - //======================================================================== - QStringList InputFilesNameList = file_getFileNames_in_Folder_nofilter(SplitFramesFolderPath); - QStringList OutPutFilesFullPathList; - for(int i=0; ispinBox_retry->value()+ForceRetryCount); retry++) - { - Waifu2x->start(cmd); - while(!Waifu2x->waitForStarted(100)&&!QProcess_stop) {} - while(!Waifu2x->waitForFinished(500)&&!QProcess_stop) - { - if(waifu2x_STOP) - { - QStringList FinfishedFileList = WaitForEngineIO(OutPutFilesFullPathList); - Waifu2x->close(); - //============ - QString file_fullpath_tmp; - for(int i=0; ispinBox_retry->value()+(ForceRetryCount-1))break; - Delay_sec_sleep(5); - emit Send_TextBrowser_NewMessage(tr("Automatic retry, please wait.")); - AllFinished=false; - break; - } - } - if(AllFinished)break; - } - //========= - AllFinished = true; - for(int i=0; icomboBox_ProcessMode_Waifu2xCaffe->currentIndex()) - { - case 0: - { - Waifu2x_Caffe_Settings_str.append("-p cpu "); - break; - } - case 1: - { - Waifu2x_Caffe_Settings_str.append("-p gpu "); - break; - } - case 2: - { - Waifu2x_Caffe_Settings_str.append("-p cudnn "); - break; - } - } - //模型 - QString model_folder_path = Current_Path + "/waifu2x-caffe/models/"; - int ImageStyle = ui->comboBox_ImageStyle_Waifu2xCaffe->currentIndex(); - switch(ImageStyle) - { - case 0: - { - switch(ui->comboBox_Model_2D_Waifu2xCaffe->currentIndex()) - { - case 0: - { - Waifu2x_Caffe_Settings_str.append("--model_dir \""+model_folder_path+"anime_style_art\" "); - break; - } - case 1: - { - Waifu2x_Caffe_Settings_str.append("--model_dir \""+model_folder_path+"anime_style_art_rgb\" "); - break; - } - case 2: - { - Waifu2x_Caffe_Settings_str.append("--model_dir \""+model_folder_path+"cunet\" "); - break; - } - case 3: - { - Waifu2x_Caffe_Settings_str.append("--model_dir \""+model_folder_path+"photo\" "); - break; - } - case 4: - { - Waifu2x_Caffe_Settings_str.append("--model_dir \""+model_folder_path+"upconv_7_anime_style_art_rgb\" "); - break; - } - case 5: - { - Waifu2x_Caffe_Settings_str.append("--model_dir \""+model_folder_path+"upconv_7_photo\" "); - break; - } - case 6: - { - Waifu2x_Caffe_Settings_str.append("--model_dir \""+model_folder_path+"upresnet10\" "); - break; - } - } - break; - } - case 1: - { - switch(ui->comboBox_Model_3D_Waifu2xCaffe->currentIndex()) - { - case 0: - { - Waifu2x_Caffe_Settings_str.append("--model_dir \""+model_folder_path+"upconv_7_photo\" "); - break; - } - case 1: - { - Waifu2x_Caffe_Settings_str.append("--model_dir \""+model_folder_path+"photo\" "); - break; - } - } - break; - } - } - //TTA - if(ui->checkBox_TTA_Waifu2xCaffe->isChecked()) - { - Waifu2x_Caffe_Settings_str.append("-t 1 "); - } - else - { - Waifu2x_Caffe_Settings_str.append("-t 0 "); - } - //显卡设定 - if(ui->checkBox_EnableMultiGPU_Waifu2xCaffe->isChecked()==false) - { - //单个显卡 - //GPU ID - if(ui->comboBox_ProcessMode_Waifu2xCaffe->currentIndex()>0) - { - Waifu2x_Caffe_Settings_str.append("--gpu "+QString::number(ui->spinBox_GPUID_Waifu2xCaffe->value(),10)+" "); - } - //Batch size - Waifu2x_Caffe_Settings_str.append("-b "+QString::number(ui->spinBox_BatchSize_Waifu2xCaffe->value(),10)+" "); - //Split size - Waifu2x_Caffe_Settings_str.append("-c "+QString::number(ui->spinBox_SplitSize_Waifu2xCaffe->value(),10)+" "); - } - return Waifu2x_Caffe_Settings_str; -} -/* -Waifu2x_Caffe -读取配置生成配置string -*/ -QString MainWindow::Waifu2x_Caffe_ReadSettings() -{ - QString Waifu2x_Caffe_Settings_str = ""; - Waifu2x_Caffe_Settings_str.append(Waifu2xCaffe_PreLoad_Settings_Str); - //显卡设定 - if(ui->checkBox_EnableMultiGPU_Waifu2xCaffe->isChecked()) - { - //多显卡 - Waifu2x_Caffe_Settings_str.append(Waifu2xCaffe_GetGPUInfo()+" "); - } - return Waifu2x_Caffe_Settings_str; -} -//判断是否启用了caffe引擎 -bool MainWindow::isWaifu2xCaffeEnabled() -{ - if(ui->comboBox_Engine_Image->currentIndex()!=4&&ui->comboBox_Engine_GIF->currentIndex()!=4&&ui->comboBox_Engine_Video->currentIndex()!=4) - { - ui->label_ImageStyle_W2xCaffe->setVisible(0); - ui->comboBox_ImageStyle_Waifu2xCaffe->setVisible(0); - ui->comboBox_ImageStyle_Waifu2xCaffe->setEnabled(0); - return false; - } - else - { - ui->label_ImageStyle_W2xCaffe->setVisible(1); - ui->comboBox_ImageStyle_Waifu2xCaffe->setVisible(1); - ui->comboBox_ImageStyle_Waifu2xCaffe->setEnabled(1); - return true; - } -} -/* -删除caffe引擎生成的错误日志 -*/ -void MainWindow::DeleteErrorLog_Waifu2xCaffe() -{ - QStringList FileNameList = file_getFileNames_in_Folder_nofilter(Current_Path);//读取合法的文件名 - QString Full_Path_File = ""; - if(!FileNameList.isEmpty()) - { - for(int i = 0; i < FileNameList.size(); i++) - { - QString tmp = FileNameList.at(i); - Full_Path_File = Current_Path + "/" + tmp; - if(Full_Path_File.contains("error_log_")) - { - QFile::remove(Full_Path_File); - } - } - } -} - -void MainWindow::on_checkBox_EnableMultiGPU_Waifu2xCaffe_stateChanged(int arg1) -{ - if(ui->checkBox_EnableMultiGPU_Waifu2xCaffe->isChecked()) - { - ui->lineEdit_MultiGPUInfo_Waifu2xCaffe->setEnabled(1); - ui->pushButton_VerifyGPUsConfig_Waifu2xCaffe->setEnabled(1); - //=== - ui->pushButton_SplitSize_Add_Waifu2xCaffe->setEnabled(0); - ui->pushButton_SplitSize_Minus_Waifu2xCaffe->setEnabled(0); - ui->spinBox_BatchSize_Waifu2xCaffe->setEnabled(0); - ui->spinBox_GPUID_Waifu2xCaffe->setEnabled(0); - ui->spinBox_SplitSize_Waifu2xCaffe->setEnabled(0); - } - else - { - ui->lineEdit_MultiGPUInfo_Waifu2xCaffe->setEnabled(0); - ui->pushButton_VerifyGPUsConfig_Waifu2xCaffe->setEnabled(0); - //=== - ui->pushButton_SplitSize_Add_Waifu2xCaffe->setEnabled(1); - ui->pushButton_SplitSize_Minus_Waifu2xCaffe->setEnabled(1); - ui->spinBox_BatchSize_Waifu2xCaffe->setEnabled(1); - ui->spinBox_GPUID_Waifu2xCaffe->setEnabled(1); - ui->spinBox_SplitSize_Waifu2xCaffe->setEnabled(1); - } -} - -void MainWindow::on_comboBox_ProcessMode_Waifu2xCaffe_currentIndexChanged(int index) -{ - if(ui->comboBox_ProcessMode_Waifu2xCaffe->currentIndex()==0) - { - ui->checkBox_EnableMultiGPU_Waifu2xCaffe->setEnabled(0); - ui->checkBox_EnableMultiGPU_Waifu2xCaffe->setChecked(0); - } - else - { - ui->checkBox_EnableMultiGPU_Waifu2xCaffe->setEnabled(1); - } -} -//读取多显卡设定 -QString MainWindow::Waifu2xCaffe_GetGPUInfo() -{ - GetGPUInfo_QMutex_Waifu2xCaffe.lock(); - //==== - QStringList GPU_List = ui->lineEdit_MultiGPUInfo_Waifu2xCaffe->text().trimmed().remove(" ").remove(" ").split(":"); - GPU_List.removeDuplicates(); - GPU_List.removeAll(""); - //==== - int MAX_GPU_ID_Waifu2xCaffe = GPU_List.size()-1; - if(GPU_ID_Waifu2xCaffe_GetGPUInfo>MAX_GPU_ID_Waifu2xCaffe) - { - GPU_ID_Waifu2xCaffe_GetGPUInfo=0; - } - //====== - QString GPUInfo=""; - QStringList GPUID_BatchSize_SplitSize = GPU_List.at(GPU_ID_Waifu2xCaffe_GetGPUInfo).split(","); - GPUID_BatchSize_SplitSize.removeAll(""); - if(GPUID_BatchSize_SplitSize.size()==3) - { - GPUInfo = "--gpu "+GPUID_BatchSize_SplitSize.at(0).trimmed()+" -b "+GPUID_BatchSize_SplitSize.at(1).trimmed()+" -c "+GPUID_BatchSize_SplitSize.at(2).trimmed(); - } - else - { - GPUInfo = "--gpu 0 -b 1 -c 64"; - } - //====== - GPU_ID_Waifu2xCaffe_GetGPUInfo++; - if(GPU_ID_Waifu2xCaffe_GetGPUInfo>MAX_GPU_ID_Waifu2xCaffe) - { - GPU_ID_Waifu2xCaffe_GetGPUInfo=0; - } - //====== - GetGPUInfo_QMutex_Waifu2xCaffe.unlock(); - return GPUInfo; -} - -void MainWindow::on_lineEdit_MultiGPUInfo_Waifu2xCaffe_editingFinished() -{ - QString Format_str="0123456789:,"; - QString GPUs_str = ui->lineEdit_MultiGPUInfo_Waifu2xCaffe->text().trimmed().replace(":",":").replace(",",",").remove(" ").remove(" "); - for (int i=0; ilineEdit_MultiGPUInfo_Waifu2xCaffe->setText(GPUs_str); -} - -void MainWindow::on_pushButton_VerifyGPUsConfig_Waifu2xCaffe_clicked() -{ - on_lineEdit_MultiGPUInfo_Waifu2xCaffe_editingFinished(); - QStringList GPU_List = ui->lineEdit_MultiGPUInfo_Waifu2xCaffe->text().trimmed().remove(" ").remove(" ").split(":"); - GPU_List.removeDuplicates(); - GPU_List.removeAll(""); - //====== - QString VerRes = ""; - //====== - for (int i=0; isetWindowTitle(tr("GPUs List according to your configuration")); - MSG->setText(VerRes); - MSG->setIcon(QMessageBox::Information); - MSG->setModal(true); - MSG->show(); - //====== - emit Send_TextBrowser_NewMessage("\nWaifu2x-caffe GPUs List(user configuration):\n"+VerRes); -} - -int MainWindow::Get_NumOfGPU_W2xCaffe() -{ - QStringList GPU_List = ui->lineEdit_MultiGPUInfo_Waifu2xCaffe->text().trimmed().remove(" ").remove(" ").split(":"); - GPU_List.removeDuplicates(); - GPU_List.removeAll(""); - int GPUNum = 0; - QStringList GPUID_BatchSize_SplitSize; - //====== - for (int i=0; i FileProgressWatch_QFuture = QtConcurrent::run(this, &MainWindow::CurrentFileProgress_WatchFolderFileNum, scaledFramesFolder);//启动waifu2x 主线程 - if(ui->checkBox_ShowInterPro->isChecked()==false) - { - FileProgressWatch_isEnabled=false; - FileProgressWatch_QFuture.cancel(); - emit Send_CurrentFileProgress_Stop(); - } - //=======获取显卡信息======== - int NumOfGPU = 1; - if(ui->checkBox_EnableMultiGPU_Waifu2xCaffe->isChecked()==true) - { - NumOfGPU = Get_NumOfGPU_W2xCaffe(); - } - //============创建显卡文件夹=========== - QStringList GPU_splitFramesFolder_List; - for(int i = 0; i < NumOfGPU; i++) - { - QString GPU_splitFramesFolder = splitFramesFolder+"/"+"GPU_"+QString::number(i); - if(file_isDirExist(GPU_splitFramesFolder)) - { - file_DelDir(GPU_splitFramesFolder); - file_mkDir(GPU_splitFramesFolder); - } - else - { - file_mkDir(GPU_splitFramesFolder); - } - GPU_splitFramesFolder_List.append(GPU_splitFramesFolder); - } - int TotalFramesNum = framesFileName_qStrList.size(); - int FramesNumForEachGPU = TotalFramesNum/NumOfGPU; - if(FramesNumForEachGPU<1)FramesNumForEachGPU=1; - int start_num=0; - for(int x = 0; x < GPU_splitFramesFolder_List.size(); x++) - { - if(x==GPU_splitFramesFolder_List.size()-1)FramesNumForEachGPU=TotalFramesNum; - QStringList file_waitformove = framesFileName_qStrList.mid(start_num,FramesNumForEachGPU); - for(int i = 0; i < file_waitformove.size(); i++) - { - QString FileName = file_waitformove.at(i); - QFile::rename(splitFramesFolder+"/"+FileName,GPU_splitFramesFolder_List.at(x)+"/"+FileName); - } - start_num+=FramesNumForEachGPU; - } - //========================= - bool Frame_failed = false;//放大失败标志 - int Sub_gif_ThreadNumRunning = 0; - //==== - QMap Sub_Thread_info; - Sub_Thread_info["scaledFramesFolder"]= scaledFramesFolder; - if(CustRes_isContained(sourceFileFullPath)) - { - QMap Res_map = CustRes_getResMap(sourceFileFullPath);//res_map["fullpath"],["height"],["width"] - Sub_Thread_info["ScaleRatio"] = QString("%1").arg(CustRes_CalNewScaleRatio(sourceFileFullPath,Res_map["height"].toInt(),Res_map["width"].toInt())); - } - else - { - Sub_Thread_info["ScaleRatio"] = QString("%1").arg(qRound(ui->doubleSpinBox_ScaleRatio_gif->value())); - } - //========================= - for(int i = 0; i < GPU_splitFramesFolder_List.size(); i++) - { - Sub_Thread_info["splitFramesFolder"]=GPU_splitFramesFolder_List.at(i); - mutex_SubThreadNumRunning.lock(); - Sub_gif_ThreadNumRunning++; - mutex_SubThreadNumRunning.unlock(); - QtConcurrent::run(this,&MainWindow::Waifu2x_Caffe_APNG_scale,Sub_Thread_info,&Sub_gif_ThreadNumRunning,&Frame_failed); - while (Sub_gif_ThreadNumRunning >= NumOfGPU) - { - Delay_msec_sleep(500); - } - if(waifu2x_STOP) - { - while (Sub_gif_ThreadNumRunning > 0) - { - Delay_msec_sleep(500); - } - FileProgressWatch_isEnabled=false; - FileProgressWatch_QFuture.cancel(); - return false; - } - if(Frame_failed) - { - FileProgressWatch_isEnabled=false; - FileProgressWatch_QFuture.cancel(); - emit Send_TextBrowser_NewMessage(tr("Error occured when processing [")+sourceFileFullPath+tr("]. Error: [Failed to scale frames.]")); - return false; - } - } - while (Sub_gif_ThreadNumRunning!=0) - { - Delay_msec_sleep(500); - } - FileProgressWatch_isEnabled=false; - FileProgressWatch_QFuture.cancel(); - emit Send_CurrentFileProgress_Stop(); - //======================= 检查是否成功放大所有帧 =========================== - QStringList framesFileName_qStrList_scaled = file_getFileNames_in_Folder_nofilter(scaledFramesFolder); - if(framesFileName_qStrList.size()!=framesFileName_qStrList_scaled.size()) - { - emit Send_TextBrowser_NewMessage(tr("Error occured when processing [")+sourceFileFullPath+tr("]. Error: [Failed to scale frames.]")); - return false; - } - //============================================================ - //组装apng - APNG_Frames2APNG(sourceFileFullPath, scaledFramesFolder, resultFileFullPath, false); - return true; -} -/* -Waifu2x Caffe APNG 放大子线程 -*/ -int MainWindow::Waifu2x_Caffe_APNG_scale(QMap Sub_Thread_info,int *Sub_gif_ThreadNumRunning,bool *Frame_failed) -{ - bool AllFinished=true; - QString splitFramesFolder = Sub_Thread_info["splitFramesFolder"]; - QString scaledFramesFolder = Sub_Thread_info["scaledFramesFolder"]; - //=========== - int ScaleRatio = Sub_Thread_info["ScaleRatio"].toInt(); - int DenoiseLevel = ui->spinBox_DenoiseLevel_gif->value(); - //=========== - QString program = Current_Path + "/waifu2x-caffe/waifu2x-caffe_waifu2xEX.exe"; - //==== - QString ImageProcessingModeCMD = ""; - if(DenoiseLevel==-1) - { - ImageProcessingModeCMD = " -m scale -s " + QString::number(ScaleRatio, 10)+" "; - } - else - { - int DenoiseLevel_tmp =0; - if((ui->comboBox_Model_2D_Waifu2xCaffe->currentIndex()==0)&&(DenoiseLevel==0)&&(ui->comboBox_ImageStyle_Waifu2xCaffe->currentIndex()==0)) - { - DenoiseLevel_tmp=1; - } - else - { - DenoiseLevel_tmp = DenoiseLevel; - } - ImageProcessingModeCMD = " -m noise_scale -s " + QString::number(ScaleRatio, 10)+ " -n " + QString::number(DenoiseLevel_tmp, 10)+" "; - } - //======= - //======================================================================== - QStringList InputFilesNameList = file_getFileNames_in_Folder_nofilter(splitFramesFolder); - QStringList OutPutFilesFullPathList; - for(int i=0; ispinBox_retry->value()+ForceRetryCount); retry++) - { - Waifu2x->start(cmd); - while(!Waifu2x->waitForStarted(100)&&!QProcess_stop) {} - while(!Waifu2x->waitForFinished(500)&&!QProcess_stop) - { - if(waifu2x_STOP) - { - Waifu2x->close(); - mutex_SubThreadNumRunning.lock(); - *Sub_gif_ThreadNumRunning=*Sub_gif_ThreadNumRunning-1; - mutex_SubThreadNumRunning.unlock(); - return 0; - } - } - AllFinished = true; - for(int i=0; ispinBox_retry->value()+(ForceRetryCount-1))break; - Delay_sec_sleep(5); - emit Send_TextBrowser_NewMessage(tr("Automatic retry, please wait.")); - AllFinished=false; - break; - } - } - if(AllFinished)break; - } - //========= - AllFinished = true; - for(int i=0; i. + + My Github homepage: https://github.com/AaronFeng753 +*/ + +#include "mainwindow.h" +#include "ui_mainwindow.h" + +int MainWindow::Waifu2x_Caffe_Image(int rowNum,bool ReProcess_MissingAlphaChannel) +{ + //============================= 读取设置 ================================ + int DenoiseLevel = ui->spinBox_DenoiseLevel_image->value(); + bool DelOriginal = (ui->checkBox_DelOriginal->isChecked()||ui->checkBox_ReplaceOriginalFile->isChecked()); + QString OutPutPath_Final =""; + //========================= 拆解map得到参数 ============================= + emit Send_Table_image_ChangeStatus_rowNumInt_statusQString(rowNum, "Processing"); + QString SourceFile_fullPath = Table_model_image->item(rowNum,2)->text(); + if(!QFile::exists(SourceFile_fullPath)) + { + emit Send_TextBrowser_NewMessage(tr("Error occured when processing [")+SourceFile_fullPath+tr("]. Error: [File does not exist.]")); + emit Send_Table_image_ChangeStatus_rowNumInt_statusQString(rowNum, "Failed"); + emit Send_progressbar_Add(); + mutex_ThreadNumRunning.lock(); + ThreadNumRunning--; + mutex_ThreadNumRunning.unlock();//线程数量统计-1 + return 0; + } + //========= 转换到 PNG ========= + QString SourceFile_fullPath_Original = SourceFile_fullPath; + SourceFile_fullPath = Imgae_PreProcess(SourceFile_fullPath_Original,ReProcess_MissingAlphaChannel); + //======================================================= + int ScaleRatio = 2; + bool CustRes_isEnabled = false; + int CustRes_height=0; + int CustRes_width=0; + if(CustRes_isContained(SourceFile_fullPath_Original)) + { + CustRes_isEnabled=true; + QMap Res_map = CustRes_getResMap(SourceFile_fullPath_Original);//res_map["fullpath"],["height"],["width"] + ScaleRatio = CustRes_CalNewScaleRatio(SourceFile_fullPath,Res_map["height"].toInt(),Res_map["width"].toInt()); + if(ScaleRatio==0) + { + emit Send_TextBrowser_NewMessage(tr("Error occured when processing [")+SourceFile_fullPath_Original+tr("]. Error: [The resolution of the source file cannot be read, so the image cannot be scaled to a custom resolution.]")); + emit Send_Table_image_ChangeStatus_rowNumInt_statusQString(rowNum, "Failed"); + emit Send_progressbar_Add(); + mutex_ThreadNumRunning.lock(); + ThreadNumRunning--; + mutex_ThreadNumRunning.unlock();//线程数量统计-1 + return 0; + } + CustRes_height=Res_map["height"].toInt(); + CustRes_width=Res_map["width"].toInt(); + } + else + { + double ScaleRatio_double_tmp = ui->doubleSpinBox_ScaleRatio_image->value(); + if(ScaleRatio_double_tmp == (int)ScaleRatio_double_tmp) + { + ScaleRatio = qRound(ScaleRatio_double_tmp); + } + else + { + CustRes_isEnabled=true; + QMap Res_map = DoubleScaleRatio_Cal_NewScaleRatio_NewHW(SourceFile_fullPath,ScaleRatio_double_tmp); + //==== + if(Res_map.isEmpty()) + { + emit Send_TextBrowser_NewMessage(tr("Error occured when processing [")+SourceFile_fullPath+tr("]. Error: [Unable to read the resolution of the source file.]")); + emit Send_Table_image_ChangeStatus_rowNumInt_statusQString(rowNum, "Failed"); + emit Send_progressbar_Add(); + mutex_ThreadNumRunning.lock(); + ThreadNumRunning--; + mutex_ThreadNumRunning.unlock();//线程数量统计-1 + return 0; + } + //==== + ScaleRatio = Res_map["ScaleRatio"].toInt(); + CustRes_height = Res_map["Height_new"].toInt(); + CustRes_width = Res_map["width_new"].toInt(); + } + } + //======================================================= + QFileInfo fileinfo(SourceFile_fullPath); + QString file_name = file_getBaseName(SourceFile_fullPath); + QString file_ext = fileinfo.suffix(); + QString file_path = file_getFolderPath(fileinfo); + QString OutPut_Path = file_path + "/" + file_name + "_waifu2x_"+QString::number(ScaleRatio, 10)+"x_"+QString::number(DenoiseLevel, 10)+"n_"+file_ext+".png"; + //============================== 放大 ======================================= + QString Waifu2x_folder_path = Current_Path + "/waifu2x-caffe"; + QString program = Waifu2x_folder_path + "/waifu2x-caffe_waifu2xEX.exe"; + //==== + QString ImageProcessingModeCMD = ""; + if(DenoiseLevel==-1) + { + ImageProcessingModeCMD = " -m scale -s " + QString::number(ScaleRatio, 10)+" "; + } + else + { + int DenoiseLevel_tmp =0; + if((ui->comboBox_Model_2D_Waifu2xCaffe->currentIndex()==0)&&(DenoiseLevel==0)&&(ui->comboBox_ImageStyle_Waifu2xCaffe->currentIndex()==0)) + { + DenoiseLevel_tmp=1; + } + else + { + DenoiseLevel_tmp = DenoiseLevel; + } + ImageProcessingModeCMD = " -m noise_scale -s " + QString::number(ScaleRatio, 10)+ " -n " + QString::number(DenoiseLevel_tmp, 10)+" "; + } + //==== + QString cmd = "\"" + program + "\"" + " -i " + "\"" + SourceFile_fullPath + "\"" + " -o " + "\"" + OutPut_Path + "\"" + ImageProcessingModeCMD + Waifu2x_Caffe_ReadSettings(); + //======== + for(int retry=0; retry<(ui->spinBox_retry->value()+ForceRetryCount); retry++) + { + QProcess *Waifu2x = new QProcess(); + Waifu2x->start(cmd); + while(!Waifu2x->waitForStarted(100)&&!QProcess_stop) {} + while(!Waifu2x->waitForFinished(500)&&!QProcess_stop) + { + if(waifu2x_STOP) + { + Waifu2x->close(); + QFile::remove(OutPut_Path); + emit Send_Table_image_ChangeStatus_rowNumInt_statusQString(rowNum, "Interrupted"); + mutex_ThreadNumRunning.lock(); + ThreadNumRunning--; + mutex_ThreadNumRunning.unlock(); + return 0; + } + } + if(QFile::exists(OutPut_Path)) + { + break; + } + else + { + if(retry==ui->spinBox_retry->value()+(ForceRetryCount-1))break; + Delay_sec_sleep(5); + emit Send_TextBrowser_NewMessage(tr("Automatic retry, please wait.")); + } + } + //======== + if(!QFile::exists(OutPut_Path)) + { + if(SourceFile_fullPath_Original!=SourceFile_fullPath) + { + QFile::remove(SourceFile_fullPath); + } + emit Send_TextBrowser_NewMessage(tr("Error occured when processing [")+SourceFile_fullPath_Original+tr("]. Error: [Unable to scale the picture.]")); + emit Send_Table_image_ChangeStatus_rowNumInt_statusQString(rowNum, "Failed"); + emit Send_progressbar_Add(); + mutex_ThreadNumRunning.lock(); + ThreadNumRunning--; + mutex_ThreadNumRunning.unlock(); + return 0; + } + OutPutPath_Final = OutPut_Path; + //============================ 调整大小 ==================================================== + if(CustRes_isEnabled) + { + do + { + QImage qimage_adj(OutPut_Path); + //读取放大后的图片并调整大小 + QImage qimage_adj_scaled = qimage_adj.scaled(CustRes_width,CustRes_height,CustRes_AspectRatioMode,Qt::SmoothTransformation); + QImageWriter qimageW_adj; + qimageW_adj.setFormat("png"); + qimageW_adj.setFileName(OutPut_Path); + if(qimageW_adj.canWrite()) + { + qimageW_adj.write(qimage_adj_scaled); + } + if(!QFile::exists(OutPut_Path)) + { + emit Send_TextBrowser_NewMessage(tr("Error occured when processing [")+SourceFile_fullPath+tr("]. Error: [Unable to resize the scaled picture to the target size]")); + emit Send_Table_image_ChangeStatus_rowNumInt_statusQString(rowNum, "Failed"); + emit Send_progressbar_Add(); + mutex_ThreadNumRunning.lock(); + ThreadNumRunning--; + mutex_ThreadNumRunning.unlock();//线程数量统计-1 + return 0; + } + } + while(false); + QString OutPut_Path_CustRes = file_path + "/" + file_name + "_waifu2x_"+QString::number(CustRes_width, 10)+"x"+QString::number(CustRes_height, 10)+"_"+QString::number(DenoiseLevel, 10)+"n_"+file_ext+".png"; + QFile::remove(OutPut_Path_CustRes); + QFile::rename(OutPut_Path,OutPut_Path_CustRes); + OutPutPath_Final = OutPut_Path_CustRes; + } + //=========================== 另存为JPG&压缩JPG =========================================== + OutPutPath_Final = SaveImageAs_FormatAndQuality(SourceFile_fullPath_Original,OutPutPath_Final,true,DenoiseLevel); + //================== 检查是否丢失了透明通道 ===================== + if(ReProcess_MissingAlphaChannel==false) + { + QImage QImage_source(SourceFile_fullPath_Original); + QImage QImage_Final(OutPutPath_Final); + if(QImage_source.hasAlphaChannel()==true && QImage_Final.hasAlphaChannel()==false && ui->checkBox_AutoDetectAlphaChannel->isChecked()) + { + QFile::remove(OutPutPath_Final); + emit Send_TextBrowser_NewMessage(tr("Since the Alpha channel in the resulting image is lost, this image will be reprocessed to fix it:[")+SourceFile_fullPath_Original+tr("].\nIf the reprocessing happens a lot, you should consider enable [Always pre-process images with Alpha Channel] in [Additional settings].")); + return Waifu2x_Caffe_Image(rowNum,true); + } + } + //============================= 删除原文件 & & 更新table status ============================ + if(SourceFile_fullPath_Original!=SourceFile_fullPath) + { + QFile::remove(SourceFile_fullPath); + SourceFile_fullPath = SourceFile_fullPath_Original; + } + if(DelOriginal) + { + if(ReplaceOriginalFile(SourceFile_fullPath,OutPutPath_Final)==false) + { + if(QAction_checkBox_MoveToRecycleBin_checkBox_DelOriginal->isChecked()) + { + file_MoveToTrash(SourceFile_fullPath); + } + else + { + QFile::remove(SourceFile_fullPath); + } + } + emit Send_Table_image_ChangeStatus_rowNumInt_statusQString(rowNum, "Finished, original file deleted"); + } + else + { + emit Send_Table_image_ChangeStatus_rowNumInt_statusQString(rowNum, "Finished"); + } + //========== 移动到输出路径 ========= + if(ui->checkBox_OutPath_isEnabled->isChecked()) + { + MoveFileToOutputPath(OutPutPath_Final,SourceFile_fullPath); + } + //============================ 更新进度条 ================================= + emit Send_progressbar_Add(); + //=========================== 更新线程数量统计============================== + mutex_ThreadNumRunning.lock(); + ThreadNumRunning--; + mutex_ThreadNumRunning.unlock();//线程数量统计-1 + return 0; +} + + +int MainWindow::Waifu2x_Caffe_GIF(int rowNum) +{ + //============================= 读取设置 ================================ + int ScaleRatio = ui->doubleSpinBox_ScaleRatio_gif->value(); + int DenoiseLevel = ui->spinBox_DenoiseLevel_gif->value(); + bool DelOriginal = (ui->checkBox_DelOriginal->isChecked()||ui->checkBox_ReplaceOriginalFile->isChecked()); + bool OptGIF = ui->checkBox_OptGIF->isChecked(); + int Sub_gif_ThreadNumRunning = 0; + QString OutPutPath_Final =""; + //========================= 拆解map得到参数 ============================= + emit Send_Table_gif_ChangeStatus_rowNumInt_statusQString(rowNum, "Processing"); + QString SourceFile_fullPath = Table_model_gif->item(rowNum,2)->text(); + if(!QFile::exists(SourceFile_fullPath)) + { + emit Send_TextBrowser_NewMessage(tr("Error occured when processing [")+SourceFile_fullPath+tr("]. Error: [File does not exist.]")); + emit Send_Table_gif_ChangeStatus_rowNumInt_statusQString(rowNum, "Failed"); + emit Send_progressbar_Add(); + return 0; + } + //========================== + bool CustRes_isEnabled = false; + int CustRes_height=0; + int CustRes_width=0; + if(CustRes_isContained(SourceFile_fullPath)) + { + CustRes_isEnabled=true; + QMap Res_map = CustRes_getResMap(SourceFile_fullPath);//res_map["fullpath"],["height"],["width"] + CustRes_height=Res_map["height"].toInt(); + CustRes_width=Res_map["width"].toInt(); + } + //========================== + QFileInfo fileinfo(SourceFile_fullPath); + QString file_name = file_getBaseName(SourceFile_fullPath); + QString file_ext = fileinfo.suffix(); + QString file_path = file_getFolderPath(fileinfo); + QString ResGIFPath = file_path + "/" + file_name + "_waifu2x_"+QString::number(ScaleRatio, 10)+"x_"+QString::number(DenoiseLevel, 10)+"n.gif"; + //=========================== 获取帧时间 ==================================== + int GIF_Duration = Gif_getDuration(SourceFile_fullPath); + if(GIF_Duration==0)//检查是否成功获取duration + { + emit Send_TextBrowser_NewMessage(tr("Error occured when processing [")+SourceFile_fullPath+tr("]. Error: [Can't get Duration value of GIF file.]")); + emit Send_Table_gif_ChangeStatus_rowNumInt_statusQString(rowNum, "Failed"); + //file_DelDir(SplitFramesFolderPath); + emit Send_progressbar_Add(); + return 0;//如果启用stop位,则直接return + } + //============================== 拆分 ========================================== + QString SplitFramesFolderPath = file_path+"/"+file_name+"_SplitFrames_W2xEX";//拆分后存储frame的文件夹 + Gif_splitGif(SourceFile_fullPath,SplitFramesFolderPath); + //============================== 扫描获取文件名 =============================== + QStringList Frame_fileName_list = file_getFileNames_in_Folder_nofilter(SplitFramesFolderPath); + if(Frame_fileName_list.isEmpty())//检查是否成功拆分gif + { + emit Send_TextBrowser_NewMessage(tr("Error occured when processing [")+SourceFile_fullPath+tr("]. Error: [Can't split GIF into frames.]")); + emit Send_Table_gif_ChangeStatus_rowNumInt_statusQString(rowNum, "Failed"); + file_DelDir(SplitFramesFolderPath); + emit Send_progressbar_Add(); + return 0;//如果启用stop位,则直接return + } + //===========建立存储放大后frame的文件夹=========== + QString ScaledFramesFolderPath = SplitFramesFolderPath+"/ScaledFrames_W2xEX"; + if(file_isDirExist(ScaledFramesFolderPath)) + { + file_DelDir(ScaledFramesFolderPath); + file_mkDir(ScaledFramesFolderPath); + } + else + { + file_mkDir(ScaledFramesFolderPath); + } + //==========开始放大========================== + emit Send_CurrentFileProgress_Start(file_name+"."+file_ext,Frame_fileName_list.size()); + FileProgressWatch_isEnabled=true; + QFuture FileProgressWatch_QFuture = QtConcurrent::run(this, &MainWindow::CurrentFileProgress_WatchFolderFileNum, ScaledFramesFolderPath);//启动waifu2x 主线程 + if(ui->checkBox_ShowInterPro->isChecked()==false) + { + FileProgressWatch_isEnabled=false; + FileProgressWatch_QFuture.cancel(); + emit Send_CurrentFileProgress_Stop(); + } + //=======获取显卡信息======== + int NumOfGPU = 1; + if(ui->checkBox_EnableMultiGPU_Waifu2xCaffe->isChecked()==true) + { + NumOfGPU = Get_NumOfGPU_W2xCaffe(); + } + //============创建显卡文件夹=========== + QStringList GPU_SplitFramesFolderPath_List; + for(int i = 0; i < NumOfGPU; i++) + { + QString GPU_SplitFramesFolderPath = SplitFramesFolderPath+"/"+"GPU_"+QString::number(i); + if(file_isDirExist(GPU_SplitFramesFolderPath)) + { + file_DelDir(GPU_SplitFramesFolderPath); + file_mkDir(GPU_SplitFramesFolderPath); + } + else + { + file_mkDir(GPU_SplitFramesFolderPath); + } + GPU_SplitFramesFolderPath_List.append(GPU_SplitFramesFolderPath); + } + int TotalFramesNum = Frame_fileName_list.size(); + int FramesNumForEachGPU = TotalFramesNum/NumOfGPU; + if(FramesNumForEachGPU<1)FramesNumForEachGPU=1; + int start_num=0; + for(int x = 0; x < GPU_SplitFramesFolderPath_List.size(); x++) + { + if(x==GPU_SplitFramesFolderPath_List.size()-1)FramesNumForEachGPU=TotalFramesNum; + QStringList file_waitformove = Frame_fileName_list.mid(start_num,FramesNumForEachGPU); + for(int i = 0; i < file_waitformove.size(); i++) + { + QString FileName = file_waitformove.at(i); + QFile::rename(SplitFramesFolderPath+"/"+FileName,GPU_SplitFramesFolderPath_List.at(x)+"/"+FileName); + } + start_num+=FramesNumForEachGPU; + } + //========================= + bool Frame_failed = false;//放大失败标志 + //==== + QMap Sub_Thread_info; + Sub_Thread_info["ScaledFramesFolderPath"]= ScaledFramesFolderPath; + if(CustRes_isEnabled == true) + { + Sub_Thread_info["ScaleRatio"] = QString("%1").arg(CustRes_CalNewScaleRatio(SourceFile_fullPath,CustRes_height,CustRes_width)); + } + else + { + Sub_Thread_info["ScaleRatio"] = QString("%1").arg(qRound(ui->doubleSpinBox_ScaleRatio_gif->value())); + } + //========================= + for(int i = 0; i < GPU_SplitFramesFolderPath_List.size(); i++) + { + Sub_Thread_info["SplitFramesFolderPath"]=GPU_SplitFramesFolderPath_List.at(i); + mutex_SubThreadNumRunning.lock(); + Sub_gif_ThreadNumRunning++; + mutex_SubThreadNumRunning.unlock(); + QtConcurrent::run(this,&MainWindow::Waifu2x_Caffe_GIF_scale,Sub_Thread_info,&Sub_gif_ThreadNumRunning,&Frame_failed); + while (Sub_gif_ThreadNumRunning >= NumOfGPU) + { + Delay_msec_sleep(500); + } + if(waifu2x_STOP) + { + while (Sub_gif_ThreadNumRunning > 0) + { + Delay_msec_sleep(500); + } + FileProgressWatch_isEnabled=false; + FileProgressWatch_QFuture.cancel(); + file_DelDir(SplitFramesFolderPath); + emit Send_Table_gif_ChangeStatus_rowNumInt_statusQString(rowNum, "Interrupted"); + return 0;//如果启用stop位,则直接return + } + if(Frame_failed) + { + FileProgressWatch_isEnabled=false; + FileProgressWatch_QFuture.cancel(); + emit Send_TextBrowser_NewMessage(tr("Error occured when processing [")+SourceFile_fullPath+tr("]. Error: [Failed to scale frames.]")); + emit Send_Table_gif_ChangeStatus_rowNumInt_statusQString(rowNum, "Failed"); + file_DelDir(SplitFramesFolderPath); + emit Send_progressbar_Add(); + return 0;//如果启用stop位,则直接return + } + } + while (Sub_gif_ThreadNumRunning!=0) + { + Delay_msec_sleep(500); + } + FileProgressWatch_isEnabled=false; + FileProgressWatch_QFuture.cancel(); + emit Send_CurrentFileProgress_Stop(); + //======================= 检查是否成功放大所有帧 =========================== + QStringList Frame_fileName_list_scaled = file_getFileNames_in_Folder_nofilter(ScaledFramesFolderPath); + if(Frame_fileName_list.size()!=Frame_fileName_list_scaled.size()) + { + emit Send_TextBrowser_NewMessage(tr("Error occured when processing [")+SourceFile_fullPath+tr("]. Error: [Failed to scale frames.]")); + emit Send_Table_gif_ChangeStatus_rowNumInt_statusQString(rowNum, "Failed"); + file_DelDir(SplitFramesFolderPath); + emit Send_progressbar_Add(); + return 0;//如果启用stop位,则直接return + } + //======================================== 组装 ====================================================== + if(CustRes_isEnabled) + { + ResGIFPath = file_path + "/" + file_name + "_waifu2x_"+QString::number(CustRes_width, 10)+"x"+QString::number(CustRes_height,10)+"_"+QString::number(DenoiseLevel, 10)+"n.gif"; + } + Gif_assembleGif(ResGIFPath,ScaledFramesFolderPath,GIF_Duration,CustRes_isEnabled,CustRes_height,CustRes_width,false,""); + if(!QFile::exists(ResGIFPath)) + { + emit Send_TextBrowser_NewMessage(tr("Error occured when processing [")+SourceFile_fullPath+tr("]. Error: [Unable to assemble gif.]")); + emit Send_Table_gif_ChangeStatus_rowNumInt_statusQString(rowNum, "Failed"); + file_DelDir(SplitFramesFolderPath); + emit Send_progressbar_Add(); + return 0;//如果启用stop位,则直接return + } + OutPutPath_Final = ResGIFPath; + //======================================= 优化gif =================================================== + if(OptGIF) + { + QString ResGIFPath_compressed = ""; + if(CustRes_isEnabled) + { + ResGIFPath_compressed = file_path + "/" + file_name + "_waifu2x_"+QString::number(CustRes_width, 10)+"x"+QString::number(CustRes_height,10)+"_"+QString::number(DenoiseLevel, 10)+"n_opt.gif"; + } + else + { + ResGIFPath_compressed = file_path + "/" + file_name + "_waifu2x_"+QString::number(ScaleRatio, 10)+"x_"+QString::number(DenoiseLevel, 10)+"n_opt.gif"; + } + OutPutPath_Final = Gif_compressGif(ResGIFPath,ResGIFPath_compressed); + } + //============================== 删除缓存文件 ==================================================== + file_DelDir(SplitFramesFolderPath); + //============================= 删除原文件 & & 更新table status ============================ + if(DelOriginal) + { + if(ReplaceOriginalFile(SourceFile_fullPath,OutPutPath_Final)==false) + { + if(QAction_checkBox_MoveToRecycleBin_checkBox_DelOriginal->isChecked()) + { + file_MoveToTrash(SourceFile_fullPath); + } + else + { + QFile::remove(SourceFile_fullPath); + } + } + emit Send_Table_gif_ChangeStatus_rowNumInt_statusQString(rowNum, "Finished, original file deleted"); + } + else + { + emit Send_Table_gif_ChangeStatus_rowNumInt_statusQString(rowNum, "Finished"); + } + //========== 移动到输出路径 ========= + if(ui->checkBox_OutPath_isEnabled->isChecked()) + { + MoveFileToOutputPath(OutPutPath_Final,SourceFile_fullPath); + } + //============================ 更新进度条 ================================= + emit Send_progressbar_Add(); + //=========================== ============================== + return 0; +} + +int MainWindow::Waifu2x_Caffe_GIF_scale(QMap Sub_Thread_info,int *Sub_gif_ThreadNumRunning,bool *Frame_failed) +{ + bool AllFinished=true; + QString SplitFramesFolderPath = Sub_Thread_info["SplitFramesFolderPath"]; + QString ScaledFramesFolderPath = Sub_Thread_info["ScaledFramesFolderPath"]; + //=========== + int ScaleRatio = Sub_Thread_info["ScaleRatio"].toInt(); + int DenoiseLevel = ui->spinBox_DenoiseLevel_gif->value(); + //=========== + QString program = Current_Path + "/waifu2x-caffe/waifu2x-caffe_waifu2xEX.exe"; + //==== + QString ImageProcessingModeCMD = ""; + if(DenoiseLevel==-1) + { + ImageProcessingModeCMD = " -m scale -s " + QString::number(ScaleRatio, 10)+" "; + } + else + { + int DenoiseLevel_tmp =0; + if((ui->comboBox_Model_2D_Waifu2xCaffe->currentIndex()==0)&&(DenoiseLevel==0)&&(ui->comboBox_ImageStyle_Waifu2xCaffe->currentIndex()==0)) + { + DenoiseLevel_tmp=1; + } + else + { + DenoiseLevel_tmp = DenoiseLevel; + } + ImageProcessingModeCMD = " -m noise_scale -s " + QString::number(ScaleRatio, 10)+ " -n " + QString::number(DenoiseLevel_tmp, 10)+" "; + } + //======= + //======================================================================== + QStringList InputFilesNameList = file_getFileNames_in_Folder_nofilter(SplitFramesFolderPath); + QStringList OutPutFilesFullPathList; + for(int i=0; ispinBox_retry->value()+ForceRetryCount); retry++) + { + Waifu2x->start(cmd); + while(!Waifu2x->waitForStarted(100)&&!QProcess_stop) {} + while(!Waifu2x->waitForFinished(500)&&!QProcess_stop) + { + if(waifu2x_STOP) + { + Waifu2x->close(); + mutex_SubThreadNumRunning.lock(); + *Sub_gif_ThreadNumRunning=*Sub_gif_ThreadNumRunning-1; + mutex_SubThreadNumRunning.unlock(); + return 0; + } + } + AllFinished = true; + for(int i=0; ispinBox_retry->value()+(ForceRetryCount-1))break; + Delay_sec_sleep(5); + emit Send_TextBrowser_NewMessage(tr("Automatic retry, please wait.")); + AllFinished=false; + break; + } + } + if(AllFinished)break; + } + //========= + AllFinished = true; + for(int i=0; idoubleSpinBox_ScaleRatio_video->value(); + int DenoiseLevel = ui->spinBox_DenoiseLevel_video->value(); + bool DelOriginal = (ui->checkBox_DelOriginal->isChecked()||ui->checkBox_ReplaceOriginalFile->isChecked()); + bool isCacheExists = false; + bool isVideoConfigChanged = true; + int Sub_video_ThreadNumRunning = 0; + //========================= 拆解map得到参数 ============================= + emit Send_Table_video_ChangeStatus_rowNumInt_statusQString(rowNum, "Processing"); + QString SourceFile_fullPath = Table_model_video->item(rowNum,2)->text(); + if(!QFile::exists(SourceFile_fullPath)) + { + emit Send_TextBrowser_NewMessage(tr("Error occured when processing [")+SourceFile_fullPath+tr("]. Error: [File does not exist.]")); + emit Send_Table_video_ChangeStatus_rowNumInt_statusQString(rowNum, "Failed"); + emit Send_progressbar_Add(); + return 0; + } + //========================== + QFileInfo fileinfo(SourceFile_fullPath); + QString file_name = file_getBaseName(SourceFile_fullPath); + QString file_ext = fileinfo.suffix(); + QString file_path = file_getFolderPath(fileinfo); + //=================================================================== + //生成mp4 + QString video_mp4_fullpath=video_To_CFRMp4(SourceFile_fullPath); + if(!QFile::exists(video_mp4_fullpath))//检查是否成功生成mp4 + { + emit Send_TextBrowser_NewMessage(tr("Error occured when processing [")+SourceFile_fullPath+tr("]. Error: [Cannot convert video format to mp4.]")); + emit Send_Table_video_ChangeStatus_rowNumInt_statusQString(rowNum, "Failed"); + emit Send_progressbar_Add(); + return 0;//如果启用stop位,则直接return + } + //============ 读取自定义分辨率 ============== + bool CustRes_isEnabled = false; + int CustRes_height=0; + int CustRes_width=0; + if(CustRes_isContained(SourceFile_fullPath)) + { + CustRes_isEnabled=true; + QMap Res_map = CustRes_getResMap(SourceFile_fullPath);//res_map["fullpath"],["height"],["width"] + CustRes_height=Res_map["height"].toInt(); + CustRes_width=Res_map["width"].toInt(); + } + //================= + QString AudioPath = file_path+"/Audio_"+file_name+"_"+file_ext+"_W2xEX.wav";//音频 + QString SplitFramesFolderPath = file_path+"/"+file_name+"_"+file_ext+"_SplitFrames_W2xEX";//拆分后存储frame的文件夹 + QString ScaledFramesFolderPath = SplitFramesFolderPath+"/ScaledFrames_W2xEX";//存储放大后的帧 + //========================== + // 检测之前的视频配置文件 + //========================== + QString VideoConfiguration_fullPath = file_path+"/VideoConfiguration_"+file_name+"_"+file_ext+"_Waifu2xEX.ini"; + if(QFile::exists(VideoConfiguration_fullPath)) + { + QSettings *configIniRead = new QSettings(VideoConfiguration_fullPath, QSettings::IniFormat); + configIniRead->setIniCodec(QTextCodec::codecForName("UTF-8")); + //=================== 加载之前存储的视频信息 ========================= + int ScaleRatio_old = configIniRead->value("/VideoConfiguration/ScaleRatio").toInt(); + int DenoiseLevel_old = configIniRead->value("/VideoConfiguration/DenoiseLevel").toInt(); + bool CustRes_isEnabled_old = configIniRead->value("/VideoConfiguration/CustRes_isEnabled").toBool(); + int CustRes_height_old = configIniRead->value("/VideoConfiguration/CustRes_height").toInt(); + int CustRes_width_old = configIniRead->value("/VideoConfiguration/CustRes_width").toInt(); + QString EngineName_old = configIniRead->value("/VideoConfiguration/EngineName").toString(); + bool isProcessBySegment_old = configIniRead->value("/VideoConfiguration/isProcessBySegment").toBool(); + //=================== 比对信息 ================================ + if(EngineName_old=="waifu2x-caffe") + { + if(CustRes_isEnabled_old==false&&CustRes_isEnabled==false) + { + if(ScaleRatio_old!=ScaleRatio||DenoiseLevel_old!=DenoiseLevel) + { + isVideoConfigChanged=true; + } + else + { + isVideoConfigChanged=false; + } + } + else + { + if(CustRes_isEnabled_old==true&&CustRes_isEnabled==true) + { + if(CustRes_height_old!=CustRes_height||CustRes_width_old!=CustRes_width) + { + isVideoConfigChanged=true; + } + else + { + isVideoConfigChanged=false; + } + } + else + { + isVideoConfigChanged=true; + } + } + if(isProcessBySegment_old==true) + { + isVideoConfigChanged=true; + } + } + else + { + isVideoConfigChanged=true; + } + } + else + { + emit Send_video_write_VideoConfiguration(VideoConfiguration_fullPath,ScaleRatio,DenoiseLevel,CustRes_isEnabled,CustRes_height,CustRes_width,"waifu2x-caffe",false,"","",ui->groupBox_FrameInterpolation->isChecked(),0); + } + //======================= + // 检测缓存是否存在 + //======================= + if(QFile::exists(video_mp4_fullpath)&&file_isDirExist(SplitFramesFolderPath)&&file_isDirExist(ScaledFramesFolderPath)&&QFile::exists(VideoConfiguration_fullPath)) + { + if(!isVideoConfigChanged) + { + isCacheExists=true; + emit Send_TextBrowser_NewMessage(tr("The previous video cache file is detected and processing of the previous video cache will continue. If you want to restart processing of the current video:[")+SourceFile_fullPath+tr("], delete the cache manually.")); + } + else + { + isCacheExists=false; + //======== + QFile::remove(VideoConfiguration_fullPath); + file_DelDir(SplitFramesFolderPath); + QFile::remove(AudioPath); + DelVfiDir(video_mp4_fullpath); + emit Send_video_write_VideoConfiguration(VideoConfiguration_fullPath,ScaleRatio,DenoiseLevel,CustRes_isEnabled,CustRes_height,CustRes_width,"waifu2x-caffe",false,"","",ui->groupBox_FrameInterpolation->isChecked(),0); + //======= + emit Send_TextBrowser_NewMessage(tr("The previous video cache file was detected, but because you changed the settings about the video resolution or denoise level, the previous cache will be deleted and processing of the video:[")+SourceFile_fullPath+tr("] will restart.")); + } + } + else + { + isCacheExists=false; + //======== + QFile::remove(VideoConfiguration_fullPath); + file_DelDir(SplitFramesFolderPath); + QFile::remove(AudioPath); + DelVfiDir(video_mp4_fullpath); + emit Send_video_write_VideoConfiguration(VideoConfiguration_fullPath,ScaleRatio,DenoiseLevel,CustRes_isEnabled,CustRes_height,CustRes_width,"waifu2x-caffe",false,"","",ui->groupBox_FrameInterpolation->isChecked(),0); + //======== + } + if(!isCacheExists) + { + //============================== 拆分 ========================================== + if(file_isDirExist(SplitFramesFolderPath)) + { + file_DelDir(SplitFramesFolderPath); + file_mkDir(SplitFramesFolderPath); + } + else + { + file_mkDir(SplitFramesFolderPath); + } + QFile::remove(AudioPath); + video_video2images(video_mp4_fullpath,SplitFramesFolderPath,AudioPath); + if(waifu2x_STOP) + { + emit Send_Table_video_ChangeStatus_rowNumInt_statusQString(rowNum, "Interrupted"); + return 0;//如果启用stop位,则直接return + } + } + //============================== 扫描获取文件名 =============================== + QStringList Frame_fileName_list = file_getFileNames_in_Folder_nofilter(SplitFramesFolderPath); + if(!isCacheExists) + { + if(Frame_fileName_list.isEmpty())//检查是否成功拆分为帧 + { + emit Send_TextBrowser_NewMessage(tr("Error occured when processing [")+SourceFile_fullPath+tr("]. Error: [Unable to split video into pictures.]")); + emit Send_Table_video_ChangeStatus_rowNumInt_statusQString(rowNum, "Failed"); + emit Send_progressbar_Add(); + return 0;//如果启用stop位,则直接return + } + } + //============================== 放大 ======================================= + //===========建立存储放大后frame的文件夹=========== + if(!isCacheExists) + { + if(file_isDirExist(ScaledFramesFolderPath)) + { + file_DelDir(ScaledFramesFolderPath); + file_mkDir(ScaledFramesFolderPath); + } + else + { + file_mkDir(ScaledFramesFolderPath); + } + } + //==========开始放大========================== + emit Send_CurrentFileProgress_Start(file_name+"."+file_ext,(Frame_fileName_list.size()+file_getFileNames_in_Folder_nofilter(ScaledFramesFolderPath).size())); + FileProgressWatch_isEnabled=true; + QFuture FileProgressWatch_QFuture = QtConcurrent::run(this, &MainWindow::CurrentFileProgress_WatchFolderFileNum, ScaledFramesFolderPath);//启动waifu2x 主线程 + if(ui->checkBox_ShowInterPro->isChecked()==false) + { + FileProgressWatch_isEnabled=false; + FileProgressWatch_QFuture.cancel(); + emit Send_CurrentFileProgress_Stop(); + } + //=======获取显卡信息======== + int NumOfGPU = 1; + if(ui->checkBox_EnableMultiGPU_Waifu2xCaffe->isChecked()==true) + { + NumOfGPU = Get_NumOfGPU_W2xCaffe(); + } + //============创建显卡文件夹=========== + QStringList GPU_SplitFramesFolderPath_List; + for(int i = 0; i < NumOfGPU; i++) + { + QString GPU_SplitFramesFolderPath = SplitFramesFolderPath+"/"+"GPU_"+QString::number(i); + if(file_isDirExist(GPU_SplitFramesFolderPath)==false) + { + file_DelDir(GPU_SplitFramesFolderPath); + file_mkDir(GPU_SplitFramesFolderPath); + } + else + { + file_mkDir(GPU_SplitFramesFolderPath); + } + GPU_SplitFramesFolderPath_List.append(GPU_SplitFramesFolderPath); + } + int TotalFramesNum = Frame_fileName_list.size(); + int FramesNumForEachGPU = TotalFramesNum/NumOfGPU; + if(FramesNumForEachGPU<1)FramesNumForEachGPU=1; + int start_num=0; + for(int x = 0; x < GPU_SplitFramesFolderPath_List.size(); x++) + { + if(x==GPU_SplitFramesFolderPath_List.size()-1)FramesNumForEachGPU=TotalFramesNum; + QStringList file_waitformove = Frame_fileName_list.mid(start_num,FramesNumForEachGPU); + for(int i = 0; i < file_waitformove.size(); i++) + { + QString FileName = file_waitformove.at(i); + QFile::rename(SplitFramesFolderPath+"/"+FileName,GPU_SplitFramesFolderPath_List.at(x)+"/"+FileName); + } + start_num+=FramesNumForEachGPU; + } + //========================= + bool Frame_failed = false;//放大失败标志 + QMap Sub_Thread_info; + Sub_Thread_info["ScaledFramesFolderPath"]=ScaledFramesFolderPath; + if(CustRes_isEnabled == true) + { + Sub_Thread_info["ScaleRatio"] = QString("%1").arg(CustRes_CalNewScaleRatio(video_mp4_fullpath,CustRes_height,CustRes_width)); + } + else + { + Sub_Thread_info["ScaleRatio"] = QString("%1").arg(ScaleRatio); + } + //========================= + for(int i = 0; i < GPU_SplitFramesFolderPath_List.size(); i++) + { + Sub_Thread_info["SplitFramesFolderPath"]=GPU_SplitFramesFolderPath_List.at(i); + mutex_SubThreadNumRunning.lock(); + Sub_video_ThreadNumRunning++; + mutex_SubThreadNumRunning.unlock(); + QtConcurrent::run(this,&MainWindow::Waifu2x_Caffe_Video_scale,Sub_Thread_info,&Sub_video_ThreadNumRunning,&Frame_failed); + while (Sub_video_ThreadNumRunning >= NumOfGPU) + { + Delay_msec_sleep(500); + } + if(waifu2x_STOP) + { + while (Sub_video_ThreadNumRunning > 0) + { + Delay_msec_sleep(500); + } + FileProgressWatch_isEnabled=false; + FileProgressWatch_QFuture.cancel(); + Restore_SplitFramesFolderPath(SplitFramesFolderPath,GPU_SplitFramesFolderPath_List); + emit Send_Table_video_ChangeStatus_rowNumInt_statusQString(rowNum, "Interrupted"); + return 0;//如果启用stop位,则直接return + } + if(Frame_failed) + { + FileProgressWatch_isEnabled=false; + FileProgressWatch_QFuture.cancel(); + Restore_SplitFramesFolderPath(SplitFramesFolderPath,GPU_SplitFramesFolderPath_List); + emit Send_TextBrowser_NewMessage(tr("Error occured when processing [")+SourceFile_fullPath+tr("]. Error: [Failed to scale frames.]")); + emit Send_Table_video_ChangeStatus_rowNumInt_statusQString(rowNum, "Failed"); + emit Send_progressbar_Add(); + return 0;//如果启用stop位,则直接return + } + } + while (Sub_video_ThreadNumRunning!=0) + { + Delay_msec_sleep(500); + } + FileProgressWatch_isEnabled=false; + FileProgressWatch_QFuture.cancel(); + emit Send_CurrentFileProgress_Stop(); + //================ 扫描放大后的帧文件数量,判断是否放大成功 ======================= + QStringList Frame_fileName_list_scaled = file_getFileNames_in_Folder_nofilter(ScaledFramesFolderPath); + if(Frame_fileName_list_scaled.size()checkBox_KeepVideoCache->isChecked()==false) + { + QFile::remove(VideoConfiguration_fullPath); + file_DelDir(SplitFramesFolderPath); + QFile::remove(AudioPath); + if(SourceFile_fullPath!=video_mp4_fullpath)QFile::remove(video_mp4_fullpath); + } + else + { + DelOriginal=false; + } + //============================= 删除原文件 & & 更新table status ============================ + if(DelOriginal) + { + if(ReplaceOriginalFile(SourceFile_fullPath,video_mp4_scaled_fullpath)==false) + { + if(QAction_checkBox_MoveToRecycleBin_checkBox_DelOriginal->isChecked()) + { + file_MoveToTrash(SourceFile_fullPath); + } + else + { + QFile::remove(SourceFile_fullPath); + } + } + emit Send_Table_video_ChangeStatus_rowNumInt_statusQString(rowNum, "Finished, original file deleted"); + } + else + { + emit Send_Table_video_ChangeStatus_rowNumInt_statusQString(rowNum, "Finished"); + } + //========== 移动到输出路径 ========= + if(ui->checkBox_OutPath_isEnabled->isChecked()) + { + MoveFileToOutputPath(video_mp4_scaled_fullpath,SourceFile_fullPath); + } + //============================ 更新进度条 ================================= + emit Send_progressbar_Add(); + //=========================== ============================== + return 0; +} + +/* +#### 分段处理 #### +调用Waifu2x-caffe处理视频 +读取设置,拆分,创建放大子线程,组装视频 +*/ +int MainWindow::Waifu2x_Caffe_Video_BySegment(int rowNum) +{ + //============================= 读取设置 ================================ + int ScaleRatio = ui->doubleSpinBox_ScaleRatio_video->value(); + int DenoiseLevel = ui->spinBox_DenoiseLevel_video->value(); + bool DelOriginal = (ui->checkBox_DelOriginal->isChecked()||ui->checkBox_ReplaceOriginalFile->isChecked()); + bool isCacheExists = false; + bool isVideoConfigChanged = true; + int Sub_video_ThreadNumRunning = 0; + int SegmentDuration = ui->spinBox_SegmentDuration->value(); + //========================= 拆解map得到参数 ============================= + emit Send_Table_video_ChangeStatus_rowNumInt_statusQString(rowNum, "Processing"); + QString SourceFile_fullPath = Table_model_video->item(rowNum,2)->text(); + if(!QFile::exists(SourceFile_fullPath)) + { + emit Send_TextBrowser_NewMessage(tr("Error occured when processing [")+SourceFile_fullPath+tr("]. Error: [File does not exist.]")); + emit Send_Table_video_ChangeStatus_rowNumInt_statusQString(rowNum, "Failed"); + emit Send_progressbar_Add(); + return 0; + } + //========================== + QFileInfo fileinfo(SourceFile_fullPath); + QString file_name = file_getBaseName(SourceFile_fullPath); + QString file_ext = fileinfo.suffix(); + QString file_path = file_getFolderPath(fileinfo); + //=================================================================== + //生成mp4 + QString video_mp4_fullpath=video_To_CFRMp4(SourceFile_fullPath); + if(!QFile::exists(video_mp4_fullpath))//检查是否成功生成mp4 + { + emit Send_TextBrowser_NewMessage(tr("Error occured when processing [")+SourceFile_fullPath+tr("]. Error: [Cannot convert video format to mp4.]")); + emit Send_Table_video_ChangeStatus_rowNumInt_statusQString(rowNum, "Failed"); + emit Send_progressbar_Add(); + return 0;//如果启用stop位,则直接return + } + //============== 读取自定义分辨率 ============ + bool CustRes_isEnabled = false; + int CustRes_height=0; + int CustRes_width=0; + if(CustRes_isContained(SourceFile_fullPath)) + { + CustRes_isEnabled=true; + QMap Res_map = CustRes_getResMap(SourceFile_fullPath);//res_map["fullpath"],["height"],["width"] + CustRes_height=Res_map["height"].toInt(); + CustRes_width=Res_map["width"].toInt(); + } + //================= + QString AudioPath = file_path+"/Audio_"+file_name+"_"+file_ext+"_W2xEX.wav";//音频 + QString SplitFramesFolderPath = file_path+"/"+file_name+"_"+file_ext+"_SplitFrames_W2xEX";//拆分后存储frame的文件夹 + QString ScaledFramesFolderPath = SplitFramesFolderPath+"/ScaledFrames_W2xEX";//存储放大后的帧 + //=== + QString VideoClipsFolderPath = "";//存储视频片段的文件夹(完整路径) + QString DateStr = ""; + do + { + DateStr = video_getClipsFolderNo(); + VideoClipsFolderPath = file_path+"/"+DateStr+"_VideoClipsWaifu2xEX";//存储视频片段的文件夹(完整路径) + } + while(file_isDirExist(VideoClipsFolderPath)); + QString VideoClipsFolderName = DateStr+"_VideoClipsWaifu2xEX";//存储视频片段的文件夹(名称) + //========================== + // 检测之前的视频配置文件 + //========================== + QString VideoConfiguration_fullPath = file_path+"/VideoConfiguration_"+file_name+"_"+file_ext+"_Waifu2xEX.ini"; + if(QFile::exists(VideoConfiguration_fullPath)) + { + QSettings *configIniRead = new QSettings(VideoConfiguration_fullPath, QSettings::IniFormat); + configIniRead->setIniCodec(QTextCodec::codecForName("UTF-8")); + //=================== 加载之前存储的视频信息 ========================= + int ScaleRatio_old = configIniRead->value("/VideoConfiguration/ScaleRatio").toInt(); + int DenoiseLevel_old = configIniRead->value("/VideoConfiguration/DenoiseLevel").toInt(); + bool CustRes_isEnabled_old = configIniRead->value("/VideoConfiguration/CustRes_isEnabled").toBool(); + int CustRes_height_old = configIniRead->value("/VideoConfiguration/CustRes_height").toInt(); + int CustRes_width_old = configIniRead->value("/VideoConfiguration/CustRes_width").toInt(); + QString EngineName_old = configIniRead->value("/VideoConfiguration/EngineName").toString(); + bool isProcessBySegment_old = configIniRead->value("/VideoConfiguration/isProcessBySegment").toBool(); + bool isVideoFrameInterpolationEnabled_old = configIniRead->value("/VideoConfiguration/isVideoFrameInterpolationEnabled").toBool(); + int MultipleOfFPS_old = configIniRead->value("/VideoConfiguration/MultipleOfFPS").toInt(); + //=================== 比对信息 ================================ + if(EngineName_old=="waifu2x-caffe") + { + if(CustRes_isEnabled_old==false&&CustRes_isEnabled==false) + { + if(ScaleRatio_old!=ScaleRatio||DenoiseLevel_old!=DenoiseLevel) + { + isVideoConfigChanged=true; + } + else + { + isVideoConfigChanged=false; + } + } + else + { + if(CustRes_isEnabled_old==true&&CustRes_isEnabled==true) + { + if(CustRes_height_old!=CustRes_height||CustRes_width_old!=CustRes_width) + { + isVideoConfigChanged=true; + } + else + { + isVideoConfigChanged=false; + } + } + else + { + isVideoConfigChanged=true; + } + } + if(isProcessBySegment_old == false) + { + isVideoConfigChanged=true; + } + if(isVideoFrameInterpolationEnabled_old != ui->groupBox_FrameInterpolation->isChecked()) + { + isVideoConfigChanged=true; + } + if(MultipleOfFPS_old != ui->spinBox_MultipleOfFPS_VFI->value() && ui->groupBox_FrameInterpolation->isChecked()) + { + isVideoConfigChanged=true; + } + } + else + { + isVideoConfigChanged=true; + } + //============ 修正文件夹名称 ============= + QString VideoClipsFolderPath_old = configIniRead->value("/VideoConfiguration/VideoClipsFolderPath").toString(); + QString VideoClipsFolderName_old = configIniRead->value("/VideoConfiguration/VideoClipsFolderName").toString(); + file_mkDir(VideoClipsFolderPath_old); + if(file_isDirExist(VideoClipsFolderPath_old)==true) + { + VideoClipsFolderPath = VideoClipsFolderPath_old; + VideoClipsFolderName = VideoClipsFolderName_old; + } + } + else + { + emit Send_video_write_VideoConfiguration(VideoConfiguration_fullPath,ScaleRatio,DenoiseLevel,CustRes_isEnabled,CustRes_height,CustRes_width,"waifu2x-caffe",true,VideoClipsFolderPath,VideoClipsFolderName,ui->groupBox_FrameInterpolation->isChecked(),ui->spinBox_MultipleOfFPS_VFI->value()); + } + //======================= + // 检测缓存是否存在 + //======================= + if(file_isDirExist(SplitFramesFolderPath)) + { + if(!isVideoConfigChanged) + { + isCacheExists=true; + emit Send_TextBrowser_NewMessage(tr("The previous video cache file is detected and processing of the previous video cache will continue. If you want to restart processing of the current video:[")+SourceFile_fullPath+tr("], delete the cache manually.")); + } + else + { + isCacheExists=false; + //======== + QFile::remove(VideoConfiguration_fullPath); + file_DelDir(SplitFramesFolderPath); + file_DelDir(VideoClipsFolderPath); + QFile::remove(AudioPath); + DelVfiDir(video_mp4_fullpath); + emit Send_video_write_VideoConfiguration(VideoConfiguration_fullPath,ScaleRatio,DenoiseLevel,CustRes_isEnabled,CustRes_height,CustRes_width,"waifu2x-caffe",true,VideoClipsFolderPath,VideoClipsFolderName,ui->groupBox_FrameInterpolation->isChecked(),ui->spinBox_MultipleOfFPS_VFI->value()); + //======= + emit Send_TextBrowser_NewMessage(tr("The previous video cache file was detected, but because you changed the settings about the video resolution or denoise level, the previous cache will be deleted and processing of the video:[")+SourceFile_fullPath+tr("] will restart.")); + } + } + else + { + isCacheExists=false; + //======== + QFile::remove(VideoConfiguration_fullPath); + file_DelDir(SplitFramesFolderPath); + file_DelDir(VideoClipsFolderPath); + QFile::remove(AudioPath); + DelVfiDir(video_mp4_fullpath); + emit Send_video_write_VideoConfiguration(VideoConfiguration_fullPath,ScaleRatio,DenoiseLevel,CustRes_isEnabled,CustRes_height,CustRes_width,"waifu2x-caffe",true,VideoClipsFolderPath,VideoClipsFolderName,ui->groupBox_FrameInterpolation->isChecked(),ui->spinBox_MultipleOfFPS_VFI->value()); + //======== + } + /*==================================== + 提取音频 + ======================================*/ + if(!QFile::exists(AudioPath)) + { + video_get_audio(video_mp4_fullpath,AudioPath); + } + //================================== 开始分段处理视频 ================================================= + int StartTime = 0;//起始时间(秒) + int VideoDuration = video_get_duration(video_mp4_fullpath); + bool isSplitComplete = false; + bool isScaleComplete = false; + /* + ============================================ + 开始之前先读取进度 + ============================================ + */ + int OLD_SegmentDuration=-1; + bool read_OLD_SegmentDuration =false; + int LastVideoClipNo = -1; + if(QFile::exists(VideoConfiguration_fullPath)) + { + QSettings *configIniRead = new QSettings(VideoConfiguration_fullPath, QSettings::IniFormat); + configIniRead->setIniCodec(QTextCodec::codecForName("UTF-8")); + //=================== 加载进度 ========================= + StartTime = configIniRead->value("/Progress/StartTime").toInt(); + isSplitComplete = configIniRead->value("/Progress/isSplitComplete").toBool(); + isScaleComplete = configIniRead->value("/Progress/isScaleComplete").toBool(); + OLD_SegmentDuration = configIniRead->value("/Progress/OLDSegmentDuration").toInt(); + LastVideoClipNo = configIniRead->value("/Progress/LastVideoClipNo").toInt(); + } + if(OLD_SegmentDuration>0) + { + read_OLD_SegmentDuration = true; + } + /* + 加载进度条 + */ + int SegmentDuration_tmp_progressbar = 0; + if(read_OLD_SegmentDuration) + { + SegmentDuration_tmp_progressbar = OLD_SegmentDuration; + } + else + { + SegmentDuration_tmp_progressbar = SegmentDuration; + } + if(ui->checkBox_ShowInterPro->isChecked()&&VideoDuration>SegmentDuration_tmp_progressbar) + { + emit Send_CurrentFileProgress_Start(file_name+"."+file_ext,VideoDuration); + if(StartTime>0) + { + emit Send_CurrentFileProgress_progressbar_Add_SegmentDuration(StartTime); + } + } + /* + ============================================ + 正式开始处理 + ============================================ + */ + int SegmentDuration_tmp=0; + int TimeLeft_tmp=0; + while(VideoDuration>StartTime) + { + /*========================== + 计算视频片段时间 + ==========================*/ + TimeLeft_tmp = VideoDuration-StartTime; + if((TimeLeft_tmp)>=SegmentDuration) + { + SegmentDuration_tmp = SegmentDuration; + } + else + { + SegmentDuration_tmp = TimeLeft_tmp; + } + if(read_OLD_SegmentDuration) + { + SegmentDuration_tmp = OLD_SegmentDuration; + read_OLD_SegmentDuration=false; + } + /*========================== + 拆分视频片段 + ==========================*/ + if(isSplitComplete==false) + { + if(file_isDirExist(SplitFramesFolderPath)) + { + file_DelDir(SplitFramesFolderPath); + file_mkDir(SplitFramesFolderPath); + } + else + { + file_mkDir(SplitFramesFolderPath); + } + video_video2images_ProcessBySegment(video_mp4_fullpath,SplitFramesFolderPath,StartTime,SegmentDuration_tmp); + if(waifu2x_STOP) + { + emit Send_Table_video_ChangeStatus_rowNumInt_statusQString(rowNum, "Interrupted"); + return 0;//如果启用stop位,则直接return + } + } + /*========================== + 处理视频片段的帧 + ==========================*/ + if(isScaleComplete==false) + { + //============================== 扫描获取文件名 =============================== + QStringList Frame_fileName_list = file_getFileNames_in_Folder_nofilter(SplitFramesFolderPath); + if(isSplitComplete==false) + { + if(Frame_fileName_list.isEmpty())//检查是否成功拆分为帧 + { + emit Send_TextBrowser_NewMessage(tr("Error occured when processing [")+SourceFile_fullPath+tr("]. Error: [Unable to split video into pictures.]")); + emit Send_Table_video_ChangeStatus_rowNumInt_statusQString(rowNum, "Failed"); + emit Send_progressbar_Add(); + return 0;//如果启用stop位,则直接return + } + } + /* + 记录进度 + 帧拆分成功 + */ + emit Send_video_write_Progress_ProcessBySegment(VideoConfiguration_fullPath,StartTime,true,false,SegmentDuration_tmp,LastVideoClipNo); + //============================== 放大 ======================================= + //===========建立存储放大后frame的文件夹=========== + if(isSplitComplete==false) + { + if(file_isDirExist(ScaledFramesFolderPath)) + { + file_DelDir(ScaledFramesFolderPath); + file_mkDir(ScaledFramesFolderPath); + } + else + { + file_mkDir(ScaledFramesFolderPath); + } + } + //==========开始放大========================== + FileProgressWatch_isEnabled=true; + QFuture FileProgressWatch_QFuture = QtConcurrent::run(this, &MainWindow::CurrentFileProgress_WatchFolderFileNum_Textbrower, SourceFile_fullPath,ScaledFramesFolderPath,Frame_fileName_list.size()+file_getFileNames_in_Folder_nofilter(ScaledFramesFolderPath).size()); + if(ui->checkBox_ShowInterPro->isChecked()==false) + { + FileProgressWatch_isEnabled=false; + FileProgressWatch_QFuture.cancel(); + } + //=======获取显卡信息======== + int NumOfGPU = 1; + if(ui->checkBox_EnableMultiGPU_Waifu2xCaffe->isChecked()==true) + { + NumOfGPU = Get_NumOfGPU_W2xCaffe(); + } + //============创建显卡文件夹=========== + QStringList GPU_SplitFramesFolderPath_List; + for(int i = 0; i < NumOfGPU; i++) + { + QString GPU_SplitFramesFolderPath = SplitFramesFolderPath+"/"+"GPU_"+QString::number(i); + if(file_isDirExist(GPU_SplitFramesFolderPath)==false) + { + file_DelDir(GPU_SplitFramesFolderPath); + file_mkDir(GPU_SplitFramesFolderPath); + } + else + { + file_mkDir(GPU_SplitFramesFolderPath); + } + GPU_SplitFramesFolderPath_List.append(GPU_SplitFramesFolderPath); + } + int TotalFramesNum = Frame_fileName_list.size(); + int FramesNumForEachGPU = TotalFramesNum/NumOfGPU; + if(FramesNumForEachGPU<1)FramesNumForEachGPU=1; + int start_num=0; + for(int x = 0; x < GPU_SplitFramesFolderPath_List.size(); x++) + { + if(x==GPU_SplitFramesFolderPath_List.size()-1)FramesNumForEachGPU=TotalFramesNum; + QStringList file_waitformove = Frame_fileName_list.mid(start_num,FramesNumForEachGPU); + for(int i = 0; i < file_waitformove.size(); i++) + { + QString FileName = file_waitformove.at(i); + QFile::rename(SplitFramesFolderPath+"/"+FileName,GPU_SplitFramesFolderPath_List.at(x)+"/"+FileName); + } + start_num+=FramesNumForEachGPU; + } + //========================= + bool Frame_failed = false;//放大失败标志 + QMap Sub_Thread_info; + Sub_Thread_info["ScaledFramesFolderPath"]=ScaledFramesFolderPath; + if(CustRes_isEnabled == true) + { + Sub_Thread_info["ScaleRatio"] = QString("%1").arg(CustRes_CalNewScaleRatio(video_mp4_fullpath,CustRes_height,CustRes_width)); + } + else + { + Sub_Thread_info["ScaleRatio"] = QString("%1").arg(ScaleRatio); + } + //========================= + for(int i = 0; i < GPU_SplitFramesFolderPath_List.size(); i++) + { + Sub_Thread_info["SplitFramesFolderPath"]=GPU_SplitFramesFolderPath_List.at(i); + mutex_SubThreadNumRunning.lock(); + Sub_video_ThreadNumRunning++; + mutex_SubThreadNumRunning.unlock(); + QtConcurrent::run(this,&MainWindow::Waifu2x_Caffe_Video_scale,Sub_Thread_info,&Sub_video_ThreadNumRunning,&Frame_failed); + while (Sub_video_ThreadNumRunning >= NumOfGPU) + { + Delay_msec_sleep(500); + } + if(waifu2x_STOP) + { + while (Sub_video_ThreadNumRunning > 0) + { + Delay_msec_sleep(500); + } + FileProgressWatch_isEnabled=false; + FileProgressWatch_QFuture.cancel(); + Restore_SplitFramesFolderPath(SplitFramesFolderPath,GPU_SplitFramesFolderPath_List); + emit Send_Table_video_ChangeStatus_rowNumInt_statusQString(rowNum, "Interrupted"); + return 0;//如果启用stop位,则直接return + } + if(Frame_failed) + { + FileProgressWatch_isEnabled=false; + FileProgressWatch_QFuture.cancel(); + Restore_SplitFramesFolderPath(SplitFramesFolderPath,GPU_SplitFramesFolderPath_List); + emit Send_TextBrowser_NewMessage(tr("Error occured when processing [")+SourceFile_fullPath+tr("]. Error: [Failed to scale frames.]")); + emit Send_Table_video_ChangeStatus_rowNumInt_statusQString(rowNum, "Failed"); + emit Send_progressbar_Add(); + return 0;//如果启用stop位,则直接return + } + } + while (Sub_video_ThreadNumRunning!=0) + { + Delay_msec_sleep(500); + } + FileProgressWatch_isEnabled=false; + FileProgressWatch_QFuture.cancel(); + //================ 扫描放大后的帧文件数量,判断是否放大成功 ======================= + QStringList Frame_fileName_list_scaled = file_getFileNames_in_Folder_nofilter(ScaledFramesFolderPath); + if(Frame_fileName_list_scaled.size()checkBox_ShowInterPro->isChecked()) + { + emit Send_CurrentFileProgress_progressbar_Add_SegmentDuration(SegmentDuration_tmp); + } + StartTime+=SegmentDuration_tmp; + isSplitComplete = false; + isScaleComplete = false; + LastVideoClipNo=VideoClipNo; + emit Send_video_write_Progress_ProcessBySegment(VideoConfiguration_fullPath,StartTime,false,false,-1,VideoClipNo); + } + emit Send_CurrentFileProgress_Stop(); + //====================================================== + // 组装(片段到成片) + //====================================================== + QString video_mp4_scaled_fullpath = ""; + if(CustRes_isEnabled) + { + video_mp4_scaled_fullpath = file_path+"/"+file_name+"_waifu2x_"+QString::number(CustRes_width,10)+"x"+QString::number(CustRes_height,10)+"_"+QString::number(DenoiseLevel,10)+"n"+"_"+file_ext+".mp4"; + } + else + { + video_mp4_scaled_fullpath = file_path+"/"+file_name+"_waifu2x_"+QString::number(ScaleRatio,10)+"x_"+QString::number(DenoiseLevel,10)+"n"+"_"+file_ext+".mp4"; + } + QFile::remove(video_mp4_scaled_fullpath); + video_AssembleVideoClips(VideoClipsFolderPath,VideoClipsFolderName,video_mp4_scaled_fullpath,AudioPath); + if(QFile::exists(video_mp4_scaled_fullpath)==false)//检查是否成功生成视频 + { + if(waifu2x_STOP) + { + emit Send_Table_video_ChangeStatus_rowNumInt_statusQString(rowNum, "Interrupted"); + return 0;//如果启用stop位,则直接return + } + emit Send_TextBrowser_NewMessage(tr("Error occured when processing [")+SourceFile_fullPath+tr("]. Error: [Unable to assemble video clips.]")); + emit Send_Table_video_ChangeStatus_rowNumInt_statusQString(rowNum, "Failed"); + emit Send_progressbar_Add(); + return 0;//如果启用stop位,则直接return + } + //============================== 删除缓存文件 ==================================================== + if(ui->checkBox_KeepVideoCache->isChecked()==false) + { + QFile::remove(VideoConfiguration_fullPath); + file_DelDir(SplitFramesFolderPath); + file_DelDir(VideoClipsFolderPath); + QFile::remove(AudioPath); + if(SourceFile_fullPath!=video_mp4_fullpath)QFile::remove(video_mp4_fullpath); + } + else + { + DelOriginal=false; + } + //============================= 删除原文件 & & 更新table status ============================ + if(DelOriginal) + { + if(ReplaceOriginalFile(SourceFile_fullPath,video_mp4_scaled_fullpath)==false) + { + if(QAction_checkBox_MoveToRecycleBin_checkBox_DelOriginal->isChecked()) + { + file_MoveToTrash(SourceFile_fullPath); + } + else + { + QFile::remove(SourceFile_fullPath); + } + } + emit Send_Table_video_ChangeStatus_rowNumInt_statusQString(rowNum, "Finished, original file deleted"); + } + else + { + emit Send_Table_video_ChangeStatus_rowNumInt_statusQString(rowNum, "Finished"); + } + //========== 移动到输出路径 ========= + if(ui->checkBox_OutPath_isEnabled->isChecked()) + { + MoveFileToOutputPath(video_mp4_scaled_fullpath,SourceFile_fullPath); + } + //============================ 更新进度条 ================================= + emit Send_progressbar_Add(); + //=========================== ============================== + return 0; +} +/* +视频帧放大函数 +*/ +int MainWindow::Waifu2x_Caffe_Video_scale(QMap Sub_Thread_info,int *Sub_video_ThreadNumRunning,bool *Frame_failed) +{ + bool AllFinished=true; + QString SplitFramesFolderPath = Sub_Thread_info["SplitFramesFolderPath"]; + QString ScaledFramesFolderPath = Sub_Thread_info["ScaledFramesFolderPath"]; + //=========== + int ScaleRatio = Sub_Thread_info["ScaleRatio"].toInt(); + int DenoiseLevel = ui->spinBox_DenoiseLevel_video->value(); + //=========== + QString program = Current_Path + "/waifu2x-caffe/waifu2x-caffe_waifu2xEX.exe"; + //==== + QString ImageProcessingModeCMD = ""; + if(DenoiseLevel==-1) + { + ImageProcessingModeCMD = " -m scale -s " + QString::number(ScaleRatio, 10)+" "; + } + else + { + int DenoiseLevel_tmp =0; + if((ui->comboBox_Model_2D_Waifu2xCaffe->currentIndex()==0)&&(DenoiseLevel==0)&&(ui->comboBox_ImageStyle_Waifu2xCaffe->currentIndex()==0)) + { + DenoiseLevel_tmp=1; + } + else + { + DenoiseLevel_tmp = DenoiseLevel; + } + ImageProcessingModeCMD = " -m noise_scale -s " + QString::number(ScaleRatio, 10)+ " -n " + QString::number(DenoiseLevel_tmp, 10)+" "; + } + //======= + //======================================================================== + QStringList InputFilesNameList = file_getFileNames_in_Folder_nofilter(SplitFramesFolderPath); + QStringList OutPutFilesFullPathList; + for(int i=0; ispinBox_retry->value()+ForceRetryCount); retry++) + { + Waifu2x->start(cmd); + while(!Waifu2x->waitForStarted(100)&&!QProcess_stop) {} + while(!Waifu2x->waitForFinished(500)&&!QProcess_stop) + { + if(waifu2x_STOP) + { + QStringList FinfishedFileList = WaitForEngineIO(OutPutFilesFullPathList); + Waifu2x->close(); + //============ + QString file_fullpath_tmp; + for(int i=0; ispinBox_retry->value()+(ForceRetryCount-1))break; + Delay_sec_sleep(5); + emit Send_TextBrowser_NewMessage(tr("Automatic retry, please wait.")); + AllFinished=false; + break; + } + } + if(AllFinished)break; + } + //========= + AllFinished = true; + for(int i=0; icomboBox_ProcessMode_Waifu2xCaffe->currentIndex()) + { + case 0: + { + Waifu2x_Caffe_Settings_str.append("-p cpu "); + break; + } + case 1: + { + Waifu2x_Caffe_Settings_str.append("-p gpu "); + break; + } + case 2: + { + Waifu2x_Caffe_Settings_str.append("-p cudnn "); + break; + } + } + //模型 + QString model_folder_path = Current_Path + "/waifu2x-caffe/models/"; + int ImageStyle = ui->comboBox_ImageStyle_Waifu2xCaffe->currentIndex(); + switch(ImageStyle) + { + case 0: + { + switch(ui->comboBox_Model_2D_Waifu2xCaffe->currentIndex()) + { + case 0: + { + Waifu2x_Caffe_Settings_str.append("--model_dir \""+model_folder_path+"anime_style_art\" "); + break; + } + case 1: + { + Waifu2x_Caffe_Settings_str.append("--model_dir \""+model_folder_path+"anime_style_art_rgb\" "); + break; + } + case 2: + { + Waifu2x_Caffe_Settings_str.append("--model_dir \""+model_folder_path+"cunet\" "); + break; + } + case 3: + { + Waifu2x_Caffe_Settings_str.append("--model_dir \""+model_folder_path+"photo\" "); + break; + } + case 4: + { + Waifu2x_Caffe_Settings_str.append("--model_dir \""+model_folder_path+"upconv_7_anime_style_art_rgb\" "); + break; + } + case 5: + { + Waifu2x_Caffe_Settings_str.append("--model_dir \""+model_folder_path+"upconv_7_photo\" "); + break; + } + case 6: + { + Waifu2x_Caffe_Settings_str.append("--model_dir \""+model_folder_path+"upresnet10\" "); + break; + } + } + break; + } + case 1: + { + switch(ui->comboBox_Model_3D_Waifu2xCaffe->currentIndex()) + { + case 0: + { + Waifu2x_Caffe_Settings_str.append("--model_dir \""+model_folder_path+"upconv_7_photo\" "); + break; + } + case 1: + { + Waifu2x_Caffe_Settings_str.append("--model_dir \""+model_folder_path+"photo\" "); + break; + } + } + break; + } + } + //TTA + if(ui->checkBox_TTA_Waifu2xCaffe->isChecked()) + { + Waifu2x_Caffe_Settings_str.append("-t 1 "); + } + else + { + Waifu2x_Caffe_Settings_str.append("-t 0 "); + } + //显卡设定 + if(ui->checkBox_EnableMultiGPU_Waifu2xCaffe->isChecked()==false) + { + //单个显卡 + //GPU ID + if(ui->comboBox_ProcessMode_Waifu2xCaffe->currentIndex()>0) + { + Waifu2x_Caffe_Settings_str.append("--gpu "+QString::number(ui->spinBox_GPUID_Waifu2xCaffe->value(),10)+" "); + } + //Batch size + Waifu2x_Caffe_Settings_str.append("-b "+QString::number(ui->spinBox_BatchSize_Waifu2xCaffe->value(),10)+" "); + //Split size + Waifu2x_Caffe_Settings_str.append("-c "+QString::number(ui->spinBox_SplitSize_Waifu2xCaffe->value(),10)+" "); + } + return Waifu2x_Caffe_Settings_str; +} +/* +Waifu2x_Caffe +读取配置生成配置string +*/ +QString MainWindow::Waifu2x_Caffe_ReadSettings() +{ + QString Waifu2x_Caffe_Settings_str = ""; + Waifu2x_Caffe_Settings_str.append(Waifu2xCaffe_PreLoad_Settings_Str); + //显卡设定 + if(ui->checkBox_EnableMultiGPU_Waifu2xCaffe->isChecked()) + { + //多显卡 + Waifu2x_Caffe_Settings_str.append(Waifu2xCaffe_GetGPUInfo()+" "); + } + return Waifu2x_Caffe_Settings_str; +} +//判断是否启用了caffe引擎 +bool MainWindow::isWaifu2xCaffeEnabled() +{ + if(ui->comboBox_Engine_Image->currentIndex()!=4&&ui->comboBox_Engine_GIF->currentIndex()!=4&&ui->comboBox_Engine_Video->currentIndex()!=4) + { + ui->label_ImageStyle_W2xCaffe->setVisible(0); + ui->comboBox_ImageStyle_Waifu2xCaffe->setVisible(0); + ui->comboBox_ImageStyle_Waifu2xCaffe->setEnabled(0); + return false; + } + else + { + ui->label_ImageStyle_W2xCaffe->setVisible(1); + ui->comboBox_ImageStyle_Waifu2xCaffe->setVisible(1); + ui->comboBox_ImageStyle_Waifu2xCaffe->setEnabled(1); + return true; + } +} +/* +删除caffe引擎生成的错误日志 +*/ +void MainWindow::DeleteErrorLog_Waifu2xCaffe() +{ + QStringList FileNameList = file_getFileNames_in_Folder_nofilter(Current_Path);//读取合法的文件名 + QString Full_Path_File = ""; + if(!FileNameList.isEmpty()) + { + for(int i = 0; i < FileNameList.size(); i++) + { + QString tmp = FileNameList.at(i); + Full_Path_File = Current_Path + "/" + tmp; + if(Full_Path_File.contains("error_log_")) + { + QFile::remove(Full_Path_File); + } + } + } +} + +void MainWindow::on_checkBox_EnableMultiGPU_Waifu2xCaffe_stateChanged(int arg1) +{ + if(ui->checkBox_EnableMultiGPU_Waifu2xCaffe->isChecked()) + { + ui->lineEdit_MultiGPUInfo_Waifu2xCaffe->setEnabled(1); + ui->pushButton_VerifyGPUsConfig_Waifu2xCaffe->setEnabled(1); + //=== + ui->pushButton_SplitSize_Add_Waifu2xCaffe->setEnabled(0); + ui->pushButton_SplitSize_Minus_Waifu2xCaffe->setEnabled(0); + ui->spinBox_BatchSize_Waifu2xCaffe->setEnabled(0); + ui->spinBox_GPUID_Waifu2xCaffe->setEnabled(0); + ui->spinBox_SplitSize_Waifu2xCaffe->setEnabled(0); + } + else + { + ui->lineEdit_MultiGPUInfo_Waifu2xCaffe->setEnabled(0); + ui->pushButton_VerifyGPUsConfig_Waifu2xCaffe->setEnabled(0); + //=== + ui->pushButton_SplitSize_Add_Waifu2xCaffe->setEnabled(1); + ui->pushButton_SplitSize_Minus_Waifu2xCaffe->setEnabled(1); + ui->spinBox_BatchSize_Waifu2xCaffe->setEnabled(1); + ui->spinBox_GPUID_Waifu2xCaffe->setEnabled(1); + ui->spinBox_SplitSize_Waifu2xCaffe->setEnabled(1); + } +} + +void MainWindow::on_comboBox_ProcessMode_Waifu2xCaffe_currentIndexChanged(int index) +{ + if(ui->comboBox_ProcessMode_Waifu2xCaffe->currentIndex()==0) + { + ui->checkBox_EnableMultiGPU_Waifu2xCaffe->setEnabled(0); + ui->checkBox_EnableMultiGPU_Waifu2xCaffe->setChecked(0); + } + else + { + ui->checkBox_EnableMultiGPU_Waifu2xCaffe->setEnabled(1); + } +} +//读取多显卡设定 +QString MainWindow::Waifu2xCaffe_GetGPUInfo() +{ + GetGPUInfo_QMutex_Waifu2xCaffe.lock(); + //==== + QStringList GPU_List = ui->lineEdit_MultiGPUInfo_Waifu2xCaffe->text().trimmed().remove(" ").remove(" ").split(":"); + GPU_List.removeDuplicates(); + GPU_List.removeAll(""); + //==== + int MAX_GPU_ID_Waifu2xCaffe = GPU_List.size()-1; + if(GPU_ID_Waifu2xCaffe_GetGPUInfo>MAX_GPU_ID_Waifu2xCaffe) + { + GPU_ID_Waifu2xCaffe_GetGPUInfo=0; + } + //====== + QString GPUInfo=""; + QStringList GPUID_BatchSize_SplitSize = GPU_List.at(GPU_ID_Waifu2xCaffe_GetGPUInfo).split(","); + GPUID_BatchSize_SplitSize.removeAll(""); + if(GPUID_BatchSize_SplitSize.size()==3) + { + GPUInfo = "--gpu "+GPUID_BatchSize_SplitSize.at(0).trimmed()+" -b "+GPUID_BatchSize_SplitSize.at(1).trimmed()+" -c "+GPUID_BatchSize_SplitSize.at(2).trimmed(); + } + else + { + GPUInfo = "--gpu 0 -b 1 -c 64"; + } + //====== + GPU_ID_Waifu2xCaffe_GetGPUInfo++; + if(GPU_ID_Waifu2xCaffe_GetGPUInfo>MAX_GPU_ID_Waifu2xCaffe) + { + GPU_ID_Waifu2xCaffe_GetGPUInfo=0; + } + //====== + GetGPUInfo_QMutex_Waifu2xCaffe.unlock(); + return GPUInfo; +} + +void MainWindow::on_lineEdit_MultiGPUInfo_Waifu2xCaffe_editingFinished() +{ + QString Format_str="0123456789:,"; + QString GPUs_str = ui->lineEdit_MultiGPUInfo_Waifu2xCaffe->text().trimmed().replace(":",":").replace(",",",").remove(" ").remove(" "); + for (int i=0; ilineEdit_MultiGPUInfo_Waifu2xCaffe->setText(GPUs_str); +} + +void MainWindow::on_pushButton_VerifyGPUsConfig_Waifu2xCaffe_clicked() +{ + on_lineEdit_MultiGPUInfo_Waifu2xCaffe_editingFinished(); + QStringList GPU_List = ui->lineEdit_MultiGPUInfo_Waifu2xCaffe->text().trimmed().remove(" ").remove(" ").split(":"); + GPU_List.removeDuplicates(); + GPU_List.removeAll(""); + //====== + QString VerRes = ""; + //====== + for (int i=0; isetWindowTitle(tr("GPUs List according to your configuration")); + MSG->setText(VerRes); + MSG->setIcon(QMessageBox::Information); + MSG->setModal(true); + MSG->show(); + //====== + emit Send_TextBrowser_NewMessage("\nWaifu2x-caffe GPUs List(user configuration):\n"+VerRes); +} + +int MainWindow::Get_NumOfGPU_W2xCaffe() +{ + QStringList GPU_List = ui->lineEdit_MultiGPUInfo_Waifu2xCaffe->text().trimmed().remove(" ").remove(" ").split(":"); + GPU_List.removeDuplicates(); + GPU_List.removeAll(""); + int GPUNum = 0; + QStringList GPUID_BatchSize_SplitSize; + //====== + for (int i=0; i FileProgressWatch_QFuture = QtConcurrent::run(this, &MainWindow::CurrentFileProgress_WatchFolderFileNum, scaledFramesFolder);//启动waifu2x 主线程 + if(ui->checkBox_ShowInterPro->isChecked()==false) + { + FileProgressWatch_isEnabled=false; + FileProgressWatch_QFuture.cancel(); + emit Send_CurrentFileProgress_Stop(); + } + //=======获取显卡信息======== + int NumOfGPU = 1; + if(ui->checkBox_EnableMultiGPU_Waifu2xCaffe->isChecked()==true) + { + NumOfGPU = Get_NumOfGPU_W2xCaffe(); + } + //============创建显卡文件夹=========== + QStringList GPU_splitFramesFolder_List; + for(int i = 0; i < NumOfGPU; i++) + { + QString GPU_splitFramesFolder = splitFramesFolder+"/"+"GPU_"+QString::number(i); + if(file_isDirExist(GPU_splitFramesFolder)) + { + file_DelDir(GPU_splitFramesFolder); + file_mkDir(GPU_splitFramesFolder); + } + else + { + file_mkDir(GPU_splitFramesFolder); + } + GPU_splitFramesFolder_List.append(GPU_splitFramesFolder); + } + int TotalFramesNum = framesFileName_qStrList.size(); + int FramesNumForEachGPU = TotalFramesNum/NumOfGPU; + if(FramesNumForEachGPU<1)FramesNumForEachGPU=1; + int start_num=0; + for(int x = 0; x < GPU_splitFramesFolder_List.size(); x++) + { + if(x==GPU_splitFramesFolder_List.size()-1)FramesNumForEachGPU=TotalFramesNum; + QStringList file_waitformove = framesFileName_qStrList.mid(start_num,FramesNumForEachGPU); + for(int i = 0; i < file_waitformove.size(); i++) + { + QString FileName = file_waitformove.at(i); + QFile::rename(splitFramesFolder+"/"+FileName,GPU_splitFramesFolder_List.at(x)+"/"+FileName); + } + start_num+=FramesNumForEachGPU; + } + //========================= + bool Frame_failed = false;//放大失败标志 + int Sub_gif_ThreadNumRunning = 0; + //==== + QMap Sub_Thread_info; + Sub_Thread_info["scaledFramesFolder"]= scaledFramesFolder; + if(CustRes_isContained(sourceFileFullPath)) + { + QMap Res_map = CustRes_getResMap(sourceFileFullPath);//res_map["fullpath"],["height"],["width"] + Sub_Thread_info["ScaleRatio"] = QString("%1").arg(CustRes_CalNewScaleRatio(sourceFileFullPath,Res_map["height"].toInt(),Res_map["width"].toInt())); + } + else + { + Sub_Thread_info["ScaleRatio"] = QString("%1").arg(qRound(ui->doubleSpinBox_ScaleRatio_gif->value())); + } + //========================= + for(int i = 0; i < GPU_splitFramesFolder_List.size(); i++) + { + Sub_Thread_info["splitFramesFolder"]=GPU_splitFramesFolder_List.at(i); + mutex_SubThreadNumRunning.lock(); + Sub_gif_ThreadNumRunning++; + mutex_SubThreadNumRunning.unlock(); + QtConcurrent::run(this,&MainWindow::Waifu2x_Caffe_APNG_scale,Sub_Thread_info,&Sub_gif_ThreadNumRunning,&Frame_failed); + while (Sub_gif_ThreadNumRunning >= NumOfGPU) + { + Delay_msec_sleep(500); + } + if(waifu2x_STOP) + { + while (Sub_gif_ThreadNumRunning > 0) + { + Delay_msec_sleep(500); + } + FileProgressWatch_isEnabled=false; + FileProgressWatch_QFuture.cancel(); + return false; + } + if(Frame_failed) + { + FileProgressWatch_isEnabled=false; + FileProgressWatch_QFuture.cancel(); + emit Send_TextBrowser_NewMessage(tr("Error occured when processing [")+sourceFileFullPath+tr("]. Error: [Failed to scale frames.]")); + return false; + } + } + while (Sub_gif_ThreadNumRunning!=0) + { + Delay_msec_sleep(500); + } + FileProgressWatch_isEnabled=false; + FileProgressWatch_QFuture.cancel(); + emit Send_CurrentFileProgress_Stop(); + //======================= 检查是否成功放大所有帧 =========================== + QStringList framesFileName_qStrList_scaled = file_getFileNames_in_Folder_nofilter(scaledFramesFolder); + if(framesFileName_qStrList.size()!=framesFileName_qStrList_scaled.size()) + { + emit Send_TextBrowser_NewMessage(tr("Error occured when processing [")+sourceFileFullPath+tr("]. Error: [Failed to scale frames.]")); + return false; + } + //============================================================ + //组装apng + APNG_Frames2APNG(sourceFileFullPath, scaledFramesFolder, resultFileFullPath, false); + return true; +} +/* +Waifu2x Caffe APNG 放大子线程 +*/ +int MainWindow::Waifu2x_Caffe_APNG_scale(QMap Sub_Thread_info,int *Sub_gif_ThreadNumRunning,bool *Frame_failed) +{ + bool AllFinished=true; + QString splitFramesFolder = Sub_Thread_info["splitFramesFolder"]; + QString scaledFramesFolder = Sub_Thread_info["scaledFramesFolder"]; + //=========== + int ScaleRatio = Sub_Thread_info["ScaleRatio"].toInt(); + int DenoiseLevel = ui->spinBox_DenoiseLevel_gif->value(); + //=========== + QString program = Current_Path + "/waifu2x-caffe/waifu2x-caffe_waifu2xEX.exe"; + //==== + QString ImageProcessingModeCMD = ""; + if(DenoiseLevel==-1) + { + ImageProcessingModeCMD = " -m scale -s " + QString::number(ScaleRatio, 10)+" "; + } + else + { + int DenoiseLevel_tmp =0; + if((ui->comboBox_Model_2D_Waifu2xCaffe->currentIndex()==0)&&(DenoiseLevel==0)&&(ui->comboBox_ImageStyle_Waifu2xCaffe->currentIndex()==0)) + { + DenoiseLevel_tmp=1; + } + else + { + DenoiseLevel_tmp = DenoiseLevel; + } + ImageProcessingModeCMD = " -m noise_scale -s " + QString::number(ScaleRatio, 10)+ " -n " + QString::number(DenoiseLevel_tmp, 10)+" "; + } + //======= + //======================================================================== + QStringList InputFilesNameList = file_getFileNames_in_Folder_nofilter(splitFramesFolder); + QStringList OutPutFilesFullPathList; + for(int i=0; ispinBox_retry->value()+ForceRetryCount); retry++) + { + Waifu2x->start(cmd); + while(!Waifu2x->waitForStarted(100)&&!QProcess_stop) {} + while(!Waifu2x->waitForFinished(500)&&!QProcess_stop) + { + if(waifu2x_STOP) + { + Waifu2x->close(); + mutex_SubThreadNumRunning.lock(); + *Sub_gif_ThreadNumRunning=*Sub_gif_ThreadNumRunning-1; + mutex_SubThreadNumRunning.unlock(); + return 0; + } + } + AllFinished = true; + for(int i=0; ispinBox_retry->value()+(ForceRetryCount-1))break; + Delay_sec_sleep(5); + emit Send_TextBrowser_NewMessage(tr("Automatic retry, please wait.")); + AllFinished=false; + break; + } + } + if(AllFinished)break; + } + //========= + AllFinished = true; + for(int i=0; i. - - My Github homepage: https://github.com/AaronFeng753 -*/ - -#include "mainwindow.h" -#include "ui_mainwindow.h" - -int MainWindow::Waifu2x_Converter_Image(int rowNum,bool ReProcess_MissingAlphaChannel) -{ - //============================= 读取设置 ================================ - int DenoiseLevel = ui->spinBox_DenoiseLevel_image->value(); - bool DelOriginal = (ui->checkBox_DelOriginal->isChecked()||ui->checkBox_ReplaceOriginalFile->isChecked()); - QString OutPutPath_Final =""; - //========================= 拆解map得到参数 ============================= - emit Send_Table_image_ChangeStatus_rowNumInt_statusQString(rowNum, "Processing"); - QString SourceFile_fullPath = Table_model_image->item(rowNum,2)->text(); - if(!QFile::exists(SourceFile_fullPath)) - { - emit Send_TextBrowser_NewMessage(tr("Error occured when processing [")+SourceFile_fullPath+tr("]. Error: [File does not exist.]")); - emit Send_Table_image_ChangeStatus_rowNumInt_statusQString(rowNum, "Failed"); - emit Send_progressbar_Add(); - mutex_ThreadNumRunning.lock(); - ThreadNumRunning--; - mutex_ThreadNumRunning.unlock();//线程数量统计-1 - return 0; - } - //========= 转换到 PNG ========= - QString SourceFile_fullPath_Original = SourceFile_fullPath; - SourceFile_fullPath = Imgae_PreProcess(SourceFile_fullPath_Original,ReProcess_MissingAlphaChannel); - //======================================================= - int ScaleRatio = 2; - bool CustRes_isEnabled = false; - int CustRes_height=0; - int CustRes_width=0; - if(CustRes_isContained(SourceFile_fullPath_Original)) - { - CustRes_isEnabled=true; - QMap Res_map = CustRes_getResMap(SourceFile_fullPath_Original);//res_map["fullpath"],["height"],["width"] - ScaleRatio = CustRes_CalNewScaleRatio(SourceFile_fullPath,Res_map["height"].toInt(),Res_map["width"].toInt()); - if(ScaleRatio==0) - { - emit Send_TextBrowser_NewMessage(tr("Error occured when processing [")+SourceFile_fullPath_Original+tr("]. Error: [The resolution of the source file cannot be read, so the image cannot be scaled to a custom resolution.]")); - emit Send_Table_image_ChangeStatus_rowNumInt_statusQString(rowNum, "Failed"); - emit Send_progressbar_Add(); - mutex_ThreadNumRunning.lock(); - ThreadNumRunning--; - mutex_ThreadNumRunning.unlock();//线程数量统计-1 - return 0; - } - CustRes_height=Res_map["height"].toInt(); - CustRes_width=Res_map["width"].toInt(); - } - else - { - double ScaleRatio_double_tmp = ui->doubleSpinBox_ScaleRatio_image->value(); - if(ScaleRatio_double_tmp == (int)ScaleRatio_double_tmp) - { - ScaleRatio = qRound(ScaleRatio_double_tmp); - } - else - { - CustRes_isEnabled=true; - QMap Res_map = DoubleScaleRatio_Cal_NewScaleRatio_NewHW(SourceFile_fullPath,ScaleRatio_double_tmp); - //==== - if(Res_map.isEmpty()) - { - emit Send_TextBrowser_NewMessage(tr("Error occured when processing [")+SourceFile_fullPath+tr("]. Error: [Unable to read the resolution of the source file.]")); - emit Send_Table_image_ChangeStatus_rowNumInt_statusQString(rowNum, "Failed"); - emit Send_progressbar_Add(); - mutex_ThreadNumRunning.lock(); - ThreadNumRunning--; - mutex_ThreadNumRunning.unlock();//线程数量统计-1 - return 0; - } - //==== - ScaleRatio = Res_map["ScaleRatio"].toInt(); - CustRes_height = Res_map["Height_new"].toInt(); - CustRes_width = Res_map["width_new"].toInt(); - } - } - //======================================================= - QFileInfo fileinfo(SourceFile_fullPath); - QString file_name = file_getBaseName(SourceFile_fullPath); - QString file_ext = fileinfo.suffix(); - QString file_path = file_getFolderPath(fileinfo); - QString OutPut_Path = file_path + "/" + file_name + "_waifu2x_"+QString::number(ScaleRatio, 10)+"x_"+QString::number(DenoiseLevel, 10)+"n_"+file_ext+".png"; - //============================== 放大 ======================================= - QString Denoise_cmd = " --noise-level " + QString::number(DenoiseLevel, 10); - //==== - QString cmd = "\"" + Current_Path + "/waifu2x-converter/waifu2x-converter-cpp_waifu2xEX.exe" + "\"" + " -i " + "\"" + SourceFile_fullPath + "\"" + " -o " + "\"" + OutPut_Path + "\"" + " --scale-ratio " + QString::number(ScaleRatio, 10) + Denoise_cmd + Waifu2xConverter_ReadSettings(); - //======== - for(int retry=0; retry<(ui->spinBox_retry->value()+ForceRetryCount); retry++) - { - QProcess *Waifu2x = new QProcess(); - Waifu2x->start(cmd); - while(!Waifu2x->waitForStarted(100)&&!QProcess_stop) {} - while(!Waifu2x->waitForFinished(500)&&!QProcess_stop) - { - if(waifu2x_STOP) - { - Waifu2x->close(); - QFile::remove(OutPut_Path); - emit Send_Table_image_ChangeStatus_rowNumInt_statusQString(rowNum, "Interrupted"); - mutex_ThreadNumRunning.lock(); - ThreadNumRunning--; - mutex_ThreadNumRunning.unlock(); - return 0; - } - } - if(QFile::exists(OutPut_Path)) - { - break; - } - else - { - if(retry==ui->spinBox_retry->value()+(ForceRetryCount-1))break; - Delay_sec_sleep(5); - emit Send_TextBrowser_NewMessage(tr("Automatic retry, please wait.")); - } - } - //======== - if(!QFile::exists(OutPut_Path)) - { - if(SourceFile_fullPath_Original!=SourceFile_fullPath) - { - QFile::remove(SourceFile_fullPath); - } - emit Send_TextBrowser_NewMessage(tr("Error occured when processing [")+SourceFile_fullPath_Original+tr("]. Error: [Unable to scale the picture.]")); - emit Send_Table_image_ChangeStatus_rowNumInt_statusQString(rowNum, "Failed"); - emit Send_progressbar_Add(); - mutex_ThreadNumRunning.lock(); - ThreadNumRunning--; - mutex_ThreadNumRunning.unlock(); - return 0; - } - OutPutPath_Final = OutPut_Path; - //============================ 调整大小 ==================================================== - if(CustRes_isEnabled) - { - do - { - QImage qimage_adj(OutPut_Path); - //读取放大后的图片并调整大小 - QImage qimage_adj_scaled = qimage_adj.scaled(CustRes_width,CustRes_height,CustRes_AspectRatioMode,Qt::SmoothTransformation); - QImageWriter qimageW_adj; - qimageW_adj.setFormat("png"); - qimageW_adj.setFileName(OutPut_Path); - if(qimageW_adj.canWrite()) - { - qimageW_adj.write(qimage_adj_scaled); - } - if(!QFile::exists(OutPut_Path)) - { - emit Send_TextBrowser_NewMessage(tr("Error occured when processing [")+SourceFile_fullPath+tr("]. Error: [Unable to resize the scaled picture to the target size]")); - emit Send_Table_image_ChangeStatus_rowNumInt_statusQString(rowNum, "Failed"); - emit Send_progressbar_Add(); - mutex_ThreadNumRunning.lock(); - ThreadNumRunning--; - mutex_ThreadNumRunning.unlock();//线程数量统计-1 - return 0; - } - } - while(false); - QString OutPut_Path_CustRes = file_path + "/" + file_name + "_waifu2x_"+QString::number(CustRes_width, 10)+"x"+QString::number(CustRes_height, 10)+"_"+QString::number(DenoiseLevel, 10)+"n_"+file_ext+".png"; - QFile::remove(OutPut_Path_CustRes); - QFile::rename(OutPut_Path,OutPut_Path_CustRes); - OutPutPath_Final = OutPut_Path_CustRes; - } - //=========================== 另存为JPG&压缩JPG =========================================== - OutPutPath_Final = SaveImageAs_FormatAndQuality(SourceFile_fullPath_Original,OutPutPath_Final,true,DenoiseLevel); - //================== 检查是否丢失了透明通道 ===================== - if(ReProcess_MissingAlphaChannel==false) - { - QImage QImage_source(SourceFile_fullPath_Original); - QImage QImage_Final(OutPutPath_Final); - if(QImage_source.hasAlphaChannel()==true && QImage_Final.hasAlphaChannel()==false && ui->checkBox_AutoDetectAlphaChannel->isChecked()) - { - QFile::remove(OutPutPath_Final); - emit Send_TextBrowser_NewMessage(tr("Since the Alpha channel in the resulting image is lost, this image will be reprocessed to fix it:[")+SourceFile_fullPath_Original+tr("].\nIf the reprocessing happens a lot, you should consider enable [Always pre-process images with Alpha Channel] in [Additional settings].")); - return Waifu2x_Converter_Image(rowNum,true); - } - } - //============================= 删除原文件 & & 更新table status ============================ - if(SourceFile_fullPath_Original!=SourceFile_fullPath) - { - QFile::remove(SourceFile_fullPath); - SourceFile_fullPath = SourceFile_fullPath_Original; - } - if(DelOriginal) - { - if(ReplaceOriginalFile(SourceFile_fullPath,OutPutPath_Final)==false) - { - if(QAction_checkBox_MoveToRecycleBin_checkBox_DelOriginal->isChecked()) - { - file_MoveToTrash(SourceFile_fullPath); - } - else - { - QFile::remove(SourceFile_fullPath); - } - } - emit Send_Table_image_ChangeStatus_rowNumInt_statusQString(rowNum, "Finished, original file deleted"); - } - else - { - emit Send_Table_image_ChangeStatus_rowNumInt_statusQString(rowNum, "Finished"); - } - //========== 移动到输出路径 ========= - if(ui->checkBox_OutPath_isEnabled->isChecked()) - { - MoveFileToOutputPath(OutPutPath_Final,SourceFile_fullPath); - } - //============================ 更新进度条 ================================= - emit Send_progressbar_Add(); - //=========================== 更新线程数量统计============================== - mutex_ThreadNumRunning.lock(); - ThreadNumRunning--; - mutex_ThreadNumRunning.unlock();//线程数量统计-1 - return 0; -} - - -int MainWindow::Waifu2x_Converter_GIF(int rowNum) -{ - //============================= 读取设置 ================================ - int ScaleRatio = ui->doubleSpinBox_ScaleRatio_gif->value(); - int DenoiseLevel = ui->spinBox_DenoiseLevel_gif->value(); - bool DelOriginal = (ui->checkBox_DelOriginal->isChecked()||ui->checkBox_ReplaceOriginalFile->isChecked()); - int Sub_gif_ThreadNumRunning = 0; - QString OutPutPath_Final =""; - //========================= 拆解map得到参数 ============================= - emit Send_Table_gif_ChangeStatus_rowNumInt_statusQString(rowNum, "Processing"); - QString SourceFile_fullPath = Table_model_gif->item(rowNum,2)->text(); - if(!QFile::exists(SourceFile_fullPath)) - { - emit Send_TextBrowser_NewMessage(tr("Error occured when processing [")+SourceFile_fullPath+tr("]. Error: [File does not exist.]")); - emit Send_Table_gif_ChangeStatus_rowNumInt_statusQString(rowNum, "Failed"); - emit Send_progressbar_Add(); - return 0; - } - //========================== - bool CustRes_isEnabled = false; - int CustRes_height=0; - int CustRes_width=0; - if(CustRes_isContained(SourceFile_fullPath)) - { - CustRes_isEnabled=true; - QMap Res_map = CustRes_getResMap(SourceFile_fullPath);//res_map["fullpath"],["height"],["width"] - CustRes_height=Res_map["height"].toInt(); - CustRes_width=Res_map["width"].toInt(); - } - //========================== - QFileInfo fileinfo(SourceFile_fullPath); - QString file_name = file_getBaseName(SourceFile_fullPath); - QString file_ext = fileinfo.suffix(); - QString file_path = file_getFolderPath(fileinfo); - QString ResGIFPath = file_path + "/" + file_name + "_waifu2x_"+QString::number(ScaleRatio, 10)+"x_"+QString::number(DenoiseLevel, 10)+"n.gif"; - //=========================== 获取帧时间 ==================================== - int GIF_Duration = Gif_getDuration(SourceFile_fullPath); - if(GIF_Duration==0)//检查是否成功获取duration - { - emit Send_TextBrowser_NewMessage(tr("Error occured when processing [")+SourceFile_fullPath+tr("]. Error: [Can't get Duration value of GIF file.]")); - emit Send_Table_gif_ChangeStatus_rowNumInt_statusQString(rowNum, "Failed"); - //file_DelDir(SplitFramesFolderPath); - emit Send_progressbar_Add(); - return 0;//如果启用stop位,则直接return - } - //============================== 拆分 ========================================== - QString SplitFramesFolderPath = file_path+"/"+file_name+"_SplitFrames_W2xEX";//拆分后存储frame的文件夹 - Gif_splitGif(SourceFile_fullPath,SplitFramesFolderPath); - //============================== 扫描获取文件名 =============================== - QStringList Frame_fileName_list = file_getFileNames_in_Folder_nofilter(SplitFramesFolderPath); - if(Frame_fileName_list.isEmpty())//检查是否成功拆分gif - { - emit Send_TextBrowser_NewMessage(tr("Error occured when processing [")+SourceFile_fullPath+tr("]. Error: [Can't split GIF into frames.]")); - emit Send_Table_gif_ChangeStatus_rowNumInt_statusQString(rowNum, "Failed"); - file_DelDir(SplitFramesFolderPath); - emit Send_progressbar_Add(); - return 0;//如果启用stop位,则直接return - } - //===========建立存储放大后frame的文件夹=========== - QString ScaledFramesFolderPath = SplitFramesFolderPath+"/ScaledFrames_W2xEX"; - if(file_isDirExist(ScaledFramesFolderPath)) - { - file_DelDir(ScaledFramesFolderPath); - file_mkDir(ScaledFramesFolderPath); - } - else - { - file_mkDir(ScaledFramesFolderPath); - } - //==========开始放大========================== - emit Send_CurrentFileProgress_Start(file_name+"."+file_ext,Frame_fileName_list.size()); - FileProgressWatch_isEnabled=true; - QFuture FileProgressWatch_QFuture = QtConcurrent::run(this, &MainWindow::CurrentFileProgress_WatchFolderFileNum, ScaledFramesFolderPath);//启动waifu2x 主线程 - if(ui->checkBox_ShowInterPro->isChecked()==false) - { - FileProgressWatch_isEnabled=false; - FileProgressWatch_QFuture.cancel(); - emit Send_CurrentFileProgress_Stop(); - } - //=======获取显卡信息======== - int NumOfGPU = 1; - if(ui->checkBox_MultiGPU_Waifu2xConverter->isChecked()==true) - { - NumOfGPU=0; - for (int i=0; i GPUInfo_tmp = GPUIDs_List_MultiGPU_Waifu2xConverter.at(i); - if(GPUInfo_tmp["isEnabled"] == "true") - { - NumOfGPU++; - } - } - } - //============创建显卡文件夹=========== - QStringList GPU_SplitFramesFolderPath_List; - for(int i = 0; i < NumOfGPU; i++) - { - QString GPU_SplitFramesFolderPath = SplitFramesFolderPath+"/"+"GPU_"+QString::number(i); - if(file_isDirExist(GPU_SplitFramesFolderPath)) - { - file_DelDir(GPU_SplitFramesFolderPath); - file_mkDir(GPU_SplitFramesFolderPath); - } - else - { - file_mkDir(GPU_SplitFramesFolderPath); - } - GPU_SplitFramesFolderPath_List.append(GPU_SplitFramesFolderPath); - } - int TotalFramesNum = Frame_fileName_list.size(); - int FramesNumForEachGPU = TotalFramesNum/NumOfGPU; - if(FramesNumForEachGPU<1)FramesNumForEachGPU=1; - int start_num=0; - for(int x = 0; x < GPU_SplitFramesFolderPath_List.size(); x++) - { - if(x==GPU_SplitFramesFolderPath_List.size()-1)FramesNumForEachGPU=TotalFramesNum; - QStringList file_waitformove = Frame_fileName_list.mid(start_num,FramesNumForEachGPU); - for(int i = 0; i < file_waitformove.size(); i++) - { - QString FileName = file_waitformove.at(i); - QFile::rename(SplitFramesFolderPath+"/"+FileName,GPU_SplitFramesFolderPath_List.at(x)+"/"+FileName); - } - start_num+=FramesNumForEachGPU; - } - //========================= - bool Frame_failed = false;//放大失败标志 - //==== - QMap Sub_Thread_info; - Sub_Thread_info["ScaledFramesFolderPath"]= ScaledFramesFolderPath; - Sub_Thread_info["Denoise_cmd"] = " --noise-level " + QString::number(DenoiseLevel, 10); - if(CustRes_isEnabled == true) - { - Sub_Thread_info["ScaleRatio"] = QString("%1").arg(CustRes_CalNewScaleRatio(SourceFile_fullPath,CustRes_height,CustRes_width)); - } - else - { - Sub_Thread_info["ScaleRatio"] = QString("%1").arg(ScaleRatio); - } - //========================= - for(int i = 0; i < GPU_SplitFramesFolderPath_List.size(); i++) - { - Sub_Thread_info["SplitFramesFolderPath"]=GPU_SplitFramesFolderPath_List.at(i); - mutex_SubThreadNumRunning.lock(); - Sub_gif_ThreadNumRunning++; - mutex_SubThreadNumRunning.unlock(); - QtConcurrent::run(this,&MainWindow::Waifu2x_Converter_GIF_scale,Sub_Thread_info,&Sub_gif_ThreadNumRunning,&Frame_failed); - while (Sub_gif_ThreadNumRunning >= NumOfGPU) - { - Delay_msec_sleep(500); - } - if(waifu2x_STOP) - { - while (Sub_gif_ThreadNumRunning > 0) - { - Delay_msec_sleep(500); - } - FileProgressWatch_isEnabled=false; - FileProgressWatch_QFuture.cancel(); - file_DelDir(SplitFramesFolderPath); - emit Send_Table_gif_ChangeStatus_rowNumInt_statusQString(rowNum, "Interrupted"); - return 0;//如果启用stop位,则直接return - } - if(Frame_failed) - { - FileProgressWatch_isEnabled=false; - FileProgressWatch_QFuture.cancel(); - emit Send_TextBrowser_NewMessage(tr("Error occured when processing [")+SourceFile_fullPath+tr("]. Error: [Failed to scale frames.]")); - emit Send_Table_gif_ChangeStatus_rowNumInt_statusQString(rowNum, "Failed"); - file_DelDir(SplitFramesFolderPath); - emit Send_progressbar_Add(); - return 0;//如果启用stop位,则直接return - } - } - while (Sub_gif_ThreadNumRunning!=0) - { - Delay_msec_sleep(500); - } - FileProgressWatch_isEnabled=false; - FileProgressWatch_QFuture.cancel(); - emit Send_CurrentFileProgress_Stop(); - //======================= 检查是否成功放大所有帧 =========================== - if(Frame_fileName_list.size() != file_getFileNames_in_Folder_nofilter(ScaledFramesFolderPath).size()) - { - emit Send_TextBrowser_NewMessage(tr("Error occured when processing [")+SourceFile_fullPath+tr("]. Error: [Failed to scale frames.]")); - emit Send_Table_gif_ChangeStatus_rowNumInt_statusQString(rowNum, "Failed"); - file_DelDir(SplitFramesFolderPath); - emit Send_progressbar_Add(); - return 0;//如果启用stop位,则直接return - } - //======================================== 组装 ====================================================== - if(CustRes_isEnabled == true) - { - ResGIFPath = file_path + "/" + file_name + "_waifu2x_"+QString::number(CustRes_width, 10)+"x"+QString::number(CustRes_height,10)+"_"+QString::number(DenoiseLevel, 10)+"n.gif"; - } - Gif_assembleGif(ResGIFPath,ScaledFramesFolderPath,GIF_Duration,CustRes_isEnabled,CustRes_height,CustRes_width,false,""); - if(QFile::exists(ResGIFPath) == false) - { - emit Send_TextBrowser_NewMessage(tr("Error occured when processing [")+SourceFile_fullPath+tr("]. Error: [Unable to assemble gif.]")); - emit Send_Table_gif_ChangeStatus_rowNumInt_statusQString(rowNum, "Failed"); - file_DelDir(SplitFramesFolderPath); - emit Send_progressbar_Add(); - return 0;//如果启用stop位,则直接return - } - OutPutPath_Final = ResGIFPath; - //======================================= 优化gif =================================================== - if(ui->checkBox_OptGIF->isChecked() == true) - { - QString ResGIFPath_compressed = ""; - if(CustRes_isEnabled == true) - { - ResGIFPath_compressed = file_path + "/" + file_name + "_waifu2x_"+QString::number(CustRes_width, 10)+"x"+QString::number(CustRes_height,10)+"_"+QString::number(DenoiseLevel, 10)+"n_opt.gif"; - } - else - { - ResGIFPath_compressed = file_path + "/" + file_name + "_waifu2x_"+QString::number(ScaleRatio, 10)+"x_"+QString::number(DenoiseLevel, 10)+"n_opt.gif"; - } - OutPutPath_Final = Gif_compressGif(ResGIFPath,ResGIFPath_compressed); - } - //============================== 删除缓存文件 ==================================================== - file_DelDir(SplitFramesFolderPath); - //============================= 删除原文件 & & 更新table status ============================ - if(DelOriginal) - { - if(ReplaceOriginalFile(SourceFile_fullPath,OutPutPath_Final)==false) - { - if(QAction_checkBox_MoveToRecycleBin_checkBox_DelOriginal->isChecked()) - { - file_MoveToTrash(SourceFile_fullPath); - } - else - { - QFile::remove(SourceFile_fullPath); - } - } - emit Send_Table_gif_ChangeStatus_rowNumInt_statusQString(rowNum, "Finished, original file deleted"); - } - else - { - emit Send_Table_gif_ChangeStatus_rowNumInt_statusQString(rowNum, "Finished"); - } - //========== 移动到输出路径 ========= - if(ui->checkBox_OutPath_isEnabled->isChecked()) - { - MoveFileToOutputPath(OutPutPath_Final,SourceFile_fullPath); - } - //============================ 更新进度条 ================================= - emit Send_progressbar_Add(); - //======= - return 0; -} - -int MainWindow::Waifu2x_Converter_GIF_scale(QMap Sub_Thread_info,int *Sub_gif_ThreadNumRunning,bool *Frame_failed) -{ - bool AllFinished; - QString SplitFramesFolderPath = Sub_Thread_info["SplitFramesFolderPath"]; - QString ScaledFramesFolderPath = Sub_Thread_info["ScaledFramesFolderPath"]; - //=========== - QString Denoise_cmd = Sub_Thread_info["Denoise_cmd"]; - //======================================================================== - QStringList InputFilesNameList = file_getFileNames_in_Folder_nofilter(SplitFramesFolderPath); - QStringList OutPutFilesFullPathList; - for(int i=0; ispinBox_retry->value()+ForceRetryCount); retry++) - { - Waifu2x->start(cmd); - while(!Waifu2x->waitForStarted(100)&&!QProcess_stop) {} - while(!Waifu2x->waitForFinished(500)&&!QProcess_stop) - { - if(waifu2x_STOP) - { - Waifu2x->close(); - mutex_SubThreadNumRunning.lock(); - *Sub_gif_ThreadNumRunning=*Sub_gif_ThreadNumRunning-1; - mutex_SubThreadNumRunning.unlock(); - return 0; - } - } - AllFinished = true; - for(int i=0; ispinBox_retry->value()+(ForceRetryCount-1))break; - Delay_sec_sleep(5); - emit Send_TextBrowser_NewMessage(tr("Automatic retry, please wait.")); - AllFinished=false; - break; - } - } - if(AllFinished)break; - } - //========= - AllFinished = true; - for(int i=0; idoubleSpinBox_ScaleRatio_video->value(); - int DenoiseLevel = ui->spinBox_DenoiseLevel_video->value(); - bool DelOriginal = (ui->checkBox_DelOriginal->isChecked()||ui->checkBox_ReplaceOriginalFile->isChecked()); - bool isCacheExists = false; - bool isVideoConfigChanged = true; - int Sub_video_ThreadNumRunning = 0; - //========================= 拆解map得到参数 ============================= - emit Send_Table_video_ChangeStatus_rowNumInt_statusQString(rowNum, "Processing"); - QString SourceFile_fullPath = Table_model_video->item(rowNum,2)->text(); - if(!QFile::exists(SourceFile_fullPath)) - { - emit Send_TextBrowser_NewMessage(tr("Error occured when processing [")+SourceFile_fullPath+tr("]. Error: [File does not exist.]")); - emit Send_Table_video_ChangeStatus_rowNumInt_statusQString(rowNum, "Failed"); - emit Send_progressbar_Add(); - return 0; - } - //========================== - QFileInfo fileinfo(SourceFile_fullPath); - QString file_name = file_getBaseName(SourceFile_fullPath); - QString file_ext = fileinfo.suffix(); - QString file_path = file_getFolderPath(fileinfo); - //=================================================================== - //生成mp4 - QString video_mp4_fullpath=video_To_CFRMp4(SourceFile_fullPath); - if(!QFile::exists(video_mp4_fullpath))//检查是否成功生成mp4 - { - emit Send_TextBrowser_NewMessage(tr("Error occured when processing [")+SourceFile_fullPath+tr("]. Error: [Cannot convert video format to mp4.]")); - emit Send_Table_video_ChangeStatus_rowNumInt_statusQString(rowNum, "Failed"); - emit Send_progressbar_Add(); - return 0;//如果启用stop位,则直接return - } - //============== 读取自定义分辨率 ============ - bool CustRes_isEnabled = false; - int CustRes_height=0; - int CustRes_width=0; - if(CustRes_isContained(SourceFile_fullPath)) - { - CustRes_isEnabled=true; - QMap Res_map = CustRes_getResMap(SourceFile_fullPath);//res_map["fullpath"],["height"],["width"] - CustRes_height=Res_map["height"].toInt(); - CustRes_width=Res_map["width"].toInt(); - } - //================= - QString AudioPath = file_path+"/Audio_"+file_name+"_"+file_ext+"_W2xEX.wav";//音频 - QString SplitFramesFolderPath = file_path+"/"+file_name+"_"+file_ext+"_SplitFrames_W2xEX";//拆分后存储frame的文件夹 - QString ScaledFramesFolderPath = SplitFramesFolderPath+"/ScaledFrames_W2xEX";//存储放大后的帧 - //========================== - // 检测之前的视频配置文件 - //========================== - QString VideoConfiguration_fullPath = file_path+"/VideoConfiguration_"+file_name+"_"+file_ext+"_Waifu2xEX.ini"; - if(QFile::exists(VideoConfiguration_fullPath)) - { - QSettings *configIniRead = new QSettings(VideoConfiguration_fullPath, QSettings::IniFormat); - configIniRead->setIniCodec(QTextCodec::codecForName("UTF-8")); - //=================== 加载之前存储的视频信息 ========================= - int ScaleRatio_old = configIniRead->value("/VideoConfiguration/ScaleRatio").toInt(); - int DenoiseLevel_old = configIniRead->value("/VideoConfiguration/DenoiseLevel").toInt(); - bool CustRes_isEnabled_old = configIniRead->value("/VideoConfiguration/CustRes_isEnabled").toBool(); - int CustRes_height_old = configIniRead->value("/VideoConfiguration/CustRes_height").toInt(); - int CustRes_width_old = configIniRead->value("/VideoConfiguration/CustRes_width").toInt(); - QString EngineName_old = configIniRead->value("/VideoConfiguration/EngineName").toString(); - bool isProcessBySegment_old = configIniRead->value("/VideoConfiguration/isProcessBySegment").toBool(); - //=================== 比对信息 ================================ - if(EngineName_old=="waifu2x-converter") - { - if(CustRes_isEnabled_old==false&&CustRes_isEnabled==false) - { - if(ScaleRatio_old!=ScaleRatio||DenoiseLevel_old!=DenoiseLevel) - { - isVideoConfigChanged=true; - } - else - { - isVideoConfigChanged=false; - } - } - else - { - if(CustRes_isEnabled_old==true&&CustRes_isEnabled==true) - { - if(CustRes_height_old!=CustRes_height||CustRes_width_old!=CustRes_width) - { - isVideoConfigChanged=true; - } - else - { - isVideoConfigChanged=false; - } - } - else - { - isVideoConfigChanged=true; - } - } - if(isProcessBySegment_old==true) - { - isVideoConfigChanged=true; - } - } - else - { - isVideoConfigChanged=true; - } - } - else - { - emit Send_video_write_VideoConfiguration(VideoConfiguration_fullPath,ScaleRatio,DenoiseLevel,CustRes_isEnabled,CustRes_height,CustRes_width,"waifu2x-converter",false,"","",ui->groupBox_FrameInterpolation->isChecked(),0); - } - //======================= - // 检测缓存是否存在 - //======================= - if(QFile::exists(video_mp4_fullpath)&&file_isDirExist(SplitFramesFolderPath)&&file_isDirExist(ScaledFramesFolderPath)&&QFile::exists(VideoConfiguration_fullPath)) - { - if(!isVideoConfigChanged) - { - isCacheExists=true; - emit Send_TextBrowser_NewMessage(tr("The previous video cache file is detected and processing of the previous video cache will continue. If you want to restart processing of the current video:[")+SourceFile_fullPath+tr("], delete the cache manually.")); - } - else - { - isCacheExists=false; - //======== - QFile::remove(VideoConfiguration_fullPath); - file_DelDir(SplitFramesFolderPath); - QFile::remove(AudioPath); - DelVfiDir(video_mp4_fullpath); - emit Send_video_write_VideoConfiguration(VideoConfiguration_fullPath,ScaleRatio,DenoiseLevel,CustRes_isEnabled,CustRes_height,CustRes_width,"waifu2x-converter",false,"","",ui->groupBox_FrameInterpolation->isChecked(),0); - //======= - emit Send_TextBrowser_NewMessage(tr("The previous video cache file was detected, but because you changed the settings about the video resolution or denoise level, the previous cache will be deleted and processing of the video:[")+SourceFile_fullPath+tr("] will restart.")); - } - } - else - { - isCacheExists=false; - //======== - QFile::remove(VideoConfiguration_fullPath); - file_DelDir(SplitFramesFolderPath); - QFile::remove(AudioPath); - DelVfiDir(video_mp4_fullpath); - emit Send_video_write_VideoConfiguration(VideoConfiguration_fullPath,ScaleRatio,DenoiseLevel,CustRes_isEnabled,CustRes_height,CustRes_width,"waifu2x-converter",false,"","",ui->groupBox_FrameInterpolation->isChecked(),0); - //======== - } - if(!isCacheExists) - { - //============================== 拆分 ========================================== - if(file_isDirExist(SplitFramesFolderPath)) - { - file_DelDir(SplitFramesFolderPath); - file_mkDir(SplitFramesFolderPath); - } - else - { - file_mkDir(SplitFramesFolderPath); - } - QFile::remove(AudioPath); - video_video2images(video_mp4_fullpath,SplitFramesFolderPath,AudioPath); - if(waifu2x_STOP) - { - emit Send_Table_video_ChangeStatus_rowNumInt_statusQString(rowNum, "Interrupted"); - return 0;//如果启用stop位,则直接return - } - } - //============================== 扫描获取文件名 =============================== - QStringList Frame_fileName_list = file_getFileNames_in_Folder_nofilter(SplitFramesFolderPath); - if(!isCacheExists) - { - if(Frame_fileName_list.isEmpty())//检查是否成功拆分为帧 - { - emit Send_TextBrowser_NewMessage(tr("Error occured when processing [")+SourceFile_fullPath+tr("]. Error: [Unable to split video into pictures.]")); - emit Send_Table_video_ChangeStatus_rowNumInt_statusQString(rowNum, "Failed"); - emit Send_progressbar_Add(); - return 0;//如果启用stop位,则直接return - } - } - //============================== 放大 ======================================= - //===========建立存储放大后frame的文件夹=========== - if(!isCacheExists) - { - if(file_isDirExist(ScaledFramesFolderPath)) - { - file_DelDir(ScaledFramesFolderPath); - file_mkDir(ScaledFramesFolderPath); - } - else - { - file_mkDir(ScaledFramesFolderPath); - } - } - //==========开始放大========================== - emit Send_CurrentFileProgress_Start(file_name+"."+file_ext,(Frame_fileName_list.size()+file_getFileNames_in_Folder_nofilter(ScaledFramesFolderPath).size())); - FileProgressWatch_isEnabled=true; - QFuture FileProgressWatch_QFuture = QtConcurrent::run(this, &MainWindow::CurrentFileProgress_WatchFolderFileNum, ScaledFramesFolderPath);//启动waifu2x 主线程 - if(ui->checkBox_ShowInterPro->isChecked()==false) - { - FileProgressWatch_isEnabled=false; - FileProgressWatch_QFuture.cancel(); - emit Send_CurrentFileProgress_Stop(); - } - //=======获取显卡信息======== - int NumOfGPU = 1; - if(ui->checkBox_MultiGPU_Waifu2xConverter->isChecked()==true) - { - NumOfGPU=0; - for (int i=0; i GPUInfo_tmp = GPUIDs_List_MultiGPU_Waifu2xConverter.at(i); - if(GPUInfo_tmp["isEnabled"] == "true") - { - NumOfGPU++; - } - } - } - //============创建显卡文件夹=========== - QStringList GPU_SplitFramesFolderPath_List; - for(int i = 0; i < NumOfGPU; i++) - { - QString GPU_SplitFramesFolderPath = SplitFramesFolderPath+"/"+"GPU_"+QString::number(i); - if(file_isDirExist(GPU_SplitFramesFolderPath)==false) - { - file_DelDir(GPU_SplitFramesFolderPath); - file_mkDir(GPU_SplitFramesFolderPath); - } - else - { - file_mkDir(GPU_SplitFramesFolderPath); - } - GPU_SplitFramesFolderPath_List.append(GPU_SplitFramesFolderPath); - } - int TotalFramesNum = Frame_fileName_list.size(); - int FramesNumForEachGPU = TotalFramesNum/NumOfGPU; - if(FramesNumForEachGPU<1)FramesNumForEachGPU=1; - int start_num=0; - for(int x = 0; x < GPU_SplitFramesFolderPath_List.size(); x++) - { - if(x==GPU_SplitFramesFolderPath_List.size()-1)FramesNumForEachGPU=TotalFramesNum; - QStringList file_waitformove = Frame_fileName_list.mid(start_num,FramesNumForEachGPU); - for(int i = 0; i < file_waitformove.size(); i++) - { - QString FileName = file_waitformove.at(i); - QFile::rename(SplitFramesFolderPath+"/"+FileName,GPU_SplitFramesFolderPath_List.at(x)+"/"+FileName); - } - start_num+=FramesNumForEachGPU; - } - //========================= - bool Frame_failed = false;//放大失败标志 - QMap Sub_Thread_info; - Sub_Thread_info["ScaledFramesFolderPath"]=ScaledFramesFolderPath; - Sub_Thread_info["Denoise_cmd"] = " --noise-level " + QString::number(DenoiseLevel, 10); - if(CustRes_isEnabled == true) - { - Sub_Thread_info["ScaleRatio"] = QString("%1").arg(CustRes_CalNewScaleRatio(video_mp4_fullpath,CustRes_height,CustRes_width)); - } - else - { - Sub_Thread_info["ScaleRatio"] = QString("%1").arg(ScaleRatio); - } - //========================= - for(int i = 0; i < GPU_SplitFramesFolderPath_List.size(); i++) - { - Sub_Thread_info["SplitFramesFolderPath"]=GPU_SplitFramesFolderPath_List.at(i); - mutex_SubThreadNumRunning.lock(); - Sub_video_ThreadNumRunning++; - mutex_SubThreadNumRunning.unlock(); - QtConcurrent::run(this,&MainWindow::Waifu2x_Converter_Video_scale,Sub_Thread_info,&Sub_video_ThreadNumRunning,&Frame_failed); - while (Sub_video_ThreadNumRunning >= NumOfGPU) - { - Delay_msec_sleep(500); - } - if(waifu2x_STOP) - { - while (Sub_video_ThreadNumRunning > 0) - { - Delay_msec_sleep(500); - } - FileProgressWatch_isEnabled=false; - FileProgressWatch_QFuture.cancel(); - Restore_SplitFramesFolderPath(SplitFramesFolderPath,GPU_SplitFramesFolderPath_List); - emit Send_Table_video_ChangeStatus_rowNumInt_statusQString(rowNum, "Interrupted"); - return 0;//如果启用stop位,则直接return - } - if(Frame_failed) - { - FileProgressWatch_isEnabled=false; - FileProgressWatch_QFuture.cancel(); - Restore_SplitFramesFolderPath(SplitFramesFolderPath,GPU_SplitFramesFolderPath_List); - emit Send_TextBrowser_NewMessage(tr("Error occured when processing [")+SourceFile_fullPath+tr("]. Error: [Failed to scale frames.]")); - emit Send_Table_video_ChangeStatus_rowNumInt_statusQString(rowNum, "Failed"); - emit Send_progressbar_Add(); - return 0;//如果启用stop位,则直接return - } - } - while (Sub_video_ThreadNumRunning!=0) - { - Delay_msec_sleep(500); - } - FileProgressWatch_isEnabled=false; - FileProgressWatch_QFuture.cancel(); - emit Send_CurrentFileProgress_Stop(); - //================ 扫描放大后的帧文件数量,判断是否放大成功 ======================= - QStringList Frame_fileName_list_scaled = file_getFileNames_in_Folder_nofilter(ScaledFramesFolderPath); - if(Frame_fileName_list_scaled.size()checkBox_KeepVideoCache->isChecked()==false) - { - QFile::remove(VideoConfiguration_fullPath); - file_DelDir(SplitFramesFolderPath); - QFile::remove(AudioPath); - if(SourceFile_fullPath!=video_mp4_fullpath)QFile::remove(video_mp4_fullpath); - } - else - { - DelOriginal=false; - } - //============================= 删除原文件 & & 更新table status ============================ - if(DelOriginal) - { - if(ReplaceOriginalFile(SourceFile_fullPath,video_mp4_scaled_fullpath)==false) - { - if(QAction_checkBox_MoveToRecycleBin_checkBox_DelOriginal->isChecked()) - { - file_MoveToTrash(SourceFile_fullPath); - } - else - { - QFile::remove(SourceFile_fullPath); - } - } - emit Send_Table_video_ChangeStatus_rowNumInt_statusQString(rowNum, "Finished, original file deleted"); - } - else - { - emit Send_Table_video_ChangeStatus_rowNumInt_statusQString(rowNum, "Finished"); - } - //========== 移动到输出路径 ========= - if(ui->checkBox_OutPath_isEnabled->isChecked()) - { - MoveFileToOutputPath(video_mp4_scaled_fullpath,SourceFile_fullPath); - } - //============================ 更新进度条 ================================= - emit Send_progressbar_Add(); - //=========================== ============================== - return 0; -} - -/* -#### 分段处理 #### -调用Waifu2x-Converter处理视频 -读取设置,拆分,创建放大子线程,组装视频 -*/ -int MainWindow::Waifu2x_Converter_Video_BySegment(int rowNum) -{ - //============================= 读取设置 ================================ - int ScaleRatio = ui->doubleSpinBox_ScaleRatio_video->value(); - int DenoiseLevel = ui->spinBox_DenoiseLevel_video->value(); - bool DelOriginal = (ui->checkBox_DelOriginal->isChecked()||ui->checkBox_ReplaceOriginalFile->isChecked()); - bool isCacheExists = false; - bool isVideoConfigChanged = true; - int Sub_video_ThreadNumRunning = 0; - int SegmentDuration = ui->spinBox_SegmentDuration->value(); - //========================= 拆解map得到参数 ============================= - emit Send_Table_video_ChangeStatus_rowNumInt_statusQString(rowNum, "Processing"); - QString SourceFile_fullPath = Table_model_video->item(rowNum,2)->text(); - if(!QFile::exists(SourceFile_fullPath)) - { - emit Send_TextBrowser_NewMessage(tr("Error occured when processing [")+SourceFile_fullPath+tr("]. Error: [File does not exist.]")); - emit Send_Table_video_ChangeStatus_rowNumInt_statusQString(rowNum, "Failed"); - emit Send_progressbar_Add(); - return 0; - } - //========================== - QFileInfo fileinfo(SourceFile_fullPath); - QString file_name = file_getBaseName(SourceFile_fullPath); - QString file_ext = fileinfo.suffix(); - QString file_path = file_getFolderPath(fileinfo); - //=================================================================== - //生成mp4 - QString video_mp4_fullpath=video_To_CFRMp4(SourceFile_fullPath); - if(!QFile::exists(video_mp4_fullpath))//检查是否成功生成mp4 - { - emit Send_TextBrowser_NewMessage(tr("Error occured when processing [")+SourceFile_fullPath+tr("]. Error: [Cannot convert video format to mp4.]")); - emit Send_Table_video_ChangeStatus_rowNumInt_statusQString(rowNum, "Failed"); - emit Send_progressbar_Add(); - return 0;//如果启用stop位,则直接return - } - //============== 读取自定义分辨率 ============ - bool CustRes_isEnabled = false; - int CustRes_height=0; - int CustRes_width=0; - if(CustRes_isContained(SourceFile_fullPath)) - { - CustRes_isEnabled=true; - QMap Res_map = CustRes_getResMap(SourceFile_fullPath);//res_map["fullpath"],["height"],["width"] - CustRes_height=Res_map["height"].toInt(); - CustRes_width=Res_map["width"].toInt(); - } - //================= - QString AudioPath = file_path+"/Audio_"+file_name+"_"+file_ext+"_W2xEX.wav";//音频 - QString SplitFramesFolderPath = file_path+"/"+file_name+"_"+file_ext+"_SplitFrames_W2xEX";//拆分后存储frame的文件夹 - QString ScaledFramesFolderPath = SplitFramesFolderPath+"/ScaledFrames_W2xEX";//存储放大后的帧 - //=== - QString VideoClipsFolderPath = "";//存储视频片段的文件夹(完整路径) - QString DateStr = ""; - do - { - DateStr = video_getClipsFolderNo(); - VideoClipsFolderPath = file_path+"/"+DateStr+"_VideoClipsWaifu2xEX";//存储视频片段的文件夹(完整路径) - } - while(file_isDirExist(VideoClipsFolderPath)); - QString VideoClipsFolderName = DateStr+"_VideoClipsWaifu2xEX";//存储视频片段的文件夹(名称) - //========================== - // 检测之前的视频配置文件 - //========================== - QString VideoConfiguration_fullPath = file_path+"/VideoConfiguration_"+file_name+"_"+file_ext+"_Waifu2xEX.ini"; - if(QFile::exists(VideoConfiguration_fullPath)) - { - QSettings *configIniRead = new QSettings(VideoConfiguration_fullPath, QSettings::IniFormat); - configIniRead->setIniCodec(QTextCodec::codecForName("UTF-8")); - //=================== 加载之前存储的视频信息 ========================= - int ScaleRatio_old = configIniRead->value("/VideoConfiguration/ScaleRatio").toInt(); - int DenoiseLevel_old = configIniRead->value("/VideoConfiguration/DenoiseLevel").toInt(); - bool CustRes_isEnabled_old = configIniRead->value("/VideoConfiguration/CustRes_isEnabled").toBool(); - int CustRes_height_old = configIniRead->value("/VideoConfiguration/CustRes_height").toInt(); - int CustRes_width_old = configIniRead->value("/VideoConfiguration/CustRes_width").toInt(); - QString EngineName_old = configIniRead->value("/VideoConfiguration/EngineName").toString(); - bool isProcessBySegment_old = configIniRead->value("/VideoConfiguration/isProcessBySegment").toBool(); - bool isVideoFrameInterpolationEnabled_old = configIniRead->value("/VideoConfiguration/isVideoFrameInterpolationEnabled").toBool(); - int MultipleOfFPS_old = configIniRead->value("/VideoConfiguration/MultipleOfFPS").toInt(); - //=================== 比对信息 ================================ - if(EngineName_old=="waifu2x-converter") - { - if(CustRes_isEnabled_old==false&&CustRes_isEnabled==false) - { - if(ScaleRatio_old!=ScaleRatio||DenoiseLevel_old!=DenoiseLevel) - { - isVideoConfigChanged=true; - } - else - { - isVideoConfigChanged=false; - } - } - else - { - if(CustRes_isEnabled_old==true&&CustRes_isEnabled==true) - { - if(CustRes_height_old!=CustRes_height||CustRes_width_old!=CustRes_width) - { - isVideoConfigChanged=true; - } - else - { - isVideoConfigChanged=false; - } - } - else - { - isVideoConfigChanged=true; - } - } - if(isProcessBySegment_old == false) - { - isVideoConfigChanged=true; - } - if(isVideoFrameInterpolationEnabled_old != ui->groupBox_FrameInterpolation->isChecked()) - { - isVideoConfigChanged=true; - } - if(MultipleOfFPS_old != ui->spinBox_MultipleOfFPS_VFI->value() && ui->groupBox_FrameInterpolation->isChecked()) - { - isVideoConfigChanged=true; - } - } - else - { - isVideoConfigChanged=true; - } - //============ 修正文件夹名称 ============= - QString VideoClipsFolderPath_old = configIniRead->value("/VideoConfiguration/VideoClipsFolderPath").toString(); - QString VideoClipsFolderName_old = configIniRead->value("/VideoConfiguration/VideoClipsFolderName").toString(); - file_mkDir(VideoClipsFolderPath_old); - if(file_isDirExist(VideoClipsFolderPath_old)==true) - { - VideoClipsFolderPath = VideoClipsFolderPath_old; - VideoClipsFolderName = VideoClipsFolderName_old; - } - } - else - { - emit Send_video_write_VideoConfiguration(VideoConfiguration_fullPath,ScaleRatio,DenoiseLevel,CustRes_isEnabled,CustRes_height,CustRes_width,"waifu2x-converter",true,VideoClipsFolderPath,VideoClipsFolderName,ui->groupBox_FrameInterpolation->isChecked(),ui->spinBox_MultipleOfFPS_VFI->value()); - } - //======================= - // 检测缓存是否存在 - //======================= - if(file_isDirExist(SplitFramesFolderPath)) - { - if(!isVideoConfigChanged) - { - isCacheExists=true; - emit Send_TextBrowser_NewMessage(tr("The previous video cache file is detected and processing of the previous video cache will continue. If you want to restart processing of the current video:[")+SourceFile_fullPath+tr("], delete the cache manually.")); - } - else - { - isCacheExists=false; - //======== - QFile::remove(VideoConfiguration_fullPath); - file_DelDir(SplitFramesFolderPath); - file_DelDir(VideoClipsFolderPath); - QFile::remove(AudioPath); - DelVfiDir(video_mp4_fullpath); - emit Send_video_write_VideoConfiguration(VideoConfiguration_fullPath,ScaleRatio,DenoiseLevel,CustRes_isEnabled,CustRes_height,CustRes_width,"waifu2x-converter",true,VideoClipsFolderPath,VideoClipsFolderName,ui->groupBox_FrameInterpolation->isChecked(),ui->spinBox_MultipleOfFPS_VFI->value()); - //======= - emit Send_TextBrowser_NewMessage(tr("The previous video cache file was detected, but because you changed the settings about the video resolution or denoise level, the previous cache will be deleted and processing of the video:[")+SourceFile_fullPath+tr("] will restart.")); - } - } - else - { - isCacheExists=false; - //======== - QFile::remove(VideoConfiguration_fullPath); - file_DelDir(SplitFramesFolderPath); - file_DelDir(VideoClipsFolderPath); - QFile::remove(AudioPath); - DelVfiDir(video_mp4_fullpath); - emit Send_video_write_VideoConfiguration(VideoConfiguration_fullPath,ScaleRatio,DenoiseLevel,CustRes_isEnabled,CustRes_height,CustRes_width,"waifu2x-converter",true,VideoClipsFolderPath,VideoClipsFolderName,ui->groupBox_FrameInterpolation->isChecked(),ui->spinBox_MultipleOfFPS_VFI->value()); - //======== - } - /*==================================== - 提取音频 - ======================================*/ - if(!QFile::exists(AudioPath)) - { - video_get_audio(video_mp4_fullpath,AudioPath); - } - //================================== 开始分段处理视频 ================================================= - int StartTime = 0;//起始时间(秒) - int VideoDuration = video_get_duration(video_mp4_fullpath); - bool isSplitComplete = false; - bool isScaleComplete = false; - /* - ============================================ - 开始之前先读取进度 - ============================================ - */ - int OLD_SegmentDuration=-1; - bool read_OLD_SegmentDuration =false; - int LastVideoClipNo = -1; - if(QFile::exists(VideoConfiguration_fullPath)) - { - QSettings *configIniRead = new QSettings(VideoConfiguration_fullPath, QSettings::IniFormat); - configIniRead->setIniCodec(QTextCodec::codecForName("UTF-8")); - //=================== 加载进度 ========================= - StartTime = configIniRead->value("/Progress/StartTime").toInt(); - isSplitComplete = configIniRead->value("/Progress/isSplitComplete").toBool(); - isScaleComplete = configIniRead->value("/Progress/isScaleComplete").toBool(); - OLD_SegmentDuration = configIniRead->value("/Progress/OLDSegmentDuration").toInt(); - LastVideoClipNo = configIniRead->value("/Progress/LastVideoClipNo").toInt(); - } - if(OLD_SegmentDuration>0) - { - read_OLD_SegmentDuration = true; - } - /* - 加载进度条 - */ - int SegmentDuration_tmp_progressbar = 0; - if(read_OLD_SegmentDuration) - { - SegmentDuration_tmp_progressbar = OLD_SegmentDuration; - } - else - { - SegmentDuration_tmp_progressbar = SegmentDuration; - } - if(ui->checkBox_ShowInterPro->isChecked()&&VideoDuration>SegmentDuration_tmp_progressbar) - { - emit Send_CurrentFileProgress_Start(file_name+"."+file_ext,VideoDuration); - if(StartTime>0) - { - emit Send_CurrentFileProgress_progressbar_Add_SegmentDuration(StartTime); - } - } - /* - ============================================ - 正式开始处理 - ============================================ - */ - int SegmentDuration_tmp=0; - int TimeLeft_tmp=0; - while(VideoDuration>StartTime) - { - /*========================== - 计算视频片段时间 - ==========================*/ - TimeLeft_tmp = VideoDuration-StartTime; - if((TimeLeft_tmp)>=SegmentDuration) - { - SegmentDuration_tmp = SegmentDuration; - } - else - { - SegmentDuration_tmp = TimeLeft_tmp; - } - if(read_OLD_SegmentDuration) - { - SegmentDuration_tmp = OLD_SegmentDuration; - read_OLD_SegmentDuration=false; - } - /*========================== - 拆分视频片段 - ==========================*/ - if(isSplitComplete==false) - { - if(file_isDirExist(SplitFramesFolderPath)) - { - file_DelDir(SplitFramesFolderPath); - file_mkDir(SplitFramesFolderPath); - } - else - { - file_mkDir(SplitFramesFolderPath); - } - video_video2images_ProcessBySegment(video_mp4_fullpath,SplitFramesFolderPath,StartTime,SegmentDuration_tmp); - if(waifu2x_STOP) - { - emit Send_Table_video_ChangeStatus_rowNumInt_statusQString(rowNum, "Interrupted"); - return 0;//如果启用stop位,则直接return - } - } - /*========================== - 处理视频片段的帧 - ==========================*/ - if(isScaleComplete==false) - { - //============================== 扫描获取文件名 =============================== - QStringList Frame_fileName_list = file_getFileNames_in_Folder_nofilter(SplitFramesFolderPath); - if(isSplitComplete==false) - { - if(Frame_fileName_list.isEmpty())//检查是否成功拆分为帧 - { - emit Send_TextBrowser_NewMessage(tr("Error occured when processing [")+SourceFile_fullPath+tr("]. Error: [Unable to split video into pictures.]")); - emit Send_Table_video_ChangeStatus_rowNumInt_statusQString(rowNum, "Failed"); - emit Send_progressbar_Add(); - return 0;//如果启用stop位,则直接return - } - } - /* - 记录进度 - 帧拆分成功 - */ - emit Send_video_write_Progress_ProcessBySegment(VideoConfiguration_fullPath,StartTime,true,false,SegmentDuration_tmp,LastVideoClipNo); - //============================== 放大 ======================================= - //===========建立存储放大后frame的文件夹=========== - if(isSplitComplete==false) - { - if(file_isDirExist(ScaledFramesFolderPath)) - { - file_DelDir(ScaledFramesFolderPath); - file_mkDir(ScaledFramesFolderPath); - } - else - { - file_mkDir(ScaledFramesFolderPath); - } - } - //==========开始放大========================== - FileProgressWatch_isEnabled=true; - QFuture FileProgressWatch_QFuture = QtConcurrent::run(this, &MainWindow::CurrentFileProgress_WatchFolderFileNum_Textbrower, SourceFile_fullPath,ScaledFramesFolderPath,Frame_fileName_list.size()+file_getFileNames_in_Folder_nofilter(ScaledFramesFolderPath).size()); - if(ui->checkBox_ShowInterPro->isChecked()==false) - { - FileProgressWatch_isEnabled=false; - FileProgressWatch_QFuture.cancel(); - } - //=======获取显卡信息======== - int NumOfGPU = 1; - if(ui->checkBox_MultiGPU_Waifu2xConverter->isChecked()==true) - { - NumOfGPU=0; - for (int i=0; i GPUInfo_tmp = GPUIDs_List_MultiGPU_Waifu2xConverter.at(i); - if(GPUInfo_tmp["isEnabled"] == "true") - { - NumOfGPU++; - } - } - } - //============创建显卡文件夹=========== - QStringList GPU_SplitFramesFolderPath_List; - for(int i = 0; i < NumOfGPU; i++) - { - QString GPU_SplitFramesFolderPath = SplitFramesFolderPath+"/"+"GPU_"+QString::number(i); - if(file_isDirExist(GPU_SplitFramesFolderPath)==false) - { - file_DelDir(GPU_SplitFramesFolderPath); - file_mkDir(GPU_SplitFramesFolderPath); - } - else - { - file_mkDir(GPU_SplitFramesFolderPath); - } - GPU_SplitFramesFolderPath_List.append(GPU_SplitFramesFolderPath); - } - int TotalFramesNum = Frame_fileName_list.size(); - int FramesNumForEachGPU = TotalFramesNum/NumOfGPU; - if(FramesNumForEachGPU<1)FramesNumForEachGPU=1; - int start_num=0; - for(int x = 0; x < GPU_SplitFramesFolderPath_List.size(); x++) - { - if(x==GPU_SplitFramesFolderPath_List.size()-1)FramesNumForEachGPU=TotalFramesNum; - QStringList file_waitformove = Frame_fileName_list.mid(start_num,FramesNumForEachGPU); - for(int i = 0; i < file_waitformove.size(); i++) - { - QString FileName = file_waitformove.at(i); - QFile::rename(SplitFramesFolderPath+"/"+FileName,GPU_SplitFramesFolderPath_List.at(x)+"/"+FileName); - } - start_num+=FramesNumForEachGPU; - } - //========================= - bool Frame_failed = false;//放大失败标志 - QMap Sub_Thread_info; - Sub_Thread_info["ScaledFramesFolderPath"]=ScaledFramesFolderPath; - Sub_Thread_info["Denoise_cmd"] = " --noise-level " + QString::number(DenoiseLevel, 10); - if(CustRes_isEnabled == true) - { - Sub_Thread_info["ScaleRatio"] = QString("%1").arg(CustRes_CalNewScaleRatio(video_mp4_fullpath,CustRes_height,CustRes_width)); - } - else - { - Sub_Thread_info["ScaleRatio"] = QString("%1").arg(ScaleRatio); - } - //========================= - for(int i = 0; i < GPU_SplitFramesFolderPath_List.size(); i++) - { - Sub_Thread_info["SplitFramesFolderPath"]=GPU_SplitFramesFolderPath_List.at(i); - mutex_SubThreadNumRunning.lock(); - Sub_video_ThreadNumRunning++; - mutex_SubThreadNumRunning.unlock(); - QtConcurrent::run(this,&MainWindow::Waifu2x_Converter_Video_scale,Sub_Thread_info,&Sub_video_ThreadNumRunning,&Frame_failed); - while (Sub_video_ThreadNumRunning >= NumOfGPU) - { - Delay_msec_sleep(500); - } - if(waifu2x_STOP) - { - while (Sub_video_ThreadNumRunning > 0) - { - Delay_msec_sleep(500); - } - FileProgressWatch_isEnabled=false; - FileProgressWatch_QFuture.cancel(); - Restore_SplitFramesFolderPath(SplitFramesFolderPath,GPU_SplitFramesFolderPath_List); - emit Send_Table_video_ChangeStatus_rowNumInt_statusQString(rowNum, "Interrupted"); - return 0;//如果启用stop位,则直接return - } - if(Frame_failed) - { - FileProgressWatch_isEnabled=false; - FileProgressWatch_QFuture.cancel(); - Restore_SplitFramesFolderPath(SplitFramesFolderPath,GPU_SplitFramesFolderPath_List); - emit Send_TextBrowser_NewMessage(tr("Error occured when processing [")+SourceFile_fullPath+tr("]. Error: [Failed to scale frames.]")); - emit Send_Table_video_ChangeStatus_rowNumInt_statusQString(rowNum, "Failed"); - emit Send_progressbar_Add(); - return 0;//如果启用stop位,则直接return - } - } - while (Sub_video_ThreadNumRunning!=0) - { - Delay_msec_sleep(500); - } - FileProgressWatch_isEnabled=false; - FileProgressWatch_QFuture.cancel(); - //================ 扫描放大后的帧文件数量,判断是否放大成功 ======================= - QStringList Frame_fileName_list_scaled = file_getFileNames_in_Folder_nofilter(ScaledFramesFolderPath); - if(Frame_fileName_list_scaled.size()checkBox_ShowInterPro->isChecked()) - { - emit Send_CurrentFileProgress_progressbar_Add_SegmentDuration(SegmentDuration_tmp); - } - StartTime+=SegmentDuration_tmp; - isSplitComplete = false; - isScaleComplete = false; - LastVideoClipNo=VideoClipNo; - emit Send_video_write_Progress_ProcessBySegment(VideoConfiguration_fullPath,StartTime,false,false,-1,VideoClipNo); - } - emit Send_CurrentFileProgress_Stop(); - //====================================================== - // 组装(片段到成片) - //====================================================== - QString video_mp4_scaled_fullpath = ""; - if(CustRes_isEnabled) - { - video_mp4_scaled_fullpath = file_path+"/"+file_name+"_waifu2x_"+QString::number(CustRes_width,10)+"x"+QString::number(CustRes_height,10)+"_"+QString::number(DenoiseLevel,10)+"n"+"_"+file_ext+".mp4"; - } - else - { - video_mp4_scaled_fullpath = file_path+"/"+file_name+"_waifu2x_"+QString::number(ScaleRatio,10)+"x_"+QString::number(DenoiseLevel,10)+"n"+"_"+file_ext+".mp4"; - } - QFile::remove(video_mp4_scaled_fullpath); - video_AssembleVideoClips(VideoClipsFolderPath,VideoClipsFolderName,video_mp4_scaled_fullpath,AudioPath); - if(QFile::exists(video_mp4_scaled_fullpath)==false)//检查是否成功生成视频 - { - if(waifu2x_STOP) - { - emit Send_Table_video_ChangeStatus_rowNumInt_statusQString(rowNum, "Interrupted"); - return 0;//如果启用stop位,则直接return - } - emit Send_TextBrowser_NewMessage(tr("Error occured when processing [")+SourceFile_fullPath+tr("]. Error: [Unable to assemble video clips.]")); - emit Send_Table_video_ChangeStatus_rowNumInt_statusQString(rowNum, "Failed"); - emit Send_progressbar_Add(); - return 0;//如果启用stop位,则直接return - } - //============================== 删除缓存文件 ==================================================== - if(ui->checkBox_KeepVideoCache->isChecked()==false) - { - QFile::remove(VideoConfiguration_fullPath); - file_DelDir(SplitFramesFolderPath); - file_DelDir(VideoClipsFolderPath); - QFile::remove(AudioPath); - if(SourceFile_fullPath!=video_mp4_fullpath)QFile::remove(video_mp4_fullpath); - } - else - { - DelOriginal=false; - } - //============================= 删除原文件 & & 更新table status ============================ - if(DelOriginal) - { - if(ReplaceOriginalFile(SourceFile_fullPath,video_mp4_scaled_fullpath)==false) - { - if(QAction_checkBox_MoveToRecycleBin_checkBox_DelOriginal->isChecked()) - { - file_MoveToTrash(SourceFile_fullPath); - } - else - { - QFile::remove(SourceFile_fullPath); - } - } - emit Send_Table_video_ChangeStatus_rowNumInt_statusQString(rowNum, "Finished, original file deleted"); - } - else - { - emit Send_Table_video_ChangeStatus_rowNumInt_statusQString(rowNum, "Finished"); - } - //========== 移动到输出路径 ========= - if(ui->checkBox_OutPath_isEnabled->isChecked()) - { - MoveFileToOutputPath(video_mp4_scaled_fullpath,SourceFile_fullPath); - } - //============================ 更新进度条 ================================= - emit Send_progressbar_Add(); - //=========================== ============================== - return 0; -} - - -int MainWindow::Waifu2x_Converter_Video_scale(QMap Sub_Thread_info,int *Sub_video_ThreadNumRunning,bool *Frame_failed) -{ - bool AllFinished; - QString SplitFramesFolderPath = Sub_Thread_info["SplitFramesFolderPath"]; - QString ScaledFramesFolderPath = Sub_Thread_info["ScaledFramesFolderPath"]; - //=========== - QString Denoise_cmd = Sub_Thread_info["Denoise_cmd"]; - //======================================================================== - QStringList InputFilesNameList = file_getFileNames_in_Folder_nofilter(SplitFramesFolderPath); - QStringList OutPutFilesFullPathList; - for(int i=0; ispinBox_retry->value()+ForceRetryCount); retry++) - { - Waifu2x->start(cmd); - while(!Waifu2x->waitForStarted(100)&&!QProcess_stop) {} - while(!Waifu2x->waitForFinished(500)&&!QProcess_stop) - { - if(waifu2x_STOP) - { - QStringList FinfishedFileList = WaitForEngineIO(OutPutFilesFullPathList); - Waifu2x->close(); - //============ - QString file_fullpath_tmp; - for(int i=0; ispinBox_retry->value()+(ForceRetryCount-1))break; - Delay_sec_sleep(5); - emit Send_TextBrowser_NewMessage(tr("Automatic retry, please wait.")); - AllFinished=false; - break; - } - } - if(AllFinished)break; - } - //========= - AllFinished = true; - for(int i=0; ipushButton_DumpProcessorList_converter->setText(tr("Loading, please wait...")); - //===== - pushButton_Start_setEnabled_self(0); - ui->pushButton_DetectGPU->setEnabled(0); - ui->pushButton_DetectGPUID_srmd->setEnabled(0); - ui->pushButton_DumpProcessorList_converter->setEnabled(0); - ui->pushButton_ListGPUs_Anime4k->setEnabled(0); - ui->pushButton_compatibilityTest->setEnabled(0); - ui->pushButton_DetectGPU_RealsrNCNNVulkan->setEnabled(0); - QtConcurrent::run(this, &MainWindow::Waifu2x_DumpProcessorList_converter); -} - -int MainWindow::Waifu2x_DumpProcessorList_converter() -{ - //============================ - // 调用converter输出列表 - //============================ - Core_num = 0; - emit Send_TextBrowser_NewMessage(tr("Detecting available Processor, please wait.")); - QString Waifu2x_folder_path = Current_Path + "/waifu2x-converter"; - QString program = Waifu2x_folder_path + "/waifu2x-converter-cpp_waifu2xEX.exe"; - QProcess *Waifu2x = new QProcess(); - QString cmd = "\"" + program + "\"" + " -l "; - Waifu2x->start(cmd); - while(!Waifu2x->waitForStarted(100)&&!QProcess_stop) {} - while(!Waifu2x->waitForFinished(100)&&!QProcess_stop) {} - QString waifu2x_stdOut = Waifu2x->readAllStandardOutput(); - Core_num = waifu2x_stdOut.count("num_core"); - emit Send_TextBrowser_NewMessage(tr("\nWaifu2x-converter processor list:\n")+waifu2x_stdOut.trimmed()); - //==================================================================== - // 获取到列表后, 对列表内处理器执行测试确认是否真的可用 - //==================================================================== - emit Send_TextBrowser_NewMessage(tr("Please wait while testing the processor.")); - //======== - Available_ProcessorList_converter.clear(); - //======== - QString InputPath = Current_Path + "/Compatibility_Test/Compatibility_Test.jpg"; - QString OutputPath = Current_Path + "/Compatibility_Test/res.png"; - QFile::remove(OutputPath); - //============== - QString model_path= Waifu2x_folder_path + "/models_rgb"; - //========= - int Processor_ID=0; - //========= - for(int i = 0; istart(cmd); - while(!Waifu2x->waitForStarted(100)&&!QProcess_stop) {} - while(!Waifu2x->waitForFinished(100)&&!QProcess_stop) {} - if(QFile::exists(OutputPath)) - { - Available_ProcessorList_converter.append(QString::number(Processor_ID,10)); - Processor_ID++; - QFile::remove(OutputPath); - } - } - QFile::remove(OutputPath); - //==================== - emit Send_TextBrowser_NewMessage(tr("Detection is complete!")); - emit Send_Waifu2x_DumpProcessorList_converter_finished(); - return 0; -} -int MainWindow::Waifu2x_DumpProcessorList_converter_finished() -{ - pushButton_Start_setEnabled_self(1); - ui->pushButton_DetectGPU->setEnabled(1); - ui->pushButton_compatibilityTest->setEnabled(1); - ui->pushButton_DetectGPUID_srmd->setEnabled(1); - ui->pushButton_DumpProcessorList_converter->setEnabled(1); - on_checkBox_SpecifyGPU_Anime4k_stateChanged(1); - ui->pushButton_DetectGPU_RealsrNCNNVulkan->setEnabled(1); - //=========================== - GPUIDs_List_MultiGPU_Waifu2xConverter.clear(); - ui->comboBox_GPUIDs_MultiGPU_Waifu2xConverter->clear(); - //=== - ui->comboBox_TargetProcessor_converter->clear(); - ui->comboBox_TargetProcessor_converter->addItem("auto"); - if(!Available_ProcessorList_converter.isEmpty()) - { - for(int i=0; icomboBox_TargetProcessor_converter->addItem(Available_ProcessorList_converter.at(i)); - AddGPU_MultiGPU_Waifu2xConverter(Available_ProcessorList_converter.at(i)); - } - } - //===== - ui->pushButton_DumpProcessorList_converter->setText(tr("Dump processor list")); - //===== - return 0; -} - -void MainWindow::on_comboBox_TargetProcessor_converter_currentIndexChanged(int index) -{ - if(ui->comboBox_TargetProcessor_converter->currentText()!="auto") - { - Processor_converter_STR = " -p "+ui->comboBox_TargetProcessor_converter->currentText()+" "; - } - else - { - Processor_converter_STR=""; - } -} -/* -预读取引擎设定 -*/ -QString MainWindow::Waifu2xConverter_PreLoad_Settings() -{ - QString Waifu2xConverter_Settings_str = " "; - //===== - if(ui->checkBox_MultiGPU_Waifu2xConverter->isChecked()==false) - { - //==========单显卡========== - //Processor ID - if(ui->comboBox_TargetProcessor_converter->currentText()!="auto") - { - Waifu2xConverter_Settings_str.append("-p "+ui->comboBox_TargetProcessor_converter->currentText()+" "); - } - //block-size - Waifu2xConverter_Settings_str.append("--block-size "+QString::number(ui->spinBox_BlockSize_converter->value(), 10)+" "); - } - //model_path - QString model_path = Current_Path + "/waifu2x-converter/models_rgb"; - Waifu2xConverter_Settings_str.append("--model-dir \""+model_path+"\" "); - //Disable GPU - if(ui->checkBox_DisableGPU_converter->isChecked())Waifu2xConverter_Settings_str.append("--disable-gpu "); - //Force OpenCL - if(ui->checkBox_ForceOpenCL_converter->isChecked())Waifu2xConverter_Settings_str.append("--force-OpenCL "); - //TTA - if(ui->checkBox_TTA_converter->isChecked()) - { - Waifu2xConverter_Settings_str.append("-t 1 "); - } - else - { - Waifu2xConverter_Settings_str.append("-t 0 "); - } - //======================================= - return Waifu2xConverter_Settings_str; -} - -/* -Waifu2x-Converter -读取设定 -*/ -QString MainWindow::Waifu2xConverter_ReadSettings() -{ - QString Waifu2xConverter_Settings_str = ""; - //===== - Waifu2xConverter_Settings_str.append(Waifu2xConverter_PreLoad_Settings_Str); - if(ui->checkBox_MultiGPU_Waifu2xConverter->isChecked()) - { - //==========多显卡========== - QMap GPUInfo = Waifu2xConverter_MultiGPU(); - //GPU ID - Waifu2xConverter_Settings_str.append("-p "+GPUInfo["ID"]+" "); - //Tile Size - Waifu2xConverter_Settings_str.append("--block-size "+GPUInfo["TileSize"]+" "); - } - //======================================= - return Waifu2xConverter_Settings_str; -} - -QMap MainWindow::Waifu2xConverter_MultiGPU() -{ - MultiGPU_QMutex_Waifu2xConverter.lock(); - //==== - int MAX_GPU_ID_Waifu2xConverter = GPUIDs_List_MultiGPU_Waifu2xConverter.size()-1; - if(GPU_ID_Waifu2xConverter_MultiGPU>MAX_GPU_ID_Waifu2xConverter) - { - GPU_ID_Waifu2xConverter_MultiGPU=0; - } - //====== - QMap GPUInfo; - do - { - GPUInfo = GPUIDs_List_MultiGPU_Waifu2xConverter.at(GPU_ID_Waifu2xConverter_MultiGPU); - if(GPUInfo["isEnabled"] != "true") - { - GPU_ID_Waifu2xConverter_MultiGPU++; - if(GPU_ID_Waifu2xConverter_MultiGPU>MAX_GPU_ID_Waifu2xConverter) - { - GPU_ID_Waifu2xConverter_MultiGPU=0; - } - } - else - { - break; - } - } - while(true); - //====== - GPU_ID_Waifu2xConverter_MultiGPU++; - if(GPU_ID_Waifu2xConverter_MultiGPU>MAX_GPU_ID_Waifu2xConverter) - { - GPU_ID_Waifu2xConverter_MultiGPU=0; - } - //====== - MultiGPU_QMutex_Waifu2xConverter.unlock(); - return GPUInfo; -} - -void MainWindow::AddGPU_MultiGPU_Waifu2xConverter(QString GPUID) -{ - QMap GPUInfo; - GPUInfo["ID"] = GPUID; - GPUInfo["isEnabled"] = "true"; - GPUInfo["TileSize"] = "300"; - GPUIDs_List_MultiGPU_Waifu2xConverter.append(GPUInfo); - ui->comboBox_GPUIDs_MultiGPU_Waifu2xConverter->addItem(GPUID); - ui->comboBox_GPUIDs_MultiGPU_Waifu2xConverter->setCurrentIndex(0); -} - -void MainWindow::on_checkBox_MultiGPU_Waifu2xConverter_stateChanged(int arg1) -{ - if(ui->checkBox_MultiGPU_Waifu2xConverter->isChecked()) - { - ui->comboBox_TargetProcessor_converter->setEnabled(0); - ui->frame_BlockSize_W2xConverter->setEnabled(0); - ui->groupBox_GPUSettings_MultiGPU_Waifu2xConverter->setEnabled(1); - } - else - { - ui->comboBox_TargetProcessor_converter->setEnabled(1); - ui->frame_BlockSize_W2xConverter->setEnabled(1); - ui->groupBox_GPUSettings_MultiGPU_Waifu2xConverter->setEnabled(0); - } -} - -void MainWindow::on_checkBox_MultiGPU_Waifu2xConverter_clicked() -{ - if(ui->checkBox_MultiGPU_Waifu2xConverter->isChecked()) - { - if(GPUIDs_List_MultiGPU_Waifu2xConverter.size()==0) - { - QMessageBox *MSG = new QMessageBox(); - MSG->setWindowTitle(tr("Notification")); - MSG->setText(tr("Please dump processor list before enable Multi-Processor.")); - MSG->setIcon(QMessageBox::Information); - MSG->setModal(true); - MSG->show(); - ui->checkBox_MultiGPU_Waifu2xConverter->setChecked(0); - return; - } - if(GPUIDs_List_MultiGPU_Waifu2xConverter.size()<2) - { - QMessageBox *MSG = new QMessageBox(); - MSG->setWindowTitle(tr("Error")); - MSG->setText(tr("Insufficient number of available Processors.")); - MSG->setIcon(QMessageBox::Warning); - MSG->setModal(true); - MSG->show(); - ui->checkBox_MultiGPU_Waifu2xConverter->setChecked(0); - return; - } - } -} - -void MainWindow::on_comboBox_GPUIDs_MultiGPU_Waifu2xConverter_currentIndexChanged(int index) -{ - if(ui->comboBox_GPUIDs_MultiGPU_Waifu2xConverter->count()==0) - { - return; - } - QMap GPUInfo=GPUIDs_List_MultiGPU_Waifu2xConverter.at(ui->comboBox_GPUIDs_MultiGPU_Waifu2xConverter->currentIndex()); - ui->checkBox_isEnable_CurrentGPU_MultiGPU_Waifu2xConverter->setChecked(GPUInfo["isEnabled"] == "true"); - ui->spinBox_TileSize_CurrentGPU_MultiGPU_Waifu2xConverter->setValue(GPUInfo["TileSize"].toInt()); -} - -void MainWindow::on_checkBox_isEnable_CurrentGPU_MultiGPU_Waifu2xConverter_clicked() -{ - QMap GPUInfo=GPUIDs_List_MultiGPU_Waifu2xConverter.at(ui->comboBox_GPUIDs_MultiGPU_Waifu2xConverter->currentIndex()); - if(ui->checkBox_isEnable_CurrentGPU_MultiGPU_Waifu2xConverter->isChecked()) - { - GPUInfo["isEnabled"] = "true"; - } - else - { - GPUInfo["isEnabled"] = "false"; - } - GPUIDs_List_MultiGPU_Waifu2xConverter.replace(ui->comboBox_GPUIDs_MultiGPU_Waifu2xConverter->currentIndex(),GPUInfo); - int enabledGPUs = 0; - for (int i=0; i GPUInfo_tmp = GPUIDs_List_MultiGPU_Waifu2xConverter.at(i); - if(GPUInfo_tmp["isEnabled"] == "true") - { - enabledGPUs++; - } - } - if(enabledGPUs<2) - { - QMap GPUInfo=GPUIDs_List_MultiGPU_Waifu2xConverter.at(ui->comboBox_GPUIDs_MultiGPU_Waifu2xConverter->currentIndex()); - GPUInfo["isEnabled"] = "true"; - GPUIDs_List_MultiGPU_Waifu2xConverter.replace(ui->comboBox_GPUIDs_MultiGPU_Waifu2xConverter->currentIndex(),GPUInfo); - ui->checkBox_isEnable_CurrentGPU_MultiGPU_Waifu2xConverter->setChecked(1); - QMessageBox *MSG = new QMessageBox(); - MSG->setWindowTitle(tr("Warning")); - MSG->setText(tr("At least 2 Processors need to be enabled !!")); - MSG->setIcon(QMessageBox::Warning); - MSG->setModal(true); - MSG->show(); - } -} - -void MainWindow::on_spinBox_TileSize_CurrentGPU_MultiGPU_Waifu2xConverter_valueChanged(int arg1) -{ - QMap GPUInfo=GPUIDs_List_MultiGPU_Waifu2xConverter.at(ui->comboBox_GPUIDs_MultiGPU_Waifu2xConverter->currentIndex()); - GPUInfo["TileSize"] = QString::number(ui->spinBox_TileSize_CurrentGPU_MultiGPU_Waifu2xConverter->value(),10); - GPUIDs_List_MultiGPU_Waifu2xConverter.replace(ui->comboBox_GPUIDs_MultiGPU_Waifu2xConverter->currentIndex(),GPUInfo); -} - -void MainWindow::on_pushButton_ShowMultiGPUSettings_Waifu2xConverter_clicked() -{ - int Max_GPU_ID = GPUIDs_List_MultiGPU_Waifu2xConverter.size(); - GPUIDs_List_MultiGPU_Waifu2xConverter.size(); - QString MultiGPUSettings_str=""; - for(int GPU_ID=0; GPU_ID GPUInfo = GPUIDs_List_MultiGPU_Waifu2xConverter.at(GPU_ID); - if(GPUInfo["isEnabled"] != "true") - { - continue; - } - else - { - MultiGPUSettings_str.append(tr("Processor ID:")+"["+GPUInfo["ID"]+"] | "+tr("Block size:")+"["+GPUInfo["TileSize"]+"]\n\n"); - } - } - //========= - QMessageBox *MSG = new QMessageBox(); - MSG->setWindowTitle(tr("Current Multi-GPU settings")); - MSG->setText(MultiGPUSettings_str); - MSG->setIcon(QMessageBox::Information); - MSG->setModal(true); - MSG->show(); -} -/* -W2xConverter 块大小调整按钮 -*/ -void MainWindow::on_pushButton_BlockSize_Add_W2xConverter_clicked() -{ - ui->spinBox_BlockSize_converter->setValue(AddTileSize_NCNNVulkan_Converter(ui->spinBox_BlockSize_converter->value())); -} - -void MainWindow::on_pushButton_BlockSize_Minus_W2xConverter_clicked() -{ - ui->spinBox_BlockSize_converter->setValue(MinusTileSize_NCNNVulkan_Converter(ui->spinBox_BlockSize_converter->value())); -} -/* -放大APNG - -Waifu2x-Converter -*/ -bool MainWindow::APNG_Waifu2xConverter(QString splitFramesFolder,QString scaledFramesFolder,QString sourceFileFullPath,QStringList framesFileName_qStrList,QString resultFileFullPath) -{ - //生成文件夹 - file_DelDir(scaledFramesFolder); - file_mkDir(scaledFramesFolder); - //============================================================ - //开始放大 - emit Send_CurrentFileProgress_Start(file_getBaseName(sourceFileFullPath)+"."+sourceFileFullPath.split(".").last(),framesFileName_qStrList.size()); - FileProgressWatch_isEnabled=true; - QFuture FileProgressWatch_QFuture = QtConcurrent::run(this, &MainWindow::CurrentFileProgress_WatchFolderFileNum, scaledFramesFolder);//启动waifu2x 主线程 - if(ui->checkBox_ShowInterPro->isChecked()==false) - { - FileProgressWatch_isEnabled=false; - FileProgressWatch_QFuture.cancel(); - emit Send_CurrentFileProgress_Stop(); - } - //=======获取显卡信息======== - int NumOfGPU = 1; - if(ui->checkBox_MultiGPU_Waifu2xConverter->isChecked()==true) - { - NumOfGPU=0; - for (int i=0; i GPUInfo_tmp = GPUIDs_List_MultiGPU_Waifu2xConverter.at(i); - if(GPUInfo_tmp["isEnabled"] == "true") - { - NumOfGPU++; - } - } - } - //============创建显卡文件夹=========== - QStringList GPU_splitFramesFolder_List; - for(int i = 0; i < NumOfGPU; i++) - { - QString GPU_splitFramesFolder = splitFramesFolder+"/"+"GPU_"+QString::number(i); - if(file_isDirExist(GPU_splitFramesFolder)) - { - file_DelDir(GPU_splitFramesFolder); - file_mkDir(GPU_splitFramesFolder); - } - else - { - file_mkDir(GPU_splitFramesFolder); - } - GPU_splitFramesFolder_List.append(GPU_splitFramesFolder); - } - int TotalFramesNum = framesFileName_qStrList.size(); - int FramesNumForEachGPU = TotalFramesNum/NumOfGPU; - if(FramesNumForEachGPU<1)FramesNumForEachGPU=1; - int start_num=0; - for(int x = 0; x < GPU_splitFramesFolder_List.size(); x++) - { - if(x==GPU_splitFramesFolder_List.size()-1)FramesNumForEachGPU=TotalFramesNum; - QStringList file_waitformove = framesFileName_qStrList.mid(start_num,FramesNumForEachGPU); - for(int i = 0; i < file_waitformove.size(); i++) - { - QString FileName = file_waitformove.at(i); - QFile::rename(splitFramesFolder+"/"+FileName,GPU_splitFramesFolder_List.at(x)+"/"+FileName); - } - start_num+=FramesNumForEachGPU; - } - //========================= - bool Frame_failed = false;//放大失败标志 - //==== - QMap Sub_Thread_info; - Sub_Thread_info["scaledFramesFolder"]= scaledFramesFolder; - Sub_Thread_info["Denoise_cmd"] = " --noise-level " + QString::number(ui->spinBox_DenoiseLevel_gif->value(), 10); - if(CustRes_isContained(sourceFileFullPath)) - { - QMap Res_map = CustRes_getResMap(sourceFileFullPath);//res_map["fullpath"],["height"],["width"] - Sub_Thread_info["ScaleRatio"] = QString("%1").arg(CustRes_CalNewScaleRatio(sourceFileFullPath,Res_map["height"].toInt(),Res_map["width"].toInt())); - } - else - { - Sub_Thread_info["ScaleRatio"] = QString("%1").arg(qRound(ui->doubleSpinBox_ScaleRatio_gif->value())); - } - //========================= - int Sub_gif_ThreadNumRunning = 0; - for(int i = 0; i < GPU_splitFramesFolder_List.size(); i++) - { - Sub_Thread_info["splitFramesFolder"]=GPU_splitFramesFolder_List.at(i); - mutex_SubThreadNumRunning.lock(); - Sub_gif_ThreadNumRunning++; - mutex_SubThreadNumRunning.unlock(); - QtConcurrent::run(this,&MainWindow::Waifu2x_Converter_APNG_scale,Sub_Thread_info,&Sub_gif_ThreadNumRunning,&Frame_failed); - while (Sub_gif_ThreadNumRunning >= NumOfGPU) - { - Delay_msec_sleep(500); - } - if(waifu2x_STOP) - { - while (Sub_gif_ThreadNumRunning > 0) - { - Delay_msec_sleep(500); - } - FileProgressWatch_isEnabled=false; - FileProgressWatch_QFuture.cancel(); - return false; - } - if(Frame_failed) - { - FileProgressWatch_isEnabled=false; - FileProgressWatch_QFuture.cancel(); - emit Send_TextBrowser_NewMessage(tr("Error occured when processing [")+sourceFileFullPath+tr("]. Error: [Failed to scale frames.]")); - return false; - } - } - while (Sub_gif_ThreadNumRunning!=0) - { - Delay_msec_sleep(500); - } - FileProgressWatch_isEnabled=false; - FileProgressWatch_QFuture.cancel(); - emit Send_CurrentFileProgress_Stop(); - //======================= 检查是否成功放大所有帧 =========================== - if(framesFileName_qStrList.size() != file_getFileNames_in_Folder_nofilter(scaledFramesFolder).size()) - { - emit Send_TextBrowser_NewMessage(tr("Error occured when processing [")+sourceFileFullPath+tr("]. Error: [Failed to scale frames.]")); - return false; - } - //============================================================ - //组装apng - APNG_Frames2APNG(sourceFileFullPath, scaledFramesFolder, resultFileFullPath, false); - return true; -} -int MainWindow::Waifu2x_Converter_APNG_scale(QMap Sub_Thread_info,int *Sub_gif_ThreadNumRunning,bool *Frame_failed) -{ - bool AllFinished; - QString splitFramesFolder = Sub_Thread_info["splitFramesFolder"]; - QString scaledFramesFolder = Sub_Thread_info["scaledFramesFolder"]; - //=========== - QString Denoise_cmd = Sub_Thread_info["Denoise_cmd"]; - //======================================================================== - QStringList InputFilesNameList = file_getFileNames_in_Folder_nofilter(splitFramesFolder); - QStringList OutPutFilesFullPathList; - for(int i=0; ispinBox_retry->value()+ForceRetryCount); retry++) - { - Waifu2x->start(cmd); - while(!Waifu2x->waitForStarted(100)&&!QProcess_stop) {} - while(!Waifu2x->waitForFinished(500)&&!QProcess_stop) - { - if(waifu2x_STOP) - { - Waifu2x->close(); - mutex_SubThreadNumRunning.lock(); - *Sub_gif_ThreadNumRunning=*Sub_gif_ThreadNumRunning-1; - mutex_SubThreadNumRunning.unlock(); - return 0; - } - } - AllFinished = true; - for(int i=0; ispinBox_retry->value()+(ForceRetryCount-1))break; - Delay_sec_sleep(5); - emit Send_TextBrowser_NewMessage(tr("Automatic retry, please wait.")); - AllFinished=false; - break; - } - } - if(AllFinished)break; - } - //========= - AllFinished = true; - for(int i=0; i. + + My Github homepage: https://github.com/AaronFeng753 +*/ + +#include "mainwindow.h" +#include "ui_mainwindow.h" + +int MainWindow::Waifu2x_Converter_Image(int rowNum,bool ReProcess_MissingAlphaChannel) +{ + //============================= 读取设置 ================================ + int DenoiseLevel = ui->spinBox_DenoiseLevel_image->value(); + bool DelOriginal = (ui->checkBox_DelOriginal->isChecked()||ui->checkBox_ReplaceOriginalFile->isChecked()); + QString OutPutPath_Final =""; + //========================= 拆解map得到参数 ============================= + emit Send_Table_image_ChangeStatus_rowNumInt_statusQString(rowNum, "Processing"); + QString SourceFile_fullPath = Table_model_image->item(rowNum,2)->text(); + if(!QFile::exists(SourceFile_fullPath)) + { + emit Send_TextBrowser_NewMessage(tr("Error occured when processing [")+SourceFile_fullPath+tr("]. Error: [File does not exist.]")); + emit Send_Table_image_ChangeStatus_rowNumInt_statusQString(rowNum, "Failed"); + emit Send_progressbar_Add(); + mutex_ThreadNumRunning.lock(); + ThreadNumRunning--; + mutex_ThreadNumRunning.unlock();//线程数量统计-1 + return 0; + } + //========= 转换到 PNG ========= + QString SourceFile_fullPath_Original = SourceFile_fullPath; + SourceFile_fullPath = Imgae_PreProcess(SourceFile_fullPath_Original,ReProcess_MissingAlphaChannel); + //======================================================= + int ScaleRatio = 2; + bool CustRes_isEnabled = false; + int CustRes_height=0; + int CustRes_width=0; + if(CustRes_isContained(SourceFile_fullPath_Original)) + { + CustRes_isEnabled=true; + QMap Res_map = CustRes_getResMap(SourceFile_fullPath_Original);//res_map["fullpath"],["height"],["width"] + ScaleRatio = CustRes_CalNewScaleRatio(SourceFile_fullPath,Res_map["height"].toInt(),Res_map["width"].toInt()); + if(ScaleRatio==0) + { + emit Send_TextBrowser_NewMessage(tr("Error occured when processing [")+SourceFile_fullPath_Original+tr("]. Error: [The resolution of the source file cannot be read, so the image cannot be scaled to a custom resolution.]")); + emit Send_Table_image_ChangeStatus_rowNumInt_statusQString(rowNum, "Failed"); + emit Send_progressbar_Add(); + mutex_ThreadNumRunning.lock(); + ThreadNumRunning--; + mutex_ThreadNumRunning.unlock();//线程数量统计-1 + return 0; + } + CustRes_height=Res_map["height"].toInt(); + CustRes_width=Res_map["width"].toInt(); + } + else + { + double ScaleRatio_double_tmp = ui->doubleSpinBox_ScaleRatio_image->value(); + if(ScaleRatio_double_tmp == (int)ScaleRatio_double_tmp) + { + ScaleRatio = qRound(ScaleRatio_double_tmp); + } + else + { + CustRes_isEnabled=true; + QMap Res_map = DoubleScaleRatio_Cal_NewScaleRatio_NewHW(SourceFile_fullPath,ScaleRatio_double_tmp); + //==== + if(Res_map.isEmpty()) + { + emit Send_TextBrowser_NewMessage(tr("Error occured when processing [")+SourceFile_fullPath+tr("]. Error: [Unable to read the resolution of the source file.]")); + emit Send_Table_image_ChangeStatus_rowNumInt_statusQString(rowNum, "Failed"); + emit Send_progressbar_Add(); + mutex_ThreadNumRunning.lock(); + ThreadNumRunning--; + mutex_ThreadNumRunning.unlock();//线程数量统计-1 + return 0; + } + //==== + ScaleRatio = Res_map["ScaleRatio"].toInt(); + CustRes_height = Res_map["Height_new"].toInt(); + CustRes_width = Res_map["width_new"].toInt(); + } + } + //======================================================= + QFileInfo fileinfo(SourceFile_fullPath); + QString file_name = file_getBaseName(SourceFile_fullPath); + QString file_ext = fileinfo.suffix(); + QString file_path = file_getFolderPath(fileinfo); + QString OutPut_Path = file_path + "/" + file_name + "_waifu2x_"+QString::number(ScaleRatio, 10)+"x_"+QString::number(DenoiseLevel, 10)+"n_"+file_ext+".png"; + //============================== 放大 ======================================= + QString Denoise_cmd = " --noise-level " + QString::number(DenoiseLevel, 10); + //==== + QString cmd = "\"" + Current_Path + "/waifu2x-converter/waifu2x-converter-cpp_waifu2xEX.exe" + "\"" + " -i " + "\"" + SourceFile_fullPath + "\"" + " -o " + "\"" + OutPut_Path + "\"" + " --scale-ratio " + QString::number(ScaleRatio, 10) + Denoise_cmd + Waifu2xConverter_ReadSettings(); + //======== + for(int retry=0; retry<(ui->spinBox_retry->value()+ForceRetryCount); retry++) + { + QProcess *Waifu2x = new QProcess(); + Waifu2x->start(cmd); + while(!Waifu2x->waitForStarted(100)&&!QProcess_stop) {} + while(!Waifu2x->waitForFinished(500)&&!QProcess_stop) + { + if(waifu2x_STOP) + { + Waifu2x->close(); + QFile::remove(OutPut_Path); + emit Send_Table_image_ChangeStatus_rowNumInt_statusQString(rowNum, "Interrupted"); + mutex_ThreadNumRunning.lock(); + ThreadNumRunning--; + mutex_ThreadNumRunning.unlock(); + return 0; + } + } + if(QFile::exists(OutPut_Path)) + { + break; + } + else + { + if(retry==ui->spinBox_retry->value()+(ForceRetryCount-1))break; + Delay_sec_sleep(5); + emit Send_TextBrowser_NewMessage(tr("Automatic retry, please wait.")); + } + } + //======== + if(!QFile::exists(OutPut_Path)) + { + if(SourceFile_fullPath_Original!=SourceFile_fullPath) + { + QFile::remove(SourceFile_fullPath); + } + emit Send_TextBrowser_NewMessage(tr("Error occured when processing [")+SourceFile_fullPath_Original+tr("]. Error: [Unable to scale the picture.]")); + emit Send_Table_image_ChangeStatus_rowNumInt_statusQString(rowNum, "Failed"); + emit Send_progressbar_Add(); + mutex_ThreadNumRunning.lock(); + ThreadNumRunning--; + mutex_ThreadNumRunning.unlock(); + return 0; + } + OutPutPath_Final = OutPut_Path; + //============================ 调整大小 ==================================================== + if(CustRes_isEnabled) + { + do + { + QImage qimage_adj(OutPut_Path); + //读取放大后的图片并调整大小 + QImage qimage_adj_scaled = qimage_adj.scaled(CustRes_width,CustRes_height,CustRes_AspectRatioMode,Qt::SmoothTransformation); + QImageWriter qimageW_adj; + qimageW_adj.setFormat("png"); + qimageW_adj.setFileName(OutPut_Path); + if(qimageW_adj.canWrite()) + { + qimageW_adj.write(qimage_adj_scaled); + } + if(!QFile::exists(OutPut_Path)) + { + emit Send_TextBrowser_NewMessage(tr("Error occured when processing [")+SourceFile_fullPath+tr("]. Error: [Unable to resize the scaled picture to the target size]")); + emit Send_Table_image_ChangeStatus_rowNumInt_statusQString(rowNum, "Failed"); + emit Send_progressbar_Add(); + mutex_ThreadNumRunning.lock(); + ThreadNumRunning--; + mutex_ThreadNumRunning.unlock();//线程数量统计-1 + return 0; + } + } + while(false); + QString OutPut_Path_CustRes = file_path + "/" + file_name + "_waifu2x_"+QString::number(CustRes_width, 10)+"x"+QString::number(CustRes_height, 10)+"_"+QString::number(DenoiseLevel, 10)+"n_"+file_ext+".png"; + QFile::remove(OutPut_Path_CustRes); + QFile::rename(OutPut_Path,OutPut_Path_CustRes); + OutPutPath_Final = OutPut_Path_CustRes; + } + //=========================== 另存为JPG&压缩JPG =========================================== + OutPutPath_Final = SaveImageAs_FormatAndQuality(SourceFile_fullPath_Original,OutPutPath_Final,true,DenoiseLevel); + //================== 检查是否丢失了透明通道 ===================== + if(ReProcess_MissingAlphaChannel==false) + { + QImage QImage_source(SourceFile_fullPath_Original); + QImage QImage_Final(OutPutPath_Final); + if(QImage_source.hasAlphaChannel()==true && QImage_Final.hasAlphaChannel()==false && ui->checkBox_AutoDetectAlphaChannel->isChecked()) + { + QFile::remove(OutPutPath_Final); + emit Send_TextBrowser_NewMessage(tr("Since the Alpha channel in the resulting image is lost, this image will be reprocessed to fix it:[")+SourceFile_fullPath_Original+tr("].\nIf the reprocessing happens a lot, you should consider enable [Always pre-process images with Alpha Channel] in [Additional settings].")); + return Waifu2x_Converter_Image(rowNum,true); + } + } + //============================= 删除原文件 & & 更新table status ============================ + if(SourceFile_fullPath_Original!=SourceFile_fullPath) + { + QFile::remove(SourceFile_fullPath); + SourceFile_fullPath = SourceFile_fullPath_Original; + } + if(DelOriginal) + { + if(ReplaceOriginalFile(SourceFile_fullPath,OutPutPath_Final)==false) + { + if(QAction_checkBox_MoveToRecycleBin_checkBox_DelOriginal->isChecked()) + { + file_MoveToTrash(SourceFile_fullPath); + } + else + { + QFile::remove(SourceFile_fullPath); + } + } + emit Send_Table_image_ChangeStatus_rowNumInt_statusQString(rowNum, "Finished, original file deleted"); + } + else + { + emit Send_Table_image_ChangeStatus_rowNumInt_statusQString(rowNum, "Finished"); + } + //========== 移动到输出路径 ========= + if(ui->checkBox_OutPath_isEnabled->isChecked()) + { + MoveFileToOutputPath(OutPutPath_Final,SourceFile_fullPath); + } + //============================ 更新进度条 ================================= + emit Send_progressbar_Add(); + //=========================== 更新线程数量统计============================== + mutex_ThreadNumRunning.lock(); + ThreadNumRunning--; + mutex_ThreadNumRunning.unlock();//线程数量统计-1 + return 0; +} + + +int MainWindow::Waifu2x_Converter_GIF(int rowNum) +{ + //============================= 读取设置 ================================ + int ScaleRatio = ui->doubleSpinBox_ScaleRatio_gif->value(); + int DenoiseLevel = ui->spinBox_DenoiseLevel_gif->value(); + bool DelOriginal = (ui->checkBox_DelOriginal->isChecked()||ui->checkBox_ReplaceOriginalFile->isChecked()); + int Sub_gif_ThreadNumRunning = 0; + QString OutPutPath_Final =""; + //========================= 拆解map得到参数 ============================= + emit Send_Table_gif_ChangeStatus_rowNumInt_statusQString(rowNum, "Processing"); + QString SourceFile_fullPath = Table_model_gif->item(rowNum,2)->text(); + if(!QFile::exists(SourceFile_fullPath)) + { + emit Send_TextBrowser_NewMessage(tr("Error occured when processing [")+SourceFile_fullPath+tr("]. Error: [File does not exist.]")); + emit Send_Table_gif_ChangeStatus_rowNumInt_statusQString(rowNum, "Failed"); + emit Send_progressbar_Add(); + return 0; + } + //========================== + bool CustRes_isEnabled = false; + int CustRes_height=0; + int CustRes_width=0; + if(CustRes_isContained(SourceFile_fullPath)) + { + CustRes_isEnabled=true; + QMap Res_map = CustRes_getResMap(SourceFile_fullPath);//res_map["fullpath"],["height"],["width"] + CustRes_height=Res_map["height"].toInt(); + CustRes_width=Res_map["width"].toInt(); + } + //========================== + QFileInfo fileinfo(SourceFile_fullPath); + QString file_name = file_getBaseName(SourceFile_fullPath); + QString file_ext = fileinfo.suffix(); + QString file_path = file_getFolderPath(fileinfo); + QString ResGIFPath = file_path + "/" + file_name + "_waifu2x_"+QString::number(ScaleRatio, 10)+"x_"+QString::number(DenoiseLevel, 10)+"n.gif"; + //=========================== 获取帧时间 ==================================== + int GIF_Duration = Gif_getDuration(SourceFile_fullPath); + if(GIF_Duration==0)//检查是否成功获取duration + { + emit Send_TextBrowser_NewMessage(tr("Error occured when processing [")+SourceFile_fullPath+tr("]. Error: [Can't get Duration value of GIF file.]")); + emit Send_Table_gif_ChangeStatus_rowNumInt_statusQString(rowNum, "Failed"); + //file_DelDir(SplitFramesFolderPath); + emit Send_progressbar_Add(); + return 0;//如果启用stop位,则直接return + } + //============================== 拆分 ========================================== + QString SplitFramesFolderPath = file_path+"/"+file_name+"_SplitFrames_W2xEX";//拆分后存储frame的文件夹 + Gif_splitGif(SourceFile_fullPath,SplitFramesFolderPath); + //============================== 扫描获取文件名 =============================== + QStringList Frame_fileName_list = file_getFileNames_in_Folder_nofilter(SplitFramesFolderPath); + if(Frame_fileName_list.isEmpty())//检查是否成功拆分gif + { + emit Send_TextBrowser_NewMessage(tr("Error occured when processing [")+SourceFile_fullPath+tr("]. Error: [Can't split GIF into frames.]")); + emit Send_Table_gif_ChangeStatus_rowNumInt_statusQString(rowNum, "Failed"); + file_DelDir(SplitFramesFolderPath); + emit Send_progressbar_Add(); + return 0;//如果启用stop位,则直接return + } + //===========建立存储放大后frame的文件夹=========== + QString ScaledFramesFolderPath = SplitFramesFolderPath+"/ScaledFrames_W2xEX"; + if(file_isDirExist(ScaledFramesFolderPath)) + { + file_DelDir(ScaledFramesFolderPath); + file_mkDir(ScaledFramesFolderPath); + } + else + { + file_mkDir(ScaledFramesFolderPath); + } + //==========开始放大========================== + emit Send_CurrentFileProgress_Start(file_name+"."+file_ext,Frame_fileName_list.size()); + FileProgressWatch_isEnabled=true; + QFuture FileProgressWatch_QFuture = QtConcurrent::run(this, &MainWindow::CurrentFileProgress_WatchFolderFileNum, ScaledFramesFolderPath);//启动waifu2x 主线程 + if(ui->checkBox_ShowInterPro->isChecked()==false) + { + FileProgressWatch_isEnabled=false; + FileProgressWatch_QFuture.cancel(); + emit Send_CurrentFileProgress_Stop(); + } + //=======获取显卡信息======== + int NumOfGPU = 1; + if(ui->checkBox_MultiGPU_Waifu2xConverter->isChecked()==true) + { + NumOfGPU=0; + for (int i=0; i GPUInfo_tmp = GPUIDs_List_MultiGPU_Waifu2xConverter.at(i); + if(GPUInfo_tmp["isEnabled"] == "true") + { + NumOfGPU++; + } + } + } + //============创建显卡文件夹=========== + QStringList GPU_SplitFramesFolderPath_List; + for(int i = 0; i < NumOfGPU; i++) + { + QString GPU_SplitFramesFolderPath = SplitFramesFolderPath+"/"+"GPU_"+QString::number(i); + if(file_isDirExist(GPU_SplitFramesFolderPath)) + { + file_DelDir(GPU_SplitFramesFolderPath); + file_mkDir(GPU_SplitFramesFolderPath); + } + else + { + file_mkDir(GPU_SplitFramesFolderPath); + } + GPU_SplitFramesFolderPath_List.append(GPU_SplitFramesFolderPath); + } + int TotalFramesNum = Frame_fileName_list.size(); + int FramesNumForEachGPU = TotalFramesNum/NumOfGPU; + if(FramesNumForEachGPU<1)FramesNumForEachGPU=1; + int start_num=0; + for(int x = 0; x < GPU_SplitFramesFolderPath_List.size(); x++) + { + if(x==GPU_SplitFramesFolderPath_List.size()-1)FramesNumForEachGPU=TotalFramesNum; + QStringList file_waitformove = Frame_fileName_list.mid(start_num,FramesNumForEachGPU); + for(int i = 0; i < file_waitformove.size(); i++) + { + QString FileName = file_waitformove.at(i); + QFile::rename(SplitFramesFolderPath+"/"+FileName,GPU_SplitFramesFolderPath_List.at(x)+"/"+FileName); + } + start_num+=FramesNumForEachGPU; + } + //========================= + bool Frame_failed = false;//放大失败标志 + //==== + QMap Sub_Thread_info; + Sub_Thread_info["ScaledFramesFolderPath"]= ScaledFramesFolderPath; + Sub_Thread_info["Denoise_cmd"] = " --noise-level " + QString::number(DenoiseLevel, 10); + if(CustRes_isEnabled == true) + { + Sub_Thread_info["ScaleRatio"] = QString("%1").arg(CustRes_CalNewScaleRatio(SourceFile_fullPath,CustRes_height,CustRes_width)); + } + else + { + Sub_Thread_info["ScaleRatio"] = QString("%1").arg(ScaleRatio); + } + //========================= + for(int i = 0; i < GPU_SplitFramesFolderPath_List.size(); i++) + { + Sub_Thread_info["SplitFramesFolderPath"]=GPU_SplitFramesFolderPath_List.at(i); + mutex_SubThreadNumRunning.lock(); + Sub_gif_ThreadNumRunning++; + mutex_SubThreadNumRunning.unlock(); + QtConcurrent::run(this,&MainWindow::Waifu2x_Converter_GIF_scale,Sub_Thread_info,&Sub_gif_ThreadNumRunning,&Frame_failed); + while (Sub_gif_ThreadNumRunning >= NumOfGPU) + { + Delay_msec_sleep(500); + } + if(waifu2x_STOP) + { + while (Sub_gif_ThreadNumRunning > 0) + { + Delay_msec_sleep(500); + } + FileProgressWatch_isEnabled=false; + FileProgressWatch_QFuture.cancel(); + file_DelDir(SplitFramesFolderPath); + emit Send_Table_gif_ChangeStatus_rowNumInt_statusQString(rowNum, "Interrupted"); + return 0;//如果启用stop位,则直接return + } + if(Frame_failed) + { + FileProgressWatch_isEnabled=false; + FileProgressWatch_QFuture.cancel(); + emit Send_TextBrowser_NewMessage(tr("Error occured when processing [")+SourceFile_fullPath+tr("]. Error: [Failed to scale frames.]")); + emit Send_Table_gif_ChangeStatus_rowNumInt_statusQString(rowNum, "Failed"); + file_DelDir(SplitFramesFolderPath); + emit Send_progressbar_Add(); + return 0;//如果启用stop位,则直接return + } + } + while (Sub_gif_ThreadNumRunning!=0) + { + Delay_msec_sleep(500); + } + FileProgressWatch_isEnabled=false; + FileProgressWatch_QFuture.cancel(); + emit Send_CurrentFileProgress_Stop(); + //======================= 检查是否成功放大所有帧 =========================== + if(Frame_fileName_list.size() != file_getFileNames_in_Folder_nofilter(ScaledFramesFolderPath).size()) + { + emit Send_TextBrowser_NewMessage(tr("Error occured when processing [")+SourceFile_fullPath+tr("]. Error: [Failed to scale frames.]")); + emit Send_Table_gif_ChangeStatus_rowNumInt_statusQString(rowNum, "Failed"); + file_DelDir(SplitFramesFolderPath); + emit Send_progressbar_Add(); + return 0;//如果启用stop位,则直接return + } + //======================================== 组装 ====================================================== + if(CustRes_isEnabled == true) + { + ResGIFPath = file_path + "/" + file_name + "_waifu2x_"+QString::number(CustRes_width, 10)+"x"+QString::number(CustRes_height,10)+"_"+QString::number(DenoiseLevel, 10)+"n.gif"; + } + Gif_assembleGif(ResGIFPath,ScaledFramesFolderPath,GIF_Duration,CustRes_isEnabled,CustRes_height,CustRes_width,false,""); + if(QFile::exists(ResGIFPath) == false) + { + emit Send_TextBrowser_NewMessage(tr("Error occured when processing [")+SourceFile_fullPath+tr("]. Error: [Unable to assemble gif.]")); + emit Send_Table_gif_ChangeStatus_rowNumInt_statusQString(rowNum, "Failed"); + file_DelDir(SplitFramesFolderPath); + emit Send_progressbar_Add(); + return 0;//如果启用stop位,则直接return + } + OutPutPath_Final = ResGIFPath; + //======================================= 优化gif =================================================== + if(ui->checkBox_OptGIF->isChecked() == true) + { + QString ResGIFPath_compressed = ""; + if(CustRes_isEnabled == true) + { + ResGIFPath_compressed = file_path + "/" + file_name + "_waifu2x_"+QString::number(CustRes_width, 10)+"x"+QString::number(CustRes_height,10)+"_"+QString::number(DenoiseLevel, 10)+"n_opt.gif"; + } + else + { + ResGIFPath_compressed = file_path + "/" + file_name + "_waifu2x_"+QString::number(ScaleRatio, 10)+"x_"+QString::number(DenoiseLevel, 10)+"n_opt.gif"; + } + OutPutPath_Final = Gif_compressGif(ResGIFPath,ResGIFPath_compressed); + } + //============================== 删除缓存文件 ==================================================== + file_DelDir(SplitFramesFolderPath); + //============================= 删除原文件 & & 更新table status ============================ + if(DelOriginal) + { + if(ReplaceOriginalFile(SourceFile_fullPath,OutPutPath_Final)==false) + { + if(QAction_checkBox_MoveToRecycleBin_checkBox_DelOriginal->isChecked()) + { + file_MoveToTrash(SourceFile_fullPath); + } + else + { + QFile::remove(SourceFile_fullPath); + } + } + emit Send_Table_gif_ChangeStatus_rowNumInt_statusQString(rowNum, "Finished, original file deleted"); + } + else + { + emit Send_Table_gif_ChangeStatus_rowNumInt_statusQString(rowNum, "Finished"); + } + //========== 移动到输出路径 ========= + if(ui->checkBox_OutPath_isEnabled->isChecked()) + { + MoveFileToOutputPath(OutPutPath_Final,SourceFile_fullPath); + } + //============================ 更新进度条 ================================= + emit Send_progressbar_Add(); + //======= + return 0; +} + +int MainWindow::Waifu2x_Converter_GIF_scale(QMap Sub_Thread_info,int *Sub_gif_ThreadNumRunning,bool *Frame_failed) +{ + bool AllFinished; + QString SplitFramesFolderPath = Sub_Thread_info["SplitFramesFolderPath"]; + QString ScaledFramesFolderPath = Sub_Thread_info["ScaledFramesFolderPath"]; + //=========== + QString Denoise_cmd = Sub_Thread_info["Denoise_cmd"]; + //======================================================================== + QStringList InputFilesNameList = file_getFileNames_in_Folder_nofilter(SplitFramesFolderPath); + QStringList OutPutFilesFullPathList; + for(int i=0; ispinBox_retry->value()+ForceRetryCount); retry++) + { + Waifu2x->start(cmd); + while(!Waifu2x->waitForStarted(100)&&!QProcess_stop) {} + while(!Waifu2x->waitForFinished(500)&&!QProcess_stop) + { + if(waifu2x_STOP) + { + Waifu2x->close(); + mutex_SubThreadNumRunning.lock(); + *Sub_gif_ThreadNumRunning=*Sub_gif_ThreadNumRunning-1; + mutex_SubThreadNumRunning.unlock(); + return 0; + } + } + AllFinished = true; + for(int i=0; ispinBox_retry->value()+(ForceRetryCount-1))break; + Delay_sec_sleep(5); + emit Send_TextBrowser_NewMessage(tr("Automatic retry, please wait.")); + AllFinished=false; + break; + } + } + if(AllFinished)break; + } + //========= + AllFinished = true; + for(int i=0; idoubleSpinBox_ScaleRatio_video->value(); + int DenoiseLevel = ui->spinBox_DenoiseLevel_video->value(); + bool DelOriginal = (ui->checkBox_DelOriginal->isChecked()||ui->checkBox_ReplaceOriginalFile->isChecked()); + bool isCacheExists = false; + bool isVideoConfigChanged = true; + int Sub_video_ThreadNumRunning = 0; + //========================= 拆解map得到参数 ============================= + emit Send_Table_video_ChangeStatus_rowNumInt_statusQString(rowNum, "Processing"); + QString SourceFile_fullPath = Table_model_video->item(rowNum,2)->text(); + if(!QFile::exists(SourceFile_fullPath)) + { + emit Send_TextBrowser_NewMessage(tr("Error occured when processing [")+SourceFile_fullPath+tr("]. Error: [File does not exist.]")); + emit Send_Table_video_ChangeStatus_rowNumInt_statusQString(rowNum, "Failed"); + emit Send_progressbar_Add(); + return 0; + } + //========================== + QFileInfo fileinfo(SourceFile_fullPath); + QString file_name = file_getBaseName(SourceFile_fullPath); + QString file_ext = fileinfo.suffix(); + QString file_path = file_getFolderPath(fileinfo); + //=================================================================== + //生成mp4 + QString video_mp4_fullpath=video_To_CFRMp4(SourceFile_fullPath); + if(!QFile::exists(video_mp4_fullpath))//检查是否成功生成mp4 + { + emit Send_TextBrowser_NewMessage(tr("Error occured when processing [")+SourceFile_fullPath+tr("]. Error: [Cannot convert video format to mp4.]")); + emit Send_Table_video_ChangeStatus_rowNumInt_statusQString(rowNum, "Failed"); + emit Send_progressbar_Add(); + return 0;//如果启用stop位,则直接return + } + //============== 读取自定义分辨率 ============ + bool CustRes_isEnabled = false; + int CustRes_height=0; + int CustRes_width=0; + if(CustRes_isContained(SourceFile_fullPath)) + { + CustRes_isEnabled=true; + QMap Res_map = CustRes_getResMap(SourceFile_fullPath);//res_map["fullpath"],["height"],["width"] + CustRes_height=Res_map["height"].toInt(); + CustRes_width=Res_map["width"].toInt(); + } + //================= + QString AudioPath = file_path+"/Audio_"+file_name+"_"+file_ext+"_W2xEX.wav";//音频 + QString SplitFramesFolderPath = file_path+"/"+file_name+"_"+file_ext+"_SplitFrames_W2xEX";//拆分后存储frame的文件夹 + QString ScaledFramesFolderPath = SplitFramesFolderPath+"/ScaledFrames_W2xEX";//存储放大后的帧 + //========================== + // 检测之前的视频配置文件 + //========================== + QString VideoConfiguration_fullPath = file_path+"/VideoConfiguration_"+file_name+"_"+file_ext+"_Waifu2xEX.ini"; + if(QFile::exists(VideoConfiguration_fullPath)) + { + QSettings *configIniRead = new QSettings(VideoConfiguration_fullPath, QSettings::IniFormat); + configIniRead->setIniCodec(QTextCodec::codecForName("UTF-8")); + //=================== 加载之前存储的视频信息 ========================= + int ScaleRatio_old = configIniRead->value("/VideoConfiguration/ScaleRatio").toInt(); + int DenoiseLevel_old = configIniRead->value("/VideoConfiguration/DenoiseLevel").toInt(); + bool CustRes_isEnabled_old = configIniRead->value("/VideoConfiguration/CustRes_isEnabled").toBool(); + int CustRes_height_old = configIniRead->value("/VideoConfiguration/CustRes_height").toInt(); + int CustRes_width_old = configIniRead->value("/VideoConfiguration/CustRes_width").toInt(); + QString EngineName_old = configIniRead->value("/VideoConfiguration/EngineName").toString(); + bool isProcessBySegment_old = configIniRead->value("/VideoConfiguration/isProcessBySegment").toBool(); + //=================== 比对信息 ================================ + if(EngineName_old=="waifu2x-converter") + { + if(CustRes_isEnabled_old==false&&CustRes_isEnabled==false) + { + if(ScaleRatio_old!=ScaleRatio||DenoiseLevel_old!=DenoiseLevel) + { + isVideoConfigChanged=true; + } + else + { + isVideoConfigChanged=false; + } + } + else + { + if(CustRes_isEnabled_old==true&&CustRes_isEnabled==true) + { + if(CustRes_height_old!=CustRes_height||CustRes_width_old!=CustRes_width) + { + isVideoConfigChanged=true; + } + else + { + isVideoConfigChanged=false; + } + } + else + { + isVideoConfigChanged=true; + } + } + if(isProcessBySegment_old==true) + { + isVideoConfigChanged=true; + } + } + else + { + isVideoConfigChanged=true; + } + } + else + { + emit Send_video_write_VideoConfiguration(VideoConfiguration_fullPath,ScaleRatio,DenoiseLevel,CustRes_isEnabled,CustRes_height,CustRes_width,"waifu2x-converter",false,"","",ui->groupBox_FrameInterpolation->isChecked(),0); + } + //======================= + // 检测缓存是否存在 + //======================= + if(QFile::exists(video_mp4_fullpath)&&file_isDirExist(SplitFramesFolderPath)&&file_isDirExist(ScaledFramesFolderPath)&&QFile::exists(VideoConfiguration_fullPath)) + { + if(!isVideoConfigChanged) + { + isCacheExists=true; + emit Send_TextBrowser_NewMessage(tr("The previous video cache file is detected and processing of the previous video cache will continue. If you want to restart processing of the current video:[")+SourceFile_fullPath+tr("], delete the cache manually.")); + } + else + { + isCacheExists=false; + //======== + QFile::remove(VideoConfiguration_fullPath); + file_DelDir(SplitFramesFolderPath); + QFile::remove(AudioPath); + DelVfiDir(video_mp4_fullpath); + emit Send_video_write_VideoConfiguration(VideoConfiguration_fullPath,ScaleRatio,DenoiseLevel,CustRes_isEnabled,CustRes_height,CustRes_width,"waifu2x-converter",false,"","",ui->groupBox_FrameInterpolation->isChecked(),0); + //======= + emit Send_TextBrowser_NewMessage(tr("The previous video cache file was detected, but because you changed the settings about the video resolution or denoise level, the previous cache will be deleted and processing of the video:[")+SourceFile_fullPath+tr("] will restart.")); + } + } + else + { + isCacheExists=false; + //======== + QFile::remove(VideoConfiguration_fullPath); + file_DelDir(SplitFramesFolderPath); + QFile::remove(AudioPath); + DelVfiDir(video_mp4_fullpath); + emit Send_video_write_VideoConfiguration(VideoConfiguration_fullPath,ScaleRatio,DenoiseLevel,CustRes_isEnabled,CustRes_height,CustRes_width,"waifu2x-converter",false,"","",ui->groupBox_FrameInterpolation->isChecked(),0); + //======== + } + if(!isCacheExists) + { + //============================== 拆分 ========================================== + if(file_isDirExist(SplitFramesFolderPath)) + { + file_DelDir(SplitFramesFolderPath); + file_mkDir(SplitFramesFolderPath); + } + else + { + file_mkDir(SplitFramesFolderPath); + } + QFile::remove(AudioPath); + video_video2images(video_mp4_fullpath,SplitFramesFolderPath,AudioPath); + if(waifu2x_STOP) + { + emit Send_Table_video_ChangeStatus_rowNumInt_statusQString(rowNum, "Interrupted"); + return 0;//如果启用stop位,则直接return + } + } + //============================== 扫描获取文件名 =============================== + QStringList Frame_fileName_list = file_getFileNames_in_Folder_nofilter(SplitFramesFolderPath); + if(!isCacheExists) + { + if(Frame_fileName_list.isEmpty())//检查是否成功拆分为帧 + { + emit Send_TextBrowser_NewMessage(tr("Error occured when processing [")+SourceFile_fullPath+tr("]. Error: [Unable to split video into pictures.]")); + emit Send_Table_video_ChangeStatus_rowNumInt_statusQString(rowNum, "Failed"); + emit Send_progressbar_Add(); + return 0;//如果启用stop位,则直接return + } + } + //============================== 放大 ======================================= + //===========建立存储放大后frame的文件夹=========== + if(!isCacheExists) + { + if(file_isDirExist(ScaledFramesFolderPath)) + { + file_DelDir(ScaledFramesFolderPath); + file_mkDir(ScaledFramesFolderPath); + } + else + { + file_mkDir(ScaledFramesFolderPath); + } + } + //==========开始放大========================== + emit Send_CurrentFileProgress_Start(file_name+"."+file_ext,(Frame_fileName_list.size()+file_getFileNames_in_Folder_nofilter(ScaledFramesFolderPath).size())); + FileProgressWatch_isEnabled=true; + QFuture FileProgressWatch_QFuture = QtConcurrent::run(this, &MainWindow::CurrentFileProgress_WatchFolderFileNum, ScaledFramesFolderPath);//启动waifu2x 主线程 + if(ui->checkBox_ShowInterPro->isChecked()==false) + { + FileProgressWatch_isEnabled=false; + FileProgressWatch_QFuture.cancel(); + emit Send_CurrentFileProgress_Stop(); + } + //=======获取显卡信息======== + int NumOfGPU = 1; + if(ui->checkBox_MultiGPU_Waifu2xConverter->isChecked()==true) + { + NumOfGPU=0; + for (int i=0; i GPUInfo_tmp = GPUIDs_List_MultiGPU_Waifu2xConverter.at(i); + if(GPUInfo_tmp["isEnabled"] == "true") + { + NumOfGPU++; + } + } + } + //============创建显卡文件夹=========== + QStringList GPU_SplitFramesFolderPath_List; + for(int i = 0; i < NumOfGPU; i++) + { + QString GPU_SplitFramesFolderPath = SplitFramesFolderPath+"/"+"GPU_"+QString::number(i); + if(file_isDirExist(GPU_SplitFramesFolderPath)==false) + { + file_DelDir(GPU_SplitFramesFolderPath); + file_mkDir(GPU_SplitFramesFolderPath); + } + else + { + file_mkDir(GPU_SplitFramesFolderPath); + } + GPU_SplitFramesFolderPath_List.append(GPU_SplitFramesFolderPath); + } + int TotalFramesNum = Frame_fileName_list.size(); + int FramesNumForEachGPU = TotalFramesNum/NumOfGPU; + if(FramesNumForEachGPU<1)FramesNumForEachGPU=1; + int start_num=0; + for(int x = 0; x < GPU_SplitFramesFolderPath_List.size(); x++) + { + if(x==GPU_SplitFramesFolderPath_List.size()-1)FramesNumForEachGPU=TotalFramesNum; + QStringList file_waitformove = Frame_fileName_list.mid(start_num,FramesNumForEachGPU); + for(int i = 0; i < file_waitformove.size(); i++) + { + QString FileName = file_waitformove.at(i); + QFile::rename(SplitFramesFolderPath+"/"+FileName,GPU_SplitFramesFolderPath_List.at(x)+"/"+FileName); + } + start_num+=FramesNumForEachGPU; + } + //========================= + bool Frame_failed = false;//放大失败标志 + QMap Sub_Thread_info; + Sub_Thread_info["ScaledFramesFolderPath"]=ScaledFramesFolderPath; + Sub_Thread_info["Denoise_cmd"] = " --noise-level " + QString::number(DenoiseLevel, 10); + if(CustRes_isEnabled == true) + { + Sub_Thread_info["ScaleRatio"] = QString("%1").arg(CustRes_CalNewScaleRatio(video_mp4_fullpath,CustRes_height,CustRes_width)); + } + else + { + Sub_Thread_info["ScaleRatio"] = QString("%1").arg(ScaleRatio); + } + //========================= + for(int i = 0; i < GPU_SplitFramesFolderPath_List.size(); i++) + { + Sub_Thread_info["SplitFramesFolderPath"]=GPU_SplitFramesFolderPath_List.at(i); + mutex_SubThreadNumRunning.lock(); + Sub_video_ThreadNumRunning++; + mutex_SubThreadNumRunning.unlock(); + QtConcurrent::run(this,&MainWindow::Waifu2x_Converter_Video_scale,Sub_Thread_info,&Sub_video_ThreadNumRunning,&Frame_failed); + while (Sub_video_ThreadNumRunning >= NumOfGPU) + { + Delay_msec_sleep(500); + } + if(waifu2x_STOP) + { + while (Sub_video_ThreadNumRunning > 0) + { + Delay_msec_sleep(500); + } + FileProgressWatch_isEnabled=false; + FileProgressWatch_QFuture.cancel(); + Restore_SplitFramesFolderPath(SplitFramesFolderPath,GPU_SplitFramesFolderPath_List); + emit Send_Table_video_ChangeStatus_rowNumInt_statusQString(rowNum, "Interrupted"); + return 0;//如果启用stop位,则直接return + } + if(Frame_failed) + { + FileProgressWatch_isEnabled=false; + FileProgressWatch_QFuture.cancel(); + Restore_SplitFramesFolderPath(SplitFramesFolderPath,GPU_SplitFramesFolderPath_List); + emit Send_TextBrowser_NewMessage(tr("Error occured when processing [")+SourceFile_fullPath+tr("]. Error: [Failed to scale frames.]")); + emit Send_Table_video_ChangeStatus_rowNumInt_statusQString(rowNum, "Failed"); + emit Send_progressbar_Add(); + return 0;//如果启用stop位,则直接return + } + } + while (Sub_video_ThreadNumRunning!=0) + { + Delay_msec_sleep(500); + } + FileProgressWatch_isEnabled=false; + FileProgressWatch_QFuture.cancel(); + emit Send_CurrentFileProgress_Stop(); + //================ 扫描放大后的帧文件数量,判断是否放大成功 ======================= + QStringList Frame_fileName_list_scaled = file_getFileNames_in_Folder_nofilter(ScaledFramesFolderPath); + if(Frame_fileName_list_scaled.size()checkBox_KeepVideoCache->isChecked()==false) + { + QFile::remove(VideoConfiguration_fullPath); + file_DelDir(SplitFramesFolderPath); + QFile::remove(AudioPath); + if(SourceFile_fullPath!=video_mp4_fullpath)QFile::remove(video_mp4_fullpath); + } + else + { + DelOriginal=false; + } + //============================= 删除原文件 & & 更新table status ============================ + if(DelOriginal) + { + if(ReplaceOriginalFile(SourceFile_fullPath,video_mp4_scaled_fullpath)==false) + { + if(QAction_checkBox_MoveToRecycleBin_checkBox_DelOriginal->isChecked()) + { + file_MoveToTrash(SourceFile_fullPath); + } + else + { + QFile::remove(SourceFile_fullPath); + } + } + emit Send_Table_video_ChangeStatus_rowNumInt_statusQString(rowNum, "Finished, original file deleted"); + } + else + { + emit Send_Table_video_ChangeStatus_rowNumInt_statusQString(rowNum, "Finished"); + } + //========== 移动到输出路径 ========= + if(ui->checkBox_OutPath_isEnabled->isChecked()) + { + MoveFileToOutputPath(video_mp4_scaled_fullpath,SourceFile_fullPath); + } + //============================ 更新进度条 ================================= + emit Send_progressbar_Add(); + //=========================== ============================== + return 0; +} + +/* +#### 分段处理 #### +调用Waifu2x-Converter处理视频 +读取设置,拆分,创建放大子线程,组装视频 +*/ +int MainWindow::Waifu2x_Converter_Video_BySegment(int rowNum) +{ + //============================= 读取设置 ================================ + int ScaleRatio = ui->doubleSpinBox_ScaleRatio_video->value(); + int DenoiseLevel = ui->spinBox_DenoiseLevel_video->value(); + bool DelOriginal = (ui->checkBox_DelOriginal->isChecked()||ui->checkBox_ReplaceOriginalFile->isChecked()); + bool isCacheExists = false; + bool isVideoConfigChanged = true; + int Sub_video_ThreadNumRunning = 0; + int SegmentDuration = ui->spinBox_SegmentDuration->value(); + //========================= 拆解map得到参数 ============================= + emit Send_Table_video_ChangeStatus_rowNumInt_statusQString(rowNum, "Processing"); + QString SourceFile_fullPath = Table_model_video->item(rowNum,2)->text(); + if(!QFile::exists(SourceFile_fullPath)) + { + emit Send_TextBrowser_NewMessage(tr("Error occured when processing [")+SourceFile_fullPath+tr("]. Error: [File does not exist.]")); + emit Send_Table_video_ChangeStatus_rowNumInt_statusQString(rowNum, "Failed"); + emit Send_progressbar_Add(); + return 0; + } + //========================== + QFileInfo fileinfo(SourceFile_fullPath); + QString file_name = file_getBaseName(SourceFile_fullPath); + QString file_ext = fileinfo.suffix(); + QString file_path = file_getFolderPath(fileinfo); + //=================================================================== + //生成mp4 + QString video_mp4_fullpath=video_To_CFRMp4(SourceFile_fullPath); + if(!QFile::exists(video_mp4_fullpath))//检查是否成功生成mp4 + { + emit Send_TextBrowser_NewMessage(tr("Error occured when processing [")+SourceFile_fullPath+tr("]. Error: [Cannot convert video format to mp4.]")); + emit Send_Table_video_ChangeStatus_rowNumInt_statusQString(rowNum, "Failed"); + emit Send_progressbar_Add(); + return 0;//如果启用stop位,则直接return + } + //============== 读取自定义分辨率 ============ + bool CustRes_isEnabled = false; + int CustRes_height=0; + int CustRes_width=0; + if(CustRes_isContained(SourceFile_fullPath)) + { + CustRes_isEnabled=true; + QMap Res_map = CustRes_getResMap(SourceFile_fullPath);//res_map["fullpath"],["height"],["width"] + CustRes_height=Res_map["height"].toInt(); + CustRes_width=Res_map["width"].toInt(); + } + //================= + QString AudioPath = file_path+"/Audio_"+file_name+"_"+file_ext+"_W2xEX.wav";//音频 + QString SplitFramesFolderPath = file_path+"/"+file_name+"_"+file_ext+"_SplitFrames_W2xEX";//拆分后存储frame的文件夹 + QString ScaledFramesFolderPath = SplitFramesFolderPath+"/ScaledFrames_W2xEX";//存储放大后的帧 + //=== + QString VideoClipsFolderPath = "";//存储视频片段的文件夹(完整路径) + QString DateStr = ""; + do + { + DateStr = video_getClipsFolderNo(); + VideoClipsFolderPath = file_path+"/"+DateStr+"_VideoClipsWaifu2xEX";//存储视频片段的文件夹(完整路径) + } + while(file_isDirExist(VideoClipsFolderPath)); + QString VideoClipsFolderName = DateStr+"_VideoClipsWaifu2xEX";//存储视频片段的文件夹(名称) + //========================== + // 检测之前的视频配置文件 + //========================== + QString VideoConfiguration_fullPath = file_path+"/VideoConfiguration_"+file_name+"_"+file_ext+"_Waifu2xEX.ini"; + if(QFile::exists(VideoConfiguration_fullPath)) + { + QSettings *configIniRead = new QSettings(VideoConfiguration_fullPath, QSettings::IniFormat); + configIniRead->setIniCodec(QTextCodec::codecForName("UTF-8")); + //=================== 加载之前存储的视频信息 ========================= + int ScaleRatio_old = configIniRead->value("/VideoConfiguration/ScaleRatio").toInt(); + int DenoiseLevel_old = configIniRead->value("/VideoConfiguration/DenoiseLevel").toInt(); + bool CustRes_isEnabled_old = configIniRead->value("/VideoConfiguration/CustRes_isEnabled").toBool(); + int CustRes_height_old = configIniRead->value("/VideoConfiguration/CustRes_height").toInt(); + int CustRes_width_old = configIniRead->value("/VideoConfiguration/CustRes_width").toInt(); + QString EngineName_old = configIniRead->value("/VideoConfiguration/EngineName").toString(); + bool isProcessBySegment_old = configIniRead->value("/VideoConfiguration/isProcessBySegment").toBool(); + bool isVideoFrameInterpolationEnabled_old = configIniRead->value("/VideoConfiguration/isVideoFrameInterpolationEnabled").toBool(); + int MultipleOfFPS_old = configIniRead->value("/VideoConfiguration/MultipleOfFPS").toInt(); + //=================== 比对信息 ================================ + if(EngineName_old=="waifu2x-converter") + { + if(CustRes_isEnabled_old==false&&CustRes_isEnabled==false) + { + if(ScaleRatio_old!=ScaleRatio||DenoiseLevel_old!=DenoiseLevel) + { + isVideoConfigChanged=true; + } + else + { + isVideoConfigChanged=false; + } + } + else + { + if(CustRes_isEnabled_old==true&&CustRes_isEnabled==true) + { + if(CustRes_height_old!=CustRes_height||CustRes_width_old!=CustRes_width) + { + isVideoConfigChanged=true; + } + else + { + isVideoConfigChanged=false; + } + } + else + { + isVideoConfigChanged=true; + } + } + if(isProcessBySegment_old == false) + { + isVideoConfigChanged=true; + } + if(isVideoFrameInterpolationEnabled_old != ui->groupBox_FrameInterpolation->isChecked()) + { + isVideoConfigChanged=true; + } + if(MultipleOfFPS_old != ui->spinBox_MultipleOfFPS_VFI->value() && ui->groupBox_FrameInterpolation->isChecked()) + { + isVideoConfigChanged=true; + } + } + else + { + isVideoConfigChanged=true; + } + //============ 修正文件夹名称 ============= + QString VideoClipsFolderPath_old = configIniRead->value("/VideoConfiguration/VideoClipsFolderPath").toString(); + QString VideoClipsFolderName_old = configIniRead->value("/VideoConfiguration/VideoClipsFolderName").toString(); + file_mkDir(VideoClipsFolderPath_old); + if(file_isDirExist(VideoClipsFolderPath_old)==true) + { + VideoClipsFolderPath = VideoClipsFolderPath_old; + VideoClipsFolderName = VideoClipsFolderName_old; + } + } + else + { + emit Send_video_write_VideoConfiguration(VideoConfiguration_fullPath,ScaleRatio,DenoiseLevel,CustRes_isEnabled,CustRes_height,CustRes_width,"waifu2x-converter",true,VideoClipsFolderPath,VideoClipsFolderName,ui->groupBox_FrameInterpolation->isChecked(),ui->spinBox_MultipleOfFPS_VFI->value()); + } + //======================= + // 检测缓存是否存在 + //======================= + if(file_isDirExist(SplitFramesFolderPath)) + { + if(!isVideoConfigChanged) + { + isCacheExists=true; + emit Send_TextBrowser_NewMessage(tr("The previous video cache file is detected and processing of the previous video cache will continue. If you want to restart processing of the current video:[")+SourceFile_fullPath+tr("], delete the cache manually.")); + } + else + { + isCacheExists=false; + //======== + QFile::remove(VideoConfiguration_fullPath); + file_DelDir(SplitFramesFolderPath); + file_DelDir(VideoClipsFolderPath); + QFile::remove(AudioPath); + DelVfiDir(video_mp4_fullpath); + emit Send_video_write_VideoConfiguration(VideoConfiguration_fullPath,ScaleRatio,DenoiseLevel,CustRes_isEnabled,CustRes_height,CustRes_width,"waifu2x-converter",true,VideoClipsFolderPath,VideoClipsFolderName,ui->groupBox_FrameInterpolation->isChecked(),ui->spinBox_MultipleOfFPS_VFI->value()); + //======= + emit Send_TextBrowser_NewMessage(tr("The previous video cache file was detected, but because you changed the settings about the video resolution or denoise level, the previous cache will be deleted and processing of the video:[")+SourceFile_fullPath+tr("] will restart.")); + } + } + else + { + isCacheExists=false; + //======== + QFile::remove(VideoConfiguration_fullPath); + file_DelDir(SplitFramesFolderPath); + file_DelDir(VideoClipsFolderPath); + QFile::remove(AudioPath); + DelVfiDir(video_mp4_fullpath); + emit Send_video_write_VideoConfiguration(VideoConfiguration_fullPath,ScaleRatio,DenoiseLevel,CustRes_isEnabled,CustRes_height,CustRes_width,"waifu2x-converter",true,VideoClipsFolderPath,VideoClipsFolderName,ui->groupBox_FrameInterpolation->isChecked(),ui->spinBox_MultipleOfFPS_VFI->value()); + //======== + } + /*==================================== + 提取音频 + ======================================*/ + if(!QFile::exists(AudioPath)) + { + video_get_audio(video_mp4_fullpath,AudioPath); + } + //================================== 开始分段处理视频 ================================================= + int StartTime = 0;//起始时间(秒) + int VideoDuration = video_get_duration(video_mp4_fullpath); + bool isSplitComplete = false; + bool isScaleComplete = false; + /* + ============================================ + 开始之前先读取进度 + ============================================ + */ + int OLD_SegmentDuration=-1; + bool read_OLD_SegmentDuration =false; + int LastVideoClipNo = -1; + if(QFile::exists(VideoConfiguration_fullPath)) + { + QSettings *configIniRead = new QSettings(VideoConfiguration_fullPath, QSettings::IniFormat); + configIniRead->setIniCodec(QTextCodec::codecForName("UTF-8")); + //=================== 加载进度 ========================= + StartTime = configIniRead->value("/Progress/StartTime").toInt(); + isSplitComplete = configIniRead->value("/Progress/isSplitComplete").toBool(); + isScaleComplete = configIniRead->value("/Progress/isScaleComplete").toBool(); + OLD_SegmentDuration = configIniRead->value("/Progress/OLDSegmentDuration").toInt(); + LastVideoClipNo = configIniRead->value("/Progress/LastVideoClipNo").toInt(); + } + if(OLD_SegmentDuration>0) + { + read_OLD_SegmentDuration = true; + } + /* + 加载进度条 + */ + int SegmentDuration_tmp_progressbar = 0; + if(read_OLD_SegmentDuration) + { + SegmentDuration_tmp_progressbar = OLD_SegmentDuration; + } + else + { + SegmentDuration_tmp_progressbar = SegmentDuration; + } + if(ui->checkBox_ShowInterPro->isChecked()&&VideoDuration>SegmentDuration_tmp_progressbar) + { + emit Send_CurrentFileProgress_Start(file_name+"."+file_ext,VideoDuration); + if(StartTime>0) + { + emit Send_CurrentFileProgress_progressbar_Add_SegmentDuration(StartTime); + } + } + /* + ============================================ + 正式开始处理 + ============================================ + */ + int SegmentDuration_tmp=0; + int TimeLeft_tmp=0; + while(VideoDuration>StartTime) + { + /*========================== + 计算视频片段时间 + ==========================*/ + TimeLeft_tmp = VideoDuration-StartTime; + if((TimeLeft_tmp)>=SegmentDuration) + { + SegmentDuration_tmp = SegmentDuration; + } + else + { + SegmentDuration_tmp = TimeLeft_tmp; + } + if(read_OLD_SegmentDuration) + { + SegmentDuration_tmp = OLD_SegmentDuration; + read_OLD_SegmentDuration=false; + } + /*========================== + 拆分视频片段 + ==========================*/ + if(isSplitComplete==false) + { + if(file_isDirExist(SplitFramesFolderPath)) + { + file_DelDir(SplitFramesFolderPath); + file_mkDir(SplitFramesFolderPath); + } + else + { + file_mkDir(SplitFramesFolderPath); + } + video_video2images_ProcessBySegment(video_mp4_fullpath,SplitFramesFolderPath,StartTime,SegmentDuration_tmp); + if(waifu2x_STOP) + { + emit Send_Table_video_ChangeStatus_rowNumInt_statusQString(rowNum, "Interrupted"); + return 0;//如果启用stop位,则直接return + } + } + /*========================== + 处理视频片段的帧 + ==========================*/ + if(isScaleComplete==false) + { + //============================== 扫描获取文件名 =============================== + QStringList Frame_fileName_list = file_getFileNames_in_Folder_nofilter(SplitFramesFolderPath); + if(isSplitComplete==false) + { + if(Frame_fileName_list.isEmpty())//检查是否成功拆分为帧 + { + emit Send_TextBrowser_NewMessage(tr("Error occured when processing [")+SourceFile_fullPath+tr("]. Error: [Unable to split video into pictures.]")); + emit Send_Table_video_ChangeStatus_rowNumInt_statusQString(rowNum, "Failed"); + emit Send_progressbar_Add(); + return 0;//如果启用stop位,则直接return + } + } + /* + 记录进度 + 帧拆分成功 + */ + emit Send_video_write_Progress_ProcessBySegment(VideoConfiguration_fullPath,StartTime,true,false,SegmentDuration_tmp,LastVideoClipNo); + //============================== 放大 ======================================= + //===========建立存储放大后frame的文件夹=========== + if(isSplitComplete==false) + { + if(file_isDirExist(ScaledFramesFolderPath)) + { + file_DelDir(ScaledFramesFolderPath); + file_mkDir(ScaledFramesFolderPath); + } + else + { + file_mkDir(ScaledFramesFolderPath); + } + } + //==========开始放大========================== + FileProgressWatch_isEnabled=true; + QFuture FileProgressWatch_QFuture = QtConcurrent::run(this, &MainWindow::CurrentFileProgress_WatchFolderFileNum_Textbrower, SourceFile_fullPath,ScaledFramesFolderPath,Frame_fileName_list.size()+file_getFileNames_in_Folder_nofilter(ScaledFramesFolderPath).size()); + if(ui->checkBox_ShowInterPro->isChecked()==false) + { + FileProgressWatch_isEnabled=false; + FileProgressWatch_QFuture.cancel(); + } + //=======获取显卡信息======== + int NumOfGPU = 1; + if(ui->checkBox_MultiGPU_Waifu2xConverter->isChecked()==true) + { + NumOfGPU=0; + for (int i=0; i GPUInfo_tmp = GPUIDs_List_MultiGPU_Waifu2xConverter.at(i); + if(GPUInfo_tmp["isEnabled"] == "true") + { + NumOfGPU++; + } + } + } + //============创建显卡文件夹=========== + QStringList GPU_SplitFramesFolderPath_List; + for(int i = 0; i < NumOfGPU; i++) + { + QString GPU_SplitFramesFolderPath = SplitFramesFolderPath+"/"+"GPU_"+QString::number(i); + if(file_isDirExist(GPU_SplitFramesFolderPath)==false) + { + file_DelDir(GPU_SplitFramesFolderPath); + file_mkDir(GPU_SplitFramesFolderPath); + } + else + { + file_mkDir(GPU_SplitFramesFolderPath); + } + GPU_SplitFramesFolderPath_List.append(GPU_SplitFramesFolderPath); + } + int TotalFramesNum = Frame_fileName_list.size(); + int FramesNumForEachGPU = TotalFramesNum/NumOfGPU; + if(FramesNumForEachGPU<1)FramesNumForEachGPU=1; + int start_num=0; + for(int x = 0; x < GPU_SplitFramesFolderPath_List.size(); x++) + { + if(x==GPU_SplitFramesFolderPath_List.size()-1)FramesNumForEachGPU=TotalFramesNum; + QStringList file_waitformove = Frame_fileName_list.mid(start_num,FramesNumForEachGPU); + for(int i = 0; i < file_waitformove.size(); i++) + { + QString FileName = file_waitformove.at(i); + QFile::rename(SplitFramesFolderPath+"/"+FileName,GPU_SplitFramesFolderPath_List.at(x)+"/"+FileName); + } + start_num+=FramesNumForEachGPU; + } + //========================= + bool Frame_failed = false;//放大失败标志 + QMap Sub_Thread_info; + Sub_Thread_info["ScaledFramesFolderPath"]=ScaledFramesFolderPath; + Sub_Thread_info["Denoise_cmd"] = " --noise-level " + QString::number(DenoiseLevel, 10); + if(CustRes_isEnabled == true) + { + Sub_Thread_info["ScaleRatio"] = QString("%1").arg(CustRes_CalNewScaleRatio(video_mp4_fullpath,CustRes_height,CustRes_width)); + } + else + { + Sub_Thread_info["ScaleRatio"] = QString("%1").arg(ScaleRatio); + } + //========================= + for(int i = 0; i < GPU_SplitFramesFolderPath_List.size(); i++) + { + Sub_Thread_info["SplitFramesFolderPath"]=GPU_SplitFramesFolderPath_List.at(i); + mutex_SubThreadNumRunning.lock(); + Sub_video_ThreadNumRunning++; + mutex_SubThreadNumRunning.unlock(); + QtConcurrent::run(this,&MainWindow::Waifu2x_Converter_Video_scale,Sub_Thread_info,&Sub_video_ThreadNumRunning,&Frame_failed); + while (Sub_video_ThreadNumRunning >= NumOfGPU) + { + Delay_msec_sleep(500); + } + if(waifu2x_STOP) + { + while (Sub_video_ThreadNumRunning > 0) + { + Delay_msec_sleep(500); + } + FileProgressWatch_isEnabled=false; + FileProgressWatch_QFuture.cancel(); + Restore_SplitFramesFolderPath(SplitFramesFolderPath,GPU_SplitFramesFolderPath_List); + emit Send_Table_video_ChangeStatus_rowNumInt_statusQString(rowNum, "Interrupted"); + return 0;//如果启用stop位,则直接return + } + if(Frame_failed) + { + FileProgressWatch_isEnabled=false; + FileProgressWatch_QFuture.cancel(); + Restore_SplitFramesFolderPath(SplitFramesFolderPath,GPU_SplitFramesFolderPath_List); + emit Send_TextBrowser_NewMessage(tr("Error occured when processing [")+SourceFile_fullPath+tr("]. Error: [Failed to scale frames.]")); + emit Send_Table_video_ChangeStatus_rowNumInt_statusQString(rowNum, "Failed"); + emit Send_progressbar_Add(); + return 0;//如果启用stop位,则直接return + } + } + while (Sub_video_ThreadNumRunning!=0) + { + Delay_msec_sleep(500); + } + FileProgressWatch_isEnabled=false; + FileProgressWatch_QFuture.cancel(); + //================ 扫描放大后的帧文件数量,判断是否放大成功 ======================= + QStringList Frame_fileName_list_scaled = file_getFileNames_in_Folder_nofilter(ScaledFramesFolderPath); + if(Frame_fileName_list_scaled.size()checkBox_ShowInterPro->isChecked()) + { + emit Send_CurrentFileProgress_progressbar_Add_SegmentDuration(SegmentDuration_tmp); + } + StartTime+=SegmentDuration_tmp; + isSplitComplete = false; + isScaleComplete = false; + LastVideoClipNo=VideoClipNo; + emit Send_video_write_Progress_ProcessBySegment(VideoConfiguration_fullPath,StartTime,false,false,-1,VideoClipNo); + } + emit Send_CurrentFileProgress_Stop(); + //====================================================== + // 组装(片段到成片) + //====================================================== + QString video_mp4_scaled_fullpath = ""; + if(CustRes_isEnabled) + { + video_mp4_scaled_fullpath = file_path+"/"+file_name+"_waifu2x_"+QString::number(CustRes_width,10)+"x"+QString::number(CustRes_height,10)+"_"+QString::number(DenoiseLevel,10)+"n"+"_"+file_ext+".mp4"; + } + else + { + video_mp4_scaled_fullpath = file_path+"/"+file_name+"_waifu2x_"+QString::number(ScaleRatio,10)+"x_"+QString::number(DenoiseLevel,10)+"n"+"_"+file_ext+".mp4"; + } + QFile::remove(video_mp4_scaled_fullpath); + video_AssembleVideoClips(VideoClipsFolderPath,VideoClipsFolderName,video_mp4_scaled_fullpath,AudioPath); + if(QFile::exists(video_mp4_scaled_fullpath)==false)//检查是否成功生成视频 + { + if(waifu2x_STOP) + { + emit Send_Table_video_ChangeStatus_rowNumInt_statusQString(rowNum, "Interrupted"); + return 0;//如果启用stop位,则直接return + } + emit Send_TextBrowser_NewMessage(tr("Error occured when processing [")+SourceFile_fullPath+tr("]. Error: [Unable to assemble video clips.]")); + emit Send_Table_video_ChangeStatus_rowNumInt_statusQString(rowNum, "Failed"); + emit Send_progressbar_Add(); + return 0;//如果启用stop位,则直接return + } + //============================== 删除缓存文件 ==================================================== + if(ui->checkBox_KeepVideoCache->isChecked()==false) + { + QFile::remove(VideoConfiguration_fullPath); + file_DelDir(SplitFramesFolderPath); + file_DelDir(VideoClipsFolderPath); + QFile::remove(AudioPath); + if(SourceFile_fullPath!=video_mp4_fullpath)QFile::remove(video_mp4_fullpath); + } + else + { + DelOriginal=false; + } + //============================= 删除原文件 & & 更新table status ============================ + if(DelOriginal) + { + if(ReplaceOriginalFile(SourceFile_fullPath,video_mp4_scaled_fullpath)==false) + { + if(QAction_checkBox_MoveToRecycleBin_checkBox_DelOriginal->isChecked()) + { + file_MoveToTrash(SourceFile_fullPath); + } + else + { + QFile::remove(SourceFile_fullPath); + } + } + emit Send_Table_video_ChangeStatus_rowNumInt_statusQString(rowNum, "Finished, original file deleted"); + } + else + { + emit Send_Table_video_ChangeStatus_rowNumInt_statusQString(rowNum, "Finished"); + } + //========== 移动到输出路径 ========= + if(ui->checkBox_OutPath_isEnabled->isChecked()) + { + MoveFileToOutputPath(video_mp4_scaled_fullpath,SourceFile_fullPath); + } + //============================ 更新进度条 ================================= + emit Send_progressbar_Add(); + //=========================== ============================== + return 0; +} + + +int MainWindow::Waifu2x_Converter_Video_scale(QMap Sub_Thread_info,int *Sub_video_ThreadNumRunning,bool *Frame_failed) +{ + bool AllFinished; + QString SplitFramesFolderPath = Sub_Thread_info["SplitFramesFolderPath"]; + QString ScaledFramesFolderPath = Sub_Thread_info["ScaledFramesFolderPath"]; + //=========== + QString Denoise_cmd = Sub_Thread_info["Denoise_cmd"]; + //======================================================================== + QStringList InputFilesNameList = file_getFileNames_in_Folder_nofilter(SplitFramesFolderPath); + QStringList OutPutFilesFullPathList; + for(int i=0; ispinBox_retry->value()+ForceRetryCount); retry++) + { + Waifu2x->start(cmd); + while(!Waifu2x->waitForStarted(100)&&!QProcess_stop) {} + while(!Waifu2x->waitForFinished(500)&&!QProcess_stop) + { + if(waifu2x_STOP) + { + QStringList FinfishedFileList = WaitForEngineIO(OutPutFilesFullPathList); + Waifu2x->close(); + //============ + QString file_fullpath_tmp; + for(int i=0; ispinBox_retry->value()+(ForceRetryCount-1))break; + Delay_sec_sleep(5); + emit Send_TextBrowser_NewMessage(tr("Automatic retry, please wait.")); + AllFinished=false; + break; + } + } + if(AllFinished)break; + } + //========= + AllFinished = true; + for(int i=0; ipushButton_DumpProcessorList_converter->setText(tr("Loading, please wait...")); + //===== + pushButton_Start_setEnabled_self(0); + ui->pushButton_DetectGPU->setEnabled(0); + ui->pushButton_DetectGPUID_srmd->setEnabled(0); + ui->pushButton_DumpProcessorList_converter->setEnabled(0); + ui->pushButton_ListGPUs_Anime4k->setEnabled(0); + ui->pushButton_compatibilityTest->setEnabled(0); + ui->pushButton_DetectGPU_RealsrNCNNVulkan->setEnabled(0); + QtConcurrent::run(this, &MainWindow::Waifu2x_DumpProcessorList_converter); +} + +int MainWindow::Waifu2x_DumpProcessorList_converter() +{ + //============================ + // 调用converter输出列表 + //============================ + Core_num = 0; + emit Send_TextBrowser_NewMessage(tr("Detecting available Processor, please wait.")); + QString Waifu2x_folder_path = Current_Path + "/waifu2x-converter"; + QString program = Waifu2x_folder_path + "/waifu2x-converter-cpp_waifu2xEX.exe"; + QProcess *Waifu2x = new QProcess(); + QString cmd = "\"" + program + "\"" + " -l "; + Waifu2x->start(cmd); + while(!Waifu2x->waitForStarted(100)&&!QProcess_stop) {} + while(!Waifu2x->waitForFinished(100)&&!QProcess_stop) {} + QString waifu2x_stdOut = Waifu2x->readAllStandardOutput(); + Core_num = waifu2x_stdOut.count("num_core"); + emit Send_TextBrowser_NewMessage(tr("\nWaifu2x-converter processor list:\n")+waifu2x_stdOut.trimmed()); + //==================================================================== + // 获取到列表后, 对列表内处理器执行测试确认是否真的可用 + //==================================================================== + emit Send_TextBrowser_NewMessage(tr("Please wait while testing the processor.")); + //======== + Available_ProcessorList_converter.clear(); + //======== + QString InputPath = Current_Path + "/Compatibility_Test/Compatibility_Test.jpg"; + QString OutputPath = Current_Path + "/Compatibility_Test/res.png"; + QFile::remove(OutputPath); + //============== + QString model_path= Waifu2x_folder_path + "/models_rgb"; + //========= + int Processor_ID=0; + //========= + for(int i = 0; istart(cmd); + while(!Waifu2x->waitForStarted(100)&&!QProcess_stop) {} + while(!Waifu2x->waitForFinished(100)&&!QProcess_stop) {} + if(QFile::exists(OutputPath)) + { + Available_ProcessorList_converter.append(QString::number(Processor_ID,10)); + Processor_ID++; + QFile::remove(OutputPath); + } + } + QFile::remove(OutputPath); + //==================== + emit Send_TextBrowser_NewMessage(tr("Detection is complete!")); + emit Send_Waifu2x_DumpProcessorList_converter_finished(); + return 0; +} +int MainWindow::Waifu2x_DumpProcessorList_converter_finished() +{ + pushButton_Start_setEnabled_self(1); + ui->pushButton_DetectGPU->setEnabled(1); + ui->pushButton_compatibilityTest->setEnabled(1); + ui->pushButton_DetectGPUID_srmd->setEnabled(1); + ui->pushButton_DumpProcessorList_converter->setEnabled(1); + on_checkBox_SpecifyGPU_Anime4k_stateChanged(1); + ui->pushButton_DetectGPU_RealsrNCNNVulkan->setEnabled(1); + //=========================== + GPUIDs_List_MultiGPU_Waifu2xConverter.clear(); + ui->comboBox_GPUIDs_MultiGPU_Waifu2xConverter->clear(); + //=== + ui->comboBox_TargetProcessor_converter->clear(); + ui->comboBox_TargetProcessor_converter->addItem("auto"); + if(!Available_ProcessorList_converter.isEmpty()) + { + for(int i=0; icomboBox_TargetProcessor_converter->addItem(Available_ProcessorList_converter.at(i)); + AddGPU_MultiGPU_Waifu2xConverter(Available_ProcessorList_converter.at(i)); + } + } + //===== + ui->pushButton_DumpProcessorList_converter->setText(tr("Dump processor list")); + //===== + return 0; +} + +void MainWindow::on_comboBox_TargetProcessor_converter_currentIndexChanged(int index) +{ + if(ui->comboBox_TargetProcessor_converter->currentText()!="auto") + { + Processor_converter_STR = " -p "+ui->comboBox_TargetProcessor_converter->currentText()+" "; + } + else + { + Processor_converter_STR=""; + } +} +/* +预读取引擎设定 +*/ +QString MainWindow::Waifu2xConverter_PreLoad_Settings() +{ + QString Waifu2xConverter_Settings_str = " "; + //===== + if(ui->checkBox_MultiGPU_Waifu2xConverter->isChecked()==false) + { + //==========单显卡========== + //Processor ID + if(ui->comboBox_TargetProcessor_converter->currentText()!="auto") + { + Waifu2xConverter_Settings_str.append("-p "+ui->comboBox_TargetProcessor_converter->currentText()+" "); + } + //block-size + Waifu2xConverter_Settings_str.append("--block-size "+QString::number(ui->spinBox_BlockSize_converter->value(), 10)+" "); + } + //model_path + QString model_path = Current_Path + "/waifu2x-converter/models_rgb"; + Waifu2xConverter_Settings_str.append("--model-dir \""+model_path+"\" "); + //Disable GPU + if(ui->checkBox_DisableGPU_converter->isChecked())Waifu2xConverter_Settings_str.append("--disable-gpu "); + //Force OpenCL + if(ui->checkBox_ForceOpenCL_converter->isChecked())Waifu2xConverter_Settings_str.append("--force-OpenCL "); + //TTA + if(ui->checkBox_TTA_converter->isChecked()) + { + Waifu2xConverter_Settings_str.append("-t 1 "); + } + else + { + Waifu2xConverter_Settings_str.append("-t 0 "); + } + //======================================= + return Waifu2xConverter_Settings_str; +} + +/* +Waifu2x-Converter +读取设定 +*/ +QString MainWindow::Waifu2xConverter_ReadSettings() +{ + QString Waifu2xConverter_Settings_str = ""; + //===== + Waifu2xConverter_Settings_str.append(Waifu2xConverter_PreLoad_Settings_Str); + if(ui->checkBox_MultiGPU_Waifu2xConverter->isChecked()) + { + //==========多显卡========== + QMap GPUInfo = Waifu2xConverter_MultiGPU(); + //GPU ID + Waifu2xConverter_Settings_str.append("-p "+GPUInfo["ID"]+" "); + //Tile Size + Waifu2xConverter_Settings_str.append("--block-size "+GPUInfo["TileSize"]+" "); + } + //======================================= + return Waifu2xConverter_Settings_str; +} + +QMap MainWindow::Waifu2xConverter_MultiGPU() +{ + MultiGPU_QMutex_Waifu2xConverter.lock(); + //==== + int MAX_GPU_ID_Waifu2xConverter = GPUIDs_List_MultiGPU_Waifu2xConverter.size()-1; + if(GPU_ID_Waifu2xConverter_MultiGPU>MAX_GPU_ID_Waifu2xConverter) + { + GPU_ID_Waifu2xConverter_MultiGPU=0; + } + //====== + QMap GPUInfo; + do + { + GPUInfo = GPUIDs_List_MultiGPU_Waifu2xConverter.at(GPU_ID_Waifu2xConverter_MultiGPU); + if(GPUInfo["isEnabled"] != "true") + { + GPU_ID_Waifu2xConverter_MultiGPU++; + if(GPU_ID_Waifu2xConverter_MultiGPU>MAX_GPU_ID_Waifu2xConverter) + { + GPU_ID_Waifu2xConverter_MultiGPU=0; + } + } + else + { + break; + } + } + while(true); + //====== + GPU_ID_Waifu2xConverter_MultiGPU++; + if(GPU_ID_Waifu2xConverter_MultiGPU>MAX_GPU_ID_Waifu2xConverter) + { + GPU_ID_Waifu2xConverter_MultiGPU=0; + } + //====== + MultiGPU_QMutex_Waifu2xConverter.unlock(); + return GPUInfo; +} + +void MainWindow::AddGPU_MultiGPU_Waifu2xConverter(QString GPUID) +{ + QMap GPUInfo; + GPUInfo["ID"] = GPUID; + GPUInfo["isEnabled"] = "true"; + GPUInfo["TileSize"] = "300"; + GPUIDs_List_MultiGPU_Waifu2xConverter.append(GPUInfo); + ui->comboBox_GPUIDs_MultiGPU_Waifu2xConverter->addItem(GPUID); + ui->comboBox_GPUIDs_MultiGPU_Waifu2xConverter->setCurrentIndex(0); +} + +void MainWindow::on_checkBox_MultiGPU_Waifu2xConverter_stateChanged(int arg1) +{ + if(ui->checkBox_MultiGPU_Waifu2xConverter->isChecked()) + { + ui->comboBox_TargetProcessor_converter->setEnabled(0); + ui->frame_BlockSize_W2xConverter->setEnabled(0); + ui->groupBox_GPUSettings_MultiGPU_Waifu2xConverter->setEnabled(1); + } + else + { + ui->comboBox_TargetProcessor_converter->setEnabled(1); + ui->frame_BlockSize_W2xConverter->setEnabled(1); + ui->groupBox_GPUSettings_MultiGPU_Waifu2xConverter->setEnabled(0); + } +} + +void MainWindow::on_checkBox_MultiGPU_Waifu2xConverter_clicked() +{ + if(ui->checkBox_MultiGPU_Waifu2xConverter->isChecked()) + { + if(GPUIDs_List_MultiGPU_Waifu2xConverter.size()==0) + { + QMessageBox *MSG = new QMessageBox(); + MSG->setWindowTitle(tr("Notification")); + MSG->setText(tr("Please dump processor list before enable Multi-Processor.")); + MSG->setIcon(QMessageBox::Information); + MSG->setModal(true); + MSG->show(); + ui->checkBox_MultiGPU_Waifu2xConverter->setChecked(0); + return; + } + if(GPUIDs_List_MultiGPU_Waifu2xConverter.size()<2) + { + QMessageBox *MSG = new QMessageBox(); + MSG->setWindowTitle(tr("Error")); + MSG->setText(tr("Insufficient number of available Processors.")); + MSG->setIcon(QMessageBox::Warning); + MSG->setModal(true); + MSG->show(); + ui->checkBox_MultiGPU_Waifu2xConverter->setChecked(0); + return; + } + } +} + +void MainWindow::on_comboBox_GPUIDs_MultiGPU_Waifu2xConverter_currentIndexChanged(int index) +{ + if(ui->comboBox_GPUIDs_MultiGPU_Waifu2xConverter->count()==0) + { + return; + } + QMap GPUInfo=GPUIDs_List_MultiGPU_Waifu2xConverter.at(ui->comboBox_GPUIDs_MultiGPU_Waifu2xConverter->currentIndex()); + ui->checkBox_isEnable_CurrentGPU_MultiGPU_Waifu2xConverter->setChecked(GPUInfo["isEnabled"] == "true"); + ui->spinBox_TileSize_CurrentGPU_MultiGPU_Waifu2xConverter->setValue(GPUInfo["TileSize"].toInt()); +} + +void MainWindow::on_checkBox_isEnable_CurrentGPU_MultiGPU_Waifu2xConverter_clicked() +{ + QMap GPUInfo=GPUIDs_List_MultiGPU_Waifu2xConverter.at(ui->comboBox_GPUIDs_MultiGPU_Waifu2xConverter->currentIndex()); + if(ui->checkBox_isEnable_CurrentGPU_MultiGPU_Waifu2xConverter->isChecked()) + { + GPUInfo["isEnabled"] = "true"; + } + else + { + GPUInfo["isEnabled"] = "false"; + } + GPUIDs_List_MultiGPU_Waifu2xConverter.replace(ui->comboBox_GPUIDs_MultiGPU_Waifu2xConverter->currentIndex(),GPUInfo); + int enabledGPUs = 0; + for (int i=0; i GPUInfo_tmp = GPUIDs_List_MultiGPU_Waifu2xConverter.at(i); + if(GPUInfo_tmp["isEnabled"] == "true") + { + enabledGPUs++; + } + } + if(enabledGPUs<2) + { + QMap GPUInfo=GPUIDs_List_MultiGPU_Waifu2xConverter.at(ui->comboBox_GPUIDs_MultiGPU_Waifu2xConverter->currentIndex()); + GPUInfo["isEnabled"] = "true"; + GPUIDs_List_MultiGPU_Waifu2xConverter.replace(ui->comboBox_GPUIDs_MultiGPU_Waifu2xConverter->currentIndex(),GPUInfo); + ui->checkBox_isEnable_CurrentGPU_MultiGPU_Waifu2xConverter->setChecked(1); + QMessageBox *MSG = new QMessageBox(); + MSG->setWindowTitle(tr("Warning")); + MSG->setText(tr("At least 2 Processors need to be enabled !!")); + MSG->setIcon(QMessageBox::Warning); + MSG->setModal(true); + MSG->show(); + } +} + +void MainWindow::on_spinBox_TileSize_CurrentGPU_MultiGPU_Waifu2xConverter_valueChanged(int arg1) +{ + QMap GPUInfo=GPUIDs_List_MultiGPU_Waifu2xConverter.at(ui->comboBox_GPUIDs_MultiGPU_Waifu2xConverter->currentIndex()); + GPUInfo["TileSize"] = QString::number(ui->spinBox_TileSize_CurrentGPU_MultiGPU_Waifu2xConverter->value(),10); + GPUIDs_List_MultiGPU_Waifu2xConverter.replace(ui->comboBox_GPUIDs_MultiGPU_Waifu2xConverter->currentIndex(),GPUInfo); +} + +void MainWindow::on_pushButton_ShowMultiGPUSettings_Waifu2xConverter_clicked() +{ + int Max_GPU_ID = GPUIDs_List_MultiGPU_Waifu2xConverter.size(); + GPUIDs_List_MultiGPU_Waifu2xConverter.size(); + QString MultiGPUSettings_str=""; + for(int GPU_ID=0; GPU_ID GPUInfo = GPUIDs_List_MultiGPU_Waifu2xConverter.at(GPU_ID); + if(GPUInfo["isEnabled"] != "true") + { + continue; + } + else + { + MultiGPUSettings_str.append(tr("Processor ID:")+"["+GPUInfo["ID"]+"] | "+tr("Block size:")+"["+GPUInfo["TileSize"]+"]\n\n"); + } + } + //========= + QMessageBox *MSG = new QMessageBox(); + MSG->setWindowTitle(tr("Current Multi-GPU settings")); + MSG->setText(MultiGPUSettings_str); + MSG->setIcon(QMessageBox::Information); + MSG->setModal(true); + MSG->show(); +} +/* +W2xConverter 块大小调整按钮 +*/ +void MainWindow::on_pushButton_BlockSize_Add_W2xConverter_clicked() +{ + ui->spinBox_BlockSize_converter->setValue(AddTileSize_NCNNVulkan_Converter(ui->spinBox_BlockSize_converter->value())); +} + +void MainWindow::on_pushButton_BlockSize_Minus_W2xConverter_clicked() +{ + ui->spinBox_BlockSize_converter->setValue(MinusTileSize_NCNNVulkan_Converter(ui->spinBox_BlockSize_converter->value())); +} +/* +放大APNG + +Waifu2x-Converter +*/ +bool MainWindow::APNG_Waifu2xConverter(QString splitFramesFolder,QString scaledFramesFolder,QString sourceFileFullPath,QStringList framesFileName_qStrList,QString resultFileFullPath) +{ + //生成文件夹 + file_DelDir(scaledFramesFolder); + file_mkDir(scaledFramesFolder); + //============================================================ + //开始放大 + emit Send_CurrentFileProgress_Start(file_getBaseName(sourceFileFullPath)+"."+sourceFileFullPath.split(".").last(),framesFileName_qStrList.size()); + FileProgressWatch_isEnabled=true; + QFuture FileProgressWatch_QFuture = QtConcurrent::run(this, &MainWindow::CurrentFileProgress_WatchFolderFileNum, scaledFramesFolder);//启动waifu2x 主线程 + if(ui->checkBox_ShowInterPro->isChecked()==false) + { + FileProgressWatch_isEnabled=false; + FileProgressWatch_QFuture.cancel(); + emit Send_CurrentFileProgress_Stop(); + } + //=======获取显卡信息======== + int NumOfGPU = 1; + if(ui->checkBox_MultiGPU_Waifu2xConverter->isChecked()==true) + { + NumOfGPU=0; + for (int i=0; i GPUInfo_tmp = GPUIDs_List_MultiGPU_Waifu2xConverter.at(i); + if(GPUInfo_tmp["isEnabled"] == "true") + { + NumOfGPU++; + } + } + } + //============创建显卡文件夹=========== + QStringList GPU_splitFramesFolder_List; + for(int i = 0; i < NumOfGPU; i++) + { + QString GPU_splitFramesFolder = splitFramesFolder+"/"+"GPU_"+QString::number(i); + if(file_isDirExist(GPU_splitFramesFolder)) + { + file_DelDir(GPU_splitFramesFolder); + file_mkDir(GPU_splitFramesFolder); + } + else + { + file_mkDir(GPU_splitFramesFolder); + } + GPU_splitFramesFolder_List.append(GPU_splitFramesFolder); + } + int TotalFramesNum = framesFileName_qStrList.size(); + int FramesNumForEachGPU = TotalFramesNum/NumOfGPU; + if(FramesNumForEachGPU<1)FramesNumForEachGPU=1; + int start_num=0; + for(int x = 0; x < GPU_splitFramesFolder_List.size(); x++) + { + if(x==GPU_splitFramesFolder_List.size()-1)FramesNumForEachGPU=TotalFramesNum; + QStringList file_waitformove = framesFileName_qStrList.mid(start_num,FramesNumForEachGPU); + for(int i = 0; i < file_waitformove.size(); i++) + { + QString FileName = file_waitformove.at(i); + QFile::rename(splitFramesFolder+"/"+FileName,GPU_splitFramesFolder_List.at(x)+"/"+FileName); + } + start_num+=FramesNumForEachGPU; + } + //========================= + bool Frame_failed = false;//放大失败标志 + //==== + QMap Sub_Thread_info; + Sub_Thread_info["scaledFramesFolder"]= scaledFramesFolder; + Sub_Thread_info["Denoise_cmd"] = " --noise-level " + QString::number(ui->spinBox_DenoiseLevel_gif->value(), 10); + if(CustRes_isContained(sourceFileFullPath)) + { + QMap Res_map = CustRes_getResMap(sourceFileFullPath);//res_map["fullpath"],["height"],["width"] + Sub_Thread_info["ScaleRatio"] = QString("%1").arg(CustRes_CalNewScaleRatio(sourceFileFullPath,Res_map["height"].toInt(),Res_map["width"].toInt())); + } + else + { + Sub_Thread_info["ScaleRatio"] = QString("%1").arg(qRound(ui->doubleSpinBox_ScaleRatio_gif->value())); + } + //========================= + int Sub_gif_ThreadNumRunning = 0; + for(int i = 0; i < GPU_splitFramesFolder_List.size(); i++) + { + Sub_Thread_info["splitFramesFolder"]=GPU_splitFramesFolder_List.at(i); + mutex_SubThreadNumRunning.lock(); + Sub_gif_ThreadNumRunning++; + mutex_SubThreadNumRunning.unlock(); + QtConcurrent::run(this,&MainWindow::Waifu2x_Converter_APNG_scale,Sub_Thread_info,&Sub_gif_ThreadNumRunning,&Frame_failed); + while (Sub_gif_ThreadNumRunning >= NumOfGPU) + { + Delay_msec_sleep(500); + } + if(waifu2x_STOP) + { + while (Sub_gif_ThreadNumRunning > 0) + { + Delay_msec_sleep(500); + } + FileProgressWatch_isEnabled=false; + FileProgressWatch_QFuture.cancel(); + return false; + } + if(Frame_failed) + { + FileProgressWatch_isEnabled=false; + FileProgressWatch_QFuture.cancel(); + emit Send_TextBrowser_NewMessage(tr("Error occured when processing [")+sourceFileFullPath+tr("]. Error: [Failed to scale frames.]")); + return false; + } + } + while (Sub_gif_ThreadNumRunning!=0) + { + Delay_msec_sleep(500); + } + FileProgressWatch_isEnabled=false; + FileProgressWatch_QFuture.cancel(); + emit Send_CurrentFileProgress_Stop(); + //======================= 检查是否成功放大所有帧 =========================== + if(framesFileName_qStrList.size() != file_getFileNames_in_Folder_nofilter(scaledFramesFolder).size()) + { + emit Send_TextBrowser_NewMessage(tr("Error occured when processing [")+sourceFileFullPath+tr("]. Error: [Failed to scale frames.]")); + return false; + } + //============================================================ + //组装apng + APNG_Frames2APNG(sourceFileFullPath, scaledFramesFolder, resultFileFullPath, false); + return true; +} +int MainWindow::Waifu2x_Converter_APNG_scale(QMap Sub_Thread_info,int *Sub_gif_ThreadNumRunning,bool *Frame_failed) +{ + bool AllFinished; + QString splitFramesFolder = Sub_Thread_info["splitFramesFolder"]; + QString scaledFramesFolder = Sub_Thread_info["scaledFramesFolder"]; + //=========== + QString Denoise_cmd = Sub_Thread_info["Denoise_cmd"]; + //======================================================================== + QStringList InputFilesNameList = file_getFileNames_in_Folder_nofilter(splitFramesFolder); + QStringList OutPutFilesFullPathList; + for(int i=0; ispinBox_retry->value()+ForceRetryCount); retry++) + { + Waifu2x->start(cmd); + while(!Waifu2x->waitForStarted(100)&&!QProcess_stop) {} + while(!Waifu2x->waitForFinished(500)&&!QProcess_stop) + { + if(waifu2x_STOP) + { + Waifu2x->close(); + mutex_SubThreadNumRunning.lock(); + *Sub_gif_ThreadNumRunning=*Sub_gif_ThreadNumRunning-1; + mutex_SubThreadNumRunning.unlock(); + return 0; + } + } + AllFinished = true; + for(int i=0; ispinBox_retry->value()+(ForceRetryCount-1))break; + Delay_sec_sleep(5); + emit Send_TextBrowser_NewMessage(tr("Automatic retry, please wait.")); + AllFinished=false; + break; + } + } + if(AllFinished)break; + } + //========= + AllFinished = true; + for(int i=0; i. - - My Github homepage: https://github.com/AaronFeng753 -*/ - -#include "mainwindow.h" -#include "ui_mainwindow.h" - -int MainWindow::Waifu2x_NCNN_Vulkan_Image(int rowNum,bool ReProcess_MissingAlphaChannel) -{ - //============================= 读取设置 ================================ - int DenoiseLevel = ui->spinBox_DenoiseLevel_image->value(); - bool DelOriginal = (ui->checkBox_DelOriginal->isChecked()||ui->checkBox_ReplaceOriginalFile->isChecked()); - QString OutPutPath_Final =""; - //========================= 拆解map得到参数 ============================= - //将状态设定到处理中 - emit Send_Table_image_ChangeStatus_rowNumInt_statusQString(rowNum, "Processing"); - //得到原文件路径 - QString SourceFile_fullPath = Table_model_image->item(rowNum,2)->text(); - if(!QFile::exists(SourceFile_fullPath))//判断源文件是否存在 - { - emit Send_TextBrowser_NewMessage(tr("Error occured when processing [")+SourceFile_fullPath+tr("]. Error: [File does not exist.]")); - emit Send_Table_image_ChangeStatus_rowNumInt_statusQString(rowNum, "Failed"); - emit Send_progressbar_Add(); - mutex_ThreadNumRunning.lock(); - ThreadNumRunning--; - mutex_ThreadNumRunning.unlock();//线程数量统计-1 - return 0; - } - //========= 转换到 PNG ========= - QString SourceFile_fullPath_Original = SourceFile_fullPath; - SourceFile_fullPath = Imgae_PreProcess(SourceFile_fullPath_Original,ReProcess_MissingAlphaChannel); - //=============== - int ScaleRatio=2; - bool CustRes_isEnabled = false; - int CustRes_height=0; - int CustRes_width=0; - //检查是是否有自定义分辨率 - if(CustRes_isContained(SourceFile_fullPath_Original)) - { - CustRes_isEnabled=true; - QMap Res_map = CustRes_getResMap(SourceFile_fullPath_Original);//res_map["fullpath"],["height"],["width"] - ScaleRatio = CustRes_CalNewScaleRatio(SourceFile_fullPath,Res_map["height"].toInt(),Res_map["width"].toInt()); - CustRes_height=Res_map["height"].toInt(); - CustRes_width=Res_map["width"].toInt(); - } - else - { - double ScaleRatio_double_tmp = ui->doubleSpinBox_ScaleRatio_image->value(); - if(ScaleRatio_double_tmp == (int)ScaleRatio_double_tmp) - { - ScaleRatio = qRound(ScaleRatio_double_tmp); - } - else - { - CustRes_isEnabled=true; - QMap Res_map = DoubleScaleRatio_Cal_NewScaleRatio_NewHW(SourceFile_fullPath,ScaleRatio_double_tmp); - //==== - if(Res_map.isEmpty()) - { - emit Send_TextBrowser_NewMessage(tr("Error occured when processing [")+SourceFile_fullPath+tr("]. Error: [Unable to read the resolution of the source file.]")); - emit Send_Table_image_ChangeStatus_rowNumInt_statusQString(rowNum, "Failed"); - emit Send_progressbar_Add(); - mutex_ThreadNumRunning.lock(); - ThreadNumRunning--; - mutex_ThreadNumRunning.unlock();//线程数量统计-1 - return 0; - } - //==== - ScaleRatio = Res_map["ScaleRatio"].toInt(); - CustRes_height = Res_map["Height_new"].toInt(); - CustRes_width = Res_map["width_new"].toInt(); - } - } - //=============== - QFileInfo fileinfo(SourceFile_fullPath); - QString file_name = file_getBaseName(SourceFile_fullPath); - QString file_ext = fileinfo.suffix(); - QString file_path = file_getFolderPath(fileinfo); - QString OutPut_Path = file_path + "/" + file_name + "_waifu2x_"+QString::number(ScaleRatio, 10)+"x_"+QString::number(DenoiseLevel, 10)+"n_"+file_ext+".png"; - //============================== 放大 ======================================= - QProcess *Waifu2x = new QProcess(); - QString Waifu2x_folder_path = Waifu2x_ncnn_vulkan_FolderPath; - QString program = Waifu2x_ncnn_vulkan_ProgramPath; - //========== - int ScaleRatio_tmp=Calculate_Temporary_ScaleRatio_W2xNCNNVulkan(ScaleRatio); - //====== - QString InputPath_tmp = SourceFile_fullPath; - QString OutputPath_tmp =""; - int DenoiseLevel_tmp = DenoiseLevel; - QString ErrorMSG=""; - QString StanderMSG=""; - QString cmd=""; - //====== - for(int retry=0; retry<(ui->spinBox_retry->value()+ForceRetryCount); retry++) - { - bool waifu2x_qprocess_failed = false; - InputPath_tmp = SourceFile_fullPath; - OutputPath_tmp =""; - DenoiseLevel_tmp = DenoiseLevel; - for(int i=2; i<=ScaleRatio_tmp; i*=2) - { - ErrorMSG=""; - StanderMSG=""; - //========== - OutputPath_tmp = file_path + "/" + file_name + "_waifu2x_"+QString::number(i, 10)+"x_"+QString::number(DenoiseLevel, 10)+"n_"+file_ext+".png"; - cmd = "\"" + program + "\"" + " -i " + "\"" + InputPath_tmp + "\"" + " -o " + "\"" + OutputPath_tmp + "\"" + " -s " + "2" + " -n " + QString::number(DenoiseLevel_tmp, 10) + Waifu2x_NCNN_Vulkan_ReadSettings(); - Waifu2x->start(cmd); - while(!Waifu2x->waitForStarted(100)&&!QProcess_stop) {} - while(!Waifu2x->waitForFinished(500)&&!QProcess_stop) - { - if(waifu2x_STOP) - { - Waifu2x->close(); - if(i>2) - { - QFile::remove(InputPath_tmp); - } - QFile::remove(OutputPath_tmp); - emit Send_Table_image_ChangeStatus_rowNumInt_statusQString(rowNum, "Interrupted"); - mutex_ThreadNumRunning.lock(); - ThreadNumRunning--; - mutex_ThreadNumRunning.unlock(); - return 0; - } - ErrorMSG.append(Waifu2x->readAllStandardError().toLower()); - StanderMSG.append(Waifu2x->readAllStandardOutput().toLower()); - if(ErrorMSG.contains("failed")||StanderMSG.contains("failed")) - { - waifu2x_qprocess_failed = true; - Waifu2x->close(); - if(i>2) - { - QFile::remove(InputPath_tmp); - } - QFile::remove(OutputPath_tmp); - break; - } - } - //=============== - if(waifu2x_qprocess_failed)break; - //=============== - ErrorMSG.append(Waifu2x->readAllStandardError().toLower()); - StanderMSG.append(Waifu2x->readAllStandardOutput().toLower()); - if(ErrorMSG.contains("failed")||StanderMSG.contains("failed")) - { - waifu2x_qprocess_failed = true; - if(i>2) - { - QFile::remove(InputPath_tmp); - } - QFile::remove(OutputPath_tmp); - break; - } - //=============== - if(i>2) - { - QFile::remove(InputPath_tmp); - } - DenoiseLevel_tmp = -1; - InputPath_tmp = OutputPath_tmp; - } - //========= 检测是否成功,是否需要重试 ============ - if(QFile::exists(OutputPath_tmp)&&!waifu2x_qprocess_failed) - { - break; - } - else - { - QFile::remove(OutputPath_tmp); - if(retry==ui->spinBox_retry->value()+(ForceRetryCount-1))break; - emit Send_TextBrowser_NewMessage(tr("Automatic retry, please wait.")); - Delay_sec_sleep(5); - } - } - if(!QFile::exists(OutputPath_tmp)) - { - if(SourceFile_fullPath_Original!=SourceFile_fullPath) - { - QFile::remove(SourceFile_fullPath); - } - emit Send_TextBrowser_NewMessage(tr("Error occured when processing [")+SourceFile_fullPath_Original+tr("]. Error: [Unable to scale the picture.]")); - emit Send_Table_image_ChangeStatus_rowNumInt_statusQString(rowNum, "Failed"); - emit Send_progressbar_Add(); - mutex_ThreadNumRunning.lock(); - ThreadNumRunning--; - mutex_ThreadNumRunning.unlock(); - return 0; - } - OutPutPath_Final = OutputPath_tmp; - //============================ 调整大小 ==================================================== - if(ScaleRatio_tmp != ScaleRatio||CustRes_isEnabled) - { - int New_height=0; - int New_width=0; - if(CustRes_isEnabled) - { - New_height= CustRes_height; - New_width= CustRes_width; - } - else - { - QMap res_map_OriginalFile = Image_Gif_Read_Resolution(SourceFile_fullPath); - New_height = res_map_OriginalFile["height"]*ScaleRatio; - New_width = res_map_OriginalFile["width"]*ScaleRatio; - } - QImage qimage_adj(OutputPath_tmp); - //读取放大后的图片并调整大小 - QImage qimage_adj_scaled = qimage_adj.scaled(New_width,New_height,CustRes_AspectRatioMode,Qt::SmoothTransformation); - QImageWriter qimageW_adj; - qimageW_adj.setFormat("png"); - qimageW_adj.setFileName(OutPut_Path); - if(qimageW_adj.canWrite()) - { - qimageW_adj.write(qimage_adj_scaled); - } - QFile::remove(OutputPath_tmp); - if(QFile::exists(OutPut_Path)==false) - { - emit Send_TextBrowser_NewMessage(tr("Error occured when processing [")+SourceFile_fullPath+tr("]. Error: [Unable to resize the scaled picture to the target size]")); - emit Send_Table_image_ChangeStatus_rowNumInt_statusQString(rowNum, "Failed"); - emit Send_progressbar_Add(); - mutex_ThreadNumRunning.lock(); - ThreadNumRunning--; - mutex_ThreadNumRunning.unlock();//线程数量统计-1 - return 0; - } - OutPutPath_Final = OutPut_Path; - } - if(CustRes_isEnabled) - { - QString OutPut_Path_CustRes = file_path + "/" + file_name + "_waifu2x_"+QString::number(CustRes_width, 10)+"x"+QString::number(CustRes_height, 10)+"_"+QString::number(DenoiseLevel, 10)+"n_"+file_ext+".png"; - QFile::remove(OutPut_Path_CustRes); - QFile::rename(OutPut_Path,OutPut_Path_CustRes); - OutPutPath_Final = OutPut_Path_CustRes; - } - //=========================== 另存为JPG&压缩JPG =========================================== - OutPutPath_Final = SaveImageAs_FormatAndQuality(SourceFile_fullPath_Original,OutPutPath_Final,true,DenoiseLevel); - //================== 检查是否丢失了透明通道 ===================== - if(ReProcess_MissingAlphaChannel==false && ui->comboBox_version_Waifu2xNCNNVulkan->currentIndex()==0) - { - QImage QImage_source(SourceFile_fullPath_Original); - QImage QImage_Final(OutPutPath_Final); - if(QImage_source.hasAlphaChannel()==true && QImage_Final.hasAlphaChannel()==false && ui->checkBox_AutoDetectAlphaChannel->isChecked()) - { - QFile::remove(OutPutPath_Final); - emit Send_TextBrowser_NewMessage(tr("Since the Alpha channel in the resulting image is lost, this image will be reprocessed to fix it:[")+SourceFile_fullPath_Original+tr("].\nIf the reprocessing happens a lot, you should consider enable [Always pre-process images with Alpha Channel] in [Additional settings].")); - return Waifu2x_NCNN_Vulkan_Image(rowNum,true); - } - } - //============================= 删除原文件 & 更新table status ============================ - if(SourceFile_fullPath_Original!=SourceFile_fullPath) - { - QFile::remove(SourceFile_fullPath); - SourceFile_fullPath = SourceFile_fullPath_Original; - } - if(DelOriginal) - { - if(ReplaceOriginalFile(SourceFile_fullPath,OutPutPath_Final)==false) - { - if(QAction_checkBox_MoveToRecycleBin_checkBox_DelOriginal->isChecked()) - { - file_MoveToTrash(SourceFile_fullPath); - } - else - { - QFile::remove(SourceFile_fullPath); - } - } - emit Send_Table_image_ChangeStatus_rowNumInt_statusQString(rowNum, "Finished, original file deleted"); - } - else - { - emit Send_Table_image_ChangeStatus_rowNumInt_statusQString(rowNum, "Finished"); - } - //========== 移动到输出路径 ========= - if(ui->checkBox_OutPath_isEnabled->isChecked()) - { - MoveFileToOutputPath(OutPutPath_Final,SourceFile_fullPath); - } - //============================ 更新进度条 ================================= - emit Send_progressbar_Add(); - //=========================== 更新线程数量统计============================== - mutex_ThreadNumRunning.lock(); - ThreadNumRunning--; - mutex_ThreadNumRunning.unlock();//线程数量统计-1 - return 0; -} - -/* - - ============================================================================================= - ============================================================================================= - ============================= Waifu2x_NCNN_Vulkan_GIF ======================================= - ============================================================================================= - ============================================================================================= - -*/ - -int MainWindow::Waifu2x_NCNN_Vulkan_GIF(int rowNum) -{ - //============================= 读取设置 ================================ - int ScaleRatio = ui->doubleSpinBox_ScaleRatio_gif->value(); - int DenoiseLevel = ui->spinBox_DenoiseLevel_gif->value(); - bool DelOriginal = (ui->checkBox_DelOriginal->isChecked()||ui->checkBox_ReplaceOriginalFile->isChecked()); - bool OptGIF = ui->checkBox_OptGIF->isChecked(); - QString OutPutPath_Final =""; - //========================= 拆解map得到参数 ============================= - emit Send_Table_gif_ChangeStatus_rowNumInt_statusQString(rowNum, "Processing"); - QString SourceFile_fullPath = Table_model_gif->item(rowNum,2)->text(); - if(!QFile::exists(SourceFile_fullPath)) - { - emit Send_TextBrowser_NewMessage(tr("Error occured when processing [")+SourceFile_fullPath+tr("]. Error: [File does not exist.]")); - emit Send_Table_gif_ChangeStatus_rowNumInt_statusQString(rowNum, "Failed"); - emit Send_progressbar_Add(); - return 0; - } - //========================== - bool CustRes_isEnabled = false; - int CustRes_height=0; - int CustRes_width=0; - if(CustRes_isContained(SourceFile_fullPath)) - { - CustRes_isEnabled=true; - QMap Res_map = CustRes_getResMap(SourceFile_fullPath);//res_map["fullpath"],["height"],["width"] - CustRes_height=Res_map["height"].toInt(); - CustRes_width=Res_map["width"].toInt(); - } - //========================== - QFileInfo fileinfo(SourceFile_fullPath); - QString file_name = file_getBaseName(SourceFile_fullPath); - QString file_ext = fileinfo.suffix(); - QString file_path = file_getFolderPath(fileinfo); - QString ResGIFPath = file_path + "/" + file_name + "_waifu2x_"+QString::number(ScaleRatio, 10)+"x_"+QString::number(DenoiseLevel, 10)+"n.gif"; - //=========================== 获取帧时间 ==================================== - int GIF_Duration = Gif_getDuration(SourceFile_fullPath); - if(GIF_Duration==0)//检查是否成功获取duration - { - emit Send_TextBrowser_NewMessage(tr("Error occured when processing [")+SourceFile_fullPath+tr("]. Error: [Can't get Duration value of GIF file.]")); - emit Send_Table_gif_ChangeStatus_rowNumInt_statusQString(rowNum, "Failed"); - emit Send_progressbar_Add(); - return 0;//如果启用stop位,则直接return - } - //============================== 拆分 ========================================== - QString SplitFramesFolderPath = file_path+"/"+file_name+"_SplitFrames_W2xEX";//拆分后存储frame的文件夹 - Gif_splitGif(SourceFile_fullPath,SplitFramesFolderPath); - //============================== 扫描获取文件名 =============================== - QStringList Frame_fileName_list = file_getFileNames_in_Folder_nofilter(SplitFramesFolderPath); - if(Frame_fileName_list.isEmpty())//检查是否成功拆分gif - { - emit Send_TextBrowser_NewMessage(tr("Error occured when processing [")+SourceFile_fullPath+tr("]. Error: [Can't split GIF into frames.]")); - emit Send_Table_gif_ChangeStatus_rowNumInt_statusQString(rowNum, "Failed"); - file_DelDir(SplitFramesFolderPath); - emit Send_progressbar_Add(); - return 0;//如果启用stop位,则直接return - } - //===========建立存储放大后frame的文件夹=========== - QString ScaledFramesFolderPath = SplitFramesFolderPath+"/ScaledFrames_W2xEX"; - file_DelDir(ScaledFramesFolderPath); - file_mkDir(ScaledFramesFolderPath); - //==========开始放大========================== - //读取放大倍数 - int ScaleRatio_Original = 2; - if(CustRes_isEnabled == true) - { - ScaleRatio_Original = CustRes_CalNewScaleRatio(SourceFile_fullPath,CustRes_height,CustRes_width); - } - else - { - ScaleRatio_Original = ui->doubleSpinBox_ScaleRatio_gif->value(); - } - int ScaleRatio_Max=Calculate_Temporary_ScaleRatio_W2xNCNNVulkan(ScaleRatio_Original); - bool isOverScaled = (ScaleRatio_Max!=ScaleRatio_Original); - //初始化进度讯息 - int NumOfSplitFrames = Frame_fileName_list.size(); - if(ui->checkBox_ShowInterPro->isChecked()) - { - int NumOfRounds=0; - for(int ScaleRatio_Current_tmp=2; ScaleRatio_Current_tmp<=ScaleRatio_Max; ScaleRatio_Current_tmp*=2) - { - NumOfRounds++; - } - emit Send_CurrentFileProgress_Start(file_name+"."+file_ext,NumOfSplitFrames*NumOfRounds); - } - //读取配置讯息 - QString Waifu2x_NCNN_Vulkan_Settings_str = Waifu2x_NCNN_Vulkan_ReadSettings_Video_GIF(ui->spinBox_ThreadNum_gif_internal->value()); - QProcess *Waifu2x = new QProcess(); - QString program = Waifu2x_ncnn_vulkan_ProgramPath; - bool waifu2x_qprocess_failed = false; - int DenoiseLevel_tmp = DenoiseLevel; - DenoiseLevel_tmp = DenoiseLevel; - int CountFinishedRounds=0; - //==== - for(int ScaleRatio_Current_tmp=2; ScaleRatio_Current_tmp<=ScaleRatio_Max && Frame_fileName_list.isEmpty()==false; ScaleRatio_Current_tmp*=2) - { - for(int retry=0; retry<(ui->spinBox_retry->value()+ForceRetryCount); retry++) - { - QString ErrorMSG=""; - QString StanderMSG=""; - //========== - waifu2x_qprocess_failed = false; - QString cmd = "\"" + program + "\"" + " -i " + "\"" + SplitFramesFolderPath + "\"" + " -o " + "\"" + ScaledFramesFolderPath + "\"" + " -s " + "2" + " -n " + QString::number(DenoiseLevel_tmp, 10) + Waifu2x_NCNN_Vulkan_Settings_str; - Waifu2x->start(cmd); - while(!Waifu2x->waitForStarted(100)&&!QProcess_stop) {} - while(!Waifu2x->waitForFinished(650)&&!QProcess_stop) - { - if(waifu2x_STOP) - { - Waifu2x->close(); - file_DelDir(SplitFramesFolderPath); - emit Send_Table_gif_ChangeStatus_rowNumInt_statusQString(rowNum, "Interrupted"); - mutex_ThreadNumRunning.lock(); - ThreadNumRunning--; - mutex_ThreadNumRunning.unlock(); - return 0; - } - ErrorMSG.append(Waifu2x->readAllStandardError().toLower()); - StanderMSG.append(Waifu2x->readAllStandardOutput().toLower()); - if(ErrorMSG.contains("failed")||StanderMSG.contains("failed")) - { - waifu2x_qprocess_failed = true; - Waifu2x->close(); - break; - } - if(ui->checkBox_ShowInterPro->isChecked()) - { - emit Send_CurrentFileProgress_progressbar_SetFinishedValue((NumOfSplitFrames*CountFinishedRounds)+file_getFileNames_in_Folder_nofilter(ScaledFramesFolderPath).size()); - } - } - //=============== - if(waifu2x_qprocess_failed==false) - { - ErrorMSG.append(Waifu2x->readAllStandardError().toLower()); - StanderMSG.append(Waifu2x->readAllStandardOutput().toLower()); - if(ErrorMSG.contains("failed")||StanderMSG.contains("failed")) - { - waifu2x_qprocess_failed = true; - } - } - //========= 检测是否成功,是否需要重试 ============ - if((NumOfSplitFrames == file_getFileNames_in_Folder_nofilter(ScaledFramesFolderPath).size())&&!waifu2x_qprocess_failed) - { - break; - } - else - { - //失败 - file_DelDir(ScaledFramesFolderPath); - file_mkDir(ScaledFramesFolderPath); - if(retry==ui->spinBox_retry->value()+(ForceRetryCount-1))break; - emit Send_TextBrowser_NewMessage(tr("Automatic retry, please wait.")); - Delay_sec_sleep(5); - } - } - //=========== - //根据轮数修改参数 - DenoiseLevel_tmp = -1; - if(ScaleRatio_Current_tmpisChecked()) - { - file_MoveToTrash(SourceFile_fullPath); - } - else - { - QFile::remove(SourceFile_fullPath); - } - } - emit Send_Table_gif_ChangeStatus_rowNumInt_statusQString(rowNum, "Finished, original file deleted"); - } - else - { - emit Send_Table_gif_ChangeStatus_rowNumInt_statusQString(rowNum, "Finished"); - } - //========== 移动到输出路径 ========= - if(ui->checkBox_OutPath_isEnabled->isChecked()) - { - MoveFileToOutputPath(OutPutPath_Final,SourceFile_fullPath); - } - //============================ 更新进度条 ================================= - emit Send_progressbar_Add(); - //=========================== ============================== - return 0; -} - -/* - - ============================================================================================= - ============================================================================================= - ============================= Waifu2x_NCNN_Vulkan_Video ======================================= - ============================================================================================= - ============================================================================================= - - -*/ - -int MainWindow::Waifu2x_NCNN_Vulkan_Video(int rowNum) -{ - //============================= 读取设置 ================================ - int ScaleRatio = ui->doubleSpinBox_ScaleRatio_video->value(); - int DenoiseLevel = ui->spinBox_DenoiseLevel_video->value(); - bool DelOriginal = (ui->checkBox_DelOriginal->isChecked()||ui->checkBox_ReplaceOriginalFile->isChecked()); - bool isCacheExists = false; - bool isVideoConfigChanged = true; - //========================= 拆解map得到参数 ============================= - emit Send_Table_video_ChangeStatus_rowNumInt_statusQString(rowNum, "Processing"); - QString SourceFile_fullPath = Table_model_video->item(rowNum,2)->text(); - if(!QFile::exists(SourceFile_fullPath)) - { - emit Send_TextBrowser_NewMessage(tr("Error occured when processing [")+SourceFile_fullPath+tr("]. Error: [File does not exist.]")); - emit Send_Table_video_ChangeStatus_rowNumInt_statusQString(rowNum, "Failed"); - emit Send_progressbar_Add(); - return 0; - } - //========================== - QFileInfo fileinfo_SourceFile_fullPath(SourceFile_fullPath); - QString SourceFile_fullPath_BaseName = file_getBaseName(SourceFile_fullPath); - QString SourceFile_fullPath_suffix = fileinfo_SourceFile_fullPath.suffix(); - QString SourceFile_fullPath_FolderPath = file_getFolderPath(fileinfo_SourceFile_fullPath); - //=================================================================== - //生成mp4 - QString video_mp4_fullpath=video_To_CFRMp4(SourceFile_fullPath); - if(!QFile::exists(video_mp4_fullpath))//检查是否成功生成mp4 - { - emit Send_TextBrowser_NewMessage(tr("Error occured when processing [")+SourceFile_fullPath+tr("]. Error: [Cannot convert video format to mp4.]")); - emit Send_Table_video_ChangeStatus_rowNumInt_statusQString(rowNum, "Failed"); - emit Send_progressbar_Add(); - return 0;//如果启用stop位,则直接return - } - //=========== 读取自定义分辨率 =============== - bool CustRes_isEnabled = false; - int CustRes_height=0; - int CustRes_width=0; - if(CustRes_isContained(SourceFile_fullPath)) - { - CustRes_isEnabled=true; - QMap Res_map = CustRes_getResMap(SourceFile_fullPath);//res_map["fullpath"],["height"],["width"] - CustRes_height=Res_map["height"].toInt(); - CustRes_width=Res_map["width"].toInt(); - } - //================= - QString AudioPath = SourceFile_fullPath_FolderPath+"/Audio_"+SourceFile_fullPath_BaseName+"_"+SourceFile_fullPath_suffix+"_W2xEX.wav";//音频 - QString SplitFramesFolderPath = SourceFile_fullPath_FolderPath+"/"+SourceFile_fullPath_BaseName+"_"+SourceFile_fullPath_suffix+"_SplitFrames_W2xEX";//拆分后存储frame的文件夹 - QString ScaledFramesFolderPath = SplitFramesFolderPath+"/ScaledFrames_W2xEX";//存储放大后的帧 - //========================== - // 检测之前的视频配置文件 - //========================== - QString VideoConfiguration_fullPath = SourceFile_fullPath_FolderPath+"/VideoConfiguration_"+SourceFile_fullPath_BaseName+"_"+SourceFile_fullPath_suffix+"_Waifu2xEX.ini"; - if(QFile::exists(VideoConfiguration_fullPath)) - { - QSettings *configIniRead = new QSettings(VideoConfiguration_fullPath, QSettings::IniFormat); - configIniRead->setIniCodec(QTextCodec::codecForName("UTF-8")); - //=================== 加载之前存储的视频信息 ========================= - int ScaleRatio_old = configIniRead->value("/VideoConfiguration/ScaleRatio").toInt(); - int DenoiseLevel_old = configIniRead->value("/VideoConfiguration/DenoiseLevel").toInt(); - bool CustRes_isEnabled_old = configIniRead->value("/VideoConfiguration/CustRes_isEnabled").toBool(); - int CustRes_height_old = configIniRead->value("/VideoConfiguration/CustRes_height").toInt(); - int CustRes_width_old = configIniRead->value("/VideoConfiguration/CustRes_width").toInt(); - QString EngineName_old = configIniRead->value("/VideoConfiguration/EngineName").toString(); - bool isProcessBySegment_old = configIniRead->value("/VideoConfiguration/isProcessBySegment").toBool(); - //=================== 比对信息 ================================ - if(EngineName_old=="waifu2x-ncnn-vulkan") - { - if(CustRes_isEnabled_old==false&&CustRes_isEnabled==false) - { - if(ScaleRatio_old!=ScaleRatio||DenoiseLevel_old!=DenoiseLevel) - { - isVideoConfigChanged=true; - } - else - { - isVideoConfigChanged=false; - } - } - else - { - if(CustRes_isEnabled_old==true&&CustRes_isEnabled==true) - { - if(CustRes_height_old!=CustRes_height||CustRes_width_old!=CustRes_width) - { - isVideoConfigChanged=true; - } - else - { - isVideoConfigChanged=false; - } - } - else - { - isVideoConfigChanged=true; - } - } - if(isProcessBySegment_old==true) - { - isVideoConfigChanged=true; - } - } - else - { - isVideoConfigChanged=true; - } - } - else - { - emit Send_video_write_VideoConfiguration(VideoConfiguration_fullPath,ScaleRatio,DenoiseLevel,CustRes_isEnabled,CustRes_height,CustRes_width,"waifu2x-ncnn-vulkan",false,"","",ui->groupBox_FrameInterpolation->isChecked(),0); - } - //======================= - // 检测缓存是否存在 - //======================= - if(QFile::exists(video_mp4_fullpath)&&file_isDirExist(SplitFramesFolderPath)&&file_isDirExist(ScaledFramesFolderPath)&&QFile::exists(VideoConfiguration_fullPath)) - { - if(!isVideoConfigChanged) - { - isCacheExists=true; - emit Send_TextBrowser_NewMessage(tr("The previous video cache file is detected and processing of the previous video cache will continue. If you want to restart processing of the current video:[")+SourceFile_fullPath+tr("], delete the cache manually.")); - } - else - { - isCacheExists=false; - //======== - QFile::remove(VideoConfiguration_fullPath); - file_DelDir(SplitFramesFolderPath); - QFile::remove(AudioPath); - DelVfiDir(video_mp4_fullpath); - emit Send_video_write_VideoConfiguration(VideoConfiguration_fullPath,ScaleRatio,DenoiseLevel,CustRes_isEnabled,CustRes_height,CustRes_width,"waifu2x-ncnn-vulkan",false,"","",ui->groupBox_FrameInterpolation->isChecked(),0); - //======= - emit Send_TextBrowser_NewMessage(tr("The previous video cache file was detected, but because you changed the settings about the video resolution or denoise level, the previous cache will be deleted and processing of the video:[")+SourceFile_fullPath+tr("] will restart.")); - } - } - else - { - isCacheExists=false; - //======== - QFile::remove(VideoConfiguration_fullPath); - file_DelDir(SplitFramesFolderPath); - QFile::remove(AudioPath); - DelVfiDir(video_mp4_fullpath); - emit Send_video_write_VideoConfiguration(VideoConfiguration_fullPath,ScaleRatio,DenoiseLevel,CustRes_isEnabled,CustRes_height,CustRes_width,"waifu2x-ncnn-vulkan",false,"","",ui->groupBox_FrameInterpolation->isChecked(),0); - //======== - } - if(!isCacheExists) - { - //============================== 拆分 ========================================== - if(file_isDirExist(SplitFramesFolderPath)) - { - file_DelDir(SplitFramesFolderPath); - file_mkDir(SplitFramesFolderPath); - } - else - { - file_mkDir(SplitFramesFolderPath); - } - QFile::remove(AudioPath); - video_video2images(video_mp4_fullpath,SplitFramesFolderPath,AudioPath); - if(waifu2x_STOP) - { - emit Send_Table_video_ChangeStatus_rowNumInt_statusQString(rowNum, "Interrupted"); - return 0;//如果启用stop位,则直接return - } - } - //============================== 扫描获取文件名 =============================== - QStringList Frame_fileName_list = file_getFileNames_in_Folder_nofilter(SplitFramesFolderPath); - if(!isCacheExists) - { - if(Frame_fileName_list.isEmpty())//检查是否成功拆分为帧 - { - emit Send_TextBrowser_NewMessage(tr("Error occured when processing [")+SourceFile_fullPath+tr("]. Error: [Unable to split video into pictures.]")); - emit Send_Table_video_ChangeStatus_rowNumInt_statusQString(rowNum, "Failed"); - emit Send_progressbar_Add(); - return 0;//如果启用stop位,则直接return - } - } - //============================== 放大 ======================================= - //===========建立存储放大后frame的文件夹=========== - if(!isCacheExists) - { - if(file_isDirExist(ScaledFramesFolderPath)) - { - file_DelDir(ScaledFramesFolderPath); - file_mkDir(ScaledFramesFolderPath); - } - else - { - file_mkDir(ScaledFramesFolderPath); - } - } - //==========开始放大========================== - //读取放大倍数 - int ScaleRatio_Original = 2; - if(CustRes_isEnabled == true) - { - ScaleRatio_Original = CustRes_CalNewScaleRatio(video_mp4_fullpath,CustRes_height,CustRes_width); - } - else - { - ScaleRatio_Original = ui->doubleSpinBox_ScaleRatio_video->value(); - } - int ScaleRatio_Max=Calculate_Temporary_ScaleRatio_W2xNCNNVulkan(ScaleRatio_Original); - bool isOverScaled = (ScaleRatio_Max!=ScaleRatio_Original); - //读取初始放大倍率 - int Initial_ScaleRatio = 2; - if(!Frame_fileName_list.isEmpty()) - { - QString Full_Path_File = ""; - for(int i = 0; i < Frame_fileName_list.size(); i++) - { - QString tmp = Frame_fileName_list.at(i); - Full_Path_File = SplitFramesFolderPath + "/" + tmp; - QFileInfo finfo(Full_Path_File); - if(finfo.suffix()=="png")break; - } - QImage qimage_original; - qimage_original.load(Full_Path_File); - int Frame_height = qimage_original.height(); - QMap res_map = video_get_Resolution(SourceFile_fullPath); - int Video_height = res_map["height"]; - if(Frame_height>0 && Video_height>0 && Frame_height>=Video_height)//判断是否读取失败 - { - Initial_ScaleRatio = 2*(Frame_height/Video_height); - } - } - //初始化进度讯息 - int NumOfSplitFrames = Frame_fileName_list.size()+file_getFileNames_in_Folder_nofilter(ScaledFramesFolderPath).size(); - if(ui->checkBox_ShowInterPro->isChecked()) - { - int NumOfRounds=0; - for(int ScaleRatio_Current_tmp=Initial_ScaleRatio; ScaleRatio_Current_tmp<=ScaleRatio_Max; ScaleRatio_Current_tmp*=2) - { - NumOfRounds++; - } - emit Send_CurrentFileProgress_Start(SourceFile_fullPath_BaseName+"."+SourceFile_fullPath_suffix,NumOfSplitFrames*NumOfRounds); - } - //读取配置讯息 - QString Waifu2x_NCNN_Vulkan_Settings_str = ""; - QString cmd=""; - QProcess *Waifu2x = new QProcess(); - QString program = Waifu2x_ncnn_vulkan_ProgramPath; - bool waifu2x_qprocess_failed = false; - int DenoiseLevel_tmp = DenoiseLevel; - DenoiseLevel_tmp = DenoiseLevel; - int CountFinishedRounds=0; - //==== - for(int ScaleRatio_Current_tmp=Initial_ScaleRatio; ScaleRatio_Current_tmp<=ScaleRatio_Max && Frame_fileName_list.isEmpty()==false; ScaleRatio_Current_tmp*=2) - { - for(int retry=0; retry<(ui->spinBox_retry->value()+ForceRetryCount); retry++) - { - QString ErrorMSG=""; - QString StanderMSG=""; - //========== - waifu2x_qprocess_failed = false; - Waifu2x_NCNN_Vulkan_Settings_str = Waifu2x_NCNN_Vulkan_ReadSettings_Video_GIF(ui->spinBox_ThreadNum_video_internal->value()); - cmd = "\"" + program + "\"" + " -i " + "\"" + SplitFramesFolderPath + "\"" + " -o " + "\"" + ScaledFramesFolderPath + "\"" + " -s " + "2" + " -n " + QString::number(DenoiseLevel_tmp, 10) + Waifu2x_NCNN_Vulkan_Settings_str; - Waifu2x->start(cmd); - while(!Waifu2x->waitForStarted(100)&&!QProcess_stop) {} - while(!Waifu2x->waitForFinished(650)&&!QProcess_stop) - { - if(waifu2x_STOP) - { - QStringList FinfishedFileList_FileNames = WaitForEngineIO_NcnnVulkan(ScaledFramesFolderPath); - Waifu2x->close(); - //============ - QString file_name_tmp; - QStringList FileNames_ScaledFramesFolderPath = file_getFileNames_in_Folder_nofilter(ScaledFramesFolderPath); - for(int i=0; ireadAllStandardError().toLower()); - StanderMSG.append(Waifu2x->readAllStandardOutput().toLower()); - if(ErrorMSG.contains("failed")||StanderMSG.contains("failed")) - { - waifu2x_qprocess_failed = true; - Waifu2x->close(); - break; - } - if(ui->checkBox_ShowInterPro->isChecked()) - { - emit Send_CurrentFileProgress_progressbar_SetFinishedValue((NumOfSplitFrames*CountFinishedRounds)+file_getFileNames_in_Folder_nofilter(ScaledFramesFolderPath).size()); - } - } - //=============== - if(waifu2x_qprocess_failed==false) - { - ErrorMSG.append(Waifu2x->readAllStandardError().toLower()); - StanderMSG.append(Waifu2x->readAllStandardOutput().toLower()); - if(ErrorMSG.contains("failed")||StanderMSG.contains("failed")) - { - waifu2x_qprocess_failed = true; - } - } - //========= 检测是否成功,是否需要重试 ============ - if((NumOfSplitFrames == file_getFileNames_in_Folder_nofilter(ScaledFramesFolderPath).size())&&!waifu2x_qprocess_failed) - { - break; - } - else - { - //失败 - file_DelDir(ScaledFramesFolderPath); - file_mkDir(ScaledFramesFolderPath); - if(retry==ui->spinBox_retry->value()+(ForceRetryCount-1))break; - emit Send_TextBrowser_NewMessage(tr("Automatic retry, please wait.")); - Delay_sec_sleep(5); - } - } - //=========== - //根据轮数修改参数 - DenoiseLevel_tmp = -1; - if(ScaleRatio_Current_tmpcheckBox_KeepVideoCache->isChecked()==false) - { - QFile::remove(VideoConfiguration_fullPath); - file_DelDir(SplitFramesFolderPath); - QFile::remove(AudioPath); - if(SourceFile_fullPath!=video_mp4_fullpath)QFile::remove(video_mp4_fullpath); - } - else - { - DelOriginal=false; - } - //============================= 删除原文件 & & 更新table status ============================ - if(DelOriginal) - { - if(ReplaceOriginalFile(SourceFile_fullPath,video_mp4_scaled_fullpath)==false) - { - if(QAction_checkBox_MoveToRecycleBin_checkBox_DelOriginal->isChecked()) - { - file_MoveToTrash(SourceFile_fullPath); - } - else - { - QFile::remove(SourceFile_fullPath); - } - } - emit Send_Table_video_ChangeStatus_rowNumInt_statusQString(rowNum, "Finished, original file deleted"); - } - else - { - emit Send_Table_video_ChangeStatus_rowNumInt_statusQString(rowNum, "Finished"); - } - //========== 移动到输出路径 ========= - if(ui->checkBox_OutPath_isEnabled->isChecked()) - { - MoveFileToOutputPath(video_mp4_scaled_fullpath,SourceFile_fullPath); - } - //============================ 更新进度条 ================================= - emit Send_progressbar_Add(); - //=========================== ============================== - return 0; -} -/* -#### 分段处理 #### -调用Waifu2x-NCNN-Vulkan处理视频 -读取设置,拆分,创建放大子线程,组装视频 -*/ -int MainWindow::Waifu2x_NCNN_Vulkan_Video_BySegment(int rowNum) -{ - //============================= 读取设置 ================================ - int ScaleRatio = ui->doubleSpinBox_ScaleRatio_video->value(); - int DenoiseLevel = ui->spinBox_DenoiseLevel_video->value(); - bool DelOriginal = (ui->checkBox_DelOriginal->isChecked()||ui->checkBox_ReplaceOriginalFile->isChecked()); - bool isCacheExists = false; - bool isVideoConfigChanged = true; - int SegmentDuration = ui->spinBox_SegmentDuration->value(); - //========================= 拆解map得到参数 ============================= - emit Send_Table_video_ChangeStatus_rowNumInt_statusQString(rowNum, "Processing"); - QString SourceFile_fullPath = Table_model_video->item(rowNum,2)->text(); - if(!QFile::exists(SourceFile_fullPath)) - { - emit Send_TextBrowser_NewMessage(tr("Error occured when processing [")+SourceFile_fullPath+tr("]. Error: [File does not exist.]")); - emit Send_Table_video_ChangeStatus_rowNumInt_statusQString(rowNum, "Failed"); - emit Send_progressbar_Add(); - return 0; - } - //========================== - QFileInfo fileinfo(SourceFile_fullPath); - QString file_name = file_getBaseName(SourceFile_fullPath); - QString file_ext = fileinfo.suffix(); - QString file_path = file_getFolderPath(fileinfo); - //=================================================================== - //生成mp4 - QString video_mp4_fullpath=video_To_CFRMp4(SourceFile_fullPath); - if(!QFile::exists(video_mp4_fullpath))//检查是否成功生成mp4 - { - emit Send_TextBrowser_NewMessage(tr("Error occured when processing [")+SourceFile_fullPath+tr("]. Error: [Cannot convert video format to mp4.]")); - emit Send_Table_video_ChangeStatus_rowNumInt_statusQString(rowNum, "Failed"); - emit Send_progressbar_Add(); - return 0;//如果启用stop位,则直接return - } - //============ 读取自定义分辨率 ============== - bool CustRes_isEnabled = false; - int CustRes_height=0; - int CustRes_width=0; - if(CustRes_isContained(SourceFile_fullPath)) - { - CustRes_isEnabled=true; - QMap Res_map = CustRes_getResMap(SourceFile_fullPath);//res_map["fullpath"],["height"],["width"] - CustRes_height=Res_map["height"].toInt(); - CustRes_width=Res_map["width"].toInt(); - } - //================= - QString AudioPath = file_path+"/Audio_"+file_name+"_"+file_ext+"_W2xEX.wav";//音频 - QString SplitFramesFolderPath = file_path+"/"+file_name+"_"+file_ext+"_SplitFrames_W2xEX";//拆分后存储frame的文件夹 - QString ScaledFramesFolderPath = SplitFramesFolderPath+"/ScaledFrames_W2xEX";//存储放大后的帧 - //=== - QString VideoClipsFolderPath = "";//存储视频片段的文件夹(完整路径) - QString DateStr = ""; - do - { - DateStr = video_getClipsFolderNo(); - VideoClipsFolderPath = file_path+"/"+DateStr+"_VideoClipsWaifu2xEX";//存储视频片段的文件夹(完整路径) - } - while(file_isDirExist(VideoClipsFolderPath)); - QString VideoClipsFolderName = DateStr+"_VideoClipsWaifu2xEX";//存储视频片段的文件夹(名称) - //========================== - // 检测之前的视频配置文件 - //========================== - QString VideoConfiguration_fullPath = file_path+"/VideoConfiguration_"+file_name+"_"+file_ext+"_Waifu2xEX.ini"; - if(QFile::exists(VideoConfiguration_fullPath)) - { - QSettings *configIniRead = new QSettings(VideoConfiguration_fullPath, QSettings::IniFormat); - configIniRead->setIniCodec(QTextCodec::codecForName("UTF-8")); - //=================== 加载之前存储的视频信息 ========================= - int ScaleRatio_old = configIniRead->value("/VideoConfiguration/ScaleRatio").toInt(); - int DenoiseLevel_old = configIniRead->value("/VideoConfiguration/DenoiseLevel").toInt(); - bool CustRes_isEnabled_old = configIniRead->value("/VideoConfiguration/CustRes_isEnabled").toBool(); - int CustRes_height_old = configIniRead->value("/VideoConfiguration/CustRes_height").toInt(); - int CustRes_width_old = configIniRead->value("/VideoConfiguration/CustRes_width").toInt(); - QString EngineName_old = configIniRead->value("/VideoConfiguration/EngineName").toString(); - bool isProcessBySegment_old = configIniRead->value("/VideoConfiguration/isProcessBySegment").toBool(); - bool isVideoFrameInterpolationEnabled_old = configIniRead->value("/VideoConfiguration/isVideoFrameInterpolationEnabled").toBool(); - int MultipleOfFPS_old = configIniRead->value("/VideoConfiguration/MultipleOfFPS").toInt(); - //=================== 比对信息 ================================ - if(EngineName_old=="waifu2x-ncnn-vulkan") - { - if(CustRes_isEnabled_old==false&&CustRes_isEnabled==false) - { - if(ScaleRatio_old!=ScaleRatio||DenoiseLevel_old!=DenoiseLevel) - { - isVideoConfigChanged=true; - } - else - { - isVideoConfigChanged=false; - } - } - else - { - if(CustRes_isEnabled_old==true&&CustRes_isEnabled==true) - { - if(CustRes_height_old!=CustRes_height||CustRes_width_old!=CustRes_width) - { - isVideoConfigChanged=true; - } - else - { - isVideoConfigChanged=false; - } - } - else - { - isVideoConfigChanged=true; - } - } - if(isProcessBySegment_old == false) - { - isVideoConfigChanged=true; - } - if(isVideoFrameInterpolationEnabled_old != ui->groupBox_FrameInterpolation->isChecked()) - { - isVideoConfigChanged=true; - } - if(MultipleOfFPS_old != ui->spinBox_MultipleOfFPS_VFI->value() && ui->groupBox_FrameInterpolation->isChecked()) - { - isVideoConfigChanged=true; - } - } - else - { - isVideoConfigChanged=true; - } - //============ 修正文件夹名称 ============= - QString VideoClipsFolderPath_old = configIniRead->value("/VideoConfiguration/VideoClipsFolderPath").toString(); - QString VideoClipsFolderName_old = configIniRead->value("/VideoConfiguration/VideoClipsFolderName").toString(); - file_mkDir(VideoClipsFolderPath_old); - if(file_isDirExist(VideoClipsFolderPath_old)==true) - { - VideoClipsFolderPath = VideoClipsFolderPath_old; - VideoClipsFolderName = VideoClipsFolderName_old; - } - } - else - { - emit Send_video_write_VideoConfiguration(VideoConfiguration_fullPath,ScaleRatio,DenoiseLevel,CustRes_isEnabled,CustRes_height,CustRes_width,"waifu2x-ncnn-vulkan",true,VideoClipsFolderPath,VideoClipsFolderName,ui->groupBox_FrameInterpolation->isChecked(),ui->spinBox_MultipleOfFPS_VFI->value()); - } - //======================= - // 检测缓存是否存在 - //======================= - if(file_isDirExist(SplitFramesFolderPath)) - { - if(!isVideoConfigChanged) - { - isCacheExists=true; - emit Send_TextBrowser_NewMessage(tr("The previous video cache file is detected and processing of the previous video cache will continue. If you want to restart processing of the current video:[")+SourceFile_fullPath+tr("], delete the cache manually.")); - } - else - { - isCacheExists=false; - //======== - QFile::remove(VideoConfiguration_fullPath); - file_DelDir(SplitFramesFolderPath); - file_DelDir(VideoClipsFolderPath); - QFile::remove(AudioPath); - DelVfiDir(video_mp4_fullpath); - emit Send_video_write_VideoConfiguration(VideoConfiguration_fullPath,ScaleRatio,DenoiseLevel,CustRes_isEnabled,CustRes_height,CustRes_width,"waifu2x-ncnn-vulkan",true,VideoClipsFolderPath,VideoClipsFolderName,ui->groupBox_FrameInterpolation->isChecked(),ui->spinBox_MultipleOfFPS_VFI->value()); - //======= - emit Send_TextBrowser_NewMessage(tr("The previous video cache file was detected, but because you changed the settings about the video resolution or denoise level, the previous cache will be deleted and processing of the video:[")+SourceFile_fullPath+tr("] will restart.")); - } - } - else - { - isCacheExists=false; - //======== - QFile::remove(VideoConfiguration_fullPath); - file_DelDir(SplitFramesFolderPath); - file_DelDir(VideoClipsFolderPath); - QFile::remove(AudioPath); - DelVfiDir(video_mp4_fullpath); - emit Send_video_write_VideoConfiguration(VideoConfiguration_fullPath,ScaleRatio,DenoiseLevel,CustRes_isEnabled,CustRes_height,CustRes_width,"waifu2x-ncnn-vulkan",true,VideoClipsFolderPath,VideoClipsFolderName,ui->groupBox_FrameInterpolation->isChecked(),ui->spinBox_MultipleOfFPS_VFI->value()); - //======== - } - /*==================================== - 提取音频 - ======================================*/ - if(!QFile::exists(AudioPath)) - { - video_get_audio(video_mp4_fullpath,AudioPath); - } - //================================== 开始分段处理视频 ================================================= - int StartTime = 0;//起始时间(秒) - int VideoDuration = video_get_duration(video_mp4_fullpath); - bool isSplitComplete = false; - bool isScaleComplete = false; - /* - ============================================ - 开始之前先读取进度 - ============================================ - */ - int OLD_SegmentDuration=-1; - bool read_OLD_SegmentDuration =false; - int LastVideoClipNo = -1; - if(QFile::exists(VideoConfiguration_fullPath)) - { - QSettings *configIniRead = new QSettings(VideoConfiguration_fullPath, QSettings::IniFormat); - configIniRead->setIniCodec(QTextCodec::codecForName("UTF-8")); - //=================== 加载进度 ========================= - StartTime = configIniRead->value("/Progress/StartTime").toInt(); - isSplitComplete = configIniRead->value("/Progress/isSplitComplete").toBool(); - isScaleComplete = configIniRead->value("/Progress/isScaleComplete").toBool(); - OLD_SegmentDuration = configIniRead->value("/Progress/OLDSegmentDuration").toInt(); - LastVideoClipNo = configIniRead->value("/Progress/LastVideoClipNo").toInt(); - } - if(OLD_SegmentDuration>0) - { - read_OLD_SegmentDuration = true; - } - /* - 加载进度条 - */ - int SegmentDuration_tmp_progressbar = 0; - if(read_OLD_SegmentDuration) - { - SegmentDuration_tmp_progressbar = OLD_SegmentDuration; - } - else - { - SegmentDuration_tmp_progressbar = SegmentDuration; - } - if(ui->checkBox_ShowInterPro->isChecked()&&VideoDuration>SegmentDuration_tmp_progressbar) - { - emit Send_CurrentFileProgress_Start(file_name+"."+file_ext,VideoDuration); - if(StartTime>0) - { - emit Send_CurrentFileProgress_progressbar_Add_SegmentDuration(StartTime); - } - } - /* - ============================================ - 正式开始处理 - ============================================ - */ - int SegmentDuration_tmp=0; - int TimeLeft_tmp=0; - bool isOverScaled = false; - QString video_mp4_scaled_clip_fullpath=""; - //========================== - while(VideoDuration>StartTime) - { - /*========================== - 计算视频片段时间 - ==========================*/ - TimeLeft_tmp = VideoDuration-StartTime; - if((TimeLeft_tmp)>=SegmentDuration) - { - SegmentDuration_tmp = SegmentDuration; - } - else - { - SegmentDuration_tmp = TimeLeft_tmp; - } - if(read_OLD_SegmentDuration) - { - SegmentDuration_tmp = OLD_SegmentDuration; - read_OLD_SegmentDuration=false; - } - /*========================== - 拆分视频片段 - ==========================*/ - if(isSplitComplete==false) - { - if(file_isDirExist(SplitFramesFolderPath)) - { - file_DelDir(SplitFramesFolderPath); - file_mkDir(SplitFramesFolderPath); - } - else - { - file_mkDir(SplitFramesFolderPath); - } - video_video2images_ProcessBySegment(video_mp4_fullpath,SplitFramesFolderPath,StartTime,SegmentDuration_tmp); - if(waifu2x_STOP) - { - emit Send_Table_video_ChangeStatus_rowNumInt_statusQString(rowNum, "Interrupted"); - return 0;//如果启用stop位,则直接return - } - } - /*========================== - 处理视频片段的帧 - ==========================*/ - isOverScaled = false; - if(isScaleComplete==false) - { - //============================== 扫描获取文件名 =============================== - QStringList Frame_fileName_list = file_getFileNames_in_Folder_nofilter(SplitFramesFolderPath); - if(isSplitComplete==false) - { - if(Frame_fileName_list.isEmpty())//检查是否成功拆分为帧 - { - emit Send_TextBrowser_NewMessage(tr("Error occured when processing [")+SourceFile_fullPath+tr("]. Error: [Unable to split video into pictures.]")); - emit Send_Table_video_ChangeStatus_rowNumInt_statusQString(rowNum, "Failed"); - emit Send_progressbar_Add(); - return 0;//如果启用stop位,则直接return - } - } - /* - 记录进度 - 帧拆分成功 - */ - emit Send_video_write_Progress_ProcessBySegment(VideoConfiguration_fullPath,StartTime,true,false,SegmentDuration_tmp,LastVideoClipNo); - //============================== 放大 ======================================= - //===========建立存储放大后frame的文件夹=========== - if(isSplitComplete==false) - { - if(file_isDirExist(ScaledFramesFolderPath)) - { - file_DelDir(ScaledFramesFolderPath); - file_mkDir(ScaledFramesFolderPath); - } - else - { - file_mkDir(ScaledFramesFolderPath); - } - } - //==========开始放大========================== - //读取放大倍数 - int ScaleRatio_Original = 2; - if(CustRes_isEnabled == true) - { - ScaleRatio_Original = CustRes_CalNewScaleRatio(video_mp4_fullpath,CustRes_height,CustRes_width); - } - else - { - ScaleRatio_Original = ui->doubleSpinBox_ScaleRatio_video->value(); - } - int ScaleRatio_Max=Calculate_Temporary_ScaleRatio_W2xNCNNVulkan(ScaleRatio_Original); - isOverScaled = (ScaleRatio_Max!=ScaleRatio_Original); - //读取初始放大倍率 - int Initial_ScaleRatio = 2; - if(!Frame_fileName_list.isEmpty()) - { - QString Full_Path_File = ""; - for(int i = 0; i < Frame_fileName_list.size(); i++) - { - QString tmp = Frame_fileName_list.at(i); - Full_Path_File = SplitFramesFolderPath + "/" + tmp; - QFileInfo finfo(Full_Path_File); - if(finfo.suffix()=="png")break; - } - QImage qimage_original; - qimage_original.load(Full_Path_File); - int Frame_height = qimage_original.height(); - QMap res_map = video_get_Resolution(SourceFile_fullPath); - int Video_height = res_map["height"]; - if(Frame_height>0 && Video_height>0 && Frame_height>=Video_height)//判断是否读取失败 - { - Initial_ScaleRatio = 2*(Frame_height/Video_height); - } - } - //初始化进度讯息 - int NumOfSplitFrames = Frame_fileName_list.size()+file_getFileNames_in_Folder_nofilter(ScaledFramesFolderPath).size(); - int CurrentFileProgress_MAX = 0; - int CurrentFileProgress_OLD = 0; - int CurrentFileProgress_New = 0; - if(ui->checkBox_ShowInterPro->isChecked()) - { - int NumOfRounds=0; - for(int ScaleRatio_Current_tmp=Initial_ScaleRatio; ScaleRatio_Current_tmp<=ScaleRatio_Max; ScaleRatio_Current_tmp*=2) - { - NumOfRounds++; - } - CurrentFileProgress_MAX =NumOfSplitFrames*NumOfRounds; - } - //读取配置讯息 - QProcess *Waifu2x = new QProcess(); - bool waifu2x_qprocess_failed = false; - int DenoiseLevel_tmp = DenoiseLevel; - int CountFinishedRounds=0; - QString ErrorMSG=""; - QString StanderMSG=""; - QString cmd=""; - QString Waifu2x_NCNN_Vulkan_Settings_str=""; - //==== - for(int ScaleRatio_Current_tmp=Initial_ScaleRatio; ScaleRatio_Current_tmp<=ScaleRatio_Max && Frame_fileName_list.isEmpty()==false; ScaleRatio_Current_tmp*=2) - { - for(int retry=0; retry<(ui->spinBox_retry->value()+ForceRetryCount); retry++) - { - ErrorMSG=""; - StanderMSG=""; - //========== - waifu2x_qprocess_failed = false; - Waifu2x_NCNN_Vulkan_Settings_str = Waifu2x_NCNN_Vulkan_ReadSettings_Video_GIF(ui->spinBox_ThreadNum_video_internal->value()); - cmd = "\"" + Waifu2x_ncnn_vulkan_ProgramPath + "\"" + " -i " + "\"" + SplitFramesFolderPath + "\"" + " -o " + "\"" + ScaledFramesFolderPath + "\"" + " -s " + "2" + " -n " + QString::number(DenoiseLevel_tmp, 10) + Waifu2x_NCNN_Vulkan_Settings_str; - Waifu2x->start(cmd); - while(!Waifu2x->waitForStarted(100)&&!QProcess_stop) {} - while(!Waifu2x->waitForFinished(650)&&!QProcess_stop) - { - if(waifu2x_STOP) - { - QStringList FinfishedFileList_FileNames = WaitForEngineIO_NcnnVulkan(ScaledFramesFolderPath); - Waifu2x->close(); - //============ - QString file_name_tmp; - QStringList FileNames_ScaledFramesFolderPath = file_getFileNames_in_Folder_nofilter(ScaledFramesFolderPath); - for(int i=0; ireadAllStandardError().toLower()); - StanderMSG.append(Waifu2x->readAllStandardOutput().toLower()); - if(ErrorMSG.contains("failed")||StanderMSG.contains("failed")) - { - waifu2x_qprocess_failed = true; - Waifu2x->close(); - break; - } - if(ui->checkBox_ShowInterPro->isChecked()) - { - CurrentFileProgress_New = (NumOfSplitFrames*CountFinishedRounds)+file_getFileNames_in_Folder_nofilter(ScaledFramesFolderPath).size(); - if(CurrentFileProgress_New!=CurrentFileProgress_OLD) - { - emit Send_TextBrowser_NewMessage(tr("File name:[")+SourceFile_fullPath+tr("] Scale progress:[")+QString::number(CurrentFileProgress_New,10)+"/"+QString::number(CurrentFileProgress_MAX,10)+tr("] Duration progress:[")+QString::number(StartTime,10)+"s/"+QString::number(VideoDuration,10)+"s]"); - CurrentFileProgress_OLD=CurrentFileProgress_New; - } - } - } - //=============== - if(waifu2x_qprocess_failed==false) - { - ErrorMSG.append(Waifu2x->readAllStandardError().toLower()); - StanderMSG.append(Waifu2x->readAllStandardOutput().toLower()); - if(ErrorMSG.contains("failed")||StanderMSG.contains("failed")) - { - waifu2x_qprocess_failed = true; - } - } - //========= 检测是否成功,是否需要重试 ============ - if((NumOfSplitFrames == file_getFileNames_in_Folder_nofilter(ScaledFramesFolderPath).size())&&!waifu2x_qprocess_failed) - { - break; - } - else - { - //失败 - file_DelDir(ScaledFramesFolderPath); - file_mkDir(ScaledFramesFolderPath); - if(retry==ui->spinBox_retry->value()+(ForceRetryCount-1))break; - emit Send_TextBrowser_NewMessage(tr("Automatic retry, please wait.")); - Delay_sec_sleep(5); - } - } - //=========== - //根据轮数修改参数 - DenoiseLevel_tmp = -1; - if(ScaleRatio_Current_tmpcheckBox_ShowInterPro->isChecked()) - { - emit Send_CurrentFileProgress_progressbar_Add_SegmentDuration(SegmentDuration_tmp); - } - StartTime+=SegmentDuration_tmp; - isSplitComplete = false; - isScaleComplete = false; - LastVideoClipNo=VideoClipNo; - emit Send_video_write_Progress_ProcessBySegment(VideoConfiguration_fullPath,StartTime,false,false,-1,VideoClipNo); - } - emit Send_CurrentFileProgress_Stop(); - //====================================================== - // 组装(片段到成片) - //====================================================== - QString video_mp4_scaled_fullpath = ""; - if(CustRes_isEnabled) - { - video_mp4_scaled_fullpath = file_path+"/"+file_name+"_waifu2x_"+QString::number(CustRes_width,10)+"x"+QString::number(CustRes_height,10)+"_"+QString::number(DenoiseLevel,10)+"n"+"_"+file_ext+".mp4"; - } - else - { - video_mp4_scaled_fullpath = file_path+"/"+file_name+"_waifu2x_"+QString::number(ScaleRatio,10)+"x_"+QString::number(DenoiseLevel,10)+"n"+"_"+file_ext+".mp4"; - } - QFile::remove(video_mp4_scaled_fullpath); - video_AssembleVideoClips(VideoClipsFolderPath,VideoClipsFolderName,video_mp4_scaled_fullpath,AudioPath); - if(QFile::exists(video_mp4_scaled_fullpath)==false)//检查是否成功生成视频 - { - if(waifu2x_STOP) - { - emit Send_Table_video_ChangeStatus_rowNumInt_statusQString(rowNum, "Interrupted"); - return 0;//如果启用stop位,则直接return - } - emit Send_TextBrowser_NewMessage(tr("Error occured when processing [")+SourceFile_fullPath+tr("]. Error: [Unable to assemble video clips.]")); - emit Send_Table_video_ChangeStatus_rowNumInt_statusQString(rowNum, "Failed"); - emit Send_progressbar_Add(); - return 0;//如果启用stop位,则直接return - } - //============================== 删除缓存文件 ==================================================== - if(ui->checkBox_KeepVideoCache->isChecked()==false) - { - QFile::remove(VideoConfiguration_fullPath); - file_DelDir(SplitFramesFolderPath); - file_DelDir(VideoClipsFolderPath); - QFile::remove(AudioPath); - if(SourceFile_fullPath!=video_mp4_fullpath)QFile::remove(video_mp4_fullpath); - } - else - { - DelOriginal=false; - } - //============================= 删除原文件 & & 更新table status ============================ - if(DelOriginal) - { - if(ReplaceOriginalFile(SourceFile_fullPath,video_mp4_scaled_fullpath)==false) - { - if(QAction_checkBox_MoveToRecycleBin_checkBox_DelOriginal->isChecked()) - { - file_MoveToTrash(SourceFile_fullPath); - } - else - { - QFile::remove(SourceFile_fullPath); - } - } - emit Send_Table_video_ChangeStatus_rowNumInt_statusQString(rowNum, "Finished, original file deleted"); - } - else - { - emit Send_Table_video_ChangeStatus_rowNumInt_statusQString(rowNum, "Finished"); - } - //========== 移动到输出路径 ========= - if(ui->checkBox_OutPath_isEnabled->isChecked()) - { - MoveFileToOutputPath(video_mp4_scaled_fullpath,SourceFile_fullPath); - } - //============================ 更新进度条 ================================= - emit Send_progressbar_Add(); - //=========================== ============================== - return 0; -} -/* -================================================================================ - WAIFU2X NCNN VULKAN 检测可用GPU -================================================================================= -*/ -void MainWindow::on_pushButton_DetectGPU_clicked() -{ - //==== - ui->pushButton_DetectGPU->setText(tr("Detecting, please wait...")); - //==== - pushButton_Start_setEnabled_self(0); - ui->pushButton_DetectGPU->setEnabled(0); - ui->pushButton_DetectGPUID_srmd->setEnabled(0); - ui->pushButton_DumpProcessorList_converter->setEnabled(0); - ui->pushButton_ListGPUs_Anime4k->setEnabled(0); - ui->pushButton_compatibilityTest->setEnabled(0); - ui->pushButton_DetectGPU_RealsrNCNNVulkan->setEnabled(0); - Available_GPUID.clear(); - QtConcurrent::run(this, &MainWindow::Waifu2x_DetectGPU); -} - -int MainWindow::Waifu2x_DetectGPU() -{ - emit Send_TextBrowser_NewMessage(tr("Detecting available GPU, please wait.")); - //=============== - QString InputPath = Current_Path + "/Compatibility_Test/Compatibility_Test.jpg"; - QString OutputPath = Current_Path + "/Compatibility_Test/res.png"; - QFile::remove(OutputPath); - //============== - QString Waifu2x_folder_path = Waifu2x_ncnn_vulkan_FolderPath; - QString program = Waifu2x_ncnn_vulkan_ProgramPath; - QString model_path = Waifu2x_folder_path+"/models-upconv_7_anime_style_art_rgb"; - //========= - int GPU_ID=-1; - //========= - while(true) - { - QFile::remove(OutputPath); - QProcess *Waifu2x = new QProcess(); - QString gpu_str = " -g "+QString::number(GPU_ID,10)+" "; - QString cmd = "\"" + program + "\"" + " -i " + "\"" + InputPath + "\"" + " -o " + "\"" + OutputPath + "\"" + " -s 2 -n 0 -t 32 -m " + "\"" + model_path + "\"" + " -j 1:1:1"+gpu_str; - Waifu2x->start(cmd); - while(!Waifu2x->waitForStarted(100)&&!QProcess_stop) {} - while(!Waifu2x->waitForFinished(100)&&!QProcess_stop) {} - if(QFile::exists(OutputPath) && (Waifu2x->readAllStandardError().toLower().contains("failed")||Waifu2x->readAllStandardOutput().toLower().contains("failed"))==false) - { - Available_GPUID.append(QString::number(GPU_ID,10)); - GPU_ID++; - QFile::remove(OutputPath); - } - else - { - if(GPU_ID > -1) - { - break; - } - else - { - GPU_ID++; - } - } - } - QFile::remove(OutputPath); - //=============== - emit Send_TextBrowser_NewMessage(tr("Detection is complete!")); - if(Available_GPUID.isEmpty()) - { - Send_TextBrowser_NewMessage(tr("No available GPU ID detected!")); - } - emit Send_Waifu2x_DetectGPU_finished(); - return 0; -} - -int MainWindow::Waifu2x_DetectGPU_finished() -{ - pushButton_Start_setEnabled_self(1); - ui->pushButton_DetectGPU->setEnabled(1); - ui->pushButton_compatibilityTest->setEnabled(1); - ui->pushButton_DetectGPUID_srmd->setEnabled(1); - ui->pushButton_DumpProcessorList_converter->setEnabled(1); - on_checkBox_SpecifyGPU_Anime4k_stateChanged(1); - ui->pushButton_DetectGPU_RealsrNCNNVulkan->setEnabled(1); - //==== - GPUIDs_List_MultiGPU_Waifu2xNCNNVulkan.clear(); - ui->comboBox_GPUIDs_MultiGPU_Waifu2xNCNNVulkan->clear(); - ui->comboBox_GPUID->clear(); - ui->comboBox_GPUID->addItem("auto"); - if(!Available_GPUID.isEmpty()) - { - for(int i=0; icomboBox_GPUID->addItem(Available_GPUID.at(i)); - AddGPU_MultiGPU_Waifu2xNCNNVulkan(Available_GPUID.at(i)); - } - } - //==== - ui->pushButton_DetectGPU->setText(tr("Detect available GPU ID")); - //==== - return 0; -} - -/* -Waifu2x_NCNN_Vulkan -预读取引擎配置 -*/ -QString MainWindow::Waifu2x_NCNN_Vulkan_PreLoad_Settings() -{ - QString Waifu2x_NCNN_Vulkan_Settings_str = " "; - //TTA - if(ui->checkBox_TTA_vulkan->isChecked()) - { - Waifu2x_NCNN_Vulkan_Settings_str.append("-x "); - } - if(ui->checkBox_MultiGPU_Waifu2xNCNNVulkan->isChecked()==false) - { - //==========单显卡========== - //GPU ID - if(ui->comboBox_GPUID->currentText()!="auto") - { - Waifu2x_NCNN_Vulkan_Settings_str.append("-g "+ui->comboBox_GPUID->currentText()+" "); - } - //Tile Size - Waifu2x_NCNN_Vulkan_Settings_str.append("-t "+QString::number(ui->spinBox_TileSize->value(),10)+" "); - } - //Model - int ImageStyle = ui->comboBox_ImageStyle->currentIndex(); - QString model_path=""; - if(ui->comboBox_model_vulkan->currentIndex()==0) - { - if(ImageStyle==0) - { - model_path = Waifu2x_ncnn_vulkan_FolderPath+"/models-upconv_7_anime_style_art_rgb"; - } - else - { - model_path = Waifu2x_ncnn_vulkan_FolderPath+"/models-upconv_7_photo"; - } - } - if(ui->comboBox_model_vulkan->currentIndex()==1) - { - model_path = Waifu2x_ncnn_vulkan_FolderPath+"/models-cunet"; - } - Waifu2x_NCNN_Vulkan_Settings_str.append("-m \""+model_path+"\" "); - Waifu2x_NCNN_Vulkan_Settings_str.append("-j 1:1:1 "); - //======================================= - return Waifu2x_NCNN_Vulkan_Settings_str; -} - -/* -Waifu2x_NCNN_Vulkan -读取配置生成配置string -*/ -QString MainWindow::Waifu2x_NCNN_Vulkan_ReadSettings() -{ - QString Waifu2x_NCNN_Vulkan_Settings_str = ""; - Waifu2x_NCNN_Vulkan_Settings_str.append(Waifu2x_NCNN_Vulkan_PreLoad_Settings_Str); - if(ui->checkBox_MultiGPU_Waifu2xNCNNVulkan->isChecked()) - { - //==========多显卡========== - QMap GPUInfo = Waifu2x_NCNN_Vulkan_MultiGPU(); - //GPU ID - Waifu2x_NCNN_Vulkan_Settings_str.append("-g "+GPUInfo["ID"]+" "); - //Tile Size - Waifu2x_NCNN_Vulkan_Settings_str.append("-t "+GPUInfo["TileSize"]+" "); - } - //======================================= - return Waifu2x_NCNN_Vulkan_Settings_str; -} -/* -Waifu2x_NCNN_Vulkan -显卡切换 -*/ -QMap MainWindow::Waifu2x_NCNN_Vulkan_MultiGPU() -{ - MultiGPU_QMutex_Waifu2xNCNNVulkan.lock(); - int MAX_GPU_ID_Waifu2x_NCNN_Vulkan_MultiGPU = GPUIDs_List_MultiGPU_Waifu2xNCNNVulkan.size()-1; - if(GPU_ID_Waifu2x_NCNN_Vulkan_MultiGPU>MAX_GPU_ID_Waifu2x_NCNN_Vulkan_MultiGPU) - { - GPU_ID_Waifu2x_NCNN_Vulkan_MultiGPU=0; - } - //====== - QMap GPUInfo; - do - { - GPUInfo = GPUIDs_List_MultiGPU_Waifu2xNCNNVulkan.at(GPU_ID_Waifu2x_NCNN_Vulkan_MultiGPU); - if(GPUInfo["isEnabled"] != "true") - { - GPU_ID_Waifu2x_NCNN_Vulkan_MultiGPU++; - if(GPU_ID_Waifu2x_NCNN_Vulkan_MultiGPU>MAX_GPU_ID_Waifu2x_NCNN_Vulkan_MultiGPU) - { - GPU_ID_Waifu2x_NCNN_Vulkan_MultiGPU=0; - } - } - else - { - break; - } - } - while(true); - //====== - GPU_ID_Waifu2x_NCNN_Vulkan_MultiGPU++; - if(GPU_ID_Waifu2x_NCNN_Vulkan_MultiGPU>MAX_GPU_ID_Waifu2x_NCNN_Vulkan_MultiGPU) - { - GPU_ID_Waifu2x_NCNN_Vulkan_MultiGPU=0; - } - //====== - MultiGPU_QMutex_Waifu2xNCNNVulkan.unlock(); - return GPUInfo; -} - -void MainWindow::on_checkBox_MultiGPU_Waifu2xNCNNVulkan_clicked() -{ - if(ui->checkBox_MultiGPU_Waifu2xNCNNVulkan->isChecked()) - { - if(GPUIDs_List_MultiGPU_Waifu2xNCNNVulkan.size()==0) - { - QMessageBox *MSG = new QMessageBox(); - MSG->setWindowTitle(tr("Notification")); - MSG->setText(tr("Please detect available GPU ID before enable Multi-GPU.")); - MSG->setIcon(QMessageBox::Information); - MSG->setModal(true); - MSG->show(); - ui->checkBox_MultiGPU_Waifu2xNCNNVulkan->setChecked(0); - return; - } - if(GPUIDs_List_MultiGPU_Waifu2xNCNNVulkan.size()<2) - { - QMessageBox *MSG = new QMessageBox(); - MSG->setWindowTitle(tr("Error")); - MSG->setText(tr("Insufficient number of available GPUs.")); - MSG->setIcon(QMessageBox::Warning); - MSG->setModal(true); - MSG->show(); - ui->checkBox_MultiGPU_Waifu2xNCNNVulkan->setChecked(0); - return; - } - if(ui->comboBox_version_Waifu2xNCNNVulkan->currentIndex()!=0) - { - QMessageBox *MSG = new QMessageBox(); - MSG->setWindowTitle(tr("Warning")); - MSG->setText(tr("Old versions of Waifu2x-NCNN-Vulkan doesn't support Multi-GPUs when processing Video and GIF.")); - MSG->setIcon(QMessageBox::Warning); - MSG->setModal(true); - MSG->show(); - return; - } - } -} - -void MainWindow::AddGPU_MultiGPU_Waifu2xNCNNVulkan(QString GPUID) -{ - QMap GPUInfo; - GPUInfo["ID"] = GPUID; - GPUInfo["isEnabled"] = "true"; - GPUInfo["TileSize"] = "100"; - GPUIDs_List_MultiGPU_Waifu2xNCNNVulkan.append(GPUInfo); - ui->comboBox_GPUIDs_MultiGPU_Waifu2xNCNNVulkan->addItem(GPUID); - ui->comboBox_GPUIDs_MultiGPU_Waifu2xNCNNVulkan->setCurrentIndex(0); -} - -void MainWindow::on_comboBox_GPUIDs_MultiGPU_Waifu2xNCNNVulkan_currentIndexChanged(int index) -{ - if(ui->comboBox_GPUIDs_MultiGPU_Waifu2xNCNNVulkan->count()==0) - { - return; - } - QMap GPUInfo=GPUIDs_List_MultiGPU_Waifu2xNCNNVulkan.at(ui->comboBox_GPUIDs_MultiGPU_Waifu2xNCNNVulkan->currentIndex()); - ui->checkBox_isEnable_CurrentGPU_MultiGPU_Waifu2xNCNNVulkan->setChecked(GPUInfo["isEnabled"] == "true"); - ui->spinBox_TileSize_CurrentGPU_MultiGPU_Waifu2xNCNNVulkan->setValue(GPUInfo["TileSize"].toInt()); -} - -void MainWindow::on_spinBox_TileSize_CurrentGPU_MultiGPU_Waifu2xNCNNVulkan_valueChanged(int arg1) -{ - QMap GPUInfo=GPUIDs_List_MultiGPU_Waifu2xNCNNVulkan.at(ui->comboBox_GPUIDs_MultiGPU_Waifu2xNCNNVulkan->currentIndex()); - GPUInfo["TileSize"] = QString::number(ui->spinBox_TileSize_CurrentGPU_MultiGPU_Waifu2xNCNNVulkan->value(),10); - GPUIDs_List_MultiGPU_Waifu2xNCNNVulkan.replace(ui->comboBox_GPUIDs_MultiGPU_Waifu2xNCNNVulkan->currentIndex(),GPUInfo); -} - -void MainWindow::on_checkBox_isEnable_CurrentGPU_MultiGPU_Waifu2xNCNNVulkan_clicked() -{ - QMap GPUInfo=GPUIDs_List_MultiGPU_Waifu2xNCNNVulkan.at(ui->comboBox_GPUIDs_MultiGPU_Waifu2xNCNNVulkan->currentIndex()); - if(ui->checkBox_isEnable_CurrentGPU_MultiGPU_Waifu2xNCNNVulkan->isChecked()) - { - GPUInfo["isEnabled"] = "true"; - } - else - { - GPUInfo["isEnabled"] = "false"; - } - GPUIDs_List_MultiGPU_Waifu2xNCNNVulkan.replace(ui->comboBox_GPUIDs_MultiGPU_Waifu2xNCNNVulkan->currentIndex(),GPUInfo); - int enabledGPUs = 0; - for (int i=0; i GPUInfo_tmp = GPUIDs_List_MultiGPU_Waifu2xNCNNVulkan.at(i); - if(GPUInfo_tmp["isEnabled"] == "true") - { - enabledGPUs++; - } - } - if(enabledGPUs<2) - { - QMap GPUInfo=GPUIDs_List_MultiGPU_Waifu2xNCNNVulkan.at(ui->comboBox_GPUIDs_MultiGPU_Waifu2xNCNNVulkan->currentIndex()); - GPUInfo["isEnabled"] = "true"; - GPUIDs_List_MultiGPU_Waifu2xNCNNVulkan.replace(ui->comboBox_GPUIDs_MultiGPU_Waifu2xNCNNVulkan->currentIndex(),GPUInfo); - ui->checkBox_isEnable_CurrentGPU_MultiGPU_Waifu2xNCNNVulkan->setChecked(1); - QMessageBox *MSG = new QMessageBox(); - MSG->setWindowTitle(tr("Warning")); - MSG->setText(tr("At least 2 GPUs need to be enabled !!")); - MSG->setIcon(QMessageBox::Warning); - MSG->setModal(true); - MSG->show(); - } -} - -void MainWindow::on_checkBox_MultiGPU_Waifu2xNCNNVulkan_stateChanged(int arg1) -{ - if(ui->checkBox_MultiGPU_Waifu2xNCNNVulkan->isChecked()) - { - ui->comboBox_GPUID->setEnabled(0); - ui->frame_TileSize_W2xNcnnVulkan->setEnabled(0); - ui->groupBox_GPUSettings_MultiGPU_Waifu2xNCNNVulkan->setEnabled(1); - } - else - { - ui->comboBox_GPUID->setEnabled(1); - ui->frame_TileSize_W2xNcnnVulkan->setEnabled(1); - ui->groupBox_GPUSettings_MultiGPU_Waifu2xNCNNVulkan->setEnabled(0); - } -} - -void MainWindow::on_pushButton_ShowMultiGPUSettings_Waifu2xNCNNVulkan_clicked() -{ - int Max_GPU_ID = GPUIDs_List_MultiGPU_Waifu2xNCNNVulkan.size(); - QString MultiGPUSettings_str=""; - for(int GPU_ID=0; GPU_ID GPUInfo = GPUIDs_List_MultiGPU_Waifu2xNCNNVulkan.at(GPU_ID); - if(GPUInfo["isEnabled"] != "true") - { - continue; - } - else - { - MultiGPUSettings_str.append("GPU ID:["+GPUInfo["ID"]+"] | "+tr("Tile size:")+"["+GPUInfo["TileSize"]+"]\n\n"); - } - } - //========= - QMessageBox *MSG = new QMessageBox(); - MSG->setWindowTitle(tr("Current Multi-GPU settings")); - MSG->setText(MultiGPUSettings_str); - MSG->setIcon(QMessageBox::Information); - MSG->setModal(true); - MSG->show(); -} -/* -W2x NCNN Vulkan 块大小调整按钮 + -*/ -void MainWindow::on_pushButton_TileSize_Add_W2xNCNNVulkan_clicked() -{ - ui->spinBox_TileSize->setValue(AddTileSize_NCNNVulkan_Converter(ui->spinBox_TileSize->value())); -} -/* -W2x NCNN Vulkan 块大小调整按钮 - -*/ -void MainWindow::on_pushButton_TileSize_Minus_W2xNCNNVulkan_clicked() -{ - ui->spinBox_TileSize->setValue(MinusTileSize_NCNNVulkan_Converter(ui->spinBox_TileSize->value())); -} -/* -计算 临时放大倍率 -*/ -int MainWindow::Calculate_Temporary_ScaleRatio_W2xNCNNVulkan(int ScaleRatio) -{ - int ScaleRatio_tmp=0; - //如果设定的scaleRatio不是偶数,则+1,并输出到tmp - if((ScaleRatio%2)==0) - { - ScaleRatio_tmp = ScaleRatio; - } - else - { - ScaleRatio_tmp = ScaleRatio+1; - } - //判断是否为2的幂数 - if((ScaleRatio_tmp&(ScaleRatio_tmp-1))!=0) - { - for(int i=1; true; i++) - { - int pow_ =pow(2,i); - if(pow_>=ScaleRatio_tmp) - { - ScaleRatio_tmp=pow_; - break; - } - } - } - return ScaleRatio_tmp; -} -/* -读取配置讯息 Video GIF -*/ -QString MainWindow::Waifu2x_NCNN_Vulkan_ReadSettings_Video_GIF(int ThreadNum) -{ - QString Waifu2x_NCNN_Vulkan_Settings_str = " "; - //TTA - if(ui->checkBox_TTA_vulkan->isChecked()) - { - Waifu2x_NCNN_Vulkan_Settings_str.append("-x "); - } - if(ui->checkBox_MultiGPU_Waifu2xNCNNVulkan->isChecked()==true && ui->comboBox_version_Waifu2xNCNNVulkan->currentIndex()==0) - { - //==============多显卡================ - int NumOfGPUs_Available = GPUIDs_List_MultiGPU_Waifu2xNCNNVulkan.size();//获取显卡总数 - int NumOfGPUs_Enabled = 0; - QString GPU_ID_cmd = "-g "; - QString TileSize_cmd = "-t "; - for(int i=0; i GPUInfo = GPUIDs_List_MultiGPU_Waifu2xNCNNVulkan.at(i); - if(GPUInfo["isEnabled"] != "true")continue; - NumOfGPUs_Enabled++; - if(i==0) - { - GPU_ID_cmd.append(GPUInfo["ID"]); - TileSize_cmd.append(GPUInfo["TileSize"]); - } - else - { - GPU_ID_cmd.append(","+GPUInfo["ID"]); - TileSize_cmd.append(","+GPUInfo["TileSize"]); - } - } - Waifu2x_NCNN_Vulkan_Settings_str.append(GPU_ID_cmd+" "); - Waifu2x_NCNN_Vulkan_Settings_str.append(TileSize_cmd+" "); - //线程数量 - int NumOfThreads_PerGPU = ThreadNum/NumOfGPUs_Enabled; - if(NumOfThreads_PerGPU<1)NumOfThreads_PerGPU=1; - int LoadAndWrite_tnum = NumOfGPUs_Enabled*NumOfThreads_PerGPU; - QString Jobs_cmd = ""; - for(int i=0; icomboBox_GPUID->currentText()!="auto" && ui->checkBox_MultiGPU_Waifu2xNCNNVulkan->isChecked()==false) - { - Waifu2x_NCNN_Vulkan_Settings_str.append("-g "+ui->comboBox_GPUID->currentText()+" "); - } - //Tile Size - Waifu2x_NCNN_Vulkan_Settings_str.append("-t "+QString::number(ui->spinBox_TileSize->value(),10)+" "); - //线程数量 - QString jobs_num_str = QString("%1").arg(ThreadNum); - Waifu2x_NCNN_Vulkan_Settings_str.append("-j "+jobs_num_str+":"+jobs_num_str+":"+jobs_num_str+" "); - } - //Model - int ImageStyle = ui->comboBox_ImageStyle->currentIndex(); - QString model_path=""; - if(ui->comboBox_model_vulkan->currentIndex()==0) - { - if(ImageStyle==0) - { - model_path = Waifu2x_ncnn_vulkan_FolderPath+"/models-upconv_7_anime_style_art_rgb"; - } - else - { - model_path = Waifu2x_ncnn_vulkan_FolderPath+"/models-upconv_7_photo"; - } - } - if(ui->comboBox_model_vulkan->currentIndex()==1) - { - model_path = Waifu2x_ncnn_vulkan_FolderPath+"/models-cunet"; - } - Waifu2x_NCNN_Vulkan_Settings_str.append("-m \""+model_path+"\" "); - return Waifu2x_NCNN_Vulkan_Settings_str; -} -/* -计算 实际输入CMD的放大倍率 列表 -*/ -/* -QList MainWindow::Calculate_CMD_ScaleRatio_List_W2xNCNNVulkan(int ScaleRatio) -{ - QList CMD_ScaleRatio_List; - int ScaleRatio_MAX = Calculate_Temporary_ScaleRatio_W2xNCNNVulkan(ScaleRatio); - if(ScaleRatio_MAX<=32) - { - CMD_ScaleRatio_List.append(ScaleRatio_MAX); - return CMD_ScaleRatio_List; - } - int ScaleRatio_MAX_tmp = ScaleRatio_MAX/32; - CMD_ScaleRatio_List.append(32); - do - { - if(ScaleRatio_MAX_tmp/32 > 1) - { - ScaleRatio_MAX_tmp/=32; - CMD_ScaleRatio_List.append(32); - } - else - { - CMD_ScaleRatio_List.append(ScaleRatio_MAX_tmp); - break; - } - } - while(true); - return CMD_ScaleRatio_List; -} -*/ -/* -放大APNG - -Waifu2x-NCNN-Vulkan -*/ -bool MainWindow::APNG_Waifu2xNCNNVulkan(QString splitFramesFolder,QString scaledFramesFolder,QString sourceFileFullPath,QStringList framesFileName_qStrList,QString resultFileFullPath) -{ - //生成文件夹 - file_DelDir(scaledFramesFolder); - file_mkDir(scaledFramesFolder); - //============================================================ - //开始放大 - //读取放大倍数 - int ScaleRatio_Original = 2; - if(CustRes_isContained(sourceFileFullPath)) - { - QMap Res_map = CustRes_getResMap(sourceFileFullPath);//res_map["fullpath"],["height"],["width"] - ScaleRatio_Original = CustRes_CalNewScaleRatio(sourceFileFullPath,Res_map["height"].toInt(),Res_map["width"].toInt()); - } - else - { - ScaleRatio_Original = ui->doubleSpinBox_ScaleRatio_gif->value(); - } - int ScaleRatio_Max = Calculate_Temporary_ScaleRatio_W2xNCNNVulkan(ScaleRatio_Original); - bool isOverScaled = (ScaleRatio_Max!=ScaleRatio_Original); - //初始化进度讯息 - int NumOfSplitFrames = framesFileName_qStrList.size(); - if(ui->checkBox_ShowInterPro->isChecked()) - { - int NumOfRounds=0; - for(int ScaleRatio_Current_tmp=2; ScaleRatio_Current_tmp<=ScaleRatio_Max; ScaleRatio_Current_tmp*=2) - { - NumOfRounds++; - } - emit Send_CurrentFileProgress_Start(file_getBaseName(sourceFileFullPath)+"."+sourceFileFullPath.split(".").last(),NumOfSplitFrames*NumOfRounds); - } - //读取配置讯息 - QString Waifu2x_NCNN_Vulkan_Settings_str = Waifu2x_NCNN_Vulkan_ReadSettings_Video_GIF(ui->spinBox_ThreadNum_gif_internal->value()); - QProcess *Waifu2x = new QProcess(); - QString program = Waifu2x_ncnn_vulkan_ProgramPath; - bool waifu2x_qprocess_failed = false; - int DenoiseLevel_tmp = ui->spinBox_DenoiseLevel_gif->value(); - int CountFinishedRounds=0; - //==== - for(int ScaleRatio_Current_tmp=2; ScaleRatio_Current_tmp<=ScaleRatio_Max && framesFileName_qStrList.isEmpty()==false; ScaleRatio_Current_tmp*=2) - { - for(int retry=0; retry<(ui->spinBox_retry->value()+ForceRetryCount); retry++) - { - QString ErrorMSG=""; - QString StanderMSG=""; - //========== - waifu2x_qprocess_failed = false; - QString cmd = "\"" + program + "\"" + " -i " + "\"" + splitFramesFolder + "\"" + " -o " + "\"" + scaledFramesFolder + "\"" + " -s " + "2" + " -n " + QString::number(DenoiseLevel_tmp, 10) + Waifu2x_NCNN_Vulkan_Settings_str; - Waifu2x->start(cmd); - while(!Waifu2x->waitForStarted(100)&&!QProcess_stop) {} - while(!Waifu2x->waitForFinished(650)&&!QProcess_stop) - { - if(waifu2x_STOP) - { - Waifu2x->close(); - mutex_ThreadNumRunning.lock(); - ThreadNumRunning--; - mutex_ThreadNumRunning.unlock(); - return false;//中断,返回 - } - ErrorMSG.append(Waifu2x->readAllStandardError().toLower()); - StanderMSG.append(Waifu2x->readAllStandardOutput().toLower()); - if(ErrorMSG.contains("failed")||StanderMSG.contains("failed")) - { - waifu2x_qprocess_failed = true; - Waifu2x->close(); - break; - } - if(ui->checkBox_ShowInterPro->isChecked()) - { - emit Send_CurrentFileProgress_progressbar_SetFinishedValue((NumOfSplitFrames*CountFinishedRounds)+file_getFileNames_in_Folder_nofilter(scaledFramesFolder).size()); - } - } - //=============== - if(waifu2x_qprocess_failed==false) - { - ErrorMSG.append(Waifu2x->readAllStandardError().toLower()); - StanderMSG.append(Waifu2x->readAllStandardOutput().toLower()); - if(ErrorMSG.contains("failed")||StanderMSG.contains("failed")) - { - waifu2x_qprocess_failed = true; - } - } - //========= 检测是否成功,是否需要重试 ============ - if((NumOfSplitFrames == file_getFileNames_in_Folder_nofilter(scaledFramesFolder).size())&&!waifu2x_qprocess_failed) - { - break; - } - else - { - //失败 - file_DelDir(scaledFramesFolder); - file_mkDir(scaledFramesFolder); - if(retry==ui->spinBox_retry->value()+(ForceRetryCount-1))break; - emit Send_TextBrowser_NewMessage(tr("Automatic retry, please wait.")); - Delay_sec_sleep(5); - } - } - //=========== - //根据轮数修改参数 - DenoiseLevel_tmp = -1; - if(ScaleRatio_Current_tmp. + + My Github homepage: https://github.com/AaronFeng753 +*/ + +#include "mainwindow.h" +#include "ui_mainwindow.h" + +int MainWindow::Waifu2x_NCNN_Vulkan_Image(int rowNum,bool ReProcess_MissingAlphaChannel) +{ + //============================= 读取设置 ================================ + int DenoiseLevel = ui->spinBox_DenoiseLevel_image->value(); + bool DelOriginal = (ui->checkBox_DelOriginal->isChecked()||ui->checkBox_ReplaceOriginalFile->isChecked()); + QString OutPutPath_Final =""; + //========================= 拆解map得到参数 ============================= + //将状态设定到处理中 + emit Send_Table_image_ChangeStatus_rowNumInt_statusQString(rowNum, "Processing"); + //得到原文件路径 + QString SourceFile_fullPath = Table_model_image->item(rowNum,2)->text(); + if(!QFile::exists(SourceFile_fullPath))//判断源文件是否存在 + { + emit Send_TextBrowser_NewMessage(tr("Error occured when processing [")+SourceFile_fullPath+tr("]. Error: [File does not exist.]")); + emit Send_Table_image_ChangeStatus_rowNumInt_statusQString(rowNum, "Failed"); + emit Send_progressbar_Add(); + mutex_ThreadNumRunning.lock(); + ThreadNumRunning--; + mutex_ThreadNumRunning.unlock();//线程数量统计-1 + return 0; + } + //========= 转换到 PNG ========= + QString SourceFile_fullPath_Original = SourceFile_fullPath; + SourceFile_fullPath = Imgae_PreProcess(SourceFile_fullPath_Original,ReProcess_MissingAlphaChannel); + //=============== + int ScaleRatio=2; + bool CustRes_isEnabled = false; + int CustRes_height=0; + int CustRes_width=0; + //检查是是否有自定义分辨率 + if(CustRes_isContained(SourceFile_fullPath_Original)) + { + CustRes_isEnabled=true; + QMap Res_map = CustRes_getResMap(SourceFile_fullPath_Original);//res_map["fullpath"],["height"],["width"] + ScaleRatio = CustRes_CalNewScaleRatio(SourceFile_fullPath,Res_map["height"].toInt(),Res_map["width"].toInt()); + CustRes_height=Res_map["height"].toInt(); + CustRes_width=Res_map["width"].toInt(); + } + else + { + double ScaleRatio_double_tmp = ui->doubleSpinBox_ScaleRatio_image->value(); + if(ScaleRatio_double_tmp == (int)ScaleRatio_double_tmp) + { + ScaleRatio = qRound(ScaleRatio_double_tmp); + } + else + { + CustRes_isEnabled=true; + QMap Res_map = DoubleScaleRatio_Cal_NewScaleRatio_NewHW(SourceFile_fullPath,ScaleRatio_double_tmp); + //==== + if(Res_map.isEmpty()) + { + emit Send_TextBrowser_NewMessage(tr("Error occured when processing [")+SourceFile_fullPath+tr("]. Error: [Unable to read the resolution of the source file.]")); + emit Send_Table_image_ChangeStatus_rowNumInt_statusQString(rowNum, "Failed"); + emit Send_progressbar_Add(); + mutex_ThreadNumRunning.lock(); + ThreadNumRunning--; + mutex_ThreadNumRunning.unlock();//线程数量统计-1 + return 0; + } + //==== + ScaleRatio = Res_map["ScaleRatio"].toInt(); + CustRes_height = Res_map["Height_new"].toInt(); + CustRes_width = Res_map["width_new"].toInt(); + } + } + //=============== + QFileInfo fileinfo(SourceFile_fullPath); + QString file_name = file_getBaseName(SourceFile_fullPath); + QString file_ext = fileinfo.suffix(); + QString file_path = file_getFolderPath(fileinfo); + QString OutPut_Path = file_path + "/" + file_name + "_waifu2x_"+QString::number(ScaleRatio, 10)+"x_"+QString::number(DenoiseLevel, 10)+"n_"+file_ext+".png"; + //============================== 放大 ======================================= + QProcess *Waifu2x = new QProcess(); + QString Waifu2x_folder_path = Waifu2x_ncnn_vulkan_FolderPath; + QString program = Waifu2x_ncnn_vulkan_ProgramPath; + //========== + int ScaleRatio_tmp=Calculate_Temporary_ScaleRatio_W2xNCNNVulkan(ScaleRatio); + //====== + QString InputPath_tmp = SourceFile_fullPath; + QString OutputPath_tmp =""; + int DenoiseLevel_tmp = DenoiseLevel; + QString ErrorMSG=""; + QString StanderMSG=""; + QString cmd=""; + //====== + for(int retry=0; retry<(ui->spinBox_retry->value()+ForceRetryCount); retry++) + { + bool waifu2x_qprocess_failed = false; + InputPath_tmp = SourceFile_fullPath; + OutputPath_tmp =""; + DenoiseLevel_tmp = DenoiseLevel; + for(int i=2; i<=ScaleRatio_tmp; i*=2) + { + ErrorMSG=""; + StanderMSG=""; + //========== + OutputPath_tmp = file_path + "/" + file_name + "_waifu2x_"+QString::number(i, 10)+"x_"+QString::number(DenoiseLevel, 10)+"n_"+file_ext+".png"; + cmd = "\"" + program + "\"" + " -i " + "\"" + InputPath_tmp + "\"" + " -o " + "\"" + OutputPath_tmp + "\"" + " -s " + "2" + " -n " + QString::number(DenoiseLevel_tmp, 10) + Waifu2x_NCNN_Vulkan_ReadSettings(); + Waifu2x->start(cmd); + while(!Waifu2x->waitForStarted(100)&&!QProcess_stop) {} + while(!Waifu2x->waitForFinished(500)&&!QProcess_stop) + { + if(waifu2x_STOP) + { + Waifu2x->close(); + if(i>2) + { + QFile::remove(InputPath_tmp); + } + QFile::remove(OutputPath_tmp); + emit Send_Table_image_ChangeStatus_rowNumInt_statusQString(rowNum, "Interrupted"); + mutex_ThreadNumRunning.lock(); + ThreadNumRunning--; + mutex_ThreadNumRunning.unlock(); + return 0; + } + ErrorMSG.append(Waifu2x->readAllStandardError().toLower()); + StanderMSG.append(Waifu2x->readAllStandardOutput().toLower()); + if(ErrorMSG.contains("failed")||StanderMSG.contains("failed")) + { + waifu2x_qprocess_failed = true; + Waifu2x->close(); + if(i>2) + { + QFile::remove(InputPath_tmp); + } + QFile::remove(OutputPath_tmp); + break; + } + } + //=============== + if(waifu2x_qprocess_failed)break; + //=============== + ErrorMSG.append(Waifu2x->readAllStandardError().toLower()); + StanderMSG.append(Waifu2x->readAllStandardOutput().toLower()); + if(ErrorMSG.contains("failed")||StanderMSG.contains("failed")) + { + waifu2x_qprocess_failed = true; + if(i>2) + { + QFile::remove(InputPath_tmp); + } + QFile::remove(OutputPath_tmp); + break; + } + //=============== + if(i>2) + { + QFile::remove(InputPath_tmp); + } + DenoiseLevel_tmp = -1; + InputPath_tmp = OutputPath_tmp; + } + //========= 检测是否成功,是否需要重试 ============ + if(QFile::exists(OutputPath_tmp)&&!waifu2x_qprocess_failed) + { + break; + } + else + { + QFile::remove(OutputPath_tmp); + if(retry==ui->spinBox_retry->value()+(ForceRetryCount-1))break; + emit Send_TextBrowser_NewMessage(tr("Automatic retry, please wait.")); + Delay_sec_sleep(5); + } + } + if(!QFile::exists(OutputPath_tmp)) + { + if(SourceFile_fullPath_Original!=SourceFile_fullPath) + { + QFile::remove(SourceFile_fullPath); + } + emit Send_TextBrowser_NewMessage(tr("Error occured when processing [")+SourceFile_fullPath_Original+tr("]. Error: [Unable to scale the picture.]")); + emit Send_Table_image_ChangeStatus_rowNumInt_statusQString(rowNum, "Failed"); + emit Send_progressbar_Add(); + mutex_ThreadNumRunning.lock(); + ThreadNumRunning--; + mutex_ThreadNumRunning.unlock(); + return 0; + } + OutPutPath_Final = OutputPath_tmp; + //============================ 调整大小 ==================================================== + if(ScaleRatio_tmp != ScaleRatio||CustRes_isEnabled) + { + int New_height=0; + int New_width=0; + if(CustRes_isEnabled) + { + New_height= CustRes_height; + New_width= CustRes_width; + } + else + { + QMap res_map_OriginalFile = Image_Gif_Read_Resolution(SourceFile_fullPath); + New_height = res_map_OriginalFile["height"]*ScaleRatio; + New_width = res_map_OriginalFile["width"]*ScaleRatio; + } + QImage qimage_adj(OutputPath_tmp); + //读取放大后的图片并调整大小 + QImage qimage_adj_scaled = qimage_adj.scaled(New_width,New_height,CustRes_AspectRatioMode,Qt::SmoothTransformation); + QImageWriter qimageW_adj; + qimageW_adj.setFormat("png"); + qimageW_adj.setFileName(OutPut_Path); + if(qimageW_adj.canWrite()) + { + qimageW_adj.write(qimage_adj_scaled); + } + QFile::remove(OutputPath_tmp); + if(QFile::exists(OutPut_Path)==false) + { + emit Send_TextBrowser_NewMessage(tr("Error occured when processing [")+SourceFile_fullPath+tr("]. Error: [Unable to resize the scaled picture to the target size]")); + emit Send_Table_image_ChangeStatus_rowNumInt_statusQString(rowNum, "Failed"); + emit Send_progressbar_Add(); + mutex_ThreadNumRunning.lock(); + ThreadNumRunning--; + mutex_ThreadNumRunning.unlock();//线程数量统计-1 + return 0; + } + OutPutPath_Final = OutPut_Path; + } + if(CustRes_isEnabled) + { + QString OutPut_Path_CustRes = file_path + "/" + file_name + "_waifu2x_"+QString::number(CustRes_width, 10)+"x"+QString::number(CustRes_height, 10)+"_"+QString::number(DenoiseLevel, 10)+"n_"+file_ext+".png"; + QFile::remove(OutPut_Path_CustRes); + QFile::rename(OutPut_Path,OutPut_Path_CustRes); + OutPutPath_Final = OutPut_Path_CustRes; + } + //=========================== 另存为JPG&压缩JPG =========================================== + OutPutPath_Final = SaveImageAs_FormatAndQuality(SourceFile_fullPath_Original,OutPutPath_Final,true,DenoiseLevel); + //================== 检查是否丢失了透明通道 ===================== + if(ReProcess_MissingAlphaChannel==false && ui->comboBox_version_Waifu2xNCNNVulkan->currentIndex()==0) + { + QImage QImage_source(SourceFile_fullPath_Original); + QImage QImage_Final(OutPutPath_Final); + if(QImage_source.hasAlphaChannel()==true && QImage_Final.hasAlphaChannel()==false && ui->checkBox_AutoDetectAlphaChannel->isChecked()) + { + QFile::remove(OutPutPath_Final); + emit Send_TextBrowser_NewMessage(tr("Since the Alpha channel in the resulting image is lost, this image will be reprocessed to fix it:[")+SourceFile_fullPath_Original+tr("].\nIf the reprocessing happens a lot, you should consider enable [Always pre-process images with Alpha Channel] in [Additional settings].")); + return Waifu2x_NCNN_Vulkan_Image(rowNum,true); + } + } + //============================= 删除原文件 & 更新table status ============================ + if(SourceFile_fullPath_Original!=SourceFile_fullPath) + { + QFile::remove(SourceFile_fullPath); + SourceFile_fullPath = SourceFile_fullPath_Original; + } + if(DelOriginal) + { + if(ReplaceOriginalFile(SourceFile_fullPath,OutPutPath_Final)==false) + { + if(QAction_checkBox_MoveToRecycleBin_checkBox_DelOriginal->isChecked()) + { + file_MoveToTrash(SourceFile_fullPath); + } + else + { + QFile::remove(SourceFile_fullPath); + } + } + emit Send_Table_image_ChangeStatus_rowNumInt_statusQString(rowNum, "Finished, original file deleted"); + } + else + { + emit Send_Table_image_ChangeStatus_rowNumInt_statusQString(rowNum, "Finished"); + } + //========== 移动到输出路径 ========= + if(ui->checkBox_OutPath_isEnabled->isChecked()) + { + MoveFileToOutputPath(OutPutPath_Final,SourceFile_fullPath); + } + //============================ 更新进度条 ================================= + emit Send_progressbar_Add(); + //=========================== 更新线程数量统计============================== + mutex_ThreadNumRunning.lock(); + ThreadNumRunning--; + mutex_ThreadNumRunning.unlock();//线程数量统计-1 + return 0; +} + +/* + + ============================================================================================= + ============================================================================================= + ============================= Waifu2x_NCNN_Vulkan_GIF ======================================= + ============================================================================================= + ============================================================================================= + +*/ + +int MainWindow::Waifu2x_NCNN_Vulkan_GIF(int rowNum) +{ + //============================= 读取设置 ================================ + int ScaleRatio = ui->doubleSpinBox_ScaleRatio_gif->value(); + int DenoiseLevel = ui->spinBox_DenoiseLevel_gif->value(); + bool DelOriginal = (ui->checkBox_DelOriginal->isChecked()||ui->checkBox_ReplaceOriginalFile->isChecked()); + bool OptGIF = ui->checkBox_OptGIF->isChecked(); + QString OutPutPath_Final =""; + //========================= 拆解map得到参数 ============================= + emit Send_Table_gif_ChangeStatus_rowNumInt_statusQString(rowNum, "Processing"); + QString SourceFile_fullPath = Table_model_gif->item(rowNum,2)->text(); + if(!QFile::exists(SourceFile_fullPath)) + { + emit Send_TextBrowser_NewMessage(tr("Error occured when processing [")+SourceFile_fullPath+tr("]. Error: [File does not exist.]")); + emit Send_Table_gif_ChangeStatus_rowNumInt_statusQString(rowNum, "Failed"); + emit Send_progressbar_Add(); + return 0; + } + //========================== + bool CustRes_isEnabled = false; + int CustRes_height=0; + int CustRes_width=0; + if(CustRes_isContained(SourceFile_fullPath)) + { + CustRes_isEnabled=true; + QMap Res_map = CustRes_getResMap(SourceFile_fullPath);//res_map["fullpath"],["height"],["width"] + CustRes_height=Res_map["height"].toInt(); + CustRes_width=Res_map["width"].toInt(); + } + //========================== + QFileInfo fileinfo(SourceFile_fullPath); + QString file_name = file_getBaseName(SourceFile_fullPath); + QString file_ext = fileinfo.suffix(); + QString file_path = file_getFolderPath(fileinfo); + QString ResGIFPath = file_path + "/" + file_name + "_waifu2x_"+QString::number(ScaleRatio, 10)+"x_"+QString::number(DenoiseLevel, 10)+"n.gif"; + //=========================== 获取帧时间 ==================================== + int GIF_Duration = Gif_getDuration(SourceFile_fullPath); + if(GIF_Duration==0)//检查是否成功获取duration + { + emit Send_TextBrowser_NewMessage(tr("Error occured when processing [")+SourceFile_fullPath+tr("]. Error: [Can't get Duration value of GIF file.]")); + emit Send_Table_gif_ChangeStatus_rowNumInt_statusQString(rowNum, "Failed"); + emit Send_progressbar_Add(); + return 0;//如果启用stop位,则直接return + } + //============================== 拆分 ========================================== + QString SplitFramesFolderPath = file_path+"/"+file_name+"_SplitFrames_W2xEX";//拆分后存储frame的文件夹 + Gif_splitGif(SourceFile_fullPath,SplitFramesFolderPath); + //============================== 扫描获取文件名 =============================== + QStringList Frame_fileName_list = file_getFileNames_in_Folder_nofilter(SplitFramesFolderPath); + if(Frame_fileName_list.isEmpty())//检查是否成功拆分gif + { + emit Send_TextBrowser_NewMessage(tr("Error occured when processing [")+SourceFile_fullPath+tr("]. Error: [Can't split GIF into frames.]")); + emit Send_Table_gif_ChangeStatus_rowNumInt_statusQString(rowNum, "Failed"); + file_DelDir(SplitFramesFolderPath); + emit Send_progressbar_Add(); + return 0;//如果启用stop位,则直接return + } + //===========建立存储放大后frame的文件夹=========== + QString ScaledFramesFolderPath = SplitFramesFolderPath+"/ScaledFrames_W2xEX"; + file_DelDir(ScaledFramesFolderPath); + file_mkDir(ScaledFramesFolderPath); + //==========开始放大========================== + //读取放大倍数 + int ScaleRatio_Original = 2; + if(CustRes_isEnabled == true) + { + ScaleRatio_Original = CustRes_CalNewScaleRatio(SourceFile_fullPath,CustRes_height,CustRes_width); + } + else + { + ScaleRatio_Original = ui->doubleSpinBox_ScaleRatio_gif->value(); + } + int ScaleRatio_Max=Calculate_Temporary_ScaleRatio_W2xNCNNVulkan(ScaleRatio_Original); + bool isOverScaled = (ScaleRatio_Max!=ScaleRatio_Original); + //初始化进度讯息 + int NumOfSplitFrames = Frame_fileName_list.size(); + if(ui->checkBox_ShowInterPro->isChecked()) + { + int NumOfRounds=0; + for(int ScaleRatio_Current_tmp=2; ScaleRatio_Current_tmp<=ScaleRatio_Max; ScaleRatio_Current_tmp*=2) + { + NumOfRounds++; + } + emit Send_CurrentFileProgress_Start(file_name+"."+file_ext,NumOfSplitFrames*NumOfRounds); + } + //读取配置讯息 + QString Waifu2x_NCNN_Vulkan_Settings_str = Waifu2x_NCNN_Vulkan_ReadSettings_Video_GIF(ui->spinBox_ThreadNum_gif_internal->value()); + QProcess *Waifu2x = new QProcess(); + QString program = Waifu2x_ncnn_vulkan_ProgramPath; + bool waifu2x_qprocess_failed = false; + int DenoiseLevel_tmp = DenoiseLevel; + DenoiseLevel_tmp = DenoiseLevel; + int CountFinishedRounds=0; + //==== + for(int ScaleRatio_Current_tmp=2; ScaleRatio_Current_tmp<=ScaleRatio_Max && Frame_fileName_list.isEmpty()==false; ScaleRatio_Current_tmp*=2) + { + for(int retry=0; retry<(ui->spinBox_retry->value()+ForceRetryCount); retry++) + { + QString ErrorMSG=""; + QString StanderMSG=""; + //========== + waifu2x_qprocess_failed = false; + QString cmd = "\"" + program + "\"" + " -i " + "\"" + SplitFramesFolderPath + "\"" + " -o " + "\"" + ScaledFramesFolderPath + "\"" + " -s " + "2" + " -n " + QString::number(DenoiseLevel_tmp, 10) + Waifu2x_NCNN_Vulkan_Settings_str; + Waifu2x->start(cmd); + while(!Waifu2x->waitForStarted(100)&&!QProcess_stop) {} + while(!Waifu2x->waitForFinished(650)&&!QProcess_stop) + { + if(waifu2x_STOP) + { + Waifu2x->close(); + file_DelDir(SplitFramesFolderPath); + emit Send_Table_gif_ChangeStatus_rowNumInt_statusQString(rowNum, "Interrupted"); + mutex_ThreadNumRunning.lock(); + ThreadNumRunning--; + mutex_ThreadNumRunning.unlock(); + return 0; + } + ErrorMSG.append(Waifu2x->readAllStandardError().toLower()); + StanderMSG.append(Waifu2x->readAllStandardOutput().toLower()); + if(ErrorMSG.contains("failed")||StanderMSG.contains("failed")) + { + waifu2x_qprocess_failed = true; + Waifu2x->close(); + break; + } + if(ui->checkBox_ShowInterPro->isChecked()) + { + emit Send_CurrentFileProgress_progressbar_SetFinishedValue((NumOfSplitFrames*CountFinishedRounds)+file_getFileNames_in_Folder_nofilter(ScaledFramesFolderPath).size()); + } + } + //=============== + if(waifu2x_qprocess_failed==false) + { + ErrorMSG.append(Waifu2x->readAllStandardError().toLower()); + StanderMSG.append(Waifu2x->readAllStandardOutput().toLower()); + if(ErrorMSG.contains("failed")||StanderMSG.contains("failed")) + { + waifu2x_qprocess_failed = true; + } + } + //========= 检测是否成功,是否需要重试 ============ + if((NumOfSplitFrames == file_getFileNames_in_Folder_nofilter(ScaledFramesFolderPath).size())&&!waifu2x_qprocess_failed) + { + break; + } + else + { + //失败 + file_DelDir(ScaledFramesFolderPath); + file_mkDir(ScaledFramesFolderPath); + if(retry==ui->spinBox_retry->value()+(ForceRetryCount-1))break; + emit Send_TextBrowser_NewMessage(tr("Automatic retry, please wait.")); + Delay_sec_sleep(5); + } + } + //=========== + //根据轮数修改参数 + DenoiseLevel_tmp = -1; + if(ScaleRatio_Current_tmpisChecked()) + { + file_MoveToTrash(SourceFile_fullPath); + } + else + { + QFile::remove(SourceFile_fullPath); + } + } + emit Send_Table_gif_ChangeStatus_rowNumInt_statusQString(rowNum, "Finished, original file deleted"); + } + else + { + emit Send_Table_gif_ChangeStatus_rowNumInt_statusQString(rowNum, "Finished"); + } + //========== 移动到输出路径 ========= + if(ui->checkBox_OutPath_isEnabled->isChecked()) + { + MoveFileToOutputPath(OutPutPath_Final,SourceFile_fullPath); + } + //============================ 更新进度条 ================================= + emit Send_progressbar_Add(); + //=========================== ============================== + return 0; +} + +/* + + ============================================================================================= + ============================================================================================= + ============================= Waifu2x_NCNN_Vulkan_Video ======================================= + ============================================================================================= + ============================================================================================= + + +*/ + +int MainWindow::Waifu2x_NCNN_Vulkan_Video(int rowNum) +{ + //============================= 读取设置 ================================ + int ScaleRatio = ui->doubleSpinBox_ScaleRatio_video->value(); + int DenoiseLevel = ui->spinBox_DenoiseLevel_video->value(); + bool DelOriginal = (ui->checkBox_DelOriginal->isChecked()||ui->checkBox_ReplaceOriginalFile->isChecked()); + bool isCacheExists = false; + bool isVideoConfigChanged = true; + //========================= 拆解map得到参数 ============================= + emit Send_Table_video_ChangeStatus_rowNumInt_statusQString(rowNum, "Processing"); + QString SourceFile_fullPath = Table_model_video->item(rowNum,2)->text(); + if(!QFile::exists(SourceFile_fullPath)) + { + emit Send_TextBrowser_NewMessage(tr("Error occured when processing [")+SourceFile_fullPath+tr("]. Error: [File does not exist.]")); + emit Send_Table_video_ChangeStatus_rowNumInt_statusQString(rowNum, "Failed"); + emit Send_progressbar_Add(); + return 0; + } + //========================== + QFileInfo fileinfo_SourceFile_fullPath(SourceFile_fullPath); + QString SourceFile_fullPath_BaseName = file_getBaseName(SourceFile_fullPath); + QString SourceFile_fullPath_suffix = fileinfo_SourceFile_fullPath.suffix(); + QString SourceFile_fullPath_FolderPath = file_getFolderPath(fileinfo_SourceFile_fullPath); + //=================================================================== + //生成mp4 + QString video_mp4_fullpath=video_To_CFRMp4(SourceFile_fullPath); + if(!QFile::exists(video_mp4_fullpath))//检查是否成功生成mp4 + { + emit Send_TextBrowser_NewMessage(tr("Error occured when processing [")+SourceFile_fullPath+tr("]. Error: [Cannot convert video format to mp4.]")); + emit Send_Table_video_ChangeStatus_rowNumInt_statusQString(rowNum, "Failed"); + emit Send_progressbar_Add(); + return 0;//如果启用stop位,则直接return + } + //=========== 读取自定义分辨率 =============== + bool CustRes_isEnabled = false; + int CustRes_height=0; + int CustRes_width=0; + if(CustRes_isContained(SourceFile_fullPath)) + { + CustRes_isEnabled=true; + QMap Res_map = CustRes_getResMap(SourceFile_fullPath);//res_map["fullpath"],["height"],["width"] + CustRes_height=Res_map["height"].toInt(); + CustRes_width=Res_map["width"].toInt(); + } + //================= + QString AudioPath = SourceFile_fullPath_FolderPath+"/Audio_"+SourceFile_fullPath_BaseName+"_"+SourceFile_fullPath_suffix+"_W2xEX.wav";//音频 + QString SplitFramesFolderPath = SourceFile_fullPath_FolderPath+"/"+SourceFile_fullPath_BaseName+"_"+SourceFile_fullPath_suffix+"_SplitFrames_W2xEX";//拆分后存储frame的文件夹 + QString ScaledFramesFolderPath = SplitFramesFolderPath+"/ScaledFrames_W2xEX";//存储放大后的帧 + //========================== + // 检测之前的视频配置文件 + //========================== + QString VideoConfiguration_fullPath = SourceFile_fullPath_FolderPath+"/VideoConfiguration_"+SourceFile_fullPath_BaseName+"_"+SourceFile_fullPath_suffix+"_Waifu2xEX.ini"; + if(QFile::exists(VideoConfiguration_fullPath)) + { + QSettings *configIniRead = new QSettings(VideoConfiguration_fullPath, QSettings::IniFormat); + configIniRead->setIniCodec(QTextCodec::codecForName("UTF-8")); + //=================== 加载之前存储的视频信息 ========================= + int ScaleRatio_old = configIniRead->value("/VideoConfiguration/ScaleRatio").toInt(); + int DenoiseLevel_old = configIniRead->value("/VideoConfiguration/DenoiseLevel").toInt(); + bool CustRes_isEnabled_old = configIniRead->value("/VideoConfiguration/CustRes_isEnabled").toBool(); + int CustRes_height_old = configIniRead->value("/VideoConfiguration/CustRes_height").toInt(); + int CustRes_width_old = configIniRead->value("/VideoConfiguration/CustRes_width").toInt(); + QString EngineName_old = configIniRead->value("/VideoConfiguration/EngineName").toString(); + bool isProcessBySegment_old = configIniRead->value("/VideoConfiguration/isProcessBySegment").toBool(); + //=================== 比对信息 ================================ + if(EngineName_old=="waifu2x-ncnn-vulkan") + { + if(CustRes_isEnabled_old==false&&CustRes_isEnabled==false) + { + if(ScaleRatio_old!=ScaleRatio||DenoiseLevel_old!=DenoiseLevel) + { + isVideoConfigChanged=true; + } + else + { + isVideoConfigChanged=false; + } + } + else + { + if(CustRes_isEnabled_old==true&&CustRes_isEnabled==true) + { + if(CustRes_height_old!=CustRes_height||CustRes_width_old!=CustRes_width) + { + isVideoConfigChanged=true; + } + else + { + isVideoConfigChanged=false; + } + } + else + { + isVideoConfigChanged=true; + } + } + if(isProcessBySegment_old==true) + { + isVideoConfigChanged=true; + } + } + else + { + isVideoConfigChanged=true; + } + } + else + { + emit Send_video_write_VideoConfiguration(VideoConfiguration_fullPath,ScaleRatio,DenoiseLevel,CustRes_isEnabled,CustRes_height,CustRes_width,"waifu2x-ncnn-vulkan",false,"","",ui->groupBox_FrameInterpolation->isChecked(),0); + } + //======================= + // 检测缓存是否存在 + //======================= + if(QFile::exists(video_mp4_fullpath)&&file_isDirExist(SplitFramesFolderPath)&&file_isDirExist(ScaledFramesFolderPath)&&QFile::exists(VideoConfiguration_fullPath)) + { + if(!isVideoConfigChanged) + { + isCacheExists=true; + emit Send_TextBrowser_NewMessage(tr("The previous video cache file is detected and processing of the previous video cache will continue. If you want to restart processing of the current video:[")+SourceFile_fullPath+tr("], delete the cache manually.")); + } + else + { + isCacheExists=false; + //======== + QFile::remove(VideoConfiguration_fullPath); + file_DelDir(SplitFramesFolderPath); + QFile::remove(AudioPath); + DelVfiDir(video_mp4_fullpath); + emit Send_video_write_VideoConfiguration(VideoConfiguration_fullPath,ScaleRatio,DenoiseLevel,CustRes_isEnabled,CustRes_height,CustRes_width,"waifu2x-ncnn-vulkan",false,"","",ui->groupBox_FrameInterpolation->isChecked(),0); + //======= + emit Send_TextBrowser_NewMessage(tr("The previous video cache file was detected, but because you changed the settings about the video resolution or denoise level, the previous cache will be deleted and processing of the video:[")+SourceFile_fullPath+tr("] will restart.")); + } + } + else + { + isCacheExists=false; + //======== + QFile::remove(VideoConfiguration_fullPath); + file_DelDir(SplitFramesFolderPath); + QFile::remove(AudioPath); + DelVfiDir(video_mp4_fullpath); + emit Send_video_write_VideoConfiguration(VideoConfiguration_fullPath,ScaleRatio,DenoiseLevel,CustRes_isEnabled,CustRes_height,CustRes_width,"waifu2x-ncnn-vulkan",false,"","",ui->groupBox_FrameInterpolation->isChecked(),0); + //======== + } + if(!isCacheExists) + { + //============================== 拆分 ========================================== + if(file_isDirExist(SplitFramesFolderPath)) + { + file_DelDir(SplitFramesFolderPath); + file_mkDir(SplitFramesFolderPath); + } + else + { + file_mkDir(SplitFramesFolderPath); + } + QFile::remove(AudioPath); + video_video2images(video_mp4_fullpath,SplitFramesFolderPath,AudioPath); + if(waifu2x_STOP) + { + emit Send_Table_video_ChangeStatus_rowNumInt_statusQString(rowNum, "Interrupted"); + return 0;//如果启用stop位,则直接return + } + } + //============================== 扫描获取文件名 =============================== + QStringList Frame_fileName_list = file_getFileNames_in_Folder_nofilter(SplitFramesFolderPath); + if(!isCacheExists) + { + if(Frame_fileName_list.isEmpty())//检查是否成功拆分为帧 + { + emit Send_TextBrowser_NewMessage(tr("Error occured when processing [")+SourceFile_fullPath+tr("]. Error: [Unable to split video into pictures.]")); + emit Send_Table_video_ChangeStatus_rowNumInt_statusQString(rowNum, "Failed"); + emit Send_progressbar_Add(); + return 0;//如果启用stop位,则直接return + } + } + //============================== 放大 ======================================= + //===========建立存储放大后frame的文件夹=========== + if(!isCacheExists) + { + if(file_isDirExist(ScaledFramesFolderPath)) + { + file_DelDir(ScaledFramesFolderPath); + file_mkDir(ScaledFramesFolderPath); + } + else + { + file_mkDir(ScaledFramesFolderPath); + } + } + //==========开始放大========================== + //读取放大倍数 + int ScaleRatio_Original = 2; + if(CustRes_isEnabled == true) + { + ScaleRatio_Original = CustRes_CalNewScaleRatio(video_mp4_fullpath,CustRes_height,CustRes_width); + } + else + { + ScaleRatio_Original = ui->doubleSpinBox_ScaleRatio_video->value(); + } + int ScaleRatio_Max=Calculate_Temporary_ScaleRatio_W2xNCNNVulkan(ScaleRatio_Original); + bool isOverScaled = (ScaleRatio_Max!=ScaleRatio_Original); + //读取初始放大倍率 + int Initial_ScaleRatio = 2; + if(!Frame_fileName_list.isEmpty()) + { + QString Full_Path_File = ""; + for(int i = 0; i < Frame_fileName_list.size(); i++) + { + QString tmp = Frame_fileName_list.at(i); + Full_Path_File = SplitFramesFolderPath + "/" + tmp; + QFileInfo finfo(Full_Path_File); + if(finfo.suffix()=="png")break; + } + QImage qimage_original; + qimage_original.load(Full_Path_File); + int Frame_height = qimage_original.height(); + QMap res_map = video_get_Resolution(SourceFile_fullPath); + int Video_height = res_map["height"]; + if(Frame_height>0 && Video_height>0 && Frame_height>=Video_height)//判断是否读取失败 + { + Initial_ScaleRatio = 2*(Frame_height/Video_height); + } + } + //初始化进度讯息 + int NumOfSplitFrames = Frame_fileName_list.size()+file_getFileNames_in_Folder_nofilter(ScaledFramesFolderPath).size(); + if(ui->checkBox_ShowInterPro->isChecked()) + { + int NumOfRounds=0; + for(int ScaleRatio_Current_tmp=Initial_ScaleRatio; ScaleRatio_Current_tmp<=ScaleRatio_Max; ScaleRatio_Current_tmp*=2) + { + NumOfRounds++; + } + emit Send_CurrentFileProgress_Start(SourceFile_fullPath_BaseName+"."+SourceFile_fullPath_suffix,NumOfSplitFrames*NumOfRounds); + } + //读取配置讯息 + QString Waifu2x_NCNN_Vulkan_Settings_str = ""; + QString cmd=""; + QProcess *Waifu2x = new QProcess(); + QString program = Waifu2x_ncnn_vulkan_ProgramPath; + bool waifu2x_qprocess_failed = false; + int DenoiseLevel_tmp = DenoiseLevel; + DenoiseLevel_tmp = DenoiseLevel; + int CountFinishedRounds=0; + //==== + for(int ScaleRatio_Current_tmp=Initial_ScaleRatio; ScaleRatio_Current_tmp<=ScaleRatio_Max && Frame_fileName_list.isEmpty()==false; ScaleRatio_Current_tmp*=2) + { + for(int retry=0; retry<(ui->spinBox_retry->value()+ForceRetryCount); retry++) + { + QString ErrorMSG=""; + QString StanderMSG=""; + //========== + waifu2x_qprocess_failed = false; + Waifu2x_NCNN_Vulkan_Settings_str = Waifu2x_NCNN_Vulkan_ReadSettings_Video_GIF(ui->spinBox_ThreadNum_video_internal->value()); + cmd = "\"" + program + "\"" + " -i " + "\"" + SplitFramesFolderPath + "\"" + " -o " + "\"" + ScaledFramesFolderPath + "\"" + " -s " + "2" + " -n " + QString::number(DenoiseLevel_tmp, 10) + Waifu2x_NCNN_Vulkan_Settings_str; + Waifu2x->start(cmd); + while(!Waifu2x->waitForStarted(100)&&!QProcess_stop) {} + while(!Waifu2x->waitForFinished(650)&&!QProcess_stop) + { + if(waifu2x_STOP) + { + QStringList FinfishedFileList_FileNames = WaitForEngineIO_NcnnVulkan(ScaledFramesFolderPath); + Waifu2x->close(); + //============ + QString file_name_tmp; + QStringList FileNames_ScaledFramesFolderPath = file_getFileNames_in_Folder_nofilter(ScaledFramesFolderPath); + for(int i=0; ireadAllStandardError().toLower()); + StanderMSG.append(Waifu2x->readAllStandardOutput().toLower()); + if(ErrorMSG.contains("failed")||StanderMSG.contains("failed")) + { + waifu2x_qprocess_failed = true; + Waifu2x->close(); + break; + } + if(ui->checkBox_ShowInterPro->isChecked()) + { + emit Send_CurrentFileProgress_progressbar_SetFinishedValue((NumOfSplitFrames*CountFinishedRounds)+file_getFileNames_in_Folder_nofilter(ScaledFramesFolderPath).size()); + } + } + //=============== + if(waifu2x_qprocess_failed==false) + { + ErrorMSG.append(Waifu2x->readAllStandardError().toLower()); + StanderMSG.append(Waifu2x->readAllStandardOutput().toLower()); + if(ErrorMSG.contains("failed")||StanderMSG.contains("failed")) + { + waifu2x_qprocess_failed = true; + } + } + //========= 检测是否成功,是否需要重试 ============ + if((NumOfSplitFrames == file_getFileNames_in_Folder_nofilter(ScaledFramesFolderPath).size())&&!waifu2x_qprocess_failed) + { + break; + } + else + { + //失败 + file_DelDir(ScaledFramesFolderPath); + file_mkDir(ScaledFramesFolderPath); + if(retry==ui->spinBox_retry->value()+(ForceRetryCount-1))break; + emit Send_TextBrowser_NewMessage(tr("Automatic retry, please wait.")); + Delay_sec_sleep(5); + } + } + //=========== + //根据轮数修改参数 + DenoiseLevel_tmp = -1; + if(ScaleRatio_Current_tmpcheckBox_KeepVideoCache->isChecked()==false) + { + QFile::remove(VideoConfiguration_fullPath); + file_DelDir(SplitFramesFolderPath); + QFile::remove(AudioPath); + if(SourceFile_fullPath!=video_mp4_fullpath)QFile::remove(video_mp4_fullpath); + } + else + { + DelOriginal=false; + } + //============================= 删除原文件 & & 更新table status ============================ + if(DelOriginal) + { + if(ReplaceOriginalFile(SourceFile_fullPath,video_mp4_scaled_fullpath)==false) + { + if(QAction_checkBox_MoveToRecycleBin_checkBox_DelOriginal->isChecked()) + { + file_MoveToTrash(SourceFile_fullPath); + } + else + { + QFile::remove(SourceFile_fullPath); + } + } + emit Send_Table_video_ChangeStatus_rowNumInt_statusQString(rowNum, "Finished, original file deleted"); + } + else + { + emit Send_Table_video_ChangeStatus_rowNumInt_statusQString(rowNum, "Finished"); + } + //========== 移动到输出路径 ========= + if(ui->checkBox_OutPath_isEnabled->isChecked()) + { + MoveFileToOutputPath(video_mp4_scaled_fullpath,SourceFile_fullPath); + } + //============================ 更新进度条 ================================= + emit Send_progressbar_Add(); + //=========================== ============================== + return 0; +} +/* +#### 分段处理 #### +调用Waifu2x-NCNN-Vulkan处理视频 +读取设置,拆分,创建放大子线程,组装视频 +*/ +int MainWindow::Waifu2x_NCNN_Vulkan_Video_BySegment(int rowNum) +{ + //============================= 读取设置 ================================ + int ScaleRatio = ui->doubleSpinBox_ScaleRatio_video->value(); + int DenoiseLevel = ui->spinBox_DenoiseLevel_video->value(); + bool DelOriginal = (ui->checkBox_DelOriginal->isChecked()||ui->checkBox_ReplaceOriginalFile->isChecked()); + bool isCacheExists = false; + bool isVideoConfigChanged = true; + int SegmentDuration = ui->spinBox_SegmentDuration->value(); + //========================= 拆解map得到参数 ============================= + emit Send_Table_video_ChangeStatus_rowNumInt_statusQString(rowNum, "Processing"); + QString SourceFile_fullPath = Table_model_video->item(rowNum,2)->text(); + if(!QFile::exists(SourceFile_fullPath)) + { + emit Send_TextBrowser_NewMessage(tr("Error occured when processing [")+SourceFile_fullPath+tr("]. Error: [File does not exist.]")); + emit Send_Table_video_ChangeStatus_rowNumInt_statusQString(rowNum, "Failed"); + emit Send_progressbar_Add(); + return 0; + } + //========================== + QFileInfo fileinfo(SourceFile_fullPath); + QString file_name = file_getBaseName(SourceFile_fullPath); + QString file_ext = fileinfo.suffix(); + QString file_path = file_getFolderPath(fileinfo); + //=================================================================== + //生成mp4 + QString video_mp4_fullpath=video_To_CFRMp4(SourceFile_fullPath); + if(!QFile::exists(video_mp4_fullpath))//检查是否成功生成mp4 + { + emit Send_TextBrowser_NewMessage(tr("Error occured when processing [")+SourceFile_fullPath+tr("]. Error: [Cannot convert video format to mp4.]")); + emit Send_Table_video_ChangeStatus_rowNumInt_statusQString(rowNum, "Failed"); + emit Send_progressbar_Add(); + return 0;//如果启用stop位,则直接return + } + //============ 读取自定义分辨率 ============== + bool CustRes_isEnabled = false; + int CustRes_height=0; + int CustRes_width=0; + if(CustRes_isContained(SourceFile_fullPath)) + { + CustRes_isEnabled=true; + QMap Res_map = CustRes_getResMap(SourceFile_fullPath);//res_map["fullpath"],["height"],["width"] + CustRes_height=Res_map["height"].toInt(); + CustRes_width=Res_map["width"].toInt(); + } + //================= + QString AudioPath = file_path+"/Audio_"+file_name+"_"+file_ext+"_W2xEX.wav";//音频 + QString SplitFramesFolderPath = file_path+"/"+file_name+"_"+file_ext+"_SplitFrames_W2xEX";//拆分后存储frame的文件夹 + QString ScaledFramesFolderPath = SplitFramesFolderPath+"/ScaledFrames_W2xEX";//存储放大后的帧 + //=== + QString VideoClipsFolderPath = "";//存储视频片段的文件夹(完整路径) + QString DateStr = ""; + do + { + DateStr = video_getClipsFolderNo(); + VideoClipsFolderPath = file_path+"/"+DateStr+"_VideoClipsWaifu2xEX";//存储视频片段的文件夹(完整路径) + } + while(file_isDirExist(VideoClipsFolderPath)); + QString VideoClipsFolderName = DateStr+"_VideoClipsWaifu2xEX";//存储视频片段的文件夹(名称) + //========================== + // 检测之前的视频配置文件 + //========================== + QString VideoConfiguration_fullPath = file_path+"/VideoConfiguration_"+file_name+"_"+file_ext+"_Waifu2xEX.ini"; + if(QFile::exists(VideoConfiguration_fullPath)) + { + QSettings *configIniRead = new QSettings(VideoConfiguration_fullPath, QSettings::IniFormat); + configIniRead->setIniCodec(QTextCodec::codecForName("UTF-8")); + //=================== 加载之前存储的视频信息 ========================= + int ScaleRatio_old = configIniRead->value("/VideoConfiguration/ScaleRatio").toInt(); + int DenoiseLevel_old = configIniRead->value("/VideoConfiguration/DenoiseLevel").toInt(); + bool CustRes_isEnabled_old = configIniRead->value("/VideoConfiguration/CustRes_isEnabled").toBool(); + int CustRes_height_old = configIniRead->value("/VideoConfiguration/CustRes_height").toInt(); + int CustRes_width_old = configIniRead->value("/VideoConfiguration/CustRes_width").toInt(); + QString EngineName_old = configIniRead->value("/VideoConfiguration/EngineName").toString(); + bool isProcessBySegment_old = configIniRead->value("/VideoConfiguration/isProcessBySegment").toBool(); + bool isVideoFrameInterpolationEnabled_old = configIniRead->value("/VideoConfiguration/isVideoFrameInterpolationEnabled").toBool(); + int MultipleOfFPS_old = configIniRead->value("/VideoConfiguration/MultipleOfFPS").toInt(); + //=================== 比对信息 ================================ + if(EngineName_old=="waifu2x-ncnn-vulkan") + { + if(CustRes_isEnabled_old==false&&CustRes_isEnabled==false) + { + if(ScaleRatio_old!=ScaleRatio||DenoiseLevel_old!=DenoiseLevel) + { + isVideoConfigChanged=true; + } + else + { + isVideoConfigChanged=false; + } + } + else + { + if(CustRes_isEnabled_old==true&&CustRes_isEnabled==true) + { + if(CustRes_height_old!=CustRes_height||CustRes_width_old!=CustRes_width) + { + isVideoConfigChanged=true; + } + else + { + isVideoConfigChanged=false; + } + } + else + { + isVideoConfigChanged=true; + } + } + if(isProcessBySegment_old == false) + { + isVideoConfigChanged=true; + } + if(isVideoFrameInterpolationEnabled_old != ui->groupBox_FrameInterpolation->isChecked()) + { + isVideoConfigChanged=true; + } + if(MultipleOfFPS_old != ui->spinBox_MultipleOfFPS_VFI->value() && ui->groupBox_FrameInterpolation->isChecked()) + { + isVideoConfigChanged=true; + } + } + else + { + isVideoConfigChanged=true; + } + //============ 修正文件夹名称 ============= + QString VideoClipsFolderPath_old = configIniRead->value("/VideoConfiguration/VideoClipsFolderPath").toString(); + QString VideoClipsFolderName_old = configIniRead->value("/VideoConfiguration/VideoClipsFolderName").toString(); + file_mkDir(VideoClipsFolderPath_old); + if(file_isDirExist(VideoClipsFolderPath_old)==true) + { + VideoClipsFolderPath = VideoClipsFolderPath_old; + VideoClipsFolderName = VideoClipsFolderName_old; + } + } + else + { + emit Send_video_write_VideoConfiguration(VideoConfiguration_fullPath,ScaleRatio,DenoiseLevel,CustRes_isEnabled,CustRes_height,CustRes_width,"waifu2x-ncnn-vulkan",true,VideoClipsFolderPath,VideoClipsFolderName,ui->groupBox_FrameInterpolation->isChecked(),ui->spinBox_MultipleOfFPS_VFI->value()); + } + //======================= + // 检测缓存是否存在 + //======================= + if(file_isDirExist(SplitFramesFolderPath)) + { + if(!isVideoConfigChanged) + { + isCacheExists=true; + emit Send_TextBrowser_NewMessage(tr("The previous video cache file is detected and processing of the previous video cache will continue. If you want to restart processing of the current video:[")+SourceFile_fullPath+tr("], delete the cache manually.")); + } + else + { + isCacheExists=false; + //======== + QFile::remove(VideoConfiguration_fullPath); + file_DelDir(SplitFramesFolderPath); + file_DelDir(VideoClipsFolderPath); + QFile::remove(AudioPath); + DelVfiDir(video_mp4_fullpath); + emit Send_video_write_VideoConfiguration(VideoConfiguration_fullPath,ScaleRatio,DenoiseLevel,CustRes_isEnabled,CustRes_height,CustRes_width,"waifu2x-ncnn-vulkan",true,VideoClipsFolderPath,VideoClipsFolderName,ui->groupBox_FrameInterpolation->isChecked(),ui->spinBox_MultipleOfFPS_VFI->value()); + //======= + emit Send_TextBrowser_NewMessage(tr("The previous video cache file was detected, but because you changed the settings about the video resolution or denoise level, the previous cache will be deleted and processing of the video:[")+SourceFile_fullPath+tr("] will restart.")); + } + } + else + { + isCacheExists=false; + //======== + QFile::remove(VideoConfiguration_fullPath); + file_DelDir(SplitFramesFolderPath); + file_DelDir(VideoClipsFolderPath); + QFile::remove(AudioPath); + DelVfiDir(video_mp4_fullpath); + emit Send_video_write_VideoConfiguration(VideoConfiguration_fullPath,ScaleRatio,DenoiseLevel,CustRes_isEnabled,CustRes_height,CustRes_width,"waifu2x-ncnn-vulkan",true,VideoClipsFolderPath,VideoClipsFolderName,ui->groupBox_FrameInterpolation->isChecked(),ui->spinBox_MultipleOfFPS_VFI->value()); + //======== + } + /*==================================== + 提取音频 + ======================================*/ + if(!QFile::exists(AudioPath)) + { + video_get_audio(video_mp4_fullpath,AudioPath); + } + //================================== 开始分段处理视频 ================================================= + int StartTime = 0;//起始时间(秒) + int VideoDuration = video_get_duration(video_mp4_fullpath); + bool isSplitComplete = false; + bool isScaleComplete = false; + /* + ============================================ + 开始之前先读取进度 + ============================================ + */ + int OLD_SegmentDuration=-1; + bool read_OLD_SegmentDuration =false; + int LastVideoClipNo = -1; + if(QFile::exists(VideoConfiguration_fullPath)) + { + QSettings *configIniRead = new QSettings(VideoConfiguration_fullPath, QSettings::IniFormat); + configIniRead->setIniCodec(QTextCodec::codecForName("UTF-8")); + //=================== 加载进度 ========================= + StartTime = configIniRead->value("/Progress/StartTime").toInt(); + isSplitComplete = configIniRead->value("/Progress/isSplitComplete").toBool(); + isScaleComplete = configIniRead->value("/Progress/isScaleComplete").toBool(); + OLD_SegmentDuration = configIniRead->value("/Progress/OLDSegmentDuration").toInt(); + LastVideoClipNo = configIniRead->value("/Progress/LastVideoClipNo").toInt(); + } + if(OLD_SegmentDuration>0) + { + read_OLD_SegmentDuration = true; + } + /* + 加载进度条 + */ + int SegmentDuration_tmp_progressbar = 0; + if(read_OLD_SegmentDuration) + { + SegmentDuration_tmp_progressbar = OLD_SegmentDuration; + } + else + { + SegmentDuration_tmp_progressbar = SegmentDuration; + } + if(ui->checkBox_ShowInterPro->isChecked()&&VideoDuration>SegmentDuration_tmp_progressbar) + { + emit Send_CurrentFileProgress_Start(file_name+"."+file_ext,VideoDuration); + if(StartTime>0) + { + emit Send_CurrentFileProgress_progressbar_Add_SegmentDuration(StartTime); + } + } + /* + ============================================ + 正式开始处理 + ============================================ + */ + int SegmentDuration_tmp=0; + int TimeLeft_tmp=0; + bool isOverScaled = false; + QString video_mp4_scaled_clip_fullpath=""; + //========================== + while(VideoDuration>StartTime) + { + /*========================== + 计算视频片段时间 + ==========================*/ + TimeLeft_tmp = VideoDuration-StartTime; + if((TimeLeft_tmp)>=SegmentDuration) + { + SegmentDuration_tmp = SegmentDuration; + } + else + { + SegmentDuration_tmp = TimeLeft_tmp; + } + if(read_OLD_SegmentDuration) + { + SegmentDuration_tmp = OLD_SegmentDuration; + read_OLD_SegmentDuration=false; + } + /*========================== + 拆分视频片段 + ==========================*/ + if(isSplitComplete==false) + { + if(file_isDirExist(SplitFramesFolderPath)) + { + file_DelDir(SplitFramesFolderPath); + file_mkDir(SplitFramesFolderPath); + } + else + { + file_mkDir(SplitFramesFolderPath); + } + video_video2images_ProcessBySegment(video_mp4_fullpath,SplitFramesFolderPath,StartTime,SegmentDuration_tmp); + if(waifu2x_STOP) + { + emit Send_Table_video_ChangeStatus_rowNumInt_statusQString(rowNum, "Interrupted"); + return 0;//如果启用stop位,则直接return + } + } + /*========================== + 处理视频片段的帧 + ==========================*/ + isOverScaled = false; + if(isScaleComplete==false) + { + //============================== 扫描获取文件名 =============================== + QStringList Frame_fileName_list = file_getFileNames_in_Folder_nofilter(SplitFramesFolderPath); + if(isSplitComplete==false) + { + if(Frame_fileName_list.isEmpty())//检查是否成功拆分为帧 + { + emit Send_TextBrowser_NewMessage(tr("Error occured when processing [")+SourceFile_fullPath+tr("]. Error: [Unable to split video into pictures.]")); + emit Send_Table_video_ChangeStatus_rowNumInt_statusQString(rowNum, "Failed"); + emit Send_progressbar_Add(); + return 0;//如果启用stop位,则直接return + } + } + /* + 记录进度 + 帧拆分成功 + */ + emit Send_video_write_Progress_ProcessBySegment(VideoConfiguration_fullPath,StartTime,true,false,SegmentDuration_tmp,LastVideoClipNo); + //============================== 放大 ======================================= + //===========建立存储放大后frame的文件夹=========== + if(isSplitComplete==false) + { + if(file_isDirExist(ScaledFramesFolderPath)) + { + file_DelDir(ScaledFramesFolderPath); + file_mkDir(ScaledFramesFolderPath); + } + else + { + file_mkDir(ScaledFramesFolderPath); + } + } + //==========开始放大========================== + //读取放大倍数 + int ScaleRatio_Original = 2; + if(CustRes_isEnabled == true) + { + ScaleRatio_Original = CustRes_CalNewScaleRatio(video_mp4_fullpath,CustRes_height,CustRes_width); + } + else + { + ScaleRatio_Original = ui->doubleSpinBox_ScaleRatio_video->value(); + } + int ScaleRatio_Max=Calculate_Temporary_ScaleRatio_W2xNCNNVulkan(ScaleRatio_Original); + isOverScaled = (ScaleRatio_Max!=ScaleRatio_Original); + //读取初始放大倍率 + int Initial_ScaleRatio = 2; + if(!Frame_fileName_list.isEmpty()) + { + QString Full_Path_File = ""; + for(int i = 0; i < Frame_fileName_list.size(); i++) + { + QString tmp = Frame_fileName_list.at(i); + Full_Path_File = SplitFramesFolderPath + "/" + tmp; + QFileInfo finfo(Full_Path_File); + if(finfo.suffix()=="png")break; + } + QImage qimage_original; + qimage_original.load(Full_Path_File); + int Frame_height = qimage_original.height(); + QMap res_map = video_get_Resolution(SourceFile_fullPath); + int Video_height = res_map["height"]; + if(Frame_height>0 && Video_height>0 && Frame_height>=Video_height)//判断是否读取失败 + { + Initial_ScaleRatio = 2*(Frame_height/Video_height); + } + } + //初始化进度讯息 + int NumOfSplitFrames = Frame_fileName_list.size()+file_getFileNames_in_Folder_nofilter(ScaledFramesFolderPath).size(); + int CurrentFileProgress_MAX = 0; + int CurrentFileProgress_OLD = 0; + int CurrentFileProgress_New = 0; + if(ui->checkBox_ShowInterPro->isChecked()) + { + int NumOfRounds=0; + for(int ScaleRatio_Current_tmp=Initial_ScaleRatio; ScaleRatio_Current_tmp<=ScaleRatio_Max; ScaleRatio_Current_tmp*=2) + { + NumOfRounds++; + } + CurrentFileProgress_MAX =NumOfSplitFrames*NumOfRounds; + } + //读取配置讯息 + QProcess *Waifu2x = new QProcess(); + bool waifu2x_qprocess_failed = false; + int DenoiseLevel_tmp = DenoiseLevel; + int CountFinishedRounds=0; + QString ErrorMSG=""; + QString StanderMSG=""; + QString cmd=""; + QString Waifu2x_NCNN_Vulkan_Settings_str=""; + //==== + for(int ScaleRatio_Current_tmp=Initial_ScaleRatio; ScaleRatio_Current_tmp<=ScaleRatio_Max && Frame_fileName_list.isEmpty()==false; ScaleRatio_Current_tmp*=2) + { + for(int retry=0; retry<(ui->spinBox_retry->value()+ForceRetryCount); retry++) + { + ErrorMSG=""; + StanderMSG=""; + //========== + waifu2x_qprocess_failed = false; + Waifu2x_NCNN_Vulkan_Settings_str = Waifu2x_NCNN_Vulkan_ReadSettings_Video_GIF(ui->spinBox_ThreadNum_video_internal->value()); + cmd = "\"" + Waifu2x_ncnn_vulkan_ProgramPath + "\"" + " -i " + "\"" + SplitFramesFolderPath + "\"" + " -o " + "\"" + ScaledFramesFolderPath + "\"" + " -s " + "2" + " -n " + QString::number(DenoiseLevel_tmp, 10) + Waifu2x_NCNN_Vulkan_Settings_str; + Waifu2x->start(cmd); + while(!Waifu2x->waitForStarted(100)&&!QProcess_stop) {} + while(!Waifu2x->waitForFinished(650)&&!QProcess_stop) + { + if(waifu2x_STOP) + { + QStringList FinfishedFileList_FileNames = WaitForEngineIO_NcnnVulkan(ScaledFramesFolderPath); + Waifu2x->close(); + //============ + QString file_name_tmp; + QStringList FileNames_ScaledFramesFolderPath = file_getFileNames_in_Folder_nofilter(ScaledFramesFolderPath); + for(int i=0; ireadAllStandardError().toLower()); + StanderMSG.append(Waifu2x->readAllStandardOutput().toLower()); + if(ErrorMSG.contains("failed")||StanderMSG.contains("failed")) + { + waifu2x_qprocess_failed = true; + Waifu2x->close(); + break; + } + if(ui->checkBox_ShowInterPro->isChecked()) + { + CurrentFileProgress_New = (NumOfSplitFrames*CountFinishedRounds)+file_getFileNames_in_Folder_nofilter(ScaledFramesFolderPath).size(); + if(CurrentFileProgress_New!=CurrentFileProgress_OLD) + { + emit Send_TextBrowser_NewMessage(tr("File name:[")+SourceFile_fullPath+tr("] Scale progress:[")+QString::number(CurrentFileProgress_New,10)+"/"+QString::number(CurrentFileProgress_MAX,10)+tr("] Duration progress:[")+QString::number(StartTime,10)+"s/"+QString::number(VideoDuration,10)+"s]"); + CurrentFileProgress_OLD=CurrentFileProgress_New; + } + } + } + //=============== + if(waifu2x_qprocess_failed==false) + { + ErrorMSG.append(Waifu2x->readAllStandardError().toLower()); + StanderMSG.append(Waifu2x->readAllStandardOutput().toLower()); + if(ErrorMSG.contains("failed")||StanderMSG.contains("failed")) + { + waifu2x_qprocess_failed = true; + } + } + //========= 检测是否成功,是否需要重试 ============ + if((NumOfSplitFrames == file_getFileNames_in_Folder_nofilter(ScaledFramesFolderPath).size())&&!waifu2x_qprocess_failed) + { + break; + } + else + { + //失败 + file_DelDir(ScaledFramesFolderPath); + file_mkDir(ScaledFramesFolderPath); + if(retry==ui->spinBox_retry->value()+(ForceRetryCount-1))break; + emit Send_TextBrowser_NewMessage(tr("Automatic retry, please wait.")); + Delay_sec_sleep(5); + } + } + //=========== + //根据轮数修改参数 + DenoiseLevel_tmp = -1; + if(ScaleRatio_Current_tmpcheckBox_ShowInterPro->isChecked()) + { + emit Send_CurrentFileProgress_progressbar_Add_SegmentDuration(SegmentDuration_tmp); + } + StartTime+=SegmentDuration_tmp; + isSplitComplete = false; + isScaleComplete = false; + LastVideoClipNo=VideoClipNo; + emit Send_video_write_Progress_ProcessBySegment(VideoConfiguration_fullPath,StartTime,false,false,-1,VideoClipNo); + } + emit Send_CurrentFileProgress_Stop(); + //====================================================== + // 组装(片段到成片) + //====================================================== + QString video_mp4_scaled_fullpath = ""; + if(CustRes_isEnabled) + { + video_mp4_scaled_fullpath = file_path+"/"+file_name+"_waifu2x_"+QString::number(CustRes_width,10)+"x"+QString::number(CustRes_height,10)+"_"+QString::number(DenoiseLevel,10)+"n"+"_"+file_ext+".mp4"; + } + else + { + video_mp4_scaled_fullpath = file_path+"/"+file_name+"_waifu2x_"+QString::number(ScaleRatio,10)+"x_"+QString::number(DenoiseLevel,10)+"n"+"_"+file_ext+".mp4"; + } + QFile::remove(video_mp4_scaled_fullpath); + video_AssembleVideoClips(VideoClipsFolderPath,VideoClipsFolderName,video_mp4_scaled_fullpath,AudioPath); + if(QFile::exists(video_mp4_scaled_fullpath)==false)//检查是否成功生成视频 + { + if(waifu2x_STOP) + { + emit Send_Table_video_ChangeStatus_rowNumInt_statusQString(rowNum, "Interrupted"); + return 0;//如果启用stop位,则直接return + } + emit Send_TextBrowser_NewMessage(tr("Error occured when processing [")+SourceFile_fullPath+tr("]. Error: [Unable to assemble video clips.]")); + emit Send_Table_video_ChangeStatus_rowNumInt_statusQString(rowNum, "Failed"); + emit Send_progressbar_Add(); + return 0;//如果启用stop位,则直接return + } + //============================== 删除缓存文件 ==================================================== + if(ui->checkBox_KeepVideoCache->isChecked()==false) + { + QFile::remove(VideoConfiguration_fullPath); + file_DelDir(SplitFramesFolderPath); + file_DelDir(VideoClipsFolderPath); + QFile::remove(AudioPath); + if(SourceFile_fullPath!=video_mp4_fullpath)QFile::remove(video_mp4_fullpath); + } + else + { + DelOriginal=false; + } + //============================= 删除原文件 & & 更新table status ============================ + if(DelOriginal) + { + if(ReplaceOriginalFile(SourceFile_fullPath,video_mp4_scaled_fullpath)==false) + { + if(QAction_checkBox_MoveToRecycleBin_checkBox_DelOriginal->isChecked()) + { + file_MoveToTrash(SourceFile_fullPath); + } + else + { + QFile::remove(SourceFile_fullPath); + } + } + emit Send_Table_video_ChangeStatus_rowNumInt_statusQString(rowNum, "Finished, original file deleted"); + } + else + { + emit Send_Table_video_ChangeStatus_rowNumInt_statusQString(rowNum, "Finished"); + } + //========== 移动到输出路径 ========= + if(ui->checkBox_OutPath_isEnabled->isChecked()) + { + MoveFileToOutputPath(video_mp4_scaled_fullpath,SourceFile_fullPath); + } + //============================ 更新进度条 ================================= + emit Send_progressbar_Add(); + //=========================== ============================== + return 0; +} +/* +================================================================================ + WAIFU2X NCNN VULKAN 检测可用GPU +================================================================================= +*/ +void MainWindow::on_pushButton_DetectGPU_clicked() +{ + //==== + ui->pushButton_DetectGPU->setText(tr("Detecting, please wait...")); + //==== + pushButton_Start_setEnabled_self(0); + ui->pushButton_DetectGPU->setEnabled(0); + ui->pushButton_DetectGPUID_srmd->setEnabled(0); + ui->pushButton_DumpProcessorList_converter->setEnabled(0); + ui->pushButton_ListGPUs_Anime4k->setEnabled(0); + ui->pushButton_compatibilityTest->setEnabled(0); + ui->pushButton_DetectGPU_RealsrNCNNVulkan->setEnabled(0); + Available_GPUID.clear(); + QtConcurrent::run(this, &MainWindow::Waifu2x_DetectGPU); +} + +int MainWindow::Waifu2x_DetectGPU() +{ + emit Send_TextBrowser_NewMessage(tr("Detecting available GPU, please wait.")); + //=============== + QString InputPath = Current_Path + "/Compatibility_Test/Compatibility_Test.jpg"; + QString OutputPath = Current_Path + "/Compatibility_Test/res.png"; + QFile::remove(OutputPath); + //============== + QString Waifu2x_folder_path = Waifu2x_ncnn_vulkan_FolderPath; + QString program = Waifu2x_ncnn_vulkan_ProgramPath; + QString model_path = Waifu2x_folder_path+"/models-upconv_7_anime_style_art_rgb"; + //========= + int GPU_ID=-1; + //========= + while(true) + { + QFile::remove(OutputPath); + QProcess *Waifu2x = new QProcess(); + QString gpu_str = " -g "+QString::number(GPU_ID,10)+" "; + QString cmd = "\"" + program + "\"" + " -i " + "\"" + InputPath + "\"" + " -o " + "\"" + OutputPath + "\"" + " -s 2 -n 0 -t 32 -m " + "\"" + model_path + "\"" + " -j 1:1:1"+gpu_str; + Waifu2x->start(cmd); + while(!Waifu2x->waitForStarted(100)&&!QProcess_stop) {} + while(!Waifu2x->waitForFinished(100)&&!QProcess_stop) {} + if(QFile::exists(OutputPath) && (Waifu2x->readAllStandardError().toLower().contains("failed")||Waifu2x->readAllStandardOutput().toLower().contains("failed"))==false) + { + Available_GPUID.append(QString::number(GPU_ID,10)); + GPU_ID++; + QFile::remove(OutputPath); + } + else + { + if(GPU_ID > -1) + { + break; + } + else + { + GPU_ID++; + } + } + } + QFile::remove(OutputPath); + //=============== + emit Send_TextBrowser_NewMessage(tr("Detection is complete!")); + if(Available_GPUID.isEmpty()) + { + Send_TextBrowser_NewMessage(tr("No available GPU ID detected!")); + } + emit Send_Waifu2x_DetectGPU_finished(); + return 0; +} + +int MainWindow::Waifu2x_DetectGPU_finished() +{ + pushButton_Start_setEnabled_self(1); + ui->pushButton_DetectGPU->setEnabled(1); + ui->pushButton_compatibilityTest->setEnabled(1); + ui->pushButton_DetectGPUID_srmd->setEnabled(1); + ui->pushButton_DumpProcessorList_converter->setEnabled(1); + on_checkBox_SpecifyGPU_Anime4k_stateChanged(1); + ui->pushButton_DetectGPU_RealsrNCNNVulkan->setEnabled(1); + //==== + GPUIDs_List_MultiGPU_Waifu2xNCNNVulkan.clear(); + ui->comboBox_GPUIDs_MultiGPU_Waifu2xNCNNVulkan->clear(); + ui->comboBox_GPUID->clear(); + ui->comboBox_GPUID->addItem("auto"); + if(!Available_GPUID.isEmpty()) + { + for(int i=0; icomboBox_GPUID->addItem(Available_GPUID.at(i)); + AddGPU_MultiGPU_Waifu2xNCNNVulkan(Available_GPUID.at(i)); + } + } + //==== + ui->pushButton_DetectGPU->setText(tr("Detect available GPU ID")); + //==== + return 0; +} + +/* +Waifu2x_NCNN_Vulkan +预读取引擎配置 +*/ +QString MainWindow::Waifu2x_NCNN_Vulkan_PreLoad_Settings() +{ + QString Waifu2x_NCNN_Vulkan_Settings_str = " "; + //TTA + if(ui->checkBox_TTA_vulkan->isChecked()) + { + Waifu2x_NCNN_Vulkan_Settings_str.append("-x "); + } + if(ui->checkBox_MultiGPU_Waifu2xNCNNVulkan->isChecked()==false) + { + //==========单显卡========== + //GPU ID + if(ui->comboBox_GPUID->currentText()!="auto") + { + Waifu2x_NCNN_Vulkan_Settings_str.append("-g "+ui->comboBox_GPUID->currentText()+" "); + } + //Tile Size + Waifu2x_NCNN_Vulkan_Settings_str.append("-t "+QString::number(ui->spinBox_TileSize->value(),10)+" "); + } + //Model + int ImageStyle = ui->comboBox_ImageStyle->currentIndex(); + QString model_path=""; + if(ui->comboBox_model_vulkan->currentIndex()==0) + { + if(ImageStyle==0) + { + model_path = Waifu2x_ncnn_vulkan_FolderPath+"/models-upconv_7_anime_style_art_rgb"; + } + else + { + model_path = Waifu2x_ncnn_vulkan_FolderPath+"/models-upconv_7_photo"; + } + } + if(ui->comboBox_model_vulkan->currentIndex()==1) + { + model_path = Waifu2x_ncnn_vulkan_FolderPath+"/models-cunet"; + } + Waifu2x_NCNN_Vulkan_Settings_str.append("-m \""+model_path+"\" "); + Waifu2x_NCNN_Vulkan_Settings_str.append("-j 1:1:1 "); + //======================================= + return Waifu2x_NCNN_Vulkan_Settings_str; +} + +/* +Waifu2x_NCNN_Vulkan +读取配置生成配置string +*/ +QString MainWindow::Waifu2x_NCNN_Vulkan_ReadSettings() +{ + QString Waifu2x_NCNN_Vulkan_Settings_str = ""; + Waifu2x_NCNN_Vulkan_Settings_str.append(Waifu2x_NCNN_Vulkan_PreLoad_Settings_Str); + if(ui->checkBox_MultiGPU_Waifu2xNCNNVulkan->isChecked()) + { + //==========多显卡========== + QMap GPUInfo = Waifu2x_NCNN_Vulkan_MultiGPU(); + //GPU ID + Waifu2x_NCNN_Vulkan_Settings_str.append("-g "+GPUInfo["ID"]+" "); + //Tile Size + Waifu2x_NCNN_Vulkan_Settings_str.append("-t "+GPUInfo["TileSize"]+" "); + } + //======================================= + return Waifu2x_NCNN_Vulkan_Settings_str; +} +/* +Waifu2x_NCNN_Vulkan +显卡切换 +*/ +QMap MainWindow::Waifu2x_NCNN_Vulkan_MultiGPU() +{ + MultiGPU_QMutex_Waifu2xNCNNVulkan.lock(); + int MAX_GPU_ID_Waifu2x_NCNN_Vulkan_MultiGPU = GPUIDs_List_MultiGPU_Waifu2xNCNNVulkan.size()-1; + if(GPU_ID_Waifu2x_NCNN_Vulkan_MultiGPU>MAX_GPU_ID_Waifu2x_NCNN_Vulkan_MultiGPU) + { + GPU_ID_Waifu2x_NCNN_Vulkan_MultiGPU=0; + } + //====== + QMap GPUInfo; + do + { + GPUInfo = GPUIDs_List_MultiGPU_Waifu2xNCNNVulkan.at(GPU_ID_Waifu2x_NCNN_Vulkan_MultiGPU); + if(GPUInfo["isEnabled"] != "true") + { + GPU_ID_Waifu2x_NCNN_Vulkan_MultiGPU++; + if(GPU_ID_Waifu2x_NCNN_Vulkan_MultiGPU>MAX_GPU_ID_Waifu2x_NCNN_Vulkan_MultiGPU) + { + GPU_ID_Waifu2x_NCNN_Vulkan_MultiGPU=0; + } + } + else + { + break; + } + } + while(true); + //====== + GPU_ID_Waifu2x_NCNN_Vulkan_MultiGPU++; + if(GPU_ID_Waifu2x_NCNN_Vulkan_MultiGPU>MAX_GPU_ID_Waifu2x_NCNN_Vulkan_MultiGPU) + { + GPU_ID_Waifu2x_NCNN_Vulkan_MultiGPU=0; + } + //====== + MultiGPU_QMutex_Waifu2xNCNNVulkan.unlock(); + return GPUInfo; +} + +void MainWindow::on_checkBox_MultiGPU_Waifu2xNCNNVulkan_clicked() +{ + if(ui->checkBox_MultiGPU_Waifu2xNCNNVulkan->isChecked()) + { + if(GPUIDs_List_MultiGPU_Waifu2xNCNNVulkan.size()==0) + { + QMessageBox *MSG = new QMessageBox(); + MSG->setWindowTitle(tr("Notification")); + MSG->setText(tr("Please detect available GPU ID before enable Multi-GPU.")); + MSG->setIcon(QMessageBox::Information); + MSG->setModal(true); + MSG->show(); + ui->checkBox_MultiGPU_Waifu2xNCNNVulkan->setChecked(0); + return; + } + if(GPUIDs_List_MultiGPU_Waifu2xNCNNVulkan.size()<2) + { + QMessageBox *MSG = new QMessageBox(); + MSG->setWindowTitle(tr("Error")); + MSG->setText(tr("Insufficient number of available GPUs.")); + MSG->setIcon(QMessageBox::Warning); + MSG->setModal(true); + MSG->show(); + ui->checkBox_MultiGPU_Waifu2xNCNNVulkan->setChecked(0); + return; + } + if(ui->comboBox_version_Waifu2xNCNNVulkan->currentIndex()!=0) + { + QMessageBox *MSG = new QMessageBox(); + MSG->setWindowTitle(tr("Warning")); + MSG->setText(tr("Old versions of Waifu2x-NCNN-Vulkan doesn't support Multi-GPUs when processing Video and GIF.")); + MSG->setIcon(QMessageBox::Warning); + MSG->setModal(true); + MSG->show(); + return; + } + } +} + +void MainWindow::AddGPU_MultiGPU_Waifu2xNCNNVulkan(QString GPUID) +{ + QMap GPUInfo; + GPUInfo["ID"] = GPUID; + GPUInfo["isEnabled"] = "true"; + GPUInfo["TileSize"] = "100"; + GPUIDs_List_MultiGPU_Waifu2xNCNNVulkan.append(GPUInfo); + ui->comboBox_GPUIDs_MultiGPU_Waifu2xNCNNVulkan->addItem(GPUID); + ui->comboBox_GPUIDs_MultiGPU_Waifu2xNCNNVulkan->setCurrentIndex(0); +} + +void MainWindow::on_comboBox_GPUIDs_MultiGPU_Waifu2xNCNNVulkan_currentIndexChanged(int index) +{ + if(ui->comboBox_GPUIDs_MultiGPU_Waifu2xNCNNVulkan->count()==0) + { + return; + } + QMap GPUInfo=GPUIDs_List_MultiGPU_Waifu2xNCNNVulkan.at(ui->comboBox_GPUIDs_MultiGPU_Waifu2xNCNNVulkan->currentIndex()); + ui->checkBox_isEnable_CurrentGPU_MultiGPU_Waifu2xNCNNVulkan->setChecked(GPUInfo["isEnabled"] == "true"); + ui->spinBox_TileSize_CurrentGPU_MultiGPU_Waifu2xNCNNVulkan->setValue(GPUInfo["TileSize"].toInt()); +} + +void MainWindow::on_spinBox_TileSize_CurrentGPU_MultiGPU_Waifu2xNCNNVulkan_valueChanged(int arg1) +{ + QMap GPUInfo=GPUIDs_List_MultiGPU_Waifu2xNCNNVulkan.at(ui->comboBox_GPUIDs_MultiGPU_Waifu2xNCNNVulkan->currentIndex()); + GPUInfo["TileSize"] = QString::number(ui->spinBox_TileSize_CurrentGPU_MultiGPU_Waifu2xNCNNVulkan->value(),10); + GPUIDs_List_MultiGPU_Waifu2xNCNNVulkan.replace(ui->comboBox_GPUIDs_MultiGPU_Waifu2xNCNNVulkan->currentIndex(),GPUInfo); +} + +void MainWindow::on_checkBox_isEnable_CurrentGPU_MultiGPU_Waifu2xNCNNVulkan_clicked() +{ + QMap GPUInfo=GPUIDs_List_MultiGPU_Waifu2xNCNNVulkan.at(ui->comboBox_GPUIDs_MultiGPU_Waifu2xNCNNVulkan->currentIndex()); + if(ui->checkBox_isEnable_CurrentGPU_MultiGPU_Waifu2xNCNNVulkan->isChecked()) + { + GPUInfo["isEnabled"] = "true"; + } + else + { + GPUInfo["isEnabled"] = "false"; + } + GPUIDs_List_MultiGPU_Waifu2xNCNNVulkan.replace(ui->comboBox_GPUIDs_MultiGPU_Waifu2xNCNNVulkan->currentIndex(),GPUInfo); + int enabledGPUs = 0; + for (int i=0; i GPUInfo_tmp = GPUIDs_List_MultiGPU_Waifu2xNCNNVulkan.at(i); + if(GPUInfo_tmp["isEnabled"] == "true") + { + enabledGPUs++; + } + } + if(enabledGPUs<2) + { + QMap GPUInfo=GPUIDs_List_MultiGPU_Waifu2xNCNNVulkan.at(ui->comboBox_GPUIDs_MultiGPU_Waifu2xNCNNVulkan->currentIndex()); + GPUInfo["isEnabled"] = "true"; + GPUIDs_List_MultiGPU_Waifu2xNCNNVulkan.replace(ui->comboBox_GPUIDs_MultiGPU_Waifu2xNCNNVulkan->currentIndex(),GPUInfo); + ui->checkBox_isEnable_CurrentGPU_MultiGPU_Waifu2xNCNNVulkan->setChecked(1); + QMessageBox *MSG = new QMessageBox(); + MSG->setWindowTitle(tr("Warning")); + MSG->setText(tr("At least 2 GPUs need to be enabled !!")); + MSG->setIcon(QMessageBox::Warning); + MSG->setModal(true); + MSG->show(); + } +} + +void MainWindow::on_checkBox_MultiGPU_Waifu2xNCNNVulkan_stateChanged(int arg1) +{ + if(ui->checkBox_MultiGPU_Waifu2xNCNNVulkan->isChecked()) + { + ui->comboBox_GPUID->setEnabled(0); + ui->frame_TileSize_W2xNcnnVulkan->setEnabled(0); + ui->groupBox_GPUSettings_MultiGPU_Waifu2xNCNNVulkan->setEnabled(1); + } + else + { + ui->comboBox_GPUID->setEnabled(1); + ui->frame_TileSize_W2xNcnnVulkan->setEnabled(1); + ui->groupBox_GPUSettings_MultiGPU_Waifu2xNCNNVulkan->setEnabled(0); + } +} + +void MainWindow::on_pushButton_ShowMultiGPUSettings_Waifu2xNCNNVulkan_clicked() +{ + int Max_GPU_ID = GPUIDs_List_MultiGPU_Waifu2xNCNNVulkan.size(); + QString MultiGPUSettings_str=""; + for(int GPU_ID=0; GPU_ID GPUInfo = GPUIDs_List_MultiGPU_Waifu2xNCNNVulkan.at(GPU_ID); + if(GPUInfo["isEnabled"] != "true") + { + continue; + } + else + { + MultiGPUSettings_str.append("GPU ID:["+GPUInfo["ID"]+"] | "+tr("Tile size:")+"["+GPUInfo["TileSize"]+"]\n\n"); + } + } + //========= + QMessageBox *MSG = new QMessageBox(); + MSG->setWindowTitle(tr("Current Multi-GPU settings")); + MSG->setText(MultiGPUSettings_str); + MSG->setIcon(QMessageBox::Information); + MSG->setModal(true); + MSG->show(); +} +/* +W2x NCNN Vulkan 块大小调整按钮 + +*/ +void MainWindow::on_pushButton_TileSize_Add_W2xNCNNVulkan_clicked() +{ + ui->spinBox_TileSize->setValue(AddTileSize_NCNNVulkan_Converter(ui->spinBox_TileSize->value())); +} +/* +W2x NCNN Vulkan 块大小调整按钮 - +*/ +void MainWindow::on_pushButton_TileSize_Minus_W2xNCNNVulkan_clicked() +{ + ui->spinBox_TileSize->setValue(MinusTileSize_NCNNVulkan_Converter(ui->spinBox_TileSize->value())); +} +/* +计算 临时放大倍率 +*/ +int MainWindow::Calculate_Temporary_ScaleRatio_W2xNCNNVulkan(int ScaleRatio) +{ + int ScaleRatio_tmp=0; + //如果设定的scaleRatio不是偶数,则+1,并输出到tmp + if((ScaleRatio%2)==0) + { + ScaleRatio_tmp = ScaleRatio; + } + else + { + ScaleRatio_tmp = ScaleRatio+1; + } + //判断是否为2的幂数 + if((ScaleRatio_tmp&(ScaleRatio_tmp-1))!=0) + { + for(int i=1; true; i++) + { + int pow_ =pow(2,i); + if(pow_>=ScaleRatio_tmp) + { + ScaleRatio_tmp=pow_; + break; + } + } + } + return ScaleRatio_tmp; +} +/* +读取配置讯息 Video GIF +*/ +QString MainWindow::Waifu2x_NCNN_Vulkan_ReadSettings_Video_GIF(int ThreadNum) +{ + QString Waifu2x_NCNN_Vulkan_Settings_str = " "; + //TTA + if(ui->checkBox_TTA_vulkan->isChecked()) + { + Waifu2x_NCNN_Vulkan_Settings_str.append("-x "); + } + if(ui->checkBox_MultiGPU_Waifu2xNCNNVulkan->isChecked()==true && ui->comboBox_version_Waifu2xNCNNVulkan->currentIndex()==0) + { + //==============多显卡================ + int NumOfGPUs_Available = GPUIDs_List_MultiGPU_Waifu2xNCNNVulkan.size();//获取显卡总数 + int NumOfGPUs_Enabled = 0; + QString GPU_ID_cmd = "-g "; + QString TileSize_cmd = "-t "; + for(int i=0; i GPUInfo = GPUIDs_List_MultiGPU_Waifu2xNCNNVulkan.at(i); + if(GPUInfo["isEnabled"] != "true")continue; + NumOfGPUs_Enabled++; + if(i==0) + { + GPU_ID_cmd.append(GPUInfo["ID"]); + TileSize_cmd.append(GPUInfo["TileSize"]); + } + else + { + GPU_ID_cmd.append(","+GPUInfo["ID"]); + TileSize_cmd.append(","+GPUInfo["TileSize"]); + } + } + Waifu2x_NCNN_Vulkan_Settings_str.append(GPU_ID_cmd+" "); + Waifu2x_NCNN_Vulkan_Settings_str.append(TileSize_cmd+" "); + //线程数量 + int NumOfThreads_PerGPU = ThreadNum/NumOfGPUs_Enabled; + if(NumOfThreads_PerGPU<1)NumOfThreads_PerGPU=1; + int LoadAndWrite_tnum = NumOfGPUs_Enabled*NumOfThreads_PerGPU; + QString Jobs_cmd = ""; + for(int i=0; icomboBox_GPUID->currentText()!="auto" && ui->checkBox_MultiGPU_Waifu2xNCNNVulkan->isChecked()==false) + { + Waifu2x_NCNN_Vulkan_Settings_str.append("-g "+ui->comboBox_GPUID->currentText()+" "); + } + //Tile Size + Waifu2x_NCNN_Vulkan_Settings_str.append("-t "+QString::number(ui->spinBox_TileSize->value(),10)+" "); + //线程数量 + QString jobs_num_str = QString("%1").arg(ThreadNum); + Waifu2x_NCNN_Vulkan_Settings_str.append("-j "+jobs_num_str+":"+jobs_num_str+":"+jobs_num_str+" "); + } + //Model + int ImageStyle = ui->comboBox_ImageStyle->currentIndex(); + QString model_path=""; + if(ui->comboBox_model_vulkan->currentIndex()==0) + { + if(ImageStyle==0) + { + model_path = Waifu2x_ncnn_vulkan_FolderPath+"/models-upconv_7_anime_style_art_rgb"; + } + else + { + model_path = Waifu2x_ncnn_vulkan_FolderPath+"/models-upconv_7_photo"; + } + } + if(ui->comboBox_model_vulkan->currentIndex()==1) + { + model_path = Waifu2x_ncnn_vulkan_FolderPath+"/models-cunet"; + } + Waifu2x_NCNN_Vulkan_Settings_str.append("-m \""+model_path+"\" "); + return Waifu2x_NCNN_Vulkan_Settings_str; +} +/* +计算 实际输入CMD的放大倍率 列表 +*/ +/* +QList MainWindow::Calculate_CMD_ScaleRatio_List_W2xNCNNVulkan(int ScaleRatio) +{ + QList CMD_ScaleRatio_List; + int ScaleRatio_MAX = Calculate_Temporary_ScaleRatio_W2xNCNNVulkan(ScaleRatio); + if(ScaleRatio_MAX<=32) + { + CMD_ScaleRatio_List.append(ScaleRatio_MAX); + return CMD_ScaleRatio_List; + } + int ScaleRatio_MAX_tmp = ScaleRatio_MAX/32; + CMD_ScaleRatio_List.append(32); + do + { + if(ScaleRatio_MAX_tmp/32 > 1) + { + ScaleRatio_MAX_tmp/=32; + CMD_ScaleRatio_List.append(32); + } + else + { + CMD_ScaleRatio_List.append(ScaleRatio_MAX_tmp); + break; + } + } + while(true); + return CMD_ScaleRatio_List; +} +*/ +/* +放大APNG + +Waifu2x-NCNN-Vulkan +*/ +bool MainWindow::APNG_Waifu2xNCNNVulkan(QString splitFramesFolder,QString scaledFramesFolder,QString sourceFileFullPath,QStringList framesFileName_qStrList,QString resultFileFullPath) +{ + //生成文件夹 + file_DelDir(scaledFramesFolder); + file_mkDir(scaledFramesFolder); + //============================================================ + //开始放大 + //读取放大倍数 + int ScaleRatio_Original = 2; + if(CustRes_isContained(sourceFileFullPath)) + { + QMap Res_map = CustRes_getResMap(sourceFileFullPath);//res_map["fullpath"],["height"],["width"] + ScaleRatio_Original = CustRes_CalNewScaleRatio(sourceFileFullPath,Res_map["height"].toInt(),Res_map["width"].toInt()); + } + else + { + ScaleRatio_Original = ui->doubleSpinBox_ScaleRatio_gif->value(); + } + int ScaleRatio_Max = Calculate_Temporary_ScaleRatio_W2xNCNNVulkan(ScaleRatio_Original); + bool isOverScaled = (ScaleRatio_Max!=ScaleRatio_Original); + //初始化进度讯息 + int NumOfSplitFrames = framesFileName_qStrList.size(); + if(ui->checkBox_ShowInterPro->isChecked()) + { + int NumOfRounds=0; + for(int ScaleRatio_Current_tmp=2; ScaleRatio_Current_tmp<=ScaleRatio_Max; ScaleRatio_Current_tmp*=2) + { + NumOfRounds++; + } + emit Send_CurrentFileProgress_Start(file_getBaseName(sourceFileFullPath)+"."+sourceFileFullPath.split(".").last(),NumOfSplitFrames*NumOfRounds); + } + //读取配置讯息 + QString Waifu2x_NCNN_Vulkan_Settings_str = Waifu2x_NCNN_Vulkan_ReadSettings_Video_GIF(ui->spinBox_ThreadNum_gif_internal->value()); + QProcess *Waifu2x = new QProcess(); + QString program = Waifu2x_ncnn_vulkan_ProgramPath; + bool waifu2x_qprocess_failed = false; + int DenoiseLevel_tmp = ui->spinBox_DenoiseLevel_gif->value(); + int CountFinishedRounds=0; + //==== + for(int ScaleRatio_Current_tmp=2; ScaleRatio_Current_tmp<=ScaleRatio_Max && framesFileName_qStrList.isEmpty()==false; ScaleRatio_Current_tmp*=2) + { + for(int retry=0; retry<(ui->spinBox_retry->value()+ForceRetryCount); retry++) + { + QString ErrorMSG=""; + QString StanderMSG=""; + //========== + waifu2x_qprocess_failed = false; + QString cmd = "\"" + program + "\"" + " -i " + "\"" + splitFramesFolder + "\"" + " -o " + "\"" + scaledFramesFolder + "\"" + " -s " + "2" + " -n " + QString::number(DenoiseLevel_tmp, 10) + Waifu2x_NCNN_Vulkan_Settings_str; + Waifu2x->start(cmd); + while(!Waifu2x->waitForStarted(100)&&!QProcess_stop) {} + while(!Waifu2x->waitForFinished(650)&&!QProcess_stop) + { + if(waifu2x_STOP) + { + Waifu2x->close(); + mutex_ThreadNumRunning.lock(); + ThreadNumRunning--; + mutex_ThreadNumRunning.unlock(); + return false;//中断,返回 + } + ErrorMSG.append(Waifu2x->readAllStandardError().toLower()); + StanderMSG.append(Waifu2x->readAllStandardOutput().toLower()); + if(ErrorMSG.contains("failed")||StanderMSG.contains("failed")) + { + waifu2x_qprocess_failed = true; + Waifu2x->close(); + break; + } + if(ui->checkBox_ShowInterPro->isChecked()) + { + emit Send_CurrentFileProgress_progressbar_SetFinishedValue((NumOfSplitFrames*CountFinishedRounds)+file_getFileNames_in_Folder_nofilter(scaledFramesFolder).size()); + } + } + //=============== + if(waifu2x_qprocess_failed==false) + { + ErrorMSG.append(Waifu2x->readAllStandardError().toLower()); + StanderMSG.append(Waifu2x->readAllStandardOutput().toLower()); + if(ErrorMSG.contains("failed")||StanderMSG.contains("failed")) + { + waifu2x_qprocess_failed = true; + } + } + //========= 检测是否成功,是否需要重试 ============ + if((NumOfSplitFrames == file_getFileNames_in_Folder_nofilter(scaledFramesFolder).size())&&!waifu2x_qprocess_failed) + { + break; + } + else + { + //失败 + file_DelDir(scaledFramesFolder); + file_mkDir(scaledFramesFolder); + if(retry==ui->spinBox_retry->value()+(ForceRetryCount-1))break; + emit Send_TextBrowser_NewMessage(tr("Automatic retry, please wait.")); + Delay_sec_sleep(5); + } + } + //=========== + //根据轮数修改参数 + DenoiseLevel_tmp = -1; + if(ScaleRatio_Current_tmp