[Libreoffice-commits] core.git: include/vcl vcl/source vcl/unx

Luboš Luňák (via logerrit) logerrit at kemper.freedesktop.org
Wed Jul 1 05:37:01 UTC 2020


 include/vcl/bitmapaccess.hxx             |    4 
 vcl/source/gdi/bmpacc.cxx                |  167 ++++++++++++-------------------
 vcl/source/gdi/salmisc.cxx               |   36 +-----
 vcl/unx/generic/print/genpspgraphics.cxx |   55 ----------
 4 files changed, 81 insertions(+), 181 deletions(-)

New commits:
commit 8663d81828541072999b26451f7d6e6bfcb5f951
Author:     Luboš Luňák <l.lunak at collabora.com>
AuthorDate: Mon Jun 29 21:50:59 2020 +0200
Commit:     Luboš Luňák <l.lunak at collabora.com>
CommitDate: Wed Jul 1 07:36:15 2020 +0200

    remove code duplication for BitmapReadAccess pixel functions
    
    Change-Id: Ib243fea4276cfb86b4fdff8d0c84cea7c4523d82
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/97487
    Tested-by: Jenkins
    Reviewed-by: Luboš Luňák <l.lunak at collabora.com>

diff --git a/include/vcl/bitmapaccess.hxx b/include/vcl/bitmapaccess.hxx
index da29fee9ada0..72f53af6e31e 100644
--- a/include/vcl/bitmapaccess.hxx
+++ b/include/vcl/bitmapaccess.hxx
@@ -232,8 +232,6 @@ protected:
     FncGetPixel mFncGetPixel;
     FncSetPixel mFncSetPixel;
 
-    SAL_DLLPRIVATE bool ImplSetAccessPointers( ScanlineFormat nFormat );
-
 public:
 
     SAL_DLLPRIVATE BitmapBuffer* ImplGetBitmapBuffer() const
@@ -277,6 +275,8 @@ public:
     static void SetPixelForN32BitTcRgbx(Scanline pScanline, long nX, const BitmapColor& rBitmapColor, const ColorMask& rMask);
     static void SetPixelForN32BitTcMask(Scanline pScanline, long nX, const BitmapColor& rBitmapColor, const ColorMask& rMask);
 
+    static FncGetPixel GetPixelFunction( ScanlineFormat nFormat );
+    static FncSetPixel SetPixelFunction( ScanlineFormat nFormat );
 };
 
 
diff --git a/vcl/source/gdi/bmpacc.cxx b/vcl/source/gdi/bmpacc.cxx
index 70500a8b8723..8b7760772880 100644
--- a/vcl/source/gdi/bmpacc.cxx
+++ b/vcl/source/gdi/bmpacc.cxx
@@ -95,9 +95,10 @@ BitmapReadAccess::BitmapReadAccess( Bitmap& rBitmap, BitmapAccessMode nMode ) :
 
     maColorMask = mpBuffer->maColorMask;
 
-    bool bOk = ImplSetAccessPointers(RemoveScanline(mpBuffer->mnFormat));
+    mFncGetPixel = GetPixelFunction(mpBuffer->mnFormat);
+    mFncSetPixel = SetPixelFunction(mpBuffer->mnFormat);
 
-    if (!bOk)
+    if (!mFncGetPixel || !mFncSetPixel)
     {
         xImpBmp->ReleaseBuffer( mpBuffer, mnAccessMode );
         mpBuffer = nullptr;
@@ -117,129 +118,101 @@ namespace
     }
 }
 
