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

Tomaž Vajngerl (via logerrit) logerrit at kemper.freedesktop.org
Tue Apr 30 08:55:09 UTC 2019


 vcl/source/bitmap/BitmapScaleSuperFilter.cxx |   28 ++++++++++++++++++++-------
 1 file changed, 21 insertions(+), 7 deletions(-)

New commits:
commit 60095b481d9663f7bcfe8078d669030ab2bc6a05
Author:     Tomaž Vajngerl <tomaz.vajngerl at collabora.co.uk>
AuthorDate: Tue Apr 30 00:53:37 2019 +0900
Commit:     Tomaž Vajngerl <quikee at gmail.com>
CommitDate: Tue Apr 30 10:53:23 2019 +0200

    tdf#125014 only use a fastpath if src. and dest. bitcount matches
    
    It can happen that a bitmap is 32-bit (made from a VirtualDevice)
    but we can't even create a 32-bit bitmap ourselves. In that case
    we can only create a 24-bit, but now we can't use the fastpath
    anymore as the bitdepth of source and destination is not the same.
    
    Fix this by making sure the general scaler will be used when
    source and destination bitmaps don't have the same bitcount.
    
    Change-Id: Icdb974093558d618b7c056b29963b45ee31ce200
    Reviewed-on: https://gerrit.libreoffice.org/71540
    Tested-by: Jenkins
    Reviewed-by: Tomaž Vajngerl <quikee at gmail.com>

diff --git a/vcl/source/bitmap/BitmapScaleSuperFilter.cxx b/vcl/source/bitmap/BitmapScaleSuperFilter.cxx
index 26ea43af44a8..54f22f2dc5d8 100644
--- a/vcl/source/bitmap/BitmapScaleSuperFilter.cxx
+++ b/vcl/source/bitmap/BitmapScaleSuperFilter.cxx
@@ -1049,10 +1049,12 @@ BitmapEx BitmapScaleSuperFilter::execute(BitmapEx const& rBitmap) const
     {
         Bitmap::ScopedReadAccess pReadAccess(aBitmap);
 
-        sal_Int16 nTargetBitcount = aBitmap.GetBitCount() == 32 ? 32 : 24;
+        sal_uInt16 nSourceBitcount = aBitmap.GetBitCount();
 
-        Bitmap aOutBmp(Size(nDstW, nDstH), nTargetBitcount);
+        Bitmap aOutBmp(Size(nDstW, nDstH), std::max(nSourceBitcount, sal_uInt16(24)));
         Size aOutSize = aOutBmp.GetSizePixel();
+        sal_uInt16 nTargetBitcount = aOutBmp.GetBitCount();
+
         if (!aOutSize.Width() || !aOutSize.Height())
         {
             SAL_WARN("vcl.gdi", "bmp creation failed");
@@ -1076,7 +1078,10 @@ BitmapEx BitmapScaleSuperFilter::execute(BitmapEx const& rBitmap) const
                                    bVMirr, bHMirr );
 
             bool bScaleUp = fScaleX >= fScaleThresh && fScaleY >= fScaleThresh;
-            if( pReadAccess->HasPalette() )
+            // If we have a source bitmap with a palette the scaling converts
+            // from up to 8 bit image -> 24 bit non-palette, which is then
+            // adapted back to the same type as original.
+            if (pReadAccess->HasPalette())
             {
                 switch( pReadAccess->GetScanlineFormat() )
                 {
@@ -1090,21 +1095,30 @@ BitmapEx BitmapScaleSuperFilter::execute(BitmapEx const& rBitmap) const
                     break;
                 }
             }
+            // Here we know that we are dealing with a non-palette source bitmap.
+            // The target is either 24 or 32 bit, depending on the image and
+            // the capabilities of the backend. If for some reason the destination
+            // is not the same bit-depth as the source, then we can't use
+            // a fast path, so we always need to process with a general scaler.
+            else if (nSourceBitcount != nTargetBitcount)
+            {
+                pScaleRangeFn = bScaleUp ? scaleUpNonPalleteGeneral : scaleDownNonPalleteGeneral;
+            }
+            // If we get here then we can only use a fast path, but let's
+            // still keep the fallback to the general scaler alive.
             else
             {
                 switch( pReadAccess->GetScanlineFormat() )
                 {
                 case ScanlineFormat::N24BitTcBgr:
                 case ScanlineFormat::N24BitTcRgb:
-                    pScaleRangeFn = bScaleUp ? scaleUp24bit
-                                             : scaleDown24bit;
+                    pScaleRangeFn = bScaleUp ? scaleUp24bit : scaleDown24bit;
                     break;
                 case ScanlineFormat::N32BitTcRgba:
                 case ScanlineFormat::N32BitTcBgra:
                 case ScanlineFormat::N32BitTcArgb:
                 case ScanlineFormat::N32BitTcAbgr:
-                    pScaleRangeFn = bScaleUp ? scaleUp32bit
-                                             : scaleDown32bit;
+                    pScaleRangeFn = bScaleUp ? scaleUp32bit : scaleDown32bit;
                     break;
                 default:
                     pScaleRangeFn = bScaleUp ? scaleUpNonPalleteGeneral


More information about the Libreoffice-commits mailing list