include/vcl/gdimtf.hxx | 4 +-- vcl/source/gdi/gdimtf.cxx | 58 +++++++++++++++++++++++----------------------- 2 files changed, 31 insertions(+), 31 deletions(-)
New commits: commit 998085f830836f043d2541045b5ad3f5970e3b6a Author: Daniel Lee <[email protected]> AuthorDate: Fri Nov 7 23:31:55 2025 -0600 Commit: Noel Grandin <[email protected]> CommitDate: Sat Nov 22 08:15:12 2025 +0100 tdf#114441: Replaced sal_uLong in GDI MF code The maximum size of the GDI metafile is 4GB, so sal_uInt32 is sufficient for metafile size related variables. The number of possible colors is 0xFFFFFF so sal_uInt32 is sufficient to store the number of colors. The R, G, B fields have a maximum of 255 so sal_uInt8 is sufficient for storing them. Change-Id: I0f0108df6eeb087ce1e799905c4f9ee03b409ab9 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/193608 Tested-by: Jenkins Reviewed-by: Noel Grandin <[email protected]> diff --git a/include/vcl/gdimtf.hxx b/include/vcl/gdimtf.hxx index 7254b4f85632..6275d45400ed 100644 --- a/include/vcl/gdimtf.hxx +++ b/include/vcl/gdimtf.hxx @@ -136,7 +136,7 @@ public: void Convert( MtfConversion eConversion ); void ReplaceColors( const Color* pSearchColors, const Color* rReplaceColors, - sal_uLong nColorCount ); + sal_uInt32 nColorCount ); GDIMetaFile GetMonochromeMtf( const Color& rCol ) const; @@ -177,7 +177,7 @@ public: void SetPrefMapMode( const MapMode& rMapMode ) { m_aPrefMapMode = rMapMode; } - SAL_DLLPRIVATE sal_uLong GetSizeBytes() const; + SAL_DLLPRIVATE sal_uInt32 GetSizeBytes() const; /// Creates an antialiased thumbnail bool CreateThumbnail(Bitmap& rBitmapEx, diff --git a/vcl/source/gdi/gdimtf.cxx b/vcl/source/gdi/gdimtf.cxx index 8b2cf001fbe2..14829676567c 100644 --- a/vcl/source/gdi/gdimtf.cxx +++ b/vcl/source/gdi/gdimtf.cxx @@ -91,21 +91,21 @@ struct ImplBmpMonoParam struct ImplColReplaceParam { - std::unique_ptr<sal_uLong[]> pMinR; - std::unique_ptr<sal_uLong[]> pMaxR; - std::unique_ptr<sal_uLong[]> pMinG; - std::unique_ptr<sal_uLong[]> pMaxG; - std::unique_ptr<sal_uLong[]> pMinB; - std::unique_ptr<sal_uLong[]> pMaxB; + std::unique_ptr<sal_uInt8[]> pMinR; + std::unique_ptr<sal_uInt8[]> pMaxR; + std::unique_ptr<sal_uInt8[]> pMinG; + std::unique_ptr<sal_uInt8[]> pMaxG; + std::unique_ptr<sal_uInt8[]> pMinB; + std::unique_ptr<sal_uInt8[]> pMaxB; const Color * pDstCols; - sal_uLong nCount; + sal_uInt32 nCount; }; struct ImplBmpReplaceParam { const Color* pSrcCols; const Color* pDstCols; - sal_uLong nCount; + sal_uInt32 nCount; }; } @@ -1328,9 +1328,9 @@ tools::Rectangle GDIMetaFile::GetBoundRect( OutputDevice& i_rReference ) const std::vector<vcl::PushFlags> aPushFlagStack; tools::Rectangle aBound; - const sal_uLong nCount(GetActionSize()); + const sal_uInt32 nCount(GetActionSize()); - for(sal_uLong a(0); a < nCount; a++) + for(sal_uInt32 a(0); a < nCount; a++) { MetaAction* pAction = GetAction(a); const MetaActionType nActionType = pAction->GetType(); @@ -1780,9 +1780,9 @@ Bitmap GDIMetaFile::ImplBmpMonoFnc( const Bitmap& rBmp, const void* pBmpParam ) Color GDIMetaFile::ImplColReplaceFnc( const Color& rColor, const void* pColParam ) { - const sal_uLong nR = rColor.GetRed(), nG = rColor.GetGreen(), nB = rColor.GetBlue(); + const sal_uInt8 nR = rColor.GetRed(), nG = rColor.GetGreen(), nB = rColor.GetBlue(); - for( sal_uLong i = 0; i < static_cast<const ImplColReplaceParam*>(pColParam)->nCount; i++ ) + for( sal_uInt32 i = 0; i < static_cast<const ImplColReplaceParam*>(pColParam)->nCount; i++ ) { if( ( static_cast<const ImplColReplaceParam*>(pColParam)->pMinR[ i ] <= nR ) && ( static_cast<const ImplColReplaceParam*>(pColParam)->pMaxR[ i ] >= nR ) && @@ -2154,33 +2154,33 @@ void GDIMetaFile::Convert( MtfConversion eConversion ) ImplExchangeColors( ImplColConvertFnc, &aColParam, ImplBmpConvertFnc, &aBmpParam ); } -void GDIMetaFile::ReplaceColors( const Color* pSearchColors, const Color* pReplaceColors, sal_uLong nColorCount ) +void GDIMetaFile::ReplaceColors( const Color* pSearchColors, const Color* pReplaceColors, sal_uInt32 nColorCount ) { ImplColReplaceParam aColParam; ImplBmpReplaceParam aBmpParam; - aColParam.pMinR.reset(new sal_uLong[ nColorCount ]); - aColParam.pMaxR.reset(new sal_uLong[ nColorCount ]); - aColParam.pMinG.reset(new sal_uLong[ nColorCount ]); - aColParam.pMaxG.reset(new sal_uLong[ nColorCount ]); - aColParam.pMinB.reset(new sal_uLong[ nColorCount ]); - aColParam.pMaxB.reset(new sal_uLong[ nColorCount ]); + aColParam.pMinR.reset(new sal_uInt8[ nColorCount ]); + aColParam.pMaxR.reset(new sal_uInt8[ nColorCount ]); + aColParam.pMinG.reset(new sal_uInt8[ nColorCount ]); + aColParam.pMaxG.reset(new sal_uInt8[ nColorCount ]); + aColParam.pMinB.reset(new sal_uInt8[ nColorCount ]); + aColParam.pMaxB.reset(new sal_uInt8[ nColorCount ]); - for( sal_uLong i = 0; i < nColorCount; i++ ) + for( sal_uInt32 i = 0; i < nColorCount; i++ ) { - tools::Long nVal; + sal_uInt8 nVal; nVal = pSearchColors[ i ].GetRed(); - aColParam.pMinR[ i ] = static_cast<sal_uLong>(std::max( nVal, tools::Long(0) )); - aColParam.pMaxR[ i ] = static_cast<sal_uLong>(std::min( nVal, tools::Long(255) )); + aColParam.pMinR[ i ] = std::max( nVal, sal_uInt8(0) ); + aColParam.pMaxR[ i ] = std::min( nVal, sal_uInt8(255) ); nVal = pSearchColors[ i ].GetGreen(); - aColParam.pMinG[ i ] = static_cast<sal_uLong>(std::max( nVal, tools::Long(0) )); - aColParam.pMaxG[ i ] = static_cast<sal_uLong>(std::min( nVal, tools::Long(255) )); + aColParam.pMinG[ i ] = std::max( nVal, sal_uInt8(0) ); + aColParam.pMaxG[ i ] = std::min( nVal, sal_uInt8(255) ); nVal = pSearchColors[ i ].GetBlue(); - aColParam.pMinB[ i ] = static_cast<sal_uLong>(std::max( nVal, tools::Long(0) )); - aColParam.pMaxB[ i ] = static_cast<sal_uLong>(std::min( nVal, tools::Long(255) )); + aColParam.pMinB[ i ] = std::max( nVal, sal_uInt8(0) ); + aColParam.pMaxB[ i ] = std::min( nVal, sal_uInt8(255) ); } aColParam.pDstCols = pReplaceColors; @@ -2208,9 +2208,9 @@ GDIMetaFile GDIMetaFile::GetMonochromeMtf( const Color& rColor ) const return aRet; } -sal_uLong GDIMetaFile::GetSizeBytes() const +sal_uInt32 GDIMetaFile::GetSizeBytes() const { - sal_uLong nSizeBytes = 0; + sal_uInt32 nSizeBytes = 0; for( size_t i = 0, nObjCount = GetActionSize(); i < nObjCount; ++i ) {
