Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(143)

Side by Side Diff: core/fpdfapi/page/cpdf_image.cpp

Issue 2517163003: Use more unique_ptrs in CPDF_Image. (Closed)
Patch Set: rebase Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « core/fpdfapi/page/cpdf_image.h ('k') | core/fpdfapi/page/cpdf_imageobject.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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>
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
54 54
55 void CPDF_Image::FinishInitialization() { 55 void CPDF_Image::FinishInitialization() {
56 m_pOC = m_pDict->GetDictFor("OC"); 56 m_pOC = m_pDict->GetDictFor("OC");
57 m_bIsMask = 57 m_bIsMask =
58 !m_pDict->KeyExist("ColorSpace") || m_pDict->GetIntegerFor("ImageMask"); 58 !m_pDict->KeyExist("ColorSpace") || m_pDict->GetIntegerFor("ImageMask");
59 m_bInterpolate = !!m_pDict->GetIntegerFor("Interpolate"); 59 m_bInterpolate = !!m_pDict->GetIntegerFor("Interpolate");
60 m_Height = m_pDict->GetIntegerFor("Height"); 60 m_Height = m_pDict->GetIntegerFor("Height");
61 m_Width = m_pDict->GetIntegerFor("Width"); 61 m_Width = m_pDict->GetIntegerFor("Width");
62 } 62 }
63 63
64 CPDF_Image* CPDF_Image::Clone() {
65 CPDF_Image* pImage = new CPDF_Image(m_pDocument);
66 pImage->m_bIsInline = m_bIsInline;
67 if (m_pOwnedStream) {
68 pImage->m_pOwnedStream = ToStream(m_pOwnedStream->Clone());
69 pImage->m_pStream = pImage->m_pOwnedStream.get();
70 } else {
71 pImage->m_pStream = m_pStream;
72 }
73 if (m_pOwnedDict) {
74 pImage->m_pOwnedDict = ToDictionary(m_pOwnedDict->Clone());
75 pImage->m_pDict = pImage->m_pOwnedDict.get();
76 } else {
77 pImage->m_pDict = m_pDict;
78 }
79 return pImage;
80 }
81
82 void CPDF_Image::ConvertStreamToIndirectObject() { 64 void CPDF_Image::ConvertStreamToIndirectObject() {
83 if (!m_pStream->IsInline()) 65 if (!m_pStream->IsInline())
84 return; 66 return;
85 67
86 ASSERT(m_pOwnedStream); 68 ASSERT(m_pOwnedStream);
87 m_pDocument->AddIndirectObject(std::move(m_pOwnedStream)); 69 m_pDocument->AddIndirectObject(std::move(m_pOwnedStream));
88 } 70 }
89 71
90 std::unique_ptr<CPDF_Dictionary> CPDF_Image::InitJPEG(uint8_t* pData, 72 std::unique_ptr<CPDF_Dictionary> CPDF_Image::InitJPEG(uint8_t* pData,
91 uint32_t size) { 73 uint32_t size) {
(...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after
322 304
323 void CPDF_Image::ResetCache(CPDF_Page* pPage, const CFX_DIBitmap* pBitmap) { 305 void CPDF_Image::ResetCache(CPDF_Page* pPage, const CFX_DIBitmap* pBitmap) {
324 pPage->GetRenderCache()->ResetBitmap(m_pStream, pBitmap); 306 pPage->GetRenderCache()->ResetBitmap(m_pStream, pBitmap);
325 } 307 }
326 308
327 CFX_DIBSource* CPDF_Image::LoadDIBSource(CFX_DIBSource** ppMask, 309 CFX_DIBSource* CPDF_Image::LoadDIBSource(CFX_DIBSource** ppMask,
328 uint32_t* pMatteColor, 310 uint32_t* pMatteColor,
329 bool bStdCS, 311 bool bStdCS,
330 uint32_t GroupFamily, 312 uint32_t GroupFamily,
331 bool bLoadMask) const { 313 bool bLoadMask) const {
332 std::unique_ptr<CPDF_DIBSource> source(new CPDF_DIBSource); 314 auto source = pdfium::MakeUnique<CPDF_DIBSource>();
333 if (source->Load(m_pDocument, m_pStream, 315 if (source->Load(m_pDocument, m_pStream,
334 reinterpret_cast<CPDF_DIBSource**>(ppMask), pMatteColor, 316 reinterpret_cast<CPDF_DIBSource**>(ppMask), pMatteColor,
335 nullptr, nullptr, bStdCS, GroupFamily, bLoadMask)) { 317 nullptr, nullptr, bStdCS, GroupFamily, bLoadMask)) {
336 return source.release(); 318 return source.release();
337 } 319 }
338 return nullptr; 320 return nullptr;
339 } 321 }
340 322
341 CFX_DIBSource* CPDF_Image::DetachBitmap() { 323 CFX_DIBSource* CPDF_Image::DetachBitmap() {
342 CFX_DIBSource* pBitmap = m_pDIBSource; 324 CFX_DIBSource* pBitmap = m_pDIBSource;
343 m_pDIBSource = nullptr; 325 m_pDIBSource = nullptr;
344 return pBitmap; 326 return pBitmap;
345 } 327 }
346 328
347 CFX_DIBSource* CPDF_Image::DetachMask() { 329 CFX_DIBSource* CPDF_Image::DetachMask() {
348 CFX_DIBSource* pBitmap = m_pMask; 330 CFX_DIBSource* pBitmap = m_pMask;
349 m_pMask = nullptr; 331 m_pMask = nullptr;
350 return pBitmap; 332 return pBitmap;
351 } 333 }
352 334
353 bool CPDF_Image::StartLoadDIBSource(CPDF_Dictionary* pFormResource, 335 bool CPDF_Image::StartLoadDIBSource(CPDF_Dictionary* pFormResource,
354 CPDF_Dictionary* pPageResource, 336 CPDF_Dictionary* pPageResource,
355 bool bStdCS, 337 bool bStdCS,
356 uint32_t GroupFamily, 338 uint32_t GroupFamily,
357 bool bLoadMask) { 339 bool bLoadMask) {
358 std::unique_ptr<CPDF_DIBSource> source(new CPDF_DIBSource); 340 auto source = pdfium::MakeUnique<CPDF_DIBSource>();
359 int ret = 341 int ret =
360 source->StartLoadDIBSource(m_pDocument, m_pStream, true, pFormResource, 342 source->StartLoadDIBSource(m_pDocument, m_pStream, true, pFormResource,
361 pPageResource, bStdCS, GroupFamily, bLoadMask); 343 pPageResource, bStdCS, GroupFamily, bLoadMask);
362 if (ret == 2) { 344 if (ret == 2) {
363 m_pDIBSource = source.release(); 345 m_pDIBSource = source.release();
364 return true; 346 return true;
365 } 347 }
366 if (!ret) { 348 if (!ret) {
367 m_pDIBSource = nullptr; 349 m_pDIBSource = nullptr;
368 return false; 350 return false;
(...skipping 12 matching lines...) Expand all
381 } 363 }
382 if (!ret) { 364 if (!ret) {
383 delete m_pDIBSource; 365 delete m_pDIBSource;
384 m_pDIBSource = nullptr; 366 m_pDIBSource = nullptr;
385 return false; 367 return false;
386 } 368 }
387 m_pMask = pSource->DetachMask(); 369 m_pMask = pSource->DetachMask();
388 m_MatteColor = pSource->GetMatteColor(); 370 m_MatteColor = pSource->GetMatteColor();
389 return false; 371 return false;
390 } 372 }
OLDNEW
« no previous file with comments | « core/fpdfapi/page/cpdf_image.h ('k') | core/fpdfapi/page/cpdf_imageobject.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698