diff options
author | Lei Zhang <thestig@chromium.org> | 2017-05-09 18:37:10 -0700 |
---|---|---|
committer | Chromium commit bot <commit-bot@chromium.org> | 2017-05-10 21:56:24 +0000 |
commit | bdc4580d450f84f094a93a0227a3f708416bc563 (patch) | |
tree | deec66aff0196fbd30da0217bd39bee5f4d89396 /core/fpdfapi/render | |
parent | 0a0892626d24ce82e7026c32c71b1de036d4bbe1 (diff) | |
download | pdfium-bdc4580d450f84f094a93a0227a3f708416bc563.tar.xz |
Split DCT decoder creation from CPDF_DIBSource::CreateDecoder().
Change-Id: Ia0ea49f0460fcb8e55542f237d321bb9207aa8e1
Reviewed-on: https://pdfium-review.googlesource.com/5250
Reviewed-by: Tom Sepez <tsepez@chromium.org>
Commit-Queue: Lei Zhang <thestig@chromium.org>
Diffstat (limited to 'core/fpdfapi/render')
-rw-r--r-- | core/fpdfapi/render/cpdf_dibsource.cpp | 133 | ||||
-rw-r--r-- | core/fpdfapi/render/cpdf_dibsource.h | 3 |
2 files changed, 78 insertions, 58 deletions
diff --git a/core/fpdfapi/render/cpdf_dibsource.cpp b/core/fpdfapi/render/cpdf_dibsource.cpp index 0b8c89551c..c2156a1555 100644 --- a/core/fpdfapi/render/cpdf_dibsource.cpp +++ b/core/fpdfapi/render/cpdf_dibsource.cpp @@ -537,64 +537,8 @@ int CPDF_DIBSource::CreateDecoder() { ->CreateRunLengthDecoder(src_data, src_size, m_Width, m_Height, m_nComponents, m_bpc); } else if (decoder == "DCTDecode") { - m_pDecoder = CPDF_ModuleMgr::Get()->GetJpegModule()->CreateDecoder( - src_data, src_size, m_Width, m_Height, m_nComponents, - !pParams || pParams->GetIntegerFor("ColorTransform", 1)); - if (!m_pDecoder) { - bool bTransform = false; - int comps; - int bpc; - CCodec_JpegModule* pJpegModule = CPDF_ModuleMgr::Get()->GetJpegModule(); - if (pJpegModule->LoadInfo(src_data, src_size, &m_Width, &m_Height, &comps, - &bpc, &bTransform)) { - if (m_nComponents != static_cast<uint32_t>(comps)) { - FX_Free(m_pCompData); - m_pCompData = nullptr; - m_nComponents = static_cast<uint32_t>(comps); - if (m_pColorSpace) { - switch (m_Family) { - case PDFCS_DEVICEGRAY: - case PDFCS_DEVICERGB: - case PDFCS_DEVICECMYK: { - uint32_t dwMinComps = ComponentsForFamily(m_Family); - if (m_pColorSpace->CountComponents() < dwMinComps || - m_nComponents < dwMinComps) { - return 0; - } - break; - } - case PDFCS_LAB: { - if (m_nComponents != 3 || m_pColorSpace->CountComponents() < 3) - return 0; - break; - } - case PDFCS_ICCBASED: { - if (!IsAllowedICCComponents(m_nComponents) || - !IsAllowedICCComponents(m_pColorSpace->CountComponents()) || - m_pColorSpace->CountComponents() < m_nComponents) { - return 0; - } - break; - } - default: { - if (m_pColorSpace->CountComponents() != m_nComponents) - return 0; - break; - } - } - } else { - if (m_Family == PDFCS_LAB && m_nComponents != 3) - return 0; - } - m_pCompData = GetDecodeAndMaskArray(&m_bDefaultDecode, &m_bColorKey); - if (!m_pCompData) - return 0; - } - m_bpc = bpc; - m_pDecoder = CPDF_ModuleMgr::Get()->GetJpegModule()->CreateDecoder( - src_data, src_size, m_Width, m_Height, m_nComponents, bTransform); - } - } + if (!CreateDCTDecoder(src_data, src_size, pParams)) + return 0; } if (!m_pDecoder) return 0; @@ -612,6 +556,79 @@ int CPDF_DIBSource::CreateDecoder() { return 1; } +bool CPDF_DIBSource::CreateDCTDecoder(const uint8_t* src_data, + uint32_t src_size, + const CPDF_Dictionary* pParams) { + m_pDecoder = CPDF_ModuleMgr::Get()->GetJpegModule()->CreateDecoder( + src_data, src_size, m_Width, m_Height, m_nComponents, + !pParams || pParams->GetIntegerFor("ColorTransform", 1)); + if (m_pDecoder) + return true; + + bool bTransform = false; + int comps; + int bpc; + CCodec_JpegModule* pJpegModule = CPDF_ModuleMgr::Get()->GetJpegModule(); + if (!pJpegModule->LoadInfo(src_data, src_size, &m_Width, &m_Height, &comps, + &bpc, &bTransform)) { + return false; + } + + if (m_nComponents == static_cast<uint32_t>(comps)) { + m_bpc = bpc; + m_pDecoder = CPDF_ModuleMgr::Get()->GetJpegModule()->CreateDecoder( + src_data, src_size, m_Width, m_Height, m_nComponents, bTransform); + return true; + } + + m_nComponents = static_cast<uint32_t>(comps); + FX_Free(m_pCompData); + m_pCompData = nullptr; + if (m_pColorSpace) { + switch (m_Family) { + case PDFCS_DEVICEGRAY: + case PDFCS_DEVICERGB: + case PDFCS_DEVICECMYK: { + uint32_t dwMinComps = ComponentsForFamily(m_Family); + if (m_pColorSpace->CountComponents() < dwMinComps || + m_nComponents < dwMinComps) { + return false; + } + break; + } + case PDFCS_LAB: { + if (m_nComponents != 3 || m_pColorSpace->CountComponents() < 3) + return false; + break; + } + case PDFCS_ICCBASED: { + if (!IsAllowedICCComponents(m_nComponents) || + !IsAllowedICCComponents(m_pColorSpace->CountComponents()) || + m_pColorSpace->CountComponents() < m_nComponents) { + return false; + } + break; + } + default: { + if (m_pColorSpace->CountComponents() != m_nComponents) + return false; + break; + } + } + } else { + if (m_Family == PDFCS_LAB && m_nComponents != 3) + return false; + } + m_pCompData = GetDecodeAndMaskArray(&m_bDefaultDecode, &m_bColorKey); + if (!m_pCompData) + return false; + + m_bpc = bpc; + m_pDecoder = CPDF_ModuleMgr::Get()->GetJpegModule()->CreateDecoder( + src_data, src_size, m_Width, m_Height, m_nComponents, bTransform); + return true; +} + void CPDF_DIBSource::LoadJpxBitmap() { CCodec_JpxModule* pJpxModule = CPDF_ModuleMgr::Get()->GetJpxModule(); if (!pJpxModule) diff --git a/core/fpdfapi/render/cpdf_dibsource.h b/core/fpdfapi/render/cpdf_dibsource.h index e9fc6c1132..00f8c3a2f5 100644 --- a/core/fpdfapi/render/cpdf_dibsource.h +++ b/core/fpdfapi/render/cpdf_dibsource.h @@ -84,6 +84,9 @@ class CPDF_DIBSource : public CFX_DIBSource { void LoadJpxBitmap(); void LoadPalette(); int CreateDecoder(); + bool CreateDCTDecoder(const uint8_t* src_data, + uint32_t src_size, + const CPDF_Dictionary* pParams); void TranslateScanline24bpp(uint8_t* dest_scan, const uint8_t* src_scan) const; void ValidateDictParam(); |