summaryrefslogtreecommitdiff
path: root/core/fpdfapi
diff options
context:
space:
mode:
authorLei Zhang <thestig@chromium.org>2017-03-17 15:14:19 -0700
committerChromium commit bot <commit-bot@chromium.org>2017-03-17 22:54:26 +0000
commit85f019a8e7d33cbba368a6c6b75fd091269e14a1 (patch)
tree8dcf6fcd98309a48ebbd9e46cc8c0d23a57c0965 /core/fpdfapi
parent240fe6d79f234896a966ddce0b9a125776dc9171 (diff)
downloadpdfium-85f019a8e7d33cbba368a6c6b75fd091269e14a1.tar.xz
Add pdfium::clamp() as a placeholder for std::clamp().chromium/3046
Ue it to fix a typo as well. BUG=pdfium:634 Change-Id: I2d686242ffb841aedc2fae6a3cf7a00bea667404 Reviewed-on: https://pdfium-review.googlesource.com/3113 Commit-Queue: Lei Zhang <thestig@chromium.org> Reviewed-by: Tom Sepez <tsepez@chromium.org>
Diffstat (limited to 'core/fpdfapi')
-rw-r--r--core/fpdfapi/font/cpdf_cidfont.cpp9
-rw-r--r--core/fpdfapi/page/cpdf_allstates.cpp15
-rw-r--r--core/fpdfapi/page/cpdf_colorspace.cpp12
-rw-r--r--core/fpdfapi/page/fpdf_page_colors.cpp3
-rw-r--r--core/fpdfapi/page/fpdf_page_func.cpp24
-rw-r--r--core/fpdfapi/render/cpdf_imagerenderer.cpp7
6 files changed, 34 insertions, 36 deletions
diff --git a/core/fpdfapi/font/cpdf_cidfont.cpp b/core/fpdfapi/font/cpdf_cidfont.cpp
index 4c378f7598..217a6eaf2e 100644
--- a/core/fpdfapi/font/cpdf_cidfont.cpp
+++ b/core/fpdfapi/font/cpdf_cidfont.cpp
@@ -21,6 +21,7 @@
#include "core/fpdfapi/parser/cpdf_stream_acc.h"
#include "third_party/base/numerics/safe_math.h"
#include "third_party/base/ptr_util.h"
+#include "third_party/base/stl_util.h"
namespace {
@@ -450,10 +451,10 @@ FX_RECT CPDF_CIDFont::GetCharBBox(uint32_t charcode) {
if (!err) {
FXFT_BBox cbox;
FXFT_Glyph_Get_CBox(glyph, FXFT_GLYPH_BBOX_PIXELS, &cbox);
- cbox.xMin = std::min(std::max(cbox.xMin, kMinCBox), kMaxCBox);
- cbox.xMax = std::min(std::max(cbox.xMax, kMinCBox), kMaxCBox);
- cbox.yMin = std::min(std::max(cbox.yMin, kMinCBox), kMaxCBox);
- cbox.yMax = std::min(std::max(cbox.yMax, kMinCBox), kMaxCBox);
+ cbox.xMin = pdfium::clamp(cbox.xMin, kMinCBox, kMaxCBox);
+ cbox.xMax = pdfium::clamp(cbox.xMax, kMinCBox, kMaxCBox);
+ cbox.yMin = pdfium::clamp(cbox.yMin, kMinCBox, kMaxCBox);
+ cbox.yMax = pdfium::clamp(cbox.yMax, kMinCBox, kMaxCBox);
int pixel_size_x = ((FXFT_Face)face)->size->metrics.x_ppem;
int pixel_size_y = ((FXFT_Face)face)->size->metrics.y_ppem;
if (pixel_size_x == 0 || pixel_size_y == 0) {
diff --git a/core/fpdfapi/page/cpdf_allstates.cpp b/core/fpdfapi/page/cpdf_allstates.cpp
index a30696e8b7..c67d3152c0 100644
--- a/core/fpdfapi/page/cpdf_allstates.cpp
+++ b/core/fpdfapi/page/cpdf_allstates.cpp
@@ -14,14 +14,7 @@
#include "core/fpdfapi/parser/cpdf_array.h"
#include "core/fpdfapi/parser/cpdf_dictionary.h"
#include "core/fxge/cfx_graphstatedata.h"
-
-namespace {
-
-float ClipFloat(float f) {
- return std::max(0.0f, std::min(1.0f, f));
-}
-
-} // namespace
+#include "third_party/base/stl_util.h"
CPDF_AllStates::CPDF_AllStates()
: m_TextLeading(0), m_TextRise(0), m_TextHorzScale(1.0f) {}
@@ -117,10 +110,12 @@ void CPDF_AllStates::ProcessExtGS(CPDF_Dictionary* pGS,
}
break;
case FXBSTR_ID('C', 'A', 0, 0):
- m_GeneralState.SetStrokeAlpha(ClipFloat(pObject->GetNumber()));
+ m_GeneralState.SetStrokeAlpha(
+ pdfium::clamp(pObject->GetNumber(), 0.0f, 1.0f));
break;
case FXBSTR_ID('c', 'a', 0, 0):
- m_GeneralState.SetFillAlpha(ClipFloat(pObject->GetNumber()));
+ m_GeneralState.SetFillAlpha(
+ pdfium::clamp(pObject->GetNumber(), 0.0f, 1.0f));
break;
case FXBSTR_ID('O', 'P', 0, 0):
m_GeneralState.SetStrokeOP(!!pObject->GetInteger());
diff --git a/core/fpdfapi/page/cpdf_colorspace.cpp b/core/fpdfapi/page/cpdf_colorspace.cpp
index 1aaa1440a4..cc4afa55c9 100644
--- a/core/fpdfapi/page/cpdf_colorspace.cpp
+++ b/core/fpdfapi/page/cpdf_colorspace.cpp
@@ -24,6 +24,7 @@
#include "core/fxcodec/fx_codec.h"
#include "core/fxcrt/cfx_maybe_owned.h"
#include "core/fxcrt/fx_memory.h"
+#include "third_party/base/stl_util.h"
namespace {
@@ -227,7 +228,7 @@ class CPDF_DeviceNCS : public CPDF_ColorSpace {
};
float RGB_Conversion(float colorComponent) {
- colorComponent = std::min(std::max(colorComponent, 0.0f), 1.0f);
+ colorComponent = pdfium::clamp(colorComponent, 0.0f, 1.0f);
int scale = std::max(static_cast<int>(colorComponent * 1023), 0);
if (scale < 192)
return g_sRGBSamples1[scale] / 255.0f;
@@ -686,11 +687,12 @@ void CPDF_LabCS::GetDefaultValue(int iComponent,
*min = 0.0f;
*max = 100 * 1.0f;
*value = 0.0f;
- } else {
- *min = m_Ranges[iComponent * 2 - 2];
- *max = m_Ranges[iComponent * 2 - 1];
- *value = std::min(std::max(0.0f, *min), *max);
+ return;
}
+
+ *min = m_Ranges[iComponent * 2 - 2];
+ *max = m_Ranges[iComponent * 2 - 1];
+ *value = pdfium::clamp(0.0f, *min, *max);
}
bool CPDF_LabCS::v_Load(CPDF_Document* pDoc, CPDF_Array* pArray) {
diff --git a/core/fpdfapi/page/fpdf_page_colors.cpp b/core/fpdfapi/page/fpdf_page_colors.cpp
index e69620ea9a..adee5ff84b 100644
--- a/core/fpdfapi/page/fpdf_page_colors.cpp
+++ b/core/fpdfapi/page/fpdf_page_colors.cpp
@@ -18,11 +18,12 @@
#include "core/fpdfapi/parser/cpdf_stream_acc.h"
#include "core/fpdfapi/parser/cpdf_string.h"
#include "core/fxcodec/fx_codec.h"
+#include "third_party/base/stl_util.h"
namespace {
float NormalizeChannel(float fVal) {
- return std::min(std::max(fVal, 0.0f), 1.0f);
+ return pdfium::clamp(fVal, 0.0f, 1.0f);
}
bool DetectSRGB(const uint8_t* pData, uint32_t dwSize) {
diff --git a/core/fpdfapi/page/fpdf_page_func.cpp b/core/fpdfapi/page/fpdf_page_func.cpp
index 94695daca2..30f3b895d4 100644
--- a/core/fpdfapi/page/fpdf_page_func.cpp
+++ b/core/fpdfapi/page/fpdf_page_func.cpp
@@ -21,6 +21,7 @@
#include "core/fpdfapi/parser/cpdf_stream_acc.h"
#include "core/fxcrt/fx_safe_types.h"
#include "third_party/base/ptr_util.h"
+#include "third_party/base/stl_util.h"
namespace {
@@ -541,8 +542,8 @@ bool CPDF_SampledFunc::v_Call(float* inputs, float* results) const {
encoded_input[i] =
PDF_Interpolate(inputs[i], m_pDomains[i * 2], m_pDomains[i * 2 + 1],
m_EncodeInfo[i].encode_min, m_EncodeInfo[i].encode_max);
- index[i] = std::min((uint32_t)std::max(0.f, encoded_input[i]),
- m_EncodeInfo[i].sizes - 1);
+ index[i] = pdfium::clamp(static_cast<uint32_t>(encoded_input[i]), 0U,
+ m_EncodeInfo[i].sizes - 1);
pos += index[i] * blocksize[i];
}
FX_SAFE_INT32 bits_to_output = m_nOutputs;
@@ -816,19 +817,16 @@ bool CPDF_Function::Call(float* inputs,
*nresults = m_nOutputs;
for (uint32_t i = 0; i < m_nInputs; i++) {
- if (inputs[i] < m_pDomains[i * 2])
- inputs[i] = m_pDomains[i * 2];
- else if (inputs[i] > m_pDomains[i * 2 + 1])
- inputs[i] = m_pDomains[i * 2] + 1;
+ inputs[i] =
+ pdfium::clamp(inputs[i], m_pDomains[i * 2], m_pDomains[i * 2 + 1]);
}
v_Call(inputs, results);
- if (m_pRanges) {
- for (uint32_t i = 0; i < m_nOutputs; i++) {
- if (results[i] < m_pRanges[i * 2])
- results[i] = m_pRanges[i * 2];
- else if (results[i] > m_pRanges[i * 2 + 1])
- results[i] = m_pRanges[i * 2 + 1];
- }
+ if (!m_pRanges)
+ return true;
+
+ for (uint32_t i = 0; i < m_nOutputs; i++) {
+ results[i] =
+ pdfium::clamp(results[i], m_pRanges[i * 2], m_pRanges[i * 2 + 1]);
}
return true;
}
diff --git a/core/fpdfapi/render/cpdf_imagerenderer.cpp b/core/fpdfapi/render/cpdf_imagerenderer.cpp
index 7903ad4a62..d3778452a3 100644
--- a/core/fpdfapi/render/cpdf_imagerenderer.cpp
+++ b/core/fpdfapi/render/cpdf_imagerenderer.cpp
@@ -30,6 +30,7 @@
#include "core/fxge/cfx_fxgedevice.h"
#include "core/fxge/cfx_pathdata.h"
#include "third_party/base/ptr_util.h"
+#include "third_party/base/stl_util.h"
#ifdef _SKIA_SUPPORT_
#include "core/fxge/skia/fx_skia_device.h"
@@ -273,11 +274,11 @@ void CPDF_ImageRenderer::CalculateDrawImage(CFX_FxgeDevice* pBitmapDevice1,
continue;
}
int orig = (*dest_scan - matte_b) * 255 / alpha + matte_b;
- *dest_scan++ = std::min(std::max(orig, 0), 255);
+ *dest_scan++ = pdfium::clamp(orig, 0, 255);
orig = (*dest_scan - matte_g) * 255 / alpha + matte_g;
- *dest_scan++ = std::min(std::max(orig, 0), 255);
+ *dest_scan++ = pdfium::clamp(orig, 0, 255);
orig = (*dest_scan - matte_r) * 255 / alpha + matte_r;
- *dest_scan++ = std::min(std::max(orig, 0), 255);
+ *dest_scan++ = pdfium::clamp(orig, 0, 255);
dest_scan++;
}
}