vcl/source/bitmap/BitmapScaleSuperFilter.cxx |  684 ++++++++++-----------------
 1 file changed, 278 insertions(+), 406 deletions(-)

New commits:
commit 99b6997a314cf74df17ea3eda1abcabd63d89cef
Author:     Tomaž Vajngerl <tomaz.vajng...@collabora.co.uk>
AuthorDate: Sat Apr 13 14:42:09 2019 +0900
Commit:     Tomaž Vajngerl <qui...@gmail.com>
CommitDate: Sat Apr 13 13:32:00 2019 +0200

    BitmapScaleSuper: generalize 24bit scaling
    
    Until now we had RGB and BGR version. Because we never change the
    byte order when scaling and the scanline type, we can generalize
    the two funcions into one, where we only need to be careful that
    we don't change the order of color components.
    
    The same is done already for 4 variants of 32-bit bitmap, where
    we really only need 1 function for all 4 variants, using the same
    principle.
    
    Change-Id: I0f6d6b0c06a45e53bcd048e2ae009a471bf90a06
    Reviewed-on: https://gerrit.libreoffice.org/70695
    Tested-by: Jenkins
    Reviewed-by: Tomaž Vajngerl <qui...@gmail.com>

diff --git a/vcl/source/bitmap/BitmapScaleSuperFilter.cxx 
b/vcl/source/bitmap/BitmapScaleSuperFilter.cxx
index bd8db3ace9e7..1011efa31287 100644
--- a/vcl/source/bitmap/BitmapScaleSuperFilter.cxx
+++ b/vcl/source/bitmap/BitmapScaleSuperFilter.cxx
@@ -259,84 +259,57 @@ void scalePalleteGeneral(ScaleContext &rCtx, long 
nStartY, long nEndY)
     }
 }
 
-void scale24bitBGR(ScaleContext &rCtx, long nStartY, long nEndY)
+void scaleUp24bit(ScaleContext &rCtx, long nStartY, long nEndY)
 {
-    const long nStartX = 0, nEndX = rCtx.mnDestW - 1;
+    const int nColorComponents = 3;
 
-    for( long nY = nStartY; nY <= nEndY; nY++ )
+    const long nStartX = 0;
+    const long nEndX = rCtx.mnDestW - 1;
+
+    for (long nY = nStartY; nY <= nEndY; nY++)
     {
-        long nTempY = rCtx.maMapIY[ nY ];
-        BilinearWeightType nTempFY = rCtx.maMapFY[ nY ];
-        Scanline pLine0 = rCtx.mpSrc->GetScanline( nTempY );
-        Scanline pLine1 = rCtx.mpSrc->GetScanline( ++nTempY );
-        Scanline pScanDest = rCtx.mpDest->GetScanline( nY );
+        long nTempY = rCtx.maMapIY[nY];
+        BilinearWeightType nTempFY = rCtx.maMapFY[nY];
 
-        for( long nX = nStartX, nXDst = 0; nX <= nEndX; nX++ )
-        {
-            long nOff = 3 * rCtx.maMapIX[ nX ];
-            BilinearWeightType nTempFX = rCtx.maMapFX[ nX ];
+        Scanline pLine0 = rCtx.mpSrc->GetScanline(nTempY+0);
+        Scanline pLine1 = rCtx.mpSrc->GetScanline(nTempY+1);
+        Scanline pScanDest = rCtx.mpDest->GetScanline(nY);
 
-            Scanline pTmp0 = pLine0 + nOff ;
-            Scanline pTmp1 = pTmp0 + 3;
-            sal_uInt8 cB0 = MAP( *pTmp0, *pTmp1, nTempFX );
-            pTmp0++; pTmp1++;
-            sal_uInt8 cG0 = MAP( *pTmp0, *pTmp1, nTempFX );
-            pTmp0++; pTmp1++;
-            sal_uInt8 cR0 = MAP( *pTmp0, *pTmp1, nTempFX );
-
-            pTmp0 = pLine1 + nOff;
-            pTmp1 = pTmp0 + 3;
-            sal_uInt8 cB1 = MAP( *pTmp0, *pTmp1, nTempFX );
-            pTmp0++; pTmp1++;
-            sal_uInt8 cG1 = MAP( *pTmp0, *pTmp1, nTempFX );
-            pTmp0++; pTmp1++;
-            sal_uInt8 cR1 = MAP( *pTmp0, *pTmp1, nTempFX );
+        sal_uInt8 nComponent1[nColorComponents];
+        sal_uInt8 nComponent2[nColorComponents];
 
-            BitmapColor aColRes( MAP( cR0, cR1, nTempFY ),
-                    MAP( cG0, cG1, nTempFY ),
-                    MAP( cB0, cB1, nTempFY ) );
-            rCtx.mpDest->SetPixelOnData( pScanDest, nXDst++, aColRes );
-        }
-    }
-}
+        Scanline pColorPtr0;
+        Scanline pColorPtr1;
 
-void scale24bitRGB(ScaleContext &rCtx, long nStartY, long nEndY)
-{
-    const long nStartX = 0, nEndX = rCtx.mnDestW - 1;
+        for (long nX = nStartX; nX <= nEndX; nX++)
+        {
+            long nTempX = rCtx.maMapIX[nX];
+            BilinearWeightType nTempFX = rCtx.maMapFX[nX];
 
-    for( long nY = nStartY; nY <= nEndY; nY++ )
-    {
-        long nTempY = rCtx.maMapIY[ nY ];
-        BilinearWeightType nTempFY = rCtx.maMapFY[ nY ];
-        Scanline pLine0 = rCtx.mpSrc->GetScanline( nTempY );
-        Scanline pLine1 = rCtx.mpSrc->GetScanline( ++nTempY );
-        Scanline pScanDest = rCtx.mpDest->GetScanline( nY );
+            pColorPtr0 = pLine0 + nTempX * nColorComponents;
+            pColorPtr1 = pColorPtr0 + nColorComponents;
 
-        for( long nX = nStartX, nXDst = 0; nX <= nEndX; nX++ )
-        {
-            long nOff = 3 * rCtx.maMapIX[ nX ];
-            BilinearWeightType nTempFX = rCtx.maMapFX[ nX ];
+            nComponent1[0] = MAP(*pColorPtr0, *pColorPtr1, nTempFX);
+            pColorPtr0++; pColorPtr1++;
+            nComponent1[1] = MAP(*pColorPtr0, *pColorPtr1, nTempFX);
+            pColorPtr0++; pColorPtr1++;
+            nComponent1[2] = MAP(*pColorPtr0, *pColorPtr1, nTempFX);
+
+            pColorPtr0 = pLine1 + nTempX * nColorComponents;
+            pColorPtr1 = pColorPtr0 + nColorComponents;
 
-            Scanline pTmp0 = pLine0 + nOff;
-            Scanline pTmp1 = pTmp0 + 3;
-            sal_uInt8 cR0 = MAP( *pTmp0, *pTmp1, nTempFX );
-            pTmp0++; pTmp1++;
-            sal_uInt8 cG0 = MAP( *pTmp0, *pTmp1, nTempFX );
-            pTmp0++; pTmp1++;
-            sal_uInt8 cB0 = MAP( *pTmp0, *pTmp1, nTempFX );
-
-            pTmp0 = pLine1 + nOff;
-            pTmp1 = pTmp0 + 3;
-            sal_uInt8 cR1 = MAP( *pTmp0, *pTmp1, nTempFX );
-            pTmp0++; pTmp1++;
-            sal_uInt8 cG1 = MAP( *pTmp0, *pTmp1, nTempFX );
-            pTmp0++; pTmp1++;
-            sal_uInt8 cB1 = MAP( *pTmp0, *pTmp1, nTempFX );
+            nComponent2[0] = MAP(*pColorPtr0, *pColorPtr1, nTempFX);
+            pColorPtr0++; pColorPtr1++;
+            nComponent2[1] = MAP(*pColorPtr0, *pColorPtr1, nTempFX);
+            pColorPtr0++; pColorPtr1++;
+            nComponent2[2] = MAP(*pColorPtr0, *pColorPtr1, nTempFX);
 
-            BitmapColor aColRes( MAP( cR0, cR1, nTempFY ),
-                    MAP( cG0, cG1, nTempFY ),
-                    MAP( cB0, cB1, nTempFY ) );
-            rCtx.mpDest->SetPixelOnData( pScanDest, nXDst++, aColRes );
+            *pScanDest = MAP(nComponent1[0], nComponent2[0], nTempFY);
+            pScanDest++;
+            *pScanDest = MAP(nComponent1[1], nComponent2[1], nTempFY);
+            pScanDest++;
+            *pScanDest = MAP(nComponent1[2], nComponent2[2], nTempFY);
+            pScanDest++;
         }
     }
 }
@@ -771,246 +744,134 @@ void scalePalleteGeneral2(ScaleContext &rCtx, long 
nStartY, long nEndY)
     }
 }
 
-void scale24bitBGR2(ScaleContext &rCtx, long nStartY, long nEndY)
+void scaleDown24bit(ScaleContext &rCtx, long nStartY, long nEndY)
 {
-    const long nStartX = 0, nEndX = rCtx.mnDestW - 1;
+    const int constColorComponents = 3;
 
-    for( long nY = nStartY; nY <= nEndY; nY++ )
+    const long nStartX = 0;
+    const long nEndX = rCtx.mnDestW - 1;
+
+    for (long nY = nStartY; nY <= nEndY; nY++)
     {
-        long nTop = rCtx.mbVMirr ? ( nY + 1 ) : nY;
-        long nBottom = rCtx.mbVMirr ? nY : ( nY + 1 ) ;
+        long nTop = rCtx.mbVMirr ? (nY + 1) : nY;
+        long nBottom = rCtx.mbVMirr ? nY : (nY + 1);
 
         long nLineStart;
         long nLineRange;
-        if( nY ==nEndY )
+        if (nY == nEndY)
         {
-            nLineStart = rCtx.maMapIY[ nY ];
+            nLineStart = rCtx.maMapIY[nY];
             nLineRange = 0;
         }
         else
         {
-            nLineStart = rCtx.maMapIY[ nTop ] ;
-            nLineRange = ( rCtx.maMapIY[ nBottom ] == rCtx.maMapIY[ nTop ] ) ? 
1 :( rCtx.maMapIY[ nBottom ] - rCtx.maMapIY[ nTop ] );
+            nLineStart = rCtx.maMapIY[nTop];
+            nLineRange = (rCtx.maMapIY[nBottom] == rCtx.maMapIY[nTop]) ?
+                            1 : (rCtx.maMapIY[nBottom] - rCtx.maMapIY[nTop]);
         }
 
-        Scanline pScanDest = rCtx.mpDest->GetScanline( nY );
-        for( long nX = nStartX , nXDst = 0; nX <= nEndX; nX++ )
+        Scanline pScanDest = rCtx.mpDest->GetScanline(nY);
+        for (long nX = nStartX; nX <= nEndX; nX++)
         {
-            long nLeft = rCtx.mbHMirr ? ( nX + 1 ) : nX;
-            long nRight = rCtx.mbHMirr ? nX : ( nX + 1 ) ;
+            long nLeft = rCtx.mbHMirr ? (nX + 1) : nX;
+            long nRight = rCtx.mbHMirr ? nX : (nX + 1);
 
             long nRowStart;
             long nRowRange;
-            if( nX == nEndX )
+            if (nX == nEndX)
             {
-                nRowStart = rCtx.maMapIX[ nX ];
+                nRowStart = rCtx.maMapIX[nX];
                 nRowRange = 0;
             }
             else
             {
-                nRowStart = rCtx.maMapIX[ nLeft ];
-                nRowRange = ( rCtx.maMapIX[ nRight ] == rCtx.maMapIX[ nLeft ] 
)? 1 : ( rCtx.maMapIX[ nRight ] - rCtx.maMapIX[ nLeft ] );
+                nRowStart = rCtx.maMapIX[nLeft];
+                nRowRange = (rCtx.maMapIX[nRight] == rCtx.maMapIX[nLeft]) ?
+                                1 : (rCtx.maMapIX[nRight] - 
rCtx.maMapIX[nLeft]);
             }
 
-            long nSumR = 0;
-            long nSumG = 0;
-            long nSumB = 0;
+            long nSum1 = 0;
+            long nSum2 = 0;
+            long nSum3 = 0;
             BilinearWeightType nTotalWeightY = 0;
 
-            for(long i = 0; i<= nLineRange; i++)
-            {
-                Scanline pTmpY = rCtx.mpSrc->GetScanline( nLineStart + i );
-                Scanline pTmpX = pTmpY + 3 * nRowStart;
-                long nSumRowR = 0;
-                long nSumRowG = 0;
-                long nSumRowB = 0;
-                BilinearWeightType nTotalWeightX = 0;
-
-                for(long j = 0; j <= nRowRange; j++)
-                {
-                    if(nX == nEndX )
-                    {
-                        nSumRowB += ( *pTmpX ) << MAP_PRECISION; pTmpX++;
-                        nSumRowG += ( *pTmpX ) << MAP_PRECISION; pTmpX++;
-                        nSumRowR += ( *pTmpX ) << MAP_PRECISION; pTmpX++;
-                        nTotalWeightX += lclMaxWeight();
-                    }
-                    else if( j == 0 )
-                    {
-                        BilinearWeightType nWeightX = lclMaxWeight() - 
rCtx.maMapFX[ nLeft ];
-                        nSumRowB += ( nWeightX *( *pTmpX )) ;pTmpX++;
-                        nSumRowG += ( nWeightX *( *pTmpX )) ;pTmpX++;
-                        nSumRowR += ( nWeightX *( *pTmpX )) ;pTmpX++;
-                        nTotalWeightX += nWeightX;
-                    }
-                    else if ( nRowRange == j )
-                    {
-                        BilinearWeightType nWeightX = rCtx.maMapFX[ nRight ] ;
-                        nSumRowB += ( nWeightX *( *pTmpX ) );pTmpX++;
-                        nSumRowG += ( nWeightX *( *pTmpX ) );pTmpX++;
-                        nSumRowR += ( nWeightX *( *pTmpX ) );pTmpX++;
-                        nTotalWeightX += nWeightX;
-                    }
-                    else
-                    {
-                        nSumRowB += ( *pTmpX ) << MAP_PRECISION; pTmpX++;
-                        nSumRowG += ( *pTmpX ) << MAP_PRECISION; pTmpX++;
-                        nSumRowR += ( *pTmpX ) << MAP_PRECISION; pTmpX++;
-                        nTotalWeightX += lclMaxWeight();
-                    }
-                }
-
-                BilinearWeightType nWeightY = lclMaxWeight();
-                if( nY == nEndY )
-                    nWeightY = lclMaxWeight();
-                else if( i == 0 )
-                    nWeightY = lclMaxWeight() - rCtx.maMapFY[ nTop ];
-                else if( nLineRange == 1 )
-                    nWeightY = rCtx.maMapFY[ nTop ];
-                else if ( nLineRange == i )
-                    nWeightY = rCtx.maMapFY[ nBottom ];
-
-                if (nTotalWeightX)
-                {
-                    nSumRowB /= nTotalWeightX;
-                    nSumRowG /= nTotalWeightX;
-                    nSumRowR /= nTotalWeightX;
-                }
-                nSumB += nWeightY * nSumRowB;
-                nSumG += nWeightY * nSumRowG;
-                nSumR += nWeightY * nSumRowR;
-                nTotalWeightY += nWeightY;
-            }
-
-            if (nTotalWeightY)
-            {
-                nSumR /= nTotalWeightY;
-                nSumG /= nTotalWeightY;
-                nSumB /= nTotalWeightY;
-            }
-            BitmapColor aColRes(static_cast<sal_uInt8>(nSumR), 
static_cast<sal_uInt8>(nSumG), static_cast<sal_uInt8>(nSumB));
-            rCtx.mpDest->SetPixelOnData( pScanDest, nXDst++, aColRes );
-        }
-    }
-}
-
-void scale24bitRGB2(ScaleContext &rCtx, long nStartY, long nEndY)
-{
-    const long nStartX = 0, nEndX = rCtx.mnDestW - 1;
-
-    for( long nY = nStartY; nY <= nEndY; nY++ )
-    {
-        long nTop = rCtx.mbVMirr ? ( nY + 1 ) : nY;
-        long nBottom = rCtx.mbVMirr ? nY : ( nY + 1 ) ;
-
-        long nLineStart, nLineRange;
-        if( nY ==nEndY )
-        {
-            nLineStart = rCtx.maMapIY[ nY ];
-            nLineRange = 0;
-        }
-        else
-        {
-            nLineStart = rCtx.maMapIY[ nTop ] ;
-            nLineRange = ( rCtx.maMapIY[ nBottom ] == rCtx.maMapIY[ nTop ] ) ? 
1 :( rCtx.maMapIY[ nBottom ] - rCtx.maMapIY[ nTop ] );
-        }
-
-        Scanline pScanDest = rCtx.mpDest->GetScanline( nY );
-        for( long nX = nStartX , nXDst = 0; nX <= nEndX; nX++ )
-        {
-            long nLeft = rCtx.mbHMirr ? ( nX + 1 ) : nX;
-            long nRight = rCtx.mbHMirr ? nX : ( nX + 1 ) ;
-
-            long nRowStart, nRowRange;
-            if( nX == nEndX )
-            {
-                nRowStart = rCtx.maMapIX[ nX ];
-                nRowRange = 0;
-            }
-            else
+            for (long i = 0; i<= nLineRange; i++)
             {
-                nRowStart = rCtx.maMapIX[ nLeft ];
-                nRowRange = ( rCtx.maMapIX[ nRight ] == rCtx.maMapIX[ nLeft ] 
)? 1 : ( rCtx.maMapIX[ nRight ] - rCtx.maMapIX[ nLeft ] );
-            }
-
-            long nSumR = 0;
-            long nSumG = 0;
-            long nSumB = 0;
-            BilinearWeightType nTotalWeightY = 0;
+                Scanline pTmpY = rCtx.mpSrc->GetScanline(nLineStart + i);
+                Scanline pTmpX = pTmpY + constColorComponents * nRowStart;
 
-            for(long i = 0; i<= nLineRange; i++)
-            {
-                Scanline pTmpY = rCtx.mpSrc->GetScanline( nLineStart + i );
-                Scanline pTmpX = pTmpY + 3 * nRowStart;
-                long nSumRowR = 0;
-                long nSumRowG = 0;
-                long nSumRowB = 0;
+                long nSumRow1 = 0;
+                long nSumRow2 = 0;
+                long nSumRow3 = 0;
                 BilinearWeightType nTotalWeightX = 0;
 
-                for(long j = 0; j <= nRowRange; j++)
+                for (long j = 0; j <= nRowRange; j++)
                 {
-                    if(nX == nEndX )
+                    if (nX == nEndX)
                     {
-                        nSumRowR += ( *pTmpX ) << MAP_PRECISION; pTmpX++;
-                        nSumRowG += ( *pTmpX ) << MAP_PRECISION; pTmpX++;
-                        nSumRowB += ( *pTmpX ) << MAP_PRECISION; pTmpX++;
+                        nSumRow1 += (*pTmpX) << MAP_PRECISION; pTmpX++;
+                        nSumRow2 += (*pTmpX) << MAP_PRECISION; pTmpX++;
+                        nSumRow3 += (*pTmpX) << MAP_PRECISION; pTmpX++;
                         nTotalWeightX += lclMaxWeight();
                     }
-                    else if( j == 0 )
+                    else if(j == 0)
                     {
-                        BilinearWeightType nWeightX = lclMaxWeight() - 
rCtx.maMapFX[ nLeft ];
-                        nSumRowR += ( nWeightX *( *pTmpX )) ;pTmpX++;
-                        nSumRowG += ( nWeightX *( *pTmpX )) ;pTmpX++;
-                        nSumRowB += ( nWeightX *( *pTmpX )) ;pTmpX++;
+                        BilinearWeightType nWeightX = lclMaxWeight() - 
rCtx.maMapFX[nLeft];
+                        nSumRow1 += (nWeightX * (*pTmpX)); pTmpX++;
+                        nSumRow2 += (nWeightX * (*pTmpX)); pTmpX++;
+                        nSumRow3 += (nWeightX * (*pTmpX)); pTmpX++;
                         nTotalWeightX += nWeightX;
                     }
                     else if ( nRowRange == j )
                     {
                         BilinearWeightType nWeightX = rCtx.maMapFX[ nRight ] ;
-                        nSumRowR += ( nWeightX *( *pTmpX ) );pTmpX++;
-                        nSumRowG += ( nWeightX *( *pTmpX ) );pTmpX++;
-                        nSumRowB += ( nWeightX *( *pTmpX ) );pTmpX++;
+                        nSumRow1 += (nWeightX * (*pTmpX)); pTmpX++;
+                        nSumRow2 += (nWeightX * (*pTmpX)); pTmpX++;
+                        nSumRow3 += (nWeightX * (*pTmpX)); pTmpX++;
                         nTotalWeightX += nWeightX;
                     }
                     else
                     {
-                        nSumRowR += ( *pTmpX ) << MAP_PRECISION; pTmpX++;
-                        nSumRowG += ( *pTmpX ) << MAP_PRECISION; pTmpX++;
-                        nSumRowB += ( *pTmpX ) << MAP_PRECISION; pTmpX++;
+                        nSumRow1 += (*pTmpX) << MAP_PRECISION; pTmpX++;
+                        nSumRow2 += (*pTmpX) << MAP_PRECISION; pTmpX++;
+                        nSumRow3 += (*pTmpX) << MAP_PRECISION; pTmpX++;
                         nTotalWeightX += lclMaxWeight();
                     }
                 }
 
                 BilinearWeightType nWeightY = lclMaxWeight();
-                if( nY == nEndY )
+                if (nY == nEndY)
                     nWeightY = lclMaxWeight();
-                else if( i == 0 )
-                    nWeightY = lclMaxWeight() - rCtx.maMapFY[ nTop ];
-                else if( nLineRange == 1 )
-                    nWeightY = rCtx.maMapFY[ nTop ];
-                else if ( nLineRange == i )
-                    nWeightY = rCtx.maMapFY[ nBottom ];
+                else if (i == 0)
+                    nWeightY = lclMaxWeight() - rCtx.maMapFY[nTop];
+                else if (nLineRange == 1)
+                    nWeightY = rCtx.maMapFY[nTop];
+                else if (nLineRange == i)
+                    nWeightY = rCtx.maMapFY[nBottom];
 
                 if (nTotalWeightX)
                 {
-                    nSumRowB /= nTotalWeightX;
-                    nSumRowG /= nTotalWeightX;
-                    nSumRowR /= nTotalWeightX;
+                    nSumRow1 /= nTotalWeightX;
+                    nSumRow2 /= nTotalWeightX;
+                    nSumRow3 /= nTotalWeightX;
                 }
-                nSumB += nWeightY * nSumRowB;
-                nSumG += nWeightY * nSumRowG;
-                nSumR += nWeightY * nSumRowR;
+                nSum1 += nWeightY * nSumRow1;
+                nSum2 += nWeightY * nSumRow2;
+                nSum3 += nWeightY * nSumRow3;
                 nTotalWeightY += nWeightY;
             }
 
             if (nTotalWeightY)
             {
-                nSumR /= nTotalWeightY;
-                nSumG /= nTotalWeightY;
-                nSumB /= nTotalWeightY;
+                nSum1 /= nTotalWeightY;
+                nSum2 /= nTotalWeightY;
+                nSum3 /= nTotalWeightY;
             }
-            BitmapColor aColRes(static_cast<sal_uInt8>(nSumR), 
static_cast<sal_uInt8>(nSumG), static_cast<sal_uInt8>(nSumB));
-            rCtx.mpDest->SetPixelOnData( pScanDest, nXDst++, aColRes );
+
+            // Write the calculated color components to the destination
+            *pScanDest = nSum1; pScanDest++;
+            *pScanDest = nSum2; pScanDest++;
+            *pScanDest = nSum3; pScanDest++;
         }
     }
 }
@@ -1233,10 +1094,8 @@ BitmapEx BitmapScaleSuperFilter::execute(BitmapEx const& 
rBitmap) const
                 switch( pReadAccess->GetScanlineFormat() )
                 {
                 case ScanlineFormat::N24BitTcBgr:
-                    pScaleRangeFn = bScaleUp ? scale24bitBGR : scale24bitBGR2;
-                    break;
                 case ScanlineFormat::N24BitTcRgb:
-                    pScaleRangeFn = bScaleUp ? scale24bitRGB : scale24bitRGB2;
+                    pScaleRangeFn = bScaleUp ? scaleUp24bit : scaleDown24bit;
                     break;
                 case ScanlineFormat::N32BitTcRgba:
                 case ScanlineFormat::N32BitTcBgra:
commit e90b92129122ccfb2b05061c7252c5dd737b7d65
Author:     Tomaž Vajngerl <tomaz.vajng...@collabora.co.uk>
AuthorDate: Sat Apr 13 14:23:23 2019 +0900
Commit:     Tomaž Vajngerl <qui...@gmail.com>
CommitDate: Sat Apr 13 13:31:50 2019 +0200

    BitmapScaleSuper: make it easy to change the percision
    
    Most calculations work with integers for speed, which sacrifices
    some bits of an integer type for decimal values (fixed-point
    precision). In this case we used 7 bits for decimal values. This
    change makes the precision easily adjustable.
    
    In addition the actual type of bilinar weights, which was until
    now the type long (that hasn't a standardized bit length), but is
    now changed to sal_Int32 (so we know exactly how much bits we can
    use) and can be changed to sal_Int64 in the future if necessary
    by just adjusting the typedef.
    
    Change-Id: I8d41751c20e14cd1b9b64b055ff66bd1ca7c9f1d
    Reviewed-on: https://gerrit.libreoffice.org/70694
    Tested-by: Jenkins
    Reviewed-by: Tomaž Vajngerl <qui...@gmail.com>

diff --git a/vcl/source/bitmap/BitmapScaleSuperFilter.cxx 
b/vcl/source/bitmap/BitmapScaleSuperFilter.cxx
index a09bad11e201..bd8db3ace9e7 100644
--- a/vcl/source/bitmap/BitmapScaleSuperFilter.cxx
+++ b/vcl/source/bitmap/BitmapScaleSuperFilter.cxx
@@ -32,48 +32,67 @@
 
 namespace {
 
-#define MAP( cVal0, cVal1, nFrac )  
(static_cast<sal_uInt8>(((static_cast<long>(cVal0)<<7)+nFrac*(static_cast<long>(cVal1)-(cVal0)))>>7))
+#define MAP_PRECISION 7
 
-void generateMap(long nW, long nDstW, bool bHMirr, long* pMapIX, long* pMapFX)
+typedef sal_Int32 BilinearWeightType;
+
+constexpr BilinearWeightType lclMaxWeight()
 {
-    const double fRevScaleX = (nDstW > 1) ? static_cast<double>(nW - 1) / 
(nDstW - 1) : 0.0;
+    return BilinearWeightType(1) << MAP_PRECISION;
+}
 
-    long nTemp = nW - 2;
-    long nTempX = nW - 1;
-    for (long nX = 0; nX < nDstW; nX++)
-    {
-        double fTemp = nX * fRevScaleX;
-        if (bHMirr)
-            fTemp = nTempX - fTemp;
-        pMapIX[nX] = MinMax(static_cast<long>(fTemp), 0, nTemp);
-        pMapFX[nX] = static_cast<long>((fTemp - pMapIX[nX]) * 128.0);
-    }
+constexpr sal_uInt8 MAP(sal_uInt8 cVal0, sal_uInt8 cVal1, BilinearWeightType 
nFrac)
+{
+    return sal_uInt8(((BilinearWeightType(cVal0) << MAP_PRECISION) + nFrac * 
(BilinearWeightType(cVal1) - BilinearWeightType(cVal0))) >> MAP_PRECISION);
 }
 
-struct ScaleContext {
-    BitmapReadAccess  * const mpSrc;
-    BitmapWriteAccess *mpDest;
+struct ScaleContext
+{
+    BitmapReadAccess* const mpSrc;
+    BitmapWriteAccess* mpDest;
     long mnDestW;
-    bool mbHMirr, mbVMirr;
-    std::unique_ptr<long[]> mpMapIX;
-    std::unique_ptr<long[]> mpMapIY;
-    std::unique_ptr<long[]> mpMapFX;
-    std::unique_ptr<long[]> mpMapFY;
+    bool mbHMirr;
+    bool mbVMirr;
+    std::vector<long> maMapIX;
+    std::vector<long> maMapIY;
+    std::vector<BilinearWeightType> maMapFX;
+    std::vector<BilinearWeightType> maMapFY;
+
     ScaleContext( BitmapReadAccess *pSrc,
                   BitmapWriteAccess *pDest,
                   long nSrcW, long nDestW,
                   long nSrcH, long nDestH,
                   bool bHMirr, bool bVMirr)
-        : mpSrc( pSrc ), mpDest( pDest )
-        , mnDestW( nDestW )
-        , mbHMirr( bHMirr ), mbVMirr( bVMirr )
-        , mpMapIX( new long[ nDestW ] )
-        , mpMapIY( new long[ nDestH ] )
-        , mpMapFX( new long[ nDestW ] )
-        , mpMapFY( new long[ nDestH ] )
+        : mpSrc(pSrc)
+        , mpDest(pDest)
+        , mnDestW(nDestW)
+        , mbHMirr(bHMirr)
+        , mbVMirr(bVMirr)
+        , maMapIX(nDestW)
+        , maMapIY(nDestH)
+        , maMapFX(nDestW)
+        , maMapFY(nDestH)
     {
-        generateMap(nSrcW, nDestW, bHMirr, mpMapIX.get(), mpMapFX.get());
-        generateMap(nSrcH, nDestH, bVMirr, mpMapIY.get(), mpMapFY.get());
+        generateMap(nSrcW, nDestW, bHMirr, maMapIX, maMapFX);
+        generateMap(nSrcH, nDestH, bVMirr, maMapIY, maMapFY);
+    }
+
+    static void generateMap(long nSourceLength, long nDestinationLength, bool 
bMirrored,
+        std::vector<long> & rMapIX, std::vector<BilinearWeightType> & rMapFX)
+    {
+        const double fRevScale = (nDestinationLength > 1) ? 
double(nSourceLength - 1) / (nDestinationLength - 1) : 0.0;
+
+        long nTemp = nSourceLength - 2;
+        long nTempX = nSourceLength - 1;
+
+        for (long i = 0; i < nDestinationLength; i++)
+        {
+            double fTemp = i * fRevScale;
+            if (bMirrored)
+                fTemp = nTempX - fTemp;
+            rMapIX[i] = MinMax(long(fTemp), 0, nTemp);
+            rMapFX[i] = BilinearWeightType((fTemp - rMapIX[i]) * 
(BilinearWeightType(1) << MAP_PRECISION));
+        }
     }
 };
 
@@ -115,8 +134,8 @@ void scaleUp32bit(ScaleContext &rCtx, long nStartY, long 
nEndY)
 
     for (long nY = nStartY; nY <= nEndY; nY++)
     {
-        long nTempY = rCtx.mpMapIY[nY];
-        long nTempFY = rCtx.mpMapFY[nY];
+        long nTempY = rCtx.maMapIY[nY];
+        BilinearWeightType nTempFY = rCtx.maMapFY[nY];
 
         Scanline pLine0 = rCtx.mpSrc->GetScanline(nTempY+0);
         Scanline pLine1 = rCtx.mpSrc->GetScanline(nTempY+1);
@@ -130,8 +149,8 @@ void scaleUp32bit(ScaleContext &rCtx, long nStartY, long 
nEndY)
 
         for (long nX = nStartX; nX <= nEndX; nX++)
         {
-            long nTempX = rCtx.mpMapIX[nX];
-            long nTempFX = rCtx.mpMapFX[nX];
+            long nTempX = rCtx.maMapIX[nX];
+            BilinearWeightType nTempFX = rCtx.maMapFX[nX];
 
             pColorPtr0 = pLine0 + nTempX * nColorComponents;
             pColorPtr1 = pColorPtr0 + nColorComponents;
@@ -173,16 +192,16 @@ void scalePallete8bit(ScaleContext &rCtx, long nStartY, 
long nEndY)
 
     for( long nY = nStartY; nY <= nEndY; nY++ )
     {
-        long nTempY = rCtx.mpMapIY[ nY ];
-        long nTempFY = rCtx.mpMapFY[ nY ];
+        long nTempY = rCtx.maMapIY[ nY ];
+        BilinearWeightType nTempFY = rCtx.maMapFY[ nY ];
         Scanline pLine0 = rCtx.mpSrc->GetScanline( nTempY );
         Scanline pLine1 = rCtx.mpSrc->GetScanline( ++nTempY );
         Scanline pScanDest = rCtx.mpDest->GetScanline( nY );
 
         for(long nX = nStartX, nXDst = 0; nX <= nEndX; nX++ )
         {
-            long nTempX = rCtx.mpMapIX[ nX ];
-            long nTempFX = rCtx.mpMapFX[ nX ];
+            long nTempX = rCtx.maMapIX[ nX ];
+            BilinearWeightType nTempFX = rCtx.maMapFX[ nX ];
 
             const BitmapColor& rCol0 = rCtx.mpSrc->GetPaletteColor( pLine0[ 
nTempX ] );
             const BitmapColor& rCol2 = rCtx.mpSrc->GetPaletteColor( pLine1[ 
nTempX ] );
@@ -211,14 +230,14 @@ void scalePalleteGeneral(ScaleContext &rCtx, long 
nStartY, long nEndY)
 
     for( long nY = nStartY; nY <= nEndY; nY++ )
     {
-        long nTempY = rCtx.mpMapIY[ nY ];
-        long nTempFY = rCtx.mpMapFY[ nY ];
+        long nTempY = rCtx.maMapIY[ nY ];
+        BilinearWeightType nTempFY = rCtx.maMapFY[ nY ];
         Scanline pScanline = rCtx.mpDest->GetScanline( nY );
 
         for( long nX = nStartX, nXDst = 0; nX <= nEndX; nX++ )
         {
-            long nTempX = rCtx.mpMapIX[ nX ];
-            long nTempFX = rCtx.mpMapFX[ nX ];
+            long nTempX = rCtx.maMapIX[ nX ];
+            BilinearWeightType nTempFX = rCtx.maMapFX[ nX ];
 
             BitmapColor aCol0 = rCtx.mpSrc->GetPaletteColor( 
rCtx.mpSrc->GetPixelIndex( nTempY, nTempX ) );
             BitmapColor aCol1 = rCtx.mpSrc->GetPaletteColor( 
rCtx.mpSrc->GetPixelIndex( nTempY, ++nTempX ) );
@@ -246,16 +265,16 @@ void scale24bitBGR(ScaleContext &rCtx, long nStartY, long 
nEndY)
 
     for( long nY = nStartY; nY <= nEndY; nY++ )
     {
-        long nTempY = rCtx.mpMapIY[ nY ];
-        long nTempFY = rCtx.mpMapFY[ nY ];
+        long nTempY = rCtx.maMapIY[ nY ];
+        BilinearWeightType nTempFY = rCtx.maMapFY[ nY ];
         Scanline pLine0 = rCtx.mpSrc->GetScanline( nTempY );
         Scanline pLine1 = rCtx.mpSrc->GetScanline( ++nTempY );
         Scanline pScanDest = rCtx.mpDest->GetScanline( nY );
 
         for( long nX = nStartX, nXDst = 0; nX <= nEndX; nX++ )
         {
-            long nOff = 3 * rCtx.mpMapIX[ nX ];
-            long nTempFX = rCtx.mpMapFX[ nX ];
+            long nOff = 3 * rCtx.maMapIX[ nX ];
+            BilinearWeightType nTempFX = rCtx.maMapFX[ nX ];
 
             Scanline pTmp0 = pLine0 + nOff ;
             Scanline pTmp1 = pTmp0 + 3;
@@ -287,16 +306,16 @@ void scale24bitRGB(ScaleContext &rCtx, long nStartY, long 
nEndY)
 
     for( long nY = nStartY; nY <= nEndY; nY++ )
     {
-        long nTempY = rCtx.mpMapIY[ nY ];
-        long nTempFY = rCtx.mpMapFY[ nY ];
+        long nTempY = rCtx.maMapIY[ nY ];
+        BilinearWeightType nTempFY = rCtx.maMapFY[ nY ];
         Scanline pLine0 = rCtx.mpSrc->GetScanline( nTempY );
         Scanline pLine1 = rCtx.mpSrc->GetScanline( ++nTempY );
         Scanline pScanDest = rCtx.mpDest->GetScanline( nY );
 
         for( long nX = nStartX, nXDst = 0; nX <= nEndX; nX++ )
         {
-            long nOff = 3 * rCtx.mpMapIX[ nX ];
-            long nTempFX = rCtx.mpMapFX[ nX ];
+            long nOff = 3 * rCtx.maMapIX[ nX ];
+            BilinearWeightType nTempFX = rCtx.maMapFX[ nX ];
 
             Scanline pTmp0 = pLine0 + nOff;
             Scanline pTmp1 = pTmp0 + 3;
@@ -328,14 +347,14 @@ void scaleNonPalleteGeneral(ScaleContext &rCtx, long 
nStartY, long nEndY)
 
     for( long nY = nStartY; nY <= nEndY; nY++ )
     {
-        long nTempY = rCtx.mpMapIY[ nY ];
-        long nTempFY = rCtx.mpMapFY[ nY ];
+        long nTempY = rCtx.maMapIY[ nY ];
+        BilinearWeightType nTempFY = rCtx.maMapFY[ nY ];
         Scanline pScanDest = rCtx.mpDest->GetScanline( nY );
 
         for( long nX = nStartX, nXDst = 0; nX <= nEndX; nX++ )
         {
-            long nTempX = rCtx.mpMapIX[ nX ];
-            long nTempFX = rCtx.mpMapFX[ nX ];
+            long nTempX = rCtx.maMapIX[ nX ];
+            BilinearWeightType nTempFX = rCtx.maMapFX[ nX ];
 
             BitmapColor aCol0 = rCtx.mpSrc->GetPixel( nTempY, nTempX );
             BitmapColor aCol1 = rCtx.mpSrc->GetPixel( nTempY, ++nTempX );
@@ -363,7 +382,6 @@ void scaleDown32bit(ScaleContext &rCtx, long nStartY, long 
nEndY)
 
     const long nStartX = 0;
     const long nEndX = rCtx.mnDestW - 1;
-    const long nMax = 1 << 7;
 
     for (long nY = nStartY; nY <= nEndY; nY++)
     {
@@ -374,14 +392,14 @@ void scaleDown32bit(ScaleContext &rCtx, long nStartY, 
long nEndY)
         long nLineRange;
         if (nY == nEndY)
         {
-            nLineStart = rCtx.mpMapIY[nY];
+            nLineStart = rCtx.maMapIY[nY];
             nLineRange = 0;
         }
         else
         {
-            nLineStart = rCtx.mpMapIY[nTop];
-            nLineRange = (rCtx.mpMapIY[nBottom] == rCtx.mpMapIY[nTop]) ?
-                            1 : (rCtx.mpMapIY[nBottom] - rCtx.mpMapIY[nTop]);
+            nLineStart = rCtx.maMapIY[nTop];
+            nLineRange = (rCtx.maMapIY[nBottom] == rCtx.maMapIY[nTop]) ?
+                            1 : (rCtx.maMapIY[nBottom] - rCtx.maMapIY[nTop]);
         }
 
         Scanline pScanDest = rCtx.mpDest->GetScanline(nY);
@@ -394,21 +412,21 @@ void scaleDown32bit(ScaleContext &rCtx, long nStartY, 
long nEndY)
             long nRowRange;
             if (nX == nEndX)
             {
-                nRowStart = rCtx.mpMapIX[nX];
+                nRowStart = rCtx.maMapIX[nX];
                 nRowRange = 0;
             }
             else
             {
-                nRowStart = rCtx.mpMapIX[nLeft];
-                nRowRange = (rCtx.mpMapIX[nRight] == rCtx.mpMapIX[nLeft]) ?
-                                1 : (rCtx.mpMapIX[nRight] - 
rCtx.mpMapIX[nLeft]);
+                nRowStart = rCtx.maMapIX[nLeft];
+                nRowRange = (rCtx.maMapIX[nRight] == rCtx.maMapIX[nLeft]) ?
+                                1 : (rCtx.maMapIX[nRight] - 
rCtx.maMapIX[nLeft]);
             }
 
             long nSum1 = 0;
             long nSum2 = 0;
             long nSum3 = 0;
             long nSum4 = 0;
-            long nTotalWeightY = 0;
+            BilinearWeightType nTotalWeightY = 0;
 
             for (long i = 0; i<= nLineRange; i++)
             {
@@ -419,21 +437,21 @@ void scaleDown32bit(ScaleContext &rCtx, long nStartY, 
long nEndY)
                 long nSumRow2 = 0;
                 long nSumRow3 = 0;
                 long nSumRow4 = 0;
-                long nTotalWeightX = 0;
+                BilinearWeightType nTotalWeightX = 0;
 
                 for (long j = 0; j <= nRowRange; j++)
                 {
                     if (nX == nEndX)
                     {
-                        nSumRow1 += (*pTmpX) << 7; pTmpX++;
-                        nSumRow2 += (*pTmpX) << 7; pTmpX++;
-                        nSumRow3 += (*pTmpX) << 7; pTmpX++;
-                        nSumRow4 += (*pTmpX) << 7; pTmpX++;
-                        nTotalWeightX += 1 << 7;
+                        nSumRow1 += (*pTmpX) << MAP_PRECISION; pTmpX++;
+                        nSumRow2 += (*pTmpX) << MAP_PRECISION; pTmpX++;
+                        nSumRow3 += (*pTmpX) << MAP_PRECISION; pTmpX++;
+                        nSumRow4 += (*pTmpX) << MAP_PRECISION; pTmpX++;
+                        nTotalWeightX += lclMaxWeight();
                     }
                     else if(j == 0)
                     {
-                        long nWeightX = nMax- rCtx.mpMapFX[nLeft];
+                        BilinearWeightType nWeightX = lclMaxWeight() - 
rCtx.maMapFX[nLeft];
                         nSumRow1 += (nWeightX * (*pTmpX)); pTmpX++;
                         nSumRow2 += (nWeightX * (*pTmpX)); pTmpX++;
                         nSumRow3 += (nWeightX * (*pTmpX)); pTmpX++;
@@ -442,7 +460,7 @@ void scaleDown32bit(ScaleContext &rCtx, long nStartY, long 
nEndY)
                     }
                     else if ( nRowRange == j )
                     {
-                        long nWeightX = rCtx.mpMapFX[ nRight ] ;
+                        BilinearWeightType nWeightX = rCtx.maMapFX[ nRight ] ;
                         nSumRow1 += (nWeightX * (*pTmpX)); pTmpX++;
                         nSumRow2 += (nWeightX * (*pTmpX)); pTmpX++;
                         nSumRow3 += (nWeightX * (*pTmpX)); pTmpX++;
@@ -451,23 +469,23 @@ void scaleDown32bit(ScaleContext &rCtx, long nStartY, 
long nEndY)
                     }
                     else
                     {
-                        nSumRow1 += (*pTmpX) << 7; pTmpX++;
-                        nSumRow2 += (*pTmpX) << 7; pTmpX++;
-                        nSumRow3 += (*pTmpX) << 7; pTmpX++;
-                        nSumRow4 += (*pTmpX) << 7; pTmpX++;
-                        nTotalWeightX += 1 << 7;
+                        nSumRow1 += (*pTmpX) << MAP_PRECISION; pTmpX++;
+                        nSumRow2 += (*pTmpX) << MAP_PRECISION; pTmpX++;
+                        nSumRow3 += (*pTmpX) << MAP_PRECISION; pTmpX++;
+                        nSumRow4 += (*pTmpX) << MAP_PRECISION; pTmpX++;
+                        nTotalWeightX += lclMaxWeight();
                     }
                 }
 
-                long nWeightY = nMax;
+                BilinearWeightType nWeightY = lclMaxWeight();
                 if (nY == nEndY)
-                    nWeightY = nMax;
+                    nWeightY = lclMaxWeight();
                 else if (i == 0)
-                    nWeightY = nMax - rCtx.mpMapFY[nTop];
+                    nWeightY = lclMaxWeight() - rCtx.maMapFY[nTop];
                 else if (nLineRange == 1)
-                    nWeightY = rCtx.mpMapFY[nTop];
+                    nWeightY = rCtx.maMapFY[nTop];
                 else if (nLineRange == i)
-                    nWeightY = rCtx.mpMapFY[nBottom];
+                    nWeightY = rCtx.maMapFY[nBottom];
 
                 if (nTotalWeightX)
                 {
@@ -503,7 +521,6 @@ void scaleDown32bit(ScaleContext &rCtx, long nStartY, long 
nEndY)
 void scalePallete8bit2(ScaleContext &rCtx, long nStartY, long nEndY)
 {
     const long nStartX = 0, nEndX = rCtx.mnDestW - 1;
-    const long nMax = 1 << 7;
 
     for( long nY = nStartY; nY <= nEndY; nY++ )
     {
@@ -513,13 +530,13 @@ void scalePallete8bit2(ScaleContext &rCtx, long nStartY, 
long nEndY)
         long nLineStart, nLineRange;
         if( nY == nEndY )
         {
-            nLineStart = rCtx.mpMapIY[ nY ];
+            nLineStart = rCtx.maMapIY[ nY ];
             nLineRange = 0;
         }
         else
         {
-            nLineStart = rCtx.mpMapIY[ nTop ] ;
-            nLineRange = ( rCtx.mpMapIY[ nBottom ] == rCtx.mpMapIY[ nTop ] ) ? 
1 :( rCtx.mpMapIY[ nBottom ] - rCtx.mpMapIY[ nTop ] );
+            nLineStart = rCtx.maMapIY[ nTop ] ;
+            nLineRange = ( rCtx.maMapIY[ nBottom ] == rCtx.maMapIY[ nTop ] ) ? 
1 :( rCtx.maMapIY[ nBottom ] - rCtx.maMapIY[ nTop ] );
         }
 
         Scanline pScanDest = rCtx.mpDest->GetScanline( nY );
@@ -532,19 +549,19 @@ void scalePallete8bit2(ScaleContext &rCtx, long nStartY, 
long nEndY)
             long nRowRange;
             if( nX == nEndX )
             {
-                nRowStart = rCtx.mpMapIX[ nX ];
+                nRowStart = rCtx.maMapIX[ nX ];
                 nRowRange = 0;
             }
             else
             {
-                nRowStart = rCtx.mpMapIX[ nLeft ];
-                nRowRange = ( rCtx.mpMapIX[ nRight ] == rCtx.mpMapIX[ nLeft ] 
)? 1 : ( rCtx.mpMapIX[ nRight ] - rCtx.mpMapIX[ nLeft ] );
+                nRowStart = rCtx.maMapIX[ nLeft ];
+                nRowRange = ( rCtx.maMapIX[ nRight ] == rCtx.maMapIX[ nLeft ] 
)? 1 : ( rCtx.maMapIX[ nRight ] - rCtx.maMapIX[ nLeft ] );
             }
 
             long nSumR = 0;
             long nSumG = 0;
             long nSumB = 0;
-            long nTotalWeightY = 0;
+            BilinearWeightType nTotalWeightY = 0;
 
             for(long i = 0; i<= nLineRange; i++)
             {
@@ -552,7 +569,7 @@ void scalePallete8bit2(ScaleContext &rCtx, long nStartY, 
long nEndY)
                 long nSumRowR = 0;
                 long nSumRowG = 0;
                 long nSumRowB = 0;
-                long nTotalWeightX = 0;
+                BilinearWeightType nTotalWeightX = 0;
 
                 for(long j = 0; j <= nRowRange; j++)
                 {
@@ -560,14 +577,14 @@ void scalePallete8bit2(ScaleContext &rCtx, long nStartY, 
long nEndY)
 
                     if(nX == nEndX )
                     {
-                        nSumRowB += rCol.GetBlue() << 7;
-                        nSumRowG += rCol.GetGreen() << 7;
-                        nSumRowR += rCol.GetRed() << 7;
-                        nTotalWeightX += 1 << 7;
+                        nSumRowB += rCol.GetBlue() << MAP_PRECISION;
+                        nSumRowG += rCol.GetGreen() << MAP_PRECISION;
+                        nSumRowR += rCol.GetRed() << MAP_PRECISION;
+                        nTotalWeightX += lclMaxWeight();
                     }
                     else if( j == 0 )
                     {
-                        long nWeightX = nMax- rCtx.mpMapFX[ nLeft ];
+                        BilinearWeightType nWeightX = lclMaxWeight() - 
rCtx.maMapFX[ nLeft ];
                         nSumRowB += ( nWeightX *rCol.GetBlue()) ;
                         nSumRowG += ( nWeightX *rCol.GetGreen()) ;
                         nSumRowR += ( nWeightX *rCol.GetRed()) ;
@@ -575,7 +592,7 @@ void scalePallete8bit2(ScaleContext &rCtx, long nStartY, 
long nEndY)
                     }
                     else if ( nRowRange == j )
                     {
-                        long nWeightX = rCtx.mpMapFX[ nRight ] ;
+                        BilinearWeightType nWeightX = rCtx.maMapFX[ nRight ] ;
                         nSumRowB += ( nWeightX *rCol.GetBlue() );
                         nSumRowG += ( nWeightX *rCol.GetGreen() );
                         nSumRowR += ( nWeightX *rCol.GetRed() );
@@ -583,22 +600,22 @@ void scalePallete8bit2(ScaleContext &rCtx, long nStartY, 
long nEndY)
                     }
                     else
                     {
-                        nSumRowB += rCol.GetBlue() << 7;
-                        nSumRowG += rCol.GetGreen() << 7;
-                        nSumRowR += rCol.GetRed() << 7;
-                        nTotalWeightX += 1 << 7;
+                        nSumRowB += rCol.GetBlue() << MAP_PRECISION;
+                        nSumRowG += rCol.GetGreen() << MAP_PRECISION;
+                        nSumRowR += rCol.GetRed() << MAP_PRECISION;
+                        nTotalWeightX += lclMaxWeight();
                     }
                 }
 
-                long nWeightY = nMax;
+                BilinearWeightType nWeightY = lclMaxWeight();
                 if( nY == nEndY )
-                    nWeightY = nMax;
+                    nWeightY = lclMaxWeight();
                 else if( i == 0 )
-                    nWeightY = nMax - rCtx.mpMapFY[ nTop ];
+                    nWeightY = lclMaxWeight() - rCtx.maMapFY[ nTop ];
                 else if( nLineRange == 1 )
-                    nWeightY = rCtx.mpMapFY[ nTop ];
+                    nWeightY = rCtx.maMapFY[ nTop ];
                 else if ( nLineRange == i )
-                    nWeightY = rCtx.mpMapFY[ nBottom ];
+                    nWeightY = rCtx.maMapFY[ nBottom ];
 
                 if (nTotalWeightX)
                 {
@@ -629,7 +646,6 @@ void scalePallete8bit2(ScaleContext &rCtx, long nStartY, 
long nEndY)
 void scalePalleteGeneral2(ScaleContext &rCtx, long nStartY, long nEndY)
 {
     const long nStartX = 0, nEndX = rCtx.mnDestW - 1;
-    const long nMax = 1 << 7;
 
     for( long nY = nStartY; nY <= nEndY; nY++ )
     {
@@ -639,13 +655,13 @@ void scalePalleteGeneral2(ScaleContext &rCtx, long 
nStartY, long nEndY)
         long nLineStart, nLineRange;
         if( nY ==nEndY )
         {
-            nLineStart = rCtx.mpMapIY[ nY ];
+            nLineStart = rCtx.maMapIY[ nY ];
             nLineRange = 0;
         }
         else
         {
-            nLineStart = rCtx.mpMapIY[ nTop ] ;
-            nLineRange = ( rCtx.mpMapIY[ nBottom ] == rCtx.mpMapIY[ nTop ] ) ? 
1 :( rCtx.mpMapIY[ nBottom ] - rCtx.mpMapIY[ nTop ] );
+            nLineStart = rCtx.maMapIY[ nTop ] ;
+            nLineRange = ( rCtx.maMapIY[ nBottom ] == rCtx.maMapIY[ nTop ] ) ? 
1 :( rCtx.maMapIY[ nBottom ] - rCtx.maMapIY[ nTop ] );
         }
 
         Scanline pScanDest = rCtx.mpDest->GetScanline( nY );
@@ -657,26 +673,26 @@ void scalePalleteGeneral2(ScaleContext &rCtx, long 
nStartY, long nEndY)
             long nRowStart, nRowRange;
             if( nX == nEndX )
             {
-                nRowStart = rCtx.mpMapIX[ nX ];
+                nRowStart = rCtx.maMapIX[ nX ];
                 nRowRange = 0;
             }
             else
             {
-                nRowStart = rCtx.mpMapIX[ nLeft ];
-                nRowRange = ( rCtx.mpMapIX[ nRight ] == rCtx.mpMapIX[ nLeft ] 
)? 1 : ( rCtx.mpMapIX[ nRight ] - rCtx.mpMapIX[ nLeft ] );
+                nRowStart = rCtx.maMapIX[ nLeft ];
+                nRowRange = ( rCtx.maMapIX[ nRight ] == rCtx.maMapIX[ nLeft ] 
)? 1 : ( rCtx.maMapIX[ nRight ] - rCtx.maMapIX[ nLeft ] );
             }
 
             long nSumR = 0;
             long nSumG = 0;
             long nSumB = 0;
-            long nTotalWeightY = 0;
+            BilinearWeightType nTotalWeightY = 0;
 
             for(long i = 0; i<= nLineRange; i++)
             {
                 long nSumRowR = 0;
                 long nSumRowG = 0;
                 long nSumRowB = 0;
-                long nTotalWeightX = 0;
+                BilinearWeightType nTotalWeightX = 0;
 
                 Scanline pScanlineSrc = rCtx.mpSrc->GetScanline( nLineStart + 
i );
                 for(long j = 0; j <= nRowRange; j++)
@@ -686,15 +702,15 @@ void scalePalleteGeneral2(ScaleContext &rCtx, long 
nStartY, long nEndY)
                     if(nX == nEndX )
                     {
 
-                        nSumRowB += aCol0.GetBlue() << 7;
-                        nSumRowG += aCol0.GetGreen() << 7;
-                        nSumRowR += aCol0.GetRed() << 7;
-                        nTotalWeightX += 1 << 7;
+                        nSumRowB += aCol0.GetBlue() << MAP_PRECISION;
+                        nSumRowG += aCol0.GetGreen() << MAP_PRECISION;
+                        nSumRowR += aCol0.GetRed() << MAP_PRECISION;
+                        nTotalWeightX += lclMaxWeight();
                     }
                     else if( j == 0 )
                     {
 
-                        long nWeightX = nMax- rCtx.mpMapFX[ nLeft ];
+                        BilinearWeightType nWeightX = lclMaxWeight() - 
rCtx.maMapFX[ nLeft ];
                         nSumRowB += ( nWeightX *aCol0.GetBlue()) ;
                         nSumRowG += ( nWeightX *aCol0.GetGreen()) ;
                         nSumRowR += ( nWeightX *aCol0.GetRed()) ;
@@ -703,7 +719,7 @@ void scalePalleteGeneral2(ScaleContext &rCtx, long nStartY, 
long nEndY)
                     else if ( nRowRange == j )
                     {
 
-                        long nWeightX = rCtx.mpMapFX[ nRight ] ;
+                        BilinearWeightType nWeightX = rCtx.maMapFX[ nRight ] ;
                         nSumRowB += ( nWeightX *aCol0.GetBlue() );
                         nSumRowG += ( nWeightX *aCol0.GetGreen() );
                         nSumRowR += ( nWeightX *aCol0.GetRed() );
@@ -712,22 +728,22 @@ void scalePalleteGeneral2(ScaleContext &rCtx, long 
nStartY, long nEndY)
                     else
                     {
 
-                        nSumRowB += aCol0.GetBlue() << 7;
-                        nSumRowG += aCol0.GetGreen() << 7;
-                        nSumRowR += aCol0.GetRed() << 7;
-                        nTotalWeightX += 1 << 7;
+                        nSumRowB += aCol0.GetBlue() << MAP_PRECISION;
+                        nSumRowG += aCol0.GetGreen() << MAP_PRECISION;
+                        nSumRowR += aCol0.GetRed() << MAP_PRECISION;
+                        nTotalWeightX += lclMaxWeight();
                     }
                 }
 
-                long nWeightY = nMax;
+                long nWeightY = lclMaxWeight();
                 if( nY == nEndY )
-                    nWeightY = nMax;
+                    nWeightY = lclMaxWeight();
                 else if( i == 0 )
-                    nWeightY = nMax - rCtx.mpMapFY[ nTop ];
+                    nWeightY = lclMaxWeight() - rCtx.maMapFY[ nTop ];
                 else if( nLineRange == 1 )
-                    nWeightY = rCtx.mpMapFY[ nTop ];
+                    nWeightY = rCtx.maMapFY[ nTop ];
                 else if ( nLineRange == i )
-                    nWeightY = rCtx.mpMapFY[ nBottom ];
+                    nWeightY = rCtx.maMapFY[ nBottom ];
 
                 if (nTotalWeightX)
                 {
@@ -758,7 +774,6 @@ void scalePalleteGeneral2(ScaleContext &rCtx, long nStartY, 
long nEndY)
 void scale24bitBGR2(ScaleContext &rCtx, long nStartY, long nEndY)
 {
     const long nStartX = 0, nEndX = rCtx.mnDestW - 1;
-    const long nMax = 1 << 7;
 
     for( long nY = nStartY; nY <= nEndY; nY++ )
     {
@@ -769,13 +784,13 @@ void scale24bitBGR2(ScaleContext &rCtx, long nStartY, 
long nEndY)
         long nLineRange;
         if( nY ==nEndY )
         {
-            nLineStart = rCtx.mpMapIY[ nY ];
+            nLineStart = rCtx.maMapIY[ nY ];
             nLineRange = 0;
         }
         else
         {
-            nLineStart = rCtx.mpMapIY[ nTop ] ;
-            nLineRange = ( rCtx.mpMapIY[ nBottom ] == rCtx.mpMapIY[ nTop ] ) ? 
1 :( rCtx.mpMapIY[ nBottom ] - rCtx.mpMapIY[ nTop ] );
+            nLineStart = rCtx.maMapIY[ nTop ] ;
+            nLineRange = ( rCtx.maMapIY[ nBottom ] == rCtx.maMapIY[ nTop ] ) ? 
1 :( rCtx.maMapIY[ nBottom ] - rCtx.maMapIY[ nTop ] );
         }
 
         Scanline pScanDest = rCtx.mpDest->GetScanline( nY );
@@ -788,19 +803,19 @@ void scale24bitBGR2(ScaleContext &rCtx, long nStartY, 
long nEndY)
             long nRowRange;
             if( nX == nEndX )
             {
-                nRowStart = rCtx.mpMapIX[ nX ];
+                nRowStart = rCtx.maMapIX[ nX ];
                 nRowRange = 0;
             }
             else
             {
-                nRowStart = rCtx.mpMapIX[ nLeft ];
-                nRowRange = ( rCtx.mpMapIX[ nRight ] == rCtx.mpMapIX[ nLeft ] 
)? 1 : ( rCtx.mpMapIX[ nRight ] - rCtx.mpMapIX[ nLeft ] );
+                nRowStart = rCtx.maMapIX[ nLeft ];
+                nRowRange = ( rCtx.maMapIX[ nRight ] == rCtx.maMapIX[ nLeft ] 
)? 1 : ( rCtx.maMapIX[ nRight ] - rCtx.maMapIX[ nLeft ] );
             }
 
             long nSumR = 0;
             long nSumG = 0;
             long nSumB = 0;
-            long nTotalWeightY = 0;
+            BilinearWeightType nTotalWeightY = 0;
 
             for(long i = 0; i<= nLineRange; i++)
             {
@@ -809,20 +824,20 @@ void scale24bitBGR2(ScaleContext &rCtx, long nStartY, 
long nEndY)
                 long nSumRowR = 0;
                 long nSumRowG = 0;
                 long nSumRowB = 0;
-                long nTotalWeightX = 0;
+                BilinearWeightType nTotalWeightX = 0;
 
                 for(long j = 0; j <= nRowRange; j++)
                 {
                     if(nX == nEndX )
                     {
-                        nSumRowB += ( *pTmpX ) << 7;pTmpX++;
-                        nSumRowG += ( *pTmpX ) << 7;pTmpX++;
-                        nSumRowR += ( *pTmpX ) << 7;pTmpX++;
-                        nTotalWeightX += 1 << 7;
+                        nSumRowB += ( *pTmpX ) << MAP_PRECISION; pTmpX++;
+                        nSumRowG += ( *pTmpX ) << MAP_PRECISION; pTmpX++;
+                        nSumRowR += ( *pTmpX ) << MAP_PRECISION; pTmpX++;
+                        nTotalWeightX += lclMaxWeight();
                     }
                     else if( j == 0 )
                     {
-                        long nWeightX = nMax- rCtx.mpMapFX[ nLeft ];
+                        BilinearWeightType nWeightX = lclMaxWeight() - 
rCtx.maMapFX[ nLeft ];
                         nSumRowB += ( nWeightX *( *pTmpX )) ;pTmpX++;
                         nSumRowG += ( nWeightX *( *pTmpX )) ;pTmpX++;
                         nSumRowR += ( nWeightX *( *pTmpX )) ;pTmpX++;
@@ -830,7 +845,7 @@ void scale24bitBGR2(ScaleContext &rCtx, long nStartY, long 
nEndY)
                     }
                     else if ( nRowRange == j )
                     {
-                        long nWeightX = rCtx.mpMapFX[ nRight ] ;
+                        BilinearWeightType nWeightX = rCtx.maMapFX[ nRight ] ;
                         nSumRowB += ( nWeightX *( *pTmpX ) );pTmpX++;
                         nSumRowG += ( nWeightX *( *pTmpX ) );pTmpX++;
                         nSumRowR += ( nWeightX *( *pTmpX ) );pTmpX++;
@@ -838,22 +853,22 @@ void scale24bitBGR2(ScaleContext &rCtx, long nStartY, 
long nEndY)
                     }
                     else
                     {
-                        nSumRowB += ( *pTmpX ) << 7;pTmpX++;
-                        nSumRowG += ( *pTmpX ) << 7;pTmpX++;
-                        nSumRowR += ( *pTmpX ) << 7;pTmpX++;
-                        nTotalWeightX += 1 << 7;
+                        nSumRowB += ( *pTmpX ) << MAP_PRECISION; pTmpX++;
+                        nSumRowG += ( *pTmpX ) << MAP_PRECISION; pTmpX++;
+                        nSumRowR += ( *pTmpX ) << MAP_PRECISION; pTmpX++;
+                        nTotalWeightX += lclMaxWeight();
                     }
                 }
 
-                long nWeightY = nMax;
+                BilinearWeightType nWeightY = lclMaxWeight();
                 if( nY == nEndY )
-                    nWeightY = nMax;
+                    nWeightY = lclMaxWeight();
                 else if( i == 0 )
-                    nWeightY = nMax - rCtx.mpMapFY[ nTop ];
+                    nWeightY = lclMaxWeight() - rCtx.maMapFY[ nTop ];
                 else if( nLineRange == 1 )
-                    nWeightY = rCtx.mpMapFY[ nTop ];
+                    nWeightY = rCtx.maMapFY[ nTop ];
                 else if ( nLineRange == i )
-                    nWeightY = rCtx.mpMapFY[ nBottom ];
+                    nWeightY = rCtx.maMapFY[ nBottom ];
 
                 if (nTotalWeightX)
                 {
@@ -882,7 +897,6 @@ void scale24bitBGR2(ScaleContext &rCtx, long nStartY, long 
nEndY)
 void scale24bitRGB2(ScaleContext &rCtx, long nStartY, long nEndY)
 {
     const long nStartX = 0, nEndX = rCtx.mnDestW - 1;
-    const long nMax = 1 << 7;
 
     for( long nY = nStartY; nY <= nEndY; nY++ )
     {
@@ -892,13 +906,13 @@ void scale24bitRGB2(ScaleContext &rCtx, long nStartY, 
long nEndY)
         long nLineStart, nLineRange;
         if( nY ==nEndY )
         {
-            nLineStart = rCtx.mpMapIY[ nY ];
+            nLineStart = rCtx.maMapIY[ nY ];
             nLineRange = 0;
         }
         else
         {
-            nLineStart = rCtx.mpMapIY[ nTop ] ;
-            nLineRange = ( rCtx.mpMapIY[ nBottom ] == rCtx.mpMapIY[ nTop ] ) ? 
1 :( rCtx.mpMapIY[ nBottom ] - rCtx.mpMapIY[ nTop ] );
+            nLineStart = rCtx.maMapIY[ nTop ] ;
+            nLineRange = ( rCtx.maMapIY[ nBottom ] == rCtx.maMapIY[ nTop ] ) ? 
1 :( rCtx.maMapIY[ nBottom ] - rCtx.maMapIY[ nTop ] );
         }
 
         Scanline pScanDest = rCtx.mpDest->GetScanline( nY );
@@ -910,19 +924,19 @@ void scale24bitRGB2(ScaleContext &rCtx, long nStartY, 
long nEndY)
             long nRowStart, nRowRange;
             if( nX == nEndX )
             {
-                nRowStart = rCtx.mpMapIX[ nX ];
+                nRowStart = rCtx.maMapIX[ nX ];
                 nRowRange = 0;
             }
             else
             {
-                nRowStart = rCtx.mpMapIX[ nLeft ];
-                nRowRange = ( rCtx.mpMapIX[ nRight ] == rCtx.mpMapIX[ nLeft ] 
)? 1 : ( rCtx.mpMapIX[ nRight ] - rCtx.mpMapIX[ nLeft ] );
+                nRowStart = rCtx.maMapIX[ nLeft ];
+                nRowRange = ( rCtx.maMapIX[ nRight ] == rCtx.maMapIX[ nLeft ] 
)? 1 : ( rCtx.maMapIX[ nRight ] - rCtx.maMapIX[ nLeft ] );
             }
 
             long nSumR = 0;
             long nSumG = 0;
             long nSumB = 0;
-            long nTotalWeightY = 0;
+            BilinearWeightType nTotalWeightY = 0;
 
             for(long i = 0; i<= nLineRange; i++)
             {
@@ -931,20 +945,20 @@ void scale24bitRGB2(ScaleContext &rCtx, long nStartY, 
long nEndY)
                 long nSumRowR = 0;
                 long nSumRowG = 0;
                 long nSumRowB = 0;
-                long nTotalWeightX = 0;
+                BilinearWeightType nTotalWeightX = 0;
 
                 for(long j = 0; j <= nRowRange; j++)
                 {
                     if(nX == nEndX )
                     {
-                        nSumRowR += ( *pTmpX ) << 7;pTmpX++;
-                        nSumRowG += ( *pTmpX ) << 7;pTmpX++;
-                        nSumRowB += ( *pTmpX ) << 7;pTmpX++;
-                        nTotalWeightX += 1 << 7;
+                        nSumRowR += ( *pTmpX ) << MAP_PRECISION; pTmpX++;
+                        nSumRowG += ( *pTmpX ) << MAP_PRECISION; pTmpX++;
+                        nSumRowB += ( *pTmpX ) << MAP_PRECISION; pTmpX++;
+                        nTotalWeightX += lclMaxWeight();
                     }
                     else if( j == 0 )
                     {
-                        long nWeightX = nMax- rCtx.mpMapFX[ nLeft ];
+                        BilinearWeightType nWeightX = lclMaxWeight() - 
rCtx.maMapFX[ nLeft ];
                         nSumRowR += ( nWeightX *( *pTmpX )) ;pTmpX++;
                         nSumRowG += ( nWeightX *( *pTmpX )) ;pTmpX++;
                         nSumRowB += ( nWeightX *( *pTmpX )) ;pTmpX++;
@@ -952,7 +966,7 @@ void scale24bitRGB2(ScaleContext &rCtx, long nStartY, long 
nEndY)
                     }
                     else if ( nRowRange == j )
                     {
-                        long nWeightX = rCtx.mpMapFX[ nRight ] ;
+                        BilinearWeightType nWeightX = rCtx.maMapFX[ nRight ] ;
                         nSumRowR += ( nWeightX *( *pTmpX ) );pTmpX++;
                         nSumRowG += ( nWeightX *( *pTmpX ) );pTmpX++;
                         nSumRowB += ( nWeightX *( *pTmpX ) );pTmpX++;
@@ -960,22 +974,22 @@ void scale24bitRGB2(ScaleContext &rCtx, long nStartY, 
long nEndY)
                     }
                     else
                     {
-                        nSumRowR += ( *pTmpX ) << 7;pTmpX++;
-                        nSumRowG += ( *pTmpX ) << 7;pTmpX++;
-                        nSumRowB += ( *pTmpX ) << 7;pTmpX++;
-                        nTotalWeightX += 1 << 7;
+                        nSumRowR += ( *pTmpX ) << MAP_PRECISION; pTmpX++;
+                        nSumRowG += ( *pTmpX ) << MAP_PRECISION; pTmpX++;
+                        nSumRowB += ( *pTmpX ) << MAP_PRECISION; pTmpX++;
+                        nTotalWeightX += lclMaxWeight();
                     }
                 }
 
-                long nWeightY = nMax;
+                BilinearWeightType nWeightY = lclMaxWeight();
                 if( nY == nEndY )
-                    nWeightY = nMax;
+                    nWeightY = lclMaxWeight();
                 else if( i == 0 )
-                    nWeightY = nMax - rCtx.mpMapFY[ nTop ];
+                    nWeightY = lclMaxWeight() - rCtx.maMapFY[ nTop ];
                 else if( nLineRange == 1 )
-                    nWeightY = rCtx.mpMapFY[ nTop ];
+                    nWeightY = rCtx.maMapFY[ nTop ];
                 else if ( nLineRange == i )
-                    nWeightY = rCtx.mpMapFY[ nBottom ];
+                    nWeightY = rCtx.maMapFY[ nBottom ];
 
                 if (nTotalWeightX)
                 {
@@ -1004,7 +1018,6 @@ void scale24bitRGB2(ScaleContext &rCtx, long nStartY, 
long nEndY)
 void scaleNonPalleteGeneral2(ScaleContext &rCtx, long nStartY, long nEndY)
 {
     const long nStartX = 0, nEndX = rCtx.mnDestW - 1;
-    const long nMax = 1 << 7;
 
     for( long nY = nStartY; nY <= nEndY; nY++ )
     {
@@ -1014,13 +1027,13 @@ void scaleNonPalleteGeneral2(ScaleContext &rCtx, long 
nStartY, long nEndY)
         long nLineStart, nLineRange;
         if( nY ==nEndY )
         {
-            nLineStart = rCtx.mpMapIY[ nY ];
+            nLineStart = rCtx.maMapIY[ nY ];
             nLineRange = 0;
         }
         else
         {
-            nLineStart = rCtx.mpMapIY[ nTop ] ;
-            nLineRange = ( rCtx.mpMapIY[ nBottom ] == rCtx.mpMapIY[ nTop ] ) ? 
1 :( rCtx.mpMapIY[ nBottom ] - rCtx.mpMapIY[ nTop ] );
+            nLineStart = rCtx.maMapIY[ nTop ] ;
+            nLineRange = ( rCtx.maMapIY[ nBottom ] == rCtx.maMapIY[ nTop ] ) ? 
1 :( rCtx.maMapIY[ nBottom ] - rCtx.maMapIY[ nTop ] );
         }
 
         Scanline pScanDest = rCtx.mpDest->GetScanline( nY );
@@ -1032,26 +1045,26 @@ void scaleNonPalleteGeneral2(ScaleContext &rCtx, long 
nStartY, long nEndY)
             long nRowStart, nRowRange;
             if( nX == nEndX )
             {
-                nRowStart = rCtx.mpMapIX[ nX ];
+                nRowStart = rCtx.maMapIX[ nX ];
                 nRowRange = 0;
             }
             else
             {
-                nRowStart = rCtx.mpMapIX[ nLeft ];
-                nRowRange = ( rCtx.mpMapIX[ nRight ] == rCtx.mpMapIX[ nLeft ] 
)? 1 : ( rCtx.mpMapIX[ nRight ] - rCtx.mpMapIX[ nLeft ] );
+                nRowStart = rCtx.maMapIX[ nLeft ];
+                nRowRange = ( rCtx.maMapIX[ nRight ] == rCtx.maMapIX[ nLeft ] 
)? 1 : ( rCtx.maMapIX[ nRight ] - rCtx.maMapIX[ nLeft ] );
             }
 
             long nSumR = 0;
             long nSumG = 0;
             long nSumB = 0;
-            long nTotalWeightY = 0;
+            BilinearWeightType nTotalWeightY = 0;
 
             for(long i = 0; i<= nLineRange; i++)
             {
                 long nSumRowR = 0;
                 long nSumRowG = 0;
                 long nSumRowB = 0;
-                long nTotalWeightX = 0;
+                BilinearWeightType nTotalWeightX = 0;
 
                 Scanline pScanlineSrc = rCtx.mpSrc->GetScanline( nLineStart + 
i );
                 for(long j = 0; j <= nRowRange; j++)
@@ -1061,15 +1074,15 @@ void scaleNonPalleteGeneral2(ScaleContext &rCtx, long 
nStartY, long nEndY)
                     if(nX == nEndX )
                     {
 
-                        nSumRowB += aCol0.GetBlue() << 7;
-                        nSumRowG += aCol0.GetGreen() << 7;
-                        nSumRowR += aCol0.GetRed() << 7;
-                        nTotalWeightX += 1 << 7;
+                        nSumRowB += aCol0.GetBlue() << MAP_PRECISION;
+                        nSumRowG += aCol0.GetGreen() << MAP_PRECISION;
+                        nSumRowR += aCol0.GetRed() << MAP_PRECISION;
+                        nTotalWeightX += lclMaxWeight();
                     }
                     else if( j == 0 )
                     {
 
-                        long nWeightX = nMax- rCtx.mpMapFX[ nLeft ];
+                        BilinearWeightType nWeightX = lclMaxWeight() - 
rCtx.maMapFX[ nLeft ];
                         nSumRowB += ( nWeightX *aCol0.GetBlue()) ;
                         nSumRowG += ( nWeightX *aCol0.GetGreen()) ;
                         nSumRowR += ( nWeightX *aCol0.GetRed()) ;
@@ -1078,7 +1091,7 @@ void scaleNonPalleteGeneral2(ScaleContext &rCtx, long 
nStartY, long nEndY)
                     else if ( nRowRange == j )
                     {
 
-                        long nWeightX = rCtx.mpMapFX[ nRight ] ;
+                        BilinearWeightType nWeightX = rCtx.maMapFX[ nRight ] ;
                         nSumRowB += ( nWeightX *aCol0.GetBlue() );
                         nSumRowG += ( nWeightX *aCol0.GetGreen() );
                         nSumRowR += ( nWeightX *aCol0.GetRed() );
@@ -1086,22 +1099,22 @@ void scaleNonPalleteGeneral2(ScaleContext &rCtx, long 
nStartY, long nEndY)
                     }
                     else
                     {
-                        nSumRowB += aCol0.GetBlue() << 7;
-                        nSumRowG += aCol0.GetGreen() << 7;
-                        nSumRowR += aCol0.GetRed() << 7;
-                        nTotalWeightX += 1 << 7;
+                        nSumRowB += aCol0.GetBlue() << MAP_PRECISION;
+                        nSumRowG += aCol0.GetGreen() << MAP_PRECISION;
+                        nSumRowR += aCol0.GetRed() << MAP_PRECISION;
+                        nTotalWeightX += lclMaxWeight();
                     }
                 }
 
-                long nWeightY = nMax;
+                BilinearWeightType nWeightY = lclMaxWeight();
                 if( nY == nEndY )
-                    nWeightY = nMax;
+                    nWeightY = lclMaxWeight();
                 else if( i == 0 )
-                    nWeightY = nMax - rCtx.mpMapFY[ nTop ];
+                    nWeightY = lclMaxWeight() - rCtx.maMapFY[ nTop ];
                 else if( nLineRange == 1 )
-                    nWeightY = rCtx.mpMapFY[ nTop ];
+                    nWeightY = rCtx.maMapFY[ nTop ];
                 else if ( nLineRange == i )
-                    nWeightY = rCtx.mpMapFY[ nBottom ];
+                    nWeightY = rCtx.maMapFY[ nBottom ];
 
                 if (nTotalWeightX)
                 {
_______________________________________________
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits

Reply via email to