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

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

Issue 1507043004: Cleanup CPDF_DIBSource::LoadColorInfo() and ValidateDictParam(). (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: Created 5 years 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/src/fpdfapi/fpdf_page/pageint.h ('k') | core/src/fpdfapi/fpdf_render/render_int.h » ('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 "render_int.h" 7 #include "render_int.h"
8 8
9 #include <vector> 9 #include <vector>
10 10
(...skipping 447 matching lines...) Expand 10 before | Expand all | Expand 10 after
458 if (m_pColorSpace && m_bStdCS) { 458 if (m_pColorSpace && m_bStdCS) {
459 m_pColorSpace->EnableStdConversion(FALSE); 459 m_pColorSpace->EnableStdConversion(FALSE);
460 } 460 }
461 return ret1; 461 return ret1;
462 } 462 }
463 if (m_Status == 2) { 463 if (m_Status == 2) {
464 return ContinueLoadMaskDIB(pPause); 464 return ContinueLoadMaskDIB(pPause);
465 } 465 }
466 return 0; 466 return 0;
467 } 467 }
468 FX_BOOL CPDF_DIBSource::LoadColorInfo(CPDF_Dictionary* pFormResources, 468
469 CPDF_Dictionary* pPageResources) { 469 bool CPDF_DIBSource::LoadColorInfo(const CPDF_Dictionary* pFormResources,
470 m_bpc_orig = m_pDict->GetInteger(FX_BSTRC("BitsPerComponent")); 470 const CPDF_Dictionary* pPageResources) {
471 if (m_pDict->GetInteger("ImageMask")) { 471 m_bpc_orig = m_pDict->GetInteger("BitsPerComponent");
472 if (m_pDict->GetInteger("ImageMask"))
472 m_bImageMask = TRUE; 473 m_bImageMask = TRUE;
473 } 474
474 if (m_bImageMask || !m_pDict->KeyExist(FX_BSTRC("ColorSpace"))) { 475 if (m_bImageMask || !m_pDict->KeyExist("ColorSpace")) {
475 if (!m_bImageMask) { 476 if (!m_bImageMask) {
476 CPDF_Object* pFilter = m_pDict->GetElementValue(FX_BSTRC("Filter")); 477 CPDF_Object* pFilter = m_pDict->GetElementValue("Filter");
477 if (pFilter) { 478 if (pFilter) {
478 CFX_ByteString filter; 479 CFX_ByteString filter;
479 if (pFilter->IsName()) { 480 if (pFilter->IsName()) {
480 filter = pFilter->GetString(); 481 filter = pFilter->GetString();
481 if (filter == FX_BSTRC("JPXDecode")) {
482 m_bDoBpcCheck = FALSE;
483 return TRUE;
484 }
485 } else if (CPDF_Array* pArray = pFilter->AsArray()) { 482 } else if (CPDF_Array* pArray = pFilter->AsArray()) {
486 if (pArray->GetString(pArray->GetCount() - 1) == 483 filter = pArray->GetString(pArray->GetCount() - 1);
487 FX_BSTRC("JPXDecode")) { 484 }
488 m_bDoBpcCheck = FALSE; 485
489 return TRUE; 486 if (filter == FX_BSTRC("JPXDecode")) {
490 } 487 m_bDoBpcCheck = FALSE;
488 return true;
491 } 489 }
492 } 490 }
493 } 491 }
494 m_bImageMask = TRUE; 492 m_bImageMask = TRUE;
495 m_bpc = m_nComponents = 1; 493 m_bpc = m_nComponents = 1;
496 CPDF_Array* pDecode = m_pDict->GetArray(FX_BSTRC("Decode")); 494 CPDF_Array* pDecode = m_pDict->GetArray("Decode");
497 m_bDefaultDecode = pDecode == NULL || pDecode->GetInteger(0) == 0; 495 m_bDefaultDecode = !pDecode || !pDecode->GetInteger(0);
498 return TRUE; 496 return true;
499 } 497 }
500 CPDF_Object* pCSObj = m_pDict->GetElementValue(FX_BSTRC("ColorSpace")); 498
501 if (pCSObj == NULL) { 499 CPDF_Object* pCSObj = m_pDict->GetElementValue("ColorSpace");
502 return FALSE; 500 if (!pCSObj)
503 } 501 return false;
502
504 CPDF_DocPageData* pDocPageData = m_pDocument->GetPageData(); 503 CPDF_DocPageData* pDocPageData = m_pDocument->GetPageData();
505 if (pFormResources) { 504 if (pFormResources)
506 m_pColorSpace = pDocPageData->GetColorSpace(pCSObj, pFormResources); 505 m_pColorSpace = pDocPageData->GetColorSpace(pCSObj, pFormResources);
507 } 506 if (!m_pColorSpace)
508 if (m_pColorSpace == NULL) {
509 m_pColorSpace = pDocPageData->GetColorSpace(pCSObj, pPageResources); 507 m_pColorSpace = pDocPageData->GetColorSpace(pCSObj, pPageResources);
510 } 508 if (!m_pColorSpace)
511 if (m_pColorSpace == NULL) { 509 return false;
512 return FALSE; 510
513 }
514 m_Family = m_pColorSpace->GetFamily(); 511 m_Family = m_pColorSpace->GetFamily();
515 m_nComponents = m_pColorSpace->CountComponents(); 512 m_nComponents = m_pColorSpace->CountComponents();
516 if (m_Family == PDFCS_ICCBASED && pCSObj->IsName()) { 513 if (m_Family == PDFCS_ICCBASED && pCSObj->IsName()) {
517 CFX_ByteString cs = pCSObj->GetString(); 514 CFX_ByteString cs = pCSObj->GetString();
518 if (cs == FX_BSTRC("DeviceGray")) { 515 if (cs == "DeviceGray") {
519 m_nComponents = 1; 516 m_nComponents = 1;
520 } else if (cs == FX_BSTRC("DeviceRGB")) { 517 } else if (cs == "DeviceRGB") {
521 m_nComponents = 3; 518 m_nComponents = 3;
522 } else if (cs == FX_BSTRC("DeviceCMYK")) { 519 } else if (cs == "DeviceCMYK") {
523 m_nComponents = 4; 520 m_nComponents = 4;
524 } 521 }
525 } 522 }
526 ValidateDictParam(); 523 ValidateDictParam();
527 m_pCompData = GetDecodeAndMaskArray(m_bDefaultDecode, m_bColorKey); 524 m_pCompData = GetDecodeAndMaskArray(m_bDefaultDecode, m_bColorKey);
528 if (m_pCompData == NULL) { 525 return !!m_pCompData;
529 return FALSE;
530 }
531 return TRUE;
532 } 526 }
527
533 DIB_COMP_DATA* CPDF_DIBSource::GetDecodeAndMaskArray(FX_BOOL& bDefaultDecode, 528 DIB_COMP_DATA* CPDF_DIBSource::GetDecodeAndMaskArray(FX_BOOL& bDefaultDecode,
534 FX_BOOL& bColorKey) { 529 FX_BOOL& bColorKey) {
535 if (m_pColorSpace == NULL) { 530 if (m_pColorSpace == NULL) {
536 return NULL; 531 return NULL;
537 } 532 }
538 DIB_COMP_DATA* pCompData = FX_Alloc(DIB_COMP_DATA, m_nComponents); 533 DIB_COMP_DATA* pCompData = FX_Alloc(DIB_COMP_DATA, m_nComponents);
539 int max_data = (1 << m_bpc) - 1; 534 int max_data = (1 << m_bpc) - 1;
540 CPDF_Array* pDecode = m_pDict->GetArray(FX_BSTRC("Decode")); 535 CPDF_Array* pDecode = m_pDict->GetArray(FX_BSTRC("Decode"));
541 if (pDecode) { 536 if (pDecode) {
542 for (FX_DWORD i = 0; i < m_nComponents; i++) { 537 for (FX_DWORD i = 0; i < m_nComponents; i++) {
(...skipping 374 matching lines...) Expand 10 before | Expand all | Expand 10 after
917 m_pColorSpace->GetRGB(temp_buf, R, G, B); 912 m_pColorSpace->GetRGB(temp_buf, R, G, B);
918 FX_Free(temp_buf); 913 FX_Free(temp_buf);
919 } else { 914 } else {
920 m_pColorSpace->GetRGB(color_value, R, G, B); 915 m_pColorSpace->GetRGB(color_value, R, G, B);
921 } 916 }
922 SetPaletteArgb(i, ArgbEncode(255, FXSYS_round(R * 255), 917 SetPaletteArgb(i, ArgbEncode(255, FXSYS_round(R * 255),
923 FXSYS_round(G * 255), FXSYS_round(B * 255))); 918 FXSYS_round(G * 255), FXSYS_round(B * 255)));
924 } 919 }
925 } 920 }
926 } 921 }
922
927 void CPDF_DIBSource::ValidateDictParam() { 923 void CPDF_DIBSource::ValidateDictParam() {
928 m_bpc = m_bpc_orig; 924 m_bpc = m_bpc_orig;
929 CPDF_Object* pFilter = m_pDict->GetElementValue(FX_BSTRC("Filter")); 925 CPDF_Object* pFilter = m_pDict->GetElementValue("Filter");
930 if (pFilter) { 926 if (pFilter) {
931 if (pFilter->IsName()) { 927 if (pFilter->IsName()) {
932 CFX_ByteString filter = pFilter->GetString(); 928 CFX_ByteString filter = pFilter->GetString();
933 if (filter == FX_BSTRC("CCITTFaxDecode") || 929 if (filter == "CCITTFaxDecode" || filter == "JBIG2Decode") {
934 filter == FX_BSTRC("JBIG2Decode")) {
935 m_bpc = 1; 930 m_bpc = 1;
936 m_nComponents = 1; 931 m_nComponents = 1;
937 } 932 } else if (filter == "RunLengthDecode") {
938 if (filter == FX_BSTRC("RunLengthDecode")) {
939 if (m_bpc != 1) { 933 if (m_bpc != 1) {
940 m_bpc = 8; 934 m_bpc = 8;
941 } 935 }
942 } else if (filter == FX_BSTRC("DCTDecode")) { 936 } else if (filter == "DCTDecode") {
943 m_bpc = 8; 937 m_bpc = 8;
944 } 938 }
945 } else if (CPDF_Array* pArray = pFilter->AsArray()) { 939 } else if (CPDF_Array* pArray = pFilter->AsArray()) {
946 if (pArray->GetString(pArray->GetCount() - 1) == 940 CFX_ByteString filter = pArray->GetString(pArray->GetCount() - 1);
947 FX_BSTRC("CCITTFaxDecode") || 941 if (filter == "CCITTFaxDecode" || filter == "JBIG2Decode") {
948 pArray->GetString(pArray->GetCount() - 1) ==
949 FX_BSTRC("JBIG2Decode")) {
950 m_bpc = 1; 942 m_bpc = 1;
951 m_nComponents = 1; 943 m_nComponents = 1;
952 } 944 } else if (filter == "DCTDecode") {
953 if (pArray->GetString(pArray->GetCount() - 1) == FX_BSTRC("DCTDecode")) { 945 // Previously, filter == "RunLengthDecode" was checked in the "if"
954 // Previously, pArray->GetString(pArray->GetCount() - 1) == 946 // statement as well, but too many documents don't conform to it.
955 // FX_BSTRC("RunLengthDecode") was checked in the "if" statement as
956 // well,
957 // but too many documents don't conform to it.
958 m_bpc = 8; 947 m_bpc = 8;
959 } 948 }
960 } 949 }
961 } 950 }
962 if (m_bpc != 1 && m_bpc != 2 && m_bpc != 4 && m_bpc != 8 && m_bpc != 16) { 951 switch (m_bpc) {
Tom Sepez 2015/12/09 19:27:26 nit: not sure this is an improvement. Maybe we ne
Lei Zhang 2015/12/10 08:02:32 Done.
963 m_bpc = 0; 952 case 1:
953 case 2:
954 case 4:
955 case 8:
956 case 16:
957 break;
958 default:
959 m_bpc = 0;
960 break;
964 } 961 }
965 } 962 }
963
966 #define NORMALCOLOR_MAX(color, max) \ 964 #define NORMALCOLOR_MAX(color, max) \
967 (color) > (max) ? (max) : (color) < 0 ? 0 : (color); 965 (color) > (max) ? (max) : (color) < 0 ? 0 : (color);
968 void CPDF_DIBSource::TranslateScanline24bpp(uint8_t* dest_scan, 966 void CPDF_DIBSource::TranslateScanline24bpp(uint8_t* dest_scan,
969 const uint8_t* src_scan) const { 967 const uint8_t* src_scan) const {
970 if (m_bpc == 0) { 968 if (m_bpc == 0) {
971 return; 969 return;
972 } 970 }
973 int max_data = (1 << m_bpc) - 1; 971 int max_data = (1 << m_bpc) - 1;
974 if (m_bDefaultDecode) { 972 if (m_bDefaultDecode) {
975 if (m_Family == PDFCS_DEVICERGB || m_Family == PDFCS_CALRGB) { 973 if (m_Family == PDFCS_DEVICERGB || m_Family == PDFCS_CALRGB) {
(...skipping 674 matching lines...) Expand 10 before | Expand all | Expand 10 after
1650 } 1648 }
1651 FX_BOOL CPDF_ImageLoader::Continue(void* LoadHandle, IFX_Pause* pPause) { 1649 FX_BOOL CPDF_ImageLoader::Continue(void* LoadHandle, IFX_Pause* pPause) {
1652 return ((CPDF_ProgressiveImageLoaderHandle*)LoadHandle)->Continue(pPause); 1650 return ((CPDF_ProgressiveImageLoaderHandle*)LoadHandle)->Continue(pPause);
1653 } 1651 }
1654 CPDF_ImageLoader::~CPDF_ImageLoader() { 1652 CPDF_ImageLoader::~CPDF_ImageLoader() {
1655 if (!m_bCached) { 1653 if (!m_bCached) {
1656 delete m_pBitmap; 1654 delete m_pBitmap;
1657 delete m_pMask; 1655 delete m_pMask;
1658 } 1656 }
1659 } 1657 }
OLDNEW
« no previous file with comments | « core/src/fpdfapi/fpdf_page/pageint.h ('k') | core/src/fpdfapi/fpdf_render/render_int.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698