diff options
author | Tomaž Vajngerl <quikee@gmail.com> | 2012-07-25 23:50:33 +0200 |
---|---|---|
committer | Tomaž Vajngerl <quikee@gmail.com> | 2012-07-25 23:53:42 +0200 |
commit | 085e747b6ca4148b35f37daf622a5ee79710cd66 (patch) | |
tree | 2456f839026cbea541916c423a6a772f3cd805b0 /vcl | |
parent | 8f5b707d905f84f0102d1fdf365761ca03688742 (diff) |
Fix bitmap resizing issue when using ScaleRotateCrop with BitmapEx.
Change-Id: I1fd08d94c506580ed7557066448ccb10adb9b16d
Diffstat (limited to 'vcl')
-rw-r--r-- | vcl/inc/vcl/bitmapex.hxx | 2 | ||||
-rw-r--r-- | vcl/source/gdi/bitmap3.cxx | 191 | ||||
-rw-r--r-- | vcl/source/gdi/bitmapex.cxx | 15 |
3 files changed, 22 insertions, 186 deletions
diff --git a/vcl/inc/vcl/bitmapex.hxx b/vcl/inc/vcl/bitmapex.hxx index a29c27177679..437c70a794a8 100644 --- a/vcl/inc/vcl/bitmapex.hxx +++ b/vcl/inc/vcl/bitmapex.hxx @@ -60,7 +60,7 @@ private: Size aBitmapSize; Color aTransparentColor; TransparentType eTransparent; - sal_Bool bAlpha; + sal_Bool bAlpha; public: diff --git a/vcl/source/gdi/bitmap3.cxx b/vcl/source/gdi/bitmap3.cxx index b1a028cfe67c..edae9e1c715a 100644 --- a/vcl/source/gdi/bitmap3.cxx +++ b/vcl/source/gdi/bitmap3.cxx @@ -2383,7 +2383,7 @@ sal_Bool Bitmap::ScaleCropRotate( { bool bRet; - if ( rScaleY < 0.6 && rScaleX < 0.6 ) + if ( rScaleX < 0.6 || rScaleY < 0.6 ) { bRet = ImplTransformAveraging( rScaleX, rScaleY, rRectPixel, nAngle10, rFillColor); } @@ -2508,24 +2508,22 @@ bool Bitmap::ImplTransformAveraging( const double& rScaleX, const double& rScale // Filtering shows bad results at shrinking for a factor less than 0.5 because of limited sampling. bool Bitmap::ImplTransformBilinearFiltering( const double& rScaleX, const double& rScaleY, const Rectangle& rRotatedRectangle, const long nAngle10, const Color& rFillColor ) { - const Size aSizePix( GetSizePixel() ); - - const int nOriginWidth = aSizePix.Width(); - const int nOriginHeight = aSizePix.Height(); - - const int nScaledWidth = FRound( aSizePix.Width() * rScaleX ); - const int nScaledHeight = FRound( aSizePix.Height() * rScaleY ); + const int nOriginWidth = GetSizePixel().Width(); + const int nOriginHeight = GetSizePixel().Height(); - const int nStartX = rRotatedRectangle.Left(); - const int nStartY = rRotatedRectangle.Top(); - const int nEndX = rRotatedRectangle.Right(); - const int nEndY = rRotatedRectangle.Bottom(); + const int nScaledWidth = FRound( nOriginWidth * rScaleX ); + const int nScaledHeight = FRound( nOriginHeight * rScaleY ); const int nTargetWidth = rRotatedRectangle.GetWidth(); const int nTargetHeight = rRotatedRectangle.GetHeight(); - const double fCosAngle = cos( nAngle10 * F_PI1800 ); - const double fSinAngle = sin( nAngle10 * F_PI1800 ); + const int nStartX = rRotatedRectangle.Left(); + const int nEndX = rRotatedRectangle.Right(); + const int nStartY = rRotatedRectangle.Top(); + const int nEndY = rRotatedRectangle.Bottom(); + + const double fCosAngle = cos( nAngle10 * F_PI1800 ); + const double fSinAngle = sin( nAngle10 * F_PI1800 ); Bitmap aOutBmp( Size( nTargetWidth, nTargetHeight ), 24 ); @@ -2612,169 +2610,4 @@ bool Bitmap::ImplTransformBilinearFiltering( const double& rScaleX, const double return true; } -/*bool Bitmap::ImplScaleSuperFast( const double& rScaleX, const double& rScaleY, const Rectangle& rRectPixel ) -{ - const Size aSizePix( GetSizePixel() ); - - const int nOriginWidth = aSizePix.Width(); - const int nOriginHeight = aSizePix.Height(); - - const int nStartX = rRectPixel.Left(); - const int nStartY = rRectPixel.Top(); - const int nEndX = rRectPixel.Right(); - const int nEndY = rRectPixel.Bottom(); - - const int nTargetWidth = rRectPixel.GetWidth(); - const int nTargetHeight = rRectPixel.GetHeight(); - - BitmapColor aColor00, aColor01, aColor10, aColor11, aResultColor; - - Bitmap aOutBmp( Size( nTargetWidth, nTargetHeight ), 24 ); - - BitmapReadAccess* pReadAccess = AcquireReadAccess(); - BitmapWriteAccess* pWriteAccess = aOutBmp.AcquireWriteAccess(); - - if( !pReadAccess || !pWriteAccess ) - return false; - - double aReverseScaleX = 1.0 / rScaleX; - double aReverseScaleY = 1.0 / rScaleY; - - int x, y, xOut, yOut; - - for( y = nStartY, yOut = 0; y <= nEndY; y++, yOut++ ) - { - double sy0 = ((y + 0.5) * aReverseScaleY) - 0.5; - - int y0 = MinMax( floor( sy0 ), 0, nOriginHeight - 1); - int y1 = MinMax( y0 + 1, 0, nOriginHeight - 1); - - for( x = nStartX, xOut = 0; x <= nEndX; x++, xOut++ ) - { - double sx0 = ((x + 0.5) * aReverseScaleX) - 0.5; - int x0 = MinMax( floor( sx0 ), 0, nOriginWidth - 1); - int x1 = MinMax( x0 + 1, 0, nOriginWidth - 1); - - aColor00 = pReadAccess->GetPixel( y0, x0 ); - aColor01 = pReadAccess->GetPixel( y1, x0 ); - aColor10 = pReadAccess->GetPixel( y0, x1 ); - aColor11 = pReadAccess->GetPixel( y1, x1 ); - - if( pReadAccess->HasPalette() ) - { - aColor00 = pReadAccess->GetPaletteColor( aColor00 ); - aColor01 = pReadAccess->GetPaletteColor( aColor01 ); - aColor10 = pReadAccess->GetPaletteColor( aColor10 ); - aColor11 = pReadAccess->GetPaletteColor( aColor11 ); - } - - double fx0 = sx0 - x0; - double fy0 = sy0 - y0; - double fx1 = 1.0 - fx0; - double fy1 = 1.0 - fy0; - - double w00 = fx1 * fy1; - double w01 = fx1 * fy0; - double w10 = fx0 * fy1; - double w11 = fx0 * fy0; - - double red = aColor00.GetRed() * w00 + aColor10.GetRed() * w10 + aColor01.GetRed() * w01 + aColor11.GetRed() * w11; - double green = aColor00.GetGreen() * w00 + aColor10.GetGreen() * w10 + aColor01.GetGreen() * w01 + aColor11.GetGreen() * w11; - double blue = aColor00.GetBlue() * w00 + aColor10.GetBlue() * w10 + aColor01.GetBlue() * w01 + aColor11.GetBlue() * w11; - - aResultColor.SetRed( MinMax(red, 0, 255) ); - aResultColor.SetGreen( MinMax(green, 0, 255) ); - aResultColor.SetBlue( MinMax(blue, 0, 255) ); - - pWriteAccess->SetPixel( yOut, xOut, aResultColor ); - } - } - - ReleaseAccess( pReadAccess ); - aOutBmp.ReleaseAccess( pWriteAccess ); - ImplAssignWithSize( aOutBmp ); - - return true; -} -bool Bitmap::ImplScaleSuper( const double& rScaleX, const double& rScaleY, const Rectangle& rRectPixel, const long nAngle10, const Color& rFillColor ) -{ - Rectangle aRect( rRectPixel ); - - const int nStartX = aRect.Left(); - const int nStartY = aRect.Top(); - const int nEndX = aRect.Right(); - const int nEndY = aRect.Bottom(); - - const int nTargetWidth = aRect.GetWidth(); - const int nTargetHeight = aRect.GetHeight(); - - const int nOriginWidth = GetSizePixel().Width(); - const int nOriginHeight = GetSizePixel().Height(); - - const double aReverseScaleX = 1.0 / rScaleX; - const double aReverseScaleY = 1.0 / rScaleY; - - if( nTargetWidth <= 1L || nTargetHeight <= 1L ) - return false; - - BitmapColor aColor, aResultColor; - - Bitmap aOutBmp( Size( nTargetWidth, nTargetHeight ), 24 ); - - BitmapReadAccess* pReadAccess = AcquireReadAccess(); - BitmapWriteAccess* pWriteAccess = aOutBmp.AcquireWriteAccess(); - - if( !pReadAccess || !pWriteAccess ) - return false; - - int x, y, xOut, yOut; - int aCount; - double aSumRed, aSumGreen, aSumBlue; - - for( y = nStartY, yOut = 0; y <= nEndY; y++, yOut++ ) - { - int yStart = MinMax( floor( y * aReverseScaleY ), 0, nOriginHeight - 1); - int yEnd = MinMax( floor( (y+1) * aReverseScaleY ), 0, nOriginHeight - 1); - - for( x = nStartX, xOut = 0; x <= nEndX; x++, xOut++ ) - { - int xStart = MinMax( floor( x * aReverseScaleX ), 0, nOriginWidth - 1); - int xEnd = MinMax( floor( (x+1) * aReverseScaleX ), 0, nOriginWidth - 1); - - aSumRed = aSumGreen = aSumBlue = 0.0; - aCount = 0; - - for (int yIn = yStart; yIn < yEnd; yIn++) - { - for (int xIn = xStart; xIn < xEnd; xIn++) - { - aColor = pReadAccess->GetPixel( yIn, xIn ); - - if( pReadAccess->HasPalette() ) - aColor = pReadAccess->GetPaletteColor( aColor ); - - aSumRed += aColor.GetRed(); - aSumGreen += aColor.GetGreen(); - aSumBlue += aColor.GetBlue(); - - aCount++; - } - } - - aResultColor.SetRed( MinMax(aSumRed / aCount, 0, 255) ); - aResultColor.SetGreen( MinMax(aSumGreen / aCount, 0, 255) ); - aResultColor.SetBlue( MinMax(aSumBlue / aCount, 0, 255) ); - - pWriteAccess->SetPixel( yOut, xOut, aResultColor ); - } - } - - ReleaseAccess( pReadAccess ); - aOutBmp.ReleaseAccess( pWriteAccess ); - ImplAssignWithSize( aOutBmp ); - - return true; -} -*/ - /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/vcl/source/gdi/bitmapex.cxx b/vcl/source/gdi/bitmapex.cxx index e9a3ab4b390a..beba5d50a6a7 100644 --- a/vcl/source/gdi/bitmapex.cxx +++ b/vcl/source/gdi/bitmapex.cxx @@ -444,16 +444,16 @@ sal_Bool BitmapEx::Scale( const Size& rNewSize, sal_uLong nScaleFlag ) } sal_Bool BitmapEx::ScaleCropRotate( - const double& rScaleX, const double& rScaleY, const Rectangle& rRectPixel, long nAngle10, - const Color& rFillColor, sal_uLong nScaleFlag ) + const double& rScaleX, const double& rScaleY, const Rectangle& rRectPixel, + long nAngle10, const Color& rFillColor, sal_uLong nScaleFlag ) { - sal_Bool bRet = sal_False; + bool bRet = false; + + const bool bTransparentRotate = ( Color( COL_TRANSPARENT ) == rFillColor ); if( !!aBitmap ) { - const sal_Bool bTransRotate = ( Color( COL_TRANSPARENT ) == rFillColor ); - - if( bTransRotate ) + if( bTransparentRotate ) { if( eTransparent == TRANSPARENT_COLOR ) { @@ -482,6 +482,9 @@ sal_Bool BitmapEx::ScaleCropRotate( } } + if (bRet) + aBitmapSize = aBitmap.GetSizePixel(); + return bRet; } |