Nest PixelWeight in CStretchEngine
Also remove "C" from CWeightTable since it is a nested class and
doesn't need the "C" to avoid collisions, etc.
Change-Id: I5758b6cd96304f780a6e8f6e5bb5a200d110a5a3
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/82151
Commit-Queue: Tom Sepez <tsepez@chromium.org>
Reviewed-by: Lei Zhang <thestig@chromium.org>
diff --git a/core/fxcodec/progressive_decoder.h b/core/fxcodec/progressive_decoder.h
index d8b4b78..8a862d9 100644
--- a/core/fxcodec/progressive_decoder.h
+++ b/core/fxcodec/progressive_decoder.h
@@ -121,7 +121,8 @@
#endif // PDF_ENABLE_XFA_BMP
private:
- using WeightTable = CStretchEngine::CWeightTable;
+ using WeightTable = CStretchEngine::WeightTable;
+ using PixelWeight = CStretchEngine::PixelWeight;
class HorzTable {
public:
diff --git a/core/fxge/dib/cstretchengine.cpp b/core/fxge/dib/cstretchengine.cpp
index 4465d3a..537acd3 100644
--- a/core/fxge/dib/cstretchengine.cpp
+++ b/core/fxge/dib/cstretchengine.cpp
@@ -20,7 +20,7 @@
#include "third_party/base/stl_util.h"
static_assert(
- std::is_trivially_destructible<PixelWeight>::value,
+ std::is_trivially_destructible<CStretchEngine::PixelWeight>::value,
"PixelWeight storage may be re-used without invoking its destructor");
namespace {
@@ -43,7 +43,8 @@
} // namespace
// static
-size_t PixelWeight::TotalBytesForWeightCount(size_t weight_count) {
+size_t CStretchEngine::PixelWeight::TotalBytesForWeightCount(
+ size_t weight_count) {
const size_t extra_weights = weight_count > 0 ? weight_count - 1 : 0;
FX_SAFE_SIZE_T total_bytes = extra_weights;
total_bytes *= sizeof(m_Weights[0]);
@@ -51,11 +52,11 @@
return total_bytes.ValueOrDie();
}
-CStretchEngine::CWeightTable::CWeightTable() = default;
+CStretchEngine::WeightTable::WeightTable() = default;
-CStretchEngine::CWeightTable::~CWeightTable() = default;
+CStretchEngine::WeightTable::~WeightTable() = default;
-bool CStretchEngine::CWeightTable::CalculateWeights(
+bool CStretchEngine::WeightTable::CalculateWeights(
int dest_len,
int dest_min,
int dest_max,
@@ -150,7 +151,7 @@
return true;
}
-const PixelWeight* CStretchEngine::CWeightTable::GetPixelWeight(
+const CStretchEngine::PixelWeight* CStretchEngine::WeightTable::GetPixelWeight(
int pixel) const {
DCHECK(pixel >= m_DestMin);
return reinterpret_cast<const PixelWeight*>(
@@ -457,7 +458,7 @@
if (m_DestHeight == 0)
return;
- CWeightTable table;
+ WeightTable table;
if (!table.CalculateWeights(m_DestHeight, m_DestClip.top, m_DestClip.bottom,
m_SrcHeight, m_SrcClip.top, m_SrcClip.bottom,
m_ResampleOptions)) {
diff --git a/core/fxge/dib/cstretchengine.h b/core/fxge/dib/cstretchengine.h
index 8a2901a..8d047eb 100644
--- a/core/fxge/dib/cstretchengine.h
+++ b/core/fxge/dib/cstretchengine.h
@@ -21,39 +21,67 @@
class PauseIndicatorIface;
class ScanlineComposerIface;
-struct PixelWeight {
- static size_t TotalBytesForWeightCount(size_t weight_count);
-
- void SetStartEnd(int src_start, int src_end, size_t weight_count) {
- CHECK_LT(static_cast<size_t>(src_end - src_start), weight_count);
- m_SrcStart = src_start;
- m_SrcEnd = src_end;
- }
-
- uint32_t GetWeightForPosition(int position) const {
- CHECK_GE(position, m_SrcStart);
- CHECK_LE(position, m_SrcEnd);
- return m_Weights[position - m_SrcStart];
- }
-
- void SetWeightForPosition(int position, uint32_t weight) {
- CHECK_GE(position, m_SrcStart);
- CHECK_LE(position, m_SrcEnd);
- m_Weights[position - m_SrcStart] = weight;
- }
-
- void RemoveLastWeight() {
- CHECK_GT(m_SrcEnd, m_SrcStart);
- --m_SrcEnd;
- }
-
- int m_SrcStart;
- int m_SrcEnd; // Note: inclusive.
- uint32_t m_Weights[1]; // Not really 1, variable size.
-};
-
class CStretchEngine {
public:
+ struct PixelWeight {
+ static size_t TotalBytesForWeightCount(size_t weight_count);
+
+ void SetStartEnd(int src_start, int src_end, size_t weight_count) {
+ CHECK_LT(static_cast<size_t>(src_end - src_start), weight_count);
+ m_SrcStart = src_start;
+ m_SrcEnd = src_end;
+ }
+
+ uint32_t GetWeightForPosition(int position) const {
+ CHECK_GE(position, m_SrcStart);
+ CHECK_LE(position, m_SrcEnd);
+ return m_Weights[position - m_SrcStart];
+ }
+
+ void SetWeightForPosition(int position, uint32_t weight) {
+ CHECK_GE(position, m_SrcStart);
+ CHECK_LE(position, m_SrcEnd);
+ m_Weights[position - m_SrcStart] = weight;
+ }
+
+ void RemoveLastWeight() {
+ CHECK_GT(m_SrcEnd, m_SrcStart);
+ --m_SrcEnd;
+ }
+
+ int m_SrcStart;
+ int m_SrcEnd; // Note: inclusive.
+ uint32_t m_Weights[1]; // Not really 1, variable size.
+ };
+
+ class WeightTable {
+ public:
+ WeightTable();
+ ~WeightTable();
+
+ // Accepts a negative `dest_len` argument, producing a "mirror
+ // image" of the result if `dest_len` is negative.
+ bool CalculateWeights(int dest_len,
+ int dest_min,
+ int dest_max,
+ int src_len,
+ int src_min,
+ int src_max,
+ const FXDIB_ResampleOptions& options);
+
+ const PixelWeight* GetPixelWeight(int pixel) const;
+ PixelWeight* GetPixelWeight(int pixel) {
+ return const_cast<PixelWeight*>(
+ static_cast<const WeightTable*>(this)->GetPixelWeight(pixel));
+ }
+
+ private:
+ int m_DestMin = 0;
+ size_t m_ItemSizeBytes = 0;
+ size_t m_WeightTablesSizeBytes = 0;
+ std::vector<uint8_t, FxAllocAllocator<uint8_t>> m_WeightTables;
+ };
+
CStretchEngine(ScanlineComposerIface* pDestBitmap,
FXDIB_Format dest_format,
int dest_width,
@@ -72,34 +100,6 @@
return m_ResampleOptions;
}
- class CWeightTable {
- public:
- CWeightTable();
- ~CWeightTable();
-
- // Accepts a negative `dest_len` argument, producing a "mirror
- // image" of the result if `dest_len` is negative.
- bool CalculateWeights(int dest_len,
- int dest_min,
- int dest_max,
- int src_len,
- int src_min,
- int src_max,
- const FXDIB_ResampleOptions& options);
-
- const PixelWeight* GetPixelWeight(int pixel) const;
- PixelWeight* GetPixelWeight(int pixel) {
- return const_cast<PixelWeight*>(
- static_cast<const CWeightTable*>(this)->GetPixelWeight(pixel));
- }
-
- private:
- int m_DestMin = 0;
- size_t m_ItemSizeBytes = 0;
- size_t m_WeightTablesSizeBytes = 0;
- std::vector<uint8_t, FxAllocAllocator<uint8_t>> m_WeightTables;
- };
-
private:
enum class State : uint8_t { kInitial, kHorizontal, kVertical };
@@ -137,7 +137,7 @@
TransformMethod m_TransMethod;
State m_State = State::kInitial;
int m_CurRow;
- CWeightTable m_WeightTable;
+ WeightTable m_WeightTable;
};
#endif // CORE_FXGE_DIB_CSTRETCHENGINE_H_