GUIでモデルごとの分割サイズMod制限に引っかかった場合はエラーダイアログを出すようにした resolved #135

モデルによっては分割サイズがある数で割り切れないとエラーが起きるのでその対応
This commit is contained in:
lltcggie 2018-12-01 15:25:41 +09:00
parent 62c0f4bc71
commit c131ca38c4
6 changed files with 60 additions and 28 deletions

View File

@ -100,5 +100,6 @@
"MessageLogFatalError":"A fatal error has occurred.\r\nThere is a possibility the split size is too large",
"IDC_STATIC_BATCH_SIZE":"Batch size",
"MessageBatchSizeCheckError":"Batch size must be greater than 0",
"IDC_RADIO_MODEL_CUNET":"2-D illust (CUnet Model)"
"IDC_RADIO_MODEL_CUNET":"2-D illust (CUnet Model)",
"MessageCropSizeDivisibleCheckError":"Split size of this model must be divisible by %d"
}

View File

@ -100,5 +100,6 @@
"MessageLogFatalError":"致命的なエラーが発生しました。\r\n分割サイズが大きすぎる可能性があります",
"IDC_STATIC_BATCH_SIZE":"バッチサイズ",
"MessageBatchSizeCheckError":"バッチサイズは0より大きい整数である必要があります",
"IDC_RADIO_MODEL_CUNET":"2次元イラスト (CUnet)"
"IDC_RADIO_MODEL_CUNET":"2次元イラスト (CUnet)",
"MessageCropSizeDivisibleCheckError":"このモデルの分割サイズは %d で割り切れる必要があります"
}

View File

@ -1,4 +1,4 @@
{"name":"CUnet","arch_name":"upcunet","has_noise_scale":true,"has_noise_only":true, "channels":3,
{"name":"CUnet","arch_name":"upcunet","has_noise_scale":true,"has_noise_only":true,"channels":3,"force_divisible_crop_size":4,
"scale_factor":2,"offset":36,
"scale_factor_noise":1,"offset_noise":28
}

View File

@ -192,12 +192,14 @@ Waifu2x::eWaifu2xError cNet::GetInfo(const boost::filesystem::path & info_path,
const bool has_noise_scale = d.HasMember("has_noise_scale") && d["has_noise_scale"].GetBool() ? true : false;
const bool has_noise_only = d.HasMember("has_noise_only") && d["has_noise_only"].GetBool() ? true : false;
const int channels = d["channels"].GetInt();
const int force_divisible_crop_size = d.HasMember("force_divisible_crop_size") ? d["force_divisible_crop_size"].GetInt() : 1;
info.name = name;
info.arch_name = arch_name;
info.has_noise_scale = has_noise_scale;
info.has_noise_only = has_noise_only;
info.channels = channels;
info.force_divisible_crop_size = force_divisible_crop_size;
if (d.HasMember("offset"))
{

View File

@ -76,6 +76,7 @@ public:
bool has_noise_scale;
bool has_noise_only;
int channels;
int force_divisible_crop_size;
stParam noise;
stParam scale;

View File

@ -453,6 +453,10 @@ bool DialogEvent::SyncMember(const bool NotSyncCropSize, const bool silent)
GetWindowText(GetDlgItem(dh, IDC_COMBO_CROP_SIZE), buf, _countof(buf));
buf[_countof(buf) - 1] = TEXT('\0');
Waifu2x::stInfo info;
if (!Waifu2x::GetInfo(model_dir, info))
info.force_divisible_crop_size = 1;
TCHAR *ptr = nullptr;
crop_size = _tcstol(buf, &ptr, 10);
if (!ptr || *ptr != '\0' || crop_size <= 0)
@ -462,6 +466,14 @@ bool DialogEvent::SyncMember(const bool NotSyncCropSize, const bool silent)
MessageBox(dh, langStringList.GetString(L"MessageCropSizeCheckError").c_str(), langStringList.GetString(L"MessageTitleError").c_str(), MB_OK | MB_ICONERROR);
}
else if (crop_size % info.force_divisible_crop_size != 0) // このモデルでは設定できないCropSize
{
wchar_t buf[1024] = { TEXT('\0') };
swprintf(buf, langStringList.GetString(L"MessageCropSizeDivisibleCheckError").c_str(), info.force_divisible_crop_size);
ret = false;
MessageBoxW(dh, buf, langStringList.GetString(L"MessageTitleError").c_str(), MB_OK | MB_ICONERROR);
}
}
{
@ -557,6 +569,9 @@ void DialogEvent::SetCropSizeList(const boost::filesystem::path & input_path)
{
const int n = list[i];
if (n % info.force_divisible_crop_size != 0) // このモデルでは設定できないCropSize
continue;
tstring str(to_tstring(n));
const int index = SendMessage(hcrop, CB_ADDSTRING, 0, (LPARAM)str.c_str());
@ -575,6 +590,9 @@ void DialogEvent::SetCropSizeList(const boost::filesystem::path & input_path)
int defaultListIndex = -1;
for (const auto n : CropSizeList)
{
if (n % info.force_divisible_crop_size != 0) // このモデルでは設定できないCropSize
continue;
tstring str(to_tstring(n));
const int index = SendMessage(hcrop, CB_ADDSTRING, 0, (LPARAM)str.c_str());
@ -1822,31 +1840,6 @@ void DialogEvent::Create(HWND hWnd, WPARAM wParam, LPARAM lParam, LPVOID lpData)
SendMessage(hbatch, CB_SETCURSEL, 0, 0);
}
{
HWND hcrop = GetDlgItem(dh, IDC_COMBO_CROP_SIZE);
SendMessage(hcrop, CB_ADDSTRING, 0, (LPARAM)TEXT("-----------------------"));
// CropSizeListÌlðljÁµÄ¢­
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);
}
tstring tScaleRatio;
tstring tScaleWidth;
tstring tScaleHeight;
@ -2088,6 +2081,40 @@ void DialogEvent::Create(HWND hWnd, WPARAM wParam, LPARAM lParam, LPVOID lpData)
SendMessage(GetDlgItem(dh, IDC_COMBO_MODEL), CB_SETCURSEL, index, 0);
{
HWND hcrop = GetDlgItem(dh, IDC_COMBO_CROP_SIZE);
SendMessage(hcrop, CB_ADDSTRING, 0, (LPARAM)TEXT("-----------------------"));
const auto model_dir = ModelPathList[index];
Waifu2x::stInfo info;
if (!Waifu2x::GetInfo(model_dir, info))
info.force_divisible_crop_size = 1;
// CropSizeListの値を追加していく
int mindiff = INT_MAX;
int defaultListIndex = -1;
for (const auto n : CropSizeList)
{
if (n % info.force_divisible_crop_size != 0) // このモデルでは設定できないCropSize
continue;
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);
}
if (use_tta)
SendMessage(GetDlgItem(hWnd, IDC_CHECK_TTA), BM_SETCHECK, BST_CHECKED, 0);
else