Skip to content

Commit

Permalink
Add snipping toolbar when HDR is active to pick between preserving HD…
Browse files Browse the repository at this point in the history
…R or tonemapping to SDR.
  • Loading branch information
Kaldaien committed Jul 20, 2024
1 parent fbe42af commit f391068
Show file tree
Hide file tree
Showing 7 changed files with 313 additions and 55 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,4 @@
/resources/icons/SKIV2.ico
/resources/icons/SKIV3.ico
/resources/icons/SKIV4a.ico
/post_build.bat
1 change: 1 addition & 0 deletions SKIV.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -519,6 +519,7 @@
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
<None Include="post_build.bat" />
<None Include="resources\shaders\calibration.hlsli" />
<None Include="resources\shaders\colorspaces.hlsli" />
<None Include="resources\shaders\tone_mapping.hlsli" />
Expand Down
1 change: 1 addition & 0 deletions include/utility/image.h
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ HRESULT SKIV_Image_SaveToDisk_HDR (const DirectX::Image& image, const wchar_t*
HRESULT SKIV_Image_SaveToDisk_SDR (const DirectX::Image& image, const wchar_t* wszFileName, bool force_sRGB);
HRESULT SKIV_Image_CaptureDesktop (DirectX::ScratchImage& image, POINT pos, int flags = 0x0);
void SKIV_Image_CaptureRegion (ImRect capture_area);
HRESULT SKIV_Image_TonemapToSDR (const DirectX::Image& image, DirectX::ScratchImage& final_sdr);

// Structs

Expand Down
1 change: 1 addition & 0 deletions include/utility/registry.h
Original file line number Diff line number Diff line change
Expand Up @@ -435,6 +435,7 @@ struct SKIF_RegistrySettings {
bool _SnippingMode = false;
bool _SnippingModeExit = false;
bool _SnippingModeTempHDR = false;
int _SnippingTonemapsHDR = 0;

// Keybindings

Expand Down
18 changes: 0 additions & 18 deletions post_build.bat

This file was deleted.

133 changes: 99 additions & 34 deletions src/SKIV.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1869,6 +1869,8 @@ wWinMain ( _In_ HINSTANCE hInstance,



bool bHoveringSnipToolbar = false;

ImGui::BeginGroup ();

static bool last_snip_state = false;
Expand Down Expand Up @@ -1934,11 +1936,10 @@ wWinMain ( _In_ HINSTANCE hInstance,

if (SKIV_DesktopImage._srv != nullptr)
{

static const ImVec2 srgb_uv0 = ImVec2 (0, 0),
srgb_uv1 = ImVec2 (1, 1),
hdr_uv0 = ImVec2 (-1024.0f, -1024.0f), // HDR formats
hdr_uv1 = ImVec2 (-2048.0f, -2048.0f); // HDR formats
static const ImVec2 srgb_uv0 = ImVec2 (0, 0),
srgb_uv1 = ImVec2 (1, 1),
hdr_uv0 = ImVec2 (-1024.0f, -1024.0f), // HDR formats
hdr_uv1 = ImVec2 (-2048.0f, -2048.0f); // HDR formats

SKIF_ImGui_OptImage (SKIV_DesktopImage._srv, SKIV_DesktopImage._resolution,
(HDR_Image && SKIV_HDR) ? hdr_uv0 : srgb_uv0,
Expand Down Expand Up @@ -1974,7 +1975,7 @@ wWinMain ( _In_ HINSTANCE hInstance,
L"Progman", // Program Manager
L"Button", // Start button?
//L"ApplicationFrameWindow", // UWP stuff (ignores HDR + WCG Image Viewer)
L"Windows.UI.Core.CoreWindow" // UWP stuff
//L"Windows.UI.Core.CoreWindow" // UWP stuff
};

wchar_t wszWindowTextBuffer [64] = { };
Expand Down Expand Up @@ -2094,49 +2095,113 @@ wWinMain ( _In_ HINSTANCE hInstance,

static bool clicked = false;

if (! clicked && SKIF_ImGui_SelectionRect (&selection, allowable, 0, SelectionFlag_Filled))
{
_registry._SnippingModeExit = true;
capture_area = selection;
}

else if (! ImGui::IsMouseDragging (ImGuiMouseButton_Left))
if (HDR_Image && SKIV_HDR)
{
_GetRectBelowCursor ( );
static ImVec2 vSnippingToolbarSize = ImVec2 (128.0f, 32.0f);

ImGui::SetNextWindowPos (ImVec2 (ImGui::GetCurrentWindow ()->Size.x / 2.0f -
vSnippingToolbarSize.x / 2.0f,
ImGui::GetStyle ().ItemSpacing.y +
vSnippingToolbarSize.y / 2.0f));

ImGui::PushStyleColor (ImGuiCol_ChildBg, ImGui::GetStyleColorVec4 (ImGuiCol_WindowBg));
ImGui::BeginChild ("Snipping Tool###SnippingToolbar", ImVec2 (0.0f, 0.0f),
ImGuiChildFlags_AlwaysUseWindowPadding | ImGuiChildFlags_AutoResizeX |
ImGuiChildFlags_AutoResizeY | ((_registry.bUIBorders) ? ImGuiChildFlags_Border
: ImGuiChildFlags_None
| ImGuiChildFlags_FrameStyle),
ImGuiWindowFlags_NoScrollbar |
ImGuiWindowFlags_NoDecoration |
ImGuiWindowFlags_AlwaysAutoResize);

ImGui::BringWindowToDisplayFront (ImGui::GetCurrentWindow ());

ImGui::PopStyleColor ();
ImGui::BeginGroup ();
ImGui::PushStyleColor (ImGuiCol_Text, ImColor (1.0f, 1.0f, 1.0f, 1.0f).Value);
ImGui::TextUnformatted (ICON_FA_SCISSORS " Snipping Tool");
ImGui::Separator ();
ImGui::PopStyleColor ();
ImGui::TreePush ("");
ImGui::RadioButton ("Capture HDR PNG", &_registry._SnippingTonemapsHDR, 0);
if (ImGui::IsItemHovered ())
{
ImGui::BeginTooltip ();
ImGui::TextUnformatted ("HDR PNG may have Compatibility Issues");
ImGui::Separator ();
ImGui::BulletText ("Generally the clipboard contents can only be pasted into browser-derived software (i.e. built using Chromium, Electron) and SKIV.");
ImGui::BulletText ("Some browsers cannot interpret HDR10 PNG correctly and the image will not render in HDR when pasted.");
ImGui::EndTooltip ();
}
ImGui::SameLine ();
ImGui::RadioButton ("Tonemap HDR to SDR", &_registry._SnippingTonemapsHDR, 1);
if (ImGui::IsItemHovered ())
{
ImGui::BeginTooltip ();
ImGui::TextUnformatted ("High Quality HDR to SDR Tonemap");
ImGui::Separator ();
ImGui::BulletText ("Stored in the clipboard as a Bitmap for maximum compatibility with SDR software.");
ImGui::EndTooltip ();
}
ImGui::TreePop ();
ImGui::EndGroup ();
if ( ImGui::IsWindowHovered () ||
ImGui::IsItemActive () )
{
bHoveringSnipToolbar = true;
}

// Keep the selection within the allowed rectangle
selection_auto.ClipWithFull (allowable);
vSnippingToolbarSize = ImGui::GetWindowSize ();
ImGui::EndChild ();

if (ImGui::IsMouseClicked (ImGuiMouseButton_Left))
clicked = true;
}

else if (ImGui::IsMouseReleased (ImGuiMouseButton_Left))
if (! bHoveringSnipToolbar)
{
if (! clicked && SKIF_ImGui_SelectionRect (&selection, allowable, 0, SelectionFlag_Filled))
{
clicked = false;
_registry._SnippingModeExit = true;
capture_area = selection_auto;
capture_area = selection;
}

else if (selection_auto.Min != selection_auto.Max)
else if (! ImGui::IsMouseDragging (ImGuiMouseButton_Left))
{
ImDrawList* draw_list =
ImGui::GetForegroundDrawList ();
_GetRectBelowCursor ( );

draw_list->AddRect (selection_auto.Min, selection_auto.Max, ImGui::GetColorU32 (IM_COL32(0,130,216,255)), 0.0f, 0, 5.0f); // Border
//draw_list->AddRectFilled (selection_auto.Min, selection_auto.Max, ImGui::GetColorU32 (IM_COL32(0,130,216,50))); // Background
// Keep the selection within the allowed rectangle
selection_auto.ClipWithFull (allowable);

if (ImGui::IsMouseClicked (ImGuiMouseButton_Left))
clicked = true;

else if (ImGui::IsMouseReleased (ImGuiMouseButton_Left))
{
clicked = false;
_registry._SnippingModeExit = true;
capture_area = selection_auto;
}

else if (selection_auto.Min != selection_auto.Max)
{
ImDrawList* draw_list =
ImGui::GetForegroundDrawList ();

draw_list->AddRect (selection_auto.Min, selection_auto.Max, ImGui::GetColorU32 (IM_COL32(0,130,216,255)), 0.0f, 0, 5.0f); // Border
//draw_list->AddRectFilled (selection_auto.Min, selection_auto.Max, ImGui::GetColorU32 (IM_COL32(0,130,216,50))); // Background
}
}
}

else
clicked = false;
else
clicked = false;

if (capture_area.GetArea() != 0)
{
ignoredWindows.clear();
if (capture_area.GetArea() != 0)
{
ignoredWindows.clear();

PLOG_VERBOSE << "Attempting to capture region...";
PLOG_VERBOSE << "Attempting to capture region...";

SKIV_Image_CaptureRegion (capture_area);
SKIV_Image_CaptureRegion (capture_area);
}
}
#pragma endregion
}
Expand Down
Loading

0 comments on commit f391068

Please sign in to comment.