Put fx_codec.h and fx_codec.cpp together.
- Move fx_codec.cpp up a directory.
- Audit functions defined in fx_codec.h, and either put the
implementations in fx_codec.cpp or move them out of fx_codec.h.
Change-Id: I0583b0f84a7c2b97b49e719212f3146d1a6a60bb
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/56291
Reviewed-by: Tom Sepez <tsepez@chromium.org>
Commit-Queue: Lei Zhang <thestig@chromium.org>
diff --git a/core/fpdfapi/page/cpdf_colorspace.cpp b/core/fpdfapi/page/cpdf_colorspace.cpp
index afe84cb..4d89af5 100644
--- a/core/fpdfapi/page/cpdf_colorspace.cpp
+++ b/core/fpdfapi/page/cpdf_colorspace.cpp
@@ -525,6 +525,16 @@
return pCS;
}
+// static
+uint32_t CPDF_ColorSpace::ComponentsForFamily(int family) {
+ if (family == PDFCS_DEVICERGB)
+ return 3;
+ if (family == PDFCS_DEVICEGRAY)
+ return 1;
+ ASSERT(family == PDFCS_DEVICECMYK);
+ return 4;
+}
+
size_t CPDF_ColorSpace::GetBufSize() const {
if (m_Family == PDFCS_PATTERN)
return sizeof(PatternValue);
diff --git a/core/fpdfapi/page/cpdf_colorspace.h b/core/fpdfapi/page/cpdf_colorspace.h
index 2757c53..333d9b9 100644
--- a/core/fpdfapi/page/cpdf_colorspace.h
+++ b/core/fpdfapi/page/cpdf_colorspace.h
@@ -53,6 +53,7 @@
CPDF_Document* pDoc,
const CPDF_Object* pCSObj,
std::set<const CPDF_Object*>* pVisited);
+ static uint32_t ComponentsForFamily(int family);
size_t GetBufSize() const;
float* CreateBuf() const;
diff --git a/core/fpdfapi/page/cpdf_devicecs.cpp b/core/fpdfapi/page/cpdf_devicecs.cpp
index 68e5b38..3b559ec 100644
--- a/core/fpdfapi/page/cpdf_devicecs.cpp
+++ b/core/fpdfapi/page/cpdf_devicecs.cpp
@@ -15,6 +15,7 @@
#include "core/fpdfapi/parser/cpdf_document.h"
#include "core/fpdfapi/parser/cpdf_stream_acc.h"
#include "core/fpdfapi/parser/cpdf_string.h"
+#include "core/fxcodec/fx_codec.h"
#include "core/fxge/dib/cfx_cmyk_to_srgb.h"
#include "third_party/base/logging.h"
#include "third_party/base/stl_util.h"
@@ -27,33 +28,6 @@
} // namespace
-uint32_t ComponentsForFamily(int family) {
- if (family == PDFCS_DEVICERGB)
- return 3;
- if (family == PDFCS_DEVICEGRAY)
- return 1;
- ASSERT(family == PDFCS_DEVICECMYK);
- return 4;
-}
-
-void ReverseRGB(uint8_t* pDestBuf, const uint8_t* pSrcBuf, int pixels) {
- if (pDestBuf == pSrcBuf) {
- for (int i = 0; i < pixels; i++) {
- uint8_t temp = pDestBuf[2];
- pDestBuf[2] = pDestBuf[0];
- pDestBuf[0] = temp;
- pDestBuf += 3;
- }
- } else {
- for (int i = 0; i < pixels; i++) {
- *pDestBuf++ = pSrcBuf[2];
- *pDestBuf++ = pSrcBuf[1];
- *pDestBuf++ = pSrcBuf[0];
- pSrcBuf += 3;
- }
- }
-}
-
CPDF_DeviceCS::CPDF_DeviceCS(int family) : CPDF_ColorSpace(nullptr, family) {
ASSERT(family == PDFCS_DEVICEGRAY || family == PDFCS_DEVICERGB ||
family == PDFCS_DEVICECMYK);
diff --git a/core/fpdfapi/render/cpdf_dibbase.cpp b/core/fpdfapi/render/cpdf_dibbase.cpp
index bc1c567..128a24c 100644
--- a/core/fpdfapi/render/cpdf_dibbase.cpp
+++ b/core/fpdfapi/render/cpdf_dibbase.cpp
@@ -544,7 +544,7 @@
case PDFCS_DEVICEGRAY:
case PDFCS_DEVICERGB:
case PDFCS_DEVICECMYK: {
- uint32_t dwMinComps = ComponentsForFamily(m_Family);
+ uint32_t dwMinComps = CPDF_ColorSpace::ComponentsForFamily(m_Family);
if (m_pColorSpace->CountComponents() < dwMinComps ||
m_nComponents < dwMinComps) {
return false;
diff --git a/core/fxcodec/BUILD.gn b/core/fxcodec/BUILD.gn
index ca3baa2..07e3182 100644
--- a/core/fxcodec/BUILD.gn
+++ b/core/fxcodec/BUILD.gn
@@ -22,7 +22,6 @@
"codec/faxmodule.h",
"codec/flatemodule.cpp",
"codec/flatemodule.h",
- "codec/fx_codec.cpp",
"codec/iccmodule.cpp",
"codec/iccmodule.h",
"codec/jbig2module.cpp",
@@ -33,6 +32,7 @@
"codec/jpxmodule.h",
"codec/scanlinedecoder.cpp",
"codec/scanlinedecoder.h",
+ "fx_codec.cpp",
"fx_codec.h",
"fx_codec_def.h",
"jbig2/JBig2_ArithDecoder.cpp",
diff --git a/core/fxcodec/codec/fx_codec.cpp b/core/fxcodec/fx_codec.cpp
similarity index 83%
rename from core/fxcodec/codec/fx_codec.cpp
rename to core/fxcodec/fx_codec.cpp
index 65a29ae..65f3c47 100644
--- a/core/fxcodec/codec/fx_codec.cpp
+++ b/core/fxcodec/fx_codec.cpp
@@ -75,6 +75,24 @@
}
#endif // PDF_ENABLE_XFA
+void ReverseRGB(uint8_t* pDestBuf, const uint8_t* pSrcBuf, int pixels) {
+ if (pDestBuf == pSrcBuf) {
+ for (int i = 0; i < pixels; i++) {
+ uint8_t temp = pDestBuf[2];
+ pDestBuf[2] = pDestBuf[0];
+ pDestBuf[0] = temp;
+ pDestBuf += 3;
+ }
+ } else {
+ for (int i = 0; i < pixels; i++) {
+ *pDestBuf++ = pSrcBuf[2];
+ *pDestBuf++ = pSrcBuf[1];
+ *pDestBuf++ = pSrcBuf[0];
+ pSrcBuf += 3;
+ }
+ }
+}
+
FX_SAFE_UINT32 CalculatePitch8(uint32_t bpc, uint32_t components, int width) {
FX_SAFE_UINT32 pitch = bpc;
pitch *= components;
diff --git a/core/fxcodec/fx_codec.h b/core/fxcodec/fx_codec.h
index 1e69366..32c2810 100644
--- a/core/fxcodec/fx_codec.h
+++ b/core/fxcodec/fx_codec.h
@@ -122,7 +122,6 @@
};
void ReverseRGB(uint8_t* pDestBuf, const uint8_t* pSrcBuf, int pixels);
-uint32_t ComponentsForFamily(int family);
FX_SAFE_UINT32 CalculatePitch8(uint32_t bpc, uint32_t components, int width);
FX_SAFE_UINT32 CalculatePitch32(int bpp, int width);