diff options
author | tsepez <tsepez@chromium.org> | 2016-11-23 14:34:58 -0800 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2016-11-23 14:34:58 -0800 |
commit | 9fd0c630ea2225fc544949d88d1bf63acc43112e (patch) | |
tree | a24d041a6a0912abf6d7915833b22e3fa2380150 /core/fpdfapi | |
parent | 81b224669647c9dd3c5ea2e013ee3cc109744bb8 (diff) | |
download | pdfium-9fd0c630ea2225fc544949d88d1bf63acc43112e.tar.xz |
Use CFX_MaybeOwned<> in CPDF_Image
Review-Url: https://codereview.chromium.org/2523093003
Diffstat (limited to 'core/fpdfapi')
-rw-r--r-- | core/fpdfapi/page/cpdf_image.cpp | 42 | ||||
-rw-r--r-- | core/fpdfapi/page/cpdf_image.h | 11 |
2 files changed, 25 insertions, 28 deletions
diff --git a/core/fpdfapi/page/cpdf_image.cpp b/core/fpdfapi/page/cpdf_image.cpp index 8a5faa6d0a..5d1d51de89 100644 --- a/core/fpdfapi/page/cpdf_image.cpp +++ b/core/fpdfapi/page/cpdf_image.cpp @@ -35,18 +35,19 @@ CPDF_Image::CPDF_Image(CPDF_Document* pDoc, std::unique_ptr<CPDF_Stream> pStream) : m_bIsInline(true), m_pDocument(pDoc), - m_pStream(pStream.get()), - m_pOwnedStream(std::move(pStream)) { - m_pOwnedDict = - ToDictionary(std::unique_ptr<CPDF_Object>(m_pStream->GetDict()->Clone())); - m_pDict = m_pOwnedDict.get(); + m_pStream(std::move(pStream)), + m_pDict(ToDictionary(m_pStream->GetDict()->Clone())) { + ASSERT(m_pStream.IsOwned()); + ASSERT(m_pDict.IsOwned()); FinishInitialization(); } CPDF_Image::CPDF_Image(CPDF_Document* pDoc, uint32_t dwStreamObjNum) : m_pDocument(pDoc), - m_pStream(ToStream(pDoc->GetIndirectObject(dwStreamObjNum))) { - m_pDict = m_pStream->GetDict(); + m_pStream(ToStream(pDoc->GetIndirectObject(dwStreamObjNum))), + m_pDict(m_pStream->GetDict()) { + ASSERT(!m_pStream.IsOwned()); + ASSERT(!m_pDict.IsOwned()); FinishInitialization(); } @@ -65,8 +66,8 @@ void CPDF_Image::ConvertStreamToIndirectObject() { if (!m_pStream->IsInline()) return; - ASSERT(m_pOwnedStream); - m_pDocument->AddIndirectObject(std::move(m_pOwnedStream)); + ASSERT(m_pStream.IsOwned()); + m_pDocument->AddIndirectObject(m_pStream.Release()); } std::unique_ptr<CPDF_Dictionary> CPDF_Image::InitJPEG(uint8_t* pData, @@ -110,10 +111,8 @@ std::unique_ptr<CPDF_Dictionary> CPDF_Image::InitJPEG(uint8_t* pData, m_bIsMask = false; m_Width = width; m_Height = height; - if (!m_pStream) { - m_pOwnedStream = pdfium::MakeUnique<CPDF_Stream>(); - m_pStream = m_pOwnedStream.get(); - } + if (!m_pStream) + m_pStream = pdfium::MakeUnique<CPDF_Stream>(); return pDict; } @@ -291,10 +290,9 @@ void CPDF_Image::SetImage(const CFX_DIBitmap* pBitmap) { dest_offset = 0; } } - if (!m_pStream) { - m_pOwnedStream = pdfium::MakeUnique<CPDF_Stream>(); - m_pStream = m_pOwnedStream.get(); - } + if (!m_pStream) + m_pStream = pdfium::MakeUnique<CPDF_Stream>(); + m_pStream->InitStream(dest_buf, dest_size, std::move(pDict)); m_bIsMask = pBitmap->IsAlphaMask(); m_Width = BitmapWidth; @@ -303,7 +301,7 @@ void CPDF_Image::SetImage(const CFX_DIBitmap* pBitmap) { } void CPDF_Image::ResetCache(CPDF_Page* pPage, const CFX_DIBitmap* pBitmap) { - pPage->GetRenderCache()->ResetBitmap(m_pStream, pBitmap); + pPage->GetRenderCache()->ResetBitmap(m_pStream.Get(), pBitmap); } CFX_DIBSource* CPDF_Image::LoadDIBSource(CFX_DIBSource** ppMask, @@ -312,7 +310,7 @@ CFX_DIBSource* CPDF_Image::LoadDIBSource(CFX_DIBSource** ppMask, uint32_t GroupFamily, bool bLoadMask) const { auto source = pdfium::MakeUnique<CPDF_DIBSource>(); - if (source->Load(m_pDocument, m_pStream, + if (source->Load(m_pDocument, m_pStream.Get(), reinterpret_cast<CPDF_DIBSource**>(ppMask), pMatteColor, nullptr, nullptr, bStdCS, GroupFamily, bLoadMask)) { return source.release(); @@ -338,9 +336,9 @@ bool CPDF_Image::StartLoadDIBSource(CPDF_Dictionary* pFormResource, uint32_t GroupFamily, bool bLoadMask) { auto source = pdfium::MakeUnique<CPDF_DIBSource>(); - int ret = - source->StartLoadDIBSource(m_pDocument, m_pStream, true, pFormResource, - pPageResource, bStdCS, GroupFamily, bLoadMask); + int ret = source->StartLoadDIBSource(m_pDocument, m_pStream.Get(), true, + pFormResource, pPageResource, bStdCS, + GroupFamily, bLoadMask); if (ret == 2) { m_pDIBSource = source.release(); return true; diff --git a/core/fpdfapi/page/cpdf_image.h b/core/fpdfapi/page/cpdf_image.h index 3438e2b98e..38c7e3e728 100644 --- a/core/fpdfapi/page/cpdf_image.h +++ b/core/fpdfapi/page/cpdf_image.h @@ -10,6 +10,7 @@ #include <memory> #include "core/fpdfapi/parser/cpdf_stream.h" +#include "core/fxcrt/cfx_maybe_owned.h" #include "core/fxcrt/fx_system.h" class CFX_DIBSource; @@ -28,8 +29,8 @@ class CPDF_Image { void ConvertStreamToIndirectObject(); - CPDF_Dictionary* GetInlineDict() const { return m_pDict; } - CPDF_Stream* GetStream() const { return m_pStream; } + CPDF_Dictionary* GetInlineDict() const { return m_pDict.Get(); } + CPDF_Stream* GetStream() const { return m_pStream.Get(); } CPDF_Dictionary* GetDict() const { return m_pStream ? m_pStream->GetDict() : nullptr; } @@ -77,10 +78,8 @@ class CPDF_Image { bool m_bIsMask = false; bool m_bInterpolate = false; CPDF_Document* const m_pDocument; - CPDF_Stream* m_pStream = nullptr; - CPDF_Dictionary* m_pDict = nullptr; - std::unique_ptr<CPDF_Stream> m_pOwnedStream; - std::unique_ptr<CPDF_Dictionary> m_pOwnedDict; + CFX_MaybeOwned<CPDF_Stream> m_pStream; + CFX_MaybeOwned<CPDF_Dictionary> m_pDict; CPDF_Dictionary* m_pOC = nullptr; }; |