diff options
author | Mike Kaganski <mike.kaganski@collabora.com> | 2020-05-13 17:05:12 +0200 |
---|---|---|
committer | Mike Kaganski <mike.kaganski@collabora.com> | 2020-05-13 23:46:16 +0200 |
commit | 3689f6f15e1f33d7f48e612691878b45c9d140a6 (patch) | |
tree | b730fc3fabc5c8ead1fa98b35de2b628d013056f /vcl/source/bitmap/bitmap.cxx | |
parent | cbc13ac0624685582ebd4634812681274db803aa (diff) |
Use statics initializers instead of checks
Change-Id: I8c474a35e3c4b9a202e4003c6b895f18ac88fb09
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/94001
Tested-by: Jenkins
Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com>
Diffstat (limited to 'vcl/source/bitmap/bitmap.cxx')
-rw-r--r-- | vcl/source/bitmap/bitmap.cxx | 77 |
1 files changed, 36 insertions, 41 deletions
diff --git a/vcl/source/bitmap/bitmap.cxx b/vcl/source/bitmap/bitmap.cxx index dacb0df3d3c4..20045fc78f5e 100644 --- a/vcl/source/bitmap/bitmap.cxx +++ b/vcl/source/bitmap/bitmap.cxx @@ -116,71 +116,66 @@ Bitmap::~Bitmap() const BitmapPalette& Bitmap::GetGreyPalette( int nEntries ) { - static BitmapPalette aGreyPalette2; - static BitmapPalette aGreyPalette4; - static BitmapPalette aGreyPalette16; - static BitmapPalette aGreyPalette256; - // Create greyscale palette with 2, 4, 16 or 256 entries - if( 2 == nEntries || 4 == nEntries || 16 == nEntries || 256 == nEntries ) + switch (nEntries) { - if( 2 == nEntries ) + case 2: { - if( !aGreyPalette2.GetEntryCount() ) - { - aGreyPalette2.SetEntryCount( 2 ); - aGreyPalette2[ 0 ] = BitmapColor( 0, 0, 0 ); - aGreyPalette2[ 1 ] = BitmapColor( 255, 255, 255 ); - } + static const BitmapPalette aGreyPalette2 = [] { + BitmapPalette aPalette(2); + aPalette[0] = BitmapColor(0, 0, 0); + aPalette[1] = BitmapColor(255, 255, 255); + return aPalette; + }(); return aGreyPalette2; } - else if( 4 == nEntries ) + case 4: { - if( !aGreyPalette4.GetEntryCount() ) - { - aGreyPalette4.SetEntryCount( 4 ); - aGreyPalette4[ 0 ] = BitmapColor( 0, 0, 0 ); - aGreyPalette4[ 1 ] = BitmapColor( 85, 85, 85 ); - aGreyPalette4[ 2 ] = BitmapColor( 170, 170, 170 ); - aGreyPalette4[ 3 ] = BitmapColor( 255, 255, 255 ); - } + static const BitmapPalette aGreyPalette4 = [] { + BitmapPalette aPalette(4); + aPalette[0] = BitmapColor(0, 0, 0); + aPalette[1] = BitmapColor(85, 85, 85); + aPalette[2] = BitmapColor(170, 170, 170); + aPalette[3] = BitmapColor(255, 255, 255); + return aPalette; + }(); return aGreyPalette4; } - else if( 16 == nEntries ) + case 16: { - if( !aGreyPalette16.GetEntryCount() ) - { + static const BitmapPalette aGreyPalette16 = [] { sal_uInt8 cGrey = 0; sal_uInt8 const cGreyInc = 17; - aGreyPalette16.SetEntryCount( 16 ); + BitmapPalette aPalette(16); - for( sal_uInt16 i = 0; i < 16; i++, cGrey = sal::static_int_cast<sal_uInt8>(cGrey + cGreyInc) ) - aGreyPalette16[ i ] = BitmapColor( cGrey, cGrey, cGrey ); - } + for (sal_uInt16 i = 0; i < 16; ++i, cGrey += cGreyInc) + aPalette[i] = BitmapColor(cGrey, cGrey, cGrey); + + return aPalette; + }(); return aGreyPalette16; } - else + case 256: { - if( !aGreyPalette256.GetEntryCount() ) - { - aGreyPalette256.SetEntryCount( 256 ); + static const BitmapPalette aGreyPalette256 = [] { + BitmapPalette aPalette(256); - for( sal_uInt16 i = 0; i < 256; i++ ) - aGreyPalette256[ i ] = BitmapColor( static_cast<sal_uInt8>(i), static_cast<sal_uInt8>(i), static_cast<sal_uInt8>(i) ); - } + for (sal_uInt16 i = 0; i < 256; ++i) + aPalette[i] = BitmapColor(static_cast<sal_uInt8>(i), static_cast<sal_uInt8>(i), + static_cast<sal_uInt8>(i)); + + return aPalette; + }(); return aGreyPalette256; } } - else - { - OSL_FAIL( "Bitmap::GetGreyPalette: invalid entry count (2/4/16/256 allowed)" ); - return aGreyPalette2; - } + OSL_FAIL("Bitmap::GetGreyPalette: invalid entry count (2/4/16/256 allowed)"); + return GetGreyPalette(2); } bool BitmapPalette::IsGreyPalette() const |