-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSettings.cpp
88 lines (73 loc) · 3.2 KB
/
Settings.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#include "CandidateFinder.h"
#include "Settings.h"
#include "imgui.h"
#include "ImFileDialog/ImFileDialog.h"
#include <algorithm>
Settings& Settings::getInstance() {
static Settings instance;
return instance;
}
CandidateFinder* Settings::showSettingsWindow(CandidateFinder* globalCandidateFinder, bool& newFileWasOpened) {
CandidateFinder* candidateFinder = globalCandidateFinder;
ImGui::Begin("Settings");
ImGui::Text("Width");
ImGui::InputInt("min##1", &globalSettings.widthMin);
ImGui::InputInt("max##1", &globalSettings.widthMax);
ImGui::Text("Limit height");
ImGui::SameLine();
ImGui::Checkbox("##limitHeight", &globalSettings.limitHeight);
if (globalSettings.limitHeight) {
ImGui::Text("Height");
ImGui::InputInt("min##2", &globalSettings.heightMin);
ImGui::InputInt("max##2", &globalSettings.heightMax);
}
ImGui::Text("Bitdepth");
static int current_bitdepthInt = 0;
const char* bitDepthItems[] = { "8 bit", "16 bit", "24 bit", "32 bit"};
ImGui::Combo("bitdepth", ¤t_bitdepthInt, bitDepthItems, IM_ARRAYSIZE(bitDepthItems));
globalSettings.bitDepth = static_cast<Bitdepth>(current_bitdepthInt);
ImGui::Text("Absolute correlation hysteresis");
bool hysteresisMinChanged = false, hysteresisMaxChanged = false;
hysteresisMinChanged = ImGui::SliderFloat("min##3", &globalSettings.hysteresisMin, 0.0f, 1.0f);
hysteresisMaxChanged = ImGui::SliderFloat("max##3", &globalSettings.hysteresisMax, 0.0f, 1.0f);
// a file can be opened to start analysis, an already running analysis
// will be cancelled
if (ImGui::Button("Open file..."))
ifd::FileDialog::Instance().Open("FileOpenDialog", "Open file", ",.*");
if (ifd::FileDialog::Instance().IsDone("FileOpenDialog")) {
if (ifd::FileDialog::Instance().HasResult()) {
auto selectedFile = ifd::FileDialog::Instance().GetResult();
uint64_t filesize = std::filesystem::file_size(selectedFile);
unsigned char* data = (unsigned char*)malloc(filesize);
if (data != nullptr) {
FILE* f = _wfopen(selectedFile.wstring().c_str(), L"rb");
unsigned char* dataptr = data;
size_t bytes_read;
do {
bytes_read = fread(dataptr, 1, 1024, f);
dataptr += bytes_read;
} while (bytes_read > 0);
fclose(f);
if (candidateFinder != nullptr) {
delete candidateFinder;
candidateFinder = nullptr;
}
candidateFinder = new CandidateFinder(globalSettings, data, filesize);
newFileWasOpened = true;
}
}
ifd::FileDialog::Instance().Close();
}
ImGui::End();
// depending on which of the min/max values was changed, we want to adjust the other if needed
// to satisfy the min <= max condition
if (hysteresisMinChanged) {
globalSettings.hysteresisMax = std::max(globalSettings.hysteresisMin, globalSettings.hysteresisMax);
globalSettings.hysteresisMin = std::min(globalSettings.hysteresisMin, globalSettings.hysteresisMax);
}
else if (hysteresisMaxChanged) {
globalSettings.hysteresisMin = std::min(globalSettings.hysteresisMin, globalSettings.hysteresisMax);
globalSettings.hysteresisMax = std::max(globalSettings.hysteresisMin, globalSettings.hysteresisMax);
}
return candidateFinder;
}