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) { | 1498 if (!ret) |
1499 m_pImageLoader->m_bCached = TRUE; | 1499 HandleFailureWithCache(); |
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 { | 1500 } else { |
1507 ret = pImage->m_pImage->StartLoadDIBSource(pRenderStatus->m_pFormResource, | 1501 ret = m_pImage->GetImage()->StartLoadDIBSource( |
1508 pRenderStatus->m_pPageResource, | 1502 pRenderStatus->m_pFormResource, pRenderStatus->m_pPageResource, bStdCS, |
1509 bStdCS, GroupFamily, bLoadMask); | 1503 GroupFamily, bLoadMask); |
1510 if (!ret) { | 1504 if (!ret) |
1511 m_pImageLoader->m_bCached = FALSE; | 1505 HandleFailureWithoutCache(); |
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 } | 1506 } |
1517 return ret; | 1507 return ret; |
1518 } | 1508 } |
1519 | 1509 |
1520 FX_BOOL CPDF_ImageLoaderHandle::Continue(IFX_Pause* pPause) { | 1510 FX_BOOL CPDF_ImageLoaderHandle::Continue(IFX_Pause* pPause) { |
1521 FX_BOOL ret; | 1511 FX_BOOL ret; |
1522 if (m_pCache) { | 1512 if (m_pCache) { |
1523 ret = m_pCache->Continue(pPause); | 1513 ret = m_pCache->Continue(pPause); |
1524 if (!ret) { | 1514 if (!ret) |
1525 m_pImageLoader->m_bCached = TRUE; | 1515 HandleFailureWithCache(); |
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 { | 1516 } else { |
1533 ret = m_pImage->m_pImage->Continue(pPause); | 1517 ret = m_pImage->GetImage()->Continue(pPause); |
1534 if (!ret) { | 1518 if (!ret) |
1535 m_pImageLoader->m_bCached = FALSE; | 1519 HandleFailureWithoutCache(); |
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 } | 1520 } |
1541 return ret; | 1521 return ret; |
1542 } | 1522 } |
1543 | 1523 |
1524 void CPDF_ImageLoaderHandle::HandleFailureWithCache() { | |
Wei Li
2016/08/05 22:58:21
Use HandleFailure(bool cached) to reduce to one fu
Lei Zhang
2016/08/06 05:34:25
Done.
| |
1525 m_pImageLoader->m_bCached = TRUE; | |
1526 m_pImageLoader->m_pBitmap = m_pCache->GetCurImageCacheEntry()->DetachBitmap(); | |
1527 m_pImageLoader->m_pMask = m_pCache->GetCurImageCacheEntry()->DetachMask(); | |
1528 m_pImageLoader->m_MatteColor = | |
1529 m_pCache->GetCurImageCacheEntry()->m_MatteColor; | |
1530 } | |
1531 | |
1532 void CPDF_ImageLoaderHandle::HandleFailureWithoutCache() { | |
1533 CPDF_Image* pImage = m_pImage->GetImage(); | |
1534 m_pImageLoader->m_bCached = FALSE; | |
1535 m_pImageLoader->m_pBitmap = pImage->DetachBitmap(); | |
1536 m_pImageLoader->m_pMask = pImage->DetachMask(); | |
1537 m_pImageLoader->m_MatteColor = pImage->m_MatteColor; | |
1538 } | |
1539 | |
1544 FX_BOOL CPDF_ImageLoader::Start( | 1540 FX_BOOL CPDF_ImageLoader::Start( |
1545 const CPDF_ImageObject* pImage, | 1541 const CPDF_ImageObject* pImage, |
1546 CPDF_PageRenderCache* pCache, | 1542 CPDF_PageRenderCache* pCache, |
1547 std::unique_ptr<CPDF_ImageLoaderHandle>* pLoadHandle, | 1543 std::unique_ptr<CPDF_ImageLoaderHandle>* pLoadHandle, |
1548 FX_BOOL bStdCS, | 1544 FX_BOOL bStdCS, |
1549 uint32_t GroupFamily, | 1545 uint32_t GroupFamily, |
1550 FX_BOOL bLoadMask, | 1546 FX_BOOL bLoadMask, |
1551 CPDF_RenderStatus* pRenderStatus, | 1547 CPDF_RenderStatus* pRenderStatus, |
1552 int32_t nDownsampleWidth, | 1548 int32_t nDownsampleWidth, |
1553 int32_t nDownsampleHeight) { | 1549 int32_t nDownsampleHeight) { |
1554 m_nDownsampleWidth = nDownsampleWidth; | 1550 m_nDownsampleWidth = nDownsampleWidth; |
1555 m_nDownsampleHeight = nDownsampleHeight; | 1551 m_nDownsampleHeight = nDownsampleHeight; |
1556 pLoadHandle->reset(new CPDF_ImageLoaderHandle); | 1552 pLoadHandle->reset(new CPDF_ImageLoaderHandle); |
1557 return (*pLoadHandle) | 1553 return (*pLoadHandle) |
1558 ->Start(this, pImage, pCache, bStdCS, GroupFamily, bLoadMask, | 1554 ->Start(this, pImage, pCache, bStdCS, GroupFamily, bLoadMask, |
1559 pRenderStatus, m_nDownsampleWidth, m_nDownsampleHeight); | 1555 pRenderStatus, m_nDownsampleWidth, m_nDownsampleHeight); |
1560 } | 1556 } |
1561 | 1557 |
1562 FX_BOOL CPDF_ImageLoader::Continue(CPDF_ImageLoaderHandle* LoadHandle, | 1558 FX_BOOL CPDF_ImageLoader::Continue(CPDF_ImageLoaderHandle* LoadHandle, |
1563 IFX_Pause* pPause) { | 1559 IFX_Pause* pPause) { |
1564 return LoadHandle->Continue(pPause); | 1560 return LoadHandle->Continue(pPause); |
1565 } | 1561 } |
1566 | 1562 |
1567 CPDF_ImageLoader::~CPDF_ImageLoader() { | 1563 CPDF_ImageLoader::~CPDF_ImageLoader() { |
1568 if (!m_bCached) { | 1564 if (!m_bCached) { |
1569 delete m_pBitmap; | 1565 delete m_pBitmap; |
1570 delete m_pMask; | 1566 delete m_pMask; |
1571 } | 1567 } |
1572 } | 1568 } |
OLD | NEW |