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/fpdf_page/include/cpdf_imageobject.h" | 7 #include "core/fpdfapi/fpdf_page/include/cpdf_imageobject.h" |
8 | 8 |
9 #include "core/fpdfapi/fpdf_page/include/cpdf_image.h" | 9 #include "core/fpdfapi/fpdf_page/include/cpdf_image.h" |
10 #include "core/fpdfapi/fpdf_page/pageint.h" | 10 #include "core/fpdfapi/fpdf_page/pageint.h" |
11 #include "core/fpdfapi/fpdf_parser/include/cpdf_document.h" | 11 #include "core/fpdfapi/fpdf_parser/include/cpdf_document.h" |
12 | 12 |
13 CPDF_ImageObject::CPDF_ImageObject() : m_pImage(nullptr) {} | 13 CPDF_ImageObject::CPDF_ImageObject() : m_pImage(nullptr) {} |
14 | 14 |
15 CPDF_ImageObject::~CPDF_ImageObject() { | 15 CPDF_ImageObject::~CPDF_ImageObject() { |
16 if (!m_pImage) { | 16 if (!m_pImage) |
| 17 return; |
| 18 |
| 19 if (m_pImage->CanRelease()) { |
| 20 m_pImage->Release(); |
17 return; | 21 return; |
18 } | 22 } |
19 if (m_pImage->IsInline() || | 23 |
20 (m_pImage->GetStream() && m_pImage->GetStream()->GetObjNum() == 0)) { | 24 CPDF_DocPageData* pPageData = m_pImage->GetDocument()->GetPageData(); |
21 delete m_pImage; | 25 const CPDF_Object* pImageStream = m_pImage->GetStream(); |
22 } else { | 26 if (pPageData->HasImage(pImageStream)) { |
23 m_pImage->GetDocument()->GetPageData()->ReleaseImage(m_pImage->GetStream()); | 27 pPageData->ReleaseImage(pImageStream); |
| 28 return; |
24 } | 29 } |
| 30 |
| 31 delete m_pImage; |
25 } | 32 } |
26 | 33 |
27 CPDF_ImageObject* CPDF_ImageObject::Clone() const { | 34 CPDF_ImageObject* CPDF_ImageObject::Clone() const { |
28 CPDF_ImageObject* obj = new CPDF_ImageObject; | 35 CPDF_ImageObject* obj = new CPDF_ImageObject; |
29 obj->CopyData(this); | 36 obj->CopyData(this); |
30 | 37 |
31 obj->m_pImage = m_pImage->Clone(); | 38 obj->m_pImage = m_pImage->Clone(); |
32 obj->m_Matrix = m_Matrix; | 39 obj->m_Matrix = m_Matrix; |
33 return obj; | 40 return obj; |
34 } | 41 } |
(...skipping 17 matching lines...) Expand all Loading... |
52 | 59 |
53 const CPDF_ImageObject* CPDF_ImageObject::AsImage() const { | 60 const CPDF_ImageObject* CPDF_ImageObject::AsImage() const { |
54 return this; | 61 return this; |
55 } | 62 } |
56 | 63 |
57 void CPDF_ImageObject::CalcBoundingBox() { | 64 void CPDF_ImageObject::CalcBoundingBox() { |
58 m_Left = m_Bottom = 0; | 65 m_Left = m_Bottom = 0; |
59 m_Right = m_Top = 1.0f; | 66 m_Right = m_Top = 1.0f; |
60 m_Matrix.TransformRect(m_Left, m_Right, m_Top, m_Bottom); | 67 m_Matrix.TransformRect(m_Left, m_Right, m_Top, m_Bottom); |
61 } | 68 } |
OLD | NEW |