From f0833bc9c122290b8f60091e89b7abebe64d36ba Mon Sep 17 00:00:00 2001 From: lltcggie Date: Sat, 19 Mar 2016 19:28:33 +0900 Subject: [PATCH] =?UTF-8?q?GUI=E3=81=A7=E6=AE=8B=E3=82=8A=E6=99=82?= =?UTF-8?q?=E9=96=93=E3=81=8C=E8=A1=A8=E7=A4=BA=E3=81=95=E3=82=8C=E3=82=8B?= =?UTF-8?q?=E3=82=88=E3=81=86=E3=81=AB=E3=81=97=E3=81=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bin/lang/english.json | 4 +- bin/lang/japanese.json | 4 +- waifu2x-caffe-gui/Source.cpp | 80 +++++++++++++++++++++++++++++++++++- 3 files changed, 85 insertions(+), 3 deletions(-) diff --git a/bin/lang/english.json b/bin/lang/english.json index 432f613..58ea274 100644 --- a/bin/lang/english.json +++ b/bin/lang/english.json @@ -69,5 +69,7 @@ "MessagecuDNNDefautlError":"You can not use cuDNN", "MessageExtStr":"Input file extensions(%s)", "MessageAllFileFolder":"All files and folders(*.*)", -"MessageTitleInputDialog":"Please select input file or folder" +"MessageTitleInputDialog":"Please select input file or folder", +"MessageTimeLeftUnkown":"Time Left: Unkown", +"MessageTimeLeft":"Time Left" } diff --git a/bin/lang/japanese.json b/bin/lang/japanese.json index 12c1b32..478196e 100644 --- a/bin/lang/japanese.json +++ b/bin/lang/japanese.json @@ -70,5 +70,7 @@ "MessagecuDNNDefautlError":"cuDNNは使えません", "MessageExtStr":"指定された変換対象拡張子(%s)", "MessageAllFileFolder":"すべてのファイル、フォルダ(*.*)", -"MessageTitleInputDialog":"入力するファイルかフォルダを選択してください" +"MessageTitleInputDialog":"入力するファイルかフォルダを選択してください", +"MessageTimeLeftUnkown":"残り時間: 不明", +"MessageTimeLeft":"残り時間" } diff --git a/waifu2x-caffe-gui/Source.cpp b/waifu2x-caffe-gui/Source.cpp index e0b2246..8ef6d35 100644 --- a/waifu2x-caffe-gui/Source.cpp +++ b/waifu2x-caffe-gui/Source.cpp @@ -27,6 +27,8 @@ #include "CDialog.h" #include "CControl.h" +#pragma comment(lib, "winmm.lib") + #undef ERROR #define WM_FAILD_CREATE_DIR (WM_APP + 5) @@ -44,6 +46,8 @@ const TCHAR * const SettingFileName = TEXT("setting.ini"); const TCHAR * const LangDir = TEXT("lang"); const TCHAR * const LangListFileName = TEXT("lang/LangList.txt"); +const UINT_PTR nIDEventTimeLeft = 1000; + // http://stackoverflow.com/questions/10167382/boostfilesystem-get-relative-path boost::filesystem::path relativePath(const boost::filesystem::path &path, const boost::filesystem::path &relative_to) @@ -172,6 +176,9 @@ private: LangStringList langStringList; std::wstring LangName; + std::atomic TimeLeftThread; + std::atomic TimeLeftGetTimeThread; + private: template static tstring to_tstring(T val) @@ -672,6 +679,11 @@ private: ProgessFunc(maxFile, 0); + DWORD startTime = 0; + + int64_t processeNum = 0; + int64_t count = 0; + const auto fileNum = file_paths.size(); for (const auto &p : file_paths) { ret = w.waifu2x(p.first, p.second, [this]() @@ -682,6 +694,8 @@ private: num++; ProgessFunc(maxFile, num); + count++; + if (ret != Waifu2x::eWaifu2xError_OK) { SendMessage(dh, WM_ON_WAIFU2X_ERROR, (WPARAM)&ret, (LPARAM)&p); @@ -689,6 +703,26 @@ private: if (ret == Waifu2x::eWaifu2xError_Cancel) break; } + else if(count >= 2) + processeNum++; + + if(count == 1) // ŏ̈ڂ͓ڈȍ~xȂ͂Ȃ̂Ŏc莞Ԃ̌vZɂ͎gȂ + startTime = timeGetTime(); + if (count >= 2) + { + const auto nt = timeGetTime(); + TimeLeftGetTimeThread = nt; + + const auto ElapsedTimeMS = nt - startTime; + + const double avgProcessTime = (double)ElapsedTimeMS / (double)processeNum / 1000.0; + + const auto leftnum = fileNum - count; + + const auto TimeLeft = avgProcessTime * leftnum; + + TimeLeftThread = ceil(TimeLeft); + } } const auto ProcessEndTime = std::chrono::system_clock::now(); @@ -945,7 +979,8 @@ private: public: DialogEvent() : dh(nullptr), mode("noise_scale"), noise_level(1), scale_ratio(2.0), scale_width(0), scale_height(0), model_dir(TEXT("models/anime_style_art_rgb")), process("gpu"), outputExt(TEXT(".png")), inputFileExt(TEXT("png:jpg:jpeg:tif:tiff:bmp:tga")), - use_tta(false), output_quality(100), output_depth(8), crop_size(128), batch_size(1), isLastError(false), scaleType(eScaleTypeEnd) + use_tta(false), output_quality(100), output_depth(8), crop_size(128), batch_size(1), isLastError(false), scaleType(eScaleTypeEnd), + TimeLeftThread(-1), TimeLeftGetTimeThread(0) { } @@ -995,6 +1030,9 @@ public: cancelFlag = false; isLastError = false; + TimeLeftThread = -1; + TimeLeftGetTimeThread = 0; + processThread = std::thread(std::bind(&DialogEvent::ProcessWaifu2x, this)); EnableWindow(GetDlgItem(dh, IDC_BUTTON_CANCEL), TRUE); @@ -1003,10 +1041,14 @@ public: SetWindowText(GetDlgItem(hWnd, IDC_EDIT_LOG), TEXT("")); logMessage.clear(); + + SetTimer(dh, nIDEventTimeLeft, 1000, NULL); } void WaitThreadExit(HWND hWnd, WPARAM wParam, LPARAM lParam, LPVOID lpData) { + KillTimer(dh, nIDEventTimeLeft); + processThread.join(); EnableWindow(GetDlgItem(dh, IDC_BUTTON_CANCEL), FALSE); EnableWindow(GetDlgItem(dh, IDC_BUTTON_EXEC), TRUE); @@ -1024,6 +1066,41 @@ public: MessageBox(dh, langStringList.GetString(L"MessageErrorHappen").c_str(), langStringList.GetString(L"MessageTitleError").c_str(), MB_OK | MB_ICONERROR); } + void Timer(HWND hWnd, WPARAM wParam, LPARAM lParam, LPVOID lpData) + { + const int64_t TimeLeft = TimeLeftThread; + const DWORD TimeLeftGetTime = TimeLeftGetTimeThread; + + if (TimeLeft == -1) + { + SetWindowText(GetDlgItem(dh, IDC_EDIT_LOG), langStringList.GetString(L"MessageTimeLeftUnkown").c_str()); + } + else + { + if (TimeLeftGetTime > 0) + { + const DWORD tnow = timeGetTime(); + + const DWORD leftprevSec = (tnow - TimeLeftGetTime) / 1000; + + int64_t TimeLeftNow = TimeLeft - (int64_t)leftprevSec; + if (TimeLeftNow < 0) + TimeLeftNow = 0; + + const int64_t sec = TimeLeftNow % 60; + const int64_t min = (TimeLeftNow / 60) % 60; + const int64_t hour = (TimeLeftNow / 60 / 60) % 60; + + TCHAR msg[1024]; + _stprintf_s(msg, TEXT("%s: %02d:%02d:%02d"), langStringList.GetString(L"MessageTimeLeft").c_str(), hour, min, sec); + msg[_countof(msg) - 1] = TEXT('\0'); + + // \ + SetWindowText(GetDlgItem(dh, IDC_EDIT_LOG), msg); + } + } + } + void OnDialogEnd(HWND hWnd, WPARAM wParam, LPARAM lParam, LPVOID lpData) { SaveIni(); @@ -1923,6 +2000,7 @@ int WINAPI WinMain(HINSTANCE hInstance, cDialog.SetEventCallBack(SetClassFunc(DialogEvent::OnFaildCreateDir, &cDialogEvent), NULL, WM_FAILD_CREATE_DIR); cDialog.SetEventCallBack(SetClassFunc(DialogEvent::OnWaifu2xError, &cDialogEvent), NULL, WM_ON_WAIFU2X_ERROR); cDialog.SetEventCallBack(SetClassFunc(DialogEvent::WaitThreadExit, &cDialogEvent), NULL, WM_END_THREAD); + cDialog.SetEventCallBack(SetClassFunc(DialogEvent::Timer, &cDialogEvent), NULL, WM_TIMER); // _CAO\ cDialog.DoModal(hInstance, IDD_DIALOG);