summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTomaž Vajngerl <quikee@gmail.com>2012-07-25 23:50:33 +0200
committerTomaž Vajngerl <quikee@gmail.com>2012-07-25 23:53:42 +0200
commit085e747b6ca4148b35f37daf622a5ee79710cd66 (patch)
tree2456f839026cbea541916c423a6a772f3cd805b0
parent8f5b707d905f84f0102d1fdf365761ca03688742 (diff)
Fix bitmap resizing issue when using ScaleRotateCrop with BitmapEx.
Change-Id: I1fd08d94c506580ed7557066448ccb10adb9b16d
-rw-r--r--svtools/source/graphic/grfmgr2.cxx41
-rw-r--r--vcl/inc/vcl/bitmapex.hxx2
-rw-r--r--vcl/source/gdi/bitmap3.cxx191
-rw-r--r--vcl/source/gdi/bitmapex.cxx15
4 files changed, 47 insertions, 202 deletions
diff --git a/svtools/source/graphic/grfmgr2.cxx b/svtools/source/graphic/grfmgr2.cxx
index f3b6a073b9ec..dc6c3c7b8d0a 100644
--- a/svtools/source/graphic/grfmgr2.cxx
+++ b/svtools/source/graphic/grfmgr2.cxx
@@ -304,11 +304,11 @@ sal_Bool GraphicManager::ImplCreateOutput( OutputDevice* pOutputDevice,
bool isHorizontalMirrored = ( rAttributes.GetMirrorFlags() & BMP_MIRROR_HORZ ) != 0;
bool isVerticalMirrored = ( rAttributes.GetMirrorFlags() & BMP_MIRROR_VERT ) != 0;
- Rectangle aBitmapRectangle( aOutPointInPixels, aOutSizeInPixels );
// calculate output sizes
if( !pResultBitmapEx )
{
+ Rectangle aBitmapRectangle( aOutPointInPixels, aOutSizeInPixels );
Rectangle aOutRect( Point(), pOutputDevice->GetOutputSizePixel() );
if( pOutputDevice->GetOutDevType() == OUTDEV_WINDOW )
@@ -332,7 +332,6 @@ sal_Bool GraphicManager::ImplCreateOutput( OutputDevice* pOutputDevice,
aOutRect.Top() - aBitmapRectangle.Top(),
aOutRect.Right() - aBitmapRectangle.Left(),
aOutRect.Bottom() - aBitmapRectangle.Top() );
-
}
}
else
@@ -352,14 +351,11 @@ sal_Bool GraphicManager::ImplCreateOutput( OutputDevice* pOutputDevice,
// do transformation
- // #105229# Don't scale if output size equals bitmap size
- // #107226# Copy through only if we're not mirroring
if( !isHorizontalMirrored &&
!isVerticalMirrored &&
- aOutSizeInPixels == rBitmapSizePixels &&
- !nRotation)
+ !nRotation &&
+ aOutSizeInPixels == rBitmapSizePixels)
{
- // #107226# Use original dimensions when just copying through
aOutPoint = pOutputDevice->PixelToLogic( aOutPointInPixels );
aOutSize = pOutputDevice->PixelToLogic( aOutSizeInPixels );
bRet = true;
@@ -374,20 +370,33 @@ sal_Bool GraphicManager::ImplCreateOutput( OutputDevice* pOutputDevice,
if( isHorizontalMirrored || isVerticalMirrored )
bRet = aBitmapEx.Mirror( rAttributes.GetMirrorFlags() );
- // depending on the flags, scale the image to the desired proportions
- // use FAST scale if no smooth scale is desired
- if( nFlags & GRFMGR_DRAW_SMOOTHSCALE)
+ if (nRotation)
{
Polygon aPoly( Rectangle( Point(), aUnrotatedSizeInPixels) );
aPoly.Rotate( Point(), nRotation );
Rectangle aNewBound( aPoly.GetBoundRect() );
- Rectangle aCropRectangle2 (
- aCropRectangle.Left() + aNewBound.Left(),
- aCropRectangle.Top() + aNewBound.Top(),
- aCropRectangle.Right() + aNewBound.Left(),
- aCropRectangle.Bottom() + aNewBound.Top());
- bRet = aBitmapEx.ScaleCropRotate( fScaleX, fScaleY, aCropRectangle2, nRotation, COL_TRANSPARENT );
+ aCropRectangle = Rectangle (
+ aCropRectangle.Left() + aNewBound.Left(),
+ aCropRectangle.Top() + aNewBound.Top(),
+ aCropRectangle.Right() + aNewBound.Left(),
+ aCropRectangle.Bottom() + aNewBound.Top() );
+ }
+ if( nFlags & GRFMGR_DRAW_SMOOTHSCALE)
+ {
+ bRet = aBitmapEx.ScaleCropRotate( fScaleX, fScaleY, aCropRectangle, nRotation, COL_TRANSPARENT );
+ }
+ else
+ {
+ aCropRectangle = Rectangle (
+ aCropRectangle.Left() / fScaleX,
+ aCropRectangle.Right() / fScaleX,
+ aCropRectangle.Top() / fScaleY,
+ aCropRectangle.Bottom() / fScaleY );
+
+ bRet = aBitmapEx.Crop( aCropRectangle );
+ if (bRet)
+ bRet = aBitmapEx.Scale( fScaleX, fScaleY );
}
}
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;
}