| 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 "render_int.h" | 7 #include "render_int.h" |
| 8 | 8 |
| 9 #include <memory> |
| 9 #include <vector> | 10 #include <vector> |
| 10 | 11 |
| 11 #include "core/include/fpdfapi/fpdf_module.h" | 12 #include "core/include/fpdfapi/fpdf_module.h" |
| 12 #include "core/include/fpdfapi/fpdf_pageobj.h" | 13 #include "core/include/fpdfapi/fpdf_pageobj.h" |
| 13 #include "core/include/fpdfapi/fpdf_render.h" | 14 #include "core/include/fpdfapi/fpdf_render.h" |
| 14 #include "core/include/fxcodec/fx_codec.h" | 15 #include "core/include/fxcodec/fx_codec.h" |
| 15 #include "core/include/fxcrt/fx_safe_types.h" | 16 #include "core/include/fxcrt/fx_safe_types.h" |
| 16 #include "core/include/fxge/fx_ge.h" | 17 #include "core/include/fxge/fx_ge.h" |
| 17 #include "core/src/fpdfapi/fpdf_page/pageint.h" | 18 #include "core/src/fpdfapi/fpdf_page/pageint.h" |
| 18 #include "third_party/base/nonstd_unique_ptr.h" | |
| 19 | 19 |
| 20 namespace { | 20 namespace { |
| 21 | 21 |
| 22 unsigned int GetBits8(const uint8_t* pData, uint64_t bitpos, size_t nbits) { | 22 unsigned int GetBits8(const uint8_t* pData, uint64_t bitpos, size_t nbits) { |
| 23 ASSERT(nbits == 1 || nbits == 2 || nbits == 4 || nbits == 8 || nbits == 16); | 23 ASSERT(nbits == 1 || nbits == 2 || nbits == 4 || nbits == 8 || nbits == 16); |
| 24 ASSERT((bitpos & (nbits - 1)) == 0); | 24 ASSERT((bitpos & (nbits - 1)) == 0); |
| 25 unsigned int byte = pData[bitpos / 8]; | 25 unsigned int byte = pData[bitpos / 8]; |
| 26 if (nbits == 8) { | 26 if (nbits == 8) { |
| 27 return byte; | 27 return byte; |
| 28 } | 28 } |
| (...skipping 27 matching lines...) Expand all Loading... |
| 56 pitch += 31; | 56 pitch += 31; |
| 57 pitch /= 32; // quantized to number of 32-bit words. | 57 pitch /= 32; // quantized to number of 32-bit words. |
| 58 pitch *= 4; // and then back to bytes, (not just /8 in one step). | 58 pitch *= 4; // and then back to bytes, (not just /8 in one step). |
| 59 return pitch; | 59 return pitch; |
| 60 } | 60 } |
| 61 | 61 |
| 62 bool IsAllowedBPCValue(int bpc) { | 62 bool IsAllowedBPCValue(int bpc) { |
| 63 return bpc == 1 || bpc == 2 || bpc == 4 || bpc == 8 || bpc == 16; | 63 return bpc == 1 || bpc == 2 || bpc == 4 || bpc == 8 || bpc == 16; |
| 64 } | 64 } |
| 65 | 65 |
| 66 // Wrapper class to use with nonstd::unique_ptr for CJPX_Decoder. | 66 // Wrapper class to use with std::unique_ptr for CJPX_Decoder. |
| 67 class JpxBitMapContext { | 67 class JpxBitMapContext { |
| 68 public: | 68 public: |
| 69 explicit JpxBitMapContext(ICodec_JpxModule* jpx_module) | 69 explicit JpxBitMapContext(ICodec_JpxModule* jpx_module) |
| 70 : jpx_module_(jpx_module), decoder_(nullptr) {} | 70 : jpx_module_(jpx_module), decoder_(nullptr) {} |
| 71 | 71 |
| 72 ~JpxBitMapContext() { | 72 ~JpxBitMapContext() { |
| 73 jpx_module_->DestroyDecoder(decoder_); | 73 jpx_module_->DestroyDecoder(decoder_); |
| 74 } | 74 } |
| 75 | 75 |
| 76 // Takes ownership of |decoder|. | 76 // Takes ownership of |decoder|. |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 192 if (m_pJbig2Context) { | 192 if (m_pJbig2Context) { |
| 193 ICodec_Jbig2Module* pJbig2Module = CPDF_ModuleMgr::Get()->GetJbig2Module(); | 193 ICodec_Jbig2Module* pJbig2Module = CPDF_ModuleMgr::Get()->GetJbig2Module(); |
| 194 pJbig2Module->DestroyJbig2Context(m_pJbig2Context); | 194 pJbig2Module->DestroyJbig2Context(m_pJbig2Context); |
| 195 } | 195 } |
| 196 delete m_pGlobalStream; | 196 delete m_pGlobalStream; |
| 197 } | 197 } |
| 198 CFX_DIBitmap* CPDF_DIBSource::GetBitmap() const { | 198 CFX_DIBitmap* CPDF_DIBSource::GetBitmap() const { |
| 199 return m_pCachedBitmap ? m_pCachedBitmap.get() : Clone(); | 199 return m_pCachedBitmap ? m_pCachedBitmap.get() : Clone(); |
| 200 } | 200 } |
| 201 void CPDF_DIBSource::ReleaseBitmap(CFX_DIBitmap* pBitmap) const { | 201 void CPDF_DIBSource::ReleaseBitmap(CFX_DIBitmap* pBitmap) const { |
| 202 if (pBitmap && pBitmap != m_pCachedBitmap) { | 202 if (pBitmap && pBitmap != m_pCachedBitmap.get()) { |
| 203 delete pBitmap; | 203 delete pBitmap; |
| 204 } | 204 } |
| 205 } | 205 } |
| 206 FX_BOOL CPDF_DIBSource::Load(CPDF_Document* pDoc, | 206 FX_BOOL CPDF_DIBSource::Load(CPDF_Document* pDoc, |
| 207 const CPDF_Stream* pStream, | 207 const CPDF_Stream* pStream, |
| 208 CPDF_DIBSource** ppMask, | 208 CPDF_DIBSource** ppMask, |
| 209 FX_DWORD* pMatteColor, | 209 FX_DWORD* pMatteColor, |
| 210 CPDF_Dictionary* pFormResources, | 210 CPDF_Dictionary* pFormResources, |
| 211 CPDF_Dictionary* pPageResources, | 211 CPDF_Dictionary* pPageResources, |
| 212 FX_BOOL bStdCS, | 212 FX_BOOL bStdCS, |
| (...skipping 462 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 675 if (provided_pitch.ValueOrDie() < requested_pitch.ValueOrDie()) { | 675 if (provided_pitch.ValueOrDie() < requested_pitch.ValueOrDie()) { |
| 676 return 0; | 676 return 0; |
| 677 } | 677 } |
| 678 return 1; | 678 return 1; |
| 679 } | 679 } |
| 680 void CPDF_DIBSource::LoadJpxBitmap() { | 680 void CPDF_DIBSource::LoadJpxBitmap() { |
| 681 ICodec_JpxModule* pJpxModule = CPDF_ModuleMgr::Get()->GetJpxModule(); | 681 ICodec_JpxModule* pJpxModule = CPDF_ModuleMgr::Get()->GetJpxModule(); |
| 682 if (!pJpxModule) | 682 if (!pJpxModule) |
| 683 return; | 683 return; |
| 684 | 684 |
| 685 nonstd::unique_ptr<JpxBitMapContext> context( | 685 std::unique_ptr<JpxBitMapContext> context(new JpxBitMapContext(pJpxModule)); |
| 686 new JpxBitMapContext(pJpxModule)); | |
| 687 context->set_decoder(pJpxModule->CreateDecoder( | 686 context->set_decoder(pJpxModule->CreateDecoder( |
| 688 m_pStreamAcc->GetData(), m_pStreamAcc->GetSize(), m_pColorSpace)); | 687 m_pStreamAcc->GetData(), m_pStreamAcc->GetSize(), m_pColorSpace)); |
| 689 if (!context->decoder()) | 688 if (!context->decoder()) |
| 690 return; | 689 return; |
| 691 | 690 |
| 692 FX_DWORD width = 0; | 691 FX_DWORD width = 0; |
| 693 FX_DWORD height = 0; | 692 FX_DWORD height = 0; |
| 694 FX_DWORD components = 0; | 693 FX_DWORD components = 0; |
| 695 pJpxModule->GetImageInfo(context->decoder(), &width, &height, &components); | 694 pJpxModule->GetImageInfo(context->decoder(), &width, &height, &components); |
| 696 if ((int)width < m_Width || (int)height < m_Height) | 695 if ((int)width < m_Width || (int)height < m_Height) |
| (...skipping 924 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1621 FX_BOOL CPDF_ImageLoader::Continue(CPDF_ImageLoaderHandle* LoadHandle, | 1620 FX_BOOL CPDF_ImageLoader::Continue(CPDF_ImageLoaderHandle* LoadHandle, |
| 1622 IFX_Pause* pPause) { | 1621 IFX_Pause* pPause) { |
| 1623 return LoadHandle->Continue(pPause); | 1622 return LoadHandle->Continue(pPause); |
| 1624 } | 1623 } |
| 1625 CPDF_ImageLoader::~CPDF_ImageLoader() { | 1624 CPDF_ImageLoader::~CPDF_ImageLoader() { |
| 1626 if (!m_bCached) { | 1625 if (!m_bCached) { |
| 1627 delete m_pBitmap; | 1626 delete m_pBitmap; |
| 1628 delete m_pMask; | 1627 delete m_pMask; |
| 1629 } | 1628 } |
| 1630 } | 1629 } |
| OLD | NEW |