| 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> | 10 #include <memory> |
| 11 #include <vector> | 11 #include <vector> |
| 12 | 12 |
| 13 #include "core/fpdfapi/cpdf_modulemgr.h" | 13 #include "core/fpdfapi/cpdf_modulemgr.h" |
| 14 #include "core/fpdfapi/page/cpdf_docpagedata.h" | 14 #include "core/fpdfapi/page/cpdf_docpagedata.h" |
| 15 #include "core/fpdfapi/page/cpdf_page.h" | 15 #include "core/fpdfapi/page/cpdf_page.h" |
| 16 #include "core/fpdfapi/parser/cpdf_array.h" | 16 #include "core/fpdfapi/parser/cpdf_array.h" |
| 17 #include "core/fpdfapi/parser/cpdf_boolean.h" | 17 #include "core/fpdfapi/parser/cpdf_boolean.h" |
| 18 #include "core/fpdfapi/parser/cpdf_dictionary.h" |
| 18 #include "core/fpdfapi/parser/cpdf_document.h" | 19 #include "core/fpdfapi/parser/cpdf_document.h" |
| 19 #include "core/fpdfapi/parser/cpdf_string.h" | 20 #include "core/fpdfapi/parser/cpdf_string.h" |
| 20 #include "core/fpdfapi/render/cpdf_pagerendercache.h" | 21 #include "core/fpdfapi/render/cpdf_pagerendercache.h" |
| 21 #include "core/fpdfapi/render/render_int.h" | 22 #include "core/fpdfapi/render/render_int.h" |
| 22 #include "core/fxcodec/fx_codec.h" | 23 #include "core/fxcodec/fx_codec.h" |
| 23 #include "core/fxge/fx_dib.h" | 24 #include "core/fxge/fx_dib.h" |
| 24 | 25 |
| 25 CPDF_Image::CPDF_Image(CPDF_Document* pDoc) | 26 CPDF_Image::CPDF_Image(CPDF_Document* pDoc) : m_pDocument(pDoc) {} |
| 26 : CPDF_Image(pDoc, nullptr, false) {} | |
| 27 | 27 |
| 28 CPDF_Image::CPDF_Image(CPDF_Document* pDoc, CPDF_Stream* pStream, bool bInline) | 28 CPDF_Image::CPDF_Image(CPDF_Document* pDoc, UniqueStream pStream) |
| 29 : m_pDIBSource(nullptr), | 29 : m_pDocument(pDoc), |
| 30 m_pMask(nullptr), | 30 m_pStream(pStream.get()), |
| 31 m_MatteColor(0), | 31 m_pOwnedStream(std::move(pStream)) { |
| 32 m_pStream(pStream), | 32 if (!m_pStream) |
| 33 m_bInline(bInline), | |
| 34 m_pInlineDict(nullptr), | |
| 35 m_Height(0), | |
| 36 m_Width(0), | |
| 37 m_bIsMask(false), | |
| 38 m_bInterpolate(false), | |
| 39 m_pDocument(pDoc), | |
| 40 m_pOC(nullptr) { | |
| 41 if (!pStream) | |
| 42 return; | 33 return; |
| 43 | 34 |
| 44 CPDF_Dictionary* pDict = pStream->GetDict(); | 35 m_pOwnedDict = ToDictionary(UniqueObject(m_pStream->GetDict()->Clone())); |
| 45 if (m_bInline) | 36 m_pDict = m_pOwnedDict.get(); |
| 46 m_pInlineDict = ToDictionary(pDict->Clone()); | 37 FinishInitialization(); |
| 47 | |
| 48 m_pOC = pDict->GetDictFor("OC"); | |
| 49 m_bIsMask = | |
| 50 !pDict->KeyExist("ColorSpace") || pDict->GetIntegerFor("ImageMask"); | |
| 51 m_bInterpolate = !!pDict->GetIntegerFor("Interpolate"); | |
| 52 m_Height = pDict->GetIntegerFor("Height"); | |
| 53 m_Width = pDict->GetIntegerFor("Width"); | |
| 54 } | 38 } |
| 55 | 39 |
| 56 CPDF_Image::~CPDF_Image() { | 40 CPDF_Image::CPDF_Image(CPDF_Document* pDoc, uint32_t dwStreamObjNum) |
| 57 if (m_bInline) { | 41 : m_pDocument(pDoc), |
| 58 if (m_pStream) | 42 m_pStream(ToStream(pDoc->GetIndirectObject(dwStreamObjNum))) { |
| 59 m_pStream->Release(); | 43 if (!m_pStream) |
| 60 if (m_pInlineDict) | 44 return; |
| 61 m_pInlineDict->Release(); | 45 |
| 62 } | 46 m_pDict = m_pStream->GetDict(); |
| 47 FinishInitialization(); |
| 48 } |
| 49 |
| 50 CPDF_Image::~CPDF_Image() {} |
| 51 |
| 52 void CPDF_Image::FinishInitialization() { |
| 53 m_pOC = m_pDict->GetDictFor("OC"); |
| 54 m_bIsMask = |
| 55 !m_pDict->KeyExist("ColorSpace") || m_pDict->GetIntegerFor("ImageMask"); |
| 56 m_bInterpolate = !!m_pDict->GetIntegerFor("Interpolate"); |
| 57 m_Height = m_pDict->GetIntegerFor("Height"); |
| 58 m_Width = m_pDict->GetIntegerFor("Width"); |
| 63 } | 59 } |
| 64 | 60 |
| 65 CPDF_Image* CPDF_Image::Clone() { | 61 CPDF_Image* CPDF_Image::Clone() { |
| 66 if (!m_pStream->IsInline()) | 62 CPDF_Image* pImage = new CPDF_Image(m_pDocument); |
| 67 return m_pDocument->GetPageData()->GetImage(m_pStream); | 63 if (m_pOwnedStream) { |
| 68 | 64 pImage->m_pOwnedStream = ToStream(UniqueObject(m_pOwnedStream->Clone())); |
| 69 CPDF_Image* pImage = | 65 pImage->m_pStream = pImage->m_pOwnedStream.get(); |
| 70 new CPDF_Image(m_pDocument, ToStream(m_pStream->Clone()), m_bInline); | 66 } else { |
| 71 if (m_bInline) | 67 pImage->m_pStream = m_pStream; |
| 72 pImage->SetInlineDict(ToDictionary(m_pInlineDict->CloneDirectObject())); | 68 } |
| 73 | 69 if (m_pOwnedDict) { |
| 70 pImage->m_pOwnedDict = ToDictionary(UniqueObject(m_pOwnedDict->Clone())); |
| 71 pImage->m_pDict = pImage->m_pOwnedDict.get(); |
| 72 } else { |
| 73 pImage->m_pDict = m_pDict; |
| 74 } |
| 74 return pImage; | 75 return pImage; |
| 75 } | 76 } |
| 76 | 77 |
| 77 CPDF_Dictionary* CPDF_Image::InitJPEG(uint8_t* pData, uint32_t size) { | 78 CPDF_Dictionary* CPDF_Image::InitJPEG(uint8_t* pData, uint32_t size) { |
| 78 int32_t width; | 79 int32_t width; |
| 79 int32_t height; | 80 int32_t height; |
| 80 int32_t num_comps; | 81 int32_t num_comps; |
| 81 int32_t bits; | 82 int32_t bits; |
| 82 bool color_trans; | 83 bool color_trans; |
| 83 if (!CPDF_ModuleMgr::Get()->GetJpegModule()->LoadInfo( | 84 if (!CPDF_ModuleMgr::Get()->GetJpegModule()->LoadInfo( |
| (...skipping 318 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 402 } | 403 } |
| 403 if (!ret) { | 404 if (!ret) { |
| 404 delete m_pDIBSource; | 405 delete m_pDIBSource; |
| 405 m_pDIBSource = nullptr; | 406 m_pDIBSource = nullptr; |
| 406 return FALSE; | 407 return FALSE; |
| 407 } | 408 } |
| 408 m_pMask = pSource->DetachMask(); | 409 m_pMask = pSource->DetachMask(); |
| 409 m_MatteColor = pSource->GetMatteColor(); | 410 m_MatteColor = pSource->GetMatteColor(); |
| 410 return FALSE; | 411 return FALSE; |
| 411 } | 412 } |
| OLD | NEW |