Kaydet (Commit) f136890d authored tarafından Stephan Bergmann's avatar Stephan Bergmann

Clean up AlphaMask::CopyPixel "override" hack

...that required undefined downcasts of Bitmap objects that are not actually AlphaMasks.

Change-Id: I629f4a81d40a2a85cd877ffec13445786ef58187
üst e842914a
...@@ -105,9 +105,6 @@ public: ...@@ -105,9 +105,6 @@ public:
Bitmap GetBitmap() const; Bitmap GetBitmap() const;
bool CopyPixel( const Rectangle& rRectDst, const Rectangle& rRectSrc,
const AlphaMask* pAlphaSrc = NULL);
bool Erase( sal_uInt8 cTransparency ); bool Erase( sal_uInt8 cTransparency );
bool Replace( const Bitmap& rMask, sal_uInt8 rReplaceTransparency ); bool Replace( const Bitmap& rMask, sal_uInt8 rReplaceTransparency );
bool Replace( sal_uInt8 cSearchTransparency, sal_uInt8 cReplaceTransparency, bool Replace( sal_uInt8 cSearchTransparency, sal_uInt8 cReplaceTransparency,
......
...@@ -512,6 +512,9 @@ public: ...@@ -512,6 +512,9 @@ public:
const Rectangle& rRectSrc, const Rectangle& rRectSrc,
const Bitmap* pBmpSrc = NULL ); const Bitmap* pBmpSrc = NULL );
bool CopyPixel_AlphaOptimized( const Rectangle& rRectDst, const Rectangle& rRectSrc,
const Bitmap* pBmpSrc = NULL);
/** Perform boolean operations with another bitmap /** Perform boolean operations with another bitmap
@param rMask @param rMask
......
...@@ -76,114 +76,6 @@ Bitmap AlphaMask::GetBitmap() const ...@@ -76,114 +76,6 @@ Bitmap AlphaMask::GetBitmap() const
return ImplGetBitmap(); return ImplGetBitmap();
} }
bool AlphaMask::CopyPixel( const Rectangle& rRectDst, const Rectangle& rRectSrc,
const AlphaMask* pAlphaSrc )
{
// Note: this code is copied from Bitmap::CopyPixel but avoids any palette lookups
// This optimization is possible because the palettes of AlphaMasks are always identical (8bit GreyPalette, see ctor)
const Size aSizePix( GetSizePixel() );
Rectangle aRectDst( rRectDst );
bool bRet = false;
aRectDst.Intersection( Rectangle( Point(), aSizePix ) );
if( !aRectDst.IsEmpty() )
{
if( pAlphaSrc && ( *pAlphaSrc != *this ) )
{
Bitmap* pSrc = (Bitmap*) pAlphaSrc;
const Size aCopySizePix( pSrc->GetSizePixel() );
Rectangle aRectSrc( rRectSrc );
aRectSrc.Intersection( Rectangle( Point(), aCopySizePix ) );
if( !aRectSrc.IsEmpty() )
{
BitmapReadAccess* pReadAcc = pSrc->AcquireReadAccess();
if( pReadAcc )
{
BitmapWriteAccess* pWriteAcc = AcquireWriteAccess();
if( pWriteAcc )
{
const long nWidth = std::min( aRectSrc.GetWidth(), aRectDst.GetWidth() );
const long nHeight = std::min( aRectSrc.GetHeight(), aRectDst.GetHeight() );
const long nSrcEndX = aRectSrc.Left() + nWidth;
const long nSrcEndY = aRectSrc.Top() + nHeight;
long nDstY = aRectDst.Top();
for( long nSrcY = aRectSrc.Top(); nSrcY < nSrcEndY; nSrcY++, nDstY++ )
for( long nSrcX = aRectSrc.Left(), nDstX = aRectDst.Left(); nSrcX < nSrcEndX; nSrcX++, nDstX++ )
pWriteAcc->SetPixel( nDstY, nDstX, pReadAcc->GetPixel( nSrcY, nSrcX ) );
ReleaseAccess( pWriteAcc );
bRet = ( nWidth > 0L ) && ( nHeight > 0L );
}
pSrc->ReleaseAccess( pReadAcc );
}
}
}
else
{
Rectangle aRectSrc( rRectSrc );
aRectSrc.Intersection( Rectangle( Point(), aSizePix ) );
if( !aRectSrc.IsEmpty() && ( aRectSrc != aRectDst ) )
{
BitmapWriteAccess* pWriteAcc = AcquireWriteAccess();
if( pWriteAcc )
{
const long nWidth = std::min( aRectSrc.GetWidth(), aRectDst.GetWidth() );
const long nHeight = std::min( aRectSrc.GetHeight(), aRectDst.GetHeight() );
const long nSrcX = aRectSrc.Left();
const long nSrcY = aRectSrc.Top();
const long nSrcEndX1 = nSrcX + nWidth - 1L;
const long nSrcEndY1 = nSrcY + nHeight - 1L;
const long nDstX = aRectDst.Left();
const long nDstY = aRectDst.Top();
const long nDstEndX1 = nDstX + nWidth - 1L;
const long nDstEndY1 = nDstY + nHeight - 1L;
if( ( nDstX <= nSrcX ) && ( nDstY <= nSrcY ) )
{
for( long nY = nSrcY, nYN = nDstY; nY <= nSrcEndY1; nY++, nYN++ )
for( long nX = nSrcX, nXN = nDstX; nX <= nSrcEndX1; nX++, nXN++ )
pWriteAcc->SetPixel( nYN, nXN, pWriteAcc->GetPixel( nY, nX ) );
}
else if( ( nDstX <= nSrcX ) && ( nDstY >= nSrcY ) )
{
for( long nY = nSrcEndY1, nYN = nDstEndY1; nY >= nSrcY; nY--, nYN-- )
for( long nX = nSrcX, nXN = nDstX; nX <= nSrcEndX1; nX++, nXN++ )
pWriteAcc->SetPixel( nYN, nXN, pWriteAcc->GetPixel( nY, nX ) );
}
else if( ( nDstX >= nSrcX ) && ( nDstY <= nSrcY ) )
{
for( long nY = nSrcY, nYN = nDstY; nY <= nSrcEndY1; nY++, nYN++ )
for( long nX = nSrcEndX1, nXN = nDstEndX1; nX >= nSrcX; nX--, nXN-- )
pWriteAcc->SetPixel( nYN, nXN, pWriteAcc->GetPixel( nY, nX ) );
}
else
{
for( long nY = nSrcEndY1, nYN = nDstEndY1; nY >= nSrcY; nY--, nYN-- )
for( long nX = nSrcEndX1, nXN = nDstEndX1; nX >= nSrcX; nX--, nXN-- )
pWriteAcc->SetPixel( nYN, nXN, pWriteAcc->GetPixel( nY, nX ) );
}
ReleaseAccess( pWriteAcc );
bRet = true;
}
}
}
}
return bRet;
}
bool AlphaMask::Erase( sal_uInt8 cTransparency ) bool AlphaMask::Erase( sal_uInt8 cTransparency )
{ {
return Bitmap::Erase( Color( cTransparency, cTransparency, cTransparency ) ); return Bitmap::Erase( Color( cTransparency, cTransparency, cTransparency ) );
......
...@@ -1004,6 +1004,114 @@ bool Bitmap::CopyPixel( const Rectangle& rRectDst, ...@@ -1004,6 +1004,114 @@ bool Bitmap::CopyPixel( const Rectangle& rRectDst,
return bRet; return bRet;
} }
bool Bitmap::CopyPixel_AlphaOptimized( const Rectangle& rRectDst, const Rectangle& rRectSrc,
const Bitmap* pBmpSrc )
{
// Note: this code is copied from Bitmap::CopyPixel but avoids any palette lookups
// This optimization is possible because the palettes of AlphaMasks are always identical (8bit GreyPalette, see ctor)
const Size aSizePix( GetSizePixel() );
Rectangle aRectDst( rRectDst );
bool bRet = false;
aRectDst.Intersection( Rectangle( Point(), aSizePix ) );
if( !aRectDst.IsEmpty() )
{
if( pBmpSrc && ( *pBmpSrc != *this ) )
{
Bitmap* pSrc = (Bitmap*) pBmpSrc;
const Size aCopySizePix( pSrc->GetSizePixel() );
Rectangle aRectSrc( rRectSrc );
aRectSrc.Intersection( Rectangle( Point(), aCopySizePix ) );
if( !aRectSrc.IsEmpty() )
{
BitmapReadAccess* pReadAcc = pSrc->AcquireReadAccess();
if( pReadAcc )
{
BitmapWriteAccess* pWriteAcc = AcquireWriteAccess();
if( pWriteAcc )
{
const long nWidth = std::min( aRectSrc.GetWidth(), aRectDst.GetWidth() );
const long nHeight = std::min( aRectSrc.GetHeight(), aRectDst.GetHeight() );
const long nSrcEndX = aRectSrc.Left() + nWidth;
const long nSrcEndY = aRectSrc.Top() + nHeight;
long nDstY = aRectDst.Top();
for( long nSrcY = aRectSrc.Top(); nSrcY < nSrcEndY; nSrcY++, nDstY++ )
for( long nSrcX = aRectSrc.Left(), nDstX = aRectDst.Left(); nSrcX < nSrcEndX; nSrcX++, nDstX++ )
pWriteAcc->SetPixel( nDstY, nDstX, pReadAcc->GetPixel( nSrcY, nSrcX ) );
ReleaseAccess( pWriteAcc );
bRet = ( nWidth > 0L ) && ( nHeight > 0L );
}
pSrc->ReleaseAccess( pReadAcc );
}
}
}
else
{
Rectangle aRectSrc( rRectSrc );
aRectSrc.Intersection( Rectangle( Point(), aSizePix ) );
if( !aRectSrc.IsEmpty() && ( aRectSrc != aRectDst ) )
{
BitmapWriteAccess* pWriteAcc = AcquireWriteAccess();
if( pWriteAcc )
{
const long nWidth = std::min( aRectSrc.GetWidth(), aRectDst.GetWidth() );
const long nHeight = std::min( aRectSrc.GetHeight(), aRectDst.GetHeight() );
const long nSrcX = aRectSrc.Left();
const long nSrcY = aRectSrc.Top();
const long nSrcEndX1 = nSrcX + nWidth - 1L;
const long nSrcEndY1 = nSrcY + nHeight - 1L;
const long nDstX = aRectDst.Left();
const long nDstY = aRectDst.Top();
const long nDstEndX1 = nDstX + nWidth - 1L;
const long nDstEndY1 = nDstY + nHeight - 1L;
if( ( nDstX <= nSrcX ) && ( nDstY <= nSrcY ) )
{
for( long nY = nSrcY, nYN = nDstY; nY <= nSrcEndY1; nY++, nYN++ )
for( long nX = nSrcX, nXN = nDstX; nX <= nSrcEndX1; nX++, nXN++ )
pWriteAcc->SetPixel( nYN, nXN, pWriteAcc->GetPixel( nY, nX ) );
}
else if( ( nDstX <= nSrcX ) && ( nDstY >= nSrcY ) )
{
for( long nY = nSrcEndY1, nYN = nDstEndY1; nY >= nSrcY; nY--, nYN-- )
for( long nX = nSrcX, nXN = nDstX; nX <= nSrcEndX1; nX++, nXN++ )
pWriteAcc->SetPixel( nYN, nXN, pWriteAcc->GetPixel( nY, nX ) );
}
else if( ( nDstX >= nSrcX ) && ( nDstY <= nSrcY ) )
{
for( long nY = nSrcY, nYN = nDstY; nY <= nSrcEndY1; nY++, nYN++ )
for( long nX = nSrcEndX1, nXN = nDstEndX1; nX >= nSrcX; nX--, nXN-- )
pWriteAcc->SetPixel( nYN, nXN, pWriteAcc->GetPixel( nY, nX ) );
}
else
{
for( long nY = nSrcEndY1, nYN = nDstEndY1; nY >= nSrcY; nY--, nYN-- )
for( long nX = nSrcEndX1, nXN = nDstEndX1; nX >= nSrcX; nX--, nXN-- )
pWriteAcc->SetPixel( nYN, nXN, pWriteAcc->GetPixel( nY, nX ) );
}
ReleaseAccess( pWriteAcc );
bRet = true;
}
}
}
}
return bRet;
}
bool Bitmap::Expand( sal_uLong nDX, sal_uLong nDY, const Color* pInitColor ) bool Bitmap::Expand( sal_uLong nDX, sal_uLong nDY, const Color* pInitColor )
{ {
bool bRet = false; bool bRet = false;
......
...@@ -525,7 +525,7 @@ bool BitmapEx::CopyPixel( const Rectangle& rRectDst, const Rectangle& rRectSrc, ...@@ -525,7 +525,7 @@ bool BitmapEx::CopyPixel( const Rectangle& rRectDst, const Rectangle& rRectSrc,
{ {
if( IsAlpha() ) if( IsAlpha() )
// cast to use the optimized AlphaMask::CopyPixel // cast to use the optimized AlphaMask::CopyPixel
((AlphaMask*) &aMask)->CopyPixel( rRectDst, rRectSrc, (AlphaMask*)&pBmpExSrc->aMask ); aMask.CopyPixel_AlphaOptimized( rRectDst, rRectSrc, &pBmpExSrc->aMask );
else if( IsTransparent() ) else if( IsTransparent() )
{ {
AlphaMask* pAlpha = new AlphaMask( aMask ); AlphaMask* pAlpha = new AlphaMask( aMask );
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment