Rename CCodec_JpegModule to fxcodec::JpegModule.

Also consolidate 'extern "C"' sections in jpegmodule.cpp.

BUG=pdfium:1311

Change-Id: If6ec0581381d90c72e772759bb290d511cb59f82
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/55830
Commit-Queue: Lei Zhang <thestig@chromium.org>
Reviewed-by: Tom Sepez <tsepez@chromium.org>
diff --git a/core/fpdfapi/page/cpdf_image.cpp b/core/fpdfapi/page/cpdf_image.cpp
index 322666f..156872b 100644
--- a/core/fpdfapi/page/cpdf_image.cpp
+++ b/core/fpdfapi/page/cpdf_image.cpp
@@ -24,7 +24,7 @@
 #include "core/fpdfapi/parser/cpdf_string.h"
 #include "core/fpdfapi/render/cpdf_dibbase.h"
 #include "core/fpdfapi/render/cpdf_pagerendercache.h"
-#include "core/fxcodec/codec/ccodec_jpegmodule.h"
+#include "core/fxcodec/codec/jpegmodule.h"
 #include "core/fxcodec/fx_codec.h"
 #include "core/fxcrt/fx_stream.h"
 #include "core/fxge/dib/cfx_dibitmap.h"
diff --git a/core/fpdfapi/page/cpdf_streamparser.cpp b/core/fpdfapi/page/cpdf_streamparser.cpp
index 7d790fb..c026115 100644
--- a/core/fpdfapi/page/cpdf_streamparser.cpp
+++ b/core/fpdfapi/page/cpdf_streamparser.cpp
@@ -26,8 +26,8 @@
 #include "core/fpdfapi/parser/cpdf_string.h"
 #include "core/fpdfapi/parser/fpdf_parser_decode.h"
 #include "core/fpdfapi/parser/fpdf_parser_utility.h"
-#include "core/fxcodec/codec/ccodec_jpegmodule.h"
 #include "core/fxcodec/codec/ccodec_scanlinedecoder.h"
+#include "core/fxcodec/codec/jpegmodule.h"
 #include "core/fxcodec/fx_codec.h"
 #include "core/fxcrt/fx_extension.h"
 #include "core/fxcrt/fx_safe_types.h"
diff --git a/core/fpdfapi/render/cpdf_dibbase.cpp b/core/fpdfapi/render/cpdf_dibbase.cpp
index 070a1fc..19614d0 100644
--- a/core/fpdfapi/render/cpdf_dibbase.cpp
+++ b/core/fpdfapi/render/cpdf_dibbase.cpp
@@ -25,9 +25,9 @@
 #include "core/fpdfapi/render/cpdf_renderstatus.h"
 #include "core/fxcodec/codec/ccodec_basicmodule.h"
 #include "core/fxcodec/codec/ccodec_jbig2module.h"
-#include "core/fxcodec/codec/ccodec_jpegmodule.h"
 #include "core/fxcodec/codec/ccodec_scanlinedecoder.h"
 #include "core/fxcodec/codec/cjpx_decoder.h"
+#include "core/fxcodec/codec/jpegmodule.h"
 #include "core/fxcodec/codec/jpxmodule.h"
 #include "core/fxcodec/fx_codec.h"
 #include "core/fxcrt/cfx_fixedbufgrow.h"
@@ -512,8 +512,7 @@
 
 bool CPDF_DIBBase::CreateDCTDecoder(pdfium::span<const uint8_t> src_span,
                                     const CPDF_Dictionary* pParams) {
-  CCodec_JpegModule* pJpegModule =
-      CCodec_ModuleMgr::GetInstance()->GetJpegModule();
+  JpegModule* pJpegModule = CCodec_ModuleMgr::GetInstance()->GetJpegModule();
   m_pDecoder = pJpegModule->CreateDecoder(
       src_span, m_Width, m_Height, m_nComponents,
       !pParams || pParams->GetIntegerFor("ColorTransform", 1));
diff --git a/core/fxcodec/BUILD.gn b/core/fxcodec/BUILD.gn
index 1c6b104..ccdbd3c 100644
--- a/core/fxcodec/BUILD.gn
+++ b/core/fxcodec/BUILD.gn
@@ -17,8 +17,6 @@
     "codec/ccodec_flatemodule.h",
     "codec/ccodec_jbig2module.cpp",
     "codec/ccodec_jbig2module.h",
-    "codec/ccodec_jpegmodule.cpp",
-    "codec/ccodec_jpegmodule.h",
     "codec/ccodec_scanlinedecoder.cpp",
     "codec/ccodec_scanlinedecoder.h",
     "codec/cfx_codec_memory.cpp",
@@ -30,6 +28,8 @@
     "codec/fx_codec.cpp",
     "codec/iccmodule.cpp",
     "codec/iccmodule.h",
+    "codec/jpegmodule.cpp",
+    "codec/jpegmodule.h",
     "codec/jpxmodule.cpp",
     "codec/jpxmodule.h",
     "fx_codec.h",
diff --git a/core/fxcodec/codec/ccodec_progressivedecoder.cpp b/core/fxcodec/codec/ccodec_progressivedecoder.cpp
index 01125bb..9413a95 100644
--- a/core/fxcodec/codec/ccodec_progressivedecoder.cpp
+++ b/core/fxcodec/codec/ccodec_progressivedecoder.cpp
@@ -1038,14 +1038,14 @@
 }
 #endif  // PDF_ENABLE_XFA_GIF
 
