Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(608)

Side by Side Diff: core/src/fxge/win32/fx_win32_dib.cpp

Issue 1520063002: Get rid of most instance of 'foo == NULL' (Closed) Base URL: https://pdfium.googlesource.com/pdfium@bstr_isnull
Patch Set: rebase Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « core/src/fxge/win32/fx_win32_device.cpp ('k') | core/src/fxge/win32/fx_win32_dwrite.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 PDFium Authors. All rights reserved. 1 // Copyright 2014 PDFium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6 6
7 #include "core/include/fxge/fx_ge.h" 7 #include "core/include/fxge/fx_ge.h"
8 8
9 #if _FX_OS_ == _FX_WIN32_DESKTOP_ || _FX_OS_ == _FX_WIN64_DESKTOP_ 9 #if _FX_OS_ == _FX_WIN32_DESKTOP_ || _FX_OS_ == _FX_WIN64_DESKTOP_
10 #include <windows.h> 10 #include <windows.h>
(...skipping 10 matching lines...) Expand all
21 BITMAPINFOHEADER* pbmih = (BITMAPINFOHEADER*)result.GetBuffer(len); 21 BITMAPINFOHEADER* pbmih = (BITMAPINFOHEADER*)result.GetBuffer(len);
22 FXSYS_memset(pbmih, 0, sizeof(BITMAPINFOHEADER)); 22 FXSYS_memset(pbmih, 0, sizeof(BITMAPINFOHEADER));
23 pbmih->biSize = sizeof(BITMAPINFOHEADER); 23 pbmih->biSize = sizeof(BITMAPINFOHEADER);
24 pbmih->biBitCount = pBitmap->GetBPP(); 24 pbmih->biBitCount = pBitmap->GetBPP();
25 pbmih->biCompression = BI_RGB; 25 pbmih->biCompression = BI_RGB;
26 pbmih->biHeight = -(int)pBitmap->GetHeight(); 26 pbmih->biHeight = -(int)pBitmap->GetHeight();
27 pbmih->biPlanes = 1; 27 pbmih->biPlanes = 1;
28 pbmih->biWidth = pBitmap->GetWidth(); 28 pbmih->biWidth = pBitmap->GetWidth();
29 if (pBitmap->GetBPP() == 8) { 29 if (pBitmap->GetBPP() == 8) {
30 FX_DWORD* pPalette = (FX_DWORD*)(pbmih + 1); 30 FX_DWORD* pPalette = (FX_DWORD*)(pbmih + 1);
31 if (pBitmap->GetPalette() == NULL) { 31 if (pBitmap->GetPalette()) {
32 for (int i = 0; i < 256; i++) { 32 for (int i = 0; i < 256; i++) {
33 pPalette[i] = i * 0x010101; 33 pPalette[i] = pBitmap->GetPalette()[i];
34 } 34 }
35 } else { 35 } else {
36 for (int i = 0; i < 256; i++) { 36 for (int i = 0; i < 256; i++) {
37 pPalette[i] = pBitmap->GetPalette()[i]; 37 pPalette[i] = i * 0x010101;
38 } 38 }
39 } 39 }
40 } 40 }
41 if (pBitmap->GetBPP() == 1) { 41 if (pBitmap->GetBPP() == 1) {
42 FX_DWORD* pPalette = (FX_DWORD*)(pbmih + 1); 42 FX_DWORD* pPalette = (FX_DWORD*)(pbmih + 1);
43 if (pBitmap->GetPalette() == NULL) { 43 if (pBitmap->GetPalette()) {
44 pPalette[0] = pBitmap->GetPalette()[0];
45 pPalette[1] = pBitmap->GetPalette()[1];
46 } else {
44 pPalette[0] = 0; 47 pPalette[0] = 0;
45 pPalette[1] = 0xffffff; 48 pPalette[1] = 0xffffff;
46 } else {
47 pPalette[0] = pBitmap->GetPalette()[0];
48 pPalette[1] = pBitmap->GetPalette()[1];
49 } 49 }
50 } 50 }
51 result.ReleaseBuffer(len); 51 result.ReleaseBuffer(len);
52 return result; 52 return result;
53 } 53 }
54 CFX_DIBitmap* _FX_WindowsDIB_LoadFromBuf(BITMAPINFO* pbmi, 54 CFX_DIBitmap* _FX_WindowsDIB_LoadFromBuf(BITMAPINFO* pbmi,
55 LPVOID pData, 55 LPVOID pData,
56 FX_BOOL bAlpha) { 56 FX_BOOL bAlpha) {
57 int width = pbmi->bmiHeader.biWidth; 57 int width = pbmi->bmiHeader.biWidth;
58 int height = pbmi->bmiHeader.biHeight; 58 int height = pbmi->bmiHeader.biHeight;
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
118 CWin32Platform* pPlatform = 118 CWin32Platform* pPlatform =
119 (CWin32Platform*)CFX_GEModule::Get()->GetPlatformData(); 119 (CWin32Platform*)CFX_GEModule::Get()->GetPlatformData();
120 if (pPlatform->m_GdiplusExt.IsAvailable()) { 120 if (pPlatform->m_GdiplusExt.IsAvailable()) {
121 WINDIB_Open_Args_ args; 121 WINDIB_Open_Args_ args;
122 args.flags = WINDIB_OPEN_PATHNAME; 122 args.flags = WINDIB_OPEN_PATHNAME;
123 args.path_name = filename; 123 args.path_name = filename;
124 return pPlatform->m_GdiplusExt.LoadDIBitmap(args); 124 return pPlatform->m_GdiplusExt.LoadDIBitmap(args);
125 } 125 }
126 HBITMAP hBitmap = (HBITMAP)LoadImageW(NULL, (wchar_t*)filename, IMAGE_BITMAP, 126 HBITMAP hBitmap = (HBITMAP)LoadImageW(NULL, (wchar_t*)filename, IMAGE_BITMAP,
127 0, 0, LR_LOADFROMFILE); 127 0, 0, LR_LOADFROMFILE);
128 if (hBitmap == NULL) { 128 if (!hBitmap) {
129 return NULL; 129 return NULL;
130 } 130 }
131 HDC hDC = CreateCompatibleDC(NULL); 131 HDC hDC = CreateCompatibleDC(NULL);
132 int width, height; 132 int width, height;
133 GetBitmapSize(hBitmap, width, height); 133 GetBitmapSize(hBitmap, width, height);
134 CFX_DIBitmap* pDIBitmap = new CFX_DIBitmap; 134 CFX_DIBitmap* pDIBitmap = new CFX_DIBitmap;
135 if (!pDIBitmap->Create(width, height, FXDIB_Rgb)) { 135 if (!pDIBitmap->Create(width, height, FXDIB_Rgb)) {
136 delete pDIBitmap; 136 delete pDIBitmap;
137 DeleteDC(hDC); 137 DeleteDC(hDC);
138 return NULL; 138 return NULL;
(...skipping 12 matching lines...) Expand all
151 CWin32Platform* pPlatform = 151 CWin32Platform* pPlatform =
152 (CWin32Platform*)CFX_GEModule::Get()->GetPlatformData(); 152 (CWin32Platform*)CFX_GEModule::Get()->GetPlatformData();
153 if (pPlatform->m_GdiplusExt.IsAvailable()) { 153 if (pPlatform->m_GdiplusExt.IsAvailable()) {
154 return pPlatform->m_GdiplusExt.LoadDIBitmap(args); 154 return pPlatform->m_GdiplusExt.LoadDIBitmap(args);
155 } 155 }
156 if (args.flags == WINDIB_OPEN_MEMORY) { 156 if (args.flags == WINDIB_OPEN_MEMORY) {
157 return NULL; 157 return NULL;
158 } 158 }
159 HBITMAP hBitmap = (HBITMAP)LoadImageW(NULL, (wchar_t*)args.path_name, 159 HBITMAP hBitmap = (HBITMAP)LoadImageW(NULL, (wchar_t*)args.path_name,
160 IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE); 160 IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE);
161 if (hBitmap == NULL) { 161 if (!hBitmap) {
162 return NULL; 162 return NULL;
163 } 163 }
164 HDC hDC = CreateCompatibleDC(NULL); 164 HDC hDC = CreateCompatibleDC(NULL);
165 int width, height; 165 int width, height;
166 GetBitmapSize(hBitmap, width, height); 166 GetBitmapSize(hBitmap, width, height);
167 CFX_DIBitmap* pDIBitmap = new CFX_DIBitmap; 167 CFX_DIBitmap* pDIBitmap = new CFX_DIBitmap;
168 if (!pDIBitmap->Create(width, height, FXDIB_Rgb)) { 168 if (!pDIBitmap->Create(width, height, FXDIB_Rgb)) {
169 delete pDIBitmap; 169 delete pDIBitmap;
170 DeleteDC(hDC); 170 DeleteDC(hDC);
171 return NULL; 171 return NULL;
172 } 172 }
173 CFX_ByteString info = GetBitmapInfo(pDIBitmap); 173 CFX_ByteString info = GetBitmapInfo(pDIBitmap);
174 int ret = GetDIBits(hDC, hBitmap, 0, height, pDIBitmap->GetBuffer(), 174 int ret = GetDIBits(hDC, hBitmap, 0, height, pDIBitmap->GetBuffer(),
175 (BITMAPINFO*)info.c_str(), DIB_RGB_COLORS); 175 (BITMAPINFO*)info.c_str(), DIB_RGB_COLORS);
176 if (!ret) { 176 if (!ret) {
177 delete pDIBitmap; 177 delete pDIBitmap;
178 pDIBitmap = NULL; 178 pDIBitmap = NULL;
179 } 179 }
180 DeleteDC(hDC); 180 DeleteDC(hDC);
181 return pDIBitmap; 181 return pDIBitmap;
182 } 182 }
183 CFX_DIBitmap* CFX_WindowsDIB::LoadFromDDB(HDC hDC, 183 CFX_DIBitmap* CFX_WindowsDIB::LoadFromDDB(HDC hDC,
184 HBITMAP hBitmap, 184 HBITMAP hBitmap,
185 FX_DWORD* pPalette, 185 FX_DWORD* pPalette,
186 FX_DWORD palsize) { 186 FX_DWORD palsize) {
187 FX_BOOL bCreatedDC = hDC == NULL; 187 FX_BOOL bCreatedDC = !hDC;
188 if (hDC == NULL) { 188 if (bCreatedDC) {
189 hDC = CreateCompatibleDC(NULL); 189 hDC = CreateCompatibleDC(NULL);
190 } 190 }
191 BITMAPINFOHEADER bmih; 191 BITMAPINFOHEADER bmih;
192 FXSYS_memset(&bmih, 0, sizeof bmih); 192 FXSYS_memset(&bmih, 0, sizeof bmih);
193 bmih.biSize = sizeof bmih; 193 bmih.biSize = sizeof bmih;
194 GetDIBits(hDC, hBitmap, 0, 0, NULL, (BITMAPINFO*)&bmih, DIB_RGB_COLORS); 194 GetDIBits(hDC, hBitmap, 0, 0, NULL, (BITMAPINFO*)&bmih, DIB_RGB_COLORS);
195 int width = bmih.biWidth; 195 int width = bmih.biWidth;
196 int height = abs(bmih.biHeight); 196 int height = abs(bmih.biHeight);
197 bmih.biHeight = -height; 197 bmih.biHeight = -height;
198 bmih.biCompression = BI_RGB; 198 bmih.biCompression = BI_RGB;
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
280 DeleteDC(m_hMemDC); 280 DeleteDC(m_hMemDC);
281 DeleteObject(m_hBitmap); 281 DeleteObject(m_hBitmap);
282 } 282 }
283 void CFX_WindowsDIB::LoadFromDevice(HDC hDC, int left, int top) { 283 void CFX_WindowsDIB::LoadFromDevice(HDC hDC, int left, int top) {
284 ::BitBlt(m_hMemDC, 0, 0, m_Width, m_Height, hDC, left, top, SRCCOPY); 284 ::BitBlt(m_hMemDC, 0, 0, m_Width, m_Height, hDC, left, top, SRCCOPY);
285 } 285 }
286 void CFX_WindowsDIB::SetToDevice(HDC hDC, int left, int top) { 286 void CFX_WindowsDIB::SetToDevice(HDC hDC, int left, int top) {
287 ::BitBlt(hDC, left, top, m_Width, m_Height, m_hMemDC, 0, 0, SRCCOPY); 287 ::BitBlt(hDC, left, top, m_Width, m_Height, m_hMemDC, 0, 0, SRCCOPY);
288 } 288 }
289 #endif 289 #endif
OLDNEW
« no previous file with comments | « core/src/fxge/win32/fx_win32_device.cpp ('k') | core/src/fxge/win32/fx_win32_dwrite.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698