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 "../../../include/fxge/fx_ge.h" | 7 #include "../../../include/fxge/fx_ge.h" |
8 #if _FX_OS_ == _FX_WIN32_DESKTOP_ || _FX_OS_ == _FX_WIN64_DESKTOP_ | 8 #if _FX_OS_ == _FX_WIN32_DESKTOP_ || _FX_OS_ == _FX_WIN64_DESKTOP_ |
9 #include <windows.h> | 9 #include <windows.h> |
10 #include "../../../include/fxge/fx_ge_win32.h" | 10 #include "../../../include/fxge/fx_ge_win32.h" |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
42 pPalette[0] = 0; | 42 pPalette[0] = 0; |
43 pPalette[1] = 0xffffff; | 43 pPalette[1] = 0xffffff; |
44 } else { | 44 } else { |
45 pPalette[0] = pBitmap->GetPalette()[0]; | 45 pPalette[0] = pBitmap->GetPalette()[0]; |
46 pPalette[1] = pBitmap->GetPalette()[1]; | 46 pPalette[1] = pBitmap->GetPalette()[1]; |
47 } | 47 } |
48 } | 48 } |
49 result.ReleaseBuffer(len); | 49 result.ReleaseBuffer(len); |
50 return result; | 50 return result; |
51 } | 51 } |
52 CFX_DIBitmap* _FX_WindowsDIB_LoadFromBuf(BITMAPINFO* pbmi, LPVOID pData, FX_BOOL
bAlpha) | 52 CFX_DIBitmap* _FX_WindowsDIB_LoadFromBuf(BITMAPINFO* pbmi, LPVOID pData, bool bA
lpha) |
53 { | 53 { |
54 int width = pbmi->bmiHeader.biWidth; | 54 int width = pbmi->bmiHeader.biWidth; |
55 int height = pbmi->bmiHeader.biHeight; | 55 int height = pbmi->bmiHeader.biHeight; |
56 BOOL bBottomUp = TRUE; | 56 BOOL bBottomUp = true; |
57 if (height < 0) { | 57 if (height < 0) { |
58 height = -height; | 58 height = -height; |
59 bBottomUp = FALSE; | 59 bBottomUp = false; |
60 } | 60 } |
61 int pitch = (width * pbmi->bmiHeader.biBitCount + 31) / 32 * 4; | 61 int pitch = (width * pbmi->bmiHeader.biBitCount + 31) / 32 * 4; |
62 CFX_DIBitmap* pBitmap = new CFX_DIBitmap; | 62 CFX_DIBitmap* pBitmap = new CFX_DIBitmap; |
63 FXDIB_Format format = bAlpha ? (FXDIB_Format)(pbmi->bmiHeader.biBitCount + 0
x200) : (FXDIB_Format)pbmi->bmiHeader.biBitCount; | 63 FXDIB_Format format = bAlpha ? (FXDIB_Format)(pbmi->bmiHeader.biBitCount + 0
x200) : (FXDIB_Format)pbmi->bmiHeader.biBitCount; |
64 FX_BOOL ret = pBitmap->Create(width, height, format); | 64 bool ret = pBitmap->Create(width, height, format); |
65 if (!ret) { | 65 if (!ret) { |
66 delete pBitmap; | 66 delete pBitmap; |
67 return NULL; | 67 return NULL; |
68 } | 68 } |
69 FXSYS_memcpy(pBitmap->GetBuffer(), pData, pitch * height); | 69 FXSYS_memcpy(pBitmap->GetBuffer(), pData, pitch * height); |
70 if (bBottomUp) { | 70 if (bBottomUp) { |
71 uint8_t* temp_buf = FX_Alloc(uint8_t, pitch); | 71 uint8_t* temp_buf = FX_Alloc(uint8_t, pitch); |
72 int top = 0, bottom = height - 1; | 72 int top = 0, bottom = height - 1; |
73 while (top < bottom) { | 73 while (top < bottom) { |
74 FXSYS_memcpy(temp_buf, pBitmap->GetBuffer() + top * pitch, pitch); | 74 FXSYS_memcpy(temp_buf, pBitmap->GetBuffer() + top * pitch, pitch); |
(...skipping 11 matching lines...) Expand all Loading... |
86 } | 86 } |
87 } else if (pbmi->bmiHeader.biBitCount == 8) { | 87 } else if (pbmi->bmiHeader.biBitCount == 8) { |
88 for (int i = 0; i < 256; i ++) { | 88 for (int i = 0; i < 256; i ++) { |
89 pBitmap->SetPaletteEntry(i, ((FX_DWORD*)pbmi->bmiColors)[i] | 0xff00
0000); | 89 pBitmap->SetPaletteEntry(i, ((FX_DWORD*)pbmi->bmiColors)[i] | 0xff00
0000); |
90 } | 90 } |
91 } | 91 } |
92 return pBitmap; | 92 return pBitmap; |
93 } | 93 } |
94 CFX_DIBitmap* CFX_WindowsDIB::LoadFromBuf(BITMAPINFO* pbmi, LPVOID pData) | 94 CFX_DIBitmap* CFX_WindowsDIB::LoadFromBuf(BITMAPINFO* pbmi, LPVOID pData) |
95 { | 95 { |
96 return _FX_WindowsDIB_LoadFromBuf(pbmi, pData, FALSE); | 96 return _FX_WindowsDIB_LoadFromBuf(pbmi, pData, false); |
97 } | 97 } |
98 HBITMAP CFX_WindowsDIB::GetDDBitmap(const CFX_DIBitmap* pBitmap, HDC hDC) | 98 HBITMAP CFX_WindowsDIB::GetDDBitmap(const CFX_DIBitmap* pBitmap, HDC hDC) |
99 { | 99 { |
100 CFX_ByteString info = GetBitmapInfo(pBitmap); | 100 CFX_ByteString info = GetBitmapInfo(pBitmap); |
101 HBITMAP hBitmap = NULL; | 101 HBITMAP hBitmap = NULL; |
102 hBitmap = CreateDIBitmap(hDC, (BITMAPINFOHEADER*)info.c_str(), CBM_INIT, | 102 hBitmap = CreateDIBitmap(hDC, (BITMAPINFOHEADER*)info.c_str(), CBM_INIT, |
103 pBitmap->GetBuffer(), (BITMAPINFO*)info.c_str(), DIB_RGB_COLORS); | 103 pBitmap->GetBuffer(), (BITMAPINFO*)info.c_str(), DIB_RGB_COLORS); |
104 return hBitmap; | 104 return hBitmap; |
105 } | 105 } |
106 void GetBitmapSize(HBITMAP hBitmap, int& w, int& h) | 106 void GetBitmapSize(HBITMAP hBitmap, int& w, int& h) |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
166 int ret = GetDIBits(hDC, hBitmap, 0, height, pDIBitmap->GetBuffer(), (BITMAP
INFO*)info.c_str(), DIB_RGB_COLORS); | 166 int ret = GetDIBits(hDC, hBitmap, 0, height, pDIBitmap->GetBuffer(), (BITMAP
INFO*)info.c_str(), DIB_RGB_COLORS); |
167 if (!ret) { | 167 if (!ret) { |
168 delete pDIBitmap; | 168 delete pDIBitmap; |
169 pDIBitmap = NULL; | 169 pDIBitmap = NULL; |
170 } | 170 } |
171 DeleteDC(hDC); | 171 DeleteDC(hDC); |
172 return pDIBitmap; | 172 return pDIBitmap; |
173 } | 173 } |
174 CFX_DIBitmap* CFX_WindowsDIB::LoadFromDDB(HDC hDC, HBITMAP hBitmap, FX_DWORD* pP
alette, FX_DWORD palsize) | 174 CFX_DIBitmap* CFX_WindowsDIB::LoadFromDDB(HDC hDC, HBITMAP hBitmap, FX_DWORD* pP
alette, FX_DWORD palsize) |
175 { | 175 { |
176 FX_BOOL bCreatedDC = hDC == NULL; | 176 bool bCreatedDC = hDC == NULL; |
177 if (hDC == NULL) { | 177 if (hDC == NULL) { |
178 hDC = CreateCompatibleDC(NULL); | 178 hDC = CreateCompatibleDC(NULL); |
179 } | 179 } |
180 BITMAPINFOHEADER bmih; | 180 BITMAPINFOHEADER bmih; |
181 FXSYS_memset(&bmih, 0, sizeof bmih); | 181 FXSYS_memset(&bmih, 0, sizeof bmih); |
182 bmih.biSize = sizeof bmih; | 182 bmih.biSize = sizeof bmih; |
183 GetDIBits(hDC, hBitmap, 0, 0, NULL, (BITMAPINFO*)&bmih, DIB_RGB_COLORS); | 183 GetDIBits(hDC, hBitmap, 0, 0, NULL, (BITMAPINFO*)&bmih, DIB_RGB_COLORS); |
184 int width = bmih.biWidth; | 184 int width = bmih.biWidth; |
185 int height = abs(bmih.biHeight); | 185 int height = abs(bmih.biHeight); |
186 bmih.biHeight = -height; | 186 bmih.biHeight = -height; |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
267 } | 267 } |
268 void CFX_WindowsDIB::LoadFromDevice(HDC hDC, int left, int top) | 268 void CFX_WindowsDIB::LoadFromDevice(HDC hDC, int left, int top) |
269 { | 269 { |
270 ::BitBlt(m_hMemDC, 0, 0, m_Width, m_Height, hDC, left, top, SRCCOPY); | 270 ::BitBlt(m_hMemDC, 0, 0, m_Width, m_Height, hDC, left, top, SRCCOPY); |
271 } | 271 } |
272 void CFX_WindowsDIB::SetToDevice(HDC hDC, int left, int top) | 272 void CFX_WindowsDIB::SetToDevice(HDC hDC, int left, int top) |
273 { | 273 { |
274 ::BitBlt(hDC, left, top, m_Width, m_Height, m_hMemDC, 0, 0, SRCCOPY); | 274 ::BitBlt(hDC, left, top, m_Width, m_Height, m_hMemDC, 0, 0, SRCCOPY); |
275 } | 275 } |
276 #endif | 276 #endif |
OLD | NEW |