-bool CCodec_ProgressiveDecoder::JpegReadMoreData(CCodec_JpegModule* pJpegModule,
+bool CCodec_ProgressiveDecoder::JpegReadMoreData(JpegModule* pJpegModule,
                                                  FXCODEC_STATUS& err_status) {
   return ReadMoreData(pJpegModule, m_pJpegContext.get(), false, err_status);
 }
 
 bool CCodec_ProgressiveDecoder::JpegDetectImageTypeInBuffer(
     CFX_DIBAttribute* pAttribute) {
-  CCodec_JpegModule* pJpegModule = m_pCodecMgr->GetJpegModule();
+  JpegModule* pJpegModule = m_pCodecMgr->GetJpegModule();
   m_pJpegContext = pJpegModule->Start();
   if (!m_pJpegContext) {
     m_status = FXCODEC_STATUS_ERR_MEMORY;
@@ -1086,7 +1086,7 @@
 
 FXCODEC_STATUS CCodec_ProgressiveDecoder::JpegStartDecode(
     const RetainPtr<CFX_DIBitmap>& pDIBitmap) {
-  CCodec_JpegModule* pJpegModule = m_pCodecMgr->GetJpegModule();
+  JpegModule* pJpegModule = m_pCodecMgr->GetJpegModule();
   int down_scale = 1;
   GetDownScale(down_scale);
   // Setting jump marker before calling StartScanLine, since a longjmp to
@@ -1133,7 +1133,7 @@
 }
 
 FXCODEC_STATUS CCodec_ProgressiveDecoder::JpegContinueDecode() {
-  CCodec_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) {
diff --git a/core/fxcodec/codec/ccodec_progressivedecoder.h b/core/fxcodec/codec/ccodec_progressivedecoder.h
index f148f4a..64c9103 100644
--- a/core/fxcodec/codec/ccodec_progressivedecoder.h
+++ b/core/fxcodec/codec/ccodec_progressivedecoder.h
@@ -11,7 +11,7 @@
 #include <utility>
 #include <vector>
 
-#include "core/fxcodec/codec/ccodec_jpegmodule.h"
+#include "core/fxcodec/codec/jpegmodule.h"
 #include "core/fxcodec/fx_codec_def.h"
 #include "core/fxcrt/fx_system.h"
 #include "core/fxcrt/retain_ptr.h"
@@ -214,8 +214,7 @@
   FXCODEC_STATUS TiffContinueDecode();
 #endif  // PDF_ENABLE_XFA_TIFF
 
-  bool JpegReadMoreData(CCodec_JpegModule* pJpegModule,
-                        FXCODEC_STATUS& err_status);
+  bool JpegReadMoreData(JpegModule* pJpegModule, FXCODEC_STATUS& err_status);
   bool JpegDetectImageTypeInBuffer(CFX_DIBAttribute* pAttribute);
   FXCODEC_STATUS JpegStartDecode(const RetainPtr<CFX_DIBitmap>& pDIBitmap);
   FXCODEC_STATUS JpegContinueDecode();
diff --git a/core/fxcodec/codec/fx_codec.cpp b/core/fxcodec/codec/fx_codec.cpp
index 0284cb5..0f6a944 100644
--- a/core/fxcodec/codec/fx_codec.cpp
+++ b/core/fxcodec/codec/fx_codec.cpp
@@ -12,8 +12,8 @@
 #include <utility>
 
 #include "core/fxcodec/codec/ccodec_jbig2module.h"
-#include "core/fxcodec/codec/ccodec_jpegmodule.h"
 #include "core/fxcodec/codec/codec_int.h"
+#include "core/fxcodec/codec/jpegmodule.h"
 #include "core/fxcrt/fx_extension.h"
 #include "core/fxcrt/fx_safe_types.h"
 #include "third_party/base/logging.h"
@@ -45,7 +45,7 @@
 }
 
 CCodec_ModuleMgr::CCodec_ModuleMgr()
-    : m_pJpegModule(pdfium::MakeUnique<CCodec_JpegModule>()),
+    : m_pJpegModule(pdfium::MakeUnique<JpegModule>()),
       m_pJbig2Module(pdfium::MakeUnique<CCodec_Jbig2Module>()) {
 #ifdef PDF_ENABLE_XFA_BMP
   SetBmpModule(pdfium::MakeUnique<BmpModule>());
diff --git a/core/fxcodec/codec/ccodec_jpegmodule.cpp b/core/fxcodec/codec/jpegmodule.cpp
similarity index 87%
rename from core/fxcodec/codec/ccodec_jpegmodule.cpp
rename to core/fxcodec/codec/jpegmodule.cpp
index 0310c95..03b1e96 100644
--- a/core/fxcodec/codec/ccodec_jpegmodule.cpp
+++ b/core/fxcodec/codec/jpegmodule.cpp
@@ -4,7 +4,7 @@
 
 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
 
-#include "core/fxcodec/codec/ccodec_jpegmodule.h"
+#include "core/fxcodec/codec/jpegmodule.h"
 
 #include <setjmp.h>
 
@@ -100,6 +100,31 @@
   return false;
 }
 #endif  // defined(OS_WIN)
+
+static void error_fatal1(j_common_ptr cinfo) {
+  auto* pContext = reinterpret_cast<CJpegContext*>(cinfo->client_data);
+  longjmp(pContext->m_JumpMark, -1);
+}
+
+static void src_skip_data1(jpeg_decompress_struct* cinfo, long num) {
+  if (cinfo->src->bytes_in_buffer < static_cast<size_t>(num)) {
+    auto* pContext = reinterpret_cast<CJpegContext*>(cinfo->client_data);
+    pContext->m_SkipSize = (unsigned int)(num - cinfo->src->bytes_in_buffer);
+    cinfo->src->bytes_in_buffer = 0;
+  } else {
+    cinfo->src->next_input_byte += num;
+    cinfo->src->bytes_in_buffer -= num;
+  }
+}
+
+static void* jpeg_alloc_func(unsigned int size) {
+  return FX_Alloc(char, size);
+}
+
+static void jpeg_free_func(void* p) {
+  FX_Free(p);
+}
+
 }  // extern "C"
 
 #ifdef PDF_ENABLE_XFA
@@ -161,10 +186,39 @@
   return true;
 }
 
-class CCodec_JpegDecoder final : public CCodec_ScanlineDecoder {
+CJpegContext::CJpegContext()
+    : m_SkipSize(0), m_AllocFunc(jpeg_alloc_func), m_FreeFunc(jpeg_free_func) {
+  memset(&m_Info, 0, sizeof(m_Info));
+  m_Info.client_data = this;
+  m_Info.err = &m_ErrMgr;
+
+  memset(&m_ErrMgr, 0, sizeof(m_ErrMgr));
+  m_ErrMgr.error_exit = error_fatal1;
+  m_ErrMgr.emit_message = error_do_nothing1;
+  m_ErrMgr.output_message = error_do_nothing;
+  m_ErrMgr.format_message = error_do_nothing2;
+  m_ErrMgr.reset_error_mgr = error_do_nothing;
+
+  memset(&m_SrcMgr, 0, sizeof(m_SrcMgr));
+  m_SrcMgr.init_source = src_do_nothing;
+  m_SrcMgr.term_source = src_do_nothing;
+  m_SrcMgr.skip_input_data = src_skip_data1;
+  m_SrcMgr.fill_input_buffer = src_fill_buffer;
+  m_SrcMgr.resync_to_restart = src_resync;
+}
+
+CJpegContext::~CJpegContext() {
+  jpeg_destroy_decompress(&m_Info);
+}
+
+namespace fxcodec {
+
+namespace {
+
+class JpegDecoder final : public CCodec_ScanlineDecoder {
  public:
-  CCodec_JpegDecoder();
-  ~CCodec_JpegDecoder() override;
+  JpegDecoder();
+  ~JpegDecoder() override;
 
   bool Create(pdfium::span<const uint8_t> src_buf,
               int width,
@@ -209,18 +263,18 @@
   uint32_t m_nDefaultScaleDenom = 1;
 };
 
-CCodec_JpegDecoder::CCodec_JpegDecoder() {
+JpegDecoder::JpegDecoder() {
   memset(&m_Cinfo, 0, sizeof(m_Cinfo));
   memset(&m_Jerr, 0, sizeof(m_Jerr));
   memset(&m_Src, 0, sizeof(m_Src));
 }
 
-CCodec_JpegDecoder::~CCodec_JpegDecoder() {
+JpegDecoder::~JpegDecoder() {
   if (m_bInited)
     jpeg_destroy_decompress(&m_Cinfo);
 }
 
-bool CCodec_JpegDecoder::InitDecode(bool bAcceptKnownBadHeader) {
+bool JpegDecoder::InitDecode(bool bAcceptKnownBadHeader) {
   m_Cinfo.err = &m_Jerr;
   m_Cinfo.client_data = &m_JmpBuf;
   if (setjmp(m_JmpBuf) == -1)
@@ -264,11 +318,11 @@
   return true;
 }
 
-bool CCodec_JpegDecoder::Create(pdfium::span<const uint8_t> src_span,
-                                int width,
-                                int height,
-                                int nComps,
-                                bool ColorTransform) {
+bool JpegDecoder::Create(pdfium::span<const uint8_t> src_span,
+                         int width,
+                         int height,
+                         int nComps,
+                         bool ColorTransform) {
   m_SrcSpan = JpegScanSOI(src_span);
   if (m_SrcSpan.size() < 2)
     return false;
@@ -305,7 +359,7 @@
   return true;
 }
 
-bool CCodec_JpegDecoder::v_Rewind() {
+bool JpegDecoder::v_Rewind() {
   if (m_bStarted) {
     jpeg_destroy_decompress(&m_Cinfo);
     if (!InitDecode(/*bAcceptKnownBadHeader=*/false)) {
@@ -330,7 +384,7 @@
   return true;
 }
 
-uint8_t* CCodec_JpegDecoder::v_GetNextLine() {
+uint8_t* JpegDecoder::v_GetNextLine() {
   if (setjmp(m_JmpBuf) == -1)
     return nullptr;
 
@@ -339,24 +393,24 @@
   return nlines > 0 ? m_pScanlineBuf.get() : nullptr;
 }
 
-uint32_t CCodec_JpegDecoder::GetSrcOffset() {
+uint32_t JpegDecoder::GetSrcOffset() {
   return static_cast<uint32_t>(m_SrcSpan.size() - m_Src.bytes_in_buffer);
 }
 
-void CCodec_JpegDecoder::CalcPitch() {
+void JpegDecoder::CalcPitch() {
   m_Pitch = static_cast<uint32_t>(m_Cinfo.image_width) * m_Cinfo.num_components;
   m_Pitch += 3;
   m_Pitch /= 4;
   m_Pitch *= 4;
 }
 
-void CCodec_JpegDecoder::InitDecompressSrc() {
+void JpegDecoder::InitDecompressSrc() {
   m_Cinfo.src = &m_Src;
   m_Src.bytes_in_buffer = m_SrcSpan.size();
   m_Src.next_input_byte = m_SrcSpan.data();
 }
 
-bool CCodec_JpegDecoder::HasKnownBadHeaderWithInvalidHeight() const {
+bool JpegDecoder::HasKnownBadHeaderWithInvalidHeight() const {
   // Perform lots of possibly redundant checks to make sure this has no false
   // positives.
   bool bDimensionChecks = m_Cinfo.err->msg_code == JERR_IMAGE_TOO_BIG &&
@@ -381,7 +435,7 @@
          pHeaderDimensions[3] == nExpectedWidthByte2;
 }
 
-void CCodec_JpegDecoder::PatchUpKnownBadHeaderWithInvalidHeight() {
+void JpegDecoder::PatchUpKnownBadHeaderWithInvalidHeight() {
   ASSERT(m_SrcSpan.size() >
          kKnownBadHeaderWithInvalidHeightByteOffsetStart + 1);
   uint8_t* pData =
@@ -390,17 +444,19 @@
   pData[1] = m_OrigHeight & 0xff;
 }
 
-void CCodec_JpegDecoder::PatchUpTrailer() {
+void JpegDecoder::PatchUpTrailer() {
   uint8_t* pData = GetWritableSrcData();
   pData[m_SrcSpan.size() - 2] = 0xff;
   pData[m_SrcSpan.size() - 1] = 0xd9;
 }
 
-uint8_t* CCodec_JpegDecoder::GetWritableSrcData() {
+uint8_t* JpegDecoder::GetWritableSrcData() {
   return const_cast<uint8_t*>(m_SrcSpan.data());
 }
 
-std::unique_ptr<CCodec_ScanlineDecoder> CCodec_JpegModule::CreateDecoder(
+}  // namespace
+
+std::unique_ptr<CCodec_ScanlineDecoder> JpegModule::CreateDecoder(
     pdfium::span<const uint8_t> src_span,
     int width,
     int height,
@@ -408,77 +464,24 @@
     bool ColorTransform) {
   ASSERT(!src_span.empty());
 
-  auto pDecoder = pdfium::MakeUnique<CCodec_JpegDecoder>();
+  auto pDecoder = pdfium::MakeUnique<JpegDecoder>();
   if (!pDecoder->Create(src_span, width, height, nComps, ColorTransform))
     return nullptr;
 
   return std::move(pDecoder);
 }
 
-bool CCodec_JpegModule::LoadInfo(pdfium::span<const uint8_t> src_span,
-                                 int* width,
-                                 int* height,
-                                 int* num_components,
-                                 int* bits_per_components,
-                                 bool* color_transform) {
+bool JpegModule::LoadInfo(pdfium::span<const uint8_t> src_span,
+                          int* width,
+                          int* height,
+                          int* num_components,
+                          int* bits_per_components,
+                          bool* color_transform) {
   return JpegLoadInfo(src_span, width, height, num_components,
                       bits_per_components, color_transform);
 }
 
-extern "C" {
-
-static void error_fatal1(j_common_ptr cinfo) {
-  auto* pContext = reinterpret_cast<CJpegContext*>(cinfo->client_data);
-  longjmp(pContext->m_JumpMark, -1);
-}
-
-static void src_skip_data1(jpeg_decompress_struct* cinfo, long num) {
-  if (cinfo->src->bytes_in_buffer < static_cast<size_t>(num)) {
-    auto* pContext = reinterpret_cast<CJpegContext*>(cinfo->client_data);
-    pContext->m_SkipSize = (unsigned int)(num - cinfo->src->bytes_in_buffer);
-    cinfo->src->bytes_in_buffer = 0;
-  } else {
-    cinfo->src->next_input_byte += num;
-    cinfo->src->bytes_in_buffer -= num;
-  }
-}
-
-static void* jpeg_alloc_func(unsigned int size) {
-  return FX_Alloc(char, size);
-}
-
-static void jpeg_free_func(void* p) {
-  FX_Free(p);
-}
-
-}  // extern "C"
-
-CJpegContext::CJpegContext()
-    : m_SkipSize(0), m_AllocFunc(jpeg_alloc_func), m_FreeFunc(jpeg_free_func) {
-  memset(&m_Info, 0, sizeof(m_Info));
-  m_Info.client_data = this;
-  m_Info.err = &m_ErrMgr;
-
-  memset(&m_ErrMgr, 0, sizeof(m_ErrMgr));
-  m_ErrMgr.error_exit = error_fatal1;
-  m_ErrMgr.emit_message = error_do_nothing1;
-  m_ErrMgr.output_message = error_do_nothing;
-  m_ErrMgr.format_message = error_do_nothing2;
-  m_ErrMgr.reset_error_mgr = error_do_nothing;
-
-  memset(&m_SrcMgr, 0, sizeof(m_SrcMgr));
-  m_SrcMgr.init_source = src_do_nothing;
-  m_SrcMgr.term_source = src_do_nothing;
-  m_SrcMgr.skip_input_data = src_skip_data1;
-  m_SrcMgr.fill_input_buffer = src_fill_buffer;
-  m_SrcMgr.resync_to_restart = src_resync;
-}
-
-CJpegContext::~CJpegContext() {
-  jpeg_destroy_decompress(&m_Info);
-}
-
-std::unique_ptr<CodecModuleIface::Context> CCodec_JpegModule::Start() {
+std::unique_ptr<CodecModuleIface::Context> JpegModule::Start() {
   // Use ordinary pointer until past the possibility of a longjump.
   auto* pContext = new CJpegContext();
   if (setjmp(pContext->m_JumpMark) == -1) {
@@ -492,9 +495,9 @@
   return pdfium::WrapUnique(pContext);
 }
 
-bool CCodec_JpegModule::Input(Context* pContext,
-                              RetainPtr<CFX_CodecMemory> codec_memory,
-                              CFX_DIBAttribute*) {
+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) {
@@ -512,11 +515,11 @@
 }
 
 #ifdef PDF_ENABLE_XFA
-int CCodec_JpegModule::ReadHeader(Context* pContext,
-                                  int* width,
-                                  int* height,
-                                  int* nComps,
-                                  CFX_DIBAttribute* pAttribute) {
+int JpegModule::ReadHeader(Context* pContext,
+                           int* width,
+                           int* height,
+                           int* nComps,
+                           CFX_DIBAttribute* pAttribute) {
   ASSERT(pAttribute);
 
   auto* ctx = static_cast<CJpegContext*>(pContext);
@@ -534,32 +537,31 @@
 }
 #endif  // PDF_ENABLE_XFA
 
-bool CCodec_JpegModule::StartScanline(Context* pContext, int down_scale) {
+bool JpegModule::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 CCodec_JpegModule::ReadScanline(Context* pContext,
-                                     unsigned char* dest_buf) {
+bool JpegModule::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 CCodec_JpegModule::GetAvailInput(Context* pContext) const {
+FX_FILESIZE JpegModule::GetAvailInput(Context* pContext) const {
   auto* ctx = static_cast<CJpegContext*>(pContext);
   return static_cast<FX_FILESIZE>(ctx->m_SrcMgr.bytes_in_buffer);
 }
 
-jmp_buf* CCodec_JpegModule::GetJumpMark(Context* pContext) {
+jmp_buf* JpegModule::GetJumpMark(Context* pContext) {
   return static_cast<CJpegContext*>(pContext)->GetJumpMark();
 }
 
 #if defined(OS_WIN)
-bool CCodec_JpegModule::JpegEncode(const RetainPtr<CFX_DIBBase>& pSource,
-                                   uint8_t** dest_buf,
-                                   size_t* dest_size) {
+bool JpegModule::JpegEncode(const RetainPtr<CFX_DIBBase>& pSource,
+                            uint8_t** dest_buf,
+                            size_t* dest_size) {
   jpeg_error_mgr jerr;
   jerr.error_exit = error_do_nothing;
   jerr.emit_message = error_do_nothing1;
@@ -658,3 +660,5 @@
   return true;
 }
 #endif  // defined(OS_WIN)
+
+}  // namespace fxcodec
diff --git a/core/fxcodec/codec/ccodec_jpegmodule.h b/core/fxcodec/codec/jpegmodule.h
similarity index 86%
rename from core/fxcodec/codec/ccodec_jpegmodule.h
rename to core/fxcodec/codec/jpegmodule.h
index e0286fc..1f3436c 100644
--- a/core/fxcodec/codec/ccodec_jpegmodule.h
+++ b/core/fxcodec/codec/jpegmodule.h
@@ -4,8 +4,8 @@
 
 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
 
-#ifndef CORE_FXCODEC_CODEC_CCODEC_JPEGMODULE_H_
-#define CORE_FXCODEC_CODEC_CCODEC_JPEGMODULE_H_
+#ifndef CORE_FXCODEC_CODEC_JPEGMODULE_H_
+#define CORE_FXCODEC_CODEC_JPEGMODULE_H_
 
 #include <csetjmp>
 #include <memory>
@@ -18,7 +18,9 @@
 class CFX_DIBAttribute;
 class CFX_DIBBase;
 
-class CCodec_JpegModule final : public CodecModuleIface {
+namespace fxcodec {
+
+class JpegModule final : public CodecModuleIface {
  public:
   std::unique_ptr<CCodec_ScanlineDecoder> CreateDecoder(
       pdfium::span<const uint8_t> src_buf,
@@ -61,4 +63,8 @@
 #endif  // defined(OS_WIN)
 };
 
-#endif  // CORE_FXCODEC_CODEC_CCODEC_JPEGMODULE_H_
+}  // namespace fxcodec
+
+using JpegModule = fxcodec::JpegModule;
+
+#endif  // CORE_FXCODEC_CODEC_JPEGMODULE_H_
diff --git a/core/fxcodec/fx_codec.h b/core/fxcodec/fx_codec.h
index 3fc46aa..60a7b91 100644
--- a/core/fxcodec/fx_codec.h
+++ b/core/fxcodec/fx_codec.h
@@ -35,7 +35,6 @@
 #endif  // PDF_ENABLE_XFA
 
 class CCodec_Jbig2Module;
-class CCodec_JpegModule;
 
 #ifdef PDF_ENABLE_XFA
 class CCodec_ProgressiveDecoder;
@@ -52,6 +51,10 @@
 };
 #endif  // PDF_ENABLE_XFA
 
+namespace fxcodec {
+class JpegModule;
+}
+
 class CCodec_ModuleMgr {
  public:
   // Per-process singleton managed by callers.
@@ -59,7 +62,7 @@
   static void Destroy();
   static CCodec_ModuleMgr* GetInstance();
 
-  CCodec_JpegModule* GetJpegModule() const { return m_pJpegModule.get(); }
+  fxcodec::JpegModule* GetJpegModule() const { return m_pJpegModule.get(); }
   CCodec_Jbig2Module* GetJbig2Module() const { return m_pJbig2Module.get(); }
 
 #ifdef PDF_ENABLE_XFA
@@ -98,7 +101,7 @@
   CCodec_ModuleMgr();
   ~CCodec_ModuleMgr();
 
-  std::unique_ptr<CCodec_JpegModule> m_pJpegModule;
+  std::unique_ptr<fxcodec::JpegModule> m_pJpegModule;
   std::unique_ptr<CCodec_Jbig2Module> m_pJbig2Module;
 
 #ifdef PDF_ENABLE_XFA
diff --git a/fpdfsdk/fpdf_view.cpp b/fpdfsdk/fpdf_view.cpp
index 76a590e..fe5cbb7 100644
--- a/fpdfsdk/fpdf_view.cpp
+++ b/fpdfsdk/fpdf_view.cpp
@@ -56,7 +56,7 @@
 #include "core/fxcodec/codec/ccodec_basicmodule.h"
 #include "core/fxcodec/codec/ccodec_faxmodule.h"
 #include "core/fxcodec/codec/ccodec_flatemodule.h"
-#include "core/fxcodec/codec/ccodec_jpegmodule.h"
+#include "core/fxcodec/codec/jpegmodule.h"
 #include "core/fxge/cfx_windowsrenderdevice.h"
 #include "core/fxge/win32/cfx_psrenderer.h"
 #include "public/fpdf_edit.h"
@@ -85,7 +85,7 @@
 #if defined(OS_WIN)
 constexpr EncoderIface kEncoderIface = {
     CCodec_BasicModule::A85Encode, CCodec_FaxModule::FaxEncode,
-    CCodec_FlateModule::Encode, CCodec_JpegModule::JpegEncode,
+    CCodec_FlateModule::Encode, JpegModule::JpegEncode,
     CCodec_BasicModule::RunLengthEncode};
 #endif  // defined(OS_WIN)