LCOV - code coverage report
Current view: top level - vcl/source/gdi - salmisc.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 23 228 10.1 %
Date: 2015-06-13 12:38:46 Functions: 1 6 16.7 %
Legend: Lines: hit not hit

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

Generated by: LCOV version 1.11