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

Side by Side Diff: core/fpdfapi/render/fpdf_render_loadimage.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
« no previous file with comments | « core/fpdfapi/render/cpdf_scaledrenderbuffer.cpp ('k') | core/fpdfdoc/cpdf_variabletext.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 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/render/render_int.h" 7 #include "core/fpdfapi/render/render_int.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_image.h" 15 #include "core/fpdfapi/page/cpdf_image.h"
16 #include "core/fpdfapi/page/cpdf_imageobject.h" 16 #include "core/fpdfapi/page/cpdf_imageobject.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_document.h" 19 #include "core/fpdfapi/parser/cpdf_document.h"
20 #include "core/fpdfapi/parser/fpdf_parser_decode.h" 20 #include "core/fpdfapi/parser/fpdf_parser_decode.h"
21 #include "core/fpdfapi/render/cpdf_pagerendercache.h" 21 #include "core/fpdfapi/render/cpdf_pagerendercache.h"
22 #include "core/fpdfapi/render/cpdf_renderstatus.h" 22 #include "core/fpdfapi/render/cpdf_renderstatus.h"
23 #include "core/fxcodec/fx_codec.h" 23 #include "core/fxcodec/fx_codec.h"
24 #include "core/fxcrt/fx_safe_types.h" 24 #include "core/fxcrt/fx_safe_types.h"
25 #include "third_party/base/ptr_util.h"
25 26
26 namespace { 27 namespace {
27 28
28 unsigned int GetBits8(const uint8_t* pData, uint64_t bitpos, size_t nbits) { 29 unsigned int GetBits8(const uint8_t* pData, uint64_t bitpos, size_t nbits) {
29 ASSERT(nbits == 1 || nbits == 2 || nbits == 4 || nbits == 8 || nbits == 16); 30 ASSERT(nbits == 1 || nbits == 2 || nbits == 4 || nbits == 8 || nbits == 16);
30 ASSERT((bitpos & (nbits - 1)) == 0); 31 ASSERT((bitpos & (nbits - 1)) == 0);
31 unsigned int byte = pData[bitpos / 8]; 32 unsigned int byte = pData[bitpos / 8];
32 if (nbits == 8) 33 if (nbits == 8)
33 return byte; 34 return byte;
34 35
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
164 return false; 165 return false;
165 } 166 }
166 if (m_bDoBpcCheck && (m_bpc == 0 || m_nComponents == 0)) { 167 if (m_bDoBpcCheck && (m_bpc == 0 || m_nComponents == 0)) {
167 return false; 168 return false;
168 } 169 }
169 FX_SAFE_UINT32 src_size = 170 FX_SAFE_UINT32 src_size =
170 CalculatePitch8(m_bpc, m_nComponents, m_Width) * m_Height; 171 CalculatePitch8(m_bpc, m_nComponents, m_Width) * m_Height;
171 if (!src_size.IsValid()) { 172 if (!src_size.IsValid()) {
172 return false; 173 return false;
173 } 174 }
174 m_pStreamAcc.reset(new CPDF_StreamAcc); 175 m_pStreamAcc = pdfium::MakeUnique<CPDF_StreamAcc>();
175 m_pStreamAcc->LoadAllData(pStream, false, src_size.ValueOrDie(), true); 176 m_pStreamAcc->LoadAllData(pStream, false, src_size.ValueOrDie(), true);
176 if (m_pStreamAcc->GetSize() == 0 || !m_pStreamAcc->GetData()) { 177 if (m_pStreamAcc->GetSize() == 0 || !m_pStreamAcc->GetData()) {
177 return false; 178 return false;
178 } 179 }
179 if (!CreateDecoder()) { 180 if (!CreateDecoder()) {
180 return false; 181 return false;
181 } 182 }
182 if (m_bImageMask) { 183 if (m_bImageMask) {
183 m_bpp = 1; 184 m_bpp = 1;
184 m_bpc = 1; 185 m_bpc = 1;
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
286 return 0; 287 return 0;
287 } 288 }
288 if (m_bDoBpcCheck && (m_bpc == 0 || m_nComponents == 0)) { 289 if (m_bDoBpcCheck && (m_bpc == 0 || m_nComponents == 0)) {
289 return 0; 290 return 0;
290 } 291 }
291 FX_SAFE_UINT32 src_size = 292 FX_SAFE_UINT32 src_size =
292 CalculatePitch8(m_bpc, m_nComponents, m_Width) * m_Height; 293 CalculatePitch8(m_bpc, m_nComponents, m_Width) * m_Height;
293 if (!src_size.IsValid()) { 294 if (!src_size.IsValid()) {
294 return 0; 295 return 0;
295 } 296 }
296 m_pStreamAcc.reset(new CPDF_StreamAcc); 297 m_pStreamAcc = pdfium::MakeUnique<CPDF_StreamAcc>();
297 m_pStreamAcc->LoadAllData(pStream, false, src_size.ValueOrDie(), true); 298 m_pStreamAcc->LoadAllData(pStream, false, src_size.ValueOrDie(), true);
298 if (m_pStreamAcc->GetSize() == 0 || !m_pStreamAcc->GetData()) { 299 if (m_pStreamAcc->GetSize() == 0 || !m_pStreamAcc->GetData()) {
299 return 0; 300 return 0;
300 } 301 }
301 int ret = CreateDecoder(); 302 int ret = CreateDecoder();
302 if (!ret) 303 if (!ret)
303 return ret; 304 return ret;
304 305
305 if (ret != 1) { 306 if (ret != 1) {
306 if (!ContinueToLoadMask()) { 307 if (!ContinueToLoadMask()) {
(...skipping 21 matching lines...) Expand all
328 329
329 int CPDF_DIBSource::ContinueLoadDIBSource(IFX_Pause* pPause) { 330 int CPDF_DIBSource::ContinueLoadDIBSource(IFX_Pause* pPause) {
330 FXCODEC_STATUS ret; 331 FXCODEC_STATUS ret;
331 if (m_Status == 1) { 332 if (m_Status == 1) {
332 const CFX_ByteString& decoder = m_pStreamAcc->GetImageDecoder(); 333 const CFX_ByteString& decoder = m_pStreamAcc->GetImageDecoder();
333 if (decoder == "JPXDecode") { 334 if (decoder == "JPXDecode") {
334 return 0; 335 return 0;
335 } 336 }
336 CCodec_Jbig2Module* pJbig2Module = CPDF_ModuleMgr::Get()->GetJbig2Module(); 337 CCodec_Jbig2Module* pJbig2Module = CPDF_ModuleMgr::Get()->GetJbig2Module();
337 if (!m_pJbig2Context) { 338 if (!m_pJbig2Context) {
338 m_pJbig2Context.reset(new CCodec_Jbig2Context()); 339 m_pJbig2Context = pdfium::MakeUnique<CCodec_Jbig2Context>();
339 if (m_pStreamAcc->GetImageParam()) { 340 if (m_pStreamAcc->GetImageParam()) {
340 CPDF_Stream* pGlobals = 341 CPDF_Stream* pGlobals =
341 m_pStreamAcc->GetImageParam()->GetStreamFor("JBIG2Globals"); 342 m_pStreamAcc->GetImageParam()->GetStreamFor("JBIG2Globals");
342 if (pGlobals) { 343 if (pGlobals) {
343 m_pGlobalStream.reset(new CPDF_StreamAcc); 344 m_pGlobalStream = pdfium::MakeUnique<CPDF_StreamAcc>();
344 m_pGlobalStream->LoadAllData(pGlobals, false); 345 m_pGlobalStream->LoadAllData(pGlobals, false);
345 } 346 }
346 } 347 }
347 ret = pJbig2Module->StartDecode( 348 ret = pJbig2Module->StartDecode(
348 m_pJbig2Context.get(), m_pDocument->CodecContext(), m_Width, m_Height, 349 m_pJbig2Context.get(), m_pDocument->CodecContext(), m_Width, m_Height,
349 m_pStreamAcc.get(), m_pGlobalStream.get(), 350 m_pStreamAcc.get(), m_pGlobalStream.get(),
350 m_pCachedBitmap->GetBuffer(), m_pCachedBitmap->GetPitch(), pPause); 351 m_pCachedBitmap->GetBuffer(), m_pCachedBitmap->GetPitch(), pPause);
351 if (ret < 0) { 352 if (ret < 0) {
352 m_pCachedBitmap.reset(); 353 m_pCachedBitmap.reset();
353 m_pGlobalStream.reset(); 354 m_pGlobalStream.reset();
(...skipping 315 matching lines...) Expand 10 before | Expand all | Expand 10 after
669 format = FXDIB_8bppRgb; 670 format = FXDIB_8bppRgb;
670 } else if (components <= 3) { 671 } else if (components <= 3) {
671 format = FXDIB_Rgb; 672 format = FXDIB_Rgb;
672 } else if (components == 4) { 673 } else if (components == 4) {
673 format = FXDIB_Rgb32; 674 format = FXDIB_Rgb32;
674 } else { 675 } else {
675 width = (width * components + 2) / 3; 676 width = (width * components + 2) / 3;
676 format = FXDIB_Rgb; 677 format = FXDIB_Rgb;
677 } 678 }
678 679
679 m_pCachedBitmap.reset(new CFX_DIBitmap); 680 m_pCachedBitmap = pdfium::MakeUnique<CFX_DIBitmap>();
680 if (!m_pCachedBitmap->Create(width, height, format)) { 681 if (!m_pCachedBitmap->Create(width, height, format)) {
681 m_pCachedBitmap.reset(); 682 m_pCachedBitmap.reset();
682 return; 683 return;
683 } 684 }
684 m_pCachedBitmap->Clear(0xFFFFFFFF); 685 m_pCachedBitmap->Clear(0xFFFFFFFF);
685 std::vector<uint8_t> output_offsets(components); 686 std::vector<uint8_t> output_offsets(components);
686 for (uint32_t i = 0; i < components; ++i) 687 for (uint32_t i = 0; i < components; ++i)
687 output_offsets[i] = i; 688 output_offsets[i] = i;
688 if (bSwapRGB) { 689 if (bSwapRGB) {
689 output_offsets[0] = 2; 690 output_offsets[0] = 2;
(...skipping 780 matching lines...) Expand 10 before | Expand all | Expand 10 after
1470 *pDestPixel++ = FXARGB_G(argb); 1471 *pDestPixel++ = FXARGB_G(argb);
1471 *pDestPixel = FXARGB_R(argb); 1472 *pDestPixel = FXARGB_R(argb);
1472 } 1473 }
1473 } 1474 }
1474 } 1475 }
1475 1476
1476 bool CPDF_DIBSource::TransMask() const { 1477 bool CPDF_DIBSource::TransMask() const {
1477 return m_bLoadMask && m_GroupFamily == PDFCS_DEVICECMYK && 1478 return m_bLoadMask && m_GroupFamily == PDFCS_DEVICECMYK &&
1478 m_Family == PDFCS_DEVICECMYK; 1479 m_Family == PDFCS_DEVICECMYK;
1479 } 1480 }
OLDNEW
« no previous file with comments | « core/fpdfapi/render/cpdf_scaledrenderbuffer.cpp ('k') | core/fpdfdoc/cpdf_variabletext.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698