[Libreoffice-commits] .: 3 commits - svtools/inc svtools/source

Tomaž Vajngerl tvajngerl at kemper.freedesktop.org
Mon Jun 25 12:25:12 PDT 2012


 svtools/inc/svtools/grfmgr.hxx     |   29 
 svtools/source/graphic/grfmgr2.cxx | 1097 ++++---------------------------------
 2 files changed, 125 insertions(+), 1001 deletions(-)

New commits:
commit 447844036930f6503e6791e2207bc6408a4cbb84
Author: Tomaž Vajngerl <quikee at gmail.com>
Date:   Mon Jun 25 21:19:21 2012 +0200

    Remove ImplCreateScaled and ImplCreateRotatedScaled
    
    ImplCreateScaled and ImplCreateRotatedScaled are now not used anymore,
    so they can be removed.
    
    Change-Id: I42bbb49eedd474e580ccc9e7dd9e00609451501b

diff --git a/svtools/inc/svtools/grfmgr.hxx b/svtools/inc/svtools/grfmgr.hxx
index 438efcd..e9d470b 100644
--- a/svtools/inc/svtools/grfmgr.hxx
+++ b/svtools/inc/svtools/grfmgr.hxx
@@ -589,35 +589,6 @@ private:
                             BitmapEx& rOutBmpEx
                         );
 
-    sal_Bool SVT_DLLPRIVATE ImplCreateScaled(
-                            const BitmapEx& rBmpEx,
-                            long* pMapIX,
-                            long* pMapFX,
-                            long* pMapIY,
-                            long* pMapFY,
-                            long nStartX,
-                            long nEndX,
-                            long nStartY,
-                            long nEndY,
-                            BitmapEx& rOutBmpEx
-                        );
-
-    sal_Bool SVT_DLLPRIVATE ImplCreateRotatedScaled(
-                            const BitmapEx& rBmpEx,
-                            sal_uInt16 nRot10,
-                            const Size& rOutSzPix,
-                            const Size& rUntSzPix,
-                            long* pMapIX,
-                            long* pMapFX,
-                            long* pMapIY,
-                            long* pMapFY,
-                            long nStartX,
-                            long nEndX,
-                            long nStartY,
-                            long nEndY,
-                            BitmapEx& rOutBmpEx
-                        );
-
     static void SVT_DLLPRIVATE ImplAdjust(
                             BitmapEx& rBmpEx,
                             const GraphicAttr& rAttr,
diff --git a/svtools/source/graphic/grfmgr2.cxx b/svtools/source/graphic/grfmgr2.cxx
index fa01654..9e8490c 100644
--- a/svtools/source/graphic/grfmgr2.cxx
+++ b/svtools/source/graphic/grfmgr2.cxx
@@ -796,736 +796,6 @@ sal_Bool GraphicManager::ImplCreateOutput( OutputDevice* pOut,
     return sal_True;
 }
 
-sal_Bool GraphicManager::ImplCreateScaled( const BitmapEx& rBmpEx,
-                                       long* pMapIX, long* pMapFX, long* pMapIY, long* pMapFY,
-                                       long nStartX, long nEndX, long nStartY, long nEndY,
-                                       BitmapEx& rOutBmpEx )
-{
-    Bitmap              aBmp( rBmpEx.GetBitmap() );
-    Bitmap              aOutBmp;
-    BitmapReadAccess*   pAcc = aBmp.AcquireReadAccess();
-    BitmapWriteAccess*  pWAcc;
-    BitmapColor         aCol0, aCol1, aColRes;
-    const long          nDstW = nEndX - nStartX + 1L;
-    const long          nDstH = nEndY - nStartY + 1L;
-    long                nX, nY, nTmpX, nTmpY, nTmpFX, nTmpFY;
-    long                nXDst, nYDst;
-    sal_uInt8               cR0, cG0, cB0, cR1, cG1, cB1;
-    sal_Bool                bRet = sal_False;
-
-    DBG_ASSERT( aBmp.GetSizePixel() == rBmpEx.GetSizePixel(),
-                "GraphicManager::ImplCreateScaled(): bmp size inconsistent" );
-
-    if( pAcc )
-    {
-        aOutBmp = Bitmap( Size( nDstW, nDstH ), 24 );
-        pWAcc = aOutBmp.AcquireWriteAccess();
-
-        if( pWAcc )
-        {
-            if( pAcc->HasPalette() )
-            {
-                if( pAcc->GetScanlineFormat() == BMP_FORMAT_8BIT_PAL )
-                {
-                    Scanline pLine0, pLine1;
-
-                    for( nY = nStartY, nYDst = 0L; nY <= nEndY; nY++, nYDst++ )
-                    {
-                        nTmpY = pMapIY[ nY ]; nTmpFY = pMapFY[ nY ];
-                        pLine0 = pAcc->GetScanline( nTmpY );
-                        pLine1 = pAcc->GetScanline( ++nTmpY );
-
-                        for( nX = nStartX, nXDst = 0L; nX <= nEndX; nX++ )
-                        {
-                            nTmpX = pMapIX[ nX ]; nTmpFX = pMapFX[ nX ];
-
-                            const BitmapColor& rCol0 = pAcc->GetPaletteColor( pLine0[ nTmpX ] );
-                            const BitmapColor& rCol2 = pAcc->GetPaletteColor( pLine1[ nTmpX ] );
-                            const BitmapColor& rCol1 = pAcc->GetPaletteColor( pLine0[ ++nTmpX ] );
-                            const BitmapColor& rCol3 = pAcc->GetPaletteColor( pLine1[ nTmpX ] );
-
-                            cR0 = MAP( rCol0.GetRed(), rCol1.GetRed(), nTmpFX );
-                            cG0 = MAP( rCol0.GetGreen(), rCol1.GetGreen(), nTmpFX );
-                            cB0 = MAP( rCol0.GetBlue(), rCol1.GetBlue(), nTmpFX );
-
-                            cR1 = MAP( rCol2.GetRed(), rCol3.GetRed(), nTmpFX );
-                            cG1 = MAP( rCol2.GetGreen(), rCol3.GetGreen(), nTmpFX );
-                            cB1 = MAP( rCol2.GetBlue(), rCol3.GetBlue(), nTmpFX );
-
-                            aColRes.SetRed( MAP( cR0, cR1, nTmpFY ) );
-                            aColRes.SetGreen( MAP( cG0, cG1, nTmpFY ) );
-                            aColRes.SetBlue( MAP( cB0, cB1, nTmpFY ) );
-                            pWAcc->SetPixel( nYDst, nXDst++, aColRes );
-                        }
-                    }
-                }
-                else
-                {
-                    for( nY = nStartY, nYDst = 0L; nY <= nEndY; nY++, nYDst++ )
-                    {
-                        nTmpY = pMapIY[ nY ], nTmpFY = pMapFY[ nY ];
-
-                        for( nX = nStartX, nXDst = 0L; nX <= nEndX; nX++ )
-                        {
-                            nTmpX = pMapIX[ nX ]; nTmpFX = pMapFX[ nX ];
-
-                            aCol0 = pAcc->GetPaletteColor( pAcc->GetPixel( nTmpY, nTmpX ) );
-                            aCol1 = pAcc->GetPaletteColor( pAcc->GetPixel( nTmpY, ++nTmpX ) );
-                            cR0 = MAP( aCol0.GetRed(), aCol1.GetRed(), nTmpFX );
-                            cG0 = MAP( aCol0.GetGreen(), aCol1.GetGreen(), nTmpFX );
-                            cB0 = MAP( aCol0.GetBlue(), aCol1.GetBlue(), nTmpFX );
-
-                            aCol1 = pAcc->GetPaletteColor( pAcc->GetPixel( ++nTmpY, nTmpX ) );
-                            aCol0 = pAcc->GetPaletteColor( pAcc->GetPixel( nTmpY--, --nTmpX ) );
-                            cR1 = MAP( aCol0.GetRed(), aCol1.GetRed(), nTmpFX );
-                            cG1 = MAP( aCol0.GetGreen(), aCol1.GetGreen(), nTmpFX );
-                            cB1 = MAP( aCol0.GetBlue(), aCol1.GetBlue(), nTmpFX );
-
-                            aColRes.SetRed( MAP( cR0, cR1, nTmpFY ) );
-                            aColRes.SetGreen( MAP( cG0, cG1, nTmpFY ) );
-                            aColRes.SetBlue( MAP( cB0, cB1, nTmpFY ) );
-                            pWAcc->SetPixel( nYDst, nXDst++, aColRes );
-                        }
-                    }
-                }
-            }
-            else
-            {
-                if( pAcc->GetScanlineFormat() == BMP_FORMAT_24BIT_TC_BGR )
-                {
-                    Scanline    pLine0, pLine1, pTmp0, pTmp1;
-                    long        nOff;
-
-                    for( nY = nStartY, nYDst = 0L; nY <= nEndY; nY++, nYDst++ )
-                    {
-                        nTmpY = pMapIY[ nY ]; nTmpFY = pMapFY[ nY ];
-                        pLine0 = pAcc->GetScanline( nTmpY );
-                        pLine1 = pAcc->GetScanline( ++nTmpY );
-
-                        for( nX = nStartX, nXDst = 0L; nX <= nEndX; nX++ )
-                        {
-                            nOff = 3L * ( nTmpX = pMapIX[ nX ] );
-                            nTmpFX = pMapFX[ nX ];
-
-                            pTmp1 = ( pTmp0 = pLine0 + nOff ) + 3L;
-                            cB0 = MAP( *pTmp0, *pTmp1, nTmpFX ); pTmp0++; pTmp1++;
-                            cG0 = MAP( *pTmp0, *pTmp1, nTmpFX ); pTmp0++; pTmp1++;
-                            cR0 = MAP( *pTmp0, *pTmp1, nTmpFX );
-
-                            pTmp1 = ( pTmp0 = pLine1 + nOff ) + 3L;
-                            cB1 = MAP( *pTmp0, *pTmp1, nTmpFX ); pTmp0++; pTmp1++;
-                            cG1 = MAP( *pTmp0, *pTmp1, nTmpFX ); pTmp0++; pTmp1++;
-                            cR1 = MAP( *pTmp0, *pTmp1, nTmpFX );
-
-                            aColRes.SetRed( MAP( cR0, cR1, nTmpFY ) );
-                            aColRes.SetGreen( MAP( cG0, cG1, nTmpFY ) );
-                            aColRes.SetBlue( MAP( cB0, cB1, nTmpFY ) );
-                            pWAcc->SetPixel( nYDst, nXDst++, aColRes );
-                        }
-                    }
-                }
-                else if( pAcc->GetScanlineFormat() == BMP_FORMAT_24BIT_TC_RGB )
-                {
-                    Scanline    pLine0, pLine1, pTmp0, pTmp1;
-                    long        nOff;
-
-                    for( nY = nStartY, nYDst = 0L; nY <= nEndY; nY++, nYDst++ )
-                    {
-                        nTmpY = pMapIY[ nY ]; nTmpFY = pMapFY[ nY ];
-                        pLine0 = pAcc->GetScanline( nTmpY );
-                        pLine1 = pAcc->GetScanline( ++nTmpY );
-
-                        for( nX = nStartX, nXDst = 0L; nX <= nEndX; nX++ )
-                        {
-                            nOff = 3L * ( nTmpX = pMapIX[ nX ] );
-                            nTmpFX = pMapFX[ nX ];
-
-                            pTmp1 = ( pTmp0 = pLine0 + nOff ) + 3L;
-                            cR0 = MAP( *pTmp0, *pTmp1, nTmpFX ); pTmp0++; pTmp1++;
-                            cG0 = MAP( *pTmp0, *pTmp1, nTmpFX ); pTmp0++; pTmp1++;
-                            cB0 = MAP( *pTmp0, *pTmp1, nTmpFX );
-
-                            pTmp1 = ( pTmp0 = pLine1 + nOff ) + 3L;
-                            cR1 = MAP( *pTmp0, *pTmp1, nTmpFX ); pTmp0++; pTmp1++;
-                            cG1 = MAP( *pTmp0, *pTmp1, nTmpFX ); pTmp0++; pTmp1++;
-                            cB1 = MAP( *pTmp0, *pTmp1, nTmpFX );
-
-                            aColRes.SetRed( MAP( cR0, cR1, nTmpFY ) );
-                            aColRes.SetGreen( MAP( cG0, cG1, nTmpFY ) );
-                            aColRes.SetBlue( MAP( cB0, cB1, nTmpFY ) );
-                            pWAcc->SetPixel( nYDst, nXDst++, aColRes );
-                        }
-                    }
-                }
-                else
-                {
-                    for( nY = nStartY, nYDst = 0L; nY <= nEndY; nY++, nYDst++ )
-                    {
-                        nTmpY = pMapIY[ nY ]; nTmpFY = pMapFY[ nY ];
-
-                        for( nX = nStartX, nXDst = 0L; nX <= nEndX; nX++ )
-                        {
-                            nTmpX = pMapIX[ nX ]; nTmpFX = pMapFX[ nX ];
-
-                            aCol0 = pAcc->GetPixel( nTmpY, nTmpX );
-                            aCol1 = pAcc->GetPixel( nTmpY, ++nTmpX );
-                            cR0 = MAP( aCol0.GetRed(), aCol1.GetRed(), nTmpFX );
-                            cG0 = MAP( aCol0.GetGreen(), aCol1.GetGreen(), nTmpFX );
-                            cB0 = MAP( aCol0.GetBlue(), aCol1.GetBlue(), nTmpFX );
-
-                            aCol1 = pAcc->GetPixel( ++nTmpY, nTmpX );
-                            aCol0 = pAcc->GetPixel( nTmpY--, --nTmpX );
-                            cR1 = MAP( aCol0.GetRed(), aCol1.GetRed(), nTmpFX );
-                            cG1 = MAP( aCol0.GetGreen(), aCol1.GetGreen(), nTmpFX );
-                            cB1 = MAP( aCol0.GetBlue(), aCol1.GetBlue(), nTmpFX );
-
-                            aColRes.SetRed( MAP( cR0, cR1, nTmpFY ) );
-                            aColRes.SetGreen( MAP( cG0, cG1, nTmpFY ) );
-                            aColRes.SetBlue( MAP( cB0, cB1, nTmpFY ) );
-                            pWAcc->SetPixel( nYDst, nXDst++, aColRes );
-                        }
-                    }
-                }
-            }
-
-            aOutBmp.ReleaseAccess( pWAcc );
-            bRet = sal_True;
-        }
-
-        aBmp.ReleaseAccess( pAcc );
-    }
-
-    if( bRet && rBmpEx.IsTransparent() )
-    {
-        bRet = sal_False;
-
-        if( rBmpEx.IsAlpha() )
-        {
-            DBG_ASSERT( rBmpEx.GetAlpha().GetSizePixel() == rBmpEx.GetSizePixel(),
-                        "GraphicManager::ImplCreateScaled(): alpha mask size inconsistent" );
-
-            AlphaMask   aAlpha( rBmpEx.GetAlpha() );
-            AlphaMask   aOutAlpha;
-
-            pAcc = aAlpha.AcquireReadAccess();
-
-            if( pAcc )
-            {
-                aOutAlpha = AlphaMask( Size( nDstW, nDstH ) );
-                pWAcc = aOutAlpha.AcquireWriteAccess();
-
-                if( pWAcc )
-                {
-                    if( pAcc->GetScanlineFormat() == BMP_FORMAT_8BIT_PAL &&
-                        pWAcc->GetScanlineFormat() == BMP_FORMAT_8BIT_PAL )
-                    {
-                        Scanline pLine0, pLine1, pLineW;
-
-                        for( nY = nStartY, nYDst = 0L; nY <= nEndY; nY++, nYDst++ )
-                        {
-                            nTmpY = pMapIY[ nY ]; nTmpFY = pMapFY[ nY ];
-                            pLine0 = pAcc->GetScanline( nTmpY );
-                            pLine1 = pAcc->GetScanline( ++nTmpY );
-                            pLineW = pWAcc->GetScanline( nYDst );
-
-                            for( nX = nStartX, nXDst = 0L; nX <= nEndX; nX++, nXDst++ )
-                            {
-                                nTmpX = pMapIX[ nX ]; nTmpFX = pMapFX[ nX ];
-
-                                const long  nAlpha0 = pLine0[ nTmpX ];
-                                const long  nAlpha2 = pLine1[ nTmpX ];
-                                const long  nAlpha1 = pLine0[ ++nTmpX ];
-                                const long  nAlpha3 = pLine1[ nTmpX ];
-                                const long  n0 = MAP( nAlpha0, nAlpha1, nTmpFX );
-                                const long  n1 = MAP( nAlpha2, nAlpha3, nTmpFX );
-
-                                *pLineW++ = MAP( n0, n1, nTmpFY );
-                            }
-                        }
-                    }
-                    else
-                    {
-                        BitmapColor aAlphaValue( 0 );
-
-                        for( nY = nStartY, nYDst = 0L; nY <= nEndY; nY++, nYDst++ )
-                        {
-                            nTmpY = pMapIY[ nY ], nTmpFY = pMapFY[ nY ];
-
-                            for( nX = nStartX, nXDst = 0L; nX <= nEndX; nX++ )
-                            {
-                                nTmpX = pMapIX[ nX ]; nTmpFX = pMapFX[ nX ];
-
-                                long        nAlpha0 = pAcc->GetPixel( nTmpY, nTmpX ).GetIndex();
-                                long        nAlpha1 = pAcc->GetPixel( nTmpY, ++nTmpX ).GetIndex();
-                                const long  n0 = MAP( nAlpha0, nAlpha1, nTmpFX );
-
-                                nAlpha1 = pAcc->GetPixel( ++nTmpY, nTmpX ).GetIndex();
-                                nAlpha0 = pAcc->GetPixel( nTmpY--, --nTmpX ).GetIndex();
-                                const long  n1 = MAP( nAlpha0, nAlpha1, nTmpFX );
-
-                                aAlphaValue.SetIndex( MAP( n0, n1, nTmpFY ) );
-                                pWAcc->SetPixel( nYDst, nXDst++, aAlphaValue );
-                            }
-                        }
-                    }
-
-                    aOutAlpha.ReleaseAccess( pWAcc );
-                    bRet = sal_True;
-                }
-
-                aAlpha.ReleaseAccess( pAcc );
-
-                if( bRet )
-                    rOutBmpEx = BitmapEx( aOutBmp, aOutAlpha );
-            }
-        }
-        else
-        {
-            DBG_ASSERT( rBmpEx.GetMask().GetSizePixel() == rBmpEx.GetSizePixel(),
-                        "GraphicManager::ImplCreateScaled(): mask size inconsistent" );
-
-            Bitmap  aMsk( rBmpEx.GetMask() );
-            Bitmap  aOutMsk;
-
-            pAcc = aMsk.AcquireReadAccess();
-
-            if( pAcc )
-            {
-                // #i40115# Use the same palette for destination
-                // bitmap. Otherwise, we'd have to color-map even the
-                // case below, when both masks are one bit deep.
-                if( pAcc->HasPalette() )
-                    aOutMsk = Bitmap( Size( nDstW, nDstH ),
-                                      1,
-                                      &pAcc->GetPalette() );
-                else
-                    aOutMsk = Bitmap( Size( nDstW, nDstH ), 1 );
-
-                pWAcc = aOutMsk.AcquireWriteAccess();
-
-                if( pWAcc )
-                {
-                    long* pMapLX = new long[ nDstW ];
-                    long* pMapLY = new long[ nDstH ];
-
-                    // create new horizontal mapping table
-                    for( nX = 0UL, nTmpX = nStartX; nX < nDstW; nTmpX++ )
-                        pMapLX[ nX++ ] = FRound( (double) pMapIX[ nTmpX ] + pMapFX[ nTmpX ] / 1048576. );
-
-                    // create new vertical mapping table
-                    for( nY = 0UL, nTmpY = nStartY; nY < nDstH; nTmpY++ )
-                        pMapLY[ nY++ ] = FRound( (double) pMapIY[ nTmpY ] + pMapFY[ nTmpY ] / 1048576. );
-
-                    // do normal scaling
-                    if( pAcc->GetScanlineFormat() == BMP_FORMAT_1BIT_MSB_PAL &&
-                        pWAcc->GetScanlineFormat() == BMP_FORMAT_1BIT_MSB_PAL )
-                    {
-                        // optimized
-                        for( nY = 0; nY < nDstH; nY++ )
-                        {
-                            Scanline pSrc = pAcc->GetScanline( pMapLY[ nY ] );
-                            Scanline pDst = pWAcc->GetScanline( nY );
-
-                            for( nX = 0L; nX < nDstW; nX++ )
-                            {
-                                const long nSrcX = pMapLX[ nX ];
-
-                                if( pSrc[ nSrcX >> 3 ] & ( 1 << ( 7 - ( nSrcX & 7 ) ) ) )
-                                    pDst[ nX >> 3 ] |= 1 << ( 7 - ( nX & 7 ) );
-                                else
-                                    pDst[ nX >> 3 ] &= ~( 1 << ( 7 - ( nX & 7 ) ) );
-                            }
-                        }
-                    }
-                    else
-                    {
-                        const BitmapColor aB( pAcc->GetBestMatchingColor( Color( COL_BLACK ) ) );
-                        const BitmapColor aWB( pWAcc->GetBestMatchingColor( Color( COL_BLACK ) ) );
-                        const BitmapColor aWW( pWAcc->GetBestMatchingColor( Color( COL_WHITE ) ) );
-
-                        if( pAcc->HasPalette() )
-                        {
-                            for( nY = 0L; nY < nDstH; nY++ )
-                            {
-                                for( nX = 0L; nX < nDstW; nX++ )
-                                {
-                                    if( pAcc->GetPaletteColor( (sal_uInt8) pAcc->GetPixel( pMapLY[ nY ], pMapLX[ nX ] ) ) == aB )
-                                        pWAcc->SetPixel( nY, nX, aWB );
-                                    else
-                                        pWAcc->SetPixel( nY, nX, aWW );
-                                }
-                            }
-                        }
-                        else
-                        {
-                            for( nY = 0L; nY < nDstH; nY++ )
-                            {
-                                for( nX = 0L; nX < nDstW; nX++ )
-                                {
-                                    if( pAcc->GetPixel( pMapLY[ nY ], pMapLX[ nX ] ) == aB )
-                                        pWAcc->SetPixel( nY, nX, aWB );
-                                    else
-                                        pWAcc->SetPixel( nY, nX, aWW );
-                                }
-                            }
-                        }
-                    }
-
-                    delete[] pMapLX;
-                    delete[] pMapLY;
-                    aOutMsk.ReleaseAccess( pWAcc );
-                    bRet = sal_True;
-                }
-
-                aMsk.ReleaseAccess( pAcc );
-
-                if( bRet )
-                    rOutBmpEx = BitmapEx( aOutBmp, aOutMsk );
-            }
-        }
-
-        if( !bRet )
-            rOutBmpEx = aOutBmp;
-    }
-    else
-        rOutBmpEx = aOutBmp;
-
-    return bRet;
-}
-
-// -----------------------------------------------------------------------------
-
-sal_Bool GraphicManager::ImplCreateRotatedScaled( const BitmapEx& rBmpEx,
-                                              sal_uInt16 nRot10, const Size& /*rOutSzPix*/, const Size& rUnrotatedSzPix,
-                                              long* pMapIX, long* pMapFX, long* pMapIY, long* pMapFY,
-                                              long nStartX, long nEndX, long nStartY, long nEndY,
-                                              BitmapEx& rOutBmpEx )
-{
-    Point               aPt;
-    Bitmap              aBmp( rBmpEx.GetBitmap() );
-    Bitmap              aOutBmp;
-    BitmapReadAccess*   pAcc = aBmp.AcquireReadAccess();
-    BitmapWriteAccess*  pWAcc;
-    Polygon             aPoly( Rectangle( aPt, rUnrotatedSzPix ) ); aPoly.Rotate( Point(), nRot10 );
-    Rectangle           aNewBound( aPoly.GetBoundRect() );
-    const double        fCosAngle = cos( nRot10 * F_PI1800 ), fSinAngle = sin( nRot10 * F_PI1800 );
-    double              fTmp;
-    const long          nDstW = nEndX - nStartX + 1L;
-    const long          nDstH = nEndY - nStartY + 1L;
-    const long          nUnRotW = rUnrotatedSzPix.Width();
-    const long          nUnRotH = rUnrotatedSzPix.Height();
-    long*               pCosX = new long[ nDstW ];
-    long*               pSinX = new long[ nDstW ];
-    long*               pCosY = new long[ nDstH ];
-    long*               pSinY = new long[ nDstH ];
-    long                nX, nY, nTmpX, nTmpY, nTmpFX, nTmpFY, nUnRotX, nUnRotY, nSinY, nCosY;
-    sal_uInt8               cR0, cG0, cB0, cR1, cG1, cB1;
-    sal_Bool                bRet = sal_False;
-
-    // create horizontal mapping table
-    for( nX = 0L, nTmpX = aNewBound.Left() + nStartX; nX < nDstW; nX++ )
-    {
-        fTmp = nTmpX++ << 8;
-        pCosX[ nX ] = FRound( fCosAngle * fTmp );
-        pSinX[ nX ] = FRound( fSinAngle * fTmp );
-    }
-
-    // create vertical mapping table
-    for( nY = 0L, nTmpY = aNewBound.Top() + nStartY; nY < nDstH; nY++ )
-    {
-        fTmp = nTmpY++ << 8;
-        pCosY[ nY ] = FRound( fCosAngle * fTmp );
-        pSinY[ nY ] = FRound( fSinAngle * fTmp );
-    }
-
-    if( pAcc )
-    {
-        aOutBmp = Bitmap( Size( nDstW, nDstH ), 24 );
-        pWAcc = aOutBmp.AcquireWriteAccess();
-
-        if( pWAcc )
-        {
-            BitmapColor aColRes;
-
-            if( pAcc->HasPalette() )
-            {
-                for( nY = 0; nY < nDstH; nY++ )
-                {
-                    nSinY = pSinY[ nY ];
-                    nCosY = pCosY[ nY ];
-
-                    for( nX = 0; nX < nDstW; nX++ )
-                    {
-                        nUnRotX = ( pCosX[ nX ] - nSinY ) >> 8;
-                        nUnRotY = ( pSinX[ nX ] + nCosY ) >> 8;
-
-                        if( ( nUnRotX >= 0L ) && ( nUnRotX < nUnRotW ) &&
-                            ( nUnRotY >= 0L ) && ( nUnRotY < nUnRotH ) )
-                        {
-                            nTmpX = pMapIX[ nUnRotX ]; nTmpFX = pMapFX[ nUnRotX ];
-                            nTmpY = pMapIY[ nUnRotY ], nTmpFY = pMapFY[ nUnRotY ];
-
-                            const BitmapColor& rCol0 = pAcc->GetPaletteColor( pAcc->GetPixel( nTmpY, nTmpX ) );
-                            const BitmapColor& rCol1 = pAcc->GetPaletteColor( pAcc->GetPixel( nTmpY, ++nTmpX ) );
-                            cR0 = MAP( rCol0.GetRed(), rCol1.GetRed(), nTmpFX );
-                            cG0 = MAP( rCol0.GetGreen(), rCol1.GetGreen(), nTmpFX );
-                            cB0 = MAP( rCol0.GetBlue(), rCol1.GetBlue(), nTmpFX );
-
-                            const BitmapColor& rCol3 = pAcc->GetPaletteColor( pAcc->GetPixel( ++nTmpY, nTmpX ) );
-                            const BitmapColor& rCol2 = pAcc->GetPaletteColor( pAcc->GetPixel( nTmpY, --nTmpX ) );
-                            cR1 = MAP( rCol2.GetRed(), rCol3.GetRed(), nTmpFX );
-                            cG1 = MAP( rCol2.GetGreen(), rCol3.GetGreen(), nTmpFX );
-                            cB1 = MAP( rCol2.GetBlue(), rCol3.GetBlue(), nTmpFX );
-
-                            aColRes.SetRed( MAP( cR0, cR1, nTmpFY ) );
-                            aColRes.SetGreen( MAP( cG0, cG1, nTmpFY ) );
-                            aColRes.SetBlue( MAP( cB0, cB1, nTmpFY ) );
-                            pWAcc->SetPixel( nY, nX, aColRes );
-                        }
-                    }
-                }
-            }
-            else
-            {
-                BitmapColor aCol0, aCol1;
-
-                for( nY = 0; nY < nDstH; nY++ )
-                {
-                    nSinY = pSinY[ nY ];
-                    nCosY = pCosY[ nY ];
-
-                    for( nX = 0; nX < nDstW; nX++ )
-                    {
-                        nUnRotX = ( pCosX[ nX ] - nSinY ) >> 8;
-                        nUnRotY = ( pSinX[ nX ] + nCosY ) >> 8;
-
-                        if( ( nUnRotX >= 0L ) && ( nUnRotX < nUnRotW ) &&
-                            ( nUnRotY >= 0L ) && ( nUnRotY < nUnRotH ) )
-                        {
-                            nTmpX = pMapIX[ nUnRotX ]; nTmpFX = pMapFX[ nUnRotX ];
-                            nTmpY = pMapIY[ nUnRotY ], nTmpFY = pMapFY[ nUnRotY ];
-
-                            aCol0 = pAcc->GetPixel( nTmpY, nTmpX );
-                            aCol1 = pAcc->GetPixel( nTmpY, ++nTmpX );
-                            cR0 = MAP( aCol0.GetRed(), aCol1.GetRed(), nTmpFX );
-                            cG0 = MAP( aCol0.GetGreen(), aCol1.GetGreen(), nTmpFX );
-                            cB0 = MAP( aCol0.GetBlue(), aCol1.GetBlue(), nTmpFX );
-
-                            aCol1 = pAcc->GetPixel( ++nTmpY, nTmpX );
-                            aCol0 = pAcc->GetPixel( nTmpY, --nTmpX );
-                            cR1 = MAP( aCol0.GetRed(), aCol1.GetRed(), nTmpFX );
-                            cG1 = MAP( aCol0.GetGreen(), aCol1.GetGreen(), nTmpFX );
-                            cB1 = MAP( aCol0.GetBlue(), aCol1.GetBlue(), nTmpFX );
-
-                            aColRes.SetRed( MAP( cR0, cR1, nTmpFY ) );
-                            aColRes.SetGreen( MAP( cG0, cG1, nTmpFY ) );
-                            aColRes.SetBlue( MAP( cB0, cB1, nTmpFY ) );
-                            pWAcc->SetPixel( nY, nX, aColRes );
-                        }
-                    }
-                }
-            }
-
-            aOutBmp.ReleaseAccess( pWAcc );
-            bRet = sal_True;
-        }
-
-        aBmp.ReleaseAccess( pAcc );
-    }
-
-    // mask processing
-    if( bRet && ( rBmpEx.IsTransparent() || ( nRot10 != 900 && nRot10 != 1800 && nRot10 != 2700 ) ) )
-    {
-        bRet = sal_False;
-
-        if( rBmpEx.IsAlpha() )
-        {
-            AlphaMask   aAlpha( rBmpEx.GetAlpha() );
-            AlphaMask   aOutAlpha;
-
-            pAcc = aAlpha.AcquireReadAccess();
-
-            if( pAcc )
-            {
-                aOutAlpha = AlphaMask( Size( nDstW, nDstH ) );
-                pWAcc = aOutAlpha.AcquireWriteAccess();
-
-                if( pWAcc )
-                {
-                    if( pAcc->GetScanlineFormat() == BMP_FORMAT_8BIT_PAL &&
-                        pWAcc->GetScanlineFormat() == BMP_FORMAT_8BIT_PAL )
-                    {
-                        Scanline pLine0, pLine1, pLineW;
-
-                        for( nY = 0; nY < nDstH; nY++ )
-                        {
-                            nSinY = pSinY[ nY ], nCosY = pCosY[ nY ];
-                            pLineW = pWAcc->GetScanline( nY );
-
-                            for( nX = 0; nX < nDstW; nX++ )
-                            {
-                                nUnRotX = ( pCosX[ nX ] - nSinY ) >> 8;
-                                nUnRotY = ( pSinX[ nX ] + nCosY ) >> 8;
-
-                                if( ( nUnRotX >= 0L ) && ( nUnRotX < nUnRotW ) &&
-                                    ( nUnRotY >= 0L ) && ( nUnRotY < nUnRotH ) )
-                                {
-                                    nTmpX = pMapIX[ nUnRotX ], nTmpFX = pMapFX[ nUnRotX ];
-                                    nTmpY = pMapIY[ nUnRotY ], nTmpFY = pMapFY[ nUnRotY ];
-
-                                    pLine0 = pAcc->GetScanline( nTmpY++ );
-                                    pLine1 = pAcc->GetScanline( nTmpY );
-
-                                    const long  nAlpha0 = pLine0[ nTmpX ];
-                                    const long  nAlpha2 = pLine1[ nTmpX++ ];
-                                    const long  nAlpha1 = pLine0[ nTmpX ];
-                                    const long  nAlpha3 = pLine1[ nTmpX ];
-                                    const long  n0 = MAP( nAlpha0, nAlpha1, nTmpFX );
-                                    const long  n1 = MAP( nAlpha2, nAlpha3, nTmpFX );
-
-                                    *pLineW++ = MAP( n0, n1, nTmpFY );
-                                }
-                                else
-                                    *pLineW++ = 255;
-                            }
-                        }
-                    }
-                    else
-                    {
-                        const BitmapColor   aTrans( pWAcc->GetBestMatchingColor( Color( COL_WHITE ) ) );
-                        BitmapColor         aAlphaVal( 0 );
-
-                        for( nY = 0; nY < nDstH; nY++ )
-                        {
-                            nSinY = pSinY[ nY ], nCosY = pCosY[ nY ];
-
-                            for( nX = 0; nX < nDstW; nX++ )
-                            {
-                                nUnRotX = ( pCosX[ nX ] - nSinY ) >> 8;
-                                nUnRotY = ( pSinX[ nX ] + nCosY ) >> 8;
-
-                                if( ( nUnRotX >= 0L ) && ( nUnRotX < nUnRotW ) &&
-                                    ( nUnRotY >= 0L ) && ( nUnRotY < nUnRotH ) )
-                                {
-                                    nTmpX = pMapIX[ nUnRotX ]; nTmpFX = pMapFX[ nUnRotX ];
-                                    nTmpY = pMapIY[ nUnRotY ], nTmpFY = pMapFY[ nUnRotY ];
-
-                                    const long  nAlpha0 = pAcc->GetPixel( nTmpY, nTmpX ).GetIndex();
-                                    const long  nAlpha1 = pAcc->GetPixel( nTmpY, ++nTmpX ).GetIndex();
-                                    const long  nAlpha3 = pAcc->GetPixel( ++nTmpY, nTmpX ).GetIndex();
-                                    const long  nAlpha2 = pAcc->GetPixel( nTmpY, --nTmpX ).GetIndex();
-                                    const long  n0 = MAP( nAlpha0, nAlpha1, nTmpFX );
-                                    const long  n1 = MAP( nAlpha2, nAlpha3, nTmpFX );
-
-                                    aAlphaVal.SetIndex( MAP( n0, n1, nTmpFY ) );
-                                    pWAcc->SetPixel( nY, nX, aAlphaVal );
-                                }
-                                else
-                                    pWAcc->SetPixel( nY, nX, aTrans );
-                            }
-                        }
-                    }
-
-                    aOutAlpha.ReleaseAccess( pWAcc );
-                    bRet = sal_True;
-                }
-
-                aAlpha.ReleaseAccess( pAcc );
-            }
-
-            if( bRet )
-                rOutBmpEx = BitmapEx( aOutBmp, aOutAlpha );
-        }
-        else
-        {
-            Bitmap aOutMsk( Size( nDstW, nDstH ), 1 );
-            pWAcc = aOutMsk.AcquireWriteAccess();
-
-            if( pWAcc )
-            {
-                Bitmap              aMsk( rBmpEx.GetMask() );
-                const BitmapColor   aB( pWAcc->GetBestMatchingColor( Color( COL_BLACK ) ) );
-                const BitmapColor   aW( pWAcc->GetBestMatchingColor( Color( COL_WHITE ) ) );
-                BitmapReadAccess*   pMAcc = NULL;
-
-                if( !aMsk || ( ( pMAcc = aMsk.AcquireReadAccess() ) != NULL ) )
-                {
-                    long*       pMapLX = new long[ nUnRotW ];
-                    long*       pMapLY = new long[ nUnRotH ];
-                    BitmapColor aTestB;
-
-                    if( pMAcc )
-                        aTestB = pMAcc->GetBestMatchingColor( Color( COL_BLACK ) );
-
-                    // create new horizontal mapping table
-                    for( nX = 0UL; nX < nUnRotW; nX++ )
-                        pMapLX[ nX ] = FRound( (double) pMapIX[ nX ] + pMapFX[ nX ] / 1048576. );
-
-                    // create new vertical mapping table
-                    for( nY = 0UL; nY < nUnRotH; nY++ )
-                        pMapLY[ nY ] = FRound( (double) pMapIY[ nY ] + pMapFY[ nY ] / 1048576. );
-
-                    // do mask rotation
-                    for( nY = 0; nY < nDstH; nY++ )
-                    {
-                        nSinY = pSinY[ nY ];
-                        nCosY = pCosY[ nY ];
-
-                        for( nX = 0; nX < nDstW; nX++ )
-                        {
-                            nUnRotX = ( pCosX[ nX ] - nSinY ) >> 8;
-                            nUnRotY = ( pSinX[ nX ] + nCosY ) >> 8;
-
-                            if( ( nUnRotX >= 0L ) && ( nUnRotX < nUnRotW ) &&
-                                ( nUnRotY >= 0L ) && ( nUnRotY < nUnRotH ) )
-                            {
-                                if( pMAcc )
-                                {
-                                    if( pMAcc->GetPixel( pMapLY[ nUnRotY ], pMapLX[ nUnRotX ] ) == aTestB )
-                                        pWAcc->SetPixel( nY, nX, aB );
-                                    else
-                                        pWAcc->SetPixel( nY, nX, aW );
-                                }
-                                else
-                                    pWAcc->SetPixel( nY, nX, aB );
-                            }
-                            else
-                                pWAcc->SetPixel( nY, nX, aW );
-                        }
-                    }
-
-                    delete[] pMapLX;
-                    delete[] pMapLY;
-
-                    if( pMAcc )
-                        aMsk.ReleaseAccess( pMAcc );
-
-                    bRet = sal_True;
-                }
-
-                aOutMsk.ReleaseAccess( pWAcc );
-            }
-
-            if( bRet )
-                rOutBmpEx = BitmapEx( aOutBmp, aOutMsk );
-        }
-
-        if( !bRet )
-            rOutBmpEx = aOutBmp;
-    }
-    else
-        rOutBmpEx = aOutBmp;
-
-    delete[] pSinX;
-    delete[] pCosX;
-    delete[] pSinY;
-    delete[] pCosY;
-
-    return bRet;
-}
-
-// -----------------------------------------------------------------------------
-
 void GraphicManager::ImplAdjust( BitmapEx& rBmpEx, const GraphicAttr& rAttr, sal_uLong nAdjustmentFlags )
 {
     GraphicAttr aAttr( rAttr );
commit 764525b39c78bfad1f6fc44a8517a565547f67cf
Author: Tomaž Vajngerl <quikee at gmail.com>
Date:   Mon Jun 25 21:07:06 2012 +0200

    use only Bitmap scaling and fixes to scaling
    
    "grfmgr" uses its own scaling functions instead of the scaling
    functions available on Bitmap object. The step to use the Bitmap::Scale
    for most scenarios was already made, now the "grfmgr" functions are
    not used anymore.
    
    In addition this commit fixes croping the bitmap with large zoom
    levels.
    
    Change-Id: Ib27029d2cdf4684146befc131e3c72656dfa407c

diff --git a/svtools/source/graphic/grfmgr2.cxx b/svtools/source/graphic/grfmgr2.cxx
index 33192b5..fa01654 100644
--- a/svtools/source/graphic/grfmgr2.cxx
+++ b/svtools/source/graphic/grfmgr2.cxx
@@ -265,228 +265,159 @@ sal_Bool GraphicManager::ImplDraw( OutputDevice* pOut, const Point& rPt,
     return bRet;
 }
 
-// -----------------------------------------------------------------------------
-
-sal_Bool GraphicManager::ImplCreateOutput( OutputDevice* pOut,
-                                       const Point& rPt, const Size& rSz,
-                                       const BitmapEx& rBmpEx, const GraphicAttr& rAttr,
+sal_Bool GraphicManager::ImplCreateOutput( OutputDevice* pOutputDevice,
+                                       const Point& rPoint, const Size& rSize,
+                                       const BitmapEx& rBitmapEx, const GraphicAttr& rAttr,
                                        const sal_uLong nFlags, BitmapEx* pBmpEx )
 {
-    sal_uInt16  nRot10 = rAttr.GetRotation() % 3600;
-    Point   aOutPtPix;
-    Size    aOutSzPix;
-    Size    aUnrotatedSzPix( pOut->LogicToPixel( rSz ) );
-    sal_Bool    bRet = sal_False;
+    bool        bRet = false;
+    Point       aOutPointInPixels;
+    Size        aOutSizeInPixels;
+    int         nRotation = rAttr.GetRotation() % 3600;
+    Size        aUnrotatedSizeInPixels( pOutputDevice->LogicToPixel( rSize ) );
 
-    if( nRot10 )
-    {
-        Polygon aPoly( Rectangle( rPt, rSz ) );
+    BitmapEx    aBitmapEx( rBitmapEx );
 
-        aPoly.Rotate( rPt, nRot10 );
-        const Rectangle aRotBoundRect( aPoly.GetBoundRect() );
-        aOutPtPix = pOut->LogicToPixel( aRotBoundRect.TopLeft() );
-        aOutSzPix = pOut->LogicToPixel( aRotBoundRect.GetSize() );
+    if( !aUnrotatedSizeInPixels.Width() || !aUnrotatedSizeInPixels.Height() )
+        return false;
+
+    if( nRotation )
+    {
+        Polygon aRotationPolygon( Rectangle( rPoint, rSize ) );
+        aRotationPolygon.Rotate( rPoint, nRotation );
+        const Rectangle aRotationBoundRectangle( aRotationPolygon.GetBoundRect() );
+        aOutPointInPixels = pOutputDevice->LogicToPixel( aRotationBoundRectangle.TopLeft() );
+        aOutSizeInPixels = pOutputDevice->LogicToPixel( aRotationBoundRectangle.GetSize() );
+
+        // rotate the image before further processing
+        aBitmapEx.Rotate( nRotation, COL_TRANSPARENT );
     }
     else
     {
-        aOutPtPix = pOut->LogicToPixel( rPt );
-        aOutSzPix = aUnrotatedSzPix;
+        aOutPointInPixels = pOutputDevice->LogicToPixel( rPoint );
+        aOutSizeInPixels = aUnrotatedSizeInPixels;
     }
 
-    if( aUnrotatedSzPix.Width() && aUnrotatedSzPix.Height() )
+    Point           aOutPoint;
+    Size            aOutSize;
+    const Size&     rBitmapSizePixels = rBitmapEx.GetSizePixel();
+    long            nStartX, nStartY, nEndX, nEndY;
+    bool            isHorizontalMirrored = ( rAttr.GetMirrorFlags() & BMP_MIRROR_HORZ ) != 0;
+    bool            isVerticalMirrored   = ( rAttr.GetMirrorFlags() & BMP_MIRROR_VERT ) != 0;
+
+    Rectangle   aBmpRect( aOutPointInPixels, aOutSizeInPixels );
+
+    // calculate output sizes
+    if( !pBmpEx )
     {
-        BitmapEx        aBmpEx( rBmpEx );
-        BitmapEx        aOutBmpEx;
-        Point           aOutPt;
-        Size            aOutSz;
-        const Size      rBmpSzPix = rBmpEx.GetSizePixel();
-        const long      nW = rBmpSzPix.Width();
-        const long      nH = rBmpSzPix.Height();
-        const long      nNewW = aUnrotatedSzPix.Width();
-        const long      nNewH = aUnrotatedSzPix.Height();
-        double          fTmp;
-        long*           pMapIX = new long[ nNewW ];
-        long*           pMapFX = new long[ nNewW ];
-        long*           pMapIY = new long[ nNewH ];
-        long*           pMapFY = new long[ nNewH ];
-        long            nStartX = -1, nStartY = -1, nEndX = -1, nEndY = -1;
-        long            nX, nY, nTmp, nTmpX, nTmpY;
-        sal_Bool            bHMirr = ( rAttr.GetMirrorFlags() & BMP_MIRROR_HORZ ) != 0;
-        sal_Bool            bVMirr = ( rAttr.GetMirrorFlags() & BMP_MIRROR_VERT ) != 0;
+        Point       aPoint;
+        Rectangle   aOutRect( aPoint, pOutputDevice->GetOutputSizePixel() );
 
-        if( !( nFlags & GRFMGR_DRAW_SMOOTHSCALE ))
+        if( pOutputDevice->GetOutDevType() == OUTDEV_WINDOW )
         {
-            // #98290# Use a different mapping for non-interpolating mode, to avoid missing rows/columns
-            const double    fRevScaleX = ( nNewW > 1L ) ? ( (double) nW / nNewW ) : 0.0;
-            const double    fRevScaleY = ( nNewH > 1L ) ? ( (double) nH / nNewH ) : 0.0;
-
-            // create horizontal mapping table
-            for( nX = 0L, nTmpX = nW - 1L, nTmp = nW - 2L; nX < nNewW; nX++ )
+            const Region aPaintRgn( ( (Window*) pOutputDevice )->GetPaintRegion() );
+            if( !aPaintRgn.IsNull() )
             {
-                fTmp = nX * fRevScaleX;
-
-                if( bHMirr )
-                    fTmp = nTmpX - fTmp;
-
-                // #98290# Do not use round to zero, otherwise last column will be missing
-                pMapIX[ nX ] = MinMax( (long) fTmp, 0, nTmp );
-                pMapFX[ nX ] = fTmp >= nTmp+1 ? 1048576 : 0;
-            }
-
-            // create vertical mapping table
-            for( nY = 0L, nTmpY = nH - 1L, nTmp = nH - 2L; nY < nNewH; nY++ )
-            {
-                fTmp = nY * fRevScaleY;
-
-                if( bVMirr )
-                    fTmp = nTmpY - fTmp;
-
-                // #98290# Do not use round to zero, otherwise last row will be missing
-                pMapIY[ nY ] = MinMax( (long) fTmp, 0, nTmp );
-                pMapFY[ nY ] = fTmp >= nTmp+1 ? 1048576 : 0;
+                aOutRect.Intersection( pOutputDevice->LogicToPixel( aPaintRgn.GetBoundRect() ) );
             }
         }
+        aOutRect.Intersection( aBmpRect );
 
-        // calculate output sizes
-        if( !pBmpEx )
+        if( !aOutRect.IsEmpty() )
         {
-            Point       aPt;
-            Rectangle   aOutRect( aPt, pOut->GetOutputSizePixel() );
-            Rectangle   aBmpRect( aOutPtPix, aOutSzPix );
+            aOutPoint = pOutputDevice->PixelToLogic( aOutRect.TopLeft() );
+            aOutSize = pOutputDevice->PixelToLogic( aOutRect.GetSize() );
+            nStartX = aOutRect.Left() - aBmpRect.Left();
+            nStartY = aOutRect.Top() - aBmpRect.Top();
+            nEndX = aOutRect.Right() - aBmpRect.Left();
+            nEndY = aOutRect.Bottom() - aBmpRect.Top();
+        }
+        else
+            nStartX = -1L; // invalid
+    }
+    else
+    {
+        aOutPoint = pOutputDevice->PixelToLogic( aOutPointInPixels );
+        aOutSize = pOutputDevice->PixelToLogic( aOutSizeInPixels );
+        nStartX = nStartY = 0;
+        nEndX = aOutSizeInPixels.Width() - 1L;
+        nEndY = aOutSizeInPixels.Height() - 1L;
+    }
 
-            if( pOut->GetOutDevType() == OUTDEV_WINDOW )
-            {
-                const Region aPaintRgn( ( (Window*) pOut )->GetPaintRegion() );
-                if( !aPaintRgn.IsNull() )
-                    aOutRect.Intersection( pOut->LogicToPixel( aPaintRgn.GetBoundRect() ) );
-            }
 
-            aOutRect.Intersection( aBmpRect );
+    if( nStartX < 0L )
+        return false;
 
-            if( !aOutRect.IsEmpty() )
-            {
-                aOutPt = pOut->PixelToLogic( aOutRect.TopLeft() );
-                aOutSz = pOut->PixelToLogic( aOutRect.GetSize() );
-                nStartX = aOutRect.Left() - aBmpRect.Left();
-                nStartY = aOutRect.Top() - aBmpRect.Top();
-                nEndX = aOutRect.Right() - aBmpRect.Left();
-                nEndY = aOutRect.Bottom() - aBmpRect.Top();
-            }
-            else
-                nStartX = -1L; // invalid
-        }
-        else
-        {
-            aOutPt = pOut->PixelToLogic( aOutPtPix );
-            aOutSz = pOut->PixelToLogic( aOutSzPix );
-            nStartX = nStartY = 0;
-            nEndX = aOutSzPix.Width() - 1L;
-            nEndY = aOutSzPix.Height() - 1L;
-        }
+    // do transformation
 
-        // do transformation
-        if( nStartX >= 0L )
-        {
-            const sal_Bool bSimple = ( 1 == nW || 1 == nH );
+    // #105229# Don't scale if output size equals bitmap size
+    // #107226# Copy through only if we're not mirroring
+    if( !isHorizontalMirrored &&
+        !isVerticalMirrored &&
+        aOutSizeInPixels == rBitmapSizePixels &&
+        !nRotation)
+    {
+        // #107226# Use original dimensions when just copying through
+        aOutPoint = pOutputDevice->PixelToLogic( aOutPointInPixels );
+        aOutSize = pOutputDevice->PixelToLogic( aOutSizeInPixels );
+        bRet = true;
+    }
+    else
+    {
+        // calculate scaling factors
+        double fScaleX = aBmpRect.GetWidth()  / (double) aBitmapEx.GetSizePixel().Width();
+        double fScaleY = aBmpRect.GetHeight() / (double) aBitmapEx.GetSizePixel().Height();
 
-            if( nRot10 )
-            {
-                if( bSimple )
-                {
-                    bRet = ( aOutBmpEx = aBmpEx ).Scale( aUnrotatedSzPix );
+        // calculate crop regions on original non-scaled bitmap
+        long nOriginalStartX = nStartX / fScaleX;
+        long nOriginalEndX = nEndX / fScaleX;
+        long nOriginalStartY = nStartY / fScaleY;
+        long nOriginalEndY = nEndY / fScaleY;
 
-                    if( bRet )
-                        bRet = aOutBmpEx.Rotate( nRot10, COL_TRANSPARENT );
-                }
-                else if( nFlags & GRFMGR_DRAW_SMOOTHSCALE )
-                {
-                    // Scale using Bitmap::Scale() rather than this algorithm, as that one provides
-                    // better quality, while being somewhat slower (the result should be cached though).
-                    aOutBmpEx = aBmpEx;
-                    bRet = true;
-                    if( bHMirr || bVMirr )
-                        bRet = aOutBmpEx.Mirror(( bHMirr ? BMP_MIRROR_HORZ : BMP_MIRROR_NONE )
-                                    | ( bVMirr ? BMP_MIRROR_VERT : BMP_MIRROR_NONE ));
-                    if( bRet )
-                        bRet = aOutBmpEx.Rotate( nRot10, COL_TRANSPARENT );
-                    if( bRet ) // scale as last (rotating would destroy the smooth scaling)
-                        bRet = aOutBmpEx.Scale( Size( nEndX - nStartX + 1, nEndY - nStartY + 1 ));
-                }
-                else
-                {
-                    bRet = ImplCreateRotatedScaled( aBmpEx,
-                                                    nRot10, aOutSzPix, aUnrotatedSzPix,
-                                                    pMapIX, pMapFX, pMapIY, pMapFY, nStartX, nEndX, nStartY, nEndY,
-                                                    aOutBmpEx );
-                }
-            }
-            else
-            {
-                // #105229# Don't scale if output size equals bitmap size
-                // #107226# Copy through only if we're not mirroring
-                if( !bHMirr && !bVMirr && aOutSzPix == rBmpSzPix )
-                {
-                    // #107226# Use original dimensions when just copying through
-                    aOutPt = pOut->PixelToLogic( aOutPtPix );
-                    aOutSz = pOut->PixelToLogic( aOutSzPix );
-                    aOutBmpEx = aBmpEx;
-                    bRet = sal_True;
-                }
-                else
-                {
-                    if( bSimple )
-                        bRet = ( aOutBmpEx = aBmpEx ).Scale( Size( nEndX - nStartX + 1, nEndY - nStartY + 1 ) );
-                    else if( nFlags & GRFMGR_DRAW_SMOOTHSCALE )
-                    {
-                    // Scale using Bitmap::Scale() rather than this algorithm, as that one provides
-                    // better quality, while being somewhat slower (the result should be cached though).
-                        aOutBmpEx = aBmpEx;
-                        bRet = aOutBmpEx.Scale( Size( nEndX - nStartX + 1, nEndY - nStartY + 1 ));
-                        if( bRet && ( bHMirr || bVMirr ))
-                            bRet = aOutBmpEx.Mirror(( bHMirr ? BMP_MIRROR_HORZ : BMP_MIRROR_NONE )
-                                    | ( bVMirr ? BMP_MIRROR_VERT : BMP_MIRROR_NONE ));
-                    }
-                    else
-                    {
-                        bRet = ImplCreateScaled( aBmpEx,
-                                                 pMapIX, pMapFX, pMapIY, pMapFY,
-                                                 nStartX, nEndX, nStartY, nEndY,
-                                                 aOutBmpEx );
-                    }
-                }
-            }
+        Size aScaleSize( nEndX - nStartX + 1, nEndY - nStartY + 1 );
 
-            if( bRet )
-            {
-                // attribute adjustment if neccessary
-                if( rAttr.IsSpecialDrawMode() || rAttr.IsAdjusted() || rAttr.IsTransparent() )
-                    ImplAdjust( aOutBmpEx, rAttr, ADJUSTMENT_DRAWMODE | ADJUSTMENT_COLORS | ADJUSTMENT_TRANSPARENCY );
+        // crop the bitmap, so we deal with a smaller bitmap
+        // todo: join crop and scale step into one step on Bitmap to decrease processing
+        bRet = aBitmapEx.Crop( Rectangle( nOriginalStartX, nOriginalStartY, nOriginalEndX, nOriginalEndY ) );
 
-                // OutDev adjustment if neccessary
-                if( pOut->GetOutDevType() != OUTDEV_PRINTER && pOut->GetBitCount() <= 8 && aOutBmpEx.GetBitCount() >= 8 )
-                    aOutBmpEx.Dither( BMP_DITHER_MATRIX );
-            }
-        }
+        // mirror the image - this should not impact the picture dimenstions
+        if( isHorizontalMirrored || isVerticalMirrored )
+            bRet = aBitmapEx.Mirror( rAttr.GetMirrorFlags() );
+
+        // depending on the flags, scale the image to the desired proportions
+        // use FAST scale if no smooth scale is desired
+        if( !( nFlags & GRFMGR_DRAW_SMOOTHSCALE ))
+            bRet = aBitmapEx.Scale( aScaleSize, BMP_SCALE_FAST );
+        else
+            bRet = aBitmapEx.Scale( aScaleSize );
+    }
 
-        // delete lookup tables
-        delete[] pMapIX;
-        delete[] pMapFX;
-        delete[] pMapIY;
-        delete[] pMapFY;
+    if( bRet )
+    {
+        // attribute adjustment if neccessary
+        if( rAttr.IsSpecialDrawMode() || rAttr.IsAdjusted() || rAttr.IsTransparent() )
+            ImplAdjust( aBitmapEx, rAttr, ADJUSTMENT_DRAWMODE | ADJUSTMENT_COLORS | ADJUSTMENT_TRANSPARENCY );
+
+        // OutDev adjustment if neccessary
+        if( pOutputDevice->GetOutDevType() != OUTDEV_PRINTER &&
+                pOutputDevice->GetBitCount() <= 8 &&
+                aBitmapEx.GetBitCount() >= 8 )
+        {
+            aBitmapEx.Dither( BMP_DITHER_MATRIX );
+        }
+    }
 
-        // create output
-        if( bRet )
+    // create output
+    if( bRet )
+    {
+        if( pBmpEx )
         {
-            if( !pBmpEx )
-                pOut->DrawBitmapEx( aOutPt, aOutSz, aOutBmpEx );
-            else
-            {
-                if( !rAttr.IsTransparent() && !aOutBmpEx.IsAlpha() )
-                    aOutBmpEx = BitmapEx( aOutBmpEx.GetBitmap().CreateDisplayBitmap( pOut ), aOutBmpEx.GetMask() );
+            if( !rAttr.IsTransparent() && !aBitmapEx.IsAlpha() )
+                aBitmapEx = BitmapEx( aBitmapEx.GetBitmap().CreateDisplayBitmap( pOutputDevice ), aBitmapEx.GetMask() );
 
-                pOut->DrawBitmapEx( aOutPt, aOutSz, *pBmpEx = aOutBmpEx );
-            }
+            *pBmpEx = aBitmapEx;
         }
+        pOutputDevice->DrawBitmapEx( aOutPoint, aOutSize, aBitmapEx);
     }
 
     return bRet;
commit 16e73f6d728d7fe40c4a87ee7e29caf649090407
Author: Tomaž Vajngerl <quikee at gmail.com>
Date:   Mon Jun 25 20:10:38 2012 +0200

    Cleanup code comments and change Sal_bool to bool
    
    Change-Id: Iebc86650365041939be0df339790e01391f72e89

diff --git a/svtools/source/graphic/grfmgr2.cxx b/svtools/source/graphic/grfmgr2.cxx
index 8c20523..33192b5 100644
--- a/svtools/source/graphic/grfmgr2.cxx
+++ b/svtools/source/graphic/grfmgr2.cxx
@@ -57,8 +57,6 @@ GraphicManager::GraphicManager( sal_uLong nCacheSize, sal_uLong nMaxObjCacheSize
 {
 }
 
-// -----------------------------------------------------------------------------
-
 GraphicManager::~GraphicManager()
 {
     for( size_t i = 0, n = maObjList.size(); i < n; ++i )
@@ -67,36 +65,26 @@ GraphicManager::~GraphicManager()
     delete mpCache;
 }
 
-// -----------------------------------------------------------------------------
-
 void GraphicManager::SetMaxCacheSize( sal_uLong nNewCacheSize )
 {
     mpCache->SetMaxDisplayCacheSize( nNewCacheSize );
 }
 
-// -----------------------------------------------------------------------------
-
 void GraphicManager::SetMaxObjCacheSize( sal_uLong nNewMaxObjSize, sal_Bool bDestroyGreaterCached )
 {
     mpCache->SetMaxObjDisplayCacheSize( nNewMaxObjSize, bDestroyGreaterCached );
 }
 
-// -----------------------------------------------------------------------------
-
 void GraphicManager::SetCacheTimeout( sal_uLong nTimeoutSeconds )
 {
     mpCache->SetCacheTimeout( nTimeoutSeconds );
 }
 
-// -----------------------------------------------------------------------------
-
 void GraphicManager::ReleaseFromCache( const GraphicObject& /*rObj*/ )
 {
     // !!!
 }
 
-// -----------------------------------------------------------------------------
-
 sal_Bool GraphicManager::IsInCache( OutputDevice* pOut, const Point& rPt,
                                     const Size& rSz, const GraphicObject& rObj,
                                     const GraphicAttr& rAttr ) const
@@ -104,8 +92,6 @@ sal_Bool GraphicManager::IsInCache( OutputDevice* pOut, const Point& rPt,
     return mpCache->IsInDisplayCache( pOut, rPt, rSz, rObj, rAttr );
 }
 
-// -----------------------------------------------------------------------------
-
 sal_Bool GraphicManager::DrawObj( OutputDevice* pOut, const Point& rPt, const Size& rSz,
                               GraphicObject& rObj, const GraphicAttr& rAttr,
                               const sal_uLong nFlags, sal_Bool& rCached )
@@ -162,8 +148,6 @@ sal_Bool GraphicManager::DrawObj( OutputDevice* pOut, const Point& rPt, const Si
     return bRet;
 }
 
-// -----------------------------------------------------------------------------
-
 void GraphicManager::ImplRegisterObj( const GraphicObject& rObj, Graphic& rSubstitute,
                                       const rtl::OString* pID, const GraphicObject* pCopyObj )
 {
@@ -171,8 +155,6 @@ void GraphicManager::ImplRegisterObj( const GraphicObject& rObj, Graphic& rSubst
     mpCache->AddGraphicObject( rObj, rSubstitute, pID, pCopyObj );
 }
 
-// -----------------------------------------------------------------------------
-
 void GraphicManager::ImplUnregisterObj( const GraphicObject& rObj )
 {
     mpCache->ReleaseGraphicObject( rObj );
@@ -185,36 +167,26 @@ void GraphicManager::ImplUnregisterObj( const GraphicObject& rObj )
     }
 }
 
-// -----------------------------------------------------------------------------
-
 void GraphicManager::ImplGraphicObjectWasSwappedOut( const GraphicObject& rObj )
 {
     mpCache->GraphicObjectWasSwappedOut( rObj );
 }
 
-// -----------------------------------------------------------------------------
-
 rtl::OString GraphicManager::ImplGetUniqueID( const GraphicObject& rObj ) const
 {
     return mpCache->GetUniqueID( rObj );
 }
 
-// -----------------------------------------------------------------------------
-
 sal_Bool GraphicManager::ImplFillSwappedGraphicObject( const GraphicObject& rObj, Graphic& rSubstitute )
 {
     return( mpCache->FillSwappedGraphicObject( rObj, rSubstitute ) );
 }
 
-// -----------------------------------------------------------------------------
-
 void GraphicManager::ImplGraphicObjectWasSwappedIn( const GraphicObject& rObj )
 {
     mpCache->GraphicObjectWasSwappedIn( rObj );
 }
 
-// -----------------------------------------------------------------------------
-
 sal_Bool GraphicManager::ImplDraw( OutputDevice* pOut, const Point& rPt,
                                const Size& rSz, GraphicObject& rObj,
                                const GraphicAttr& rAttr,
@@ -520,8 +492,6 @@ sal_Bool GraphicManager::ImplCreateOutput( OutputDevice* pOut,
     return bRet;
 }
 
-// -----------------------------------------------------------------------------
-
 // This function checks whether the bitmap is usable for skipping
 // mtf rendering by using just this one bitmap (i.e. in case the metafile
 // contains just this one pixmap that covers the entire metafile area).
@@ -895,8 +865,6 @@ sal_Bool GraphicManager::ImplCreateOutput( OutputDevice* pOut,
     return sal_True;
 }
 
-// -----------------------------------------------------------------------------
-
 sal_Bool GraphicManager::ImplCreateScaled( const BitmapEx& rBmpEx,
                                        long* pMapIX, long* pMapFX, long* pMapIY, long* pMapFY,
                                        long nStartX, long nEndX, long nStartY, long nEndY,
@@ -1730,8 +1698,6 @@ void GraphicManager::ImplAdjust( BitmapEx& rBmpEx, const GraphicAttr& rAttr, sal
     }
 }
 
-// -----------------------------------------------------------------------------
-
 void GraphicManager::ImplAdjust( GDIMetaFile& rMtf, const GraphicAttr& rAttr, sal_uLong nAdjustmentFlags )
 {
     GraphicAttr aAttr( rAttr );
@@ -1783,8 +1749,6 @@ void GraphicManager::ImplAdjust( GDIMetaFile& rMtf, const GraphicAttr& rAttr, sa
     }
 }
 
-// -----------------------------------------------------------------------------
-
 void GraphicManager::ImplAdjust( Animation& rAnimation, const GraphicAttr& rAttr, sal_uLong nAdjustmentFlags )
 {
     GraphicAttr aAttr( rAttr );
@@ -1836,8 +1800,6 @@ void GraphicManager::ImplAdjust( Animation& rAnimation, const GraphicAttr& rAttr
     }
 }
 
-// -----------------------------------------------------------------------------
-
 void GraphicManager::ImplDraw( OutputDevice* pOut, const Point& rPt, const Size& rSz,
                                const GDIMetaFile& rMtf, const GraphicAttr& rAttr )
 {
@@ -1865,8 +1827,6 @@ void GraphicManager::ImplDraw( OutputDevice* pOut, const Point& rPt, const Size&
     pOut->Pop();
 }
 
-// -----------------------------------------------------------------------------
-
 struct ImplTileInfo
 {
     ImplTileInfo() : aTileTopLeft(), aNextTileTopLeft(), aTileSizePixel(), nTilesEmptyX(0), nTilesEmptyY(0) {}
@@ -1930,8 +1890,6 @@ bool GraphicObject::ImplRenderTempTile( VirtualDevice& rVDev, int nExponent,
     return bRet;
 }
 
-// -----------------------------------------------------------------------------
-
 // define for debug drawings
 //#define DBG_TEST
 
@@ -2115,8 +2073,6 @@ bool GraphicObject::ImplRenderTileRecursive( VirtualDevice& rVDev, int nExponent
     return true;
 }
 
-// -----------------------------------------------------------------------------
-
 bool GraphicObject::ImplDrawTiled( OutputDevice* pOut, const Rectangle& rArea, const Size& rSizePixel,
                                    const Size& rOffset, const GraphicAttr* pAttr, sal_uLong nFlags, int nTileCacheSize1D )
 {
@@ -2225,8 +2181,6 @@ bool GraphicObject::ImplDrawTiled( OutputDevice* pOut, const Rectangle& rArea, c
     return bRet;
 }
 
-// -----------------------------------------------------------------------------
-
 bool GraphicObject::ImplDrawTiled( OutputDevice& rOut, const Point& rPosPixel,
                                    int nNumTilesX, int nNumTilesY,
                                    const Size& rTileSizePixel, const GraphicAttr* pAttr, sal_uLong nFlags )
@@ -2237,11 +2191,11 @@ bool GraphicObject::ImplDrawTiled( OutputDevice& rOut, const Point& rPosPixel,
 
     // #107607# Use logical coordinates for metafile playing, too
     bool    bDrawInPixel( rOut.GetConnectMetaFile() == NULL && GRAPHIC_BITMAP == GetType() );
-    sal_Bool    bRet( sal_False );
+    bool    bRet = false;
 
     // #105229# Switch off mapping (converting to logic and back to
     // pixel might cause roundoff errors)
-    sal_Bool bOldMap( rOut.IsMapModeEnabled() );
+    bool bOldMap( rOut.IsMapModeEnabled() );
 
     if( bDrawInPixel )
         rOut.EnableMapMode( sal_False );
@@ -2275,8 +2229,6 @@ bool GraphicObject::ImplDrawTiled( OutputDevice& rOut, const Point& rPosPixel,
     return bRet;
 }
 
-// -----------------------------------------------------------------------------
-
 void GraphicObject::ImplTransformBitmap( BitmapEx&          rBmpEx,
                                          const GraphicAttr& rAttr,
                                          const Size&        rCropLeftTop,


More information about the Libreoffice-commits mailing list