From c131ca38c48b05947d69f9bfc49ec4c60ba0ed4b Mon Sep 17 00:00:00 2001 From: lltcggie Date: Sat, 1 Dec 2018 15:25:41 +0900 Subject: [PATCH] =?UTF-8?q?GUI=E3=81=A7=E3=83=A2=E3=83=87=E3=83=AB?= =?UTF-8?q?=E3=81=94=E3=81=A8=E3=81=AE=E5=88=86=E5=89=B2=E3=82=B5=E3=82=A4?= =?UTF-8?q?=E3=82=BAMod=E5=88=B6=E9=99=90=E3=81=AB=E5=BC=95=E3=81=A3?= =?UTF-8?q?=E3=81=8B=E3=81=8B=E3=81=A3=E3=81=9F=E5=A0=B4=E5=90=88=E3=81=AF?= =?UTF-8?q?=E3=82=A8=E3=83=A9=E3=83=BC=E3=83=80=E3=82=A4=E3=82=A2=E3=83=AD?= =?UTF-8?q?=E3=82=B0=E3=82=92=E5=87=BA=E3=81=99=E3=82=88=E3=81=86=E3=81=AB?= =?UTF-8?q?=E3=81=97=E3=81=9F=20resolved=20#135=20=E3=83=A2=E3=83=87?= =?UTF-8?q?=E3=83=AB=E3=81=AB=E3=82=88=E3=81=A3=E3=81=A6=E3=81=AF=E5=88=86?= =?UTF-8?q?=E5=89=B2=E3=82=B5=E3=82=A4=E3=82=BA=E3=81=8C=E3=81=82=E3=82=8B?= =?UTF-8?q?=E6=95=B0=E3=81=A7=E5=89=B2=E3=82=8A=E5=88=87=E3=82=8C=E3=81=AA?= =?UTF-8?q?=E3=81=84=E3=81=A8=E3=82=A8=E3=83=A9=E3=83=BC=E3=81=8C=E8=B5=B7?= =?UTF-8?q?=E3=81=8D=E3=82=8B=E3=81=AE=E3=81=A7=E3=81=9D=E3=81=AE=E5=AF=BE?= =?UTF-8?q?=E5=BF=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bin/lang/english.json | 3 +- bin/lang/japanese.json | 3 +- bin/models/cunet/info.json | 2 +- common/cNet.cpp | 2 + common/waifu2x.h | 1 + waifu2x-caffe-gui/MainDialog.cpp | 77 +++++++++++++++++++++----------- 6 files changed, 60 insertions(+), 28 deletions(-) diff --git a/bin/lang/english.json b/bin/lang/english.json index c445f03..edd68bc 100644 --- a/bin/lang/english.json +++ b/bin/lang/english.json @@ -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" } diff --git a/bin/lang/japanese.json b/bin/lang/japanese.json index 5b972ec..4899ebc 100644 --- a/bin/lang/japanese.json +++ b/bin/lang/japanese.json @@ -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 で割り切れる必要があります" } diff --git a/bin/models/cunet/info.json b/bin/models/cunet/info.json index d95a76b..fafc76b 100644 --- a/bin/models/cunet/info.json +++ b/bin/models/cunet/info.json @@ -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 } \ No newline at end of file diff --git a/common/cNet.cpp b/common/cNet.cpp index 5fdea92..71686de 100644 --- a/common/cNet.cpp +++ b/common/cNet.cpp @@ -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")) { diff --git a/common/waifu2x.h b/common/waifu2x.h index 1749960..929c305 100644 --- a/common/waifu2x.h +++ b/common/waifu2x.h @@ -76,6 +76,7 @@ class Waifu2x bool has_noise_scale; bool has_noise_only; int channels; + int force_divisible_crop_size; stParam noise; stParam scale; diff --git a/waifu2x-caffe-gui/MainDialog.cpp b/waifu2x-caffe-gui/MainDialog.cpp index 1556071..f9dd1bc 100644 --- a/waifu2x-caffe-gui/MainDialog.cpp +++ b/waifu2x-caffe-gui/MainDialog.cpp @@ -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) // ̃fł͐ݒłȂ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) // ̃fł͐ݒłȂ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) // ̃fł͐ݒłȂ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̒lljĂ - 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̒lljĂ + int mindiff = INT_MAX; + int defaultListIndex = -1; + for (const auto n : CropSizeList) + { + if (n % info.force_divisible_crop_size != 0) // ̃fł͐ݒłȂ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