-bool BitmapReadAccess::ImplSetAccessPointers( ScanlineFormat nFormat )
+FncGetPixel BitmapReadAccess::GetPixelFunction( ScanlineFormat nFormat )
 {
-    bool bRet = true;
+    switch( RemoveScanline( nFormat ))
+    {
+        case ScanlineFormat::N1BitMsbPal:
+            return GetPixelForN1BitMsbPal;
+        case ScanlineFormat::N1BitLsbPal:
+            return GetPixelForN1BitLsbPal;
+        case ScanlineFormat::N4BitMsnPal:
+            return GetPixelForN4BitMsnPal;
+        case ScanlineFormat::N4BitLsnPal:
+            return GetPixelForN4BitLsnPal;
+        case ScanlineFormat::N8BitPal:
+            return GetPixelForN8BitPal;
+        case ScanlineFormat::N8BitTcMask:
+            return GetPixelForN8BitTcMask;
+        case ScanlineFormat::N24BitTcBgr:
+            return GetPixelForN24BitTcBgr;
+        case ScanlineFormat::N24BitTcRgb:
+            return GetPixelForN24BitTcRgb;
+        case ScanlineFormat::N32BitTcAbgr:
+            if (Bitmap32IsPreMultipled())
+                return GetPixelForN32BitTcAbgr;
+            else
+                return GetPixelForN32BitTcXbgr;
+        case ScanlineFormat::N32BitTcArgb:
+            if (Bitmap32IsPreMultipled())
+                return GetPixelForN32BitTcArgb;
+            else
+                return GetPixelForN32BitTcXrgb;
+        case ScanlineFormat::N32BitTcBgra:
+            if (Bitmap32IsPreMultipled())
+                return GetPixelForN32BitTcBgra;
+            else
+                return GetPixelForN32BitTcBgrx;
+        case ScanlineFormat::N32BitTcRgba:
+            if (Bitmap32IsPreMultipled())
+                return GetPixelForN32BitTcRgba;
+            else
+                return GetPixelForN32BitTcRgbx;
+        case ScanlineFormat::N32BitTcMask:
+            return GetPixelForN32BitTcMask;
+
+        default:
+            return nullptr;
+    }
+}
 
-    switch( nFormat )
+FncSetPixel BitmapReadAccess::SetPixelFunction( ScanlineFormat nFormat )
+{
+    switch( RemoveScanline( nFormat ))
     {
         case ScanlineFormat::N1BitMsbPal:
-        {
-            mFncGetPixel = GetPixelForN1BitMsbPal;
-            mFncSetPixel = SetPixelForN1BitMsbPal;
-        }
-        break;
+            return SetPixelForN1BitMsbPal;
         case ScanlineFormat::N1BitLsbPal:
-        {
-            mFncGetPixel = GetPixelForN1BitLsbPal;
-            mFncSetPixel = SetPixelForN1BitLsbPal;
-        }
-        break;
+            return SetPixelForN1BitLsbPal;
         case ScanlineFormat::N4BitMsnPal:
-        {
-            mFncGetPixel = GetPixelForN4BitMsnPal;
-            mFncSetPixel = SetPixelForN4BitMsnPal;
-        }
-        break;
+            return SetPixelForN4BitMsnPal;
         case ScanlineFormat::N4BitLsnPal:
-        {
-            mFncGetPixel = GetPixelForN4BitLsnPal;
-            mFncSetPixel = SetPixelForN4BitLsnPal;
-        }
-        break;
+            return SetPixelForN4BitLsnPal;
         case ScanlineFormat::N8BitPal:
-        {
-            mFncGetPixel = GetPixelForN8BitPal;
-            mFncSetPixel = SetPixelForN8BitPal;
-        }
-        break;
+            return SetPixelForN8BitPal;
         case ScanlineFormat::N8BitTcMask:
-        {
-            mFncGetPixel = GetPixelForN8BitTcMask;
-            mFncSetPixel = SetPixelForN8BitTcMask;
-        }
-        break;
+            return SetPixelForN8BitTcMask;
         case ScanlineFormat::N24BitTcBgr:
-        {
-            mFncGetPixel = GetPixelForN24BitTcBgr;
-            mFncSetPixel = SetPixelForN24BitTcBgr;
-        }
-        break;
+            return SetPixelForN24BitTcBgr;
         case ScanlineFormat::N24BitTcRgb:
-        {
-            mFncGetPixel = GetPixelForN24BitTcRgb;
-            mFncSetPixel = SetPixelForN24BitTcRgb;
-        }
-        break;
+            return SetPixelForN24BitTcRgb;
         case ScanlineFormat::N32BitTcAbgr:
-        {
             if (Bitmap32IsPreMultipled())
-            {
-                mFncGetPixel = GetPixelForN32BitTcAbgr;
-                mFncSetPixel = SetPixelForN32BitTcAbgr;
-            }
+                return SetPixelForN32BitTcAbgr;
             else
-            {
-                mFncGetPixel = GetPixelForN32BitTcXbgr;
-                mFncSetPixel = SetPixelForN32BitTcXbgr;
-            }
-        }
-        break;
+                return SetPixelForN32BitTcXbgr;
         case ScanlineFormat::N32BitTcArgb:
-        {
             if (Bitmap32IsPreMultipled())
-            {
-                mFncGetPixel = GetPixelForN32BitTcArgb;
-                mFncSetPixel = SetPixelForN32BitTcArgb;
-            }
+                return SetPixelForN32BitTcArgb;
             else
-            {
-                mFncGetPixel = GetPixelForN32BitTcXrgb;
-                mFncSetPixel = SetPixelForN32BitTcXrgb;
-            }
-        }
-        break;
+                return SetPixelForN32BitTcXrgb;
         case ScanlineFormat::N32BitTcBgra:
-        {
             if (Bitmap32IsPreMultipled())
-            {
-                mFncGetPixel = GetPixelForN32BitTcBgra;
-                mFncSetPixel = SetPixelForN32BitTcBgra;
-            }
+                return SetPixelForN32BitTcBgra;
             else
-            {
-                mFncGetPixel = GetPixelForN32BitTcBgrx;
-                mFncSetPixel = SetPixelForN32BitTcBgrx;
-            }
-        }
-        break;
+                return SetPixelForN32BitTcBgrx;
         case ScanlineFormat::N32BitTcRgba:
-        {
             if (Bitmap32IsPreMultipled())
-            {
-                mFncGetPixel = GetPixelForN32BitTcRgba;
-                mFncSetPixel = SetPixelForN32BitTcRgba;
-            }
+                return SetPixelForN32BitTcRgba;
             else
-            {
-                mFncGetPixel = GetPixelForN32BitTcRgbx;
-                mFncSetPixel = SetPixelForN32BitTcRgbx;
-            }
-        }
-        break;
+                return SetPixelForN32BitTcRgbx;
         case ScanlineFormat::N32BitTcMask:
-        {
-            mFncGetPixel = GetPixelForN32BitTcMask;
-            mFncSetPixel = SetPixelForN32BitTcMask;
-        }
+            return SetPixelForN32BitTcMask;
         break;
 
         default:
-            bRet = false;
-        break;
+            return nullptr;
     }
-
-    return bRet;
 }
 
 BitmapColor BitmapReadAccess::GetInterpolatedColorWithFallback( double fY, double fX, const BitmapColor& rFallback ) const
diff --git a/vcl/source/gdi/salmisc.cxx b/vcl/source/gdi/salmisc.cxx
index a6a5e36279a2..6f790f727ca6 100644
--- a/vcl/source/gdi/salmisc.cxx
+++ b/vcl/source/gdi/salmisc.cxx
@@ -26,11 +26,6 @@
 #include <tools/helpers.hxx>
 #include <memory>
 
-#define IMPL_CASE_GET_FORMAT( Format )                          \
-case( ScanlineFormat::Format ):                                 \
-    pFncGetPixel = BitmapReadAccess::GetPixelFor##Format;       \
-break
-
 #define IMPL_CASE_SET_FORMAT( Format, BitCount )                \
 case( ScanlineFormat::Format ):                                 \
 {                                                               \
@@ -270,29 +265,14 @@ std::unique_ptr<BitmapBuffer> StretchAndConvert(
     std::unique_ptr<BitmapBuffer> pDstBuffer(new BitmapBuffer);
 
     // set function for getting pixels
-    switch( RemoveScanline( rSrcBuffer.mnFormat ) )
-    {
-        IMPL_CASE_GET_FORMAT( N1BitMsbPal );
-        IMPL_CASE_GET_FORMAT( N1BitLsbPal );
-        IMPL_CASE_GET_FORMAT( N4BitMsnPal );
-        IMPL_CASE_GET_FORMAT( N4BitLsnPal );
-        IMPL_CASE_GET_FORMAT( N8BitPal );
-        IMPL_CASE_GET_FORMAT( N8BitTcMask );
-        IMPL_CASE_GET_FORMAT( N24BitTcBgr );
-        IMPL_CASE_GET_FORMAT( N24BitTcRgb );
-        IMPL_CASE_GET_FORMAT( N32BitTcAbgr );
-        IMPL_CASE_GET_FORMAT( N32BitTcArgb );
-        IMPL_CASE_GET_FORMAT( N32BitTcBgra );
-        IMPL_CASE_GET_FORMAT( N32BitTcRgba );
-        IMPL_CASE_GET_FORMAT( N32BitTcMask );
-
-        default:
-            // should never come here
-            // initialize pFncGetPixel to something valid that is
-            // least likely to crash
-            pFncGetPixel = BitmapReadAccess::GetPixelForN1BitMsbPal;
-            OSL_FAIL( "unknown read format" );
-        break;
+    pFncGetPixel = BitmapReadAccess::GetPixelFunction( rSrcBuffer.mnFormat );
+    if( !pFncGetPixel )
+    {
+        // should never come here
+        // initialize pFncGetPixel to something valid that is
+        // least likely to crash
+        pFncGetPixel = BitmapReadAccess::GetPixelForN1BitMsbPal;
+        OSL_FAIL( "unknown read format" );
     }
 
     // set function for setting pixels
diff --git a/vcl/unx/generic/print/genpspgraphics.cxx b/vcl/unx/generic/print/genpspgraphics.cxx
index 03319d1acf53..a79aaab72fd8 100644
--- a/vcl/unx/generic/print/genpspgraphics.cxx
+++ b/vcl/unx/generic/print/genpspgraphics.cxx
@@ -78,11 +78,6 @@ public:
     virtual sal_uInt32  GetDepth () const override;
 };
 
-    bool Bitmap32IsPreMultipled()
-    {
-        auto pBackendCapabilities = ImplGetSVData()->mpDefInst->GetBackendCapabilities();
-        return pBackendCapabilities->mbSupportsBitmap32;
-    }
 }
 
 SalPrinterBmp::SalPrinterBmp (BitmapBuffer* pBuffer)
@@ -104,55 +99,7 @@ SalPrinterBmp::SalPrinterBmp (BitmapBuffer* pBuffer)
     }
 
     // request read access to the pixels
-    switch( RemoveScanline( mpBmpBuffer->mnFormat ) )
-    {
-        case ScanlineFormat::N1BitMsbPal:
-            mpFncGetPixel = BitmapReadAccess::GetPixelForN1BitMsbPal;  break;
-        case ScanlineFormat::N1BitLsbPal:
-            mpFncGetPixel = BitmapReadAccess::GetPixelForN1BitLsbPal;  break;
-        case ScanlineFormat::N4BitMsnPal:
-            mpFncGetPixel = BitmapReadAccess::GetPixelForN4BitMsnPal;  break;
-        case ScanlineFormat::N4BitLsnPal:
-            mpFncGetPixel = BitmapReadAccess::GetPixelForN4BitLsnPal;  break;
-        case ScanlineFormat::N8BitPal:
-            mpFncGetPixel = BitmapReadAccess::GetPixelForN8BitPal;      break;
-        case ScanlineFormat::N8BitTcMask:
-            mpFncGetPixel = BitmapReadAccess::GetPixelForN8BitTcMask;  break;
-        case ScanlineFormat::N24BitTcBgr:
-            mpFncGetPixel = BitmapReadAccess::GetPixelForN24BitTcBgr;  break;
-        case ScanlineFormat::N24BitTcRgb:
-            mpFncGetPixel = BitmapReadAccess::GetPixelForN24BitTcRgb;  break;
-        case ScanlineFormat::N32BitTcAbgr:
-            if (Bitmap32IsPreMultipled())
-                mpFncGetPixel = BitmapReadAccess::GetPixelForN32BitTcAbgr;
-            else
-                mpFncGetPixel = BitmapReadAccess::GetPixelForN32BitTcXbgr;
-            break;
-        case ScanlineFormat::N32BitTcArgb:
-            if (Bitmap32IsPreMultipled())
-                mpFncGetPixel = BitmapReadAccess::GetPixelForN32BitTcArgb;
-            else
-                mpFncGetPixel = BitmapReadAccess::GetPixelForN32BitTcXrgb;
-            break;
-        case ScanlineFormat::N32BitTcBgra:
-            if (Bitmap32IsPreMultipled())
-                mpFncGetPixel = BitmapReadAccess::GetPixelForN32BitTcBgra;
-            else
-                mpFncGetPixel = BitmapReadAccess::GetPixelForN32BitTcBgrx;
-            break;
-        case ScanlineFormat::N32BitTcRgba:
-            if (Bitmap32IsPreMultipled())
-                mpFncGetPixel = BitmapReadAccess::GetPixelForN32BitTcRgba;
-            else
-                mpFncGetPixel = BitmapReadAccess::GetPixelForN32BitTcRgbx;
-            break;
-        case ScanlineFormat::N32BitTcMask:
-            mpFncGetPixel = BitmapReadAccess::GetPixelForN32BitTcMask; break;
-        default:
-            OSL_FAIL("Error: SalPrinterBmp::SalPrinterBmp() unknown bitmap format");
-            mpFncGetPixel = nullptr;
-        break;
-    }
+    mpFncGetPixel = BitmapReadAccess::GetPixelFunction( mpBmpBuffer->mnFormat );
 }
 
 sal_uInt32


More information about the Libreoffice-commits mailing list