Skip to content

Commit

Permalink
Improved logic related to clipboard capture
Browse files Browse the repository at this point in the history
  • Loading branch information
Aemony committed Jun 26, 2024
1 parent fb59ec1 commit a99296d
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 36 deletions.
32 changes: 26 additions & 6 deletions src/SKIV.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -851,7 +851,7 @@ void SKIF_Initialize (LPWSTR lpCmdLine)
<< "\n| > user data | " << _path_cache.skiv_userdata
<< "\n+------------------+-------------------------------------+";

// SKIV also uses a folder to temporary internet files
// SKIV also uses a folder to temporary files
const std::wstring tempDir =
std::wstring (_path_cache.app_data_local.path) + LR"(\Temp\skiv\)";

Expand Down Expand Up @@ -908,6 +908,12 @@ void SKIF_Initialize (LPWSTR lpCmdLine)
FindClose (hFind);
}
}

// Create the folder for temporary files
else {
std::error_code ec;
std::filesystem::create_directories (_path_cache.skiv_temp, ec);
}
}

bool bKeepWindowAlive = true,
Expand Down Expand Up @@ -1795,10 +1801,24 @@ wWinMain ( _In_ HINSTANCE hInstance,
}
}

//SKIF_ImGui_OptImage (SKIV_DesktopImage, vDesktopSize, ImVec2 (-1024.0f, -1024.0f),
// ImVec2 (-2048.0f, -2048.0f));
SKIF_ImGui_OptImage (SKIV_DesktopImage, vDesktopSize, ImVec2 (-1024.0f, -1024.0f),
ImVec2 (-2048.0f, -2048.0f));

extern uint32_t SKIV_HDR_VisualizationId;
extern float SKIV_HDR_SDRWhite;
extern float SKIV_HDR_MaxCLL;
extern float SKIV_HDR_MaxLuminance;
extern float SKIV_HDR_DisplayMaxLuminance;
extern float SKIV_HDR_BrightnessScale;

//SKIV_HDR_VisualizationId = SKIV_HDR_VISUALIZTION_GAMUT;
//SKIV_HDR_SDRWhite = 0.0f;
//SKIV_HDR_MaxCLL = 0.0f;
//SKIV_HDR_MaxLuminance = 0.0f;
//SKIV_HDR_DisplayMaxLuminance = 0.0f;
//SKIV_HDR_BrightnessScale = 0.1f;

SKIF_ImGui_OptImage (SKIV_DesktopImage, vDesktopSize);
//SKIF_ImGui_OptImage (SKIV_DesktopImage, vDesktopSize);

