mirror of
https://github.com/smartcmd/MinecraftConsoles.git
synced 2026-08-20 09:57:09 +00:00
fixed screenshot opacity issue (sorta)
This commit is contained in:
parent
e87fb36bc4
commit
39315712a5
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue