Skip to content

Commit afaf635

Browse files
committed
GUIのデフォルト分割サイズがすごく大きい値になってしまうことがあるバグを修正
1 parent 6e0dbb9 commit afaf635

File tree

1 file changed

+17
-5
lines changed

1 file changed

+17
-5
lines changed

waifu2x-caffe-gui/Source.cpp

+17-5
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ const size_t AR_PATH_MAX(1024);
2727

2828
const int MinCommonDivisor = 50;
2929
const int DefaultCommonDivisor = 128;
30+
const std::pair<int, int> DefaultCommonDivisorRange = {90, 140};
3031

3132
const char * const CropSizeListName = "crop_size_list.txt";
3233

@@ -292,7 +293,7 @@ class DialogEvent
292293
), list.end());
293294

294295
int mindiff = INT_MAX;
295-
int defaultIndex = 0;
296+
int defaultIndex = -1;
296297
for (int i = 0; i < list.size(); i++)
297298
{
298299
const int n = list[i];
@@ -301,23 +302,34 @@ class DialogEvent
301302
SendMessageA(hcrop, CB_ADDSTRING, 0, (LPARAM)str.c_str());
302303

303304
const int diff = abs(DefaultCommonDivisor - n);
304-
if (diff < mindiff)
305+
if (DefaultCommonDivisorRange.first <= n && n <= DefaultCommonDivisorRange.second && diff < mindiff)
305306
{
306307
mindiff = diff;
307308
defaultIndex = i;
308309
}
309310
}
310311

311-
if (SendMessageA(hcrop, CB_ADDSTRING, 0, (LPARAM)"-----------------------") == defaultIndex)
312-
defaultIndex = 1;
312+
SendMessageA(hcrop, CB_ADDSTRING, 0, (LPARAM)"-----------------------");
313313

314314
// CropSizeListの値を追加していく
315+
mindiff = INT_MAX;
316+
int defaultListIndex = -1;
315317
for (const auto n : CropSizeList)
316318
{
317319
std::string str(std::to_string(n));
318-
SendMessageA(hcrop, CB_ADDSTRING, 0, (LPARAM)str.c_str());
320+
const int index = SendMessageA(hcrop, CB_ADDSTRING, 0, (LPARAM)str.c_str());
321+
322+
const int diff = abs(DefaultCommonDivisor - n);
323+
if (DefaultCommonDivisorRange.first <= n && n <= DefaultCommonDivisorRange.second && diff < mindiff)
324+
{
325+
mindiff = diff;
326+
defaultListIndex = index;
327+
}
319328
}
320329

330+
if (defaultIndex == -1)
331+
defaultIndex = defaultListIndex;
332+
321333
if (GetWindowTextLength(hcrop) == 0)
322334
SendMessage(hcrop, CB_SETCURSEL, defaultIndex, 0);
323335
}

0 commit comments

Comments
 (0)