| 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 1240 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1251 } | 1251 } |
| 1252 if (pMatrix) { | 1252 if (pMatrix) { |
| 1253 CallFunc(GdipDeleteMatrix)(pMatrix); | 1253 CallFunc(GdipDeleteMatrix)(pMatrix); |
| 1254 } | 1254 } |
| 1255 FX_Free(points); | 1255 FX_Free(points); |
| 1256 FX_Free(types); | 1256 FX_Free(types); |
| 1257 CallFunc(GdipDeletePath)(pGpPath); | 1257 CallFunc(GdipDeletePath)(pGpPath); |
| 1258 CallFunc(GdipDeleteGraphics)(pGraphics); | 1258 CallFunc(GdipDeleteGraphics)(pGraphics); |
| 1259 return TRUE; | 1259 return TRUE; |
| 1260 } | 1260 } |
| 1261 |
| 1261 class GpStream final : public IStream { | 1262 class GpStream final : public IStream { |
| 1262 LONG m_RefCount; | 1263 public: |
| 1263 int m_ReadPos; | 1264 GpStream() : m_RefCount(1), m_ReadPos(0) {} |
| 1264 CFX_ByteTextBuf m_InterStream; | |
| 1265 | 1265 |
| 1266 public: | 1266 // IUnknown |
| 1267 GpStream() { | 1267 HRESULT STDMETHODCALLTYPE QueryInterface(REFIID iid, |
| 1268 m_RefCount = 1; | 1268 void** ppvObject) override { |
| 1269 m_ReadPos = 0; | |
| 1270 } | |
| 1271 virtual HRESULT STDMETHODCALLTYPE QueryInterface(REFIID iid, | |
| 1272 void** ppvObject) { | |
| 1273 if (iid == __uuidof(IUnknown) || iid == __uuidof(IStream) || | 1269 if (iid == __uuidof(IUnknown) || iid == __uuidof(IStream) || |
| 1274 iid == __uuidof(ISequentialStream)) { | 1270 iid == __uuidof(ISequentialStream)) { |
| 1275 *ppvObject = static_cast<IStream*>(this); | 1271 *ppvObject = static_cast<IStream*>(this); |
| 1276 AddRef(); | 1272 AddRef(); |
| 1277 return S_OK; | 1273 return S_OK; |
| 1278 } | 1274 } |
| 1279 return E_NOINTERFACE; | 1275 return E_NOINTERFACE; |
| 1280 } | 1276 } |
| 1281 virtual ULONG STDMETHODCALLTYPE AddRef(void) { | 1277 ULONG STDMETHODCALLTYPE AddRef(void) override { |
| 1282 return (ULONG)InterlockedIncrement(&m_RefCount); | 1278 return (ULONG)InterlockedIncrement(&m_RefCount); |
| 1283 } | 1279 } |
| 1284 virtual ULONG STDMETHODCALLTYPE Release(void) { | 1280 ULONG STDMETHODCALLTYPE Release(void) override { |
| 1285 ULONG res = (ULONG)InterlockedDecrement(&m_RefCount); | 1281 ULONG res = (ULONG)InterlockedDecrement(&m_RefCount); |
| 1286 if (res == 0) { | 1282 if (res == 0) { |
| 1287 delete this; | 1283 delete this; |
| 1288 } | 1284 } |
| 1289 return res; | 1285 return res; |
| 1290 } | 1286 } |
| 1291 | 1287 |
| 1292 public: | 1288 // ISequentialStream |
| 1293 virtual HRESULT STDMETHODCALLTYPE Read(void* Output, | 1289 HRESULT STDMETHODCALLTYPE Read(void* Output, |
| 1294 ULONG cb, | 1290 ULONG cb, |
| 1295 ULONG* pcbRead) { | 1291 ULONG* pcbRead) override { |
| 1296 size_t bytes_left; | 1292 size_t bytes_left; |
| 1297 size_t bytes_out; | 1293 size_t bytes_out; |
| 1298 if (pcbRead) { | 1294 if (pcbRead) { |
| 1299 *pcbRead = 0; | 1295 *pcbRead = 0; |
| 1300 } | 1296 } |
| 1301 if (m_ReadPos == m_InterStream.GetLength()) { | 1297 if (m_ReadPos == m_InterStream.GetLength()) { |
| 1302 return HRESULT_FROM_WIN32(ERROR_END_OF_MEDIA); | 1298 return HRESULT_FROM_WIN32(ERROR_END_OF_MEDIA); |
| 1303 } | 1299 } |
| 1304 bytes_left = m_InterStream.GetLength() - m_ReadPos; | 1300 bytes_left = m_InterStream.GetLength() - m_ReadPos; |
| 1305 bytes_out = std::min(pdfium::base::checked_cast<size_t>(cb), bytes_left); | 1301 bytes_out = std::min(pdfium::base::checked_cast<size_t>(cb), bytes_left); |
| 1306 FXSYS_memcpy(Output, m_InterStream.GetBuffer() + m_ReadPos, bytes_out); | 1302 FXSYS_memcpy(Output, m_InterStream.GetBuffer() + m_ReadPos, bytes_out); |
| 1307 m_ReadPos += (int32_t)bytes_out; | 1303 m_ReadPos += (int32_t)bytes_out; |
| 1308 if (pcbRead) { | 1304 if (pcbRead) { |
| 1309 *pcbRead = (ULONG)bytes_out; | 1305 *pcbRead = (ULONG)bytes_out; |
| 1310 } | 1306 } |
| 1311 return S_OK; | 1307 return S_OK; |
| 1312 } | 1308 } |
| 1313 virtual HRESULT STDMETHODCALLTYPE Write(void const* Input, | 1309 HRESULT STDMETHODCALLTYPE Write(void const* Input, |
| 1314 ULONG cb, | 1310 ULONG cb, |
| 1315 ULONG* pcbWritten) { | 1311 ULONG* pcbWritten) override { |
| 1316 if (cb <= 0) { | 1312 if (cb <= 0) { |
| 1317 if (pcbWritten) { | 1313 if (pcbWritten) { |
| 1318 *pcbWritten = 0; | 1314 *pcbWritten = 0; |
| 1319 } | 1315 } |
| 1320 return S_OK; | 1316 return S_OK; |
| 1321 } | 1317 } |
| 1322 m_InterStream.InsertBlock(m_InterStream.GetLength(), Input, cb); | 1318 m_InterStream.InsertBlock(m_InterStream.GetLength(), Input, cb); |
| 1323 if (pcbWritten) { | 1319 if (pcbWritten) { |
| 1324 *pcbWritten = cb; | 1320 *pcbWritten = cb; |
| 1325 } | 1321 } |
| 1326 return S_OK; | 1322 return S_OK; |
| 1327 } | 1323 } |
| 1328 | 1324 |
| 1329 public: | 1325 // IStream |
| 1330 virtual HRESULT STDMETHODCALLTYPE SetSize(ULARGE_INTEGER) { | 1326 HRESULT STDMETHODCALLTYPE SetSize(ULARGE_INTEGER) override { |
| 1331 return E_NOTIMPL; | 1327 return E_NOTIMPL; |
| 1332 } | 1328 } |
| 1333 virtual HRESULT STDMETHODCALLTYPE CopyTo(IStream*, | 1329 HRESULT STDMETHODCALLTYPE CopyTo(IStream*, |
| 1334 ULARGE_INTEGER, | 1330 ULARGE_INTEGER, |
| 1335 ULARGE_INTEGER*, | 1331 ULARGE_INTEGER*, |
| 1336 ULARGE_INTEGER*) { | 1332 ULARGE_INTEGER*) override { |
| 1337 return E_NOTIMPL; | 1333 return E_NOTIMPL; |
| 1338 } | 1334 } |
| 1339 virtual HRESULT STDMETHODCALLTYPE Commit(DWORD) { return E_NOTIMPL; } | 1335 HRESULT STDMETHODCALLTYPE Commit(DWORD) override { return E_NOTIMPL; } |
| 1340 virtual HRESULT STDMETHODCALLTYPE Revert(void) { return E_NOTIMPL; } | 1336 HRESULT STDMETHODCALLTYPE Revert(void) override { return E_NOTIMPL; } |
| 1341 virtual HRESULT STDMETHODCALLTYPE LockRegion(ULARGE_INTEGER, | 1337 HRESULT STDMETHODCALLTYPE LockRegion(ULARGE_INTEGER, |
| 1342 ULARGE_INTEGER, | 1338 ULARGE_INTEGER, |
| 1343 DWORD) { | 1339 DWORD) override { |
| 1344 return E_NOTIMPL; | 1340 return E_NOTIMPL; |
| 1345 } | 1341 } |
| 1346 virtual HRESULT STDMETHODCALLTYPE UnlockRegion(ULARGE_INTEGER, | 1342 HRESULT STDMETHODCALLTYPE UnlockRegion(ULARGE_INTEGER, |
| 1347 ULARGE_INTEGER, | 1343 ULARGE_INTEGER, |
| 1348 DWORD) { | 1344 DWORD) override { |
| 1349 return E_NOTIMPL; | 1345 return E_NOTIMPL; |
| 1350 } | 1346 } |
| 1351 virtual HRESULT STDMETHODCALLTYPE Clone(IStream** stream) { | 1347 HRESULT STDMETHODCALLTYPE Clone(IStream** stream) override { |
| 1352 return E_NOTIMPL; | 1348 return E_NOTIMPL; |
| 1353 } | 1349 } |
| 1354 virtual HRESULT STDMETHODCALLTYPE Seek(LARGE_INTEGER liDistanceToMove, | 1350 HRESULT STDMETHODCALLTYPE Seek(LARGE_INTEGER liDistanceToMove, |
| 1355 DWORD dwOrigin, | 1351 DWORD dwOrigin, |
| 1356 ULARGE_INTEGER* lpNewFilePointer) { | 1352 ULARGE_INTEGER* lpNewFilePointer) override { |
| 1357 long start = 0; | 1353 long start = 0; |
| 1358 long new_read_position; | 1354 long new_read_position; |
| 1359 switch (dwOrigin) { | 1355 switch (dwOrigin) { |
| 1360 case STREAM_SEEK_SET: | 1356 case STREAM_SEEK_SET: |
| 1361 start = 0; | 1357 start = 0; |
| 1362 break; | 1358 break; |
| 1363 case STREAM_SEEK_CUR: | 1359 case STREAM_SEEK_CUR: |
| 1364 start = m_ReadPos; | 1360 start = m_ReadPos; |
| 1365 break; | 1361 break; |
| 1366 case STREAM_SEEK_END: | 1362 case STREAM_SEEK_END: |
| 1367 start = m_InterStream.GetLength(); | 1363 start = m_InterStream.GetLength(); |
| 1368 break; | 1364 break; |
| 1369 default: | 1365 default: |
| 1370 return STG_E_INVALIDFUNCTION; | 1366 return STG_E_INVALIDFUNCTION; |
| 1371 break; | 1367 break; |
| 1372 } | 1368 } |
| 1373 new_read_position = start + (long)liDistanceToMove.QuadPart; | 1369 new_read_position = start + (long)liDistanceToMove.QuadPart; |
| 1374 if (new_read_position < 0 || | 1370 if (new_read_position < 0 || |
| 1375 new_read_position > m_InterStream.GetLength()) { | 1371 new_read_position > m_InterStream.GetLength()) { |
| 1376 return STG_E_SEEKERROR; | 1372 return STG_E_SEEKERROR; |
| 1377 } | 1373 } |
| 1378 m_ReadPos = new_read_position; | 1374 m_ReadPos = new_read_position; |
| 1379 if (lpNewFilePointer) { | 1375 if (lpNewFilePointer) { |
| 1380 lpNewFilePointer->QuadPart = m_ReadPos; | 1376 lpNewFilePointer->QuadPart = m_ReadPos; |
| 1381 } | 1377 } |
| 1382 return S_OK; | 1378 return S_OK; |
| 1383 } | 1379 } |
| 1384 virtual HRESULT STDMETHODCALLTYPE Stat(STATSTG* pStatstg, DWORD grfStatFlag) { | 1380 HRESULT STDMETHODCALLTYPE Stat(STATSTG* pStatstg, |
| 1381 DWORD grfStatFlag) override { |
| 1385 if (!pStatstg) { | 1382 if (!pStatstg) { |
| 1386 return STG_E_INVALIDFUNCTION; | 1383 return STG_E_INVALIDFUNCTION; |
| 1387 } | 1384 } |
| 1388 ZeroMemory(pStatstg, sizeof(STATSTG)); | 1385 ZeroMemory(pStatstg, sizeof(STATSTG)); |
| 1389 pStatstg->cbSize.QuadPart = m_InterStream.GetLength(); | 1386 pStatstg->cbSize.QuadPart = m_InterStream.GetLength(); |
| 1390 return S_OK; | 1387 return S_OK; |
| 1391 } | 1388 } |
| 1389 |
| 1390 private: |
| 1391 LONG m_RefCount; |
| 1392 int m_ReadPos; |
| 1393 CFX_ByteTextBuf m_InterStream; |
| 1392 }; | 1394 }; |
| 1395 |
| 1393 typedef struct { | 1396 typedef struct { |
| 1394 BITMAPINFO* pbmi; | 1397 BITMAPINFO* pbmi; |
| 1395 int Stride; | 1398 int Stride; |
| 1396 LPBYTE pScan0; | 1399 LPBYTE pScan0; |
| 1397 GpBitmap* pBitmap; | 1400 GpBitmap* pBitmap; |
| 1398 BitmapData* pBitmapData; | 1401 BitmapData* pBitmapData; |
| 1399 GpStream* pStream; | 1402 GpStream* pStream; |
| 1400 } PREVIEW3_DIBITMAP; | 1403 } PREVIEW3_DIBITMAP; |
| 1404 |
| 1401 static PREVIEW3_DIBITMAP* LoadDIBitmap(WINDIB_Open_Args_ args) { | 1405 static PREVIEW3_DIBITMAP* LoadDIBitmap(WINDIB_Open_Args_ args) { |
| 1402 GpBitmap* pBitmap; | 1406 GpBitmap* pBitmap; |
| 1403 GpStream* pStream = nullptr; | 1407 GpStream* pStream = nullptr; |
| 1404 CGdiplusExt& GdiplusExt = | 1408 CGdiplusExt& GdiplusExt = |
| 1405 ((CWin32Platform*)CFX_GEModule::Get()->GetPlatformData())->m_GdiplusExt; | 1409 ((CWin32Platform*)CFX_GEModule::Get()->GetPlatformData())->m_GdiplusExt; |
| 1406 Status status = Ok; | 1410 Status status = Ok; |
| 1407 if (args.flags == WINDIB_OPEN_PATHNAME) { | 1411 if (args.flags == WINDIB_OPEN_PATHNAME) { |
| 1408 status = CallFunc(GdipCreateBitmapFromFileICM)((wchar_t*)args.path_name, | 1412 status = CallFunc(GdipCreateBitmapFromFileICM)((wchar_t*)args.path_name, |
| 1409 &pBitmap); | 1413 &pBitmap); |
| 1410 } else { | 1414 } else { |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1470 } | 1474 } |
| 1471 PREVIEW3_DIBITMAP* pInfo = FX_Alloc(PREVIEW3_DIBITMAP, 1); | 1475 PREVIEW3_DIBITMAP* pInfo = FX_Alloc(PREVIEW3_DIBITMAP, 1); |
| 1472 pInfo->pbmi = (BITMAPINFO*)buf; | 1476 pInfo->pbmi = (BITMAPINFO*)buf; |
| 1473 pInfo->pScan0 = (LPBYTE)pBitmapData->Scan0; | 1477 pInfo->pScan0 = (LPBYTE)pBitmapData->Scan0; |
| 1474 pInfo->Stride = pBitmapData->Stride; | 1478 pInfo->Stride = pBitmapData->Stride; |
| 1475 pInfo->pBitmap = pBitmap; | 1479 pInfo->pBitmap = pBitmap; |
| 1476 pInfo->pBitmapData = pBitmapData; | 1480 pInfo->pBitmapData = pBitmapData; |
| 1477 pInfo->pStream = pStream; | 1481 pInfo->pStream = pStream; |
| 1478 return pInfo; | 1482 return pInfo; |
| 1479 } | 1483 } |
| 1484 |
| 1480 static void FreeDIBitmap(PREVIEW3_DIBITMAP* pInfo) { | 1485 static void FreeDIBitmap(PREVIEW3_DIBITMAP* pInfo) { |
| 1481 CGdiplusExt& GdiplusExt = | 1486 CGdiplusExt& GdiplusExt = |
| 1482 ((CWin32Platform*)CFX_GEModule::Get()->GetPlatformData())->m_GdiplusExt; | 1487 ((CWin32Platform*)CFX_GEModule::Get()->GetPlatformData())->m_GdiplusExt; |
| 1483 CallFunc(GdipBitmapUnlockBits)(pInfo->pBitmap, pInfo->pBitmapData); | 1488 CallFunc(GdipBitmapUnlockBits)(pInfo->pBitmap, pInfo->pBitmapData); |
| 1484 CallFunc(GdipDisposeImage)(pInfo->pBitmap); | 1489 CallFunc(GdipDisposeImage)(pInfo->pBitmap); |
| 1485 FX_Free(pInfo->pBitmapData); | 1490 FX_Free(pInfo->pBitmapData); |
| 1486 FX_Free((LPBYTE)pInfo->pbmi); | 1491 FX_Free((LPBYTE)pInfo->pbmi); |
| 1487 if (pInfo->pStream) { | 1492 if (pInfo->pStream) { |
| 1488 pInfo->pStream->Release(); | 1493 pInfo->pStream->Release(); |
| 1489 } | 1494 } |
| 1490 FX_Free(pInfo); | 1495 FX_Free(pInfo); |
| 1491 } | 1496 } |
| 1497 |
| 1492 CFX_DIBitmap* _FX_WindowsDIB_LoadFromBuf(BITMAPINFO* pbmi, | 1498 CFX_DIBitmap* _FX_WindowsDIB_LoadFromBuf(BITMAPINFO* pbmi, |
| 1493 LPVOID pData, | 1499 LPVOID pData, |
| 1494 FX_BOOL bAlpha); | 1500 FX_BOOL bAlpha); |
| 1495 CFX_DIBitmap* CGdiplusExt::LoadDIBitmap(WINDIB_Open_Args_ args) { | 1501 CFX_DIBitmap* CGdiplusExt::LoadDIBitmap(WINDIB_Open_Args_ args) { |
| 1496 PREVIEW3_DIBITMAP* pInfo = ::LoadDIBitmap(args); | 1502 PREVIEW3_DIBITMAP* pInfo = ::LoadDIBitmap(args); |
| 1497 if (!pInfo) { | 1503 if (!pInfo) { |
| 1498 return nullptr; | 1504 return nullptr; |
| 1499 } | 1505 } |
| 1500 int height = abs(pInfo->pbmi->bmiHeader.biHeight); | 1506 int height = abs(pInfo->pbmi->bmiHeader.biHeight); |
| 1501 int width = pInfo->pbmi->bmiHeader.biWidth; | 1507 int width = pInfo->pbmi->bmiHeader.biWidth; |
| 1502 int dest_pitch = (width * pInfo->pbmi->bmiHeader.biBitCount + 31) / 32 * 4; | 1508 int dest_pitch = (width * pInfo->pbmi->bmiHeader.biBitCount + 31) / 32 * 4; |
| 1503 LPBYTE pData = FX_Alloc2D(BYTE, dest_pitch, height); | 1509 LPBYTE pData = FX_Alloc2D(BYTE, dest_pitch, height); |
| 1504 if (dest_pitch == pInfo->Stride) { | 1510 if (dest_pitch == pInfo->Stride) { |
| 1505 FXSYS_memcpy(pData, pInfo->pScan0, dest_pitch * height); | 1511 FXSYS_memcpy(pData, pInfo->pScan0, dest_pitch * height); |
| 1506 } else { | 1512 } else { |
| 1507 for (int i = 0; i < height; i++) { | 1513 for (int i = 0; i < height; i++) { |
| 1508 FXSYS_memcpy(pData + dest_pitch * i, pInfo->pScan0 + pInfo->Stride * i, | 1514 FXSYS_memcpy(pData + dest_pitch * i, pInfo->pScan0 + pInfo->Stride * i, |
| 1509 dest_pitch); | 1515 dest_pitch); |
| 1510 } | 1516 } |
| 1511 } | 1517 } |
| 1512 CFX_DIBitmap* pDIBitmap = _FX_WindowsDIB_LoadFromBuf( | 1518 CFX_DIBitmap* pDIBitmap = _FX_WindowsDIB_LoadFromBuf( |
| 1513 pInfo->pbmi, pData, pInfo->pbmi->bmiHeader.biBitCount == 32); | 1519 pInfo->pbmi, pData, pInfo->pbmi->bmiHeader.biBitCount == 32); |
| 1514 FX_Free(pData); | 1520 FX_Free(pData); |
| 1515 FreeDIBitmap(pInfo); | 1521 FreeDIBitmap(pInfo); |
| 1516 return pDIBitmap; | 1522 return pDIBitmap; |
| 1517 } | 1523 } |
| 1518 #endif | 1524 #endif |
| OLD | NEW |