diff --git a/include/utility/image.h b/include/utility/image.h index 930a4e0..19ba1d8 100644 --- a/include/utility/image.h +++ b/include/utility/image.h @@ -125,17 +125,18 @@ 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); +HRESULT SKIV_Image_TonemapToSDR (const DirectX::Image& image, DirectX::ScratchImage& final_sdr, float mastering_max_nits); // Structs struct skiv_image_desktop_s { - CComPtr _srv = nullptr; - CComPtr _res = nullptr; - bool _hdr_image = false; - ImVec2 _resolution = ImVec2 (0.0f, 0.0f); - ImVec2 _desktop_pos = ImVec2 (0.0f, 0.0f); - DXGI_MODE_ROTATION _rotation = DXGI_MODE_ROTATION_UNSPECIFIED; + CComPtr _srv = nullptr; + CComPtr _res = nullptr; + bool _hdr_image = false; + ImVec2 _resolution = ImVec2 (0.0f, 0.0f); + ImVec2 _desktop_pos = ImVec2 (0.0f, 0.0f); + DXGI_MODE_ROTATION _rotation = DXGI_MODE_ROTATION_UNSPECIFIED; + float _max_display_nits = 1000.0f; bool process (void) { @@ -180,11 +181,12 @@ struct skiv_image_desktop_s { void clear (void) { - _res = nullptr; - _srv = nullptr; - _hdr_image = false; - _resolution = ImVec2 (0.0f, 0.0f); - _desktop_pos = ImVec2 (0.0f, 0.0f); - _rotation = DXGI_MODE_ROTATION_UNSPECIFIED; + _res = nullptr; + _srv = nullptr; + _hdr_image = false; + _resolution = ImVec2 (0.0f, 0.0f); + _desktop_pos = ImVec2 (0.0f, 0.0f); + _max_display_nits = 1000.0f; + _rotation = DXGI_MODE_ROTATION_UNSPECIFIED; } }; \ No newline at end of file diff --git a/src/SKIV.cpp b/src/SKIV.cpp index ce237da..371390f 100644 --- a/src/SKIV.cpp +++ b/src/SKIV.cpp @@ -2015,9 +2015,6 @@ wWinMain ( _In_ HINSTANCE hInstance, auto _IgnoreWindow = [&](HWND hWnd) -> bool { - if (hWnd == SKIF_ImGui_hWnd) - return true; - if (ignoredWindows.count (hWnd)) return true; @@ -2038,8 +2035,8 @@ wWinMain ( _In_ HINSTANCE hInstance, || ! IsWindowVisible (hWnd) || (RealGetWindowClassW (hWnd, wszWindowTextBuffer, 64) && ignoreClassNames.count (wszWindowTextBuffer)) || ! GetWindowTextW (hWnd, wszWindowTextBuffer, 64) - //|| (GetWindowLongPtr (hWnd, GWL_EXSTYLE) & WS_EX_TOOLWINDOW) - //|| (GetWindowLongPtr (hWnd, GWL_STYLE) & WS_POPUP) // Ignores some games, but allows some invisible stupid windows (UWP) + || (GetWindowLongPtr (hWnd, GWL_EXSTYLE) & WS_EX_TOOLWINDOW) + //|| (GetWindowLongPtr (hWnd, GWL_STYLE) & WS_POPUP) // Ignores some games, but allows some invisible stupid windows (UWP) ) { ignoredWindows.insert (hWnd); diff --git a/src/utility/image.cpp b/src/utility/image.cpp index afe78b6..6b3c3ab 100644 --- a/src/utility/image.cpp +++ b/src/utility/image.cpp @@ -8,12 +8,15 @@ #include #include #include +#include #include #include #include #include #include +skiv_image_desktop_s SKIV_DesktopImage; + extern std::wstring defaultHDRFileExt; extern std::wstring defaultSDRFileExt; extern CComPtr SKIF_D3D11_GetDevice (bool bWait = true); @@ -988,7 +991,7 @@ bool SKIV_Image_CopyToClipboard (const DirectX::Image* pImage, bool snipped, boo DirectX::ScratchImage tonemapped_sdr; if (_registry._SnippingTonemapsHDR && isHDR) { - if (SUCCEEDED (SKIV_Image_TonemapToSDR (*pImage, tonemapped_sdr))) + if (SUCCEEDED (SKIV_Image_TonemapToSDR (*pImage, tonemapped_sdr, SKIV_DesktopImage._max_display_nits))) { pImage = tonemapped_sdr.GetImage (0,0,0); } @@ -1097,7 +1100,7 @@ bool SKIV_Image_CopyToClipboard (const DirectX::Image* pImage, bool snipped, boo } HRESULT -SKIV_Image_TonemapToSDR (const DirectX::Image& image, DirectX::ScratchImage& final_sdr) +SKIV_Image_TonemapToSDR (const DirectX::Image& image, DirectX::ScratchImage& final_sdr, float mastering_max_nits) { using namespace DirectX; @@ -1168,7 +1171,8 @@ SKIV_Image_TonemapToSDR (const DirectX::Image& image, DirectX::ScratchImage& fin XMVECTOR maxTonemappedRGB = g_XMZero; // If it's too bright, don't bother trying to tonemap the full range... - static constexpr float _maxNitsToTonemap = 10000.0f/80.0f; + const float _maxNitsToTonemap = (mastering_max_nits != 0.0f ? mastering_max_nits + : 1000.0f) / 80.0f; const float maxYInPQ = SKIV_Image_LinearToPQY (std::min (_maxNitsToTonemap, XMVectorGetY (maxLum))), @@ -1184,7 +1188,7 @@ SKIV_Image_TonemapToSDR (const DirectX::Image& image, DirectX::ScratchImage& fin auto TonemapHDR = [](float L, float Lc, float Ld) -> float { - float a = ( Ld / pow (Lc, 2.0f)); + float a = ( Ld / pow (Lc, 2.15f)); float b = (1.0f / Ld); return @@ -1392,7 +1396,7 @@ SKIV_Image_SaveToDisk_SDR (const DirectX::Image& image, const wchar_t* wszFileNa auto TonemapHDR = [](float L, float Lc, float Ld) -> float { - float a = ( Ld / pow (Lc, 2.0f)); + float a = ( Ld / pow (Lc, 2.15f)); float b = (1.0f / Ld); return @@ -1641,8 +1645,6 @@ SKIV_Image_SaveToDisk_HDR (const DirectX::Image& image, const wchar_t* wszFileNa wszImplicitFileName, nullptr, SK_WIC_SetMaximumQuality); } -skiv_image_desktop_s SKIV_DesktopImage; - HRESULT SKIV_Image_CaptureDesktop (DirectX::ScratchImage& image, POINT point, int flags) { @@ -1670,6 +1672,7 @@ SKIV_Image_CaptureDesktop (DirectX::ScratchImage& image, POINT point, int flags) CComPtr pCursorOutput; DXGI_OUTPUT_DESC out_desc = {}; + DXGI_OUTPUT_DESC1 out_desc1= {}; while (SUCCEEDED (pFactory->EnumAdapters (uiAdapter++, &pAdapter.p))) { @@ -1680,6 +1683,13 @@ SKIV_Image_CaptureDesktop (DirectX::ScratchImage& image, POINT point, int flags) { pOutput->GetDesc (&out_desc); + CComQIPtr + pOutput6 (pOutput); + if (pOutput6.p != nullptr) + { + pOutput6->GetDesc1 (&out_desc1); + } + if (out_desc.AttachedToDesktop && PtInRect (&out_desc.DesktopCoordinates, point)) { pCursorOutput = pOutput; @@ -1860,6 +1870,7 @@ SKIV_Image_CaptureDesktop (DirectX::ScratchImage& image, POINT point, int flags) SKIV_DesktopImage._desktop_pos = ImVec2 (static_cast (out_desc.DesktopCoordinates.left), static_cast (out_desc.DesktopCoordinates.top)); + SKIV_DesktopImage._max_display_nits = out_desc1.MaxLuminance; pDevCtx->Flush ();