19f62ea84SAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 39f62ea84SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 49f62ea84SAndrew Rist * or more contributor license agreements. See the NOTICE file 59f62ea84SAndrew Rist * distributed with this work for additional information 69f62ea84SAndrew Rist * regarding copyright ownership. The ASF licenses this file 79f62ea84SAndrew Rist * to you under the Apache License, Version 2.0 (the 89f62ea84SAndrew Rist * "License"); you may not use this file except in compliance 99f62ea84SAndrew Rist * with the License. You may obtain a copy of the License at 109f62ea84SAndrew Rist * 119f62ea84SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 129f62ea84SAndrew Rist * 139f62ea84SAndrew Rist * Unless required by applicable law or agreed to in writing, 149f62ea84SAndrew Rist * software distributed under the License is distributed on an 159f62ea84SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 169f62ea84SAndrew Rist * KIND, either express or implied. See the License for the 179f62ea84SAndrew Rist * specific language governing permissions and limitations 189f62ea84SAndrew Rist * under the License. 199f62ea84SAndrew Rist * 209f62ea84SAndrew Rist *************************************************************/ 219f62ea84SAndrew Rist 229f62ea84SAndrew 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 291*5f27b83cSArmin Le Grand BitmapBuffer* StretchAndConvert( 292*5f27b83cSArmin Le Grand const BitmapBuffer& rSrcBuffer, const SalTwoRect& rTwoRect, 293*5f27b83cSArmin Le Grand sal_uLong nDstBitmapFormat, const BitmapPalette* pDstPal, const ColorMask* pDstMask ) 294cdf0e10cSrcweir { 295cdf0e10cSrcweir FncGetPixel pFncGetPixel; 296cdf0e10cSrcweir FncSetPixel pFncSetPixel; 297cdf0e10cSrcweir BitmapBuffer* pDstBuffer = new BitmapBuffer; 298cdf0e10cSrcweir long i; 299cdf0e10cSrcweir 300cdf0e10cSrcweir // set function for getting pixels 301cdf0e10cSrcweir switch( BMP_SCANLINE_FORMAT( rSrcBuffer.mnFormat ) ) 302cdf0e10cSrcweir { 303cdf0e10cSrcweir IMPL_CASE_GET_FORMAT( _1BIT_MSB_PAL ); 304cdf0e10cSrcweir IMPL_CASE_GET_FORMAT( _1BIT_LSB_PAL ); 305cdf0e10cSrcweir IMPL_CASE_GET_FORMAT( _4BIT_MSN_PAL ); 306cdf0e10cSrcweir IMPL_CASE_GET_FORMAT( _4BIT_LSN_PAL ); 307cdf0e10cSrcweir IMPL_CASE_GET_FORMAT( _8BIT_PAL ); 308cdf0e10cSrcweir IMPL_CASE_GET_FORMAT( _8BIT_TC_MASK ); 309cdf0e10cSrcweir IMPL_CASE_GET_FORMAT( _16BIT_TC_MSB_MASK ); 310cdf0e10cSrcweir IMPL_CASE_GET_FORMAT( _16BIT_TC_LSB_MASK ); 311cdf0e10cSrcweir IMPL_CASE_GET_FORMAT( _24BIT_TC_BGR ); 312cdf0e10cSrcweir IMPL_CASE_GET_FORMAT( _24BIT_TC_RGB ); 313cdf0e10cSrcweir IMPL_CASE_GET_FORMAT( _24BIT_TC_MASK ); 314cdf0e10cSrcweir IMPL_CASE_GET_FORMAT( _32BIT_TC_ABGR ); 315cdf0e10cSrcweir IMPL_CASE_GET_FORMAT( _32BIT_TC_ARGB ); 316cdf0e10cSrcweir IMPL_CASE_GET_FORMAT( _32BIT_TC_BGRA ); 317cdf0e10cSrcweir IMPL_CASE_GET_FORMAT( _32BIT_TC_RGBA ); 318cdf0e10cSrcweir IMPL_CASE_GET_FORMAT( _32BIT_TC_MASK ); 319cdf0e10cSrcweir 320cdf0e10cSrcweir default: 321cdf0e10cSrcweir // should never come here 322cdf0e10cSrcweir // initialize pFncGetPixel to something valid that is 323cdf0e10cSrcweir // least likely to crash 324cdf0e10cSrcweir pFncGetPixel = BitmapReadAccess::GetPixelFor_1BIT_MSB_PAL; 325cdf0e10cSrcweir DBG_ERROR( "unknown read format" ); 326cdf0e10cSrcweir break; 327cdf0e10cSrcweir } 328cdf0e10cSrcweir 329cdf0e10cSrcweir // set function for setting pixels 330cdf0e10cSrcweir const sal_uLong nDstScanlineFormat = BMP_SCANLINE_FORMAT( nDstBitmapFormat ); 331cdf0e10cSrcweir switch( nDstScanlineFormat ) 332cdf0e10cSrcweir { 333cdf0e10cSrcweir IMPL_CASE_SET_FORMAT( _1BIT_MSB_PAL, 1 ); 334cdf0e10cSrcweir IMPL_CASE_SET_FORMAT( _1BIT_LSB_PAL, 1 ); 335cdf0e10cSrcweir IMPL_CASE_SET_FORMAT( _4BIT_MSN_PAL, 1 ); 336cdf0e10cSrcweir IMPL_CASE_SET_FORMAT( _4BIT_LSN_PAL, 4 ); 337cdf0e10cSrcweir IMPL_CASE_SET_FORMAT( _8BIT_PAL, 8 ); 338cdf0e10cSrcweir IMPL_CASE_SET_FORMAT( _8BIT_TC_MASK, 8 ); 339cdf0e10cSrcweir IMPL_CASE_SET_FORMAT( _16BIT_TC_MSB_MASK, 16 ); 340cdf0e10cSrcweir IMPL_CASE_SET_FORMAT( _16BIT_TC_LSB_MASK, 16 ); 341cdf0e10cSrcweir IMPL_CASE_SET_FORMAT( _24BIT_TC_BGR, 24 ); 342cdf0e10cSrcweir IMPL_CASE_SET_FORMAT( _24BIT_TC_RGB, 24 ); 343cdf0e10cSrcweir IMPL_CASE_SET_FORMAT( _24BIT_TC_MASK, 24 ); 344cdf0e10cSrcweir IMPL_CASE_SET_FORMAT( _32BIT_TC_ABGR, 32 ); 345cdf0e10cSrcweir IMPL_CASE_SET_FORMAT( _32BIT_TC_ARGB, 32 ); 346cdf0e10cSrcweir IMPL_CASE_SET_FORMAT( _32BIT_TC_BGRA, 32 ); 347cdf0e10cSrcweir IMPL_CASE_SET_FORMAT( _32BIT_TC_RGBA, 32 ); 348cdf0e10cSrcweir IMPL_CASE_SET_FORMAT( _32BIT_TC_MASK, 32 ); 349cdf0e10cSrcweir 350cdf0e10cSrcweir default: 351cdf0e10cSrcweir // should never come here 352cdf0e10cSrcweir // initialize pFncSetPixel to something valid that is 353cdf0e10cSrcweir // least likely to crash 354cdf0e10cSrcweir pFncSetPixel = BitmapReadAccess::SetPixelFor_1BIT_MSB_PAL; 355cdf0e10cSrcweir pDstBuffer->mnBitCount = 1; 356cdf0e10cSrcweir DBG_ERROR( "unknown write format" ); 357cdf0e10cSrcweir break; 358cdf0e10cSrcweir } 359cdf0e10cSrcweir 360cdf0e10cSrcweir // fill destination buffer 361cdf0e10cSrcweir pDstBuffer->mnFormat = nDstBitmapFormat; 362cdf0e10cSrcweir pDstBuffer->mnWidth = rTwoRect.mnDestWidth; 363cdf0e10cSrcweir pDstBuffer->mnHeight = rTwoRect.mnDestHeight; 364cdf0e10cSrcweir pDstBuffer->mnScanlineSize = AlignedWidth4Bytes( pDstBuffer->mnBitCount * pDstBuffer->mnWidth ); 365cdf0e10cSrcweir try 366cdf0e10cSrcweir { 367cdf0e10cSrcweir pDstBuffer->mpBits = new sal_uInt8[ pDstBuffer->mnScanlineSize * pDstBuffer->mnHeight ]; 368cdf0e10cSrcweir } 369cdf0e10cSrcweir catch( const std::bad_alloc& ) 370cdf0e10cSrcweir { 371cdf0e10cSrcweir // memory exception, clean up 372cdf0e10cSrcweir pDstBuffer->mpBits = NULL; 373cdf0e10cSrcweir delete pDstBuffer; 374cdf0e10cSrcweir return NULL; 375cdf0e10cSrcweir } 376cdf0e10cSrcweir 377cdf0e10cSrcweir // do we need a destination palette or color mask? 378cdf0e10cSrcweir if( ( nDstScanlineFormat == BMP_FORMAT_1BIT_MSB_PAL ) || 379cdf0e10cSrcweir ( nDstScanlineFormat == BMP_FORMAT_1BIT_LSB_PAL ) || 380cdf0e10cSrcweir ( nDstScanlineFormat == BMP_FORMAT_4BIT_MSN_PAL ) || 381cdf0e10cSrcweir ( nDstScanlineFormat == BMP_FORMAT_4BIT_LSN_PAL ) || 382cdf0e10cSrcweir ( nDstScanlineFormat == BMP_FORMAT_8BIT_PAL ) ) 383cdf0e10cSrcweir { 384cdf0e10cSrcweir DBG_ASSERT( pDstPal, "destination buffer requires palette" ); 385cdf0e10cSrcweir pDstBuffer->maPalette = *pDstPal; 386cdf0e10cSrcweir } 387cdf0e10cSrcweir else if( ( nDstScanlineFormat == BMP_FORMAT_8BIT_TC_MASK ) || 388cdf0e10cSrcweir ( nDstScanlineFormat == BMP_FORMAT_16BIT_TC_MSB_MASK ) || 389cdf0e10cSrcweir ( nDstScanlineFormat == BMP_FORMAT_16BIT_TC_LSB_MASK ) || 390cdf0e10cSrcweir ( nDstScanlineFormat == BMP_FORMAT_24BIT_TC_MASK ) || 391cdf0e10cSrcweir ( nDstScanlineFormat == BMP_FORMAT_32BIT_TC_MASK ) ) 392cdf0e10cSrcweir { 393cdf0e10cSrcweir DBG_ASSERT( pDstMask, "destination buffer requires color mask" ); 394cdf0e10cSrcweir pDstBuffer->maColorMask = *pDstMask; 395cdf0e10cSrcweir } 396cdf0e10cSrcweir 397cdf0e10cSrcweir // short circuit the most important conversions 398cdf0e10cSrcweir bool bFastConvert = ImplFastBitmapConversion( *pDstBuffer, rSrcBuffer, rTwoRect ); 399cdf0e10cSrcweir if( bFastConvert ) 400cdf0e10cSrcweir return pDstBuffer; 401cdf0e10cSrcweir 402cdf0e10cSrcweir const long nSrcX = rTwoRect.mnSrcX, nSrcY = rTwoRect.mnSrcY; 403cdf0e10cSrcweir const long nSrcDX = rTwoRect.mnSrcWidth, nSrcDY = rTwoRect.mnSrcHeight; 404cdf0e10cSrcweir const long nDstDX = rTwoRect.mnDestWidth, nDstDY = rTwoRect.mnDestHeight; 405cdf0e10cSrcweir Scanline* pSrcScan = NULL; 406cdf0e10cSrcweir Scanline* pDstScan = NULL; 407cdf0e10cSrcweir long* pMapX = NULL; 408cdf0e10cSrcweir long* pMapY = NULL; 409cdf0e10cSrcweir long nTmp, nOffset; 410cdf0e10cSrcweir 411cdf0e10cSrcweir try 412cdf0e10cSrcweir { 413cdf0e10cSrcweir pSrcScan = new Scanline[ rSrcBuffer.mnHeight ]; 414cdf0e10cSrcweir pDstScan = new Scanline[ nDstDY ]; 415cdf0e10cSrcweir pMapX = new long[ nDstDX ]; 416cdf0e10cSrcweir pMapY = new long[ nDstDY ]; 417cdf0e10cSrcweir } 418cdf0e10cSrcweir catch( const std::bad_alloc& ) 419cdf0e10cSrcweir { 420cdf0e10cSrcweir // memory exception, clean up 421cdf0e10cSrcweir // remark: the buffer ptr causing the exception 422cdf0e10cSrcweir // is still NULL here 423cdf0e10cSrcweir delete[] pSrcScan; 424cdf0e10cSrcweir delete[] pDstScan; 425cdf0e10cSrcweir delete[] pMapX; 426cdf0e10cSrcweir delete[] pMapY; 427cdf0e10cSrcweir delete pDstBuffer; 428cdf0e10cSrcweir return NULL; 429cdf0e10cSrcweir } 430cdf0e10cSrcweir 431cdf0e10cSrcweir // horizontal mapping table 432cdf0e10cSrcweir if( nDstDX != nSrcDX ) 433cdf0e10cSrcweir { 434cdf0e10cSrcweir const double fFactorX = ( nDstDX > 1 ) ? (double) ( nSrcDX - 1 ) / ( nDstDX - 1 ) : 0.0; 435cdf0e10cSrcweir 436cdf0e10cSrcweir for( i = 0L; i < nDstDX; i++ ) 437cdf0e10cSrcweir pMapX[ i ] = nSrcX + FRound( i * fFactorX ); 438cdf0e10cSrcweir } 439cdf0e10cSrcweir else 440cdf0e10cSrcweir { 441cdf0e10cSrcweir for( i = 0L, nTmp = nSrcX; i < nDstDX; i++ ) 442cdf0e10cSrcweir pMapX[ i ] = nTmp++; 443cdf0e10cSrcweir } 444cdf0e10cSrcweir 445cdf0e10cSrcweir // vertical mapping table 446cdf0e10cSrcweir if( nDstDY != nSrcDY ) 447cdf0e10cSrcweir { 448cdf0e10cSrcweir const double fFactorY = ( nDstDY > 1 ) ? (double) ( nSrcDY - 1 ) / ( nDstDY - 1 ) : 0.0; 449cdf0e10cSrcweir 450cdf0e10cSrcweir for( i = 0L; i < nDstDY; i++ ) 451cdf0e10cSrcweir pMapY[ i ] = nSrcY + FRound( i * fFactorY ); 452cdf0e10cSrcweir } 453cdf0e10cSrcweir else 454cdf0e10cSrcweir { 455cdf0e10cSrcweir for( i = 0L, nTmp = nSrcY; i < nDstDY; i++ ) 456cdf0e10cSrcweir pMapY[ i ] = nTmp++; 457cdf0e10cSrcweir } 458cdf0e10cSrcweir 459cdf0e10cSrcweir // source scanline buffer 460cdf0e10cSrcweir Scanline pTmpScan; 461cdf0e10cSrcweir if( BMP_SCANLINE_ADJUSTMENT( rSrcBuffer.mnFormat ) == BMP_FORMAT_TOP_DOWN ) 462cdf0e10cSrcweir pTmpScan = rSrcBuffer.mpBits, nOffset = rSrcBuffer.mnScanlineSize; 463cdf0e10cSrcweir else 464cdf0e10cSrcweir { 465cdf0e10cSrcweir pTmpScan = rSrcBuffer.mpBits + ( rSrcBuffer.mnHeight - 1 ) * rSrcBuffer.mnScanlineSize; 466cdf0e10cSrcweir nOffset = -rSrcBuffer.mnScanlineSize; 467cdf0e10cSrcweir } 468cdf0e10cSrcweir 469cdf0e10cSrcweir for( i = 0L; i < rSrcBuffer.mnHeight; i++, pTmpScan += nOffset ) 470cdf0e10cSrcweir pSrcScan[ i ] = pTmpScan; 471cdf0e10cSrcweir 472cdf0e10cSrcweir // destination scanline buffer 473cdf0e10cSrcweir if( BMP_SCANLINE_ADJUSTMENT( pDstBuffer->mnFormat ) == BMP_FORMAT_TOP_DOWN ) 474cdf0e10cSrcweir pTmpScan = pDstBuffer->mpBits, nOffset = pDstBuffer->mnScanlineSize; 475cdf0e10cSrcweir else 476cdf0e10cSrcweir { 477cdf0e10cSrcweir pTmpScan = pDstBuffer->mpBits + ( nDstDY - 1 ) * pDstBuffer->mnScanlineSize; 478cdf0e10cSrcweir nOffset = -pDstBuffer->mnScanlineSize; 479cdf0e10cSrcweir } 480cdf0e10cSrcweir 481cdf0e10cSrcweir for( i = 0L; i < nDstDY; i++, pTmpScan += nOffset ) 482cdf0e10cSrcweir pDstScan[ i ] = pTmpScan; 483cdf0e10cSrcweir 484cdf0e10cSrcweir // do buffer scaling and conversion 485cdf0e10cSrcweir if( rSrcBuffer.mnBitCount <= 8 && pDstBuffer->mnBitCount <= 8 ) 486cdf0e10cSrcweir { 487cdf0e10cSrcweir ImplPALToPAL( rSrcBuffer, *pDstBuffer, pFncGetPixel, pFncSetPixel, 488cdf0e10cSrcweir pSrcScan, pDstScan, pMapX, pMapY ); 489cdf0e10cSrcweir } 490cdf0e10cSrcweir else if( rSrcBuffer.mnBitCount <= 8 && pDstBuffer->mnBitCount > 8 ) 491cdf0e10cSrcweir { 492cdf0e10cSrcweir ImplPALToTC( rSrcBuffer, *pDstBuffer, pFncGetPixel, pFncSetPixel, 493cdf0e10cSrcweir pSrcScan, pDstScan, pMapX, pMapY ); 494cdf0e10cSrcweir } 495cdf0e10cSrcweir else if( rSrcBuffer.mnBitCount > 8 && pDstBuffer->mnBitCount > 8 ) 496cdf0e10cSrcweir { 497cdf0e10cSrcweir ImplTCToTC( rSrcBuffer, *pDstBuffer, pFncGetPixel, pFncSetPixel, 498cdf0e10cSrcweir pSrcScan, pDstScan, pMapX, pMapY ); 499cdf0e10cSrcweir } 500cdf0e10cSrcweir else 501cdf0e10cSrcweir { 502cdf0e10cSrcweir ImplTCToPAL( rSrcBuffer, *pDstBuffer, pFncGetPixel, pFncSetPixel, 503cdf0e10cSrcweir pSrcScan, pDstScan, pMapX, pMapY ); 504cdf0e10cSrcweir } 505cdf0e10cSrcweir 506cdf0e10cSrcweir // cleanup 507cdf0e10cSrcweir delete[] pSrcScan; 508cdf0e10cSrcweir delete[] pDstScan; 509cdf0e10cSrcweir delete[] pMapX; 510cdf0e10cSrcweir delete[] pMapY; 511cdf0e10cSrcweir 512cdf0e10cSrcweir return pDstBuffer; 513cdf0e10cSrcweir } 514