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/fpdfapi/fpdf_render/render_int.h" | 7 #include "core/fpdfapi/fpdf_render/render_int.h" |
8 | 8 |
9 #include <algorithm> | 9 #include <algorithm> |
10 #include <memory> | 10 #include <memory> |
(...skipping 10 matching lines...) Expand all Loading... |
21 #include "core/fxcodec/include/fx_codec.h" | 21 #include "core/fxcodec/include/fx_codec.h" |
22 #include "core/fxcrt/include/fx_safe_types.h" | 22 #include "core/fxcrt/include/fx_safe_types.h" |
23 #include "core/fxge/include/fx_ge.h" | 23 #include "core/fxge/include/fx_ge.h" |
24 | 24 |
25 namespace { | 25 namespace { |
26 | 26 |
27 unsigned int GetBits8(const uint8_t* pData, uint64_t bitpos, size_t nbits) { | 27 unsigned int GetBits8(const uint8_t* pData, uint64_t bitpos, size_t nbits) { |
28 ASSERT(nbits == 1 || nbits == 2 || nbits == 4 || nbits == 8 || nbits == 16); | 28 ASSERT(nbits == 1 || nbits == 2 || nbits == 4 || nbits == 8 || nbits == 16); |
29 ASSERT((bitpos & (nbits - 1)) == 0); | 29 ASSERT((bitpos & (nbits - 1)) == 0); |
30 unsigned int byte = pData[bitpos / 8]; | 30 unsigned int byte = pData[bitpos / 8]; |
31 if (nbits == 8) { | 31 if (nbits == 8) |
32 return byte; | 32 return byte; |
33 } else if (nbits == 16) { | 33 |
| 34 if (nbits == 16) |
34 return byte * 256 + pData[bitpos / 8 + 1]; | 35 return byte * 256 + pData[bitpos / 8 + 1]; |
35 } | |
36 | 36 |
37 return (byte >> (8 - nbits - (bitpos % 8))) & ((1 << nbits) - 1); | 37 return (byte >> (8 - nbits - (bitpos % 8))) & ((1 << nbits) - 1); |
38 } | 38 } |
39 | 39 |
40 FX_SAFE_UINT32 CalculatePitch8(uint32_t bpc, uint32_t components, int width) { | 40 FX_SAFE_UINT32 CalculatePitch8(uint32_t bpc, uint32_t components, int width) { |
41 FX_SAFE_UINT32 pitch = bpc; | 41 FX_SAFE_UINT32 pitch = bpc; |
42 pitch *= components; | 42 pitch *= components; |
43 pitch *= width; | 43 pitch *= width; |
44 pitch += 7; | 44 pitch += 7; |
45 pitch /= 8; | 45 pitch /= 8; |
(...skipping 1439 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1485 CPDF_RenderStatus* pRenderStatus, | 1485 CPDF_RenderStatus* pRenderStatus, |
1486 int32_t nDownsampleWidth, | 1486 int32_t nDownsampleWidth, |
1487 int32_t nDownsampleHeight) { | 1487 int32_t nDownsampleHeight) { |
1488 m_pImageLoader = pImageLoader; | 1488 m_pImageLoader = pImageLoader; |
1489 m_pCache = pCache; | 1489 m_pCache = pCache; |
1490 m_pImage = const_cast<CPDF_ImageObject*>(pImage); | 1490 m_pImage = const_cast<CPDF_ImageObject*>(pImage); |
1491 m_nDownsampleWidth = nDownsampleWidth; | 1491 m_nDownsampleWidth = nDownsampleWidth; |
1492 m_nDownsampleHeight = nDownsampleHeight; | 1492 m_nDownsampleHeight = nDownsampleHeight; |
1493 FX_BOOL ret; | 1493 FX_BOOL ret; |
1494 if (pCache) { | 1494 if (pCache) { |
1495 ret = pCache->StartGetCachedBitmap(pImage->m_pImage->GetStream(), bStdCS, | 1495 ret = pCache->StartGetCachedBitmap( |
1496 GroupFamily, bLoadMask, pRenderStatus, | 1496 m_pImage->GetImage()->GetStream(), bStdCS, GroupFamily, bLoadMask, |
1497 m_nDownsampleWidth, m_nDownsampleHeight); | 1497 pRenderStatus, m_nDownsampleWidth, m_nDownsampleHeight); |
1498 if (!ret) { | |
1499 m_pImageLoader->m_bCached = TRUE; | |
1500 m_pImageLoader->m_pBitmap = | |
1501 pCache->GetCurImageCacheEntry()->DetachBitmap(); | |
1502 m_pImageLoader->m_pMask = pCache->GetCurImageCacheEntry()->DetachMask(); | |
1503 m_pImageLoader->m_MatteColor = | |
1504 pCache->GetCurImageCacheEntry()->m_MatteColor; | |
1505 } | |
1506 } else { | 1498 } else { |
1507 ret = pImage->m_pImage->StartLoadDIBSource(pRenderStatus->m_pFormResource, | 1499 ret = m_pImage->GetImage()->StartLoadDIBSource( |
1508 pRenderStatus->m_pPageResource, | 1500 pRenderStatus->m_pFormResource, pRenderStatus->m_pPageResource, bStdCS, |
1509 bStdCS, GroupFamily, bLoadMask); | 1501 GroupFamily, bLoadMask); |
1510 if (!ret) { | |
1511 m_pImageLoader->m_bCached = FALSE; | |
1512 m_pImageLoader->m_pBitmap = m_pImage->m_pImage->DetachBitmap(); | |
1513 m_pImageLoader->m_pMask = m_pImage->m_pImage->DetachMask(); | |
1514 m_pImageLoader->m_MatteColor = m_pImage->m_pImage->m_MatteColor; | |
1515 } | |
1516 } | 1502 } |
| 1503 if (!ret) |
| 1504 HandleFailure(); |
1517 return ret; | 1505 return ret; |
1518 } | 1506 } |
1519 | 1507 |
1520 FX_BOOL CPDF_ImageLoaderHandle::Continue(IFX_Pause* pPause) { | 1508 FX_BOOL CPDF_ImageLoaderHandle::Continue(IFX_Pause* pPause) { |
1521 FX_BOOL ret; | 1509 FX_BOOL ret = m_pCache ? m_pCache->Continue(pPause) |
1522 if (m_pCache) { | 1510 : m_pImage->GetImage()->Continue(pPause); |
1523 ret = m_pCache->Continue(pPause); | 1511 if (!ret) |
1524 if (!ret) { | 1512 HandleFailure(); |
1525 m_pImageLoader->m_bCached = TRUE; | |
1526 m_pImageLoader->m_pBitmap = | |
1527 m_pCache->GetCurImageCacheEntry()->DetachBitmap(); | |
1528 m_pImageLoader->m_pMask = m_pCache->GetCurImageCacheEntry()->DetachMask(); | |
1529 m_pImageLoader->m_MatteColor = | |
1530 m_pCache->GetCurImageCacheEntry()->m_MatteColor; | |
1531 } | |
1532 } else { | |
1533 ret = m_pImage->m_pImage->Continue(pPause); | |
1534 if (!ret) { | |
1535 m_pImageLoader->m_bCached = FALSE; | |
1536 m_pImageLoader->m_pBitmap = m_pImage->m_pImage->DetachBitmap(); | |
1537 m_pImageLoader->m_pMask = m_pImage->m_pImage->DetachMask(); | |
1538 m_pImageLoader->m_MatteColor = m_pImage->m_pImage->m_MatteColor; | |
1539 } | |
1540 } | |
1541 return ret; | 1513 return ret; |
1542 } | 1514 } |
1543 | 1515 |
| 1516 void CPDF_ImageLoaderHandle::HandleFailure() { |
| 1517 if (m_pCache) { |
| 1518 CPDF_ImageCacheEntry* entry = m_pCache->GetCurImageCacheEntry(); |
| 1519 m_pImageLoader->m_bCached = TRUE; |
| 1520 m_pImageLoader->m_pBitmap = entry->DetachBitmap(); |
| 1521 m_pImageLoader->m_pMask = entry->DetachMask(); |
| 1522 m_pImageLoader->m_MatteColor = entry->m_MatteColor; |
| 1523 } else { |
| 1524 CPDF_Image* pImage = m_pImage->GetImage(); |
| 1525 m_pImageLoader->m_bCached = FALSE; |
| 1526 m_pImageLoader->m_pBitmap = pImage->DetachBitmap(); |
| 1527 m_pImageLoader->m_pMask = pImage->DetachMask(); |
| 1528 m_pImageLoader->m_MatteColor = pImage->m_MatteColor; |
| 1529 } |
| 1530 } |
| 1531 |
1544 FX_BOOL CPDF_ImageLoader::Start( | 1532 FX_BOOL CPDF_ImageLoader::Start( |
1545 const CPDF_ImageObject* pImage, | 1533 const CPDF_ImageObject* pImage, |
1546 CPDF_PageRenderCache* pCache, | 1534 CPDF_PageRenderCache* pCache, |
1547 std::unique_ptr<CPDF_ImageLoaderHandle>* pLoadHandle, | 1535 std::unique_ptr<CPDF_ImageLoaderHandle>* pLoadHandle, |
1548 FX_BOOL bStdCS, | 1536 FX_BOOL bStdCS, |
1549 uint32_t GroupFamily, | 1537 uint32_t GroupFamily, |
1550 FX_BOOL bLoadMask, | 1538 FX_BOOL bLoadMask, |
1551 CPDF_RenderStatus* pRenderStatus, | 1539 CPDF_RenderStatus* pRenderStatus, |
1552 int32_t nDownsampleWidth, | 1540 int32_t nDownsampleWidth, |
1553 int32_t nDownsampleHeight) { | 1541 int32_t nDownsampleHeight) { |
1554 m_nDownsampleWidth = nDownsampleWidth; | 1542 m_nDownsampleWidth = nDownsampleWidth; |
1555 m_nDownsampleHeight = nDownsampleHeight; | 1543 m_nDownsampleHeight = nDownsampleHeight; |
1556 pLoadHandle->reset(new CPDF_ImageLoaderHandle); | 1544 pLoadHandle->reset(new CPDF_ImageLoaderHandle); |
1557 return (*pLoadHandle) | 1545 return (*pLoadHandle) |
1558 ->Start(this, pImage, pCache, bStdCS, GroupFamily, bLoadMask, | 1546 ->Start(this, pImage, pCache, bStdCS, GroupFamily, bLoadMask, |
1559 pRenderStatus, m_nDownsampleWidth, m_nDownsampleHeight); | 1547 pRenderStatus, m_nDownsampleWidth, m_nDownsampleHeight); |
1560 } | 1548 } |
1561 | 1549 |
1562 FX_BOOL CPDF_ImageLoader::Continue(CPDF_ImageLoaderHandle* LoadHandle, | 1550 FX_BOOL CPDF_ImageLoader::Continue(CPDF_ImageLoaderHandle* LoadHandle, |
1563 IFX_Pause* pPause) { | 1551 IFX_Pause* pPause) { |
1564 return LoadHandle->Continue(pPause); | 1552 return LoadHandle->Continue(pPause); |
1565 } | 1553 } |
1566 | 1554 |
1567 CPDF_ImageLoader::~CPDF_ImageLoader() { | 1555 CPDF_ImageLoader::~CPDF_ImageLoader() { |
1568 if (!m_bCached) { | 1556 if (!m_bCached) { |
1569 delete m_pBitmap; | 1557 delete m_pBitmap; |
1570 delete m_pMask; | 1558 delete m_pMask; |
1571 } | 1559 } |
1572 } | 1560 } |
OLD | NEW |