1*9f62ea84SAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*9f62ea84SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*9f62ea84SAndrew Rist * or more contributor license agreements. See the NOTICE file 5*9f62ea84SAndrew Rist * distributed with this work for additional information 6*9f62ea84SAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*9f62ea84SAndrew Rist * to you under the Apache License, Version 2.0 (the 8*9f62ea84SAndrew Rist * "License"); you may not use this file except in compliance 9*9f62ea84SAndrew Rist * with the License. You may obtain a copy of the License at 10cdf0e10cSrcweir * 11*9f62ea84SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12cdf0e10cSrcweir * 13*9f62ea84SAndrew Rist * Unless required by applicable law or agreed to in writing, 14*9f62ea84SAndrew Rist * software distributed under the License is distributed on an 15*9f62ea84SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*9f62ea84SAndrew Rist * KIND, either express or implied. See the License for the 17*9f62ea84SAndrew Rist * specific language governing permissions and limitations 18*9f62ea84SAndrew Rist * under the License. 19cdf0e10cSrcweir * 20*9f62ea84SAndrew Rist *************************************************************/ 21*9f62ea84SAndrew Rist 22*9f62ea84SAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 25cdf0e10cSrcweir #include "precompiled_vcl.hxx" 26cdf0e10cSrcweir #include <rtl/memory.h> 27cdf0e10cSrcweir #include <vcl/bmpacc.hxx> 28cdf0e10cSrcweir #include <vcl/salbtype.hxx> 29cdf0e10cSrcweir #include <bmpfast.hxx> 30cdf0e10cSrcweir 31cdf0e10cSrcweir // ----------- 32cdf0e10cSrcweir // - Defines - 33cdf0e10cSrcweir // ----------- 34cdf0e10cSrcweir 35cdf0e10cSrcweir #define IMPL_CASE_GET_FORMAT( Format ) \ 36cdf0e10cSrcweir case( BMP_FORMAT##Format ): \ 37cdf0e10cSrcweir pFncGetPixel = BitmapReadAccess::GetPixelFor##Format; \ 38cdf0e10cSrcweir break 39cdf0e10cSrcweir 40cdf0e10cSrcweir // ----------------------------------------------------------------------------- 41cdf0e10cSrcweir 42cdf0e10cSrcweir #define IMPL_CASE_SET_FORMAT( Format, BitCount ) \ 43cdf0e10cSrcweir case( BMP_FORMAT##Format ): \ 44cdf0e10cSrcweir { \ 45cdf0e10cSrcweir pFncSetPixel = BitmapReadAccess::SetPixelFor##Format; \ 46cdf0e10cSrcweir pDstBuffer->mnBitCount = BitCount; \ 47cdf0e10cSrcweir } \ 48cdf0e10cSrcweir break 49cdf0e10cSrcweir 50cdf0e10cSrcweir // ----------------------------------------------------------------------------- 51cdf0e10cSrcweir 52cdf0e10cSrcweir #define DOUBLE_SCANLINES() \ 53cdf0e10cSrcweir while( ( nActY < nHeight1 ) && ( pMapY[ nActY + 1 ] == nMapY ) ) \ 54cdf0e10cSrcweir { \ 55cdf0e10cSrcweir memcpy( pDstScanMap[ nActY + 1L ], pDstScan, rDstBuffer.mnScanlineSize ); \ 56cdf0e10cSrcweir nActY++; \ 57cdf0e10cSrcweir } 58cdf0e10cSrcweir 59cdf0e10cSrcweir // ----------- 60cdf0e10cSrcweir // - Inlines - 61cdf0e10cSrcweir // ----------- 62cdf0e10cSrcweir 63cdf0e10cSrcweir #define TC_TO_PAL_COLORS 4096 64cdf0e10cSrcweir 65cdf0e10cSrcweir static long ImplIndexFromColor( const BitmapColor& rCol ) 66cdf0e10cSrcweir { 67cdf0e10cSrcweir #if TC_TO_PAL_COLORS == 4096 68cdf0e10cSrcweir 69cdf0e10cSrcweir return( ( ( (long) rCol.GetBlue() >> 4L) << 8L ) | 70cdf0e10cSrcweir ( ( (long) rCol.GetGreen() >> 4L ) << 4L ) | 71cdf0e10cSrcweir ( (long) rCol.GetRed() >> 4L ) ); 72cdf0e10cSrcweir 73cdf0e10cSrcweir #elif TC_TO_PAL_COLORS == 32768 74cdf0e10cSrcweir 75cdf0e10cSrcweir return( ( ( (long) rCol.GetBlue() >> 3L) << 10L ) | 76cdf0e10cSrcweir ( ( (long) rCol.GetGreen() >> 3L ) << 5L ) | 77cdf0e10cSrcweir ( (long) rCol.GetRed() >> 3L ) ); 78cdf0e10cSrcweir 79cdf0e10cSrcweir #endif 80cdf0e10cSrcweir } 81cdf0e10cSrcweir 82cdf0e10cSrcweir 83cdf0e10cSrcweir #define COLOR_TO_INDEX( _def_rCol ) 84cdf0e10cSrcweir 85cdf0e10cSrcweir // ------------------------ 86cdf0e10cSrcweir // - conversion functions - 87cdf0e10cSrcweir // ------------------------ 88cdf0e10cSrcweir 89cdf0e10cSrcweir static void ImplPALToPAL( const BitmapBuffer& rSrcBuffer, BitmapBuffer& rDstBuffer, 90cdf0e10cSrcweir FncGetPixel pFncGetPixel, FncSetPixel pFncSetPixel, 91cdf0e10cSrcweir Scanline* pSrcScanMap, Scanline* pDstScanMap, long* pMapX, long* pMapY ) 92cdf0e10cSrcweir { 93cdf0e10cSrcweir const long nWidth = rDstBuffer.mnWidth, nHeight = rDstBuffer.mnHeight, nHeight1 = nHeight - 1; 94cdf0e10cSrcweir const ColorMask& rSrcMask = rSrcBuffer.maColorMask; 95cdf0e10cSrcweir const ColorMask& rDstMask = rDstBuffer.maColorMask; 96cdf0e10cSrcweir BitmapPalette aColMap( rSrcBuffer.maPalette.GetEntryCount() ); 97cdf0e10cSrcweir BitmapColor* pColMapBuf = aColMap.ImplGetColorBuffer(); 98cdf0e10cSrcweir BitmapColor aIndex( 0 ); 99cdf0e10cSrcweir 100cdf0e10cSrcweir for( sal_uInt16 i = 0, nSrcCount = aColMap.GetEntryCount(), nDstCount = rDstBuffer.maPalette.GetEntryCount(); i < nSrcCount; i++ ) 101cdf0e10cSrcweir { 102cdf0e10cSrcweir if( ( i < nDstCount ) && ( rSrcBuffer.maPalette[ i ] == rDstBuffer.maPalette[ i ] ) ) 103cdf0e10cSrcweir aIndex.SetIndex( sal::static_int_cast<sal_uInt8>(i) ); 104cdf0e10cSrcweir else 105cdf0e10cSrcweir aIndex.SetIndex( sal::static_int_cast<sal_uInt8>(rDstBuffer.maPalette.GetBestIndex( rSrcBuffer.maPalette[ i ] )) ); 106cdf0e10cSrcweir 107cdf0e10cSrcweir pColMapBuf[ i ] = aIndex; 108cdf0e10cSrcweir } 109cdf0e10cSrcweir 110cdf0e10cSrcweir for( long nActY = 0, nMapY; nActY < nHeight; nActY++ ) 111cdf0e10cSrcweir { 112cdf0e10cSrcweir Scanline pSrcScan( pSrcScanMap[ nMapY = pMapY[ nActY ] ] ), pDstScan( pDstScanMap[ nActY ] ); 113cdf0e10cSrcweir 114cdf0e10cSrcweir for( long nX = 0L; nX < nWidth; nX++ ) 115cdf0e10cSrcweir pFncSetPixel( pDstScan, nX, pColMapBuf[ pFncGetPixel( pSrcScan, pMapX[ nX ], rSrcMask ).GetIndex() ], rDstMask ); 116cdf0e10cSrcweir 117cdf0e10cSrcweir DOUBLE_SCANLINES(); 118cdf0e10cSrcweir } 119cdf0e10cSrcweir } 120cdf0e10cSrcweir 121cdf0e10cSrcweir // ----------------------------------------------------------------------------- 122cdf0e10cSrcweir 123cdf0e10cSrcweir static void ImplPALToTC( const BitmapBuffer& rSrcBuffer, BitmapBuffer& rDstBuffer, 124cdf0e10cSrcweir FncGetPixel pFncGetPixel, FncSetPixel pFncSetPixel, 125cdf0e10cSrcweir Scanline* pSrcScanMap, Scanline* pDstScanMap, long* pMapX, long* pMapY ) 126cdf0e10cSrcweir { 127cdf0e10cSrcweir const long nWidth = rDstBuffer.mnWidth, nHeight = rDstBuffer.mnHeight, nHeight1 = nHeight - 1; 128cdf0e10cSrcweir const ColorMask& rSrcMask = rSrcBuffer.maColorMask; 129cdf0e10cSrcweir const ColorMask& rDstMask = rDstBuffer.maColorMask; 130cdf0e10cSrcweir const BitmapColor* pColBuf = rSrcBuffer.maPalette.ImplGetColorBuffer(); 131cdf0e10cSrcweir 132cdf0e10cSrcweir if( BMP_SCANLINE_FORMAT( rSrcBuffer.mnFormat ) == BMP_FORMAT_1BIT_MSB_PAL ) 133cdf0e10cSrcweir { 134cdf0e10cSrcweir const BitmapColor aCol0( pColBuf[ 0 ] ); 135cdf0e10cSrcweir const BitmapColor aCol1( pColBuf[ 1 ] ); 136cdf0e10cSrcweir long nMapX; 137cdf0e10cSrcweir 138cdf0e10cSrcweir for( long nActY = 0, nMapY; nActY < nHeight; nActY++ ) 139cdf0e10cSrcweir { 140cdf0e10cSrcweir Scanline pSrcScan( pSrcScanMap[ nMapY = pMapY[ nActY ] ] ), pDstScan( pDstScanMap[ nActY ] ); 141cdf0e10cSrcweir 142cdf0e10cSrcweir for( long nX = 0L; nX < nWidth; ) 143cdf0e10cSrcweir { 144cdf0e10cSrcweir nMapX = pMapX[ nX ]; 145cdf0e10cSrcweir pFncSetPixel( pDstScan, nX++, 146cdf0e10cSrcweir pSrcScan[ nMapX >> 3 ] & ( 1 << ( 7 - ( nMapX & 7 ) ) ) ? aCol1 : aCol0, 147cdf0e10cSrcweir rDstMask ); 148cdf0e10cSrcweir } 149cdf0e10cSrcweir 150cdf0e10cSrcweir DOUBLE_SCANLINES(); 151cdf0e10cSrcweir } 152cdf0e10cSrcweir } 153cdf0e10cSrcweir else if( BMP_SCANLINE_FORMAT( rSrcBuffer.mnFormat ) == BMP_FORMAT_4BIT_MSN_PAL ) 154cdf0e10cSrcweir { 155cdf0e10cSrcweir long nMapX; 156cdf0e10cSrcweir 157cdf0e10cSrcweir for( long nActY = 0, nMapY; nActY < nHeight; nActY++ ) 158cdf0e10cSrcweir { 159cdf0e10cSrcweir Scanline pSrcScan( pSrcScanMap[ nMapY = pMapY[ nActY ] ] ), pDstScan( pDstScanMap[ nActY ] ); 160cdf0e10cSrcweir 161cdf0e10cSrcweir for( long nX = 0L; nX < nWidth; ) 162cdf0e10cSrcweir { 163cdf0e10cSrcweir nMapX = pMapX[ nX ]; 164cdf0e10cSrcweir pFncSetPixel( pDstScan, nX++, 165cdf0e10cSrcweir pColBuf[ ( pSrcScan[ nMapX >> 1 ] >> ( nMapX & 1 ? 0 : 4 ) ) & 0x0f ], 166cdf0e10cSrcweir rDstMask ); 167cdf0e10cSrcweir } 168cdf0e10cSrcweir 169cdf0e10cSrcweir DOUBLE_SCANLINES(); 170cdf0e10cSrcweir } 171cdf0e10cSrcweir } 172cdf0e10cSrcweir else if( BMP_SCANLINE_FORMAT( rSrcBuffer.mnFormat ) == BMP_FORMAT_8BIT_PAL ) 173cdf0e10cSrcweir { 174cdf0e10cSrcweir for( long nActY = 0, nMapY; nActY < nHeight; nActY++ ) 175cdf0e10cSrcweir { 176cdf0e10cSrcweir Scanline pSrcScan( pSrcScanMap[ nMapY = pMapY[ nActY ] ] ), pDstScan( pDstScanMap[ nActY ] ); 177cdf0e10cSrcweir 178cdf0e10cSrcweir for( long nX = 0L; nX < nWidth; nX++ ) 179cdf0e10cSrcweir pFncSetPixel( pDstScan, nX, pColBuf[ pSrcScan[ pMapX[ nX ] ] ], rDstMask ); 180cdf0e10cSrcweir 181cdf0e10cSrcweir DOUBLE_SCANLINES(); 182cdf0e10cSrcweir } 183cdf0e10cSrcweir } 184cdf0e10cSrcweir else 185cdf0e10cSrcweir { 186cdf0e10cSrcweir for( long nActY = 0, nMapY; nActY < nHeight; nActY++ ) 187cdf0e10cSrcweir { 188cdf0e10cSrcweir Scanline pSrcScan( pSrcScanMap[ nMapY = pMapY[ nActY ] ] ), pDstScan( pDstScanMap[ nActY ] ); 189cdf0e10cSrcweir 190cdf0e10cSrcweir for( long nX = 0L; nX < nWidth; nX++ ) 191cdf0e10cSrcweir pFncSetPixel( pDstScan, nX, pColBuf[ pFncGetPixel( pSrcScan, pMapX[ nX ], rSrcMask ).GetIndex() ], rDstMask ); 192cdf0e10cSrcweir 193cdf0e10cSrcweir DOUBLE_SCANLINES(); 194cdf0e10cSrcweir } 195cdf0e10cSrcweir } 196cdf0e10cSrcweir } 197cdf0e10cSrcweir 198cdf0e10cSrcweir // ----------------------------------------------------------------------------- 199cdf0e10cSrcweir 200cdf0e10cSrcweir static void ImplTCToTC( const BitmapBuffer& rSrcBuffer, BitmapBuffer& rDstBuffer, 201cdf0e10cSrcweir FncGetPixel pFncGetPixel, FncSetPixel pFncSetPixel, 202cdf0e10cSrcweir Scanline* pSrcScanMap, Scanline* pDstScanMap, long* pMapX, long* pMapY ) 203cdf0e10cSrcweir { 204cdf0e10cSrcweir const long nWidth = rDstBuffer.mnWidth, nHeight = rDstBuffer.mnHeight, nHeight1 = nHeight - 1; 205cdf0e10cSrcweir const ColorMask& rSrcMask = rSrcBuffer.maColorMask; 206cdf0e10cSrcweir const ColorMask& rDstMask = rDstBuffer.maColorMask; 207cdf0e10cSrcweir 208cdf0e10cSrcweir if( BMP_SCANLINE_FORMAT( rSrcBuffer.mnFormat ) == BMP_FORMAT_24BIT_TC_BGR ) 209cdf0e10cSrcweir { 210cdf0e10cSrcweir BitmapColor aCol; 211cdf0e10cSrcweir sal_uInt8* pPixel; 212cdf0e10cSrcweir 213cdf0e10cSrcweir for( long nActY = 0, nMapY; nActY < nHeight; nActY++ ) 214cdf0e10cSrcweir { 215cdf0e10cSrcweir Scanline pSrcScan( pSrcScanMap[ nMapY = pMapY[ nActY ] ] ), pDstScan( pDstScanMap[ nActY ] ); 216cdf0e10cSrcweir 217cdf0e10cSrcweir for( long nX = 0L; nX < nWidth; nX++ ) 218cdf0e10cSrcweir { 219cdf0e10cSrcweir aCol.SetBlue( *( pPixel = ( pSrcScan + pMapX[ nX ] * 3 ) )++ ); 220cdf0e10cSrcweir aCol.SetGreen( *pPixel++ ); 221cdf0e10cSrcweir aCol.SetRed( *pPixel ); 222cdf0e10cSrcweir pFncSetPixel( pDstScan, nX, aCol, rDstMask ); 223cdf0e10cSrcweir } 224cdf0e10cSrcweir 225cdf0e10cSrcweir DOUBLE_SCANLINES() 226cdf0e10cSrcweir } 227cdf0e10cSrcweir } 228cdf0e10cSrcweir else 229cdf0e10cSrcweir { 230cdf0e10cSrcweir for( long nActY = 0, nMapY; nActY < nHeight; nActY++ ) 231cdf0e10cSrcweir { 232cdf0e10cSrcweir Scanline pSrcScan( pSrcScanMap[ nMapY = pMapY[ nActY ] ] ), pDstScan( pDstScanMap[ nActY ] ); 233cdf0e10cSrcweir 234cdf0e10cSrcweir for( long nX = 0L; nX < nWidth; nX++ ) 235cdf0e10cSrcweir pFncSetPixel( pDstScan, nX, pFncGetPixel( pSrcScan, pMapX[ nX ], rSrcMask ), rDstMask ); 236cdf0e10cSrcweir 237cdf0e10cSrcweir DOUBLE_SCANLINES(); 238cdf0e10cSrcweir } 239cdf0e10cSrcweir } 240cdf0e10cSrcweir } 241cdf0e10cSrcweir 242cdf0e10cSrcweir // ----------------------------------------------------------------------------- 243cdf0e10cSrcweir 244cdf0e10cSrcweir static void ImplTCToPAL( const BitmapBuffer& rSrcBuffer, BitmapBuffer& rDstBuffer, 245cdf0e10cSrcweir FncGetPixel pFncGetPixel, FncSetPixel pFncSetPixel, 246cdf0e10cSrcweir Scanline* pSrcScanMap, Scanline* pDstScanMap, long* pMapX, long* pMapY ) 247cdf0e10cSrcweir { 248cdf0e10cSrcweir const long nWidth = rDstBuffer.mnWidth, nHeight = rDstBuffer.mnHeight, nHeight1 = nHeight - 1; 249cdf0e10cSrcweir const ColorMask& rSrcMask = rSrcBuffer.maColorMask; 250cdf0e10cSrcweir const ColorMask& rDstMask = rDstBuffer.maColorMask; 251cdf0e10cSrcweir BitmapPalette aColMap( rSrcBuffer.maPalette.GetEntryCount() ); 252cdf0e10cSrcweir sal_uInt8* pColToPalMap = new sal_uInt8[ TC_TO_PAL_COLORS ]; 253cdf0e10cSrcweir BitmapColor aIndex( 0 ); 254cdf0e10cSrcweir 255cdf0e10cSrcweir for( long nR = 0; nR < 16; nR++ ) 256cdf0e10cSrcweir { 257cdf0e10cSrcweir for( long nG = 0; nG < 16; nG++ ) 258cdf0e10cSrcweir { 259cdf0e10cSrcweir for( long nB = 0; nB < 16; nB++ ) 260cdf0e10cSrcweir { 261cdf0e10cSrcweir BitmapColor aCol( sal::static_int_cast<sal_uInt8>(nR << 4), 262cdf0e10cSrcweir sal::static_int_cast<sal_uInt8>(nG << 4), 263cdf0e10cSrcweir sal::static_int_cast<sal_uInt8>(nB << 4) ); 264cdf0e10cSrcweir pColToPalMap[ ImplIndexFromColor( aCol ) ] = (sal_uInt8) rDstBuffer.maPalette.GetBestIndex( aCol ); 265cdf0e10cSrcweir } 266cdf0e10cSrcweir } 267cdf0e10cSrcweir } 268cdf0e10cSrcweir 269cdf0e10cSrcweir for( long nActY = 0, nMapY; nActY < nHeight; nActY++ ) 270cdf0e10cSrcweir { 271cdf0e10cSrcweir Scanline pSrcScan( pSrcScanMap[ nMapY = pMapY[ nActY ] ] ), pDstScan( pDstScanMap[ nActY ] ); 272cdf0e10cSrcweir 273cdf0e10cSrcweir for( long nX = 0L; nX < nWidth; nX++ ) 274cdf0e10cSrcweir { 275cdf0e10cSrcweir aIndex.SetIndex( pColToPalMap[ ImplIndexFromColor( pFncGetPixel( pSrcScan, pMapX[ nX ], rSrcMask ) ) ] ); 276cdf0e10cSrcweir pFncSetPixel( pDstScan, nX, aIndex, rDstMask ); 277cdf0e10cSrcweir } 278cdf0e10cSrcweir 279cdf0e10cSrcweir DOUBLE_SCANLINES(); 280cdf0e10cSrcweir } 281cdf0e10cSrcweir 282cdf0e10cSrcweir delete[] pColToPalMap; 283cdf0e10cSrcweir } 284cdf0e10cSrcweir 285cdf0e10cSrcweir // ----------------------------------------------------------------------------- 286cdf0e10cSrcweir 287cdf0e10cSrcweir // --------------------- 288cdf0e10cSrcweir // - StretchAndConvert - 289cdf0e10cSrcweir // --------------------- 290cdf0e10cSrcweir 291cdf0e10cSrcweir BitmapBuffer* StretchAndConvert( const BitmapBuffer& rSrcBuffer, const SalTwoRect& rTwoRect, 292cdf0e10cSrcweir sal_uLong nDstBitmapFormat, BitmapPalette* pDstPal, ColorMask* pDstMask ) 293cdf0e10cSrcweir { 294cdf0e10cSrcweir FncGetPixel pFncGetPixel; 295cdf0e10cSrcweir FncSetPixel pFncSetPixel; 296cdf0e10cSrcweir BitmapBuffer* pDstBuffer = new BitmapBuffer; 297cdf0e10cSrcweir long i; 298cdf0e10cSrcweir 299cdf0e10cSrcweir // set function for getting pixels 300cdf0e10cSrcweir switch( BMP_SCANLINE_FORMAT( rSrcBuffer.mnFormat ) ) 301cdf0e10cSrcweir { 302cdf0e10cSrcweir IMPL_CASE_GET_FORMAT( _1BIT_MSB_PAL ); 303cdf0e10cSrcweir IMPL_CASE_GET_FORMAT( _1BIT_LSB_PAL ); 304cdf0e10cSrcweir IMPL_CASE_GET_FORMAT( _4BIT_MSN_PAL ); 305cdf0e10cSrcweir IMPL_CASE_GET_FORMAT( _4BIT_LSN_PAL ); 306cdf0e10cSrcweir IMPL_CASE_GET_FORMAT( _8BIT_PAL ); 307cdf0e10cSrcweir IMPL_CASE_GET_FORMAT( _8BIT_TC_MASK ); 308cdf0e10cSrcweir IMPL_CASE_GET_FORMAT( _16BIT_TC_MSB_MASK ); 309cdf0e10cSrcweir IMPL_CASE_GET_FORMAT( _16BIT_TC_LSB_MASK ); 310cdf0e10cSrcweir IMPL_CASE_GET_FORMAT( _24BIT_TC_BGR ); 311cdf0e10cSrcweir IMPL_CASE_GET_FORMAT( _24BIT_TC_RGB ); 312cdf0e10cSrcweir IMPL_CASE_GET_FORMAT( _24BIT_TC_MASK ); 313cdf0e10cSrcweir IMPL_CASE_GET_FORMAT( _32BIT_TC_ABGR ); 314cdf0e10cSrcweir IMPL_CASE_GET_FORMAT( _32BIT_TC_ARGB ); 315cdf0e10cSrcweir IMPL_CASE_GET_FORMAT( _32BIT_TC_BGRA ); 316cdf0e10cSrcweir IMPL_CASE_GET_FORMAT( _32BIT_TC_RGBA ); 317cdf0e10cSrcweir IMPL_CASE_GET_FORMAT( _32BIT_TC_MASK ); 318cdf0e10cSrcweir 319cdf0e10cSrcweir default: 320cdf0e10cSrcweir // should never come here 321cdf0e10cSrcweir // initialize pFncGetPixel to something valid that is 322cdf0e10cSrcweir // least likely to crash 323cdf0e10cSrcweir pFncGetPixel = BitmapReadAccess::GetPixelFor_1BIT_MSB_PAL; 324cdf0e10cSrcweir DBG_ERROR( "unknown read format" ); 325cdf0e10cSrcweir break; 326cdf0e10cSrcweir } 327cdf0e10cSrcweir 328cdf0e10cSrcweir // set function for setting pixels 329cdf0e10cSrcweir const sal_uLong nDstScanlineFormat = BMP_SCANLINE_FORMAT( nDstBitmapFormat ); 330cdf0e10cSrcweir switch( nDstScanlineFormat ) 331cdf0e10cSrcweir { 332cdf0e10cSrcweir IMPL_CASE_SET_FORMAT( _1BIT_MSB_PAL, 1 ); 333cdf0e10cSrcweir IMPL_CASE_SET_FORMAT( _1BIT_LSB_PAL, 1 ); 334cdf0e10cSrcweir IMPL_CASE_SET_FORMAT( _4BIT_MSN_PAL, 1 ); 335cdf0e10cSrcweir IMPL_CASE_SET_FORMAT( _4BIT_LSN_PAL, 4 ); 336cdf0e10cSrcweir IMPL_CASE_SET_FORMAT( _8BIT_PAL, 8 ); 337cdf0e10cSrcweir IMPL_CASE_SET_FORMAT( _8BIT_TC_MASK, 8 ); 338cdf0e10cSrcweir IMPL_CASE_SET_FORMAT( _16BIT_TC_MSB_MASK, 16 ); 339cdf0e10cSrcweir IMPL_CASE_SET_FORMAT( _16BIT_TC_LSB_MASK, 16 ); 340cdf0e10cSrcweir IMPL_CASE_SET_FORMAT( _24BIT_TC_BGR, 24 ); 341cdf0e10cSrcweir IMPL_CASE_SET_FORMAT( _24BIT_TC_RGB, 24 ); 342cdf0e10cSrcweir IMPL_CASE_SET_FORMAT( _24BIT_TC_MASK, 24 ); 343cdf0e10cSrcweir IMPL_CASE_SET_FORMAT( _32BIT_TC_ABGR, 32 ); 344cdf0e10cSrcweir IMPL_CASE_SET_FORMAT( _32BIT_TC_ARGB, 32 ); 345cdf0e10cSrcweir IMPL_CASE_SET_FORMAT( _32BIT_TC_BGRA, 32 ); 346cdf0e10cSrcweir IMPL_CASE_SET_FORMAT( _32BIT_TC_RGBA, 32 ); 347cdf0e10cSrcweir IMPL_CASE_SET_FORMAT( _32BIT_TC_MASK, 32 ); 348cdf0e10cSrcweir 349cdf0e10cSrcweir default: 350cdf0e10cSrcweir // should never come here 351cdf0e10cSrcweir // initialize pFncSetPixel to something valid that is 352cdf0e10cSrcweir // least likely to crash 353cdf0e10cSrcweir pFncSetPixel = BitmapReadAccess::SetPixelFor_1BIT_MSB_PAL; 354cdf0e10cSrcweir pDstBuffer->mnBitCount = 1; 355cdf0e10cSrcweir DBG_ERROR( "unknown write format" ); 356cdf0e10cSrcweir break; 357cdf0e10cSrcweir } 358cdf0e10cSrcweir 359cdf0e10cSrcweir // fill destination buffer 360cdf0e10cSrcweir pDstBuffer->mnFormat = nDstBitmapFormat; 361cdf0e10cSrcweir pDstBuffer->mnWidth = rTwoRect.mnDestWidth; 362cdf0e10cSrcweir pDstBuffer->mnHeight = rTwoRect.mnDestHeight; 363cdf0e10cSrcweir pDstBuffer->mnScanlineSize = AlignedWidth4Bytes( pDstBuffer->mnBitCount * pDstBuffer->mnWidth ); 364cdf0e10cSrcweir try 365cdf0e10cSrcweir { 366cdf0e10cSrcweir pDstBuffer->mpBits = new sal_uInt8[ pDstBuffer->mnScanlineSize * pDstBuffer->mnHeight ]; 367cdf0e10cSrcweir } 368cdf0e10cSrcweir catch( const std::bad_alloc& ) 369cdf0e10cSrcweir { 370cdf0e10cSrcweir // memory exception, clean up 371cdf0e10cSrcweir pDstBuffer->mpBits = NULL; 372cdf0e10cSrcweir delete pDstBuffer; 373cdf0e10cSrcweir return NULL; 374cdf0e10cSrcweir } 375cdf0e10cSrcweir 376cdf0e10cSrcweir // do we need a destination palette or color mask? 377cdf0e10cSrcweir if( ( nDstScanlineFormat == BMP_FORMAT_1BIT_MSB_PAL ) || 378cdf0e10cSrcweir ( nDstScanlineFormat == BMP_FORMAT_1BIT_LSB_PAL ) || 379cdf0e10cSrcweir ( nDstScanlineFormat == BMP_FORMAT_4BIT_MSN_PAL ) || 380cdf0e10cSrcweir ( nDstScanlineFormat == BMP_FORMAT_4BIT_LSN_PAL ) || 381cdf0e10cSrcweir ( nDstScanlineFormat == BMP_FORMAT_8BIT_PAL ) ) 382cdf0e10cSrcweir { 383cdf0e10cSrcweir DBG_ASSERT( pDstPal, "destination buffer requires palette" ); 384cdf0e10cSrcweir pDstBuffer->maPalette = *pDstPal; 385cdf0e10cSrcweir } 386cdf0e10cSrcweir else if( ( nDstScanlineFormat == BMP_FORMAT_8BIT_TC_MASK ) || 387cdf0e10cSrcweir ( nDstScanlineFormat == BMP_FORMAT_16BIT_TC_MSB_MASK ) || 388cdf0e10cSrcweir ( nDstScanlineFormat == BMP_FORMAT_16BIT_TC_LSB_MASK ) || 389cdf0e10cSrcweir ( nDstScanlineFormat == BMP_FORMAT_24BIT_TC_MASK ) || 390cdf0e10cSrcweir ( nDstScanlineFormat == BMP_FORMAT_32BIT_TC_MASK ) ) 391cdf0e10cSrcweir { 392cdf0e10cSrcweir DBG_ASSERT( pDstMask, "destination buffer requires color mask" ); 393cdf0e10cSrcweir pDstBuffer->maColorMask = *pDstMask; 394cdf0e10cSrcweir } 395cdf0e10cSrcweir 396cdf0e10cSrcweir // short circuit the most important conversions 397cdf0e10cSrcweir bool bFastConvert = ImplFastBitmapConversion( *pDstBuffer, rSrcBuffer, rTwoRect ); 398cdf0e10cSrcweir if( bFastConvert ) 399cdf0e10cSrcweir return pDstBuffer; 400cdf0e10cSrcweir 401cdf0e10cSrcweir const long nSrcX = rTwoRect.mnSrcX, nSrcY = rTwoRect.mnSrcY; 402cdf0e10cSrcweir const long nSrcDX = rTwoRect.mnSrcWidth, nSrcDY = rTwoRect.mnSrcHeight; 403cdf0e10cSrcweir const long nDstDX = rTwoRect.mnDestWidth, nDstDY = rTwoRect.mnDestHeight; 404cdf0e10cSrcweir Scanline* pSrcScan = NULL; 405cdf0e10cSrcweir Scanline* pDstScan = NULL; 406cdf0e10cSrcweir long* pMapX = NULL; 407cdf0e10cSrcweir long* pMapY = NULL; 408cdf0e10cSrcweir long nTmp, nOffset; 409cdf0e10cSrcweir 410cdf0e10cSrcweir try 411cdf0e10cSrcweir { 412cdf0e10cSrcweir pSrcScan = new Scanline[ rSrcBuffer.mnHeight ]; 413cdf0e10cSrcweir pDstScan = new Scanline[ nDstDY ]; 414cdf0e10cSrcweir pMapX = new long[ nDstDX ]; 415cdf0e10cSrcweir pMapY = new long[ nDstDY ]; 416cdf0e10cSrcweir } 417cdf0e10cSrcweir catch( const std::bad_alloc& ) 418cdf0e10cSrcweir { 419cdf0e10cSrcweir // memory exception, clean up 420cdf0e10cSrcweir // remark: the buffer ptr causing the exception 421cdf0e10cSrcweir // is still NULL here 422cdf0e10cSrcweir delete[] pSrcScan; 423cdf0e10cSrcweir delete[] pDstScan; 424cdf0e10cSrcweir delete[] pMapX; 425cdf0e10cSrcweir delete[] pMapY; 426cdf0e10cSrcweir delete pDstBuffer; 427cdf0e10cSrcweir return NULL; 428cdf0e10cSrcweir } 429cdf0e10cSrcweir 430cdf0e10cSrcweir // horizontal mapping table 431cdf0e10cSrcweir if( nDstDX != nSrcDX ) 432cdf0e10cSrcweir { 433cdf0e10cSrcweir const double fFactorX = ( nDstDX > 1 ) ? (double) ( nSrcDX - 1 ) / ( nDstDX - 1 ) : 0.0; 434cdf0e10cSrcweir 435cdf0e10cSrcweir for( i = 0L; i < nDstDX; i++ ) 436cdf0e10cSrcweir pMapX[ i ] = nSrcX + FRound( i * fFactorX ); 437cdf0e10cSrcweir } 438cdf0e10cSrcweir else 439cdf0e10cSrcweir { 440cdf0e10cSrcweir for( i = 0L, nTmp = nSrcX; i < nDstDX; i++ ) 441cdf0e10cSrcweir pMapX[ i ] = nTmp++; 442cdf0e10cSrcweir } 443cdf0e10cSrcweir 444cdf0e10cSrcweir // vertical mapping table 445cdf0e10cSrcweir if( nDstDY != nSrcDY ) 446cdf0e10cSrcweir { 447cdf0e10cSrcweir const double fFactorY = ( nDstDY > 1 ) ? (double) ( nSrcDY - 1 ) / ( nDstDY - 1 ) : 0.0; 448cdf0e10cSrcweir 449cdf0e10cSrcweir for( i = 0L; i < nDstDY; i++ ) 450cdf0e10cSrcweir pMapY[ i ] = nSrcY + FRound( i * fFactorY ); 451cdf0e10cSrcweir } 452cdf0e10cSrcweir else 453cdf0e10cSrcweir { 454cdf0e10cSrcweir for( i = 0L, nTmp = nSrcY; i < nDstDY; i++ ) 455cdf0e10cSrcweir pMapY[ i ] = nTmp++; 456cdf0e10cSrcweir } 457cdf0e10cSrcweir 458cdf0e10cSrcweir // source scanline buffer 459cdf0e10cSrcweir Scanline pTmpScan; 460cdf0e10cSrcweir if( BMP_SCANLINE_ADJUSTMENT( rSrcBuffer.mnFormat ) == BMP_FORMAT_TOP_DOWN ) 461cdf0e10cSrcweir pTmpScan = rSrcBuffer.mpBits, nOffset = rSrcBuffer.mnScanlineSize; 462cdf0e10cSrcweir else 463cdf0e10cSrcweir { 464cdf0e10cSrcweir pTmpScan = rSrcBuffer.mpBits + ( rSrcBuffer.mnHeight - 1 ) * rSrcBuffer.mnScanlineSize; 465cdf0e10cSrcweir nOffset = -rSrcBuffer.mnScanlineSize; 466cdf0e10cSrcweir } 467cdf0e10cSrcweir 468cdf0e10cSrcweir for( i = 0L; i < rSrcBuffer.mnHeight; i++, pTmpScan += nOffset ) 469cdf0e10cSrcweir pSrcScan[ i ] = pTmpScan; 470cdf0e10cSrcweir 471cdf0e10cSrcweir // destination scanline buffer 472cdf0e10cSrcweir if( BMP_SCANLINE_ADJUSTMENT( pDstBuffer->mnFormat ) == BMP_FORMAT_TOP_DOWN ) 473cdf0e10cSrcweir pTmpScan = pDstBuffer->mpBits, nOffset = pDstBuffer->mnScanlineSize; 474cdf0e10cSrcweir else 475cdf0e10cSrcweir { 476cdf0e10cSrcweir pTmpScan = pDstBuffer->mpBits + ( nDstDY - 1 ) * pDstBuffer->mnScanlineSize; 477cdf0e10cSrcweir nOffset = -pDstBuffer->mnScanlineSize; 478cdf0e10cSrcweir } 479cdf0e10cSrcweir 480cdf0e10cSrcweir for( i = 0L; i < nDstDY; i++, pTmpScan += nOffset ) 481cdf0e10cSrcweir pDstScan[ i ] = pTmpScan; 482cdf0e10cSrcweir 483cdf0e10cSrcweir // do buffer scaling and conversion 484cdf0e10cSrcweir if( rSrcBuffer.mnBitCount <= 8 && pDstBuffer->mnBitCount <= 8 ) 485cdf0e10cSrcweir { 486cdf0e10cSrcweir ImplPALToPAL( rSrcBuffer, *pDstBuffer, pFncGetPixel, pFncSetPixel, 487cdf0e10cSrcweir pSrcScan, pDstScan, pMapX, pMapY ); 488cdf0e10cSrcweir } 489cdf0e10cSrcweir else if( rSrcBuffer.mnBitCount <= 8 && pDstBuffer->mnBitCount > 8 ) 490cdf0e10cSrcweir { 491cdf0e10cSrcweir ImplPALToTC( rSrcBuffer, *pDstBuffer, pFncGetPixel, pFncSetPixel, 492cdf0e10cSrcweir pSrcScan, pDstScan, pMapX, pMapY ); 493cdf0e10cSrcweir } 494cdf0e10cSrcweir else if( rSrcBuffer.mnBitCount > 8 && pDstBuffer->mnBitCount > 8 ) 495cdf0e10cSrcweir { 496cdf0e10cSrcweir ImplTCToTC( rSrcBuffer, *pDstBuffer, pFncGetPixel, pFncSetPixel, 497cdf0e10cSrcweir pSrcScan, pDstScan, pMapX, pMapY ); 498cdf0e10cSrcweir } 499cdf0e10cSrcweir else 500cdf0e10cSrcweir { 501cdf0e10cSrcweir ImplTCToPAL( rSrcBuffer, *pDstBuffer, pFncGetPixel, pFncSetPixel, 502cdf0e10cSrcweir pSrcScan, pDstScan, pMapX, pMapY ); 503cdf0e10cSrcweir } 504cdf0e10cSrcweir 505cdf0e10cSrcweir // cleanup 506cdf0e10cSrcweir delete[] pSrcScan; 507cdf0e10cSrcweir delete[] pDstScan; 508cdf0e10cSrcweir delete[] pMapX; 509cdf0e10cSrcweir delete[] pMapY; 510cdf0e10cSrcweir 511cdf0e10cSrcweir return pDstBuffer; 512cdf0e10cSrcweir } 513