summaryrefslogtreecommitdiff
path: root/core/fxge/win32/fx_win32_dib.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'core/fxge/win32/fx_win32_dib.cpp')
-rw-r--r--core/fxge/win32/fx_win32_dib.cpp52
1 files changed, 25 insertions, 27 deletions
diff --git a/core/fxge/win32/fx_win32_dib.cpp b/core/fxge/win32/fx_win32_dib.cpp
index 9b85b57317..9815457bbd 100644
--- a/core/fxge/win32/fx_win32_dib.cpp
+++ b/core/fxge/win32/fx_win32_dib.cpp
@@ -11,7 +11,8 @@
#include "core/fxge/win32/cfx_windowsdib.h"
#include "core/fxge/win32/win32_int.h"
-CFX_ByteString CFX_WindowsDIB::GetBitmapInfo(const CFX_DIBitmap* pBitmap) {
+CFX_ByteString CFX_WindowsDIB::GetBitmapInfo(
+ const CFX_RetainPtr<CFX_DIBitmap>& pBitmap) {
CFX_ByteString result;
int len = sizeof(BITMAPINFOHEADER);
if (pBitmap->GetBPP() == 1 || pBitmap->GetBPP() == 8) {
@@ -51,9 +52,9 @@ CFX_ByteString CFX_WindowsDIB::GetBitmapInfo(const CFX_DIBitmap* pBitmap) {
return result;
}
-CFX_DIBitmap* _FX_WindowsDIB_LoadFromBuf(BITMAPINFO* pbmi,
- LPVOID pData,
- bool bAlpha) {
+CFX_RetainPtr<CFX_DIBitmap> _FX_WindowsDIB_LoadFromBuf(BITMAPINFO* pbmi,
+ LPVOID pData,
+ bool bAlpha) {
int width = pbmi->bmiHeader.biWidth;
int height = pbmi->bmiHeader.biHeight;
BOOL bBottomUp = true;
@@ -62,15 +63,13 @@ CFX_DIBitmap* _FX_WindowsDIB_LoadFromBuf(BITMAPINFO* pbmi,
bBottomUp = false;
}
int pitch = (width * pbmi->bmiHeader.biBitCount + 31) / 32 * 4;
- CFX_DIBitmap* pBitmap = new CFX_DIBitmap;
+ auto pBitmap = pdfium::MakeRetain<CFX_DIBitmap>();
FXDIB_Format format = bAlpha
? (FXDIB_Format)(pbmi->bmiHeader.biBitCount + 0x200)
: (FXDIB_Format)pbmi->bmiHeader.biBitCount;
- bool ret = pBitmap->Create(width, height, format);
- if (!ret) {
- delete pBitmap;
+ if (!pBitmap->Create(width, height, format))
return nullptr;
- }
+
FXSYS_memcpy(pBitmap->GetBuffer(), pData, pitch * height);
if (bBottomUp) {
uint8_t* temp_buf = FX_Alloc(uint8_t, pitch);
@@ -98,11 +97,13 @@ CFX_DIBitmap* _FX_WindowsDIB_LoadFromBuf(BITMAPINFO* pbmi,
return pBitmap;
}
-CFX_DIBitmap* CFX_WindowsDIB::LoadFromBuf(BITMAPINFO* pbmi, LPVOID pData) {
+CFX_RetainPtr<CFX_DIBitmap> CFX_WindowsDIB::LoadFromBuf(BITMAPINFO* pbmi,
+ LPVOID pData) {
return _FX_WindowsDIB_LoadFromBuf(pbmi, pData, false);
}
-HBITMAP CFX_WindowsDIB::GetDDBitmap(const CFX_DIBitmap* pBitmap, HDC hDC) {
+HBITMAP CFX_WindowsDIB::GetDDBitmap(const CFX_RetainPtr<CFX_DIBitmap>& pBitmap,
+ HDC hDC) {
CFX_ByteString info = GetBitmapInfo(pBitmap);
return CreateDIBitmap(hDC, (BITMAPINFOHEADER*)info.c_str(), CBM_INIT,
pBitmap->GetBuffer(), (BITMAPINFO*)info.c_str(),
@@ -116,7 +117,8 @@ void GetBitmapSize(HBITMAP hBitmap, int& w, int& h) {
h = bmp.bmHeight;
}
-CFX_DIBitmap* CFX_WindowsDIB::LoadFromFile(const wchar_t* filename) {
+CFX_RetainPtr<CFX_DIBitmap> CFX_WindowsDIB::LoadFromFile(
+ const wchar_t* filename) {
CWin32Platform* pPlatform =
(CWin32Platform*)CFX_GEModule::Get()->GetPlatformData();
if (pPlatform->m_GdiplusExt.IsAvailable()) {
@@ -131,30 +133,29 @@ CFX_DIBitmap* CFX_WindowsDIB::LoadFromFile(const wchar_t* filename) {
return nullptr;
}
HDC hDC = CreateCompatibleDC(nullptr);
- int width, height;
+ int width;
+ int height;
GetBitmapSize(hBitmap, width, height);
- CFX_DIBitmap* pDIBitmap = new CFX_DIBitmap;
+ auto pDIBitmap = pdfium::MakeRetain<CFX_DIBitmap>();
if (!pDIBitmap->Create(width, height, FXDIB_Rgb)) {
- delete pDIBitmap;
DeleteDC(hDC);
return nullptr;
}
CFX_ByteString info = GetBitmapInfo(pDIBitmap);
int ret = GetDIBits(hDC, hBitmap, 0, height, pDIBitmap->GetBuffer(),
(BITMAPINFO*)info.c_str(), DIB_RGB_COLORS);
- if (!ret) {
- delete pDIBitmap;
- pDIBitmap = nullptr;
- }
DeleteDC(hDC);
+ if (!ret)
+ return nullptr;
return pDIBitmap;
}
-CFX_DIBitmap* CFX_WindowsDIB::LoadFromFile(const char* filename) {
+CFX_RetainPtr<CFX_DIBitmap> CFX_WindowsDIB::LoadFromFile(const char* filename) {
return LoadFromFile(CFX_WideString::FromLocal(filename).c_str());
}
-CFX_DIBitmap* CFX_WindowsDIB::LoadDIBitmap(WINDIB_Open_Args_ args) {
+CFX_RetainPtr<CFX_DIBitmap> CFX_WindowsDIB::LoadDIBitmap(
+ WINDIB_Open_Args_ args) {
CWin32Platform* pPlatform =
(CWin32Platform*)CFX_GEModule::Get()->GetPlatformData();
if (pPlatform->m_GdiplusExt.IsAvailable()) {
@@ -171,20 +172,17 @@ CFX_DIBitmap* CFX_WindowsDIB::LoadDIBitmap(WINDIB_Open_Args_ args) {
HDC hDC = CreateCompatibleDC(nullptr);
int width, height;
GetBitmapSize(hBitmap, width, height);
- CFX_DIBitmap* pDIBitmap = new CFX_DIBitmap;
+ auto pDIBitmap = pdfium::MakeRetain<CFX_DIBitmap>();
if (!pDIBitmap->Create(width, height, FXDIB_Rgb)) {
- delete pDIBitmap;
DeleteDC(hDC);
return nullptr;
}
CFX_ByteString info = GetBitmapInfo(pDIBitmap);
int ret = GetDIBits(hDC, hBitmap, 0, height, pDIBitmap->GetBuffer(),
(BITMAPINFO*)info.c_str(), DIB_RGB_COLORS);
- if (!ret) {
- delete pDIBitmap;
- pDIBitmap = nullptr;
- }
DeleteDC(hDC);
+ if (!ret)
+ return nullptr;
return pDIBitmap;
}