vcl/skia/salbmp.cxx |   14 ++++++++++++--
 1 file changed, 12 insertions(+), 2 deletions(-)

New commits:
commit 3769d01791e54be0fbfc6d706596283213700ad0
Author:     Luboš Luňák <l.lu...@centrum.cz>
AuthorDate: Tue Jul 7 12:15:20 2020 +0000
Commit:     Luboš Luňák <l.lu...@collabora.com>
CommitDate: Wed Jul 8 09:31:12 2020 +0200

    prevent SkiaSalBitmap::Scale() from breaking indexed bitmaps (tdf#134574)
    
    Since the actual scaling is done later at some unknown time,
    the palette mustn't change, but scaling can change colors.
    
    Change-Id: Ie254c8b31993d9d509c32a730dd8c8b5d3cb2256
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/98258
    Tested-by: Jenkins
    Reviewed-by: Luboš Luňák <l.lu...@collabora.com>

diff --git a/vcl/skia/salbmp.cxx b/vcl/skia/salbmp.cxx
index 8cd1a158dc2f..6373eeea405a 100644
--- a/vcl/skia/salbmp.cxx
+++ b/vcl/skia/salbmp.cxx
@@ -296,8 +296,8 @@ bool SkiaSalBitmap::Scale(const double& rScaleX, const 
double& rScaleY, BmpScale
     if (mSize == newSize)
         return true;
 
-    SAL_INFO("vcl.skia.trace", "scale(" << this << "): " << mSize << "->" << 
newSize << ":"
-                                        << static_cast<int>(nScaleFlag));
+    SAL_INFO("vcl.skia.trace", "scale(" << this << "): " << mSize << "/" << 
mBitCount << "->"
+                                        << newSize << ":" << 
static_cast<int>(nScaleFlag));
 
     // The idea here is that the actual scaling will be delayed until the 
result
     // is actually needed. Usually the scaled bitmap will be drawn somewhere,
@@ -319,8 +319,18 @@ bool SkiaSalBitmap::Scale(const double& rScaleX, const 
double& rScaleY, BmpScale
             currentQuality = kHigh_SkFilterQuality;
             break;
         default:
+            SAL_INFO("vcl.skia.trace", "scale(" << this << "): unsupported 
scale algorithm");
             return false;
     }
+    if (mBitCount < 24 && !mPalette.IsGreyPalette8Bit())
+    {
+        // Scaling can introduce additional colors not present in the original
+        // bitmap (e.g. when smoothing). If the bitmap is indexed (has 
non-trivial palette),
+        // this would break the bitmap, because the actual scaling is done 
only somewhen later.
+        // Linear 8bit palette (grey) is ok, since there we use directly the 
values as colors.
+        SAL_INFO("vcl.skia.trace", "scale(" << this << "): indexed bitmap");
+        return false;
+    }
     // if there is already one scale() pending, use the lowest quality of all 
requested
     static_assert(kMedium_SkFilterQuality < kHigh_SkFilterQuality);
     mScaleQuality = std::min(mScaleQuality, currentQuality);
_______________________________________________
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits

Reply via email to