Skip to content

Commit fc9e2d2

Browse files
committed
implement info
- Start collecting various info across the entire application. - Changes to overlay.
1 parent 4b5cac1 commit fc9e2d2

9 files changed

+123
-50
lines changed

w-image-viewer/config.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,7 @@ void Config::read_top_level(const std::string& key, const std::string& val)
147147
read(raw_thumb)
148148
read(overlay_show)
149149
read(overlay_position)
150+
read(overlay_config)
150151
}
151152

152153
void Config::read_scale(const std::string& key, const std::string& val, Config_scale& scale)
@@ -221,6 +222,7 @@ void Config::write_top_level(std::ofstream& file)
221222
write(raw_thumb)
222223
write(overlay_show)
223224
write(overlay_position)
225+
write(overlay_config)
224226
}
225227

226228
void Config::write_scale(std::ofstream& file, const Config_scale& scale)

w-image-viewer/config.h

+1
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ class Config
6868
std::vector<Scale_profile> scale_profiles;
6969
Config_pair<bool, "ovrl"> overlay_show;
7070
Config_pair<int, "ovrl_pos"> overlay_position;
71+
Config_pair<uint64_t, "ovrl_cfg"> overlay_config;
7172
private:
7273
void read_top_level(const std::string& key, const std::string& val);
7374
void read_scale(const std::string& key, const std::string& val, Config_scale& scale);

w-image-viewer/global.h

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
#pragma once
22

33
#include "config.h"
4+
#include "info.h"
45

5-
inline Config g_config;
6+
inline Config g_config;
7+
inline Info g_info;

w-image-viewer/info.h

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#pragma once
2+
3+
// Use for collecting various info across the entire application.
4+
struct Info
5+
{
6+
int image_width; // The original image width.
7+
int image_height; // The original image height.
8+
float scale; // Current image scale.
9+
int scaled_width; // Scaled image width.
10+
int scaled_height; // Scaled image height.
11+
int kernel_index; // Currently used scale kernel.
12+
13+
// Currently used scale kernel size.
14+
// In case of orthogonal scaling: (ceil(kernel_radius / scale) * 2) * 2.
15+
// In case of cylindrical scaling: (ceil(kernel_radius / scale) * 2) ^ 2.
16+
int kernel_size;
17+
};

w-image-viewer/renderer.cpp

+22-2
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ void Renderer::update()
100100
user_interface.is_zooming = false;
101101
user_interface.is_rotating = false;
102102
}
103-
user_interface.update(scale);
103+
user_interface.update();
104104
}
105105

106106
void Renderer::draw() const
@@ -121,6 +121,10 @@ void Renderer::create_image()
121121
std::unique_ptr<uint8_t[]> data;
122122
image.get_data_for_d3d(data, format, sys_mem_pitch);
123123

124+
// Info.
125+
g_info.image_width = image.get_width<int>();
126+
g_info.image_height = image.get_height<int>();
127+
124128
// Create texture.
125129
const D3D11_TEXTURE2D_DESC texture2d_desc{
126130

@@ -816,19 +820,35 @@ void Renderer::update_scale_and_dims_output() noexcept
816820
scale = std::pow(2.0f, auto_zoom + user_interface.image_zoom);
817821
dims_output.width = static_cast<int>(std::ceil(image_w * scale));
818822
dims_output.height = static_cast<int>(std::ceil(image_h * scale));
823+
824+
// Info.
825+
g_info.scale = scale;
826+
g_info.scaled_width = dims_output.width;
827+
g_info.scaled_height = dims_output.height;
819828
}
820829

