OLD | NEW |
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 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
52 | 52 |
53 FX_SAFE_DWORD CalculatePitch32(int bpp, int width) { | 53 FX_SAFE_DWORD CalculatePitch32(int bpp, int width) { |
54 FX_SAFE_DWORD pitch = bpp; | 54 FX_SAFE_DWORD pitch = bpp; |
55 pitch *= width; | 55 pitch *= width; |
56 pitch += 31; | 56 pitch += 31; |
57 pitch /= 32; // quantized to number of 32-bit words. | 57 pitch /= 32; // quantized to number of 32-bit words. |
58 pitch *= 4; // and then back to bytes, (not just /8 in one step). | 58 pitch *= 4; // and then back to bytes, (not just /8 in one step). |
59 return pitch; | 59 return pitch; |
60 } | 60 } |
61 | 61 |
| 62 bool IsAllowedBPCValue(int bpc) { |
| 63 return bpc == 1 || bpc == 2 || bpc == 4 || bpc == 8 || bpc == 16; |
| 64 } |
| 65 |
62 // Wrapper class to use with nonstd::unique_ptr for CJPX_Decoder. | 66 // Wrapper class to use with nonstd::unique_ptr for CJPX_Decoder. |
63 class JpxBitMapContext { | 67 class JpxBitMapContext { |
64 public: | 68 public: |
65 explicit JpxBitMapContext(ICodec_JpxModule* jpx_module) | 69 explicit JpxBitMapContext(ICodec_JpxModule* jpx_module) |
66 : jpx_module_(jpx_module), decoder_(nullptr) {} | 70 : jpx_module_(jpx_module), decoder_(nullptr) {} |
67 | 71 |
68 ~JpxBitMapContext() { | 72 ~JpxBitMapContext() { |
69 jpx_module_->DestroyDecoder(decoder_); | 73 jpx_module_->DestroyDecoder(decoder_); |
70 } | 74 } |
71 | 75 |
(...skipping 386 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
458 if (m_pColorSpace && m_bStdCS) { | 462 if (m_pColorSpace && m_bStdCS) { |
459 m_pColorSpace->EnableStdConversion(FALSE); | 463 m_pColorSpace->EnableStdConversion(FALSE); |
460 } | 464 } |
461 return ret1; | 465 return ret1; |
462 } | 466 } |
463 if (m_Status == 2) { | 467 if (m_Status == 2) { |
464 return ContinueLoadMaskDIB(pPause); | 468 return ContinueLoadMaskDIB(pPause); |
465 } | 469 } |
466 return 0; | 470 return 0; |
467 } | 471 } |
468 FX_BOOL CPDF_DIBSource::LoadColorInfo(CPDF_Dictionary* pFormResources, | 472 |
469 CPDF_Dictionary* pPageResources) { | 473 bool CPDF_DIBSource::LoadColorInfo(const CPDF_Dictionary* pFormResources, |
470 m_bpc_orig = m_pDict->GetInteger(FX_BSTRC("BitsPerComponent")); | 474 const CPDF_Dictionary* pPageResources) { |
471 if (m_pDict->GetInteger("ImageMask")) { | 475 m_bpc_orig = m_pDict->GetInteger("BitsPerComponent"); |
| 476 if (m_pDict->GetInteger("ImageMask")) |
472 m_bImageMask = TRUE; | 477 m_bImageMask = TRUE; |
473 } | 478 |
474 if (m_bImageMask || !m_pDict->KeyExist(FX_BSTRC("ColorSpace"))) { | 479 if (m_bImageMask || !m_pDict->KeyExist("ColorSpace")) { |
475 if (!m_bImageMask) { | 480 if (!m_bImageMask) { |
476 CPDF_Object* pFilter = m_pDict->GetElementValue(FX_BSTRC("Filter")); | 481 CPDF_Object* pFilter = m_pDict->GetElementValue("Filter"); |
477 if (pFilter) { | 482 if (pFilter) { |
478 CFX_ByteString filter; | 483 CFX_ByteString filter; |
479 if (pFilter->IsName()) { | 484 if (pFilter->IsName()) { |
480 filter = pFilter->GetString(); | 485 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()) { | 486 } else if (CPDF_Array* pArray = pFilter->AsArray()) { |
486 if (pArray->GetString(pArray->GetCount() - 1) == | 487 filter = pArray->GetString(pArray->GetCount() - 1); |
487 FX_BSTRC("JPXDecode")) { | 488 } |
488 m_bDoBpcCheck = FALSE; | 489 |
489 return TRUE; | 490 if (filter == FX_BSTRC("JPXDecode")) { |
490 } | 491 m_bDoBpcCheck = FALSE; |
| 492 return true; |
491 } | 493 } |
492 } | 494 } |
493 } | 495 } |
494 m_bImageMask = TRUE; | 496 m_bImageMask = TRUE; |
495 m_bpc = m_nComponents = 1; | 497 m_bpc = m_nComponents = 1; |
496 CPDF_Array* pDecode = m_pDict->GetArray(FX_BSTRC("Decode")); | 498 CPDF_Array* pDecode = m_pDict->GetArray("Decode"); |
497 m_bDefaultDecode = pDecode == NULL || pDecode->GetInteger(0) == 0; | 499 m_bDefaultDecode = !pDecode || !pDecode->GetInteger(0); |
498 return TRUE; | 500 return true; |
499 } | 501 } |
500 CPDF_Object* pCSObj = m_pDict->GetElementValue(FX_BSTRC("ColorSpace")); | 502 |
501 if (pCSObj == NULL) { | 503 CPDF_Object* pCSObj = m_pDict->GetElementValue("ColorSpace"); |
502 return FALSE; | 504 if (!pCSObj) |
503 } | 505 return false; |
| 506 |
504 CPDF_DocPageData* pDocPageData = m_pDocument->GetPageData(); | 507 CPDF_DocPageData* pDocPageData = m_pDocument->GetPageData(); |
505 if (pFormResources) { | 508 if (pFormResources) |
506 m_pColorSpace = pDocPageData->GetColorSpace(pCSObj, pFormResources); | 509 m_pColorSpace = pDocPageData->GetColorSpace(pCSObj, pFormResources); |
507 } | 510 if (!m_pColorSpace) |
508 if (m_pColorSpace == NULL) { | |
509 m_pColorSpace = pDocPageData->GetColorSpace(pCSObj, pPageResources); | 511 m_pColorSpace = pDocPageData->GetColorSpace(pCSObj, pPageResources); |
510 } | 512 if (!m_pColorSpace) |
511 if (m_pColorSpace == NULL) { | 513 return false; |
512 return FALSE; | 514 |
513 } | |
514 m_Family = m_pColorSpace->GetFamily(); | 515 m_Family = m_pColorSpace->GetFamily(); |
515 m_nComponents = m_pColorSpace->CountComponents(); | 516 m_nComponents = m_pColorSpace->CountComponents(); |
516 if (m_Family == PDFCS_ICCBASED && pCSObj->IsName()) { | 517 if (m_Family == PDFCS_ICCBASED && pCSObj->IsName()) { |
517 CFX_ByteString cs = pCSObj->GetString(); | 518 CFX_ByteString cs = pCSObj->GetString(); |
518 if (cs == FX_BSTRC("DeviceGray")) { | 519 if (cs == "DeviceGray") { |
519 m_nComponents = 1; | 520 m_nComponents = 1; |
520 } else if (cs == FX_BSTRC("DeviceRGB")) { | 521 } else if (cs == "DeviceRGB") { |
521 m_nComponents = 3; | 522 m_nComponents = 3; |
522 } else if (cs == FX_BSTRC("DeviceCMYK")) { | 523 } else if (cs == "DeviceCMYK") { |
523 m_nComponents = 4; | 524 m_nComponents = 4; |
524 } | 525 } |
525 } | 526 } |
526 ValidateDictParam(); | 527 ValidateDictParam(); |
527 m_pCompData = GetDecodeAndMaskArray(m_bDefaultDecode, m_bColorKey); | 528 m_pCompData = GetDecodeAndMaskArray(m_bDefaultDecode, m_bColorKey); |
528 if (m_pCompData == NULL) { | 529 return !!m_pCompData; |
529 return FALSE; | |
530 } | |
531 return TRUE; | |
532 } | 530 } |
| 531 |
533 DIB_COMP_DATA* CPDF_DIBSource::GetDecodeAndMaskArray(FX_BOOL& bDefaultDecode, | 532 DIB_COMP_DATA* CPDF_DIBSource::GetDecodeAndMaskArray(FX_BOOL& bDefaultDecode, |
534 FX_BOOL& bColorKey) { | 533 FX_BOOL& bColorKey) { |
535 if (m_pColorSpace == NULL) { | 534 if (m_pColorSpace == NULL) { |
536 return NULL; | 535 return NULL; |
537 } | 536 } |
538 DIB_COMP_DATA* pCompData = FX_Alloc(DIB_COMP_DATA, m_nComponents); | 537 DIB_COMP_DATA* pCompData = FX_Alloc(DIB_COMP_DATA, m_nComponents); |
539 int max_data = (1 << m_bpc) - 1; | 538 int max_data = (1 << m_bpc) - 1; |
540 CPDF_Array* pDecode = m_pDict->GetArray(FX_BSTRC("Decode")); | 539 CPDF_Array* pDecode = m_pDict->GetArray(FX_BSTRC("Decode")); |
541 if (pDecode) { | 540 if (pDecode) { |
542 for (FX_DWORD i = 0; i < m_nComponents; i++) { | 541 for (FX_DWORD i = 0; i < m_nComponents; i++) { |
(...skipping 374 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
917 m_pColorSpace->GetRGB(temp_buf, R, G, B); | 916 m_pColorSpace->GetRGB(temp_buf, R, G, B); |
918 FX_Free(temp_buf); | 917 FX_Free(temp_buf); |
919 } else { | 918 } else { |
920 m_pColorSpace->GetRGB(color_value, R, G, B); | 919 m_pColorSpace->GetRGB(color_value, R, G, B); |
921 } | 920 } |
922 SetPaletteArgb(i, ArgbEncode(255, FXSYS_round(R * 255), | 921 SetPaletteArgb(i, ArgbEncode(255, FXSYS_round(R * 255), |
923 FXSYS_round(G * 255), FXSYS_round(B * 255))); | 922 FXSYS_round(G * 255), FXSYS_round(B * 255))); |
924 } | 923 } |
925 } | 924 } |
926 } | 925 } |
| 926 |
927 void CPDF_DIBSource::ValidateDictParam() { | 927 void CPDF_DIBSource::ValidateDictParam() { |
928 m_bpc = m_bpc_orig; | 928 m_bpc = m_bpc_orig; |
929 CPDF_Object* pFilter = m_pDict->GetElementValue(FX_BSTRC("Filter")); | 929 CPDF_Object* pFilter = m_pDict->GetElementValue("Filter"); |
930 if (pFilter) { | 930 if (pFilter) { |
931 if (pFilter->IsName()) { | 931 if (pFilter->IsName()) { |
932 CFX_ByteString filter = pFilter->GetString(); | 932 CFX_ByteString filter = pFilter->GetString(); |
933 if (filter == FX_BSTRC("CCITTFaxDecode") || | 933 if (filter == "CCITTFaxDecode" || filter == "JBIG2Decode") { |
934 filter == FX_BSTRC("JBIG2Decode")) { | |
935 m_bpc = 1; | 934 m_bpc = 1; |
936 m_nComponents = 1; | 935 m_nComponents = 1; |
937 } | 936 } else if (filter == "RunLengthDecode") { |
938 if (filter == FX_BSTRC("RunLengthDecode")) { | |
939 if (m_bpc != 1) { | 937 if (m_bpc != 1) { |
940 m_bpc = 8; | 938 m_bpc = 8; |
941 } | 939 } |
942 } else if (filter == FX_BSTRC("DCTDecode")) { | 940 } else if (filter == "DCTDecode") { |
943 m_bpc = 8; | 941 m_bpc = 8; |
944 } | 942 } |
945 } else if (CPDF_Array* pArray = pFilter->AsArray()) { | 943 } else if (CPDF_Array* pArray = pFilter->AsArray()) { |
946 if (pArray->GetString(pArray->GetCount() - 1) == | 944 CFX_ByteString filter = pArray->GetString(pArray->GetCount() - 1); |
947 FX_BSTRC("CCITTFaxDecode") || | 945 if (filter == "CCITTFaxDecode" || filter == "JBIG2Decode") { |
948 pArray->GetString(pArray->GetCount() - 1) == | |
949 FX_BSTRC("JBIG2Decode")) { | |
950 m_bpc = 1; | 946 m_bpc = 1; |
951 m_nComponents = 1; | 947 m_nComponents = 1; |
952 } | 948 } else if (filter == "DCTDecode") { |
953 if (pArray->GetString(pArray->GetCount() - 1) == FX_BSTRC("DCTDecode")) { | 949 // Previously, filter == "RunLengthDecode" was checked in the "if" |
954 // Previously, pArray->GetString(pArray->GetCount() - 1) == | 950 // 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; | 951 m_bpc = 8; |
959 } | 952 } |
960 } | 953 } |
961 } | 954 } |
962 if (m_bpc != 1 && m_bpc != 2 && m_bpc != 4 && m_bpc != 8 && m_bpc != 16) { | 955 |
| 956 if (!IsAllowedBPCValue(m_bpc)) |
963 m_bpc = 0; | 957 m_bpc = 0; |
964 } | |
965 } | 958 } |
| 959 |
966 #define NORMALCOLOR_MAX(color, max) \ | 960 #define NORMALCOLOR_MAX(color, max) \ |
967 (color) > (max) ? (max) : (color) < 0 ? 0 : (color); | 961 (color) > (max) ? (max) : (color) < 0 ? 0 : (color); |
968 void CPDF_DIBSource::TranslateScanline24bpp(uint8_t* dest_scan, | 962 void CPDF_DIBSource::TranslateScanline24bpp(uint8_t* dest_scan, |
969 const uint8_t* src_scan) const { | 963 const uint8_t* src_scan) const { |
970 if (m_bpc == 0) { | 964 if (m_bpc == 0) { |
971 return; | 965 return; |
972 } | 966 } |
973 int max_data = (1 << m_bpc) - 1; | 967 int max_data = (1 << m_bpc) - 1; |
974 if (m_bDefaultDecode) { | 968 if (m_bDefaultDecode) { |
975 if (m_Family == PDFCS_DEVICERGB || m_Family == PDFCS_CALRGB) { | 969 if (m_Family == PDFCS_DEVICERGB || m_Family == PDFCS_CALRGB) { |
(...skipping 674 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1650 } | 1644 } |
1651 FX_BOOL CPDF_ImageLoader::Continue(void* LoadHandle, IFX_Pause* pPause) { | 1645 FX_BOOL CPDF_ImageLoader::Continue(void* LoadHandle, IFX_Pause* pPause) { |
1652 return ((CPDF_ProgressiveImageLoaderHandle*)LoadHandle)->Continue(pPause); | 1646 return ((CPDF_ProgressiveImageLoaderHandle*)LoadHandle)->Continue(pPause); |
1653 } | 1647 } |
1654 CPDF_ImageLoader::~CPDF_ImageLoader() { | 1648 CPDF_ImageLoader::~CPDF_ImageLoader() { |
1655 if (!m_bCached) { | 1649 if (!m_bCached) { |
1656 delete m_pBitmap; | 1650 delete m_pBitmap; |
1657 delete m_pMask; | 1651 delete m_pMask; |
1658 } | 1652 } |
1659 } | 1653 } |
OLD | NEW |