diff options
author | Tomaž Vajngerl <tomaz.vajngerl@collabora.co.uk> | 2015-03-25 14:42:42 +0900 |
---|---|---|
committer | Tomaž Vajngerl <tomaz.vajngerl@collabora.co.uk> | 2015-03-27 10:45:15 +0900 |
commit | 33094a542fbcdcdaf14d5d7304e79f2e5b8cd4de (patch) | |
tree | 51541f146cdb69684a03d08cfabce8803f466a8e | |
parent | 132ad4f1416126a74f8b48f65da786a4e0ec8c1b (diff) |
vcl: use unique_ptr for fillcolor, linecolor in bmpacc
Change-Id: I09d00c4492d2866aeb79d1a4818a55f9cdfdc4f0
-rw-r--r-- | include/vcl/bmpacc.hxx | 4 | ||||
-rw-r--r-- | vcl/source/gdi/bmpacc.cxx | 10 | ||||
-rw-r--r-- | vcl/source/gdi/bmpacc3.cxx | 177 |
3 files changed, 106 insertions, 85 deletions
diff --git a/include/vcl/bmpacc.hxx b/include/vcl/bmpacc.hxx index f0ab33b989f2..ebc00c75c4c4 100644 --- a/include/vcl/bmpacc.hxx +++ b/include/vcl/bmpacc.hxx @@ -221,8 +221,8 @@ public: private: - BitmapColor* mpLineColor; - BitmapColor* mpFillColor; + std::unique_ptr<BitmapColor> mpLineColor; + std::unique_ptr<BitmapColor> mpFillColor; BitmapWriteAccess() {} diff --git a/vcl/source/gdi/bmpacc.cxx b/vcl/source/gdi/bmpacc.cxx index cdda5dcb87be..2e7982f07a68 100644 --- a/vcl/source/gdi/bmpacc.cxx +++ b/vcl/source/gdi/bmpacc.cxx @@ -491,17 +491,15 @@ BitmapColor BitmapReadAccess::GetColorWithFallback( double fY, double fX, const return rFallback; } -BitmapWriteAccess::BitmapWriteAccess( Bitmap& rBitmap ) : - BitmapReadAccess( rBitmap, BITMAP_WRITE_ACCESS ), - mpLineColor ( NULL ), - mpFillColor ( NULL ) +BitmapWriteAccess::BitmapWriteAccess(Bitmap& rBitmap) + : BitmapReadAccess(rBitmap, BITMAP_WRITE_ACCESS) + , mpLineColor() + , mpFillColor() { } BitmapWriteAccess::~BitmapWriteAccess() { - delete mpLineColor; - delete mpFillColor; } void BitmapWriteAccess::CopyScanline( long nY, const BitmapReadAccess& rReadAcc ) diff --git a/vcl/source/gdi/bmpacc3.cxx b/vcl/source/gdi/bmpacc3.cxx index 70f23c6b5491..c94fb0060631 100644 --- a/vcl/source/gdi/bmpacc3.cxx +++ b/vcl/source/gdi/bmpacc3.cxx @@ -28,28 +28,45 @@ void BitmapWriteAccess::SetLineColor( const Color& rColor ) { - delete mpLineColor; - - if( rColor.GetTransparency() == 255 ) - mpLineColor = NULL; + if (rColor.GetTransparency() == 255) + { + mpLineColor.reset(); + } else - mpLineColor = ( HasPalette() ? new BitmapColor( (sal_uInt8) GetBestPaletteIndex( rColor ) ) : new BitmapColor( rColor ) ); + { + if (HasPalette()) + { + mpLineColor.reset(new BitmapColor(static_cast<sal_uInt8>(GetBestPaletteIndex(rColor)))); + } + else + { + mpLineColor.reset(new BitmapColor(rColor)); + } + } } void BitmapWriteAccess::SetFillColor() { - delete mpFillColor; - mpFillColor = NULL; + mpFillColor.reset(); } void BitmapWriteAccess::SetFillColor( const Color& rColor ) { - delete mpFillColor; - - if( rColor.GetTransparency() == 255 ) - mpFillColor = NULL; + if (rColor.GetTransparency() == 255) + { + mpFillColor.reset(); + } else - mpFillColor = ( HasPalette() ? new BitmapColor( (sal_uInt8) GetBestPaletteIndex( rColor ) ) : new BitmapColor( rColor ) ); + { + if (HasPalette()) + { + mpFillColor.reset(new BitmapColor(static_cast<sal_uInt8>(GetBestPaletteIndex(rColor)))); + } + else + { + mpFillColor.reset(new BitmapColor(rColor)); + } + } } void BitmapWriteAccess::Erase( const Color& rColor ) @@ -57,31 +74,33 @@ void BitmapWriteAccess::Erase( const Color& rColor ) // convert the color format from RGB to palette index if needed // TODO: provide and use Erase( BitmapColor& method) BitmapColor aColor = rColor; - if( HasPalette() ) - aColor = BitmapColor( (sal_uInt8)GetBestPaletteIndex( rColor) ); + if (HasPalette()) + { + aColor = BitmapColor(static_cast<sal_uInt8>(GetBestPaletteIndex(rColor))); + } // try fast bitmap method first - if( ImplFastEraseBitmap( *mpBuffer, aColor ) ) + if (ImplFastEraseBitmap(*mpBuffer, aColor)) return; // use the canonical method to clear the bitmap - BitmapColor* pOldFillColor = mpFillColor ? new BitmapColor( *mpFillColor ) : NULL; - const Point aPoint; - const Rectangle aRect( aPoint, maBitmap.GetSizePixel() ); - - SetFillColor( rColor ); - FillRect( aRect ); - delete mpFillColor; - mpFillColor = pOldFillColor; + BitmapColor* pOldFillColor = mpFillColor ? new BitmapColor(*mpFillColor) : NULL; + const Point aPoint; + const Rectangle aRect(aPoint, maBitmap.GetSizePixel()); + + SetFillColor(rColor); + FillRect(aRect); + + mpFillColor.reset(pOldFillColor); } void BitmapWriteAccess::DrawLine( const Point& rStart, const Point& rEnd ) { - if( mpLineColor ) + if (mpLineColor) { - const BitmapColor& rLineColor = *mpLineColor; - long nX, nY; + const BitmapColor& rLineColor = *mpLineColor.get(); + long nX, nY; - if ( rStart.X() == rEnd.X() ) + if (rStart.X() == rEnd.X()) { // Vertical Line const long nEndY = rEnd.Y(); @@ -89,7 +108,7 @@ void BitmapWriteAccess::DrawLine( const Point& rStart, const Point& rEnd ) nX = rStart.X(); nY = rStart.Y(); - if ( nEndY > nY ) + if (nEndY > nY) { for (; nY <= nEndY; nY++ ) SetPixel( nY, nX, rLineColor ); @@ -100,7 +119,7 @@ void BitmapWriteAccess::DrawLine( const Point& rStart, const Point& rEnd ) SetPixel( nY, nX, rLineColor ); } } - else if ( rStart.Y() == rEnd.Y() ) + else if (rStart.Y() == rEnd.Y()) { // Horizontal Line const long nEndX = rEnd.X(); @@ -108,29 +127,29 @@ void BitmapWriteAccess::DrawLine( const Point& rStart, const Point& rEnd ) nX = rStart.X(); nY = rStart.Y(); - if ( nEndX > nX ) + if (nEndX > nX) { - for (; nX <= nEndX; nX++ ) - SetPixel( nY, nX, rLineColor ); + for (; nX <= nEndX; nX++) + SetPixel(nY, nX, rLineColor); } else { - for (; nX >= nEndX; nX-- ) - SetPixel( nY, nX, rLineColor ); + for (; nX >= nEndX; nX--) + SetPixel(nY, nX, rLineColor); } } else { const long nDX = labs( rEnd.X() - rStart.X() ); const long nDY = labs( rEnd.Y() - rStart.Y() ); - long nX1; - long nY1; - long nX2; - long nY2; + long nX1; + long nY1; + long nX2; + long nY2; - if ( nDX >= nDY ) + if (nDX >= nDY) { - if ( rStart.X() < rEnd.X() ) + if (rStart.X() < rEnd.X()) { nX1 = rStart.X(); nY1 = rStart.Y(); @@ -145,22 +164,22 @@ void BitmapWriteAccess::DrawLine( const Point& rStart, const Point& rEnd ) nY2 = rStart.Y(); } - const long nDYX = ( nDY - nDX ) << 1; - const long nDY2 = nDY << 1; - long nD = nDY2 - nDX; - bool bPos = nY1 < nY2; + const long nDYX = (nDY - nDX) << 1; + const long nDY2 = nDY << 1; + long nD = nDY2 - nDX; + bool bPos = nY1 < nY2; - for ( nX = nX1, nY = nY1; nX <= nX2; nX++ ) + for (nX = nX1, nY = nY1; nX <= nX2; nX++) { - SetPixel( nY, nX, rLineColor ); + SetPixel(nY, nX, rLineColor); - if ( nD < 0 ) + if (nD < 0) nD += nDY2; else { nD += nDYX; - if ( bPos ) + if (bPos) nY++; else nY--; @@ -169,7 +188,7 @@ void BitmapWriteAccess::DrawLine( const Point& rStart, const Point& rEnd ) } else { - if ( rStart.Y() < rEnd.Y() ) + if (rStart.Y() < rEnd.Y()) { nX1 = rStart.X(); nY1 = rStart.Y(); @@ -184,22 +203,22 @@ void BitmapWriteAccess::DrawLine( const Point& rStart, const Point& rEnd ) nY2 = rStart.Y(); } - const long nDYX = ( nDX - nDY ) << 1; + const long nDYX = (nDX - nDY) << 1; const long nDY2 = nDX << 1; - long nD = nDY2 - nDY; - bool bPos = nX1 < nX2; + long nD = nDY2 - nDY; + bool bPos = nX1 < nX2; - for ( nX = nX1, nY = nY1; nY <= nY2; nY++ ) + for (nX = nX1, nY = nY1; nY <= nY2; nY++) { - SetPixel( nY, nX, rLineColor ); + SetPixel(nY, nX, rLineColor); - if ( nD < 0 ) + if (nD < 0) nD += nDY2; else { nD += nDYX; - if ( bPos ) + if (bPos) nX++; else nX--; @@ -212,39 +231,43 @@ void BitmapWriteAccess::DrawLine( const Point& rStart, const Point& rEnd ) void BitmapWriteAccess::FillRect( const Rectangle& rRect ) { - if( mpFillColor ) + if (mpFillColor) { - const BitmapColor& rFillColor = *mpFillColor; - Point aPoint; - Rectangle aRect( aPoint, maBitmap.GetSizePixel() ); + const BitmapColor& rFillColor = *mpFillColor.get(); + Point aPoint; + Rectangle aRect(aPoint, maBitmap.GetSizePixel()); - aRect.Intersection( rRect ); + aRect.Intersection(rRect); - if( !aRect.IsEmpty() ) + if (!aRect.IsEmpty()) { - const long nStartX = rRect.Left(); - const long nStartY = rRect.Top(); - const long nEndX = rRect.Right(); - const long nEndY = rRect.Bottom(); - - for( long nY = nStartY; nY <= nEndY; nY++ ) - for( long nX = nStartX; nX <= nEndX; nX++ ) - SetPixel( nY, nX, rFillColor ); + const long nStartX = rRect.Left(); + const long nStartY = rRect.Top(); + const long nEndX = rRect.Right(); + const long nEndY = rRect.Bottom(); + + for (long nY = nStartY; nY <= nEndY; nY++) + { + for (long nX = nStartX; nX <= nEndX; nX++) + { + SetPixel(nY, nX, rFillColor); + } + } } } } void BitmapWriteAccess::DrawRect( const Rectangle& rRect ) { - if( mpFillColor ) - FillRect( rRect ); + if (mpFillColor) + FillRect(rRect); - if( mpLineColor && ( !mpFillColor || ( *mpFillColor != *mpLineColor ) ) ) + if (mpLineColor && (!mpFillColor || ( *mpFillColor.get() != *mpLineColor.get()))) { - DrawLine( rRect.TopLeft(), rRect.TopRight() ); - DrawLine( rRect.TopRight(), rRect.BottomRight() ); - DrawLine( rRect.BottomRight(), rRect.BottomLeft() ); - DrawLine( rRect.BottomLeft(), rRect.TopLeft() ); + DrawLine(rRect.TopLeft(), rRect.TopRight()); + DrawLine(rRect.TopRight(), rRect.BottomRight()); + DrawLine(rRect.BottomRight(), rRect.BottomLeft()); + DrawLine(rRect.BottomLeft(), rRect.TopLeft()); } } |