summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLei Zhang <thestig@chromium.org>2018-03-05 15:16:37 +0000
committerChromium commit bot <commit-bot@chromium.org>2018-03-05 15:16:37 +0000
commit1330ebbff8a31beb19d38b2a680625a19240a4f0 (patch)
tree2699dde2f80b46527b5dd40184efe3ac927529fa
parent40482e6f06eac0c5089e44df2d62881127eeeb3e (diff)
downloadpdfium-1330ebbff8a31beb19d38b2a680625a19240a4f0.tar.xz
Make FPDFBitmap_GetFormat() work for JBIG images.
BUG=pdfium:945 Change-Id: I2a880e747b6f5a2fabed4d34ce47b69ff589ce3f Reviewed-on: https://pdfium-review.googlesource.com/27814 Commit-Queue: dsinclair <dsinclair@chromium.org> Reviewed-by: dsinclair <dsinclair@chromium.org>
-rw-r--r--core/fpdfapi/page/cpdf_image.cpp8
-rw-r--r--core/fpdfapi/render/cpdf_dibsource.cpp4
-rw-r--r--core/fpdfapi/render/cpdf_dibsource.h2
-rw-r--r--core/fxge/dib/cfx_dibsource.cpp5
-rw-r--r--fpdfsdk/fpdfedit_embeddertest.cpp7
5 files changed, 19 insertions, 7 deletions
diff --git a/core/fpdfapi/page/cpdf_image.cpp b/core/fpdfapi/page/cpdf_image.cpp
index 8ce4185446..b74de62250 100644
--- a/core/fpdfapi/page/cpdf_image.cpp
+++ b/core/fpdfapi/page/cpdf_image.cpp
@@ -331,7 +331,13 @@ RetainPtr<CFX_DIBSource> CPDF_Image::LoadDIBSource() const {
if (!source->Load(m_pDocument.Get(), m_pStream.Get()))
return nullptr;
- return source;
+ if (!source->IsJBigImage())
+ return source;
+
+ CPDF_DIBSource::LoadState ret = CPDF_DIBSource::LoadState::kContinue;
+ while (ret == CPDF_DIBSource::LoadState::kContinue)
+ ret = source->ContinueLoadDIBSource(nullptr);
+ return ret == CPDF_DIBSource::LoadState::kSuccess ? source : nullptr;
}
RetainPtr<CFX_DIBSource> CPDF_Image::DetachBitmap() {
diff --git a/core/fpdfapi/render/cpdf_dibsource.cpp b/core/fpdfapi/render/cpdf_dibsource.cpp
index 8a752374b6..3c8d471767 100644
--- a/core/fpdfapi/render/cpdf_dibsource.cpp
+++ b/core/fpdfapi/render/cpdf_dibsource.cpp
@@ -708,6 +708,10 @@ RetainPtr<CPDF_DIBSource> CPDF_DIBSource::DetachMask() {
return std::move(m_pMask);
}
+bool CPDF_DIBSource::IsJBigImage() const {
+ return m_pStreamAcc->GetImageDecoder() == "JBIG2Decode";
+}
+
CPDF_DIBSource::LoadState CPDF_DIBSource::StartLoadMaskDIB() {
m_pMask = pdfium::MakeRetain<CPDF_DIBSource>();
LoadState ret = m_pMask->StartLoadDIBSource(
diff --git a/core/fpdfapi/render/cpdf_dibsource.h b/core/fpdfapi/render/cpdf_dibsource.h
index a3e44c57e7..a29385f6ad 100644
--- a/core/fpdfapi/render/cpdf_dibsource.h
+++ b/core/fpdfapi/render/cpdf_dibsource.h
@@ -76,6 +76,8 @@ class CPDF_DIBSource : public CFX_DIBSource {
LoadState ContinueLoadDIBSource(IFX_PauseIndicator* pPause);
RetainPtr<CPDF_DIBSource> DetachMask();
+ bool IsJBigImage() const;
+
private:
CPDF_DIBSource();
diff --git a/core/fxge/dib/cfx_dibsource.cpp b/core/fxge/dib/cfx_dibsource.cpp
index f96ca1e074..104b3caf96 100644
--- a/core/fxge/dib/cfx_dibsource.cpp
+++ b/core/fxge/dib/cfx_dibsource.cpp
@@ -1225,12 +1225,13 @@ bool CFX_DIBSource::ConvertBuffer(
}
case FXDIB_8bppRgb:
case FXDIB_8bppRgba: {
- if (bpp == 8 && !pSrcBitmap->GetPalette()) {
+ const bool bpp_1_or_8 = (bpp == 1 || bpp == 8);
+ if (bpp_1_or_8 && !pSrcBitmap->GetPalette()) {
return ConvertBuffer(FXDIB_8bppMask, dest_buf, dest_pitch, width,
height, pSrcBitmap, src_left, src_top, p_pal);
}
p_pal->reset(FX_Alloc(uint32_t, 256));
- if ((bpp == 1 || bpp == 8) && pSrcBitmap->GetPalette()) {
+ if (bpp_1_or_8 && pSrcBitmap->GetPalette()) {
ConvertBuffer_Plt2PltRgb8(dest_buf, dest_pitch, width, height,
pSrcBitmap, src_left, src_top, p_pal->get());
return true;
diff --git a/fpdfsdk/fpdfedit_embeddertest.cpp b/fpdfsdk/fpdfedit_embeddertest.cpp
index 8754a665f7..3fc6cae8b4 100644
--- a/fpdfsdk/fpdfedit_embeddertest.cpp
+++ b/fpdfsdk/fpdfedit_embeddertest.cpp
@@ -1131,12 +1131,11 @@ TEST_F(FPDFEditEmbeddertest, ExtractJBigImageBitmap) {
FPDF_PAGEOBJECT obj = FPDFPage_GetObject(page, 0);
ASSERT_EQ(FPDF_PAGEOBJ_IMAGE, FPDFPageObj_GetType(obj));
{
- // TODO(bug_945): This should return a valid bitmap. This test should be
- // able to successfully check |bitmap| using FPDFBitmap_GetFormat() and
- // CompareBitmap().
std::unique_ptr<void, FPDFBitmapDeleter> bitmap(
FPDFImageObj_GetBitmap(obj));
- ASSERT_FALSE(bitmap);
+ ASSERT_TRUE(bitmap);
+ EXPECT_EQ(FPDFBitmap_Gray, FPDFBitmap_GetFormat(bitmap.get()));
+ CompareBitmap(bitmap.get(), 1152, 720, "3f6a48e2b3e91b799bf34567f55cb4de");
}
UnloadPage(page);