Move XFA-only portion of JpegModule into an inner class.

Create an inner ProgressiveDecoder class for code that's only used when
XFA is enabled. Remaining JpegModule methods all become static, and
ModuleMgr no longer needs to manage an instance of JpegModule.

Change-Id: Ib8e6e6b54c26683e7cc6602ecc926bd63a83d67d
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/69914
Commit-Queue: Lei Zhang <thestig@chromium.org>
Reviewed-by: Tom Sepez <tsepez@chromium.org>
diff --git a/core/fpdfapi/page/cpdf_dib.cpp b/core/fpdfapi/page/cpdf_dib.cpp
index c6cb3da..50982b5 100644
--- a/core/fpdfapi/page/cpdf_dib.cpp
+++ b/core/fpdfapi/page/cpdf_dib.cpp
@@ -554,15 +554,13 @@
 
 bool CPDF_DIB::CreateDCTDecoder(pdfium::span<const uint8_t> src_span,
                                 const CPDF_Dictionary* pParams) {
-  JpegModule* pJpegModule = fxcodec::ModuleMgr::GetInstance()->GetJpegModule();
-  m_pDecoder = pJpegModule->CreateDecoder(
+  m_pDecoder = JpegModule::CreateDecoder(
       src_span, m_Width, m_Height, m_nComponents,
       !pParams || pParams->GetIntegerFor("ColorTransform", 1));
   if (m_pDecoder)
     return true;
 
-  Optional<JpegModule::JpegImageInfo> info_opt =
-      pJpegModule->LoadInfo(src_span);
+  Optional<JpegModule::JpegImageInfo> info_opt = JpegModule::LoadInfo(src_span);
   if (!info_opt.has_value())
     return false;
 
@@ -577,8 +575,8 @@
 
   if (m_nComponents == static_cast<uint32_t>(info.num_components)) {
     m_bpc = info.bits_per_components;
-    m_pDecoder = pJpegModule->CreateDecoder(
-        src_span, m_Width, m_Height, m_nComponents, info.color_transform);
+    m_pDecoder = JpegModule::CreateDecoder(src_span, m_Width, m_Height,
+                                           m_nComponents, info.color_transform);
     return true;
   }
 
@@ -622,8 +620,8 @@
     return false;
 
   m_bpc = info.bits_per_components;
-  m_pDecoder = pJpegModule->CreateDecoder(src_span, m_Width, m_Height,
-                                          m_nComponents, info.color_transform);
+  m_pDecoder = JpegModule::CreateDecoder(src_span, m_Width, m_Height,
+                                         m_nComponents, info.color_transform);
   return true;
 }
 
diff --git a/core/fpdfapi/page/cpdf_image.cpp b/core/fpdfapi/page/cpdf_image.cpp
index 1ed8f7e..f46ba8e 100644
--- a/core/fpdfapi/page/cpdf_image.cpp
+++ b/core/fpdfapi/page/cpdf_image.cpp
@@ -23,7 +23,6 @@
 #include "core/fpdfapi/parser/cpdf_reference.h"
 #include "core/fpdfapi/parser/cpdf_stream.h"
 #include "core/fpdfapi/parser/cpdf_string.h"
-#include "core/fxcodec/fx_codec.h"
 #include "core/fxcodec/jpeg/jpegmodule.h"
 #include "core/fxcrt/fx_memory_wrappers.h"
 #include "core/fxcrt/fx_stream.h"
@@ -83,8 +82,7 @@
 
 RetainPtr<CPDF_Dictionary> CPDF_Image::InitJPEG(
     pdfium::span<uint8_t> src_span) {
-  Optional<JpegModule::JpegImageInfo> info_opt =
-      fxcodec::ModuleMgr::GetInstance()->GetJpegModule()->LoadInfo(src_span);
+  Optional<JpegModule::JpegImageInfo> info_opt = JpegModule::LoadInfo(src_span);
   if (!info_opt.has_value())
     return nullptr;
 
diff --git a/core/fpdfapi/page/cpdf_streamparser.cpp b/core/fpdfapi/page/cpdf_streamparser.cpp
index 26857f4..75e5908 100644
--- a/core/fpdfapi/page/cpdf_streamparser.cpp
+++ b/core/fpdfapi/page/cpdf_streamparser.cpp
@@ -91,10 +91,9 @@
                             &ignored_size);
   }
   if (decoder == "DCTDecode") {
-    std::unique_ptr<ScanlineDecoder> pDecoder =
-        fxcodec::ModuleMgr::GetInstance()->GetJpegModule()->CreateDecoder(
-            src_span, width, height, 0,
-            !pParam || pParam->GetIntegerFor("ColorTransform", 1));
+    std::unique_ptr<ScanlineDecoder> pDecoder = JpegModule::CreateDecoder(
+        src_span, width, height, 0,
+        !pParam || pParam->GetIntegerFor("ColorTransform", 1));
     return DecodeAllScanlines(std::move(pDecoder));
   }
   if (decoder == "CCITTFaxDecode") {
diff --git a/core/fxcodec/BUILD.gn b/core/fxcodec/BUILD.gn
index 9ec1cee..db8ff37 100644
--- a/core/fxcodec/BUILD.gn
+++ b/core/fxcodec/BUILD.gn
@@ -64,7 +64,6 @@
     "jpx/cjpx_decoder.h",
     "jpx/jpx_decode_utils.cpp",
     "jpx/jpx_decode_utils.h",
-    "progressive_decoder_iface.h",
     "scanlinedecoder.cpp",
     "scanlinedecoder.h",
   ]
