Put various fxcodec bits into namespace fxcodec.
- Functions in fx_codec.h.
- Some bmp classes.
BUG=pdfium:1311
Change-Id: I2fef4c28f494379579b988dc5ba823c91d75f2b5
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/56293
Commit-Queue: Lei Zhang <thestig@chromium.org>
Reviewed-by: Tom Sepez <tsepez@chromium.org>
diff --git a/core/fpdfapi/page/cpdf_colorspace.cpp b/core/fpdfapi/page/cpdf_colorspace.cpp
index 4d89af5..431fa1e 100644
--- a/core/fpdfapi/page/cpdf_colorspace.cpp
+++ b/core/fpdfapi/page/cpdf_colorspace.cpp
@@ -759,7 +759,7 @@
pDestBuf += 3;
}
}
- ReverseRGB(pDestBuf, pSrcBuf, pixels);
+ fxcodec::ReverseRGB(pDestBuf, pSrcBuf, pixels);
}
CPDF_LabCS::CPDF_LabCS(CPDF_Document* pDoc)
@@ -954,7 +954,7 @@
int image_height,
bool bTransMask) const {
if (m_pProfile->IsSRGB()) {
- ReverseRGB(pDestBuf, pSrcBuf, pixels);
+ fxcodec::ReverseRGB(pDestBuf, pSrcBuf, pixels);
return;
}
if (!m_pProfile->transform()) {
diff --git a/core/fpdfapi/page/cpdf_devicecs.cpp b/core/fpdfapi/page/cpdf_devicecs.cpp
index 3b559ec..e557516 100644
--- a/core/fpdfapi/page/cpdf_devicecs.cpp
+++ b/core/fpdfapi/page/cpdf_devicecs.cpp
@@ -34,7 +34,7 @@
SetComponentsForStockCS(ComponentsForFamily(GetFamily()));
}
-CPDF_DeviceCS::~CPDF_DeviceCS() {}
+CPDF_DeviceCS::~CPDF_DeviceCS() = default;
uint32_t CPDF_DeviceCS::v_Load(CPDF_Document* pDoc,
const CPDF_Array* pArray,
@@ -93,7 +93,7 @@
}
break;
case PDFCS_DEVICERGB:
- ReverseRGB(pDestBuf, pSrcBuf, pixels);
+ fxcodec::ReverseRGB(pDestBuf, pSrcBuf, pixels);
break;
case PDFCS_DEVICECMYK:
if (bTransMask) {
diff --git a/core/fpdfapi/page/cpdf_streamparser.cpp b/core/fpdfapi/page/cpdf_streamparser.cpp
index 6d51136..44b3785 100644
--- a/core/fpdfapi/page/cpdf_streamparser.cpp
+++ b/core/fpdfapi/page/cpdf_streamparser.cpp
@@ -53,7 +53,7 @@
if (width <= 0 || height <= 0)
return FX_INVALID_OFFSET;
- FX_SAFE_UINT32 size = CalculatePitch8(bpc, ncomps, width);
+ FX_SAFE_UINT32 size = fxcodec::CalculatePitch8(bpc, ncomps, width);
size *= height;
if (size.ValueOrDefault(0) == 0)
return FX_INVALID_OFFSET;
@@ -160,7 +160,7 @@
nComponents = pCS ? pCS->CountComponents() : 3;
bpc = pDict->GetIntegerFor("BitsPerComponent");
}
- FX_SAFE_UINT32 size = CalculatePitch8(bpc, nComponents, width);
+ FX_SAFE_UINT32 size = fxcodec::CalculatePitch8(bpc, nComponents, width);
size *= height;
if (!size.IsValid())
return nullptr;
diff --git a/core/fpdfapi/render/cpdf_dibbase.cpp b/core/fpdfapi/render/cpdf_dibbase.cpp
index 128a24c..67ef464 100644
--- a/core/fpdfapi/render/cpdf_dibbase.cpp
+++ b/core/fpdfapi/render/cpdf_dibbase.cpp
@@ -124,7 +124,7 @@
return false;
FX_SAFE_UINT32 src_size =
- CalculatePitch8(m_bpc, m_nComponents, m_Width) * m_Height;
+ fxcodec::CalculatePitch8(m_bpc, m_nComponents, m_Width) * m_Height;
if (!src_size.IsValid())
return false;
@@ -148,7 +148,7 @@
} else {
m_bpp = 24;
}
- FX_SAFE_UINT32 pitch = CalculatePitch32(m_bpp, m_Width);
+ FX_SAFE_UINT32 pitch = fxcodec::CalculatePitch32(m_bpp, m_Width);
if (!pitch.IsValid())
return false;
@@ -157,7 +157,7 @@
if (m_bColorKey) {
m_bpp = 32;
m_AlphaFlag = 2;
- pitch = CalculatePitch32(m_bpp, m_Width);
+ pitch = fxcodec::CalculatePitch32(m_bpp, m_Width);
if (!pitch.IsValid())
return false;
@@ -183,7 +183,7 @@
if (!m_bpc || !m_nComponents) {
return false;
}
- FX_SAFE_UINT32 pitch = CalculatePitch32(m_bpp, m_Width);
+ FX_SAFE_UINT32 pitch = fxcodec::CalculatePitch32(m_bpp, m_Width);
if (!pitch.IsValid())
return false;
@@ -195,7 +195,7 @@
if (m_bColorKey) {
m_bpp = 32;
m_AlphaFlag = 2;
- pitch = CalculatePitch32(m_bpp, m_Width);
+ pitch = fxcodec::CalculatePitch32(m_bpp, m_Width);
if (!pitch.IsValid())
return false;
m_pMaskedLine.reset(FX_Alloc(uint8_t, pitch.ValueOrDie()));
@@ -237,7 +237,7 @@
return LoadState::kFail;
FX_SAFE_UINT32 src_size =
- CalculatePitch8(m_bpc, m_nComponents, m_Width) * m_Height;
+ fxcodec::CalculatePitch8(m_bpc, m_nComponents, m_Width) * m_Height;
if (!src_size.IsValid())
return LoadState::kFail;
@@ -497,10 +497,10 @@
return LoadState::kFail;
FX_SAFE_UINT32 requested_pitch =
- CalculatePitch8(m_bpc, m_nComponents, m_Width);
+ fxcodec::CalculatePitch8(m_bpc, m_nComponents, m_Width);
if (!requested_pitch.IsValid())
return LoadState::kFail;
- FX_SAFE_UINT32 provided_pitch = CalculatePitch8(
+ FX_SAFE_UINT32 provided_pitch = fxcodec::CalculatePitch8(
m_pDecoder->GetBPC(), m_pDecoder->CountComps(), m_pDecoder->GetWidth());
if (!provided_pitch.IsValid())
return LoadState::kFail;
@@ -961,7 +961,8 @@
if (m_bpc == 0)
return nullptr;
- FX_SAFE_UINT32 src_pitch = CalculatePitch8(m_bpc, m_nComponents, m_Width);
+ FX_SAFE_UINT32 src_pitch =
+ fxcodec::CalculatePitch8(m_bpc, m_nComponents, m_Width);
if (!src_pitch.IsValid())
return nullptr;
uint32_t src_pitch_value = src_pitch.ValueOrDie();
@@ -1093,7 +1094,8 @@
}
uint32_t src_width = m_Width;
- FX_SAFE_UINT32 pitch = CalculatePitch8(m_bpc, m_nComponents, m_Width);
+ FX_SAFE_UINT32 pitch =
+ fxcodec::CalculatePitch8(m_bpc, m_nComponents, m_Width);
if (!pitch.IsValid())
return;
diff --git a/core/fxcodec/bmp/cfx_bmpcontext.cpp b/core/fxcodec/bmp/cfx_bmpcontext.cpp
index 596d117..a35a585 100644
--- a/core/fxcodec/bmp/cfx_bmpcontext.cpp
+++ b/core/fxcodec/bmp/cfx_bmpcontext.cpp
@@ -6,8 +6,12 @@
#include "core/fxcodec/bmp/cfx_bmpcontext.h"
+namespace fxcodec {
+
CFX_BmpContext::CFX_BmpContext(BmpModule* pModule,
BmpModule::Delegate* pDelegate)
: m_Bmp(this), m_pModule(pModule), m_pDelegate(pDelegate) {}
CFX_BmpContext::~CFX_BmpContext() = default;
+
+} // namespace fxcodec
diff --git a/core/fxcodec/bmp/cfx_bmpcontext.h b/core/fxcodec/bmp/cfx_bmpcontext.h
index 7aa20b3..e368a9b 100644
--- a/core/fxcodec/bmp/cfx_bmpcontext.h
+++ b/core/fxcodec/bmp/cfx_bmpcontext.h
@@ -12,6 +12,8 @@
#include "core/fxcodec/codec/bmpmodule.h"
#include "core/fxcrt/unowned_ptr.h"
+namespace fxcodec {
+
class CFX_BmpContext final : public CodecModuleIface::Context {
public:
CFX_BmpContext(BmpModule* pModule, BmpModule::Delegate* pDelegate);
@@ -22,4 +24,6 @@
UnownedPtr<BmpModule::Delegate> const m_pDelegate;
};
+} // namespace fxcodec
+
#endif // CORE_FXCODEC_BMP_CFX_BMPCONTEXT_H_
diff --git a/core/fxcodec/bmp/cfx_bmpdecompressor.cpp b/core/fxcodec/bmp/cfx_bmpdecompressor.cpp
index f494b8e..082c3d0 100644
--- a/core/fxcodec/bmp/cfx_bmpdecompressor.cpp
+++ b/core/fxcodec/bmp/cfx_bmpdecompressor.cpp
@@ -18,6 +18,8 @@
#include "third_party/base/logging.h"
#include "third_party/base/numerics/safe_math.h"
+namespace fxcodec {
+
namespace {
#define BMP_PAL_ENCODE(a, r, g, b) \
@@ -705,3 +707,5 @@
height_ = -signed_height;
img_tb_flag_ = true;
}
+
+} // namespace fxcodec
diff --git a/core/fxcodec/bmp/cfx_bmpdecompressor.h b/core/fxcodec/bmp/cfx_bmpdecompressor.h
index 2d25141..dcdd91b 100644
--- a/core/fxcodec/bmp/cfx_bmpdecompressor.h
+++ b/core/fxcodec/bmp/cfx_bmpdecompressor.h
@@ -16,9 +16,12 @@
#include "core/fxcrt/retain_ptr.h"
#include "core/fxcrt/unowned_ptr.h"
-class CFX_BmpContext;
class CFX_CodecMemory;
+namespace fxcodec {
+
+class CFX_BmpContext;
+
class CFX_BmpDecompressor {
public:
explicit CFX_BmpDecompressor(CFX_BmpContext* context);
@@ -94,4 +97,6 @@
RetainPtr<CFX_CodecMemory> input_buffer_;
};
+} // namespace fxcodec
+
#endif // CORE_FXCODEC_BMP_CFX_BMPDECOMPRESSOR_H_
diff --git a/core/fxcodec/fx_codec.cpp b/core/fxcodec/fx_codec.cpp
index 65f3c47..567f8c3 100644
--- a/core/fxcodec/fx_codec.cpp
+++ b/core/fxcodec/fx_codec.cpp
@@ -75,6 +75,8 @@
}
#endif // PDF_ENABLE_XFA
+namespace fxcodec {
+
void ReverseRGB(uint8_t* pDestBuf, const uint8_t* pSrcBuf, int pixels) {
if (pDestBuf == pSrcBuf) {
for (int i = 0; i < pixels; i++) {
@@ -110,3 +112,5 @@
pitch *= 4; // and then back to bytes, (not just /8 in one step).
return pitch;
}
+
+} // namespace fxcodec
diff --git a/core/fxcodec/fx_codec.h b/core/fxcodec/fx_codec.h
index 32c2810..7b26a8e 100644
--- a/core/fxcodec/fx_codec.h
+++ b/core/fxcodec/fx_codec.h
@@ -121,9 +121,13 @@
#endif // PDF_ENABLE_XFA
};
+namespace fxcodec {
+
void ReverseRGB(uint8_t* pDestBuf, const uint8_t* pSrcBuf, int pixels);
FX_SAFE_UINT32 CalculatePitch8(uint32_t bpc, uint32_t components, int width);
FX_SAFE_UINT32 CalculatePitch32(int bpp, int width);
+} // namespace fxcodec
+
#endif // CORE_FXCODEC_FX_CODEC_H_