From 77809fba7d4bf5e0b604ffa3937c18d5530c2d56 Mon Sep 17 00:00:00 2001 From: Luboš Luňák Date: Fri, 9 Oct 2020 19:28:49 +0200 Subject: implement ImplFastBitmapConversion() for 8bit gray source MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit With some documents SvpSalGraphics::drawTransformedBitmap() ends up calling StretchAndConvert() with 8bit grayscale source bitmap (e.g. OutputDevice::DrawTransformBitmapExDirect() uses them as dummy alpha masks). But ImplFastBitmapConversion() doesn't handle this case, so StretchAndConvert() falls back to doing it manually, easily making this 3x slower. But 8bit grayscale bitmaps sort of are actually non-paletted, so this is easy to optimize. Change-Id: I93aa3f283c8a182d76f3aa267ebd471e63d945e8 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/104129 Tested-by: Jenkins Reviewed-by: Luboš Luňák --- vcl/source/gdi/bmpfast.cxx | 34 ++++++++++++++++++++++------------ 1 file changed, 22 insertions(+), 12 deletions(-) (limited to 'vcl/source/gdi/bmpfast.cxx') diff --git a/vcl/source/gdi/bmpfast.cxx b/vcl/source/gdi/bmpfast.cxx index 76a5239d4ceb..5528d9fcf455 100644 --- a/vcl/source/gdi/bmpfast.cxx +++ b/vcl/source/gdi/bmpfast.cxx @@ -173,20 +173,21 @@ public: } }; +// This assumes the content uses the grayscale palette (needs to be checked +// by code allowing the use of the format). +// Only reading color is implemented, since e.g. 24bpp input couldn't be +// easily guaranteed to be grayscale. template <> -class TrueColorPixelPtr : public BasePixelPtr +class TrueColorPixelPtr : public BasePixelPtr { public: void operator++() { mpPixel += 1; } - PIXBYTE GetAlpha() const { return mpPixel[0]; } -}; -// TODO: for some reason many Alpha maps are ScanlineFormat::N8BitPal -// they should be ScanlineFormat::N8BitTcMask -template <> -class TrueColorPixelPtr -: public TrueColorPixelPtr -{}; + PIXBYTE GetRed() const { return mpPixel[0]; } + PIXBYTE GetGreen() const { return mpPixel[0]; } + PIXBYTE GetBlue() const { return mpPixel[0]; } + static PIXBYTE GetAlpha() { return 255; } +}; } @@ -251,7 +252,8 @@ static void ImplBlendLines( const TrueColorPixelPtr& rDst, TrueColorPixelPtr aSrc( rSrc ); while( --nPixelCount >= 0 ) { - ImplBlendPixels(aDst, aSrc, aMsk.GetAlpha()); + // VCL masks store alpha as color, hence the GetRed() and not GetAlpha(). + ImplBlendPixels(aDst, aSrc, aMsk.GetRed()); ++aDst; ++aSrc; ++aMsk; @@ -424,7 +426,6 @@ bool ImplFastBitmapConversion( BitmapBuffer& rDst, const BitmapBuffer& rSrc, case ScanlineFormat::N1BitLsbPal: case ScanlineFormat::N4BitMsnPal: case ScanlineFormat::N4BitLsnPal: - case ScanlineFormat::N8BitPal: break; case ScanlineFormat::N8BitTcMask: @@ -433,6 +434,11 @@ bool ImplFastBitmapConversion( BitmapBuffer& rDst, const BitmapBuffer& rSrc, // return ImplConvertFromBitmap( rDst, rSrc ); break; + case ScanlineFormat::N8BitPal: + if(rSrc.maPalette.IsGreyPalette8Bit()) + return ImplConvertFromBitmap( rDst, rSrc ); + break; + case ScanlineFormat::N24BitTcBgr: return ImplConvertFromBitmap( rDst, rSrc ); case ScanlineFormat::N24BitTcRgb: @@ -737,7 +743,6 @@ bool ImplFastBitmapBlending( BitmapWriteAccess const & rDstWA, case ScanlineFormat::N1BitLsbPal: case ScanlineFormat::N4BitMsnPal: case ScanlineFormat::N4BitLsnPal: - case ScanlineFormat::N8BitPal: break; case ScanlineFormat::N8BitTcMask: @@ -746,6 +751,11 @@ bool ImplFastBitmapBlending( BitmapWriteAccess const & rDstWA, // return ImplBlendFromBitmap( rDst, rSrc ); break; + case ScanlineFormat::N8BitPal: + if(rSrc.maPalette.IsGreyPalette8Bit()) + return ImplBlendFromBitmap( rDst, rSrc, rMsk ); + break; + case ScanlineFormat::N24BitTcBgr: return ImplBlendFromBitmap( rDst, rSrc, rMsk ); case ScanlineFormat::N24BitTcRgb: -- cgit