Simplify WinBITMAPToOOBMP a bit

Use CreateCompatibleDC to avoid using actual desktop DC.
Use ScopedHDC for reliable resource management.

Change-Id: Ia6662cf50355e4259e1d985d1deec8a828f9c8ef
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/193649
Tested-by: Jenkins
Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com>
This commit is contained in:
Mike Kaganski
2025-11-09 10:22:01 +01:00
parent c3eae64e6e
commit c874834280
+5 -7
View File
@@ -29,6 +29,7 @@
#include <shlguid.h>
#include <objidl.h>
#include <shellapi.h>
#include <win/scoped_gdi.hxx>
#include <string>
#include <sstream>
@@ -397,8 +398,6 @@ css::uno::Sequence<sal_Int8> CF_HDROPToFileList(HGLOBAL hGlobal)
Sequence< sal_Int8 > WinBITMAPToOOBMP( HBITMAP aHBMP )
{
Sequence< sal_Int8 > ooBmpStream;
if (BITMAP bm{}; GetObjectW(aHBMP, sizeof(bm), &bm))
{
size_t nDataBytes = ((bm.bmWidth * bm.bmBitsPixel + 31) / 32) * 4 * bm.bmHeight;
@@ -414,15 +413,14 @@ Sequence< sal_Int8 > WinBITMAPToOOBMP( HBITMAP aHBMP )
pBmp->bmiHeader.biBitCount = bm.bmBitsPixel;
pBmp->bmiHeader.biCompression = BI_RGB;
HDC hdc = GetDC(nullptr);
if (GetDIBits(hdc, aHBMP, 0, bm.bmHeight, pBmp + 1, pBmp, DIB_RGB_COLORS))
ScopedHDC hdc(CreateCompatibleDC(nullptr));
if (GetDIBits(hdc.get(), aHBMP, 0, bm.bmHeight, pBmp + 1, pBmp, DIB_RGB_COLORS))
{
ooBmpStream = WinDIBToOOBMP( aBitmapStream );
return WinDIBToOOBMP(aBitmapStream);
}
ReleaseDC(nullptr, hdc);
}
return ooBmpStream;
return {};
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */