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

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

Issue 1783933002: Change colorspace's number of components to be unsigned (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: address comments Created 4 years, 9 months 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/src/fpdfapi/fpdf_render/render_int.h" 7 #include "core/src/fpdfapi/fpdf_render/render_int.h"
8 8
9 #include <algorithm> 9 #include <algorithm>
10 #include <memory> 10 #include <memory>
(...skipping 691 matching lines...) Expand 10 before | Expand all | Expand 10 after
702 702
703 FX_DWORD width = 0; 703 FX_DWORD width = 0;
704 FX_DWORD height = 0; 704 FX_DWORD height = 0;
705 FX_DWORD components = 0; 705 FX_DWORD components = 0;
706 pJpxModule->GetImageInfo(context->decoder(), &width, &height, &components); 706 pJpxModule->GetImageInfo(context->decoder(), &width, &height, &components);
707 if (static_cast<int>(width) < m_Width || static_cast<int>(height) < m_Height) 707 if (static_cast<int>(width) < m_Width || static_cast<int>(height) < m_Height)
708 return; 708 return;
709 709
710 FX_BOOL bSwapRGB = FALSE; 710 FX_BOOL bSwapRGB = FALSE;
711 if (m_pColorSpace) { 711 if (m_pColorSpace) {
712 if (components != (FX_DWORD)m_pColorSpace->CountComponents()) 712 if (components != m_pColorSpace->CountComponents())
713 return; 713 return;
714 714
715 if (m_pColorSpace == CPDF_ColorSpace::GetStockCS(PDFCS_DEVICERGB)) { 715 if (m_pColorSpace == CPDF_ColorSpace::GetStockCS(PDFCS_DEVICERGB)) {
716 bSwapRGB = TRUE; 716 bSwapRGB = TRUE;
717 m_pColorSpace = nullptr; 717 m_pColorSpace = nullptr;
718 } 718 }
719 } else { 719 } else {
720 if (components == 3) { 720 if (components == 3) {
721 bSwapRGB = TRUE; 721 bSwapRGB = TRUE;
722 } else if (components == 4) { 722 } else if (components == 4) {
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
769 } 769 }
770 m_bpc = 8; 770 m_bpc = 8;
771 } 771 }
772 772
773 CPDF_DIBSource* CPDF_DIBSource::LoadMask(FX_DWORD& MatteColor) { 773 CPDF_DIBSource* CPDF_DIBSource::LoadMask(FX_DWORD& MatteColor) {
774 MatteColor = 0xFFFFFFFF; 774 MatteColor = 0xFFFFFFFF;
775 CPDF_Stream* pSoftMask = m_pDict->GetStreamBy("SMask"); 775 CPDF_Stream* pSoftMask = m_pDict->GetStreamBy("SMask");
776 if (pSoftMask) { 776 if (pSoftMask) {
777 CPDF_Array* pMatte = pSoftMask->GetDict()->GetArrayBy("Matte"); 777 CPDF_Array* pMatte = pSoftMask->GetDict()->GetArrayBy("Matte");
778 if (pMatte && m_pColorSpace && 778 if (pMatte && m_pColorSpace &&
779 (FX_DWORD)m_pColorSpace->CountComponents() <= m_nComponents) { 779 m_pColorSpace->CountComponents() <= m_nComponents) {
780 std::vector<FX_FLOAT> colors(m_nComponents); 780 std::vector<FX_FLOAT> colors(m_nComponents);
781 for (FX_DWORD i = 0; i < m_nComponents; i++) { 781 for (FX_DWORD i = 0; i < m_nComponents; i++) {
782 colors[i] = pMatte->GetFloatAt(i); 782 colors[i] = pMatte->GetFloatAt(i);
783 } 783 }
784 FX_FLOAT R, G, B; 784 FX_FLOAT R, G, B;
785 m_pColorSpace->GetRGB(colors.data(), R, G, B); 785 m_pColorSpace->GetRGB(colors.data(), R, G, B);
786 MatteColor = FXARGB_MAKE(0, FXSYS_round(R * 255), FXSYS_round(G * 255), 786 MatteColor = FXARGB_MAKE(0, FXSYS_round(R * 255), FXSYS_round(G * 255),
787 FXSYS_round(B * 255)); 787 FXSYS_round(B * 255));
788 } 788 }
789 return LoadMaskDIB(pSoftMask); 789 return LoadMaskDIB(pSoftMask);
790 } 790 }
791 791
792 if (CPDF_Stream* pStream = ToStream(m_pDict->GetElementValue("Mask"))) 792 if (CPDF_Stream* pStream = ToStream(m_pDict->GetElementValue("Mask")))
793 return LoadMaskDIB(pStream); 793 return LoadMaskDIB(pStream);
794 794
795 return nullptr; 795 return nullptr;
796 } 796 }
797 797
798 int CPDF_DIBSource::StratLoadMask() { 798 int CPDF_DIBSource::StratLoadMask() {
799 m_MatteColor = 0XFFFFFFFF; 799 m_MatteColor = 0XFFFFFFFF;
800 m_pMaskStream = m_pDict->GetStreamBy("SMask"); 800 m_pMaskStream = m_pDict->GetStreamBy("SMask");
801 if (m_pMaskStream) { 801 if (m_pMaskStream) {
802 CPDF_Array* pMatte = m_pMaskStream->GetDict()->GetArrayBy("Matte"); 802 CPDF_Array* pMatte = m_pMaskStream->GetDict()->GetArrayBy("Matte");
803 if (pMatte && m_pColorSpace && 803 if (pMatte && m_pColorSpace &&
804 (FX_DWORD)m_pColorSpace->CountComponents() <= m_nComponents) { 804 m_pColorSpace->CountComponents() <= m_nComponents) {
805 FX_FLOAT R, G, B; 805 FX_FLOAT R, G, B;
806 std::vector<FX_FLOAT> colors(m_nComponents); 806 std::vector<FX_FLOAT> colors(m_nComponents);
807 for (FX_DWORD i = 0; i < m_nComponents; i++) { 807 for (FX_DWORD i = 0; i < m_nComponents; i++) {
808 colors[i] = pMatte->GetFloatAt(i); 808 colors[i] = pMatte->GetFloatAt(i);
809 } 809 }
810 m_pColorSpace->GetRGB(colors.data(), R, G, B); 810 m_pColorSpace->GetRGB(colors.data(), R, G, B);
811 m_MatteColor = FXARGB_MAKE(0, FXSYS_round(R * 255), FXSYS_round(G * 255), 811 m_MatteColor = FXARGB_MAKE(0, FXSYS_round(R * 255), FXSYS_round(G * 255),
812 FXSYS_round(B * 255)); 812 FXSYS_round(B * 255));
813 } 813 }
814 return StartLoadMaskDIB(); 814 return StartLoadMaskDIB();
(...skipping 827 matching lines...) Expand 10 before | Expand all | Expand 10 after
1642 IFX_Pause* pPause) { 1642 IFX_Pause* pPause) {
1643 return LoadHandle->Continue(pPause); 1643 return LoadHandle->Continue(pPause);
1644 } 1644 }
1645 1645
1646 CPDF_ImageLoader::~CPDF_ImageLoader() { 1646 CPDF_ImageLoader::~CPDF_ImageLoader() {
1647 if (!m_bCached) { 1647 if (!m_bCached) {
1648 delete m_pBitmap; 1648 delete m_pBitmap;
1649 delete m_pMask; 1649 delete m_pMask;
1650 } 1650 }
1651 } 1651 }
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