Get rid of CCodec_ModuleMgr::GetIccModule().

The CCodec_IccModule class consists of a set of methods that can all be
static. Make the methods static, and make sure CCodec_IccModule cannot
be instantiated. Then CCodec_ModuleMgr::GetIccModule() becomes pointless
and all the callers can just call CCodec_IccModule directly.

Change-Id: I75fbc0b6f179c84b8d42fb3edbc5a8d433c5622e
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/55012
Commit-Queue: Lei Zhang <thestig@chromium.org>
Reviewed-by: Tom Sepez <tsepez@chromium.org>
diff --git a/core/fpdfapi/cpdf_modulemgr.cpp b/core/fpdfapi/cpdf_modulemgr.cpp
index 83d097a..5dfe8e9 100644
--- a/core/fpdfapi/cpdf_modulemgr.cpp
+++ b/core/fpdfapi/cpdf_modulemgr.cpp
@@ -68,10 +68,6 @@
   return m_pCodecModule->GetJbig2Module();
 }
 
-CCodec_IccModule* CPDF_ModuleMgr::GetIccModule() {
-  return m_pCodecModule->GetIccModule();
-}
-
 void CPDF_ModuleMgr::InitPageModule() {
   m_pPageModule = pdfium::MakeUnique<CPDF_PageModule>();
 }
diff --git a/core/fpdfapi/cpdf_modulemgr.h b/core/fpdfapi/cpdf_modulemgr.h
index 6694f82..d66a8f7 100644
--- a/core/fpdfapi/cpdf_modulemgr.h
+++ b/core/fpdfapi/cpdf_modulemgr.h
@@ -11,7 +11,6 @@
 #include <utility>
 
 class CCodec_FlateModule;
-class CCodec_IccModule;
 class CCodec_Jbig2Module;
 class CCodec_JpegModule;
 class CCodec_ModuleMgr;
@@ -52,7 +51,6 @@
 
   CCodec_JpegModule* GetJpegModule();
   CCodec_Jbig2Module* GetJbig2Module();
-  CCodec_IccModule* GetIccModule();
   CCodec_FlateModule* GetFlateModule();
 
  private:
diff --git a/core/fpdfapi/page/cpdf_colorspace.cpp b/core/fpdfapi/page/cpdf_colorspace.cpp
index 722d0e8..9d054ca 100644
--- a/core/fpdfapi/page/cpdf_colorspace.cpp
+++ b/core/fpdfapi/page/cpdf_colorspace.cpp
@@ -915,9 +915,8 @@
   }
   if (m_pProfile->transform()) {
     float rgb[3];
-    CCodec_IccModule* pIccModule = CPDF_ModuleMgr::Get()->GetIccModule();
-    pIccModule->SetComponents(CountComponents());
-    pIccModule->Translate(m_pProfile->transform(), pBuf, rgb);
+    CCodec_IccModule::Translate(m_pProfile->transform(), CountComponents(),
+                                pBuf, rgb);
     *R = rgb[0];
     *G = rgb[1];
     *B = rgb[2];
@@ -972,8 +971,8 @@
       bTranslate = nPixelCount.ValueOrDie() < nMaxColors * 3 / 2;
   }
   if (bTranslate) {
-    CPDF_ModuleMgr::Get()->GetIccModule()->TranslateScanline(
-        m_pProfile->transform(), pDestBuf, pSrcBuf, pixels);
+    CCodec_IccModule::TranslateScanline(m_pProfile->transform(), pDestBuf,
+                                        pSrcBuf, pixels);
     return;
   }
 
@@ -990,7 +989,7 @@
         order /= 52;
       }
     }
-    CPDF_ModuleMgr::Get()->GetIccModule()->TranslateScanline(
+    CCodec_IccModule::TranslateScanline(
         m_pProfile->transform(), m_pCache.data(), temp_src.data(), nMaxColors);
   }
   for (int i = 0; i < pixels; i++) {
diff --git a/core/fpdfapi/page/cpdf_iccprofile.cpp b/core/fpdfapi/page/cpdf_iccprofile.cpp
index 0d60507..811ef35 100644
--- a/core/fpdfapi/page/cpdf_iccprofile.cpp
+++ b/core/fpdfapi/page/cpdf_iccprofile.cpp
@@ -6,7 +6,6 @@
 
 #include "core/fpdfapi/page/cpdf_iccprofile.h"
 
-#include "core/fpdfapi/cpdf_modulemgr.h"
 #include "core/fpdfapi/parser/cpdf_stream.h"
 #include "core/fxcodec/codec/ccodec_iccmodule.h"
 
@@ -27,10 +26,9 @@
     return;
   }
 
