| OLD | NEW |
| 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/fxge/include/fx_ge.h" | 7 #include "core/fxge/include/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 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 182 int ret = GetDIBits(hDC, hBitmap, 0, height, pDIBitmap->GetBuffer(), | 182 int ret = GetDIBits(hDC, hBitmap, 0, height, pDIBitmap->GetBuffer(), |
| 183 (BITMAPINFO*)info.c_str(), DIB_RGB_COLORS); | 183 (BITMAPINFO*)info.c_str(), DIB_RGB_COLORS); |
| 184 if (!ret) { | 184 if (!ret) { |
| 185 delete pDIBitmap; | 185 delete pDIBitmap; |
| 186 pDIBitmap = nullptr; | 186 pDIBitmap = nullptr; |
| 187 } | 187 } |
| 188 DeleteDC(hDC); | 188 DeleteDC(hDC); |
| 189 return pDIBitmap; | 189 return pDIBitmap; |
| 190 } | 190 } |
| 191 | 191 |
| 192 CFX_DIBitmap* CFX_WindowsDIB::LoadFromDDB(HDC hDC, | |
| 193 HBITMAP hBitmap, | |
| 194 uint32_t* pPalette, | |
| 195 uint32_t palsize) { | |
| 196 FX_BOOL bCreatedDC = !hDC; | |
| 197 if (bCreatedDC) { | |
| 198 hDC = CreateCompatibleDC(nullptr); | |
| 199 } | |
| 200 BITMAPINFOHEADER bmih; | |
| 201 FXSYS_memset(&bmih, 0, sizeof bmih); | |
| 202 bmih.biSize = sizeof bmih; | |
| 203 GetDIBits(hDC, hBitmap, 0, 0, nullptr, (BITMAPINFO*)&bmih, DIB_RGB_COLORS); | |
| 204 int width = bmih.biWidth; | |
| 205 int height = abs(bmih.biHeight); | |
| 206 bmih.biHeight = -height; | |
| 207 bmih.biCompression = BI_RGB; | |
| 208 CFX_DIBitmap* pDIBitmap = new CFX_DIBitmap; | |
| 209 int ret = 0; | |
| 210 if (bmih.biBitCount == 1 || bmih.biBitCount == 8) { | |
| 211 int size = sizeof(BITMAPINFOHEADER) + 8; | |
| 212 if (bmih.biBitCount == 8) { | |
| 213 size += sizeof(uint32_t) * 254; | |
| 214 } | |
| 215 BITMAPINFO* pbmih = (BITMAPINFO*)FX_Alloc(uint8_t, size); | |
| 216 pbmih->bmiHeader.biSize = sizeof(BITMAPINFOHEADER); | |
| 217 pbmih->bmiHeader.biBitCount = bmih.biBitCount; | |
| 218 pbmih->bmiHeader.biCompression = BI_RGB; | |
| 219 pbmih->bmiHeader.biHeight = -height; | |
| 220 pbmih->bmiHeader.biPlanes = 1; | |
| 221 pbmih->bmiHeader.biWidth = bmih.biWidth; | |
| 222 if (!pDIBitmap->Create(bmih.biWidth, height, bmih.biBitCount == 1 | |
| 223 ? FXDIB_1bppRgb | |
| 224 : FXDIB_8bppRgb)) { | |
| 225 delete pDIBitmap; | |
| 226 FX_Free(pbmih); | |
| 227 if (bCreatedDC) { | |
| 228 DeleteDC(hDC); | |
| 229 } | |
| 230 return nullptr; | |
| 231 } | |
| 232 ret = GetDIBits(hDC, hBitmap, 0, height, pDIBitmap->GetBuffer(), | |
| 233 (BITMAPINFO*)pbmih, DIB_RGB_COLORS); | |
| 234 FX_Free(pbmih); | |
| 235 pbmih = nullptr; | |
| 236 pDIBitmap->CopyPalette(pPalette, palsize); | |
| 237 } else { | |
| 238 if (bmih.biBitCount <= 24) { | |
| 239 bmih.biBitCount = 24; | |
| 240 } else { | |
| 241 bmih.biBitCount = 32; | |
| 242 } | |
| 243 if (!pDIBitmap->Create(bmih.biWidth, height, | |
| 244 bmih.biBitCount == 24 ? FXDIB_Rgb : FXDIB_Rgb32)) { | |
| 245 delete pDIBitmap; | |
| 246 if (bCreatedDC) { | |
| 247 DeleteDC(hDC); | |
| 248 } | |
| 249 return nullptr; | |
| 250 } | |
| 251 ret = GetDIBits(hDC, hBitmap, 0, height, pDIBitmap->GetBuffer(), | |
| 252 (BITMAPINFO*)&bmih, DIB_RGB_COLORS); | |
| 253 if (ret != 0 && bmih.biBitCount == 32) { | |
| 254 int pitch = pDIBitmap->GetPitch(); | |
| 255 for (int row = 0; row < height; row++) { | |
| 256 uint8_t* dest_scan = (uint8_t*)(pDIBitmap->GetBuffer() + row * pitch); | |
| 257 for (int col = 0; col < width; col++) { | |
| 258 dest_scan[3] = 255; | |
| 259 dest_scan += 4; | |
| 260 } | |
| 261 } | |
| 262 } | |
| 263 } | |
| 264 if (ret == 0) { | |
| 265 delete pDIBitmap; | |
| 266 pDIBitmap = nullptr; | |
| 267 } | |
| 268 if (bCreatedDC) { | |
| 269 DeleteDC(hDC); | |
| 270 } | |
| 271 return pDIBitmap; | |
| 272 } | |
| 273 | |
| 274 CFX_WindowsDIB::CFX_WindowsDIB(HDC hDC, int width, int height) { | 192 CFX_WindowsDIB::CFX_WindowsDIB(HDC hDC, int width, int height) { |
| 275 Create(width, height, FXDIB_Rgb, (uint8_t*)1); | 193 Create(width, height, FXDIB_Rgb, (uint8_t*)1); |
| 276 BITMAPINFOHEADER bmih; | 194 BITMAPINFOHEADER bmih; |
| 277 FXSYS_memset(&bmih, 0, sizeof bmih); | 195 FXSYS_memset(&bmih, 0, sizeof bmih); |
| 278 bmih.biSize = sizeof bmih; | 196 bmih.biSize = sizeof bmih; |
| 279 bmih.biBitCount = 24; | 197 bmih.biBitCount = 24; |
| 280 bmih.biHeight = -height; | 198 bmih.biHeight = -height; |
| 281 bmih.biPlanes = 1; | 199 bmih.biPlanes = 1; |
| 282 bmih.biWidth = width; | 200 bmih.biWidth = width; |
| 283 m_hBitmap = CreateDIBSection(hDC, (BITMAPINFO*)&bmih, DIB_RGB_COLORS, | 201 m_hBitmap = CreateDIBSection(hDC, (BITMAPINFO*)&bmih, DIB_RGB_COLORS, |
| 284 (LPVOID*)&m_pBuffer, nullptr, 0); | 202 (LPVOID*)&m_pBuffer, nullptr, 0); |
| 285 m_hMemDC = CreateCompatibleDC(hDC); | 203 m_hMemDC = CreateCompatibleDC(hDC); |
| 286 m_hOldBitmap = (HBITMAP)SelectObject(m_hMemDC, m_hBitmap); | 204 m_hOldBitmap = (HBITMAP)SelectObject(m_hMemDC, m_hBitmap); |
| 287 } | 205 } |
| 288 | 206 |
| 289 CFX_WindowsDIB::~CFX_WindowsDIB() { | 207 CFX_WindowsDIB::~CFX_WindowsDIB() { |
| 290 SelectObject(m_hMemDC, m_hOldBitmap); | 208 SelectObject(m_hMemDC, m_hOldBitmap); |
| 291 DeleteDC(m_hMemDC); | 209 DeleteDC(m_hMemDC); |
| 292 DeleteObject(m_hBitmap); | 210 DeleteObject(m_hBitmap); |
| 293 } | 211 } |
| 294 | 212 |
| 295 void CFX_WindowsDIB::LoadFromDevice(HDC hDC, int left, int top) { | 213 void CFX_WindowsDIB::LoadFromDevice(HDC hDC, int left, int top) { |
| 296 ::BitBlt(m_hMemDC, 0, 0, m_Width, m_Height, hDC, left, top, SRCCOPY); | 214 ::BitBlt(m_hMemDC, 0, 0, m_Width, m_Height, hDC, left, top, SRCCOPY); |
| 297 } | 215 } |
| 298 | 216 |
| 299 void CFX_WindowsDIB::SetToDevice(HDC hDC, int left, int top) { | 217 void CFX_WindowsDIB::SetToDevice(HDC hDC, int left, int top) { |
| 300 ::BitBlt(hDC, left, top, m_Width, m_Height, m_hMemDC, 0, 0, SRCCOPY); | 218 ::BitBlt(hDC, left, top, m_Width, m_Height, m_hMemDC, 0, 0, SRCCOPY); |
| 301 } | 219 } |
| 302 #endif | 220 #endif |
| OLD | NEW |