Revert "Remove FX_Alloc() null checks now that it can't return NULL."
[pdfium.git] / core / src / fxge / win32 / fx_win32_gdipext.cpp
index d3aeecc..49c3f2b 100644 (file)
@@ -7,9 +7,14 @@
 #include "../../../include/fxge/fx_ge.h"
 #if _FX_OS_ == _FX_WIN32_DESKTOP_ || _FX_OS_ == _FX_WIN64_
 #include <windows.h>
+#include <algorithm>
+namespace Gdiplus {
+  using std::min;
+  using std::max;
+}  // namespace Gdiplus
+#include <gdiplus.h>
 #include "../../../include/fxge/fx_ge_win32.h"
 #include "win32_int.h"
-#include "../Microsoft SDK/include/GdiPlus.h"
 using namespace Gdiplus;
 using namespace Gdiplus::DllExports;
 #define GdiFillType2Gdip(fill_type) (fill_type == ALTERNATE ? FillModeAlternate : FillModeWinding)
@@ -297,10 +302,7 @@ static CFX_DIBitmap* _StretchMonoToGray(int dest_width, int dest_height,
     int result_width = pClipRect->Width();
     int result_height = pClipRect->Height();
     int result_pitch = (result_width + 3) / 4 * 4;
-    CFX_DIBitmap* pStretched = FX_NEW CFX_DIBitmap;
-    if (!pStretched) {
-        return NULL;
-    }
+    CFX_DIBitmap* pStretched = new CFX_DIBitmap;
     if (!pStretched->Create(result_width, result_height, FXDIB_8bppRgb)) {
         delete pStretched;
         return NULL;
@@ -1003,7 +1005,7 @@ BOOL CGdiplusExt::DrawPath(HDC hDC, const CFX_PathData* pPathData,
     CallFunc(GdipDeleteGraphics)(pGraphics);
     return TRUE;
 }
-class GpStream : public IStream, public CFX_Object
+class GpStream FX_FINAL : public IStream
 {
     LONG       m_RefCount;
     int     m_ReadPos;
@@ -1159,10 +1161,7 @@ static PREVIEW3_DIBITMAP* LoadDIBitmap(WINDIB_Open_Args_ args)
         if (args.memory_size == 0 || !args.memory_base) {
             return NULL;
         }
-        pStream = FX_NEW GpStream;
-        if (!pStream) {
-            return NULL;
-        }
+        pStream = new GpStream;
         pStream->Write(args.memory_base, (ULONG)args.memory_size, NULL);
         status = CallFunc(GdipCreateBitmapFromStreamICM)(pStream, &pBitmap);
     }
@@ -1200,7 +1199,6 @@ static PREVIEW3_DIBITMAP* LoadDIBitmap(WINDIB_Open_Args_ args)
         return NULL;
     }
     BITMAPINFOHEADER* pbmih = (BITMAPINFOHEADER*)buf;
-    FXSYS_memset32(buf, 0, info_size);
     pbmih->biBitCount = bpp;
     pbmih->biCompression = BI_RGB;
     pbmih->biHeight = -(int)height;
@@ -1268,16 +1266,14 @@ CFX_DIBitmap* CGdiplusExt::LoadDIBitmap(WINDIB_Open_Args_ args)
     int height = abs(pInfo->pbmi->bmiHeader.biHeight);
     int width = pInfo->pbmi->bmiHeader.biWidth;
     int dest_pitch = (width * pInfo->pbmi->bmiHeader.biBitCount + 31) / 32 * 4;
-    LPBYTE pData = FX_Alloc(BYTE, dest_pitch * height);
-    if (pData == NULL) {
-        FreeDIBitmap(pInfo);
-        return NULL;
-    }
+    LPBYTE pData = FX_Alloc2D(BYTE, dest_pitch, height);
     if (dest_pitch == pInfo->Stride) {
         FXSYS_memcpy32(pData, pInfo->pScan0, dest_pitch * height);
-    } else for (int i = 0; i < height; i ++) {
+    } else {
+        for (int i = 0; i < height; i ++) {
             FXSYS_memcpy32(pData + dest_pitch * i, pInfo->pScan0 + pInfo->Stride * i, dest_pitch);
         }
+    }
     CFX_DIBitmap* pDIBitmap = _FX_WindowsDIB_LoadFromBuf(pInfo->pbmi, pData, pInfo->pbmi->bmiHeader.biBitCount == 32);
     FX_Free(pData);
     FreeDIBitmap(pInfo);