Skip to content

Commit

Permalink
Fix incorrect origin position used when calculating the usable snippi…
Browse files Browse the repository at this point in the history
…ng selection rectangle
  • Loading branch information
Kaldaien committed Jul 22, 2024
1 parent 91dea96 commit 5d79b33
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 19 deletions.
22 changes: 12 additions & 10 deletions include/utility/image.h
Original file line number Diff line number Diff line change
Expand Up @@ -130,11 +130,12 @@ HRESULT SKIV_Image_TonemapToSDR (const DirectX::Image& image, DirectX::Scratc
// Structs

struct skiv_image_desktop_s {
CComPtr <ID3D11ShaderResourceView> _srv = nullptr;
CComPtr <ID3D11Resource> _res = nullptr;
bool _hdr_image = false;
ImVec2 _resolution = ImVec2 (0.0f, 0.0f);
DXGI_MODE_ROTATION _rotation = DXGI_MODE_ROTATION_UNSPECIFIED;
CComPtr <ID3D11ShaderResourceView> _srv = nullptr;
CComPtr <ID3D11Resource> _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;

bool process (void)
{
Expand Down Expand Up @@ -179,10 +180,11 @@ struct skiv_image_desktop_s {

void clear (void)
{
_res = nullptr;
_srv = nullptr;
_hdr_image = false;
_resolution = 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);
_rotation = DXGI_MODE_ROTATION_UNSPECIFIED;
}
};
6 changes: 4 additions & 2 deletions src/SKIV.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1969,8 +1969,8 @@ wWinMain ( _In_ HINSTANCE hInstance,
std::swap (resolution.x, resolution.y);
}

// Desktop Pos, Desktop Pos + Desktop Size
ImRect allowable (monitor_extent.Min, monitor_extent.Min + resolution);
ImRect allowable (SKIV_DesktopImage._desktop_pos,
SKIV_DesktopImage._desktop_pos + resolution);
ImRect capture_area;

bool HDR_Image = SKIV_DesktopImage._hdr_image;
Expand Down Expand Up @@ -2056,6 +2056,8 @@ wWinMain ( _In_ HINSTANCE hInstance,
if (SKIV_DesktopImage._rotation == DXGI_MODE_ROTATION_ROTATE90 ||
SKIV_DesktopImage._rotation == DXGI_MODE_ROTATION_ROTATE270)
{
selection_auto.Min = ImVec2 (0.0f, 0.0f);
selection_auto.Max = ImVec2 (0.0f, 0.0f);
return;
}

Expand Down
23 changes: 16 additions & 7 deletions src/utility/image.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1646,7 +1646,7 @@ skiv_image_desktop_s SKIV_DesktopImage;
HRESULT
SKIV_Image_CaptureDesktop (DirectX::ScratchImage& image, POINT point, int flags)
{
SKIV_DesktopImage.clear();
SKIV_DesktopImage.clear ();

std::ignore = image;
std::ignore = flags;
Expand All @@ -1669,6 +1669,7 @@ SKIV_Image_CaptureDesktop (DirectX::ScratchImage& image, POINT point, int flags)
UINT uiAdapter = 0;

CComPtr <IDXGIOutput> pCursorOutput;
DXGI_OUTPUT_DESC out_desc = {};

while (SUCCEEDED (pFactory->EnumAdapters (uiAdapter++, &pAdapter.p)))
{
Expand All @@ -1677,7 +1678,6 @@ SKIV_Image_CaptureDesktop (DirectX::ScratchImage& image, POINT point, int flags)

while (SUCCEEDED (pAdapter->EnumOutputs (uiOutput++, &pOutput)))
{
DXGI_OUTPUT_DESC out_desc;
pOutput->GetDesc (&out_desc);

if (out_desc.AttachedToDesktop && PtInRect (&out_desc.DesktopCoordinates, point))
Expand Down Expand Up @@ -1856,7 +1856,10 @@ SKIV_Image_CaptureDesktop (DirectX::ScratchImage& image, POINT point, int flags)
pDevCtx->CopyResource (pDesktopImage, pDuplicatedTex);
pDevice->CreateShaderResourceView (pDesktopImage, &srvDesc, &SKIV_DesktopImage._srv);

SKIV_DesktopImage._rotation = dup_desc.Rotation;
SKIV_DesktopImage._rotation = dup_desc.Rotation;
SKIV_DesktopImage._desktop_pos =
ImVec2 (static_cast <float> (out_desc.DesktopCoordinates.left),
static_cast <float> (out_desc.DesktopCoordinates.top));

pDevCtx->Flush ();

Expand Down Expand Up @@ -1892,14 +1895,18 @@ SKIV_Image_CaptureRegion (ImRect capture_area)
if (SKIV_DesktopImage._rotation == DXGI_MODE_ROTATION_ROTATE90 ||
SKIV_DesktopImage._rotation == DXGI_MODE_ROTATION_ROTATE270)
{
float height = minfo.rcMonitor.right - minfo.rcMonitor.left;
float width = minfo.rcMonitor.bottom - minfo.rcMonitor.top;
const float height =
static_cast <float> (minfo.rcMonitor.right - minfo.rcMonitor.left),
width =
static_cast <float> (minfo.rcMonitor.bottom - minfo.rcMonitor.top);

std::swap (capture_area.Min.x, capture_area.Min.y);
std::swap (capture_area.Max.x, capture_area.Max.y);

float capture_height = capture_area.Max.y - capture_area.Min.y;
float capture_width = capture_area.Max.x - capture_area.Min.x;
const float capture_height =
static_cast <float> (capture_area.Max.y - capture_area.Min.y),
capture_width =
static_cast <float> (capture_area.Max.x - capture_area.Min.x);

if (SKIV_DesktopImage._rotation == DXGI_MODE_ROTATION_ROTATE90)
{
Expand All @@ -1909,6 +1916,8 @@ SKIV_Image_CaptureRegion (ImRect capture_area)

else
{
std::ignore = capture_width;
std::ignore = width;
//capture_area.Min.x = width - capture_width;
//capture_area.Max.x = width;
}
Expand Down

0 comments on commit 5d79b33

Please sign in to comment.