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

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

Issue 2571913002: Avoid the ptr.reset(new XXX()) anti-pattern (Closed)
Patch Set: rebase Created 4 years 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
OLDNEW
1 // Copyright 2014 PDFium Authors. All rights reserved. 1 // Copyright 2014 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/pageint.h" 7 #include "core/fpdfapi/page/pageint.h"
8 8
9 #include <limits.h> 9 #include <limits.h>
10 10
11 #include <algorithm> 11 #include <algorithm>
12 #include <memory> 12 #include <memory>
13 #include <utility> 13 #include <utility>
14 #include <vector> 14 #include <vector>
15 15
16 #include "core/fpdfapi/page/cpdf_psengine.h" 16 #include "core/fpdfapi/page/cpdf_psengine.h"
17 #include "core/fpdfapi/parser/cpdf_array.h" 17 #include "core/fpdfapi/parser/cpdf_array.h"
18 #include "core/fpdfapi/parser/cpdf_dictionary.h" 18 #include "core/fpdfapi/parser/cpdf_dictionary.h"
19 #include "core/fpdfapi/parser/cpdf_simple_parser.h" 19 #include "core/fpdfapi/parser/cpdf_simple_parser.h"
20 #include "core/fpdfapi/parser/cpdf_stream.h" 20 #include "core/fpdfapi/parser/cpdf_stream.h"
21 #include "core/fpdfapi/parser/cpdf_stream_acc.h" 21 #include "core/fpdfapi/parser/cpdf_stream_acc.h"
22 #include "core/fxcrt/fx_safe_types.h" 22 #include "core/fxcrt/fx_safe_types.h"
23 #include "third_party/base/ptr_util.h"
23 24
24 namespace { 25 namespace {
25 26
26 struct PDF_PSOpName { 27 struct PDF_PSOpName {
27 const FX_CHAR* name; 28 const FX_CHAR* name;
28 PDF_PSOP op; 29 PDF_PSOP op;
29 }; 30 };
30 31
31 const PDF_PSOpName kPsOpNames[] = { 32 const PDF_PSOpName kPsOpNames[] = {
32 {"add", PSOP_ADD}, {"sub", PSOP_SUB}, 33 {"add", PSOP_ADD}, {"sub", PSOP_SUB},
(...skipping 455 matching lines...) Expand 10 before | Expand all | Expand 10 after
488 489
489 CPDF_Dictionary* pDict = pStream->GetDict(); 490 CPDF_Dictionary* pDict = pStream->GetDict();
490 CPDF_Array* pSize = pDict->GetArrayFor("Size"); 491 CPDF_Array* pSize = pDict->GetArrayFor("Size");
491 CPDF_Array* pEncode = pDict->GetArrayFor("Encode"); 492 CPDF_Array* pEncode = pDict->GetArrayFor("Encode");
492 CPDF_Array* pDecode = pDict->GetArrayFor("Decode"); 493 CPDF_Array* pDecode = pDict->GetArrayFor("Decode");
493 m_nBitsPerSample = pDict->GetIntegerFor("BitsPerSample"); 494 m_nBitsPerSample = pDict->GetIntegerFor("BitsPerSample");
494 if (!IsValidBitsPerSample(m_nBitsPerSample)) 495 if (!IsValidBitsPerSample(m_nBitsPerSample))
495 return false; 496 return false;
496 497
497 m_SampleMax = 0xffffffff >> (32 - m_nBitsPerSample); 498 m_SampleMax = 0xffffffff >> (32 - m_nBitsPerSample);
498 m_pSampleStream.reset(new CPDF_StreamAcc); 499 m_pSampleStream = pdfium::MakeUnique<CPDF_StreamAcc>();
499 m_pSampleStream->LoadAllData(pStream, false); 500 m_pSampleStream->LoadAllData(pStream, false);
500 FX_SAFE_UINT32 nTotalSampleBits = 1; 501 FX_SAFE_UINT32 nTotalSampleBits = 1;
501 m_EncodeInfo.resize(m_nInputs); 502 m_EncodeInfo.resize(m_nInputs);
502 for (uint32_t i = 0; i < m_nInputs; i++) { 503 for (uint32_t i = 0; i < m_nInputs; i++) {
503 m_EncodeInfo[i].sizes = pSize ? pSize->GetIntegerAt(i) : 0; 504 m_EncodeInfo[i].sizes = pSize ? pSize->GetIntegerAt(i) : 0;
504 if (!pSize && i == 0) 505 if (!pSize && i == 0)
505 m_EncodeInfo[i].sizes = pDict->GetIntegerFor("Size"); 506 m_EncodeInfo[i].sizes = pDict->GetIntegerFor("Size");
506 nTotalSampleBits *= m_EncodeInfo[i].sizes; 507 nTotalSampleBits *= m_EncodeInfo[i].sizes;
507 if (pEncode) { 508 if (pEncode) {
508 m_EncodeInfo[i].encode_min = pEncode->GetFloatAt(i * 2); 509 m_EncodeInfo[i].encode_min = pEncode->GetFloatAt(i * 2);
(...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after
735 return pFunc; 736 return pFunc;
736 737
737 int iType = -1; 738 int iType = -1;
738 if (CPDF_Stream* pStream = pFuncObj->AsStream()) 739 if (CPDF_Stream* pStream = pFuncObj->AsStream())
739 iType = pStream->GetDict()->GetIntegerFor("FunctionType"); 740 iType = pStream->GetDict()->GetIntegerFor("FunctionType");
740 else if (CPDF_Dictionary* pDict = pFuncObj->AsDictionary()) 741 else if (CPDF_Dictionary* pDict = pFuncObj->AsDictionary())
741 iType = pDict->GetIntegerFor("FunctionType"); 742 iType = pDict->GetIntegerFor("FunctionType");
742 743
743 Type type = IntegerToFunctionType(iType); 744 Type type = IntegerToFunctionType(iType);
744 if (type == Type::kType0Sampled) 745 if (type == Type::kType0Sampled)
745 pFunc.reset(new CPDF_SampledFunc()); 746 pFunc = pdfium::MakeUnique<CPDF_SampledFunc>();
746 else if (type == Type::kType2ExpotentialInterpolation) 747 else if (type == Type::kType2ExpotentialInterpolation)
747 pFunc.reset(new CPDF_ExpIntFunc()); 748 pFunc = pdfium::MakeUnique<CPDF_ExpIntFunc>();
748 else if (type == Type::kType3Stitching) 749 else if (type == Type::kType3Stitching)
749 pFunc.reset(new CPDF_StitchFunc()); 750 pFunc = pdfium::MakeUnique<CPDF_StitchFunc>();
750 else if (type == Type::kType4PostScript) 751 else if (type == Type::kType4PostScript)
751 pFunc.reset(new CPDF_PSFunc()); 752 pFunc = pdfium::MakeUnique<CPDF_PSFunc>();
752 753
753 if (!pFunc || !pFunc->Init(pFuncObj)) 754 if (!pFunc || !pFunc->Init(pFuncObj))
754 return nullptr; 755 return nullptr;
755 756
756 return pFunc; 757 return pFunc;
757 } 758 }
758 759
759 // static 760 // static
760 CPDF_Function::Type CPDF_Function::IntegerToFunctionType(int iType) { 761 CPDF_Function::Type CPDF_Function::IntegerToFunctionType(int iType) {
761 switch (iType) { 762 switch (iType) {
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
850 return m_Type == Type::kType2ExpotentialInterpolation 851 return m_Type == Type::kType2ExpotentialInterpolation
851 ? static_cast<const CPDF_ExpIntFunc*>(this) 852 ? static_cast<const CPDF_ExpIntFunc*>(this)
852 : nullptr; 853 : nullptr;
853 } 854 }
854 855
855 const CPDF_StitchFunc* CPDF_Function::ToStitchFunc() const { 856 const CPDF_StitchFunc* CPDF_Function::ToStitchFunc() const {
856 return m_Type == Type::kType3Stitching 857 return m_Type == Type::kType3Stitching
857 ? static_cast<const CPDF_StitchFunc*>(this) 858 ? static_cast<const CPDF_StitchFunc*>(this)
858 : nullptr; 859 : nullptr;
859 } 860 }
OLDNEW
« no previous file with comments | « core/fpdfapi/page/cpdf_tilingpattern.cpp ('k') | core/fpdfapi/parser/cpdf_document_unittest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698