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

Side by Side Diff: core/src/fpdfapi/fpdf_render/fpdf_render_loadimage.cpp

Issue 1520063002: Get rid of most instance of 'foo == NULL' (Closed) Base URL: https://pdfium.googlesource.com/pdfium@bstr_isnull
Patch Set: rebase Created 5 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 "render_int.h" 7 #include "render_int.h"
8 8
9 #include <vector> 9 #include <vector>
10 10
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after
205 } 205 }
206 FX_BOOL CPDF_DIBSource::Load(CPDF_Document* pDoc, 206 FX_BOOL CPDF_DIBSource::Load(CPDF_Document* pDoc,
207 const CPDF_Stream* pStream, 207 const CPDF_Stream* pStream,
208 CPDF_DIBSource** ppMask, 208 CPDF_DIBSource** ppMask,
209 FX_DWORD* pMatteColor, 209 FX_DWORD* pMatteColor,
210 CPDF_Dictionary* pFormResources, 210 CPDF_Dictionary* pFormResources,
211 CPDF_Dictionary* pPageResources, 211 CPDF_Dictionary* pPageResources,
212 FX_BOOL bStdCS, 212 FX_BOOL bStdCS,
213 FX_DWORD GroupFamily, 213 FX_DWORD GroupFamily,
214 FX_BOOL bLoadMask) { 214 FX_BOOL bLoadMask) {
215 if (pStream == NULL) { 215 if (!pStream) {
216 return FALSE; 216 return FALSE;
217 } 217 }
218 m_pDocument = pDoc; 218 m_pDocument = pDoc;
219 m_pDict = pStream->GetDict(); 219 m_pDict = pStream->GetDict();
220 if (m_pDict == NULL) { 220 if (!m_pDict) {
221 return FALSE; 221 return FALSE;
222 } 222 }
223 m_pStream = pStream; 223 m_pStream = pStream;
224 m_Width = m_pDict->GetInteger("Width"); 224 m_Width = m_pDict->GetInteger("Width");
225 m_Height = m_pDict->GetInteger("Height"); 225 m_Height = m_pDict->GetInteger("Height");
226 if (m_Width <= 0 || m_Height <= 0 || m_Width > kMaxImageDimension || 226 if (m_Width <= 0 || m_Height <= 0 || m_Width > kMaxImageDimension ||
227 m_Height > kMaxImageDimension) { 227 m_Height > kMaxImageDimension) {
228 return FALSE; 228 return FALSE;
229 } 229 }
230 m_GroupFamily = GroupFamily; 230 m_GroupFamily = GroupFamily;
231 m_bLoadMask = bLoadMask; 231 m_bLoadMask = bLoadMask;
232 if (!LoadColorInfo(m_pStream->GetObjNum() != 0 ? NULL : pFormResources, 232 if (!LoadColorInfo(m_pStream->GetObjNum() != 0 ? NULL : pFormResources,
233 pPageResources)) { 233 pPageResources)) {
234 return FALSE; 234 return FALSE;
235 } 235 }
236 if (m_bDoBpcCheck && (m_bpc == 0 || m_nComponents == 0)) { 236 if (m_bDoBpcCheck && (m_bpc == 0 || m_nComponents == 0)) {
237 return FALSE; 237 return FALSE;
238 } 238 }
239 FX_SAFE_DWORD src_size = 239 FX_SAFE_DWORD src_size =
240 CalculatePitch8(m_bpc, m_nComponents, m_Width) * m_Height; 240 CalculatePitch8(m_bpc, m_nComponents, m_Width) * m_Height;
241 if (!src_size.IsValid()) { 241 if (!src_size.IsValid()) {
242 return FALSE; 242 return FALSE;
243 } 243 }
244 m_pStreamAcc = new CPDF_StreamAcc; 244 m_pStreamAcc = new CPDF_StreamAcc;
245 m_pStreamAcc->LoadAllData(pStream, FALSE, src_size.ValueOrDie(), TRUE); 245 m_pStreamAcc->LoadAllData(pStream, FALSE, src_size.ValueOrDie(), TRUE);
246 if (m_pStreamAcc->GetSize() == 0 || m_pStreamAcc->GetData() == NULL) { 246 if (m_pStreamAcc->GetSize() == 0 || !m_pStreamAcc->GetData()) {
247 return FALSE; 247 return FALSE;
248 } 248 }
249 if (!CreateDecoder()) { 249 if (!CreateDecoder()) {
250 return FALSE; 250 return FALSE;
251 } 251 }
252 if (m_bImageMask) { 252 if (m_bImageMask) {
253 m_bpp = 1; 253 m_bpp = 1;
254 m_bpc = 1; 254 m_bpc = 1;
255 m_nComponents = 1; 255 m_nComponents = 1;
256 m_AlphaFlag = 1; 256 m_AlphaFlag = 1;
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
326 return 1; 326 return 1;
327 } 327 }
328 int CPDF_DIBSource::StartLoadDIBSource(CPDF_Document* pDoc, 328 int CPDF_DIBSource::StartLoadDIBSource(CPDF_Document* pDoc,
329 const CPDF_Stream* pStream, 329 const CPDF_Stream* pStream,
330 FX_BOOL bHasMask, 330 FX_BOOL bHasMask,
331 CPDF_Dictionary* pFormResources, 331 CPDF_Dictionary* pFormResources,
332 CPDF_Dictionary* pPageResources, 332 CPDF_Dictionary* pPageResources,
333 FX_BOOL bStdCS, 333 FX_BOOL bStdCS,
334 FX_DWORD GroupFamily, 334 FX_DWORD GroupFamily,
335 FX_BOOL bLoadMask) { 335 FX_BOOL bLoadMask) {
336 if (pStream == NULL) { 336 if (!pStream) {
337 return 0; 337 return 0;
338 } 338 }
339 m_pDocument = pDoc; 339 m_pDocument = pDoc;
340 m_pDict = pStream->GetDict(); 340 m_pDict = pStream->GetDict();
341 m_pStream = pStream; 341 m_pStream = pStream;
342 m_bStdCS = bStdCS; 342 m_bStdCS = bStdCS;
343 m_bHasMask = bHasMask; 343 m_bHasMask = bHasMask;
344 m_Width = m_pDict->GetInteger("Width"); 344 m_Width = m_pDict->GetInteger("Width");
345 m_Height = m_pDict->GetInteger("Height"); 345 m_Height = m_pDict->GetInteger("Height");
346 if (m_Width <= 0 || m_Height <= 0 || m_Width > kMaxImageDimension || 346 if (m_Width <= 0 || m_Height <= 0 || m_Width > kMaxImageDimension ||
347 m_Height > kMaxImageDimension) { 347 m_Height > kMaxImageDimension) {
348 return 0; 348 return 0;
349 } 349 }
350 m_GroupFamily = GroupFamily; 350 m_GroupFamily = GroupFamily;
351 m_bLoadMask = bLoadMask; 351 m_bLoadMask = bLoadMask;
352 if (!LoadColorInfo(m_pStream->GetObjNum() != 0 ? NULL : pFormResources, 352 if (!LoadColorInfo(m_pStream->GetObjNum() != 0 ? NULL : pFormResources,
353 pPageResources)) { 353 pPageResources)) {
354 return 0; 354 return 0;
355 } 355 }
356 if (m_bDoBpcCheck && (m_bpc == 0 || m_nComponents == 0)) { 356 if (m_bDoBpcCheck && (m_bpc == 0 || m_nComponents == 0)) {
357 return 0; 357 return 0;
358 } 358 }
359 FX_SAFE_DWORD src_size = 359 FX_SAFE_DWORD src_size =
360 CalculatePitch8(m_bpc, m_nComponents, m_Width) * m_Height; 360 CalculatePitch8(m_bpc, m_nComponents, m_Width) * m_Height;
361 if (!src_size.IsValid()) { 361 if (!src_size.IsValid()) {
362 return 0; 362 return 0;
363 } 363 }
364 m_pStreamAcc = new CPDF_StreamAcc; 364 m_pStreamAcc = new CPDF_StreamAcc;
365 m_pStreamAcc->LoadAllData(pStream, FALSE, src_size.ValueOrDie(), TRUE); 365 m_pStreamAcc->LoadAllData(pStream, FALSE, src_size.ValueOrDie(), TRUE);
366 if (m_pStreamAcc->GetSize() == 0 || m_pStreamAcc->GetData() == NULL) { 366 if (m_pStreamAcc->GetSize() == 0 || !m_pStreamAcc->GetData()) {
367 return 0; 367 return 0;
368 } 368 }
369 int ret = CreateDecoder(); 369 int ret = CreateDecoder();
370 if (ret != 1) { 370 if (ret != 1) {
371 if (!ret) { 371 if (!ret) {
372 return ret; 372 return ret;
373 } 373 }
374 if (!ContinueToLoadMask()) { 374 if (!ContinueToLoadMask()) {
375 return 0; 375 return 0;
376 } 376 }
(...skipping 17 matching lines...) Expand all
394 return ret; 394 return ret;
395 } 395 }
396 int CPDF_DIBSource::ContinueLoadDIBSource(IFX_Pause* pPause) { 396 int CPDF_DIBSource::ContinueLoadDIBSource(IFX_Pause* pPause) {
397 FXCODEC_STATUS ret; 397 FXCODEC_STATUS ret;
398 if (m_Status == 1) { 398 if (m_Status == 1) {
399 const CFX_ByteString& decoder = m_pStreamAcc->GetImageDecoder(); 399 const CFX_ByteString& decoder = m_pStreamAcc->GetImageDecoder();
400 if (decoder == "JPXDecode") { 400 if (decoder == "JPXDecode") {
401 return 0; 401 return 0;
402 } 402 }
403 ICodec_Jbig2Module* pJbig2Module = CPDF_ModuleMgr::Get()->GetJbig2Module(); 403 ICodec_Jbig2Module* pJbig2Module = CPDF_ModuleMgr::Get()->GetJbig2Module();
404 if (m_pJbig2Context == NULL) { 404 if (!m_pJbig2Context) {
405 m_pJbig2Context = pJbig2Module->CreateJbig2Context(); 405 m_pJbig2Context = pJbig2Module->CreateJbig2Context();
406 if (m_pStreamAcc->GetImageParam()) { 406 if (m_pStreamAcc->GetImageParam()) {
407 CPDF_Stream* pGlobals = 407 CPDF_Stream* pGlobals =
408 m_pStreamAcc->GetImageParam()->GetStream("JBIG2Globals"); 408 m_pStreamAcc->GetImageParam()->GetStream("JBIG2Globals");
409 if (pGlobals) { 409 if (pGlobals) {
410 m_pGlobalStream = new CPDF_StreamAcc; 410 m_pGlobalStream = new CPDF_StreamAcc;
411 m_pGlobalStream->LoadAllData(pGlobals, FALSE); 411 m_pGlobalStream->LoadAllData(pGlobals, FALSE);
412 } 412 }
413 } 413 }
414 ret = pJbig2Module->StartDecode(m_pJbig2Context, m_pDocument, m_Width, 414 ret = pJbig2Module->StartDecode(m_pJbig2Context, m_pDocument, m_Width,
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
524 m_nComponents = 4; 524 m_nComponents = 4;
525 } 525 }
526 } 526 }
527 ValidateDictParam(); 527 ValidateDictParam();
528 m_pCompData = GetDecodeAndMaskArray(m_bDefaultDecode, m_bColorKey); 528 m_pCompData = GetDecodeAndMaskArray(m_bDefaultDecode, m_bColorKey);
529 return !!m_pCompData; 529 return !!m_pCompData;
530 } 530 }
531 531
532 DIB_COMP_DATA* CPDF_DIBSource::GetDecodeAndMaskArray(FX_BOOL& bDefaultDecode, 532 DIB_COMP_DATA* CPDF_DIBSource::GetDecodeAndMaskArray(FX_BOOL& bDefaultDecode,
533 FX_BOOL& bColorKey) { 533 FX_BOOL& bColorKey) {
534 if (m_pColorSpace == NULL) { 534 if (!m_pColorSpace) {
535 return NULL; 535 return NULL;
536 } 536 }
537 DIB_COMP_DATA* pCompData = FX_Alloc(DIB_COMP_DATA, m_nComponents); 537 DIB_COMP_DATA* pCompData = FX_Alloc(DIB_COMP_DATA, m_nComponents);
538 int max_data = (1 << m_bpc) - 1; 538 int max_data = (1 << m_bpc) - 1;
539 CPDF_Array* pDecode = m_pDict->GetArray("Decode"); 539 CPDF_Array* pDecode = m_pDict->GetArray("Decode");
540 if (pDecode) { 540 if (pDecode) {
541 for (FX_DWORD i = 0; i < m_nComponents; i++) { 541 for (FX_DWORD i = 0; i < m_nComponents; i++) {
542 pCompData[i].m_DecodeMin = pDecode->GetNumber(i * 2); 542 pCompData[i].m_DecodeMin = pDecode->GetNumber(i * 2);
543 FX_FLOAT max = pDecode->GetNumber(i * 2 + 1); 543 FX_FLOAT max = pDecode->GetNumber(i * 2 + 1);
544 pCompData[i].m_DecodeStep = (max - pCompData[i].m_DecodeMin) / max_data; 544 pCompData[i].m_DecodeStep = (max - pCompData[i].m_DecodeMin) / max_data;
(...skipping 13 matching lines...) Expand all
558 pCompData[i].m_DecodeStep); 558 pCompData[i].m_DecodeStep);
559 if (m_Family == PDFCS_INDEXED) { 559 if (m_Family == PDFCS_INDEXED) {
560 pCompData[i].m_DecodeStep = (FX_FLOAT)max_data; 560 pCompData[i].m_DecodeStep = (FX_FLOAT)max_data;
561 } 561 }
562 pCompData[i].m_DecodeStep = 562 pCompData[i].m_DecodeStep =
563 (pCompData[i].m_DecodeStep - pCompData[i].m_DecodeMin) / max_data; 563 (pCompData[i].m_DecodeStep - pCompData[i].m_DecodeMin) / max_data;
564 } 564 }
565 } 565 }
566 if (!m_pDict->KeyExist("SMask")) { 566 if (!m_pDict->KeyExist("SMask")) {
567 CPDF_Object* pMask = m_pDict->GetElementValue("Mask"); 567 CPDF_Object* pMask = m_pDict->GetElementValue("Mask");
568 if (pMask == NULL) { 568 if (!pMask) {
569 return pCompData; 569 return pCompData;
570 } 570 }
571 if (CPDF_Array* pArray = pMask->AsArray()) { 571 if (CPDF_Array* pArray = pMask->AsArray()) {
572 if (pArray->GetCount() >= m_nComponents * 2) { 572 if (pArray->GetCount() >= m_nComponents * 2) {
573 for (FX_DWORD i = 0; i < m_nComponents; i++) { 573 for (FX_DWORD i = 0; i < m_nComponents; i++) {
574 int min_num = pArray->GetInteger(i * 2); 574 int min_num = pArray->GetInteger(i * 2);
575 int max_num = pArray->GetInteger(i * 2 + 1); 575 int max_num = pArray->GetInteger(i * 2 + 1);
576 pCompData[i].m_ColorKeyMin = FX_MAX(min_num, 0); 576 pCompData[i].m_ColorKeyMin = FX_MAX(min_num, 0);
577 pCompData[i].m_ColorKeyMax = FX_MIN(max_num, max_data); 577 pCompData[i].m_ColorKeyMax = FX_MIN(max_num, max_data);
578 } 578 }
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
621 if (pJpegModule->LoadInfo(src_data, src_size, m_Width, m_Height, comps, 621 if (pJpegModule->LoadInfo(src_data, src_size, m_Width, m_Height, comps,
622 bpc, bTransform)) { 622 bpc, bTransform)) {
623 if (m_nComponents != comps) { 623 if (m_nComponents != comps) {
624 FX_Free(m_pCompData); 624 FX_Free(m_pCompData);
625 m_nComponents = comps; 625 m_nComponents = comps;
626 if (m_Family == PDFCS_LAB && m_nComponents != 3) { 626 if (m_Family == PDFCS_LAB && m_nComponents != 3) {
627 m_pCompData = NULL; 627 m_pCompData = NULL;
628 return 0; 628 return 0;
629 } 629 }
630 m_pCompData = GetDecodeAndMaskArray(m_bDefaultDecode, m_bColorKey); 630 m_pCompData = GetDecodeAndMaskArray(m_bDefaultDecode, m_bColorKey);
631 if (m_pCompData == NULL) { 631 if (!m_pCompData) {
632 return 0; 632 return 0;
633 } 633 }
634 } 634 }
635 m_bpc = bpc; 635 m_bpc = bpc;
636 m_pDecoder = CPDF_ModuleMgr::Get()->GetJpegModule()->CreateDecoder( 636 m_pDecoder = CPDF_ModuleMgr::Get()->GetJpegModule()->CreateDecoder(
637 src_data, src_size, m_Width, m_Height, m_nComponents, bTransform); 637 src_data, src_size, m_Width, m_Height, m_nComponents, bTransform);
638 } 638 }
639 } 639 }
640 } else if (decoder == "FlateDecode") { 640 } else if (decoder == "FlateDecode") {
641 m_pDecoder = FPDFAPI_CreateFlateDecoder( 641 m_pDecoder = FPDFAPI_CreateFlateDecoder(
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after
800 m_MatteColor = FXARGB_MAKE(0, FXSYS_round(R * 255), FXSYS_round(G * 255), 800 m_MatteColor = FXARGB_MAKE(0, FXSYS_round(R * 255), FXSYS_round(G * 255),
801 FXSYS_round(B * 255)); 801 FXSYS_round(B * 255));
802 } 802 }
803 return StartLoadMaskDIB(); 803 return StartLoadMaskDIB();
804 } 804 }
805 805
806 m_pMaskStream = ToStream(m_pDict->GetElementValue("Mask")); 806 m_pMaskStream = ToStream(m_pDict->GetElementValue("Mask"));
807 return m_pMaskStream ? StartLoadMaskDIB() : 1; 807 return m_pMaskStream ? StartLoadMaskDIB() : 1;
808 } 808 }
809 int CPDF_DIBSource::ContinueLoadMaskDIB(IFX_Pause* pPause) { 809 int CPDF_DIBSource::ContinueLoadMaskDIB(IFX_Pause* pPause) {
810 if (m_pMask == NULL) { 810 if (!m_pMask) {
811 return 1; 811 return 1;
812 } 812 }
813 int ret = m_pMask->ContinueLoadDIBSource(pPause); 813 int ret = m_pMask->ContinueLoadDIBSource(pPause);
814 if (ret == 2) { 814 if (ret == 2) {
815 return ret; 815 return ret;
816 } 816 }
817 if (m_pColorSpace && m_bStdCS) { 817 if (m_pColorSpace && m_bStdCS) {
818 m_pColorSpace->EnableStdConversion(FALSE); 818 m_pColorSpace->EnableStdConversion(FALSE);
819 } 819 }
820 if (!ret) { 820 if (!ret) {
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
853 } 853 }
854 return 1; 854 return 1;
855 } 855 }
856 void CPDF_DIBSource::LoadPalette() { 856 void CPDF_DIBSource::LoadPalette() {
857 if (m_bpc == 0) { 857 if (m_bpc == 0) {
858 return; 858 return;
859 } 859 }
860 if (m_bpc * m_nComponents > 8) { 860 if (m_bpc * m_nComponents > 8) {
861 return; 861 return;
862 } 862 }
863 if (m_pColorSpace == NULL) { 863 if (!m_pColorSpace) {
864 return; 864 return;
865 } 865 }
866 if (m_bpc * m_nComponents == 1) { 866 if (m_bpc * m_nComponents == 1) {
867 if (m_bDefaultDecode && 867 if (m_bDefaultDecode &&
868 (m_Family == PDFCS_DEVICEGRAY || m_Family == PDFCS_DEVICERGB)) { 868 (m_Family == PDFCS_DEVICEGRAY || m_Family == PDFCS_DEVICERGB)) {
869 return; 869 return;
870 } 870 }
871 if (m_pColorSpace->CountComponents() > 3) { 871 if (m_pColorSpace->CountComponents() > 3) {
872 return; 872 return;
873 } 873 }
(...skipping 725 matching lines...) Expand 10 before | Expand all | Expand 10 after
1599 } 1599 }
1600 } 1600 }
1601 return ret; 1601 return ret;
1602 } 1602 }
1603 FX_BOOL CPDF_ImageLoader::Load(const CPDF_ImageObject* pImage, 1603 FX_BOOL CPDF_ImageLoader::Load(const CPDF_ImageObject* pImage,
1604 CPDF_PageRenderCache* pCache, 1604 CPDF_PageRenderCache* pCache,
1605 FX_BOOL bStdCS, 1605 FX_BOOL bStdCS,
1606 FX_DWORD GroupFamily, 1606 FX_DWORD GroupFamily,
1607 FX_BOOL bLoadMask, 1607 FX_BOOL bLoadMask,
1608 CPDF_RenderStatus* pRenderStatus) { 1608 CPDF_RenderStatus* pRenderStatus) {
1609 if (pImage == NULL) { 1609 if (!pImage) {
1610 return FALSE; 1610 return FALSE;
1611 } 1611 }
1612 if (pCache) { 1612 if (pCache) {
1613 pCache->GetCachedBitmap(pImage->m_pImage->GetStream(), m_pBitmap, m_pMask, 1613 pCache->GetCachedBitmap(pImage->m_pImage->GetStream(), m_pBitmap, m_pMask,
1614 m_MatteColor, bStdCS, GroupFamily, bLoadMask, 1614 m_MatteColor, bStdCS, GroupFamily, bLoadMask,
1615 pRenderStatus, m_nDownsampleWidth, 1615 pRenderStatus, m_nDownsampleWidth,
1616 m_nDownsampleHeight); 1616 m_nDownsampleHeight);
1617 m_bCached = TRUE; 1617 m_bCached = TRUE;
1618 } else { 1618 } else {
1619 m_pBitmap = pImage->m_pImage->LoadDIBSource(&m_pMask, &m_MatteColor, bStdCS, 1619 m_pBitmap = pImage->m_pImage->LoadDIBSource(&m_pMask, &m_MatteColor, bStdCS,
(...skipping 23 matching lines...) Expand all
1643 } 1643 }
1644 FX_BOOL CPDF_ImageLoader::Continue(void* LoadHandle, IFX_Pause* pPause) { 1644 FX_BOOL CPDF_ImageLoader::Continue(void* LoadHandle, IFX_Pause* pPause) {
1645 return ((CPDF_ProgressiveImageLoaderHandle*)LoadHandle)->Continue(pPause); 1645 return ((CPDF_ProgressiveImageLoaderHandle*)LoadHandle)->Continue(pPause);
1646 } 1646 }
1647 CPDF_ImageLoader::~CPDF_ImageLoader() { 1647 CPDF_ImageLoader::~CPDF_ImageLoader() {
1648 if (!m_bCached) { 1648 if (!m_bCached) {
1649 delete m_pBitmap; 1649 delete m_pBitmap;
1650 delete m_pMask; 1650 delete m_pMask;
1651 } 1651 }
1652 } 1652 }
OLDNEW
« no previous file with comments | « core/src/fpdfapi/fpdf_render/fpdf_render_image.cpp ('k') | core/src/fpdfapi/fpdf_render/fpdf_render_pattern.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698