//ImDrawList* draw_list =
// ImGui::GetForegroundDrawList ();
Expand Down Expand Up @@ -2064,8 +2084,8 @@ wWinMain ( _In_ HINSTANCE hInstance,
PLOG_VERBOSE << "DirectX::CopyRectangle ( ): SUCCEEDED";

extern bool
SKIV_Image_CopyToClipboard (const DirectX::Image* pImage, bool snipped);
if (SKIV_Image_CopyToClipboard (subrect.GetImages (), true))
SKIV_Image_CopyToClipboard (const DirectX::Image* pImage, bool snipped, bool isHDR);
if (SKIV_Image_CopyToClipboard (subrect.GetImages (), true, (_registry.iHDRMode > 0 && SKIF_Util_IsHDRActive ( ))))
PLOG_VERBOSE << "SKIV_Image_CopyToClipboard ( ): SUCCEEDED";
else
PLOG_WARNING << "SKIV_Image_CopyToClipboard ( ): FAILED";
Expand Down
69 changes: 39 additions & 30 deletions src/tabs/viewer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -572,7 +572,12 @@ static int getTextureLoadQueuePos (void) {
}

// External declaration
extern void SKIF_Shell_AddJumpList (std::wstring name, std::wstring path, std::wstring parameters, std::wstring directory, std::wstring icon_path, bool bService);
extern void SKIF_Shell_AddJumpList (std::wstring name, std::wstring path, std::wstring parameters, std::wstring directory, std::wstring icon_path, bool bService);

// Forward declarations
bool SKIV_Image_CopyToClipboard (const DirectX::Image* pImage, bool snipped, bool isHDR);
HRESULT SKIF_Image_SaveToDisk_HDR (const DirectX::Image& image, const wchar_t* wszFileName);
HRESULT SKIF_Image_SaveToDisk_SDR (const DirectX::Image& image, const wchar_t* wszFileName);

// Functions / Structs

Expand Down Expand Up @@ -1474,9 +1479,7 @@ SKIF_UI_Tab_DrawViewer (void)
SUCCEEDED (DirectX::CopyRectangle (*captured_img.GetImages (), src_rect,
*subrect.GetImages (), DirectX::TEX_FILTER_DEFAULT, 0, 0)))
{
extern bool
SKIV_Image_CopyToClipboard (const DirectX::Image* pImage, bool snipped);
if (SKIV_Image_CopyToClipboard (subrect.GetImages (), true))
if (SKIV_Image_CopyToClipboard (subrect.GetImages (), true, cover.is_hdr))
{
ImGui::InsertNotification (
{
Expand All @@ -1492,6 +1495,7 @@ SKIF_UI_Tab_DrawViewer (void)

copyRect = { 0,0,0,0 };
}

else {
ImGui::InsertNotification (
{
Expand All @@ -1510,9 +1514,7 @@ SKIF_UI_Tab_DrawViewer (void)

else
{
extern bool
SKIV_Image_CopyToClipboard (const DirectX::Image* pImage, bool snipped);
if (SKIV_Image_CopyToClipboard (captured_img.GetImages (), false))
if (SKIV_Image_CopyToClipboard (captured_img.GetImages (), false, cover.is_hdr))
{
ImGui::InsertNotification (
{
Expand All @@ -1522,6 +1524,7 @@ SKIF_UI_Tab_DrawViewer (void)
}
);
}

else {
ImGui::InsertNotification (
{
Expand Down Expand Up @@ -3113,9 +3116,6 @@ SKIF_UI_Tab_DrawViewer (void)
DirectX::ScratchImage captured_img;
if (SUCCEEDED (DirectX::CaptureTexture (pDevice, pDevCtx, pCoverRes, captured_img)))
{
HRESULT SKIF_Image_SaveToDisk_HDR (const DirectX::Image& image, const wchar_t* wszFileName);
HRESULT SKIF_Image_SaveToDisk_SDR (const DirectX::Image& image, const wchar_t* wszFileName);

if (cover.is_hdr)
{
hr =
Expand Down Expand Up @@ -3254,8 +3254,6 @@ SKIF_UI_Tab_DrawViewer (void)
DirectX::ScratchImage captured_img;
if (SUCCEEDED (DirectX::CaptureTexture (pDevice, pDevCtx, pCoverRes, captured_img)))
{
HRESULT SKIF_Image_SaveToDisk_HDR (const DirectX::Image& image, const wchar_t* wszFileName);
HRESULT SKIF_Image_SaveToDisk_SDR (const DirectX::Image& image, const wchar_t* wszFileName);

if (cover.is_hdr)
{
Expand Down Expand Up @@ -4289,7 +4287,7 @@ SK_WIC_SetMaximumQuality (IPropertyBag2 *props)
bool
SKIV_HDR_SavePNGToDisk (const wchar_t* wszPNGPath, const DirectX::Image* png_image,
const DirectX::Image* raw_image,
const char* szUtf8MetadataTitle)
const char* szUtf8MetadataTitle, bool isHDR)
{
if ( wszPNGPath == nullptr ||
png_image == nullptr ||
Expand Down Expand Up @@ -4318,9 +4316,8 @@ SKIV_HDR_SavePNGToDisk (const wchar_t* wszPNGPath, const DirectX::Image* png_ima
{
PLOG_VERBOSE << "DirectX::SaveToWICFile ( ): SUCCEEDED";

return (png_image->format == DXGI_FORMAT_R16G16B16A16_UNORM)
? SKIV_PNG_MakeHDR (wszPNGPath, *png_image, *raw_image)
: true;
return (isHDR) ? SKIV_PNG_MakeHDR (wszPNGPath, *png_image, *raw_image)
: true;
} else
PLOG_VERBOSE << "DirectX::SaveToWICFile ( ): FAILED";

Expand Down Expand Up @@ -4375,28 +4372,40 @@ void SKIV_HandleCopyShortcut (void)

CComPtr <ID3D11ShaderResourceView> SKIV_DesktopImage;

bool SKIV_Image_CopyToClipboard (const DirectX::Image* pImage, bool snipped)
bool SKIV_Image_CopyToClipboard (const DirectX::Image* pImage, bool snipped, bool isHDR)
{
if (pImage == nullptr)
return false;

DirectX::ScratchImage hdr10_img;
if (SKIV_HDR_ConvertImageToPNG (*pImage, hdr10_img))
{
PLOG_VERBOSE << "SKIV_HDR_ConvertImageToPNG ( ): TRUE";
static SKIF_CommonPathsCache& _path_cache = SKIF_CommonPathsCache::GetInstance ( );

std::wstring wsPNGPath = _path_cache.skiv_temp;
wsPNGPath += snipped ? L"SKIV_Snip"
: L"SKIV_Clipboard";
wsPNGPath += L".png";

PLOG_VERBOSE << wsPNGPath;

wchar_t wszPNGPath [MAX_PATH + 2] = { };
GetCurrentDirectoryW (MAX_PATH, wszPNGPath);
if (isHDR)
{
if (SUCCEEDED (SKIF_Image_SaveToDisk_HDR (*pImage, wsPNGPath.c_str())))
{
PLOG_VERBOSE << "SKIF_Image_SaveToDisk_HDR ( ): SUCCEEDED";

PathAppendW (wszPNGPath, snipped ? L"SKIV_HDR_Snip"
: L"SKIV_HDR_Clipboard");
PathAddExtensionW (wszPNGPath, L".png");
if (SKIV_PNG_CopyToClipboard (*pImage, wsPNGPath.c_str(), 0))
{
PLOG_VERBOSE << "SKIV_PNG_CopyToClipboard ( ): TRUE";
return true;
}
}
}

if (SKIV_HDR_SavePNGToDisk (wszPNGPath, hdr10_img.GetImages (), pImage, nullptr))
else {
if (SUCCEEDED (SKIF_Image_SaveToDisk_SDR (*pImage, wsPNGPath.c_str())))
{
PLOG_VERBOSE << "SKIV_HDR_SavePNGToDisk ( ): TRUE";
PLOG_VERBOSE << "SKIF_Image_SaveToDisk_SDR ( ): SUCCEEDED";

if (SKIV_PNG_CopyToClipboard (*hdr10_img.GetImage (0,0,0), wszPNGPath, 0))
if (SKIV_PNG_CopyToClipboard (*pImage, wsPNGPath.c_str(), 0))
{
PLOG_VERBOSE << "SKIV_PNG_CopyToClipboard ( ): TRUE";
return true;
Expand Down Expand Up @@ -4917,7 +4926,7 @@ SKIF_Image_SaveToDisk_HDR (const DirectX::Image& image, const wchar_t* wszFileNa
DirectX::ScratchImage png_img;
if (SKIV_HDR_ConvertImageToPNG (image, png_img))
{
if (SKIV_HDR_SavePNGToDisk (wszImplicitFileName, png_img.GetImages (), &image, nullptr))
if (SKIV_HDR_SavePNGToDisk (wszImplicitFileName, png_img.GetImages (), &image, nullptr, true))
{
return S_OK;
}
Expand Down

0 comments on commit a99296d

Please sign in to comment.