[Libreoffice-commits] core.git: vcl/win

Libreoffice Gerrit user logerrit at kemper.freedesktop.org
Wed Dec 12 08:03:49 UTC 2018


 vcl/win/gdi/gdiimpl.cxx |  195 ++++++++++++++++++++++++------------------------
 vcl/win/gdi/gdiimpl.hxx |    2 
 2 files changed, 102 insertions(+), 95 deletions(-)

New commits:
commit 1f399944ab9d2d46b372a259374cb1c2d26f107c
Author:     Dmitriy Shilin <dshil at fastmail.com>
AuthorDate: Tue Dec 11 08:46:41 2018 +0300
Commit:     Mike Kaganski <mike.kaganski at collabora.com>
CommitDate: Wed Dec 12 09:03:22 2018 +0100

    tdf#107792 vcl: simplify SetFillColor()
    
    Change-Id: If01e88d80922ca140e7e5d388cb5760f0bb20d79
    Reviewed-on: https://gerrit.libreoffice.org/64913
    Tested-by: Jenkins
    Reviewed-by: Mike Kaganski <mike.kaganski at collabora.com>

diff --git a/vcl/win/gdi/gdiimpl.cxx b/vcl/win/gdi/gdiimpl.cxx
index 2200dbda000a..cebacda7e5f5 100644
--- a/vcl/win/gdi/gdiimpl.cxx
+++ b/vcl/win/gdi/gdiimpl.cxx
@@ -165,31 +165,6 @@ void ImplPreparePolyDraw( bool                      bCloseFigures,
     }
 }
 
-
-static BYTE aOrdDither8Bit[8][8] =
-{
-   {  0, 38,  9, 48,  2, 40, 12, 50 },
-   { 25, 12, 35, 22, 28, 15, 37, 24 },
-   {  6, 44,  3, 41,  8, 47,  5, 44 },
-   { 32, 19, 28, 16, 34, 21, 31, 18 },
-   {  1, 40, 11, 49,  0, 39, 10, 48 },
-   { 27, 14, 36, 24, 26, 13, 36, 23 },
-   {  8, 46,  4, 43,  7, 45,  4, 42 },
-   { 33, 20, 30, 17, 32, 20, 29, 16 }
-};
-
-static BYTE aOrdDither16Bit[8][8] =
-{
-   { 0, 6, 1, 7, 0, 6, 1, 7 },
-   { 4, 2, 5, 3, 4, 2, 5, 3 },
-   { 1, 7, 0, 6, 1, 7, 0, 6 },
-   { 5, 3, 4, 2, 5, 3, 4, 2 },
-   { 0, 6, 1, 7, 0, 6, 1, 7 },
-   { 4, 2, 5, 3, 4, 2, 5, 3 },
-   { 1, 7, 0, 6, 1, 7, 0, 6 },
-   { 5, 3, 4, 2, 5, 3, 4, 2 }
-};
-
 Color ImplGetROPColor( SalROPColor nROPColor )
 {
     Color nColor;
@@ -1443,96 +1418,126 @@ void WinSalGraphicsImpl::SetFillColor()
     mbStockBrush = TRUE;
 }
 
-void WinSalGraphicsImpl::SetFillColor( Color nColor )
+void WinSalGraphicsImpl::SetFillColor(Color nColor)
 {
+    COLORREF nBrushColor = PALETTERGB(nColor.GetRed(),
+                                      nColor.GetGreen(),
+                                      nColor.GetBlue());
+    bool bStockBrush = false;
+
+    HBRUSH hNewBrush = SearchStockBrush(nBrushColor);
+    if (hNewBrush)
+        bStockBrush = true;
+    else
+        hNewBrush = MakeBrush(nColor);
+
+    ResetBrush(hNewBrush);
+
+    // set new data
+    mnBrushColor = nBrushColor;
     maFillColor = nColor;
-    SalData*    pSalData    = GetSalData();
+    mbBrush     = TRUE;
+    mbStockBrush = bStockBrush;
+}
+
+HBRUSH WinSalGraphicsImpl::SearchStockBrush(COLORREF nBrushColor)
+{
+    // Only screen, because printer has problems, when we use stock objects.
+    if (!mrParent.isPrinter())
+    {
+        const SalData* pSalData = GetSalData();
+
+        for (sal_uInt16 i = 0; i < pSalData->mnStockBrushCount; i++)
+        {
+            if (nBrushColor == pSalData->maStockBrushColorAry[i])
+                return pSalData->mhStockBrushAry[i];
+        }
+    }
+
+    return nullptr;
+}
+
+HBRUSH WinSalGraphicsImpl::MakeBrush(Color nColor)
+{
+    const SalData* pSalData = GetSalData();
+
     BYTE        nRed        = nColor.GetRed();
     BYTE        nGreen      = nColor.GetGreen();
     BYTE        nBlue       = nColor.GetBlue();
-    COLORREF    nBrushColor = PALETTERGB( nRed, nGreen, nBlue );
-    HBRUSH      hNewBrush   = nullptr;
-    bool        bStockBrush = FALSE;
+    COLORREF    nBrushColor = PALETTERGB(nRed, nGreen, nBlue);
 
-    // search for stock brush (only screen, because printer have problems,
-    // when we use stock objects)
-    if ( !mrParent.isPrinter() )
+    if (mrParent.isPrinter() || !pSalData->mhDitherDIB)
+        return CreateSolidBrush(nBrushColor);
+
+    if (24 == reinterpret_cast<BITMAPINFOHEADER*>(pSalData->mpDitherDIB)->biBitCount)
     {
-        for ( sal_uInt16 i = 0; i < pSalData->mnStockBrushCount; i++ )
+        static const BYTE aOrdDither16Bit[8][8] =
+        {
+           { 0, 6, 1, 7, 0, 6, 1, 7 },
+           { 4, 2, 5, 3, 4, 2, 5, 3 },
+           { 1, 7, 0, 6, 1, 7, 0, 6 },
+           { 5, 3, 4, 2, 5, 3, 4, 2 },
+           { 0, 6, 1, 7, 0, 6, 1, 7 },
+           { 4, 2, 5, 3, 4, 2, 5, 3 },
+           { 1, 7, 0, 6, 1, 7, 0, 6 },
+           { 5, 3, 4, 2, 5, 3, 4, 2 }
+        };
+
+        BYTE* pTmp = pSalData->mpDitherDIBData;
+        long* pDitherDiff = pSalData->mpDitherDiff;
+        BYTE* pDitherLow = pSalData->mpDitherLow;
+        BYTE* pDitherHigh = pSalData->mpDitherHigh;
+
+        for(int nY = 0; nY < 8; ++nY)
         {
-            if ( nBrushColor == pSalData->maStockBrushColorAry[ i ] )
+            for(int nX = 0; nX < 8; ++nX)
             {
-                hNewBrush = pSalData->mhStockBrushAry[i];
-                bStockBrush = TRUE;
-                break;
+                const BYTE nThres = aOrdDither16Bit[nY][nX];
+                *pTmp++ = DMAP(nBlue, nThres);
+                *pTmp++ = DMAP(nGreen, nThres);
+                *pTmp++ = DMAP(nRed, nThres);
             }
         }
+
+        return CreateDIBPatternBrush(pSalData->mhDitherDIB, DIB_RGB_COLORS);
     }
 
-    // create new brush
-    if ( !hNewBrush )
-    {
-        if ( mrParent.isPrinter() || !pSalData->mhDitherDIB )
-            hNewBrush = CreateSolidBrush( nBrushColor );
-        else
-        {
-            if ( 24 == reinterpret_cast<BITMAPINFOHEADER*>(pSalData->mpDitherDIB)->biBitCount )
-            {
-                BYTE* pTmp = pSalData->mpDitherDIBData;
-                long* pDitherDiff = pSalData->mpDitherDiff;
-                BYTE* pDitherLow = pSalData->mpDitherLow;
-                BYTE* pDitherHigh = pSalData->mpDitherHigh;
+    if (ImplIsSysColorEntry(nColor))
+        return CreateSolidBrush(PALRGB_TO_RGB(nBrushColor));
 
-                for( long nY = 0L; nY < 8L; nY++ )
-                {
-                    for( long nX = 0L; nX < 8L; nX++ )
-                    {
-                        const long nThres = aOrdDither16Bit[ nY ][ nX ];
-                        *pTmp++ = DMAP( nBlue, nThres );
-                        *pTmp++ = DMAP( nGreen, nThres );
-                        *pTmp++ = DMAP( nRed, nThres );
-                    }
-                }
+    if (ImplIsPaletteEntry(nRed, nGreen, nBlue))
+        return CreateSolidBrush(nBrushColor);
 
-                hNewBrush = CreateDIBPatternBrush( pSalData->mhDitherDIB, DIB_RGB_COLORS );
-            }
-            else if ( ImplIsSysColorEntry( nColor ) )
-            {
-                nBrushColor = PALRGB_TO_RGB( nBrushColor );
-                hNewBrush = CreateSolidBrush( nBrushColor );
-            }
-            else if ( ImplIsPaletteEntry( nRed, nGreen, nBlue ) )
-                hNewBrush = CreateSolidBrush( nBrushColor );
-            else
-            {
-                BYTE* pTmp = pSalData->mpDitherDIBData;
-                long* pDitherDiff = pSalData->mpDitherDiff;
-                BYTE* pDitherLow = pSalData->mpDitherLow;
-                BYTE* pDitherHigh = pSalData->mpDitherHigh;
+    static const BYTE aOrdDither8Bit[8][8] =
+    {
+       {  0, 38,  9, 48,  2, 40, 12, 50 },
+       { 25, 12, 35, 22, 28, 15, 37, 24 },
+       {  6, 44,  3, 41,  8, 47,  5, 44 },
+       { 32, 19, 28, 16, 34, 21, 31, 18 },
+       {  1, 40, 11, 49,  0, 39, 10, 48 },
+       { 27, 14, 36, 24, 26, 13, 36, 23 },
+       {  8, 46,  4, 43,  7, 45,  4, 42 },
+       { 33, 20, 30, 17, 32, 20, 29, 16 }
+    };
 
-                for ( long nY = 0L; nY < 8L; nY++ )
-                {
-                    for ( long nX = 0L; nX < 8L; nX++ )
-                    {
-                        const long nThres = aOrdDither8Bit[ nY ][ nX ];
-                        *pTmp = DMAP( nRed, nThres ) + DMAP( nGreen, nThres ) * 6 + DMAP( nBlue, nThres ) * 36;
-                        pTmp++;
-                    }
-                }
+    BYTE* pTmp = pSalData->mpDitherDIBData;
+    long* pDitherDiff = pSalData->mpDitherDiff;
+    BYTE* pDitherLow = pSalData->mpDitherLow;
+    BYTE* pDitherHigh = pSalData->mpDitherHigh;
 
-                hNewBrush = CreateDIBPatternBrush( pSalData->mhDitherDIB, DIB_PAL_COLORS );
-            }
+    for (int nY = 0; nY < 8; ++nY)
+    {
+        for (int nX = 0; nX < 8; ++nX)
+        {
+            const BYTE nThres = aOrdDither8Bit[nY][nX];
+            *pTmp = DMAP(nRed, nThres) +
+                    DMAP(nGreen, nThres) * 6 +
+                    DMAP(nBlue, nThres) * 36;
+            pTmp++;
         }
-
-        bStockBrush = FALSE;
     }
 
-    ResetBrush(hNewBrush);
-
-    // set new data
-    mnBrushColor = nBrushColor;
-    mbBrush     = TRUE;
-    mbStockBrush = bStockBrush;
+    return CreateDIBPatternBrush(pSalData->mhDitherDIB, DIB_PAL_COLORS);
 }
 
 void WinSalGraphicsImpl::ResetBrush(HBRUSH hNewBrush)
diff --git a/vcl/win/gdi/gdiimpl.hxx b/vcl/win/gdi/gdiimpl.hxx
index 24c904f9ab54..6bee309e6ec1 100644
--- a/vcl/win/gdi/gdiimpl.hxx
+++ b/vcl/win/gdi/gdiimpl.hxx
@@ -56,6 +56,8 @@ private:
     HPEN MakePen(Color nColor, COLORREF nPenColor);
     void ResetPen(HPEN hNewPen);
 
+    HBRUSH SearchStockBrush(COLORREF nBrushColor);
+    HBRUSH MakeBrush(Color nColor);
     void ResetBrush(HBRUSH hNewBrush);
 public:
 


More information about the Libreoffice-commits mailing list