summaryrefslogtreecommitdiff
path: root/core/fpdfapi/render/cpdf_dibsource.cpp
diff options
context:
space:
mode:
authorLei Zhang <thestig@chromium.org>2017-05-09 18:37:10 -0700
committerChromium commit bot <commit-bot@chromium.org>2017-05-10 21:56:24 +0000
commitbdc4580d450f84f094a93a0227a3f708416bc563 (patch)
treedeec66aff0196fbd30da0217bd39bee5f4d89396 /core/fpdfapi/render/cpdf_dibsource.cpp
parent0a0892626d24ce82e7026c32c71b1de036d4bbe1 (diff)
downloadpdfium-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/cpdf_dibsource.cpp')
-rw-r--r--core/fpdfapi/render/cpdf_dibsource.cpp133
1 files changed, 75 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)