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:
Andrzej Hunt 2014-05-23 19:59:03 +01:00
parent dbf426edea
commit e82d491263
4 changed files with 79 additions and 46 deletions

View File

@ -20,6 +20,7 @@
#ifndef IOS #ifndef IOS
#include "headless/svpbmp.hxx" #include "headless/svpbmp.hxx"
#include "headless/svpinst.hxx"
#include <basegfx/vector/b2ivector.hxx> #include <basegfx/vector/b2ivector.hxx>
#include <basegfx/range/b2ibox.hxx> #include <basegfx/range/b2ibox.hxx>
@ -40,25 +41,12 @@ bool SvpSalBitmap::Create( const Size& rSize,
sal_uInt16 nBitCount, sal_uInt16 nBitCount,
const BitmapPalette& rPalette ) const BitmapPalette& rPalette )
{ {
basebmp::Format nFormat = SVP_DEFAULT_BITMAP_FORMAT;
SAL_INFO( "vcl.headless", "SvpSalBitmap::Create(" << rSize.Width() << "," << rSize.Height() << "," << nBitCount << ")" ); SAL_INFO( "vcl.headless", "SvpSalBitmap::Create(" << rSize.Width() << "," << rSize.Height() << "," << nBitCount << ")" );
switch( nBitCount )
{ SvpSalInstance* pInst = SvpSalInstance::s_pDefaultInstance;
case 1: nFormat = FORMAT_ONE_BIT_MSB_PAL; break; assert( pInst );
case 4: nFormat = FORMAT_FOUR_BIT_MSB_PAL; break; basebmp::Format nFormat = pInst->getFormatForBitCount( nBitCount );
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
}
B2IVector aSize( rSize.Width(), rSize.Height() ); B2IVector aSize( rSize.Width(), rSize.Height() );
if( aSize.getX() == 0 ) if( aSize.getX() == 0 )
aSize.setX( 1 ); aSize.setX( 1 );

View File

@ -45,6 +45,8 @@
// FIXME: remove when we re-work the svp mainloop // FIXME: remove when we re-work the svp mainloop
#include <unx/salunxtime.h> #include <unx/salunxtime.h>
using namespace basebmp;
bool SvpSalInstance::isFrameAlive( const SalFrame* pFrame ) const bool SvpSalInstance::isFrameAlive( const SalFrame* pFrame ) const
{ {
for( std::list< SalFrame* >::const_iterator it = m_aFrames.begin(); for( std::list< SalFrame* >::const_iterator it = m_aFrames.begin();
@ -405,4 +407,47 @@ void SvpSalTimer::Start( sal_uLong nMS )
m_pInstance->StartTimer( 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: */ /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

View File

@ -20,6 +20,7 @@
#ifndef IOS #ifndef IOS
#include "headless/svpbmp.hxx" #include "headless/svpbmp.hxx"
#include "headless/svpinst.hxx"
#include "headless/svpvd.hxx" #include "headless/svpvd.hxx"
#include "headless/svpgdi.hxx" #include "headless/svpgdi.hxx"
@ -63,36 +64,23 @@ bool SvpSalVirtualDevice::SetSizeUsingBuffer( long nNewDX, long nNewDY, const ba
aDevSize.setY( 1 ); aDevSize.setY( 1 );
if( ! m_aDevice.get() || m_aDevice->getSize() != aDevSize ) if( ! m_aDevice.get() || m_aDevice->getSize() != aDevSize )
{ {
basebmp::Format nFormat = SVP_DEFAULT_BITMAP_FORMAT; SvpSalInstance* pInst = SvpSalInstance::s_pDefaultInstance;
std::vector< basebmp::Color > aDevPal; assert( pInst );
switch( m_nBitCount ) basebmp::Format nFormat = pInst->getFormatForBitCount( m_nBitCount );
if ( m_nBitCount == 1 )
{ {
case 1: nFormat = FORMAT_ONE_BIT_MSB_PAL; std::vector< basebmp::Color > aDevPal(2);
aDevPal.reserve(2); aDevPal.push_back( basebmp::Color( 0, 0, 0 ) );
aDevPal.push_back( basebmp::Color( 0, 0, 0 ) ); aDevPal.push_back( basebmp::Color( 0xff, 0xff, 0xff ) );
aDevPal.push_back( basebmp::Color( 0xff, 0xff, 0xff ) ); m_aDevice = createBitmapDevice( aDevSize, false, nFormat, PaletteMemorySharedVector( new std::vector< basebmp::Color >(aDevPal) ) );
break; }
case 4: nFormat = FORMAT_FOUR_BIT_MSB_PAL; break; else
case 8: nFormat = FORMAT_EIGHT_BIT_PAL; break; {
#ifdef OSL_BIGENDIAN m_aDevice = pBuffer ?
case 16: nFormat = FORMAT_SIXTEEN_BIT_MSB_TC_MASK; break; createBitmapDevice( aDevSize, false, nFormat, pBuffer, PaletteMemorySharedVector() )
#else : createBitmapDevice( aDevSize, false, nFormat );
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 = 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 // update device in existing graphics
for( std::list< SvpSalGraphics* >::iterator it = m_aGraphics.begin(); for( std::list< SvpSalGraphics* >::iterator it = m_aGraphics.begin();

View File

@ -27,6 +27,7 @@
#include <saltimer.hxx> #include <saltimer.hxx>
#include <generic/geninst.h> #include <generic/geninst.h>
#include <generic/genprn.h> #include <generic/genprn.h>
#include <basebmp/scanlineformats.hxx>
#include <list> #include <list>
@ -84,6 +85,9 @@ class SvpSalInstance : public SalGenericInstance
void DoReleaseYield( int nTimeoutMS ); void DoReleaseYield( int nTimeoutMS );
typedef std::map< sal_uInt16, ::basebmp::Format > BitCountFormatMap;
BitCountFormatMap m_aBitCountFormatMap;
public: public:
static SvpSalInstance* s_pDefaultInstance; static SvpSalInstance* s_pDefaultInstance;
@ -161,6 +165,14 @@ public:
virtual void AddToRecentDocumentList(const OUString& rFileUrl, const OUString& rMimeType, const OUString& rDocumentService) SAL_OVERRIDE; virtual void AddToRecentDocumentList(const OUString& rFileUrl, const OUString& rMimeType, const OUString& rDocumentService) SAL_OVERRIDE;
virtual GenPspGraphics *CreatePrintGraphics() 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 #endif // INCLUDED_VCL_INC_HEADLESS_SVPINST_HXX