Separate TiffModule from ModuleMgr.
TiffModule does not need to implement ProgressiveDecoderIface. Make
TiffModule method static and disallow instantiation.
Change-Id: I97708897712e5d132fb7ffbd38eedea8f843fa4f
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/69933
Reviewed-by: Tom Sepez <tsepez@chromium.org>
Commit-Queue: Lei Zhang <thestig@chromium.org>
diff --git a/core/fxcodec/fx_codec.cpp b/core/fxcodec/fx_codec.cpp
index 51e8117..920cffe 100644
--- a/core/fxcodec/fx_codec.cpp
+++ b/core/fxcodec/fx_codec.cpp
@@ -55,10 +55,6 @@
#ifdef PDF_ENABLE_XFA_PNG
SetPngModule(pdfium::MakeUnique<PngModule>());
#endif
-
-#ifdef PDF_ENABLE_XFA_TIFF
- SetTiffModule(pdfium::MakeUnique<TiffModule>());
-#endif
}
ModuleMgr::~ModuleMgr() = default;
diff --git a/core/fxcodec/fx_codec.h b/core/fxcodec/fx_codec.h
index 8ab623a..3202031 100644
--- a/core/fxcodec/fx_codec.h
+++ b/core/fxcodec/fx_codec.h
@@ -27,10 +27,6 @@
#ifdef PDF_ENABLE_XFA_PNG
#include "core/fxcodec/png/pngmodule.h"
#endif // PDF_ENABLE_XFA_PNG
-
-#ifdef PDF_ENABLE_XFA_TIFF
-#include "core/fxcodec/tiff/tiffmodule.h"
-#endif // PDF_ENABLE_XFA_TIFF
#endif // PDF_ENABLE_XFA
namespace fxcodec {
@@ -80,13 +76,6 @@
m_pPngModule = std::move(module);
}
#endif // PDF_ENABLE_XFA_PNG
-
-#ifdef PDF_ENABLE_XFA_TIFF
- TiffModule* GetTiffModule() const { return m_pTiffModule.get(); }
- void SetTiffModule(std::unique_ptr<TiffModule> module) {
- m_pTiffModule = std::move(module);
- }
-#endif // PDF_ENABLE_XFA_TIFF
#endif // PDF_ENABLE_XFA
private:
@@ -105,10 +94,6 @@
#ifdef PDF_ENABLE_XFA_PNG
std::unique_ptr<PngModule> m_pPngModule;
#endif // PDF_ENABLE_XFA_PNG
-
-#ifdef PDF_ENABLE_XFA_TIFF
- std::unique_ptr<TiffModule> m_pTiffModule;
-#endif // PDF_ENABLE_XFA_TIFF
#endif // PDF_ENABLE_XFA
};
diff --git a/core/fxcodec/progressivedecoder.cpp b/core/fxcodec/progressivedecoder.cpp
index 87772b7..1541cd1 100644
--- a/core/fxcodec/progressivedecoder.cpp
+++ b/core/fxcodec/progressivedecoder.cpp
@@ -23,6 +23,10 @@
#include "third_party/base/logging.h"
#include "third_party/base/ptr_util.h"
+#ifdef PDF_ENABLE_XFA_TIFF
+#include "core/fxcodec/tiff/tiffmodule.h"
+#endif // PDF_ENABLE_XFA_TIFF
+
namespace fxcodec {
namespace {
@@ -1298,16 +1302,15 @@
#ifdef PDF_ENABLE_XFA_TIFF
bool ProgressiveDecoder::TiffDetectImageTypeFromFile(
CFX_DIBAttribute* pAttribute) {
- TiffModule* pTiffModule = m_pCodecMgr->GetTiffModule();
- m_pTiffContext = pTiffModule->CreateDecoder(m_pFile);
+ m_pTiffContext = TiffModule::CreateDecoder(m_pFile);
if (!m_pTiffContext) {
m_status = FXCODEC_STATUS_ERR_FORMAT;
return false;
}
int32_t dummy_bpc;
- bool ret = pTiffModule->LoadFrameInfo(m_pTiffContext.get(), 0, &m_SrcWidth,
- &m_SrcHeight, &m_SrcComponents,
- &dummy_bpc, pAttribute);
+ bool ret = TiffModule::LoadFrameInfo(m_pTiffContext.get(), 0, &m_SrcWidth,
+ &m_SrcHeight, &m_SrcComponents,
+ &dummy_bpc, pAttribute);
m_SrcComponents = 4;
m_clipBox = FX_RECT(0, 0, m_SrcWidth, m_SrcHeight);
if (!ret) {
@@ -1319,7 +1322,6 @@
}
FXCODEC_STATUS ProgressiveDecoder::TiffContinueDecode() {
- TiffModule* pTiffModule = m_pCodecMgr->GetTiffModule();
bool ret = false;
if (m_pDeviceBitmap->GetBPP() == 32 &&
m_pDeviceBitmap->GetWidth() == m_SrcWidth && m_SrcWidth == m_sizeX &&
@@ -1327,7 +1329,7 @@
m_startX == 0 && m_startY == 0 && m_clipBox.left == 0 &&
m_clipBox.top == 0 && m_clipBox.right == m_SrcWidth &&
m_clipBox.bottom == m_SrcHeight) {
- ret = pTiffModule->Decode(m_pTiffContext.get(), m_pDeviceBitmap);
+ ret = TiffModule::Decode(m_pTiffContext.get(), m_pDeviceBitmap);
m_pDeviceBitmap = nullptr;
m_pFile = nullptr;
if (!ret) {
@@ -1346,7 +1348,7 @@
m_status = FXCODEC_STATUS_ERR_MEMORY;
return m_status;
}
- ret = pTiffModule->Decode(m_pTiffContext.get(), pDIBitmap);
+ ret = TiffModule::Decode(m_pTiffContext.get(), pDIBitmap);
if (!ret) {
m_pDeviceBitmap = nullptr;
m_pFile = nullptr;
diff --git a/core/fxcodec/progressivedecoder.h b/core/fxcodec/progressivedecoder.h
index f3fe497..53d3413 100644
--- a/core/fxcodec/progressivedecoder.h
+++ b/core/fxcodec/progressivedecoder.h
@@ -31,10 +31,6 @@
#include "core/fxcodec/png/pngmodule.h"
#endif // PDF_ENABLE_XFA_PNG
-#ifdef PDF_ENABLE_XFA_TIFF
-#include "core/fxcodec/tiff/tiffmodule.h"
-#endif // PDF_ENABLE_XFA_TIFF
-
class CFX_DIBitmap;
class IFX_SeekableReadStream;
diff --git a/core/fxcodec/tiff/tiffmodule.cpp b/core/fxcodec/tiff/tiffmodule.cpp
index 19ed7bb..8c560f2 100644
--- a/core/fxcodec/tiff/tiffmodule.cpp
+++ b/core/fxcodec/tiff/tiffmodule.cpp
@@ -483,6 +483,7 @@
namespace fxcodec {
+// static
std::unique_ptr<ProgressiveDecoderIface::Context> TiffModule::CreateDecoder(
const RetainPtr<IFX_SeekableReadStream>& file_ptr) {
auto pDecoder = pdfium::MakeUnique<CTiffContext>();
@@ -492,19 +493,8 @@
return pDecoder;
}
-FX_FILESIZE TiffModule::GetAvailInput(Context* pContext) const {
- NOTREACHED();
- return 0;
-}
-
-bool TiffModule::Input(Context* pContext,
- RetainPtr<CFX_CodecMemory> codec_memory,
- CFX_DIBAttribute*) {
- NOTREACHED();
- return false;
-}
-
-bool TiffModule::LoadFrameInfo(Context* pContext,
+// static
+bool TiffModule::LoadFrameInfo(ProgressiveDecoderIface::Context* pContext,
int32_t frame,
int32_t* width,
int32_t* height,
@@ -517,7 +507,8 @@
return ctx->LoadFrameInfo(frame, width, height, comps, bpc, pAttribute);
}
-bool TiffModule::Decode(Context* pContext,
+// static
+bool TiffModule::Decode(ProgressiveDecoderIface::Context* pContext,
const RetainPtr<CFX_DIBitmap>& pDIBitmap) {
auto* ctx = static_cast<CTiffContext*>(pContext);
return ctx->Decode(pDIBitmap);
diff --git a/core/fxcodec/tiff/tiffmodule.h b/core/fxcodec/tiff/tiffmodule.h
index 01c0577..3c60d14 100644
--- a/core/fxcodec/tiff/tiffmodule.h
+++ b/core/fxcodec/tiff/tiffmodule.h
@@ -11,6 +11,10 @@
#include "core/fxcodec/progressive_decoder_iface.h"
+#ifndef PDF_ENABLE_XFA_TIFF
+#error "TIFF must be enabled"
+#endif
+
class CFX_DIBitmap;
class IFX_SeekableReadStream;
@@ -18,25 +22,24 @@
class CFX_DIBAttribute;
-class TiffModule final : public ProgressiveDecoderIface {
+class TiffModule {
public:
- std::unique_ptr<Context> CreateDecoder(
+ static std::unique_ptr<ProgressiveDecoderIface::Context> CreateDecoder(
const RetainPtr<IFX_SeekableReadStream>& file_ptr);
- // ProgressiveDecoderIface:
- FX_FILESIZE GetAvailInput(Context* pContext) const override;
- bool Input(Context* pContext,
- RetainPtr<CFX_CodecMemory> codec_memory,
- CFX_DIBAttribute* pAttribute) override;
+ static bool LoadFrameInfo(ProgressiveDecoderIface::Context* ctx,
+ int32_t frame,
+ int32_t* width,
+ int32_t* height,
+ int32_t* comps,
+ int32_t* bpc,
+ CFX_DIBAttribute* pAttribute);
+ static bool Decode(ProgressiveDecoderIface::Context* ctx,
+ const RetainPtr<CFX_DIBitmap>& pDIBitmap);
- bool LoadFrameInfo(Context* ctx,
- int32_t frame,
- int32_t* width,
- int32_t* height,
- int32_t* comps,
- int32_t* bpc,
- CFX_DIBAttribute* pAttribute);
- bool Decode(Context* ctx, const RetainPtr<CFX_DIBitmap>& pDIBitmap);
+ TiffModule() = delete;
+ TiffModule(const TiffModule&) = delete;
+ TiffModule& operator=(const TiffModule&) = delete;
};
} // namespace fxcodec