OLD | NEW |
| (Empty) |
1 // Copyright 2014 PDFium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com | |
6 | |
7 #include "core/src/fpdfapi/fpdf_page/pageint.h" | |
8 | |
9 #include "core/include/fpdfapi/cpdf_dictionary.h" | |
10 #include "core/include/fpdfapi/cpdf_document.h" | |
11 #include "core/include/fpdfapi/fpdf_page.h" | |
12 #include "core/include/fpdfapi/fpdf_pageobj.h" | |
13 | |
14 CPDF_ImageObject::CPDF_ImageObject() : m_pImage(nullptr) {} | |
15 | |
16 CPDF_ImageObject::~CPDF_ImageObject() { | |
17 if (!m_pImage) { | |
18 return; | |
19 } | |
20 if (m_pImage->IsInline() || | |
21 (m_pImage->GetStream() && m_pImage->GetStream()->GetObjNum() == 0)) { | |
22 delete m_pImage; | |
23 } else { | |
24 m_pImage->GetDocument()->GetPageData()->ReleaseImage(m_pImage->GetStream()); | |
25 } | |
26 } | |
27 | |
28 CPDF_ImageObject* CPDF_ImageObject::Clone() const { | |
29 CPDF_ImageObject* obj = new CPDF_ImageObject; | |
30 obj->CopyData(this); | |
31 | |
32 obj->m_pImage = m_pImage->Clone(); | |
33 obj->m_Matrix = m_Matrix; | |
34 return obj; | |
35 } | |
36 | |
37 void CPDF_ImageObject::Transform(const CFX_Matrix& matrix) { | |
38 m_Matrix.Concat(matrix); | |
39 CalcBoundingBox(); | |
40 } | |
41 void CPDF_ImageObject::CalcBoundingBox() { | |
42 m_Left = m_Bottom = 0; | |
43 m_Right = m_Top = 1.0f; | |
44 m_Matrix.TransformRect(m_Left, m_Right, m_Top, m_Bottom); | |
45 } | |
46 void CPDF_Image::Release() { | |
47 if (m_bInline || (m_pStream && m_pStream->GetObjNum() == 0)) { | |
48 delete this; | |
49 } | |
50 } | |
51 CPDF_Image* CPDF_Image::Clone() { | |
52 if (m_pStream->GetObjNum()) | |
53 return m_pDocument->GetPageData()->GetImage(m_pStream); | |
54 | |
55 CPDF_Image* pImage = new CPDF_Image(m_pDocument); | |
56 pImage->LoadImageF(ToStream(m_pStream->Clone()), m_bInline); | |
57 if (m_bInline) | |
58 pImage->SetInlineDict(ToDictionary(m_pInlineDict->Clone(TRUE))); | |
59 | |
60 return pImage; | |
61 } | |
62 CPDF_Image::CPDF_Image(CPDF_Document* pDoc) { | |
63 m_pDocument = pDoc; | |
64 m_pStream = NULL; | |
65 m_pOC = NULL; | |
66 m_bInline = FALSE; | |
67 m_pInlineDict = NULL; | |
68 m_pDIBSource = NULL; | |
69 m_pMask = NULL; | |
70 m_MatteColor = 0; | |
71 } | |
72 CPDF_Image::~CPDF_Image() { | |
73 if (m_bInline) { | |
74 if (m_pStream) { | |
75 m_pStream->Release(); | |
76 } | |
77 if (m_pInlineDict) { | |
78 m_pInlineDict->Release(); | |
79 } | |
80 } | |
81 } | |
82 FX_BOOL CPDF_Image::LoadImageF(CPDF_Stream* pStream, FX_BOOL bInline) { | |
83 m_pStream = pStream; | |
84 if (m_bInline && m_pInlineDict) { | |
85 m_pInlineDict->Release(); | |
86 m_pInlineDict = NULL; | |
87 } | |
88 m_bInline = bInline; | |
89 CPDF_Dictionary* pDict = pStream->GetDict(); | |
90 if (m_bInline) { | |
91 m_pInlineDict = ToDictionary(pDict->Clone()); | |
92 } | |
93 m_pOC = pDict->GetDictBy("OC"); | |
94 m_bIsMask = | |
95 !pDict->KeyExist("ColorSpace") || pDict->GetIntegerBy("ImageMask"); | |
96 m_bInterpolate = pDict->GetIntegerBy("Interpolate"); | |
97 m_Height = pDict->GetIntegerBy("Height"); | |
98 m_Width = pDict->GetIntegerBy("Width"); | |
99 return TRUE; | |
100 } | |
OLD | NEW |