[Libreoffice-commits] core.git: Branch 'feature/perfwork4' - 5 commits - vcl/source

Michael Meeks michael.meeks at collabora.com
Thu Oct 16 07:08:42 PDT 2014


 vcl/source/bitmap/bitmapscalesuper.cxx |  603 +++++++++++++++------------------
 1 file changed, 291 insertions(+), 312 deletions(-)

New commits:
commit 00c56138f11597bb16bbe9e80746d0b1bee34786
Author: Michael Meeks <michael.meeks at collabora.com>
Date:   Thu Oct 16 08:46:11 2014 -0300

    vcl: parallelize image scaling.
    
    Change-Id: Ia452487c0c8c66a35c4b9fba225348bdef1a27f7

diff --git a/vcl/source/bitmap/bitmapscalesuper.cxx b/vcl/source/bitmap/bitmapscalesuper.cxx
index 29819c9..4e734c4 100644
--- a/vcl/source/bitmap/bitmapscalesuper.cxx
+++ b/vcl/source/bitmap/bitmapscalesuper.cxx
@@ -20,6 +20,9 @@
 #include <vcl/bmpacc.hxx>
 #include <vcl/bitmapscalesuper.hxx>
 
+#include <algorithm>
+#include <thread>
+#include <osl/thread.hxx>
 #include <boost/scoped_array.hpp>
 
 namespace {
@@ -71,11 +74,38 @@ struct ScaleContext {
     }
 };
 
+#define SCALE_THREAD_STRIP 32
+struct ScaleRangeContext {
+    ScaleContext &mrCtx;
+    long mnStartY, mnEndY;
+    ScaleRangeContext( ScaleContext &rCtx, long nStartY )
+        : mrCtx( rCtx ), mnStartY( nStartY ),
+          mnEndY( nStartY + SCALE_THREAD_STRIP ) {}
+};
+
+typedef void (*ScaleRangeFn)(ScaleContext &rCtx, long nStartY, long nEndY);
+
+// FIXME: should really be pooled & managed intelligently etc.
+class ScaleThread : public osl::Thread
+{
+    ScaleRangeFn mpFn;
+    std::vector< ScaleRangeContext > maStrips;
+public:
+    ScaleThread( ScaleRangeFn pFn ) : mpFn( pFn ) {}
+    void push( ScaleRangeContext &aRC ) { maStrips.push_back( aRC ); }
+    virtual void SAL_CALL run() SAL_OVERRIDE
+    {
+        std::vector< ScaleRangeContext >::iterator it;
+        for (it = maStrips.begin(); it != maStrips.end(); ++it)
+            mpFn( it->mrCtx, it->mnStartY, it->mnEndY );
+    }
+};
+
 void scalePallete8bit(ScaleContext &rCtx, long nStartY, long nEndY)
 {
     const long nStartX = 0, nEndX = rCtx.mnDestW - 1L;
 
-    for( long nY = nStartY, nYDst = 0L; nY <= nEndY; nY++, nYDst++ )
+    for( long nY = nStartY; nY <= nEndY; nY++ )
     {
         long nTempY = rCtx.mpMapIY[ nY ];
         long nTempFY = rCtx.mpMapFY[ nY ];
@@ -103,7 +133,7 @@ void scalePallete8bit(ScaleContext &rCtx, long nStartY, long nEndY)
             BitmapColor aColRes( MAP( cR0, cR1, nTempFY ),
                     MAP( cG0, cG1, nTempFY ),
                     MAP( cB0, cB1, nTempFY ) );
-            rCtx.mpDest->SetPixel( nYDst, nXDst++, aColRes );
+            rCtx.mpDest->SetPixel( nY, nXDst++, aColRes );
         }
     }
 }
@@ -112,7 +142,7 @@ void scalePalleteGeneral(ScaleContext &rCtx, long nStartY, long nEndY)
 {
     const long nStartX = 0, nEndX = rCtx.mnDestW - 1L;
 
-    for( long nY = nStartY, nYDst = 0L; nY <= nEndY; nY++, nYDst++ )
+    for( long nY = nStartY; nY <= nEndY; nY++ )
     {
         long nTempY = rCtx.mpMapIY[ nY ];
         long nTempFY = rCtx.mpMapFY[ nY ];
@@ -137,7 +167,7 @@ void scalePalleteGeneral(ScaleContext &rCtx, long nStartY, long nEndY)
             BitmapColor aColRes( MAP( cR0, cR1, nTempFY ),
                     MAP( cG0, cG1, nTempFY ),
                     MAP( cB0, cB1, nTempFY ) );
-            rCtx.mpDest->SetPixel( nYDst, nXDst++, aColRes );
+            rCtx.mpDest->SetPixel( nY, nXDst++, aColRes );
         }
     }
 }
@@ -146,7 +176,7 @@ void scale24bitBGR(ScaleContext &rCtx, long nStartY, long nEndY)
 {
     const long nStartX = 0, nEndX = rCtx.mnDestW - 1L;
 
-    for( long nY = nStartY, nYDst = 0L; nY <= nEndY; nY++, nYDst++ )
+    for( long nY = nStartY; nY <= nEndY; nY++ )
     {
         long nTempY = rCtx.mpMapIY[ nY ];
         long nTempFY = rCtx.mpMapFY[ nY ];
@@ -176,7 +206,7 @@ void scale24bitBGR(ScaleContext &rCtx, long nStartY, long nEndY)
             BitmapColor aColRes( MAP( cR0, cR1, nTempFY ),
                     MAP( cG0, cG1, nTempFY ),
                     MAP( cB0, cB1, nTempFY ) );
-            rCtx.mpDest->SetPixel( nYDst, nXDst++, aColRes );
+            rCtx.mpDest->SetPixel( nY, nXDst++, aColRes );
         }
     }
 }
@@ -185,7 +215,7 @@ void scale24bitRGB(ScaleContext &rCtx, long nStartY, long nEndY)
 {
     const long nStartX = 0, nEndX = rCtx.mnDestW - 1L;
 
-    for( long nY = nStartY, nYDst = 0L; nY <= nEndY; nY++, nYDst++ )
+    for( long nY = nStartY; nY <= nEndY; nY++ )
     {
         long nTempY = rCtx.mpMapIY[ nY ];
         long nTempFY = rCtx.mpMapFY[ nY ];
@@ -215,7 +245,7 @@ void scale24bitRGB(ScaleContext &rCtx, long nStartY, long nEndY)
             BitmapColor aColRes( MAP( cR0, cR1, nTempFY ),
                     MAP( cG0, cG1, nTempFY ),
                     MAP( cB0, cB1, nTempFY ) );
-            rCtx.mpDest->SetPixel( nYDst, nXDst++, aColRes );
+            rCtx.mpDest->SetPixel( nY, nXDst++, aColRes );
         }
     }
 }
@@ -224,7 +254,7 @@ void scaleNonPalleteGeneral(ScaleContext &rCtx, long nStartY, long nEndY)
 {
     const long nStartX = 0, nEndX = rCtx.mnDestW - 1L;
 
-    for( long nY = nStartY, nYDst = 0L; nY <= nEndY; nY++, nYDst++ )
+    for( long nY = nStartY; nY <= nEndY; nY++ )
     {
         long nTempY = rCtx.mpMapIY[ nY ];
         long nTempFY = rCtx.mpMapFY[ nY ];
@@ -249,7 +279,7 @@ void scaleNonPalleteGeneral(ScaleContext &rCtx, long nStartY, long nEndY)
             BitmapColor aColRes( MAP( cR0, cR1, nTempFY ),
                     MAP( cG0, cG1, nTempFY ),
                     MAP( cB0, cB1, nTempFY ) );
-            rCtx.mpDest->SetPixel( nYDst, nXDst++, aColRes );
+            rCtx.mpDest->SetPixel( nY, nXDst++, aColRes );
         }
     }
 }
@@ -259,7 +289,7 @@ void scalePallete8bit2(ScaleContext &rCtx, long nStartY, long nEndY)
     const long nStartX = 0, nEndX = rCtx.mnDestW - 1L;
     const long nMax = 1 << 7L;
 
-    for( long nY = nStartY , nYDst = 0L; nY <= nEndY; nY++, nYDst++ )
+    for( long nY = nStartY; nY <= nEndY; nY++ )
     {
         long nTop = rCtx.mbVMirr ? ( nY + 1 ) : nY;
         long nBottom = rCtx.mbVMirr ? nY : ( nY + 1 ) ;
@@ -374,7 +404,7 @@ void scalePallete8bit2(ScaleContext &rCtx, long nStartY, long nEndY)
             }
 
             BitmapColor aColRes((sal_uInt8)nSumR, (sal_uInt8)nSumG, (sal_uInt8)nSumB);
-            rCtx.mpDest->SetPixel( nYDst, nXDst++, aColRes );
+            rCtx.mpDest->SetPixel( nY, nXDst++, aColRes );
         }
     }
 }
@@ -384,7 +414,7 @@ void scalePalleteGeneral2(ScaleContext &rCtx, long nStartY, long nEndY)
     const long nStartX = 0, nEndX = rCtx.mnDestW - 1L;
     const long nMax = 1 << 7L;
 
-    for( long nY = nStartY , nYDst = 0L; nY <= nEndY; nY++, nYDst++ )
+    for( long nY = nStartY; nY <= nEndY; nY++ )
     {
         long nTop = rCtx.mbVMirr ? ( nY + 1 ) : nY;
         long nBottom = rCtx.mbVMirr ? nY : ( nY + 1 ) ;
@@ -501,7 +531,7 @@ void scalePalleteGeneral2(ScaleContext &rCtx, long nStartY, long nEndY)
             }
 
             BitmapColor aColRes((sal_uInt8)nSumR, (sal_uInt8)nSumG, (sal_uInt8)nSumB);
-            rCtx.mpDest->SetPixel( nYDst, nXDst++, aColRes );
+            rCtx.mpDest->SetPixel( nY, nXDst++, aColRes );
         }
     }
 }
@@ -511,7 +541,7 @@ void scale24bitBGR2(ScaleContext &rCtx, long nStartY, long nEndY)
     const long nStartX = 0, nEndX = rCtx.mnDestW - 1L;
     const long nMax = 1 << 7L;
 
-    for( long nY = nStartY , nYDst = 0L; nY <= nEndY; nY++, nYDst++ )
+    for( long nY = nStartY; nY <= nEndY; nY++ )
     {
         long nTop = rCtx.mbVMirr ? ( nY + 1 ) : nY;
         long nBottom = rCtx.mbVMirr ? nY : ( nY + 1 ) ;
@@ -624,7 +654,7 @@ void scale24bitBGR2(ScaleContext &rCtx, long nStartY, long nEndY)
                 nSumB /= nTotalWeightY;
             }
             BitmapColor aColRes((sal_uInt8)nSumR, (sal_uInt8)nSumG, (sal_uInt8)nSumB);
-            rCtx.mpDest->SetPixel( nYDst, nXDst++, aColRes );
+            rCtx.mpDest->SetPixel( nY, nXDst++, aColRes );
         }
     }
 }
@@ -634,7 +664,7 @@ void scale24bitRGB2(ScaleContext &rCtx, long nStartY, long nEndY)
     const long nStartX = 0, nEndX = rCtx.mnDestW - 1L;
     const long nMax = 1 << 7L;
 
-    for( long nY = nStartY , nYDst = 0L; nY <= nEndY; nY++, nYDst++ )
+    for( long nY = nStartY; nY <= nEndY; nY++ )
     {
         long nTop = rCtx.mbVMirr ? ( nY + 1 ) : nY;
         long nBottom = rCtx.mbVMirr ? nY : ( nY + 1 ) ;
@@ -745,7 +775,7 @@ void scale24bitRGB2(ScaleContext &rCtx, long nStartY, long nEndY)
                 nSumB /= nTotalWeightY;
             }
             BitmapColor aColRes((sal_uInt8)nSumR, (sal_uInt8)nSumG, (sal_uInt8)nSumB);
-            rCtx.mpDest->SetPixel( nYDst, nXDst++, aColRes );
+            rCtx.mpDest->SetPixel( nY, nXDst++, aColRes );
         }
     }
 }
@@ -755,7 +785,7 @@ void scaleNonPalleteGeneral2(ScaleContext &rCtx, long nStartY, long nEndY)
     const long nStartX = 0, nEndX = rCtx.mnDestW - 1L;
     const long nMax = 1 << 7L;
 
-    for( long nY = nStartY , nYDst = 0L; nY <= nEndY; nY++, nYDst++ )
+    for( long nY = nStartY; nY <= nEndY; nY++ )
     {
         long nTop = rCtx.mbVMirr ? ( nY + 1 ) : nY;
         long nBottom = rCtx.mbVMirr ? nY : ( nY + 1 ) ;
@@ -871,7 +901,7 @@ void scaleNonPalleteGeneral2(ScaleContext &rCtx, long nStartY, long nEndY)
             }
 
             BitmapColor aColRes((sal_uInt8)nSumR, (sal_uInt8)nSumG, (sal_uInt8)nSumB);
-            rCtx.mpDest->SetPixel( nYDst, nXDst++, aColRes );
+            rCtx.mpDest->SetPixel( nY, nXDst++, aColRes );
         }
     }
 }
@@ -916,6 +946,7 @@ bool BitmapScaleSuper::filter(Bitmap& rBitmap)
 
     if (pReadAccess && pWriteAccess)
     {
+        ScaleRangeFn pScaleRangeFn;
         ScaleContext aContext( pReadAccess.get(),
                                pWriteAccess.get(),
                                pReadAccess->Width(),
@@ -923,7 +954,6 @@ bool BitmapScaleSuper::filter(Bitmap& rBitmap)
                                pReadAccess->Height(),
                                pWriteAccess->Height(),
                                bVMirr, bHMirr );
-        void (*scaleRangeFn)(ScaleContext &rCtx, long nStartY, long nEndY);
 
         bool bScaleUp = fScaleX >= fScaleThresh && fScaleY >= fScaleThresh;
         if( pReadAccess->HasPalette() )
@@ -931,10 +961,10 @@ bool BitmapScaleSuper::filter(Bitmap& rBitmap)
             switch( pReadAccess->GetScanlineFormat() )
             {
             case BMP_FORMAT_8BIT_PAL:
-                scaleRangeFn = bScaleUp ? scalePallete8bit : scalePallete8bit2;
+                pScaleRangeFn = bScaleUp ? scalePallete8bit : scalePallete8bit2;
                 break;
             default:
-                scaleRangeFn = bScaleUp ? scalePalleteGeneral
+                pScaleRangeFn = bScaleUp ? scalePalleteGeneral
                                         : scalePalleteGeneral2;
                 break;
             }
@@ -944,18 +974,63 @@ bool BitmapScaleSuper::filter(Bitmap& rBitmap)
             switch( pReadAccess->GetScanlineFormat() )
             {
             case BMP_FORMAT_24BIT_TC_BGR:
-                scaleRangeFn = bScaleUp ? scale24bitBGR : scale24bitBGR2;
+                pScaleRangeFn = bScaleUp ? scale24bitBGR : scale24bitBGR2;
                 break;
             case BMP_FORMAT_24BIT_TC_RGB:
-                scaleRangeFn = bScaleUp ? scale24bitRGB : scale24bitRGB2;
+                pScaleRangeFn = bScaleUp ? scale24bitRGB : scale24bitRGB2;
                 break;
             default:
-                scaleRangeFn = bScaleUp ? scaleNonPalleteGeneral
+                pScaleRangeFn = bScaleUp ? scaleNonPalleteGeneral
                                         : scaleNonPalleteGeneral2;
                 break;
             }
         }
-        scaleRangeFn( aContext, nStartY, nEndY );
+
+        // We want to thread - only if there is a lot of work to do:
+        // We work hard when there is a large destination image, or
+        // A large source image.
+        bool bHorizontalWork = pReadAccess->Width() > 512 || pWriteAccess->Width() > 512;
+
+        static bool bDisableThreadedScaling = getenv ("VCL_NO_THREAD_SCALE");
+        if ( bDisableThreadedScaling || !bHorizontalWork ||
+             nEndY - nStartY < SCALE_THREAD_STRIP )
+        {
+            SAL_INFO("vcl.gdi", "Scale in main thread");
+            pScaleRangeFn( aContext, nStartY, nEndY );
+        }
+        else
+        {
+            // partition and queue work
+            sal_uInt32 nThreads = std::max(std::thread::hardware_concurrency(), 1U);
+            sal_uInt32 nStrips = ((nEndY - nStartY) + SCALE_THREAD_STRIP - 1) / SCALE_THREAD_STRIP;
+            sal_uInt32 nStripsPerThread = nStrips / nThreads;
+            SAL_INFO("vcl.gdi", "Scale in " << nStrips << " strips " << nStripsPerThread << " per thread" << " we have " << nThreads << " CPU threads ");
+            long nStripY = nStartY;
+            std::vector<ScaleThread *> aThreads;
+            for ( sal_uInt32 t = 0; t < nThreads - 1; t++ )
+            {
+                ScaleThread *pThread = new ScaleThread( pScaleRangeFn );
+                for ( sal_uInt32 j = 0; j < nStripsPerThread; j++ )
+                {
+                    ScaleRangeContext aRC( aContext, nStripY );
+                    pThread->push( aRC );
+                    nStripY += SCALE_THREAD_STRIP;
+                }
+                pThread->create(); // set it running
+                aThreads.push_back( pThread );
+            }
+            // finish any remaining bits here
+            pScaleRangeFn( aContext, nStripY, nEndY );
+
+            // join threads...
+            for ( std::vector<ScaleThread *>::iterator it = aThreads.begin();
+                  it != aThreads.end(); ++it )
+            {
+                (*it)->join();
+                delete *it;
+            }
+            SAL_INFO("vcl.gdi", "Joined all scaling threads");
+        }
 
         bRet = true;
     }
commit 36dc9e75ac092748dbf13d67f24e92e9b61507e8
Author: Michael Meeks <michael.meeks at collabora.com>
Date:   Tue Oct 14 20:10:08 2014 -0300

    vcl: re-factor scaling to use a single fn. pointer based invocation.
    
    Change-Id: Ide61808dbfa82ce67794150f44b6bac4f3c8e302

diff --git a/vcl/source/bitmap/bitmapscalesuper.cxx b/vcl/source/bitmap/bitmapscalesuper.cxx
index e808562..29819c9 100644
--- a/vcl/source/bitmap/bitmapscalesuper.cxx
+++ b/vcl/source/bitmap/bitmapscalesuper.cxx
@@ -923,47 +923,39 @@ bool BitmapScaleSuper::filter(Bitmap& rBitmap)
                                pReadAccess->Height(),
                                pWriteAccess->Height(),
                                bVMirr, bHMirr );
+        void (*scaleRangeFn)(ScaleContext &rCtx, long nStartY, long nEndY);
+
+        bool bScaleUp = fScaleX >= fScaleThresh && fScaleY >= fScaleThresh;
         if( pReadAccess->HasPalette() )
         {
-            if( pReadAccess->GetScanlineFormat() == BMP_FORMAT_8BIT_PAL )
+            switch( pReadAccess->GetScanlineFormat() )
             {
-                if( fScaleX >= fScaleThresh && fScaleY >= fScaleThresh )
-                    scalePallete8bit(aContext, nStartY, nEndY);
-                else
-                    scalePallete8bit2(aContext, nStartY, nEndY);
-            }
-            else
-            {
-                if( fScaleX >= fScaleThresh && fScaleY >= fScaleThresh )
-                    scalePalleteGeneral(aContext, nStartY, nEndY);
-                else
-                    scalePalleteGeneral2(aContext, nStartY, nEndY);
+            case BMP_FORMAT_8BIT_PAL:
+                scaleRangeFn = bScaleUp ? scalePallete8bit : scalePallete8bit2;
+                break;
+            default:
+                scaleRangeFn = bScaleUp ? scalePalleteGeneral
+                                        : scalePalleteGeneral2;
+                break;
             }
         }
         else
         {
-            if( pReadAccess->GetScanlineFormat() == BMP_FORMAT_24BIT_TC_BGR )
-            {
-                if( fScaleX >= fScaleThresh && fScaleY >= fScaleThresh )
-                    scale24bitBGR(aContext, nStartY, nEndY);
-                else
-                    scale24bitBGR2(aContext, nStartY, nEndY);
-            }
-            else if( pReadAccess->GetScanlineFormat() == BMP_FORMAT_24BIT_TC_RGB )
-            {
-                if( fScaleX >= fScaleThresh && fScaleY >= fScaleThresh )
-                    scale24bitRGB(aContext, nStartY, nEndY);
-                else
-                    scale24bitRGB2(aContext, nStartY, nEndY);
-            }
-            else
+            switch( pReadAccess->GetScanlineFormat() )
             {
-                if( fScaleX >= fScaleThresh && fScaleY >= fScaleThresh )
-                    scaleNonPalleteGeneral(aContext, nStartY, nEndY);
-                else
-                    scaleNonPalleteGeneral2(aContext, nStartY, nEndY);
+            case BMP_FORMAT_24BIT_TC_BGR:
+                scaleRangeFn = bScaleUp ? scale24bitBGR : scale24bitBGR2;
+                break;
+            case BMP_FORMAT_24BIT_TC_RGB:
+                scaleRangeFn = bScaleUp ? scale24bitRGB : scale24bitRGB2;
+                break;
+            default:
+                scaleRangeFn = bScaleUp ? scaleNonPalleteGeneral
+                                        : scaleNonPalleteGeneral2;
+                break;
             }
         }
+        scaleRangeFn( aContext, nStartY, nEndY );
 
         bRet = true;
     }
commit ec17637a7b5906ab0f6b59505dc67515a8bf6ee6
Author: Michael Meeks <michael.meeks at collabora.com>
Date:   Tue Oct 14 19:52:16 2014 -0300

    vcl: Re-factor to use the ScaleContext to pass parameters.
    
    Change-Id: If4359a6b776b4a94a6934e9fd02ede475a0612a7

diff --git a/vcl/source/bitmap/bitmapscalesuper.cxx b/vcl/source/bitmap/bitmapscalesuper.cxx
index dc5404c..e808562 100644
--- a/vcl/source/bitmap/bitmapscalesuper.cxx
+++ b/vcl/source/bitmap/bitmapscalesuper.cxx
@@ -43,8 +43,8 @@ void generateMap(long nW, long nDstW, bool bHMirr, long* pMapIX, long* pMapFX)
 }
 
 struct ScaleContext {
-    BitmapReadAccess *mpSrc;   // was pAcc
-    BitmapWriteAccess *mpDest; // was pWAcc
+    BitmapReadAccess  *mpSrc;
+    BitmapWriteAccess *mpDest;
     long mnSrcW, mnDestW;
     long mnSrcH, mnDestH;
     bool mbHMirr, mbVMirr;
@@ -58,7 +58,7 @@ struct ScaleContext {
                   long nSrcH, long nDestH,
                   bool bHMirr, bool bVMirr)
         : mpSrc( pSrc ), mpDest( pDest )
-        , mnSrcW( nSrcW ), mnDestW( nDestH )
+        , mnSrcW( nSrcW ), mnDestW( nDestW )
         , mnSrcH( nSrcH ), mnDestH( nDestH )
         , mbHMirr( bHMirr ), mbVMirr( bVMirr )
         , mpMapIX( new long[ nDestW ] )
@@ -71,34 +71,26 @@ struct ScaleContext {
     }
 };
 
-void scalePallete8bit(BitmapReadAccess* pAcc, BitmapWriteAccess* pWAcc,
-                      long nStartX, long nEndX, long nStartY, long nEndY,
-                      bool bVMirr, bool bHMirr)
+void scalePallete8bit(ScaleContext &rCtx, long nStartY, long nEndY)
 {
-    boost::scoped_array<long> pMapIX(new long[pWAcc->Width()]);
-    boost::scoped_array<long> pMapIY(new long[pWAcc->Height()]);
-    boost::scoped_array<long> pMapFX(new long[pWAcc->Width()]);
-    boost::scoped_array<long> pMapFY(new long[pWAcc->Height()]);
-
-    generateMap(pAcc->Width(),  pWAcc->Width(),  bHMirr, pMapIX.get(), pMapFX.get());
-    generateMap(pAcc->Height(), pWAcc->Height(), bVMirr, pMapIY.get(), pMapFY.get());
+    const long nStartX = 0, nEndX = rCtx.mnDestW - 1L;
 
     for( long nY = nStartY, nYDst = 0L; nY <= nEndY; nY++, nYDst++ )
     {
-        long nTempY = pMapIY[ nY ];
-        long nTempFY = pMapFY[ nY ];
-        Scanline pLine0 = pAcc->GetScanline( nTempY );
-        Scanline pLine1 = pAcc->GetScanline( ++nTempY );
+        long nTempY = rCtx.mpMapIY[ nY ];
+        long nTempFY = rCtx.mpMapFY[ nY ];
+        Scanline pLine0 = rCtx.mpSrc->GetScanline( nTempY );
+        Scanline pLine1 = rCtx.mpSrc->GetScanline( ++nTempY );
 
         for(long nX = nStartX, nXDst = 0L; nX <= nEndX; nX++ )
         {
-            long nTempX = pMapIX[ nX ];
-            long nTempFX = pMapFX[ nX ];
+            long nTempX = rCtx.mpMapIX[ nX ];
+            long nTempFX = rCtx.mpMapFX[ nX ];
 
-            const BitmapColor& rCol0 = pAcc->GetPaletteColor( pLine0[ nTempX ] );
-            const BitmapColor& rCol2 = pAcc->GetPaletteColor( pLine1[ nTempX ] );
-            const BitmapColor& rCol1 = pAcc->GetPaletteColor( pLine0[ ++nTempX ] );
-            const BitmapColor& rCol3 = pAcc->GetPaletteColor( pLine1[ nTempX ] );
+            const BitmapColor& rCol0 = rCtx.mpSrc->GetPaletteColor( pLine0[ nTempX ] );
+            const BitmapColor& rCol2 = rCtx.mpSrc->GetPaletteColor( pLine1[ nTempX ] );
+            const BitmapColor& rCol1 = rCtx.mpSrc->GetPaletteColor( pLine0[ ++nTempX ] );
+            const BitmapColor& rCol3 = rCtx.mpSrc->GetPaletteColor( pLine1[ nTempX ] );
 
             sal_uInt8 cR0 = MAP( rCol0.GetRed(), rCol1.GetRed(), nTempFX );
             sal_uInt8 cG0 = MAP( rCol0.GetGreen(), rCol1.GetGreen(), nTempFX );
@@ -111,42 +103,33 @@ void scalePallete8bit(BitmapReadAccess* pAcc, BitmapWriteAccess* pWAcc,
             BitmapColor aColRes( MAP( cR0, cR1, nTempFY ),
                     MAP( cG0, cG1, nTempFY ),
                     MAP( cB0, cB1, nTempFY ) );
-            pWAcc->SetPixel( nYDst, nXDst++, aColRes );
+            rCtx.mpDest->SetPixel( nYDst, nXDst++, aColRes );
         }
     }
 }
 
-void scalePalleteGeneral(BitmapReadAccess* pAcc, BitmapWriteAccess* pWAcc,
-                         long nStartX, long nEndX, long nStartY, long nEndY,
-                         bool bVMirr, bool bHMirr)
-
+void scalePalleteGeneral(ScaleContext &rCtx, long nStartY, long nEndY)
 {
-    boost::scoped_array<long> pMapIX(new long[pWAcc->Width()]);
-    boost::scoped_array<long> pMapIY(new long[pWAcc->Height()]);
-    boost::scoped_array<long> pMapFX(new long[pWAcc->Width()]);
-    boost::scoped_array<long> pMapFY(new long[pWAcc->Height()]);
-
-    generateMap(pAcc->Width(),  pWAcc->Width(),  bHMirr, pMapIX.get(), pMapFX.get());
-    generateMap(pAcc->Height(), pWAcc->Height(), bVMirr, pMapIY.get(), pMapFY.get());
+    const long nStartX = 0, nEndX = rCtx.mnDestW - 1L;
 
     for( long nY = nStartY, nYDst = 0L; nY <= nEndY; nY++, nYDst++ )
     {
-        long nTempY = pMapIY[ nY ];
-        long nTempFY = pMapFY[ nY ];
+        long nTempY = rCtx.mpMapIY[ nY ];
+        long nTempFY = rCtx.mpMapFY[ nY ];
 
         for( long nX = nStartX, nXDst = 0L; nX <= nEndX; nX++ )
         {
-            long nTempX = pMapIX[ nX ];
-            long nTempFX = pMapFX[ nX ];
+            long nTempX = rCtx.mpMapIX[ nX ];
+            long nTempFX = rCtx.mpMapFX[ nX ];
 
-            BitmapColor aCol0 = pAcc->GetPaletteColor( pAcc->GetPixelIndex( nTempY, nTempX ) );
-            BitmapColor aCol1 = pAcc->GetPaletteColor( pAcc->GetPixelIndex( nTempY, ++nTempX ) );
+            BitmapColor aCol0 = rCtx.mpSrc->GetPaletteColor( rCtx.mpSrc->GetPixelIndex( nTempY, nTempX ) );
+            BitmapColor aCol1 = rCtx.mpSrc->GetPaletteColor( rCtx.mpSrc->GetPixelIndex( nTempY, ++nTempX ) );
             sal_uInt8 cR0 = MAP( aCol0.GetRed(), aCol1.GetRed(), nTempFX );
             sal_uInt8 cG0 = MAP( aCol0.GetGreen(), aCol1.GetGreen(), nTempFX );
             sal_uInt8 cB0 = MAP( aCol0.GetBlue(), aCol1.GetBlue(), nTempFX );
 
-            aCol1 = pAcc->GetPaletteColor( pAcc->GetPixelIndex( ++nTempY, nTempX ) );
-            aCol0 = pAcc->GetPaletteColor( pAcc->GetPixelIndex( nTempY--, --nTempX ) );
+            aCol1 = rCtx.mpSrc->GetPaletteColor( rCtx.mpSrc->GetPixelIndex( ++nTempY, nTempX ) );
+            aCol0 = rCtx.mpSrc->GetPaletteColor( rCtx.mpSrc->GetPixelIndex( nTempY--, --nTempX ) );
             sal_uInt8 cR1 = MAP( aCol0.GetRed(), aCol1.GetRed(), nTempFX );
             sal_uInt8 cG1 = MAP( aCol0.GetGreen(), aCol1.GetGreen(), nTempFX );
             sal_uInt8 cB1 = MAP( aCol0.GetBlue(), aCol1.GetBlue(), nTempFX );
@@ -154,34 +137,26 @@ void scalePalleteGeneral(BitmapReadAccess* pAcc, BitmapWriteAccess* pWAcc,
             BitmapColor aColRes( MAP( cR0, cR1, nTempFY ),
                     MAP( cG0, cG1, nTempFY ),
                     MAP( cB0, cB1, nTempFY ) );
-            pWAcc->SetPixel( nYDst, nXDst++, aColRes );
+            rCtx.mpDest->SetPixel( nYDst, nXDst++, aColRes );
         }
     }
 }
 
-void scale24bitBGR(BitmapReadAccess* pAcc, BitmapWriteAccess* pWAcc,
-                         long nStartX, long nEndX, long nStartY, long nEndY,
-                         bool bVMirr, bool bHMirr)
+void scale24bitBGR(ScaleContext &rCtx, long nStartY, long nEndY)
 {
-    boost::scoped_array<long> pMapIX(new long[pWAcc->Width()]);
-    boost::scoped_array<long> pMapIY(new long[pWAcc->Height()]);
-    boost::scoped_array<long> pMapFX(new long[pWAcc->Width()]);
-    boost::scoped_array<long> pMapFY(new long[pWAcc->Height()]);
-
-    generateMap(pAcc->Width(),  pWAcc->Width(),  bHMirr, pMapIX.get(), pMapFX.get());
-    generateMap(pAcc->Height(), pWAcc->Height(), bVMirr, pMapIY.get(), pMapFY.get());
+    const long nStartX = 0, nEndX = rCtx.mnDestW - 1L;
 
     for( long nY = nStartY, nYDst = 0L; nY <= nEndY; nY++, nYDst++ )
     {
-        long nTempY = pMapIY[ nY ];
-        long nTempFY = pMapFY[ nY ];
-        Scanline pLine0 = pAcc->GetScanline( nTempY );
-        Scanline pLine1 = pAcc->GetScanline( ++nTempY );
+        long nTempY = rCtx.mpMapIY[ nY ];
+        long nTempFY = rCtx.mpMapFY[ nY ];
+        Scanline pLine0 = rCtx.mpSrc->GetScanline( nTempY );
+        Scanline pLine1 = rCtx.mpSrc->GetScanline( ++nTempY );
 
         for( long nX = nStartX, nXDst = 0L; nX <= nEndX; nX++ )
         {
-            long nOff = 3L * pMapIX[ nX ];
-            long nTempFX = pMapFX[ nX ];
+            long nOff = 3L * rCtx.mpMapIX[ nX ];
+            long nTempFX = rCtx.mpMapFX[ nX ];
 
             Scanline pTmp0 = pLine0 + nOff ;
             Scanline pTmp1 = pTmp0 + 3L;
@@ -201,34 +176,26 @@ void scale24bitBGR(BitmapReadAccess* pAcc, BitmapWriteAccess* pWAcc,
             BitmapColor aColRes( MAP( cR0, cR1, nTempFY ),
                     MAP( cG0, cG1, nTempFY ),
                     MAP( cB0, cB1, nTempFY ) );
-            pWAcc->SetPixel( nYDst, nXDst++, aColRes );
+            rCtx.mpDest->SetPixel( nYDst, nXDst++, aColRes );
         }
     }
 }
 
-void scale24bitRGB(BitmapReadAccess* pAcc, BitmapWriteAccess* pWAcc,
-                   long nStartX, long nEndX, long nStartY, long nEndY,
-                   bool bVMirr, bool bHMirr)
+void scale24bitRGB(ScaleContext &rCtx, long nStartY, long nEndY)
 {
-    boost::scoped_array<long> pMapIX(new long[pWAcc->Width()]);
-    boost::scoped_array<long> pMapIY(new long[pWAcc->Height()]);
-    boost::scoped_array<long> pMapFX(new long[pWAcc->Width()]);
-    boost::scoped_array<long> pMapFY(new long[pWAcc->Height()]);
-
-    generateMap(pAcc->Width(),  pWAcc->Width(),  bHMirr, pMapIX.get(), pMapFX.get());
-    generateMap(pAcc->Height(), pWAcc->Height(), bVMirr, pMapIY.get(), pMapFY.get());
+    const long nStartX = 0, nEndX = rCtx.mnDestW - 1L;
 
     for( long nY = nStartY, nYDst = 0L; nY <= nEndY; nY++, nYDst++ )
     {
-        long nTempY = pMapIY[ nY ];
-        long nTempFY = pMapFY[ nY ];
-        Scanline pLine0 = pAcc->GetScanline( nTempY );
-        Scanline pLine1 = pAcc->GetScanline( ++nTempY );
+        long nTempY = rCtx.mpMapIY[ nY ];
+        long nTempFY = rCtx.mpMapFY[ nY ];
+        Scanline pLine0 = rCtx.mpSrc->GetScanline( nTempY );
+        Scanline pLine1 = rCtx.mpSrc->GetScanline( ++nTempY );
 
         for( long nX = nStartX, nXDst = 0L; nX <= nEndX; nX++ )
         {
-            long nOff = 3L * pMapIX[ nX ];
-            long nTempFX = pMapFX[ nX ];
+            long nOff = 3L * rCtx.mpMapIX[ nX ];
+            long nTempFX = rCtx.mpMapFX[ nX ];
 
             Scanline pTmp0 = pLine0 + nOff;
             Scanline pTmp1 = pTmp0 + 3L;
@@ -248,41 +215,33 @@ void scale24bitRGB(BitmapReadAccess* pAcc, BitmapWriteAccess* pWAcc,
             BitmapColor aColRes( MAP( cR0, cR1, nTempFY ),
                     MAP( cG0, cG1, nTempFY ),
                     MAP( cB0, cB1, nTempFY ) );
-            pWAcc->SetPixel( nYDst, nXDst++, aColRes );
+            rCtx.mpDest->SetPixel( nYDst, nXDst++, aColRes );
         }
     }
 }
 
-void scaleNonPalleteGeneral(BitmapReadAccess* pAcc, BitmapWriteAccess* pWAcc,
-                            long nStartX, long nEndX, long nStartY, long nEndY,
-                            bool bVMirr, bool bHMirr)
+void scaleNonPalleteGeneral(ScaleContext &rCtx, long nStartY, long nEndY)
 {
-    boost::scoped_array<long> pMapIX(new long[pWAcc->Width()]);
-    boost::scoped_array<long> pMapIY(new long[pWAcc->Height()]);
-    boost::scoped_array<long> pMapFX(new long[pWAcc->Width()]);
-    boost::scoped_array<long> pMapFY(new long[pWAcc->Height()]);
-
-    generateMap(pAcc->Width(),  pWAcc->Width(),  bHMirr, pMapIX.get(), pMapFX.get());
-    generateMap(pAcc->Height(), pWAcc->Height(), bVMirr, pMapIY.get(), pMapFY.get());
+    const long nStartX = 0, nEndX = rCtx.mnDestW - 1L;
 
     for( long nY = nStartY, nYDst = 0L; nY <= nEndY; nY++, nYDst++ )
     {
-        long nTempY = pMapIY[ nY ];
-        long nTempFY = pMapFY[ nY ];
+        long nTempY = rCtx.mpMapIY[ nY ];
+        long nTempFY = rCtx.mpMapFY[ nY ];
 
         for( long nX = nStartX, nXDst = 0L; nX <= nEndX; nX++ )
         {
-            long nTempX = pMapIX[ nX ];
-            long nTempFX = pMapFX[ nX ];
+            long nTempX = rCtx.mpMapIX[ nX ];
+            long nTempFX = rCtx.mpMapFX[ nX ];
 
-            BitmapColor aCol0 = pAcc->GetPixel( nTempY, nTempX );
-            BitmapColor aCol1 = pAcc->GetPixel( nTempY, ++nTempX );
+            BitmapColor aCol0 = rCtx.mpSrc->GetPixel( nTempY, nTempX );
+            BitmapColor aCol1 = rCtx.mpSrc->GetPixel( nTempY, ++nTempX );
             sal_uInt8 cR0 = MAP( aCol0.GetRed(), aCol1.GetRed(), nTempFX );
             sal_uInt8 cG0 = MAP( aCol0.GetGreen(), aCol1.GetGreen(), nTempFX );
             sal_uInt8 cB0 = MAP( aCol0.GetBlue(), aCol1.GetBlue(), nTempFX );
 
-            aCol1 = pAcc->GetPixel( ++nTempY, nTempX );
-            aCol0 = pAcc->GetPixel( nTempY--, --nTempX );
+            aCol1 = rCtx.mpSrc->GetPixel( ++nTempY, nTempX );
+            aCol0 = rCtx.mpSrc->GetPixel( nTempY--, --nTempX );
             sal_uInt8 cR1 = MAP( aCol0.GetRed(), aCol1.GetRed(), nTempFX );
             sal_uInt8 cG1 = MAP( aCol0.GetGreen(), aCol1.GetGreen(), nTempFX );
             sal_uInt8 cB1 = MAP( aCol0.GetBlue(), aCol1.GetBlue(), nTempFX );
@@ -290,58 +249,49 @@ void scaleNonPalleteGeneral(BitmapReadAccess* pAcc, BitmapWriteAccess* pWAcc,
             BitmapColor aColRes( MAP( cR0, cR1, nTempFY ),
                     MAP( cG0, cG1, nTempFY ),
                     MAP( cB0, cB1, nTempFY ) );
-            pWAcc->SetPixel( nYDst, nXDst++, aColRes );
+            rCtx.mpDest->SetPixel( nYDst, nXDst++, aColRes );
         }
     }
 }
 
-void scalePallete8bit2(BitmapReadAccess* pAcc, BitmapWriteAccess* pWAcc,
-               long nStartX, long nEndX, long nStartY, long nEndY,
-               bool bVMirr, bool bHMirr)
+void scalePallete8bit2(ScaleContext &rCtx, long nStartY, long nEndY)
 {
-    boost::scoped_array<long> pMapIX(new long[pWAcc->Width()]);
-    boost::scoped_array<long> pMapIY(new long[pWAcc->Height()]);
-    boost::scoped_array<long> pMapFX(new long[pWAcc->Width()]);
-    boost::scoped_array<long> pMapFY(new long[pWAcc->Height()]);
-
-    generateMap(pAcc->Width(),  pWAcc->Width(),  bHMirr, pMapIX.get(), pMapFX.get());
-    generateMap(pAcc->Height(), pWAcc->Height(), bVMirr, pMapIY.get(), pMapFY.get());
-
+    const long nStartX = 0, nEndX = rCtx.mnDestW - 1L;
     const long nMax = 1 << 7L;
 
     for( long nY = nStartY , nYDst = 0L; nY <= nEndY; nY++, nYDst++ )
     {
-        long nTop = bVMirr ? ( nY + 1 ) : nY;
-        long nBottom = bVMirr ? nY : ( nY + 1 ) ;
+        long nTop = rCtx.mbVMirr ? ( nY + 1 ) : nY;
+        long nBottom = rCtx.mbVMirr ? nY : ( nY + 1 ) ;
 
         long nLineStart, nLineRange;
         if( nY == nEndY )
         {
-            nLineStart = pMapIY[ nY ];
+            nLineStart = rCtx.mpMapIY[ nY ];
             nLineRange = 0;
         }
         else
         {
-            nLineStart = pMapIY[ nTop ] ;
-            nLineRange = ( pMapIY[ nBottom ] == pMapIY[ nTop ] ) ? 1 :( pMapIY[ nBottom ] - pMapIY[ nTop ] );
+            nLineStart = rCtx.mpMapIY[ nTop ] ;
+            nLineRange = ( rCtx.mpMapIY[ nBottom ] == rCtx.mpMapIY[ nTop ] ) ? 1 :( rCtx.mpMapIY[ nBottom ] - rCtx.mpMapIY[ nTop ] );
         }
 
         for( long nX = nStartX , nXDst = 0L; nX <= nEndX; nX++ )
         {
-            long nLeft = bHMirr ? ( nX + 1 ) : nX;
-            long nRight = bHMirr ? nX : ( nX + 1 ) ;
+            long nLeft = rCtx.mbHMirr ? ( nX + 1 ) : nX;
+            long nRight = rCtx.mbHMirr ? nX : ( nX + 1 ) ;
 
             long nRowStart;
             long nRowRange;
             if( nX == nEndX )
             {
-                nRowStart = pMapIX[ nX ];
+                nRowStart = rCtx.mpMapIX[ nX ];
                 nRowRange = 0;
             }
             else
             {
-                nRowStart = pMapIX[ nLeft ];
-                nRowRange = ( pMapIX[ nRight ] == pMapIX[ nLeft ] )? 1 : ( pMapIX[ nRight ] - pMapIX[ nLeft ] );
+                nRowStart = rCtx.mpMapIX[ nLeft ];
+                nRowRange = ( rCtx.mpMapIX[ nRight ] == rCtx.mpMapIX[ nLeft ] )? 1 : ( rCtx.mpMapIX[ nRight ] - rCtx.mpMapIX[ nLeft ] );
             }
 
             long nSumR = 0;
@@ -351,7 +301,7 @@ void scalePallete8bit2(BitmapReadAccess* pAcc, BitmapWriteAccess* pWAcc,
 
             for(int i = 0; i<= nLineRange; i++)
             {
-                Scanline pTmpY = pAcc->GetScanline( nLineStart + i );
+                Scanline pTmpY = rCtx.mpSrc->GetScanline( nLineStart + i );
                 long nSumRowR = 0;
                 long nSumRowG = 0;
                 long nSumRowB = 0;
@@ -359,7 +309,7 @@ void scalePallete8bit2(BitmapReadAccess* pAcc, BitmapWriteAccess* pWAcc,
 
                 for(int j = 0; j <= nRowRange; j++)
                 {
-                    const BitmapColor& rCol = pAcc->GetPaletteColor( pTmpY[ nRowStart + j ] );
+                    const BitmapColor& rCol = rCtx.mpSrc->GetPaletteColor( pTmpY[ nRowStart + j ] );
 
                     if(nX == nEndX )
                     {
@@ -370,7 +320,7 @@ void scalePallete8bit2(BitmapReadAccess* pAcc, BitmapWriteAccess* pWAcc,
                     }
                     else if( j == 0 )
                     {
-                        long nWeightX = (nMax- pMapFX[ nLeft ]) ;
+                        long nWeightX = (nMax- rCtx.mpMapFX[ nLeft ]) ;
                         nSumRowB += ( nWeightX *rCol.GetBlue()) ;
                         nSumRowG += ( nWeightX *rCol.GetGreen()) ;
                         nSumRowR += ( nWeightX *rCol.GetRed()) ;
@@ -378,7 +328,7 @@ void scalePallete8bit2(BitmapReadAccess* pAcc, BitmapWriteAccess* pWAcc,
                     }
                     else if ( nRowRange == j )
                     {
-                        long nWeightX = pMapFX[ nRight ] ;
+                        long nWeightX = rCtx.mpMapFX[ nRight ] ;
                         nSumRowB += ( nWeightX *rCol.GetBlue() );
                         nSumRowG += ( nWeightX *rCol.GetGreen() );
                         nSumRowR += ( nWeightX *rCol.GetRed() );
@@ -397,11 +347,11 @@ void scalePallete8bit2(BitmapReadAccess* pAcc, BitmapWriteAccess* pWAcc,
                 if( nY == nEndY )
                     nWeightY = nMax;
                 else if( i == 0 )
-                    nWeightY = nMax - pMapFY[ nTop ];
+                    nWeightY = nMax - rCtx.mpMapFY[ nTop ];
                 else if( nLineRange == 1 )
-                    nWeightY = pMapFY[ nTop ];
+                    nWeightY = rCtx.mpMapFY[ nTop ];
                 else if ( nLineRange == i )
-                    nWeightY = pMapFY[ nBottom ];
+                    nWeightY = rCtx.mpMapFY[ nBottom ];
 
                 if (nTotalWeightX)
                 {
@@ -424,57 +374,48 @@ void scalePallete8bit2(BitmapReadAccess* pAcc, BitmapWriteAccess* pWAcc,
             }
 
             BitmapColor aColRes((sal_uInt8)nSumR, (sal_uInt8)nSumG, (sal_uInt8)nSumB);
-            pWAcc->SetPixel( nYDst, nXDst++, aColRes );
+            rCtx.mpDest->SetPixel( nYDst, nXDst++, aColRes );
         }
     }
 }
 
-void scalePalleteGeneral2(BitmapReadAccess* pAcc, BitmapWriteAccess* pWAcc,
-                          long nStartX, long nEndX, long nStartY, long nEndY,
-                          bool bVMirr, bool bHMirr)
+void scalePalleteGeneral2(ScaleContext &rCtx, long nStartY, long nEndY)
 {
-    boost::scoped_array<long> pMapIX(new long[pWAcc->Width()]);
-    boost::scoped_array<long> pMapIY(new long[pWAcc->Height()]);
-    boost::scoped_array<long> pMapFX(new long[pWAcc->Width()]);
-    boost::scoped_array<long> pMapFY(new long[pWAcc->Height()]);
-
-    generateMap(pAcc->Width(),  pWAcc->Width(),  bHMirr, pMapIX.get(), pMapFX.get());
-    generateMap(pAcc->Height(), pWAcc->Height(), bVMirr, pMapIY.get(), pMapFY.get());
-
+    const long nStartX = 0, nEndX = rCtx.mnDestW - 1L;
     const long nMax = 1 << 7L;
 
     for( long nY = nStartY , nYDst = 0L; nY <= nEndY; nY++, nYDst++ )
     {
-        long nTop = bVMirr ? ( nY + 1 ) : nY;
-        long nBottom = bVMirr ? nY : ( nY + 1 ) ;
+        long nTop = rCtx.mbVMirr ? ( nY + 1 ) : nY;
+        long nBottom = rCtx.mbVMirr ? nY : ( nY + 1 ) ;
 
         long nLineStart, nLineRange;
         if( nY ==nEndY )
         {
-            nLineStart = pMapIY[ nY ];
+            nLineStart = rCtx.mpMapIY[ nY ];
             nLineRange = 0;
         }
         else
         {
-            nLineStart = pMapIY[ nTop ] ;
-            nLineRange = ( pMapIY[ nBottom ] == pMapIY[ nTop ] ) ? 1 :( pMapIY[ nBottom ] - pMapIY[ nTop ] );
+            nLineStart = rCtx.mpMapIY[ nTop ] ;
+            nLineRange = ( rCtx.mpMapIY[ nBottom ] == rCtx.mpMapIY[ nTop ] ) ? 1 :( rCtx.mpMapIY[ nBottom ] - rCtx.mpMapIY[ nTop ] );
         }
 
         for( long nX = nStartX , nXDst = 0L; nX <= nEndX; nX++ )
         {
-            long nLeft = bHMirr ? ( nX + 1 ) : nX;
-            long nRight = bHMirr ? nX : ( nX + 1 ) ;
+            long nLeft = rCtx.mbHMirr ? ( nX + 1 ) : nX;
+            long nRight = rCtx.mbHMirr ? nX : ( nX + 1 ) ;
 
             long nRowStart, nRowRange;
             if( nX == nEndX )
             {
-                nRowStart = pMapIX[ nX ];
+                nRowStart = rCtx.mpMapIX[ nX ];
                 nRowRange = 0;
             }
             else
             {
-                nRowStart = pMapIX[ nLeft ];
-                nRowRange = ( pMapIX[ nRight ] == pMapIX[ nLeft ] )? 1 : ( pMapIX[ nRight ] - pMapIX[ nLeft ] );
+                nRowStart = rCtx.mpMapIX[ nLeft ];
+                nRowRange = ( rCtx.mpMapIX[ nRight ] == rCtx.mpMapIX[ nLeft ] )? 1 : ( rCtx.mpMapIX[ nRight ] - rCtx.mpMapIX[ nLeft ] );
             }
 
             long nSumR = 0;
@@ -491,7 +432,7 @@ void scalePalleteGeneral2(BitmapReadAccess* pAcc, BitmapWriteAccess* pWAcc,
 
                 for(int j = 0; j <= nRowRange; j++)
                 {
-                    BitmapColor aCol0 = pAcc->GetPaletteColor ( pAcc->GetPixelIndex( nLineStart + i, nRowStart + j ) );
+                    BitmapColor aCol0 = rCtx.mpSrc->GetPaletteColor ( rCtx.mpSrc->GetPixelIndex( nLineStart + i, nRowStart + j ) );
 
                     if(nX == nEndX )
                     {
@@ -504,7 +445,7 @@ void scalePalleteGeneral2(BitmapReadAccess* pAcc, BitmapWriteAccess* pWAcc,
                     else if( j == 0 )
                     {
 
-                        long nWeightX = (nMax- pMapFX[ nLeft ]) ;
+                        long nWeightX = (nMax- rCtx.mpMapFX[ nLeft ]) ;
                         nSumRowB += ( nWeightX *aCol0.GetBlue()) ;
                         nSumRowG += ( nWeightX *aCol0.GetGreen()) ;
                         nSumRowR += ( nWeightX *aCol0.GetRed()) ;
@@ -513,7 +454,7 @@ void scalePalleteGeneral2(BitmapReadAccess* pAcc, BitmapWriteAccess* pWAcc,
                     else if ( nRowRange == j )
                     {
 
-                        long nWeightX = pMapFX[ nRight ] ;
+                        long nWeightX = rCtx.mpMapFX[ nRight ] ;
                         nSumRowB += ( nWeightX *aCol0.GetBlue() );
                         nSumRowG += ( nWeightX *aCol0.GetGreen() );
                         nSumRowR += ( nWeightX *aCol0.GetRed() );
@@ -533,11 +474,11 @@ void scalePalleteGeneral2(BitmapReadAccess* pAcc, BitmapWriteAccess* pWAcc,
                 if( nY == nEndY )
                     nWeightY = nMax;
                 else if( i == 0 )
-                    nWeightY = nMax - pMapFY[ nTop ];
+                    nWeightY = nMax - rCtx.mpMapFY[ nTop ];
                 else if( nLineRange == 1 )
-                    nWeightY = pMapFY[ nTop ];
+                    nWeightY = rCtx.mpMapFY[ nTop ];
                 else if ( nLineRange == i )
-                    nWeightY = pMapFY[ nBottom ];
+                    nWeightY = rCtx.mpMapFY[ nBottom ];
 
                 if (nTotalWeightX)
                 {
@@ -560,59 +501,50 @@ void scalePalleteGeneral2(BitmapReadAccess* pAcc, BitmapWriteAccess* pWAcc,
             }
 
             BitmapColor aColRes((sal_uInt8)nSumR, (sal_uInt8)nSumG, (sal_uInt8)nSumB);
-            pWAcc->SetPixel( nYDst, nXDst++, aColRes );
+            rCtx.mpDest->SetPixel( nYDst, nXDst++, aColRes );
         }
     }
 }
 
-void scale24bitBGR2(BitmapReadAccess* pAcc, BitmapWriteAccess* pWAcc,
-                    long nStartX, long nEndX, long nStartY, long nEndY,
-                    bool bVMirr, bool bHMirr)
+void scale24bitBGR2(ScaleContext &rCtx, long nStartY, long nEndY)
 {
-    boost::scoped_array<long> pMapIX(new long[pWAcc->Width()]);
-    boost::scoped_array<long> pMapIY(new long[pWAcc->Height()]);
-    boost::scoped_array<long> pMapFX(new long[pWAcc->Width()]);
-    boost::scoped_array<long> pMapFY(new long[pWAcc->Height()]);
-
-    generateMap(pAcc->Width(),  pWAcc->Width(),  bHMirr, pMapIX.get(), pMapFX.get());
-    generateMap(pAcc->Height(), pWAcc->Height(), bVMirr, pMapIY.get(), pMapFY.get());
-
+    const long nStartX = 0, nEndX = rCtx.mnDestW - 1L;
     const long nMax = 1 << 7L;
 
     for( long nY = nStartY , nYDst = 0L; nY <= nEndY; nY++, nYDst++ )
     {
-        long nTop = bVMirr ? ( nY + 1 ) : nY;
-        long nBottom = bVMirr ? nY : ( nY + 1 ) ;
+        long nTop = rCtx.mbVMirr ? ( nY + 1 ) : nY;
+        long nBottom = rCtx.mbVMirr ? nY : ( nY + 1 ) ;
 
         long nLineStart;
         long nLineRange;
         if( nY ==nEndY )
         {
-            nLineStart = pMapIY[ nY ];
+            nLineStart = rCtx.mpMapIY[ nY ];
             nLineRange = 0;
         }
         else
         {
-            nLineStart = pMapIY[ nTop ] ;
-            nLineRange = ( pMapIY[ nBottom ] == pMapIY[ nTop ] ) ? 1 :( pMapIY[ nBottom ] - pMapIY[ nTop ] );
+            nLineStart = rCtx.mpMapIY[ nTop ] ;
+            nLineRange = ( rCtx.mpMapIY[ nBottom ] == rCtx.mpMapIY[ nTop ] ) ? 1 :( rCtx.mpMapIY[ nBottom ] - rCtx.mpMapIY[ nTop ] );
         }
 
         for( long nX = nStartX , nXDst = 0L; nX <= nEndX; nX++ )
         {
-            long nLeft = bHMirr ? ( nX + 1 ) : nX;
-            long nRight = bHMirr ? nX : ( nX + 1 ) ;
+            long nLeft = rCtx.mbHMirr ? ( nX + 1 ) : nX;
+            long nRight = rCtx.mbHMirr ? nX : ( nX + 1 ) ;
 
             long nRowStart;
             long nRowRange;
             if( nX == nEndX )
             {
-                nRowStart = pMapIX[ nX ];
+                nRowStart = rCtx.mpMapIX[ nX ];
                 nRowRange = 0;
             }
             else
             {
-                nRowStart = pMapIX[ nLeft ];
-                nRowRange = ( pMapIX[ nRight ] == pMapIX[ nLeft ] )? 1 : ( pMapIX[ nRight ] - pMapIX[ nLeft ] );
+                nRowStart = rCtx.mpMapIX[ nLeft ];
+                nRowRange = ( rCtx.mpMapIX[ nRight ] == rCtx.mpMapIX[ nLeft ] )? 1 : ( rCtx.mpMapIX[ nRight ] - rCtx.mpMapIX[ nLeft ] );
             }
 
             long nSumR = 0;
@@ -622,7 +554,7 @@ void scale24bitBGR2(BitmapReadAccess* pAcc, BitmapWriteAccess* pWAcc,
 
             for(int i = 0; i<= nLineRange; i++)
             {
-                Scanline pTmpY = pAcc->GetScanline( nLineStart + i );
+                Scanline pTmpY = rCtx.mpSrc->GetScanline( nLineStart + i );
                 Scanline pTmpX = pTmpY + 3L * nRowStart;
                 long nSumRowR = 0;
                 long nSumRowG = 0;
@@ -640,7 +572,7 @@ void scale24bitBGR2(BitmapReadAccess* pAcc, BitmapWriteAccess* pWAcc,
                     }
                     else if( j == 0 )
                     {
-                        long nWeightX = (nMax- pMapFX[ nLeft ]) ;
+                        long nWeightX = (nMax- rCtx.mpMapFX[ nLeft ]) ;
                         nSumRowB += ( nWeightX *( *pTmpX )) ;pTmpX++;
                         nSumRowG += ( nWeightX *( *pTmpX )) ;pTmpX++;
                         nSumRowR += ( nWeightX *( *pTmpX )) ;pTmpX++;
@@ -648,7 +580,7 @@ void scale24bitBGR2(BitmapReadAccess* pAcc, BitmapWriteAccess* pWAcc,
                     }
                     else if ( nRowRange == j )
                     {
-                        long nWeightX = pMapFX[ nRight ] ;
+                        long nWeightX = rCtx.mpMapFX[ nRight ] ;
                         nSumRowB += ( nWeightX *( *pTmpX ) );pTmpX++;
                         nSumRowG += ( nWeightX *( *pTmpX ) );pTmpX++;
                         nSumRowR += ( nWeightX *( *pTmpX ) );pTmpX++;
@@ -667,11 +599,11 @@ void scale24bitBGR2(BitmapReadAccess* pAcc, BitmapWriteAccess* pWAcc,
                 if( nY == nEndY )
                     nWeightY = nMax;
                 else if( i == 0 )
-                    nWeightY = nMax - pMapFY[ nTop ];
+                    nWeightY = nMax - rCtx.mpMapFY[ nTop ];
                 else if( nLineRange == 1 )
-                    nWeightY = pMapFY[ nTop ];
+                    nWeightY = rCtx.mpMapFY[ nTop ];
                 else if ( nLineRange == i )
-                    nWeightY = pMapFY[ nBottom ];
+                    nWeightY = rCtx.mpMapFY[ nBottom ];
 
                 if (nTotalWeightX)
                 {
@@ -692,57 +624,48 @@ void scale24bitBGR2(BitmapReadAccess* pAcc, BitmapWriteAccess* pWAcc,
                 nSumB /= nTotalWeightY;
             }
             BitmapColor aColRes((sal_uInt8)nSumR, (sal_uInt8)nSumG, (sal_uInt8)nSumB);
-            pWAcc->SetPixel( nYDst, nXDst++, aColRes );
+            rCtx.mpDest->SetPixel( nYDst, nXDst++, aColRes );
         }
     }
 }
 
-void scale24bitRGB2(BitmapReadAccess* pAcc, BitmapWriteAccess* pWAcc,
-                    long nStartX, long nEndX, long nStartY, long nEndY,
-                    bool bVMirr, bool bHMirr)
+void scale24bitRGB2(ScaleContext &rCtx, long nStartY, long nEndY)
 {
-    boost::scoped_array<long> pMapIX(new long[pWAcc->Width()]);
-    boost::scoped_array<long> pMapIY(new long[pWAcc->Height()]);
-    boost::scoped_array<long> pMapFX(new long[pWAcc->Width()]);
-    boost::scoped_array<long> pMapFY(new long[pWAcc->Height()]);
-
-    generateMap(pAcc->Width(),  pWAcc->Width(),  bHMirr, pMapIX.get(), pMapFX.get());
-    generateMap(pAcc->Height(), pWAcc->Height(), bVMirr, pMapIY.get(), pMapFY.get());
-
+    const long nStartX = 0, nEndX = rCtx.mnDestW - 1L;
     const long nMax = 1 << 7L;
 
     for( long nY = nStartY , nYDst = 0L; nY <= nEndY; nY++, nYDst++ )
     {
-        long nTop = bVMirr ? ( nY + 1 ) : nY;
-        long nBottom = bVMirr ? nY : ( nY + 1 ) ;
+        long nTop = rCtx.mbVMirr ? ( nY + 1 ) : nY;
+        long nBottom = rCtx.mbVMirr ? nY : ( nY + 1 ) ;
 
         long nLineStart, nLineRange;
         if( nY ==nEndY )
         {
-            nLineStart = pMapIY[ nY ];
+            nLineStart = rCtx.mpMapIY[ nY ];
             nLineRange = 0;
         }
         else
         {
-            nLineStart = pMapIY[ nTop ] ;
-            nLineRange = ( pMapIY[ nBottom ] == pMapIY[ nTop ] ) ? 1 :( pMapIY[ nBottom ] - pMapIY[ nTop ] );
+            nLineStart = rCtx.mpMapIY[ nTop ] ;
+            nLineRange = ( rCtx.mpMapIY[ nBottom ] == rCtx.mpMapIY[ nTop ] ) ? 1 :( rCtx.mpMapIY[ nBottom ] - rCtx.mpMapIY[ nTop ] );
         }
 
         for( long nX = nStartX , nXDst = 0L; nX <= nEndX; nX++ )
         {
-            long nLeft = bHMirr ? ( nX + 1 ) : nX;
-            long nRight = bHMirr ? nX : ( nX + 1 ) ;
+            long nLeft = rCtx.mbHMirr ? ( nX + 1 ) : nX;
+            long nRight = rCtx.mbHMirr ? nX : ( nX + 1 ) ;
 
             long nRowStart, nRowRange;
             if( nX == nEndX )
             {
-                nRowStart = pMapIX[ nX ];
+                nRowStart = rCtx.mpMapIX[ nX ];
                 nRowRange = 0;
             }
             else
             {
-                nRowStart = pMapIX[ nLeft ];
-                nRowRange = ( pMapIX[ nRight ] == pMapIX[ nLeft ] )? 1 : ( pMapIX[ nRight ] - pMapIX[ nLeft ] );
+                nRowStart = rCtx.mpMapIX[ nLeft ];
+                nRowRange = ( rCtx.mpMapIX[ nRight ] == rCtx.mpMapIX[ nLeft ] )? 1 : ( rCtx.mpMapIX[ nRight ] - rCtx.mpMapIX[ nLeft ] );
             }
 
             long nSumR = 0;
@@ -752,7 +675,7 @@ void scale24bitRGB2(BitmapReadAccess* pAcc, BitmapWriteAccess* pWAcc,
 
             for(int i = 0; i<= nLineRange; i++)
             {
-                Scanline pTmpY = pAcc->GetScanline( nLineStart + i );
+                Scanline pTmpY = rCtx.mpSrc->GetScanline( nLineStart + i );
                 Scanline pTmpX = pTmpY + 3L * nRowStart;
                 long nSumRowR = 0;
                 long nSumRowG = 0;
@@ -770,7 +693,7 @@ void scale24bitRGB2(BitmapReadAccess* pAcc, BitmapWriteAccess* pWAcc,
                     }
                     else if( j == 0 )
                     {
-                        long nWeightX = (nMax- pMapFX[ nLeft ]) ;
+                        long nWeightX = (nMax- rCtx.mpMapFX[ nLeft ]) ;
                         nSumRowR += ( nWeightX *( *pTmpX )) ;pTmpX++;
                         nSumRowG += ( nWeightX *( *pTmpX )) ;pTmpX++;
                         nSumRowB += ( nWeightX *( *pTmpX )) ;pTmpX++;
@@ -778,7 +701,7 @@ void scale24bitRGB2(BitmapReadAccess* pAcc, BitmapWriteAccess* pWAcc,
                     }
                     else if ( nRowRange == j )
                     {
-                        long nWeightX = pMapFX[ nRight ] ;
+                        long nWeightX = rCtx.mpMapFX[ nRight ] ;
                         nSumRowR += ( nWeightX *( *pTmpX ) );pTmpX++;
                         nSumRowG += ( nWeightX *( *pTmpX ) );pTmpX++;
                         nSumRowB += ( nWeightX *( *pTmpX ) );pTmpX++;
@@ -797,11 +720,11 @@ void scale24bitRGB2(BitmapReadAccess* pAcc, BitmapWriteAccess* pWAcc,
                 if( nY == nEndY )
                     nWeightY = nMax;
                 else if( i == 0 )
-                    nWeightY = nMax - pMapFY[ nTop ];
+                    nWeightY = nMax - rCtx.mpMapFY[ nTop ];
                 else if( nLineRange == 1 )
-                    nWeightY = pMapFY[ nTop ];
+                    nWeightY = rCtx.mpMapFY[ nTop ];
                 else if ( nLineRange == i )
-                    nWeightY = pMapFY[ nBottom ];
+                    nWeightY = rCtx.mpMapFY[ nBottom ];
 
                 if (nTotalWeightX)
                 {
@@ -822,57 +745,48 @@ void scale24bitRGB2(BitmapReadAccess* pAcc, BitmapWriteAccess* pWAcc,
                 nSumB /= nTotalWeightY;
             }
             BitmapColor aColRes((sal_uInt8)nSumR, (sal_uInt8)nSumG, (sal_uInt8)nSumB);
-            pWAcc->SetPixel( nYDst, nXDst++, aColRes );
+            rCtx.mpDest->SetPixel( nYDst, nXDst++, aColRes );
         }
     }
 }
 
-void scaleNonPalleteGeneral2(BitmapReadAccess* pAcc, BitmapWriteAccess* pWAcc,
-                             long nStartX, long nEndX, long nStartY, long nEndY,
-                             bool bVMirr, bool bHMirr)
+void scaleNonPalleteGeneral2(ScaleContext &rCtx, long nStartY, long nEndY)
 {
-    boost::scoped_array<long> pMapIX(new long[pWAcc->Width()]);
-    boost::scoped_array<long> pMapIY(new long[pWAcc->Height()]);
-    boost::scoped_array<long> pMapFX(new long[pWAcc->Width()]);
-    boost::scoped_array<long> pMapFY(new long[pWAcc->Height()]);
-
-    generateMap(pAcc->Width(),  pWAcc->Width(),  bHMirr, pMapIX.get(), pMapFX.get());
-    generateMap(pAcc->Height(), pWAcc->Height(), bVMirr, pMapIY.get(), pMapFY.get());
-
+    const long nStartX = 0, nEndX = rCtx.mnDestW - 1L;
     const long nMax = 1 << 7L;
 
     for( long nY = nStartY , nYDst = 0L; nY <= nEndY; nY++, nYDst++ )
     {
-        long nTop = bVMirr ? ( nY + 1 ) : nY;
-        long nBottom = bVMirr ? nY : ( nY + 1 ) ;
+        long nTop = rCtx.mbVMirr ? ( nY + 1 ) : nY;
+        long nBottom = rCtx.mbVMirr ? nY : ( nY + 1 ) ;
 
         long nLineStart, nLineRange;
         if( nY ==nEndY )
         {
-            nLineStart = pMapIY[ nY ];
+            nLineStart = rCtx.mpMapIY[ nY ];
             nLineRange = 0;
         }
         else
         {
-            nLineStart = pMapIY[ nTop ] ;
-            nLineRange = ( pMapIY[ nBottom ] == pMapIY[ nTop ] ) ? 1 :( pMapIY[ nBottom ] - pMapIY[ nTop ] );
+            nLineStart = rCtx.mpMapIY[ nTop ] ;
+            nLineRange = ( rCtx.mpMapIY[ nBottom ] == rCtx.mpMapIY[ nTop ] ) ? 1 :( rCtx.mpMapIY[ nBottom ] - rCtx.mpMapIY[ nTop ] );
         }
 
         for( long nX = nStartX , nXDst = 0L; nX <= nEndX; nX++ )
         {
-            long nLeft = bHMirr ? ( nX + 1 ) : nX;
-            long nRight = bHMirr ? nX : ( nX + 1 ) ;
+            long nLeft = rCtx.mbHMirr ? ( nX + 1 ) : nX;
+            long nRight = rCtx.mbHMirr ? nX : ( nX + 1 ) ;
 
             long nRowStart, nRowRange;
             if( nX == nEndX )
             {
-                nRowStart = pMapIX[ nX ];
+                nRowStart = rCtx.mpMapIX[ nX ];
                 nRowRange = 0;
             }
             else
             {
-                nRowStart = pMapIX[ nLeft ];
-                nRowRange = ( pMapIX[ nRight ] == pMapIX[ nLeft ] )? 1 : ( pMapIX[ nRight ] - pMapIX[ nLeft ] );
+                nRowStart = rCtx.mpMapIX[ nLeft ];
+                nRowRange = ( rCtx.mpMapIX[ nRight ] == rCtx.mpMapIX[ nLeft ] )? 1 : ( rCtx.mpMapIX[ nRight ] - rCtx.mpMapIX[ nLeft ] );
             }
 
             long nSumR = 0;
@@ -889,7 +803,7 @@ void scaleNonPalleteGeneral2(BitmapReadAccess* pAcc, BitmapWriteAccess* pWAcc,
 
                 for(int j = 0; j <= nRowRange; j++)
                 {
-                    BitmapColor aCol0 = pAcc->GetPixel( nLineStart + i, nRowStart + j );
+                    BitmapColor aCol0 = rCtx.mpSrc->GetPixel( nLineStart + i, nRowStart + j );
 
                     if(nX == nEndX )
                     {
@@ -902,7 +816,7 @@ void scaleNonPalleteGeneral2(BitmapReadAccess* pAcc, BitmapWriteAccess* pWAcc,
                     else if( j == 0 )
                     {
 
-                        long nWeightX = (nMax- pMapFX[ nLeft ]) ;
+                        long nWeightX = (nMax- rCtx.mpMapFX[ nLeft ]) ;
                         nSumRowB += ( nWeightX *aCol0.GetBlue()) ;
                         nSumRowG += ( nWeightX *aCol0.GetGreen()) ;
                         nSumRowR += ( nWeightX *aCol0.GetRed()) ;
@@ -911,7 +825,7 @@ void scaleNonPalleteGeneral2(BitmapReadAccess* pAcc, BitmapWriteAccess* pWAcc,
                     else if ( nRowRange == j )
                     {
 
-                        long nWeightX = pMapFX[ nRight ] ;
+                        long nWeightX = rCtx.mpMapFX[ nRight ] ;
                         nSumRowB += ( nWeightX *aCol0.GetBlue() );
                         nSumRowG += ( nWeightX *aCol0.GetGreen() );
                         nSumRowR += ( nWeightX *aCol0.GetRed() );
@@ -930,11 +844,11 @@ void scaleNonPalleteGeneral2(BitmapReadAccess* pAcc, BitmapWriteAccess* pWAcc,
                 if( nY == nEndY )
                     nWeightY = nMax;
                 else if( i == 0 )
-                    nWeightY = nMax - pMapFY[ nTop ];
+                    nWeightY = nMax - rCtx.mpMapFY[ nTop ];
                 else if( nLineRange == 1 )
-                    nWeightY = pMapFY[ nTop ];
+                    nWeightY = rCtx.mpMapFY[ nTop ];
                 else if ( nLineRange == i )
-                    nWeightY = pMapFY[ nBottom ];
+                    nWeightY = rCtx.mpMapFY[ nBottom ];
 
                 if (nTotalWeightX)
                 {
@@ -957,7 +871,7 @@ void scaleNonPalleteGeneral2(BitmapReadAccess* pAcc, BitmapWriteAccess* pWAcc,
             }
 
             BitmapColor aColRes((sal_uInt8)nSumR, (sal_uInt8)nSumG, (sal_uInt8)nSumB);
-            pWAcc->SetPixel( nYDst, nXDst++, aColRes );
+            rCtx.mpDest->SetPixel( nYDst, nXDst++, aColRes );
         }
     }
 }
@@ -997,44 +911,33 @@ bool BitmapScaleSuper::filter(Bitmap& rBitmap)
     Bitmap aOutBmp(Size(nDstW, nDstH), 24);
     Bitmap::ScopedWriteAccess pWriteAccess(aOutBmp);
 
-    const long nStartX = 0;
     const long nStartY = 0;
-    const long nEndX = nDstW - 1L;
-    const long nEndY = nDstH - 1L;
+    const long nEndY   = nDstH - 1L;
 
     if (pReadAccess && pWriteAccess)
     {
+        ScaleContext aContext( pReadAccess.get(),
+                               pWriteAccess.get(),
+                               pReadAccess->Width(),
+                               pWriteAccess->Width(),
+                               pReadAccess->Height(),
+                               pWriteAccess->Height(),
+                               bVMirr, bHMirr );
         if( pReadAccess->HasPalette() )
         {
             if( pReadAccess->GetScanlineFormat() == BMP_FORMAT_8BIT_PAL )
             {
                 if( fScaleX >= fScaleThresh && fScaleY >= fScaleThresh )
-                {
-                    scalePallete8bit(pReadAccess.get(), pWriteAccess.get(),
-                               nStartX, nEndX, nStartY, nEndY,
-                               bVMirr, bHMirr);
-                }
+                    scalePallete8bit(aContext, nStartY, nEndY);
                 else
-                {
-                    scalePallete8bit2(pReadAccess.get(), pWriteAccess.get(),
-                               nStartX, nEndX, nStartY, nEndY,
-                               bVMirr, bHMirr);
-                }
+                    scalePallete8bit2(aContext, nStartY, nEndY);
             }
             else
             {
                 if( fScaleX >= fScaleThresh && fScaleY >= fScaleThresh )
-                {
-                    scalePalleteGeneral(pReadAccess.get(), pWriteAccess.get(),
-                               nStartX, nEndX, nStartY, nEndY,
-                               bVMirr, bHMirr);
-                }
+                    scalePalleteGeneral(aContext, nStartY, nEndY);
                 else
-                {
-                    scalePalleteGeneral2(pReadAccess.get(), pWriteAccess.get(),
-                               nStartX, nEndX, nStartY, nEndY,
-                               bVMirr, bHMirr);
-                }
+                    scalePalleteGeneral2(aContext, nStartY, nEndY);
             }
         }
         else
@@ -1042,47 +945,23 @@ bool BitmapScaleSuper::filter(Bitmap& rBitmap)
             if( pReadAccess->GetScanlineFormat() == BMP_FORMAT_24BIT_TC_BGR )
             {
                 if( fScaleX >= fScaleThresh && fScaleY >= fScaleThresh )
-                {
-                    scale24bitBGR(pReadAccess.get(), pWriteAccess.get(),
-                               nStartX, nEndX, nStartY, nEndY,
-                               bVMirr, bHMirr);
-                }
+                    scale24bitBGR(aContext, nStartY, nEndY);
                 else
-                {
-                    scale24bitBGR2(pReadAccess.get(), pWriteAccess.get(),
-                               nStartX, nEndX, nStartY, nEndY,
-                               bVMirr, bHMirr);
-                }
+                    scale24bitBGR2(aContext, nStartY, nEndY);
             }
             else if( pReadAccess->GetScanlineFormat() == BMP_FORMAT_24BIT_TC_RGB )
             {
                 if( fScaleX >= fScaleThresh && fScaleY >= fScaleThresh )
-                {
-                    scale24bitRGB(pReadAccess.get(), pWriteAccess.get(),
-                               nStartX, nEndX, nStartY, nEndY,
-                               bVMirr, bHMirr);
-                }
+                    scale24bitRGB(aContext, nStartY, nEndY);
                 else
-                {
-                    scale24bitRGB2(pReadAccess.get(), pWriteAccess.get(),
-                               nStartX, nEndX, nStartY, nEndY,
-                               bVMirr, bHMirr);
-                }
+                    scale24bitRGB2(aContext, nStartY, nEndY);
             }
             else
             {
                 if( fScaleX >= fScaleThresh && fScaleY >= fScaleThresh )
-                {
-                    scaleNonPalleteGeneral(pReadAccess.get(), pWriteAccess.get(),
-                               nStartX, nEndX, nStartY, nEndY,
-                               bVMirr, bHMirr);
-                }
+                    scaleNonPalleteGeneral(aContext, nStartY, nEndY);
                 else
-                {
-                    scaleNonPalleteGeneral2(pReadAccess.get(), pWriteAccess.get(),
-                               nStartX, nEndX, nStartY, nEndY,
-                               bVMirr, bHMirr);
-                }
+                    scaleNonPalleteGeneral2(aContext, nStartY, nEndY);
             }
         }
 
commit 5f019b6790303ca595a310aa862260ef3a556a76
Author: Michael Meeks <michael.meeks at collabora.com>
Date:   Tue Oct 14 19:16:21 2014 -0300

    vcl: create a ScaleContext to share copy/paste Bitmap scaling code.
    
    Change-Id: I5a90b7c6065829d74c61b833f0551b8adc3f2711

diff --git a/vcl/source/bitmap/bitmapscalesuper.cxx b/vcl/source/bitmap/bitmapscalesuper.cxx
index 070747b9..dc5404c 100644
--- a/vcl/source/bitmap/bitmapscalesuper.cxx
+++ b/vcl/source/bitmap/bitmapscalesuper.cxx
@@ -42,6 +42,35 @@ void generateMap(long nW, long nDstW, bool bHMirr, long* pMapIX, long* pMapFX)
     }
 }
 
+struct ScaleContext {
+    BitmapReadAccess *mpSrc;   // was pAcc
+    BitmapWriteAccess *mpDest; // was pWAcc
+    long mnSrcW, mnDestW;
+    long mnSrcH, mnDestH;
+    bool mbHMirr, mbVMirr;
+    boost::scoped_array<long> mpMapIX;
+    boost::scoped_array<long> mpMapIY;
+    boost::scoped_array<long> mpMapFX;
+    boost::scoped_array<long> mpMapFY;
+    ScaleContext( BitmapReadAccess *pSrc,
+                  BitmapWriteAccess *pDest,
+                  long nSrcW, long nDestW,
+                  long nSrcH, long nDestH,
+                  bool bHMirr, bool bVMirr)
+        : mpSrc( pSrc ), mpDest( pDest )
+        , mnSrcW( nSrcW ), mnDestW( nDestH )
+        , mnSrcH( nSrcH ), mnDestH( nDestH )
+        , mbHMirr( bHMirr ), mbVMirr( bVMirr )
+        , mpMapIX( new long[ nDestW ] )
+        , mpMapIY( new long[ nDestH ] )
+        , mpMapFX( new long[ nDestW ] )
+        , mpMapFY( new long[ nDestH ] )
+    {
+        generateMap(nSrcW, nDestW, bHMirr, mpMapIX.get(), mpMapFX.get());
+        generateMap(nSrcH, nDestH, bVMirr, mpMapIY.get(), mpMapFY.get());
+    }
+};
+
 void scalePallete8bit(BitmapReadAccess* pAcc, BitmapWriteAccess* pWAcc,
                       long nStartX, long nEndX, long nStartY, long nEndY,
                       bool bVMirr, bool bHMirr)
@@ -799,8 +828,8 @@ void scale24bitRGB2(BitmapReadAccess* pAcc, BitmapWriteAccess* pWAcc,
 }
 
 void scaleNonPalleteGeneral2(BitmapReadAccess* pAcc, BitmapWriteAccess* pWAcc,
-                    long nStartX, long nEndX, long nStartY, long nEndY,
-                    bool bVMirr, bool bHMirr)
+                             long nStartX, long nEndX, long nStartY, long nEndY,
+                             bool bVMirr, bool bHMirr)
 {
     boost::scoped_array<long> pMapIX(new long[pWAcc->Width()]);
     boost::scoped_array<long> pMapIY(new long[pWAcc->Height()]);
commit 64eb9e2924b8649da9e831d81ee721714b81eb0d
Author: Michael Meeks <michael.meeks at collabora.com>
Date:   Tue Oct 14 19:04:12 2014 -0300

    vcl: hide bitmap helpers in an anonymous namespace.
    
    Change-Id: I96ad50f538cfb6ecd256c4268feb81796a135b2b

diff --git a/vcl/source/bitmap/bitmapscalesuper.cxx b/vcl/source/bitmap/bitmapscalesuper.cxx
index cbfb08e..070747b9 100644
--- a/vcl/source/bitmap/bitmapscalesuper.cxx
+++ b/vcl/source/bitmap/bitmapscalesuper.cxx
@@ -22,6 +22,8 @@
 
 #include <boost/scoped_array.hpp>
 
+namespace {
+
 #define MAP( cVal0, cVal1, nFrac )  ((sal_uInt8)((((long)(cVal0)<<7L)+nFrac*((long)(cVal1)-(cVal0)))>>7L))
 
 void generateMap(long nW, long nDstW, bool bHMirr, long* pMapIX, long* pMapFX)
@@ -176,8 +178,8 @@ void scale24bitBGR(BitmapReadAccess* pAcc, BitmapWriteAccess* pWAcc,
 }
 
 void scale24bitRGB(BitmapReadAccess* pAcc, BitmapWriteAccess* pWAcc,
-                         long nStartX, long nEndX, long nStartY, long nEndY,
-                         bool bVMirr, bool bHMirr)
+                   long nStartX, long nEndX, long nStartY, long nEndY,
+                   bool bVMirr, bool bHMirr)
 {
     boost::scoped_array<long> pMapIX(new long[pWAcc->Width()]);
     boost::scoped_array<long> pMapIY(new long[pWAcc->Height()]);
@@ -931,6 +933,8 @@ void scaleNonPalleteGeneral2(BitmapReadAccess* pAcc, BitmapWriteAccess* pWAcc,
     }
 }
 
+} // end anonymous namespace
+
 BitmapScaleSuper::BitmapScaleSuper(const double& rScaleX, const double& rScaleY) :
     mrScaleX(rScaleX),
     mrScaleY(rScaleY)


More information about the Libreoffice-commits mailing list