diff options
author | Lei Zhang <thestig@chromium.org> | 2018-03-05 14:55:07 +0000 |
---|---|---|
committer | Chromium commit bot <commit-bot@chromium.org> | 2018-03-05 14:55:07 +0000 |
commit | aa11f46e7bd846ef26d4cdd2be4f92f7a63d1cdb (patch) | |
tree | 5427063bd20630ae67c045490c1b41a8143c5668 /core/fpdfapi/render | |
parent | b05836511dfab9483438fc8dcbab2f4ae6dcc1b1 (diff) | |
download | pdfium-aa11f46e7bd846ef26d4cdd2be4f92f7a63d1cdb.tar.xz |
Change CPDF_DIBSource::LoadJpxBitmap() to return a bitmap.
Change-Id: If819bee4809142e2f9c9b0830f00264b0fbaf862
Reviewed-on: https://pdfium-review.googlesource.com/27852
Commit-Queue: dsinclair <dsinclair@chromium.org>
Reviewed-by: dsinclair <dsinclair@chromium.org>
Diffstat (limited to 'core/fpdfapi/render')
-rw-r--r-- | core/fpdfapi/render/cpdf_dibsource.cpp | 32 | ||||
-rw-r--r-- | core/fpdfapi/render/cpdf_dibsource.h | 2 |
2 files changed, 16 insertions, 18 deletions
diff --git a/core/fpdfapi/render/cpdf_dibsource.cpp b/core/fpdfapi/render/cpdf_dibsource.cpp index 1a35826232..1233992f72 100644 --- a/core/fpdfapi/render/cpdf_dibsource.cpp +++ b/core/fpdfapi/render/cpdf_dibsource.cpp @@ -460,7 +460,7 @@ int CPDF_DIBSource::CreateDecoder() { return 0; if (decoder == "JPXDecode") { - LoadJpxBitmap(); + m_pCachedBitmap = LoadJpxBitmap(); return m_pCachedBitmap ? 1 : 0; } if (decoder == "JBIG2Decode") { @@ -580,25 +580,25 @@ bool CPDF_DIBSource::CreateDCTDecoder(const uint8_t* src_data, return true; } -void CPDF_DIBSource::LoadJpxBitmap() { +RetainPtr<CFX_DIBitmap> CPDF_DIBSource::LoadJpxBitmap() { CCodec_JpxModule* pJpxModule = CPDF_ModuleMgr::Get()->GetJpxModule(); auto context = pdfium::MakeUnique<JpxBitMapContext>(pJpxModule); context->set_decoder(pJpxModule->CreateDecoder( m_pStreamAcc->GetData(), m_pStreamAcc->GetSize(), m_pColorSpace)); if (!context->decoder()) - return; + return nullptr; uint32_t width = 0; uint32_t height = 0; uint32_t components = 0; pJpxModule->GetImageInfo(context->decoder(), &width, &height, &components); if (static_cast<int>(width) < m_Width || static_cast<int>(height) < m_Height) - return; + return nullptr; bool bSwapRGB = false; if (m_pColorSpace) { if (components != m_pColorSpace->CountComponents()) - return; + return nullptr; if (m_pColorSpace == CPDF_ColorSpace::GetStockCS(PDFCS_DEVICERGB)) { bSwapRGB = true; @@ -625,12 +625,11 @@ void CPDF_DIBSource::LoadJpxBitmap() { format = FXDIB_Rgb; } - m_pCachedBitmap = pdfium::MakeRetain<CFX_DIBitmap>(); - if (!m_pCachedBitmap->Create(width, height, format)) { - m_pCachedBitmap.Reset(); - return; - } - m_pCachedBitmap->Clear(0xFFFFFFFF); + auto pCachedBitmap = pdfium::MakeRetain<CFX_DIBitmap>(); + if (!pCachedBitmap->Create(width, height, format)) + return nullptr; + + pCachedBitmap->Clear(0xFFFFFFFF); std::vector<uint8_t> output_offsets(components); for (uint32_t i = 0; i < components; ++i) output_offsets[i] = i; @@ -638,17 +637,15 @@ void CPDF_DIBSource::LoadJpxBitmap() { output_offsets[0] = 2; output_offsets[2] = 0; } - if (!pJpxModule->Decode(context->decoder(), m_pCachedBitmap->GetBuffer(), - m_pCachedBitmap->GetPitch(), output_offsets)) { - m_pCachedBitmap.Reset(); - return; + if (!pJpxModule->Decode(context->decoder(), pCachedBitmap->GetBuffer(), + pCachedBitmap->GetPitch(), output_offsets)) { + return nullptr; } if (m_pColorSpace && m_pColorSpace->GetFamily() == PDFCS_INDEXED && m_bpc < 8) { int scale = 8 - m_bpc; for (uint32_t row = 0; row < height; ++row) { - uint8_t* scanline = - const_cast<uint8_t*>(m_pCachedBitmap->GetScanline(row)); + uint8_t* scanline = const_cast<uint8_t*>(pCachedBitmap->GetScanline(row)); for (uint32_t col = 0; col < width; ++col) { *scanline = (*scanline) >> scale; ++scanline; @@ -656,6 +653,7 @@ void CPDF_DIBSource::LoadJpxBitmap() { } } m_bpc = 8; + return pCachedBitmap; } int CPDF_DIBSource::StartLoadMask() { diff --git a/core/fpdfapi/render/cpdf_dibsource.h b/core/fpdfapi/render/cpdf_dibsource.h index dce5a535c4..931fdc4fc8 100644 --- a/core/fpdfapi/render/cpdf_dibsource.h +++ b/core/fpdfapi/render/cpdf_dibsource.h @@ -86,7 +86,7 @@ class CPDF_DIBSource : public CFX_DIBSource { bool LoadColorInfo(const CPDF_Dictionary* pFormResources, const CPDF_Dictionary* pPageResources); DIB_COMP_DATA* GetDecodeAndMaskArray(bool* bDefaultDecode, bool* bColorKey); - void LoadJpxBitmap(); + RetainPtr<CFX_DIBitmap> LoadJpxBitmap(); void LoadPalette(); int CreateDecoder(); bool CreateDCTDecoder(const uint8_t* src_data, |