diff options
author | Caolán McNamara <caolanm@redhat.com> | 2018-01-31 10:32:11 +0000 |
---|---|---|
committer | Caolán McNamara <caolanm@redhat.com> | 2018-01-31 14:48:54 +0100 |
commit | a3251b83e3fb49b5dc28dde8825f71d0e468f4bb (patch) | |
tree | e85ed4c859a898e374d011829be65546298f02a8 /filter | |
parent | 96ae2a3300811897c24cccb20f8c2faf382483df (diff) |
ofz: speed up bitmap image fuzzing
Change-Id: I73c9ee7aef7062e3cb025c6ae0f3bb6a91485330
Reviewed-on: https://gerrit.libreoffice.org/48983
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Caolán McNamara <caolanm@redhat.com>
Tested-by: Caolán McNamara <caolanm@redhat.com>
Diffstat (limited to 'filter')
-rw-r--r-- | filter/source/graphicfilter/icgm/bitmap.cxx | 19 | ||||
-rw-r--r-- | filter/source/graphicfilter/ipict/ipict.cxx | 108 | ||||
-rw-r--r-- | filter/source/graphicfilter/itiff/itiff.cxx | 22 | ||||
-rw-r--r-- | filter/source/msfilter/msdffimp.cxx | 8 |
4 files changed, 88 insertions, 69 deletions
diff --git a/filter/source/graphicfilter/icgm/bitmap.cxx b/filter/source/graphicfilter/icgm/bitmap.cxx index eb2f337d8e4b..bcc08874b292 100644 --- a/filter/source/graphicfilter/icgm/bitmap.cxx +++ b/filter/source/graphicfilter/icgm/bitmap.cxx @@ -94,9 +94,10 @@ void CGMBitmap::ImplGetBitmap( CGMBitmapDescriptor& rDesc ) for ( ny = 0; --nyCount ; ny++, rDesc.mpBuf += rDesc.mnScanSize ) { nxC = nxCount; + Scanline pScanline = rDesc.mpAcc->GetScanline(ny); for ( nx = 0; --nxC; nx++ ) { // this is not fast, but a one bit/pixel format is rarely used - rDesc.mpAcc->SetPixelIndex( ny, nx, static_cast<sal_uInt8>( (*( rDesc.mpBuf + (nx >> 3)) >> ((nx & 7)^7))) & 1 ); + rDesc.mpAcc->SetPixelOnData(pScanline, nx, BitmapColor(static_cast<sal_uInt8>( (*( rDesc.mpBuf + (nx >> 3)) >> ((nx & 7)^7))) & 1)); } } } @@ -108,9 +109,10 @@ void CGMBitmap::ImplGetBitmap( CGMBitmapDescriptor& rDesc ) for ( ny = 0; --nyCount; ny++, rDesc.mpBuf += rDesc.mnScanSize ) { nxC = nxCount; + Scanline pScanline = rDesc.mpAcc->GetScanline(ny); for ( nx = 0; --nxC; nx++ ) { // this is not fast, but a two bits/pixel format is rarely used - rDesc.mpAcc->SetPixelIndex( ny, nx, static_cast<sal_uInt8>( (*(rDesc.mpBuf + (nx >> 2)) >> (((nx & 3)^3) << 1))) & 3 ); + rDesc.mpAcc->SetPixelOnData(pScanline, nx, BitmapColor(static_cast<sal_uInt8>( (*(rDesc.mpBuf + (nx >> 2)) >> (((nx & 3)^3) << 1))) & 3)); } } } @@ -127,11 +129,12 @@ void CGMBitmap::ImplGetBitmap( CGMBitmapDescriptor& rDesc ) for ( nx = 0; --nxC; nx++ ) { nDat = *pTemp++; - rDesc.mpAcc->SetPixelIndex( ny, nx, static_cast<sal_uInt8>(nDat >> 4) ); + Scanline pScanline = rDesc.mpAcc->GetScanline(ny); + rDesc.mpAcc->SetPixelOnData(pScanline, nx, BitmapColor(static_cast<sal_uInt8>(nDat >> 4))); if ( --nxC ) { - nx ++; - rDesc.mpAcc->SetPixelIndex( ny, nx, static_cast<sal_uInt8>(nDat & 15) ); + ++nx; + rDesc.mpAcc->SetPixelOnData(pScanline, nx, BitmapColor(static_cast<sal_uInt8>(nDat & 15))); } else break; @@ -146,10 +149,11 @@ void CGMBitmap::ImplGetBitmap( CGMBitmapDescriptor& rDesc ) for ( ny = 0; --nyCount; ny++, rDesc.mpBuf += rDesc.mnScanSize ) { sal_uInt8* pTemp = rDesc.mpBuf; + Scanline pScanline = rDesc.mpAcc->GetScanline(ny); nxC = nxCount; for ( nx = 0; --nxC; nx++ ) { - rDesc.mpAcc->SetPixelIndex( ny, nx, *(pTemp++) ); + rDesc.mpAcc->SetPixelOnData(pScanline, nx, BitmapColor(*(pTemp++))); } } } @@ -162,12 +166,13 @@ void CGMBitmap::ImplGetBitmap( CGMBitmapDescriptor& rDesc ) { sal_uInt8* pTemp = rDesc.mpBuf; nxC = nxCount; + Scanline pScanline = rDesc.mpAcc->GetScanline(ny); for ( nx = 0; --nxC; nx++ ) { aBitmapColor.SetRed( *pTemp++ ); aBitmapColor.SetGreen( *pTemp++ ); aBitmapColor.SetBlue( *pTemp++ ); - rDesc.mpAcc->SetPixel( ny, nx, aBitmapColor ); + rDesc.mpAcc->SetPixelOnData(pScanline, nx, aBitmapColor); } } } diff --git a/filter/source/graphicfilter/ipict/ipict.cxx b/filter/source/graphicfilter/ipict/ipict.cxx index 323501eaffeb..8239fe05bed2 100644 --- a/filter/source/graphicfilter/ipict/ipict.cxx +++ b/filter/source/graphicfilter/ipict/ipict.cxx @@ -238,8 +238,9 @@ private: void SetLineColor( const Color& rColor ); void SetFillColor( const Color& rColor ); - // OSNOLA: returns the text encoding which must be used for system id - static rtl_TextEncoding GetTextEncoding (sal_uInt16 fId = 0xFFFF); + // OSNOLA: returns the text encoding which must be used for system id + static rtl_TextEncoding GetTextEncoding (sal_uInt16 fId = 0xFFFF); + public: PictReader() @@ -258,46 +259,46 @@ public: }; - -#define SETBYTE \ - switch ( nPixelSize ) \ - { \ - case 1 : \ - pAcc->SetPixelIndex( ny, nx++, nDat >> 7 ); \ - if ( nx == nWidth ) break; \ - pAcc->SetPixelIndex( ny, nx++, nDat >> 6 ); \ - if ( nx == nWidth ) break; \ - pAcc->SetPixelIndex( ny, nx++, nDat >> 5 ); \ - if ( nx == nWidth ) break; \ - pAcc->SetPixelIndex( ny, nx++, nDat >> 4 ); \ - if ( nx == nWidth ) break; \ - pAcc->SetPixelIndex( ny, nx++, nDat >> 3 ); \ - if ( nx == nWidth ) break; \ - pAcc->SetPixelIndex( ny, nx++, nDat >> 2 ); \ - if ( nx == nWidth ) break; \ - pAcc->SetPixelIndex( ny, nx++, nDat >> 1 ); \ - if ( nx == nWidth ) break; \ - pAcc->SetPixelIndex( ny, nx++, nDat ); \ - break; \ - case 2 : \ - pAcc->SetPixelIndex( ny, nx++, nDat >> 6 ); \ - if ( nx == nWidth ) break; \ - pAcc->SetPixelIndex( ny, nx++, (nDat>>4)&3);\ - if ( nx == nWidth ) break; \ - pAcc->SetPixelIndex( ny, nx++, (nDat>>2)&3 );\ - if ( nx == nWidth ) break; \ - pAcc->SetPixelIndex( ny, nx++, nDat & 3); \ - break; \ - case 4 : \ - pAcc->SetPixelIndex( ny, nx++, nDat >> 4 ); \ - if ( nx == nWidth ) break; \ - pAcc->SetPixelIndex( ny, nx++, nDat ); \ - break; \ - case 8 : \ - pAcc->SetPixelIndex( ny, nx++, nDat ); \ - break; \ +static void SetByte(sal_uInt16& nx, Scanline pScanline, BitmapWriteAccess* pAcc, sal_uInt16 nPixelSize, sal_uInt8 nDat, sal_uInt16 nWidth) +{ + switch (nPixelSize) + { + case 1: + pAcc->SetPixelOnData(pScanline, nx++, BitmapColor(nDat >> 7)); + if ( nx == nWidth ) break; + pAcc->SetPixelOnData(pScanline, nx++, BitmapColor(nDat >> 6)); + if ( nx == nWidth ) break; + pAcc->SetPixelOnData(pScanline, nx++, BitmapColor(nDat >> 5)); + if ( nx == nWidth ) break; + pAcc->SetPixelOnData(pScanline, nx++, BitmapColor(nDat >> 4)); + if ( nx == nWidth ) break; + pAcc->SetPixelOnData(pScanline, nx++, BitmapColor(nDat >> 3)); + if ( nx == nWidth ) break; + pAcc->SetPixelOnData(pScanline, nx++, BitmapColor(nDat >> 2)); + if ( nx == nWidth ) break; + pAcc->SetPixelOnData(pScanline, nx++, BitmapColor(nDat >> 1)); + if ( nx == nWidth ) break; + pAcc->SetPixelOnData(pScanline, nx++, BitmapColor(nDat)); + break; + case 2: + pAcc->SetPixelOnData(pScanline, nx++, BitmapColor(nDat >> 6)); + if ( nx == nWidth ) break; + pAcc->SetPixelOnData(pScanline, nx++, BitmapColor((nDat>>4)&3)); + if ( nx == nWidth ) break; + pAcc->SetPixelOnData(pScanline, nx++, BitmapColor((nDat>>2)&3)); + if ( nx == nWidth ) break; + pAcc->SetPixelOnData(pScanline, nx++, BitmapColor(nDat & 3)); + break; + case 4: + pAcc->SetPixelOnData(pScanline, nx++, BitmapColor(nDat >> 4)); + if ( nx == nWidth ) break; + pAcc->SetPixelOnData(pScanline, nx++, BitmapColor(nDat)); + break; + case 8: + pAcc->SetPixelOnData(pScanline, nx++, BitmapColor(nDat)); + break; } - +} #define BITMAPERROR \ { \ @@ -876,6 +877,7 @@ sal_uLong PictReader::ReadPixMapEtc( Bitmap &rBitmap, bool bBaseAddr, bool bColo for (sal_uInt16 ny = 0; ny < nHeight; ++ny) { + Scanline pScanline = pAcc->GetScanline(ny); sal_uInt16 nx = 0; if ( nRowBytes < 8 || nPackType == 1 ) { @@ -883,7 +885,7 @@ sal_uLong PictReader::ReadPixMapEtc( Bitmap &rBitmap, bool bBaseAddr, bool bColo { pPict->ReadUChar( nDat ); if ( nx < nWidth ) - SETBYTE; + SetByte(nx, pScanline, pAcc, nPixelSize, nDat, nWidth); } nDataSize += nRowBytes; } @@ -914,7 +916,7 @@ sal_uLong PictReader::ReadPixMapEtc( Bitmap &rBitmap, bool bBaseAddr, bool bColo { pPict->ReadUChar( nDat ); if ( nx < nWidth ) - SETBYTE; + SetByte(nx, pScanline, pAcc, nPixelSize, nDat, nWidth); } nByteCount -= 1 + nCount; } @@ -925,7 +927,7 @@ sal_uLong PictReader::ReadPixMapEtc( Bitmap &rBitmap, bool bBaseAddr, bool bColo for (size_t i = 0; i < nCount; ++i) { if ( nx < nWidth ) - SETBYTE; + SetByte(nx, pScanline, pAcc, nPixelSize, nDat, nWidth); } nByteCount -= 2; } @@ -962,13 +964,14 @@ sal_uLong PictReader::ReadPixMapEtc( Bitmap &rBitmap, bool bBaseAddr, bool bColo sal_uInt16 nx = 0; if ( nRowBytes < 8 || nPackType == 1 ) { + Scanline pScanline = pAcc->GetScanline(ny); for (size_t i = 0; i < nWidth; ++i) { pPict->ReadUInt16( nD ); nRed = static_cast<sal_uInt8>( nD >> 7 ); nGreen = static_cast<sal_uInt8>( nD >> 2 ); nBlue = static_cast<sal_uInt8>( nD << 3 ); - pAcc->SetPixel( ny, nx++, BitmapColor( nRed, nGreen, nBlue ) ); + pAcc->SetPixelOnData(pScanline, nx++, BitmapColor(nRed, nGreen, nBlue)); } nDataSize += static_cast<sal_uLong>(nWidth) * 2; } @@ -1001,13 +1004,14 @@ sal_uLong PictReader::ReadPixMapEtc( Bitmap &rBitmap, bool bBaseAddr, bool bColo this case. Have a look at 32bit, there I changed the encoding, so that it is used a straight forward array */ + Scanline pScanline = pAcc->GetScanline(ny); for (size_t i = 0; i < nCount; ++i) { pPict->ReadUInt16( nD ); nRed = static_cast<sal_uInt8>( nD >> 7 ); nGreen = static_cast<sal_uInt8>( nD >> 2 ); nBlue = static_cast<sal_uInt8>( nD << 3 ); - pAcc->SetPixel( ny, nx++, BitmapColor( nRed, nGreen, nBlue ) ); + pAcc->SetPixelOnData(pScanline, nx++, BitmapColor(nRed, nGreen, nBlue)); } } else @@ -1021,9 +1025,10 @@ sal_uLong PictReader::ReadPixMapEtc( Bitmap &rBitmap, bool bBaseAddr, bool bColo nRed = static_cast<sal_uInt8>( nD >> 7 ); nGreen = static_cast<sal_uInt8>( nD >> 2 ); nBlue = static_cast<sal_uInt8>( nD << 3 ); + Scanline pScanline = pAcc->GetScanline(ny); for (size_t i = 0; i < nCount; ++i) { - pAcc->SetPixel( ny, nx++, BitmapColor( nRed, nGreen, nBlue ) ); + pAcc->SetPixelOnData(pScanline, nx++, BitmapColor(nRed, nGreen, nBlue)); } } } @@ -1056,11 +1061,12 @@ sal_uLong PictReader::ReadPixMapEtc( Bitmap &rBitmap, bool bBaseAddr, bool bColo for (sal_uInt16 ny = 0; ny < nHeight; ++ny) { + Scanline pScanline = pAcc->GetScanline(ny); for (sal_uInt16 nx = 0; nx < nWidth; ++nx) { sal_uInt8 nDummy; pPict->ReadUChar( nDummy ).ReadUChar( nRed ).ReadUChar( nGreen ).ReadUChar( nBlue ); - pAcc->SetPixel( ny, nx, BitmapColor( nRed, nGreen, nBlue) ); + pAcc->SetPixelOnData(pScanline, nx, BitmapColor(nRed, nGreen, nBlue)); } nDataSize += static_cast<sal_uLong>(nWidth) * 4; } @@ -1080,10 +1086,11 @@ sal_uLong PictReader::ReadPixMapEtc( Bitmap &rBitmap, bool bBaseAddr, bool bColo for (sal_uInt16 ny = 0; ny < nHeight; ++ny) { + Scanline pScanline = pAcc->GetScanline(ny); for (sal_uInt16 nx = 0; nx < nWidth; ++nx) { pPict->ReadUChar( nRed ).ReadUChar( nGreen ).ReadUChar( nBlue ); - pAcc->SetPixel( ny, nx, BitmapColor( nRed, nGreen, nBlue ) ); + pAcc->SetPixelOnData(pScanline, nx, BitmapColor(nRed, nGreen, nBlue)); } nDataSize += static_cast<sal_uLong>(nWidth) * 3; } @@ -1149,8 +1156,9 @@ sal_uLong PictReader::ReadPixMapEtc( Bitmap &rBitmap, bool bBaseAddr, bool bColo sal_uInt8* pTmp = aScanline.data(); if ( nCmpCount == 4 ) pTmp += nWidth; + Scanline pScanline = pAcc->GetScanline(ny); for (sal_uInt16 nx = 0; nx < nWidth; pTmp++) - pAcc->SetPixel( ny, nx++, BitmapColor( *pTmp, pTmp[ nWidth ], pTmp[ 2 * nWidth ] ) ); + pAcc->SetPixelOnData(pScanline, nx++, BitmapColor(*pTmp, pTmp[ nWidth ], pTmp[ 2 * nWidth ])); nDataSize += static_cast<sal_uLong>(nByteCount); pPict->Seek( nSrcBitsPos + static_cast<sal_uLong>(nByteCount) ); } diff --git a/filter/source/graphicfilter/itiff/itiff.cxx b/filter/source/graphicfilter/itiff/itiff.cxx index ed80d69dc72a..6e7bb2461eac 100644 --- a/filter/source/graphicfilter/itiff/itiff.cxx +++ b/filter/source/graphicfilter/itiff/itiff.cxx @@ -789,6 +789,10 @@ bool TIFFReader::ConvertScanline(sal_Int32 nY) { sal_uInt8* pt = getMapData(0); + Scanline pMaskScanLine = nullptr; + if (nSamplesPerPixel >= 4 && xMaskAcc) + pMaskScanLine = xMaskAcc->GetScanline(nY); + // are the values being saved as difference? if ( 2 == nPredictor ) { @@ -801,11 +805,11 @@ bool TIFFReader::ConvertScanline(sal_Int32 nY) nLRed = nLRed + pt[ 0 ]; nLGreen = nLGreen + pt[ 1 ]; nLBlue = nLBlue + pt[ 2 ]; - pAcc->SetPixel( nY, nx, Color( nLRed, nLGreen, nLBlue ) ); - if (nSamplesPerPixel >= 4 && xMaskAcc) + pAcc->SetPixelOnData(pScanLine, nx, Color(nLRed, nLGreen, nLBlue)); + if (pMaskScanLine) { nLAlpha = nLAlpha + pt[ 3 ]; - xMaskAcc->SetPixel( nY, nx, BitmapColor(~nLAlpha) ); + xMaskAcc->SetPixelOnData(pMaskScanLine, nx, BitmapColor(~nLAlpha)); } } } @@ -813,11 +817,11 @@ bool TIFFReader::ConvertScanline(sal_Int32 nY) { for (sal_Int32 nx = 0; nx < nImageWidth; nx++, pt += nSamplesPerPixel) { - pAcc->SetPixel( nY, nx, Color( pt[0], pt[1], pt[2] ) ); - if (nSamplesPerPixel >= 4 && xMaskAcc) + pAcc->SetPixelOnData(pScanLine, nx, Color(pt[0], pt[1], pt[2])); + if (pMaskScanLine) { sal_uInt8 nAlpha = pt[3]; - xMaskAcc->SetPixel( nY, nx, BitmapColor(~nAlpha) ); + xMaskAcc->SetPixelOnData(pMaskScanLine, nx, BitmapColor(~nAlpha)); } } } @@ -841,7 +845,7 @@ bool TIFFReader::ConvertScanline(sal_Int32 nY) nGreen = GetBits( getMapData(1), nx * nBitsPerSample, nBitsPerSample ); nBlue = GetBits( getMapData(2), nx * nBitsPerSample, nBitsPerSample ); } - pAcc->SetPixel( nY, nx, Color( static_cast<sal_uInt8>( nRed - nMinMax ), static_cast<sal_uInt8>( nGreen - nMinMax ), static_cast<sal_uInt8>(nBlue - nMinMax) ) ); + pAcc->SetPixelOnData(pScanLine, nx, Color(static_cast<sal_uInt8>(nRed - nMinMax), static_cast<sal_uInt8>(nGreen - nMinMax), static_cast<sal_uInt8>(nBlue - nMinMax))); } } } @@ -867,7 +871,7 @@ bool TIFFReader::ConvertScanline(sal_Int32 nY) nRed = 255 - static_cast<sal_uInt8>( nRed - nMinMax ); nGreen = 255 - static_cast<sal_uInt8>( nGreen - nMinMax ); nBlue = 255 - static_cast<sal_uInt8>( nBlue - nMinMax ); - pAcc->SetPixel( nY, nx, Color( static_cast<sal_uInt8>(nRed), static_cast<sal_uInt8>(nGreen), static_cast<sal_uInt8>(nBlue) ) ); + pAcc->SetPixelOnData(pScanLine, nx, Color(static_cast<sal_uInt8>(nRed), static_cast<sal_uInt8>(nGreen), static_cast<sal_uInt8>(nBlue))); } } } @@ -909,7 +913,7 @@ bool TIFFReader::ConvertScanline(sal_Int32 nY) 255L/static_cast<sal_Int32>(nMaxSampleValue-nMinSampleValue) ) )); nBlue = static_cast<sal_uInt8>(std::max( 0L, 255L - ( ( static_cast<sal_Int32>(nSamp[ 2 ]) + nBlack - ( static_cast<sal_Int32>(nMinSampleValue) << 1 ) ) * 255L/static_cast<sal_Int32>(nMaxSampleValue-nMinSampleValue) ) )); - pAcc->SetPixel( nY, nx, Color ( static_cast<sal_uInt8>(nRed), static_cast<sal_uInt8>(nGreen), static_cast<sal_uInt8>(nBlue) ) ); + pAcc->SetPixelOnData(pScanLine, nx, Color(static_cast<sal_uInt8>(nRed), static_cast<sal_uInt8>(nGreen), static_cast<sal_uInt8>(nBlue))); } } } diff --git a/filter/source/msfilter/msdffimp.cxx b/filter/source/msfilter/msdffimp.cxx index f840ee3fce62..b07351a3389e 100644 --- a/filter/source/msfilter/msdffimp.cxx +++ b/filter/source/msfilter/msdffimp.cxx @@ -1117,6 +1117,7 @@ void ApplyRectangularGradientAsBitmap( const SvxMSDffManager& rManager, SvStream { for ( long nY = 0; nY < aBitmapSizePixel.Height(); nY++ ) { + Scanline pScanline = pAcc->GetScanline(nY); for ( long nX = 0; nX < aBitmapSizePixel.Width(); nX++ ) { double fX = static_cast< double >( nX ) / aBitmapSizePixel.Width(); @@ -1233,7 +1234,7 @@ void ApplyRectangularGradientAsBitmap( const SvxMSDffManager& rManager, SvStream if ( nBlue > 255 ) nBlue = 255; - pAcc->SetPixel( nY, nX, BitmapColor( static_cast< sal_Int8 >( nRed ), static_cast< sal_Int8 >( nGreen ), static_cast< sal_Int8 >( nBlue ) ) ); + pAcc->SetPixelOnData(pScanline, nX, BitmapColor(static_cast<sal_Int8>(nRed), static_cast<sal_Int8>(nGreen), static_cast<sal_Int8>(nBlue))); } } Bitmap::ReleaseAccess( pAcc ); @@ -1376,6 +1377,7 @@ void DffPropertyReader::ApplyFillAttributes( SvStream& rIn, SfxItemSet& rSet, co for (long y = 0; y < pWrite->Height(); ++y) { + Scanline pScanline = pWrite->GetScanline(y); for (long x = 0; x < pWrite->Width(); ++x) { Color aReadColor; @@ -1385,9 +1387,9 @@ void DffPropertyReader::ApplyFillAttributes( SvStream& rIn, SfxItemSet& rSet, co aReadColor = pRead->GetPixel(y, x); if (aReadColor.GetColor() == 0) - pWrite->SetPixel(y, x, aCol2); + pWrite->SetPixelOnData(pScanline, x, aCol2); else - pWrite->SetPixel(y, x, aCol1); + pWrite->SetPixelOnData(pScanline, x, aCol1); } } } |