Rename CCodec_FaxModule to fxcodec::FaxModule.

BUG=pdfium:1311

Change-Id: Ia305dd3288f4d4a96765df7842679860918d2185
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/55833
Commit-Queue: Lei Zhang <thestig@chromium.org>
Reviewed-by: Tom Sepez <tsepez@chromium.org>
diff --git a/core/fpdfapi/parser/fpdf_parser_decode.cpp b/core/fpdfapi/parser/fpdf_parser_decode.cpp
index 57ae853..5e2085d 100644
--- a/core/fpdfapi/parser/fpdf_parser_decode.cpp
+++ b/core/fpdfapi/parser/fpdf_parser_decode.cpp
@@ -17,8 +17,8 @@
 #include "core/fpdfapi/parser/cpdf_array.h"
 #include "core/fpdfapi/parser/cpdf_dictionary.h"
 #include "core/fpdfapi/parser/fpdf_parser_utility.h"
-#include "core/fxcodec/codec/ccodec_faxmodule.h"
 #include "core/fxcodec/codec/ccodec_scanlinedecoder.h"
+#include "core/fxcodec/codec/faxmodule.h"
 #include "core/fxcodec/codec/flatemodule.h"
 #include "core/fxcodec/fx_codec.h"
 #include "core/fxcrt/fx_extension.h"
@@ -312,8 +312,8 @@
     if (Rows > USHRT_MAX)
       Rows = 0;
   }
