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

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

Issue 493163003: Use number of components from ICC profile and alternateCS (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: Created 6 years, 4 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 499 matching lines...) Expand 10 before | Expand all | Expand 10 after
510 lab[1] = (FX_FLOAT)(pSrcBuf[1] - 128); 510 lab[1] = (FX_FLOAT)(pSrcBuf[1] - 128);
511 lab[2] = (FX_FLOAT)(pSrcBuf[2] - 128); 511 lab[2] = (FX_FLOAT)(pSrcBuf[2] - 128);
512 GetRGB(lab, R, G, B); 512 GetRGB(lab, R, G, B);
513 pDestBuf[0] = (FX_INT32)(B * 255); 513 pDestBuf[0] = (FX_INT32)(B * 255);
514 pDestBuf[1] = (FX_INT32)(G * 255); 514 pDestBuf[1] = (FX_INT32)(G * 255);
515 pDestBuf[2] = (FX_INT32)(R * 255); 515 pDestBuf[2] = (FX_INT32)(R * 255);
516 pDestBuf += 3; 516 pDestBuf += 3;
517 pSrcBuf += 3; 517 pSrcBuf += 3;
518 } 518 }
519 } 519 }
520 CPDF_IccProfile::CPDF_IccProfile(FX_LPCBYTE pData, FX_DWORD dwSize, int nCompone nts) 520 CPDF_IccProfile::CPDF_IccProfile(FX_LPCBYTE pData, FX_DWORD dwSize)
521 { 521 {
522 m_bsRGB = nComponents == 3 && dwSize == 3144 && FXSYS_memcmp32(pData + 0x190 , "sRGB IEC61966-2.1", 17) == 0; 522 if (dwSize == 3144 && FXSYS_memcmp32(pData + 0x190, "sRGB IEC61966-2.1", 17) == 0) {
523 m_pTransform = NULL; 523 m_bsRGB = TRUE;
524 if (!m_bsRGB && CPDF_ModuleMgr::Get()->GetIccModule()) { 524 m_pTransform = NULL;
525 m_pTransform = CPDF_ModuleMgr::Get()->GetIccModule()->CreateTransform_sR GB(pData, dwSize, nComponents); 525 m_srcnComponents = 3;
jun_fang 2014/08/25 18:56:51 In some cases, m_nSrcComponents may not initialize
Bo Xu 2014/08/25 20:28:17 Done.
526 }
527 else if (CPDF_ModuleMgr::Get()->GetIccModule()) {
528 m_bsRGB = FALSE;
529 m_pTransform = CPDF_ModuleMgr::Get()->GetIccModule()->CreateTransform_sR GB(pData, dwSize, &m_srcnComponents);
Tom Sepez 2014/08/25 18:18:51 If neither expression in this if-statement is true
Bo Xu 2014/08/25 20:28:17 That's right. Done.
526 } 530 }
527 } 531 }
528 CPDF_IccProfile::~CPDF_IccProfile() 532 CPDF_IccProfile::~CPDF_IccProfile()
529 { 533 {
530 if (m_pTransform) { 534 if (m_pTransform) {
531 CPDF_ModuleMgr::Get()->GetIccModule()->DestroyTransform(m_pTransform); 535 CPDF_ModuleMgr::Get()->GetIccModule()->DestroyTransform(m_pTransform);
532 } 536 }
533 } 537 }
534 class CPDF_ICCBasedCS : public CPDF_ColorSpace 538 class CPDF_ICCBasedCS : public CPDF_ColorSpace
535 { 539 {
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
576 if (m_pProfile && m_pDocument) { 580 if (m_pProfile && m_pDocument) {
577 m_pDocument->GetPageData()->ReleaseIccProfile(NULL, m_pProfile); 581 m_pDocument->GetPageData()->ReleaseIccProfile(NULL, m_pProfile);
578 } 582 }
579 } 583 }
580 FX_BOOL CPDF_ICCBasedCS::v_Load(CPDF_Document* pDoc, CPDF_Array* pArray) 584 FX_BOOL CPDF_ICCBasedCS::v_Load(CPDF_Document* pDoc, CPDF_Array* pArray)
581 { 585 {
582 CPDF_Stream* pStream = pArray->GetStream(1); 586 CPDF_Stream* pStream = pArray->GetStream(1);
583 if (pStream == NULL) { 587 if (pStream == NULL) {
584 return FALSE; 588 return FALSE;
585 } 589 }
590 m_pProfile = pDoc->LoadIccProfile(pStream);
591 if (!m_pProfile) {
592 return FALSE;
593 }
594 m_nComponents = m_pProfile->GetComponents(); //Try using the nComponents fro m ICC profile
586 CPDF_Dictionary* pDict = pStream->GetDict(); 595 CPDF_Dictionary* pDict = pStream->GetDict();
587 m_nComponents = pDict ? pDict->GetInteger(FX_BSTRC("N")) : 0; 596 FX_INT32 Dict_nComponents = pDict ? pDict->GetInteger(FX_BSTRC("N")) : 0;
Tom Sepez 2014/08/25 18:18:51 nit: nDictComponents for consistency perhaps.
Bo Xu 2014/08/25 20:28:17 Done.
588 if (m_nComponents != 1 && m_nComponents != 3 && m_nComponents != 4) { 597 if (m_pProfile->m_pTransform == NULL) { // No valid ICC profile or using sRG B
589 return FALSE; 598 CPDF_Object* pAlterCSObj = pDict ? pDict->GetElementValue(FX_BSTRC("Alte rnate")) : NULL;
599 if (pAlterCSObj) {
600 CPDF_ColorSpace* alter_cs = CPDF_ColorSpace::Load(pDoc, pAlterCSObj) ;
Tom Sepez 2014/08/25 18:18:51 nit: If you wanted to do some cleanup along the wa
Bo Xu 2014/08/25 20:28:17 Done.
601 if (alter_cs) {
602 if (m_nComponents == 0) { // NO valid ICC profile
603 if (alter_cs->CountComponents() > 0) { // Use Alternative co lorspace
604 m_nComponents = alter_cs->CountComponents();
605 m_pAlterCS = alter_cs;
606 m_bOwn = TRUE;
607 }
608 else { // No valid alternative colorspace
609 alter_cs->ReleaseCS();
610 if (Dict_nComponents == 1 || Dict_nComponents == 3 || Di ct_nComponents == 4 ) {
Tom Sepez 2014/08/25 18:18:51 nit: prefer early return as in if (Dict_nComponent
Bo Xu 2014/08/25 20:28:17 Done.
611 m_nComponents = Dict_nComponents;
612 }
613 else {
614 return FALSE;
615 }
616 }
617
618 }
619 else { // Using sRGB
620 if (alter_cs->CountComponents() != m_nComponents) {
621 alter_cs->ReleaseCS();
622 }
623 else {
624 m_pAlterCS = alter_cs;
625 m_bOwn = TRUE;
626 }
627 }
628 }
629 }
630 if (!m_pAlterCS) {
631 if (m_nComponents == 1) {
632 m_pAlterCS = GetStockCS(PDFCS_DEVICEGRAY);
633 }
634 if (m_nComponents == 3) {
Tom Sepez 2014/08/25 18:18:51 nit: else if
635 m_pAlterCS = GetStockCS(PDFCS_DEVICERGB);
636 }
637 else if (m_nComponents == 4) {
638 m_pAlterCS = GetStockCS(PDFCS_DEVICECMYK);
639 }
640 }
590 } 641 }
591 CPDF_Array* pRanges = pDict->GetArray(FX_BSTRC("Range")); 642 CPDF_Array* pRanges = pDict->GetArray(FX_BSTRC("Range"));
592 m_pRanges = FX_Alloc(FX_FLOAT, m_nComponents * 2); 643 m_pRanges = FX_Alloc(FX_FLOAT, m_nComponents * 2);
593 for (int i = 0; i < m_nComponents * 2; i ++) { 644 for (int i = 0; i < m_nComponents * 2; i ++) {
594 if (pRanges) { 645 if (pRanges) {
595 m_pRanges[i] = pRanges->GetNumber(i); 646 m_pRanges[i] = pRanges->GetNumber(i);
596 } else if (i % 2) { 647 } else if (i % 2) {
597 m_pRanges[i] = 1.0f; 648 m_pRanges[i] = 1.0f;
598 } else { 649 } else {
599 m_pRanges[i] = 0; 650 m_pRanges[i] = 0;
600 } 651 }
601 } 652 }
602 m_pProfile = pDoc->LoadIccProfile(pStream, m_nComponents);
603 if (!m_pProfile) {
604 return FALSE;
605 }
606 if (m_pProfile->m_pTransform == NULL) {
607 CPDF_Object* pAlterCSObj = pDict ? pDict->GetElementValue(FX_BSTRC("Alte rnate")) : NULL;
608 if (pAlterCSObj) {
609 CPDF_ColorSpace* alter_cs = CPDF_ColorSpace::Load(pDoc, pAlterCSObj) ;
610 if (alter_cs) {
611 if (alter_cs->CountComponents() > m_nComponents) {
612 alter_cs->ReleaseCS();
613 } else {
614 m_pAlterCS = alter_cs;
615 m_bOwn = TRUE;
616 }
617 }
618 }
619 if (!m_pAlterCS) {
620 if (m_nComponents == 3) {
621 m_pAlterCS = GetStockCS(PDFCS_DEVICERGB);
622 } else if (m_nComponents == 4) {
623 m_pAlterCS = GetStockCS(PDFCS_DEVICECMYK);
624 } else {
625 m_pAlterCS = GetStockCS(PDFCS_DEVICEGRAY);
626 }
627 }
628 }
629 return TRUE; 653 return TRUE;
630 } 654 }
631 FX_BOOL CPDF_ICCBasedCS::GetRGB(FX_FLOAT* pBuf, FX_FLOAT& R, FX_FLOAT& G, FX_FLO AT& B) const 655 FX_BOOL CPDF_ICCBasedCS::GetRGB(FX_FLOAT* pBuf, FX_FLOAT& R, FX_FLOAT& G, FX_FLO AT& B) const
632 { 656 {
633 if (m_pProfile && m_pProfile->m_bsRGB) { 657 if (m_pProfile && m_pProfile->m_bsRGB) {
634 R = pBuf[0]; 658 R = pBuf[0];
635 G = pBuf[1]; 659 G = pBuf[1];
636 B = pBuf[2]; 660 B = pBuf[2];
637 return TRUE; 661 return TRUE;
638 } 662 }
(...skipping 760 matching lines...) Expand 10 before | Expand all | Expand 10 after
1399 PatternValue* pvalue = (PatternValue*)m_pBuffer; 1423 PatternValue* pvalue = (PatternValue*)m_pBuffer;
1400 return pvalue->m_nComps ? pvalue->m_Comps : NULL; 1424 return pvalue->m_nComps ? pvalue->m_Comps : NULL;
1401 } 1425 }
1402 FX_BOOL CPDF_Color::IsEqual(const CPDF_Color& other) const 1426 FX_BOOL CPDF_Color::IsEqual(const CPDF_Color& other) const
1403 { 1427 {
1404 if (m_pCS != other.m_pCS || m_pCS == NULL) { 1428 if (m_pCS != other.m_pCS || m_pCS == NULL) {
1405 return FALSE; 1429 return FALSE;
1406 } 1430 }
1407 return FXSYS_memcmp32(m_pBuffer, other.m_pBuffer, m_pCS->GetBufSize()) == 0; 1431 return FXSYS_memcmp32(m_pBuffer, other.m_pBuffer, m_pCS->GetBufSize()) == 0;
1408 } 1432 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698