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

ofz: speed up bitmap image fuzzing

Change-Id: I73c9ee7aef7062e3cb025c6ae0f3bb6a91485330
Reviewed-on: https://gerrit.libreoffice.org/48983Tested-by: 's avatarJenkins <ci@libreoffice.org>
Reviewed-by: 's avatarCaolán McNamara <caolanm@redhat.com>
Tested-by: 's avatarCaolán McNamara <caolanm@redhat.com>
üst 96ae2a33
......@@ -182,10 +182,11 @@ uno::Reference< graphic::XGraphic > SAL_CALL FrameGrabber::grabFrame( double fMe
for( int y = 0; y < nHeight; ++y )
{
sal_uInt8 *p = pData + y * nStride;
for( int x = 0; x < nWidth; ++x )
Scanline pScanline = pWrite->GetScanline(y);
for (int x = 0; x < nWidth; ++x)
{
BitmapColor col( p[0], p[1], p[2] );
pWrite->SetPixel( y, x, col );
BitmapColor col(p[0], p[1], p[2]);
pWrite->SetPixelOnData(pScanline, x, col);
p += 3;
}
}
......
......@@ -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);
}
}
}
......
......@@ -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)));
}
}
}
......
......@@ -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);
}
}
}
......
......@@ -241,8 +241,9 @@ bool XBMReader::ParseData( SvStream* pInStm, const OString& aLastLine, XBMFormat
if( bProcessed )
{
Scanline pScanline = pAcc1->GetScanline(nRow);
while( ( nCol < nWidth ) && ( nBit < nBits ) )
pAcc1->SetPixel( nRow, nCol++, ( nValue & ( 1 << nBit++ ) ) ? aBlack : aWhite );
pAcc1->SetPixelOnData(pScanline, nCol++, ( nValue & ( 1 << nBit++ ) ) ? aBlack : aWhite);
if( nCol == nWidth )
{
......
......@@ -305,6 +305,8 @@ bool XPMReader::ImplGetScanLine( sal_uLong nY )
bStatus = false;
else
{
Scanline pScanline = mpAcc->GetScanline(nY);
Scanline pMaskScanline = mpMaskAcc ? mpMaskAcc->GetScanline(nY) : nullptr;
for (sal_uLong i = 0; i < mnWidth; ++i)
{
OString aKey(reinterpret_cast<sal_Char*>(pString), mnCpp);
......@@ -312,11 +314,11 @@ bool XPMReader::ImplGetScanLine( sal_uLong nY )
if (it != maColMap.end())
{
if (mnColors > 256)
mpAcc->SetPixel(nY, i, Color(it->second[1], it->second[2], it->second[3]));
mpAcc->SetPixelOnData(pScanline, i, Color(it->second[1], it->second[2], it->second[3]));
else
mpAcc->SetPixel(nY, i, BitmapColor(it->second[1]));
if (mpMaskAcc)
mpMaskAcc->SetPixel(nY, i, it->second[0] ? aWhite : aBlack);
mpAcc->SetPixelOnData(pScanline, i, BitmapColor(it->second[1]));
if (pMaskScanline)
mpMaskAcc->SetPixelOnData(pMaskScanline, i, it->second[0] ? aWhite : aBlack);
}
pString += mnCpp;
}
......
......@@ -376,6 +376,7 @@ bool ImplDecodeRLE(sal_uInt8* pBuffer, DIBV5Header const & rHeader, BitmapWriteA
if( nRunByte > 2 )
{
Scanline pScanline = rAcc.GetScanline(nY);
if( bRLE4 )
{
nCountByte = nRunByte >> 1;
......@@ -388,10 +389,10 @@ bool ImplDecodeRLE(sal_uInt8* pBuffer, DIBV5Header const & rHeader, BitmapWriteA
cTmp = *pRLE++;
if( nX < nWidth )
rAcc.SetPixelIndex(nY, nX++, SanitizePaletteIndex(cTmp >> 4, rPalette, bForceToMonoWhileReading));
rAcc.SetPixelOnData(pScanline, nX++, BitmapColor(SanitizePaletteIndex(cTmp >> 4, rPalette, bForceToMonoWhileReading)));
if( nX < nWidth )
rAcc.SetPixelIndex(nY, nX++, SanitizePaletteIndex(cTmp & 0x0f, rPalette, bForceToMonoWhileReading));
rAcc.SetPixelOnData(pScanline, nX++, BitmapColor(SanitizePaletteIndex(cTmp & 0x0f, rPalette, bForceToMonoWhileReading)));
}
if( nRunByte & 1 )
......@@ -400,7 +401,7 @@ bool ImplDecodeRLE(sal_uInt8* pBuffer, DIBV5Header const & rHeader, BitmapWriteA
return false;
if( nX < nWidth )
rAcc.SetPixelIndex(nY, nX++, SanitizePaletteIndex(*pRLE >> 4, rPalette, bForceToMonoWhileReading));
rAcc.SetPixelOnData(pScanline, nX++, BitmapColor(SanitizePaletteIndex(*pRLE >> 4, rPalette, bForceToMonoWhileReading)));
pRLE++;
}
......@@ -421,7 +422,7 @@ bool ImplDecodeRLE(sal_uInt8* pBuffer, DIBV5Header const & rHeader, BitmapWriteA
return false;
if( nX < nWidth )
rAcc.SetPixelIndex(nY, nX++, SanitizePaletteIndex(*pRLE, rPalette, bForceToMonoWhileReading));
rAcc.SetPixelOnData(pScanline, nX++, BitmapColor(SanitizePaletteIndex(*pRLE, rPalette, bForceToMonoWhileReading)));
pRLE++;
}
......@@ -461,6 +462,7 @@ bool ImplDecodeRLE(sal_uInt8* pBuffer, DIBV5Header const & rHeader, BitmapWriteA
return false;
cTmp = *pRLE++;
Scanline pScanline = rAcc.GetScanline(nY);
if( bRLE4 )
{
nRunByte = nCountByte >> 1;
......@@ -468,19 +470,19 @@ bool ImplDecodeRLE(sal_uInt8* pBuffer, DIBV5Header const & rHeader, BitmapWriteA
for( sal_uLong i = 0; i < nRunByte; i++ )
{
if( nX < nWidth )
rAcc.SetPixelIndex(nY, nX++, SanitizePaletteIndex(cTmp >> 4, rPalette, bForceToMonoWhileReading));
rAcc.SetPixelOnData(pScanline, nX++, BitmapColor(SanitizePaletteIndex(cTmp >> 4, rPalette, bForceToMonoWhileReading)));
if( nX < nWidth )
rAcc.SetPixelIndex(nY, nX++, SanitizePaletteIndex(cTmp & 0x0f, rPalette, bForceToMonoWhileReading));
rAcc.SetPixelOnData(pScanline, nX++, BitmapColor(SanitizePaletteIndex(cTmp & 0x0f, rPalette, bForceToMonoWhileReading)));
}
if( ( nCountByte & 1 ) && ( nX < nWidth ) )
rAcc.SetPixelIndex(nY, nX++, SanitizePaletteIndex(cTmp >> 4, rPalette, bForceToMonoWhileReading));
rAcc.SetPixelOnData(pScanline, nX++, BitmapColor(SanitizePaletteIndex(cTmp >> 4, rPalette, bForceToMonoWhileReading)));
}
else
{
for( sal_uLong i = 0; ( i < nCountByte ) && ( nX < nWidth ); i++ )
rAcc.SetPixelIndex(nY, nX++, SanitizePaletteIndex(cTmp, rPalette, bForceToMonoWhileReading));
rAcc.SetPixelOnData(pScanline, nX++, BitmapColor(SanitizePaletteIndex(cTmp, rPalette, bForceToMonoWhileReading)));
}
}
}
......@@ -584,7 +586,7 @@ bool ImplReadDIBBits(SvStream& rIStm, DIBV5Header& rHeader, BitmapWriteAccess& r
return false;
}
sal_uInt8 cTmp = *pTmp++;
Scanline pScanline = rAcc.GetScanline(nY);
for( long nX = 0, nShift = 8; nX < nWidth; nX++ )
{
if( !nShift )
......@@ -594,7 +596,7 @@ bool ImplReadDIBBits(SvStream& rIStm, DIBV5Header& rHeader, BitmapWriteAccess& r
}
auto nIndex = (cTmp >> --nShift) & 1;
rAcc.SetPixelIndex(nY, nX, SanitizePaletteIndex(nIndex, rPalette, bForceToMonoWhileReading));
rAcc.SetPixelOnData(pScanline, nX, BitmapColor(SanitizePaletteIndex(nIndex, rPalette, bForceToMonoWhileReading)));
}
}
}
......@@ -611,7 +613,7 @@ bool ImplReadDIBBits(SvStream& rIStm, DIBV5Header& rHeader, BitmapWriteAccess& r
return false;
}
sal_uInt8 cTmp = *pTmp++;
Scanline pScanline = rAcc.GetScanline(nY);
for( long nX = 0, nShift = 2; nX < nWidth; nX++ )
{
if( !nShift )
......@@ -621,7 +623,7 @@ bool ImplReadDIBBits(SvStream& rIStm, DIBV5Header& rHeader, BitmapWriteAccess& r
}
auto nIndex = (cTmp >> ( --nShift << 2 ) ) & 0x0f;
rAcc.SetPixelIndex(nY, nX, SanitizePaletteIndex(nIndex, rPalette, bForceToMonoWhileReading));
rAcc.SetPixelOnData(pScanline, nX, BitmapColor(SanitizePaletteIndex(nIndex, rPalette, bForceToMonoWhileReading)));
}
}
}
......@@ -638,10 +640,11 @@ bool ImplReadDIBBits(SvStream& rIStm, DIBV5Header& rHeader, BitmapWriteAccess& r
return false;
}
Scanline pScanline = rAcc.GetScanline(nY);
for( long nX = 0; nX < nWidth; nX++ )
{
auto nIndex = *pTmp++;
rAcc.SetPixelIndex(nY, nX, SanitizePaletteIndex(nIndex, rPalette, bForceToMonoWhileReading));
rAcc.SetPixelOnData(pScanline, nX, BitmapColor(SanitizePaletteIndex(nIndex, rPalette, bForceToMonoWhileReading)));
}
}
}
......@@ -671,10 +674,11 @@ bool ImplReadDIBBits(SvStream& rIStm, DIBV5Header& rHeader, BitmapWriteAccess& r
return false;
}
Scanline pScanline = rAcc.GetScanline(nY);
for( long nX = 0; nX < nWidth; nX++ )
{
aMask.GetColorFor16BitLSB( aColor, reinterpret_cast<sal_uInt8*>(pTmp16++) );
rAcc.SetPixel(nY, nX, SanitizeColor(aColor, bForceToMonoWhileReading));
rAcc.SetPixelOnData(pScanline, nX, SanitizeColor(aColor, bForceToMonoWhileReading));
}
}
}
......@@ -693,12 +697,13 @@ bool ImplReadDIBBits(SvStream& rIStm, DIBV5Header& rHeader, BitmapWriteAccess& r
return false;
}
Scanline pScanline = rAcc.GetScanline(nY);
for( long nX = 0; nX < nWidth; nX++ )
{
aPixelColor.SetBlue( *pTmp++ );
aPixelColor.SetGreen( *pTmp++ );
aPixelColor.SetRed( *pTmp++ );
rAcc.SetPixel(nY, nX, SanitizeColor(aPixelColor, bForceToMonoWhileReading));
rAcc.SetPixelOnData(pScanline, nX, SanitizeColor(aPixelColor, bForceToMonoWhileReading));
}
}
}
......@@ -733,11 +738,13 @@ bool ImplReadDIBBits(SvStream& rIStm, DIBV5Header& rHeader, BitmapWriteAccess& r
return false;
}
Scanline pScanline = rAcc.GetScanline(nY);
Scanline pAlphaScanline = pAccAlpha->GetScanline(nY);
for( long nX = 0; nX < nWidth; nX++ )
{
aMask.GetColorAndAlphaFor32Bit( aColor, aAlpha, reinterpret_cast<sal_uInt8*>(pTmp32++) );
rAcc.SetPixel(nY, nX, SanitizeColor(aColor, bForceToMonoWhileReading));
pAccAlpha->SetPixelIndex(nY, nX, sal_uInt8(0xff) - aAlpha);
rAcc.SetPixelOnData(pScanline, nX, SanitizeColor(aColor, bForceToMonoWhileReading));
pAccAlpha->SetPixelOnData(pAlphaScanline, nX, BitmapColor(sal_uInt8(0xff) - aAlpha));
rAlphaUsed |= 0xff != aAlpha;
}
}
......@@ -753,10 +760,11 @@ bool ImplReadDIBBits(SvStream& rIStm, DIBV5Header& rHeader, BitmapWriteAccess& r
return false;
}
Scanline pScanline = rAcc.GetScanline(nY);
for( long nX = 0; nX < nWidth; nX++ )
{
aMask.GetColorFor32Bit( aColor, reinterpret_cast<sal_uInt8*>(pTmp32++) );
rAcc.SetPixel(nY, nX, SanitizeColor(aColor, bForceToMonoWhileReading));
rAcc.SetPixelOnData(pScanline, nX, SanitizeColor(aColor, bForceToMonoWhileReading));
}
}
}
......
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