vcl/source/bitmap/BitmapPopArtFilter.cxx |  123 ++++++++++++++-----------------
 1 file changed, 58 insertions(+), 65 deletions(-)

New commits:
commit 89f0b965b26eca7ca9be18122881b955072f3fa8
Author:     Chris Sherlock <chris.sherloc...@gmail.com>
AuthorDate: Sun Sep 1 05:45:20 2024 +1000
Commit:     Michael Weghorn <m.wegh...@posteo.de>
CommitDate: Mon Sep 30 08:34:04 2024 +0200

    vcl: flatten BitmapPopArtFilter::execute()
    
    Change-Id: Icfbf2e625fb01f336c0c5eec8553b24922376680
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/173204
    Reviewed-by: Michael Weghorn <m.wegh...@posteo.de>
    Tested-by: Jenkins

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: */

Reply via email to