include/vcl/BitmapPopArtFilter.hxx | 2 +- vcl/source/bitmap/BitmapPopArtFilter.cxx | 21 +++++++++------------ 2 files changed, 10 insertions(+), 13 deletions(-)
New commits: commit 5a6914af4678a24c794055ba23dd9cf0857f0254 Author: Julien Nabet <serval2...@yahoo.fr> AuthorDate: Mon Sep 19 20:57:19 2022 +0200 Commit: Julien Nabet <serval2...@yahoo.fr> CommitDate: Tue Sep 20 08:18:21 2022 +0200 Simplify a bit by using sal_uInt16 in vcl/BitmapPopArtFilter Since we're in the "if (bRet)" block, it means 22 bool bRet = isPalettePixelFormat(aBitmap.getPixelFormat()) 23 || aBitmap.Convert(BmpConversion::N8BitColors); is verified. isPalettePixelFormat implementation is: 29 constexpr bool isPalettePixelFormat(PixelFormat ePixelFormat) 30 { 31 assert(ePixelFormat != PixelFormat::INVALID); 32 return sal_uInt16(ePixelFormat) <= 8; 33 } So we know we're using 8 bits max and this line: pWriteAcc->GetBitCount() can't give more than 8 and we can safely declare nEntryCount as sal_uInt16 (idem for "n" just below) Since "nFirstEntry" and "nLastEntry" are related to "nEntryCount", idem for mnIndex they can also be sal_uInt16. Thanks to these, we can avoid all sal::static_int_cast<sal_uInt16> conversions. Change-Id: I8cac2d01f00be33c86058c7a6eb7b9e25fb2635e Reviewed-on: https://gerrit.libreoffice.org/c/core/+/140206 Tested-by: Jenkins Reviewed-by: Noel Grandin <noel.gran...@collabora.co.uk> Reviewed-by: Julien Nabet <serval2...@yahoo.fr> diff --git a/include/vcl/BitmapPopArtFilter.hxx b/include/vcl/BitmapPopArtFilter.hxx index e5733f7338cc..c25804d359fb 100644 --- a/include/vcl/BitmapPopArtFilter.hxx +++ b/include/vcl/BitmapPopArtFilter.hxx @@ -23,7 +23,7 @@ public: private: struct PopArtEntry { - sal_uInt32 mnIndex; + sal_uInt16 mnIndex; sal_uInt32 mnCount; }; }; diff --git a/vcl/source/bitmap/BitmapPopArtFilter.cxx b/vcl/source/bitmap/BitmapPopArtFilter.cxx index ce37c91fdd58..39856cf8b6eb 100644 --- a/vcl/source/bitmap/BitmapPopArtFilter.cxx +++ b/vcl/source/bitmap/BitmapPopArtFilter.cxx @@ -32,14 +32,14 @@ BitmapEx BitmapPopArtFilter::execute(BitmapEx const& rBitmapEx) const { const sal_Int32 nWidth = pWriteAcc->Width(); const sal_Int32 nHeight = pWriteAcc->Height(); - const int nEntryCount = 1 << pWriteAcc->GetBitCount(); - int n = 0; + const sal_uInt16 nEntryCount = 1 << pWriteAcc->GetBitCount(); + sal_uInt16 n = 0; std::vector<PopArtEntry> aPopArtTable(nEntryCount); for (n = 0; n < nEntryCount; n++) { PopArtEntry& rEntry = aPopArtTable[n]; - rEntry.mnIndex = static_cast<sal_uInt16>(n); + rEntry.mnIndex = n; rEntry.mnCount = 0; } @@ -60,8 +60,8 @@ BitmapEx BitmapPopArtFilter::execute(BitmapEx const& rBitmapEx) const }); // get last used entry - sal_uLong nFirstEntry; - sal_uLong nLastEntry = 0; + sal_uInt16 nFirstEntry; + sal_uInt16 nLastEntry = 0; for (n = 0; n < nEntryCount; n++) { @@ -70,19 +70,16 @@ BitmapEx BitmapPopArtFilter::execute(BitmapEx const& rBitmapEx) const } // rotate palette (one entry) - const BitmapColor aFirstCol(pWriteAcc->GetPaletteColor( - sal::static_int_cast<sal_uInt16>(aPopArtTable[0].mnIndex))); + const BitmapColor aFirstCol(pWriteAcc->GetPaletteColor(aPopArtTable[0].mnIndex)); for (nFirstEntry = 0; nFirstEntry < nLastEntry; nFirstEntry++) { pWriteAcc->SetPaletteColor( - sal::static_int_cast<sal_uInt16>(aPopArtTable[nFirstEntry].mnIndex), - pWriteAcc->GetPaletteColor( - sal::static_int_cast<sal_uInt16>(aPopArtTable[nFirstEntry + 1].mnIndex))); + aPopArtTable[nFirstEntry].mnIndex, + pWriteAcc->GetPaletteColor(aPopArtTable[nFirstEntry + 1].mnIndex)); } - pWriteAcc->SetPaletteColor( - sal::static_int_cast<sal_uInt16>(aPopArtTable[nLastEntry].mnIndex), aFirstCol); + pWriteAcc->SetPaletteColor(aPopArtTable[nLastEntry].mnIndex, aFirstCol); // cleanup pWriteAcc.reset();