Replace IccModule with IccTransform.
The module class, with its static methods, serves no purpose, and the
actions it performs are better served as methods of the LCmsCmm class.
-- Rename from LCmsCmm for clarity.
Change-Id: I7f8ada3c41d43b73f1f59c4280af412e7f98e774
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/84633
Commit-Queue: Tom Sepez <tsepez@chromium.org>
Reviewed-by: Lei Zhang <thestig@chromium.org>
diff --git a/core/fxcodec/BUILD.gn b/core/fxcodec/BUILD.gn
index 784dcce..4564510 100644
--- a/core/fxcodec/BUILD.gn
+++ b/core/fxcodec/BUILD.gn
@@ -18,8 +18,8 @@
"fx_codec.cpp",
"fx_codec.h",
"fx_codec_def.h",
- "icc/iccmodule.cpp",
- "icc/iccmodule.h",
+ "icc/icc_transform.cpp",
+ "icc/icc_transform.h",
"jbig2/JBig2_ArithDecoder.cpp",
"jbig2/JBig2_ArithDecoder.h",
"jbig2/JBig2_ArithIntDecoder.cpp",
diff --git a/core/fxcodec/icc/iccmodule.cpp b/core/fxcodec/icc/icc_transform.cpp
similarity index 77%
rename from core/fxcodec/icc/iccmodule.cpp
rename to core/fxcodec/icc/icc_transform.cpp
index 9cf0c4f..b8483ba 100644
--- a/core/fxcodec/icc/iccmodule.cpp
+++ b/core/fxcodec/icc/icc_transform.cpp
@@ -4,7 +4,7 @@
// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
-#include "core/fxcodec/icc/iccmodule.h"
+#include "core/fxcodec/icc/icc_transform.h"
#include <algorithm>
#include <memory>
@@ -13,6 +13,7 @@
#include "core/fxcrt/fx_memory_wrappers.h"
#include "third_party/base/cxx17_backports.h"
#include "third_party/base/notreached.h"
+#include "third_party/base/ptr_util.h"
namespace fxcodec {
@@ -37,21 +38,21 @@
} // namespace
-CLcmsCmm::CLcmsCmm(cmsHTRANSFORM hTransform,
- int srcComponents,
- bool bIsLab,
- bool bNormal)
+IccTransform::IccTransform(cmsHTRANSFORM hTransform,
+ int srcComponents,
+ bool bIsLab,
+ bool bNormal)
: m_hTransform(hTransform),
m_nSrcComponents(srcComponents),
m_bLab(bIsLab),
m_bNormal(bNormal) {}
-CLcmsCmm::~CLcmsCmm() {
+IccTransform::~IccTransform() {
cmsDeleteTransform(m_hTransform);
}
// static
-std::unique_ptr<CLcmsCmm> IccModule::CreateTransformSRGB(
+std::unique_ptr<IccTransform> IccTransform::CreateTransformSRGB(
pdfium::span<const uint8_t> span) {
ScopedCmsProfile srcProfile(cmsOpenProfileFromMem(span.data(), span.size()));
if (!srcProfile)
@@ -62,8 +63,8 @@
return nullptr;
cmsColorSpaceSignature srcCS = cmsGetColorSpace(srcProfile.get());
-
uint32_t nSrcComponents = cmsChannelsOf(srcCS);
+
// According to PDF spec, number of components must be 1, 3, or 4.
if (nSrcComponents != 1 && nSrcComponents != 3 && nSrcComponents != 4)
return nullptr;
@@ -105,27 +106,24 @@
if (!hTransform)
return nullptr;
- return std::make_unique<CLcmsCmm>(hTransform, nSrcComponents, bLab, bNormal);
+ // Private ctor.
+ return pdfium::WrapUnique(
+ new IccTransform(hTransform, nSrcComponents, bLab, bNormal));
}
-// static
-void IccModule::Translate(CLcmsCmm* pTransform,
- pdfium::span<const float> pSrcValues,
- pdfium::span<float> pDestValues) {
- if (!pTransform)
- return;
-
+void IccTransform::Translate(pdfium::span<const float> pSrcValues,
+ pdfium::span<float> pDestValues) {
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 `pSrcValues.size()`
// components are used.
- if (pTransform->IsLab()) {
+ if (m_bLab) {
std::vector<double, FxAllocAllocator<double>> inputs(
std::max<size_t>(pSrcValues.size(), 16));
for (uint32_t i = 0; i < pSrcValues.size(); ++i)
inputs[i] = pSrcValues[i];
- cmsDoTransform(pTransform->transform(), inputs.data(), output, 1);
+ cmsDoTransform(m_hTransform, inputs.data(), output, 1);
} else {
std::vector<uint8_t, FxAllocAllocator<uint8_t>> inputs(
std::max<size_t>(pSrcValues.size(), 16));
@@ -133,20 +131,17 @@
inputs[i] =
pdfium::clamp(static_cast<int>(pSrcValues[i] * 255.0f), 0, 255);
}
- cmsDoTransform(pTransform->transform(), inputs.data(), output, 1);
+ cmsDoTransform(m_hTransform, inputs.data(), output, 1);
}
pDestValues[0] = output[2] / 255.0f;
pDestValues[1] = output[1] / 255.0f;
pDestValues[2] = output[0] / 255.0f;
}
-// static
-void IccModule::TranslateScanline(CLcmsCmm* pTransform,
- unsigned char* pDest,
- const unsigned char* pSrc,
- int32_t pixels) {
- if (pTransform)
- cmsDoTransform(pTransform->transform(), pSrc, pDest, pixels);
+void IccTransform::TranslateScanline(unsigned char* pDest,
+ const unsigned char* pSrc,
+ int32_t pixels) {
+ cmsDoTransform(m_hTransform, pSrc, pDest, pixels);
}
} // namespace fxcodec
diff --git a/core/fxcodec/icc/icc_transform.h b/core/fxcodec/icc/icc_transform.h
new file mode 100644
index 0000000..9ea0c34
--- /dev/null
+++ b/core/fxcodec/icc/icc_transform.h
@@ -0,0 +1,53 @@
+// Copyright 2016 PDFium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
+
+#ifndef CORE_FXCODEC_ICC_ICC_TRANSFORM_H_
+#define CORE_FXCODEC_ICC_ICC_TRANSFORM_H_
+
+#include <stdint.h>
+
+#include <memory>
+
+#include "core/fxcodec/fx_codec_def.h"
+#include "third_party/base/span.h"
+
+#if defined(USE_SYSTEM_LCMS2)
+#include <lcms2.h>
+#else
+#include "third_party/lcms/include/lcms2.h"
+#endif
+
+namespace fxcodec {
+
+class IccTransform {
+ public:
+ static std::unique_ptr<IccTransform> CreateTransformSRGB(
+ pdfium::span<const uint8_t> span);
+
+ ~IccTransform();
+
+ void Translate(pdfium::span<const float> pSrcValues,
+ pdfium::span<float> pDestValues);
+ void TranslateScanline(uint8_t* pDest, const uint8_t* pSrc, int pixels);
+
+ int components() const { return m_nSrcComponents; }
+ bool IsNormal() const { return m_bNormal; }
+
+ private:
+ IccTransform(cmsHTRANSFORM transform,
+ int srcComponents,
+ bool bIsLab,
+ bool bNormal);
+
+ const cmsHTRANSFORM m_hTransform;
+ const int m_nSrcComponents;
+ const bool m_bLab;
+ const bool m_bNormal;
+};
+
+} // namespace fxcodec
+
+#endif // CORE_FXCODEC_ICC_ICC_TRANSFORM_H_
diff --git a/core/fxcodec/icc/iccmodule.h b/core/fxcodec/icc/iccmodule.h
deleted file mode 100644
index 0f2fa7f..0000000
--- a/core/fxcodec/icc/iccmodule.h
+++ /dev/null
@@ -1,67 +0,0 @@
-// Copyright 2016 PDFium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
-
-#ifndef CORE_FXCODEC_ICC_ICCMODULE_H_
-#define CORE_FXCODEC_ICC_ICCMODULE_H_
-
-#include <stdint.h>
-
-#include <memory>
-
-#include "core/fxcodec/fx_codec_def.h"
-#include "third_party/base/span.h"
-
-#if defined(USE_SYSTEM_LCMS2)
-#include <lcms2.h>
-#else
-#include "third_party/lcms/include/lcms2.h"
-#endif
-
-namespace fxcodec {
-
-class CLcmsCmm {
- public:
- CLcmsCmm(cmsHTRANSFORM transform,
- int srcComponents,
- bool bIsLab,
- bool bNormal);
- ~CLcmsCmm();
-
- cmsHTRANSFORM transform() const { return m_hTransform; }
- int components() const { return m_nSrcComponents; }
- bool IsLab() const { return m_bLab; }
- bool IsNormal() const { return m_bNormal; }
-
- private:
- const cmsHTRANSFORM m_hTransform;
- const int m_nSrcComponents;
- const bool m_bLab;
- const bool m_bNormal;
-};
-
-class IccModule {
- public:
- static std::unique_ptr<CLcmsCmm> CreateTransformSRGB(
- pdfium::span<const uint8_t> span);
- static void Translate(CLcmsCmm* pTransform,
- pdfium::span<const float> pSrcValues,
- pdfium::span<float> pDestValues);
- static void TranslateScanline(CLcmsCmm* pTransform,
- uint8_t* pDest,
- const uint8_t* pSrc,
- int pixels);
-
- IccModule() = delete;
- IccModule(const IccModule&) = delete;
- IccModule& operator=(const IccModule&) = delete;
-};
-
-} // namespace fxcodec
-
-using CLcmsCmm = fxcodec::CLcmsCmm;
-using IccModule = fxcodec::IccModule;
-
-#endif // CORE_FXCODEC_ICC_ICCMODULE_H_