-  auto* pIccModule = CPDF_ModuleMgr::Get()->GetIccModule();
-  m_Transform = pIccModule->CreateTransform_sRGB(span);
+  m_Transform = CCodec_IccModule::CreateTransform_sRGB(span);
   if (m_Transform)
     m_nSrcComponents = m_Transform->components();
 }
 
-CPDF_IccProfile::~CPDF_IccProfile() {}
+CPDF_IccProfile::~CPDF_IccProfile() = default;
diff --git a/core/fxcodec/codec/ccodec_iccmodule.cpp b/core/fxcodec/codec/ccodec_iccmodule.cpp
index ae88dec..2448a10 100644
--- a/core/fxcodec/codec/ccodec_iccmodule.cpp
+++ b/core/fxcodec/codec/ccodec_iccmodule.cpp
@@ -48,10 +48,7 @@
   cmsDeleteTransform(m_hTransform);
 }
 
-CCodec_IccModule::CCodec_IccModule() {}
-
-CCodec_IccModule::~CCodec_IccModule() {}
-
+// static
 std::unique_ptr<CLcmsCmm> CCodec_IccModule::CreateTransform_sRGB(
     pdfium::span<const uint8_t> span) {
   ScopedCmsProfile srcProfile(cmsOpenProfileFromMem(span.data(), span.size()));
@@ -110,17 +107,18 @@
                                       bNormal);
 }
 
