Skip to content

Commit

Permalink
CUGAN: limit param
Browse files Browse the repository at this point in the history
  • Loading branch information
YukihoAA committed Oct 16, 2022
1 parent ad1d509 commit b23d5b9
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 17 deletions.
11 changes: 9 additions & 2 deletions waifu2x_snowshell/Main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) {
return TRUE;
if (SnowSetting::CurrentConverter == &SnowSetting::CONVERTER_VULKAN)
DialogBox(g_hInst, MAKEINTRESOURCE(IDD_DIALOG3), hWnd, SettingDlgProcVulkan);
else if (SnowSetting::CurrentConverter == &SnowSetting::CONVERTER_CUGAN || SnowSetting::CurrentConverter == &SnowSetting::CONVERTER_ESRGAN)
else if (SnowSetting::CurrentConverter == &SnowSetting::CONVERTER_CUGAN)
DialogBox(g_hInst, MAKEINTRESOURCE(IDD_DIALOG3), hWnd, SettingDlgProcCugan);
else
DialogBox(g_hInst, MAKEINTRESOURCE(IDD_DIALOG1), hWnd, SettingDlgProc);
Expand All @@ -219,6 +219,11 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) {
case ID_MENU_SCALE_x2_0:
SnowSetting::checkScale(hMenu, LOWORD(wParam) - ID_MENU_SCALE_x1_0);
UIText[1] = SnowSetting::getScaleText();

if (SnowSetting::CurrentConverter == &SnowSetting::CONVERTER_CUGAN) {
SnowSetting::checkNoise(hMenu, SnowSetting::getNoise());
UIText[0] = SnowSetting::getNoiseText();
}
InvalidateRect(hWnd, NULL, TRUE);
return TRUE;
case ID_MENU_GPU_CPU:
Expand Down Expand Up @@ -339,8 +344,10 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) {
prtTextBorder(hMemDC, 430, 2, L"waifu2x-caffe", 13, RGB(0x21, 0x21, 0x21), 1);
else if (SnowSetting::CurrentConverter == &SnowSetting::CONVERTER_VULKAN)
prtTextBorder(hMemDC, 385, 2, L"waifu2x-ncnn-vulkan", 19, RGB(0x21, 0x21, 0x21), 1);
else
else if (SnowSetting::CurrentConverter == &SnowSetting::CONVERTER_CUGAN)
prtTextBorder(hMemDC, 405, 2, L"realcugan-vulkan", 16, RGB(0x21, 0x21, 0x21), 1);
else
prtTextBorder(hMemDC, 400, 2, L"realesrgan-vulkan", 17, RGB(0x21, 0x21, 0x21), 1);

prtTextBorder(hMemDC, 410, 288, L" =▶", 3, RGB(0x21, 0x21, 0x21), 1);

Expand Down
46 changes: 31 additions & 15 deletions waifu2x_snowshell/SnowSetting.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -600,13 +600,13 @@ bool SnowSetting::loadSetting()
setConverterNum(CONVERTER_NUM_CUGAN);
setScale(getScale());
}
else if (checkVulkan() && CONVERTER_ESRGAN.getAvailable()) {
setConverterNum(CONVERTER_NUM_ESRGAN);
setScale(getScale());
}
else if (checkCuda() && CONVERTER_CAFFE.getAvailable()) {
setConverterNum(CONVERTER_NUM_CAFFE);
}
else if (checkVulkan() && CONVERTER_ESRGAN.getAvailable()) {
setConverterNum(CONVERTER_NUM_ESRGAN);
setScale(SCALE_CUSTOM);
}
else if (CONVERTER_CPP.getAvailable()) {
setConverterNum(CONVERTER_NUM_CPP);
}
Expand Down Expand Up @@ -846,10 +846,12 @@ void SnowSetting::setScale(int Scale)

if (Scale > SCALE_MAX || Scale < 0)
Scale = SCALE_x2_0;

if (CurrentConverter == &CONVERTER_VULKAN && Scale != SCALE_x1_0 && Scale != SCALE_x2_0 && Scale != SCALE_CUSTOM)
else if (CurrentConverter == &CONVERTER_ESRGAN) {
Scale = SCALE_CUSTOM;
}
else if (CurrentConverter == &CONVERTER_VULKAN && Scale != SCALE_x1_0 && Scale != SCALE_x2_0 && Scale != SCALE_CUSTOM)
Scale = SCALE_x2_0;
else if ((CurrentConverter == &CONVERTER_CUGAN || CurrentConverter == &CONVERTER_ESRGAN) && Scale != SCALE_x2_0 && Scale != SCALE_CUSTOM)
else if (CurrentConverter == &CONVERTER_CUGAN&& Scale != SCALE_x2_0 && Scale != SCALE_CUSTOM)
Scale = SCALE_x2_0;

