2015-05-29 01:47:26 +09:00
|
|
|
|
#define _CRT_SECURE_NO_WARNINGS
|
2015-12-07 13:36:49 +09:00
|
|
|
|
#include <glog/logging.h>
|
2015-05-29 01:47:26 +09:00
|
|
|
|
#include <windows.h>
|
|
|
|
|
#include <Commctrl.h>
|
|
|
|
|
#include <tchar.h>
|
2015-11-19 02:34:46 +09:00
|
|
|
|
#include <stdio.h>
|
2015-05-29 01:47:26 +09:00
|
|
|
|
#include <string>
|
|
|
|
|
#include <thread>
|
|
|
|
|
#include <atomic>
|
2015-06-03 03:01:56 +09:00
|
|
|
|
#include <chrono>
|
2015-06-06 15:36:19 +09:00
|
|
|
|
#include <iostream>
|
|
|
|
|
#include <fstream>
|
2015-11-19 02:34:46 +09:00
|
|
|
|
#include <algorithm>
|
2015-05-29 01:47:26 +09:00
|
|
|
|
#include <boost/filesystem.hpp>
|
|
|
|
|
#include <boost/tokenizer.hpp>
|
|
|
|
|
#include <boost/foreach.hpp>
|
2015-06-04 02:11:46 +09:00
|
|
|
|
#include <boost/math/common_factor_rt.hpp>
|
2015-12-27 01:33:49 +09:00
|
|
|
|
#include <boost/lexical_cast.hpp>
|
2015-06-04 02:11:46 +09:00
|
|
|
|
#include <opencv2/opencv.hpp>
|
2015-12-04 00:48:55 +09:00
|
|
|
|
#include <cblas.h>
|
2015-12-17 16:28:53 +09:00
|
|
|
|
#include <dlgs.h>
|
2015-05-29 01:47:26 +09:00
|
|
|
|
#include "resource.h"
|
2015-12-27 02:46:42 +09:00
|
|
|
|
#include "tstring.h"
|
|
|
|
|
#include "LangStringList.h"
|
2015-05-29 01:47:26 +09:00
|
|
|
|
#include "../common/waifu2x.h"
|
|
|
|
|
|
|
|
|
|
#include "CDialog.h"
|
|
|
|
|
#include "CControl.h"
|
|
|
|
|
|
2015-12-07 13:36:49 +09:00
|
|
|
|
#undef ERROR
|
|
|
|
|
|
2015-05-29 01:47:26 +09:00
|
|
|
|
#define WM_FAILD_CREATE_DIR (WM_APP + 5)
|
2015-06-03 03:01:56 +09:00
|
|
|
|
#define WM_ON_WAIFU2X_ERROR (WM_APP + 6)
|
2015-05-29 01:47:26 +09:00
|
|
|
|
#define WM_END_THREAD (WM_APP + 7)
|
|
|
|
|
|
|
|
|
|
const size_t AR_PATH_MAX(1024);
|
|
|
|
|
|
2015-06-04 02:11:46 +09:00
|
|
|
|
const int MinCommonDivisor = 50;
|
|
|
|
|
const int DefaultCommonDivisor = 128;
|
2015-06-08 19:38:12 +09:00
|
|
|
|
const std::pair<int, int> DefaultCommonDivisorRange = {90, 140};
|
2015-06-04 02:11:46 +09:00
|
|
|
|
|
2015-12-07 01:28:34 +09:00
|
|
|
|
const TCHAR * const CropSizeListName = TEXT("crop_size_list.txt");
|
|
|
|
|
const TCHAR * const SettingFileName = TEXT("setting.ini");
|
2015-12-27 02:46:42 +09:00
|
|
|
|
const TCHAR * const LangDir = TEXT("lang");
|
2015-12-27 01:33:49 +09:00
|
|
|
|
const TCHAR * const LangListFileName = TEXT("lang/LangList.txt");
|
2015-06-06 15:36:19 +09:00
|
|
|
|
|
2015-05-29 01:47:26 +09:00
|
|
|
|
|
|
|
|
|
// http://stackoverflow.com/questions/10167382/boostfilesystem-get-relative-path
|
|
|
|
|
boost::filesystem::path relativePath(const boost::filesystem::path &path, const boost::filesystem::path &relative_to)
|
|
|
|
|
{
|
|
|
|
|
// create absolute paths
|
|
|
|
|
boost::filesystem::path p = boost::filesystem::absolute(path);
|
|
|
|
|
boost::filesystem::path r = boost::filesystem::absolute(relative_to);
|
|
|
|
|
|
|
|
|
|
// if root paths are different, return absolute path
|
|
|
|
|
if (p.root_path() != r.root_path())
|
|
|
|
|
return p;
|
|
|
|
|
|
|
|
|
|
// initialize relative path
|
|
|
|
|
boost::filesystem::path result;
|
|
|
|
|
|
|
|
|
|
// find out where the two paths diverge
|
|
|
|
|
boost::filesystem::path::const_iterator itr_path = p.begin();
|
|
|
|
|
boost::filesystem::path::const_iterator itr_relative_to = r.begin();
|
|
|
|
|
while (*itr_path == *itr_relative_to && itr_path != p.end() && itr_relative_to != r.end()) {
|
|
|
|
|
++itr_path;
|
|
|
|
|
++itr_relative_to;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// add "../" for each remaining token in relative_to
|
|
|
|
|
if (itr_relative_to != r.end()) {
|
|
|
|
|
++itr_relative_to;
|
|
|
|
|
while (itr_relative_to != r.end()) {
|
|
|
|
|
result /= "..";
|
|
|
|
|
++itr_relative_to;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// add remaining path
|
|
|
|
|
while (itr_path != p.end()) {
|
|
|
|
|
result /= *itr_path;
|
|
|
|
|
++itr_path;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
2015-06-04 02:11:46 +09:00
|
|
|
|
std::vector<int> CommonDivisorList(const int N)
|
|
|
|
|
{
|
|
|
|
|
std::vector<int> list;
|
|
|
|
|
|
|
|
|
|
const int sq = sqrt(N);
|
|
|
|
|
for (int i = 1; i <= sq; i++)
|
|
|
|
|
{
|
|
|
|
|
if (N % i == 0)
|
|
|
|
|
list.push_back(i);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const int sqs = list.size();
|
|
|
|
|
for (int i = 0; i < sqs; i++)
|
|
|
|
|
list.push_back(N / list[i]);
|
|
|
|
|
|
|
|
|
|
std::sort(list.begin(), list.end());
|
|
|
|
|
|
|
|
|
|
return list;
|
|
|
|
|
}
|
|
|
|
|
|
2015-05-29 01:47:26 +09:00
|
|
|
|
// <20>_<EFBFBD>C<EFBFBD>A<EFBFBD><41><EFBFBD>O<EFBFBD>p
|
|
|
|
|
class DialogEvent
|
|
|
|
|
{
|
|
|
|
|
private:
|
|
|
|
|
HWND dh;
|
|
|
|
|
|
2015-12-07 01:28:34 +09:00
|
|
|
|
boost::filesystem::path exeDir;
|
2015-06-06 15:36:19 +09:00
|
|
|
|
std::vector<int> CropSizeList;
|
|
|
|
|
|
2015-12-06 21:10:48 +09:00
|
|
|
|
tstring input_str;
|
|
|
|
|
tstring output_str;
|
2015-05-29 01:47:26 +09:00
|
|
|
|
std::string mode;
|
|
|
|
|
int noise_level;
|
|
|
|
|
double scale_ratio;
|
2015-12-06 21:10:48 +09:00
|
|
|
|
tstring model_dir;
|
2015-05-29 01:47:26 +09:00
|
|
|
|
std::string process;
|
2015-12-06 21:10:48 +09:00
|
|
|
|
tstring outputExt;
|
|
|
|
|
tstring inputFileExt;
|
2015-05-29 01:47:26 +09:00
|
|
|
|
|
2015-11-19 02:01:00 +09:00
|
|
|
|
bool use_tta;
|
|
|
|
|
|
2015-06-03 03:24:01 +09:00
|
|
|
|
int crop_size;
|
|
|
|
|
int batch_size;
|
|
|
|
|
|
2015-12-06 21:10:48 +09:00
|
|
|
|
std::vector<tstring> extList;
|
2015-06-04 02:11:46 +09:00
|
|
|
|
|
2015-05-29 01:47:26 +09:00
|
|
|
|
std::thread processThread;
|
|
|
|
|
std::atomic_bool cancelFlag;
|
|
|
|
|
|
2015-12-06 21:10:48 +09:00
|
|
|
|
tstring autoSetAddName;
|
2015-05-29 01:47:26 +09:00
|
|
|
|
bool isLastError;
|
|
|
|
|
|
2015-12-06 21:10:48 +09:00
|
|
|
|
tstring logMessage;
|
2015-06-03 03:01:56 +09:00
|
|
|
|
|
|
|
|
|
std::string usedProcess;
|
|
|
|
|
std::chrono::system_clock::duration cuDNNCheckTime;
|
|
|
|
|
std::chrono::system_clock::duration InitTime;
|
|
|
|
|
std::chrono::system_clock::duration ProcessTime;
|
2015-06-02 01:04:20 +09:00
|
|
|
|
|
2015-12-06 21:24:09 +09:00
|
|
|
|
enum eModelType
|
|
|
|
|
{
|
|
|
|
|
eModelTypeRGB,
|
|
|
|
|
eModelTypePhoto,
|
|
|
|
|
eModelTypeY,
|
2015-12-07 01:28:34 +09:00
|
|
|
|
eModelTypeEnd,
|
2015-12-06 21:24:09 +09:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
eModelType modelType;
|
|
|
|
|
|
2015-12-27 01:33:49 +09:00
|
|
|
|
LangStringList langStringList;
|
|
|
|
|
|
2015-05-29 01:47:26 +09:00
|
|
|
|
private:
|
2015-12-07 01:28:34 +09:00
|
|
|
|
template<typename T>
|
|
|
|
|
static tstring to_tstring(T val)
|
2015-05-29 01:47:26 +09:00
|
|
|
|
{
|
2015-12-06 21:10:48 +09:00
|
|
|
|
#ifdef UNICODE
|
|
|
|
|
return std::to_wstring(val);
|
|
|
|
|
#else
|
|
|
|
|
return std::to_string(val);
|
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
tstring AddName() const
|
|
|
|
|
{
|
2015-12-06 21:24:09 +09:00
|
|
|
|
tstring addstr;
|
|
|
|
|
|
|
|
|
|
addstr += TEXT("(");
|
|
|
|
|
switch (modelType)
|
|
|
|
|
{
|
|
|
|
|
case eModelTypeRGB:
|
|
|
|
|
addstr += TEXT("RGB");
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case eModelTypePhoto:
|
|
|
|
|
addstr += TEXT("Photo");
|
|
|
|
|
break;
|
2015-12-06 21:10:48 +09:00
|
|
|
|
|
2015-12-06 21:24:09 +09:00
|
|
|
|
case eModelTypeY:
|
|
|
|
|
addstr += TEXT("Y");
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
addstr += TEXT(")");
|
|
|
|
|
|
|
|
|
|
addstr += TEXT("(");
|
2015-12-06 21:10:48 +09:00
|
|
|
|
if (mode == "noise")
|
|
|
|
|
addstr += TEXT("noise");
|
|
|
|
|
else if (mode == "scale")
|
|
|
|
|
addstr += TEXT("scale");
|
|
|
|
|
else if (mode == "noise_scale")
|
|
|
|
|
addstr += TEXT("noise_scale");
|
|
|
|
|
else if (mode == "auto_scale")
|
|
|
|
|
addstr += TEXT("auto_scale");
|
|
|
|
|
addstr += TEXT(")");
|
2015-05-29 01:47:26 +09:00
|
|
|
|
|
|
|
|
|
if (mode.find("noise") != mode.npos || mode.find("auto_scale") != mode.npos)
|
2015-12-06 21:10:48 +09:00
|
|
|
|
addstr += TEXT("(Level") + to_tstring(noise_level) + TEXT(")");
|
2015-11-19 02:22:49 +09:00
|
|
|
|
if (use_tta)
|
2015-12-06 21:10:48 +09:00
|
|
|
|
addstr += TEXT("(tta)");
|
2015-05-29 01:47:26 +09:00
|
|
|
|
if (mode.find("scale") != mode.npos)
|
2015-12-06 21:10:48 +09:00
|
|
|
|
addstr += TEXT("(x") + to_tstring(scale_ratio) + TEXT(")");
|
2015-05-29 01:47:26 +09:00
|
|
|
|
|
|
|
|
|
return addstr;
|
|
|
|
|
}
|
|
|
|
|
|
2015-06-04 02:11:46 +09:00
|
|
|
|
bool SyncMember(const bool NotSyncCropSize)
|
2015-05-29 01:47:26 +09:00
|
|
|
|
{
|
|
|
|
|
bool ret = true;
|
|
|
|
|
|
|
|
|
|
{
|
2015-12-06 21:10:48 +09:00
|
|
|
|
TCHAR buf[AR_PATH_MAX] = TEXT("");
|
|
|
|
|
GetWindowText(GetDlgItem(dh, IDC_EDIT_INPUT), buf, _countof(buf));
|
|
|
|
|
buf[_countof(buf) - 1] = TEXT('\0');
|
2015-05-29 01:47:26 +09:00
|
|
|
|
|
|
|
|
|
input_str = buf;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
{
|
2015-12-06 21:10:48 +09:00
|
|
|
|
TCHAR buf[AR_PATH_MAX] = TEXT("");
|
|
|
|
|
GetWindowText(GetDlgItem(dh, IDC_EDIT_OUTPUT), buf, _countof(buf));
|
|
|
|
|
buf[_countof(buf) - 1] = TEXT('\0');
|
2015-05-29 01:47:26 +09:00
|
|
|
|
|
|
|
|
|
output_str = buf;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (SendMessage(GetDlgItem(dh, IDC_RADIO_MODE_NOISE), BM_GETCHECK, 0, 0))
|
|
|
|
|
mode = "noise";
|
|
|
|
|
else if (SendMessage(GetDlgItem(dh, IDC_RADIO_MODE_SCALE), BM_GETCHECK, 0, 0))
|
|
|
|
|
mode = "scale";
|
|
|
|
|
else if (SendMessage(GetDlgItem(dh, IDC_RADIO_MODE_NOISE_SCALE), BM_GETCHECK, 0, 0))
|
|
|
|
|
mode = "noise_scale";
|
|
|
|
|
else
|
|
|
|
|
mode = "auto_scale";
|
|
|
|
|
|
|
|
|
|
if (SendMessage(GetDlgItem(dh, IDC_RADIONOISE_LEVEL1), BM_GETCHECK, 0, 0))
|
|
|
|
|
noise_level = 1;
|
|
|
|
|
else
|
|
|
|
|
noise_level = 2;
|
|
|
|
|
|
|
|
|
|
{
|
2015-12-06 21:10:48 +09:00
|
|
|
|
TCHAR buf[AR_PATH_MAX] = TEXT("");
|
|
|
|
|
GetWindowText(GetDlgItem(dh, IDC_EDIT_SCALE_RATIO), buf, _countof(buf));
|
|
|
|
|
buf[_countof(buf) - 1] = TEXT('\0');
|
2015-05-29 01:47:26 +09:00
|
|
|
|
|
2015-12-06 21:10:48 +09:00
|
|
|
|
TCHAR *ptr = nullptr;
|
|
|
|
|
scale_ratio = _tcstod(buf, &ptr);
|
|
|
|
|
if (!ptr || *ptr != TEXT('\0') || scale_ratio <= 0.0)
|
2015-05-29 01:47:26 +09:00
|
|
|
|
{
|
|
|
|
|
scale_ratio = 2.0;
|
|
|
|
|
ret = false;
|
|
|
|
|
|
2015-12-27 04:09:08 +09:00
|
|
|
|
MessageBox(dh, langStringList.GetString(L"MessageScaleRateCheckError").c_str(), langStringList.GetString(L"MessageTitleError").c_str(), MB_OK | MB_ICONERROR);
|
2015-05-29 01:47:26 +09:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-06-24 01:07:27 +09:00
|
|
|
|
if (SendMessage(GetDlgItem(dh, IDC_RADIO_MODEL_RGB), BM_GETCHECK, 0, 0))
|
2015-12-06 21:24:09 +09:00
|
|
|
|
{
|
2015-12-06 21:10:48 +09:00
|
|
|
|
model_dir = TEXT("models/anime_style_art_rgb");
|
2015-12-06 21:24:09 +09:00
|
|
|
|
modelType = eModelTypeRGB;
|
|
|
|
|
}
|
2015-06-24 01:07:27 +09:00
|
|
|
|
else if (SendMessage(GetDlgItem(dh, IDC_RADIO_MODEL_Y), BM_GETCHECK, 0, 0))
|
2015-12-06 21:24:09 +09:00
|
|
|
|
{
|
2015-12-06 21:10:48 +09:00
|
|
|
|
model_dir = TEXT("models/anime_style_art");
|
2015-12-06 21:24:09 +09:00
|
|
|
|
modelType = eModelTypeY;
|
|
|
|
|
}
|
2015-06-24 01:07:27 +09:00
|
|
|
|
else
|
2015-12-06 21:24:09 +09:00
|
|
|
|
{
|
2015-12-06 21:10:48 +09:00
|
|
|
|
model_dir = TEXT("models/photo");
|
2015-12-06 21:24:09 +09:00
|
|
|
|
modelType = eModelTypePhoto;
|
|
|
|
|
}
|
2015-06-24 01:07:27 +09:00
|
|
|
|
|
2015-05-29 01:47:26 +09:00
|
|
|
|
{
|
2015-12-06 21:10:48 +09:00
|
|
|
|
TCHAR buf[AR_PATH_MAX] = TEXT("");
|
|
|
|
|
GetWindowText(GetDlgItem(dh, IDC_EDIT_OUT_EXT), buf, _countof(buf));
|
|
|
|
|
buf[_countof(buf) - 1] = TEXT('\0');
|
2015-05-29 01:47:26 +09:00
|
|
|
|
|
|
|
|
|
outputExt = buf;
|
2015-12-06 21:10:48 +09:00
|
|
|
|
if (outputExt.length() > 0 && outputExt[0] != TEXT('.'))
|
|
|
|
|
outputExt = TEXT(".") + outputExt;
|
2015-05-29 01:47:26 +09:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (SendMessage(GetDlgItem(dh, IDC_RADIO_MODE_CPU), BM_GETCHECK, 0, 0))
|
|
|
|
|
process = "cpu";
|
|
|
|
|
else
|
|
|
|
|
process = "gpu";
|
|
|
|
|
|
|
|
|
|
{
|
2015-12-06 21:10:48 +09:00
|
|
|
|
TCHAR buf[AR_PATH_MAX] = TEXT("");
|
|
|
|
|
GetWindowText(GetDlgItem(dh, IDC_EDIT_INPUT_EXT_LIST), buf, _countof(buf));
|
|
|
|
|
buf[_countof(buf) - 1] = TEXT('\0');
|
2015-05-29 01:47:26 +09:00
|
|
|
|
|
|
|
|
|
inputFileExt = buf;
|
2015-06-04 02:11:46 +09:00
|
|
|
|
|
|
|
|
|
// input_extention_list<73><EFBFBD><F095B68E><EFBFBD><EFBFBD>̔z<CC94><7A><EFBFBD>ɂ<EFBFBD><C982><EFBFBD>
|
|
|
|
|
|
2015-12-06 21:10:48 +09:00
|
|
|
|
typedef boost::char_separator<TCHAR> char_separator;
|
|
|
|
|
typedef boost::tokenizer<char_separator, tstring::const_iterator, tstring> tokenizer;
|
2015-06-04 02:11:46 +09:00
|
|
|
|
|
2015-12-06 21:10:48 +09:00
|
|
|
|
char_separator sep(TEXT(":"), TEXT(""), boost::drop_empty_tokens);
|
2015-06-04 02:11:46 +09:00
|
|
|
|
tokenizer tokens(inputFileExt, sep);
|
|
|
|
|
|
2015-12-06 21:10:48 +09:00
|
|
|
|
for (auto tok_iter = tokens.begin(); tok_iter != tokens.end(); ++tok_iter)
|
2015-11-19 02:34:46 +09:00
|
|
|
|
{
|
2015-12-06 21:10:48 +09:00
|
|
|
|
tstring ext(*tok_iter);
|
2015-11-19 02:34:46 +09:00
|
|
|
|
std::transform(ext.begin(), ext.end(), ext.begin(), ::tolower);
|
2015-12-06 21:10:48 +09:00
|
|
|
|
extList.push_back(TEXT(".") + ext);
|
2015-11-19 02:34:46 +09:00
|
|
|
|
}
|
2015-05-29 01:47:26 +09:00
|
|
|
|
}
|
|
|
|
|
|
2015-06-04 02:11:46 +09:00
|
|
|
|
if (!NotSyncCropSize)
|
2015-06-03 03:52:29 +09:00
|
|
|
|
{
|
2015-12-06 21:10:48 +09:00
|
|
|
|
TCHAR buf[AR_PATH_MAX] = TEXT("");
|
|
|
|
|
GetWindowText(GetDlgItem(dh, IDC_COMBO_CROP_SIZE), buf, _countof(buf));
|
|
|
|
|
buf[_countof(buf) - 1] = TEXT('\0');
|
2015-06-03 03:52:29 +09:00
|
|
|
|
|
2015-12-06 21:10:48 +09:00
|
|
|
|
TCHAR *ptr = nullptr;
|
|
|
|
|
crop_size = _tcstol(buf, &ptr, 10);
|
2015-06-03 04:33:41 +09:00
|
|
|
|
if (!ptr || *ptr != '\0' || crop_size <= 0)
|
2015-06-03 03:52:29 +09:00
|
|
|
|
{
|
|
|
|
|
crop_size = 128;
|
|
|
|
|
ret = false;
|
|
|
|
|
|
2015-12-27 04:09:08 +09:00
|
|
|
|
MessageBox(dh, langStringList.GetString(L"MessageCropSizeCheckError").c_str(), langStringList.GetString(L"MessageTitleError").c_str(), MB_OK | MB_ICONERROR);
|
2015-06-03 03:52:29 +09:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-11-19 02:01:00 +09:00
|
|
|
|
use_tta = SendMessage(GetDlgItem(dh, IDC_CHECK_TTA), BM_GETCHECK, 0, 0) == BST_CHECKED;
|
|
|
|
|
|
2015-05-29 01:47:26 +09:00
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
|
2015-06-04 02:11:46 +09:00
|
|
|
|
void SetCropSizeList(const boost::filesystem::path &input_path)
|
|
|
|
|
{
|
|
|
|
|
HWND hcrop = GetDlgItem(dh, IDC_COMBO_CROP_SIZE);
|
|
|
|
|
|
|
|
|
|
int gcd = 1;
|
|
|
|
|
if (boost::filesystem::is_directory(input_path))
|
|
|
|
|
{
|
|
|
|
|
BOOST_FOREACH(const boost::filesystem::path& p, std::make_pair(boost::filesystem::recursive_directory_iterator(input_path),
|
|
|
|
|
boost::filesystem::recursive_directory_iterator()))
|
|
|
|
|
{
|
2015-11-19 02:34:46 +09:00
|
|
|
|
|
|
|
|
|
if (!boost::filesystem::is_directory(p))
|
2015-06-04 02:11:46 +09:00
|
|
|
|
{
|
2015-12-06 21:10:48 +09:00
|
|
|
|
tstring ext(getTString(p.extension()));
|
|
|
|
|
#ifdef UNICODE
|
|
|
|
|
std::transform(ext.begin(), ext.end(), ext.begin(), ::towlower);
|
|
|
|
|
#else
|
2015-11-19 02:34:46 +09:00
|
|
|
|
std::transform(ext.begin(), ext.end(), ext.begin(), ::tolower);
|
2015-12-06 21:10:48 +09:00
|
|
|
|
#endif
|
2015-11-19 02:34:46 +09:00
|
|
|
|
if (std::find(extList.begin(), extList.end(), ext) != extList.end())
|
|
|
|
|
{
|
|
|
|
|
auto mat = Waifu2x::LoadMat(p.string());
|
|
|
|
|
if (mat.empty())
|
|
|
|
|
continue;
|
2015-06-04 02:11:46 +09:00
|
|
|
|
|
2015-11-19 02:34:46 +09:00
|
|
|
|
auto size = mat.size();
|
|
|
|
|
mat.release();
|
2015-06-04 02:11:46 +09:00
|
|
|
|
|
2015-11-19 02:34:46 +09:00
|
|
|
|
gcd = boost::math::gcd(size.width, size.height);
|
|
|
|
|
}
|
2015-06-04 02:11:46 +09:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2015-07-10 04:09:22 +09:00
|
|
|
|
auto mat = Waifu2x::LoadMat(input_path.string());
|
2015-06-04 02:11:46 +09:00
|
|
|
|
if (mat.empty())
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
auto size = mat.size();
|
|
|
|
|
mat.release();
|
|
|
|
|
|
|
|
|
|
gcd = boost::math::gcd(size.width, size.height);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
while (SendMessage(hcrop, CB_GETCOUNT, 0, 0) != 0)
|
|
|
|
|
SendMessage(hcrop, CB_DELETESTRING, 0, 0);
|
|
|
|
|
|
|
|
|
|
// <20>ő<EFBFBD><C591><EFBFBD><EFBFBD>̖̃<F1909482><CC83>X<EFBFBD>g<EFBFBD>擾
|
|
|
|
|
std::vector<int> list(CommonDivisorList(gcd));
|
|
|
|
|
|
|
|
|
|
// MinCommonDivisor<6F><72><EFBFBD><EFBFBD><EFBFBD>̖폜
|
|
|
|
|
list.erase(std::remove_if(list.begin(), list.end(), [](const int v)
|
|
|
|
|
{
|
|
|
|
|
return v < MinCommonDivisor;
|
|
|
|
|
}
|
|
|
|
|
), list.end());
|
|
|
|
|
|
|
|
|
|
int mindiff = INT_MAX;
|
2015-06-08 19:38:12 +09:00
|
|
|
|
int defaultIndex = -1;
|
2015-06-04 02:11:46 +09:00
|
|
|
|
for (int i = 0; i < list.size(); i++)
|
|
|
|
|
{
|
|
|
|
|
const int n = list[i];
|
|
|
|
|
|
2015-12-06 21:10:48 +09:00
|
|
|
|
tstring str(to_tstring(n));
|
|
|
|
|
SendMessage(hcrop, CB_ADDSTRING, 0, (LPARAM)str.c_str());
|
2015-06-04 02:11:46 +09:00
|
|
|
|
|
|
|
|
|
const int diff = abs(DefaultCommonDivisor - n);
|
2015-06-08 19:38:12 +09:00
|
|
|
|
if (DefaultCommonDivisorRange.first <= n && n <= DefaultCommonDivisorRange.second && diff < mindiff)
|
2015-06-04 02:11:46 +09:00
|
|
|
|
{
|
|
|
|
|
mindiff = diff;
|
|
|
|
|
defaultIndex = i;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-12-06 21:10:48 +09:00
|
|
|
|
SendMessage(hcrop, CB_ADDSTRING, 0, (LPARAM)TEXT("-----------------------"));
|
2015-06-06 04:36:45 +09:00
|
|
|
|
|
2015-06-06 15:36:19 +09:00
|
|
|
|
// CropSizeList<73>̒l<CC92><6C><EFBFBD>lj<EFBFBD><C789><EFBFBD><EFBFBD>Ă<EFBFBD><C482><EFBFBD>
|
2015-06-08 19:38:12 +09:00
|
|
|
|
mindiff = INT_MAX;
|
|
|
|
|
int defaultListIndex = -1;
|
2015-06-06 15:36:19 +09:00
|
|
|
|
for (const auto n : CropSizeList)
|
2015-06-06 04:36:45 +09:00
|
|
|
|
{
|
2015-12-06 21:10:48 +09:00
|
|
|
|
tstring str(to_tstring(n));
|
|
|
|
|
const int index = SendMessage(hcrop, CB_ADDSTRING, 0, (LPARAM)str.c_str());
|
2015-06-08 19:38:12 +09:00
|
|
|
|
|
|
|
|
|
const int diff = abs(DefaultCommonDivisor - n);
|
|
|
|
|
if (DefaultCommonDivisorRange.first <= n && n <= DefaultCommonDivisorRange.second && diff < mindiff)
|
|
|
|
|
{
|
|
|
|
|
mindiff = diff;
|
|
|
|
|
defaultListIndex = index;
|
|
|
|
|
}
|
2015-06-06 04:36:45 +09:00
|
|
|
|
}
|
|
|
|
|
|
2015-06-08 19:38:12 +09:00
|
|
|
|
if (defaultIndex == -1)
|
|
|
|
|
defaultIndex = defaultListIndex;
|
|
|
|
|
|
2015-06-04 03:22:44 +09:00
|
|
|
|
if (GetWindowTextLength(hcrop) == 0)
|
|
|
|
|
SendMessage(hcrop, CB_SETCURSEL, defaultIndex, 0);
|
2015-06-04 02:11:46 +09:00
|
|
|
|
}
|
|
|
|
|
|
2015-05-29 01:47:26 +09:00
|
|
|
|
void ProcessWaifu2x()
|
|
|
|
|
{
|
|
|
|
|
const boost::filesystem::path input_path(boost::filesystem::absolute(input_str));
|
|
|
|
|
|
2015-12-06 21:10:48 +09:00
|
|
|
|
std::vector<std::pair<tstring, tstring>> file_paths;
|
2015-05-29 01:47:26 +09:00
|
|
|
|
if (boost::filesystem::is_directory(input_path)) // input_path<74><68><EFBFBD>t<EFBFBD>H<EFBFBD><48><EFBFBD>_<EFBFBD>Ȃ炻<C882>̃f<CC83>B<EFBFBD><42><EFBFBD>N<EFBFBD>g<EFBFBD><67><EFBFBD>ȉ<EFBFBD><C889>̉摜<CC89>t<EFBFBD>@<40>C<EFBFBD><43><EFBFBD><EFBFBD><EFBFBD>ꊇ<EFBFBD>ϊ<EFBFBD>
|
|
|
|
|
{
|
|
|
|
|
boost::filesystem::path output_path(output_str);
|
|
|
|
|
|
|
|
|
|
output_path = boost::filesystem::absolute(output_path);
|
|
|
|
|
|
|
|
|
|
if (!boost::filesystem::exists(output_path))
|
|
|
|
|
{
|
|
|
|
|
if (!boost::filesystem::create_directory(output_path))
|
|
|
|
|
{
|
|
|
|
|
SendMessage(dh, WM_FAILD_CREATE_DIR, (WPARAM)&output_path, 0);
|
|
|
|
|
PostMessage(dh, WM_END_THREAD, 0, 0);
|
|
|
|
|
// printf("<22>o<EFBFBD>̓t<CD83>H<EFBFBD><48><EFBFBD>_<EFBFBD>u%s<>v<EFBFBD>̍쐬<CC8D>Ɏ<EFBFBD><C98E>s<EFBFBD><73><EFBFBD>܂<EFBFBD><DC82><EFBFBD>\n", output_path.string().c_str());
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// <20>ϊ<EFBFBD><CF8A><EFBFBD><EFBFBD><EFBFBD><EFBFBD>摜<EFBFBD>̓<EFBFBD><CC93>́A<CD81>o<EFBFBD>̓p<CD83>X<EFBFBD><58><EFBFBD>擾
|
2015-06-04 02:11:46 +09:00
|
|
|
|
const auto func = [this, &input_path, &output_path, &file_paths](const boost::filesystem::path &path)
|
2015-05-29 01:47:26 +09:00
|
|
|
|
{
|
|
|
|
|
BOOST_FOREACH(const boost::filesystem::path& p, std::make_pair(boost::filesystem::recursive_directory_iterator(path),
|
|
|
|
|
boost::filesystem::recursive_directory_iterator()))
|
|
|
|
|
{
|
2015-11-19 02:34:46 +09:00
|
|
|
|
if (!boost::filesystem::is_directory(p))
|
2015-05-29 01:47:26 +09:00
|
|
|
|
{
|
2015-12-06 21:10:48 +09:00
|
|
|
|
tstring ext(getTString(p.extension()));
|
|
|
|
|
#ifdef UNICODE
|
|
|
|
|
std::transform(ext.begin(), ext.end(), ext.begin(), ::towlower);
|
|
|
|
|
#else
|
2015-11-19 02:34:46 +09:00
|
|
|
|
std::transform(ext.begin(), ext.end(), ext.begin(), ::tolower);
|
2015-12-06 21:10:48 +09:00
|
|
|
|
#endif
|
|
|
|
|
|
2015-11-19 02:34:46 +09:00
|
|
|
|
if (std::find(extList.begin(), extList.end(), ext) != extList.end())
|
|
|
|
|
{
|
|
|
|
|
const auto out_relative = relativePath(p, input_path);
|
|
|
|
|
const auto out_absolute = output_path / out_relative;
|
2015-05-29 01:47:26 +09:00
|
|
|
|
|
2015-12-06 21:10:48 +09:00
|
|
|
|
const auto out = getTString(out_absolute.branch_path() / out_absolute.stem()) + outputExt;
|
2015-05-29 01:47:26 +09:00
|
|
|
|
|
2015-12-06 21:10:48 +09:00
|
|
|
|
file_paths.emplace_back(getTString(p), out);
|
2015-11-19 02:34:46 +09:00
|
|
|
|
}
|
2015-05-29 01:47:26 +09:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
if (!func(input_path))
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
for (const auto &p : file_paths)
|
|
|
|
|
{
|
|
|
|
|
const boost::filesystem::path out_path(p.second);
|
|
|
|
|
const boost::filesystem::path out_dir(out_path.parent_path());
|
|
|
|
|
|
|
|
|
|
if (!boost::filesystem::exists(out_dir))
|
|
|
|
|
{
|
|
|
|
|
if (!boost::filesystem::create_directories(out_dir))
|
|
|
|
|
{
|
|
|
|
|
SendMessage(dh, WM_FAILD_CREATE_DIR, (WPARAM)&out_dir, 0);
|
|
|
|
|
PostMessage(dh, WM_END_THREAD, 0, 0);
|
|
|
|
|
//printf("<22>o<EFBFBD>̓t<CD83>H<EFBFBD><48><EFBFBD>_<EFBFBD>u%s<>v<EFBFBD>̍쐬<CC8D>Ɏ<EFBFBD><C98E>s<EFBFBD><73><EFBFBD>܂<EFBFBD><DC82><EFBFBD>\n", out_absolute.string().c_str());
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
file_paths.emplace_back(input_str, output_str);
|
|
|
|
|
|
|
|
|
|
bool isFirst = true;
|
|
|
|
|
|
|
|
|
|
const auto ProgessFunc = [this, &isFirst](const int ProgressFileMax, const int ProgressFileNow)
|
|
|
|
|
{
|
|
|
|
|
if (isFirst)
|
|
|
|
|
{
|
|
|
|
|
isFirst = true;
|
|
|
|
|
|
|
|
|
|
SendMessage(GetDlgItem(dh, IDC_PROGRESS), PBM_SETRANGE32, 0, ProgressFileMax);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
SendMessage(GetDlgItem(dh, IDC_PROGRESS), PBM_SETPOS, ProgressFileNow, 0);
|
|
|
|
|
};
|
|
|
|
|
|
2015-06-03 03:01:56 +09:00
|
|
|
|
const auto cuDNNCheckStartTime = std::chrono::system_clock::now();
|
2015-06-02 01:04:20 +09:00
|
|
|
|
|
2015-06-03 03:01:56 +09:00
|
|
|
|
if (process == "gpu")
|
|
|
|
|
Waifu2x::can_use_cuDNN();
|
2015-06-02 01:04:20 +09:00
|
|
|
|
|
2015-06-03 03:01:56 +09:00
|
|
|
|
const auto cuDNNCheckEndTime = std::chrono::system_clock::now();
|
|
|
|
|
|
|
|
|
|
Waifu2x::eWaifu2xError ret;
|
|
|
|
|
|
|
|
|
|
Waifu2x w;
|
2015-11-19 02:01:00 +09:00
|
|
|
|
ret = w.init(__argc, __argv, mode, noise_level, scale_ratio, model_dir, process, use_tta, crop_size, batch_size);
|
2015-06-03 03:01:56 +09:00
|
|
|
|
if(ret != Waifu2x::eWaifu2xError_OK)
|
|
|
|
|
SendMessage(dh, WM_ON_WAIFU2X_ERROR, (WPARAM)&ret, 0);
|
|
|
|
|
else
|
2015-05-29 01:47:26 +09:00
|
|
|
|
{
|
2015-06-03 03:01:56 +09:00
|
|
|
|
const auto InitEndTime = std::chrono::system_clock::now();
|
2015-05-29 01:47:26 +09:00
|
|
|
|
|
2015-06-03 03:01:56 +09:00
|
|
|
|
for (const auto &p : file_paths)
|
|
|
|
|
{
|
|
|
|
|
ret = w.waifu2x(p.first, p.second, [this]()
|
|
|
|
|
{
|
|
|
|
|
return cancelFlag;
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
if (ret != Waifu2x::eWaifu2xError_OK)
|
|
|
|
|
{
|
|
|
|
|
SendMessage(dh, WM_ON_WAIFU2X_ERROR, (WPARAM)&ret, (LPARAM)&p);
|
|
|
|
|
|
|
|
|
|
if (ret == Waifu2x::eWaifu2xError_Cancel)
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const auto ProcessEndTime = std::chrono::system_clock::now();
|
|
|
|
|
|
|
|
|
|
cuDNNCheckTime = cuDNNCheckEndTime - cuDNNCheckStartTime;
|
|
|
|
|
InitTime = InitEndTime - cuDNNCheckEndTime;
|
|
|
|
|
ProcessTime = ProcessEndTime - InitEndTime;
|
|
|
|
|
usedProcess = w.used_process();
|
|
|
|
|
}
|
2015-05-29 01:47:26 +09:00
|
|
|
|
|
|
|
|
|
PostMessage(dh, WM_END_THREAD, 0, 0);
|
|
|
|
|
}
|
|
|
|
|
|
2015-12-06 21:31:51 +09:00
|
|
|
|
void ReplaceAddString() // <20>t<EFBFBD>@<40>C<EFBFBD><43><EFBFBD><EFBFBD><EFBFBD>̎<EFBFBD><CC8E><EFBFBD><EFBFBD>ݒ蕔<DD92><E89594><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
2015-05-29 01:47:26 +09:00
|
|
|
|
{
|
2015-06-04 02:11:46 +09:00
|
|
|
|
SyncMember(true);
|
2015-05-29 01:47:26 +09:00
|
|
|
|
|
|
|
|
|
const boost::filesystem::path output_path(output_str);
|
2015-12-06 21:10:48 +09:00
|
|
|
|
tstring stem;
|
2015-11-19 02:46:23 +09:00
|
|
|
|
|
|
|
|
|
if (!boost::filesystem::is_directory(input_str))
|
2015-12-06 21:10:48 +09:00
|
|
|
|
stem = getTString(output_path.stem());
|
2015-11-19 02:46:23 +09:00
|
|
|
|
else
|
2015-12-06 21:10:48 +09:00
|
|
|
|
stem = getTString(output_path.filename());
|
2015-11-19 02:46:23 +09:00
|
|
|
|
|
2015-05-29 01:47:26 +09:00
|
|
|
|
if (stem.length() > 0 && stem.length() >= autoSetAddName.length())
|
|
|
|
|
{
|
2015-12-06 21:31:51 +09:00
|
|
|
|
const auto pos = stem.find(autoSetAddName);
|
|
|
|
|
if (pos != tstring::npos)
|
2015-05-29 01:47:26 +09:00
|
|
|
|
{
|
2015-12-06 21:10:48 +09:00
|
|
|
|
const tstring addstr(AddName());
|
2015-12-06 21:31:51 +09:00
|
|
|
|
|
|
|
|
|
auto new_name = stem;
|
|
|
|
|
new_name.replace(pos, autoSetAddName.length(), addstr);
|
|
|
|
|
|
2015-05-29 01:47:26 +09:00
|
|
|
|
autoSetAddName = addstr;
|
|
|
|
|
|
2015-11-19 02:46:23 +09:00
|
|
|
|
boost::filesystem::path new_out_path;
|
|
|
|
|
if (!boost::filesystem::is_directory(input_str))
|
2015-12-06 21:31:51 +09:00
|
|
|
|
new_out_path = output_path.branch_path() / (new_name + outputExt);
|
2015-11-19 02:46:23 +09:00
|
|
|
|
else
|
2015-12-06 21:31:51 +09:00
|
|
|
|
new_out_path = output_path.branch_path() / (new_name);
|
2015-05-29 01:47:26 +09:00
|
|
|
|
|
2015-12-06 21:10:48 +09:00
|
|
|
|
SetWindowText(GetDlgItem(dh, IDC_EDIT_OUTPUT), getTString(new_out_path).c_str());
|
2015-05-29 01:47:26 +09:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-12-06 21:10:48 +09:00
|
|
|
|
void AddLogMessage(const TCHAR *msg)
|
2015-06-03 03:01:56 +09:00
|
|
|
|
{
|
|
|
|
|
if (logMessage.length() == 0)
|
|
|
|
|
logMessage += msg;
|
|
|
|
|
else
|
2015-12-06 21:10:48 +09:00
|
|
|
|
logMessage += tstring(TEXT("\r\n")) + msg;
|
2015-06-03 03:01:56 +09:00
|
|
|
|
|
2015-12-06 21:10:48 +09:00
|
|
|
|
SetWindowText(GetDlgItem(dh, IDC_EDIT_LOG), logMessage.c_str());
|
2015-06-03 03:01:56 +09:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Waifu2xTime()
|
|
|
|
|
{
|
2015-12-06 21:10:48 +09:00
|
|
|
|
TCHAR msg[1024 * 2];
|
|
|
|
|
TCHAR *ptr = msg;
|
2015-06-03 03:01:56 +09:00
|
|
|
|
|
|
|
|
|
{
|
2015-12-06 21:10:48 +09:00
|
|
|
|
tstring p;
|
|
|
|
|
if (usedProcess == "cpu")
|
|
|
|
|
p = TEXT("CPU");
|
|
|
|
|
else if (usedProcess == "gpu")
|
|
|
|
|
p = TEXT("CUDA");
|
|
|
|
|
else // if (p == "cudnn")
|
|
|
|
|
p = TEXT("cuDNN");
|
|
|
|
|
|
2015-12-27 04:18:22 +09:00
|
|
|
|
ptr += _stprintf(ptr, (langStringList.GetString(L"MessageUseProcessorMode") + L"\r\n").c_str(), p.c_str());
|
2015-06-03 03:01:56 +09:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
uint64_t t = std::chrono::duration_cast<std::chrono::milliseconds>(ProcessTime).count();
|
|
|
|
|
const int msec = t % 1000; t /= 1000;
|
|
|
|
|
const int sec = t % 60; t /= 60;
|
|
|
|
|
const int min = t % 60; t /= 60;
|
|
|
|
|
const int hour = (int)t;
|
2015-12-27 04:18:22 +09:00
|
|
|
|
ptr += _stprintf(ptr, (langStringList.GetString(L"MessageProcessTime") + L"\r\n").c_str(), hour, min, sec, msec);
|
2015-06-03 03:01:56 +09:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
uint64_t t = std::chrono::duration_cast<std::chrono::milliseconds>(InitTime).count();
|
|
|
|
|
const int msec = t % 1000; t /= 1000;
|
|
|
|
|
const int sec = t % 60; t /= 60;
|
|
|
|
|
const int min = t % 60; t /= 60;
|
|
|
|
|
const int hour = (int)t;
|
2015-12-27 04:18:22 +09:00
|
|
|
|
ptr += _stprintf(ptr, (langStringList.GetString(L"MessageInitTime") + L"\r\n").c_str(), hour, min, sec, msec);
|
2015-06-03 03:01:56 +09:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (process == "gpu" || process == "cudnn")
|
|
|
|
|
{
|
|
|
|
|
uint64_t t = std::chrono::duration_cast<std::chrono::milliseconds>(cuDNNCheckTime).count();
|
|
|
|
|
const int msec = t % 1000; t /= 1000;
|
|
|
|
|
const int sec = t % 60; t /= 60;
|
|
|
|
|
const int min = t % 60; t /= 60;
|
|
|
|
|
const int hour = (int)t;
|
2015-12-27 04:09:08 +09:00
|
|
|
|
ptr += _stprintf(ptr, langStringList.GetString(L"MessagecuDNNCheckTime").c_str(), hour, min, sec, msec);
|
2015-06-03 03:01:56 +09:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
AddLogMessage(msg);
|
|
|
|
|
}
|
|
|
|
|
|
2015-12-07 01:28:34 +09:00
|
|
|
|
void SaveIni(const bool isSyncMember = true)
|
|
|
|
|
{
|
|
|
|
|
if (isSyncMember)
|
|
|
|
|
SyncMember(true);
|
|
|
|
|
|
|
|
|
|
const boost::filesystem::path SettingFilePath(exeDir / SettingFileName);
|
|
|
|
|
|
|
|
|
|
tstring tScale;
|
|
|
|
|
tstring tmode;
|
|
|
|
|
tstring tprcess;
|
|
|
|
|
tstring toutputExt;
|
|
|
|
|
|
|
|
|
|
tScale = to_tstring(scale_ratio);
|
|
|
|
|
|
|
|
|
|
if (mode == ("noise"))
|
|
|
|
|
tmode = TEXT("noise");
|
|
|
|
|
else if (mode == ("scale"))
|
|
|
|
|
tmode = TEXT("scale");
|
|
|
|
|
else if (mode == ("auto_scale"))
|
|
|
|
|
tmode = TEXT("auto_scale");
|
|
|
|
|
else // noise_scale
|
|
|
|
|
tmode = TEXT("noise_scale");
|
|
|
|
|
|
|
|
|
|
if (process == "gpu")
|
|
|
|
|
tprcess = TEXT("gpu");
|
|
|
|
|
else
|
|
|
|
|
tprcess = TEXT("cpu");
|
|
|
|
|
|
|
|
|
|
toutputExt = outputExt;
|
|
|
|
|
if (toutputExt.length() > 0 && toutputExt[0] == TEXT('.'))
|
|
|
|
|
toutputExt.erase(0, 1);
|
|
|
|
|
|
|
|
|
|
WritePrivateProfileString(TEXT("Setting"), TEXT("LastScale"), tScale.c_str(), getTString(SettingFilePath).c_str());
|
|
|
|
|
|
|
|
|
|
WritePrivateProfileString(TEXT("Setting"), TEXT("LastOutputExt"), toutputExt.c_str(), getTString(SettingFilePath).c_str());
|
|
|
|
|
|
|
|
|
|
WritePrivateProfileString(TEXT("Setting"), TEXT("LastInputFileExt"), inputFileExt.c_str(), getTString(SettingFilePath).c_str());
|
|
|
|
|
|
|
|
|
|
WritePrivateProfileString(TEXT("Setting"), TEXT("LastMode"), tmode.c_str(), getTString(SettingFilePath).c_str());
|
|
|
|
|
|
|
|
|
|
WritePrivateProfileString(TEXT("Setting"), TEXT("LastNoiseLevel"), to_tstring(noise_level).c_str(), getTString(SettingFilePath).c_str());
|
|
|
|
|
|
|
|
|
|
WritePrivateProfileString(TEXT("Setting"), TEXT("LastProcess"), tprcess.c_str(), getTString(SettingFilePath).c_str());
|
|
|
|
|
|
|
|
|
|
WritePrivateProfileString(TEXT("Setting"), TEXT("LastModel"), to_tstring(modelType).c_str(), getTString(SettingFilePath).c_str());
|
|
|
|
|
|
|
|
|
|
WritePrivateProfileString(TEXT("Setting"), TEXT("LastUseTTA"), to_tstring(use_tta ? 1 : 0).c_str(), getTString(SettingFilePath).c_str());
|
|
|
|
|
}
|
|
|
|
|
|
2015-12-17 16:28:53 +09:00
|
|
|
|
// <20>o<EFBFBD>̓p<CD83>X<EFBFBD><58><EFBFBD>I<EFBFBD><49><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
static UINT_PTR CALLBACK OFNHookProcIn(
|
|
|
|
|
_In_ HWND hdlg,
|
|
|
|
|
_In_ UINT uiMsg,
|
|
|
|
|
_In_ WPARAM wParam,
|
|
|
|
|
_In_ LPARAM lParam
|
|
|
|
|
)
|
|
|
|
|
{
|
|
|
|
|
switch (uiMsg)
|
|
|
|
|
{
|
|
|
|
|
case WM_INITDIALOG:
|
|
|
|
|
{
|
|
|
|
|
// <20>_<EFBFBD>C<EFBFBD>A<EFBFBD><41><EFBFBD>O<EFBFBD>𒆉<EFBFBD><F0928689>ɕ\<5C><>
|
|
|
|
|
|
|
|
|
|
HWND hParent = GetParent(hdlg);
|
|
|
|
|
|
|
|
|
|
HWND hwndScreen;
|
|
|
|
|
RECT rectScreen;
|
|
|
|
|
hwndScreen = GetDesktopWindow();
|
|
|
|
|
GetWindowRect(hwndScreen, &rectScreen);
|
|
|
|
|
|
|
|
|
|
RECT rDialog;
|
|
|
|
|
GetWindowRect(hParent, &rDialog);
|
|
|
|
|
const int Width = rDialog.left = rDialog.right;
|
|
|
|
|
const int Height = rDialog.bottom - rDialog.top;
|
|
|
|
|
|
|
|
|
|
int DialogPosX;
|
|
|
|
|
int DialogPosY;
|
|
|
|
|
DialogPosX = ((rectScreen.right - rectScreen.left) / 2 - Width / 2);
|
|
|
|
|
DialogPosY = ((rectScreen.bottom - rectScreen.top) / 2 - Height / 2);
|
|
|
|
|
SetWindowPos(hParent, NULL, DialogPosX, DialogPosY, 0, 0, SWP_NOSIZE | SWP_NOZORDER);
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case WM_NOTIFY:
|
|
|
|
|
{
|
|
|
|
|
// <20>t<EFBFBD>@<40>C<EFBFBD><43><EFBFBD>ƃt<C683>H<EFBFBD><48><EFBFBD>_<EFBFBD><5F><EFBFBD>I<EFBFBD><49><EFBFBD>ł<EFBFBD><C582><EFBFBD><EFBFBD>悤<EFBFBD>ɂ<EFBFBD><C982><EFBFBD>
|
|
|
|
|
|
|
|
|
|
NMHDR *pnmh;
|
|
|
|
|
OFNOTIFY *pnot;
|
|
|
|
|
|
|
|
|
|
pnot = (OFNOTIFY *)lParam;
|
|
|
|
|
pnmh = &pnot->hdr;
|
|
|
|
|
switch (pnmh->code)
|
|
|
|
|
{
|
|
|
|
|
case CDN_SELCHANGE:
|
|
|
|
|
{
|
|
|
|
|
TCHAR szPath[AR_PATH_MAX] = TEXT("");
|
|
|
|
|
HWND hParent = GetParent(hdlg);
|
|
|
|
|
if (CommDlg_OpenSave_GetFilePath(hParent, szPath, _countof(szPath)) > 0)
|
|
|
|
|
{
|
|
|
|
|
szPath[_countof(szPath) - 1] = TEXT('\0');
|
|
|
|
|
|
|
|
|
|
boost::filesystem::path p(szPath);
|
|
|
|
|
const auto filename = getTString(p.filename());
|
|
|
|
|
|
|
|
|
|
CommDlg_OpenSave_SetControlText(hParent, edt1, filename.c_str());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return 0L;
|
|
|
|
|
}
|
|
|
|
|
|
2015-05-29 01:47:26 +09:00
|
|
|
|
public:
|
2015-12-06 21:10:48 +09:00
|
|
|
|
DialogEvent() : dh(nullptr), mode("noise_scale"), noise_level(1), scale_ratio(2.0), model_dir(TEXT("models/anime_style_art_rgb")),
|
|
|
|
|
process("gpu"), outputExt(TEXT("png")), inputFileExt(TEXT("png:jpg:jpeg:tif:tiff:bmp:tga")),
|
2015-11-19 02:01:00 +09:00
|
|
|
|
use_tta(false), crop_size(128), batch_size(1), isLastError(false)
|
2015-05-29 01:47:26 +09:00
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Exec(HWND hWnd, WPARAM wParam, LPARAM lParam, LPVOID lpData)
|
|
|
|
|
{
|
|
|
|
|
if (processThread.joinable())
|
|
|
|
|
return;
|
|
|
|
|
|
2015-06-06 04:39:33 +09:00
|
|
|
|
if (!SyncMember(false))
|
|
|
|
|
return;
|
2015-05-29 01:47:26 +09:00
|
|
|
|
|
|
|
|
|
if (input_str.length() == 0)
|
|
|
|
|
{
|
2015-12-27 04:09:08 +09:00
|
|
|
|
MessageBox(dh, langStringList.GetString(L"MessageInputPathCheckError").c_str(), langStringList.GetString(L"MessageTitleError").c_str(), MB_OK | MB_ICONERROR);
|
2015-05-29 01:47:26 +09:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (output_str.length() == 0)
|
|
|
|
|
{
|
2015-12-27 04:09:08 +09:00
|
|
|
|
MessageBox(dh, langStringList.GetString(L"MessageOutputPathCheckError").c_str(), langStringList.GetString(L"MessageTitleError").c_str(), MB_OK | MB_ICONERROR);
|
2015-05-29 01:47:26 +09:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (outputExt.length() == 0)
|
|
|
|
|
{
|
2015-12-27 04:09:08 +09:00
|
|
|
|
MessageBox(dh, langStringList.GetString(L"MessageOutputExtCheckError").c_str(), langStringList.GetString(L"MessageTitleError").c_str(), MB_OK | MB_ICONERROR);
|
2015-05-29 01:47:26 +09:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2015-06-08 03:34:42 +09:00
|
|
|
|
if (process == "gpu" || process == "cudnn")
|
|
|
|
|
{
|
|
|
|
|
const auto flag = Waifu2x::can_use_CUDA();
|
|
|
|
|
switch (flag)
|
|
|
|
|
{
|
|
|
|
|
case Waifu2x::eWaifu2xCudaError_NotFind:
|
2015-12-27 04:09:08 +09:00
|
|
|
|
MessageBox(dh, langStringList.GetString(L"MessageCudaNotFindError").c_str(), langStringList.GetString(L"MessageTitleError").c_str(), MB_OK | MB_ICONERROR);
|
2015-06-08 03:34:42 +09:00
|
|
|
|
return;
|
|
|
|
|
case Waifu2x::eWaifu2xCudaError_OldVersion:
|
2015-12-27 04:09:08 +09:00
|
|
|
|
MessageBox(dh, langStringList.GetString(L"MessageCudaOldVersionError").c_str(), langStringList.GetString(L"MessageTitleError").c_str(), MB_OK | MB_ICONERROR);
|
2015-06-08 03:34:42 +09:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-12-07 01:28:34 +09:00
|
|
|
|
SaveIni(true); // <20><><EFBFBD><EFBFBD><EFBFBD>I<EFBFBD><49><EFBFBD>̉\<5C><><EFBFBD><EFBFBD><EFBFBD>l<EFBFBD><6C><EFBFBD>Ď<EFBFBD><C48E>s<EFBFBD><73><EFBFBD>ɐݒ<C990><DD92>ۑ<EFBFBD>
|
|
|
|
|
|
2015-05-29 01:47:26 +09:00
|
|
|
|
SendMessage(GetDlgItem(dh, IDC_PROGRESS), PBM_SETPOS, 0, 0);
|
|
|
|
|
cancelFlag = false;
|
|
|
|
|
isLastError = false;
|
|
|
|
|
|
|
|
|
|
processThread = std::thread(std::bind(&DialogEvent::ProcessWaifu2x, this));
|
|
|
|
|
|
|
|
|
|
EnableWindow(GetDlgItem(dh, IDC_BUTTON_CANCEL), TRUE);
|
|
|
|
|
EnableWindow(GetDlgItem(dh, IDC_BUTTON_EXEC), FALSE);
|
2015-06-03 03:04:17 +09:00
|
|
|
|
EnableWindow(GetDlgItem(dh, IDC_BUTTON_CHECK_CUDNN), FALSE);
|
2015-06-02 01:15:06 +09:00
|
|
|
|
|
2015-12-06 21:10:48 +09:00
|
|
|
|
SetWindowText(GetDlgItem(hWnd, IDC_EDIT_LOG), TEXT(""));
|
2015-06-03 03:01:56 +09:00
|
|
|
|
logMessage.clear();
|
2015-05-29 01:47:26 +09:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void WaitThreadExit(HWND hWnd, WPARAM wParam, LPARAM lParam, LPVOID lpData)
|
|
|
|
|
{
|
|
|
|
|
processThread.join();
|
|
|
|
|
EnableWindow(GetDlgItem(dh, IDC_BUTTON_CANCEL), FALSE);
|
|
|
|
|
EnableWindow(GetDlgItem(dh, IDC_BUTTON_EXEC), TRUE);
|
2015-06-03 03:04:17 +09:00
|
|
|
|
EnableWindow(GetDlgItem(dh, IDC_BUTTON_CHECK_CUDNN), TRUE);
|
2015-05-29 01:47:26 +09:00
|
|
|
|
|
|
|
|
|
if (!isLastError)
|
2015-06-02 01:04:20 +09:00
|
|
|
|
{
|
2015-06-03 03:01:56 +09:00
|
|
|
|
if (!cancelFlag)
|
2015-12-27 04:09:08 +09:00
|
|
|
|
AddLogMessage(langStringList.GetString(L"MessageTransSuccess").c_str());
|
2015-06-02 01:04:20 +09:00
|
|
|
|
|
2015-06-03 03:01:56 +09:00
|
|
|
|
Waifu2xTime();
|
|
|
|
|
MessageBeep(MB_ICONASTERISK);
|
2015-06-02 01:04:20 +09:00
|
|
|
|
}
|
2015-06-03 03:01:56 +09:00
|
|
|
|
else
|
2015-12-27 04:09:08 +09:00
|
|
|
|
MessageBox(dh, langStringList.GetString(L"MessageErrorHappen").c_str(), langStringList.GetString(L"MessageTitleError").c_str(), MB_OK | MB_ICONERROR);
|
2015-06-02 01:04:20 +09:00
|
|
|
|
}
|
|
|
|
|
|
2015-05-29 01:47:26 +09:00
|
|
|
|
void OnDialogEnd(HWND hWnd, WPARAM wParam, LPARAM lParam, LPVOID lpData)
|
|
|
|
|
{
|
2015-12-07 01:28:34 +09:00
|
|
|
|
SaveIni();
|
|
|
|
|
|
2015-05-29 01:47:26 +09:00
|
|
|
|
if (!processThread.joinable())
|
|
|
|
|
PostQuitMessage(0);
|
|
|
|
|
else
|
|
|
|
|
MessageBeep(MB_ICONEXCLAMATION);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void OnFaildCreateDir(HWND hWnd, WPARAM wParam, LPARAM lParam, LPVOID lpData)
|
|
|
|
|
{
|
|
|
|
|
const boost::filesystem::path *p = (const boost::filesystem::path *)wParam;
|
|
|
|
|
|
2015-12-27 04:09:08 +09:00
|
|
|
|
TCHAR msg[1024 * 2];
|
|
|
|
|
_stprintf(msg, langStringList.GetString(L"MessageCreateOutDirError").c_str(), getTString(*p).c_str());
|
2015-05-29 01:47:26 +09:00
|
|
|
|
|
2015-12-27 04:09:08 +09:00
|
|
|
|
MessageBox(dh, msg, langStringList.GetString(L"MessageTitleError").c_str(), MB_OK | MB_ICONERROR);
|
2015-05-29 01:47:26 +09:00
|
|
|
|
|
|
|
|
|
isLastError = true;
|
|
|
|
|
}
|
|
|
|
|
|
2015-06-03 03:01:56 +09:00
|
|
|
|
void OnWaifu2xError(HWND hWnd, WPARAM wParam, LPARAM lParam, LPVOID lpData)
|
2015-05-29 01:47:26 +09:00
|
|
|
|
{
|
2015-06-03 03:01:56 +09:00
|
|
|
|
const Waifu2x::eWaifu2xError ret = *(const Waifu2x::eWaifu2xError *)wParam;
|
2015-05-29 01:47:26 +09:00
|
|
|
|
|
2015-06-03 03:01:56 +09:00
|
|
|
|
if (ret != Waifu2x::eWaifu2xError_OK)
|
2015-05-29 01:47:26 +09:00
|
|
|
|
{
|
2015-12-06 21:10:48 +09:00
|
|
|
|
TCHAR msg[1024] = TEXT("");
|
2015-05-29 01:47:26 +09:00
|
|
|
|
|
2015-06-03 03:01:56 +09:00
|
|
|
|
if (lParam == 0)
|
2015-05-29 01:47:26 +09:00
|
|
|
|
{
|
2015-06-03 03:01:56 +09:00
|
|
|
|
switch (ret)
|
|
|
|
|
{
|
|
|
|
|
case Waifu2x::eWaifu2xError_Cancel:
|
2015-12-27 04:09:08 +09:00
|
|
|
|
_stprintf(msg, langStringList.GetString(L"MessageCancelError").c_str());
|
2015-06-03 03:01:56 +09:00
|
|
|
|
break;
|
|
|
|
|
case Waifu2x::eWaifu2xError_InvalidParameter:
|
2015-12-27 04:09:08 +09:00
|
|
|
|
_stprintf(msg, langStringList.GetString(L"MessageInvalidParameterError").c_str());
|
2015-06-03 03:01:56 +09:00
|
|
|
|
break;
|
|
|
|
|
case Waifu2x::eWaifu2xError_FailedOpenModelFile:
|
2015-12-27 04:09:08 +09:00
|
|
|
|
_stprintf(msg, langStringList.GetString(L"MessageFailedOpenModelFileError").c_str());
|
2015-06-03 03:01:56 +09:00
|
|
|
|
break;
|
|
|
|
|
case Waifu2x::eWaifu2xError_FailedParseModelFile:
|
2015-12-27 04:09:08 +09:00
|
|
|
|
_stprintf(msg, langStringList.GetString(L"MessageFailedParseModelFileError").c_str());
|
2015-06-03 03:01:56 +09:00
|
|
|
|
break;
|
|
|
|
|
case Waifu2x::eWaifu2xError_FailedConstructModel:
|
2015-12-27 04:09:08 +09:00
|
|
|
|
_stprintf(msg, langStringList.GetString(L"MessageFailedConstructModelError").c_str());
|
2015-06-03 03:01:56 +09:00
|
|
|
|
break;
|
|
|
|
|
}
|
2015-05-29 01:47:26 +09:00
|
|
|
|
}
|
2015-06-03 03:01:56 +09:00
|
|
|
|
else
|
2015-05-29 01:47:26 +09:00
|
|
|
|
{
|
2015-12-06 21:10:48 +09:00
|
|
|
|
const auto &fp = *(const std::pair<tstring, tstring> *)lParam;
|
2015-05-29 01:47:26 +09:00
|
|
|
|
|
2015-06-03 03:01:56 +09:00
|
|
|
|
switch (ret)
|
2015-05-29 01:47:26 +09:00
|
|
|
|
{
|
2015-06-03 03:01:56 +09:00
|
|
|
|
case Waifu2x::eWaifu2xError_Cancel:
|
2015-12-27 04:09:08 +09:00
|
|
|
|
_stprintf(msg, langStringList.GetString(L"MessageCancelError").c_str());
|
2015-06-03 03:01:56 +09:00
|
|
|
|
break;
|
|
|
|
|
case Waifu2x::eWaifu2xError_InvalidParameter:
|
2015-12-27 04:09:08 +09:00
|
|
|
|
_stprintf(msg, langStringList.GetString(L"MessageInvalidParameterError").c_str());
|
2015-05-29 01:47:26 +09:00
|
|
|
|
break;
|
2015-06-03 03:01:56 +09:00
|
|
|
|
case Waifu2x::eWaifu2xError_FailedOpenInputFile:
|
2015-12-27 04:09:08 +09:00
|
|
|
|
_stprintf(msg, langStringList.GetString(L"MessageFailedOpenInputFileError").c_str(), fp.first.c_str());
|
2015-05-29 01:47:26 +09:00
|
|
|
|
break;
|
2015-06-03 03:01:56 +09:00
|
|
|
|
case Waifu2x::eWaifu2xError_FailedOpenOutputFile:
|
2015-12-27 04:09:08 +09:00
|
|
|
|
_stprintf(msg, langStringList.GetString(L"MessageFailedOpenOutputFileError").c_str(), fp.second.c_str());
|
2015-05-29 01:47:26 +09:00
|
|
|
|
break;
|
2015-06-03 03:01:56 +09:00
|
|
|
|
case Waifu2x::eWaifu2xError_FailedProcessCaffe:
|
2015-12-27 04:09:08 +09:00
|
|
|
|
_stprintf(msg, langStringList.GetString(L"MessageFailedProcessCaffeError").c_str());
|
2015-05-29 01:47:26 +09:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-06-03 03:01:56 +09:00
|
|
|
|
AddLogMessage(msg);
|
2015-05-29 01:47:26 +09:00
|
|
|
|
|
2015-06-03 03:01:56 +09:00
|
|
|
|
if (ret != Waifu2x::eWaifu2xError_Cancel)
|
|
|
|
|
isLastError = true;
|
2015-05-29 01:47:26 +09:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-12-27 02:46:42 +09:00
|
|
|
|
void SetWindowTextLang()
|
|
|
|
|
{
|
|
|
|
|
#define SET_WINDOW_TEXT(id) SetWindowTextW(GetDlgItem(dh, id), langStringList.GetString(L#id).c_str());
|
|
|
|
|
|
|
|
|
|
SET_WINDOW_TEXT(IDC_STATIC_IO_SETTING);
|
|
|
|
|
SET_WINDOW_TEXT(IDC_STATIC_INPUT_PATH);
|
|
|
|
|
SET_WINDOW_TEXT(IDC_BUTTON_INPUT_REF);
|
|
|
|
|
SET_WINDOW_TEXT(IDC_STATIC_OUTPUT_PATH);
|
|
|
|
|
SET_WINDOW_TEXT(IDC_STATIC_TANS_EXT_LIST);
|
|
|
|
|
SET_WINDOW_TEXT(IDC_STATIC_OUTPUT_EXT);
|
|
|
|
|
SET_WINDOW_TEXT(IDC_STATIC_OUTPUT_QUALITY);
|
|
|
|
|
SET_WINDOW_TEXT(IDC_STATIC_QUALITY_PROCESS_SETTING);
|
|
|
|
|
SET_WINDOW_TEXT(IDC_STATIC_TRANS_MODE);
|
|
|
|
|
SET_WINDOW_TEXT(IDC_RADIO_MODE_NOISE_SCALE);
|
|
|
|
|
SET_WINDOW_TEXT(IDC_RADIO_MODE_SCALE);
|
|
|
|
|
SET_WINDOW_TEXT(IDC_RADIO_MODE_NOISE);
|
|
|
|
|
SET_WINDOW_TEXT(IDC_RADIO_AUTO_SCALE);
|
|
|
|
|
SET_WINDOW_TEXT(IDC_STATIC_JPEG_NOISE_LEVEL);
|
|
|
|
|
SET_WINDOW_TEXT(IDC_RADIONOISE_LEVEL1);
|
|
|
|
|
SET_WINDOW_TEXT(IDC_RADIONOISE_LEVEL2);
|
|
|
|
|
SET_WINDOW_TEXT(IDC_STATIC_SCALE_RATE);
|
|
|
|
|
SET_WINDOW_TEXT(IDC_STATIC_MODEL);
|
|
|
|
|
SET_WINDOW_TEXT(IDC_RADIO_MODEL_RGB);
|
|
|
|
|
SET_WINDOW_TEXT(IDC_RADIO_MODEL_PHOTO);
|
|
|
|
|
SET_WINDOW_TEXT(IDC_RADIO_MODEL_Y);
|
|
|
|
|
SET_WINDOW_TEXT(IDC_CHECK_TTA);
|
|
|
|
|
SET_WINDOW_TEXT(IDC_STATIC_PROCESS_SPEED_SETTING);
|
|
|
|
|
SET_WINDOW_TEXT(IDC_STATIC_PROCESSOR);
|
|
|
|
|
SET_WINDOW_TEXT(IDC_RADIO_MODE_GPU);
|
|
|
|
|
SET_WINDOW_TEXT(IDC_RADIO_MODE_CPU);
|
|
|
|
|
SET_WINDOW_TEXT(IDC_STATIC_CROP_SIZE);
|
|
|
|
|
SET_WINDOW_TEXT(IDC_BUTTON_CHECK_CUDNN);
|
|
|
|
|
SET_WINDOW_TEXT(IDC_BUTTON_CANCEL);
|
|
|
|
|
SET_WINDOW_TEXT(IDC_BUTTON_EXEC);
|
|
|
|
|
SET_WINDOW_TEXT(IDC_STATIC_LANG_UI);
|
|
|
|
|
|
|
|
|
|
#undef SET_WINDOW_TEXT
|
|
|
|
|
}
|
|
|
|
|
|
2015-05-29 01:47:26 +09:00
|
|
|
|
void Create(HWND hWnd, WPARAM wParam, LPARAM lParam, LPVOID lpData)
|
|
|
|
|
{
|
|
|
|
|
dh = hWnd;
|
|
|
|
|
|
2015-12-07 01:28:34 +09:00
|
|
|
|
{
|
|
|
|
|
TCHAR texepath[1024 * 3] = TEXT("");
|
|
|
|
|
GetModuleFileName(NULL, texepath, _countof(texepath));
|
|
|
|
|
texepath[_countof(texepath) - 1] = TEXT('\0');
|
2015-05-29 01:47:26 +09:00
|
|
|
|
|
2015-12-07 01:28:34 +09:00
|
|
|
|
const boost::filesystem::path exePath(texepath);
|
|
|
|
|
exeDir = exePath.branch_path();
|
|
|
|
|
}
|
2015-06-06 15:36:19 +09:00
|
|
|
|
|
2015-12-27 01:33:49 +09:00
|
|
|
|
{
|
2015-12-27 02:46:42 +09:00
|
|
|
|
const boost::filesystem::path LangDirPath(exeDir / LangDir);
|
2015-12-27 01:33:49 +09:00
|
|
|
|
const boost::filesystem::path LangListPath(exeDir / LangListFileName);
|
2015-12-27 02:46:42 +09:00
|
|
|
|
langStringList.SetLangBaseDir(getTString(LangDirPath));
|
2015-12-27 01:33:49 +09:00
|
|
|
|
langStringList.ReadLangList(getTString(LangListPath));
|
|
|
|
|
}
|
|
|
|
|
|
2015-12-27 02:46:42 +09:00
|
|
|
|
SetWindowTextLang();
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
HWND hlang = GetDlgItem(dh, IDC_COMBO_LANG);
|
|
|
|
|
|
|
|
|
|
const auto &list = langStringList.GetLangList();
|
|
|
|
|
for (const auto &lang : list)
|
|
|
|
|
{
|
|
|
|
|
const int index = SendMessageW(hlang, CB_ADDSTRING, 0, (LPARAM)lang.LangName.c_str());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int defaultListIndex = 0;
|
|
|
|
|
const auto &DefaultLang = langStringList.GetLang();
|
|
|
|
|
for (size_t i = 0; i < list.size(); i++)
|
|
|
|
|
{
|
|
|
|
|
const auto &lang = list[i];
|
|
|
|
|
if (lang.LangName == DefaultLang.LangName && lang.LangID == DefaultLang.LangID
|
|
|
|
|
&& lang.SubLangID == DefaultLang.SubLangID && lang.FileName == DefaultLang.FileName)
|
|
|
|
|
{
|
|
|
|
|
(int)defaultListIndex = i;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
SendMessage(hlang, CB_SETCURSEL, defaultListIndex, 0);
|
|
|
|
|
}
|
|
|
|
|
|
2015-12-07 01:28:34 +09:00
|
|
|
|
const boost::filesystem::path CropSizeListPath(exeDir / CropSizeListName);
|
|
|
|
|
std::ifstream ifs(CropSizeListPath.wstring());
|
2015-06-06 15:36:19 +09:00
|
|
|
|
if (ifs)
|
|
|
|
|
{
|
|
|
|
|
std::string str;
|
|
|
|
|
while (getline(ifs, str))
|
|
|
|
|
{
|
|
|
|
|
char *ptr = nullptr;
|
|
|
|
|
const long n = strtol(str.c_str(), &ptr, 10);
|
|
|
|
|
if (ptr && *ptr == '\0')
|
|
|
|
|
CropSizeList.push_back(n);
|
|
|
|
|
}
|
|
|
|
|
}
|
2015-12-07 01:28:34 +09:00
|
|
|
|
|
2015-12-16 23:31:47 +09:00
|
|
|
|
{
|
|
|
|
|
HWND hcrop = GetDlgItem(dh, IDC_COMBO_CROP_SIZE);
|
|
|
|
|
|
|
|
|
|
SendMessage(hcrop, CB_ADDSTRING, 0, (LPARAM)TEXT("-----------------------"));
|
|
|
|
|
|
|
|
|
|
// CropSizeList<73>̒l<CC92><6C><EFBFBD>lj<EFBFBD><C789><EFBFBD><EFBFBD>Ă<EFBFBD><C482><EFBFBD>
|
|
|
|
|
int mindiff = INT_MAX;
|
|
|
|
|
int defaultListIndex = -1;
|
|
|
|
|
for (const auto n : CropSizeList)
|
|
|
|
|
{
|
|
|
|
|
tstring str(to_tstring(n));
|
|
|
|
|
const int index = SendMessage(hcrop, CB_ADDSTRING, 0, (LPARAM)str.c_str());
|
|
|
|
|
|
|
|
|
|
const int diff = abs(DefaultCommonDivisor - n);
|
|
|
|
|
if (DefaultCommonDivisorRange.first <= n && n <= DefaultCommonDivisorRange.second && diff < mindiff)
|
|
|
|
|
{
|
|
|
|
|
mindiff = diff;
|
|
|
|
|
defaultListIndex = index;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (GetWindowTextLength(hcrop) == 0)
|
|
|
|
|
SendMessage(hcrop, CB_SETCURSEL, defaultListIndex, 0);
|
|
|
|
|
}
|
|
|
|
|
|
2015-12-07 01:28:34 +09:00
|
|
|
|
const boost::filesystem::path SettingFilePath(exeDir / SettingFileName);
|
|
|
|
|
|
|
|
|
|
tstring tScale;
|
|
|
|
|
tstring tmode;
|
|
|
|
|
tstring tprcess;
|
|
|
|
|
{
|
|
|
|
|
TCHAR tmp[1000];
|
|
|
|
|
|
|
|
|
|
GetPrivateProfileString(TEXT("Setting"), TEXT("LastScale"), TEXT("2.00"), tmp, _countof(tmp), getTString(SettingFilePath).c_str());
|
|
|
|
|
tmp[_countof(tmp) - 1] = TEXT('\0');
|
|
|
|
|
tScale = tmp;
|
|
|
|
|
|
|
|
|
|
GetPrivateProfileString(TEXT("Setting"), TEXT("LastOutputExt"), TEXT("png"), tmp, _countof(tmp), getTString(SettingFilePath).c_str());
|
|
|
|
|
tmp[_countof(tmp) - 1] = TEXT('\0');
|
|
|
|
|
outputExt = tmp;
|
|
|
|
|
|
|
|
|
|
GetPrivateProfileString(TEXT("Setting"), TEXT("LastInputFileExt"), TEXT("png:jpg:jpeg:tif:tiff:bmp:tga"), tmp, _countof(tmp), getTString(SettingFilePath).c_str());
|
|
|
|
|
tmp[_countof(tmp) - 1] = TEXT('\0');
|
|
|
|
|
inputFileExt = tmp;
|
|
|
|
|
|
|
|
|
|
GetPrivateProfileString(TEXT("Setting"), TEXT("LastMode"), TEXT("noise_scale"), tmp, _countof(tmp), getTString(SettingFilePath).c_str());
|
|
|
|
|
tmp[_countof(tmp) - 1] = TEXT('\0');
|
|
|
|
|
tmode = tmp;
|
|
|
|
|
|
|
|
|
|
noise_level = GetPrivateProfileInt(TEXT("Setting"), TEXT("LastNoiseLevel"), 1, getTString(SettingFilePath).c_str());
|
|
|
|
|
|
|
|
|
|
GetPrivateProfileString(TEXT("Setting"), TEXT("LastProcess"), TEXT("gpu"), tmp, _countof(tmp), getTString(SettingFilePath).c_str());
|
|
|
|
|
tmp[_countof(tmp) - 1] = TEXT('\0');
|
|
|
|
|
tprcess = tmp;
|
|
|
|
|
|
|
|
|
|
modelType = (eModelType)GetPrivateProfileInt(TEXT("Setting"), TEXT("LastModel"), 0, getTString(SettingFilePath).c_str());
|
|
|
|
|
|
|
|
|
|
use_tta = GetPrivateProfileInt(TEXT("Setting"), TEXT("LastUseTTA"), 0, getTString(SettingFilePath).c_str()) != 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TCHAR *ptr = nullptr;
|
|
|
|
|
const double tempScale = _tcstod(tScale.c_str(), &ptr);
|
|
|
|
|
if (!ptr || *ptr != TEXT('\0') || tempScale <= 0.0)
|
|
|
|
|
tScale = TEXT("2.00");
|
|
|
|
|
|
|
|
|
|
if (outputExt.length() > 0 && outputExt[0] == TEXT('.'))
|
|
|
|
|
outputExt.erase(0, 1);
|
|
|
|
|
|
|
|
|
|
if (!(1 <= noise_level && noise_level <= 2))
|
|
|
|
|
noise_level = 1;
|
|
|
|
|
|
|
|
|
|
if (tprcess == TEXT("gpu"))
|
|
|
|
|
process = "gpu";
|
|
|
|
|
else
|
|
|
|
|
process = "cpu";
|
|
|
|
|
|
|
|
|
|
if (!((eModelType)0 <= modelType && modelType < eModelTypeEnd))
|
|
|
|
|
modelType = eModelTypeRGB;
|
|
|
|
|
|
|
|
|
|
if (tmode == TEXT("noise"))
|
|
|
|
|
{
|
|
|
|
|
SendMessage(GetDlgItem(hWnd, IDC_RADIO_MODE_NOISE_SCALE), BM_SETCHECK, BST_UNCHECKED, 0);
|
|
|
|
|
SendMessage(GetDlgItem(hWnd, IDC_RADIO_MODE_SCALE), BM_SETCHECK, BST_UNCHECKED, 0);
|
|
|
|
|
SendMessage(GetDlgItem(hWnd, IDC_RADIO_MODE_NOISE), BM_SETCHECK, BST_CHECKED, 0);
|
|
|
|
|
SendMessage(GetDlgItem(hWnd, IDC_RADIO_AUTO_SCALE), BM_SETCHECK, BST_UNCHECKED, 0);
|
|
|
|
|
}
|
|
|
|
|
else if (tmode == TEXT("scale"))
|
|
|
|
|
{
|
|
|
|
|
SendMessage(GetDlgItem(hWnd, IDC_RADIO_MODE_NOISE_SCALE), BM_SETCHECK, BST_UNCHECKED, 0);
|
|
|
|
|
SendMessage(GetDlgItem(hWnd, IDC_RADIO_MODE_SCALE), BM_SETCHECK, BST_CHECKED, 0);
|
|
|
|
|
SendMessage(GetDlgItem(hWnd, IDC_RADIO_MODE_NOISE), BM_SETCHECK, BST_UNCHECKED, 0);
|
|
|
|
|
SendMessage(GetDlgItem(hWnd, IDC_RADIO_AUTO_SCALE), BM_SETCHECK, BST_UNCHECKED, 0);
|
|
|
|
|
}
|
|
|
|
|
else if (tmode == TEXT("auto_scale"))
|
|
|
|
|
{
|
|
|
|
|
SendMessage(GetDlgItem(hWnd, IDC_RADIO_MODE_NOISE_SCALE), BM_SETCHECK, BST_UNCHECKED, 0);
|
|
|
|
|
SendMessage(GetDlgItem(hWnd, IDC_RADIO_MODE_SCALE), BM_SETCHECK, BST_UNCHECKED, 0);
|
|
|
|
|
SendMessage(GetDlgItem(hWnd, IDC_RADIO_MODE_NOISE), BM_SETCHECK, BST_UNCHECKED, 0);
|
|
|
|
|
SendMessage(GetDlgItem(hWnd, IDC_RADIO_AUTO_SCALE), BM_SETCHECK, BST_CHECKED, 0);
|
|
|
|
|
}
|
|
|
|
|
else // noise_scale
|
|
|
|
|
{
|
|
|
|
|
SendMessage(GetDlgItem(hWnd, IDC_RADIO_MODE_NOISE_SCALE), BM_SETCHECK, BST_CHECKED, 0);
|
|
|
|
|
SendMessage(GetDlgItem(hWnd, IDC_RADIO_MODE_SCALE), BM_SETCHECK, BST_UNCHECKED, 0);
|
|
|
|
|
SendMessage(GetDlgItem(hWnd, IDC_RADIO_MODE_NOISE), BM_SETCHECK, BST_UNCHECKED, 0);
|
|
|
|
|
SendMessage(GetDlgItem(hWnd, IDC_RADIO_AUTO_SCALE), BM_SETCHECK, BST_UNCHECKED, 0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (noise_level == 1)
|
|
|
|
|
{
|
|
|
|
|
SendMessage(GetDlgItem(hWnd, IDC_RADIONOISE_LEVEL1), BM_SETCHECK, BST_CHECKED, 0);
|
|
|
|
|
SendMessage(GetDlgItem(hWnd, IDC_RADIONOISE_LEVEL2), BM_SETCHECK, BST_UNCHECKED, 0);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
SendMessage(GetDlgItem(hWnd, IDC_RADIONOISE_LEVEL1), BM_SETCHECK, BST_UNCHECKED, 0);
|
|
|
|
|
SendMessage(GetDlgItem(hWnd, IDC_RADIONOISE_LEVEL2), BM_SETCHECK, BST_CHECKED, 0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (process == "gpu")
|
|
|
|
|
{
|
|
|
|
|
SendMessage(GetDlgItem(hWnd, IDC_RADIO_MODE_GPU), BM_SETCHECK, BST_CHECKED, 0);
|
|
|
|
|
SendMessage(GetDlgItem(hWnd, IDC_RADIO_MODE_CPU), BM_SETCHECK, BST_UNCHECKED, 0);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
SendMessage(GetDlgItem(hWnd, IDC_RADIO_MODE_GPU), BM_SETCHECK, BST_UNCHECKED, 0);
|
|
|
|
|
SendMessage(GetDlgItem(hWnd, IDC_RADIO_MODE_CPU), BM_SETCHECK, BST_CHECKED, 0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (modelType == eModelTypeRGB)
|
|
|
|
|
{
|
|
|
|
|
SendMessage(GetDlgItem(hWnd, IDC_RADIO_MODEL_RGB), BM_SETCHECK, BST_CHECKED, 0);
|
|
|
|
|
SendMessage(GetDlgItem(hWnd, IDC_RADIO_MODEL_PHOTO), BM_SETCHECK, BST_UNCHECKED, 0);
|
|
|
|
|
SendMessage(GetDlgItem(hWnd, IDC_RADIO_MODEL_Y), BM_SETCHECK, BST_UNCHECKED, 0);
|
|
|
|
|
}
|
|
|
|
|
else if (modelType == eModelTypePhoto)
|
|
|
|
|
{
|
|
|
|
|
SendMessage(GetDlgItem(hWnd, IDC_RADIO_MODEL_RGB), BM_SETCHECK, BST_UNCHECKED, 0);
|
|
|
|
|
SendMessage(GetDlgItem(hWnd, IDC_RADIO_MODEL_PHOTO), BM_SETCHECK, BST_CHECKED, 0);
|
|
|
|
|
SendMessage(GetDlgItem(hWnd, IDC_RADIO_MODEL_Y), BM_SETCHECK, BST_UNCHECKED, 0);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
SendMessage(GetDlgItem(hWnd, IDC_RADIO_MODEL_RGB), BM_SETCHECK, BST_UNCHECKED, 0);
|
|
|
|
|
SendMessage(GetDlgItem(hWnd, IDC_RADIO_MODEL_PHOTO), BM_SETCHECK, BST_UNCHECKED, 0);
|
|
|
|
|
SendMessage(GetDlgItem(hWnd, IDC_RADIO_MODEL_Y), BM_SETCHECK, BST_CHECKED, 0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (use_tta)
|
|
|
|
|
SendMessage(GetDlgItem(hWnd, IDC_CHECK_TTA), BM_SETCHECK, BST_CHECKED, 0);
|
|
|
|
|
else
|
|
|
|
|
SendMessage(GetDlgItem(hWnd, IDC_CHECK_TTA), BM_SETCHECK, BST_UNCHECKED, 0);
|
|
|
|
|
|
|
|
|
|
SetWindowText(GetDlgItem(hWnd, IDC_EDIT_SCALE_RATIO), tScale.c_str());
|
|
|
|
|
SetWindowText(GetDlgItem(hWnd, IDC_EDIT_OUT_EXT), outputExt.c_str());
|
|
|
|
|
SetWindowText(GetDlgItem(hWnd, IDC_EDIT_INPUT_EXT_LIST), inputFileExt.c_str());
|
|
|
|
|
|
|
|
|
|
EnableWindow(GetDlgItem(dh, IDC_BUTTON_CANCEL), FALSE);
|
2015-05-29 01:47:26 +09:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Cancel(HWND hWnd, WPARAM wParam, LPARAM lParam, LPVOID lpData)
|
|
|
|
|
{
|
|
|
|
|
cancelFlag = true;
|
|
|
|
|
EnableWindow(GetDlgItem(dh, IDC_BUTTON_CANCEL), FALSE);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void RadioButtom(HWND hWnd, WPARAM wParam, LPARAM lParam, LPVOID lpData)
|
|
|
|
|
{
|
|
|
|
|
ReplaceAddString();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CheckCUDNN(HWND hWnd, WPARAM wParam, LPARAM lParam, LPVOID lpData)
|
|
|
|
|
{
|
2015-06-08 03:34:42 +09:00
|
|
|
|
const auto flag = Waifu2x::can_use_CUDA();
|
|
|
|
|
switch (flag)
|
|
|
|
|
{
|
|
|
|
|
case Waifu2x::eWaifu2xCudaError_NotFind:
|
2015-12-27 04:09:08 +09:00
|
|
|
|
MessageBox(dh, langStringList.GetString(L"MessageCudaNotFindError").c_str(), langStringList.GetString(L"MessageTitleResult").c_str(), MB_OK | MB_ICONERROR);
|
2015-06-08 03:34:42 +09:00
|
|
|
|
return;
|
|
|
|
|
case Waifu2x::eWaifu2xCudaError_OldVersion:
|
2015-12-27 04:09:08 +09:00
|
|
|
|
MessageBox(dh, langStringList.GetString(L"MessageCudaOldVersionError").c_str(), langStringList.GetString(L"MessageTitleResult").c_str(), MB_OK | MB_ICONERROR);
|
2015-06-08 03:34:42 +09:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2015-06-03 13:51:48 +09:00
|
|
|
|
switch (Waifu2x::can_use_cuDNN())
|
|
|
|
|
{
|
|
|
|
|
case Waifu2x::eWaifu2xcuDNNError_OK:
|
2015-12-27 04:09:08 +09:00
|
|
|
|
MessageBox(dh, langStringList.GetString(L"MessagecuDNNOK").c_str(), langStringList.GetString(L"MessageTitleResult").c_str(), MB_OK | MB_ICONINFORMATION);
|
2015-06-03 13:51:48 +09:00
|
|
|
|
break;
|
|
|
|
|
case Waifu2x::eWaifu2xcuDNNError_NotFind:
|
2015-12-27 04:09:08 +09:00
|
|
|
|
{
|
|
|
|
|
TCHAR msg[1024 * 2];
|
|
|
|
|
_stprintf(msg, langStringList.GetString(L"MessagecuDNNNotFind").c_str(), TEXT(CUDNN_DLL_NAME));
|
|
|
|
|
MessageBox(dh, msg, langStringList.GetString(L"MessageTitleResult").c_str(), MB_OK | MB_ICONERROR);
|
2015-06-03 13:51:48 +09:00
|
|
|
|
break;
|
2015-12-27 04:09:08 +09:00
|
|
|
|
}
|
2015-06-03 13:51:48 +09:00
|
|
|
|
case Waifu2x::eWaifu2xcuDNNError_OldVersion:
|
2015-12-27 04:09:08 +09:00
|
|
|
|
{
|
|
|
|
|
TCHAR msg[1024 * 2];
|
|
|
|
|
_stprintf(msg, langStringList.GetString(L"MessagecuDNNOldVersionError").c_str(), TEXT(CUDNN_DLL_NAME), TEXT(CUDNN_REQUIRE_VERION_TEXT));
|
|
|
|
|
MessageBox(dh, msg, langStringList.GetString(L"MessageTitleResult").c_str(), MB_OK | MB_ICONERROR);
|
2015-06-03 13:51:48 +09:00
|
|
|
|
break;
|
2015-12-27 04:09:08 +09:00
|
|
|
|
}
|
2015-06-03 13:51:48 +09:00
|
|
|
|
case Waifu2x::eWaifu2xcuDNNError_CannotCreate:
|
2015-12-27 04:09:08 +09:00
|
|
|
|
MessageBox(dh, langStringList.GetString(L"MessagecuDNNCannotCreateError").c_str(), langStringList.GetString(L"MessageTitleResult").c_str(), MB_OK | MB_ICONERROR);
|
2015-06-03 13:51:48 +09:00
|
|
|
|
break;
|
|
|
|
|
default:
|
2015-12-27 04:09:08 +09:00
|
|
|
|
MessageBox(dh, langStringList.GetString(L"MessagecuDNNDefautlError").c_str(), langStringList.GetString(L"MessageTitleResult").c_str(), MB_OK | MB_ICONERROR);
|
2015-06-03 13:51:48 +09:00
|
|
|
|
}
|
2015-05-29 01:47:26 +09:00
|
|
|
|
}
|
|
|
|
|
|
2015-12-17 16:28:53 +09:00
|
|
|
|
LRESULT OnSetInputFilePath(const TCHAR *tPath)
|
2015-05-29 01:47:26 +09:00
|
|
|
|
{
|
2015-12-17 16:28:53 +09:00
|
|
|
|
HWND hWnd = GetDlgItem(dh, IDC_EDIT_INPUT);
|
2015-05-29 01:47:26 +09:00
|
|
|
|
|
2015-12-17 16:28:53 +09:00
|
|
|
|
boost::filesystem::path path(tPath);
|
|
|
|
|
|
|
|
|
|
if (!boost::filesystem::exists(path))
|
2015-05-29 01:47:26 +09:00
|
|
|
|
{
|
2015-12-27 04:09:08 +09:00
|
|
|
|
MessageBox(dh, langStringList.GetString(L"MessageInputCheckError").c_str(), langStringList.GetString(L"MessageTitleError").c_str(), MB_OK | MB_ICONERROR);
|
2015-12-17 16:28:53 +09:00
|
|
|
|
return 0L;
|
|
|
|
|
}
|
2015-05-29 01:47:26 +09:00
|
|
|
|
|
2015-12-17 16:28:53 +09:00
|
|
|
|
if (!SyncMember(true))
|
|
|
|
|
return 0L;
|
2015-05-29 01:47:26 +09:00
|
|
|
|
|
2015-12-17 16:28:53 +09:00
|
|
|
|
if (boost::filesystem::is_directory(path))
|
|
|
|
|
{
|
|
|
|
|
HWND ho = GetDlgItem(dh, IDC_EDIT_OUTPUT);
|
2015-06-04 02:11:46 +09:00
|
|
|
|
|
2015-12-17 16:28:53 +09:00
|
|
|
|
const tstring addstr(AddName());
|
|
|
|
|
autoSetAddName = AddName();
|
2015-05-29 01:47:26 +09:00
|
|
|
|
|
2015-12-17 16:28:53 +09:00
|
|
|
|
const auto str = getTString(path.branch_path() / (path.stem().wstring() + addstr));
|
|
|
|
|
SetWindowText(ho, str.c_str());
|
2015-05-29 01:47:26 +09:00
|
|
|
|
|
2015-12-17 16:28:53 +09:00
|
|
|
|
SetWindowText(hWnd, tPath);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
HWND ho = GetDlgItem(dh, IDC_EDIT_OUTPUT);
|
2015-05-29 01:47:26 +09:00
|
|
|
|
|
2015-12-17 16:28:53 +09:00
|
|
|
|
tstring outputFileName = tPath;
|
2015-05-29 01:47:26 +09:00
|
|
|
|
|
2015-12-17 16:28:53 +09:00
|
|
|
|
const auto tailDot = outputFileName.find_last_of('.');
|
|
|
|
|
if (tailDot != outputFileName.npos)
|
|
|
|
|
outputFileName.erase(tailDot, outputFileName.length());
|
2015-05-29 01:47:26 +09:00
|
|
|
|
|
2015-12-17 16:28:53 +09:00
|
|
|
|
const tstring addstr(AddName());
|
|
|
|
|
autoSetAddName = addstr;
|
2015-05-29 01:47:26 +09:00
|
|
|
|
|
2015-12-17 16:28:53 +09:00
|
|
|
|
outputFileName += addstr + outputExt;
|
2015-05-29 01:47:26 +09:00
|
|
|
|
|
2015-12-17 16:28:53 +09:00
|
|
|
|
SetWindowText(ho, outputFileName.c_str());
|
2015-05-29 01:47:26 +09:00
|
|
|
|
|
2015-12-17 16:28:53 +09:00
|
|
|
|
SetWindowText(hWnd, tPath);
|
|
|
|
|
}
|
2015-05-29 01:47:26 +09:00
|
|
|
|
|
2015-12-17 16:28:53 +09:00
|
|
|
|
SetCropSizeList(path);
|
2015-05-29 01:47:26 +09:00
|
|
|
|
|
2015-12-17 16:28:53 +09:00
|
|
|
|
return 0L;
|
|
|
|
|
}
|
2015-06-04 02:11:46 +09:00
|
|
|
|
|
2015-12-17 16:28:53 +09:00
|
|
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD>œn<C593><6E><EFBFBD><EFBFBD><EFBFBD><EFBFBD>hWnd<6E><64>IDC_EDIT<49><54>HWND(<28>R<EFBFBD><52><EFBFBD>g<EFBFBD><67><EFBFBD>[<5B><><EFBFBD>̃C<CC83>x<EFBFBD><78><EFBFBD>g<EFBFBD><67><EFBFBD><EFBFBD><EFBFBD><EFBFBD>)
|
|
|
|
|
LRESULT DropInput(HWND hWnd, WPARAM wParam, LPARAM lParam, WNDPROC OrgSubWnd, LPVOID lpData)
|
|
|
|
|
{
|
|
|
|
|
TCHAR szTmp[AR_PATH_MAX];
|
|
|
|
|
|
|
|
|
|
// <20>h<EFBFBD><68><EFBFBD>b<EFBFBD>v<EFBFBD><76><EFBFBD>ꂽ<EFBFBD>t<EFBFBD>@<40>C<EFBFBD><43><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>擾
|
|
|
|
|
UINT FileNum = DragQueryFile((HDROP)wParam, 0xFFFFFFFF, szTmp, _countof(szTmp));
|
|
|
|
|
if (FileNum >= 1)
|
|
|
|
|
{
|
|
|
|
|
DragQueryFile((HDROP)wParam, 0, szTmp, _countof(szTmp));
|
|
|
|
|
szTmp[_countof(szTmp) - 1] = TEXT('\0');
|
|
|
|
|
|
|
|
|
|
OnSetInputFilePath(szTmp);
|
2015-05-29 01:47:26 +09:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return 0L;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD>œn<C593><6E><EFBFBD><EFBFBD><EFBFBD><EFBFBD>hWnd<6E><64>IDC_EDIT<49><54>HWND(<28>R<EFBFBD><52><EFBFBD>g<EFBFBD><67><EFBFBD>[<5B><><EFBFBD>̃C<CC83>x<EFBFBD><78><EFBFBD>g<EFBFBD><67><EFBFBD><EFBFBD><EFBFBD><EFBFBD>)
|
|
|
|
|
LRESULT DropOutput(HWND hWnd, WPARAM wParam, LPARAM lParam, WNDPROC OrgSubWnd, LPVOID lpData)
|
|
|
|
|
{
|
|
|
|
|
TCHAR szTmp[AR_PATH_MAX];
|
|
|
|
|
|
|
|
|
|
// <20>h<EFBFBD><68><EFBFBD>b<EFBFBD>v<EFBFBD><76><EFBFBD>ꂽ<EFBFBD>t<EFBFBD>@<40>C<EFBFBD><43><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>擾
|
|
|
|
|
UINT FileNum = DragQueryFile((HDROP)wParam, 0xFFFFFFFF, szTmp, AR_PATH_MAX);
|
|
|
|
|
if (FileNum >= 1)
|
|
|
|
|
{
|
|
|
|
|
DragQueryFile((HDROP)wParam, 0, szTmp, AR_PATH_MAX);
|
|
|
|
|
SetWindowText(hWnd, szTmp);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return 0L;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
LRESULT TextInput(HWND hWnd, WPARAM wParam, LPARAM lParam, WNDPROC OrgSubWnd, LPVOID lpData)
|
|
|
|
|
{
|
|
|
|
|
const auto ret = CallWindowProc(OrgSubWnd, hWnd, WM_CHAR, wParam, lParam);
|
|
|
|
|
ReplaceAddString();
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
2015-12-17 16:28:53 +09:00
|
|
|
|
|
|
|
|
|
void InputRef(HWND hWnd, WPARAM wParam, LPARAM lParam, LPVOID lpData)
|
|
|
|
|
{
|
2015-12-17 17:17:33 +09:00
|
|
|
|
SyncMember(false);
|
|
|
|
|
|
2015-12-17 16:28:53 +09:00
|
|
|
|
OPENFILENAME ofn;
|
|
|
|
|
TCHAR szPath[AR_PATH_MAX] = TEXT("");
|
|
|
|
|
TCHAR szFile[AR_PATH_MAX] = TEXT("");
|
|
|
|
|
|
|
|
|
|
GetCurrentDirectory(_countof(szPath), szPath);
|
|
|
|
|
szPath[_countof(szPath) - 1] = TEXT('\0');
|
|
|
|
|
|
2015-12-17 17:17:33 +09:00
|
|
|
|
tstring extStr;
|
|
|
|
|
for (const auto &ext : extList)
|
|
|
|
|
{
|
|
|
|
|
if (extStr.length() != 0)
|
|
|
|
|
extStr += TEXT(";*") + ext;
|
|
|
|
|
else
|
|
|
|
|
extStr = TEXT("*") + ext;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TCHAR szFilter[AR_PATH_MAX] = TEXT("");
|
|
|
|
|
TCHAR *tfp = szFilter;
|
|
|
|
|
|
|
|
|
|
if (extStr.length() > 0)
|
|
|
|
|
{
|
2015-12-27 04:09:08 +09:00
|
|
|
|
tfp += _stprintf(tfp, langStringList.GetString(L"MessageExtStr").c_str(), extStr.c_str());
|
2015-12-17 17:17:33 +09:00
|
|
|
|
tfp++;
|
|
|
|
|
|
|
|
|
|
memcpy(tfp, extStr.c_str(), extStr.length() * sizeof(TCHAR));
|
|
|
|
|
tfp += extStr.length();
|
|
|
|
|
|
|
|
|
|
*tfp = TEXT('\0');
|
|
|
|
|
tfp++;
|
|
|
|
|
}
|
|
|
|
|
|
2015-12-27 04:09:08 +09:00
|
|
|
|
const tstring allFilesTitle(langStringList.GetString(L"MessageAllFileFolder").c_str());
|
2015-12-17 17:17:33 +09:00
|
|
|
|
memcpy(tfp, allFilesTitle.c_str(), allFilesTitle.length() * sizeof(TCHAR));
|
|
|
|
|
tfp += allFilesTitle.length();
|
|
|
|
|
*tfp = TEXT('\0');
|
|
|
|
|
tfp++;
|
|
|
|
|
|
|
|
|
|
const tstring allFilesExt(TEXT("*.*"));
|
|
|
|
|
memcpy(tfp, allFilesExt.c_str(), allFilesExt.length() * sizeof(TCHAR));
|
|
|
|
|
tfp += allFilesExt.length();
|
|
|
|
|
|
|
|
|
|
*tfp = TEXT('\0');
|
|
|
|
|
tfp++;
|
|
|
|
|
*tfp = TEXT('\0');
|
|
|
|
|
tfp++;
|
|
|
|
|
|
2015-12-17 16:28:53 +09:00
|
|
|
|
ofn.lStructSize = sizeof(ofn);
|
|
|
|
|
ofn.hwndOwner = NULL;
|
|
|
|
|
ofn.lpstrFile = szFile;
|
|
|
|
|
ofn.nMaxFile = _countof(szFile);
|
2015-12-17 17:17:33 +09:00
|
|
|
|
ofn.lpstrFilter = szFilter;
|
2015-12-17 16:28:53 +09:00
|
|
|
|
ofn.nFilterIndex = 1;
|
2015-12-27 04:09:08 +09:00
|
|
|
|
ofn.lpstrTitle = langStringList.GetString(L"MessageTitleInputDialog").c_str();
|
2015-12-17 16:28:53 +09:00
|
|
|
|
ofn.lpstrInitialDir = szPath;
|
|
|
|
|
ofn.lpstrCustomFilter = NULL;
|
|
|
|
|
ofn.nMaxCustFilter = 0;
|
|
|
|
|
ofn.lpstrFileTitle = NULL;
|
|
|
|
|
ofn.nMaxFileTitle = 0;
|
|
|
|
|
ofn.nFileOffset = 0;
|
|
|
|
|
ofn.nFileExtension = 0;
|
|
|
|
|
ofn.lpstrDefExt = NULL;
|
|
|
|
|
ofn.lCustData = 0;
|
|
|
|
|
ofn.lpfnHook = OFNHookProcIn;
|
|
|
|
|
ofn.lpTemplateName = 0;
|
|
|
|
|
ofn.Flags = OFN_HIDEREADONLY | OFN_NOVALIDATE | OFN_PATHMUSTEXIST | OFN_READONLY | OFN_EXPLORER | OFN_ENABLEHOOK;
|
|
|
|
|
if (GetOpenFileName(&ofn))
|
|
|
|
|
{
|
|
|
|
|
szFile[_countof(szFile) - 1] = TEXT('\0');
|
|
|
|
|
OnSetInputFilePath(szFile);
|
|
|
|
|
}
|
|
|
|
|
}
|
2015-12-27 02:46:42 +09:00
|
|
|
|
|
|
|
|
|
void LangChange(HWND hWnd, WPARAM wParam, LPARAM lParam, LPVOID lpData)
|
|
|
|
|
{
|
|
|
|
|
if (HIWORD(wParam) != CBN_SELCHANGE)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
HWND hlang = GetDlgItem(dh, IDC_COMBO_LANG);
|
|
|
|
|
|
|
|
|
|
const int cur = SendMessage(hlang, CB_GETCURSEL, 0, 0);
|
|
|
|
|
|
|
|
|
|
const auto &list = langStringList.GetLangList();
|
|
|
|
|
|
|
|
|
|
if (list.size() <= cur)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
langStringList.SetLang(list[cur]);
|
|
|
|
|
|
|
|
|
|
SetWindowTextLang();
|
|
|
|
|
}
|
2015-05-29 01:47:26 +09:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
int WINAPI WinMain(HINSTANCE hInstance,
|
|
|
|
|
HINSTANCE hPrevInstance,
|
|
|
|
|
LPSTR lpCmdLine,
|
|
|
|
|
int nCmdShow)
|
|
|
|
|
{
|
2015-12-04 00:48:55 +09:00
|
|
|
|
Waifu2x::init_liblary();
|
|
|
|
|
|
2015-12-18 00:20:17 +09:00
|
|
|
|
// <20>Ǘ<EFBFBD><C797>Ҍ<EFBFBD><D28C><EFBFBD><EFBFBD>ŋN<C58B><4E><EFBFBD><EFBFBD><EFBFBD>Ă<EFBFBD><C482>t<EFBFBD>@<40>C<EFBFBD><43><EFBFBD>̃h<CC83><68><EFBFBD>b<EFBFBD>v<EFBFBD><76><EFBFBD>t<F382AF95><74><EFBFBD><EFBFBD><EFBFBD>悤<EFBFBD>ɂ<EFBFBD><C982><EFBFBD>
|
|
|
|
|
ChangeWindowMessageFilter(WM_DROPFILES, MSGFLT_ADD);
|
|
|
|
|
ChangeWindowMessageFilter(WM_COPYDATA, MSGFLT_ADD);
|
|
|
|
|
ChangeWindowMessageFilter(0x0049, MSGFLT_ADD);
|
|
|
|
|
|
2015-12-07 16:59:42 +09:00
|
|
|
|
// Caffe<66>̃G<CC83><47><EFBFBD>[<5B>łȂ<C582><C882><EFBFBD><EFBFBD>O<EFBFBD><4F><EFBFBD>ۑ<EFBFBD><DB91><EFBFBD><EFBFBD>Ȃ<EFBFBD><C882>悤<EFBFBD>ɂ<EFBFBD><C982><EFBFBD>
|
|
|
|
|
google::SetLogDestination(google::INFO, "");
|
|
|
|
|
google::SetLogDestination(google::WARNING, "");
|
|
|
|
|
|
|
|
|
|
// Caffe<66>̃G<CC83><47><EFBFBD>[<5B><><EFBFBD>O<EFBFBD><4F><EFBFBD>uerror_log_<67>`<60>v<EFBFBD>ɏo<C98F><6F>
|
|
|
|
|
google::SetLogDestination(google::ERROR, "error_log_");
|
|
|
|
|
google::SetLogDestination(google::FATAL, "error_log_");
|
|
|
|
|
|
2015-05-29 01:47:26 +09:00
|
|
|
|
// CDialog<6F>N<EFBFBD><4E><EFBFBD>X<EFBFBD>Ń_<C583>C<EFBFBD>A<EFBFBD><41><EFBFBD>O<EFBFBD><4F><EFBFBD>쐬<EFBFBD><EC90AC><EFBFBD><EFBFBD>
|
|
|
|
|
CDialog cDialog;
|
|
|
|
|
CDialog cDialog2;
|
|
|
|
|
// IDC_EDIT<49>̃T<CC83>u<EFBFBD>N<EFBFBD><4E><EFBFBD>X
|
|
|
|
|
CControl cControlInput(IDC_EDIT_INPUT);
|
|
|
|
|
CControl cControlOutput(IDC_EDIT_OUTPUT);
|
|
|
|
|
CControl cControlScale(IDC_EDIT_SCALE_RATIO);
|
|
|
|
|
CControl cControlOutExt(IDC_EDIT_OUT_EXT);
|
|
|
|
|
|
|
|
|
|
// <20>o<EFBFBD>^<5E><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><D690><EFBFBD><EFBFBD>܂Ƃ߂<C682><DF82>ꂽ<EFBFBD>N<EFBFBD><4E><EFBFBD>X
|
|
|
|
|
// <20>O<EFBFBD><4F><EFBFBD>[<5B>o<EFBFBD><6F><EFBFBD><EFBFBD><D690><EFBFBD><EFBFBD>g<EFBFBD><67><EFBFBD>N<CE83><4E><EFBFBD>X<EFBFBD>ɂ܂Ƃ߂<C682><DF82>K<EFBFBD>v<EFBFBD>͂Ȃ<CD82><C882><EFBFBD><EFBFBD><EFBFBD><EFBFBD>̕<EFBFBD><CC95>@<40><><EFBFBD>𗧂<F097A782><C282>Ƃ<EFBFBD><C682><EFBFBD><EFBFBD><EFBFBD><EFBFBD>͂<EFBFBD>
|
|
|
|
|
DialogEvent cDialogEvent;
|
|
|
|
|
|
|
|
|
|
// <20>N<EFBFBD><4E><EFBFBD>X<EFBFBD>̊<CC8A><D690><EFBFBD><EFBFBD>o<EFBFBD>^<5E><><EFBFBD><EFBFBD><EFBFBD>ꍇ
|
|
|
|
|
|
|
|
|
|
// IDC_EDIT<49><54>WM_DROPFILES<45><53><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ă<EFBFBD><C482><EFBFBD><EFBFBD>Ƃ<EFBFBD><C682>Ɏ<EFBFBD><C98E>s<EFBFBD><73><EFBFBD><EFBFBD><EFBFBD><EFBFBD><D690>̓o<CC93>^
|
|
|
|
|
cControlInput.SetEventCallBack(SetClassCustomFunc(DialogEvent::DropInput, &cDialogEvent), NULL, WM_DROPFILES);
|
|
|
|
|
cControlOutput.SetEventCallBack(SetClassCustomFunc(DialogEvent::DropOutput, &cDialogEvent), NULL, WM_DROPFILES);
|
|
|
|
|
cControlScale.SetEventCallBack(SetClassCustomFunc(DialogEvent::TextInput, &cDialogEvent), NULL, WM_CHAR);
|
|
|
|
|
cControlOutExt.SetEventCallBack(SetClassCustomFunc(DialogEvent::TextInput, &cDialogEvent), NULL, WM_CHAR);
|
|
|
|
|
|
|
|
|
|
// <20>R<EFBFBD><52><EFBFBD>g<EFBFBD><67><EFBFBD>[<5B><><EFBFBD>̃T<CC83>u<EFBFBD>N<EFBFBD><4E><EFBFBD>X<EFBFBD><58><EFBFBD>o<EFBFBD>^
|
|
|
|
|
cDialog.AddControl(&cControlInput);
|
|
|
|
|
cDialog.AddControl(&cControlOutput);
|
|
|
|
|
cDialog.AddControl(&cControlScale);
|
|
|
|
|
cDialog.AddControl(&cControlOutExt);
|
|
|
|
|
|
|
|
|
|
// <20>e<EFBFBD>R<EFBFBD><52><EFBFBD>g<EFBFBD><67><EFBFBD>[<5B><><EFBFBD>̃C<CC83>x<EFBFBD><78><EFBFBD>g<EFBFBD>Ŏ<EFBFBD><C58E>s<EFBFBD><73><EFBFBD><EFBFBD><EFBFBD><EFBFBD><D690>̓o<CC93>^
|
|
|
|
|
cDialog.SetCommandCallBack(SetClassFunc(DialogEvent::Exec, &cDialogEvent), NULL, IDC_BUTTON_EXEC);
|
|
|
|
|
cDialog.SetCommandCallBack(SetClassFunc(DialogEvent::Cancel, &cDialogEvent), NULL, IDC_BUTTON_CANCEL);
|
2015-12-17 16:28:53 +09:00
|
|
|
|
cDialog.SetCommandCallBack(SetClassFunc(DialogEvent::InputRef, &cDialogEvent), NULL, IDC_BUTTON_INPUT_REF);
|
2015-05-29 01:47:26 +09:00
|
|
|
|
|
|
|
|
|
cDialog.SetCommandCallBack(SetClassFunc(DialogEvent::RadioButtom, &cDialogEvent), NULL, IDC_RADIO_MODE_NOISE);
|
|
|
|
|
cDialog.SetCommandCallBack(SetClassFunc(DialogEvent::RadioButtom, &cDialogEvent), NULL, IDC_RADIO_MODE_SCALE);
|
|
|
|
|
cDialog.SetCommandCallBack(SetClassFunc(DialogEvent::RadioButtom, &cDialogEvent), NULL, IDC_RADIO_MODE_NOISE_SCALE);
|
|
|
|
|
cDialog.SetCommandCallBack(SetClassFunc(DialogEvent::RadioButtom, &cDialogEvent), NULL, IDC_RADIO_AUTO_SCALE);
|
|
|
|
|
cDialog.SetCommandCallBack(SetClassFunc(DialogEvent::RadioButtom, &cDialogEvent), NULL, IDC_RADIONOISE_LEVEL1);
|
2015-06-01 22:09:57 +09:00
|
|
|
|
cDialog.SetCommandCallBack(SetClassFunc(DialogEvent::RadioButtom, &cDialogEvent), NULL, IDC_RADIONOISE_LEVEL2);
|
2015-05-29 01:47:26 +09:00
|
|
|
|
cDialog.SetCommandCallBack(SetClassFunc(DialogEvent::RadioButtom, &cDialogEvent), NULL, IDC_RADIO_MODE_CPU);
|
|
|
|
|
cDialog.SetCommandCallBack(SetClassFunc(DialogEvent::RadioButtom, &cDialogEvent), NULL, IDC_RADIO_MODE_GPU);
|
2015-12-06 21:24:09 +09:00
|
|
|
|
cDialog.SetCommandCallBack(SetClassFunc(DialogEvent::RadioButtom, &cDialogEvent), NULL, IDC_RADIO_MODEL_RGB);
|
|
|
|
|
cDialog.SetCommandCallBack(SetClassFunc(DialogEvent::RadioButtom, &cDialogEvent), NULL, IDC_RADIO_MODEL_PHOTO);
|
|
|
|
|
cDialog.SetCommandCallBack(SetClassFunc(DialogEvent::RadioButtom, &cDialogEvent), NULL, IDC_RADIO_MODEL_Y);
|
2015-05-29 01:47:26 +09:00
|
|
|
|
|
2015-11-19 02:22:49 +09:00
|
|
|
|
cDialog.SetCommandCallBack(SetClassFunc(DialogEvent::RadioButtom, &cDialogEvent), NULL, IDC_CHECK_TTA);
|
|
|
|
|
|
2015-05-29 01:47:26 +09:00
|
|
|
|
cDialog.SetCommandCallBack(SetClassFunc(DialogEvent::CheckCUDNN, &cDialogEvent), NULL, IDC_BUTTON_CHECK_CUDNN);
|
|
|
|
|
|
2015-12-27 02:46:42 +09:00
|
|
|
|
cDialog.SetCommandCallBack(SetClassFunc(DialogEvent::LangChange, &cDialogEvent), NULL, IDC_COMBO_LANG);
|
|
|
|
|
|
2015-05-29 01:47:26 +09:00
|
|
|
|
// <20>_<EFBFBD>C<EFBFBD>A<EFBFBD><41><EFBFBD>O<EFBFBD>̃C<CC83>x<EFBFBD><78><EFBFBD>g<EFBFBD>Ŏ<EFBFBD><C58E>s<EFBFBD><73><EFBFBD><EFBFBD><EFBFBD><EFBFBD><D690>̓o<CC93>^
|
|
|
|
|
cDialog.SetEventCallBack(SetClassFunc(DialogEvent::Create, &cDialogEvent), NULL, WM_INITDIALOG);
|
|
|
|
|
cDialog.SetEventCallBack(SetClassFunc(DialogEvent::OnDialogEnd, &cDialogEvent), NULL, WM_CLOSE);
|
|
|
|
|
cDialog.SetEventCallBack(SetClassFunc(DialogEvent::OnFaildCreateDir, &cDialogEvent), NULL, WM_FAILD_CREATE_DIR);
|
2015-06-03 03:01:56 +09:00
|
|
|
|
cDialog.SetEventCallBack(SetClassFunc(DialogEvent::OnWaifu2xError, &cDialogEvent), NULL, WM_ON_WAIFU2X_ERROR);
|
2015-05-29 01:47:26 +09:00
|
|
|
|
cDialog.SetEventCallBack(SetClassFunc(DialogEvent::WaitThreadExit, &cDialogEvent), NULL, WM_END_THREAD);
|
|
|
|
|
|
|
|
|
|
// <20>_<EFBFBD>C<EFBFBD>A<EFBFBD><41><EFBFBD>O<EFBFBD><4F><EFBFBD>\<5C><>
|
|
|
|
|
cDialog.DoModal(hInstance, IDD_DIALOG);
|
|
|
|
|
|
2015-12-04 00:48:55 +09:00
|
|
|
|
Waifu2x::quit_liblary();
|
|
|
|
|
|
2015-05-29 01:47:26 +09:00
|
|
|
|
return 0;
|
|
|
|
|
}
|