mirror of
https://github.com/lltcggie/waifu2x-caffe.git
synced 2025-06-26 13:42:48 +00:00
GUIで残り時間が表示されるようにした
This commit is contained in:
parent
f322933de8
commit
f0833bc9c1
@ -69,5 +69,7 @@
|
|||||||
"MessagecuDNNDefautlError":"You can not use cuDNN",
|
"MessagecuDNNDefautlError":"You can not use cuDNN",
|
||||||
"MessageExtStr":"Input file extensions(%s)",
|
"MessageExtStr":"Input file extensions(%s)",
|
||||||
"MessageAllFileFolder":"All files and folders(*.*)",
|
"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"
|
||||||
}
|
}
|
||||||
|
@ -70,5 +70,7 @@
|
|||||||
"MessagecuDNNDefautlError":"cuDNNは使えません",
|
"MessagecuDNNDefautlError":"cuDNNは使えません",
|
||||||
"MessageExtStr":"指定された変換対象拡張子(%s)",
|
"MessageExtStr":"指定された変換対象拡張子(%s)",
|
||||||
"MessageAllFileFolder":"すべてのファイル、フォルダ(*.*)",
|
"MessageAllFileFolder":"すべてのファイル、フォルダ(*.*)",
|
||||||
"MessageTitleInputDialog":"入力するファイルかフォルダを選択してください"
|
"MessageTitleInputDialog":"入力するファイルかフォルダを選択してください",
|
||||||
|
"MessageTimeLeftUnkown":"残り時間: 不明",
|
||||||
|
"MessageTimeLeft":"残り時間"
|
||||||
}
|
}
|
||||||
|
@ -27,6 +27,8 @@
|
|||||||
#include "CDialog.h"
|
#include "CDialog.h"
|
||||||
#include "CControl.h"
|
#include "CControl.h"
|
||||||
|
|
||||||
|
#pragma comment(lib, "winmm.lib")
|
||||||
|
|
||||||
#undef ERROR
|
#undef ERROR
|
||||||
|
|
||||||
#define WM_FAILD_CREATE_DIR (WM_APP + 5)
|
#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 LangDir = TEXT("lang");
|
||||||
const TCHAR * const LangListFileName = TEXT("lang/LangList.txt");
|
const TCHAR * const LangListFileName = TEXT("lang/LangList.txt");
|
||||||
|
|
||||||
|
const UINT_PTR nIDEventTimeLeft = 1000;
|
||||||
|
|
||||||
|
|
||||||
// http://stackoverflow.com/questions/10167382/boostfilesystem-get-relative-path
|
// http://stackoverflow.com/questions/10167382/boostfilesystem-get-relative-path
|
||||||
boost::filesystem::path relativePath(const boost::filesystem::path &path, const boost::filesystem::path &relative_to)
|
boost::filesystem::path relativePath(const boost::filesystem::path &path, const boost::filesystem::path &relative_to)
|
||||||
@ -172,6 +176,9 @@ private:
|
|||||||
LangStringList langStringList;
|
LangStringList langStringList;
|
||||||
std::wstring LangName;
|
std::wstring LangName;
|
||||||
|
|
||||||
|
std::atomic<int64_t> TimeLeftThread;
|
||||||
|
std::atomic<DWORD> TimeLeftGetTimeThread;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
template<typename T>
|
template<typename T>
|
||||||
static tstring to_tstring(T val)
|
static tstring to_tstring(T val)
|
||||||
@ -672,6 +679,11 @@ private:
|
|||||||
|
|
||||||
ProgessFunc(maxFile, 0);
|
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)
|
for (const auto &p : file_paths)
|
||||||
{
|
{
|
||||||
ret = w.waifu2x(p.first, p.second, [this]()
|
ret = w.waifu2x(p.first, p.second, [this]()
|
||||||
@ -682,6 +694,8 @@ private:
|
|||||||
num++;
|
num++;
|
||||||
ProgessFunc(maxFile, num);
|
ProgessFunc(maxFile, num);
|
||||||
|
|
||||||
|
count++;
|
||||||
|
|
||||||
if (ret != Waifu2x::eWaifu2xError_OK)
|
if (ret != Waifu2x::eWaifu2xError_OK)
|
||||||
{
|
{
|
||||||
SendMessage(dh, WM_ON_WAIFU2X_ERROR, (WPARAM)&ret, (LPARAM)&p);
|
SendMessage(dh, WM_ON_WAIFU2X_ERROR, (WPARAM)&ret, (LPARAM)&p);
|
||||||
@ -689,6 +703,26 @@ private:
|
|||||||
if (ret == Waifu2x::eWaifu2xError_Cancel)
|
if (ret == Waifu2x::eWaifu2xError_Cancel)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
else if(count >= 2)
|
||||||
|
processeNum++;
|
||||||
|
|
||||||
|
if(count == 1) // 最初の一回目は二回目以降より遅くなるはずなので残り時間の計算には使わない
|
||||||
|
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();
|
const auto ProcessEndTime = std::chrono::system_clock::now();
|
||||||
@ -945,7 +979,8 @@ private:
|
|||||||
public:
|
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")),
|
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")),
|
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;
|
cancelFlag = false;
|
||||||
isLastError = false;
|
isLastError = false;
|
||||||
|
|
||||||
|
TimeLeftThread = -1;
|
||||||
|
TimeLeftGetTimeThread = 0;
|
||||||
|
|
||||||
processThread = std::thread(std::bind(&DialogEvent::ProcessWaifu2x, this));
|
processThread = std::thread(std::bind(&DialogEvent::ProcessWaifu2x, this));
|
||||||
|
|
||||||
EnableWindow(GetDlgItem(dh, IDC_BUTTON_CANCEL), TRUE);
|
EnableWindow(GetDlgItem(dh, IDC_BUTTON_CANCEL), TRUE);
|
||||||
@ -1003,10 +1041,14 @@ public:
|
|||||||
|
|
||||||
SetWindowText(GetDlgItem(hWnd, IDC_EDIT_LOG), TEXT(""));
|
SetWindowText(GetDlgItem(hWnd, IDC_EDIT_LOG), TEXT(""));
|
||||||
logMessage.clear();
|
logMessage.clear();
|
||||||
|
|
||||||
|
SetTimer(dh, nIDEventTimeLeft, 1000, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
void WaitThreadExit(HWND hWnd, WPARAM wParam, LPARAM lParam, LPVOID lpData)
|
void WaitThreadExit(HWND hWnd, WPARAM wParam, LPARAM lParam, LPVOID lpData)
|
||||||
{
|
{
|
||||||
|
KillTimer(dh, nIDEventTimeLeft);
|
||||||
|
|
||||||
processThread.join();
|
processThread.join();
|
||||||
EnableWindow(GetDlgItem(dh, IDC_BUTTON_CANCEL), FALSE);
|
EnableWindow(GetDlgItem(dh, IDC_BUTTON_CANCEL), FALSE);
|
||||||
EnableWindow(GetDlgItem(dh, IDC_BUTTON_EXEC), TRUE);
|
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);
|
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)
|
void OnDialogEnd(HWND hWnd, WPARAM wParam, LPARAM lParam, LPVOID lpData)
|
||||||
{
|
{
|
||||||
SaveIni();
|
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::OnFaildCreateDir, &cDialogEvent), NULL, WM_FAILD_CREATE_DIR);
|
||||||
cDialog.SetEventCallBack(SetClassFunc(DialogEvent::OnWaifu2xError, &cDialogEvent), NULL, WM_ON_WAIFU2X_ERROR);
|
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::WaitThreadExit, &cDialogEvent), NULL, WM_END_THREAD);
|
||||||
|
cDialog.SetEventCallBack(SetClassFunc(DialogEvent::Timer, &cDialogEvent), NULL, WM_TIMER);
|
||||||
|
|
||||||
// ƒ_ƒCƒAƒ<41>ƒO‚ð•\ަ
|
// ƒ_ƒCƒAƒ<41>ƒO‚ð•\ަ
|
||||||
cDialog.DoModal(hInstance, IDD_DIALOG);
|
cDialog.DoModal(hInstance, IDD_DIALOG);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user