diff options
author | Lei Zhang <thestig@chromium.org> | 2017-03-17 15:14:19 -0700 |
---|---|---|
committer | Chromium commit bot <commit-bot@chromium.org> | 2017-03-17 22:54:26 +0000 |
commit | 85f019a8e7d33cbba368a6c6b75fd091269e14a1 (patch) | |
tree | 8dcf6fcd98309a48ebbd9e46cc8c0d23a57c0965 /core/fpdfapi/page/fpdf_page_func.cpp | |
parent | 240fe6d79f234896a966ddce0b9a125776dc9171 (diff) | |
download | pdfium-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/page/fpdf_page_func.cpp')
-rw-r--r-- | core/fpdfapi/page/fpdf_page_func.cpp | 24 |
1 files changed, 11 insertions, 13 deletions
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; } |