vcl/source/bitmap/BitmapColorQuantizationFilter.cxx | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-)
New commits: commit 10d8402957fe7b8a148a2abd719b7f2cb15f05a7 Author: Chris Sherlock <chris.sherloc...@gmail.com> AuthorDate: Fri Sep 20 18:49:00 2024 +1000 Commit: Michael Weghorn <m.wegh...@posteo.de> CommitDate: Thu Jan 23 10:56:42 2025 +0100 vcl: move variables closer to first use in BitmapColorQuantizationFilter Change-Id: I8a539718ef0eedfea9fadb2bd5ec321bcb8f108e Reviewed-on: https://gerrit.libreoffice.org/c/core/+/173703 Tested-by: Jenkins Reviewed-by: Michael Weghorn <m.wegh...@posteo.de> diff --git a/vcl/source/bitmap/BitmapColorQuantizationFilter.cxx b/vcl/source/bitmap/BitmapColorQuantizationFilter.cxx index e8bb7817b95c..500d3d22569b 100644 --- a/vcl/source/bitmap/BitmapColorQuantizationFilter.cxx +++ b/vcl/source/bitmap/BitmapColorQuantizationFilter.cxx @@ -27,17 +27,11 @@ BitmapEx BitmapColorQuantizationFilter::execute(BitmapEx const& aBitmapEx) const if (!pRAcc) return BitmapEx(); - auto const cappedNewColorCount = std::min(mnNewColorCount, sal_uInt16(256)); - const sal_uInt32 nValidBits = 4; - const sal_uInt32 nRightShiftBits = 8 - nValidBits; - const sal_uInt32 nLeftShiftBits1 = nValidBits; - const sal_uInt32 nLeftShiftBits2 = nValidBits << 1; const sal_uInt32 nColorsPerComponent = 1 << nValidBits; const sal_uInt32 nColorOffset = 256 / nColorsPerComponent; const sal_uInt32 nTotalColors = nColorsPerComponent * nColorsPerComponent * nColorsPerComponent; - const sal_Int32 nWidth = pRAcc->Width(); - const sal_Int32 nHeight = pRAcc->Height(); + std::unique_ptr<PopularColorCount[]> pCountTable(new PopularColorCount[nTotalColors]); memset(pCountTable.get(), 0, nTotalColors * sizeof(PopularColorCount)); @@ -54,6 +48,13 @@ BitmapEx BitmapColorQuantizationFilter::execute(BitmapEx const& aBitmapEx) const } } + const sal_uInt32 nRightShiftBits = 8 - nValidBits; + const sal_uInt32 nLeftShiftBits1 = nValidBits; + const sal_uInt32 nLeftShiftBits2 = nValidBits << 1; + + const sal_Int32 nWidth = pRAcc->Width(); + const sal_Int32 nHeight = pRAcc->Height(); + if (pRAcc->HasPalette()) { for (sal_Int32 nY = 0; nY < nHeight; nY++) @@ -90,6 +91,8 @@ BitmapEx BitmapColorQuantizationFilter::execute(BitmapEx const& aBitmapEx) const } } + auto const cappedNewColorCount = std::min(mnNewColorCount, sal_uInt16(256)); + BitmapPalette aNewPal(cappedNewColorCount); std::qsort(pCountTable.get(), nTotalColors, sizeof(PopularColorCount),