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 | |
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>
-rw-r--r-- | include/tools/helpers.hxx | 47 | ||||
-rw-r--r-- | include/vcl/bitmap.hxx | 7 | ||||
-rw-r--r-- | tools/CppunitTest_tools_test.mk | 1 | ||||
-rw-r--r-- | tools/qa/cppunit/test_minmax.cxx | 98 | ||||
-rw-r--r-- | tools/source/generic/poly.cxx | 8 | ||||
-rw-r--r-- | vcl/source/bitmap/BitmapColorizeFilter.cxx | 6 | ||||
-rw-r--r-- | vcl/source/bitmap/BitmapConvolutionMatrixFilter.cxx | 9 | ||||
-rw-r--r-- | vcl/source/bitmap/BitmapGaussianSeparableBlurFilter.cxx | 7 | ||||
-rw-r--r-- | vcl/source/bitmap/BitmapInterpolateScaleFilter.cxx | 6 | ||||
-rw-r--r-- | vcl/source/bitmap/BitmapScaleConvolutionFilter.cxx | 14 | ||||
-rw-r--r-- | vcl/source/bitmap/BitmapScaleSuperFilter.cxx | 2 | ||||
-rw-r--r-- | vcl/source/bitmap/BitmapSeparableUnsharpenFilter.cxx | 15 | ||||
-rw-r--r-- | vcl/source/bitmap/bitmap.cxx | 20 | ||||
-rw-r--r-- | vcl/source/bitmap/bitmappaint.cxx | 36 | ||||
-rw-r--r-- | vcl/source/filter/ipsd/ipsd.cxx | 6 | ||||
-rw-r--r-- | vcl/source/gdi/gdimtf.cxx | 20 | ||||
-rw-r--r-- | vcl/source/outdev/bitmap.cxx | 2 | ||||
-rw-r--r-- | vcl/source/outdev/transparent.cxx | 2 |
18 files changed, 86 insertions, 220 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; diff --git a/tools/CppunitTest_tools_test.mk b/tools/CppunitTest_tools_test.mk index d27f8c3efa58..1063b778ab0a 100644 --- a/tools/CppunitTest_tools_test.mk +++ b/tools/CppunitTest_tools_test.mk @@ -28,7 +28,6 @@ $(eval $(call gb_CppunitTest_add_exception_objects,tools_test, \ tools/qa/cppunit/test_urlobj \ tools/qa/cppunit/test_color \ tools/qa/cppunit/test_rectangle \ - tools/qa/cppunit/test_minmax \ tools/qa/cppunit/test_100mm2twips \ tools/qa/cppunit/test_fround \ tools/qa/cppunit/test_xmlwalker \ diff --git a/tools/qa/cppunit/test_minmax.cxx b/tools/qa/cppunit/test_minmax.cxx deleted file mode 100644 index 509499910216..000000000000 --- a/tools/qa/cppunit/test_minmax.cxx +++ /dev/null @@ -1,98 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* - * This file is part of the LibreOffice project. - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. - * - * This file incorporates work covered by the following license notice: - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed - * with this work for additional information regarding copyright - * ownership. The ASF licenses this file to you under the Apache - * License, Version 2.0 (the "License"); you may not use this file - * except in compliance with the License. You may obtain a copy of - * the License at http://www.apache.org/licenses/LICENSE-2.0 . - */ - -#include <sal/types.h> -#include <cppunit/TestFixture.h> -#include <cppunit/extensions/HelperMacros.h> - -#include <tools/helpers.hxx> - -namespace tools -{ -class MinMaxTest : public CppUnit::TestFixture -{ -public: - void testSignedMinMax() - { - sal_Int32 nSignedVal = -10; - tools::Long nMin = 1; - tools::Long nMax = 10; - CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(nMin), - static_cast<sal_Int32>(MinMax(nSignedVal, nMin, nMax))); - - nSignedVal = -10; - nMin = -15; - nMax = 10; - CPPUNIT_ASSERT_EQUAL(nSignedVal, static_cast<sal_Int32>(MinMax(nSignedVal, nMin, nMax))); - - nSignedVal = -15; - nMin = -15; - nMax = 10; - CPPUNIT_ASSERT_EQUAL(nSignedVal, static_cast<sal_Int32>(MinMax(nSignedVal, nMin, nMax))); - } - - void testUnsignedMinMax() - { - sal_uInt32 nUnsignedVal = 5; - tools::Long nMin = 1; - tools::Long nMax = 10; - CPPUNIT_ASSERT_EQUAL(nUnsignedVal, - static_cast<sal_uInt32>(MinMax(nUnsignedVal, nMin, nMax))); - - nUnsignedVal = 5; - nMin = 1; - nMax = 5; - CPPUNIT_ASSERT_EQUAL(nUnsignedVal, - static_cast<sal_uInt32>(MinMax(nUnsignedVal, nMin, nMax))); - - nUnsignedVal = 5; - nMin = 5; - nMax = 5; - CPPUNIT_ASSERT_EQUAL(nUnsignedVal, - static_cast<sal_uInt32>(MinMax(nUnsignedVal, nMin, nMax))); - - nUnsignedVal = 10; - nMin = -20; - nMax = 15; - CPPUNIT_ASSERT_EQUAL(nUnsignedVal, - static_cast<sal_uInt32>(MinMax(nUnsignedVal, nMin, nMax))); - - nUnsignedVal = 20; - nMin = 10; - nMax = 15; - CPPUNIT_ASSERT_EQUAL(static_cast<sal_uInt32>(nMax), - static_cast<sal_uInt32>(MinMax(nUnsignedVal, nMin, nMax))); - - nUnsignedVal = 5; - nMin = 10; - nMax = 15; // irrelevant, but cannot be less than nMin - CPPUNIT_ASSERT_EQUAL(static_cast<sal_uInt32>(nMin), - static_cast<sal_uInt32>(MinMax(nUnsignedVal, nMin, nMax))); - } - - CPPUNIT_TEST_SUITE(MinMaxTest); - CPPUNIT_TEST(testSignedMinMax); - CPPUNIT_TEST(testUnsignedMinMax); - CPPUNIT_TEST_SUITE_END(); -}; - -CPPUNIT_TEST_SUITE_REGISTRATION(MinMaxTest); -} // namespace tools - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/tools/source/generic/poly.cxx b/tools/source/generic/poly.cxx index efd04b9b3e3d..89405eea410a 100644 --- a/tools/source/generic/poly.cxx +++ b/tools/source/generic/poly.cxx @@ -178,10 +178,10 @@ ImplPolygon::ImplPolygon( const Point& rCenter, tools::Long nRadX, tools::Long n const bool bOverflow = o3tl::checked_multiply(nRadX, nRadY, nRadXY); if (!bOverflow) { - nPoints = static_cast<sal_uInt16>(MinMax( + nPoints = std::clamp( ( M_PI * ( 1.5 * ( nRadX + nRadY ) - sqrt( static_cast<double>(std::abs(nRadXY)) ) ) ), - 32, 256 )); + 32.0, 256.0 ); } else { @@ -244,10 +244,10 @@ ImplPolygon::ImplPolygon(const tools::Rectangle& rBound, const Point& rStart, co const bool bOverflow = o3tl::checked_multiply(nRadX, nRadY, nRadXY); if (!bOverflow) { - nPoints = static_cast<sal_uInt16>(MinMax( + nPoints = std::clamp( ( M_PI * ( 1.5 * ( nRadX + nRadY ) - sqrt( static_cast<double>(std::abs(nRadXY)) ) ) ), - 32, 256 )); + 32.0, 256.0 ); } else { diff --git a/vcl/source/bitmap/BitmapColorizeFilter.cxx b/vcl/source/bitmap/BitmapColorizeFilter.cxx index 5f58f6147986..b006ddcdc1c0 100644 --- a/vcl/source/bitmap/BitmapColorizeFilter.cxx +++ b/vcl/source/bitmap/BitmapColorizeFilter.cxx @@ -37,9 +37,9 @@ BitmapEx BitmapColorizeFilter::execute(BitmapEx const& rBitmapEx) const for (nX = 0; nX < 256; ++nX) { - aMapR[nX] = MinMax((nX + cR) / 2, 0, 255); - aMapG[nX] = MinMax((nX + cG) / 2, 0, 255); - aMapB[nX] = MinMax((nX + cB) / 2, 0, 255); + aMapR[nX] = std::clamp((nX + cR) / 2, sal_Int32(0), sal_Int32(255)); + aMapG[nX] = std::clamp((nX + cG) / 2, sal_Int32(0), sal_Int32(255)); + aMapB[nX] = std::clamp((nX + cB) / 2, sal_Int32(0), sal_Int32(255)); } if (pWriteAccess->HasPalette()) diff --git a/vcl/source/bitmap/BitmapConvolutionMatrixFilter.cxx b/vcl/source/bitmap/BitmapConvolutionMatrixFilter.cxx index 39b8cf4cc18d..dc6b7e1fee70 100644 --- a/vcl/source/bitmap/BitmapConvolutionMatrixFilter.cxx +++ b/vcl/source/bitmap/BitmapConvolutionMatrixFilter.cxx @@ -141,9 +141,12 @@ BitmapEx BitmapConvolutionMatrixFilter::execute(BitmapEx const& rBitmapEx) const // calculate destination color pWriteAcc->SetPixelOnData( pScanline, nX, - BitmapColor(static_cast<sal_uInt8>(MinMax(nSumR / nDivisor, 0, 255)), - static_cast<sal_uInt8>(MinMax(nSumG / nDivisor, 0, 255)), - static_cast<sal_uInt8>(MinMax(nSumB / nDivisor, 0, 255)))); + BitmapColor(static_cast<sal_uInt8>( + std::clamp(nSumR / nDivisor, sal_Int32(0), sal_Int32(255))), + static_cast<sal_uInt8>( + std::clamp(nSumG / nDivisor, sal_Int32(0), sal_Int32(255))), + static_cast<sal_uInt8>( + std::clamp(nSumB / nDivisor, sal_Int32(0), sal_Int32(255))))); } if (++nY < nHeight) diff --git a/vcl/source/bitmap/BitmapGaussianSeparableBlurFilter.cxx b/vcl/source/bitmap/BitmapGaussianSeparableBlurFilter.cxx index 85c790422140..0b3662e67ce8 100644 --- a/vcl/source/bitmap/BitmapGaussianSeparableBlurFilter.cxx +++ b/vcl/source/bitmap/BitmapGaussianSeparableBlurFilter.cxx @@ -124,9 +124,10 @@ bool BitmapGaussianSeparableBlurFilter::convolutionPass(const Bitmap& rBitmap, B aValueBlue += aWeight * aColor.GetBlue(); } - BitmapColor aResultColor(static_cast<sal_uInt8>(MinMax(aValueRed / aSum, 0, 255)), - static_cast<sal_uInt8>(MinMax(aValueGreen / aSum, 0, 255)), - static_cast<sal_uInt8>(MinMax(aValueBlue / aSum, 0, 255))); + BitmapColor aResultColor( + static_cast<sal_uInt8>(std::clamp(aValueRed / aSum, 0.0, 255.0)), + static_cast<sal_uInt8>(std::clamp(aValueGreen / aSum, 0.0, 255.0)), + static_cast<sal_uInt8>(std::clamp(aValueBlue / aSum, 0.0, 255.0))); int nDestX = nSourceY; int nDestY = nSourceX; diff --git a/vcl/source/bitmap/BitmapInterpolateScaleFilter.cxx b/vcl/source/bitmap/BitmapInterpolateScaleFilter.cxx index ce32f2512163..701c91298a80 100644 --- a/vcl/source/bitmap/BitmapInterpolateScaleFilter.cxx +++ b/vcl/source/bitmap/BitmapInterpolateScaleFilter.cxx @@ -82,7 +82,8 @@ BitmapEx BitmapInterpolateScaleFilter::execute(BitmapEx const& rBitmapEx) const for (sal_Int32 nX = 0, nTemp = nWidth - 2; nX < nNewWidth; nX++) { double fTemp = nX * fRevScaleX; - pLutInt[nX] = MinMax(static_cast<sal_Int32>(fTemp), 0, nTemp); + pLutInt[nX] + = std::clamp(static_cast<sal_Int32>(fTemp), sal_Int32(0), nTemp); fTemp -= pLutInt[nX]; pLutFrac[nX] = static_cast<sal_Int32>(fTemp * 1024.); } @@ -176,7 +177,8 @@ BitmapEx BitmapInterpolateScaleFilter::execute(BitmapEx const& rBitmapEx) const for (sal_Int32 nY = 0, nTemp = nHeight - 2; nY < nNewHeight; nY++) { double fTemp = nY * fRevScaleY; - pLutInt[nY] = MinMax(static_cast<sal_Int32>(fTemp), 0, nTemp); + pLutInt[nY] + = std::clamp(static_cast<sal_Int32>(fTemp), sal_Int32(0), nTemp); fTemp -= pLutInt[nY]; pLutFrac[nY] = static_cast<sal_Int32>(fTemp * 1024.); } diff --git a/vcl/source/bitmap/BitmapScaleConvolutionFilter.cxx b/vcl/source/bitmap/BitmapScaleConvolutionFilter.cxx index 6ee56d14a366..5bec5810cb5f 100644 --- a/vcl/source/bitmap/BitmapScaleConvolutionFilter.cxx +++ b/vcl/source/bitmap/BitmapScaleConvolutionFilter.cxx @@ -71,7 +71,7 @@ void ImplCalculateContributions( } // Handling on edges - const sal_Int32 aPixelIndex(MinMax(j, 0, aSourceSize - 1)); + const sal_Int32 aPixelIndex(std::clamp(j, sal_Int32(0), aSourceSize - 1)); const sal_Int32 nIndex(aIndex + aCurrentCount); // scale the weight by 255 since we're converting from float to int @@ -151,9 +151,9 @@ bool ImplScaleConvolutionHor(Bitmap& rSource, Bitmap& rTarget, const double& rSc assert(aSum != 0); const BitmapColor aResultColor( - static_cast< sal_uInt8 >(MinMax(static_cast< sal_Int32 >(aValueRed / aSum), 0, 255)), - static_cast< sal_uInt8 >(MinMax(static_cast< sal_Int32 >(aValueGreen / aSum), 0, 255)), - static_cast< sal_uInt8 >(MinMax(static_cast< sal_Int32 >(aValueBlue / aSum), 0, 255))); + static_cast< sal_uInt8 >(std::clamp< sal_Int32 >(aValueRed / aSum, 0, 255)), + static_cast< sal_uInt8 >(std::clamp< sal_Int32 >(aValueGreen / aSum, 0, 255)), + static_cast< sal_uInt8 >(std::clamp< sal_Int32 >(aValueBlue / aSum, 0, 255))); pWriteAcc->SetPixelOnData(pScanline, x, aResultColor); } @@ -233,9 +233,9 @@ bool ImplScaleConvolutionVer(Bitmap& rSource, Bitmap& rTarget, const double& rSc assert(aSum != 0); const BitmapColor aResultColor( - static_cast< sal_uInt8 >(MinMax(static_cast< sal_Int32 >(aValueRed / aSum), 0, 255)), - static_cast< sal_uInt8 >(MinMax(static_cast< sal_Int32 >(aValueGreen / aSum), 0, 255)), - static_cast< sal_uInt8 >(MinMax(static_cast< sal_Int32 >(aValueBlue / aSum), 0, 255))); + static_cast< sal_uInt8 >(std::clamp< sal_Int32 >(aValueRed / aSum, 0, 255)), + static_cast< sal_uInt8 >(std::clamp< sal_Int32 >(aValueGreen / aSum, 0, 255)), + static_cast< sal_uInt8 >(std::clamp< sal_Int32 >(aValueBlue / aSum, 0, 255))); if(pWriteAcc->HasPalette()) { diff --git a/vcl/source/bitmap/BitmapScaleSuperFilter.cxx b/vcl/source/bitmap/BitmapScaleSuperFilter.cxx index 59ed78c8d6f3..3389195aceec 100644 --- a/vcl/source/bitmap/BitmapScaleSuperFilter.cxx +++ b/vcl/source/bitmap/BitmapScaleSuperFilter.cxx @@ -100,7 +100,7 @@ struct ScaleContext double fTemp = i * fRevScale; if (bMirrored) fTemp = nTempX - fTemp; - rMapIX[i] = MinMax(sal_Int32(fTemp), 0, nTemp); + rMapIX[i] = std::clamp(sal_Int32(fTemp), sal_Int32(0), nTemp); rMapFX[i] = BilinearWeightType((fTemp - rMapIX[i]) * (BilinearWeightType(1) << MAP_PRECISION)); } } diff --git a/vcl/source/bitmap/BitmapSeparableUnsharpenFilter.cxx b/vcl/source/bitmap/BitmapSeparableUnsharpenFilter.cxx index bbf5950dc968..641725cb32d1 100644 --- a/vcl/source/bitmap/BitmapSeparableUnsharpenFilter.cxx +++ b/vcl/source/bitmap/BitmapSeparableUnsharpenFilter.cxx @@ -51,14 +51,15 @@ BitmapEx BitmapSeparableUnsharpenFilter::execute(BitmapEx const& rBitmapEx) cons aColor = pReadAcc->GetColor(y, x); BitmapColor aResultColor( - static_cast<sal_uInt8>(MinMax( - aColor.GetRed() + (aColor.GetRed() - aColorBlur.GetRed()) * aAmount, 0, 255)), - static_cast<sal_uInt8>(MinMax( - aColor.GetGreen() + (aColor.GetGreen() - aColorBlur.GetGreen()) * aAmount, 0, - 255)), static_cast<sal_uInt8>( - MinMax(aColor.GetBlue() + (aColor.GetBlue() - aColorBlur.GetBlue()) * aAmount, - 0, 255))); + std::clamp(aColor.GetRed() + (aColor.GetRed() - aColorBlur.GetRed()) * aAmount, + 0.0, 255.0)), + static_cast<sal_uInt8>(std::clamp( + aColor.GetGreen() + (aColor.GetGreen() - aColorBlur.GetGreen()) * aAmount, 0.0, + 255.0)), + static_cast<sal_uInt8>(std::clamp( + aColor.GetBlue() + (aColor.GetBlue() - aColorBlur.GetBlue()) * aAmount, 0.0, + 255.0))); pWriteAcc->SetPixelOnData(pScanline, x, aResultColor); } diff --git a/vcl/source/bitmap/bitmap.cxx b/vcl/source/bitmap/bitmap.cxx index 80bff80e05f4..917c59e7e3b7 100644 --- a/vcl/source/bitmap/bitmap.cxx +++ b/vcl/source/bitmap/bitmap.cxx @@ -1524,15 +1524,15 @@ bool Bitmap::Adjust( short nLuminancePercent, short nContrastPercent, // calculate slope if( nContrastPercent >= 0 ) - fM = 128.0 / ( 128.0 - 1.27 * MinMax( nContrastPercent, 0, 100 ) ); + fM = 128.0 / ( 128.0 - 1.27 * std::clamp( nContrastPercent, short(0), short(100) ) ); else - fM = ( 128.0 + 1.27 * MinMax( nContrastPercent, -100, 0 ) ) / 128.0; + fM = ( 128.0 + 1.27 * std::clamp( nContrastPercent, short(-100), short(0) ) ) / 128.0; if(!msoBrightness) // total offset = luminance offset + contrast offset - fOff = MinMax( nLuminancePercent, -100, 100 ) * 2.55 + 128.0 - fM * 128.0; + fOff = std::clamp( nLuminancePercent, short(-100), short(100) ) * 2.55 + 128.0 - fM * 128.0; else - fOff = MinMax( nLuminancePercent, -100, 100 ) * 2.55; + fOff = std::clamp( nLuminancePercent, short(-100), short(100) ) * 2.55; // channel offset = channel offset + total offset fROff = nChannelRPercent * 2.55 + fOff; @@ -1548,18 +1548,18 @@ bool Bitmap::Adjust( short nLuminancePercent, short nContrastPercent, { if(!msoBrightness) { - cMapR[ nX ] = static_cast<sal_uInt8>(MinMax( FRound( nX * fM + fROff ), 0, 255 )); - cMapG[ nX ] = static_cast<sal_uInt8>(MinMax( FRound( nX * fM + fGOff ), 0, 255 )); - cMapB[ nX ] = static_cast<sal_uInt8>(MinMax( FRound( nX * fM + fBOff ), 0, 255 )); + cMapR[ nX ] = FRound( std::clamp( nX * fM + fROff, 0.0, 255.0 ) ); + cMapG[ nX ] = FRound( std::clamp( nX * fM + fGOff, 0.0, 255.0 ) ); + cMapB[ nX ] = FRound( std::clamp( nX * fM + fBOff, 0.0, 255.0 ) ); } else { // LO simply uses (in a somewhat optimized form) "newcolor = (oldcolor-128)*contrast+brightness+128" // as the formula, i.e. contrast first, brightness afterwards. MSOffice, for whatever weird reason, // use neither first, but apparently it applies half of brightness before contrast and half afterwards. - cMapR[ nX ] = static_cast<sal_uInt8>(MinMax( FRound( (nX+fROff/2-128) * fM + 128 + fROff/2 ), 0, 255 )); - cMapG[ nX ] = static_cast<sal_uInt8>(MinMax( FRound( (nX+fGOff/2-128) * fM + 128 + fGOff/2 ), 0, 255 )); - cMapB[ nX ] = static_cast<sal_uInt8>(MinMax( FRound( (nX+fBOff/2-128) * fM + 128 + fBOff/2 ), 0, 255 )); + cMapR[ nX ] = FRound( std::clamp( (nX+fROff/2-128) * fM + 128 + fROff/2, 0.0, 255.0 ) ); + cMapG[ nX ] = FRound( std::clamp( (nX+fGOff/2-128) * fM + 128 + fGOff/2, 0.0, 255.0 ) ); + cMapB[ nX ] = FRound( std::clamp( (nX+fBOff/2-128) * fM + 128 + fBOff/2, 0.0, 255.0 ) ); } if( bGamma ) { diff --git a/vcl/source/bitmap/bitmappaint.cxx b/vcl/source/bitmap/bitmappaint.cxx index 91a43b951748..dc4fda1eedac 100644 --- a/vcl/source/bitmap/bitmappaint.cxx +++ b/vcl/source/bitmap/bitmappaint.cxx @@ -556,12 +556,12 @@ Bitmap Bitmap::CreateMask(const Color& rTransColor, sal_uInt8 nTol) const BitmapColor aCol; tools::Long nR, nG, nB; - const tools::Long nMinR = MinMax<tools::Long>(rTransColor.GetRed() - nTol, 0, 255); - const tools::Long nMaxR = MinMax<tools::Long>(rTransColor.GetRed() + nTol, 0, 255); - const tools::Long nMinG = MinMax<tools::Long>(rTransColor.GetGreen() - nTol, 0, 255); - const tools::Long nMaxG = MinMax<tools::Long>(rTransColor.GetGreen() + nTol, 0, 255); - const tools::Long nMinB = MinMax<tools::Long>(rTransColor.GetBlue() - nTol, 0, 255); - const tools::Long nMaxB = MinMax<tools::Long>(rTransColor.GetBlue() + nTol, 0, 255); + const tools::Long nMinR = std::clamp<tools::Long>(rTransColor.GetRed() - nTol, 0, 255); + const tools::Long nMaxR = std::clamp<tools::Long>(rTransColor.GetRed() + nTol, 0, 255); + const tools::Long nMinG = std::clamp<tools::Long>(rTransColor.GetGreen() - nTol, 0, 255); + const tools::Long nMaxG = std::clamp<tools::Long>(rTransColor.GetGreen() + nTol, 0, 255); + const tools::Long nMinB = std::clamp<tools::Long>(rTransColor.GetBlue() - nTol, 0, 255); + const tools::Long nMaxB = std::clamp<tools::Long>(rTransColor.GetBlue() + nTol, 0, 255); if (pReadAcc->HasPalette()) { @@ -724,12 +724,12 @@ AlphaMask Bitmap::CreateAlphaMask(const Color& rTransColor, sal_uInt8 nTol) cons BitmapColor aCol; tools::Long nR, nG, nB; - const tools::Long nMinR = MinMax<tools::Long>(rTransColor.GetRed() - nTol, 0, 255); - const tools::Long nMaxR = MinMax<tools::Long>(rTransColor.GetRed() + nTol, 0, 255); - const tools::Long nMinG = MinMax<tools::Long>(rTransColor.GetGreen() - nTol, 0, 255); - const tools::Long nMaxG = MinMax<tools::Long>(rTransColor.GetGreen() + nTol, 0, 255); - const tools::Long nMinB = MinMax<tools::Long>(rTransColor.GetBlue() - nTol, 0, 255); - const tools::Long nMaxB = MinMax<tools::Long>(rTransColor.GetBlue() + nTol, 0, 255); + const tools::Long nMinR = std::clamp<tools::Long>(rTransColor.GetRed() - nTol, 0, 255); + const tools::Long nMaxR = std::clamp<tools::Long>(rTransColor.GetRed() + nTol, 0, 255); + const tools::Long nMinG = std::clamp<tools::Long>(rTransColor.GetGreen() - nTol, 0, 255); + const tools::Long nMaxG = std::clamp<tools::Long>(rTransColor.GetGreen() + nTol, 0, 255); + const tools::Long nMinB = std::clamp<tools::Long>(rTransColor.GetBlue() - nTol, 0, 255); + const tools::Long nMaxB = std::clamp<tools::Long>(rTransColor.GetBlue() + nTol, 0, 255); if (pReadAcc->HasPalette()) { @@ -1019,12 +1019,12 @@ bool Bitmap::Replace(const Color& rSearchColor, const Color& rReplaceColor, sal_ if (!pAcc) return false; - const tools::Long nMinR = MinMax<tools::Long>(rSearchColor.GetRed() - nTol, 0, 255); - const tools::Long nMaxR = MinMax<tools::Long>(rSearchColor.GetRed() + nTol, 0, 255); - const tools::Long nMinG = MinMax<tools::Long>(rSearchColor.GetGreen() - nTol, 0, 255); - const tools::Long nMaxG = MinMax<tools::Long>(rSearchColor.GetGreen() + nTol, 0, 255); - const tools::Long nMinB = MinMax<tools::Long>(rSearchColor.GetBlue() - nTol, 0, 255); - const tools::Long nMaxB = MinMax<tools::Long>(rSearchColor.GetBlue() + nTol, 0, 255); + const tools::Long nMinR = std::clamp<tools::Long>(rSearchColor.GetRed() - nTol, 0, 255); + const tools::Long nMaxR = std::clamp<tools::Long>(rSearchColor.GetRed() + nTol, 0, 255); + const tools::Long nMinG = std::clamp<tools::Long>(rSearchColor.GetGreen() - nTol, 0, 255); + const tools::Long nMaxG = std::clamp<tools::Long>(rSearchColor.GetGreen() + nTol, 0, 255); + const tools::Long nMinB = std::clamp<tools::Long>(rSearchColor.GetBlue() - nTol, 0, 255); + const tools::Long nMaxB = std::clamp<tools::Long>(rSearchColor.GetBlue() + nTol, 0, 255); if (pAcc->HasPalette()) { diff --git a/vcl/source/filter/ipsd/ipsd.cxx b/vcl/source/filter/ipsd/ipsd.cxx index 04446e728b84..887dccce1bf3 100644 --- a/vcl/source/filter/ipsd/ipsd.cxx +++ b/vcl/source/filter/ipsd/ipsd.cxx @@ -691,9 +691,9 @@ bool PSDReader::ImplReadBody() sal_Int32 nDAT = aBlack[ nX + nY * mpFileHeader->nColumns ] * ( nBlackMax - 256 ) / 0x1ff; aBitmapColor = mpBitmap->GetPixel( nY, nX ); - sal_uInt8 cR = static_cast<sal_uInt8>(MinMax( aBitmapColor.GetRed() - nDAT, 0, 255L )); - sal_uInt8 cG = static_cast<sal_uInt8>(MinMax( aBitmapColor.GetGreen() - nDAT, 0, 255L )); - sal_uInt8 cB = static_cast<sal_uInt8>(MinMax( aBitmapColor.GetBlue() - nDAT, 0, 255L )); + sal_uInt8 cR = static_cast<sal_uInt8>(std::clamp( aBitmapColor.GetRed() - nDAT, sal_Int32(0), sal_Int32(255) )); + sal_uInt8 cG = static_cast<sal_uInt8>(std::clamp( aBitmapColor.GetGreen() - nDAT, sal_Int32(0), sal_Int32(255) )); + sal_uInt8 cB = static_cast<sal_uInt8>(std::clamp( aBitmapColor.GetBlue() - nDAT, sal_Int32(0), sal_Int32(255) )); mpBitmap->SetPixel( nY, nX, Color( cR, cG, cB ) ); } } diff --git a/vcl/source/gdi/gdimtf.cxx b/vcl/source/gdi/gdimtf.cxx index 359b9f69b944..ecb7c25aa368 100644 --- a/vcl/source/gdi/gdimtf.cxx +++ b/vcl/source/gdi/gdimtf.cxx @@ -2084,15 +2084,15 @@ void GDIMetaFile::Adjust( short nLuminancePercent, short nContrastPercent, // calculate slope if( nContrastPercent >= 0 ) - fM = 128.0 / ( 128.0 - 1.27 * MinMax( nContrastPercent, 0, 100 ) ); + fM = 128.0 / ( 128.0 - 1.27 * std::clamp( nContrastPercent, short(0), short(100) ) ); else - fM = ( 128.0 + 1.27 * MinMax( nContrastPercent, -100, 0 ) ) / 128.0; + fM = ( 128.0 + 1.27 * std::clamp( nContrastPercent, short(-100), short(0) ) ) / 128.0; if(!msoBrightness) // total offset = luminance offset + contrast offset - fOff = MinMax( nLuminancePercent, -100, 100 ) * 2.55 + 128.0 - fM * 128.0; + fOff = std::clamp( nLuminancePercent, short(-100), short(100) ) * 2.55 + 128.0 - fM * 128.0; else - fOff = MinMax( nLuminancePercent, -100, 100 ) * 2.55; + fOff = std::clamp( nLuminancePercent, short(-100), short(100) ) * 2.55; // channel offset = channel offset + total offset fROff = nChannelRPercent * 2.55 + fOff; @@ -2108,15 +2108,15 @@ void GDIMetaFile::Adjust( short nLuminancePercent, short nContrastPercent, { if(!msoBrightness) { - aColParam.pMapR[ nX ] = static_cast<sal_uInt8>(MinMax( FRound( nX * fM + fROff ), 0, 255 )); - aColParam.pMapG[ nX ] = static_cast<sal_uInt8>(MinMax( FRound( nX * fM + fGOff ), 0, 255 )); - aColParam.pMapB[ nX ] = static_cast<sal_uInt8>(MinMax( FRound( nX * fM + fBOff ), 0, 255 )); + aColParam.pMapR[ nX ] = FRound(std::clamp( nX * fM + fROff, 0.0, 255.0 )); + aColParam.pMapG[ nX ] = FRound(std::clamp( nX * fM + fGOff, 0.0, 255.0 )); + aColParam.pMapB[ nX ] = FRound(std::clamp( nX * fM + fBOff, 0.0, 255.0 )); } else { - aColParam.pMapR[ nX ] = static_cast<sal_uInt8>(MinMax( FRound( (nX+fROff/2-128) * fM + 128 + fROff/2 ), 0, 255 )); - aColParam.pMapG[ nX ] = static_cast<sal_uInt8>(MinMax( FRound( (nX+fGOff/2-128) * fM + 128 + fGOff/2 ), 0, 255 )); - aColParam.pMapB[ nX ] = static_cast<sal_uInt8>(MinMax( FRound( (nX+fBOff/2-128) * fM + 128 + fBOff/2 ), 0, 255 )); + aColParam.pMapR[ nX ] = FRound(std::clamp( (nX+fROff/2-128) * fM + 128 + fROff/2, 0.0, 255.0 )); + aColParam.pMapG[ nX ] = FRound(std::clamp( (nX+fGOff/2-128) * fM + 128 + fGOff/2, 0.0, 255.0 )); + aColParam.pMapB[ nX ] = FRound(std::clamp( (nX+fBOff/2-128) * fM + 128 + fBOff/2, 0.0, 255.0 )); } if( bGamma ) { diff --git a/vcl/source/outdev/bitmap.cxx b/vcl/source/outdev/bitmap.cxx index fa1b93421b0a..d95c97e8633c 100644 --- a/vcl/source/outdev/bitmap.cxx +++ b/vcl/source/outdev/bitmap.cxx @@ -430,7 +430,7 @@ private: { double fTemp = std::abs((nOffset + i) * fReverseScale); - pMap[i] = MinMax(nDstLocation + tools::Long(fTemp), 0, nSampleRange); + pMap[i] = std::clamp(nDstLocation + tools::Long(fTemp), tools::Long(0), nSampleRange); pMapOffset[i] = static_cast<tools::Long>((fTemp - pMap[i]) * 128.0); } } diff --git a/vcl/source/outdev/transparent.cxx b/vcl/source/outdev/transparent.cxx index 11f89efc7a27..8817f54c738d 100644 --- a/vcl/source/outdev/transparent.cxx +++ b/vcl/source/outdev/transparent.cxx @@ -337,7 +337,7 @@ void OutputDevice::EmulateDrawTransparent ( const tools::PolyPolygon& rPolyPoly, { ScopedVclPtrInstance< VirtualDevice > aVDev(*this); const Size aDstSz( aDstRect.GetSize() ); - const sal_uInt8 cTrans = static_cast<sal_uInt8>(MinMax( FRound( nTransparencePercent * 2.55 ), 0, 255 )); + const sal_uInt8 cTrans = FRound( std::clamp( nTransparencePercent * 2.55, 0.0, 255.0 ) ); if( aDstRect.Left() || aDstRect.Top() ) aPolyPoly.Move( -aDstRect.Left(), -aDstRect.Top() ); |