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

Side by Side Diff: core/src/fpdfapi/fpdf_page/fpdf_page_colors.cpp

Issue 656753002: Store the address of the page data map's value for proper referencing. (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: typedef Created 6 years, 2 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 "../../../include/fpdfapi/fpdf_page.h" 7 #include "../../../include/fpdfapi/fpdf_page.h"
8 #include "../../../include/fpdfapi/fpdf_module.h" 8 #include "../../../include/fpdfapi/fpdf_module.h"
9 #include "../../../include/fxcodec/fx_codec.h" 9 #include "../../../include/fxcodec/fx_codec.h"
10 #include "pageint.h" 10 #include "pageint.h"
(...skipping 742 matching lines...) Expand 10 before | Expand all | Expand 10 after
753 min = 0; 753 min = 0;
754 max = (FX_FLOAT)m_MaxIndex; 754 max = (FX_FLOAT)m_MaxIndex;
755 } 755 }
756 virtual FX_BOOL GetRGB(FX_FLOAT* pBuf, FX_FLOAT& R, FX_FLOAT& G, FX_FLOAT& B) const; 756 virtual FX_BOOL GetRGB(FX_FLOAT* pBuf, FX_FLOAT& R, FX_FLOAT& G, FX_FLOAT& B) const;
757 virtual CPDF_ColorSpace* GetBaseCS() const 757 virtual CPDF_ColorSpace* GetBaseCS() const
758 { 758 {
759 return m_pBaseCS; 759 return m_pBaseCS;
760 } 760 }
761 virtual void EnableStdConversion(FX_BOOL bEnabled); 761 virtual void EnableStdConversion(FX_BOOL bEnabled);
762 CPDF_ColorSpace* m_pBaseCS; 762 CPDF_ColorSpace* m_pBaseCS;
763 CPDF_CountedColorSpace* m_pCountedBaseCS;
763 int m_nBaseComponents; 764 int m_nBaseComponents;
764 int m_MaxIndex; 765 int m_MaxIndex;
765 CFX_ByteString m_Table; 766 CFX_ByteString m_Table;
766 FX_FLOAT* m_pCompMinMax; 767 FX_FLOAT* m_pCompMinMax;
767 }; 768 };
768 CPDF_IndexedCS::CPDF_IndexedCS() 769 CPDF_IndexedCS::CPDF_IndexedCS()
769 { 770 {
770 m_pBaseCS = NULL; 771 m_pBaseCS = NULL;
772 m_pCountedBaseCS = NULL;
771 m_Family = PDFCS_INDEXED; 773 m_Family = PDFCS_INDEXED;
772 m_nComponents = 1; 774 m_nComponents = 1;
773 m_pCompMinMax = NULL; 775 m_pCompMinMax = NULL;
774 } 776 }
775 CPDF_IndexedCS::~CPDF_IndexedCS() 777 CPDF_IndexedCS::~CPDF_IndexedCS()
776 { 778 {
777 if (m_pCompMinMax) { 779 if (m_pCompMinMax) {
778 FX_Free(m_pCompMinMax); 780 FX_Free(m_pCompMinMax);
779 } 781 }
782 CPDF_ColorSpace* pCS = m_pCountedBaseCS ? m_pCountedBaseCS->m_Obj : NULL;
783 if (pCS && m_pDocument) {
784 m_pDocument->GetPageData()->ReleaseColorSpace(pCS->GetArray());
785 }
780 } 786 }
781 FX_BOOL CPDF_IndexedCS::v_Load(CPDF_Document* pDoc, CPDF_Array* pArray) 787 FX_BOOL CPDF_IndexedCS::v_Load(CPDF_Document* pDoc, CPDF_Array* pArray)
782 { 788 {
783 if (pArray->GetCount() < 4) { 789 if (pArray->GetCount() < 4) {
784 return FALSE; 790 return FALSE;
785 } 791 }
786 CPDF_Object* pBaseObj = pArray->GetElementValue(1); 792 CPDF_Object* pBaseObj = pArray->GetElementValue(1);
787 if (pBaseObj == m_pArray) { 793 if (pBaseObj == m_pArray) {
788 return FALSE; 794 return FALSE;
789 } 795 }
790 CPDF_DocPageData* pDocPageData = pDoc->GetPageData(); 796 CPDF_DocPageData* pDocPageData = pDoc->GetPageData();
791 m_pBaseCS = pDocPageData->GetColorSpace(pBaseObj, NULL); 797 m_pBaseCS = pDocPageData->GetColorSpace(pBaseObj, NULL);
792 if (m_pBaseCS == NULL) { 798 if (m_pBaseCS == NULL) {
793 return FALSE; 799 return FALSE;
794 } 800 }
801 m_pCountedBaseCS = pDocPageData->FindColorSpacePtr(m_pBaseCS->GetArray());
795 m_nBaseComponents = m_pBaseCS->CountComponents(); 802 m_nBaseComponents = m_pBaseCS->CountComponents();
796 m_pCompMinMax = FX_Alloc(FX_FLOAT, m_nBaseComponents * 2); 803 m_pCompMinMax = FX_Alloc(FX_FLOAT, m_nBaseComponents * 2);
797 FX_FLOAT defvalue; 804 FX_FLOAT defvalue;
798 for (int i = 0; i < m_nBaseComponents; i ++) { 805 for (int i = 0; i < m_nBaseComponents; i ++) {
799 m_pBaseCS->GetDefaultValue(i, defvalue, m_pCompMinMax[i * 2], m_pCompMin Max[i * 2 + 1]); 806 m_pBaseCS->GetDefaultValue(i, defvalue, m_pCompMinMax[i * 2], m_pCompMin Max[i * 2 + 1]);
800 m_pCompMinMax[i * 2 + 1] -= m_pCompMinMax[i * 2]; 807 m_pCompMinMax[i * 2 + 1] -= m_pCompMinMax[i * 2];
801 } 808 }
802 m_MaxIndex = pArray->GetInteger(2); 809 m_MaxIndex = pArray->GetInteger(2);
803 CPDF_Object* pTableObj = pArray->GetElementValue(3); 810 CPDF_Object* pTableObj = pArray->GetElementValue(3);
804 if (pTableObj == NULL) { 811 if (pTableObj == NULL) {
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
838 void CPDF_IndexedCS::EnableStdConversion(FX_BOOL bEnabled) 845 void CPDF_IndexedCS::EnableStdConversion(FX_BOOL bEnabled)
839 { 846 {
840 CPDF_ColorSpace::EnableStdConversion(bEnabled); 847 CPDF_ColorSpace::EnableStdConversion(bEnabled);
841 if (m_pBaseCS) { 848 if (m_pBaseCS) {
842 m_pBaseCS->EnableStdConversion(bEnabled); 849 m_pBaseCS->EnableStdConversion(bEnabled);
843 } 850 }
844 } 851 }
845 #define MAX_PATTERN_COLORCOMPS 16 852 #define MAX_PATTERN_COLORCOMPS 16
846 typedef struct _PatternValue { 853 typedef struct _PatternValue {
847 CPDF_Pattern* m_pPattern; 854 CPDF_Pattern* m_pPattern;
855 CPDF_CountedPattern* m_pCountedPattern;
848 int m_nComps; 856 int m_nComps;
849 FX_FLOAT m_Comps[MAX_PATTERN_COLORCOMPS]; 857 FX_FLOAT m_Comps[MAX_PATTERN_COLORCOMPS];
850 } PatternValue; 858 } PatternValue;
851 CPDF_PatternCS::CPDF_PatternCS() 859 CPDF_PatternCS::CPDF_PatternCS()
852 { 860 {
853 m_Family = PDFCS_PATTERN; 861 m_Family = PDFCS_PATTERN;
854 m_pBaseCS = NULL; 862 m_pBaseCS = NULL;
855 m_nComponents = 1; 863 m_nComponents = 1;
864 m_pCountedBaseCS = NULL;
856 } 865 }
857 CPDF_PatternCS::~CPDF_PatternCS() 866 CPDF_PatternCS::~CPDF_PatternCS()
858 { 867 {
868 CPDF_ColorSpace* pCS = m_pCountedBaseCS ? m_pCountedBaseCS->m_Obj : NULL;
869 if (pCS && m_pDocument) {
870 m_pDocument->GetPageData()->ReleaseColorSpace(pCS->GetArray());
871 }
859 } 872 }
860 FX_BOOL CPDF_PatternCS::v_Load(CPDF_Document* pDoc, CPDF_Array* pArray) 873 FX_BOOL CPDF_PatternCS::v_Load(CPDF_Document* pDoc, CPDF_Array* pArray)
861 { 874 {
862 CPDF_Object* pBaseCS = pArray->GetElementValue(1); 875 CPDF_Object* pBaseCS = pArray->GetElementValue(1);
863 if (pBaseCS == m_pArray) { 876 if (pBaseCS == m_pArray) {
864 return FALSE; 877 return FALSE;
865 } 878 }
866 CPDF_DocPageData* pDocPageData = pDoc->GetPageData(); 879 CPDF_DocPageData* pDocPageData = pDoc->GetPageData();
867 m_pBaseCS = pDocPageData->GetColorSpace(pBaseCS, NULL); 880 m_pBaseCS = pDocPageData->GetColorSpace(pBaseCS, NULL);
868 if (m_pBaseCS) { 881 if (m_pBaseCS) {
869 if (m_pBaseCS->GetFamily() == PDFCS_PATTERN) { 882 if (m_pBaseCS->GetFamily() == PDFCS_PATTERN) {
870 return FALSE; 883 return FALSE;
871 } 884 }
885 m_pCountedBaseCS = pDocPageData->FindColorSpacePtr(m_pBaseCS->GetArray() );
872 m_nComponents = m_pBaseCS->CountComponents() + 1; 886 m_nComponents = m_pBaseCS->CountComponents() + 1;
873 if (m_pBaseCS->CountComponents() > MAX_PATTERN_COLORCOMPS) { 887 if (m_pBaseCS->CountComponents() > MAX_PATTERN_COLORCOMPS) {
874 return FALSE; 888 return FALSE;
875 } 889 }
876 } else { 890 } else {
877 m_nComponents = 1; 891 m_nComponents = 1;
878 } 892 }
879 return TRUE; 893 return TRUE;
880 } 894 }
881 FX_BOOL CPDF_PatternCS::GetRGB(FX_FLOAT* pBuf, FX_FLOAT& R, FX_FLOAT& G, FX_FLOA T& B) const 895 FX_BOOL CPDF_PatternCS::GetRGB(FX_FLOAT* pBuf, FX_FLOAT& R, FX_FLOAT& G, FX_FLOA T& B) const
(...skipping 402 matching lines...) Expand 10 before | Expand all | Expand 10 after
1284 ReleaseBuffer(); 1298 ReleaseBuffer();
1285 ReleaseColorSpace(); 1299 ReleaseColorSpace();
1286 } 1300 }
1287 void CPDF_Color::ReleaseBuffer() 1301 void CPDF_Color::ReleaseBuffer()
1288 { 1302 {
1289 if (!m_pBuffer) { 1303 if (!m_pBuffer) {
1290 return; 1304 return;
1291 } 1305 }
1292 if (m_pCS->GetFamily() == PDFCS_PATTERN) { 1306 if (m_pCS->GetFamily() == PDFCS_PATTERN) {
1293 PatternValue* pvalue = (PatternValue*)m_pBuffer; 1307 PatternValue* pvalue = (PatternValue*)m_pBuffer;
1294 CPDF_Pattern* pPattern = pvalue->m_pPattern; 1308 CPDF_Pattern* pPattern = pvalue->m_pCountedPattern ? pvalue->m_pCountedP attern->m_Obj : NULL;
1295 if (pPattern && pPattern->m_pDocument) { 1309 if (pPattern && pPattern->m_pDocument) {
1296 CPDF_DocPageData *pPageData = pPattern->m_pDocument->GetPageData(); 1310 CPDF_DocPageData *pPageData = pPattern->m_pDocument->GetPageData();
1297 if (pPageData && !pPageData->IsForceClear()) { 1311 if (pPageData) {
1298 pPageData->ReleasePattern(pPattern->m_pPatternObj); 1312 pPageData->ReleasePattern(pPattern->m_pPatternObj);
1299 } 1313 }
1300 } 1314 }
1301 } 1315 }
1302 FX_Free(m_pBuffer); 1316 FX_Free(m_pBuffer);
1303 m_pBuffer = NULL; 1317 m_pBuffer = NULL;
1304 } 1318 }
1305 void CPDF_Color::ReleaseColorSpace() 1319 void CPDF_Color::ReleaseColorSpace()
1306 { 1320 {
1307 if (m_pCS && m_pCS->m_pDocument && m_pCS->GetArray()) { 1321 if (m_pCS && m_pCS->m_pDocument && m_pCS->GetArray()) {
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
1341 if (ncomps > MAX_PATTERN_COLORCOMPS) { 1355 if (ncomps > MAX_PATTERN_COLORCOMPS) {
1342 return; 1356 return;
1343 } 1357 }
1344 if (m_pCS == NULL || m_pCS->GetFamily() != PDFCS_PATTERN) { 1358 if (m_pCS == NULL || m_pCS->GetFamily() != PDFCS_PATTERN) {
1345 if (m_pBuffer) { 1359 if (m_pBuffer) {
1346 FX_Free(m_pBuffer); 1360 FX_Free(m_pBuffer);
1347 } 1361 }
1348 m_pCS = CPDF_ColorSpace::GetStockCS(PDFCS_PATTERN); 1362 m_pCS = CPDF_ColorSpace::GetStockCS(PDFCS_PATTERN);
1349 m_pBuffer = m_pCS->CreateBuf(); 1363 m_pBuffer = m_pCS->CreateBuf();
1350 } 1364 }
1365 CPDF_DocPageData *pDocPageData = NULL;
1351 PatternValue* pvalue = (PatternValue*)m_pBuffer; 1366 PatternValue* pvalue = (PatternValue*)m_pBuffer;
1352 if (pvalue->m_pPattern && pvalue->m_pPattern->m_pDocument) { 1367 if (pvalue->m_pPattern && pvalue->m_pPattern->m_pDocument) {
1353 CPDF_DocPageData *pDocPageData = pvalue->m_pPattern->m_pDocument->GetPag eData(); 1368 pDocPageData = pvalue->m_pPattern->m_pDocument->GetPageData();
1354 if (pDocPageData && !pDocPageData->IsForceClear()) { 1369 if (pDocPageData) {
1355 pDocPageData->ReleasePattern(pvalue->m_pPattern->m_pPatternObj); 1370 pDocPageData->ReleasePattern(pvalue->m_pPattern->m_pPatternObj);
1356 } 1371 }
1357 } 1372 }
1358 pvalue->m_nComps = ncomps; 1373 pvalue->m_nComps = ncomps;
1359 pvalue->m_pPattern = pPattern; 1374 pvalue->m_pPattern = pPattern;
1360 if (ncomps) { 1375 if (ncomps) {
1361 FXSYS_memcpy32(pvalue->m_Comps, comps, ncomps * sizeof(FX_FLOAT)); 1376 FXSYS_memcpy32(pvalue->m_Comps, comps, ncomps * sizeof(FX_FLOAT));
1362 } 1377 }
1378 pvalue->m_pCountedPattern = NULL;
1379 if (pPattern && pPattern->m_pDocument)
1380 {
1381 if (!pDocPageData) {
1382 pDocPageData = pPattern->m_pDocument->GetPageData();
1383 }
1384 pvalue->m_pCountedPattern = pDocPageData->FindPatternPtr(pPattern->m_pPa tternObj);
1385 }
1363 } 1386 }
1364 void CPDF_Color::Copy(const CPDF_Color* pSrc) 1387 void CPDF_Color::Copy(const CPDF_Color* pSrc)
1365 { 1388 {
1366 ReleaseBuffer(); 1389 ReleaseBuffer();
1367 ReleaseColorSpace(); 1390 ReleaseColorSpace();
1368 m_pCS = pSrc->m_pCS; 1391 m_pCS = pSrc->m_pCS;
1369 if (m_pCS && m_pCS->m_pDocument) { 1392 if (m_pCS && m_pCS->m_pDocument) {
1370 CPDF_Array* pArray = m_pCS->GetArray(); 1393 CPDF_Array* pArray = m_pCS->GetArray();
1371 if (pArray) { 1394 if (pArray) {
1372 m_pCS = m_pCS->m_pDocument->GetPageData()->GetCopiedColorSpace(pArra y); 1395 m_pCS = m_pCS->m_pDocument->GetPageData()->GetCopiedColorSpace(pArra y);
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
1421 PatternValue* pvalue = (PatternValue*)m_pBuffer; 1444 PatternValue* pvalue = (PatternValue*)m_pBuffer;
1422 return pvalue->m_nComps ? pvalue->m_Comps : NULL; 1445 return pvalue->m_nComps ? pvalue->m_Comps : NULL;
1423 } 1446 }
1424 FX_BOOL CPDF_Color::IsEqual(const CPDF_Color& other) const 1447 FX_BOOL CPDF_Color::IsEqual(const CPDF_Color& other) const
1425 { 1448 {
1426 if (m_pCS != other.m_pCS || m_pCS == NULL) { 1449 if (m_pCS != other.m_pCS || m_pCS == NULL) {
1427 return FALSE; 1450 return FALSE;
1428 } 1451 }
1429 return FXSYS_memcmp32(m_pBuffer, other.m_pBuffer, m_pCS->GetBufSize()) == 0; 1452 return FXSYS_memcmp32(m_pBuffer, other.m_pBuffer, m_pCS->GetBufSize()) == 0;
1430 } 1453 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698