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 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
63 template <typename T> | 63 template <typename T> |
64 T ClampValue(T value, T max_value) { | 64 T ClampValue(T value, T max_value) { |
65 value = std::min(value, max_value); | 65 value = std::min(value, max_value); |
66 value = std::max<T>(0, value); | 66 value = std::max<T>(0, value); |
67 return value; | 67 return value; |
68 } | 68 } |
69 | 69 |
70 // Wrapper class to use with std::unique_ptr for CJPX_Decoder. | 70 // Wrapper class to use with std::unique_ptr for CJPX_Decoder. |
71 class JpxBitMapContext { | 71 class JpxBitMapContext { |
72 public: | 72 public: |
73 explicit JpxBitMapContext(ICodec_JpxModule* jpx_module) | 73 explicit JpxBitMapContext(CCodec_JpxModule* jpx_module) |
74 : jpx_module_(jpx_module), decoder_(nullptr) {} | 74 : jpx_module_(jpx_module), decoder_(nullptr) {} |
75 | 75 |
76 ~JpxBitMapContext() { jpx_module_->DestroyDecoder(decoder_); } | 76 ~JpxBitMapContext() { jpx_module_->DestroyDecoder(decoder_); } |
77 | 77 |
78 // Takes ownership of |decoder|. | 78 // Takes ownership of |decoder|. |
79 void set_decoder(CJPX_Decoder* decoder) { decoder_ = decoder; } | 79 void set_decoder(CJPX_Decoder* decoder) { decoder_ = decoder; } |
80 | 80 |
81 CJPX_Decoder* decoder() { return decoder_; } | 81 CJPX_Decoder* decoder() { return decoder_; } |
82 | 82 |
83 private: | 83 private: |
84 ICodec_JpxModule* const jpx_module_; // Weak pointer. | 84 CCodec_JpxModule* const jpx_module_; // Weak pointer. |
85 CJPX_Decoder* decoder_; // Decoder, owned. | 85 CJPX_Decoder* decoder_; // Decoder, owned. |
86 | 86 |
87 // Disallow evil constructors | 87 // Disallow evil constructors |
88 JpxBitMapContext(const JpxBitMapContext&); | 88 JpxBitMapContext(const JpxBitMapContext&); |
89 void operator=(const JpxBitMapContext&); | 89 void operator=(const JpxBitMapContext&); |
90 }; | 90 }; |
91 | 91 |
92 const int kMaxImageDimension = 0x01FFFF; | 92 const int kMaxImageDimension = 0x01FFFF; |
93 | 93 |
94 } // namespace | 94 } // namespace |
(...skipping 27 matching lines...) Expand all Loading... |
122 CPDF_DIBSource::~CPDF_DIBSource() { | 122 CPDF_DIBSource::~CPDF_DIBSource() { |
123 FX_Free(m_pMaskedLine); | 123 FX_Free(m_pMaskedLine); |
124 FX_Free(m_pLineBuf); | 124 FX_Free(m_pLineBuf); |
125 m_pCachedBitmap.reset(); | 125 m_pCachedBitmap.reset(); |
126 FX_Free(m_pCompData); | 126 FX_Free(m_pCompData); |
127 CPDF_ColorSpace* pCS = m_pColorSpace; | 127 CPDF_ColorSpace* pCS = m_pColorSpace; |
128 if (pCS && m_pDocument) { | 128 if (pCS && m_pDocument) { |
129 m_pDocument->GetPageData()->ReleaseColorSpace(pCS->GetArray()); | 129 m_pDocument->GetPageData()->ReleaseColorSpace(pCS->GetArray()); |
130 } | 130 } |
131 if (m_pJbig2Context) { | 131 if (m_pJbig2Context) { |
132 ICodec_Jbig2Module* pJbig2Module = CPDF_ModuleMgr::Get()->GetJbig2Module(); | 132 CCodec_Jbig2Module* pJbig2Module = CPDF_ModuleMgr::Get()->GetJbig2Module(); |
133 pJbig2Module->DestroyJbig2Context(m_pJbig2Context); | 133 pJbig2Module->DestroyJbig2Context(m_pJbig2Context); |
134 } | 134 } |
135 } | 135 } |
136 | 136 |
137 CFX_DIBitmap* CPDF_DIBSource::GetBitmap() const { | 137 CFX_DIBitmap* CPDF_DIBSource::GetBitmap() const { |
138 return m_pCachedBitmap ? m_pCachedBitmap.get() : Clone(); | 138 return m_pCachedBitmap ? m_pCachedBitmap.get() : Clone(); |
139 } | 139 } |
140 | 140 |
141 void CPDF_DIBSource::ReleaseBitmap(CFX_DIBitmap* pBitmap) const { | 141 void CPDF_DIBSource::ReleaseBitmap(CFX_DIBitmap* pBitmap) const { |
142 if (pBitmap && pBitmap != m_pCachedBitmap.get()) { | 142 if (pBitmap && pBitmap != m_pCachedBitmap.get()) { |
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
337 return ret; | 337 return ret; |
338 } | 338 } |
339 | 339 |
340 int CPDF_DIBSource::ContinueLoadDIBSource(IFX_Pause* pPause) { | 340 int CPDF_DIBSource::ContinueLoadDIBSource(IFX_Pause* pPause) { |
341 FXCODEC_STATUS ret; | 341 FXCODEC_STATUS ret; |
342 if (m_Status == 1) { | 342 if (m_Status == 1) { |
343 const CFX_ByteString& decoder = m_pStreamAcc->GetImageDecoder(); | 343 const CFX_ByteString& decoder = m_pStreamAcc->GetImageDecoder(); |
344 if (decoder == "JPXDecode") { | 344 if (decoder == "JPXDecode") { |
345 return 0; | 345 return 0; |
346 } | 346 } |
347 ICodec_Jbig2Module* pJbig2Module = CPDF_ModuleMgr::Get()->GetJbig2Module(); | 347 CCodec_Jbig2Module* pJbig2Module = CPDF_ModuleMgr::Get()->GetJbig2Module(); |
348 if (!m_pJbig2Context) { | 348 if (!m_pJbig2Context) { |
349 m_pJbig2Context = pJbig2Module->CreateJbig2Context(); | 349 m_pJbig2Context = pJbig2Module->CreateJbig2Context(); |
350 if (m_pStreamAcc->GetImageParam()) { | 350 if (m_pStreamAcc->GetImageParam()) { |
351 CPDF_Stream* pGlobals = | 351 CPDF_Stream* pGlobals = |
352 m_pStreamAcc->GetImageParam()->GetStreamBy("JBIG2Globals"); | 352 m_pStreamAcc->GetImageParam()->GetStreamBy("JBIG2Globals"); |
353 if (pGlobals) { | 353 if (pGlobals) { |
354 m_pGlobalStream.reset(new CPDF_StreamAcc); | 354 m_pGlobalStream.reset(new CPDF_StreamAcc); |
355 m_pGlobalStream->LoadAllData(pGlobals, FALSE); | 355 m_pGlobalStream->LoadAllData(pGlobals, FALSE); |
356 } | 356 } |
357 } | 357 } |
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
520 pCompData[i].m_ColorKeyMin = std::max(min_num, 0); | 520 pCompData[i].m_ColorKeyMin = std::max(min_num, 0); |
521 pCompData[i].m_ColorKeyMax = std::min(max_num, max_data); | 521 pCompData[i].m_ColorKeyMax = std::min(max_num, max_data); |
522 } | 522 } |
523 } | 523 } |
524 bColorKey = TRUE; | 524 bColorKey = TRUE; |
525 } | 525 } |
526 } | 526 } |
527 return pCompData; | 527 return pCompData; |
528 } | 528 } |
529 | 529 |
530 ICodec_ScanlineDecoder* FPDFAPI_CreateFaxDecoder( | 530 CCodec_ScanlineDecoder* FPDFAPI_CreateFaxDecoder( |
531 const uint8_t* src_buf, | 531 const uint8_t* src_buf, |
532 uint32_t src_size, | 532 uint32_t src_size, |
533 int width, | 533 int width, |
534 int height, | 534 int height, |
535 const CPDF_Dictionary* pParams); | 535 const CPDF_Dictionary* pParams); |
536 | 536 |
537 ICodec_ScanlineDecoder* FPDFAPI_CreateFlateDecoder( | 537 CCodec_ScanlineDecoder* FPDFAPI_CreateFlateDecoder( |
538 const uint8_t* src_buf, | 538 const uint8_t* src_buf, |
539 uint32_t src_size, | 539 uint32_t src_size, |
540 int width, | 540 int width, |
541 int height, | 541 int height, |
542 int nComps, | 542 int nComps, |
543 int bpc, | 543 int bpc, |
544 const CPDF_Dictionary* pParams); | 544 const CPDF_Dictionary* pParams); |
545 | 545 |
546 int CPDF_DIBSource::CreateDecoder() { | 546 int CPDF_DIBSource::CreateDecoder() { |
547 const CFX_ByteString& decoder = m_pStreamAcc->GetImageDecoder(); | 547 const CFX_ByteString& decoder = m_pStreamAcc->GetImageDecoder(); |
(...skipping 10 matching lines...) Expand all Loading... |
558 m_pDecoder.reset(FPDFAPI_CreateFaxDecoder(src_data, src_size, m_Width, | 558 m_pDecoder.reset(FPDFAPI_CreateFaxDecoder(src_data, src_size, m_Width, |
559 m_Height, pParams)); | 559 m_Height, pParams)); |
560 } else if (decoder == "DCTDecode") { | 560 } else if (decoder == "DCTDecode") { |
561 m_pDecoder.reset(CPDF_ModuleMgr::Get()->GetJpegModule()->CreateDecoder( | 561 m_pDecoder.reset(CPDF_ModuleMgr::Get()->GetJpegModule()->CreateDecoder( |
562 src_data, src_size, m_Width, m_Height, m_nComponents, | 562 src_data, src_size, m_Width, m_Height, m_nComponents, |
563 pParams ? pParams->GetIntegerBy("ColorTransform", 1) : 1)); | 563 pParams ? pParams->GetIntegerBy("ColorTransform", 1) : 1)); |
564 if (!m_pDecoder) { | 564 if (!m_pDecoder) { |
565 FX_BOOL bTransform = FALSE; | 565 FX_BOOL bTransform = FALSE; |
566 int comps; | 566 int comps; |
567 int bpc; | 567 int bpc; |
568 ICodec_JpegModule* pJpegModule = CPDF_ModuleMgr::Get()->GetJpegModule(); | 568 CCodec_JpegModule* pJpegModule = CPDF_ModuleMgr::Get()->GetJpegModule(); |
569 if (pJpegModule->LoadInfo(src_data, src_size, m_Width, m_Height, comps, | 569 if (pJpegModule->LoadInfo(src_data, src_size, m_Width, m_Height, comps, |
570 bpc, bTransform)) { | 570 bpc, bTransform)) { |
571 if (m_nComponents != static_cast<uint32_t>(comps)) { | 571 if (m_nComponents != static_cast<uint32_t>(comps)) { |
572 FX_Free(m_pCompData); | 572 FX_Free(m_pCompData); |
573 m_nComponents = static_cast<uint32_t>(comps); | 573 m_nComponents = static_cast<uint32_t>(comps); |
574 if (m_Family == PDFCS_LAB && m_nComponents != 3) { | 574 if (m_Family == PDFCS_LAB && m_nComponents != 3) { |
575 m_pCompData = nullptr; | 575 m_pCompData = nullptr; |
576 return 0; | 576 return 0; |
577 } | 577 } |
578 m_pCompData = GetDecodeAndMaskArray(m_bDefaultDecode, m_bColorKey); | 578 m_pCompData = GetDecodeAndMaskArray(m_bDefaultDecode, m_bColorKey); |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
621 if (!provided_pitch.IsValid()) { | 621 if (!provided_pitch.IsValid()) { |
622 return 0; | 622 return 0; |
623 } | 623 } |
624 if (provided_pitch.ValueOrDie() < requested_pitch.ValueOrDie()) { | 624 if (provided_pitch.ValueOrDie() < requested_pitch.ValueOrDie()) { |
625 return 0; | 625 return 0; |
626 } | 626 } |
627 return 1; | 627 return 1; |
628 } | 628 } |
629 | 629 |
630 void CPDF_DIBSource::LoadJpxBitmap() { | 630 void CPDF_DIBSource::LoadJpxBitmap() { |
631 ICodec_JpxModule* pJpxModule = CPDF_ModuleMgr::Get()->GetJpxModule(); | 631 CCodec_JpxModule* pJpxModule = CPDF_ModuleMgr::Get()->GetJpxModule(); |
632 if (!pJpxModule) | 632 if (!pJpxModule) |
633 return; | 633 return; |
634 | 634 |
635 std::unique_ptr<JpxBitMapContext> context(new JpxBitMapContext(pJpxModule)); | 635 std::unique_ptr<JpxBitMapContext> context(new JpxBitMapContext(pJpxModule)); |
636 context->set_decoder(pJpxModule->CreateDecoder( | 636 context->set_decoder(pJpxModule->CreateDecoder( |
637 m_pStreamAcc->GetData(), m_pStreamAcc->GetSize(), m_pColorSpace)); | 637 m_pStreamAcc->GetData(), m_pStreamAcc->GetSize(), m_pColorSpace)); |
638 if (!context->decoder()) | 638 if (!context->decoder()) |
639 return; | 639 return; |
640 | 640 |
641 uint32_t width = 0; | 641 uint32_t width = 0; |
(...skipping 926 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1568 IFX_Pause* pPause) { | 1568 IFX_Pause* pPause) { |
1569 return LoadHandle->Continue(pPause); | 1569 return LoadHandle->Continue(pPause); |
1570 } | 1570 } |
1571 | 1571 |
1572 CPDF_ImageLoader::~CPDF_ImageLoader() { | 1572 CPDF_ImageLoader::~CPDF_ImageLoader() { |
1573 if (!m_bCached) { | 1573 if (!m_bCached) { |
1574 delete m_pBitmap; | 1574 delete m_pBitmap; |
1575 delete m_pMask; | 1575 delete m_pMask; |
1576 } | 1576 } |
1577 } | 1577 } |
OLD | NEW |