Kaydet (Commit) 035751dd authored tarafından Caolán McNamara's avatar Caolán McNamara

ofz: optimize 1bit mask to avoid timeout

Change-Id: Ieaf3eb0800d2e80f16cfa29718d752e43ad534d0
Reviewed-on: https://gerrit.libreoffice.org/43418Reviewed-by: 's avatarCaolán McNamara <caolanm@redhat.com>
Tested-by: 's avatarCaolán McNamara <caolanm@redhat.com>
üst f2410ad4
...@@ -1137,7 +1137,6 @@ Bitmap Bitmap::CreateMask( const Color& rTransColor, sal_uLong nTol ) const ...@@ -1137,7 +1137,6 @@ Bitmap Bitmap::CreateMask( const Color& rTransColor, sal_uLong nTol ) const
if( !nTol ) if( !nTol )
{ {
const BitmapColor aTest( pReadAcc->GetBestMatchingColor( rTransColor ) ); const BitmapColor aTest( pReadAcc->GetBestMatchingColor( rTransColor ) );
long nX, nY;
if( pReadAcc->GetScanlineFormat() == ScanlineFormat::N4BitMsnPal || if( pReadAcc->GetScanlineFormat() == ScanlineFormat::N4BitMsnPal ||
pReadAcc->GetScanlineFormat() == ScanlineFormat::N4BitLsnPal ) pReadAcc->GetScanlineFormat() == ScanlineFormat::N4BitLsnPal )
...@@ -1150,12 +1149,11 @@ Bitmap Bitmap::CreateMask( const Color& rTransColor, sal_uLong nTol ) const ...@@ -1150,12 +1149,11 @@ Bitmap Bitmap::CreateMask( const Color& rTransColor, sal_uLong nTol ) const
aWhite.GetIndex() == 1 ) aWhite.GetIndex() == 1 )
{ {
// optimized for 1Bit-MSB destination palette // optimized for 1Bit-MSB destination palette
for( nY = 0; nY < nHeight; nY++ ) for (long nY = 0; nY < nHeight; ++nY)
{ {
Scanline pSrc = pReadAcc->GetScanline( nY ); Scanline pSrc = pReadAcc->GetScanline( nY );
Scanline pDst = pWriteAcc->GetScanline( nY ); Scanline pDst = pWriteAcc->GetScanline( nY );
long nShift = 0; for (long nX = 0, nShift = nShiftInit; nX < nWidth; nX++, nShift ^= 4)
for( nX = 0, nShift = nShiftInit; nX < nWidth; nX++, nShift ^= 4 )
{ {
if( cTest == ( ( pSrc[ nX >> 1 ] >> nShift ) & 0x0f ) ) if( cTest == ( ( pSrc[ nX >> 1 ] >> nShift ) & 0x0f ) )
pDst[ nX >> 3 ] |= 1 << ( 7 - ( nX & 7 ) ); pDst[ nX >> 3 ] |= 1 << ( 7 - ( nX & 7 ) );
...@@ -1166,11 +1164,10 @@ Bitmap Bitmap::CreateMask( const Color& rTransColor, sal_uLong nTol ) const ...@@ -1166,11 +1164,10 @@ Bitmap Bitmap::CreateMask( const Color& rTransColor, sal_uLong nTol ) const
} }
else else
{ {
for( nY = 0; nY < nHeight; nY++ ) for (long nY = 0; nY < nHeight; ++nY)
{ {
Scanline pSrc = pReadAcc->GetScanline( nY ); Scanline pSrc = pReadAcc->GetScanline( nY );
long nShift = 0; for (long nX = 0, nShift = nShiftInit; nX < nWidth; nX++, nShift ^= 4)
for( nX = 0, nShift = nShiftInit; nX < nWidth; nX++, nShift ^= 4 )
{ {
if( cTest == ( ( pSrc[ nX >> 1 ] >> nShift ) & 0x0f ) ) if( cTest == ( ( pSrc[ nX >> 1 ] >> nShift ) & 0x0f ) )
pWriteAcc->SetPixel( nY, nX, aWhite ); pWriteAcc->SetPixel( nY, nX, aWhite );
...@@ -1189,11 +1186,11 @@ Bitmap Bitmap::CreateMask( const Color& rTransColor, sal_uLong nTol ) const ...@@ -1189,11 +1186,11 @@ Bitmap Bitmap::CreateMask( const Color& rTransColor, sal_uLong nTol ) const
aWhite.GetIndex() == 1 ) aWhite.GetIndex() == 1 )
{ {
// optimized for 1Bit-MSB destination palette // optimized for 1Bit-MSB destination palette
for( nY = 0; nY < nHeight; nY++ ) for (long nY = 0; nY < nHeight; ++nY)
{ {
Scanline pSrc = pReadAcc->GetScanline( nY ); Scanline pSrc = pReadAcc->GetScanline( nY );
Scanline pDst = pWriteAcc->GetScanline( nY ); Scanline pDst = pWriteAcc->GetScanline( nY );
for( nX = 0; nX < nWidth; nX++ ) for (long nX = 0; nX < nWidth; ++nX)
{ {
if( cTest == pSrc[ nX ] ) if( cTest == pSrc[ nX ] )
pDst[ nX >> 3 ] |= 1 << ( 7 - ( nX & 7 ) ); pDst[ nX >> 3 ] |= 1 << ( 7 - ( nX & 7 ) );
...@@ -1204,10 +1201,10 @@ Bitmap Bitmap::CreateMask( const Color& rTransColor, sal_uLong nTol ) const ...@@ -1204,10 +1201,10 @@ Bitmap Bitmap::CreateMask( const Color& rTransColor, sal_uLong nTol ) const
} }
else else
{ {
for( nY = 0; nY < nHeight; nY++ ) for (long nY = 0; nY < nHeight; ++nY)
{ {
Scanline pSrc = pReadAcc->GetScanline( nY ); Scanline pSrc = pReadAcc->GetScanline( nY );
for( nX = 0; nX < nWidth; nX++ ) for (long nX = 0; nX < nWidth; ++nX)
{ {
if( cTest == pSrc[ nX ] ) if( cTest == pSrc[ nX ] )
pWriteAcc->SetPixel( nY, nX, aWhite ); pWriteAcc->SetPixel( nY, nX, aWhite );
...@@ -1217,12 +1214,25 @@ Bitmap Bitmap::CreateMask( const Color& rTransColor, sal_uLong nTol ) const ...@@ -1217,12 +1214,25 @@ Bitmap Bitmap::CreateMask( const Color& rTransColor, sal_uLong nTol ) const
} }
} }
} }
else if (pWriteAcc->GetScanlineFormat() == pReadAcc->GetScanlineFormat() && aWhite.GetIndex() == 1 &&
(pReadAcc->GetScanlineFormat() == ScanlineFormat::N1BitLsbPal || pReadAcc->GetScanlineFormat() == ScanlineFormat::N1BitMsbPal))
{
for (long nY = 0; nY < nHeight; ++nY)
{
Scanline pSrc = pReadAcc->GetScanline(nY);
Scanline pDst = pWriteAcc->GetScanline(nY);
assert(pWriteAcc->GetScanlineSize() == pReadAcc->GetScanlineSize());
const long nScanlineSize = pWriteAcc->GetScanlineSize();
for (long nX = 0; nX < nScanlineSize; ++nX)
pDst[nX] = ~pSrc[nX];
}
}
else else
{ {
// not optimized // not optimized
for( nY = 0; nY < nHeight; nY++ ) for (long nY = 0; nY < nHeight; ++nY)
{ {
for( nX = 0; nX < nWidth; nX++ ) for (long nX = 0; nX < nWidth; ++nX)
{ {
if( aTest == pReadAcc->GetPixel( nY, nX ) ) if( aTest == pReadAcc->GetPixel( nY, nX ) )
pWriteAcc->SetPixel( nY, nX, aWhite ); pWriteAcc->SetPixel( nY, nX, aWhite );
......
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