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

Mark Page aptitude at btconnect.com
Mon Dec 5 05:57:38 UTC 2016


 vcl/source/filter/igif/gifread.cxx    |   30 ++++++++----------------
 vcl/source/filter/ixbm/xbmread.cxx    |   11 ++------
 vcl/source/filter/ixpm/xpmread.cxx    |   42 +++++++++++-----------------------
 vcl/source/filter/jpeg/JpegWriter.cxx |    6 +---
 vcl/source/filter/jpeg/JpegWriter.hxx |    2 -
 vcl/source/filter/wmf/winwmf.cxx      |   10 +++-----
 vcl/source/gdi/alpha.cxx              |   13 ++--------
 vcl/source/gdi/pdfwriter_impl.cxx     |    8 +++---
 vcl/source/gdi/pngwrite.cxx           |   18 +++++---------
 9 files changed, 48 insertions(+), 92 deletions(-)

New commits:
commit a8b986572c288860f2076a50cdeadb1ee4aecd6d
Author: Mark Page <aptitude at btconnect.com>
Date:   Fri Dec 2 12:53:47 2016 +0000

    Change Read/Write access to Scoped Read/Write access
    
    Change-Id: I4834d057e1997710f5ac9691d6c3eecb24e26881
    Reviewed-on: https://gerrit.libreoffice.org/31550
    Tested-by: Jenkins <ci at libreoffice.org>
    Reviewed-by: Noel Grandin <noel.grandin at collabora.co.uk>

diff --git a/vcl/source/filter/igif/gifread.cxx b/vcl/source/filter/igif/gifread.cxx
index 1bfae2f..3c98628 100644
--- a/vcl/source/filter/igif/gifread.cxx
+++ b/vcl/source/filter/igif/gifread.cxx
@@ -58,8 +58,8 @@ class GIFReader : public GraphicReader
     SvStream&           rIStm;
     std::vector<sal_uInt8> aSrcBuf;
     std::unique_ptr<GIFLZWDecompressor> pDecomp;
-    BitmapWriteAccess*  pAcc8;
-    BitmapWriteAccess*  pAcc1;
+    Bitmap::ScopedWriteAccess pAcc8;
+    Bitmap::ScopedWriteAccess pAcc1;
     long                nYAcc;
     long                nLastPos;
     sal_uInt32          nLogWidth100;
@@ -113,8 +113,6 @@ GIFReader::GIFReader( SvStream& rStm )
     : aGPalette ( 256 )
     , aLPalette ( 256 )
     , rIStm ( rStm )
-    , pAcc8 ( nullptr )
-    , pAcc1 ( nullptr )
     , nYAcc ( 0 )
     , nLastPos ( rStm.Tell() )
     , nLogWidth100 ( 0UL )
@@ -150,12 +148,6 @@ GIFReader::GIFReader( SvStream& rStm )
 GIFReader::~GIFReader()
 {
     aImGraphic.SetContext( nullptr );
-
-    if( pAcc1 )
-        Bitmap::ReleaseAccess( pAcc1 );
-
-    if( pAcc8 )
-        Bitmap::ReleaseAccess( pAcc8 );
 }
 
 void GIFReader::ClearImageExtensions()
@@ -193,7 +185,7 @@ void GIFReader::CreateBitmaps( long nWidth, long nHeight, BitmapPalette* pPal,
         if( !aAnimation.Count() )
             aBmp1.Erase( aWhite );
 
-        pAcc1 = aBmp1.AcquireWriteAccess();
+        pAcc1 = Bitmap::ScopedWriteAccess(aBmp1);
 
         if( pAcc1 )
         {
@@ -213,7 +205,7 @@ void GIFReader::CreateBitmaps( long nWidth, long nHeight, BitmapPalette* pPal,
         else
           aBmp8.Erase( Color( COL_WHITE ) );
 
-        pAcc8 = aBmp8.AcquireWriteAccess();
+        pAcc8 = Bitmap::ScopedWriteAccess(aBmp8);
         bStatus = ( pAcc8 != nullptr );
     }
 }
@@ -623,13 +615,11 @@ void GIFReader::CreateNewBitmaps()
 {
     AnimationBitmap aAnimBmp;
 
-    Bitmap::ReleaseAccess( pAcc8 );
-    pAcc8 = nullptr;
+    pAcc8.reset();
 
     if( bGCTransparent )
     {
-        Bitmap::ReleaseAccess( pAcc1 );
-        pAcc1 = nullptr;
+        pAcc1.reset();
         aAnimBmp.aBmpEx = BitmapEx( aBmp8, aBmp1 );
     }
     else
@@ -664,20 +654,20 @@ const Graphic& GIFReader::GetIntermediateGraphic()
     {
         Bitmap  aBmp;
 
-        Bitmap::ReleaseAccess( pAcc8 );
+        pAcc8.reset();
 
         if ( bGCTransparent )
         {
-            Bitmap::ReleaseAccess( pAcc1 );
+            pAcc1.reset();
             aImGraphic = BitmapEx( aBmp8, aBmp1 );
 
-            pAcc1 = aBmp1.AcquireWriteAccess();
+            pAcc1 = Bitmap::ScopedWriteAccess(aBmp1);
             bStatus = bStatus && ( pAcc1 != nullptr );
         }
         else
             aImGraphic = aBmp8;
 
-        pAcc8 = aBmp8.AcquireWriteAccess();
+        pAcc8 = Bitmap::ScopedWriteAccess(aBmp8);
         bStatus = bStatus && ( pAcc8 != nullptr );
     }
 
diff --git a/vcl/source/filter/ixbm/xbmread.cxx b/vcl/source/filter/ixbm/xbmread.cxx
index 5b0741f..1c29a1f 100644
--- a/vcl/source/filter/ixbm/xbmread.cxx
+++ b/vcl/source/filter/ixbm/xbmread.cxx
@@ -38,7 +38,7 @@ class XBMReader : public GraphicReader
 {
     SvStream&           rIStm;
     Bitmap              aBmp1;
-    BitmapWriteAccess*  pAcc1;
+    Bitmap::ScopedWriteAccess pAcc1;
     short*              pHexTable;
     BitmapColor         aWhite;
     BitmapColor         aBlack;
@@ -62,7 +62,6 @@ public:
 
 XBMReader::XBMReader( SvStream& rStm ) :
             rIStm           ( rStm ),
-            pAcc1           ( nullptr ),
             nLastPos        ( rStm.Tell() ),
             nWidth          ( 0 ),
             nHeight         ( 0 ),
@@ -76,9 +75,6 @@ XBMReader::XBMReader( SvStream& rStm ) :
 XBMReader::~XBMReader()
 {
     delete[] pHexTable;
-
-    if( pAcc1 )
-        Bitmap::ReleaseAccess( pAcc1 );
 }
 
 void XBMReader::InitTable()
@@ -332,7 +328,7 @@ ReadState XBMReader::ReadXBM( Graphic& rGraphic )
                         if ( bStatus && nWidth && nHeight )
                         {
                             aBmp1 = Bitmap( Size( nWidth, nHeight ), 1 );
-                            pAcc1 = aBmp1.AcquireWriteAccess();
+                            pAcc1 = Bitmap::ScopedWriteAccess(aBmp1);
 
                             if( pAcc1 )
                             {
@@ -352,8 +348,7 @@ ReadState XBMReader::ReadXBM( Graphic& rGraphic )
         {
             Bitmap aBlackBmp( Size( pAcc1->Width(), pAcc1->Height() ), 1 );
 
-            Bitmap::ReleaseAccess( pAcc1 );
-            pAcc1 = nullptr;
+            pAcc1.reset();
             aBlackBmp.Erase( Color( COL_BLACK ) );
             rGraphic = BitmapEx( aBlackBmp, aBmp1 );
             eReadState = XBMREAD_OK;
diff --git a/vcl/source/filter/ixpm/xpmread.cxx b/vcl/source/filter/ixpm/xpmread.cxx
index 1d45b61..269f716 100644
--- a/vcl/source/filter/ixpm/xpmread.cxx
+++ b/vcl/source/filter/ixpm/xpmread.cxx
@@ -56,12 +56,12 @@ class XPMReader : public GraphicReader
 {
 private:
 
-    SvStream&           mrIStm;
-    Bitmap              maBmp;
-    BitmapWriteAccess*  mpAcc;
-    Bitmap              maMaskBmp;
-    BitmapWriteAccess*  mpMaskAcc;
-    long                mnLastPos;
+    SvStream&                   mrIStm;
+    Bitmap                      maBmp;
+    Bitmap::ScopedWriteAccess   mpAcc;
+    Bitmap                      maMaskBmp;
+    Bitmap::ScopedWriteAccess   mpMaskAcc;
+    long                        mnLastPos;
 
     sal_uLong               mnWidth;
     sal_uLong               mnHeight;
@@ -102,8 +102,6 @@ public:
 
 XPMReader::XPMReader(SvStream& rStm)
     : mrIStm(rStm)
-    , mpAcc(nullptr)
-    , mpMaskAcc(nullptr)
     , mnLastPos(rStm.Tell())
     , mnWidth(0)
     , mnHeight(0)
@@ -129,8 +127,6 @@ XPMReader::XPMReader(SvStream& rStm)
 
 XPMReader::~XPMReader()
 {
-    if( mpAcc )
-        Bitmap::ReleaseAccess( mpAcc );
 }
 
 ReadState XPMReader::ReadXPM( Graphic& rGraphic )
@@ -199,13 +195,14 @@ ReadState XPMReader::ReadXPM( Graphic& rGraphic )
                         nBits = 1;
 
                     maBmp = Bitmap( Size( mnWidth, mnHeight ), nBits );
-                    mpAcc = maBmp.AcquireWriteAccess();
+                    mpAcc = Bitmap::ScopedWriteAccess(maBmp);
 
                     // mbTransparent is TRUE if at least one colour is transparent
                     if ( mbTransparent )
                     {
                         maMaskBmp = Bitmap( Size( mnWidth, mnHeight ), 1 );
-                        if ( ( mpMaskAcc = maMaskBmp.AcquireWriteAccess() ) == nullptr )
+                        mpMaskAcc = Bitmap::ScopedWriteAccess(maMaskBmp);
+                        if ( !mpMaskAcc )
                             mbStatus = false;
                     }
                     if( mpAcc && mbStatus )
@@ -256,34 +253,23 @@ ReadState XPMReader::ReadXPM( Graphic& rGraphic )
         }
         if( mbStatus )
         {
+            mpAcc.reset();
             if ( mpMaskAcc )
             {
-                Bitmap::ReleaseAccess ( mpMaskAcc);
-                mpMaskAcc = nullptr;
-                Bitmap::ReleaseAccess( mpAcc );
-                mpAcc = nullptr;
+                mpMaskAcc.reset();
                 rGraphic = Graphic( BitmapEx( maBmp, maMaskBmp ) );
             }
             else
             {
-                Bitmap::ReleaseAccess( mpAcc );
-                mpAcc = nullptr;
                 rGraphic = maBmp;
             }
             eReadState = XPMREAD_OK;
         }
         else
         {
-            if ( mpMaskAcc )
-            {
-                Bitmap::ReleaseAccess ( mpMaskAcc);
-                mpMaskAcc = nullptr;
-            }
-            if ( mpAcc )
-            {
-                Bitmap::ReleaseAccess( mpAcc );
-                mpAcc = nullptr;
-            }
+            mpMaskAcc.reset();
+            mpAcc.reset();
+
             eReadState = XPMREAD_ERROR;
         }
     }
diff --git a/vcl/source/filter/jpeg/JpegWriter.cxx b/vcl/source/filter/jpeg/JpegWriter.cxx
index d25bf89..c2b5308 100644
--- a/vcl/source/filter/jpeg/JpegWriter.cxx
+++ b/vcl/source/filter/jpeg/JpegWriter.cxx
@@ -105,7 +105,6 @@ void jpeg_svstream_dest (j_compress_ptr cinfo, void* output)
 
 JPEGWriter::JPEGWriter( SvStream& rStream, const css::uno::Sequence< css::beans::PropertyValue >* pFilterData, bool* pExportWasGrey ) :
     mrStream     ( rStream ),
-    mpReadAccess ( nullptr ),
     mpBuffer     ( nullptr ),
     mbNative     ( false ),
     mpExpWasGrey ( pExportWasGrey )
@@ -198,7 +197,7 @@ bool JPEGWriter::Write( const Graphic& rGraphic )
             aGraphicBmp = rGraphic.GetBitmap();
     }
 
-    mpReadAccess = aGraphicBmp.AcquireReadAccess();
+    mpReadAccess = Bitmap::ScopedReadAccess(aGraphicBmp);
     if( mpReadAccess )
     {
         if ( !mbGreys )  // bitmap was not explicitly converted into greyscale,
@@ -236,8 +235,7 @@ bool JPEGWriter::Write( const Graphic& rGraphic )
         delete[] mpBuffer;
         mpBuffer = nullptr;
 
-        Bitmap::ReleaseAccess( mpReadAccess );
-        mpReadAccess = nullptr;
+        mpReadAccess.reset();
     }
     if ( mxStatusIndicator.is() )
         mxStatusIndicator->end();
diff --git a/vcl/source/filter/jpeg/JpegWriter.hxx b/vcl/source/filter/jpeg/JpegWriter.hxx
index e5600e4..94e3ee2 100644
--- a/vcl/source/filter/jpeg/JpegWriter.hxx
+++ b/vcl/source/filter/jpeg/JpegWriter.hxx
@@ -29,7 +29,7 @@
 class JPEGWriter final
 {
     SvStream&           mrStream;
-    BitmapReadAccess*   mpReadAccess;
+    Bitmap::ScopedReadAccess mpReadAccess;
     sal_uInt8*          mpBuffer;
     bool                mbNative;
     bool                mbGreys;
diff --git a/vcl/source/filter/wmf/winwmf.cxx b/vcl/source/filter/wmf/winwmf.cxx
index f1b907f..757da51 100644
--- a/vcl/source/filter/wmf/winwmf.cxx
+++ b/vcl/source/filter/wmf/winwmf.cxx
@@ -651,8 +651,7 @@ void WMFReader::ReadRecordParams( sal_uInt16 nFunc )
             if (bOk)
             {
                 Bitmap aBmp( Size( nWidth, nHeight ), nBitCount );
-                BitmapWriteAccess* pAcc;
-                pAcc = aBmp.AcquireWriteAccess();
+                Bitmap::ScopedWriteAccess pAcc(aBmp);
                 if ( pAcc )
                 {
                     for (sal_uInt16 y = 0; y < nHeight && pWMF->good(); ++y)
@@ -672,7 +671,7 @@ void WMFReader::ReadRecordParams( sal_uInt16 nFunc )
                             }
                         }
                     }
-                    Bitmap::ReleaseAccess( pAcc );
+                    pAcc.reset();
                     if ( nSye && nSxe &&
                         ( ( nSx + nSxe ) <= aBmp.GetSizePixel().Width() ) &&
                             ( ( nSy + nSye <= aBmp.GetSizePixel().Height() ) ) )
@@ -740,14 +739,13 @@ void WMFReader::ReadRecordParams( sal_uInt16 nFunc )
         case W_META_DIBCREATEPATTERNBRUSH:
         {
             Bitmap  aBmp;
-            BitmapReadAccess* pBmp;
             sal_uInt32  nRed = 0, nGreen = 0, nBlue = 0, nCount = 1;
             sal_uInt16  nFunction = 0;
 
             pWMF->ReadUInt16( nFunction ).ReadUInt16( nFunction );
 
             ReadDIB(aBmp, *pWMF, false);
-            pBmp = aBmp.AcquireReadAccess();
+            Bitmap::ScopedReadAccess pBmp(aBmp);
             if ( pBmp )
             {
                 for ( long y = 0; y < pBmp->Height(); y++ )
@@ -764,7 +762,7 @@ void WMFReader::ReadRecordParams( sal_uInt16 nFunc )
                 nCount = pBmp->Height() * pBmp->Width();
                 if ( !nCount )
                     nCount++;
-                Bitmap::ReleaseAccess( pBmp );
+                pBmp.reset();
             }
             Color aColor( (sal_uInt8)( nRed / nCount ), (sal_uInt8)( nGreen / nCount ), (sal_uInt8)( nBlue / nCount ) );
             pOut->CreateObject(o3tl::make_unique<WinMtfFillStyle>( aColor, false ));
diff --git a/vcl/source/gdi/alpha.cxx b/vcl/source/gdi/alpha.cxx
index d88d093..1289016 100644
--- a/vcl/source/gdi/alpha.cxx
+++ b/vcl/source/gdi/alpha.cxx
@@ -88,8 +88,8 @@ bool AlphaMask::Erase( sal_uInt8 cTransparency )
 
 bool AlphaMask::Replace( const Bitmap& rMask, sal_uInt8 cReplaceTransparency )
 {
-    BitmapReadAccess*   pMaskAcc = ( (Bitmap&) rMask ).AcquireReadAccess();
-    BitmapWriteAccess*  pAcc = AcquireWriteAccess();
+    Bitmap::ScopedReadAccess pMaskAcc( const_cast<Bitmap&>(rMask) );
+    AlphaMask::ScopedWriteAccess pAcc(*this);
     bool                bRet = false;
 
     if( pMaskAcc && pAcc )
@@ -104,16 +104,12 @@ bool AlphaMask::Replace( const Bitmap& rMask, sal_uInt8 cReplaceTransparency )
                 if( pMaskAcc->GetPixel( nY, nX ) == aMaskWhite )
                     pAcc->SetPixel( nY, nX, aReplace );
     }
-
-    Bitmap::ReleaseAccess( pMaskAcc );
-    ReleaseAccess( pAcc );
-
     return bRet;
 }
 
 bool AlphaMask::Replace( sal_uInt8 cSearchTransparency, sal_uInt8 cReplaceTransparency )
 {
-    BitmapWriteAccess*  pAcc = AcquireWriteAccess();
+    AlphaMask::ScopedWriteAccess pAcc(*this);
     bool                bRet = false;
 
     if( pAcc && pAcc->GetBitCount() == 8 )
@@ -150,9 +146,6 @@ bool AlphaMask::Replace( sal_uInt8 cSearchTransparency, sal_uInt8 cReplaceTransp
         bRet = true;
     }
 
-    if( pAcc )
-        ReleaseAccess( pAcc );
-
     return bRet;
 }
 
diff --git a/vcl/source/gdi/pdfwriter_impl.cxx b/vcl/source/gdi/pdfwriter_impl.cxx
index c3c3bc4..d075984 100644
--- a/vcl/source/gdi/pdfwriter_impl.cxx
+++ b/vcl/source/gdi/pdfwriter_impl.cxx
@@ -293,11 +293,11 @@ void doTestCode()
 
     // prepare an alpha mask
     Bitmap aTransMask( Size( 256, 256 ), 8, &Bitmap::GetGreyPalette( 256 ) );
-    BitmapWriteAccess* pAcc = aTransMask.AcquireWriteAccess();
+    Bitmap::ScopedWriteAccess pAcc(aTransMask);
     for( int nX = 0; nX < 256; nX++ )
         for( int nY = 0; nY < 256; nY++ )
             pAcc->SetPixel( nX, nY, BitmapColor( (sal_uInt8)((nX+nY)/2) ) );
-    aTransMask.ReleaseAccess( pAcc );
+    pAcc.reset();
     aTransMask.SetPrefMapMode( MapUnit::MapMM );
     aTransMask.SetPrefSize( Size( 10, 10 ) );
 
@@ -317,10 +317,10 @@ void doTestCode()
     aWriter.DrawRect( aTranspRect );
 
     Bitmap aImageBmp( Size( 256, 256 ), 24 );
-    pAcc = aImageBmp.AcquireWriteAccess();
+    pAcc = Bitmap::ScopedWriteAccess(aImageBmp);
     pAcc->SetFillColor( Color( 0xff, 0, 0xff ) );
     pAcc->FillRect( Rectangle( Point( 0, 0 ), Size( 256, 256 ) ) );
-    aImageBmp.ReleaseAccess( pAcc );
+    pAcc.reset();
     BitmapEx aBmpEx( aImageBmp, AlphaMask( aTransMask ) );
     aWriter.DrawBitmapEx( Point( 1500, 19500 ), Size( 4800, 3000 ), aBmpEx );
 
diff --git a/vcl/source/gdi/pngwrite.cxx b/vcl/source/gdi/pngwrite.cxx
index 20c4079..433b97b 100644
--- a/vcl/source/gdi/pngwrite.cxx
+++ b/vcl/source/gdi/pngwrite.cxx
@@ -66,7 +66,7 @@ private:
     sal_uInt32 mnMaxChunkSize;
     bool mbStatus;
 
-    BitmapReadAccess* mpAccess;
+    Bitmap::ScopedReadAccess mpAccess;
     BitmapReadAccess* mpMaskAccess;
     ZCodec mpZCodec;
 
@@ -102,7 +102,6 @@ PNGWriterImpl::PNGWriterImpl( const BitmapEx& rBmpEx,
     , mnInterlaced(0)
     , mnMaxChunkSize(0)
     , mbStatus(true)
-    , mpAccess(nullptr)
     , mpMaskAccess(nullptr)
     , mpDeflateInBuf(nullptr)
     , mpPreviousScan(nullptr)
@@ -157,7 +156,7 @@ PNGWriterImpl::PNGWriterImpl( const BitmapEx& rBmpEx,
                 aBmp.Convert(BMP_CONVERSION_8BIT_TRANS);
                 aBmp.Replace(rBmpEx.GetMask(), BMP_COL_TRANS);
                 mnBitsPerPixel = 8;
-                mpAccess = aBmp.AcquireReadAccess();
+                mpAccess = Bitmap::ScopedReadAccess(aBmp);
                 if (mpAccess)
                 {
                     if (ImplWriteHeader())
@@ -167,8 +166,7 @@ PNGWriterImpl::PNGWriterImpl( const BitmapEx& rBmpEx,
                         ImplWriteTransparent();
                         ImplWriteIDAT();
                     }
-                    Bitmap::ReleaseAccess(mpAccess);
-                    mpAccess = nullptr;
+                    mpAccess.reset();
                 }
                 else
                 {
@@ -177,7 +175,7 @@ PNGWriterImpl::PNGWriterImpl( const BitmapEx& rBmpEx,
             }
             else
             {
-                mpAccess = aBmp.AcquireReadAccess(); // true RGB with alphachannel
+                mpAccess = Bitmap::ScopedReadAccess(aBmp); // true RGB with alphachannel
                 if (mpAccess)
                 {
                     mbTrueAlpha = rBmpEx.IsAlpha();
@@ -219,8 +217,7 @@ PNGWriterImpl::PNGWriterImpl( const BitmapEx& rBmpEx,
                             mbStatus = false;
                         }
                     }
-                    Bitmap::ReleaseAccess(mpAccess);
-                    mpAccess = nullptr;
+                    mpAccess.reset();
                 }
                 else
                 {
@@ -230,7 +227,7 @@ PNGWriterImpl::PNGWriterImpl( const BitmapEx& rBmpEx,
         }
         else
         {
-            mpAccess = aBmp.AcquireReadAccess(); // palette + RGB without alphachannel
+            mpAccess = Bitmap::ScopedReadAccess(aBmp); // palette + RGB without alphachannel
             if (mpAccess)
             {
                 if (ImplWriteHeader())
@@ -241,8 +238,7 @@ PNGWriterImpl::PNGWriterImpl( const BitmapEx& rBmpEx,
 
                     ImplWriteIDAT();
                 }
-                Bitmap::ReleaseAccess(mpAccess);
-                mpAccess = nullptr;
+                mpAccess.reset();
             }
             else
             {


More information about the Libreoffice-commits mailing list