summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--vcl/source/bitmap/BitmapColorQuantizationFilter.cxx17
1 files changed, 10 insertions, 7 deletions
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),