svp: deduplicate bitcount->colourspace mapping and allow overriding.
Although svp defaults to BGR, we might want to use alternative formats (e.g. for tiled rendering to bitmap buffers which are to be used in e.g. gtk), it is probably safest to keep the current defaults but allow the user to change to whatever format they may require. (This currently only makes sense for the 32-bit RGBA/ARGB/etc. formats. However the 23 bit formats could potentially be expanded to allow a similar RGB/BGR choice.) Change-Id: I70bd3d6e7d297faef163b910f576655efee4cb3f
This commit is contained in:
parent
dbf426edea
commit
e82d491263
@ -20,6 +20,7 @@
|
||||
#ifndef IOS
|
||||
|
||||
#include "headless/svpbmp.hxx"
|
||||
#include "headless/svpinst.hxx"
|
||||
|
||||
#include <basegfx/vector/b2ivector.hxx>
|
||||
#include <basegfx/range/b2ibox.hxx>
|
||||
@ -40,25 +41,12 @@ bool SvpSalBitmap::Create( const Size& rSize,
|
||||
sal_uInt16 nBitCount,
|
||||
const BitmapPalette& rPalette )
|
||||
{
|
||||
basebmp::Format nFormat = SVP_DEFAULT_BITMAP_FORMAT;
|
||||
SAL_INFO( "vcl.headless", "SvpSalBitmap::Create(" << rSize.Width() << "," << rSize.Height() << "," << nBitCount << ")" );
|
||||
switch( nBitCount )
|
||||
{
|
||||
case 1: nFormat = FORMAT_ONE_BIT_MSB_PAL; break;
|
||||
case 4: nFormat = FORMAT_FOUR_BIT_MSB_PAL; break;
|
||||
case 8: nFormat = FORMAT_EIGHT_BIT_PAL; break;
|
||||
#ifdef OSL_BIGENDIAN
|
||||
case 16: nFormat = FORMAT_SIXTEEN_BIT_MSB_TC_MASK; break;
|
||||
#else
|
||||
case 16: nFormat = FORMAT_SIXTEEN_BIT_LSB_TC_MASK; break;
|
||||
#endif
|
||||
case 24: nFormat = FORMAT_TWENTYFOUR_BIT_TC_MASK; break;
|
||||
#ifdef ANDROID
|
||||
case 32: nFormat = FORMAT_THIRTYTWO_BIT_TC_MASK_RGBA; break;
|
||||
#else
|
||||
case 32: nFormat = FORMAT_THIRTYTWO_BIT_TC_MASK_BGRA; break;
|
||||
#endif
|
||||
}
|
||||
|
||||
SvpSalInstance* pInst = SvpSalInstance::s_pDefaultInstance;
|
||||
assert( pInst );
|
||||
basebmp::Format nFormat = pInst->getFormatForBitCount( nBitCount );
|
||||
|
||||
B2IVector aSize( rSize.Width(), rSize.Height() );
|
||||
if( aSize.getX() == 0 )
|
||||
aSize.setX( 1 );
|
||||
|
@ -45,6 +45,8 @@
|
||||
// FIXME: remove when we re-work the svp mainloop
|
||||
#include <unx/salunxtime.h>
|
||||
|
||||
using namespace basebmp;
|
||||
|
||||
bool SvpSalInstance::isFrameAlive( const SalFrame* pFrame ) const
|
||||
{
|
||||
for( std::list< SalFrame* >::const_iterator it = m_aFrames.begin();
|
||||
@ -405,4 +407,47 @@ void SvpSalTimer::Start( sal_uLong nMS )
|
||||
m_pInstance->StartTimer( nMS );
|
||||
}
|
||||
|
||||
void SvpSalInstance::setBitCountFormatMapping( sal_uInt16 nBitCount,
|
||||
Format aFormat )
|
||||
{
|
||||
m_aBitCountFormatMap[nBitCount] = aFormat;
|
||||
}
|
||||
|
||||
Format SvpSalInstance::getFormatForBitCount( sal_uInt16 nBitCount )
|
||||
{
|
||||
BitCountFormatMap::iterator aIt;
|
||||
if ( (aIt = m_aBitCountFormatMap.find( nBitCount )) != m_aBitCountFormatMap.end() )
|
||||
{
|
||||
return aIt->second;
|
||||
}
|
||||
|
||||
switch( nBitCount )
|
||||
{
|
||||
case 1:
|
||||
return FORMAT_ONE_BIT_MSB_PAL;
|
||||
case 4:
|
||||
return FORMAT_FOUR_BIT_MSB_PAL;
|
||||
case 8:
|
||||
return FORMAT_EIGHT_BIT_PAL;
|
||||
case 16:
|
||||
#ifdef OSL_BIGENDIAN
|
||||
return FORMAT_SIXTEEN_BIT_MSB_TC_MASK;
|
||||
#else
|
||||
return FORMAT_SIXTEEN_BIT_LSB_TC_MASK;
|
||||
#endif
|
||||
case 24:
|
||||
return FORMAT_TWENTYFOUR_BIT_TC_MASK;
|
||||
case 32:
|
||||
return FORMAT_THIRTYTWO_BIT_TC_MASK_BGRA;
|
||||
case 0:
|
||||
#ifdef ANDROID
|
||||
return FORMAT_THIRTYTWO_BIT_TC_MASK_RGBA;
|
||||
#else
|
||||
return FORMAT_TWENTYFOUR_BIT_TC_MASK;
|
||||
#endif
|
||||
default:
|
||||
return SVP_DEFAULT_BITMAP_FORMAT;
|
||||
}
|
||||
|
||||
}
|
||||
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|
||||
|
@ -20,6 +20,7 @@
|
||||
#ifndef IOS
|
||||
|
||||
#include "headless/svpbmp.hxx"
|
||||
#include "headless/svpinst.hxx"
|
||||
#include "headless/svpvd.hxx"
|
||||
#include "headless/svpgdi.hxx"
|
||||
|
||||
@ -63,36 +64,23 @@ bool SvpSalVirtualDevice::SetSizeUsingBuffer( long nNewDX, long nNewDY, const ba
|
||||
aDevSize.setY( 1 );
|
||||
if( ! m_aDevice.get() || m_aDevice->getSize() != aDevSize )
|
||||
{
|
||||
basebmp::Format nFormat = SVP_DEFAULT_BITMAP_FORMAT;
|
||||
std::vector< basebmp::Color > aDevPal;
|
||||
switch( m_nBitCount )
|
||||
SvpSalInstance* pInst = SvpSalInstance::s_pDefaultInstance;
|
||||
assert( pInst );
|
||||
basebmp::Format nFormat = pInst->getFormatForBitCount( m_nBitCount );
|
||||
|
||||
if ( m_nBitCount == 1 )
|
||||
{
|
||||
case 1: nFormat = FORMAT_ONE_BIT_MSB_PAL;
|
||||
aDevPal.reserve(2);
|
||||
std::vector< basebmp::Color > aDevPal(2);
|
||||
aDevPal.push_back( basebmp::Color( 0, 0, 0 ) );
|
||||
aDevPal.push_back( basebmp::Color( 0xff, 0xff, 0xff ) );
|
||||
break;
|
||||
case 4: nFormat = FORMAT_FOUR_BIT_MSB_PAL; break;
|
||||
case 8: nFormat = FORMAT_EIGHT_BIT_PAL; break;
|
||||
#ifdef OSL_BIGENDIAN
|
||||
case 16: nFormat = FORMAT_SIXTEEN_BIT_MSB_TC_MASK; break;
|
||||
#else
|
||||
case 16: nFormat = FORMAT_SIXTEEN_BIT_LSB_TC_MASK; break;
|
||||
#endif
|
||||
case 24: nFormat = FORMAT_TWENTYFOUR_BIT_TC_MASK; break;
|
||||
case 32: nFormat = FORMAT_THIRTYTWO_BIT_TC_MASK_BGRA; break;
|
||||
#ifdef ANDROID
|
||||
case 0: nFormat = FORMAT_THIRTYTWO_BIT_TC_MASK_RGBA; break;
|
||||
#else
|
||||
case 0: nFormat = FORMAT_TWENTYFOUR_BIT_TC_MASK; break;
|
||||
#endif
|
||||
m_aDevice = createBitmapDevice( aDevSize, false, nFormat, PaletteMemorySharedVector( new std::vector< basebmp::Color >(aDevPal) ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
m_aDevice = pBuffer ?
|
||||
createBitmapDevice( aDevSize, false, nFormat, pBuffer, PaletteMemorySharedVector() )
|
||||
: createBitmapDevice( aDevSize, false, nFormat );
|
||||
}
|
||||
m_aDevice = aDevPal.empty()
|
||||
? ( pBuffer
|
||||
? createBitmapDevice( aDevSize, false, nFormat, pBuffer, PaletteMemorySharedVector() )
|
||||
: createBitmapDevice( aDevSize, false, nFormat )
|
||||
)
|
||||
: createBitmapDevice( aDevSize, false, nFormat, PaletteMemorySharedVector( new std::vector< basebmp::Color >(aDevPal) ) );
|
||||
|
||||
// update device in existing graphics
|
||||
for( std::list< SvpSalGraphics* >::iterator it = m_aGraphics.begin();
|
||||
|
@ -27,6 +27,7 @@
|
||||
#include <saltimer.hxx>
|
||||
#include <generic/geninst.h>
|
||||
#include <generic/genprn.h>
|
||||
#include <basebmp/scanlineformats.hxx>
|
||||
|
||||
#include <list>
|
||||
|
||||
@ -84,6 +85,9 @@ class SvpSalInstance : public SalGenericInstance
|
||||
|
||||
void DoReleaseYield( int nTimeoutMS );
|
||||
|
||||
typedef std::map< sal_uInt16, ::basebmp::Format > BitCountFormatMap;
|
||||
BitCountFormatMap m_aBitCountFormatMap;
|
||||
|
||||
public:
|
||||
static SvpSalInstance* s_pDefaultInstance;
|
||||
|
||||
@ -161,6 +165,14 @@ public:
|
||||
virtual void AddToRecentDocumentList(const OUString& rFileUrl, const OUString& rMimeType, const OUString& rDocumentService) SAL_OVERRIDE;
|
||||
|
||||
virtual GenPspGraphics *CreatePrintGraphics() SAL_OVERRIDE;
|
||||
|
||||
// We want to be able to select colourspace, i.e. ARGB vs RGBA vs BGRA etc.
|
||||
// -- as the rest of vcl always uses bit depths, it is perhaps simplest
|
||||
// to let us simply change the mapping of bitcount to format (which was
|
||||
// previously unchangeable).
|
||||
SAL_DLLPUBLIC_EXPORT void setBitCountFormatMapping( sal_uInt16 nBitCount, ::basebmp::Format aFormat );
|
||||
|
||||
SAL_DLLPUBLIC_EXPORT ::basebmp::Format getFormatForBitCount( sal_uInt16 );
|
||||
};
|
||||
|
||||
#endif // INCLUDED_VCL_INC_HEADLESS_SVPINST_HXX
|
||||
|
Loading…
x
Reference in New Issue
Block a user