821830
void Renderer::update_scale_profile() noexcept
822831
{
823832
for (const auto& profile : g_config.scale_profiles) {
824833
if (profile.range.is_inrange(scale)) {
825834
p_scale_profile = &profile.config;
826-
return;
835+
goto info;
827836
}
828837
}
829838

830839
// Else use default profile.
831840
p_scale_profile = &g_config.scale_profiles[0].config;
841+
842+
// Info.
843+
info:
844+
g_info.kernel_index = p_scale_profile->kernel_index.val;
845+
if (p_scale_profile->kernel_cylindrical_use.val) {
846+
const auto a{ static_cast<int>(std::ceil(get_kernel_radius() / scale)) };
847+
g_info.kernel_size = a * a;
848+
}
849+
else
850+
g_info.kernel_size = static_cast<int>(std::ceil(get_kernel_radius() / scale)) * 2;
851+
832852
}
833853

834854
float Renderer::get_kernel_radius() const noexcept

w-image-viewer/user_interface.cpp

+72-45
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,36 @@
99
#include "window.h"
1010
#include "message.h"
1111

12+
enum WIV_OVERLAY_SHOW_ : uint64_t
13+
{
14+
WIV_OVERLAY_SHOW_IMAGE_DIMS = 1 << 0,
15+
WIV_OVERLAY_SHOW_SCALE = 1 << 1,
16+
WIV_OVERLAY_SHOW_SCALED_DIMS = 1 << 2,
17+
WIV_OVERLAY_SHOW_KERNEL_INDEX = 1 << 3,
18+
WIV_OVERLAY_SHOW_KERNEL_SIZE = 1 << 4
19+
};
20+
21+
namespace
22+
{
23+
// The order has to be same as in the enum WIV_KERNEL_FUNCTION_.
24+
constexpr std::array kernel_function_names{
25+
"Lanczos",
26+
"Ginseng",
27+
"Hamming",
28+
"Power of cosine",
29+
"Kaiser",
30+
"Power of Garamond",
31+
"Power of Blackman",
32+
"GNW",
33+
"Said",
34+
"Nearest neighbor",
35+
"Linear",
36+
"Bicubic",
37+
"Modified FSR",
38+
"BC-Spline"
39+
};
40+
}
41+
1242
void User_interface::create(HWND hwnd, ID3D11Device* device, ID3D11DeviceContext* device_context, bool* should_update)
1343
{
1444
this->hwnd = hwnd;
@@ -40,15 +70,15 @@ void User_interface::create(HWND hwnd, ID3D11Device* device, ID3D11DeviceContext
4070
ImGui_ImplDX11_Init(device, device_context);
4171
}
4272

43-
void User_interface::update(float scale)
73+
void User_interface::update()
4474
{
4575
// Feed inputs to dear imgui, start new frame.
4676
ImGui_ImplDX11_NewFrame();
4777
ImGui_ImplWin32_NewFrame();
4878
ImGui::NewFrame();
4979

5080
input();
51-
overlay(scale);
81+
overlay();
5282
context_menu();
5383
window_settings();
5484
window_about();
@@ -264,7 +294,7 @@ void User_interface::input()
264294
//
265295
}
266296

267-
void User_interface::overlay(float scale)
297+
void User_interface::overlay()
268298
{
269299
if (is_overlay_open) {
270300

@@ -280,27 +310,21 @@ void User_interface::overlay(float scale)
280310
ImGui::SetNextWindowPos(window_pos, ImGuiCond_Always, window_pos_pivot);
281311

282312
ImGui::SetNextWindowBgAlpha(0.35f);
283-
if (ImGui::Begin("##overlay", nullptr, ImGuiWindowFlags_NoDecoration | ImGuiWindowFlags_NoNav | ImGuiWindowFlags_NoMove)) {
284-
ImGui::Text("Scale: %.6f", scale);
285-
286-
// Context menu.
287-
if (ImGui::BeginPopupContextWindow()) {
288-
if (ImGui::MenuItem("Top-left", nullptr, g_config.overlay_position.val == 0))
289-
g_config.overlay_position.val = 0;
290-
if (ImGui::MenuItem("Top-right", nullptr, g_config.overlay_position.val == 1))
291-
g_config.overlay_position.val = 1;
292-
if (ImGui::MenuItem("Bottom-left", nullptr, g_config.overlay_position.val == 2))
293-
g_config.overlay_position.val = 2;
294-
if (ImGui::MenuItem("Bottom-right", nullptr, g_config.overlay_position.val == 3))
295-
g_config.overlay_position.val = 3;
296-
ImGui::Separator();
297-
if (ImGui::MenuItem("Save position"))
298-
g_config.write();
299-
ImGui::Separator();
300-
if (ImGui::MenuItem("Close"))
301-
is_overlay_open = false;
302-
ImGui::EndPopup();
313+
if (ImGui::Begin("##overlay", nullptr, ImGuiWindowFlags_NoDecoration | ImGuiWindowFlags_NoInputs | ImGuiWindowFlags_AlwaysAutoResize)) {
314+
if (g_config.overlay_config.val & WIV_OVERLAY_SHOW_IMAGE_DIMS) {
315+
ImGui::Text("Image W: %i", g_info.image_width);
316+
ImGui::Text("Image H: %i", g_info.image_height);
303317
}
318+
if (g_config.overlay_config.val & WIV_OVERLAY_SHOW_SCALE)
319+
ImGui::Text("Scale: %.6f", g_info.scale);
320+
if (g_config.overlay_config.val & WIV_OVERLAY_SHOW_SCALED_DIMS) {
321+
ImGui::Text("Scaled W: %i", g_info.scaled_width);
322+
ImGui::Text("Scaled H: %i", g_info.scaled_height);
323+
}
324+
if (g_config.overlay_config.val & WIV_OVERLAY_SHOW_KERNEL_INDEX)
325+
ImGui::Text(kernel_function_names[g_info.kernel_index]);
326+
if (g_config.overlay_config.val & WIV_OVERLAY_SHOW_KERNEL_SIZE)
327+
ImGui::Text("Kernel size: %i", g_info.kernel_size);
304328
}
305329

306330
ImGui::End();
@@ -418,8 +442,6 @@ void User_interface::window_settings()
418442
ImGui::Spacing();
419443
ImGui::ColorEdit4("Background color", g_config.clear_color.val.data(), ImGuiColorEditFlags_NoAlpha | ImGuiColorEditFlags_DisplayHSV);
420444
ImGui::Spacing();
421-
ImGui::Checkbox("Show overlay on start", &g_config.overlay_show.val);
422-
ImGui::Spacing();
423445
ImGui::Checkbox("Read only thumbnail in RAW images", &g_config.raw_thumb.val);
424446
ImGui::Spacing();
425447
}
@@ -500,26 +522,7 @@ void User_interface::window_settings()
500522
ImGui::SeparatorText("Scale");
501523
ImGui::Checkbox("Use cylindrical filtering (Jinc based)", &scale.kernel_cylindrical_use.val);
502524
ImGui::Spacing();
503-
504-
// The order has to be same as in the enum WIV_KERNEL_FUNCTION_.
505-
static constinit const std::array kernel_index_items{
506-
"Lanczos",
507-
"Ginseng",
508-
"Hamming",
509-
"Power of cosine",
510-
"Kaiser",
511-
"Power of Garamond",
512-
"Power of Blackman",
513-
"GNW",
514-
"Said",
515-
"Nearest neighbor",
516-
"Linear",
517-
"Bicubic",
518-
"Modified FSR",
519-
"BC-Spline"
520-
};
521-
522-
ImGui::Combo("Kernel-function", &scale.kernel_index.val, kernel_index_items.data(), kernel_index_items.size());
525+
ImGui::Combo("Kernel-function", &scale.kernel_index.val, kernel_function_names.data(), kernel_function_names.size());
523526
const auto& i{ scale.kernel_index.val };
524527
dimm(i == WIV_KERNEL_FUNCTION_NEAREST || i == WIV_KERNEL_FUNCTION_LINEAR || i == WIV_KERNEL_FUNCTION_BICUBIC || i == WIV_KERNEL_FUNCTION_FSR || i == WIV_KERNEL_FUNCTION_BCSPLINE);
525528
ImGui::InputFloat("Radius##kernel", &scale.kernel_radius.val, 0.0f, 0.0f, "%.6f");
@@ -640,6 +643,30 @@ void User_interface::window_settings()
640643
ImGui::ColorEdit3("Second tile color", g_config.alpha_tile2_color.val.data(), ImGuiColorEditFlags_DisplayHSV);
641644
ImGui::Spacing();
642645
}
646+
if (ImGui::CollapsingHeader("Overlay")) {
647+
ImGui::Checkbox("Show overlay on start", &g_config.overlay_show.val);
648+
ImGui::Spacing();
649+
static constinit const std::array overlay_position_items{
650+
"Top-left",
651+
"Top-right",
652+
"Bottom-left",
653+
"Bottom-right"
654+
};
655+
ImGui::Combo("Overlay position", &g_config.overlay_position.val, overlay_position_items.data(), overlay_position_items.size());
656+
ImGui::Spacing();
657+
ImGui::TextUnformatted("Show:");
658+
if (ImGui::Selectable("Image dimensions", g_config.overlay_config.val & WIV_OVERLAY_SHOW_IMAGE_DIMS))
659+
g_config.overlay_config.val ^= WIV_OVERLAY_SHOW_IMAGE_DIMS;
660+
if (ImGui::Selectable("Scale factor", g_config.overlay_config.val & WIV_OVERLAY_SHOW_SCALE))
661+
g_config.overlay_config.val ^= WIV_OVERLAY_SHOW_SCALE;
662+
if (ImGui::Selectable("Scaled dimensions", g_config.overlay_config.val & WIV_OVERLAY_SHOW_SCALED_DIMS))
663+
g_config.overlay_config.val ^= WIV_OVERLAY_SHOW_SCALED_DIMS;
664+
if (ImGui::Selectable("Kernel function", g_config.overlay_config.val & WIV_OVERLAY_SHOW_KERNEL_INDEX))
665+
g_config.overlay_config.val ^= WIV_OVERLAY_SHOW_KERNEL_INDEX;
666+
if (ImGui::Selectable("Scale kernel size", g_config.overlay_config.val & WIV_OVERLAY_SHOW_KERNEL_SIZE))
667+
g_config.overlay_config.val ^= WIV_OVERLAY_SHOW_KERNEL_SIZE;
668+
ImGui::Spacing();
669+
}
643670
ImGui::SeparatorText("Changes");
644671
if (ImGui::Button("Write changes")) {
645672
g_config.write();

w-image-viewer/user_interface.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ class User_interface
1414
{
1515
public:
1616
void create(HWND hwnd, ID3D11Device* device, ID3D11DeviceContext* device_context, bool* should_update);
17-
void update(float scale);
17+
void update();
1818
void draw() const;
1919
void auto_window_size() const;
2020
void reset_image_panzoom() noexcept;
@@ -34,7 +34,7 @@ class User_interface
3434

3535
private:
3636
void input();
37-
void overlay(float scale);
37+
void overlay();
3838
void context_menu();
3939
void window_settings();
4040
void window_about();

w-image-viewer/w-image-viewer.vcxproj

+1
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,7 @@
163163
<ClInclude Include="icc.h" />
164164
<ClInclude Include="image.h" />
165165
<ClInclude Include="cms_lut.h" />
166+
<ClInclude Include="info.h" />
166167
<ClInclude Include="range.h" />
167168
<ClInclude Include="supported_extensions.h" />
168169
<ClInclude Include="message.h" />

w-image-viewer/w-image-viewer.vcxproj.filters

+3
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,9 @@
8484
<ClInclude Include="message.h">
8585
<Filter>Header Files</Filter>
8686
</ClInclude>
87+
<ClInclude Include="info.h">
88+
<Filter>Header Files</Filter>
89+
</ClInclude>
8790
</ItemGroup>
8891
<ItemGroup>
8992
<ClCompile Include="main.cpp">

0 commit comments

Comments
 (0)