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

Generated by: LCOV version 1.10