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_image.h" | 7 #include "core/fpdfapi/fpdf_page/include/cpdf_image.h" |
8 | 8 |
| 9 #include <memory> |
| 10 |
9 #include "core/fpdfapi/fpdf_page/include/cpdf_page.h" | 11 #include "core/fpdfapi/fpdf_page/include/cpdf_page.h" |
10 #include "core/fpdfapi/fpdf_page/pageint.h" | 12 #include "core/fpdfapi/fpdf_page/pageint.h" |
11 #include "core/fpdfapi/fpdf_parser/cpdf_boolean.h" | 13 #include "core/fpdfapi/fpdf_parser/cpdf_boolean.h" |
12 #include "core/fpdfapi/fpdf_parser/include/cpdf_array.h" | 14 #include "core/fpdfapi/fpdf_parser/include/cpdf_array.h" |
13 #include "core/fpdfapi/fpdf_parser/include/cpdf_document.h" | 15 #include "core/fpdfapi/fpdf_parser/include/cpdf_document.h" |
14 #include "core/fpdfapi/fpdf_parser/include/cpdf_string.h" | 16 #include "core/fpdfapi/fpdf_parser/include/cpdf_string.h" |
15 #include "core/fpdfapi/fpdf_render/cpdf_pagerendercache.h" | 17 #include "core/fpdfapi/fpdf_render/cpdf_pagerendercache.h" |
16 #include "core/fpdfapi/fpdf_render/render_int.h" | 18 #include "core/fpdfapi/fpdf_render/render_int.h" |
17 #include "core/fpdfapi/include/cpdf_modulemgr.h" | 19 #include "core/fpdfapi/include/cpdf_modulemgr.h" |
18 #include "core/fxcodec/include/fx_codec.h" | 20 #include "core/fxcodec/include/fx_codec.h" |
19 #include "core/fxge/include/fx_dib.h" | 21 #include "core/fxge/include/fx_dib.h" |
20 | 22 |
21 CPDF_Image::CPDF_Image(CPDF_Document* pDoc) | 23 CPDF_Image::CPDF_Image(CPDF_Document* pDoc) |
22 : m_pDIBSource(nullptr), | 24 : m_pDIBSource(nullptr), |
23 m_pMask(nullptr), | 25 m_pMask(nullptr), |
24 m_MatteColor(0), | 26 m_MatteColor(0), |
25 m_pStream(nullptr), | 27 m_pStream(nullptr), |
26 m_bInline(FALSE), | 28 m_bInline(false), |
27 m_pInlineDict(nullptr), | 29 m_pInlineDict(nullptr), |
| 30 m_Height(0), |
| 31 m_Width(0), |
| 32 m_bIsMask(false), |
| 33 m_bInterpolate(false), |
28 m_pDocument(pDoc), | 34 m_pDocument(pDoc), |
29 m_pOC(nullptr) {} | 35 m_pOC(nullptr) {} |
30 | 36 |
31 CPDF_Image::~CPDF_Image() { | 37 CPDF_Image::~CPDF_Image() { |
32 if (m_bInline) { | 38 if (m_bInline) { |
33 if (m_pStream) | 39 if (m_pStream) |
34 m_pStream->Release(); | 40 m_pStream->Release(); |
35 if (m_pInlineDict) | 41 if (m_pInlineDict) |
36 m_pInlineDict->Release(); | 42 m_pInlineDict->Release(); |
37 } | 43 } |
38 } | 44 } |
39 | 45 |
| 46 bool CPDF_Image::CanRelease() const { |
| 47 return m_bInline || (m_pStream && m_pStream->GetObjNum() == 0); |
| 48 } |
| 49 |
40 void CPDF_Image::Release() { | 50 void CPDF_Image::Release() { |
41 if (m_bInline || (m_pStream && m_pStream->GetObjNum() == 0)) | 51 if (CanRelease()) |
42 delete this; | 52 delete this; |
43 } | 53 } |
44 | 54 |
45 CPDF_Image* CPDF_Image::Clone() { | 55 CPDF_Image* CPDF_Image::Clone() { |
46 if (m_pStream->GetObjNum()) | 56 if (m_pStream->GetObjNum()) |
47 return m_pDocument->GetPageData()->GetImage(m_pStream); | 57 return m_pDocument->GetPageData()->GetImage(m_pStream); |
48 | 58 |
49 CPDF_Image* pImage = new CPDF_Image(m_pDocument); | 59 CPDF_Image* pImage = new CPDF_Image(m_pDocument); |
50 pImage->LoadImageF(ToStream(m_pStream->Clone()), m_bInline); | 60 pImage->LoadImageF(ToStream(m_pStream->Clone()), m_bInline); |
51 if (m_bInline) | 61 if (m_bInline) |
52 pImage->SetInlineDict(ToDictionary(m_pInlineDict->Clone(TRUE))); | 62 pImage->SetInlineDict(ToDictionary(m_pInlineDict->Clone(TRUE))); |
53 | 63 |
54 return pImage; | 64 return pImage; |
55 } | 65 } |
56 | 66 |
57 FX_BOOL CPDF_Image::LoadImageF(CPDF_Stream* pStream, FX_BOOL bInline) { | 67 void CPDF_Image::LoadImageF(CPDF_Stream* pStream, bool bInline) { |
58 m_pStream = pStream; | 68 m_pStream = pStream; |
59 if (m_bInline && m_pInlineDict) { | 69 if (m_bInline && m_pInlineDict) { |
60 m_pInlineDict->Release(); | 70 m_pInlineDict->Release(); |
61 m_pInlineDict = nullptr; | 71 m_pInlineDict = nullptr; |
62 } | 72 } |
63 m_bInline = bInline; | 73 m_bInline = bInline; |
64 CPDF_Dictionary* pDict = pStream->GetDict(); | 74 CPDF_Dictionary* pDict = pStream->GetDict(); |
65 if (m_bInline) { | 75 if (m_bInline) |
66 m_pInlineDict = ToDictionary(pDict->Clone()); | 76 m_pInlineDict = ToDictionary(pDict->Clone()); |
67 } | 77 |
68 m_pOC = pDict->GetDictBy("OC"); | 78 m_pOC = pDict->GetDictBy("OC"); |
69 m_bIsMask = | 79 m_bIsMask = |
70 !pDict->KeyExist("ColorSpace") || pDict->GetIntegerBy("ImageMask"); | 80 !pDict->KeyExist("ColorSpace") || pDict->GetIntegerBy("ImageMask"); |
71 m_bInterpolate = pDict->GetIntegerBy("Interpolate"); | 81 m_bInterpolate = pDict->GetIntegerBy("Interpolate"); |
72 m_Height = pDict->GetIntegerBy("Height"); | 82 m_Height = pDict->GetIntegerBy("Height"); |
73 m_Width = pDict->GetIntegerBy("Width"); | 83 m_Width = pDict->GetIntegerBy("Width"); |
74 return TRUE; | |
75 } | 84 } |
76 | 85 |
77 CPDF_Dictionary* CPDF_Image::InitJPEG(uint8_t* pData, uint32_t size) { | 86 CPDF_Dictionary* CPDF_Image::InitJPEG(uint8_t* pData, uint32_t size) { |
78 int32_t width; | 87 int32_t width; |
79 int32_t height; | 88 int32_t height; |
80 int32_t num_comps; | 89 int32_t num_comps; |
81 int32_t bits; | 90 int32_t bits; |
82 bool color_trans; | 91 bool color_trans; |
83 if (!CPDF_ModuleMgr::Get()->GetJpegModule()->LoadInfo( | 92 if (!CPDF_ModuleMgr::Get()->GetJpegModule()->LoadInfo( |
84 pData, size, &width, &height, &num_comps, &bits, &color_trans)) { | 93 pData, size, &width, &height, &num_comps, &bits, &color_trans)) { |
(...skipping 328 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
413 } | 422 } |
414 if (!ret) { | 423 if (!ret) { |
415 delete m_pDIBSource; | 424 delete m_pDIBSource; |
416 m_pDIBSource = nullptr; | 425 m_pDIBSource = nullptr; |
417 return FALSE; | 426 return FALSE; |
418 } | 427 } |
419 m_pMask = pSource->DetachMask(); | 428 m_pMask = pSource->DetachMask(); |
420 m_MatteColor = pSource->GetMatteColor(); | 429 m_MatteColor = pSource->GetMatteColor(); |
421 return FALSE; | 430 return FALSE; |
422 } | 431 } |
OLD | NEW |