| OLD | NEW |
| 1 // Copyright 2016 PDFium Authors. All rights reserved. | 1 // Copyright 2016 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/page/cpdf_image.h" | 7 #include "core/fpdfapi/page/cpdf_image.h" |
| 8 | 8 |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 #include <memory> | |
| 11 #include <utility> | 10 #include <utility> |
| 12 #include <vector> | 11 #include <vector> |
| 13 | 12 |
| 14 #include "core/fpdfapi/cpdf_modulemgr.h" | 13 #include "core/fpdfapi/cpdf_modulemgr.h" |
| 15 #include "core/fpdfapi/page/cpdf_docpagedata.h" | |
| 16 #include "core/fpdfapi/page/cpdf_page.h" | 14 #include "core/fpdfapi/page/cpdf_page.h" |
| 17 #include "core/fpdfapi/parser/cpdf_array.h" | 15 #include "core/fpdfapi/parser/cpdf_array.h" |
| 18 #include "core/fpdfapi/parser/cpdf_boolean.h" | 16 #include "core/fpdfapi/parser/cpdf_boolean.h" |
| 19 #include "core/fpdfapi/parser/cpdf_dictionary.h" | 17 #include "core/fpdfapi/parser/cpdf_dictionary.h" |
| 20 #include "core/fpdfapi/parser/cpdf_document.h" | 18 #include "core/fpdfapi/parser/cpdf_document.h" |
| 21 #include "core/fpdfapi/parser/cpdf_name.h" | 19 #include "core/fpdfapi/parser/cpdf_name.h" |
| 22 #include "core/fpdfapi/parser/cpdf_number.h" | 20 #include "core/fpdfapi/parser/cpdf_number.h" |
| 23 #include "core/fpdfapi/parser/cpdf_reference.h" | 21 #include "core/fpdfapi/parser/cpdf_reference.h" |
| 24 #include "core/fpdfapi/parser/cpdf_string.h" | 22 #include "core/fpdfapi/parser/cpdf_string.h" |
| 25 #include "core/fpdfapi/render/cpdf_pagerendercache.h" | 23 #include "core/fpdfapi/render/cpdf_pagerendercache.h" |
| 26 #include "core/fpdfapi/render/render_int.h" | 24 #include "core/fpdfapi/render/render_int.h" |
| 27 #include "core/fxcodec/fx_codec.h" | 25 #include "core/fxcodec/fx_codec.h" |
| 28 #include "core/fxge/fx_dib.h" | 26 #include "core/fxge/fx_dib.h" |
| 29 | 27 |
| 30 CPDF_Image::CPDF_Image(CPDF_Document* pDoc) : m_pDocument(pDoc) {} | 28 CPDF_Image::CPDF_Image(CPDF_Document* pDoc) : m_pDocument(pDoc) {} |
| 31 | 29 |
| 32 CPDF_Image::CPDF_Image(CPDF_Document* pDoc, | 30 CPDF_Image::CPDF_Image(CPDF_Document* pDoc, |
| 33 std::unique_ptr<CPDF_Stream> pStream) | 31 std::unique_ptr<CPDF_Stream> pStream) |
| 34 : m_pDocument(pDoc), | 32 : m_bIsInline(true), |
| 33 m_pDocument(pDoc), |
| 35 m_pStream(pStream.get()), | 34 m_pStream(pStream.get()), |
| 36 m_pOwnedStream(std::move(pStream)) { | 35 m_pOwnedStream(std::move(pStream)) { |
| 37 m_pOwnedDict = | 36 m_pOwnedDict = |
| 38 ToDictionary(std::unique_ptr<CPDF_Object>(m_pStream->GetDict()->Clone())); | 37 ToDictionary(std::unique_ptr<CPDF_Object>(m_pStream->GetDict()->Clone())); |
| 39 m_pDict = m_pOwnedDict.get(); | 38 m_pDict = m_pOwnedDict.get(); |
| 40 FinishInitialization(); | 39 FinishInitialization(); |
| 41 } | 40 } |
| 42 | 41 |
| 43 CPDF_Image::CPDF_Image(CPDF_Document* pDoc, uint32_t dwStreamObjNum) | 42 CPDF_Image::CPDF_Image(CPDF_Document* pDoc, uint32_t dwStreamObjNum) |
| 44 : m_pDocument(pDoc), | 43 : m_pDocument(pDoc), |
| 45 m_pStream(ToStream(pDoc->GetIndirectObject(dwStreamObjNum))) { | 44 m_pStream(ToStream(pDoc->GetIndirectObject(dwStreamObjNum))) { |
| 46 m_pDict = m_pStream->GetDict(); | 45 m_pDict = m_pStream->GetDict(); |
| 47 FinishInitialization(); | 46 FinishInitialization(); |
| 48 } | 47 } |
| 49 | 48 |
| 50 CPDF_Image::~CPDF_Image() {} | 49 CPDF_Image::~CPDF_Image() {} |
| 51 | 50 |
| 52 void CPDF_Image::FinishInitialization() { | 51 void CPDF_Image::FinishInitialization() { |
| 53 m_pOC = m_pDict->GetDictFor("OC"); | 52 m_pOC = m_pDict->GetDictFor("OC"); |
| 54 m_bIsMask = | 53 m_bIsMask = |
| 55 !m_pDict->KeyExist("ColorSpace") || m_pDict->GetIntegerFor("ImageMask"); | 54 !m_pDict->KeyExist("ColorSpace") || m_pDict->GetIntegerFor("ImageMask"); |
| 56 m_bInterpolate = !!m_pDict->GetIntegerFor("Interpolate"); | 55 m_bInterpolate = !!m_pDict->GetIntegerFor("Interpolate"); |
| 57 m_Height = m_pDict->GetIntegerFor("Height"); | 56 m_Height = m_pDict->GetIntegerFor("Height"); |
| 58 m_Width = m_pDict->GetIntegerFor("Width"); | 57 m_Width = m_pDict->GetIntegerFor("Width"); |
| 59 } | 58 } |
| 60 | 59 |
| 61 CPDF_Image* CPDF_Image::Clone() { | 60 CPDF_Image* CPDF_Image::Clone() { |
| 62 CPDF_Image* pImage = new CPDF_Image(m_pDocument); | 61 CPDF_Image* pImage = new CPDF_Image(m_pDocument); |
| 62 pImage->m_bIsInline = m_bIsInline; |
| 63 if (m_pOwnedStream) { | 63 if (m_pOwnedStream) { |
| 64 pImage->m_pOwnedStream = | 64 pImage->m_pOwnedStream = ToStream(m_pOwnedStream->Clone()); |
| 65 ToStream(std::unique_ptr<CPDF_Object>(m_pOwnedStream->Clone())); | |
| 66 pImage->m_pStream = pImage->m_pOwnedStream.get(); | 65 pImage->m_pStream = pImage->m_pOwnedStream.get(); |
| 67 } else { | 66 } else { |
| 68 pImage->m_pStream = m_pStream; | 67 pImage->m_pStream = m_pStream; |
| 69 } | 68 } |
| 70 if (m_pOwnedDict) { | 69 if (m_pOwnedDict) { |
| 71 pImage->m_pOwnedDict = | 70 pImage->m_pOwnedDict = ToDictionary(m_pOwnedDict->Clone()); |
| 72 ToDictionary(std::unique_ptr<CPDF_Object>(m_pOwnedDict->Clone())); | |
| 73 pImage->m_pDict = pImage->m_pOwnedDict.get(); | 71 pImage->m_pDict = pImage->m_pOwnedDict.get(); |
| 74 } else { | 72 } else { |
| 75 pImage->m_pDict = m_pDict; | 73 pImage->m_pDict = m_pDict; |
| 76 } | 74 } |
| 77 return pImage; | 75 return pImage; |
| 78 } | 76 } |
| 79 | 77 |
| 80 void CPDF_Image::ConvertStreamToIndirectObject() { | 78 void CPDF_Image::ConvertStreamToIndirectObject() { |
| 81 if (!m_pStream->IsInline()) | 79 if (!m_pStream->IsInline()) |
| 82 return; | 80 return; |
| (...skipping 327 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 410 } | 408 } |
| 411 if (!ret) { | 409 if (!ret) { |
| 412 delete m_pDIBSource; | 410 delete m_pDIBSource; |
| 413 m_pDIBSource = nullptr; | 411 m_pDIBSource = nullptr; |
| 414 return false; | 412 return false; |
| 415 } | 413 } |
| 416 m_pMask = pSource->DetachMask(); | 414 m_pMask = pSource->DetachMask(); |
| 417 m_MatteColor = pSource->GetMatteColor(); | 415 m_MatteColor = pSource->GetMatteColor(); |
| 418 return false; | 416 return false; |
| 419 } | 417 } |
| OLD | NEW |