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

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

Issue 554913003: Change the forced clear order of CPDF_DocPageData::Clear, and remove m_pDocument in CPDF_Color (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: Nit Created 6 years, 3 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
« no previous file with comments | « core/include/fpdfapi/fpdf_resource.h ('k') | core/src/fpdfapi/fpdf_page/fpdf_page_doc.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 "../../../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 1274 matching lines...) Expand 10 before | Expand all | Expand 10 after
1285 ReleaseColorSpace(); 1285 ReleaseColorSpace();
1286 } 1286 }
1287 void CPDF_Color::ReleaseBuffer() 1287 void CPDF_Color::ReleaseBuffer()
1288 { 1288 {
1289 if (!m_pBuffer) { 1289 if (!m_pBuffer) {
1290 return; 1290 return;
1291 } 1291 }
1292 if (m_pCS->GetFamily() == PDFCS_PATTERN) { 1292 if (m_pCS->GetFamily() == PDFCS_PATTERN) {
1293 PatternValue* pvalue = (PatternValue*)m_pBuffer; 1293 PatternValue* pvalue = (PatternValue*)m_pBuffer;
1294 CPDF_Pattern* pPattern = pvalue->m_pPattern; 1294 CPDF_Pattern* pPattern = pvalue->m_pPattern;
1295 if (pPattern && m_pDocument) { 1295 if (pPattern && pPattern->m_pDocument) {
1296 CPDF_DocPageData *pPageData = m_pDocument->GetPageData(); 1296 CPDF_DocPageData *pPageData = pPattern->m_pDocument->GetPageData();
1297 if (pPageData && !pPageData->IsForceClear()) { 1297 if (pPageData && !pPageData->IsForceClear()) {
1298 pPageData->ReleasePattern(pPattern->m_pPatternObj); 1298 pPageData->ReleasePattern(pPattern->m_pPatternObj);
1299 } 1299 }
1300 } 1300 }
1301 } 1301 }
1302 FX_Free(m_pBuffer); 1302 FX_Free(m_pBuffer);
1303 m_pBuffer = NULL; 1303 m_pBuffer = NULL;
1304 } 1304 }
1305 void CPDF_Color::ReleaseColorSpace() 1305 void CPDF_Color::ReleaseColorSpace()
1306 { 1306 {
1307 if (m_pDocument && m_pCS && m_pCS->GetArray()) { 1307 if (m_pCS && m_pCS->m_pDocument && m_pCS->GetArray()) {
1308 m_pDocument->GetPageData()->ReleaseColorSpace(m_pCS->GetArray()); 1308 m_pCS->m_pDocument->GetPageData()->ReleaseColorSpace(m_pCS->GetArray());
1309 m_pCS = NULL; 1309 m_pCS = NULL;
1310 m_pDocument = NULL;
1311 } 1310 }
1312 } 1311 }
1313 void CPDF_Color::SetColorSpace(CPDF_ColorSpace* pCS) 1312 void CPDF_Color::SetColorSpace(CPDF_ColorSpace* pCS)
1314 { 1313 {
1315 if (m_pCS == pCS) { 1314 if (m_pCS == pCS) {
1316 if (m_pBuffer == NULL) { 1315 if (m_pBuffer == NULL) {
1317 m_pBuffer = pCS->CreateBuf(); 1316 m_pBuffer = pCS->CreateBuf();
1318 } 1317 }
1319 ReleaseColorSpace(); 1318 ReleaseColorSpace();
1320 m_pCS = pCS; 1319 m_pCS = pCS;
1321 m_pDocument = pCS->m_pDocument;
1322 return; 1320 return;
1323 } 1321 }
1324 ReleaseBuffer(); 1322 ReleaseBuffer();
1325 ReleaseColorSpace(); 1323 ReleaseColorSpace();
1326 m_pCS = pCS; 1324 m_pCS = pCS;
1327 m_pDocument = pCS->m_pDocument;
1328 if (m_pCS) { 1325 if (m_pCS) {
1329 m_pBuffer = pCS->CreateBuf(); 1326 m_pBuffer = pCS->CreateBuf();
1330 pCS->GetDefaultColor(m_pBuffer); 1327 pCS->GetDefaultColor(m_pBuffer);
1331 } 1328 }
1332 } 1329 }
1333 void CPDF_Color::SetValue(FX_FLOAT* comps) 1330 void CPDF_Color::SetValue(FX_FLOAT* comps)
1334 { 1331 {
1335 if (m_pBuffer == NULL) { 1332 if (m_pBuffer == NULL) {
1336 return; 1333 return;
1337 } 1334 }
1338 if (m_pCS->GetFamily() != PDFCS_PATTERN) { 1335 if (m_pCS->GetFamily() != PDFCS_PATTERN) {
1339 FXSYS_memcpy32(m_pBuffer, comps, m_pCS->CountComponents() * sizeof(FX_FL OAT)); 1336 FXSYS_memcpy32(m_pBuffer, comps, m_pCS->CountComponents() * sizeof(FX_FL OAT));
1340 } 1337 }
1341 } 1338 }
1342 void CPDF_Color::SetValue(CPDF_Pattern* pPattern, FX_FLOAT* comps, int ncomps) 1339 void CPDF_Color::SetValue(CPDF_Pattern* pPattern, FX_FLOAT* comps, int ncomps)
1343 { 1340 {
1344 if (ncomps > MAX_PATTERN_COLORCOMPS) { 1341 if (ncomps > MAX_PATTERN_COLORCOMPS) {
1345 return; 1342 return;
1346 } 1343 }
1347 if (m_pCS == NULL || m_pCS->GetFamily() != PDFCS_PATTERN) { 1344 if (m_pCS == NULL || m_pCS->GetFamily() != PDFCS_PATTERN) {
1348 if (m_pBuffer) { 1345 if (m_pBuffer) {
1349 FX_Free(m_pBuffer); 1346 FX_Free(m_pBuffer);
1350 } 1347 }
1351 m_pCS = CPDF_ColorSpace::GetStockCS(PDFCS_PATTERN); 1348 m_pCS = CPDF_ColorSpace::GetStockCS(PDFCS_PATTERN);
1352 m_pBuffer = m_pCS->CreateBuf(); 1349 m_pBuffer = m_pCS->CreateBuf();
1353 } 1350 }
1354 PatternValue* pvalue = (PatternValue*)m_pBuffer; 1351 PatternValue* pvalue = (PatternValue*)m_pBuffer;
1355 if (pvalue->m_pPattern && m_pDocument) { 1352 if (pvalue->m_pPattern && pvalue->m_pPattern->m_pDocument) {
1356 CPDF_DocPageData *pDocPageData = m_pDocument->GetPageData(); 1353 CPDF_DocPageData *pDocPageData = pvalue->m_pPattern->m_pDocument->GetPag eData();
1357 if (pDocPageData && !pDocPageData->IsForceClear()) { 1354 if (pDocPageData && !pDocPageData->IsForceClear()) {
1358 pDocPageData->ReleasePattern(pvalue->m_pPattern->m_pPatternObj); 1355 pDocPageData->ReleasePattern(pvalue->m_pPattern->m_pPatternObj);
1359 } 1356 }
1360 } 1357 }
1361 pvalue->m_nComps = ncomps; 1358 pvalue->m_nComps = ncomps;
1362 pvalue->m_pPattern = pPattern; 1359 pvalue->m_pPattern = pPattern;
1363 if (ncomps) { 1360 if (ncomps) {
1364 FXSYS_memcpy32(pvalue->m_Comps, comps, ncomps * sizeof(FX_FLOAT)); 1361 FXSYS_memcpy32(pvalue->m_Comps, comps, ncomps * sizeof(FX_FLOAT));
1365 } 1362 }
1366 } 1363 }
1367 void CPDF_Color::Copy(const CPDF_Color* pSrc) 1364 void CPDF_Color::Copy(const CPDF_Color* pSrc)
1368 { 1365 {
1369 ReleaseBuffer(); 1366 ReleaseBuffer();
1370 ReleaseColorSpace(); 1367 ReleaseColorSpace();
1371 m_pCS = pSrc->m_pCS; 1368 m_pCS = pSrc->m_pCS;
1372 if (m_pCS && m_pCS->m_pDocument) { 1369 if (m_pCS && m_pCS->m_pDocument) {
1373 CPDF_Array* pArray = m_pCS->GetArray(); 1370 CPDF_Array* pArray = m_pCS->GetArray();
1374 if (pArray) { 1371 if (pArray) {
1375 m_pCS = m_pCS->m_pDocument->GetPageData()->GetCopiedColorSpace(pArra y); 1372 m_pCS = m_pCS->m_pDocument->GetPageData()->GetCopiedColorSpace(pArra y);
1376 } 1373 }
1377 } 1374 }
1378 if (m_pCS == NULL) { 1375 if (m_pCS == NULL) {
1379 return; 1376 return;
1380 } 1377 }
1381 m_pBuffer = m_pCS->CreateBuf(); 1378 m_pBuffer = m_pCS->CreateBuf();
1382 FXSYS_memcpy32(m_pBuffer, pSrc->m_pBuffer, m_pCS->GetBufSize()); 1379 FXSYS_memcpy32(m_pBuffer, pSrc->m_pBuffer, m_pCS->GetBufSize());
1383 if (m_pCS->GetFamily() == PDFCS_PATTERN) { 1380 if (m_pCS->GetFamily() == PDFCS_PATTERN) {
1384 PatternValue* pvalue = (PatternValue*)m_pBuffer; 1381 PatternValue* pvalue = (PatternValue*)m_pBuffer;
1385 if (pvalue->m_pPattern && m_pDocument) { 1382 if (pvalue->m_pPattern && pvalue->m_pPattern->m_pDocument) {
1386 pvalue->m_pPattern = m_pDocument->GetPageData()->GetPattern(pvalue-> m_pPattern->m_pPatternObj, FALSE, &pvalue->m_pPattern->m_ParentMatrix); 1383 pvalue->m_pPattern = pvalue->m_pPattern->m_pDocument->GetPageData()- >GetPattern(pvalue->m_pPattern->m_pPatternObj, FALSE, &pvalue->m_pPattern->m_Par entMatrix);
1387 } 1384 }
1388 } 1385 }
1389 } 1386 }
1390 FX_BOOL CPDF_Color::GetRGB(int& R, int& G, int& B) const 1387 FX_BOOL CPDF_Color::GetRGB(int& R, int& G, int& B) const
1391 { 1388 {
1392 if (m_pCS == NULL || m_pBuffer == NULL) { 1389 if (m_pCS == NULL || m_pBuffer == NULL) {
1393 return FALSE; 1390 return FALSE;
1394 } 1391 }
1395 FX_FLOAT r=0.0f, g=0.0f, b=0.0f; 1392 FX_FLOAT r=0.0f, g=0.0f, b=0.0f;
1396 if (!m_pCS->GetRGB(m_pBuffer, r, g, b)) { 1393 if (!m_pCS->GetRGB(m_pBuffer, r, g, b)) {
(...skipping 27 matching lines...) Expand all
1424 PatternValue* pvalue = (PatternValue*)m_pBuffer; 1421 PatternValue* pvalue = (PatternValue*)m_pBuffer;
1425 return pvalue->m_nComps ? pvalue->m_Comps : NULL; 1422 return pvalue->m_nComps ? pvalue->m_Comps : NULL;
1426 } 1423 }
1427 FX_BOOL CPDF_Color::IsEqual(const CPDF_Color& other) const 1424 FX_BOOL CPDF_Color::IsEqual(const CPDF_Color& other) const
1428 { 1425 {
1429 if (m_pCS != other.m_pCS || m_pCS == NULL) { 1426 if (m_pCS != other.m_pCS || m_pCS == NULL) {
1430 return FALSE; 1427 return FALSE;
1431 } 1428 }
1432 return FXSYS_memcmp32(m_pBuffer, other.m_pBuffer, m_pCS->GetBufSize()) == 0; 1429 return FXSYS_memcmp32(m_pBuffer, other.m_pBuffer, m_pCS->GetBufSize()) == 0;
1433 } 1430 }
OLDNEW
« no previous file with comments | « core/include/fpdfapi/fpdf_resource.h ('k') | core/src/fpdfapi/fpdf_page/fpdf_page_doc.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698