Rename some colorspace methods
- Change CountInputs() to InputCount()
- Change CountOutputs() to OutputCount()
- Change CountComponents() to ComponentCount()
Also switch a few DCHECK() calls to CHECK_OP() along the way.
Change-Id: Icd360db9d3739713c86291ba1e54ebcf7a39d356
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/117110
Reviewed-by: Tom Sepez <tsepez@chromium.org>
Reviewed-by: Thomas Sepez <tsepez@google.com>
Commit-Queue: Lei Zhang <thestig@chromium.org>
diff --git a/core/fpdfapi/page/cpdf_color.cpp b/core/fpdfapi/page/cpdf_color.cpp
index 86c5cf1..9ab04b1 100644
--- a/core/fpdfapi/page/cpdf_color.cpp
+++ b/core/fpdfapi/page/cpdf_color.cpp
@@ -10,6 +10,7 @@
#include "core/fpdfapi/page/cpdf_patterncs.h"
#include "core/fxcrt/check.h"
+#include "core/fxcrt/check_op.h"
CPDF_Color::CPDF_Color() = default;
@@ -39,8 +40,8 @@
}
void CPDF_Color::SetValueForNonPattern(std::vector<float> values) {
- DCHECK(!IsPatternInternal());
- DCHECK(m_pCS->CountComponents() <= values.size());
+ CHECK(!IsPatternInternal());
+ CHECK_LE(m_pCS->ComponentCount(), values.size());
m_Buffer = std::move(values);
}
@@ -68,8 +69,8 @@
return *this;
}
-uint32_t CPDF_Color::CountComponents() const {
- return m_pCS->CountComponents();
+uint32_t CPDF_Color::ComponentCount() const {
+ return m_pCS->ComponentCount();
}
bool CPDF_Color::IsColorSpaceRGB() const {
diff --git a/core/fpdfapi/page/cpdf_color.h b/core/fpdfapi/page/cpdf_color.h
index 3bb358a..1a745e8 100644
--- a/core/fpdfapi/page/cpdf_color.h
+++ b/core/fpdfapi/page/cpdf_color.h
@@ -35,7 +35,7 @@
void SetValueForPattern(RetainPtr<CPDF_Pattern> pattern,
pdfium::span<float> values);
- uint32_t CountComponents() const;
+ uint32_t ComponentCount() const;
bool IsColorSpaceRGB() const;
bool GetRGB(int* R, int* G, int* B) const;
diff --git a/core/fpdfapi/page/cpdf_colorspace.cpp b/core/fpdfapi/page/cpdf_colorspace.cpp
index 40b06ee..6468ae0 100644
--- a/core/fpdfapi/page/cpdf_colorspace.cpp
+++ b/core/fpdfapi/page/cpdf_colorspace.cpp
@@ -615,7 +615,7 @@
return buf;
}
-uint32_t CPDF_ColorSpace::CountComponents() const {
+uint32_t CPDF_ColorSpace::ComponentCount() const {
return m_nComponents;
}
@@ -982,7 +982,7 @@
}
if (profile_->IsSupported()) {
float rgb[3];
- profile_->Translate(pBuf.first(CountComponents()), rgb);
+ profile_->Translate(pBuf.first(ComponentCount()), rgb);
*R = rgb[0];
*G = rgb[1];
*B = rgb[2];
@@ -1016,7 +1016,7 @@
}
// |nMaxColors| will not overflow since |nComponents| is limited in size.
- const uint32_t nComponents = CountComponents();
+ const uint32_t nComponents = ComponentCount();
DCHECK(fxcodec::IccTransform::IsValidIccComponents(nComponents));
int nMaxColors = 1;
for (uint32_t i = 0; i < nComponents; i++)
@@ -1094,8 +1094,9 @@
if (pAlterCS->GetFamily() == Family::kPattern)
return false;
- if (pAlterCS->CountComponents() != nExpectedComponents)
+ if (pAlterCS->ComponentCount() != nExpectedComponents) {
return false;
+ }
m_pBaseCS = std::move(pAlterCS);
return true;
@@ -1164,8 +1165,9 @@
RetainPtr<const CPDF_Object> pFuncObj = pArray->GetDirectObjectAt(3);
if (pFuncObj && !pFuncObj->IsName()) {
auto pFunc = CPDF_Function::Load(std::move(pFuncObj));
- if (pFunc && pFunc->CountOutputs() >= m_pBaseCS->CountComponents())
+ if (pFunc && pFunc->OutputCount() >= m_pBaseCS->ComponentCount()) {
m_pFunc = std::move(pFunc);
+ }
}
return 1;
}
@@ -1181,7 +1183,7 @@
if (!m_pBaseCS)
return false;
- int nComps = m_pBaseCS->CountComponents();
+ int nComps = m_pBaseCS->ComponentCount();
std::vector<float> results(nComps);
for (int i = 0; i < nComps; i++)
results[i] = pBuf[0];
@@ -1189,7 +1191,7 @@
}
// Using at least 16 elements due to the call m_pAltCS->GetRGB() below.
- std::vector<float> results(std::max(m_pFunc->CountOutputs(), 16u));
+ std::vector<float> results(std::max(m_pFunc->OutputCount(), 16u));
uint32_t nresults = m_pFunc->Call(pBuf.first(1), results).value_or(0);
if (nresults == 0)
return false;
@@ -1235,8 +1237,9 @@
if (m_pBaseCS->IsSpecial())
return 0;
- if (m_pFunc->CountOutputs() < m_pBaseCS->CountComponents())
+ if (m_pFunc->OutputCount() < m_pBaseCS->ComponentCount()) {
return 0;
+ }
return fxcrt::CollectionSize<uint32_t>(*pObj);
}
@@ -1249,9 +1252,9 @@
return false;
// Using at least 16 elements due to the call m_pAltCS->GetRGB() below.
- std::vector<float> results(std::max(m_pFunc->CountOutputs(), 16u));
+ std::vector<float> results(std::max(m_pFunc->OutputCount(), 16u));
uint32_t nresults =
- m_pFunc->Call(pBuf.first(CountComponents()), pdfium::make_span(results))
+ m_pFunc->Call(pBuf.first(ComponentCount()), pdfium::make_span(results))
.value_or(0);
if (nresults == 0)
diff --git a/core/fpdfapi/page/cpdf_colorspace.h b/core/fpdfapi/page/cpdf_colorspace.h
index cd73fef..e6a10dd 100644
--- a/core/fpdfapi/page/cpdf_colorspace.h
+++ b/core/fpdfapi/page/cpdf_colorspace.h
@@ -93,7 +93,7 @@
// Should only be called if this colorspace is not a pattern.
std::vector<float> CreateBufAndSetDefaultColor() const;
- uint32_t CountComponents() const;
+ uint32_t ComponentCount() const;
Family GetFamily() const { return m_Family; }
bool IsSpecial() const {
return GetFamily() == Family::kSeparation ||
diff --git a/core/fpdfapi/page/cpdf_colorstate.cpp b/core/fpdfapi/page/cpdf_colorstate.cpp
index cc0217f..0ab0e27 100644
--- a/core/fpdfapi/page/cpdf_colorstate.cpp
+++ b/core/fpdfapi/page/cpdf_colorstate.cpp
@@ -117,8 +117,9 @@
color->SetColorSpace(
CPDF_ColorSpace::GetStockCS(CPDF_ColorSpace::Family::kDeviceGray));
}
- if (color->CountComponents() > values.size())
+ if (color->ComponentCount() > values.size()) {
return;
+ }
if (!color->IsPattern())
color->SetValueForNonPattern(std::move(values));
diff --git a/core/fpdfapi/page/cpdf_dib.cpp b/core/fpdfapi/page/cpdf_dib.cpp
index f5d665a..91002d8 100644
--- a/core/fpdfapi/page/cpdf_dib.cpp
+++ b/core/fpdfapi/page/cpdf_dib.cpp
@@ -426,7 +426,7 @@
// |m_nComponents| does not get reached, then a decoder can try to set
// |m_nComponents| based on the number of channels in the image being
// decoded.
- m_nComponents = m_pColorSpace->CountComponents();
+ m_nComponents = m_pColorSpace->ComponentCount();
m_Family = m_pColorSpace->GetFamily();
if (m_Family == CPDF_ColorSpace::Family::kICCBased && pCSObj->IsName()) {
ByteString cs = pCSObj->GetString();
@@ -588,7 +588,7 @@
m_nComponents = static_cast<uint32_t>(info.num_components);
m_CompData.clear();
if (m_pColorSpace) {
- uint32_t colorspace_comps = m_pColorSpace->CountComponents();
+ uint32_t colorspace_comps = m_pColorSpace->ComponentCount();
switch (m_Family) {
case CPDF_ColorSpace::Family::kDeviceGray:
case CPDF_ColorSpace::Family::kDeviceRGB:
@@ -843,7 +843,7 @@
if (pMatte && m_pColorSpace &&
m_Family != CPDF_ColorSpace::Family::kPattern &&
pMatte->size() == m_nComponents &&
- m_pColorSpace->CountComponents() <= m_nComponents) {
+ m_pColorSpace->ComponentCount() <= m_nComponents) {
std::vector<float> colors =
ReadArrayElementsToVector(pMatte.Get(), m_nComponents);
@@ -919,7 +919,7 @@
m_Family == CPDF_ColorSpace::Family::kDeviceRGB)) {
return;
}
- if (m_pColorSpace->CountComponents() > 3) {
+ if (m_pColorSpace->ComponentCount() > 3) {
return;
}
float color_values[3];
@@ -976,8 +976,8 @@
float G = 0;
float B = 0;
if (m_nComponents == 1 && m_Family == CPDF_ColorSpace::Family::kICCBased &&
- m_pColorSpace->CountComponents() > 1) {
- int nComponents = m_pColorSpace->CountComponents();
+ m_pColorSpace->ComponentCount() > 1) {
+ int nComponents = m_pColorSpace->ComponentCount();
std::vector<float> temp_buf(nComponents);
for (int k = 0; k < nComponents; ++k)
temp_buf[k] = color_values[0];
@@ -1076,7 +1076,7 @@
if (m_bpc != 8)
return false;
- if (m_nComponents == m_pColorSpace->CountComponents()) {
+ if (m_nComponents == m_pColorSpace->ComponentCount()) {
m_pColorSpace->TranslateImageLine(dest_scan, src_scan, m_Width, m_Width,
m_Height, TransMask());
}
diff --git a/core/fpdfapi/page/cpdf_function.h b/core/fpdfapi/page/cpdf_function.h
index e7fda22..58bca25 100644
--- a/core/fpdfapi/page/cpdf_function.h
+++ b/core/fpdfapi/page/cpdf_function.h
@@ -38,8 +38,8 @@
std::optional<uint32_t> Call(pdfium::span<const float> inputs,
pdfium::span<float> results) const;
- uint32_t CountInputs() const { return m_nInputs; }
- uint32_t CountOutputs() const { return m_nOutputs; }
+ uint32_t InputCount() const { return m_nInputs; }
+ uint32_t OutputCount() const { return m_nOutputs; }
float GetDomain(int i) const { return m_Domains[i]; }
float GetRange(int i) const { return m_Ranges[i]; }
float Interpolate(float x,
diff --git a/core/fpdfapi/page/cpdf_indexedcs.cpp b/core/fpdfapi/page/cpdf_indexedcs.cpp
index a52f48a..1c0b77b 100644
--- a/core/fpdfapi/page/cpdf_indexedcs.cpp
+++ b/core/fpdfapi/page/cpdf_indexedcs.cpp
@@ -52,7 +52,7 @@
if (family == Family::kIndexed || family == Family::kPattern)
return 0;
- m_nBaseComponents = m_pBaseCS->CountComponents();
+ m_nBaseComponents = m_pBaseCS->ComponentCount();
DCHECK(m_nBaseComponents);
m_pCompMinMax = DataVector<float>(Fx2DSizeOrDie(m_nBaseComponents, 2));
float defvalue;
@@ -86,7 +86,7 @@
return false;
DCHECK(m_nBaseComponents);
- DCHECK_EQ(m_nBaseComponents, m_pBaseCS->CountComponents());
+ DCHECK_EQ(m_nBaseComponents, m_pBaseCS->ComponentCount());
FX_SAFE_SIZE_T length = index;
length += 1;
diff --git a/core/fpdfapi/page/cpdf_meshstream.cpp b/core/fpdfapi/page/cpdf_meshstream.cpp
index 26d0229..39ce012 100644
--- a/core/fpdfapi/page/cpdf_meshstream.cpp
+++ b/core/fpdfapi/page/cpdf_meshstream.cpp
@@ -128,7 +128,7 @@
if (ShouldCheckBitsPerFlag(m_type) && !IsValidBitsPerFlag(m_nFlagBits))
return false;
- uint32_t nComponents = m_pCS->CountComponents();
+ uint32_t nComponents = m_pCS->ComponentCount();
if (nComponents > kMaxComponents)
return false;
@@ -220,8 +220,9 @@
float result[kMaxComponents] = {};
for (const auto& func : m_funcs) {
- if (func && func->CountOutputs() <= kMaxComponents)
+ if (func && func->OutputCount() <= kMaxComponents) {
func->Call(pdfium::make_span(color_value, 1u), result);
+ }
}
m_pCS->GetRGB(result, &r, &g, &b);
diff --git a/core/fpdfapi/page/cpdf_patterncs.cpp b/core/fpdfapi/page/cpdf_patterncs.cpp
index 96e9960..462bf67 100644
--- a/core/fpdfapi/page/cpdf_patterncs.cpp
+++ b/core/fpdfapi/page/cpdf_patterncs.cpp
@@ -35,10 +35,11 @@
if (m_pBaseCS->GetFamily() == Family::kPattern)
return 0;
- if (m_pBaseCS->CountComponents() > kMaxPatternColorComps)
+ if (m_pBaseCS->ComponentCount() > kMaxPatternColorComps) {
return 0;
+ }
- return m_pBaseCS->CountComponents() + 1;
+ return m_pBaseCS->ComponentCount() + 1;
}
bool CPDF_PatternCS::GetRGB(pdfium::span<const float> pBuf,
diff --git a/core/fpdfapi/page/cpdf_shadingpattern.cpp b/core/fpdfapi/page/cpdf_shadingpattern.cpp
index 113d184..4f7e3ba 100644
--- a/core/fpdfapi/page/cpdf_shadingpattern.cpp
+++ b/core/fpdfapi/page/cpdf_shadingpattern.cpp
@@ -124,7 +124,7 @@
}
}
- uint32_t nNumColorSpaceComponents = m_pCS->CountComponents();
+ uint32_t nNumColorSpaceComponents = m_pCS->ComponentCount();
switch (m_ShadingType) {
case kFunctionBasedShading: {
// Either one 2-to-N function or N 2-to-1 functions.
@@ -163,12 +163,12 @@
if (!function)
return false;
- if (function->CountInputs() != nExpectedNumInputs ||
- function->CountOutputs() != nExpectedNumOutputs) {
+ if (function->InputCount() != nExpectedNumInputs ||
+ function->OutputCount() != nExpectedNumOutputs) {
return false;
}
- nTotalOutputs += function->CountOutputs();
+ nTotalOutputs += function->OutputCount();
}
return nTotalOutputs.IsValid();
diff --git a/core/fpdfapi/page/cpdf_stitchfunc.cpp b/core/fpdfapi/page/cpdf_stitchfunc.cpp
index 61e04bb..ddce719 100644
--- a/core/fpdfapi/page/cpdf_stitchfunc.cpp
+++ b/core/fpdfapi/page/cpdf_stitchfunc.cpp
@@ -76,10 +76,11 @@
// Check that the input dimensionality is 1, and that all output
// dimensionalities are the same.
- if (pFunc->CountInputs() != kRequiredNumInputs)
+ if (pFunc->InputCount() != kRequiredNumInputs) {
return false;
+ }
- uint32_t nFuncOutputs = pFunc->CountOutputs();
+ uint32_t nFuncOutputs = pFunc->OutputCount();
if (nFuncOutputs == 0)
return false;
diff --git a/core/fpdfapi/page/cpdf_streamparser.cpp b/core/fpdfapi/page/cpdf_streamparser.cpp
index 952dc4c..4a067fc 100644
--- a/core/fpdfapi/page/cpdf_streamparser.cpp
+++ b/core/fpdfapi/page/cpdf_streamparser.cpp
@@ -162,7 +162,7 @@
if (pCSObj) {
RetainPtr<CPDF_ColorSpace> pCS =
CPDF_DocPageData::FromDocument(pDoc)->GetColorSpace(pCSObj, nullptr);
- nComponents = pCS ? pCS->CountComponents() : 3;
+ nComponents = pCS ? pCS->ComponentCount() : 3;
bpc = pDict->GetIntegerFor("BitsPerComponent");
}
std::optional<uint32_t> maybe_size =
diff --git a/core/fpdfapi/render/cpdf_docrenderdata.cpp b/core/fpdfapi/render/cpdf_docrenderdata.cpp
index 9f2591c..70c1993 100644
--- a/core/fpdfapi/render/cpdf_docrenderdata.cpp
+++ b/core/fpdfapi/render/cpdf_docrenderdata.cpp
@@ -111,7 +111,7 @@
for (size_t v = 0; v < CPDF_TransferFunc::kChannelSampleSize; ++v) {
float input = static_cast<float>(v) / 255.0f;
for (int i = 0; i < 3; ++i) {
- if (pFuncs[i]->CountOutputs() > kMaxOutputs) {
+ if (pFuncs[i]->OutputCount() > kMaxOutputs) {
samples[i][v] = v;
continue;
}
@@ -125,8 +125,9 @@
} else {
for (size_t v = 0; v < CPDF_TransferFunc::kChannelSampleSize; ++v) {
float input = static_cast<float>(v) / 255.0f;
- if (pFuncs[0]->CountOutputs() <= kMaxOutputs)
+ if (pFuncs[0]->OutputCount() <= kMaxOutputs) {
pFuncs[0]->Call(pdfium::span_from_ref(input), output);
+ }
size_t o = FXSYS_roundf(output[0] * 255);
if (o != v)
bIdentity = false;
diff --git a/core/fpdfapi/render/cpdf_rendershading.cpp b/core/fpdfapi/render/cpdf_rendershading.cpp
index c8489f1..d10409a 100644
--- a/core/fpdfapi/render/cpdf_rendershading.cpp
+++ b/core/fpdfapi/render/cpdf_rendershading.cpp
@@ -46,7 +46,7 @@
FX_SAFE_UINT32 total = 0;
for (const auto& func : funcs) {
if (func)
- total += func->CountOutputs();
+ total += func->OutputCount();
}
return total.ValueOrDefault(0);
}
@@ -55,7 +55,7 @@
const std::vector<std::unique_ptr<CPDF_Function>>& funcs,
const RetainPtr<CPDF_ColorSpace>& pCS) {
uint32_t funcs_outputs = CountOutputsFromFunctions(funcs);
- return funcs_outputs ? std::max(funcs_outputs, pCS->CountComponents()) : 0;
+ return funcs_outputs ? std::max(funcs_outputs, pCS->ComponentCount()) : 0;
}
std::array<FX_ARGB, kShadingSteps> GetShadingSteps(
@@ -65,8 +65,8 @@
const RetainPtr<CPDF_ColorSpace>& pCS,
int alpha,
size_t results_count) {
- DCHECK(results_count >= CountOutputsFromFunctions(funcs));
- DCHECK(results_count >= pCS->CountComponents());
+ CHECK_GE(results_count, CountOutputsFromFunctions(funcs));
+ CHECK_GE(results_count, pCS->ComponentCount());
std::array<FX_ARGB, kShadingSteps> shading_steps;
std::vector<float> result_array(results_count);
float diff = t_max - t_min;
@@ -285,8 +285,8 @@
int width = pBitmap->GetWidth();
int height = pBitmap->GetHeight();
- DCHECK(total_results >= CountOutputsFromFunctions(funcs));
- DCHECK(total_results >= pCS->CountComponents());
+ CHECK_GE(total_results, CountOutputsFromFunctions(funcs));
+ CHECK_GE(total_results, pCS->ComponentCount());
std::vector<float> result_array(total_results);
for (int row = 0; row < height; ++row) {
uint32_t* dib_buf =
@@ -893,9 +893,9 @@
pPattern->GetShadingObject()->GetDict();
if (!pPattern->IsShadingObject() && pDict->KeyExist("Background")) {
RetainPtr<const CPDF_Array> pBackColor = pDict->GetArrayFor("Background");
- if (pBackColor && pBackColor->size() >= pColorSpace->CountComponents()) {
+ if (pBackColor && pBackColor->size() >= pColorSpace->ComponentCount()) {
std::vector<float> comps = ReadArrayElementsToVector(
- pBackColor.Get(), pColorSpace->CountComponents());
+ pBackColor.Get(), pColorSpace->ComponentCount());
float R = 0.0f;
float G = 0.0f;
diff --git a/core/fpdfapi/render/cpdf_renderstatus.cpp b/core/fpdfapi/render/cpdf_renderstatus.cpp
index 2ff450e..0daefe3 100644
--- a/core/fpdfapi/render/cpdf_renderstatus.cpp
+++ b/core/fpdfapi/render/cpdf_renderstatus.cpp
@@ -1386,7 +1386,7 @@
const int src_pitch = bitmap->GetPitch();
DataVector<uint8_t> transfers(256);
if (pFunc) {
- std::vector<float> results(pFunc->CountOutputs());
+ std::vector<float> results(pFunc->OutputCount());
for (size_t i = 0; i < transfers.size(); ++i) {
float input = i / 255.0f;
pFunc->Call(pdfium::span_from_ref(input), results);
@@ -1449,7 +1449,7 @@
// Store Color Space Family to use in CPDF_RenderStatus::Initialize().
*pCSFamily = family;
- uint32_t comps = std::max(8u, pCS->CountComponents());
+ uint32_t comps = std::max(8u, pCS->ComponentCount());
size_t count = std::min<size_t>(8, pBC->size());
std::vector<float> floats = ReadArrayElementsToVector(pBC.Get(), count);
floats.resize(comps);
diff --git a/core/fxge/skia/fx_skia_device.cpp b/core/fxge/skia/fx_skia_device.cpp
index 0b981c5..7b252de 100644
--- a/core/fxge/skia/fx_skia_device.cpp
+++ b/core/fxge/skia/fx_skia_device.cpp
@@ -282,7 +282,7 @@
bool AddColors(const CPDF_ExpIntFunc* func,
DataVector<SkColor>& colors,
bool is_encode_reversed) {
- if (func->CountInputs() != 1) {
+ if (func->InputCount() != 1) {
return false;
}
if (func->GetExponent() != 1) {
@@ -316,10 +316,10 @@
bool AddSamples(const CPDF_SampledFunc* func,
DataVector<SkColor>& colors,
DataVector<SkScalar>& pos) {
- if (func->CountInputs() != 1) {
+ if (func->InputCount() != 1) {
return false;
}
- if (func->CountOutputs() != 3) { // expect rgb
+ if (func->OutputCount() != 3) { // expect rgb
return false;
}
if (func->GetEncodeInfo().empty()) {