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

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

Issue 2453163002: Take advantage of implicit std::unique_ptr<>(nulltpr_t) ctor. (Closed)
Patch Set: 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_clippath.cpp ('k') | core/fpdfapi/page/fpdf_page_func.cpp » ('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_colorspace.h" 7 #include "core/fpdfapi/page/cpdf_colorspace.h"
8 8
9 #include <memory> 9 #include <memory>
10 10
(...skipping 314 matching lines...) Expand 10 before | Expand all | Expand 10 after
325 return nullptr; 325 return nullptr;
326 } 326 }
327 327
328 CPDF_ColorSpace* CPDF_ColorSpace::GetStockCS(int family) { 328 CPDF_ColorSpace* CPDF_ColorSpace::GetStockCS(int family) {
329 return CPDF_ModuleMgr::Get()->GetPageModule()->GetStockCS(family); 329 return CPDF_ModuleMgr::Get()->GetPageModule()->GetStockCS(family);
330 } 330 }
331 331
332 std::unique_ptr<CPDF_ColorSpace> CPDF_ColorSpace::Load(CPDF_Document* pDoc, 332 std::unique_ptr<CPDF_ColorSpace> CPDF_ColorSpace::Load(CPDF_Document* pDoc,
333 CPDF_Object* pObj) { 333 CPDF_Object* pObj) {
334 if (!pObj) 334 if (!pObj)
335 return std::unique_ptr<CPDF_ColorSpace>(); 335 return nullptr;
336 336
337 if (pObj->IsName()) { 337 if (pObj->IsName()) {
338 return std::unique_ptr<CPDF_ColorSpace>( 338 return std::unique_ptr<CPDF_ColorSpace>(
339 ColorspaceFromName(pObj->GetString())); 339 ColorspaceFromName(pObj->GetString()));
340 } 340 }
341 if (CPDF_Stream* pStream = pObj->AsStream()) { 341 if (CPDF_Stream* pStream = pObj->AsStream()) {
342 CPDF_Dictionary* pDict = pStream->GetDict(); 342 CPDF_Dictionary* pDict = pStream->GetDict();
343 if (!pDict) 343 if (!pDict)
344 return std::unique_ptr<CPDF_ColorSpace>(); 344 return nullptr;
345 345
346 for (const auto& it : *pDict) { 346 for (const auto& it : *pDict) {
347 std::unique_ptr<CPDF_ColorSpace> pRet; 347 std::unique_ptr<CPDF_ColorSpace> pRet;
348 CPDF_Object* pValue = it.second; 348 CPDF_Object* pValue = it.second;
349 if (ToName(pValue)) 349 if (ToName(pValue))
350 pRet.reset(ColorspaceFromName(pValue->GetString())); 350 pRet.reset(ColorspaceFromName(pValue->GetString()));
351 if (pRet) 351 if (pRet)
352 return pRet; 352 return pRet;
353 } 353 }
354 return std::unique_ptr<CPDF_ColorSpace>(); 354 return nullptr;
355 } 355 }
356 356
357 CPDF_Array* pArray = pObj->AsArray(); 357 CPDF_Array* pArray = pObj->AsArray();
358 if (!pArray || pArray->IsEmpty()) 358 if (!pArray || pArray->IsEmpty())
359 return std::unique_ptr<CPDF_ColorSpace>(); 359 return nullptr;
360 360
361 CPDF_Object* pFamilyObj = pArray->GetDirectObjectAt(0); 361 CPDF_Object* pFamilyObj = pArray->GetDirectObjectAt(0);
362 if (!pFamilyObj) 362 if (!pFamilyObj)
363 return std::unique_ptr<CPDF_ColorSpace>(); 363 return nullptr;
364 364
365 CFX_ByteString familyname = pFamilyObj->GetString(); 365 CFX_ByteString familyname = pFamilyObj->GetString();
366 if (pArray->GetCount() == 1) 366 if (pArray->GetCount() == 1)
367 return std::unique_ptr<CPDF_ColorSpace>(ColorspaceFromName(familyname)); 367 return std::unique_ptr<CPDF_ColorSpace>(ColorspaceFromName(familyname));
368 368
369 std::unique_ptr<CPDF_ColorSpace> pCS; 369 std::unique_ptr<CPDF_ColorSpace> pCS;
370 uint32_t id = familyname.GetID(); 370 uint32_t id = familyname.GetID();
371 if (id == FXBSTR_ID('C', 'a', 'l', 'G')) { 371 if (id == FXBSTR_ID('C', 'a', 'l', 'G')) {
372 pCS.reset(new CPDF_CalGray(pDoc)); 372 pCS.reset(new CPDF_CalGray(pDoc));
373 } else if (id == FXBSTR_ID('C', 'a', 'l', 'R')) { 373 } else if (id == FXBSTR_ID('C', 'a', 'l', 'R')) {
374 pCS.reset(new CPDF_CalRGB(pDoc)); 374 pCS.reset(new CPDF_CalRGB(pDoc));
375 } else if (id == FXBSTR_ID('L', 'a', 'b', 0)) { 375 } else if (id == FXBSTR_ID('L', 'a', 'b', 0)) {
376 pCS.reset(new CPDF_LabCS(pDoc)); 376 pCS.reset(new CPDF_LabCS(pDoc));
377 } else if (id == FXBSTR_ID('I', 'C', 'C', 'B')) { 377 } else if (id == FXBSTR_ID('I', 'C', 'C', 'B')) {
378 pCS.reset(new CPDF_ICCBasedCS(pDoc)); 378 pCS.reset(new CPDF_ICCBasedCS(pDoc));
379 } else if (id == FXBSTR_ID('I', 'n', 'd', 'e') || 379 } else if (id == FXBSTR_ID('I', 'n', 'd', 'e') ||
380 id == FXBSTR_ID('I', 0, 0, 0)) { 380 id == FXBSTR_ID('I', 0, 0, 0)) {
381 pCS.reset(new CPDF_IndexedCS(pDoc)); 381 pCS.reset(new CPDF_IndexedCS(pDoc));
382 } else if (id == FXBSTR_ID('S', 'e', 'p', 'a')) { 382 } else if (id == FXBSTR_ID('S', 'e', 'p', 'a')) {
383 pCS.reset(new CPDF_SeparationCS(pDoc)); 383 pCS.reset(new CPDF_SeparationCS(pDoc));
384 } else if (id == FXBSTR_ID('D', 'e', 'v', 'i')) { 384 } else if (id == FXBSTR_ID('D', 'e', 'v', 'i')) {
385 pCS.reset(new CPDF_DeviceNCS(pDoc)); 385 pCS.reset(new CPDF_DeviceNCS(pDoc));
386 } else if (id == FXBSTR_ID('P', 'a', 't', 't')) { 386 } else if (id == FXBSTR_ID('P', 'a', 't', 't')) {
387 pCS.reset(new CPDF_PatternCS(pDoc)); 387 pCS.reset(new CPDF_PatternCS(pDoc));
388 } else { 388 } else {
389 return std::unique_ptr<CPDF_ColorSpace>(); 389 return nullptr;
390 } 390 }
391 pCS->m_pArray = pArray; 391 pCS->m_pArray = pArray;
392 if (!pCS->v_Load(pDoc, pArray)) 392 if (!pCS->v_Load(pDoc, pArray))
393 return std::unique_ptr<CPDF_ColorSpace>(); 393 return nullptr;
394 394
395 return pCS; 395 return pCS;
396 } 396 }
397 397
398 void CPDF_ColorSpace::Release() { 398 void CPDF_ColorSpace::Release() {
399 if (this == GetStockCS(PDFCS_DEVICERGB) || 399 if (this == GetStockCS(PDFCS_DEVICERGB) ||
400 this == GetStockCS(PDFCS_DEVICEGRAY) || 400 this == GetStockCS(PDFCS_DEVICEGRAY) ||
401 this == GetStockCS(PDFCS_DEVICECMYK) || 401 this == GetStockCS(PDFCS_DEVICECMYK) ||
402 this == GetStockCS(PDFCS_PATTERN)) { 402 this == GetStockCS(PDFCS_PATTERN)) {
403 return; 403 return;
(...skipping 865 matching lines...) Expand 10 before | Expand all | Expand 10 after
1269 1269
1270 return m_pAltCS->GetRGB(results, R, G, B); 1270 return m_pAltCS->GetRGB(results, R, G, B);
1271 } 1271 }
1272 1272
1273 void CPDF_DeviceNCS::EnableStdConversion(FX_BOOL bEnabled) { 1273 void CPDF_DeviceNCS::EnableStdConversion(FX_BOOL bEnabled) {
1274 CPDF_ColorSpace::EnableStdConversion(bEnabled); 1274 CPDF_ColorSpace::EnableStdConversion(bEnabled);
1275 if (m_pAltCS) { 1275 if (m_pAltCS) {
1276 m_pAltCS->EnableStdConversion(bEnabled); 1276 m_pAltCS->EnableStdConversion(bEnabled);
1277 } 1277 }
1278 } 1278 }
OLDNEW
« no previous file with comments | « core/fpdfapi/page/cpdf_clippath.cpp ('k') | core/fpdfapi/page/fpdf_page_func.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698