@@ -81,6 +80,7 @@
 
   if (pdf_enable_xfa) {
     sources += [
+      "progressive_decoder_iface.h",
       "progressivedecoder.cpp",
       "progressivedecoder.h",
     ]
diff --git a/core/fxcodec/fx_codec.cpp b/core/fxcodec/fx_codec.cpp
index 5625534..4dcf695 100644
--- a/core/fxcodec/fx_codec.cpp
+++ b/core/fxcodec/fx_codec.cpp
@@ -12,7 +12,6 @@
 #include <utility>
 
 #include "core/fxcodec/jbig2/jbig2module.h"
-#include "core/fxcodec/jpeg/jpegmodule.h"
 #include "core/fxcrt/fx_extension.h"
 #include "core/fxcrt/fx_safe_types.h"
 #include "third_party/base/logging.h"
@@ -45,9 +44,7 @@
   return g_ModuleMgr;
 }
 
-ModuleMgr::ModuleMgr()
-    : m_pJpegModule(pdfium::MakeUnique<JpegModule>()),
-      m_pJbig2Module(pdfium::MakeUnique<Jbig2Module>()) {
+ModuleMgr::ModuleMgr() : m_pJbig2Module(pdfium::MakeUnique<Jbig2Module>()) {
 #ifdef PDF_ENABLE_XFA_BMP
   SetBmpModule(pdfium::MakeUnique<BmpModule>());
 #endif
diff --git a/core/fxcodec/fx_codec.h b/core/fxcodec/fx_codec.h
index 6b54386..7f20475 100644
--- a/core/fxcodec/fx_codec.h
+++ b/core/fxcodec/fx_codec.h
@@ -49,7 +49,6 @@
 #endif  // PDF_ENABLE_XFA
 
 class Jbig2Module;
-class JpegModule;
 class ProgressiveDecoder;
 
 class ModuleMgr {
@@ -59,7 +58,6 @@
   static void Destroy();
   static ModuleMgr* GetInstance();
 
-  JpegModule* GetJpegModule() const { return m_pJpegModule.get(); }
   Jbig2Module* GetJbig2Module() const { return m_pJbig2Module.get(); }
 
 #ifdef PDF_ENABLE_XFA
@@ -98,7 +96,6 @@
   ModuleMgr();
   ~ModuleMgr();
 
-  std::unique_ptr<JpegModule> m_pJpegModule;
   std::unique_ptr<Jbig2Module> m_pJbig2Module;
 
 #ifdef PDF_ENABLE_XFA
diff --git a/core/fxcodec/jpeg/jpegmodule.cpp b/core/fxcodec/jpeg/jpegmodule.cpp
index 2b54982..634dbbf 100644
--- a/core/fxcodec/jpeg/jpegmodule.cpp
+++ b/core/fxcodec/jpeg/jpegmodule.cpp
@@ -37,6 +37,11 @@
 #endif
 }  // extern "C"
 
+#ifdef PDF_ENABLE_XFA
+#include "third_party/base/no_destructor.h"
+#endif
+
+#ifdef PDF_ENABLE_XFA
 class CJpegContext final : public ProgressiveDecoderIface::Context {
  public:
   CJpegContext();
@@ -52,6 +57,7 @@
   void* (*m_AllocFunc)(unsigned int);
   void (*m_FreeFunc)(void*);
 };
+#endif
 
 static pdfium::span<const uint8_t> JpegScanSOI(
     pdfium::span<const uint8_t> src_span) {
@@ -102,6 +108,7 @@
 }
 #endif  // defined(OS_WIN)
 
+#ifdef PDF_ENABLE_XFA
 static void error_fatal1(j_common_ptr cinfo) {
   auto* pContext = reinterpret_cast<CJpegContext*>(cinfo->client_data);
   longjmp(pContext->m_JumpMark, -1);
@@ -125,6 +132,7 @@
 static void jpeg_free_func(void* p) {
   FX_Free(p);
 }
+#endif
 
 }  // extern "C"
 
@@ -187,6 +195,7 @@
   return true;
 }
 
+#ifdef PDF_ENABLE_XFA
 CJpegContext::CJpegContext()
     : m_AllocFunc(jpeg_alloc_func), m_FreeFunc(jpeg_free_func) {
   m_Info.client_data = this;
@@ -208,6 +217,7 @@
 CJpegContext::~CJpegContext() {
   jpeg_destroy_decompress(&m_Info);
 }
+#endif
 
 namespace fxcodec {
 
@@ -477,6 +487,7 @@
 
 }  // namespace
 
+// static
 std::unique_ptr<ScanlineDecoder> JpegModule::CreateDecoder(
     pdfium::span<const uint8_t> src_span,
     int width,
@@ -492,6 +503,7 @@
   return std::move(pDecoder);
 }
 
+// static
 Optional<JpegModule::JpegImageInfo> JpegModule::LoadInfo(
     pdfium::span<const uint8_t> src_span) {
   JpegImageInfo info;
@@ -502,7 +514,16 @@
   return info;
 }
 
-std::unique_ptr<ProgressiveDecoderIface::Context> JpegModule::Start() {
+#ifdef PDF_ENABLE_XFA
+// static
+JpegModule::ProgressiveDecoder* JpegModule::ProgressiveDecoder::GetInstance() {
+  static pdfium::base::NoDestructor<JpegModule::ProgressiveDecoder> s;
+  return s.get();
+}
+
+// static
+std::unique_ptr<ProgressiveDecoderIface::Context>
+JpegModule::ProgressiveDecoder::Start() {
   // Use ordinary pointer until past the possibility of a longjump.
   auto* pContext = new CJpegContext();
   if (setjmp(pContext->m_JumpMark) == -1) {
@@ -516,31 +537,17 @@
   return pdfium::WrapUnique(pContext);
 }
 
-bool JpegModule::Input(Context* pContext,
-                       RetainPtr<CFX_CodecMemory> codec_memory,
-                       CFX_DIBAttribute*) {
-  pdfium::span<uint8_t> src_buf = codec_memory->GetSpan();
-  auto* ctx = static_cast<CJpegContext*>(pContext);
-  if (ctx->m_SkipSize) {
-    if (ctx->m_SkipSize > src_buf.size()) {
-      ctx->m_SrcMgr.bytes_in_buffer = 0;
-      ctx->m_SkipSize -= src_buf.size();
-      return true;
-    }
-    src_buf = src_buf.subspan(ctx->m_SkipSize);
-    ctx->m_SkipSize = 0;
-  }
-  ctx->m_SrcMgr.next_input_byte = src_buf.data();
-  ctx->m_SrcMgr.bytes_in_buffer = src_buf.size();
-  return true;
+// static
+jmp_buf& JpegModule::ProgressiveDecoder::GetJumpMark(Context* pContext) {
+  return static_cast<CJpegContext*>(pContext)->GetJumpMark();
 }
 
-#ifdef PDF_ENABLE_XFA
-int JpegModule::ReadHeader(Context* pContext,
-                           int* width,
-                           int* height,
-                           int* nComps,
-                           CFX_DIBAttribute* pAttribute) {
+// static
+int JpegModule::ProgressiveDecoder::ReadHeader(Context* pContext,
+                                               int* width,
+                                               int* height,
+                                               int* nComps,
+                                               CFX_DIBAttribute* pAttribute) {
   ASSERT(pAttribute);
 
   auto* ctx = static_cast<CJpegContext*>(pContext);
@@ -556,28 +563,51 @@
   JpegLoadAttribute(ctx->m_Info, pAttribute);
   return 0;
 }
-#endif  // PDF_ENABLE_XFA
 
-bool JpegModule::StartScanline(Context* pContext, int down_scale) {
+// static
+bool JpegModule::ProgressiveDecoder::StartScanline(Context* pContext,
+                                                   int down_scale) {
   auto* ctx = static_cast<CJpegContext*>(pContext);
   ctx->m_Info.scale_denom = static_cast<unsigned int>(down_scale);
   return !!jpeg_start_decompress(&ctx->m_Info);
 }
 
-bool JpegModule::ReadScanline(Context* pContext, unsigned char* dest_buf) {
+// static
+bool JpegModule::ProgressiveDecoder::ReadScanline(Context* pContext,
+                                                  unsigned char* dest_buf) {
   auto* ctx = static_cast<CJpegContext*>(pContext);
   unsigned int nlines = jpeg_read_scanlines(&ctx->m_Info, &dest_buf, 1);
   return nlines == 1;
 }
 
-FX_FILESIZE JpegModule::GetAvailInput(Context* pContext) const {
+JpegModule::ProgressiveDecoder::ProgressiveDecoder() = default;
+
+FX_FILESIZE JpegModule::ProgressiveDecoder::GetAvailInput(
+    Context* pContext) const {
   auto* ctx = static_cast<CJpegContext*>(pContext);
   return static_cast<FX_FILESIZE>(ctx->m_SrcMgr.bytes_in_buffer);
 }
 
-jmp_buf& JpegModule::GetJumpMark(Context* pContext) {
-  return static_cast<CJpegContext*>(pContext)->GetJumpMark();
+bool JpegModule::ProgressiveDecoder::Input(
+    Context* pContext,
+    RetainPtr<CFX_CodecMemory> codec_memory,
+    CFX_DIBAttribute*) {
+  pdfium::span<uint8_t> src_buf = codec_memory->GetSpan();
+  auto* ctx = static_cast<CJpegContext*>(pContext);
+  if (ctx->m_SkipSize) {
+    if (ctx->m_SkipSize > src_buf.size()) {
+      ctx->m_SrcMgr.bytes_in_buffer = 0;
+      ctx->m_SkipSize -= src_buf.size();
+      return true;
+    }
+    src_buf = src_buf.subspan(ctx->m_SkipSize);
+    ctx->m_SkipSize = 0;
+  }
+  ctx->m_SrcMgr.next_input_byte = src_buf.data();
+  ctx->m_SrcMgr.bytes_in_buffer = src_buf.size();
+  return true;
 }
+#endif  // PDF_ENABLE_XFA
 
 #if defined(OS_WIN)
 bool JpegModule::JpegEncode(const RetainPtr<CFX_DIBBase>& pSource,
diff --git a/core/fxcodec/jpeg/jpegmodule.h b/core/fxcodec/jpeg/jpegmodule.h
index 20a10cf..de970b3 100644
--- a/core/fxcodec/jpeg/jpegmodule.h
+++ b/core/fxcodec/jpeg/jpegmodule.h
@@ -7,14 +7,22 @@
 #ifndef CORE_FXCODEC_JPEG_JPEGMODULE_H_
 #define CORE_FXCODEC_JPEG_JPEGMODULE_H_
 
-#include <csetjmp>
 #include <memory>
 
 #include "build/build_config.h"
-#include "core/fxcodec/progressive_decoder_iface.h"
 #include "third_party/base/optional.h"
 #include "third_party/base/span.h"
 
+#if defined(OS_WIN)
+#include "core/fxcrt/retain_ptr.h"
+#endif
+
+#ifdef PDF_ENABLE_XFA
+#include <csetjmp>
+
+#include "core/fxcodec/progressive_decoder_iface.h"
+#endif
+
 class CFX_DIBBase;
 
 namespace fxcodec {
@@ -22,7 +30,7 @@
 class CFX_DIBAttribute;
 class ScanlineDecoder;
 
-class JpegModule final : public ProgressiveDecoderIface {
+class JpegModule {
  public:
   struct JpegImageInfo {
     int width;
@@ -32,40 +40,52 @@
     bool color_transform;
   };
 
-  std::unique_ptr<ScanlineDecoder> CreateDecoder(
+#ifdef PDF_ENABLE_XFA
+  class ProgressiveDecoder final : public ProgressiveDecoderIface {
+   public:
+    static ProgressiveDecoder* GetInstance();
+
+    static std::unique_ptr<Context> Start();
+
+    static jmp_buf& GetJumpMark(Context* pContext);
+
+    static int ReadHeader(Context* pContext,
+                          int* width,
+                          int* height,
+                          int* nComps,
+                          CFX_DIBAttribute* pAttribute);
+
+    static bool StartScanline(Context* pContext, int down_scale);
+    static bool ReadScanline(Context* pContext, uint8_t* dest_buf);
+
+    ProgressiveDecoder();
+
+    // ProgressiveDecoderIface:
+    FX_FILESIZE GetAvailInput(Context* pContext) const override;
+    bool Input(Context* pContext,
+               RetainPtr<CFX_CodecMemory> codec_memory,
+               CFX_DIBAttribute* pAttribute) override;
+  };
+#endif  // PDF_ENABLE_XFA
+
+  static std::unique_ptr<ScanlineDecoder> CreateDecoder(
       pdfium::span<const uint8_t> src_span,
       int width,
       int height,
       int nComps,
       bool ColorTransform);
 
-  // ProgressiveDecoderIface:
-  FX_FILESIZE GetAvailInput(Context* pContext) const override;
-  bool Input(Context* pContext,
-             RetainPtr<CFX_CodecMemory> codec_memory,
-             CFX_DIBAttribute* pAttribute) override;
-
-  jmp_buf& GetJumpMark(Context* pContext);
-  Optional<JpegImageInfo> LoadInfo(pdfium::span<const uint8_t> src_span);
-
-  std::unique_ptr<Context> Start();
-
-#ifdef PDF_ENABLE_XFA
-  int ReadHeader(Context* pContext,
-                 int* width,
-                 int* height,
-                 int* nComps,
-                 CFX_DIBAttribute* pAttribute);
-#endif  // PDF_ENABLE_XFA
-
-  bool StartScanline(Context* pContext, int down_scale);
-  bool ReadScanline(Context* pContext, uint8_t* dest_buf);
+  static Optional<JpegImageInfo> LoadInfo(pdfium::span<const uint8_t> src_span);
 
 #if defined(OS_WIN)
   static bool JpegEncode(const RetainPtr<CFX_DIBBase>& pSource,
                          uint8_t** dest_buf,
                          size_t* dest_size);
 #endif  // defined(OS_WIN)
+
+  JpegModule() = delete;
+  JpegModule(const JpegModule&) = delete;
+  JpegModule& operator=(const JpegModule&) = delete;
 };
 
 }  // namespace fxcodec
diff --git a/core/fxcodec/progressive_decoder_iface.h b/core/fxcodec/progressive_decoder_iface.h
index 111e95c..2ab902b 100644
--- a/core/fxcodec/progressive_decoder_iface.h
+++ b/core/fxcodec/progressive_decoder_iface.h
@@ -10,6 +10,10 @@
 #include "core/fxcrt/fx_system.h"
 #include "core/fxcrt/retain_ptr.h"
 
+#ifndef PDF_ENABLE_XFA
+#error "XFA Only"
+#endif
+
 class CFX_CodecMemory;
 
 namespace fxcodec {
diff --git a/core/fxcodec/progressivedecoder.cpp b/core/fxcodec/progressivedecoder.cpp
index de94ecd..5b890ad 100644
--- a/core/fxcodec/progressivedecoder.cpp
+++ b/core/fxcodec/progressivedecoder.cpp
@@ -974,41 +974,42 @@
 }
 #endif  // PDF_ENABLE_XFA_GIF
 
-bool ProgressiveDecoder::JpegReadMoreData(JpegModule* pJpegModule,
-                                          FXCODEC_STATUS* err_status) {
-  return ReadMoreData(pJpegModule, m_pJpegContext.get(), false, err_status);
+bool ProgressiveDecoder::JpegReadMoreData(FXCODEC_STATUS* err_status) {
+  return ReadMoreData(JpegModule::ProgressiveDecoder::GetInstance(),
+                      m_pJpegContext.get(), false, err_status);
 }
 
 bool ProgressiveDecoder::JpegDetectImageTypeInBuffer(
     CFX_DIBAttribute* pAttribute) {
-  JpegModule* pJpegModule = m_pCodecMgr->GetJpegModule();
-  m_pJpegContext = pJpegModule->Start();
+  m_pJpegContext = JpegModule::ProgressiveDecoder::Start();
   if (!m_pJpegContext) {
     m_status = FXCODEC_STATUS_ERR_MEMORY;
     return false;
   }
-  pJpegModule->Input(m_pJpegContext.get(), m_pCodecMemory, nullptr);
+  JpegModule::ProgressiveDecoder::GetInstance()->Input(m_pJpegContext.get(),
+                                                       m_pCodecMemory, nullptr);
 
   // Setting jump marker before calling ReadHeader, since a longjmp to
   // the marker indicates a fatal error.
-  if (setjmp(pJpegModule->GetJumpMark(m_pJpegContext.get())) == -1) {
+  if (setjmp(JpegModule::ProgressiveDecoder::GetJumpMark(
+          m_pJpegContext.get())) == -1) {
     m_pJpegContext.reset();
     m_status = FXCODEC_STATUS_ERR_FORMAT;
     return false;
   }
 
-  int32_t readResult =
-      pJpegModule->ReadHeader(m_pJpegContext.get(), &m_SrcWidth, &m_SrcHeight,
-                              &m_SrcComponents, pAttribute);
+  int32_t readResult = JpegModule::ProgressiveDecoder::ReadHeader(
+      m_pJpegContext.get(), &m_SrcWidth, &m_SrcHeight, &m_SrcComponents,
+      pAttribute);
   while (readResult == 2) {
     FXCODEC_STATUS error_status = FXCODEC_STATUS_ERR_FORMAT;
-    if (!JpegReadMoreData(pJpegModule, &error_status)) {
+    if (!JpegReadMoreData(&error_status)) {
       m_status = error_status;
       return false;
     }
-    readResult =
-        pJpegModule->ReadHeader(m_pJpegContext.get(), &m_SrcWidth, &m_SrcHeight,
-                                &m_SrcComponents, pAttribute);
+    readResult = JpegModule::ProgressiveDecoder::ReadHeader(
+        m_pJpegContext.get(), &m_SrcWidth, &m_SrcHeight, &m_SrcComponents,
+        pAttribute);
   }
   if (!readResult) {
     m_SrcBPC = 8;
@@ -1022,28 +1023,29 @@
 
 FXCODEC_STATUS ProgressiveDecoder::JpegStartDecode(
     const RetainPtr<CFX_DIBitmap>& pDIBitmap) {
-  JpegModule* pJpegModule = m_pCodecMgr->GetJpegModule();
   int down_scale = GetDownScale();
   // Setting jump marker before calling StartScanLine, since a longjmp to
   // the marker indicates a fatal error.
-  if (setjmp(pJpegModule->GetJumpMark(m_pJpegContext.get())) == -1) {
+  if (setjmp(JpegModule::ProgressiveDecoder::GetJumpMark(
+          m_pJpegContext.get())) == -1) {
     m_pJpegContext.reset();
     m_status = FXCODEC_STATUS_ERROR;
     return FXCODEC_STATUS_ERROR;
   }
 
-  bool startStatus =
-      pJpegModule->StartScanline(m_pJpegContext.get(), down_scale);
+  bool startStatus = JpegModule::ProgressiveDecoder::StartScanline(
+      m_pJpegContext.get(), down_scale);
   while (!startStatus) {
     FXCODEC_STATUS error_status = FXCODEC_STATUS_ERROR;
-    if (!JpegReadMoreData(pJpegModule, &error_status)) {
+    if (!JpegReadMoreData(&error_status)) {
       m_pDeviceBitmap = nullptr;
       m_pFile = nullptr;
       m_status = error_status;
       return m_status;
     }
 
-    startStatus = pJpegModule->StartScanline(m_pJpegContext.get(), down_scale);
+    startStatus = JpegModule::ProgressiveDecoder::StartScanline(
+        m_pJpegContext.get(), down_scale);
   }
   int scanline_size = (m_SrcWidth + down_scale - 1) / down_scale;
   scanline_size = FxAlignToBoundary<4>(scanline_size * m_SrcComponents);
@@ -1067,28 +1069,29 @@
 }
 
 FXCODEC_STATUS ProgressiveDecoder::JpegContinueDecode() {
-  JpegModule* pJpegModule = m_pCodecMgr->GetJpegModule();
+  // JpegModule* pJpegModule = m_pCodecMgr->GetJpegModule();
   // Setting jump marker before calling ReadScanLine, since a longjmp to
   // the marker indicates a fatal error.
-  if (setjmp(pJpegModule->GetJumpMark(m_pJpegContext.get())) == -1) {
+  if (setjmp(JpegModule::ProgressiveDecoder::GetJumpMark(
+          m_pJpegContext.get())) == -1) {
     m_pJpegContext.reset();
     m_status = FXCODEC_STATUS_ERROR;
     return FXCODEC_STATUS_ERROR;
   }
 
   while (true) {
-    bool readRes =
-        pJpegModule->ReadScanline(m_pJpegContext.get(), m_pDecodeBuf.get());
+    bool readRes = JpegModule::ProgressiveDecoder::ReadScanline(
+        m_pJpegContext.get(), m_pDecodeBuf.get());
     while (!readRes) {
       FXCODEC_STATUS error_status = FXCODEC_STATUS_DECODE_FINISH;
-      if (!JpegReadMoreData(pJpegModule, &error_status)) {
+      if (!JpegReadMoreData(&error_status)) {
         m_pDeviceBitmap = nullptr;
         m_pFile = nullptr;
         m_status = error_status;
         return m_status;
       }
-      readRes =
-          pJpegModule->ReadScanline(m_pJpegContext.get(), m_pDecodeBuf.get());
+      readRes = JpegModule::ProgressiveDecoder::ReadScanline(
+          m_pJpegContext.get(), m_pDecodeBuf.get());
     }
     if (m_SrcFormat == FXCodec_Rgb) {
       int src_Bpp = (m_SrcFormat & 0xff) >> 3;
diff --git a/core/fxcodec/progressivedecoder.h b/core/fxcodec/progressivedecoder.h
index 628bdbf..f3fe497 100644
--- a/core/fxcodec/progressivedecoder.h
+++ b/core/fxcodec/progressivedecoder.h
@@ -213,7 +213,7 @@
   FXCODEC_STATUS TiffContinueDecode();
 #endif  // PDF_ENABLE_XFA_TIFF
 
-  bool JpegReadMoreData(JpegModule* pJpegModule, FXCODEC_STATUS* err_status);
+  bool JpegReadMoreData(FXCODEC_STATUS* err_status);
   bool JpegDetectImageTypeInBuffer(CFX_DIBAttribute* pAttribute);
   FXCODEC_STATUS JpegStartDecode(const RetainPtr<CFX_DIBitmap>& pDIBitmap);
   FXCODEC_STATUS JpegContinueDecode();