+// static
 void CCodec_IccModule::Translate(CLcmsCmm* pTransform,
+                                 uint32_t nSrcComponents,
                                  const float* pSrcValues,
                                  float* pDestValues) {
   if (!pTransform)
     return;
 
-  uint32_t nSrcComponents = m_nComponents;
   uint8_t output[4];
   // TODO(npm): Currently the CmsDoTransform method is part of LCMS and it will
   // apply some member of m_hTransform to the input. We need to go over all the
-  // places which set transform to verify that only nSrcComponents are used.
+  // places which set transform to verify that only |nSrcComponents| are used.
   if (pTransform->IsLab()) {
     std::vector<double> inputs(std::max(nSrcComponents, 16u));
     for (uint32_t i = 0; i < nSrcComponents; ++i)
@@ -139,6 +137,7 @@
   pDestValues[2] = output[0] / 255.0f;
 }
 
+// static
 void CCodec_IccModule::TranslateScanline(CLcmsCmm* pTransform,
                                          unsigned char* pDest,
                                          const unsigned char* pSrc,
diff --git a/core/fxcodec/codec/ccodec_iccmodule.h b/core/fxcodec/codec/ccodec_iccmodule.h
index 432ca1c..a9db38a 100644
--- a/core/fxcodec/codec/ccodec_iccmodule.h
+++ b/core/fxcodec/codec/ccodec_iccmodule.h
@@ -42,22 +42,20 @@
 
 class CCodec_IccModule {
  public:
-  CCodec_IccModule();
-  ~CCodec_IccModule();
-
-  std::unique_ptr<CLcmsCmm> CreateTransform_sRGB(
+  static std::unique_ptr<CLcmsCmm> CreateTransform_sRGB(
       pdfium::span<const uint8_t> span);
-  void Translate(CLcmsCmm* pTransform,
-                 const float* pSrcValues,
-                 float* pDestValues);
-  void TranslateScanline(CLcmsCmm* pTransform,
-                         uint8_t* pDest,
-                         const uint8_t* pSrc,
-                         int pixels);
-  void SetComponents(uint32_t nComponents) { m_nComponents = nComponents; }
+  static void Translate(CLcmsCmm* pTransform,
+                        uint32_t nSrcComponents,
+                        const float* pSrcValues,
+                        float* pDestValues);
+  static void TranslateScanline(CLcmsCmm* pTransform,
+                                uint8_t* pDest,
+                                const uint8_t* pSrc,
+                                int pixels);
 
- protected:
-  uint32_t m_nComponents = 0;
+  CCodec_IccModule() = delete;
+  CCodec_IccModule(const CCodec_IccModule&) = delete;
+  CCodec_IccModule& operator=(const CCodec_IccModule&) = delete;
 };
 
 #endif  // CORE_FXCODEC_CODEC_CCODEC_ICCMODULE_H_
diff --git a/core/fxcodec/codec/fx_codec.cpp b/core/fxcodec/codec/fx_codec.cpp
index f008ce1..0ffaabc 100644
--- a/core/fxcodec/codec/fx_codec.cpp
+++ b/core/fxcodec/codec/fx_codec.cpp
@@ -11,7 +11,6 @@
 #include <memory>
 #include <utility>
 
-#include "core/fxcodec/codec/ccodec_iccmodule.h"
 #include "core/fxcodec/codec/ccodec_jbig2module.h"
 #include "core/fxcodec/codec/ccodec_jpegmodule.h"
 #include "core/fxcodec/codec/codec_int.h"
@@ -22,8 +21,7 @@
 
 CCodec_ModuleMgr::CCodec_ModuleMgr()
     : m_pJpegModule(pdfium::MakeUnique<CCodec_JpegModule>()),
-      m_pJbig2Module(pdfium::MakeUnique<CCodec_Jbig2Module>()),
-      m_pIccModule(pdfium::MakeUnique<CCodec_IccModule>()) {}
+      m_pJbig2Module(pdfium::MakeUnique<CCodec_Jbig2Module>()) {}
 
 CCodec_ModuleMgr::~CCodec_ModuleMgr() = default;
 
diff --git a/core/fxcodec/fx_codec.h b/core/fxcodec/fx_codec.h
index 6b95258..034d6ce 100644
--- a/core/fxcodec/fx_codec.h
+++ b/core/fxcodec/fx_codec.h
@@ -34,7 +34,6 @@
 #endif  // PDF_ENABLE_XFA_TIFF
 #endif  // PDF_ENABLE_XFA
 
-class CCodec_IccModule;
 class CCodec_Jbig2Module;
 class CCodec_JpegModule;
 
@@ -60,7 +59,6 @@
 
   CCodec_JpegModule* GetJpegModule() const { return m_pJpegModule.get(); }
   CCodec_Jbig2Module* GetJbig2Module() const { return m_pJbig2Module.get(); }
-  CCodec_IccModule* GetIccModule() const { return m_pIccModule.get(); }
 
 #ifdef PDF_ENABLE_XFA
   std::unique_ptr<CCodec_ProgressiveDecoder> CreateProgressiveDecoder();
@@ -97,7 +95,6 @@
  protected:
   std::unique_ptr<CCodec_JpegModule> m_pJpegModule;
   std::unique_ptr<CCodec_Jbig2Module> m_pJbig2Module;
-  std::unique_ptr<CCodec_IccModule> m_pIccModule;
 
 #ifdef PDF_ENABLE_XFA
 #ifdef PDF_ENABLE_XFA_BMP
diff --git a/testing/fuzzers/pdf_codec_icc_fuzzer.cc b/testing/fuzzers/pdf_codec_icc_fuzzer.cc
index faafc36..6d06a90 100644
--- a/testing/fuzzers/pdf_codec_icc_fuzzer.cc
+++ b/testing/fuzzers/pdf_codec_icc_fuzzer.cc
@@ -8,17 +8,16 @@
 #include "third_party/base/span.h"
 
 extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
-  CCodec_IccModule icc_module;
   std::unique_ptr<CLcmsCmm> transform =
-      icc_module.CreateTransform_sRGB(pdfium::make_span(data, size));
+      CCodec_IccModule::CreateTransform_sRGB(pdfium::make_span(data, size));
 
   if (transform) {
     float src[4];
     float dst[4];
     for (int i = 0; i < 4; i++)
       src[i] = 0.5f;
-    icc_module.SetComponents(transform->components());
-    icc_module.Translate(transform.get(), src, dst);
+    CCodec_IccModule::Translate(transform.get(), transform->components(), src,
+                                dst);
   }
 
   return 0;