unroll code for early returns, no logic changed intended
Change-Id: Ic1cc63a5fe3ad2c949f91c395c00f5f99bd7602a
This commit is contained in:
parent
6aa482428e
commit
218179ddbf
@ -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 )
|
||||
{
|
||||
const sal_uInt16 nColors = ( nBitCount <= 8 ) ? ( 1 << nBitCount ) : 0;
|
||||
if(!pDIB)
|
||||
return nullptr;
|
||||
|
||||
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];
|
||||
#ifdef __SANITIZE_ADDRESS__
|
||||
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;
|
||||
}
|
||||
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;
|
||||
}
|
||||
}
|
||||
else
|
||||
|
||||
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
|
||||
#endif
|
||||
{
|
||||
std::memset(pDIB->mpBits, 0, size);
|
||||
}
|
||||
}
|
||||
catch (const std::bad_alloc&)
|
||||
{
|
||||
delete pDIB;
|
||||
pDIB = nullptr;
|
||||
}
|
||||
|
||||
return pDIB;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user