fixed screenshot opacity issue (sorta)

This commit is contained in:
retuci0 2026-03-16 17:55:09 +01:00
parent e87fb36bc4
commit 39315712a5

View file

@ -130,12 +130,12 @@ bool ScreenshotManager::takeScreenshot(const std::wstring& path) {
GUID wicFormat = GUID_WICPixelFormat32bppBGRA;
// we swizzle R / B because WIC expects BGRA for some fucking reason
const UINT width = desc.Width;
const UINT height = desc.Height;
const UINT srcRowPitch = mapped.RowPitch;
const UINT dstStride = width * 4;
// write data and shi
std::vector<BYTE> imageData(dstStride * height);
BYTE* dst = imageData.data();
BYTE* srcBase = reinterpret_cast<BYTE*>(mapped.pData);
@ -143,14 +143,23 @@ bool ScreenshotManager::takeScreenshot(const std::wstring& path) {
BYTE* src = srcBase + y * srcRowPitch;
BYTE* row = dst + y * dstStride;
for (UINT x = 0; x < width; ++x) {
// read original rgba
BYTE r = src[x * 4 + 0];
BYTE g = src[x * 4 + 1];
BYTE b = src[x * 4 + 2];
BYTE a = src[x * 4 + 3];
row[x * 4 + 0] = b;
row[x * 4 + 1] = g;
row[x * 4 + 2] = r;
row[x * 4 + 3] = a;
// black background to fix opacity issues (sorta)
// (using integer math with rounding: (value * a + 127) / 255)
UINT br = (r * a + 127) / 255;
UINT bg = (g * a + 127) / 255;
UINT bb = (b * a + 127) / 255;
// we swizzle R / B because WIC expects BGRA for some fucking reason
row[x * 4 + 0] = static_cast<BYTE>(bb);
row[x * 4 + 1] = static_cast<BYTE>(bg);
row[x * 4 + 2] = static_cast<BYTE>(br);
row[x * 4 + 3] = 255;
}
}