-  return CCodec_FaxModule::CreateDecoder(src_span, width, height, K, EndOfLine,
-                                         ByteAlign, BlackIs1, Columns, Rows);
+  return FaxModule::CreateDecoder(src_span, width, height, K, EndOfLine,
+                                  ByteAlign, BlackIs1, Columns, Rows);
 }
 
 std::unique_ptr<CCodec_ScanlineDecoder> CreateFlateDecoder(
diff --git a/core/fxcodec/BUILD.gn b/core/fxcodec/BUILD.gn
index dc3201a..e4a550b 100644
--- a/core/fxcodec/BUILD.gn
+++ b/core/fxcodec/BUILD.gn
@@ -12,8 +12,6 @@
     "JBig2_DocumentContext.h",
     "codec/ccodec_basicmodule.cpp",
     "codec/ccodec_basicmodule.h",
-    "codec/ccodec_faxmodule.cpp",
-    "codec/ccodec_faxmodule.h",
     "codec/ccodec_scanlinedecoder.cpp",
     "codec/ccodec_scanlinedecoder.h",
     "codec/cfx_codec_memory.cpp",
@@ -22,6 +20,8 @@
     "codec/cjpx_decoder.h",
     "codec/codec_int.h",
     "codec/codec_module_iface.h",
+    "codec/faxmodule.cpp",
+    "codec/faxmodule.h",
     "codec/flatemodule.cpp",
     "codec/flatemodule.h",
     "codec/fx_codec.cpp",
diff --git a/core/fxcodec/codec/ccodec_faxmodule.cpp b/core/fxcodec/codec/faxmodule.cpp
similarity index 90%
rename from core/fxcodec/codec/ccodec_faxmodule.cpp
rename to core/fxcodec/codec/faxmodule.cpp
index 4079366..506970d 100644
--- a/core/fxcodec/codec/ccodec_faxmodule.cpp
+++ b/core/fxcodec/codec/faxmodule.cpp
@@ -4,7 +4,7 @@
 
 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
 
-#include "core/fxcodec/codec/ccodec_faxmodule.h"
+#include "core/fxcodec/codec/faxmodule.h"
 
 #include <algorithm>
 #include <iterator>
@@ -21,6 +21,8 @@
 #include "third_party/base/ptr_util.h"
 #include "third_party/base/stl_util.h"
 
+namespace fxcodec {
+
 namespace {
 
 const uint8_t OneLeadPos[256] = {
@@ -453,16 +455,16 @@
   }
 }
 
-class CCodec_FaxDecoder final : public CCodec_ScanlineDecoder {
+class FaxDecoder final : public CCodec_ScanlineDecoder {
  public:
-  CCodec_FaxDecoder(pdfium::span<const uint8_t> src_span,
-                    int width,
-                    int height,
-                    int K,
-                    bool EndOfLine,
-                    bool EncodedByteAlign,
-                    bool BlackIs1);
-  ~CCodec_FaxDecoder() override;
+  FaxDecoder(pdfium::span<const uint8_t> src_span,
+             int width,
+             int height,
+             int K,
+             bool EndOfLine,
+             bool EncodedByteAlign,
+             bool BlackIs1);
+  ~FaxDecoder() override;
 
   // CCodec_ScanlineDecoder
   bool v_Rewind() override;
@@ -482,13 +484,13 @@
   std::vector<uint8_t> m_RefBuf;
 };
 
-CCodec_FaxDecoder::CCodec_FaxDecoder(pdfium::span<const uint8_t> src_span,
-                                     int width,
-                                     int height,
-                                     int K,
-                                     bool EndOfLine,
-                                     bool EncodedByteAlign,
-                                     bool BlackIs1)
+FaxDecoder::FaxDecoder(pdfium::span<const uint8_t> src_span,
+                       int width,
+                       int height,
+                       int K,
+                       bool EndOfLine,
+                       bool EncodedByteAlign,
+                       bool BlackIs1)
     : CCodec_ScanlineDecoder(width,
                              height,
                              width,
@@ -504,15 +506,15 @@
       m_ScanlineBuf(m_Pitch),
       m_RefBuf(m_Pitch) {}
 
-CCodec_FaxDecoder::~CCodec_FaxDecoder() = default;
+FaxDecoder::~FaxDecoder() = default;
 
-bool CCodec_FaxDecoder::v_Rewind() {
+bool FaxDecoder::v_Rewind() {
   memset(m_RefBuf.data(), 0xff, m_RefBuf.size());
   m_bitpos = 0;
   return true;
 }
 
-uint8_t* CCodec_FaxDecoder::v_GetNextLine() {
+uint8_t* FaxDecoder::v_GetNextLine() {
   int bitsize = m_SrcSpan.size() * 8;
   FaxSkipEOL(m_SrcSpan.data(), bitsize, &m_bitpos);
   if (m_bitpos >= bitsize)
@@ -557,11 +559,11 @@
   return m_ScanlineBuf.data();
 }
 
-uint32_t CCodec_FaxDecoder::GetSrcOffset() {
+uint32_t FaxDecoder::GetSrcOffset() {
   return std::min(static_cast<size_t>((m_bitpos + 7) / 8), m_SrcSpan.size());
 }
 
-void CCodec_FaxDecoder::InvertBuffer() {
+void FaxDecoder::InvertBuffer() {
   ASSERT(m_Pitch == m_ScanlineBuf.size());
   ASSERT(m_Pitch % 4 == 0);
   uint32_t* data = reinterpret_cast<uint32_t*>(m_ScanlineBuf.data());
@@ -572,7 +574,7 @@
 }  // namespace
 
 // static
-std::unique_ptr<CCodec_ScanlineDecoder> CCodec_FaxModule::CreateDecoder(
+std::unique_ptr<CCodec_ScanlineDecoder> FaxModule::CreateDecoder(
     pdfium::span<const uint8_t> src_span,
     int width,
     int height,
@@ -593,19 +595,19 @@
   if (actual_width > kMaxImageDimension || actual_height > kMaxImageDimension)
     return nullptr;
 
-  return pdfium::MakeUnique<CCodec_FaxDecoder>(src_span, actual_width,
-                                               actual_height, K, EndOfLine,
-                                               EncodedByteAlign, BlackIs1);
+  return pdfium::MakeUnique<FaxDecoder>(src_span, actual_width, actual_height,
+                                        K, EndOfLine, EncodedByteAlign,
+                                        BlackIs1);
 }
 
 // static
-int CCodec_FaxModule::FaxG4Decode(const uint8_t* src_buf,
-                                  uint32_t src_size,
-                                  int starting_bitpos,
-                                  int width,
-                                  int height,
-                                  int pitch,
-                                  uint8_t* dest_buf) {
+int FaxModule::FaxG4Decode(const uint8_t* src_buf,
+                           uint32_t src_size,
+                           int starting_bitpos,
+                           int width,
+                           int height,
+                           int pitch,
+                           uint8_t* dest_buf) {
   ASSERT(pitch != 0);
 
   std::vector<uint8_t> ref_buf(pitch, 0xff);
@@ -663,10 +665,10 @@
     0x17, 12, 0x1c, 12, 0x1d, 12, 0x1e, 12, 0x1f, 12,
 };
 
-class CCodec_FaxEncoder {
+class FaxEncoder {
  public:
-  CCodec_FaxEncoder(const uint8_t* src_buf, int width, int height, int pitch);
-  ~CCodec_FaxEncoder();
+  FaxEncoder(const uint8_t* src_buf, int width, int height, int pitch);
+  ~FaxEncoder();
   void Encode(std::unique_ptr<uint8_t, FxFreeDeleter>* dest_buf,
               uint32_t* dest_size);
 
@@ -685,10 +687,7 @@
   const uint8_t* m_pSrcBuf;
 };
 
-CCodec_FaxEncoder::CCodec_FaxEncoder(const uint8_t* src_buf,
-                                     int width,
-                                     int height,
-                                     int pitch)
+FaxEncoder::FaxEncoder(const uint8_t* src_buf, int width, int height, int pitch)
     : m_Cols(width), m_Rows(height), m_Pitch(pitch), m_pSrcBuf(src_buf) {
   m_RefLine.resize(pitch);
   std::fill(std::begin(m_RefLine), std::end(m_RefLine), 0xff);
@@ -696,16 +695,16 @@
   m_DestBuf.SetAllocStep(10240);
 }
 
-CCodec_FaxEncoder::~CCodec_FaxEncoder() = default;
+FaxEncoder::~FaxEncoder() = default;
 
-void CCodec_FaxEncoder::AddBitStream(int data, int bitlen) {
+void FaxEncoder::AddBitStream(int data, int bitlen) {
   for (int i = bitlen - 1; i >= 0; --i, ++m_DestBitpos) {
     if (data & (1 << i))
       m_LineBuf[m_DestBitpos / 8] |= 1 << (7 - m_DestBitpos % 8);
   }
 }
 
-void CCodec_FaxEncoder::FaxEncodeRun(int run, bool bWhite) {
+void FaxEncoder::FaxEncodeRun(int run, bool bWhite) {
   while (run >= 2560) {
     AddBitStream(0x1f, 12);
     run -= 2560;
@@ -722,7 +721,7 @@
   AddBitStream(*p, p[1]);
 }
 
-void CCodec_FaxEncoder::FaxEncode2DLine(const uint8_t* src_buf) {
+void FaxEncoder::FaxEncode2DLine(const uint8_t* src_buf) {
   int a0 = -1;
   bool a0color = true;
   while (1) {
@@ -777,9 +776,8 @@
   }
 }
 
-void CCodec_FaxEncoder::Encode(
-    std::unique_ptr<uint8_t, FxFreeDeleter>* dest_buf,
-    uint32_t* dest_size) {
+void FaxEncoder::Encode(std::unique_ptr<uint8_t, FxFreeDeleter>* dest_buf,
+                        uint32_t* dest_size) {
   m_DestBitpos = 0;
   uint8_t last_byte = 0;
   for (int i = 0; i < m_Rows; ++i) {
@@ -801,15 +799,16 @@
 }  // namespace
 
 // static
-void CCodec_FaxModule::FaxEncode(
-    const uint8_t* src_buf,
-    int width,
-    int height,
-    int pitch,
-    std::unique_ptr<uint8_t, FxFreeDeleter>* dest_buf,
-    uint32_t* dest_size) {
-  CCodec_FaxEncoder encoder(src_buf, width, height, pitch);
+void FaxModule::FaxEncode(const uint8_t* src_buf,
+                          int width,
+                          int height,
+                          int pitch,
+                          std::unique_ptr<uint8_t, FxFreeDeleter>* dest_buf,
+                          uint32_t* dest_size) {
+  FaxEncoder encoder(src_buf, width, height, pitch);
   encoder.Encode(dest_buf, dest_size);
 }
 
 #endif  // defined(OS_WIN)
+
+}  // namespace fxcodec
diff --git a/core/fxcodec/codec/ccodec_faxmodule.h b/core/fxcodec/codec/faxmodule.h
similarity index 80%
rename from core/fxcodec/codec/ccodec_faxmodule.h
rename to core/fxcodec/codec/faxmodule.h
index d2cc07a..d07632b 100644
--- a/core/fxcodec/codec/ccodec_faxmodule.h
+++ b/core/fxcodec/codec/faxmodule.h
@@ -4,8 +4,8 @@
 
 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
 
-#ifndef CORE_FXCODEC_CODEC_CCODEC_FAXMODULE_H_
-#define CORE_FXCODEC_CODEC_CCODEC_FAXMODULE_H_
+#ifndef CORE_FXCODEC_CODEC_FAXMODULE_H_
+#define CORE_FXCODEC_CODEC_FAXMODULE_H_
 
 #include <memory>
 
@@ -16,7 +16,9 @@
 
 class CCodec_ScanlineDecoder;
 
-class CCodec_FaxModule {
+namespace fxcodec {
+
+class FaxModule {
  public:
   static std::unique_ptr<CCodec_ScanlineDecoder> CreateDecoder(
       pdfium::span<const uint8_t> src_buf,
@@ -47,9 +49,13 @@
                         uint32_t* dest_size);
 #endif  // defined(OS_WIN)
 
-  CCodec_FaxModule() = delete;
-  CCodec_FaxModule(const CCodec_FaxModule&) = delete;
-  CCodec_FaxModule& operator=(const CCodec_FaxModule&) = delete;
+  FaxModule() = delete;
+  FaxModule(const FaxModule&) = delete;
+  FaxModule& operator=(const FaxModule&) = delete;
 };
 
-#endif  // CORE_FXCODEC_CODEC_CCODEC_FAXMODULE_H_
+}  // namespace fxcodec
+
+using FaxModule = fxcodec::FaxModule;
+
+#endif  // CORE_FXCODEC_CODEC_FAXMODULE_H_
diff --git a/core/fxcodec/jbig2/JBig2_GrdProc.cpp b/core/fxcodec/jbig2/JBig2_GrdProc.cpp
index 2394183..9a95c8f 100644
--- a/core/fxcodec/jbig2/JBig2_GrdProc.cpp
+++ b/core/fxcodec/jbig2/JBig2_GrdProc.cpp
@@ -10,7 +10,7 @@
 #include <memory>
 #include <utility>
 
-#include "core/fxcodec/codec/ccodec_faxmodule.h"
+#include "core/fxcodec/codec/faxmodule.h"
 #include "core/fxcodec/jbig2/JBig2_ArithDecoder.h"
 #include "core/fxcodec/jbig2/JBig2_BitStream.h"
 #include "core/fxcodec/jbig2/JBig2_Image.h"
@@ -458,9 +458,9 @@
     return m_ProssiveStatus;
   }
   int bitpos = static_cast<int>(pStream->getBitPos());
-  bitpos = CCodec_FaxModule::FaxG4Decode(pStream->getBuf(),
-                                         pStream->getLength(), bitpos, GBW, GBH,
-                                         image->stride(), image->data());
+  bitpos =
+      FaxModule::FaxG4Decode(pStream->getBuf(), pStream->getLength(), bitpos,
+                             GBW, GBH, image->stride(), image->data());
   pStream->setBitPos(bitpos);
   for (uint32_t i = 0; i < image->stride() * GBH; ++i)
     image->data()[i] = ~image->data()[i];
diff --git a/fpdfsdk/fpdf_view.cpp b/fpdfsdk/fpdf_view.cpp
index 5adb561..4e4946e 100644
--- a/fpdfsdk/fpdf_view.cpp
+++ b/fpdfsdk/fpdf_view.cpp
@@ -54,7 +54,7 @@
 
 #if defined(OS_WIN)
 #include "core/fxcodec/codec/ccodec_basicmodule.h"
-#include "core/fxcodec/codec/ccodec_faxmodule.h"
+#include "core/fxcodec/codec/faxmodule.h"
 #include "core/fxcodec/codec/flatemodule.h"
 #include "core/fxcodec/codec/jpegmodule.h"
 #include "core/fxge/cfx_windowsrenderdevice.h"
@@ -84,9 +84,8 @@
 
 #if defined(OS_WIN)
 constexpr EncoderIface kEncoderIface = {
-    CCodec_BasicModule::A85Encode, CCodec_FaxModule::FaxEncode,
-    FlateModule::Encode, JpegModule::JpegEncode,
-    CCodec_BasicModule::RunLengthEncode};
+    CCodec_BasicModule::A85Encode, FaxModule::FaxEncode, FlateModule::Encode,
+    JpegModule::JpegEncode, CCodec_BasicModule::RunLengthEncode};
 #endif  // defined(OS_WIN)
 
 void RenderPageImpl(CPDF_PageRenderContext* pContext,
diff --git a/testing/fuzzers/pdf_codec_fax_fuzzer.cc b/testing/fuzzers/pdf_codec_fax_fuzzer.cc
index c7d44e5..09f6efb 100644
--- a/testing/fuzzers/pdf_codec_fax_fuzzer.cc
+++ b/testing/fuzzers/pdf_codec_fax_fuzzer.cc
@@ -5,8 +5,8 @@
 #include <cstdint>
 #include <memory>
 
-#include "core/fxcodec/codec/ccodec_faxmodule.h"
 #include "core/fxcodec/codec/ccodec_scanlinedecoder.h"
+#include "core/fxcodec/codec/faxmodule.h"
 #include "testing/fuzzers/pdfium_fuzzer_util.h"
 
 extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
@@ -26,15 +26,15 @@
   int Rows = GetInteger(data + 16);
   bool EndOfLine = !(data[20] & 0x01);
   bool ByteAlign = !(data[20] & 0x02);
-  // This controls if CCodec_FaxDecoder::InvertBuffer() gets called. The method
-  // is not interesting, and calling it doubles the runtime.
+  // This controls if fxcodec::FaxDecoder::InvertBuffer() gets called.
+  // The method is not interesting, and calling it doubles the runtime.
   const bool kBlackIs1 = false;
   data += kParameterSize;
   size -= kParameterSize;
 
   std::unique_ptr<CCodec_ScanlineDecoder> decoder =
-      CCodec_FaxModule::CreateDecoder({data, size}, width, height, K, EndOfLine,
-                                      ByteAlign, kBlackIs1, Columns, Rows);
+      FaxModule::CreateDecoder({data, size}, width, height, K, EndOfLine,
+                               ByteAlign, kBlackIs1, Columns, Rows);
 
   if (decoder) {
     int line = 0;