diff options
author | Mike Kaganski <mike.kaganski@collabora.com> | 2023-10-04 15:13:53 +0300 |
---|---|---|
committer | Mike Kaganski <mike.kaganski@collabora.com> | 2023-10-05 13:58:12 +0200 |
commit | d205274a014acabbed88b18d5058682a0ca46f9c (patch) | |
tree | 826c236b1104d262122f74d0277e0fff206ed273 /include | |
parent | 3c162a7a312022716e0648f95662b33577b5993d (diff) |
Drop MinMax in favor of std::clamp
Change-Id: I021f524b232ddbe091981444d859d35dd9cd05ac
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/157582
Tested-by: Jenkins
Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com>
Diffstat (limited to 'include')
-rw-r--r-- | include/tools/helpers.hxx | 47 | ||||
-rw-r--r-- | include/vcl/bitmap.hxx | 7 |
2 files changed, 6 insertions, 48 deletions
diff --git a/include/tools/helpers.hxx b/include/tools/helpers.hxx index 5f61ba80836c..05ee59960f50 100644 --- a/include/tools/helpers.hxx +++ b/include/tools/helpers.hxx @@ -15,53 +15,6 @@ #include <limits> #include <type_traits> -template<typename T> -inline -typename std::enable_if< - std::is_signed<T>::value || std::is_floating_point<T>::value, long >::type -MinMax(T nVal, tools::Long nMin, tools::Long nMax) -{ - assert(nMin <= nMax); - if (nVal >= nMin) - { - if (nVal <= nMax) - return static_cast<tools::Long>(nVal); - else - return nMax; - } - else - { - return nMin; - } -} - -template<typename T> -inline -typename std::enable_if< - std::is_unsigned<T>::value, long >::type -MinMax(T nVal, tools::Long nMin, tools::Long nMax) -{ - assert(nMin <= nMax); - if (nMax < 0) - { - return nMax; - } - else - { - if (nMin < 0 || nVal >= static_cast<unsigned long>(nMin)) - { - if (nVal <= static_cast<unsigned long>(nMax)) - return static_cast<tools::Long>(nVal); - else - return nMax; - } - else - { - return nMin; - } - } -} - inline sal_uInt32 AlignedWidth4Bytes(sal_uInt32 nWidthBits) { if (nWidthBits > SAL_MAX_UINT32 - 31) diff --git a/include/vcl/bitmap.hxx b/include/vcl/bitmap.hxx index 1c5f7bcc7ec6..b0a26700d6f5 100644 --- a/include/vcl/bitmap.hxx +++ b/include/vcl/bitmap.hxx @@ -21,6 +21,7 @@ #define INCLUDED_VCL_BITMAP_HXX #include <tools/degree.hxx> +#include <tools/helpers.hxx> #include <vcl/checksum.hxx> #include <vcl/dllapi.h> #include <vcl/mapmod.hxx> @@ -30,9 +31,13 @@ #include <o3tl/typed_flags_set.hxx> +#include <algorithm> #include <memory> -#define GAMMA( _def_cVal, _def_InvGamma ) (static_cast<sal_uInt8>(MinMax(FRound(pow( _def_cVal/255.0,_def_InvGamma)*255.0),0,255))) +inline sal_uInt8 GAMMA(double _def_cVal, double _def_InvGamma) +{ + return FRound(std::clamp(pow(_def_cVal / 255.0, _def_InvGamma) * 255.0, 0.0, 255.0)); +} class Color; |