[Libreoffice-commits] core.git: svtools/source vcl/source
Caolán McNamara
caolanm at redhat.com
Mon Apr 17 18:08:12 UTC 2017
svtools/source/graphic/grfmgr.cxx | 59 ++++---
vcl/source/gdi/dibtools.cxx | 311 ++++++++++++++++++--------------------
2 files changed, 188 insertions(+), 182 deletions(-)
New commits:
commit ce0e70fdd643b88b70cbcfa55847f0285116273a
Author: Caolán McNamara <caolanm at redhat.com>
Date: Mon Apr 17 16:10:42 2017 +0100
move the exception handling
Change-Id: Ie61a424a78be85c1dc54dd56451319356227f443
diff --git a/svtools/source/graphic/grfmgr.cxx b/svtools/source/graphic/grfmgr.cxx
index 07ec46fc0b5d..c271fd4d5720 100644
--- a/svtools/source/graphic/grfmgr.cxx
+++ b/svtools/source/graphic/grfmgr.cxx
@@ -943,43 +943,56 @@ bool GraphicObject::SwapOut()
bool GraphicObject::SwapOut( SvStream* pOStm )
{
- bool bRet = !mbAutoSwapped;
- // swap out as a link
- if( pOStm == GRFMGR_AUTOSWAPSTREAM_LINK )
+ bool bRet = false;
+ try
{
- maGraphic.SwapOutAsLink();
+ bRet = !mbAutoSwapped;
+ // swap out as a link
+ if( pOStm == GRFMGR_AUTOSWAPSTREAM_LINK )
+ {
+ maGraphic.SwapOutAsLink();
+ }
+ else
+ {
+ bRet = bRet && maGraphic.SwapOut( pOStm );
+ }
+
+ if (bRet)
+ mpGlobalMgr->ImplGraphicObjectWasSwappedOut(*this);
}
- else
+ catch(...)
{
- bRet = bRet && maGraphic.SwapOut( pOStm );
+ SAL_WARN( "svtools", "GraphicObject::SwapIn exception");
}
-
- if (bRet)
- mpGlobalMgr->ImplGraphicObjectWasSwappedOut(*this);
-
return bRet;
}
bool GraphicObject::SwapIn()
{
bool bRet = false;
-
- if( mbAutoSwapped )
+ try
{
- ImplAutoSwapIn();
- bRet = true;
- }
- else
- {
- bRet = maGraphic.SwapIn();
+ if( mbAutoSwapped )
+ {
+ ImplAutoSwapIn();
+ bRet = true;
+ }
+ else
+ {
+ bRet = maGraphic.SwapIn();
- if (bRet)
- mpGlobalMgr->ImplGraphicObjectWasSwappedIn(*this);
- }
+ if (bRet)
+ mpGlobalMgr->ImplGraphicObjectWasSwappedIn(*this);
+ }
- if( bRet )
+ if( bRet )
+ {
+ ImplAssignGraphicData();
+ }
+ }
+ catch (...)
{
- ImplAssignGraphicData();
+ SAL_WARN( "svtools", "GraphicObject::SwapIn exception");
}
return bRet;
diff --git a/vcl/source/gdi/dibtools.cxx b/vcl/source/gdi/dibtools.cxx
index 1b0b2aee4e11..dc3666978fb7 100644
--- a/vcl/source/gdi/dibtools.cxx
+++ b/vcl/source/gdi/dibtools.cxx
@@ -1389,192 +1389,185 @@ bool ImplWriteDIBBits(SvStream& rOStm, BitmapReadAccess& rAcc, BitmapReadAccess*
bool ImplWriteDIBBody(const Bitmap& rBitmap, SvStream& rOStm, BitmapReadAccess& rAcc, BitmapReadAccess* pAccAlpha, bool bCompressed)
{
- try
+ const MapMode aMapPixel(MapUnit::MapPixel);
+ DIBV5Header aHeader;
+ sal_uLong nImageSizePos(0);
+ sal_uLong nEndPos(0);
+ sal_uInt32 nCompression(COMPRESS_NONE);
+ bool bRet(false);
+
+ aHeader.nSize = pAccAlpha ? DIBV5HEADERSIZE : DIBINFOHEADERSIZE; // size dependent on CF_DIB type to use
+ aHeader.nWidth = rAcc.Width();
+ aHeader.nHeight = rAcc.Height();
+ aHeader.nPlanes = 1;
+
+ if(!pAccAlpha && isBitfieldCompression(rAcc.GetScanlineFormat()))
{
- const MapMode aMapPixel(MapUnit::MapPixel);
- DIBV5Header aHeader;
- sal_uLong nImageSizePos(0);
- sal_uLong nEndPos(0);
- sal_uInt32 nCompression(COMPRESS_NONE);
- bool bRet(false);
-
- aHeader.nSize = pAccAlpha ? DIBV5HEADERSIZE : DIBINFOHEADERSIZE; // size dependent on CF_DIB type to use
- aHeader.nWidth = rAcc.Width();
- aHeader.nHeight = rAcc.Height();
- aHeader.nPlanes = 1;
-
- if(!pAccAlpha && isBitfieldCompression(rAcc.GetScanlineFormat()))
- {
- aHeader.nBitCount = (ScanlineFormat::N16BitTcLsbMask == rAcc.GetScanlineFormat()) ? 16 : 32;
- aHeader.nSizeImage = rAcc.Height() * rAcc.GetScanlineSize();
- nCompression = BITFIELDS;
- }
- else
+ aHeader.nBitCount = (ScanlineFormat::N16BitTcLsbMask == rAcc.GetScanlineFormat()) ? 16 : 32;
+ aHeader.nSizeImage = rAcc.Height() * rAcc.GetScanlineSize();
+ nCompression = BITFIELDS;
+ }
+ else
+ {
+ // #i5xxx# Limit bitcount to 24bit, the 32 bit cases are
+ // not handled properly below (would have to set color
+ // masks, and nCompression=BITFIELDS - but color mask is
+ // not set for formats != *_TC_*). Note that this very
+ // problem might cause trouble at other places - the
+ // introduction of 32 bit RGBA bitmaps is relatively
+ // recent.
+ // #i59239# discretize bitcount to 1,4,8,24 (other cases
+ // are not written below)
+ const sal_uInt16 nBitCount(pAccAlpha ? 32 : discretizeBitcount(rAcc.GetBitCount()));
+ aHeader.nBitCount = nBitCount;
+ aHeader.nSizeImage = rAcc.Height() * AlignedWidth4Bytes(rAcc.Width() * aHeader.nBitCount);
+
+ if(bCompressed)
{
- // #i5xxx# Limit bitcount to 24bit, the 32 bit cases are
- // not handled properly below (would have to set color
- // masks, and nCompression=BITFIELDS - but color mask is
- // not set for formats != *_TC_*). Note that this very
- // problem might cause trouble at other places - the
- // introduction of 32 bit RGBA bitmaps is relatively
- // recent.
- // #i59239# discretize bitcount to 1,4,8,24 (other cases
- // are not written below)
- const sal_uInt16 nBitCount(pAccAlpha ? 32 : discretizeBitcount(rAcc.GetBitCount()));
- aHeader.nBitCount = nBitCount;
- aHeader.nSizeImage = rAcc.Height() * AlignedWidth4Bytes(rAcc.Width() * aHeader.nBitCount);
-
- if(bCompressed)
+ if(4 == nBitCount)
{
- if(4 == nBitCount)
- {
- nCompression = RLE_4;
- }
- else if(8 == nBitCount)
- {
- nCompression = RLE_8;
- }
+ nCompression = RLE_4;
+ }
+ else if(8 == nBitCount)
+ {
+ nCompression = RLE_8;
}
}
+ }
- if((rOStm.GetCompressMode() & SvStreamCompressFlags::ZBITMAP) && (rOStm.GetVersion() >= SOFFICE_FILEFORMAT_40))
- {
- aHeader.nCompression = ZCOMPRESS;
- }
- else
- {
- aHeader.nCompression = nCompression;
- }
+ if((rOStm.GetCompressMode() & SvStreamCompressFlags::ZBITMAP) && (rOStm.GetVersion() >= SOFFICE_FILEFORMAT_40))
+ {
+ aHeader.nCompression = ZCOMPRESS;
+ }
+ else
+ {
+ aHeader.nCompression = nCompression;
+ }
- if(rBitmap.GetPrefSize().Width() && rBitmap.GetPrefSize().Height() && (rBitmap.GetPrefMapMode() != aMapPixel))
+ if(rBitmap.GetPrefSize().Width() && rBitmap.GetPrefSize().Height() && (rBitmap.GetPrefMapMode() != aMapPixel))
+ {
+ // #i48108# Try to recover xpels/ypels as previously stored on
+ // disk. The problem with just converting maPrefSize to 100th
+ // mm and then relating that to the bitmap pixel size is that
+ // MapMode is integer-based, and suffers from roundoffs,
+ // especially if maPrefSize is small. Trying to circumvent
+ // that by performing part of the math in floating point.
+ const Size aScale100000(OutputDevice::LogicToLogic(Size(100000, 100000), MapUnit::Map100thMM, rBitmap.GetPrefMapMode()));
+ const double fBmpWidthM((double)rBitmap.GetPrefSize().Width() / aScale100000.Width());
+ const double fBmpHeightM((double)rBitmap.GetPrefSize().Height() / aScale100000.Height());
+
+ if(!basegfx::fTools::equalZero(fBmpWidthM) && !basegfx::fTools::equalZero(fBmpHeightM))
{
- // #i48108# Try to recover xpels/ypels as previously stored on
- // disk. The problem with just converting maPrefSize to 100th
- // mm and then relating that to the bitmap pixel size is that
- // MapMode is integer-based, and suffers from roundoffs,
- // especially if maPrefSize is small. Trying to circumvent
- // that by performing part of the math in floating point.
- const Size aScale100000(OutputDevice::LogicToLogic(Size(100000, 100000), MapUnit::Map100thMM, rBitmap.GetPrefMapMode()));
- const double fBmpWidthM((double)rBitmap.GetPrefSize().Width() / aScale100000.Width());
- const double fBmpHeightM((double)rBitmap.GetPrefSize().Height() / aScale100000.Height());
-
- if(!basegfx::fTools::equalZero(fBmpWidthM) && !basegfx::fTools::equalZero(fBmpHeightM))
- {
- aHeader.nXPelsPerMeter = basegfx::fround(rAcc.Width() / fabs(fBmpWidthM));
- aHeader.nYPelsPerMeter = basegfx::fround(rAcc.Height() / fabs(fBmpHeightM));
- }
+ aHeader.nXPelsPerMeter = basegfx::fround(rAcc.Width() / fabs(fBmpWidthM));
+ aHeader.nYPelsPerMeter = basegfx::fround(rAcc.Height() / fabs(fBmpHeightM));
}
+ }
- aHeader.nColsUsed = ((!pAccAlpha && aHeader.nBitCount <= 8) ? rAcc.GetPaletteEntryCount() : 0);
- aHeader.nColsImportant = 0;
+ aHeader.nColsUsed = ((!pAccAlpha && aHeader.nBitCount <= 8) ? rAcc.GetPaletteEntryCount() : 0);
+ aHeader.nColsImportant = 0;
- rOStm.WriteUInt32( aHeader.nSize );
- rOStm.WriteInt32( aHeader.nWidth );
- rOStm.WriteInt32( aHeader.nHeight );
- rOStm.WriteUInt16( aHeader.nPlanes );
- rOStm.WriteUInt16( aHeader.nBitCount );
- rOStm.WriteUInt32( aHeader.nCompression );
+ rOStm.WriteUInt32( aHeader.nSize );
+ rOStm.WriteInt32( aHeader.nWidth );
+ rOStm.WriteInt32( aHeader.nHeight );
+ rOStm.WriteUInt16( aHeader.nPlanes );
+ rOStm.WriteUInt16( aHeader.nBitCount );
+ rOStm.WriteUInt32( aHeader.nCompression );
- nImageSizePos = rOStm.Tell();
- rOStm.SeekRel( sizeof( aHeader.nSizeImage ) );
+ nImageSizePos = rOStm.Tell();
+ rOStm.SeekRel( sizeof( aHeader.nSizeImage ) );
- rOStm.WriteInt32( aHeader.nXPelsPerMeter );
- rOStm.WriteInt32( aHeader.nYPelsPerMeter );
- rOStm.WriteUInt32( aHeader.nColsUsed );
- rOStm.WriteUInt32( aHeader.nColsImportant );
+ rOStm.WriteInt32( aHeader.nXPelsPerMeter );
+ rOStm.WriteInt32( aHeader.nYPelsPerMeter );
+ rOStm.WriteUInt32( aHeader.nColsUsed );
+ rOStm.WriteUInt32( aHeader.nColsImportant );
- if(pAccAlpha) // only write DIBV5 when asked to do so
- {
- aHeader.nV5CSType = 0x57696E20; // LCS_WINDOWS_COLOR_SPACE
- aHeader.nV5Intent = 0x00000004; // LCS_GM_IMAGES
-
- rOStm.WriteUInt32( aHeader.nV5RedMask );
- rOStm.WriteUInt32( aHeader.nV5GreenMask );
- rOStm.WriteUInt32( aHeader.nV5BlueMask );
- rOStm.WriteUInt32( aHeader.nV5AlphaMask );
- rOStm.WriteUInt32( aHeader.nV5CSType );
-
- rOStm.WriteInt32( aHeader.aV5Endpoints.aXyzRed.aXyzX );
- rOStm.WriteInt32( aHeader.aV5Endpoints.aXyzRed.aXyzY );
- rOStm.WriteInt32( aHeader.aV5Endpoints.aXyzRed.aXyzZ );
- rOStm.WriteInt32( aHeader.aV5Endpoints.aXyzGreen.aXyzX );
- rOStm.WriteInt32( aHeader.aV5Endpoints.aXyzGreen.aXyzY );
- rOStm.WriteInt32( aHeader.aV5Endpoints.aXyzGreen.aXyzZ );
- rOStm.WriteInt32( aHeader.aV5Endpoints.aXyzBlue.aXyzX );
- rOStm.WriteInt32( aHeader.aV5Endpoints.aXyzBlue.aXyzY );
- rOStm.WriteInt32( aHeader.aV5Endpoints.aXyzBlue.aXyzZ );
-
- rOStm.WriteUInt32( aHeader.nV5GammaRed );
- rOStm.WriteUInt32( aHeader.nV5GammaGreen );
- rOStm.WriteUInt32( aHeader.nV5GammaBlue );
- rOStm.WriteUInt32( aHeader.nV5Intent );
- rOStm.WriteUInt32( aHeader.nV5ProfileData );
- rOStm.WriteUInt32( aHeader.nV5ProfileSize );
- rOStm.WriteUInt32( aHeader.nV5Reserved );
- }
+ if(pAccAlpha) // only write DIBV5 when asked to do so
+ {
+ aHeader.nV5CSType = 0x57696E20; // LCS_WINDOWS_COLOR_SPACE
+ aHeader.nV5Intent = 0x00000004; // LCS_GM_IMAGES
+
+ rOStm.WriteUInt32( aHeader.nV5RedMask );
+ rOStm.WriteUInt32( aHeader.nV5GreenMask );
+ rOStm.WriteUInt32( aHeader.nV5BlueMask );
+ rOStm.WriteUInt32( aHeader.nV5AlphaMask );
+ rOStm.WriteUInt32( aHeader.nV5CSType );
+
+ rOStm.WriteInt32( aHeader.aV5Endpoints.aXyzRed.aXyzX );
+ rOStm.WriteInt32( aHeader.aV5Endpoints.aXyzRed.aXyzY );
+ rOStm.WriteInt32( aHeader.aV5Endpoints.aXyzRed.aXyzZ );
+ rOStm.WriteInt32( aHeader.aV5Endpoints.aXyzGreen.aXyzX );
+ rOStm.WriteInt32( aHeader.aV5Endpoints.aXyzGreen.aXyzY );
+ rOStm.WriteInt32( aHeader.aV5Endpoints.aXyzGreen.aXyzZ );
+ rOStm.WriteInt32( aHeader.aV5Endpoints.aXyzBlue.aXyzX );
+ rOStm.WriteInt32( aHeader.aV5Endpoints.aXyzBlue.aXyzY );
+ rOStm.WriteInt32( aHeader.aV5Endpoints.aXyzBlue.aXyzZ );
+
+ rOStm.WriteUInt32( aHeader.nV5GammaRed );
+ rOStm.WriteUInt32( aHeader.nV5GammaGreen );
+ rOStm.WriteUInt32( aHeader.nV5GammaBlue );
+ rOStm.WriteUInt32( aHeader.nV5Intent );
+ rOStm.WriteUInt32( aHeader.nV5ProfileData );
+ rOStm.WriteUInt32( aHeader.nV5ProfileSize );
+ rOStm.WriteUInt32( aHeader.nV5Reserved );
+ }
+
+ if(ZCOMPRESS == aHeader.nCompression)
+ {
+ ZCodec aCodec;
+ SvMemoryStream aMemStm(aHeader.nSizeImage + 4096, 65535);
+ sal_uLong nCodedPos(rOStm.Tell());
+ sal_uLong nLastPos(0);
+ sal_uInt32 nCodedSize(0);
+ sal_uInt32 nUncodedSize(0);
- if(ZCOMPRESS == aHeader.nCompression)
+ // write uncoded data palette
+ if(aHeader.nColsUsed)
{
- ZCodec aCodec;
- SvMemoryStream aMemStm(aHeader.nSizeImage + 4096, 65535);
- sal_uLong nCodedPos(rOStm.Tell());
- sal_uLong nLastPos(0);
- sal_uInt32 nCodedSize(0);
- sal_uInt32 nUncodedSize(0);
-
- // write uncoded data palette
- if(aHeader.nColsUsed)
- {
- ImplWriteDIBPalette(aMemStm, rAcc);
- }
+ ImplWriteDIBPalette(aMemStm, rAcc);
+ }
- // write uncoded bits
- bRet = ImplWriteDIBBits(aMemStm, rAcc, pAccAlpha, nCompression, aHeader.nSizeImage);
+ // write uncoded bits
+ bRet = ImplWriteDIBBits(aMemStm, rAcc, pAccAlpha, nCompression, aHeader.nSizeImage);
- // get uncoded size
- nUncodedSize = aMemStm.Tell();
+ // get uncoded size
+ nUncodedSize = aMemStm.Tell();
- // seek over compress info
- rOStm.SeekRel(12);
+ // seek over compress info
+ rOStm.SeekRel(12);
- // write compressed data
- aCodec.BeginCompression(3);
- aCodec.Write(rOStm, static_cast<sal_uInt8 const *>(aMemStm.GetData()), nUncodedSize);
- aCodec.EndCompression();
+ // write compressed data
+ aCodec.BeginCompression(3);
+ aCodec.Write(rOStm, static_cast<sal_uInt8 const *>(aMemStm.GetData()), nUncodedSize);
+ aCodec.EndCompression();
- // update compress info ( coded size, uncoded size, uncoded compression )
- nLastPos = rOStm.Tell();
- nCodedSize = nLastPos - nCodedPos - 12;
- rOStm.Seek(nCodedPos);
- rOStm.WriteUInt32( nCodedSize ).WriteUInt32( nUncodedSize ).WriteUInt32( nCompression );
- rOStm.Seek(nLastPos);
+ // update compress info ( coded size, uncoded size, uncoded compression )
+ nLastPos = rOStm.Tell();
+ nCodedSize = nLastPos - nCodedPos - 12;
+ rOStm.Seek(nCodedPos);
+ rOStm.WriteUInt32( nCodedSize ).WriteUInt32( nUncodedSize ).WriteUInt32( nCompression );
+ rOStm.Seek(nLastPos);
- if(bRet)
- {
- bRet = (ERRCODE_NONE == rOStm.GetError());
- }
- }
- else
+ if(bRet)
{
- if(aHeader.nColsUsed)
- {
- ImplWriteDIBPalette(rOStm, rAcc);
- }
-
- bRet = ImplWriteDIBBits(rOStm, rAcc, pAccAlpha, aHeader.nCompression, aHeader.nSizeImage);
+ bRet = (ERRCODE_NONE == rOStm.GetError());
}
-
- nEndPos = rOStm.Tell();
- rOStm.Seek(nImageSizePos);
- rOStm.WriteUInt32( aHeader.nSizeImage );
- rOStm.Seek(nEndPos);
-
- return bRet;
}
- catch (...)
+ else
{
- return false;
+ if(aHeader.nColsUsed)
+ {
+ ImplWriteDIBPalette(rOStm, rAcc);
+ }
+
+ bRet = ImplWriteDIBBits(rOStm, rAcc, pAccAlpha, aHeader.nCompression, aHeader.nSizeImage);
}
+
+ nEndPos = rOStm.Tell();
+ rOStm.Seek(nImageSizePos);
+ rOStm.WriteUInt32( aHeader.nSizeImage );
+ rOStm.Seek(nEndPos);
+
+ return bRet;
}
bool ImplWriteDIBFileHeader(SvStream& rOStm, BitmapReadAccess& rAcc, bool bUseDIBV5)
More information about the Libreoffice-commits
mailing list