[Libreoffice-commits] core.git: vcl/source

Luboš Luňák (via logerrit) logerrit at kemper.freedesktop.org
Mon Oct 12 13:11:24 UTC 2020


 vcl/source/gdi/bmpfast.cxx |   34 ++++++++++++++++++++++------------
 1 file changed, 22 insertions(+), 12 deletions(-)

New commits:
commit 77809fba7d4bf5e0b604ffa3937c18d5530c2d56
Author:     Luboš Luňák <l.lunak at collabora.com>
AuthorDate: Fri Oct 9 19:28:49 2020 +0200
Commit:     Luboš Luňák <l.lunak at collabora.com>
CommitDate: Mon Oct 12 15:10:44 2020 +0200

    implement ImplFastBitmapConversion() for 8bit gray source
    
    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 <l.lunak at collabora.com>

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<ScanlineFormat::N8BitTcMask> : public BasePixelPtr
+class TrueColorPixelPtr<ScanlineFormat::N8BitPal> : 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<ScanlineFormat::N8BitPal>
-: public TrueColorPixelPtr<ScanlineFormat::N8BitTcMask>
-{};
+    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<DSTFMT>& rDst,
     TrueColorPixelPtr<SRCFMT> 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<ScanlineFormat::N32BitTcMask>( rDst, rSrc );
             break;
 
+        case ScanlineFormat::N8BitPal:
+            if(rSrc.maPalette.IsGreyPalette8Bit())
+                return ImplConvertFromBitmap<ScanlineFormat::N8BitPal>( rDst, rSrc );
+            break;
+
         case ScanlineFormat::N24BitTcBgr:
             return ImplConvertFromBitmap<ScanlineFormat::N24BitTcBgr>( 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<ScanlineFormat::N32BitTcMask>( rDst, rSrc );
             break;
 
+        case ScanlineFormat::N8BitPal:
+            if(rSrc.maPalette.IsGreyPalette8Bit())
+                return ImplBlendFromBitmap<ScanlineFormat::N8BitPal>( rDst, rSrc, rMsk );
+            break;
+
         case ScanlineFormat::N24BitTcBgr:
             return ImplBlendFromBitmap<ScanlineFormat::N24BitTcBgr>( rDst, rSrc, rMsk );
         case ScanlineFormat::N24BitTcRgb:


More information about the Libreoffice-commits mailing list