diff options
author | RĂ¼diger Timm <rt@openoffice.org> | 2006-02-09 13:50:28 +0000 |
---|---|---|
committer | RĂ¼diger Timm <rt@openoffice.org> | 2006-02-09 13:50:28 +0000 |
commit | e4bffbf60bd0f3a50f8842a66edde146893b5e1e (patch) | |
tree | aa9cac001c93d1fbac4316cb617ed2ab41abf901 /vcl/source/gdi/bitmap2.cxx | |
parent | 1dcbf9908456e2302f8a419d4d482c392566b5b3 (diff) |
INTEGRATION: CWS thbpp2 (1.9.160); FILE MERGED
2006/02/03 16:43:51 thb 1.9.160.2: #i59239# Using consistent behaviour now between ImplWriteDIBBits and ImplWriteDIBFileHeader (otherwise, reader would chop 12 extra bytes from the bitmap)
2006/01/30 10:10:21 thb 1.9.160.1: #i59239# Limit bitcount to 1,4,8 or 24, and fallback to 24 bit for non-default cases (fixing mem overwrite)
Diffstat (limited to 'vcl/source/gdi/bitmap2.cxx')
-rw-r--r-- | vcl/source/gdi/bitmap2.cxx | 97 |
1 files changed, 57 insertions, 40 deletions
diff --git a/vcl/source/gdi/bitmap2.cxx b/vcl/source/gdi/bitmap2.cxx index 7e021568e864..39a15fdf06e2 100644 --- a/vcl/source/gdi/bitmap2.cxx +++ b/vcl/source/gdi/bitmap2.cxx @@ -4,9 +4,9 @@ * * $RCSfile: bitmap2.cxx,v $ * - * $Revision: 1.9 $ + * $Revision: 1.10 $ * - * last change: $Author: rt $ $Date: 2005-09-09 11:52:43 $ + * last change: $Author: rt $ $Date: 2006-02-09 14:50:28 $ * * The Contents of this file are made available subject to * the terms of GNU Lesser General Public License Version 2.1. @@ -109,6 +109,22 @@ struct DIBInfoHeader ~DIBInfoHeader() {} }; +namespace +{ + inline USHORT discretizeBitcount( UINT16 nInputCount ) + { + return ( nInputCount <= 1 ) ? 1 : + ( nInputCount <= 4 ) ? 4 : + ( nInputCount <= 8 ) ? 8 : 24; + } + + inline bool isBitfieldCompression( ULONG nScanlineFormat ) + { + return nScanlineFormat == BMP_FORMAT_16BIT_TC_LSB_MASK || + nScanlineFormat == BMP_FORMAT_32BIT_TC_MASK; + } +} + // ---------- // - Bitmap - // ---------- @@ -169,9 +185,7 @@ BOOL Bitmap::ImplReadDIB( SvStream& rIStm, Bitmap& rBmp, ULONG nOffset ) if( ImplReadDIBInfoHeader( rIStm, aHeader ) && aHeader.nWidth && aHeader.nHeight && aHeader.nBitCount ) { - USHORT nBitCount = ( aHeader.nBitCount <= 1 ) ? 1 : - ( aHeader.nBitCount <= 4 ) ? 4 : - ( aHeader.nBitCount <= 8 ) ? 8 : 24; + const USHORT nBitCount( discretizeBitcount(aHeader.nBitCount) ); const Size aSizePixel( aHeader.nWidth, aHeader.nHeight ); BitmapPalette aDummyPal; @@ -686,39 +700,38 @@ BOOL Bitmap::ImplWriteDIB( SvStream& rOStm, BitmapReadAccess& rAcc, BOOL bCompre aHeader.nHeight = rAcc.Height(); aHeader.nPlanes = 1; - switch( rAcc.GetScanlineFormat() ) + if( isBitfieldCompression( rAcc.GetScanlineFormat() ) ) { - case( BMP_FORMAT_16BIT_TC_LSB_MASK ): - case( BMP_FORMAT_32BIT_TC_MASK ): - { - aHeader.nBitCount = ( rAcc.GetScanlineFormat() == BMP_FORMAT_16BIT_TC_LSB_MASK ) ? 16 : 32; - nCompression = BITFIELDS; - } - break; + aHeader.nBitCount = ( rAcc.GetScanlineFormat() == BMP_FORMAT_16BIT_TC_LSB_MASK ) ? 16 : 32; + aHeader.nSizeImage = rAcc.Height() * rAcc.GetScanlineSize(); - default: + nCompression = BITFIELDS; + } + else + { + // #i5xxx# Limit bitcount to 24bit, the 32 bit cases are + // not handled properly below (would have to set color + // masks, and nCompression=BITFIELDS - but color mask is + // not set for formats != *_TC_*). Note that this very + // problem might cause trouble at other places - the + // introduction of 32 bit RGBA bitmaps is relatively + // recent. + // #i59239# discretize bitcount to 1,4,8,24 (other cases + // are not written below) + const UINT16 nBitCount( (UINT16)rAcc.GetBitCount() ); + aHeader.nBitCount = discretizeBitcount( nBitCount ); + aHeader.nSizeImage = rAcc.Height() * + AlignedWidth4Bytes( rAcc.Width()*aHeader.nBitCount ); + + if( bCompressed ) { - // #i5xxx# Limit bitcount to 24bit, the 32 bit cases are - // not handled properly below (would have to set color - // masks, and nCompression=BITFIELDS - but color mask is - // not set for formats != *_TC_*). Note that this very - // problem might cause trouble at other places - the - // introduction of 32 bit RGBA bitmaps is relatively - // recent. - aHeader.nBitCount = ::std::min( 24U, - (unsigned int)rAcc.GetBitCount() ); - - if( bCompressed ) - { - if( 4 == aHeader.nBitCount ) - nCompression = RLE_4; - else if( 8 == aHeader.nBitCount ) - nCompression = RLE_8; - } - else - nCompression = COMPRESS_NONE; + if( 4 == nBitCount ) + nCompression = RLE_4; + else if( 8 == nBitCount ) + nCompression = RLE_8; } - break; + else + nCompression = COMPRESS_NONE; } if( ( rOStm.GetCompressMode() & COMPRESSMODE_ZBITMAP ) && @@ -729,8 +742,6 @@ BOOL Bitmap::ImplWriteDIB( SvStream& rOStm, BitmapReadAccess& rAcc, BOOL bCompre else aHeader.nCompression = nCompression; - aHeader.nSizeImage = rAcc.Height() * rAcc.GetScanlineSize(); - if( maPrefSize.Width() && maPrefSize.Height() && ( maPrefMapMode != aMapPixel ) ) { const Size aSize100( OutputDevice::LogicToLogic( maPrefSize, maPrefMapMode, MAP_100TH_MM ) ); @@ -814,7 +825,8 @@ BOOL Bitmap::ImplWriteDIB( SvStream& rOStm, BitmapReadAccess& rAcc, BOOL bCompre BOOL Bitmap::ImplWriteDIBFileHeader( SvStream& rOStm, BitmapReadAccess& rAcc ) { - UINT32 nPalCount = ( rAcc.HasPalette() ? rAcc.GetPaletteEntryCount() : rAcc.HasColorMask() ? 3UL : 0UL ); + UINT32 nPalCount = ( rAcc.HasPalette() ? rAcc.GetPaletteEntryCount() : + isBitfieldCompression( rAcc.GetScanlineFormat() ) ? 3UL : 0UL ); UINT32 nOffset = 14 + DIBINFOHEADERSIZE + nPalCount * 4UL; rOStm << (UINT16) 0x4D42; @@ -894,9 +906,11 @@ BOOL Bitmap::ImplWriteDIBBits( SvStream& rOStm, BitmapReadAccess& rAcc, // formats != *_TC_*). Note that this very problem might cause // trouble at other places - the introduction of 32 bit RGBA // bitmaps is relatively recent. - const USHORT nBitCount = ::std::min( 24U, - (unsigned int)rAcc.GetBitCount() ); - const ULONG nAlignedWidth = AlignedWidth4Bytes( rAcc.Width() * nBitCount); + // #i59239# discretize bitcount for aligned width to 1,4,8,24 + // (other cases are not written below) + const USHORT nBitCount( (USHORT)rAcc.GetBitCount() ); + const ULONG nAlignedWidth = AlignedWidth4Bytes( rAcc.Width() * + discretizeBitcount(nBitCount)); BOOL bNative = FALSE; switch( rAcc.GetScanlineFormat() ) @@ -992,7 +1006,10 @@ BOOL Bitmap::ImplWriteDIBBits( SvStream& rOStm, BitmapReadAccess& rAcc, } break; + // #i59239# fallback to 24 bit format, if bitcount is non-default default: + // FALLTHROUGH intended + case( 24 ): { BitmapColor aPixelColor; |