vcl/source/gdi/bitmap.cxx | 36 +++++++++++++++++++++++------------- 1 file changed, 23 insertions(+), 13 deletions(-)
New commits: commit ac5ecfeb5dd8578ca37876b6e0b23911d7cdae1c Author: Caolán McNamara <caol...@redhat.com> Date: Mon Oct 16 11:08:47 2017 +0100 ofz: optimize 1bit mask to avoid timeout Change-Id: Ieaf3eb0800d2e80f16cfa29718d752e43ad534d0 Reviewed-on: https://gerrit.libreoffice.org/43418 Reviewed-by: Caolán McNamara <caol...@redhat.com> Tested-by: Caolán McNamara <caol...@redhat.com> (cherry picked from commit 035751dd33550def4a269a01eaae74fcaf8f5ecc) Reviewed-on: https://gerrit.libreoffice.org/45457 Reviewed-by: Ashod Nakashian <ashnak...@gmail.com> Tested-by: Ashod Nakashian <ashnak...@gmail.com> diff --git a/vcl/source/gdi/bitmap.cxx b/vcl/source/gdi/bitmap.cxx index e7490fb846f8..b29d94f6d4d9 100644 --- a/vcl/source/gdi/bitmap.cxx +++ b/vcl/source/gdi/bitmap.cxx @@ -1144,7 +1144,6 @@ Bitmap Bitmap::CreateMask( const Color& rTransColor, sal_uLong nTol ) const if( !nTol ) { const BitmapColor aTest( pReadAcc->GetBestMatchingColor( rTransColor ) ); - long nX, nY; if( pReadAcc->GetScanlineFormat() == ScanlineFormat::N4BitMsnPal || pReadAcc->GetScanlineFormat() == ScanlineFormat::N4BitLsnPal ) @@ -1157,12 +1156,11 @@ Bitmap Bitmap::CreateMask( const Color& rTransColor, sal_uLong nTol ) const aWhite.GetIndex() == 1 ) { // 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 pDst = pWriteAcc->GetScanline( nY ); - long nShift = 0; - for( nX = 0, nShift = nShiftInit; nX < nWidth; nX++, nShift ^= 4 ) + for (long nX = 0, nShift = nShiftInit; nX < nWidth; nX++, nShift ^= 4) { if( cTest == ( ( pSrc[ nX >> 1 ] >> nShift ) & 0x0f ) ) pDst[ nX >> 3 ] |= 1 << ( 7 - ( nX & 7 ) ); @@ -1173,11 +1171,10 @@ Bitmap Bitmap::CreateMask( const Color& rTransColor, sal_uLong nTol ) const } else { - for( nY = 0; nY < nHeight; nY++ ) + for (long nY = 0; nY < nHeight; ++nY) { Scanline pSrc = pReadAcc->GetScanline( nY ); - long nShift = 0; - for( nX = 0, nShift = nShiftInit; nX < nWidth; nX++, nShift ^= 4 ) + for (long nX = 0, nShift = nShiftInit; nX < nWidth; nX++, nShift ^= 4) { if( cTest == ( ( pSrc[ nX >> 1 ] >> nShift ) & 0x0f ) ) pWriteAcc->SetPixel( nY, nX, aWhite ); @@ -1196,11 +1193,11 @@ Bitmap Bitmap::CreateMask( const Color& rTransColor, sal_uLong nTol ) const aWhite.GetIndex() == 1 ) { // 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 pDst = pWriteAcc->GetScanline( nY ); - for( nX = 0; nX < nWidth; nX++ ) + for (long nX = 0; nX < nWidth; ++nX) { if( cTest == pSrc[ nX ] ) pDst[ nX >> 3 ] |= 1 << ( 7 - ( nX & 7 ) ); @@ -1211,10 +1208,10 @@ Bitmap Bitmap::CreateMask( const Color& rTransColor, sal_uLong nTol ) const } else { - for( nY = 0; nY < nHeight; nY++ ) + for (long nY = 0; nY < nHeight; ++nY) { Scanline pSrc = pReadAcc->GetScanline( nY ); - for( nX = 0; nX < nWidth; nX++ ) + for (long nX = 0; nX < nWidth; ++nX) { if( cTest == pSrc[ nX ] ) pWriteAcc->SetPixel( nY, nX, aWhite ); @@ -1224,12 +1221,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 { // 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 ) ) pWriteAcc->SetPixel( nY, nX, aWhite );
_______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits