[Libreoffice-commits] core.git: 2 commits - include/svx include/vcl svtools/source svx/source vcl/source

Noel Grandin noel.grandin at collabora.co.uk
Wed Feb 14 06:29:44 UTC 2018


 include/svx/svdhdl.hxx             |    2 
 include/vcl/bitmapex.hxx           |    3 +
 svtools/source/graphic/grfmgr2.cxx |   57 --------------------------
 svx/source/svdraw/svdhdl.cxx       |   81 +++++++++++++++++--------------------
 vcl/source/gdi/bitmapex.cxx        |   55 +++++++++++++++++++++++++
 5 files changed, 99 insertions(+), 99 deletions(-)

New commits:
commit d03c6ee8d0e2f5637038cf80b890e97630b60b9e
Author: Noel Grandin <noel.grandin at collabora.co.uk>
Date:   Tue Feb 13 16:14:57 2018 +0200

    move transparency adjust code to BitmapEx
    
    part of making Bitmap an internal implementation detail of vcl/
    
    Change-Id: I6978d84c86c3d55b3ebbeacda60fd94b160daa29
    Reviewed-on: https://gerrit.libreoffice.org/49667
    Tested-by: Jenkins <ci at libreoffice.org>
    Reviewed-by: Noel Grandin <noel.grandin at collabora.co.uk>

diff --git a/include/vcl/bitmapex.hxx b/include/vcl/bitmapex.hxx
index 9faf3c8eb41c..ce45c0a6891f 100644
--- a/include/vcl/bitmapex.hxx
+++ b/include/vcl/bitmapex.hxx
@@ -441,6 +441,9 @@ public:
                             const Size &rSize );
 
     void                setAlphaFrom( sal_uInt8 cIndexFrom, sal_Int8 nAlphaTo );
+
+    void                AdjustTransparency( sal_uInt8 cTrans );
+
 public:
 
     SAL_DLLPRIVATE std::shared_ptr<ImpBitmap> const & ImplGetBitmapImpBitmap() const { return aBitmap.ImplGetImpBitmap(); }
diff --git a/svtools/source/graphic/grfmgr2.cxx b/svtools/source/graphic/grfmgr2.cxx
index 451365cd7270..584c31daa07f 100644
--- a/svtools/source/graphic/grfmgr2.cxx
+++ b/svtools/source/graphic/grfmgr2.cxx
@@ -1452,63 +1452,10 @@ void GraphicManager::ImplAdjust( BitmapEx& rBmpEx, const GraphicAttr& rAttr, Gra
         rBmpEx.Rotate( aAttr.GetRotation(), Color( COL_TRANSPARENT ) );
     }
 
-    if( !(( nAdjustmentFlags & GraphicAdjustmentFlags::TRANSPARENCY ) && aAttr.IsTransparent()) )
-        return;
-
-    AlphaMask   aAlpha;
-    sal_uInt8       cTrans = aAttr.GetTransparency();
-
-    if( !rBmpEx.IsTransparent() )
-        aAlpha = AlphaMask( rBmpEx.GetSizePixel(), &cTrans );
-    else if( !rBmpEx.IsAlpha() )
-    {
-        aAlpha = rBmpEx.GetMask();
-        aAlpha.Replace( 0, cTrans );
-    }
-    else
+    if( ( nAdjustmentFlags & GraphicAdjustmentFlags::TRANSPARENCY ) && aAttr.IsTransparent() )
     {
-        aAlpha = rBmpEx.GetAlpha();
-        BitmapWriteAccess* pA = aAlpha.AcquireWriteAccess();
-
-        if( pA )
-        {
-            sal_uLong       nTrans = cTrans, nNewTrans;
-            const long  nWidth = pA->Width(), nHeight = pA->Height();
-
-            if( pA->GetScanlineFormat() == ScanlineFormat::N8BitPal )
-            {
-                for( long nY = 0; nY < nHeight; nY++ )
-                {
-                    Scanline pAScan = pA->GetScanline( nY );
-
-                    for( long nX = 0; nX < nWidth; nX++ )
-                    {
-                        nNewTrans = nTrans + *pAScan;
-                        *pAScan++ = static_cast<sal_uInt8>( ( nNewTrans & 0xffffff00 ) ? 255 : nNewTrans );
-                    }
-                }
-            }
-            else
-            {
-                BitmapColor aAlphaValue( 0 );
-
-                for( long nY = 0; nY < nHeight; nY++ )
-                {
-                    Scanline pScanline = pA->GetScanline( nY );
-                    for( long nX = 0; nX < nWidth; nX++ )
-                    {
-                        nNewTrans = nTrans + pA->GetIndexFromData( pScanline, nX );
-                        aAlphaValue.SetIndex( static_cast<sal_uInt8>( ( nNewTrans & 0xffffff00 ) ? 255 : nNewTrans ) );
-                        pA->SetPixelOnData( pScanline, nX, aAlphaValue );
-                    }
-                }
-            }
-
-            aAlpha.ReleaseAccess( pA );
-        }
+        rBmpEx.AdjustTransparency(aAttr.GetTransparency());
     }
-
-    rBmpEx = BitmapEx( rBmpEx.GetBitmap(), aAlpha );
 }
 
 void GraphicManager::ImplAdjust( GDIMetaFile& rMtf, const GraphicAttr& rAttr, GraphicAdjustmentFlags nAdjustmentFlags )
diff --git a/vcl/source/gdi/bitmapex.cxx b/vcl/source/gdi/bitmapex.cxx
index 797319164de4..962f75cc03f4 100644
--- a/vcl/source/gdi/bitmapex.cxx
+++ b/vcl/source/gdi/bitmapex.cxx
@@ -1322,4 +1322,59 @@ void BitmapEx::setAlphaFrom( sal_uInt8 cIndexFrom, sal_Int8 nAlphaTo )
         }
     }
 }
+
+void BitmapEx::AdjustTransparency(sal_uInt8 cTrans)
+{
+    AlphaMask   aAlpha;
+
+    if( !IsTransparent() )
+        aAlpha = AlphaMask( GetSizePixel(), &cTrans );
+    else if( !IsAlpha() )
+    {
+        aAlpha = GetMask();
+        aAlpha.Replace( 0, cTrans );
+    }
+    else
+    {
+        aAlpha = GetAlpha();
+        Bitmap::ScopedWriteAccess pA(aAlpha);
+        assert(pA);
+
+        if( !pA )
+            return;
+
+        sal_uLong       nTrans = cTrans, nNewTrans;
+        const long  nWidth = pA->Width(), nHeight = pA->Height();
+
+        if( pA->GetScanlineFormat() == ScanlineFormat::N8BitPal )
+        {
+            for( long nY = 0; nY < nHeight; nY++ )
+            {
+                Scanline pAScan = pA->GetScanline( nY );
+
+                for( long nX = 0; nX < nWidth; nX++ )
+                {
+                    nNewTrans = nTrans + *pAScan;
+                    *pAScan++ = static_cast<sal_uInt8>( ( nNewTrans & 0xffffff00 ) ? 255 : nNewTrans );
+                }
+            }
+        }
+        else
+        {
+            BitmapColor aAlphaValue( 0 );
+
+            for( long nY = 0; nY < nHeight; nY++ )
+            {
+                Scanline pScanline = pA->GetScanline( nY );
+                for( long nX = 0; nX < nWidth; nX++ )
+                {
+                    nNewTrans = nTrans + pA->GetIndexFromData( pScanline, nX );
+                    aAlphaValue.SetIndex( static_cast<sal_uInt8>( ( nNewTrans & 0xffffff00 ) ? 255 : nNewTrans ) );
+                    pA->SetPixelOnData( pScanline, nX, aAlphaValue );
+                }
+            }
+        }
+    }
+    *this = BitmapEx( GetBitmap(), aAlpha );
+}
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
commit e7ed95234244b9f3a2c5c3810984627f05e73384
Author: Noel Grandin <noel.grandin at collabora.co.uk>
Date:   Tue Feb 13 15:29:19 2018 +0200

    use VirtualDevice/BitmapEx in CreateColorDropper
    
    part of making Bitmap an internal detail of vcl
    
    Change-Id: Ieec5df8976ee0e117a2388dda8ef86b018274915
    Reviewed-on: https://gerrit.libreoffice.org/49666
    Tested-by: Jenkins <ci at libreoffice.org>
    Reviewed-by: Noel Grandin <noel.grandin at collabora.co.uk>

diff --git a/include/svx/svdhdl.hxx b/include/svx/svdhdl.hxx
index c1e1452c7b85..f738a996e409 100644
--- a/include/svx/svdhdl.hxx
+++ b/include/svx/svdhdl.hxx
@@ -255,7 +255,7 @@ class SVX_DLLPUBLIC SdrHdlColor : public SdrHdl
     SVX_DLLPRIVATE virtual void CreateB2dIAObject() override;
 
     // help functions
-    SVX_DLLPRIVATE Bitmap CreateColorDropper(Color aCol);
+    SVX_DLLPRIVATE BitmapEx CreateColorDropper(Color aCol);
     SVX_DLLPRIVATE static Color GetLuminance(const Color& rCol);
 
 public:
diff --git a/svx/source/svdraw/svdhdl.cxx b/svx/source/svdraw/svdhdl.cxx
index f7fe5b520e7d..293674a88314 100644
--- a/svx/source/svdraw/svdhdl.cxx
+++ b/svx/source/svdraw/svdhdl.cxx
@@ -1114,12 +1114,12 @@ void SdrHdlColor::CreateB2dIAObject()
                         rtl::Reference< sdr::overlay::OverlayManager > xManager = rPageWindow.GetOverlayManager();
                         if (xManager.is())
                         {
-                            Bitmap aBmpCol(CreateColorDropper(aMarkerColor));
+                            BitmapEx aBmpCol(CreateColorDropper(aMarkerColor));
                             basegfx::B2DPoint aPosition(aPos.X(), aPos.Y());
                             sdr::overlay::OverlayObject* pNewOverlayObject = new
                                 sdr::overlay::OverlayBitmapEx(
                                     aPosition,
-                                    BitmapEx(aBmpCol),
+                                    aBmpCol,
                                     static_cast<sal_uInt16>(aBmpCol.GetSizePixel().Width() - 1) >> 1,
                                     static_cast<sal_uInt16>(aBmpCol.GetSizePixel().Height() - 1) >> 1
                                 );
@@ -1135,49 +1135,44 @@ void SdrHdlColor::CreateB2dIAObject()
     }
 }
 
-Bitmap SdrHdlColor::CreateColorDropper(Color aCol)
+BitmapEx SdrHdlColor::CreateColorDropper(Color aCol)
 {
     // get the Bitmap
-    Bitmap aRetval(aMarkerSize, 24);
-    aRetval.Erase(aCol);
-
-    // get write access
-    std::unique_ptr<BitmapWriteAccess> pWrite(aRetval.AcquireWriteAccess());
-    DBG_ASSERT(pWrite, "Got NO write access to a new Bitmap!");
-
-    if(pWrite)
-    {
-        // draw outer border
-        sal_Int32 nWidth = aMarkerSize.Width();
-        sal_Int32 nHeight = aMarkerSize.Height();
-
-        pWrite->SetLineColor(Color(COL_LIGHTGRAY));
-        pWrite->DrawLine(Point(0, 0), Point(0, nHeight - 1));
-        pWrite->DrawLine(Point(1, 0), Point(nWidth - 1, 0));
-        pWrite->SetLineColor(Color(COL_GRAY));
-        pWrite->DrawLine(Point(1, nHeight - 1), Point(nWidth - 1, nHeight - 1));
-        pWrite->DrawLine(Point(nWidth - 1, 1), Point(nWidth - 1, nHeight - 2));
-
-        // draw lighter UpperLeft
-        const Color aLightColor(
-            static_cast<sal_uInt8>(::std::min(static_cast<sal_Int16>(static_cast<sal_Int16>(aCol.GetRed()) + sal_Int16(0x0040)), sal_Int16(0x00ff))),
-            static_cast<sal_uInt8>(::std::min(static_cast<sal_Int16>(static_cast<sal_Int16>(aCol.GetGreen()) + sal_Int16(0x0040)), sal_Int16(0x00ff))),
-            static_cast<sal_uInt8>(::std::min(static_cast<sal_Int16>(static_cast<sal_Int16>(aCol.GetBlue()) + sal_Int16(0x0040)), sal_Int16(0x00ff))));
-        pWrite->SetLineColor(aLightColor);
-        pWrite->DrawLine(Point(1, 1), Point(1, nHeight - 2));
-        pWrite->DrawLine(Point(2, 1), Point(nWidth - 2, 1));
-
-        // draw darker LowerRight
-        const Color aDarkColor(
-            static_cast<sal_uInt8>(::std::max(static_cast<sal_Int16>(static_cast<sal_Int16>(aCol.GetRed()) - sal_Int16(0x0040)), sal_Int16(0x0000))),
-            static_cast<sal_uInt8>(::std::max(static_cast<sal_Int16>(static_cast<sal_Int16>(aCol.GetGreen()) - sal_Int16(0x0040)), sal_Int16(0x0000))),
-            static_cast<sal_uInt8>(::std::max(static_cast<sal_Int16>(static_cast<sal_Int16>(aCol.GetBlue()) - sal_Int16(0x0040)), sal_Int16(0x0000))));
-        pWrite->SetLineColor(aDarkColor);
-        pWrite->DrawLine(Point(2, nHeight - 2), Point(nWidth - 2, nHeight - 2));
-        pWrite->DrawLine(Point(nWidth - 2, 2), Point(nWidth - 2, nHeight - 3));
-    }
-
-    return aRetval;
+    VclPtr<VirtualDevice> pWrite(VclPtr<VirtualDevice>::Create());
+    pWrite->SetOutputSizePixel(aMarkerSize);
+    pWrite->SetBackground(aCol);
+    pWrite->Erase();
+
+    // draw outer border
+    sal_Int32 nWidth = aMarkerSize.Width();
+    sal_Int32 nHeight = aMarkerSize.Height();
+
+    pWrite->SetLineColor(Color(COL_LIGHTGRAY));
+    pWrite->DrawLine(Point(0, 0), Point(0, nHeight - 1));
+    pWrite->DrawLine(Point(1, 0), Point(nWidth - 1, 0));
+    pWrite->SetLineColor(Color(COL_GRAY));
+    pWrite->DrawLine(Point(1, nHeight - 1), Point(nWidth - 1, nHeight - 1));
+    pWrite->DrawLine(Point(nWidth - 1, 1), Point(nWidth - 1, nHeight - 2));
+
+    // draw lighter UpperLeft
+    const Color aLightColor(
+        static_cast<sal_uInt8>(::std::min(static_cast<sal_Int16>(static_cast<sal_Int16>(aCol.GetRed()) + sal_Int16(0x0040)), sal_Int16(0x00ff))),
+        static_cast<sal_uInt8>(::std::min(static_cast<sal_Int16>(static_cast<sal_Int16>(aCol.GetGreen()) + sal_Int16(0x0040)), sal_Int16(0x00ff))),
+        static_cast<sal_uInt8>(::std::min(static_cast<sal_Int16>(static_cast<sal_Int16>(aCol.GetBlue()) + sal_Int16(0x0040)), sal_Int16(0x00ff))));
+    pWrite->SetLineColor(aLightColor);
+    pWrite->DrawLine(Point(1, 1), Point(1, nHeight - 2));
+    pWrite->DrawLine(Point(2, 1), Point(nWidth - 2, 1));
+
+    // draw darker LowerRight
+    const Color aDarkColor(
+        static_cast<sal_uInt8>(::std::max(static_cast<sal_Int16>(static_cast<sal_Int16>(aCol.GetRed()) - sal_Int16(0x0040)), sal_Int16(0x0000))),
+        static_cast<sal_uInt8>(::std::max(static_cast<sal_Int16>(static_cast<sal_Int16>(aCol.GetGreen()) - sal_Int16(0x0040)), sal_Int16(0x0000))),
+        static_cast<sal_uInt8>(::std::max(static_cast<sal_Int16>(static_cast<sal_Int16>(aCol.GetBlue()) - sal_Int16(0x0040)), sal_Int16(0x0000))));
+    pWrite->SetLineColor(aDarkColor);
+    pWrite->DrawLine(Point(2, nHeight - 2), Point(nWidth - 2, nHeight - 2));
+    pWrite->DrawLine(Point(nWidth - 2, 2), Point(nWidth - 2, nHeight - 3));
+
+    return pWrite->GetBitmapEx(Point(0,0), aMarkerSize);
 }
 
 Color SdrHdlColor::GetLuminance(const Color& rCol)


More information about the Libreoffice-commits mailing list