Kaydet (Commit) 64e6e7c6 authored tarafından Mark Page's avatar Mark Page Kaydeden (comit) Michael Stahl

Use smart pointers for gdi pdf functions

Change-Id: Ia78adfbd0d07449e12a7e0d02acf8a1a1108437c
Reviewed-on: https://gerrit.libreoffice.org/31421Tested-by: 's avatarJenkins <ci@libreoffice.org>
Reviewed-by: 's avatarMichael Stahl <mstahl@redhat.com>
üst 0de5101d
......@@ -39,6 +39,7 @@
#include <cppuhelper/implbase.hxx>
#include <i18nlangtag/languagetag.hxx>
#include <o3tl/numeric.hxx>
#include <o3tl/make_unique.hxx>
#include <osl/file.hxx>
#include <osl/thread.h>
#include <rtl/crc.h>
......@@ -1722,8 +1723,6 @@ void PDFWriterImpl::PDFPage::appendWaveLine( sal_Int32 nWidth, sal_Int32 nY, sal
m_aContext(rContext),
m_aFile(m_aContext.URL),
m_bOpen(false),
m_pCodec( nullptr ),
m_pMemStream(nullptr),
m_aDocDigest( rtl_digest_createMD5() ),
m_aCipher( nullptr ),
m_aDigest( nullptr ),
......@@ -2139,8 +2138,8 @@ void PDFWriterImpl::beginCompression()
{
if (!g_bDebugDisableCompression)
{
m_pCodec = new ZCodec( 0x4000, 0x4000 );
m_pMemStream = new SvMemoryStream();
m_pCodec = o3tl::make_unique<ZCodec>( 0x4000, 0x4000 );
m_pMemStream = o3tl::make_unique<SvMemoryStream>();
m_pCodec->BeginCompression();
}
}
......@@ -2150,13 +2149,11 @@ void PDFWriterImpl::endCompression()
if (!g_bDebugDisableCompression && m_pCodec)
{
m_pCodec->EndCompression();
delete m_pCodec;
m_pCodec = nullptr;
m_pCodec.reset();
sal_uInt64 nLen = m_pMemStream->Tell();
m_pMemStream->Seek( 0 );
writeBuffer( m_pMemStream->GetData(), nLen );
delete m_pMemStream;
m_pMemStream = nullptr;
m_pMemStream.reset();
}
}
......
......@@ -713,8 +713,8 @@ private:
std::list< GraphicsState > m_aGraphicsStack;
GraphicsState m_aCurrentPDFState;
ZCodec* m_pCodec;
SvMemoryStream* m_pMemStream;
std::unique_ptr<ZCodec> m_pCodec;
std::unique_ptr<SvMemoryStream> m_pMemStream;
std::vector< PDFAddStream > m_aAdditionalStreams;
std::set< PDFWriter::ErrorCode > m_aErrors;
......
......@@ -28,6 +28,7 @@
#include <vcl/svapp.hxx>
#include <vcl/alpha.hxx>
#include <osl/endian.h>
#include <o3tl/make_unique.hxx>
namespace vcl
{
......@@ -74,11 +75,12 @@ private:
std::vector<vcl::PNGReader::ChunkData>::iterator maChunkIter;
std::vector<sal_uInt8>::iterator maDataIter;
Bitmap* mpBmp;
BitmapWriteAccess* mpAcc;
Bitmap* mpMaskBmp;
AlphaMask* mpAlphaMask;
BitmapWriteAccess* mpMaskAcc;
std::unique_ptr<Bitmap> mpBmp;
BitmapWriteAccess* mpAcc;
std::unique_ptr<Bitmap> mpMaskBmp;
std::unique_ptr<AlphaMask> mpAlphaMask;
BitmapWriteAccess* mpMaskAcc;
ZCodec mpZCodec;
sal_uInt8* mpInflateInBuf; // as big as the size of a scanline + alphachannel + 1
sal_uInt8* mpScanPrior; // pointer to the latest scanline
......@@ -165,10 +167,7 @@ public:
PNGReaderImpl::PNGReaderImpl( SvStream& rPNGStream )
: mrPNGStream( rPNGStream ),
mpBmp ( nullptr ),
mpAcc ( nullptr ),
mpMaskBmp ( nullptr ),
mpAlphaMask ( nullptr ),
mpMaskAcc ( nullptr ),
mpInflateInBuf ( nullptr ),
mpScanPrior ( nullptr ),
......@@ -246,9 +245,6 @@ PNGReaderImpl::~PNGReaderImpl()
if( mpColorTable != mpDefaultColorTable )
delete[] mpColorTable;
delete mpBmp;
delete mpAlphaMask;
delete mpMaskBmp;
delete[] mpTransTab;
delete[] mpInflateInBuf;
delete[] mpScanPrior;
......@@ -665,14 +661,14 @@ bool PNGReaderImpl::ImplReadHeader( const Size& rPreviewSizeHint )
if ( !mpInflateInBuf || !mpScanPrior )
return false;
mpBmp = new Bitmap( maTargetSize, mnTargetDepth );
mpBmp = o3tl::make_unique<Bitmap>( maTargetSize, mnTargetDepth );
mpAcc = mpBmp->AcquireWriteAccess();
if( !mpAcc )
return false;
if ( mbAlphaChannel )
{
mpAlphaMask = new AlphaMask( maTargetSize );
mpAlphaMask = o3tl::make_unique<AlphaMask>( maTargetSize );
mpAlphaMask->Erase( 128 );
mpMaskAcc = mpAlphaMask->AcquireWriteAccess();
if( !mpMaskAcc )
......@@ -789,12 +785,12 @@ bool PNGReaderImpl::ImplReadTransparent()
{
if( bNeedAlpha)
{
mpAlphaMask = new AlphaMask( maTargetSize );
mpAlphaMask = o3tl::make_unique<AlphaMask>( maTargetSize );
mpMaskAcc = mpAlphaMask->AcquireWriteAccess();
}
else
{
mpMaskBmp = new Bitmap( maTargetSize, 1 );
mpMaskBmp = o3tl::make_unique<Bitmap>( maTargetSize, 1 );
mpMaskAcc = mpMaskBmp->AcquireWriteAccess();
}
mbTransparent = (mpMaskAcc != nullptr);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment