diff options
author | Mark Page <aptitude@btconnect.com> | 2016-12-02 12:53:47 +0000 |
---|---|---|
committer | Ashod Nakashian <ashod.nakashian@collabora.co.uk> | 2017-11-28 00:12:43 -0500 |
commit | a0417abfb7a468310587132e84fe1ea3a2e955bd (patch) | |
tree | 12c755cd085da10f301dda6e36c5e883a37f852a /vcl | |
parent | 2fe8cce9f46d987e744d8f74519226a550dbae5a (diff) |
Change Read/Write access to Scoped Read/Write access
Change-Id: I4834d057e1997710f5ac9691d6c3eecb24e26881
Reviewed-on: https://gerrit.libreoffice.org/31550
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
(cherry picked from commit a8b986572c288860f2076a50cdeadb1ee4aecd6d)
Diffstat (limited to 'vcl')
-rw-r--r-- | vcl/source/filter/igif/gifread.cxx | 30 | ||||
-rw-r--r-- | vcl/source/filter/ixbm/xbmread.cxx | 11 | ||||
-rw-r--r-- | vcl/source/filter/ixpm/xpmread.cxx | 42 | ||||
-rw-r--r-- | vcl/source/filter/jpeg/JpegWriter.cxx | 6 | ||||
-rw-r--r-- | vcl/source/filter/jpeg/JpegWriter.hxx | 2 | ||||
-rw-r--r-- | vcl/source/filter/wmf/winwmf.cxx | 10 | ||||
-rw-r--r-- | vcl/source/gdi/alpha.cxx | 13 | ||||
-rw-r--r-- | vcl/source/gdi/pdfwriter_impl.cxx | 8 | ||||
-rw-r--r-- | vcl/source/gdi/pngwrite.cxx | 18 |
9 files changed, 48 insertions, 92 deletions
diff --git a/vcl/source/filter/igif/gifread.cxx b/vcl/source/filter/igif/gifread.cxx index c8dd766704f6..0cf4b5062f54 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 15931a6af8c7..84555f469ddc 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 6aaaa1c828ee..c449116d29d3 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 ) @@ -198,13 +194,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 ) @@ -257,34 +254,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 d25bf89406d6..c2b5308ce50a 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 e5600e4e49cc..94e3ee2df09e 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 ce836587648a..2493c4d242fd 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 d88d093e7545..128901612acb 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 eba705f95a3b..c51caa91417c 100644 --- a/vcl/source/gdi/pdfwriter_impl.cxx +++ b/vcl/source/gdi/pdfwriter_impl.cxx @@ -295,11 +295,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 ) ); @@ -319,10 +319,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 eddcaf7c81bb..108e412a5640 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) { if ((mbTrueAlpha = rBmpEx.IsAlpha())) @@ -218,8 +216,7 @@ PNGWriterImpl::PNGWriterImpl( const BitmapEx& rBmpEx, mbStatus = false; } } - Bitmap::ReleaseAccess(mpAccess); - mpAccess = nullptr; + mpAccess.reset(); } else { @@ -229,7 +226,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()) @@ -240,8 +237,7 @@ PNGWriterImpl::PNGWriterImpl( const BitmapEx& rBmpEx, ImplWriteIDAT(); } - Bitmap::ReleaseAccess(mpAccess); - mpAccess = nullptr; + mpAccess.reset(); } else { |