Remove most CFX_WindowsDIB code. It's all unused. Similarly, CGdiplusExt::LoadDIBitmap() is also unused. Change-Id: I34d34572cf21a9d8e8c244a630bd80dae94ceb45 Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/75631 Reviewed-by: Hui Yingst <nigi@chromium.org> Commit-Queue: Lei Zhang <thestig@chromium.org>
diff --git a/core/fxge/win32/cfx_windowsdib.cpp b/core/fxge/win32/cfx_windowsdib.cpp index 03e7b82..464c763 100644 --- a/core/fxge/win32/cfx_windowsdib.cpp +++ b/core/fxge/win32/cfx_windowsdib.cpp
@@ -8,27 +8,7 @@ #include <windows.h> -#include <vector> - -#include "core/fxcrt/fx_memory_wrappers.h" #include "core/fxcrt/fx_system.h" -#include "core/fxge/cfx_gemodule.h" -#include "core/fxge/win32/cwin32_platform.h" - -namespace { - -void GetBitmapSize(HBITMAP hBitmap, int& w, int& h) { - BITMAP bmp; - GetObject(hBitmap, sizeof bmp, &bmp); - w = bmp.bmWidth; - h = bmp.bmHeight; -} - -FXDIB_Format GetBitmapFormat(int bpp) { - return bpp == 32 ? FXDIB_Format::kArgb : MakeRGBFormat(bpp); -} - -} // namespace // static ByteString CFX_WindowsDIB::GetBitmapInfo( @@ -76,155 +56,3 @@ result.ReleaseBuffer(len); return result; } - -// static -RetainPtr<CFX_DIBitmap> CFX_WindowsDIB::LoadFromBuf(BITMAPINFO* pbmi, - void* pData) { - int width = pbmi->bmiHeader.biWidth; - int height = pbmi->bmiHeader.biHeight; - BOOL bBottomUp = true; - if (height < 0) { - height = -height; - bBottomUp = false; - } - int pitch = (width * pbmi->bmiHeader.biBitCount + 31) / 32 * 4; - auto pBitmap = pdfium::MakeRetain<CFX_DIBitmap>(); - FXDIB_Format format = GetBitmapFormat(pbmi->bmiHeader.biBitCount); - if (!pBitmap->Create(width, height, format)) - return nullptr; - - memcpy(pBitmap->GetBuffer(), pData, pitch * height); - if (bBottomUp) { - std::vector<uint8_t, FxAllocAllocator<uint8_t>> temp_buf(pitch); - int top = 0; - int bottom = height - 1; - while (top < bottom) { - uint8_t* top_ptr = pBitmap->GetBuffer() + top * pitch; - uint8_t* bottom_ptr = pBitmap->GetBuffer() + bottom * pitch; - memcpy(temp_buf.data(), top_ptr, pitch); - memcpy(top_ptr, bottom_ptr, pitch); - memcpy(bottom_ptr, temp_buf.data(), pitch); - top++; - bottom--; - } - } - if (pbmi->bmiHeader.biBitCount == 1) { - for (int i = 0; i < 2; i++) - pBitmap->SetPaletteArgb(i, ((uint32_t*)pbmi->bmiColors)[i] | 0xff000000); - } else if (pbmi->bmiHeader.biBitCount == 8) { - for (int i = 0; i < 256; i++) - pBitmap->SetPaletteArgb(i, ((uint32_t*)pbmi->bmiColors)[i] | 0xff000000); - } - return pBitmap; -} - -// static -HBITMAP CFX_WindowsDIB::GetDDBitmap(const RetainPtr<CFX_DIBitmap>& pBitmap, - HDC hDC) { - ByteString info = GetBitmapInfo(pBitmap); - return CreateDIBitmap(hDC, (BITMAPINFOHEADER*)info.c_str(), CBM_INIT, - pBitmap->GetBuffer(), (BITMAPINFO*)info.c_str(), - DIB_RGB_COLORS); -} - -// static -RetainPtr<CFX_DIBitmap> CFX_WindowsDIB::LoadFromFile(const wchar_t* filename) { - auto* pPlatform = - static_cast<CWin32Platform*>(CFX_GEModule::Get()->GetPlatform()); - if (pPlatform->m_GdiplusExt.IsAvailable()) { - WINDIB_Open_Args_ args; - args.flags = WINDIB_OPEN_PATHNAME; - args.path_name = filename; - return pPlatform->m_GdiplusExt.LoadDIBitmap(args); - } - HBITMAP hBitmap = (HBITMAP)LoadImageW(nullptr, (wchar_t*)filename, - IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE); - if (!hBitmap) { - return nullptr; - } - HDC hDC = CreateCompatibleDC(nullptr); - int width; - int height; - GetBitmapSize(hBitmap, width, height); - auto pDIBitmap = pdfium::MakeRetain<CFX_DIBitmap>(); - if (!pDIBitmap->Create(width, height, FXDIB_Format::kRgb)) { - DeleteDC(hDC); - return nullptr; - } - ByteString info = GetBitmapInfo(pDIBitmap); - int ret = GetDIBits(hDC, hBitmap, 0, height, pDIBitmap->GetBuffer(), - (BITMAPINFO*)info.c_str(), DIB_RGB_COLORS); - DeleteDC(hDC); - if (!ret) - return nullptr; - return pDIBitmap; -} - -// static -RetainPtr<CFX_DIBitmap> CFX_WindowsDIB::LoadFromFile(const char* filename) { - return LoadFromFile(WideString::FromDefANSI(filename).c_str()); -} - -// static -RetainPtr<CFX_DIBitmap> CFX_WindowsDIB::LoadDIBitmap(WINDIB_Open_Args_ args) { - auto* pPlatform = - static_cast<CWin32Platform*>(CFX_GEModule::Get()->GetPlatform()); - if (pPlatform->m_GdiplusExt.IsAvailable()) { - return pPlatform->m_GdiplusExt.LoadDIBitmap(args); - } - if (args.flags == WINDIB_OPEN_MEMORY) { - return nullptr; - } - HBITMAP hBitmap = (HBITMAP)LoadImageW(nullptr, (wchar_t*)args.path_name, - IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE); - if (!hBitmap) { - return nullptr; - } - HDC hDC = CreateCompatibleDC(nullptr); - int width, height; - GetBitmapSize(hBitmap, width, height); - auto pDIBitmap = pdfium::MakeRetain<CFX_DIBitmap>(); - if (!pDIBitmap->Create(width, height, FXDIB_Format::kRgb)) { - DeleteDC(hDC); - return nullptr; - } - ByteString info = GetBitmapInfo(pDIBitmap); - int ret = GetDIBits(hDC, hBitmap, 0, height, pDIBitmap->GetBuffer(), - (BITMAPINFO*)info.c_str(), DIB_RGB_COLORS); - DeleteDC(hDC); - if (!ret) - return nullptr; - return pDIBitmap; -} - -CFX_WindowsDIB::CFX_WindowsDIB(HDC hDC, int width, int height) { - Create(width, height, FXDIB_Format::kRgb, (uint8_t*)1, 0); - BITMAPINFOHEADER bmih; - memset(&bmih, 0, sizeof bmih); - bmih.biSize = sizeof bmih; - bmih.biBitCount = 24; - bmih.biHeight = -height; - bmih.biPlanes = 1; - bmih.biWidth = width; - LPVOID pData = nullptr; - m_hBitmap = CreateDIBSection(hDC, (BITMAPINFO*)&bmih, DIB_RGB_COLORS, &pData, - nullptr, 0); - m_pBuffer.Reset(static_cast<uint8_t*>(pData)); - m_hMemDC = CreateCompatibleDC(hDC); - m_hOldBitmap = (HBITMAP)SelectObject(m_hMemDC, m_hBitmap); -} - -CFX_WindowsDIB::~CFX_WindowsDIB() { - SelectObject(m_hMemDC, m_hOldBitmap); - DeleteDC(m_hMemDC); - DeleteObject(m_hBitmap); -} - -// static -void CFX_WindowsDIB::LoadFromDevice(HDC hDC, int left, int top) { - ::BitBlt(m_hMemDC, 0, 0, m_Width, m_Height, hDC, left, top, SRCCOPY); -} - -void CFX_WindowsDIB::SetToDevice(HDC hDC, int left, int top) { - ::BitBlt(hDC, left, top, m_Width, m_Height, m_hMemDC, 0, 0, SRCCOPY); -}
diff --git a/core/fxge/win32/cfx_windowsdib.h b/core/fxge/win32/cfx_windowsdib.h index 184b197..61e0843 100644 --- a/core/fxge/win32/cfx_windowsdib.h +++ b/core/fxge/win32/cfx_windowsdib.h
@@ -7,45 +7,16 @@ #ifndef CORE_FXGE_WIN32_CFX_WINDOWSDIB_H_ #define CORE_FXGE_WIN32_CFX_WINDOWSDIB_H_ -#include <windows.h> - #include "core/fxcrt/bytestring.h" #include "core/fxge/dib/cfx_dibitmap.h" -#define WINDIB_OPEN_MEMORY 0x1 -#define WINDIB_OPEN_PATHNAME 0x2 - -struct WINDIB_Open_Args_ { - int flags; - const uint8_t* memory_base; - size_t memory_size; - const wchar_t* path_name; -}; - -class CFX_WindowsDIB final : public CFX_DIBitmap { +class CFX_WindowsDIB { public: - CONSTRUCT_VIA_MAKE_RETAIN; - static ByteString GetBitmapInfo(const RetainPtr<CFX_DIBitmap>& pBitmap); - static HBITMAP GetDDBitmap(const RetainPtr<CFX_DIBitmap>& pBitmap, HDC hDC); - static RetainPtr<CFX_DIBitmap> LoadFromBuf(BITMAPINFO* pbmi, void* pData); - static RetainPtr<CFX_DIBitmap> LoadFromFile(const wchar_t* filename); - static RetainPtr<CFX_DIBitmap> LoadFromFile(const char* filename); - static RetainPtr<CFX_DIBitmap> LoadDIBitmap(WINDIB_Open_Args_ args); - - HBITMAP GetWindowsBitmap() const { return m_hBitmap; } - - void LoadFromDevice(HDC hDC, int left, int top); - void SetToDevice(HDC hDC, int left, int top); - - private: - CFX_WindowsDIB(HDC hDC, int width, int height); - ~CFX_WindowsDIB() override; - - HDC m_hMemDC; - HBITMAP m_hBitmap; - HBITMAP m_hOldBitmap; + CFX_WindowsDIB() = delete; + CFX_WindowsDIB(const CFX_WindowsDIB&) = delete; + CFX_WindowsDIB& operator=(const CFX_WindowsDIB&) = delete; }; #endif // CORE_FXGE_WIN32_CFX_WINDOWSDIB_H_
diff --git a/core/fxge/win32/cgdi_plus_ext.cpp b/core/fxge/win32/cgdi_plus_ext.cpp index 4e915a5..344a5d7 100644 --- a/core/fxge/win32/cgdi_plus_ext.cpp +++ b/core/fxge/win32/cgdi_plus_ext.cpp
@@ -17,12 +17,13 @@ #include <vector> #include "core/fxcrt/fx_memory.h" +#include "core/fxcrt/fx_string.h" #include "core/fxcrt/fx_system.h" #include "core/fxge/cfx_fillrenderoptions.h" #include "core/fxge/cfx_gemodule.h" #include "core/fxge/cfx_graphstatedata.h" #include "core/fxge/cfx_pathdata.h" -#include "core/fxge/win32/cfx_windowsdib.h" +#include "core/fxge/dib/cfx_dibitmap.h" #include "core/fxge/win32/cwin32_platform.h" #include "third_party/base/span.h" #include "third_party/base/stl_util.h" @@ -650,110 +651,6 @@ std::ostringstream m_InterStream; }; -struct PREVIEW3_DIBITMAP { - BITMAPINFO* pbmi; - int Stride; - LPBYTE pScan0; - Gdiplus::GpBitmap* pBitmap; - Gdiplus::BitmapData* pBitmapData; - GpStream* pStream; -}; - -struct DIBitmapDeleter { - void operator()(PREVIEW3_DIBITMAP* bitmap) const { - const CGdiplusExt& GdiplusExt = GetGdiplusExt(); - CallFunc(GdipBitmapUnlockBits)(bitmap->pBitmap, bitmap->pBitmapData); - CallFunc(GdipDisposeImage)(bitmap->pBitmap); - FX_Free(bitmap->pBitmapData); - FX_Free((LPBYTE)bitmap->pbmi); - if (bitmap->pStream) - bitmap->pStream->Release(); - FX_Free(bitmap); - } -}; - -using ScopedDIBitmap = std::unique_ptr<PREVIEW3_DIBITMAP, DIBitmapDeleter>; - -ScopedDIBitmap LoadDIBitmapImpl(WINDIB_Open_Args_ args) { - Gdiplus::GpBitmap* pBitmap; - GpStream* pStream = nullptr; - const CGdiplusExt& GdiplusExt = GetGdiplusExt(); - if (args.flags == WINDIB_OPEN_PATHNAME) { - if (CallFunc(GdipCreateBitmapFromFileICM)(args.path_name, &pBitmap) != - Gdiplus::Ok) { - return nullptr; - } - } else { - if (args.memory_size == 0 || !args.memory_base) - return nullptr; - - pStream = new GpStream; - pStream->Write(args.memory_base, (ULONG)args.memory_size, nullptr); - if (CallFunc(GdipCreateBitmapFromStreamICM)(pStream, &pBitmap) != - Gdiplus::Ok) { - pStream->Release(); - return nullptr; - } - } - - UINT height; - UINT width; - CallFunc(GdipGetImageHeight)(pBitmap, &height); - CallFunc(GdipGetImageWidth)(pBitmap, &width); - Gdiplus::PixelFormat pixel_format; - CallFunc(GdipGetImagePixelFormat)(pBitmap, &pixel_format); - int info_size = sizeof(BITMAPINFOHEADER); - int bpp = 24; - int dest_pixel_format = PixelFormat24bppRGB; - if (pixel_format == PixelFormat1bppIndexed) { - info_size += 8; - bpp = 1; - dest_pixel_format = PixelFormat1bppIndexed; - } else if (pixel_format == PixelFormat8bppIndexed) { - info_size += 1024; - bpp = 8; - dest_pixel_format = PixelFormat8bppIndexed; - } else if (pixel_format == PixelFormat32bppARGB) { - bpp = 32; - dest_pixel_format = PixelFormat32bppARGB; - } - LPBYTE buf = FX_Alloc(BYTE, info_size); - BITMAPINFOHEADER* pbmih = (BITMAPINFOHEADER*)buf; - pbmih->biBitCount = bpp; - pbmih->biCompression = BI_RGB; - pbmih->biHeight = -(int)height; - pbmih->biPlanes = 1; - pbmih->biWidth = width; - Gdiplus::Rect rect(0, 0, width, height); - Gdiplus::BitmapData* pBitmapData = FX_Alloc(Gdiplus::BitmapData, 1); - CallFunc(GdipBitmapLockBits)(pBitmap, &rect, Gdiplus::ImageLockModeRead, - dest_pixel_format, pBitmapData); - if (pixel_format == PixelFormat1bppIndexed || - pixel_format == PixelFormat8bppIndexed) { - DWORD* ppal = (DWORD*)(buf + sizeof(BITMAPINFOHEADER)); - struct { - UINT flags; - UINT Count; - DWORD Entries[256]; - } pal; - int size = 0; - CallFunc(GdipGetImagePaletteSize)(pBitmap, &size); - CallFunc(GdipGetImagePalette)(pBitmap, (Gdiplus::ColorPalette*)&pal, size); - int entries = pixel_format == PixelFormat1bppIndexed ? 2 : 256; - for (int i = 0; i < entries; i++) { - ppal[i] = pal.Entries[i] & 0x00ffffff; - } - } - ScopedDIBitmap pInfo(FX_Alloc(PREVIEW3_DIBITMAP, 1)); - pInfo->pbmi = (BITMAPINFO*)buf; - pInfo->pScan0 = (LPBYTE)pBitmapData->Scan0; - pInfo->Stride = pBitmapData->Stride; - pInfo->pBitmap = pBitmap; - pInfo->pBitmapData = pBitmapData; - pInfo->pStream = pStream; - return pInfo; -} - } // namespace CGdiplusExt::CGdiplusExt() = default; @@ -979,26 +876,3 @@ CallFunc(GdipDeleteGraphics)(pGraphics); return true; } - -RetainPtr<CFX_DIBitmap> CGdiplusExt::LoadDIBitmap(WINDIB_Open_Args_ args) { - ScopedDIBitmap pInfo = LoadDIBitmapImpl(args); - if (!pInfo) - return nullptr; - - int height = abs(pInfo->pbmi->bmiHeader.biHeight); - int width = pInfo->pbmi->bmiHeader.biWidth; - int dest_pitch = (width * pInfo->pbmi->bmiHeader.biBitCount + 31) / 32 * 4; - std::vector<uint8_t, FxAllocAllocator<uint8_t>> data = - pdfium::Vector2D<uint8_t, FxAllocAllocator<uint8_t>>(dest_pitch, height); - if (dest_pitch == pInfo->Stride) { - memcpy(data.data(), pInfo->pScan0, dest_pitch * height); - } else { - for (int i = 0; i < height; i++) { - memcpy(data.data() + dest_pitch * i, pInfo->pScan0 + pInfo->Stride * i, - dest_pitch); - } - } - RetainPtr<CFX_DIBitmap> pDIBitmap = - CFX_WindowsDIB::LoadFromBuf(pInfo->pbmi, data.data()); - return pDIBitmap; -}
diff --git a/core/fxge/win32/cgdi_plus_ext.h b/core/fxge/win32/cgdi_plus_ext.h index fe6a6a8..9a495a9 100644 --- a/core/fxge/win32/cgdi_plus_ext.h +++ b/core/fxge/win32/cgdi_plus_ext.h
@@ -21,7 +21,6 @@ struct CFX_FillRenderOptions; struct FXDIB_ResampleOptions; struct FX_RECT; -struct WINDIB_Open_Args_; class CGdiplusExt { public: @@ -46,8 +45,6 @@ uint32_t stroke_argb, const CFX_FillRenderOptions& fill_options); - RetainPtr<CFX_DIBitmap> LoadDIBitmap(WINDIB_Open_Args_ args); - std::vector<FARPROC> m_Functions; private: