[Libreoffice-commits] .: vcl/inc vcl/source
Caolán McNamara
caolan at kemper.freedesktop.org
Thu Nov 3 16:45:49 PDT 2011
vcl/inc/vcl/salbtype.hxx | 24 ++++++------------
vcl/source/gdi/bitmap.cxx | 61 ++++++++++++++++++++++++----------------------
2 files changed, 42 insertions(+), 43 deletions(-)
New commits:
commit 5436b3242ae84aca1d8a3d750bee6bf39ea52224
Author: Caolán McNamara <caolanm at redhat.com>
Date: Thu Nov 3 23:40:04 2011 +0000
Unwind and refactor some of the Grey Palette stuff
We get some assertions in the smoketest with --enable-debug, looking
closer I think to use a single bIsGrey flag we...
a) would need to check after every modification of a Palette that mbIsGrey is
still valid and update it accordingly
b) There are a lot of routes outside of direct assignation to the stock Grey
Palettes that can result in Grey palettes in e.g. the pngreader, they would
all need updating :-(
So, how about just refactoring the original HasGreyPalette and IsGreyPalette.
diff --git a/vcl/inc/vcl/salbtype.hxx b/vcl/inc/vcl/salbtype.hxx
index aca81ab..fc323c7 100644
--- a/vcl/inc/vcl/salbtype.hxx
+++ b/vcl/inc/vcl/salbtype.hxx
@@ -181,7 +181,6 @@ private:
BitmapColor* mpBitmapColor;
sal_uInt16 mnCount;
- bool mbIsGrey;
public:
@@ -207,8 +206,7 @@ public:
inline BitmapColor& operator[]( sal_uInt16 nIndex );
inline sal_uInt16 GetBestIndex( const BitmapColor& rCol ) const;
- bool IsGreyPalette() const { return !GetEntryCount() || mbIsGrey; }
- void SetGreyPalette( bool bGrey ) { mbIsGrey = bGrey; }
+ bool IsGreyPalette() const;
};
// ---------------
@@ -535,18 +533,16 @@ inline sal_uLong BitmapColor::GetColorError( const BitmapColor& rBitmapColor ) c
// ------------------------------------------------------------------
-inline BitmapPalette::BitmapPalette()
- : mpBitmapColor(NULL)
- , mnCount(0)
- , mbIsGrey(false)
+inline BitmapPalette::BitmapPalette() :
+ mpBitmapColor ( NULL ),
+ mnCount ( 0 )
{
}
// ------------------------------------------------------------------
-inline BitmapPalette::BitmapPalette( const BitmapPalette& rBitmapPalette )
- : mnCount(rBitmapPalette.mnCount)
- , mbIsGrey(rBitmapPalette.mbIsGrey)
+inline BitmapPalette::BitmapPalette( const BitmapPalette& rBitmapPalette ) :
+ mnCount( rBitmapPalette.mnCount )
{
if( mnCount )
{
@@ -560,9 +556,8 @@ inline BitmapPalette::BitmapPalette( const BitmapPalette& rBitmapPalette )
// ------------------------------------------------------------------
-inline BitmapPalette::BitmapPalette( sal_uInt16 nCount )
- : mnCount(nCount)
- , mbIsGrey(false)
+inline BitmapPalette::BitmapPalette( sal_uInt16 nCount ) :
+ mnCount( nCount )
{
if( mnCount )
{
@@ -587,7 +582,6 @@ inline BitmapPalette& BitmapPalette::operator=( const BitmapPalette& rBitmapPale
{
delete[] (sal_uInt8*) mpBitmapColor;
mnCount = rBitmapPalette.mnCount;
- mbIsGrey = rBitmapPalette.mbIsGrey;
if( mnCount )
{
@@ -607,7 +601,7 @@ inline sal_Bool BitmapPalette::operator==( const BitmapPalette& rBitmapPalette )
{
sal_Bool bRet = sal_False;
- if( rBitmapPalette.mnCount == mnCount && rBitmapPalette.mbIsGrey == mbIsGrey )
+ if( rBitmapPalette.mnCount == mnCount )
{
bRet = sal_True;
diff --git a/vcl/source/gdi/bitmap.cxx b/vcl/source/gdi/bitmap.cxx
index 4df609a..bdfc53e 100644
--- a/vcl/source/gdi/bitmap.cxx
+++ b/vcl/source/gdi/bitmap.cxx
@@ -177,7 +177,6 @@ const BitmapPalette& Bitmap::GetGreyPalette( int nEntries )
aGreyPalette2.SetEntryCount( 2 );
aGreyPalette2[ 0 ] = BitmapColor( 0, 0, 0 );
aGreyPalette2[ 1 ] = BitmapColor( 255, 255, 255 );
- aGreyPalette2.SetGreyPalette( true );
}
return aGreyPalette2;
@@ -191,7 +190,6 @@ const BitmapPalette& Bitmap::GetGreyPalette( int nEntries )
aGreyPalette4[ 1 ] = BitmapColor( 85, 85, 85 );
aGreyPalette4[ 2 ] = BitmapColor( 170, 170, 170 );
aGreyPalette4[ 3 ] = BitmapColor( 255, 255, 255 );
- aGreyPalette4.SetGreyPalette( true );
}
return aGreyPalette4;
@@ -206,7 +204,6 @@ const BitmapPalette& Bitmap::GetGreyPalette( int nEntries )
for( sal_uInt16 i = 0; i < 16; i++, cGrey = sal::static_int_cast<sal_uInt8>(cGrey + cGreyInc) )
aGreyPalette16[ i ] = BitmapColor( cGrey, cGrey, cGrey );
- aGreyPalette16.SetGreyPalette( true );
}
return aGreyPalette16;
@@ -219,7 +216,6 @@ const BitmapPalette& Bitmap::GetGreyPalette( int nEntries )
for( sal_uInt16 i = 0; i < 256; i++ )
aGreyPalette256[ i ] = BitmapColor( (sal_uInt8) i, (sal_uInt8) i, (sal_uInt8) i );
- aGreyPalette256.SetGreyPalette( true );
}
return aGreyPalette256;
@@ -228,12 +224,39 @@ const BitmapPalette& Bitmap::GetGreyPalette( int nEntries )
else
{
OSL_FAIL( "Bitmap::GetGreyPalette: invalid entry count (2/4/16/256 allowed)" );
- return GetGreyPalette( 2 );
+ return aGreyPalette2;
}
}
// ------------------------------------------------------------------
+bool BitmapPalette::IsGreyPalette() const
+{
+ const int nEntryCount = GetEntryCount();
+ if( !nEntryCount ) // NOTE: an empty palette means 1:1 mapping
+ return true;
+ // see above: only certain entry values will result in a valid call to GetGreyPalette
+ if( nEntryCount == 2 || nEntryCount == 4 || nEntryCount == 16 || nEntryCount == 256 )
+ {
+ const BitmapPalette& rGreyPalette = Bitmap::GetGreyPalette( nEntryCount );
+ if( rGreyPalette == *this )
+ return true;
+ }
+
+ bool bRet = false;
+ // TODO: is it worth to compare the entries for the general case?
+ if (nEntryCount == 2)
+ {
+ const BitmapColor& rCol0(mpBitmapColor[0]);
+ const BitmapColor& rCol1(mpBitmapColor[1]);
+ bRet = rCol0.GetRed() == rCol0.GetGreen() && rCol0.GetRed() == rCol0.GetBlue() &&
+ rCol1.GetRed() == rCol1.GetGreen() && rCol1.GetRed() == rCol1.GetBlue();
+ }
+ return bRet;
+}
+
+// ------------------------------------------------------------------
+
Bitmap& Bitmap::operator=( const Bitmap& rBitmap )
{
maPrefSize = rBitmap.maPrefSize;
@@ -295,32 +318,14 @@ sal_uInt16 Bitmap::GetBitCount() const
sal_Bool Bitmap::HasGreyPalette() const
{
const sal_uInt16 nBitCount = GetBitCount();
- sal_Bool bRet = sal_False;
+ sal_Bool bRet = nBitCount == 1 ? sal_True : sal_False;
- if( 1 == nBitCount )
- {
- BitmapReadAccess* pRAcc = ( (Bitmap*) this )->AcquireReadAccess();
+ BitmapReadAccess* pRAcc = ( (Bitmap*) this )->AcquireReadAccess();
- if( pRAcc )
- {
- const BitmapColor& rCol0( pRAcc->GetPaletteColor( 0 ) );
- const BitmapColor& rCol1( pRAcc->GetPaletteColor( 1 ) );
- bRet = rCol0.GetRed() == rCol0.GetGreen() && rCol0.GetRed() == rCol0.GetBlue() &&
- rCol1.GetRed() == rCol1.GetGreen() && rCol1.GetRed() == rCol1.GetBlue();
- ( (Bitmap*) this )->ReleaseAccess( pRAcc );
- }
- else
- bRet = sal_True;
- }
- else if( 4 == nBitCount || 8 == nBitCount )
+ if( pRAcc )
{
- BitmapReadAccess* pRAcc = ( (Bitmap*) this )->AcquireReadAccess();
-
- if( pRAcc )
- {
- bRet = pRAcc->HasPalette() && pRAcc->GetPalette().IsGreyPalette();
- ( (Bitmap*) this )->ReleaseAccess( pRAcc );
- }
+ bRet = pRAcc->HasPalette() && pRAcc->GetPalette().IsGreyPalette();
+ ( (Bitmap*) this )->ReleaseAccess( pRAcc );
}
return bRet;
More information about the Libreoffice-commits
mailing list