OLD | NEW |
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/fpdf_render/render_int.h" | 7 #include "core/fpdfapi/fpdf_render/render_int.h" |
8 | 8 |
9 #include <algorithm> | 9 #include <algorithm> |
10 #include <memory> | 10 #include <memory> |
(...skipping 402 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
413 } | 413 } |
414 | 414 |
415 bool CPDF_DIBSource::LoadColorInfo(const CPDF_Dictionary* pFormResources, | 415 bool CPDF_DIBSource::LoadColorInfo(const CPDF_Dictionary* pFormResources, |
416 const CPDF_Dictionary* pPageResources) { | 416 const CPDF_Dictionary* pPageResources) { |
417 m_bpc_orig = m_pDict->GetIntegerBy("BitsPerComponent"); | 417 m_bpc_orig = m_pDict->GetIntegerBy("BitsPerComponent"); |
418 if (m_pDict->GetIntegerBy("ImageMask")) | 418 if (m_pDict->GetIntegerBy("ImageMask")) |
419 m_bImageMask = TRUE; | 419 m_bImageMask = TRUE; |
420 | 420 |
421 if (m_bImageMask || !m_pDict->KeyExist("ColorSpace")) { | 421 if (m_bImageMask || !m_pDict->KeyExist("ColorSpace")) { |
422 if (!m_bImageMask) { | 422 if (!m_bImageMask) { |
423 CPDF_Object* pFilter = m_pDict->GetElementValue("Filter"); | 423 CPDF_Object* pFilter = m_pDict->GetDirectObjectBy("Filter"); |
424 if (pFilter) { | 424 if (pFilter) { |
425 CFX_ByteString filter; | 425 CFX_ByteString filter; |
426 if (pFilter->IsName()) { | 426 if (pFilter->IsName()) { |
427 filter = pFilter->GetString(); | 427 filter = pFilter->GetString(); |
428 } else if (CPDF_Array* pArray = pFilter->AsArray()) { | 428 } else if (CPDF_Array* pArray = pFilter->AsArray()) { |
429 filter = pArray->GetStringAt(pArray->GetCount() - 1); | 429 filter = pArray->GetStringAt(pArray->GetCount() - 1); |
430 } | 430 } |
431 | 431 |
432 if (filter == "JPXDecode") { | 432 if (filter == "JPXDecode") { |
433 m_bDoBpcCheck = FALSE; | 433 m_bDoBpcCheck = FALSE; |
434 return true; | 434 return true; |
435 } | 435 } |
436 } | 436 } |
437 } | 437 } |
438 m_bImageMask = TRUE; | 438 m_bImageMask = TRUE; |
439 m_bpc = m_nComponents = 1; | 439 m_bpc = m_nComponents = 1; |
440 CPDF_Array* pDecode = m_pDict->GetArrayBy("Decode"); | 440 CPDF_Array* pDecode = m_pDict->GetArrayBy("Decode"); |
441 m_bDefaultDecode = !pDecode || !pDecode->GetIntegerAt(0); | 441 m_bDefaultDecode = !pDecode || !pDecode->GetIntegerAt(0); |
442 return true; | 442 return true; |
443 } | 443 } |
444 | 444 |
445 CPDF_Object* pCSObj = m_pDict->GetElementValue("ColorSpace"); | 445 CPDF_Object* pCSObj = m_pDict->GetDirectObjectBy("ColorSpace"); |
446 if (!pCSObj) | 446 if (!pCSObj) |
447 return false; | 447 return false; |
448 | 448 |
449 CPDF_DocPageData* pDocPageData = m_pDocument->GetPageData(); | 449 CPDF_DocPageData* pDocPageData = m_pDocument->GetPageData(); |
450 if (pFormResources) | 450 if (pFormResources) |
451 m_pColorSpace = pDocPageData->GetColorSpace(pCSObj, pFormResources); | 451 m_pColorSpace = pDocPageData->GetColorSpace(pCSObj, pFormResources); |
452 if (!m_pColorSpace) | 452 if (!m_pColorSpace) |
453 m_pColorSpace = pDocPageData->GetColorSpace(pCSObj, pPageResources); | 453 m_pColorSpace = pDocPageData->GetColorSpace(pCSObj, pPageResources); |
454 if (!m_pColorSpace) | 454 if (!m_pColorSpace) |
455 return false; | 455 return false; |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
501 m_pColorSpace->GetDefaultValue(i, def_value, pCompData[i].m_DecodeMin, | 501 m_pColorSpace->GetDefaultValue(i, def_value, pCompData[i].m_DecodeMin, |
502 pCompData[i].m_DecodeStep); | 502 pCompData[i].m_DecodeStep); |
503 if (m_Family == PDFCS_INDEXED) { | 503 if (m_Family == PDFCS_INDEXED) { |
504 pCompData[i].m_DecodeStep = max_data; | 504 pCompData[i].m_DecodeStep = max_data; |
505 } | 505 } |
506 pCompData[i].m_DecodeStep = | 506 pCompData[i].m_DecodeStep = |
507 (pCompData[i].m_DecodeStep - pCompData[i].m_DecodeMin) / max_data; | 507 (pCompData[i].m_DecodeStep - pCompData[i].m_DecodeMin) / max_data; |
508 } | 508 } |
509 } | 509 } |
510 if (!m_pDict->KeyExist("SMask")) { | 510 if (!m_pDict->KeyExist("SMask")) { |
511 CPDF_Object* pMask = m_pDict->GetElementValue("Mask"); | 511 CPDF_Object* pMask = m_pDict->GetDirectObjectBy("Mask"); |
512 if (!pMask) { | 512 if (!pMask) { |
513 return pCompData; | 513 return pCompData; |
514 } | 514 } |
515 if (CPDF_Array* pArray = pMask->AsArray()) { | 515 if (CPDF_Array* pArray = pMask->AsArray()) { |
516 if (pArray->GetCount() >= m_nComponents * 2) { | 516 if (pArray->GetCount() >= m_nComponents * 2) { |
517 for (uint32_t i = 0; i < m_nComponents; i++) { | 517 for (uint32_t i = 0; i < m_nComponents; i++) { |
518 int min_num = pArray->GetIntegerAt(i * 2); | 518 int min_num = pArray->GetIntegerAt(i * 2); |
519 int max_num = pArray->GetIntegerAt(i * 2 + 1); | 519 int max_num = pArray->GetIntegerAt(i * 2 + 1); |
520 pCompData[i].m_ColorKeyMin = std::max(min_num, 0); | 520 pCompData[i].m_ColorKeyMin = std::max(min_num, 0); |
521 pCompData[i].m_ColorKeyMax = std::min(max_num, max_data); | 521 pCompData[i].m_ColorKeyMax = std::min(max_num, max_data); |
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
720 colors[i] = pMatte->GetFloatAt(i); | 720 colors[i] = pMatte->GetFloatAt(i); |
721 } | 721 } |
722 FX_FLOAT R, G, B; | 722 FX_FLOAT R, G, B; |
723 m_pColorSpace->GetRGB(colors.data(), R, G, B); | 723 m_pColorSpace->GetRGB(colors.data(), R, G, B); |
724 MatteColor = FXARGB_MAKE(0, FXSYS_round(R * 255), FXSYS_round(G * 255), | 724 MatteColor = FXARGB_MAKE(0, FXSYS_round(R * 255), FXSYS_round(G * 255), |
725 FXSYS_round(B * 255)); | 725 FXSYS_round(B * 255)); |
726 } | 726 } |
727 return LoadMaskDIB(pSoftMask); | 727 return LoadMaskDIB(pSoftMask); |
728 } | 728 } |
729 | 729 |
730 if (CPDF_Stream* pStream = ToStream(m_pDict->GetElementValue("Mask"))) | 730 if (CPDF_Stream* pStream = ToStream(m_pDict->GetDirectObjectBy("Mask"))) |
731 return LoadMaskDIB(pStream); | 731 return LoadMaskDIB(pStream); |
732 | 732 |
733 return nullptr; | 733 return nullptr; |
734 } | 734 } |
735 | 735 |
736 int CPDF_DIBSource::StratLoadMask() { | 736 int CPDF_DIBSource::StratLoadMask() { |
737 m_MatteColor = 0XFFFFFFFF; | 737 m_MatteColor = 0XFFFFFFFF; |
738 m_pMaskStream = m_pDict->GetStreamBy("SMask"); | 738 m_pMaskStream = m_pDict->GetStreamBy("SMask"); |
739 if (m_pMaskStream) { | 739 if (m_pMaskStream) { |
740 CPDF_Array* pMatte = m_pMaskStream->GetDict()->GetArrayBy("Matte"); | 740 CPDF_Array* pMatte = m_pMaskStream->GetDict()->GetArrayBy("Matte"); |
741 if (pMatte && m_pColorSpace && | 741 if (pMatte && m_pColorSpace && |
742 m_pColorSpace->CountComponents() <= m_nComponents) { | 742 m_pColorSpace->CountComponents() <= m_nComponents) { |
743 FX_FLOAT R, G, B; | 743 FX_FLOAT R, G, B; |
744 std::vector<FX_FLOAT> colors(m_nComponents); | 744 std::vector<FX_FLOAT> colors(m_nComponents); |
745 for (uint32_t i = 0; i < m_nComponents; i++) { | 745 for (uint32_t i = 0; i < m_nComponents; i++) { |
746 colors[i] = pMatte->GetFloatAt(i); | 746 colors[i] = pMatte->GetFloatAt(i); |
747 } | 747 } |
748 m_pColorSpace->GetRGB(colors.data(), R, G, B); | 748 m_pColorSpace->GetRGB(colors.data(), R, G, B); |
749 m_MatteColor = FXARGB_MAKE(0, FXSYS_round(R * 255), FXSYS_round(G * 255), | 749 m_MatteColor = FXARGB_MAKE(0, FXSYS_round(R * 255), FXSYS_round(G * 255), |
750 FXSYS_round(B * 255)); | 750 FXSYS_round(B * 255)); |
751 } | 751 } |
752 return StartLoadMaskDIB(); | 752 return StartLoadMaskDIB(); |
753 } | 753 } |
754 | 754 |
755 m_pMaskStream = ToStream(m_pDict->GetElementValue("Mask")); | 755 m_pMaskStream = ToStream(m_pDict->GetDirectObjectBy("Mask")); |
756 return m_pMaskStream ? StartLoadMaskDIB() : 1; | 756 return m_pMaskStream ? StartLoadMaskDIB() : 1; |
757 } | 757 } |
758 | 758 |
759 int CPDF_DIBSource::ContinueLoadMaskDIB(IFX_Pause* pPause) { | 759 int CPDF_DIBSource::ContinueLoadMaskDIB(IFX_Pause* pPause) { |
760 if (!m_pMask) { | 760 if (!m_pMask) { |
761 return 1; | 761 return 1; |
762 } | 762 } |
763 int ret = m_pMask->ContinueLoadDIBSource(pPause); | 763 int ret = m_pMask->ContinueLoadDIBSource(pPause); |
764 if (ret == 2) { | 764 if (ret == 2) { |
765 return ret; | 765 return ret; |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
872 m_pColorSpace->GetRGB(color_value, R, G, B); | 872 m_pColorSpace->GetRGB(color_value, R, G, B); |
873 } | 873 } |
874 SetPaletteArgb(i, ArgbEncode(255, FXSYS_round(R * 255), | 874 SetPaletteArgb(i, ArgbEncode(255, FXSYS_round(R * 255), |
875 FXSYS_round(G * 255), FXSYS_round(B * 255))); | 875 FXSYS_round(G * 255), FXSYS_round(B * 255))); |
876 } | 876 } |
877 } | 877 } |
878 } | 878 } |
879 | 879 |
880 void CPDF_DIBSource::ValidateDictParam() { | 880 void CPDF_DIBSource::ValidateDictParam() { |
881 m_bpc = m_bpc_orig; | 881 m_bpc = m_bpc_orig; |
882 CPDF_Object* pFilter = m_pDict->GetElementValue("Filter"); | 882 CPDF_Object* pFilter = m_pDict->GetDirectObjectBy("Filter"); |
883 if (pFilter) { | 883 if (pFilter) { |
884 if (pFilter->IsName()) { | 884 if (pFilter->IsName()) { |
885 CFX_ByteString filter = pFilter->GetString(); | 885 CFX_ByteString filter = pFilter->GetString(); |
886 if (filter == "CCITTFaxDecode" || filter == "JBIG2Decode") { | 886 if (filter == "CCITTFaxDecode" || filter == "JBIG2Decode") { |
887 m_bpc = 1; | 887 m_bpc = 1; |
888 m_nComponents = 1; | 888 m_nComponents = 1; |
889 } else if (filter == "RunLengthDecode") { | 889 } else if (filter == "RunLengthDecode") { |
890 if (m_bpc != 1) { | 890 if (m_bpc != 1) { |
891 m_bpc = 8; | 891 m_bpc = 8; |
892 } | 892 } |
(...skipping 689 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1582 IFX_Pause* pPause) { | 1582 IFX_Pause* pPause) { |
1583 return LoadHandle->Continue(pPause); | 1583 return LoadHandle->Continue(pPause); |
1584 } | 1584 } |
1585 | 1585 |
1586 CPDF_ImageLoader::~CPDF_ImageLoader() { | 1586 CPDF_ImageLoader::~CPDF_ImageLoader() { |
1587 if (!m_bCached) { | 1587 if (!m_bCached) { |
1588 delete m_pBitmap; | 1588 delete m_pBitmap; |
1589 delete m_pMask; | 1589 delete m_pMask; |
1590 } | 1590 } |
1591 } | 1591 } |
OLD | NEW |