Singletone->Scale = Scale;
Expand Down Expand Up @@ -934,7 +936,7 @@ void SnowSetting::setConverterNum(int ConverterNum)
if (!wcscmp(VulkanScale[i], Singletone->ScaleRatio.c_str()))
return;
}
Singletone->ScaleRatio = L"2.0";
Singletone->ScaleRatio = L"4.0";
}
break;
case CONVERTER_NUM_CUGAN:
Expand All @@ -946,19 +948,15 @@ void SnowSetting::setConverterNum(int ConverterNum)
if (!wcscmp(VulkanScale[i], Singletone->ScaleRatio.c_str()))
return;
}
Singletone->ScaleRatio = L"2.0";
Singletone->ScaleRatio = L"4.0";
}
break;
case CONVERTER_NUM_ESRGAN:
CONVERTER_ESRGAN.checkAvailable();
if (CONVERTER_ESRGAN.getAvailable()) {
Singletone->CurrentConverter = &CONVERTER_ESRGAN;
Singletone->ConverterNum = ConverterNum;
for (int i = 0; i < CuganScaleNum; i++) {
if (!wcscmp(VulkanScale[i], Singletone->ScaleRatio.c_str()))
return;
}
Singletone->ScaleRatio = L"2.0";
Singletone->ScaleRatio = L"4.0";
}
break;
}
Expand Down Expand Up @@ -1010,8 +1008,17 @@ void SnowSetting::checkNoise(HMENU hMenu, int sel)
EnableMenuItem(hMenu, MENU_NOISE, MF_BYPOSITION | MF_GRAYED);
return;
}
else if (CurrentConverter == &CONVERTER_CUGAN && getScale() == SCALE_CUSTOM) {
EnableMenuItem(hSubMenu, NOISE_MID, MF_BYPOSITION | MF_GRAYED);
EnableMenuItem(hSubMenu, NOISE_HIGH, MF_BYPOSITION | MF_GRAYED);

if (getNoise() == NOISE_MID || getNoise() == NOISE_HIGH)
setNoise(NOISE_LOW);
}
else {
EnableMenuItem(hMenu, MENU_NOISE, MF_BYPOSITION | MF_ENABLED);
EnableMenuItem(hSubMenu, NOISE_MID, MF_BYPOSITION | MF_ENABLED);
EnableMenuItem(hSubMenu, NOISE_HIGH, MF_BYPOSITION | MF_ENABLED);
}

for (int i = 0; i <= NOISE_MAX; i++)
Expand All @@ -1026,6 +1033,15 @@ void SnowSetting::checkScale(HMENU hMenu, int sel)
if (sel != -1)
setScale(sel);

if (CurrentConverter == &CONVERTER_ESRGAN) {
EnableMenuItem(hMenu, MENU_SCALE, MF_BYPOSITION | MF_GRAYED);
setScale(SCALE_CUSTOM);
return;
}
else {
EnableMenuItem(hMenu, MENU_SCALE, MF_BYPOSITION | MF_ENABLED);
}

for (int i = 0; i <= SCALE_MAX; i++)
CheckMenuItem(hSubMenu, i, MF_BYPOSITION | MF_UNCHECKED);

Expand All @@ -1036,7 +1052,7 @@ void SnowSetting::checkScale(HMENU hMenu, int sel)
if (getScale() == SCALE_x1_5 || getScale() == SCALE_x1_6)
setScale(SCALE_x2_0);
}
else if (CurrentConverter == &CONVERTER_CUGAN || CurrentConverter == &CONVERTER_ESRGAN) {
else if (CurrentConverter == &CONVERTER_CUGAN) {
EnableMenuItem(hSubMenu, SCALE_x1_0, MF_BYPOSITION | MF_GRAYED);
EnableMenuItem(hSubMenu, SCALE_x1_5, MF_BYPOSITION | MF_GRAYED);
EnableMenuItem(hSubMenu, SCALE_x1_6, MF_BYPOSITION | MF_GRAYED);
Expand Down

0 comments on commit b23d5b9

Please sign in to comment.