summaryrefslogtreecommitdiff
path: root/vcl
diff options
context:
space:
mode:
authorChris Sherlock <chris.sherlock79@gmail.com>2024-09-01 05:45:20 +1000
committerMichael Weghorn <m.weghorn@posteo.de>2024-09-30 08:34:04 +0200
commit89f0b965b26eca7ca9be18122881b955072f3fa8 (patch)
tree2d9f0363a4befce922a0db1c09a2c346df76dabe /vcl
parentb021286327abed031e75b6dd6fa67790f24a700a (diff)
vcl: flatten BitmapPopArtFilter::execute()
Change-Id: Icfbf2e625fb01f336c0c5eec8553b24922376680 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/173204 Reviewed-by: Michael Weghorn <m.weghorn@posteo.de> Tested-by: Jenkins
Diffstat (limited to 'vcl')
-rw-r--r--vcl/source/bitmap/BitmapPopArtFilter.cxx123
1 files changed, 58 insertions, 65 deletions
diff --git a/vcl/source/bitmap/BitmapPopArtFilter.cxx b/vcl/source/bitmap/BitmapPopArtFilter.cxx
index ee2cf716c93e..bbb42843d397 100644
--- a/vcl/source/bitmap/BitmapPopArtFilter.cxx
+++ b/vcl/source/bitmap/BitmapPopArtFilter.cxx
@@ -18,79 +18,72 @@ BitmapEx BitmapPopArtFilter::execute(BitmapEx const& rBitmapEx) const
{
Bitmap aBitmap(rBitmapEx.GetBitmap());
- bool bRet = isPalettePixelFormat(aBitmap.getPixelFormat())
- || aBitmap.Convert(BmpConversion::N8BitColors);
+ bool bConvert = isPalettePixelFormat(aBitmap.getPixelFormat())
+ || aBitmap.Convert(BmpConversion::N8BitColors);
- if (bRet)
- {
- bRet = false;
+ if (!bConvert)
+ return BitmapEx();
+
+ BitmapScopedWriteAccess pWriteAcc(aBitmap);
+
+ if (!pWriteAcc)
+ return BitmapEx();
- BitmapScopedWriteAccess pWriteAcc(aBitmap);
+ const sal_Int32 nWidth = pWriteAcc->Width();
+ const sal_Int32 nHeight = pWriteAcc->Height();
+ const sal_uInt16 nEntryCount = 1 << pWriteAcc->GetBitCount();
+ sal_uInt16 n = 0;
+ std::vector<PopArtEntry> aPopArtTable(nEntryCount);
- if (pWriteAcc)
+ for (n = 0; n < nEntryCount; n++)
+ {
+ PopArtEntry& rEntry = aPopArtTable[n];
+ rEntry.mnIndex = n;
+ rEntry.mnCount = 0;
+ }
+
+ // get pixel count for each palette entry
+ for (sal_Int32 nY = 0; nY < nHeight; nY++)
+ {
+ Scanline pScanline = pWriteAcc->GetScanline(nY);
+ for (sal_Int32 nX = 0; nX < nWidth; nX++)
{
- const sal_Int32 nWidth = pWriteAcc->Width();
- const sal_Int32 nHeight = pWriteAcc->Height();
- 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 = n;
- rEntry.mnCount = 0;
- }
-
- // get pixel count for each palette entry
- for (sal_Int32 nY = 0; nY < nHeight; nY++)
- {
- Scanline pScanline = pWriteAcc->GetScanline(nY);
- for (sal_Int32 nX = 0; nX < nWidth; nX++)
- {
- aPopArtTable[pWriteAcc->GetIndexFromData(pScanline, nX)].mnCount++;
- assert(aPopArtTable[pWriteAcc->GetIndexFromData(pScanline, nX)].mnCount != 0);
- }
- }
-
- // sort table
- std::sort(aPopArtTable.begin(), aPopArtTable.end(),
- [](const PopArtEntry& lhs, const PopArtEntry& rhs) {
- return lhs.mnCount > rhs.mnCount;
- });
-
- // get last used entry
- sal_uInt16 nFirstEntry;
- sal_uInt16 nLastEntry = 0;
-
- for (n = 0; n < nEntryCount; n++)
- {
- if (aPopArtTable[n].mnCount)
- nLastEntry = n;
- }
-
- // rotate palette (one entry)
- const BitmapColor aFirstCol(pWriteAcc->GetPaletteColor(aPopArtTable[0].mnIndex));
-
- for (nFirstEntry = 0; nFirstEntry < nLastEntry; nFirstEntry++)
- {
- pWriteAcc->SetPaletteColor(
- aPopArtTable[nFirstEntry].mnIndex,
- pWriteAcc->GetPaletteColor(aPopArtTable[nFirstEntry + 1].mnIndex));
- }
-
- pWriteAcc->SetPaletteColor(aPopArtTable[nLastEntry].mnIndex, aFirstCol);
-
- // cleanup
- pWriteAcc.reset();
- bRet = true;
+ aPopArtTable[pWriteAcc->GetIndexFromData(pScanline, nX)].mnCount++;
+ assert(aPopArtTable[pWriteAcc->GetIndexFromData(pScanline, nX)].mnCount != 0);
}
}
- if (bRet)
- return BitmapEx(aBitmap);
+ // sort table
+ std::sort(
+ aPopArtTable.begin(), aPopArtTable.end(),
+ [](const PopArtEntry& lhs, const PopArtEntry& rhs) { return lhs.mnCount > rhs.mnCount; });
+
+ // get last used entry
+ sal_uInt16 nFirstEntry;
+ sal_uInt16 nLastEntry = 0;
+
+ for (n = 0; n < nEntryCount; n++)
+ {
+ if (aPopArtTable[n].mnCount)
+ nLastEntry = n;
+ }
+
+ // rotate palette (one entry)
+ const BitmapColor aFirstCol(pWriteAcc->GetPaletteColor(aPopArtTable[0].mnIndex));
+
+ for (nFirstEntry = 0; nFirstEntry < nLastEntry; nFirstEntry++)
+ {
+ pWriteAcc->SetPaletteColor(
+ aPopArtTable[nFirstEntry].mnIndex,
+ pWriteAcc->GetPaletteColor(aPopArtTable[nFirstEntry + 1].mnIndex));
+ }
+
+ pWriteAcc->SetPaletteColor(aPopArtTable[nLastEntry].mnIndex, aFirstCol);
+
+ // cleanup
+ pWriteAcc.reset();
- return BitmapEx();
+ return BitmapEx(aBitmap);
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */