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

Tomaž Vajngerl tvajngerl at kemper.freedesktop.org
Tue Aug 14 11:43:38 PDT 2012


 svtools/source/graphic/grfmgr2.cxx |   60 +++++------
 vcl/inc/vcl/alpha.hxx              |  187 ++++++++++++++++++-------------------
 vcl/source/gdi/alpha.cxx           |   57 ++++++-----
 vcl/source/gdi/bitmap3.cxx         |    6 -
 vcl/source/gdi/bitmapex.cxx        |   53 ++++++----
 5 files changed, 191 insertions(+), 172 deletions(-)

New commits:
commit 42801a0e690a63c3a94b1d8256b6c7cd64856bd2
Author: Tomaž Vajngerl <quikee at gmail.com>
Date:   Tue Aug 14 20:39:14 2012 +0200

    Fix transparent bitmap rendering.
    
    Convert transparent mask to 8bit-grey after scale/rotate/crop
    transformation. Use correct perspective at rendering.
    
    Change-Id: I80b19d7bec880b0c58709c7c5bee6199cbc815c9

diff --git a/svtools/source/graphic/grfmgr2.cxx b/svtools/source/graphic/grfmgr2.cxx
index dc6c3c7..f738998 100644
--- a/svtools/source/graphic/grfmgr2.cxx
+++ b/svtools/source/graphic/grfmgr2.cxx
@@ -270,43 +270,43 @@ sal_Bool GraphicManager::ImplCreateOutput( OutputDevice* pOutputDevice,
                                        const sal_uLong nFlags, BitmapEx* pResultBitmapEx )
 {
     bool        bRet = false;
-    Point       aOutPointInPixels;
-    Size        aOutSizeInPixels;
-    int         nRotation = rAttributes.GetRotation() % 3600;
 
     Point       aUnrotatedPointInPixels( pOutputDevice->LogicToPixel( rPoint ) );
     Size        aUnrotatedSizeInPixels(  pOutputDevice->LogicToPixel( rSize ) );
 
-    BitmapEx    aBitmapEx( rBitmapEx );
-
-    if( !aUnrotatedSizeInPixels.Width() || !aUnrotatedSizeInPixels.Height() )
+    if( aUnrotatedSizeInPixels.Width() <= 0  || aUnrotatedSizeInPixels.Height() <= 0)
         return false;
 
-    if( nRotation )
+    Point       aOutPointInPixels;
+    Size        aOutSizeInPixels;
+    BitmapEx    aBitmapEx( rBitmapEx );
+    int         nRotation = rAttributes.GetRotation() % 3600;
+
+    if( nRotation != 0 )
     {
         Polygon aPoly( Rectangle( rPoint, rSize ) );
         aPoly.Rotate( rPoint, nRotation );
         const Rectangle aRotationBoundRect( aPoly.GetBoundRect() );
         aOutPointInPixels = pOutputDevice->LogicToPixel( aRotationBoundRect.TopLeft() );
-        aOutSizeInPixels = pOutputDevice->LogicToPixel( aRotationBoundRect.GetSize() );
+        aOutSizeInPixels  = pOutputDevice->LogicToPixel( aRotationBoundRect.GetSize() );
     }
     else
     {
         aOutPointInPixels = aUnrotatedPointInPixels;
-        aOutSizeInPixels = aUnrotatedSizeInPixels;
+        aOutSizeInPixels  = aUnrotatedSizeInPixels;
     }
 
     Point       aOutPoint;
     Size        aOutSize;
 
     const Size& rBitmapSizePixels = rBitmapEx.GetSizePixel();
-    Rectangle   aCropRectangle(-1, -1, -1, -1);
+    Rectangle   aCropRectangle(0, 0, 0, 0);
+
     bool        isHorizontalMirrored = ( rAttributes.GetMirrorFlags() & BMP_MIRROR_HORZ ) != 0;
     bool        isVerticalMirrored   = ( rAttributes.GetMirrorFlags() & BMP_MIRROR_VERT ) != 0;
 
-
     // calculate output sizes
-    if( !pResultBitmapEx )
+    if( true || !pResultBitmapEx )
     {
         Rectangle aBitmapRectangle( aOutPointInPixels, aOutSizeInPixels );
         Rectangle aOutRect( Point(), pOutputDevice->GetOutputSizePixel() );
@@ -316,9 +316,7 @@ sal_Bool GraphicManager::ImplCreateOutput( OutputDevice* pOutputDevice,
             const Region aPaintRegion( ( (Window*) pOutputDevice )->GetPaintRegion() );
 
             if( !aPaintRegion.IsNull() )
-            {
                 aOutRect.Intersection( pOutputDevice->LogicToPixel( aPaintRegion.GetBoundRect() ) );
-            }
         }
         aOutRect.Intersection( aBitmapRectangle );
 
@@ -346,31 +344,28 @@ sal_Bool GraphicManager::ImplCreateOutput( OutputDevice* pOutputDevice,
     }
 
 
-    if( aCropRectangle.GetWidth() <= 0 && aCropRectangle.GetHeight() <= 0)
+    if( aCropRectangle.GetWidth() <= 0 && aCropRectangle.GetHeight() <= 0 )
         return false;
 
     // do transformation
-
     if( !isHorizontalMirrored &&
         !isVerticalMirrored &&
         !nRotation &&
         aOutSizeInPixels == rBitmapSizePixels)
     {
+        // simple copy thorugh
         aOutPoint = pOutputDevice->PixelToLogic( aOutPointInPixels );
         aOutSize = pOutputDevice->PixelToLogic( aOutSizeInPixels );
         bRet = true;
     }
     else
     {
-        // calculate scaling factors
-        double fScaleX = aUnrotatedSizeInPixels.Width()  / (double) rBitmapSizePixels.Width();
-        double fScaleY = aUnrotatedSizeInPixels.Height() / (double) rBitmapSizePixels.Height();
-
         // mirror the image - this should not impact the picture dimenstions
         if( isHorizontalMirrored || isVerticalMirrored )
             bRet = aBitmapEx.Mirror( rAttributes.GetMirrorFlags() );
 
-        if (nRotation)
+        // prepare rotation if needed
+        if (nRotation != 0)
         {
             Polygon aPoly( Rectangle( Point(), aUnrotatedSizeInPixels) );
             aPoly.Rotate( Point(), nRotation );
@@ -382,7 +377,12 @@ sal_Bool GraphicManager::ImplCreateOutput( OutputDevice* pOutputDevice,
                                 aCropRectangle.Right()  + aNewBound.Left(),
                                 aCropRectangle.Bottom() + aNewBound.Top() );
         }
-        if( nFlags & GRFMGR_DRAW_SMOOTHSCALE)
+
+        // calculate scaling factors
+        double fScaleX = aUnrotatedSizeInPixels.Width()  / (double) rBitmapSizePixels.Width();
+        double fScaleY = aUnrotatedSizeInPixels.Height() / (double) rBitmapSizePixels.Height();
+
+        if( nFlags & GRFMGR_DRAW_SMOOTHSCALE )
         {
             bRet = aBitmapEx.ScaleCropRotate( fScaleX, fScaleY, aCropRectangle, nRotation, COL_TRANSPARENT );
         }
@@ -390,12 +390,12 @@ sal_Bool GraphicManager::ImplCreateOutput( OutputDevice* pOutputDevice,
         {
             aCropRectangle = Rectangle (
                                 aCropRectangle.Left()   / fScaleX,
-                                aCropRectangle.Right()  / fScaleX,
                                 aCropRectangle.Top()    / fScaleY,
+                                aCropRectangle.Right()  / fScaleX,
                                 aCropRectangle.Bottom() / fScaleY );
 
             bRet = aBitmapEx.Crop( aCropRectangle );
-            if (bRet)
+            if ( bRet )
                 bRet = aBitmapEx.Scale( fScaleX, fScaleY );
         }
     }
@@ -403,17 +403,17 @@ sal_Bool GraphicManager::ImplCreateOutput( OutputDevice* pOutputDevice,
     if( bRet )
     {
         // attribute adjustment if neccessary
-        if(     rAttributes.IsSpecialDrawMode()
-          ||    rAttributes.IsAdjusted()
-          ||    rAttributes.IsTransparent() )
+        if(  rAttributes.IsSpecialDrawMode()
+          || rAttributes.IsAdjusted()
+          || rAttributes.IsTransparent() )
         {
             ImplAdjust( aBitmapEx, rAttributes, ADJUSTMENT_DRAWMODE | ADJUSTMENT_COLORS | ADJUSTMENT_TRANSPARENCY );
         }
 
         // OutDev adjustment if neccessary
-        if(     pOutputDevice->GetOutDevType() != OUTDEV_PRINTER
-            &&  pOutputDevice->GetBitCount() <= 8
-            &&  aBitmapEx.GetBitCount() >= 8 )
+        if(   pOutputDevice->GetOutDevType() != OUTDEV_PRINTER
+          &&  pOutputDevice->GetBitCount() <= 8
+          &&  aBitmapEx.GetBitCount() >= 8 )
         {
             aBitmapEx.Dither( BMP_DITHER_MATRIX );
         }
diff --git a/vcl/inc/vcl/alpha.hxx b/vcl/inc/vcl/alpha.hxx
index 45eed35..d0ceb92 100644
--- a/vcl/inc/vcl/alpha.hxx
+++ b/vcl/inc/vcl/alpha.hxx
@@ -52,104 +52,107 @@ private:
 
 public:
 
-                            AlphaMask();
-                            AlphaMask( const Bitmap& rBitmap );
-                            AlphaMask( const AlphaMask& rAlphaMask );
-                            AlphaMask( const Size& rSizePixel, sal_uInt8* pEraseTransparency = NULL );
-                            ~AlphaMask();
-
-    AlphaMask&              operator=( const Bitmap& rBitmap );
-    AlphaMask&              operator=( const AlphaMask& rAlphaMask )
-                            {
-                                return (AlphaMask&) Bitmap::operator=( rAlphaMask );
-                            }
-    sal_Bool                operator!() const
-                            {
-                                return Bitmap::operator!();
-                            }
-    sal_Bool                operator==( const AlphaMask& rAlphaMask ) const
-                            {
-                                return Bitmap::operator==( rAlphaMask );
-                            }
-    sal_Bool                operator!=( const AlphaMask& rAlphaMask ) const
-                            {
-                                return Bitmap::operator!=( rAlphaMask );
-                            }
-
-    const MapMode&          GetPrefMapMode() const
-                            {
-                                return Bitmap::GetPrefMapMode();
-                            }
-    void                    SetPrefMapMode( const MapMode& rMapMode )
-                            {
-                                Bitmap::SetPrefMapMode( rMapMode );
-                            }
-
-    const Size&             GetPrefSize() const
-                            {
-                                return Bitmap::GetPrefSize();
-                            }
-    void                    SetPrefSize( const Size& rSize )
-                            {
-                                Bitmap::SetPrefSize( rSize );
-                            }
-
-    Size                    GetSizePixel() const
-                            {
-                                return Bitmap::GetSizePixel();
-                            }
-
-    sal_uLong               GetSizeBytes() const
-                            {
-                                return Bitmap::GetSizeBytes();
-                            }
-    sal_uLong               GetChecksum() const
-                            {
-                                return Bitmap::GetChecksum();
-                            }
-
-    Bitmap                  GetBitmap() const;
-
-    sal_Bool                CopyPixel(
-                                const Rectangle& rRectDst,
-                                const Rectangle& rRectSrc,
-                                const AlphaMask* pAlphaSrc = NULL
-                            );
-    sal_Bool                Erase( sal_uInt8 cTransparency );
-    sal_Bool                Replace( const Bitmap& rMask, sal_uInt8 rReplaceTransparency );
-    sal_Bool                Replace(
-                                sal_uInt8 cSearchTransparency,
-                                sal_uInt8 cReplaceTransparency,
-                                sal_uLong nTol = 0UL
-                            );
-
-    BitmapReadAccess*       AcquireReadAccess()
-                            {
-                                return Bitmap::AcquireReadAccess();
-                            }
-    BitmapWriteAccess*      AcquireWriteAccess()
-                            {
-                                return Bitmap::AcquireWriteAccess();
-                            }
-    void                    ReleaseAccess( BitmapReadAccess* pAccess );
+    AlphaMask();
+    AlphaMask( const Bitmap& rBitmap );
+    AlphaMask( const AlphaMask& rAlphaMask );
+    AlphaMask( const Size& rSizePixel, sal_uInt8* pEraseTransparency = NULL );
+    ~AlphaMask();
+
+    AlphaMask&  operator=( const Bitmap& rBitmap );
+    AlphaMask&  operator=( const AlphaMask& rAlphaMask )
+    {
+        return (AlphaMask&) Bitmap::operator=( rAlphaMask );
+    }
+
+    sal_Bool operator!() const
+    {
+        return Bitmap::operator!();
+    }
+
+    sal_Bool operator==( const AlphaMask& rAlphaMask ) const
+    {
+        return Bitmap::operator==( rAlphaMask );
+    }
+
+    sal_Bool operator!=( const AlphaMask& rAlphaMask ) const
+    {
+        return Bitmap::operator!=( rAlphaMask );
+    }
+
+    const MapMode&  GetPrefMapMode() const
+    {
+        return Bitmap::GetPrefMapMode();
+    }
+
+    void    SetPrefMapMode( const MapMode& rMapMode )
+    {
+        Bitmap::SetPrefMapMode( rMapMode );
+    }
+
+    const Size& GetPrefSize() const
+    {
+        return Bitmap::GetPrefSize();
+    }
+
+    void    SetPrefSize( const Size& rSize )
+    {
+        Bitmap::SetPrefSize( rSize );
+    }
+
+    Size    GetSizePixel() const
+    {
+        return Bitmap::GetSizePixel();
+    }
+
+    sal_uLong   GetSizeBytes() const
+    {
+        return Bitmap::GetSizeBytes();
+    }
+    sal_uLong   GetChecksum() const
+    {
+        return Bitmap::GetChecksum();
+    }
+
+    Bitmap  GetBitmap() const;
+
+    sal_Bool    CopyPixel( const Rectangle& rRectDst, const Rectangle& rRectSrc,
+                           const AlphaMask* pAlphaSrc = NULL);
+
+    sal_Bool    Erase( sal_uInt8 cTransparency );
+    sal_Bool    Replace( const Bitmap& rMask, sal_uInt8 rReplaceTransparency );
+    sal_Bool    Replace( sal_uInt8 cSearchTransparency, sal_uInt8 cReplaceTransparency,
+                         sal_uLong nTol = 0UL );
+
+    sal_Bool Scale( const Size& rNewSize, sal_uLong nScaleFlag );
+    sal_Bool Scale( const double& rScaleX, const double& rScaleY, sal_uLong nScaleFlag = BMP_SCALE_DEFAULT );
+    sal_Bool ScaleCropRotate( const double& rScaleX, const double& rScaleY, const Rectangle& rRectPixel, long nAngle10,
+                              const Color& rFillColor, sal_uLong nScaleFlag = BMP_SCALE_DEFAULT );
+
+    BitmapReadAccess*   AcquireReadAccess()
+    {
+        return Bitmap::AcquireReadAccess();
+    }
+
+    BitmapWriteAccess*  AcquireWriteAccess()
+    {
+        return Bitmap::AcquireWriteAccess();
+    }
+
+    void    ReleaseAccess( BitmapReadAccess* pAccess );
 
     typedef vcl::ScopedBitmapAccess< BitmapReadAccess, AlphaMask, &AlphaMask::AcquireReadAccess >
         ScopedReadAccess;
     typedef vcl::ScopedBitmapAccess< BitmapWriteAccess, AlphaMask, &AlphaMask::AcquireWriteAccess >
         ScopedWriteAccess;
 
-    sal_Bool                Read( SvStream& rIStm, sal_Bool bFileHeader = sal_True )
-                            {
-                                return Bitmap::Read( rIStm, bFileHeader );
-                            }
-    sal_Bool                Write(
-                                SvStream& rOStm,
-                                sal_Bool bCompressed = sal_True,
-                                sal_Bool bFileHeader = sal_True
-                            ) const
-                            {
-                                return Bitmap::Write( rOStm, bCompressed, bFileHeader );
-                            }
+    sal_Bool    Read( SvStream& rIStm, sal_Bool bFileHeader = sal_True )
+    {
+        return Bitmap::Read( rIStm, bFileHeader );
+    }
+    sal_Bool    Write( SvStream& rOStm, sal_Bool bCompressed = sal_True, sal_Bool bFileHeader = sal_True ) const
+    {
+        return Bitmap::Write( rOStm, bCompressed, bFileHeader );
+    }
 
     friend VCL_DLLPUBLIC SvStream& operator<<( SvStream& rOStm, const BitmapEx& rBitmapEx );
     friend VCL_DLLPUBLIC SvStream& operator>>( SvStream& rIStm, BitmapEx& rBitmapEx );
diff --git a/vcl/source/gdi/alpha.cxx b/vcl/source/gdi/alpha.cxx
index cbaf138..0c2ad36 100644
--- a/vcl/source/gdi/alpha.cxx
+++ b/vcl/source/gdi/alpha.cxx
@@ -39,8 +39,6 @@ AlphaMask::AlphaMask()
 {
 }
 
-// -----------------------------------------------------------------------------
-
 AlphaMask::AlphaMask( const Bitmap& rBitmap ) :
     Bitmap( rBitmap )
 {
@@ -48,15 +46,11 @@ AlphaMask::AlphaMask( const Bitmap& rBitmap ) :
         Bitmap::Convert( BMP_CONVERSION_8BIT_GREYS );
 }
 
-// -----------------------------------------------------------------------------
-
 AlphaMask::AlphaMask( const AlphaMask& rAlphaMask ) :
     Bitmap( rAlphaMask )
 {
 }
 
-// -----------------------------------------------------------------------------
-
 AlphaMask::AlphaMask( const Size& rSizePixel, sal_uInt8* pEraseTransparency ) :
     Bitmap( rSizePixel, 8, &Bitmap::GetGreyPalette( 256 ) )
 {
@@ -64,14 +58,10 @@ AlphaMask::AlphaMask( const Size& rSizePixel, sal_uInt8* pEraseTransparency ) :
         Bitmap::Erase( Color( *pEraseTransparency, *pEraseTransparency, *pEraseTransparency ) );
 }
 
-// -----------------------------------------------------------------------------
-
 AlphaMask::~AlphaMask()
 {
 }
 
-// -----------------------------------------------------------------------------
-
 AlphaMask& AlphaMask::operator=( const Bitmap& rBitmap )
 {
     *(Bitmap*) this = rBitmap;
@@ -82,30 +72,22 @@ AlphaMask& AlphaMask::operator=( const Bitmap& rBitmap )
     return *this;
 }
 
-// -----------------------------------------------------------------------------
-
 const Bitmap& AlphaMask::ImplGetBitmap() const
 {
     return( (const Bitmap&) *this );
 }
 
-// -----------------------------------------------------------------------------
-
 void AlphaMask::ImplSetBitmap( const Bitmap& rBitmap )
 {
     DBG_ASSERT( ( 8 == rBitmap.GetBitCount() ) && rBitmap.HasGreyPalette(), "AlphaMask::ImplSetBitmap: invalid bitmap" );
     *(Bitmap*) this = rBitmap;
 }
 
-// -----------------------------------------------------------------------------
-
 Bitmap AlphaMask::GetBitmap() const
 {
     return ImplGetBitmap();
 }
 
-// -----------------------------------------------------------------------------
-
 sal_Bool AlphaMask::CopyPixel( const Rectangle& rRectDst, const Rectangle& rRectSrc,
                            const AlphaMask* pAlphaSrc )
 {
@@ -215,15 +197,11 @@ sal_Bool AlphaMask::CopyPixel( const Rectangle& rRectDst, const Rectangle& rRect
 
 }
 
-// -----------------------------------------------------------------------------
-
 sal_Bool AlphaMask::Erase( sal_uInt8 cTransparency )
 {
     return Bitmap::Erase( Color( cTransparency, cTransparency, cTransparency ) );
 }
 
-// -----------------------------------------------------------------------------
-
 sal_Bool AlphaMask::Replace( const Bitmap& rMask, sal_uInt8 cReplaceTransparency )
 {
     BitmapReadAccess*   pMaskAcc = ( (Bitmap&) rMask ).AcquireReadAccess();
@@ -249,8 +227,6 @@ sal_Bool AlphaMask::Replace( const Bitmap& rMask, sal_uInt8 cReplaceTransparency
     return bRet;
 }
 
-// -----------------------------------------------------------------------------
-
 sal_Bool AlphaMask::Replace( sal_uInt8 cSearchTransparency, sal_uInt8 cReplaceTransparency, sal_uLong
 #ifdef DBG_UTIL
 nTol
@@ -302,8 +278,6 @@ nTol
     return bRet;
 }
 
-// -----------------------------------------------------------------------------
-
 void AlphaMask::ReleaseAccess( BitmapReadAccess* pAccess )
 {
     if( pAccess )
@@ -313,4 +287,35 @@ void AlphaMask::ReleaseAccess( BitmapReadAccess* pAccess )
     }
 }
 
+sal_Bool AlphaMask::Scale( const Size& rNewSize, sal_uLong nScaleFlag )
+{
+    sal_Bool bRet = Bitmap::Scale( rNewSize, nScaleFlag );
+
+    if( bRet )
+        Bitmap::Convert( BMP_CONVERSION_8BIT_GREYS );
+
+    return bRet;
+}
+
+sal_Bool AlphaMask::Scale( const double& rScaleX, const double& rScaleY, sal_uLong nScaleFlag )
+{
+    sal_Bool bRet = Bitmap::Scale( rScaleX, rScaleY, nScaleFlag );
+
+    if( bRet )
+        Bitmap::Convert( BMP_CONVERSION_8BIT_GREYS );
+
+    return bRet;
+}
+
+sal_Bool AlphaMask::ScaleCropRotate(
+        const double& rScaleX, const double& rScaleY, const Rectangle& rRectPixel, long nAngle10,
+        const Color& rFillColor, sal_uLong  nScaleFlag  )
+{
+    sal_Bool bRet = Bitmap::ScaleCropRotate( rScaleX, rScaleY, rRectPixel, nAngle10, rFillColor, nScaleFlag );
+    if( bRet )
+        Bitmap::Convert( BMP_CONVERSION_8BIT_GREYS );
+
+    return bRet;
+}
+
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/vcl/source/gdi/bitmap3.cxx b/vcl/source/gdi/bitmap3.cxx
index 1ce4253..a4900c6 100644
--- a/vcl/source/gdi/bitmap3.cxx
+++ b/vcl/source/gdi/bitmap3.cxx
@@ -2325,7 +2325,7 @@ sal_Bool Bitmap::ScaleCropRotate(
     }
     else
     {
-        bRet =  ImplTransformBilinearFiltering( rScaleX, rScaleY, rRectPixel, nAngle10, rFillColor);
+        bRet = ImplTransformBilinearFiltering( rScaleX, rScaleY, rRectPixel, nAngle10, rFillColor);
     }
 
     return bRet;
@@ -2384,9 +2384,9 @@ bool Bitmap::ImplTransformAveraging( const double& rScaleX, const double& rScale
             double unrotatedY = fSinAngle * x + fCosAngle * y;
 
             if (   unrotatedX < 0
-                || unrotatedX >= nScaledWidth
+                || unrotatedX > nScaledWidth
                 || unrotatedY < 0
-                || unrotatedY >= nScaledHeight)
+                || unrotatedY > nScaledHeight)
             {
                  pWriteAccess->SetPixel( yOut, xOut, aFillColor );
             }
diff --git a/vcl/source/gdi/bitmapex.cxx b/vcl/source/gdi/bitmapex.cxx
index e7df476..5851b74 100644
--- a/vcl/source/gdi/bitmapex.cxx
+++ b/vcl/source/gdi/bitmapex.cxx
@@ -276,14 +276,16 @@ Bitmap BitmapEx::GetMask() const
 
 AlphaMask BitmapEx::GetAlpha() const
 {
-    AlphaMask aAlpha;
-
     if( IsAlpha() )
+    {
+        AlphaMask aAlpha;
         aAlpha.ImplSetBitmap( aMask );
+        return aAlpha;
+    }
     else
-        aAlpha = aMask;
-
-    return aAlpha;
+    {
+        return aMask;
+    }
 }
 
 sal_uLong BitmapEx::GetSizeBytes() const
@@ -391,47 +393,56 @@ sal_Bool BitmapEx::ScaleCropRotate(
         const double& rScaleX, const double& rScaleY, const Rectangle& rRectPixel,
         long nAngle10, const Color& rFillColor, sal_uLong nScaleFlag )
 {
-    bool bRet = false;
+    bool bReturn = false;
 
     if( !!aBitmap )
     {
-        const bool bTransparentRotate = ( Color( COL_TRANSPARENT ) == rFillColor );
+        // If fill color is transpatent
+        const bool bTransparentRotation = Color( COL_TRANSPARENT ) == rFillColor;
 
-        bool bRightAngleRotation = (nAngle10 == 0 || nAngle10 == 900 || nAngle10 == 1800 || nAngle10 == 2700);
+        // If angle is 0, 90, 180 or 270 degreees, then we don't need to create an alpha bitmap.
+        const bool bRightAngleRotation = (nAngle10 == 0 || nAngle10 == 900 || nAngle10 == 1800 || nAngle10 == 2700);
 
-        if( !bRightAngleRotation && bTransparentRotate )
+        if( !bRightAngleRotation && bTransparentRotation )
         {
             if( eTransparent == TRANSPARENT_COLOR )
             {
-                bRet = aBitmap.ScaleCropRotate( rScaleX, rScaleY, rRectPixel, nAngle10, aTransparentColor, nScaleFlag );
+                bReturn = aBitmap.ScaleCropRotate( rScaleX, rScaleY, rRectPixel, nAngle10, aTransparentColor, nScaleFlag );
             }
-            else
+            else if( eTransparent == TRANSPARENT_NONE )
             {
-                bRet = aBitmap.ScaleCropRotate( rScaleX, rScaleY, rRectPixel, nAngle10, COL_BLACK, nScaleFlag );
-                if( eTransparent == TRANSPARENT_NONE )
+                bReturn = aBitmap.ScaleCropRotate( rScaleX, rScaleY, rRectPixel, nAngle10, COL_BLACK, nScaleFlag );
+                if ( bReturn )
                 {
                     aMask = Bitmap( aBitmapSize, 1 );
                     aMask.Erase( COL_BLACK );
+                    aMask.ScaleCropRotate( rScaleX, rScaleY, rRectPixel, nAngle10, COL_WHITE, nScaleFlag );
                     eTransparent = TRANSPARENT_BITMAP;
                 }
-
-                if( bRet && !!aMask )
+            } else {
+                bReturn = aBitmap.ScaleCropRotate( rScaleX, rScaleY, rRectPixel, nAngle10, COL_BLACK, nScaleFlag );
+                if( bReturn && !!aMask )
+                {
                     aMask.ScaleCropRotate( rScaleX, rScaleY, rRectPixel, nAngle10, COL_WHITE, nScaleFlag );
+                    aMask.Convert( BMP_CONVERSION_8BIT_GREYS );
+                }
             }
         }
         else
         {
-            bRet = aBitmap.ScaleCropRotate( rScaleX, rScaleY, rRectPixel, nAngle10, rFillColor, nScaleFlag );
-
-            if( bRet && ( eTransparent == TRANSPARENT_BITMAP ) && !!aMask )
-                aMask.ScaleCropRotate( rScaleX, rScaleY, rRectPixel, nAngle10, COL_WHITE, nScaleFlag );
+            bReturn = aBitmap.ScaleCropRotate( rScaleX, rScaleY, rRectPixel, nAngle10, rFillColor, nScaleFlag );
+            if( eTransparent == TRANSPARENT_BITMAP  && !!aMask )
+            {
+                 bReturn = aMask.ScaleCropRotate( rScaleX, rScaleY, rRectPixel, nAngle10, COL_WHITE, nScaleFlag );
+                 aMask.Convert( BMP_CONVERSION_8BIT_GREYS );
+            }
         }
     }
 
-    if (bRet)
+    if ( bReturn )
         aBitmapSize = aBitmap.GetSizePixel();
 
-    return bRet;
+    return bReturn;
 }
 
 sal_Bool BitmapEx::Rotate( long nAngle10, const Color& rFillColor )


More information about the Libreoffice-commits mailing list