summaryrefslogtreecommitdiff
path: root/vcl/headless/svpbmp.cxx
diff options
context:
space:
mode:
authorCaolán McNamara <caolanm@redhat.com>2016-12-23 17:53:50 +0000
committerCaolán McNamara <caolanm@redhat.com>2016-12-23 17:54:34 +0000
commit218179ddbffbc4d4a1e96dfaeebca19cffda5f9c (patch)
treedadef3c8a95653d9c9d3d36de470a3c87c561515 /vcl/headless/svpbmp.cxx
parent6aa482428ec301cfe45672d38b038fc92de7c4a7 (diff)
unroll code for early returns, no logic changed intended
Change-Id: Ic1cc63a5fe3ad2c949f91c395c00f5f99bd7602a
Diffstat (limited to 'vcl/headless/svpbmp.cxx')
-rw-r--r--vcl/headless/svpbmp.cxx154
1 files changed, 76 insertions, 78 deletions
diff --git a/vcl/headless/svpbmp.cxx b/vcl/headless/svpbmp.cxx
index 202d63c0a84e..10a45967cee0 100644
--- a/vcl/headless/svpbmp.cxx
+++ b/vcl/headless/svpbmp.cxx
@@ -53,97 +53,95 @@ BitmapBuffer* ImplCreateDIB(
|| nBitCount == 32)
&& "Unsupported BitCount!");
+ if (!rSize.Width() || !rSize.Height())
+ return nullptr;
+
BitmapBuffer* pDIB = nullptr;
- if( rSize.Width() && rSize.Height() )
+ try
{
- try
- {
- pDIB = new BitmapBuffer;
- }
- catch (const std::bad_alloc&)
- {
- pDIB = nullptr;
- }
+ pDIB = new BitmapBuffer;
+ }
+ catch (const std::bad_alloc&)
+ {
+ pDIB = nullptr;
+ }
- if( pDIB )
+ if(!pDIB)
+ return nullptr;
+
+ const sal_uInt16 nColors = ( nBitCount <= 8 ) ? ( 1 << nBitCount ) : 0;
+
+ switch (nBitCount)
+ {
+ case 1:
+ pDIB->mnFormat = ScanlineFormat::N1BitLsbPal;
+ break;
+ case 4:
+ pDIB->mnFormat = ScanlineFormat::N4BitMsnPal;
+ break;
+ case 8:
+ pDIB->mnFormat = ScanlineFormat::N8BitPal;
+ break;
+ case 16:
{
- const sal_uInt16 nColors = ( nBitCount <= 8 ) ? ( 1 << nBitCount ) : 0;
-
- switch (nBitCount)
- {
- case 1:
- pDIB->mnFormat = ScanlineFormat::N1BitLsbPal;
- break;
- case 4:
- pDIB->mnFormat = ScanlineFormat::N4BitMsnPal;
- break;
- case 8:
- pDIB->mnFormat = ScanlineFormat::N8BitPal;
- break;
- case 16:
- {
#ifdef OSL_BIGENDIAN
- pDIB->mnFormat= ScanlineFormat::N16BitTcMsbMask;
+ pDIB->mnFormat= ScanlineFormat::N16BitTcMsbMask;
#else
- pDIB->mnFormat= ScanlineFormat::N16BitTcLsbMask;
+ pDIB->mnFormat= ScanlineFormat::N16BitTcLsbMask;
#endif
- ColorMaskElement aRedMask(0xf800);
- aRedMask.CalcMaskShift();
- ColorMaskElement aGreenMask(0x07e0);
- aGreenMask.CalcMaskShift();
- ColorMaskElement aBlueMask(0x001f);
- aBlueMask.CalcMaskShift();
- pDIB->maColorMask = ColorMask(aRedMask, aGreenMask, aBlueMask);
- break;
- }
- default:
- nBitCount = 32;
- SAL_FALLTHROUGH;
- case 32:
- {
- pDIB->mnFormat = SVP_CAIRO_FORMAT;
- break;
- }
- }
-
- pDIB->mnFormat |= ScanlineFormat::TopDown;
- pDIB->mnWidth = rSize.Width();
- pDIB->mnHeight = rSize.Height();
- pDIB->mnScanlineSize = AlignedWidth4Bytes( pDIB->mnWidth * nBitCount );
- pDIB->mnBitCount = nBitCount;
-
- if( nColors )
- {
- pDIB->maPalette = rPal;
- pDIB->maPalette.SetEntryCount( nColors );
- }
-
- try
- {
- size_t size = pDIB->mnScanlineSize * pDIB->mnHeight;
- pDIB->mpBits = new sal_uInt8[size];
+ ColorMaskElement aRedMask(0xf800);
+ aRedMask.CalcMaskShift();
+ ColorMaskElement aGreenMask(0x07e0);
+ aGreenMask.CalcMaskShift();
+ ColorMaskElement aBlueMask(0x001f);
+ aBlueMask.CalcMaskShift();
+ pDIB->maColorMask = ColorMask(aRedMask, aGreenMask, aBlueMask);
+ break;
+ }
+ default:
+ nBitCount = 32;
+ SAL_FALLTHROUGH;
+ case 32:
+ {
+ pDIB->mnFormat = SVP_CAIRO_FORMAT;
+ break;
+ }
+ }
+
+ pDIB->mnFormat |= ScanlineFormat::TopDown;
+ pDIB->mnWidth = rSize.Width();
+ pDIB->mnHeight = rSize.Height();
+ pDIB->mnScanlineSize = AlignedWidth4Bytes( pDIB->mnWidth * nBitCount );
+ pDIB->mnBitCount = nBitCount;
+
+ if( nColors )
+ {
+ pDIB->maPalette = rPal;
+ pDIB->maPalette.SetEntryCount( nColors );
+ }
+
+ try
+ {
+ size_t size = pDIB->mnScanlineSize * pDIB->mnHeight;
+ pDIB->mpBits = new sal_uInt8[size];
#ifdef __SANITIZE_ADDRESS__
- if (!pDIB->mpBits)
- { // can only happen with ASAN allocator_may_return_null=1
- delete pDIB;
- pDIB = nullptr;
- }
- else
+ if (!pDIB->mpBits)
+ { // can only happen with ASAN allocator_may_return_null=1
+ delete pDIB;
+ pDIB = nullptr;
+ }
+ else
#endif
- {
- std::memset(pDIB->mpBits, 0, size);
- }
- }
- catch (const std::bad_alloc&)
- {
- delete pDIB;
- pDIB = nullptr;
- }
+ {
+ std::memset(pDIB->mpBits, 0, size);
}
}
- else
+ catch (const std::bad_alloc&)
+ {
+ delete pDIB;
pDIB = nullptr;
+ }
return pDIB;
}